A process in Contiki consists of a single protothread.
Data Structures | |
struct | event_data |
struct | process |
Files | |
file | process.c |
Implementation of the Contiki process kernel. | |
file | process.h |
Header file for the Contiki process interface. | |
Macros | |
#define | _DEBUG_ 0 |
#define | PRINTF(...) |
#define | PROCESS_BROADCAST NULL |
#define | PROCESS_CONF_NUMEVENTS 32 |
#define | PROCESS_EVENT_COM 0x89 |
#define | PROCESS_EVENT_CONTINUE 0x85 |
#define | PROCESS_EVENT_EXIT 0x83 |
#define | PROCESS_EVENT_EXITED 0x87 |
#define | PROCESS_EVENT_INIT 0x81 |
#define | PROCESS_EVENT_MAX 0x8a |
#define | PROCESS_EVENT_MSG 0x86 |
#define | PROCESS_EVENT_NONE 0x80 |
#define | PROCESS_EVENT_POLL 0x82 |
#define | PROCESS_EVENT_SERVICE_REMOVED 0x84 |
#define | PROCESS_EVENT_TIMER 0x88 |
#define | PROCESS_LIST() process_list |
#define | PROCESS_NONE NULL |
#define | PROCESS_STATE_CALLED 2 |
#define | PROCESS_STATE_NONE 0 |
#define | PROCESS_STATE_RUNNING 1 |
#define | PROCESS_ZOMBIE ((struct process *)0x1) |
Typedefs | |
typedef void * | process_data_t |
typedef unsigned char | process_event_t |
typedef unsigned char | process_num_events_t |
Functions | |
static void | call_process (struct process *p, process_event_t ev, process_data_t data) |
static void | do_event (void) |
static void | do_poll (void) |
static void | exit_process (struct process *p, struct process *fromprocess) |
Variables | |
static struct event_data | events [PROCESS_CONF_NUMEVENTS] |
static process_num_events_t | fevent |
static process_event_t | lastevent |
static process_num_events_t | nevents |
static volatile unsigned char | poll_requested |
struct process * | process_current = NULL |
struct process * | process_list = NULL |
CCIF struct process * | process_list |
Return values | |
#define | PROCESS_ERR_OK 0 |
Return value indicating that an operation was successful. More... | |
#define | PROCESS_ERR_FULL 1 |
Return value indicating that the event queue was full. More... | |
Process protothread functions | |
#define | PROCESS_BEGIN() |
Define the beginning of a process. More... | |
#define | PROCESS_END() |
Define the end of a process. More... | |
#define | PROCESS_WAIT_EVENT() |
Wait for an event to be posted to the process. More... | |
#define | PROCESS_WAIT_EVENT_UNTIL(c) |
Wait for an event to be posted to the process, with an extra condition. More... | |
#define | PROCESS_YIELD() |
Yield the currently running process. More... | |
#define | PROCESS_YIELD_UNTIL(c) |
Yield the currently running process until a condition occurs. More... | |
#define | PROCESS_WAIT_UNTIL(c) |
Wait for a condition to occur. More... | |
#define | PROCESS_WAIT_WHILE(c) PT_WAIT_WHILE(process_pt, c) |
#define | PROCESS_EXIT() |
Exit the currently running process. More... | |
#define | PROCESS_PT_SPAWN(pt, thread) |
Spawn a protothread from the process. More... | |
#define | PROCESS_PAUSE() |
Yield the process for a short while. More... | |
Poll and exit handlers | |
#define | PROCESS_POLLHANDLER(handler) |
Specify an action when a process is polled. More... | |
#define | PROCESS_EXITHANDLER(handler) |
Specify an action when a process exits. More... | |
Process declaration and definition | |
#define | PROCESS_THREAD(name, ev, data) |
Define the body of a process. More... | |
#define | PROCESS_NAME(name) |
Declare the name of a process. More... | |
#define | PROCESS(name, strname) |
Declare a process. More... | |
Functions called from application programs | |
CCIF struct process * | process_current |
process_event_t | process_alloc_event (void) |
Allocate a global event number. More... | |
void | process_start (struct process *p, const char *arg) |
Start a process. More... | |
void | process_exit (struct process *p) |
Cause a process to exit. More... | |
int | process_post (struct process *p, process_event_t ev, void *data) |
Post an asynchronous event. More... | |
void | process_post_synch (struct process *p, process_event_t ev, void *data) |
Post a synchronous event to a process. More... | |
#define | PROCESS_CURRENT() |
Get a pointer to the currently running process. More... | |
#define | PROCESS_CONTEXT_BEGIN(p) |
Switch context to another process. More... | |
#define | PROCESS_CONTEXT_END(p) process_current = tmp_current; } |
End a context switch. More... | |
Functions called from device drivers | |
void | process_poll (struct process *p) |
Request a process to be polled. More... | |
Functions called by the system and boot-up code | |
void | process_init (void) |
Initialize the process module. More... | |
int | process_run (void) |
Run the system once - call poll handlers and process one event. More... | |
int | process_nevents (void) |
Number of events waiting to be processed. More... | |
int | process_is_running (struct process *p) |
Check if a process is running. More... | |
#define _DEBUG_ 0 |
#define PRINTF | ( | ... | ) |
Referenced by best_parent(), calculate_rank(), call_process(), check_prefix(), create_rpl_dag(), dao_ack_input(), dao_ack_output(), dao_input(), dao_output(), dao_output_target(), dio_input(), dio_output(), dis_input(), dis_output(), eventhandler(), exit_process(), ext_hdr_options_process(), global_repair(), handle_dao_timer(), handle_dio_timer(), init(), input_callback(), ip64_eth_interface_input(), na_input(), neighbor_link_callback(), new_dio_interval(), ns_input(), nullify_parents(), output(), packet_input(), process_post(), process_start(), PROCESS_THREAD(), ra_input(), remove_ext_hdr(), remove_parents(), reset(), rm_routelist(), rpl_add_dag(), rpl_add_parent(), rpl_add_route(), rpl_free_dag(), rpl_free_instance(), rpl_init(), rpl_invert_header(), rpl_ipv6_neighbor_callback(), rpl_join_instance(), rpl_link_neighbor_callback(), rpl_local_repair(), rpl_move_parent(), rpl_nullify_parent(), rpl_process_dio(), rpl_process_parent_event(), rpl_purge_routes(), rpl_recalculate_ranks(), rpl_remove_header(), rpl_remove_parent(), rpl_repair_root(), rpl_select_dag(), rpl_set_default_route(), rpl_set_mode(), rpl_set_preferred_parent(), rpl_set_prefix(), rpl_set_root(), rpl_update_header_empty(), rpl_update_header_final(), rpl_verify_header(), schedule_dao(), send_data(), set_dao_lifetime_timer(), start_get(), tcpip_ipv6_output(), uip_ds6_defrt_add(), uip_ds6_defrt_choose(), uip_ds6_defrt_periodic(), uip_ds6_defrt_rm(), uip_ds6_init(), uip_ds6_link_neighbor_callback(), uip_ds6_nbr_add(), uip_ds6_neighbor_periodic(), uip_ds6_prefix_add(), uip_ds6_route_add(), uip_ds6_route_lookup(), uip_ds6_route_rm(), uip_ds6_send_rs(), uip_ipchksum(), uip_nd6_ns_output(), uip_nd6_rs_output(), uip_process(), uiplib_ip6addrconv(), upper_layer_chksum(), websocket_http_client_aborted(), websocket_http_client_closed(), websocket_http_client_connected(), websocket_http_client_datahandler(), websocket_http_client_timedout(), and websocket_open().
#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.
Referenced by PROCESS_THREAD().
#define PROCESS_BROADCAST NULL |
Referenced by do_event(), process_post(), and PROCESS_THREAD().
#define PROCESS_CONF_NUMEVENTS 32 |
Referenced by do_event(), and process_post().
#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 |
Referenced by ctimer_reset(), ctimer_restart(), ctimer_set(), PROCESS_THREAD(), servreg_hack_register(), simple_udp_register(), start_timeout_timer(), tcp_socket_connect(), tcp_socket_listen(), tcp_socket_unlisten(), udp_socket_register(), and websocket_open().
#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 |
Referenced by ctimer_reset(), ctimer_restart(), ctimer_set(), PROCESS_THREAD(), servreg_hack_register(), simple_udp_register(), start_timeout_timer(), tcp_socket_connect(), tcp_socket_listen(), tcp_socket_unlisten(), udp_socket_register(), and websocket_open().
#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().
Referenced by add_timer(), ctimer_set(), process_exit(), process_post(), PROCESS_THREAD(), and udp_socket_register().
#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.
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.
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.
Referenced by process_post(), and PROCESS_THREAD().
#define PROCESS_EVENT_COM 0x89 |
#define PROCESS_EVENT_CONTINUE 0x85 |
Referenced by PROCESS_THREAD().
#define PROCESS_EVENT_EXIT 0x83 |
Referenced by call_process(), and exit_process().
#define PROCESS_EVENT_EXITED 0x87 |
Referenced by eventhandler(), exit_process(), and PROCESS_THREAD().
#define PROCESS_EVENT_INIT 0x81 |
Referenced by do_event(), and process_start().
#define PROCESS_EVENT_MAX 0x8a |
Referenced by process_init().
#define PROCESS_EVENT_MSG 0x86 |
Referenced by PROCESS_THREAD(), uaodv_bad_dest(), and uaodv_request_route_to().
#define PROCESS_EVENT_NONE 0x80 |
Referenced by dhcpc_request(), and ip64_dhcpc_request().
#define PROCESS_EVENT_POLL 0x82 |
Referenced by do_poll(), and PROCESS_THREAD().
#define PROCESS_EVENT_SERVICE_REMOVED 0x84 |
#define PROCESS_EVENT_TIMER 0x88 |
Referenced by dhcpc_appcall(), eventhandler(), ip64_dhcpc_appcall(), and PROCESS_THREAD().
#define PROCESS_EXIT | ( | ) |
Exit the currently running process.
#define PROCESS_EXITHANDLER | ( | handler | ) |
Specify an action when a process exits.
handler | The action to be performed. |
Referenced by PROCESS_THREAD().
#define PROCESS_LIST | ( | ) | process_list |
#define PROCESS_NAME | ( | name | ) |
Declare the name of a process.
This macro is typically used in header files to declare the name of a process that is implemented in the C file.
#define PROCESS_NONE NULL |
Referenced by add_timer(), ctimer_stop(), etimer_expired(), etimer_stop(), eventhandler(), PROCESS_THREAD(), and tcpip_uipcall().
#define PROCESS_PAUSE | ( | ) |
Yield the process for a short while.
This macro yields the currently running process for a short while, thus letting other processes run before the process continues.
#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_STATE_CALLED 2 |
Referenced by call_process(), and process_poll().
#define PROCESS_STATE_NONE 0 |
Referenced by exit_process(), and process_is_running().
#define PROCESS_STATE_RUNNING 1 |
Referenced by call_process(), do_event(), do_poll(), process_poll(), and process_start().
#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 | ( | ) |
Wait for an event to be posted to the process.
This macro blocks the currently running process until the process receives an event.
Referenced by PROCESS_THREAD().
#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. |
Referenced by PROCESS_THREAD().
#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. |
Referenced by PROCESS_THREAD().
#define PROCESS_WAIT_WHILE | ( | c | ) | PT_WAIT_WHILE(process_pt, c) |
#define PROCESS_YIELD | ( | ) |
Yield the currently running process.
Referenced by PROCESS_THREAD().
#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. |
Referenced by PROCESS_THREAD().
#define PROCESS_ZOMBIE ((struct process *)0x1) |
typedef void* process_data_t |
typedef unsigned char process_event_t |
typedef unsigned char process_num_events_t |
|
static |
References exit_process(), NULL, printf, PRINTF, PROCESS_EVENT_EXIT, PROCESS_NAME_STRING, PROCESS_STATE_CALLED, PROCESS_STATE_RUNNING, pt, PT_ENDED, PT_EXITED, ret, and state.
Referenced by do_event(), do_poll(), exit_process(), and process_post_synch().
|
static |
References call_process(), event_data::data, data, do_poll(), event_data::ev, events, fevent, nevents, next, NULL, event_data::p, poll_requested, PROCESS_BROADCAST, PROCESS_CONF_NUMEVENTS, PROCESS_EVENT_INIT, PROCESS_STATE_RUNNING, receiver(), and state.
Referenced by process_run().
|
static |
References call_process(), needspoll, next, NULL, poll_requested, PROCESS_EVENT_POLL, PROCESS_STATE_RUNNING, and state.
Referenced by do_event(), and process_run().
References call_process(), next, NULL, PRINTF, process_current, PROCESS_EVENT_EXIT, PROCESS_EVENT_EXITED, process_is_running(), PROCESS_NAME_STRING, PROCESS_STATE_NONE, pt, and state.
Referenced by call_process(), and process_exit().
CCIF 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.
References lastevent.
Referenced by PROCESS_THREAD().
CCIF 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. |
References exit_process(), and PROCESS_CURRENT.
Referenced by autostart_exit().
void process_init | ( | void | ) |
CCIF int process_is_running | ( | struct process * | p | ) |
Check if a process is running.
This function checks if a specific process is running.
p | The process. |
Non-zero | if the process is running. |
Zero | if the process is not running. |
References PROCESS_STATE_NONE, and state.
Referenced by exit_process().
int process_nevents | ( | void | ) |
Number of events waiting to be processed.
References nevents, and poll_requested.
CCIF 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. |
References needspoll, NULL, poll_requested, PROCESS_STATE_CALLED, PROCESS_STATE_RUNNING, and state.
Referenced by etimer_request_poll(), rf212_interrupt_poll(), rf233_interrupt_poll(), sensors_changed(), serial_line_input_byte(), slip_input_byte(), and slip_poll_handler().
CCIF int process_post | ( | struct process * | p, |
process_event_t | ev, | ||
void * | 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. |
References event_data::data, data, event_data::ev, events, fevent, nevents, NULL, event_data::p, printf, PRINTF, PROCESS_BROADCAST, PROCESS_CONF_NUMEVENTS, PROCESS_CURRENT, PROCESS_ERR_FULL, PROCESS_ERR_OK, and PROCESS_NAME_STRING.
Referenced by PROCESS_THREAD(), uaodv_bad_dest(), and uaodv_request_route_to().
CCIF void process_post_synch | ( | struct process * | p, |
process_event_t | ev, | ||
void * | 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. |
References call_process(), and process_current.
Referenced by process_start(), tcpip_input(), and tcpip_uipcall().
int 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.
References do_event(), do_poll(), nevents, and poll_requested.
Referenced by main().
CCIF void process_start | ( | struct process * | p, |
const char * | arg | ||
) |
Start a process.
p | A pointer to a process structure. |
arg | An argument pointer that can be passed to the new process |
References next, NULL, PRINTF, PROCESS_EVENT_INIT, process_list, PROCESS_NAME_STRING, process_post_synch(), PROCESS_STATE_RUNNING, pt, PT_INIT, and state.
Referenced by autostart_start(), ctimer_init(), init(), init_simple_udp(), ip64_ipv4_dhcp_init(), ip64_webserver_init(), ledctrl_init(), main(), network_reboot_init(), procinit_init(), rf212_init(), rf233_init(), serial_line_init(), servreg_hack_init(), simple_udp_ping_init(), and websocket_init().
|
static |
Referenced by do_event(), and process_post().
|
static |
Referenced by do_event(), process_init(), and process_post().
|
static |
Referenced by process_alloc_event(), and process_init().
|
static |
Referenced by do_event(), process_init(), process_nevents(), process_post(), and process_run().
|
static |
Referenced by do_event(), do_poll(), process_nevents(), process_poll(), and process_run().
Referenced by exit_process(), and process_post_synch().
CCIF struct process* process_current |
Referenced by exit_process(), and process_post_synch().
Referenced by process_start().
CCIF struct process* process_list |
Referenced by process_start().