mac_rx.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /**************************************************************************************************
  2. Filename: mac_rx.c
  3. Revised: $Date: 2007-10-08 14:05:36 -0700 (Mon, 08 Oct 2007) $
  4. Revision: $Revision: 15624 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-2009 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. /* ------------------------------------------------------------------------------------------------
  34. * Includes
  35. * ------------------------------------------------------------------------------------------------
  36. */
  37. /* hal */
  38. #include "hal_defs.h"
  39. #include "hal_types.h"
  40. /* high-level */
  41. #include "mac_high_level.h"
  42. #include "mac_spec.h"
  43. /* exported low-level */
  44. #include "mac_low_level.h"
  45. /* low-level specific */
  46. #include "mac_rx.h"
  47. #include "mac_tx.h"
  48. #include "mac_rx_onoff.h"
  49. #include "mac_radio.h"
  50. /* target specific */
  51. #include "mac_radio_defs.h"
  52. #include "mac_autopend.h"
  53. /* debug */
  54. #include "mac_assert.h"
  55. /* ------------------------------------------------------------------------------------------------
  56. * Defines
  57. * ------------------------------------------------------------------------------------------------
  58. */
  59. #define MAX_PAYLOAD_BYTES_READ_PER_INTERRUPT 16 /* adjustable to tune performance */
  60. /* receive FIFO bytes needed to start a valid receive (see function rxStartIsr for details) */
  61. #define RX_THRESHOLD_START_LEN (MAC_PHY_PHR_LEN + \
  62. MAC_FCF_FIELD_LEN + \
  63. MAC_SEQ_NUM_FIELD_LEN + \
  64. MAC_FCS_FIELD_LEN)
  65. /* maximum size of addressing fields (note: command frame identifier processed as part of address) */
  66. #define MAX_ADDR_FIELDS_LEN ((MAC_EXT_ADDR_FIELD_LEN + MAC_PAN_ID_FIELD_LEN) * 2)
  67. /* addressing mode reserved value */
  68. #define ADDR_MODE_RESERVERED 1
  69. /* length of command frame identifier */
  70. #define CMD_FRAME_ID_LEN 1
  71. /* packet size mask is equal to the maximum value */
  72. #define PHY_PACKET_SIZE_MASK 0x7F
  73. /* value for promiscuous off, must not conflict with other mode variants from separate include files */
  74. #define PROMISCUOUS_MODE_OFF 0x00
  75. /* bit of proprietary FCS format that indicates if the CRC is OK */
  76. #define PROPRIETARY_FCS_CRC_OK_BIT 0x80
  77. /* dummy length value for unused entry in lookup table */
  78. #define DUMMY_LEN 0xBE
  79. /* value for rxThresholdIntState */
  80. #define RX_THRESHOLD_INT_STATE_INACTIVE 0
  81. #define RX_THRESHOLD_INT_STATE_ACTIVE 1
  82. #define RX_THRESHOLD_INT_STATE_RESET 2
  83. /* ------------------------------------------------------------------------------------------------
  84. * Macros
  85. * ------------------------------------------------------------------------------------------------
  86. */
  87. #define MEM_ALLOC(x) macDataRxMemAlloc(x)
  88. #define MEM_FREE(x) macDataRxMemFree((uint8 *)x)
  89. /*
  90. * Macro for encoding frame control information into internal flags format.
  91. * Parameter is pointer to the frame. NOTE! If either the internal frame
  92. * format *or* the specification changes, this macro will need to be modified.
  93. */
  94. #define INTERNAL_FCF_FLAGS(p) ((((p)[1] >> 4) & 0x03) | ((p)[0] & 0x78))
  95. /*
  96. * The radio replaces the actual FCS with different information. This proprietary FCS is
  97. * the same length as the original and includes:
  98. * 1) the RSSI value
  99. * 2) the average correlation value (used for LQI)
  100. * 3) a CRC passed bit
  101. *
  102. * These macros decode the proprietary FCS. The macro parameter is a pointer to the two byte FCS.
  103. */
  104. #define PROPRIETARY_FCS_RSSI(p) ((int8)((p)[0]))
  105. #define PROPRIETARY_FCS_CRC_OK(p) ((p)[1] & PROPRIETARY_FCS_CRC_OK_BIT)
  106. #define PROPRIETARY_FCS_CORRELATION_VALUE(p) ((p)[1] & ~PROPRIETARY_FCS_CRC_OK_BIT)
  107. /* ------------------------------------------------------------------------------------------------
  108. * Global Variables
  109. * ------------------------------------------------------------------------------------------------
  110. */
  111. uint8 macRxActive;
  112. uint8 macRxFilter;
  113. uint8 macRxOutgoingAckFlag;
  114. /* ------------------------------------------------------------------------------------------------
  115. * Local Constants
  116. * ------------------------------------------------------------------------------------------------
  117. */
  118. static const uint8 CODE macRxAddrLen[] =
  119. {
  120. 0, /* no address */
  121. DUMMY_LEN, /* reserved */
  122. MAC_PAN_ID_FIELD_LEN + MAC_SHORT_ADDR_FIELD_LEN, /* short address + pan id */
  123. MAC_PAN_ID_FIELD_LEN + MAC_EXT_ADDR_FIELD_LEN /* extended address + pan id */
  124. };
  125. /* ------------------------------------------------------------------------------------------------
  126. * Local Prototypes
  127. * ------------------------------------------------------------------------------------------------
  128. */
  129. static void rxHaltCleanupFinalStep(void);
  130. static void rxStartIsr(void);
  131. static void rxAddrIsr(void);
  132. static void rxPayloadIsr(void);
  133. static void rxDiscardIsr(void);
  134. static void rxFcsIsr(void);
  135. static void rxPrepPayload(void);
  136. static void rxDiscardFrame(void);
  137. static void rxDone(void);
  138. static void rxPostRxUpdates(void);
  139. /* ------------------------------------------------------------------------------------------------
  140. * Local Variables
  141. * ------------------------------------------------------------------------------------------------
  142. */
  143. static void (* pFuncRxState)(void);
  144. static macRx_t * pRxBuf;
  145. static uint8 rxBuf[MAC_PHY_PHR_LEN + MAC_FCF_FIELD_LEN + MAC_SEQ_NUM_FIELD_LEN];
  146. static uint8 rxUnreadLen;
  147. static uint8 rxNextLen;
  148. static uint8 rxPayloadLen;
  149. static uint8 rxFilter;
  150. static uint8 rxPromiscuousMode;
  151. static uint8 rxIsrActiveFlag;
  152. static uint8 rxResetFlag;
  153. static uint8 rxFifoOverflowCount;
  154. /**************************************************************************************************
  155. * @fn macRxInit
  156. *
  157. * @brief Initialize receive variable states.
  158. *
  159. * @param none
  160. *
  161. * @return none
  162. **************************************************************************************************
  163. */
  164. void macRxInit(void)
  165. {
  166. macRxFilter = RX_FILTER_OFF;
  167. rxPromiscuousMode = PROMISCUOUS_MODE_OFF;
  168. pRxBuf = NULL; /* required for macRxReset() to function correctly */
  169. macRxActive = MAC_RX_ACTIVE_NO_ACTIVITY;
  170. pFuncRxState = &rxStartIsr;
  171. macRxOutgoingAckFlag = 0;
  172. rxIsrActiveFlag = 0;
  173. rxResetFlag = 0;
  174. rxFifoOverflowCount = 0;
  175. }
  176. /**************************************************************************************************
  177. * @fn macRxRadioPowerUpInit
  178. *
  179. * @brief Initialization for after radio first powers up.
  180. *
  181. * @param none
  182. *
  183. * @return none
  184. **************************************************************************************************
  185. */
  186. void macRxRadioPowerUpInit(void)
  187. {
  188. /* set threshold at initial value */
  189. MAC_RADIO_SET_RX_THRESHOLD(RX_THRESHOLD_START_LEN);
  190. /* clear any accidental threshold interrupt that happened as part of power up sequence */
  191. MAC_RADIO_CLEAR_RX_THRESHOLD_INTERRUPT_FLAG();
  192. /* enable threshold interrupts */
  193. MAC_RADIO_ENABLE_RX_THRESHOLD_INTERRUPT();
  194. }
  195. /**************************************************************************************************
  196. * @fn macRxTxReset
  197. *
  198. * @brief Reset the receive state.
  199. *
  200. * @param none
  201. *
  202. * @return none
  203. **************************************************************************************************
  204. */
  205. void macRxTxReset(void)
  206. {
  207. /* forces receiver off, cleans up by calling macRxHaltCleanup() and macTxHaltCleanup() */
  208. macRxHardDisable();
  209. /*
  210. * Note : transmit does not require any reset logic
  211. * beyond what macRxHardDisable() provides.
  212. */
  213. /* restore deault filter mode to off */
  214. macRxFilter = RX_FILTER_OFF;
  215. /* return promiscuous mode to default off state */
  216. macRxPromiscuousMode(MAC_PROMISCUOUS_MODE_OFF);
  217. }
  218. /**************************************************************************************************
  219. * @fn macRxHaltCleanup
  220. *
  221. * @brief Cleanup up the receive logic after receiver is forced off.
  222. *
  223. * @param none
  224. *
  225. * @return none
  226. **************************************************************************************************
  227. */
  228. void macRxHaltCleanup(void)
  229. {
  230. rxResetFlag = 1;
  231. if (!rxIsrActiveFlag)
  232. {
  233. rxHaltCleanupFinalStep();
  234. rxResetFlag = 0;
  235. }
  236. }
  237. /*=================================================================================================
  238. * @fn rxHaltCleanupFinalStep
  239. *
  240. * @brief Required cleanup if receiver is halted in the middle of a receive.
  241. *
  242. * @param none
  243. *
  244. * @return none
  245. *=================================================================================================
  246. */
  247. static void rxHaltCleanupFinalStep(void)
  248. {
  249. /* cancel any upcoming ACK transmit complete callback */
  250. MAC_RADIO_CANCEL_ACK_TX_DONE_CALLBACK();
  251. /* set start of frame threshold */
  252. MAC_RADIO_SET_RX_THRESHOLD(RX_THRESHOLD_START_LEN);
  253. /* flush the receive FIFO */
  254. MAC_RADIO_FLUSH_RX_FIFO();
  255. /* clear any receive interrupt that happened to squeak through */
  256. MAC_RADIO_CLEAR_RX_THRESHOLD_INTERRUPT_FLAG();
  257. /* if data buffer has been allocated, free it */
  258. if (pRxBuf != NULL)
  259. {
  260. MEM_FREE((uint8 *) pRxBuf);
  261. }
  262. pRxBuf = NULL; /* needed to indicate buffer is no longer allocated */
  263. pFuncRxState = &rxStartIsr;
  264. /* if receive was active, perform the post receive updates */
  265. if (macRxActive || macRxOutgoingAckFlag)
  266. {
  267. macRxActive = MAC_RX_ACTIVE_NO_ACTIVITY;
  268. macRxOutgoingAckFlag = 0;
  269. rxPostRxUpdates();
  270. }
  271. }
  272. /**************************************************************************************************
  273. * @fn macRxThresholdIsr
  274. *
  275. * @brief Interrupt service routine called when bytes in FIFO reach threshold value.
  276. * It implements a state machine for receiving a packet.
  277. *
  278. * @param none
  279. *
  280. * @return none
  281. **************************************************************************************************
  282. */
  283. void macRxThresholdIsr(void)
  284. {
  285. /* if currently reseting, do not execute receive ISR logic */
  286. if (rxResetFlag)
  287. {
  288. return;
  289. }
  290. /*
  291. * Call the function that handles the current receive state.
  292. * A flag is set for the duration of the call to indicate
  293. * the ISR is executing. This is necessary for the reset
  294. * logic so it does not perform a reset in the middle of
  295. * executing the ISR.
  296. */
  297. rxIsrActiveFlag = 1;
  298. (*pFuncRxState)();
  299. rxIsrActiveFlag = 0;
  300. /* if a reset occurred during the ISR, peform cleanup here */
  301. if (rxResetFlag)
  302. {
  303. rxHaltCleanupFinalStep();
  304. rxResetFlag = 0;
  305. }
  306. }
  307. /*=================================================================================================
  308. * @fn rxStartIsr
  309. *
  310. * @brief First ISR state for receiving a packet - compute packet length, allocate
  311. * buffer, initialize buffer. Acknowledgements are handled immediately without
  312. * allocating a buffer.
  313. *
  314. * @param none
  315. *
  316. * @return none
  317. *=================================================================================================
  318. */
  319. static void rxStartIsr(void)
  320. {
  321. uint8 addrLen;
  322. uint8 ackWithPending;
  323. uint8 dstAddrMode;
  324. uint8 srcAddrMode;
  325. MAC_ASSERT(!macRxActive); /* receive on top of receive */
  326. /* indicate rx is active */
  327. macRxActive = MAC_RX_ACTIVE_STARTED;
  328. /*
  329. * For bullet proof functionality, need to see if the receiver was just turned off.
  330. * The logic to request turning off the receiver, disables interrupts and then checks
  331. * the value of macRxActive. If it is TRUE, the receiver will not be turned off.
  332. *
  333. * There is a small hole though. It's possible to attempt turning off the receiver
  334. * in the window from when the receive interrupt fires and the point where macRxActive
  335. * is set to TRUE. To plug this hole, the on/off status must be tested *after*
  336. * macRxActive has been set. If the receiver is off at this point, there is nothing
  337. * in the RX fifo and the receive is simply aborted.
  338. *
  339. * Also, there are some considerations in case a hard disable just happened. Usually,
  340. * the receiver will just be off at this point after a hard disable. The check described
  341. * above will account for this case too. However, if a hard disable were immediately
  342. * followed by an enable, the receiver would be on. To catch this case, the receive
  343. * FIFO is also tested to see if it is empty. Recovery is identical to the other cases.
  344. */
  345. if (!macRxOnFlag || MAC_RADIO_RX_FIFO_IS_EMPTY())
  346. {
  347. /* reset active flag */
  348. macRxActive = MAC_RX_ACTIVE_NO_ACTIVITY;
  349. /*
  350. * To be absolutely bulletproof, must make sure no transmit queue'ed up during
  351. * the tiny, tiny window when macRxActive was not zero.
  352. */
  353. rxPostRxUpdates();
  354. /* return immediately from here */
  355. return;
  356. }
  357. /*
  358. * If interrupts are held off for too long it's possible the previous "transmit done"
  359. * callback is pending. If this is the case, it needs to be completed before
  360. * continuing with the receive logic.
  361. */
  362. MAC_RADIO_FORCE_TX_DONE_IF_PENDING();
  363. /*
  364. * It's possible receive logic is still waiting for confirmation of an ACK that went out
  365. * for the previous receive. This is OK but the callback needs to be canceled at this point.
  366. * That callback execute receive cleanup logic that will run at the completion
  367. * of *this* receive. Also, it is important the flag for the outgoing ACK to be cleared.
  368. */
  369. MAC_RADIO_CANCEL_ACK_TX_DONE_CALLBACK();
  370. macRxOutgoingAckFlag = 0;
  371. /*
  372. * Make a module-local copy of macRxFilter. This prevents the selected
  373. * filter from changing in the middle of a receive.
  374. */
  375. rxFilter = macRxFilter;
  376. /*-------------------------------------------------------------------------------
  377. * Read initial frame information from FIFO.
  378. *
  379. * This code is not triggered until the following are in the RX FIFO:
  380. * frame length - one byte containing length of MAC frame (excludes this field)
  381. * frame control field - two bytes defining frame type, addressing fields, control flags
  382. * sequence number - one byte unique sequence identifier
  383. * additional two bytes - these bytes are available in case the received frame is an ACK,
  384. * if so, the frame can be verified and responded to immediately,
  385. * if not an ACK, these bytes will be processed normally
  386. */
  387. /* read frame length, frame control field, and sequence number from FIFO */
  388. MAC_RADIO_READ_RX_FIFO(rxBuf, MAC_PHY_PHR_LEN + MAC_FCF_FIELD_LEN + MAC_SEQ_NUM_FIELD_LEN);
  389. /* bytes to read from FIFO equals frame length minus length of MHR fields just read from FIFO */
  390. rxUnreadLen = (rxBuf[0] & PHY_PACKET_SIZE_MASK) - MAC_FCF_FIELD_LEN - MAC_SEQ_NUM_FIELD_LEN;
  391. /*
  392. * Workaround for chip bug #1547. The receive buffer can sometimes be corrupted by hardware.
  393. * This usually occurs under heavy traffic. If a corrupted receive buffer is detected
  394. * the entire receive buffer is flushed.
  395. *
  396. * In the case that this workaround is not needed, an assert is used to make sure the
  397. * receive length field is not corrupted. This is important because a corrupted receive
  398. * length field is utterly fatal and, if not caught here, extremely hard to track down.
  399. */
  400. if (macChipVersion == REV_A)
  401. {
  402. if ((rxUnreadLen > (MAC_A_MAX_PHY_PACKET_SIZE - MAC_FCF_FIELD_LEN - MAC_SEQ_NUM_FIELD_LEN)) ||
  403. (MAC_FRAME_TYPE(&rxBuf[1]) > MAC_FRAME_TYPE_MAX_VALID))
  404. {
  405. MAC_RADIO_FLUSH_RX_FIFO();
  406. rxDone();
  407. return;
  408. }
  409. }
  410. else
  411. {
  412. /* radio supplied a corrupted receive buffer length */
  413. MAC_ASSERT(rxUnreadLen <= (MAC_A_MAX_PHY_PACKET_SIZE - MAC_FCF_FIELD_LEN - MAC_SEQ_NUM_FIELD_LEN));
  414. }
  415. /*-------------------------------------------------------------------------------
  416. * Process ACKs.
  417. *
  418. * If this frame is an ACK, process it immediately and exit from here.
  419. * If this frame is not an ACK and transmit is listening for an ACK, let
  420. * the transmit logic know an non-ACK was received so transmit can complete.
  421. *
  422. * In promiscuous mode ACKs are treated like any other frame.
  423. */
  424. if ((MAC_FRAME_TYPE(&rxBuf[1]) == MAC_FRAME_TYPE_ACK) && (rxPromiscuousMode == PROMISCUOUS_MODE_OFF))
  425. {
  426. halIntState_t s;
  427. uint8 fcsBuf[MAC_FCF_FIELD_LEN];
  428. /*
  429. * There are guaranteed to be two unread bytes in the FIFO. By defintion, for ACK frames
  430. * these two bytes will be the FCS.
  431. */
  432. /* read FCS from FIFO (threshold set so bytes are guaranteed to be there) */
  433. MAC_RADIO_READ_RX_FIFO(fcsBuf, MAC_FCS_FIELD_LEN);
  434. /*
  435. * This critical section ensures that the ACK timeout won't be triggered in the
  436. * millde of receiving the ACK frame.
  437. */
  438. HAL_ENTER_CRITICAL_SECTION(s);
  439. /* see if transmit is listening for an ACK */
  440. if (macTxActive == MAC_TX_ACTIVE_LISTEN_FOR_ACK)
  441. {
  442. MAC_ASSERT(pMacDataTx != NULL); /* transmit buffer must be present */
  443. /* record link quality metrics for the receive ACK */
  444. {
  445. int8 rssiDbm;
  446. uint8 corr;
  447. rssiDbm = PROPRIETARY_FCS_RSSI(fcsBuf) + MAC_RADIO_RSSI_OFFSET;
  448. #if defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  449. MAC_RADIO_RSSI_LNA_OFFSET(rssiDbm);
  450. #endif
  451. corr = PROPRIETARY_FCS_CORRELATION_VALUE(fcsBuf);
  452. pMacDataTx->internal.mpduLinkQuality = macRadioComputeLQI(rssiDbm, corr);
  453. pMacDataTx->internal.correlation = corr;
  454. pMacDataTx->internal.rssi= rssiDbm;
  455. }
  456. /*
  457. * It's okay if the ACK timeout is triggered here. The callbacks for ACK received
  458. * or ACK not received will check "macTxActive" flag before taking any actions.
  459. */
  460. HAL_EXIT_CRITICAL_SECTION(s);
  461. /*
  462. * An ACK was received so transmit logic needs to know. If the FCS failed,
  463. * the transmit logic still needs to know. In that case, treat the frame
  464. * as a non-ACK to complete the active transmit.
  465. */
  466. if (PROPRIETARY_FCS_CRC_OK(fcsBuf))
  467. {
  468. /* call transmit logic to indicate ACK was received */
  469. macTxAckReceivedCallback(MAC_SEQ_NUMBER(&rxBuf[1]), MAC_FRAME_PENDING(&rxBuf[1]));
  470. }
  471. else
  472. {
  473. macTxAckNotReceivedCallback();
  474. }
  475. }
  476. else
  477. {
  478. HAL_EXIT_CRITICAL_SECTION(s);
  479. }
  480. /* receive is done, exit from here */
  481. rxDone();
  482. return;
  483. }
  484. else if (macTxActive == MAC_TX_ACTIVE_LISTEN_FOR_ACK)
  485. {
  486. macTxAckNotReceivedCallback();
  487. }
  488. /*-------------------------------------------------------------------------------
  489. * Apply filtering.
  490. *
  491. * For efficiency, see if filtering is even 'on' before processing. Also test
  492. * to make sure promiscuous mode is disabled. If promiscuous mode is enabled,
  493. * do not apply filtering.
  494. */
  495. if ((rxFilter != RX_FILTER_OFF) && !rxPromiscuousMode)
  496. {
  497. if (/* filter all frames */
  498. (rxFilter == RX_FILTER_ALL) ||
  499. /* filter non-beacon frames */
  500. ((rxFilter == RX_FILTER_NON_BEACON_FRAMES) &&
  501. (MAC_FRAME_TYPE(&rxBuf[1]) != MAC_FRAME_TYPE_BEACON)) ||
  502. /* filter non-command frames */
  503. ((rxFilter == RX_FILTER_NON_COMMAND_FRAMES) &&
  504. ((MAC_FRAME_TYPE(&rxBuf[1]) != MAC_FRAME_TYPE_COMMAND))))
  505. {
  506. /* discard rest of frame */
  507. rxDiscardFrame();
  508. return;
  509. }
  510. }
  511. /*-------------------------------------------------------------------------------
  512. * Compute length of addressing fields. Compute payload length.
  513. */
  514. /* decode addressing modes */
  515. dstAddrMode = MAC_DEST_ADDR_MODE(&rxBuf[1]);
  516. srcAddrMode = MAC_SRC_ADDR_MODE(&rxBuf[1]);
  517. /*
  518. * Workaround for chip bug #1547. The receive buffer can sometimes be corrupted by hardware.
  519. * This usually occurs under heavy traffic. If a corrupted receive buffer is detected
  520. * the entire receive buffer is flushed.
  521. */
  522. if (macChipVersion == REV_A)
  523. {
  524. if ((srcAddrMode == ADDR_MODE_RESERVERED) || (dstAddrMode == ADDR_MODE_RESERVERED))
  525. {
  526. MAC_RADIO_FLUSH_RX_FIFO();
  527. rxDone();
  528. return;
  529. }
  530. }
  531. /*
  532. * Compute the addressing field length. A lookup table based on addressing
  533. * mode is used for efficiency. If the source address is present and the
  534. * frame is intra-PAN, the PAN Id is not repeated. In this case, the address
  535. * length is adjusted to match the smaller length.
  536. */
  537. addrLen = macRxAddrLen[dstAddrMode] + macRxAddrLen[srcAddrMode];
  538. if ((srcAddrMode != SADDR_MODE_NONE) && MAC_INTRA_PAN(&rxBuf[1]))
  539. {
  540. addrLen -= MAC_PAN_ID_FIELD_LEN;
  541. }
  542. /*
  543. * If there are not enough unread bytes to include the computed address
  544. * plus FCS field, the frame is corrupted and must be discarded.
  545. */
  546. if ((addrLen + MAC_FCS_FIELD_LEN) > rxUnreadLen)
  547. {
  548. /* discard frame and exit */
  549. rxDiscardFrame();
  550. return;
  551. }
  552. /* payload length is equal to unread bytes minus address length, minus the FCS */
  553. rxPayloadLen = rxUnreadLen - addrLen - MAC_FCS_FIELD_LEN;
  554. /*-------------------------------------------------------------------------------
  555. * Allocate memory for the incoming frame.
  556. */
  557. pRxBuf = (macRx_t *) MEM_ALLOC(sizeof(macRx_t) + rxPayloadLen);
  558. if (pRxBuf == NULL)
  559. {
  560. /* Cancel the outgoing TX ACK */
  561. MAC_RADIO_CANCEL_TX_ACK();
  562. /* buffer allocation failed, discard the frame and exit*/
  563. rxDiscardFrame();
  564. return;
  565. }
  566. /*-------------------------------------------------------------------------------
  567. * Set up to process ACK request. Do not ACK if in promiscuous mode.
  568. */
  569. ackWithPending = 0;
  570. if (!rxPromiscuousMode)
  571. {
  572. macRxOutgoingAckFlag = MAC_ACK_REQUEST(&rxBuf[1]);
  573. }
  574. /*-------------------------------------------------------------------------------
  575. * Process any ACK request.
  576. */
  577. if (macRxOutgoingAckFlag)
  578. {
  579. halIntState_t s;
  580. /*
  581. * This critical section ensures that the callback ISR is initiated within time
  582. * to guarantee correlation with the strobe.
  583. */
  584. HAL_ENTER_CRITICAL_SECTION(s);
  585. /* Do not ack data packet with pending more data */
  586. if( MAC_FRAME_TYPE(&rxBuf[1]) == MAC_FRAME_TYPE_COMMAND )
  587. {
  588. if( macRxCheckMACPendingCallback())
  589. {
  590. /* Check is any mac data pending for end devices */
  591. ackWithPending = MAC_RX_FLAG_ACK_PENDING;
  592. }
  593. else
  594. {
  595. if( macSrcMatchIsEnabled )
  596. {
  597. /* When autopend is enabled, check if allpending is set to true */
  598. if( MAC_SrcMatchCheckAllPending() == MAC_AUTOACK_PENDING_ALL_ON )
  599. {
  600. ackWithPending = MAC_RX_FLAG_ACK_PENDING;
  601. }
  602. }
  603. else
  604. {
  605. /* When autopend is disabled, check the application pending callback */
  606. if( macRxCheckPendingCallback() )
  607. {
  608. ackWithPending = MAC_RX_FLAG_ACK_PENDING;
  609. }
  610. }
  611. }
  612. }
  613. if( ackWithPending == MAC_RX_FLAG_ACK_PENDING )
  614. {
  615. MAC_RADIO_TX_ACK_PEND();
  616. }
  617. else
  618. {
  619. MAC_RADIO_TX_ACK();
  620. }
  621. /* request a callback to macRxAckTxDoneCallback() when the ACK transmit has finished */
  622. MAC_RADIO_REQUEST_ACK_TX_DONE_CALLBACK();
  623. HAL_EXIT_CRITICAL_SECTION(s);
  624. }
  625. /*-------------------------------------------------------------------------------
  626. * Populate the receive buffer going up to high-level.
  627. */
  628. /* configure the payload buffer */
  629. pRxBuf->msdu.p = (uint8 *) (pRxBuf + 1);
  630. pRxBuf->msdu.len = rxPayloadLen;
  631. /* set internal values */
  632. pRxBuf->mac.srcAddr.addrMode = srcAddrMode;
  633. pRxBuf->mac.dstAddr.addrMode = dstAddrMode;
  634. pRxBuf->mac.timestamp = MAC_RADIO_BACKOFF_CAPTURE();
  635. pRxBuf->mac.timestamp2 = MAC_RADIO_TIMER_CAPTURE();
  636. pRxBuf->internal.frameType = MAC_FRAME_TYPE(&rxBuf[1]);
  637. pRxBuf->mac.dsn = MAC_SEQ_NUMBER(&rxBuf[1]);
  638. pRxBuf->internal.flags = INTERNAL_FCF_FLAGS(&rxBuf[1]) | ackWithPending;
  639. pRxBuf->sec.securityLevel = MAC_SEC_LEVEL_NONE;
  640. /*-------------------------------------------------------------------------------
  641. * If the processing the addressing fields does not require more bytes from
  642. * the FIFO go directly address processing function. Otherwise, configure
  643. * interrupt to jump there once bytes are received.
  644. */
  645. if (addrLen == 0)
  646. {
  647. /* no addressing fields to read, prepare for payload interrupts */
  648. pFuncRxState = &rxPayloadIsr;
  649. rxPrepPayload();
  650. }
  651. else
  652. {
  653. /* need to read and process addressing fields, prepare for address interrupt */
  654. rxNextLen = addrLen;
  655. MAC_RADIO_SET_RX_THRESHOLD(rxNextLen);
  656. pFuncRxState = &rxAddrIsr;
  657. }
  658. }
  659. /*=================================================================================================
  660. * @fn rxAddrIsr
  661. *
  662. * @brief Receive ISR state for decoding address. Reads and stores the address information
  663. * from the incoming packet.
  664. *
  665. * @param none
  666. *
  667. * @return none
  668. *=================================================================================================
  669. */
  670. static void rxAddrIsr(void)
  671. {
  672. uint8 buf[MAX_ADDR_FIELDS_LEN];
  673. uint8 dstAddrMode;
  674. uint8 srcAddrMode;
  675. uint8 * p;
  676. MAC_ASSERT(rxNextLen != 0); /* logic assumes at least one address byte in buffer */
  677. /* read out address fields into local buffer in one shot */
  678. MAC_RADIO_READ_RX_FIFO(buf, rxNextLen);
  679. /* set pointer to buffer with addressing fields */
  680. p = buf;
  681. /* destination address */
  682. dstAddrMode = MAC_DEST_ADDR_MODE(&rxBuf[1]);
  683. if (dstAddrMode != SADDR_MODE_NONE)
  684. {
  685. pRxBuf->mac.srcPanId = pRxBuf->mac.dstPanId = BUILD_UINT16(p[0], p[1]);
  686. p += MAC_PAN_ID_FIELD_LEN;
  687. if (dstAddrMode == SADDR_MODE_EXT)
  688. {
  689. sAddrExtCpy(pRxBuf->mac.dstAddr.addr.extAddr, p);
  690. p += MAC_EXT_ADDR_FIELD_LEN;
  691. }
  692. else
  693. {
  694. pRxBuf->mac.dstAddr.addr.shortAddr = BUILD_UINT16(p[0], p[1]);
  695. p += MAC_SHORT_ADDR_FIELD_LEN;
  696. }
  697. }
  698. /* sources address */
  699. srcAddrMode = MAC_SRC_ADDR_MODE(&rxBuf[1]);
  700. if (srcAddrMode != SADDR_MODE_NONE)
  701. {
  702. if (!(pRxBuf->internal.flags & MAC_RX_FLAG_INTRA_PAN))
  703. {
  704. pRxBuf->mac.srcPanId = BUILD_UINT16(p[0], p[1]);
  705. p += MAC_PAN_ID_FIELD_LEN;
  706. }
  707. if (srcAddrMode == SADDR_MODE_EXT)
  708. {
  709. sAddrExtCpy(pRxBuf->mac.srcAddr.addr.extAddr, p);
  710. }
  711. else
  712. {
  713. pRxBuf->mac.srcAddr.addr.shortAddr = BUILD_UINT16(p[0], p[1]);
  714. }
  715. }
  716. /*-------------------------------------------------------------------------------
  717. * Prepare for payload interrupts.
  718. */
  719. pFuncRxState = &rxPayloadIsr;
  720. rxPrepPayload();
  721. }
  722. /*=================================================================================================
  723. * @fn rxPrepPayload
  724. *
  725. * @brief Common code to prepare for the payload ISR.
  726. *
  727. * @param none
  728. *
  729. * @return none
  730. *=================================================================================================
  731. */
  732. static void rxPrepPayload(void)
  733. {
  734. if (rxPayloadLen == 0)
  735. {
  736. MAC_RADIO_SET_RX_THRESHOLD(MAC_FCS_FIELD_LEN);
  737. pFuncRxState = &rxFcsIsr;
  738. }
  739. else
  740. {
  741. rxNextLen = MIN(rxPayloadLen, MAX_PAYLOAD_BYTES_READ_PER_INTERRUPT);
  742. MAC_RADIO_SET_RX_THRESHOLD(rxNextLen);
  743. }
  744. }
  745. /*=================================================================================================
  746. * @fn rxPayloadIsr
  747. *
  748. * @brief Receive ISR state for reading out and storing the packet payload.
  749. *
  750. * @param none
  751. *
  752. * @return none
  753. *=================================================================================================
  754. */
  755. static void rxPayloadIsr(void)
  756. {
  757. MAC_RADIO_READ_RX_FIFO(pRxBuf->msdu.p, rxNextLen);
  758. pRxBuf->msdu.p += rxNextLen;
  759. rxPayloadLen -= rxNextLen;
  760. rxPrepPayload();
  761. }
  762. /*=================================================================================================
  763. * @fn rxFcsIsr
  764. *
  765. * @brief Receive ISR state for handling the FCS.
  766. *
  767. * @param none
  768. *
  769. * @return none
  770. *=================================================================================================
  771. */
  772. static void rxFcsIsr(void)
  773. {
  774. uint8 crcOK;
  775. uint8 ackWithPending = 0;
  776. /* read FCS, rxBuf is now available storage */
  777. MAC_RADIO_READ_RX_FIFO(rxBuf, MAC_FCS_FIELD_LEN);
  778. /*
  779. * The FCS has actually been replaced within the radio by a proprietary version of the FCS.
  780. * This proprietary FCS is two bytes (same length as the real FCS) and contains:
  781. * 1) the RSSI value
  782. * 2) the average correlation value (used for LQI)
  783. * 3) a CRC passed bit
  784. */
  785. /* save the "CRC-is-OK" status */
  786. crcOK = PROPRIETARY_FCS_CRC_OK(rxBuf);
  787. /*
  788. * See if the frame should be passed up to high-level MAC. If the CRC is OK, the
  789. * the frame is always passed up. Frames with a bad CRC are also passed up *if*
  790. * a special variant of promiscuous mode is active.
  791. */
  792. if (crcOK || (rxPromiscuousMode == MAC_PROMISCUOUS_MODE_WITH_BAD_CRC))
  793. {
  794. int8 rssiDbm;
  795. uint8 corr;
  796. /*
  797. * As power saving optimization, set state variable to indicate physical receive
  798. * has completed and then request turning of the receiver. This means the receiver
  799. * can be off (if other conditions permit) during execution of the callback function.
  800. *
  801. * The receiver will be requested to turn off once again at the end of the receive
  802. * logic. There is no harm in doing this.
  803. */
  804. macRxActive = MAC_RX_ACTIVE_DONE;
  805. macRxOffRequest();
  806. /* decode RSSI and correlation values */
  807. rssiDbm = PROPRIETARY_FCS_RSSI(rxBuf) + MAC_RADIO_RSSI_OFFSET;
  808. #if defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
  809. MAC_RADIO_RSSI_LNA_OFFSET(rssiDbm);
  810. #endif
  811. corr = PROPRIETARY_FCS_CORRELATION_VALUE(rxBuf);
  812. /* Read the source matching result back */
  813. if( macSrcMatchIsEnabled && MAC_RADIO_SRC_MATCH_RESULT() )
  814. {
  815. /* This result will not overwrite the previously determined pRxBuf->internal.flags */
  816. ackWithPending = MAC_RX_FLAG_ACK_PENDING;
  817. }
  818. /* record parameters that get passed up to high-level */
  819. pRxBuf->internal.flags |= ( crcOK | ackWithPending );
  820. pRxBuf->mac.mpduLinkQuality = macRadioComputeLQI(rssiDbm, corr);
  821. pRxBuf->mac.rssi = rssiDbm;
  822. pRxBuf->mac.correlation = corr;
  823. /* set the MSDU pointer to point at start of data */
  824. pRxBuf->msdu.p = (uint8 *) (pRxBuf + 1);
  825. /* finally... execute callback function */
  826. macRxCompleteCallback(pRxBuf);
  827. pRxBuf = NULL; /* needed to indicate buffer is no longer allocated */
  828. }
  829. else
  830. {
  831. /*
  832. * The CRC is bad so no ACK was sent. Cancel any callback and clear the flag.
  833. * (It's OK to cancel the outgoing ACK even if an ACK was not requested. It's
  834. * slightly more efficient to do so.)
  835. */
  836. MAC_RADIO_CANCEL_ACK_TX_DONE_CALLBACK();
  837. macRxOutgoingAckFlag = 0;
  838. /* the CRC failed so the packet must be discarded */
  839. MEM_FREE((uint8 *) pRxBuf);
  840. pRxBuf = NULL; /* needed to indicate buffer is no longer allocated */
  841. }
  842. /* reset threshold level, reset receive state, and complete receive logic */
  843. MAC_RADIO_SET_RX_THRESHOLD(RX_THRESHOLD_START_LEN);
  844. pFuncRxState = &rxStartIsr;
  845. rxDone();
  846. }
  847. /*=================================================================================================
  848. * @fn rxDone
  849. *
  850. * @brief Common exit point for receive.
  851. *
  852. * @param none
  853. *
  854. * @return none
  855. *=================================================================================================
  856. */
  857. static void rxDone(void)
  858. {
  859. /* if the receive FIFO has overflowed, flush it here */
  860. if (MAC_RADIO_RX_FIFO_HAS_OVERFLOWED())
  861. {
  862. MAC_RADIO_FLUSH_RX_FIFO();
  863. }
  864. /* mark receive as inactive */
  865. macRxActive = MAC_RX_ACTIVE_NO_ACTIVITY;
  866. /* if there is no outgoing ACK, run the post receive updates */
  867. if (!macRxOutgoingAckFlag)
  868. {
  869. rxPostRxUpdates();
  870. }
  871. }
  872. /**************************************************************************************************
  873. * @fn macRxAckTxDoneCallback
  874. *
  875. * @brief Function called when the outoing ACK has completed transmitting.
  876. *
  877. * @param none
  878. *
  879. * @return none
  880. **************************************************************************************************
  881. */
  882. void macRxAckTxDoneCallback(void)
  883. {
  884. macRxOutgoingAckFlag = 0;
  885. /*
  886. * With certain interrupt priorities and timing conditions, it is possible this callback
  887. * could be executed before the primary receive logic completes. To prevent this, the
  888. * post updates are only executed if receive logic is no longer active. In the case the
  889. * post updates are not executed here, they will execute when the main receive logic
  890. * completes.
  891. */
  892. if (!macRxActive)
  893. {
  894. rxPostRxUpdates();
  895. }
  896. }
  897. /*=================================================================================================
  898. * @fn rxPostRxUpdates
  899. *
  900. * @brief Updates that need to be performed once receive is complete.
  901. *
  902. * It is not fatal to execute this function if somehow receive is active. Under
  903. * certain timing/interrupt conditions a new receive may have started before this
  904. * function executes. This should happen very rarely (if it happens at all) and
  905. * would cause no problems.
  906. *
  907. * @param none
  908. *
  909. * @return none
  910. *=================================================================================================
  911. */
  912. static void rxPostRxUpdates(void)
  913. {
  914. /* turn off receiver if permitted */
  915. macRxOffRequest();
  916. /* update the transmit power, update may have been blocked by transmit of outgoing ACK */
  917. macRadioUpdateTxPower();
  918. /* initiate and transmit that was queued during receive */
  919. macTxStartQueuedFrame();
  920. }
  921. /*=================================================================================================
  922. * @fn rxDiscardFrame
  923. *
  924. * @brief Initializes for discarding a packet. Must be called before ACK is strobed.
  925. *
  926. * @param none
  927. *
  928. * @return none
  929. *=================================================================================================
  930. */
  931. static void rxDiscardFrame(void)
  932. {
  933. MAC_ASSERT(pFuncRxState == &rxStartIsr); /* illegal state for calling discard frame function */
  934. if (rxUnreadLen == 0)
  935. {
  936. rxDone();
  937. }
  938. else
  939. {
  940. rxNextLen = MIN(rxUnreadLen, MAX_PAYLOAD_BYTES_READ_PER_INTERRUPT);
  941. MAC_RADIO_SET_RX_THRESHOLD(rxNextLen);
  942. pFuncRxState = &rxDiscardIsr;
  943. }
  944. }
  945. /*=================================================================================================
  946. * @fn rxDiscardIsr
  947. *
  948. * @brief Receive ISR state for discarding a packet.
  949. *
  950. * @param none
  951. *
  952. * @return none
  953. *=================================================================================================
  954. */
  955. static void rxDiscardIsr(void)
  956. {
  957. uint8 buf[MAX_PAYLOAD_BYTES_READ_PER_INTERRUPT];
  958. MAC_RADIO_READ_RX_FIFO(buf, rxNextLen);
  959. rxUnreadLen -= rxNextLen;
  960. /* read out and discard bytes until all bytes of packet are disposed of */
  961. if (rxUnreadLen != 0)
  962. {
  963. if (rxUnreadLen < MAX_PAYLOAD_BYTES_READ_PER_INTERRUPT)
  964. {
  965. rxNextLen = rxUnreadLen;
  966. MAC_RADIO_SET_RX_THRESHOLD(rxNextLen);
  967. }
  968. }
  969. else
  970. {
  971. /* reset threshold level, reset receive state, and complete receive logic */
  972. MAC_RADIO_SET_RX_THRESHOLD(RX_THRESHOLD_START_LEN);
  973. pFuncRxState = &rxStartIsr;
  974. rxDone();
  975. }
  976. }
  977. /**************************************************************************************************
  978. * @fn maxRxRifoOverflowIsr
  979. *
  980. * @brief This interrupt service routine is called when RX FIFO overflow. Note that this
  981. * exception does not retrieve the good frames that are trapped in the RX FIFO.
  982. * It simply halts and cleanup the RX.
  983. *
  984. * @param none
  985. *
  986. * @return none
  987. **************************************************************************************************
  988. */
  989. void macRxFifoOverflowIsr(void)
  990. {
  991. rxFifoOverflowCount++; /* This flag is used for debug purpose only */
  992. macRxOff();
  993. macRxHaltCleanup();
  994. macRxOnRequest();
  995. }
  996. /**************************************************************************************************
  997. * @fn macRxPromiscuousMode
  998. *
  999. * @brief Sets promiscuous mode - enabling or disabling it.
  1000. *
  1001. * @param none
  1002. *
  1003. * @return none
  1004. **************************************************************************************************
  1005. */
  1006. void macRxPromiscuousMode(uint8 mode)
  1007. {
  1008. rxPromiscuousMode = mode;
  1009. if (rxPromiscuousMode == MAC_PROMISCUOUS_MODE_OFF)
  1010. {
  1011. MAC_RADIO_TURN_ON_RX_FRAME_FILTERING();
  1012. }
  1013. else
  1014. {
  1015. MAC_ASSERT((mode == MAC_PROMISCUOUS_MODE_WITH_BAD_CRC) ||
  1016. (mode == MAC_PROMISCUOUS_MODE_COMPLIANT)); /* invalid mode */
  1017. MAC_RADIO_TURN_OFF_RX_FRAME_FILTERING();
  1018. }
  1019. }
  1020. /**************************************************************************************************
  1021. * Compile Time Integrity Checks
  1022. **************************************************************************************************
  1023. */
  1024. /* check for changes to the spec that would affect the source code */
  1025. #if ((MAC_A_MAX_PHY_PACKET_SIZE != 0x7F ) || \
  1026. (MAC_FCF_FIELD_LEN != 2 ) || \
  1027. (MAC_FCF_FRAME_TYPE_POS != 0 ) || \
  1028. (MAC_FCF_FRAME_PENDING_POS != 4 ) || \
  1029. (MAC_FCF_ACK_REQUEST_POS != 5 ) || \
  1030. (MAC_FCF_INTRA_PAN_POS != 6 ) || \
  1031. (MAC_FCF_DST_ADDR_MODE_POS != 10 ) || \
  1032. (MAC_FCF_FRAME_VERSION_POS != 12 ) || \
  1033. (MAC_FCF_SRC_ADDR_MODE_POS != 14 ))
  1034. #error "ERROR! Change to the spec that requires modification of source code."
  1035. #endif
  1036. /* check for changes to the internal flags format */
  1037. #if ((MAC_RX_FLAG_VERSION != 0x03) || \
  1038. (MAC_RX_FLAG_ACK_PENDING != 0x04) || \
  1039. (MAC_RX_FLAG_SECURITY != 0x08) || \
  1040. (MAC_RX_FLAG_PENDING != 0x10) || \
  1041. (MAC_RX_FLAG_ACK_REQUEST != 0x20) || \
  1042. (MAC_RX_FLAG_INTRA_PAN != 0x40))
  1043. #error "ERROR! Change to the internal RX flags format. Requires modification of source code."
  1044. #endif
  1045. /* validate CRC OK bit optimization */
  1046. #if (MAC_RX_FLAG_CRC_OK != PROPRIETARY_FCS_CRC_OK_BIT)
  1047. #error "ERROR! Optimization relies on these bits having the same position."
  1048. #endif
  1049. #if (MAC_RX_ACTIVE_NO_ACTIVITY != 0x00)
  1050. #error "ERROR! Zero is reserved value of macRxActive. Allows boolean operations, e.g !macRxActive."
  1051. #endif
  1052. #if (MAC_PROMISCUOUS_MODE_OFF != 0x00)
  1053. #error "ERROR! Zero is reserved value of rxPromiscuousMode. Allows boolean operations, e.g !rxPromiscuousMode."
  1054. #endif
  1055. /**************************************************************************************************
  1056. */