diff --git a/examples/slip-radio/Makefile b/examples/slip-radio/Makefile index f4bd8ca35..d59b5e240 100644 --- a/examples/slip-radio/Makefile +++ b/examples/slip-radio/Makefile @@ -2,19 +2,15 @@ CONTIKI_PROJECT=slip-radio all: $(CONTIKI_PROJECT) MODULES += os/services/slip-cmd -ifeq ($(TARGET),) - -include Makefile.target -endif - CONTIKI=../.. +-include $(CONTIKI)/Makefile.identify-target +### Optionally, the target can add its own Makefile, to do things like e.g. +### add more source files to the build or define make variables. +-include $(TARGET)/Makefile.$(TARGET) + +PROJECTDIRS += $(TARGET) PROJECT_SOURCEFILES += slip-net.c -ifeq ($(TARGET),sky) - PROJECT_SOURCEFILES += slip-radio-cc2420.c slip-radio-sky-sensors.c -endif -ifeq ($(TARGET),nooliberry) - PROJECT_SOURCEFILES += slip-radio-rf230.c -endif # custom net layer, but with IPv6 enabled MAKE_NET = MAKE_NET_IPV6 diff --git a/examples/slip-radio/project-conf.h b/examples/slip-radio/project-conf.h index fc51e55ec..89e135a42 100644 --- a/examples/slip-radio/project-conf.h +++ b/examples/slip-radio/project-conf.h @@ -29,23 +29,18 @@ #ifndef PROJECT_CONF_H_ #define PROJECT_CONF_H_ - -#define QUEUEBUF_CONF_NUM 4 - -#define UIP_CONF_BUFFER_SIZE 140 - +/*---------------------------------------------------------------------------*/ +/* Include target-specific header */ +#ifdef TARGET_CONF_PATH +#include TARGET_CONF_PATH +#endif /* TARGET_CONF_PATH */ +/*---------------------------------------------------------------------------*/ #define UIP_CONF_ROUTER 0 #define CMD_CONF_OUTPUT slip_radio_cmd_output -/* add the cmd_handler_cc2420 + some sensors if TARGET_SKY */ -#ifdef CONTIKI_TARGET_SKY -#define CMD_CONF_HANDLERS slip_radio_cmd_handler,cmd_handler_cc2420 -#define SLIP_RADIO_CONF_SENSORS slip_radio_sky_sensors -/* add the cmd_handler_rf230 if TARGET_NOOLIBERRY. Other RF230 platforms can be added */ -#elif CONTIKI_TARGET_NOOLIBERRY -#define CMD_CONF_HANDLERS slip_radio_cmd_handler,cmd_handler_rf230 -#else +/* Default CMD handlers if the target did not specify them */ +#ifndef CMD_CONF_HANDLERS #define CMD_CONF_HANDLERS slip_radio_cmd_handler #endif @@ -53,7 +48,5 @@ #define NETSTACK_CONF_NETWORK slipnet_driver #define NETSTACK_CONF_FRAMER no_framer - -#define UART1_CONF_RX_WITH_DMA 1 - +/*---------------------------------------------------------------------------*/ #endif /* PROJECT_CONF_H_ */ diff --git a/examples/slip-radio/sky/Makefile.sky b/examples/slip-radio/sky/Makefile.sky new file mode 100644 index 000000000..83a91472d --- /dev/null +++ b/examples/slip-radio/sky/Makefile.sky @@ -0,0 +1,4 @@ +PROJECT_SOURCEFILES += slip-radio-cc2420.c slip-radio-sky-sensors.c +PROJECT_SOURCEFILES += slip-radio-putchar.c + +CFLAGS += -DTARGET_CONF_PATH=\"target-conf.h\" diff --git a/examples/slip-radio/slip-radio-cc2420.c b/examples/slip-radio/sky/slip-radio-cc2420.c similarity index 100% rename from examples/slip-radio/slip-radio-cc2420.c rename to examples/slip-radio/sky/slip-radio-cc2420.c diff --git a/examples/slip-radio/slip-radio-rf230.c b/examples/slip-radio/sky/slip-radio-putchar.c similarity index 61% rename from examples/slip-radio/slip-radio-rf230.c rename to examples/slip-radio/sky/slip-radio-putchar.c index 67c3ecc33..7d688cdd1 100644 --- a/examples/slip-radio/slip-radio-rf230.c +++ b/examples/slip-radio/sky/slip-radio-putchar.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Swedish Institute of Computer Science + * Copyright (c) 2011, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,48 +25,39 @@ * 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. - * - * Sets up some commands for the RF230 radio. */ - +/*---------------------------------------------------------------------------*/ #include "contiki.h" -#include "cmd.h" +#include "dev/slip.h" -#include "radio/rf230/radio.h" -#include "radio/rf230bb/rf230bb.h" - - -#define DEBUG 0 -#if DEBUG #include -#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) -#define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args) -#else -#define PRINTF(...) -#define PRINTSHORT(...) -#endif - +/*---------------------------------------------------------------------------*/ +#define SLIP_END 0300 +#undef putchar +/*---------------------------------------------------------------------------*/ int -cmd_handler_rf230(const uint8_t *data, int len) +putchar(int c) { - if(data[0] == '!') { - if(data[1] == 'C') { - PRINTF("CMD: Setting channel: %d\n", data[2]); - rf230_set_channel(data[2]); - return 1; - } - } else if(data[0] == '?') { - if(data[1] == 'C') { - uint8_t buf[4]; - PRINTF("CMD: Getting channel: %d\n", data[2]); - buf[0] = '!'; - buf[1] = 'C'; - buf[2] = rf230_get_channel(); - cmd_send(buf, 3); - return 1; - } + static char debug_frame = 0; + + if(!debug_frame) { /* Start of debug output */ + slip_arch_writeb(SLIP_END); + slip_arch_writeb('\r'); /* Type debug line == '\r' */ + debug_frame = 1; } - return 0; + + /* Need to also print '\n' because for example COOJA will not show + any output before line end */ + slip_arch_writeb((char)c); + + /* + * Line buffered output, a newline marks the end of debug output and + * implicitly flushes debug output. + */ + if(c == '\n') { + slip_arch_writeb(SLIP_END); + debug_frame = 0; + } + return c; } +/*---------------------------------------------------------------------------*/ diff --git a/examples/slip-radio/slip-radio-sky-sensors.c b/examples/slip-radio/sky/slip-radio-sky-sensors.c similarity index 100% rename from examples/slip-radio/slip-radio-sky-sensors.c rename to examples/slip-radio/sky/slip-radio-sky-sensors.c diff --git a/examples/slip-radio/sky/target-conf.h b/examples/slip-radio/sky/target-conf.h new file mode 100644 index 000000000..08fa66512 --- /dev/null +++ b/examples/slip-radio/sky/target-conf.h @@ -0,0 +1,43 @@ +/* + * 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. + */ +/*---------------------------------------------------------------------------*/ +#ifndef TARGET_CONF_H_ +#define TARGET_CONF_H_ +/*---------------------------------------------------------------------------*/ +#define QUEUEBUF_CONF_NUM 4 +#define UIP_CONF_BUFFER_SIZE 140 + +#define CMD_CONF_HANDLERS slip_radio_cmd_handler,cmd_handler_cc2420 +#define SLIP_RADIO_CONF_SENSORS slip_radio_sky_sensors +#define UART1_CONF_RX_WITH_DMA 1 +/*---------------------------------------------------------------------------*/ +#endif /* TARGET_CONF_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/examples/slip-radio/slip-net.c b/examples/slip-radio/slip-net.c index 4449462e2..1a787c85c 100644 --- a/examples/slip-radio/slip-net.c +++ b/examples/slip-radio/slip-net.c @@ -32,17 +32,19 @@ #include "net/ipv6/uip.h" #include "net/packetbuf.h" #include "dev/slip.h" +#include "os/sys/log.h" + #include +#define LOG_MODULE "slip-net" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ #define SLIP_END 0300 #define SLIP_ESC 0333 #define SLIP_ESC_END 0334 #define SLIP_ESC_ESC 0335 - -#define DEBUG 0 - /*---------------------------------------------------------------------------*/ -void +static void slipnet_init(void) { } @@ -68,7 +70,7 @@ slip_send_packet(const uint8_t *ptr, int len) slip_arch_writeb(SLIP_END); } /*---------------------------------------------------------------------------*/ -void +static void slipnet_input(void) { int i; @@ -79,29 +81,28 @@ slipnet_input(void) uip_len = packetbuf_datalen(); i = packetbuf_copyto(uip_buf); - if(DEBUG) { - printf("Slipnet got input of len: %d, copied: %d\n", - packetbuf_datalen(), i); + LOG_DBG("Slipnet got input of len: %d, copied: %d\n", + packetbuf_datalen(), i); - for(i = 0; i < uip_len; i++) { - printf("%02x", (unsigned char) uip_buf[i]); - if((i & 15) == 15) printf("\n"); - else if((i & 7) == 7) printf(" "); + for(i = 0; i < uip_len; i++) { + LOG_DBG("%02x", (unsigned char)uip_buf[i]); + if((i & 15) == 15) { + LOG_DBG_("\n"); + } else if((i & 7) == 7) { + LOG_DBG_(" "); } - printf("\n"); } + LOG_DBG_("\n"); - /* printf("SUT: %u\n", uip_len); */ slip_send_packet(uip_buf, uip_len); } - +/*---------------------------------------------------------------------------*/ static uint8_t slipnet_output(const linkaddr_t *localdest) { /* do nothing... */ return 1; } - /*---------------------------------------------------------------------------*/ const struct network_driver slipnet_driver = { "slipnet", diff --git a/examples/slip-radio/slip-radio-mc1322x.c b/examples/slip-radio/slip-radio-mc1322x.c deleted file mode 100644 index da518b11c..000000000 --- a/examples/slip-radio/slip-radio-mc1322x.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2011, Swedish Institute of Computer Science - * 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. - * - * Sets up some commands for the MC1322x radio chip. - */ - -#include "contiki.h" -#include "mc1322x.h" -#include "cmd.h" -#include - -int -cmd_handler_mc1322x(const uint8_t *data, int len) -{ - if(data[0] == '!') { - if(data[1] == 'C') { - printf("mc1322x_cmd: setting channel: %d\n", data[2]); - set_channel(data[2]-11); - return 1; - } - } else if(data[0] == '?') { - if(data[1] == 'C') { - uint8_t buf[4]; - printf("mc1322x_cmd: getting channel: %d\n", data[2]); - buf[0] = '!'; - buf[1] = 'C'; - //Not implemented in MACA driver - buf[2] = 0; - cmd_send(buf, 3); - return 1; - } - } - return 0; -} diff --git a/examples/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index 193ec44aa..720bc9694 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -42,30 +42,29 @@ #include "net/netstack.h" #include "net/packetbuf.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" #include "cmd.h" #include "slip-radio.h" #include "packetutils.h" +#include "os/sys/log.h" +#include + +#define LOG_MODULE "slip-radio" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ #ifdef SLIP_RADIO_CONF_SENSORS extern const struct slip_radio_sensors SLIP_RADIO_CONF_SENSORS; #endif void slip_send_packet(const uint8_t *ptr, int len); - /* max 16 packets at the same time??? */ +/* max 16 packets at the same time??? */ uint8_t packet_ids[16]; int packet_pos; static int slip_radio_cmd_handler(const uint8_t *data, int len); -#if CONTIKI_TARGET_NOOLIBERRY -int cmd_handler_rf230(const uint8_t *data, int len); -#else /* Leave CC2420 as default */ int cmd_handler_cc2420(const uint8_t *data, int len); -#endif /* CONTIKI_TARGET */ - /*---------------------------------------------------------------------------*/ #ifdef CMD_CONF_HANDLERS CMD_HANDLERS(CMD_CONF_HANDLERS); @@ -119,8 +118,8 @@ packet_sent(void *ptr, int status, int transmissions) uint8_t sid; int pos; sid = *((uint8_t *)ptr); - PRINTF("Slip-radio: packet sent! sid: %d, status: %d, tx: %d\n", - sid, status, transmissions); + LOG_DBG("Slip-radio: packet sent! sid: %d, status: %d, tx: %d\n", + sid, status, transmissions); /* packet callback from lower layers */ /* neighbor_info_packet_sent(status, transmissions); */ pos = 0; @@ -146,7 +145,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len) packetbuf_clear(); pos = packetutils_deserialize_atts(&data[3], len - 3); if(pos < 0) { - PRINTF("slip-radio: illegal packet attributes\n"); + LOG_ERR("slip-radio: illegal packet attributes\n"); return 1; } pos += 3; @@ -157,8 +156,8 @@ slip_radio_cmd_handler(const uint8_t *data, int len) memcpy(packetbuf_dataptr(), &data[pos], len); packetbuf_set_datalen(len); - PRINTF("slip-radio: sending %u (%d bytes)\n", - data[2], packetbuf_datalen()); + LOG_DBG("slip-radio: sending %u (%d bytes)\n", + data[2], packetbuf_datalen()); /* parse frame before sending to get addresses, etc. */ parse_frame(); @@ -166,13 +165,13 @@ slip_radio_cmd_handler(const uint8_t *data, int len) packet_pos++; if(packet_pos >= sizeof(packet_ids)) { - packet_pos = 0; + packet_pos = 0; } return 1; } } else if(uip_buf[0] == '?') { - PRINTF("Got request message of type %c\n", uip_buf[1]); + LOG_DBG("Got request message of type %c\n", uip_buf[1]); if(data[1] == 'M') { /* this is just a test so far... just to see if it works */ uip_buf[0] = '!'; @@ -197,7 +196,7 @@ slip_radio_cmd_output(const uint8_t *data, int data_len) static void slip_input_callback(void) { - PRINTF("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]); + LOG_DBG("SR-SIN: %u '%c%c'\n", uip_len, uip_buf[0], uip_buf[1]); cmd_input(uip_buf, uip_len); uip_clear_buf(); } @@ -211,36 +210,6 @@ init(void) packet_pos = 0; } /*---------------------------------------------------------------------------*/ -#if !SLIP_RADIO_CONF_NO_PUTCHAR -#undef putchar -int -putchar(int c) -{ -#define SLIP_END 0300 - static char debug_frame = 0; - - if(!debug_frame) { /* Start of debug output */ - slip_arch_writeb(SLIP_END); - slip_arch_writeb('\r'); /* Type debug line == '\r' */ - debug_frame = 1; - } - - /* Need to also print '\n' because for example COOJA will not show - any output before line end */ - slip_arch_writeb((char)c); - - /* - * Line buffered output, a newline marks the end of debug output and - * implicitly flushes debug output. - */ - if(c == '\n') { - slip_arch_writeb(SLIP_END); - debug_frame = 0; - } - return c; -} -#endif -/*---------------------------------------------------------------------------*/ PROCESS(slip_radio_process, "Slip radio process"); AUTOSTART_PROCESSES(&slip_radio_process); /*---------------------------------------------------------------------------*/ diff --git a/examples/slip-radio/slip-radio.h b/examples/slip-radio/slip-radio.h index a80e81c4f..18f55a077 100644 --- a/examples/slip-radio/slip-radio.h +++ b/examples/slip-radio/slip-radio.h @@ -33,9 +33,9 @@ struct slip_radio_sensors { /** Initialize the driver */ - void (* init)(void); + void (*init)(void); /** Send the sensor data packet via the command send */ - void (* send)(void); + void (*send)(void); }; #endif /* SLIP_RADIO_H_ */ diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index 9054a3560..5fa09d2e5 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -9,6 +9,7 @@ multicast/sky \ libs/logging/native \ rpl-udp/sky \ native-border-router/native \ +slip-radio/sky \ TOOLS= diff --git a/tests/02-compile-arm-ports/Makefile b/tests/02-compile-arm-ports/Makefile index ab20dbb57..4a1395c56 100644 --- a/tests/02-compile-arm-ports/Makefile +++ b/tests/02-compile-arm-ports/Makefile @@ -15,6 +15,7 @@ hello-world/cc2538dk \ rpl-border-router/cc2538dk \ rpl-udp/cc2538dk \ coap-example/cc2538dk \ +slip-radio/cc2538dk \ ipso-objects/cc2538dk \ multicast/cc2538dk \ platform-specific/cc2538-common/cc2538dk \