Contiki-NG
|
Files | |
file | process.c |
Implementation of the Contiki process kernel. | |
file | process.h |
Header file for the Contiki process interface. | |
Functions called from application programs | |
process_event_t | process_alloc_event (void) |
Allocate a global event number. | |
void | process_start (struct process *p, process_data_t data) |
Start a process. | |
void | process_exit (struct process *p) |
Cause a process to exit. | |
int | process_post (struct process *p, process_event_t ev, process_data_t data) |
Post an asynchronous event. | |
void | process_post_synch (struct process *p, process_event_t ev, process_data_t data) |
Post a synchronous event to a process. | |
#define | PROCESS_CURRENT() |
Get a pointer to the currently running process. | |
#define | PROCESS_CONTEXT_BEGIN(p) |
Switch context to another process. | |
#define | PROCESS_CONTEXT_END(p) process_current = tmp_current; } |
End a context switch. | |
Functions called by the system and boot-up code | |
void | process_init (void) |
Initialize the process module. | |
process_num_events_t | process_run (void) |
Run the system once - call poll handlers and process one event. | |
process_num_events_t | process_nevents (void) |
Number of events waiting to be processed. | |
bool | process_is_running (struct process *p) |
Check if a process is running. | |
Functions called from device drivers | |
void | process_poll (struct process *p) |
Request a process to be polled. | |
Return values | |
#define | PROCESS_ERR_OK 0 |
Return value indicating that an operation was successful. | |
#define | PROCESS_ERR_FULL 1 |
Return value indicating that the event queue was full. | |
Process protothread functions | |
#define | PROCESS_BEGIN() |
Define the beginning of a process. | |
#define | PROCESS_END() |
Define the end of a process. | |
#define | PROCESS_WAIT_EVENT() |
Wait for an event to be posted to the process. | |
#define | PROCESS_WAIT_EVENT_UNTIL(c) |
Wait for an event to be posted to the process, with an extra condition. | |
#define | PROCESS_YIELD() |
Yield the currently running process. | |
#define | PROCESS_YIELD_UNTIL(c) |
Yield the currently running process until a condition occurs. | |
#define | PROCESS_WAIT_UNTIL(c) |
Wait for a condition to occur. | |
#define | PROCESS_EXIT() |
Exit the currently running process. | |
#define | PROCESS_PT_SPAWN(pt, thread) |
Spawn a protothread from the process. | |
#define | PROCESS_PAUSE() |
Yield the process for a short while. | |
Poll and exit handlers | |
#define | PROCESS_POLLHANDLER(handler) |
Specify an action when a process is polled. | |
#define | PROCESS_EXITHANDLER(handler) |
Specify an action when a process exits. | |
Process declaration and definition | |
#define | PROCESS_THREAD(name, ev, data) |
Define the body of a process. | |
#define | PROCESS_NAME(name) |
Declare the name of a process. | |
#define | PROCESS(name, strname) |
Declare a process. | |
A process in Contiki consists of a single protothread.
#define PROCESS | ( | name, | |
strname ) |
Declare a process.
This macro declares a process. The process has two names: the variable of the process structure, which is used by the C program, and a human readable string name, which is used when debugging. A configuration option allows removal of the readable name to save RAM.
name | The variable name of the process structure. |
strname | The string representation of the process' name. |
#define PROCESS_BEGIN | ( | ) |
Define the beginning of a process.
This macro defines the beginning of a process, and must always appear in a PROCESS_THREAD() definition. The PROCESS_END() macro must come at the end of the process.
Definition at line 121 of file process.h.
Referenced by PROCESS_THREAD().
#define PROCESS_CONTEXT_BEGIN | ( | p | ) |
Switch context to another process.
This function switch context to the specified process and executes the code as if run by that process. Typical use of this function is to switch context in services, called by other processes. Each PROCESS_CONTEXT_BEGIN() must be followed by the PROCESS_CONTEXT_END() macro to end the context switch.
Example:
p | The process to use as context |
Definition at line 428 of file process.h.
Referenced by ctimer_reset(), ctimer_restart(), ctimer_set_with_process(), and simple_udp_register().
#define PROCESS_CONTEXT_END | ( | p | ) | process_current = tmp_current; } |
End a context switch.
This function ends a context switch and changes back to the previous process.
p | The process used in the context switch |
Definition at line 442 of file process.h.
Referenced by ctimer_reset(), ctimer_restart(), ctimer_set_with_process(), and simple_udp_register().
#define PROCESS_CURRENT | ( | ) |
Get a pointer to the currently running process.
This macro get a pointer to the currently running process. Typically, this macro is used to post an event to the current process with process_post().
Definition at line 404 of file process.h.
Referenced by ctimer_set(), process_exit(), process_post(), simple_udp_register(), tcp_listen(), and tcp_unlisten().
#define PROCESS_END | ( | ) |
Define the end of a process.
This macro defines the end of a process. It must appear in a PROCESS_THREAD() definition and must always be included. The process exits when the PROCESS_END() macro is reached.
Definition at line 132 of file process.h.
Referenced by PROCESS_THREAD().
#define PROCESS_ERR_FULL 1 |
Return value indicating that the event queue was full.
This value is returned from process_post() to indicate that the event queue was full and that an event could not be posted.
Definition at line 84 of file process.h.
Referenced by process_post().
#define PROCESS_ERR_OK 0 |
Return value indicating that an operation was successful.
This value is returned to indicate that an operation was successful.
Definition at line 76 of file process.h.
Referenced by process_post().
#define PROCESS_EXITHANDLER | ( | handler | ) |
Specify an action when a process exits.
handler | The action to be performed. |
#define PROCESS_NAME | ( | name | ) |
#define PROCESS_PAUSE | ( | ) |
#define PROCESS_POLLHANDLER | ( | handler | ) |
Specify an action when a process is polled.
handler | The action to be performed. |
#define PROCESS_PT_SPAWN | ( | pt, | |
thread ) |
Spawn a protothread from the process.
pt | The protothread state (struct pt) for the new protothread |
thread | The call to the protothread function. |
#define PROCESS_THREAD | ( | name, | |
ev, | |||
data ) |
Define the body of a process.
This macro is used to define the body (protothread) of a process. The process is called whenever an event occurs in the system, A process always start with the PROCESS_BEGIN() macro and end with the PROCESS_END() macro.
#define PROCESS_WAIT_EVENT | ( | ) |
#define PROCESS_WAIT_EVENT_UNTIL | ( | c | ) |
Wait for an event to be posted to the process, with an extra condition.
This macro is similar to PROCESS_WAIT_EVENT() in that it blocks the currently running process until the process receives an event. But PROCESS_WAIT_EVENT_UNTIL() takes an extra condition which must be true for the process to continue.
c | The condition that must be true for the process to continue. |
#define PROCESS_WAIT_UNTIL | ( | c | ) |
Wait for a condition to occur.
This macro does not guarantee that the process yields, and should therefore be used with care. In most cases, PROCESS_WAIT_EVENT(), PROCESS_WAIT_EVENT_UNTIL(), PROCESS_YIELD() or PROCESS_YIELD_UNTIL() should be used instead.
c | The condition to wait for. |
#define PROCESS_YIELD_UNTIL | ( | c | ) |
Yield the currently running process until a condition occurs.
This macro is different from PROCESS_WAIT_UNTIL() in that PROCESS_YIELD_UNTIL() is guaranteed to always yield at least once. This ensures that the process does not end up in an infinite loop and monopolizing the CPU.
c | The condition to wait for. |
Definition at line 179 of file process.h.
Referenced by PROCESS_THREAD().
process_event_t process_alloc_event | ( | void | ) |
Allocate a global event number.
In Contiki, event numbers above 128 are global and may be posted from one process to another. This function allocates one such event number.
Definition at line 111 of file process.c.
Referenced by button_hal_init(), and tz_api_init().
void process_exit | ( | struct process * | p | ) |
Cause a process to exit.
p | The process that is to be exited This function causes a process to exit. The process can either be the currently executing process, or another process that is currently running. |
Definition at line 222 of file process.c.
References PROCESS_CURRENT.
Referenced by rf_ble_beacond_stop().
void process_init | ( | void | ) |
bool process_is_running | ( | struct process * | p | ) |
process_num_events_t process_nevents | ( | void | ) |
Number of events waiting to be processed.
Definition at line 319 of file process.c.
Referenced by lpm_drop(), platform_idle(), platform_main_loop(), and tz_api_poll().
void process_poll | ( | struct process * | p | ) |
Request a process to be polled.
This function typically is called from an interrupt handler to cause a process to be polled.
p | A pointer to the process' process structure. |
Definition at line 366 of file process.c.
Referenced by cc2420_interrupt(), cc2538_rf_err_isr(), cc2538_rf_rx_tx_isr(), crypto_isr(), etimer_request_poll(), pka_isr(), serial_line_input_byte(), tsch_disassociate(), tsch_schedule_keepalive(), and usb_interrupt_handler().
int process_post | ( | struct process * | p, |
process_event_t | ev, | ||
process_data_t | data ) |
Post an asynchronous event.
This function posts an asynchronous event to one or more processes. The handing of the event is deferred until the target process is scheduled by the kernel. An event can be broadcast to all processes, in which case all processes in the system will be scheduled to handle the event.
ev | The event to be posted. |
data | The auxiliary data to be sent with the event |
p | The process to which the event should be posted, or PROCESS_BROADCAST if the event should be posted to all processes. |
PROCESS_ERR_OK | The event could be posted. |
PROCESS_ERR_FULL | The event queue was full and the event could not be posted. |
Definition at line 325 of file process.c.
References PROCESS_CURRENT, PROCESS_ERR_FULL, and PROCESS_ERR_OK.
Referenced by mqtt_auth(), mqtt_connect(), mqtt_disconnect(), mqtt_publish(), mqtt_subscribe(), mqtt_unsubscribe(), newdata(), resolv_query(), tcpip_poll_tcp(), tcpip_poll_udp(), and tz_api_init().
void process_post_synch | ( | struct process * | p, |
process_event_t | ev, | ||
process_data_t | data ) |
Post a synchronous event to a process.
p | A pointer to the process' process structure. |
ev | The event to be posted. |
data | A pointer to additional data that is posted together with the event. |
Definition at line 357 of file process.c.
Referenced by process_start(), tcpip_icmp6_call(), and tcpip_input().
process_num_events_t process_run | ( | void | ) |
Run the system once - call poll handlers and process one event.
This function should be called repeatedly from the main() program to actually run the Contiki system. It calls the necessary poll handlers, and processes one event. The function returns the number of events that are waiting in the event queue so that the caller may choose to put the CPU to sleep when there are no pending events.
Definition at line 305 of file process.c.
Referenced by platform_main_loop(), platform_main_loop(), and tz_api_poll().
void process_start | ( | struct process * | p, |
process_data_t | data ) |
Start a process.
p | A pointer to a process structure. |
data | An argument pointer that can be passed to the new process |
Definition at line 121 of file process.c.
References process_post_synch(), and PT_INIT.
Referenced by button_hal_init(), coap_transport_init(), ctimer_init(), init(), platform_init_stage_three(), platform_init_stage_three(), platform_main_loop(), rf_ble_beacond_start(), rtcc_init(), serial_shell_init(), simple_energest_init(), snmp_init(), soc_trng_init(), stack_check_init(), usb_init(), and usb_serial_init().