Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > BestEffortMessaging
view LossyCom.h @ 4:7ba5a3a6102d
System with multiple point 2 point trigger working
| author | Merten Sach <msach@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 13 Mar 2012 18:22:12 +0100 |
| parents | 5c0fb7c519d7 |
| children | 95a03e431480 |
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 BroadcastTriggerCounter;
62 volatile uint16_t* p2pTriggerCounter;
63 uint16_t numEndpoints;
64 lossyCom__msg_t* outboxArray;
65 }lossyCom__exchange_t;
67 /*
68 * Endpoint data structure.
69 */
70 typedef struct {
71 uint16_t lastReceivedBroadcastTrigger;
72 uint16_t lastReceivedp2pTrigger;
73 lossyCom__endpointID_t endpointID;
74 lossyCom__exchange_t* centralExchange;
75 lossyCom__msgHandler msgHandler;
76 void* msgHandlerData;
77 } lossyCom__endpoint_t;
79 /***********************************
80 * Function Declarations
81 ***********************************/
83 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
85 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
86 lossyCom__exchange_t* exchange,
87 lossyCom__endpointID_t endpointID,
88 lossyCom__msgHandler msgHandler,
89 void* msgHandlerData);
91 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
92 lossyCom__msgBody_t msg);
94 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
95 lossyCom__endpointID_t receiverEndpointID,
96 lossyCom__msgBody_t msg);
98 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
