IoTivity-Lite
Contiki processes

A process in Contiki consists of a single protothread. More...

Macros

#define NULL   0
 
#define OC_PROCESS_BROADCAST   NULL
 
#define OC_PROCESS_EVENT_COM   0x89
 
#define OC_PROCESS_EVENT_CONTINUE   0x85
 
#define OC_PROCESS_EVENT_EXIT   0x83
 
#define OC_PROCESS_EVENT_EXITED   0x87
 
#define OC_PROCESS_EVENT_INIT   0x81
 
#define OC_PROCESS_EVENT_MAX   0x8a
 
#define OC_PROCESS_EVENT_MSG   0x86
 
#define OC_PROCESS_EVENT_NONE   0x80
 
#define OC_PROCESS_EVENT_POLL   0x82
 
#define OC_PROCESS_EVENT_SERVICE_REMOVED   0x84
 
#define OC_PROCESS_EVENT_TIMER   0x88
 
#define OC_PROCESS_LIST()   oc_process_list
 
#define OC_PROCESS_NONE   NULL
 
#define OC_PROCESS_ZOMBIE   ((struct oc_process *)0x1)
 

Typedefs

typedef void * oc_process_data_t
 
typedef unsigned char oc_process_event_t
 
typedef unsigned long oc_process_num_events_t
 

Variables

struct oc_process * oc_process_list
 

Functions called from application programs

typedef bool(* oc_process_drop_event_t) (oc_process_event_t ev, oc_process_data_t data, const void *user_data)
 This function is responsible for determining whether an event should be removed from the event queue of a given process. More...
 
struct oc_process * oc_process_current
 
void oc_process_start (struct oc_process *p, oc_process_data_t data)
 Start a process. More...
 
int oc_process_post (struct oc_process *p, oc_process_event_t ev, oc_process_data_t data)
 Post an asynchronous event. More...
 
int oc_process_drop (const struct oc_process *p, oc_process_drop_event_t drop_event, const void *user_data)
 Drop events from a process' event queue. More...
 
void oc_process_post_synch (struct oc_process *p, oc_process_event_t ev, oc_process_data_t data)
 Post a synchronous event to a process. More...
 
void oc_process_exit (struct oc_process *p)
 Cause a process to exit. More...
 
oc_process_event_t oc_process_alloc_event (void)
 Allocate a global event number. More...
 
#define OC_PROCESS_CURRENT()
 Get a pointer to the currently running process. More...
 
#define OC_PROCESS_CONTEXT_BEGIN(p)
 Switch context to another process. More...
 
#define OC_PROCESS_CONTEXT_END(p)
 End a context switch. More...
 

Functions called from device drivers

void oc_process_poll (struct oc_process *p)
 Request a process to be polled. More...
 

Functions called by the system and boot-up code

int oc_process_run (void)
 Run the system once - call poll handlers and process one event. More...
 
int oc_process_is_running (const struct oc_process *p)
 Check if a process is running. More...
 
int oc_process_nevents (void)
 Number of events waiting to be processed. More...
 
bool oc_process_needs_poll (void)
 Check if processes need to be polled. More...
 
bool oc_process_is_closing_all_tls_sessions (void)
 Check if closing of all tls sessions is currently scheduled by the process. More...
 

Return values

#define OC_PROCESS_ERR_OK   0
 Return value indicating that an operation was successful. More...
 
#define OC_PROCESS_ERR_FULL   1
 Return value indicating that the event queue was full. More...
 

Process protothread functions

#define OC_PROCESS_BEGIN()
 Define the beginning of a process. More...
 
#define OC_PROCESS_END()
 Define the end of a process. More...
 
#define OC_PROCESS_WAIT_EVENT()
 Wait for an event to be posted to the process. More...
 
#define OC_PROCESS_WAIT_EVENT_UNTIL(c)
 Wait for an event to be posted to the process, with an extra condition. More...
 
#define OC_PROCESS_YIELD()
 Yield the currently running process. More...
 
#define OC_PROCESS_YIELD_UNTIL(c)
 Yield the currently running process until a condition occurs. More...
 
#define OC_PROCESS_WAIT_UNTIL(c)
 Wait for a condition to occur. More...
 
#define OC_PROCESS_WAIT_WHILE(c)   PT_WAIT_WHILE(process_pt, c)
 
#define OC_PROCESS_EXIT()
 Exit the currently running process. More...
 
#define OC_PROCESS_PT_SPAWN(pt, thread)
 Spawn a protothread from the process. More...
 
