Sergey Pastor / 1

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers os_port_chibios.h Source File

os_port_chibios.h

Go to the documentation of this file.
00001 /**
00002  * @file os_port_chibios.h
00003  * @brief RTOS abstraction layer (ChibiOS/RT)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License
00011  * as published by the Free Software Foundation; either version 2
00012  * of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00022  *
00023  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00024  * @version 1.7.6
00025  **/
00026 
00027 #ifndef _OS_PORT_CHIBIOS_H
00028 #define _OS_PORT_CHIBIOS_H
00029 
00030 //Dependencies
00031 #include "ch.h"
00032 
00033 //Maximum number of tasks that can be dynamically created
00034 #ifndef OS_PORT_MAX_TASKS
00035    #define OS_PORT_MAX_TASKS 16
00036 #elif (OS_PORT_MAX_TASKS < 1)
00037    #error OS_PORT_MAX_TASKS parameter is not valid
00038 #endif
00039 
00040 //Task priority (normal)
00041 #ifndef OS_TASK_PRIORITY_NORMAL
00042    #define OS_TASK_PRIORITY_NORMAL NORMALPRIO
00043 #endif
00044 
00045 //Task priority (high)
00046 #ifndef OS_TASK_PRIORITY_HIGH
00047    #define OS_TASK_PRIORITY_HIGH HIGHPRIO
00048 #endif
00049 
00050 //Milliseconds to system ticks
00051 #ifndef OS_MS_TO_SYSTICKS
00052    #define OS_MS_TO_SYSTICKS(n) (n)
00053 #endif
00054 
00055 //System ticks to milliseconds
00056 #ifndef OS_SYSTICKS_TO_MS
00057    #define OS_SYSTICKS_TO_MS(n) (n)
00058 #endif
00059 
00060 //Enter interrupt service routine
00061 #define osEnterIsr() CH_IRQ_PROLOGUE(); chSysLockFromISR()
00062 
00063 //Leave interrupt service routine
00064 #define osExitIsr(flag) chSysUnlockFromISR(); CH_IRQ_EPILOGUE()
00065 
00066 //Check kernel version
00067 #if (CH_KERNEL_MAJOR < 3)
00068    #define thread_t Thread
00069    #define semaphore_t Semaphore
00070    #define binary_semaphore_t BinarySemaphore
00071    #define mutex_t Mutex
00072    #define chThdTerminatedX chThdTerminated
00073    #define chSemObjectInit chSemInit
00074    #define chBSemObjectInit chBSemInit
00075    #define chMtxObjectInit chMtxInit
00076    #define chVTGetSystemTime chTimeNow
00077    #define chSysLockFromISR chSysLockFromIsr
00078    #define chSysUnlockFromISR chSysUnlockFromIsr
00079    #define THD_WORKING_AREA_SIZE THD_WA_SIZE
00080    #define MSG_OK RDY_OK
00081 #endif
00082 
00083 
00084 /**
00085  * @brief Task object
00086  **/
00087 
00088 typedef struct
00089 {
00090    thread_t *tp;
00091 } OsTask;
00092 
00093 
00094 /**
00095  * @brief Event object
00096  **/
00097 
00098 typedef binary_semaphore_t OsEvent;
00099 
00100 
00101 /**
00102  * @brief Semaphore object
00103  **/
00104 
00105 typedef semaphore_t OsSemaphore;
00106 
00107 
00108 /**
00109  * @brief Mutex object
00110  **/
00111 
00112 typedef mutex_t OsMutex;
00113 
00114 
00115 /**
00116  * @brief Task routine
00117  **/
00118 
00119 typedef void (*OsTaskCode)(void *params);
00120 
00121 
00122 //Kernel management
00123 void osInitKernel(void);
00124 void osStartKernel(void);
00125 
00126 //Task management
00127 bool_t osCreateStaticTask(OsTask *task, const char_t *name, OsTaskCode taskCode,
00128    void *params, void *stack, size_t stackSize, int_t priority);
00129 
00130 OsTask *osCreateTask(const char_t *name, OsTaskCode taskCode,
00131    void *params, size_t stackSize, int_t priority);
00132 
00133 void osDeleteTask(OsTask *task);
00134 void osDelayTask(systime_t delay);
00135 void osSwitchTask(void);
00136 void osSuspendAllTasks(void);
00137 void osResumeAllTasks(void);
00138 
00139 //Event management
00140 bool_t osCreateEvent(OsEvent *event);
00141 void osDeleteEvent(OsEvent *event);
00142 void osSetEvent(OsEvent *event);
00143 void osResetEvent(OsEvent *event);
00144 bool_t osWaitForEvent(OsEvent *event, systime_t timeout);
00145 bool_t osSetEventFromIsr(OsEvent *event);
00146 
00147 //Semaphore management
00148 bool_t osCreateSemaphore(OsSemaphore *semaphore, uint_t count);
00149 void osDeleteSemaphore(OsSemaphore *semaphore);
00150 bool_t osWaitForSemaphore(OsSemaphore *semaphore, systime_t timeout);
00151 void osReleaseSemaphore(OsSemaphore *semaphore);
00152 
00153 //Mutex management
00154 bool_t osCreateMutex(OsMutex *mutex);
00155 void osDeleteMutex(OsMutex *mutex);
00156 void osAcquireMutex(OsMutex *mutex);
00157 void osReleaseMutex(OsMutex *mutex);
00158 
00159 //System time
00160 systime_t osGetSystemTime(void);
00161 
00162 //Memory management
00163 void *osAllocMem(size_t size);
00164 void osFreeMem(void *p);
00165 
00166 #endif
00167