Table of Contents

1. Blink examples and Wsim main options
2. WSim logging options and simulation informations
3. WSim execution traces and events
4. Serial port communications and external programs
5. Step by Step debugging using GDB
6. WSim and eSimu performance estimation

The repository contains several examples already using the WaspOS API. They can be found in /comb/trunk/firmware/apps/samples/

examples:

1. Blink examples and Wsim main options

#! /bin/sh
WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2

MODE="--mode=time --modearg=10s"

${WSIM} ${MODE} --ui $1

Sample application Screenshot : 01_blink_led

Figure IV.1. Sample application Screenshot : 01_blink_led


2. WSim logging options and simulation informations

#! /bin/sh
WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2

LOG="--logfile=wsim.log --verbose=2"
MODE="--mode=time --modearg=10s"

${WSIM} ${MODE} --ui ${LOG} $1

WSim 0.99.1svn, copyright 2005, 2006, 2007, 2008, 2009
Laboratoire Citi, INRIA, INSA de Lyon
A. Fraboulet, G. Chelius, E. Fleury
wsim:pid:27823
wsim: 64 bits edition
mcu   : msp430
model : msp430f1611
  xin : 32768
  xt2 : 0
wsim:libselect_socket:init: udp:localhost:6000:localhost:7000
libselect:skt: localhost
libselect:skt: 6000
libselect:skt: localhost
libselect:skt: 7000
wsim:libselect_socket:init: udp link creation for localhost:6000 to localhost:7000
wsim:libselect_socket:init: done
wsim:libselect:create: udp:localhost:6000:localhost:7000, id=0, fd_in=5
wsim:libselect:register: id=0, fd_in=5
libelf: file size 212466
libelf: memory allocation ok
libelf: opening elf file 01_blink_led/mantis_trace/01_blink_led.elf

libelf:hdr: Elf file header
libelf:hdr: ident 7f 45 4c 46 01 01 01 ff 00 00 00 00 00 00 00 00 
libelf:hdr:id: class         1 ELF32
libelf:hdr:id: data          1 2's LSB
libelf:hdr:id: version       1
libelf:hdr:id: abi type    255 Standalone
libelf:hdr:id: abi version   0
libelf:hdr:id: pad           0
libelf:hdr: type    2 Executable

[...]

[...]

== Machine description
mcu   : msp430
model : msp430f1611
  xin : 32768
  xt2 : 0
device list:
  dev 00 : System Platform
  dev 01 : Led display
  dev 02 : Led display
  dev 03 : Led display
  dev 04 : at45db flash memory
  dev 05 : cc2420 radio device
  dev 06 : ptty serial I/O
==
gui:Pixel format 0xfafafa
gui:Display 212x134x24 
gui:   3 bytes per pixel, pitch 636
gui:   mask R 0x00ff0000 G 0x0000ff00 B 0x000000ff A 0x00000000
gui:   colorkey 0x00000000
wsim: starting tracer
msp430:basic_clock: speed tracer start
cc2420:state: ENTERING VREG_OFF
machine: will run for 50000000000 nano seconds
msp430:intr: Interrupt 5 received but GIE = 0 (current PC = 0x435c [29872300])
iclbsn: writing on port 3 byte 0x0a at PC 0x4c88
iclbsn: cc2420 CS set to 1
cc2420:pins:write: from mcu CSn = 1
iclbsn: writing on port 2 byte 0x10 at PC 0x4ad6
iclbsn: writing on port 2 byte 0x10 at PC 0x4b04
iclbsn: writing on port 2 byte 0x00 at PC 0x4b6a
iclbsn: writing on port 2 byte 0x10 at PC 0x4b7a
iclbsn: writing on port 2 byte 0x00 at PC 0x4c3a
iclbsn: writing on port 2 byte 0x10 at PC 0x4c46
iclbsn: writing on port 2 byte 0x00 at PC 0x4c3a
iclbsn: writing on port 2 byte 0x10 at PC 0x4c46
iclbsn: writing on port 2 byte 0x00 at PC 0x4c5e

[...]

[...]

================
WSim stats:
-----------
  simulation user time          : 18.18401 s (18401150000 ns)
  simulation backtracks         : 0

Machine stats:
--------------
  simulated time                : 50000000266 ns (50.000 s)
  simulation speedup            : 2.72
  machine exit with signal      : none

MCU:
----
  simulated mcu instructions    : 7932566
  simulated mcu cycles          : 22287486
  simulated mcu mean freq       : 445749.72 c/s (0.45 MHz)
  simulation mean freq          : 1211200.62 c/s (1.21 MHz)
     - does not take into account sleep modes
  mcu exit at PC                : 0x5386
  mcu exit in LPM mode          : LPM0
  mcu exit with IV              : 0x0000

DEVICES:
--------
  - System Platform             :
  - Led display                 :
  - Led display                 :
  - Led display                 :
  - at45db flash memory         :
  - cc2420 radio device         :
  - ptty serial I/O             :

================

3. WSim execution traces and events

#! /bin/sh
WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2
WTRC=~/wasp/build/wtracer/src/wtracer 

LOG="--logfile=wsim.log --verbose=2"
TRC="--trace=wsim.trc"
MODE="--mode=time --modearg=10s"

${WSIM} ${MODE} --ui ${LOG} ${TRC} $1
${WTRC} --in=wsim.trc --out=wsim.vcd --format=vcd

gtkwave wsim.vcd

Sample application Screenshot : 01_blink_led, led traces

Figure IV.2. Sample application Screenshot : 01_blink_led, led traces


Sample application Screenshot : 01_blink_led, traces

Figure IV.3. Sample application Screenshot : 01_blink_led, traces


