PIC24 Support Libraries
Data Structures | Macros | Typedefs | Functions
esos.h File Reference
#include "all_generic.h"
#include "esos_task.h"
#include "esos_mail.h"
#include "esos_comm.h"
#include "esos_irq.h"

Go to the source code of this file.

Data Structures

struct  stMailBoxDesc
 
struct  stMailEnvelope
 

Macros

#define MAX_NUM_CHILD_TASKS   MAX_NUM_USER_TASKS
 
#define ESOS_USER_FLAG_0
 
#define ESOS_USER_FLAG_1
 
#define ESOS_USER_FLAG_2
 
#define ESOS_USER_FLAG_3
 
#define ESOS_USER_FLAG_4
 
#define ESOS_USER_FLAG_5
 
#define ESOS_USER_FLAG_6
 
#define ESOS_USER_FLAG_7
 
#define ESOS_USER_FLAG_8
 
#define ESOS_USER_FLAG_9
 
#define ESOS_USER_FLAG_A
 
#define ESOS_USER_FLAG_B
 
#define ESOS_USER_FLAG_C
 
#define ESOS_USER_FLAG_D
 
#define ESOS_USER_FLAG_E
 
#define ESOS_USER_FLAG_F
 
#define ESOS_USER_TIMER(timername)
 
#define esos_GetSystemTick()
 
#define esos_GetNumberRegisteredTasks()
 
#define esos_GetFutureSystemTick(deltaT)
 
#define esos_SetUserFlag(mask)
 
#define esos_ClearUserFlag(mask)
 
#define esos_IsUserFlagSet(mask)
 
#define esos_IsUserFlagClear(mask)
 
#define esos_GetNumberRunningTimers()
 
#define esos_IsTimerRunning(hndl)
 

Typedefs

typedef int main_t
 
typedef uint8_t ESOS_TMR_HANDLE
 

Functions

void user_init (void)
 
ESOS_TASK_HANDLE esos_GetFreeChildTaskStruct ()
 
uint32_t esos_GetRandomUint32 ()
 
ESOS_TASK_HANDLE esos_GetTaskHandle (uint8_t(*taskname)(ESOS_TASK_HANDLE pstTask))
 
ESOS_TASK_HANDLE esos_GetTaskHandleFromID (uint16_t u16_TaskID)
 
uint32_t esos_string_hash_u32 (char *psz_str)
 
uint32_t esos_buffer_hash_u32 (void *buf, uint16_t len)
 
ESOS_TMR_HANDLE esos_RegisterTimer (void(*pfnTmrFcn)(void), uint32_t u32_period)
 
uint8_t esos_UnregisterTimer (ESOS_TMR_HANDLE hnd_timer)
 
ESOS_TMR_HANDLE esos_GetTimerHandle (void(*pfnTmrFcn)(void))
 
uint8_t esos_ChangeTimerPeriod (ESOS_TMR_HANDLE hnd_timer, uint32_t u32_period)
 

Detailed Description

Embedded Systems Operating System (ESOS)

Definition in file esos.h.

Macro Definition Documentation

◆ esos_ClearUserFlag

#define esos_ClearUserFlag (   mask)

Clears bits in the global user flags provided by ESOS

Parameters
maskAn uint16 value composed of the OR-ed user mask flag masks, where each flag in the OR will be cleared
Note
User should use the provided bits masks like ESOS_USER_FLAG_0 and ESOS_USER_FLAG_1 and ... ESOS_USER_FLAG_F to create their own readable constants
#define HEADLIGHTS_ARE_ON ESOS_USER_FLAG_3
#define MY_USER_FRIENDLY_FLAG ESOS_USER_FLAG_7
esos_ClearUserFlag( HEADLIGHTS_ARE_ON | MY_USER_FRIENDLY_FLAG);
See also
esos_SetUserFlag
esos_IsUserFlagSet
esos_IsUserFlagClear

Definition at line 382 of file esos.h.

