EasyGUI
System functions

System based function for OS management, timings, etc. More...

Macros

#define GUI_SYS_MBOX_NULL   (osMessageQId)0
 Value indicating message queue is not valid. More...
 
#define GUI_SYS_SEM_NULL   (osSemaphoreId)0
 Value indicating semaphore is not valid. More...
 
#define GUI_SYS_MUTEX_NULL   (osMutexId)0
 Value indicating mutex is not valid. More...
 
#define GUI_SYS_TIMEOUT   ((uint32_t)osWaitForever)
 Value indicating timeout for OS timings. More...
 
#define GUI_SYS_THREAD_PRIO   (osPriorityNormal)
 ESP stack threads priority parameter. More...
 
#define GUI_SYS_THREAD_SS   (1024)
 Stack size of system threads. More...
 

Typedefs

typedef void(* gui_sys_thread_fn) (void *)
 Thread function prototype.
 
typedef osMutexId gui_sys_mutex_t
 ESP system mutex ID type. More...
 
typedef osSemaphoreId gui_sys_sem_t
 ESP system semaphore ID type. More...
 
typedef osMessageQId gui_sys_mbox_t
 ESP system message queue ID type. More...
 
typedef osThreadId gui_sys_thread_t
 ESP system thread ID type. More...
 
typedef osPriority gui_sys_thread_prio_t
 ESP system thread priority type. More...
 

Functions

uint8_t gui_sys_init (void)
 Init system dependant parameters. More...
 
uint32_t gui_sys_now (void)
 Get current time in units of milliseconds. More...
 
uint8_t gui_sys_protect (void)
 Unprotect stack core. More...
 
uint8_t gui_sys_unprotect (void)
 Unprotect stack core. More...
 
uint8_t gui_sys_mutex_create (gui_sys_mutex_t *p)
 Create a new mutex and pass it to input pointer. More...
 
uint8_t gui_sys_mutex_delete (gui_sys_mutex_t *p)
 Delete mutex from OS. More...
 
uint8_t gui_sys_mutex_lock (gui_sys_mutex_t *p)
 Wait forever to lock the mutex. More...
 
uint8_t gui_sys_mutex_unlock (gui_sys_mutex_t *p)
 Unlock mutex. More...
 
uint8_t gui_sys_mutex_isvalid (gui_sys_mutex_t *p)
 Check if mutex structure is valid OS entry. More...
 
uint8_t gui_sys_mutex_invalid (gui_sys_mutex_t *p)
 Set mutex structure as invalid. More...
 
uint8_t gui_sys_sem_create (gui_sys_sem_t *p, uint8_t cnt)
 Create a new binary semaphore and set initial state. More...
 
uint8_t gui_sys_sem_delete (gui_sys_sem_t *p)
 Delete binary semaphore. More...
 
uint32_t gui_sys_sem_wait (gui_sys_sem_t *p, uint32_t timeout)
 Wait for semaphore to be available. More...
 
uint8_t gui_sys_sem_release (gui_sys_sem_t *p)
 Release semaphore. More...
 
uint8_t gui_sys_sem_isvalid (gui_sys_sem_t *p)
 Check if semaphore is valid. More...
 
uint8_t gui_sys_sem_invalid (gui_sys_sem_t *p)
 Invalid semaphore. More...
 
uint8_t gui_sys_mbox_create (gui_sys_mbox_t *b, size_t size)
 Create a new message queue with entry type of void * More...
 
uint8_t gui_sys_mbox_delete (gui_sys_mbox_t *b)
 Delete message queue. More...
 
uint32_t gui_sys_mbox_put (gui_sys_mbox_t *b, void *m)
 Put a new entry to message queue and wait until memory available. More...
 
uint32_t gui_sys_mbox_get (gui_sys_mbox_t *b, void **m, uint32_t timeout)
 Get a new entry from message queue with timeout. More...
 
uint8_t gui_sys_mbox_putnow (gui_sys_mbox_t *b, void *m)
 Put a new entry to message queue without timeout (now or fail) More...
 
uint8_t gui_sys_mbox_getnow (gui_sys_mbox_t *b, void **m)
 Get an entry from message queue immediatelly. More...
 
uint8_t gui_sys_mbox_isvalid (gui_sys_mbox_t *b)
 Check if message queue is valid. More...
 
uint8_t gui_sys_mbox_invalid (gui_sys_mbox_t *b)
 Invalid message queue. More...
 
uint8_t gui_sys_thread_create (gui_sys_thread_t *t, const char *name, gui_sys_thread_fn thread_fn, void *const arg, size_t stack_size, gui_sys_thread_prio_t prio)
 Create a new thread. More...
 
uint8_t gui_sys_thread_terminate (gui_sys_thread_t *t)
 
