| 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@3
|
29 #define MAX_TRIGGER 65535
|
|
msach@0
|
30
|
|
msach@0
|
31 /***********************************
|
|
msach@0
|
32 * Type Definitions
|
|
msach@0
|
33 ***********************************/
|
|
msach@0
|
34
|
|
msach@0
|
35 /*
|
|
msach@0
|
36 * A message consists of the
|
|
msach@1
|
37 * 16bit saved trigger value +1 when the message was sent
|
|
msach@0
|
38 * 16bit receiver identifier, this is the index of the slot in the array
|
|
msach@0
|
39 * 65536 is the broadcast identifier
|
|
msach@0
|
40 * 32bit message body, the message format is defined by the endpoints
|
|
msach@1
|
41 *
|
|
msach@1
|
42 * | 16bit trigger value | 16bit receiverID | 32bit message body |
|
|
msach@0
|
43 */
|
|
msach@1
|
44 #define ENDPOINT_ID_SHIFT 32
|
|
msach@1
|
45 #define TRIGGER_SHIFT 48
|
|
msach@0
|
46 typedef uint64_t lossyCom__msg_t;
|
|
msach@0
|
47 typedef uint32_t lossyCom__msgBody_t;
|
|
msach@0
|
48 typedef uint16_t lossyCom__endpointID_t;
|
|
msach@0
|
49
|
|
msach@0
|
50 /*
|
|
msach@0
|
51 * Message Handler that has two arguments the sender endpoint ID and the Msg
|
|
msach@0
|
52 * Example:
|
|
msach@0
|
53 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
|
|
msach@0
|
54 */
|
|
msach@1
|
55 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t, void*);
|
|
msach@0
|
56
|
|
msach@0
|
57 /*
|
|
msach@0
|
58 * Central communication structure.
|
|
msach@0
|
59 */
|
|
msach@0
|
60 typedef struct{
|
|
msach@2
|
61 volatile uint16_t triggerCounter;
|
|
msach@0
|
62 uint16_t numEndpoints;
|
|
msach@0
|
63 lossyCom__msg_t* outboxArray;
|
|
msach@0
|
64 }lossyCom__exchange_t;
|
|
msach@0
|
65
|
|
msach@0
|
66 /*
|
|
msach@0
|
67 * Endpoint data structure.
|
|
msach@0
|
68 */
|
|
msach@0
|
69 typedef struct {
|
|
msach@0
|
70 uint16_t localTriggerCopy;
|
|
msach@0
|
71 lossyCom__endpointID_t endpointID;
|
|
msach@1
|
72 lossyCom__exchange_t* centralExchange;
|
|
msach@1
|
73 lossyCom__msgHandler msgHandler;
|
|
msach@1
|
74 void* msgHandlerData;
|
|
msach@0
|
75 } lossyCom__endpoint_t;
|
|
msach@0
|
76
|
|
msach@0
|
77 /***********************************
|
|
msach@0
|
78 * Function Declarations
|
|
msach@0
|
79 ***********************************/
|
|
msach@0
|
80
|
|
msach@0
|
81 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
|
|
msach@0
|
82
|
|
msach@0
|
83 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
84 lossyCom__exchange_t* exchange,
|
|
msach@0
|
85 lossyCom__endpointID_t endpointID,
|
|
msach@1
|
86 lossyCom__msgHandler msgHandler,
|
|
msach@1
|
87 void* msgHandlerData);
|
|
msach@0
|
88
|
|
msach@0
|
89 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
90 lossyCom__msgBody_t msg);
|
|
msach@0
|
91
|
|
msach@0
|
92 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
93 lossyCom__endpointID_t receiverEndpointID,
|
|
msach@0
|
94 lossyCom__msgBody_t msg);
|
|
msach@0
|
95
|
|
msach@0
|
96 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint); |