annotate 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
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@4 61 volatile uint16_t BroadcastTriggerCounter;
msach@4 62 volatile uint16_t* p2pTriggerCounter;
msach@4 63 uint16_t numEndpoints;
msach@4 64 lossyCom__msg_t* outboxArray;
msach@0 65 }lossyCom__exchange_t;
msach@0 66
msach@0 67 /*
msach@0 68 * Endpoint data structure.
msach@0 69 */
msach@0 70 typedef struct {
msach@4 71 uint16_t lastReceivedBroadcastTrigger;
msach@4 72 uint16_t lastReceivedp2pTrigger;
msach@0 73 lossyCom__endpointID_t endpointID;
msach@4 74 lossyCom__exchange_t* centralExchange;
msach@4 75 lossyCom__msgHandler msgHandler;
msach@4 76 void* msgHandlerData;
msach@0 77 } lossyCom__endpoint_t;
msach@0 78
msach@0 79 /***********************************
msach@0 80 * Function Declarations
msach@0 81 ***********************************/
msach@0 82
msach@0 83 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
msach@0 84
msach@0 85 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
msach@0 86 lossyCom__exchange_t* exchange,
msach@0 87 lossyCom__endpointID_t endpointID,
msach@1 88 lossyCom__msgHandler msgHandler,
msach@1 89 void* msgHandlerData);
msach@0 90
msach@0 91 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
msach@0 92 lossyCom__msgBody_t msg);
msach@0 93
msach@0 94 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
msach@0 95 lossyCom__endpointID_t receiverEndpointID,
msach@0 96 lossyCom__msgBody_t msg);
msach@0 97
msach@0 98 void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);