hal_drivers.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**************************************************************************************************
  2. Filename: hal_drivers.c
  3. Revised: $Date: 2007-07-06 10:42:24 -0700 (Fri, 06 Jul 2007) $
  4. Revision: $Revision: 13579 $
  5. Description: This file contains the interface to the Drivers Service.
  6. Copyright 2005-2010 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 揂S 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. #include "hal_types.h"
  37. #include "OSAL.h"
  38. #include "hal_drivers.h"
  39. #include "hal_adc.h"
  40. #if (defined HAL_DMA) && (HAL_DMA == TRUE)
  41. #include "hal_dma.h"
  42. #endif
  43. #include "hal_key.h"
  44. #include "hal_lcd.h"
  45. #include "hal_led.h"
  46. #include "hal_timer.h"
  47. #include "hal_uart.h"
  48. #include "hal_sleep.h"
  49. #if (defined HAL_AES) && (HAL_AES == TRUE)
  50. #include "hal_aes.h"
  51. #endif
  52. #if (defined HAL_SPI) && (HAL_SPI == TRUE)
  53. #include "hal_spi.h"
  54. #endif
  55. #if (defined HAL_HID) && (HAL_HID == TRUE)
  56. #include "usb_hid.h"
  57. #endif
  58. #ifdef CC2591_COMPRESSION_WORKAROUND
  59. #include "mac_rx.h"
  60. #endif
  61. /**************************************************************************************************
  62. * MACROS
  63. **************************************************************************************************/
  64. /**************************************************************************************************
  65. * CONSTANTS
  66. **************************************************************************************************/
  67. /**************************************************************************************************
  68. * TYPEDEFS
  69. **************************************************************************************************/
  70. /**************************************************************************************************
  71. * GLOBAL VARIABLES
  72. **************************************************************************************************/
  73. uint8 Hal_TaskID;
  74. extern void HalLedUpdate( void ); /* Notes: This for internal only so it shouldn't be in hal_led.h */
  75. /**************************************************************************************************
  76. * FUNCTIONS - API
  77. **************************************************************************************************/
  78. /**************************************************************************************************
  79. * @fn Hal_Init
  80. *
  81. * @brief Hal Initialization function.
  82. *
  83. * @param task_id - Hal TaskId
  84. *
  85. * @return None
  86. **************************************************************************************************/
  87. void Hal_Init( uint8 task_id )
  88. {
  89. /* Register task ID */
  90. Hal_TaskID = task_id;
  91. #ifdef CC2591_COMPRESSION_WORKAROUND
  92. osal_start_reload_timer( Hal_TaskID, PERIOD_RSSI_RESET_EVT, PERIOD_RSSI_RESET_TIMEOUT );
  93. #endif
  94. }
  95. /**************************************************************************************************
  96. * @fn Hal_DriverInit
  97. *
  98. * @brief Initialize HW - These need to be initialized before anyone.
  99. *
  100. * @param task_id - Hal TaskId
  101. *
  102. * @return None
  103. **************************************************************************************************/
  104. void HalDriverInit (void)
  105. {
  106. /* TIMER */
  107. #if (defined HAL_TIMER) && (HAL_TIMER == TRUE)
  108. #error "The hal timer driver module is removed."
  109. #endif
  110. /* ADC */
  111. #if (defined HAL_ADC) && (HAL_ADC == TRUE)
  112. HalAdcInit();
  113. #endif
  114. /* DMA */
  115. #if (defined HAL_DMA) && (HAL_DMA == TRUE)
  116. // Must be called before the init call to any module that uses DMA.
  117. HalDmaInit();
  118. #endif
  119. /* AES */
  120. #if (defined HAL_AES) && (HAL_AES == TRUE)
  121. HalAesInit();
  122. #endif
  123. /* LCD */
  124. #if (defined HAL_LCD) && (HAL_LCD == TRUE)
  125. //HalLcdInit();
  126. #endif
  127. /* LED */
  128. #if (defined HAL_LED) && (HAL_LED == TRUE)
  129. //HalLedInit();
  130. #endif
  131. /* UART */
  132. #if (defined HAL_UART) && (HAL_UART == TRUE)
  133. HalUARTInit();
  134. #endif
  135. /* KEY */
  136. #if (defined HAL_KEY) && (HAL_KEY == TRUE)
  137. //HalKeyInit();
  138. #endif
  139. /* SPI */
  140. #if (defined HAL_SPI) && (HAL_SPI == TRUE)
  141. HalSpiInit();
  142. #endif
  143. /* HID */
  144. #if (defined HAL_HID) && (HAL_HID == TRUE)
  145. usbHidInit();
  146. #endif
  147. }
  148. /**************************************************************************************************
  149. * @fn Hal_ProcessEvent
  150. *
  151. * @brief Hal Process Event
  152. *
  153. * @param task_id - Hal TaskId
  154. * events - events
  155. *
  156. * @return None
  157. **************************************************************************************************/
  158. uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
  159. {
  160. uint8 *msgPtr;
  161. (void)task_id; // Intentionally unreferenced parameter
  162. if ( events & SYS_EVENT_MSG )//系统消息事件
  163. {
  164. msgPtr = osal_msg_receive(Hal_TaskID);
  165. while (msgPtr)
  166. {
  167. /* Do something here - for now, just deallocate the msg and move on */
  168. /* De-allocate */
  169. osal_msg_deallocate( msgPtr );
  170. /* Next */
  171. msgPtr = osal_msg_receive( Hal_TaskID );
  172. }
  173. return events ^ SYS_EVENT_MSG;
  174. }
  175. if ( events & HAL_LED_BLINK_EVENT )//LED闪烁
  176. {
  177. #if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
  178. // HalLedUpdate();
  179. #endif /* BLINK_LEDS && HAL_LED */
  180. return events ^ HAL_LED_BLINK_EVENT;
  181. }
  182. if (events & HAL_KEY_EVENT)//按键处理
  183. {
  184. #if (defined HAL_KEY) && (HAL_KEY == TRUE)
  185. /* Check for keys */
  186. //HalKeyPoll();
  187. /* if interrupt disabled, do next polling */
  188. // if (!Hal_KeyIntEnable)
  189. // {
  190. // osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
  191. // }
  192. #endif // HAL_KEY
  193. return events ^ HAL_KEY_EVENT;
  194. }
  195. #ifdef POWER_SAVING //如果定义休眠功能 这项预编译有用
  196. if ( events & HAL_SLEEP_TIMER_EVENT )
  197. {
  198. halRestoreSleepLevel();
  199. return events ^ HAL_SLEEP_TIMER_EVENT;
  200. }
  201. #endif
  202. #ifdef CC2591_COMPRESSION_WORKAROUND
  203. if ( events & PERIOD_RSSI_RESET_EVT )
  204. {
  205. macRxResetRssi();
  206. return (events ^ PERIOD_RSSI_RESET_EVT);
  207. }
  208. #endif
  209. /* Nothing interested, discard the message */
  210. return 0;
  211. }
  212. /**************************************************************************************************
  213. * @fn Hal_ProcessPoll
  214. *
  215. * @brief This routine will be called by OSAL to poll UART, TIMER...
  216. *
  217. * @param task_id - Hal TaskId
  218. *
  219. * @return None
  220. **************************************************************************************************/
  221. void Hal_ProcessPoll ()
  222. {
  223. /* Timer Poll */
  224. #if (defined HAL_TIMER) && (HAL_TIMER == TRUE)
  225. #error "The hal timer driver module is removed."
  226. #endif
  227. /* UART Poll */
  228. #if (defined HAL_UART) && (HAL_UART == TRUE)
  229. HalUARTPoll();
  230. #endif
  231. /* SPI Poll */
  232. #if (defined HAL_SPI) && (HAL_SPI == TRUE)
  233. HalSpiPoll();
  234. #endif
  235. /* HID poll */
  236. #if (defined HAL_HID) && (HAL_HID == TRUE)
  237. usbHidProcessEvents();
  238. #endif
  239. #if defined( POWER_SAVING )
  240. /* Allow sleep before the next OSAL event loop */
  241. ALLOW_SLEEP_MODE();
  242. #endif
  243. }
  244. /**************************************************************************************************
  245. **************************************************************************************************/