2 * (C) Copyright 2003, Li-Pro.Net <www.li-pro.net>
3 * Stephan Linz <linz@li-pro.net>
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
23 * asm-nios/status_led.h
25 * NIOS PIO based status led support functions
28 #ifndef __ASM_STATUS_LED_H__
29 #define __ASM_STATUS_LED_H__
33 /* led_id_t is unsigned int mask */
34 typedef unsigned int led_id_t;
36 #ifdef STATUS_LED_WRONLY /* emulate read access */
37 static led_id_t __led_portval = 0;
40 static inline void __led_init (led_id_t mask, int state)
42 nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
44 #ifdef STATUS_LED_WRONLY /* emulate read access */
46 #if (STATUS_LED_ACTIVE == 0)
47 if (state == STATUS_LED_ON)
48 __led_portval &= ~mask;
50 __led_portval |= mask;
52 if (state == STATUS_LED_ON)
53 __led_portval |= mask;
55 __led_portval &= ~mask;
58 piop->data = __led_portval;
60 #else /* !STATUS_LED_WRONLY */
62 #if (STATUS_LED_ACTIVE == 0)
63 if (state == STATUS_LED_ON)
68 if (state == STATUS_LED_ON)
74 piop->direction |= mask;
76 #endif /* STATUS_LED_WRONLY */
79 static inline void __led_toggle (led_id_t mask)
81 nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
83 #ifdef STATUS_LED_WRONLY /* emulate read access */
85 __led_portval ^= mask;
86 piop->data = __led_portval;
88 #else /* !STATUS_LED_WRONLY */
92 #endif /* STATUS_LED_WRONLY */
95 static inline void __led_set (led_id_t mask, int state)
97 nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
99 #ifdef STATUS_LED_WRONLY /* emulate read access */
101 #if (STATUS_LED_ACTIVE == 0)
102 if (state == STATUS_LED_ON)
103 __led_portval &= ~mask;
105 __led_portval |= mask;
107 if (state == STATUS_LED_ON)
108 __led_portval |= mask;
110 __led_portval &= ~mask;
113 piop->data = __led_portval;
115 #else /* !STATUS_LED_WRONLY */
117 #if (STATUS_LED_ACTIVE == 0)
118 if (state == STATUS_LED_ON)
123 if (state == STATUS_LED_ON)
129 #endif /* STATUS_LED_WRONLY */
132 #endif /* __ASM_STATUS_LED_H__ */