| 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@0
|
24
|
|
msach@0
|
25
|
|
msach@0
|
26 /***********************************
|
|
msach@0
|
27 * Type Definitions
|
|
msach@0
|
28 ***********************************/
|
|
msach@0
|
29
|
|
msach@0
|
30 #define BROADCAST_ID 65535
|
|
msach@0
|
31 #define ENDPOINT_ID_SHIFT 32
|
|
msach@0
|
32 #define TRIGGER_SHIFT 48
|
|
msach@0
|
33
|
|
msach@0
|
34 /*
|
|
msach@0
|
35 * A message consists of the
|
|
msach@0
|
36 * 16bit saved trigger value 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@0
|
40 */
|
|
msach@0
|
41 typedef uint64_t lossyCom__msg_t;
|
|
msach@0
|
42 typedef uint32_t lossyCom__msgBody_t;
|
|
msach@0
|
43 typedef uint16_t lossyCom__endpointID_t;
|
|
msach@0
|
44
|
|
msach@0
|
45 /*
|
|
msach@0
|
46 * Message Handler that has two arguments the sender endpoint ID and the Msg
|
|
msach@0
|
47 * Example:
|
|
msach@0
|
48 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
|
|
msach@0
|
49 */
|
|
msach@0
|
50 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t);
|
|
msach@0
|
51
|
|
msach@0
|
52 /*
|
|
msach@0
|
53 * Central communication structure.
|
|
msach@0
|
54 */
|
|
msach@0
|
55 typedef struct{
|
|
msach@0
|
56 uint16_t triggerCounter;
|
|
msach@0
|
57 uint16_t numEndpoints;
|
|
msach@0
|
58 lossyCom__msg_t* outboxArray;
|
|
msach@0
|
59 }lossyCom__exchange_t;
|
|
msach@0
|
60
|
|
msach@0
|
61 /*
|
|
msach@0
|
62 * Endpoint data structure.
|
|
msach@0
|
63 */
|
|
msach@0
|
64 typedef struct {
|
|
msach@0
|
65 uint16_t localTriggerCopy;
|
|
msach@0
|
66 lossyCom__endpointID_t endpointID;
|
|
msach@0
|
67 lossyCom__exchange_t* centralExchangePtr;
|
|
msach@0
|
68 lossyCom__msgHandler* msgHandler;
|
|
msach@0
|
69 } lossyCom__endpoint_t;
|
|
msach@0
|
70
|
|
msach@0
|
71 /***********************************
|
|
msach@0
|
72 * Function Declarations
|
|
msach@0
|
73 ***********************************/
|
|
msach@0
|
74
|
|
msach@0
|
75 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
|
|
msach@0
|
76
|
|
msach@0
|
77 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
78 lossyCom__exchange_t* exchange,
|
|
msach@0
|
79 lossyCom__endpointID_t endpointID,
|
|
msach@0
|
80 lossyCom__msgHandler* msgHandler);
|
|
msach@0
|
81
|
|
msach@0
|
82 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
83 lossyCom__msgBody_t msg);
|
|
msach@0
|
84
|
|
msach@0
|
85 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
86 lossyCom__endpointID_t receiverEndpointID,
|
|
msach@0
|
87 lossyCom__msgBody_t msg);
|
|
msach@0
|
88
|
|
msach@0
|
89 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint); |