os_port_chibios.h File Reference

RTOS abstraction layer (ChibiOS/RT) More...

#include "ch.h"

Go to the source code of this file.

Data Structures

struct  OsTaskTcb
 Task control block. More...
 

Macros

#define OS_STATIC_TASK_SUPPORT   DISABLED
 
#define OS_INVALID_TASK_ID   NULL
 
#define OS_SELF_TASK_ID   NULL
 
#define OS_TASK_PRIORITY_NORMAL   NORMALPRIO
 
#define OS_TASK_PRIORITY_HIGH   HIGHPRIO
 
#define OS_MS_TO_SYSTICKS(n)   (n)
 
#define OS_SYSTICKS_TO_MS(n)   (n)
 
#define osGetSystemTime64()   osGetSystemTime()
 
#define osEnterTask()
 
#define osExitTask()
 
#define osEnterIsr()   CH_IRQ_PROLOGUE(); chSysLockFromISR()
 
#define osExitIsr(flag)   chSysUnlockFromISR(); CH_IRQ_EPILOGUE()
 
#define thread_t   Thread
 
#define semaphore_t   Semaphore
 
#define binary_semaphore_t   BinarySemaphore
 
#define mutex_t   Mutex
 
#define chThdTerminatedX   chThdTerminated
 
#define chSemObjectInit   chSemInit
 
#define chBSemObjectInit   chBSemInit
 
#define chMtxObjectInit   chMtxInit
 
#define chVTGetSystemTime   chTimeNow
 
#define chSysLockFromISR   chSysLockFromIsr
 
#define chSysUnlockFromISR   chSysUnlockFromIsr
 
#define THD_WORKING_AREA_SIZE   THD_WA_SIZE
 
#define MSG_OK   RDY_OK
 

Typedefs

typedef uint32_t systime_t
 System time. More...
 
typedef thread_tOsTaskId
 Task identifier. More...
 
typedef uint32_t OsStackType
 Stack data type. More...
 
typedef binary_semaphore_t OsEvent
 Event object. More...
 
typedef semaphore_t OsSemaphore
 Semaphore object. More...
 
typedef mutex_t OsMutex
 Mutex object. More...
 
typedef void(* OsTaskCode) (void *param)
 Task routine. More...
 

Functions

void osInitKernel (void)
 Kernel initialization. More...
 
void osStartKernel (void)
 Start kernel. More...
 
OsTaskId osCreateTask (const char_t *name, OsTaskCode taskCode, void *param, size_t stackSize, int_t priority)
 Create a task. More...
 
OsTaskId osCreateStaticTask (const char_t *name, OsTaskCode taskCode, void *param, OsTaskTcb *tcb, OsStackType *stack, size_t stackSize, int_t priority)
 Create a task with statically allocated memory. More...
 
void osDeleteTask (OsTaskId taskId)
 Delete a task. More...
 
void osDelayTask (systime_t delay)
 Delay routine. More...
 
void osSwitchTask (void)
 Yield control to the next task. More...
 
void osSuspendAllTasks (void)
 Suspend scheduler activity. More...
 
void osResumeAllTasks (void)
 Resume scheduler activity. More...
 
bool_t osCreateEvent (OsEvent *event)
 Create an event object. More...
 
void osDeleteEvent (OsEvent *event)
 Delete an event object. More...
 
void osSetEvent (OsEvent *event)
 Set the specified event object to the signaled state. More...
 
void osResetEvent (OsEvent *event)
 Set the specified event object to the nonsignaled state. More...
 
bool_t osWaitForEvent (OsEvent *event, systime_t timeout)
 Wait until the specified event is in the signaled state. More...
 
bool_t osSetEventFromIsr (OsEvent *event)
 Set an event object to the signaled state from an interrupt service routine. More...
 
bool_t osCreateSemaphore (OsSemaphore *semaphore, uint_t count)
 Create a semaphore object. More...
 
void osDeleteSemaphore (OsSemaphore *semaphore)
 Delete a semaphore object. More...
 
bool_t osWaitForSemaphore (OsSemaphore *semaphore, systime_t timeout)
 Wait for the specified semaphore to be available. More...
 
