NanoRK on zigduino
Today's outline
● NanoRK
● NanoRK TASKs
– Period time, Reserve time
– Wait and Signal
● NanoRK bmac & basic_rf
● Tips and Tricks
NanoRK task
What is nanoRK?
● A Realtime Operating System for sensor nodes for use in wireless sensor networks
● PriorityBased Preemptive Multitasking
● Resource Reservations
PriorityBased Preemptive Multitasking
● Priority
● Preemptive
● Multitask
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.prio = 2;
TaskOne.FirstActivation = TRUE;
TaskOne.Type = BASIC_TASK;
TaskOne.SchType = PREEMPTIVE;
TaskOne.period.secs = 0;
TaskOne.period.secs = 0;
TaskOne.period.nano_secs = 100*NANOS_PER_MS;
TaskOne.period.nano_secs = 100*NANOS_PER_MS;
TaskOne.cpu_reserve.secs = 0;
TaskOne.cpu_reserve.secs = 0;
TaskOne.cpu_reserve.nano_secs = 10*NANOS_PER_MS;
TaskOne.cpu_reserve.nano_secs = 10*NANOS_PER_MS;
TaskOne.offset.secs = 0;
TaskOne.offset.nano_secs= 0;
nrk_activate_task (&TaskOne);
Task pool
Control the NanoRK tasks
● Task Management
● nrk_wait_untiil_next_period();
● Scheduling base on priority
Task2 Priority=2
Task3 Priority=3
Task pool wait_next Task1
Priority=1 Task2 Priority=2
Task3 Priority=3
Task pool Task2 Priority=2
Task3 Priority=3 Task pool Task3
Priority=3 Task2 Priority=2
Task1 Priority=1
Task pool
Control the NanoRK tasks
● Signals
● Create and signal
– nrk_sig_t signal_one;
– signal_one=nrk_signal_create();
– nrk_event_signal( signal_one );
● Wait a signal
– nrk_signal_register(signal_one);
– nrk_event_wait(SIG(signal_one));
Task2 Priority=2
Task3 Priority=3 Task pool
signal(two)
Task1
wait(one) Task2 wait(two)
Task3 wait(three)
Task pool Task2 Priority=2
Task3 Priority=3 Task pool Task2
wait(two)
Task1 wait(one)
Task3 wait(three)
Cpu reserve time
● Resource Reservations
● Task is forced to stop when overdraw its budget
● Recharge budget next time running
● Reserve time = 0 → disable reservations
● ERROR? Program halt?
● *NRK ERROR(1): Task Reserve Violated
● //#define NRK_REPORT_ERRORS
● //#define NRK_HALT_ON_ERROR
Any questions about
NanoRK task?
NanoRK radio
●
BMAC
●
Basic RF
BMAC
● CSMA base
● Lowpower listen
● Preamble needed for TX
● Tradeoff between check rate and preamble
BMAC on nanoRK
● The preamble is replaced with repeating packets on the nanoRK w/ zigduino
● Receiver go sleep after getting a packet
● Implement by a bmac task
● The api sets the config of this task.
Basic RF
● Aloha protocol (No mac protocol)
● Which means you have to listen all the time
● Do nothing for collision avoidance
● Hardware ack is available
● While the bmac ack is not working for now
Basic RF on nanoRK
● Directly using the hardware radio
● The chip atmega128rfa1
● For TX, hardware ack is available
● While the bmac ack is not working for now
● For RX, support hardware CRC check
● CRC fail => packet error
Basic RF V.S BMAC
BMAC Basic RF
Hardware
ACK Not work Work
Date rate Lower Higher
Collision
avoidance YES NO
Task base YES NO
Any questions about
NanoRK radio?
Tips & Tricks
It's all about stacks
● Don't Allocate Large Data Structures Inside Functions
● Use nrk_kprintf() Whenever Possible
● Be Very Careful With Dynamic Memory
● Array will always be a good choice.
● Avoid floating point (NO FPU)
Do it by yourself?
● http://www.nanork.org/wiki/Documentation
● http://140.112.91.208/nanoRK/HTML/
● Take a look of the examples in nanoRK