- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# picoos.h File Reference

pico]OS main include file More...

Go to the source code of this file.

## Data Structures
struct | PICOEVENT
| Event info structure. More...
struct | PICOTASK
| Task info structure. More...
## Defines
#define | E_OK 0
| No Error (the operation was successful).
#define | E_FAIL 1
| The operation failed.
#define | E_NOMEM 2
| The System ran out of memory.
#define | E_ARG 3
| The given argument is wrong or inacceptable.
#define | E_FORB 4
| The operation is forbidden at the current operation stage.
#define | E_NOMORE 5
| For query operations: End of query (no more elements).
#define | E_NOTFOUND 6
| The query operation was not successfull.
#define | MS(msec) ((UINT_t)((1L*HZ*(UINT_t)(msec))/1000))
#define | HZ (timerticks per second)
#define | POS_TIMEAFTER(x, y) ((((SJIF_t)(x)) - ((SJIF_t)(y))) >= 0)
#define | POSLIST_ELEMENT(elem, type, member)
#define | POSLIST_IS_EMPTY(plisthead) ((plisthead)->next == (POSLIST_t*)(plisthead))
#define | POSLIST_NEXT_ENTRY(plist) (plist)->next
#define | POSLIST_PREV_ENTRY(plist) (plist)->prev
#define | POSLIST_FIRST_ENTRY(plisthead) (plisthead)->next
#define | POSLIST_LAST_ENTRY(plisthead) (plisthead)->prev
#define | POSLIST_IS_FIRST_ENTRY(element) ((element)->prev==(element)->head)
#define | POSLIST_IS_LAST_ENTRY(element) ((element)->next==(element)->head)
#define | POSLIST_IS_END(plisthead, element) ((element)==(POSLIST_t*)(plisthead))
#define | POSLIST_FOR_EACH_ENTRY(plisthead, runvar)
#define | POSLIST_FOREACH_BEGIN(plisthead, runvar, type, listmember)
#define | POSLIST_FOREACH_END
#define | P_ASSERT(text, x) if (!(x)) p_pos_assert((const char*)(text), __FILE__, __LINE__)
| pico]OS assertion macro.
#define | POS_SETTASKNAME(taskhandle, taskname)
| This macro assigns a name to a pico]OS task.
#define | POS_SETEVENTNAME(eventhandle, name)
| This macro assigns a name to a pico]OS event.
## Typedefs
typedef signed MVAR_t | VAR_t
| Signed machine variable type. This variable type is the fastest for the target architecture.
typedef unsigned MVAR_t | UVAR_t
| Unsigned machine variable type. This variable type is the fastest for the target architecture.
typedef signed MINT_t | INT_t
| Signed integer.
typedef unsigned MINT_t | UINT_t
| Unsigned integer.
typedef unsigned MPTR_t | MEMPTR_t
| Memory pointer type.
typedef VAR_t | SJIF_t
| Signed type of JIF_t.
typedef UVAR_t | JIF_t
| Timer counter type. Can be UVAR_t or UINT_t.
typedef void(* | POSTASKFUNC_t )(void *arg)
| Generic function pointer.
typedef void(* | POSINTFUNC_t )(UVAR_t arg)
| Software interrupt callback function pointer.
typedef void(* | POSIDLEFUNC_t )(void)
| Idle task function pointer.
typedef POSSEMA * | POSSEMA_t
| Handle to a semaphore object.
typedef POSMUTEX * | POSMUTEX_t
| Handle to a mutex object.
typedef POSFLAG * | POSFLAG_t
| Handle to a flag object.
typedef POSTIMER * | POSTIMER_t
| Handle to a timer object.
typedef volatile INT_t | POSATOMIC_t
| Atomic variable.
typedef POSLIST | POSLIST_t
| List variable. This variable type is used as running variable of a list or as list link.
typedef POSLISTHEAD | POSLISTHEAD_t
| List variable. This variable defines the head of a list.
typedef POSTASK * | POSTASK_t
| Task environment structure.
## Enumerations
enum | PTASKSTATE { task_notExisting = 0, task_created = 1, task_running = 2, task_suspended = 3, task_sleeping = 4, task_waitingForSemaphore = 5, task_waitingForSemaphoreWithTimeout = 6, task_waitingForMutex = 7, task_waitingForMutexWithTimeout = 8, task_waitingForFlag = 9, task_waitingForFlagWithTimeout = 10, task_waitingForMessage = 11, task_waitingForMessageWithTimeout = 12 }
| Task states (used for debugging when POSCFG_FEATURE_DEBUGHELP is set to 1). More...
enum | PEVENTTYPE { event_semaphore = 0, event_mutex = 1, event_flags = 2 }
| Event types (used for debugging when POSCFG_FEATURE_DEBUGHELP is set to 1). More...
## Functions
POSFROMEXT UVAR_t | p_pos_findbit (const UVAR_t bitfield)
POSFROMEXT UVAR_t | p_pos_findbit (const UVAR_t bitfield, UVAR_t rrOffset)
POSFROMEXT void | p_pos_initArch (void)
POSFROMEXT void | p_pos_initTask (POSTASK_t task, void *stackstart, POSTASKFUNC_t funcptr, void *funcarg)
POSFROMEXT VAR_t | p_pos_initTask (POSTASK_t task, UINT_t stacksize, POSTASKFUNC_t funcptr, void *funcarg)
POSFROMEXT void | p_pos_freeStack (POSTASK_t task)
POSFROMEXT VAR_t | p_pos_initTask (POSTASK_t task, POSTASKFUNC_t funcptr, void *funcarg)
POSFROMEXT void | p_pos_startFirstContext (void)
POSFROMEXT void | p_pos_softContextSwitch (void)
POSFROMEXT void | p_pos_intContextSwitch (void)
POSEXTERN void | c_pos_intEnter (void)
POSEXTERN void | c_pos_intExit (void)
POSEXTERN void | c_pos_timerInterrupt (void)
POSEXTERN void | posTaskYield (void)
POSEXTERN void | posTaskSleep (UINT_t ticks)
POSEXTERN POSTASK_t | posTaskCreate (POSTASKFUNC_t funcptr, void *funcarg, VAR_t priority, void *stackstart)
POSEXTERN void | posInit (POSTASKFUNC_t firstfunc, void *funcarg, VAR_t priority, void *stackFirstTask, void *stackIdleTask)
POSEXTERN POSTASK_t | posTaskCreate (POSTASKFUNC_t funcptr, void *funcarg, VAR_t priority, UINT_t stacksize)
POSEXTERN void | posInit (POSTASKFUNC_t firstfunc, void *funcarg, VAR_t priority, UINT_t taskStackSize, UINT_t idleStackSize)
POSEXTERN POSTASK_t | posTaskCreate (POSTASKFUNC_t funcptr, void *funcarg, VAR_t priority)
POSEXTERN void | posInit (POSTASKFUNC_t firstfunc, void *funcarg, VAR_t priority)
POSEXTERN void | posTaskExit (void)
POSEXTERN POSTASK_t | posTaskGetCurrent (void)
POSEXTERN VAR_t | posTaskUnused (POSTASK_t taskhandle)
POSEXTERN VAR_t | posTaskSetPriority (POSTASK_t taskhandle, VAR_t priority)
POSEXTERN VAR_t | posTaskGetPriority (POSTASK_t taskhandle)
POSEXTERN void | posTaskSchedLock (void)
POSEXTERN void | posTaskSchedUnlock (void)
POSEXTERN void * | posTaskGetUserspace (void)
POSEXTERN POSIDLEFUNC_t | posInstallIdleTaskHook (POSIDLEFUNC_t idlefunc)
POSEXTERN POSSEMA_t | posSemaCreate (INT_t initcount)
POSEXTERN void | posSemaDestroy (POSSEMA_t sema)
POSEXTERN VAR_t | posSemaGet (POSSEMA_t sema)
POSEXTERN VAR_t | posSemaSignal (POSSEMA_t sema)
POSEXTERN VAR_t | posSemaWait (POSSEMA_t sema, UINT_t timeoutticks)
POSEXTERN POSMUTEX_t | posMutexCreate (void)
POSEXTERN void | posMutexDestroy (POSMUTEX_t mutex)
POSEXTERN VAR_t | posMutexTryLock (POSMUTEX_t mutex)
POSEXTERN VAR_t | posMutexLock (POSMUTEX_t mutex)
POSEXTERN VAR_t | posMutexUnlock (POSMUTEX_t mutex)
POSEXTERN void * | posMessageAlloc (void)
POSEXTERN void | posMessageFree (void *buf)
POSEXTERN VAR_t | posMessageSend (void *buf, POSTASK_t taskhandle)
POSEXTERN void * | posMessageGet (void)
POSEXTERN VAR_t | posMessageAvailable (void)
POSEXTERN void * | posMessageWait (UINT_t timeoutticks)
POSEXTERN POSFLAG_t | posFlagCreate (void)
POSEXTERN void | posFlagDestroy (POSFLAG_t flg)
POSEXTERN VAR_t | posFlagSet (POSFLAG_t flg, UVAR_t flgnum)
POSEXTERN VAR_t | posFlagGet (POSFLAG_t flg, UVAR_t mode)
POSEXTERN VAR_t | posFlagWait (POSFLAG_t flg, UINT_t timeoutticks)
POSEXTERN POSTIMER_t | posTimerCreate (void)
POSEXTERN VAR_t | posTimerSet (POSTIMER_t tmr, POSSEMA_t sema, UINT_t waitticks, UINT_t periodticks)
POSEXTERN VAR_t | posTimerStart (POSTIMER_t tmr)
POSEXTERN VAR_t | posTimerStop (POSTIMER_t tmr)
POSEXTERN void | posTimerDestroy (POSTIMER_t tmr)
POSEXTERN VAR_t | posTimerFired (POSTIMER_t tmr)
POSEXTERN void | posSoftInt (UVAR_t intno, UVAR_t param)
POSEXTERN VAR_t | posSoftIntSetHandler (UVAR_t intno, POSINTFUNC_t inthandler)
POSEXTERN VAR_t | posSoftIntDelHandler (UVAR_t intno)
POSEXTERN void | posAtomicSet (POSATOMIC_t *var, INT_t value)
POSEXTERN INT_t | posAtomicGet (POSATOMIC_t *var)
POSEXTERN INT_t | posAtomicAdd (POSATOMIC_t *var, INT_t value)
POSEXTERN INT_t | posAtomicSub (POSATOMIC_t *var, INT_t value)
POSEXTERN void | posListAdd (POSLISTHEAD_t *listhead, UVAR_t pos, POSLIST_t *new)
POSEXTERN POSLIST_t * | posListGet (POSLISTHEAD_t *listhead, UVAR_t pos, UINT_t timeout)
POSEXTERN void | posListRemove (POSLIST_t *listelem)
POSEXTERN void | posListJoin (POSLISTHEAD_t *baselisthead, UVAR_t pos, POSLISTHEAD_t *joinlisthead)
POSEXTERN UINT_t | posListLen (POSLISTHEAD_t *listhead)
POSEXTERN void | posListInit (POSLISTHEAD_t *listhead)
POSEXTERN void | posListTerm (POSLISTHEAD_t *listhead)
## Variables
POSEXTERN volatile POSTASK_t | posCurrentTask_g
| Global task variable. This variable points to the environment structure of the currently active task.
POSEXTERN volatile POSTASK_t | posNextTask_g
| Global task variable. This variable points to the environment structure of the next task that shall be scheduled.
POSEXTERN volatile UVAR_t | posInInterrupt_g
| Global flag variable. This variable is nonzero when the CPU is currently executing an interrupt service routine.
POSEXTERN volatile UVAR_t | posRunning_g
| Global flag variable. This variable is nonzero when the operating system is initialized and running.
VAR_t | errno
| Unix style error variable. This variable is global for the currently runnig task.
POSEXTERN volatile JIF_t | jiffies
| Global timer variable. The jiffies counter variable is incremented HZ times per second.
PICOTASK * | picodeb_taskhistory [3]
| This array contains the last 3 tasks that run.
PICOTASK * | picodeb_tasklist
| Pointer to the list of active tasks.
PICOEVENT * | picodeb_eventlist
| Pointer to the list of all system events.

