Merge pull request #1177 from STclab/stm32nucleo-spirit1
Stm32nucleo spirit1
This commit is contained in:
commit
0f5332430b
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
|||
*.a
|
||||
*.bin
|
||||
*.map
|
||||
*.png
|
||||
|
|
4
.gitmodules
vendored
4
.gitmodules
vendored
|
@ -10,3 +10,7 @@
|
|||
[submodule "cpu/cc26xx-cc13xx/lib/cc13xxware"]
|
||||
path = cpu/cc26xx-cc13xx/lib/cc13xxware
|
||||
url = https://github.com/g-oikonomou/cc13xxware.git
|
||||
[submodule "platform/stm32nucleo-spirit1/stm32cube-lib"]
|
||||
path = platform/stm32nucleo-spirit1/stm32cube-lib
|
||||
url = https://github.com/STclab/stm32nucleo-spirit1-lib
|
||||
|
||||
|
|
136
cpu/arm/stm32l152/Makefile.stm32l152
Normal file
136
cpu/arm/stm32l152/Makefile.stm32l152
Normal file
|
@ -0,0 +1,136 @@
|
|||
# Makefile for the STM32L152 Cortex M3 medium-density microcontroller
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
# CPU folder
|
||||
CONTIKI_CPU=$(CONTIKI)/cpu/arm/stm32l152
|
||||
|
||||
# Source folders for contiki cpu files
|
||||
CONTIKI_CPU_DIRS = .
|
||||
|
||||
# source files: proprietary sources for startup. Refer to CMSIS docs.
|
||||
PROP_SYS_ARCH_C = system_stm32l1xx.c
|
||||
|
||||
|
||||
ifdef IAR
|
||||
include $(CONTIKI_CPU)/Makefile.stm32l152.iar
|
||||
else
|
||||
include $(CONTIKI_CPU)/Makefile.stm32l152.gnu
|
||||
endif
|
||||
|
||||
|
||||
# source files: Contiki arch source files
|
||||
CONTIKI_CPU_ARCH= watchdog.c \
|
||||
rtimer-arch.c \
|
||||
clock.c
|
||||
|
||||
ifdef GCC
|
||||
CONTIKI_CPU_PORT= syscalls.c \
|
||||
console.c \
|
||||
crt.c \
|
||||
uart.c
|
||||
else
|
||||
CONTIKI_CPU_PORT=
|
||||
endif
|
||||
|
||||
|
||||
|
||||
UIPDRIVERS=
|
||||
|
||||
# to be implemented
|
||||
ELFLOADER=
|
||||
|
||||
|
||||
# add CPU folder to search path for .s (assembler) files
|
||||
ifdef GCC
|
||||
vpath %.s $(CONTIKI)/platform/$(TARGET)/stm32cube-lib/stm32cube-prj/startup_files/gcc
|
||||
else
|
||||
vpath %.s $(CONTIKI)/platform/$(TARGET)/stm32cube-lib/stm32cube-prj/startup_files/iar
|
||||
endif
|
||||
|
||||
# include all files above
|
||||
ssubst = ${patsubst %.s,%.o,${patsubst %.s79,%.o,$(1)}}
|
||||
CONTIKI_TARGET_SOURCEFILES += $(PROP_SYS_ARCH_C) $(PROP_USB_ARCH) $(CONTIKI_CPU_ARCH) $(CONTIKI_CPU_PORT) $(ELFLOADER) $(UIPDRIVERS)
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)}
|
||||
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,${call ssubst, $(PROP_SYS_ARCH_S)}}
|
||||
#CONTIKI_OBJECTFILES += ${addprefix $(OBJECTDIR)/,${call ssubst, $(PROP_SYS_ARCH_S)}}
|
||||
|
||||
#------------------------------------------------ defines common for IAR and GCC
|
||||
# set CPU speed in Hz, NB this might have unexpected side-effects if not at 32
|
||||
# Mhz as it is not immediately clear how specialized the startup code etc is.
|
||||
# That being said, setting to 24MHz seems to work fine, looking at Contiki clocks
|
||||
# at least.
|
||||
F_CPU = 32000000
|
||||
|
||||
CFLAGS+=\
|
||||
-DHSE_VALUE=$(F_CPU)ul \
|
||||
-DUSE_STDPERIPH_DRIVER \
|
||||
-DSTM32L1XX_MD \
|
||||
-DIAR_ARM_CM3 \
|
||||
-DVECT_TAB_FLASH \
|
||||
-DWITH_UIP6
|
||||
|
||||
# ------------------------------------------------------------------ Build rules
|
||||
CUSTOM_RULE_C_TO_CE=yes
|
||||
CUSTOM_RULE_C_TO_CO=yes
|
||||
CUSTOM_RULE_C_TO_O=yes
|
||||
CUSTOM_RULE_S_TO_OBJECTDIR_O=yes
|
||||
CUSTOM_RULE_LINK=yes
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
%.o: %.s
|
||||
$(AS) $(ASFLAGS) $< -o $@
|
||||
|
||||
define FINALIZE_CYGWIN_DEPENDENCY
|
||||
sed -e 's/ \([A-Z]\):\\/ \/cygdrive\/\L\1\//' -e 's/\\\([^ ]\)/\/\1/g' \
|
||||
<$(@:.o=.P) >$(@:.o=.d); \
|
||||
rm -f $(@:.o=.P)
|
||||
endef
|
||||
|
||||
$(OBJECTDIR)/%.o: %.s
|
||||
$(AS) $(ASFLAGS) $< -o $@
|
||||
|
||||
%.ce: %.o
|
||||
$(LD) $(LDFLAGS) --relocatable -T $(CONTIKI_CPU)/merge-rodata.ld $< -o $@ $(LDLIBS)
|
||||
$(STRIP) -K _init -K _fini --strip-unneeded -g -x $@
|
||||
|
||||
%-stripped.o: %.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
$(STRIP) --strip $@
|
||||
|
||||
%-stripped.o: %.o
|
||||
$(STRIP) --strip $@ $<
|
||||
|
||||
%.o: ${CONTIKI_TARGET}/loader/%.S
|
||||
$(AS) -o $(notdir $(<:.S=.o)) $<
|
||||
|
||||
ifdef IAR
|
||||
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUPFOLDER) # $(OBJECTDIR)/empty-symbols.o
|
||||
$(LD) $(LDFLAGS) -o $@ $(filter-out %.a,$^) $(filter %.a,$^) $(LDLIBS)
|
||||
else
|
||||
#CONTIKI_CPU_OBJS=$(CONTIKI_CPU_PORT:%.c=obj_stm32nucleo-spirit1/%.o)
|
||||
CONTIKI_CPU_OBJS=$(CONTIKI_CPU_PORT:%.c=$(OBJECTDIR)/%.o)
|
||||
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(OBJECTDIR)/symbols.o
|
||||
$(TRACE_LD)
|
||||
$(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} -Wl,-\( ${filter %.a,$^} $(TARGET_LIBFILES) -Wl,-\) $(CONTIKI_CPU_OBJS) -o $@
|
||||
@echo >> contiki-$(TARGET).map
|
||||
@$(SIZE) $(SIZEFLAGS) $@ >> contiki-$(TARGET).map
|
||||
endif
|
||||
|
||||
%.hex: %.ihex
|
||||
# @rm $*.hex
|
||||
@mv -f $*.ihex $*.hex
|
||||
|
||||
.PHONY: symbols.c
|
||||
|
||||
symbols.c:
|
||||
cp ${CONTIKI}/tools/empty-symbols.c symbols.c
|
||||
cp ${CONTIKI}/tools/empty-symbols.h symbols.h
|
||||
|
||||
# Don't use core/loader/elfloader.c, use elfloader-otf.c instead
|
||||
$(OBJECTDIR)/elfloader.o:
|
||||
echo -n >$@
|
||||
|
65
cpu/arm/stm32l152/Makefile.stm32l152.gnu
Normal file
65
cpu/arm/stm32l152/Makefile.stm32l152.gnu
Normal file
|
@ -0,0 +1,65 @@
|
|||
PROP_SYS_ARCH_S = startup_stm32l152xe.s
|
||||
|
||||
### Compiler definitions
|
||||
GCC = 1
|
||||
CC = arm-none-eabi-gcc
|
||||
LD = arm-none-eabi-gcc
|
||||
SIZE = arm-none-eabi-size
|
||||
AS = arm-none-eabi-as
|
||||
AR = arm-none-eabi-ar
|
||||
NM = arm-none-eabi-nm
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
STRIP = arm-none-eabi-strip
|
||||
|
||||
%.ihex: %.$(TARGET)
|
||||
$(OBJCOPY) -O ihex $^ $@
|
||||
%.bin: %.$(TARGET)
|
||||
$(OBJCOPY) -O binary $^ $@
|
||||
%.co: %.c
|
||||
$(CC) $(CFLAGS) -c -DAUTOSTART_ENABLE $< -o $@
|
||||
|
||||
|
||||
ifndef LDSCRIPT
|
||||
LDSCRIPT = $(CONTIKI)/platform/$(TARGET)/stm32cube-lib/stm32cube-prj/linker/gcc/STM32L152RETx_FLASH.ld
|
||||
endif
|
||||
|
||||
#ASFLAGS += -mcpu=cortex-m3 -mthumb
|
||||
|
||||
# this platform wields a STM32L152VB medium-density device
|
||||
CFLAGS+=-DSTM32L1XX_MD=1
|
||||
|
||||
CFLAGS+=\
|
||||
-I$(CONTIKI)/cpu/arm/common/CMSIS \
|
||||
-Wall -g -O0 \
|
||||
-DWITH_UIP -DWITH_ASCII \
|
||||
-mcpu=cortex-m3 \
|
||||
-mthumb \
|
||||
-mno-unaligned-access \
|
||||
-mfix-cortex-m3-ldrd \
|
||||
-std=gnu99 \
|
||||
-Wl,-cref \
|
||||
-D __SOURCEFILE__=\"$*.c\"
|
||||
|
||||
|
||||
LDFLAGS += -Wl,-Map=contiki-$(TARGET).map,--cref,--no-warn-mismatch
|
||||
|
||||
|
||||
LDLIBS += $(CONTIKI_CPU)/lib/smallprintf_thumb2.a
|
||||
|
||||
|
||||
|
||||
LDFLAGS += -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -T$(LDSCRIPT) -Wl,-Map=output.map -Wl,--gc-sections -lm
|
||||
|
||||
|
||||
LDFLAGS += $(LDLIBS)
|
||||
|
||||
SMALL=1
|
||||
ifeq ($(SMALL),1)
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fdata-sections
|
||||
|
||||
LDFLAGS += -Wl,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__
|
||||
|
||||
endif # /SMALL
|
||||
|
||||
|
84
cpu/arm/stm32l152/Makefile.stm32l152.iar
Normal file
84
cpu/arm/stm32l152/Makefile.stm32l152.iar
Normal file
|
@ -0,0 +1,84 @@
|
|||
PROP_SYS_ARCH_S = startup_stm32l152xe.s
|
||||
|
||||
|
||||
# Compiler definitions
|
||||
IAR = 1
|
||||
CC = iccarm
|
||||
LD = ilinkarm
|
||||
AS = iasmarm
|
||||
AR = iarchive
|
||||
OBJCOPY = ielftool
|
||||
STRIP = iobjmanip
|
||||
SIZE =
|
||||
NM =
|
||||
|
||||
%.ihex: %.$(TARGET)
|
||||
$(OBJCOPY) $^ --ihex $@
|
||||
%.bin: %.$(TARGET)
|
||||
$(OBJCOPY) --bin $@
|
||||
|
||||
|
||||
# Find the path to compiler; this works with cygwin
|
||||
ifndef IAR_PATH
|
||||
IAR_BIN_PATH := $(shell dirname "`which $(CC)`")
|
||||
IAR_PATH_C := $(shell dirname "$(IAR_BIN_PATH)")
|
||||
IAR_PATH := $(shell cygpath -m "$(IAR_PATH_C)")
|
||||
endif
|
||||
|
||||
# ------------compiler flags
|
||||
CFLAGS+=\
|
||||
-I"$(IAR_PATH)/CMSIS/Include" \
|
||||
--diag_suppress Pa050 \
|
||||
--no_unroll \
|
||||
--no_inline \
|
||||
--no_tbaa \
|
||||
--no_scheduling \
|
||||
--debug \
|
||||
--endian=little \
|
||||
--cpu=Cortex-M3 \
|
||||
-Om \
|
||||
-e \
|
||||
--fpu=None \
|
||||
--dlib_config "$(IAR_PATH)/inc/c/DLib_Config_Normal.h" \
|
||||
-DIAR=1 \
|
||||
-DWITH_USB_PRINTF=1
|
||||
|
||||
# -I$(CONTIKI)/cpu/arm/common/CMSIS \
|
||||
|
||||
# ------------assembler flags
|
||||
ASFLAGS+= -s+ -r -DIAR_ARM_CM3 -cAOM -B -t8 --cpu Cortex-M3 --fpu None
|
||||
|
||||
#iasmarm -s+ -w+ -r -DIAR_ARM_CM3 -cAOM -B -t8 --cpu Cortex-M3 --fpu None startup_stm32l1xx_md.s
|
||||
|
||||
# ------------archive creation flags
|
||||
AROPTS= --create --output
|
||||
|
||||
# ----------linker flags
|
||||
# this will also generate log and symbol map files
|
||||
ICF_FILE="$(CONTIKI)/platform/$(TARGET)/stm32cube-lib/stm32cube-prj/linker/iar/stm32l1xx_flash.icf"
|
||||
LDFLAGS+= \
|
||||
--config $(ICF_FILE) \
|
||||
--entry __iar_program_start \
|
||||
--redirect _Printf=_PrintfLarge \
|
||||
--redirect _Scanf=_ScanfLarge \
|
||||
--semihosting \
|
||||
--no_exceptions \
|
||||
--no_remove \
|
||||
--cpu=Cortex-M3 \
|
||||
--log libraries,initialization,modules,redirects,sections,veneers,unused_fragments \
|
||||
--log_file contiki-$(TARGET).log \
|
||||
--map contiki-$(TARGET).map \
|
||||
--vfe
|
||||
|
||||
CUSTOM_RULE_C_TO_OBJECTDIR_O=yes
|
||||
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
|
||||
$(CC) $(CFLAGS) --dependencies=m $(@:.o=.P) $< -o $@
|
||||
ifeq ($(HOST_OS),Windows)
|
||||
@$(FINALIZE_CYGWIN_DEPENDENCY)
|
||||
endif
|
||||
|
||||
%.co: %.c
|
||||
$(CC) $(CFLAGS) -DAUTOSTART_ENABLE $< -o $@
|
||||
|
||||
|
||||
|
109
cpu/arm/stm32l152/clock.c
Normal file
109
cpu/arm/stm32l152/clock.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "platform-conf.h"
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/leds.h"
|
||||
#include "stm32l1xx.h"
|
||||
#include "stm32l1xx_hal_rcc.h"
|
||||
#include "stm32l1xx_hal_cortex.h"
|
||||
#include "stm32l1xx_hal.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define RELOAD_VALUE ((F_CPU / CLOCK_CONF_SECOND) - 1)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static volatile unsigned long seconds = 0;
|
||||
static volatile clock_time_t ticks;
|
||||
void st_lib_sys_tick_handler(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
st_lib_sys_tick_handler(void)
|
||||
{
|
||||
ticks++;
|
||||
if((ticks % CLOCK_SECOND) == 0) {
|
||||
seconds++;
|
||||
energest_flush();
|
||||
}
|
||||
HAL_IncTick();
|
||||
|
||||
if(etimer_pending()) {
|
||||
etimer_request_poll();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
clock_init(void)
|
||||
{
|
||||
ticks = 0;
|
||||
st_lib_hal_systick_clk_source_config(SYSTICK_CLKSOURCE_HCLK);
|
||||
st_lib_hal_systick_config(RELOAD_VALUE);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned long
|
||||
clock_seconds(void)
|
||||
{
|
||||
return seconds;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
clock_set_seconds(unsigned long sec)
|
||||
{
|
||||
seconds = sec;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
clock_time_t
|
||||
clock_time(void)
|
||||
{
|
||||
return ticks;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
clock_delay(unsigned int i)
|
||||
{
|
||||
for(; i > 0; i--) {
|
||||
unsigned int j;
|
||||
for(j = 50; j > 0; j--) {
|
||||
asm ("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Wait for a multiple of clock ticks (7.8 ms at 128 Hz). */
|
||||
void
|
||||
clock_wait(clock_time_t t)
|
||||
{
|
||||
clock_time_t start;
|
||||
start = clock_time();
|
||||
while(clock_time() - start < (clock_time_t)t) ;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
189
cpu/arm/stm32l152/console.c
Normal file
189
cpu/arm/stm32l152/console.c
Normal file
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "console.h"
|
||||
#include "stm32l1xx.h"
|
||||
#include "stm32l1xx_hal_dma.h"
|
||||
#include "stm32l1xx_hal_uart.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern st_lib_uart_handle_typedef st_lib_uart_handle;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initialises Nucleo UART port for user IO
|
||||
* @retval 0
|
||||
*/
|
||||
int
|
||||
console_init(void)
|
||||
{
|
||||
st_lib_uart_handle.Instance = USART2;
|
||||
|
||||
st_lib_uart_handle.Init.BaudRate = 115200;
|
||||
st_lib_uart_handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
st_lib_uart_handle.Init.StopBits = UART_STOPBITS_1;
|
||||
st_lib_uart_handle.Init.Parity = UART_PARITY_NONE;
|
||||
st_lib_uart_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
st_lib_uart_handle.Init.Mode = UART_MODE_TX_RX;
|
||||
|
||||
st_lib_hal_uart_init(&st_lib_uart_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Sends a character to serial port
|
||||
* @param ch Character to send
|
||||
* @retval Character sent
|
||||
*/
|
||||
int
|
||||
uart_send_char(int ch)
|
||||
{
|
||||
st_lib_hal_uart_transmit(&st_lib_uart_handle, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
|
||||
return ch;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @brief Receives a character from serial port
|
||||
* @retval Character received
|
||||
*/
|
||||
int
|
||||
uart_receive_char(void)
|
||||
{
|
||||
uint8_t ch;
|
||||
st_lib_hal_uart_receive(&st_lib_uart_handle, &ch, 1, HAL_MAX_DELAY);
|
||||
|
||||
/* Echo character back to console */
|
||||
st_lib_hal_uart_transmit(&st_lib_uart_handle, &ch, 1, HAL_MAX_DELAY);
|
||||
|
||||
/* And cope with Windows */
|
||||
if(ch == '\r') {
|
||||
uint8_t ret = '\n';
|
||||
st_lib_hal_uart_transmit(&st_lib_uart_handle, &ret, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
|
||||
size_t __write(int Handle, const unsigned char *Buf, size_t Bufsize);
|
||||
size_t __read(int Handle, unsigned char *Buf, size_t Bufsize);
|
||||
|
||||
/** @brief IAR specific low level standard input
|
||||
* @param handle IAR internal handle
|
||||
* @param buf Buffer where to store characters read from stdin
|
||||
* @param bufsize Number of characters to read
|
||||
* @retval Number of characters read
|
||||
*/
|
||||
size_t
|
||||
__read(int handle, unsigned char *buf, size_t bufsize)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(handle != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < bufsize; i++) {
|
||||
buf[i] = uart_receive_char();
|
||||
}
|
||||
|
||||
return bufsize;
|
||||
}
|
||||
/** @brief IAR specific low level standard output
|
||||
* @param handle IAR internal handle
|
||||
* @param buf Buffer containing characters to be written to stdout
|
||||
* @param bufsize Number of characters to write
|
||||
* @retval Number of characters read
|
||||
*/
|
||||
size_t
|
||||
__write(int handle, const unsigned char *buf, size_t bufsize)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(handle != 1 && handle != 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < bufsize; i++) {
|
||||
uart_send_char(buf[i]);
|
||||
}
|
||||
|
||||
return bufsize;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#elif defined(__CC_ARM)
|
||||
/**
|
||||
* @brief fputc call for standard output implementation
|
||||
* @param ch Character to print
|
||||
* @param f File pointer
|
||||
* @retval Character printed
|
||||
*/
|
||||
int
|
||||
fputc(int ch, FILE *f)
|
||||
{
|
||||
return uart_send_char(ch);
|
||||
}
|
||||
/** @brief fgetc call for standard input implementation
|
||||
* @param f File pointer
|
||||
* @retval Character acquired from standard input
|
||||
*/
|
||||
int
|
||||
fgetc(FILE *f)
|
||||
{
|
||||
return uart_receive_char();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
/** @brief putchar call for standard output implementation
|
||||
* @param ch Character to print
|
||||
* @retval Character printed
|
||||
*/
|
||||
int
|
||||
__io_putchar(int ch)
|
||||
{
|
||||
return uart_send_char(ch);
|
||||
}
|
||||
/** @brief getchar call for standard input implementation
|
||||
* @param None
|
||||
* @retval Character acquired from standard input
|
||||
*/
|
||||
int
|
||||
__io_getchar(void)
|
||||
{
|
||||
return uart_receive_char();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#else
|
||||
#error "Toolchain not supported"
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
67
cpu/arm/stm32l152/console.h
Normal file
67
cpu/arm/stm32l152/console.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
size_t __write(int handle, const unsigned char *buf, size_t bufsize);
|
||||
size_t __read(int handle, unsigned char *buf, size_t bufsize);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#elif defined(__CC_ARM)
|
||||
/**
|
||||
* @brief fputc call for standard output implementation
|
||||
* @param ch Character to print
|
||||
* @param f File pointer
|
||||
* @retval Character printed
|
||||
*/
|
||||
int fputc(int ch, FILE *f);
|
||||
|
||||
/** @brief fgetc call for standard input implementation
|
||||
* @param f File pointer
|
||||
* @retval Character acquired from standard input
|
||||
*/
|
||||
int fgetc(FILE *f);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#elif defined(__GNUC__)
|
||||
/** @brief putchar call for standard output implementation
|
||||
* @param ch Character to print
|
||||
* @retval Character printed
|
||||
*/
|
||||
int __io_putchar(int ch);
|
||||
|
||||
/** @brief getchar call for standard input implementation
|
||||
* @param None
|
||||
* @retval Character acquired from standard input
|
||||
*/
|
||||
int __io_getchar(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#else
|
||||
#error "Toolchain not supported"
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
87
cpu/arm/stm32l152/crt.c
Normal file
87
cpu/arm/stm32l152/crt.c
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_lseek(int file,
|
||||
int ptr,
|
||||
int dir)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_close(int file)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
_exit(int n)
|
||||
{
|
||||
/* FIXME: return code is thrown away. */
|
||||
while(1) ;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_kill(int n, int m)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_fstat(int file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_isatty(int fd)
|
||||
{
|
||||
return 1;
|
||||
fd = fd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_getpid(int n)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
_open(const char *path, int flags, ...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
BIN
cpu/arm/stm32l152/lib/e_stdio_intonly_thumb2.a
Normal file
BIN
cpu/arm/stm32l152/lib/e_stdio_intonly_thumb2.a
Normal file
Binary file not shown.
BIN
cpu/arm/stm32l152/lib/e_stdio_thumb2.a
Normal file
BIN
cpu/arm/stm32l152/lib/e_stdio_thumb2.a
Normal file
Binary file not shown.
BIN
cpu/arm/stm32l152/lib/smallprintf_thumb2.a
Normal file
BIN
cpu/arm/stm32l152/lib/smallprintf_thumb2.a
Normal file
Binary file not shown.
42
cpu/arm/stm32l152/mtarch.h
Normal file
42
cpu/arm/stm32l152/mtarch.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Implementation of multithreading in ARM Cortex-M3. To be done.
|
||||
*/
|
||||
#ifndef __MTARCH_H__
|
||||
#define __MTARCH_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
struct mtarch_thread {
|
||||
short mt_thread;
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __MTARCH_H__ */
|
11575
cpu/arm/stm32l152/regs.h
Normal file
11575
cpu/arm/stm32l152/regs.h
Normal file
File diff suppressed because it is too large
Load diff
105
cpu/arm/stm32l152/rtimer-arch.c
Normal file
105
cpu/arm/stm32l152/rtimer-arch.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "platform-conf.h"
|
||||
|
||||
#include "sys/rtimer.h"
|
||||
#include "sys/process.h"
|
||||
#include "dev/watchdog.h"
|
||||
|
||||
#include "stm32l1xx.h"
|
||||
#include "stm32l1xx_hal_gpio.h"
|
||||
#include "stm32l1xx_hal_rcc.h"
|
||||
#include "stm32l1xx_hal_tim.h"
|
||||
#include "stm32l1xx_hal_cortex.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
volatile uint32_t rtimer_clock = 0uL;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
st_lib_tim_handle_typedef htim2;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
st_lib_tim2_irq_handler(void)
|
||||
{
|
||||
/* clear interrupt pending flag */
|
||||
st_lib_hal_tim_clear_it(&htim2, TIM_IT_UPDATE);
|
||||
|
||||
rtimer_clock++;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rtimer_arch_init(void)
|
||||
{
|
||||
st_lib_tim_clock_config_typedef s_clock_source_config;
|
||||
st_lib_tim_oc_init_typedef s_config_oc;
|
||||
|
||||
st_lib_tim2_clk_enable();
|
||||
htim2.Instance = TIM2;
|
||||
htim2.Init.Prescaler = PRESCALER;
|
||||
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim2.Init.Period = 1;
|
||||
|
||||
st_lib_hal_tim_base_init(&htim2);
|
||||
st_lib_hal_tim_base_start_it(&htim2);
|
||||
|
||||
s_clock_source_config.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
st_lib_hal_tim_config_clock_source(&htim2, &s_clock_source_config);
|
||||
|
||||
st_lib_hal_tim_oc_init(&htim2);
|
||||
|
||||
s_config_oc.OCMode = TIM_OCMODE_TIMING;
|
||||
s_config_oc.Pulse = 0;
|
||||
s_config_oc.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
st_lib_hal_tim_oc_config_channel(&htim2, &s_config_oc, TIM_CHANNEL_1);
|
||||
|
||||
st_lib_hal_tim_clear_flag(&htim2, TIM_FLAG_UPDATE);
|
||||
|
||||
/* Enable TIM2 Update interrupt */
|
||||
st_lib_hal_tim_enable_it(&htim2, TIM_IT_UPDATE);
|
||||
|
||||
st_lib_hal_tim_enable(&htim2);
|
||||
|
||||
st_lib_hal_nvic_set_priority((st_lib_irq_n_type)TIM2_IRQn, 0, 0);
|
||||
st_lib_hal_nvic_enable_irq((st_lib_irq_n_type)(TIM2_IRQn));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
rtimer_clock_t
|
||||
rtimer_arch_now(void)
|
||||
{
|
||||
return rtimer_clock;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rtimer_arch_schedule(rtimer_clock_t t)
|
||||
{
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
45
cpu/arm/stm32l152/rtimer-arch.h
Normal file
45
cpu/arm/stm32l152/rtimer-arch.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __RTIMER_ARCH_H__
|
||||
#define __RTIMER_ARCH_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki-conf.h"
|
||||
#include "sys/clock.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
rtimer_clock_t rtimer_arch_now(void);
|
||||
void rtimer_arch_disable_irq(void);
|
||||
void rtimer_arch_enable_irq(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __RTIMER_ARCH_H__ */
|
||||
/*---------------------------------------------------------------------------*/
|
66
cpu/arm/stm32l152/syscalls.c
Normal file
66
cpu/arm/stm32l152/syscalls.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Function implementation taken and adapted from:
|
||||
* cpu/stm32w108/e_stdio/src/syscalls.c
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern int errno;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Register name faking - works in collusion with the linker. */
|
||||
register char *stack_ptr asm ("sp");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
caddr_t
|
||||
_sbrk(int incr)
|
||||
{
|
||||
extern char end; /* Defined by the linker */
|
||||
static char *heap_end;
|
||||
char *prev_heap_end;
|
||||
|
||||
if(heap_end == 0) {
|
||||
heap_end = &end;
|
||||
}
|
||||
prev_heap_end = heap_end;
|
||||
if(heap_end + incr > stack_ptr) {
|
||||
_write(1, "Heap and stack collision\n", 25);
|
||||
/*abort ();*/
|
||||
errno = ENOMEM;
|
||||
return (caddr_t)-1;
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
return (caddr_t)prev_heap_end;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
53
cpu/arm/stm32l152/uart.c
Normal file
53
cpu/arm/stm32l152/uart.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "console.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
size_t
|
||||
_write(int handle, const unsigned char *buffer, size_t size)
|
||||
{
|
||||
int data_idx;
|
||||
|
||||
for(data_idx = 0; data_idx < size; data_idx++) {
|
||||
__io_putchar(*buffer++);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
size_t
|
||||
_read(int handle, unsigned char *buffer, size_t size)
|
||||
{
|
||||
/* scanf calls _read() with len=1024, so eat one character at time */
|
||||
*buffer = __io_getchar();
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
61
cpu/arm/stm32l152/watchdog.c
Normal file
61
cpu/arm/stm32l152/watchdog.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "dev/watchdog.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
watchdog_init(void)
|
||||
{
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
watchdog_start(void)
|
||||
{
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
watchdog_periodic(void)
|
||||
{
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
watchdog_stop(void)
|
||||
{
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
watchdog_reboot(void)
|
||||
{
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -808,7 +808,8 @@ EXCLUDE_SYMLINKS = NO
|
|||
# exclude all test directories for example use the pattern */test/*
|
||||
|
||||
EXCLUDE_PATTERNS = */cpu/cc26xx-cc13xx/lib/* \
|
||||
*/cpu/cc26xx-cc13xx/rf-core/api/*
|
||||
*/cpu/cc26xx-cc13xx/rf-core/api/* \
|
||||
*/platform/stm32nucleo-spirit1/stm32cube-lib/*
|
||||
|
||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||
|
|
8
examples/stm32nucleo-spirit1/sensor-demo/Makefile
Normal file
8
examples/stm32nucleo-spirit1/sensor-demo/Makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
CONTIKI_PROJECT = sensor-demo
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
TARGET=stm32nucleo-spirit1
|
||||
SENSORBOARD=iks01a1
|
||||
|
||||
CONTIKI = ../../..
|
||||
include $(CONTIKI)/Makefile.include
|
17
examples/stm32nucleo-spirit1/sensor-demo/README.md
Normal file
17
examples/stm32nucleo-spirit1/sensor-demo/README.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
Sensor Demo
|
||||
============
|
||||
|
||||
The sensor demo can be used to read the values of all sensors and print them every 5 seconds on the terminal.
|
||||
|
||||
In order to use this example the X-NUCLEO-IKS01A1 expansion board featuring ST environmental and motion MEMS sensors
|
||||
must be used. It needs to be connected on top of the NUCLEO-L152RE (MCU) and the X-NUCLEO-IDS01Ax
|
||||
(sub-1GHz RF communication) boards.
|
||||
|
||||
To build the example type:
|
||||
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a4 SENSORBOARD=iks01a1
|
||||
or
|
||||
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a5 SENSORBOARD=iks01a1
|
||||
|
||||
depending on the X-NUCLEO-IDS01Ax expansion board for sub GHz radio connectivity you have.
|
144
examples/stm32nucleo-spirit1/sensor-demo/sensor-demo.c
Normal file
144
examples/stm32nucleo-spirit1/sensor-demo/sensor-demo.c
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
|
||||
#include <stdio.h> /* For printf() */
|
||||
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#include "net/ip/uip-udp-packet.h"
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/radio-sensor.h"
|
||||
#include "dev/sensor-common.h"
|
||||
|
||||
#include "st-lib.h"
|
||||
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/humidity-sensor.h"
|
||||
#include "dev/pressure-sensor.h"
|
||||
#include "dev/magneto-sensor.h"
|
||||
#include "dev/acceleration-sensor.h"
|
||||
#include "dev/gyroscope-sensor.h"
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "net/ip/uip-debug.h"
|
||||
|
||||
#define PRINT_INTERVAL 5 * CLOCK_SECOND
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(sensor_demo_process, "Sensor demo process");
|
||||
AUTOSTART_PROCESSES(&sensor_demo_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(sensor_demo_process, ev, data)
|
||||
{
|
||||
static struct etimer etimer;
|
||||
static unsigned long _button_pressed;
|
||||
static int sensor_value = 0;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
PROCESS_PAUSE();
|
||||
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
SENSORS_ACTIVATE(radio_sensor);
|
||||
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
SENSORS_ACTIVATE(temperature_sensor);
|
||||
SENSORS_ACTIVATE(humidity_sensor);
|
||||
SENSORS_ACTIVATE(pressure_sensor);
|
||||
SENSORS_ACTIVATE(magneto_sensor);
|
||||
SENSORS_ACTIVATE(acceleration_sensor);
|
||||
SENSORS_ACTIVATE(gyroscope_sensor);
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
|
||||
while(1) {
|
||||
etimer_set(&etimer, PRINT_INTERVAL);
|
||||
|
||||
PROCESS_WAIT_EVENT();
|
||||
if(ev == sensors_event && data == &button_sensor) {
|
||||
printf("Sensor event detected: Button Pressed.\n\n");
|
||||
printf("Toggling Leds\n");
|
||||
_button_pressed++;
|
||||
leds_toggle(LEDS_ALL);
|
||||
}
|
||||
|
||||
printf("Button state:\t%s (pressed %lu times)\n", button_sensor.value(0) ? "Released" : "Pressed",
|
||||
_button_pressed);
|
||||
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
printf("LEDs status:\tRED:n/a GREEN:%s\n", leds_get() & LEDS_GREEN ? "on" : "off");
|
||||
#else
|
||||
printf("LEDs status:\tRED:%s GREEN:%s\n", leds_get() & LEDS_RED ? "on" : "off",
|
||||
leds_get() & LEDS_GREEN ? "on" : "off");
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
sensor_value = radio_sensor.value(RADIO_SENSOR_LAST_PACKET);
|
||||
printf("Radio (RSSI):\t%d.%d dBm\n", sensor_value / 10, ABS_VALUE(sensor_value) % 10);
|
||||
printf("Radio (LQI):\t%d\n", radio_sensor.value(RADIO_SENSOR_LAST_VALUE));
|
||||
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
sensor_value = temperature_sensor.value(0);
|
||||
printf("Temperature:\t%d.%d C\n", sensor_value / 10, ABS_VALUE(sensor_value) % 10);
|
||||
|
||||
sensor_value = humidity_sensor.value(0);
|
||||
printf("Humidity:\t%d.%d rH\n", sensor_value / 10, ABS_VALUE(sensor_value) % 10);
|
||||
|
||||
sensor_value = pressure_sensor.value(0);
|
||||
printf("Pressure:\t%d.%d mbar\n", sensor_value / 10, ABS_VALUE(sensor_value) % 10);
|
||||
|
||||
/* NOTE: this demo uses the mapping of ST Nucleo sensors on Contiki sensor API.
|
||||
* For a real use case of sensors like acceleration, magneto and gyroscope,
|
||||
* it is better to directly call the ST lib to get the three value (X/Y/Z)
|
||||
* at once.
|
||||
*/
|
||||
printf("Magneto:\t%d/%d/%d (X/Y/Z) mgauss\n", magneto_sensor.value(X_AXIS),
|
||||
magneto_sensor.value(Y_AXIS),
|
||||
magneto_sensor.value(Z_AXIS));
|
||||
|
||||
printf("Acceleration:\t%d/%d/%d (X/Y/Z) mg\n", acceleration_sensor.value(X_AXIS),
|
||||
acceleration_sensor.value(Y_AXIS),
|
||||
acceleration_sensor.value(Z_AXIS));
|
||||
|
||||
printf("Gyroscope:\t%d/%d/%d (X/Y/Z) mdps\n", gyroscope_sensor.value(X_AXIS),
|
||||
gyroscope_sensor.value(Y_AXIS),
|
||||
gyroscope_sensor.value(Z_AXIS));
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
2
platform/stm32nucleo-spirit1/Makefile.ids01a4
Normal file
2
platform/stm32nucleo-spirit1/Makefile.ids01a4
Normal file
|
@ -0,0 +1,2 @@
|
|||
#Simply set the correct flag
|
||||
CFLAGS += -DX_NUCLEO_IDS01A4
|
2
platform/stm32nucleo-spirit1/Makefile.ids01a5
Normal file
2
platform/stm32nucleo-spirit1/Makefile.ids01a5
Normal file
|
@ -0,0 +1,2 @@
|
|||
#Simply set the correct flag
|
||||
CFLAGS += -DX_NUCLEO_IDS01A5
|
23
platform/stm32nucleo-spirit1/Makefile.iks01a1
Normal file
23
platform/stm32nucleo-spirit1/Makefile.iks01a1
Normal file
|
@ -0,0 +1,23 @@
|
|||
CFLAGS += -DX_NUCLEO_IKS01A1
|
||||
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/x_nucleo_iks01a1
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/sensors/hts221 stm32cube-lib/drivers/sensors/lps25h stm32cube-lib/drivers/sensors/lps25hb\
|
||||
stm32cube-lib/drivers/sensors/lsm6ds0 stm32cube-lib/drivers/sensors/lsm6ds3 stm32cube-lib/drivers/sensors/lis3mdl
|
||||
|
||||
ARCH_DEV_SENSORS = temperature-sensor.c humidity-sensor.c pressure-sensor.c magneto-sensor.c acceleration-sensor.c gyroscope-sensor.c
|
||||
|
||||
ARCH_DRIVERS_IKS01A1 = x_nucleo_iks01a1.c x_nucleo_iks01a1_hum_temp.c x_nucleo_iks01a1_imu_6axes.c \
|
||||
x_nucleo_iks01a1_magneto.c x_nucleo_iks01a1_pressure.c
|
||||
|
||||
|
||||
ARCH_DRIVERS_SENSORS = hts221.c \
|
||||
lis3mdl.c \
|
||||
lps25h.c \
|
||||
lps25hb.c \
|
||||
lsm6ds0.c \
|
||||
lsm6ds3.c
|
||||
|
||||
ARCH+=$(ARCH_DEV_SENSORS)
|
||||
ARCH+=$(ARCH_DRIVERS_IKS01A1)
|
||||
ARCH+=$(ARCH_DRIVERS_SENSORS)
|
||||
|
246
platform/stm32nucleo-spirit1/Makefile.stm32nucleo-spirit1
Normal file
246
platform/stm32nucleo-spirit1/Makefile.stm32nucleo-spirit1
Normal file
|
@ -0,0 +1,246 @@
|
|||
|
||||
CONTIKI_TARGET_DIRS = .
|
||||
|
||||
ifeq ($(BOARD),)
|
||||
BOARD=ids01a4
|
||||
${info ***************************************************}
|
||||
${info BOARD not specified, default to ids01a4 (868 MHz)!}
|
||||
${info ***************************************************}
|
||||
else ifeq ($(BOARD),ids01a4)
|
||||
${info ***************************************************}
|
||||
${info Using ids01a4 SPIRIT1 expansion board (868 MHz)}
|
||||
${info ***************************************************}
|
||||
else ifeq ($(BOARD),ids01a5)
|
||||
${info ***************************************************}
|
||||
${info Using ids01a5 SPIRIT1 expansion board (915 MHz)}
|
||||
${info ***************************************************}
|
||||
else
|
||||
${info ***************************************************}
|
||||
${info You must specify a valid SPIRIT1 board to use:}
|
||||
${info make BOARD=ids01a4 for X-NUCLEO-IDS01A4 (868 MHz)}
|
||||
${info make BOARD=ids01a5 for X-NUCLEO-IDS01A5 (915 MHz)}
|
||||
${info ***************************************************}
|
||||
${error }
|
||||
endif
|
||||
|
||||
### Include the board-specific makefile
|
||||
PLATFORM_ROOT_DIR = $(CONTIKI)/platform/$(TARGET)
|
||||
-include $(PLATFORM_ROOT_DIR)/Makefile.$(BOARD)
|
||||
|
||||
ifeq ($(SENSORBOARD),iks01a1)
|
||||
${info Compiling with X-NUCLEO-IKS01A1 sensors files}
|
||||
${info ***************************************************}
|
||||
-include $(PLATFORM_ROOT_DIR)/Makefile.$(SENSORBOARD)
|
||||
else ifeq ($(SENSORBOARD),)
|
||||
${info NOT compiling files for any sensors expansion board}
|
||||
${info ***************************************************}
|
||||
else
|
||||
${info Error: SENSORBOARD can be: iks01a1}
|
||||
${info ***************************************************}
|
||||
${error }
|
||||
endif
|
||||
|
||||
|
||||
|
||||
#Currently we support only GCC
|
||||
GCC=1
|
||||
|
||||
CONTIKI_TARGET_DIRS += dev
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/stm32cube-prj/Src
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/stm32l1xx_nucleo
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/x_nucleo_ids01ax
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/Common
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/spirit1/src stm32cube-lib/drivers/spirit1/inc
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/CMSIS
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/STM32L1xx_HAL_Driver
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/STM32L1xx_HAL_Driver/Src
|
||||
CONTIKI_TARGET_DIRS += stm32cube-lib/drivers/STM32L1xx_HAL_Driver/Inc
|
||||
|
||||
|
||||
ARCH_DEV = button-sensor.c leds-arch.c radio-sensor.c
|
||||
|
||||
ARCH_NUCLEOSPIRIT1 = contiki-spirit1-main.c uart-msg.c spirit1-arch.c spirit1.c node-id.c
|
||||
|
||||
ARCH_NUCLEOSPIRIT1_STM32CUBEHAL = spirit1_appli.c stm32l1xx_hal_msp.c stm32l1xx_it.c stm32cube_hal_init.c
|
||||
|
||||
ARCH_DRIVERS_STM32L1xx = stm32l1xx_nucleo.c
|
||||
|
||||
ARCH_DRIVERS_IDS01AX = radio_gpio.c radio_shield_config.c radio_spi.c
|
||||
|
||||
ARCH_DRIVERS_SPIRIT1 = \
|
||||
SPIRIT1_Util.c \
|
||||
SPIRIT_Aes.c \
|
||||
SPIRIT_Calibration.c \
|
||||
SPIRIT_Commands.c \
|
||||
SPIRIT_Csma.c \
|
||||
SPIRIT_DirectRF.c \
|
||||
SPIRIT_General.c \
|
||||
SPIRIT_Gpio.c \
|
||||
SPIRIT_Irq.c \
|
||||
SPIRIT_LinearFifo.c \
|
||||
SPIRIT_Management.c \
|
||||
SPIRIT_PktBasic.c \
|
||||
SPIRIT_PktCommon.c \
|
||||
SPIRIT_PktMbus.c \
|
||||
SPIRIT_PktStack.c \
|
||||
SPIRIT_Qi.c \
|
||||
SPIRIT_Radio.c \
|
||||
SPIRIT_Timer.c \
|
||||
SPIRIT_Types.c
|
||||
|
||||
STM32L1XX_HAL =\
|
||||
stm32l1xx_hal.c\
|
||||
stm32l1xx_hal_adc_ex.c\
|
||||
stm32l1xx_hal_adc.c\
|
||||
stm32l1xx_hal_comp.c\
|
||||
stm32l1xx_hal_cortex.c\
|
||||
stm32l1xx_hal_crc.c\
|
||||
stm32l1xx_hal_cryp_ex.c\
|
||||
stm32l1xx_hal_cryp.c\
|
||||
stm32l1xx_hal_dac_ex.c\
|
||||
stm32l1xx_hal_dac.c\
|
||||
stm32l1xx_hal_dma.c\
|
||||
stm32l1xx_hal_flash_ex.c\
|
||||
stm32l1xx_hal_flash.c\
|
||||
stm32l1xx_hal_flash_ramfunc.c\
|
||||
stm32l1xx_hal_gpio.c\
|
||||
stm32l1xx_hal_i2c.c\
|
||||
stm32l1xx_hal_i2s.c\
|
||||
stm32l1xx_hal_irda.c\
|
||||
stm32l1xx_hal_iwdg.c\
|
||||
stm32l1xx_hal_lcd.c\
|
||||
stm32l1xx_hal_nor.c\
|
||||
stm32l1xx_hal_opamp_ex.c\
|
||||
stm32l1xx_hal_opamp.c\
|
||||
stm32l1xx_hal_pcd_ex.c\
|
||||
stm32l1xx_hal_pcd.c\
|
||||
stm32l1xx_hal_pwr_ex.c\
|
||||
stm32l1xx_hal_pwr.c\
|
||||
stm32l1xx_hal_rcc_ex.c\
|
||||
stm32l1xx_hal_rcc.c\
|
||||
stm32l1xx_hal_rtc_ex.c\
|
||||
stm32l1xx_hal_rtc.c\
|
||||
stm32l1xx_hal_sd.c\
|
||||
stm32l1xx_hal_smartcard.c\
|
||||
stm32l1xx_hal_spi_ex.c\
|
||||
stm32l1xx_hal_spi.c\
|
||||
stm32l1xx_hal_sram.c\
|
||||
stm32l1xx_hal_tim_ex.c\
|
||||
stm32l1xx_hal_tim.c\
|
||||
stm32l1xx_hal_uart.c\
|
||||
stm32l1xx_hal_usart.c\
|
||||
stm32l1xx_hal_wwdg.c\
|
||||
stm32l1xx_ll_fsmc.c\
|
||||
stm32l1xx_ll_sdmmc.c
|
||||
|
||||
ARCH+=$(ARCH_DEV)
|
||||
ARCH+=$(ARCH_NUCLEOSPIRIT1)
|
||||
ARCH+=$(ARCH_NUCLEOSPIRIT1_STM32CUBEHAL)
|
||||
ARCH+=$(ARCH_DRIVERS_STM32L1xx)
|
||||
ARCH+=$(ARCH_DRIVERS_IDS01AX)
|
||||
ARCH+=$(ARCH_DRIVERS_SPIRIT1)
|
||||
ARCH+=$(STM32L1XX_HAL)
|
||||
|
||||
CFLAGS += -DUSE_STM32L152_EVAL \
|
||||
-DSTM32L152xE \
|
||||
-DUSE_STM32L1XX_NUCLEO \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DUSE_STDPERIPH_DRIVER \
|
||||
-DNO_EEPROM \
|
||||
-DSPIRIT1_ST_SHIELD \
|
||||
-DSPIRIT_MODULE \
|
||||
-DUSE_SPIRIT1_DEFAULT
|
||||
|
||||
CFLAGS += -I. \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/ \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/stm32cube-lib/stm32cube-prj/Inc \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/stm32cube-lib/drivers/Common \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/stm32cube-lib/drivers/spirit1/inc \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/stm32cube-lib/drivers/CMSIS \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/stm32cube-lib/drivers/STM32L1xx_HAL_Driver/Inc \
|
||||
-I$(CONTIKI)/cpu/arm/stm32l152 \
|
||||
-I$(CONTIKI)/core \
|
||||
-I$(CONTIKI)/platform/$(TARGET)/dev
|
||||
|
||||
ifdef UIP_CONF_IPV6
|
||||
CFLAGS += -DWITH_UIP6=1
|
||||
endif
|
||||
|
||||
|
||||
ifndef CONTIKI_TARGET_MAIN
|
||||
CONTIKI_TARGET_MAIN = contiki-spirit1-main.c
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(CONTIKI_TARGET_MAIN)
|
||||
|
||||
MCU=stm32l152
|
||||
CONTIKI_CPU=$(CONTIKI)/cpu/arm/stm32l152
|
||||
include $(CONTIKI)/cpu/arm/stm32l152/Makefile.stm32l152
|
||||
|
||||
|
||||
MODULES+=core/net \
|
||||
core/net/mac core/net/mac/contikimac \
|
||||
core/net/llsec
|
||||
|
||||
|
||||
# build rules ------------------------------------
|
||||
|
||||
CLEAN += *.stm32nucleo-spirit1 symbols.c symbols.h contiki-stm32nucleo-spirit1.log
|
||||
|
||||
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
|
||||
|
||||
help:
|
||||
@echo A few useful make commands:
|
||||
@echo make help - shows this help
|
||||
@echo make TARGET=stm32nucleo-spirit1 savetarget - stores selection of target to avoid using TARGET= on every make invokation
|
||||
@echo make program.upload - compiles and uploads program to connected board
|
||||
@echo make program.upload IAR=1 - uses the IAR compiler instead of gcc (not implemented yet)
|
||||
@echo make program.upload NODEID=x - uploads with node_id set to x
|
||||
|
||||
# Serialdump rules
|
||||
ifeq ($(HOST_OS),Windows)
|
||||
SERIALDUMP = serialdump-windows
|
||||
# this ID is a string with which the node identifies itself as, and is used to
|
||||
# find the proper /dev/comX-port in Cygwin to connect to.
|
||||
CYGWIN_DEV_ID="stm32nucleo-spirit1 Spirit1 Platform"
|
||||
# include $(CONTIKI)/tools/cygwin/Makefile.cygwin
|
||||
endif
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
SERIALDUMP = serialdump-macos
|
||||
endif
|
||||
ifndef SERIALDUMP
|
||||
# Assume Linux
|
||||
SERIALDUMP = serialdump-linux
|
||||
endif
|
||||
|
||||
# IAR/windows/cygwin only for now; after GCC port, see if stm32flash works with Linux
|
||||
STLINKCLI=ST-LINK_CLI.exe
|
||||
%.upload: %.hex
|
||||
#Note: this command only uploads to a single connected device
|
||||
#$(STLINKCLI) -ME || $(STLINKCLI) -ME || $(STLINKCLI) -ME || $(STLINKCLI) -ME
|
||||
$(STLINKCLI) -Q -P $*.hex -V -Run
|
||||
|
||||
|
||||
# devcon requires WinDriverKit, downloadable from microsoft.com
|
||||
DEVCON=devcon.exe
|
||||
DEVCON_ALLDEVS=$(shell $(DEVCON) find =USB | grep "STMicroelectronics STLink dongle" | cut -d " " -f 1)
|
||||
devcon_enableonly:
|
||||
devcon disable =USB @"USB\VID_0483&PID_3748\*"
|
||||
devcon enable =USB @"$(ID)"
|
||||
|
||||
%.uploadall: %.hex
|
||||
$(foreach D,$(DEVCON_ALLDEVS), echo D IS "$(D)" && make devcon_enableonly ID="$(D)" && make $*.upload && ) echo "Done"
|
||||
devcon enable =USB @"USB\VID_0483&PID_3748\*"
|
||||
|
||||
login:
|
||||
@echo "Connecting to $(COMPORT)"
|
||||
$(CONTIKI)/tools/sky/$(SERIALDUMP) -b115200 $(COMPORT)
|
||||
|
||||
%.ramusage: %.$(TARGET)
|
||||
$(NM) -S $< --size-sort --line-numbers | grep -v " T " | grep -v " t "
|
||||
%.romusage: %.$(TARGET)
|
||||
$(NM) -S $< --size-sort --line-numbers | grep -v " b " | grep -v " B " | grep -v " d " | grep -v " D "
|
||||
|
||||
|
||||
|
||||
|
167
platform/stm32nucleo-spirit1/README.md
Normal file
167
platform/stm32nucleo-spirit1/README.md
Normal file
|
@ -0,0 +1,167 @@
|
|||
Getting Started with Contiki for STM32 Nucleo equipped with sub-1GHz SPIRIT1 expansion boards
|
||||
=============================================================================================
|
||||
|
||||
This guide explains how to get started with the STM32 Nucleo and expansion boards port to Contiki.
|
||||
|
||||
Maintainers and Contacts
|
||||
========================
|
||||
|
||||
Long-term maintainers:
|
||||
* Marco Grella, marco.grella@st.com, github user: [STclab](https://github.com/STclab)
|
||||
* Alok Mittal, alok.mittal@st.com, github user: [STclab](https://github.com/STclab)
|
||||
* Indar Prakash Singhal, indar.singhal@st.com, github user: [STclab](https://github.com/STclab)
|
||||
|
||||
Contributors:
|
||||
* David Siorpaes, david.siorpaes@st.com, github user: [siorpaes](https://github.com/siorpaes)
|
||||
* Luca Celetto, luca.celetto@st.com
|
||||
|
||||
Port Feature
|
||||
============
|
||||
|
||||
The port supports the following boards from ST:
|
||||
- NUCLEO-L152RE board, based on the STM32L152RET6 ultra-low power microcontroller
|
||||
- X-NUCLEO-IDS01A4 based on sub-1GHz SPSGRF-868 SPIRIT1 module (operating at 868 MHz)
|
||||
- X-NUCLEO-IDS01A5 based on sub-1GHz SPSGRF-915 SPIRIT1 module (operating at 915 MHz)
|
||||
- X-NUCLEO-IKS01A1 featuring motion MEMS and environmental sensors (optional)
|
||||
|
||||
The following drivers are included:
|
||||
- LEDs and buttons (user, reset)
|
||||
- USB
|
||||
- SPIRIT1 sub-1GHz transceiver
|
||||
- HTS221, LIS3MDL, LPS25HB, LSM6DS0 sensors
|
||||
|
||||
|
||||
Hardware Requirements
|
||||
=====================
|
||||
|
||||
* NUCLEO-L152RE development board
|
||||
|
||||
>The NUCLEO-L152RE board belongs to the STM32 Nucleo family.
|
||||
It features an STM32L152RET6 ultra-low power microcontroller based on ARM Cortex M3 MCU.
|
||||
Detailed information on the NUCLEO-L152RE development board can be found at:
|
||||
http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260002
|
||||
|
||||
|
||||
* X-NUCLEO-IDS01Ax sub-1GHz expansion board
|
||||
|
||||
>The X-NUCLEO-IDS01A4 and X-NUCLEO-IDS01A5 are STM32 Nucleo expansion boards that use
|
||||
the module SPSGRF-868 or SPSGRF-915 based on SPIRIT1 low data rate, low power sub-1 GHz transceiver.
|
||||
|
||||
>The user can select the X-NUCLEO-IDS01A4 board to operate the SPIRIT1 transceiver at 868MHz or the X-NUCLEO-IDS01A5 board to operate the SPIRIT1 transceiver at 915MHz.
|
||||
|
||||
>Detailed information on the X-NUCLEO-IDS01A4 expansion board can be found at:
|
||||
http://www.st.com/web/catalog/tools/FM146/CL2167/SC2006/PF261982
|
||||
|
||||
>Detailed information on the X-NUCLEO-IDS01A5 expansion board can be found at:
|
||||
http://www.st.com/web/catalog/tools/FM146/CL2167/SC2006/PF261983
|
||||
|
||||
>Detailed information on the SPIRIT1 sub-1GHz transceiver can be found at:
|
||||
http://www.st.com/web/catalog/sense_power/FM2185/SC1845/PF253167
|
||||
|
||||
* X-NUCLEO-IKS01A1, motion MEMS and environmental sensors expansion board (OPTIONAL)
|
||||
|
||||
>The X-NUCLEO-IKS01A1 is a motion MEMS and environmental sensor evaluation board.
|
||||
The use of this board is optional in the stm32nucleo-spirit1 Contiki platform.
|
||||
|
||||
>Detailed information on the X-NUCLEO-IKS01A1 expansion board can be found at:
|
||||
http://www.st.com/web/catalog/tools/FM146/CL2167/SC2006/PF261191
|
||||
|
||||
|
||||
* USB type A to Mini-B USB cable, to connect the STM32 Nucleo board to the PC
|
||||
|
||||
Software Requirements
|
||||
=====================
|
||||
|
||||
The following software are needed:
|
||||
|
||||
* ST port of Contiki for STM32 Nucleo and expansion boards.
|
||||
|
||||
>The port is automatically installed when both the Contiki and the submodule repository are cloned: the former hosts the Contiki distribution and the ST platform interface, the latter hosts the actual library. The following commands are needed to download the full porting:
|
||||
|
||||
git clone https://github.com/STclab/contiki.git
|
||||
cd contiki/
|
||||
git checkout stm32nucleo-spirit1
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
|
||||
Note: the first and third steps are required only if using the STclab GitHub repository, they won't be needed any more once the Pull Request is accepted.
|
||||
|
||||
The platform name is: stm32nucleo-spirit1
|
||||
|
||||
* A toolchain to build the firmware: The port has been developed and tested with GNU Tools
|
||||
for ARM Embedded Processors.
|
||||
>The toolchain can be found at: https://launchpad.net/gcc-arm-embedded
|
||||
The port was developed and tested using this version: gcc-arm-none-eabi v4.8.3
|
||||
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
The following examples have been successfully tested:
|
||||
|
||||
* examples/stm32nucleo-spirit1/sensor-demo
|
||||
* examples/ipv6/simple-udp-rpl (multicast, rpl-border-router, simple-udp-rpl)
|
||||
|
||||
|
||||
Build an example
|
||||
================
|
||||
In order to build an example go to the selected example directory (see a list of tested
|
||||
examples in the previous section).
|
||||
|
||||
For example, go to examples/ipv6/simple-udp-rpl directory.
|
||||
|
||||
|
||||
If the X-NUCLEO-IDS01A4 sub-1GHz RF expansion board is used, the following must be run:
|
||||
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a4 clean
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a4
|
||||
|
||||
If the X-NUCLEO-IDS01A5 sub-1GHz RF expansion board is used, the following must be run:
|
||||
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a5 clean
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a5
|
||||
|
||||
|
||||
This will create executables for UDP sender and receiver nodes.
|
||||
|
||||
In order to generate binary files that can be flashed on the STM32 Nucleo the following command must be run:
|
||||
|
||||
arm-none-eabi-objcopy -O binary unicast-sender.stm32nucleo-spirit1 unicast-sender.bin
|
||||
arm-none-eabi-objcopy -O binary unicast-receiver.stm32nucleo-spirit1 unicast-receiver.bin
|
||||
|
||||
These executables can be programmed on the nodes using the procedure described hereafter.
|
||||
|
||||
|
||||
In case you need to build an example that uses the additional sensors expansion board
|
||||
(for example, considering a system made of NUCLEO-L152RE, X-NUCLEO-IDS01A4 and X-NUCLEO-IKS01A1)
|
||||
then the command to be run would be:
|
||||
|
||||
make TARGET=stm32nucleo-spirit1 BOARD=ids01a4 SENSORBOARD=iks01a1
|
||||
|
||||
System setup
|
||||
============
|
||||
|
||||
1. Check that the jumper on the J1 connector on the X-NUCLEO-IDS01Ax expansion board is connected.
|
||||
This jumper provides the required voltage to the devices on the board.
|
||||
|
||||
2. Connect the X-NUCLEO-IDS01Ax board to the STM32 Nucleo board (NUCLEO-L152RE) from the top.
|
||||
|
||||
3. If the optional X-NUCLEO-IKS01A1 board is used, connect it on top of the X-NUCLEO-IDS01Ax board.
|
||||
|
||||
4. Power the STM32 Nucleo board using the Mini-B USB cable connected to the PC.
|
||||
|
||||
5. Program the firmware on the STM32 Nucleo board.
|
||||
This can be done by copying the binary file on the USB mass storage that is
|
||||
automatically created when plugging the STM32 Nucleo board to the PC.
|
||||
|
||||
6. Reset the MCU by using the reset button on the STM32 Nucleo board
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
140
platform/stm32nucleo-spirit1/contiki-conf.h
Normal file
140
platform/stm32nucleo-spirit1/contiki-conf.h
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "platform-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define SLIP_BRIDGE_CONF_NO_PUTCHAR 1
|
||||
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
#define NULLRDC_CONF_802154_AUTOACK 0
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
|
||||
#undef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
#define NETSTACK_RDC_HEADER_LEN 0
|
||||
|
||||
#undef NETSTACK_CONF_MAC
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_MAC_HEADER_LEN 0
|
||||
|
||||
#define SICSLOWPAN_CONF_MAC_MAX_PAYLOAD \
|
||||
(NETSTACK_RADIO_MAX_PAYLOAD_LEN - NETSTACK_MAC_HEADER_LEN - \
|
||||
NETSTACK_RDC_HEADER_LEN)
|
||||
|
||||
#define RIMESTATS_CONF_ENABLED 0
|
||||
#define RIMESTATS_CONF_ON 0
|
||||
|
||||
/* Network setup for IPv6 */
|
||||
#define CXMAC_CONF_ANNOUNCEMENTS 0
|
||||
|
||||
/* A trick to resolve a compilation error with IAR. */
|
||||
#ifdef __ICCARM__
|
||||
#define UIP_CONF_DS6_AADDR_NBU 1
|
||||
#endif
|
||||
|
||||
/* radio driver blocks until ACK is received */
|
||||
#define NULLRDC_CONF_ACK_WAIT_TIME (0)
|
||||
#define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0
|
||||
#define IEEE802154_CONF_PANID 0xABCD
|
||||
|
||||
#define AODV_COMPLIANCE
|
||||
|
||||
#define WITH_ASCII 1
|
||||
|
||||
#define PROCESS_CONF_NUMEVENTS 8
|
||||
#define PROCESS_CONF_STATS 1
|
||||
/*#define PROCESS_CONF_FASTPOLL 4*/
|
||||
|
||||
#define LINKADDR_CONF_SIZE 8
|
||||
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
|
||||
/* configure number of neighbors and routes */
|
||||
#ifndef UIP_CONF_DS6_ROUTE_NBU
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 30
|
||||
#endif /* UIP_CONF_DS6_ROUTE_NBU */
|
||||
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000 /* 90000// 600000 */
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#define UIP_CONF_IPV6 1
|
||||
#ifndef UIP_CONF_IPV6_QUEUE_PKT
|
||||
#define UIP_CONF_IPV6_QUEUE_PKT 0
|
||||
#endif /* UIP_CONF_IPV6_QUEUE_PKT */
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 280
|
||||
/* #define UIP_CONF_BUFFER_SIZE 600 */
|
||||
#endif
|
||||
|
||||
#define SICSLOWPAN_CONF_MAXAGE 4
|
||||
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
|
||||
|
||||
#ifndef SICSLOWPAN_CONF_MAX_MAC_TRANSMISSIONS
|
||||
#define SICSLOWPAN_CONF_MAX_MAC_TRANSMISSIONS 5
|
||||
#endif /* SICSLOWPAN_CONF_MAX_MAC_TRANSMISSIONS */
|
||||
|
||||
#define UIP_CONF_ICMP_DEST_UNREACH 1
|
||||
|
||||
#define UIP_CONF_DHCP_LIGHT
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
#ifndef UIP_CONF_RECEIVE_WINDOW
|
||||
#define UIP_CONF_RECEIVE_WINDOW 150
|
||||
#endif
|
||||
#ifndef UIP_CONF_TCP_MSS
|
||||
#define UIP_CONF_TCP_MSS UIP_CONF_RECEIVE_WINDOW
|
||||
#endif
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||
#define UIP_CONF_UDP_CONNS 12
|
||||
#define UIP_CONF_FWCACHE_SIZE 30
|
||||
#define UIP_CONF_BROADCAST 1
|
||||
#define UIP_ARCH_IPCHKSUM 0
|
||||
#define UIP_CONF_UDP 1
|
||||
#define UIP_CONF_UDP_CHECKSUMS 1
|
||||
#define UIP_CONF_TCP 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* include the project config */
|
||||
/* PROJECT_CONF_H might be defined in the project Makefile */
|
||||
#ifdef PROJECT_CONF_H
|
||||
#include PROJECT_CONF_H
|
||||
#endif /* PROJECT_CONF_H */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* CONTIKI_CONF_H */
|
||||
/*---------------------------------------------------------------------------*/
|
195
platform/stm32nucleo-spirit1/contiki-spirit1-main.c
Normal file
195
platform/stm32nucleo-spirit1/contiki-spirit1-main.c
Normal file
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* main file for stm32nucleo-spirit1 platform
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "stm32cube_hal_init.h"
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "sys/autostart.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/xmem.h"
|
||||
#include "lib/random.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
#include "net/rime/rime.h"
|
||||
#include "stm32l1xx.h"
|
||||
#include "SPIRIT_Config.h"
|
||||
#include "SPIRIT_Management.h"
|
||||
#include "spirit1.h"
|
||||
#include "spirit1-arch.h"
|
||||
#include "node-id.h"
|
||||
#include "hw-config.h"
|
||||
#include "stdbool.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/radio-sensor.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#endif /*NETSTACK_CONF_WITH_IPV6*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
extern const struct sensors_sensor temperature_sensor;
|
||||
extern const struct sensors_sensor humidity_sensor;
|
||||
extern const struct sensors_sensor pressure_sensor;
|
||||
extern const struct sensors_sensor magneto_sensor;
|
||||
extern const struct sensors_sensor acceleration_sensor;
|
||||
extern const struct sensors_sensor gyroscope_sensor;
|
||||
SENSORS(&button_sensor,
|
||||
&radio_sensor,
|
||||
&temperature_sensor,
|
||||
&humidity_sensor,
|
||||
&pressure_sensor,
|
||||
&magneto_sensor,
|
||||
&acceleration_sensor,
|
||||
&gyroscope_sensor);
|
||||
#else /*X_NUCLEO_IKS01A1*/
|
||||
SENSORS(&button_sensor,
|
||||
&radio_sensor);
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern unsigned char node_mac[8];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef __GNUC__
|
||||
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
|
||||
set to 'Yes') calls __io_putchar() */
|
||||
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
|
||||
#else
|
||||
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE * f)
|
||||
#endif /* __GNUC__ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
PROCINIT(&etimer_process, &tcpip_process);
|
||||
#else /*NETSTACK_CONF_WITH_IPV6*/
|
||||
PROCINIT(&etimer_process);
|
||||
#warning "No TCP/IP process!"
|
||||
#endif /*NETSTACK_CONF_WITH_IPV6*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUSYWAIT_UNTIL(cond, max_time) \
|
||||
do { \
|
||||
rtimer_clock_t t0; \
|
||||
t0 = RTIMER_NOW(); \
|
||||
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \
|
||||
} while(0)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void set_rime_addr(void);
|
||||
void stm32cube_hal_init();
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
static void
|
||||
panic_main(void)
|
||||
{
|
||||
volatile uint16_t k;
|
||||
while(1) {
|
||||
leds_toggle(LEDS_ALL);
|
||||
for(k = 0; k < 0xffff / 8; k += 1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
stm32cube_hal_init();
|
||||
|
||||
/* init LEDs */
|
||||
leds_init();
|
||||
|
||||
/* Initialize Contiki and our processes. */
|
||||
clock_init();
|
||||
ctimer_init();
|
||||
rtimer_init();
|
||||
watchdog_init();
|
||||
process_init();
|
||||
process_start(&etimer_process, NULL);
|
||||
|
||||
/* Restore node id if such has been stored in external mem */
|
||||
node_id_restore(); /* also configures node_mac[] */
|
||||
|
||||
set_rime_addr();
|
||||
random_init(node_id);
|
||||
|
||||
netstack_init();
|
||||
spirit_radio_driver.on();
|
||||
|
||||
energest_init();
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
|
||||
|
||||
queuebuf_init();
|
||||
process_start(&tcpip_process, NULL);
|
||||
|
||||
uip_ipaddr_t ipaddr;
|
||||
uip_ip6addr(&ipaddr, 0xfc00, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6*/
|
||||
|
||||
process_start(&sensors_process, NULL);
|
||||
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
watchdog_start();
|
||||
|
||||
while(1) {
|
||||
int r = 0;
|
||||
do {
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_rime_addr(void)
|
||||
{
|
||||
linkaddr_t addr;
|
||||
|
||||
memset(&addr, 0, sizeof(linkaddr_t));
|
||||
memcpy(addr.u8, node_mac, sizeof(addr.u8));
|
||||
|
||||
linkaddr_set_node_addr(&addr);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
142
platform/stm32nucleo-spirit1/dev/acceleration-sensor.c
Normal file
142
platform/stm32nucleo-spirit1/dev/acceleration-sensor.c
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-temperature-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Temperature sensor (on expansion board)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "acceleration-sensor.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
/*Acceleration and Gyroscope sensors share the same hw*/
|
||||
if(!st_lib_bsp_imu_6axes_is_initialized()) {
|
||||
if(IMU_6AXES_OK == st_lib_bsp_imu_6axes_init()) {
|
||||
_active = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
int32_t ret_val = 0;
|
||||
volatile st_lib_axes_raw_typedef axes_raw_data;
|
||||
|
||||
/* NOTE: this is a demo of mapping ST Nucleo sensors on Contiki sensor API.
|
||||
* For a real use case of sensors like acceleration, magneto and gyroscope,
|
||||
* it is better to directly call the ST lib to get the three value (X/Y/Z)
|
||||
* at once.
|
||||
*/
|
||||
st_lib_bsp_imu_6axes_x_get_axes_raw(&axes_raw_data);
|
||||
|
||||
switch(type) {
|
||||
case X_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_X;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_Y;
|
||||
break;
|
||||
case Z_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_Z;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(acceleration_sensor, ACCELERATION_SENSOR,
|
||||
value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
60
platform/stm32nucleo-spirit1/dev/acceleration-sensor.h
Normal file
60
platform/stm32nucleo-spirit1/dev/acceleration-sensor.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-acceleration-sensor Acceleration Sensor
|
||||
*
|
||||
* Maps the acceleration sensor on the STM32 Nucleo Sensor Expansion board.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 Acceleration Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef ACCELERATION_SENSOR_H_
|
||||
#define ACCELERATION_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "sensor-common.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor acceleration_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define ACCELERATION_SENSOR "Acceleration"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* ACCELERATION_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
111
platform/stm32nucleo-spirit1/dev/button-sensor.c
Normal file
111
platform/stm32nucleo-spirit1/dev/button-sensor.c
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 User Button
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "dev/button-sensor.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
/* See spirit1_appli.c for the Callback: it triggers the relevant
|
||||
* sensors_changed event
|
||||
*/
|
||||
st_lib_bsp_pb_init(BUTTON_USER, BUTTON_MODE_EXTI);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return st_lib_bsp_pb_get_state(BUTTON_USER);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
141
platform/stm32nucleo-spirit1/dev/gyroscope-sensor.c
Normal file
141
platform/stm32nucleo-spirit1/dev/gyroscope-sensor.c
Normal file
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-gyroscope-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Gyroscope sensor (on expansion board)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "gyroscope-sensor.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
/*Acceleration and Gyroscope sensors share the same hw*/
|
||||
if(!st_lib_bsp_imu_6axes_is_initialized()) {
|
||||
if(IMU_6AXES_OK == st_lib_bsp_imu_6axes_init()) {
|
||||
_active = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
int32_t ret_val = 0;
|
||||
volatile st_lib_axes_raw_typedef axes_raw_data;
|
||||
|
||||
/* NOTE: this is a demo of mapping ST Nucleo sensors on Contiki sensor API.
|
||||
* For a real use case of sensors like acceleration, magneto and gyroscope,
|
||||
* it is better to directly call the ST lib to get the three value (X/Y/Z)
|
||||
* at once.
|
||||
*/
|
||||
st_lib_bsp_imu_6axes_g_get_axes_raw(&axes_raw_data);
|
||||
|
||||
switch(type) {
|
||||
case X_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_X;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_Y;
|
||||
break;
|
||||
case Z_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_Z;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(gyroscope_sensor, GYROSCOPE_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
60
platform/stm32nucleo-spirit1/dev/gyroscope-sensor.h
Normal file
60
platform/stm32nucleo-spirit1/dev/gyroscope-sensor.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-gyroscope-sensor Gyroscope Sensor
|
||||
*
|
||||
* Maps the gyroscope sensor on the STM32 Sensor Expansion board.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 Gyroscope Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef GYROSCOPE_SENSOR_H_
|
||||
#define GYROSCOPE_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "sensor-common.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor gyroscope_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define GYROSCOPE_SENSOR "Gyroscope"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* GYROSCOPE_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
122
platform/stm32nucleo-spirit1/dev/humidity-sensor.c
Normal file
122
platform/stm32nucleo-spirit1/dev/humidity-sensor.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-humidity-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Humidity sensor (on expansion board)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "humidity-sensor.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
/*Temperature and Humity sensors share the same hw*/
|
||||
if(!st_lib_bsp_hum_temp_is_initialized()) {
|
||||
st_lib_bsp_hum_temp_init();
|
||||
_active = 1;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
uint32_t humidity;
|
||||
volatile float humidity_value;
|
||||
|
||||
st_lib_bsp_hum_temp_get_humidity((float *)&humidity_value);
|
||||
|
||||
humidity = humidity_value * 10;
|
||||
return humidity;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(humidity_sensor, HUMIDITY_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
59
platform/stm32nucleo-spirit1/dev/humidity-sensor.h
Normal file
59
platform/stm32nucleo-spirit1/dev/humidity-sensor.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-humidity-sensor Humidity Sensor
|
||||
*
|
||||
* Maps the humidity sensor on the STM32 Nucleo Sensor Expansion board.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 Humidity Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef HUMIDITY_SENSOR_H_
|
||||
#define HUMIDITY_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor humidity_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define HUMIDITY_SENSOR "Humidity"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* HUMIDITY_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
113
platform/stm32nucleo-spirit1/dev/leds-arch.c
Normal file
113
platform/stm32nucleo-spirit1/dev/leds-arch.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 LEDs
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/leds.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef X_NUCLEO_IKS01A1
|
||||
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
|
||||
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
|
||||
*/
|
||||
extern st_lib_gpio_typedef *st_lib_a_led_gpio_port[];
|
||||
extern const uint16_t st_lib_a_led_gpio_pin[];
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
|
||||
extern st_lib_gpio_typedef *st_lib_gpio_port[];
|
||||
extern const uint16_t st_lib_gpio_pin[];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
leds_arch_init(void)
|
||||
{
|
||||
/* We have at least one led, the one on the Nucleo (GREEN)*/
|
||||
st_lib_bsp_led_init(LED2);
|
||||
st_lib_bsp_led_off(LED2);
|
||||
|
||||
#ifndef X_NUCLEO_IKS01A1
|
||||
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
|
||||
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
|
||||
*/
|
||||
st_lib_radio_shield_led_init(RADIO_SHIELD_LED);
|
||||
st_lib_radio_shield_led_off(RADIO_SHIELD_LED);
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
leds_arch_get(void)
|
||||
{
|
||||
unsigned char ret = 0;
|
||||
if(st_lib_hal_gpio_read_pin(st_lib_gpio_port[LED2], st_lib_gpio_pin[LED2])) {
|
||||
ret |= LEDS_GREEN;
|
||||
}
|
||||
|
||||
#ifndef X_NUCLEO_IKS01A1
|
||||
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
|
||||
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
|
||||
*/
|
||||
if(st_lib_hal_gpio_read_pin(st_lib_a_led_gpio_port[RADIO_SHIELD_LED],
|
||||
st_lib_a_led_gpio_pin[RADIO_SHIELD_LED])) {
|
||||
ret |= LEDS_RED;
|
||||
}
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
leds_arch_set(unsigned char leds)
|
||||
{
|
||||
if(leds & LEDS_GREEN) {
|
||||
st_lib_bsp_led_on(LED2);
|
||||
} else {
|
||||
st_lib_bsp_led_off(LED2);
|
||||
}
|
||||
|
||||
#ifndef X_NUCLEO_IKS01A1
|
||||
/* The Red LED (on SPIRIT1 exp board) is exposed only if the
|
||||
* X-NUCLEO-IKS01A1 sensor board is NOT used, becasue of a pin conflict.
|
||||
*/
|
||||
if(leds & LEDS_RED) {
|
||||
st_lib_radio_shield_led_on(RADIO_SHIELD_LED);
|
||||
} else {
|
||||
st_lib_radio_shield_led_off(RADIO_SHIELD_LED);
|
||||
}
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
137
platform/stm32nucleo-spirit1/dev/magneto-sensor.c
Normal file
137
platform/stm32nucleo-spirit1/dev/magneto-sensor.c
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-magneto-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Magneto sensor (on expansion board)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "magneto-sensor.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
BSP_MAGNETO_Init();
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
int32_t ret_val = 0;
|
||||
volatile st_lib_axes_raw_typedef axes_raw_data;
|
||||
|
||||
/* NOTE: this is a demo of mapping ST Nucleo sensors on Contiki sensor API.
|
||||
* For a real use case of sensors like acceleration, magneto and gyroscope,
|
||||
* it is better to directly call the ST lib to get the three value (X/Y/Z)
|
||||
* at once.
|
||||
*/
|
||||
st_lib_bsp_magneto_m_get_axes_raw(&axes_raw_data);
|
||||
|
||||
switch(type) {
|
||||
case X_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_X;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_Y;
|
||||
break;
|
||||
case Z_AXIS:
|
||||
ret_val = axes_raw_data.AXIS_Z;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(magneto_sensor, MAGNETO_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
60
platform/stm32nucleo-spirit1/dev/magneto-sensor.h
Normal file
60
platform/stm32nucleo-spirit1/dev/magneto-sensor.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-magneto-sensor Magneto Sensor
|
||||
*
|
||||
* Maps the magneto sensor on the STM32 Nucleo Sensor Expansion board.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 Magneto Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef MAGNETO_SENSOR_H_
|
||||
#define MAGNETO_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "sensor-common.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor magneto_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define MAGNETO_SENSOR "Magneto"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* MAGNETO_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
118
platform/stm32nucleo-spirit1/dev/pressure-sensor.c
Normal file
118
platform/stm32nucleo-spirit1/dev/pressure-sensor.c
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-pressure-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Pressure sensor (on expansion board)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "pressure-sensor.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
st_lib_bsp_pressure_init();
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
uint16_t pressure;
|
||||
volatile float pressure_value;
|
||||
|
||||
st_lib_bsp_pressure_get_pressure((float *)&pressure_value);
|
||||
pressure = pressure_value * 10;
|
||||
|
||||
return pressure;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(pressure_sensor, PRESSURE_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/** @} */
|
59
platform/stm32nucleo-spirit1/dev/pressure-sensor.h
Normal file
59
platform/stm32nucleo-spirit1/dev/pressure-sensor.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-pressure-sensor Pressure Sensor
|
||||
*
|
||||
* Maps the pressure sensor on the STM32 Nucleo Sensor Expansion board.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 Pressure Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef PRESSURE_SENSOR_H_
|
||||
#define PRESSURE_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor pressure_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define PRESSURE_SENSOR "Pressure"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* PRESSURE_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
128
platform/stm32nucleo-spirit1/dev/radio-sensor.c
Normal file
128
platform/stm32nucleo-spirit1/dev/radio-sensor.c
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Radio Sensor (RSSI, LQI, ...)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "dev/radio-sensor.h"
|
||||
#include "dev/sensor-common.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "net/packetbuf.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
/*Nothing to do at the moment, can be used in the future.*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
int32_t radio_sensor;
|
||||
float radio_sensor_value;
|
||||
|
||||
switch(type) {
|
||||
case RADIO_SENSOR_LAST_PACKET:
|
||||
/*TODO: check which method of getting these value is more appropriate */
|
||||
radio_sensor_value = DBM_VALUE(packetbuf_attr(PACKETBUF_ATTR_RSSI));
|
||||
/* radio_sensor_value = st_lib_spirit_qi_get_rssi_dbm(); */
|
||||
radio_sensor = (int32_t)(radio_sensor_value * 10);
|
||||
break;
|
||||
case RADIO_SENSOR_LAST_VALUE:
|
||||
default:
|
||||
/*TODO: check which method of getting these value is more appropriate */
|
||||
radio_sensor = packetbuf_attr(PACKETBUF_ATTR_LINK_QUALITY);
|
||||
/* radio_sensor = (int32_t) st_lib_spirit_qi_get_lqi(); */
|
||||
}
|
||||
|
||||
return radio_sensor;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
53
platform/stm32nucleo-spirit1/dev/sensor-common.h
Normal file
53
platform/stm32nucleo-spirit1/dev/sensor-common.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
*
|
||||
* \file
|
||||
* Header file for common sensor definitions.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef SENSOR_COMMON_H_
|
||||
#define SENSOR_COMMON_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define X_AXIS 0x00
|
||||
#define Y_AXIS 0x01
|
||||
#define Z_AXIS 0x02
|
||||
|
||||
#define ABS_VALUE(x) (((x) > 0) ? (x) : (-(x)))
|
||||
#define DBM_VALUE(x) (-120.0 + ((float)((x) - 20)) / 2)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*SENSOR_COMMON_H_*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
121
platform/stm32nucleo-spirit1/dev/temperature-sensor.c
Normal file
121
platform/stm32nucleo-spirit1/dev/temperature-sensor.c
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-temperature-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the stm32nucleo-spirit1 Temperature sensor (on expansion board)
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "temperature-sensor.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int _active = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
/*Temperature and Humity sensors share the same hw*/
|
||||
if(!st_lib_bsp_hum_temp_is_initialized()) {
|
||||
st_lib_bsp_hum_temp_init();
|
||||
_active = 1;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
_active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
_active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return _active;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
int32_t temperature;
|
||||
volatile float temperature_value;
|
||||
|
||||
st_lib_bsp_hum_temp_get_temperature((float *)&temperature_value);
|
||||
temperature = temperature_value * 10;
|
||||
return temperature;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
|
||||
value, configure, status);
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
59
platform/stm32nucleo-spirit1/dev/temperature-sensor.h
Normal file
59
platform/stm32nucleo-spirit1/dev/temperature-sensor.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-temperature-sensor Temperature Sensor
|
||||
*
|
||||
* Maps the temperature sensor on the STM32 Nucleo Sensor Expansion board.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 Temperature Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef TEMPERATURE_SENSOR_H_
|
||||
#define TEMPERATURE_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor temperature_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define TEMPERATURE_SENSOR "Temperature"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* TEMPERATURE_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
48
platform/stm32nucleo-spirit1/dev/uart1.h
Normal file
48
platform/stm32nucleo-spirit1/dev/uart1.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1-peripherals
|
||||
* @{
|
||||
*
|
||||
*
|
||||
* \file
|
||||
* Header file for UART related definitions.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef UART1_H_
|
||||
#define UART1_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BAUD2UBR(baud) baud
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* UART1_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
117
platform/stm32nucleo-spirit1/hw-config.h
Normal file
117
platform/stm32nucleo-spirit1/hw-config.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __HW_CONFIG_H
|
||||
#define __HW_CONFIG_H
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "stm32l-spirit1-config.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define UART_RxBufferSize 512
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define I2Cx I2C1
|
||||
#define I2Cx_CLK_ENABLE() __I2C1_CLK_ENABLE()
|
||||
#define I2Cx_SDA_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
|
||||
#define I2Cx_SCL_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define I2Cx_FORCE_RESET() __I2C1_FORCE_RESET()
|
||||
#define I2Cx_RELEASE_RESET() __I2C1_RELEASE_RESET()
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Definition for I2Cx Pins */
|
||||
#define I2Cx_SCL_PIN GPIO_PIN_8
|
||||
#define I2Cx_SCL_GPIO_PORT GPIOB
|
||||
#define I2Cx_SDA_PIN GPIO_PIN_9
|
||||
#define I2Cx_SDA_GPIO_PORT GPIOB
|
||||
#define I2Cx_SCL_SDA_AF GPIO_AF4_I2C1
|
||||
|
||||
/* Definition for I2Cx's NVIC */
|
||||
#define I2Cx_EV_IRQn I2C1_EV_IRQn
|
||||
#define I2Cx_ER_IRQn I2C1_ER_IRQn
|
||||
#define I2Cx_EV_IRQHandler I2C1_EV_IRQHandler
|
||||
#define I2Cx_ER_IRQHandler I2C1_ER_IRQHandler
|
||||
|
||||
#define I2Cx I2C1
|
||||
#define I2Cx_CLK_ENABLE() __I2C1_CLK_ENABLE()
|
||||
#define I2Cx_SDA_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
|
||||
#define I2Cx_SCL_GPIO_CLK_ENABLE() __GPIOB_CLK_ENABLE()
|
||||
|
||||
#define I2Cx_FORCE_RESET() __I2C1_FORCE_RESET()
|
||||
#define I2Cx_RELEASE_RESET() __I2C1_RELEASE_RESET()
|
||||
|
||||
/* Definition for I2Cx Pins */
|
||||
#define I2Cx_SCL_PIN GPIO_PIN_8
|
||||
#define I2Cx_SCL_GPIO_PORT GPIOB
|
||||
#define I2Cx_SDA_PIN GPIO_PIN_9
|
||||
#define I2Cx_SDA_GPIO_PORT GPIOB
|
||||
#define I2Cx_SCL_SDA_AF GPIO_AF4_I2C1
|
||||
|
||||
/* Definition for I2Cx's NVIC */
|
||||
#define I2Cx_EV_IRQn I2C1_EV_IRQn
|
||||
#define I2Cx_ER_IRQn I2C1_ER_IRQn
|
||||
#define I2Cx_EV_IRQHandler I2C1_EV_IRQHandler
|
||||
#define I2Cx_ER_IRQHandler I2C1_ER_IRQHandler
|
||||
|
||||
/* User can use this section to tailor USARTx/UARTx instance used and associated
|
||||
resources */
|
||||
/* Definition for USARTx clock resources */
|
||||
#define USARTx USART2
|
||||
#define USARTx_CLK_ENABLE() __USART2_CLK_ENABLE();
|
||||
#define DMAx_CLK_ENABLE() __DMA1_CLK_ENABLE()
|
||||
#define USARTx_RX_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
|
||||
#define USARTx_TX_GPIO_CLK_ENABLE() __GPIOA_CLK_ENABLE()
|
||||
|
||||
#define USARTx_FORCE_RESET() __USART2_FORCE_RESET()
|
||||
#define USARTx_RELEASE_RESET() __USART2_RELEASE_RESET()
|
||||
|
||||
/* Definition for USARTx Pins */
|
||||
#define USARTx_TX_PIN GPIO_PIN_2
|
||||
#define USARTx_TX_GPIO_PORT GPIOA
|
||||
|
||||
#define USARTx_RX_PIN GPIO_PIN_3
|
||||
#define USARTx_RX_GPIO_PORT GPIOA
|
||||
|
||||
/* Definition for USARTx's NVIC */
|
||||
#define USARTx_IRQn USART2_IRQn
|
||||
#define USARTx_IRQHandler USART2_IRQHandler
|
||||
|
||||
#define USARTx_TX_AF GPIO_AF7_USART2
|
||||
#define USARTx_RX_AF GPIO_AF7_USART2
|
||||
|
||||
/* Enable sensor mask */
|
||||
#define PRESSURE_SENSOR 0x00000001
|
||||
#define TEMPERATURE_SENSOR 0x00000002
|
||||
#define HUMIDITY_SENSOR 0x00000004
|
||||
#define UV_SENSOR 0x00000008
|
||||
#define ACCELEROMETER_SENSOR 0x00000010
|
||||
#define GYROSCOPE_SENSOR 0x00000020
|
||||
#define MAGNETIC_SENSOR 0x00000040
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*__HW_CONFIG_H*/
|
||||
/*---------------------------------------------------------------------------*/
|
55
platform/stm32nucleo-spirit1/node-id.c
Normal file
55
platform/stm32nucleo-spirit1/node-id.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "node-id.h"
|
||||
#include "contiki-conf.h"
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned short node_id = 0;
|
||||
unsigned char node_mac[8];
|
||||
volatile uint32_t device_id[3];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEVICE_ID_REG0 (*((volatile uint32_t *)0x1FF80050))
|
||||
#define DEVICE_ID_REG1 (*((volatile uint32_t *)0x1FF80054))
|
||||
#define DEVICE_ID_REG2 (*((volatile uint32_t *)0x1FF80064))
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
node_id_restore(void)
|
||||
{
|
||||
device_id[0] = DEVICE_ID_REG0;
|
||||
device_id[1] = DEVICE_ID_REG1;
|
||||
device_id[2] = DEVICE_ID_REG2;
|
||||
|
||||
(*(uint32_t *)node_mac) = DEVICE_ID_REG1;
|
||||
(*(((uint32_t *)node_mac) + 1)) = DEVICE_ID_REG2 + DEVICE_ID_REG0;
|
||||
node_id = (unsigned short)DEVICE_ID_REG2;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
109
platform/stm32nucleo-spirit1/platform-conf.h
Normal file
109
platform/stm32nucleo-spirit1/platform-conf.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup stm32nucleo-spirit1
|
||||
* @{
|
||||
*
|
||||
* \defgroup stm32nucleo-spirit1-peripherals User Button on STM32 Nucleo
|
||||
*
|
||||
* Defines some of the platforms capabilities
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the stm32nucleo-spirit1 platform configuration
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __PLATFORM_CONF_H__
|
||||
#define __PLATFORM_CONF_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define PLATFORM_HAS_LEDS 1
|
||||
#define PLATFORM_HAS_BUTTON 1
|
||||
#define PLATFORM_HAS_RADIO 1
|
||||
|
||||
#define LEDS_GREEN 1 /*Nucleo LED*/
|
||||
#define LEDS_RED 2 /*SPIRIT1 LED*/
|
||||
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
#define LEDS_CONF_ALL 1 /*Can't use SPIRIT1 LED in this case*/
|
||||
#else
|
||||
#define LEDS_CONF_ALL 3 /*No sensors -> we can use SPIRIT1 LED in this case*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define F_CPU 32000000ul
|
||||
#define RTIMER_ARCH_SECOND 32768
|
||||
#define PRESCALER ((F_CPU / (RTIMER_ARCH_SECOND * 2)))
|
||||
|
||||
#define UART1_CONF_TX_WITH_INTERRUPT 0
|
||||
#define WITH_SERIAL_LINE_INPUT 1
|
||||
#define TELNETD_CONF_NUMLINES 6
|
||||
#define NETSTACK_CONF_RADIO spirit_radio_driver
|
||||
#define NETSTACK_RADIO_MAX_PAYLOAD_LEN 96 /* spirit1-config.h */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* define ticks/second for slow and fast clocks. Notice that these should be a
|
||||
power of two, eg 64,128,256,512 etc, for efficiency as POT's can be optimized
|
||||
well. */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
/* One tick: 62.5 ms */
|
||||
|
||||
#define RTIMER_CLOCK_LT(a, b) ((signed short)((a) - (b)) < 0)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef unsigned long clock_time_t;
|
||||
typedef unsigned long long rtimer_clock_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define CC_CONF_REGISTER_ARGS 0
|
||||
#define CC_CONF_FUNCTION_POINTER_ARGS 1
|
||||
#define CC_CONF_FASTCALL
|
||||
#define CC_CONF_VA_ARGS 1
|
||||
#define CC_CONF_INLINE inline
|
||||
|
||||
#define CCIF
|
||||
#define CLIF
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef uint8_t u8_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef int32_t s32_t;
|
||||
typedef unsigned short uip_stats_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define MULTICHAN_CONF_SET_CHANNEL(x)
|
||||
#define MULTICHAN_CONF_READ_RSSI(x) 0
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __PLATFORM_CONF_H__ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
78
platform/stm32nucleo-spirit1/spirit1-arch.c
Normal file
78
platform/stm32nucleo-spirit1/spirit1-arch.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "stm32l1xx.h"
|
||||
#include "spirit1-arch.h"
|
||||
#include "spirit1.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern void spirit1_interrupt_callback(void);
|
||||
st_lib_spirit_bool spiritdk_timer_expired = S_FALSE;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* use the SPI-port to acquire the status bytes from the radio. */
|
||||
#define CS_TO_SCLK_DELAY 0x0100
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern st_lib_spi_handle_typedef st_lib_p_spi_handle;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
spirit1_arch_refresh_status(void)
|
||||
{
|
||||
volatile uint16_t mcstate = 0x0000;
|
||||
uint8_t header[2];
|
||||
header[0] = 0x01;
|
||||
header[1] = MC_STATE1_BASE;
|
||||
uint32_t spi_timeout = ((uint32_t)1000); /*<! Value of Timeout when SPI communication fails */
|
||||
|
||||
IRQ_DISABLE();
|
||||
|
||||
/* Puts the SPI chip select low to start the transaction */
|
||||
st_lib_radio_spi_cs_low();
|
||||
|
||||
for(volatile uint16_t index = 0; index < CS_TO_SCLK_DELAY; index++) {
|
||||
}
|
||||
|
||||
/* Write the aHeader bytes and read the SPIRIT1 status bytes */
|
||||
st_lib_hal_spi_transmit_receive(&st_lib_p_spi_handle, (uint8_t *)&header[0], (uint8_t *)&mcstate, 1, spi_timeout);
|
||||
mcstate = mcstate << 8;
|
||||
|
||||
/* Write the aHeader bytes and read the SPIRIT1 status bytes */
|
||||
st_lib_hal_spi_transmit_receive(&st_lib_p_spi_handle, (uint8_t *)&header[1], (uint8_t *)&mcstate, 1, spi_timeout);
|
||||
|
||||
/* To be sure to don't rise the Chip Select before the end of last sending */
|
||||
while(st_lib_hal_spi_get_flag(&st_lib_p_spi_handle, SPI_FLAG_TXE) == RESET) ;
|
||||
|
||||
/* Puts the SPI chip select high to end the transaction */
|
||||
st_lib_radio_spi_cs_high();
|
||||
|
||||
IRQ_ENABLE();
|
||||
|
||||
return mcstate;
|
||||
}
|
49
platform/stm32nucleo-spirit1/spirit1-arch.h
Normal file
49
platform/stm32nucleo-spirit1/spirit1-arch.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __SPIRIT1_ARCH_H__
|
||||
#define __SPIRIT1_ARCH_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "string.h"
|
||||
#include "SPIRIT_Management.h"
|
||||
#include "radio_gpio.h"
|
||||
#include "radio_spi.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define IRQ_ENABLE() st_lib_radio_gpio_interrupt_cmd(RADIO_GPIO_IRQ, 0x0F, 0x0F, ENABLE);
|
||||
#define IRQ_DISABLE() st_lib_radio_gpio_interrupt_cmd(RADIO_GPIO_IRQ, 0x0F, 0x0F, DISABLE);
|
||||
#define spirit_spi_busy() (!(RADIO_SPI_CS_PORT->IDR & RADIO_SPI_CS_PIN))
|
||||
#define SPIRIT1_STATUS() (spirit1_arch_refresh_status() & SPIRIT1_STATE_STATEBITS)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t spirit1_arch_refresh_status(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __SPIRIT1_ARCH_H__ */
|
59
platform/stm32nucleo-spirit1/spirit1-config.h
Normal file
59
platform/stm32nucleo-spirit1/spirit1-config.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __SPIRIT1_CONFIG_H__
|
||||
#define __SPIRIT1_CONFIG_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "radio.h"
|
||||
#include "SPIRIT_Config.h"
|
||||
#include "spirit1-const.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define CCA_THRESHOLD -120.0 /* dBm */
|
||||
#define XTAL_FREQUENCY 50000000 /* Hz */
|
||||
#define SPIRIT_MAX_FIFO_LEN 96
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* The MAX_PACKET_LEN is an arbitrary value used to define the two array
|
||||
* spirit_txbuf and spirit_rxbuf.
|
||||
* The SPIRIT1 supports with its packet handler a length of 65,535 bytes,
|
||||
* and in direct mode (without packet handler) there is no limit of data.
|
||||
*/
|
||||
#define MAX_PACKET_LEN SPIRIT_MAX_FIFO_LEN
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Spirit1 IC version
|
||||
*/
|
||||
#define SPIRIT1_VERSION SPIRIT_VERSION_3_0
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __SPIRIT1_CONFIG_H__ */
|
||||
/*---------------------------------------------------------------------------*/
|
65
platform/stm32nucleo-spirit1/spirit1-const.h
Normal file
65
platform/stm32nucleo-spirit1/spirit1-const.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __SPIRIT1_CONST_H__
|
||||
#define __SPIRIT1_CONST_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* The state bitfield and values for different states, as read from MC_STATE[1:0] registers,
|
||||
which are returned on any SPI read or write operation. */
|
||||
#define SPIRIT1_STATE_STATEBITS (0x00FE)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#define SPIRIT1_STATE_STANDBY ((0x0040) << 1)
|
||||
#define SPIRIT1_STATE_SLEEP ((0x0036) << 1)
|
||||
#define SPIRIT1_STATE_READY ((0x0003) << 1)
|
||||
#define SPIRIT1_STATE_LOCK ((0x000F) << 1)
|
||||
#define SPIRIT1_STATE_RX ((0x0033) << 1)
|
||||
#define SPIRIT1_STATE_TX ((0x005F) << 1)
|
||||
/* NB the below states were extracted from ST drivers, but are not specified in the datasheet */
|
||||
#define SPIRIT1_STATE_PM_SETUP ((0x003D) << 1)
|
||||
#define SPIRIT1_STATE_XO_SETTLING ((0x0023) << 1)
|
||||
#define SPIRIT1_STATE_SYNTH_SETUP ((0x0053) << 1)
|
||||
#define SPIRIT1_STATE_PROTOCOL ((0x001F) << 1)
|
||||
#define SPIRIT1_STATE_SYNTH_CALIBRATION ((0x004F) << 1)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* strobe commands */
|
||||
#define SPIRIT1_STROBE_TX 0x60
|
||||
#define SPIRIT1_STROBE_RX 0x61
|
||||
#define SPIRIT1_STROBE_READY 0x62
|
||||
#define SPIRIT1_STROBE_STANDBY 0x63
|
||||
#define SPIRIT1_STROBE_SLEEP 0x64
|
||||
#define SPIRIT1_STROBE_SABORT 0x67
|
||||
#define SPIRIT1_STROBE_SRES 0x70
|
||||
#define SPIRIT1_STROBE_FRX 0x71
|
||||
#define SPIRIT1_STROBE_FTX 0x72
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __SPIRIT1_CONST_H__ */
|
||||
/*---------------------------------------------------------------------------*/
|
713
platform/stm32nucleo-spirit1/spirit1.c
Normal file
713
platform/stm32nucleo-spirit1/spirit1.c
Normal file
|
@ -0,0 +1,713 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "spirit1.h"
|
||||
#include "spirit1-arch.h"
|
||||
#include "stm32l1xx.h"
|
||||
#include "contiki.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/packetbuf.h"
|
||||
#include "net/rime/rimestats.h"
|
||||
#include "spirit1-arch.h"
|
||||
#include <stdio.h>
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* MGR extern st_lib_spirit_irqs st_lib_x_irq_status; */
|
||||
extern volatile st_lib_spirit_flag_status rx_timeout;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define XXX_ACK_WORKAROUND 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUSYWAIT_UNTIL(cond, max_time) \
|
||||
do { \
|
||||
rtimer_clock_t t0; \
|
||||
t0 = RTIMER_NOW(); \
|
||||
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \
|
||||
} while(0)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define CLEAR_TXBUF() (spirit_txbuf[0] = 0)
|
||||
#define CLEAR_RXBUF() (spirit_rxbuf[0] = 0)
|
||||
#define IS_TXBUF_EMPTY() (spirit_txbuf[0] == 0)
|
||||
#define IS_RXBUF_EMPTY() (spirit_rxbuf[0] == 0)
|
||||
#define IS_RXBUF_FULL() (spirit_rxbuf[0] != 0)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* transceiver state. */
|
||||
#define ON 0
|
||||
#define OFF 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static volatile unsigned int spirit_on = OFF;
|
||||
static volatile uint8_t receiving_packet = 0;
|
||||
static packetbuf_attr_t last_rssi = 0; /* MGR */
|
||||
static packetbuf_attr_t last_lqi = 0; /* MGR */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* The buffers which hold incoming data.
|
||||
* The +1 because of the first byte,
|
||||
* which will contain the length of the packet.
|
||||
*/
|
||||
static uint8_t spirit_rxbuf[MAX_PACKET_LEN + 1];
|
||||
static uint8_t spirit_txbuf[MAX_PACKET_LEN + 1 - SPIRIT_MAX_FIFO_LEN];
|
||||
void st_lib_spirit_management_set_frequency_base(uint32_t);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int just_got_an_ack = 0; /* Interrupt callback just detected an ack */
|
||||
#if NULLRDC_CONF_802154_AUTOACK
|
||||
#define ACK_LEN 3
|
||||
static int wants_an_ack = 0; /* The packet sent expects an ack */
|
||||
/* static int just_got_an_ack = 0; / * Interrupt callback just detected an ack * / */
|
||||
/* #define ACKPRINTF printf */
|
||||
#define ACKPRINTF(...)
|
||||
#endif /* NULLRDC_CONF_802154_AUTOACK */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int packet_is_prepared = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(spirit_radio_process, "SPIRIT radio driver");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int spirit_radio_init(void);
|
||||
static int spirit_radio_prepare(const void *payload, unsigned short payload_len);
|
||||
static int spirit_radio_transmit(unsigned short payload_len);
|
||||
static int spirit_radio_send(const void *data, unsigned short len);
|
||||
static int spirit_radio_read(void *buf, unsigned short bufsize);
|
||||
static int spirit_radio_channel_clear(void);
|
||||
static int spirit_radio_receiving_packet(void);
|
||||
static int spirit_radio_pending_packet(void);
|
||||
static int spirit_radio_on(void);
|
||||
static int spirit_radio_off(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const struct radio_driver spirit_radio_driver =
|
||||
{
|
||||
spirit_radio_init,
|
||||
spirit_radio_prepare,
|
||||
spirit_radio_transmit,
|
||||
spirit_radio_send,
|
||||
spirit_radio_read,
|
||||
spirit_radio_channel_clear,
|
||||
spirit_radio_receiving_packet,
|
||||
spirit_radio_pending_packet,
|
||||
spirit_radio_on,
|
||||
spirit_radio_off,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
spirit1_printstatus(void)
|
||||
{
|
||||
int s = SPIRIT1_STATUS();
|
||||
if(s == SPIRIT1_STATE_STANDBY) {
|
||||
printf("spirit1: SPIRIT1_STATE_STANDBY\n");
|
||||
} else if(s == SPIRIT1_STATE_READY) {
|
||||
printf("spirit1: SPIRIT1_STATE_READY\n");
|
||||
} else if(s == SPIRIT1_STATE_TX) {
|
||||
printf("spirit1: SPIRIT1_STATE_TX\n");
|
||||
} else if(s == SPIRIT1_STATE_RX) {
|
||||
printf("spirit1: SPIRIT1_STATE_RX\n");
|
||||
} else {
|
||||
printf("spirit1: status: %d\n", s);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Strobe a command. The rationale for this is to clean up the messy legacy code. */
|
||||
static void
|
||||
spirit1_strobe(uint8_t s)
|
||||
{
|
||||
st_lib_spirit_cmd_strobe_command(s);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
spirit_set_ready_state(void)
|
||||
{
|
||||
PRINTF("READY IN\n");
|
||||
|
||||
st_lib_spirit_irq_clear_status();
|
||||
IRQ_DISABLE();
|
||||
|
||||
if(SPIRIT1_STATUS() == SPIRIT1_STATE_STANDBY) {
|
||||
spirit1_strobe(SPIRIT1_STROBE_READY);
|
||||
} else if(SPIRIT1_STATUS() == SPIRIT1_STATE_RX) {
|
||||
spirit1_strobe(SPIRIT1_STROBE_SABORT);
|
||||
st_lib_spirit_irq_clear_status();
|
||||
}
|
||||
|
||||
IRQ_ENABLE();
|
||||
|
||||
PRINTF("READY OUT\n");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_init(void)
|
||||
{
|
||||
|
||||
PRINTF("RADIO INIT IN\n");
|
||||
|
||||
st_lib_spirit_spi_init();
|
||||
|
||||
/* Configure radio shut-down (SDN) pin and activate radio */
|
||||
st_lib_radio_gpio_init(RADIO_GPIO_SDN, RADIO_MODE_GPIO_OUT);
|
||||
|
||||
/* Configures the SPIRIT1 library */
|
||||
st_lib_spirit_radio_set_xtal_frequency(XTAL_FREQUENCY);
|
||||
st_lib_spirit_management_set_frequency_base(XTAL_FREQUENCY);
|
||||
|
||||
/* wake up to READY state */
|
||||
/* weirdly enough, this *should* actually *set* the pin, not clear it! The pins is declared as GPIO_pin13 == 0x2000 */
|
||||
RADIO_GPIO_SDN_PORT->BSRR = RADIO_GPIO_SDN_PIN;
|
||||
st_lib_hal_gpio_write_pin(RADIO_GPIO_SDN_PORT, RADIO_GPIO_SDN_PIN, GPIO_PIN_RESET);
|
||||
|
||||
/* wait minimum 1.5 ms to allow SPIRIT1 a proper boot-up sequence */
|
||||
BUSYWAIT_UNTIL(0, 3 * RTIMER_SECOND / 2000);
|
||||
|
||||
/* Soft reset of core */
|
||||
spirit1_strobe(SPIRIT1_STROBE_SRES);
|
||||
|
||||
/* Configures the SPIRIT1 radio part */
|
||||
st_lib_s_radio_init x_radio_init = {
|
||||
/* XTAL_FREQUENCY, */
|
||||
XTAL_OFFSET_PPM,
|
||||
BASE_FREQUENCY,
|
||||
CHANNEL_SPACE,
|
||||
CHANNEL_NUMBER,
|
||||
MODULATION_SELECT,
|
||||
DATARATE,
|
||||
FREQ_DEVIATION,
|
||||
BANDWIDTH
|
||||
};
|
||||
st_lib_spirit_radio_init(&x_radio_init);
|
||||
st_lib_spirit_radio_set_xtal_frequency(XTAL_FREQUENCY);
|
||||
st_lib_spirit_radio_set_pa_level_dbm(0, POWER_DBM);
|
||||
st_lib_spirit_radio_set_pa_level_max_index(0);
|
||||
|
||||
/* Configures the SPIRIT1 packet handler part*/
|
||||
st_lib_pkt_basic_init x_basic_init = {
|
||||
PREAMBLE_LENGTH,
|
||||
SYNC_LENGTH,
|
||||
SYNC_WORD,
|
||||
LENGTH_TYPE,
|
||||
LENGTH_WIDTH,
|
||||
CRC_MODE,
|
||||
CONTROL_LENGTH,
|
||||
EN_ADDRESS,
|
||||
EN_FEC,
|
||||
EN_WHITENING
|
||||
};
|
||||
st_lib_spirit_pkt_basic_init(&x_basic_init);
|
||||
|
||||
/* Enable the following interrupt sources, routed to GPIO */
|
||||
st_lib_spirit_irq_de_init(NULL);
|
||||
st_lib_spirit_irq_clear_status();
|
||||
st_lib_spirit_irq(TX_DATA_SENT, S_ENABLE);
|
||||
st_lib_spirit_irq(RX_DATA_READY, S_ENABLE);
|
||||
st_lib_spirit_irq(VALID_SYNC, S_ENABLE);
|
||||
st_lib_spirit_irq(RX_DATA_DISC, S_ENABLE);
|
||||
st_lib_spirit_irq(TX_FIFO_ERROR, S_ENABLE);
|
||||
st_lib_spirit_irq(RX_FIFO_ERROR, S_ENABLE);
|
||||
|
||||
/* Configure Spirit1 */
|
||||
st_lib_spirit_radio_persisten_rx(S_ENABLE);
|
||||
st_lib_spirit_qi_set_sqi_threshold(SQI_TH_0);
|
||||
st_lib_spirit_qi_sqi_check(S_ENABLE);
|
||||
st_lib_spirit_qi_set_rssi_threshold_dbm(CCA_THRESHOLD);
|
||||
st_lib_spirit_timer_set_rx_timeout_stop_condition(SQI_ABOVE_THRESHOLD);
|
||||
SET_INFINITE_RX_TIMEOUT();
|
||||
st_lib_spirit_radio_afc_freeze_on_sync(S_ENABLE);
|
||||
|
||||
/* Puts the SPIRIT1 in STANDBY mode (125us -> rx/tx) */
|
||||
spirit1_strobe(SPIRIT1_STROBE_STANDBY);
|
||||
spirit_on = OFF;
|
||||
CLEAR_RXBUF();
|
||||
CLEAR_TXBUF();
|
||||
|
||||
/* Initializes the mcu pin as input, used for IRQ */
|
||||
st_lib_radio_gpio_init(RADIO_GPIO_IRQ, RADIO_MODE_EXTI_IN);
|
||||
|
||||
/* Configure the radio to route the IRQ signal to its GPIO 3 */
|
||||
st_lib_spirit_gpio_init(&(st_lib_s_gpio_init){SPIRIT_GPIO_IRQ, SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_LP, SPIRIT_GPIO_DIG_OUT_IRQ });
|
||||
|
||||
process_start(&spirit_radio_process, NULL);
|
||||
|
||||
PRINTF("Spirit1 init done\n");
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_prepare(const void *payload, unsigned short payload_len)
|
||||
{
|
||||
PRINTF("Spirit1: prep %u\n", payload_len);
|
||||
packet_is_prepared = 0;
|
||||
|
||||
/* Checks if the payload length is supported */
|
||||
if(payload_len > MAX_PACKET_LEN) {
|
||||
return RADIO_TX_ERR;
|
||||
}
|
||||
|
||||
/* Should we delay for an ack? */
|
||||
#if NULLRDC_CONF_802154_AUTOACK
|
||||
frame802154_t info154;
|
||||
wants_an_ack = 0;
|
||||
if(payload_len > ACK_LEN
|
||||
&& frame802154_parse((char *)payload, payload_len, &info154) != 0) {
|
||||
if(info154.fcf.frame_type == FRAME802154_DATAFRAME
|
||||
&& info154.fcf.ack_required != 0) {
|
||||
wants_an_ack = 1;
|
||||
}
|
||||
}
|
||||
#endif /* NULLRDC_CONF_802154_AUTOACK */
|
||||
|
||||
/* Sets the length of the packet to send */
|
||||
IRQ_DISABLE();
|
||||
spirit1_strobe(SPIRIT1_STROBE_FTX);
|
||||
st_lib_spirit_pkt_basic_set_payload_length(payload_len);
|
||||
st_lib_spirit_spi_write_linear_fifo(payload_len, (uint8_t *)payload);
|
||||
IRQ_ENABLE();
|
||||
|
||||
PRINTF("PREPARE OUT\n");
|
||||
|
||||
packet_is_prepared = 1;
|
||||
return RADIO_TX_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_transmit(unsigned short payload_len)
|
||||
{
|
||||
/* This function blocks until the packet has been transmitted */
|
||||
rtimer_clock_t rtimer_txdone, rtimer_rxack;
|
||||
|
||||
PRINTF("TRANSMIT IN\n");
|
||||
if(!packet_is_prepared) {
|
||||
return RADIO_TX_ERR;
|
||||
}
|
||||
|
||||
/* Stores the length of the packet to send */
|
||||
/* Others spirit_radio_prepare will be in hold */
|
||||
spirit_txbuf[0] = payload_len;
|
||||
|
||||
/* Puts the SPIRIT1 in TX state */
|
||||
receiving_packet = 0;
|
||||
spirit_set_ready_state();
|
||||
spirit1_strobe(SPIRIT1_STROBE_TX);
|
||||
just_got_an_ack = 0;
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_TX, 1 * RTIMER_SECOND / 1000);
|
||||
/* BUSYWAIT_UNTIL(SPIRIT1_STATUS() != SPIRIT1_STATE_TX, 4 * RTIMER_SECOND/1000); //For GFSK with high data rate */
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() != SPIRIT1_STATE_TX, 50 * RTIMER_SECOND / 1000); /* For FSK with low data rate */
|
||||
|
||||
/* Reset radio - needed for immediate RX of ack */
|
||||
CLEAR_TXBUF();
|
||||
CLEAR_RXBUF();
|
||||
IRQ_DISABLE();
|
||||
st_lib_spirit_irq_clear_status();
|
||||
spirit1_strobe(SPIRIT1_STROBE_SABORT);
|
||||
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 2500);
|
||||
spirit1_strobe(SPIRIT1_STROBE_READY);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_READY, 1 * RTIMER_SECOND / 1000);
|
||||
spirit1_strobe(SPIRIT1_STROBE_RX);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 1 * RTIMER_SECOND / 1000);
|
||||
IRQ_ENABLE();
|
||||
|
||||
#if XXX_ACK_WORKAROUND
|
||||
just_got_an_ack = 1;
|
||||
#endif /* XXX_ACK_WORKAROUND */
|
||||
|
||||
#if NULLRDC_CONF_802154_AUTOACK
|
||||
if(wants_an_ack) {
|
||||
rtimer_txdone = RTIMER_NOW();
|
||||
BUSYWAIT_UNTIL(just_got_an_ack, 2 * RTIMER_SECOND / 1000);
|
||||
rtimer_rxack = RTIMER_NOW();
|
||||
|
||||
if(just_got_an_ack) {
|
||||
ACKPRINTF("debug_ack: ack received after %u/%u ticks\n",
|
||||
(uint32_t)(rtimer_rxack - rtimer_txdone), 2 * RTIMER_SECOND / 1000);
|
||||
} else {
|
||||
ACKPRINTF("debug_ack: no ack received\n");
|
||||
}
|
||||
}
|
||||
#endif /* NULLRDC_CONF_802154_AUTOACK */
|
||||
|
||||
PRINTF("TRANSMIT OUT\n");
|
||||
|
||||
CLEAR_TXBUF();
|
||||
|
||||
packet_is_prepared = 0;
|
||||
|
||||
clock_wait(1);
|
||||
|
||||
return RADIO_TX_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_send(const void *payload, unsigned short payload_len)
|
||||
{
|
||||
if(spirit_radio_prepare(payload, payload_len) == RADIO_TX_ERR) {
|
||||
return RADIO_TX_ERR;
|
||||
}
|
||||
return spirit_radio_transmit(payload_len);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_read(void *buf, unsigned short bufsize)
|
||||
{
|
||||
PRINTF("READ IN\n");
|
||||
|
||||
/* Checks if the RX buffer is empty */
|
||||
if(IS_RXBUF_EMPTY()) {
|
||||
IRQ_DISABLE();
|
||||
CLEAR_RXBUF();
|
||||
spirit1_strobe(SPIRIT1_STROBE_SABORT);
|
||||
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 2500);
|
||||
spirit1_strobe(SPIRIT1_STROBE_READY);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_READY, 1 * RTIMER_SECOND / 1000);
|
||||
spirit1_strobe(SPIRIT1_STROBE_RX);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 1 * RTIMER_SECOND / 1000);
|
||||
PRINTF("READ OUT RX BUF EMPTY\n");
|
||||
IRQ_ENABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(bufsize < spirit_rxbuf[0]) {
|
||||
/* If buf has the correct size */
|
||||
PRINTF("TOO SMALL BUF\n");
|
||||
return 0;
|
||||
} else {
|
||||
/* Copies the packet received */
|
||||
memcpy(buf, spirit_rxbuf + 1, spirit_rxbuf[0]);
|
||||
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_RSSI, last_rssi); /* MGR */
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, last_lqi); /* MGR */
|
||||
bufsize = spirit_rxbuf[0];
|
||||
CLEAR_RXBUF();
|
||||
|
||||
PRINTF("READ OUT\n");
|
||||
|
||||
return bufsize;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_channel_clear(void)
|
||||
{
|
||||
float rssi_value;
|
||||
/* Local variable used to memorize the SPIRIT1 state */
|
||||
uint8_t spirit_state = ON;
|
||||
|
||||
PRINTF("CHANNEL CLEAR IN\n");
|
||||
|
||||
if(spirit_on == OFF) {
|
||||
/* Wakes up the SPIRIT1 */
|
||||
spirit_radio_on();
|
||||
spirit_state = OFF;
|
||||
}
|
||||
|
||||
/* */
|
||||
IRQ_DISABLE();
|
||||
spirit1_strobe(SPIRIT1_STROBE_SABORT);
|
||||
/* SpiritCmdStrobeSabort();*/
|
||||
st_lib_spirit_irq_clear_status();
|
||||
IRQ_ENABLE();
|
||||
{
|
||||
rtimer_clock_t timeout = RTIMER_NOW() + 5 * RTIMER_SECOND / 1000;
|
||||
do {
|
||||
st_lib_spirit_refresh_status();
|
||||
} while((st_lib_g_x_status.MC_STATE != MC_STATE_READY) && (RTIMER_NOW() < timeout));
|
||||
if(RTIMER_NOW() < timeout) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Stores the RSSI value */
|
||||
rssi_value = st_lib_spirit_qi_get_rssi_dbm();
|
||||
|
||||
/* Puts the SPIRIT1 in its previous state */
|
||||
if(spirit_state == OFF) {
|
||||
spirit_radio_off();
|
||||
} else {
|
||||
spirit1_strobe(SPIRIT1_STROBE_RX);
|
||||
/* SpiritCmdStrobeRx();*/
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 5 * RTIMER_SECOND / 1000);
|
||||
}
|
||||
|
||||
PRINTF("CHANNEL CLEAR OUT\n");
|
||||
|
||||
/* Checks the RSSI value with the threshold */
|
||||
if(rssi_value < CCA_THRESHOLD) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_receiving_packet(void)
|
||||
{
|
||||
return receiving_packet;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_pending_packet(void)
|
||||
{
|
||||
PRINTF("PENDING PACKET\n");
|
||||
return !IS_RXBUF_EMPTY();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_off(void)
|
||||
{
|
||||
PRINTF("Spirit1: ->off\n");
|
||||
if(spirit_on == ON) {
|
||||
/* Disables the mcu to get IRQ from the SPIRIT1 */
|
||||
IRQ_DISABLE();
|
||||
|
||||
/* first stop rx/tx */
|
||||
spirit1_strobe(SPIRIT1_STROBE_SABORT);
|
||||
|
||||
/* Clear any pending irqs */
|
||||
st_lib_spirit_irq_clear_status();
|
||||
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_READY, 5 * RTIMER_SECOND / 1000);
|
||||
if(SPIRIT1_STATUS() != SPIRIT1_STATE_READY) {
|
||||
PRINTF("Spirit1: failed off->ready\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Puts the SPIRIT1 in STANDBY */
|
||||
spirit1_strobe(SPIRIT1_STROBE_STANDBY);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_STANDBY, 5 * RTIMER_SECOND / 1000);
|
||||
if(SPIRIT1_STATUS() != SPIRIT1_STATE_STANDBY) {
|
||||
PRINTF("Spirit1: failed off->stdby\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
spirit_on = OFF;
|
||||
CLEAR_TXBUF();
|
||||
CLEAR_RXBUF();
|
||||
}
|
||||
PRINTF("Spirit1: off.\n");
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
spirit_radio_on(void)
|
||||
{
|
||||
|
||||
PRINTF("Spirit1: on\n");
|
||||
spirit1_strobe(SPIRIT1_STROBE_SABORT);
|
||||
BUSYWAIT_UNTIL(0, RTIMER_SECOND / 2500);
|
||||
if(spirit_on == OFF) {
|
||||
IRQ_DISABLE();
|
||||
/* ensure we are in READY state as we go from there to Rx */
|
||||
spirit1_strobe(SPIRIT1_STROBE_READY);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_READY, 5 * RTIMER_SECOND / 1000);
|
||||
if(SPIRIT1_STATUS() != SPIRIT1_STATE_READY) {
|
||||
PRINTF("Spirit1: failed to turn on\n");
|
||||
while(1) ;
|
||||
/* return 1; */
|
||||
}
|
||||
|
||||
/* now we go to Rx */
|
||||
spirit1_strobe(SPIRIT1_STROBE_RX);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 5 * RTIMER_SECOND / 1000);
|
||||
if(SPIRIT1_STATUS() != SPIRIT1_STATE_RX) {
|
||||
PRINTF("Spirit1: failed to enter rx\n");
|
||||
while(1) ;
|
||||
/* return 1; */
|
||||
}
|
||||
|
||||
/* Enables the mcu to get IRQ from the SPIRIT1 */
|
||||
IRQ_ENABLE();
|
||||
spirit_on = ON;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int interrupt_callback_in_progress = 0;
|
||||
static int interrupt_callback_wants_poll = 0;
|
||||
PROCESS_THREAD(spirit_radio_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
PRINTF("Spirit1: process started\n");
|
||||
|
||||
while(1) {
|
||||
int len;
|
||||
|
||||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
||||
PRINTF("Spirit1: polled\n");
|
||||
|
||||
packetbuf_clear();
|
||||
len = spirit_radio_read(packetbuf_dataptr(), PACKETBUF_SIZE);
|
||||
|
||||
if(len > 0) {
|
||||
|
||||
#if NULLRDC_CONF_802154_AUTOACK
|
||||
/* Check if the packet has an ACK request */
|
||||
frame802154_t info154;
|
||||
if(len > ACK_LEN &&
|
||||
frame802154_parse((char *)packetbuf_dataptr(), len, &info154) != 0) {
|
||||
if(info154.fcf.frame_type == FRAME802154_DATAFRAME &&
|
||||
info154.fcf.ack_required != 0 &&
|
||||
linkaddr_cmp((linkaddr_t *)&info154.dest_addr,
|
||||
&linkaddr_node_addr)) {
|
||||
|
||||
#if !XXX_ACK_WORKAROUND
|
||||
/* Send an ACK packet */
|
||||
uint8_t ack_frame[ACK_LEN] = {
|
||||
FRAME802154_ACKFRAME,
|
||||
0x00,
|
||||
info154.seq
|
||||
};
|
||||
IRQ_DISABLE();
|
||||
spirit1_strobe(SPIRIT1_STROBE_FTX);
|
||||
st_lib_spirit_pkt_basic_set_payload_length((uint16_t)ACK_LEN);
|
||||
st_lib_spirit_spi_write_linear_fifo((uint16_t)ACK_LEN, (uint8_t *)ack_frame);
|
||||
|
||||
spirit_set_ready_state();
|
||||
IRQ_ENABLE();
|
||||
spirit1_strobe(SPIRIT1_STROBE_TX);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_TX, 1 * RTIMER_SECOND / 1000);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() != SPIRIT1_STATE_TX, 1 * RTIMER_SECOND / 1000);
|
||||
ACKPRINTF("debug_ack: sent ack %d\n", ack_frame[2]);
|
||||
#endif /* !XXX_ACK_WORKAROUND */
|
||||
}
|
||||
}
|
||||
#endif /* NULLRDC_CONF_802154_AUTOACK */
|
||||
|
||||
packetbuf_set_datalen(len);
|
||||
NETSTACK_RDC.input();
|
||||
}
|
||||
|
||||
if(!IS_RXBUF_EMPTY()) {
|
||||
process_poll(&spirit_radio_process);
|
||||
}
|
||||
|
||||
if(interrupt_callback_wants_poll) {
|
||||
spirit1_interrupt_callback();
|
||||
|
||||
if(SPIRIT1_STATUS() == SPIRIT1_STATE_READY) {
|
||||
spirit1_strobe(SPIRIT1_STROBE_RX);
|
||||
BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 1 * RTIMER_SECOND / 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
spirit1_interrupt_callback(void)
|
||||
{
|
||||
#define INTPRINTF(...) /* PRINTF */
|
||||
st_lib_spirit_irqs x_irq_status;
|
||||
if(spirit_spi_busy() || interrupt_callback_in_progress) {
|
||||
process_poll(&spirit_radio_process);
|
||||
interrupt_callback_wants_poll = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
interrupt_callback_wants_poll = 0;
|
||||
interrupt_callback_in_progress = 1;
|
||||
|
||||
/* get interrupt source from radio */
|
||||
st_lib_spirit_irq_get_status(&x_irq_status);
|
||||
st_lib_spirit_irq_clear_status();
|
||||
|
||||
if(x_irq_status.IRQ_RX_FIFO_ERROR) {
|
||||
receiving_packet = 0;
|
||||
interrupt_callback_in_progress = 0;
|
||||
spirit1_strobe(SPIRIT1_STROBE_FRX);
|
||||
return;
|
||||
}
|
||||
|
||||
if(x_irq_status.IRQ_TX_FIFO_ERROR) {
|
||||
receiving_packet = 0;
|
||||
interrupt_callback_in_progress = 0;
|
||||
spirit1_strobe(SPIRIT1_STROBE_FTX);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The IRQ_VALID_SYNC is used to notify a new packet is coming */
|
||||
if(x_irq_status.IRQ_VALID_SYNC) {
|
||||
INTPRINTF("SYNC\n");
|
||||
receiving_packet = 1;
|
||||
}
|
||||
|
||||
/* The IRQ_TX_DATA_SENT notifies the packet received. Puts the SPIRIT1 in RX */
|
||||
if(x_irq_status.IRQ_TX_DATA_SENT) {
|
||||
spirit1_strobe(SPIRIT1_STROBE_RX);
|
||||
/* SpiritCmdStrobeRx();*/
|
||||
INTPRINTF("SENT\n");
|
||||
CLEAR_TXBUF();
|
||||
interrupt_callback_in_progress = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* The IRQ_RX_DATA_READY notifies a new packet arrived */
|
||||
if(x_irq_status.IRQ_RX_DATA_READY) {
|
||||
st_lib_spirit_spi_read_linear_fifo(st_lib_spirit_linear_fifo_read_num_elements_rx_fifo(),
|
||||
&spirit_rxbuf[1]);
|
||||
spirit_rxbuf[0] = st_lib_spirit_pkt_basic_get_received_pkt_length();
|
||||
spirit1_strobe(SPIRIT1_STROBE_FRX);
|
||||
|
||||
INTPRINTF("RECEIVED\n");
|
||||
|
||||
process_poll(&spirit_radio_process);
|
||||
|
||||
last_rssi = (packetbuf_attr_t)st_lib_spirit_qi_get_rssi(); /* MGR */
|
||||
last_lqi = (packetbuf_attr_t)st_lib_spirit_qi_get_lqi(); /* MGR */
|
||||
|
||||
receiving_packet = 0;
|
||||
|
||||
#if NULLRDC_CONF_802154_AUTOACK
|
||||
if(spirit_rxbuf[0] == ACK_LEN) {
|
||||
/* For debugging purposes we assume this is an ack for us */
|
||||
just_got_an_ack = 1;
|
||||
}
|
||||
#endif /* NULLRDC_CONF_802154_AUTOACK */
|
||||
|
||||
interrupt_callback_in_progress = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(x_irq_status.IRQ_RX_DATA_DISC) {
|
||||
/* RX command - to ensure the device will be ready for the next reception */
|
||||
if(x_irq_status.IRQ_RX_TIMEOUT) {
|
||||
st_lib_spirit_cmd_strobe_flush_rx_fifo();
|
||||
rx_timeout = SET;
|
||||
}
|
||||
}
|
||||
|
||||
interrupt_callback_in_progress = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
46
platform/stm32nucleo-spirit1/spirit1.h
Normal file
46
platform/stm32nucleo-spirit1/spirit1.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef __SPIRIT_H__
|
||||
#define __SPIRIT_H__
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "radio.h"
|
||||
#include "SPIRIT_Config.h"
|
||||
#include "spirit1-config.h"
|
||||
#include "spirit1_appli.h"
|
||||
#include "spirit1-const.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct radio_driver spirit_radio_driver;
|
||||
void spirit1_interrupt_callback(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* __SPIRIT_H__ */
|
||||
/*---------------------------------------------------------------------------*/
|
348
platform/stm32nucleo-spirit1/st-lib.h
Normal file
348
platform/stm32nucleo-spirit1/st-lib.h
Normal file
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \defgroup stm32nucleo-spirit1 STM32Cube HAL APIs
|
||||
*
|
||||
* Abstraction of STM32Cube HAL APIs as per Contiki coding rules
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the STM32Cube HAL APIs
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef ST_LIB_H_
|
||||
#define ST_LIB_H_
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* extern global varialbles */
|
||||
#define st_lib_uart_handle UartHandle
|
||||
|
||||
#define st_lib_g_x_status g_xStatus
|
||||
|
||||
#define st_lib_p_spi_handle pSpiHandle
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* misc */
|
||||
#define st_lib_tim2_irq_handler(...) TIM2_IRQHandler(__VA_ARGS__)
|
||||
#define st_lib_spirit_management_set_frequency_base(...) SpiritManagementSetFrequencyBase(__VA_ARGS__)
|
||||
#define st_lib_sys_tick_handler(...) SysTick_Handler(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* MCU_Interface.h */
|
||||
#include "MCU_Interface.h"
|
||||
|
||||
#define st_lib_spirit_spi_init(...) SpiritSpiInit(__VA_ARGS__)
|
||||
#define st_lib_spirit_spi_read_linear_fifo(...) SpiritSpiReadLinearFifo(__VA_ARGS__)
|
||||
#define st_lib_spirit_spi_write_linear_fifo(...) SpiritSpiWriteLinearFifo(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* radio_gpio.h */
|
||||
#include "radio_gpio.h"
|
||||
|
||||
#define st_lib_radio_gpio_interrupt_cmd(...) RadioGpioInterruptCmd(__VA_ARGS__)
|
||||
#define st_lib_radio_gpio_init(...) RadioGpioInit(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* radio_shield_config.h */
|
||||
#include "radio_shield_config.h"
|
||||
|
||||
#define st_lib_a_led_gpio_port aLED_GPIO_PORT
|
||||
#define st_lib_a_led_gpio_pin aLED_GPIO_PIN
|
||||
|
||||
#define st_lib_radio_shield_led_init(...) RadioShieldLedInit(__VA_ARGS__)
|
||||
#define st_lib_radio_shield_led_off(...) RadioShieldLedOff(__VA_ARGS__)
|
||||
#define st_lib_radio_shield_led_on(...) RadioShieldLedOn(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* radio_spi.h */
|
||||
#include "radio_spi.h"
|
||||
|
||||
#define st_lib_radio_spi_cs_high(...) RadioSpiCSHigh(__VA_ARGS__)
|
||||
#define st_lib_radio_spi_cs_low(...) RadioSpiCSLow(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Commands.h */
|
||||
#include "SPIRIT_Commands.h"
|
||||
|
||||
#define st_lib_spirit_cmd_strobe_flush_rx_fifo(...) SpiritCmdStrobeFlushRxFifo(__VA_ARGS__)
|
||||
#define st_lib_spirit_cmd_strobe_command(...) SpiritCmdStrobeCommand(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Gpio.h */
|
||||
#include "SPIRIT_Gpio.h"
|
||||
|
||||
#define st_lib_s_gpio_init SGpioInit
|
||||
|
||||
#define st_lib_spirit_gpio_init(...) SpiritGpioInit(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Irq.h */
|
||||
#include "SPIRIT_Irq.h"
|
||||
|
||||
#define st_lib_spirit_irqs SpiritIrqs
|
||||
|
||||
#define st_lib_spirit_irq(...) SpiritIrq(__VA_ARGS__)
|
||||
#define st_lib_spirit_irq_de_init(...) SpiritIrqDeInit(__VA_ARGS__)
|
||||
#define st_lib_spirit_irq_init(...) SpiritIrqInit(__VA_ARGS__)
|
||||
#define st_lib_spirit_irq_get_mask(...) SpiritIrqGetMask(__VA_ARGS__)
|
||||
#define st_lib_spirit_irq_get_status(...) SpiritIrqGetStatus(__VA_ARGS__)
|
||||
#define st_lib_spirit_irq_clear_status(...) SpiritIrqClearStatus(__VA_ARGS__)
|
||||
#define st_lib_spirit_irq_chack_flag(...) SpiritIrqCheckFlag(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_LinearFifo.h */
|
||||
#include "SPIRIT_LinearFifo.h"
|
||||
|
||||
#define st_lib_spirit_linear_fifo_read_num_elements_rx_fifo(...) SpiritLinearFifoReadNumElementsRxFifo(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_PktBasic.h */
|
||||
#include "SPIRIT_PktBasic.h"
|
||||
|
||||
#define st_lib_pkt_basic_init PktBasicInit
|
||||
|
||||
#define st_lib_spirit_pkt_basic_init(...) SpiritPktBasicInit(__VA_ARGS__)
|
||||
#define st_lib_spirit_pkt_basic_get_received_pkt_length(...) SpiritPktBasicGetReceivedPktLength(__VA_ARGS__)
|
||||
#define st_lib_spirit_pkt_basic_set_payload_length(...) SpiritPktBasicSetPayloadLength(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Qi.h */
|
||||
#include "SPIRIT_Qi.h"
|
||||
|
||||
#define st_lib_spirit_qi_get_rssi_dbm(...) SpiritQiGetRssidBm(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_pqi_check(...) SpiritQiPqiCheck(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_sqi_check(...) SpiritQiSqiCheck(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_set_pqi_threshold(...) SpiritQiSetPqiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_pqi_threshold(...) SpiritQiGetPqiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_set_sqi_threshold(...) SpiritQiSetSqiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_sqi_threshold(...) SpiritQiGetSqiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_set_rssi_threshold(...) SpiritQiSetRssiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_rssi_threshold(...) SpiritQiGetRssiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_compute_rssi_threshold(...) SpiritQiComputeRssiThreshold(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_set_rssi_threshold_dbm(...) SpiritQiSetRssiThresholddBm(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_pqi(...) SpiritQiGetPqi(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_sqi(...) SpiritQiGetSqi(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_lqi(...) SpiritQiGetLqi(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_cs(...) SpiritQiGetCs(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_rssi(...) SpiritQiGetRssi(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_set_rssi_filter_gain(...) SpiritQiSetRssiFilterGain(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_rssi_filter_gain(...) SpiritQiGetRssiFilterGain(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_set_cs_mode(...) SpiritQiSetCsMode(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_get_cs_mode(...) SpiritQiGetCsMode(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_cs_timeout_mask(...) SpiritQiCsTimeoutMask(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_pqi_timeout_mask(...) SpiritQiPqiTimeoutMask(__VA_ARGS__)
|
||||
#define st_lib_spirit_qi_sqi_timeout_mask(...) SpiritQiSqiTimeoutMask(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Radio.h */
|
||||
#include "SPIRIT_Radio.h"
|
||||
|
||||
#define st_lib_s_radio_init SRadioInit
|
||||
|
||||
#define st_lib_spirit_radio_afc_freeze_on_sync(...) SpiritRadioAFCFreezeOnSync(__VA_ARGS__)
|
||||
#define st_lib_spirit_radio_init(...) SpiritRadioInit(__VA_ARGS__)
|
||||
#define st_lib_spirit_radio_persisten_rx(...) SpiritRadioPersistenRx(__VA_ARGS__)
|
||||
#define st_lib_spirit_radio_set_pa_level_dbm(...) SpiritRadioSetPALeveldBm(__VA_ARGS__)
|
||||
#define st_lib_spirit_radio_set_pa_level_max_index(...) SpiritRadioSetPALevelMaxIndex(__VA_ARGS__)
|
||||
#define st_lib_spirit_radio_set_xtal_frequency(...) SpiritRadioSetXtalFrequency(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Timer.h */
|
||||
#include "SPIRIT_Timer.h"
|
||||
|
||||
#define st_lib_spirit_timer_set_rx_timeout_stop_condition(...) SpiritTimerSetRxTimeoutStopCondition(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* SPIRIT_Types.h */
|
||||
#include "SPIRIT_Types.h"
|
||||
|
||||
#define st_lib_spirit_bool SpiritBool
|
||||
#define st_lib_spirit_status SpiritStatus
|
||||
#define st_lib_spirit_flag_status SpiritFlagStatus
|
||||
|
||||
#define st_lib_spirit_refresh_status(...) SpiritRefreshStatus(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l152xe.h */
|
||||
#include "stm32l152xe.h"
|
||||
|
||||
#define st_lib_irq_n_type IRQn_Type
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx.h */
|
||||
#include "stm32l1xx.h"
|
||||
|
||||
#define st_lib_flag_status FlagStatus
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx_hal_cortex.h */
|
||||
#include "stm32l1xx_hal_cortex.h"
|
||||
|
||||
#define st_lib_hal_nvic_enable_irq(...) HAL_NVIC_EnableIRQ(__VA_ARGS__)
|
||||
#define st_lib_hal_nvic_set_priority(...) HAL_NVIC_SetPriority(__VA_ARGS__)
|
||||
#define st_lib_hal_systick_clk_source_config(...) HAL_SYSTICK_CLKSourceConfig(__VA_ARGS__)
|
||||
#define st_lib_hal_systick_config(...) HAL_SYSTICK_Config(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx_hal_rcc.h */
|
||||
#include "stm32l1xx_hal_rcc.h"
|
||||
|
||||
#define st_lib_tim2_clk_enable(...) __TIM2_CLK_ENABLE(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx_hal_spi.h */
|
||||
#include "stm32l1xx_hal_spi.h"
|
||||
|
||||
#define st_lib_spi_handle_typedef SPI_HandleTypeDef
|
||||
|
||||
#define st_lib_hal_spi_get_flag(...) __HAL_SPI_GET_FLAG(__VA_ARGS__)
|
||||
#define st_lib_hal_spi_transmit_receive(...) HAL_SPI_TransmitReceive(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx_hal_tim.h */
|
||||
#include "stm32l1xx_hal_tim.h"
|
||||
|
||||
#define st_lib_tim_handle_typedef TIM_HandleTypeDef
|
||||
#define st_lib_tim_clock_config_typedef TIM_ClockConfigTypeDef
|
||||
#define st_lib_tim_oc_init_typedef TIM_OC_InitTypeDef
|
||||
|
||||
#define st_lib_hal_tim_base_init(...) HAL_TIM_Base_Init(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_base_start_it(...) HAL_TIM_Base_Start_IT(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_config_clock_source(...) HAL_TIM_ConfigClockSource(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_clear_flag(...) __HAL_TIM_CLEAR_FLAG(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_clear_it(...) __HAL_TIM_CLEAR_IT(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_enable(...) __HAL_TIM_ENABLE(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_enable_it(...) __HAL_TIM_ENABLE_IT(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_oc_init(...) HAL_TIM_OC_Init(__VA_ARGS__)
|
||||
#define st_lib_hal_tim_oc_config_channel(...) HAL_TIM_OC_ConfigChannel(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx_hal_uart.h */
|
||||
#include "stm32l1xx_hal_uart.h"
|
||||
|
||||
#define st_lib_uart_handle_typedef UART_HandleTypeDef
|
||||
|
||||
#define st_lib_hal_uart_enable_it(...) __HAL_UART_ENABLE_IT(__VA_ARGS__)
|
||||
#define st_lib_hal_uart_init(...) HAL_UART_Init(__VA_ARGS__)
|
||||
#define st_lib_hal_uart_receive(...) HAL_UART_Receive(__VA_ARGS__)
|
||||
#define st_lib_hal_uart_receive_it(...) HAL_UART_Receive_IT(__VA_ARGS__)
|
||||
#define st_lib_hal_uart_rx_cplt_callback(...) HAL_UART_RxCpltCallback(__VA_ARGS__)
|
||||
#define st_lib_hal_uart_transmit(...) HAL_UART_Transmit(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* stm32l1xx_nucleo.h */
|
||||
#include "stm32l1xx_nucleo.h"
|
||||
|
||||
#define st_lib_gpio_typedef GPIO_TypeDef
|
||||
#define st_lib_gpio_port GPIO_PORT
|
||||
#define st_lib_gpio_pin GPIO_PIN
|
||||
|
||||
#define st_lib_bsp_led_init(...) BSP_LED_Init(__VA_ARGS__)
|
||||
#define st_lib_bsp_led_off(...) BSP_LED_Off(__VA_ARGS__)
|
||||
#define st_lib_bsp_led_on(...) BSP_LED_On(__VA_ARGS__)
|
||||
#define st_lib_bsp_pb_init(...) BSP_PB_Init(__VA_ARGS__)
|
||||
#define st_lib_bsp_pb_get_state(...) BSP_PB_GetState(__VA_ARGS__)
|
||||
#define st_lib_hal_gpio_read_pin(...) HAL_GPIO_ReadPin(__VA_ARGS__)
|
||||
#define st_lib_hal_gpio_write_pin(...) HAL_GPIO_WritePin(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef X_NUCLEO_IKS01A1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* x_nucleo_iks01a1.h */
|
||||
#include "x_nucleo_iks01a1.h"
|
||||
|
||||
#define st_lib_axes_raw_typedef AxesRaw_TypeDef
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* x_nucleo_iks01a1_hum_temp.h */
|
||||
#include "x_nucleo_iks01a1_hum_temp.h"
|
||||
|
||||
#define st_lib_bsp_hum_temp_is_initialized(...) BSP_HUM_TEMP_isInitialized(__VA_ARGS__)
|
||||
#define st_lib_bsp_hum_temp_init(...) BSP_HUM_TEMP_Init(__VA_ARGS__)
|
||||
#define st_lib_bsp_hum_temp_get_humidity(...) BSP_HUM_TEMP_GetHumidity(__VA_ARGS__)
|
||||
#define st_lib_bsp_hum_temp_get_temperature(...) BSP_HUM_TEMP_GetTemperature(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* x_nucleo_iks01a1_imu_6axes.h */
|
||||
#include "x_nucleo_iks01a1_imu_6axes.h"
|
||||
|
||||
#define st_lib_bsp_imu_6axes_is_initialized(...) BSP_IMU_6AXES_isInitialized(__VA_ARGS__)
|
||||
#define st_lib_bsp_imu_6axes_init(...) BSP_IMU_6AXES_Init(__VA_ARGS__)
|
||||
#define st_lib_bsp_imu_6axes_g_get_axes_raw(...) BSP_IMU_6AXES_G_GetAxesRaw(__VA_ARGS__)
|
||||
#define st_lib_bsp_imu_6axes_x_get_axes_raw(...) BSP_IMU_6AXES_X_GetAxesRaw(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* x_nucleo_iks01a1_magneto.h */
|
||||
#include "x_nucleo_iks01a1_magneto.h"
|
||||
|
||||
#define st_lib_bsp_magneto_m_get_axes_raw(...) BSP_MAGNETO_M_GetAxesRaw(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* x_nucleo_iks01a1_pressure.h */
|
||||
#include "x_nucleo_iks01a1_pressure.h"
|
||||
|
||||
#define st_lib_bsp_pressure_init(...) BSP_PRESSURE_Init(__VA_ARGS__)
|
||||
#define st_lib_bsp_pressure_get_pressure(...) BSP_PRESSURE_GetPressure(__VA_ARGS__)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*X_NUCLEO_IKS01A1*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /*ST_LIB_H_*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
1
platform/stm32nucleo-spirit1/stm32cube-lib
Submodule
1
platform/stm32nucleo-spirit1/stm32cube-lib
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 34e784ff39a5dc4da288ce696235f41b1db4bf5c
|
102
platform/stm32nucleo-spirit1/stm32l-spirit1-config.h
Normal file
102
platform/stm32nucleo-spirit1/stm32l-spirit1-config.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L_SPIRIT1_CONFIG_H
|
||||
#define __STM32L_SPIRIT1_CONFIG_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Define the STM32F10x hardware depending on the used evaluation board */
|
||||
#ifdef USE_STM3210B_EVAL
|
||||
#define USB_DISCONNECT GPIOD
|
||||
#define USB_DISCONNECT_PIN GPIO_PIN_9
|
||||
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOD
|
||||
#define EVAL_COM1_IRQHandler USART1_IRQHandler
|
||||
|
||||
#elif defined(USE_STM3210E_EVAL)
|
||||
#define USB_DISCONNECT GPIOB
|
||||
#define USB_DISCONNECT_PIN GPIO_PIN_14
|
||||
#define RCC_APB2Periph_GPIO_DISCONNECT RCC_APB2Periph_GPIOB
|
||||
#define EVAL_COM1_IRQHandler USART1_IRQHandler
|
||||
|
||||
#elif defined(USE_STM3210C_EVAL)
|
||||
#define USB_DISCONNECT 0
|
||||
#define USB_DISCONNECT_PIN 0
|
||||
#define RCC_APB2Periph_GPIO_DISCONNECT 0
|
||||
#define EVAL_COM1_IRQHandler USART2_IRQHandler
|
||||
|
||||
#elif defined(USE_STM32L152_EVAL) || defined(USE_STM32L152D_EVAL)
|
||||
/*
|
||||
For STM32L15xx devices it is possible to use the internal USB pullup
|
||||
controlled by register SYSCFG_PMC (refer to RM0038 reference manual for
|
||||
more details).
|
||||
It is also possible to use external pullup (and disable the internal pullup)
|
||||
by setting the define USB_USE_EXTERNAL_PULLUP in file platform_config.h
|
||||
and configuring the right pin to be used for the external pull up configuration.
|
||||
To have more details on how to use an external pull up, please refer to
|
||||
STM3210E-EVAL evaluation board manuals.
|
||||
*/
|
||||
/* Uncomment the following define to use an external pull up instead of the
|
||||
integrated STM32L15xx internal pull up. In this case make sure to set up
|
||||
correctly the external required hardware and the GPIO defines below.*/
|
||||
/* #define USB_USE_EXTERNAL_PULLUP */
|
||||
|
||||
#if !defined(USB_USE_EXTERNAL_PULLUP)
|
||||
#define STM32L15_USB_CONNECT SYSCFG_USBPuCmd(ENABLE)
|
||||
#define STM32L15_USB_DISCONNECT SYSCFG_USBPuCmd(DISABLE)
|
||||
|
||||
#elif defined(USB_USE_EXTERNAL_PULLUP)
|
||||
/* PA0 is chosen just as illustrating example, you should modify the defines
|
||||
below according to your hardware configuration. */
|
||||
#define USB_DISCONNECT GPIOA
|
||||
#define USB_DISCONNECT_PIN GPIO_PIN_0
|
||||
#define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOA
|
||||
#define STM32L15_USB_CONNECT GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
|
||||
#define STM32L15_USB_DISCONNECT GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
|
||||
#endif /* USB_USE_EXTERNAL_PULLUP */
|
||||
|
||||
#ifdef USE_STM32L152_EVAL
|
||||
#define EVAL_COM1_IRQHandler USART2_IRQHandler
|
||||
#elif defined(USE_STM32L152D_EVAL)
|
||||
#define EVAL_COM1_IRQHandler USART1_IRQHandler
|
||||
#endif /*USE_STM32L152_EVAL*/
|
||||
|
||||
#endif /* USE_STM3210B_EVAL */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#endif /* __STM32L_SPIRIT1_CONFIG_H */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
90
platform/stm32nucleo-spirit1/uart-msg.c
Normal file
90
platform/stm32nucleo-spirit1/uart-msg.c
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2012, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/leds.h"
|
||||
#include "stm32l1xx_nucleo.h"
|
||||
#include "platform-conf.h"
|
||||
#include <stdio.h>
|
||||
#include "dev/slip.h"
|
||||
#include "hw-config.h"
|
||||
#include "stm32l1xx_hal.h"
|
||||
#include "st-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void uart_send_msg(char *);
|
||||
extern st_lib_uart_handle_typedef st_lib_uart_handle;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned char databyte[1] = { 0 };
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Rx Transfer completed callbacks.
|
||||
* @param huart: Pointer to a st_lib_uart_handle_typedef structure that contains
|
||||
* the configuration information for the specified UART module.
|
||||
* @retval None
|
||||
*/
|
||||
void
|
||||
st_lib_hal_uart_rx_cplt_callback(st_lib_uart_handle_typedef *huart)
|
||||
{
|
||||
slip_input_byte(databyte[0]);
|
||||
st_lib_hal_uart_receive_it(&st_lib_uart_handle, databyte, 1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uart1_set_input(int (*input)(unsigned char c))
|
||||
{
|
||||
st_lib_hal_uart_receive_it(&st_lib_uart_handle, databyte, 1);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_arch_init(unsigned long ubr)
|
||||
{
|
||||
st_lib_hal_uart_enable_it(&st_lib_uart_handle, UART_IT_RXNE);
|
||||
/* uart1_set_input(slip_input_byte); */
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_arch_writeb(unsigned char c)
|
||||
{
|
||||
uart_send_msg(&c);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Send a message via UART
|
||||
* @param msg the pointer to the message to be sent
|
||||
* @retval None
|
||||
*/
|
||||
void
|
||||
uart_send_msg(char *msg)
|
||||
{
|
||||
st_lib_hal_uart_transmit(&st_lib_uart_handle, (uint8_t *)msg, 1, 5000);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
|
@ -35,6 +35,7 @@ zolertia/z1/z1 \
|
|||
settings-example/avr-raven \
|
||||
ipv6/multicast/sky \
|
||||
|
||||
|
||||
TOOLS=
|
||||
|
||||
include ../Makefile.compile-test
|
||||
|
|
|
@ -23,6 +23,14 @@ zolertia/zoul/cc1200-demo/zoul \
|
|||
er-rest-example/zoul \
|
||||
hello-world/zoul \
|
||||
cc2538dk/mqtt-demo/zoul \
|
||||
er-rest-example/stm32nucleo-spirit1 \
|
||||
ipv6/rpl-border-router/stm32nucleo-spirit1 \
|
||||
ipv6/rpl-udp/stm32nucleo-spirit1 \
|
||||
ipv6/simple-udp-rpl/stm32nucleo-spirit1 \
|
||||
stm32nucleo-spirit1/sensor-demo/stm32nucleo-spirit1 \
|
||||
ipv6/multicast/stm32nucleo-spirit1 \
|
||||
udp-ipv6/stm32nucleo-spirit1 \
|
||||
hello-world/stm32nucleo-spirit1 \
|
||||
|
||||
TOOLS=
|
||||
|
||||
|
|
Loading…
Reference in a new issue