Contiki 3.x
leds.c
1 /*
2  * Copyright (c) 2005, 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  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 #include "dev/leds.h"
34 #include "sys/clock.h"
35 #include "sys/energest.h"
36 
37 static unsigned char leds;
38 /*---------------------------------------------------------------------------*/
39 static void
40 show_leds(unsigned char new_leds)
41 {
42  unsigned char changed;
43  changed = leds ^ new_leds;
44  leds = new_leds;
45 
46  if(changed & LEDS_GREEN) {
47  /* Green did change */
48  if(leds & LEDS_GREEN) {
49  ENERGEST_ON(ENERGEST_TYPE_LED_GREEN);
50  } else {
51  ENERGEST_OFF(ENERGEST_TYPE_LED_GREEN);
52  }
53  }
54  if(changed & LEDS_YELLOW) {
55  if(leds & LEDS_YELLOW) {
56  ENERGEST_ON(ENERGEST_TYPE_LED_YELLOW);
57  } else {
58  ENERGEST_OFF(ENERGEST_TYPE_LED_YELLOW);
59  }
60  }
61  if(changed & LEDS_RED) {
62  if(leds & LEDS_RED) {
63  ENERGEST_ON(ENERGEST_TYPE_LED_RED);
64  } else {
65  ENERGEST_OFF(ENERGEST_TYPE_LED_RED);
66  }
67  }
68  leds_arch_set(leds);
69 }
70 /*---------------------------------------------------------------------------*/
71 void
72 leds_init(void)
73 {
75  leds = 0;
76 }
77 /*---------------------------------------------------------------------------*/
78 void
80 {
81  /* Blink all leds that were initially off. */
82  unsigned char blink;
83  blink = ~leds;
84  leds_toggle(blink);
85 
86  clock_delay(400);
87 
88  leds_toggle(blink);
89 }
90 /*---------------------------------------------------------------------------*/
91 unsigned char
92 leds_get(void) {
93  return leds_arch_get();
94 }
95 /*---------------------------------------------------------------------------*/
96 void
97 leds_set(unsigned char ledv)
98 {
99  show_leds(ledv);
100 }
101 /*---------------------------------------------------------------------------*/
102 void
103 leds_on(unsigned char ledv)
104 {
105  show_leds(leds | ledv);
106 }
107 /*---------------------------------------------------------------------------*/
108 void
109 leds_off(unsigned char ledv)
110 {
111  show_leds(leds & ~ledv);
112 }
113 /*---------------------------------------------------------------------------*/
114 void
115 leds_toggle(unsigned char ledv)
116 {
117  show_leds(leds ^ ledv);
118 }
119 /*---------------------------------------------------------------------------*/
#define LEDS_RED
LED1 (Red) -> PC0.
Definition: board.h:89
void leds_arch_init(void)
Leds implementation.
Definition: leds-arch.c:48
#define LEDS_YELLOW
LED2 (Yellow) -> PC1.
Definition: board.h:80
Header file for the energy estimation mechanism
#define LEDS_GREEN
LED3 (Green) -> PC2.
Definition: board.h:81
unsigned char leds_get(void)
Returns the current status of all leds.
Definition: leds.c:92
void clock_delay(unsigned int delay)
Obsolete delay function but we implement it here since some code still uses it.
Definition: clock.c:60
void leds_blink(void)
Blink all LEDs.
Definition: leds.c:79