Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > BestEffortMessaging
view LossyCom.h @ 5:95a03e431480
corrected comments and variable renaming
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 13 Mar 2012 19:07:49 +0100 |
| parents | 7ba5a3a6102d |
| children |
line source
1 /*
2 * This describes a best effort communication channel. Mainly designed for
3 * communication between Core-Controllers, so they can inform each other about
4 * their status and pass work around. This is to avoid idling cores that occupy
5 * the Masterlock.
6 *
7 * The communication entities poll a central trigger counter and per receiver
8 * trigger counter that increase when there are new messages.
9 * However it's not guaranteed that the increase of the counter reflects the
10 * number of new messages. The new trigger counter can even be lower than the
11 * last see counter for some receiver.
12 *
13 * The messages consist of a single 64bit word so it can be written in one
14 * operation and therefore avoiding inconsistent messages.
15 *
16 * The messages are handled with a handler function provided by the receiver
17 * when acquiring the communication endpoint.
18 *
19 * The message passing is handled by a central struct that is used w/o any lock.
20 * It consists of a array messages for the number of communicating endpoints.
21 * The number of endpoints is fixed at initialization time.
22 */
24 #ifndef LOSSYCOM_H
25 #define LOSSYCOM_H
27 #include <stdint.h>
29 /***********************************
30 * General Defines
31 ***********************************/
32 //never use this number as a endpoint!
33 #define BROADCAST_ID 65535
34 #define MAX_TRIGGER 65535
36 /***********************************
37 * Type Definitions
38 ***********************************/
40 /*
41 * A message consists of the
42 * 16bit saved trigger value +1 when the message was sent
43 * 16bit receiver identifier, this is the index of the slot in the array
44 * 65536 is the broadcast identifier
45 * 32bit message body, the message format is defined by the endpoints
46 *
47 * | 16bit trigger value | 16bit receiverID | 32bit message body |
48 */
49 #define ENDPOINT_ID_SHIFT 32
50 #define TRIGGER_SHIFT 48
51 typedef uint64_t lossyCom__msg_t;
52 typedef uint32_t lossyCom__msgBody_t;
53 typedef uint16_t lossyCom__endpointID_t;
55 /*
56 * Message Handler that has two arguments the sender endpoint ID and the Msg
57 * Example:
58 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
59 */
60 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t, void*);
62 /*
63 * Central communication structure.
64 */
65 typedef struct{
66 volatile uint16_t broadcastTriggerCounter;
67 volatile uint16_t* p2pTriggerCounters;
68 uint16_t numEndpoints;
69 lossyCom__msg_t* outboxArray;
70 }lossyCom__exchange_t;
72 /*
73 * Endpoint data structure.
74 */
75 typedef struct {
76 lossyCom__exchange_t* centralExchange;
77 lossyCom__endpointID_t endpointID;
78 lossyCom__msgHandler msgHandler;
79 void* msgHandlerData;
80 uint16_t lastReceivedBroadcastTrigger;
81 uint16_t lastReceivedp2pTrigger;
82 } lossyCom__endpoint_t;
84 /***********************************
85 * Function Declarations
86 ***********************************/
88 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
90 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
91 lossyCom__exchange_t* exchange,
92 lossyCom__endpointID_t endpointID,
93 lossyCom__msgHandler msgHandler,
94 void* msgHandlerData);
96 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
97 lossyCom__msgBody_t msg);
99 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
100 lossyCom__endpointID_t receiverEndpointID,
101 lossyCom__msgBody_t msg);
103 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
105 #endif //LOSSYCOM_H
