Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > BestEffortMessaging
view LossyCom.h @ 3:5c0fb7c519d7
Check for trigger counter overflow
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 13 Mar 2012 15:21:36 +0100 |
| parents | b6dd31dbab8c |
| children | 7ba5a3a6102d |
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 that increases when
8 * there are new messages. However it's not guaranteed that the increase of the
9 * counter reflects the number of new messages.
10 *
11 * The messages consist of a single 64bit word so it can be written in one
12 * operation and therefore avoiding inconsistent messages.
13 *
14 * The messages are handled with a handler function provided by the receiver
15 * when acquiring the communication endpoint.
16 *
17 * The message passing is handled by a central struct that is used w/o any lock.
18 * It consists of a array messages for the number of communicating entities. The
19 * number of entities is fixed at initialization.
20 */
22 #include <stdint.h>
24 /***********************************
25 * General Defines
26 ***********************************/
27 //never use this number as a endpoint!
28 #define BROADCAST_ID 65535
29 #define MAX_TRIGGER 65535
31 /***********************************
32 * Type Definitions
33 ***********************************/
35 /*
36 * A message consists of the
37 * 16bit saved trigger value +1 when the message was sent
38 * 16bit receiver identifier, this is the index of the slot in the array
39 * 65536 is the broadcast identifier
40 * 32bit message body, the message format is defined by the endpoints
41 *
42 * | 16bit trigger value | 16bit receiverID | 32bit message body |
43 */
44 #define ENDPOINT_ID_SHIFT 32
45 #define TRIGGER_SHIFT 48
46 typedef uint64_t lossyCom__msg_t;
47 typedef uint32_t lossyCom__msgBody_t;
48 typedef uint16_t lossyCom__endpointID_t;
50 /*
51 * Message Handler that has two arguments the sender endpoint ID and the Msg
52 * Example:
53 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
54 */
55 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t, void*);
57 /*
58 * Central communication structure.
59 */
60 typedef struct{
61 volatile uint16_t triggerCounter;
62 uint16_t numEndpoints;
63 lossyCom__msg_t* outboxArray;
64 }lossyCom__exchange_t;
66 /*
67 * Endpoint data structure.
68 */
69 typedef struct {
70 uint16_t localTriggerCopy;
71 lossyCom__endpointID_t endpointID;
72 lossyCom__exchange_t* centralExchange;
73 lossyCom__msgHandler msgHandler;
74 void* msgHandlerData;
75 } lossyCom__endpoint_t;
77 /***********************************
78 * Function Declarations
79 ***********************************/
81 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
83 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
84 lossyCom__exchange_t* exchange,
85 lossyCom__endpointID_t endpointID,
86 lossyCom__msgHandler msgHandler,
87 void* msgHandlerData);
89 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
90 lossyCom__msgBody_t msg);
92 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
93 lossyCom__endpointID_t receiverEndpointID,
94 lossyCom__msgBody_t msg);
96 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