◆ esos_GetFutureSystemTick

#define esos_GetFutureSystemTick (   deltaT)

Returns the system tick value of a future time

Parameters
deltaTthe number of ticks in the future you'd like the system tick value for
Returns
The uint32 number corresponding to the system tick value of that future time
See also
esos_GetSystemTick

Definition at line 344 of file esos.h.

◆ esos_GetNumberRegisteredTasks

#define esos_GetNumberRegisteredTasks ( )

Get the current number of user task registered with the ESOS scheduler.

Returns
The uint8_t number of currently registered user tasks
Note
This value does not include the number of child tasks (tasks of the type ESOS_CHILD_TASK ), just the tasks of the type ESOS_USER_TASK

Definition at line 333 of file esos.h.

◆ esos_GetNumberRunningTimers

#define esos_GetNumberRunningTimers ( )

Get the current number of user software timers registers (running) in the ESOS timer services

Returns
The uint8_t number of currently registered user tasks

Definition at line 445 of file esos.h.

Referenced by esos_GetTimerHandle(), and esos_RegisterTimer().

◆ esos_GetSystemTick

#define esos_GetSystemTick ( )

Get the current value of the ESOS system tick counter In the current implementation of ESOS, a tick equal 1.0ms. Therefore, the value returned by this function is approximately equal to the number of milliseconds since the since was last reset.

Returns
The uint32 value of current value of the ESOS system tick counter
Note
This counter value will roll-over every 49.7 days.

Definition at line 307 of file esos.h.

◆ esos_IsTimerRunning

#define esos_IsTimerRunning (   hndl)

Determines if the software timer represented by the handle is currently running

Parameters
hndlThe ESOS_TMR_HANDLE of a software timer
Return values
TRUEif the timer is currently running
FALSEif the timer is not currently running
See also
ESOS_USER_TIMER
esos_UnregisterTimer
esos_GetTimerHandle
esos_ChangeTimerPeriod

Definition at line 458 of file esos.h.

Referenced by esos_ChangeTimerPeriod(), esos_GetTimerHandle(), and esos_UnregisterTimer().

◆ esos_IsUserFlagClear

#define esos_IsUserFlagClear (   mask)

Queries whether the global user flags provided by ESOS are clear

Parameters
maskAn uint16 value composed of the OR-ed user mask flag masks, where each flag in the OR will be checked for being clear
Return values
TRUEif at least one of the flags is clear
FALSEif none of the flags are clear
Note
User should use the provided bits masks like ESOS_USER_FLAG_0 and ESOS_USER_FLAG_1 and ... ESOS_USER_FLAG_F to create their own readable constants
#define HEADLIGHTS_ARE_ON ESOS_USER_FLAG_3
#define MY_USER_FRIENDLY_FLAG ESOS_USER_FLAG_7
esos_ClearUserFlag( HEADLIGHTS_ARE_ON | MY_USER_FRIENDLY_FLAG);
while(esos_IsUserFlagClear( HEADLIGHTS_ARE_ON)); // infinite loop
See also
esos_SetUserFlag
esos_ClearUserFlag
esos_IsUserFlagSet

Definition at line 426 of file esos.h.

◆ esos_IsUserFlagSet

#define esos_IsUserFlagSet (   mask)

Queries whether the global user flags provided by ESOS are set

Parameters
maskAn uint16 value composed of the OR-ed user mask flag masks, where each flag in the OR will be checked for being set
Return values
TRUEif at least one of the flags is set
FALSEif none of the flags are set
Note
User should use the provided bits masks like ESOS_USER_FLAG_0 and ESOS_USER_FLAG_1 and ... ESOS_USER_FLAG_F to create their own readable constants
#define HEADLIGHTS_ARE_ON ESOS_USER_FLAG_3
#define MY_USER_FRIENDLY_FLAG ESOS_USER_FLAG_7
esos_ClearUserFlag( HEADLIGHTS_ARE_ON | MY_USER_FRIENDLY_FLAG);
while(esos_IsUserFlagSet( HEADLIGHTS_ARE_ON)); // falls through
See also
esos_SetUserFlag
esos_ClearUserFlag
esos_IsUserFlagClear

