Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
pal_rtos.c
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 #include "pal_rtos.h" 00019 #include "pal_plat_rtos.h" 00020 00021 #if PAL_UNIQUE_THREAD_PRIORITY 00022 //! Threads priorities array. 00023 uint8_t g_palThreadPriorities[PAL_MAX_NUMBER_OF_THREADS] = {0}; 00024 #endif //PAL_UNIQUE_THREAD_PRIORITY 00025 00026 void pal_osReboot(void) 00027 { 00028 pal_plat_osReboot(); 00029 } 00030 00031 uint32_t pal_osKernelSysTick(void) 00032 { 00033 uint32_t result; 00034 result = pal_plat_osKernelSysTick(); 00035 return result; 00036 } 00037 00038 00039 uint64_t pal_osKernelSysTick64(void) 00040 { 00041 00042 #if PAL_RTOS_64BIT_TICK_SUPPORTED 00043 uint64_t result; 00044 result = pal_plat_osKernelSysTick64(); 00045 return result; 00046 #else 00047 static uint64_t lastValue = 0; 00048 static uint64_t wraparoundsDetected = 0; 00049 const uint64_t one = 1; 00050 uint64_t tmp = pal_plat_osKernelSysTick() + (wraparoundsDetected << 32); 00051 if (tmp < lastValue) //erez's "wraparound algorithm" if we detect a wrap around add 1 to the higher 32 bits 00052 { 00053 tmp = tmp + (one << 32); 00054 wraparoundsDetected++; 00055 } 00056 lastValue = tmp; 00057 return (uint64_t)tmp; 00058 #endif 00059 } 00060 00061 uint64_t pal_osKernelSysTickMicroSec(uint64_t microseconds) 00062 { 00063 uint64_t result; 00064 result = pal_plat_osKernelSysTickMicroSec(microseconds); 00065 return result; 00066 } 00067 00068 uint64_t pal_osKernelSysMilliSecTick(uint64_t sysTicks) 00069 { 00070 uint64_t result; 00071 result = pal_plat_osKernelSysMilliSecTick(sysTicks); 00072 return result; 00073 } 00074 00075 uint64_t pal_osKernelSysTickFrequency(void) 00076 { 00077 uint64_t result; 00078 result = pal_plat_osKernelSysTickFrequency(); 00079 return result; 00080 } 00081 00082 palStatus_t pal_osThreadCreate(palThreadFuncPtr function, void* funcArgument, palThreadPriority_t priority, uint32_t stackSize, uint32_t* stackPtr, palThreadLocalStore_t* store, palThreadID_t* threadID) 00083 { 00084 palStatus_t status = PAL_SUCCESS; 00085 00086 #if PAL_UNIQUE_THREAD_PRIORITY 00087 //! check if the priority have been used by other thread before 00088 if(PAL_osPriorityError == priority) 00089 { 00090 status = PAL_ERR_INVALID_ARGUMENT; 00091 } 00092 00093 if ((PAL_SUCCESS == status) && (g_palThreadPriorities[priority+PRIORYT_INDEX_OFFSET])) 00094 { 00095 *threadID = NULLPTR; 00096 status = PAL_ERR_RTOS_PRIORITY; 00097 } 00098 #endif //PAL_IGNORE_UNIQUE_THREAD_PRIORITY 00099 00100 if (PAL_SUCCESS == status) 00101 { 00102 status = pal_plat_osThreadCreate(function, funcArgument, priority, stackSize, stackPtr, store, threadID); 00103 } 00104 return status; 00105 } 00106 00107 palStatus_t pal_osThreadTerminate(palThreadID_t* threadID) 00108 { 00109 palStatus_t status; 00110 status = pal_plat_osThreadTerminate(threadID); 00111 return status; 00112 } 00113 00114 palThreadID_t pal_osThreadGetId(void) 00115 { 00116 palThreadID_t result; 00117 result = pal_plat_osThreadGetId(); 00118 return result; 00119 } 00120 00121 void* pal_osThreadGetLocalStore(void) 00122 { 00123 void* result; 00124 result = pal_plat_osThreadGetLocalStore(); 00125 return result; 00126 } 00127 00128 palStatus_t pal_osDelay(uint32_t milliseconds) 00129 { 00130 palStatus_t status; 00131 status = pal_plat_osDelay(milliseconds); 00132 return status; 00133 } 00134 00135 00136 palStatus_t pal_osTimerCreate(palTimerFuncPtr function, void* funcArgument, palTimerType_t timerType, palTimerID_t* timerID) 00137 { 00138 palStatus_t status; 00139 status = pal_plat_osTimerCreate(function, funcArgument, timerType, timerID); 00140 return status; 00141 } 00142 00143 palStatus_t pal_osTimerStart(palTimerID_t timerID, uint32_t millisec) 00144 { 00145 palStatus_t status; 00146 status = pal_plat_osTimerStart(timerID, millisec); 00147 return status; 00148 } 00149 00150 palStatus_t pal_osTimerStop(palTimerID_t timerID) 00151 { 00152 palStatus_t status; 00153 status = pal_plat_osTimerStop(timerID); 00154 return status; 00155 } 00156 00157 palStatus_t pal_osTimerDelete(palTimerID_t* timerID) 00158 { 00159 palStatus_t status; 00160 status = pal_plat_osTimerDelete(timerID); 00161 return status; 00162 } 00163 00164 palStatus_t pal_osMutexCreate(palMutexID_t* mutexID) 00165 { 00166 palStatus_t status; 00167 status = pal_plat_osMutexCreate(mutexID); 00168 return status; 00169 } 00170 00171 palStatus_t pal_osMutexWait(palMutexID_t mutexID, uint32_t millisec) 00172 { 00173 palStatus_t status; 00174 status = pal_plat_osMutexWait(mutexID, millisec); 00175 return status; 00176 } 00177 00178 palStatus_t pal_osMutexRelease(palMutexID_t mutexID) 00179 { 00180 palStatus_t status; 00181 status = pal_plat_osMutexRelease(mutexID); 00182 return status; 00183 } 00184 00185 palStatus_t pal_osMutexDelete(palMutexID_t* mutexID) 00186 { 00187 palStatus_t status; 00188 status = pal_plat_osMutexDelete(mutexID); 00189 return status; 00190 } 00191 palStatus_t pal_osSemaphoreCreate(uint32_t count, palSemaphoreID_t* semaphoreID) 00192 { 00193 palStatus_t status; 00194 status = pal_plat_osSemaphoreCreate(count, semaphoreID); 00195 return status; 00196 } 00197 00198 palStatus_t pal_osSemaphoreWait(palSemaphoreID_t semaphoreID, uint32_t millisec, int32_t* countersAvailable) 00199 { 00200 palStatus_t status; 00201 status = pal_plat_osSemaphoreWait(semaphoreID, millisec, countersAvailable); 00202 return status; 00203 } 00204 00205 palStatus_t pal_osSemaphoreRelease(palSemaphoreID_t semaphoreID) 00206 { 00207 palStatus_t status; 00208 status = pal_plat_osSemaphoreRelease(semaphoreID); 00209 return status; 00210 } 00211 00212 palStatus_t pal_osSemaphoreDelete(palSemaphoreID_t* semaphoreID) 00213 { 00214 palStatus_t status; 00215 status = pal_plat_osSemaphoreDelete(semaphoreID); 00216 return status; 00217 } 00218 00219 palStatus_t pal_osPoolCreate(uint32_t blockSize, uint32_t blockCount, palMemoryPoolID_t* memoryPoolID) 00220 { 00221 palStatus_t status; 00222 status = pal_plat_osPoolCreate(blockSize, blockCount, memoryPoolID); 00223 return status; 00224 } 00225 00226 void* pal_osPoolAlloc(palMemoryPoolID_t memoryPoolID) 00227 { 00228 void* result; 00229 result = pal_plat_osPoolAlloc(memoryPoolID); 00230 return result; 00231 } 00232 00233 void* pal_osPoolCAlloc(palMemoryPoolID_t memoryPoolID) 00234 { 00235 void* result; 00236 //TODO(nirson01): debug print in case of failed alloc? 00237 result = pal_plat_osPoolCAlloc(memoryPoolID); 00238 return result; 00239 } 00240 00241 palStatus_t pal_osPoolFree(palMemoryPoolID_t memoryPoolID, void* block) 00242 { 00243 palStatus_t status; 00244 //TODO(nirson01): debug print in case of failed alloc? 00245 status = pal_plat_osPoolFree(memoryPoolID, block); 00246 return status; 00247 } 00248 00249 palStatus_t pal_osPoolDestroy(palMemoryPoolID_t* memoryPoolID) 00250 { 00251 palStatus_t status; 00252 status = pal_plat_osPoolDestroy(memoryPoolID); 00253 return status; 00254 } 00255 00256 palStatus_t pal_osMessageQueueCreate(uint32_t messageQSize, palMessageQID_t* messageQID) 00257 { 00258 palStatus_t status; 00259 status = pal_plat_osMessageQueueCreate(messageQSize, messageQID); 00260 return status; 00261 } 00262 00263 palStatus_t pal_osMessagePut(palMessageQID_t messageQID, uint32_t info, uint32_t timeout) 00264 { 00265 palStatus_t status; 00266 status = pal_plat_osMessagePut(messageQID, info, timeout); 00267 return status; 00268 } 00269 00270 palStatus_t pal_osMessageGet(palMessageQID_t messageQID, uint32_t timeout, uint32_t* messageValue) 00271 { 00272 palStatus_t status; 00273 status = pal_plat_osMessageGet(messageQID, timeout, messageValue); 00274 return status; 00275 } 00276 00277 palStatus_t pal_osMessageQueueDestroy(palMessageQID_t* messageQID) 00278 { 00279 palStatus_t status; 00280 status = pal_plat_osMessageQueueDestroy(messageQID); 00281 return status; 00282 } 00283 00284 int32_t pal_osAtomicIncrement(int32_t* valuePtr, int32_t increment) 00285 { 00286 int32_t result; 00287 result = pal_plat_osAtomicIncrement(valuePtr, increment); 00288 return result; 00289 } 00290 00291 00292 00293 #ifdef DEBUG 00294 #include "stdarg.h" 00295 #endif 00296 00297 void dbgPrintf( const char* function, uint32_t line, const char * format, ... ) 00298 { 00299 #ifdef DEBUG 00300 static palMutexID_t printfMutex = NULLPTR; 00301 00302 va_list args; 00303 if (!printfMutex) 00304 { 00305 pal_osMutexCreate(&printfMutex); 00306 } 00307 pal_osMutexWait(printfMutex, PAL_MAX_UINT32); 00308 #ifdef VERBOSE 00309 pal_plat_printf("%s:%ld\t",function,line); 00310 #endif 00311 va_start (args, format); 00312 pal_plat_vprintf (format, args); 00313 va_end (args); 00314 pal_osMutexRelease(printfMutex); 00315 #endif 00316 } 00317 00318 00319
Generated on Tue Jul 12 2022 21:20:29 by
