blob: 241c9176889c7523b280e6f13695b5435f57df27 [file] [log] [blame]
wdenkc935d3b2004-01-03 19:43:48 +00001/*
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
28#ifndef __ASM_STATUS_LED_H__
29#define __ASM_STATUS_LED_H__
30
31#include <nios-io.h>
32
33/* led_id_t is unsigned int mask */
34typedef unsigned int led_id_t;
35
36#ifdef STATUS_LED_WRONLY /* emulate read access */
37static led_id_t __led_portval = 0;
38#endif
39
40static inline void __led_init (led_id_t mask, int state)
41{
42 nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
43
44#ifdef STATUS_LED_WRONLY /* emulate read access */
45
46#if (STATUS_LED_ACTIVE == 0)
47 if (state == STATUS_LED_ON)
48 __led_portval &= ~mask;
49 else
50 __led_portval |= mask;
51#else
52 if (state == STATUS_LED_ON)
53 __led_portval |= mask;
54 else
55 __led_portval &= ~mask;
56#endif
57
58 piop->data = __led_portval;
59
60#else /* !STATUS_LED_WRONLY */
61
62#if (STATUS_LED_ACTIVE == 0)
63 if (state == STATUS_LED_ON)
64 piop->data &= ~mask;
65 else
66 piop->data |= mask;
67#else
68 if (state == STATUS_LED_ON)
69 piop->data |= mask;
70 else
71 piop->data &= ~mask;
72#endif
73
74 piop->direction |= mask;
75
76#endif /* STATUS_LED_WRONLY */
77}
78
79static inline void __led_toggle (led_id_t mask)
80{
81 nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
82
83#ifdef STATUS_LED_WRONLY /* emulate read access */
84
85 __led_portval ^= mask;
86 piop->data = __led_portval;
87
88#else /* !STATUS_LED_WRONLY */
89
90 piop->data ^= mask;
91
92#endif /* STATUS_LED_WRONLY */
93}
94
95static inline void __led_set (led_id_t mask, int state)
96{
97 nios_pio_t *piop = (nios_pio_t*)STATUS_LED_BASE;
98
99#ifdef STATUS_LED_WRONLY /* emulate read access */
100
101#if (STATUS_LED_ACTIVE == 0)
102 if (state == STATUS_LED_ON)
103 __led_portval &= ~mask;
104 else
105 __led_portval |= mask;
106#else
107 if (state == STATUS_LED_ON)
108 __led_portval |= mask;
109 else
110 __led_portval &= ~mask;
111#endif
112
113 piop->data = __led_portval;
114
115#else /* !STATUS_LED_WRONLY */
116
117#if (STATUS_LED_ACTIVE == 0)
118 if (state == STATUS_LED_ON)
119 piop->data &= ~mask;
120 else
121 piop->data |= mask;
122#else
123 if (state == STATUS_LED_ON)
124 piop->data |= mask;
125 else
126 piop->data &= ~mask;
127#endif
128
129#endif /* STATUS_LED_WRONLY */
130}
131
132#endif /* __ASM_STATUS_LED_H__ */