From b2eba53df9c1cd67e9203847770a4aa1000b22fa Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Fri, 23 Feb 2018 14:15:36 +0000 Subject: [PATCH 01/40] TSCH: fix a bug in tsch_schedule_slot_operation scheduling --- os/net/mac/tsch/tsch-slot-operation.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 3596b913c..607b552fe 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -297,15 +297,16 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ "!dl-miss %s %d %d", str, (int)(now-ref_time), (int)offset); ); + } else { + r = rtimer_set(tm, ref_time + offset, 1, (void (*)(struct rtimer *, void *))tsch_slot_operation, NULL); + if(r == RTIMER_OK) { + return 1; + } + } - return 0; - } - ref_time += offset; - r = rtimer_set(tm, ref_time, 1, (void (*)(struct rtimer *, void *))tsch_slot_operation, NULL); - if(r != RTIMER_OK) { - return 0; - } - return 1; + /* block until the time to schedule comes */ + BUSYWAIT_UNTIL_ABS(0, ref_time, offset); + return 0; } /*---------------------------------------------------------------------------*/ /* Schedule slot operation conditionally, and YIELD if success only. @@ -315,8 +316,8 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ do { \ if(tsch_schedule_slot_operation(tm, ref_time, offset - RTIMER_GUARD, str)) { \ PT_YIELD(pt); \ + BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ } \ - BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ } while(0); /*---------------------------------------------------------------------------*/ /* Get EB, broadcast or unicast packet to be sent, and target neighbor. */ @@ -1010,12 +1011,12 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) TSCH_ASN_INC(tsch_current_asn, timeslot_diff); /* Time to next wake up */ time_to_next_active_slot = timeslot_diff * tsch_timing[tsch_ts_timeslot_length] + drift_correction; + time_to_next_active_slot += tsch_timesync_adaptive_compensate(time_to_next_active_slot); drift_correction = 0; is_drift_correction_used = 0; /* Update current slot start */ prev_slot_start = current_slot_start; current_slot_start += time_to_next_active_slot; - current_slot_start += tsch_timesync_adaptive_compensate(time_to_next_active_slot); } while(!tsch_schedule_slot_operation(t, prev_slot_start, time_to_next_active_slot, "main")); } From 61880704b1818600c56d96ddd85323e23b9bcb8f Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 24 Feb 2018 15:32:36 -0800 Subject: [PATCH 02/40] CSMA: adopt default values from IEEE for CSMA_MIN_BE and CSMA_MAX_BE --- os/net/mac/csma/csma-output.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 0bbc34fb0..65403324e 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -66,14 +66,14 @@ #ifdef CSMA_CONF_MIN_BE #define CSMA_MIN_BE CSMA_CONF_MIN_BE #else -#define CSMA_MIN_BE 0 +#define CSMA_MIN_BE 3 #endif /* macMaxBE: Maximum backoff exponent. Range 3--8 */ #ifdef CSMA_CONF_MAX_BE #define CSMA_MAX_BE CSMA_CONF_MAX_BE #else -#define CSMA_MAX_BE 4 +#define CSMA_MAX_BE 5 #endif /* macMaxCSMABackoffs: Maximum number of backoffs in case of channel busy/collision. Range 0--5 */ @@ -281,7 +281,7 @@ schedule_transmission(struct neighbor_queue *n) clock_time_t delay; int backoff_exponent; /* BE in IEEE 802.15.4 */ - backoff_exponent = MIN(n->collisions, CSMA_MAX_BE); + backoff_exponent = MIN(n->collisions + CSMA_MIN_BE, CSMA_MAX_BE); /* Compute max delay as per IEEE 802.15.4: 2^BE-1 backoff periods */ delay = ((1 << backoff_exponent) - 1) * backoff_period(); @@ -310,7 +310,7 @@ free_packet(struct neighbor_queue *n, struct packet_queue *p, int status) if(list_head(n->packet_queue) != NULL) { /* There is a next packet. We reset current tx information */ n->transmissions = 0; - n->collisions = CSMA_MIN_BE; + n->collisions = 0; /* Schedule next transmissions */ schedule_transmission(n); } else { @@ -365,7 +365,7 @@ collision(struct packet_queue *q, struct neighbor_queue *n, n->collisions += num_transmissions; if(n->collisions > CSMA_MAX_BACKOFF) { - n->collisions = CSMA_MIN_BE; + n->collisions = 0; /* Increment to indicate a next retry */ n->transmissions++; } @@ -384,7 +384,7 @@ noack(struct packet_queue *q, struct neighbor_queue *n, int num_transmissions) metadata = (struct qbuf_metadata *)q->ptr; - n->collisions = CSMA_MIN_BE; + n->collisions = 0; n->transmissions += num_transmissions; if(n->transmissions >= metadata->max_transmissions) { From d526323ce24a5dfb63c369aa0caa4ebb6f951792 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Sat, 24 Feb 2018 15:35:58 -0800 Subject: [PATCH 03/40] CSMA for Cooja motes: increase backoff_period --- os/net/mac/csma/csma-output.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 65403324e..74803ecf1 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -154,9 +154,15 @@ neighbor_queue_from_addr(const linkaddr_t *addr) static clock_time_t backoff_period(void) { +#if CONTIKI_TARGET_COOJA + /* Increase normal value by 20 to compensate for the coarse-grained + radio medium with Cooja motes */ + return MAX(20 * CLOCK_SECOND / 3125, 1); +#else /* CONTIKI_TARGET_COOJA */ /* Use the default in IEEE 802.15.4: aUnitBackoffPeriod which is * 20 symbols i.e. 320 usec. That is, 1/3125 second. */ return MAX(CLOCK_SECOND / 3125, 1); +#endif /* CONTIKI_TARGET_COOJA */ } /*---------------------------------------------------------------------------*/ static int From bfb4f9537bd4a25087cdde08c2cc4ec0e619ec48 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 27 Feb 2018 08:20:46 -0800 Subject: [PATCH 04/40] 6p-packet example: use MAC address instead of node_id to hardcode coordinator --- examples/6tisch/6p-packet/sixp-node.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/6tisch/6p-packet/sixp-node.c b/examples/6tisch/6p-packet/sixp-node.c index d911701bc..43cabbe29 100644 --- a/examples/6tisch/6p-packet/sixp-node.c +++ b/examples/6tisch/6p-packet/sixp-node.c @@ -30,11 +30,13 @@ #include #include -#include #include #include #include +/* Hard-coded MAC address of the TSCH coordinator */ +static linkaddr_t coordinator_addr = {{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}; + extern const sixtop_sf_t test_sf; extern int test_sf_start(const linkaddr_t *addr); @@ -49,7 +51,7 @@ PROCESS_THREAD(sixp_node_process, ev, data) sixtop_add_sf(&test_sf); - if(node_id == COORDINATOR_NODE_ID) { + if(linkaddr_cmp(&coordinator_addr, &linkaddr_node_addr)) { tsch_set_coordinator(1); assert(test_sf_start(NULL) == 0); } else { From 0290692815c2ece465e97f0c6a8a13abb71b63c7 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 27 Feb 2018 08:35:53 -0800 Subject: [PATCH 05/40] ipv6-hooks example: added missing include --- examples/ipv6-hooks/ipv6-hooks.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/ipv6-hooks/ipv6-hooks.c b/examples/ipv6-hooks/ipv6-hooks.c index eafc45654..d3ca8861c 100644 --- a/examples/ipv6-hooks/ipv6-hooks.c +++ b/examples/ipv6-hooks/ipv6-hooks.c @@ -4,6 +4,7 @@ #include "net/netstack.h" #include "net/ipv6/simple-udp.h" #include "net/ipv6/uipbuf.h" +#include "net/ipv6/uip-ds6.h" #include "sys/log.h" #define LOG_MODULE "App" From 6ced7e506fdcb4d456a1ad5f06fcce3bc42f1859 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 27 Feb 2018 17:34:43 +0000 Subject: [PATCH 06/40] IPSO objects: include dev/leds.h --- examples/ipso-objects/example-ipso-objects.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/ipso-objects/example-ipso-objects.c b/examples/ipso-objects/example-ipso-objects.c index ee4b992e4..aa565603b 100644 --- a/examples/ipso-objects/example-ipso-objects.c +++ b/examples/ipso-objects/example-ipso-objects.c @@ -37,6 +37,7 @@ */ #include "contiki.h" +#include "dev/leds.h" #include "services/lwm2m/lwm2m-engine.h" #include "services/lwm2m/lwm2m-rd-client.h" #include "services/lwm2m/lwm2m-device.h" From a64d5e0c18c00aba4ddf5dc7b8f1f03a08ad782b Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 27 Feb 2018 17:43:06 +0000 Subject: [PATCH 07/40] Include strings.h for strncasecmp() --- os/storage/antelope/aql-lexer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/os/storage/antelope/aql-lexer.c b/os/storage/antelope/aql-lexer.c index cad604efb..4bdefecf2 100644 --- a/os/storage/antelope/aql-lexer.c +++ b/os/storage/antelope/aql-lexer.c @@ -42,6 +42,7 @@ #include #include #include +#include struct keyword { char *string; From 3a1b830f9262d689dedcd5541279c576db30258b Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 27 Feb 2018 17:57:34 +0000 Subject: [PATCH 08/40] MQTT demo: add missing include --- examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c | 1 + examples/platform-specific/nrf52dk/mqtt-demo/mqtt-demo.c | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c b/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c index c28b5c741..b818b88ca 100644 --- a/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c +++ b/examples/platform-specific/cc2538-common/mqtt-demo/mqtt-demo.c @@ -55,6 +55,7 @@ #include "dev/cc2538-sensors.h" #include +#include /*---------------------------------------------------------------------------*/ /* * IBM server: messaging.quickstart.internetofthings.ibmcloud.com diff --git a/examples/platform-specific/nrf52dk/mqtt-demo/mqtt-demo.c b/examples/platform-specific/nrf52dk/mqtt-demo/mqtt-demo.c index 80339a4ad..6fa071617 100644 --- a/examples/platform-specific/nrf52dk/mqtt-demo/mqtt-demo.c +++ b/examples/platform-specific/nrf52dk/mqtt-demo/mqtt-demo.c @@ -55,6 +55,7 @@ #include "dev/leds.h" #include +#include /*---------------------------------------------------------------------------*/ /* * IBM server: quickstart.messaging.internetofthings.ibmcloud.com From b2063a98152eac6f36ee00c567e03007dff4811f Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 27 Feb 2018 18:05:49 +0000 Subject: [PATCH 09/40] Zoul: test-servo.c was defined as project multiple times --- examples/platform-specific/zoul/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform-specific/zoul/Makefile b/examples/platform-specific/zoul/Makefile index bc018f171..3b8a3a751 100644 --- a/examples/platform-specific/zoul/Makefile +++ b/examples/platform-specific/zoul/Makefile @@ -3,7 +3,7 @@ CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd test-iaq CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor -CONTIKI_PROJECT += test-zonik test-dht22.c test-ac-dimmer.c test-servo.c +CONTIKI_PROJECT += test-zonik test-dht22.c test-ac-dimmer.c CONTIKI_PROJECT += test-bme280 CONTIKI_TARGET_SOURCEFILES += tsl256x.c sht25.c bmpx8x.c motion-sensor.c From b321e3e11a044af7f116bf2032b546ce3f6ec80d Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 27 Feb 2018 12:32:41 -0800 Subject: [PATCH 10/40] Zoul at-test example: added missing include --- examples/platform-specific/zoul/at-test/at-master-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform-specific/zoul/at-test/at-master-test.c b/examples/platform-specific/zoul/at-test/at-master-test.c index 012010c87..b7a1acddc 100644 --- a/examples/platform-specific/zoul/at-test/at-master-test.c +++ b/examples/platform-specific/zoul/at-test/at-master-test.c @@ -52,6 +52,7 @@ #include "dev/ioc.h" #include "lib/list.h" #include "dev/sha256.h" +#include "net/linkaddr.h" #include #include #include From a2262786b1ca3bc9dae8cfdaa342a85a076e16b6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 27 Feb 2018 12:34:58 -0800 Subject: [PATCH 11/40] Zoul platform.c: removing leftover PRINTF --- arch/platform/zoul/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/platform/zoul/platform.c b/arch/platform/zoul/platform.c index f71c9e46a..4e5c7cc39 100644 --- a/arch/platform/zoul/platform.c +++ b/arch/platform/zoul/platform.c @@ -124,7 +124,7 @@ rtc_init(void) */ /* Get the system date in the following format: wd dd mm yy hh mm ss */ - PRINTF("Setting RTC from system date: %s\n", DATE); + LOG_INFO("Setting RTC from system date: %s\n", DATE); /* Configure the RTC with the current values */ td.weekdays = (uint8_t)strtol(DATE, &next, 10); @@ -149,7 +149,7 @@ rtc_init(void) /* Set the time and date */ if(rtcc_set_time_date(&td) == AB08_ERROR) { - PRINTF("Failed to set time and date\n"); + LOG_INFO("Failed to set time and date\n"); } #endif #endif From 635d8d78f7920a9c54ab0a32e3c5851bbed06d2f Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Tue, 27 Feb 2018 12:35:58 -0800 Subject: [PATCH 12/40] Zoul platform.c: include stdlib.h --- arch/platform/zoul/platform.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/platform/zoul/platform.c b/arch/platform/zoul/platform.c index 4e5c7cc39..48e90cdfe 100644 --- a/arch/platform/zoul/platform.c +++ b/arch/platform/zoul/platform.c @@ -69,6 +69,7 @@ #include #include #include +#include /*---------------------------------------------------------------------------*/ /* Log configuration */ #include "sys/log.h" From c4f7d0f147f431d0553c867bb4447ad98ca656d7 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 27 Feb 2018 23:06:23 +0000 Subject: [PATCH 13/40] Fix Zoul at-test example Add missing include and fix the CONTIKI path in the makefile --- examples/platform-specific/zoul/at-test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform-specific/zoul/at-test/Makefile b/examples/platform-specific/zoul/at-test/Makefile index 8715c949f..04d282aaa 100644 --- a/examples/platform-specific/zoul/at-test/Makefile +++ b/examples/platform-specific/zoul/at-test/Makefile @@ -2,5 +2,5 @@ CONTIKI_PROJECT = at-master-test MODULES = os/services/at-master all: $(CONTIKI_PROJECT) -CONTIKI = ../../.. +CONTIKI = ../../../.. include $(CONTIKI)/Makefile.include From 6004084785259526dc75ab6dfd1a71a6d1fa9f1e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 27 Feb 2018 23:05:00 +0000 Subject: [PATCH 14/40] Fix Zoul build when RTCC is enabled --- arch/platform/zoul/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/platform/zoul/platform.c b/arch/platform/zoul/platform.c index 48e90cdfe..4cf503162 100644 --- a/arch/platform/zoul/platform.c +++ b/arch/platform/zoul/platform.c @@ -150,7 +150,7 @@ rtc_init(void) /* Set the time and date */ if(rtcc_set_time_date(&td) == AB08_ERROR) { - LOG_INFO("Failed to set time and date\n"); + LOG_ERR("Failed to set time and date\n"); } #endif #endif From f22b54ae9fbf9b2886cc12670f0be433b1c93ae1 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 27 Feb 2018 23:16:24 +0000 Subject: [PATCH 15/40] Update Zoul/Orion example Makefile.target to specify the board --- .../platform-specific/zoul/orion/ip64-router/Makefile.target | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform-specific/zoul/orion/ip64-router/Makefile.target b/examples/platform-specific/zoul/orion/ip64-router/Makefile.target index 75430a6e4..420fc52cc 100644 --- a/examples/platform-specific/zoul/orion/ip64-router/Makefile.target +++ b/examples/platform-specific/zoul/orion/ip64-router/Makefile.target @@ -1 +1,2 @@ TARGET = zoul +BOARD = orion From bd73649eac6a9c22df9998c5ac66dfe643b8723d Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 27 Feb 2018 23:04:39 +0000 Subject: [PATCH 16/40] Update Zoul rev-b Makefile to specify the BOARD The examples in this directory are only meant for BOARD remote-revb --- examples/platform-specific/zoul/rev-b/Makefile.target | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform-specific/zoul/rev-b/Makefile.target b/examples/platform-specific/zoul/rev-b/Makefile.target index 75430a6e4..cb458a6d9 100644 --- a/examples/platform-specific/zoul/rev-b/Makefile.target +++ b/examples/platform-specific/zoul/rev-b/Makefile.target @@ -1 +1,2 @@ TARGET = zoul +BOARD = remote-revb From b632064f3d0be57d7333c1838b91c7f75f887e94 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 27 Feb 2018 23:11:59 +0000 Subject: [PATCH 17/40] Compile-test zoul examples --- tests/03-compile-arm-ports-02/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index 454c5d161..6aca008db 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -8,6 +8,10 @@ platform-specific/cc2538-common/mqtt-demo/zoul \ platform-specific/cc2538-common/crypto/zoul \ platform-specific/cc2538-common/pka/zoul \ platform-specific/zoul/orion/ip64-router/zoul:BOARD=orion \ +platform-specific/zoul/rev-b/zoul:BOARD=remote-revb \ +platform-specific/zoul/at-test/zoul \ +platform-specific/zoul/rtcc/zoul \ +platform-specific/zoul/zoul \ coap/zoul \ ipso-objects/zoul \ ipso-objects/zoul:MAKE_WITH_DTLS=1 \ From e3614403267c678f9e58ce69250c43248102523f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 18:57:26 +0000 Subject: [PATCH 18/40] Introduce new LED Hardware Abstraction Layer --- os/dev/leds.c | 187 +++++++++++++++++++++++---- os/dev/leds.h | 349 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 454 insertions(+), 82 deletions(-) diff --git a/os/dev/leds.c b/os/dev/leds.c index f7028f0c2..eff3197a1 100644 --- a/os/dev/leds.c +++ b/os/dev/leds.c @@ -1,38 +1,51 @@ /* * Copyright (c) 2005, Swedish Institute of Computer Science + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ - +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup leds + * @{ + * + * \file + * Implementation of the platform-independent aspects of the LED HAL + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" #include "dev/leds.h" -#include "sys/clock.h" +#include +#include +/*---------------------------------------------------------------------------*/ +#if LEDS_LEGACY_API /*---------------------------------------------------------------------------*/ void leds_init(void) @@ -59,26 +72,154 @@ leds_get(void) { } /*---------------------------------------------------------------------------*/ void -leds_set(unsigned char ledv) +leds_set(leds_mask_t ledv) { leds_arch_set(ledv); } /*---------------------------------------------------------------------------*/ void -leds_on(unsigned char ledv) +leds_on(leds_mask_t ledv) { leds_arch_set(leds_arch_get() | ledv); } /*---------------------------------------------------------------------------*/ void -leds_off(unsigned char ledv) +leds_off(leds_mask_t ledv) { leds_arch_set(leds_arch_get() & ~ledv); } /*---------------------------------------------------------------------------*/ void -leds_toggle(unsigned char ledv) +leds_toggle(leds_mask_t ledv) { leds_arch_set(leds_arch_get() ^ ledv); } /*---------------------------------------------------------------------------*/ +#else /* LEDS_LEGACY_API */ +/*---------------------------------------------------------------------------*/ +extern const leds_t leds_arch_leds[]; +/*---------------------------------------------------------------------------*/ +void +leds_init() +{ + leds_num_t led; + + for(led = 0; led < LEDS_COUNT; led++) { + gpio_hal_arch_pin_set_output(leds_arch_leds[led].pin); + } + leds_off(LEDS_ALL); +} +/*---------------------------------------------------------------------------*/ +void +leds_single_on(leds_num_t led) +{ + if(led >= LEDS_COUNT) { + return; + } + + if(leds_arch_leds[led].negative_logic) { + gpio_hal_arch_clear_pin(leds_arch_leds[led].pin); + } else { + gpio_hal_arch_set_pin(leds_arch_leds[led].pin); + } +} +/*---------------------------------------------------------------------------*/ +void +leds_single_off(leds_num_t led) +{ + if(led >= LEDS_COUNT) { + return; + } + + if(leds_arch_leds[led].negative_logic) { + gpio_hal_arch_set_pin(leds_arch_leds[led].pin); + } else { + gpio_hal_arch_clear_pin(leds_arch_leds[led].pin); + } +} +/*---------------------------------------------------------------------------*/ +void +leds_single_toggle(leds_num_t led) +{ + if(led >= LEDS_COUNT) { + return; + } + + gpio_hal_arch_toggle_pin(leds_arch_leds[led].pin); +} +/*---------------------------------------------------------------------------*/ +void +leds_on(leds_mask_t leds) +{ + leds_num_t led; + + for(led = 0; led < LEDS_COUNT; led++) { + if((1 << led) & leds) { + if(leds_arch_leds[led].negative_logic) { + gpio_hal_arch_clear_pin(leds_arch_leds[led].pin); + } else { + gpio_hal_arch_set_pin(leds_arch_leds[led].pin); + } + } + } +} +/*---------------------------------------------------------------------------*/ +void +leds_off(leds_mask_t leds) +{ + leds_num_t led; + + for(led = 0; led < LEDS_COUNT; led++) { + if((1 << led) & leds) { + if(leds_arch_leds[led].negative_logic) { + gpio_hal_arch_set_pin(leds_arch_leds[led].pin); + } else { + gpio_hal_arch_clear_pin(leds_arch_leds[led].pin); + } + } + } +} +/*---------------------------------------------------------------------------*/ +void +leds_toggle(leds_mask_t leds) +{ + leds_num_t led; + + for(led = 0; led < LEDS_COUNT; led++) { + if((1 << led) & leds) { + gpio_hal_arch_toggle_pin(leds_arch_leds[led].pin); + } + } +} +/*---------------------------------------------------------------------------*/ +void +leds_set(leds_mask_t leds) +{ + leds_off(LEDS_ALL); + leds_on(leds); +} +/*---------------------------------------------------------------------------*/ +leds_mask_t +leds_get() +{ + leds_mask_t rv = 0; + leds_num_t led; + uint8_t pin_state; + + for(led = 0; led < LEDS_COUNT; led++) { + pin_state = gpio_hal_arch_read_pin(leds_arch_leds[led].pin); + + if((leds_arch_leds[led].negative_logic == false && pin_state == 1) || + (leds_arch_leds[led].negative_logic == true && pin_state == 0)) { + rv |= 1 << led; + } + } + + return rv; +} +/*---------------------------------------------------------------------------*/ +#endif /* LEDS_LEGACY_API */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/os/dev/leds.h b/os/dev/leds.h index d99fb8196..654ed250e 100644 --- a/os/dev/leds.h +++ b/os/dev/leds.h @@ -1,98 +1,329 @@ /* * Copyright (c) 2005, Swedish Institute of Computer Science + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of the Contiki operating system. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ +/*---------------------------------------------------------------------------*/ /** * \addtogroup dev * @{ */ - +/*---------------------------------------------------------------------------*/ /** - * \defgroup leds LEDs API + * \defgroup leds LED Hardware Abstraction Layer * - * The LEDs API defines a set of functions for accessing LEDs for - * Contiki plaforms with LEDs. + * The LED HAL provides a set of functions that can manipulate LEDS. * - * A platform with LED support must implement this API. + * Currently, the LED HAL supports two APIs: + * + * - The new, platform-independent API (recommended for all new platforms). + * - The legacy API (supported until all existing platforms have been ported + * to support the new API). + * + * The two APIs use very similar semantics and have an overlapping set of + * function calls. This is done so that platform-independent examples can + * work on all platforms, irrespective of which API each platform supports. + * + * The legacy API can be enabled by the platform code by defining + * LEDS_CONF_LEGACY_API 1. + * + * Once all platforms supported in contiki-ng/contiki-ng have been ported to + * the new API, the legacy API will be deleted without warning. For this + * reason, it is strongly recommended to use the new API for new platforms and + * for platforms hosted in external repositories. + * + * The new API provides a set of common LED manipulation functions that can be + * used in a platform-independent fashion. Functions exist to manipulate one + * LED at a time (\c leds_single_XYZ), as well as to manipulate multiple LEDs + * at a time (\c leds_XYZ). + * + * The assumption is that each LED is connected to a GPIO pin using either + * positive or negative logic. + * + * LEDs on a device are numbered incrementally, starting from 0 and counting + * upwards. Thus, if a device has 3 LEDs they will be numbered 0, 1 and 2. + * Convenience macros (LEDS_LED_n) are provided to refer to LEDs. These macros + * can be used as arguments to functions that manipulate a single LED, such + * as leds_single_on() but \e not leds_on(). + * + * The legacy scheme that uses colours to refer to LEDs is maintained, without + * semantic changes, but with minor changes in logic: + * + * - Firstly, we now define 5 LED colours: Red, Green, Blue, Yellow, Orange. + * These are sufficient to cover all currently-supported platforms. + * - Secondly, unless a platform specifies that a LED of a specific colour + * exists, the HAL will assume that it does not. + * - Trying to manipulate a non-existent LED will not cause build errors, but + * will not cause any changes to LED state either. + * - We no longer map non-existing LED colours to existing ones. + * + * Note that, in order to avoid changes to LED colour semantics between the + * two APIs, references to LED by colour are bitwise OR masks and should + * therefore only be used as argument to functions that manipulate multiple + * LEDS (e.g. leds_off() and \e not leds_single_off()). + * + * In terms of porting for new platforms, developers simply have to: + * + * - Define variables of type leds_t to represent their platform's LEDs + * - Specify the number of LEDs on their device by defining LEDS_CONF_COUNT + * - Map red colours to numbers (e.g. \#define LEDS_CONF_RED 1) + * + * \file + * Header file for the LED HAL * @{ */ - +/*---------------------------------------------------------------------------*/ #ifndef LEDS_H_ #define LEDS_H_ - -/* Allow platform to override LED numbering */ +/*---------------------------------------------------------------------------*/ #include "contiki.h" +#include "dev/gpio-hal.h" +#include +#include +/*---------------------------------------------------------------------------*/ +#if LEDS_CONF_LEGACY_API +/** + * \brief Define to 1 to enabled the legacy LED API. + */ +#define LEDS_LEGACY_API LEDS_CONF_LEGACY_API +#else +#define LEDS_LEGACY_API 0 +#endif +/*---------------------------------------------------------------------------*/ +/** + * \brief A default LED colour for non-existing LEDs + */ +#define LEDS_COLOUR_NONE 0x00 +/*---------------------------------------------------------------------------*/ +/* LED colour to number mappings. Applicable to both APIs */ +#ifdef LEDS_CONF_RED +#define LEDS_RED LEDS_CONF_RED +#else +#define LEDS_RED LEDS_COLOUR_NONE +#endif + +#ifdef LEDS_CONF_GREEN +#define LEDS_GREEN LEDS_CONF_GREEN +#else +#define LEDS_GREEN LEDS_COLOUR_NONE +#endif + +#ifdef LEDS_CONF_BLUE +#define LEDS_BLUE LEDS_CONF_BLUE +#else +#define LEDS_BLUE LEDS_COLOUR_NONE +#endif + +#ifdef LEDS_CONF_YELLOW +#define LEDS_YELLOW LEDS_CONF_YELLOW +#else +#define LEDS_YELLOW LEDS_COLOUR_NONE +#endif + +#ifdef LEDS_CONF_ORANGE +#define LEDS_ORANGE LEDS_CONF_ORANGE +#else +#define LEDS_ORANGE LEDS_COLOUR_NONE +#endif +/*---------------------------------------------------------------------------*/ +/** + * \brief The LED number + */ +typedef uint8_t leds_num_t; + +/** + * \brief An OR mask datatype to represents multiple LEDs. + */ +typedef uint8_t leds_mask_t; +/*---------------------------------------------------------------------------*/ +#if LEDS_LEGACY_API +/*---------------------------------------------------------------------------*/ +#ifdef LEDS_CONF_ALL +#define LEDS_ALL LEDS_CONF_ALL +#else +#define LEDS_ALL 7 +#endif +/*---------------------------------------------------------------------------*/ +void leds_blink(void); + +/* Legacy LED API arch-specific functions */ +void leds_arch_init(void); +leds_mask_t leds_arch_get(void); +void leds_arch_set(leds_mask_t leds); +/*---------------------------------------------------------------------------*/ +#else /* LEDS_LEGACY_API */ +/*---------------------------------------------------------------------------*/ +#ifdef LEDS_CONF_COUNT +#define LEDS_COUNT LEDS_CONF_COUNT +#else +/** + * \brief The number of LEDs present on a device + */ +#define LEDS_COUNT 0 +#endif +/*---------------------------------------------------------------------------*/ +/** + * \brief The OR mask representation of all device LEDs + */ +#define LEDS_ALL ((1 << LEDS_COUNT) - 1) +/*---------------------------------------------------------------------------*/ +#endif /* LEDS_LEGACY_API */ +/*---------------------------------------------------------------------------*/ +#define LEDS_LED1 0x00 /**< Convenience macro to refer to the 1st LED (LED 1) */ +#define LEDS_LED2 0x01 /**< Convenience macro to refer to the 2nd LED (LED 2) */ +#define LEDS_LED3 0x02 /**< Convenience macro to refer to the 3rd LED (LED 3) */ +#define LEDS_LED4 0x03 /**< Convenience macro to refer to the 4th LED (LED 4) */ +#define LEDS_LED5 0x04 /**< Convenience macro to refer to the 5th LED (LED 5) */ +/*---------------------------------------------------------------------------*/ +/** + * \brief A LED logical representation + * + * \e pin corresponds to the GPIO pin a LED is driven by, using GPIO HAL pin + * representation. + * + * \e negative_logic should be set to false if the LED is active low. + */ +typedef struct leds_s { + gpio_hal_pin_t pin; + bool negative_logic; +} leds_t; +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert a LED number to a mask representation + * \param l The pin number (normally a variable of type leds_num_t) + * \return An OR mask of type leds_mask_t + */ +#define LEDS_NUM_TO_MASK(l) (1 << (l)) +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialise the LED HAL + * + * This function will set corresponding LED GPIO pins to output and will also + * set the initial state of all LEDs to off. + */ void leds_init(void); /** - * Blink all LEDs. + * \brief Turn a single LED on + * \param led The led + * + * The \e led argument should be the LED's number, in other words one of the + * LED_Ln macros. + * + * This function will not change the state of other LEDs. */ -void leds_blink(void); - -#ifndef LEDS_GREEN -#define LEDS_GREEN 1 -#endif /* LEDS_GREEN */ -#ifndef LEDS_YELLOW -#define LEDS_YELLOW 2 -#endif /* LEDS_YELLOW */ -#ifndef LEDS_RED -#define LEDS_RED 4 -#endif /* LEDS_RED */ -#ifndef LEDS_BLUE -#define LEDS_BLUE LEDS_YELLOW -#endif /* LEDS_BLUE */ - -#ifdef LEDS_CONF_ALL -#define LEDS_ALL LEDS_CONF_ALL -#else /* LEDS_CONF_ALL */ -#define LEDS_ALL 7 -#endif /* LEDS_CONF_ALL */ +void leds_single_on(leds_num_t led); /** - * Returns the current status of all leds + * \brief Turn a single LED off + * \param led The led + * + * The \e led argument should be the LED's number, in other words one of the + * LED_Ln macros. + * + * This function will not change the state of other LEDs. */ -unsigned char leds_get(void); -void leds_set(unsigned char leds); -void leds_on(unsigned char leds); -void leds_off(unsigned char leds); -void leds_toggle(unsigned char leds); +void leds_single_off(leds_num_t led); /** - * Leds implementation + * \brief Toggle a single LED + * \param led The led + * + * The \e led argument should be the LED's number, in other words one of the + * LED_Ln macros. + * + * This function will not change the state of other LEDs. */ -void leds_arch_init(void); -unsigned char leds_arch_get(void); -void leds_arch_set(unsigned char leds); +void leds_single_toggle(leds_num_t led); +/** + * \brief Turn on multiple LEDs + * \param leds The leds to be turned on as an OR mask + * + * The \e led argument should be a bitwise mask of the LEDs to be changed. + * For example, to turn on LEDs 1 and 3, you should pass + * LED_NUM_TO_MASK(LED_L1) | LED_NUM_TO_MASK(LED_L3) = 1 | 4 = 5 + * + * This function will not change the state of other LEDs. + */ +void leds_on(leds_mask_t leds); + +/** + * \brief Turn off multiple LEDs + * \param leds The leds to be turned off as an OR mask + * + * The \e led argument should be a bitwise mask of the LEDs to be changed. + * For example, to turn on LEDs 1 and 3, you should pass + * LED_NUM_TO_MASK(LED_L1) | LED_NUM_TO_MASK(LED_L3) = 1 | 4 = 5 + * + * This function will not change the state of other LEDs. + */ +void leds_off(leds_mask_t leds); + +/** + * \brief Toggle multiple LEDs + * \param leds The leds to be toggled as an OR mask + * + * The \e led argument should be a bitwise mask of the LEDs to be changed. + * For example, to turn on LEDs 1 and 3, you should pass + * LED_NUM_TO_MASK(LED_L1) | LED_NUM_TO_MASK(LED_L3) = 1 | 4 = 5 + * + * This function will not change the state of other LEDs. + */ +void leds_toggle(leds_mask_t leds); + +/** + * \brief Set all LEDs to a specific state + * \param leds The state of all LEDs afer this function returns + * + * The \e led argument should be a bitwise mask of the LEDs to be changed. + * For example, to turn on LEDs 1 and 3, you should pass + * LED_NUM_TO_MASK(LED_L1) | LED_NUM_TO_MASK(LED_L3) = 1 | 4 = 5 + * + * This function will change the state of all LEDs. LEDs not set in the \e leds + * mask will be turned off. + */ +void leds_set(leds_mask_t leds); + +/** + * \brief Get the status of LEDs + * \return A bitwise mask indicating whether each individual LED is on or off + * + * The return value is a bitwise mask. If a bit is set then the corresponding + * LED is on. + */ +leds_mask_t leds_get(void); +/*---------------------------------------------------------------------------*/ #endif /* LEDS_H_ */ - -/** @} */ -/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From 424bee94643c959ffbf4c34b54201ce442c1d65a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 20:45:03 +0000 Subject: [PATCH 19/40] Add CC2538 GPIO conversion macro --- arch/cpu/cc2538/dev/gpio.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/cpu/cc2538/dev/gpio.h b/arch/cpu/cc2538/dev/gpio.h index a09ed8cfe..67b28cf0d 100644 --- a/arch/cpu/cc2538/dev/gpio.h +++ b/arch/cpu/cc2538/dev/gpio.h @@ -326,6 +326,14 @@ * number. */ #define GPIO_PORT_TO_BASE(PORT) (GPIO_A_BASE + ((PORT) << 12)) + +/** + * \brief Converts a port/pin pair to GPIO HAL pin number + * \param PORT The port number in the range 0 - 3 (GPIO_n_NUM). + * \param PIN The pin number in the range 0 - 7. + * \return The pin representation using GPIO HAL semantics + */ +#define GPIO_PORT_PIN_TO_GPIO_HAL_PIN(PORT, PIN) (((PORT) << 3) + (PIN)) /** @} */ /*---------------------------------------------------------------------------*/ /** \name GPIO Register offset declarations From f468fcd2a731413910d247f2f6ea795b62019218 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 18:57:35 +0000 Subject: [PATCH 20/40] Implement and use the new LED HAL (CC2538DK) --- arch/platform/cc2538dk/Makefile.cc2538dk | 2 +- arch/platform/cc2538dk/dev/board.h | 25 +++++---- arch/platform/cc2538dk/dev/leds-arch.c | 65 ++++++++++-------------- arch/platform/cc2538dk/platform.c | 2 +- 4 files changed, 44 insertions(+), 50 deletions(-) diff --git a/arch/platform/cc2538dk/Makefile.cc2538dk b/arch/platform/cc2538dk/Makefile.cc2538dk index c633782e9..e7be95c28 100644 --- a/arch/platform/cc2538dk/Makefile.cc2538dk +++ b/arch/platform/cc2538dk/Makefile.cc2538dk @@ -6,7 +6,7 @@ endif CONTIKI_TARGET_DIRS = . dev -CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c +CONTIKI_TARGET_SOURCEFILES += leds-arch.c CONTIKI_TARGET_SOURCEFILES += platform.c CONTIKI_TARGET_SOURCEFILES += sensors.c smartrf-sensors.c CONTIKI_TARGET_SOURCEFILES += button-sensor.c als-sensor.c diff --git a/arch/platform/cc2538dk/dev/board.h b/arch/platform/cc2538dk/dev/board.h index 6e3021ceb..0b2a4cd09 100644 --- a/arch/platform/cc2538dk/dev/board.h +++ b/arch/platform/cc2538dk/dev/board.h @@ -71,20 +71,25 @@ * @{ */ /*---------------------------------------------------------------------------*/ -#define LEDS_YELLOW 2 /**< LED2 (Yellow) -> PC1 */ -#define LEDS_GREEN 4 /**< LED3 (Green) -> PC2 */ -#define LEDS_ORANGE 8 /**< LED4 (Orange) -> PC3 */ +#define LEDS_CONF_YELLOW 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_ORANGE 4 + +#define LEDS_ARCH_L1_PORT GPIO_C_NUM +#define LEDS_ARCH_L1_PIN 1 +#define LEDS_ARCH_L2_PORT GPIO_C_NUM +#define LEDS_ARCH_L2_PIN 2 +#define LEDS_ARCH_L3_PORT GPIO_C_NUM +#define LEDS_ARCH_L3_PIN 3 #if USB_SERIAL_CONF_ENABLE -#define LEDS_CONF_ALL 14 -#define LEDS_RED LEDS_ORANGE +#define LEDS_CONF_COUNT 3 #else -#define LEDS_CONF_ALL 15 -#define LEDS_RED 1 /**< LED1 (Red) -> PC0 */ +#define LEDS_ARCH_L4_PORT GPIO_C_NUM +#define LEDS_ARCH_L4_PIN 0 +#define LEDS_CONF_RED 8 +#define LEDS_CONF_COUNT 4 #endif - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/cc2538dk/dev/leds-arch.c b/arch/platform/cc2538dk/dev/leds-arch.c index 661f46160..c849355b4 100644 --- a/arch/platform/cc2538dk/dev/leds-arch.c +++ b/arch/platform/cc2538dk/dev/leds-arch.c @@ -1,16 +1,16 @@ /* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. @@ -28,45 +28,34 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ -/** - * \addtogroup cc2538-smartrf - * @{ - * - * \defgroup cc2538dk-leds SmartRF06EB LED driver - * - * LED driver implementation for the TI SmartRF06EB + cc2538EM - * @{ - * - * \file - * LED driver implementation for the TI SmartRF06EB + cc2538EM - */ +/*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "reg.h" #include "dev/leds.h" -#include "dev/gpio.h" +#include "dev/gpio-hal.h" +#include "dev/gpio-hal-arch.h" -#define LEDS_GPIO_PIN_MASK LEDS_ALL +#include /*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - GPIO_SET_OUTPUT(GPIO_C_BASE, LEDS_GPIO_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return GPIO_READ_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - GPIO_WRITE_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK, leds); -} +const leds_t leds_arch_leds[] = { + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L1_PORT, LEDS_ARCH_L1_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L2_PORT, LEDS_ARCH_L2_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L3_PORT, LEDS_ARCH_L3_PIN), + .negative_logic = false + }, +#if !USB_SERIAL_CONF_ENABLE + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L4_PORT, LEDS_ARCH_L4_PIN), + .negative_logic = false + }, +#endif +}; /*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ + diff --git a/arch/platform/cc2538dk/platform.c b/arch/platform/cc2538dk/platform.c index 3897c6292..8add14292 100644 --- a/arch/platform/cc2538dk/platform.c +++ b/arch/platform/cc2538dk/platform.c @@ -74,7 +74,7 @@ #define LOG_LEVEL LOG_LEVEL_MAIN /*---------------------------------------------------------------------------*/ static void -fade(unsigned char l) +fade(leds_mask_t l) { volatile int i; int k, j; From e39472f7d08bc10501949e5ef26af16ddca0c0e9 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 20:52:32 +0000 Subject: [PATCH 21/40] Implement and use the new LED HAL (OpenMote) --- arch/platform/openmote-cc2538/board.h | 21 ++++-- arch/platform/openmote-cc2538/dev/leds-arch.c | 65 +++++++------------ arch/platform/openmote-cc2538/platform.c | 2 +- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/arch/platform/openmote-cc2538/board.h b/arch/platform/openmote-cc2538/board.h index 56724a753..f7fbfc6c2 100644 --- a/arch/platform/openmote-cc2538/board.h +++ b/arch/platform/openmote-cc2538/board.h @@ -63,14 +63,21 @@ * @{ */ /*---------------------------------------------------------------------------*/ -#define LEDS_RED 16 /**< LED1 (Red) -> PC4 */ -#define LEDS_YELLOW 64 /**< LED2 (Yellow) -> PC6 */ -#define LEDS_GREEN 128 /**< LED3 (Green) -> PC7 */ -#define LEDS_ORANGE 32 /**< LED4 (Orange) -> PC5 */ -#define LEDS_CONF_ALL 240 +#define LEDS_ARCH_L1_PORT GPIO_C_NUM +#define LEDS_ARCH_L1_PIN 4 +#define LEDS_ARCH_L2_PORT GPIO_C_NUM +#define LEDS_ARCH_L2_PIN 6 +#define LEDS_ARCH_L3_PORT GPIO_C_NUM +#define LEDS_ARCH_L3_PIN 7 +#define LEDS_ARCH_L4_PORT GPIO_C_NUM +#define LEDS_ARCH_L4_PIN 5 -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_YELLOW 2 +#define LEDS_CONF_GREEN 4 +#define LEDS_CONF_ORANGE 8 + +#define LEDS_CONF_COUNT 4 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/openmote-cc2538/dev/leds-arch.c b/arch/platform/openmote-cc2538/dev/leds-arch.c index 28454dacf..2bc13bed8 100644 --- a/arch/platform/openmote-cc2538/dev/leds-arch.c +++ b/arch/platform/openmote-cc2538/dev/leds-arch.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -26,48 +27,32 @@ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * This file is part of the Contiki operating system. - * - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup openmote-cc2538 - * @{ - * - * \defgroup openmote-leds OpenMote-CC2538 LED driver - * @{ - * - * \file - * LED driver implementation for the OpenMote-CC2538 platform */ /*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "reg.h" #include "dev/leds.h" -#include "dev/gpio.h" +#include "dev/gpio-hal.h" + +#include /*---------------------------------------------------------------------------*/ -#define LEDS_GPIO_PIN_MASK LEDS_ALL +const leds_t leds_arch_leds[] = { + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L1_PORT, LEDS_ARCH_L1_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L2_PORT, LEDS_ARCH_L2_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L3_PORT, LEDS_ARCH_L3_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L4_PORT, LEDS_ARCH_L4_PIN), + .negative_logic = false + }, +}; /*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - GPIO_SET_OUTPUT(GPIO_C_BASE, LEDS_GPIO_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return GPIO_READ_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - GPIO_WRITE_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK, leds); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ + + diff --git a/arch/platform/openmote-cc2538/platform.c b/arch/platform/openmote-cc2538/platform.c index df1d74a47..4b390e51b 100644 --- a/arch/platform/openmote-cc2538/platform.c +++ b/arch/platform/openmote-cc2538/platform.c @@ -82,7 +82,7 @@ void board_init(void); /*---------------------------------------------------------------------------*/ static void -fade(unsigned char l) +fade(leds_mask_t l) { volatile int i; int k, j; From ce4caf2c7c30b54df4b5c5c5b220154836a24f9b Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 18:57:49 +0000 Subject: [PATCH 22/40] Implement and use the new LED HAL (Zoul) --- arch/platform/zoul/Makefile.zoul | 2 +- arch/platform/zoul/dev/leds-arch.c | 61 ++++------- .../zoul/firefly-reva/Makefile.firefly-reva | 2 +- arch/platform/zoul/firefly-reva/board.h | 31 ++---- arch/platform/zoul/firefly/Makefile.firefly | 2 +- arch/platform/zoul/firefly/board.h | 31 ++---- arch/platform/zoul/orion/Makefile.orion | 2 +- arch/platform/zoul/orion/board.h | 31 ++---- arch/platform/zoul/platform.c | 2 +- .../zoul/remote-reva/Makefile.remote-reva | 2 +- arch/platform/zoul/remote-reva/board.h | 31 ++---- .../zoul/remote-revb/Makefile.remote-revb | 2 +- arch/platform/zoul/remote-revb/board.h | 31 ++---- .../platform/zoul/remote-revb/leds-res-arch.c | 103 ------------------ 14 files changed, 78 insertions(+), 255 deletions(-) delete mode 100644 arch/platform/zoul/remote-revb/leds-res-arch.c diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 252aa52d0..9ec38d805 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -31,7 +31,7 @@ PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET) -include $(PLATFORM_ROOT_DIR)/$(BOARD)/Makefile.$(BOARD) ### Include -CONTIKI_TARGET_SOURCEFILES += platform.c +CONTIKI_TARGET_SOURCEFILES += platform.c leds-arch.c CONTIKI_TARGET_SOURCEFILES += leds.c cc1200-zoul-arch.c CONTIKI_TARGET_SOURCEFILES += adc-zoul.c button-sensor.c zoul-sensors.c CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) diff --git a/arch/platform/zoul/dev/leds-arch.c b/arch/platform/zoul/dev/leds-arch.c index f09ed645c..eea4187c0 100644 --- a/arch/platform/zoul/dev/leds-arch.c +++ b/arch/platform/zoul/dev/leds-arch.c @@ -1,17 +1,16 @@ /* - * Copyright (c) 2015, Zolertia - http://www.zolertia.com - * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. @@ -29,45 +28,27 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ -/** - * \addtogroup zoul - * @{ - * - * \defgroup zoul-leds Zoul LED driver - * - * LED driver implementation for the Zoul-based platforms - * @{ - * - * \file - * LED driver implementation for the Zoul-based platforms - */ +/*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "reg.h" #include "dev/leds.h" -#include "dev/gpio.h" +#include "dev/gpio-hal.h" + +#include /*---------------------------------------------------------------------------*/ -#define LEDS_GPIO_PIN_MASK LEDS_ALL -/*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - GPIO_SET_OUTPUT(GPIO_D_BASE, LEDS_GPIO_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return GPIO_READ_PIN(GPIO_D_BASE, LEDS_GPIO_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - GPIO_WRITE_PIN(GPIO_D_BASE, LEDS_GPIO_PIN_MASK, leds); -} +const leds_t leds_arch_leds[] = { + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L1_PORT, LEDS_ARCH_L1_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L2_PORT, LEDS_ARCH_L2_PIN), + .negative_logic = false + }, + { + .pin = GPIO_PORT_PIN_TO_GPIO_HAL_PIN(LEDS_ARCH_L3_PORT, LEDS_ARCH_L3_PIN), + .negative_logic = false + }, +}; /*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ + diff --git a/arch/platform/zoul/firefly-reva/Makefile.firefly-reva b/arch/platform/zoul/firefly-reva/Makefile.firefly-reva index 50cb71997..afecf9fa5 100644 --- a/arch/platform/zoul/firefly-reva/Makefile.firefly-reva +++ b/arch/platform/zoul/firefly-reva/Makefile.firefly-reva @@ -1,2 +1,2 @@ MOTELIST_ZOLERTIA = firefly -BOARD_SOURCEFILES += board.c leds-arch.c +BOARD_SOURCEFILES += board.c diff --git a/arch/platform/zoul/firefly-reva/board.h b/arch/platform/zoul/firefly-reva/board.h index 4eaacac3a..784f9e902 100644 --- a/arch/platform/zoul/firefly-reva/board.h +++ b/arch/platform/zoul/firefly-reva/board.h @@ -98,29 +98,18 @@ * @{ */ /*---------------------------------------------------------------------------*/ -/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN_PIN 4 -#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ +#define LEDS_ARCH_L1_PORT GPIO_D_NUM +#define LEDS_ARCH_L1_PIN 5 +#define LEDS_ARCH_L2_PORT GPIO_D_NUM +#define LEDS_ARCH_L2_PIN 4 +#define LEDS_ARCH_L3_PORT GPIO_D_NUM +#define LEDS_ARCH_L3_PIN 3 -#define LEDS_BLUE_PIN 3 -#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_BLUE 4 -#define LEDS_RED_PIN 5 -#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ - -#define LEDS_GREEN_PORT_BASE GPIO_D_BASE -#define LEDS_BLUE_PORT_BASE GPIO_D_BASE -#define LEDS_RED_PORT_BASE GPIO_D_BASE - -#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) - -#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */ -#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */ -#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */ -#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */ - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 3 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/zoul/firefly/Makefile.firefly b/arch/platform/zoul/firefly/Makefile.firefly index 50cb71997..afecf9fa5 100644 --- a/arch/platform/zoul/firefly/Makefile.firefly +++ b/arch/platform/zoul/firefly/Makefile.firefly @@ -1,2 +1,2 @@ MOTELIST_ZOLERTIA = firefly -BOARD_SOURCEFILES += board.c leds-arch.c +BOARD_SOURCEFILES += board.c diff --git a/arch/platform/zoul/firefly/board.h b/arch/platform/zoul/firefly/board.h index e78dc22af..0367ea8df 100644 --- a/arch/platform/zoul/firefly/board.h +++ b/arch/platform/zoul/firefly/board.h @@ -98,29 +98,18 @@ * @{ */ /*---------------------------------------------------------------------------*/ -/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN_PIN 4 -#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ +#define LEDS_ARCH_L1_PORT GPIO_D_NUM +#define LEDS_ARCH_L1_PIN 5 +#define LEDS_ARCH_L2_PORT GPIO_D_NUM +#define LEDS_ARCH_L2_PIN 4 +#define LEDS_ARCH_L3_PORT GPIO_D_NUM +#define LEDS_ARCH_L3_PIN 3 -#define LEDS_BLUE_PIN 3 -#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_BLUE 4 -#define LEDS_RED_PIN 5 -#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ - -#define LEDS_GREEN_PORT_BASE GPIO_D_BASE -#define LEDS_BLUE_PORT_BASE GPIO_D_BASE -#define LEDS_RED_PORT_BASE GPIO_D_BASE - -#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) - -#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */ -#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */ -#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */ -#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */ - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 3 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/zoul/orion/Makefile.orion b/arch/platform/zoul/orion/Makefile.orion index 7c5804d39..e3ecb601b 100644 --- a/arch/platform/zoul/orion/Makefile.orion +++ b/arch/platform/zoul/orion/Makefile.orion @@ -3,4 +3,4 @@ MODULES += arch/dev/enc28j60 CC2538_ENC28J60_ARCH ?= gpio WITH_IP64 ?= 1 CFLAGS += -DUIP_FALLBACK_INTERFACE=ip64_uip_fallback_interface -BOARD_SOURCEFILES += board.c enc28j60-arch-$(CC2538_ENC28J60_ARCH).c leds-arch.c +BOARD_SOURCEFILES += board.c enc28j60-arch-$(CC2538_ENC28J60_ARCH).c diff --git a/arch/platform/zoul/orion/board.h b/arch/platform/zoul/orion/board.h index f1c22ad9e..ee80cc709 100644 --- a/arch/platform/zoul/orion/board.h +++ b/arch/platform/zoul/orion/board.h @@ -67,29 +67,18 @@ * @{ */ /*---------------------------------------------------------------------------*/ -/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN_PIN 4 -#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ +#define LEDS_ARCH_L1_PORT GPIO_D_NUM +#define LEDS_ARCH_L1_PIN 5 +#define LEDS_ARCH_L2_PORT GPIO_D_NUM +#define LEDS_ARCH_L2_PIN 4 +#define LEDS_ARCH_L3_PORT GPIO_D_NUM +#define LEDS_ARCH_L3_PIN 3 -#define LEDS_BLUE_PIN 3 -#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_BLUE 4 -#define LEDS_RED_PIN 5 -#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ - -#define LEDS_GREEN_PORT_BASE GPIO_D_BASE -#define LEDS_BLUE_PORT_BASE GPIO_D_BASE -#define LEDS_RED_PORT_BASE GPIO_D_BASE - -#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) - -#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */ -#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */ -#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */ -#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */ - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 3 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/zoul/platform.c b/arch/platform/zoul/platform.c index 4cf503162..2b0a394b1 100644 --- a/arch/platform/zoul/platform.c +++ b/arch/platform/zoul/platform.c @@ -82,7 +82,7 @@ void board_init(void); /*---------------------------------------------------------------------------*/ static void -fade(unsigned char l) +fade(leds_mask_t l) { volatile int i; int k, j; diff --git a/arch/platform/zoul/remote-reva/Makefile.remote-reva b/arch/platform/zoul/remote-reva/Makefile.remote-reva index 6b4a80e75..fcccdf0f4 100644 --- a/arch/platform/zoul/remote-reva/Makefile.remote-reva +++ b/arch/platform/zoul/remote-reva/Makefile.remote-reva @@ -1,4 +1,4 @@ MOTELIST_ZOLERTIA = remote -BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c leds-arch.c +BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc diff --git a/arch/platform/zoul/remote-reva/board.h b/arch/platform/zoul/remote-reva/board.h index dfd79b914..23722badd 100644 --- a/arch/platform/zoul/remote-reva/board.h +++ b/arch/platform/zoul/remote-reva/board.h @@ -102,29 +102,18 @@ * @{ */ /*---------------------------------------------------------------------------*/ -/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */ -#define LEDS_GREEN_PIN 4 -#define LEDS_GREEN (1 << LEDS_GREEN_PIN) /**< LED1 (Green) -> PD4 */ +#define LEDS_ARCH_L1_PORT GPIO_D_NUM +#define LEDS_ARCH_L1_PIN 5 +#define LEDS_ARCH_L2_PORT GPIO_D_NUM +#define LEDS_ARCH_L2_PIN 4 +#define LEDS_ARCH_L3_PORT GPIO_D_NUM +#define LEDS_ARCH_L3_PIN 3 -#define LEDS_BLUE_PIN 3 -#define LEDS_BLUE (1 << LEDS_BLUE_PIN) /**< LED2 (Blue) -> PD3 */ +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_BLUE 4 -#define LEDS_RED_PIN 5 -#define LEDS_RED (1 << LEDS_RED_PIN) /**< LED3 (Red) -> PD5 */ - -#define LEDS_GREEN_PORT_BASE GPIO_D_BASE -#define LEDS_BLUE_PORT_BASE GPIO_D_BASE -#define LEDS_RED_PORT_BASE GPIO_D_BASE - -#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) - -#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (24) */ -#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (48) */ -#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (40) */ -#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (56) */ - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 3 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/zoul/remote-revb/Makefile.remote-revb b/arch/platform/zoul/remote-revb/Makefile.remote-revb index d23362c32..fcccdf0f4 100644 --- a/arch/platform/zoul/remote-revb/Makefile.remote-revb +++ b/arch/platform/zoul/remote-revb/Makefile.remote-revb @@ -1,4 +1,4 @@ MOTELIST_ZOLERTIA = remote -BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c leds-res-arch.c power-mgmt.c +BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc diff --git a/arch/platform/zoul/remote-revb/board.h b/arch/platform/zoul/remote-revb/board.h index 601eced0c..244489562 100644 --- a/arch/platform/zoul/remote-revb/board.h +++ b/arch/platform/zoul/remote-revb/board.h @@ -105,29 +105,18 @@ * @{ */ /*---------------------------------------------------------------------------*/ -#define LEDS_RED 1 /**< LED1 (Red) -> PD4 */ -#define LEDS_RED_PIN 4 -#define LEDS_RED_PIN_MASK (1 << LEDS_RED_PIN) -#define LEDS_RED_PORT_BASE GPIO_D_BASE +#define LEDS_ARCH_L1_PORT GPIO_D_NUM +#define LEDS_ARCH_L1_PIN 4 +#define LEDS_ARCH_L2_PORT GPIO_B_NUM +#define LEDS_ARCH_L2_PIN 7 +#define LEDS_ARCH_L3_PORT GPIO_B_NUM +#define LEDS_ARCH_L3_PIN 6 -#define LEDS_GREEN 2 /**< LED2 (Green) -> PB7 */ -#define LEDS_GREEN_PIN 7 -#define LEDS_GREEN_PIN_MASK (1 << LEDS_GREEN_PIN) -#define LEDS_GREEN_PORT_BASE GPIO_B_BASE +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_BLUE 4 -#define LEDS_BLUE 4 /**< LED3 (Blue) -> PB6 */ -#define LEDS_BLUE_PIN 6 -#define LEDS_BLUE_PIN_MASK (1 << LEDS_BLUE_PIN) -#define LEDS_BLUE_PORT_BASE GPIO_B_BASE - -#define LEDS_CONF_ALL (LEDS_GREEN | LEDS_BLUE | LEDS_RED) /* 7 */ -#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /* 6 */ -#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /* 3 */ -#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /* 5 */ -#define LEDS_WHITE LEDS_ALL /* 7 */ - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 3 /** @} */ /*---------------------------------------------------------------------------*/ /** \name USB configuration diff --git a/arch/platform/zoul/remote-revb/leds-res-arch.c b/arch/platform/zoul/remote-revb/leds-res-arch.c deleted file mode 100644 index 59484c2ff..000000000 --- a/arch/platform/zoul/remote-revb/leds-res-arch.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2015, Zolertia - http://www.zolertia.com - * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/** - * \addtogroup zoul - * @{ - * - * \defgroup remote-revb-leds RE-Mote revision B arch LED - * - * LED driver implementation for the RE-Mote revision B - * @{ - * - * \file - * LED driver implementation for the RE-Mote revision B - */ -#include "contiki.h" -#include "reg.h" -#include "dev/leds.h" -#include "dev/gpio.h" -#include "dev/ioc.h" -/*---------------------------------------------------------------------------*/ -#define LEDS_PORTB_PIN_MASK (LEDS_GREEN_PIN_MASK | LEDS_BLUE_PIN_MASK) -/*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - /* Initialize LED2 (Green) and LED3 (Blue) */ - GPIO_SOFTWARE_CONTROL(GPIO_B_BASE, LEDS_PORTB_PIN_MASK); - GPIO_SET_OUTPUT(GPIO_B_BASE, LEDS_PORTB_PIN_MASK); - GPIO_CLR_PIN(GPIO_B_BASE, LEDS_PORTB_PIN_MASK); - - /* Initialize LED1 (Red) */ - GPIO_SOFTWARE_CONTROL(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK); - GPIO_SET_OUTPUT(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK); - GPIO_CLR_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - uint8_t mask_leds; - - mask_leds = GPIO_READ_PIN(LEDS_GREEN_PORT_BASE, LEDS_GREEN_PIN_MASK) == 0 ? 0: LEDS_GREEN; - mask_leds |= GPIO_READ_PIN(LEDS_BLUE_PORT_BASE, LEDS_BLUE_PIN_MASK) == 0 ? 0 : LEDS_BLUE; - mask_leds |= GPIO_READ_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK) == 0 ? 0 : LEDS_RED; - - return mask_leds; -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - if(leds & LEDS_GREEN) { - GPIO_SET_PIN(LEDS_GREEN_PORT_BASE, LEDS_GREEN_PIN_MASK); - } else { - GPIO_CLR_PIN(LEDS_GREEN_PORT_BASE, LEDS_GREEN_PIN_MASK); - } - - if(leds & LEDS_BLUE) { - GPIO_SET_PIN(LEDS_BLUE_PORT_BASE, LEDS_BLUE_PIN_MASK); - } else { - GPIO_CLR_PIN(LEDS_BLUE_PORT_BASE, LEDS_BLUE_PIN_MASK); - } - - if(leds & LEDS_RED) { - GPIO_SET_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK); - } else { - GPIO_CLR_PIN(LEDS_RED_PORT_BASE, LEDS_RED_PIN_MASK); - } -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ From f932e51128c64863f6e07831082ae354e06cd333 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 18:57:58 +0000 Subject: [PATCH 23/40] Implement the new LED HAL (SmartRF06 CC26xx/CC13xx) --- .../srf06-cc26xx/srf06/Makefile.srf06 | 2 +- .../srf06-cc26xx/srf06/cc13xx/board.h | 22 ++----- .../srf06-cc26xx/srf06/cc26xx/board.h | 22 ++----- arch/platform/srf06-cc26xx/srf06/leds-arch.c | 66 ++++--------------- 4 files changed, 24 insertions(+), 88 deletions(-) diff --git a/arch/platform/srf06-cc26xx/srf06/Makefile.srf06 b/arch/platform/srf06-cc26xx/srf06/Makefile.srf06 index 44d115ec8..bcfe21bca 100644 --- a/arch/platform/srf06-cc26xx/srf06/Makefile.srf06 +++ b/arch/platform/srf06-cc26xx/srf06/Makefile.srf06 @@ -2,7 +2,7 @@ CFLAGS += -DBOARD_SMARTRF06EB=1 CONTIKI_TARGET_DIRS += srf06 -BOARD_SOURCEFILES += leds-arch.c srf06-sensors.c button-sensor.c board.c +BOARD_SOURCEFILES += srf06-sensors.c button-sensor.c board.c BOARD_SOURCEFILES += als-sensor.c ### Signal that we can be programmed with cc2538-bsl diff --git a/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h b/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h index e210d82d8..bf12b2b09 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h +++ b/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h @@ -58,20 +58,16 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 /**< LED1 (Red) */ -#define LEDS_YELLOW 2 /**< LED2 (Yellow) */ -#define LEDS_GREEN 4 /**< LED3 (Green) */ -#define LEDS_ORANGE 8 /**< LED4 (Orange) */ - -#define LEDS_CONF_ALL 15 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 4 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_YELLOW 2 +#define LEDS_CONF_GREEN 4 +#define LEDS_CONF_ORANGE 8 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -84,12 +80,6 @@ #define BOARD_IOID_LED_2 IOID_27 #define BOARD_IOID_LED_3 IOID_7 #define BOARD_IOID_LED_4 IOID_6 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_2 (1 << BOARD_IOID_LED_2) -#define BOARD_LED_3 (1 << BOARD_IOID_LED_3) -#define BOARD_LED_4 (1 << BOARD_IOID_LED_4) -#define BOARD_LED_ALL (BOARD_LED_1 | BOARD_LED_2 | BOARD_LED_3 | \ - BOARD_LED_4) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h b/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h index 99f97fbf2..44080f474 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h +++ b/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h @@ -58,20 +58,16 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 /**< LED1 (Red) */ -#define LEDS_YELLOW 2 /**< LED2 (Yellow) */ -#define LEDS_GREEN 4 /**< LED3 (Green) */ -#define LEDS_ORANGE 8 /**< LED4 (Orange) */ - -#define LEDS_CONF_ALL 15 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 4 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_YELLOW 2 +#define LEDS_CONF_GREEN 4 +#define LEDS_CONF_ORANGE 8 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -84,12 +80,6 @@ #define BOARD_IOID_LED_2 IOID_27 #define BOARD_IOID_LED_3 IOID_7 #define BOARD_IOID_LED_4 IOID_6 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_2 (1 << BOARD_IOID_LED_2) -#define BOARD_LED_3 (1 << BOARD_IOID_LED_3) -#define BOARD_LED_4 (1 << BOARD_IOID_LED_4) -#define BOARD_LED_ALL (BOARD_LED_1 | BOARD_LED_2 | BOARD_LED_3 | \ - BOARD_LED_4) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/srf06/leds-arch.c b/arch/platform/srf06-cc26xx/srf06/leds-arch.c index 2a1627005..9de716b97 100644 --- a/arch/platform/srf06-cc26xx/srf06/leds-arch.c +++ b/arch/platform/srf06-cc26xx/srf06/leds-arch.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -28,63 +29,18 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /*---------------------------------------------------------------------------*/ -/** - * \addtogroup srf06-common-peripherals - * @{ - * - * \file - * Driver for the SmartRF06EB LEDs when a CC13xx/CC26xx EM is mounted on it - */ -/*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "dev/leds.h" -#include "ti-lib.h" -/*---------------------------------------------------------------------------*/ -static unsigned char c; -static int inited = 0; -/*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - if(inited) { - return; - } - inited = 1; +#include "dev/led.h" +#include "dev/gpio-hal.h" - ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_LED_1); - ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_LED_2); - ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_LED_3); - ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_LED_4); - - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); -} +#include /*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return c; -} +const led_t led_arch_leds[] = { + { .pin = BOARD_IOID_LED_1, .negative_logic = false }, + { .pin = BOARD_IOID_LED_2, .negative_logic = false }, + { .pin = BOARD_IOID_LED_3, .negative_logic = false }, + { .pin = BOARD_IOID_LED_4, .negative_logic = false }, +}; /*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - c = leds; - /* Clear everything */ - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); - if((leds & LEDS_RED) == LEDS_RED) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_1); - } - if((leds & LEDS_YELLOW) == LEDS_YELLOW) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_2); - } - if((leds & LEDS_GREEN) == LEDS_GREEN) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_3); - } - if((leds & LEDS_ORANGE) == LEDS_ORANGE) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_4); - } -} -/*---------------------------------------------------------------------------*/ -/** @} */ From 877c758aaf5ccce15323c2bf3545edd0945a06f9 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 20:46:02 +0000 Subject: [PATCH 24/40] Implement the new LED HAL (Launchpad CC26xx/CC13xx) --- .../srf06-cc26xx/launchpad/Makefile.launchpad | 2 +- .../srf06-cc26xx/launchpad/cc1310/board.h | 17 ++---- .../srf06-cc26xx/launchpad/cc1350/board.h | 17 ++---- .../srf06-cc26xx/launchpad/cc2650/board.h | 17 ++---- .../srf06-cc26xx/launchpad/leds-arch.c | 56 ++++--------------- 5 files changed, 23 insertions(+), 86 deletions(-) diff --git a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad index 54bd81ced..8676c4171 100644 --- a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad +++ b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad @@ -2,7 +2,7 @@ CFLAGS += -DBOARD_LAUNCHPAD=1 CONTIKI_TARGET_DIRS += launchpad common -BOARD_SOURCEFILES += board.c launchpad-sensors.c leds-arch.c button-sensor.c +BOARD_SOURCEFILES += board.c launchpad-sensors.c button-sensor.c BOARD_SOURCEFILES += ext-flash.c board-spi.c ### Signal that we can be programmed with cc2538-bsl diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h index 1d56d776a..d8a87e53a 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h @@ -55,20 +55,14 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 -#define LEDS_GREEN 2 -#define LEDS_YELLOW LEDS_GREEN -#define LEDS_ORANGE LEDS_RED - -#define LEDS_CONF_ALL 3 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 2 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_YELLOW 2 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -79,9 +73,6 @@ */ #define BOARD_IOID_LED_1 IOID_6 #define BOARD_IOID_LED_2 IOID_7 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_2 (1 << BOARD_IOID_LED_2) -#define BOARD_LED_ALL (BOARD_LED_1 | BOARD_LED_2) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h index 9b5019179..c80fb1326 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h @@ -55,20 +55,14 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 -#define LEDS_GREEN 2 -#define LEDS_YELLOW LEDS_GREEN -#define LEDS_ORANGE LEDS_RED - -#define LEDS_CONF_ALL 3 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 2 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_YELLOW 2 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -79,9 +73,6 @@ */ #define BOARD_IOID_LED_1 IOID_6 #define BOARD_IOID_LED_2 IOID_7 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_2 (1 << BOARD_IOID_LED_2) -#define BOARD_LED_ALL (BOARD_LED_1 | BOARD_LED_2) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h index 65a5bb766..1ea40957a 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h @@ -55,20 +55,14 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 -#define LEDS_GREEN 2 -#define LEDS_YELLOW LEDS_GREEN -#define LEDS_ORANGE LEDS_RED - -#define LEDS_CONF_ALL 3 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 2 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_YELLOW 2 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -79,9 +73,6 @@ */ #define BOARD_IOID_LED_1 IOID_6 #define BOARD_IOID_LED_2 IOID_7 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_2 (1 << BOARD_IOID_LED_2) -#define BOARD_LED_ALL (BOARD_LED_1 | BOARD_LED_2) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/leds-arch.c b/arch/platform/srf06-cc26xx/launchpad/leds-arch.c index 0d8385ad6..5d70dea40 100644 --- a/arch/platform/srf06-cc26xx/launchpad/leds-arch.c +++ b/arch/platform/srf06-cc26xx/launchpad/leds-arch.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -28,54 +29,17 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /*---------------------------------------------------------------------------*/ -/** - * \addtogroup launchpad-peripherals - * @{ - * - * \file - * Driver for LaunchPad LEDs - */ -/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/leds.h" - +#include "dev/gpio-hal.h" #include "ti-lib.h" -/*---------------------------------------------------------------------------*/ -static unsigned char c; -static int inited = 0; -/*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - if(inited) { - return; - } - inited = 1; - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_LED_1); - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_LED_2); +#include +/*---------------------------------------------------------------------------*/ +const leds_t leds_arch_leds[] = { + { .pin = BOARD_IOID_LED_1, .negative_logic = false }, + { .pin = BOARD_IOID_LED_2, .negative_logic = false }, +}; +/*---------------------------------------------------------------------------*/ - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return c; -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - c = leds; - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); - if((leds & LEDS_RED) == LEDS_RED) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_1); - } - if((leds & LEDS_YELLOW) == LEDS_YELLOW) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_2); - } -} -/*---------------------------------------------------------------------------*/ -/** @} */ From ab710a8ed0a74d26a04349a7693e1a328b229458 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 20:46:13 +0000 Subject: [PATCH 25/40] Implement the new LED HAL (Sensortag CC26xx/CC13xx) --- .../sensortag/cc1350/Makefile.cc1350 | 3 -- .../srf06-cc26xx/sensortag/cc1350/board.h | 15 ++---- .../srf06-cc26xx/sensortag/cc1350/leds-arch.c | 48 +++-------------- .../sensortag/cc2650/Makefile.cc2650 | 3 -- .../srf06-cc26xx/sensortag/cc2650/board.h | 17 ++---- .../srf06-cc26xx/sensortag/cc2650/leds-arch.c | 53 +++---------------- 6 files changed, 22 insertions(+), 117 deletions(-) diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 b/arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 index 3cacec197..cdae4c2b1 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/Makefile.cc1350 @@ -1,6 +1,3 @@ -### Add to the source list -BOARD_SOURCEFILES += leds-arch.c - ### Will allow the inclusion of the correct CPU makefile CPU_FAMILY = cc13xx diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h index dbd64e538..d9269c8ff 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h @@ -58,20 +58,13 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 -#define LEDS_GREEN LEDS_RED -#define LEDS_YELLOW LEDS_RED -#define LEDS_ORANGE LEDS_RED - -#define LEDS_CONF_ALL 1 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 1 +#define LEDS_CONF_RED 1 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -81,8 +74,6 @@ * @{ */ #define BOARD_IOID_LED_1 IOID_10 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_ALL BOARD_LED_1 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c b/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c index f4214628e..21b8cf968 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/leds-arch.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -28,50 +29,15 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /*---------------------------------------------------------------------------*/ -/** - * \addtogroup sensortag-cc13xx-peripherals - * @{ - * - * \file - * Driver for the Sensortag-CC1350 LEDs - */ -/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/leds.h" +#include "dev/gpio-hal.h" -#include "ti-lib.h" +#include /*---------------------------------------------------------------------------*/ -static unsigned char c; -static int inited = 0; +const leds_t leds_arch_leds[] = { + { .pin = BOARD_IOID_LED_1, .negative_logic = false }, +}; /*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - if(inited) { - return; - } - inited = 1; - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_LED_1); - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return c; -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - c = leds; - ti_lib_gpio_clear_dio(BOARD_IOID_LED_1); - - if((leds & LEDS_RED) == LEDS_RED) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_1); - } -} -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 b/arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 index 5b7cdadd9..e91cabda4 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/Makefile.cc2650 @@ -1,6 +1,3 @@ -### Add to the source list -BOARD_SOURCEFILES += leds-arch.c - ### Will allow the inclusion of the correct CPU makefile CPU_FAMILY = cc26xx diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h index 977712ef2..2794e633e 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h @@ -58,20 +58,14 @@ #include "ioc.h" /*---------------------------------------------------------------------------*/ /** - * \name LED configurations + * \name LED HAL configuration * * Those values are not meant to be modified by the user * @{ */ -#define LEDS_RED 1 -#define LEDS_GREEN 2 -#define LEDS_YELLOW LEDS_GREEN -#define LEDS_ORANGE LEDS_RED - -#define LEDS_CONF_ALL 3 - -/* Notify various examples that we have LEDs */ -#define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_COUNT 2 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -82,9 +76,6 @@ */ #define BOARD_IOID_LED_1 IOID_10 #define BOARD_IOID_LED_2 IOID_15 -#define BOARD_LED_1 (1 << BOARD_IOID_LED_1) -#define BOARD_LED_2 (1 << BOARD_IOID_LED_2) -#define BOARD_LED_ALL (BOARD_LED_1 | BOARD_LED_2) /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c b/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c index c36959063..cab4888b7 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/leds-arch.c @@ -1,10 +1,11 @@ /* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -28,54 +29,16 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /*---------------------------------------------------------------------------*/ -/** - * \addtogroup sensortag-cc26xx-peripherals - * @{ - * - * \file - * Driver for the Sensortag-CC26XX LEDs - */ -/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/leds.h" +#include "dev/gpio-hal.h" -#include "ti-lib.h" +#include /*---------------------------------------------------------------------------*/ -static unsigned char c; -static int inited = 0; +const leds_t leds_arch_leds[] = { + { .pin = BOARD_IOID_LED_1, .negative_logic = false }, + { .pin = BOARD_IOID_LED_2, .negative_logic = false }, +}; /*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ - if(inited) { - return; - } - inited = 1; - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_LED_1); - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_LED_2); - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - return c; -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ - c = leds; - ti_lib_gpio_clear_multi_dio(BOARD_LED_ALL); - - if((leds & LEDS_RED) == LEDS_RED) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_1); - } - if((leds & LEDS_YELLOW) == LEDS_YELLOW) { - ti_lib_gpio_set_dio(BOARD_IOID_LED_2); - } -} -/*---------------------------------------------------------------------------*/ -/** @} */ From b1537374fbe96bd853fcd7980b80cb2462d6ac5b Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 28 Feb 2018 23:03:26 +0000 Subject: [PATCH 26/40] Migrate to the new LED HAL (CC26xx/CC13xx) --- arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx | 3 +-- arch/platform/srf06-cc26xx/platform.c | 4 ++-- arch/platform/srf06-cc26xx/srf06/leds-arch.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx index 9d4966fb7..7bead9fff 100644 --- a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx @@ -14,8 +14,7 @@ CONTIKI_TARGET_DIRS += . PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET) -include $(PLATFORM_ROOT_DIR)/$(BOARD)/Makefile.$(notdir $(BOARD)) -CONTIKI_TARGET_SOURCEFILES += platform.c -CONTIKI_TARGET_SOURCEFILES += sensors.c leds.c +CONTIKI_TARGET_SOURCEFILES += platform.c leds-arch.c CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) diff --git a/arch/platform/srf06-cc26xx/platform.c b/arch/platform/srf06-cc26xx/platform.c index ac44b5b0f..6737c056e 100644 --- a/arch/platform/srf06-cc26xx/platform.c +++ b/arch/platform/srf06-cc26xx/platform.c @@ -47,8 +47,8 @@ #include "ti-lib.h" #include "contiki.h" #include "contiki-net.h" -#include "leds.h" #include "lpm.h" +#include "dev/leds.h" #include "dev/gpio-hal.h" #include "dev/oscillators.h" #include "ieee-addr.h" @@ -84,7 +84,7 @@ unsigned short node_id = 0; void board_init(void); /*---------------------------------------------------------------------------*/ static void -fade(unsigned char l) +fade(leds_mask_t l) { volatile int i; int k, j; diff --git a/arch/platform/srf06-cc26xx/srf06/leds-arch.c b/arch/platform/srf06-cc26xx/srf06/leds-arch.c index 9de716b97..fba996b39 100644 --- a/arch/platform/srf06-cc26xx/srf06/leds-arch.c +++ b/arch/platform/srf06-cc26xx/srf06/leds-arch.c @@ -30,12 +30,12 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "dev/led.h" +#include "dev/leds.h" #include "dev/gpio-hal.h" #include /*---------------------------------------------------------------------------*/ -const led_t led_arch_leds[] = { +const leds_t leds_arch_leds[] = { { .pin = BOARD_IOID_LED_1, .negative_logic = false }, { .pin = BOARD_IOID_LED_2, .negative_logic = false }, { .pin = BOARD_IOID_LED_3, .negative_logic = false }, From d52bfa0f2290da2508667debb5fa82aea79959e8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 21:08:12 +0000 Subject: [PATCH 27/40] Enable the legacy LED API for respective platforms --- arch/platform/cooja/contiki-conf.h | 2 ++ arch/platform/jn516x/jn516x-def.h | 2 ++ arch/platform/native/contiki-conf.h | 2 ++ arch/platform/nrf52dk/nrf52dk-def.h | 1 + arch/platform/sky/sky-def.h | 2 ++ 5 files changed, 9 insertions(+) diff --git a/arch/platform/cooja/contiki-conf.h b/arch/platform/cooja/contiki-conf.h index 4a8e17c64..5069e94e5 100644 --- a/arch/platform/cooja/contiki-conf.h +++ b/arch/platform/cooja/contiki-conf.h @@ -46,6 +46,8 @@ #define COOJA 1 +#define LEDS_CONF_LEGACY_API 1 + #ifndef EEPROM_CONF_SIZE #define EEPROM_CONF_SIZE 1024 #endif diff --git a/arch/platform/jn516x/jn516x-def.h b/arch/platform/jn516x/jn516x-def.h index 2526d2698..596d55333 100644 --- a/arch/platform/jn516x/jn516x-def.h +++ b/arch/platform/jn516x/jn516x-def.h @@ -196,6 +196,8 @@ typedef uint32_t rtimer_clock_t; #define PLATFORM_HAS_SHT11 0 #define PLATFORM_HAS_RADIO 1 +#define LEDS_CONF_LEGACY_API 1 + #define PLATFORM_CONF_PROVIDES_MAIN_LOOP 1 /* CPU target speed in Hz diff --git a/arch/platform/native/contiki-conf.h b/arch/platform/native/contiki-conf.h index eef8b0a83..b8a43a604 100644 --- a/arch/platform/native/contiki-conf.h +++ b/arch/platform/native/contiki-conf.h @@ -66,6 +66,8 @@ typedef int32_t s32_t; typedef unsigned int uip_stats_t; +#define LEDS_CONF_LEGACY_API 1 + #ifndef UIP_CONF_BYTE_ORDER #define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN #endif diff --git a/arch/platform/nrf52dk/nrf52dk-def.h b/arch/platform/nrf52dk/nrf52dk-def.h index ea4060ca2..b5de033e4 100644 --- a/arch/platform/nrf52dk/nrf52dk-def.h +++ b/arch/platform/nrf52dk/nrf52dk-def.h @@ -60,6 +60,7 @@ * @{ */ #define PLATFORM_HAS_LEDS 1 +#define LEDS_CONF_LEGACY_API 1 #define LEDS_1 (1 << (LED_1 - LED_START)) // 1 #define LEDS_2 (1 << (LED_2 - LED_START)) // 2 diff --git a/arch/platform/sky/sky-def.h b/arch/platform/sky/sky-def.h index 0fa6ee29f..edab43ee7 100644 --- a/arch/platform/sky/sky-def.h +++ b/arch/platform/sky/sky-def.h @@ -75,6 +75,8 @@ #define LEDS_CONF_GREEN 0x20 #define LEDS_CONF_YELLOW 0x40 +#define LEDS_CONF_LEGACY_API 1 + /* DCO speed resynchronization for more robust UART, etc. */ #ifndef DCOSYNCH_CONF_ENABLED #define DCOSYNCH_CONF_ENABLED (!(MAC_CONF_WITH_TSCH)) /* TSCH needs timerB From 0dfd39adcf17b82aaa3ca750976ea05410dc4d83 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 28 Feb 2018 21:32:28 +0000 Subject: [PATCH 28/40] Adjust data types for legacy LED API implementations --- arch/cpu/msp430/leds-arch.c | 6 +++--- arch/platform/cooja/dev/leds-arch.c | 6 +++--- arch/platform/jn516x/dev/dongle/leds-arch.c | 6 +++--- arch/platform/native/dev/leds-arch.c | 6 +++--- arch/platform/nrf52dk/dev/leds-arch.c | 6 +++--- arch/platform/nrf52dk/nrf52dk-def.h | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/arch/cpu/msp430/leds-arch.c b/arch/cpu/msp430/leds-arch.c index fe63d8ae4..c8131ee3e 100644 --- a/arch/cpu/msp430/leds-arch.c +++ b/arch/cpu/msp430/leds-arch.c @@ -46,10 +46,10 @@ leds_arch_init(void) LEDS_PxOUT |= (LEDS_CONF_RED | LEDS_CONF_GREEN | LEDS_CONF_YELLOW); } /*---------------------------------------------------------------------------*/ -unsigned char +leds_mask_t leds_arch_get(void) { - unsigned char leds; + leds_mask_t leds; leds = LEDS_PxOUT; return ((leds & LEDS_CONF_RED) ? 0 : LEDS_RED) | ((leds & LEDS_CONF_GREEN) ? 0 : LEDS_GREEN) @@ -57,7 +57,7 @@ leds_arch_get(void) } /*---------------------------------------------------------------------------*/ void -leds_arch_set(unsigned char leds) +leds_arch_set(leds_mask_t leds) { LEDS_PxOUT = (LEDS_PxOUT & ~(LEDS_CONF_RED|LEDS_CONF_GREEN|LEDS_CONF_YELLOW)) | ((leds & LEDS_RED) ? 0 : LEDS_CONF_RED) diff --git a/arch/platform/cooja/dev/leds-arch.c b/arch/platform/cooja/dev/leds-arch.c index db91e9baa..b65df2945 100644 --- a/arch/platform/cooja/dev/leds-arch.c +++ b/arch/platform/cooja/dev/leds-arch.c @@ -34,18 +34,18 @@ const struct simInterface leds_interface; // COOJA variables -unsigned char simLedsValue; +leds_mask_t simLedsValue; /*-----------------------------------------------------------------------------------*/ void leds_arch_init() { simLedsValue = 0; } /*-----------------------------------------------------------------------------------*/ -unsigned char leds_arch_get() { +leds_mask_t leds_arch_get() { return simLedsValue; } /*-----------------------------------------------------------------------------------*/ -void leds_arch_set(unsigned char leds) { +void leds_arch_set(leds_mask_t leds) { if(leds != simLedsValue) { simLedsValue = leds; } diff --git a/arch/platform/jn516x/dev/dongle/leds-arch.c b/arch/platform/jn516x/dev/dongle/leds-arch.c index 5eff3c63e..513d52b76 100644 --- a/arch/platform/jn516x/dev/dongle/leds-arch.c +++ b/arch/platform/jn516x/dev/dongle/leds-arch.c @@ -38,7 +38,7 @@ #define LED_G (1 << 16) #define LED_R (1 << 17) -static volatile uint8_t leds; +static volatile leds_mask_t leds; /*---------------------------------------------------------------------------*/ void @@ -49,14 +49,14 @@ leds_arch_init(void) leds = 0; } /*---------------------------------------------------------------------------*/ -unsigned char +leds_mask_t leds_arch_get(void) { return leds; } /*---------------------------------------------------------------------------*/ void -leds_arch_set(unsigned char c) +leds_arch_set(leds_mask_t c) { uint32 on_mask = 0; uint32 off_mask = 0; diff --git a/arch/platform/native/dev/leds-arch.c b/arch/platform/native/dev/leds-arch.c index 1308c57dc..07addc84e 100644 --- a/arch/platform/native/dev/leds-arch.c +++ b/arch/platform/native/dev/leds-arch.c @@ -38,7 +38,7 @@ */ #include "dev/leds.h" -static unsigned char leds; +static leds_mask_t leds; /*---------------------------------------------------------------------------*/ void leds_arch_init(void) @@ -46,14 +46,14 @@ leds_arch_init(void) leds = 0; } /*---------------------------------------------------------------------------*/ -unsigned char +leds_mask_t leds_arch_get(void) { return leds; } /*---------------------------------------------------------------------------*/ void -leds_arch_set(unsigned char l) +leds_arch_set(leds_mask_t l) { leds = l; } diff --git a/arch/platform/nrf52dk/dev/leds-arch.c b/arch/platform/nrf52dk/dev/leds-arch.c index 019589493..cda1317ef 100644 --- a/arch/platform/nrf52dk/dev/leds-arch.c +++ b/arch/platform/nrf52dk/dev/leds-arch.c @@ -55,14 +55,14 @@ leds_arch_init(void) LEDS_OFF(LEDS_MASK); } /*---------------------------------------------------------------------------*/ -unsigned char +leds_mask_t leds_arch_get(void) { - return (unsigned char)(LED_IS_ON(LEDS_MASK) >> LED_START); + return (leds_mask_t)(LED_IS_ON(LEDS_MASK) >> LED_START); } /*---------------------------------------------------------------------------*/ void -leds_arch_set(unsigned char leds) +leds_arch_set(leds_mask_t leds) { unsigned int mask = (unsigned int)leds << LED_START; LEDS_OFF(LEDS_MASK); diff --git a/arch/platform/nrf52dk/nrf52dk-def.h b/arch/platform/nrf52dk/nrf52dk-def.h index b5de033e4..0e387f0f0 100644 --- a/arch/platform/nrf52dk/nrf52dk-def.h +++ b/arch/platform/nrf52dk/nrf52dk-def.h @@ -67,10 +67,10 @@ #define LEDS_3 (1 << (LED_3 - LED_START)) // 4 #define LEDS_4 (1 << (LED_4 - LED_START)) // 8 -#define LEDS_GREEN LEDS_1 -#define LEDS_YELLOW LEDS_2 -#define LEDS_RED LEDS_3 -#define LEDS_BLUE LEDS_4 +#define LEDS_CONF_GREEN LEDS_1 +#define LEDS_CONF_YELLOW LEDS_2 +#define LEDS_CONF_RED LEDS_3 +#define LEDS_CONF_BLUE LEDS_4 #define LEDS_CONF_ALL (LEDS_1 | LEDS_2 | LEDS_3 | LEDS_4) From c8debbac225e586dca365ac7f3f3410c4a0fc3a1 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 28 Feb 2018 02:17:49 +0000 Subject: [PATCH 29/40] Add RGB LED driver --- arch/dev/rgb-led/rgb-led.c | 62 ++++++++++++++++++++++ arch/dev/rgb-led/rgb-led.h | 89 ++++++++++++++++++++++++++++++++ arch/platform/zoul/Makefile.zoul | 2 +- 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 arch/dev/rgb-led/rgb-led.c create mode 100644 arch/dev/rgb-led/rgb-led.h diff --git a/arch/dev/rgb-led/rgb-led.c b/arch/dev/rgb-led/rgb-led.c new file mode 100644 index 000000000..521583022 --- /dev/null +++ b/arch/dev/rgb-led/rgb-led.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup rgb-led + * @{ + * + * \file + * Implementation of the RGB LED driver. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +#include "dev/rgb-led/rgb-led.h" +/*---------------------------------------------------------------------------*/ +void +rgb_led_off(void) +{ + leds_off(LEDS_ALL); +} +/*----------------------------------------------------------------------------*/ +void +rgb_led_set(uint8_t colour) +{ + leds_mask_t leds = + ((colour & RGB_LED_RED) ? LEDS_RED : LEDS_COLOUR_NONE) | + ((colour & RGB_LED_GREEN) ? LEDS_GREEN : LEDS_COLOUR_NONE) | + ((colour & RGB_LED_BLUE) ? LEDS_BLUE : LEDS_COLOUR_NONE); + + leds_off(LEDS_ALL); + leds_on(leds); +} +/*----------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/dev/rgb-led/rgb-led.h b/arch/dev/rgb-led/rgb-led.h new file mode 100644 index 000000000..d0cd81d38 --- /dev/null +++ b/arch/dev/rgb-led/rgb-led.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#ifndef RGB_LED_H_ +#define RGB_LED_H_ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup dev + * @{ + */ +/*---------------------------------------------------------------------------*/ +/** + * \defgroup rgb-led Generic RGB LED driver + * + * This is a driver for a tri-color RGB LED part, such as for example the + * Broadcom (ex Avago Technologies) PLCC-4 Tricolor Black Surface LED present + * on all Zolertia Zoul-based boards. + * + * + * This driver sits on top of the LED HAL. Therefore, any port that wishes to + * use this driver should first implement the GPIO HAL and the new LED API. + * This driver will set the colour of the RGB LED by using combinations of + * LED_RED, LED_GREEN and LED_BLUE. Therefore, those must be correctly defined + * by the platform configuration. + * @{ + * + * \file + * Header file for the RGB LED driver. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" + +#include +/*---------------------------------------------------------------------------*/ +#define RGB_LED_RED 1 +#define RGB_LED_GREEN 2 +#define RGB_LED_BLUE 4 +#define RGB_LED_MAGENTA (RGB_LED_RED | RGB_LED_BLUE) +#define RGB_LED_YELLOW (RGB_LED_RED | RGB_LED_GREEN) +#define RGB_LED_CYAN (RGB_LED_GREEN | RGB_LED_BLUE ) +#define RGB_LED_WHITE (RGB_LED_RED | RGB_LED_GREEN | RGB_LED_BLUE) +/*---------------------------------------------------------------------------*/ +/** + * \brief Turn off the RGB LED + */ +void rgb_led_off(void); + +/** + * \brief Set the colour of the RGB LED + * \param colour The colour to set + * + * \e colour can take the value of one of the RGB_LED_xyz defines. + */ +void rgb_led_set(uint8_t colour); +/*---------------------------------------------------------------------------*/ +#endif /* RGB_LED_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 9ec38d805..5f6bfba42 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -44,7 +44,7 @@ CLEAN += *.zoul CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 -MODULES += arch/dev/cc1200 os/storage/cfs +MODULES += arch/dev/cc1200 arch/dev/rgb-led os/storage/cfs BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py From 21151279c299eca5990f6f543d760b876aaada2d Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 21:18:32 +0000 Subject: [PATCH 30/40] Remove LED use from examples that don't really need them --- examples/libs/trickle-library/trickle-library.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/libs/trickle-library/trickle-library.c b/examples/libs/trickle-library/trickle-library.c index 30e02caf0..c449aade9 100644 --- a/examples/libs/trickle-library/trickle-library.c +++ b/examples/libs/trickle-library/trickle-library.c @@ -36,7 +36,6 @@ #include "contiki-net.h" #include "lib/trickle-timer.h" -#include "dev/leds.h" #include "lib/random.h" #include @@ -80,7 +79,6 @@ AUTOSTART_PROCESSES(&trickle_protocol_process); static void tcpip_handler(void) { - leds_on(LEDS_GREEN); if(uip_newdata()) { PRINTF("At %lu (I=%lu, c=%u): ", (unsigned long)clock_time(), (unsigned long)tt.i_cur, tt.c); @@ -109,7 +107,6 @@ tcpip_handler(void) tt.ct.etimer.timer.interval)); } } - leds_off(LEDS_GREEN); return; } /*---------------------------------------------------------------------------*/ @@ -126,8 +123,6 @@ trickle_tx(void *ptr, uint8_t suppress) return; } - leds_on(LEDS_RED); - PRINTF("At %lu (I=%lu, c=%u): ", (unsigned long)clock_time(), (unsigned long)loc_tt->i_cur, loc_tt->c); @@ -144,8 +139,6 @@ trickle_tx(void *ptr, uint8_t suppress) /* Restore to 'accept incoming from any IP' */ uip_create_unspecified(&trickle_conn->ripaddr); - - leds_off(LEDS_RED); } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(trickle_protocol_process, ev, data) From db058b166c719611750d9ac0c00713ef7f52b2bf Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 21:39:56 +0000 Subject: [PATCH 31/40] Migrate to LED HAL (CoAP example) --- examples/coap/resources/res-leds.c | 7 ++++--- examples/coap/resources/res-toggle.c | 9 ++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/coap/resources/res-leds.c b/examples/coap/resources/res-leds.c index 243d438ae..d601e49f5 100644 --- a/examples/coap/resources/res-leds.c +++ b/examples/coap/resources/res-leds.c @@ -37,12 +37,13 @@ */ #include "contiki.h" - -#if PLATFORM_HAS_LEDS -#include #include "coap-engine.h" #include "dev/leds.h" +#include + +#if PLATFORM_HAS_LEDS || LEDS_COUNT + #define DEBUG 0 #if DEBUG #include diff --git a/examples/coap/resources/res-toggle.c b/examples/coap/resources/res-toggle.c index 7f341c4f8..b90ac77c7 100644 --- a/examples/coap/resources/res-toggle.c +++ b/examples/coap/resources/res-toggle.c @@ -37,14 +37,13 @@ */ #include "contiki.h" - -#if PLATFORM_HAS_LEDS - -#include -#include "contiki.h" #include "coap-engine.h" #include "dev/leds.h" +#include + +#if PLATFORM_HAS_LEDS || LEDS_COUNT + static void res_post_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); /* A simple actuator example. Toggles the red led */ From a1b9ba26309367bb9b53070423c07d52916177bb Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 21:40:19 +0000 Subject: [PATCH 32/40] Migrate to LED HAL (IPSO Objects) --- examples/ipso-objects/example-ipso-objects.c | 5 +++-- os/services/ipso-objects/ipso-leds-control.c | 6 +++++- os/services/ipso-objects/ipso-objects.c | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/ipso-objects/example-ipso-objects.c b/examples/ipso-objects/example-ipso-objects.c index aa565603b..013c62205 100644 --- a/examples/ipso-objects/example-ipso-objects.c +++ b/examples/ipso-objects/example-ipso-objects.c @@ -46,6 +46,7 @@ #include "services/ipso-objects/ipso-objects.h" #include "services/ipso-objects/ipso-sensor-template.h" #include "services/ipso-objects/ipso-control-template.h" +#include "dev/leds.h" #define DEBUG DEBUG_NONE #include "net/ipv6/uip-debug.h" @@ -98,9 +99,9 @@ static lwm2m_status_t leds_set_val(ipso_control_t *control, uint8_t value) { if(value > 0) { - leds_on(LEDS_YELLOW); + leds_single_on(LEDS_LED1); } else { - leds_off(LEDS_YELLOW); + leds_single_off(LEDS_LED1); } return LWM2M_STATUS_OK; } diff --git a/os/services/ipso-objects/ipso-leds-control.c b/os/services/ipso-objects/ipso-leds-control.c index 8cfbdac41..2c64da328 100644 --- a/os/services/ipso-objects/ipso-leds-control.c +++ b/os/services/ipso-objects/ipso-leds-control.c @@ -56,11 +56,15 @@ #define PRINTF(...) #endif +#if LEDS_LEGACY_API #if LEDS_ALL & LEDS_BLUE || LEDS_ALL & LEDS_RED || LEDS_ALL & LEDS_BLUE #define LEDS_CONTROL_NUMBER (((LEDS_ALL & LEDS_BLUE) ? 1 : 0) + ((LEDS_ALL & LEDS_RED) ? 1 : 0) + ((LEDS_ALL & LEDS_GREEN) ? 1 : 0)) #else #define LEDS_CONTROL_NUMBER 1 #endif +#else /* LEDS_LEGACY_API */ +#define LEDS_CONTROL_NUMBER LEDS_COUNT +#endif /* LEDS_LEGACY_API */ typedef struct led_state { ipso_control_t control; @@ -72,7 +76,7 @@ static led_state_t leds_controls[LEDS_CONTROL_NUMBER]; static lwm2m_status_t set_value(ipso_control_t *control, uint8_t value) { -#if PLATFORM_HAS_LEDS +#if PLATFORM_HAS_LEDS || LEDS_COUNT led_state_t *state; state = (led_state_t *)control; diff --git a/os/services/ipso-objects/ipso-objects.c b/os/services/ipso-objects/ipso-objects.c index b1138ca09..f8538ee43 100644 --- a/os/services/ipso-objects/ipso-objects.c +++ b/os/services/ipso-objects/ipso-objects.c @@ -42,6 +42,7 @@ */ #include "contiki.h" +#include "dev/leds.h" #include "ipso-objects.h" /*---------------------------------------------------------------------------*/ void @@ -58,7 +59,7 @@ ipso_objects_init(void) #ifdef IPSO_LIGHT_CONTROL ipso_light_control_init(); -#elif PLATFORM_HAS_LEDS +#elif PLATFORM_HAS_LEDS || LEDS_COUNT ipso_leds_control_init(); #endif } From ad32bdd070d91884706f7657e1ad21b221782b4a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 26 Feb 2018 01:41:22 +0000 Subject: [PATCH 33/40] Migrate to LED HAL (GPIO HAL example) --- examples/dev/gpio-hal/zoul/pins.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/dev/gpio-hal/zoul/pins.c b/examples/dev/gpio-hal/zoul/pins.c index 950254088..ff44bf4d1 100644 --- a/examples/dev/gpio-hal/zoul/pins.c +++ b/examples/dev/gpio-hal/zoul/pins.c @@ -32,11 +32,9 @@ #include "contiki.h" #include "dev/gpio-hal.h" /*---------------------------------------------------------------------------*/ -#define BASE_TO_PORT_NUM(base) (((base) - GPIO_A_BASE) >> 12) - -gpio_hal_pin_t out_pin1 = (BASE_TO_PORT_NUM(LEDS_GREEN_PORT_BASE) << 3) + LEDS_GREEN_PIN; -gpio_hal_pin_t out_pin2 = (BASE_TO_PORT_NUM(LEDS_BLUE_PORT_BASE) << 3) + LEDS_BLUE_PIN; -gpio_hal_pin_t out_pin3 = (BASE_TO_PORT_NUM(LEDS_RED_PORT_BASE) << 3) + LEDS_RED_PIN; +gpio_hal_pin_t out_pin1 = (LEDS_ARCH_L1_PORT << 3) + LEDS_ARCH_L1_PIN; +gpio_hal_pin_t out_pin2 = (LEDS_ARCH_L2_PORT << 3) + LEDS_ARCH_L2_PIN; +gpio_hal_pin_t out_pin3 = (LEDS_ARCH_L3_PORT << 3) + LEDS_ARCH_L3_PIN; /*---------------------------------------------------------------------------*/ gpio_hal_pin_t btn_pin = (BUTTON_USER_PORT << 3) + BUTTON_USER_PIN; /*---------------------------------------------------------------------------*/ From 40ca7d0443f2eb3cd673bc65a1a74298ffa0cea5 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 25 Feb 2018 22:24:36 +0000 Subject: [PATCH 34/40] Migrate to LED HAL (Zoul examples) --- examples/platform-specific/zoul/rev-b/test-power-mgmt.c | 2 +- examples/platform-specific/zoul/test-grove-gyro.c | 2 +- examples/platform-specific/zoul/test-tsl256x.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/platform-specific/zoul/rev-b/test-power-mgmt.c b/examples/platform-specific/zoul/rev-b/test-power-mgmt.c index 0bb364aba..942a01933 100644 --- a/examples/platform-specific/zoul/rev-b/test-power-mgmt.c +++ b/examples/platform-specific/zoul/rev-b/test-power-mgmt.c @@ -136,7 +136,7 @@ PROCESS_THREAD(test_remote_pm, ev, data) printf("PM: Soft shutdown, timeout set to %lu\n", pm_get_timeout()); leds_off(LEDS_ALL); - leds_on(LEDS_PURPLE); + leds_on(LEDS_RED); /* Wait just enough to be able to check the LED result */ etimer_set(&et, CLOCK_SECOND * 3); diff --git a/examples/platform-specific/zoul/test-grove-gyro.c b/examples/platform-specific/zoul/test-grove-gyro.c index 978aa69f8..74ff66e03 100644 --- a/examples/platform-specific/zoul/test-grove-gyro.c +++ b/examples/platform-specific/zoul/test-grove-gyro.c @@ -65,7 +65,7 @@ gyro_interrupt_callback(uint8_t status) * returns the outcome of the read operation, check to validate if the * data is valid to read */ - leds_toggle(LEDS_PURPLE); + leds_toggle(LEDS_RED); printf("Gyro: X_axis %u, Y_axis %u, Z_axis %u\n", gyro_values.x, gyro_values.y, diff --git a/examples/platform-specific/zoul/test-tsl256x.c b/examples/platform-specific/zoul/test-tsl256x.c index ed6f72327..0e6fce588 100644 --- a/examples/platform-specific/zoul/test-tsl256x.c +++ b/examples/platform-specific/zoul/test-tsl256x.c @@ -63,7 +63,7 @@ void light_interrupt_callback(uint8_t value) { printf("* Light sensor interrupt!\n"); - leds_toggle(LEDS_PURPLE); + leds_toggle(LEDS_RED); } /*---------------------------------------------------------------------------*/ PROCESS_THREAD(remote_tsl256x_process, ev, data) From 92ab28bc8fffb93362d1c3395b5725549ea6d396 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 1 Mar 2018 00:17:30 +0000 Subject: [PATCH 35/40] Add LED HAL example and tests --- examples/dev/leds/Makefile | 8 +++ examples/dev/leds/README.md | 15 +++++ examples/dev/leds/leds-example.c | 82 ++++++++++++++++++++++++++ tests/02-compile-arm-ports-01/Makefile | 8 +++ tests/03-compile-arm-ports-02/Makefile | 6 ++ 5 files changed, 119 insertions(+) create mode 100644 examples/dev/leds/Makefile create mode 100644 examples/dev/leds/README.md create mode 100644 examples/dev/leds/leds-example.c diff --git a/examples/dev/leds/Makefile b/examples/dev/leds/Makefile new file mode 100644 index 000000000..7c5f5f592 --- /dev/null +++ b/examples/dev/leds/Makefile @@ -0,0 +1,8 @@ +CONTIKI_PROJECT = leds-example +CONTIKI = ../../.. + +MODULES_REL += $(TARGET) + +all: $(CONTIKI_PROJECT) + +include $(CONTIKI)/Makefile.include diff --git a/examples/dev/leds/README.md b/examples/dev/leds/README.md new file mode 100644 index 000000000..05bdc20ba --- /dev/null +++ b/examples/dev/leds/README.md @@ -0,0 +1,15 @@ +# LED HAL Example +This example demonstrates and tests the functionality of the LED HAL. You can +use it to: + +* Understand the logic of the LED HAL. +* Test your implementation of arch-specific LED HAL components if you are +developing a new port. + +This example assumes a device with at least 1 LED. + +# Supported devices +This example is expected to work off-the-shelf on the following boards: + +* All CC13xx/CC26xx devices +* All CC2538 devices diff --git a/examples/dev/leds/leds-example.c b/examples/dev/leds/leds-example.c new file mode 100644 index 000000000..9015e75ce --- /dev/null +++ b/examples/dev/leds/leds-example.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +#include "sys/etimer.h" + +#include +/*---------------------------------------------------------------------------*/ +static struct etimer et; +static uint8_t counter; +/*---------------------------------------------------------------------------*/ +PROCESS(leds_example, "LED HAL Example"); +AUTOSTART_PROCESSES(&leds_example); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(leds_example, ev, data) +{ + PROCESS_BEGIN(); + + counter = 0; + + etimer_set(&et, CLOCK_SECOND); + + while(1) { + + PROCESS_YIELD(); + + if(ev == PROCESS_EVENT_TIMER && data == &et) { + if((counter & 7) == 0) { + leds_set(LEDS_ALL); + } else if((counter & 7) == 1) { + leds_off(LEDS_ALL); + } else if((counter & 7) == 2) { + leds_on(LEDS_ALL); + } else if((counter & 7) == 3) { + leds_toggle(LEDS_ALL); + } else if((counter & 7) == 4) { + leds_single_on(LEDS_LED1); + } else if((counter & 7) == 5) { + leds_single_off(LEDS_LED1); + } else if((counter & 7) == 6) { + leds_single_toggle(LEDS_LED1); + } else if((counter & 7) == 7) { + leds_toggle(LEDS_ALL); + } + + counter++; + etimer_set(&et, CLOCK_SECOND); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index 83ab79b13..a43637d91 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -21,6 +21,13 @@ dev/gpio-hal/srf06-cc26xx:BOARD=sensortag/cc2650 \ dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1310 \ dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1350 \ dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc2650 \ +dev/leds/srf06-cc26xx:BOARD=srf06/cc13xx \ +dev/leds/srf06-cc26xx:BOARD=srf06/cc26xx \ +dev/leds/srf06-cc26xx:BOARD=sensortag/cc1350 \ +dev/leds/srf06-cc26xx:BOARD=sensortag/cc2650 \ +dev/leds/srf06-cc26xx:BOARD=launchpad/cc1310 \ +dev/leds/srf06-cc26xx:BOARD=launchpad/cc1350 \ +dev/leds/srf06-cc26xx:BOARD=launchpad/cc2650 \ 6tisch/etsi-plugtest-2017/srf06-cc26xx:BOARD=launchpad/cc2650 \ storage/cfs-coffee/cc2538dk \ sensniff/cc2538dk \ @@ -30,6 +37,7 @@ slip-radio/cc2538dk \ ipso-objects/cc2538dk \ multicast/cc2538dk \ dev/gpio-hal/cc2538dk \ +dev/leds/cc2538dk \ platform-specific/cc2538-common/cc2538dk \ platform-specific/cc2538-common/mqtt-demo/cc2538dk \ platform-specific/cc2538-common/crypto/cc2538dk \ diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index 6aca008db..fd015e088 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -39,11 +39,17 @@ dev/gpio-hal/zoul:BOARD=remote-revb \ dev/gpio-hal/zoul:BOARD=firefly-reva \ dev/gpio-hal/zoul:BOARD=firefly \ dev/gpio-hal/zoul:BOARD=orion \ +dev/leds/zoul:BOARD=remote-reva \ +dev/leds/zoul:BOARD=remote-revb \ +dev/leds/zoul:BOARD=firefly-reva \ +dev/leds/zoul:BOARD=firefly \ +dev/leds/zoul:BOARD=orion \ storage/cfs-coffee/openmote-cc2538 \ sensniff/openmote-cc2538 \ hello-world/openmote-cc2538 \ rpl-udp/openmote-cc2538 \ dev/gpio-hal/openmote-cc2538 \ +dev/leds/openmote-cc2538 \ rpl-border-router/openmote-cc2538 TOOLS= From be307bf00445ad77ee526ea6976f67de95f9b7f1 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 1 Mar 2018 01:09:03 +0000 Subject: [PATCH 36/40] Add RGB LED example and tests --- examples/dev/rgb-led/Makefile | 8 +++ examples/dev/rgb-led/Makefile.target | 1 + examples/dev/rgb-led/README.md | 14 +++++ examples/dev/rgb-led/rgb-led-example.c | 82 ++++++++++++++++++++++++++ tests/03-compile-arm-ports-02/Makefile | 5 ++ 5 files changed, 110 insertions(+) create mode 100644 examples/dev/rgb-led/Makefile create mode 100644 examples/dev/rgb-led/Makefile.target create mode 100644 examples/dev/rgb-led/README.md create mode 100644 examples/dev/rgb-led/rgb-led-example.c diff --git a/examples/dev/rgb-led/Makefile b/examples/dev/rgb-led/Makefile new file mode 100644 index 000000000..0b3f4b229 --- /dev/null +++ b/examples/dev/rgb-led/Makefile @@ -0,0 +1,8 @@ +CONTIKI_PROJECT = rgb-led-example +CONTIKI = ../../.. + +MODULES_REL += $(TARGET) + +all: $(CONTIKI_PROJECT) + +include $(CONTIKI)/Makefile.include diff --git a/examples/dev/rgb-led/Makefile.target b/examples/dev/rgb-led/Makefile.target new file mode 100644 index 000000000..75430a6e4 --- /dev/null +++ b/examples/dev/rgb-led/Makefile.target @@ -0,0 +1 @@ +TARGET = zoul diff --git a/examples/dev/rgb-led/README.md b/examples/dev/rgb-led/README.md new file mode 100644 index 000000000..1b10926ce --- /dev/null +++ b/examples/dev/rgb-led/README.md @@ -0,0 +1,14 @@ +# RGB LED Example +This example demonstrates and tests the functionality of the RGB LED driver. +You can use it to: + +* Understand the logic of the RGB LED driver. +* Test your implementation if you are developing a new port for a device that +features this part. + +This example assumes a device with an RGB LED. + +# Supported devices +This example is expected to work off-the-shelf on the following boards: + +* All Zoul-based devices diff --git a/examples/dev/rgb-led/rgb-led-example.c b/examples/dev/rgb-led/rgb-led-example.c new file mode 100644 index 000000000..e2c2de21e --- /dev/null +++ b/examples/dev/rgb-led/rgb-led-example.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/rgb-led/rgb-led.h" +#include "sys/etimer.h" + +#include +/*---------------------------------------------------------------------------*/ +static struct etimer et; +static uint8_t counter; +/*---------------------------------------------------------------------------*/ +PROCESS(rgb_led_example, "RGB LED Example"); +AUTOSTART_PROCESSES(&rgb_led_example); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(rgb_led_example, ev, data) +{ + PROCESS_BEGIN(); + + counter = 0; + + etimer_set(&et, CLOCK_SECOND); + + while(1) { + + PROCESS_YIELD(); + + if(ev == PROCESS_EVENT_TIMER && data == &et) { + if((counter & 7) == 0) { + rgb_led_off(); + } else if((counter & 7) == 1) { + rgb_led_set(RGB_LED_RED); + } else if((counter & 7) == 2) { + rgb_led_set(RGB_LED_GREEN); + } else if((counter & 7) == 3) { + rgb_led_set(RGB_LED_BLUE); + } else if((counter & 7) == 4) { + rgb_led_set(RGB_LED_CYAN); + } else if((counter & 7) == 5) { + rgb_led_set(RGB_LED_MAGENTA); + } else if((counter & 7) == 6) { + rgb_led_set(RGB_LED_YELLOW); + } else if((counter & 7) == 7) { + rgb_led_set(RGB_LED_WHITE); + } + + counter++; + etimer_set(&et, CLOCK_SECOND); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index fd015e088..01aab98b6 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -44,6 +44,11 @@ dev/leds/zoul:BOARD=remote-revb \ dev/leds/zoul:BOARD=firefly-reva \ dev/leds/zoul:BOARD=firefly \ dev/leds/zoul:BOARD=orion \ +dev/rgb-led/zoul:BOARD=remote-reva \ +dev/rgb-led/zoul:BOARD=remote-revb \ +dev/rgb-led/zoul:BOARD=firefly-reva \ +dev/rgb-led/zoul:BOARD=firefly \ +dev/rgb-led/zoul:BOARD=orion \ storage/cfs-coffee/openmote-cc2538 \ sensniff/openmote-cc2538 \ hello-world/openmote-cc2538 \ From b2148b87650e09cb12796ca68ba9b185737e5402 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 2 Mar 2018 02:42:11 -0800 Subject: [PATCH 37/40] Remove uses of obsolete flag CONTIKI_TARGET_COOJA_IP64 --- os/net/mac/tsch/tsch-private.h | 8 ++++---- os/net/mac/tsch/tsch-slot-operation.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/os/net/mac/tsch/tsch-private.h b/os/net/mac/tsch/tsch-private.h index fd2d9d42b..fc5559b38 100644 --- a/os/net/mac/tsch/tsch-private.h +++ b/os/net/mac/tsch/tsch-private.h @@ -53,10 +53,10 @@ #include "net/linkaddr.h" #include "net/mac/tsch/tsch-asn.h" #include "net/mac/tsch/tsch-conf.h" -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA #include "lib/simEnvChange.h" #include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ /************ Types ***********/ @@ -124,7 +124,7 @@ void tsch_disassociate(void); #define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length) /* Wait for a condition with timeout t0+offset. */ -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA #define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) { \ simProcessRunValue = 1; \ @@ -133,6 +133,6 @@ void tsch_disassociate(void); #else #define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ; -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ #endif /* __TSCH_PRIVATE_H__ */ /** @} */ diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index 3596b913c..d70ed56c4 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -59,10 +59,10 @@ #include "net/mac/tsch/tsch-packet.h" #include "net/mac/tsch/tsch-security.h" #include "net/mac/tsch/tsch-adaptive-timesync.h" -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA #include "lib/simEnvChange.h" #include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ #include "sys/log.h" /* TSCH debug macros, i.e. to set LEDs or GPIOs on various TSCH @@ -107,7 +107,7 @@ #if RTIMER_SECOND < (32 * 1024) #error "TSCH: RTIMER_SECOND < (32 * 1024)" #endif -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA /* Use 0 usec guard time for Cooja Mote with a 1 MHz Rtimer*/ #define RTIMER_GUARD 0u #elif RTIMER_SECOND >= 200000 @@ -208,10 +208,10 @@ tsch_get_lock(void) busy_wait = 1; busy_wait_time = RTIMER_NOW(); while(tsch_in_slot_operation) { -#if CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 +#if CONTIKI_TARGET_COOJA simProcessRunValue = 1; cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA || CONTIKI_TARGET_COOJA_IP64 */ +#endif /* CONTIKI_TARGET_COOJA */ } busy_wait_time = RTIMER_NOW() - busy_wait_time; } From aaa8658e8daedcd035e8fae969362ad3b67a36b6 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 2 Mar 2018 04:14:23 -0800 Subject: [PATCH 38/40] tsch-log: fixed alignement of the log fields --- os/net/mac/tsch/tsch-log.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/os/net/mac/tsch/tsch-log.c b/os/net/mac/tsch/tsch-log.c index 54fca2710..fdaaf3b53 100644 --- a/os/net/mac/tsch/tsch-log.c +++ b/os/net/mac/tsch/tsch-log.c @@ -85,10 +85,10 @@ tsch_log_process_pending(void) while((log_index = ringbufindex_peek_get(&log_ringbuf)) != -1) { struct tsch_log_t *log = &log_array[log_index]; if(log->link == NULL) { - printf("[INFO: TSCH-LOG ] {asn-%x.%lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); + printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); } else { struct tsch_slotframe *sf = tsch_schedule_get_slotframe_by_handle(log->link->slotframe_handle); - printf("[INFO: TSCH-LOG ] {asn-%x.%lx link-%u-%u-%u-%u ch-%u} ", + printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link %2u %3u %3u %2u ch %2u} ", log->asn.ms1b, log->asn.ls4b, log->link->slotframe_handle, sf ? sf->size.val : 0, log->link->timeslot, log->link->channel_offset, tsch_calculate_channel(&log->asn, log->link->channel_offset)); @@ -100,10 +100,10 @@ tsch_log_process_pending(void) log_lladdr_compact(&linkaddr_node_addr); printf("->"); log_lladdr_compact(&log->tx.dest); - printf(", len %u, seq %u, st %d %d", + printf(", len %3u, seq %3u, st %d %2d", log->tx.datalen, log->tx.seqno, log->tx.mac_tx_status, log->tx.num_tx); if(log->tx.drift_used) { - printf(", dr %d", log->tx.drift); + printf(", dr %3d", log->tx.drift); } printf("\n"); break; @@ -113,12 +113,14 @@ tsch_log_process_pending(void) log_lladdr_compact(&log->rx.src); printf("->"); log_lladdr_compact(log->rx.is_unicast ? &linkaddr_node_addr : NULL); - printf(", len %u, seq %u", + printf(", len %3u, seq %3u", log->rx.datalen, log->rx.seqno); + printf(", edr %3d", (int)log->rx.estimated_drift); if(log->rx.drift_used) { - printf(", dr %d", log->rx.drift); + printf(", dr %3d\n", log->rx.drift); + } else { + printf("\n"); } - printf(", edr %d\n", log->rx.estimated_drift); break; case tsch_log_message: printf("%s\n", log->message); From 80c9f9ea1f67fd5210f234ca6b820bc6fd1317cb Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 2 Mar 2018 08:10:41 -0800 Subject: [PATCH 39/40] http-socket.h: include cc.h instead of re-defining MAX --- os/net/app-layer/http-socket/http-socket.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/os/net/app-layer/http-socket/http-socket.h b/os/net/app-layer/http-socket/http-socket.h index 5b683e10b..adac80c3e 100644 --- a/os/net/app-layer/http-socket/http-socket.h +++ b/os/net/app-layer/http-socket/http-socket.h @@ -32,6 +32,7 @@ #define HTTP_SOCKET_H #include "tcp-socket.h" +#include "sys/cc.h" struct http_socket; @@ -62,8 +63,6 @@ typedef void (* http_socket_callback_t)(struct http_socket *s, const uint8_t *data, uint16_t datalen); -#define MAX(n, m) (((n) < (m)) ? (m) : (n)) - #define HTTP_SOCKET_INPUTBUFSIZE UIP_TCP_MSS #define HTTP_SOCKET_OUTPUTBUFSIZE MAX(UIP_TCP_MSS, 128) From b909fb287868cfa219dd3005ba9e011fa6e893dc Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 2 Mar 2018 07:45:05 -0800 Subject: [PATCH 40/40] Docker: enable IPv6 automatically in container --- .travis.yml | 2 +- .../04-border-router-traceroute.sh | 3 --- tests/17-tun-rpl-br/05-native-ping.sh | 3 --- tests/17-tun-rpl-br/06-native-coap.sh | 3 --- tests/17-tun-rpl-br/test-border-router.sh | 3 --- tests/17-tun-rpl-br/test-nbr.sh | 3 --- tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh | 3 --- tools/docker/Dockerfile | 22 +++++++++---------- 8 files changed, 12 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 23b972a13..00dba89ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ before_install: - ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar script: # The test script for each build. - - docker run --privileged -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash -c "make -C tests/??-$TEST_NAME"; + - docker run --privileged -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash --login -c "make -C tests/??-$TEST_NAME"; # Check outcome of the test - $CNG_HOST_PATH/tests/check-test.sh $CNG_HOST_PATH/tests/??-$TEST_NAME; exit $?; diff --git a/tests/17-tun-rpl-br/04-border-router-traceroute.sh b/tests/17-tun-rpl-br/04-border-router-traceroute.sh index 0dba7f835..a150c530f 100755 --- a/tests/17-tun-rpl-br/04-border-router-traceroute.sh +++ b/tests/17-tun-rpl-br/04-border-router-traceroute.sh @@ -17,9 +17,6 @@ java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -c JPID=$! sleep 20 -echo "Enabling IPv6" -sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Connect to the simlation echo "Starting tunslip6" make -C $CONTIKI/tools tunslip6 diff --git a/tests/17-tun-rpl-br/05-native-ping.sh b/tests/17-tun-rpl-br/05-native-ping.sh index e47536e3f..9e677c16e 100755 --- a/tests/17-tun-rpl-br/05-native-ping.sh +++ b/tests/17-tun-rpl-br/05-native-ping.sh @@ -7,9 +7,6 @@ BASENAME=01-native-ping IPADDR=fd00::302:304:506:708 -echo "Enabling IPv6" -sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Starting Contiki-NG native node echo "Starting native node" make -C $CONTIKI/examples/hello-world > make.log 2> make.err diff --git a/tests/17-tun-rpl-br/06-native-coap.sh b/tests/17-tun-rpl-br/06-native-coap.sh index da5e06a72..16dd8aab7 100755 --- a/tests/17-tun-rpl-br/06-native-coap.sh +++ b/tests/17-tun-rpl-br/06-native-coap.sh @@ -10,9 +10,6 @@ IPADDR=fd00::302:304:506:708 declare -i OKCOUNT=0 declare -i TESTCOUNT=0 -echo "Enabling IPv6" -sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Starting Contiki-NG native node echo "Starting native CoAP server" make -C $CONTIKI/examples/coap > make.log 2> make.err diff --git a/tests/17-tun-rpl-br/test-border-router.sh b/tests/17-tun-rpl-br/test-border-router.sh index fac803ba8..b8c8f018e 100755 --- a/tests/17-tun-rpl-br/test-border-router.sh +++ b/tests/17-tun-rpl-br/test-border-router.sh @@ -18,9 +18,6 @@ java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -c JPID=$! sleep 20 -echo "Enabling IPv6" -sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Connect to the simlation echo "Starting tunslip6" make -C $CONTIKI/tools tunslip6 diff --git a/tests/17-tun-rpl-br/test-nbr.sh b/tests/17-tun-rpl-br/test-nbr.sh index 63862a656..9a1824f7c 100644 --- a/tests/17-tun-rpl-br/test-nbr.sh +++ b/tests/17-tun-rpl-br/test-nbr.sh @@ -18,9 +18,6 @@ java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -c JPID=$! sleep 20 -echo "Enabling IPv6" -sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Connect to the simlation echo "Starting native border-router" nohup make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=native >> $BASENAME.nbr.log 2>&1 & diff --git a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh index 537d7a15e..15fd96243 100755 --- a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh +++ b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh @@ -7,9 +7,6 @@ BASENAME=06-lwm2m-test IPADDR=fd00::302:304:506:708 -echo "Enabling IPv6" -sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Starting Contiki-NG native node echo "Starting native node - lwm2m/ipso objects" make -C $CONTIKI/examples/ipso-objects > make.log 2> make.err diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index 14c1636ae..d8e9c0a79 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -67,24 +67,24 @@ WORKDIR ${HOME} RUN echo "#!/bin/bash\nant -Dbasedir=${COOJA} -f ${COOJA}/build.xml run" > ${HOME}/cooja && \ chmod +x ${HOME}/cooja -# Optional: download Contiki-NG and pre-compile Cooja. -# Else, use a Docker bind mount to share the repo with the host. -# Docker run option: -# -v :/home/user/contiki-ng -#RUN git clone --recursive https://github.com/contiki-ng/contiki-ng.git ${CONTIKI_NG} -#RUN ant -q -f ${CONTIKI_NG}/tools/cooja/build.xml jar - -# Enable IPv6 -- must be done at runtime, not in Dockerfile -#RUN sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 - # Install coap-cli RUN sudo apt-get install -y npm \ && sudo apt-get clean \ && sudo npm install coap-cli -g \ && sudo ln -s /usr/bin/nodejs /usr/bin/node +# Optional: download Contiki-NG and pre-compile Cooja. +# Else, use a Docker bind mount to share the repo with the host. +# Docker run option: +# -v :/home/user/contiki-ng +RUN git clone --recursive https://github.com/contiki-ng/contiki-ng.git ${CONTIKI_NG} +RUN ant -q -f ${CONTIKI_NG}/tools/cooja/build.xml jar + # Working directory WORKDIR ${CONTIKI_NG} +# Enable IPv6 -- must be done at runtime, not in Dockerfile +RUN echo "sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 > /dev/null" >> /home/user/.profile + # Start a bash -CMD bash +CMD bash --login