Contiki 3.x
leds-arch.c
Go to the documentation of this file.
1 /*
2  * Contiki PIC32 Port project
3  *
4  * Copyright (c) 2012,
5  * Scuola Superiore Sant'Anna (http://www.sssup.it) and
6  * Consorzio Nazionale Interuniversitario per le Telecomunicazioni
7  * (http://www.cnit.it).
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the Institute nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 /**
38  * \addtogroup SeedEye Contiki SEEDEYE Platform
39  *
40  * @{
41  */
42 
43 /**
44  * \file platform/seedeye/dev/leds-arch.c
45  * \brief LEDs Specific Arch Conf
46  * \author Giovanni Pellerano <giovanni.pellerano@evilaliv3.org>
47  * \date 2012-03-21
48  */
49 
50 #include "contiki-conf.h"
51 
52 #include "dev/leds.h"
53 
54 #include "p32xxxx.h"
55 
56 /*
57  * IPM2 has 2 red LEDs, LED1 is mapped to the Contiki
58  * LEDS_RED and LED2 is mapped to LEDS_GREEN.
59  */
60 
61 #define LEDS_CONF_GREEN 0x04
62 #define LEDS_CONF_RED 0x08
63 
64 #define SEEDEYE_BOARD_V2_CAT3(x,y,z) x ## y ## z
65 
66 /* NOTE: Led0 works in a negated logic. */
67 #define led_0_on (LATCCLR = LEDS_CONF_RED)
68 #define led_0_off (LATCSET = LEDS_CONF_RED)
69 #define led_0_toggle (LATCINV = LEDS_CONF_RED)
70 #define led_1_on (LATCSET = LEDS_CONF_GREEN)
71 #define led_1_off (LATCCLR = LEDS_CONF_GREEN)
72 #define led_1_toggle (LATCINV = LEDS_CONF_GREEN)
73 #define led_on(n) SEEDEYE_BOARD_V2_CAT3(led_,n,_on)
74 #define led_off(n) SEEDEYE_BOARD_V2_CAT3(led_,n,_off)
75 #define led_toggle(n) SEEDEYE_BOARD_V2_CAT3(led_,n,_toggle)
76 
77 /*---------------------------------------------------------------------------*/
78 void
80 {
81  TRISCCLR = 0x0C;
82 
83  led_0_off;
84  led_1_off;
85 }
86 /*---------------------------------------------------------------------------*/
87 unsigned char
88 leds_arch_get(void)
89 {
90  return (PORTC & LEDS_CONF_RED ? 0 : LEDS_RED) | (~PORTC & LEDS_CONF_GREEN ? 0 : LEDS_GREEN);
91 }
92 /*---------------------------------------------------------------------------*/
93 void
94 leds_arch_set(unsigned char leds)
95 {
96  if(leds & LEDS_RED) {
97  led_0_on;
98  } else {
99  led_0_off;
100  }
101 
102  if(leds & LEDS_GREEN) {
103  led_1_on;
104  } else {
105  led_1_off;
106  }
107 }
108 /*---------------------------------------------------------------------------*/
109 
110 /** @} */
#define LEDS_RED
LED1 (Red) -&gt; PC0.
Definition: board.h:89
void leds_arch_init(void)
Leds implementation.
Definition: leds-arch.c:48
#define LEDS_GREEN
LED3 (Green) -&gt; PC2.
Definition: board.h:81
#define PORTC
Peripheral PORTC base pointer.
Definition: MK60D10.h:6423