diff options
author | 2016-02-21 12:53:51 +0200 | |
---|---|---|
committer | 2016-02-21 12:53:51 +0200 | |
commit | 4ee6eadf9e88b89f017c3c06e2d376cf953f6a42 (patch) | |
tree | 0d7d4e841c9cb7713caee616dbd0d5171ad5e429 /serial_link/protocol/transport.h | |
parent | b7059d35f90a7cc8b07944d78984afa832190bdc (diff) | |
download | qmk_firmware-4ee6eadf9e88b89f017c3c06e2d376cf953f6a42.tar.gz |
Local and remote objects WIP
Diffstat (limited to 'serial_link/protocol/transport.h')
-rw-r--r-- | serial_link/protocol/transport.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/serial_link/protocol/transport.h b/serial_link/protocol/transport.h index 01119857d..6f2cf277f 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 |