Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
pal/Source/PAL-Impl/Services-API/pal_rtos.h@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a7a43371b306 | 1 | /* |
ram54288 | 0:a7a43371b306 | 2 | * Copyright (c) 2016 ARM Limited. All rights reserved. |
ram54288 | 0:a7a43371b306 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a7a43371b306 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a7a43371b306 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a7a43371b306 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a7a43371b306 | 7 | * |
ram54288 | 0:a7a43371b306 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a7a43371b306 | 9 | * |
ram54288 | 0:a7a43371b306 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a7a43371b306 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a7a43371b306 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a7a43371b306 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a7a43371b306 | 14 | * limitations under the License. |
ram54288 | 0:a7a43371b306 | 15 | */ |
ram54288 | 0:a7a43371b306 | 16 | |
ram54288 | 0:a7a43371b306 | 17 | |
ram54288 | 0:a7a43371b306 | 18 | #ifndef _PAL_RTOS_H |
ram54288 | 0:a7a43371b306 | 19 | #define _PAL_RTOS_H |
ram54288 | 0:a7a43371b306 | 20 | |
ram54288 | 0:a7a43371b306 | 21 | #include <stdint.h> |
ram54288 | 0:a7a43371b306 | 22 | |
ram54288 | 0:a7a43371b306 | 23 | #ifdef __cplusplus |
ram54288 | 0:a7a43371b306 | 24 | extern "C" { |
ram54288 | 0:a7a43371b306 | 25 | #endif |
ram54288 | 0:a7a43371b306 | 26 | |
ram54288 | 0:a7a43371b306 | 27 | #include "pal_macros.h" |
ram54288 | 0:a7a43371b306 | 28 | #include "pal_types.h" |
ram54288 | 0:a7a43371b306 | 29 | |
ram54288 | 0:a7a43371b306 | 30 | //! Wait forever define. used for Semaphores and Mutexes |
ram54288 | 0:a7a43371b306 | 31 | #define PAL_RTOS_WAIT_FOREVER PAL_MAX_UINT32 |
ram54288 | 0:a7a43371b306 | 32 | |
ram54288 | 0:a7a43371b306 | 33 | //! Primitives IDs types declarations |
ram54288 | 0:a7a43371b306 | 34 | typedef uintptr_t palThreadID_t; |
ram54288 | 0:a7a43371b306 | 35 | typedef uintptr_t palTimerID_t; |
ram54288 | 0:a7a43371b306 | 36 | typedef uintptr_t palMutexID_t; |
ram54288 | 0:a7a43371b306 | 37 | typedef uintptr_t palSemaphoreID_t; |
ram54288 | 0:a7a43371b306 | 38 | typedef uintptr_t palMemoryPoolID_t; |
ram54288 | 0:a7a43371b306 | 39 | typedef uintptr_t palMessageQID_t; |
ram54288 | 0:a7a43371b306 | 40 | |
ram54288 | 0:a7a43371b306 | 41 | //! Timers types supported in PAL |
ram54288 | 0:a7a43371b306 | 42 | typedef enum palTimerType { |
ram54288 | 0:a7a43371b306 | 43 | palOsTimerOnce = 0, /*! One shot timer*/ |
ram54288 | 0:a7a43371b306 | 44 | palOsTimerPeriodic = 1 /*! Periodic (repeating) timer*/ |
ram54288 | 0:a7a43371b306 | 45 | } palTimerType_t; |
ram54288 | 0:a7a43371b306 | 46 | |
ram54288 | 0:a7a43371b306 | 47 | //! PAL timer function prototype |
ram54288 | 0:a7a43371b306 | 48 | typedef void(*palTimerFuncPtr)(void const *funcArgument); |
ram54288 | 0:a7a43371b306 | 49 | |
ram54288 | 0:a7a43371b306 | 50 | //! PAL thread function prototype |
ram54288 | 0:a7a43371b306 | 51 | typedef void(*palThreadFuncPtr)(void const *funcArgument); |
ram54288 | 0:a7a43371b306 | 52 | |
ram54288 | 0:a7a43371b306 | 53 | //! Available priorities in PAL implementation, each priority can appear only once. |
ram54288 | 0:a7a43371b306 | 54 | typedef enum pal_osPriority { |
ram54288 | 0:a7a43371b306 | 55 | PAL_osPriorityIdle = -3, |
ram54288 | 0:a7a43371b306 | 56 | PAL_osPriorityLow = -2, |
ram54288 | 0:a7a43371b306 | 57 | PAL_osPriorityBelowNormal = -1, |
ram54288 | 0:a7a43371b306 | 58 | PAL_osPriorityNormal = 0, |
ram54288 | 0:a7a43371b306 | 59 | PAL_osPriorityAboveNormal = +1, |
ram54288 | 0:a7a43371b306 | 60 | PAL_osPriorityHigh = +2, |
ram54288 | 0:a7a43371b306 | 61 | PAL_osPriorityRealtime = +3, |
ram54288 | 0:a7a43371b306 | 62 | PAL_osPriorityError = 0x84 |
ram54288 | 0:a7a43371b306 | 63 | } palThreadPriority_t; /*! Thread priority levels for PAL threads - each thread must have a different priority*/ |
ram54288 | 0:a7a43371b306 | 64 | |
ram54288 | 0:a7a43371b306 | 65 | //! Thread Local Store struct. |
ram54288 | 0:a7a43371b306 | 66 | //! Can be used to hold: State, configurations and etc inside the thread. |
ram54288 | 0:a7a43371b306 | 67 | typedef struct pal_threadLocalStore{ |
ram54288 | 0:a7a43371b306 | 68 | void* storeData; |
ram54288 | 0:a7a43371b306 | 69 | } palThreadLocalStore_t; |
ram54288 | 0:a7a43371b306 | 70 | |
ram54288 | 0:a7a43371b306 | 71 | //------- system general functions |
ram54288 | 0:a7a43371b306 | 72 | /*! Initiates a system reboot |
ram54288 | 0:a7a43371b306 | 73 | */ |
ram54288 | 0:a7a43371b306 | 74 | void pal_osReboot(void); |
ram54288 | 0:a7a43371b306 | 75 | |
ram54288 | 0:a7a43371b306 | 76 | //------- system tick functions |
ram54288 | 0:a7a43371b306 | 77 | /*! Get the RTOS kernel system timer counter. |
ram54288 | 0:a7a43371b306 | 78 | * \note this counter will wrap around very often (e.g. once every 42 sec for 100Mhz) |
ram54288 | 0:a7a43371b306 | 79 | * \return the RTOS kernel system timer counter |
ram54288 | 0:a7a43371b306 | 80 | */ |
ram54288 | 0:a7a43371b306 | 81 | uint32_t pal_osKernelSysTick(void); |
ram54288 | 0:a7a43371b306 | 82 | |
ram54288 | 0:a7a43371b306 | 83 | /*! Get the RTOS kernel system timer counter. |
ram54288 | 0:a7a43371b306 | 84 | * \return the RTOS kernel system timer counter |
ram54288 | 0:a7a43371b306 | 85 | */ |
ram54288 | 0:a7a43371b306 | 86 | uint64_t pal_osKernelSysTick64(void); |
ram54288 | 0:a7a43371b306 | 87 | |
ram54288 | 0:a7a43371b306 | 88 | /*! Converts value from microseconds to kernel sys tick |
ram54288 | 0:a7a43371b306 | 89 | * |
ram54288 | 0:a7a43371b306 | 90 | * @param[in] microseconds the amount of microseconds to convert into system ticks |
ram54288 | 0:a7a43371b306 | 91 | * |
ram54288 | 0:a7a43371b306 | 92 | * \return converted value in system ticks |
ram54288 | 0:a7a43371b306 | 93 | */ |
ram54288 | 0:a7a43371b306 | 94 | uint64_t pal_osKernelSysTickMicroSec(uint64_t microseconds); |
ram54288 | 0:a7a43371b306 | 95 | |
ram54288 | 0:a7a43371b306 | 96 | /*! Converts value from kernel system ticks to milliseconds. |
ram54288 | 0:a7a43371b306 | 97 | * |
ram54288 | 0:a7a43371b306 | 98 | * @param[in] sysTicks the amount of kernel system ticks to convert into millieseconds |
ram54288 | 0:a7a43371b306 | 99 | * |
ram54288 | 0:a7a43371b306 | 100 | * \return converted value in system ticks |
ram54288 | 0:a7a43371b306 | 101 | */ |
ram54288 | 0:a7a43371b306 | 102 | uint64_t pal_osKernelSysMilliSecTick(uint64_t sysTicks); |
ram54288 | 0:a7a43371b306 | 103 | |
ram54288 | 0:a7a43371b306 | 104 | /*! Get the system tick frequency |
ram54288 | 0:a7a43371b306 | 105 | * \return the system tick frequency |
ram54288 | 0:a7a43371b306 | 106 | */ |
ram54288 | 0:a7a43371b306 | 107 | uint64_t pal_osKernelSysTickFrequency(void); |
ram54288 | 0:a7a43371b306 | 108 | |
ram54288 | 0:a7a43371b306 | 109 | /*! Creates and starts thread function. |
ram54288 | 0:a7a43371b306 | 110 | * |
ram54288 | 0:a7a43371b306 | 111 | * @param[in] function: function pointer to the thread callback function. |
ram54288 | 0:a7a43371b306 | 112 | * @param[in] funcArgument: argument for the thread function. |
ram54288 | 0:a7a43371b306 | 113 | * @param[in] priority: priotity of the thread. |
ram54288 | 0:a7a43371b306 | 114 | * @param[in] stackSize: the stack size of the thread can NOT be 0. |
ram54288 | 0:a7a43371b306 | 115 | * @param[in] stackPtr: pointer to the thread's stack can NOT be NULL. |
ram54288 | 0:a7a43371b306 | 116 | * @param[in] store: pointer to thread's local sotre, can be NULL. |
ram54288 | 0:a7a43371b306 | 117 | * @param[out] threadID: holds the created thread ID handle - zero value indecates an error. |
ram54288 | 0:a7a43371b306 | 118 | * |
ram54288 | 0:a7a43371b306 | 119 | * \return PAL_SUCCESS when thread created successfully. |
ram54288 | 0:a7a43371b306 | 120 | * PAL_ERR_RTOS_PRIORITY : the given priority already used before in the system. |
ram54288 | 0:a7a43371b306 | 121 | * |
ram54288 | 0:a7a43371b306 | 122 | * \note Each thread MUST be with unique priority. |
ram54288 | 0:a7a43371b306 | 123 | * \note When the priority of the created thread function is higher than the current running thread, the |
ram54288 | 0:a7a43371b306 | 124 | * created thread function starts instantly and becomes the new running thread. |
ram54288 | 0:a7a43371b306 | 125 | */ |
ram54288 | 0:a7a43371b306 | 126 | palStatus_t pal_osThreadCreate(palThreadFuncPtr function, void* funcArgument, palThreadPriority_t priority, uint32_t stackSize, uint32_t* stackPtr, palThreadLocalStore_t* store, palThreadID_t* threadID); |
ram54288 | 0:a7a43371b306 | 127 | |
ram54288 | 0:a7a43371b306 | 128 | |
ram54288 | 0:a7a43371b306 | 129 | /*! Terminates and free allocated data for the thread. |
ram54288 | 0:a7a43371b306 | 130 | * |
ram54288 | 0:a7a43371b306 | 131 | * @param[in] threadID: thread ID to stop and terminate. |
ram54288 | 0:a7a43371b306 | 132 | * |
ram54288 | 0:a7a43371b306 | 133 | * \return palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 134 | * PAL_ERR_RTOS_RESOURCE: if the thread ID is not correct. |
ram54288 | 0:a7a43371b306 | 135 | */ |
ram54288 | 0:a7a43371b306 | 136 | palStatus_t pal_osThreadTerminate(palThreadID_t* threadID); |
ram54288 | 0:a7a43371b306 | 137 | |
ram54288 | 0:a7a43371b306 | 138 | /*! Get ID of the current thread |
ram54288 | 0:a7a43371b306 | 139 | * \return the ID of the current thread - in case of error return PAL_MAX_UINT32 |
ram54288 | 0:a7a43371b306 | 140 | * \note for thread with Real Time priority the function will always return PAL_MAX_UINT32 |
ram54288 | 0:a7a43371b306 | 141 | */ |
ram54288 | 0:a7a43371b306 | 142 | palThreadID_t pal_osThreadGetId(void); |
ram54288 | 0:a7a43371b306 | 143 | |
ram54288 | 0:a7a43371b306 | 144 | /*! Get the storage of current thread |
ram54288 | 0:a7a43371b306 | 145 | * \return the storage of the current thread */ |
ram54288 | 0:a7a43371b306 | 146 | void* pal_osThreadGetLocalStore(void); |
ram54288 | 0:a7a43371b306 | 147 | |
ram54288 | 0:a7a43371b306 | 148 | /*! Wait for a specified time period in milliseconds. |
ram54288 | 0:a7a43371b306 | 149 | * |
ram54288 | 0:a7a43371b306 | 150 | * @param[in] milliseconds the amount of milliseconds to wait before proceeding. |
ram54288 | 0:a7a43371b306 | 151 | * |
ram54288 | 0:a7a43371b306 | 152 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 153 | */ |
ram54288 | 0:a7a43371b306 | 154 | palStatus_t pal_osDelay(uint32_t milliseconds); |
ram54288 | 0:a7a43371b306 | 155 | |
ram54288 | 0:a7a43371b306 | 156 | /*! Creates a Timer. |
ram54288 | 0:a7a43371b306 | 157 | * |
ram54288 | 0:a7a43371b306 | 158 | * @param[in] function: function pointer to the timer callback function. |
ram54288 | 0:a7a43371b306 | 159 | * @param[in] funcArgument: funcArgument for the timer callback function. |
ram54288 | 0:a7a43371b306 | 160 | * @param[in] timerType: timer type to be created - (periodic or oneShot). |
ram54288 | 0:a7a43371b306 | 161 | * @param[out] timerID: holds the created timer ID handle - zero value indecates an error. |
ram54288 | 0:a7a43371b306 | 162 | * |
ram54288 | 0:a7a43371b306 | 163 | * \return PAL_SUCCESS when timer created successfully. |
ram54288 | 0:a7a43371b306 | 164 | * PAL_ERR_NO_MEMORY: no memory resource available to create timer object. |
ram54288 | 0:a7a43371b306 | 165 | * |
ram54288 | 0:a7a43371b306 | 166 | * \note the timer function runs according to the platform resources of stack-size and priority. |
ram54288 | 0:a7a43371b306 | 167 | */ |
ram54288 | 0:a7a43371b306 | 168 | palStatus_t pal_osTimerCreate(palTimerFuncPtr function, void* funcArgument, palTimerType_t timerType, palTimerID_t* timerID); |
ram54288 | 0:a7a43371b306 | 169 | |
ram54288 | 0:a7a43371b306 | 170 | /*! Start or restart a timer. |
ram54288 | 0:a7a43371b306 | 171 | * |
ram54288 | 0:a7a43371b306 | 172 | * @param[in] timerID the handle for the timer to start |
ram54288 | 0:a7a43371b306 | 173 | * @param[in] millisec the amount of time in milliseconds to set the timer to. |
ram54288 | 0:a7a43371b306 | 174 | * |
ram54288 | 0:a7a43371b306 | 175 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 176 | */ |
ram54288 | 0:a7a43371b306 | 177 | palStatus_t pal_osTimerStart(palTimerID_t timerID, uint32_t millisec); |
ram54288 | 0:a7a43371b306 | 178 | |
ram54288 | 0:a7a43371b306 | 179 | /*! Stop a timer. |
ram54288 | 0:a7a43371b306 | 180 | * @param[in] timerID the handle for the timer to stop |
ram54288 | 0:a7a43371b306 | 181 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 182 | */ |
ram54288 | 0:a7a43371b306 | 183 | palStatus_t pal_osTimerStop(palTimerID_t timerID); |
ram54288 | 0:a7a43371b306 | 184 | |
ram54288 | 0:a7a43371b306 | 185 | /*! Delete the timer object |
ram54288 | 0:a7a43371b306 | 186 | * |
ram54288 | 0:a7a43371b306 | 187 | * @param[inout] timerID: the handle for the timer to delete, in success:(*timerID = NULL). |
ram54288 | 0:a7a43371b306 | 188 | * |
ram54288 | 0:a7a43371b306 | 189 | * \return PAL_SUCCESS when timer deleted successfully. |
ram54288 | 0:a7a43371b306 | 190 | * PAL_ERR_RTOS_PARAMETER when timerID is incorrect. |
ram54288 | 0:a7a43371b306 | 191 | */ |
ram54288 | 0:a7a43371b306 | 192 | palStatus_t pal_osTimerDelete(palTimerID_t* timerID); |
ram54288 | 0:a7a43371b306 | 193 | |
ram54288 | 0:a7a43371b306 | 194 | /*! Create and initialize Mutex object |
ram54288 | 0:a7a43371b306 | 195 | * |
ram54288 | 0:a7a43371b306 | 196 | * @param[out] mutexID: holds the created mutex ID handle - zero value indecates an error. |
ram54288 | 0:a7a43371b306 | 197 | * |
ram54288 | 0:a7a43371b306 | 198 | * \return PAL_SUCCESS when mutex created successfully. |
ram54288 | 0:a7a43371b306 | 199 | * PAL_ERR_NO_MEMORY: no memory resource available to create mutex object. |
ram54288 | 0:a7a43371b306 | 200 | */ |
ram54288 | 0:a7a43371b306 | 201 | palStatus_t pal_osMutexCreate(palMutexID_t* mutexID); |
ram54288 | 0:a7a43371b306 | 202 | |
ram54288 | 0:a7a43371b306 | 203 | /*! Wait until a Mutex becomes available. |
ram54288 | 0:a7a43371b306 | 204 | * |
ram54288 | 0:a7a43371b306 | 205 | * @param[in] mutexID the handle for the mutex |
ram54288 | 0:a7a43371b306 | 206 | * @param[in] millisec the timeout for the waiting operation if the |
ram54288 | 0:a7a43371b306 | 207 | timeout expires before the semaphore is released and |
ram54288 | 0:a7a43371b306 | 208 | error will be returned from the function, PAL_RTOS_WAIT_FOREVER can be used. |
ram54288 | 0:a7a43371b306 | 209 | * |
ram54288 | 0:a7a43371b306 | 210 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and one of the following error codes in case of failure: |
ram54288 | 0:a7a43371b306 | 211 | * PAL_ERR_RTOS_RESOURCE - mutex not avaialbe but no time out set. |
ram54288 | 0:a7a43371b306 | 212 | * PAL_ERR_RTOS_TIMEOUT - mutex was not available until timeout expired. |
ram54288 | 0:a7a43371b306 | 213 | * PAL_ERR_RTOS_PARAMETER - mutex id is invalid |
ram54288 | 0:a7a43371b306 | 214 | * PAL_ERR_RTOS_ISR - cannot be called from interrupt service routines |
ram54288 | 0:a7a43371b306 | 215 | */ |
ram54288 | 0:a7a43371b306 | 216 | palStatus_t pal_osMutexWait(palMutexID_t mutexID, uint32_t millisec); |
ram54288 | 0:a7a43371b306 | 217 | |
ram54288 | 0:a7a43371b306 | 218 | /*! Release a Mutex that was obtained by osMutexWait. |
ram54288 | 0:a7a43371b306 | 219 | * |
ram54288 | 0:a7a43371b306 | 220 | * @param[in] mutexID the handle for the mutex |
ram54288 | 0:a7a43371b306 | 221 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 222 | */ |
ram54288 | 0:a7a43371b306 | 223 | palStatus_t pal_osMutexRelease(palMutexID_t mutexID); |
ram54288 | 0:a7a43371b306 | 224 | |
ram54288 | 0:a7a43371b306 | 225 | /*!Delete a Mutex object. |
ram54288 | 0:a7a43371b306 | 226 | * |
ram54288 | 0:a7a43371b306 | 227 | * @param[inout] mutexID: Mutex handle to delete, in success:(*mutexID = NULL). |
ram54288 | 0:a7a43371b306 | 228 | * |
ram54288 | 0:a7a43371b306 | 229 | * \return PAL_SUCCESS when mutex deleted successfully. |
ram54288 | 0:a7a43371b306 | 230 | * PAL_ERR_RTOS_RESOURCE - mutex already released. |
ram54288 | 0:a7a43371b306 | 231 | * PAL_ERR_RTOS_PARAMETER - mutex id is invalid. |
ram54288 | 0:a7a43371b306 | 232 | * PAL_ERR_RTOS_ISR - cannot be called from interrupt service routines. |
ram54288 | 0:a7a43371b306 | 233 | * \note After this call the mutex_id is no longer valid and cannot be used. |
ram54288 | 0:a7a43371b306 | 234 | */ |
ram54288 | 0:a7a43371b306 | 235 | palStatus_t pal_osMutexDelete(palMutexID_t* mutexID); |
ram54288 | 0:a7a43371b306 | 236 | |
ram54288 | 0:a7a43371b306 | 237 | /*! Create and initialize a Semaphore object |
ram54288 | 0:a7a43371b306 | 238 | * |
ram54288 | 0:a7a43371b306 | 239 | * @param[in] count: number of available resources |
ram54288 | 0:a7a43371b306 | 240 | * @param[out] semaphoreID: holds the created semaphore ID handle - zero value indecates an error. |
ram54288 | 0:a7a43371b306 | 241 | * |
ram54288 | 0:a7a43371b306 | 242 | * \return PAL_SUCCESS when semaphore created successfully. |
ram54288 | 0:a7a43371b306 | 243 | * PAL_ERR_NO_MEMORY: no memory resource available to create semaphore object. |
ram54288 | 0:a7a43371b306 | 244 | */ |
ram54288 | 0:a7a43371b306 | 245 | palStatus_t pal_osSemaphoreCreate(uint32_t count, palSemaphoreID_t* semaphoreID); |
ram54288 | 0:a7a43371b306 | 246 | |
ram54288 | 0:a7a43371b306 | 247 | /*! Wait until a Semaphore token becomes available. |
ram54288 | 0:a7a43371b306 | 248 | * |
ram54288 | 0:a7a43371b306 | 249 | * @param[in] semaphoreID the handle for the semaphore |
ram54288 | 0:a7a43371b306 | 250 | * @param[in] millisec the timeout for the waiting operation if the timeout |
ram54288 | 0:a7a43371b306 | 251 | expires before the semaphore is released and error will be |
ram54288 | 0:a7a43371b306 | 252 | returned from the function, PAL_RTOS_WAIT_FOREVER can be used. |
ram54288 | 0:a7a43371b306 | 253 | * @param[out] counteresAvailable the number of semaphore available at the call if semaphore is available, if semaphore was not available (timeout/error) zero is returned. |
ram54288 | 0:a7a43371b306 | 254 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and one of the following error codes in case of failure: |
ram54288 | 0:a7a43371b306 | 255 | * PAL_ERR_RTOS_TIMEOUT - semaphore was not available until timeout expired. |
ram54288 | 0:a7a43371b306 | 256 | * PAL_ERR_RTOS_PARAMETER - semaphore id is invalid. |
ram54288 | 0:a7a43371b306 | 257 | */ |
ram54288 | 0:a7a43371b306 | 258 | palStatus_t pal_osSemaphoreWait(palSemaphoreID_t semaphoreID, uint32_t millisec, int32_t* countersAvailable); |
ram54288 | 0:a7a43371b306 | 259 | |
ram54288 | 0:a7a43371b306 | 260 | /*! Release a Semaphore token. |
ram54288 | 0:a7a43371b306 | 261 | * |
ram54288 | 0:a7a43371b306 | 262 | * @param[in] semaphoreID the handle for the semaphore |
ram54288 | 0:a7a43371b306 | 263 | * |
ram54288 | 0:a7a43371b306 | 264 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 265 | */ |
ram54288 | 0:a7a43371b306 | 266 | palStatus_t pal_osSemaphoreRelease(palSemaphoreID_t semaphoreID); |
ram54288 | 0:a7a43371b306 | 267 | |
ram54288 | 0:a7a43371b306 | 268 | /*! Delete a Semaphore object |
ram54288 | 0:a7a43371b306 | 269 | * |
ram54288 | 0:a7a43371b306 | 270 | * @param[inout] semaphoreID: Semaphore handle to delete, in success:(*semaphoreID = NULL). |
ram54288 | 0:a7a43371b306 | 271 | * |
ram54288 | 0:a7a43371b306 | 272 | * \return PAL_SUCCESS when semaphore deleted successfully. |
ram54288 | 0:a7a43371b306 | 273 | * PAL_ERR_RTOS_RESOURCE - semaphore already released. |
ram54288 | 0:a7a43371b306 | 274 | * PAL_ERR_RTOS_PARAMETER - semaphore id is invalid. |
ram54288 | 0:a7a43371b306 | 275 | * \note After this call the semaphore_id is no longer valid and cannot be used. |
ram54288 | 0:a7a43371b306 | 276 | */ |
ram54288 | 0:a7a43371b306 | 277 | palStatus_t pal_osSemaphoreDelete(palSemaphoreID_t* semaphoreID); |
ram54288 | 0:a7a43371b306 | 278 | |
ram54288 | 0:a7a43371b306 | 279 | /*! Create and initialize a memory pool. |
ram54288 | 0:a7a43371b306 | 280 | * |
ram54288 | 0:a7a43371b306 | 281 | * @param[in] blockSize: size of single block in bytes. |
ram54288 | 0:a7a43371b306 | 282 | * @param[in] blockCount: maximum number of blocks in memory pool. |
ram54288 | 0:a7a43371b306 | 283 | * @param[out] memoryPoolID: holds the created memory pool ID handle - zero value indecates an error. |
ram54288 | 0:a7a43371b306 | 284 | * |
ram54288 | 0:a7a43371b306 | 285 | * \return PAL_SUCCESS when memory pool created successfully. |
ram54288 | 0:a7a43371b306 | 286 | * PAL_ERR_NO_MEMORY: no memory resource available to create memory pool object. |
ram54288 | 0:a7a43371b306 | 287 | */ |
ram54288 | 0:a7a43371b306 | 288 | palStatus_t pal_osPoolCreate(uint32_t blockSize, uint32_t blockCount, palMemoryPoolID_t* memoryPoolID); |
ram54288 | 0:a7a43371b306 | 289 | |
ram54288 | 0:a7a43371b306 | 290 | /*! Allocate a single memory block from a memory pool. |
ram54288 | 0:a7a43371b306 | 291 | * |
ram54288 | 0:a7a43371b306 | 292 | * @param[in] memoryPoolID the handle for the memory pool |
ram54288 | 0:a7a43371b306 | 293 | * |
ram54288 | 0:a7a43371b306 | 294 | * \return the function returns a pointer to a single allocated memory from the pool or NULL in case of failure. |
ram54288 | 0:a7a43371b306 | 295 | */ |
ram54288 | 0:a7a43371b306 | 296 | void* pal_osPoolAlloc(palMemoryPoolID_t memoryPoolID); |
ram54288 | 0:a7a43371b306 | 297 | |
ram54288 | 0:a7a43371b306 | 298 | /*! Allocate a single memory block from a memory pool and set memory block to zero. |
ram54288 | 0:a7a43371b306 | 299 | * |
ram54288 | 0:a7a43371b306 | 300 | * @param[in] memoryPoolID the handle for the memory pool |
ram54288 | 0:a7a43371b306 | 301 | * |
ram54288 | 0:a7a43371b306 | 302 | * \return the function returns a pointer to a single allocated memory from the pool or NULL in case of failure. |
ram54288 | 0:a7a43371b306 | 303 | */ |
ram54288 | 0:a7a43371b306 | 304 | void* pal_osPoolCAlloc(palMemoryPoolID_t memoryPoolID); |
ram54288 | 0:a7a43371b306 | 305 | |
ram54288 | 0:a7a43371b306 | 306 | /*! Return an memoryPoolID memory block back to a specific memory pool. |
ram54288 | 0:a7a43371b306 | 307 | * |
ram54288 | 0:a7a43371b306 | 308 | * @param[in] memoryPoolHandle the handle for the memory pool |
ram54288 | 0:a7a43371b306 | 309 | * @param[in] block the block to free |
ram54288 | 0:a7a43371b306 | 310 | * |
ram54288 | 0:a7a43371b306 | 311 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 312 | */ |
ram54288 | 0:a7a43371b306 | 313 | palStatus_t pal_osPoolFree(palMemoryPoolID_t memoryPoolID, void* block); |
ram54288 | 0:a7a43371b306 | 314 | |
ram54288 | 0:a7a43371b306 | 315 | /*! Delete a memory pool object. |
ram54288 | 0:a7a43371b306 | 316 | * |
ram54288 | 0:a7a43371b306 | 317 | * @param[inout] memoryPoolID the handle for the memory pool, in success:(*memoryPoolID = NULL). |
ram54288 | 0:a7a43371b306 | 318 | * |
ram54288 | 0:a7a43371b306 | 319 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 320 | */ |
ram54288 | 0:a7a43371b306 | 321 | palStatus_t pal_osPoolDestroy(palMemoryPoolID_t* memoryPoolID); |
ram54288 | 0:a7a43371b306 | 322 | |
ram54288 | 0:a7a43371b306 | 323 | |
ram54288 | 0:a7a43371b306 | 324 | /*! Create and initialize a message queue. |
ram54288 | 0:a7a43371b306 | 325 | * |
ram54288 | 0:a7a43371b306 | 326 | * @param[in] messageQSize: size of the message queue. |
ram54288 | 0:a7a43371b306 | 327 | * @param[out] memoryPoolID: holds the created memory pool ID handle - zero value indecates an error. |
ram54288 | 0:a7a43371b306 | 328 | * |
ram54288 | 0:a7a43371b306 | 329 | * \return PAL_SUCCESS when message queue created successfully. |
ram54288 | 0:a7a43371b306 | 330 | * PAL_ERR_NO_MEMORY: no memory resource available to create message queue object. |
ram54288 | 0:a7a43371b306 | 331 | */ |
ram54288 | 0:a7a43371b306 | 332 | palStatus_t pal_osMessageQueueCreate(uint32_t messageQSize, palMessageQID_t* messageQID); |
ram54288 | 0:a7a43371b306 | 333 | |
ram54288 | 0:a7a43371b306 | 334 | /*! Put a Message to a Queue. |
ram54288 | 0:a7a43371b306 | 335 | * |
ram54288 | 0:a7a43371b306 | 336 | * @param[in] messageQID the handle for the memory pool |
ram54288 | 0:a7a43371b306 | 337 | * @param[in] info the data to send |
ram54288 | 0:a7a43371b306 | 338 | * @param[in] timeout timeout in milliseconds |
ram54288 | 0:a7a43371b306 | 339 | * |
ram54288 | 0:a7a43371b306 | 340 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 341 | */ |
ram54288 | 0:a7a43371b306 | 342 | palStatus_t pal_osMessagePut(palMessageQID_t messageQID, uint32_t info, uint32_t timeout); |
ram54288 | 0:a7a43371b306 | 343 | |
ram54288 | 0:a7a43371b306 | 344 | /*! Get a Message or Wait for a Message from a Queue. |
ram54288 | 0:a7a43371b306 | 345 | * |
ram54288 | 0:a7a43371b306 | 346 | * @param[in] messageQID the handle for the memory pool |
ram54288 | 0:a7a43371b306 | 347 | * @param[in] timeout timeout in milliseconds |
ram54288 | 0:a7a43371b306 | 348 | * @param[out] event the data to send |
ram54288 | 0:a7a43371b306 | 349 | * |
ram54288 | 0:a7a43371b306 | 350 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and one of the following error codes in case of failure: |
ram54288 | 0:a7a43371b306 | 351 | * PAL_ERR_RTOS_RESOURCE - in case semaphore was not available but not due to time out. |
ram54288 | 0:a7a43371b306 | 352 | * PAL_ERR_RTOS_TIMEOUT - no message arrived during the timeout period. |
ram54288 | 0:a7a43371b306 | 353 | * PAL_ERR_RTOS_RESOURCE - no message received and there was no timeout |
ram54288 | 0:a7a43371b306 | 354 | */ |
ram54288 | 0:a7a43371b306 | 355 | palStatus_t pal_osMessageGet(palMessageQID_t messageQID, uint32_t timeout, uint32_t* messageValue); |
ram54288 | 0:a7a43371b306 | 356 | |
ram54288 | 0:a7a43371b306 | 357 | /*! Delete a message queue object. |
ram54288 | 0:a7a43371b306 | 358 | * |
ram54288 | 0:a7a43371b306 | 359 | * @param[inout] messageQID the handle for the message queue, in success:(*messageQID = NULL). |
ram54288 | 0:a7a43371b306 | 360 | * |
ram54288 | 0:a7a43371b306 | 361 | * \return the function returns the status in the form of palStatus_t which will be PAL_SUCCESS(0) in case of success and another negative value indicating a specific error code in case of failure |
ram54288 | 0:a7a43371b306 | 362 | */ |
ram54288 | 0:a7a43371b306 | 363 | palStatus_t pal_osMessageQueueDestroy(palMessageQID_t* messageQID); |
ram54288 | 0:a7a43371b306 | 364 | |
ram54288 | 0:a7a43371b306 | 365 | /*! Perform an atomic increment for a signed32 bit value |
ram54288 | 0:a7a43371b306 | 366 | * |
ram54288 | 0:a7a43371b306 | 367 | * @param[in,out] valuePtr the address of the value to increment |
ram54288 | 0:a7a43371b306 | 368 | * @param[int] increment the amount by which to increment |
ram54288 | 0:a7a43371b306 | 369 | * |
ram54288 | 0:a7a43371b306 | 370 | * \returns the function returns the value of the valuePtr after the increment operation. |
ram54288 | 0:a7a43371b306 | 371 | */ |
ram54288 | 0:a7a43371b306 | 372 | int32_t pal_osAtomicIncrement(int32_t* valuePtr, int32_t increment); |
ram54288 | 0:a7a43371b306 | 373 | |
ram54288 | 0:a7a43371b306 | 374 | |
ram54288 | 0:a7a43371b306 | 375 | |
ram54288 | 0:a7a43371b306 | 376 | |
ram54288 | 0:a7a43371b306 | 377 | /*! Printf like function with prefix of function and line. |
ram54288 | 0:a7a43371b306 | 378 | * |
ram54288 | 0:a7a43371b306 | 379 | * @param[in] function name of the current function |
ram54288 | 0:a7a43371b306 | 380 | * @param[in] line line number to be printed |
ram54288 | 0:a7a43371b306 | 381 | * @param[in] format print format (just like printf) |
ram54288 | 0:a7a43371b306 | 382 | * |
ram54288 | 0:a7a43371b306 | 383 | * \returns the function returns the value of the valuePtr after the increment operation. |
ram54288 | 0:a7a43371b306 | 384 | */ |
ram54288 | 0:a7a43371b306 | 385 | void dbgPrintf( const char* function, uint32_t line, const char * format, ... ); |
ram54288 | 0:a7a43371b306 | 386 | |
ram54288 | 0:a7a43371b306 | 387 | #define PAL_PRINTF( ARGS...) \ |
ram54288 | 0:a7a43371b306 | 388 | dbgPrintf(__FUNCTION__,__LINE__, ARGS); |
ram54288 | 0:a7a43371b306 | 389 | |
ram54288 | 0:a7a43371b306 | 390 | |
ram54288 | 0:a7a43371b306 | 391 | |
ram54288 | 0:a7a43371b306 | 392 | |
ram54288 | 0:a7a43371b306 | 393 | |
ram54288 | 0:a7a43371b306 | 394 | #ifdef __cplusplus |
ram54288 | 0:a7a43371b306 | 395 | } |
ram54288 | 0:a7a43371b306 | 396 | #endif |
ram54288 | 0:a7a43371b306 | 397 | #endif //_PAL_RTOS_H |