tasks.c 41 KB

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