## Detailed Description

pico]OS main include file

Author:
  Dennis Kuschel

## Define Documentation

#define MS | ( | msec |  | ) | ((UINT_t)((1L*HZ*(UINT_t)(msec))/1000))

| Convert milliseconds into HZ timer ticks. This macro is used to convert milliseconds into the timer tick rate (see HZ define). Example: Use posTaskSleep(MS(1000)) to sleep 1000 ms.

## Typedef Documentation

typedef signed MINT_t INT_t

| Signed integer. The bit size can be changed by the user by defining MINT_t to something other than int in the port configuration file. This integer type is used by the operating system e.g. for semaphore counters and timer. See also: UINT_t

typedef UVAR_t JIF_t

| Timer counter type. Can be UVAR_t or UINT_t. See also: SJIF_t

typedef unsigned MPTR_t MEMPTR_t

| Memory pointer type. This variable type is an integer with the width of the address lines of memory architecure. The bit width is equal to the width of a void-pointer. This variable type is needed by the operating system for lossless typecasting of void pointers to integers. MPTR_t is a define that is set in the port configuration file. When MPTR_t is not set, it defaults to long. See also: MPTR_t

typedef volatile INT_t POSATOMIC_t

| Atomic variable. See also: posAtomicGet, posAtomicSet, posAtomicAdd, posAtomicSub

