Merge branch 'release-4.1' into contrib/native/button-hal
This commit is contained in:
commit
6fa97286b3
@ -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),)
|
||||
@ -263,7 +265,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),)
|
||||
@ -288,15 +291,23 @@ sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||
rm -f $(@:.o=.$$$$)
|
||||
endef
|
||||
|
||||
clean:
|
||||
-rm -f *~ *core core *.srec \
|
||||
*.lst *.map *.o \
|
||||
*.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
|
||||
rm -rf $(CLEAN)
|
||||
-rm -rf $(OBJECTDIR)
|
||||
### Harmonize filename of a .map file, if the platform's build system wants
|
||||
### to create one
|
||||
CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@))
|
||||
|
||||
distclean: clean
|
||||
-rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)}
|
||||
.PHONY: clean distclean usage help targets boards savetarget savedefines viewconf
|
||||
|
||||
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:
|
||||
@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)
|
||||
|
||||
@ -351,7 +362,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
|
||||
@ -361,7 +372,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 $@
|
||||
@ -374,7 +385,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)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Contiki-NG: The OS for Next Generation IoT Devices
|
||||
|
||||
[![Build Status](https://travis-ci.org/contiki-ng/contiki-ng.svg?branch=master)](https://travis-ci.org/contiki-ng/contiki-ng/branches)
|
||||
[![License](https://img.shields.io/badge/License-3--Clause%20BSD-brightgreen.svg)](https://github.com/contiki-ng/contiki-ng/blob/master/LICENSE.md)
|
||||
[![license](https://img.shields.io/badge/license-3--clause%20bsd-brightgreen.svg)](https://github.com/contiki-ng/contiki-ng/blob/master/LICENSE.md)
|
||||
[![Latest release](https://img.shields.io/github/release/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/releases/latest)
|
||||
[![GitHub Release Date](https://img.shields.io/github/release-date/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/releases/latest)
|
||||
[![Last commit](https://img.shields.io/github/last-commit/contiki-ng/contiki-ng.svg)](https://github.com/contiki-ng/contiki-ng/commit/HEAD)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 $@
|
||||
|
||||
|
@ -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 spi-legacy.c adc.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
|
||||
|
@ -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"
|
||||
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#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 { \
|
||||
|
@ -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"
|
||||
|
||||
@ -120,7 +120,7 @@
|
||||
} while(0)
|
||||
#define SPIX_FLUSH(spi) do { \
|
||||
while(REG(SSI_BASE(spi) + SSI_SR) & SSI_SR_RNE) { \
|
||||
SPIX_BUF(spi); \
|
||||
SPIX_BUF(spi); \
|
||||
} \
|
||||
} while(0)
|
||||
#define SPIX_CS_CLR(port, pin) do { \
|
||||
@ -138,13 +138,13 @@
|
||||
#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-legacy.h for the CC2538
|
||||
#else
|
||||
#define SPI_FLUSH() SPIX_FLUSH(SPI_DEFAULT_INSTANCE)
|
||||
#endif
|
||||
#define SPI_CS_CLR(port, pin) SPIX_CS_CLR(port, pin)
|
||||
#define SPI_CS_SET(port, pin) SPIX_CS_SET(port, pin)
|
||||
#endif /* #ifdef SPI_DEFAULT_INSTANCE */
|
||||
#endif /* #ifdef SPI_DEFAULT_INSTANCE */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \name Arch-specific SPI functions
|
||||
* @{
|
||||
@ -215,7 +215,7 @@ void spix_cs_init(uint8_t port, uint8_t pin);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* SPI_ARCH_H_ */
|
||||
#endif /* SPI_ARCH_LEGACY_H_ */
|
||||
|
||||
/**
|
||||
* @}
|
355
arch/cpu/cc2538/dev/spi-arch.c
Normal file
355
arch/cpu/cc2538/dev/spi-arch.c
Normal file
@ -0,0 +1,355 @@
|
||||
/*
|
||||
* 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 <stdint.h>
|
||||
#include "contiki.h"
|
||||
#include "reg.h"
|
||||
#include "dev/spi.h"
|
||||
#include "gpio-hal-arch.h"
|
||||
#include "sys/cc.h"
|
||||
#include "ioc.h"
|
||||
#include "sys-ctrl.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
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* 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
|
||||
|
||||
#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
|
||||
* 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 = 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 = SPI_ARCH_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[SPI_CONTROLLER_COUNT] = { { 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));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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_lock_and_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 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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* 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));
|
||||
|
||||
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_and_unlock(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);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -39,11 +39,11 @@
|
||||
*/
|
||||
#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"
|
||||
#include "dev/spi.h"
|
||||
#include "dev/spi-legacy.h"
|
||||
#include "dev/ssi.h"
|
||||
#include "dev/gpio.h"
|
||||
/*---------------------------------------------------------------------------*/
|
@ -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-arch.c
|
||||
|
||||
MODULES += os/lib/dbg-io
|
||||
|
||||
|
@ -104,5 +104,7 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define SPI_CONF_CONTROLLER_COUNT 2
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* CC13XX_CC26XX_DEF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
237
arch/cpu/cc26xx-cc13xx/dev/spi-arch.c
Normal file
237
arch/cpu/cc26xx-cc13xx/dev/spi-arch.c
Normal file
@ -0,0 +1,237 @@
|
||||
/*
|
||||
* 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 "contiki.h"
|
||||
#include "ti-lib.h"
|
||||
#include "dev/spi.h"
|
||||
#include "sys/mutex.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
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[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,
|
||||
.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
|
||||
}
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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_lock_and_open(spi_device_t *dev)
|
||||
{
|
||||
uint32_t c;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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_and_unlock(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);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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;
|
||||
}
|
@ -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
|
||||
@ -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
|
||||
@ -197,7 +200,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)
|
||||
@ -220,8 +223,8 @@ $(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
|
||||
java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $<
|
||||
%.mspsim-maptable: %.$(TARGET)
|
||||
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
|
||||
|
@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/spi.h"
|
||||
#include "dev/spi-legacy.h"
|
||||
#include "cc2420.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -21,12 +21,12 @@ CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR)
|
||||
CFLAGS += $(CFLAGSNO)
|
||||
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
AROPTS = -r
|
||||
LDFLAGS += -Wl,-flat_namespace
|
||||
AROPTS = -rc
|
||||
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
|
||||
|
||||
|
@ -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
|
||||
@ -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:
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
11
arch/dev/ext-flash/README.md
Normal file
11
arch/dev/ext-flash/README.md
Normal file
@ -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`.
|
@ -38,12 +38,34 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "ext-flash.h"
|
||||
#include "ti-lib.h"
|
||||
#include "board-spi.h"
|
||||
#include "dev/spi.h"
|
||||
#include "gpio-hal.h"
|
||||
#include "sys/log.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#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,38 +94,53 @@
|
||||
|
||||
#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
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* 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 void
|
||||
select_on_bus(void)
|
||||
static bool
|
||||
select_on_bus(spi_device_t *flash_spi_configuration)
|
||||
{
|
||||
ti_lib_gpio_clear_dio(BOARD_IOID_FLASH_CS);
|
||||
if(spi_select(flash_spi_configuration) == SPI_DEV_STATUS_OK) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Set external flash CSN line
|
||||
*/
|
||||
static void
|
||||
deselect(void)
|
||||
deselect(spi_device_t *flash_spi_configuration)
|
||||
{
|
||||
ti_lib_gpio_set_dio(BOARD_IOID_FLASH_CS);
|
||||
spi_deselect(flash_spi_configuration);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
@ -111,20 +148,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 };
|
||||
|
||||
select_on_bus();
|
||||
if(select_on_bus(flash_spi_configuration) == 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) {
|
||||
deselect();
|
||||
if(ret != SPI_DEV_STATUS_OK) {
|
||||
deselect(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -135,19 +171,20 @@ 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();
|
||||
deselect(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(buf & BLS_STATUS_BIT_BUSY)) {
|
||||
/* Now ready */
|
||||
break;
|
||||
}
|
||||
}
|
||||
deselect();
|
||||
deselect(flash_spi_configuration);
|
||||
return true;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@ -159,32 +196,30 @@ 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;
|
||||
|
||||
select_on_bus();
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return VERIFY_PART_LOCKED;
|
||||
}
|
||||
|
||||
ret = board_spi_write(wbuf, sizeof(wbuf));
|
||||
|
||||
if(ret == false) {
|
||||
deselect();
|
||||
if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) {
|
||||
deselect(flash_spi_configuration);
|
||||
return VERIFY_PART_ERROR;
|
||||
}
|
||||
|
||||
ret = board_spi_read(rbuf, sizeof(rbuf));
|
||||
deselect();
|
||||
|
||||
if(ret == false) {
|
||||
ret = spi_read(flash_spi_configuration, rbuf, sizeof(rbuf));
|
||||
deselect(flash_spi_configuration);
|
||||
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,34 +229,41 @@ verify_part(void)
|
||||
* \brief Put the device in power save mode. No access to data; only
|
||||
* the status register is accessible.
|
||||
*/
|
||||
static void
|
||||
power_down(void)
|
||||
static bool
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
cmd = BLS_CODE_PD;
|
||||
select_on_bus();
|
||||
board_spi_write(&cmd, sizeof(cmd));
|
||||
deselect();
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(spi_write_byte(flash_spi_configuration, cmd) != SPI_DEV_STATUS_OK) {
|
||||
deselect(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Should not be required */
|
||||
deselect();
|
||||
deselect(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
@ -229,20 +271,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;
|
||||
select_on_bus();
|
||||
success = board_spi_write(&cmd, sizeof(cmd));
|
||||
|
||||
if(success) {
|
||||
success = wait_ready() == true ? true : false;
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
deselect();
|
||||
success = (spi_write(flash_spi_configuration, &cmd, sizeof(cmd)) == SPI_DEV_STATUS_OK);
|
||||
|
||||
if(success) {
|
||||
success = wait_ready(flash_spi_configuration) == true ? true : false;
|
||||
}
|
||||
|
||||
deselect(flash_spi_configuration);
|
||||
|
||||
return success;
|
||||
}
|
||||
@ -252,14 +297,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 };
|
||||
|
||||
select_on_bus();
|
||||
ret = board_spi_write(wbuf, sizeof(wbuf));
|
||||
deselect();
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = (spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) == SPI_DEV_STATUS_OK);
|
||||
deselect(flash_spi_configuration);
|
||||
|
||||
if(ret == false) {
|
||||
return false;
|
||||
@ -268,39 +316,66 @@ write_enable(void)
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
bool
|
||||
ext_flash_open()
|
||||
ext_flash_open(spi_device_t *conf)
|
||||
{
|
||||
board_spi_open(4000000, BOARD_IOID_SPI_CLK_FLASH);
|
||||
spi_device_t *flash_spi_configuration;
|
||||
|
||||
/* GPIO pin configuration */
|
||||
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_FLASH_CS);
|
||||
flash_spi_configuration = get_spi_conf(conf);
|
||||
|
||||
/* Check if platform has ext-flash */
|
||||
if(flash_spi_configuration->pin_spi_sck == GPIO_HAL_PIN_UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(spi_acquire(flash_spi_configuration) != SPI_DEV_STATUS_OK) {
|
||||
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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ext_flash_close()
|
||||
{
|
||||
/* Put the part in low power mode */
|
||||
power_down();
|
||||
if(verify_part(flash_spi_configuration) == VERIFY_PART_OK) {
|
||||
return true;
|
||||
}
|
||||
|
||||
board_spi_close();
|
||||
/* Failed to verify */
|
||||
spi_release(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
bool
|
||||
ext_flash_read(size_t offset, size_t length, uint8_t *buf)
|
||||
ext_flash_close(spi_device_t *conf)
|
||||
{
|
||||
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 ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
bool
|
||||
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 */
|
||||
bool ret = wait_ready();
|
||||
if(ret == false) {
|
||||
if(wait_ready(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -313,41 +388,44 @@ 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(board_spi_write(wbuf, sizeof(wbuf)) == false) {
|
||||
/* failure */
|
||||
deselect();
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = board_spi_read(buf, length);
|
||||
if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) {
|
||||
/* failure */
|
||||
deselect(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
|
||||
deselect();
|
||||
ret = (spi_read(flash_spi_configuration, buf, length) == SPI_DEV_STATUS_OK);
|
||||
|
||||
deselect(flash_spi_configuration);
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
bool
|
||||
ext_flash_write(size_t offset, size_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];
|
||||
bool ret;
|
||||
size_t ilen; /* interim length per instruction */
|
||||
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 */
|
||||
ret = wait_ready();
|
||||
if(ret == false) {
|
||||
if(wait_ready(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = write_enable();
|
||||
if(ret == false) {
|
||||
if(write_enable(flash_spi_configuration) == 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,28 +443,30 @@ 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(board_spi_write(wbuf, sizeof(wbuf)) == false) {
|
||||
/* failure */
|
||||
deselect();
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(board_spi_write(buf, ilen) == 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(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
buf += ilen;
|
||||
deselect();
|
||||
deselect(flash_spi_configuration);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
bool
|
||||
ext_flash_erase(size_t offset, size_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
|
||||
@ -394,24 +474,25 @@ 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;
|
||||
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;
|
||||
|
||||
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(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = write_enable();
|
||||
if(ret == false) {
|
||||
if(write_enable(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -419,37 +500,37 @@ ext_flash_erase(size_t offset, size_t length)
|
||||
wbuf[2] = (offset >> 8) & 0xff;
|
||||
wbuf[3] = offset & 0xff;
|
||||
|
||||
select_on_bus();
|
||||
|
||||
if(board_spi_write(wbuf, sizeof(wbuf)) == false) {
|
||||
/* failure */
|
||||
deselect();
|
||||
if(select_on_bus(flash_spi_configuration) == false) {
|
||||
return false;
|
||||
}
|
||||
deselect();
|
||||
|
||||
offset += BLS_ERASE_SECTOR_SIZE;
|
||||
if(spi_write(flash_spi_configuration, wbuf, sizeof(wbuf)) != SPI_DEV_STATUS_OK) {
|
||||
/* failure */
|
||||
deselect(flash_spi_configuration);
|
||||
return false;
|
||||
}
|
||||
deselect(flash_spi_configuration);
|
||||
|
||||
offset += EXT_FLASH_ERASE_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
bool
|
||||
ext_flash_test(void)
|
||||
ext_flash_init(spi_device_t *conf)
|
||||
{
|
||||
bool ret;
|
||||
if(ext_flash_open(conf) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = ext_flash_open();
|
||||
ext_flash_close();
|
||||
if(ext_flash_close(conf) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
ext_flash_init()
|
||||
{
|
||||
ext_flash_open();
|
||||
ext_flash_close();
|
||||
LOG_INFO("Flash init successful\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
@ -42,25 +42,30 @@
|
||||
#ifndef EXT_FLASH_H_
|
||||
#define EXT_FLASH_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "dev/spi.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Initialize storage driver.
|
||||
* \param conf 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 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).
|
||||
*/
|
||||
void ext_flash_close(void);
|
||||
bool ext_flash_close(spi_device_t *conf);
|
||||
|
||||
/**
|
||||
* \brief Read storage content
|
||||
* \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
|
||||
@ -68,10 +73,11 @@ 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(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf);
|
||||
|
||||
/**
|
||||
* \brief Erase storage sectors corresponding to the range.
|
||||
* \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.
|
||||
@ -79,26 +85,22 @@ 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(spi_device_t *conf, uint32_t offset, uint32_t length);
|
||||
|
||||
/**
|
||||
* \brief Write to storage sectors.
|
||||
* \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
|
||||
*
|
||||
* \return True when successful.
|
||||
*/
|
||||
bool ext_flash_write(size_t offset, size_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 conf SPI bus configuration struct. NULL for default.
|
||||
*
|
||||
* This function will explicitly put the part in its lowest power mode
|
||||
* (power-down).
|
||||
@ -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_ */
|
||||
/*---------------------------------------------------------------------------*/
|
@ -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
|
||||
|
@ -57,5 +57,3 @@ const leds_t leds_arch_leds[] = {
|
||||
#endif
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -64,6 +64,8 @@ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
CLEAN += COOJA.log
|
||||
|
||||
### Define the CPU directory
|
||||
CONTIKI_CPU=$(CONTIKI)/arch/cpu/x86
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
@ -140,7 +142,6 @@ ifdef nodemac
|
||||
CFLAGS += -DMACID=$(nodemac)
|
||||
endif
|
||||
|
||||
CLEAN += *.jn516x
|
||||
CLEAN += *.jn516x.bin
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += $(ARCH)
|
||||
@ -234,16 +235,16 @@ 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,$^}) \
|
||||
$(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
|
||||
%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
|
||||
%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB)
|
||||
echo Creating empty $@
|
||||
touch $@
|
||||
endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2014, SICS Swedish ICT.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -25,24 +25,32 @@
|
||||
* 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"
|
||||
|
||||
#ifndef BR_PROJECT_ROUTER_CONF_H_
|
||||
#define BR_PROJECT_ROUTER_CONF_H_
|
||||
#include <MicroInt.h>
|
||||
#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;
|
||||
|
||||
#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_ */
|
||||
while(s && *s != 0) {
|
||||
if(i >= len) {
|
||||
break;
|
||||
}
|
||||
uart0_writeb(*s++);
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -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
|
||||
|
@ -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 <beshr@sics.se> and Simon Duquennoy <simonduq@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
}
|
@ -429,11 +429,3 @@ 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
|
@ -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}
|
||||
@ -30,8 +27,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
|
||||
|
@ -17,8 +17,6 @@ CONTIKI_SOURCEFILES += dbg.c
|
||||
MODULES += os/lib/dbg-io
|
||||
endif
|
||||
|
||||
CLEAN += *.nrf52dk
|
||||
|
||||
### Unless the example dictates otherwise, build with code size optimisations switched off
|
||||
SMALL ?= 0
|
||||
|
||||
|
@ -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
|
||||
|
@ -54,5 +54,3 @@ const leds_t leds_arch_leds[] = {
|
||||
},
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <contiki.h>
|
||||
#include <dev/spi.h>
|
||||
#include "dev/spi-legacy.h"
|
||||
#include <dev/leds.h>
|
||||
|
||||
#include "dev/i2c.h"
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dev/spi.h"
|
||||
#include "dev/spi-legacy.h"
|
||||
#include "dev/xmem.h"
|
||||
#include "dev/watchdog.h"
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -43,44 +43,41 @@
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/xmem.h"
|
||||
|
||||
/*** MX25R8035F Memory Organization
|
||||
The memory is organized as:
|
||||
8Mbit = 1048576 bytes (8 bits each)
|
||||
256 sectors (32 Kbits, 4096 bytes each)
|
||||
4096 pages (256 bytes each).
|
||||
Each page can be individually programmed (bits are programmed from 1 to 0). The device is
|
||||
sector or bulk erasable (bits are erased from 0 to 1) but not page erasable
|
||||
*/
|
||||
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL //Total size of the External Flash Memory in the Z1
|
||||
/*
|
||||
* MX25R8035F Memory Organization
|
||||
* The memory is organized as:
|
||||
* 8Mbit = 1048576 bytes (8 bits each)
|
||||
* 256 sectors (32 Kbits, 4096 bytes each)
|
||||
* 4096 pages (256 bytes each).
|
||||
* Each page can be individually programmed (bits are programmed from 1 to 0).
|
||||
* The device is sector or bulk erasable (bits are erased from 0 to 1) but not
|
||||
* page erasable
|
||||
*/
|
||||
#define COFFEE_XMEM_TOTAL_SIZE_KB 1024UL /* Total size of the External Flash Memory in the Z1 */
|
||||
|
||||
/* Coffee configuration parameters. */
|
||||
#define COFFEE_SECTOR_SIZE 4096UL
|
||||
#define COFFEE_PAGE_SIZE 256UL
|
||||
#define COFFEE_START 0UL //COFFEE_SECTOR_SIZE
|
||||
#define COFFEE_START 0UL /* COFFEE_SECTOR_SIZE */
|
||||
#define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START)
|
||||
#define COFFEE_NAME_LENGTH 16
|
||||
#define COFFEE_MAX_OPEN_FILES 6
|
||||
#define COFFEE_FD_SET_SIZE 8
|
||||
#define COFFEE_LOG_TABLE_LIMIT 256
|
||||
#define COFFEE_DYN_SIZE 2*1024
|
||||
#define COFFEE_DYN_SIZE 2 * 1024
|
||||
#define COFFEE_LOG_SIZE 1024
|
||||
|
||||
#define COFFEE_MICRO_LOGS 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Flash operations. */
|
||||
#define COFFEE_WRITE(buf, size, offset) \
|
||||
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
|
||||
#define COFFEE_WRITE(buf, size, offset) \
|
||||
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
|
||||
|
||||
#define COFFEE_READ(buf, size, offset) \
|
||||
xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
|
||||
#define COFFEE_READ(buf, size, offset) \
|
||||
xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
|
||||
|
||||
#define COFFEE_ERASE(sector) \
|
||||
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
|
||||
#define COFFEE_ERASE(sector) \
|
||||
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
|
||||
|
||||
/* Coffee types. */
|
||||
typedef int16_t coffee_page_t;
|
||||
|
@ -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 <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
@ -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 <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \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_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
@ -49,21 +49,17 @@
|
||||
|
||||
#define XMEM_BUFF_LENGHT 128
|
||||
|
||||
|
||||
#if 0
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...) do {} while (0)
|
||||
#define PRINTF(...) do {} while(0)
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
xmem_init(void)
|
||||
{
|
||||
ext_flash_open();
|
||||
ext_flash_open(NULL);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
xmem_pread(void *_p, int size, unsigned long addr)
|
||||
{
|
||||
@ -71,30 +67,29 @@ 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);
|
||||
for (i = 0; i < size; i++){
|
||||
rv = ext_flash_read(NULL, addr, size, _p);
|
||||
for(i = 0; i < size; i++) {
|
||||
x = ~*((uint8_t *)_p + i);
|
||||
*((uint8_t *)_p+i) = x;
|
||||
*((uint8_t *)_p + i) = x;
|
||||
}
|
||||
|
||||
ext_flash_close();
|
||||
ext_flash_close(NULL);
|
||||
|
||||
if(rv)
|
||||
if(rv) {
|
||||
return size;
|
||||
}
|
||||
|
||||
PRINTF("Could not read flash memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
xmem_pwrite(const void *_buf, int size, unsigned long addr)
|
||||
{
|
||||
@ -104,43 +99,40 @@ 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;
|
||||
}
|
||||
|
||||
for (remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) {
|
||||
for(remain = size, j = 0; remain > 0; remain -= XMEM_BUFF_LENGHT, j += XMEM_BUFF_LENGHT) {
|
||||
int to_write = MIN(XMEM_BUFF_LENGHT, remain);
|
||||
for (i = 0; i < to_write; i++) {
|
||||
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);
|
||||
if (!rv) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
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,14 +146,15 @@ 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();
|
||||
|
||||
if(rv)
|
||||
if(rv) {
|
||||
return size;
|
||||
}
|
||||
|
||||
PRINTF("Could not erase flash memory\n");
|
||||
return -1;
|
||||
|
@ -3,7 +3,8 @@ 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
|
||||
|
||||
MODULES += arch/dev/ext-flash
|
||||
|
||||
### Signal that we can be programmed with cc2538-bsl
|
||||
BOARD_SUPPORTS_BSL=1
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 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
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -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 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
|
||||
|
@ -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 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
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -41,5 +41,3 @@ const leds_t leds_arch_leds[] = {
|
||||
{ .pin = BOARD_IOID_LED_2, .negative_logic = false },
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -6,5 +6,7 @@ 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
|
||||
|
||||
MODULES += arch/dev/ext-flash
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 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
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -39,5 +39,3 @@ const leds_t leds_arch_leds[] = {
|
||||
{ .pin = BOARD_IOID_LED_1, .negative_logic = false },
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -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 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
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -40,5 +40,3 @@ const leds_t leds_arch_leds[] = {
|
||||
{ .pin = BOARD_IOID_LED_2, .negative_logic = false },
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -42,5 +42,3 @@ const leds_t leds_arch_leds[] = {
|
||||
{ .pin = BOARD_IOID_LED_4, .negative_logic = false },
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -46,10 +46,10 @@
|
||||
#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"
|
||||
#include "dev/spi-legacy.h"
|
||||
#include "dev/ssi.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "dev/gpio-hal.h"
|
||||
|
@ -50,5 +50,3 @@ const leds_t leds_arch_leds[] = {
|
||||
},
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -39,10 +39,10 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "spi-arch.h"
|
||||
#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)
|
||||
|
@ -43,8 +43,8 @@
|
||||
* eth-gw SPI arch specifics
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "spi-arch.h"
|
||||
#include "spi.h"
|
||||
#include "dev/spi-arch-legacy.h"
|
||||
#include "dev/spi-legacy.h"
|
||||
#include "dev/gpio.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define RESET_PORT GPIO_PORT_TO_BASE(ETH_RESET_PORT)
|
||||
|
@ -78,4 +78,3 @@ specifies the used advertisement interval in milliseconds.
|
||||
[rfc7668]: https://tools.ietf.org/html/rfc7668
|
||||
[bleSpec]: https://www.bluetooth.com/specifications/bluetooth-core-specification/legacy-specifications
|
||||
[bleachWeb]: http://www.iti.tugraz.at/BLEach
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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)
|
@ -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 <theo.van.daele@nxp.com>
|
||||
*
|
||||
*/
|
||||
#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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -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 <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Joel Hoglund <joel@sics.se>
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
*/
|
||||
|
||||
#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 <string.h>
|
||||
|
||||
#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
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
92
os/dev/spi-legacy.h
Normal file
92
os/dev/spi-legacy.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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
|
||||
* Basic SPI macros
|
||||
* \author
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
*/
|
||||
|
||||
#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
|
||||
on for example MSP430 but not on AVR. */
|
||||
#ifdef SPI_WAITFORTxREADY
|
||||
#define SPI_WAITFORTx_BEFORE() SPI_WAITFORTxREADY()
|
||||
#define SPI_WAITFORTx_AFTER()
|
||||
#define SPI_WAITFORTx_ENDED() SPI_WAITFOREOTx()
|
||||
#else /* SPI_WAITFORTxREADY */
|
||||
#define SPI_WAITFORTx_BEFORE()
|
||||
#define SPI_WAITFORTx_AFTER() SPI_WAITFOREOTx()
|
||||
#define SPI_WAITFORTx_ENDED()
|
||||
#endif /* SPI_WAITFORTxREADY */
|
||||
|
||||
extern unsigned char spi_busy;
|
||||
|
||||
void spi_init(void);
|
||||
|
||||
/* Write one character to SPI */
|
||||
#define SPI_WRITE(data) \
|
||||
do { \
|
||||
SPI_WAITFORTx_BEFORE(); \
|
||||
SPI_TXBUF = data; \
|
||||
SPI_WAITFOREOTx(); \
|
||||
} while(0)
|
||||
|
||||
/* Write one character to SPI - will not wait for end
|
||||
useful for multiple writes with wait after final */
|
||||
#define SPI_WRITE_FAST(data) \
|
||||
do { \
|
||||
SPI_WAITFORTx_BEFORE(); \
|
||||
SPI_TXBUF = data; \
|
||||
SPI_WAITFORTx_AFTER(); \
|
||||
} while(0)
|
||||
|
||||
/* Read one character from SPI */
|
||||
#define SPI_READ(data) \
|
||||
do { \
|
||||
SPI_TXBUF = 0; \
|
||||
SPI_WAITFOREORx(); \
|
||||
data = SPI_RXBUF; \
|
||||
} while(0)
|
||||
|
||||
/* Flush the SPI read register */
|
||||
#ifndef SPI_FLUSH
|
||||
#define SPI_FLUSH() \
|
||||
do { \
|
||||
SPI_RXBUF; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#endif /* SPI_LEGACY_H_ */
|
222
os/dev/spi.c
Normal file
222
os/dev/spi.c
Normal file
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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 spi-hal
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Implementation of the platform-independent aspects of the SPI HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <dev/spi.h>
|
||||
#include "contiki.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_acquire(spi_device_t *dev)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
/* lock and open the bus */
|
||||
return spi_arch_lock_and_open(dev);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_release(spi_device_t *dev)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
/* close and unlock the bus */
|
||||
return spi_arch_close_and_unlock(dev);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_select(spi_device_t *dev)
|
||||
{
|
||||
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 >= SPI_CONTROLLER_COUNT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return spi_arch_has_lock(dev);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_write_byte(spi_device_t *dev, uint8_t data)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_arch_has_lock(dev)) {
|
||||
return SPI_DEV_STATUS_BUS_LOCKED;
|
||||
}
|
||||
|
||||
return spi_arch_transfer(dev, &data, 1, 0, 0, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_write(spi_device_t *dev, const uint8_t *data, int size)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_arch_has_lock(dev)) {
|
||||
return SPI_DEV_STATUS_BUS_LOCKED;
|
||||
}
|
||||
|
||||
return spi_arch_transfer(dev, data, size, 0, 0, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_read_byte(spi_device_t *dev, uint8_t *buf)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_arch_has_lock(dev)) {
|
||||
return SPI_DEV_STATUS_BUS_LOCKED;
|
||||
}
|
||||
|
||||
return spi_arch_transfer(dev, NULL, 0, buf, 1, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_read(spi_device_t *dev, uint8_t *buf, int size)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_arch_has_lock(dev)) {
|
||||
return SPI_DEV_STATUS_BUS_LOCKED;
|
||||
}
|
||||
|
||||
return spi_arch_transfer(dev, NULL, 0, buf, size, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_read_skip(spi_device_t *dev, int size)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_arch_has_lock(dev)) {
|
||||
return SPI_DEV_STATUS_BUS_LOCKED;
|
||||
}
|
||||
|
||||
return spi_arch_transfer(dev, NULL, 0, NULL, 0, size);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_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_arch_transfer(dev, wdata, wsize, rbuf, rsize, ignore);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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 >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
/* write the register first (will read a status) */
|
||||
status = spi_write_byte(dev, reg);
|
||||
if(status != SPI_DEV_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* then read the value (will read the value) */
|
||||
status = spi_read(dev, data, size);
|
||||
if(status != SPI_DEV_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
spi_status_t
|
||||
spi_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result)
|
||||
{
|
||||
if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) {
|
||||
return SPI_DEV_STATUS_EINVAL;
|
||||
}
|
||||
|
||||
if(!spi_arch_has_lock(dev)) {
|
||||
return SPI_DEV_STATUS_BUS_LOCKED;
|
||||
}
|
||||
|
||||
return spi_arch_transfer(dev, &strobe, 1, result, 1, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
397
os/dev/spi.h
397
os/dev/spi.h
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* 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
|
||||
@ -10,83 +11,339 @@
|
||||
* 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.
|
||||
* 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
|
||||
* Basic SPI macros
|
||||
* \author
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Header file for the SPI HAL
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef SPI_H_
|
||||
#define SPI_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "gpio-hal.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
|
||||
on for example MSP430 but not on AVR. */
|
||||
#ifdef SPI_WAITFORTxREADY
|
||||
#define SPI_WAITFORTx_BEFORE() SPI_WAITFORTxREADY()
|
||||
#define SPI_WAITFORTx_AFTER()
|
||||
#define SPI_WAITFORTx_ENDED() SPI_WAITFOREOTx()
|
||||
#else /* SPI_WAITFORTxREADY */
|
||||
#define SPI_WAITFORTx_BEFORE()
|
||||
#define SPI_WAITFORTx_AFTER() SPI_WAITFOREOTx()
|
||||
#define SPI_WAITFORTx_ENDED()
|
||||
#endif /* SPI_WAITFORTxREADY */
|
||||
|
||||
extern unsigned char spi_busy;
|
||||
|
||||
void spi_init(void);
|
||||
|
||||
/* Write one character to SPI */
|
||||
#define SPI_WRITE(data) \
|
||||
do { \
|
||||
SPI_WAITFORTx_BEFORE(); \
|
||||
SPI_TXBUF = data; \
|
||||
SPI_WAITFOREOTx(); \
|
||||
} while(0)
|
||||
|
||||
/* Write one character to SPI - will not wait for end
|
||||
useful for multiple writes with wait after final */
|
||||
#define SPI_WRITE_FAST(data) \
|
||||
do { \
|
||||
SPI_WAITFORTx_BEFORE(); \
|
||||
SPI_TXBUF = data; \
|
||||
SPI_WAITFORTx_AFTER(); \
|
||||
} while(0)
|
||||
|
||||
/* Read one character from SPI */
|
||||
#define SPI_READ(data) \
|
||||
do { \
|
||||
SPI_TXBUF = 0; \
|
||||
SPI_WAITFOREORx(); \
|
||||
data = SPI_RXBUF; \
|
||||
} while(0)
|
||||
|
||||
/* Flush the SPI read register */
|
||||
#ifndef SPI_FLUSH
|
||||
#define SPI_FLUSH() \
|
||||
do { \
|
||||
SPI_RXBUF; \
|
||||
} while(0)
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Include Arch-Specific conf */
|
||||
#ifdef SPI_HAL_CONF_ARCH_HDR_PATH
|
||||
#include SPI_HAL_CONF_ARCH_HDR_PATH
|
||||
#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
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
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 wsize Size of data to write.
|
||||
* \param buf A pointer to buffer to copy the data read. Set to NULL
|
||||
* to skip reading.
|
||||
* \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.
|
||||
* 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 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 Locks and 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_lock_and_open(spi_device_t *dev);
|
||||
|
||||
/**
|
||||
* \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
|
||||
* and unlock it.
|
||||
* It should work only if the device has already locked the SPI
|
||||
* controller.
|
||||
*
|
||||
*/
|
||||
spi_status_t spi_arch_close_and_unlock(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_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
@ -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 */
|
||||
@ -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 */
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
@ -829,7 +829,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
|
||||
if(best_dag->preferred_parent != last_parent) {
|
||||
rpl_set_default_route(instance, rpl_parent_get_ipaddr(best_dag->preferred_parent));
|
||||
PRINTF("RPL: Changed preferred parent, rank changed from %u to %u\n",
|
||||
(unsigned)old_rank, best_dag->rank);
|
||||
(unsigned)old_rank, best_dag->rank);
|
||||
RPL_STAT(rpl_stats.parent_switch++);
|
||||
if(RPL_IS_STORING(instance)) {
|
||||
if(last_parent != NULL) {
|
||||
@ -848,7 +848,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
|
||||
#endif
|
||||
} else if(best_dag->rank != old_rank) {
|
||||
PRINTF("RPL: Preferred parent update, rank changed from %u to %u\n",
|
||||
(unsigned)old_rank, best_dag->rank);
|
||||
(unsigned)old_rank, best_dag->rank);
|
||||
}
|
||||
return best_dag;
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -46,7 +46,6 @@
|
||||
* During execution, the fill can be checked in order to find out
|
||||
* the extent to which the stack has been used.
|
||||
*
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
@ -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 \
|
||||
|
@ -23,4 +23,3 @@ if(failed) {
|
||||
log.testFailed();
|
||||
}
|
||||
log.testOK();
|
||||
|
||||
|
@ -24,4 +24,3 @@ if(failed) {
|
||||
log.testFailed();
|
||||
}
|
||||
log.testOK();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 7ab51eaaa309c123fbd318c6ad3338cce1e48e48
|
||||
Subproject commit 67b858437f7cf1e4e027d821c4c2ac15fdf2ab44
|
Loading…
Reference in New Issue
Block a user