#define OC_PROCESS_PAUSE()
 Yield the process for a short while. More...
 

Poll and exit handlers

#define OC_PROCESS_POLLHANDLER(handler)
 Specify an action when a process is polled. More...
 
#define OC_PROCESS_EXITHANDLER(handler)
 Specify an action when a process exits. More...
 

Process declaration and definition

#define OC_PROCESS_THREAD(name, ev, data)
 Define the body of a process. More...
 
#define OC_PROCESS_NAME(name)
 Declare the name of a process. More...
 
#define OC_PROCESS(name, strname)
 Declare a process. More...
 

Detailed Description

A process in Contiki consists of a single protothread.

Macro Definition Documentation

◆ OC_PROCESS

#define OC_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.

Parameters
nameThe variable name of the process structure.
strnameThe string representation of the process' name.

◆ OC_PROCESS_BEGIN

#define OC_PROCESS_BEGIN ( )

Define the beginning of a process.

This macro defines the beginning of a process, and must always appear in a OC_PROCESS_THREAD() definition. The OC_PROCESS_END() macro must come at the end of the process.

◆ OC_PROCESS_CONTEXT_BEGIN

#define OC_PROCESS_CONTEXT_BEGIN (   p)
Value:
{ \
struct oc_process *tmp_current = OC_PROCESS_CURRENT(); \
oc_process_current = p;
#define OC_PROCESS_CURRENT()
Get a pointer to the currently running process.
Definition: oc_process.h:430

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 OC_PROCESS_CONTEXT_BEGIN() must be followed by the OC_PROCESS_CONTEXT_END() macro to end the context switch.

Example:

OC_PROCESS_CONTEXT_BEGIN(&test_process);
etimer_set(&timer, CLOCK_SECOND);
OC_PROCESS_CONTEXT_END(&test_process);
#define OC_PROCESS_CONTEXT_END(p)
End a context switch.
Definition: oc_process.h:469
#define OC_PROCESS_CONTEXT_BEGIN(p)
Switch context to another process.
Definition: oc_process.h:454
Parameters
pThe process to use as context
See also
OC_PROCESS_CONTEXT_END()
OC_PROCESS_CURRENT()

◆ OC_PROCESS_CONTEXT_END

#define OC_PROCESS_CONTEXT_END (   p)
Value:
oc_process_current = tmp_current; \
}

End a context switch.

This function ends a context switch and changes back to the previous process.

Parameters
pThe process used in the context switch
See also
OC_PROCESS_CONTEXT_START()

◆ OC_PROCESS_CURRENT

#define OC_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().

◆ OC_PROCESS_END

#define OC_PROCESS_END ( )

Define the end of a process.

This macro defines the end of a process. It must appear in a OC_PROCESS_THREAD() definition and must always be included. The process exits when the OC_PROCESS_END() macro is reached.

◆ OC_PROCESS_ERR_FULL

#define OC_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.

◆ OC_PROCESS_ERR_OK

#define OC_PROCESS_ERR_OK   0

Return value indicating that an operation was successful.

        This value is returned to indicate that an operation
        was successful.

◆ OC_PROCESS_EXIT

#define OC_PROCESS_EXIT ( )

Exit the currently running process.

◆ OC_PROCESS_EXITHANDLER

#define OC_PROCESS_EXITHANDLER (   handler)

Specify an action when a process exits.

Note
This declaration must come immediately before the OC_PROCESS_BEGIN() macro.
Parameters
handlerThe action to be performed.

◆ OC_PROCESS_NAME

#define OC_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.

◆ OC_PROCESS_PAUSE

#define OC_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.

◆ OC_PROCESS_POLLHANDLER

#define OC_PROCESS_POLLHANDLER (   handler)

Specify an action when a process is polled.

Note
This declaration must come immediately before the OC_PROCESS_BEGIN() macro.
Parameters
handlerThe action to be performed.

◆ OC_PROCESS_PT_SPAWN

#define OC_PROCESS_PT_SPAWN (   pt,
  thread 
)

Spawn a protothread from the process.

Parameters
ptThe protothread state (struct pt) for the new protothread
threadThe call to the protothread function.
See also
PT_SPAWN()

◆ OC_PROCESS_THREAD

#define OC_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 OC_PROCESS_BEGIN() macro and end with the OC_PROCESS_END() macro.

◆ OC_PROCESS_WAIT_EVENT

#define OC_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.

◆ OC_PROCESS_WAIT_EVENT_UNTIL

#define OC_PROCESS_WAIT_EVENT_UNTIL (   c)