typedef struct POSFLAG* POSFLAG_t

| Handle to a flag object. See also: posFlagCreate, posFlagDestroy, posFlagGet, posFlagSet

typedef void(* POSINTFUNC_t)(UVAR_t arg)

| Software interrupt callback function pointer. The parameter arg is the value that was dropped in the call to posSoftInt. See also: posSoftInt

typedef struct POSLIST POSLIST_t

| List variable. This variable type is used as running variable of a list or as list link. See also: POSLISTHEAD_t, posListInit, posListTerm, posListAdd, posListGet

typedef struct POSLISTHEAD POSLISTHEAD_t

| List variable. This variable defines the head of a list. See also: POSLIST_t, posListInit, posListTerm, posListAdd, posListGet

typedef struct POSMUTEX* POSMUTEX_t

| Handle to a mutex object. See also: posMutexCreate, posMutexLock, posMutexTryLock, posMutexUnlock

typedef struct POSSEMA* POSSEMA_t

| Handle to a semaphore object. See also: posSemaCreate, posSemaGet, posSemaWait, posSemaSignal

typedef struct POSTASK* POSTASK_t

| Task environment structure. Most members of this structure are private, and are hidden from the user. The user can add its own members to the structure. For this purpose the user must define the macro POS_USERTASKDATA in the pico]OS configuration file. Here is an example of this macro:
     #define POS_USERTASKDATA \
       void            *stackptr; \
       unsigned short  stack[FIXED_STACK_SIZE]; \
       int             errno;
