diff LossyCom.h @ 0:29d8b41926f0

Initial commit - compiles but has still the wrong name
author Merten Sach <msach@mailbox.tu-berlin.de>
date Wed, 07 Mar 2012 19:46:37 +0100
parents
children 826448e34e80
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LossyCom.h	Wed Mar 07 19:46:37 2012 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/*
     1.5 + * This describes a best effort communication channel. Mainly designed for
     1.6 + * communication between Core-Controllers, so they can inform each other about
     1.7 + * their status and pass work around. This is to avoid idling cores that occupy
     1.8 + * the Masterlock.
     1.9 + * 
    1.10 + * The communication entities poll a central trigger counter that increases when
    1.11 + * there are new messages. However it's not guaranteed that the increase of the
    1.12 + * counter reflects the number of new messages.
    1.13 + * 
    1.14 + * The messages consist of a single 64bit word so it can be written in one 
    1.15 + * operation and therefore avoiding inconsistent messages.
    1.16 + * 
    1.17 + * The messages are handled with a handler function provided by the receiver
    1.18 + * when acquiring the communication endpoint.
    1.19 + * 
    1.20 + * The message passing is handled by a central struct that is used w/o any lock.
    1.21 + * It consists of a array messages for the number of communicating entities. The
    1.22 + * number of entities is fixed at initialization.
    1.23 + */
    1.24 +
    1.25 +#include <stdint.h>
    1.26 +
    1.27 +
    1.28 +
    1.29 +/***********************************
    1.30 + * Type Definitions
    1.31 + ***********************************/
    1.32 +
    1.33 +#define BROADCAST_ID 65535
    1.34 +#define ENDPOINT_ID_SHIFT 32
    1.35 +#define TRIGGER_SHIFT 48
    1.36 +
    1.37 +/*
    1.38 + * A message consists of the 
    1.39 + * 16bit saved trigger value when the message was sent
    1.40 + * 16bit receiver identifier, this is the index of the slot in the array
    1.41 + *  65536 is the broadcast identifier
    1.42 + * 32bit message body, the message format is defined by the endpoints
    1.43 + */
    1.44 +typedef uint64_t lossyCom__msg_t;
    1.45 +typedef uint32_t lossyCom__msgBody_t;
    1.46 +typedef uint16_t lossyCom__endpointID_t;
    1.47 +
    1.48 +/*
    1.49 + * Message Handler that has two arguments the sender endpoint ID and the Msg
    1.50 + * Example: 
    1.51 + * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
    1.52 + */
    1.53 +typedef void  (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t);
    1.54 +
    1.55 +/*
    1.56 + * Central communication structure.
    1.57 + */
    1.58 +typedef struct{
    1.59 +    uint16_t triggerCounter;
    1.60 +    uint16_t numEndpoints;
    1.61 +    lossyCom__msg_t* outboxArray;
    1.62 +}lossyCom__exchange_t;
    1.63 +
    1.64 +/*
    1.65 + * Endpoint data structure.
    1.66 + */
    1.67 +typedef struct {
    1.68 +    uint16_t localTriggerCopy;
    1.69 +    lossyCom__endpointID_t endpointID;
    1.70 +    lossyCom__exchange_t* centralExchangePtr;
    1.71 +    lossyCom__msgHandler* msgHandler;
    1.72 +} lossyCom__endpoint_t;
    1.73 +
    1.74 +/***********************************
    1.75 + * Function Declarations
    1.76 + ***********************************/
    1.77 +
    1.78 +lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
    1.79 +
    1.80 +void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
    1.81 +                                   lossyCom__exchange_t* exchange,
    1.82 +                                   lossyCom__endpointID_t endpointID,
    1.83 +                                   lossyCom__msgHandler* msgHandler);
    1.84 +
    1.85 +void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
    1.86 +                            lossyCom__msgBody_t msg);
    1.87 +
    1.88 +void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,
    1.89 +                       lossyCom__endpointID_t receiverEndpointID,
    1.90 +                       lossyCom__msgBody_t msg);
    1.91 +
    1.92 +void lossyCom__receiveMsg(lossyCom__endpoint_t* localEndpoint);
    1.93 \ No newline at end of file