tasks.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. /* Standard includes. */
  29. #include <stdlib.h>
  30. #include <string.h>
  31. /* FreeRTOS includes. */
  32. #include "FreeRTOS.h"
  33. #include "task.h"
  34. /* Values that can be assigned to the ucNotifyState member of the TCB. */
  35. #define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 ) /* Must be zero as it is the initialised value. */
  36. #define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 )
  37. #define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 )
  38. /*
  39. * Several functions take a TaskHandle_t parameter that can optionally be NULL,
  40. * where NULL is used to indicate that the handle of the currently executing
  41. * task should be used in place of the parameter. This macro simply checks to
  42. * see if the parameter is NULL and returns a pointer to the appropriate TCB.
  43. */
  44. #define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( xTaskGetCurrentTaskHandle() ) : ( pxHandle ) )
  45. /*
  46. * Task control block. A task control block (TCB) is allocated for each task,
  47. * and stores task state information, including a pointer to the task's context
  48. * (the task's run time environment, including register values)
  49. */
  50. typedef struct tskTaskControlBlock
  51. {
  52. struct rt_thread thread;
  53. #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  54. TaskHookFunction_t pxTaskTag;
  55. #endif
  56. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  57. volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
  58. volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
  59. #endif
  60. #if ( INCLUDE_xTaskAbortDelay == 1 )
  61. uint8_t ucDelayAborted;
  62. #endif
  63. } tskTCB;
  64. typedef tskTCB TCB_t;
  65. /* Other file private variables. --------------------------------*/
  66. static volatile BaseType_t xSchedulerRunning = pdFALSE;
  67. /*-----------------------------------------------------------*/
  68. /*
  69. * Called after a Task_t structure has been allocated either statically or
  70. * dynamically to fill in the structure's members.
  71. */
  72. static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
  73. const char * const pcName,
  74. const uint32_t ulStackDepth,
  75. void * const pvParameters,
  76. UBaseType_t uxPriority,
  77. TaskHandle_t * const pxCreatedTask,
  78. TCB_t * pxNewTCB,
  79. StackType_t * const puxStackBuffer );
  80. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  81. TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  82. const char * const pcName,
  83. const uint32_t ulStackDepth,
  84. void * const pvParameters,
  85. UBaseType_t uxPriority,
  86. StackType_t * const puxStackBuffer,
  87. StaticTask_t * const pxTaskBuffer )
  88. {
  89. TCB_t * pxNewTCB;
  90. TaskHandle_t xReturn = NULL;
  91. configASSERT( puxStackBuffer != NULL );
  92. configASSERT( pxTaskBuffer != NULL );
  93. #if ( configASSERT_DEFINED == 1 )
  94. {
  95. /* Sanity check that the size of the structure used to declare a
  96. * variable of type StaticTask_t equals the size of the real task
  97. * structure. */
  98. volatile size_t xSize = sizeof( StaticTask_t );
  99. configASSERT( xSize == sizeof( TCB_t ) );
  100. ( void ) xSize; /* Prevent lint warning when configASSERT() is not used. */
  101. }
  102. #endif /* configASSERT_DEFINED */
  103. if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) )
  104. {
  105. pxNewTCB = ( TCB_t * ) pxTaskBuffer;
  106. prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, puxStackBuffer );
  107. rt_thread_startup( ( rt_thread_t ) pxNewTCB );
  108. }
  109. return xReturn;
  110. }
  111. #endif /* SUPPORT_STATIC_ALLOCATION */
  112. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  113. BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  114. const char * const pcName,
  115. const configSTACK_DEPTH_TYPE usStackDepth,
  116. void * const pvParameters,
  117. UBaseType_t uxPriority,
  118. TaskHandle_t * const pxCreatedTask )
  119. {
  120. TCB_t * pxNewTCB;
  121. BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
  122. void * stack_start = RT_NULL;
  123. pxNewTCB = ( TCB_t * ) RT_KERNEL_MALLOC( sizeof( TCB_t ) );
  124. if ( pxNewTCB != NULL )
  125. {
  126. stack_start = RT_KERNEL_MALLOC( usStackDepth * sizeof( StackType_t ) );
  127. if ( stack_start != RT_NULL )
  128. {
  129. prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, ( StackType_t * ) stack_start );
  130. xReturn = pdPASS;
  131. /* Mark as dynamic */
  132. #if RT_VER_NUM < 0x50000
  133. ( ( struct rt_thread * ) pxNewTCB )-> type &= ~RT_Object_Class_Static;
  134. #else
  135. ( ( struct rt_thread * ) pxNewTCB )-> parent.type &= ~RT_Object_Class_Static;
  136. #endif /* RT_VER_NUM < 0x50000 */
  137. rt_thread_startup( ( rt_thread_t ) pxNewTCB );
  138. }
  139. else
  140. {
  141. RT_KERNEL_FREE( pxNewTCB );
  142. }
  143. }
  144. return xReturn;
  145. }
  146. #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  147. /*-----------------------------------------------------------*/
  148. #ifdef ESP_PLATFORM
  149. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  150. BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
  151. const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  152. const uint32_t usStackDepth,
  153. void * const pvParameters,
  154. UBaseType_t uxPriority,
  155. TaskHandle_t * const pvCreatedTask,
  156. const BaseType_t xCoreID)
  157. {
  158. ( void ) xCoreID;
  159. return xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask );
  160. }
  161. #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  162. #endif
  163. /*-----------------------------------------------------------*/
  164. static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
  165. const char * const pcName,
  166. const uint32_t ulStackDepth,
  167. void * const pvParameters,
  168. UBaseType_t uxPriority,
  169. TaskHandle_t * const pxCreatedTask,
  170. TCB_t * pxNewTCB,
  171. StackType_t * const puxStackBuffer )
  172. {
  173. /* This is used as an array index so must ensure it's not too large. */
  174. configASSERT( uxPriority < configMAX_PRIORITIES );
  175. if( uxPriority >= ( UBaseType_t ) configMAX_PRIORITIES )
  176. {
  177. uxPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;
  178. }
  179. rt_thread_init( ( struct rt_thread * ) pxNewTCB, pcName, pxTaskCode, pvParameters,
  180. puxStackBuffer, ulStackDepth * sizeof( StackType_t ), FREERTOS_PRIORITY_TO_RTTHREAD( uxPriority ), 1 );
  181. #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  182. pxNewTCB->pxTaskTag = NULL;
  183. #endif
  184. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  185. rt_memset( ( void * ) &( pxNewTCB->ulNotifiedValue[ 0 ] ), 0x00, sizeof( pxNewTCB->ulNotifiedValue ) );
  186. rt_memset( ( void * ) &( pxNewTCB->ucNotifyState[ 0 ] ), 0x00, sizeof( pxNewTCB->ucNotifyState ) );
  187. #endif
  188. #if ( INCLUDE_xTaskAbortDelay == 1 )
  189. pxNewTCB->ucDelayAborted = pdFALSE;
  190. #endif
  191. if ( pxCreatedTask != NULL )
  192. {
  193. *pxCreatedTask = ( TaskHandle_t ) pxNewTCB;
  194. }
  195. }
  196. /*-----------------------------------------------------------*/
  197. #if ( INCLUDE_vTaskDelete == 1 )
  198. void vTaskDelete( TaskHandle_t xTaskToDelete )
  199. {
  200. rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTaskToDelete );
  201. if ( thread == RT_NULL )
  202. {
  203. thread = rt_thread_self();
  204. }
  205. #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  206. if ( rt_object_is_systemobject( ( rt_object_t ) thread ) )
  207. #endif
  208. {
  209. #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  210. rt_thread_detach( thread );
  211. #endif
  212. #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  213. }
  214. else
  215. {
  216. #endif
  217. #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  218. rt_thread_delete( thread );
  219. #endif
  220. }
  221. if ( thread == rt_thread_self() )
  222. {
  223. rt_schedule();
  224. }
  225. }
  226. #endif /* INCLUDE_vTaskDelete */
  227. /*-----------------------------------------------------------*/
  228. #if ( INCLUDE_xTaskDelayUntil == 1 )
  229. BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  230. const TickType_t xTimeIncrement )
  231. {
  232. BaseType_t xShouldDelay = pdFALSE;
  233. rt_base_t level;
  234. rt_tick_t cur_tick;
  235. RT_ASSERT( pxPreviousWakeTime != RT_NULL );
  236. RT_ASSERT( xTimeIncrement > 0U );
  237. level = rt_hw_interrupt_disable();
  238. cur_tick = rt_tick_get();
  239. if (cur_tick - *pxPreviousWakeTime < xTimeIncrement)
  240. {
  241. rt_thread_delay_until( pxPreviousWakeTime, xTimeIncrement );
  242. xShouldDelay = pdTRUE;
  243. }
  244. rt_hw_interrupt_enable( level );
  245. return xShouldDelay;
  246. }
  247. #endif /* INCLUDE_xTaskDelayUntil */
  248. /*-----------------------------------------------------------*/
  249. #if ( INCLUDE_vTaskDelay == 1 )
  250. void vTaskDelay( const TickType_t xTicksToDelay )
  251. {
  252. rt_thread_delay( xTicksToDelay );
  253. }
  254. #endif /* INCLUDE_vTaskDelay */
  255. /*-----------------------------------------------------------*/
  256. #if ( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_xTaskAbortDelay == 1 ) )
  257. eTaskState eTaskGetState( TaskHandle_t xTask )
  258. {
  259. eTaskState eReturn;
  260. rt_thread_t thread = ( rt_thread_t ) xTask;
  261. rt_base_t level;
  262. configASSERT( xTask );
  263. level = rt_hw_interrupt_disable();
  264. switch ( thread->stat & RT_THREAD_STAT_MASK )
  265. {
  266. case RT_THREAD_READY:
  267. {
  268. eReturn = eReady;
  269. break;
  270. }
  271. case RT_THREAD_SUSPEND:
  272. {
  273. /* If thread timer is activated it is blocked with a timeout */
  274. if ( thread->thread_timer.parent.flag & RT_TIMER_FLAG_ACTIVATED )
  275. {
  276. eReturn = eBlocked;
  277. }
  278. /* Otherwise it is suspended or blocked with an infinite timeout */
  279. else
  280. {
  281. eReturn = eSuspended;
  282. }
  283. break;
  284. }
  285. case RT_THREAD_RUNNING:
  286. {
  287. eReturn = eRunning;
  288. break;
  289. }
  290. case RT_THREAD_CLOSE:
  291. {
  292. eReturn = eDeleted;
  293. break;
  294. }
  295. default:
  296. eReturn = eInvalid;
  297. }
  298. rt_hw_interrupt_enable( level );
  299. return eReturn;
  300. }
  301. #endif /* INCLUDE_eTaskGetState */
  302. /*-----------------------------------------------------------*/
  303. #if ( INCLUDE_uxTaskPriorityGet == 1 )
  304. UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask )
  305. {
  306. UBaseType_t uxReturn;
  307. rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTask );
  308. rt_base_t level;
  309. level = rt_hw_interrupt_disable();
  310. uxReturn = thread->current_priority;
  311. rt_hw_interrupt_enable( level );
  312. return RTTHREAD_PRIORITY_TO_FREERTOS( uxReturn );
  313. }
  314. #endif /* INCLUDE_uxTaskPriorityGet */
  315. /*-----------------------------------------------------------*/
  316. #if ( INCLUDE_uxTaskPriorityGet == 1 )
  317. UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask )
  318. {
  319. return uxTaskPriorityGet( xTask );
  320. }
  321. #endif /* INCLUDE_uxTaskPriorityGet */
  322. /*-----------------------------------------------------------*/
  323. #if ( INCLUDE_vTaskPrioritySet == 1 )
  324. void vTaskPrioritySet( TaskHandle_t xTask,
  325. UBaseType_t uxNewPriority )
  326. {
  327. extern rt_thread_t rt_current_thread;
  328. rt_thread_t thread;
  329. rt_uint8_t current_priority;
  330. rt_bool_t need_schedule = RT_FALSE;
  331. rt_base_t level;
  332. configASSERT( uxNewPriority < configMAX_PRIORITIES );
  333. /* Ensure the new priority is valid. */
  334. if( uxNewPriority >= ( UBaseType_t ) configMAX_PRIORITIES )
  335. {
  336. uxNewPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;
  337. }
  338. uxNewPriority = FREERTOS_PRIORITY_TO_RTTHREAD( uxNewPriority );
  339. level = rt_hw_interrupt_disable();
  340. thread = ( rt_thread_t ) prvGetTCBFromHandle( xTask );
  341. current_priority = thread->current_priority;
  342. if ( current_priority != uxNewPriority )
  343. {
  344. rt_thread_control( thread, RT_THREAD_CTRL_CHANGE_PRIORITY, &uxNewPriority);
  345. if ( uxNewPriority < current_priority )
  346. {
  347. /* The priority of a task other than the currently running task is being raised.
  348. * Need to schedule if the priority is raised above that of the running task */
  349. if ( thread != rt_current_thread && uxNewPriority <= rt_current_thread->current_priority )
  350. {
  351. need_schedule = RT_TRUE;
  352. }
  353. }
  354. /* Setting the priority of the running task down means
  355. * there may now be another task of higher priority that
  356. * is ready to execute. */
  357. else if ( thread == rt_current_thread )
  358. {
  359. need_schedule = RT_TRUE;
  360. }
  361. }
  362. rt_hw_interrupt_enable( level );
  363. if ( need_schedule == RT_TRUE )
  364. {
  365. rt_schedule();
  366. }
  367. }
  368. #endif /* INCLUDE_vTaskPrioritySet */
  369. /*-----------------------------------------------------------*/
  370. #if ( INCLUDE_vTaskSuspend == 1 )
  371. void vTaskSuspend( TaskHandle_t xTaskToSuspend )
  372. {
  373. rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTaskToSuspend );
  374. if ( rt_thread_suspend( thread ) == RT_EOK )
  375. {
  376. rt_schedule();
  377. }
  378. }
  379. #endif /* INCLUDE_vTaskSuspend */
  380. /*-----------------------------------------------------------*/
  381. #if ( INCLUDE_vTaskSuspend == 1 )
  382. void vTaskResume( TaskHandle_t xTaskToResume )
  383. {
  384. rt_thread_t thread = ( rt_thread_t ) xTaskToResume;
  385. rt_bool_t need_schedule = RT_FALSE;
  386. rt_base_t level;
  387. /* It does not make sense to resume the calling task. */
  388. configASSERT( xTaskToResume );
  389. if ( thread != NULL && thread != rt_thread_self() )
  390. {
  391. level = rt_hw_interrupt_disable();
  392. /* A task with higher priority than the current running task is ready */
  393. if ( rt_thread_resume( thread ) == RT_EOK && thread->current_priority <= rt_thread_self()->current_priority )
  394. {
  395. need_schedule = RT_TRUE;
  396. }
  397. rt_hw_interrupt_enable( level );
  398. }
  399. if (need_schedule == RT_TRUE)
  400. {
  401. rt_schedule();
  402. }
  403. }
  404. #endif /* INCLUDE_vTaskSuspend */
  405. /*-----------------------------------------------------------*/
  406. #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
  407. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )
  408. {
  409. vTaskResume( xTaskToResume );
  410. return pdFALSE;
  411. }
  412. #endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */
  413. /*-----------------------------------------------------------*/
  414. void vTaskStartScheduler( void )
  415. {
  416. xSchedulerRunning = pdTRUE;
  417. #ifdef ESP_PLATFORM
  418. extern int rtthread_startup(void);
  419. rtthread_startup();
  420. #endif
  421. }
  422. /*-----------------------------------------------------------*/
  423. void vTaskEndScheduler( void )
  424. {
  425. xSchedulerRunning = pdFALSE;
  426. vPortEndScheduler();
  427. }
  428. /*----------------------------------------------------------*/
  429. void vTaskSuspendAll( void )
  430. {
  431. rt_enter_critical();
  432. }
  433. /*----------------------------------------------------------*/
  434. BaseType_t xTaskResumeAll( void )
  435. {
  436. rt_exit_critical();
  437. return pdFALSE;
  438. }
  439. /*-----------------------------------------------------------*/
  440. TickType_t xTaskGetTickCount( void )
  441. {
  442. return rt_tick_get();
  443. }
  444. /*-----------------------------------------------------------*/
  445. TickType_t xTaskGetTickCountFromISR( void )
  446. {
  447. return rt_tick_get();
  448. }
  449. /*-----------------------------------------------------------*/
  450. UBaseType_t uxTaskGetNumberOfTasks( void )
  451. {
  452. UBaseType_t uxReturn = 0;
  453. rt_base_t level;
  454. struct rt_object_information *information;
  455. struct rt_list_node *node = RT_NULL;
  456. information = rt_object_get_information( RT_Object_Class_Thread );
  457. RT_ASSERT( information != RT_NULL );
  458. level = rt_hw_interrupt_disable();
  459. rt_list_for_each( node, &( information->object_list ) )
  460. {
  461. uxReturn += 1;
  462. }
  463. rt_hw_interrupt_enable( level );
  464. return uxReturn;
  465. }
  466. /*-----------------------------------------------------------*/
  467. char * pcTaskGetName( TaskHandle_t xTaskToQuery )
  468. {
  469. rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTaskToQuery );
  470. #if RT_VER_NUM < 0x50000
  471. return &( thread->name[ 0 ] );
  472. #else
  473. return &( thread->parent.name[ 0 ] );
  474. #endif /* RT_VER_NUM < 0x50000 */
  475. }
  476. /*-----------------------------------------------------------*/
  477. #if ( INCLUDE_xTaskGetHandle == 1 )
  478. TaskHandle_t xTaskGetHandle( const char * pcNameToQuery )
  479. {
  480. return ( TaskHandle_t ) rt_thread_find( ( char * ) pcNameToQuery );
  481. }
  482. #endif /* INCLUDE_xTaskGetHandle */
  483. /*-----------------------------------------------------------*/
  484. #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
  485. TaskHandle_t xTaskGetIdleTaskHandle( void )
  486. {
  487. return ( TaskHandle_t ) rt_thread_find( "tidle0" );
  488. }
  489. #endif /* INCLUDE_xTaskGetIdleTaskHandle */
  490. /*----------------------------------------------------------*/
  491. #if ( INCLUDE_xTaskAbortDelay == 1 )
  492. BaseType_t xTaskAbortDelay( TaskHandle_t xTask )
  493. {
  494. TCB_t * pxTCB = xTask;
  495. BaseType_t xReturn;
  496. rt_thread_t thread = ( rt_thread_t ) xTask;
  497. rt_bool_t need_schedule = RT_FALSE;
  498. rt_base_t level;
  499. configASSERT( pxTCB );
  500. level = rt_hw_interrupt_disable();
  501. if ( eTaskGetState( xTask ) == eBlocked )
  502. {
  503. rt_thread_resume( thread );
  504. thread->error = -RT_ETIMEOUT;
  505. pxTCB->ucDelayAborted = pdTRUE;
  506. if ( thread->current_priority < rt_thread_self()->current_priority ){
  507. need_schedule = RT_TRUE;
  508. }
  509. xReturn = pdPASS;
  510. }
  511. else
  512. {
  513. xReturn = pdFAIL;
  514. }
  515. rt_hw_interrupt_enable( level );
  516. if ( need_schedule == RT_TRUE )
  517. {
  518. rt_schedule();
  519. }
  520. return xReturn;
  521. }
  522. #endif /* INCLUDE_xTaskAbortDelay */
  523. /*----------------------------------------------------------*/
  524. #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  525. void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  526. TaskHookFunction_t pxHookFunction )
  527. {
  528. TCB_t * xTCB = prvGetTCBFromHandle( xTask );
  529. rt_base_t level;
  530. level = rt_hw_interrupt_disable();
  531. xTCB->pxTaskTag = pxHookFunction;
  532. rt_hw_interrupt_enable( level );
  533. }
  534. #endif /* configUSE_APPLICATION_TASK_TAG */
  535. /*-----------------------------------------------------------*/
  536. #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  537. TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask )
  538. {
  539. TaskHookFunction_t xReturn;
  540. TCB_t * xTCB = prvGetTCBFromHandle( xTask );
  541. rt_base_t level;
  542. level = rt_hw_interrupt_disable();
  543. xReturn = xTCB->pxTaskTag;
  544. rt_hw_interrupt_enable( level );
  545. return xReturn;
  546. }
  547. #endif /* configUSE_APPLICATION_TASK_TAG */
  548. /*-----------------------------------------------------------*/
  549. #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  550. TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask )
  551. {
  552. return xTaskGetApplicationTaskTag( xTask );
  553. }
  554. #endif /* configUSE_APPLICATION_TASK_TAG */
  555. /*-----------------------------------------------------------*/
  556. #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  557. BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  558. void * pvParameter )
  559. {
  560. BaseType_t xReturn;
  561. TCB_t * xTCB = prvGetTCBFromHandle( xTask );
  562. if( xTCB->pxTaskTag != NULL )
  563. {
  564. xReturn = xTCB->pxTaskTag( pvParameter );
  565. }
  566. else
  567. {
  568. xReturn = pdFAIL;
  569. }
  570. return xReturn;
  571. }
  572. #endif /* configUSE_APPLICATION_TASK_TAG */
  573. /*-----------------------------------------------------------*/
  574. void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )
  575. {
  576. rt_base_t level;
  577. configASSERT( pxTimeOut );
  578. level = rt_hw_interrupt_disable();
  579. pxTimeOut->xOverflowCount = 0;
  580. pxTimeOut->xTimeOnEntering = ( TickType_t ) rt_tick_get();
  581. rt_hw_interrupt_enable( level );
  582. }
  583. /*-----------------------------------------------------------*/
  584. void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )
  585. {
  586. /* For internal use only as it does not use a critical section. */
  587. pxTimeOut->xOverflowCount = 0;
  588. pxTimeOut->xTimeOnEntering = ( TickType_t ) rt_tick_get();;
  589. }
  590. /*-----------------------------------------------------------*/
  591. BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  592. TickType_t * const pxTicksToWait )
  593. {
  594. TCB_t * pxCurrentTCB = ( TCB_t * ) rt_thread_self();
  595. BaseType_t xReturn;
  596. rt_base_t level;
  597. configASSERT( pxTimeOut );
  598. configASSERT( pxTicksToWait );
  599. level = rt_hw_interrupt_disable();
  600. /* Minor optimisation. The tick count cannot change in this block. */
  601. const TickType_t xConstTickCount = ( TickType_t ) rt_tick_get();
  602. const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering;
  603. #if ( INCLUDE_xTaskAbortDelay == 1 )
  604. if( pxCurrentTCB->ucDelayAborted != ( uint8_t ) pdFALSE )
  605. {
  606. /* The delay was aborted, which is not the same as a time out,
  607. * but has the same result. */
  608. pxCurrentTCB->ucDelayAborted = pdFALSE;
  609. xReturn = pdTRUE;
  610. }
  611. else
  612. #endif
  613. #if ( INCLUDE_vTaskSuspend == 1 )
  614. if( *pxTicksToWait == portMAX_DELAY )
  615. {
  616. /* If INCLUDE_vTaskSuspend is set to 1 and the block time
  617. * specified is the maximum block time then the task should block
  618. * indefinitely, and therefore never time out. */
  619. xReturn = pdFALSE;
  620. }
  621. else
  622. #endif
  623. if( xElapsedTime < *pxTicksToWait )
  624. {
  625. /* Not a genuine timeout. Adjust parameters for time remaining. */
  626. *pxTicksToWait -= xElapsedTime;
  627. vTaskInternalSetTimeOutState( pxTimeOut );
  628. xReturn = pdFALSE;
  629. }
  630. else
  631. {
  632. *pxTicksToWait = ( TickType_t ) 0;
  633. xReturn = pdTRUE;
  634. }
  635. rt_hw_interrupt_enable( level );
  636. return xReturn;
  637. }
  638. /*-----------------------------------------------------------*/
  639. #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) )
  640. TaskHandle_t xTaskGetCurrentTaskHandle( void )
  641. {
  642. TaskHandle_t xReturn;
  643. /* A critical section is not required as this is not called from
  644. * an interrupt and the current TCB will always be the same for any
  645. * individual execution thread. */
  646. xReturn = ( TaskHandle_t ) rt_thread_self();
  647. return xReturn;
  648. }
  649. #endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */
  650. /*-----------------------------------------------------------*/
  651. #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) )
  652. BaseType_t xTaskGetSchedulerState( void )
  653. {
  654. BaseType_t xReturn;
  655. if( xSchedulerRunning == pdFALSE )
  656. {
  657. xReturn = taskSCHEDULER_NOT_STARTED;
  658. }
  659. else
  660. {
  661. if( rt_critical_level() == 0 )
  662. {
  663. xReturn = taskSCHEDULER_RUNNING;
  664. }
  665. else
  666. {
  667. xReturn = taskSCHEDULER_SUSPENDED;
  668. }
  669. }
  670. return xReturn;
  671. }
  672. #endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) ) */
  673. /*-----------------------------------------------------------*/
  674. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  675. uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWait,
  676. BaseType_t xClearCountOnExit,
  677. TickType_t xTicksToWait )
  678. {
  679. uint32_t ulReturn;
  680. TCB_t * pxCurrentTCB = ( TCB_t * ) rt_thread_self();
  681. rt_thread_t thread = ( rt_thread_t ) pxCurrentTCB;
  682. rt_base_t level;
  683. configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  684. level = rt_hw_interrupt_disable();
  685. /* Only block if the notification count is not already non-zero. */
  686. if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL )
  687. {
  688. /* Mark this task as waiting for a notification. */
  689. pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION;
  690. if( xTicksToWait > ( TickType_t ) 0 )
  691. {
  692. rt_thread_suspend( thread );
  693. if ( ( rt_int32_t ) xTicksToWait > 0 )
  694. {
  695. rt_timer_control(&(thread->thread_timer),
  696. RT_TIMER_CTRL_SET_TIME,
  697. &xTicksToWait);
  698. rt_timer_start(&(thread->thread_timer));
  699. }
  700. rt_hw_interrupt_enable(level);
  701. rt_schedule();
  702. /* Clear thread error. */
  703. thread->error = RT_EOK;
  704. }
  705. }
  706. rt_hw_interrupt_enable( level );
  707. level = rt_hw_interrupt_disable();
  708. ulReturn = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ];
  709. if( ulReturn != 0UL )
  710. {
  711. if( xClearCountOnExit != pdFALSE )
  712. {
  713. pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = 0UL;
  714. }
  715. else
  716. {
  717. pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = ulReturn - ( uint32_t ) 1;
  718. }
  719. }
  720. pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION;
  721. rt_hw_interrupt_enable( level );
  722. return ulReturn;
  723. }
  724. #endif /* configUSE_TASK_NOTIFICATIONS */
  725. /*-----------------------------------------------------------*/
  726. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  727. BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWait,
  728. uint32_t ulBitsToClearOnEntry,
  729. uint32_t ulBitsToClearOnExit,
  730. uint32_t * pulNotificationValue,
  731. TickType_t xTicksToWait )
  732. {
  733. BaseType_t xReturn;
  734. TCB_t * pxCurrentTCB = ( TCB_t * ) rt_thread_self();
  735. rt_thread_t thread = ( rt_thread_t ) pxCurrentTCB;
  736. rt_base_t level;
  737. configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  738. level = rt_hw_interrupt_disable();
  739. /* Only block if a notification is not already pending. */
  740. if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED )
  741. {
  742. /* Clear bits in the task's notification value as bits may get
  743. * set by the notifying task or interrupt. This can be used to
  744. * clear the value to zero. */
  745. pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] &= ~ulBitsToClearOnEntry;
  746. /* Mark this task as waiting for a notification. */
  747. pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION;
  748. if( xTicksToWait > ( TickType_t ) 0 )
  749. {
  750. rt_thread_suspend( thread );
  751. if ( ( rt_int32_t ) xTicksToWait > 0 )
  752. {
  753. rt_timer_control(&(thread->thread_timer),
  754. RT_TIMER_CTRL_SET_TIME,
  755. &xTicksToWait);
  756. rt_timer_start(&(thread->thread_timer));
  757. }
  758. rt_hw_interrupt_enable(level);
  759. rt_schedule();
  760. /* Clear thread error. It is not used to determine the function return value. */
  761. thread->error = RT_EOK;
  762. }
  763. else
  764. {
  765. rt_hw_interrupt_enable( level );
  766. }
  767. }
  768. else
  769. {
  770. rt_hw_interrupt_enable( level );
  771. }
  772. level = rt_hw_interrupt_disable();
  773. if( pulNotificationValue != NULL )
  774. {
  775. /* Output the current notification value, which may or may not
  776. * have changed. */
  777. *pulNotificationValue = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ];
  778. }
  779. /* If ucNotifyValue is set then either the task never entered the
  780. * blocked state (because a notification was already pending) or the
  781. * task unblocked because of a notification. Otherwise the task
  782. * unblocked because of a timeout. */
  783. if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED )
  784. {
  785. /* A notification was not received. */
  786. xReturn = pdFALSE;
  787. }
  788. else
  789. {
  790. /* A notification was already pending or a notification was
  791. * received while the task was waiting. */
  792. pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] &= ~ulBitsToClearOnExit;
  793. xReturn = pdTRUE;
  794. }
  795. pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION;
  796. rt_hw_interrupt_enable( level );
  797. return xReturn;
  798. }
  799. #endif /* configUSE_TASK_NOTIFICATIONS */
  800. /*-----------------------------------------------------------*/
  801. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  802. BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  803. UBaseType_t uxIndexToNotify,
  804. uint32_t ulValue,
  805. eNotifyAction eAction,
  806. uint32_t * pulPreviousNotificationValue )
  807. {
  808. TCB_t * pxTCB;
  809. BaseType_t xReturn = pdPASS;
  810. uint8_t ucOriginalNotifyState;
  811. rt_base_t level;
  812. configASSERT( uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  813. configASSERT( xTaskToNotify );
  814. pxTCB = xTaskToNotify;
  815. level = rt_hw_interrupt_disable();
  816. if( pulPreviousNotificationValue != NULL )
  817. {
  818. *pulPreviousNotificationValue = pxTCB->ulNotifiedValue[ uxIndexToNotify ];
  819. }
  820. ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ];
  821. pxTCB->ucNotifyState[ uxIndexToNotify ] = taskNOTIFICATION_RECEIVED;
  822. switch( eAction )
  823. {
  824. case eSetBits:
  825. pxTCB->ulNotifiedValue[ uxIndexToNotify ] |= ulValue;
  826. break;
  827. case eIncrement:
  828. ( pxTCB->ulNotifiedValue[ uxIndexToNotify ] )++;
  829. break;
  830. case eSetValueWithOverwrite:
  831. pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue;
  832. break;
  833. case eSetValueWithoutOverwrite:
  834. if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED )
  835. {
  836. pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue;
  837. }
  838. else
  839. {
  840. /* The value could not be written to the task. */
  841. xReturn = pdFAIL;
  842. }
  843. break;
  844. case eNoAction:
  845. /* The task is being notified without its notify value being
  846. * updated. */
  847. break;
  848. default:
  849. /* Should not get here if all enums are handled.
  850. * Artificially force an assert by testing a value the
  851. * compiler can't assume is const. */
  852. configASSERT( xTaskToNotify == NULL );
  853. break;
  854. }
  855. /* If the task is in the blocked state specifically to wait for a
  856. * notification then unblock it now. */
  857. if( ucOriginalNotifyState == taskWAITING_NOTIFICATION )
  858. {
  859. rt_thread_resume( ( rt_thread_t ) pxTCB );
  860. if( ( ( rt_thread_t ) pxTCB )->current_priority < rt_thread_self()->current_priority )
  861. {
  862. /* The notified task has a priority above the currently
  863. * executing task so a schedule is required. */
  864. rt_schedule();
  865. }
  866. }
  867. rt_hw_interrupt_enable( level );
  868. return xReturn;
  869. }
  870. #endif /* configUSE_TASK_NOTIFICATIONS */
  871. /*-----------------------------------------------------------*/
  872. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  873. BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  874. UBaseType_t uxIndexToNotify,
  875. uint32_t ulValue,
  876. eNotifyAction eAction,
  877. uint32_t * pulPreviousNotificationValue,
  878. BaseType_t * pxHigherPriorityTaskWoken )
  879. {
  880. BaseType_t xReturn;
  881. xReturn = xTaskGenericNotify( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue );
  882. if ( pxHigherPriorityTaskWoken != NULL )
  883. {
  884. *pxHigherPriorityTaskWoken = pdFALSE;
  885. }
  886. return xReturn;
  887. }
  888. #endif /* configUSE_TASK_NOTIFICATIONS */
  889. /*-----------------------------------------------------------*/
  890. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  891. void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  892. UBaseType_t uxIndexToNotify,
  893. BaseType_t * pxHigherPriorityTaskWoken )
  894. {
  895. xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify );
  896. if ( pxHigherPriorityTaskWoken != NULL )
  897. {
  898. *pxHigherPriorityTaskWoken = pdFALSE;
  899. }
  900. }
  901. #endif /* configUSE_TASK_NOTIFICATIONS */
  902. /*-----------------------------------------------------------*/
  903. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  904. BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  905. UBaseType_t uxIndexToClear )
  906. {
  907. TCB_t * pxTCB;
  908. BaseType_t xReturn;
  909. rt_base_t level;
  910. configASSERT( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  911. /* If null is passed in here then it is the calling task that is having
  912. * its notification state cleared. */
  913. pxTCB = prvGetTCBFromHandle( xTask );
  914. level = rt_hw_interrupt_disable();
  915. if( pxTCB->ucNotifyState[ uxIndexToClear ] == taskNOTIFICATION_RECEIVED )
  916. {
  917. pxTCB->ucNotifyState[ uxIndexToClear ] = taskNOT_WAITING_NOTIFICATION;
  918. xReturn = pdPASS;
  919. }
  920. else
  921. {
  922. xReturn = pdFAIL;
  923. }
  924. rt_hw_interrupt_enable( level );
  925. return xReturn;
  926. }
  927. #endif /* configUSE_TASK_NOTIFICATIONS */
  928. /*-----------------------------------------------------------*/
  929. #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  930. uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  931. UBaseType_t uxIndexToClear,
  932. uint32_t ulBitsToClear )
  933. {
  934. TCB_t * pxTCB;
  935. uint32_t ulReturn;
  936. rt_base_t level;
  937. /* If null is passed in here then it is the calling task that is having
  938. * its notification state cleared. */
  939. pxTCB = prvGetTCBFromHandle( xTask );
  940. level = rt_hw_interrupt_disable();
  941. /* Return the notification as it was before the bits were cleared,
  942. * then clear the bit mask. */
  943. ulReturn = pxTCB->ulNotifiedValue[ uxIndexToClear ];
  944. pxTCB->ulNotifiedValue[ uxIndexToClear ] &= ~ulBitsToClear;
  945. rt_hw_interrupt_enable( level );
  946. return ulReturn;
  947. }
  948. #endif /* configUSE_TASK_NOTIFICATIONS */
  949. /*-----------------------------------------------------------*/
  950. #if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
  951. /* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  952. * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  953. * user to determine the return type. It gets around the problem of the value
  954. * overflowing on 8-bit types without breaking backward compatibility for
  955. * applications that expect an 8-bit return type. */
  956. configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )
  957. {
  958. uint32_t ulCount = 0U;
  959. rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTask );
  960. rt_uint8_t * stack_addr = thread->stack_addr;
  961. #ifdef ARCH_CPU_STACK_GROWS_UPWARD
  962. stack_addr = stack_addr + thread->stack_size - 1;
  963. while ( *stack_addr == '#' )
  964. {
  965. ulCount += 1;
  966. stack_addr -= 1;
  967. }
  968. #else
  969. while ( *stack_addr == '#' )
  970. {
  971. ulCount += 1;
  972. stack_addr += 1;
  973. }
  974. #endif
  975. ulCount /= ( uint32_t ) sizeof( StackType_t );
  976. return ( configSTACK_DEPTH_TYPE ) ulCount;
  977. }
  978. #endif /* INCLUDE_uxTaskGetStackHighWaterMark2 */
  979. /*-----------------------------------------------------------*/
  980. #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
  981. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
  982. {
  983. return ( UBaseType_t ) uxTaskGetStackHighWaterMark2( xTask );
  984. }
  985. #endif /* INCLUDE_uxTaskGetStackHighWaterMark */
  986. /*-----------------------------------------------------------*/
  987. #ifdef ESP_PLATFORM
  988. BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
  989. {
  990. ( void ) xTask;
  991. return 0;
  992. }
  993. TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t cpuid )
  994. {
  995. ( void ) cpuid;
  996. return xTaskGetCurrentTaskHandle();
  997. }
  998. TaskHandle_t xTaskGetIdleTaskHandleForCPU( UBaseType_t cpuid )
  999. {
  1000. ( void ) cpuid;
  1001. return xTaskGetIdleTaskHandle();
  1002. }
  1003. #if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 )
  1004. #include "freertos_tasks_c_additions.h"
  1005. #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT
  1006. static void freertos_tasks_c_additions_init( void )
  1007. {
  1008. FREERTOS_TASKS_C_ADDITIONS_INIT();
  1009. }
  1010. #endif
  1011. #endif /* if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) */
  1012. /* Unimplemented */
  1013. #include "esp_log.h"
  1014. static const char *TAG = "freertos";
  1015. #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  1016. void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
  1017. BaseType_t xIndex,
  1018. void * pvValue )
  1019. {
  1020. ESP_LOGE(TAG, "vTaskSetThreadLocalStoragePointer unimplemented");
  1021. configASSERT(0);
  1022. }
  1023. void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
  1024. BaseType_t xIndex )
  1025. {
  1026. ESP_LOGE(TAG, "pvTaskGetThreadLocalStoragePointer unimplemented");
  1027. configASSERT(0);
  1028. return NULL;
  1029. }
  1030. #if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS )
  1031. typedef void (*TlsDeleteCallbackFunction_t)( int, void * );
  1032. void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback)
  1033. {
  1034. ESP_LOGE(TAG, "vTaskSetThreadLocalStoragePointerAndDelCallback unimplemented");
  1035. configASSERT(0);
  1036. }
  1037. #endif
  1038. #endif
  1039. #endif