Merge branch 'master' of 10.0.1.24:cerebrum
[cerebrum.git] / common / comm.h
blob547d73d700f01b6733bf4a18a0592cfb97e9a052
2 #ifndef __COMM_H__
3 #define __COMM_H__
5 #include <stdint.h>
7 /*
8 *comm callback function pointer type.
9 *function signature:
10 *uint8_t callback(uint8_t arglen, uint8_t* argbuf);
11 * payload_offst: number of bytes since the start of this payload
12 * arglen: length of the argument string passed to the function
13 * argbuf: buffer containing the argument string
15 typedef struct comm_callback_descriptor comm_callback_descriptor;
16 typedef void (*comm_callback)(const comm_callback_descriptor* cb, void* argbuf_end);
17 struct comm_callback_descriptor {
18 comm_callback callback;
19 void* argbuf;
20 uint16_t argbuf_len;
22 typedef struct {
23 comm_callback_descriptor const * descriptor;
24 void* argbuf_end;
25 } callback_stack_t;
27 extern const comm_callback_descriptor comm_callbacks[];
28 extern const uint16_t callback_count;
30 extern volatile callback_stack_t next_callback;
31 extern const volatile uint8_t global_argbuf[];
33 #ifndef ARGBUF_SIZE
34 //needs to be at least 4 bytes to accomodate args_t in comm_handle(uint8_t)
35 #ifndef __TEST__
36 #define ARGBUF_SIZE 32
37 #else
38 #define ARGBUF_SIZE 257
39 #endif
40 #endif
42 #define ADDRESS_DISCOVERY 0xFFFF
43 #define ADDRESS_INVALID 0xFFFE
45 void comm_loop(void);
47 #endif//__COMM_H__