Definition at line 404 of file esos.h.

◆ esos_SetUserFlag

#define esos_SetUserFlag (   mask)

Sets bits in the global user flags provided by ESOS

Parameters
maskAn uint16 value composed of the OR-ed user mask flag masks, where each flag in the OR will be set
Note
User should use the provided bits masks like ESOS_USER_FLAG_0 to create their own readable constants
#define HEADLIGHTS_ARE_ON ESOS_USER_FLAG_3
#define MY_USER_FRIENDLY_FLAG ESOS_USER_FLAG_7
esos_SetUserFlag( HEADLIGHTS_ARE_ON | MY_USER_FRIENDLY_FLAG);
See also
esos_ClearUserFlag
esos_IsUserFlagSet
esos_IsUserFlagClear

Definition at line 362 of file esos.h.

◆ ESOS_USER_FLAG_0

#define ESOS_USER_FLAG_0

Mask for a global user flag provided by ESOS

Definition at line 148 of file esos.h.

◆ ESOS_USER_FLAG_1

#define ESOS_USER_FLAG_1

Mask for a global user flag provided by ESOS

Definition at line 152 of file esos.h.

◆ ESOS_USER_FLAG_2

#define ESOS_USER_FLAG_2

Mask for a global user flag provided by ESOS

Definition at line 156 of file esos.h.

◆ ESOS_USER_FLAG_3

#define ESOS_USER_FLAG_3

Mask for a global user flag provided by ESOS

Definition at line 160 of file esos.h.

◆ ESOS_USER_FLAG_4

#define ESOS_USER_FLAG_4

Mask for a global user flag provided by ESOS

Definition at line 164 of file esos.h.

◆ ESOS_USER_FLAG_5

#define ESOS_USER_FLAG_5

Mask for a global user flag provided by ESOS

Definition at line 168 of file esos.h.

◆ ESOS_USER_FLAG_6

#define ESOS_USER_FLAG_6

Mask for a global user flag provided by ESOS

Definition at line 172 of file esos.h.

◆ ESOS_USER_FLAG_7

#define ESOS_USER_FLAG_7

Mask for a global user flag provided by ESOS

Definition at line 176 of file esos.h.

◆ ESOS_USER_FLAG_8

#define ESOS_USER_FLAG_8

Mask for a global user flag provided by ESOS

Definition at line 180 of file esos.h.

◆ ESOS_USER_FLAG_9

#define ESOS_USER_FLAG_9

Mask for a global user flag provided by ESOS

Definition at line 184 of file esos.h.

◆ ESOS_USER_FLAG_A

#define ESOS_USER_FLAG_A

Mask for a global user flag provided by ESOS

Definition at line 188 of file esos.h.

◆ ESOS_USER_FLAG_B

#define ESOS_USER_FLAG_B

Mask for a global user flag provided by ESOS

Definition at line 192 of file esos.h.

◆ ESOS_USER_FLAG_C

#define ESOS_USER_FLAG_C

Mask for a global user flag provided by ESOS

Definition at line 196 of file esos.h.

◆ ESOS_USER_FLAG_D

#define ESOS_USER_FLAG_D

Mask for a global user flag provided by ESOS

Definition at line 200 of file esos.h.

◆ ESOS_USER_FLAG_E

#define ESOS_USER_FLAG_E

Mask for a global user flag provided by ESOS

Definition at line 204 of file esos.h.

◆ ESOS_USER_FLAG_F

#define ESOS_USER_FLAG_F

Mask for a global user flag provided by ESOS

Definition at line 208 of file esos.h.

◆ ESOS_USER_TIMER

#define ESOS_USER_TIMER (   timername)

Declaration of an user-defined timer callback (for ESOS timer services)

