From 790c253d6d3866ce0481691ae19bf12cede1e14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Thu, 18 Jun 2015 22:31:53 +0200 Subject: [PATCH 1/7] cc2538: Define and use device features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define the available CC2538 devices and their features, and use them to define the linker script memory regions. The .nrdata output section is now always defined in order to trigger an error if it is used but no memory is available for it. The CC2538 device used by Contiki is made a configuration option, the CC2538SF53 device being the default. This makes more sense than defining the flash memory address and size as configuration options like previously, all the more not all values are possible and all the features are linked by each device. This change also makes it possible to: - use the correct SRAM parameters for the CC2538NF11, - know at build time if the AES, SHA, ECC and RSA hardware features are available on the selected CC2538 device. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/Makefile.cc2538 | 3 +- cpu/cc2538/cc2538.lds | 66 +++++++--------- cpu/cc2538/dev/cc2538-dev.h | 126 +++++++++++++++++++++++++++++++ cpu/cc2538/dev/flash-cca.h | 10 +++ platform/cc2538dk/contiki-conf.h | 15 ---- platform/remote/contiki-conf.h | 15 ---- 6 files changed, 165 insertions(+), 70 deletions(-) create mode 100644 cpu/cc2538/dev/cc2538-dev.h diff --git a/cpu/cc2538/Makefile.cc2538 b/cpu/cc2538/Makefile.cc2538 index 0d4d3c73f..b555d7e8f 100644 --- a/cpu/cc2538/Makefile.cc2538 +++ b/cpu/cc2538/Makefile.cc2538 @@ -110,7 +110,8 @@ CUSTOM_RULE_LINK=1 ### This rule is used to generate the correct linker script LDGENFLAGS += $(addprefix -D,$(subst $(COMMA), ,$(DEFINES))) LDGENFLAGS += $(addprefix -I,$(SOURCEDIRS)) -LDGENFLAGS += -imacros "contiki-conf.h" +LDGENFLAGS += -imacros "contiki-conf.h" -imacros "dev/cc2538-dev.h" +LDGENFLAGS += -imacros "dev/flash-cca.h" LDGENFLAGS += -x c -P -E # NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR) diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index cfd4cb48c..a2dd0d209 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -33,40 +33,30 @@ * stage. Rather, it is used as input for the auto-generation of the actual * ld script, which is called cc2538.ld and will be in the project directory */ -#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0) -#define NRSRAM_START 0x20000000 -#define NRSRAM_LEN 0x00004000 -#define SRAM_START 0x20004000 -#define SRAM_LEN 0x00004000 -#else -#define SRAM_START 0x20000000 -#define SRAM_LEN 0x00008000 -#endif - -#ifdef FLASH_CONF_ORIGIN -#define FLASH_ORIGIN FLASH_CONF_ORIGIN -#else -#error FLASH_CONF_ORIGIN is not specified. Please define FLASH_CONF_ORIGIN in contiki-conf.h. -#endif - -#ifdef FLASH_CONF_SIZE -#define FLASH_SIZE FLASH_CONF_SIZE -#else -#error FLASH_CONF_SIZE is not specified. Please define FLASH_CONF_SIZE in contiki-conf.h. -#endif - -#define FLASH_CCA_LENGTH 44 -#define FLASH_LENGTH (FLASH_SIZE - FLASH_CCA_LENGTH) -#define FLASH_CCA_ORIGIN (FLASH_ORIGIN + FLASH_LENGTH) - MEMORY { - FLASH (rx) : ORIGIN = FLASH_ORIGIN, LENGTH = FLASH_LENGTH - FLASH_CCA (RX) : ORIGIN = FLASH_CCA_ORIGIN, LENGTH = FLASH_CCA_LENGTH -#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0) - NRSRAM (RWX) : ORIGIN = NRSRAM_START, LENGTH = NRSRAM_LEN + FLASH_FW (rx) : ORIGIN = CC2538_DEV_FLASH_ADDR, + LENGTH = CC2538_DEV_FLASH_SIZE - FLASH_CCA_SIZE + FLASH_CCA (RX) : ORIGIN = FLASH_CCA_ADDR, LENGTH = FLASH_CCA_SIZE + + /* + * If PM2 is enabled, then the PM2 SRAM limitations apply, i.e. the + * regular-leakage SRAM is a non-retention SRAM and the low-leakage SRAM is + * a full-retention SRAM. + * Else, the data in the regular-leakage SRAM is always retained, so there + * are virtually a non-retention SRAM with a size of 0 bytes and a + * full-retention SRAM spanning the whole SRAM, which is more convenient to + * use. + */ +#if LPM_CONF_ENABLE && LPM_CONF_MAX_PM >= 2 + NRSRAM (RWX) : ORIGIN = CC2538_DEV_RLSRAM_ADDR, + LENGTH = CC2538_DEV_RLSRAM_SIZE + FRSRAM (RWX) : ORIGIN = CC2538_DEV_LLSRAM_ADDR, + LENGTH = CC2538_DEV_LLSRAM_SIZE +#else + NRSRAM (RWX) : ORIGIN = CC2538_DEV_RLSRAM_ADDR, LENGTH = 0 + FRSRAM (RWX) : ORIGIN = CC2538_DEV_SRAM_ADDR, LENGTH = CC2538_DEV_SRAM_SIZE #endif - SRAM (RWX) : ORIGIN = SRAM_START, LENGTH = SRAM_LEN } SECTIONS @@ -78,25 +68,25 @@ SECTIONS *(.text*) *(.rodata*) _etext = .; - } > FLASH= 0 + } > FLASH_FW= 0 .socdata (NOLOAD) : { *(.udma_channel_control_table) - } > SRAM + } > FRSRAM .data : ALIGN(4) { _data = .; *(.data*) _edata = .; - } > SRAM AT > FLASH + } > FRSRAM AT > FLASH_FW _ldata = LOADADDR(.data); .ARM.exidx : { *(.ARM.exidx*) - } > FLASH + } > FLASH_FW .bss : { @@ -104,21 +94,19 @@ SECTIONS *(.bss*) *(COMMON) _ebss = .; - } > SRAM + } > FRSRAM .stack (NOLOAD) : { *(.stack) - } > SRAM + } > FRSRAM -#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0) .nrdata (NOLOAD) : { _nrdata = .; *(.nrdata*) _enrdata = .; } > NRSRAM -#endif .flashcca : { diff --git a/cpu/cc2538/dev/cc2538-dev.h b/cpu/cc2538/dev/cc2538-dev.h new file mode 100644 index 000000000..7bb81f662 --- /dev/null +++ b/cpu/cc2538/dev/cc2538-dev.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, Benoît Thébaudeau + * 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-devices cc2538 family of devices + * + * Definitions for the cc2538 family of devices + * @{ + * + * \file + * Header file for the cc2538 devices definitions + */ +#ifndef CC2538_DEV_H_ +#define CC2538_DEV_H_ + +#include "contiki-conf.h" +#include "sys/cc.h" +/*----------------------------------------------------------------------------*/ +/** \name Bit-fields for the CC2538 devices features + * @{ + */ +#define CC2538_DEV_ID_M 0x0000000F /**< ID mask */ +#define CC2538_DEV_ID_S 0 /**< ID shift */ +#define CC2538_DEV_FLASH_SIZE_KB_M 0x0000FFF0 /**< kiB flash size mask */ +#define CC2538_DEV_FLASH_SIZE_KB_S 4 /**< kiB flash size shift */ +#define CC2538_DEV_SRAM_SIZE_KB_M 0x00FF0000 /**< kiB SRAM size mask */ +#define CC2538_DEV_SRAM_SIZE_KB_S 16 /**< kiB SRAM size shift */ +#define CC2538_DEV_AES_SHA_M 0x01000000 /**< Security HW AES/SHA */ +#define CC2538_DEV_ECC_RSA_M 0x02000000 /**< Security HW ECC/RSA */ +/** @} */ +/*----------------------------------------------------------------------------*/ +/** \name Macro defining a CC2538 device from its features + * @{ + */ +#define CC2538_DEV_DEF(id, flash_size_kb, sram_size_kb, aes_sha, ecc_rsa) \ + ((id) << CC2538_DEV_ID_S | (flash_size_kb) << CC2538_DEV_FLASH_SIZE_KB_S | \ + (sram_size_kb) << CC2538_DEV_SRAM_SIZE_KB_S | \ + ((aes_sha) ? CC2538_DEV_AES_SHA_M : 0) | \ + ((ecc_rsa) ? CC2538_DEV_ECC_RSA_M : 0)) +/** @} */ +/*----------------------------------------------------------------------------*/ +/** \name Available CC2538 devices + * @{ + */ +#define CC2538_DEV_CC2538SF53 CC2538_DEV_DEF(0, 512, 32, 1, 1) +#define CC2538_DEV_CC2538SF23 CC2538_DEV_DEF(1, 256, 32, 1, 1) +#define CC2538_DEV_CC2538NF53 CC2538_DEV_DEF(2, 512, 32, 1, 0) +#define CC2538_DEV_CC2538NF23 CC2538_DEV_DEF(3, 256, 32, 1, 0) +#define CC2538_DEV_CC2538NF11 CC2538_DEV_DEF(4, 128, 16, 1, 0) +/** @} */ +/*----------------------------------------------------------------------------*/ +/** \name CC2538 device used by Contiki + * @{ + */ +#ifdef CC2538_DEV_CONF +#define CC2538_DEV CC2538_DEV_CONF +#else +#define CC2538_DEV CC2538_DEV_CC2538SF53 +#endif +/** @} */ +/*----------------------------------------------------------------------------*/ +/** \name Features of the CC2538 device used by Contiki + * @{ + */ +/** Flash address */ +#define CC2538_DEV_FLASH_ADDR 0x00200000 +/** Flash size in bytes */ +#define CC2538_DEV_FLASH_SIZE (((CC2538_DEV & CC2538_DEV_FLASH_SIZE_KB_M) >> \ + CC2538_DEV_FLASH_SIZE_KB_S) << 10) +/** SRAM (non-retention + low-leakage) address */ +#define CC2538_DEV_SRAM_ADDR (CC2538_DEV_RLSRAM_SIZE ? \ + CC2538_DEV_RLSRAM_ADDR : \ + CC2538_DEV_LLSRAM_ADDR) +/** SRAM (non-retention + low-leakage) size in bytes */ +#define CC2538_DEV_SRAM_SIZE (((CC2538_DEV & CC2538_DEV_SRAM_SIZE_KB_M) >> \ + CC2538_DEV_SRAM_SIZE_KB_S) << 10) +/** Regular-leakage SRAM address */ +#define CC2538_DEV_RLSRAM_ADDR 0x20000000 +/** Regular-leakage SRAM size in bytes */ +#define CC2538_DEV_RLSRAM_SIZE (CC2538_DEV_SRAM_SIZE - CC2538_DEV_LLSRAM_SIZE) +/** Low-leakage SRAM address */ +#define CC2538_DEV_LLSRAM_ADDR 0x20004000 +/** Low-leakage SRAM size in bytes */ +#define CC2538_DEV_LLSRAM_SIZE MIN(CC2538_DEV_SRAM_SIZE, 16384) +/** Security HW AES/SHA */ +#define CC2538_DEV_AES_SHA (!!(CC2538_DEV & CC2538_DEV_AES_SHA_M)) +/** Security HW ECC/RSA */ +#define CC2538_DEV_ECC_RSA (!!(CC2538_DEV & CC2538_DEV_ECC_RSA_M)) +/** @} */ + +#endif /* CC2538_DEV_H_ */ + +/** + * @} + * @} + */ diff --git a/cpu/cc2538/dev/flash-cca.h b/cpu/cc2538/dev/flash-cca.h index 2dff2978b..bbd5074be 100644 --- a/cpu/cc2538/dev/flash-cca.h +++ b/cpu/cc2538/dev/flash-cca.h @@ -48,8 +48,18 @@ #ifndef FLASH_CCA_H_ #define FLASH_CCA_H_ +#include "dev/cc2538-dev.h" + #include /*---------------------------------------------------------------------------*/ +/** \name Flash lock bit page and CCA location + * @{ + */ +#define FLASH_CCA_ADDR (CC2538_DEV_FLASH_ADDR + CC2538_DEV_FLASH_SIZE - \ + FLASH_CCA_SIZE) /**< Address */ +#define FLASH_CCA_SIZE 0x0000002C /**< Size in bytes */ +/** @} */ +/*---------------------------------------------------------------------------*/ /** \name Bootloader backdoor configuration bit fields * @{ */ diff --git a/platform/cc2538dk/contiki-conf.h b/platform/cc2538dk/contiki-conf.h index 7d5924de4..ddc3e3746 100644 --- a/platform/cc2538dk/contiki-conf.h +++ b/platform/cc2538dk/contiki-conf.h @@ -57,21 +57,6 @@ typedef uint32_t rtimer_clock_t; #define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH 0 /**< A logic low level activates the boot loader */ #endif /** @} */ - -/*---------------------------------------------------------------------------*/ -/** - * \name Flash Memory configuration - * - * @{ - */ -#ifndef FLASH_CONF_ORIGIN -#define FLASH_CONF_ORIGIN 0x00200000 -#endif - -#ifndef FLASH_CONF_SIZE -#define FLASH_CONF_SIZE 0x00080000 /* 512 KiB */ -#endif -/** @} */ /*---------------------------------------------------------------------------*/ /** * \name Watchdog Timer configuration diff --git a/platform/remote/contiki-conf.h b/platform/remote/contiki-conf.h index 10e689cdf..e5acdcb5d 100644 --- a/platform/remote/contiki-conf.h +++ b/platform/remote/contiki-conf.h @@ -57,21 +57,6 @@ typedef uint32_t rtimer_clock_t; #define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH 0 /**< A logic low level activates the boot loader */ #endif /** @} */ - -/*---------------------------------------------------------------------------*/ -/** - * \name Flash Memory configuration - * - * @{ - */ -#ifndef FLASH_CONF_ORIGIN -#define FLASH_CONF_ORIGIN 0x00200000 -#endif - -#ifndef FLASH_CONF_SIZE -#define FLASH_CONF_SIZE 0x00080000 /* 512 KiB */ -#endif -/** @} */ /*---------------------------------------------------------------------------*/ /** * \name Watchdog Timer configuration From efb4b858e24de48823be8c7ef1dbdebb140bfbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Thu, 25 Jun 2015 22:37:22 +0200 Subject: [PATCH 2/7] cc2538: Define the flash memory organization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define the flash memory page and word sizes. These definitions are grouped with the flash lock bit page and CCA definitions, so flash-cca.h is renamed to flash.h. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/Makefile.cc2538 | 2 +- cpu/cc2538/dev/{flash-cca.h => flash.h} | 20 +++++++++++++------- cpu/cc2538/startup-gcc.c | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) rename cpu/cc2538/dev/{flash-cca.h => flash.h} (91%) diff --git a/cpu/cc2538/Makefile.cc2538 b/cpu/cc2538/Makefile.cc2538 index b555d7e8f..bb70be6b5 100644 --- a/cpu/cc2538/Makefile.cc2538 +++ b/cpu/cc2538/Makefile.cc2538 @@ -111,7 +111,7 @@ CUSTOM_RULE_LINK=1 LDGENFLAGS += $(addprefix -D,$(subst $(COMMA), ,$(DEFINES))) LDGENFLAGS += $(addprefix -I,$(SOURCEDIRS)) LDGENFLAGS += -imacros "contiki-conf.h" -imacros "dev/cc2538-dev.h" -LDGENFLAGS += -imacros "dev/flash-cca.h" +LDGENFLAGS += -imacros "dev/flash.h" LDGENFLAGS += -x c -P -E # NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR) diff --git a/cpu/cc2538/dev/flash-cca.h b/cpu/cc2538/dev/flash.h similarity index 91% rename from cpu/cc2538/dev/flash-cca.h rename to cpu/cc2538/dev/flash.h index bbd5074be..6af19723e 100644 --- a/cpu/cc2538/dev/flash-cca.h +++ b/cpu/cc2538/dev/flash.h @@ -36,22 +36,28 @@ * \addtogroup cc2538 * @{ * - * \defgroup cc2538-flash-cca cc2538 flash CCA + * \defgroup cc2538-flash cc2538 flash memory * - * Definitions for the cc2538 flash lock bit page and customer configuration - * area + * Definitions for the cc2538 flash memory * @{ * * \file - * Header file for the flash lock bit page and CCA definitions + * Header file for the flash memory definitions */ -#ifndef FLASH_CCA_H_ -#define FLASH_CCA_H_ +#ifndef FLASH_H_ +#define FLASH_H_ #include "dev/cc2538-dev.h" #include /*---------------------------------------------------------------------------*/ +/** \name Flash memory organization + * @{ + */ +#define FLASH_PAGE_SIZE 2048 +#define FLASH_WORD_SIZE 4 +/** @} */ +/*---------------------------------------------------------------------------*/ /** \name Flash lock bit page and CCA location * @{ */ @@ -95,7 +101,7 @@ typedef struct { } flash_cca_lock_page_t; /** @} */ -#endif /* FLASH_CCA_H_ */ +#endif /* FLASH_H_ */ /** * @} diff --git a/cpu/cc2538/startup-gcc.c b/cpu/cc2538/startup-gcc.c index 0c0da7104..35c2329d2 100644 --- a/cpu/cc2538/startup-gcc.c +++ b/cpu/cc2538/startup-gcc.c @@ -38,7 +38,7 @@ */ #include "contiki.h" #include "reg.h" -#include "flash-cca.h" +#include "flash.h" #include "sys-ctrl.h" #include "rom-util.h" From a191fcdb84bb49e84933eed7c925330f5a051624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Fri, 26 Jun 2015 00:31:15 +0200 Subject: [PATCH 3/7] cc2538: nvic: Simplify VTABLE configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only thing needed for VTABLE is the absolute address of the vector table. Splitting it between code/SRAM base and offset complicates things and brings nothing. Consequently, this commit merges the NVIC VTABLE configurations into a single one giving the vector table absolute address. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/dev/nvic.c | 2 +- cpu/cc2538/dev/nvic.h | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/cpu/cc2538/dev/nvic.c b/cpu/cc2538/dev/nvic.c index 86e97c093..71e2414f8 100644 --- a/cpu/cc2538/dev/nvic.c +++ b/cpu/cc2538/dev/nvic.c @@ -57,7 +57,7 @@ nvic_init() interrupt_unpend = (uint32_t *)NVIC_UNPEND0; /* Provide our interrupt table to the NVIC */ - REG(SCB_VTABLE) = (NVIC_CONF_VTABLE_BASE + NVIC_CONF_VTABLE_OFFSET); + REG(SCB_VTABLE) = NVIC_VTABLE_ADDRESS; } /*---------------------------------------------------------------------------*/ void diff --git a/cpu/cc2538/dev/nvic.h b/cpu/cc2538/dev/nvic.h index b8c70b4a2..6c7563680 100644 --- a/cpu/cc2538/dev/nvic.h +++ b/cpu/cc2538/dev/nvic.h @@ -48,18 +48,13 @@ /** \name NVIC Constants and Configuration * @{ */ -#define NVIC_VTABLE_IN_SRAM 0x20000000 -#define NVIC_VTABLE_IN_CODE 0x00000000 - #define NVIC_INTERRUPT_ENABLED 0x00000001 #define NVIC_INTERRUPT_DISABLED 0x00000000 -#ifndef NVIC_CONF_VTABLE_BASE -#define NVIC_CONF_VTABLE_BASE NVIC_VTABLE_IN_CODE -#endif - -#ifndef NVIC_CONF_VTABLE_OFFSET -#define NVIC_CONF_VTABLE_OFFSET 0x200000 +#ifdef NVIC_CONF_VTABLE_ADDRESS +#define NVIC_VTABLE_ADDRESS NVIC_CONF_VTABLE_ADDRESS +#else +#define NVIC_VTABLE_ADDRESS 0x200000 #endif /** @} */ /*---------------------------------------------------------------------------*/ From 96dd24836c1057264a20f88c6b1de6b9db7304e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Wed, 1 Jul 2015 22:15:53 +0200 Subject: [PATCH 4/7] cc2538: Use &vectors instead of flash/.text start address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current CC2538 linker script in Contiki places the vector table at the beginning of the flash memory / .text output section. However, this location is arbitrary (the only requirement is that the vector table is 512-byte aligned), and custom linker scripts may be used with Contiki, which means that Contiki may be used with a vector table placed elsewhere. Thus, using the flash/.text start address in the CCA and as the default NVIC VTABLE value was wrong. This commit rather uses the address of the vectors[] array from startup-gcc.c, which makes it possible to freely move around the vector table without breaking anything or having to use a custom startup-gcc.c and to configure the NVIC driver for that. Moreover, referencing the vectors[] array naturally prevents it and its input section from being garbage-collected by the linker, so this commit also removes the now-unneeded "used" and "KEEP" keywords from the vector table. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/cc2538.lds | 2 +- cpu/cc2538/dev/nvic.h | 3 ++- cpu/cc2538/startup-gcc.c | 29 +++++++++++++---------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index a2dd0d209..60a37c796 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -64,7 +64,7 @@ SECTIONS .text : { _text = .; - KEEP(*(.vectors)) + *(.vectors) *(.text*) *(.rodata*) _etext = .; diff --git a/cpu/cc2538/dev/nvic.h b/cpu/cc2538/dev/nvic.h index 6c7563680..8f2f68259 100644 --- a/cpu/cc2538/dev/nvic.h +++ b/cpu/cc2538/dev/nvic.h @@ -54,7 +54,8 @@ #ifdef NVIC_CONF_VTABLE_ADDRESS #define NVIC_VTABLE_ADDRESS NVIC_CONF_VTABLE_ADDRESS #else -#define NVIC_VTABLE_ADDRESS 0x200000 +extern void(*const vectors[])(void); +#define NVIC_VTABLE_ADDRESS ((uint32_t)&vectors) #endif /** @} */ /*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2538/startup-gcc.c b/cpu/cc2538/startup-gcc.c index 35c2329d2..d3d6ec401 100644 --- a/cpu/cc2538/startup-gcc.c +++ b/cpu/cc2538/startup-gcc.c @@ -94,22 +94,7 @@ void pka_isr(void); /* Allocate stack space */ static unsigned long stack[512] __attribute__ ((section(".stack"))); /*---------------------------------------------------------------------------*/ -/* Linker construct indicating .text section location */ -extern uint8_t _text[0]; -/*---------------------------------------------------------------------------*/ -__attribute__ ((section(".flashcca"), used)) -const flash_cca_lock_page_t __cca = { - FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */ - FLASH_CCA_IMAGE_VALID, /* Image valid */ - &_text, /* Vector table located at the start of .text */ - /* Unlock all pages and debug */ - { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } -}; -/*---------------------------------------------------------------------------*/ -__attribute__ ((section(".vectors"), used)) +__attribute__((__section__(".vectors"))) void(*const vectors[])(void) = { (void (*)(void))((unsigned long)stack + sizeof(stack)), /* Stack pointer */ @@ -277,6 +262,18 @@ void(*const vectors[])(void) = default_handler, /* 162 MACTimer */ }; /*---------------------------------------------------------------------------*/ +__attribute__((__section__(".flashcca"), __used__)) +const flash_cca_lock_page_t flash_cca_lock_page = { + FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */ + FLASH_CCA_IMAGE_VALID, /* Image valid */ + &vectors, /* Vector table */ + /* Unlock all pages and debug */ + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } +}; +/*---------------------------------------------------------------------------*/ /* Linker constructs indicating .data and .bss segment locations */ extern uint8_t _ldata; extern uint8_t _data; From ee3ee049e44320d61f3d74f638cd572b2a55c16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Wed, 1 Jul 2015 22:20:13 +0200 Subject: [PATCH 5/7] cc2538: Set the entry point to the CCA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No entry point was defined, so it defaulted to the beginning of the .text output section where the vector table is located by default in Contiki. Actually, the vector table may be located elsewhere, and the ROM-based boot loader first reads the CCA to find the vector table. Consequently, this commit sets the entry point to the CCA, which fixes both the entry point and the initial symbol reference, so this commit also removes the now-unneeded "__used__" and "KEEP" keywords from the CCA. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/cc2538.lds | 3 ++- cpu/cc2538/startup-gcc.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index 60a37c796..adb7f6ccd 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -59,6 +59,7 @@ MEMORY #endif } +ENTRY(flash_cca_lock_page) SECTIONS { .text : @@ -110,6 +111,6 @@ SECTIONS .flashcca : { - KEEP(*(.flashcca)) + *(.flashcca) } > FLASH_CCA } diff --git a/cpu/cc2538/startup-gcc.c b/cpu/cc2538/startup-gcc.c index d3d6ec401..d01aefa50 100644 --- a/cpu/cc2538/startup-gcc.c +++ b/cpu/cc2538/startup-gcc.c @@ -262,7 +262,7 @@ void(*const vectors[])(void) = default_handler, /* 162 MACTimer */ }; /*---------------------------------------------------------------------------*/ -__attribute__((__section__(".flashcca"), __used__)) +__attribute__((__section__(".flashcca"))) const flash_cca_lock_page_t flash_cca_lock_page = { FLASH_CCA_BOOTLDR_CFG, /* Boot loader backdoor configuration */ FLASH_CCA_IMAGE_VALID, /* Image valid */ From cbcf1262d6e4d410255c668263f6f978e7122a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Tue, 17 Nov 2015 23:28:38 +0100 Subject: [PATCH 6/7] cc2538: upload: Support .bin not starting at beginning of flash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Depending on the linker script, the generated .bin file may start beyond the beginning of the flash memory. However, no target address was passed to cc2538-bsl.py by the upload make target, so it used the beginning of the flash memory in all cases. The load address of the lowest loadable output section is now passed to cc2538-bsl.py. The start address of the .text output section or the address of the _text symbol could have been used too, but this would not have been compatible with all the possible custom linker scripts. Signed-off-by: Benoît Thébaudeau --- platform/cc2538dk/Makefile.cc2538dk | 4 ++-- platform/remote/Makefile.remote | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/cc2538dk/Makefile.cc2538dk b/platform/cc2538dk/Makefile.cc2538dk index 5c3fd77ec..f962a0fa7 100644 --- a/platform/cc2538dk/Makefile.cc2538dk +++ b/platform/cc2538dk/Makefile.cc2538dk @@ -30,9 +30,9 @@ MODULES += core/net core/net/mac \ BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -%.upload: %.bin +%.upload: %.bin %.elf ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else - python $(BSL) -e -w -v $< + python $(BSL) -e -w -v -a $$($(OBJDUMP) -h $*.elf | sed -n '/\/{g;1!p;};h' | awk '{print "0x" $$5}' | sort -g | head -1) $< endif diff --git a/platform/remote/Makefile.remote b/platform/remote/Makefile.remote index a9acc1dbc..3d351bfdd 100644 --- a/platform/remote/Makefile.remote +++ b/platform/remote/Makefile.remote @@ -38,9 +38,9 @@ MODULES += core/net core/net/mac \ BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -%.upload: %.bin +%.upload: %.bin %.elf ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else - $(PYTHON) $(BSL) $(BSL_FLAGS) $< + $(PYTHON) $(BSL) $(BSL_FLAGS) -a $$($(OBJDUMP) -h $*.elf | sed -n '/\/{g;1!p;};h' | awk '{print "0x" $$5}' | sort -g | head -1) $< endif From 5d98cb71e2468be25738a4696e358ce55cd2017b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Sun, 12 Jul 2015 21:48:18 +0200 Subject: [PATCH 7/7] cc2538: Add support for Coffee MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coffee is placed by default at the beginning of the flash memory, right before the firmware. This avoids the memory gaps that there could be before and after Coffee if it were placed after the firmware, because it is unlikely that the end of the firmware is aligned with a flash page boundary, and the CCA is not flash-page-aligned. Thanks to that, Coffee is also always in the same flash area if its size remains unchanged, even if the firmware changes, which makes it possible to keep the Coffee files when reprogramming the firmware after a partial flash erase command. The default configuration of Coffee is set to use sensible values for a typical usage on this SoC, i.e. for sensor data logging. The default size of Coffee is set to 0 in order not to waste flash if Coffee is unused. COFFEE_CONF_CUSTOM_PORT can be defined to a header file to be used with "#include" in order to override the default CC2538 port of Coffee. This makes it possible to use Coffee with an external memory device rather than with the internal flash memory, without having to alter the Contiki files. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/Makefile.cc2538 | 3 +- cpu/cc2538/cc2538.lds | 4 +- cpu/cc2538/cfs-coffee-arch.c | 144 +++++++++++++++++++++++++++ cpu/cc2538/cfs-coffee-arch.h | 182 +++++++++++++++++++++++++++++++++++ platform/cc2538dk/README.md | 1 + platform/remote/README.md | 1 + 6 files changed, 332 insertions(+), 3 deletions(-) create mode 100644 cpu/cc2538/cfs-coffee-arch.c create mode 100644 cpu/cc2538/cfs-coffee-arch.h diff --git a/cpu/cc2538/Makefile.cc2538 b/cpu/cc2538/Makefile.cc2538 index bb70be6b5..873bf9779 100644 --- a/cpu/cc2538/Makefile.cc2538 +++ b/cpu/cc2538/Makefile.cc2538 @@ -60,6 +60,7 @@ CONTIKI_CPU_SOURCEFILES += ecc-curve.c CONTIKI_CPU_SOURCEFILES += dbg.c ieee-addr.c 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 DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c @@ -111,7 +112,7 @@ CUSTOM_RULE_LINK=1 LDGENFLAGS += $(addprefix -D,$(subst $(COMMA), ,$(DEFINES))) LDGENFLAGS += $(addprefix -I,$(SOURCEDIRS)) LDGENFLAGS += -imacros "contiki-conf.h" -imacros "dev/cc2538-dev.h" -LDGENFLAGS += -imacros "dev/flash.h" +LDGENFLAGS += -imacros "dev/flash.h" -imacros "cfs-coffee-arch.h" LDGENFLAGS += -x c -P -E # NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR) diff --git a/cpu/cc2538/cc2538.lds b/cpu/cc2538/cc2538.lds index adb7f6ccd..ce90ebfa6 100644 --- a/cpu/cc2538/cc2538.lds +++ b/cpu/cc2538/cc2538.lds @@ -35,8 +35,8 @@ */ MEMORY { - FLASH_FW (rx) : ORIGIN = CC2538_DEV_FLASH_ADDR, - LENGTH = CC2538_DEV_FLASH_SIZE - FLASH_CCA_SIZE + FLASH_FW (rx) : ORIGIN = COFFEE_START + COFFEE_SIZE, + LENGTH = FLASH_CCA_ADDR - (COFFEE_START + COFFEE_SIZE) FLASH_CCA (RX) : ORIGIN = FLASH_CCA_ADDR, LENGTH = FLASH_CCA_SIZE /* diff --git a/cpu/cc2538/cfs-coffee-arch.c b/cpu/cc2538/cfs-coffee-arch.c new file mode 100644 index 000000000..6d3664f5b --- /dev/null +++ b/cpu/cc2538/cfs-coffee-arch.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2013, ADVANSEE - http://www.advansee.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-cfs-coffee-arch + * @{ + * + * \file + * Module for the cc2538 Coffee port + */ +#include "contiki-conf.h" +#include "sys/cc.h" +#include "cfs/cfs-coffee.h" +#include "dev/cc2538-dev.h" +#include "dev/rom-util.h" +#include "dev/flash.h" +#include "dev/watchdog.h" +#include "cpu.h" +#include "cfs-coffee-arch.h" + +#include + +#ifndef COFFEE_CONF_CUSTOM_PORT +/*---------------------------------------------------------------------------*/ +#if !COFFEE_SECTOR_SIZE || COFFEE_SECTOR_SIZE % FLASH_PAGE_SIZE +#error COFFEE_SECTOR_SIZE must be a non-zero multiple of the flash page size +#endif +#if !COFFEE_PAGE_SIZE || COFFEE_SECTOR_SIZE % COFFEE_PAGE_SIZE +#error COFFEE_PAGE_SIZE must be a divisor of COFFEE_SECTOR_SIZE +#endif +#if COFFEE_PAGE_SIZE % FLASH_WORD_SIZE +#error COFFEE_PAGE_SIZE must be a multiple of the flash word size +#endif +#if COFFEE_START % FLASH_PAGE_SIZE +#error COFFEE_START must be aligned with a flash page boundary +#endif +#if COFFEE_SIZE % COFFEE_SECTOR_SIZE +#error COFFEE_SIZE must be a multiple of COFFEE_SECTOR_SIZE +#endif +#if COFFEE_SIZE / COFFEE_PAGE_SIZE > INT16_MAX +#error Too many Coffee pages for coffee_page_t +#endif +#if COFFEE_START < CC2538_DEV_FLASH_ADDR || \ + COFFEE_START + COFFEE_SIZE > FLASH_CCA_ADDR +#error Coffee does not fit in flash +#endif +/*---------------------------------------------------------------------------*/ +void +cfs_coffee_arch_erase(uint16_t sector) +{ + watchdog_periodic(); + INTERRUPTS_DISABLE(); + rom_util_page_erase(COFFEE_START + sector * COFFEE_SECTOR_SIZE, + COFFEE_SECTOR_SIZE); + INTERRUPTS_ENABLE(); +} +/*---------------------------------------------------------------------------*/ +void +cfs_coffee_arch_write(const void *buf, unsigned int size, cfs_offset_t offset) +{ + const uint32_t *src = buf; + uint32_t flash_addr = COFFEE_START + offset; + unsigned int align; + uint32_t word, len; + uint32_t page_buf[COFFEE_PAGE_SIZE / FLASH_WORD_SIZE]; + unsigned int i; + + if(size && (align = flash_addr & (FLASH_WORD_SIZE - 1))) { + len = MIN(FLASH_WORD_SIZE - align, size); + word = ~((*src & ((1 << (len << 3)) - 1)) << (align << 3)); + watchdog_periodic(); + INTERRUPTS_DISABLE(); + rom_util_program_flash(&word, flash_addr & ~(FLASH_WORD_SIZE - 1), + FLASH_WORD_SIZE); + INTERRUPTS_ENABLE(); + *(const uint8_t **)&src += len; + size -= len; + flash_addr += len; + } + + while(size >= FLASH_WORD_SIZE) { + len = MIN(size & ~(FLASH_WORD_SIZE - 1), COFFEE_PAGE_SIZE); + for(i = 0; i < len / FLASH_WORD_SIZE; i++) { + page_buf[i] = ~*src++; + } + watchdog_periodic(); + INTERRUPTS_DISABLE(); + rom_util_program_flash(page_buf, flash_addr, len); + INTERRUPTS_ENABLE(); + size -= len; + flash_addr += len; + } + + if(size) { + word = ~(*src & ((1 << (size << 3)) - 1)); + watchdog_periodic(); + INTERRUPTS_DISABLE(); + rom_util_program_flash(&word, flash_addr, FLASH_WORD_SIZE); + INTERRUPTS_ENABLE(); + } +} +/*---------------------------------------------------------------------------*/ +void +cfs_coffee_arch_read(void *buf, unsigned int size, cfs_offset_t offset) +{ + const uint8_t *src; + uint8_t *dst; + + watchdog_periodic(); + for(src = (const void *)(COFFEE_START + offset), dst = buf; size; size--) { + *dst++ = ~*src++; + } +} + +#endif /* COFFEE_CONF_CUSTOM_PORT */ + +/** @} */ diff --git a/cpu/cc2538/cfs-coffee-arch.h b/cpu/cc2538/cfs-coffee-arch.h new file mode 100644 index 000000000..9d53994e5 --- /dev/null +++ b/cpu/cc2538/cfs-coffee-arch.h @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2013, ADVANSEE - http://www.advansee.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-cfs-coffee-arch cc2538 Coffee port module + * + * Module for the cc2538 Coffee port + * @{ + * + * \file + * Header file for the cc2538 Coffee port module + */ +#ifndef CFS_COFFEE_ARCH_H_ +#define CFS_COFFEE_ARCH_H_ + +#include "contiki-conf.h" +#include "cfs/cfs-coffee.h" +#include "dev/cc2538-dev.h" +#include "dev/flash.h" + +#include + +#ifdef COFFEE_CONF_CUSTOM_PORT +#include COFFEE_CONF_CUSTOM_PORT +#else +/*---------------------------------------------------------------------------*/ +/** \name Coffee port constants + * @{ + */ +/** Logical sector size */ +#ifdef COFFEE_CONF_SECTOR_SIZE +#define COFFEE_SECTOR_SIZE COFFEE_CONF_SECTOR_SIZE +#else +#define COFFEE_SECTOR_SIZE FLASH_PAGE_SIZE +#endif +/** Logical page size */ +#ifdef COFFEE_CONF_PAGE_SIZE +#define COFFEE_PAGE_SIZE COFFEE_CONF_PAGE_SIZE +#else +#define COFFEE_PAGE_SIZE (COFFEE_SECTOR_SIZE / 8) +#endif +/** Start offset of the file system */ +#ifdef COFFEE_CONF_START +#define COFFEE_START COFFEE_CONF_START +#else +#define COFFEE_START CC2538_DEV_FLASH_ADDR +#endif +/** Total size in bytes of the file system */ +#ifdef COFFEE_CONF_SIZE +#define COFFEE_SIZE COFFEE_CONF_SIZE +#else +#define COFFEE_SIZE 0 +#endif +/** Maximal filename length */ +#ifdef COFFEE_CONF_NAME_LENGTH +#define COFFEE_NAME_LENGTH COFFEE_CONF_NAME_LENGTH +#else +#define COFFEE_NAME_LENGTH 40 +#endif +/** Number of file cache entries */ +#ifdef COFFEE_CONF_MAX_OPEN_FILES +#define COFFEE_MAX_OPEN_FILES COFFEE_CONF_MAX_OPEN_FILES +#else +#define COFFEE_MAX_OPEN_FILES 5 +#endif +/** Number of file descriptor entries */ +#ifdef COFFEE_CONF_FD_SET_SIZE +#define COFFEE_FD_SET_SIZE COFFEE_CONF_FD_SET_SIZE +#else +#define COFFEE_FD_SET_SIZE 5 +#endif +/** Maximal amount of log table entries read in one batch */ +#ifdef COFFEE_CONF_LOG_TABLE_LIMIT +#define COFFEE_LOG_TABLE_LIMIT COFFEE_CONF_LOG_TABLE_LIMIT +#endif +/** Default reserved file size */ +#ifdef COFFEE_CONF_DYN_SIZE +#define COFFEE_DYN_SIZE COFFEE_CONF_DYN_SIZE +#else +#define COFFEE_DYN_SIZE (COFFEE_SECTOR_SIZE - 50) +#endif +/** Default micro-log size */ +#ifdef COFFEE_CONF_LOG_SIZE +#define COFFEE_LOG_SIZE COFFEE_CONF_LOG_SIZE +#endif +/** Whether Coffee will use micro logs */ +#ifdef COFFEE_CONF_MICRO_LOGS +#define COFFEE_MICRO_LOGS COFFEE_CONF_MICRO_LOGS +#else +#define COFFEE_MICRO_LOGS 0 +#endif +/** Whether files are expected to be appended to only */ +#ifdef COFFEE_CONF_APPEND_ONLY +#define COFFEE_APPEND_ONLY COFFEE_CONF_APPEND_ONLY +#else +#define COFFEE_APPEND_ONLY 1 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Coffee port macros + * @{ + */ +/** Erase */ +#define COFFEE_ERASE(sector) \ + cfs_coffee_arch_erase(sector) +/** Write */ +#define COFFEE_WRITE(buf, size, offset) \ + cfs_coffee_arch_write((buf), (size), (offset)) +/** Read */ +#define COFFEE_READ(buf, size, offset) \ + cfs_coffee_arch_read((buf), (size), (offset)) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Coffee port types + * @{ + */ +typedef int16_t coffee_page_t; /**< Page */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Coffee port functions + * @{ + */ + +/** \brief Erases a device sector + * \param sector Sector to erase + */ +void cfs_coffee_arch_erase(uint16_t sector); + +/** \brief Writes a buffer to the device + * \param buf Pointer to the buffer + * \param size Byte size of the buffer + * \param offset Device offset to write to + */ +void cfs_coffee_arch_write(const void *buf, unsigned int size, + cfs_offset_t offset); + +/** \brief Reads from the device to a buffer + * \param buf Pointer to the buffer + * \param size Byte size of the buffer + * \param offset Device offset to read from + */ +void cfs_coffee_arch_read(void *buf, unsigned int size, cfs_offset_t offset); + +/** @} */ + +#endif /* COFFEE_CONF_CUSTOM_PORT */ +#endif /* CFS_COFFEE_ARCH_H_ */ + +/** + * @} + * @} + */ diff --git a/platform/cc2538dk/README.md b/platform/cc2538dk/README.md index 295777c8e..904ba7d7f 100644 --- a/platform/cc2538dk/README.md +++ b/platform/cc2538dk/README.md @@ -31,6 +31,7 @@ In terms of hardware support, the following drivers have been implemented: * ADC * Cryptoprocessor (AES-CCM-256, SHA-256) * Public Key Accelerator (ECDH, ECDSA) + * Flash-based port of Coffee * SmartRF06 EB and BB peripherals * LEDs * Buttons diff --git a/platform/remote/README.md b/platform/remote/README.md index 387591caa..19594be56 100644 --- a/platform/remote/README.md +++ b/platform/remote/README.md @@ -46,6 +46,7 @@ In terms of hardware support, the following drivers have been implemented: * ADC * Cryptoprocessor (AES-CCM-256, SHA-256) * Public Key Accelerator (ECDH, ECDSA) + * Flash-based port of Coffee * LEDs * Buttons * Internal/external 2.4GHz antenna switch controllable by SW.