hal_led.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. /**************************************************************************************************
  2. Filename: hal_led.c
  3. Revised: $Date: 2012-02-14 12:43:32 -0800 (Tue, 14 Feb 2012) $
  4. Revision: $Revision: 29281 $
  5. Description: This file contains the interface to the HAL LED Service.
  6. Copyright 2006-2012 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_mcu.h"
  37. //#include "hal_defs.h"
  38. //#include "hal_types.h"
  39. //#include "hal_drivers.h"
  40. //#include "hal_led.h"
  41. //#include "osal.h"
  42. //#include "hal_board.h"
  43. //
  44. ///***************************************************************************************************
  45. // * CONSTANTS
  46. // ***************************************************************************************************/
  47. //
  48. ///***************************************************************************************************
  49. // * MACROS
  50. // ***************************************************************************************************/
  51. //
  52. ///***************************************************************************************************
  53. // * TYPEDEFS
  54. // ***************************************************************************************************/
  55. ///* LED control structure */
  56. //typedef struct {
  57. // uint8 mode; /* Operation mode */
  58. // uint8 todo; /* Blink cycles left */
  59. // uint8 onPct; /* On cycle percentage */
  60. // uint16 time; /* On/off cycle time (msec) */
  61. // uint32 next; /* Time for next change */
  62. //} HalLedControl_t;
  63. //
  64. //typedef struct
  65. //{
  66. // HalLedControl_t HalLedControlTable[HAL_LED_DEFAULT_MAX_LEDS];
  67. // uint8 sleepActive;
  68. //} HalLedStatus_t;
  69. //
  70. //
  71. ///***************************************************************************************************
  72. // * GLOBAL VARIABLES
  73. // ***************************************************************************************************/
  74. //
  75. //
  76. //static uint8 HalLedState; // LED state at last set/clr/blink update
  77. //
  78. //#if HAL_LED == TRUE
  79. //static uint8 HalSleepLedState; // LED state at last set/clr/blink update
  80. //static uint8 preBlinkState; // Original State before going to blink mode
  81. // // bit 0, 1, 2, 3 represent led 0, 1, 2, 3
  82. //#endif
  83. //
  84. //#ifdef BLINK_LEDS
  85. // static HalLedStatus_t HalLedStatusControl;
  86. //#endif
  87. //
  88. ///***************************************************************************************************
  89. // * LOCAL FUNCTION
  90. // ***************************************************************************************************/
  91. //#if (HAL_LED == TRUE)
  92. //void HalLedUpdate (void);
  93. //void HalLedOnOff (uint8 leds, uint8 mode);
  94. //#endif /* HAL_LED */
  95. //
  96. ///***************************************************************************************************
  97. // * FUNCTIONS - API
  98. // ***************************************************************************************************/
  99. //
  100. ///***************************************************************************************************
  101. // * @fn HalLedInit
  102. // *
  103. // * @brief Initialize LED Service
  104. // *
  105. // * @param init - pointer to void that contains the initialized value
  106. // *
  107. // * @return None
  108. // ***************************************************************************************************/
  109. //void HalLedInit (void)
  110. //{
  111. //#if (HAL_LED == TRUE)
  112. // /* Initialize all LEDs to OFF */
  113. // HalLedSet (HAL_LED_ALL, HAL_LED_MODE_OFF);
  114. //#endif /* HAL_LED */
  115. //#ifdef BLINK_LEDS
  116. // /* Initialize sleepActive to FALSE */
  117. // HalLedStatusControl.sleepActive = FALSE;
  118. //#endif
  119. //}
  120. //
  121. ///***************************************************************************************************
  122. // * @fn HalLedSet
  123. // *
  124. // * @brief Tun ON/OFF/TOGGLE given LEDs
  125. // *
  126. // * @param led - bit mask value of leds to be turned ON/OFF/TOGGLE
  127. // * mode - BLINK, FLASH, TOGGLE, ON, OFF
  128. // * @return None
  129. // ***************************************************************************************************/
  130. //uint8 HalLedSet (uint8 leds, uint8 mode)
  131. //{
  132. //
  133. //#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
  134. // uint8 led;
  135. // HalLedControl_t *sts;
  136. //
  137. // switch (mode)
  138. // {
  139. // case HAL_LED_MODE_BLINK:
  140. // /* Default blink, 1 time, D% duty cycle */
  141. // HalLedBlink (leds, 1, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
  142. // break;
  143. //
  144. // case HAL_LED_MODE_FLASH:
  145. // /* Default flash, N times, D% duty cycle */
  146. // HalLedBlink (leds, HAL_LED_DEFAULT_FLASH_COUNT, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
  147. // break;
  148. //
  149. // case HAL_LED_MODE_ON:
  150. // case HAL_LED_MODE_OFF:
  151. // case HAL_LED_MODE_TOGGLE:
  152. //
  153. // led = HAL_LED_1;
  154. // leds &= HAL_LED_ALL;
  155. // sts = HalLedStatusControl.HalLedControlTable;
  156. //
  157. // while (leds)
  158. // {
  159. // if (leds & led)
  160. // {
  161. // if (mode != HAL_LED_MODE_TOGGLE)
  162. // {
  163. // sts->mode = mode; /* ON or OFF */
  164. // }
  165. // else
  166. // {
  167. // sts->mode ^= HAL_LED_MODE_ON; /* Toggle */
  168. // }
  169. // HalLedOnOff (led, sts->mode);
  170. // leds ^= led;
  171. // }
  172. // led <<= 1;
  173. // sts++;
  174. // }
  175. // break;
  176. //
  177. // default:
  178. // break;
  179. // }
  180. //
  181. //#elif (HAL_LED == TRUE)
  182. // LedOnOff(leds, mode);
  183. //#else
  184. // // HAL LED is disabled, suppress unused argument warnings
  185. // (void) leds;
  186. // (void) mode;
  187. //#endif /* BLINK_LEDS && HAL_LED */
  188. //
  189. // return ( HalLedState );
  190. //
  191. //}
  192. //
  193. ///***************************************************************************************************
  194. // * @fn HalLedBlink
  195. // *
  196. // * @brief Blink the leds
  197. // *
  198. // * @param leds - bit mask value of leds to be blinked
  199. // * numBlinks - number of blinks
  200. // * percent - the percentage in each period where the led
  201. // * will be on
  202. // * period - length of each cycle in milliseconds
  203. // *
  204. // * @return None
  205. // ***************************************************************************************************/
  206. //void HalLedBlink (uint8 leds, uint8 numBlinks, uint8 percent, uint16 period)
  207. //{
  208. //#if (defined (BLINK_LEDS)) && (HAL_LED == TRUE)
  209. // uint8 led;
  210. // HalLedControl_t *sts;
  211. //
  212. // if (leds && percent && period)
  213. // {
  214. // if (percent < 100)
  215. // {
  216. // led = HAL_LED_1;
  217. // leds &= HAL_LED_ALL;
  218. // sts = HalLedStatusControl.HalLedControlTable;
  219. //
  220. // while (leds)
  221. // {
  222. // if (leds & led)
  223. // {
  224. // /* Store the current state of the led before going to blinking if not already blinking */
  225. // if(sts->mode < HAL_LED_MODE_BLINK )
  226. // preBlinkState |= (led & HalLedState);
  227. //
  228. // sts->mode = HAL_LED_MODE_OFF; /* Stop previous blink */
  229. // sts->time = period; /* Time for one on/off cycle */
  230. // sts->onPct = percent; /* % of cycle LED is on */
  231. // sts->todo = numBlinks; /* Number of blink cycles */
  232. // if (!numBlinks) sts->mode |= HAL_LED_MODE_FLASH; /* Continuous */
  233. // sts->next = osal_GetSystemClock(); /* Start now */
  234. // sts->mode |= HAL_LED_MODE_BLINK; /* Enable blinking */
  235. // leds ^= led;
  236. // }
  237. // led <<= 1;
  238. // sts++;
  239. // }
  240. // // Cancel any overlapping timer for blink events
  241. // osal_stop_timerEx(Hal_TaskID, HAL_LED_BLINK_EVENT);
  242. // osal_set_event (Hal_TaskID, HAL_LED_BLINK_EVENT);
  243. // }
  244. // else
  245. // {
  246. // HalLedSet (leds, HAL_LED_MODE_ON); /* >= 100%, turn on */
  247. // }
  248. // }
  249. // else
  250. // {
  251. // HalLedSet (leds, HAL_LED_MODE_OFF); /* No on time, turn off */
  252. // }
  253. //#elif (HAL_LED == TRUE)
  254. // percent = (leds & HalLedState) ? HAL_LED_MODE_OFF : HAL_LED_MODE_ON;
  255. // HalLedOnOff (leds, percent); /* Toggle */
  256. //#else
  257. // // HAL LED is disabled, suppress unused argument warnings
  258. // (void) leds;
  259. // (void) numBlinks;
  260. // (void) percent;
  261. // (void) period;
  262. //#endif /* BLINK_LEDS && HAL_LED */
  263. //}
  264. //
  265. //#if (HAL_LED == TRUE)
  266. ///***************************************************************************************************
  267. // * @fn HalLedUpdate
  268. // *
  269. // * @brief Update leds to work with blink
  270. // *
  271. // * @param none
  272. // *
  273. // * @return none
  274. // ***************************************************************************************************/
  275. //void HalLedUpdate (void)
  276. //{
  277. // uint8 led;
  278. // uint8 pct;
  279. // uint8 leds;
  280. // HalLedControl_t *sts;
  281. // uint32 time;
  282. // uint16 next;
  283. // uint16 wait;
  284. //
  285. // next = 0;
  286. // led = HAL_LED_1;
  287. // leds = HAL_LED_ALL;
  288. // sts = HalLedStatusControl.HalLedControlTable;
  289. //
  290. // /* Check if sleep is active or not */
  291. // if (!HalLedStatusControl.sleepActive)
  292. // {
  293. // while (leds)
  294. // {
  295. // if (leds & led)
  296. // {
  297. // if (sts->mode & HAL_LED_MODE_BLINK)
  298. // {
  299. // time = osal_GetSystemClock();
  300. // if (time >= sts->next)
  301. // {
  302. // if (sts->mode & HAL_LED_MODE_ON)
  303. // {
  304. // pct = 100 - sts->onPct; /* Percentage of cycle for off */
  305. // sts->mode &= ~HAL_LED_MODE_ON; /* Say it's not on */
  306. // HalLedOnOff (led, HAL_LED_MODE_OFF); /* Turn it off */
  307. //
  308. // if (!(sts->mode & HAL_LED_MODE_FLASH))
  309. // {
  310. // sts->todo--; /* Not continuous, reduce count */
  311. // }
  312. // }
  313. // else if ( (!sts->todo) && !(sts->mode & HAL_LED_MODE_FLASH) )
  314. // {
  315. // sts->mode ^= HAL_LED_MODE_BLINK; /* No more blinks */
  316. // }
  317. // else
  318. // {
  319. // pct = sts->onPct; /* Percentage of cycle for on */
  320. // sts->mode |= HAL_LED_MODE_ON; /* Say it's on */
  321. // HalLedOnOff (led, HAL_LED_MODE_ON); /* Turn it on */
  322. // }
  323. // if (sts->mode & HAL_LED_MODE_BLINK)
  324. // {
  325. // wait = (((uint32)pct * (uint32)sts->time) / 100);
  326. // sts->next = time + wait;
  327. // }
  328. // else
  329. // {
  330. // /* no more blink, no more wait */
  331. // wait = 0;
  332. // /* After blinking, set the LED back to the state before it blinks */
  333. // HalLedSet (led, ((preBlinkState & led)!=0)?HAL_LED_MODE_ON:HAL_LED_MODE_OFF);
  334. // /* Clear the saved bit */
  335. // preBlinkState &= (led ^ 0xFF);
  336. // }
  337. // }
  338. // else
  339. // {
  340. // wait = sts->next - time; /* Time left */
  341. // }
  342. //
  343. // if (!next || ( wait && (wait < next) ))
  344. // {
  345. // next = wait;
  346. // }
  347. // }
  348. // leds ^= led;
  349. // }
  350. // led <<= 1;
  351. // sts++;
  352. // }
  353. //
  354. // if (next)
  355. // {
  356. // osal_start_timerEx(Hal_TaskID, HAL_LED_BLINK_EVENT, next); /* Schedule event */
  357. // }
  358. // }
  359. //}
  360. //
  361. ///***************************************************************************************************
  362. // * @fn HalLedOnOff
  363. // *
  364. // * @brief Turns specified LED ON or OFF
  365. // *
  366. // * @param leds - LED bit mask
  367. // * mode - LED_ON,LED_OFF,
  368. // *
  369. // * @return none
  370. // ***************************************************************************************************/
  371. //void HalLedOnOff (uint8 leds, uint8 mode)
  372. //{
  373. // if (leds & HAL_LED_1)
  374. // {
  375. // if (mode == HAL_LED_MODE_ON)
  376. // {
  377. // HAL_TURN_ON_LED1();
  378. // }
  379. // else
  380. // {
  381. // HAL_TURN_OFF_LED1();
  382. // }
  383. // }
  384. //
  385. // if (leds & HAL_LED_2)
  386. // {
  387. // if (mode == HAL_LED_MODE_ON)
  388. // {
  389. // HAL_TURN_ON_LED2();
  390. // }
  391. // else
  392. // {
  393. // HAL_TURN_OFF_LED2();
  394. // }
  395. // }
  396. //
  397. // if (leds & HAL_LED_3)
  398. // {
  399. // if (mode == HAL_LED_MODE_ON)
  400. // {
  401. // HAL_TURN_ON_LED3();
  402. // }
  403. // else
  404. // {
  405. // HAL_TURN_OFF_LED3();
  406. // }
  407. // }
  408. //
  409. // if (leds & HAL_LED_4)
  410. // {
  411. // if (mode == HAL_LED_MODE_ON)
  412. // {
  413. // HAL_TURN_ON_LED4();
  414. // }
  415. // else
  416. // {
  417. // HAL_TURN_OFF_LED4();
  418. // }
  419. // }
  420. //
  421. // /* Remember current state */
  422. // if (mode)
  423. // {
  424. // HalLedState |= leds;
  425. // }
  426. // else
  427. // {
  428. // HalLedState &= (leds ^ 0xFF);
  429. // }
  430. //}
  431. //#endif /* HAL_LED */
  432. //
  433. ///***************************************************************************************************
  434. // * @fn HalGetLedState
  435. // *
  436. // * @brief Dim LED2 - Dim (set level) of LED2
  437. // *
  438. // * @param none
  439. // *
  440. // * @return led state
  441. // ***************************************************************************************************/
  442. //uint8 HalLedGetState ()
  443. //{
  444. //#if (HAL_LED == TRUE)
  445. // return HalLedState;
  446. //#else
  447. // return 0;
  448. //#endif
  449. //}
  450. //
  451. ///***************************************************************************************************
  452. // * @fn HalLedEnterSleep
  453. // *
  454. // * @brief Store current LEDs state before sleep
  455. // *
  456. // * @param none
  457. // *
  458. // * @return none
  459. // ***************************************************************************************************/
  460. //void HalLedEnterSleep( void )
  461. //{
  462. //#ifdef BLINK_LEDS
  463. // /* Sleep ON */
  464. // HalLedStatusControl.sleepActive = TRUE;
  465. //#endif /* BLINK_LEDS */
  466. //
  467. //#if (HAL_LED == TRUE)
  468. // /* Save the state of each led */
  469. // HalSleepLedState = 0;
  470. // HalSleepLedState |= HAL_STATE_LED1();
  471. // HalSleepLedState |= HAL_STATE_LED2() << 1;
  472. // HalSleepLedState |= HAL_STATE_LED3() << 2;
  473. // HalSleepLedState |= HAL_STATE_LED4() << 3;
  474. //
  475. // /* TURN OFF all LEDs to save power */
  476. // HalLedOnOff (HAL_LED_ALL, HAL_LED_MODE_OFF);
  477. //#endif /* HAL_LED */
  478. //
  479. //}
  480. //
  481. ///***************************************************************************************************
  482. // * @fn HalLedExitSleep
  483. // *
  484. // * @brief Restore current LEDs state after sleep
  485. // *
  486. // * @param none
  487. // *
  488. // * @return none
  489. // ***************************************************************************************************/
  490. //void HalLedExitSleep( void )
  491. //{
  492. //#if (HAL_LED == TRUE)
  493. // /* Load back the saved state */
  494. // HalLedOnOff(HalSleepLedState, HAL_LED_MODE_ON);
  495. //
  496. // /* Restart - This takes care BLINKING LEDS */
  497. // HalLedUpdate();
  498. //#endif /* HAL_LED */
  499. //
  500. //#ifdef BLINK_LEDS
  501. // /* Sleep OFF */
  502. // HalLedStatusControl.sleepActive = FALSE;
  503. //#endif /* BLINK_LEDS */
  504. //}
  505. //
  506. ///***************************************************************************************************
  507. //***************************************************************************************************/
  508. //
  509. //
  510. //
  511. //