This macro is used to declare a user-timer. All timers using ESOS timer services must be declared with this macro.

Parameters
timernameThe name of the software timer to create.
Note
You are really creating a C function implementing the user timer callback. Since ESOS timer serivces calls this callback function at the appropriate time, this function cannot be passed arguments and cannot return values

Definition at line 223 of file esos.h.

◆ MAX_NUM_CHILD_TASKS

#define MAX_NUM_CHILD_TASKS   MAX_NUM_USER_TASKS

Define the maximum number of user tasks in the system

Note
Technically, this is actually the maximum number of tasks that will be running "concurrently". Usually, this number is the maximum number of tasks that the user has defined, UNLESS they are absolutely sure that two (or more) tasks are mutually exclusive in execution.
BOTH "parent" and "child" tasks use this NUMBER to allocate their pool of tasks. So this number should be equal to or greater than the MAXIMUM number of concurrently running child –OR– parent tasks.

Definition at line 112 of file esos.h.

Referenced by esos_GetFreeChildTaskStruct().

Typedef Documentation

◆ ESOS_TMR_HANDLE

Handle to a software timer in the ESOS timer service.

See also
ESOS_USER_TIMER
esos_RegisterTimer
esos_UnregisterTimer
esos_GetTimerHandle
esos_ChangeTimerPeriod

Definition at line 236 of file esos.h.

◆ main_t

typedef int main_t

Define the constants and structures required for our little embedded systems operating system

Definition at line 91 of file esos.h.

Function Documentation

◆ esos_buffer_hash_u32()

uint32_t esos_buffer_hash_u32 ( void *  buf,
uint16_t  len 
)

Create a 32-bit (uint32_t) hash value for a buffer of voids Routine maintains "state" in the form of variable __esos_u32FNVHash This "state" is used in all of the ESOS FNV hash functions. Based on the Fowler/Noll/Vo (FNV1a) hash algorithm and code provided at http://www.isthe.com/chongo/tech/comp/fnv/

Parameters
bufpointer to a buffer of voids
lenlength of the buffer of voids
Return values
uint32_tvalue of the resulting hash
See also
esos_string_hash_u32
esos_hash_u32_to_u16

Definition at line 379 of file esos.c.

◆ esos_ChangeTimerPeriod()

uint8_t esos_ChangeTimerPeriod ( ESOS_TMR_HANDLE  hnd_timer,
uint32_t  u32_period 
)

Change a timer period.

Parameters
hnd_timerhandle to timer whose period is to be changed
u32_periodnew period for timer selected by mask
Return values
FALSEif timer is not currently running
TRUEif timer period was changed
See also
esos_RegisterTimer
esos_UnregisterTimer
esos_GetTimerHandle
esos_IsTimerRunning

Definition at line 591 of file esos.c.

◆ esos_GetFreeChildTaskStruct()

ESOS_TASK_HANDLE esos_GetFreeChildTaskStruct ( )

Searches child task pool to find a free child task structure and returns a handle (pst) back to the caller

Return values
TaskHandleif a child task structure is available
ESOS_BAD_CHILD_TASK_HANDLEif no structures are available at this time

Definition at line 298 of file esos.c.

◆ esos_GetRandomUint32()

uint32_t esos_GetRandomUint32 ( void  )

Returns a 31-bit pseudo-random number generated by the Park-Miller algorithm.

See also
esos_SetRandomUint32Seed
Note
Visit http://www.firstpr.com.au/dsp/rand31/ for more information

Definition at line 332 of file esos.c.

◆ esos_GetTaskHandle()

ESOS_TASK_HANDLE esos_GetTaskHandle ( uint8_t(*)(ESOS_TASK_HANDLE pstTask)  taskname)

Find the (active) task handle for a given task function

