X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=tos%2Flib%2Fmac%2Ftkn154%2FTKN154_MAC.h;h=f1e301ed75bf685195215603987764f5d175e93e;hp=8edccc00a2a163541aadc1eafaa3e26d020eb88e;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400 diff --git a/tos/lib/mac/tkn154/TKN154_MAC.h b/tos/lib/mac/tkn154/TKN154_MAC.h index 8edccc00..f1e301ed 100644 --- a/tos/lib/mac/tkn154/TKN154_MAC.h +++ b/tos/lib/mac/tkn154/TKN154_MAC.h @@ -37,6 +37,7 @@ #include "TKN154.h" #include "TKN154_PHY.h" +#include "TKN154_platform.h" /**************************************************** * IEEE 802.15.4 PAN information base identifiers @@ -74,9 +75,7 @@ enum { IEEE154_macMaxFrameTotalWaitTime = 0x58, IEEE154_macMaxFrameRetries = 0x59, IEEE154_macMinBE = 0x4F, -// no identifier defined in standard IEEE154_macMinLIFSPeriod = 0xA0, -// no identifier defined in standard IEEE154_macMinSIFSPeriod = 0xA1, IEEE154_macPANId = 0x50, IEEE154_macPromiscuousMode = 0x51, @@ -89,7 +88,7 @@ enum { IEEE154_macTimestampSupported = 0x5C, IEEE154_macTransactionPersistenceTime = 0x55, -// attributes not present in the standard PIB: + // custom attributes (not present in the standard PIB) IEEE154_macPanCoordinator = 0xF0, }; @@ -128,15 +127,57 @@ enum { FC2_FRAME_VERSION_MASK = 0x30, }; +/** some unique strings */ +#define SYNC_POLL_CLIENT unique("PollP.client") +#define ASSOCIATE_POLL_CLIENT unique("PollP.client") #define CAP_TX_CLIENT "CapQueueP.FrameTx.client" #define INDIRECT_TX_CLIENT "IndirectTx.client" #define IEEE802154_RADIO_RESOURCE "RadioRxTxP.resource" enum { + // The following identfiers map to components that access the radio + // via RadioClientC(). They are used as parameters for RadioClientC(), + // the TransferableResource.transferTo() command and in + // the TransferableResource.transferredFrom() event + + RADIO_CLIENT_SCAN = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_PIB = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_PROMISCUOUSMODE = unique(IEEE802154_RADIO_RESOURCE), + + RADIO_CLIENT_BEACONTRANSMIT = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_COORDBROADCAST = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_COORDCAP = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_COORDCFP = unique(IEEE802154_RADIO_RESOURCE), + + RADIO_CLIENT_BEACONSYNCHRONIZE = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_DEVICECAP = unique(IEEE802154_RADIO_RESOURCE), + RADIO_CLIENT_DEVICECFP = unique(IEEE802154_RADIO_RESOURCE), +}; + +enum { + // parameter for the generic DispatchSlottedCsmaP OUTGOING_SUPERFRAME, INCOMING_SUPERFRAME, }; +/**************************************************** + * Default time-related constants for beacon-enabled PANs, + * these may be overridden by platform-specific constants. + * */ + +#ifndef IEEE154_MAX_BEACON_JITTER + // will start to listen for a beacon MAX_BEACON_JITTER_TIME(BO) symbols + // before its expected arrival, where BO is the current beacon order + // (here --by default-- BO is ignored) + #define IEEE154_MAX_BEACON_JITTER(BO) 20 +#endif + +#ifndef IEEE154_MAX_BEACON_LISTEN_TIME + // maximum time to listen for a beacon after its expected arrival, + // before it is declared as missed + #define IEEE154_MAX_BEACON_LISTEN_TIME(BO) (128 * IEEE154_SYMBOLS_PER_OCTET + IEEE154_MAX_BEACON_JITTER(BO)) +#endif + typedef struct { uint8_t length; // top bit denotes -> promiscuous mode uint8_t mhr[MHR_MAX_LEN]; @@ -165,15 +206,16 @@ typedef struct ieee154_metadata_t metadata; } ieee154_txcontrol_t; +typedef struct ieee154_csma { + uint8_t BE; // initial backoff exponent + uint8_t macMaxBE; // maximum backoff exponent + uint8_t macMaxCsmaBackoffs; // maximum number of allowed backoffs + uint8_t NB; // number of backoff during current transmission +} ieee154_csma_t; + typedef struct { ieee154_txframe_t *frame; - ieee154_macMaxBE_t BE; - ieee154_macMaxCSMABackoffs_t allowedBackoffs; - ieee154_macMaxBE_t macMaxBE; - ieee154_macMinBE_t macMinBE; - uint8_t NB; - uint16_t backoff; - uint16_t backoffElapsed; + ieee154_csma_t csma; uint32_t transactionTime; } ieee154_cap_frame_backup_t; @@ -198,10 +240,19 @@ enum { BEACON_INDEX_SF_SPEC2 = 1, BEACON_INDEX_GTS_SPEC = 2, + SF_SPEC1_BO_MASK = 0x0F, + SF_SPEC1_BO_OFFSET = 0, + SF_SPEC1_SO_MASK = 0xF0, + SF_SPEC1_SO_OFFSET = 4, + + SF_SPEC2_FINAL_CAPSLOT_MASK = 0x0F, + SF_SPEC2_FINAL_CAPSLOT_OFFSET = 0, + SF_SPEC2_BATT_LIFE_EXT = 0x10, SF_SPEC2_PAN_COORD = 0x40, SF_SPEC2_ASSOCIATION_PERMIT = 0x80, GTS_DESCRIPTOR_COUNT_MASK = 0x07, + GTS_DESCRIPTOR_COUNT_OFFSET = 0, GTS_LENGTH_MASK = 0xF0, GTS_LENGTH_OFFSET = 4, GTS_SPEC_PERMIT = 0x80, @@ -214,8 +265,8 @@ enum { // PHY sublayer constants IEEE154_aTurnaroundTime = 12, - FRAMECTL_LENGTH_MASK = 0x7F, // "length" member in ieee154_frame_t - FRAMECTL_PROMISCUOUS = 0x80, // "length" member in ieee154_frame_t + FRAMECTL_LENGTH_MASK = 0x7F, // "length" member in ieee154_header_t + FRAMECTL_PROMISCUOUS = 0x80, // "length" member in ieee154_header_t }; #define IEEE154_SUPPORTED_CHANNELPAGE (IEEE154_SUPPORTED_CHANNELS >> 27) @@ -237,5 +288,61 @@ enum { IEEE154_aUnitBackoffPeriod = 20, }; +// combine function for IsRadioTokenRequested (GetNow) interface +typedef bool token_requested_t __attribute__((combine(rcombine))); +token_requested_t rcombine(token_requested_t r1, token_requested_t r2) +{ + return r1 || r2; +} + +#ifdef TKN154_DEBUG + + /****************************************************************** + * ATTENTION! Debugging over serial is a lot of overhead. To + * keep it simple, here are the rules you have to follow when + * using the dbg_serial() macro: + * + * - dbg_serial() is used like dbg(), i.e. you pass it at least + * two strings, the first one describing the component/file, + * the second is a format string (like in printf()) + * - following the second string, there may be zero up to + * two parameters -- these must be (cast to) uint32_t and + * the format specifier must be "%lu", e.g. + * dbg_serial("MyComponentP", "Value: %lu\n", (uint32_t) val); + * - both strings must be constants (pointers always valid) + * - no data is sent over serial, unless dbg_serial_flush() is + * called; try to call it when the system is idle or at least + * when no time-critical operations are pending; on TelosB + * you can also press the user button to trigger a flush + * - on the PC use the printf java client to display the debug + * output (see tinyos-2.x/apps/tests/TestPrintf/README.txt); + * the output format is component:line-in-source-code:text + * + * The ASSERT(X) macro is used to test for errors. If X evaluates + * to zero, then 3 leds start blinking simulataneously (about 2Hz) + * and the node *continuously* outputs over serial the filename/line + * where the (first) ASSERT has failed. This means, even if your + * TelosB was not attached to your PC while the ASSERT failed you + * can typically still pull the information out later. + * + * When TKN154_DEBUG is not defined (which is the default), then + * dbg_serial() maps to dbg(), i.e. is completely removed unless + * the platform is TOSSIM, and in the ASSERT(X) statement X is + * evaluated/executed, but the result is ignored. + **/ + + /* -> functions are defined in DebugP.nc */ + void tkn154_assert(bool val, const char *filename, uint16_t line, const char *func); + void tkn154_dbg_serial(const char *filename, uint16_t line, ...); + void tkn154_dbg_serial_flush(); + #define ASSERT(X) tkn154_assert(X, __FILE__,__LINE__,__FUNCTION__) + #define dbg_serial(m, ...) tkn154_dbg_serial(m, __LINE__,__VA_ARGS__) + #define dbg_serial_flush() tkn154_dbg_serial_flush() +#else + // Note: in an ASSERT(X) the X must always be evaluated/executed! + #define ASSERT(X) while(!(X)){ break;} + #define dbg_serial(m, ...) dbg(m, __VA_ARGS__) + #define dbg_serial_flush() +#endif #endif // __TKN154_MAC_H