void osReleaseSemaphore (OsSemaphore *semaphore)
 Release the specified semaphore object. More...
 
bool_t osCreateMutex (OsMutex *mutex)
 Create a mutex object. More...
 
void osDeleteMutex (OsMutex *mutex)
 Delete a mutex object. More...
 
void osAcquireMutex (OsMutex *mutex)
 Acquire ownership of the specified mutex object. More...
 
void osReleaseMutex (OsMutex *mutex)
 Release ownership of the specified mutex object. More...
 
systime_t osGetSystemTime (void)
 Retrieve system time. More...
 
void * osAllocMem (size_t size)
 Allocate a memory block. More...
 
void osFreeMem (void *p)
 Release a previously allocated memory block. More...
 

Detailed Description

RTOS abstraction layer (ChibiOS/RT)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2023 Oryx Embedded SARL. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.3.0

Definition in file os_port_chibios.h.

Macro Definition Documentation

◆ binary_semaphore_t

#define binary_semaphore_t   BinarySemaphore

Definition at line 85 of file os_port_chibios.h.

◆ chBSemObjectInit

#define chBSemObjectInit   chBSemInit

Definition at line 89 of file os_port_chibios.h.

◆ chMtxObjectInit

#define chMtxObjectInit   chMtxInit

Definition at line 90 of file os_port_chibios.h.

◆ chSemObjectInit

#define chSemObjectInit   chSemInit

Definition at line 88 of file os_port_chibios.h.

◆ chSysLockFromISR

#define chSysLockFromISR   chSysLockFromIsr

Definition at line 92 of file os_port_chibios.h.

◆ chSysUnlockFromISR

#define chSysUnlockFromISR   chSysUnlockFromIsr

Definition at line 93 of file os_port_chibios.h.

◆ chThdTerminatedX

#define chThdTerminatedX   chThdTerminated

Definition at line 87 of file os_port_chibios.h.

◆ chVTGetSystemTime

#define chVTGetSystemTime   chTimeNow

Definition at line 91 of file os_port_chibios.h.

◆ MSG_OK

#define MSG_OK   RDY_OK

Definition at line 95 of file os_port_chibios.h.

◆ mutex_t

#define mutex_t   Mutex

Definition at line 86 of file os_port_chibios.h.

◆ OS_INVALID_TASK_ID

#define OS_INVALID_TASK_ID   NULL

Definition at line 43 of file os_port_chibios.h.

◆ OS_MS_TO_SYSTICKS

#define OS_MS_TO_SYSTICKS (   n)    (n)

Definition at line 59 of file os_port_chibios.h.

◆ OS_SELF_TASK_ID

#define OS_SELF_TASK_ID   NULL

Definition at line 45 of file os_port_chibios.h.

◆ OS_STATIC_TASK_SUPPORT

#define OS_STATIC_TASK_SUPPORT   DISABLED

Definition at line 37 of file os_port_chibios.h.

◆ OS_SYSTICKS_TO_MS

#define OS_SYSTICKS_TO_MS (   n)    (n)

Definition at line 64 of file os_port_chibios.h.

◆ OS_TASK_PRIORITY_HIGH

#define OS_TASK_PRIORITY_HIGH   HIGHPRIO

Definition at line 54 of file os_port_chibios.h.

◆ OS_TASK_PRIORITY_NORMAL

#define OS_TASK_PRIORITY_NORMAL   NORMALPRIO

Definition at line 49 of file os_port_chibios.h.

◆ osEnterIsr

#define osEnterIsr ( )    CH_IRQ_PROLOGUE(); chSysLockFromISR()

Definition at line 77 of file os_port_chibios.h.

◆ osEnterTask

#define osEnterTask ( )

Definition at line 73 of file os_port_chibios.h.

◆ osExitIsr

#define osExitIsr (   flag)    chSysUnlockFromISR(); CH_IRQ_EPILOGUE()

Definition at line 79 of file os_port_chibios.h.

◆ osExitTask

#define osExitTask ( )

Definition at line 75 of file os_port_chibios.h.

◆ osGetSystemTime64

#define osGetSystemTime64 ( )    osGetSystemTime()

Definition at line 69 of file os_port_chibios.h.

◆ semaphore_t

