Ram Gandikota / Mbed OS ABCD
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pal_plat_rtos.h Source File

pal_plat_rtos.h

00001 /*
00002 * Copyright (c) 2016 ARM Limited. All rights reserved.
00003 * SPDX-License-Identifier: Apache-2.0
00004 * Licensed under the Apache License, Version 2.0 (the License); you may
00005 * not use this file except in compliance with the License.
00006 * You may obtain a copy of the License at
00007 *
00008 * http://www.apache.org/licenses/LICENSE-2.0
00009 *
00010 * Unless required by applicable law or agreed to in writing, software
00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 * See the License for the specific language governing permissions and
00014 * limitations under the License.
00015 */
00016 
00017 
00018 #ifndef _PAL_PLAT_RTOS_H
00019 #define _PAL_PLAT_RTOS_H
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 #include "pal_rtos.h"
00026 #include "pal_configuration.h"
00027 #include "pal_types.h"
00028 
00029 #if PAL_UNIQUE_THREAD_PRIORITY
00030 //! This array holds a counter for each thread priority.
00031 //! If the counter is more than 1, it means that more than 
00032 //! one thread has the same priority and this is a forbidden
00033 //! situation. The mapping between the priorities and the index
00034 //! in the array is as follow:
00035 //!
00036 //! PAL_osPriorityIdle --> g_palThreadPriorities[0]
00037 //! PAL_osPriorityLow --> g_palThreadPriorities[1]
00038 //! PAL_osPriorityBelowNormal --> g_palThreadPriorities[2]
00039 //! PAL_osPriorityNormal --> g_palThreadPriorities[3]
00040 //! PAL_osPriorityAboveNormal --> g_palThreadPriorities[4]
00041 //! PAL_osPriorityHigh --> g_palThreadPriorities[5]
00042 //! PAL_osPriorityRealtime --> g_palThreadPriorities[6]
00043 
00044 //! An array of PAL thread priorities. The size of the array is defined in the Service API (pal_rtos.h) by "PAL_MAX_NUMBER_OF_THREADS"
00045 extern uint8_t g_palThreadPriorities[PAL_MAX_NUMBER_OF_THREADS];
00046 
00047 #define PRIORYT_INDEX_OFFSET 3
00048 #endif //PAL_UNIQUE_THREAD_PRIORITY
00049 
00050 /*! Initiate a system reboot.
00051 */
00052 void pal_plat_osReboot(void);
00053 
00054 /*! Initialize all data structures (semaphores, mutexes, memory pools, message queues) at system initialization.
00055 *   In case of a failure in any of the initializations, the function returns with an error and stops the rest of the initializations.
00056 * @param[in] opaqueContext The context passed to the initialization (not required for generic CMSIS, pass NULL in this case).
00057 * \return PAL_SUCCESS(0) in case of success, PAL_ERR_CREATION_FAILED in case of failure.
00058 */
00059 palStatus_t pal_plat_RTOSInitialize(void* opaqueContext);
00060 
00061 /*! De-Initialize thread objects.
00062 */
00063 void pal_plat_RTOSDestroy(void);
00064 
00065 /*! Get the RTOS kernel system timer counter.
00066 *
00067 * \return The RTOS kernel system timer counter.
00068 *
00069 * \note The required tick counter is the OS (platform) kernel system tick counter.
00070 * \note This counter wraps around very often (for example, once every 42 sec for 100Mhz).
00071 */
00072 uint32_t pal_plat_osKernelSysTick();
00073 
00074 /*! Get the RTOS kernel system timer counter.
00075 *
00076 * \return The RTOS kernel system timer counter.
00077 *
00078 * \note The required tick counter is the OS (platform) kernel system tick counter.
00079 */
00080 uint64_t pal_plat_osKernelSysTick64(void); // optional API - not part of original CMSIS API.
00081 
00082 /*! Convert the value from microseconds to kernel sys ticks.
00083 * This is the same as CMSIS macro osKernelSysTickMicroSec.
00084 */
00085 uint64_t pal_plat_osKernelSysTickMicroSec(uint64_t microseconds);
00086 
00087 /*! Convert the value from kernel system ticks to milliseconds.
00088 *
00089 * @param[in] sysTicks The number of kernel system ticks to convert into millieseconds.
00090 *
00091 * \return The converted value in system ticks.
00092 */
00093 uint64_t pal_plat_osKernelSysMilliSecTick(uint64_t sysTicks);
00094 
00095 /*! Get the system tick frequency.
00096 * \return The system tick frequency.
00097 */
00098 uint64_t pal_plat_osKernelSysTickFrequency(void);
00099 
00100 /*! Create and start a thread function.
00101 *
00102 * @param[in] function A function pointer to the thread callback function.
00103 * @param[in] funcArgument An argument for the thread function.
00104 * @param[in] priority The priority of the thread.
00105 * @param[in] stackSize The stack size of the thread.
00106 * @param[in] stackPtr A pointer to the thread's stack.
00107 * @param[in] store A pointer to thread's local store, can be NULL.
00108 * @param[out] threadID The created thread ID handle, zero indicates an error.
00109 *
00110 * \return The ID of the created thread, in case of error return zero.
00111 * \note Each thread MUST have a unique priority.
00112 * \note When the priority of the created thread function is higher than the current running thread, the 
00113 *       created thread function starts instantly and becomes the new running thread. 
00114 * \note the create function MUST not wait for platform resources and it should return "PAL_ERR_RTOS_RESOURCE", unless the platform API is blocking.
00115 */
00116 palStatus_t pal_plat_osThreadCreate(palThreadFuncPtr function, void* funcArgument, palThreadPriority_t priority, uint32_t stackSize, uint32_t* stackPtr, palThreadLocalStore_t* store, palThreadID_t* threadID);
00117 
00118 /*! Terminate and free allocated data for the thread.
00119 *
00120 * @param[in] threadID The ID of the thread to stop and terminate.
00121 *
00122 * \return palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00123 */
00124 palStatus_t pal_plat_osThreadTerminate(palThreadID_t* threadID);
00125 
00126 /*! Get the ID of the current thread.
00127 * \return The ID of the current thread, in case of error return PAL_MAX_UINT32.
00128 * \note For a thread with real time priority, the function always returns PAL_MAX_UINT32.
00129 */
00130 palThreadID_t pal_plat_osThreadGetId();
00131 
00132 /*! Get the storage of the current thread.
00133 * \return The storage of the current thread.
00134 */
00135 void* pal_plat_osThreadGetLocalStore();
00136 
00137 /*! Wait for a specified period of time in milliseconds.
00138 *
00139 * @param[in] milliseconds The number of milliseconds to wait before proceeding.
00140 *
00141 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00142 */
00143 palStatus_t pal_plat_osDelay(uint32_t milliseconds);
00144 
00145 /*! Create a timer.
00146 *
00147 * @param[in] function A function pointer to the timer callback function.
00148 * @param[in] funcArgument An argument for the timer callback function.
00149 * @param[in] timerType The timer type to be created, periodic or oneShot.
00150 * @param[out] timerID The ID of the created timer, zero value indicates an error.
00151 *
00152 * \return PAL_SUCCESS when the timer was created successfully. A specific error in case of failure.
00153 *         PAL_ERR_NO_MEMORY: no memory resource available to create timer object.
00154 *
00155 * \note the timer callback function runs according to the platform resources of stack-size and priority.
00156 * \note the create function MUST not wait for platform resources and it should return "PAL_ERR_RTOS_RESOURCE", unless the platform API is blocking.
00157 */
00158 palStatus_t pal_plat_osTimerCreate(palTimerFuncPtr function, void* funcArgument, palTimerType_t timerType, palTimerID_t* timerID);
00159 
00160 /*! Start or restart a timer.
00161 *
00162 * @param[in] timerID The handle for the timer to start.
00163 * @param[in] millisec The time in milliseconds to set the timer to.
00164 *
00165 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00166 */
00167 palStatus_t pal_plat_osTimerStart(palTimerID_t timerID, uint32_t millisec);
00168 
00169 /*! Stop a timer.
00170 *
00171 * @param[in] timerID The handle for the timer to stop.
00172 *
00173 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00174 */
00175 palStatus_t pal_plat_osTimerStop(palTimerID_t timerID);
00176 
00177 /*! Delete the timer object
00178 *
00179 * @param[inout] timerID The handle for the timer to delete. In success, *timerID = NULL.
00180 *
00181 * \return PAL_SUCCESS when the timer was deleted successfully, PAL_ERR_RTOS_PARAMETER when the timerID is incorrect.
00182 */
00183 palStatus_t pal_plat_osTimerDelete(palTimerID_t* timerID);
00184 
00185 /*! Create and initialize a mutex object.
00186 *
00187 * @param[out] mutexID The created mutex ID handle, zero value indicates an error.
00188 *
00189 * \return PAL_SUCCESS when the mutex was created successfully, a specific error in case of failure.
00190 *         PAL_ERR_NO_MEMORY: no memory resource available to create mutex object.
00191 * \note the create function MUST not wait for platform resources and it should return "PAL_ERR_RTOS_RESOURCE", unless the platform API is blocking.
00192 */
00193 palStatus_t pal_plat_osMutexCreate(palMutexID_t* mutexID);
00194 
00195 /*! Wait until a mutex becomes available.
00196 *
00197 * @param[in] mutexID The handle for the mutex.
00198 * @param[in] millisec The timeout for the waiting operation if the timeout expires before the semaphore is released and an error is returned from the function.
00199 *
00200 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, one of the following error codes in case of failure:
00201 *         PAL_ERR_RTOS_RESOURCE - Mutex not available but no timeout set.
00202 *         PAL_ERR_RTOS_TIMEOUT - Mutex was not available until timeout expired.
00203 *         PAL_ERR_RTOS_PARAMETER - Mutex ID is invalid.
00204 *         PAL_ERR_RTOS_ISR - Cannot be called from interrupt service routines.
00205 */
00206 palStatus_t pal_plat_osMutexWait(palMutexID_t mutexID, uint32_t millisec);
00207 
00208 /*! Release a mutex that was obtained by osMutexWait.
00209 *
00210 * @param[in] mutexID The handle for the mutex.
00211 *
00212 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00213 */
00214 palStatus_t pal_plat_osMutexRelease(palMutexID_t mutexID);
00215 
00216 /*!Delete a mutex object.
00217 *
00218 * @param[inout] mutexID The ID of the mutex to delete. In success, *mutexID = NULL.
00219 *
00220 * \return PAL_SUCCESS when the mutex was deleted successfully, one of the following error codes in case of failure:
00221 *         PAL_ERR_RTOS_RESOURCE - Mutex already released.
00222 *         PAL_ERR_RTOS_PARAMETER - Mutex ID is invalid.
00223 *         PAL_ERR_RTOS_ISR - Cannot be called from interrupt service routines.
00224 * \note After this call, mutex_id is no longer valid and cannot be used.
00225 */
00226 palStatus_t pal_plat_osMutexDelete(palMutexID_t* mutexID);
00227 
00228 /*! Create and initialize a semaphore object.
00229 *
00230 * @param[in] count The number of available resources.
00231 * @param[out] semaphoreID The ID of the created semaphore, zero value indicates an error.
00232 *
00233 * \return PAL_SUCCESS when the semaphore was created successfully, a specific error in case of failure.
00234 *         PAL_ERR_NO_MEMORY: no memory resource available to create semaphore object.
00235 * \note the create function MUST not wait for platform resources and it should return "PAL_ERR_RTOS_RESOURCE", unless the platform API is blocking.
00236 */
00237 palStatus_t pal_plat_osSemaphoreCreate(uint32_t count, palSemaphoreID_t* semaphoreID);
00238 
00239 /*! Wait until a semaphore token becomes available.
00240 *
00241 * @param[in] semaphoreID The handle for the semaphore.
00242 * @param[in] millisec The timeout for the waiting operation if the timeout expires before the semaphore is released and an error is returned from the function.
00243 * @param[out] countersAvailable The number of semaphores available, if semaphores are not available (timeout/error) zero is returned. 
00244 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, one of the following error codes in case of failure:
00245 *       PAL_ERR_RTOS_TIMEOUT - Semaphore was not available until timeout expired.
00246 *       PAL_ERR_RTOS_PARAMETER - Semaphore ID is invalid.
00247 */
00248 palStatus_t pal_plat_osSemaphoreWait(palSemaphoreID_t semaphoreID, uint32_t millisec, int32_t* countersAvailable);
00249 
00250 /*! Release a semaphore token.
00251 *
00252 * @param[in] semaphoreID The handle for the semaphore.
00253 *
00254 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00255 */
00256 palStatus_t pal_plat_osSemaphoreRelease(palSemaphoreID_t semaphoreID);
00257 
00258 /*! Delete a semaphore object.
00259 *
00260 * @param[inout] semaphoreID: The ID of the semaphore to delete. In success, *semaphoreID = NULL.
00261 *
00262 * \return PAL_SUCCESS when the semaphore was deleted successfully, one of the following error codes in case of failure:
00263 *         PAL_ERR_RTOS_RESOURCE - Semaphore already released.
00264 *         PAL_ERR_RTOS_PARAMETER - Semaphore ID is invalid.
00265 * \note After this call, the semaphore_id is no longer valid and cannot be used.
00266 */
00267 palStatus_t pal_plat_osSemaphoreDelete(palSemaphoreID_t* semaphoreID);
00268 
00269 /*! Create and initialize a memory pool.
00270 *
00271 * @param[in] blockSize The size of a single block in bytes.
00272 * @param[in] blockCount The maximum number of blocks in the memory pool.
00273 * @param[out] memoryPoolID The ID of the created memory pool, zero value indicates an error.
00274 *
00275 * \return PAL_SUCCESS when the memory pool was created successfully, a specific error in case of failure.
00276 *         PAL_ERR_NO_MEMORY: no memory resource available to create memory pool object.
00277 * \note the create function MUST not wait for platform resources and it should return "PAL_ERR_RTOS_RESOURCE", unless the platform API is blocking.
00278 */
00279 palStatus_t pal_plat_osPoolCreate(uint32_t blockSize, uint32_t blockCount, palMemoryPoolID_t* memoryPoolID);
00280 
00281 /*! Allocate a single memory block from a memory pool.
00282 *
00283 * @param[in] memoryPoolID The handle for the memory pool.
00284 *
00285 * \return A pointer to a single allocated memory from the pool, NULL in case of failure.
00286 */
00287 void* pal_plat_osPoolAlloc(palMemoryPoolID_t memoryPoolID);
00288 
00289 /*! Allocate a single memory block from a memory pool and set memory block to zero.
00290 *
00291 * @param[in] memoryPoolID The handle for the memory pool.
00292 *
00293 * \return A pointer to a single allocated memory from the pool, NULL in case of failure.
00294 */
00295 void* pal_plat_osPoolCAlloc(palMemoryPoolID_t memoryPoolID);
00296 
00297 /*! Return the memoryPoolID of the memory block back to a specific memory pool.
00298 *
00299 * @param[in] memoryPoolID The handle for the memory pool.
00300 * @param[in] block The block to be freed.
00301 *
00302 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00303 */
00304 palStatus_t pal_plat_osPoolFree(palMemoryPoolID_t memoryPoolID, void* block);
00305 
00306 /*! Delete a memory pool object.
00307 *
00308 * @param[inout] memoryPoolID The handle for the memory pool. In success, *memoryPoolID = NULL.
00309 *
00310 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00311 */
00312 palStatus_t pal_plat_osPoolDestroy(palMemoryPoolID_t* memoryPoolID);
00313 
00314 /*! Create and initialize a message queue.
00315 *
00316 * @param[in] messageQSize The size of the message queue.
00317 * @param[out] messageQID The ID of the created message queue, zero value indicates an error.
00318 *
00319 * \return PAL_SUCCESS when the message queue was created successfully, a specific error in case of failure.
00320 *         PAL_ERR_NO_MEMORY: no memory resource available to create message queue object.
00321 * \note the create function MUST not wait for platform resources and it should return "PAL_ERR_RTOS_RESOURCE", unless the platform API is blocking.
00322 */
00323 palStatus_t pal_plat_osMessageQueueCreate(uint32_t messageQSize, palMessageQID_t* messageQID);
00324 
00325 /*! Put a message to a queue.
00326 *
00327 * @param[in] messageQID The handle for the message queue.
00328 * @param[in] info The data to send.
00329 * @param[in] timeout The timeout in milliseconds.
00330 *
00331 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00332 */
00333 palStatus_t pal_plat_osMessagePut(palMessageQID_t messageQID, uint32_t info, uint32_t timeout);
00334 
00335 /*! Get a message or wait for a message from a queue.
00336 *
00337 * @param[in] messageQID The handle for the message queue.
00338 * @param[in] timeout The timeout in milliseconds.
00339 * @param[out] messageValue The data to send.
00340 *
00341 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, one of the following error codes in case of failure:
00342 * PAL_ERR_RTOS_RESOURCE - Semaphore was not available but not due to timeout.
00343 * PAL_ERR_RTOS_TIMEOUT -  No message arrived during the timeout period.
00344 * PAL_ERR_RTOS_RESOURCE -  No message received and there was no timeout.
00345 */
00346 palStatus_t pal_plat_osMessageGet(palMessageQID_t messageQID, uint32_t timeout, uint32_t* messageValue);
00347 
00348 /*! Delete a message queue object.
00349 *
00350 * @param[inout] messageQID The handle for the message queue. In success, *messageQID = NULL.
00351 *
00352 * \return The status in the form of palStatus_t; PAL_SUCCESS(0) in case of success, a negative value indicating a specific error code in case of failure.
00353 */
00354 palStatus_t pal_plat_osMessageQueueDestroy(palMessageQID_t* messageQID);
00355 
00356 /*! Perform an atomic increment for a signed32 bit value.
00357 *
00358 * @param[in,out] valuePtr The address of the value to increment.
00359 * @param[in] increment The number by which to increment.
00360 *
00361 * \returns The value of the valuePtr after the increment operation.
00362 */
00363 int32_t pal_plat_osAtomicIncrement(int32_t* valuePtr, int32_t increment);
00364 
00365 #ifdef DEBUG
00366 #include "stdio.h"
00367 #define pal_plat_printf(ARGS...) printf(ARGS)
00368 #define pal_plat_vprintf(FORMAT,LIST) vprintf(FORMAT,LIST)  
00369 
00370 #endif
00371 #ifdef __cplusplus
00372 }
00373 #endif
00374 #endif //_PAL_COMMON_H