uint8_t gui_sys_thread_yield (void)
 

System ports

List of already available system ports. Configure GUI_CFG_SYS_PORT with one of these values to use preconfigured ports

#define GUI_SYS_PORT_CMSIS_OS   1
 
#define GUI_SYS_PORT_WIN32   2
 

Detailed Description

System based function for OS management, timings, etc.

Macro Definition Documentation

◆ GUI_SYS_MBOX_NULL

#define GUI_SYS_MBOX_NULL   (osMessageQId)0

Value indicating message queue is not valid.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ GUI_SYS_MUTEX_NULL

#define GUI_SYS_MUTEX_NULL   (osMutexId)0

Value indicating mutex is not valid.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ GUI_SYS_PORT_CMSIS_OS

#define GUI_SYS_PORT_CMSIS_OS   1

CMSIS-OS based port for OS systems capable of ARM CMSIS standard

◆ GUI_SYS_PORT_WIN32

#define GUI_SYS_PORT_WIN32   2

WIN32 based port to use ESP library with Windows applications

◆ GUI_SYS_SEM_NULL

#define GUI_SYS_SEM_NULL   (osSemaphoreId)0

Value indicating semaphore is not valid.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ GUI_SYS_THREAD_PRIO

#define GUI_SYS_THREAD_PRIO   (osPriorityNormal)

ESP stack threads priority parameter.

Note
Usually normal priority is ok. If many threads are in the system and high traffic is introduced This value might need to be set to higher value
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ GUI_SYS_THREAD_SS

#define GUI_SYS_THREAD_SS   (1024)

Stack size of system threads.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ GUI_SYS_TIMEOUT

#define GUI_SYS_TIMEOUT   ((uint32_t)osWaitForever)

Value indicating timeout for OS timings.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

Typedef Documentation

◆ gui_sys_mbox_t

typedef osMessageQId gui_sys_mbox_t

ESP system message queue ID type.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ gui_sys_mutex_t

typedef osMutexId gui_sys_mutex_t

ESP system mutex ID type.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ gui_sys_sem_t

typedef osSemaphoreId gui_sys_sem_t

ESP system semaphore ID type.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ gui_sys_thread_prio_t

typedef osPriority gui_sys_thread_prio_t

ESP system thread priority type.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

◆ gui_sys_thread_t

typedef osThreadId gui_sys_thread_t

ESP system thread ID type.

Note
Keep as is in case of CMSIS based OS, otherwise change for your OS

Function Documentation

◆ gui_sys_init()

uint8_t gui_sys_init ( void  )

Init system dependant parameters.

Note
Called from high-level application layer when required
Returns
1 on success, 0 otherwise

◆ gui_sys_mbox_create()

uint8_t gui_sys_mbox_create ( gui_sys_mbox_t b,
size_t  size 
)

Create a new message queue with entry type of void *

Note
This function is required with OS
Parameters
[out]bPointer to message queue structure
[in]sizeNumber of entries for message queue to hold
Returns
1 on success, 0 otherwise

◆ gui_sys_mbox_delete()

uint8_t gui_sys_mbox_delete ( gui_sys_mbox_t b)

Delete message queue.

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mbox_get()

uint32_t gui_sys_mbox_get ( gui_sys_mbox_t b,
void **  m,
uint32_t  timeout 
)

Get a new entry from message queue with timeout.

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
[in]mPointer to pointer to result to save value from message queue to
[in]timeoutMaximal timeout to wait for new message. When 0 is applied, wait for unlimited time
Returns
Time in units of milliseconds needed to put a message to queue

◆ gui_sys_mbox_getnow()

uint8_t gui_sys_mbox_getnow ( gui_sys_mbox_t b,
void **  m 
)

Get an entry from message queue immediatelly.

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
[in]mPointer to pointer to result to save value from message queue to
Returns
1 on success, 0 otherwise

◆ gui_sys_mbox_invalid()

uint8_t gui_sys_mbox_invalid ( gui_sys_mbox_t b)

Invalid message queue.

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mbox_isvalid()

uint8_t gui_sys_mbox_isvalid ( gui_sys_mbox_t b)

Check if message queue is valid.

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mbox_put()

uint32_t gui_sys_mbox_put ( gui_sys_mbox_t b,
void *  m 
)

Put a new entry to message queue and wait until memory available.

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
[in]mPointer to entry to insert to message queue
Returns
Time in units of milliseconds needed to put a message to queue

◆ gui_sys_mbox_putnow()

uint8_t gui_sys_mbox_putnow ( gui_sys_mbox_t b,
void *  m 
)

Put a new entry to message queue without timeout (now or fail)

Note
This function is required with OS
Parameters
[in]bPointer to message queue structure
[in]mPointer to message to save to queue
Returns
1 on success, 0 otherwise