Wait for an event to be posted to the process, with an extra condition.

This macro is similar to OC_PROCESS_WAIT_EVENT() in that it blocks the currently running process until the process receives an event. But OC_PROCESS_WAIT_EVENT_UNTIL() takes an extra condition which must be true for the process to continue.

Parameters
cThe condition that must be true for the process to continue.
See also
PT_WAIT_UNTIL()

◆ OC_PROCESS_WAIT_UNTIL

#define OC_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, OC_PROCESS_WAIT_EVENT(), OC_PROCESS_WAIT_EVENT_UNTIL(), OC_PROCESS_YIELD() or OC_PROCESS_YIELD_UNTIL() should be used instead.

Parameters
cThe condition to wait for.

◆ OC_PROCESS_YIELD

#define OC_PROCESS_YIELD ( )

Yield the currently running process.

◆ OC_PROCESS_YIELD_UNTIL

#define OC_PROCESS_YIELD_UNTIL (   c)

Yield the currently running process until a condition occurs.

This macro is different from OC_PROCESS_WAIT_UNTIL() in that OC_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.

Parameters
cThe condition to wait for.

Typedef Documentation

◆ oc_process_drop_event_t

typedef bool(* oc_process_drop_event_t) (oc_process_event_t ev, oc_process_data_t data, const void *user_data)

This function is responsible for determining whether an event should be removed from the event queue of a given process.

Parameters
evThe event to be dropped.
dataThe auxiliary data to be sent with the event
user_dataData to be passed to the drop_event function.
Returns
true Drop the event.

Function Documentation

◆ oc_process_alloc_event()

oc_process_event_t oc_process_alloc_event ( void  )

Allocate a global event number.

Returns
The allocated 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.
Note
There currently is no way to deallocate an allocated event number.

◆ oc_process_drop()

int oc_process_drop ( const struct oc_process *  p,
oc_process_drop_event_t  drop_event,
const void *  user_data 
)

Drop events from a process' event queue.

Parameters
pA pointer to the process' process structure.
drop_eventfunction to determine if an event should be dropped.
user_dataData to be passed to the drop_event function.
Returns
int Number of events dropped.

◆ oc_process_exit()

void oc_process_exit ( struct oc_process *  p)

Cause a process to exit.

Parameters
pThe 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.
See also
OC_PROCESS_CURRENT()

◆ oc_process_is_closing_all_tls_sessions()

bool oc_process_is_closing_all_tls_sessions ( void  )

Check if closing of all tls sessions is currently scheduled by the process.

Returns
true closing of all tls is sessions is scheduled by the process
false otherwise

◆ oc_process_is_running()

int oc_process_is_running ( const struct oc_process *  p)

Check if a process is running.

This function checks if a specific process is running.

Parameters
pThe process.
Return values
Non-zeroif the process is running.
Zeroif the process is not running.

◆ oc_process_needs_poll()

bool oc_process_needs_poll ( void  )

Check if processes need to be polled.

Returns
True if there are processes that need to be polled.

◆ oc_process_nevents()

int oc_process_nevents ( void  )

Number of events waiting to be processed.

Returns
The number of events that are currently waiting to be processed.

◆ oc_process_poll()

void oc_process_poll ( struct oc_process *  p)

Request a process to be polled.

This function typically is called from an interrupt handler to cause a process to be polled.

Parameters
pA pointer to the process' process structure.

◆ oc_process_post()

int oc_process_post ( struct oc_process *  p,
oc_process_event_t  ev,
oc_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.

Parameters
evThe event to be posted.
dataThe auxiliary data to be sent with the event
pThe process to which the event should be posted, or OC_PROCESS_BROADCAST if the event should be posted to all processes.
Return values
OC_PROCESS_ERR_OKThe event could be posted.
OC_PROCESS_ERR_FULLThe event queue was full and the event could not be posted.

◆ oc_process_post_synch()

void oc_process_post_synch ( struct oc_process *  p,
oc_process_event_t  ev,
oc_process_data_t  data 
)

Post a synchronous event to a process.

Parameters
pA pointer to the process' process structure.
evThe event to be posted.
dataA pointer to additional data that is posted together with the event.

◆ oc_process_run()

int oc_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.

Returns
The number of events that are currently waiting in the event queue.

◆ oc_process_start()

void oc_process_start ( struct oc_process *  p,
oc_process_data_t  data 
)

Start a process.

Parameters
pA pointer to a process structure.
dataAn argument pointer that can be passed to the new process