Parameters
tasknamename of task (argument to ESOS_USER_TASK declaration
Return values
NULLPTRif task is not found among the active tasks
TaskHandlethe handle to the task function requested
See also
ESOS_USER_TASK
esos_RegisterTask
esos_UnregisterTask

Definition at line 219 of file esos.c.

◆ esos_GetTaskHandleFromID()

ESOS_TASK_HANDLE esos_GetTaskHandleFromID ( uint16_t  u16_TaskID)

Find the (active) task handle for a given task function

Parameters
u16_TaskIDname of task (argument to ESOS_USER_TASK declaration)
Return values
NULLPTRif task is not found among the active tasks
TaskHandlethe handle to the task function requested
See also
ESOS_USER_TASK
esos_RegisterTask
esos_UnregisterTask

Definition at line 255 of file esos.c.

◆ esos_GetTimerHandle()

ESOS_TMR_HANDLE esos_GetTimerHandle ( void(*)(void)  pfnTmrFcn)

Finds the timer handle to the provided and ACTIVE timer function

Parameters
pfnTmrFcnpointer to timer function (will execute each time timer expires)
Return values
ESOS_TMR_FAILUREcould not find the function in the active timer list
timerHandlehandle to timer
See also
esos_RegisterTimer
esos_UnregisterTimer
esos_ChangeTimerPeriod
esos_IsTimerRunning

Definition at line 564 of file esos.c.

◆ esos_RegisterTimer()

ESOS_TMR_HANDLE esos_RegisterTimer ( void(*)(void)  timername,
uint32_t  u32_period 
)

Adds a timer to the ESOS timer service. Timer function will execute at its next opportunity. Timer functions must have void arguments and void returns.

Parameters
timernamename under which timer was declared in ESOS_USER_TIMER. and contains the code to run when software timer expires
u32_periodperiod of timer in system ticks (currently, milliseconds)
Return values
ESOS_TMR_FAILUREif no more timers can added at this time
timerhandleif timer service was registered
See also
ESOS_USER_TIMER
esos_UnregisterTimer
esos_GetTimerHandle
esos_ChangeTimerPeriod
esos_IsTimerRunning

Definition at line 514 of file esos.c.

◆ esos_string_hash_u32()

uint32_t esos_string_hash_u32 ( char *  psz_str)

Create a 32-bit (uint32_t) hash value for a provided string Routine maintains "state" in the form of variable __esos_u32FNVHash This "state" is used in all of the ESOS FNV hash functions. Based on the Fowler/Noll/Vo (FNV1a) hash algorithm and code provided at http://www.isthe.com/chongo/tech/comp/fnv/

Parameters
psz_strpointer to zero-terminated string
Return values
uint32_tvalue of the resulting hash
See also
esos_string_hash_u32
esos_hash_u32_to_u16

Definition at line 415 of file esos.c.

◆ esos_UnregisterTimer()

uint8_t esos_UnregisterTimer ( ESOS_TMR_HANDLE  hnd_timer)

Removes a timer from the ESOS timer service.

Parameters
hnd_timerhandle to timer to remove
Return values
FALSEif timer wasn't active in the first place
TRUEif timer was stopped and removed
See also
esos_RegisterTimer
esos_GetTimerHandle
esos_ChangeTimerPeriod

Definition at line 543 of file esos.c.

◆ user_init()

void user_init ( void  )

User-provided function to initialize user's hardware configuration register user tasks.

Note
All ESOS applications MUST provide this function.
This function MUST register at least one ESOS task.
user_init() is a centralized initialization routine where the user can setup their application. It is called automagically by ES_OS during the operating system initialization.
User should set up any state machines and init all application variables. They can also turn on any needed peripherals here.
User shall not mess with the interrupt hardware directly!!! The ESOS must be aware of the interrupts and provides esos_XXXXXXX functions for the user to use. Using these ESOS-provided functions, the user may (and probably should) initialize, register, and enable interrupts in this routine.
Furthermore, the user should register AT LEAST one user application task here via esos_RegisterTask or the ES_OS scheduler will have nothing to schedule to run when this function returns.

Definition at line 116 of file app_ecan_receiver.c.