Contiki 2.5
qleds.c
1 /*
2  * Copyright (c) 2007, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)$Id: qleds.c,v 1.1 2007/02/02 14:07:34 bg- Exp $
30  */
31 
32 #include "contiki.h"
33 
34 #include "dev/leds.h"
35 
36 #include <avr/io.h>
37 
38 void
39 leds_init(void)
40 {
41 #ifdef CB_GATEWAY
42  DDRE |= LEDS_CONF_GREEN | LEDS_CONF_YELLOW;
43  PORTE |= LEDS_CONF_GREEN | LEDS_CONF_YELLOW; /* LEDS off */
44 #else
45  DDRB |= LEDS_CONF_ORANGE | LEDS_CONF_GREEN;
46  DDRE |= LEDS_CONF_RED | LEDS_CONF_YELLOW;
47 
48  PORTB &= ~(LEDS_CONF_ORANGE | LEDS_CONF_GREEN);
49  PORTE &= ~(LEDS_CONF_RED | LEDS_CONF_YELLOW);
50 #endif
51 }
52 
53 void
54 leds_on(unsigned char leds)
55 {
56 #ifdef CB_GATEWAY
57  if (leds & LEDS_GREEN)
58  PORTE &= ~LEDS_CONF_GREEN;
59  if (leds & LEDS_YELLOW)
60  PORTE &= ~LEDS_CONF_YELLOW;
61 #else
62  if (leds & LEDS_ORANGE)
63  PORTB |= LEDS_CONF_ORANGE;
64  if (leds & LEDS_GREEN)
65  PORTB |= LEDS_CONF_GREEN;
66 
67  if (leds & LEDS_RED)
68  PORTE |= LEDS_CONF_RED;
69  if (leds & LEDS_YELLOW)
70  PORTE |= LEDS_CONF_YELLOW;
71 #endif
72 }
73 
74 void
75 leds_off(unsigned char leds)
76 {
77 #ifdef CB_GATEWAY
78  if (leds & LEDS_GREEN)
79  PORTE |= LEDS_CONF_GREEN;
80  if (leds & LEDS_YELLOW)
81  PORTE |= LEDS_CONF_YELLOW;
82 #else
83  if (leds & LEDS_ORANGE)
84  PORTB &= ~LEDS_CONF_ORANGE;
85  if (leds & LEDS_GREEN)
86  PORTB &= ~LEDS_CONF_GREEN;
87 
88  if (leds & LEDS_RED)
89  PORTE &= ~LEDS_CONF_RED;
90  if (leds & LEDS_YELLOW)
91  PORTE &= ~LEDS_CONF_YELLOW;
92 #endif
93 }
94 
95 void
96 leds_toggle(unsigned char leds)
97 {
98  /*
99  * Synonym: void leds_invert(unsigned char leds);
100  */
101  asm(".global leds_invert\nleds_invert:\n");
102 
103 #ifdef CB_GATEWAY
104  if (leds & LEDS_GREEN)
105  PORTE ^= ~LEDS_CONF_GREEN;
106  if (leds & LEDS_YELLOW)
107  PORTE ^= ~LEDS_CONF_YELLOW;
108 #else
109  if (leds & LEDS_ORANGE)
110  PORTB ^= LEDS_CONF_ORANGE;
111  if (leds & LEDS_GREEN)
112  PORTB ^= LEDS_CONF_GREEN;
113 
114  if (leds & LEDS_RED)
115  PORTE ^= LEDS_CONF_RED;
116  if (leds & LEDS_YELLOW)
117  PORTE ^= LEDS_CONF_YELLOW;
118 #endif
119 }