an operating system for the msp430 microcontroler ...2009.rmll.info/img/pdf/tinyos_rmll2009.pdfan...
TRANSCRIPT
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
An operating system for the MSP430microcontroler: development of a FAT driver
for TinyOS-2.x
G. Goavec-Merou, J.-M FriedtAssociation Projet Aurore, Besancon
July 13, 2009
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Why an OS on a microcontroler ?
Sensor networks are under development for a wide range ofapplications: a set of nodes spatially distributed monitorenvironmental propertiescomplex and reusable software ⇒ dedicated operating systemfor such applications (low memory footprint & powerconsumption)TinyOS-2.x is a free (BSD license) operating system (a.k.aexecutive environment) for embedded platformsData acquisition during periodic wakeup sequencesData storage over a filesystem: radiofrequency links are not(yet) reliabl enough to answer our needs (+ consumption &communication range)
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Presentation
Two main systeme classes:Powerful but enrgy consuming platforms.Low power platforms will litte energy consumption.
A sensor node must beautonomoususe little electrical power to run on batteries
Objective:comfort of developing an application in the context of the former(OS) within the constraints of the latter: executive environmentgenerates a monolithic application within the context close to thatfound in an OS.
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Node architecture
Vservo
"JT
AG
"
US
B
DV
CC
1P
6.3/
A3
2P
6.4/
A4
3P
6.5/
A5
4P
6.6/
A6
5P
6.7/
A7
6V
RE
F+
7X
IN8
XO
UT
/TC
LK9
VE
RE
F+
10V
ER
EF
-11
P1.
0/T
AC
LK12
P1.
1/T
A0
13P
1.2/
TA
114
P1.
3/T
A2
15P
1.4/
SM
CLK
16
P1.5/TA017
P1.6/TA118
P1.7/TA219
P2.0/ACLK20
P2.1/TAINCLK21
P2.2/CAOUT/TA022
P2.3/CA0/TA123
P2.4/CA1/TA224
P2.5/ROSC25
P2.6/ADC12CLK26
P2.7/TA027
P3.0/STE028
P3.1/SIMO029
P3.2/SOMI030
P3.3/UCLK31
P3.4/UTXD032
P3.
5/U
RX
D0
33
P3.
6/U
TX
D1
34
P3.
7/U
RX
D1
35
P4.
0/T
B0
36
P4.
1/T
B1
37
P4.
2/T
B2
38
P4.
3/T
B3
39
P4.
4/T
B4
40
P4.
5/T
B5
41
P4.
6/T
B6
42
P4.
7/T
BC
LK43
P5.
0/S
TE
144
P5.
1/S
IMO
145
P5.
2/S
OM
I146
P5.
3/U
CLK
147
P5.
4/M
CLK
48
P5.5/SMCLK 49P5.6/ALK 50
P5.7/TBOUTH 51XT2OUT 52
XT2IN 53TDO/TDI 54
TDI 55TMS 56TCK 57
!RST/NMI 58P6.0/A0 59P6.1/A1 60P6.2/A2 61
AVSS 62DVSS 63AVCC 64
12
34
56
78
JP4
R8
C9
C1
C10
C13
C14
R14
C35
C36
C11
C12
A1
B2
C13
IC3A
A8
B9
C6
IC3C
714
IC3PVDD VSS
LED
5
LED
6
D3
3V3OUT17
USBDM16
USBDP15
_RESET19
OSCI27
OSCO28
GN
D1
7
GN
D2
18
GN
D3
21
TXD 1
RXD 5
_RTS 3
_CTS 11
_DTR 2
_DSR 9
_DCD 10
_RI 6
CBUS0 23
CBUS1 22
CBUS2 13
CBUS3 14
CBUS4 12
VC
CIO
4
AG
ND
25
TEST26
VC
C20IC5
CS 1
DI 2
GND 3
VCC 4
SCK 5
GND1 6
DO 7
IRQ 8
WP WP
CD CD
SW SW
SHIELD 14
D+D-VBUSGND
R1
21
Q1
Q3
R4
R5
1 2
JP1 1 2
JP2
GATE1 2
GATE2 7
GN
D3
IN14
IN25
VC
C6 IC2
Q2D
SGQ4
D
SG
SHDN/5
LBI2
LBO/ 3REF4
FB
1
LX 7
OUT 8
GN
D6
IC4
C2
L1R2
123
JP3123
JP5
12
JP7
12
JP6
12345
MP
S_R
ST
VDD
VDD
VDD
GND
GN
D
GN
D
TD
I
TC
LKTC
K
TD
OT
MS
ONOFF1
ONOFF2
VSERIE VSERIE
3.3
SHOOT2
SHOOT1
CS
VC
C_S
DS
CK
MO
SI
MIS
O
4.0MHz xtal
3k
VD
D
100n
1nGN
D
GND
GND
GND
1n
GN
D
VDD
10k
VDD
100nf
>22uF
GND
GND
4066
D
4066
D
VDDGND
4k7
2k
2k
LTC1157
GND
2N3819
2N3819
MAX1674
GND
GND GND
A non commercial platform to make sure we understand thewhole configuration procedure of TinyOS-2.x:
MSP430F149 microcontroler (60 KB flash, 2 KB de RAM)L1 C/A ET312 GPS receiver (RS232)removable SD card (SPI bus)
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
TinyOS-2.x
Compromise between low levelprogramming and an operting system:
set of routinesstructure including abstractionlayers during the developmentphaseuses the nesC programminglanguagegenerates a single monolithicapplication
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Node integration
Defined by two items:a declaration filea configuration directory
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Platform directory content
projet.target.platformhardware.hPlatformC.ncPlatformP.nc
PLATFORM = pro j e t$ ( c a l l TOSMake include platform ,msp)
p ro j e t : $ (BUILD DEPS)@:
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Platform directory content
projet.target.platformhardware.hPlatformC.ncPlatformP.nc
push ( @includes , qw(
%T/ ch ips /msp430%T/ ch ips /msp430/adc12%T/ ch ips /msp430/dma%T/ chips /msp430/ pins%T/ ch ips /msp430/ timer%T/ ch ips /msp430/ usart%T/ ch ips /msp430/ s en so r s%T/ l i b / timer%T/ l i b / s e r i a l%T/ l i b /power) ) ;
push ( @opts , qw(−gcc=msp430−gcc−mmcu=msp430x149−fnesc−t a rg e t=msp430−fnesc−no−debug−fnesc−s chedu l e r=TinySchedulerC , TinySchedulerC →
↪→ . TaskBasic , TaskBasic , TaskBasic , runTask , →↪→ postTask
) ) ;
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Platform directory content
projet.target.platformhardware.hPlatformC.ncPlatformP.nc
#inc lude " h a r d w a r e . h "
con f i gu r a t i on PlatformC {prov ides i n t e r f a c e I n i t ;
}implementation {
components PlatformP , Msp430ClockC ;I n i t = PlatformP ;PlatformP . Msp430ClockInit −> Msp430ClockC . →
↪→ I n i t ;}
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Platform directory content
projet.target.platformhardware.hPlatformC.ncPlatformP.nc
#inc lude " h a r d w a r e . h "
module PlatformP {prov ides i n t e r f a c e I n i t ;uses i n t e r f a c e I n i t as Msp430ClockInit ;uses i n t e r f a c e I n i t as Leds In i t ;
}implementation {
command e r r o r t I n i t . i n i t ( ) {c a l l Msp430ClockInit . i n i t ( ) ;c a l l Leds In i t . i n i t ( ) ;re turn SUCCESS;
}de f au l t command e r r o r t Leds In i t . i n i t ( ) { →
↪→ return SUCCESS; }}
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Validating the platform: blinking LEDs
Applicationexample:apps/Blink
#inc lude " h a r d w a r e . h "con f i gu r a t i on PlatformLedsC {
prov ides i n t e r f a c e GeneralIO as Led0 ;prov ides i n t e r f a c e GeneralIO as Led1 ;prov ides i n t e r f a c e GeneralIO as Led2 ;uses i n t e r f a c e I n i t ;
}implementation {
components HplMsp430GeneralIOC as GeneralIOC ,new Msp430GpioC ( ) as Led0Impl ,
new Msp430GpioC ( ) as Led1Impl ;
components new NoPinC () as Led2Impl ;components PlatformP ;
I n i t = PlatformP . Leds In i t ; // Raccorde l ’ event →↪→ i n i t c e l u i de PlatformP
Led0 = Led0Impl ;Led0Impl −> GeneralIOC . Port16 ;Led1 = Led1Impl ;Led1Impl −> GeneralIOC . Port17 ;Led2 = Led2Impl ; // No led2 on board
}
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Beyond the LED driver: using an LCD
#inc lude " h a r d w a r e . h "con f i gu r a t i on PlatformLcdC {
prov ides i n t e r f a c e GeneralIO as LcdData0 ;[ . . . ]
p rov ides i n t e r f a c e GeneralIO as LcdData3 ;prov ides i n t e r f a c e GeneralIO as LcdE ;prov ides i n t e r f a c e GeneralIO as LcdRS ;uses i n t e r f a c e I n i t ;
}implementation {
components HplMsp430GeneralIOC as GeneralIOC ,new Msp430GpioC ( ) as LcdData0Impl ,
[ . . . ]new Msp430GpioC ( ) as LcdData3Impl ,new Msp430GpioC ( ) as LcdEImpl ,new Msp430GpioC ( ) as LcdRSImpl ;
components PlatformP ;
I n i t = PlatformP . LcdIn i t ;
LcdData0 = LcdData0Impl ;LcdData0Impl −> GeneralIOC . Port24 ;
[ . . . ]
LcdData3 = LcdData3Impl ;LcdData3Impl −> GeneralIOC . Port27 ;
LcdE = LcdEImpl ;LcdEImpl −> GeneralIOC . Port23 ;
LcdRS = LcdRSImpl ;LcdRSImpl −> GeneralIOC . Port22 ;
}
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Exploiting the LCD driver
Bitwise signal manipulation
// Ecr i t un demi oc t e tvoid writeDB ( u in t 8 t va l ) {
val = val & 0 x0f ;i f ( va l & LCD DATA0)
c a l l LcdData0 . s e t ( ) ;e l s e c a l l LcdData0 . c l r ( ) ;
i f ( va l & LCD DATA1)c a l l LcdData1 . s e t ( ) ;
e l s e c a l l LcdData1 . c l r ( ) ;
i f ( va l & LCD DATA2)c a l l LcdData2 . s e t ( ) ;
e l s e c a l l LcdData2 . c l r ( ) ;
i f ( va l & LCD DATA3)c a l l LcdData3 . s e t ( ) ;
e l s e c a l l LcdData3 . c l r ( ) ;}
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
LCD results
An interface useful for debugging and interacting with a user
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Asynchronous communication
RS232: two-way communication protocol.TinyOS model.
packets are embedded for network routing (' IP header onethernet)incompatible with a GPS receiver (NMEA sentences do notcomply with this encapsulation)
use of raw RS232 communication
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
RS232 communication
Raw RS232 interfaceThe public interface.The configuration.
#inc lude " h a r d w a r e . h "con f i gu r a t i on Plat formSer ia lC {
prov ides i n t e r f a c e StdControl ;prov ides i n t e r f a c e UartStream ;prov ides i n t e r f a c e UartByte ;
}implementation {
components new Msp430Uart1C ( ) as UartC , p r o j e t S e r i a lP ;UartStream = UartC . UartStream ;UartByte = UartC . UartByte ;StdControl = p ro j e t S e r i a lP . Control ;p r o j e t S e r i a lP . Msp430UartConfigure <− UartC . Msp430UartConfigure ;p r o j e t S e r i a lP . Resource −> UartC . Resource ;p r o j e t S e r i a lP . ResourceRequested −> UartC . ResourceRequested ;components LedsC ;p r o j e t S e r i a lP . Leds −> LedsC ;
}
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
RS232 communication
Raw RS232 interfaceThe public interface.The configuration.
msp430 uar t un ion con f i g t msp430 uar t p ro j con f i g = { {ubr : UBR 32KHZ 4800 ,umctl : UMCTL 32KHZ 4800 ,s s e l : 0x01 ,pena : 0 ,pev : 0 ,spb : 0 ,c l en : 1 ,l i s t e n : 1 ,mm: 0 ,ckpl : 0 ,urxse : 0 ,u rxe i e : 1 ,urxwie : 0 ,urxe : 0 ,utxe : 1} } ;
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Example of an OEM GPS receiver
Continuous position information receptionUses ASCII sentences (NMEA) = termination characterdefines the end of the sentenceAsynchronous communication (RS232, 4800 bauds)Bandwidth: 144 B/s
$GPRMC,101236 .000 ,A,4821 .6999 ,N,00446 .5093 ,W,0 .94 ,167 .02 ,281208 , ,∗11$GPGGA,101237 .000 ,4821 .6991 ,N,00446 .5093 ,W, 1 , 0 5 , 8 . 2 , 5 . 1 ,M, 5 2 . 5 ,M→
↪→ , ,0000∗40$GPRMC,101237 .000 ,A,4821 .6991 ,N,00446 .5093 ,W,0 .81 ,167 .67 ,281208 , ,∗1F$GPGGA,101238 .000 ,4821 .6987 ,N,00446 .5092 ,W, 1 , 0 5 , 8 . 2 , 5 . 4 ,M, 5 2 . 5 ,M→
↪→ , ,0000∗4C
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Synchronous communication
SPI: asymetric master-slave protocol.N + 2 signals to communicate with N slaves : MOSI (MasterOut Slave In), MISO (Master In Slave Out) and N ChipSelect signalshigh bandwidth (shared clock)hardware implementation on most microcontrolers.
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Use of the SPI bus
Implementation of a module managing a Secure Digital card (SD)for non volatile mass storage.
communication
USB
SD
LCD
MSP430JTAG
programmation
SPI compatibleLarge storage capacity.Default buffer size 512 bytes, might be reduced during config.Lack of native drivers for TinyOS-2.xBlocking model selected
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Filesystems
Objectives:Efficient data saving.Direct data retrieval.Acquired data are structured
TinyOS modelWhich filesystem ?
simple and hence small memory footprint/power consumptioncross-platform.designed for older personnal computers.still in use.
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Presentation of FAT
Access through theMaster Boot Record(MBR)PartitionClustersFile Allocation TableImplemented asmultiple modulesBandwidth: 1.6 kB/s
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Presentation of FAT
Access through theMaster Boot Record(MBR)PartitionClustersFile Allocation TableImplemented asmultiple modulesBandwidth: 1.6 kB/s
1
2
5
FAT
2
8
8 FF
...
7
513
FF513
00
00
00...
00
00
00
00
00
00
Fich_1
Fich_2
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Presentation of FAT
Access through theMaster Boot Record(MBR)PartitionClustersFile Allocation TableImplemented asmultiple modulesBandwidth: 1.6 kB/s
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Example: periodic acquisition and data storagein a file
/∗ D clenchement du timer ∗/event void Timer0 . f i r e d ( ) {
c a l l f a tCont ro l . s t a r t ( ) ;}/∗ Fat f i n i de s ’ i n i t ∗/event void fa tCont ro l . startDone ( e r r o r t e r r o r ){
i f ( e r r o r == SUCCESS) c a l l f i l eC on t r o l . s t a r t ( ) ;}/∗ F i l e f i n i t son i n i t ∗/event void f i l eC on t r o l . startDone ( e r r o r t e r r o r ) {
i f ( e r r o r == SUCCESS)c a l l ReadStream . pos tBuf f e r ( tampon+5, ( u in t16 t )NBLINES) ;
}/∗ La l e c t u r e e s t f i n i e ∗/event void ReadStream . bufferDone ( e r r o r t r e su l t ,
u i n t 8 t ∗ buf , u in t16 t count ) {i f ( r e s u l t == SUCCESS)
c a l l f i l e . wr i t e ( tampon , count+5) ; // Ecr i tu r ec a l l f a tCont ro l . stop ( ) ; // Tout t e i n d r e
}event void fa tCont ro l . stopDone ( e r r o r t e r r o r ){
i f ( e r r o r == SUCCESS)c a l l f i l eC on t r o l . stop ( ) ;
}
MSP430
wakeup wakeup
instrument
open file
init SD
acquisition
RS232 sentences data
storage file/SD
close deep
sleep
timer
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Results
Development of an application using the drivers for :Data acquisition and storage on an SD card on the embeddeddeviceData transfer to computer using SD card readerUse of the data to generate a graph
Trackcharacteristics
68004sentencesDuration11 hoursFile size:4.7 MB
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Conclusion
Working environment close to the one familiar for developmentunder an OS
easy port of a C program thanks to nesCtransparent port from one platform to anothereasier code maintenance, focus on the innovative workour contribution: a driver for data storage (result of analog todigital conversion, RS232) on a FAT formatted SD card (SPIbus)
The driver has been validated on a Crossbow Telos2 board,further developments include testing on a MicaZ platform(AVR processor)
G. Goavec-Merou & al OS for MSP430
OS forMSP430
G. Goavec-Merou &
al
Objectives
Softwaredevelop-ment
Platform
Commu-nication
Filesystem
Results
Conclusion
Questions
Further readings: http://jmfriedt.free.fr/tinyOS.pdf [inFrench]
G. Goavec-Merou & al OS for MSP430