Sample application Screenshot : 01_blink_led, traces (zoom)

Figure IV.4. Sample application Screenshot : 01_blink_led, traces (zoom)


Traces from WSim can also be used to draw plots using Gnuplot. The following figure is obtained from the simulation

wtracer --in=wsim.trc --format=gplot --out=wsim.gp
gnuplot < wsim.gp

Sample application Screenshot : 01_blink_led, traces (zoom)

Figure IV.5. Sample application Screenshot : 01_blink_led, traces (zoom)


4. Serial port communications and external programs

Sample application Screenshot : 02_trace_demo

Figure IV.6. Sample application Screenshot : 02_trace_demo


#! /bin/sh
WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2
WTRC=~/wasp/build/wtracer/src/wtracer 

LOG="--logfile=wsim.log --verbose=2"
TRC="--trace=wsim.trc"
SERIAL="--serial1_io=udp:localhost:6000:localhost:7000"
MODE="--mode=time --modearg=10s"

${WSIM} ${MODE} --ui ${LOG} ${TRC} ${SERIAL} $1
${WTRC} --in=wsim.trc --out=wsim.vcd --format=vcd

nc -u -p 7000 localhost 6000

Sample application Screenshot : 02_trace_demo, serial through UDP

Figure IV.7. Sample application Screenshot : 02_trace_demo, serial through UDP


#! /bin/sh
WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2
WTRC=~/wasp/build/wtracer/src/wtracer 

LOG="--logfile=wsim.log --verbose=2"
TRC="--trace=wsim.trc"
#SERIAL="--serial1_io=stdout"
SERIAL="--serial1_io=udp:localhost:6000:localhost:7000"
MODE="--mode=time --modearg=10s"

${WSIM} ${MODE} --ui ${LOG} ${TRC} ${SERIAL} $1
${WTRC} --in=wsim.trc --out=wsim.vcd --format=vcd

./bsnmon udp:localhost:7000:localhost:6000

Sample application Screenshot : 02_trace_demo, serial through bsnmon

Figure IV.8. Sample application Screenshot : 02_trace_demo, serial through bsnmon


5. Step by Step debugging using GDB

#! /bin/sh
WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2
WTRC=~/wasp/build/wtracer/src/wtracer 

LOG="--logfile=wsim.log --verbose=2"
TRC="--trace=wsim.trc"
SERIAL="--serial1_io=udp:localhost:6000:localhost:7000"
#MODE="--mode=time --modearg=10s"
MODE="--mode=gdb"

${WSIM} ${MODE} --ui ${LOG} ${TRC} ${SERIAL} $1
${WTRC} --in=wsim.trc --out=wsim.vcd --format=vcd

Sample application Screenshot : 02_trace_demo, step by step mode

Figure IV.9. Sample application Screenshot : 02_trace_demo, step by step mode


The debugger can be used to go through the code and find out why and how the leds are toggled on and off in the blink_example

target remote localhost:2159
break main
continue
break mos_led_on
continue

The blinking program uses macros in mos_led_on(). Steping through the code will go over macros and hide their internals. To see the correct behavior in the code you have to go through assembly step by step by using the stepi command.

[Note]GDB step and next behavior

The current msp430 GDB version (6.8) has a problem using the next command and the behavior of a step command is executed. In order to debug msp430 without going through all instructions you have to place breakpoints and exec a continue command. GDB 5.1 does next and step commands with a correct behavior.

6. WSim and eSimu performance estimation

[Note]Including eSimu tracer

WSim must be compiled with eSimu trace output. The --enable-etrace switch must be set on the configure command line when building WSim.

An eSimu enabled version of WSim provides two new command line options.

--esimu[=arg]          : enable energy trace
--esimu-start          : enable energy trace from simulation start

The first option is used to specify the name of the trace file. The second option is used to start eSimu trace recording right from the beginning of the simulation. Without this option a special macro must be used to in the msp430 code to trap the simulator and start and stop simulation traces.

Be aware that the trace file might get very large if you use it for a complete simulation. The start/stop mode is used to monitor specific portions of a complete application and can be used within a loop or within a function. Results are cummulative and will represent all calls to the function or parts of a loop

#! /bin/sh
#WSIM=~/wasp/build/wsim/platforms/iclbsn/wsim-iclbsn2
WSIM=~/wasp/build-esimu/wsim/platforms/iclbsn/wsim-iclbsn2
WTRC=~/wasp/build/wtracer/src/wtracer 
ESIM=~/wasp/build/esimu/src/eSimu

LOG="--logfile=wsim.log --verbose=2"
TRC="--trace=wsim.trc"
SERIAL="--serial1_io=udp:localhost:6000:localhost:7000"
MODE="--mode=time --modearg=10s"
ETRC="--esimu=wsim.etr --esimu-start"

${WSIM} ${MODE} --ui ${LOG} ${TRC} ${ETRC} ${SERIAL} $1
${WTRC} --in=wsim.trc --out=wsim.vcd --format=vcd
${ESIM} 

esimu -i wsim.etr -p -e 01_blink_led/mantis_trace/01_blink_led.elf

----------------------------------
Generating the energygrind file :
         ./energygrind.out
(II) First == 0x00004000
----------------------------------
Summary 
Cycles  :          10000000540
Energy  :       11968683449310 fJ (1.196868e-02 J)
IC_miss :                    0
DC_miss :                    0

kcachegrind energygrind.out

Sample application Screenshot : 01_blink_led, performance estimation

Figure IV.10. Sample application Screenshot : 01_blink_led, performance estimation


Sample application Screenshot : linear energy consumption

Figure IV.11. Sample application Screenshot : linear energy consumption