summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-08-20 11:08:00 -0500
committerJeff Epler <jepler@gmail.com>2020-09-21 16:44:26 -0500
commita2e1867f69ec2d703a9651e5c36a02b0e14dfd9c (patch)
treed114916bc977fce546d3b6a5aaca3f925971bf86 /shared-module
parente7a213a11420ed362dfb672cd0fa6e77c032fa07 (diff)
_canio: Minimal implementation for SAM E5x MCUs
Tested & working: * Send standard packets * Receive standard packets (1 FIFO, no filter) Interoperation between SAM E54 Xplained running this tree and MicroPython running on STM32F405 Feather with an external transceiver was also tested. Many other aspects of a full implementation are not yet present, such as error detection and recovery.
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/_canio/Match.c43
-rw-r--r--shared-module/_canio/Match.h41
-rw-r--r--shared-module/_canio/Message.c85
-rw-r--r--shared-module/_canio/Message.h47
4 files changed, 216 insertions, 0 deletions
diff --git a/shared-module/_canio/Match.c b/shared-module/_canio/Match.c
new file mode 100644
index 000000000..2b696addb
--- /dev/null
+++ b/shared-module/_canio/Match.c
@@ -0,0 +1,43 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-module/_canio/Match.h"
+
+void common_hal_canio_match_construct(canio_match_obj_t *self, int address, int mask, bool extended) {
+ self->address = address;
+ self->mask = mask;
+ self->extended = extended;
+}
+
+int common_hal_canio_match_address_get(const canio_match_obj_t *self) {
+ return self->address;
+}
+int common_hal_canio_match_mask_get(const canio_match_obj_t *self) {
+ return self->mask;
+}
+bool common_hal_canio_match_extended_get(const canio_match_obj_t *self) {
+ return self->extended;
+}
diff --git a/shared-module/_canio/Match.h b/shared-module/_canio/Match.h
new file mode 100644
index 000000000..099df976d
--- /dev/null
+++ b/shared-module/_canio/Match.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ int address;
+ int mask;
+ bool extended;
+} canio_match_obj_t;
+
+void common_hal_canio_match_construct(canio_match_obj_t *self, int address, int mask, bool extended);
+int common_hal_canio_match_address_get(const canio_match_obj_t *self);
+int common_hal_canio_match_mask_get(const canio_match_obj_t *self);
+bool common_hal_canio_match_extended_get(const canio_match_obj_t *self);
diff --git a/shared-module/_canio/Message.c b/shared-module/_canio/Message.c
new file mode 100644
index 000000000..df6a40a0a
--- /dev/null
+++ b/shared-module/_canio/Message.c
@@ -0,0 +1,85 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-module/_canio/Message.h"
+
+#include <string.h>
+
+void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void *data, size_t size, bool rtr)
+{
+ self->id = id;
+ self->size = size;
+ self->rtr = rtr;
+ if (data) {
+ memcpy(self->data, data, size);
+ } else {
+ memset(self->data, 0, size);
+ }
+}
+
+int common_hal_canio_message_id_get(const canio_message_obj_t *self)
+{
+ return self->id;
+}
+
+void common_hal_canio_message_id_set(canio_message_obj_t *self, int id)
+{
+ self->id = id;
+}
+
+
+const void *common_hal_canio_message_data_get(const canio_message_obj_t *self)
+{
+ return self->data;
+}
+
+const void common_hal_canio_message_data_set(canio_message_obj_t *self, const void *data, size_t size)
+{
+ memcpy(self->data, data, size);
+}
+
+
+size_t common_hal_canio_message_size_get(const canio_message_obj_t *self)
+{
+ return self->size;
+}
+
+void common_hal_canio_message_size_set(canio_message_obj_t *self, size_t size)
+{
+ memset(self->data, 0, size);
+ self->size = size;
+}
+
+
+bool common_hal_canio_message_rtr_get(const canio_message_obj_t *self)
+{
+ return self->rtr;
+}
+
+void common_hal_canio_message_rtr_set(canio_message_obj_t *self, bool rtr)
+{
+ self->rtr = rtr;
+}
diff --git a/shared-module/_canio/Message.h b/shared-module/_canio/Message.h
new file mode 100644
index 000000000..e846f1095
--- /dev/null
+++ b/shared-module/_canio/Message.h
@@ -0,0 +1,47 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#pragma once
+
+#include "py/obj.h"
+
+typedef struct {
+ mp_obj_base_t base;
+ int id;
+ size_t size;
+ uint8_t data[8];
+ bool rtr;
+} canio_message_obj_t;
+
+void common_hal_canio_message_construct(canio_message_obj_t *self, int id, void *data, size_t size, bool rtr);
+bool common_hal_canio_message_rtr_get(const canio_message_obj_t *self);
+int common_hal_canio_message_id_get(const canio_message_obj_t *self);
+const void *common_hal_canio_message_data_get(const canio_message_obj_t *self);
+size_t common_hal_canio_message_size_get(const canio_message_obj_t *self);
+void common_hal_canio_message_rtr_set(canio_message_obj_t *self, bool rtr);
+void common_hal_canio_message_id_set(canio_message_obj_t *self, int id);
+void common_hal_canio_message_data_set(canio_message_obj_t *self, const void *data, size_t size);
+void common_hal_canio_message_size_set(canio_message_obj_t *self, size_t size);