Introducing Contiki-NG Processes
Contiki-NG applications can run on a process that executes in either cooperative or preemptive mode. Cooperative mode is regular execution in the micro-controller. A process with preemptive mode runs with interruptions resulting from I/O or timers. In general, we can create a process in Contiki-NG by calling PROCESS(). We can define a process as
1 | PROCESS(inner_name,outter_name); |
where
inner_nameis a variable of the process,outter_nameis a process name that is represented as a string for users notification.
Then, we implement this process using PROCESS_THREAD. We can declare this as follows:
1 | PROCESS_THREAD(inner_name, ev, data) |
The following is a list of macros API for processes:
PROCESS_BEGIN()- Declares the beginning of a process protothreadPROCESS_END()- Declares the end of a process protothreadPROCESS_EXIT()- Exits the processPROCESS_WAIT_EVENT()- Waits for any incoming eventPROCESS_WAIT_EVENT_UNTIL()- Waits for an event, but with conditionsPROCESS_YIELD()- Waits for an event; equivalent toPROCESS_WAIT_EVENT()PROCESS_WAIT_UNTIL()- Waits for a given condition; may not yield the micro-controllerPROCESS_PAUSE()- Temporarily yields the micro-controller
For demo purposes, we will create a simple Contiki-NG app. Create a folder called demo-process. Then, create two files, demo-process.c and Makefile.
demo-process.cMakefile
The first step is to write a program for demo-process.c. We define three processes as follows:
demo-process.c
1 |
|
Save this program. We continue to Makefile. We declare our program and the path of the Contiki-NG root directory via CONTIKI:
Makefile
1 | CONTIKI_PROJECT = demo-process |
Change the Contiki-NG path directory in CONTIKI. To compile and run the program, we can open Terminal and navigate to a program folder. We can type the following commands
1 | make TARGET=native |