Fixed mbxxx platform
This commit is contained in:
parent
10f64c0ce8
commit
fcb09d5d30
|
@ -68,16 +68,17 @@ STRIP = strip
|
|||
ifndef DEBUG
|
||||
OPTI = -Ohz --no_unroll
|
||||
endif
|
||||
CFLAGSNO = --endian=little --cpu=Cortex-M3 -e --diag_suppress Pa050 -D BOARD_HEADER=\"board.h\" \
|
||||
CFLAGSNO = --debug --endian=little --cpu=Cortex-M3 -e --diag_suppress Pa050 -D BOARD_HEADER=\"board.h\" \
|
||||
-D BOARD_MB851 -D "PLATFORM_HEADER=\"hal/micro/cortexm3/compiler/iar.h\"" -D CORTEXM3 \
|
||||
-D CORTEXM3_STM32W108 -D PHY_STM32W108XX -D DISABLE_WATCHDOG -D ENABLE_ADC_EXTENDED_RANGE_BROKEN \
|
||||
-D __SOURCEFILE__=\"$*.c\" -lC $(OBJECTDIR) \
|
||||
-I $(CONTIKI)/../iar-files \
|
||||
-I $(IAR_PATH)/arm/inc --dlib_config=DLib_Config_Normal.h
|
||||
|
||||
CFLAGS += $(CFLAGSNO) $(OPTI)
|
||||
CFLAGS += $(CFLAGSNO) $(OPTI) -D__ICCARM__
|
||||
AROPTS = --create
|
||||
ASFLAGS = -s+ -w+ --cpu Cortex-M3 -L$(OBJECTDIR)
|
||||
LDFLAGS += --redirect _Printf=_PrintfSmall --redirect _Scanf=_ScanfSmall --map=contiki-$(TARGET).map
|
||||
LDFLAGS += --semihosting --redirect _Printf=_PrintfSmall --redirect _Scanf=_ScanfSmall --map=contiki-$(TARGET).map
|
||||
ifndef COFFEE
|
||||
LDFLAGS+= --config $(CONTIKI_CPU)/iar-cfg.icf
|
||||
endif
|
||||
|
@ -97,19 +98,30 @@ ifndef DEBUG
|
|||
OPTI = -Os -ffunction-sections
|
||||
endif
|
||||
|
||||
ifeq ($(CPUREV), CC)
|
||||
LD-EXT=-stm32w108CC
|
||||
${warning "using stm32w108CC specific ld file"}
|
||||
else ifeq ($(CPUREV), xB)
|
||||
LD-EXT=-stm32w108xB
|
||||
${warning "using stm32w108xB specific ld file"}
|
||||
else
|
||||
${error "No CPUREV specified. Cpu revision should be specified. Please read cpu/stm32w108/README.txt for more details."}
|
||||
endif
|
||||
|
||||
CFLAGSNO = -mthumb -mcpu=cortex-m3 -D "PLATFORM_HEADER=\"hal/micro/cortexm3/compiler/gnu.h\"" \
|
||||
-D BOARD_HEADER=\"board.h\" -g -Wall -Wno-strict-aliasing -mlittle-endian \
|
||||
-D BOARD_MB851 -D CORTEXM3 -D CORTEXM3_STM32W108 -D PHY_STM32W108XX -D DISABLE_WATCHDOG -D ENABLE_ADC_EXTENDED_RANGE_BROKEN \
|
||||
-D CORTEXM3 -D CORTEXM3_STM32W108 -D PHY_STM32W108XX -D DISABLE_WATCHDOG -D ENABLE_ADC_EXTENDED_RANGE_BROKEN \
|
||||
-D __SOURCEFILE__=\"$*.c\"
|
||||
CFLAGS += $(CFLAGSNO) $(OPTI)
|
||||
ASFLAGS = -mthumb -mcpu=cortex-m3 -c -g -Wall -Os -ffunction-sections \
|
||||
-mlittle-endian -fshort-enums -x assembler-with-cpp -Wa,-EL
|
||||
|
||||
ifndef CPU_LD_CONFIG
|
||||
CPU_LD_CONFIG=$(CONTIKI_CPU)/gnu.ld
|
||||
CPU_LD_CONFIG=$(CONTIKI_CPU)/gnu$(LD-EXT).ld
|
||||
endif # CPU_LD_CONFIG
|
||||
|
||||
LDFLAGS += -mcpu=cortex-m3 \
|
||||
LDFLAGS += -L$(CONTIKI_CPU)\
|
||||
-mcpu=cortex-m3 \
|
||||
-mthumb \
|
||||
-Wl,-T -Xlinker $(CPU_LD_CONFIG) \
|
||||
-Wl,-static \
|
||||
|
@ -302,8 +314,8 @@ endif
|
|||
|
||||
# a target that gives a user-friendly memory profile, taking into account the RAM
|
||||
# that is statically occupied by the stack as defined in cpu/stm32w108/gnu.ld
|
||||
RAM_SIZE = 8192
|
||||
FLASH_SIZE = 128*1024
|
||||
RAM_SIZE = 2*8192
|
||||
FLASH_SIZE = 2*128*1024
|
||||
STACK_SIZE = 1280
|
||||
%.size: %.$(TARGET)
|
||||
@size -A $< | egrep "data|bss" | awk '{s+=$$2} END {s=s+$(STACK_SIZE); f=$(RAM_SIZE)-s; printf "[RAM] used %6d, free %6d\n",s,f;}'
|
||||
|
|
22
cpu/stm32w108/README.txt
Normal file
22
cpu/stm32w108/README.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
Building instructions.
|
||||
|
||||
In order to build your applications you need to find out the right cpu revision for the board you are using.
|
||||
|
||||
Valid CPUREV values are CC or xB
|
||||
|
||||
Examples:
|
||||
|
||||
The MB851RevD board has a cpu with code
|
||||
stm32w 108CCU7
|
||||
so CC is your CPUREV value and the command is
|
||||
make TARGET=mbxxx CPUREV=CC ...
|
||||
|
||||
or
|
||||
|
||||
The MB851RevC board has a cpu with code
|
||||
stm32w 108CBU6
|
||||
so xB is your CPUREV value.
|
||||
make TARGET=mbxxx CPUREV=xB ...
|
||||
|
||||
|
||||
NOTE: if the last word is B you need to use x as wildcard.
|
177
cpu/stm32w108/gnu-stm32w108.ld
Normal file
177
cpu/stm32w108/gnu-stm32w108.ld
Normal file
|
@ -0,0 +1,177 @@
|
|||
/* default stack sizes.
|
||||
|
||||
These are used by the startup in order to allocate stacks for the different modes.
|
||||
*/
|
||||
|
||||
__Stack_Size = 0x500 ;
|
||||
|
||||
PROVIDE ( _Stack_Size = __Stack_Size ) ;
|
||||
|
||||
__Stack_Init = 0x20000000;
|
||||
|
||||
_estack = __Stack_Init + __Stack_Size;
|
||||
|
||||
/*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/
|
||||
PROVIDE ( _Stack_Init = __Stack_Init ) ;
|
||||
|
||||
|
||||
/* Sections management for FLASH mode */
|
||||
|
||||
/* Sections Definitions */
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
/* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH */
|
||||
|
||||
.isr_vector (DEFINED(ST_BTL) ? (0x08000000 + _BOOTLOADER_SIZE) : 0x08000000) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__ApplicationFlashStart = . ;
|
||||
/* . = . + _ROM_base ;*/
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >ROM_region
|
||||
|
||||
/* for some STRx devices, the beginning of the startup code is stored in the .flashtext section, which goes to FLASH */
|
||||
.flashtext :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.flashtext) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >ROM_region
|
||||
|
||||
/* the program code is stored in the .text section, which goes to Flash */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
|
||||
*(.text) /* remaining code */
|
||||
*(.text.*) /* remaining code */
|
||||
*(.rodata) /* read-only data (constants) */
|
||||
*(.rodata*)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
/* This is used by the startup in order to initialize the .data section */
|
||||
_sidata = _etext;
|
||||
} >ROM_region
|
||||
/*
|
||||
NVM (NOLOAD):
|
||||
{
|
||||
. = ALIGN(1024);
|
||||
*(NVM)
|
||||
. = ALIGN(4);
|
||||
} > NVM_region
|
||||
*/
|
||||
/* This is to emulate place at end of IAR linker */
|
||||
NVM (ORIGIN(ROM_region) + LENGTH(ROM_region) - _NVM_size) (NOLOAD):
|
||||
{
|
||||
*(NVM)
|
||||
} > ROM_region
|
||||
FAT (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(FAT))
|
||||
. = ALIGN(4);
|
||||
} > FIB_region
|
||||
|
||||
/*
|
||||
.FAT (NOLOAD):
|
||||
{
|
||||
KEEP(*(.FAT))
|
||||
} > FIB_region
|
||||
*/
|
||||
/* after that it's only debugging information. */
|
||||
|
||||
|
||||
/* This is the initialized data section
|
||||
The program executes knowing that the data is in the RAM
|
||||
but the loader puts the initial values in the FLASH (inidata).
|
||||
It is one task of the startup to copy the initial values from FLASH to RAM. */
|
||||
.data _estack : AT ( _sidata )
|
||||
{
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .data section */
|
||||
_sdata = . ;
|
||||
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .data section */
|
||||
_edata = . ;
|
||||
} >RAM_region
|
||||
|
||||
|
||||
/* This is the uninitialized data section */
|
||||
.bss :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss section */
|
||||
_sbss = .;
|
||||
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
/* This is used by the startup in order to initialize the .bss section */
|
||||
_ebss = . ;
|
||||
} >RAM_region
|
||||
|
||||
PROVIDE ( end = _ebss );
|
||||
PROVIDE ( _end = _ebss );
|
||||
|
||||
__exidx_start = .;
|
||||
__exidx_end = .;
|
||||
|
||||
/* remove the debugging information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.comment 0 : { *(.comment) }
|
||||
/* DWARF debug sections.
|
||||
Symbols in the DWARF debugging sections are relative to the beginning
|
||||
of the section so we begin them at 0. */
|
||||
/* DWARF 1 */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
/* GNU DWARF 1 extensions */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
/* DWARF 1.1 and DWARF 2 */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
/* DWARF 2 */
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
/* SGI/MIPS DWARF 2 extensions */
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
}
|
||||
|
||||
__ApplicationFlashEnd = _sidata + (_edata - _sdata);
|
||||
__RAMStart = __Stack_Init;
|
||||
__RAMEnd = _ebss;
|
||||
|
16
cpu/stm32w108/gnu-stm32w108CC.ld
Normal file
16
cpu/stm32w108/gnu-stm32w108CC.ld
Normal file
|
@ -0,0 +1,16 @@
|
|||
/******************************************************************************/
|
||||
/* Peripheral memory map */
|
||||
/******************************************************************************/
|
||||
_BOOTLOADER_SIZE = 0 ;
|
||||
/* This value needs to be fine tuned if the NVM section grows */
|
||||
_NVM_size = 0x1000;
|
||||
|
||||
/* include the memory spaces definitions sub-script */
|
||||
MEMORY
|
||||
{
|
||||
RAM_region (xrw) : ORIGIN = 0x20000000, LENGTH = 16K
|
||||
ROM_region (rx) : ORIGIN = 0x08000000, LENGTH = 256K
|
||||
FIB_region (ra) : ORIGIN = 0x08040000, LENGTH = 2K
|
||||
}
|
||||
|
||||
INCLUDE "gnu-stm32w108.ld"
|
17
cpu/stm32w108/gnu-stm32w108xB.ld
Normal file
17
cpu/stm32w108/gnu-stm32w108xB.ld
Normal file
|
@ -0,0 +1,17 @@
|
|||
/******************************************************************************/
|
||||
/* Peripheral memory map */
|
||||
/******************************************************************************/
|
||||
/* Size of IAP bootloader */
|
||||
_BOOTLOADER_SIZE = 0x3000 ;
|
||||
/* This value needs to be fine tuned if the NVM section grows */
|
||||
_NVM_size = 0x800;
|
||||
/* include the memory spaces definitions sub-script */
|
||||
MEMORY
|
||||
{
|
||||
RAM_region (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
ROM_region (rx) : ORIGIN = 0x08000000, LENGTH = 128K
|
||||
FIB_region (ra) : ORIGIN = 0x08040000, LENGTH = 2K
|
||||
}
|
||||
|
||||
INCLUDE "gnu-stm32w108.ld"
|
||||
|
|
@ -21,7 +21,6 @@ __Stack_Init = 0x20000000;
|
|||
|
||||
_estack = __Stack_Init + __Stack_Size;
|
||||
|
||||
|
||||
/*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/
|
||||
PROVIDE ( _Stack_Init = __Stack_Init ) ;
|
||||
|
||||
|
|
149
cpu/stm32w108/hal/micro/cortexm3/cstartup-m.s
Normal file
149
cpu/stm32w108/hal/micro/cortexm3/cstartup-m.s
Normal file
|
@ -0,0 +1,149 @@
|
|||
/**************************************************
|
||||
*
|
||||
* Part one of the system initialization code, contains low-level
|
||||
* initialization, plain thumb variant.
|
||||
*
|
||||
|
||||
* Customized by St Corporation for STM32W
|
||||
*<!--(C) COPYRIGHT 2010 STMicroelectronics. All rights reserved. -->
|
||||
*
|
||||
**************************************************/
|
||||
|
||||
;
|
||||
; The modules in this file are included in the libraries, and may be replaced
|
||||
; by any user-defined modules that define the PUBLIC symbol _program_start or
|
||||
; a user defined start symbol.
|
||||
; To override the cstartup defined in the library, simply add your modified
|
||||
; version to the workbench project.
|
||||
;
|
||||
; The vector table is normally located at address 0.
|
||||
; When debugging in RAM, it can be located in RAM, aligned to at least 2^6.
|
||||
; The name "__vector_table" has special meaning for C-SPY:
|
||||
; it is where the SP start value is found, and the NVIC vector
|
||||
; table register (VTOR) is initialized to this address if != 0.
|
||||
;
|
||||
; Cortex-M version
|
||||
;
|
||||
|
||||
MODULE ?cstartup
|
||||
|
||||
;; Forward declaration of sections.
|
||||
SECTION CSTACK:DATA:NOROOT(3)
|
||||
|
||||
SECTION .intvec:CODE:NOROOT(2)
|
||||
|
||||
EXTERN __iar_program_start
|
||||
PUBLIC __vector_table
|
||||
|
||||
DATA
|
||||
__vector_table
|
||||
DCD sfe(CSTACK)
|
||||
DCD __iar_program_start
|
||||
|
||||
;; Standard Cortex-M3 Vectors
|
||||
DCD NMI_Handler ;;NMI Handler
|
||||
DCD HardFault_Handler ;;Hard Fault Handler
|
||||
DCD MemManage_Handler ;;Memory Fault Handler
|
||||
DCD BusFault_Handler ;;Bus Fault Handler
|
||||
DCD UsageFault_Handler ;;Usage Fault Handler
|
||||
DCD 0 ;;Reserved
|
||||
DCD 0 ;;Reserved
|
||||
DCD 0 ;;Reserved
|
||||
DCD 0 ;;Reserved
|
||||
DCD SVC_Handler ;;SVCall Handler
|
||||
DCD DebugMon_Handler ;;Debug Monitor Handler
|
||||
DCD 0 ;;Reserved
|
||||
DCD PendSV_Handler ;;PendSV Handler
|
||||
DCD SysTick_Handler ;;SysTick Handler
|
||||
|
||||
;; STM32W Vectors
|
||||
DCD halTimer1Isr ;;Timer 1 Handler
|
||||
DCD halTimer2Isr ;;Timer 2 Handler
|
||||
DCD halManagementIsr ;;Management Handler
|
||||
DCD halBaseBandIsr ;;BaseBand Handler
|
||||
DCD halSleepTimerIsr ;;Sleep Timer Handler
|
||||
DCD halSc1Isr ;;SC1 Handler
|
||||
DCD halSc2Isr ;;SC2 Handler
|
||||
DCD halSecurityIsr ;;Security Handler
|
||||
DCD halStackMacTimerIsr ;;MAC Timer Handler
|
||||
DCD stmRadioTransmitIsr ;;MAC TX Handler
|
||||
DCD stmRadioReceiveIsr ;;MAC RX Handler
|
||||
DCD halAdcIsr ;;ADC Handler
|
||||
DCD halIrqAIsr ;;GPIO IRQA Handler
|
||||
DCD halIrqBIsr ;;GPIO IRQB Handler
|
||||
DCD halIrqCIsr ;;GPIO IRQC Handler
|
||||
DCD halIrqDIsr ;;GPIO IRQD Handler
|
||||
DCD halDebugIsr ;;Debug Handler
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;
|
||||
;; Default interrupt handlers.
|
||||
;;
|
||||
|
||||
PUBWEAK NMI_Handler
|
||||
PUBWEAK HardFault_Handler
|
||||
PUBWEAK MemManage_Handler
|
||||
PUBWEAK BusFault_Handler
|
||||
PUBWEAK UsageFault_Handler
|
||||
PUBWEAK SVC_Handler
|
||||
PUBWEAK DebugMon_Handler
|
||||
PUBWEAK PendSV_Handler
|
||||
PUBWEAK SysTick_Handler
|
||||
|
||||
PUBWEAK halTimer1Isr
|
||||
PUBWEAK halTimer2Isr
|
||||
PUBWEAK halManagementIsr
|
||||
PUBWEAK halBaseBandIsr
|
||||
PUBWEAK halSleepTimerIsr
|
||||
PUBWEAK halSc1Isr
|
||||
PUBWEAK halSc2Isr
|
||||
PUBWEAK halSecurityIsr
|
||||
PUBWEAK halStackMacTimerIsr
|
||||
PUBWEAK stmRadioTransmitIsr
|
||||
PUBWEAK stmRadioReceiveIsr
|
||||
PUBWEAK halAdcIsr
|
||||
PUBWEAK halIrqAIsr
|
||||
PUBWEAK halIrqBIsr
|
||||
PUBWEAK halIrqCIsr
|
||||
PUBWEAK halIrqDIsr
|
||||
PUBWEAK halDebugIsr
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SECTION .text:CODE:REORDER(1)
|
||||
THUMB
|
||||
|
||||
NMI_Handler
|
||||
HardFault_Handler
|
||||
MemManage_Handler
|
||||
BusFault_Handler
|
||||
UsageFault_Handler
|
||||
SVC_Handler
|
||||
DebugMon_Handler
|
||||
PendSV_Handler
|
||||
SysTick_Handler
|
||||
halTimer1Isr
|
||||
halTimer2Isr
|
||||
halManagementIsr
|
||||
halBaseBandIsr
|
||||
halSleepTimerIsr
|
||||
halSc1Isr
|
||||
halSc2Isr
|
||||
halSecurityIsr
|
||||
halStackMacTimerIsr
|
||||
stmRadioTransmitIsr
|
||||
stmRadioReceiveIsr
|
||||
halAdcIsr
|
||||
halIrqAIsr
|
||||
halIrqBIsr
|
||||
halIrqCIsr
|
||||
halIrqDIsr
|
||||
halDebugIsr
|
||||
Default_Handler
|
||||
B Default_Handler
|
||||
|
||||
END
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1,49 +0,0 @@
|
|||
ELFloader and shell command 'exec' example for MB851 (STM32W) platform
|
||||
-----------------------------------------------------------
|
||||
|
||||
Compiles the Contiki hello-world application as a Contiki executable (.ce).
|
||||
The Contiki executable is then uploaded to the MB851 platform via serial, and
|
||||
is stored in the filesystem. Finally, the executable is loaded via the shell
|
||||
command 'exec'.
|
||||
|
||||
NOTE:
|
||||
You may have to reduce the ELF loader memory usage (/platform/sky/contiki-conf.h).
|
||||
Since hello-world uses very little memory:
|
||||
#define ELFLOADER_CONF_DATAMEMORY_SIZE 0x100
|
||||
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x100
|
||||
|
||||
1. Upload Sky shell with 'exec' command and symbols (requires several
|
||||
recompilations to generate correct symbols):
|
||||
|
||||
make
|
||||
make CORE=shell-exec-test.mb851
|
||||
make shell-exec-test.flash CORE=shell-exec-test.mb851 PORT=AUTO
|
||||
|
||||
2. Verify access to the shell and the filesystem:
|
||||
|
||||
> make login DEV=/dev/comX
|
||||
SHELL> echo hello shell
|
||||
SHELL> echo test | write mytest.txt
|
||||
SHELL> ls
|
||||
SHELL> read mytest.txt
|
||||
[CTRL-C] to exit the shell
|
||||
|
||||
3. Upload Contiki executable hello-world.ce:
|
||||
|
||||
> make upload-executable DEV=/dev/comX
|
||||
[CTRL-C] to exit the shell when the entire file has been uploaded (after ~30 sec)
|
||||
|
||||
4. Verify that hello-world.ce exists in CFS:
|
||||
|
||||
> make login DEV=/dev/comX
|
||||
SHELL> ls
|
||||
SHELL> read hello-world.ce | size
|
||||
|
||||
The last command output should equal the size of hello-world.ce in this
|
||||
directory!
|
||||
|
||||
5. Load and start hello world:
|
||||
|
||||
SHELL> exec hello-world.ce
|
||||
|
||||
The program should now start: the output 'Hello, World' appears.
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1,10 +0,0 @@
|
|||
UDP IPV6 sleep
|
||||
==============
|
||||
|
||||
Thi is an example based on the UDP-IPv6 example. A client periodically sends
|
||||
UDP packets to a fixed server. The client will also go in a deep sleep state
|
||||
during which all system peripherals are turned off to save as more energy as
|
||||
possible.
|
||||
|
||||
To avoid blocking the entire OS for too long time, the system periodically
|
||||
wakes up to let the OS poll processes and dispatch events.
|
|
@ -1 +0,0 @@
|
|||
TARGET = mb851
|
|
@ -1,37 +0,0 @@
|
|||
Compile with WITH_RIME 1 for neighbor discovery and with ENERGEST_CONF_ON for
|
||||
energy estimation.
|
||||
|
||||
Estimated consumption with batteries (2.4 V):
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>Curr</td>
|
||||
<td>Power</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>ENERGEST_TYPE_CPU</td>
|
||||
<td>7.5 mA</td>
|
||||
<td>18 mW</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>ENERGEST_TYPE_LPM</td>
|
||||
<td>3 mA</td>
|
||||
<td>7.2 mW</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>ENERGEST_TYPE_TRANSMIT</td>
|
||||
<td>21 mA</td>
|
||||
<td>50.4 mW</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>ENERGEST_TYPE_LISTEN</td>
|
||||
<td>19 mA</td>
|
||||
<td>45.6 mW</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
1
examples/mbxxx/acc-sensor/Makefile.target
Normal file
1
examples/mbxxx/acc-sensor/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
|
@ -41,6 +41,7 @@
|
|||
#include "contiki.h"
|
||||
|
||||
#include "dev/acc-sensor.h"
|
||||
#include "board.h"
|
||||
|
||||
#include <stdio.h> /* For printf() */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -54,7 +55,7 @@ PROCESS_THREAD(acc_process, ev, data)
|
|||
PROCESS_BEGIN();
|
||||
|
||||
printf("Starting measuring acceleration\r\n");
|
||||
|
||||
boardPrintStringDescription();
|
||||
SENSORS_ACTIVATE(acc_sensor);
|
||||
|
||||
// Enable High Range.
|
1
examples/mbxxx/button/Makefile.target
Normal file
1
examples/mbxxx/button/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
|
@ -42,6 +42,8 @@
|
|||
#include "dev/button-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
#include <stdio.h>
|
||||
#include "board.h"
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_button_process, "Test button");
|
||||
|
@ -52,7 +54,7 @@ PROCESS_THREAD(test_button_process, ev, data)
|
|||
PROCESS_BEGIN();
|
||||
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
boardPrintStringDescription();
|
||||
printf("Press the button to toggle the leds.");
|
||||
|
||||
while(1) {
|
1
examples/mbxxx/coffee-test/Makefile.target
Normal file
1
examples/mbxxx/coffee-test/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
|
@ -40,6 +40,7 @@
|
|||
#include "contiki.h"
|
||||
#include "cfs-coffee-arch.h"
|
||||
#include "cfs-coffee.h"
|
||||
#include "board.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -51,6 +52,7 @@ PROCESS_THREAD(coffee_test_process, ev, data)
|
|||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
boardPrintStringDescription();
|
||||
printf("Testing coffee...\n");
|
||||
|
||||
cfs_coffee_format();
|
|
@ -1,6 +1,6 @@
|
|||
CONTIKI_PROJECT = mb851-shell
|
||||
CONTIKI_PROJECT = mbxxx-shell
|
||||
|
||||
PROJECTDIRS = $(CONTIKI)/platform/mb851/apps
|
||||
PROJECTDIRS = $(CONTIKI)/platform/mbxxx/apps
|
||||
|
||||
APPS = serial-shell
|
||||
|
1
examples/mbxxx/mbxxx-shell/Makefile.target
Normal file
1
examples/mbxxx/mbxxx-shell/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
/**
|
||||
* \file
|
||||
* MB851-specific Contiki shell
|
||||
* mbxxx-specific Contiki shell
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*
|
||||
|
@ -44,10 +44,10 @@
|
|||
#include "shell-sensors.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(mb851_shell_process, "MB851 Contiki shell");
|
||||
AUTOSTART_PROCESSES(&mb851_shell_process);
|
||||
PROCESS(mbxxx_shell_process, "MBXXX Contiki shell");
|
||||
AUTOSTART_PROCESSES(&mbxxx_shell_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(mb851_shell_process, ev, data)
|
||||
PROCESS_THREAD(mbxxx_shell_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
all: mb851-websense
|
||||
all: mbxxx-websense
|
||||
|
||||
CONTIKI=../../..
|
||||
|
1
examples/mbxxx/mbxxx-websense/Makefile.target
Normal file
1
examples/mbxxx/mbxxx-websense/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
|
@ -1 +1,4 @@
|
|||
webserver IPv6
|
||||
==============
|
||||
|
||||
See sky-websense example for more info.
|
|
@ -1,7 +1,7 @@
|
|||
CONTIKI_PROJECT = shell-exec-test
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
TARGET=mb851
|
||||
TARGET=mbxxx
|
||||
COFFEE=1
|
||||
ELF_LOADER=1
|
||||
|
47
examples/mbxxx/shell-exec/README.md
Normal file
47
examples/mbxxx/shell-exec/README.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
ELFloader and shell command 'exec' example for mbxxx (STM32W) platform
|
||||
======================================================================
|
||||
|
||||
|
||||
Compiles the Contiki hello-world application as a Contiki executable (.ce).
|
||||
The Contiki executable is then uploaded to the mbxxx platform via serial, and
|
||||
is stored in the filesystem.
|
||||
Finally, the executable is loaded via the shell command 'exec'.
|
||||
|
||||
NOTE:
|
||||
You may have to reduce the ELF loader memory usage (/platform/sky/contiki-conf.h).
|
||||
Since hello-world uses very little memory:
|
||||
#define ELFLOADER_CONF_DATAMEMORY_SIZE 0x100
|
||||
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x100
|
||||
|
||||
|
||||
1. Upload Sky shell with 'exec' command and symbols (requires several recompilations to generate correct symbols):
|
||||
> make
|
||||
> make CORE=shell-exec-test.mbxxx
|
||||
> make shell-exec-test.flash CORE=shell-exec-test.mbxxx PORT=AUTO
|
||||
|
||||
|
||||
2. Verify access to the shell and the filesystem:
|
||||
> make login DEV=/dev/comX
|
||||
SHELL> echo hello shell
|
||||
SHELL> echo test | write mytest.txt
|
||||
SHELL> ls
|
||||
SHELL> read mytest.txt
|
||||
[CTRL-C] to exit the shell
|
||||
|
||||
|
||||
3. Upload Contiki executable hello-world.ce:
|
||||
> make upload-executable DEV=/dev/comX
|
||||
[CTRL-C] to exit the shell when the entire file has been uploaded (after ~30 sec)
|
||||
|
||||
|
||||
4. Verify that hello-world.ce exists in CFS:
|
||||
> make login DEV=/dev/comX
|
||||
SHELL> ls
|
||||
SHELL> read hello-world.ce | size
|
||||
The last command output should equal the size of hello-world.ce in this directory!
|
||||
|
||||
|
||||
5. Load and start hello world:
|
||||
SHELL> exec hello-world.ce
|
||||
The program should now start: the output 'Hello, World' appears.
|
||||
|
|
@ -4,7 +4,7 @@ UIP_CONF_IPV6=1
|
|||
|
||||
APPS = telnetd
|
||||
|
||||
PROJECTDIRS = $(CONTIKI)/platform/mb851/apps
|
||||
PROJECTDIRS = $(CONTIKI)/platform/mbxxx/apps
|
||||
PROJECT_SOURCEFILES = shell-sensors.c
|
||||
|
||||
|
1
examples/mbxxx/telnet-server/Makefile.target
Normal file
1
examples/mbxxx/telnet-server/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
1
examples/mbxxx/temperature/Makefile.target
Normal file
1
examples/mbxxx/temperature/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
|
@ -42,6 +42,7 @@
|
|||
#include "contiki.h"
|
||||
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "board.h"
|
||||
|
||||
#include <stdio.h> /* For printf() */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -54,6 +55,7 @@ PROCESS_THREAD(temp_process, ev, data)
|
|||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
boardPrintStringDescription();
|
||||
printf("Starting measuring temperature\r\n");
|
||||
|
||||
while(1) {
|
||||
|
@ -63,7 +65,6 @@ PROCESS_THREAD(temp_process, ev, data)
|
|||
|
||||
unsigned int temp = temperature_sensor.value(0);
|
||||
printf("Temp: %d.%d °C \r",temp/10,temp-(temp/10)*10);
|
||||
|
||||
}
|
||||
|
||||
|
1
examples/mbxxx/udp-ipv6-sleep/Makefile.target
Normal file
1
examples/mbxxx/udp-ipv6-sleep/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
10
examples/mbxxx/udp-ipv6-sleep/README.md
Normal file
10
examples/mbxxx/udp-ipv6-sleep/README.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
UDP-IPv6 Client and Server
|
||||
=========================
|
||||
|
||||
This is an example based on the udp-ipv6 example. A client periodically sends
|
||||
UDP packets to a fixed server. The client will also go in a deep sleep state
|
||||
during wich all system peripherals are turned off to save as more energy as
|
||||
possible.
|
||||
|
||||
To avoid blocking the entire OS for too long time, the system periocally
|
||||
wakes up to let the OS poll processes and dispatch events.
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "sleep.h"
|
||||
#include "board-sensors.h"
|
||||
#include "board.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -165,9 +166,9 @@ PROCESS_THREAD(udp_client_process, ev, data)
|
|||
PROCESS_YIELD();
|
||||
if(etimer_expired(&wake_timer)){ // if timer hasn't expired do not go in deep sleep, in order to receive a response.
|
||||
printf("Sleeping...\r\n");
|
||||
sensorsPowerDown();
|
||||
halBoardPowerDown();//sensorsPowerDown();
|
||||
sleep_seconds(SLEEP_INTERVAL_SECONDS); // Put system in deep sleep mode for a while.
|
||||
sensorsPowerUp();
|
||||
halBoardPowerUp();//sensorsPowerUp();
|
||||
printf("Awake\r\n");
|
||||
}
|
||||
if(etimer_expired(&et)) {
|
|
@ -1,4 +1,4 @@
|
|||
CONTIKI_PROJECT = mb851-webserver
|
||||
CONTIKI_PROJECT = mbxxx-webserver
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
DEFINES=PROJECT_CONF_H=\"webserver-ajax-conf.h\"
|
1
examples/mbxxx/webserver-ajax/Makefile.target
Normal file
1
examples/mbxxx/webserver-ajax/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = mbxxx
|
12
examples/mbxxx/webserver-ajax/README.md
Normal file
12
examples/mbxxx/webserver-ajax/README.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
webserver ajax
|
||||
==============
|
||||
|
||||
Compile with WITH_RIME 1 for neighbor discovery and with ENERGEST_CONF_ON
|
||||
for energy estimation.
|
||||
|
||||
Estimated consumption with batteries (2.4 V):
|
||||
Curr Power
|
||||
ENERGEST_TYPE_CPU: 7.5 mA 18 mW
|
||||
ENERGEST_TYPE_LPM: 3 mA 7.2 mW
|
||||
ENERGEST_TYPE_TRANSMIT: 21 mA 50.4 mW
|
||||
ENERGEST_TYPE_LISTEN: 19 mA 45.6 mW
|
Before Width: | Height: | Size: 496 B After Width: | Height: | Size: 496 B |
|
@ -37,7 +37,7 @@
|
|||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
/*
|
||||
* salvopitru: example adapted to MB851.
|
||||
* salvopitru: example adapted to mbxxx.
|
||||
*/
|
||||
|
||||
|
4
examples/mbxxx/webserver-ajax/symbols.c
Normal file
4
examples/mbxxx/webserver-ajax/symbols.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include "symbols.h"
|
||||
|
||||
const int symbols_nelts = 0;
|
||||
const struct symbols symbols[] = {{0,0}};
|
3
examples/mbxxx/webserver-ajax/symbols.h
Normal file
3
examples/mbxxx/webserver-ajax/symbols.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#include "loader/symbols.h"
|
||||
|
||||
extern const struct symbols symbols[1];
|
|
@ -1,21 +0,0 @@
|
|||
ARCH= irq.c sensors.c acc-sensor.c button-sensor.c temperature-sensor.c mems.c
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev
|
||||
ifndef CONTIKI_TARGET_MAIN
|
||||
CONTIKI_TARGET_MAIN = contiki-main.c board-mb851.c
|
||||
endif
|
||||
|
||||
ifeq ($(UIP_CONF_IPV6),1)
|
||||
CFLAGS += -DWITH_UIP6=1
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(CONTIKI_TARGET_MAIN)
|
||||
|
||||
MCU=STM32W108
|
||||
include $(CONTIKI)/cpu/stm32w108/Makefile.stm32w108
|
||||
|
||||
SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-linux
|
||||
|
||||
ifeq ($(HOST_OS),Windows)
|
||||
SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-windows
|
||||
endif
|
|
@ -1,93 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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. 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Shell function for temp and acc sensors.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "shell.h"
|
||||
#include "contiki-net.h"
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/acc-sensor.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(shell_sensors_process, "sensors");
|
||||
SHELL_COMMAND(sensors_command,
|
||||
"sensors",
|
||||
"sensors {temp|acc}: get sensor value", &shell_sensors_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(shell_sensors_process, ev, data)
|
||||
{
|
||||
char str_buf[22];
|
||||
|
||||
PROCESS_BEGIN();
|
||||
if(data == NULL) {
|
||||
shell_output_str(&sensors_command,
|
||||
"sensors {temp|acc}: a sensor must be specified", "");
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
if(strcmp(data, "temp") == 0) {
|
||||
unsigned int temp = temperature_sensor.value(0);
|
||||
snprintf(str_buf, sizeof(str_buf), "%d.%d degC", temp / 10,
|
||||
temp - (temp / 10) * 10);
|
||||
shell_output_str(&sensors_command, "Temp: ", str_buf);
|
||||
} else {
|
||||
if(strcmp(data, "acc") == 0) {
|
||||
snprintf(str_buf, sizeof(str_buf), "%d,%d,%d) mg",
|
||||
acc_sensor.value(ACC_X_AXIS), acc_sensor.value(ACC_Y_AXIS),
|
||||
acc_sensor.value(ACC_Z_AXIS));
|
||||
shell_output_str(&sensors_command, "(X,Y,Z): (", str_buf);
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
shell_sensors_init(void)
|
||||
{
|
||||
SENSORS_ACTIVATE(acc_sensor);
|
||||
shell_register_command(&sensors_command);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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. 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Header file for Contik shell sensors command.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef __SHELL_SENSORS_H__
|
||||
#define __SHELL_SENSORS_H__
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
void shell_sensors_init(void);
|
||||
|
||||
#endif /* __SHELL_SENSORS_H__ */
|
||||
/** @} */
|
|
@ -1,174 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/acc-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t sensors_status;
|
||||
|
||||
#define BUTTON_STATUS_ACTIVE (1 << 0)
|
||||
#define TEMP_STATUS_ACTIVE (1 << 1)
|
||||
#define ACC_STATUS_ACTIVE (1 << 2)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init board (currently does nothing)
|
||||
*/
|
||||
void
|
||||
board_init(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Power down board
|
||||
*/
|
||||
void
|
||||
board_power_down(void)
|
||||
{
|
||||
/* Set everything except LEDs to input */
|
||||
GPIO_PACFGL = (GPIOCFG_IN << PA0_CFG_BIT) |
|
||||
(GPIOCFG_IN << PA1_CFG_BIT) |
|
||||
(GPIOCFG_IN << PA2_CFG_BIT) | (GPIOCFG_IN << PA3_CFG_BIT);
|
||||
GPIO_PACFGH = (GPIOCFG_IN << PA4_CFG_BIT) | /* PTI EN */
|
||||
(GPIOCFG_IN << PA5_CFG_BIT) | /* PTI_DATA */
|
||||
(GPIOCFG_IN << PA6_CFG_BIT) | (GPIOCFG_IN << PA7_CFG_BIT);
|
||||
GPIO_PBCFGL = (GPIOCFG_IN << PB0_CFG_BIT) | (GPIOCFG_IN << PB1_CFG_BIT) |
|
||||
(GPIOCFG_IN << PB2_CFG_BIT) | /* Uart Tx, RX */
|
||||
(GPIOCFG_IN << PB3_CFG_BIT);
|
||||
GPIO_PBCFGH = (GPIOCFG_IN << PB4_CFG_BIT) |
|
||||
(GPIOCFG_IN << PB5_CFG_BIT) |
|
||||
(GPIOCFG_IN << PB6_CFG_BIT) | (GPIOCFG_IN << PB7_CFG_BIT);
|
||||
GPIO_PCCFGL = (GPIOCFG_IN << PC0_CFG_BIT) |
|
||||
(GPIOCFG_IN << PC1_CFG_BIT) |
|
||||
(GPIOCFG_IN << PC2_CFG_BIT) | (GPIOCFG_IN << PC3_CFG_BIT);
|
||||
GPIO_PCCFGH = (GPIOCFG_IN << PC4_CFG_BIT) | (GPIOCFG_IN << PC5_CFG_BIT) |
|
||||
(GPIOCFG_IN << PC6_CFG_BIT) | (GPIOCFG_IN << PC7_CFG_BIT); /* OSC32K */
|
||||
|
||||
leds_init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Power down sensors
|
||||
*/
|
||||
void
|
||||
board_sensors_power_down(void)
|
||||
{
|
||||
/*
|
||||
* Remember state of sensors (if active or not), in order to
|
||||
* resume their original state after calling powerUpSensors().
|
||||
* Useful when entering in sleep mode, since all system
|
||||
* peripherals have to be reinitialized.
|
||||
*/
|
||||
sensors_status = 0;
|
||||
|
||||
if(button_sensor.status(SENSORS_READY)) {
|
||||
sensors_status |= BUTTON_STATUS_ACTIVE;
|
||||
}
|
||||
if(temperature_sensor.status(SENSORS_READY)) {
|
||||
sensors_status |= TEMP_STATUS_ACTIVE;
|
||||
}
|
||||
if(acc_sensor.status(SENSORS_READY)) {
|
||||
sensors_status |= ACC_STATUS_ACTIVE;
|
||||
/* Power down accelerometer to save power */
|
||||
SENSORS_DEACTIVATE(acc_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Power up sensors
|
||||
*/
|
||||
void
|
||||
board_sensors_power_up(void)
|
||||
{
|
||||
button_sensor.configure(SENSORS_HW_INIT, 0);
|
||||
temperature_sensor.configure(SENSORS_HW_INIT, 0);
|
||||
acc_sensor.configure(SENSORS_HW_INIT, 0);
|
||||
|
||||
if(sensors_status & BUTTON_STATUS_ACTIVE) {
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
}
|
||||
if(sensors_status & TEMP_STATUS_ACTIVE) {
|
||||
SENSORS_ACTIVATE(temperature_sensor);
|
||||
}
|
||||
if(sensors_status & ACC_STATUS_ACTIVE) {
|
||||
SENSORS_ACTIVATE(acc_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Power up board
|
||||
*/
|
||||
void
|
||||
board_power_up(void)
|
||||
{
|
||||
/* Set everything to inputs */
|
||||
GPIO_PACFGL = (GPIOCFG_IN << PA0_CFG_BIT) |
|
||||
(GPIOCFG_IN << PA1_CFG_BIT) |
|
||||
(GPIOCFG_IN << PA2_CFG_BIT) | (GPIOCFG_IN << PA3_CFG_BIT);
|
||||
GPIO_PACFGH = (GPIOCFG_IN << PA4_CFG_BIT) | /* PTI EN */
|
||||
(GPIOCFG_IN << PA5_CFG_BIT) | /* PTI_DATA */
|
||||
(GPIOCFG_IN << PA6_CFG_BIT) | (GPIOCFG_IN << PA7_CFG_BIT);
|
||||
GPIO_PBCFGL = (GPIOCFG_IN << PB0_CFG_BIT) | (GPIOCFG_OUT_ALT << PB1_CFG_BIT) |
|
||||
(GPIOCFG_IN << PB2_CFG_BIT) | /* Uart Rx, Tx */
|
||||
(GPIOCFG_IN << PB3_CFG_BIT);
|
||||
GPIO_PBCFGH = (GPIOCFG_IN << PB4_CFG_BIT) |
|
||||
(GPIOCFG_IN << PB5_CFG_BIT) |
|
||||
(GPIOCFG_IN << PB6_CFG_BIT) | (GPIOCFG_IN << PB7_CFG_BIT);
|
||||
GPIO_PCCFGL = (GPIOCFG_IN << PC0_CFG_BIT) |
|
||||
(GPIOCFG_IN << PC1_CFG_BIT) |
|
||||
(GPIOCFG_IN << PC2_CFG_BIT) | (GPIOCFG_IN << PC3_CFG_BIT);
|
||||
GPIO_PCCFGH = (GPIOCFG_IN << PC4_CFG_BIT) | (GPIOCFG_IN << PC5_CFG_BIT) |
|
||||
(GPIOCFG_IN << PC6_CFG_BIT) | (GPIOCFG_IN << PC7_CFG_BIT); /* OSC32K */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* STM32W108 HAL functions needed to get use the
|
||||
hal/micro/cortexm3/micro.c functionality. */
|
||||
void halBoardInit(void) { board_init(); }
|
||||
void halBoardPowerUp(void) { board_power_up(); }
|
||||
void halBoardPowerDown(void) { board_power_down(); }
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -1,172 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* contiki-conf.h for MB851.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
* Chi-Anh La <la@imag.fr>
|
||||
* Simon Duquennoy <simonduq@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
|
||||
#ifdef PLATFORM_CONF_H
|
||||
#include PLATFORM_CONF_H
|
||||
#else
|
||||
#include "platform-conf.h"
|
||||
#endif /* PLATFORM_CONF_H */
|
||||
|
||||
/* Radio and 802.15.4 params */
|
||||
/* 802.15.4 radio channel */
|
||||
#define RF_CHANNEL 26
|
||||
/* 802.15.4 PAN ID */
|
||||
#define IEEE802154_CONF_PANID 0xabcd
|
||||
/* Use EID 64, enable hardware autoack and address filtering */
|
||||
#define RIMEADDR_CONF_SIZE 8
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define ST_CONF_RADIO_AUTOACK 1
|
||||
/* Number of buffers for incoming frames */
|
||||
#define RADIO_RXBUFS 2
|
||||
/* Set to 0 for non ethernet links */
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
|
||||
/* RDC params */
|
||||
/* TX routine passes the cca/ack result in the return parameter */
|
||||
#define RDC_CONF_HARDWARE_ACK 1
|
||||
/* TX routine does automatic cca and optional backoff */
|
||||
#define RDC_CONF_HARDWARE_CSMA 0
|
||||
/* RDC debug with LED */
|
||||
#define RDC_CONF_DEBUG_LED 0
|
||||
/* Channel check rate (per second) */
|
||||
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||
/* Use ACK for optimization (LPP, XMAC) */
|
||||
#define WITH_ACK_OPTIMIZATION 0
|
||||
|
||||
/* Netstack config */
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_CONF_RDC contikimac_driver
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_RADIO stm32w_radio_driver
|
||||
|
||||
/* ContikiMAC config */
|
||||
#define CONTIKIMAC_CONF_COMPOWER 0
|
||||
#define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0
|
||||
#define CONTIKIMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION 0
|
||||
|
||||
/* CXMAC config */
|
||||
#define CXMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define CXMAC_CONF_COMPOWER 1
|
||||
|
||||
/* XMAC config */
|
||||
#define XMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define XMAC_CONF_COMPOWER 1
|
||||
|
||||
/* Other (RAM saving) */
|
||||
#define ENERGEST_CONF_ON 0
|
||||
#define QUEUEBUF_CONF_NUM 2
|
||||
#define QUEUEBUF_CONF_REF_NUM 0
|
||||
#define UIP_CONF_DS6_NBR_NBU 4
|
||||
#define UIP_CONF_MAX_ROUTES 4
|
||||
#define RPL_CONF_MAX_PARENTS_PER_DAG 4
|
||||
#define RPL_CONF_MAX_INSTANCES 1
|
||||
#define RPL_CONF_MAX_DAG_PER_INSTANCE 1
|
||||
#define PROCESS_CONF_NUMEVENTS 16
|
||||
|
||||
#if WITH_UIP6
|
||||
|
||||
/* Network setup for IPv6 */
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
|
||||
/*
|
||||
* Specify a minimum packet size for 6lowpan compression to be
|
||||
* enabled. This is needed for ContikiMAC, which needs packets to be
|
||||
* larger than a specified size, if no ContikiMAC header should
|
||||
* be used.
|
||||
*/
|
||||
#define SICSLOWPAN_CONF_COMPRESSION_THRESHOLD 63
|
||||
#define CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER 0
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
#define UIP_CONF_IPV6_RPL 1
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
|
||||
#define UIP_CONF_BUFFER_SIZE 140
|
||||
|
||||
#define UIP_CONF_IPV6 1
|
||||
#define UIP_CONF_IPV6_QUEUE_PKT 0
|
||||
#define UIP_CONF_IPV6_CHECKS 1
|
||||
#define UIP_CONF_IPV6_REASSEMBLY 0
|
||||
#define UIP_CONF_ND6_MAX_PREFIXES 2
|
||||
#define UIP_CONF_ND6_MAX_NEIGHBORS 2
|
||||
#define UIP_CONF_ND6_MAX_DEFROUTERS 1
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||
#define UIP_CONF_UDP_CONNS 4
|
||||
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#ifndef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
#endif /* SICSLOWPAN_CONF_FRAG */
|
||||
#ifndef SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS
|
||||
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
|
||||
#endif /* SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS */
|
||||
#ifndef SICSLOWPAN_CONF_MAXAGE
|
||||
#define SICSLOWPAN_CONF_MAXAGE 2
|
||||
#endif /* SICSLOWPAN_CONF_MAXAGE */
|
||||
|
||||
#else /* WITH_UIP6 */
|
||||
|
||||
/* Network setup for non-IPv6 (rime). */
|
||||
#define NETSTACK_CONF_NETWORK rime_driver
|
||||
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
#ifdef PROJECT_CONF_H
|
||||
#include PROJECT_CONF_H
|
||||
#endif /* PROJECT_CONF_H */
|
||||
|
||||
#ifdef PLATFORM_CONF
|
||||
#include PLATFORM_CONF
|
||||
#endif /* PLATFORM_CONF */
|
||||
|
||||
#endif /* __CONTIKI_CONF_H__ */
|
||||
/** @} */
|
|
@ -1,332 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Contiki main file.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
* Chi-Anh La <la@imag.fr>
|
||||
*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include "hal/error.h"
|
||||
#include "hal/hal.h"
|
||||
#include BOARD_HEADER
|
||||
#include "micro/adc.h"
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/acc-sensor.h"
|
||||
#include "dev/uart1.h"
|
||||
#include "dev/serial-line.h"
|
||||
|
||||
#include "dev/stm32w-radio.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/rime/rimeaddr.h"
|
||||
#include "net/rime.h"
|
||||
#include "net/rime/rime-udp.h"
|
||||
#include "net/uip.h"
|
||||
|
||||
#if WITH_UIP6
|
||||
#include "net/uip-ds6.h"
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
|
||||
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",lladdr.u8[0], lladdr.u8[1], lladdr.u8[2], lladdr.u8[3],lladdr.u8[4], lladdr.u8[5], lladdr.u8[6], lladdr.u8[7])
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#define PRINT6ADDR(addr)
|
||||
#define PRINTLLADDR(addr)
|
||||
#endif
|
||||
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
PROCINIT(&tcpip_process, &sensors_process);
|
||||
#else
|
||||
PROCINIT(&sensors_process);
|
||||
#warning "No TCP/IP process!"
|
||||
#endif
|
||||
|
||||
SENSORS(&button_sensor, &temperature_sensor, &acc_sensor);
|
||||
|
||||
/* The default CCA threshold is set to -77, which is the same as the
|
||||
default setting on the TI CC2420. */
|
||||
#define DEFAULT_RADIO_CCA_THRESHOLD (-77)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
print_processes(struct process * const processes[])
|
||||
{
|
||||
#if !PROCESS_CONF_NO_PROCESS_NAMES
|
||||
/* const struct process * const * p = processes;*/
|
||||
printf("Starting");
|
||||
while(*processes != NULL) {
|
||||
printf(" '%s'", (*processes)->name);
|
||||
processes++;
|
||||
}
|
||||
printf("\n");
|
||||
#endif /* !PROCESS_CONF_NO_PROCESS_NAMES */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_rime_addr(void)
|
||||
{
|
||||
int i;
|
||||
union {
|
||||
uint8_t u8[8];
|
||||
} eui64;
|
||||
|
||||
uint8_t *stm32w_eui64 = ST_RadioGetEui64();
|
||||
{
|
||||
uint8_t c;
|
||||
/* Copy the EUI-64 to lladdr converting from Little-Endian to
|
||||
Big-Endian. */
|
||||
for(c = 0; c < 8; c++) {
|
||||
eui64.u8[c] = stm32w_eui64[7 - c];
|
||||
}
|
||||
}
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
memcpy(&uip_lladdr.addr, &eui64, sizeof(uip_lladdr.addr));
|
||||
#endif
|
||||
|
||||
#if UIP_CONF_IPV6
|
||||
rimeaddr_set_node_addr((rimeaddr_t *) &eui64);
|
||||
#else
|
||||
rimeaddr_set_node_addr((rimeaddr_t *) &eui64.u8[8 - RIMEADDR_SIZE]);
|
||||
#endif
|
||||
|
||||
printf("Rime started with address ");
|
||||
for(i = 0; i < sizeof(rimeaddr_t) - 1; i++) {
|
||||
printf("%d.", rimeaddr_node_addr.u8[i]);
|
||||
}
|
||||
printf("%d\n", rimeaddr_node_addr.u8[i]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/*
|
||||
* Initalize hardware.
|
||||
*/
|
||||
halInit();
|
||||
clock_init();
|
||||
uart1_init(115200);
|
||||
|
||||
/* LED initialization */
|
||||
leds_init();
|
||||
|
||||
INTERRUPTS_ON();
|
||||
|
||||
PRINTF("\r\nStarting ");
|
||||
PRINTF(CONTIKI_VERSION_STRING);
|
||||
PRINTF(" on MB851\r\n");
|
||||
|
||||
/*
|
||||
* Initialize Contiki and our processes.
|
||||
*/
|
||||
process_init();
|
||||
|
||||
#if WITH_SERIAL_LINE_INPUT
|
||||
uart1_set_input(serial_line_input_byte);
|
||||
serial_line_init();
|
||||
#endif
|
||||
/* rtimer and ctimer should be initialized before radio duty cycling
|
||||
layers */
|
||||
rtimer_init();
|
||||
/* etimer_process should be initialized before ctimer */
|
||||
process_start(&etimer_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
netstack_init();
|
||||
|
||||
set_rime_addr();
|
||||
|
||||
printf("%s %s, channel check rate %lu Hz\n",
|
||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
|
||||
NETSTACK_RDC.channel_check_interval()));
|
||||
printf("802.15.4 PAN ID 0x%x, EUI-%d:",
|
||||
IEEE802154_CONF_PANID, UIP_CONF_LL_802154 ? 64 : 16);
|
||||
uip_debug_lladdr_print(&rimeaddr_node_addr);
|
||||
printf(", radio channel %u\n", RF_CHANNEL);
|
||||
|
||||
procinit_init();
|
||||
|
||||
energest_init();
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
|
||||
/* Set the Clear Channel Assessment (CCA) threshold of the
|
||||
radio. The CCA threshold is used both for sending packets and for
|
||||
waking up ContikiMAC nodes. If the CCA threshold is too high,
|
||||
ContikiMAC will not wake up from neighbor transmissions. If the
|
||||
CCA threshold is too low, transmissions will be too restrictive
|
||||
and no packets will be sent. DEFAULT_RADIO_CCA_THRESHOLD is
|
||||
defined in this file. */
|
||||
ST_RadioSetEdCcaThreshold(DEFAULT_RADIO_CCA_THRESHOLD);
|
||||
|
||||
print_processes(autostart_processes);
|
||||
autostart_start(autostart_processes);
|
||||
#if UIP_CONF_IPV6
|
||||
printf("Tentative link-local IPv6 address ");
|
||||
{
|
||||
uip_ds6_addr_t *lladdr;
|
||||
|
||||
int i;
|
||||
|
||||
lladdr = uip_ds6_get_link_local(-1);
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
|
||||
lladdr->ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
||||
}
|
||||
|
||||
|
||||
if(!UIP_CONF_IPV6_RPL) {
|
||||
uip_ipaddr_t ipaddr;
|
||||
|
||||
int i;
|
||||
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
||||
printf("Tentative global IPv6 address ");
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:", ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x\n", ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
||||
}
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
watchdog_start();
|
||||
|
||||
while(1) {
|
||||
int r;
|
||||
|
||||
do {
|
||||
/* Reset watchdog. */
|
||||
watchdog_periodic();
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
||||
/* watchdog_stop(); */
|
||||
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
||||
/* Go to idle mode. */
|
||||
halSleepWithOptions(SLEEPMODE_IDLE, 0);
|
||||
/* We are awake. */
|
||||
/* watchdog_start(); */
|
||||
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#if 0
|
||||
uint8_t errcode __attribute__(( section(".noinit") ));
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
halBaseBandIsr(void)
|
||||
{
|
||||
errcode = 1;
|
||||
leds_on(LEDS_RED);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
BusFault_Handler(void)
|
||||
{
|
||||
errcode = 2;
|
||||
leds_on(LEDS_RED);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
halDebugIsr(void)
|
||||
{
|
||||
errcode = 3;
|
||||
leds_on(LEDS_RED);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
DebugMon_Handler(void)
|
||||
{
|
||||
errcode = 4;
|
||||
/* leds_on(LEDS_RED); */
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
HardFault_Handler(void)
|
||||
{
|
||||
errcode = 5;
|
||||
/* leds_on(LEDS_RED); */
|
||||
/* halReboot(); */
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
MemManage_Handler(void)
|
||||
{
|
||||
errcode = 6;
|
||||
/* leds_on(LEDS_RED); */
|
||||
/* halReboot(); */
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
UsageFault_Handler(void)
|
||||
{
|
||||
errcode = 7;
|
||||
/* leds_on(LEDS_RED); */
|
||||
/* halReboot(); */
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
Default_Handler()
|
||||
{
|
||||
/* errcode = 8; */
|
||||
leds_on(LEDS_RED);
|
||||
halReboot();
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#endif
|
||||
/** @} */
|
|
@ -1,137 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Accelerometer driver.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "dev/acc-sensor.h"
|
||||
#include "mems.h"
|
||||
#include "sys/clock.h"
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
uint8_t reg;
|
||||
|
||||
if(!i2c_read_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, ®, 1)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (reg & 0x40) ? TRUE : FALSE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
int8_t i2c_data = 0;
|
||||
uint8_t reg_addr;
|
||||
|
||||
switch (type) {
|
||||
case ACC_X_AXIS:
|
||||
reg_addr = OUTX_H;
|
||||
break;
|
||||
|
||||
case ACC_Y_AXIS:
|
||||
reg_addr = OUTY_H;
|
||||
break;
|
||||
|
||||
case ACC_Z_AXIS:
|
||||
reg_addr = OUTZ_H;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2c_read_reg(KLIS3L02DQ_SLAVE_ADDR, reg_addr, (uint8_t *) &i2c_data, 1);
|
||||
|
||||
if(mems_get_fullscale() == ACC_HIGH_RANGE) {
|
||||
return ((int16_t) i2c_data) * HIGH_RANGE_SENSITIVITY;
|
||||
} else {
|
||||
return ((int16_t) i2c_data) * LOW_RANGE_SENSITIVITY;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_HW_INIT:
|
||||
return mems_init();
|
||||
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
if(mems_on()) {
|
||||
clock_wait(8);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return mems_off();
|
||||
}
|
||||
|
||||
case ACC_RANGE:
|
||||
return mems_set_fullscale((boolean) value);
|
||||
|
||||
case ACC_HPF:
|
||||
if(value < ACC_HPF_DISABLE) {
|
||||
return i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG2,
|
||||
(1 << 4) | (uint8_t) value);
|
||||
} else {
|
||||
return i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, 0x00);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_READY:
|
||||
return active();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(acc_sensor, ACC_SENSOR, value, configure, status);
|
||||
/** @} */
|
|
@ -1,77 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Accelerometer header file.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef __ACC_SENSOR_H__
|
||||
#define __ACC_SENSOR_H__
|
||||
|
||||
#include "lib/sensors.h"
|
||||
#include "mems.h"
|
||||
|
||||
extern const struct sensors_sensor acc_sensor;
|
||||
|
||||
#define ACC_SENSOR "Acc"
|
||||
|
||||
/* The type values used in the configure() function. */
|
||||
/* Full-scale */
|
||||
#define ACC_RANGE 1
|
||||
#define ACC_LOW_RANGE MEMS_LOW_RANGE
|
||||
#define ACC_HIGH_RANGE MEMS_HIGH_RANGE
|
||||
|
||||
/* High pass filter and cut-off frequencies */
|
||||
#define ACC_HPF 2
|
||||
|
||||
#define ACC_HPF_DISABLE 4
|
||||
#define ACC_1HZ 3
|
||||
#define ACC_2HZ 2
|
||||
#define ACC_4HZ 1
|
||||
#define ACC_8HZ 0
|
||||
|
||||
/*
|
||||
* The type values used in the value() function.
|
||||
* The returned value is expressed in mg units and can be negative.
|
||||
*/
|
||||
#define ACC_X_AXIS 1
|
||||
#define ACC_Y_AXIS 2
|
||||
#define ACC_Z_AXIS 3
|
||||
|
||||
#endif /* __ACC_SENSOR_H__ */
|
||||
/** @} */
|
|
@ -1,186 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Button sensor.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"
|
||||
|
||||
#include BOARD_HEADER
|
||||
#define DEBOUNCE 1
|
||||
|
||||
/**
|
||||
* \brief Port and pin for BUTTON0.
|
||||
*/
|
||||
#undef BUTTON_S1
|
||||
#define BUTTON_S1 PORTA_PIN(7)
|
||||
#define BUTTON_S1_INPUT_GPIO BUTTON_INPUT_GPIO(PORTA)
|
||||
#define BUTTON_S1_GPIO_PIN 7
|
||||
#define BUTTON_S1_OUTPUT_GPIO GPIO_PAOUT
|
||||
|
||||
/**
|
||||
* \brief Point the proper IRQ at the desired pin for BUTTON0.
|
||||
*/
|
||||
#define BUTTON_S1_SEL() do { GPIO_IRQCSEL = BUTTON_S1; } while(0)
|
||||
/**
|
||||
* \brief The interrupt service routine for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_ISR halIrqCIsr
|
||||
/**
|
||||
* \brief The interrupt configuration register for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_INTCFG GPIO_INTCFGC
|
||||
/**
|
||||
* \brief The interrupt bit for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_INT_EN_BIT INT_IRQC
|
||||
/**
|
||||
* \brief The interrupt bit for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_FLAG_BIT INT_IRQCFLAG
|
||||
/**
|
||||
* \brief The missed interrupt bit for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_MISS_BIT INT_MISSIRQC
|
||||
|
||||
#if DEBOUNCE
|
||||
static struct timer debouncetimer;
|
||||
#endif
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
#if DEBOUNCE
|
||||
timer_set(&debouncetimer, 0);
|
||||
#endif
|
||||
|
||||
/* Configure GPIO */
|
||||
/* Input, pulled up or down (selected by GPIO_PxOUT: 0 = pull-down). */
|
||||
halGpioConfig(BUTTON_S1, GPIOCFG_IN_PUD);
|
||||
BUTTON_S1_OUTPUT_GPIO |= GPIOOUT_PULLUP << BUTTON_S1_GPIO_PIN;
|
||||
BUTTON_S1_SEL();
|
||||
BUTTON_S1_INTCFG = 0x40; /* Falling edge triggered. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
INT_CFGSET = BUTTON_S1_INT_EN_BIT;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
INT_CFGCLR = BUTTON_S1_INT_EN_BIT;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return (INT_CFGSET & BUTTON_S1_INT_EN_BIT) ? TRUE : FALSE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
#if DEBOUNCE
|
||||
return (BUTTON_S1_INPUT_GPIO & (1 << BUTTON_S1_GPIO_PIN)) ||
|
||||
!timer_expired(&debouncetimer);
|
||||
#else
|
||||
return BUTTON_S1_INPUT_GPIO & (1 << BUTTON_S1_GPIO_PIN);
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
BUTTON_S1_ISR(void)
|
||||
{
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
/* sensors_handle_irq(IRQ_BUTTON); */
|
||||
|
||||
if(INT_GPIOFLAG & BUTTON_S1_FLAG_BIT) {
|
||||
#if DEBOUNCE
|
||||
if(timer_expired(&debouncetimer)) {
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 5);
|
||||
sensors_changed(&button_sensor);
|
||||
}
|
||||
#else
|
||||
sensors_changed(&button_sensor);
|
||||
#endif
|
||||
}
|
||||
|
||||
INT_GPIOFLAG = BUTTON_S1_FLAG_BIT;
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, configure, status);
|
||||
/** @} */
|
|
@ -1,123 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : mems-regs.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V1.0
|
||||
* Date : January 2010
|
||||
* Description : stm32w108 mems registers
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _MEMS_REGS_H_
|
||||
#define _MEMS_REGS_H_
|
||||
#include <stdint.h>
|
||||
|
||||
/* Size of MEMs data */
|
||||
#define MEMS_DATA_SIZE 6
|
||||
|
||||
/* address of slave */
|
||||
#define KLIS3L02DQ_SLAVE_ADDR 0x38
|
||||
|
||||
/* accelerometer register addresses */
|
||||
#define OFFSET_X 0x16
|
||||
#define OFFSET_Y 0x17
|
||||
#define OFFSET_Z 0x18
|
||||
#define GAIN_X 0x19
|
||||
#define GAIN_Y 0x1A
|
||||
#define GAIN_Z 0x1B
|
||||
#define CTRL_REG1 0x20
|
||||
#define CTRL_REG2 0x21
|
||||
#define STATUS_REG 0x27
|
||||
#define OUTX_L 0x28
|
||||
#define OUTX_H 0x29
|
||||
#define OUTY_L 0x2A
|
||||
#define OUTY_H 0x2B
|
||||
#define OUTZ_L 0x2C
|
||||
#define OUTZ_H 0x2D
|
||||
#define FF_WU_CFG 0x30
|
||||
#define FF_WU_SRC 0x31
|
||||
#define FF_WU_ACK 0x32
|
||||
#define FF_WU_THS_L 0x34
|
||||
#define FF_WU_THS_H 0x35
|
||||
#define FF_WU_DURATION 0x36
|
||||
#define DD_CFG 0x38
|
||||
#define DD_SRC 0x39
|
||||
#define DD_ACK 0x3A
|
||||
#define DD_THSI_L 0x3C
|
||||
#define DD_THSI_H 0x3D
|
||||
#define DD_THSE_L 0x3E
|
||||
#define DD_THSE_H 0x3F
|
||||
|
||||
/* Communication control settings */
|
||||
/* I2C */
|
||||
#define REPETIR 0x80
|
||||
/* SPI */
|
||||
#define MEMS_SPI_WRITE 0x00
|
||||
#define MEMS_SPI_READ 0x80
|
||||
#define MEMS_SPI_MULTIPLE_BYTES 0x40
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* Settings for CTRL_REG1 */
|
||||
/* Power Down Control (PD) */
|
||||
#define LIS_PD_OFF 0x00
|
||||
#define LIS_PD_ON 0x40
|
||||
|
||||
/* Decimation Factor Control (DF) */
|
||||
#define LIS_DF_BY128 0x00
|
||||
#define LIS_DF_BY64 0x10
|
||||
#define LIS_DF_BY32 0x20
|
||||
#define LIS_DF_BY8 0x30
|
||||
|
||||
/* Self Test */
|
||||
#define LIS_ST_NORMAL 0x00
|
||||
#define LIS_ST_TEST 0x08
|
||||
|
||||
/* Enable Axis */
|
||||
#define LIS_EA_ALL 0x07
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* Settings for CTRL_REG2 */
|
||||
|
||||
/* Full Scale (FS) */
|
||||
#define LIS_FS_2G 0x00
|
||||
#define LIS_FS_6G 0x80
|
||||
|
||||
/* Block Data Update (BDU) */
|
||||
#define LIS_BDU_CONTINUOUS 0x00
|
||||
#define LIS_BDU_WAIT 0x40
|
||||
|
||||
/* Big/Little Endian Selection (BLE) */
|
||||
#define LIS_BLE_LE 0x00
|
||||
#define LIS_BLE_BE 0x20
|
||||
#define LIS_BLE_XX LIS_BLE_BE
|
||||
|
||||
/* Data Alignment Selection DAS */
|
||||
#define LIS_DAS_12BIT 0x00
|
||||
#define LIS_DAS_16BIT 0x01
|
||||
|
||||
/* Interrupt Enable */
|
||||
#define LIS_INTR_DISABLE 0x00
|
||||
#define LIS_INTR_ENABLE 0x08
|
||||
|
||||
/* Data Ready Enable */
|
||||
#define LIS_DRDY_DISABLE 0x00
|
||||
#define LIS_DRDY_ENABLE 0x04
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
uint8_t i2c_write_reg(uint8_t slave_addr, uint8_t reg_addr,
|
||||
uint8_t reg_value);
|
||||
uint8_t i2c_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_buf,
|
||||
uint8_t len);
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#endif /* _MEMS_REGS_H_ */
|
||||
/** @} */
|
|
@ -1,348 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : hal_led.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V1.0
|
||||
* Date : September 2009
|
||||
* Description : Driver for leds management on STM32W108 MB851 board
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include "mems.h"
|
||||
#include "timer.h"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#define TIMEOUT 20000
|
||||
#define SUCCESS 1
|
||||
#define FAIL 0
|
||||
|
||||
#define SEND_BYTE(data) do { SC2_DATA=(data); SC2_TWICTRL1 |= SC_TWISEND; \
|
||||
} while(0)
|
||||
|
||||
#define WAIT_CMD_FIN() { \
|
||||
struct timer t; \
|
||||
timer_set(&t, CLOCK_SECOND/100); \
|
||||
while((SC2_TWISTAT&SC_TWICMDFIN)!=SC_TWICMDFIN){ \
|
||||
if(timer_expired(&t)){ \
|
||||
return FAIL; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WAIT_TX_FIN() { \
|
||||
struct timer t; \
|
||||
timer_set(&t, CLOCK_SECOND/100); \
|
||||
while((SC2_TWISTAT&SC_TWITXFIN)!=SC_TWITXFIN){ \
|
||||
if(timer_expired(&t)){ \
|
||||
return FAIL; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define WAIT_RX_FIN() { \
|
||||
struct timer t; \
|
||||
timer_set(&t, CLOCK_SECOND/100); \
|
||||
while((SC2_TWISTAT&SC_TWIRXFIN)!=SC_TWIRXFIN){ \
|
||||
if(timer_expired(&t)){ \
|
||||
return FAIL; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static boolean fullscale_state;
|
||||
|
||||
static uint8_t i2c_mems_init(void);
|
||||
|
||||
static uint8_t i2c_send_frame(uint8_t address, uint8_t *p_buf, uint8_t len);
|
||||
|
||||
uint8_t i2c_write_reg(uint8_t slave_addr, uint8_t reg_addr,
|
||||
uint8_t reg_value);
|
||||
|
||||
/* static uint8_t i2c_mems_read (mems_data_t *mems_data); */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init MEMS
|
||||
* \return None
|
||||
*/
|
||||
uint8_t
|
||||
mems_init(void)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
|
||||
/* GPIO assignments */
|
||||
/* PA1: SC2SDA (Serial Data) */
|
||||
/* PA2: SC2SCL (Serial Clock) */
|
||||
/* -----SC2 I2C Master GPIO configuration */
|
||||
TIM2_CCER &= 0xFFFFEEEE;
|
||||
SC2_MODE = SC2_MODE_I2C;
|
||||
GPIO_PACFGL &= 0xFFFFF00F;
|
||||
GPIO_PACFGL |= 0x00000DD0;
|
||||
|
||||
SC2_RATELIN = 14; /* generates standard 100kbps or 400kbps */
|
||||
SC2_RATEEXP = 1; /* 3 yields 100kbps; 1 yields 400kbps */
|
||||
SC2_TWICTRL1 = 0; /* start from a clean state */
|
||||
SC2_TWICTRL2 = 0; /* start from a clean state */
|
||||
|
||||
ret = i2c_mems_init();
|
||||
fullscale_state = MEMS_LOW_RANGE;
|
||||
|
||||
/* Add later if really needed */
|
||||
#ifdef ST_DBG
|
||||
if(!ret)
|
||||
I2C_DeInit(MEMS_I2C);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Returns the 3 mems acceleration values related to x,y,z axes
|
||||
* \param mems_data pointer to mems_data_t that will be filled with the values
|
||||
* \return None
|
||||
*/
|
||||
#if 0
|
||||
uint8_t mems_get_value(mems_data_t *mems_data)
|
||||
{
|
||||
uint8_t i;
|
||||
i = i2c_mems_read(mems_data);
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Send I2C frame
|
||||
* \param address destination device address
|
||||
* \param p_buf pointer to data buffer
|
||||
* \param len length of data
|
||||
* \retval 0 frame has not been successfully sent
|
||||
* \retval 1 frame has been successfully sent
|
||||
*/
|
||||
static uint8_t
|
||||
i2c_send_frame(uint8_t address, uint8_t *p_buf, uint8_t len)
|
||||
{
|
||||
uint8_t i, data;
|
||||
|
||||
SC2_TWICTRL1 |= SC_TWISTART; /* send start */
|
||||
WAIT_CMD_FIN();
|
||||
SEND_BYTE(address); /* send the address low byte */
|
||||
WAIT_TX_FIN();
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
halInternalResetWatchDog();
|
||||
data = *(p_buf + i);
|
||||
SEND_BYTE(data);
|
||||
WAIT_TX_FIN();
|
||||
}
|
||||
|
||||
SC2_TWICTRL1 |= SC_TWISTOP;
|
||||
WAIT_CMD_FIN();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Receive I2C frame
|
||||
* \param address slave device address
|
||||
* \param p_buf pointer to data buffer
|
||||
* \param len length of data
|
||||
* \retval 0 frame has not been successfully received
|
||||
* \retval 1 frame has been successfully received
|
||||
*/
|
||||
static uint8_t
|
||||
i2c_receive_frame(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_buf,
|
||||
uint8_t len)
|
||||
{
|
||||
uint8_t i, addr = reg_addr;
|
||||
|
||||
if(len > 1) {
|
||||
addr += REPETIR;
|
||||
}
|
||||
|
||||
SC2_TWICTRL1 |= SC_TWISTART; /* send start */
|
||||
WAIT_CMD_FIN();
|
||||
|
||||
SEND_BYTE(slave_addr | 0x00); /* send the address low byte */
|
||||
WAIT_TX_FIN();
|
||||
|
||||
SEND_BYTE(addr);
|
||||
WAIT_TX_FIN();
|
||||
|
||||
SC2_TWICTRL1 |= SC_TWISTART; /* send start */
|
||||
WAIT_CMD_FIN();
|
||||
|
||||
SEND_BYTE(slave_addr | 0x01); /* send the address low byte */
|
||||
WAIT_TX_FIN();
|
||||
|
||||
for(i = 0; i < len; i++) {
|
||||
halInternalResetWatchDog();
|
||||
if(i < (len - 1)) {
|
||||
SC2_TWICTRL2 |= SC_TWIACK; /* ack on receipt of data */
|
||||
} else {
|
||||
SC2_TWICTRL2 &= ~SC_TWIACK; /* don't ack if last one */
|
||||
}
|
||||
SC2_TWICTRL1 |= SC_TWIRECV; /* set to receive */
|
||||
WAIT_RX_FIN();
|
||||
*(p_buf + i) = SC2_DATA; /* receive data */
|
||||
}
|
||||
|
||||
SC2_TWICTRL1 |= SC_TWISTOP; /* send STOP */
|
||||
WAIT_CMD_FIN();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief write a register on the I2C target
|
||||
* \param slave_addr slave device address
|
||||
* \param reg_addr address of the register to be written
|
||||
* \param reg_value value of the register to be written
|
||||
* \retval 0 register has not been successfully written
|
||||
* \retval 1 register has been successfully written
|
||||
*/
|
||||
uint8_t
|
||||
i2c_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t reg_value)
|
||||
{
|
||||
uint8_t i2c_buffer[2];
|
||||
|
||||
i2c_buffer[0] = reg_addr;
|
||||
i2c_buffer[1] = reg_value;
|
||||
return i2c_send_frame(slave_addr, i2c_buffer, 2);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief read a register from the I2C target
|
||||
* \param slave_addr slave device address
|
||||
* \param reg_addr address of the register
|
||||
* \param p_buf storage destination for the read data
|
||||
* \retval 0 register has not been successfully read
|
||||
* \retval 1 register has been successfully read
|
||||
*/
|
||||
uint8_t
|
||||
i2c_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_buf,
|
||||
uint8_t len)
|
||||
{
|
||||
return i2c_receive_frame(slave_addr, reg_addr, p_buf, len);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init MEMS
|
||||
* \return None
|
||||
* \retval 0 the device has not been successfully initialized
|
||||
* \retval 1 the device has been successfully initialized
|
||||
*/
|
||||
static uint8_t
|
||||
i2c_mems_init(void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
||||
i += i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, STATUS_REG, 0x00); /* no flag */
|
||||
i += i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, FF_WU_CFG, 0x00); /* all off */
|
||||
i += i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, DD_CFG, 0x00); /* all off */
|
||||
/* i += i2c_write_reg (KLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, (1<<4) | (1<<1) | (1 << 0)); */
|
||||
|
||||
i += i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, 0x00);
|
||||
/* i += i2c_write_reg (KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, 0xC7); */
|
||||
i += i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, 0x87);
|
||||
|
||||
if(i != 5) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief turn on the MEMS device
|
||||
* \retval 0 the device has not been successfully set to normal mode
|
||||
* \retval 1 the device has been successfully set to normal mode
|
||||
*/
|
||||
uint8_t
|
||||
mems_on(void)
|
||||
{
|
||||
return i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, 0xC7);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief turn off the MEMS device
|
||||
* \retval 0 the device has not been successfully turned off
|
||||
* \retval 1 the device has been successfully turned off
|
||||
*/
|
||||
uint8_t
|
||||
mems_off(void)
|
||||
{
|
||||
return i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, 0x87);
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief set full-scale range of the device
|
||||
* \param range HIGH for high scale selection, LOW for low range.
|
||||
* \retval 0 the device has not been successfully set to full scale mode
|
||||
* \retval 1 the device has been successfully set to full scale mode
|
||||
*/
|
||||
uint8_t
|
||||
mems_set_fullscale(boolean range)
|
||||
{
|
||||
uint8_t i2c_buffer;
|
||||
if (!i2c_read_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, &i2c_buffer, 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(range == MEMS_HIGH_RANGE) {
|
||||
i2c_buffer |= 0x20;
|
||||
} else {
|
||||
i2c_buffer &= ~0x20;
|
||||
}
|
||||
|
||||
if (!i2c_write_reg(KLIS3L02DQ_SLAVE_ADDR, CTRL_REG1, i2c_buffer)) {
|
||||
return 0;
|
||||
}
|
||||
fullscale_state = range;
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Get full-scale range of the device
|
||||
* \retval HIGH high scale selection
|
||||
* \retval LOW low range
|
||||
*/
|
||||
boolean
|
||||
mems_get_fullscale(void)
|
||||
{
|
||||
return fullscale_state;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Returns the 3 mems acceleration values related to x,y,z axes
|
||||
* \param mems_data pointer to mems_data_t that will be filled with the values
|
||||
* \retval 0 acceleration data has not been successfully read
|
||||
* \retval 1 acceleration data has been successfully read
|
||||
*/
|
||||
#if 0
|
||||
static uint8_t
|
||||
i2c_mems_read(mems_data_t *mems_data)
|
||||
{
|
||||
uint8_t i, i2c_buffer[8];
|
||||
|
||||
i = i2c_read_reg (KLIS3L02DQ_SLAVE_ADDR, OUTX_L, i2c_buffer, 8);
|
||||
mems_data->outx_h = i2c_buffer[0];
|
||||
mems_data->outx_l = i2c_buffer[1];
|
||||
mems_data->outy_h = i2c_buffer[2];
|
||||
mems_data->outy_l = i2c_buffer[3];
|
||||
mems_data->outz_h = i2c_buffer[4];
|
||||
mems_data->outz_l = i2c_buffer[5];
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
|
||||
* File Name : mems.h
|
||||
* Author : MCD Application Team
|
||||
* Version : V1.0
|
||||
* Date : January 2010
|
||||
* Description : header file for mems driver
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _MEMS_H_
|
||||
#define _MEMS_H_
|
||||
#include "mems-regs.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* Sensitivity values in mg/digit */
|
||||
#define HIGH_RANGE_SENSITIVITY 72
|
||||
#define LOW_RANGE_SENSITIVITY 18
|
||||
|
||||
#define MEMS_LOW_RANGE 0
|
||||
#define MEMS_HIGH_RANGE 1
|
||||
|
||||
/*
|
||||
* Mems data type: three acceleration values each related to a specific
|
||||
* direction.
|
||||
* Watch out: only lower data values (e.g. those terminated by the _l) are
|
||||
* currently used by the device.
|
||||
*/
|
||||
typedef struct mems_data_s {
|
||||
int8_t outx_l;
|
||||
int8_t outx_h;
|
||||
int8_t outy_l;
|
||||
int8_t outy_h;
|
||||
int8_t outz_l;
|
||||
int8_t outz_h;
|
||||
} mems_data_t;
|
||||
|
||||
uint8_t mems_init(void);
|
||||
|
||||
uint8_t mems_on(void);
|
||||
|
||||
uint8_t mems_off(void);
|
||||
|
||||
uint8_t mems_set_fullscale(boolean range);
|
||||
|
||||
boolean mems_get_fullscale(void);
|
||||
|
||||
uint8_t mems_get_value(mems_data_t * mems_data);
|
||||
|
||||
#endif /* _MEMS_H_ */
|
||||
/** @} */
|
|
@ -1,66 +0,0 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Temperature sensor.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#ifndef __TEMPERATURE_SENSOR_H__
|
||||
#define __TEMPERATURE_SENSOR_H__
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
/*
|
||||
* Value returned by temperature_sensor.value() is expressed in units of 0.1 degC.
|
||||
*
|
||||
* NOTES:
|
||||
*
|
||||
* For the temperature measurement, the ADC extended range mode is needed;
|
||||
* but this is inaccurate due to the high voltage mode bug of the general purpose ADC
|
||||
* (see STM32W108 errata).
|
||||
*
|
||||
* For the temperature measurement, the ADC extended range mode is needed;
|
||||
* but this is inaccurate due to the high voltage mode bug of the general purpose ADC
|
||||
* (see STM32W108 errata).
|
||||
*/
|
||||
extern const struct sensors_sensor temperature_sensor;
|
||||
|
||||
#define TEMPERATURE_SENSOR "Temperature"
|
||||
|
||||
#endif /* __TEMPERATURE_SENSOR_H__ */
|
||||
/** @} */
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* \defgroup mb851-platform The STM32W MB851 platform.
|
||||
*
|
||||
* The STM32W MB851 platform.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* platform-conf.h for MB851.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
* Chi-Anh La <la@imag.fr>
|
||||
* Simon Duquennoy <simonduq@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __PLATFORM_CONF_H__
|
||||
#define __PLATFORM_CONF_H__
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h> /* For memcpm() */
|
||||
|
||||
/* Platform-dependent definitions */
|
||||
#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 unsigned short uip_stats_t;
|
||||
typedef unsigned long clock_time_t;
|
||||
typedef unsigned long rtimer_clock_t;
|
||||
|
||||
#define CLOCK_CONF_SECOND 1000
|
||||
#define RTIMER_CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
|
||||
/* rtimer_second = 11719 */
|
||||
#define RT_CONF_RESOLUTION 2
|
||||
|
||||
#define UART1_CONF_TX_WITH_INTERRUPT 0
|
||||
#define WITH_SERIAL_LINE_INPUT 1
|
||||
|
||||
/* A trick to resolve a compilation error with IAR. */
|
||||
#ifdef __ICCARM__
|
||||
#define UIP_CONF_DS6_AADDR_NBU 1
|
||||
#endif /* __ICCARM__ */
|
||||
|
||||
/* LEDs ports MB851 */
|
||||
#define LEDS_CONF_RED_PIN 0
|
||||
#define LEDS_CONF_GREEN_PIN 5
|
||||
#define LEDS_CONF_PORT PORTA
|
||||
#define LEDS_CONF_RED (1<<LEDS_CONF_RED_PIN)
|
||||
#define LEDS_CONF_GREEN (1<<LEDS_CONF_GREEN_PIN)
|
||||
|
||||
#define UIP_ARCH_ADD32 1
|
||||
#define UIP_ARCH_CHKSUM 0
|
||||
#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
|
||||
|
||||
#endif /* __PLATFORM_CONF_H__ */
|
||||
/** @} */
|
|
@ -1,13 +1,12 @@
|
|||
ARCH= irq.c sensors.c acc-sensor.c button-sensor.c temperature-sensor.c mems.c contact-sensor.c
|
||||
|
||||
|
||||
ARCH= irq.c sensors.c acc-sensor.c button-sensor.c temperature-sensor.c mems.c
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev
|
||||
ifndef CONTIKI_TARGET_MAIN
|
||||
CONTIKI_TARGET_MAIN = contiki-main.c led.c button.c board.c board-mbxxx.c
|
||||
CONTIKI_TARGET_MAIN = contiki-main.c board.c
|
||||
endif
|
||||
|
||||
ifeq ($(UIP_CONF_IPV6),1)
|
||||
ifdef UIP_CONF_IPV6
|
||||
CFLAGS += -DWITH_UIP6=1
|
||||
endif
|
||||
|
||||
|
@ -21,4 +20,3 @@ SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-linux
|
|||
ifeq ($(HOST_OS),Windows)
|
||||
SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-windows
|
||||
endif
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -94,3 +99,4 @@ shell_sensors_init(void)
|
|||
shell_register_command(&sensors_command);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -45,3 +50,4 @@
|
|||
void shell_sensors_init(void);
|
||||
|
||||
#endif /* __SHELL_SENSORS_H__ */
|
||||
/** @} */
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/*#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"*/
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/acc-sensor.h"
|
||||
|
||||
static uint8_t sensors_status;
|
||||
|
||||
#define BUTTON_STATUS_ACTIVE (1 << 0)
|
||||
#define TEMP_STATUS_ACTIVE (1 << 1)
|
||||
#define ACC_STATUS_ACTIVE (1 << 2)
|
||||
|
||||
/* Remember state of sensors (if active or not), in order to
|
||||
* resume their original state after calling powerUpSensors().
|
||||
* Useful when entering in sleep mode, since all system
|
||||
* peripherals have to be reinitialized. */
|
||||
|
||||
void sensorsPowerDown(){
|
||||
|
||||
sensors_status = 0;
|
||||
|
||||
if(button_sensor.status(SENSORS_READY)){
|
||||
sensors_status |= BUTTON_STATUS_ACTIVE;
|
||||
}
|
||||
if(temperature_sensor.status(SENSORS_READY)){
|
||||
sensors_status |= TEMP_STATUS_ACTIVE;
|
||||
}
|
||||
if(acc_sensor.status(SENSORS_READY)){
|
||||
sensors_status |= ACC_STATUS_ACTIVE;
|
||||
// Power down accelerometer to save power
|
||||
SENSORS_DEACTIVATE(acc_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
void sensorsPowerUp(){
|
||||
|
||||
button_sensor.configure(SENSORS_HW_INIT, 0);
|
||||
temperature_sensor.configure(SENSORS_HW_INIT, 0);
|
||||
acc_sensor.configure(SENSORS_HW_INIT, 0);
|
||||
|
||||
if(sensors_status & BUTTON_STATUS_ACTIVE){
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
}
|
||||
if(sensors_status & TEMP_STATUS_ACTIVE){
|
||||
SENSORS_ACTIVATE(temperature_sensor);
|
||||
}
|
||||
if(sensors_status & ACC_STATUS_ACTIVE){
|
||||
SENSORS_ACTIVATE(acc_sensor);
|
||||
}
|
||||
}
|
596
platform/mbxxx/board.c
Normal file
596
platform/mbxxx/board.c
Normal file
|
@ -0,0 +1,596 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Software layer to support all the ST kits boards
|
||||
*
|
||||
* \brief
|
||||
* Board file x STM32W108 Kits boards
|
||||
*
|
||||
* This file implements a software layer to support all the ST kits boards
|
||||
* and deal with the difference in leds, buttons and sensors connected
|
||||
* to the board. This a bit too complex for customer boards adaptation
|
||||
* and customer can simplify it to adapt it to their hardware environment
|
||||
* as they normally don't need to have the software running on several boards.
|
||||
* The boards supported are:
|
||||
* - MB851 A
|
||||
* - MB851 B
|
||||
* - MB851 C
|
||||
* - MB851 D
|
||||
* - MB954 A
|
||||
* - MB954 B
|
||||
* - MB954 C
|
||||
* - MB950 A
|
||||
* - MB951 A
|
||||
* - IDZ401V1
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
#ifdef EMBERZNET_HAL
|
||||
#include "stack/include/ember.h"
|
||||
#include "stack/include/error.h"
|
||||
#include "hal/hal.h"
|
||||
#define PORTA (0 << 3)
|
||||
#define PORTB (1 << 3)
|
||||
#define PORTC (2 << 3)
|
||||
#else
|
||||
#include "error.h"
|
||||
#include "hal/hal.h"
|
||||
#include "hal/micro/cortexm3/mfg-token.h"
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
const LedResourceType LedsMB851A[] = {
|
||||
{
|
||||
"D1", /* Green LED */
|
||||
PORTB,
|
||||
6
|
||||
},
|
||||
{
|
||||
"D3", /* Yellow LED */
|
||||
PORTB,
|
||||
5
|
||||
}
|
||||
};
|
||||
|
||||
const InfraRedLedResourceType infraRedLedMB851A = {
|
||||
"D5", /* Infrared LED */
|
||||
PORTB,
|
||||
4
|
||||
};
|
||||
|
||||
const LedResourceType LedsMB954A[] = {
|
||||
{
|
||||
"D1", /* Green LED */
|
||||
PORTA,
|
||||
5
|
||||
},
|
||||
{
|
||||
"D3", /* Yellow LED */
|
||||
PORTA,
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
const LedResourceType LedsIDZ401V1[] = {
|
||||
{
|
||||
"D2", /* Yellow LED */
|
||||
PORTA,
|
||||
7
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const ButtonResourceType ButtonsMB851A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTA,
|
||||
7
|
||||
}
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsMB954A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTB,
|
||||
3
|
||||
}
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsMB950A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTB,
|
||||
3
|
||||
},
|
||||
{
|
||||
"S2",
|
||||
PORTA,
|
||||
7
|
||||
},
|
||||
{
|
||||
"S3",
|
||||
PORTB,
|
||||
7
|
||||
},
|
||||
{
|
||||
"S4",
|
||||
PORTB,
|
||||
0
|
||||
},
|
||||
{
|
||||
"S5",
|
||||
PORTB,
|
||||
6
|
||||
}
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsMB951A[] = {
|
||||
{
|
||||
"S1",
|
||||
PORTA,
|
||||
3
|
||||
},
|
||||
};
|
||||
|
||||
const ButtonResourceType ButtonsIDZ401V1[] = {
|
||||
|
||||
};
|
||||
|
||||
|
||||
const TempSensorResourceType stlm20PB7noDiv = {
|
||||
"STLM20",
|
||||
PORTB,
|
||||
7,
|
||||
1,
|
||||
FALSE
|
||||
};
|
||||
|
||||
const TempSensorResourceType stlm20PA4noDiv = {
|
||||
"STLM20",
|
||||
PORTA,
|
||||
4,
|
||||
1,
|
||||
FALSE
|
||||
};
|
||||
|
||||
const TempSensorResourceType stlm20PA4withDiv = {
|
||||
"STLM20",
|
||||
PORTA,
|
||||
4,
|
||||
2,
|
||||
TRUE
|
||||
};
|
||||
|
||||
const MemsResourceType memsSensor = {
|
||||
"LIS302",
|
||||
0
|
||||
};
|
||||
|
||||
const BoardIOType ioMB851A = {
|
||||
LedsMB851A,
|
||||
ButtonsMB851A,
|
||||
};
|
||||
|
||||
const BoardIOType ioMB954A = {
|
||||
LedsMB954A,
|
||||
ButtonsMB954A,
|
||||
};
|
||||
|
||||
const BoardIOType ioMB950A = {
|
||||
LedsMB954A,
|
||||
ButtonsMB950A,
|
||||
};
|
||||
|
||||
const BoardIOType ioMB951A = {
|
||||
LedsMB954A,
|
||||
ButtonsMB951A,
|
||||
};
|
||||
|
||||
const BoardIOType ioIDZ401V1 = {
|
||||
LedsIDZ401V1,
|
||||
ButtonsIDZ401V1,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851A = {
|
||||
"MB851 A",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI),
|
||||
BUTTONS_MB851A,
|
||||
LEDS_MB851A,
|
||||
&ioMB851A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PB7noDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851B = {
|
||||
"MB851 B",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI),
|
||||
BUTTONS_MB851B,
|
||||
LEDS_MB851B,
|
||||
&ioMB851A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PB7noDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851C = {
|
||||
"MB851 C",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM),
|
||||
BUTTONS_MB851C,
|
||||
LEDS_MB851C,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PA4withDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB851D = {
|
||||
"MB851 D",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM),
|
||||
BUTTONS_MB851D,
|
||||
LEDS_MB851D,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PA4withDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB954A = {
|
||||
"MB954 A",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_FTDI | BOARD_HAS_PA),
|
||||
BUTTONS_MB954A,
|
||||
LEDS_MB954A,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PA4noDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB954B = {
|
||||
"MB954 B",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM | BOARD_HAS_PA),
|
||||
BUTTONS_MB954B,
|
||||
LEDS_MB954B,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PA4withDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB954C = {
|
||||
"MB954 C",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F | BOARD_HAS_EEPROM | BOARD_HAS_PA),
|
||||
BUTTONS_MB954C,
|
||||
LEDS_MB954C,
|
||||
&ioMB954A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PA4noDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB950A = {
|
||||
"MB950 A",
|
||||
(BOARD_HAS_MEMS | BOARD_HAS_TEMP_SENSOR | BOARD_HAS_STM32F),
|
||||
BUTTONS_MB950A,
|
||||
LEDS_MB950A,
|
||||
&ioMB950A,
|
||||
&infraRedLedMB851A,
|
||||
&memsSensor,
|
||||
&stlm20PA4noDiv,
|
||||
};
|
||||
|
||||
const BoardResourcesType MB951A = {
|
||||
"MB951 A",
|
||||
(BOARD_HAS_STM32F),
|
||||
BUTTONS_MB951A,
|
||||
LEDS_MB951A,
|
||||
&ioMB951A,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
const BoardResourcesType IDZ401V1 = {
|
||||
"IDZ401V1",
|
||||
(BOARD_HAS_STM32F),
|
||||
BUTTONS_IDZ401V1,
|
||||
LEDS_IDZ401V1,
|
||||
&ioIDZ401V1,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const BoardResourcesType *boardList [] = {
|
||||
&MB851A,
|
||||
&MB851B,
|
||||
&MB851C,
|
||||
&MB851D,
|
||||
&MB954A,
|
||||
&MB954B,
|
||||
&MB954C,
|
||||
&MB950A,
|
||||
&MB951A,
|
||||
&IDZ401V1
|
||||
};
|
||||
|
||||
BoardResourcesType const *boardDescription = NULL;
|
||||
|
||||
#define PORT_NAME(x) ((x == PORTA) ? "A": ((x == PORTB) ? "B" : ((x == PORTC) ? "C": "?")))
|
||||
|
||||
void halBoardInit(void)
|
||||
{
|
||||
char boardName[16];
|
||||
int8_t i;
|
||||
boardDescription = NULL;
|
||||
#ifdef EMBERZNET_HAL
|
||||
halCommonGetToken(boardName, TOKEN_MFG_BOARD_NAME);
|
||||
#else
|
||||
halCommonGetMfgToken(boardName, TOKEN_MFG_BOARD_NAME);
|
||||
#endif
|
||||
|
||||
i = 15;
|
||||
while ((i >= 0) && (boardName[i] == 0xFF)) {
|
||||
boardName[i] = 0;
|
||||
i--;
|
||||
}
|
||||
|
||||
for (i = 0; i < (sizeof(boardList)/4) ; i++)
|
||||
if (strcmp(boardName, (boardList[i])->name) == 0) {
|
||||
boardDescription = (BoardResourcesType *) boardList[i];
|
||||
break;
|
||||
}
|
||||
|
||||
if (boardDescription == NULL) {
|
||||
/* Board type not identified default to MB851A also to support legacy boards */
|
||||
boardDescription = (BoardResourcesType *) &IDZ401V1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BoardResourcesType const *halBoardGetDescription(void)
|
||||
{
|
||||
return boardDescription;
|
||||
}
|
||||
|
||||
void halBoardPowerDown(void)
|
||||
{
|
||||
/* Set everything to input value */
|
||||
GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA3_CFG_BIT);
|
||||
GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)| /* PTI EN */
|
||||
(GPIOCFG_IN <<PA5_CFG_BIT)| /* PTI_DATA */
|
||||
(GPIOCFG_IN <<PA6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA7_CFG_BIT);
|
||||
GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB1_CFG_BIT)| /* Uart TX */
|
||||
(GPIOCFG_IN <<PB2_CFG_BIT)| /* Uart RX */
|
||||
(GPIOCFG_IN <<PB3_CFG_BIT);
|
||||
GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB5_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB7_CFG_BIT);
|
||||
GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC3_CFG_BIT);
|
||||
GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC5_CFG_BIT)|
|
||||
#ifdef EMBERZNET_HAL
|
||||
(CFG_C6 <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(CFG_C7 <<PC7_CFG_BIT); /* OSC32K */
|
||||
#else
|
||||
(GPIOCFG_IN <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
|
||||
#endif
|
||||
|
||||
|
||||
/* Configure GPIO for BUTTONSs */
|
||||
{
|
||||
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
|
||||
uint8_t i;
|
||||
for (i = 0; i < boardDescription->buttons; i++) {
|
||||
halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
|
||||
halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure GPIO for LEDs */
|
||||
{
|
||||
LedResourceType *leds = (LedResourceType *) boardDescription->io->leds;
|
||||
uint8_t i;
|
||||
for (i = 0; i < boardDescription->leds; i++) {
|
||||
/* LED default off */
|
||||
halGpioConfig(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), GPIOCFG_OUT);
|
||||
halGpioSet(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure GPIO for power amplifier */
|
||||
if (boardDescription->flags & BOARD_HAS_PA) {
|
||||
/* SiGe Ant Sel to output */
|
||||
halGpioConfig(PORTB_PIN(5), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(5), 1);
|
||||
/* SiGe Standby */
|
||||
halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(6), 0);
|
||||
}
|
||||
|
||||
}
|
||||
void halBoardPowerUp(void)
|
||||
{
|
||||
|
||||
/* Set everything to input value */
|
||||
GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA3_CFG_BIT);
|
||||
GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)| /* PTI EN */
|
||||
(GPIOCFG_IN <<PA5_CFG_BIT)| /* PTI_DATA */
|
||||
(GPIOCFG_IN <<PA6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PA7_CFG_BIT);
|
||||
GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
|
||||
(GPIOCFG_OUT_ALT <<PB1_CFG_BIT)| /* Uart TX */
|
||||
(GPIOCFG_IN <<PB2_CFG_BIT)| /* Uart RX */
|
||||
(GPIOCFG_IN <<PB3_CFG_BIT);
|
||||
GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB5_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB6_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PB7_CFG_BIT);
|
||||
GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC1_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC2_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC3_CFG_BIT);
|
||||
GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
|
||||
(GPIOCFG_IN <<PC5_CFG_BIT)|
|
||||
#ifdef EMBERZNET_HAL
|
||||
(CFG_C6 <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(CFG_C7 <<PC7_CFG_BIT); /* OSC32K */
|
||||
#else
|
||||
(GPIOCFG_IN <<PC6_CFG_BIT)| /* OSC32K */
|
||||
(GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
|
||||
#endif
|
||||
|
||||
/* Configure GPIO for I2C access */
|
||||
if ((boardDescription->flags & BOARD_HAS_MEMS) || (boardDescription->flags & BOARD_HAS_EEPROM)) {
|
||||
halGpioConfig(PORTA_PIN(1), GPIOCFG_OUT_ALT_OD);
|
||||
halGpioConfig(PORTA_PIN(2), GPIOCFG_OUT_ALT_OD);
|
||||
}
|
||||
/* Configure GPIO for ADC access (temp sensor) */
|
||||
if (boardDescription->flags & BOARD_HAS_TEMP_SENSOR) {
|
||||
halGpioConfig(PORTx_PIN(boardDescription->temperatureSensor->gpioPort,
|
||||
boardDescription->temperatureSensor->gpioPin),
|
||||
GPIOCFG_ANALOG);
|
||||
}
|
||||
/* Configure GPIO for LEDs */
|
||||
{
|
||||
LedResourceType *leds = (LedResourceType *) boardDescription->io->leds;
|
||||
uint8_t i;
|
||||
for (i = 0; i < boardDescription->leds; i++) {
|
||||
/* LED default off */
|
||||
halGpioConfig(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), GPIOCFG_OUT);
|
||||
halGpioSet(PORTx_PIN(leds[i].gpioPort, leds[i].gpioPin), 1);
|
||||
}
|
||||
}
|
||||
/* Configure GPIO for BUTTONSs */
|
||||
{
|
||||
ButtonResourceType *buttons = (ButtonResourceType *) boardDescription->io->buttons;
|
||||
uint8_t i;
|
||||
for (i = 0; i < boardDescription->buttons; i++) {
|
||||
halGpioConfig(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOCFG_IN_PUD);
|
||||
halGpioSet(PORTx_PIN(buttons[i].gpioPort, buttons[i].gpioPin), GPIOOUT_PULLUP);
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure GPIO for power amplifier */
|
||||
if (boardDescription->flags & BOARD_HAS_PA) {
|
||||
/* SiGe Ant Sel (default ceramic antenna) */
|
||||
halGpioConfig(PORTB_PIN(5), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(5), 1);
|
||||
/* SiGe Standby (default out of standby) */
|
||||
halGpioConfig(PORTB_PIN(6), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(6), 1);
|
||||
/* SiGe LNA (default LNA off )*/
|
||||
halGpioConfig(PORTB_PIN(7), GPIOCFG_OUT);
|
||||
halGpioSet(PORTB_PIN(7), 0);
|
||||
/* SiGe nTX Active */
|
||||
halGpioConfig(PORTC_PIN(5), GPIOCFG_OUT_ALT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
void printLeds (void)
|
||||
{
|
||||
uint8_t i=0;
|
||||
LedResourceType *leds;
|
||||
leds = (LedResourceType *) boardDescription->io->leds;
|
||||
while (i < boardDescription->leds) {
|
||||
printf ("Led %s (port:%s, bit:%d)\r\n", leds->name, PORT_NAME(leds->gpioPort), leds->gpioPin);
|
||||
leds++; i++;
|
||||
}
|
||||
}
|
||||
|
||||
void printButtons (void)
|
||||
{
|
||||
uint8_t i=0;
|
||||
ButtonResourceType *buttons;
|
||||
buttons = (ButtonResourceType *) boardDescription->io->buttons;
|
||||
while (i < boardDescription->buttons) {
|
||||
printf ("Button %s (port:%s, bit:%d)\r\n", buttons->name, PORT_NAME(buttons->gpioPort), buttons->gpioPin);
|
||||
buttons++; i++;
|
||||
}
|
||||
}
|
||||
|
||||
void boardPrintStringDescription(void)
|
||||
{
|
||||
|
||||
if (boardDescription != NULL) {
|
||||
printf ("*************************************\r\n");
|
||||
printf ("Board name = %s\r\n", boardDescription->name);
|
||||
printf ("*************************************\r\n");
|
||||
printf("Number of leds on the board: %d\n", boardDescription->leds);
|
||||
printf("Number of buttons on the board: %d\n", boardDescription->buttons);
|
||||
printLeds();
|
||||
printButtons();
|
||||
if (boardDescription->mems) {
|
||||
printf ("MEMS = %s\r\n", boardDescription->mems->name);
|
||||
}
|
||||
if (boardDescription->temperatureSensor) {
|
||||
printf ("Temp sensor = %s, port:%s, pin:%d, div:%d, adcFix:%s\r\n",
|
||||
boardDescription->temperatureSensor->name,
|
||||
PORT_NAME(boardDescription->temperatureSensor->gpioPort),
|
||||
boardDescription->temperatureSensor->gpioPin,
|
||||
boardDescription->temperatureSensor->div,
|
||||
boardDescription->temperatureSensor->adcFix ? "Yes" : "No"
|
||||
);
|
||||
}
|
||||
|
||||
printf ("EEProm:%s\r\n", (boardDescription->flags & BOARD_HAS_EEPROM) ? "Yes" : "No");
|
||||
printf ("PC i/f:%s\r\n", (boardDescription->flags & BOARD_HAS_FTDI) ? "FTDI" : "STM32F");
|
||||
printf ("Power Amplifier:%s\r\n", (boardDescription->flags & BOARD_HAS_PA) ? "Yes" : "No");
|
||||
|
||||
}
|
||||
}
|
||||
/** @} */
|
354
platform/mbxxx/board.h
Normal file
354
platform/mbxxx/board.h
Normal file
|
@ -0,0 +1,354 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Header file x STM32W108 Kits boards abstraction.
|
||||
* \brief
|
||||
* Header file x STM32W108 Kits boards abstraction.
|
||||
* See \ref board for documentation.
|
||||
*
|
||||
*
|
||||
* See hal/micro/cortexm3/stm32w108/board.h for source code.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
char boardName[16];
|
||||
|
||||
/** @addtogroup board
|
||||
* \brief ST board abstraction layer
|
||||
*
|
||||
* This header defines API and data structures to handle ST boards with thei associated resources
|
||||
* on algorithm behavior.
|
||||
* See hal/micro/cortexm3/stm32w108/board.h for source code.
|
||||
*@{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851A 2
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851B 2
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851C 2
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB851D 2
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB954A 2
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB954B 2
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB954C 2
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB950A 2
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_MB951A 2
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of LEDs in the specific board revision
|
||||
*/
|
||||
#define LEDS_IDZ401V1 1
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851A 1
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851B 1
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851C 1
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB851D 1
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB954A 1
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB954B 1
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB954C 1
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB950A 5
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_MB951A 1
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Define the number of user buttons in the specific board revision
|
||||
*/
|
||||
#define BUTTONS_IDZ401V1 0
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Data structure for led description
|
||||
*/
|
||||
typedef struct LedResourceStruct {
|
||||
/** Name of the LED as printed in the board */
|
||||
char *name;
|
||||
/** GPIO port associated with the LED */
|
||||
uint8_t gpioPort;
|
||||
/** GPIO pin associated with the LED */
|
||||
uint8_t gpioPin;
|
||||
} LedResourceType;
|
||||
|
||||
typedef LedResourceType InfraRedLedResourceType;
|
||||
|
||||
/**
|
||||
* \brief Data structure for button description
|
||||
*/
|
||||
typedef struct ButtonResourceStruct {
|
||||
/** Name of the button as printed in the board */
|
||||
char *name;
|
||||
/** GPIO port associated with the button */
|
||||
uint8_t gpioPort;
|
||||
/** GPIO pin associated with the button */
|
||||
uint8_t gpioPin;
|
||||
} ButtonResourceType;
|
||||
|
||||
/**
|
||||
* \brief Data structure for MEMS description
|
||||
*/
|
||||
typedef struct MemsResourceStruct {
|
||||
/** Name of the MEMS device */
|
||||
char *name;
|
||||
/** Serial communication port associated with the MEMS */
|
||||
uint8_t scPort;
|
||||
} MemsResourceType;
|
||||
|
||||
/**
|
||||
* \brief Data structure for temperature sensor description
|
||||
*/
|
||||
typedef struct TempSensorResourceStruct {
|
||||
/** Name of the temperature sensor device */
|
||||
char *name;
|
||||
/** GPIO port associated with the sensor */
|
||||
uint8_t gpioPort;
|
||||
/** GPIO pin associated with the sensor */
|
||||
uint8_t gpioPin;
|
||||
/** Voltage divider network from sensor vout and GPIO */
|
||||
uint8_t div;
|
||||
/** Flag to indicate whether the ADC range extension bug fix is implemented */
|
||||
boolean adcFix;
|
||||
} TempSensorResourceType;
|
||||
|
||||
/**
|
||||
* \brief Data structure for board user I/O
|
||||
*/
|
||||
typedef struct BoardIOStruct {
|
||||
/** Pointer to LED resources */
|
||||
const LedResourceType *leds;
|
||||
/** Pointer to button resources */
|
||||
const ButtonResourceType *buttons;
|
||||
} BoardIOType;
|
||||
|
||||
/**
|
||||
* \brief Flag to indicate if MEMS is present
|
||||
*/
|
||||
#define BOARD_HAS_MEMS (1 << 0)
|
||||
/**
|
||||
* \brief Flag to indicate if temeprature sensor is present
|
||||
*/
|
||||
#define BOARD_HAS_TEMP_SENSOR (1 << 1)
|
||||
/**
|
||||
* \brief Flag to indicate if external power amplifier is present
|
||||
*/
|
||||
#define BOARD_HAS_PA (1 << 2)
|
||||
/**
|
||||
* \brief Flag to indicate if EEPROM is present
|
||||
*/
|
||||
#define BOARD_HAS_EEPROM (1 << 3)
|
||||
/**
|
||||
* \brief Flag to indicate if FTDI is used as PC interface
|
||||
*/
|
||||
#define BOARD_HAS_FTDI (1 << 4)
|
||||
/**
|
||||
* \brief Flag to indicate if STM32F is used as PC interface
|
||||
*/
|
||||
#define BOARD_HAS_STM32F (1 << 5)
|
||||
|
||||
/**
|
||||
* \brief Data structure describing board features
|
||||
*/
|
||||
typedef struct BoardResourcesStruct {
|
||||
const char *name;
|
||||
const uint32_t flags;
|
||||
/** Number of buttons */
|
||||
uint8_t buttons;
|
||||
/** Number of leds */
|
||||
uint8_t leds;
|
||||
/** Board I/O description */
|
||||
const BoardIOType *io;
|
||||
/** Board infrared led description */
|
||||
const InfraRedLedResourceType* infraredLed;
|
||||
/** Board infrared MEMS description */
|
||||
const MemsResourceType *mems;
|
||||
/** Board infrared temeprature sensor description */
|
||||
const TempSensorResourceType *temperatureSensor;
|
||||
} BoardResourcesType;
|
||||
|
||||
extern BoardResourcesType const *boardDescription;
|
||||
|
||||
// Generic definitions
|
||||
#define GPIO_PxCLR_BASE (GPIO_PACLR_ADDR)
|
||||
#define GPIO_PxSET_BASE (GPIO_PASET_ADDR)
|
||||
#define GPIO_PxOUT_BASE (GPIO_PAOUT_ADDR)
|
||||
#define GPIO_PxIN_BASE (GPIO_PAIN_ADDR)
|
||||
// Each port is offset from the previous port by the same amount
|
||||
#define GPIO_Px_OFFSET (GPIO_PBCFGL_ADDR-GPIO_PACFGL_ADDR)
|
||||
|
||||
|
||||
/* leds definitions */
|
||||
#define LED_D1 PORTx_PIN(boardDescription->io->leds[0].gpioPort, boardDescription->io->leds[0].gpioPin) //PORTB_PIN(6)
|
||||
#define LED_D3 PORTx_PIN(boardDescription->io->leds[1].gpioPort, boardDescription->io->leds[1].gpioPin) // PORTB_PIN(5)
|
||||
#define DUMMY_LED 0xff
|
||||
|
||||
|
||||
/** Description buttons definition */
|
||||
#define BUTTON_Sn(n) (PORTx_PIN(boardDescription->io->buttons[n].gpioPort, boardDescription->io->buttons[n].gpioPin))
|
||||
#define BUTTON_Sn_WAKE_SOURCE(n) (1 << ((boardDescription->io->buttons[n].gpioPin) + (8 * (boardDescription->io->buttons[n].gpioPort >> 3))))
|
||||
#define BUTTON_INPUT_GPIO(port) *((volatile uint32_t *) (GPIO_PxIN_BASE + GPIO_Px_OFFSET * port))
|
||||
#define DUMMY_BUTTON 0xff
|
||||
|
||||
#define BUTTON_S1 (boardDescription->buttons>0 ? BUTTON_Sn(0): DUMMY_BUTTON)
|
||||
#define BUTTON_S2 (boardDescription->buttons>1 ? BUTTON_Sn(1): DUMMY_BUTTON)
|
||||
#define BUTTON_S3 (boardDescription->buttons>2 ? BUTTON_Sn(2): DUMMY_BUTTON)
|
||||
#define BUTTON_S4 (boardDescription->buttons>3 ? BUTTON_Sn(3): DUMMY_BUTTON)
|
||||
#define BUTTON_S5 (boardDescription->buttons>4 ? BUTTON_Sn(4): DUMMY_BUTTON)
|
||||
|
||||
#define BUTTON_S1_WAKE_SOURCE (boardDescription->buttons>0 ? BUTTON_Sn_WAKE_SOURCE(0): 0)
|
||||
#define BUTTON_S2_WAKE_SOURCE (boardDescription->buttons>1 ? BUTTON_Sn_WAKE_SOURCE(1): 0)
|
||||
#define BUTTON_S3_WAKE_SOURCE (boardDescription->buttons>2 ? BUTTON_Sn_WAKE_SOURCE(2): 0)
|
||||
#define BUTTON_S4_WAKE_SOURCE (boardDescription->buttons>3 ? BUTTON_Sn_WAKE_SOURCE(3): 0)
|
||||
#define BUTTON_S5_WAKE_SOURCE (boardDescription->buttons>4 ? BUTTON_Sn_WAKE_SOURCE(4): 0)
|
||||
|
||||
/** Description uart definition */
|
||||
#define UART_TX PORTB_PIN(1)
|
||||
#define UART_RX PORTB_PIN(2)
|
||||
#define UART_RX_WAKE_SOURCE 0x00000400
|
||||
|
||||
/** Description temperature sensor GPIO */
|
||||
#define TEMPERATURE_SENSOR_GPIO PORTx_PIN(boardDescription->temperatureSensor->gpioPort, boardDescription->temperatureSensor->gpioPin) // PORTB_PIN(7)
|
||||
|
||||
/** \brief Return pointer to board description structure
|
||||
*
|
||||
*
|
||||
* @return Pointer to board description structure
|
||||
*/
|
||||
BoardResourcesType const *halBoardGetDescription(void);
|
||||
/**
|
||||
* \brief Initialize the board description data structure after
|
||||
* autodetect of the boards based on the CIB Board name field
|
||||
* content. In case of invalid CIB data it will default to MB851A.
|
||||
* Customer normally needs to modify this file to adapt it to their specific board.
|
||||
*/
|
||||
void halBoardInit(void);
|
||||
/**
|
||||
* \brief Perform board specific action to power up the system.
|
||||
* This code depends on the actual board features and configure
|
||||
* the stm32w and on board devices for proper operation.
|
||||
* Customer normally needs to modify this file to adapt it to their specific board.
|
||||
*/
|
||||
void halBoardPowerUp(void);
|
||||
/**
|
||||
* \brief Perform board specific action to power down the system, usually before going to deep sleep.
|
||||
* This code depends on the actual board features and configure
|
||||
* the stm32w and on board devices for minimal power consumption.
|
||||
* Customer normally needs to modify this file to adapt it to their specific board.
|
||||
*/
|
||||
void halBoardPowerDown(void);
|
||||
|
||||
|
||||
void boardPrintStringDescription(void);
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
|
||||
/** @} // END addtogroup
|
||||
*/
|
||||
/** @} */
|
|
@ -1,191 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Clock for STM32W.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* File customized for mbxxx platform. It uses systick timer to control button
|
||||
* status without interrupts, as well as for system clock.
|
||||
*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include "hal/error.h"
|
||||
#include "hal/hal.h"
|
||||
#include "dev/stm32w_systick.h"
|
||||
|
||||
#include "sys/clock.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "uart1.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/stm32w-radio.h"
|
||||
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/uip-debug.h"
|
||||
|
||||
// The value that will be load in the SysTick value register.
|
||||
#define RELOAD_VALUE 24000-1 // 1 ms with a 24 MHz clock
|
||||
|
||||
static volatile clock_time_t count;
|
||||
static volatile unsigned long current_seconds = 0;
|
||||
static unsigned int second_countdown = CLOCK_SECOND;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
|
||||
count++;
|
||||
|
||||
if(button_sensor.status(SENSORS_READY)){
|
||||
button_sensor.value(0); // sensors_changed is called inside this function.
|
||||
}
|
||||
|
||||
if(etimer_pending()) {
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
if (--second_countdown == 0) {
|
||||
current_seconds++;
|
||||
second_countdown = CLOCK_SECOND;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void clock_init(void)
|
||||
{
|
||||
|
||||
ATOMIC(
|
||||
|
||||
//Counts the number of ticks.
|
||||
count = 0;
|
||||
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
||||
SysTick_SetReload(RELOAD_VALUE);
|
||||
SysTick_ITConfig(ENABLE);
|
||||
SysTick_CounterCmd(SysTick_Counter_Enable);
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
clock_time_t clock_time(void)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Delay the CPU for a multiple of TODO
|
||||
*/
|
||||
void clock_delay(unsigned int i)
|
||||
{
|
||||
for (; i > 0; i--) { /* Needs fixing XXX */
|
||||
unsigned j;
|
||||
for (j = 50; j > 0; j--)
|
||||
asm ("nop");
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Wait for a multiple of 1 ms.
|
||||
*
|
||||
*/
|
||||
void clock_wait(clock_time_t i)
|
||||
{
|
||||
clock_time_t start;
|
||||
|
||||
start = clock_time();
|
||||
while(clock_time() - start < (clock_time_t)i);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
unsigned long clock_seconds(void)
|
||||
{
|
||||
return current_seconds;
|
||||
}
|
||||
|
||||
void sleep_seconds(int seconds)
|
||||
{
|
||||
int32u quarter_seconds = seconds * 4;
|
||||
uint8_t radio_on;
|
||||
|
||||
|
||||
halPowerDown();
|
||||
radio_on = stm32w_radio_is_on();
|
||||
stm32w_radio_driver.off();
|
||||
|
||||
halSleepForQsWithOptions(&quarter_seconds, 0);
|
||||
|
||||
|
||||
ATOMIC(
|
||||
|
||||
halPowerUp();
|
||||
|
||||
// Update OS system ticks.
|
||||
current_seconds += seconds - quarter_seconds / 4 ; // Passed seconds
|
||||
count += seconds * CLOCK_SECOND - quarter_seconds * CLOCK_SECOND / 4 ;
|
||||
|
||||
if(etimer_pending()) {
|
||||
etimer_request_poll();
|
||||
}
|
||||
|
||||
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
|
||||
SysTick_SetReload(RELOAD_VALUE);
|
||||
SysTick_ITConfig(ENABLE);
|
||||
SysTick_CounterCmd(SysTick_Counter_Enable);
|
||||
|
||||
)
|
||||
|
||||
stm32w_radio_driver.init();
|
||||
if(radio_on){
|
||||
stm32w_radio_driver.on();
|
||||
}
|
||||
|
||||
uart1_init(115200);
|
||||
leds_init();
|
||||
rtimer_init();
|
||||
|
||||
PRINTF("WakeInfo: %04x\r\n", halGetWakeInfo());
|
||||
|
||||
|
||||
}
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -33,7 +38,7 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* contiki-conf.h for MBXXX.
|
||||
* Contiki-conf.h for MBXXX.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
* Chi-Anh La <la@imag.fr>
|
||||
|
@ -41,6 +46,8 @@
|
|||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
|
||||
|
@ -77,8 +84,10 @@
|
|||
#define WITH_ACK_OPTIMIZATION 0
|
||||
|
||||
/* Netstack config */
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_CONF_RDC contikimac_driver
|
||||
//#define NETSTACK_CONF_MAC csma_driver
|
||||
//#define NETSTACK_CONF_RDC contikimac_driver
|
||||
#define NETSTACK_CONF_MAC nullmac_driver
|
||||
#define NETSTACK_CONF_RDC sicslowmac_driver
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#define NETSTACK_CONF_RADIO stm32w_radio_driver
|
||||
|
||||
|
@ -100,7 +109,7 @@
|
|||
#define QUEUEBUF_CONF_NUM 2
|
||||
#define QUEUEBUF_CONF_REF_NUM 0
|
||||
#define UIP_CONF_DS6_NBR_NBU 4
|
||||
#define UIP_CONF_MAX_ROUTES 4
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 4
|
||||
#define RPL_CONF_MAX_PARENTS_PER_DAG 4
|
||||
#define RPL_CONF_MAX_INSTANCES 1
|
||||
#define RPL_CONF_MAX_DAG_PER_INSTANCE 1
|
||||
|
@ -118,6 +127,14 @@
|
|||
#define SICSLOWPAN_CONF_COMPRESSION_THRESHOLD 63
|
||||
#define CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER 0
|
||||
|
||||
#define UIP_CONF_UDP 1
|
||||
|
||||
#if (WITH_COAP==7) || (WITH_COAP==6) || (WITH_COAP==3)
|
||||
#define UIP_CONF_TCP 0
|
||||
#else
|
||||
#define UIP_CONF_TCP 1
|
||||
#endif /* WITH_COAP */
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
#define UIP_CONF_IPV6_RPL 1
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
|
@ -158,3 +175,4 @@
|
|||
#endif /* PROJECT_CONF_H */
|
||||
|
||||
#endif /* __CONTIKI_CONF_H__ */
|
||||
/** @} */
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -33,14 +32,17 @@
|
|||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Functions for net initialization.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "contiki-net.h"
|
||||
|
||||
|
@ -57,80 +59,82 @@
|
|||
#define PRINT6ADDR(addr)
|
||||
#define PRINTLLADDR(addr)
|
||||
#endif
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
print_address(uip_ds6_addr_t * lladdr)
|
||||
|
||||
void print_address(uip_ds6_addr_t *lladdr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
|
||||
lladdr->ipaddr.u8[i * 2 + 1]);
|
||||
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2], lladdr->ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
print_addresses(void)
|
||||
void print_addresses(void)
|
||||
{
|
||||
uip_ds6_addr_t *lladdr;
|
||||
|
||||
|
||||
printf("link-local IPv6 address: ");
|
||||
|
||||
lladdr = uip_ds6_get_link_local(-1);
|
||||
if(lladdr != NULL) {
|
||||
if(lladdr != NULL){
|
||||
print_address(lladdr);
|
||||
printf("\r\n");
|
||||
} else {
|
||||
printf("None\r\n");
|
||||
}
|
||||
else
|
||||
printf("None\r\n");
|
||||
|
||||
printf("global IPv6 address: ");
|
||||
|
||||
lladdr = uip_ds6_get_global(-1);
|
||||
if(lladdr != NULL) {
|
||||
if(lladdr != NULL){
|
||||
print_address(lladdr);
|
||||
printf("\r\n");
|
||||
} else {
|
||||
printf("None\r\n");
|
||||
}
|
||||
else
|
||||
printf("None\r\n");
|
||||
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#if FIXED_NET_ADDRESS
|
||||
|
||||
#include "net/rpl/rpl.h"
|
||||
void
|
||||
set_net_address(void)
|
||||
|
||||
void set_net_address(void)
|
||||
{
|
||||
uip_ipaddr_t ipaddr;
|
||||
|
||||
#if RPL_BORDER_ROUTER
|
||||
rpl_dag_t *dag;
|
||||
#endif
|
||||
|
||||
uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D, 0, 0,
|
||||
0, 0);
|
||||
uip_ip6addr(&ipaddr, NET_ADDR_A, NET_ADDR_B, NET_ADDR_C, NET_ADDR_D, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
||||
|
||||
|
||||
/* #if !UIP_CONF_ROUTER */
|
||||
/* uip_ds6_prefix_add(&ipaddr, 64, 0); For on-link determination. */
|
||||
/* #else */
|
||||
/* uip_ds6_prefix_add(&ipaddr, 64, 0, 0, 600, 600); */
|
||||
/* #endif */
|
||||
//#if !UIP_CONF_ROUTER
|
||||
// uip_ds6_prefix_add(&ipaddr, 64, 0); // For on-link determination.
|
||||
//#else
|
||||
// uip_ds6_prefix_add(&ipaddr, 64, 0, 0, 600, 600);
|
||||
//#endif
|
||||
|
||||
print_addresses();
|
||||
|
||||
#if RPL_BORDER_ROUTER
|
||||
dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr);
|
||||
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,&ipaddr);
|
||||
if(dag != NULL) {
|
||||
PRINTF("This node is setted as root of a DAG.\r\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
PRINTF("Error while setting this node as root of a DAG.\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif /* FIXED_GLOBAL_ADDRESS */
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
/** @} */
|
|
@ -1,9 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -33,7 +32,17 @@
|
|||
* 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
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Functions for net initialization.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __CONTIKI_INIT_NET_H__
|
||||
#define __CONTIKI_INIT_NET_H__
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -57,6 +62,7 @@
|
|||
#include "dev/button-sensor.h"
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/acc-sensor.h"
|
||||
#include "dev/contact-sensor.h"
|
||||
#include "dev/uart1.h"
|
||||
#include "dev/serial-line.h"
|
||||
|
||||
|
@ -66,6 +72,11 @@
|
|||
#include "net/rime.h"
|
||||
#include "net/rime/rime-udp.h"
|
||||
#include "net/uip.h"
|
||||
|
||||
#if WITH_UIP6
|
||||
#include "net/uip-ds6.h"
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
|
@ -86,7 +97,11 @@ PROCINIT(&sensors_process);
|
|||
#warning "No TCP/IP process!"
|
||||
#endif
|
||||
|
||||
SENSORS(&button_sensor,&temperature_sensor,&acc_sensor);
|
||||
SENSORS(&button_sensor, &temperature_sensor, &acc_sensor, &contact_sensor);
|
||||
|
||||
/* The default CCA threshold is set to -77, which is the same as the
|
||||
default setting on the TI CC2420. */
|
||||
#define DEFAULT_RADIO_CCA_THRESHOLD -77
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -95,14 +110,14 @@ set_rime_addr(void)
|
|||
int i;
|
||||
union {
|
||||
uint8_t u8[8];
|
||||
}eui64;
|
||||
} eui64;
|
||||
|
||||
//rimeaddr_t lladdr;
|
||||
|
||||
int8u *stm32w_eui64 = ST_RadioGetEui64();
|
||||
uint8_t *stm32w_eui64 = ST_RadioGetEui64();
|
||||
{
|
||||
int8u c;
|
||||
for(c = 0; c < 8; c++) { // Copy the EUI-64 to lladdr converting from Little-Endian to Big-Endian.
|
||||
uint8_t c;
|
||||
/* Copy the EUI-64 to lladdr converting from Little-Endian to
|
||||
Big-Endian. */
|
||||
for(c = 0; c < 8; c++) {
|
||||
eui64.u8[c] = stm32w_eui64[7 - c];
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +129,7 @@ set_rime_addr(void)
|
|||
#if UIP_CONF_IPV6
|
||||
rimeaddr_set_node_addr((rimeaddr_t *)&eui64);
|
||||
#else
|
||||
rimeaddr_set_node_addr((rimeaddr_t *)&eui64.u8[8-RIMEADDR_SIZE]);
|
||||
rimeaddr_set_node_addr((rimeaddr_t *)&eui64.u8[8 - RIMEADDR_SIZE]);
|
||||
#endif
|
||||
|
||||
printf("Rime started with address ");
|
||||
|
@ -122,7 +137,6 @@ set_rime_addr(void)
|
|||
printf("%d.", rimeaddr_node_addr.u8[i]);
|
||||
}
|
||||
printf("%d\n", rimeaddr_node_addr.u8[i]);
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
|
@ -130,21 +144,24 @@ main(void)
|
|||
{
|
||||
|
||||
/*
|
||||
* Initialize hardware.
|
||||
* Initalize hardware.
|
||||
*/
|
||||
halInit();
|
||||
clock_init();
|
||||
|
||||
uart1_init(115200);
|
||||
|
||||
// Led initialization
|
||||
/* Led initialization */
|
||||
leds_init();
|
||||
|
||||
INTERRUPTS_ON();
|
||||
|
||||
PRINTF("\r\nStarting ");
|
||||
PRINTF(CONTIKI_VERSION_STRING);
|
||||
PRINTF(" on %s\r\n",boardDescription->name);
|
||||
PRINTF(" on %s\r\n", boardDescription->name);
|
||||
boardPrintStringDescription();
|
||||
PRINTF("\r\n");
|
||||
|
||||
|
||||
/*
|
||||
* Initialize Contiki and our processes.
|
||||
|
@ -156,14 +173,15 @@ main(void)
|
|||
uart1_set_input(serial_line_input_byte);
|
||||
serial_line_init();
|
||||
#endif
|
||||
/* rtimer and ctimer should be initialized before radio duty cycling layers*/
|
||||
/* rtimer and ctimer should be initialized before radio duty cycling
|
||||
layers */
|
||||
rtimer_init();
|
||||
/* etimer_process should be initialized before ctimer */
|
||||
process_start(&etimer_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
rtimer_init();
|
||||
netstack_init();
|
||||
|
||||
set_rime_addr();
|
||||
|
||||
printf("%s %s, channel check rate %lu Hz\n",
|
||||
|
@ -180,11 +198,49 @@ main(void)
|
|||
energest_init();
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
|
||||
/* Set the Clear Channel Assessment (CCA) threshold of the
|
||||
radio. The CCA threshold is used both for sending packets and for
|
||||
waking up ContikiMAC nodes. If the CCA threshold is too high,
|
||||
ContikiMAC will not wake up from neighbor transmissions. If the
|
||||
CCA threshold is too low, transmissions will be too restrictive
|
||||
and no packets will be sent. DEFAULT_RADIO_CCA_THRESHOLD is
|
||||
defined in this file. */
|
||||
ST_RadioSetEdCcaThreshold(DEFAULT_RADIO_CCA_THRESHOLD);
|
||||
|
||||
autostart_start(autostart_processes);
|
||||
#if UIP_CONF_IPV6
|
||||
printf("Tentative link-local IPv6 address ");
|
||||
{
|
||||
uip_ds6_addr_t *lladdr;
|
||||
int i;
|
||||
lladdr = uip_ds6_get_link_local(-1);
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
|
||||
lladdr->ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
||||
}
|
||||
|
||||
|
||||
if(!UIP_CONF_IPV6_RPL) {
|
||||
uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
||||
printf("Tentative global IPv6 address ");
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:",
|
||||
ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x\n",
|
||||
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
||||
}
|
||||
#endif /* UIP_CONF_IPV6 */
|
||||
|
||||
watchdog_start();
|
||||
|
||||
while(1){
|
||||
while(1) {
|
||||
|
||||
int r;
|
||||
|
||||
|
@ -197,12 +253,12 @@ main(void)
|
|||
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_CPU);
|
||||
//watchdog_stop();
|
||||
/* watchdog_stop(); */
|
||||
ENERGEST_ON(ENERGEST_TYPE_LPM);
|
||||
/* Go to idle mode. */
|
||||
halSleepWithOptions(SLEEPMODE_IDLE,0);
|
||||
/* We are awake. */
|
||||
//watchdog_start();
|
||||
/* watchdog_start(); */
|
||||
ENERGEST_OFF(ENERGEST_TYPE_LPM);
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
|
||||
|
@ -212,7 +268,7 @@ main(void)
|
|||
|
||||
|
||||
|
||||
/*int8u errcode __attribute__(( section(".noinit") ));
|
||||
/*uint8_t errcode __attribute__(( section(".noinit") ));
|
||||
|
||||
void halBaseBandIsr(){
|
||||
|
||||
|
@ -257,11 +313,12 @@ void UsageFault_Handler(){
|
|||
errcode = 7;
|
||||
//leds_on(LEDS_RED);
|
||||
//halReboot();
|
||||
}*/
|
||||
}
|
||||
|
||||
void Default_Handler()
|
||||
{
|
||||
//errcode = 8;
|
||||
leds_on(LEDS_RED);
|
||||
halReboot();
|
||||
}
|
||||
}*/
|
||||
/** @} */
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -51,7 +56,7 @@
|
|||
static int
|
||||
active(void)
|
||||
{
|
||||
int8u reg;
|
||||
uint8_t reg;
|
||||
if(!i2c_read_reg (kLIS3L02DQ_SLAVE_ADDR,CTRL_REG1, ®, 1))
|
||||
return FALSE;
|
||||
|
||||
|
@ -62,8 +67,8 @@ static int
|
|||
value(int type)
|
||||
{
|
||||
|
||||
int8s i2c_data = 0;
|
||||
int8u reg_addr;
|
||||
int8_t i2c_data = 0;
|
||||
uint8_t reg_addr;
|
||||
|
||||
switch(type) {
|
||||
case ACC_X_AXIS:
|
||||
|
@ -82,13 +87,13 @@ value(int type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
i2c_read_reg(kLIS3L02DQ_SLAVE_ADDR, reg_addr, (int8u *)&i2c_data, 1);
|
||||
i2c_read_reg(kLIS3L02DQ_SLAVE_ADDR, reg_addr, (uint8_t *)&i2c_data, 1);
|
||||
|
||||
if(MEMS_GetFullScale()==ACC_HIGH_RANGE){
|
||||
return ((int16s)i2c_data)*HIGH_RANGE_SENSITIVITY;
|
||||
return ((int16_t)i2c_data)*HIGH_RANGE_SENSITIVITY;
|
||||
}
|
||||
else {
|
||||
return ((int16s)i2c_data)*LOW_RANGE_SENSITIVITY;
|
||||
return ((int16_t)i2c_data)*LOW_RANGE_SENSITIVITY;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,7 +122,7 @@ configure(int type, int value)
|
|||
|
||||
case ACC_HPF:
|
||||
if(value < ACC_HPF_DISABLE){
|
||||
return i2c_write_reg(kLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, (1<<4) | (int8u)value);
|
||||
return i2c_write_reg(kLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, (1<<4) | (uint8_t)value);
|
||||
}
|
||||
else {
|
||||
return i2c_write_reg(kLIS3L02DQ_SLAVE_ADDR, CTRL_REG2, 0x00);
|
||||
|
@ -144,3 +149,4 @@ SENSORS_SENSOR(acc_sensor, ACC_SENSOR,
|
|||
|
||||
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -75,3 +80,4 @@ extern const struct sensors_sensor acc_sensor;
|
|||
#define ACC_Z_AXIS 3
|
||||
|
||||
#endif /* __ACC_SENSOR_H__ */
|
||||
/** @} */
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2010, STMicroelectronics.
|
||||
* All rights reserved.
|
||||
|
@ -40,7 +45,6 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
#include "hal.h"
|
||||
#include "hal/micro/micro-common.h"
|
||||
#include "hal/micro/cortexm3/micro-common.h"
|
||||
|
||||
|
@ -48,6 +52,49 @@
|
|||
|
||||
#define DEBOUNCE 1
|
||||
|
||||
/**
|
||||
* \brief Port and pin for BUTTON0.
|
||||
*/
|
||||
|
||||
/*
|
||||
#undef BUTTON_S1
|
||||
#define BUTTON_S1 PORTA_PIN(7)
|
||||
#define BUTTON_S1_INPUT_GPIO BUTTON_INPUT_GPIO(PORTA)
|
||||
#define BUTTON_S1_GPIO_PIN 7
|
||||
#define BUTTON_S1_OUTPUT_GPIO GPIO_PAOUT
|
||||
*/
|
||||
|
||||
#undef BUTTON_S1
|
||||
#define BUTTON_S1 PORTx_PIN(boardDescription->io->buttons[0].gpioPort, boardDescription->io->buttons[0].gpioPin)
|
||||
#define BUTTON_S1_INPUT_GPIO BUTTON_INPUT_GPIO(boardDescription->io->buttons[0].gpioPort)
|
||||
#define BUTTON_S1_GPIO_PIN boardDescription->io->buttons[0].gpioPin
|
||||
#define BUTTON_S1_OUTPUT_GPIO GPIO_PAOUT
|
||||
|
||||
/**
|
||||
* \brief Point the proper IRQ at the desired pin for BUTTON0.
|
||||
*/
|
||||
#define BUTTON_S1_SEL() do { GPIO_IRQCSEL = BUTTON_S1; } while(0)
|
||||
/**
|
||||
* \brief The interrupt service routine for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_ISR halIrqCIsr
|
||||
/**
|
||||
* \brief The interrupt configuration register for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_INTCFG GPIO_INTCFGC
|
||||
/**
|
||||
* \brief The interrupt bit for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_INT_EN_BIT INT_IRQC
|
||||
/**
|
||||
* \brief The interrupt bit for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_FLAG_BIT INT_IRQCFLAG
|
||||
/**
|
||||
* \brief The missed interrupt bit for BUTTON_S1.
|
||||
*/
|
||||
#define BUTTON_S1_MISS_BIT INT_MISSIRQC
|
||||
|
||||
#if DEBOUNCE
|
||||
static struct timer debouncetimer;
|
||||
#endif
|
||||
|
@ -55,16 +102,6 @@ static struct timer debouncetimer;
|
|||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
uint8_t button_flags = 0;
|
||||
|
||||
#define BUTTON_ACTIVE_FLG 0x01
|
||||
#define BUTTON_PRESSED_FLG 0x02
|
||||
|
||||
#define BUTTON_HAS_BEEN_PRESSED() (button_flags & BUTTON_PRESSED_FLG)
|
||||
#define BUTTON_HAS_BEEN_RELEASED() (!(button_flags & BUTTON_PRESSED_FLG))
|
||||
#define BUTTON_SET_PRESSED() (button_flags |= BUTTON_PRESSED_FLG)
|
||||
#define BUTTON_SET_RELEASED() (button_flags &= ~BUTTON_PRESSED_FLG)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
|
@ -74,67 +111,43 @@ init(void)
|
|||
#endif
|
||||
|
||||
/* Configure GPIO for BUTTONSs */
|
||||
halInitButton();
|
||||
|
||||
//Input, pulled up or down (selected by GPIO_PxOUT: 0 = pull-down, 1 = pull-up).
|
||||
halGpioConfig(BUTTON_S1,GPIOCFG_IN_PUD);
|
||||
BUTTON_S1_OUTPUT_GPIO |= GPIOOUT_PULLUP << BUTTON_S1_GPIO_PIN;
|
||||
|
||||
|
||||
BUTTON_S1_SEL();
|
||||
BUTTON_S1_INTCFG = 0x40; // Falling edge triggered.
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
button_flags |= BUTTON_ACTIVE_FLG;
|
||||
INT_CFGSET = BUTTON_S1_INT_EN_BIT;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
button_flags &= ~BUTTON_ACTIVE_FLG;
|
||||
INT_CFGCLR = BUTTON_S1_INT_EN_BIT;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
active(void)
|
||||
{
|
||||
return (button_flags & BUTTON_ACTIVE_FLG)? 1 : 0;
|
||||
return (INT_CFGSET & BUTTON_S1_INT_EN_BIT) ? TRUE : FALSE ;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
if(!active()){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if DEBOUNCE
|
||||
if(timer_expired(&debouncetimer)) {
|
||||
|
||||
if(halGetButtonStatus(BUTTON_S1) == BUTTON_PRESSED){
|
||||
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 10);
|
||||
if(BUTTON_HAS_BEEN_RELEASED()){ // Button has been previously released.
|
||||
sensors_changed(&button_sensor);
|
||||
}
|
||||
BUTTON_SET_PRESSED();
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
BUTTON_SET_RELEASED();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
return (BUTTON_S1_INPUT_GPIO & (1<<BUTTON_S1_GPIO_PIN)) || !timer_expired(&debouncetimer);
|
||||
#else
|
||||
if(halGetButtonStatus(BUTTON_S1) == BUTTON_PRESSED){
|
||||
sensors_changed(&button_sensor);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
return BUTTON_S1_INPUT_GPIO & (1<<BUTTON_S1_GPIO_PIN);
|
||||
#endif
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
|
@ -167,7 +180,6 @@ status(int type)
|
|||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
void BUTTON_S1_ISR(void)
|
||||
{
|
||||
|
||||
|
@ -192,8 +204,8 @@ void BUTTON_S1_ISR(void)
|
|||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||
value, configure, status);
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
@ -32,79 +32,117 @@
|
|||
* 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
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Temperature sensor.
|
||||
* Contact sensor.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
* Stefano Pascali <stefano.pascali@st.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#include PLATFORM_HEADER
|
||||
#include BOARD_HEADER
|
||||
|
||||
#include "hal/error.h"
|
||||
#include "hal/hal.h"
|
||||
#include "micro/adc.h"
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/contact-sensor.h"
|
||||
void halIrqAIsr(void);
|
||||
|
||||
#undef TEMPERATURE_SENSOR_GPIO
|
||||
#define TEMPERATURE_SENSOR_GPIO PORTB_PIN(7)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
halGpioConfig(TEMPERATURE_SENSOR_GPIO, GPIOCFG_ANALOG);
|
||||
halInternalInitAdc();
|
||||
halAdcSetRange(TRUE);
|
||||
|
||||
//PC0 configuration: push-pull output
|
||||
halGpioConfig(PORTC_PIN(0), GPIOCFG_OUT);
|
||||
GPIO_PCSET |= PC0;
|
||||
|
||||
//PB0 (IRQA)configuration: input Pull Down.
|
||||
//halGpioConfig(PORTB_PIN(0), GPIOCFG_IN_PUD);
|
||||
//GPIO_PBOUT &= ~PB0;
|
||||
|
||||
//PB0 (IRQA)configuration: input Pull Down.
|
||||
halGpioConfig(PORTB_PIN(0), GPIOCFG_IN);
|
||||
|
||||
//configure IRQA mode: Rising and Falling edge triggered, digital filter enabled
|
||||
// GPIO_INTCFGA =0x00000160;
|
||||
|
||||
GPIO_INTCFGA = GPIO_INTCFGA_RESET;
|
||||
GPIO_INTCFGA|=GPIO_INTFILT;
|
||||
GPIO_INTCFGA|=(0x03 <<GPIO_INTMOD_BIT);
|
||||
|
||||
halIrqAIsr();
|
||||
//Enable IRQA interrupt
|
||||
INT_CFGSET = INT_IRQA;
|
||||
|
||||
|
||||
// printf("\r\n[Contact Sensor] Initialization Done\r\n");
|
||||
|
||||
}/* end switch_init */
|
||||
|
||||
|
||||
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
|
||||
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
|
||||
void halIrqAIsr(void)
|
||||
{
|
||||
//Clear Interrupt Pending Bit
|
||||
|
||||
INT_GPIOFLAG = INT_IRQAFLAG;
|
||||
|
||||
if ((GPIO_PBIN & (1)) == 0){
|
||||
leds_on(LEDS_RED);
|
||||
leds_off(LEDS_GREEN);
|
||||
}else{
|
||||
leds_on(LEDS_GREEN);
|
||||
leds_off(LEDS_RED);
|
||||
// switch_closed=TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
static uint16_t ADCvalue;
|
||||
static int16_t volts;
|
||||
halStartAdcConversion(ADC_USER_APP, ADC_REF_INT, ADC_SOURCE_ADC2_VREF2,
|
||||
ADC_CONVERSION_TIME_US_4096);
|
||||
//printf("[Contact Sensor] Value=%d\r\n", GPIO_PBIN & (1));
|
||||
return (GPIO_PBIN & (1));
|
||||
|
||||
/* This blocks for a while, about 4ms. */
|
||||
halReadAdcBlocking(ADC_USER_APP, &ADCvalue);
|
||||
|
||||
/* 100 uVolts */
|
||||
volts = halConvertValueToVolts(ADCvalue);
|
||||
|
||||
/* +- 0.23 degC in the range (-10;65) degC */
|
||||
/* return ((18641 - (int32_t)volts)*100)/1171;*/
|
||||
|
||||
/* +- 0.004 degC in the range (20;30) degC */
|
||||
return ((18663 - (int32_t) volts) * 100) / 1169;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch (type) {
|
||||
switch(type){
|
||||
case SENSORS_HW_INIT:
|
||||
init();
|
||||
return 1;
|
||||
case SENSORS_ACTIVE:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
switch(type) {
|
||||
|
||||
case SENSORS_READY:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
|
||||
SENSORS_SENSOR(contact_sensor, CONTACT_SENSOR,
|
||||
value, configure, status);
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
/** @} */
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* \addtogroup mb851-platform
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
@ -32,17 +32,26 @@
|
|||
* 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
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Button sensor.
|
||||
* Contact magnetic sensor header file.
|
||||
* \author
|
||||
* Salvatore Pitrulli <salvopitru@users.sourceforge.net>
|
||||
* Stefano Pascali <stefano.pascali@st.com>
|
||||
*/
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void
|
||||
irq_init(void)
|
||||
{
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __CONTACT_SENSOR_H__
|
||||
#define __CONTACT_SENSOR_H__
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor contact_sensor;
|
||||
|
||||
#define CONTACT_SENSOR "Contact"
|
||||
|
||||
#endif /* __CONTACT_SENSOR_H__ */
|
||||
/** @} */
|
|
@ -1,5 +1,11 @@
|
|||
/**
|
||||
* \addtogroup mbxxx-platform
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
void
|
||||
irq_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue