mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-02-07 12:30:53 +00:00
Merge pull request #1162 from bthebaudeau/cc2538-add-coffee
cc2538: Add support for Coffee
This commit is contained in:
commit
6e481d56fa
@ -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
|
||||
|
||||
@ -110,7 +111,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.h" -imacros "cfs-coffee-arch.h"
|
||||
LDGENFLAGS += -x c -P -E
|
||||
|
||||
# NB: Assumes LDSCRIPT was not overridden and is in $(OBJECTDIR)
|
||||
|
@ -33,70 +33,61 @@
|
||||
* 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 = COFFEE_START + COFFEE_SIZE,
|
||||
LENGTH = FLASH_CCA_ADDR - (COFFEE_START + COFFEE_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
|
||||
}
|
||||
|
||||
ENTRY(flash_cca_lock_page)
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
_text = .;
|
||||
KEEP(*(.vectors))
|
||||
*(.vectors)
|
||||
*(.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,24 +95,22 @@ 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 :
|
||||
{
|
||||
KEEP(*(.flashcca))
|
||||
*(.flashcca)
|
||||
} > FLASH_CCA
|
||||
}
|
||||
|
144
cpu/cc2538/cfs-coffee-arch.c
Normal file
144
cpu/cc2538/cfs-coffee-arch.c
Normal file
@ -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 <stdint.h>
|
||||
|
||||
#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 */
|
||||
|
||||
/** @} */
|
182
cpu/cc2538/cfs-coffee-arch.h
Normal file
182
cpu/cc2538/cfs-coffee-arch.h
Normal file
@ -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 <stdint.h>
|
||||
|
||||
#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_ */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
126
cpu/cc2538/dev/cc2538-dev.h
Normal file
126
cpu/cc2538/dev/cc2538-dev.h
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.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-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_ */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -36,20 +36,36 @@
|
||||
* \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 <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \name Flash memory organization
|
||||
* @{
|
||||
*/
|
||||
#define FLASH_PAGE_SIZE 2048
|
||||
#define FLASH_WORD_SIZE 4
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \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
|
||||
* @{
|
||||
*/
|
||||
@ -85,7 +101,7 @@ typedef struct {
|
||||
} flash_cca_lock_page_t;
|
||||
/** @} */
|
||||
|
||||
#endif /* FLASH_CCA_H_ */
|
||||
#endif /* FLASH_H_ */
|
||||
|
||||
/**
|
||||
* @}
|
@ -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
|
||||
|
@ -48,18 +48,14 @@
|
||||
/** \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
|
||||
extern void(*const vectors[])(void);
|
||||
#define NVIC_VTABLE_ADDRESS ((uint32_t)&vectors)
|
||||
#endif
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -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"
|
||||
|
||||
@ -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")))
|
||||
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;
|
||||
|
@ -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 '/\<LOAD\>/{g;1!p;};h' | awk '{print "0x" $$5}' | sort -g | head -1) $<
|
||||
endif
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 '/\<LOAD\>/{g;1!p;};h' | awk '{print "0x" $$5}' | sort -g | head -1) $<
|
||||
endif
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user