| 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@5
|
7 * The communication entities poll a central trigger counter and per receiver
|
|
msach@5
|
8 * trigger counter that increase when there are new messages.
|
|
msach@5
|
9 * However it's not guaranteed that the increase of the counter reflects the
|
|
msach@5
|
10 * number of new messages. The new trigger counter can even be lower than the
|
|
msach@5
|
11 * last see counter for some receiver.
|
|
msach@0
|
12 *
|
|
msach@0
|
13 * The messages consist of a single 64bit word so it can be written in one
|
|
msach@0
|
14 * operation and therefore avoiding inconsistent messages.
|
|
msach@0
|
15 *
|
|
msach@0
|
16 * The messages are handled with a handler function provided by the receiver
|
|
msach@0
|
17 * when acquiring the communication endpoint.
|
|
msach@0
|
18 *
|
|
msach@0
|
19 * The message passing is handled by a central struct that is used w/o any lock.
|
|
msach@5
|
20 * It consists of a array messages for the number of communicating endpoints.
|
|
msach@5
|
21 * The number of endpoints is fixed at initialization time.
|
|
msach@0
|
22 */
|
|
msach@0
|
23
|
|
msach@5
|
24 #ifndef LOSSYCOM_H
|
|
msach@5
|
25 #define LOSSYCOM_H
|
|
msach@5
|
26
|
|
msach@0
|
27 #include <stdint.h>
|
|
msach@0
|
28
|
|
msach@1
|
29 /***********************************
|
|
msach@1
|
30 * General Defines
|
|
msach@1
|
31 ***********************************/
|
|
msach@1
|
32 //never use this number as a endpoint!
|
|
msach@1
|
33 #define BROADCAST_ID 65535
|
|
msach@3
|
34 #define MAX_TRIGGER 65535
|
|
msach@0
|
35
|
|
msach@0
|
36 /***********************************
|
|
msach@0
|
37 * Type Definitions
|
|
msach@0
|
38 ***********************************/
|
|
msach@0
|
39
|
|
msach@0
|
40 /*
|
|
msach@0
|
41 * A message consists of the
|
|
msach@1
|
42 * 16bit saved trigger value +1 when the message was sent
|
|
msach@0
|
43 * 16bit receiver identifier, this is the index of the slot in the array
|
|
msach@0
|
44 * 65536 is the broadcast identifier
|
|
msach@0
|
45 * 32bit message body, the message format is defined by the endpoints
|
|
msach@1
|
46 *
|
|
msach@1
|
47 * | 16bit trigger value | 16bit receiverID | 32bit message body |
|
|
msach@0
|
48 */
|
|
msach@1
|
49 #define ENDPOINT_ID_SHIFT 32
|
|
msach@1
|
50 #define TRIGGER_SHIFT 48
|
|
msach@0
|
51 typedef uint64_t lossyCom__msg_t;
|
|
msach@0
|
52 typedef uint32_t lossyCom__msgBody_t;
|
|
msach@0
|
53 typedef uint16_t lossyCom__endpointID_t;
|
|
msach@0
|
54
|
|
msach@0
|
55 /*
|
|
msach@0
|
56 * Message Handler that has two arguments the sender endpoint ID and the Msg
|
|
msach@0
|
57 * Example:
|
|
msach@0
|
58 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
|
|
msach@0
|
59 */
|
|
msach@1
|
60 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t, void*);
|
|
msach@0
|
61
|
|
msach@0
|
62 /*
|
|
msach@0
|
63 * Central communication structure.
|
|
msach@0
|
64 */
|
|
msach@0
|
65 typedef struct{
|
|
msach@5
|
66 volatile uint16_t broadcastTriggerCounter;
|
|
msach@5
|
67 volatile uint16_t* p2pTriggerCounters;
|
|
msach@4
|
68 uint16_t numEndpoints;
|
|
msach@4
|
69 lossyCom__msg_t* outboxArray;
|
|
msach@0
|
70 }lossyCom__exchange_t;
|
|
msach@0
|
71
|
|
msach@0
|
72 /*
|
|
msach@0
|
73 * Endpoint data structure.
|
|
msach@0
|
74 */
|
|
msach@0
|
75 typedef struct {
|
|
msach@5
|
76 lossyCom__exchange_t* centralExchange;
|
|
msach@5
|
77 lossyCom__endpointID_t endpointID;
|
|
msach@5
|
78 lossyCom__msgHandler msgHandler;
|
|
msach@5
|
79 void* msgHandlerData;
|
|
msach@4
|
80 uint16_t lastReceivedBroadcastTrigger;
|
|
msach@4
|
81 uint16_t lastReceivedp2pTrigger;
|
|
msach@0
|
82 } lossyCom__endpoint_t;
|
|
msach@0
|
83
|
|
msach@0
|
84 /***********************************
|
|
msach@0
|
85 * Function Declarations
|
|
msach@0
|
86 ***********************************/
|
|
msach@0
|
87
|
|
msach@0
|
88 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
|
|
msach@0
|
89
|
|
msach@0
|
90 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
91 lossyCom__exchange_t* exchange,
|
|
msach@0
|
92 lossyCom__endpointID_t endpointID,
|
|
msach@1
|
93 lossyCom__msgHandler msgHandler,
|
|
msach@1
|
94 void* msgHandlerData);
|
|
msach@0
|
95
|
|
msach@0
|
96 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
97 lossyCom__msgBody_t msg);
|
|
msach@0
|
98
|
|
msach@0
|
99 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
|
|
msach@0
|
100 lossyCom__endpointID_t receiverEndpointID,
|
|
msach@0
|
101 lossyCom__msgBody_t msg);
|
|
msach@0
|
102
|
|
msach@5
|
103 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
|
|
msach@5
|
104
|
|
msach@5
|
105 #endif //LOSSYCOM_H |