FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

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