summaryrefslogtreecommitdiff
path: root/serial_link/protocol/transport.h
diff options
context:
space:
mode:
Diffstat (limited to 'serial_link/protocol/transport.h')
-rw-r--r--serial_link/protocol/transport.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/serial_link/protocol/transport.h b/serial_link/protocol/transport.h
index 01119857d3..6f2cf277fb 100644
--- a/serial_link/protocol/transport.h
+++ b/serial_link/protocol/transport.h
@@ -22,6 +22,73 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
+#ifndef SERIAL_LINK_TRANSPORT_H
+#define SERIAL_LINK_TRANSPORT_H
+
+#include "protocol/triple_buffered_object.h"
+
+#define NUM_SLAVES 8
+
+typedef struct {
+ uint16_t element_size;
+ uint16_t buffer_size;
+ uint8_t is_master;
+ uint8_t buffer[] __attribute__((aligned(4)));
+} remote_object_t;
+
+typedef struct {
+ uint16_t element_size;
+ uint8_t destination;
+ uint8_t buffer[] __attribute__((aligned(4)));
+} local_object_t;
+
+#define REMOTE_OBJECT_BUFFER(id, type) \
+typedef struct { \
+ triple_buffer_object_t object; \
+ type buffer[3]; \
+} remote_object_buffer_##id##_t;
+
+#define MASTER_REMOTE_OBJECT(id, type) \
+REMOTE_OBJECT_BUFFER(id, type) \
+typedef struct { \
+ remote_object_t object; \
+ remote_object_buffer_##id##_t buffer; \
+} master_remote_object_##id##_t; \
+master_remote_object_##id##_t remote_object_##id = { \
+ .object = { \
+ .element_size = sizeof(type), \
+ .buffer_size = sizeof(remote_object_buffer_##id##_t), \
+ .is_master = true \
+ }};
+
+#define SLAVE_REMOTE_OBJECT(id, type) \
+REMOTE_OBJECT_BUFFER(id, type) \
+typedef struct { \
+ remote_object_t object; \
+ remote_object_buffer_##id##_t buffer[NUM_SLAVES];\
+} slave_remote_object_##id##_t; \
+slave_remote_object_##id##_t remote_object_##id = { \
+ .object = { \
+ .element_size = sizeof(type), \
+ .buffer_size = sizeof(remote_object_buffer_##id##_t), \
+ .is_master = true \
+ }};
+
+#define LOCAL_OBJECT(id, type) \
+typedef struct { \
+ uint32_t element_size; \
+ uint8_t buffer[NUM_SLAVES][sizeof(type) + 16][3]; \
+} remote_object_##id##_t; \
+remote_object_##id##_t remote_object_##id = {.element_size = sizeof(type) + 16};
+
+#define REMOTE_OBJECT(id) (remote_object_t*)&remote_object_##id
+
+
void init_transport(void);
void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size);
uint32_t transport_send_frame(uint8_t to, uint8_t* data, uint16_t size);
+
+void transport_register_master_remote_object(uint8_t id, void* ptr, uint16_t size);
+void transport_register_slave_remote_object(uint8_t id, void* ptr, uint16_t size);
+
+#endif