◆ gui_sys_mutex_create()

uint8_t gui_sys_mutex_create ( gui_sys_mutex_t p)

Create a new mutex and pass it to input pointer.

Note
This function is required with OS
Recursive mutex must be created as it may be locked multiple times before unlocked
Parameters
[out]pPointer to mutex structure to save result to
Returns
1 on success, 0 otherwise

◆ gui_sys_mutex_delete()

uint8_t gui_sys_mutex_delete ( gui_sys_mutex_t p)

Delete mutex from OS.

Note
This function is required with OS
Parameters
[in]pPointer to mutex structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mutex_invalid()

uint8_t gui_sys_mutex_invalid ( gui_sys_mutex_t p)

Set mutex structure as invalid.

Note
This function is required with OS
Parameters
[in]pPointer to mutex structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mutex_isvalid()

uint8_t gui_sys_mutex_isvalid ( gui_sys_mutex_t p)

Check if mutex structure is valid OS entry.

Note
This function is required with OS
Parameters
[in]pPointer to mutex structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mutex_lock()

uint8_t gui_sys_mutex_lock ( gui_sys_mutex_t p)

Wait forever to lock the mutex.

Note
This function is required with OS
Parameters
[in]pPointer to mutex structure
Returns
1 on success, 0 otherwise

◆ gui_sys_mutex_unlock()

uint8_t gui_sys_mutex_unlock ( gui_sys_mutex_t p)

Unlock mutex.

Note
This function is required with OS
Parameters
[in]pPointer to mutex structure
Returns
1 on success, 0 otherwise

◆ gui_sys_now()

uint32_t gui_sys_now ( void  )

Get current time in units of milliseconds.

Returns
Current time in units of milliseconds

◆ gui_sys_protect()

uint8_t gui_sys_protect ( void  )

Unprotect stack core.

Note
This function is required with OS
Returns
1 on success, 0 otherwise

◆ gui_sys_sem_create()

uint8_t gui_sys_sem_create ( gui_sys_sem_t p,
uint8_t  cnt 
)

Create a new binary semaphore and set initial state.

Note
Semaphore may only have 1 token available
This function is required with OS
Parameters
[out]pPointer to semaphore structure to fill with result
[in]cntCount indicating default semaphore state: 0: Lock it immediteally 1: Leave it unlocked
Returns
1 on success, 0 otherwise

◆ gui_sys_sem_delete()

uint8_t gui_sys_sem_delete ( gui_sys_sem_t p)

Delete binary semaphore.

Note
This function is required with OS
Parameters
[in]pPointer to semaphore structure
Returns
1 on success, 0 otherwise

◆ gui_sys_sem_invalid()

uint8_t gui_sys_sem_invalid ( gui_sys_sem_t p)

Invalid semaphore.

Note
This function is required with OS
Parameters
[in]pPointer to semaphore structure
Returns
1 on success, 0 otherwise

◆ gui_sys_sem_isvalid()

uint8_t gui_sys_sem_isvalid ( gui_sys_sem_t p)

Check if semaphore is valid.

Note
This function is required with OS
Parameters
[in]pPointer to semaphore structure
Returns
1 on success, 0 otherwise

◆ gui_sys_sem_release()

uint8_t gui_sys_sem_release ( gui_sys_sem_t p)

Release semaphore.

Note
This function is required with OS
Parameters
[in]pPointer to semaphore structure
Returns
1 on success, 0 otherwise

◆ gui_sys_sem_wait()

uint32_t gui_sys_sem_wait ( gui_sys_sem_t p,
uint32_t  timeout 
)

Wait for semaphore to be available.

Note
This function is required with OS
Parameters
[in]pPointer to semaphore structure
[in]timeoutTimeout to wait in milliseconds. When 0 is applied, wait forever
Returns
Number of milliseconds waited for semaphore to become available

◆ gui_sys_thread_create()

uint8_t gui_sys_thread_create ( gui_sys_thread_t t,
const char *  name,
void(*)(void *)  thread_func,
void *const  arg,
size_t  stack_size,
gui_sys_thread_prio_t  prio 
)

Create a new thread.

Note
This function is required with OS
Parameters
[out]tPointer to thread identifier if create was successful
[in]nameName of a new thread
[in]thread_funcThread function to use as thread body
[in]argThread function argument
[in]stack_sizeSize of thread stack in uints of bytes. If set to 0, reserve default stack size
[in]prioThread priority
Returns
1 on success, 0 otherwise

◆ gui_sys_unprotect()

uint8_t gui_sys_unprotect ( void  )

Unprotect stack core.

Note
This function is required with OS
Returns
1 on success, 0 otherwise