Local and remote objects WIP

pull/482/head
Fred Sundvik 9 years ago
parent b7059d35f9
commit 4ee6eadf9e

@ -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

@ -27,7 +27,7 @@ SOFTWARE.
typedef struct {
uint8_t state;
uint8_t buffer[];
uint8_t buffer[] __attribute__((aligned(4)));
}triple_buffer_object_t;
void triple_buffer_init(triple_buffer_object_t* object);

@ -25,6 +25,32 @@ SOFTWARE.
#include <cgreen/cgreen.h>
#include "protocol/transport.c"
typedef struct {
uint32_t test;
} test_object1_t;
typedef struct {
uint32_t test1;
uint32_t test2;
} test_object2_t;
MASTER_REMOTE_OBJECT(0, test_object1_t);
SLAVE_REMOTE_OBJECT(1, test_object1_t);
MASTER_REMOTE_OBJECT(2, test_object2_t);
SLAVE_REMOTE_OBJECT(3, test_object2_t);
// We want
// master -> slave = 1 local(target all), 1 remote object
// slave -> master = 1 local(target 0), multiple remote objects
// master -> single slave (multiple local, target id), 1 remote object
remote_object_t* remote_objects[] = {
REMOTE_OBJECT(0),
REMOTE_OBJECT(1),
REMOTE_OBJECT(2),
REMOTE_OBJECT(3),
};
Describe(Transport);
BeforeEach(Transport) {
init_transport();

Loading…
Cancel
Save