Professional Documents
Culture Documents
Mote
MCU
CPU Timer
Network Peripherals
Memory Storage
❖ Limited resources
✓ RAM, ROM, Computation, Energy
• Wakeup, do work as quickly as possible, sleep
❖ Robust operation
✓ Numerous, unattended, critical
• Predictable operation
Wireless Sensor Networks 4 Embedded OS for WSNs
MSc Nguyen Khanh Loi
What is an Operating System (OS)?
Hardware
Usefulness
❖ Soft real-time: deadline may not be fulfilled
✓ Multimedia transmission and reception
✓ Networking, telecom (Mobile) networks
✓ Websites and services Soft
❖ Hard real-time: no deadlines can be missed. Hard
✓ Air traffic control
✓ Nuclear power plant control Time
❖ Traditional programing.
❖ Each task can only be executed when another task has completed.
❖ Weakness: one task can use up all CPU resources.
Task Task
Task Task
Event-driven Multi-threaded
- No wait() statements + wait() statements
- No preemption + Preemption possible
- State machines + Sequential code flow
+ Compact code - Larger code overhead
+ Locking less of a problem - Locking problematic
+ Memory efficient - Langer memory requirements
Multi threaded
Event-driven
Header files
❖Timer events:
❖a process may set a timer
❖generate an event when timer expires
❖External events:
❖I/O Interrupt.
❖UART, push-button, a radio chip…
❖Internal events:
❖Any process has the possibility to address events to any other
process, or itself.
❖Inter-process communication
Event ID Description
PROCESS_EVENT_NONE 0x80 No event.
PROCESS_EVENT_INIT 0x81 Delivered to a process when it is started.
#include "contiki.h"
#include "process.h" This message from process 1
#include <stdio.h> This message from process 3
PROCESS(myprocess1, "process 1"); Process 2 is called by my process1
PROCESS(myprocess2, "process 2");
PROCESS(myprocess3, "process 3");
AUTOSTART_PROCESSES(&myprocess1,&myprocess2,&myprocess3);
PROCESS_THREAD(myprocess1, ev, data){
PROCESS_BEGIN();
process_post(&myprocess2, 0x100, 12);
printf("This message from process 1\n");
PROCESS_END();
}
PROCESS_THREAD(myprocess2, ev, data) {
PROCESS_BEGIN();
while(1){
PROCESS_WAIT_EVENT();
printf("Process 2 is called by my process1");
break;
} PROCESS_END();
}
PROCESS_THREAD(myprocess3, ev, data) {
PROCESS_BEGIN();
printf("This message from process 3\n");
PROCESS_END();
}
#include "contiki.h"
#include "dev/leds.h"
#include <stdio.h>
static struct etimer et;
static uint8_t i;
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
PROCESS_THREAD(hello_world_process, ev, data) {
PROCESS_BEGIN();
etimer_set(&et, CLOCK_SECOND*1);
i =0;
while(1) {
PROCESS_YIELD();
if (ev==PROCESS_EVENT_TIMER) {
leds_toggle(LEDS_BLUE); //LEDS_ORANGE or LEDS_GREEN
printf("Timer fired: i=%d \n",i);
i++;
etimer_restart(&et);
}
}
PROCESS_END();
}
❖ If you plan to compile your code on the chosen platform more than
once;
make TARGE=sky savetarget
❖ Upload your code
make simple_process.upload
❖ Login to the device
make login