contiki introduction ii-from what to how
DESCRIPTION
a short introduction for Contiki, mainly focuses on implementation deTRANSCRIPT
Gucas-WSNLab
1
Contiki tutorial II. From What to How
Xu Dingxin
2011/09/05
Gucas-WSNLab
2
Outline Kernel
Process Scheduling Event processing Rime Layering Header/Deheader TDMA MAC
Gucas-WSNLab
3
Outline Kernel
Process Scheduling Event processing Rime Layering Header/Deheader TDMA MAC
Gucas-WSNLab
4
On startup…
Gucas-WSNLab
5
Two main data structures. Process List
struct process *process_list; Event Queue
static struct event_data events[PROCESS_CONF_NUM_EVENTS];
struct process {
struct process *next;
const char *name;
PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t));
struct pt pt;
unsigned char state, needspoll;
};
struct event_data {
process_event_t ev;
process_data_t data;
struct process *p;
};
Gucas-WSNLab
6
Types of System Events#define PROCESS_EVENT_NONE 0x80
#define PROCESS_EVENT_INIT 0x81
#define PROCESS_EVENT_POLL 0x82
#define PROCESS_EVENT_EXIT 0x83
#define PROCESS_EVENT_SERVICE_REMOVED 0x84
#define PROCESS_EVENT_CONTINUE 0x85
#define PROCESS_EVENT_MSG 0x86
#define PROCESS_EVENT_EXITED 0x87
#define PROCESS_EVENT_TIMER 0x88
#define PROCESS_EVENT_COM 0x89
#define PROCESS_EVENT_MAX 0x8a
Gucas-WSNLab
7
How to Invoke a Process Post an event
process_post(process_ptr, eventno, ptr); Process will be invoked later
process_post_synch(process_ptr, eventno, ptr); Process will be invoked now
Must not be called from an interrupt (device driver) Poll the process
process_poll(process_ptr); Sends a PROCESS_EVENT_POLL event to the process Can be called from an interrupt
Gucas-WSNLab
8
How to process events Find the active events.
Call the process handler ret = p->thread(&p->pt, ev, data);
intprocess_run(void){ /* Process poll events. */ if(poll_requested) { do_poll(); }
/* Process one event from the queue */ do_event();
return nevents + poll_requested;}
Gucas-WSNLab
9
Inter-process Communication All process share one stack
functions of different process can call each other directly; However, you SHOULD NOT do that.
Instead, use event mechanism process_post(struct process*p, eventno, dataptr); what you should do
define a dedicated event type define the format of dataptr and how to interpret it.
Gucas-WSNLab
10
Summary The kernel maintains a list process_list for all started
processes; and a queue events for all active events; All external interrupt send an event of type
PROCESS_EVENT_POLL to the kernel; Other types of events can be originated to
PROCESS_EVENT_POLL one way or another; The interrupt handler is rather simple:
send an event via process_poll(); the kernel will take the work of the rest; All the process is working in a non-blocking manner; Inter-process communication can be done via event
post and handle.
Gucas-WSNLab
11
Outline Kernel Process Scheduling Event processing Rime Layering Header/Deheader
TDMA MAC
Gucas-WSNLab
12
Case study: unicast
Gucas-WSNLab
13
Summary Rime primitives define packet attributes. Chameleon module take care of header construction in
network layer. Framer module take care of header construction in MAC
frames(802.15.4). Cons
separate packet headers from protocol logic; enable header compression; flexible to adapt to different module implementation.
Gucas-WSNLab
14
Outline Kernel Process Scheduling Event processing Rime Layering Header/Deheader
TDMA MAC
Gucas-WSNLab
15
TDMA MAC: buffer management Green: free buffer; Yellow: pkt sent; Red: pkt to be sent
State 2:
State 1:
State 4:
State 3:
Gucas-WSNLab
16
TDMA MAC: slot scheduling calculate the slot start
now = clock_time();frame_start =now – now%FRAME_LENGTH;slot_start = frame_start + MY_SLOT*SLOT_LENGTH;slot_end = slot_start + SLOT_LENGTH;
Gucas-WSNLab
17
That’s ALL Q&A