status_led.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <status_led.h>
  25. /*
  26. * The purpose of this code is to signal the operational status of a
  27. * target which usually boots over the network; while running in
  28. * U-Boot, a status LED is blinking. As soon as a valid BOOTP reply
  29. * message has been received, the LED is turned off. The Linux
  30. * kernel, once it is running, will start blinking the LED again,
  31. * with another frequency.
  32. */
  33. /* ------------------------------------------------------------------------- */
  34. typedef struct {
  35. led_id_t mask;
  36. int state;
  37. int period;
  38. int cnt;
  39. } led_dev_t;
  40. led_dev_t led_dev[] = {
  41. { STATUS_LED_BIT,
  42. STATUS_LED_STATE,
  43. STATUS_LED_PERIOD,
  44. 0,
  45. },
  46. #if defined(STATUS_LED_BIT1)
  47. { STATUS_LED_BIT1,
  48. STATUS_LED_STATE1,
  49. STATUS_LED_PERIOD1,
  50. 0,
  51. },
  52. #endif
  53. #if defined(STATUS_LED_BIT2)
  54. { STATUS_LED_BIT2,
  55. STATUS_LED_STATE2,
  56. STATUS_LED_PERIOD2,
  57. 0,
  58. },
  59. #endif
  60. #if defined(STATUS_LED_BIT3)
  61. { STATUS_LED_BIT3,
  62. STATUS_LED_STATE3,
  63. STATUS_LED_PERIOD3,
  64. 0,
  65. },
  66. #endif
  67. };
  68. #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
  69. static int status_led_init_done = 0;
  70. static void status_led_init (void)
  71. {
  72. led_dev_t *ld;
  73. int i;
  74. for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++)
  75. __led_init (ld->mask, ld->state);
  76. status_led_init_done = 1;
  77. }
  78. void status_led_tick (ulong timestamp)
  79. {
  80. led_dev_t *ld;
  81. int i;
  82. if (!status_led_init_done)
  83. status_led_init ();
  84. for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
  85. if (ld->state != STATUS_LED_BLINKING)
  86. continue;
  87. if (++ld->cnt >= ld->period) {
  88. __led_toggle (ld->mask);
  89. ld->cnt -= ld->period;
  90. }
  91. }
  92. }
  93. void status_led_set (int led, int state)
  94. {
  95. led_dev_t *ld;
  96. if (led < 0 || led >= MAX_LED_DEV)
  97. return;
  98. if (!status_led_init_done)
  99. status_led_init ();
  100. ld = &led_dev[led];
  101. ld->state = state;
  102. if (state == STATUS_LED_BLINKING) {
  103. ld->cnt = 0; /* always start with full period */
  104. state = STATUS_LED_ON; /* always start with LED _ON_ */
  105. }
  106. __led_set (ld->mask, state);
  107. }