NanoRK And
Zigduino
wnfa ta course
hikaru4
Today's outline
● Zigduino v.s. Firefly
● Atmel processor and the program chip
– Atmega128rfa1, FTDI chip...
● I/O Interface on the board
– GPIO, ADC, UART, SPI, I2C...
● NanoRK
● NanoRK OS Architecture
● NanoRK HOWTOs
● Tips and Tricks
● Lab2 announcement.
Zigduino
History
● Firefly
● CMU
● Firefly1.0
● Firefly2.2
● Firefly2.3
– no longer manufacture
● Firefly3.0
– Not release yet
– atmega128rfa1
● Zigduino
● logos
electro.com
● Arduinocompatible
– Arduino is an open
source electronics prototyping platform.
● Atmega128rfa1
– The same one as firefly3's
Zigduino
● Atmega128rfa1
● FTDI
● Clock Speed 16 MHz
● Flash Memory 128 KB
● SRAM 16 KB
● EEPROM 4 KB
● Radio 802.15.4(zigbee)
I/O interface
● GPIO(pin2~10)
● ADC(analog in 0~6)
● UART(RX, TX pin0,1)
● SPI(11 (MOSI), 12 (MISO), 13 (SCK))
● I2C(I2C SDA, SCL)
GPIO
● General Purpose Input/Output
● Pin2~10
● Digital input
● Digital output
● Control direction by some selector
GPIO
● Tristate Buffer Port
● MemoryMapped IO
● Control Registers
● Data Direction Register (DDR, TRIS)
● Internal Pull Up Register (PLP)
● Reading / Writing to the Port
GPIO
● Example
● LED, buzzer,
7segment display
– http://www.youtube.com/watch?v=fIjj6yDIe40
● Switch, button
– http://www.youtube.com/watch?v=qxJvsL6ES0k
ADC
● Analog to Digital Converter
● ANALOG IN 0~6
● Analog input
● Converts an Analog Signal to a Digital One
● 10 bit Resolution
ADC
● Example
● Sensor: Light sensor, temperature sensor....
UART
● Universal Asynchronous Receiver / Transmitter
● RX, TX (pin0,1)
● Serial port
communication
UART
● RX>TX
● TX>RX
● Baud rate
UART
● Example
● Open log, T07AW, GPS module...
SPI and I2C
● SPI(11 (MOSI), 12 (MISO), 13 (SCK))
● I2C(I2C SDA, SCL)
● Serial bus protocol
SPI(Serial Peripheral Interface)
● 4 Wire Serial Bus from Motorola
– MISO/MOSI <=> RX/TX
– SCLK => baud rate
– SS => slave select
I2C(InterIntegrated Circuit)
● Multidrop 2 wire serial bus protocol from Philips
– SCL: Serial Clock
– SDA:Serial Data Line
● Two Bidirectional OpenDrain Lines
Data transfer is initiated with the START bit (S) when SDA is pulled low while SCL stays high. Then, SDA sets the transferred bit while SCL is low (blue) and the data is sampled (received) when SCL rises (green). When the transfer is complete, a STOP bit (P) is sent by releasing the data line to allow it to be pulled up while SCL is constantly high.
NanoRK
What is nanoRK?
● A Realtime Operating System for sensor nodes for use in wireless sensor networks
● PriorityBased Preemptive Multitasking
● Resource Reservations
NanoRK feature
● C GNU toolchain
● Classical Preemptive Operating System Multitasking Abstractions
● RealTime Priority Based Scheduling
● Builtin Fault Handling
● Energy Efficient Scheduling based on aprior taskset knowledge
● Tickless Timer
● Small Footprint (<2K RAM, 16K ROM, including link layer)
NanoRK Motivation
● Why Prioritybased scheduling?
Timetriggered task interleaving can become daunting...
Period Execution Time Network Radio Sporadic 10ms
Audio Sensor 200 hz 10us Smart Camera 1 hz 300ms Global Positioning 5 hz 10ms
NanoRK Reservations
● CPU Utilization
● Time Allowed Per Period
● For example, a task can run for 10ms of time every 250ms
● Network Utilization
● Packets In and Out Per Period
● Sensors & Actuators Usage
● Sensor Readings Per Period
NanoRK Architecture
NanoRK Time Management
● ~1ms OS Tick Resolution
● Variable Tick Timer (interrupts occur as required, not every quantum)
● wait_until_xxx() functions
● Suspend task until the event or timeout happens
● If there is no wait_until_xxx() call, then your reserve will be violated
● If reserves are disabled, then this can starve low priority tasks and will waste battery power
Creating a NanoRK Task
NRK_STK TaskOne_Stack[NRK_APP_STACKSIZE];
nrk_task_type TaskOne;
void Task1(void);
...TaskOne.task = Task1;
nrk_task_set_stk( &TaskOne, TaskOne_Stack, NRK_APP_STACKSIZE);
TaskOne.prio = 2;
TaskOne.FirstActivation = TRUE;
TaskOne.Type = BASIC_TASK;
TaskOne.SchType = PREEMPTIVE;
TaskOne.period.secs = 0;
TaskOne.period.nano_secs = 100*NANOS_PER_MS;
TaskOne.cpu_reserve.secs = 0;
TaskOne.cpu_reserve.nano_secs = 10*NANOS_PER_MS;
TaskOne.offset.secs = 0;
TaskOne.offset.nano_secs= 0;
nrk_activate_task (&TaskOne);
NanoRK Fault Handling
● Task Time Violations
● OS will enforce time bounds given to a task
● Canary Stack Check
● Check if userspecified stack has been overflowed
● Not 100%, but incurs low overhead and better than nothing
● Unexpected Restarts
● Capture restart that occurs without powerdown
● Resource Overuse
● Manage sensors / actuators
● Low Voltage Detection
● Watchdog Timer
Configure NanoRK (nrk_cfg.h)
#define NRK_REPORT_ERRORS // print error over serial
#define NRK_HALT_ON_ERROR // stop the kernel on error
#define NRK_STACK_CHECK // Enable Canary Stack Check
#define NRK_NO_POWER_DOWN // zigduino need this define
#define NRK_MAX_TASKS 2
// Max number of tasks in your application
#define NRK_MAX_RESOURCE_CNT 1
// The number of semaphores in the system.
#define NRK_TASK_IDLE_STK_SIZE 64 // Idle task stack size min=32
#define NRK_APP_STACKSIZE 128
#define NRK_KERNEL_STACKSIZE 128
Take a break
● Next coming:
● Soldering
● NanoRK howtos
– API, debug tips
● NanoRK learning by doing
Soldering
● Some tutorial
● http://www.youtube.com/watch?v=q_xLuGPhzk
● http://v.youku.com/v_show/id_XMjMwMTUyNDU2.html
NanoRK API Quick Guide
● How to find the API you need?
● Take a look of sample code
– In folder: nanoRK/project/
● Go official API document
– http://www.nanork.org/wiki/Documentation
● Trace the source code
– http://mvnl.csie.ntu.edu.tw/nanoRK/HTML/
● Write one!!! (you will need the datasheet)
– http://ppt.cc/Q2~L
NanoRK API Quick Guide
● Example:
● svn://mvnl.csie.ntu.edu.tw/wn11fall/lab/examples/
● led_blink
– nrk_gpio_direction()
– nrk_gpio_set(), nrk_gpio_clr(), nrk_gpio_toggle()
● basic_tasks
– nrk_task_type
NanoRK Debug?
● printf() is your good friend
● You will need a serial console.
– Unix like: minicom
– Windows: teraterm, putty, hyperterm...
● Remember printf is slow.
● LED is your good friend
● pin13 = L, RFRX, RFTX
● plug more LEDs on GPIO
● much faster then printf()
NanoRK Tips and Tricks
● Tip 1. NO MORE UP arrow!!!
● “$ make clean && make && make program || make program”
● Save your time from typing and typing again during debugging.
(Or press UP arrow again and again).
NanoRK Tips and Tricks
● Tip 2. NO MORE vim makefile!!!!
● “$ make clean ROOT_DIR=~/nanoRK”
● “$ make ROOT_DIR=~/nanoRK”
● “$ make program ROOT_DIR=~/nanoRk/nanoRK PROGRAMMING_PORT=/dev/ttyUSB0”
● Don't waste your time to edit the makefile anymore.
NanoRK Tips and Tricks
● Tip 3. No MORE ctrl+a o!!!!!
● “$ LANG=C ;minicom o D /dev/ttyUSB0”
● Don't waste your time to setup the minicom anymore.
NanoRK Tips and Tricks
● Tip 4. Where is my warning/error??????
● “$ make 2>&1 | grep main.c:”
● “$ make 2>&1 | egrep 'main.c:|
myinclude.c'”
● Get your warning/error messages only.
Lab2
Zigbee RSSI localization
Lab2: zigbee RSSI localization
● Path loss exponent : step by step
● Get distance from RSSI
● Localization
● The nodes we set at CSIE 2F
● What you need to do
● Path loss exponent
● Localization algorithm
Path loss exponent
● Free space:
Pr =
4d
2
⋅Pt , Pr ∝ 1 d
2
10logPr = −2⋅10logdc
PrdBm = −2⋅ddBunitc
Path loss exponent
● Logdistance path loss model:
Pr ∝ 1 d
n
10logPr = −n⋅10logdc
PrdBm = −n⋅ddBunitc
Receive power v.s. Path loss
● Path loss:
PL = Pt
Pr ∝ dn
10logPL = n⋅10logdc
PLdB = n⋅ddBunitc
Path loss exponent
Pr ∝ 1 d
n PrdBm = −n⋅ddBunitc
RSSI to distance
Pr ∝ 1 d
n PrdBm = −n⋅ddBunitc
localization
The node we set at CSIE 2F
What you need to do?
● Path loss analysis
● Measurement the RSSI with different distance
● Take log scale
● Draw the regression line of path loss
What you need to do?
● Design the localization algorithm
● Base on RSSI
● Real time localization
● Demo
● We will announce the free time slots of the TAs.
Q&A
●