Note that the stackptr variable is required by most of the architecture ports. The stack array is an example of how to include the stack frame into the task environment structure (e.g. when POSCFG_TASKSTACKTYPE is defined to 2).

typedef void(* POSTASKFUNC_t)(void *arg)

  | Generic function pointer. Parameters:
  | arg | optional argument, can be NULL if not used.

typedef struct POSTIMER* POSTIMER_t

| Handle to a timer object. See also: posTimerCreate, posTimerDestroy, posTimerSet, posTimerStart

typedef VAR_t SJIF_t

| Signed type of JIF_t. See also: JIF_t

typedef unsigned MINT_t UINT_t

| Unsigned integer. The bit size can be changed by the user by defining MINT_t to something other than int in the pico]OS configuration file. This integer type is used by the operating system e.g. for semaphore counters and timer. See also: INT_t

typedef unsigned MVAR_t UVAR_t

| Unsigned machine variable type. This variable type is the fastest for the target architecture. See also: VAR_t

typedef signed MVAR_t VAR_t

| Signed machine variable type. This variable type is the fastest for the target architecture. See also: UVAR_t

## Variable Documentation

VAR_t errno

| Unix style error variable. This variable is global for the currently runnig task. Note: POSCFG_FEATURE_ERRNO must be set to 1 to enable this variable. See also: POSCFG_FEATURE_ERRNO, E_OK

POSEXTERN volatile POSTASK_t posCurrentTask_g

| Global task variable. This variable points to the environment structure of the currently active task. Note: Only the context switch functions p_pos_softContextSwitch, p_pos_intContextSwitch and p_pos_startFirstContext need to access this variable. See also: posNextTask_g

POSEXTERN volatile UVAR_t posInInterrupt_g

| Global flag variable. This variable is nonzero when the CPU is currently executing an interrupt service routine. Note: Only the architecture specific ISR functions need to access this variable.

POSEXTERN volatile POSTASK_t posNextTask_g

| Global task variable. This variable points to the environment structure of the next task that shall be scheduled. Note: The context switch functions p_pos_softContextSwitch and p_pos_intContextSwitch must copy the content of this variable into the posCurrentTask_g variable. See also: posCurrentTask_g

POSEXTERN volatile UVAR_t posRunning_g

| Global flag variable. This variable is nonzero when the operating system is initialized and running. Note: Only the architecture specific ISR functions need to access this variable.