#define semaphore_t   Semaphore

Definition at line 84 of file os_port_chibios.h.

◆ THD_WORKING_AREA_SIZE

#define THD_WORKING_AREA_SIZE   THD_WA_SIZE

Definition at line 94 of file os_port_chibios.h.

◆ thread_t

#define thread_t   Thread

Definition at line 83 of file os_port_chibios.h.

Typedef Documentation

◆ OsEvent

Event object.

Definition at line 139 of file os_port_chibios.h.

◆ OsMutex

typedef mutex_t OsMutex

Mutex object.

Definition at line 153 of file os_port_chibios.h.

◆ OsSemaphore

Semaphore object.

Definition at line 146 of file os_port_chibios.h.

◆ OsStackType

typedef uint32_t OsStackType

Stack data type.

Definition at line 132 of file os_port_chibios.h.

◆ OsTaskCode

typedef void(* OsTaskCode) (void *param)

Task routine.

Definition at line 160 of file os_port_chibios.h.

◆ OsTaskId

typedef thread_t* OsTaskId

Task identifier.

Definition at line 115 of file os_port_chibios.h.

◆ systime_t

typedef uint32_t systime_t

System time.

Definition at line 108 of file os_port_chibios.h.

Function Documentation

◆ osAcquireMutex()

void osAcquireMutex ( OsMutex mutex)

Acquire ownership of the specified mutex object.

Parameters
[in]mutexPointer to the mutex object

Definition at line 397 of file os_port_chibios.c.

◆ osAllocMem()

void* osAllocMem ( size_t  size)

Allocate a memory block.

Parameters
[in]sizeBytes to allocate
Returns
A pointer to the allocated memory block or NULL if there is insufficient memory available

Definition at line 444 of file os_port_chibios.c.

◆ osCreateEvent()

bool_t osCreateEvent ( OsEvent event)

Create an event object.

Parameters
[in]eventPointer to the event object
Returns
The function returns TRUE if the event object was successfully created. Otherwise, FALSE is returned

Definition at line 185 of file os_port_chibios.c.

◆ osCreateMutex()

bool_t osCreateMutex ( OsMutex mutex)

Create a mutex object.

Parameters
[in]mutexPointer to the mutex object
Returns
The function returns TRUE if the mutex was successfully created. Otherwise, FALSE is returned

Definition at line 371 of file os_port_chibios.c.

◆ osCreateSemaphore()

bool_t osCreateSemaphore ( OsSemaphore semaphore,
uint_t  count 
)

Create a semaphore object.

Parameters
[in]semaphorePointer to the semaphore object
[in]countThe maximum count for the semaphore object. This value must be greater than zero
Returns
The function returns TRUE if the semaphore was successfully created. Otherwise, FALSE is returned

Definition at line 294 of file os_port_chibios.c.

◆ osCreateStaticTask()

OsTaskId osCreateStaticTask ( const char_t name,
OsTaskCode  taskCode,
void *  param,
OsTaskTcb tcb,
OsStackType stack,
size_t  stackSize,
int_t  priority 
)

Create a task with statically allocated memory.

Parameters
[in]nameA name identifying the task
[in]taskCodePointer to the task entry function
[in]paramA pointer to a variable to be passed to the task
[in]tcbPointer to the task control block
[in]stackPointer to the stack
[in]stackSizeThe initial size of the stack, in words
[in]priorityThe priority at which the task should run
Returns
Task identifier referencing the newly created task

Definition at line 99 of file os_port_chibios.c.

◆ osCreateTask()

OsTaskId osCreateTask ( const char_t name,
OsTaskCode  taskCode,
void *  param,
size_t  stackSize,
int_t  priority 
)

Create a task.

Parameters
[in]nameA name identifying the task
[in]taskCodePointer to the task entry function
[in]paramA pointer to a variable to be passed to the task
[in]stackSizeThe initial size of the stack, in words
[in]priorityThe priority at which the task should run
Returns
Task identifier referencing the newly created task

Definition at line 73 of file os_port_chibios.c.

◆ osDelayTask()

void osDelayTask ( systime_t  delay)

Delay routine.

Parameters
[in]delayAmount of time for which the calling task should block

