Home
User Guide (for ScatterWeb)
Contents
1. restore stack pointer 718e 11 424a 06 mov amp 0x064a r1 0x064a Tasks currentTask address 0x0000 71a4 8143 54 06 mov 40 1620 r15 r3 As 00 Tasks currentTask state T DESTROYED 71ba 8 43 58 06 mov 0 1624 r15 r3 As 00 don t know why the compiler does that thing not always this way it saves on instruction tried to force it by telling all registers get clobbered through this instruction asm volatile amp savedSP 1 r15 r14 r13 r12 r1 1 r1 0 re r7 r6 restore stack pointer But this produced the same behavior like the first BUT instead of r11 being used it is now r5 which is even more worse r5 is the frame pointer and strangely used by gcc The compiler should never assume r5 is preserved over function calls very strange why it does that here even when r15 is appended to the list of clobbered registers Anyway it works with the second But that may change with O flags or anything else so best will be to put that into an extra function Make sure this function does not get inline into scos_call again with fno inline for this file 60 ScatterWeb inside bool Threading init Function Initializes the threading Parameter None Return value code True code always bool Threading add void address Function Adds thread Parameter address address of task Return value code True code if successful lt code gt False
2. Function Sends a RC5 PHI command Parameter data data to send Return value code True code True if IR sensor available lt code gt False lt code gt otherwise bool Data RC5Enable Function Enables the RC5 Parameter None Return value code True code True if IR sensor available lt code gt False lt code gt otherwise bool Data RC5Disable Function Disables the RC5 Parameter None Return value code True code True if IR sensor available lt code gt False lt code gt otherwise bool Data RC5SendNEC UINT16 datal UINT16 data2 Function Sends a RC5 NEC command Parameter data1 data1 to send data2 data2 to send Return value code True code True if IR sensor available lt code gt False lt code gt otherwise bool Data sensorHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value ScatterWeb inside 31 void Data_RC5ReceiveHandler This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value void Data RC5EventHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value 32 ScatterWeb inside 3 4 ScatterWeb IO ScatterWeb 2 x System src ScatterWeb IO
3. Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value 18 ScatterWeb inside 3 2 ScatterWeb Configuration ScatterWeb 2 x System src ScatterWeb Configuration h ifndef ScatterWeb Configuration define ScatterWeb Configuration fdefine EADR CONFIG 0 0 00 define DEBUG RADIO 0x80 define DEBUG DCO 0x40 define DEBUG SYNC 0x20 define NO 0x01 define LOW 0x02 define MEDIUM 0x03 define HIGH 0x04 define VERBOSE 0x05 define FF PROGRAMMABLE 0x01 define FF DCOCHECKER 0x02 typedef struct UINT16 id UINT16 rxReceiveLimit UINT8 transmitPower UINT8 boot logLevel UINT8 firmwareFlags extern config t Configuration bool Configuration save bool Configuration print endif The ScatterWeb Configuration provides functions that allow you to programmatically access configuration settings The configuration consists of the struct config_t defined in ScatterWeb Configuration h The variable Configuration is of that type and represents the current config in RAM and can be accessed directly every time Changes to Configuration will only be made permanent power off amp resets with a call to Configuration_save which copies the content of the Configuration to EEPROM EADR_CONFIG Initi
4. bool Time convertSystemTime const time src btime dst CONV cose b aues 15 elu P bool Time writeTime fp char t writer btime t time bool Time readTime const UINT8 c btime t time endif The ScatterWeb Time represents an instant in time typically expressed as a date and time of day This file keeps the global time of this node in the global var currentTime It contains methods for writing reading and converting currentTime avoid concurrency problems accessing currentTime must be done with disabled interrupts or in interrupt routines only This defines some macro for accessing Time currentTime safely time t Time getSystemTime time t time Function Read currentTime or safely with disabled interrupts Easier and also faster to use is CURRENT TIME time t time CURRENT TIME lt gt timet time getCurrentTime amp time Parameter time current time struct to store system time Return value pointer of time bool Time setSystemTime time t time Function Write currentTime or safely with disabled interrupts Parameter time current time to set Return value code True code always bool Time convertSystemTime const time src btime dst Function Converts time to broken down time Parameter src input current time dst output btime Return value code True code always ScatterWeb inside 65 bool Time convertTime const btime t
5. include lib ecr programming h finclude lib ecr flasher h 11 defined ESB finclude lib esb programming h include lib esb flasher h elif defined eGate elif defined eGate finclude lib egate programming h finclude lib egate flasher h finclude lib egate FTerm h finclude lib egate JTAGFunc h finclude lib egate LowLevelFunc h fendif include ScatterWeb Configuration h finclude ScatterWeb Data h finclude ScatterWeb Timers h finclude ScatterWeb Time h finclude ScatterWeb IO h finclude ScatterWeb Comm h finclude ScatterWeb Net h include ScatterWeb Messaging h include ScatterWeb Threading h include ScatterWeb String h include ScatterWeb Synchronisation h endif The ScatterWeb System contains fundamental functions that define commonly used value and reference data types events and event handlers attributes and processing exceptions 50 ScatterWeb inside ADC Starting enabling disabling ISR for ADU The main function of the ADU is to sample the unfiltered radio receive output and provide a carrier detect see interrupt routine ADC12ISR and rxReceivelimit in Configuration Look for defines in ScatterWeb System h to access other ADC readings CLOCK Methods for interfacing DS1629 RTC with temperature and LM71 temperature sensor For both devices the function getTemperature is implemented It returns the temperature in
6. ASERTA veritas iustitia libertas Freie Universit t Berlin User Guide for ScatterWeb A platform for teaching amp prototyping wireless sensor networks scatterweb mi fu berlin de Computer Systems amp Telematics Freie Universit t Berlin Germany 1 5 11 Embedded Chip Radio 5 1 2 Embedded Sensor Board 6 132 Embedded EYE BYE siio DER OR OR OR OUR OR MIR EORR 7 MM RE 8 RENE T a 9 2 10 8 12 3 1 5 16 3 2 19 8 3 ScatlerWeb Dala na 21 2SCAallEr WED On een eat 33 3 5 35 3 6 eur i em Paw III TEM 38 Ore ER 43 3 8 5 46 3 9 Sc tlerWeb qa 48 3 10 2 56 11 SCAaHer Wen eds cats aah 64 3 12 ScalterWeb 555555 Eon ore Coe eom
7. define ScatterWeb System define WAKEUPLPMI irqname 1626 asw Ware 5 0 absenden sel ug runModule bit while 0 if defined ESB defined eGate L__FrameOffset_ N uint16_t LPM1_bits defined ECR error No device specified endif define TERM BUFSIZE 82 define SERIAL BUFSIZE 82 define RADIO RXBUF 5171 270 define RADIO 5171 2 400 define TIMERS 20 define MAX TASKS 10 define INFOM M define INFOMEMNOBITS T define SET x Gay x 0x0001 y define CLEAR x y 5 define SCOS define MF RADIO 0x0002 define MF RADIO TX 0x0004 define MF TIMER 0x0008 define SI Li RIAL RX 0x0010 define MF SENSORS 0x0020 E define MF_RC5 0x0080 define INIT FCS Oxffff define S Gl RIAL define C_RADIO define C_S NSOR 02 INS define NUMBER_CALLBACKS define MICIFG 0x01 define MICIE 0x02 ECR ESB eGate attribute section infomem section infomemnobits y 48 ScatterWeb inside define MICVOLTAGE ADC12MEM2 define EX
8. rbu read button state ScatterWeb Messaging rcf read configuration ScatterWeb Configuration rer X y read eeprom from x to y ScatterWeb IO rff read firmware flags ScatterWeb Configuration rfl read flash from x to ScatterWeb IO rfr read receive limit ScatterWeb Messaging rid read id ScatterWeb Configuration rlb read boot log level ScatterWeb Configuration read green led state ScatterWeb Messaging rlo read log level ScatterWeb Configuration ScatterWeb inside 77 rlr read red led state ScatterWeb Messaging rly read yellow led state ScatterWeb Messaging rmm read microphone value ScatterWeb Messaging rrp read temp rxp ScatterWeb Messaging rsm read sensor mask ScatterWeb Event rsp read stack pointer ScatterWeb Messaging RST reset system ScatterWeb Messaging rtp read transmit power ScatterWeb Messaging rtt read temperature ScatterWeb System rvb read battery value ScatterWeb Messaging rve read extern value ScatterWeb Messaging set announce flags saf a ScatterWeb Event 01 AF SERIAL 02 2 AF RADIO or a combination of this values sbp if 1 beeper on otherwise off ScatterWeb Messaging SCO read tasks ScatterWeb Threading set firmware flags sff ScatterWeb Configuration 01 PROGRAMMABLE 02 FF DCOCHECKER or a combination of this values sfr set receive limit ScatterWeb Messaging sid set id to x ScatterWeb Configuration sir send x over 5
9. src time t dst Function Converts broken down time to time Parameter src input time dst output current time Return value code True code always bool Time writeTime fp char t writer btime t time Function Writes broken down time as a string in the form yyyy mm dd hh mm ss Parameter writer function to write time time to write Return value code True code always bool Time readTime const UINT8 c btime t time Function Reads broken down time as a string The format is the same as in Time writeTime but the year must be written without 2000 The number of digits is not fixed like in Time writeTime so it is ok to write 03 09 07 08 31 02 or 3 9 7 8 31 2 Parameter C array to store time time time to read Return value code True code always 66 ScatterWeb inside 3 12ScatterWeb Timers ScatterWeb 2 x System src ScatterWeb Timers h ifndef ScatterWeb Timers define ScatterWeb Timers include ScatterWeb System h typedef void fp timer UINT16 DOON sb rei imie 0 9 bool Timers add UINT16 ticks fp timer fp UINT16 data bool Timers reset UINT16 t fp timer fp UINT16 data bool Timers remove fp timer fp UINT16 data bool Timers eventHandler endif The ScatterWeb Timers provides the Timer component which allows you to raise an event on a specified interval The Timer component is a hardware based timer which allows you to specify a re
10. Directory Tree ScatterWeb Package Compiler installer for GNU C compiler Source current source of ScatterWeb ScatterWeb inside 73 Installation 1 Execute the installer for GNU C compiler Usage With Visual Studio 2005 you can open the sln solution files just by clicking them For compilation choose Build Build Solution in the menu bar Forflashing execute the flash bat file or integrate it into the menu bar 4 3 How to use Edit View Project Buld Debug Tools Window Community Lb Debug Win32 Bp aes set key MES Re dec 5 Hr Ho 2 ScatterWeb Process c X Solution Explorer Solution ESE 1 project 2 X 2 Global Scope g 21 Solution 1 project Hinclude ScatterWeb Event h 2 Bess include 8ystem src ScatterWeb System h a Ey app ScatterWeb Event c 1 ScatterWeb Event h Process interceptRadioHandler E a Eos ScatterWeb Comm c 1 Scatterweb Comm h Ejvoid Process radioHandler void receivedPacket Scatter Web Configuration Messaging_radioHandler N ScatterWeb Configuration h if rxPacket to BROADCAST rxPacket to Configuration id ScatterWeb Data c Process interceptRadioHandler h ScatterWeb Data h ScatterWeb IO c else ScatterWeb 10 h switch rxPacket type 4 ScatterWeb Messaging c case PING PACKET 19 ScatterW
11. EcL 1 a7 4 C3 The camera module has a serial connector to connect it to the ESB ScatterWeb inside 1 4 eGate USB Flash Transceiver Antenna Serial Connector USB Second Flash Connector to flash a further node The eGate USB has additionally a red a yellow and a green LED and a 64 Kbytes EEPROM Notice You need an appropriate flash cable obtainable on order and the JTAG also obtainable on order to flash the eGate USB 8 ScatterWeb inside 1 5 eGate WEB Transceiver Antenna Web server Flash The eGate WEB has additionally a red a yellow and a green LED and a 64 Kbytes EEPROM Notice You need an appropriate flash cable obtainable on order and the JTAG also obtainable on order to flash the eGate WEB ScatterWeb inside 9 2 Radio communiction Agilent 12 41 41 12 Jul 2005 Marker Ref 100 mH Atten 40 dB Si VBH 3 MHz Sweep 8 10 ScatterWeb inside 25 Agilent 12 43 29 12 Jul 2005 Marker Atten 40 dB Marker Span 13 575000 MHz ScatterWeb inside 11 3 ScatterWeb API As the name already implies sensor networks need sensors typically lots of sensors to collect data from their environment All sensor nodes may form an ad hoc network with some nodes acting as data sources some as relays and some as data sinks collecting data Nodes may act in all three roles at the same time The ESBs developed by the CS
12. UPDATE MESSAGE DD ING MESSAGE DD ROUTABLE PACKE DSDV UPDA PACKET DSDV SEND PACKET EST PACK T E OxFFFF 0x0000 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 38 ScatterWeb inside fdefine TRACKING PACKET 0x30 define RTS PACKE 0x31 define CTS PACKET 0x32 define IS RADIO RECEIVING cdCounter define IS RADIO SENDING P50UT 0xC0 0x40 typedef struct UINT16 to UINT16 from UINT8 type UINT8 num UINT8 header UINT16 header length UINT8 data UINT16 data length packet t extern volatile packet t rxPacket CRECEN extern extern bool Net bool Net_ bool Net bool Net bool Net bool Net bool Net char Net fendif packet t sentPacket volatile UINT8 txRetries volatile UINT8 cdCounter volatile UINT8 txState Stone 3 _setTxPower UINT8 value _send packet_t packet fp_char_t callback rxHandler txHandler _esend packet_t packet fp char t callback The ScatterWeb Net implements a network service that enables you to develop applications that use network resources w
13. getTemperature xxx x Parameter writer function to write temp temperature Return value code True code always bool String abstractWrite fp char t writer const char fmt va list argp Function Simple printf implementation for RS232 output Supports amongst others c Prints a character 96i Prints an UINT16eger in decimal format l Prints UINT32eger in decimal format b Prints a byte in hex format x Prints an int in hex format Parameter writer function to write fmt function argp list of arguments Return value code True code always 44 ScatterWeb inside bool String write UINT8 dest const char fmt Function Parameter Return value Writes dest dest fmt function list of parameters code True code always UINT16 String parseInt const UINT8 c UINT8 ptr Function Parameter Return value Parses int ptr ptr parsed int UINT32 String parseLongInt const UINT8 c UINT8 ptr Function Parameter Return value Parses long int c c ptr ptr parsed long int ScatterWeb inside 45 3 8 ScatterWeb Synchronisation ScatterWeb 2 x System src ScatterWeb Synchronisation h ifndef ScatterWeb Synchronisation define ScatterWeb Synchronisation define ROOT T define FRAME define INIT volatile struc ESYNESEerRUCE bool bool bool bo
14. green LED Parameter None Return value code True code if green led available lt code gt False lt code gt otherwise bool Data redOn Function Enables the red LED Parameter None Return value code True code if red led available lt code gt False lt code gt otherwise bool Data redOff Function Disables the red LED Parameter None Return value code True code if red led available lt code gt False lt code gt otherwise bool Data redToggle Function Toggles the red LED Parameter None Return value code True code if red led available lt code gt False lt code gt otherwise bool Data yellowOn Function Enables the yellow LED Parameter None Return value code True code if yellow led available lt code gt False lt code gt otherwise ScatterWeb inside 27 bool Data yellowOff Function Parameter Return value Disables the yellow LED None code True code if yellow led available lt code gt False lt code gt otherwise bool Data yellowToggle Function Parameter Return value Toggles the yellow LED None code True code if yellow led available lt code gt False lt code gt otherwise bool Data microphoneOn UINT16 delay UINT16 diff Function Parameter Return value Enables the microphone sensor delay delay of measurement diff diff of measurement code True code if micr
15. level register a function that expect to get pass void as parameter see C System registerCallback UINT8 type void fp_t If the line is handled the receiving function should call Comm clear 16 ScatterWeb inside bool Comm init UINT8 bps Function Parameter Return value Initializes the serial bps the bps to be set code True code always bool Comm print const char fmt Function Parameter Return value Sends bytes of data fmt function list of parameters code True code if serial is on lt code gt False lt code gt otherwise bool Comm log UINT8 level const char fmt Function Parameter Return value bool Comm on Function Parameter Return value bool Comm off Function Parameter Return value Sends bytes of log data level log level fmt function list of parameters code True code if serial is on lt code gt False lt code gt otherwise Switches the serial on None code True code always Switches the serial off None code True code always ScatterWeb inside 17 bool Comm registerByteLevel fp char t fp Function Registers byte level and will be set by Comm init UINT8 bps Parameter Fp pointer of function Return value code True code if ECR or ESB defined lt code gt False lt code gt if eGate defined bool Comm clear
16. lt code gt otherwise bool Threading doEvents Function Does events Parameter None Return value code True code always bool Threading sleep UINT16 ticks Function Sleeps for ticks Parameter ticks ticks to wait Return value code True code always bool Threading wait UINT8 adr UINT8 bitmask Function Waits until address bitmask Parameter adr address bitmask bitmask Return value code True code always bool Threading eventHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value ScatterWeb inside 61 bool Threading packetHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value bool Threading_sentPacketHandler UINT16 p UINT16 success Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value bool Threading recv UINT16 sender UINT16 type UINT16 timeout Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value bool Threading recvp UINT16 sender UINT16 type UINT16 timeout Function This member supports the ScatterWeb infrastructure and is not intended to be used directl
17. make clean or simply delete all object o files in firmware and userapp directories in this situation ScatterWeb inside 15 3 1 ScatterWeb Comm ScatterWeb 2 x System src ScatterWeb Comm h ifndef ScatterWeb_Comm define ScatterWeb Comm define BPS 2400 0x01 define BPS 14400 0x02 define BPS 19200 0x03 define BPS 38400 0x04 define BPS 57600 0x05 define BPS 115200 0x06 UINT8 Comm logLevel bool Comm init UINT8 bps Commis 41 02 222 Comi ICC haan tem tr ooo bool Comm on bool Comm off bool Comm registerByteLevel fp char t fp bool Comm clear endif The ScatterWeb Comm represents the standard output for applications The init function for the UART Comm init provides setup for all standard baud rates BPS 2400 BPS 14400 BPS 19200 BPS 38400 BPS 57600 and BPS 115200 All UART communication should be done with Comm print or Comm log as the serial output with this functions is controlled via Com struct Configuration boot logLevel in ScatterWeb Configuration All sending functions are blocking Receiving is handled by an interrupt and you can choose byte access or line access byte access To gain access to the byte level register a function that expect to get pas an UINT8 as parameter see Comm_registerByteLevel fp_char_t fp line access To gain access to the line
18. the destination id of receiver or broadcast address type must contain the packet type header data must be set to NULL or to the data that should get transported If set header length data length should contain the length of the data num can be set to transport a byte for not acknowledged packets otherwise it will get overwritten from is always overwritten with the id of this device 40 ScatterWeb inside Such a packet can then be queued into tx ring buffer with Net send and a pointer to initialized packet t Additionally these two functions accept a callback pointer to functions which accept an UINTS If set this callback is called when the packet is removed from the tx ring buffer For unacknowledged packets this is after sending the packet For acknowledged packets this is after successfully receiving an ACK for this packet callback argument is set to 1 or when all retries are made without success callback argument is set to 0 The callback function can check the variable txRetries to see how much retries it took always 0 for unacknowledged packets bool Net init Function Initializes the radio Parameter None Return value code True code always bool Net on Function Enables the radio Parameter None Return value code True code always bool Net off Function Disables the radio Parameter None Return value code True code always bool Net setTxPower UINT8
19. 08 SENSOR MOVEMENT 102 SENSOR VIBRATION 40 SENSOR VOLTAGE 80 SENSOR BUTTON 20 SENSOR LIGHT or a combination of this values erWeb 2 x Applications lt application gt lt platform gt ScatterWeb Event h ifnde defin f ScatterWeb_Event e ScatterWeb_Event finclude System src ScatterWeb System h define AF SERIAL 0x01 define AF RADIO 0x02 typedef struct UINT8 announceFlags UINT8 sensorMask appconfig t 0 P endif Processes events according to sensorMask and announceFlags 72 ScatterWeb inside t sensorMask contains what sensors will be processed commands rsm ssm 0x10 SENSOR VIBRATION Vibration sensor 0x08 SENSOR MOVEMENT PIR sensor 0x80 SENSOR_BUTTON Button 0x01 SENSOR_MICROPHONE Microphone 0x02 SENSOR_TEMPERATURE Temperature 0x04 SENSOR_RC5 RC5 Receiving 0x40 SENSOR_VOLTAGE Battery Voltage 0x20 SENSOR_LIGHT Light appconfig t announceFlags contains what will be done with sensor events commands raf saf 0x01 AF SERIAL Prints events to serial port 0x02 AF RADIO Broadcasts events in a SENSOR PACKET So to get all sensors reported over serial link and radio do lt code gt ssm FF saf 03 lt code gt bool Event init Function Initializes the event handling Parameter None Return value code True code always 4 2 How to install
20. 4558 inel 67 ScatterWeb inside 3 4 T 70 4 1 The EMPTY iir E Rr RE ERE 70 2 2 howto mstalls iion ioo Ud Ox II EE 73 2 3 HOW NO USO e et 74 4 4 HOWTOCDITIDIIQ a ooo die ceo bbb eoo aco etse edes 75 22 ee ie 76 Appendix A Terminal Command Listing 77 Appendix Terminal Command Availability 81 4 ScatterWeb inside 1 Platforms 1 1 Embedded Chip Radio Antenna Transceiver Flash Controller VIB Sensor Digital am Digital IO Ports The ECR has additionally a Temperature Sensor a red LED and a 64 Kbytes EEPROM Notice You need an appropriate flash cable obtainable on order and the JTAG also obtainable on order to flash the ECR ScatterWeb inside 5 1 2 Embedded Sensor Board ESB EV d 24 Transceiver Antenna PIR Sensor Beeper Reset Button Second Serial Flash The ESB has additionally a Temperature Sensor a VIB Sensor IR to send and to receive a Microphone and a 64 Kbytes EEPROM The ESB supports the RC5 infrared standard Notice You need the JTAG obtainable on order to flash the ESB and an appropriate serial cable also obtainable on order to interconnect the ESB and the PC PDA 6 ScatterWeb inside 1 3 Embedded EYE EYE
21. ESWs Sending and receiving of short messages SMS via connected mobile phone serial port Bluetooth connection available upon request standard for the EWS Just send the ESB an SMS triggering temperature monitoring every Tuesday morning from 7 00 a m until 11 43 a m if and only if there is movement in the room but no light it s possible with a single SMS Sending e g to control home entertainment devices and receiving e g from conventional remote controls of RC5 packets via infrared 12 ScatterWeb inside Periodic polling of sensor data and depending on settings automatic transmission via the radio interface the serial port terminal or mobile phone Simple and easy configuration and control of the ESB via terminal commands over the serial interface or radio Software The software of the sensor nodes was first separated into two parts firmware amp application to provide in field programming via radio This has recently changed because that reprogramming strategy created several problems Now the whole thing except the reprogramming code which should not change anymore see progamming c is reprogrammable Anyway the separation between firmware and application is kept because it proved good as hardware abstraction layer and to provide some OS like concepts The Firmware provides abstract functions to interface and use the hardware contains the main execution loop interrupts and provides some OS like con
22. ScatterWeb Event c Ejveid Process interceptRadioHendler a EE amp liy EOS Scatterweb Comm c 18 ScatterWeb Comm h Ejvoid Process radioHandler void receivedPacket d Scakterweb Configuration c Messaging radioHandler Scatterweb Configuration h if rxPacket to BROADCAST rxPacket to Configuration id 4 Scatterweb Data c Process interceptRadioHandler 19 ScatterWeb Data h C ScatterWeb IO c else 18 ScatterWeb IO h switch rxPacket type ScatterWeb Messaging c case PING PACKET 18 Scatterweb Messaging h if rxPacket to Configuration id 94 ScatterWeb Net c packet t packet I ScatterWeb Net h packet to rxPacket from packet type PONG PACKET Scatterweb String c packet header length 0 packet header NULL acc ih packet data length 0 packet data NULL al Net send spacket NULL 18 ScatterWeb System h break 94 ScatterWeb Threading c case PONG PACKET Ln Scatterweb Threading h if rxPacket to Configuration id Scatter Web Time c Comm print PONG from i r n rxPacket from a 8 ScatterWeb Time h 3 ScatterWeb Timers c ScatterWeb Timers h x Show output from Build Rebuild All started Project ESB Configuration Debug Win32 Performing Makefile project actions make C System bin ESB make l Entering directory cygdrive d Files AgTech ScatterUeb ScatterWeb API VS2005 Sca
23. ScatterWeb Messaging set boot log level sIb Valid values are ScatterWeb Configuration 01 NO 02 LOW 78 ScatterWeb inside 03 MEDIUM 04 HIGH 05 VERBOSE 20 DEBUG SYNC 40 DEBUG DCO 80 DEBUG RADIO or a combination of this values slg if 1 set green led on otherwise off ScatterWeb Messaging slo set log level Valid values are 01 02 LOW 03 MEDIUM 04 05 20 DEBUG SYNC 40 DCO 80 DEBUG RADIO or a combination of this values ScatterWeb Configuration slr if x 1 set red led on otherwise off ScatterWeb Messaging if 1 set yellow led on otherwise off ScatterWeb Messaging ssm set sensor mask to x Valid values are 01 SENSOR MICROPHONE 02 SENSOR TEMPERATURE 04 SENSOR RC5 08 SENSOR MOVEMENT 10 SENSOR VIBRATION 40 SENSOR VOLTAGE 802 SENSOR BUTTON 20 SENSOR LIGHT ScatterWeb Event ScatterWeb inside 79 or a combination of this values stp X set transmit power to x ScatterWeb Messaging swg toggle green led ScatterWeb Messaging swr toggle red led ScatterWeb Messaging swy toggle yellow led ScatterWeb Messaging tim read system time ScatterWeb Messaging tis x set system time to x seconds ScatterWeb Messaging tiz x set system time to x milliseconds ScatterWeb Messaging tmr read timers ScatterWeb Timers web X y
24. T Group forms a sound basis for research in sensor networks the development of university level courses in CS EE based on real hardware and prototyping of sensor net applications The ESBs are part of the ScatterWeb approach comprising a whole family of embedded web servers sensors and actors Typical communication scenarios of sensor networks based on the ESBs are ESBs communicate via the serial port with a standard PC for application development ESBs communicate with mobile phones via the serial port to connect to wide area mobile phone networks This enables remote configuration of ESBs via short messages SMS as well as reception of sensor data on arbitrary mobile phones world wide ESBs communicate via their radio interface with other ESBs or an embedded web server EWS to form a truly embedded highly flexible sensor network solution Main components of the ESB are the sensors a micro controller for processing of all data and a transceiver handling communication with other nodes Software for the following features is already available for the ESB 430 Configuration and analysis of all sensor data vibration noise movement temperature infrared luminosity Control of peripherals timer transceiver serial port EEPROM IR send receive LEDs beeper switches Sending and receiving of data packets via the radio interface transmission of sensor data communication with other systems using the same radio interface ESBs
25. TERNVOLTAGE ADC12MEM3 define BATTERYVOLTAGE ADC12MEMA define RXPVOLTAGE ADC12MEM5 define BATTERYVOLTAGE ADC12MEMA enum True 1 False 0 typedef typedef typedef typedef typedef typedef typedef typedef typedef typedef char bool 2 s tiempos unsigned char UINT8 unsigned int UINT16 unsigned long UINT32 17102 22812553 0 9 WAC Cer enero bare 001459 e Vordi Draco 9 12 161 eE tern volatile UINT16 runModule tern volatile UINT16 rxpTemp tern volatile UINT16 rxpValue tern volatile UINT8 MIC bool Sys temp t System getTemperature bool Sys bool Sys bool Sys bool Sys bool Sys bool Sys bool Sys lexoxoJL Sys UINT16 S bool Sys tem setDCO tem startWatchdog tem stopWatchdog tem reset tem wait UINT32 tem waitA UINT16 i tem powerOn tem powerOff ystem reprogram tem startConversion include lt msp430x14x h gt tem registerCallback UINT8 type void fp t 0 ScatterWeb inside 49 include lt io h gt include lt signal h gt include lt stdlib h gt include lt stdarg h gt if defined ECR
26. UINT16 datal UINT16 data2 bool Data sensorHandler void Data RC5ReceiveHandler void Data RC5EventHandler endif The ScatterWeb Data consists mostly of the functions that constitute the sensors architecture The sensors architecture enables you to build components that efficiently manage data from multiple data sources It provides the tools to initialize enable and disable data in this multiple tier system To get sensor events you must set a callback function in System callbacks C SENSOR for disabling that set System callbacks C SENSOR NULL Each sensor is separately enabled and disabled with its enable disable function The enable function takes some sensor specific arguments The first argument is the interval or debounce delay for reading the sensor internally it can also be seen as a reaction time for example for Vib If Vibration has been signaled how long the sensor must stay silent to signal NoVibration 22 ScatterWeb inside For temperature 4 arguments are needed to specify funnel function Data temperatureOn Interval StartRange Diff StepsPerDiff Interval How often is the temperature read in systems ticks 1ms StartRange How much must the temperature differ from the last value to get signaled Diff How much the Range is decreased every DiffStep measures StepsPerDiff How much measures until Range is decremented with Diff Attention Temperature data
27. a Function Adds or if it already exists resets a timer Parameter ticks ticks for elapse fp function to call if expired data parameter to call function without use OXFFFF Return value code True code if successful lt code gt False lt code gt otherwise bool Timers remove fp timer fp UINT16 data Function Removes timer if data is matching Parameter fp function to call if expired data parameter to call function without use OXFFFF Return value code True code if successful lt code gt False lt code gt otherwise bool Timers eventHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value ScatterWeb inside 69 4 Usage 4 1 The EMPTY application The EMPTY application presents the body to develop your own applications ScatterWeb Process The ScatterWeb Process module enables you to initialize and start your application ScatterWeb 3 x Applications lt application gt lt platform gt ScatterWeb Process c Special commands of ScatterWeb Process app read the name of the application You are able to include all needed files like ScatterWeb Event h include ScatterWeb Event h You are in a position to include the core of the ScatterWeb API finclude System src ScatterWeb System h The Process interceptRadioHandler handles all packets which are a
28. ags command t UINT8 messageSource bool Messaging on bool Messaging radioHandler bool Messaging doCommand const UINT8 str UINT8 flags void Messaging serialHandler endif The ScatterWeb Messaging provides functions that allow you to connect to monitor and message on the network and send receive or peek messages Control the MSP RS232 or radio with simple ASCII commands Remote command execution To issue an command over radio write id answers will get id prep ended 85 rid 85 85 85 tim 85 23080608 984 2001 09 25 03 16 48 ScatterWeb inside 35 Command creation Use the COMMAND macro to easily create a new terminal command The first argument to the Macros is always the three digit terminal command code The second argument to the Macros is a 8bit flag field For example the following 0 print test r n will evaluate to void term xxx const str attribute section commands const command t com xxx term xxx xxx 0 void term const UINT8 str print test r n Besides creating the function header it first creates a forward declaration which is then needed in the following definition of a const command t com xxx struct in the commands segment com xxx contains a pointer to the function the three digit function code and a flag field Because all those command t entries are put into a special segment command
29. al loading from EEPROM EADR_CONFIG is done by Configuration init and has to be called on initialization in main ScatterWeb inside 19 First time configuration Uncomment the following definition of firstTimeConfig and it will get laid into Infomem 0x1000 0x1100 see hex File Before Configuration init loads the regular config from EEPROM it checks if the first int which corresponds to the id in Infomem is not OxFFFF If it is not it copies the configuration from Infomem to EEPROM clearing Infomem afterwards and loading the newly written data from EEPROM to Configuration bool Configuration init Function Initializes configuration settings for the configuration section Parameter None Return value code True code always bool Configuration save Function Saves configuration settings for the configuration section Parameter None Return value code True code always bool Configuration print Function Prints configuration settings for the configuration section Parameter None Return value code True code always 20 ScatterWeb inside 3 3 ScatterWeb Data ScatterWeb 2 x System src ScatterWeb Data h ifndef ScatterWeb_Data define ScatterWeb_Data include ScatterWeb Time h define REDSTATE Data redLed define YELLOWSTATE Data yellowLed define GREENSTATE Data greenLed de
30. ame Command creation has changed and most commands are executable from a remote device with reply Commands can now be placed where they are needed Macros and a special section in flash build a table to automatically search all commands See ScatterWeb Messaging h Light sensor software has been removed due to complex handling Timer slots are also needed for constant dco checking amp adjusting ScatterWeb Timers h and a software RTC ScatterWeb Time h as the RTC is mostly abandoned because of its big current usage it s only used as an well calibrated temperature sensor ScatterWeb System h ScatterWeb Time h represents the new software RTC see currentTime ScatterWeb System h has been completely cleared only the function for reading the temperature and ensuring RTC 32 kHz output at initialization are left fiveMsTimer is replaced through currentTime or use of timers ScatterWeb Timers h its still left for internal timer use ScatterWeb Timers h module has been added no need to poll for an elapsed time anymore ScatterWeb System h includes DCO checking so DCO is recalibrated the whole time not at startup only Other modules have been more separated ScatterWeb Configuration h was in ScatterWeb IO h programming h was in flasher h The watchdog has been rewritten It s now correct and possible to see where a reset came from Additionally a feature has been added to watch stack growth and detect a stack overflow For bad conditio
31. ay delay of measurement code True code if vibration sensor available lt code gt False lt code gt otherwise bool Data vibrationOff Function Parameter Return value Disables the vibration sensor None code True code if vibration sensor available lt code gt False lt code gt otherwise ScatterWeb inside 29 bool Data lightOn UINT16 delay UINT16 thresh Function Enables the light sensor Parameter delay delay of measurement thresh threshold of measurement Return value code True code if light sensor available lt code gt False lt code gt otherwise bool Data lightOff Function Disables the light sensor Parameter None Return value code True code if light sensor available lt code gt False lt code gt otherwise bool Data greenLed Function Returns the state of the green LED Parameter None Return value code True code if green Led is switched on lt code gt False lt code gt otherwise bool Data redLed Function Returns the state of the red LED Parameter None Return value code True code if red Led is switched on lt code gt False lt code gt otherwise bool Data yellowLed Function Returns the state of the yellow LED Parameter None Return value code True codes if yellow Led is switched on lt code gt False lt code gt otherwise 30 ScatterWeb inside bool Data_RC5SendPHI int data
32. cepts The firmware supports all ScatterWeb MSP430 devices ESB and EYE eGate ECR The application userapp program is built on top of the firmware Directory tree Applications Contains application directories with PSPad project files System Contains firmware sources and binaries Major Changes Firmware and userapp are not that strictly separated anymore This made reprogramming easier and all restrictions from the old firmware lt gt userapp separation are gone Reprogramming code is now in programming h flasher h contains the radio transfer of code images For simplicity all 3 firmwares from ESB EYE eGate and ECR have been integrated into one with the use of ifdef at some hardware dependent places When compiling the command line one must always define one of ESB eGate ECR EYE This is done in the makefiles with the variable DEVICE The makefiles are now taking every source file they see in the directories and don t need to be changed for new removed files anymore Look into the makefiles and at new directory structure Radio software has changed Sending is now also done interrupt driven and comes with a ring buffer to store several packets to send Additional new features are crc16 checksums and automatic acknowledgements except broadcasts with feedback to the sender of every packet ScatterWeb inside 13 The terminal software has been moved to the firmware as many commands between devices were the s
33. curring interval at which the Elapsed event is raised in your application You can then handle this event to provide regular processing Software timers With theses function you can implement delays asynchronously Just give a time and a pointer to a function which should get called when the time has elapsed The timer entries are kept in a fixed size array MAX_TIMERS timers numberTimers The entry at position 0 will always contain the next timer to expire The ticks in the timer entries are not decreased with every system tick but first accumulated into _ticks until one of two things happen ticks becomes greater than timers O ticks what means that at least timers 0 has elapsed if no timer is running timers O ticks is set to OxFFFF so this will never happen then The interrupt routine sets calllimer to 1 and Timers eventHandler will execute It calls consolidate and all elapsed timers where ticks 0 An overflow when adding a new timer is detected For example a timer with 50000 ticks was added ticks has run up to 30000 and then a new timer with 40000 ticks comes in To get the correct offset for the timer it has to be added internally with 30000 40000 70000 ticks but that is greater than maximum integer value 65535 consolidate is called which decreases first timer to 20000 ticks to 0 the second timer is then added with 40000 ticks ScatterWeb inside 67 consolidate reads ticks and subtracts the value from all t
34. cvp Makes the task wait for a packet of a given type and a given sender if wanted A timeout can be set and Threading recvp works in promiscuous mode Threading send Threading esend A synchronous send task will continue after the packet was sent or lost removed from radio rx ring buffer Threading esend is for sending data from EEPROMm These are not many but suit the needs at the moment Constraints The goal was to write a task switching mechanism with minimal memory requirements Each preemptive OS requires and most cooperative OS use one stack per task Exceptions seen so far are PeerOS in the EYES Project which preempts only lower priority tasks and lets them reside at the stack while executing a higher priority task and Salvo which seems to implement a very similar approach To have a stack for each task increases memory requirements a lot because the size of the stack for a task is unknown and must be generously set The optimum would be the maximum stack depth of the task call tree A compiler could easily calculate this if recursion and function pointers are not used but i do not know if any compiler supports this feature The second bad is that most times a task won t use its maximum stack depth In contrast to theses approaches this mechanism uses no memory only some static allocated memory for task table and a little bit of stack space like in every other function is needed This puts some limits onto the task functi
35. ddressed to other nodes void Process interceptRadioHandler 70 ScatterWeb inside The Process radioHandler handles all packets void Process radioHandler Messaging radioHandler if rxPacket to BROADCAST rxPacket to Configuration id Process interceptRadioHandler else switch rxPacket type case PING_PACKET break case PONG_PACKET break default break The COMMAND app 0 approves other nodes to check which application on this node is running COMMAND app 0 String write term reply app EMPTY First of all the Process init will be called by the System when the complete core is initialized void Process init System registerCallback C RADIO Process radioHandler Sim 0 6 Comm log LOW Application s initialized r n r n imageData versionName ScatterWeb inside 71 ScatterWeb Event The ScatterWeb Event module presents methods for handling and forwarding sensor data events Special commands of ScatterWeb Event Scatt dsr set flags to print no sensor data to none esr set flags to print sensor data to radio raf read announce flags rsm read sensor mask saf set announce flags o Valid values are 01 AF_SERIAL 02 AF RADIO combination of this values ssm set sensor mask to x o Valid values are 01 2 SENSOR MICROPHONE 02 SENSOR TEMPERATURE 04 SENSOR RC5
36. ding_wait Threading_event hreading packe Threading_recv hreading recvp hreading send INTO 0 6 UINI Threading doEvents Threading add void address HG UINT8 adr UINT UINI UINI dl Handl ems tHandler 6 sender UINT8 bitmask Threading_sentPacketHandler UINT16 p 16 sender IIR EO Threading UIN UINT16 d UINT16 d1 PG tO UIN UINT16 type UINT16 type r16 type UIN r16 type UIN UIN UINT16 success UINT16 timeout UINT16 timeout 8 h UINT16 hl 8 UINT16 hl The ScatterWeb Threading provides functions that enable multithreaded programming ScatterOS This file implements a simple cooperative scheduling mechanism which allows to run task functions with OS like blocking calls which in fact do not block the processor but return control to the system and get later resumed 56 ScatterWeb inside The OS primitives at the moment are Threading doEvents Simply returns control to the system As this is cooperative scheduler long tasks or tasks which make no other Threading calls must interrupt themselves with Threading doEvents Threading sleep Makes the task wait a specified amount of system ticks may get longer if system is busy Threading wait Makes the task wait for a flag set Threading Threading re
37. e lt code gt False lt code gt otherwise bool Data beeperOn Function Parameter Return value Enables the beeper None code True code if beeper sensor available lt code gt False lt code gt otherwise bool Data beeperOff Function Parameter Return value Disables the beeper None code True code if beeper sensor available lt code gt False lt code gt otherwise ScatterWeb inside 25 bool Data beeperToggle Function Toggles the beeper Parameter None Return value code True code if beeper sensor available lt code gt False lt code gt otherwise bool Data buttonOn UINT16 delay Function Enables the button Parameter delay delay of measurement Return value code True code if button sensor available lt code gt False lt code gt otherwise bool Data buttonOff Function Disables the button Parameter None Return value code True code if button sensor available lt code gt False lt code gt otherwise bool Data greenOn Function Enables the green LED Parameter None Return value code True code if green led available lt code gt False lt code gt otherwise bool Data greenOff Function Disables the green LED Parameter None Return value code True code if green led available lt code gt False lt code gt otherwise 26 ScatterWeb inside bool Data greenToggle Function Toggles the
38. eb Messaging h if rxPacket to Configuration id 94 ScatterWeb Net c hONSC packets N ScatterWeb Net h packet to rxPacket from packet type PONG PACKET Scatterweb String c packet header length 0 packet header NULL packet data length 0 packet data NULL a 1 Scatterweb Synchronisation h Scatterweb System c 15 Scatterweb System h G ScatterWeb Threading c 18 ScatterWeb Threading h if rxPacket to Configuration id Ge ScatterWeb Time c Comm print PONG from ilrin rxPacket from 1 ScatterWeb Time h Scatter Web Timers c break ScatterWeb Timers h default break E COMMAND app 0 String write term reply void Process init System registerCallback C RADIO Process radioHandler Event init Comm log LOW Application initialized r n r n imageData versionNeme 3 lt 2 Ready ini Colt chi INS 74 ScatterWeb inside 4 4 ESB Microsoft Visual Studio File Edit View Project Debug Tools Window Community b Debug Win32 ScatterWeb Process c E Global Scope m v EF 5 2 Solution ESB 1 project Hinclude ScatterUeb Event h Bess include 1 1 Systen src ScatterWeb System h dy app 41
39. ecause of following problem The following instruction mov amp savedSP r1 is not really needed because if execution returns here the stack pointer should be what we saved before The important thing is to tell the compiler that the usually caller preserved registers r6 r11 may have changed The problem is the indexing into the Tasks table If following line is omitted the assembler output is scos prolog value Tasks currentTask address Tasks currentTask stackSize 7154 1e 42 5006 mov amp 0x0650 r14 0x0650 7158 3b 40 54 06 mov 1620 rii 40x0654 718a 60 12 42 71 call 28994 30x 7142 asm j volatile amp savedSP r1 restore stack pointer Tasks currentTask address 0x0000 718e 1e 42 5006 mov amp 0x0650 r14 0x0650 71a0 Of 5b add rtd ri5 2 71a2 8 43 00 00 mov 0 O r15 r3 As 00 Tasks currentTask state T DESTROYED 71b8 Of 5b add 11 ri5 5 71ba 8 43 04 00 mov 0 4 r15 3 As 00 ScatterWeb inside 59 That is bad At the beginning the base address of Tasks is moved into r11 for reading out of the table for the scos prolog call r11 is later after scos prolog call used to index into Tasks again and the compiler can assume that r11 did not change according to normal calling conventions but that may be wrong in this case When the following instruction is used the compiler omits the add r11 r15 and addresses the table directly asm volatile amp savedSP r1
40. erialHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value ScatterWeb inside 37 3 6 ScatterWeb Net ScatterWeb 2 x System src ScatterWeb Net h ifndef ScatterWeb_Net define ScatterWeb Net include define define define define define define define define define define define define define define ScatterWeb System h BROADCAST UNKNOWN ACKSPRACKE SYNC_PACKET E PING E PONG MESSAGING MESSAGING REPLY E REQUEST_PACKET E SCANNER_R SCANNER_R EPLY PACK SENSOR PACKET P T EOUEST PACKE E ej EPLY PACK DER define DER_REPLY define define FLASH FLASH REO fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine fdefine ROUTING INNER PACK P 57 ROUTING ROOT PACKE E ROUTING INFO PACKE E ROUT ING TREE PACKE RSA REQUEST PACKET RSA REPLY PACKET DHCP PACK DD INTERES ES ESSAGE DD MGMT PACKI Gl ESSAGE DD DATA M DD
41. ext to continue address in the task table change the state of the task and call scos exit scos exit now just restores the stack pointer to the value scos call saved and does a return which now is like the return of scos call and so the system is again in a clean state Related The System Stack Pointer SP The system stack pointer must always be aligned to even addresses because the stack is accessed with word data during an interrupt request service The system SP is used by the CPU to store the return addresses of subroutine calls and interrupts It uses a pre decrement post increment scheme The advantage of this scheme is that the item on the top of the stack is available The SP can be used by the user software PUSH and POP instructions but the user should remember that the CPU also uses the SP Figure 5 2 shows the system SP bits Call a subroutine CALL dst SP 2 SP PC 2 stack dst PC Return from subroutine RET MOV SP PC 58 ScatterWeb inside fno defer pop Always pop the arguments to each function call as soon as that function returns For machines which must pop arguments after a function call the compiler normally lets arguments accumulate on the stack for several function calls and pops them all at once Perhaps a cleaner and more portable but also more memory consuming implementation would be possible with setjmp longjmp macros Helper for scos call Had to be put into an extra function b
42. fference of 10 C A more low power option might be to not use checkDCO and just call System setDCO in long intervals a minute or even longer ScatterWeb inside 51 WATCHDOG Hardware watchdog LPM Power saving The sensor board features low power modes to reduce power consumption This increases battery powered lifetime up to years and makes it even possible to run the sensor board solely with a gold cap solar cell combo Following units can be switched off to reduce power consumption Unit Power consumption Corresponding function Comments ScatterWeb Net 4 7 5 2mA Net off Net on ScatterWeb Data 2 9mA System powerOff System powerOn The MSP430 itself goes to sleep when nothing more has to be done see super loop in main Power consumption with everything disabled Radio Sensor goes below 1mA This file contains special definitions amp configuration options for the firmware and includes all other headers The firmware provides abstract functions to interface and use the hardware contains the main execution loop interrupts and provides some OS like concepts The firmware supports all ScatterWeb MSP430 devices ESB EYE eGate ECR The first reprogramming concept which produced the firmware application separation was abandoned for two main reasons It relied stable almost never changing firmware At the moment this is absolutely wrong and it s questionable if it will ever be
43. fine SENSOR MOVEMENT 0x08 define SENSOR VIBRATION 0x10 define SENSOR BUTTON 0x80 define SENSOR MICROPHONE 0x01 define SENSOR TEMPERATURE 0x02 define SENSOR RC5 0x04 define SENSOR VOLTAGE 0x40 define SENSOR LIGHT 0x20 typedef struct UINT8 sensor time t timeStamp UINT16 value sdata t extern UINT8 Data sensorFlags bool Data init bool Data batteryOn UINT16 interval UINT16 thresh bool Data batteryOff bool Data beeperOn bool Data beeperOff bool Data beeperToggle bool Data buttonOn UINT16 delay 0 bool Data greenOn bool Data greenOff bool Data greenToggle bool Data redOn bool Data redOff bool Data redToggle ScatterWeb inside 21 bool Data yellowOn bool Data yellowOff bool Data yellowToggle bool Data microphoneOn UINT16 delay UINT16 diff bool Data microphoneOff bool Data movementOn UINT16 delay bool Data movementOff bool Data temperatureOn UINT16 interval UINT16 range UINT16 diff UINT16 spd bool Data temperatureOff bool Data vibrationOn UINT16 delay bool Data vibrationOff bool Data lightOn UINT16 delay UINT16 thresh bool Data lightOff bool Data greenLed bool Data redLed bool Data yellowLed bool Data RC5SendPHI int data bool Data RC5Enable bool Data RC5Disable bool Data RC5SendNEC
44. fixed point 9 7 2s complement format DS1629 initClock should be called at startup to check for the correct setting in the status register of the RTC Most functions of the clock have been removed due to high current usage while reading the clock Furthermore a software RTC has been implemented with a much finer resolution see ScatterWeb Time c The RTC is now only used as an well calibrated temperature sensor and only these functions remain here for complete clock interfacing code look into attic directory cl start cl stop cl writeOnBus cl readFromBus are the basic functions for interfacing the 2 like bus Ports ESB EYE clockSDA P50 clockSCL P51 clockAlarm P15 Note The sticks have no RTC and the ECR has the LM71 temperature sensor which is also realized in this file CRC This file offers CRC calculation DCO Initializing amp Controlling the DCO Digitally Controlled Oscillator If FF DCOCHECKER in config t firmwareFlags is set Timers init will add timer every 100 ms for checkDCO and enable Timer B1 interrupt The interrupt continually measures the ACLK with the DCO like in System setDCO and writes the result into dcoDiff checkDCO takes samples every 100 ms of dcoDiff and adjusts the DCO if needed As the DCO is temperature sensitive and both serial and radio communication depend on the DCO calibrating the DCO continuously is recommended Serial communication stops working at a temperature di
45. ggle bit 5 address bits 6 command bits 515 4 2 A0 5 C4 C2 C1 irdata format error newData 4 2 1 AO C5 C4 C2 61160 Some common addresses and commands Address Device Command 0 TV1 0 9 Numbers 0 9 channel select 1 TV2 12 Standby 5 16 Master Volume 6 VCR2 17 Master Volume 17 Tuner 18 Brightness 18 Audio Tape 19 Brightness 20 CD Player 50 Fast rewind 52 Fast run forward 53 Play 54 Stop 55 Recording It supports methods for sending with IR diode These methods are timed to the system clock 4505600 MHz and disable all interrupts and so will halt the system timer for some milliseconds Radio packet transmission amp reception are also disrupted 24 ScatterWeb inside bool Data init Function Parameter Return value Initializes the sensors None lt code gt True lt code gt if sensors available lt code gt False lt code gt otherwise bool Data batteryOn UINT16 interval UINT16 thresh Function Parameter Return value Enables the battery sensor interval interval of measurement thresh thresh of measurement code True code if battery sensor available lt code gt False lt code gt otherwise bool Data batteryOff Function Parameter Return value Disables the battery sensor None code True code if battery sensor availabl
46. h ifndef ScatterWeb IO define ScatterWeb IO define EEPROMADDRESS 0x00 define EEPROMPAGEMASK 0 7 bool IO erase UINT16 e adr UINT16 size 04 1421 02 22101150 1 6 VENELE Balz 7 1 555 4112 endif The ScatterWeb IO contains functions that allow reading and writing to the EEPROM Most important functions for writing reading the EEPROM are IO write IO read The EEPROM offers 64k memory 100000 write cycles and is accessed with an I2C like bus Currently use is storing configuration data see ScatterWeb Configuration c and temporary storage of a new software image before it gets flashed DEVICE ADDRESSING Start 1 0 1 0 A2 0 R W EEPROM memory map Region Usage o 0 0000 OxOCFF Free for use o 0 0000 OxODFF Application config APPCONFIG OxOEO0 OxOEFF Used by flasher c EADR FLASHERBUF Free for use only if flasher state IDLE OxOFOO OxOFFF Never change something here Used for configuration data ScatterWeb Configuration c CONFIG and some reprogramming variables o 0 1000 OxFFFF Programming image storage or other big data Use according to EEPROM EADR IMAGESTATE ScatterWeb inside 33 bool IO erase UINT16 e adr UINT16 size Function Parameter Return value Erase severa
47. imers i ticks or sets them to 0 if they are already smaller and ticks itself This is a safe way to synchronize with the interrupt and better than setting ticks to 0 because if ticks is just increased by the interrupt in between read and write the single tick will not get lost bool Timers init Function Parameter Return value Initialization of DCO TimerA TimerB and software timer table This method first calls SetDCO and initializes variables for timers Timer A is initialized to run from the divided 32 768 Hz Crystal at 4096 Hz Timer B is initialized to run from the self regulated DCO at 4 505600 MHz Timer 0 is used to generate an interrupt every 4 ticks once a 1024 second near to a millisecond Timer A1 3 is used by watchdog c to implement a software watchdog Timer BO is used by recir c to capture RC5 signals every 890 us Timer B1 6 is used to measure the DCO continously with TB6 None code True code always bool Timers add UINT16 ticks fp timer fp UINT16 data Function Parameter Return value Strictly adds a timer also if it exists already If ticks are passed the given functions is called ticks ticks for elapse fp function to call if expired data parameter to call function without use OXFFFF code True code if successful lt code gt False lt code gt otherwise 68 ScatterWeb inside bool Timers reset UINT16 t fp timer fp UINT16 dat
48. is in fixed point 2s complement format This approach also includes simple standard evaluation methods Periodic Reading To signal every x ms do Data temperatureOn x 0 0 0 Onchange Reading To signal only on temperature changes greater than x temperature is read every y ms do Data temperatureOn y x 0 0 Periodic amp On Change combined To signal on every change greater than x or after a time y z has passed temperature is read every z ms do Data temperatureOn z x x y Examples Data temperatureOn 5120 0 0 0 Every 5 seconds Data temperatureOn 2048 0x0080 0 0 Only on change greater 1 C temperature is read every 2 seconds Data temperatureOn 6144 0x0080 0x0080 20 Every 20 6s 2min or if changed more than 1 C temperature is read every 6 seconds Data temperatureOn 6144 0x0200 0x0040 10 Funnel function Measure every 6 seconds and decrease range from 2 C for 0 5 C every 10 6s 1min temperature is read every 6 seconds Power for sensors and RS232 voltage converter must be enabled see System powerOn System powerOff The IR Receiver is handled in file ScatterWeb Data c A good example for using the sensors is ScatterWeb Event c in EMPTY ESB project It s controlling the beeper It s receiving RC5 via IR Receiving Diode ScatterWeb inside 23 RC5 1780us bit length Manchester encoded so half bit length 890us is important Transferred packet 2 start to
49. ithout worrying about the specific details of the individual protocol ScatterWeb inside 39 This file contains following functionality for radio Setting of transmit power in 100 steps Interrupt driven rx amp tx radio MAC logic sending of packets with CSMA and random backoff CRC 16 checksums acknowledgement with automatic retransmission General Radio software supports acknowledgements so it is important to know that all packet types which are no broadcast will get acknowledged by radio software and get repeated several times if needed The radio software uses the num field for acknowledged packets to recognize doubles packet t is a struct containing a packet header fields and pointers to packet data and is used for sending amp receiving As a packet may be often constructed out of a header portion and a data portion packet t supports two data pointers to get passed in for sending so these portions don t need to be copied together When receiving however data pointer contains header and data consecutively and header and header length are null How to receive packets To receive packets of a specific type one must define a handler function and add it to Net txHandler for firmware handlers or to the RADIO app callback function When the handler is then called the function can access the received packet in rxPacket How to send packets For sending packets a packet t must be initialized to must contain
50. l bytes from EEPROM means set them to OxFF e adr start address of bytes to erase size size of bytes to erase code True code if erase successful lt code gt False lt code gt otherwise UINT8 IO read UINT16 e adr UINT8 adr UINT16 size Function Parameter Return value Reads size bytes from the EEPROM uses sequential read faster than readEEPROMByte e adr start address of bytes to read r adr array to store read bytes size size of bytes to read UINT8 pointer of r adr bool IO write UINT16 e adr UINT8 r adr UINT16 size Function Parameter Return value Writes size bytes to the EEPROM uses sequential write faster than writeEEPROMByte e adr start address of bytes to write r adr array of bytes to write size size of bytes to write code True code if write successful lt code gt False lt code gt otherwise 34 ScatterWeb inside 3 5 ScatterWeb Messaging ScatterWeb 2 x System src ScatterWeb Messaging h ifndef ScatterWeb Messaging define ScatterWeb Messaging define SERIALONLY 0x02 define COMMAND x flags void term 44x const UINT8 str attribute_ section commands const command_t com term_ x x flags void term const UINT8 str typedef void fp term const UINT8 extern UINT8 term reply TERM BUFSIZE typedef struct command struct fp term function UINT8 code 3 UINT8 fl
51. mm c 19 ScatterWeb Comm h Scatter Web Configuration c h ScatterWeb Configuration h G ScatterWeb Data c ScatterWeb Data h gt ScatterWeb IO c else h ScatterWeb IO h switch rxPacket type Scatterweb Messaging c case PING_PACKET h ScatterWeb Messaging h G ScatterWeb Net c ScatterWeb Net h G ScatterWeb String c if rxPacket to packet t packet Configuration id packet to rxPacket from PACKET packet header length 0 packet header NULL 2 Esc ail packet data length 0 packet data NULL 3 ScatterWeb Synchronisation c 1 ScatterWeb Synchronisation h Net send spacket NULL ScatterWeb System c 19 ScatterWeb System h break ScatterWeb Threading c case PONG PACKET ScatterWeb Threading h if rxPacket to Configuration id ScatterWeb Time c Comm print PONG from rxPacket from T h ScatterWeb Time h 4 ScatterWeb Timers c ScatterWeb Timers h Output ax Show output from Build x 5 Rebuild All started Project ESB Configuration Debug Win32 Performing Makefile project actions make C System bin ESB 11 Entering directory cygdrive d Files AgTech ScatterWeb ScatterWeb API VS2005 ScatterWeb 3 0 System bin ESB 11 Nothing to be done for firmvare make l Leaving directory cygdrive d Files AgTech ScatterWeb ScatterWeb API 052005 Scatte
52. n fast If a routine occupies the processor for a long time for example outputting a long text which works with the blocking sendRS232Char function it should call System startWatchdog repeatedly normally done in main to avoid a watchdog reset If a watchdog reset occurs the firmware will disable the programm if DISABLES USERAPP is set You don t need to change the makefiles anymore Makefiles in firmware and application automatically compile every c file in the src directories and look into every c and h file for changes No initialization of global values is done You can write UINT16 var 49 but var will never be initialized do initialization in code Initialization may work again if the standard startup routine is used Don t use dynamic memory allocation malloc free Dynamic memory allocation bears the following problems on MCUS o Much harder to debug o Unknown behavior at compile time o Memory fragmentation and no way missing MMU to defragment it o No memory protection between stack and heap which grow towards each other o Additionally current msp430 gcc malloc implementation seems to be buggy Sometimes an embedded engineer said Think small on MCUs If you are planning to use dynamic memory allocation you are thinking much too BIG f weird things happen look into linker map out map Sometimes compilation fails or hangs with existing objects files from another machine Do a
53. ns like that a panic function has been added The firmware can disable the application if a panic occurred An abstract printf like function has been implemented for string outputting String abstractWrite This is used by the functions String write to write a string to memory Comm print to write normal output to the serial port and Comm log to write debug output to the serial port No other methods should be used for writing to the serial port sendRS232 is not public anymore This is because serial port output is now controlled via Comm logLevel It allows several log levels some debug bits for special debugging and total disabling of all output see ScatterWeb Comm h A cooperative scheduler exists to create simple task functions ScatterWeb Threading h The main super loop goes to sleep when everything is processed all things that need to be handled are interrupt driven see main Every interrupt which needs processing from the super loop wakes the processor up with WAKEUPLPM1 which also sets a flag in runModule When all flags in runModule are reset after processing from super loop tasks the loop goes to LPM1 again If a function which needs calls as often as possible is added to the super loop you have to comment out the lines about sleeping Typedefs for UINT8 UINT16 UINT32 have been introduced because it is better style and much shorter 14 ScatterWeb inside Important things to know All routines should retur
54. ol bool endif Sync Sync Sync Sync hroni hroni hroni hroni hroni IMEOUT 5 _ LENGTH 3 ENGTH 4 sod UINT8 seqNum UINT16 masterRootId UINT8 syncPeriods Salon sation_isRoot sation_registerSyncDone fp_t fp sation registerSyncStart fp t fp sation radioHandler The ScatterWeb Synchronisation represents the synchronisation bool Synchronisation init Function Parameter Return value Initializes the synchronisation not started by system None code True code always bool Synchronisation isRoot Function Parameter Return value Checks if node is currently the root None code True code if node is root lt code gt False lt code gt otherwise 46 ScatterWeb inside bool Synchronisation registerSyncDone fp t fp Function Registers a function which is called if the sync ends Parameter fp function to call Return value code True code always bool Synchronisation registerSyncStart fp t fp Function Registers a function which is called if the sync starts Parameter fp function to call Return value code True code always bool Synchronisation radioHandler Function Filters packets for Synchronisation Parameter Return value code True code always ScatterWeb inside 47 3 9 ScatterWeb System ScatterWeb 2 x System src ScatterWeb System h ifndef ScatterWeb System
55. ons to make this possible Task functions can t and should never allocate stack space In fact you can allocate stack space and the scheduler will handle it properly that was needed for calls with long argument list which get pushed onto the stack but after a Threading call the stack content will always be undefined That means that all state must be held in vars declared globally Additionally they should be declared volatile so the compiler won t do any optimization on them hold them in registers also register content is undefined after a Threading call Secondly it means that blocking Threading functions are only allowed to call within your top level task function not in functions called from your top level task function ScatterWeb inside 57 The reason for that is again the stack which is undefined after a Threading call and so will thrash the return address for Threading calls anywhere outside from your top level task function How it works A task is initialized with Threading add which gets a pointer to the task function If a task can run like a newly added task sooner or later scos call with the id of the task in the task table and a value is called scos call saves the current stack pointer sets currentTask and calls the next to continue address of the task like a function with an int argument Then the task runs until it calls a Threading function These functions save the return address of the task on the stack as the n
56. onst UINT8 cs bool String writeTemperature fp char t writer temp t temp bool String abstractWrite fp char t writer const char fmt va list argp DO ONES teer cpm worse te COUSINS SAEI Si Cies UINT16 String parseInt const UINT8 c UINT8 ptr UINT32 String parseLongInt const UINT8 c UINT8 ptr fendif The ScatterWeb String represents text that is a series of Unicode characters int String writeUInt fp char t writer UINT16 number UINT16 length Function Converts int to String Parameter witer function to write number number to write length length to write Return value position in output out pos int String writeULongInt fp char t writer UINT32 number UINT16 length Function Converts long int to String Parameter writer function to write number number to write length length to write Return value position in output out pos ScatterWeb inside 43 bool String fromByteToHex UINT8 b UINT8 cs Function Converts the byte b into the string cs 0 cs 1 Parameter b byte cs string Return value code True code always UINT8 String fromHexToByte const UINT8 cs Function Converts the string at cs 0 cs 1 into a byte at b Parameter CS string Return value value to convert into bool String writeTemperature fp char t writer temp t temp Function Writes a temperature according to the format described in System
57. ophone sensor available lt code gt False lt code gt otherwise bool Data microphoneOff Function Parameter Return value Disables the microphone sensor None code True code if microphone sensor available lt code gt False lt code gt otherwise bool Data movementOn UINT16 delay Function Parameter Return value Enables the movement sensor delay delay of measurement lt code gt True lt code gt if movement sensor available lt code gt False lt code gt otherwise 28 ScatterWeb inside bool Data movementOff Function Parameter Return value Disables the movement sensor None lt code gt True lt code gt if movement sensor available lt code gt False lt code gt otherwise bool Data temperatureOn UINT16 interval UINT16 range UINT16 diff UINT16 spd Function Parameter Return value Enables the temperature sensor interval interval of measurement range range of measurement diff diff of measurement spd spd of measurement code True code if temperature sensor available lt code gt False lt code gt otherwise bool Data temperatureOff Function Parameter Return value Disables the temperature sensor None code True code if temperature sensor available lt code gt False lt code gt otherwise bool Data vibrationOn UINT16 delay Function Parameter Return value Enables the vibration sensor del
58. rWeb 3 0 Systemn bin ESB msp430 gcc Wall mmcu msp430x149 D ESB g 0 c src ScatterWeb Process c o bin ScatterWeb Process o msp430 gee Wl Map out out map cref Ul T System ldscript x W Wall mmcu msp430x149 g 0 o out out elf msp430 objcopy 0 ihex out out elf out out hex msp430 size out out elf text data bss dec hex filename 34212 4 1400 35616 8b20 out out elf ROM usage is text data RAM usage is data bss ESB 0 error s 0 warningis Rebuild All 1 succeeded 0 failed 0 skipped lt gt Rebuild All succeeded in 18 Colt chi INS 76 ScatterWeb inside Appendix Terminal Command Listing Command Parameter Description Location app read the name of the application ScatterWeb Process init Comm with x bps Valid values are 01 BPS 2400 brt X 02 BPS 14400 ScatterWeb Comm 03 BPS 19200 04 5 38400 05 5 57600 06 BPS 115200 dco x if x set dco if x set dco ScatterWeb Messaging dea erase eeprom ScatterWeb IO est prints software header of image ScatterWeb System flx x y broadcasting a userapp from x to y ScatterWeb System fst prints running software header ScatterWeb System Ist list commands ScatterWeb Messaging mem read free stack bytes ScatterWeb Messaging pel does a reset ScatterWeb Messaging png X send ping packet to x ScatterWeb Messaging raf read announce flags ScatterWeb Event
59. relied on the compiler linker to produce always the same assembler output for the firmware when it gets always the same sources object files This was only partially right it depended on too many factors compiler version compiler flags even the machine the compiler is running on and could be wrong under other or future conditions Perhaps one needs to write his own compiler linker or at least modify an existing one to really separate these two software parts on a MCU cleanly 52 ScatterWeb inside bool System registerCallback UINT8 type void fp_t Function Registers callback Parameter type type of callback function to call Return value code True code always temp t System getTemperature Function Returns temperature Parameter None Return value current temperature bool System setDCO Function Sets DCO Parameter None Return value code True code always bool System startWatchdog Function Starts watchdog Parameter None Return value code True code always bool System stopWatchdog Function Stops watchdog Parameter None Return value code True code always bool System reset Function Resets System Parameter None Return value code True code always ScatterWeb inside 53 bool System wait UINT32 Function Waits A simple looping waiting function Rough estimate at 2 4576 MHz w 1 gt 18us w 10 gt 62u
60. s the function doCommand can easily loop through this segment going from term start to term end also provide by the linker script and search for the command This even makes it possible to declare terminal commands where needed not only in ScatterWeb Messaging c The firmware commands will still stay centralized in ScatterWeb Messaging c to have code amp documentation of the firmware commands in one place The needed modifications of the linker script can be seen in System ldscript x dontinclude Idscript x skip text until gt text All commands must write their answer to term_reply and it should not be longer than TERM_BUFSIZE If nothing is written to term reply automatically an OK is generated The only exception to that is when the bit SERIALONLY in the flag field is set That means that the terminal command uses the serial functions directly not writing its answer to term reply and can t be called over radio 36 ScatterWeb inside bool Messaging Function Enables the Messaging started by system Parameter None Return value code True code always bool Messaging radioHandler Function Filters packets for Messaging Parameter Return value code True code always bool Messaging doCommand const UINT8 str UINT8 flags Function Executes a command Parameter str command to execute flags flags of the command Return value code True code always void Messaging s
61. s w 100 gt 500us w 400 gt 4ms This method has two big disadvantages it blocks and it s not accurate timers are better Parameter W ticks to wait Return value code True code always bool System waitA UINT16 i Function Waits which is more precise than wait because it uses TimerA to produce its interval also blocking Parameter i ticks to wait Return value code True code always bool System powerOn Function Enables the sensor and serial power Parameter None Return value code True code always bool System powerOff Function Disables the sensor and serial power Parameter None Return value code True code always UINT16 System reprogram Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value 54 ScatterWeb inside bool System startConversion Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value ScatterWeb inside 55 3 10ScatterWeb Threading ScatterWeb 2 x System src ScatterWeb Threading h ifndef ScatterWeb_1 define ScatterWeb 1 Threading Threading extern volatile UINT16 Threading_currentThread bool bool bool bool bool bool bool bool bool bool bool bool endif UI Threading init hreading sleep Threa
62. tterWeb 3 0 System bin ESB make 1 Nothing to be done for firmware make 1 Leaving directory cygdrive d Files AgTech ScatterWeb ScatterWeb API VS2005 ScatterWeb 3 0 System bin ESB msp430 gcc Wall mmcu msp430x149 D ESB g 0 c src ScatterWeb Process c o bin ScatterWeb Process o msp430 gcc Wl Map out out map cref W1 T System ldscript x W Wall mmcu msp430x149 g 0 o out out elf msp430 objcopy 0 ihex out out elf out out hex msp430 size out out elf text data bss dec hex filename 34212 4 1400 35616 8b20 out out elf ROM usage is text data RAM usage is data bss ESB 0 error s 0 warning s Rebuild All 1 succeeded 0 failed 0 skipped lt 1 Rebuild All succeeded Coll chi INS ScatterWeb inside 75 4 5 How to flash Fil ESB Microsoft Visual Studio C WINDOWS system32 cmd exe key 1 5 3e 151 catterMebNScatterWeb PI US2985 Scatterllieh 3 8 Applicatio B ESB gt make flash jtag w D ep i B48 out out he parallel JTAG X Solution Explorer Solution ESB 1 project 2 X 2 4 2 67 Sep 28 2005 12 41 11 MSC v 131 32 bit lt Intel gt ctypes Solution ESB 1 project gt actionMassErase Giese TODO 1 app actionProgram 5 ScatterWeb Event c IMSP43Onspgcc dll so ver 5 ScatterWeb Event h ScatterWeb Process c 5 Eos C Scatterweb Co
63. value Function Sets the transceiver power Parameter value tx power to set Return value code True code if value are between 0 and 100 lt code gt False lt code gt otherwise ScatterWeb inside 41 bool Net send packet t packet fp char t callback Function Sends a packet over radio Parameter packet packet to send callback will call after sending without use NULL Return value code True code if packet is successfully buffered lt code gt False lt code gt otherwise bool Net rxHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value bool Net txHandler Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value char Net esend packet t packet fp char t callback Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value 42 ScatterWeb inside 3 7 ScatterWeb String ScatterWeb 2 x System src ScatterWeb String h ifndef ScatterWeb String define ScatterWeb String int String writeUInt fp char t writer UINT16 number UINT16 length int String writeULongInt fp char t writer UINT32 number UINT16 length bool String fromByteToHex UINT8 b UINT8 cs UINT8 String fromHexToByte c
64. write y at x of eeprom ScatterWeb IO 80 ScatterWeb inside Appendix Terminal Command Availability Command ECR ESB EYE eGate USB eGate WEB app x x x x x brt x x x x x dco x x x x x dea x X X x x est X X X X X fix x x x x x fst x x x x x Ist x x x x x mem x x x x x pel X X X X X png x x x x x raf x x x x x rbu x x rcf x x x x x rer x x x x x rff x x x x x rfl x x x x x rfr x x x x x rid x x x x x rib x x x x x x x x x rlo x x x x x x x x x x rly x x x x rmm x x x x x x x rsm x x x x x rsp x x x x x RST X X X x x ScatterWeb inside 81 rtt rvb rve saf sbp SCO sff sfr sid sir slb slg slo slr sly ssm stp SWg swr tim tis tiz web 82 ScatterWeb inside
65. y from your code Parameter Return value bool Threading send UINT16 to UINT16 type UINT8 h UINT16 hl UINT8 d UINT16 dl Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value 62 ScatterWeb inside bool Threading esend UINT16 to UINT16 type UINT8 h UINT16 hl UINT16 d UINT16 dl Function This member supports the ScatterWeb infrastructure and is not intended to be used directly from your code Parameter Return value ScatterWeb inside 63 3 11 ScatterWeb Time ScatterWeb 2 x System src ScatterWeb Time h ifndef ScatterWeb Time define ScatterWeb Time include ScatterWeb System h define CURRENT TIME extern volatile time t currentTime eau N time currentTime eime O2 N define CURRENT TIME GEN 568 un extern volatile time_t currentTime UINT32 secs N 20020 8 N secs currentTime secs Simce OQA N Secs typedef struct UINT8 year UINT8 month UINT8 day UINT8 hour UINT8 min UINT8 sec btime t typedef struct UINT32 secs UTENTES ob ep 64 ScatterWeb inside time Time getSystemTime time time bool Time setSystemTime time t time
Download Pdf Manuals
Related Search
Related Contents
Avaya Configuring ATM and MPLS Services User's Manual Mise en page 1 DSLR-A200 Samsung Galaxy Tab 2 (10.1, Wi-Fi) Uživatelská přiručka Die Heiland-Trilogie Samsung Q1244V Manuel de l'utilisateur Avaya Integrated Management Release 6.0 Network Management Configuration User's Manual la version pdf MKR 61 teclado enrollable manual de instrucciones KING FRELON Copyright © All rights reserved.
Failed to retrieve file