mac_rx_onoff.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /**************************************************************************************************
  2. Filename: mac_rx_onoff.c
  3. Revised: $Date: 2007-09-11 10:58:41 -0700 (Tue, 11 Sep 2007) $
  4. Revision: $Revision: 15371 $
  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. /* exported low-level */
  41. #include "mac_low_level.h"
  42. /* low-level specific */
  43. #include "mac_rx_onoff.h"
  44. #include "mac_rx.h"
  45. #include "mac_tx.h"
  46. /* target specific */
  47. #include "mac_radio_defs.h"
  48. /* debug */
  49. #include "mac_assert.h"
  50. /* ------------------------------------------------------------------------------------------------
  51. * Global Variables
  52. * ------------------------------------------------------------------------------------------------
  53. */
  54. uint8 macRxOnFlag;
  55. uint8 macRxEnableFlags;
  56. /**************************************************************************************************
  57. * @fn macRxOnOffInit
  58. *
  59. * @brief Initialize variables for rx on/off module.
  60. *
  61. * @param none
  62. *
  63. * @return none
  64. **************************************************************************************************
  65. */
  66. MAC_INTERNAL_API void macRxOnOffInit(void)
  67. {
  68. macRxEnableFlags = 0;
  69. macRxOnFlag = 0;
  70. }
  71. /**************************************************************************************************
  72. * @fn macRxEnable
  73. *
  74. * @brief Set enable flags and then turn on receiver.
  75. *
  76. * @param flags - byte containing rx enable flags to set
  77. *
  78. * @return none
  79. **************************************************************************************************
  80. */
  81. MAC_INTERNAL_API void macRxEnable(uint8 flags)
  82. {
  83. halIntState_t s;
  84. MAC_ASSERT(flags != 0); /* rx flags not affected */
  85. /* set enable flags and then turn on receiver */
  86. HAL_ENTER_CRITICAL_SECTION(s);
  87. macRxEnableFlags |= flags;
  88. macRxOn();
  89. HAL_EXIT_CRITICAL_SECTION(s);
  90. }
  91. /**************************************************************************************************
  92. * @fn macRxSoftEnable
  93. *
  94. * @brief Set enable flags but don't turn on the receiver. Useful to leave the receiver
  95. * on after a transmit, but without turning it on immediately.
  96. *
  97. * @param flags - byte containing rx enable flags to set
  98. *
  99. * @return none
  100. **************************************************************************************************
  101. */
  102. MAC_INTERNAL_API void macRxSoftEnable(uint8 flags)
  103. {
  104. halIntState_t s;
  105. MAC_ASSERT(flags != 0); /* rx flags not affected */
  106. /* set the enable flags but do not turn on the receiver */
  107. HAL_ENTER_CRITICAL_SECTION(s);
  108. macRxEnableFlags |= flags;
  109. HAL_EXIT_CRITICAL_SECTION(s);
  110. }
  111. /**************************************************************************************************
  112. * @fn macRxDisable
  113. *
  114. * @brief Clear indicated rx enable flags. If all flags are clear, turn off receiver
  115. * unless there is an active receive or transmit.
  116. *
  117. * @param flags - byte containg rx enable flags to clear
  118. *
  119. * @return none
  120. **************************************************************************************************
  121. */
  122. MAC_INTERNAL_API void macRxDisable(uint8 flags)
  123. {
  124. halIntState_t s;
  125. MAC_ASSERT(flags != 0); /* rx flags not affected */
  126. /* clear the indicated flags */
  127. HAL_ENTER_CRITICAL_SECTION(s);
  128. macRxEnableFlags &= (flags ^ 0xFF);
  129. HAL_EXIT_CRITICAL_SECTION(s);
  130. /* turn off the radio if it is allowed */
  131. macRxOffRequest();
  132. }
  133. /**************************************************************************************************
  134. * @fn macRxHardDisable
  135. *
  136. * @brief Clear all enable flags and turn off receiver.
  137. *
  138. * @param none
  139. *
  140. * @return none
  141. **************************************************************************************************
  142. */
  143. MAC_INTERNAL_API void macRxHardDisable(void)
  144. {
  145. halIntState_t s;
  146. HAL_ENTER_CRITICAL_SECTION(s);
  147. macRxEnableFlags = 0;
  148. macRxOnFlag = 0;
  149. /* force receiver off */
  150. MAC_RADIO_RXTX_OFF();
  151. MAC_RADIO_FLUSH_RX_FIFO();
  152. MAC_DEBUG_TURN_OFF_RX_LED();
  153. HAL_EXIT_CRITICAL_SECTION(s);
  154. /* clean up after being forced off */
  155. macRxHaltCleanup();
  156. }
  157. /**************************************************************************************************
  158. * @fn macRxOnRequest
  159. *
  160. * @brief Turn on the receiver if any rx enable flag is set.
  161. *
  162. * @param none
  163. *
  164. * @return none
  165. **************************************************************************************************
  166. */
  167. MAC_INTERNAL_API void macRxOnRequest(void)
  168. {
  169. halIntState_t s;
  170. HAL_ENTER_CRITICAL_SECTION(s);
  171. if (macRxEnableFlags)
  172. {
  173. macRxOn();
  174. }
  175. HAL_EXIT_CRITICAL_SECTION(s);
  176. }
  177. /**************************************************************************************************
  178. * @fn macRxOffRequest
  179. *
  180. * @brief Turn off receiver if permitted.
  181. *
  182. * @param none
  183. *
  184. * @return none
  185. **************************************************************************************************
  186. */
  187. MAC_INTERNAL_API void macRxOffRequest(void)
  188. {
  189. halIntState_t s;
  190. HAL_ENTER_CRITICAL_SECTION(s);
  191. if (!macRxEnableFlags)
  192. {
  193. if (!MAC_RX_IS_PHYSICALLY_ACTIVE() && !MAC_TX_IS_PHYSICALLY_ACTIVE())
  194. {
  195. macRxOff();
  196. }
  197. }
  198. HAL_EXIT_CRITICAL_SECTION(s);
  199. }
  200. /**************************************************************************************************
  201. * @fn macRxOn
  202. *
  203. * @brief Turn on the receiver if it's not already on.
  204. *
  205. * @param none
  206. *
  207. * @return none
  208. **************************************************************************************************
  209. */
  210. MAC_INTERNAL_API void macRxOn(void)
  211. {
  212. halIntState_t s;
  213. HAL_ENTER_CRITICAL_SECTION(s);
  214. if (!macRxOnFlag)
  215. {
  216. macRxOnFlag = 1;
  217. MAC_RADIO_RX_ON();
  218. MAC_DEBUG_TURN_ON_RX_LED();
  219. }
  220. HAL_EXIT_CRITICAL_SECTION(s);
  221. }
  222. /**************************************************************************************************
  223. * @fn macRxOff
  224. *
  225. * @brief Turn off the receiver if it's not already off.
  226. *
  227. * @param none
  228. *
  229. * @return none
  230. **************************************************************************************************
  231. */
  232. MAC_INTERNAL_API void macRxOff(void)
  233. {
  234. halIntState_t s;
  235. HAL_ENTER_CRITICAL_SECTION(s);
  236. if (macRxOnFlag)
  237. {
  238. macRxOnFlag = 0;
  239. MAC_RADIO_RXTX_OFF();
  240. MAC_DEBUG_TURN_OFF_RX_LED();
  241. /* just in case a receive was about to start, flush the receive FIFO */
  242. MAC_RADIO_FLUSH_RX_FIFO();
  243. /* clear any receive interrupt that happened to squeak through */
  244. MAC_RADIO_CLEAR_RX_THRESHOLD_INTERRUPT_FLAG();
  245. }
  246. HAL_EXIT_CRITICAL_SECTION(s);
  247. }
  248. /**************************************************************************************************
  249. */