Definition at line 138 of file os_port_chibios.c.

◆ osDeleteEvent()

void osDeleteEvent ( OsEvent event)

Delete an event object.

Parameters
[in]eventPointer to the event object

Definition at line 200 of file os_port_chibios.c.

◆ osDeleteMutex()

void osDeleteMutex ( OsMutex mutex)

Delete a mutex object.

Parameters
[in]mutexPointer to the mutex object

Definition at line 386 of file os_port_chibios.c.

◆ osDeleteSemaphore()

void osDeleteSemaphore ( OsSemaphore semaphore)

Delete a semaphore object.

Parameters
[in]semaphorePointer to the semaphore object

Definition at line 309 of file os_port_chibios.c.

◆ osDeleteTask()

void osDeleteTask ( OsTaskId  taskId)

Delete a task.

Parameters
[in]taskIdTask identifier referencing the task to be deleted

Definition at line 119 of file os_port_chibios.c.

◆ osFreeMem()

void osFreeMem ( void *  p)

Release a previously allocated memory block.

Parameters
[in]pPreviously allocated memory block to be freed

Definition at line 465 of file os_port_chibios.c.

◆ osGetSystemTime()

systime_t osGetSystemTime ( void  )

Retrieve system time.

Returns
Number of milliseconds elapsed since the system was last started

Definition at line 425 of file os_port_chibios.c.

◆ osInitKernel()

void osInitKernel ( void  )

Kernel initialization.

Definition at line 45 of file os_port_chibios.c.

◆ osReleaseMutex()

void osReleaseMutex ( OsMutex mutex)

Release ownership of the specified mutex object.

Parameters
[in]mutexPointer to the mutex object

Definition at line 409 of file os_port_chibios.c.

◆ osReleaseSemaphore()

void osReleaseSemaphore ( OsSemaphore semaphore)

Release the specified semaphore object.

Parameters
[in]semaphorePointer to the semaphore object

Definition at line 357 of file os_port_chibios.c.

◆ osResetEvent()

void osResetEvent ( OsEvent event)

Set the specified event object to the nonsignaled state.

Parameters
[in]eventPointer to the event object

Definition at line 223 of file os_port_chibios.c.

◆ osResumeAllTasks()

void osResumeAllTasks ( void  )

Resume scheduler activity.

Definition at line 171 of file os_port_chibios.c.

◆ osSetEvent()

void osSetEvent ( OsEvent event)

Set the specified event object to the signaled state.

Parameters
[in]eventPointer to the event object

Definition at line 211 of file os_port_chibios.c.

◆ osSetEventFromIsr()

bool_t osSetEventFromIsr ( OsEvent event)

Set an event object to the signaled state from an interrupt service routine.

Parameters
[in]eventPointer to the event object
Returns
TRUE if setting the event to signaled state caused a task to unblock and the unblocked task has a priority higher than the currently running task

Definition at line 275 of file os_port_chibios.c.

◆ osStartKernel()

void osStartKernel ( void  )

Start kernel.

Definition at line 56 of file os_port_chibios.c.

◆ osSuspendAllTasks()

void osSuspendAllTasks ( void  )

Suspend scheduler activity.

Definition at line 160 of file os_port_chibios.c.

◆ osSwitchTask()

void osSwitchTask ( void  )

Yield control to the next task.

Definition at line 149 of file os_port_chibios.c.

◆ osWaitForEvent()

bool_t osWaitForEvent ( OsEvent event,
systime_t  timeout 
)

Wait until the specified event is in the signaled state.

Parameters
[in]eventPointer to the event object
[in]timeoutTimeout interval
Returns
The function returns TRUE if the state of the specified object is signaled. FALSE is returned if the timeout interval elapsed

Definition at line 238 of file os_port_chibios.c.

◆ osWaitForSemaphore()

bool_t osWaitForSemaphore ( OsSemaphore semaphore,
systime_t  timeout 
)

Wait for the specified semaphore to be available.

Parameters
[in]semaphorePointer to the semaphore object
[in]timeoutTimeout interval
Returns
The function returns TRUE if the semaphore is available. FALSE is returned if the timeout interval elapsed

Definition at line 323 of file os_port_chibios.c.