contiki introduction ii-from what to how

17
Gucas-WSNLab 1 Contiki tutorial II. From What to How Xu Dingxin 2011/09/05

Upload: dingxin-xu

Post on 14-Jun-2015

2.213 views

Category:

Technology


4 download

DESCRIPTION

a short introduction for Contiki, mainly focuses on implementation de

TRANSCRIPT

Page 1: Contiki introduction II-from what to how

Gucas-WSNLab

1

Contiki tutorial II. From What to How

Xu Dingxin

2011/09/05

Page 2: Contiki introduction II-from what to how

Gucas-WSNLab

2

Outline Kernel

Process Scheduling Event processing Rime Layering Header/Deheader TDMA MAC

Page 3: Contiki introduction II-from what to how

Gucas-WSNLab

3

Outline Kernel

Process Scheduling Event processing Rime Layering Header/Deheader TDMA MAC

Page 4: Contiki introduction II-from what to how

Gucas-WSNLab

4

On startup…

Page 5: Contiki introduction II-from what to how

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;

};

Page 6: Contiki introduction II-from what to how

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

Page 7: Contiki introduction II-from what to how

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

Page 8: Contiki introduction II-from what to how

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;}

Page 9: Contiki introduction II-from what to how

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.

Page 10: Contiki introduction II-from what to how

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.

Page 11: Contiki introduction II-from what to how

Gucas-WSNLab

11

Outline Kernel Process Scheduling Event processing Rime Layering Header/Deheader

TDMA MAC

Page 12: Contiki introduction II-from what to how

Gucas-WSNLab

12

Case study: unicast

Page 13: Contiki introduction II-from what to how

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.

Page 14: Contiki introduction II-from what to how

Gucas-WSNLab

14

Outline Kernel Process Scheduling Event processing Rime Layering Header/Deheader

TDMA MAC

Page 15: Contiki introduction II-from what to how

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:

Page 16: Contiki introduction II-from what to how

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;

Page 17: Contiki introduction II-from what to how

Gucas-WSNLab

17

That’s ALL Q&A