| rev |
line source |
|
msach@0
|
1 /*
|
|
msach@0
|
2 * This describes a best effort communication channel. Mainly designed for
|
|
msach@0
|
3 * communication between Core-Controllers, so they can inform each other about
|
|
msach@0
|
4 * their status and pass work around. This is to avoid idling cores that occupy
|
|
msach@0
|
5 * the Masterlock.
|
|
msach@0
|
6 *
|
|
msach@0
|
7 * The communication entities poll a central trigger counter that increases when
|
|
msach@0
|
8 * there are new messages. However it's not guaranteed that the increase of the
|
|
msach@0
|
9 * counter reflects the number of new messages.
|
|
msach@0
|
10 *
|
|
msach@0
|
11 * The messages consist of a single 64bit word so it can be written in one
|
|
msach@0
|
12 * operation and therefore avoiding inconsistent messages.
|
|
msach@0
|
13 *
|
|
msach@0
|
14 * The messages are handled with a handler function provided by the receiver
|
|
msach@0
|
15 * when acquiring the communication endpoint.
|
|
msach@0
|
16 *
|
|
msach@0
|
17 * The message passing is handled by a central struct that is used w/o any lock.
|
|
msach@0
|
18 * It consists of a array messages for the number of communicating entities. The
|
|
msach@0
|
19 * number of entities is fixed at initialization.
|
|
msach@0
|
20 */
|
|
msach@0
|
21
|
|
msach@0
|
22 #include <stdint.h>
|
|
msach@0
|
23
|
|
msach@1
|
24 /***********************************
|
|
msach@1
|
25 * General Defines
|
|
msach@1
|
26 ***********************************/
|
|
msach@1
|
27 //never use this number as a endpoint!
|
|
msach@1
|
28 #define BROADCAST_ID 65535
|
|
msach@0
|
29
|
|
msach@0
|
30 /***********************************
|
|
msach@0
|
31 * Type Definitions
|
|
msach@0
|
32 ***********************************/
|
|
msach@0
|
33
|
|
msach@0
|
34 /*
|
|
msach@0
|
35 * A message consists of the
|
|
msach@1
|
36 * 16bit saved trigger value +1 when the message was sent
|
|
msach@0
|
37 * 16bit receiver identifier, this is the index of the slot in the array
|
|
msach@0
|
38 * 65536 is the broadcast identifier
|
|
msach@0
|
39 * 32bit message body, the message format is defined by the endpoints
|
|
msach@1
|
40 *
|
|
msach@1
|
41 * | 16bit trigger value | 16bit receiverID | 32bit message body |
|
|
msach@0
|
42 */
|
|
msach@1
|
43 #define ENDPOINT_ID_SHIFT 32
|
|
msach@1
|
44 #define TRIGGER_SHIFT 48
|
|
msach@0
|
45 typedef uint64_t lossyCom__msg_t;
|
|
msach@0
|
46 typedef uint32_t lossyCom__msgBody_t;
|
|
msach@0
|
47 typedef uint16_t lossyCom__endpointID_t;
|
|
msach@0
|
48
|
|
msach@0
|
49 /*
|
|
msach@0
|
50 * Message Handler that has two arguments the sender endpoint ID and the Msg
|
|
msach@0
|
51 * Example:
|
|
msach@0
|
52 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
|
|
msach@0
|
53 */
|
|
msach@1
|
54 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t, void*);
|
|
msach@0
|
55
|
|
msach@0
|
56 /*
|
|
msach@0
|
57 * Central communication structure.
|
|
msach@0
|
58 */
|
|
msach@0
|
59 typedef struct{
|
|
msach@0
|
60 uint16_t triggerCounter;
|
|
msach@0
|
61 uint16_t numEndpoints;
|
|
msach@0
|
62 lossyCom__msg_t* outboxArray;
|
|
msach@0
|
63 }lossyCom__exchange_t;
|
|
msach@0
|
64
|
|
msach@0
|
65 /*
|
|
msach@0
|
66 * Endpoint data structure.
|
|
msach@0
|
67 */
|
|
msach@0
|
68 typedef struct {
|
|
msach@0
|
69 uint16_t localTriggerCopy;
|
|
msach@0
|
70 lossyCom__endpointID_t endpointID;
|
|
msach@1
|
71 lossyCom__exchange_t* centralExchange;
|
|
msach@1
|
72 lossyCom__msgHandler msgHandler;
|
|
msach@1
|
73 void* msgHandlerData;
|
|
msach@0
|
74 } lossyCom__endpoint_t;
|
|
msach@0
|
75
|
|
msach@0
|
76 /***********************************
|
|
msach@0
|
77 * Function Declarations
|
|
msach@0
|
78 ***********************************/
|
|
msach@0
|
79
|
|
msach@0
|
80 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
|
|
msach@0
|
81
|
|
msach@0
|
82 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
83 lossyCom__exchange_t* exchange,
|
|
msach@0
|
84 lossyCom__endpointID_t endpointID,
|
|
msach@1
|
85 lossyCom__msgHandler msgHandler,
|
|
msach@1
|
86 void* msgHandlerData);
|
|
msach@0
|
87
|
|
msach@0
|
88 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
89 lossyCom__msgBody_t msg);
|
|
msach@0
|
90
|
|
msach@0
|
91 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
92 lossyCom__endpointID_t receiverEndpointID,
|
|
msach@0
|
93 lossyCom__msgBody_t msg);
|
|
msach@0
|
94
|
|
msach@0
|
95 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint); |