Contiki-NG
leds-arch.c
1/*
2 * Copyright (c) 2015 NXP B.V.
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 NXP B.V. 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 NXP B.V. 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 NXP B.V. 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 * Author: Theo van Daele <theo.van.daele@nxp.com>
32 *
33 */
34#include "contiki.h"
35#include "dev/leds.h"
36#include <AppHardwareApi.h>
37#ifdef SENSOR_BOARD_DR1199
38#include "dr1199/leds-arch-1199.h"
39#endif
40#ifdef SENSOR_BOARD_DR1175
41#include "leds-extension.h"
42#include "dr1175/leds-arch-1175.h"
43#endif
44
45#define LED_D3 (1 << 3)
46#define LED_D6 (1 << 2)
47
48static volatile unsigned char leds;
49
50/*---------------------------------------------------------------------------*/
51void
52leds_arch_init(void)
53{
54 vAHI_DioSetDirection(0, LED_D3 | LED_D6);
55 vAHI_DioSetOutput(LED_D3 | LED_D6, 0); /* Default off */
56#ifdef SENSOR_BOARD_DR1199
57 leds_arch_init_1199();
58#endif
59#ifdef SENSOR_BOARD_DR1175
60 leds_arch_init_1175();
61#endif
62 leds = 0;
63}
64/*---------------------------------------------------------------------------*/
65unsigned char
66leds_arch_get(void)
67{
68 return leds;
69}
70/*---------------------------------------------------------------------------*/
71void
72leds_arch_set(unsigned char c)
73{
74 uint32 on_mask = 0;
75 uint32 off_mask = 0;
76
77 /* LOW level on pins switches ON LED for DR1174 */
78 if(c & LEDS_GP0) {
79 on_mask |= LED_D3;
80 } else {
81 off_mask |= LED_D3;
82 } if(c & LEDS_GP1) {
83 on_mask |= LED_D6;
84 } else {
85 off_mask |= LED_D6;
86 } vAHI_DioSetOutput(off_mask, on_mask);
87#ifdef SENSOR_BOARD_DR1199
88 /* DR1174 with DR1199 */
89 leds_arch_set_1199(c);
90 if(c == LEDS_ALL) {
91 leds = LEDS_GP0 | LEDS_GP1 | LEDS_RED | LEDS_BLUE | LEDS_GREEN;
92 } else {
93 leds = (c & (LEDS_GP0 | LEDS_GP1 | LEDS_RED | LEDS_BLUE | LEDS_GREEN));
94 }
95#elif SENSOR_BOARD_DR1175
96 /* DR1174 with DR1175 */
97 leds_arch_set_1175(c);
98 if(c == LEDS_ALL) {
99 leds = LEDS_GP0 | LEDS_GP1 | LEDS_RED | LEDS_BLUE | LEDS_GREEN | LEDS_WHITE;
100 } else {
101 leds = (c & (LEDS_GP0 | LEDS_GP1 | LEDS_RED | LEDS_BLUE | LEDS_GREEN | LEDS_WHITE));
102/* printf("++++++++++++++++++++ leds_arch_set: leds: 0x%x\n", leds); */
103 }
104#else
105 /* DR1174-only */
106 if(c == LEDS_ALL) {
107 leds = LEDS_GP0 | LEDS_GP1;
108 } else {
109 leds = c;
110 }
111#endif
112}
113/*---------------------------------------------------------------------------*/
114void
115leds_arch_set_level(unsigned char level, unsigned char c)
116{
117#ifdef SENSOR_BOARD_DR1175
118 leds_arch_set_level_1175(level, c, leds);
119/* printf("++++++++++++++++++++ leds_arch_set_level: leds: 0x%x\n", leds); */
120#endif
121}
#define LEDS_ALL
The OR mask representation of all device LEDs.
Definition: leds.h:195
Header file for the LED HAL.