diff options
Diffstat (limited to 'quantum/serial_link/protocol/transport.h')
| -rw-r--r-- | quantum/serial_link/protocol/transport.h | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/quantum/serial_link/protocol/transport.h b/quantum/serial_link/protocol/transport.h deleted file mode 100644 index 3ce0c9fe4..000000000 --- a/quantum/serial_link/protocol/transport.h +++ /dev/null | |||
| @@ -1,139 +0,0 @@ | |||
| 1 | /* | ||
| 2 | The MIT License (MIT) | ||
| 3 | |||
| 4 | Copyright (c) 2016 Fred Sundvik | ||
| 5 | |||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | of this software and associated documentation files (the "Software"), to deal | ||
| 8 | in the Software without restriction, including without limitation the rights | ||
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | copies of the Software, and to permit persons to whom the Software is | ||
| 11 | furnished to do so, subject to the following conditions: | ||
| 12 | |||
| 13 | The above copyright notice and this permission notice shall be included in all | ||
| 14 | copies or substantial portions of the Software. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 22 | SOFTWARE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include "serial_link/protocol/triple_buffered_object.h" | ||
| 28 | #include "serial_link/system/serial_link.h" | ||
| 29 | |||
| 30 | #define NUM_SLAVES 8 | ||
| 31 | #define LOCAL_OBJECT_EXTRA 16 | ||
| 32 | |||
| 33 | // master -> slave = 1 local(target all), 1 remote object | ||
| 34 | // slave -> master = 1 local(target 0), multiple remote objects | ||
| 35 | // master -> single slave (multiple local, target id), 1 remote object | ||
| 36 | typedef enum { | ||
| 37 | MASTER_TO_ALL_SLAVES, | ||
| 38 | MASTER_TO_SINGLE_SLAVE, | ||
| 39 | SLAVE_TO_MASTER, | ||
| 40 | } remote_object_type; | ||
| 41 | |||
| 42 | typedef struct { | ||
| 43 | remote_object_type object_type; | ||
| 44 | uint16_t object_size; | ||
| 45 | uint8_t buffer[] __attribute__((aligned(4))); | ||
| 46 | } remote_object_t; | ||
| 47 | |||
| 48 | #define REMOTE_OBJECT_SIZE(objectsize) (sizeof(triple_buffer_object_t) + objectsize * 3) | ||
| 49 | #define LOCAL_OBJECT_SIZE(objectsize) (sizeof(triple_buffer_object_t) + (objectsize + LOCAL_OBJECT_EXTRA) * 3) | ||
| 50 | |||
| 51 | #define REMOTE_OBJECT_HELPER(name, type, num_local, num_remote) \ | ||
| 52 | typedef struct { \ | ||
| 53 | remote_object_t object; \ | ||
| 54 | uint8_t buffer[num_remote * REMOTE_OBJECT_SIZE(sizeof(type)) + num_local * LOCAL_OBJECT_SIZE(sizeof(type))]; \ | ||
| 55 | } remote_object_##name##_t; | ||
| 56 | |||
| 57 | #define MASTER_TO_ALL_SLAVES_OBJECT(name, type) \ | ||
| 58 | REMOTE_OBJECT_HELPER(name, type, 1, 1) \ | ||
| 59 | remote_object_##name##_t remote_object_##name = {.object = { \ | ||
| 60 | .object_type = MASTER_TO_ALL_SLAVES, \ | ||
| 61 | .object_size = sizeof(type), \ | ||
| 62 | }}; \ | ||
| 63 | type* begin_write_##name(void) { \ | ||
| 64 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 65 | triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \ | ||
| 66 | return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \ | ||
| 67 | } \ | ||
| 68 | void end_write_##name(void) { \ | ||
| 69 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 70 | triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \ | ||
| 71 | triple_buffer_end_write_internal(tb); \ | ||
| 72 | signal_data_written(); \ | ||
| 73 | } \ | ||
| 74 | type* read_##name(void) { \ | ||
| 75 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 76 | uint8_t* start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size); \ | ||
| 77 | triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \ | ||
| 78 | return (type*)triple_buffer_read_internal(obj->object_size, tb); \ | ||
| 79 | } | ||
| 80 | |||
| 81 | #define MASTER_TO_SINGLE_SLAVE_OBJECT(name, type) \ | ||
| 82 | REMOTE_OBJECT_HELPER(name, type, NUM_SLAVES, 1) \ | ||
| 83 | remote_object_##name##_t remote_object_##name = {.object = { \ | ||
| 84 | .object_type = MASTER_TO_SINGLE_SLAVE, \ | ||
| 85 | .object_size = sizeof(type), \ | ||
| 86 | }}; \ | ||
| 87 | type* begin_write_##name(uint8_t slave) { \ | ||
| 88 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 89 | uint8_t* start = obj->buffer; \ | ||
| 90 | start += slave * LOCAL_OBJECT_SIZE(obj->object_size); \ | ||
| 91 | triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \ | ||
| 92 | return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \ | ||
| 93 | } \ | ||
| 94 | void end_write_##name(uint8_t slave) { \ | ||
| 95 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 96 | uint8_t* start = obj->buffer; \ | ||
| 97 | start += slave * LOCAL_OBJECT_SIZE(obj->object_size); \ | ||
| 98 | triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \ | ||
| 99 | triple_buffer_end_write_internal(tb); \ | ||
| 100 | signal_data_written(); \ | ||
| 101 | } \ | ||
| 102 | type* read_##name() { \ | ||
| 103 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 104 | uint8_t* start = obj->buffer + NUM_SLAVES * LOCAL_OBJECT_SIZE(obj->object_size); \ | ||
| 105 | triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \ | ||
| 106 | return (type*)triple_buffer_read_internal(obj->object_size, tb); \ | ||
| 107 | } | ||
| 108 | |||
| 109 | #define SLAVE_TO_MASTER_OBJECT(name, type) \ | ||
| 110 | REMOTE_OBJECT_HELPER(name, type, 1, NUM_SLAVES) \ | ||
| 111 | remote_object_##name##_t remote_object_##name = {.object = { \ | ||
| 112 | .object_type = SLAVE_TO_MASTER, \ | ||
| 113 | .object_size = sizeof(type), \ | ||
| 114 | }}; \ | ||
| 115 | type* begin_write_##name(void) { \ | ||
| 116 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 117 | triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \ | ||
| 118 | return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \ | ||
| 119 | } \ | ||
| 120 | void end_write_##name(void) { \ | ||
| 121 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 122 | triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; \ | ||
| 123 | triple_buffer_end_write_internal(tb); \ | ||
| 124 | signal_data_written(); \ | ||
| 125 | } \ | ||
| 126 | type* read_##name(uint8_t slave) { \ | ||
| 127 | remote_object_t* obj = (remote_object_t*)&remote_object_##name; \ | ||
| 128 | uint8_t* start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size); \ | ||
| 129 | start += slave * REMOTE_OBJECT_SIZE(obj->object_size); \ | ||
| 130 | triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \ | ||
| 131 | return (type*)triple_buffer_read_internal(obj->object_size, tb); \ | ||
| 132 | } | ||
| 133 | |||
| 134 | #define REMOTE_OBJECT(name) (remote_object_t*)&remote_object_##name | ||
| 135 | |||
| 136 | void add_remote_objects(remote_object_t** remote_objects, uint32_t num_remote_objects); | ||
| 137 | void reinitialize_serial_link_transport(void); | ||
| 138 | void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size); | ||
| 139 | void update_transport(void); | ||
