hal_drivers.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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-2007 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. #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_flash.h"
  44. #include "hal_key.h"
  45. #include "hal_lcd.h"
  46. #include "hal_led.h"
  47. #include "hal_timer.h"
  48. #include "hal_uart.h"
  49. #include "hal_sleep.h"
  50. #if (defined HAL_AES) && (HAL_AES == TRUE)
  51. #include "hal_aes.h"
  52. #endif
  53. #if (defined HAL_SPI) && (HAL_SPI == TRUE)
  54. #include "hal_spi.h"
  55. #endif
  56. /**************************************************************************************************
  57. * MACROS
  58. **************************************************************************************************/
  59. /**************************************************************************************************
  60. * CONSTANTS
  61. **************************************************************************************************/
  62. /**************************************************************************************************
  63. * TYPEDEFS
  64. **************************************************************************************************/
  65. /**************************************************************************************************
  66. * GLOBAL VARIABLES
  67. **************************************************************************************************/
  68. uint8 Hal_TaskID;
  69. extern void HalLedUpdate( void ); /* Notes: This for internal only so it shouldn't be in hal_led.h */
  70. /**************************************************************************************************
  71. * FUNCTIONS - API
  72. **************************************************************************************************/
  73. /**************************************************************************************************
  74. * @fn Hal_Init
  75. *
  76. * @brief Hal Initialization function.
  77. *
  78. * @param task_id - Hal TaskId
  79. *
  80. * @return None
  81. **************************************************************************************************/
  82. void Hal_Init( uint8 task_id )
  83. {
  84. /* Register task ID */
  85. Hal_TaskID = task_id;
  86. }
  87. /**************************************************************************************************
  88. * @fn Hal_DriverInit
  89. *
  90. * @brief Initialize HW - These need to be initialized before anyone.
  91. *
  92. * @param task_id - Hal TaskId
  93. *
  94. * @return None
  95. **************************************************************************************************/
  96. void HalDriverInit (void)
  97. {
  98. /* TIMER */
  99. #if (defined HAL_TIMER) && (HAL_TIMER == TRUE)
  100. HalTimerInit();
  101. #endif
  102. /* ADC */
  103. #if (defined HAL_ADC) && (HAL_ADC == TRUE)
  104. HalAdcInit();
  105. #endif
  106. /* DMA */
  107. #if (defined HAL_DMA) && (HAL_DMA == TRUE)
  108. // Must be called before the init call to any module that uses DMA.
  109. HalDmaInit();
  110. #endif
  111. /* Flash */
  112. #if (defined HAL_FLASH) && (HAL_FLASH == TRUE)
  113. // Must be called before the init call to any module that uses Flash access or NV.
  114. HalFlashInit();
  115. #endif
  116. /* AES */
  117. #if (defined HAL_AES) && (HAL_AES == TRUE)
  118. HalAesInit();
  119. #endif
  120. /* LCD */
  121. #if (defined HAL_LCD) && (HAL_LCD == TRUE)
  122. HalLcdInit();
  123. #endif
  124. /* LED */
  125. #if (defined HAL_LED) && (HAL_LED == TRUE)
  126. HalLedInit();
  127. #endif
  128. /* UART */
  129. #if (defined HAL_UART) && (HAL_UART == TRUE)
  130. HalUARTInit();
  131. #endif
  132. /* KEY */
  133. #if (defined HAL_KEY) && (HAL_KEY == TRUE)
  134. HalKeyInit();
  135. #endif
  136. /* SPI */
  137. #if (defined HAL_SPI) && (HAL_SPI == TRUE)
  138. HalSpiInit();
  139. #endif
  140. }
  141. /**************************************************************************************************
  142. * @fn Hal_ProcessEvent
  143. *
  144. * @brief Hal Process Event
  145. *
  146. * @param task_id - Hal TaskId
  147. * events - events
  148. *
  149. * @return None
  150. **************************************************************************************************/
  151. uint16 Hal_ProcessEvent( uint8 task_id, uint16 events )
  152. {
  153. uint8 *msgPtr;
  154. (void)task_id; // Intentionally unreferenced parameter
  155. if ( events & SYS_EVENT_MSG )
  156. {
  157. msgPtr = osal_msg_receive(Hal_TaskID);
  158. while (msgPtr)
  159. {
  160. /* Do something here - for now, just deallocate the msg and move on */
  161. /* De-allocate */
  162. osal_msg_deallocate( msgPtr );
  163. /* Next */
  164. msgPtr = osal_msg_receive( Hal_TaskID );
  165. }
  166. return events ^ SYS_EVENT_MSG;
  167. }
  168. if ( events & HAL_LED_BLINK_EVENT )
  169. {
  170. #if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
  171. HalLedUpdate();
  172. #endif /* BLINK_LEDS && HAL_LED */
  173. return events ^ HAL_LED_BLINK_EVENT;
  174. }
  175. if (events & HAL_KEY_EVENT)
  176. {
  177. #if (defined HAL_KEY) && (HAL_KEY == TRUE)
  178. /* Check for keys */
  179. HalKeyPoll();
  180. /* if interrupt disabled, do next polling */
  181. if (!Hal_KeyIntEnable)
  182. {
  183. osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
  184. }
  185. #endif // HAL_KEY
  186. return events ^ HAL_KEY_EVENT;
  187. }
  188. #ifdef POWER_SAVING
  189. if ( events & HAL_SLEEP_TIMER_EVENT )
  190. {
  191. halRestoreSleepLevel();
  192. return events ^ HAL_SLEEP_TIMER_EVENT;
  193. }
  194. #endif
  195. /* Nothing interested, discard the message */
  196. return 0;
  197. }
  198. /**************************************************************************************************
  199. * @fn Hal_ProcessPoll
  200. *
  201. * @brief This routine will be called by OSAL to poll UART, TIMER...
  202. *
  203. * @param task_id - Hal TaskId
  204. *
  205. * @return None
  206. **************************************************************************************************/
  207. void Hal_ProcessPoll ()
  208. {
  209. /* Timer Poll */
  210. #if (defined HAL_TIMER) && (HAL_TIMER == TRUE)
  211. HalTimerTick();
  212. #endif
  213. /* UART Poll */
  214. #if (defined HAL_UART) && (HAL_UART == TRUE)
  215. HalUARTPoll();
  216. #endif
  217. }
  218. /**************************************************************************************************
  219. **************************************************************************************************/