status_led.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * (C) Copyright 2003, Li-Pro.Net <www.li-pro.net>
  3. * Stephan Linz <linz@li-pro.net>
  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. * asm-nios/status_led.h
  24. *
  25. * NIOS PIO based status led support functions
  26. */
  27. #ifndef __ASM_STATUS_LED_H__
  28. #define __ASM_STATUS_LED_H__
  29. #include <nios-io.h>
  30. /* led_id_t is unsigned int mask */
  31. typedef unsigned int led_id_t;
  32. #ifdef STATUS_LED_WRONLY /* emulate read access */
  33. static led_id_t __led_portval = 0;
  34. #endif
  35. static inline void __led_init (led_id_t mask, int state)
  36. {
  37. nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
  38. #ifdef STATUS_LED_WRONLY /* emulate read access */
  39. #if (STATUS_LED_ACTIVE == 0)
  40. if (state == STATUS_LED_ON)
  41. __led_portval &= ~mask;
  42. else
  43. __led_portval |= mask;
  44. #else
  45. if (state == STATUS_LED_ON)
  46. __led_portval |= mask;
  47. else
  48. __led_portval &= ~mask;
  49. #endif
  50. piop->data = __led_portval;
  51. #else /* !STATUS_LED_WRONLY */
  52. #if (STATUS_LED_ACTIVE == 0)
  53. if (state == STATUS_LED_ON)
  54. piop->data &= ~mask;
  55. else
  56. piop->data |= mask;
  57. #else
  58. if (state == STATUS_LED_ON)
  59. piop->data |= mask;
  60. else
  61. piop->data &= ~mask;
  62. #endif
  63. piop->direction |= mask;
  64. #endif /* STATUS_LED_WRONLY */
  65. }
  66. static inline void __led_toggle (led_id_t mask)
  67. {
  68. nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
  69. #ifdef STATUS_LED_WRONLY /* emulate read access */
  70. __led_portval ^= mask;
  71. piop->data = __led_portval;
  72. #else /* !STATUS_LED_WRONLY */
  73. piop->data ^= mask;
  74. #endif /* STATUS_LED_WRONLY */
  75. }
  76. static inline void __led_set (led_id_t mask, int state)
  77. {
  78. nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
  79. #ifdef STATUS_LED_WRONLY /* emulate read access */
  80. #if (STATUS_LED_ACTIVE == 0)
  81. if (state == STATUS_LED_ON)
  82. __led_portval &= ~mask;
  83. else
  84. __led_portval |= mask;
  85. #else
  86. if (state == STATUS_LED_ON)
  87. __led_portval |= mask;
  88. else
  89. __led_portval &= ~mask;
  90. #endif
  91. piop->data = __led_portval;
  92. #else /* !STATUS_LED_WRONLY */
  93. #if (STATUS_LED_ACTIVE == 0)
  94. if (state == STATUS_LED_ON)
  95. piop->data &= ~mask;
  96. else
  97. piop->data |= mask;
  98. #else
  99. if (state == STATUS_LED_ON)
  100. piop->data |= mask;
  101. else
  102. piop->data &= ~mask;
  103. #endif
  104. #endif /* STATUS_LED_WRONLY */
  105. }
  106. #endif /* __ASM_STATUS_LED_H__ */