From 8fb2b2074e863d80ea31885068d21f9d758c0195 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 15:21:52 +0100 Subject: [PATCH 01/72] Delete jn516x-specific BR example #132 deleted other jn516x-specific BR examples, but this one was missed. This pull deletes the leftover example. This is the only place where we are still using the obsolete `SLIP_BRIDGE_CONF_NO_PUTCHAR` define (all others were removed by #135). This pull removes that too. --- arch/platform/jn516x/jn516x-def.h | 10 -- arch/platform/jn516x/lib/slip.c | 2 - .../rpl-border-router/Makefile | 42 ----- .../rpl-border-router/project-conf.h | 48 ----- .../rpl-border-router/rpl-border-router.c | 168 ------------------ .../rpl-border-router/slip-bridge.c | 160 ----------------- tests/04-compile-nxp-ports/Makefile | 1 - 7 files changed, 431 deletions(-) delete mode 100644 examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile delete mode 100644 examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/project-conf.h delete mode 100644 examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c delete mode 100644 examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/slip-bridge.c diff --git a/arch/platform/jn516x/jn516x-def.h b/arch/platform/jn516x/jn516x-def.h index 596d55333..0c76a4332 100644 --- a/arch/platform/jn516x/jn516x-def.h +++ b/arch/platform/jn516x/jn516x-def.h @@ -269,16 +269,6 @@ typedef uint32_t clock_time_t; #endif #define ENABLE_ADVANCED_BAUD_SELECTION (UART_BAUD_RATE > UART_RATE_115200) -/* Set this to zero only if we are using SLIP */ -#ifndef SLIP_BRIDGE_CONF_NO_PUTCHAR -#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT) -#define SLIP_BRIDGE_CONF_NO_PUTCHAR 0 -#else -#define SLIP_BRIDGE_CONF_NO_PUTCHAR 1 -#endif -#endif /* SLIP_BRIDGE_CONF_NO_PUTCHAR */ - - /* Extension of LED definitions from leds.h for various JN516x dev boards JN516x Dongle: LEDS_RED Red LED on dongle diff --git a/arch/platform/jn516x/lib/slip.c b/arch/platform/jn516x/lib/slip.c index a5ce4c16d..bdf3c81b5 100644 --- a/arch/platform/jn516x/lib/slip.c +++ b/arch/platform/jn516x/lib/slip.c @@ -429,11 +429,9 @@ slip_input_byte(unsigned char c) return error_return_code; } /*---------------------------------------------------------------------------*/ -#if SLIP_BRIDGE_CONF_NO_PUTCHAR int putchar(int c) { uart0_writeb(c); return 1; } -#endif diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile deleted file mode 100644 index 27454bda2..000000000 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -CONTIKI_PROJECT=rpl-border-router - -PLATFORMS_ONLY = jn516x - -TARGET ?= jn516x -JN516x_WITH_DONGLE = 1 - -CONTIKI=../../../../../.. - -PROJECT_SOURCEFILES += slip-bridge.c slip.c - -MODULES_REL += .. - -MAKE_MAC = MAKE_MAC_TSCH -MODULES += os/net/app-layer/coap -MODULES += os/services/orchestra os/lib/json - -all: $(CONTIKI_PROJECT) -include $(CONTIKI)/Makefile.include - -ifeq ($(PREFIX),) - PREFIX = aaaa::1/64 -endif - -#no flow control -connect-router: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -v1 -B 1000000 $(PREFIX) - -#using XON/XOFF flow control -connect-router-sw: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -v1 -X -B 1000000 $(PREFIX) - -#using hw flow control -connect-router-hw: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -v1 -H -B 1000000 $(PREFIX) - -#using no flow control -connect-router-no: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -v1 -B 1000000 $(PREFIX) - -connect-router-cooja: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 $(PREFIX) diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/project-conf.h b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/project-conf.h deleted file mode 100644 index c34c364e3..000000000 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/project-conf.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2010, 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. - * - */ - -#ifndef BR_PROJECT_ROUTER_CONF_H_ -#define BR_PROJECT_ROUTER_CONF_H_ - -#ifndef UIP_FALLBACK_INTERFACE -#define UIP_FALLBACK_INTERFACE rpl_interface -#endif - -/* Needed for slip-bridge */ -#define SLIP_BRIDGE_CONF_NO_PUTCHAR 0 - -#define UIP_CONF_TCP 0 -#define QUEUEBUF_CONF_NUM 16 - -#define TSCH_QUEUE_CONF_MAX_NEIGHBOR_QUEUES 8 - -#include "../../common-conf.h" - -#endif /* PROJECT_ROUTER_CONF_H_ */ diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c deleted file mode 100644 index cf88ea467..000000000 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/rpl-border-router.c +++ /dev/null @@ -1,168 +0,0 @@ -/* -* Copyright (c) 2015 NXP B.V. -* 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 NXP B.V. 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 NXP B.V. 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 NXP B.V. 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. -* -* Author: Theo van Daele -* -*/ -#include "contiki.h" -#include "contiki-lib.h" -#include "contiki-net.h" -#include "net/ipv6/uip.h" -#include "net/ipv6/uip-ds6.h" -#include "net/routing/routing.h" -#include "simple-udp.h" -#include "net/mac/tsch/tsch.h" -#include "net/netstack.h" -#include "dev/slip.h" -#include "coap-engine.h" - -#include -#include -#include -#include - -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" - -static uip_ipaddr_t prefix; -static uint8_t prefix_set; - -static void get_rssi_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); -static void get_last_rssi_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); - -static char content[COAP_MAX_CHUNK_SIZE]; -static int content_len = 0; - -#define CONTENT_PRINTF(...) { if(content_len < sizeof(content)) content_len += snprintf(content+content_len, sizeof(content)-content_len, __VA_ARGS__); } - -PROCESS(border_router_process, "Border router process"); -AUTOSTART_PROCESSES(&border_router_process); - -RESOURCE(resource_get_rssi, - "title=\"Get RSSI\"", - get_rssi_handler, - NULL, - NULL, - NULL); -static void -get_rssi_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - int rssi_level; - unsigned int accept = -1; - coap_get_header_accept(request, &accept); - if(accept == -1 || accept == TEXT_PLAIN) { - content_len = 0; - NETSTACK_RADIO.get_value(RADIO_PARAM_RSSI, &rssi_level); - CONTENT_PRINTF("%d", rssi_level); - coap_set_header_content_format(response, TEXT_PLAIN); - coap_set_payload(response, (uint8_t *)content, content_len); - } -} - -RESOURCE(resource_get_last_rssi, - "title=\"Get last RSSI\"", - get_last_rssi_handler, - NULL, - NULL, - NULL); -static void -get_last_rssi_handler(coap_message_t *request, coap_message_t *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) -{ - int last_rssi_level; - unsigned int accept = -1; - coap_get_header_accept(request, &accept); - if(accept == -1 || accept == TEXT_PLAIN) { - content_len = 0; - NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_RSSI, &last_rssi_level); - CONTENT_PRINTF("%d", last_rssi_level); - coap_set_header_content_format(response, TEXT_PLAIN); - coap_set_payload(response, (uint8_t *)content, content_len); - } -} - -/*---------------------------------------------------------------------------*/ -void -request_prefix(void) -{ - /* mess up uip_buf with a dirty request... */ - uip_buf[0] = '?'; - uip_buf[1] = 'P'; - uip_len = 2; - slip_send(); - uip_len = 0; -} -/*---------------------------------------------------------------------------*/ -void -set_prefix_64(uip_ipaddr_t *prefix_64) -{ - memcpy(&prefix, prefix_64, 16); - prefix_set = 1; -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(border_router_process, ev, data) -{ - static struct etimer et; - - PROCESS_BEGIN(); - -/* While waiting for the prefix to be sent through the SLIP connection, the future - * border router can join an existing DAG as a parent or child, or acquire a default - * router that will later take precedence over the SLIP fallback interface. - * Prevent that by turning the radio off until we are initialized as a DAG root. - */ - prefix_set = 0; - - PROCESS_PAUSE(); - - PRINTF("RPL-Border router started\n"); - - /* Request prefix until it has been received */ - while(!prefix_set) { - etimer_set(&et, CLOCK_SECOND); - request_prefix(); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - PRINTF("Waiting for prefix\n"); - } - - PRINTF("Obtained prefix: "); - uip_debug_ipaddr_print(&prefix); - PRINTF("\n"); - - NETSTACK_ROUTING.root_set_prefix(&prefix, NULL); - NETSTACK_ROUTING.root_start(); - - coap_engine_init(); - coap_activate_resource(&resource_get_rssi, "Get-RSSI"); - coap_activate_resource(&resource_get_last_rssi, "Get-Last-RSSI"); - - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/slip-bridge.c b/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/slip-bridge.c deleted file mode 100644 index 8201bf0f7..000000000 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/slip-bridge.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2010, 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. - * - */ - -/** - * \file - * Slip fallback interface - * \author - * Niclas Finne - * Joakim Eriksson - * Joel Hoglund - * Nicolas Tsiftes - */ - -#include "net/ipv6/uip.h" -#include "net/ipv6/uip-ds6.h" -#include "dev/slip.h" -#if CONTIKI_TARGET_JN516X -#include "dev/uart0.h" -#else -#include "dev/uart1.h" -#endif -#include - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" - -void set_prefix_64(uip_ipaddr_t *); - -static uip_ipaddr_t last_sender; -/*---------------------------------------------------------------------------*/ -static void -slip_input_callback(void) -{ - PRINTF("SIN: %u\n", uip_len); - if(uip_buf[0] == '!') { - PRINTF("Got configuration message of type %c\n", uip_buf[1]); - uip_len = 0; - if(uip_buf[1] == 'P') { - uip_ipaddr_t prefix; - /* Here we set a prefix !!! */ - memset(&prefix, 0, 16); - memcpy(&prefix, &uip_buf[2], 8); - PRINTF("Setting prefix "); - PRINT6ADDR(&prefix); - PRINTF("\n"); - set_prefix_64(&prefix); - } - } else if (uip_buf[0] == '?') { - PRINTF("Got request message of type %c\n", uip_buf[1]); - if(uip_buf[1] == 'M') { - char* hexchar = "0123456789abcdef"; - int j; - /* this is just a test so far... just to see if it works */ - uip_buf[0] = '!'; - for(j = 0; j < 8; j++) { - uip_buf[2 + j * 2] = hexchar[uip_lladdr.addr[j] >> 4]; - uip_buf[3 + j * 2] = hexchar[uip_lladdr.addr[j] & 15]; - } - uip_len = 18; - slip_send(); - - } - uip_len = 0; - } - /* Save the last sender received over SLIP to avoid bouncing the - packet back if no route is found */ - uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr); -} -/*---------------------------------------------------------------------------*/ -static void -init(void) -{ - slip_arch_init(); - process_start(&slip_process, NULL); - slip_set_input_callback(slip_input_callback); -} -/*---------------------------------------------------------------------------*/ -static int -output(void) -{ - if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) { - /* Do not bounce packets back over SLIP if the packet was received - over SLIP */ - PRINTF("slip-bridge: Destination off-link but no route src="); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF(" dst="); - PRINT6ADDR(&UIP_IP_BUF->destipaddr); - PRINTF("\n"); - } else { - PRINTF("SUT: %u\n", uip_len); - slip_send(); - printf("\n"); - } - return 0; -} - -/*---------------------------------------------------------------------------*/ -#if !SLIP_BRIDGE_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 -/*---------------------------------------------------------------------------*/ -const struct uip_fallback_interface rpl_interface = { - init, output -}; -/*---------------------------------------------------------------------------*/ diff --git a/tests/04-compile-nxp-ports/Makefile b/tests/04-compile-nxp-ports/Makefile index b1fdd9ea6..cec1f91af 100644 --- a/tests/04-compile-nxp-ports/Makefile +++ b/tests/04-compile-nxp-ports/Makefile @@ -11,7 +11,6 @@ platform-specific/jn516x/rpl/coap-dr1175-node/jn516x \ platform-specific/jn516x/rpl/coap-dr1199-node/jn516x \ platform-specific/jn516x/tsch/simple-sensor-network/node/jn516x \ platform-specific/jn516x/tsch/tx-power-verification/node/jn516x \ -platform-specific/jn516x/tsch/tx-power-verification/rpl-border-router/jn516x \ platform-specific/jn516x/tsch/uart1-test-node/jn516x \ sensniff/jn516x \ rpl-border-router/jn516x \ From 632ab90161d2bf1d4b25b22efb2680d9d4c456bc Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 00:53:42 +0000 Subject: [PATCH 02/72] Apply cosmetic changes --- arch/cpu/arm/common/dbg-io/dbg-printf.c | 10 ++++----- arch/cpu/arm/common/dbg-io/dbg-putchar.c | 10 +++++---- arch/cpu/arm/common/dbg-io/dbg-puts.c | 4 +++- arch/cpu/arm/common/dbg-io/dbg-snprintf.c | 10 +++++---- arch/cpu/arm/common/dbg-io/dbg-sprintf.c | 6 +++-- arch/cpu/arm/common/dbg-io/strformat.c | 27 +++++++++++++---------- arch/cpu/arm/common/dbg-io/strformat.h | 13 ++++++----- 7 files changed, 47 insertions(+), 33 deletions(-) diff --git a/arch/cpu/arm/common/dbg-io/dbg-printf.c b/arch/cpu/arm/common/dbg-io/dbg-printf.c index 9bd09c1ac..01a02aef2 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-printf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-printf.c @@ -1,21 +1,22 @@ +/*---------------------------------------------------------------------------*/ #include #include #include #include - +/*---------------------------------------------------------------------------*/ static StrFormatResult write_str(void *user_data, const char *data, unsigned int len) { if (len > 0) dbg_send_bytes((unsigned char*)data, len); return STRFORMAT_OK; } - - +/*---------------------------------------------------------------------------*/ static StrFormatContext ctxt = { write_str, NULL }; +/*---------------------------------------------------------------------------*/ int printf(const char *fmt, ...) { @@ -26,5 +27,4 @@ printf(const char *fmt, ...) va_end(ap); return res; } - - +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/dbg-putchar.c b/arch/cpu/arm/common/dbg-io/dbg-putchar.c index 54f3db53f..159b54a6e 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-putchar.c +++ b/arch/cpu/arm/common/dbg-io/dbg-putchar.c @@ -1,26 +1,28 @@ +/*---------------------------------------------------------------------------*/ #include #include #include - +/*---------------------------------------------------------------------------*/ #undef putchar #undef putc - +/*---------------------------------------------------------------------------*/ int putchar(int c) { dbg_putchar(c); return c; } - +/*---------------------------------------------------------------------------*/ int putc(int c, FILE *f) { dbg_putchar(c); return c; } - +/*---------------------------------------------------------------------------*/ int __sp(struct _reent *_ptr, int c, FILE *_p) { dbg_putchar(c); return c; } +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/dbg-puts.c b/arch/cpu/arm/common/dbg-io/dbg-puts.c index fa90d1022..5ad494ae3 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-puts.c +++ b/arch/cpu/arm/common/dbg-io/dbg-puts.c @@ -1,7 +1,8 @@ +/*---------------------------------------------------------------------------*/ #include #include #include - +/*---------------------------------------------------------------------------*/ int puts(const char *str) { @@ -9,3 +10,4 @@ puts(const char *str) dbg_putchar('\n'); return 0; } +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c index 230d6891a..10a1631ef 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c @@ -1,13 +1,14 @@ +/*---------------------------------------------------------------------------*/ #include #include #include - +/*---------------------------------------------------------------------------*/ struct FmtBuffer { char *pos; size_t left; }; - +/*---------------------------------------------------------------------------*/ static StrFormatResult buffer_str(void *user_data, const char *data, unsigned int len) { @@ -22,7 +23,7 @@ buffer_str(void *user_data, const char *data, unsigned int len) buffer->left -= len; return STRFORMAT_OK; } - +/*---------------------------------------------------------------------------*/ int snprintf(char *str, size_t size, const char *format, ...) { int res; @@ -32,7 +33,7 @@ int snprintf(char *str, size_t size, const char *format, ...) va_end(ap); return res; } - +/*---------------------------------------------------------------------------*/ int vsnprintf(char *str, size_t size, const char *format, va_list ap) { struct FmtBuffer buffer; @@ -46,3 +47,4 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap) *buffer.pos = '\0'; return res; } +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c index 8124fc363..e5abd4dc5 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c @@ -1,7 +1,8 @@ +/*---------------------------------------------------------------------------*/ #include #include #include - +/*---------------------------------------------------------------------------*/ static StrFormatResult buffer_str(void *user_data, const char *data, unsigned int len) { @@ -9,7 +10,7 @@ buffer_str(void *user_data, const char *data, unsigned int len) (*(char**)user_data) += len; return STRFORMAT_OK; } - +/*---------------------------------------------------------------------------*/ int sprintf(char *str, const char *format, ...) { @@ -24,3 +25,4 @@ sprintf(char *str, const char *format, ...) va_end(ap); return res; } +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/strformat.c b/arch/cpu/arm/common/dbg-io/strformat.c index 13b91a563..6106a75f9 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.c +++ b/arch/cpu/arm/common/dbg-io/strformat.c @@ -1,5 +1,6 @@ +/*---------------------------------------------------------------------------*/ #include - +/*---------------------------------------------------------------------------*/ #define HAVE_DOUBLE #define HAVE_LONGLONG @@ -22,9 +23,9 @@ #ifndef POINTER_INT #define POINTER_INT unsigned long #endif - +/*---------------------------------------------------------------------------*/ typedef unsigned int FormatFlags; - +/*---------------------------------------------------------------------------*/ #define MAKE_MASK(shift,size) (((1 << size) - 1) << (shift)) #define JUSTIFY_SHIFT 0 @@ -33,7 +34,6 @@ typedef unsigned int FormatFlags; #define JUSTIFY_LEFT 0x0001 #define JUSTIFY_MASK MAKE_MASK(JUSTIFY_SHIFT,JUSTIFY_SIZE) - /* How a positive number is prefixed */ #define POSITIVE_SHIFT (JUSTIFY_SHIFT + JUSTIFY_SIZE) #define POSITIVE_NONE (0x0000 << POSITIVE_SHIFT) @@ -99,6 +99,7 @@ typedef unsigned int FormatFlags; #define FLOAT_DEPENDANT (0x0002 << FLOAT_SHIFT) #define FLOAT_HEX (0x0003 << FLOAT_SHIFT) #define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE) +/*---------------------------------------------------------------------------*/ static FormatFlags parse_flags(const char **posp) @@ -130,7 +131,7 @@ parse_flags(const char **posp) } } - +/*---------------------------------------------------------------------------*/ static unsigned int parse_uint(const char **posp) { @@ -151,6 +152,7 @@ parse_uint(const char **posp) */ #define MAXCHARS ((sizeof(LARGEST_UNSIGNED) * 8 + 2) / 3 ) +/*---------------------------------------------------------------------------*/ static unsigned int output_uint_decimal(char **posp, LARGEST_UNSIGNED v) { @@ -164,7 +166,7 @@ output_uint_decimal(char **posp, LARGEST_UNSIGNED v) *posp = pos; return len; } - +/*---------------------------------------------------------------------------*/ static unsigned int output_uint_hex(char **posp, LARGEST_UNSIGNED v, unsigned int flags) { @@ -179,7 +181,7 @@ output_uint_hex(char **posp, LARGEST_UNSIGNED v, unsigned int flags) *posp = pos; return len; } - +/*---------------------------------------------------------------------------*/ static unsigned int output_uint_octal(char **posp, LARGEST_UNSIGNED v) { @@ -193,7 +195,7 @@ output_uint_octal(char **posp, LARGEST_UNSIGNED v) *posp = pos; return len; } - +/*---------------------------------------------------------------------------*/ static StrFormatResult fill_space(const StrFormatContext *ctxt, unsigned int len) { @@ -207,7 +209,7 @@ fill_space(const StrFormatContext *ctxt, unsigned int len) if (len == 0) return STRFORMAT_OK; return ctxt->write_str(ctxt->user_data, buffer, len); } - +/*---------------------------------------------------------------------------*/ static StrFormatResult fill_zero(const StrFormatContext *ctxt, unsigned int len) { @@ -221,9 +223,9 @@ fill_zero(const StrFormatContext *ctxt, unsigned int len) if (len == 0) return STRFORMAT_OK; return ctxt->write_str(ctxt->user_data, buffer, len); } - +/*---------------------------------------------------------------------------*/ #define CHECKCB(res) {if ((res) != STRFORMAT_OK) {va_end(ap); return -1;}} - +/*---------------------------------------------------------------------------*/ int format_str(const StrFormatContext *ctxt, const char *format, ...) { @@ -234,7 +236,7 @@ format_str(const StrFormatContext *ctxt, const char *format, ...) va_end(ap); return ret; } - +/*---------------------------------------------------------------------------*/ int format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap) { @@ -615,3 +617,4 @@ format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap) return written; } +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/strformat.h b/arch/cpu/arm/common/dbg-io/strformat.h index c32eed670..df6a56f39 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.h +++ b/arch/cpu/arm/common/dbg-io/strformat.h @@ -1,12 +1,14 @@ +/*---------------------------------------------------------------------------*/ #ifndef STRFORMAT_H_ #define STRFORMAT_H_ - +/*---------------------------------------------------------------------------*/ #include - +/*---------------------------------------------------------------------------*/ #define STRFORMAT_OK 0 #define STRFORMAT_FAILED 1 +/*---------------------------------------------------------------------------*/ typedef unsigned int StrFormatResult; - +/*---------------------------------------------------------------------------*/ /* The data argument may only be considered valid during the function call */ typedef StrFormatResult (*StrFormatWrite)(void *user_data, const char *data, unsigned int len); @@ -15,11 +17,12 @@ typedef struct _StrFormatContext StrFormatWrite write_str; void *user_data; } StrFormatContext; - +/*---------------------------------------------------------------------------*/ int format_str(const StrFormatContext *ctxt, const char *format, ...) __attribute__ ((__format__ (__printf__, 2,3))); int format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap); - +/*---------------------------------------------------------------------------*/ #endif /* STRFORMAT_H_ */ +/*---------------------------------------------------------------------------*/ From 4e3c7efa5fc28d554064586697d3277a473fe951 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 00:58:50 +0000 Subject: [PATCH 03/72] Fix code style --- arch/cpu/arm/common/dbg-io/dbg-printf.c | 12 +- arch/cpu/arm/common/dbg-io/dbg-putchar.c | 3 +- arch/cpu/arm/common/dbg-io/dbg-puts.c | 2 +- arch/cpu/arm/common/dbg-io/dbg-snprintf.c | 15 +- arch/cpu/arm/common/dbg-io/dbg-sprintf.c | 4 +- arch/cpu/arm/common/dbg-io/strformat.c | 740 ++++++++++++---------- arch/cpu/arm/common/dbg-io/strformat.h | 3 +- 7 files changed, 420 insertions(+), 359 deletions(-) diff --git a/arch/cpu/arm/common/dbg-io/dbg-printf.c b/arch/cpu/arm/common/dbg-io/dbg-printf.c index 01a02aef2..9ee3bd0e9 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-printf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-printf.c @@ -7,15 +7,17 @@ static StrFormatResult write_str(void *user_data, const char *data, unsigned int len) { - if (len > 0) dbg_send_bytes((unsigned char*)data, len); + if(len > 0) { + dbg_send_bytes((unsigned char *)data, len); + } return STRFORMAT_OK; } /*---------------------------------------------------------------------------*/ static StrFormatContext ctxt = - { - write_str, - NULL - }; +{ + write_str, + NULL +}; /*---------------------------------------------------------------------------*/ int printf(const char *fmt, ...) diff --git a/arch/cpu/arm/common/dbg-io/dbg-putchar.c b/arch/cpu/arm/common/dbg-io/dbg-putchar.c index 159b54a6e..eb0cb2180 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-putchar.c +++ b/arch/cpu/arm/common/dbg-io/dbg-putchar.c @@ -21,7 +21,8 @@ putc(int c, FILE *f) } /*---------------------------------------------------------------------------*/ int -__sp(struct _reent *_ptr, int c, FILE *_p) { +__sp(struct _reent *_ptr, int c, FILE *_p) +{ dbg_putchar(c); return c; } diff --git a/arch/cpu/arm/common/dbg-io/dbg-puts.c b/arch/cpu/arm/common/dbg-io/dbg-puts.c index 5ad494ae3..222a436dc 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-puts.c +++ b/arch/cpu/arm/common/dbg-io/dbg-puts.c @@ -6,7 +6,7 @@ int puts(const char *str) { - dbg_send_bytes((unsigned char*)str, strlen(str)); + dbg_send_bytes((unsigned char *)str, strlen(str)); dbg_putchar('\n'); return 0; } diff --git a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c index 10a1631ef..051d922ed 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c @@ -3,8 +3,7 @@ #include #include /*---------------------------------------------------------------------------*/ -struct FmtBuffer -{ +struct FmtBuffer { char *pos; size_t left; }; @@ -12,19 +11,20 @@ struct FmtBuffer static StrFormatResult buffer_str(void *user_data, const char *data, unsigned int len) { - struct FmtBuffer *buffer = (struct FmtBuffer*)user_data; - if (len >= buffer->left) { + struct FmtBuffer *buffer = (struct FmtBuffer *)user_data; + if(len >= buffer->left) { len = buffer->left; len--; } - + memcpy(buffer->pos, data, len); buffer->pos += len; buffer->left -= len; return STRFORMAT_OK; } /*---------------------------------------------------------------------------*/ -int snprintf(char *str, size_t size, const char *format, ...) +int +snprintf(char *str, size_t size, const char *format, ...) { int res; va_list ap; @@ -34,7 +34,8 @@ int snprintf(char *str, size_t size, const char *format, ...) return res; } /*---------------------------------------------------------------------------*/ -int vsnprintf(char *str, size_t size, const char *format, va_list ap) +int +vsnprintf(char *str, size_t size, const char *format, va_list ap) { struct FmtBuffer buffer; StrFormatContext ctxt; diff --git a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c index e5abd4dc5..8fb0d612f 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c @@ -6,8 +6,8 @@ static StrFormatResult buffer_str(void *user_data, const char *data, unsigned int len) { - memcpy(*(char**)user_data, data, len); - (*(char**)user_data) += len; + memcpy(*(char **)user_data, data, len); + (*(char **)user_data) += len; return STRFORMAT_OK; } /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/strformat.c b/arch/cpu/arm/common/dbg-io/strformat.c index 6106a75f9..37ac4ae25 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.c +++ b/arch/cpu/arm/common/dbg-io/strformat.c @@ -2,23 +2,23 @@ #include /*---------------------------------------------------------------------------*/ #define HAVE_DOUBLE - #define HAVE_LONGLONG + #ifndef LARGEST_SIGNED #ifdef HAVE_LONGLONG #define LARGEST_SIGNED long long int #else #define LARGEST_UNSIGNED long int -#endif -#endif +#endif /* HAVE_LONGLONG */ +#endif /* LARGEST_SIGNED */ #ifndef LARGEST_UNSIGNED #ifdef HAVE_LONGLONG #define LARGEST_UNSIGNED unsigned long long int #else #define LARGEST_UNSIGNED unsigned long int -#endif -#endif +#endif /* HAVE_LONGLONG */ +#endif /* LARGEST_UNSIGNED */ #ifndef POINTER_INT #define POINTER_INT unsigned long @@ -26,79 +26,78 @@ /*---------------------------------------------------------------------------*/ typedef unsigned int FormatFlags; /*---------------------------------------------------------------------------*/ -#define MAKE_MASK(shift,size) (((1 << size) - 1) << (shift)) - -#define JUSTIFY_SHIFT 0 -#define JUSTIFY_SIZE 1 -#define JUSTIFY_RIGHT 0x0000 -#define JUSTIFY_LEFT 0x0001 -#define JUSTIFY_MASK MAKE_MASK(JUSTIFY_SHIFT,JUSTIFY_SIZE) - +#define MAKE_MASK(shift, size) (((1 << size) - 1) << (shift)) +/*---------------------------------------------------------------------------*/ +#define JUSTIFY_SHIFT 0 +#define JUSTIFY_SIZE 1 +#define JUSTIFY_RIGHT 0x0000 +#define JUSTIFY_LEFT 0x0001 +#define JUSTIFY_MASK MAKE_MASK(JUSTIFY_SHIFT, JUSTIFY_SIZE) +/*---------------------------------------------------------------------------*/ /* How a positive number is prefixed */ -#define POSITIVE_SHIFT (JUSTIFY_SHIFT + JUSTIFY_SIZE) -#define POSITIVE_NONE (0x0000 << POSITIVE_SHIFT) -#define POSITIVE_SPACE (0x0001 << POSITIVE_SHIFT) -#define POSITIVE_PLUS (0x0003 << POSITIVE_SHIFT) -#define POSITIVE_MASK MAKE_MASK(POSITIVE_SHIFT, POSITIVE_SIZE) - -#define POSITIVE_SIZE 2 +#define POSITIVE_SHIFT (JUSTIFY_SHIFT + JUSTIFY_SIZE) +#define POSITIVE_NONE (0x0000 << POSITIVE_SHIFT) +#define POSITIVE_SPACE (0x0001 << POSITIVE_SHIFT) +#define POSITIVE_PLUS (0x0003 << POSITIVE_SHIFT) +#define POSITIVE_MASK MAKE_MASK(POSITIVE_SHIFT, POSITIVE_SIZE) +#define POSITIVE_SIZE 2 +/*---------------------------------------------------------------------------*/ #define ALTERNATE_FORM_SHIFT (POSITIVE_SHIFT + POSITIVE_SIZE) -#define ALTERNATE_FORM_SIZE 1 -#define ALTERNATE_FORM (0x0001 << ALTERNATE_FORM_SHIFT) - - -#define PAD_SHIFT (ALTERNATE_FORM_SHIFT + ALTERNATE_FORM_SIZE) -#define PAD_SIZE 1 -#define PAD_SPACE (0x0000 << PAD_SHIFT) -#define PAD_ZERO (0x0001 << PAD_SHIFT) - -#define SIZE_SHIFT (PAD_SHIFT + PAD_SIZE) -#define SIZE_SIZE 3 -#define SIZE_CHAR (0x0001 << SIZE_SHIFT) -#define SIZE_SHORT (0x0002 << SIZE_SHIFT) -#define SIZE_INT (0x0000 << SIZE_SHIFT) -#define SIZE_LONG (0x0003 << SIZE_SHIFT) -#define SIZE_LONGLONG (0x0004 << SIZE_SHIFT) -#define SIZE_MASK MAKE_MASK(SIZE_SHIFT,SIZE_SIZE) - -#define CONV_SHIFT (SIZE_SHIFT + SIZE_SIZE) -#define CONV_SIZE 3 -#define CONV_INTEGER (0x0001 << CONV_SHIFT) -#define CONV_FLOAT (0x0002 << CONV_SHIFT) -#define CONV_POINTER (0x0003 << CONV_SHIFT) -#define CONV_STRING (0x0004 << CONV_SHIFT) -#define CONV_CHAR (0x0005 << CONV_SHIFT) -#define CONV_PERCENT (0x0006 << CONV_SHIFT) -#define CONV_WRITTEN (0x0007 << CONV_SHIFT) -#define CONV_MASK MAKE_MASK(CONV_SHIFT, CONV_SIZE) - -#define RADIX_SHIFT (CONV_SHIFT + CONV_SIZE) -#define RADIX_SIZE 2 -#define RADIX_DECIMAL (0x0001 << RADIX_SHIFT) -#define RADIX_OCTAL (0x0002 << RADIX_SHIFT) -#define RADIX_HEX (0x0003 << RADIX_SHIFT) -#define RADIX_MASK MAKE_MASK(RADIX_SHIFT,RADIX_SIZE) - -#define SIGNED_SHIFT (RADIX_SHIFT + RADIX_SIZE) -#define SIGNED_SIZE 1 -#define SIGNED_NO (0x0000 << SIGNED_SHIFT) -#define SIGNED_YES (0x0001 << SIGNED_SHIFT) -#define SIGNED_MASK MAKE_MASK(SIGNED_SHIFT,SIGNED_SIZE) - -#define CAPS_SHIFT (SIGNED_SHIFT + SIGNED_SIZE) -#define CAPS_SIZE 1 -#define CAPS_NO (0x0000 << CAPS_SHIFT) -#define CAPS_YES (0x0001 << CAPS_SHIFT) -#define CAPS_MASK MAKE_MASK(CAPS_SHIFT,CAPS_SIZE) - -#define FLOAT_SHIFT (CAPS_SHIFT + CAPS_SIZE) -#define FLOAT_SIZE 2 -#define FLOAT_NORMAL (0x0000 << FLOAT_SHIFT) -#define FLOAT_EXPONENT (0x0001 << FLOAT_SHIFT) -#define FLOAT_DEPENDANT (0x0002 << FLOAT_SHIFT) -#define FLOAT_HEX (0x0003 << FLOAT_SHIFT) -#define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE) +#define ALTERNATE_FORM_SIZE 1 +#define ALTERNATE_FORM (0x0001 << ALTERNATE_FORM_SHIFT) +/*---------------------------------------------------------------------------*/ +#define PAD_SHIFT (ALTERNATE_FORM_SHIFT + ALTERNATE_FORM_SIZE) +#define PAD_SIZE 1 +#define PAD_SPACE (0x0000 << PAD_SHIFT) +#define PAD_ZERO (0x0001 << PAD_SHIFT) +/*---------------------------------------------------------------------------*/ +#define SIZE_SHIFT (PAD_SHIFT + PAD_SIZE) +#define SIZE_SIZE 3 +#define SIZE_CHAR (0x0001 << SIZE_SHIFT) +#define SIZE_SHORT (0x0002 << SIZE_SHIFT) +#define SIZE_INT (0x0000 << SIZE_SHIFT) +#define SIZE_LONG (0x0003 << SIZE_SHIFT) +#define SIZE_LONGLONG (0x0004 << SIZE_SHIFT) +#define SIZE_MASK MAKE_MASK(SIZE_SHIFT, SIZE_SIZE) +/*---------------------------------------------------------------------------*/ +#define CONV_SHIFT (SIZE_SHIFT + SIZE_SIZE) +#define CONV_SIZE 3 +#define CONV_INTEGER (0x0001 << CONV_SHIFT) +#define CONV_FLOAT (0x0002 << CONV_SHIFT) +#define CONV_POINTER (0x0003 << CONV_SHIFT) +#define CONV_STRING (0x0004 << CONV_SHIFT) +#define CONV_CHAR (0x0005 << CONV_SHIFT) +#define CONV_PERCENT (0x0006 << CONV_SHIFT) +#define CONV_WRITTEN (0x0007 << CONV_SHIFT) +#define CONV_MASK MAKE_MASK(CONV_SHIFT, CONV_SIZE) +/*---------------------------------------------------------------------------*/ +#define RADIX_SHIFT (CONV_SHIFT + CONV_SIZE) +#define RADIX_SIZE 2 +#define RADIX_DECIMAL (0x0001 << RADIX_SHIFT) +#define RADIX_OCTAL (0x0002 << RADIX_SHIFT) +#define RADIX_HEX (0x0003 << RADIX_SHIFT) +#define RADIX_MASK MAKE_MASK(RADIX_SHIFT, RADIX_SIZE) +/*---------------------------------------------------------------------------*/ +#define SIGNED_SHIFT (RADIX_SHIFT + RADIX_SIZE) +#define SIGNED_SIZE 1 +#define SIGNED_NO (0x0000 << SIGNED_SHIFT) +#define SIGNED_YES (0x0001 << SIGNED_SHIFT) +#define SIGNED_MASK MAKE_MASK(SIGNED_SHIFT, SIGNED_SIZE) +/*---------------------------------------------------------------------------*/ +#define CAPS_SHIFT (SIGNED_SHIFT + SIGNED_SIZE) +#define CAPS_SIZE 1 +#define CAPS_NO (0x0000 << CAPS_SHIFT) +#define CAPS_YES (0x0001 << CAPS_SHIFT) +#define CAPS_MASK MAKE_MASK(CAPS_SHIFT, CAPS_SIZE) +/*---------------------------------------------------------------------------*/ +#define FLOAT_SHIFT (CAPS_SHIFT + CAPS_SIZE) +#define FLOAT_SIZE 2 +#define FLOAT_NORMAL (0x0000 << FLOAT_SHIFT) +#define FLOAT_EXPONENT (0x0001 << FLOAT_SHIFT) +#define FLOAT_DEPENDANT (0x0002 << FLOAT_SHIFT) +#define FLOAT_HEX (0x0003 << FLOAT_SHIFT) +#define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE) /*---------------------------------------------------------------------------*/ static FormatFlags @@ -106,7 +105,8 @@ parse_flags(const char **posp) { FormatFlags flags = 0; const char *pos = *posp; - while (1) { + + while(1) { switch(*pos) { case '-': flags |= JUSTIFY_LEFT; @@ -127,9 +127,9 @@ parse_flags(const char **posp) *posp = pos; return flags; } + pos++; } - } /*---------------------------------------------------------------------------*/ static unsigned int @@ -138,11 +138,14 @@ parse_uint(const char **posp) unsigned v = 0; const char *pos = *posp; char ch; + while((ch = *pos) >= '0' && ch <= '9') { v = v * 10 + (ch - '0'); pos++; } + *posp = pos; + return v; } @@ -158,12 +161,15 @@ output_uint_decimal(char **posp, LARGEST_UNSIGNED v) { unsigned int len; char *pos = *posp; - while (v > 0) { + + while(v > 0) { *--pos = (v % 10) + '0'; v /= 10; } + len = *posp - pos; *posp = pos; + return len; } /*---------------------------------------------------------------------------*/ @@ -171,14 +177,17 @@ static unsigned int output_uint_hex(char **posp, LARGEST_UNSIGNED v, unsigned int flags) { unsigned int len; - const char *hex = (flags & CAPS_YES) ?"0123456789ABCDEF":"0123456789abcdef"; + const char *hex = (flags & CAPS_YES) ? "0123456789ABCDEF" : "0123456789abcdef"; char *pos = *posp; - while (v > 0) { + + while(v > 0) { *--pos = hex[(v % 16)]; v /= 16; } + len = *posp - pos; *posp = pos; + return len; } /*---------------------------------------------------------------------------*/ @@ -187,12 +196,15 @@ output_uint_octal(char **posp, LARGEST_UNSIGNED v) { unsigned int len; char *pos = *posp; - while (v > 0) { + + while(v > 0) { *--pos = (v % 8) + '0'; v /= 8; } + len = *posp - pos; *posp = pos; + return len; } /*---------------------------------------------------------------------------*/ @@ -201,12 +213,19 @@ fill_space(const StrFormatContext *ctxt, unsigned int len) { StrFormatResult res; static const char buffer[16] = " "; + while(len > 16) { res = ctxt->write_str(ctxt->user_data, buffer, 16); - if (res != STRFORMAT_OK) return res; + if(res != STRFORMAT_OK) { + return res; + } len -= 16; } - if (len == 0) return STRFORMAT_OK; + + if(len == 0) { + return STRFORMAT_OK; + } + return ctxt->write_str(ctxt->user_data, buffer, len); } /*---------------------------------------------------------------------------*/ @@ -215,12 +234,18 @@ fill_zero(const StrFormatContext *ctxt, unsigned int len) { StrFormatResult res; static const char buffer[16] = "0000000000000000"; + while(len > 16) { res = ctxt->write_str(ctxt->user_data, buffer, 16); - if (res != STRFORMAT_OK) return res; + if(res != STRFORMAT_OK) { + return res; + } len -= 16; } - if (len == 0) return STRFORMAT_OK; + + if(len == 0) { + return STRFORMAT_OK; + } return ctxt->write_str(ctxt->user_data, buffer, len); } /*---------------------------------------------------------------------------*/ @@ -242,67 +267,82 @@ format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap) { unsigned int written = 0; const char *pos = format; + while(*pos != '\0') { FormatFlags flags; unsigned int minwidth = 0; int precision = -1; /* Negative means no precision */ char ch; const char *start = pos; - while( (ch = *pos) != '\0' && ch != '%') pos++; - if (pos != start) { + + while((ch = *pos) != '\0' && ch != '%') { + pos++; + } + + if(pos != start) { CHECKCB(ctxt->write_str(ctxt->user_data, start, pos - start)); written += pos - start; } - if (*pos == '\0') { + + if(*pos == '\0') { va_end(ap); return written; } + pos++; - if (*pos == '\0') { + + if(*pos == '\0') { va_end(ap); return written; } + flags = parse_flags(&pos); /* parse width */ - if (*pos >= '1' && *pos <= '9') { + if(*pos >= '1' && *pos <= '9') { minwidth = parse_uint(&pos); - } else if (*pos == '*') { - int w = va_arg(ap,int); - if (w < 0) { - flags |= JUSTIFY_LEFT; - minwidth = w; + } else if(*pos == '*') { + int w = va_arg(ap, int); + + if(w < 0) { + flags |= JUSTIFY_LEFT; + minwidth = w; } else { - minwidth = w; + minwidth = w; } - pos ++; + + pos++; } /* parse precision */ - if (*pos == '.') { + if(*pos == '.') { pos++; - if (*pos >= '0' && *pos <= '9') { - precision = parse_uint(&pos); - } else if (*pos == '*') { - pos++; - precision = va_arg(ap,int); + + if(*pos >= '0' && *pos <= '9') { + precision = parse_uint(&pos); + } else if(*pos == '*') { + pos++; + precision = va_arg(ap, int); } } - if (*pos == 'l') { + + if(*pos == 'l') { pos++; - if (*pos == 'l') { - flags |= SIZE_LONGLONG; - pos++; + + if(*pos == 'l') { + flags |= SIZE_LONGLONG; + pos++; } else { - flags |= SIZE_LONG; + flags |= SIZE_LONG; } - } else if (*pos == 'h') { + } else if(*pos == 'h') { pos++; - if (*pos == 'h') { - flags |= SIZE_CHAR; - pos++; + + if(*pos == 'h') { + flags |= SIZE_CHAR; + pos++; } else { - flags |= SIZE_SHORT; + flags |= SIZE_SHORT; } } @@ -370,251 +410,269 @@ format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap) return written; } pos++; + switch(flags & CONV_MASK) { case CONV_PERCENT: CHECKCB(ctxt->write_str(ctxt->user_data, "%", 1)); written++; break; case CONV_INTEGER: - { - /* unsigned integers */ - char *prefix = 0; /* sign, "0x" or "0X" */ - unsigned int prefix_len = 0; - char buffer[MAXCHARS]; - char *conv_pos = buffer + MAXCHARS; - unsigned int conv_len = 0; - unsigned int width = 0; - unsigned int precision_fill; - unsigned int field_fill; - LARGEST_UNSIGNED uvalue = 0; - int negative = 0; - - if (precision < 0) precision = 1; - else flags &= ~PAD_ZERO; - - if (flags & SIGNED_YES) { - /* signed integers */ - LARGEST_SIGNED value = 0; - switch(flags & SIZE_MASK) { - case SIZE_CHAR: - value = (signed char)va_arg(ap, int); - break; - case SIZE_SHORT: - value = (short)va_arg(ap, int); - break; - case SIZE_INT: - value = va_arg(ap, int); - break; -#ifndef HAVE_LONGLONG - case SIZE_LONGLONG: /* Treat long long the same as long */ -#endif - case SIZE_LONG: - value = va_arg(ap, long); - break; -#ifdef HAVE_LONGLONG - case SIZE_LONGLONG: - value = va_arg(ap, long long); - break; -#endif - } - if (value < 0) { - uvalue = -value; - negative = 1; - } else { - uvalue = value; - } - } else { - - switch(flags & SIZE_MASK) { - case SIZE_CHAR: - uvalue = (unsigned char)va_arg(ap,unsigned int); - break; - case SIZE_SHORT: - uvalue = (unsigned short)va_arg(ap,unsigned int); - break; - case SIZE_INT: - uvalue = va_arg(ap,unsigned int); - break; -#ifndef HAVE_LONGLONG - case SIZE_LONGLONG: /* Treat long long the same as long */ -#endif - case SIZE_LONG: - uvalue = va_arg(ap,unsigned long); - break; -#ifdef HAVE_LONGLONG - case SIZE_LONGLONG: - uvalue = va_arg(ap,unsigned long long); - break; -#endif - } - } - - switch(flags & (RADIX_MASK)) { - case RADIX_DECIMAL: - conv_len = output_uint_decimal(&conv_pos,uvalue); - break; - case RADIX_OCTAL: - conv_len = output_uint_octal(&conv_pos,uvalue); - break; - case RADIX_HEX: - conv_len = output_uint_hex(&conv_pos,uvalue, flags); - break; - } + { + /* unsigned integers */ + char *prefix = 0; /* sign, "0x" or "0X" */ + unsigned int prefix_len = 0; + char buffer[MAXCHARS]; + char *conv_pos = buffer + MAXCHARS; + unsigned int conv_len = 0; + unsigned int width = 0; + unsigned int precision_fill; + unsigned int field_fill; + LARGEST_UNSIGNED uvalue = 0; + int negative = 0; - width += conv_len; - precision_fill = (precision > conv_len) ? precision - conv_len : 0; - if ((flags & (RADIX_MASK | ALTERNATE_FORM)) - == (RADIX_OCTAL | ALTERNATE_FORM)) { - if (precision_fill < 1) precision_fill = 1; - } - - width += precision_fill; - - if ((flags & (RADIX_MASK | ALTERNATE_FORM)) - == (RADIX_HEX | ALTERNATE_FORM) && uvalue != 0) { - prefix_len = 2; - if (flags & CAPS_YES) { - prefix = "0X"; - } else { - prefix = "0x"; - } - } - - if (flags & SIGNED_YES) { - if (negative) { - prefix = "-"; - prefix_len = 1; - } else { - switch(flags & POSITIVE_MASK) { - case POSITIVE_SPACE: - prefix = " "; - prefix_len = 1; - break; - case POSITIVE_PLUS: - prefix = "+"; - prefix_len = 1; - break; - } - } - } - - width += prefix_len; - - field_fill = (minwidth > width) ? minwidth - width : 0; - - if ((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { - if (flags & PAD_ZERO) { - precision_fill += field_fill; - field_fill = 0; /* Do not double count padding */ - } else { - CHECKCB(fill_space(ctxt,field_fill)); - } - } - - if (prefix_len > 0) - CHECKCB(ctxt->write_str(ctxt->user_data, prefix, prefix_len)); - written += prefix_len; - - CHECKCB(fill_zero(ctxt,precision_fill)); - written += precision_fill; - - CHECKCB(ctxt->write_str(ctxt->user_data, conv_pos,conv_len)); - written += conv_len; - - if ((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { - CHECKCB(fill_space(ctxt,field_fill)); - } - written += field_fill; + if(precision < 0) { + precision = 1; + } else { + flags &= ~PAD_ZERO; } - break; + + if(flags & SIGNED_YES) { + /* signed integers */ + LARGEST_SIGNED value = 0; + switch(flags & SIZE_MASK) { + case SIZE_CHAR: + value = (signed char)va_arg(ap, int); + break; + case SIZE_SHORT: + value = (short)va_arg(ap, int); + break; + case SIZE_INT: + value = va_arg(ap, int); + break; +#ifndef HAVE_LONGLONG + case SIZE_LONGLONG: /* Treat long long the same as long */ +#endif + case SIZE_LONG: + value = va_arg(ap, long); + break; +#ifdef HAVE_LONGLONG + case SIZE_LONGLONG: + value = va_arg(ap, long long); + break; +#endif + } + if(value < 0) { + uvalue = -value; + negative = 1; + } else { + uvalue = value; + } + } else { + + switch(flags & SIZE_MASK) { + case SIZE_CHAR: + uvalue = (unsigned char)va_arg(ap, unsigned int); + break; + case SIZE_SHORT: + uvalue = (unsigned short)va_arg(ap, unsigned int); + break; + case SIZE_INT: + uvalue = va_arg(ap, unsigned int); + break; +#ifndef HAVE_LONGLONG + case SIZE_LONGLONG: /* Treat long long the same as long */ +#endif + case SIZE_LONG: + uvalue = va_arg(ap, unsigned long); + break; +#ifdef HAVE_LONGLONG + case SIZE_LONGLONG: + uvalue = va_arg(ap, unsigned long long); + break; +#endif + } + } + + switch(flags & (RADIX_MASK)) { + case RADIX_DECIMAL: + conv_len = output_uint_decimal(&conv_pos, uvalue); + break; + case RADIX_OCTAL: + conv_len = output_uint_octal(&conv_pos, uvalue); + break; + case RADIX_HEX: + conv_len = output_uint_hex(&conv_pos, uvalue, flags); + break; + } + + width += conv_len; + precision_fill = (precision > conv_len) ? precision - conv_len : 0; + if((flags & (RADIX_MASK | ALTERNATE_FORM)) + == (RADIX_OCTAL | ALTERNATE_FORM)) { + if(precision_fill < 1) { + precision_fill = 1; + } + } + + width += precision_fill; + + if((flags & (RADIX_MASK | ALTERNATE_FORM)) + == (RADIX_HEX | ALTERNATE_FORM) && uvalue != 0) { + prefix_len = 2; + if(flags & CAPS_YES) { + prefix = "0X"; + } else { + prefix = "0x"; + } + } + + if(flags & SIGNED_YES) { + if(negative) { + prefix = "-"; + prefix_len = 1; + } else { + switch(flags & POSITIVE_MASK) { + case POSITIVE_SPACE: + prefix = " "; + prefix_len = 1; + break; + case POSITIVE_PLUS: + prefix = "+"; + prefix_len = 1; + break; + } + } + } + + width += prefix_len; + + field_fill = (minwidth > width) ? minwidth - width : 0; + + if((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { + if(flags & PAD_ZERO) { + precision_fill += field_fill; + field_fill = 0; /* Do not double count padding */ + } else { + CHECKCB(fill_space(ctxt, field_fill)); + } + } + + if(prefix_len > 0) { + CHECKCB(ctxt->write_str(ctxt->user_data, prefix, prefix_len)); + } + written += prefix_len; + + CHECKCB(fill_zero(ctxt, precision_fill)); + written += precision_fill; + + CHECKCB(ctxt->write_str(ctxt->user_data, conv_pos, conv_len)); + written += conv_len; + + if((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { + CHECKCB(fill_space(ctxt, field_fill)); + } + written += field_fill; + } + break; case CONV_STRING: - { - unsigned int field_fill; - unsigned int len; - char *str = va_arg(ap,char *); - if (str) { - char *pos = str; - while(*pos != '\0') pos++; - len = pos - str; - } else { - str = "(null)"; - len = 6; - } - if (precision >= 0 && precision < len) len = precision; - field_fill = (minwidth > len) ? minwidth - len : 0; - if ((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { - CHECKCB(fill_space(ctxt,field_fill)); - } - CHECKCB(ctxt->write_str(ctxt->user_data, str,len)); - written += len; - if ((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { - CHECKCB(fill_space(ctxt,field_fill)); - } - written += field_fill; + { + unsigned int field_fill; + unsigned int len; + char *str = va_arg(ap, char *); + + if(str) { + char *pos = str; + while(*pos != '\0') pos++; + len = pos - str; + } else { + str = "(null)"; + len = 6; } - break; + + if(precision >= 0 && precision < len) { + len = precision; + } + + field_fill = (minwidth > len) ? minwidth - len : 0; + + if((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { + CHECKCB(fill_space(ctxt, field_fill)); + } + + CHECKCB(ctxt->write_str(ctxt->user_data, str, len)); + written += len; + + if((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { + CHECKCB(fill_space(ctxt, field_fill)); + } + written += field_fill; + } + break; case CONV_POINTER: - { - LARGEST_UNSIGNED uvalue = - (LARGEST_UNSIGNED)(POINTER_INT)va_arg(ap,void *); - char buffer[MAXCHARS_HEX + 3]; - char *conv_pos = buffer + MAXCHARS_HEX+3; - unsigned int conv_len; - unsigned int field_fill; - - conv_len = output_uint_hex(&conv_pos,uvalue,flags); - if (conv_len == 0) { - *--conv_pos = '0'; - conv_len++; - } - *--conv_pos = 'x'; - *--conv_pos = '0'; - *--conv_pos = '#'; - conv_len += 3; + { + LARGEST_UNSIGNED uvalue = + (LARGEST_UNSIGNED)(POINTER_INT)va_arg(ap, void *); + char buffer[MAXCHARS_HEX + 3]; + char *conv_pos = buffer + MAXCHARS_HEX + 3; + unsigned int conv_len; + unsigned int field_fill; - field_fill = (minwidth > conv_len) ? minwidth - conv_len : 0; - - if ((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { - CHECKCB(fill_space(ctxt,field_fill)); - } - - CHECKCB(ctxt->write_str(ctxt->user_data, conv_pos,conv_len)); - written += conv_len; - - if ((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { - CHECKCB(fill_space(ctxt,field_fill)); - } - written += field_fill; + conv_len = output_uint_hex(&conv_pos, uvalue, flags); + + if(conv_len == 0) { + *--conv_pos = '0'; + conv_len++; } - break; + + *--conv_pos = 'x'; + *--conv_pos = '0'; + *--conv_pos = '#'; + conv_len += 3; + + field_fill = (minwidth > conv_len) ? minwidth - conv_len : 0; + + if((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { + CHECKCB(fill_space(ctxt, field_fill)); + } + + CHECKCB(ctxt->write_str(ctxt->user_data, conv_pos, conv_len)); + written += conv_len; + + if((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { + CHECKCB(fill_space(ctxt, field_fill)); + } + + written += field_fill; + } + break; case CONV_CHAR: - { - char ch = va_arg(ap,int); - unsigned int field_fill = (minwidth > 1) ? minwidth - 1 : 0; - if ((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { - CHECKCB(fill_space(ctxt,field_fill)); - written += field_fill; - } - - CHECKCB(ctxt->write_str(ctxt->user_data, &ch, 1)); - written++; - - if ((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { - CHECKCB(fill_space(ctxt,field_fill)); - } - written+= field_fill; - } - break; - case CONV_WRITTEN: - { - int *p = va_arg(ap,int*); - *p = written; - } - break; + { + char ch = va_arg(ap, int); + unsigned int field_fill = (minwidth > 1) ? minwidth - 1 : 0; + if((flags & JUSTIFY_MASK) == JUSTIFY_RIGHT) { + CHECKCB(fill_space(ctxt, field_fill)); + written += field_fill; + } + + CHECKCB(ctxt->write_str(ctxt->user_data, &ch, 1)); + written++; + + if((flags & JUSTIFY_MASK) == JUSTIFY_LEFT) { + CHECKCB(fill_space(ctxt, field_fill)); + } + written += field_fill; + } + break; + case CONV_WRITTEN: + { + int *p = va_arg(ap, int *); + *p = written; + } + break; } } - + return written; } /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/arm/common/dbg-io/strformat.h b/arch/cpu/arm/common/dbg-io/strformat.h index df6a56f39..c873e3649 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.h +++ b/arch/cpu/arm/common/dbg-io/strformat.h @@ -12,8 +12,7 @@ typedef unsigned int StrFormatResult; /* The data argument may only be considered valid during the function call */ typedef StrFormatResult (*StrFormatWrite)(void *user_data, const char *data, unsigned int len); -typedef struct _StrFormatContext -{ +typedef struct _StrFormatContext { StrFormatWrite write_str; void *user_data; } StrFormatContext; From 888a99ed3c8ce3955327dd9ee886adbc1c8f86e8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 01:01:19 +0000 Subject: [PATCH 04/72] Move macros to top of file --- arch/cpu/arm/common/dbg-io/strformat.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/cpu/arm/common/dbg-io/strformat.c b/arch/cpu/arm/common/dbg-io/strformat.c index 37ac4ae25..19e09caf4 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.c +++ b/arch/cpu/arm/common/dbg-io/strformat.c @@ -99,7 +99,13 @@ typedef unsigned int FormatFlags; #define FLOAT_HEX (0x0003 << FLOAT_SHIFT) #define FLOAT_MASK MAKE_MASK(FLOAT_SHIFT, FLOAT_SIZE) /*---------------------------------------------------------------------------*/ +#define CHECKCB(res) { if((res) != STRFORMAT_OK) { va_end(ap); return -1; } } +/*---------------------------------------------------------------------------*/ +#define MAXCHARS_HEX ((sizeof(LARGEST_UNSIGNED) * 8) / 4) +/* Largest number of characters needed for converting an unsigned integer. */ +#define MAXCHARS ((sizeof(LARGEST_UNSIGNED) * 8 + 2) / 3) +/*---------------------------------------------------------------------------*/ static FormatFlags parse_flags(const char **posp) { @@ -148,13 +154,6 @@ parse_uint(const char **posp) return v; } - -#define MAXCHARS_HEX ((sizeof(LARGEST_UNSIGNED) * 8) / 4 ) - -/* Largest number of characters needed for converting an unsigned integer. - */ -#define MAXCHARS ((sizeof(LARGEST_UNSIGNED) * 8 + 2) / 3 ) - /*---------------------------------------------------------------------------*/ static unsigned int output_uint_decimal(char **posp, LARGEST_UNSIGNED v) @@ -249,8 +248,6 @@ fill_zero(const StrFormatContext *ctxt, unsigned int len) return ctxt->write_str(ctxt->user_data, buffer, len); } /*---------------------------------------------------------------------------*/ -#define CHECKCB(res) {if ((res) != STRFORMAT_OK) {va_end(ap); return -1;}} -/*---------------------------------------------------------------------------*/ int format_str(const StrFormatContext *ctxt, const char *format, ...) { From 89148eb030beb4d100114c7ce6514855bdc40338 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 01:23:59 +0000 Subject: [PATCH 05/72] Include contiki.h --- arch/cpu/arm/common/dbg-io/dbg-printf.c | 2 ++ arch/cpu/arm/common/dbg-io/dbg-putchar.c | 2 ++ arch/cpu/arm/common/dbg-io/dbg-puts.c | 2 ++ arch/cpu/arm/common/dbg-io/dbg-snprintf.c | 2 ++ arch/cpu/arm/common/dbg-io/dbg-sprintf.c | 2 ++ arch/cpu/arm/common/dbg-io/strformat.c | 2 ++ arch/cpu/arm/common/dbg-io/strformat.h | 2 ++ 7 files changed, 14 insertions(+) diff --git a/arch/cpu/arm/common/dbg-io/dbg-printf.c b/arch/cpu/arm/common/dbg-io/dbg-printf.c index 9ee3bd0e9..88174276c 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-printf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-printf.c @@ -1,4 +1,6 @@ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include #include #include diff --git a/arch/cpu/arm/common/dbg-io/dbg-putchar.c b/arch/cpu/arm/common/dbg-io/dbg-putchar.c index eb0cb2180..f817f1699 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-putchar.c +++ b/arch/cpu/arm/common/dbg-io/dbg-putchar.c @@ -1,4 +1,6 @@ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include #include #include diff --git a/arch/cpu/arm/common/dbg-io/dbg-puts.c b/arch/cpu/arm/common/dbg-io/dbg-puts.c index 222a436dc..21e6ac64b 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-puts.c +++ b/arch/cpu/arm/common/dbg-io/dbg-puts.c @@ -1,4 +1,6 @@ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include #include #include diff --git a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c index 051d922ed..d650b13e0 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c @@ -1,4 +1,6 @@ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include #include #include diff --git a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c index 8fb0d612f..85eb6669a 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c @@ -1,4 +1,6 @@ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include #include #include diff --git a/arch/cpu/arm/common/dbg-io/strformat.c b/arch/cpu/arm/common/dbg-io/strformat.c index 19e09caf4..e905f67fd 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.c +++ b/arch/cpu/arm/common/dbg-io/strformat.c @@ -1,4 +1,6 @@ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include /*---------------------------------------------------------------------------*/ #define HAVE_DOUBLE diff --git a/arch/cpu/arm/common/dbg-io/strformat.h b/arch/cpu/arm/common/dbg-io/strformat.h index c873e3649..38315c772 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.h +++ b/arch/cpu/arm/common/dbg-io/strformat.h @@ -2,6 +2,8 @@ #ifndef STRFORMAT_H_ #define STRFORMAT_H_ /*---------------------------------------------------------------------------*/ +#include "contiki.h" + #include /*---------------------------------------------------------------------------*/ #define STRFORMAT_OK 0 From a0e8b5195080aee73ccd288820cd2994b458e5df Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 01:24:24 +0000 Subject: [PATCH 06/72] Add license and copyright notice --- arch/cpu/arm/common/dbg-io/dbg-printf.c | 30 +++++++++++++++++++++++ arch/cpu/arm/common/dbg-io/dbg-putchar.c | 30 +++++++++++++++++++++++ arch/cpu/arm/common/dbg-io/dbg-puts.c | 30 +++++++++++++++++++++++ arch/cpu/arm/common/dbg-io/dbg-snprintf.c | 30 +++++++++++++++++++++++ arch/cpu/arm/common/dbg-io/dbg-sprintf.c | 30 +++++++++++++++++++++++ arch/cpu/arm/common/dbg-io/strformat.c | 30 +++++++++++++++++++++++ arch/cpu/arm/common/dbg-io/strformat.h | 30 +++++++++++++++++++++++ 7 files changed, 210 insertions(+) diff --git a/arch/cpu/arm/common/dbg-io/dbg-printf.c b/arch/cpu/arm/common/dbg-io/dbg-printf.c index 88174276c..5afca6123 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-printf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-printf.c @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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" diff --git a/arch/cpu/arm/common/dbg-io/dbg-putchar.c b/arch/cpu/arm/common/dbg-io/dbg-putchar.c index f817f1699..842939ac3 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-putchar.c +++ b/arch/cpu/arm/common/dbg-io/dbg-putchar.c @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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" diff --git a/arch/cpu/arm/common/dbg-io/dbg-puts.c b/arch/cpu/arm/common/dbg-io/dbg-puts.c index 21e6ac64b..a15019620 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-puts.c +++ b/arch/cpu/arm/common/dbg-io/dbg-puts.c @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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" diff --git a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c index d650b13e0..e7a04ac31 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-snprintf.c @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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" diff --git a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c index 85eb6669a..8d0437869 100644 --- a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c +++ b/arch/cpu/arm/common/dbg-io/dbg-sprintf.c @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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" diff --git a/arch/cpu/arm/common/dbg-io/strformat.c b/arch/cpu/arm/common/dbg-io/strformat.c index e905f67fd..8e7d8bd3f 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.c +++ b/arch/cpu/arm/common/dbg-io/strformat.c @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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" diff --git a/arch/cpu/arm/common/dbg-io/strformat.h b/arch/cpu/arm/common/dbg-io/strformat.h index 38315c772..f02bc1791 100644 --- a/arch/cpu/arm/common/dbg-io/strformat.h +++ b/arch/cpu/arm/common/dbg-io/strformat.h @@ -1,3 +1,33 @@ +/* + * Copyright (c) 2009, Simon Berg + * 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 STRFORMAT_H_ #define STRFORMAT_H_ From bb338affeb3a9c54096b6717f99f5ff7080a7d76 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 01:33:05 +0000 Subject: [PATCH 07/72] Move dbg-io to os --- arch/cpu/arm/common/dbg-io/dbg-printf.c => os/lib/dbg-io/printf.c | 0 .../arm/common/dbg-io/dbg-putchar.c => os/lib/dbg-io/putchar.c | 0 arch/cpu/arm/common/dbg-io/dbg-puts.c => os/lib/dbg-io/puts.c | 0 .../arm/common/dbg-io/dbg-snprintf.c => os/lib/dbg-io/snprintf.c | 0 .../arm/common/dbg-io/dbg-sprintf.c => os/lib/dbg-io/sprintf.c | 0 {arch/cpu/arm/common => os/lib}/dbg-io/strformat.c | 0 {arch/cpu/arm/common => os/lib}/dbg-io/strformat.h | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename arch/cpu/arm/common/dbg-io/dbg-printf.c => os/lib/dbg-io/printf.c (100%) rename arch/cpu/arm/common/dbg-io/dbg-putchar.c => os/lib/dbg-io/putchar.c (100%) rename arch/cpu/arm/common/dbg-io/dbg-puts.c => os/lib/dbg-io/puts.c (100%) rename arch/cpu/arm/common/dbg-io/dbg-snprintf.c => os/lib/dbg-io/snprintf.c (100%) rename arch/cpu/arm/common/dbg-io/dbg-sprintf.c => os/lib/dbg-io/sprintf.c (100%) rename {arch/cpu/arm/common => os/lib}/dbg-io/strformat.c (100%) rename {arch/cpu/arm/common => os/lib}/dbg-io/strformat.h (100%) diff --git a/arch/cpu/arm/common/dbg-io/dbg-printf.c b/os/lib/dbg-io/printf.c similarity index 100% rename from arch/cpu/arm/common/dbg-io/dbg-printf.c rename to os/lib/dbg-io/printf.c diff --git a/arch/cpu/arm/common/dbg-io/dbg-putchar.c b/os/lib/dbg-io/putchar.c similarity index 100% rename from arch/cpu/arm/common/dbg-io/dbg-putchar.c rename to os/lib/dbg-io/putchar.c diff --git a/arch/cpu/arm/common/dbg-io/dbg-puts.c b/os/lib/dbg-io/puts.c similarity index 100% rename from arch/cpu/arm/common/dbg-io/dbg-puts.c rename to os/lib/dbg-io/puts.c diff --git a/arch/cpu/arm/common/dbg-io/dbg-snprintf.c b/os/lib/dbg-io/snprintf.c similarity index 100% rename from arch/cpu/arm/common/dbg-io/dbg-snprintf.c rename to os/lib/dbg-io/snprintf.c diff --git a/arch/cpu/arm/common/dbg-io/dbg-sprintf.c b/os/lib/dbg-io/sprintf.c similarity index 100% rename from arch/cpu/arm/common/dbg-io/dbg-sprintf.c rename to os/lib/dbg-io/sprintf.c diff --git a/arch/cpu/arm/common/dbg-io/strformat.c b/os/lib/dbg-io/strformat.c similarity index 100% rename from arch/cpu/arm/common/dbg-io/strformat.c rename to os/lib/dbg-io/strformat.c diff --git a/arch/cpu/arm/common/dbg-io/strformat.h b/os/lib/dbg-io/strformat.h similarity index 100% rename from arch/cpu/arm/common/dbg-io/strformat.h rename to os/lib/dbg-io/strformat.h From 8e52414e44b8cf8e58a4edcc994f5618a2f4aba1 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 01:34:08 +0000 Subject: [PATCH 08/72] Fix naming convention --- os/lib/dbg-io/printf.c | 4 ++-- os/lib/dbg-io/snprintf.c | 10 +++++----- os/lib/dbg-io/sprintf.c | 4 ++-- os/lib/dbg-io/strformat.c | 16 ++++++++-------- os/lib/dbg-io/strformat.h | 16 +++++++++------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/os/lib/dbg-io/printf.c b/os/lib/dbg-io/printf.c index 5afca6123..36ac0d2e1 100644 --- a/os/lib/dbg-io/printf.c +++ b/os/lib/dbg-io/printf.c @@ -36,7 +36,7 @@ #include #include /*---------------------------------------------------------------------------*/ -static StrFormatResult +static strformat_result write_str(void *user_data, const char *data, unsigned int len) { if(len > 0) { @@ -45,7 +45,7 @@ write_str(void *user_data, const char *data, unsigned int len) return STRFORMAT_OK; } /*---------------------------------------------------------------------------*/ -static StrFormatContext ctxt = +static strformat_context_t ctxt = { write_str, NULL diff --git a/os/lib/dbg-io/snprintf.c b/os/lib/dbg-io/snprintf.c index e7a04ac31..96f99e568 100644 --- a/os/lib/dbg-io/snprintf.c +++ b/os/lib/dbg-io/snprintf.c @@ -35,15 +35,15 @@ #include #include /*---------------------------------------------------------------------------*/ -struct FmtBuffer { +struct fmt_buffer { char *pos; size_t left; }; /*---------------------------------------------------------------------------*/ -static StrFormatResult +static strformat_result buffer_str(void *user_data, const char *data, unsigned int len) { - struct FmtBuffer *buffer = (struct FmtBuffer *)user_data; + struct fmt_buffer *buffer = (struct fmt_buffer *)user_data; if(len >= buffer->left) { len = buffer->left; len--; @@ -69,8 +69,8 @@ snprintf(char *str, size_t size, const char *format, ...) int vsnprintf(char *str, size_t size, const char *format, va_list ap) { - struct FmtBuffer buffer; - StrFormatContext ctxt; + struct fmt_buffer buffer; + strformat_context_t ctxt; int res; ctxt.write_str = buffer_str; ctxt.user_data = &buffer; diff --git a/os/lib/dbg-io/sprintf.c b/os/lib/dbg-io/sprintf.c index 8d0437869..4ecf5b540 100644 --- a/os/lib/dbg-io/sprintf.c +++ b/os/lib/dbg-io/sprintf.c @@ -35,7 +35,7 @@ #include #include /*---------------------------------------------------------------------------*/ -static StrFormatResult +static strformat_result buffer_str(void *user_data, const char *data, unsigned int len) { memcpy(*(char **)user_data, data, len); @@ -46,7 +46,7 @@ buffer_str(void *user_data, const char *data, unsigned int len) int sprintf(char *str, const char *format, ...) { - StrFormatContext ctxt; + strformat_context_t ctxt; int res; va_list ap; va_start(ap, format); diff --git a/os/lib/dbg-io/strformat.c b/os/lib/dbg-io/strformat.c index 8e7d8bd3f..b5ad18f89 100644 --- a/os/lib/dbg-io/strformat.c +++ b/os/lib/dbg-io/strformat.c @@ -239,10 +239,10 @@ output_uint_octal(char **posp, LARGEST_UNSIGNED v) return len; } /*---------------------------------------------------------------------------*/ -static StrFormatResult -fill_space(const StrFormatContext *ctxt, unsigned int len) +static strformat_result +fill_space(const strformat_context_t *ctxt, unsigned int len) { - StrFormatResult res; + strformat_result res; static const char buffer[16] = " "; while(len > 16) { @@ -260,10 +260,10 @@ fill_space(const StrFormatContext *ctxt, unsigned int len) return ctxt->write_str(ctxt->user_data, buffer, len); } /*---------------------------------------------------------------------------*/ -static StrFormatResult -fill_zero(const StrFormatContext *ctxt, unsigned int len) +static strformat_result +fill_zero(const strformat_context_t *ctxt, unsigned int len) { - StrFormatResult res; + strformat_result res; static const char buffer[16] = "0000000000000000"; while(len > 16) { @@ -281,7 +281,7 @@ fill_zero(const StrFormatContext *ctxt, unsigned int len) } /*---------------------------------------------------------------------------*/ int -format_str(const StrFormatContext *ctxt, const char *format, ...) +format_str(const strformat_context_t *ctxt, const char *format, ...) { int ret; va_list ap; @@ -292,7 +292,7 @@ format_str(const StrFormatContext *ctxt, const char *format, ...) } /*---------------------------------------------------------------------------*/ int -format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap) +format_str_v(const strformat_context_t *ctxt, const char *format, va_list ap) { unsigned int written = 0; const char *pos = format; diff --git a/os/lib/dbg-io/strformat.h b/os/lib/dbg-io/strformat.h index f02bc1791..62d99b303 100644 --- a/os/lib/dbg-io/strformat.h +++ b/os/lib/dbg-io/strformat.h @@ -39,21 +39,23 @@ #define STRFORMAT_OK 0 #define STRFORMAT_FAILED 1 /*---------------------------------------------------------------------------*/ -typedef unsigned int StrFormatResult; +typedef unsigned int strformat_result; /*---------------------------------------------------------------------------*/ /* The data argument may only be considered valid during the function call */ -typedef StrFormatResult (*StrFormatWrite)(void *user_data, const char *data, unsigned int len); +typedef strformat_result (*strformat_write)(void *user_data, + const char *data, + unsigned int len); -typedef struct _StrFormatContext { - StrFormatWrite write_str; +typedef struct strformat_context_s { + strformat_write write_str; void *user_data; -} StrFormatContext; +} strformat_context_t; /*---------------------------------------------------------------------------*/ -int format_str(const StrFormatContext *ctxt, const char *format, ...) +int format_str(const strformat_context_t *ctxt, const char *format, ...) __attribute__ ((__format__ (__printf__, 2,3))); int -format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap); +format_str_v(const strformat_context_t *ctxt, const char *format, va_list ap); /*---------------------------------------------------------------------------*/ #endif /* STRFORMAT_H_ */ /*---------------------------------------------------------------------------*/ From ed3e2c850e8e47118e38c8179b0936f7136d38ce Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 22 Nov 2017 01:41:11 +0000 Subject: [PATCH 09/72] Remove depedency to a debug-uart.h --- arch/cpu/arm/common/SD-card/cfs-sdcard.c | 1 - arch/cpu/cc2538/debug-uart.h | 47 -------------------- arch/cpu/cc26xx-cc13xx/debug-uart.h | 49 -------------------- arch/platform/nrf52dk/dbg-io/debug-uart.h | 54 ----------------------- os/lib/dbg-io/printf.c | 1 - os/lib/dbg-io/putchar.c | 1 - os/lib/dbg-io/puts.c | 1 - 7 files changed, 154 deletions(-) delete mode 100644 arch/cpu/cc2538/debug-uart.h delete mode 100644 arch/cpu/cc26xx-cc13xx/debug-uart.h delete mode 100644 arch/platform/nrf52dk/dbg-io/debug-uart.h diff --git a/arch/cpu/arm/common/SD-card/cfs-sdcard.c b/arch/cpu/arm/common/SD-card/cfs-sdcard.c index 9be29fd2e..4c44e3e6b 100644 --- a/arch/cpu/arm/common/SD-card/cfs-sdcard.c +++ b/arch/cpu/arm/common/SD-card/cfs-sdcard.c @@ -1,7 +1,6 @@ #include #include #include -#include #include diff --git a/arch/cpu/cc2538/debug-uart.h b/arch/cpu/cc2538/debug-uart.h deleted file mode 100644 index 88a2fc3e0..000000000 --- a/arch/cpu/cc2538/debug-uart.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ - * 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 cc2538-char-io - * @{ - * - * \file - * This file is here because DBG I/O expects it to be. It just includes - * our own dbg.h which has a non-misleading name and which also adheres - * to Contiki's naming convention - */ -#ifndef DEBUG_UART_H_ -#define DEBUG_UART_H_ - -#include "dbg.h" - -#endif /* DEBUG_UART_H_ */ - -/** @} */ diff --git a/arch/cpu/cc26xx-cc13xx/debug-uart.h b/arch/cpu/cc26xx-cc13xx/debug-uart.h deleted file mode 100644 index c2d9b0ffb..000000000 --- a/arch/cpu/cc26xx-cc13xx/debug-uart.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ - * 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 cc26xx-char-io - * @{ - * - * \file - * This file is here because DBG I/O expects it to be. It just includes - * our own dbg.h which has a non-misleading name and which also adheres - * to Contiki's naming convention - */ -/*---------------------------------------------------------------------------*/ -#ifndef DEBUG_UART_H_ -#define DEBUG_UART_H_ -/*---------------------------------------------------------------------------*/ -#include "dbg.h" -/*---------------------------------------------------------------------------*/ -#endif /* DEBUG_UART_H_ */ -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/arch/platform/nrf52dk/dbg-io/debug-uart.h b/arch/platform/nrf52dk/dbg-io/debug-uart.h deleted file mode 100644 index b52d2fb50..000000000 --- a/arch/platform/nrf52dk/dbg-io/debug-uart.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2015, Nordic Semiconductor - * 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. - * - */ -/** - * \addtogroup nrf52dk - * @{ - * - * \addtogroup nrf52dk-dbg-io Debug IO over UART - * @{ - * - * \file - * A header file to maintain compatibility with DBG I/O. - * \author - * Wojciech Bober - * - */ -/*---------------------------------------------------------------------------*/ -#ifndef DEBUG_UART_H_ -#define DEBUG_UART_H_ -/*---------------------------------------------------------------------------*/ -#include "dbg.h" -/*---------------------------------------------------------------------------*/ -#endif /* DEBUG_UART_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ diff --git a/os/lib/dbg-io/printf.c b/os/lib/dbg-io/printf.c index 36ac0d2e1..9a747d538 100644 --- a/os/lib/dbg-io/printf.c +++ b/os/lib/dbg-io/printf.c @@ -32,7 +32,6 @@ #include "contiki.h" #include -#include #include #include /*---------------------------------------------------------------------------*/ diff --git a/os/lib/dbg-io/putchar.c b/os/lib/dbg-io/putchar.c index 842939ac3..98a3617b2 100644 --- a/os/lib/dbg-io/putchar.c +++ b/os/lib/dbg-io/putchar.c @@ -32,7 +32,6 @@ #include "contiki.h" #include -#include #include /*---------------------------------------------------------------------------*/ #undef putchar diff --git a/os/lib/dbg-io/puts.c b/os/lib/dbg-io/puts.c index a15019620..6332ae471 100644 --- a/os/lib/dbg-io/puts.c +++ b/os/lib/dbg-io/puts.c @@ -32,7 +32,6 @@ #include "contiki.h" #include -#include #include /*---------------------------------------------------------------------------*/ int From 40f6b1a2ba12b2f58c4e3bfe04144ba752ab54a5 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 24 Mar 2018 21:17:32 +0000 Subject: [PATCH 10/72] Rename files to resolve filename conflicts --- arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 2 +- arch/cpu/cc26xx-cc13xx/{putchar.c => dbg.c} | 0 arch/cpu/nrf52832/Makefile.nrf52832 | 2 +- arch/cpu/nrf52832/{putchar.c => dbg.c} | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename arch/cpu/cc26xx-cc13xx/{putchar.c => dbg.c} (100%) rename arch/cpu/nrf52832/{putchar.c => dbg.c} (100%) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index 979d7f5e4..f5543bbc0 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -30,7 +30,7 @@ CONTIKI_CPU_DIRS += . dev rf-core rf-core/api rf-core/ble-hal $(TI_XXWARE_STARTU ### CPU-dependent source files CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c soc-rtc.c uart.c CONTIKI_CPU_SOURCEFILES += contiki-watchdog.c aux-ctrl.c -CONTIKI_CPU_SOURCEFILES += putchar.c ieee-addr.c batmon-sensor.c adc-sensor.c +CONTIKI_CPU_SOURCEFILES += dbg.c ieee-addr.c batmon-sensor.c adc-sensor.c CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c cc26xx-uart.c lpm.c CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c gpio-hal-arch.c oscillators.c CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c diff --git a/arch/cpu/cc26xx-cc13xx/putchar.c b/arch/cpu/cc26xx-cc13xx/dbg.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/putchar.c rename to arch/cpu/cc26xx-cc13xx/dbg.c diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index c2bdbbf81..5e0db414d 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -54,7 +54,7 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou CONTIKI_CPU_DIRS += . dev ble #compat ### CPU-dependent source files -CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c uart0.c putchar.c watchdog.c +CONTIKI_CPU_SOURCEFILES += clock.c rtimer-arch.c uart0.c dbg.c watchdog.c CONTIKI_CPU_SOURCEFILES += int-master.c ifneq ($(NRF52_WITHOUT_SOFTDEVICE),1) diff --git a/arch/cpu/nrf52832/putchar.c b/arch/cpu/nrf52832/dbg.c similarity index 100% rename from arch/cpu/nrf52832/putchar.c rename to arch/cpu/nrf52832/dbg.c From 6d592945a04fc3a2190fadfbc540bce978932202 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 24 Mar 2018 21:22:54 +0000 Subject: [PATCH 11/72] Use a single common dbg.h --- arch/cpu/cc2538/dbg.c | 1 - arch/cpu/cc2538/dbg.h | 89 ------------------- arch/platform/nrf52dk/dbg-io/dbg.h | 67 -------------- .../cpu/cc26xx-cc13xx => os/lib/dbg-io}/dbg.h | 25 +++--- os/lib/dbg-io/printf.c | 1 + os/lib/dbg-io/putchar.c | 1 + os/lib/dbg-io/puts.c | 1 + 7 files changed, 17 insertions(+), 168 deletions(-) delete mode 100644 arch/cpu/cc2538/dbg.h delete mode 100644 arch/platform/nrf52dk/dbg-io/dbg.h rename {arch/cpu/cc26xx-cc13xx => os/lib/dbg-io}/dbg.h (80%) diff --git a/arch/cpu/cc2538/dbg.c b/arch/cpu/cc2538/dbg.c index b97936feb..e95a6c94a 100644 --- a/arch/cpu/cc2538/dbg.c +++ b/arch/cpu/cc2538/dbg.c @@ -37,7 +37,6 @@ */ #include "contiki.h" -#include "dbg.h" #include "dev/uart.h" #include "usb/usb-serial.h" diff --git a/arch/cpu/cc2538/dbg.h b/arch/cpu/cc2538/dbg.h deleted file mode 100644 index d5ab51f9d..000000000 --- a/arch/cpu/cc2538/dbg.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ - * 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 cc2538 - * @{ - * - * \defgroup cc2538-char-io cc2538 Character I/O - * - * CPU-specific functions for debugging and SLIP I/O - * - * On the cc2538, character I/O can be directed over USB or UART. This is - * controlled by a series of configuration directives: - * - SLIP_ARCH_CONF_USB: Controls the operation of slip-arch. - * - DBG_CONF_USB: Controls all debugging output - * - * Defaults for those defines are set in contiki-conf.h - * @{ - * - * \file - * Header file for the cc2538 Debug I/O module - */ -#ifndef DBG_H_ -#define DBG_H_ - -#include "contiki.h" - -#include "usb/usb-serial.h" -/** - * \brief Print a stream of bytes - * \param seq A pointer to the stream - * \param len The number of bytes to print - * \return The number of printed bytes - * - * This function is an arch-specific implementation required by the dbg-io - * API in cpu/arm/common/dbg-io. It prints a stream of bytes over the - * peripheral used by the platform. - */ -unsigned int dbg_send_bytes(const unsigned char *seq, unsigned int len); - -/** - * \brief Flushes character output - * - * When debugging is sent over USB, this functions causes the USB - * driver to immediately TX the content of output buffers. When - * debugging is over UART, this function does nothing. - * - * There is nothing stopping you from using this macro in your code but - * normally, you won't have to. - */ -#if DBG_CONF_USB -#define dbg_flush() usb_serial_flush() -#else -#define dbg_flush() -#endif - -#endif /* DBG_H_ */ - -/** - * @} - * @} - */ diff --git a/arch/platform/nrf52dk/dbg-io/dbg.h b/arch/platform/nrf52dk/dbg-io/dbg.h deleted file mode 100644 index 5d9568270..000000000 --- a/arch/platform/nrf52dk/dbg-io/dbg.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2015, Nordic Semiconductor - * All rights reserved. - * -3 * 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. - * - */ -/** - * \addtogroup nrf52dk - * @{ - * - * \addtogroup nrf52dk-dbg-io Debug IO over UART - * @{ - * - * \file - * Header file for the debug module. - * \author - * Wojciech Bober - * - */ -#ifndef DBG_H_ -#define DBG_H_ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -/*---------------------------------------------------------------------------*/ -/** - * \brief Print a stream of bytes - * \param seq A pointer to the stream - * \param len The number of bytes to print - * \return The number of printed bytes - */ -unsigned int dbg_send_bytes(const unsigned char *seq, unsigned int len); -/** - * \brief Print a character to debug output - * \param c Character to print - * \return Printed character - */ -int dbg_putchar(int c); -/*---------------------------------------------------------------------------*/ -#endif /* DBG_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ diff --git a/arch/cpu/cc26xx-cc13xx/dbg.h b/os/lib/dbg-io/dbg.h similarity index 80% rename from arch/cpu/cc26xx-cc13xx/dbg.h rename to os/lib/dbg-io/dbg.h index 4460b6eb4..14f06fd31 100644 --- a/arch/cpu/cc26xx-cc13xx/dbg.h +++ b/os/lib/dbg-io/dbg.h @@ -1,10 +1,11 @@ /* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2015, Nordic Semiconductor * 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 @@ -27,18 +28,18 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ -/*---------------------------------------------------------------------------*/ /** - * \addtogroup cc26xx + * \addtogroup nrf52dk * @{ * - * \defgroup cc26xx-char-io CC13xx/CC26xx Character I/O - * - * CC13xx/CC26xx CPU-specific functions for debugging and SLIP I/O + * \addtogroup nrf52dk-dbg-io Debug IO over UART * @{ * * \file - * Header file for the CC13xx/CC26xx Debug I/O module + * Header file for the debug module. + * \author + * Wojciech Bober + * */ #ifndef DBG_H_ #define DBG_H_ @@ -50,12 +51,14 @@ * \param seq A pointer to the stream * \param len The number of bytes to print * \return The number of printed bytes - * - * This function is an arch-specific implementation required by the dbg-io - * API in cpu/arm/common/dbg-io. It prints a stream of bytes over the - * peripheral used by the platform. */ unsigned int dbg_send_bytes(const unsigned char *seq, unsigned int len); +/** + * \brief Print a character to debug output + * \param c Character to print + * \return Printed character + */ +int dbg_putchar(int c); /*---------------------------------------------------------------------------*/ #endif /* DBG_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/os/lib/dbg-io/printf.c b/os/lib/dbg-io/printf.c index 9a747d538..9749f1f7d 100644 --- a/os/lib/dbg-io/printf.c +++ b/os/lib/dbg-io/printf.c @@ -30,6 +30,7 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" +#include "lib/dbg-io/dbg.h" #include #include diff --git a/os/lib/dbg-io/putchar.c b/os/lib/dbg-io/putchar.c index 98a3617b2..11bb7b5e6 100644 --- a/os/lib/dbg-io/putchar.c +++ b/os/lib/dbg-io/putchar.c @@ -30,6 +30,7 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" +#include "lib/dbg-io/dbg.h" #include #include diff --git a/os/lib/dbg-io/puts.c b/os/lib/dbg-io/puts.c index 6332ae471..93d73d3a5 100644 --- a/os/lib/dbg-io/puts.c +++ b/os/lib/dbg-io/puts.c @@ -30,6 +30,7 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" +#include "lib/dbg-io/dbg.h" #include #include From 1bf1f37b24ae1b0d6631ed1ab206c56ed8dfa1e3 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 24 Mar 2018 21:25:04 +0000 Subject: [PATCH 12/72] Build dbg-io as a module --- arch/cpu/cc2538/Makefile.cc2538 | 5 ++--- arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 4 ++-- arch/platform/nrf52dk/Makefile.nrf52dk | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index f6e76f571..03758aa9b 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -27,14 +27,13 @@ CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c CONTIKI_CPU_SOURCEFILES += i2c.c cc2538-temp-sensor.c vdd3-sensor.c CONTIKI_CPU_SOURCEFILES += cfs-coffee.c cfs-coffee-arch.c pwm.c -DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c +MODULES += os/lib/dbg-io USB_SOURCEFILES += usb-core.c cdc-acm.c usb-arch.c usb-serial.c cdc-acm-descriptors.c CPU_START_SOURCEFILES = startup-gcc.c -CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(DEBUG_IO_SOURCEFILES) -CONTIKI_SOURCEFILES += $(USB_SOURCEFILES) +CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(USB_SOURCEFILES) ### Always re-build ieee-addr.o in case the command line passes a new NODEID FORCE: diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index f5543bbc0..75dbad7ad 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -37,9 +37,9 @@ CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c -DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c +MODULES += os/lib/dbg-io -CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(DEBUG_IO_SOURCEFILES) +CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) CPU_START_SOURCEFILES += fault-handlers.c $(TI_XXWARE_STARTUP_SRCS) diff --git a/arch/platform/nrf52dk/Makefile.nrf52dk b/arch/platform/nrf52dk/Makefile.nrf52dk index 6187fc532..f52467afb 100644 --- a/arch/platform/nrf52dk/Makefile.nrf52dk +++ b/arch/platform/nrf52dk/Makefile.nrf52dk @@ -15,8 +15,7 @@ CONTIKI_SOURCEFILES += rtt-printf.c segger-rtt.c segger-rtt-printf.c else CONTIKI_TARGET_DIRS += dbg-io CONTIKI_SOURCEFILES += dbg.c -CONTIKI_CPU_DIRS += ../arm/common/dbg-io -CONTIKI_CPU_SOURCEFILES += dbg-printf.c dbg-putchar.c dbg-snprintf.c dbg-sprintf.c strformat.c +MODULES += os/lib/dbg-io endif CLEAN += *.nrf52dk From 86b10b69aaebfc754bb940e04e49ac576e5d4734 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 24 Mar 2018 21:29:51 +0000 Subject: [PATCH 13/72] Resolve multiple symbol definitions --- arch/cpu/cc2538/dbg.c | 17 ++--------------- arch/cpu/cc26xx-cc13xx/dbg.c | 23 +---------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/arch/cpu/cc2538/dbg.c b/arch/cpu/cc2538/dbg.c index e95a6c94a..8f51f235c 100644 --- a/arch/cpu/cc2538/dbg.c +++ b/arch/cpu/cc2538/dbg.c @@ -60,7 +60,7 @@ #define SLIP_END 0300 /*---------------------------------------------------------------------------*/ int -putchar(int c) +dbg_putchar(int c) { #if DBG_CONF_SLIP_MUX static char debug_frame = 0; @@ -79,7 +79,7 @@ putchar(int c) write_byte(SLIP_END); debug_frame = 0; #endif - dbg_flush(); + flush(); } return c; } @@ -99,18 +99,5 @@ dbg_send_bytes(const unsigned char *s, unsigned int len) return i; } /*---------------------------------------------------------------------------*/ -int -puts(const char *s) -{ - unsigned int i = 0; - - while(s && *s != 0) { - putchar(*s++); - i++; - } - putchar('\n'); - return i; -} -/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/cpu/cc26xx-cc13xx/dbg.c b/arch/cpu/cc26xx-cc13xx/dbg.c index 7cbd1901a..bf03aade4 100644 --- a/arch/cpu/cc26xx-cc13xx/dbg.c +++ b/arch/cpu/cc26xx-cc13xx/dbg.c @@ -34,33 +34,12 @@ #include /*---------------------------------------------------------------------------*/ int -putchar(int c) +dbg_putchar(int c) { cc26xx_uart_write_byte(c); return c; } /*---------------------------------------------------------------------------*/ -int -puts(const char *str) -{ - int i; - if(str == NULL) { - return 0; - } - for(i = 0; i < strlen(str); i++) { - cc26xx_uart_write_byte(str[i]); - } - cc26xx_uart_write_byte('\n'); - - /* - * Wait for the line to go out. This is to prevent garbage when used between - * UART on/off cycles - */ - while(cc26xx_uart_busy() == UART_BUSY); - - return i; -} -/*---------------------------------------------------------------------------*/ unsigned int dbg_send_bytes(const unsigned char *s, unsigned int len) { From 04ca5fd46ad593922682fbd7ae5c4317737c398e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 24 Mar 2018 22:47:13 +0000 Subject: [PATCH 14/72] Update doxygen content and structure --- arch/cpu/cc2538/dbg.c | 10 +--------- arch/cpu/cc2538/slip-arch.c | 22 ++-------------------- arch/cpu/cc26xx-cc13xx/slip-arch.c | 17 ----------------- os/lib/dbg-io/dbg.h | 7 ++++--- 4 files changed, 7 insertions(+), 49 deletions(-) diff --git a/arch/cpu/cc2538/dbg.c b/arch/cpu/cc2538/dbg.c index 8f51f235c..c39e05af7 100644 --- a/arch/cpu/cc2538/dbg.c +++ b/arch/cpu/cc2538/dbg.c @@ -28,13 +28,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ -/** \addtogroup cc2538-char-io - * @{ */ -/** - * \file - * Implementation of arch-specific functions required by the dbg_io API in - * cpu/arm/common/dbg-io - */ +/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/uart.h" @@ -99,5 +93,3 @@ dbg_send_bytes(const unsigned char *s, unsigned int len) return i; } /*---------------------------------------------------------------------------*/ - -/** @} */ diff --git a/arch/cpu/cc2538/slip-arch.c b/arch/cpu/cc2538/slip-arch.c index 58aec9f84..dee023a4f 100644 --- a/arch/cpu/cc2538/slip-arch.c +++ b/arch/cpu/cc2538/slip-arch.c @@ -28,21 +28,12 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ -/** - * \addtogroup cc2538-char-io - * @{ - * - * \file - * Arch-specific SLIP functions for the cc2538 - * - * SLIP can be configured to operate over UART or over USB-Serial, depending - * on the value of SLIP_ARCH_CONF_USB - */ +/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/slip.h" #include "dev/uart.h" #include "usb/usb-serial.h" - +/*---------------------------------------------------------------------------*/ #ifndef SLIP_ARCH_CONF_USB #define SLIP_ARCH_CONF_USB 0 #endif @@ -59,10 +50,6 @@ #define SLIP_END 0300 /*---------------------------------------------------------------------------*/ -/** - * \brief Write a byte over SLIP - * \param c the byte - */ void slip_arch_writeb(unsigned char c) { @@ -72,14 +59,9 @@ slip_arch_writeb(unsigned char c) } } /*---------------------------------------------------------------------------*/ -/** - * \brief Initialise the arch-specific SLIP driver - */ void slip_arch_init() { set_input(slip_input_byte); } /*---------------------------------------------------------------------------*/ - -/** @} */ diff --git a/arch/cpu/cc26xx-cc13xx/slip-arch.c b/arch/cpu/cc26xx-cc13xx/slip-arch.c index 6c6914363..f4141e11d 100644 --- a/arch/cpu/cc26xx-cc13xx/slip-arch.c +++ b/arch/cpu/cc26xx-cc13xx/slip-arch.c @@ -29,31 +29,16 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc26xx-char-io - * @{ - * - * \file - * Arch-specific SLIP functions for the CC13xx/CC26xx - */ -/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/cc26xx-uart.h" #include "dev/slip.h" /*---------------------------------------------------------------------------*/ -/** - * \brief Write a byte over SLIP - * \param c the byte - */ void slip_arch_writeb(unsigned char c) { cc26xx_uart_write_byte(c); } /*---------------------------------------------------------------------------*/ -/** - * \brief Initialise the arch-specific SLIP driver - */ void slip_arch_init() { @@ -64,5 +49,3 @@ slip_arch_init() cc26xx_uart_set_input(slip_input_byte); } /*---------------------------------------------------------------------------*/ - -/** @} */ diff --git a/os/lib/dbg-io/dbg.h b/os/lib/dbg-io/dbg.h index 14f06fd31..6440b5eca 100644 --- a/os/lib/dbg-io/dbg.h +++ b/os/lib/dbg-io/dbg.h @@ -28,15 +28,16 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ +/*---------------------------------------------------------------------------*/ /** - * \addtogroup nrf52dk + * \addtogroup lib * @{ * - * \addtogroup nrf52dk-dbg-io Debug IO over UART + * \addtogroup dbg-io Portable debugging output functons * @{ * * \file - * Header file for the debug module. + * Header file for the dbg-io module. * \author * Wojciech Bober * From ce540a8bcadfd87f84e387972e3c57d425eb7750 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:12:31 +0100 Subject: [PATCH 15/72] Harmonise filename pattern for the .map file All map files are now called example-platform.map (e.g. hello-world-native.map). --- Makefile.include | 4 ++++ arch/cpu/arm/cortex-m/cm3/Makefile.cm3 | 2 +- arch/cpu/msp430/Makefile.msp430 | 6 +++--- arch/cpu/native/Makefile.native | 4 ++-- arch/cpu/nrf52832/Makefile.nrf52832 | 2 +- arch/platform/jn516x/Makefile.jn516x | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile.include b/Makefile.include index a37c5ad6a..9afb271df 100644 --- a/Makefile.include +++ b/Makefile.include @@ -288,6 +288,10 @@ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ rm -f $(@:.o=.$$$$) endef +### Harmonize filename of a .map file, if the platform's build system wants +### to create one +CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@)) + clean: -rm -f *~ *core core *.srec \ *.lst *.map *.o \ diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index f5547fea0..f5e8d2a3c 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -5,7 +5,7 @@ CFLAGS += -mcpu=cortex-m3 LDFLAGS += -mcpu=cortex-m3 -nostartfiles LDFLAGS += -T $(LDSCRIPT) LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map),--cref,--no-warn-mismatch +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch OBJCOPY_FLAGS += --gap-fill 0xff diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index ec8c33664..0bb9f356e 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -75,7 +75,7 @@ CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430xlfn.h" $(CFLAGSWERROR) # CFLAGSNO = --dlib_config $(IAR_PATH)/LIB/DLIB/dl430xlfn.h -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X $(CFLAGSWERROR) --data_model large --double=32 endif -LDFLAGSNO += -B -l contiki-$(TARGET).map -s __program_start +LDFLAGSNO += -B -l $(CONTIKI_NG_PROJECT_MAP) -s __program_start # Stack and heap size in hex ifndef IAR_STACK_SIZE IAR_STACK_SIZE=300 @@ -165,7 +165,7 @@ ifndef CFLAGSNO CFLAGSNO = -Wall -mmcu=$(CC_MCU) $(CFLAGSWERROR) endif CFLAGS += -Os -fno-strict-aliasing -LDFLAGS += -mmcu=$(CC_MCU) -Wl,-Map=contiki-$(TARGET).map +LDFLAGS += -mmcu=$(CC_MCU) -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP) ### These flags can reduce the code size and RAM usage with up to 10% SMALL ?= 1 @@ -221,7 +221,7 @@ $(COOJA_PATH)/mspsim/mspsim.jar: $(COOJA_PATH)/mspsim/build.xml java -jar ${COOJA_PATH}/mspsim/mspsim.jar -platform=${TARGET} $< mspsim-maptable: contiki-${TARGET}.map - java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $< + java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $(CONTIKI_NG_PROJECT_MAP) core-labels.o: core.${TARGET} ${CONTIKI}/tools/msp430-make-labels core.${TARGET} > core-labels.S diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index 90a784e34..cda288e65 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -21,11 +21,11 @@ CFLAGS += $(CFLAGSNO) ifeq ($(HOST_OS),Darwin) AROPTS = -r -LDFLAGS += -Wl,-flat_namespace +LDFLAGS += -Wl,-flat_namespace,-map,$(CONTIKI_NG_PROJECT_MAP) CFLAGS += -DHAVE_SNPRINTF=1 -U__ASSERT_USE_STDERR else ifeq ($(HOST_OS),Linux) -LDFLAGS += -Wl,-Map=contiki-$(TARGET).map,-export-dynamic +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),-export-dynamic endif endif diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index c2bdbbf81..3eea82453 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -139,7 +139,7 @@ CFLAGS += -ggdb CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # keep every function in separate section. This will allow linker to dump unused functions -LDFLAGS += -Xlinker -Map=$(@:.elf=-$(TARGET).map) +LDFLAGS += -Xlinker -Map=$(CONTIKI_NG_PROJECT_MAP) LDFLAGS += -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT) LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # let linker to dump unused sections diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index ecdcc2f58..a442dff73 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -239,7 +239,7 @@ ifneq ($(wildcard $(SDK_BASE_DIR)/Components/Library/*),) $(Q)$(CC) -Wl,--gc-sections $(LDFLAGS) -T$(LINKCMD) -o $@ -Wl,--start-group \ $(patsubst /cygdrive/c/%,c:/%,${filter-out %.a,$^}) \ $(patsubst /cygdrive/c/%,c:/%,${filter %.a,$^}) \ - $(ALLLIBS) -Wl,--end-group -Wl,-Map,contiki-$(TARGET).map + $(ALLLIBS) -Wl,--end-group -Wl,-Map,$(CONTIKI_NG_PROJECT_MAP) $(OBJCOPY) -S -O binary $@ $@.bin else # The SDK does not include libraries, only build objects and libraries, skip linking From 87dfa61fd62ab9c0b39b3eb2f812642ff773d6dd Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 21:06:52 +0100 Subject: [PATCH 16/72] Use dbg.c from the CPU dir and delete platform file --- arch/cpu/nrf52832/dbg.c | 38 +++++++------- arch/platform/nrf52dk/Makefile.nrf52dk | 1 - arch/platform/nrf52dk/dbg-io/dbg.c | 72 -------------------------- 3 files changed, 18 insertions(+), 93 deletions(-) delete mode 100644 arch/platform/nrf52dk/dbg-io/dbg.c diff --git a/arch/cpu/nrf52832/dbg.c b/arch/cpu/nrf52832/dbg.c index c4163ba3d..8f7be5cfc 100644 --- a/arch/cpu/nrf52832/dbg.c +++ b/arch/cpu/nrf52832/dbg.c @@ -37,34 +37,32 @@ * Wojciech Bober * */ -/*---------------------------------------------------------------------------*/ -#include #include "dev/uart0.h" /*---------------------------------------------------------------------------*/ +unsigned int +dbg_send_bytes(const unsigned char *s, unsigned int len) +{ + unsigned int i = 0; + + while (s && *s != 0) { + if (i >= len) { + break; + } + uart0_writeb(*s++); + i++; + } + + return i; +} +/*---------------------------------------------------------------------------*/ int -putchar(int c) +dbg_putchar(int c) { uart0_writeb(c); return c; } /*---------------------------------------------------------------------------*/ -int -puts(const char *str) -{ - int i; - - if (str == NULL) { - return 0; - } - - for (i = 0; i < strlen(str); i++) { - uart0_writeb(str[i]); - } - - uart0_writeb('\n'); - return i; -} -/*---------------------------------------------------------------------------*/ /** + * @} * @} */ diff --git a/arch/platform/nrf52dk/Makefile.nrf52dk b/arch/platform/nrf52dk/Makefile.nrf52dk index f52467afb..6561de980 100644 --- a/arch/platform/nrf52dk/Makefile.nrf52dk +++ b/arch/platform/nrf52dk/Makefile.nrf52dk @@ -13,7 +13,6 @@ ifeq ($(NRF52_USE_RTT),1) CONTIKI_TARGET_DIRS += rtt CONTIKI_SOURCEFILES += rtt-printf.c segger-rtt.c segger-rtt-printf.c else -CONTIKI_TARGET_DIRS += dbg-io CONTIKI_SOURCEFILES += dbg.c MODULES += os/lib/dbg-io endif diff --git a/arch/platform/nrf52dk/dbg-io/dbg.c b/arch/platform/nrf52dk/dbg-io/dbg.c deleted file mode 100644 index db9bb63c0..000000000 --- a/arch/platform/nrf52dk/dbg-io/dbg.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2015, Nordic Semiconductor - * 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. - * - */ - -/** - * \addtogroup nrf52dk - * @{ - * - * \addtogroup nrf52dk-dbg-io Debug IO over UART - * @{ - * - * \file - * Function implementations for debug io module. - * \author - * Wojciech Bober - * - */ -#include "dev/uart0.h" -/*---------------------------------------------------------------------------*/ -unsigned int -dbg_send_bytes(const unsigned char *s, unsigned int len) -{ - unsigned int i = 0; - - while (s && *s != 0) { - if (i >= len) { - break; - } - uart0_writeb(*s++); - i++; - } - - return i; -} -/*---------------------------------------------------------------------------*/ -int -dbg_putchar(int c) -{ - uart0_writeb(c); - return c; -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ From 16d8c5b4f925e02c6f8badadd9b3ad494653d18e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:14:33 +0100 Subject: [PATCH 17/72] Use a variable for the Contiki-NG archive file Prevents having to hard-code the filename in multiple cpu/platform makefiles and allows us to easily rename it across the board in the future --- Makefile.include | 6 ++++-- arch/cpu/arm/cortex-m/cm4/Makefile.cm4 | 2 +- arch/cpu/msp430/Makefile.msp430 | 2 +- arch/platform/jn516x/Makefile.jn516x | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile.include b/Makefile.include index 9afb271df..d399b77f1 100644 --- a/Makefile.include +++ b/Makefile.include @@ -10,6 +10,8 @@ WERROR ?= 1 include $(CONTIKI)/Makefile.identify-target +CONTIKI_NG_TARGET_LIB = contiki-ng-$(TARGET).a + ifeq ($(DEFINES),) -include Makefile.$(TARGET).defines ifneq ($(DEFINES),) @@ -355,7 +357,7 @@ ifndef AROPTS endif ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB -contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES) +$(CONTIKI_NG_TARGET_LIB): $(CONTIKI_OBJECTFILES) $(TRACE_AR) $(Q)$(AR) $(AROPTS) $@ $^ endif @@ -365,7 +367,7 @@ ifndef LD endif ifndef CUSTOM_RULE_LINK -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a +%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TRACE_LD) $(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \ ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index 78367b0eb..1f3cdd00b 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -6,7 +6,7 @@ LDFLAGS += -mcpu=cortex-m4 ### Compilation rules CUSTOM_RULE_LINK=1 -%.elf: $(TARGET_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(TARGET_LIBS) +%.elf: $(TARGET_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TARGET_LIBS) $(TRACE_LD) $(Q)$(CC) $(LDFLAGS) ${filter %.o %.a,$^} -o $@ diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index 0bb9f356e..2f0b18d0e 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -197,7 +197,7 @@ PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} mv $< $@ ifdef IAR -%.ihex: %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a +%.ihex: %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(LD) $(LDFLAGSNO) -Fintel-extended $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ else %.ihex: %.$(TARGET) diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index a442dff73..a70c4f3e6 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -234,7 +234,7 @@ ABS_APPLIBS = $(addsuffix _$(JENNIC_CHIP_FAMILY).a,$(addprefix $(COMPONENTS_BASE ifneq ($(wildcard $(SDK_BASE_DIR)/Components/Library/*),) # The SDK is fully installed, proceed to linking and objcopy to ready-to-upload .jn516x.bin file -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(ABS_APPLIBS) +%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(ABS_APPLIBS) echo ${filter %.a,$^} $(Q)$(CC) -Wl,--gc-sections $(LDFLAGS) -T$(LINKCMD) -o $@ -Wl,--start-group \ $(patsubst /cygdrive/c/%,c:/%,${filter-out %.a,$^}) \ @@ -243,7 +243,7 @@ ifneq ($(wildcard $(SDK_BASE_DIR)/Components/Library/*),) $(OBJCOPY) -S -O binary $@ $@.bin else # The SDK does not include libraries, only build objects and libraries, skip linking -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a +%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) echo Creating empty $@ touch $@ endif From 1d3122750aec79dd080aa0e8813f6ffe25fe406e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:15:44 +0100 Subject: [PATCH 18/72] Define different mspsim-maptable per project The rule is changed such that it makes sure the .map file gets built first. We have separate map files per project, so we need separate mspsim-maptables --- arch/cpu/msp430/Makefile.msp430 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index 2f0b18d0e..3cc432ad5 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -220,7 +220,7 @@ $(COOJA_PATH)/mspsim/mspsim.jar: $(COOJA_PATH)/mspsim/build.xml %.mspsim: %.${TARGET} ${COOJA_PATH}/mspsim/mspsim.jar java -jar ${COOJA_PATH}/mspsim/mspsim.jar -platform=${TARGET} $< -mspsim-maptable: contiki-${TARGET}.map +%.mspsim-maptable: %.$(TARGET) java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $(CONTIKI_NG_PROJECT_MAP) core-labels.o: core.${TARGET} From c7e36a3d55d9c3ba96f46963b10410c025e25dc0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:20:28 +0100 Subject: [PATCH 19/72] Change clean target to be more explicit Previously, the clean target would delete a number of file extensions, many of which currently unknown to our build system (old platforms?). This commit changes the target so that it only cleans what we know we are building. Platforms / CPUs can append to the target with platform-specific build artifacts. --- Makefile.include | 7 +++---- arch/cpu/arm/Makefile.arm | 2 +- arch/cpu/msp430/Makefile.msp430 | 3 +++ arch/platform/cc2538dk/Makefile.cc2538dk | 2 -- arch/platform/cooja/Makefile.cooja | 2 ++ arch/platform/jn516x/Makefile.jn516x | 1 - arch/platform/native/Makefile.native | 2 -- arch/platform/nrf52dk/Makefile.nrf52dk | 2 -- arch/platform/openmote-cc2538/Makefile.openmote-cc2538 | 2 -- arch/platform/sky/Makefile.sky | 2 -- arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx | 2 -- arch/platform/zoul/Makefile.zoul | 2 -- 12 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Makefile.include b/Makefile.include index d399b77f1..802be19d9 100644 --- a/Makefile.include +++ b/Makefile.include @@ -295,11 +295,10 @@ endef CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@)) clean: - -rm -f *~ *core core *.srec \ - *.lst *.map *.o \ - *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \ - rm -rf $(CLEAN) + -rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN) -rm -rf $(OBJECTDIR) + -rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT)) + -rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) distclean: clean -rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)} diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index ba93b82a0..0b2662423 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -31,7 +31,7 @@ CONTIKI_ARM_DIRS += . common/dbg-io CONTIKI_CPU_DIRS += $(addprefix ../arm/, $(CONTIKI_ARM_DIRS)) ### CPU-dependent cleanup files -CLEAN += *.d *.elf *.hex +CLEAN += *.elf *.bin *.lst *.hex *.i16hex ### Don't treat the following files as intermediate .PRECIOUS: %.elf %.hex %.bin diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index 3cc432ad5..841e11285 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -184,6 +184,9 @@ CFLAGS += $(CFLAGSNO) PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} +### CPU-dependent cleanup files +CLEAN += *.firmware *.ihex + ### Compilation rules %-stripped.o: %.c diff --git a/arch/platform/cc2538dk/Makefile.cc2538dk b/arch/platform/cc2538dk/Makefile.cc2538dk index 2b88479d2..c452ccfaf 100644 --- a/arch/platform/cc2538dk/Makefile.cc2538dk +++ b/arch/platform/cc2538dk/Makefile.cc2538dk @@ -13,8 +13,6 @@ CONTIKI_TARGET_SOURCEFILES += board-buttons.c als-sensor.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.cc2538dk - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 diff --git a/arch/platform/cooja/Makefile.cooja b/arch/platform/cooja/Makefile.cooja index 541ae51f0..d06aa08d5 100644 --- a/arch/platform/cooja/Makefile.cooja +++ b/arch/platform/cooja/Makefile.cooja @@ -64,6 +64,8 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) .SUFFIXES: +CLEAN += COOJA.log + ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/x86 diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index a70c4f3e6..fafadb831 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -140,7 +140,6 @@ ifdef nodemac CFLAGS += -DMACID=$(nodemac) endif -CLEAN += *.jn516x CLEAN += *.jn516x.bin CONTIKI_TARGET_SOURCEFILES += $(ARCH) diff --git a/arch/platform/native/Makefile.native b/arch/platform/native/Makefile.native index bee104a6c..24f433796 100644 --- a/arch/platform/native/Makefile.native +++ b/arch/platform/native/Makefile.native @@ -30,8 +30,6 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) # Enable nullmac by default MAKE_MAC ?= MAKE_MAC_NULLMAC -CLEAN += *.native - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/native include $(CONTIKI)/arch/cpu/native/Makefile.native diff --git a/arch/platform/nrf52dk/Makefile.nrf52dk b/arch/platform/nrf52dk/Makefile.nrf52dk index 6187fc532..ff6d54a44 100644 --- a/arch/platform/nrf52dk/Makefile.nrf52dk +++ b/arch/platform/nrf52dk/Makefile.nrf52dk @@ -19,8 +19,6 @@ CONTIKI_CPU_DIRS += ../arm/common/dbg-io CONTIKI_CPU_SOURCEFILES += dbg-printf.c dbg-putchar.c dbg-snprintf.c dbg-sprintf.c strformat.c endif -CLEAN += *.nrf52dk - ### Unless the example dictates otherwise, build with code size optimisations switched off SMALL ?= 0 diff --git a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 index 14aa46f78..d3863fdbc 100644 --- a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 +++ b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -20,8 +20,6 @@ CONTIKI_TARGET_SOURCEFILES += antenna.c adxl346.c max44009.c sht21.c tps62730.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.openmote-cc2538 - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 diff --git a/arch/platform/sky/Makefile.sky b/arch/platform/sky/Makefile.sky index 9467603a4..0398486b0 100644 --- a/arch/platform/sky/Makefile.sky +++ b/arch/platform/sky/Makefile.sky @@ -4,8 +4,6 @@ CONTIKI_TARGET_SOURCEFILES += contiki-sky-platform.c \ sht11.c sht11-sensor.c light-sensor.c battery-sensor.c \ button-sensor.c -CLEAN += *.sky - include $(CONTIKI)/arch/platform/sky/Makefile.common MODULES += arch/dev/cc2420 arch/dev/sht11 arch/dev/ds2411 os/storage/cfs diff --git a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx index 7bead9fff..db4209adc 100644 --- a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx @@ -19,8 +19,6 @@ CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.srf06-cc26xx - ### Unless the example dictates otherwise, build without code size optimisations SMALL ?= 0 diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 6bbcd675b..586a74ae2 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -38,8 +38,6 @@ CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -CLEAN += *.zoul - ### Define the CPU directory CONTIKI_CPU=$(CONTIKI)/arch/cpu/cc2538 include $(CONTIKI_CPU)/Makefile.cc2538 From 9a1d34e163aa630e506a08f5814711cad3ded3e3 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:20:55 +0100 Subject: [PATCH 20/72] Change distclean to clean all platforms --- Makefile.include | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile.include b/Makefile.include index 802be19d9..a55bf0901 100644 --- a/Makefile.include +++ b/Makefile.include @@ -300,8 +300,11 @@ clean: -rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT)) -rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) -distclean: clean - -rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)} +distclean: + @for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \ + echo make $$TARG clean; \ + make TARGET=$$TARG clean; \ + done -include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) From a22324291f0d1ea1a816334e5c565d0b5a19bd06 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:22:03 +0100 Subject: [PATCH 21/72] Specify a number of targets as .PHONY --- Makefile.include | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.include b/Makefile.include index a55bf0901..4a05b326a 100644 --- a/Makefile.include +++ b/Makefile.include @@ -294,6 +294,8 @@ endef ### to create one CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@)) +.PHONY: clean distclean usage help targets boards savetarget savedefines viewconf + clean: -rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN) -rm -rf $(OBJECTDIR) From 3f4a1f7c54104cb6da21d4ac1a76e45dddc1ae98 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 20:22:20 +0100 Subject: [PATCH 22/72] Extend the usage target and add help target --- Makefile.include | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile.include b/Makefile.include index 4a05b326a..75f016d42 100644 --- a/Makefile.include +++ b/Makefile.include @@ -384,7 +384,25 @@ endif $(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4 usage: - @echo "make MAKETARGETS... [TARGET=(TARGET)] [BOARD=(BOARD)] [savetarget] [targets]" + @echo "Usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [target]" + @echo "" + @echo "Typical usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]" + @echo "" + @echo " Will build Contiki-NG firmware(s) from the current example dir" + @echo " for platform TARGET, board BOARD." + @echo "" + @echo "Miscellaneous targets:" + @echo " targets Prints list of supported platforms" + @echo " boards Prints a list of supported boards for TARGET" + @echo " savegtarget Saves TARGET and BOARD for future invocations of make" + @echo " savedefines Saves DEFINES for future invocations of make" + @echo " clean Removes all compiled files for TARGET" + @echo " distclean Removes all compiled files for all TARGETs" + @echo " viewconf Prints Contiki-NG build configuration for TARGET" + +help: usage targets: @ls $(CONTIKI)/arch/platform $(TARGETDIRS) From be2a818eaa97c8922793c9900131037cf69ba2d6 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 21:19:04 +0100 Subject: [PATCH 23/72] Adjust nrf52832 compile output --- arch/cpu/nrf52832/Makefile.nrf52832 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index 3eea82453..0200f2df4 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -182,7 +182,7 @@ nrf52832.a: $(OBJECTS) # Assemble files $(OBJECT_DIRECTORY)/%.o: %.s - @echo Compiling file: $(notdir $<) + $(TRACE_CC) $(Q)$(CC) $(ASMFLAGS) $(addprefix -I$(NRF52_SDK_ROOT)/, $(INC_PATHS)) -c -o $@ $< %.jlink: From b2438b4563e9974415238b627c47b34e33835d05 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 22:20:10 +0100 Subject: [PATCH 24/72] Enable putchar for all arm platforms Instead of having to #undef putchar in every file where we want to use it, we undef it across the board. See the comment in arm-def.h as to why this needs done. --- arch/cpu/arm/arm-def.h | 19 +++++++++++++++++++ arch/cpu/cc2538/dbg.c | 3 --- os/lib/dbg-io/putchar.c | 1 - 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/cpu/arm/arm-def.h b/arch/cpu/arm/arm-def.h index 2cd31604c..92b19048d 100644 --- a/arch/cpu/arm/arm-def.h +++ b/arch/cpu/arm/arm-def.h @@ -60,6 +60,25 @@ typedef uint32_t uip_stats_t; typedef uint32_t rtimer_clock_t; #define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b))) /** @} */ + +/* + * The stdio.h that ships with the arm-gcc toolchain does this: + * + * int _EXFUN(putchar, (int)); + * [...] + * #define putchar(x) putc(x, stdout) + * + * This causes us a lot of trouble: For platforms using this toolchain, every + * time we use putchar we need to first #undef putchar. What we do here is to + * #undef putchar across the board. The resulting code will cause the linker + * to search for a symbol named putchar and this allows us to use the + * implementation under os/lib/dbg-io. + * + * This will fail if stdio.h is included before contiki.h, but it is common + * practice to include contiki.h first + */ +#include +#undef putchar /*---------------------------------------------------------------------------*/ #endif /* ARM_DEF_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc2538/dbg.c b/arch/cpu/cc2538/dbg.c index c39e05af7..7b33bc471 100644 --- a/arch/cpu/cc2538/dbg.c +++ b/arch/cpu/cc2538/dbg.c @@ -48,9 +48,6 @@ #define flush() #endif /*---------------------------------------------------------------------------*/ -#undef putchar -#undef puts - #define SLIP_END 0300 /*---------------------------------------------------------------------------*/ int diff --git a/os/lib/dbg-io/putchar.c b/os/lib/dbg-io/putchar.c index 11bb7b5e6..d5b81e2ab 100644 --- a/os/lib/dbg-io/putchar.c +++ b/os/lib/dbg-io/putchar.c @@ -35,7 +35,6 @@ #include #include /*---------------------------------------------------------------------------*/ -#undef putchar #undef putc /*---------------------------------------------------------------------------*/ int From 148e796ee115fe386381077e244980503c4eeb20 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 22:21:24 +0100 Subject: [PATCH 25/72] Don't implement putc and __sp Those two functions are not necessary in Contiki-NG --- os/lib/dbg-io/putchar.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/os/lib/dbg-io/putchar.c b/os/lib/dbg-io/putchar.c index d5b81e2ab..26a35446d 100644 --- a/os/lib/dbg-io/putchar.c +++ b/os/lib/dbg-io/putchar.c @@ -35,8 +35,6 @@ #include #include /*---------------------------------------------------------------------------*/ -#undef putc -/*---------------------------------------------------------------------------*/ int putchar(int c) { @@ -44,17 +42,3 @@ putchar(int c) return c; } /*---------------------------------------------------------------------------*/ -int -putc(int c, FILE *f) -{ - dbg_putchar(c); - return c; -} -/*---------------------------------------------------------------------------*/ -int -__sp(struct _reent *_ptr, int c, FILE *_p) -{ - dbg_putchar(c); - return c; -} -/*---------------------------------------------------------------------------*/ From 59e26c8b210215d5dda456dfb597449d59f428d9 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2018 14:28:08 +0100 Subject: [PATCH 26/72] Add some logging to the GPIO HAL --- os/dev/gpio-hal.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/os/dev/gpio-hal.c b/os/dev/gpio-hal.c index 70b50b688..658152293 100644 --- a/os/dev/gpio-hal.c +++ b/os/dev/gpio-hal.c @@ -40,10 +40,15 @@ #include "contiki.h" #include "dev/gpio-hal.h" #include "lib/list.h" +#include "sys/log.h" #include #include /*---------------------------------------------------------------------------*/ +/* Log configuration */ +#define LOG_MODULE "GPIO HAL" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ LIST(handlers); /*---------------------------------------------------------------------------*/ void @@ -78,6 +83,7 @@ void gpio_hal_arch_toggle_pin(gpio_hal_pin_t pin) { if(pin >= GPIO_HAL_PIN_COUNT) { + LOG_ERR("Pin %u out of bounds\n", pin); return; } From 1d59a258edfa9154c5064312cf73f26f9b38e334 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 31 Mar 2018 21:55:31 +0100 Subject: [PATCH 27/72] Remove obsolete typedefs --- arch/platform/native/contiki-conf.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/platform/native/contiki-conf.h b/arch/platform/native/contiki-conf.h index b8a43a604..ea1383660 100644 --- a/arch/platform/native/contiki-conf.h +++ b/arch/platform/native/contiki-conf.h @@ -58,12 +58,6 @@ int select_set_callback(int fd, const struct select_callback *callback); #define EEPROM_CONF_SIZE 1024 #endif -/* These names are deprecated, use C99 names. */ -typedef uint8_t u8_t; -typedef uint16_t u16_t; -typedef uint32_t u32_t; -typedef int32_t s32_t; - typedef unsigned int uip_stats_t; #define LEDS_CONF_LEGACY_API 1 From 84a74907f3983e138c3e0d6efaed645daebbd124 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2018 14:31:06 +0100 Subject: [PATCH 28/72] Allow the LED HAL to work on platforms without LEDs --- os/dev/leds.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/os/dev/leds.c b/os/dev/leds.c index eff3197a1..f2ce82c29 100644 --- a/os/dev/leds.c +++ b/os/dev/leds.c @@ -97,7 +97,11 @@ leds_toggle(leds_mask_t ledv) /*---------------------------------------------------------------------------*/ #else /* LEDS_LEGACY_API */ /*---------------------------------------------------------------------------*/ +#if LEDS_COUNT extern const leds_t leds_arch_leds[]; +#else +static const leds_t *leds_arch_leds = NULL; +#endif /*---------------------------------------------------------------------------*/ void leds_init() From 5d1ed3c17f8c97bb01f57363e7e442fda7f65f1b Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2018 16:15:02 +0100 Subject: [PATCH 29/72] Fix CONTIKI_VERSION_STRING Currently, the version string always ends with -dirty. This is related to the logic behind --git-dir, which assumes that the current working dir is the top-level dir of the repo, unless --work-tree is also specified --- Makefile.include | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.include b/Makefile.include index a37c5ad6a..39ec53974 100644 --- a/Makefile.include +++ b/Makefile.include @@ -263,7 +263,8 @@ CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)} ### Check for a git repo and pass version if found ### git.exe in Windows cmd shells may require no stderr redirection ifndef RELSTR -RELSTR:=${shell git --git-dir ${CONTIKI}/.git describe --tags --always --dirty} +RELSTR:=${shell git --git-dir ${CONTIKI}/.git --work-tree ${CONTIKI} describe \ + --tags --always --dirty} endif ifneq ($(RELSTR),) From a025a9020f4c2acb3d7086b65f914f084dfbdf47 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 16:16:36 +0100 Subject: [PATCH 30/72] Allow the MQTT client to build & work without platform-specific extensions --- .../arch/platform/cc2538dk/module-macros.h | 34 +++++++++++++++++++ .../platform/openmote-cc2538/module-macros.h | 34 +++++++++++++++++++ .../platform/srf06-cc26xx/module-macros.h | 34 +++++++++++++++++++ .../arch/platform/zoul/module-macros.h | 34 +++++++++++++++++++ examples/mqtt-client/mqtt-client.c | 11 ++++++ 5 files changed, 147 insertions(+) create mode 100644 examples/mqtt-client/arch/platform/cc2538dk/module-macros.h create mode 100644 examples/mqtt-client/arch/platform/openmote-cc2538/module-macros.h create mode 100644 examples/mqtt-client/arch/platform/srf06-cc26xx/module-macros.h create mode 100644 examples/mqtt-client/arch/platform/zoul/module-macros.h diff --git a/examples/mqtt-client/arch/platform/cc2538dk/module-macros.h b/examples/mqtt-client/arch/platform/cc2538dk/module-macros.h new file mode 100644 index 000000000..6f0bce121 --- /dev/null +++ b/examples/mqtt-client/arch/platform/cc2538dk/module-macros.h @@ -0,0 +1,34 @@ +/* + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* Enable MQTT client extensions */ +#define MQTT_CLIENT_CONF_WITH_EXTENSIONS 1 +/*---------------------------------------------------------------------------*/ diff --git a/examples/mqtt-client/arch/platform/openmote-cc2538/module-macros.h b/examples/mqtt-client/arch/platform/openmote-cc2538/module-macros.h new file mode 100644 index 000000000..097c26dd8 --- /dev/null +++ b/examples/mqtt-client/arch/platform/openmote-cc2538/module-macros.h @@ -0,0 +1,34 @@ +/* + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* Enable MQTT client extensions */ +#define MQTT_CLIENT_CONF_WITH_EXTENSIONS 1 +/*---------------------------------------------------------------------------*/ diff --git a/examples/mqtt-client/arch/platform/srf06-cc26xx/module-macros.h b/examples/mqtt-client/arch/platform/srf06-cc26xx/module-macros.h new file mode 100644 index 000000000..6f0bce121 --- /dev/null +++ b/examples/mqtt-client/arch/platform/srf06-cc26xx/module-macros.h @@ -0,0 +1,34 @@ +/* + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* Enable MQTT client extensions */ +#define MQTT_CLIENT_CONF_WITH_EXTENSIONS 1 +/*---------------------------------------------------------------------------*/ diff --git a/examples/mqtt-client/arch/platform/zoul/module-macros.h b/examples/mqtt-client/arch/platform/zoul/module-macros.h new file mode 100644 index 000000000..6f0bce121 --- /dev/null +++ b/examples/mqtt-client/arch/platform/zoul/module-macros.h @@ -0,0 +1,34 @@ +/* + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* Enable MQTT client extensions */ +#define MQTT_CLIENT_CONF_WITH_EXTENSIONS 1 +/*---------------------------------------------------------------------------*/ diff --git a/examples/mqtt-client/mqtt-client.c b/examples/mqtt-client/mqtt-client.c index 867ef9982..258660459 100644 --- a/examples/mqtt-client/mqtt-client.c +++ b/examples/mqtt-client/mqtt-client.c @@ -71,6 +71,12 @@ static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd"; #define MQTT_CLIENT_STATUS_LED LEDS_GREEN #endif /*---------------------------------------------------------------------------*/ +#ifdef MQTT_CLIENT_CONF_WITH_EXTENSIONS +#define MQTT_CLIENT_WITH_EXTENSIONS MQTT_CLIENT_CONF_WITH_EXTENSIONS +#else +#define MQTT_CLIENT_WITH_EXTENSIONS 0 +#endif +/*---------------------------------------------------------------------------*/ /* * A timeout used when waiting for something to happen (e.g. to connect or to * disconnect) @@ -197,8 +203,13 @@ static int def_rt_rssi = 0; /*---------------------------------------------------------------------------*/ static mqtt_client_config_t conf; /*---------------------------------------------------------------------------*/ +#if MQTT_CLIENT_WITH_EXTENSIONS extern const mqtt_client_extension_t *mqtt_client_extensions[]; extern const uint8_t mqtt_client_extension_count; +#else +static const mqtt_client_extension_t *mqtt_client_extensions[] = { NULL }; +static const uint8_t mqtt_client_extension_count = 0; +#endif /*---------------------------------------------------------------------------*/ PROCESS(mqtt_client_process, "MQTT Client"); /*---------------------------------------------------------------------------*/ From 4bc9424dd347d73562dcca58ee12c84987c8b898 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 2 Apr 2018 15:48:48 +0100 Subject: [PATCH 31/72] Ignore .e and .o even if outside obj_ --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index f8f72f54b..9f825c9f3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ *.elf *.zip *.d +*.o +*.e *.ihex *.pyc *~ From 7a17d652b56c861d31e3329b349924867a24a2f0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 2 Apr 2018 15:50:09 +0100 Subject: [PATCH 32/72] Git ignore the msp430-specific .firmware make target --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9f825c9f3..a67ff3f50 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ COOJA.testlog *.nrf52dk *.openmote-cc2538 *.sky +*.firmware *.srf06-cc26xx *.zoul From 46f73b9a8ae13e62793404cf13a200f71bf1ab17 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 2 Apr 2018 23:00:52 +0100 Subject: [PATCH 33/72] Remove obsolete Makefile --- os/net/mac/tsch/Makefile.tsch | 1 - 1 file changed, 1 deletion(-) delete mode 100644 os/net/mac/tsch/Makefile.tsch diff --git a/os/net/mac/tsch/Makefile.tsch b/os/net/mac/tsch/Makefile.tsch deleted file mode 100644 index e19ff8b13..000000000 --- a/os/net/mac/tsch/Makefile.tsch +++ /dev/null @@ -1 +0,0 @@ -CONTIKI_SOURCEFILES += tsch.c tsch-slot-operation.c tsch-queue.c tsch-packet.c tsch-schedule.c tsch-log.c tsch-rpl.c tsch-adaptive-timesync.c From 76bcfcb8cc5fe155a375c24654ea333440fe0f5d Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 15:32:14 +0100 Subject: [PATCH 34/72] Move slip.c to top-level platform code dir --- arch/platform/jn516x/{lib => }/slip.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename arch/platform/jn516x/{lib => }/slip.c (100%) diff --git a/arch/platform/jn516x/lib/slip.c b/arch/platform/jn516x/slip.c similarity index 100% rename from arch/platform/jn516x/lib/slip.c rename to arch/platform/jn516x/slip.c From f0315cf5c7c97c8409906abdb32ba3dd48ea7818 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 15:33:13 +0100 Subject: [PATCH 35/72] Implement dbg_putchar() and dbg_send_bytes() Those two functions are needed so we can use os/lib/dbg-io for this platform. The old putchar() in slip.c is no longer needed. --- arch/platform/jn516x/dbg.c | 56 +++++++++++++++++++++++++++++++++++++ arch/platform/jn516x/slip.c | 6 ---- 2 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 arch/platform/jn516x/dbg.c diff --git a/arch/platform/jn516x/dbg.c b/arch/platform/jn516x/dbg.c new file mode 100644 index 000000000..ac6cc3888 --- /dev/null +++ b/arch/platform/jn516x/dbg.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, SICS Swedish ICT. + * 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. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" + +#include +#include "dev/uart0.h" +/*---------------------------------------------------------------------------*/ +int +dbg_putchar(int c) +{ + uart0_writeb(c); + return 1; +} +/*---------------------------------------------------------------------------*/ +unsigned int +dbg_send_bytes(const unsigned char *s, unsigned int len) +{ + unsigned int i = 0; + + while(s && *s != 0) { + if(i >= len) { + break; + } + uart0_writeb(*s++); + i++; + } + return i; +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/platform/jn516x/slip.c b/arch/platform/jn516x/slip.c index bdf3c81b5..173a14d60 100644 --- a/arch/platform/jn516x/slip.c +++ b/arch/platform/jn516x/slip.c @@ -429,9 +429,3 @@ slip_input_byte(unsigned char c) return error_return_code; } /*---------------------------------------------------------------------------*/ -int -putchar(int c) -{ - uart0_writeb(c); - return 1; -} From 16f61bc769305f4b6ddfedec3cce5372636cc0c5 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 15:34:10 +0100 Subject: [PATCH 36/72] Delete platform-specific implementation of stdio functions --- arch/platform/jn516x/lib/sprintf.c | 237 ----------------------------- 1 file changed, 237 deletions(-) delete mode 100644 arch/platform/jn516x/lib/sprintf.c diff --git a/arch/platform/jn516x/lib/sprintf.c b/arch/platform/jn516x/lib/sprintf.c deleted file mode 100644 index dd2408090..000000000 --- a/arch/platform/jn516x/lib/sprintf.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - File: printf.c - - Copyright (c) 2004,2008 Kustaa Nyholm / SpareTimeLabs - - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list - of conditions and the following disclaimer. - - 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. - - Neither the name of the Kustaa Nyholm or SpareTimeLabs 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. - - */ - -/* - * This is BSD code obtained from http://www.sparetimelabs.com/printfrevisited/index.html - * From the web page: - * "The code is GPL and BSD lincensed, download the BSD licensed version from the link - * above or use the GPL licensed code from this page below." - * - * modified by Beshr Al Nahas and Simon Duquennoy - */ - -#include "contiki.h" -#include -#include -#include -#include -#include -#include "dev/uart0.h" - -static char *bf, buf[14], uc, zs; -static unsigned int num; - -static void -out(char c) -{ - *bf++ = c; -} -static void -outDgt(char dgt) -{ - out(dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10)); - zs = 1; -} -static void -divOut(unsigned int div) -{ - unsigned char dgt = 0; - while(num >= div) { - num -= div; - dgt++; - } - if(zs || dgt > 0) { - outDgt(dgt); - } -} -int -vsnprintf(char *str, size_t n, const char *fmt, __VALIST va) -{ - char ch, *p, *str_orig = str; - char next_ch; - - while((ch = *fmt++) && str - str_orig < n) { - if(ch != '%') { - *str++ = ch; - } else { - char lz = 0; - char w = 0; - ch = *(fmt++); - if(ch == '0') { - ch = *(fmt++); - lz = 1; - } - if(ch == '-' || (ch >= '0' && ch <= '9')) { - w = 0; - while(ch == '-' || (ch >= '0' && ch <= '9')) { - if(ch != '-') { - w = (((w << 2) + w) << 1) + ch - '0'; - } - ch = *fmt++; - } - } - bf = buf; - p = bf; - zs = 0; -start_format: - next_ch = *fmt; - switch(ch) { - case 0: - goto abort; - case 'l': - if(next_ch == 'x' - || next_ch == 'X' - || next_ch == 'u' - || next_ch == 'd') { - ch = *(fmt++); - goto start_format; - } - case 'u': - case 'd': - num = va_arg(va, unsigned int); - if(ch == 'd' && (int)num < 0) { - num = -(int)num; - out('-'); - } - divOut(1000000000); - divOut(100000000); - divOut(10000000); - divOut(1000000); - divOut(100000); - divOut(10000); - divOut(1000); - divOut(100); - divOut(10); - outDgt(num); - break; - case 'p': - case 'x': - case 'X': - uc = ch == 'X'; - num = va_arg(va, unsigned int); - /* divOut(0x100000000UL); */ - divOut(0x10000000); - divOut(0x1000000); - divOut(0x100000); - divOut(0x10000); - divOut(0x1000); - divOut(0x100); - divOut(0x10); - outDgt(num); - break; - case 'c': - out((char)(va_arg(va, int))); - break; - case 's': - p = va_arg(va, char *); - break; - case '%': - out('%'); - default: - break; - } - *bf = 0; - bf = p; - - while(*bf++ && w > 0) { - w--; - } - while(w-- > 0) { - if(str - str_orig < n) { - *str++ = lz ? '0' : ' '; - } else { - goto abort; - } - } - while((ch = *p++)) { - if(str - str_orig < n) { - *str++ = ch; - } else { - goto abort; - } - } - } - } - -abort: - if(str - str_orig < n) { - *str = '\0'; - } else { - *(--str) = '\0'; - } return str - str_orig; -} -int -sprintf(char *str, const char *fmt, ...) -{ - int m; - __VALIST va; - va_start(va, fmt); - m = vsnprintf(str, 0xffffffff, fmt, va); - va_end(va); - return m; -} -int -snprintf(char *str, size_t n, const char *fmt, ...) -{ - int m; - __VALIST va; - va_start(va, fmt); - m = vsnprintf(str, n, fmt, va); - va_end(va); - return m; -} -int -printf(const char *fmt, ...) -{ - int m, i; - char str[256]; - __VALIST va; - va_start(va, fmt); - m = vsnprintf(str, sizeof(str), fmt, va); - va_end(va); - for(i = 0; i < m; i++) { - putchar(str[i]); - } - return m; -} -int -puts(const char *s) -{ - char c; - while((c = *s++) != '\0') { - putchar(c); - } - putchar('\n'); - return strlen(s); -} From e3ac8c449c6a2cbd6ec1fc1bee5beb04e8c2053d Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 30 Mar 2018 15:35:30 +0100 Subject: [PATCH 37/72] Adjust build system * Remove lib from CONTIKI_TARGET_DIRS since we no longer have anything in this dir * Build dbg.c (has been added) * Do not build sprintf.c (has been removed) * Add os/lib/dbg-io to MODULES --- arch/platform/jn516x/Makefile.jn516x | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index ecdcc2f58..a2e7dc571 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -82,7 +82,7 @@ OBJDUMP:=$(CROSS_COMPILE)-objdump ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \ slip_uart0.c clock.c micromac-radio.c int-master.c \ - node-id.c watchdog.c slip.c sprintf.c + node-id.c watchdog.c slip.c dbg.c # Default uart0 for printf and slip TARGET_WITH_UART0 ?= 1 TARGET_WITH_UART1 ?= 0 @@ -100,9 +100,11 @@ ifeq ($(WITH_UART),1) ARCH += uart-driver.c endif -CONTIKI_TARGET_DIRS = . dev lib +CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_MAIN = platform.c +MODULES += os/lib/dbg-io + ifeq ($(JN516x_WITH_DR1175),1) JN516x_WITH_DR1174 = 1 CFLAGS += -DSENSOR_BOARD_DR1175 From 0683d4dc3d6972f0aa80cec538ffe516d629b291 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 17 Nov 2017 16:10:45 +0100 Subject: [PATCH 38/72] Imported SPI API from Yanzi Networks internal Contiki fork. --- arch/cpu/cc2538/Makefile.cc2538 | 3 +- arch/cpu/cc2538/spi-dev-arch.c | 185 ++++++++++++++++++++++++++++ arch/cpu/cc2538/spi-dev-arch.h | 44 +++++++ os/dev/spi-dev.c | 207 ++++++++++++++++++++++++++++++++ os/dev/spi-dev.h | 104 ++++++++++++++++ 5 files changed, 542 insertions(+), 1 deletion(-) create mode 100644 arch/cpu/cc2538/spi-dev-arch.c create mode 100644 arch/cpu/cc2538/spi-dev-arch.h create mode 100644 os/dev/spi-dev.c create mode 100644 os/dev/spi-dev.h diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index 03758aa9b..eb6d8a6b8 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -15,7 +15,8 @@ CONTIKI_CPU_DIRS = . dev usb usb/common usb/common/cdc-acm ### CPU-dependent source files CONTIKI_CPU_SOURCEFILES += soc.c clock.c rtimer-arch.c uart.c watchdog.c -CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi.c adc.c +CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c adc.c +CONTIKI_CPU_SOURCEFILES += spi.c spi-dev-arch.c CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c gpio-hal-arch.c CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c diff --git a/arch/cpu/cc2538/spi-dev-arch.c b/arch/cpu/cc2538/spi-dev-arch.c new file mode 100644 index 000000000..b20e5da5f --- /dev/null +++ b/arch/cpu/cc2538/spi-dev-arch.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2016-2017, Yanzi Networks. + * 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 HOLDER 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 +#include "dev/spi-dev.h" +#include "spi-arch.h" + +#define DEBUG 0 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +#ifdef PLATFORM_HAS_SPI_DEV_ARCH +/*---------------------------------------------------------------------------*/ +static void +spix_wait_tx_ready(int spi_instance) +{ + int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; + + /* Infinite loop until SR_TNF - Transmit FIFO Not Full */ + while(!(REG(reg + SSI_SR) & SSI_SR_TNF)); +} +/*---------------------------------------------------------------------------*/ +static int +spix_read_buf(int spi_instance) +{ + int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; + + return REG(reg + SSI_DR); +} +/*---------------------------------------------------------------------------*/ +static void +spix_write_buf(int spi_instance, int data) +{ + int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; + + REG(reg + SSI_DR) = data; +} +/*---------------------------------------------------------------------------*/ +static void +spix_wait_eotx(int spi_instance) +{ + int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; + + /* wait until not busy */ + while(REG(reg + SSI_SR) & SSI_SR_BSY); +} +/*---------------------------------------------------------------------------*/ +static void +spix_wait_eorx(int spi_instance) +{ + int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; + + /* wait as long as receive is empty */ + while(!(REG(reg + SSI_SR) & SSI_SR_RNE)); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_arch_lock(spi_device_t *dev) +{ + spi_bus_t *bus; + bus = dev->bus; + + if(bus->lock) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + /* Add support for timeout also!!! */ + bus->lock = 1; + bus->lock_device = dev; + + PRINTF("SPI: lock\n"); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +int +spi_dev_arch_has_lock(spi_device_t *dev) +{ + return dev->bus->lock_device == dev; +} +/*---------------------------------------------------------------------------*/ +int +spi_dev_arch_is_bus_locked(spi_device_t *dev) +{ + return dev->bus->lock; +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_arch_unlock(spi_device_t *dev) +{ + dev->bus->lock = 0; + dev->bus->lock_device = NULL; + + PRINTF("SPI: unlock\n"); + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_arch_restart_timeout(spi_device_t *dev) +{ + /* do nothing at the moment */ + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +/* Assumes that checking dev and bus is not NULL before calling this */ +spi_dev_status_t +spi_dev_arch_transfer(spi_device_t *dev, + const uint8_t *write_buf, int wlen, + uint8_t *inbuf, int rlen, int ignore_len) +{ + int i; + int totlen; + uint8_t c; + uint8_t spi_instance; + + spi_instance = dev->bus->config.instance; + + PRINTF("SPI: transfer (r:%d,w:%d) ", rlen, wlen); + + if(write_buf == NULL && wlen > 0) { + return SPI_DEV_STATUS_EINVAL; + } + if(inbuf == NULL && rlen > 0) { + return SPI_DEV_STATUS_EINVAL; + } + + totlen = MAX(rlen + ignore_len, wlen); + + if(totlen == 0) { + /* Nothing to do */ + return SPI_DEV_STATUS_OK; + } + + PRINTF("%c%c%c: %u ", rlen > 0 ? 'R' : '-', wlen > 0 ? 'W' : '-', + ignore_len > 0 ? 'S' : '-', totlen); + + for(i = 0; i < totlen; i++) { + spix_wait_tx_ready(spi_instance); + c = i < wlen ? write_buf[i] : 0; + spix_write_buf(spi_instance, c); + PRINTF("%c%02x->", i < rlen ? ' ' : '#', c); + spix_wait_eotx(spi_instance); + spix_wait_eorx(spi_instance); + c = spix_read_buf(spi_instance); + if(i < rlen) { + inbuf[i] = c; + } + PRINTF("%02x", c); + } + + PRINTF("\n"); + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +#endif /* PLATFORM_HAS_SPI_DEV_ARCH */ diff --git a/arch/cpu/cc2538/spi-dev-arch.h b/arch/cpu/cc2538/spi-dev-arch.h new file mode 100644 index 000000000..88ca67f24 --- /dev/null +++ b/arch/cpu/cc2538/spi-dev-arch.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016-2017, Yanzi Networks. + * 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 HOLDER 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 SPI_DEV_ARCH_H_ +#define SPI_DEV_ARCH_H_ + +#include + +/* The SPI instance for the CC2538 */ +typedef struct spi_bus_config { + uint8_t instance; +} spi_bus_config_t; + +typedef struct spi_device_config { +} spi_device_config_t; + +#endif /* SPI_DEV_ARCH_H_ */ diff --git a/os/dev/spi-dev.c b/os/dev/spi-dev.c new file mode 100644 index 000000000..be4418fcd --- /dev/null +++ b/os/dev/spi-dev.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2016-2017, Yanzi Networks. + * 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 HOLDER 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 "dev/spi-dev.h" + +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_acquire(spi_device_t *dev) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + /* lock the bus */ + return spi_dev_arch_lock(dev); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_release(spi_device_t *dev) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + /* unlock the bus */ + return spi_dev_arch_unlock(dev); +} +/*---------------------------------------------------------------------------*/ +int +spi_dev_has_bus(spi_device_t *dev) +{ + if(dev == NULL || dev->bus == NULL) { + return 0; + } + return spi_dev_arch_has_lock(dev); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_restart_timeout(spi_device_t *dev) +{ + if(!spi_dev_has_bus(dev)) { + return SPI_DEV_STATUS_EINVAL; + } + return spi_dev_arch_restart_timeout(dev); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_write_byte(spi_device_t *dev, uint8_t data) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + return spi_dev_arch_transfer(dev, &data, 1, 0, 0, 0); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_write(spi_device_t *dev, const uint8_t *data, int size) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + return spi_dev_arch_transfer(dev, data, size, 0, 0, 0); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_read_byte(spi_device_t *dev, uint8_t *buf) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + return spi_dev_arch_transfer(dev, NULL, 0, buf, 1, 0); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_read(spi_device_t *dev, uint8_t *buf, int size) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + return spi_dev_arch_transfer(dev, NULL, 0, buf, size, 0); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_read_skip(spi_device_t *dev, int size) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + return spi_dev_arch_transfer(dev, NULL, 0, NULL, 0, size); +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_transfer(spi_device_t *dev, + const uint8_t *wdata, int wsize, + uint8_t *rbuf, int rsize, int ignore) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + + if(wdata == NULL && wsize > 0) { + return SPI_DEV_STATUS_EINVAL; + } + + if(rbuf == NULL && rsize > 0) { + return SPI_DEV_STATUS_EINVAL; + } + + return spi_dev_arch_transfer(dev, wdata, wsize, rbuf, rsize, ignore); +} +/*---------------------------------------------------------------------------*/ +/* Chip select can only be done when the bus is locked to this device */ +spi_dev_status_t +spi_dev_chip_select(spi_device_t *dev, uint8_t on) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + if(spi_dev_has_bus(dev)) { + return dev->chip_select(on); + } + return SPI_DEV_STATUS_BUS_NOT_OWNED; +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) +{ + spi_dev_status_t status; + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + /* write the register first (will read a status) */ + status = spi_dev_write_byte(dev, reg); + if(status != SPI_DEV_STATUS_OK) { + return status; + } + /* then read the value (will read the value) */ + status = spi_dev_read(dev, data, size); + if(status != SPI_DEV_STATUS_OK) { + return status; + } + return status; +} +/*---------------------------------------------------------------------------*/ +spi_dev_status_t +spi_dev_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) +{ + if(dev == NULL || dev->bus == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_dev_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + return spi_dev_arch_transfer(dev, &strobe, 1, result, 1, 0); +} +/*---------------------------------------------------------------------------*/ diff --git a/os/dev/spi-dev.h b/os/dev/spi-dev.h new file mode 100644 index 000000000..48068261f --- /dev/null +++ b/os/dev/spi-dev.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016-2017, Yanzi Networks. + * 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 HOLDER 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 SPI_DEV_H_ +#define SPI_DEV_H_ + +#include "contiki.h" + +#ifdef PLATFORM_HAS_SPI_DEV_ARCH +#include "spi-dev-arch.h" +#endif + +typedef enum { + SPI_DEV_STATUS_OK, + SPI_DEV_STATUS_TIMEOUT, + SPI_DEV_STATUS_EINVAL, + SPI_DEV_STATUS_BUS_LOCKED, + SPI_DEV_STATUS_BUS_NOT_OWNED +} spi_dev_status_t; + +typedef struct spi_device spi_device_t; + +typedef struct spi_bus { + /* for locking the bus */ + spi_device_t *lock_device; + volatile uint8_t lock; +#ifdef PLATFORM_HAS_SPI_DEV_ARCH + spi_bus_config_t config; +#endif /* PLATFORM_HAS_SPI_DEV_ARCH */ +} spi_bus_t; + +struct spi_device { + spi_bus_t *bus; + /* timeout in milliseconds for this device */ + uint16_t timeout; + /* chip-select for this SPI chip - 1 = CS */ + uint8_t (* chip_select)(int on); +#ifdef PLATFORM_HAS_SPI_DEV_ARCH + spi_device_config_t config; +#endif +}; + +/* call for all spi devices */ +spi_dev_status_t spi_dev_acquire(spi_device_t *dev); +spi_dev_status_t spi_dev_release(spi_device_t *dev); +spi_dev_status_t spi_dev_restart_timeout(spi_device_t *dev); +int spi_dev_has_bus(spi_device_t *dev); +spi_dev_status_t spi_dev_write_byte(spi_device_t *dev, uint8_t data); +spi_dev_status_t spi_dev_read_byte(spi_device_t *dev, uint8_t *data); +spi_dev_status_t spi_dev_write(spi_device_t *dev, + const uint8_t *data, int size); +spi_dev_status_t spi_dev_read(spi_device_t *dev, uint8_t *data, int size); +spi_dev_status_t spi_dev_read_skip(spi_device_t *dev, int size); +spi_dev_status_t spi_dev_transfer(spi_device_t *dev, + const uint8_t *data, int wsize, + uint8_t *buf, int rsize, int ignore); +spi_dev_status_t spi_dev_chip_select(spi_device_t *dev, uint8_t on); +spi_dev_status_t spi_dev_strobe(spi_device_t *dev, uint8_t strobe, + uint8_t *status); +spi_dev_status_t spi_dev_read_register(spi_device_t *dev, uint8_t reg, + uint8_t *data, int size); + +/* Arch functions needed per CPU */ +spi_dev_status_t spi_dev_arch_lock(spi_device_t *dev); +spi_dev_status_t spi_dev_arch_unlock(spi_device_t *dev); +int spi_dev_arch_has_lock(spi_device_t *dev); +int spi_dev_arch_is_bus_locked(spi_device_t *dev); + +/* Initialize the spi bus */ +spi_dev_status_t spi_dev_arch_init(spi_device_t *dev); +spi_dev_status_t spi_dev_arch_transfer(spi_device_t *dev, + const uint8_t *data, int wlen, + uint8_t *buf, int rlen, + int ignore_len); +spi_dev_status_t spi_dev_arch_restart_timeout(spi_device_t *dev); + +#endif /* SPI_DEV_H */ From 1bb04f2d20433e3846e0ddb710622c55ee7df411 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Mon, 18 Dec 2017 16:33:13 +0000 Subject: [PATCH 39/72] revert cc2538 --- arch/cpu/cc2538/Makefile.cc2538 | 3 +- arch/cpu/cc2538/spi-dev-arch.c | 185 -------------------------------- arch/cpu/cc2538/spi-dev-arch.h | 44 -------- 3 files changed, 1 insertion(+), 231 deletions(-) delete mode 100644 arch/cpu/cc2538/spi-dev-arch.c delete mode 100644 arch/cpu/cc2538/spi-dev-arch.h diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index eb6d8a6b8..03758aa9b 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -15,8 +15,7 @@ CONTIKI_CPU_DIRS = . dev usb usb/common usb/common/cdc-acm ### CPU-dependent source files CONTIKI_CPU_SOURCEFILES += soc.c clock.c rtimer-arch.c uart.c watchdog.c -CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c adc.c -CONTIKI_CPU_SOURCEFILES += spi.c spi-dev-arch.c +CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi.c adc.c CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c gpio-hal-arch.c CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c diff --git a/arch/cpu/cc2538/spi-dev-arch.c b/arch/cpu/cc2538/spi-dev-arch.c deleted file mode 100644 index b20e5da5f..000000000 --- a/arch/cpu/cc2538/spi-dev-arch.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2016-2017, Yanzi Networks. - * 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 HOLDER 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 -#include "dev/spi-dev.h" -#include "spi-arch.h" - -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif - -#ifdef PLATFORM_HAS_SPI_DEV_ARCH -/*---------------------------------------------------------------------------*/ -static void -spix_wait_tx_ready(int spi_instance) -{ - int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; - - /* Infinite loop until SR_TNF - Transmit FIFO Not Full */ - while(!(REG(reg + SSI_SR) & SSI_SR_TNF)); -} -/*---------------------------------------------------------------------------*/ -static int -spix_read_buf(int spi_instance) -{ - int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; - - return REG(reg + SSI_DR); -} -/*---------------------------------------------------------------------------*/ -static void -spix_write_buf(int spi_instance, int data) -{ - int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; - - REG(reg + SSI_DR) = data; -} -/*---------------------------------------------------------------------------*/ -static void -spix_wait_eotx(int spi_instance) -{ - int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; - - /* wait until not busy */ - while(REG(reg + SSI_SR) & SSI_SR_BSY); -} -/*---------------------------------------------------------------------------*/ -static void -spix_wait_eorx(int spi_instance) -{ - int reg = spi_instance == 0 ? SSI0_BASE : SSI1_BASE; - - /* wait as long as receive is empty */ - while(!(REG(reg + SSI_SR) & SSI_SR_RNE)); -} -/*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_arch_lock(spi_device_t *dev) -{ - spi_bus_t *bus; - bus = dev->bus; - - if(bus->lock) { - return SPI_DEV_STATUS_BUS_LOCKED; - } - /* Add support for timeout also!!! */ - bus->lock = 1; - bus->lock_device = dev; - - PRINTF("SPI: lock\n"); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -int -spi_dev_arch_has_lock(spi_device_t *dev) -{ - return dev->bus->lock_device == dev; -} -/*---------------------------------------------------------------------------*/ -int -spi_dev_arch_is_bus_locked(spi_device_t *dev) -{ - return dev->bus->lock; -} -/*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_arch_unlock(spi_device_t *dev) -{ - dev->bus->lock = 0; - dev->bus->lock_device = NULL; - - PRINTF("SPI: unlock\n"); - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_arch_restart_timeout(spi_device_t *dev) -{ - /* do nothing at the moment */ - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -/* Assumes that checking dev and bus is not NULL before calling this */ -spi_dev_status_t -spi_dev_arch_transfer(spi_device_t *dev, - const uint8_t *write_buf, int wlen, - uint8_t *inbuf, int rlen, int ignore_len) -{ - int i; - int totlen; - uint8_t c; - uint8_t spi_instance; - - spi_instance = dev->bus->config.instance; - - PRINTF("SPI: transfer (r:%d,w:%d) ", rlen, wlen); - - if(write_buf == NULL && wlen > 0) { - return SPI_DEV_STATUS_EINVAL; - } - if(inbuf == NULL && rlen > 0) { - return SPI_DEV_STATUS_EINVAL; - } - - totlen = MAX(rlen + ignore_len, wlen); - - if(totlen == 0) { - /* Nothing to do */ - return SPI_DEV_STATUS_OK; - } - - PRINTF("%c%c%c: %u ", rlen > 0 ? 'R' : '-', wlen > 0 ? 'W' : '-', - ignore_len > 0 ? 'S' : '-', totlen); - - for(i = 0; i < totlen; i++) { - spix_wait_tx_ready(spi_instance); - c = i < wlen ? write_buf[i] : 0; - spix_write_buf(spi_instance, c); - PRINTF("%c%02x->", i < rlen ? ' ' : '#', c); - spix_wait_eotx(spi_instance); - spix_wait_eorx(spi_instance); - c = spix_read_buf(spi_instance); - if(i < rlen) { - inbuf[i] = c; - } - PRINTF("%02x", c); - } - - PRINTF("\n"); - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -#endif /* PLATFORM_HAS_SPI_DEV_ARCH */ diff --git a/arch/cpu/cc2538/spi-dev-arch.h b/arch/cpu/cc2538/spi-dev-arch.h deleted file mode 100644 index 88ca67f24..000000000 --- a/arch/cpu/cc2538/spi-dev-arch.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016-2017, Yanzi Networks. - * 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 HOLDER 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 SPI_DEV_ARCH_H_ -#define SPI_DEV_ARCH_H_ - -#include - -/* The SPI instance for the CC2538 */ -typedef struct spi_bus_config { - uint8_t instance; -} spi_bus_config_t; - -typedef struct spi_device_config { -} spi_device_config_t; - -#endif /* SPI_DEV_ARCH_H_ */ From 91882209bf5ed50e853e6b5b065a7f8889a55c67 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Tue, 28 Nov 2017 19:03:47 +0000 Subject: [PATCH 40/72] HAL SPI API Proposal Documenting the SPI HAL API --- os/dev/spi-dev.h | 104 ---------- os/dev/{spi-dev.c => spi-hal.c} | 174 +++++++++------- os/dev/spi-hal.h | 349 ++++++++++++++++++++++++++++++++ 3 files changed, 445 insertions(+), 182 deletions(-) delete mode 100644 os/dev/spi-dev.h rename os/dev/{spi-dev.c => spi-hal.c} (58%) create mode 100644 os/dev/spi-hal.h diff --git a/os/dev/spi-dev.h b/os/dev/spi-dev.h deleted file mode 100644 index 48068261f..000000000 --- a/os/dev/spi-dev.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2016-2017, Yanzi Networks. - * 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 HOLDER 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 SPI_DEV_H_ -#define SPI_DEV_H_ - -#include "contiki.h" - -#ifdef PLATFORM_HAS_SPI_DEV_ARCH -#include "spi-dev-arch.h" -#endif - -typedef enum { - SPI_DEV_STATUS_OK, - SPI_DEV_STATUS_TIMEOUT, - SPI_DEV_STATUS_EINVAL, - SPI_DEV_STATUS_BUS_LOCKED, - SPI_DEV_STATUS_BUS_NOT_OWNED -} spi_dev_status_t; - -typedef struct spi_device spi_device_t; - -typedef struct spi_bus { - /* for locking the bus */ - spi_device_t *lock_device; - volatile uint8_t lock; -#ifdef PLATFORM_HAS_SPI_DEV_ARCH - spi_bus_config_t config; -#endif /* PLATFORM_HAS_SPI_DEV_ARCH */ -} spi_bus_t; - -struct spi_device { - spi_bus_t *bus; - /* timeout in milliseconds for this device */ - uint16_t timeout; - /* chip-select for this SPI chip - 1 = CS */ - uint8_t (* chip_select)(int on); -#ifdef PLATFORM_HAS_SPI_DEV_ARCH - spi_device_config_t config; -#endif -}; - -/* call for all spi devices */ -spi_dev_status_t spi_dev_acquire(spi_device_t *dev); -spi_dev_status_t spi_dev_release(spi_device_t *dev); -spi_dev_status_t spi_dev_restart_timeout(spi_device_t *dev); -int spi_dev_has_bus(spi_device_t *dev); -spi_dev_status_t spi_dev_write_byte(spi_device_t *dev, uint8_t data); -spi_dev_status_t spi_dev_read_byte(spi_device_t *dev, uint8_t *data); -spi_dev_status_t spi_dev_write(spi_device_t *dev, - const uint8_t *data, int size); -spi_dev_status_t spi_dev_read(spi_device_t *dev, uint8_t *data, int size); -spi_dev_status_t spi_dev_read_skip(spi_device_t *dev, int size); -spi_dev_status_t spi_dev_transfer(spi_device_t *dev, - const uint8_t *data, int wsize, - uint8_t *buf, int rsize, int ignore); -spi_dev_status_t spi_dev_chip_select(spi_device_t *dev, uint8_t on); -spi_dev_status_t spi_dev_strobe(spi_device_t *dev, uint8_t strobe, - uint8_t *status); -spi_dev_status_t spi_dev_read_register(spi_device_t *dev, uint8_t reg, - uint8_t *data, int size); - -/* Arch functions needed per CPU */ -spi_dev_status_t spi_dev_arch_lock(spi_device_t *dev); -spi_dev_status_t spi_dev_arch_unlock(spi_device_t *dev); -int spi_dev_arch_has_lock(spi_device_t *dev); -int spi_dev_arch_is_bus_locked(spi_device_t *dev); - -/* Initialize the spi bus */ -spi_dev_status_t spi_dev_arch_init(spi_device_t *dev); -spi_dev_status_t spi_dev_arch_transfer(spi_device_t *dev, - const uint8_t *data, int wlen, - uint8_t *buf, int rlen, - int ignore_len); -spi_dev_status_t spi_dev_arch_restart_timeout(spi_device_t *dev); - -#endif /* SPI_DEV_H */ diff --git a/os/dev/spi-dev.c b/os/dev/spi-hal.c similarity index 58% rename from os/dev/spi-dev.c rename to os/dev/spi-hal.c index be4418fcd..c8c84bd7c 100644 --- a/os/dev/spi-dev.c +++ b/os/dev/spi-hal.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2016-2017, Yanzi Networks. + * Copyright (c) 2017, University of Bristol - http://www.bristol.ac.uk/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,122 +29,149 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "dev/spi-dev.h" +#include "spi-hal.h" /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_acquire(spi_device_t *dev) +spi_status_t +spi_acquire(spi_device_t *dev) { - if(dev == NULL || dev->bus == NULL) { + spi_status_t r; + + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } + /* lock the bus */ - return spi_dev_arch_lock(dev); + r = spi_arch_lock(dev); + if(r != SPI_DEV_STATUS_OK) { + return r; + } + + /* open the bus */ + return spi_arch_open(dev); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_release(spi_device_t *dev) +spi_status_t +spi_release(spi_device_t *dev) { - if(dev == NULL || dev->bus == NULL) { + spi_status_t r; + + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } + /* unlock the bus */ - return spi_dev_arch_unlock(dev); -} -/*---------------------------------------------------------------------------*/ -int -spi_dev_has_bus(spi_device_t *dev) -{ - if(dev == NULL || dev->bus == NULL) { - return 0; + r = spi_arch_close(dev); + if(r != SPI_DEV_STATUS_OK) { + return r; } - return spi_dev_arch_has_lock(dev); + + /* unlock the bus */ + return spi_arch_unlock(dev); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_restart_timeout(spi_device_t *dev) +spi_status_t +spi_select(spi_device_t *dev) { - if(!spi_dev_has_bus(dev)) { - return SPI_DEV_STATUS_EINVAL; + return spi_arch_select(dev); +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_deselect(spi_device_t *dev) +{ + return spi_arch_deselect(dev); +} +/*---------------------------------------------------------------------------*/ +bool +spi_has_bus(spi_device_t *dev) +{ + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + return false; } - return spi_dev_arch_restart_timeout(dev); + + return spi_arch_has_lock(dev); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_write_byte(spi_device_t *dev, uint8_t data) +spi_status_t +spi_write_byte(spi_device_t *dev, uint8_t data) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } - return spi_dev_arch_transfer(dev, &data, 1, 0, 0, 0); + + return spi_arch_transfer(dev, &data, 1, 0, 0, 0); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_write(spi_device_t *dev, const uint8_t *data, int size) +spi_status_t +spi_write(spi_device_t *dev, const uint8_t *data, int size) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } - return spi_dev_arch_transfer(dev, data, size, 0, 0, 0); + + return spi_arch_transfer(dev, data, size, 0, 0, 0); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_read_byte(spi_device_t *dev, uint8_t *buf) +spi_status_t +spi_read_byte(spi_device_t *dev, uint8_t *buf) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } - return spi_dev_arch_transfer(dev, NULL, 0, buf, 1, 0); + + return spi_arch_transfer(dev, NULL, 0, buf, 1, 0); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_read(spi_device_t *dev, uint8_t *buf, int size) +spi_status_t +spi_read(spi_device_t *dev, uint8_t *buf, int size) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } - return spi_dev_arch_transfer(dev, NULL, 0, buf, size, 0); + + return spi_arch_transfer(dev, NULL, 0, buf, size, 0); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_read_skip(spi_device_t *dev, int size) +spi_status_t +spi_read_skip(spi_device_t *dev, int size) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } - return spi_dev_arch_transfer(dev, NULL, 0, NULL, 0, size); + + return spi_arch_transfer(dev, NULL, 0, NULL, 0, size); } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_transfer(spi_device_t *dev, - const uint8_t *wdata, int wsize, - uint8_t *rbuf, int rsize, int ignore) +spi_status_t +spi_transfer(spi_device_t *dev, + const uint8_t *wdata, int wsize, + uint8_t *rbuf, int rsize, int ignore) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } @@ -155,53 +183,43 @@ spi_dev_transfer(spi_device_t *dev, return SPI_DEV_STATUS_EINVAL; } - return spi_dev_arch_transfer(dev, wdata, wsize, rbuf, rsize, ignore); + return spi_arch_transfer(dev, wdata, wsize, rbuf, rsize, ignore); } /*---------------------------------------------------------------------------*/ -/* Chip select can only be done when the bus is locked to this device */ -spi_dev_status_t -spi_dev_chip_select(spi_device_t *dev, uint8_t on) +spi_status_t +spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) { - if(dev == NULL || dev->bus == NULL) { - return SPI_DEV_STATUS_EINVAL; - } - if(spi_dev_has_bus(dev)) { - return dev->chip_select(on); - } - return SPI_DEV_STATUS_BUS_NOT_OWNED; -} -/*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) -{ - spi_dev_status_t status; - if(dev == NULL || dev->bus == NULL) { + spi_status_t status; + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } /* write the register first (will read a status) */ - status = spi_dev_write_byte(dev, reg); + status = spi_write_byte(dev, reg); if(status != SPI_DEV_STATUS_OK) { return status; } + /* then read the value (will read the value) */ - status = spi_dev_read(dev, data, size); + status = spi_read(dev, data, size); if(status != SPI_DEV_STATUS_OK) { return status; } + return status; } /*---------------------------------------------------------------------------*/ -spi_dev_status_t -spi_dev_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) +spi_status_t +spi_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) { - if(dev == NULL || dev->bus == NULL) { + if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { return SPI_DEV_STATUS_EINVAL; } - if(!spi_dev_arch_has_lock(dev)) { + if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_LOCKED; } - return spi_dev_arch_transfer(dev, &strobe, 1, result, 1, 0); + + return spi_arch_transfer(dev, &strobe, 1, result, 1, 0); } /*---------------------------------------------------------------------------*/ diff --git a/os/dev/spi-hal.h b/os/dev/spi-hal.h new file mode 100644 index 000000000..901da2a25 --- /dev/null +++ b/os/dev/spi-hal.h @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2016-2017, Yanzi Networks. + * Copyright (c) 2017, 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 HOLDER 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 spi-hal SPI Hardware Abstraction Layer + * + * The SPI HAL provides a set of common functions that can be used in a + * platform-independent fashion. + * + * + * @{ + * + * \file + * Header file for the SPI HAL + */ +/*---------------------------------------------------------------------------*/ +#ifndef SPI_HAL_H_ +#define SPI_HAL_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "gpio-hal.h" + +#include +#include +/*---------------------------------------------------------------------------*/ +/* Include Arch-Specific conf */ +#ifdef SPI_HAL_CONF_ARCH_HDR_PATH +#include SPI_HAL_CONF_ARCH_HDR_PATH +#else /* PLATFORM_IMPLEMENTS_SPI_HAL */ +#define BOARD_SPI_CONTROLLERS 0 +#endif /* SPI_HAL_CONF_ARCH_HDR_PATH */ +/*---------------------------------------------------------------------------*/ +/** + * \brief SPI return codes + * + * @{ + */ +typedef enum { + SPI_DEV_STATUS_OK, /* Everything OK */ + SPI_DEV_STATUS_EINVAL, /* Erroneous input value */ + SPI_DEV_STATUS_BUS_LOCKED, /* SPI bus is already locked */ + SPI_DEV_STATUS_BUS_NOT_OWNED, /* SPI bus is locked by someone else */ + SPI_DEV_STATUS_CLOSED /* SPI bus has not opened properly */ +} spi_status_t; +/*---------------------------------------------------------------------------*/ +/** + * \brief SPI Device Configuration + * + * This is a structure to an architecture-independent SPI configuration. + * + * @{ + */ + +typedef struct spi_device { + gpio_hal_pin_t pin_spi_sck; /* SPI SCK pin */ + gpio_hal_pin_t pin_spi_miso; /* SPI MISO pin */ + gpio_hal_pin_t pin_spi_mosi; /* SPI MOSI pin */ + gpio_hal_pin_t pin_spi_cs; /* SPI Chip Select pin */ + uint32_t spi_bit_rate; /* SPI bit rate */ + uint8_t spi_pha; /* SPI mode phase */ + uint8_t spi_pol; /* SPI mode polarity */ + uint8_t spi_controller; /* ID of SPI controller to use */ +} spi_device_t; + +/*---------------------------------------------------------------------------*/ +/* These are architecture-independent functions to be used by SPI devices. */ +/*---------------------------------------------------------------------------*/ +/** + * \brief Locks and then opens an SPI controller + * \param dev An SPI device configuration which defines the controller + * to be locked and the opening configuration. + * \return SPI return code + */ +spi_status_t spi_acquire(spi_device_t *dev); + +/** + * \brief Closes and then unlocks an SPI controller + * \param dev An SPI device configuration which defines the controller + * to be closed and unlocked. + * \return SPI return code + * + * Releasing an SPI controller should put it in low-power mode. + * This should work only if the device has already locked the SPI + * controller. + */ +spi_status_t spi_release(spi_device_t *dev); + +/** + * \brief Selects the SPI peripheral + * \param dev An SPI device configuration which defines the CS pin. + * \return SPI return code + * + * Clears the CS pin. This should work only if the device has + * already locked the SPI controller. + */ +spi_status_t spi_select(spi_device_t *dev); + +/** + * \brief Deselects the SPI peripheral + * \param dev An SPI device configuration which defines the CS pin. + * \return SPI return code + * + * Sets the CS pin. Lock is not required. + */ +spi_status_t spi_deselect(spi_device_t *dev); + +/** + * \brief Checks if a device has locked an SPI controller + * \param dev An SPI device configuration which defines the controller. + * \return true if the device has the lock, false otherwise. + */ +bool spi_has_bus(spi_device_t *dev); + +/** + * \brief Writes a single byte to an SPI device + * \param dev An SPI device configuration. + * \param data A byte of data + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_write_byte(spi_device_t *dev, uint8_t data); + +/** + * \brief Reads a single byte from an SPI device + * \param dev An SPI device configuration. + * \param data A pointer to a byte of data + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_read_byte(spi_device_t *dev, uint8_t *data); + +/** + * \brief Writes a buffer to an SPI device + * \param dev An SPI device configuration. + * \param data A pointer to the data + * \param size Size of the data to write + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_write(spi_device_t *dev, + const uint8_t *data, int size); + +/** + * \brief Reads a buffer from an SPI device + * \param dev An SPI device configuration. + * \param data A pointer to the data + * \param size Size of the data to read + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_read(spi_device_t *dev, uint8_t *data, int size); + +/** + * \brief Reads and ignores data from an SPI device + * \param dev An SPI device configuration. + * \param size Size of the data to read and ignore + * \return SPI return code + * + * Reads size bytes from the SPI and throws them away. + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_read_skip(spi_device_t *dev, int size); + +/** + * \brief Performs a generic SPI transfer + * \param dev An SPI device configuration. + * \param data A pointer to the data to be written. Set it to NULL to + * skip writing. + * \param wlen Size of data to write. + * \param buf A pointer to buffer to copy the data read. Set to NULL + * to skip reading. + * \param rlen Size of data to read. + * \param ignore_len Size of data to read and ignore. + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + * A total of rlen+ignore_len bytes will be read. The first rlen bytes will + * be copied to buf. The remaining ignore_len bytes won't be copied to the + * buffer. The maximum of wlen and rlen+ignore_len of bytes will be transfered. + */ +spi_status_t spi_transfer(spi_device_t *dev, + const uint8_t *data, int wsize, + uint8_t *buf, int rsize, int ignore); + +/** + * \brief Reads and Writes one byte from/to an SPI device + * \param dev An SPI device configuration. + * \param strobe Byte to write + * \param status Pointer to byte to read + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_strobe(spi_device_t *dev, uint8_t strobe, + uint8_t *status); + +/** + * \brief Reads a buffer of bytes from a register of an SPI device + * \param dev An SPI device configuration. + * \param reg Register + * \param data A pointer to the data + * \param size Size of the data to read + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + */ +spi_status_t spi_read_register(spi_device_t *dev, uint8_t reg, + uint8_t *data, int size); + +/*---------------------------------------------------------------------------*/ +/* These are architecture-specific functions to be implemented by each CPU. */ +/*---------------------------------------------------------------------------*/ + +/** + * \brief Locks an SPI controller to device dev. + * \param dev An SPI device configuration which defines the controller + * to be locked and the device that locks it. + * \return SPI return code + * + */ +spi_status_t spi_arch_lock(spi_device_t *dev); + +/** + * \brief Unlocks an SPI controller. + * \param dev An SPI device configuration which defines the controller + * to be unlocked and the device that unlocks it. + * \return SPI return code + * + */ +spi_status_t spi_arch_unlock(spi_device_t *dev); + +/** + * \brief Checks if a device has locked an SPI controller + * \param dev An SPI device configuration which defines the controller + * to be checked if it is locked and the respective device. + * \return 1 if the device has the lock, 0 otherwise. + * + */ +bool spi_arch_has_lock(spi_device_t *dev); + +/** + * \brief Checks if an SPI controller is locked by any device + * \param dev An SPI device configuration which defines the controller + * to be checked. + * \return 1 if the controller is locked, 0 otherwise. + * + */ +bool spi_arch_is_bus_locked(spi_device_t *dev); + +/** + * \brief Opens an SPI controller to the configuration specified. + * \param dev An SPI device configuration. + * \return SPI return code + * + * This should work only if the device has already locked the SPI + * controller. + * + */ +spi_status_t spi_arch_open(spi_device_t *dev); + +/** + * \brief Closes an SPI controller + * \param dev An SPI device configuration that specifies the controller. + * \return SPI return code + * + * This should turn off the SPI controller to put it in low power mode. + * It should work only if the device has already locked the SPI + * controller. + * + */ +spi_status_t spi_arch_close(spi_device_t *dev); + +/** + * \brief Performs an SPI transfer + * \param dev An SPI device configuration that specifies the controller. + * \param data A pointer to the data to be written. Set it to NULL to + * skip writing. + * \param wlen Length of data to write. + * \param buf A pointer to buffer to copy the data read. Set to NULL + * to skip reading. + * \param rlen Length of data to read. + * \param ignore_len Length of data to read and ignore. + * \return SPI return code + * + * It should work only if the device has already locked the SPI controller. + * A total of rlen+ignore_len bytes will be read. The first rlen bytes will + * be copied to buf. The remaining ignore_len bytes won't be copied to the + * buffer. The maximum of wlen and rlen+ignore_len of bytes will be transfered. + */ +spi_status_t spi_arch_transfer(spi_device_t *dev, + const uint8_t *data, int wlen, + uint8_t *buf, int rlen, + int ignore_len); + +/** + * \brief Selects an SPI device + * \param dev An SPI device configuration that specifies the CS pin. + * \return SPI return code + * + * Clears the CS pin. It should work only if the device has already + * locked the SPI controller. + */ +spi_status_t spi_arch_select(spi_device_t *dev); + +/** + * \brief Deselects an SPI device + * \param dev An SPI device configuration that specifies the CS pin. + * \return SPI return code + * + * Set the CS pin. Locking the SPI controller is not needed. + */ +spi_status_t spi_arch_deselect(spi_device_t *dev); + +#endif /* SPI_HAL_H_ */ From cf291c22f01fca1cea23abefeb2f74b640e21e9c Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 28 Feb 2018 10:41:05 +0000 Subject: [PATCH 41/72] Minor changes in the GPIO HAL --- arch/cpu/cc2538/dev/gpio-hal-arch.h | 1 + os/dev/gpio-hal.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/arch/cpu/cc2538/dev/gpio-hal-arch.h b/arch/cpu/cc2538/dev/gpio-hal-arch.h index 0b282c738..25abb3eb4 100644 --- a/arch/cpu/cc2538/dev/gpio-hal-arch.h +++ b/arch/cpu/cc2538/dev/gpio-hal-arch.h @@ -53,6 +53,7 @@ #include /*---------------------------------------------------------------------------*/ #define PIN_TO_PORT(pin) (pin >> 3) +#define PIN_TO_NUM(pin) (pin % 8) #define PIN_TO_PORT_BASE(pin) GPIO_PORT_TO_BASE(PIN_TO_PORT(pin)) /*---------------------------------------------------------------------------*/ #define gpio_hal_arch_interrupt_enable(p) do { \ diff --git a/os/dev/gpio-hal.h b/os/dev/gpio-hal.h index aacbfb1f1..b6af7bf74 100644 --- a/os/dev/gpio-hal.h +++ b/os/dev/gpio-hal.h @@ -130,6 +130,13 @@ typedef struct gpio_hal_event_handler_s { gpio_hal_pin_mask_t pin_mask; } gpio_hal_event_handler_t; /*---------------------------------------------------------------------------*/ +/** + * \brief Unknown GPIO + * + * A default GPIO value for unknown GPIO + */ +#define GPIO_HAL_PIN_UNKNOWN 0xFF +/*---------------------------------------------------------------------------*/ /** * \name Core GPIO functions * From e7d7ee396267a6a827d25a3e2aa2112c929a9668 Mon Sep 17 00:00:00 2001 From: "xenofon (Fontas) Fafoutis" Date: Mon, 20 Nov 2017 17:02:37 +0000 Subject: [PATCH 42/72] generic spi driver for cc26xx-cc13xx launchpad and ext-flash implementation --- arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 1 + arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c | 248 ++++++++++++++++++ arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h | 51 ++++ arch/platform/srf06-cc26xx/common/board-spi.c | 163 ------------ arch/platform/srf06-cc26xx/common/board-spi.h | 114 -------- arch/platform/srf06-cc26xx/contiki-conf.h | 3 + .../srf06-cc26xx/launchpad/Makefile.launchpad | 1 - arch/platform/srf06-cc26xx/launchpad/board.c | 2 +- .../srf06-cc26xx/launchpad/cc1310/board.h | 30 ++- .../srf06-cc26xx/launchpad/cc1350/board.h | 31 ++- .../srf06-cc26xx/launchpad/cc2650/board.h | 30 ++- .../common => os/dev}/ext-flash.c | 238 ++++++++++------- .../common => os/dev}/ext-flash.h | 12 +- 13 files changed, 510 insertions(+), 414 deletions(-) create mode 100644 arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c create mode 100644 arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h delete mode 100644 arch/platform/srf06-cc26xx/common/board-spi.c delete mode 100644 arch/platform/srf06-cc26xx/common/board-spi.h rename {arch/platform/srf06-cc26xx/common => os/dev}/ext-flash.c (66%) rename {arch/platform/srf06-cc26xx/common => os/dev}/ext-flash.h (92%) diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index 75dbad7ad..aacc98b62 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -36,6 +36,7 @@ CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c gpio-hal-arch.c oscillators.c CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c +CONTIKI_CPU_SOURCEFILES += spi-hal-arch.c MODULES += os/lib/dbg-io diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c new file mode 100644 index 000000000..c67c0d484 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2017, 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 HOLDER 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 "ti-lib.h" +#include "spi-hal.h" +#include "spi-hal-arch.h" +#include "sys/mutex.h" + +#include +#include + +typedef struct spi_locks_s { + mutex_t lock; + spi_device_t *owner; +} spi_locks_t; + +/* One lock per SPI controller */ +spi_locks_t board_spi_locks_spi[BOARD_SPI_CONTROLLERS] = { { MUTEX_STATUS_UNLOCKED, NULL } }; + +/* Arch-specific properties of each SPI controller */ +static const board_spi_controller_t spi_controller[BOARD_SPI_CONTROLLERS] = { + { + .ssi_base = SSI0_BASE, + .power_domain = PRCM_DOMAIN_SERIAL, + .prcm_periph = PRCM_PERIPH_SSI0, + .ssi_clkgr_clk_en = PRCM_SSICLKGR_CLK_EN_SSI0 + }, + { + .ssi_base = SSI1_BASE, + .power_domain = PRCM_DOMAIN_PERIPH, + .prcm_periph = PRCM_PERIPH_SSI1, + .ssi_clkgr_clk_en = PRCM_SSICLKGR_CLK_EN_SSI1 + } +}; +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_lock(spi_device_t *dev) +{ + if(mutex_try_lock(&board_spi_locks_spi[dev->spi_controller].lock) == false) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + + board_spi_locks_spi[dev->spi_controller].owner = dev; + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +bool +spi_arch_has_lock(spi_device_t *dev) +{ + if(board_spi_locks_spi[dev->spi_controller].owner == dev) { + return true; + } + + return false; +} +/*---------------------------------------------------------------------------*/ +bool +spi_arch_is_bus_locked(spi_device_t *dev) +{ + if(board_spi_locks_spi[dev->spi_controller].lock == MUTEX_STATUS_LOCKED) { + return true; + } + + return false; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_unlock(spi_device_t *dev) +{ + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + board_spi_locks_spi[dev->spi_controller].owner = NULL; + mutex_unlock(&board_spi_locks_spi[dev->spi_controller].lock); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +static uint32_t +get_mode(spi_device_t *dev) +{ + /* Select the correct SPI mode */ + if(dev->spi_pha == 0 && dev->spi_pol == 0) { + return SSI_FRF_MOTO_MODE_0; + } else if(dev->spi_pha != 0 && dev->spi_pol == 0) { + return SSI_FRF_MOTO_MODE_1; + } else if(dev->spi_pha == 0 && dev->spi_pol != 0) { + return SSI_FRF_MOTO_MODE_2; + } else { + return SSI_FRF_MOTO_MODE_3; + } +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_open(spi_device_t *dev) +{ + uint32_t c; + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + /* CS pin configuration */ + ti_lib_ioc_pin_type_gpio_output(dev->pin_spi_cs); + + /* First, make sure the SERIAL PD is on */ + ti_lib_prcm_power_domain_on(spi_controller[dev->spi_controller].power_domain); + while((ti_lib_prcm_power_domain_status(spi_controller[dev->spi_controller].power_domain) + != PRCM_DOMAIN_POWER_ON)) ; + + /* Enable clock in active mode */ + ti_lib_rom_prcm_peripheral_run_enable(spi_controller[dev->spi_controller].prcm_periph); + ti_lib_prcm_load_set(); + while(!ti_lib_prcm_load_get()) ; + + /* SPI configuration */ + ti_lib_ssi_int_disable(spi_controller[dev->spi_controller].ssi_base, SSI_RXOR | SSI_RXFF | SSI_RXTO | SSI_TXFF); + ti_lib_ssi_int_clear(spi_controller[dev->spi_controller].ssi_base, SSI_RXOR | SSI_RXTO); + ti_lib_rom_ssi_config_set_exp_clk(spi_controller[dev->spi_controller].ssi_base, ti_lib_sys_ctrl_clock_get(), + get_mode(dev), SSI_MODE_MASTER, dev->spi_bit_rate, 8); + ti_lib_rom_ioc_pin_type_ssi_master(spi_controller[dev->spi_controller].ssi_base, dev->pin_spi_miso, + dev->pin_spi_mosi, IOID_UNUSED, dev->pin_spi_sck); + + ti_lib_ssi_enable(spi_controller[dev->spi_controller].ssi_base); + + /* Get rid of residual data from SSI port */ + while(ti_lib_ssi_data_get_non_blocking(spi_controller[dev->spi_controller].ssi_base, &c)) ; + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_close(spi_device_t *dev) +{ + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + /* Power down SSI */ + ti_lib_rom_prcm_peripheral_run_disable(spi_controller[dev->spi_controller].prcm_periph); + ti_lib_prcm_load_set(); + while(!ti_lib_prcm_load_get()) ; + + /* Restore pins to a low-consumption state */ + ti_lib_ioc_pin_type_gpio_input(dev->pin_spi_miso); + ti_lib_ioc_io_port_pull_set(dev->pin_spi_miso, IOC_IOPULL_DOWN); + + ti_lib_ioc_pin_type_gpio_input(dev->pin_spi_mosi); + ti_lib_ioc_io_port_pull_set(dev->pin_spi_mosi, IOC_IOPULL_DOWN); + + ti_lib_ioc_pin_type_gpio_input(dev->pin_spi_sck); + ti_lib_ioc_io_port_pull_set(dev->pin_spi_sck, IOC_IOPULL_DOWN); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_transfer(spi_device_t *dev, + const uint8_t *write_buf, int wlen, + uint8_t *inbuf, int rlen, int ignore_len) +{ + int i; + int totlen; + uint32_t c; + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + if(ti_lib_prcm_power_domain_status(spi_controller[dev->spi_controller].power_domain) + != PRCM_DOMAIN_POWER_ON) { + return SPI_DEV_STATUS_CLOSED; + } + + /* Then check the 'run mode' clock gate */ + if(!(HWREG(PRCM_BASE + PRCM_O_SSICLKGR) & spi_controller[dev->spi_controller].ssi_clkgr_clk_en)) { + return SPI_DEV_STATUS_CLOSED; + } + + totlen = MAX(rlen + ignore_len, wlen); + + if(totlen == 0) { + /* Nothing to do */ + return SPI_DEV_STATUS_OK; + } + + for(i = 0; i < totlen; i++) { + c = i < wlen ? write_buf[i] : 0; + ti_lib_ssi_data_put(spi_controller[dev->spi_controller].ssi_base, (uint8_t)c); + ti_lib_rom_ssi_data_get(spi_controller[dev->spi_controller].ssi_base, &c); + if(i < rlen) { + inbuf[i] = (uint8_t)c; + } + } + + while(ti_lib_rom_ssi_data_get_non_blocking(spi_controller[dev->spi_controller].ssi_base, &c)) ; + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_select(spi_device_t *dev) +{ + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + ti_lib_gpio_clear_dio(dev->pin_spi_cs); + + return SPI_DEV_STATUS_OK; +} +spi_status_t +spi_arch_deselect(spi_device_t *dev) +{ + ti_lib_gpio_set_dio(dev->pin_spi_cs); + + return SPI_DEV_STATUS_OK; +} diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h new file mode 100644 index 000000000..afbe3e6c2 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017, 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 HOLDER 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 SPI_ARCH_H_ +#define SPI_ARCH_H_ + +#include "ti-lib.h" + +#include + +/*---------------------------------------------------------------------------*/ +#define BOARD_SPI_CONTROLLERS 2 +/*---------------------------------------------------------------------------*/ +#define BOARD_SPI_CONTROLLER_SPI0 0 +#define BOARD_SPI_CONTROLLER_SPI1 1 +/*---------------------------------------------------------------------------*/ +typedef struct board_spi_controller_s { + uint32_t ssi_base; + uint32_t power_domain; + uint32_t prcm_periph; + uint32_t ssi_clkgr_clk_en; +} board_spi_controller_t; + +#endif /* SPI_ARCH_H_ */ diff --git a/arch/platform/srf06-cc26xx/common/board-spi.c b/arch/platform/srf06-cc26xx/common/board-spi.c deleted file mode 100644 index fb9fecd63..000000000 --- a/arch/platform/srf06-cc26xx/common/board-spi.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ - * 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 sensortag-cc26xx-spi - * @{ - * - * \file - * Board-specific SPI driver common to the Sensortag and LaunchPad - */ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -#include "ti-lib.h" -#include "board-spi.h" -#include "board.h" - -#include -/*---------------------------------------------------------------------------*/ -static bool -accessible(void) -{ - /* First, check the PD */ - if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL) - != PRCM_DOMAIN_POWER_ON) { - return false; - } - - /* Then check the 'run mode' clock gate */ - if(!(HWREG(PRCM_BASE + PRCM_O_SSICLKGR) & PRCM_SSICLKGR_CLK_EN_SSI0)) { - return false; - } - - return true; -} -/*---------------------------------------------------------------------------*/ -bool -board_spi_write(const uint8_t *buf, size_t len) -{ - if(accessible() == false) { - return false; - } - - while(len > 0) { - uint32_t ul; - - ti_lib_ssi_data_put(SSI0_BASE, *buf); - ti_lib_rom_ssi_data_get(SSI0_BASE, &ul); - len--; - buf++; - } - - return true; -} -/*---------------------------------------------------------------------------*/ -bool -board_spi_read(uint8_t *buf, size_t len) -{ - if(accessible() == false) { - return false; - } - - while(len > 0) { - uint32_t ul; - - if(!ti_lib_rom_ssi_data_put_non_blocking(SSI0_BASE, 0)) { - /* Error */ - return false; - } - ti_lib_rom_ssi_data_get(SSI0_BASE, &ul); - *buf = (uint8_t)ul; - len--; - buf++; - } - return true; -} -/*---------------------------------------------------------------------------*/ -void -board_spi_flush() -{ - if(accessible() == false) { - return; - } - - uint32_t ul; - while(ti_lib_rom_ssi_data_get_non_blocking(SSI0_BASE, &ul)); -} -/*---------------------------------------------------------------------------*/ -void -board_spi_open(uint32_t bit_rate, uint32_t clk_pin) -{ - uint32_t buf; - - /* First, make sure the SERIAL PD is on */ - ti_lib_prcm_power_domain_on(PRCM_DOMAIN_SERIAL); - while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_SERIAL) - != PRCM_DOMAIN_POWER_ON)); - - /* Enable clock in active mode */ - ti_lib_rom_prcm_peripheral_run_enable(PRCM_PERIPH_SSI0); - ti_lib_prcm_load_set(); - while(!ti_lib_prcm_load_get()); - - /* SPI configuration */ - ti_lib_ssi_int_disable(SSI0_BASE, SSI_RXOR | SSI_RXFF | SSI_RXTO | SSI_TXFF); - ti_lib_ssi_int_clear(SSI0_BASE, SSI_RXOR | SSI_RXTO); - ti_lib_rom_ssi_config_set_exp_clk(SSI0_BASE, ti_lib_sys_ctrl_clock_get(), - SSI_FRF_MOTO_MODE_0, - SSI_MODE_MASTER, bit_rate, 8); - ti_lib_rom_ioc_pin_type_ssi_master(SSI0_BASE, BOARD_IOID_SPI_MISO, - BOARD_IOID_SPI_MOSI, IOID_UNUSED, clk_pin); - ti_lib_ssi_enable(SSI0_BASE); - - /* Get rid of residual data from SSI port */ - while(ti_lib_ssi_data_get_non_blocking(SSI0_BASE, &buf)); -} -/*---------------------------------------------------------------------------*/ -void -board_spi_close() -{ - /* Power down SSI0 */ - ti_lib_rom_prcm_peripheral_run_disable(PRCM_PERIPH_SSI0); - ti_lib_prcm_load_set(); - while(!ti_lib_prcm_load_get()); - - /* Restore pins to a low-consumption state */ - ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_SPI_MISO); - ti_lib_ioc_io_port_pull_set(BOARD_IOID_SPI_MISO, IOC_IOPULL_DOWN); - - ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_SPI_MOSI); - ti_lib_ioc_io_port_pull_set(BOARD_IOID_SPI_MOSI, IOC_IOPULL_DOWN); - - ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_SPI_CLK_FLASH); - ti_lib_ioc_io_port_pull_set(BOARD_IOID_SPI_CLK_FLASH, IOC_IOPULL_DOWN); -} -/*---------------------------------------------------------------------------*/ -/** @} */ diff --git a/arch/platform/srf06-cc26xx/common/board-spi.h b/arch/platform/srf06-cc26xx/common/board-spi.h deleted file mode 100644 index 3699db120..000000000 --- a/arch/platform/srf06-cc26xx/common/board-spi.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ - * 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 cc26xx-srf-tag - * @{ - * - * \defgroup common-cc26xx-peripherals CC13xx/CC26xx peripheral driver pool - * - * Drivers for peripherals present on more than one CC13xx/CC26xx board. For - * example, the same external flash driver is used for both the part found on - * the Sensortag as well as the part on the LaunchPad. - * - * @{ - * - * \defgroup sensortag-cc26xx-spi SensorTag/LaunchPad SPI functions - * @{ - * - * \file - * Header file for the Sensortag/LaunchPad SPI Driver - */ -/*---------------------------------------------------------------------------*/ -#ifndef BOARD_SPI_H_ -#define BOARD_SPI_H_ -/*---------------------------------------------------------------------------*/ -#include -#include -#include -/*---------------------------------------------------------------------------*/ -/** - * \brief Initialize the SPI interface - * \param bit_rate The bit rate to use - * \param clk_pin The IOID for the clock pin. This can be IOID_0 etc - * \return none - * - * This function will make sure the peripheral is powered, clocked and - * initialised. A chain of calls to board_spi_read(), board_spi_write() and - * board_spi_flush() must be preceded by a call to this function. It is - * recommended to call board_spi_close() after such chain of calls. - */ -void board_spi_open(uint32_t bit_rate, uint32_t clk_pin); - -/** - * \brief Close the SPI interface - * \return True when successful. - * - * This function will stop clocks to the SSI module and will set MISO, MOSI - * and CLK to a low leakage state. It is recommended to call this function - * after a chain of calls to board_spi_read() and board_spi_write() - */ -void board_spi_close(void); - -/** - * \brief Clear data from the SPI interface - * \return none - */ -void board_spi_flush(void); - -/** - * \brief Read from an SPI device - * \param buf The buffer to store data - * \param length The number of bytes to read - * \return True when successful. - * - * Calls to this function must be preceded by a call to board_spi_open(). It is - * recommended to call board_spi_close() at the end of an operation. - */ -bool board_spi_read(uint8_t *buf, size_t length); - -/** - * \brief Write to an SPI device - * \param buf The buffer with the data to write - * \param length The number of bytes to write - * \return True when successful. - * - * Calls to this function must be preceded by a call to board_spi_open(). It is - * recommended to call board_spi_close() at the end of an operation. - */ -bool board_spi_write(const uint8_t *buf, size_t length); -/*---------------------------------------------------------------------------*/ -#endif /* BOARD_SPI_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - * @} - */ diff --git a/arch/platform/srf06-cc26xx/contiki-conf.h b/arch/platform/srf06-cc26xx/contiki-conf.h index 4a1470b40..82daed0c1 100644 --- a/arch/platform/srf06-cc26xx/contiki-conf.h +++ b/arch/platform/srf06-cc26xx/contiki-conf.h @@ -72,6 +72,9 @@ /* Platform-specific define to signify sensor reading failure */ #define CC26XX_SENSOR_READING_ERROR 0x80000000 /*---------------------------------------------------------------------------*/ +/* SPI HAL: Path to arch-specific implementation */ +#define SPI_HAL_CONF_ARCH_HDR_PATH "dev/spi-hal-arch.h" +/*---------------------------------------------------------------------------*/ /* Include CPU-related configuration */ #include "cc13xx-cc26xx-conf.h" /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad index f10f979da..d3f4ab355 100644 --- a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad +++ b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad @@ -3,7 +3,6 @@ CFLAGS += -DBOARD_LAUNCHPAD=1 CONTIKI_TARGET_DIRS += launchpad common BOARD_SOURCEFILES += board.c board-buttons.c xmem.c -BOARD_SOURCEFILES += ext-flash.c board-spi.c ### Signal that we can be programmed with cc2538-bsl BOARD_SUPPORTS_BSL=1 diff --git a/arch/platform/srf06-cc26xx/launchpad/board.c b/arch/platform/srf06-cc26xx/launchpad/board.c index 7baf71d47..cda0a7c6c 100644 --- a/arch/platform/srf06-cc26xx/launchpad/board.c +++ b/arch/platform/srf06-cc26xx/launchpad/board.c @@ -93,7 +93,7 @@ board_init() while(!ti_lib_prcm_load_get()); /* Make sure the external flash is in the lower power mode */ - ext_flash_init(); + ext_flash_init(NULL); lpm_register_module(&launchpad_module); diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h index 7c58e1db8..81f820a13 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h @@ -103,25 +103,29 @@ #define BOARD_KEY_RIGHT (1 << BOARD_IOID_KEY_RIGHT) /** @} */ /*---------------------------------------------------------------------------*/ -/** - * \brief SPI IOID mappings - * - * Those values are not meant to be modified by the user - * @{ - */ -#define BOARD_IOID_SPI_MOSI IOID_9 -#define BOARD_IOID_SPI_MISO IOID_8 -/** @} */ -/*---------------------------------------------------------------------------*/ /** * \name External flash IOID mapping * * Those values are not meant to be modified by the user * @{ */ -#define BOARD_IOID_FLASH_CS IOID_20 -#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS) -#define BOARD_IOID_SPI_CLK_FLASH IOID_10 +#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 + +#define BOARD_IOID_FLASH_SCK IOID_10 +#define BOARD_IOID_FLASH_MOSI IOID_9 +#define BOARD_IOID_FLASH_MISO IOID_8 +#define BOARD_IOID_FLASH_CS IOID_20 + +#define EXT_FLASH_SPI_PIN_SCK 10 +#define EXT_FLASH_SPI_PIN_MOSI 9 +#define EXT_FLASH_SPI_PIN_MISO 8 +#define EXT_FLASH_SPI_PIN_CS 20 + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h index 63ad25374..5831221bc 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h @@ -103,26 +103,29 @@ #define BOARD_KEY_RIGHT (1 << BOARD_IOID_KEY_RIGHT) /** @} */ /*---------------------------------------------------------------------------*/ -/** - * \brief SPI IOID mappings - * - * Those values are not meant to be modified by the user - * @{ - */ -#define BOARD_IOID_SPI_MOSI IOID_9 -#define BOARD_IOID_SPI_MISO IOID_8 -/** @} */ -/*---------------------------------------------------------------------------*/ /** * \name External flash IOID mapping * * Those values are not meant to be modified by the user * @{ */ -#define BOARD_IOID_FLASH_CS IOID_20 -#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS) -#define BOARD_IOID_SPI_CLK_FLASH IOID_10 -/** @} */ +#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 + +#define BOARD_IOID_FLASH_SCK IOID_10 +#define BOARD_IOID_FLASH_MOSI IOID_9 +#define BOARD_IOID_FLASH_MISO IOID_8 +#define BOARD_IOID_FLASH_CS IOID_20 + +#define EXT_FLASH_SPI_PIN_SCK 10 +#define EXT_FLASH_SPI_PIN_MOSI 9 +#define EXT_FLASH_SPI_PIN_MISO 8 +#define EXT_FLASH_SPI_PIN_CS 20 + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 /*---------------------------------------------------------------------------*/ /** * \brief I2C IOID mappings diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h index 39b906e84..7b2c40403 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h @@ -103,25 +103,29 @@ #define BOARD_KEY_RIGHT (1 << BOARD_IOID_KEY_RIGHT) /** @} */ /*---------------------------------------------------------------------------*/ -/** - * \brief SPI IOID mappings - * - * Those values are not meant to be modified by the user - * @{ - */ -#define BOARD_IOID_SPI_MOSI IOID_9 -#define BOARD_IOID_SPI_MISO IOID_8 -/** @} */ -/*---------------------------------------------------------------------------*/ /** * \name External flash IOID mapping * * Those values are not meant to be modified by the user * @{ */ -#define BOARD_IOID_FLASH_CS IOID_20 -#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS) -#define BOARD_IOID_SPI_CLK_FLASH IOID_10 +#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 + +#define BOARD_IOID_FLASH_SCK IOID_10 +#define BOARD_IOID_FLASH_MOSI IOID_9 +#define BOARD_IOID_FLASH_MISO IOID_8 +#define BOARD_IOID_FLASH_CS IOID_20 + +#define EXT_FLASH_SPI_PIN_SCK 10 +#define EXT_FLASH_SPI_PIN_MOSI 9 +#define EXT_FLASH_SPI_PIN_MISO 8 +#define EXT_FLASH_SPI_PIN_CS 20 + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/common/ext-flash.c b/os/dev/ext-flash.c similarity index 66% rename from arch/platform/srf06-cc26xx/common/ext-flash.c rename to os/dev/ext-flash.c index 5631297ac..b1f428e11 100644 --- a/arch/platform/srf06-cc26xx/common/ext-flash.c +++ b/os/dev/ext-flash.c @@ -38,12 +38,34 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "ext-flash.h" -#include "ti-lib.h" -#include "board-spi.h" +#include "spi-hal.h" +#include "gpio-hal.h" +#include "sys/log.h" #include #include /*---------------------------------------------------------------------------*/ +#ifndef EXT_FLASH_SPI_CONTROLLER + +#define EXT_FLASH_SPI_CONTROLLER 0xFF /* No controller */ + +#define EXT_FLASH_SPI_PIN_SCK GPIO_HAL_PIN_UNKNOWN +#define EXT_FLASH_SPI_PIN_MOSI GPIO_HAL_PIN_UNKNOWN +#define EXT_FLASH_SPI_PIN_MISO GPIO_HAL_PIN_UNKNOWN +#define EXT_FLASH_SPI_PIN_CS GPIO_HAL_PIN_UNKNOWN + +#define EXT_FLASH_DEVICE_ID 0xFF +#define EXT_FLASH_MID 0xFF + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 + +#endif /* EXT_FLASH_SPI_CONTROLLER */ +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#define LOG_MODULE "ext-flash" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ /* Instruction codes */ #define BLS_CODE_PROGRAM 0x02 /**< Page Program */ @@ -72,29 +94,33 @@ #define BLS_STATUS_BIT_BUSY 0x01 /**< Busy bit of the status register */ /*---------------------------------------------------------------------------*/ -/* Part specific constants */ -#define BLS_DEVICE_ID_W25X20CL 0x11 -#define BLS_DEVICE_ID_W25X40CL 0x12 -#define BLS_DEVICE_ID_MX25R8035F 0x14 -#define BLS_DEVICE_ID_MX25R1635F 0x15 - -#define BLS_WINBOND_MID 0xEF -#define BLS_MACRONIX_MID 0xC2 - -#define BLS_PROGRAM_PAGE_SIZE 256 -#define BLS_ERASE_SECTOR_SIZE 4096 -/*---------------------------------------------------------------------------*/ +#define VERIFY_PART_LOCKED -2 #define VERIFY_PART_ERROR -1 #define VERIFY_PART_POWERED_DOWN 0 #define VERIFY_PART_OK 1 /*---------------------------------------------------------------------------*/ +static spi_device_t flash_spi_configuration_default = { + .spi_controller = EXT_FLASH_SPI_CONTROLLER, + .pin_spi_sck = EXT_FLASH_SPI_PIN_SCK, + .pin_spi_miso = EXT_FLASH_SPI_PIN_MISO, + .pin_spi_mosi = EXT_FLASH_SPI_PIN_MOSI, + .pin_spi_cs = EXT_FLASH_SPI_PIN_CS, + .spi_bit_rate = 4000000, + .spi_pha = 0, + .spi_pol = 0 +}; + +static spi_device_t *flash_spi_configuration; /** * Clear external flash CSN line */ -static void +static bool select_on_bus(void) { - ti_lib_gpio_clear_dio(BOARD_IOID_FLASH_CS); + if(spi_select(flash_spi_configuration) == SPI_DEV_STATUS_OK) { + return true; + } + return false; } /*---------------------------------------------------------------------------*/ /** @@ -103,7 +129,7 @@ select_on_bus(void) static void deselect(void) { - ti_lib_gpio_set_dio(BOARD_IOID_FLASH_CS); + spi_deselect(flash_spi_configuration); } /*---------------------------------------------------------------------------*/ /** @@ -116,14 +142,13 @@ wait_ready(void) bool ret; const uint8_t wbuf[1] = { BLS_CODE_READ_STATUS }; - select_on_bus(); + if(select_on_bus() == false) { + return false; + } - /* Throw away all garbages */ - board_spi_flush(); + ret = spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)); - ret = board_spi_write(wbuf, sizeof(wbuf)); - - if(ret == false) { + if(ret != SPI_DEV_STATUS_OK) { deselect(); return false; } @@ -135,13 +160,14 @@ wait_ready(void) * Thread could have yielded while waiting for flash * erase/program to complete. */ - ret = board_spi_read(&buf, sizeof(buf)); + ret = spi_read(flash_spi_configuration, &buf, sizeof(buf)); - if(ret == false) { + if(ret != SPI_DEV_STATUS_OK) { /* Error */ deselect(); return false; } + if(!(buf & BLS_STATUS_BIT_BUSY)) { /* Now ready */ break; @@ -165,26 +191,24 @@ verify_part(void) uint8_t rbuf[2] = { 0, 0 }; bool ret; - select_on_bus(); + if(select_on_bus() == false) { + return VERIFY_PART_LOCKED; + } - ret = board_spi_write(wbuf, sizeof(wbuf)); - - if(ret == false) { + if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { deselect(); return VERIFY_PART_ERROR; } - ret = board_spi_read(rbuf, sizeof(rbuf)); + ret = spi_read(flash_spi_configuration, rbuf, sizeof(rbuf)); deselect(); - - if(ret == false) { + if(ret != SPI_DEV_STATUS_OK) { return VERIFY_PART_ERROR; } - if((rbuf[0] != BLS_WINBOND_MID && rbuf[0] != BLS_MACRONIX_MID) || - (rbuf[1] != BLS_DEVICE_ID_W25X20CL && rbuf[1] != BLS_DEVICE_ID_W25X40CL - && rbuf[1] != BLS_DEVICE_ID_MX25R8035F - && rbuf[1] != BLS_DEVICE_ID_MX25R1635F)) { + LOG_DBG("Verify: %02x %02x\n", rbuf[0], rbuf[1]); + + if(rbuf[0] != EXT_FLASH_MID || rbuf[1] != EXT_FLASH_DEVICE_ID) { return VERIFY_PART_POWERED_DOWN; } return VERIFY_PART_OK; @@ -194,7 +218,7 @@ verify_part(void) * \brief Put the device in power save mode. No access to data; only * the status register is accessible. */ -static void +static bool power_down(void) { uint8_t cmd; @@ -203,25 +227,32 @@ power_down(void) /* First, wait for the device to be ready */ if(wait_ready() == false) { /* Entering here will leave the device in standby instead of powerdown */ - return; + return false; } cmd = BLS_CODE_PD; - select_on_bus(); - board_spi_write(&cmd, sizeof(cmd)); + if(select_on_bus() == false) { + return false; + } + + if(spi_write_byte(flash_spi_configuration, cmd) != SPI_DEV_STATUS_OK) { + deselect(); + return false; + } deselect(); i = 0; while(i < 10) { if(verify_part() == VERIFY_PART_POWERED_DOWN) { /* Device is powered down */ - return; + return true; } i++; } /* Should not be required */ deselect(); + return false; } /*---------------------------------------------------------------------------*/ /** @@ -235,8 +266,11 @@ power_standby(void) bool success; cmd = BLS_CODE_RPD; - select_on_bus(); - success = board_spi_write(&cmd, sizeof(cmd)); + if(select_on_bus() == false) { + return false; + } + + success = (spi_write(flash_spi_configuration, &cmd, sizeof(cmd)) == SPI_DEV_STATUS_OK); if(success) { success = wait_ready() == true ? true : false; @@ -257,8 +291,11 @@ write_enable(void) bool ret; const uint8_t wbuf[] = { BLS_CODE_WRITE_ENABLE }; - select_on_bus(); - ret = board_spi_write(wbuf, sizeof(wbuf)); + if(select_on_bus() == false) { + return false; + } + + ret = (spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) == SPI_DEV_STATUS_OK); deselect(); if(ret == false) { @@ -270,11 +307,14 @@ write_enable(void) bool ext_flash_open() { - board_spi_open(4000000, BOARD_IOID_SPI_CLK_FLASH); - - /* GPIO pin configuration */ - ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_FLASH_CS); + /* Check if platform has ext-flash */ + if(flash_spi_configuration->pin_spi_sck == 255) { + return false; + } + if(spi_acquire(flash_spi_configuration) != SPI_DEV_STATUS_OK) { + return false; + } /* Default output to clear chip select */ deselect(); @@ -284,23 +324,29 @@ ext_flash_open() return verify_part() == VERIFY_PART_OK ? true : false; } /*---------------------------------------------------------------------------*/ -void +bool ext_flash_close() { /* Put the part in low power mode */ - power_down(); + if(power_down() == false) { + return false; + } - board_spi_close(); + if(spi_release(flash_spi_configuration) != SPI_DEV_STATUS_OK) { + return false; + } + + return true; } /*---------------------------------------------------------------------------*/ bool -ext_flash_read(size_t offset, size_t length, uint8_t *buf) +ext_flash_read(uint32_t offset, uint32_t length, uint8_t *buf) { uint8_t wbuf[4]; + bool ret; /* Wait till previous erase/program operation completes */ - bool ret = wait_ready(); - if(ret == false) { + if(wait_ready() == false) { return false; } @@ -313,15 +359,17 @@ ext_flash_read(size_t offset, size_t length, uint8_t *buf) wbuf[2] = (offset >> 8) & 0xff; wbuf[3] = offset & 0xff; - select_on_bus(); + if(select_on_bus() == false) { + return false; + } - if(board_spi_write(wbuf, sizeof(wbuf)) == false) { + if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { /* failure */ deselect(); return false; } - ret = board_spi_read(buf, length); + ret = (spi_read(flash_spi_configuration, buf, length) == SPI_DEV_STATUS_OK); deselect(); @@ -329,25 +377,22 @@ ext_flash_read(size_t offset, size_t length, uint8_t *buf) } /*---------------------------------------------------------------------------*/ bool -ext_flash_write(size_t offset, size_t length, const uint8_t *buf) +ext_flash_write(uint32_t offset, uint32_t length, const uint8_t *buf) { uint8_t wbuf[4]; - bool ret; - size_t ilen; /* interim length per instruction */ + uint32_t ilen; /* interim length per instruction */ while(length > 0) { /* Wait till previous erase/program operation completes */ - ret = wait_ready(); - if(ret == false) { + if(wait_ready() == false) { return false; } - ret = write_enable(); - if(ret == false) { + if(write_enable() == false) { return false; } - ilen = BLS_PROGRAM_PAGE_SIZE - (offset % BLS_PROGRAM_PAGE_SIZE); + ilen = EXT_FLASH_PROGRAM_PAGE_SIZE - (offset % EXT_FLASH_PROGRAM_PAGE_SIZE); if(length < ilen) { ilen = length; } @@ -365,15 +410,17 @@ ext_flash_write(size_t offset, size_t length, const uint8_t *buf) * is not imposed here since above instructions * should be enough to delay * as much. */ - select_on_bus(); + if(select_on_bus() == false) { + return false; + } - if(board_spi_write(wbuf, sizeof(wbuf)) == false) { + if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { /* failure */ deselect(); return false; } - if(board_spi_write(buf, ilen) == false) { + if(spi_write(flash_spi_configuration, buf, ilen) != SPI_DEV_STATUS_OK) { /* failure */ deselect(); return false; @@ -386,7 +433,7 @@ ext_flash_write(size_t offset, size_t length, const uint8_t *buf) } /*---------------------------------------------------------------------------*/ bool -ext_flash_erase(size_t offset, size_t length) +ext_flash_erase(uint32_t offset, uint32_t length) { /* * Note that Block erase might be more efficient when the floor map @@ -394,24 +441,21 @@ ext_flash_erase(size_t offset, size_t length) * sector erase is used blindly. */ uint8_t wbuf[4]; - bool ret; - size_t i, numsectors; - size_t endoffset = offset + length - 1; + uint32_t i, numsectors; + uint32_t endoffset = offset + length - 1; - offset = (offset / BLS_ERASE_SECTOR_SIZE) * BLS_ERASE_SECTOR_SIZE; - numsectors = (endoffset - offset + BLS_ERASE_SECTOR_SIZE - 1) / BLS_ERASE_SECTOR_SIZE; + offset = (offset / EXT_FLASH_ERASE_SECTOR_SIZE) * EXT_FLASH_ERASE_SECTOR_SIZE; + numsectors = (endoffset - offset + EXT_FLASH_ERASE_SECTOR_SIZE - 1) / EXT_FLASH_ERASE_SECTOR_SIZE; wbuf[0] = BLS_CODE_SECTOR_ERASE; for(i = 0; i < numsectors; i++) { /* Wait till previous erase/program operation completes */ - ret = wait_ready(); - if(ret == false) { + if(wait_ready() == false) { return false; } - ret = write_enable(); - if(ret == false) { + if(write_enable() == false) { return false; } @@ -419,16 +463,18 @@ ext_flash_erase(size_t offset, size_t length) wbuf[2] = (offset >> 8) & 0xff; wbuf[3] = offset & 0xff; - select_on_bus(); + if(select_on_bus() == false) { + return false; + } - if(board_spi_write(wbuf, sizeof(wbuf)) == false) { + if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { /* failure */ deselect(); return false; } deselect(); - offset += BLS_ERASE_SECTOR_SIZE; + offset += EXT_FLASH_ERASE_SECTOR_SIZE; } return true; @@ -437,19 +483,31 @@ ext_flash_erase(size_t offset, size_t length) bool ext_flash_test(void) { - bool ret; + flash_spi_configuration = &flash_spi_configuration_default; - ret = ext_flash_open(); - ext_flash_close(); + if(ext_flash_open() == false) { + return false; + } - return ret; + if(ext_flash_close() == false) { + return false; + } + + LOG_INFO("Flash test successful\n"); + + return true; } /*---------------------------------------------------------------------------*/ -void -ext_flash_init() +bool +ext_flash_init(spi_device_t *conf) { - ext_flash_open(); - ext_flash_close(); + if(conf == NULL) { + flash_spi_configuration = &flash_spi_configuration_default; + } else { + flash_spi_configuration = conf; + } + + return ext_flash_test(); } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/platform/srf06-cc26xx/common/ext-flash.h b/os/dev/ext-flash.h similarity index 92% rename from arch/platform/srf06-cc26xx/common/ext-flash.h rename to os/dev/ext-flash.h index 5f2717edb..a14ccdbf0 100644 --- a/arch/platform/srf06-cc26xx/common/ext-flash.h +++ b/os/dev/ext-flash.h @@ -42,6 +42,8 @@ #ifndef EXT_FLASH_H_ #define EXT_FLASH_H_ /*---------------------------------------------------------------------------*/ +#include "spi-hal.h" + #include #include #include @@ -57,7 +59,7 @@ bool ext_flash_open(void); * * This call will put the device in its lower power mode (power down). */ -void ext_flash_close(void); +bool ext_flash_close(void); /** * \brief Read storage content @@ -68,7 +70,7 @@ void ext_flash_close(void); * * buf must be allocated by the caller */ -bool ext_flash_read(size_t offset, size_t length, uint8_t *buf); +bool ext_flash_read(uint32_t offset, uint32_t length, uint8_t *buf); /** * \brief Erase storage sectors corresponding to the range. @@ -79,7 +81,7 @@ bool ext_flash_read(size_t offset, size_t length, uint8_t *buf); * The erase operation will be sector-wise, therefore a call to this function * will generally start the erase procedure at an address lower than offset */ -bool ext_flash_erase(size_t offset, size_t length); +bool ext_flash_erase(uint32_t offset, uint32_t length); /** * \brief Write to storage sectors. @@ -89,7 +91,7 @@ bool ext_flash_erase(size_t offset, size_t length); * * \return True when successful. */ -bool ext_flash_write(size_t offset, size_t length, const uint8_t *buf); +bool ext_flash_write(uint32_t offset, uint32_t length, const uint8_t *buf); /** * \brief Test the flash (power on self-test) @@ -106,7 +108,7 @@ bool ext_flash_test(void); * In order to perform any operation, the caller must first wake the device * up by calling ext_flash_open() */ -void ext_flash_init(void); +bool ext_flash_init(spi_device_t *conf); /*---------------------------------------------------------------------------*/ #endif /* EXT_FLASH_H_ */ /*---------------------------------------------------------------------------*/ From 5e79f0a92215fc6802827b7c11404ef5f45620b7 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Tue, 19 Dec 2017 15:43:58 +0000 Subject: [PATCH 43/72] spi hal implementation for sensortag --- .../srf06-cc26xx/sensortag/Makefile.sensortag | 4 +-- arch/platform/srf06-cc26xx/sensortag/board.c | 2 +- .../srf06-cc26xx/sensortag/cc1350/board.h | 30 +++++++++------- .../srf06-cc26xx/sensortag/cc2650/board.h | 34 +++++++++---------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag b/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag index 46cf25a68..5d528b8dc 100644 --- a/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag +++ b/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag @@ -6,5 +6,5 @@ CONTIKI_TARGET_DIRS += sensortag common BOARD_SOURCEFILES += sensortag-sensors.c board-buttons.c sensor-common.c BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c xmem.c -BOARD_SOURCEFILES += ext-flash.c buzzer.c -BOARD_SOURCEFILES += board.c board-spi.c board-i2c.c +BOARD_SOURCEFILES += buzzer.c +BOARD_SOURCEFILES += board.c board-i2c.c diff --git a/arch/platform/srf06-cc26xx/sensortag/board.c b/arch/platform/srf06-cc26xx/sensortag/board.c index e2069f39f..4b6a69bde 100644 --- a/arch/platform/srf06-cc26xx/sensortag/board.c +++ b/arch/platform/srf06-cc26xx/sensortag/board.c @@ -146,7 +146,7 @@ board_init() buzzer_init(); /* Make sure the external flash is in the lower power mode */ - ext_flash_init(); + ext_flash_init(NULL); lpm_register_module(&sensortag_module); diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h index aa8719eea..bd1de7416 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h @@ -113,16 +113,6 @@ #define BOARD_KEY_RIGHT (1 << BOARD_IOID_KEY_RIGHT) /** @} */ /*---------------------------------------------------------------------------*/ -/** - * \brief SPI IOID mappings - * - * Those values are not meant to be modified by the user - * @{ - */ -#define BOARD_IOID_SPI_MOSI IOID_19 -#define BOARD_IOID_SPI_MISO IOID_18 -/** @} */ -/*---------------------------------------------------------------------------*/ /** * \name Buzzer configuration * @{ @@ -145,9 +135,23 @@ * Those values are not meant to be modified by the user * @{ */ -#define BOARD_IOID_FLASH_CS IOID_14 -#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS) -#define BOARD_IOID_SPI_CLK_FLASH IOID_17 +#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 + +#define BOARD_IOID_FLASH_SCK IOID_17 +#define BOARD_IOID_FLASH_MOSI IOID_19 +#define BOARD_IOID_FLASH_MISO IOID_18 +#define BOARD_IOID_FLASH_CS IOID_14 + +#define EXT_FLASH_SPI_PIN_SCK 17 +#define EXT_FLASH_SPI_PIN_MOSI 19 +#define EXT_FLASH_SPI_PIN_MISO 18 +#define EXT_FLASH_SPI_PIN_CS 14 + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h index 9543d2713..7db109ece 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h @@ -115,20 +115,6 @@ #define BOARD_KEY_RIGHT (1 << BOARD_IOID_KEY_RIGHT) /** @} */ /*---------------------------------------------------------------------------*/ -/** - * \brief SPI IOID mappings - * - * Those values are not meant to be modified by the user - * @{ - */ -#define BOARD_IOID_SPI_SCK IOID_17 -#define BOARD_IOID_SPI_MOSI IOID_19 -#define BOARD_IOID_SPI_MISO IOID_18 -#define BOARD_SPI_SCK (1 << BOARD_IOID_SPI_SCK) -#define BOARD_SPI_MOSI (1 << BOARD_IOID_SPI_MOSI) -#define BOARD_SPI_MISO (1 << BOARD_IOID_SPI_MISO) -/** @} */ -/*---------------------------------------------------------------------------*/ /** * \name Buzzer configuration * @{ @@ -151,9 +137,23 @@ * Those values are not meant to be modified by the user * @{ */ -#define BOARD_IOID_FLASH_CS IOID_14 -#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS) -#define BOARD_IOID_SPI_CLK_FLASH IOID_17 +#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 + +#define BOARD_IOID_FLASH_SCK IOID_17 +#define BOARD_IOID_FLASH_MOSI IOID_19 +#define BOARD_IOID_FLASH_MISO IOID_18 +#define BOARD_IOID_FLASH_CS IOID_14 + +#define EXT_FLASH_SPI_PIN_SCK 17 +#define EXT_FLASH_SPI_PIN_MOSI 19 +#define EXT_FLASH_SPI_PIN_MISO 18 +#define EXT_FLASH_SPI_PIN_CS 14 + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 /** @} */ /*---------------------------------------------------------------------------*/ /** From 2a7e9f08356bf290ec7060834c734f878d78c32d Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 21 Feb 2018 17:33:29 +0000 Subject: [PATCH 44/72] SPI HAL implementation for CC2538 --- arch/cpu/cc2538/Makefile.cc2538 | 1 + arch/cpu/cc2538/cc2538-conf.h | 3 + arch/cpu/cc2538/dev/spi-hal-arch.c | 359 +++++++++++++++++++++++++++++ arch/cpu/cc2538/dev/spi-hal-arch.h | 84 +++++++ 4 files changed, 447 insertions(+) create mode 100644 arch/cpu/cc2538/dev/spi-hal-arch.c create mode 100644 arch/cpu/cc2538/dev/spi-hal-arch.h diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index 03758aa9b..ec2f733b5 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -16,6 +16,7 @@ CONTIKI_CPU_DIRS = . dev usb usb/common usb/common/cdc-acm ### CPU-dependent source files CONTIKI_CPU_SOURCEFILES += soc.c clock.c rtimer-arch.c uart.c watchdog.c CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi.c adc.c +CONTIKI_CPU_SOURCEFILES += spi-hal-arch.c CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c gpio-hal-arch.c CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c diff --git a/arch/cpu/cc2538/cc2538-conf.h b/arch/cpu/cc2538/cc2538-conf.h index 725f95439..b0f2ace0c 100644 --- a/arch/cpu/cc2538/cc2538-conf.h +++ b/arch/cpu/cc2538/cc2538-conf.h @@ -325,6 +325,9 @@ #endif /** @} */ /*---------------------------------------------------------------------------*/ +/* SPI HAL: Path to arch-specific implementation */ +#define SPI_HAL_CONF_ARCH_HDR_PATH "dev/spi-hal-arch.h" +/*---------------------------------------------------------------------------*/ #endif /* CC2538_CONF_H_ */ /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.c b/arch/cpu/cc2538/dev/spi-hal-arch.c new file mode 100644 index 000000000..889fd5588 --- /dev/null +++ b/arch/cpu/cc2538/dev/spi-hal-arch.c @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2016-2017, Yanzi Networks. + * Copyright (c) 2018, University of Bristol. + * 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 HOLDER 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 +#include "contiki.h" +#include "reg.h" +#include "spi-hal.h" +#include "spi-hal-arch.h" +#include "gpio-hal-arch.h" +#include "sys/cc.h" +#include "ioc.h" +#include "sys-ctrl.h" +#include "spi.h" +#include "ssi.h" +#include "gpio.h" +#include "sys/log.h" +#include "sys/mutex.h" +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#define LOG_MODULE "spi-hal-arch" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ +#if (SPI0_CPRS_CPSDVSR & 1) == 1 || SPI0_CPRS_CPSDVSR < 2 || SPI0_CPRS_CPSDVSR > 254 +#error SPI0_CPRS_CPSDVSR must be an even number between 2 and 254 +#endif + +#if (SPI1_CPRS_CPSDVSR & 1) == 1 || SPI1_CPRS_CPSDVSR < 2 || SPI1_CPRS_CPSDVSR > 254 +#error SPI1_CPRS_CPSDVSR must be an even number between 2 and 254 +#endif +/*---------------------------------------------------------------------------*/ +/* + * Clock source from which the baud clock is determined for the SSI, according + * to SSI_CC.CS. + */ +#define SSI_SYS_CLOCK SYS_CTRL_SYS_CLOCK +/*---------------------------------------------------------------------------*/ +typedef struct { + uint32_t base; + uint32_t ioc_ssirxd_ssi; + uint32_t ioc_pxx_sel_ssi_clkout; + uint32_t ioc_pxx_sel_ssi_txd; + uint8_t ssi_cprs_cpsdvsr; +} spi_regs_t; +/*---------------------------------------------------------------------------*/ +static const spi_regs_t spi_regs[SSI_INSTANCE_COUNT] = { + { + .base = SSI0_BASE, + .ioc_ssirxd_ssi = IOC_SSIRXD_SSI0, + .ioc_pxx_sel_ssi_clkout = IOC_PXX_SEL_SSI0_CLKOUT, + .ioc_pxx_sel_ssi_txd = IOC_PXX_SEL_SSI0_TXD, + .ssi_cprs_cpsdvsr = SPI0_CPRS_CPSDVSR, + }, { + .base = SSI1_BASE, + .ioc_ssirxd_ssi = IOC_SSIRXD_SSI1, + .ioc_pxx_sel_ssi_clkout = IOC_PXX_SEL_SSI1_CLKOUT, + .ioc_pxx_sel_ssi_txd = IOC_PXX_SEL_SSI1_TXD, + .ssi_cprs_cpsdvsr = SPI1_CPRS_CPSDVSR, + } +}; + +typedef struct spi_locks_s { + mutex_t lock; + spi_device_t *owner; +} spi_locks_t; + +/* One lock per SPI controller */ +spi_locks_t board_spi_locks_spi[BOARD_SPI_CONTROLLERS] = { { MUTEX_STATUS_UNLOCKED, NULL } }; + +/*---------------------------------------------------------------------------*/ +static void +spix_wait_tx_ready(spi_device_t *dev) +{ + /* Infinite loop until SR_TNF - Transmit FIFO Not Full */ + while(!(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_TNF)); +} +/*---------------------------------------------------------------------------*/ +static int +spix_read_buf(spi_device_t *dev) +{ + return REG(spi_regs[dev->spi_controller].base + SSI_DR); +} +/*---------------------------------------------------------------------------*/ +static void +spix_write_buf(spi_device_t *dev, int data) +{ + REG(spi_regs[dev->spi_controller].base + SSI_DR) = data; +} +/*---------------------------------------------------------------------------*/ +static void +spix_wait_eotx(spi_device_t *dev) +{ + /* wait until not busy */ + while(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_BSY); +} +/*---------------------------------------------------------------------------*/ +static void +spix_wait_eorx(spi_device_t *dev) +{ + /* wait as long as receive is empty */ + while(!(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_RNE)); +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_lock(spi_device_t *dev) +{ + if(mutex_try_lock(&board_spi_locks_spi[dev->spi_controller].lock) == false) { + return SPI_DEV_STATUS_BUS_LOCKED; + } + + board_spi_locks_spi[dev->spi_controller].owner = dev; + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +bool +spi_arch_has_lock(spi_device_t *dev) +{ + if(board_spi_locks_spi[dev->spi_controller].owner == dev) { + return true; + } + + return false; +} +/*---------------------------------------------------------------------------*/ +bool +spi_arch_is_bus_locked(spi_device_t *dev) +{ + if(board_spi_locks_spi[dev->spi_controller].lock == MUTEX_STATUS_LOCKED) { + return true; + } + + return false; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_unlock(spi_device_t *dev) +{ + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + board_spi_locks_spi[dev->spi_controller].owner = NULL; + mutex_unlock(&board_spi_locks_spi[dev->spi_controller].lock); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ + +spi_status_t +spi_arch_open(spi_device_t *dev) +{ + uint32_t scr; + uint64_t div; + + uint32_t cs_port = PIN_TO_PORT(dev->pin_spi_cs); + uint32_t cs_pin = PIN_TO_NUM(dev->pin_spi_cs); + + uint32_t clk_port = PIN_TO_PORT(dev->pin_spi_sck); + uint32_t clk_pin = PIN_TO_NUM(dev->pin_spi_sck); + + uint32_t miso_port = PIN_TO_PORT(dev->pin_spi_miso); + uint32_t miso_pin = PIN_TO_NUM(dev->pin_spi_miso); + + uint32_t mosi_port = PIN_TO_PORT(dev->pin_spi_mosi); + uint32_t mosi_pin = PIN_TO_NUM(dev->pin_spi_mosi); + + uint32_t mode = 0; + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + /* Set SPI phase */ + if(dev->spi_pha != 0){ + mode = mode | SSI_CR0_SPH; + } + + /* Set SPI polarity */ + if(dev->spi_pol !=0){ + mode = mode | SSI_CR0_SPO; + } + + /* CS pin configuration */ + GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(cs_port), + GPIO_PIN_MASK(cs_pin)); + ioc_set_over(cs_port, cs_pin, IOC_OVERRIDE_DIS); + GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(cs_port), GPIO_PIN_MASK(cs_pin)); + GPIO_SET_PIN(GPIO_PORT_TO_BASE(cs_port), GPIO_PIN_MASK(cs_pin)); + + const spi_regs_t *regs; + + regs = &spi_regs[dev->spi_controller]; + + /* SSI Enable */ + REG(SYS_CTRL_RCGCSSI) |= (1 << dev->spi_controller); + + /* Start by disabling the peripheral before configuring it */ + REG(regs->base + SSI_CR1) = 0; + + /* Set the system clock as the SSI clock */ + REG(regs->base + SSI_CC) = 0; + + /* Set the mux correctly to connect the SSI pins to the correct GPIO pins */ + ioc_set_sel(clk_port, clk_pin, regs->ioc_pxx_sel_ssi_clkout); + ioc_set_sel(mosi_port, mosi_pin, regs->ioc_pxx_sel_ssi_txd); + REG(regs->ioc_ssirxd_ssi) = dev->pin_spi_miso; + + /* Put all the SSI gpios into peripheral mode */ + GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(clk_port), + GPIO_PIN_MASK(clk_pin)); + GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(mosi_port), + GPIO_PIN_MASK(mosi_pin)); + GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(miso_port), + GPIO_PIN_MASK(miso_pin)); + + /* Disable any pull ups or the like */ + ioc_set_over(clk_port, clk_pin, IOC_OVERRIDE_DIS); + ioc_set_over(mosi_port, mosi_pin, IOC_OVERRIDE_DIS); + ioc_set_over(miso_port, miso_pin, IOC_OVERRIDE_DIS); + + /* Configure the clock */ + REG(regs->base + SSI_CPSR) = regs->ssi_cprs_cpsdvsr; + + /* Configure the mode */ + REG(regs->base + SSI_CR0) = mode | (0x07); + + /* Configure the SSI serial clock rate */ + if(!dev->spi_bit_rate) { + scr = 255; + } else { + div = (uint64_t)regs->ssi_cprs_cpsdvsr * dev->spi_bit_rate; + scr = (SSI_SYS_CLOCK + div - 1) / div; + scr = MIN(MAX(scr, 1), 256) - 1; + } + REG(regs->base + SSI_CR0) = (REG(regs->base + SSI_CR0) & ~SSI_CR0_SCR_M) | + scr << SSI_CR0_SCR_S; + + /* Enable the SSI */ + REG(regs->base + SSI_CR1) |= SSI_CR1_SSE; + + return SPI_DEV_STATUS_OK; +} + +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_close(spi_device_t *dev) +{ + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + /* Disable SSI */ + REG(SYS_CTRL_RCGCSSI) &= ~(1 << dev->spi_controller); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_select(spi_device_t *dev) +{ + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + SPIX_CS_CLR(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs)); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_deselect(spi_device_t *dev) +{ + SPIX_CS_SET(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs)); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ +/* Assumes that checking dev and bus is not NULL before calling this */ +spi_status_t +spi_arch_transfer(spi_device_t *dev, + const uint8_t *write_buf, int wlen, + uint8_t *inbuf, int rlen, int ignore_len) +{ + int i; + int totlen; + uint8_t c; + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + LOG_DBG("SPI: transfer (r:%d,w:%d) ", rlen, wlen); + + if(write_buf == NULL && wlen > 0) { + return SPI_DEV_STATUS_EINVAL; + } + if(inbuf == NULL && rlen > 0) { + return SPI_DEV_STATUS_EINVAL; + } + + totlen = MAX(rlen + ignore_len, wlen); + + if(totlen == 0) { + /* Nothing to do */ + return SPI_DEV_STATUS_OK; + } + + LOG_DBG("%c%c%c: %u ", rlen > 0 ? 'R' : '-', wlen > 0 ? 'W' : '-', + ignore_len > 0 ? 'S' : '-', totlen); + + for(i = 0; i < totlen; i++) { + spix_wait_tx_ready(dev); + c = i < wlen ? write_buf[i] : 0; + spix_write_buf(dev, c); + LOG_DBG("%c%02x->", i < rlen ? ' ' : '#', c); + spix_wait_eotx(dev); + spix_wait_eorx(dev); + c = spix_read_buf(dev); + if(i < rlen) { + inbuf[i] = c; + } + LOG_DBG("%02x", c); + } + LOG_DBG("\n"); + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.h b/arch/cpu/cc2538/dev/spi-hal-arch.h new file mode 100644 index 000000000..7eb231496 --- /dev/null +++ b/arch/cpu/cc2538/dev/spi-hal-arch.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2013, University of Michigan. + * + * Copyright (c) 2015, Weptech elektronik GmbH + * Author: Ulf Knoblich, ulf.knoblich@weptech.de + * + * Copyright (c) 2018, University of Bristol. + * + * 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 University 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. + */ + +#ifndef SPI_ARCH_H_ +#define SPI_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#define BOARD_SPI_CONTROLLERS 2 +/*---------------------------------------------------------------------------*/ +#define BOARD_SPI_CONTROLLER_SPI0 0 +#define BOARD_SPI_CONTROLLER_SPI1 1 +/*---------------------------------------------------------------------------*/ +/* Default values for the clock rate divider */ +#ifdef SPI0_CONF_CPRS_CPSDVSR +#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR +#else +#define SPI0_CPRS_CPSDVSR 2 +#endif + +#ifdef SPI1_CONF_CPRS_CPSDVSR +#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR +#else +#define SPI1_CPRS_CPSDVSR 2 +#endif +/*---------------------------------------------------------------------------*/ +/* New API macros */ +#define SPIX_WAITFORTxREADY(spi) do { \ + while(!(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_TNF)) ; \ +} while(0) +#define SPIX_BUF(spi) REG(SSI_BASE(spi) + SSI_DR) +#define SPIX_WAITFOREOTx(spi) do { \ + while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_BSY) ; \ +} while(0) +#define SPIX_WAITFOREORx(spi) do { \ + while(!(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE)) ; \ +} while(0) +#define SPIX_FLUSH(spi) do { \ + while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE) { \ + SPIX_BUF(spi); \ + } \ +} while(0) +#define SPIX_CS_CLR(port, pin) do { \ + GPIO_CLR_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin)); \ +} while(0) +#define SPIX_CS_SET(port, pin) do { \ + GPIO_SET_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin)); \ +} while(0) + +#endif /* SPI_ARCH_H_ */ + +/** + * @} + */ From fe05c6f8655021d2cef5008bfcbbd496e9cc3b16 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 18:06:19 +0000 Subject: [PATCH 45/72] Fix doxygen errors --- os/dev/spi-hal.c | 13 ++++++++++++- os/dev/spi-hal.h | 14 ++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/os/dev/spi-hal.c b/os/dev/spi-hal.c index c8c84bd7c..fcb7a8b3e 100644 --- a/os/dev/spi-hal.c +++ b/os/dev/spi-hal.c @@ -28,7 +28,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ - +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup spi-hal + * @{ + * + * \file + * Implementation of the platform-independent aspects of the SPI HAL + */ +/*---------------------------------------------------------------------------*/ #include "spi-hal.h" /*---------------------------------------------------------------------------*/ @@ -223,3 +231,6 @@ spi_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) return spi_arch_transfer(dev, &strobe, 1, result, 1, 0); } /*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/os/dev/spi-hal.h b/os/dev/spi-hal.h index 901da2a25..7bc5f20ee 100644 --- a/os/dev/spi-hal.h +++ b/os/dev/spi-hal.h @@ -73,6 +73,7 @@ typedef enum { SPI_DEV_STATUS_BUS_NOT_OWNED, /* SPI bus is locked by someone else */ SPI_DEV_STATUS_CLOSED /* SPI bus has not opened properly */ } spi_status_t; +/** @} */ /*---------------------------------------------------------------------------*/ /** * \brief SPI Device Configuration @@ -92,7 +93,7 @@ typedef struct spi_device { uint8_t spi_pol; /* SPI mode polarity */ uint8_t spi_controller; /* ID of SPI controller to use */ } spi_device_t; - +/** @} */ /*---------------------------------------------------------------------------*/ /* These are architecture-independent functions to be used by SPI devices. */ /*---------------------------------------------------------------------------*/ @@ -201,11 +202,11 @@ spi_status_t spi_read_skip(spi_device_t *dev, int size); * \param dev An SPI device configuration. * \param data A pointer to the data to be written. Set it to NULL to * skip writing. - * \param wlen Size of data to write. + * \param wsize Size of data to write. * \param buf A pointer to buffer to copy the data read. Set to NULL * to skip reading. - * \param rlen Size of data to read. - * \param ignore_len Size of data to read and ignore. + * \param rsize Size of data to read. + * \param ignore Size of data to read and ignore. * \return SPI return code * * It should work only if the device has already locked the SPI controller. @@ -347,3 +348,8 @@ spi_status_t spi_arch_select(spi_device_t *dev); spi_status_t spi_arch_deselect(spi_device_t *dev); #endif /* SPI_HAL_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From e7eee05c7d13c08d5c6ec43a8d74c6bd3f79255e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 18:07:42 +0000 Subject: [PATCH 46/72] Add some inludes explicitly --- arch/cpu/cc2538/dev/spi-hal-arch.h | 12 +++++++----- os/dev/spi-hal.c | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.h b/arch/cpu/cc2538/dev/spi-hal-arch.h index 7eb231496..876e27af4 100644 --- a/arch/cpu/cc2538/dev/spi-hal-arch.h +++ b/arch/cpu/cc2538/dev/spi-hal-arch.h @@ -32,24 +32,26 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - +/*---------------------------------------------------------------------------*/ #ifndef SPI_ARCH_H_ #define SPI_ARCH_H_ /*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ #define BOARD_SPI_CONTROLLERS 2 /*---------------------------------------------------------------------------*/ #define BOARD_SPI_CONTROLLER_SPI0 0 #define BOARD_SPI_CONTROLLER_SPI1 1 /*---------------------------------------------------------------------------*/ /* Default values for the clock rate divider */ -#ifdef SPI0_CONF_CPRS_CPSDVSR -#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR +#ifdef SPI0_CONF_CPRS_CPSDVSR +#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR #else #define SPI0_CPRS_CPSDVSR 2 #endif -#ifdef SPI1_CONF_CPRS_CPSDVSR -#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR +#ifdef SPI1_CONF_CPRS_CPSDVSR +#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR #else #define SPI1_CPRS_CPSDVSR 2 #endif diff --git a/os/dev/spi-hal.c b/os/dev/spi-hal.c index fcb7a8b3e..532e9323f 100644 --- a/os/dev/spi-hal.c +++ b/os/dev/spi-hal.c @@ -37,8 +37,11 @@ * Implementation of the platform-independent aspects of the SPI HAL */ /*---------------------------------------------------------------------------*/ +#include "contiki.h" #include "spi-hal.h" +#include +#include /*---------------------------------------------------------------------------*/ spi_status_t spi_acquire(spi_device_t *dev) From 4a0dcf5f1e8000d4c466a2f51c8400278884c525 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 18:09:09 +0000 Subject: [PATCH 47/72] Minor code style fixes --- arch/cpu/cc2538/dev/spi-hal-arch.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.c b/arch/cpu/cc2538/dev/spi-hal-arch.c index 889fd5588..7b1469f0a 100644 --- a/arch/cpu/cc2538/dev/spi-hal-arch.c +++ b/arch/cpu/cc2538/dev/spi-hal-arch.c @@ -173,24 +173,24 @@ spi_arch_unlock(spi_device_t *dev) return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ - spi_status_t spi_arch_open(spi_device_t *dev) { + const spi_regs_t *regs; uint32_t scr; uint64_t div; uint32_t cs_port = PIN_TO_PORT(dev->pin_spi_cs); - uint32_t cs_pin = PIN_TO_NUM(dev->pin_spi_cs); + uint32_t cs_pin = PIN_TO_NUM(dev->pin_spi_cs); uint32_t clk_port = PIN_TO_PORT(dev->pin_spi_sck); - uint32_t clk_pin = PIN_TO_NUM(dev->pin_spi_sck); + uint32_t clk_pin = PIN_TO_NUM(dev->pin_spi_sck); uint32_t miso_port = PIN_TO_PORT(dev->pin_spi_miso); - uint32_t miso_pin = PIN_TO_NUM(dev->pin_spi_miso); + uint32_t miso_pin = PIN_TO_NUM(dev->pin_spi_miso); uint32_t mosi_port = PIN_TO_PORT(dev->pin_spi_mosi); - uint32_t mosi_pin = PIN_TO_NUM(dev->pin_spi_mosi); + uint32_t mosi_pin = PIN_TO_NUM(dev->pin_spi_mosi); uint32_t mode = 0; @@ -199,12 +199,12 @@ spi_arch_open(spi_device_t *dev) } /* Set SPI phase */ - if(dev->spi_pha != 0){ + if(dev->spi_pha != 0) { mode = mode | SSI_CR0_SPH; } /* Set SPI polarity */ - if(dev->spi_pol !=0){ + if(dev->spi_pol != 0) { mode = mode | SSI_CR0_SPO; } @@ -215,8 +215,6 @@ spi_arch_open(spi_device_t *dev) GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(cs_port), GPIO_PIN_MASK(cs_pin)); GPIO_SET_PIN(GPIO_PORT_TO_BASE(cs_port), GPIO_PIN_MASK(cs_pin)); - const spi_regs_t *regs; - regs = &spi_regs[dev->spi_controller]; /* SSI Enable */ @@ -261,14 +259,13 @@ spi_arch_open(spi_device_t *dev) scr = MIN(MAX(scr, 1), 256) - 1; } REG(regs->base + SSI_CR0) = (REG(regs->base + SSI_CR0) & ~SSI_CR0_SCR_M) | - scr << SSI_CR0_SCR_S; + scr << SSI_CR0_SCR_S; /* Enable the SSI */ REG(regs->base + SSI_CR1) |= SSI_CR1_SSE; return SPI_DEV_STATUS_OK; } - /*---------------------------------------------------------------------------*/ spi_status_t spi_arch_close(spi_device_t *dev) @@ -303,14 +300,12 @@ spi_arch_deselect(spi_device_t *dev) return SPI_DEV_STATUS_OK; } -/*---------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------*/ /* Assumes that checking dev and bus is not NULL before calling this */ spi_status_t spi_arch_transfer(spi_device_t *dev, - const uint8_t *write_buf, int wlen, - uint8_t *inbuf, int rlen, int ignore_len) + const uint8_t *write_buf, int wlen, + uint8_t *inbuf, int rlen, int ignore_len) { int i; int totlen; @@ -337,7 +332,7 @@ spi_arch_transfer(spi_device_t *dev, } LOG_DBG("%c%c%c: %u ", rlen > 0 ? 'R' : '-', wlen > 0 ? 'W' : '-', - ignore_len > 0 ? 'S' : '-', totlen); + ignore_len > 0 ? 'S' : '-', totlen); for(i = 0; i < totlen; i++) { spix_wait_tx_ready(dev); From 06958100445f839ed80451bab5fe65d937ee555b Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:27:17 +0000 Subject: [PATCH 48/72] Rename old CC2538 SPI driver --- arch/cpu/cc2538/Makefile.cc2538 | 2 +- arch/cpu/cc2538/{spi-arch.h => dev/spi-arch-legacy.h} | 8 ++++---- arch/cpu/cc2538/dev/{spi.c => spi-legacy.c} | 2 +- arch/platform/zoul/dev/cc1200-zoul-arch.c | 2 +- arch/platform/zoul/dev/mmc-arch.c | 2 +- arch/platform/zoul/orion/enc28j60-arch-spi.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename arch/cpu/cc2538/{spi-arch.h => dev/spi-arch-legacy.h} (98%) rename arch/cpu/cc2538/dev/{spi.c => spi-legacy.c} (99%) diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index ec2f733b5..9d61c2f9a 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -15,7 +15,7 @@ CONTIKI_CPU_DIRS = . dev usb usb/common usb/common/cdc-acm ### CPU-dependent source files CONTIKI_CPU_SOURCEFILES += soc.c clock.c rtimer-arch.c uart.c watchdog.c -CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi.c adc.c +CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi-legacy.c adc.c CONTIKI_CPU_SOURCEFILES += spi-hal-arch.c CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c gpio-hal-arch.c diff --git a/arch/cpu/cc2538/spi-arch.h b/arch/cpu/cc2538/dev/spi-arch-legacy.h similarity index 98% rename from arch/cpu/cc2538/spi-arch.h rename to arch/cpu/cc2538/dev/spi-arch-legacy.h index 8cbb87a8f..0204baefa 100644 --- a/arch/cpu/cc2538/spi-arch.h +++ b/arch/cpu/cc2538/dev/spi-arch-legacy.h @@ -78,8 +78,8 @@ * - SPI1_RX_PORT * - SPI1_RX_PIN */ -#ifndef SPI_ARCH_H_ -#define SPI_ARCH_H_ +#ifndef SPI_ARCH_LEGACY_H_ +#define SPI_ARCH_LEGACY_H_ #include "contiki.h" @@ -138,7 +138,7 @@ #define SPI_WAITFOREOTx() SPIX_WAITFOREOTx(SPI_DEFAULT_INSTANCE) #define SPI_WAITFOREORx() SPIX_WAITFOREORx(SPI_DEFAULT_INSTANCE) #ifdef SPI_FLUSH -#error You must include spi-arch.h before spi.h for the CC2538 +#error You must include spi-arch-legacy.h before spi.h for the CC2538 #else #define SPI_FLUSH() SPIX_FLUSH(SPI_DEFAULT_INSTANCE) #endif @@ -215,7 +215,7 @@ void spix_cs_init(uint8_t port, uint8_t pin); /** @} */ -#endif /* SPI_ARCH_H_ */ +#endif /* SPI_ARCH_LEGACY_H_ */ /** * @} diff --git a/arch/cpu/cc2538/dev/spi.c b/arch/cpu/cc2538/dev/spi-legacy.c similarity index 99% rename from arch/cpu/cc2538/dev/spi.c rename to arch/cpu/cc2538/dev/spi-legacy.c index a0ced2dad..417886638 100644 --- a/arch/cpu/cc2538/dev/spi.c +++ b/arch/cpu/cc2538/dev/spi-legacy.c @@ -39,7 +39,7 @@ */ #include "contiki.h" #include "reg.h" -#include "spi-arch.h" +#include "dev/spi-arch-legacy.h" #include "sys/cc.h" #include "dev/ioc.h" #include "dev/sys-ctrl.h" diff --git a/arch/platform/zoul/dev/cc1200-zoul-arch.c b/arch/platform/zoul/dev/cc1200-zoul-arch.c index 1aff2ef40..fb60d1efc 100644 --- a/arch/platform/zoul/dev/cc1200-zoul-arch.c +++ b/arch/platform/zoul/dev/cc1200-zoul-arch.c @@ -46,7 +46,7 @@ #include "contiki-net.h" #include "dev/leds.h" #include "reg.h" -#include "spi-arch.h" +#include "dev/spi-arch-legacy.h" #include "dev/ioc.h" #include "dev/sys-ctrl.h" #include "dev/spi.h" diff --git a/arch/platform/zoul/dev/mmc-arch.c b/arch/platform/zoul/dev/mmc-arch.c index b2aff5a46..2896448b0 100644 --- a/arch/platform/zoul/dev/mmc-arch.c +++ b/arch/platform/zoul/dev/mmc-arch.c @@ -39,7 +39,7 @@ #include #include #include -#include "spi-arch.h" +#include "dev/spi-arch-legacy.h" #include "dev/ioc.h" #include "dev/gpio.h" #include "dev/spi.h" diff --git a/arch/platform/zoul/orion/enc28j60-arch-spi.c b/arch/platform/zoul/orion/enc28j60-arch-spi.c index 59e6e4260..e68452f89 100644 --- a/arch/platform/zoul/orion/enc28j60-arch-spi.c +++ b/arch/platform/zoul/orion/enc28j60-arch-spi.c @@ -43,7 +43,7 @@ * eth-gw SPI arch specifics */ /*---------------------------------------------------------------------------*/ -#include "spi-arch.h" +#include "dev/spi-arch-legacy.h" #include "spi.h" #include "dev/gpio.h" /*---------------------------------------------------------------------------*/ From f6f0c15421ae27eecf4b93d80b6d857ca730e5b8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:29:46 +0000 Subject: [PATCH 49/72] Rename macro and move to HAL --- .../srf06-cc26xx/launchpad/cc1310/board.h | 2 +- .../srf06-cc26xx/launchpad/cc1350/board.h | 2 +- .../srf06-cc26xx/launchpad/cc2650/board.h | 2 +- .../srf06-cc26xx/sensortag/cc1350/board.h | 2 +- .../srf06-cc26xx/sensortag/cc2650/board.h | 2 +- os/dev/spi-hal.h | 15 +++++++++++++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h index 81f820a13..41e929571 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h @@ -109,7 +109,7 @@ * Those values are not meant to be modified by the user * @{ */ -#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 +#define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 #define BOARD_IOID_FLASH_SCK IOID_10 #define BOARD_IOID_FLASH_MOSI IOID_9 diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h index 5831221bc..643d69e0b 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h @@ -109,7 +109,7 @@ * Those values are not meant to be modified by the user * @{ */ -#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 +#define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 #define BOARD_IOID_FLASH_SCK IOID_10 #define BOARD_IOID_FLASH_MOSI IOID_9 diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h index 7b2c40403..822e776b8 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h @@ -109,7 +109,7 @@ * Those values are not meant to be modified by the user * @{ */ -#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 +#define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 #define BOARD_IOID_FLASH_SCK IOID_10 #define BOARD_IOID_FLASH_MOSI IOID_9 diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h index bd1de7416..6fdab1295 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h @@ -135,7 +135,7 @@ * Those values are not meant to be modified by the user * @{ */ -#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 +#define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 #define BOARD_IOID_FLASH_SCK IOID_17 #define BOARD_IOID_FLASH_MOSI IOID_19 diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h index 7db109ece..7da0e9458 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h @@ -137,7 +137,7 @@ * Those values are not meant to be modified by the user * @{ */ -#define EXT_FLASH_SPI_CONTROLLER BOARD_SPI_CONTROLLER_SPI0 +#define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 #define BOARD_IOID_FLASH_SCK IOID_17 #define BOARD_IOID_FLASH_MOSI IOID_19 diff --git a/os/dev/spi-hal.h b/os/dev/spi-hal.h index 7bc5f20ee..b8172bd57 100644 --- a/os/dev/spi-hal.h +++ b/os/dev/spi-hal.h @@ -57,10 +57,21 @@ /* Include Arch-Specific conf */ #ifdef SPI_HAL_CONF_ARCH_HDR_PATH #include SPI_HAL_CONF_ARCH_HDR_PATH -#else /* PLATFORM_IMPLEMENTS_SPI_HAL */ -#define BOARD_SPI_CONTROLLERS 0 #endif /* SPI_HAL_CONF_ARCH_HDR_PATH */ /*---------------------------------------------------------------------------*/ +#ifdef SPI_CONF_CONTROLLER_COUNT +/** + * \brief Number of SPI module instances on a chip + */ +#define SPI_CONTROLLER_COUNT SPI_CONF_CONTROLLER_COUNT +#else +#define SPI_CONTROLLER_COUNT 0 +#endif +/*---------------------------------------------------------------------------*/ +/* Convenience macros to enumerate SPI module instances on a chip */ +#define SPI_CONTROLLER_SPI0 0 +#define SPI_CONTROLLER_SPI1 1 +/*---------------------------------------------------------------------------*/ /** * \brief SPI return codes * From 7160e1dbd2e61ef89ca93d1d6ab9a748b9e18f01 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:36:22 +0000 Subject: [PATCH 50/72] Change the way of configuring SPI controller count --- arch/cpu/cc2538/cc2538-def.h | 2 ++ arch/cpu/cc2538/dev/spi-hal-arch.c | 2 +- arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h | 2 ++ arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c | 4 ++-- os/dev/spi-hal.c | 22 +++++++++++----------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/arch/cpu/cc2538/cc2538-def.h b/arch/cpu/cc2538/cc2538-def.h index 32aed6111..e4c7451a6 100644 --- a/arch/cpu/cc2538/cc2538-def.h +++ b/arch/cpu/cc2538/cc2538-def.h @@ -58,6 +58,8 @@ #define TSCH_CONF_HW_FRAME_FILTERING 0 #endif /* MAC_CONF_WITH_TSCH */ /*---------------------------------------------------------------------------*/ +#define SPI_CONF_CONTROLLER_COUNT 2 +/*---------------------------------------------------------------------------*/ /* Path to CMSIS header */ #define CMSIS_CONF_HEADER_PATH "cc2538_cm3.h" diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.c b/arch/cpu/cc2538/dev/spi-hal-arch.c index 7b1469f0a..0c98ff35a 100644 --- a/arch/cpu/cc2538/dev/spi-hal-arch.c +++ b/arch/cpu/cc2538/dev/spi-hal-arch.c @@ -92,7 +92,7 @@ typedef struct spi_locks_s { } spi_locks_t; /* One lock per SPI controller */ -spi_locks_t board_spi_locks_spi[BOARD_SPI_CONTROLLERS] = { { MUTEX_STATUS_UNLOCKED, NULL } }; +spi_locks_t board_spi_locks_spi[SPI_CONTROLLER_COUNT] = { { MUTEX_STATUS_UNLOCKED, NULL } }; /*---------------------------------------------------------------------------*/ static void diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h index 7b914ac1e..15db03448 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h +++ b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h @@ -104,5 +104,7 @@ /*---------------------------------------------------------------------------*/ #define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0 /*---------------------------------------------------------------------------*/ +#define SPI_CONF_CONTROLLER_COUNT 2 +/*---------------------------------------------------------------------------*/ #endif /* CC13XX_CC26XX_DEF_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c index c67c0d484..89c3e1c7a 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c @@ -42,10 +42,10 @@ typedef struct spi_locks_s { } spi_locks_t; /* One lock per SPI controller */ -spi_locks_t board_spi_locks_spi[BOARD_SPI_CONTROLLERS] = { { MUTEX_STATUS_UNLOCKED, NULL } }; +spi_locks_t board_spi_locks_spi[SPI_CONTROLLER_COUNT] = { { MUTEX_STATUS_UNLOCKED, NULL } }; /* Arch-specific properties of each SPI controller */ -static const board_spi_controller_t spi_controller[BOARD_SPI_CONTROLLERS] = { +static const board_spi_controller_t spi_controller[SPI_CONTROLLER_COUNT] = { { .ssi_base = SSI0_BASE, .power_domain = PRCM_DOMAIN_SERIAL, diff --git a/os/dev/spi-hal.c b/os/dev/spi-hal.c index 532e9323f..f4810a97a 100644 --- a/os/dev/spi-hal.c +++ b/os/dev/spi-hal.c @@ -48,7 +48,7 @@ spi_acquire(spi_device_t *dev) { spi_status_t r; - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -67,7 +67,7 @@ spi_release(spi_device_t *dev) { spi_status_t r; - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -96,7 +96,7 @@ spi_deselect(spi_device_t *dev) bool spi_has_bus(spi_device_t *dev) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return false; } @@ -106,7 +106,7 @@ spi_has_bus(spi_device_t *dev) spi_status_t spi_write_byte(spi_device_t *dev, uint8_t data) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -120,7 +120,7 @@ spi_write_byte(spi_device_t *dev, uint8_t data) spi_status_t spi_write(spi_device_t *dev, const uint8_t *data, int size) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -134,7 +134,7 @@ spi_write(spi_device_t *dev, const uint8_t *data, int size) spi_status_t spi_read_byte(spi_device_t *dev, uint8_t *buf) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -148,7 +148,7 @@ spi_read_byte(spi_device_t *dev, uint8_t *buf) spi_status_t spi_read(spi_device_t *dev, uint8_t *buf, int size) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -162,7 +162,7 @@ spi_read(spi_device_t *dev, uint8_t *buf, int size) spi_status_t spi_read_skip(spi_device_t *dev, int size) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -178,7 +178,7 @@ spi_transfer(spi_device_t *dev, const uint8_t *wdata, int wsize, uint8_t *rbuf, int rsize, int ignore) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -201,7 +201,7 @@ spi_status_t spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) { spi_status_t status; - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -223,7 +223,7 @@ spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) spi_status_t spi_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } From 03c63bdd0fd7649bb5f172538d6ca64160d7edfe Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:37:00 +0000 Subject: [PATCH 51/72] Remove spi-hal-arch.h (CC13xx/CC26xx) --- arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c | 11 ++++- arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h | 51 ----------------------- arch/platform/srf06-cc26xx/contiki-conf.h | 3 -- 3 files changed, 9 insertions(+), 56 deletions(-) delete mode 100644 arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c index 89c3e1c7a..cab47d9fa 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c @@ -27,10 +27,9 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#include "contiki.h" #include "ti-lib.h" #include "spi-hal.h" -#include "spi-hal-arch.h" #include "sys/mutex.h" #include @@ -44,7 +43,15 @@ typedef struct spi_locks_s { /* One lock per SPI controller */ spi_locks_t board_spi_locks_spi[SPI_CONTROLLER_COUNT] = { { MUTEX_STATUS_UNLOCKED, NULL } }; +/*---------------------------------------------------------------------------*/ /* Arch-specific properties of each SPI controller */ +typedef struct board_spi_controller_s { + uint32_t ssi_base; + uint32_t power_domain; + uint32_t prcm_periph; + uint32_t ssi_clkgr_clk_en; +} board_spi_controller_t; + static const board_spi_controller_t spi_controller[SPI_CONTROLLER_COUNT] = { { .ssi_base = SSI0_BASE, diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h deleted file mode 100644 index afbe3e6c2..000000000 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2017, 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 HOLDER 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 SPI_ARCH_H_ -#define SPI_ARCH_H_ - -#include "ti-lib.h" - -#include - -/*---------------------------------------------------------------------------*/ -#define BOARD_SPI_CONTROLLERS 2 -/*---------------------------------------------------------------------------*/ -#define BOARD_SPI_CONTROLLER_SPI0 0 -#define BOARD_SPI_CONTROLLER_SPI1 1 -/*---------------------------------------------------------------------------*/ -typedef struct board_spi_controller_s { - uint32_t ssi_base; - uint32_t power_domain; - uint32_t prcm_periph; - uint32_t ssi_clkgr_clk_en; -} board_spi_controller_t; - -#endif /* SPI_ARCH_H_ */ diff --git a/arch/platform/srf06-cc26xx/contiki-conf.h b/arch/platform/srf06-cc26xx/contiki-conf.h index 82daed0c1..4a1470b40 100644 --- a/arch/platform/srf06-cc26xx/contiki-conf.h +++ b/arch/platform/srf06-cc26xx/contiki-conf.h @@ -72,9 +72,6 @@ /* Platform-specific define to signify sensor reading failure */ #define CC26XX_SENSOR_READING_ERROR 0x80000000 /*---------------------------------------------------------------------------*/ -/* SPI HAL: Path to arch-specific implementation */ -#define SPI_HAL_CONF_ARCH_HDR_PATH "dev/spi-hal-arch.h" -/*---------------------------------------------------------------------------*/ /* Include CPU-related configuration */ #include "cc13xx-cc26xx-conf.h" /*---------------------------------------------------------------------------*/ From 34df610fccf08e3f2e37d7223ac331411921d3d9 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:45:52 +0000 Subject: [PATCH 52/72] Remove spi-hal-arch.h (CC2538) --- arch/cpu/cc2538/cc2538-conf.h | 3 -- arch/cpu/cc2538/dev/spi-hal-arch.c | 34 +++++++++--- arch/cpu/cc2538/dev/spi-hal-arch.h | 86 ------------------------------ 3 files changed, 27 insertions(+), 96 deletions(-) delete mode 100644 arch/cpu/cc2538/dev/spi-hal-arch.h diff --git a/arch/cpu/cc2538/cc2538-conf.h b/arch/cpu/cc2538/cc2538-conf.h index b0f2ace0c..725f95439 100644 --- a/arch/cpu/cc2538/cc2538-conf.h +++ b/arch/cpu/cc2538/cc2538-conf.h @@ -325,9 +325,6 @@ #endif /** @} */ /*---------------------------------------------------------------------------*/ -/* SPI HAL: Path to arch-specific implementation */ -#define SPI_HAL_CONF_ARCH_HDR_PATH "dev/spi-hal-arch.h" -/*---------------------------------------------------------------------------*/ #endif /* CC2538_CONF_H_ */ /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.c b/arch/cpu/cc2538/dev/spi-hal-arch.c index 0c98ff35a..3493af509 100644 --- a/arch/cpu/cc2538/dev/spi-hal-arch.c +++ b/arch/cpu/cc2538/dev/spi-hal-arch.c @@ -33,7 +33,6 @@ #include "contiki.h" #include "reg.h" #include "spi-hal.h" -#include "spi-hal-arch.h" #include "gpio-hal-arch.h" #include "sys/cc.h" #include "ioc.h" @@ -48,13 +47,34 @@ #define LOG_MODULE "spi-hal-arch" #define LOG_LEVEL LOG_LEVEL_NONE /*---------------------------------------------------------------------------*/ -#if (SPI0_CPRS_CPSDVSR & 1) == 1 || SPI0_CPRS_CPSDVSR < 2 || SPI0_CPRS_CPSDVSR > 254 -#error SPI0_CPRS_CPSDVSR must be an even number between 2 and 254 +/* Default values for the clock rate divider */ +#ifdef SPI_ARCH_CONF_SPI0_CPRS_CPSDVSR +#define SPI_ARCH_SPI0_CPRS_CPSDVSR SPI_ARCH_CONF_SPI0_CPRS_CPSDVSR +#else +#define SPI_ARCH_SPI0_CPRS_CPSDVSR 2 #endif -#if (SPI1_CPRS_CPSDVSR & 1) == 1 || SPI1_CPRS_CPSDVSR < 2 || SPI1_CPRS_CPSDVSR > 254 -#error SPI1_CPRS_CPSDVSR must be an even number between 2 and 254 +#ifdef SPI_ARCH_CONF_SPI1_CPRS_CPSDVSR +#define SPI_ARCH_SPI1_CPRS_CPSDVSR SPI_ARCH_CONF_SPI1_CPRS_CPSDVSR +#else +#define SPI_ARCH_SPI1_CPRS_CPSDVSR 2 #endif + +#if (SPI_ARCH_SPI0_CPRS_CPSDVSR & 1) == 1 || \ + SPI_ARCH_SPI0_CPRS_CPSDVSR < 2 || \ + SPI_ARCH_SPI0_CPRS_CPSDVSR > 254 +#error SPI_ARCH_SPI0_CPRS_CPSDVSR must be an even number between 2 and 254 +#endif + +#if (SPI_ARCH_SPI1_CPRS_CPSDVSR & 1) == 1 || \ + SPI_ARCH_SPI1_CPRS_CPSDVSR < 2 || \ + SPI_ARCH_SPI1_CPRS_CPSDVSR > 254 +#error SPI_ARCH_SPI1_CPRS_CPSDVSR must be an even number between 2 and 254 +#endif +/*---------------------------------------------------------------------------*/ +/* CS set and clear macros */ +#define SPIX_CS_CLR(port, pin) GPIO_CLR_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin)) +#define SPIX_CS_SET(port, pin) GPIO_SET_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin)) /*---------------------------------------------------------------------------*/ /* * Clock source from which the baud clock is determined for the SSI, according @@ -76,13 +96,13 @@ static const spi_regs_t spi_regs[SSI_INSTANCE_COUNT] = { .ioc_ssirxd_ssi = IOC_SSIRXD_SSI0, .ioc_pxx_sel_ssi_clkout = IOC_PXX_SEL_SSI0_CLKOUT, .ioc_pxx_sel_ssi_txd = IOC_PXX_SEL_SSI0_TXD, - .ssi_cprs_cpsdvsr = SPI0_CPRS_CPSDVSR, + .ssi_cprs_cpsdvsr = SPI_ARCH_SPI0_CPRS_CPSDVSR, }, { .base = SSI1_BASE, .ioc_ssirxd_ssi = IOC_SSIRXD_SSI1, .ioc_pxx_sel_ssi_clkout = IOC_PXX_SEL_SSI1_CLKOUT, .ioc_pxx_sel_ssi_txd = IOC_PXX_SEL_SSI1_TXD, - .ssi_cprs_cpsdvsr = SPI1_CPRS_CPSDVSR, + .ssi_cprs_cpsdvsr = SPI_ARCH_SPI1_CPRS_CPSDVSR, } }; diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.h b/arch/cpu/cc2538/dev/spi-hal-arch.h deleted file mode 100644 index 876e27af4..000000000 --- a/arch/cpu/cc2538/dev/spi-hal-arch.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2013, University of Michigan. - * - * Copyright (c) 2015, Weptech elektronik GmbH - * Author: Ulf Knoblich, ulf.knoblich@weptech.de - * - * Copyright (c) 2018, University of Bristol. - * - * 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 University 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. - */ -/*---------------------------------------------------------------------------*/ -#ifndef SPI_ARCH_H_ -#define SPI_ARCH_H_ -/*---------------------------------------------------------------------------*/ -#include "contiki.h" -/*---------------------------------------------------------------------------*/ -#define BOARD_SPI_CONTROLLERS 2 -/*---------------------------------------------------------------------------*/ -#define BOARD_SPI_CONTROLLER_SPI0 0 -#define BOARD_SPI_CONTROLLER_SPI1 1 -/*---------------------------------------------------------------------------*/ -/* Default values for the clock rate divider */ -#ifdef SPI0_CONF_CPRS_CPSDVSR -#define SPI0_CPRS_CPSDVSR SPI0_CONF_CPRS_CPSDVSR -#else -#define SPI0_CPRS_CPSDVSR 2 -#endif - -#ifdef SPI1_CONF_CPRS_CPSDVSR -#define SPI1_CPRS_CPSDVSR SPI1_CONF_CPRS_CPSDVSR -#else -#define SPI1_CPRS_CPSDVSR 2 -#endif -/*---------------------------------------------------------------------------*/ -/* New API macros */ -#define SPIX_WAITFORTxREADY(spi) do { \ - while(!(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_TNF)) ; \ -} while(0) -#define SPIX_BUF(spi) REG(SSI_BASE(spi) + SSI_DR) -#define SPIX_WAITFOREOTx(spi) do { \ - while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_BSY) ; \ -} while(0) -#define SPIX_WAITFOREORx(spi) do { \ - while(!(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE)) ; \ -} while(0) -#define SPIX_FLUSH(spi) do { \ - while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE) { \ - SPIX_BUF(spi); \ - } \ -} while(0) -#define SPIX_CS_CLR(port, pin) do { \ - GPIO_CLR_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin)); \ -} while(0) -#define SPIX_CS_SET(port, pin) do { \ - GPIO_SET_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin)); \ -} while(0) - -#endif /* SPI_ARCH_H_ */ - -/** - * @} - */ From 448ee8ae9636891f6cb02d698fc0a3a006458fe8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:58:20 +0000 Subject: [PATCH 53/72] Rename arch-specific SPI HAL implementations --- arch/cpu/cc2538/Makefile.cc2538 | 2 +- arch/cpu/cc2538/dev/{spi-hal-arch.c => spi-arch.c} | 0 arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx | 2 +- arch/cpu/cc26xx-cc13xx/dev/{spi-hal-arch.c => spi-arch.c} | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename arch/cpu/cc2538/dev/{spi-hal-arch.c => spi-arch.c} (100%) rename arch/cpu/cc26xx-cc13xx/dev/{spi-hal-arch.c => spi-arch.c} (100%) diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index 9d61c2f9a..891215093 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -16,7 +16,7 @@ CONTIKI_CPU_DIRS = . dev usb usb/common usb/common/cdc-acm ### CPU-dependent source files CONTIKI_CPU_SOURCEFILES += soc.c clock.c rtimer-arch.c uart.c watchdog.c CONTIKI_CPU_SOURCEFILES += nvic.c sys-ctrl.c gpio.c ioc.c spi-legacy.c adc.c -CONTIKI_CPU_SOURCEFILES += spi-hal-arch.c +CONTIKI_CPU_SOURCEFILES += spi-arch.c CONTIKI_CPU_SOURCEFILES += crypto.c aes.c ecb.c cbc.c ctr.c cbc-mac.c gcm.c CONTIKI_CPU_SOURCEFILES += ccm.c sha256.c gpio-hal-arch.c CONTIKI_CPU_SOURCEFILES += cc2538-aes-128.c cc2538-ccm-star.c diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.c b/arch/cpu/cc2538/dev/spi-arch.c similarity index 100% rename from arch/cpu/cc2538/dev/spi-hal-arch.c rename to arch/cpu/cc2538/dev/spi-arch.c diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index aacc98b62..e72954c17 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -36,7 +36,7 @@ CONTIKI_CPU_SOURCEFILES += gpio-interrupt.c gpio-hal-arch.c oscillators.c CONTIKI_CPU_SOURCEFILES += rf-core.c rf-ble.c ieee-mode.c CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c -CONTIKI_CPU_SOURCEFILES += spi-hal-arch.c +CONTIKI_CPU_SOURCEFILES += spi-arch.c MODULES += os/lib/dbg-io diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c similarity index 100% rename from arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c rename to arch/cpu/cc26xx-cc13xx/dev/spi-arch.c From ee4e287fc5d3e34bb5e1f97c880af111ecd30340 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 20:17:46 +0000 Subject: [PATCH 54/72] Rename old SPI API to -legacy.h --- arch/cpu/cc2538/dev/spi-arch-legacy.h | 2 +- arch/cpu/cc2538/dev/spi-arch.c | 1 - arch/cpu/cc2538/dev/spi-legacy.c | 2 +- arch/cpu/msp430/cc2420-arch-sfd.c | 2 +- arch/cpu/msp430/cc2420-arch.c | 2 +- arch/cpu/msp430/cc2520-arch-sfd.c | 2 +- arch/cpu/msp430/cc2520-arch.c | 2 +- arch/dev/cc2420/cc2420.c | 2 +- arch/dev/cc2420/cc2420.h | 2 +- arch/platform/sky/dev/i2c.c | 2 +- arch/platform/sky/dev/xmem.c | 2 +- arch/platform/zoul/dev/cc1200-zoul-arch.c | 2 +- arch/platform/zoul/dev/mmc-arch.c | 2 +- arch/platform/zoul/orion/enc28j60-arch-spi.c | 2 +- os/dev/{spi.h => spi-legacy.h} | 6 +++--- 15 files changed, 16 insertions(+), 17 deletions(-) rename os/dev/{spi.h => spi-legacy.h} (97%) diff --git a/arch/cpu/cc2538/dev/spi-arch-legacy.h b/arch/cpu/cc2538/dev/spi-arch-legacy.h index 0204baefa..de7a765bb 100644 --- a/arch/cpu/cc2538/dev/spi-arch-legacy.h +++ b/arch/cpu/cc2538/dev/spi-arch-legacy.h @@ -138,7 +138,7 @@ #define SPI_WAITFOREOTx() SPIX_WAITFOREOTx(SPI_DEFAULT_INSTANCE) #define SPI_WAITFOREORx() SPIX_WAITFOREORx(SPI_DEFAULT_INSTANCE) #ifdef SPI_FLUSH -#error You must include spi-arch-legacy.h before spi.h for the CC2538 +#error You must include spi-arch-legacy.h before spi-legacy.h for the CC2538 #else #define SPI_FLUSH() SPIX_FLUSH(SPI_DEFAULT_INSTANCE) #endif diff --git a/arch/cpu/cc2538/dev/spi-arch.c b/arch/cpu/cc2538/dev/spi-arch.c index 3493af509..49563e15e 100644 --- a/arch/cpu/cc2538/dev/spi-arch.c +++ b/arch/cpu/cc2538/dev/spi-arch.c @@ -37,7 +37,6 @@ #include "sys/cc.h" #include "ioc.h" #include "sys-ctrl.h" -#include "spi.h" #include "ssi.h" #include "gpio.h" #include "sys/log.h" diff --git a/arch/cpu/cc2538/dev/spi-legacy.c b/arch/cpu/cc2538/dev/spi-legacy.c index 417886638..0070df6ef 100644 --- a/arch/cpu/cc2538/dev/spi-legacy.c +++ b/arch/cpu/cc2538/dev/spi-legacy.c @@ -43,7 +43,7 @@ #include "sys/cc.h" #include "dev/ioc.h" #include "dev/sys-ctrl.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "dev/ssi.h" #include "dev/gpio.h" /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/msp430/cc2420-arch-sfd.c b/arch/cpu/msp430/cc2420-arch-sfd.c index 6ab9a1365..d1db81ce0 100644 --- a/arch/cpu/msp430/cc2420-arch-sfd.c +++ b/arch/cpu/msp430/cc2420-arch-sfd.c @@ -29,7 +29,7 @@ */ #include "contiki.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "cc2420.h" #include "isr_compat.h" diff --git a/arch/cpu/msp430/cc2420-arch.c b/arch/cpu/msp430/cc2420-arch.c index 8a6f0234d..c35ce949f 100644 --- a/arch/cpu/msp430/cc2420-arch.c +++ b/arch/cpu/msp430/cc2420-arch.c @@ -31,7 +31,7 @@ #include "contiki.h" #include "contiki-net.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "cc2420.h" #include "isr_compat.h" diff --git a/arch/cpu/msp430/cc2520-arch-sfd.c b/arch/cpu/msp430/cc2520-arch-sfd.c index e2671ca58..dc0561f94 100644 --- a/arch/cpu/msp430/cc2520-arch-sfd.c +++ b/arch/cpu/msp430/cc2520-arch-sfd.c @@ -28,7 +28,7 @@ */ #include "contiki.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "dev/cc2520/cc2520.h" #include "isr_compat.h" diff --git a/arch/cpu/msp430/cc2520-arch.c b/arch/cpu/msp430/cc2520-arch.c index 855f8bc7e..e63735271 100644 --- a/arch/cpu/msp430/cc2520-arch.c +++ b/arch/cpu/msp430/cc2520-arch.c @@ -30,7 +30,7 @@ #include "contiki.h" #include "contiki-net.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "dev/cc2520/cc2520.h" #include "isr_compat.h" diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index 00ec64675..9310ec9e4 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -39,7 +39,7 @@ #include "sys/energest.h" #include "dev/leds.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "cc2420.h" #include "cc2420_const.h" diff --git a/arch/dev/cc2420/cc2420.h b/arch/dev/cc2420/cc2420.h index 74b641ad6..a030632a6 100644 --- a/arch/dev/cc2420/cc2420.h +++ b/arch/dev/cc2420/cc2420.h @@ -43,7 +43,7 @@ #define CC2420_H_ #include "contiki.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "dev/radio.h" #include "cc2420_const.h" #include "lib/aes-128.h" diff --git a/arch/platform/sky/dev/i2c.c b/arch/platform/sky/dev/i2c.c index b9d10a9c7..1acbe897a 100644 --- a/arch/platform/sky/dev/i2c.c +++ b/arch/platform/sky/dev/i2c.c @@ -41,7 +41,7 @@ #include #include -#include +#include "dev/spi-legacy.h" #include #include "dev/i2c.h" diff --git a/arch/platform/sky/dev/xmem.c b/arch/platform/sky/dev/xmem.c index 21814ad04..4ff525bb8 100644 --- a/arch/platform/sky/dev/xmem.c +++ b/arch/platform/sky/dev/xmem.c @@ -43,7 +43,7 @@ #include #include -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "dev/xmem.h" #include "dev/watchdog.h" diff --git a/arch/platform/zoul/dev/cc1200-zoul-arch.c b/arch/platform/zoul/dev/cc1200-zoul-arch.c index fb60d1efc..8c9d8cdd7 100644 --- a/arch/platform/zoul/dev/cc1200-zoul-arch.c +++ b/arch/platform/zoul/dev/cc1200-zoul-arch.c @@ -49,7 +49,7 @@ #include "dev/spi-arch-legacy.h" #include "dev/ioc.h" #include "dev/sys-ctrl.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "dev/ssi.h" #include "dev/gpio.h" #include "dev/gpio-hal.h" diff --git a/arch/platform/zoul/dev/mmc-arch.c b/arch/platform/zoul/dev/mmc-arch.c index 2896448b0..f1eca8d32 100644 --- a/arch/platform/zoul/dev/mmc-arch.c +++ b/arch/platform/zoul/dev/mmc-arch.c @@ -42,7 +42,7 @@ #include "dev/spi-arch-legacy.h" #include "dev/ioc.h" #include "dev/gpio.h" -#include "dev/spi.h" +#include "dev/spi-legacy.h" #include "mmc-arch.h" #define USD_SEL_PORT_BASE GPIO_PORT_TO_BASE(USD_SEL_PORT) diff --git a/arch/platform/zoul/orion/enc28j60-arch-spi.c b/arch/platform/zoul/orion/enc28j60-arch-spi.c index e68452f89..bc9c9dadd 100644 --- a/arch/platform/zoul/orion/enc28j60-arch-spi.c +++ b/arch/platform/zoul/orion/enc28j60-arch-spi.c @@ -44,7 +44,7 @@ */ /*---------------------------------------------------------------------------*/ #include "dev/spi-arch-legacy.h" -#include "spi.h" +#include "dev/spi-legacy.h" #include "dev/gpio.h" /*---------------------------------------------------------------------------*/ #define RESET_PORT GPIO_PORT_TO_BASE(ETH_RESET_PORT) diff --git a/os/dev/spi.h b/os/dev/spi-legacy.h similarity index 97% rename from os/dev/spi.h rename to os/dev/spi-legacy.h index 5960c411b..d1600c785 100644 --- a/os/dev/spi.h +++ b/os/dev/spi-legacy.h @@ -36,8 +36,8 @@ * Niclas Finne */ -#ifndef SPI_H_ -#define SPI_H_ +#ifndef SPI_LEGACY_H_ +#define SPI_LEGACY_H_ /* Define macros to use for checking SPI transmission status depending on if it is possible to wait for TX buffer ready. This is possible @@ -89,4 +89,4 @@ void spi_init(void); } while(0) #endif -#endif /* SPI_H_ */ +#endif /* SPI_LEGACY_H_ */ From 8ea998847ba4537acaa2c7f851962ea30e3f5958 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 20:22:30 +0000 Subject: [PATCH 55/72] Rename old msp430/sky SPI driver --- arch/cpu/msp430/f1xxx/{spi.c => spi-legacy.c} | 0 arch/cpu/msp430/f2xxx/{spi.c => spi-legacy.c} | 0 arch/cpu/msp430/f5xxx/{spi.c => spi-legacy.c} | 0 arch/platform/sky/Makefile.common | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename arch/cpu/msp430/f1xxx/{spi.c => spi-legacy.c} (100%) rename arch/cpu/msp430/f2xxx/{spi.c => spi-legacy.c} (100%) rename arch/cpu/msp430/f5xxx/{spi.c => spi-legacy.c} (100%) diff --git a/arch/cpu/msp430/f1xxx/spi.c b/arch/cpu/msp430/f1xxx/spi-legacy.c similarity index 100% rename from arch/cpu/msp430/f1xxx/spi.c rename to arch/cpu/msp430/f1xxx/spi-legacy.c diff --git a/arch/cpu/msp430/f2xxx/spi.c b/arch/cpu/msp430/f2xxx/spi-legacy.c similarity index 100% rename from arch/cpu/msp430/f2xxx/spi.c rename to arch/cpu/msp430/f2xxx/spi-legacy.c diff --git a/arch/cpu/msp430/f5xxx/spi.c b/arch/cpu/msp430/f5xxx/spi-legacy.c similarity index 100% rename from arch/cpu/msp430/f5xxx/spi.c rename to arch/cpu/msp430/f5xxx/spi-legacy.c diff --git a/arch/platform/sky/Makefile.common b/arch/platform/sky/Makefile.common index 1dea28846..081ffaa9f 100644 --- a/arch/platform/sky/Makefile.common +++ b/arch/platform/sky/Makefile.common @@ -1,6 +1,6 @@ # $Id: Makefile.common,v 1.3 2010/08/24 16:24:11 joxe Exp $ -ARCH=spi.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \ +ARCH=spi-legacy.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \ cc2420.c cc2420-arch.c cc2420-arch-sfd.c \ sky-sensors.c uip-ipchksum.c \ uart1.c slip_uart1.c uart1-putchar.c platform.c From 2cad6263608bd904153c1a0879480b34bf6c52e0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 20:37:28 +0000 Subject: [PATCH 56/72] Rename new SPI API to spi.[ch] --- arch/cpu/cc2538/dev/spi-arch.c | 2 +- arch/cpu/cc26xx-cc13xx/dev/spi-arch.c | 2 +- os/dev/ext-flash.c | 2 +- os/dev/ext-flash.h | 3 +-- os/dev/{spi-hal.c => spi.c} | 3 +-- os/dev/{spi-hal.h => spi.h} | 6 +++--- 6 files changed, 8 insertions(+), 10 deletions(-) rename os/dev/{spi-hal.c => spi.c} (99%) rename os/dev/{spi-hal.h => spi.h} (99%) diff --git a/arch/cpu/cc2538/dev/spi-arch.c b/arch/cpu/cc2538/dev/spi-arch.c index 49563e15e..5dc44524a 100644 --- a/arch/cpu/cc2538/dev/spi-arch.c +++ b/arch/cpu/cc2538/dev/spi-arch.c @@ -32,7 +32,7 @@ #include #include "contiki.h" #include "reg.h" -#include "spi-hal.h" +#include "dev/spi.h" #include "gpio-hal-arch.h" #include "sys/cc.h" #include "ioc.h" diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c index cab47d9fa..bda3abbe2 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c @@ -29,7 +29,7 @@ */ #include "contiki.h" #include "ti-lib.h" -#include "spi-hal.h" +#include "dev/spi.h" #include "sys/mutex.h" #include diff --git a/os/dev/ext-flash.c b/os/dev/ext-flash.c index b1f428e11..7a0e6735b 100644 --- a/os/dev/ext-flash.c +++ b/os/dev/ext-flash.c @@ -38,7 +38,7 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "ext-flash.h" -#include "spi-hal.h" +#include "dev/spi.h" #include "gpio-hal.h" #include "sys/log.h" diff --git a/os/dev/ext-flash.h b/os/dev/ext-flash.h index a14ccdbf0..14017ab46 100644 --- a/os/dev/ext-flash.h +++ b/os/dev/ext-flash.h @@ -42,8 +42,7 @@ #ifndef EXT_FLASH_H_ #define EXT_FLASH_H_ /*---------------------------------------------------------------------------*/ -#include "spi-hal.h" - +#include "dev/spi.h" #include #include #include diff --git a/os/dev/spi-hal.c b/os/dev/spi.c similarity index 99% rename from os/dev/spi-hal.c rename to os/dev/spi.c index f4810a97a..d1d678a18 100644 --- a/os/dev/spi-hal.c +++ b/os/dev/spi.c @@ -37,9 +37,8 @@ * Implementation of the platform-independent aspects of the SPI HAL */ /*---------------------------------------------------------------------------*/ +#include #include "contiki.h" -#include "spi-hal.h" - #include #include /*---------------------------------------------------------------------------*/ diff --git a/os/dev/spi-hal.h b/os/dev/spi.h similarity index 99% rename from os/dev/spi-hal.h rename to os/dev/spi.h index b8172bd57..95d079263 100644 --- a/os/dev/spi-hal.h +++ b/os/dev/spi.h @@ -45,8 +45,8 @@ * Header file for the SPI HAL */ /*---------------------------------------------------------------------------*/ -#ifndef SPI_HAL_H_ -#define SPI_HAL_H_ +#ifndef SPI_H_ +#define SPI_H_ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "gpio-hal.h" @@ -358,7 +358,7 @@ spi_status_t spi_arch_select(spi_device_t *dev); */ spi_status_t spi_arch_deselect(spi_device_t *dev); -#endif /* SPI_HAL_H_ */ +#endif /* SPI_H_ */ /*---------------------------------------------------------------------------*/ /** * @} From d7baa54bd03f5d8fab99da467d953767650c542c Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Tue, 3 Apr 2018 12:58:47 +0100 Subject: [PATCH 57/72] SPI HAL API: lock()/open() and close()/unlock() merged --- arch/cpu/cc2538/dev/spi-arch.c | 40 ++++++++------------------- arch/cpu/cc26xx-cc13xx/dev/spi-arch.c | 40 ++++++++------------------- os/dev/spi.c | 24 +++------------- os/dev/spi.h | 29 ++++--------------- 4 files changed, 32 insertions(+), 101 deletions(-) diff --git a/arch/cpu/cc2538/dev/spi-arch.c b/arch/cpu/cc2538/dev/spi-arch.c index 5dc44524a..5c554e7e7 100644 --- a/arch/cpu/cc2538/dev/spi-arch.c +++ b/arch/cpu/cc2538/dev/spi-arch.c @@ -147,18 +147,6 @@ spix_wait_eorx(spi_device_t *dev) while(!(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_RNE)); } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_lock(spi_device_t *dev) -{ - if(mutex_try_lock(&board_spi_locks_spi[dev->spi_controller].lock) == false) { - return SPI_DEV_STATUS_BUS_LOCKED; - } - - board_spi_locks_spi[dev->spi_controller].owner = dev; - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ bool spi_arch_has_lock(spi_device_t *dev) { @@ -180,20 +168,7 @@ spi_arch_is_bus_locked(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_unlock(spi_device_t *dev) -{ - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - board_spi_locks_spi[dev->spi_controller].owner = NULL; - mutex_unlock(&board_spi_locks_spi[dev->spi_controller].lock); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_open(spi_device_t *dev) +spi_arch_lock_and_open(spi_device_t *dev) { const spi_regs_t *regs; uint32_t scr; @@ -213,10 +188,13 @@ spi_arch_open(spi_device_t *dev) uint32_t mode = 0; - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; + /* lock the SPI bus */ + if(mutex_try_lock(&board_spi_locks_spi[dev->spi_controller].lock) == false) { + return SPI_DEV_STATUS_BUS_LOCKED; } + board_spi_locks_spi[dev->spi_controller].owner = dev; + /* Set SPI phase */ if(dev->spi_pha != 0) { mode = mode | SSI_CR0_SPH; @@ -287,7 +265,7 @@ spi_arch_open(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_close(spi_device_t *dev) +spi_arch_close_and_unlock(spi_device_t *dev) { if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_NOT_OWNED; @@ -296,6 +274,10 @@ spi_arch_close(spi_device_t *dev) /* Disable SSI */ REG(SYS_CTRL_RCGCSSI) &= ~(1 << dev->spi_controller); + /* Unlock the SPI bus */ + board_spi_locks_spi[dev->spi_controller].owner = NULL; + mutex_unlock(&board_spi_locks_spi[dev->spi_controller].lock); + return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c index bda3abbe2..d274a1d52 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c @@ -67,18 +67,6 @@ static const board_spi_controller_t spi_controller[SPI_CONTROLLER_COUNT] = { } }; /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_lock(spi_device_t *dev) -{ - if(mutex_try_lock(&board_spi_locks_spi[dev->spi_controller].lock) == false) { - return SPI_DEV_STATUS_BUS_LOCKED; - } - - board_spi_locks_spi[dev->spi_controller].owner = dev; - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ bool spi_arch_has_lock(spi_device_t *dev) { @@ -99,19 +87,6 @@ spi_arch_is_bus_locked(spi_device_t *dev) return false; } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_unlock(spi_device_t *dev) -{ - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - board_spi_locks_spi[dev->spi_controller].owner = NULL; - mutex_unlock(&board_spi_locks_spi[dev->spi_controller].lock); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ static uint32_t get_mode(spi_device_t *dev) { @@ -128,14 +103,17 @@ get_mode(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_open(spi_device_t *dev) +spi_arch_lock_and_open(spi_device_t *dev) { uint32_t c; - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; + /* Lock the SPI bus */ + if(mutex_try_lock(&board_spi_locks_spi[dev->spi_controller].lock) == false) { + return SPI_DEV_STATUS_BUS_LOCKED; } + board_spi_locks_spi[dev->spi_controller].owner = dev; + /* CS pin configuration */ ti_lib_ioc_pin_type_gpio_output(dev->pin_spi_cs); @@ -166,7 +144,7 @@ spi_arch_open(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_close(spi_device_t *dev) +spi_arch_close_and_unlock(spi_device_t *dev) { if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_NOT_OWNED; @@ -187,6 +165,10 @@ spi_arch_close(spi_device_t *dev) ti_lib_ioc_pin_type_gpio_input(dev->pin_spi_sck); ti_lib_ioc_io_port_pull_set(dev->pin_spi_sck, IOC_IOPULL_DOWN); + /* Unlock the SPI bus */ + board_spi_locks_spi[dev->spi_controller].owner = NULL; + mutex_unlock(&board_spi_locks_spi[dev->spi_controller].lock); + return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ diff --git a/os/dev/spi.c b/os/dev/spi.c index d1d678a18..c41cf206f 100644 --- a/os/dev/spi.c +++ b/os/dev/spi.c @@ -45,39 +45,23 @@ spi_status_t spi_acquire(spi_device_t *dev) { - spi_status_t r; - if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } - /* lock the bus */ - r = spi_arch_lock(dev); - if(r != SPI_DEV_STATUS_OK) { - return r; - } - - /* open the bus */ - return spi_arch_open(dev); + /* lock and open the bus */ + return spi_arch_lock_and_open(dev); } /*---------------------------------------------------------------------------*/ spi_status_t spi_release(spi_device_t *dev) { - spi_status_t r; - if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } - /* unlock the bus */ - r = spi_arch_close(dev); - if(r != SPI_DEV_STATUS_OK) { - return r; - } - - /* unlock the bus */ - return spi_arch_unlock(dev); + /* close and unlock the bus */ + return spi_arch_close_and_unlock(dev); } /*---------------------------------------------------------------------------*/ spi_status_t diff --git a/os/dev/spi.h b/os/dev/spi.h index 95d079263..0c9aadc73 100644 --- a/os/dev/spi.h +++ b/os/dev/spi.h @@ -258,24 +258,6 @@ spi_status_t spi_read_register(spi_device_t *dev, uint8_t reg, /* These are architecture-specific functions to be implemented by each CPU. */ /*---------------------------------------------------------------------------*/ -/** - * \brief Locks an SPI controller to device dev. - * \param dev An SPI device configuration which defines the controller - * to be locked and the device that locks it. - * \return SPI return code - * - */ -spi_status_t spi_arch_lock(spi_device_t *dev); - -/** - * \brief Unlocks an SPI controller. - * \param dev An SPI device configuration which defines the controller - * to be unlocked and the device that unlocks it. - * \return SPI return code - * - */ -spi_status_t spi_arch_unlock(spi_device_t *dev); - /** * \brief Checks if a device has locked an SPI controller * \param dev An SPI device configuration which defines the controller @@ -295,7 +277,7 @@ bool spi_arch_has_lock(spi_device_t *dev); bool spi_arch_is_bus_locked(spi_device_t *dev); /** - * \brief Opens an SPI controller to the configuration specified. + * \brief Locks and opens an SPI controller to the configuration specified. * \param dev An SPI device configuration. * \return SPI return code * @@ -303,19 +285,20 @@ bool spi_arch_is_bus_locked(spi_device_t *dev); * controller. * */ -spi_status_t spi_arch_open(spi_device_t *dev); +spi_status_t spi_arch_lock_and_open(spi_device_t *dev); /** - * \brief Closes an SPI controller + * \brief Closes and unlocks an SPI controller * \param dev An SPI device configuration that specifies the controller. * \return SPI return code * - * This should turn off the SPI controller to put it in low power mode. + * This should turn off the SPI controller to put it in low power mode + * and unlock it. * It should work only if the device has already locked the SPI * controller. * */ -spi_status_t spi_arch_close(spi_device_t *dev); +spi_status_t spi_arch_close_and_unlock(spi_device_t *dev); /** * \brief Performs an SPI transfer From 1c335e9faacef063f2c48739bb51e509a19e350e Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Tue, 3 Apr 2018 13:00:23 +0100 Subject: [PATCH 58/72] fix logging error --- arch/cpu/cc2538/dev/spi-arch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/cpu/cc2538/dev/spi-arch.c b/arch/cpu/cc2538/dev/spi-arch.c index 5c554e7e7..c876e4ed7 100644 --- a/arch/cpu/cc2538/dev/spi-arch.c +++ b/arch/cpu/cc2538/dev/spi-arch.c @@ -332,23 +332,23 @@ spi_arch_transfer(spi_device_t *dev, return SPI_DEV_STATUS_OK; } - LOG_DBG("%c%c%c: %u ", rlen > 0 ? 'R' : '-', wlen > 0 ? 'W' : '-', + LOG_DBG_("%c%c%c: %u ", rlen > 0 ? 'R' : '-', wlen > 0 ? 'W' : '-', ignore_len > 0 ? 'S' : '-', totlen); for(i = 0; i < totlen; i++) { spix_wait_tx_ready(dev); c = i < wlen ? write_buf[i] : 0; spix_write_buf(dev, c); - LOG_DBG("%c%02x->", i < rlen ? ' ' : '#', c); + LOG_DBG_("%c%02x->", i < rlen ? ' ' : '#', c); spix_wait_eotx(dev); spix_wait_eorx(dev); c = spix_read_buf(dev); if(i < rlen) { inbuf[i] = c; } - LOG_DBG("%02x", c); + LOG_DBG_("%02x", c); } - LOG_DBG("\n"); + LOG_DBG_("\n"); return SPI_DEV_STATUS_OK; } From b4b6ab1bdfadfce01952a038309a87419886ca68 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 4 Apr 2018 11:08:18 +0100 Subject: [PATCH 59/72] improvements in ext-flash driver --- os/dev/ext-flash.c | 167 +++++++++++++++++++++++++-------------------- os/dev/ext-flash.h | 22 +++--- 2 files changed, 105 insertions(+), 84 deletions(-) diff --git a/os/dev/ext-flash.c b/os/dev/ext-flash.c index 7a0e6735b..2d84cbdd7 100644 --- a/os/dev/ext-flash.c +++ b/os/dev/ext-flash.c @@ -109,13 +109,22 @@ static spi_device_t flash_spi_configuration_default = { .spi_pha = 0, .spi_pol = 0 }; - -static spi_device_t *flash_spi_configuration; +/*---------------------------------------------------------------------------*/ +/** + * Get spi configuration, return default configuration if NULL + */ +static spi_device_t* +get_spi_conf(spi_device_t *conf) { + if(conf == NULL) { + return &flash_spi_configuration_default; + } + return conf; +}/*---------------------------------------------------------------------------*/ /** * Clear external flash CSN line */ static bool -select_on_bus(void) +select_on_bus(spi_device_t *flash_spi_configuration) { if(spi_select(flash_spi_configuration) == SPI_DEV_STATUS_OK) { return true; @@ -127,7 +136,7 @@ select_on_bus(void) * Set external flash CSN line */ static void -deselect(void) +deselect(spi_device_t *flash_spi_configuration) { spi_deselect(flash_spi_configuration); } @@ -137,19 +146,19 @@ deselect(void) * \return True when successful. */ static bool -wait_ready(void) +wait_ready(spi_device_t *flash_spi_configuration) { bool ret; const uint8_t wbuf[1] = { BLS_CODE_READ_STATUS }; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } ret = spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)); if(ret != SPI_DEV_STATUS_OK) { - deselect(); + deselect(flash_spi_configuration); return false; } @@ -164,7 +173,7 @@ wait_ready(void) if(ret != SPI_DEV_STATUS_OK) { /* Error */ - deselect(); + deselect(flash_spi_configuration); return false; } @@ -173,7 +182,7 @@ wait_ready(void) break; } } - deselect(); + deselect(flash_spi_configuration); return true; } /*---------------------------------------------------------------------------*/ @@ -185,23 +194,23 @@ wait_ready(void) * was powered down */ static uint8_t -verify_part(void) +verify_part(spi_device_t *flash_spi_configuration) { const uint8_t wbuf[] = { BLS_CODE_MDID, 0xFF, 0xFF, 0x00 }; uint8_t rbuf[2] = { 0, 0 }; bool ret; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return VERIFY_PART_LOCKED; } if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { - deselect(); + deselect(flash_spi_configuration); return VERIFY_PART_ERROR; } ret = spi_read(flash_spi_configuration, rbuf, sizeof(rbuf)); - deselect(); + deselect(flash_spi_configuration); if(ret != SPI_DEV_STATUS_OK) { return VERIFY_PART_ERROR; } @@ -219,31 +228,31 @@ verify_part(void) * the status register is accessible. */ static bool -power_down(void) +power_down(spi_device_t *flash_spi_configuration) { uint8_t cmd; uint8_t i; /* First, wait for the device to be ready */ - if(wait_ready() == false) { + if(wait_ready(flash_spi_configuration) == false) { /* Entering here will leave the device in standby instead of powerdown */ return false; } cmd = BLS_CODE_PD; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } if(spi_write_byte(flash_spi_configuration, cmd) != SPI_DEV_STATUS_OK) { - deselect(); + deselect(flash_spi_configuration); return false; } - deselect(); + deselect(flash_spi_configuration); i = 0; while(i < 10) { - if(verify_part() == VERIFY_PART_POWERED_DOWN) { + if(verify_part(flash_spi_configuration) == VERIFY_PART_POWERED_DOWN) { /* Device is powered down */ return true; } @@ -251,7 +260,7 @@ power_down(void) } /* Should not be required */ - deselect(); + deselect(flash_spi_configuration); return false; } /*---------------------------------------------------------------------------*/ @@ -260,23 +269,23 @@ power_down(void) * \return True if the command was written successfully */ static bool -power_standby(void) +power_standby(spi_device_t *flash_spi_configuration) { uint8_t cmd; bool success; cmd = BLS_CODE_RPD; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } success = (spi_write(flash_spi_configuration, &cmd, sizeof(cmd)) == SPI_DEV_STATUS_OK); if(success) { - success = wait_ready() == true ? true : false; + success = wait_ready(flash_spi_configuration) == true ? true : false; } - deselect(); + deselect(flash_spi_configuration); return success; } @@ -286,17 +295,17 @@ power_standby(void) * \return True when successful. */ static bool -write_enable(void) +write_enable(spi_device_t *flash_spi_configuration) { bool ret; const uint8_t wbuf[] = { BLS_CODE_WRITE_ENABLE }; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } ret = (spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) == SPI_DEV_STATUS_OK); - deselect(); + deselect(flash_spi_configuration); if(ret == false) { return false; @@ -305,8 +314,12 @@ write_enable(void) } /*---------------------------------------------------------------------------*/ bool -ext_flash_open() +ext_flash_open(spi_device_t *conf) { + spi_device_t *flash_spi_configuration; + + flash_spi_configuration = get_spi_conf(conf); + /* Check if platform has ext-flash */ if(flash_spi_configuration->pin_spi_sck == 255) { return false; @@ -316,37 +329,51 @@ ext_flash_open() return false; } /* Default output to clear chip select */ - deselect(); + deselect(flash_spi_configuration); /* Put the part is standby mode */ - power_standby(); + power_standby(flash_spi_configuration); - return verify_part() == VERIFY_PART_OK ? true : false; + if (verify_part(flash_spi_configuration) == VERIFY_PART_OK) { + return true; + } + + /* Failed to verify */ + spi_release(flash_spi_configuration); + return false; } /*---------------------------------------------------------------------------*/ bool -ext_flash_close() +ext_flash_close(spi_device_t *conf) { - /* Put the part in low power mode */ - if(power_down() == false) { - return false; - } + bool ret; + spi_device_t *flash_spi_configuration; + flash_spi_configuration = get_spi_conf(conf); + + /* Put the part in low power mode */ + ret = power_down(flash_spi_configuration); + + /* SPI is released no matter if power_down() succeeds or fails */ if(spi_release(flash_spi_configuration) != SPI_DEV_STATUS_OK) { return false; } - return true; + return ret; } /*---------------------------------------------------------------------------*/ bool -ext_flash_read(uint32_t offset, uint32_t length, uint8_t *buf) +ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf) { uint8_t wbuf[4]; bool ret; + spi_device_t *flash_spi_configuration; + + flash_spi_configuration = get_spi_conf(conf); + /* Wait till previous erase/program operation completes */ - if(wait_ready() == false) { + if(wait_ready(flash_spi_configuration) == false) { return false; } @@ -359,36 +386,40 @@ ext_flash_read(uint32_t offset, uint32_t length, uint8_t *buf) wbuf[2] = (offset >> 8) & 0xff; wbuf[3] = offset & 0xff; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { /* failure */ - deselect(); + deselect(flash_spi_configuration); return false; } ret = (spi_read(flash_spi_configuration, buf, length) == SPI_DEV_STATUS_OK); - deselect(); + deselect(flash_spi_configuration); return ret; } /*---------------------------------------------------------------------------*/ bool -ext_flash_write(uint32_t offset, uint32_t length, const uint8_t *buf) +ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf) { uint8_t wbuf[4]; uint32_t ilen; /* interim length per instruction */ + spi_device_t *flash_spi_configuration; + + flash_spi_configuration = get_spi_conf(conf); + while(length > 0) { /* Wait till previous erase/program operation completes */ - if(wait_ready() == false) { + if(wait_ready(flash_spi_configuration) == false) { return false; } - if(write_enable() == false) { + if(write_enable(flash_spi_configuration) == false) { return false; } @@ -410,30 +441,30 @@ ext_flash_write(uint32_t offset, uint32_t length, const uint8_t *buf) * is not imposed here since above instructions * should be enough to delay * as much. */ - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { /* failure */ - deselect(); + deselect(flash_spi_configuration); return false; } if(spi_write(flash_spi_configuration, buf, ilen) != SPI_DEV_STATUS_OK) { /* failure */ - deselect(); + deselect(flash_spi_configuration); return false; } buf += ilen; - deselect(); + deselect(flash_spi_configuration); } return true; } /*---------------------------------------------------------------------------*/ bool -ext_flash_erase(uint32_t offset, uint32_t length) +ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length) { /* * Note that Block erase might be more efficient when the floor map @@ -443,6 +474,10 @@ ext_flash_erase(uint32_t offset, uint32_t length) uint8_t wbuf[4]; uint32_t i, numsectors; uint32_t endoffset = offset + length - 1; + + spi_device_t *flash_spi_configuration; + + flash_spi_configuration = get_spi_conf(conf); offset = (offset / EXT_FLASH_ERASE_SECTOR_SIZE) * EXT_FLASH_ERASE_SECTOR_SIZE; numsectors = (endoffset - offset + EXT_FLASH_ERASE_SECTOR_SIZE - 1) / EXT_FLASH_ERASE_SECTOR_SIZE; @@ -451,11 +486,11 @@ ext_flash_erase(uint32_t offset, uint32_t length) for(i = 0; i < numsectors; i++) { /* Wait till previous erase/program operation completes */ - if(wait_ready() == false) { + if(wait_ready(flash_spi_configuration) == false) { return false; } - if(write_enable() == false) { + if(write_enable(flash_spi_configuration) == false) { return false; } @@ -463,16 +498,16 @@ ext_flash_erase(uint32_t offset, uint32_t length) wbuf[2] = (offset >> 8) & 0xff; wbuf[3] = offset & 0xff; - if(select_on_bus() == false) { + if(select_on_bus(flash_spi_configuration) == false) { return false; } if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) { /* failure */ - deselect(); + deselect(flash_spi_configuration); return false; } - deselect(); + deselect(flash_spi_configuration); offset += EXT_FLASH_ERASE_SECTOR_SIZE; } @@ -481,33 +516,19 @@ ext_flash_erase(uint32_t offset, uint32_t length) } /*---------------------------------------------------------------------------*/ bool -ext_flash_test(void) +ext_flash_init(spi_device_t *conf) { - flash_spi_configuration = &flash_spi_configuration_default; - - if(ext_flash_open() == false) { + if(ext_flash_open(conf) == false) { return false; } - if(ext_flash_close() == false) { + if(ext_flash_close(conf) == false) { return false; } - LOG_INFO("Flash test successful\n"); + LOG_INFO("Flash init successful\n"); return true; } /*---------------------------------------------------------------------------*/ -bool -ext_flash_init(spi_device_t *conf) -{ - if(conf == NULL) { - flash_spi_configuration = &flash_spi_configuration_default; - } else { - flash_spi_configuration = conf; - } - - return ext_flash_test(); -} -/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/dev/ext-flash.h b/os/dev/ext-flash.h index 14017ab46..8012ee6dd 100644 --- a/os/dev/ext-flash.h +++ b/os/dev/ext-flash.h @@ -49,19 +49,22 @@ /*---------------------------------------------------------------------------*/ /** * \brief Initialize storage driver. + * \param SPI bus configuration struct. NULL for default. * \return True when successful. */ -bool ext_flash_open(void); +bool ext_flash_open(spi_device_t *conf); /** * \brief Close the storage driver + * \param SPI bus configuration struct. NULL for default. * * This call will put the device in its lower power mode (power down). */ -bool ext_flash_close(void); +bool ext_flash_close(spi_device_t *conf); /** * \brief Read storage content + * \param SPI bus configuration struct. NULL for default. * \param offset Address to read from * \param length Number of bytes to read * \param buf Buffer where to store the read bytes @@ -69,10 +72,11 @@ bool ext_flash_close(void); * * buf must be allocated by the caller */ -bool ext_flash_read(uint32_t offset, uint32_t length, uint8_t *buf); +bool ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf); /** * \brief Erase storage sectors corresponding to the range. + * \param SPI bus configuration struct. NULL for default. * \param offset Address to start erasing * \param length Number of bytes to erase * \return True when successful. @@ -80,26 +84,22 @@ bool ext_flash_read(uint32_t offset, uint32_t length, uint8_t *buf); * The erase operation will be sector-wise, therefore a call to this function * will generally start the erase procedure at an address lower than offset */ -bool ext_flash_erase(uint32_t offset, uint32_t length); +bool ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length); /** * \brief Write to storage sectors. + * \param SPI bus configuration struct. NULL for default. * \param offset Address to write to * \param length Number of bytes to write * \param buf Buffer holding the bytes to be written * * \return True when successful. */ -bool ext_flash_write(uint32_t offset, uint32_t length, const uint8_t *buf); - -/** - * \brief Test the flash (power on self-test) - * \return True when successful. - */ -bool ext_flash_test(void); +bool ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf); /** * \brief Initialise the external flash + * \param SPI bus configuration struct. NULL for default. * * This function will explicitly put the part in its lowest power mode * (power-down). From 46d1dd129359b04a3fdcedf6365b19221807c7d5 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 4 Apr 2018 11:08:35 +0100 Subject: [PATCH 60/72] update xmem --- arch/platform/srf06-cc26xx/common/xmem.c | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/platform/srf06-cc26xx/common/xmem.c b/arch/platform/srf06-cc26xx/common/xmem.c index 5a79be6c1..116991c66 100644 --- a/arch/platform/srf06-cc26xx/common/xmem.c +++ b/arch/platform/srf06-cc26xx/common/xmem.c @@ -60,7 +60,7 @@ void xmem_init(void) { - ext_flash_open(); + ext_flash_open(NULL); } @@ -71,21 +71,21 @@ xmem_pread(void *_p, int size, unsigned long addr) uint8_t x; int i; - rv = ext_flash_open(); + rv = ext_flash_open(NULL); if(!rv) { PRINTF("Could not open flash to save config\n"); - ext_flash_close(); + ext_flash_close(NULL); return -1; } - rv = ext_flash_read(addr, size, _p); + rv = ext_flash_read(NULL, addr, size, _p); for (i = 0; i < size; i++){ x = ~*((uint8_t *)_p + i); *((uint8_t *)_p+i) = x; } - ext_flash_close(); + ext_flash_close(NULL); if(rv) return size; @@ -104,11 +104,11 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr) uint8_t tmp_buf[XMEM_BUFF_LENGHT]; - rv = ext_flash_open(); + rv = ext_flash_open(NULL); if(!rv) { PRINTF("Could not open flash to save config!\n"); - ext_flash_close(); + ext_flash_close(NULL); return -1; } @@ -117,14 +117,14 @@ xmem_pwrite(const void *_buf, int size, unsigned long addr) for (i = 0; i < to_write; i++) { tmp_buf[i] = ~*((uint8_t *)_buf + j + i); } - rv = ext_flash_write(addr + j, to_write, tmp_buf); + rv = ext_flash_write(NULL, addr + j, to_write, tmp_buf); if (!rv) { PRINTF("Could not write flash memory!\n"); return size - remain; } } - ext_flash_close(); + ext_flash_close(NULL); return size; } @@ -135,12 +135,12 @@ xmem_erase(long size, unsigned long addr) { int rv; - rv = ext_flash_open(); + rv = ext_flash_open(NULL); if(!rv) { PRINTF("Could not open flash to save config\n"); - ext_flash_close(); + ext_flash_close(NULL); return -1; } @@ -154,9 +154,9 @@ xmem_erase(long size, unsigned long addr) return -1; } - rv = ext_flash_erase(addr, size); + rv = ext_flash_erase(NULL, addr, size); - ext_flash_close(); + ext_flash_close(NULL); watchdog_periodic(); From ab40997fd0c4553af934b198b4727c1b7034041d Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 4 Apr 2018 11:10:25 +0100 Subject: [PATCH 61/72] ext-flash driver: minor with pin unknown --- os/dev/ext-flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/dev/ext-flash.c b/os/dev/ext-flash.c index 2d84cbdd7..547ec062c 100644 --- a/os/dev/ext-flash.c +++ b/os/dev/ext-flash.c @@ -321,7 +321,7 @@ ext_flash_open(spi_device_t *conf) flash_spi_configuration = get_spi_conf(conf); /* Check if platform has ext-flash */ - if(flash_spi_configuration->pin_spi_sck == 255) { + if(flash_spi_configuration->pin_spi_sck == GPIO_HAL_PIN_UNKNOWN) { return false; } From 629803c5e527ec2cbf63df19500be117319c4959 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 4 Apr 2018 11:30:10 +0100 Subject: [PATCH 62/72] ext-flash driver moved to arch/dev/ --- arch/dev/ext-flash/README.md | 11 +++++++++++ {os/dev => arch/dev/ext-flash}/ext-flash.c | 0 {os/dev => arch/dev/ext-flash}/ext-flash.h | 0 .../srf06-cc26xx/launchpad/Makefile.launchpad | 2 ++ .../srf06-cc26xx/sensortag/Makefile.sensortag | 2 ++ 5 files changed, 15 insertions(+) create mode 100644 arch/dev/ext-flash/README.md rename {os/dev => arch/dev/ext-flash}/ext-flash.c (100%) rename {os/dev => arch/dev/ext-flash}/ext-flash.h (100%) diff --git a/arch/dev/ext-flash/README.md b/arch/dev/ext-flash/README.md new file mode 100644 index 000000000..a16fb9c49 --- /dev/null +++ b/arch/dev/ext-flash/README.md @@ -0,0 +1,11 @@ +# Ext-flash Driver + +This is a generic driver for external SPI flash memories. It has been tested with the following parts: +- Winbond W25X20CL +- Winbond W25X40CL +- Macronix MX25R8035F +- Macronix MX25R1635F +- Macronix MX25R6435F +- Macronix MX25U6435F + +These parts have identical instruction sets; only the manufacturer and device ID differ, which must be specified in `board.h`. \ No newline at end of file diff --git a/os/dev/ext-flash.c b/arch/dev/ext-flash/ext-flash.c similarity index 100% rename from os/dev/ext-flash.c rename to arch/dev/ext-flash/ext-flash.c diff --git a/os/dev/ext-flash.h b/arch/dev/ext-flash/ext-flash.h similarity index 100% rename from os/dev/ext-flash.h rename to arch/dev/ext-flash/ext-flash.h diff --git a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad index d3f4ab355..09af79c0b 100644 --- a/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad +++ b/arch/platform/srf06-cc26xx/launchpad/Makefile.launchpad @@ -4,5 +4,7 @@ CONTIKI_TARGET_DIRS += launchpad common BOARD_SOURCEFILES += board.c board-buttons.c xmem.c +MODULES += arch/dev/ext-flash + ### Signal that we can be programmed with cc2538-bsl BOARD_SUPPORTS_BSL=1 diff --git a/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag b/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag index 5d528b8dc..5f7712fef 100644 --- a/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag +++ b/arch/platform/srf06-cc26xx/sensortag/Makefile.sensortag @@ -8,3 +8,5 @@ BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c xmem.c BOARD_SOURCEFILES += buzzer.c BOARD_SOURCEFILES += board.c board-i2c.c + +MODULES += arch/dev/ext-flash From f91b223c575d6fdc9f5bbd2bd18e6a87cd5bb56f Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 4 Apr 2018 12:23:53 +0100 Subject: [PATCH 63/72] ext-flash: doxygen errors fixed --- arch/dev/ext-flash/ext-flash.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/dev/ext-flash/ext-flash.h b/arch/dev/ext-flash/ext-flash.h index 8012ee6dd..20748a2f0 100644 --- a/arch/dev/ext-flash/ext-flash.h +++ b/arch/dev/ext-flash/ext-flash.h @@ -49,14 +49,15 @@ /*---------------------------------------------------------------------------*/ /** * \brief Initialize storage driver. - * \param SPI bus configuration struct. NULL for default. + * \param conf SPI bus configuration struct. NULL for default. * \return True when successful. */ bool ext_flash_open(spi_device_t *conf); /** * \brief Close the storage driver - * \param SPI bus configuration struct. NULL for default. + * \param conf SPI bus configuration struct. NULL for default. + * \return True when successful. * * This call will put the device in its lower power mode (power down). */ @@ -64,7 +65,7 @@ bool ext_flash_close(spi_device_t *conf); /** * \brief Read storage content - * \param SPI bus configuration struct. NULL for default. + * \param conf SPI bus configuration struct. NULL for default. * \param offset Address to read from * \param length Number of bytes to read * \param buf Buffer where to store the read bytes @@ -76,7 +77,7 @@ bool ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_ /** * \brief Erase storage sectors corresponding to the range. - * \param SPI bus configuration struct. NULL for default. + * \param conf SPI bus configuration struct. NULL for default. * \param offset Address to start erasing * \param length Number of bytes to erase * \return True when successful. @@ -88,7 +89,7 @@ bool ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length); /** * \brief Write to storage sectors. - * \param SPI bus configuration struct. NULL for default. + * \param conf SPI bus configuration struct. NULL for default. * \param offset Address to write to * \param length Number of bytes to write * \param buf Buffer holding the bytes to be written @@ -99,7 +100,7 @@ bool ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const /** * \brief Initialise the external flash - * \param SPI bus configuration struct. NULL for default. + * \param conf SPI bus configuration struct. NULL for default. * * This function will explicitly put the part in its lowest power mode * (power-down). From 9d471821a91f3b0bb80b8660e565c4a241434857 Mon Sep 17 00:00:00 2001 From: "Xenofon (Fontas) Fafoutis" Date: Wed, 4 Apr 2018 12:26:58 +0100 Subject: [PATCH 64/72] updated cc26xx-web-demo to new ext-flash api --- .../cc26xx/cc26xx-web-demo/cc26xx-web-demo.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c index 306b54640..f69a19478 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c @@ -195,15 +195,15 @@ save_config() int rv; cc26xx_web_demo_sensor_reading_t *reading = NULL; - rv = ext_flash_open(); + rv = ext_flash_open(NULL); if(!rv) { printf("Could not open flash to save config\n"); - ext_flash_close(); + ext_flash_close(NULL); return; } - rv = ext_flash_erase(CONFIG_FLASH_OFFSET, sizeof(cc26xx_web_demo_config_t)); + rv = ext_flash_erase(NULL, CONFIG_FLASH_OFFSET, sizeof(cc26xx_web_demo_config_t)); if(!rv) { printf("Error erasing flash\n"); @@ -220,14 +220,14 @@ save_config() } } - rv = ext_flash_write(CONFIG_FLASH_OFFSET, sizeof(cc26xx_web_demo_config_t), + rv = ext_flash_write(NULL, CONFIG_FLASH_OFFSET, sizeof(cc26xx_web_demo_config_t), (uint8_t *)&cc26xx_web_demo_config); if(!rv) { printf("Error saving config\n"); } } - ext_flash_close(); + ext_flash_close(NULL); #endif } /*---------------------------------------------------------------------------*/ @@ -239,18 +239,18 @@ load_config() cc26xx_web_demo_config_t tmp_cfg; cc26xx_web_demo_sensor_reading_t *reading = NULL; - int rv = ext_flash_open(); + int rv = ext_flash_open(NULL); if(!rv) { printf("Could not open flash to load config\n"); - ext_flash_close(); + ext_flash_close(NULL); return; } - rv = ext_flash_read(CONFIG_FLASH_OFFSET, sizeof(tmp_cfg), + rv = ext_flash_read(NULL, CONFIG_FLASH_OFFSET, sizeof(tmp_cfg), (uint8_t *)&tmp_cfg); - ext_flash_close(); + ext_flash_close(NULL); if(!rv) { printf("Error loading config\n"); From 96032fa47b25bbcc8d9bd7a16151c3a55055acd5 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 5 Apr 2018 08:54:08 -0700 Subject: [PATCH 65/72] Shell: added ability to trigger a RPL DTSN increment --- os/net/routing/rpl-lite/rpl-dag.c | 15 +++++++++++++++ os/net/routing/rpl-lite/rpl.h | 7 +++++++ os/services/shell/shell-commands.c | 12 ++++++++++++ 3 files changed, 34 insertions(+) diff --git a/os/net/routing/rpl-lite/rpl-dag.c b/os/net/routing/rpl-lite/rpl-dag.c index 7cf99e03b..00ee1663e 100644 --- a/os/net/routing/rpl-lite/rpl-dag.c +++ b/os/net/routing/rpl-lite/rpl-dag.c @@ -180,6 +180,21 @@ find_objective_function(rpl_ocp_t ocp) } /*---------------------------------------------------------------------------*/ void +rpl_refresh_routes(const char *str) +{ + if(rpl_dag_root_is_root()) { + LOG_WARN("incrementing DTSN (%s), current %u)\n", + str, curr_instance.dtsn_out); + if(LOG_INFO_ENABLED) { + rpl_neighbor_print_list("Refresh routes (before)"); + } + + /* Increment DTSN */ + RPL_LOLLIPOP_INCREMENT(curr_instance.dtsn_out); + } +} +/*---------------------------------------------------------------------------*/ +void rpl_global_repair(const char *str) { if(rpl_dag_root_is_root()) { diff --git a/os/net/routing/rpl-lite/rpl.h b/os/net/routing/rpl-lite/rpl.h index 7fb4c8718..25ac3863e 100644 --- a/os/net/routing/rpl-lite/rpl.h +++ b/os/net/routing/rpl-lite/rpl.h @@ -126,6 +126,13 @@ int rpl_is_reachable(void); */ int rpl_lollipop_greater_than(int a, int b); +/** + * Triggers a route fresh via DTSN increment + * + * \param str a textual description of the cause for refresh + */ +void rpl_refresh_routes(const char *str); + /** @} */ #endif /* RPL_H */ diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 2068bf249..46ee92fe5 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -412,6 +412,17 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar PT_END(pt); } +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *args)) +{ + PT_BEGIN(pt); + + SHELL_OUTPUT(output, "Triggering routes refresh\n") + rpl_refresh_routes("Shell"); + + PT_END(pt); +} #endif /* UIP_CONF_IPV6_RPL */ /*---------------------------------------------------------------------------*/ static @@ -721,6 +732,7 @@ struct shell_command_t shell_commands[] = { #if UIP_CONF_IPV6_RPL { "rpl-set-root", cmd_rpl_set_root, "'> rpl-set-root 0/1 [prefix]': Sets node as root (1) or not (0). A /64 prefix can be optionally specified." }, { "rpl-local-repair", cmd_rpl_local_repair, "'> rpl-local-repair': Triggers a RPL local repair" }, + { "rpl-refresh-routes", cmd_rpl_refresh_routes, "'> rpl-refresh-routes': Refreshes all routes through a DTSN increment" }, { "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" }, #endif /* UIP_CONF_IPV6_RPL */ #if ROUTING_CONF_RPL_LITE From 9630245cda3b81230b81402e7f4a96ef939f7c3e Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 5 Apr 2018 01:55:53 -0700 Subject: [PATCH 66/72] CSMA: reset collision count to 0, not CSMA_MIN_BE --- os/net/mac/csma/csma-output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 74803ecf1..46862fa6a 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -403,7 +403,7 @@ noack(struct packet_queue *q, struct neighbor_queue *n, int num_transmissions) static void tx_ok(struct packet_queue *q, struct neighbor_queue *n, int num_transmissions) { - n->collisions = CSMA_MIN_BE; + n->collisions = 0; n->transmissions += num_transmissions; tx_done(MAC_TX_OK, q, n); } @@ -493,7 +493,7 @@ csma_output_packet(mac_callback_t sent, void *ptr) /* Init neighbor entry */ linkaddr_copy(&n->addr, addr); n->transmissions = 0; - n->collisions = CSMA_MIN_BE; + n->collisions = 0; /* Init packet queue for this neighbor */ LIST_STRUCT_INIT(n, packet_queue); /* Add neighbor to the neighbor list */ From c56d11502b6773681863d191640bd756ab43bd23 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 5 Apr 2018 08:53:46 -0700 Subject: [PATCH 67/72] CSMA: fix configuration bug --- os/net/mac/csma/csma-output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 46862fa6a..d3493ebe5 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -85,7 +85,7 @@ /* macMaxFrameRetries: Maximum number of re-transmissions attampts. Range 0--7 */ #ifdef CSMA_CONF_MAX_FRAME_RETRIES -#define CSMA_MAX_FRAME_RETRIES CSMA_MAX_FRAME_RETRIES +#define CSMA_MAX_FRAME_RETRIES CSMA_CONF_MAX_FRAME_RETRIES #else #define CSMA_MAX_FRAME_RETRIES 7 #endif From 9dfcb2ebb6d22e12f7585fc66255017c4fdaf9c1 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Thu, 5 Apr 2018 05:34:50 -0700 Subject: [PATCH 68/72] Various logging improvements --- examples/slip-radio/slip-radio.c | 2 +- os/net/app-layer/coap/coap-engine.c | 2 +- os/net/app-layer/coap/coap-uip.c | 8 ++++---- os/net/ipv6/sicslowpan.c | 12 ++++++------ os/net/ipv6/tcpip.c | 4 +++- os/net/mac/csma/csma-output.c | 3 ++- os/net/mac/csma/csma.c | 6 +++--- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/examples/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index 30a9387df..21779a3dc 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -254,7 +254,7 @@ PROCESS_THREAD(slip_radio_process, ev, data) #ifdef SLIP_RADIO_CONF_SENSORS SLIP_RADIO_CONF_SENSORS.init(); #endif - printf("Slip Radio started...\n"); + LOG_INFO("Slip Radio started\n"); etimer_set(&et, CLOCK_SECOND * 3); diff --git a/os/net/app-layer/coap/coap-engine.c b/os/net/app-layer/coap/coap-engine.c index 0db9c2a39..fb85b5b15 100644 --- a/os/net/app-layer/coap/coap-engine.c +++ b/os/net/app-layer/coap/coap-engine.c @@ -51,7 +51,7 @@ /* Log configuration */ #include "coap-log.h" -#define LOG_MODULE "coap-engine" +#define LOG_MODULE "coap-eng" #define LOG_LEVEL LOG_LEVEL_COAP static void process_callback(coap_timer_t *t); diff --git a/os/net/app-layer/coap/coap-uip.c b/os/net/app-layer/coap/coap-uip.c index ed881ca8b..8db2bbbbf 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -359,8 +359,8 @@ process_secure_data(void) { LOG_INFO("receiving secure UDP datagram from ["); LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); - LOG_INFO_("]:%u\n Length: %u\n", uip_ntohs(UIP_UDP_BUF->srcport), - uip_datalen()); + LOG_INFO_("]:%u\n", uip_ntohs(UIP_UDP_BUF->srcport)); + LOG_INFO(" Length: %u\n", uip_datalen()); if(dtls_context) { dtls_handle_message(dtls_context, (coap_endpoint_t *)get_src_endpoint(1), @@ -374,8 +374,8 @@ process_data(void) { LOG_INFO("receiving UDP datagram from ["); LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); - LOG_INFO_("]:%u\n Length: %u\n", uip_ntohs(UIP_UDP_BUF->srcport), - uip_datalen()); + LOG_INFO_("]:%u\n", uip_ntohs(UIP_UDP_BUF->srcport)); + LOG_INFO(" Length: %u\n", uip_datalen()); coap_receive(get_src_endpoint(0), uip_appdata, uip_datalen()); } diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 3bc7a935e..4708acca7 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -1571,7 +1571,7 @@ output(const linkaddr_t *localdest) LOG_INFO("Fragmentation sending packet len %d\n", uip_len); /* Create 1st Fragment */ - LOG_INFO("output: 1rst fragment "); + LOG_INFO("output: 1st fragment "); /* Reset last tx status to ok in case the fragment transmissions are deferred */ last_tx_status = MAC_TX_OK; @@ -1591,7 +1591,7 @@ output(const linkaddr_t *localdest) /* Copy payload and send */ packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; packetbuf_payload_len = (max_payload - packetbuf_hdr_len) & 0xfffffff8; - LOG_INFO("(len %d, tag %d)\n", packetbuf_payload_len, frag_tag); + LOG_INFO_("(len %d, tag %d)\n", packetbuf_payload_len, frag_tag); memcpy(packetbuf_ptr + packetbuf_hdr_len, (uint8_t *)UIP_IP_BUF + uncomp_hdr_len, packetbuf_payload_len); packetbuf_set_datalen(packetbuf_payload_len + packetbuf_hdr_len); @@ -1636,7 +1636,7 @@ output(const linkaddr_t *localdest) /* last fragment */ packetbuf_payload_len = uip_len - processed_ip_out_len; } - LOG_INFO("(offset %d, len %d, tag %d)\n", + LOG_INFO_("(offset %d, len %d, tag %d)\n", processed_ip_out_len >> 3, packetbuf_payload_len, frag_tag); memcpy(packetbuf_ptr + packetbuf_hdr_len, (uint8_t *)UIP_IP_BUF + processed_ip_out_len, packetbuf_payload_len); @@ -1742,7 +1742,7 @@ input(void) frag_offset = 0; frag_size = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE) & 0x07ff; frag_tag = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_TAG); - LOG_INFO("size %d, tag %d, offset %d)\n", + LOG_INFO_ ("size %d, tag %d, offset %d)\n", frag_size, frag_tag, frag_offset); packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; first_fragment = 1; @@ -1767,13 +1767,13 @@ input(void) frag_offset = PACKETBUF_FRAG_PTR[PACKETBUF_FRAG_OFFSET]; frag_tag = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_TAG); frag_size = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE) & 0x07ff; - LOG_INFO("size %d, tag %d, offset %d)\n", + LOG_INFO_("size %d, tag %d, offset %d)\n", frag_size, frag_tag, frag_offset); packetbuf_hdr_len += SICSLOWPAN_FRAGN_HDR_LEN; /* If this is the last fragment, we may shave off any extrenous bytes at the end. We must be liberal in what we accept. */ - LOG_INFO("last_fragment?: packetbuf_payload_len %d frag_size %d\n", + LOG_INFO_("last_fragment?: packetbuf_payload_len %d frag_size %d\n", packetbuf_datalen() - packetbuf_hdr_len, frag_size); /* Add the fragment to the fragmentation context (this will also diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 41d317d17..5db4b9a21 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -168,6 +168,8 @@ static void packet_input(void) { if(uip_len > 0) { + LOG_INFO("input: received %u bytes\n", uip_len); + check_for_tcp_syn(); #if UIP_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS @@ -499,7 +501,7 @@ get_nexthop(uip_ipaddr_t *addr) uip_ipaddr_t *nexthop; uip_ds6_route_t *route; - LOG_INFO("output: processing packet from "); + LOG_INFO("output: processing %u bytes packet from ", uip_len); LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); LOG_INFO_(" to "); LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 74803ecf1..87a46aa18 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -523,7 +523,8 @@ csma_output_packet(mac_callback_t sent, void *ptr) LOG_INFO("sending to "); LOG_INFO_LLADDR(addr); - LOG_INFO_(", seqno %u, queue length %d, free packets %d\n", + LOG_INFO_(", len %u, seqno %u, queue length %d, free packets %d\n", + packetbuf_datalen(), packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO), list_length(n->packet_queue), memb_numfree(&packet_memb)); /* If q is the first packet in the neighbor's queue, send asap */ diff --git a/os/net/mac/csma/csma.c b/os/net/mac/csma/csma.c index aa7a98a3d..7259e35c8 100644 --- a/os/net/mac/csma/csma.c +++ b/os/net/mac/csma/csma.c @@ -108,9 +108,9 @@ input_packet(void) } #endif /* CSMA_SEND_SOFT_ACK */ if(!duplicate) { - LOG_WARN("received packet from "); - LOG_WARN_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); - LOG_WARN_(", seqno %u, len %u\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO), packetbuf_datalen()); + LOG_INFO("received packet from "); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO_(", seqno %u, len %u\n", packetbuf_attr(PACKETBUF_ATTR_MAC_SEQNO), packetbuf_datalen()); NETSTACK_NETWORK.input(); } } From 94761481915c70d4a72692a5398f63ba6fe7f323 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 6 Apr 2018 04:04:55 -0700 Subject: [PATCH 69/72] Cooja motes: larger log buffer --- arch/platform/cooja/sys/cooja-log.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/platform/cooja/sys/cooja-log.c b/arch/platform/cooja/sys/cooja-log.c index 32b064335..c7ffdb9ac 100644 --- a/arch/platform/cooja/sys/cooja-log.c +++ b/arch/platform/cooja/sys/cooja-log.c @@ -35,10 +35,9 @@ #define IMPLEMENT_PRINTF 1 -#if MAX_LOG_LENGTH < 1024 -#undef MAX_LOG_LENGTH -#define MAX_LOG_LENGTH 1024 -#endif /* MAX_LOG_LENGTH < 1024 */ +#ifndef MAX_LOG_LENGTH +#define MAX_LOG_LENGTH 8192 +#endif /* MAX_LOG_LENGTH */ const struct simInterface simlog_interface; From a94b868a4f2b171236146aa5bd74ec1b5f89763f Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2018 14:01:31 +0100 Subject: [PATCH 70/72] Tidy-up AROPTS for cpu native --- arch/cpu/native/Makefile.native | 2 +- arch/platform/native/Makefile.native | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index cda288e65..146af3e72 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -20,7 +20,7 @@ CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR) CFLAGS += $(CFLAGSNO) ifeq ($(HOST_OS),Darwin) -AROPTS = -r +AROPTS = -rc LDFLAGS += -Wl,-flat_namespace,-map,$(CONTIKI_NG_PROJECT_MAP) CFLAGS += -DHAVE_SNPRINTF=1 -U__ASSERT_USE_STDERR else diff --git a/arch/platform/native/Makefile.native b/arch/platform/native/Makefile.native index 24f433796..f8fd7286c 100644 --- a/arch/platform/native/Makefile.native +++ b/arch/platform/native/Makefile.native @@ -2,9 +2,6 @@ ifndef CONTIKI $(error CONTIKI not defined! You must specify where CONTIKI resides!) endif -ifeq ($(HOST_OS),Darwin) - AROPTS = rc -endif CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} From 6ce1c79f8c9a767ed3691a8c6ace56b2b9a78248 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 6 Apr 2018 18:20:00 +0200 Subject: [PATCH 71/72] Updated example-lwm2m-standalone to latest version --- tests/18-coap-lwm2m/example-lwm2m-standalone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/18-coap-lwm2m/example-lwm2m-standalone b/tests/18-coap-lwm2m/example-lwm2m-standalone index 7ab51eaaa..67b858437 160000 --- a/tests/18-coap-lwm2m/example-lwm2m-standalone +++ b/tests/18-coap-lwm2m/example-lwm2m-standalone @@ -1 +1 @@ -Subproject commit 7ab51eaaa309c123fbd318c6ad3338cce1e48e48 +Subproject commit 67b858437f7cf1e4e027d821c4c2ac15fdf2ab44 From c81459e565f8057b7a5aefefe9b4497e56a940ed Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 6 Apr 2018 18:22:53 +0200 Subject: [PATCH 72/72] Fixed some issues with the LWM2M IPSO and standalone regressing tests. --- tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh | 13 +++++++++++-- .../18-coap-lwm2m/07-lwm2m-standalone-test.sh | 19 ++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh index 15fd96243..7684044a8 100755 --- a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh +++ b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh @@ -3,12 +3,13 @@ # Contiki directory CONTIKI=$1 # Test basename -BASENAME=06-lwm2m-test +BASENAME=06-lwm2m-ipso-test IPADDR=fd00::302:304:506:708 # Starting Contiki-NG native node echo "Starting native node - lwm2m/ipso objects" +make -C $CONTIKI/examples/ipso-objects clean >/dev/null make -C $CONTIKI/examples/ipso-objects > make.log 2> make.err sudo $CONTIKI/examples/ipso-objects/example-ipso-objects.native > node.log 2> node.err & CPID=$! @@ -19,7 +20,15 @@ wget -nc https://joakimeriksson.github.io/resources/leshan-server-demo-1.0.0-SNA echo "Starting leshan server" java -jar leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar >leshan.log 2>leshan.err & LESHID=$! -sleep 50 + +COUNTER=10 +while [ $COUNTER -gt 0 ]; do + sleep 5 + if grep -q 'OK' leshan.err ; then + break + fi + let COUNTER-=1 +done echo "Closing native node" sleep 1 diff --git a/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh b/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh index 5516eeb46..b13352447 100755 --- a/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh +++ b/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh @@ -5,9 +5,10 @@ CONTIKI=$1 # Test basename BASENAME=07-lwm2m-standalone-test -git clone https://github.com/contiki-ng/example-lwm2m-standalone.git # Building standalone posix example -make -C example-lwm2m-standalone/lwm2m > make.log 2> make.err +echo "Compiling standalone posix example" +make CONTIKI_NG=../../$CONTIKI -C example-lwm2m-standalone/lwm2m clean >/dev/null +make CONTIKI_NG=../../$CONTIKI -C example-lwm2m-standalone/lwm2m >make.log 2>make.err echo "Downloading leshan" wget -nc https://joakimeriksson.github.io/resources/leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar @@ -20,11 +21,19 @@ example-lwm2m-standalone/lwm2m/lwm2m-example coap://127.0.0.1:5686 > node.log 2> CPID=$! -sleep 50 +COUNTER=10 +while [ $COUNTER -gt 0 ]; do + sleep 5 + if grep -q 'OK' leshan.err ; then + echo OK with $COUNTER + break + fi + let COUNTER-=1 +done -echo "Closing native node" +echo "Closing standalone example" sleep 1 -pgrep ipso | sudo xargs kill -9 +pgrep lwm2m-example | sudo xargs kill -9 echo "Closing leshan" sleep 1