tasks.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. Base on FreeRTOS V8.2.0
  3. */
  4. /* Standard includes. */
  5. #include <stdlib.h>
  6. #include <string.h>
  7. /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
  8. all the API functions to use the MPU wrappers. That should only be done when
  9. task.h is included from an application file. */
  10. #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
  11. /* FreeRTOS includes. */
  12. #include "FreeRTOS.h"
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include "task.h"
  16. #include "timers.h"
  17. #include "StackMacros.h"
  18. #define _THREAD_TIMESLICE (10u)
  19. /* Lint e961 and e750 are suppressed as a MISRA exception justified because the
  20. MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the
  21. header files above, but not in this file, in order to generate the correct
  22. privileged Vs unprivileged linkage and placement. */
  23. #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */
  24. /* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting
  25. functions but without including stdio.h here. */
  26. #if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 )
  27. /* At the bottom of this file are two optional functions that can be used
  28. to generate human readable text from the raw data generated by the
  29. uxTaskGetSystemState() function. Note the formatting functions are provided
  30. for convenience only, and are NOT considered part of the kernel. */
  31. #include <stdio.h>
  32. #endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */
  33. /* Sanity check the configuration. */
  34. #if configUSE_TICKLESS_IDLE != 0
  35. #if INCLUDE_vTaskSuspend != 1
  36. #error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0
  37. #endif /* INCLUDE_vTaskSuspend */
  38. #endif /* configUSE_TICKLESS_IDLE */
  39. #define MT2625_TASK_DEBUG
  40. #ifdef MT2625_TASK_DEBUG
  41. #define LOG_TAG "TASK"
  42. #define LOG_LVL LOG_LVL_ERROR// LOG_LVL_ERROR | LOG_LVL_DBG
  43. #include <ulog.h>
  44. #else
  45. #define LOG_I(...)
  46. #endif
  47. #define RT_REVERT_PRIORITY 64
  48. /* Value that can be assigned to the eNotifyState member of the TCB. */
  49. typedef enum
  50. {
  51. eNotWaitingNotification = 0,
  52. eWaitingNotification,
  53. eNotified
  54. } eNotifyValue;
  55. /*
  56. * Some kernel aware debuggers require the data the debugger needs access to to
  57. * be global, rather than file scope.
  58. */
  59. #ifdef portREMOVE_STATIC_QUALIFIER
  60. #define static
  61. #endif
  62. /*lint -e956 A manual analysis and inspection has been used to determine which
  63. static variables must be declared volatile. */
  64. // PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;
  65. /* Other file private variables. --------------------------------*/
  66. PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;
  67. #define RTT_USING_CPUID 0
  68. #define portNUM_PROCESSORS 20
  69. PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
  70. portSTACK_TYPE * volatile pxCurrentTCB[ portNUM_PROCESSORS ] = { NULL };
  71. portSTACK_TYPE * volatile pxSaveTCB[ portNUM_PROCESSORS ] = { NULL };
  72. /* File private functions. --------------------------------*/
  73. BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName,
  74. const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority,
  75. TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  76. {
  77. BaseType_t xReturn = pdFAIL;
  78. rt_thread_t tid = RT_NULL;
  79. uint32_t usStackDepthC;
  80. int rt_priority = RT_REVERT_PRIORITY - uxPriority;
  81. configASSERT( pxTaskCode );
  82. usStackDepthC = usStackDepth*sizeof(StackType_t) + 1024U + 512u;
  83. LOG_D("task create - name:%s; stack size:%d; priority:%d; raw:%d", pcName, usStackDepthC, rt_priority, uxPriority);
  84. tid = rt_thread_create((const char *)pcName, pxTaskCode, pvParameters,
  85. (rt_uint32_t)usStackDepthC, (rt_uint8_t)rt_priority, _THREAD_TIMESLICE);
  86. if (tid != RT_NULL)
  87. {
  88. rt_thread_startup(tid);
  89. xReturn = pdPASS;
  90. uxCurrentNumberOfTasks ++;
  91. }
  92. else
  93. {
  94. LOG_E("f:%s;l:%d. thread create failed. task name:%s", __FUNCTION__, __LINE__, pcName);
  95. }
  96. if (pxCreatedTask != RT_NULL)
  97. {
  98. *pxCreatedTask = (TaskHandle_t *)tid;
  99. }
  100. return xReturn;
  101. }
  102. /*-----------------------------------------------------------*/
  103. #if ( INCLUDE_vTaskDelete == 1 )
  104. void vTaskDelete( TaskHandle_t xTaskToDelete )
  105. {
  106. rt_thread_t thread = (rt_thread_t)xTaskToDelete;
  107. if (thread == NULL) thread = rt_thread_self();
  108. LOG_D("f:%s;l:%d. rt_thread_delete.", __FUNCTION__, __LINE__);
  109. rt_thread_delete(thread);
  110. rt_schedule();
  111. }
  112. #endif /* INCLUDE_vTaskDelete */
  113. /*-----------------------------------------------------------*/
  114. #if ( INCLUDE_vTaskDelayUntil == 1 )
  115. void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement )
  116. {
  117. rt_tick_t tick = rt_tick_get();
  118. rt_tick_t tick_to_delay = *pxPreviousWakeTime + xTimeIncrement;
  119. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  120. if ((tick_to_delay - tick) < RT_TICK_MAX / 2)
  121. {
  122. tick = tick_to_delay - tick;
  123. rt_thread_delay(tick);
  124. }
  125. *pxPreviousWakeTime = rt_tick_get();
  126. }
  127. #endif /* INCLUDE_vTaskDelayUntil */
  128. /*-----------------------------------------------------------*/
  129. #if ( INCLUDE_vTaskDelay == 1 )
  130. void vTaskDelay( const TickType_t xTicksToDelay )
  131. {
  132. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  133. rt_thread_delay((rt_tick_t)xTicksToDelay);
  134. }
  135. #endif /* INCLUDE_vTaskDelay */
  136. /*-----------------------------------------------------------*/
  137. #if ( INCLUDE_eTaskGetState == 1 )
  138. eTaskState eTaskGetState( TaskHandle_t xTask )
  139. {
  140. eTaskState eReturn;
  141. rt_uint8_t stat;
  142. rt_thread_t thread = (rt_thread_t)xTask;
  143. if (thread == NULL)
  144. thread = rt_thread_self();
  145. if (thread == NULL)
  146. {
  147. eReturn = eDeleted;
  148. LOG_E("f:%s;l:%d.[ERROR]", __FUNCTION__, __LINE__);
  149. RT_ASSERT(0);
  150. }
  151. // rt_enter_critical();
  152. stat = thread->stat & RT_THREAD_STAT_MASK;
  153. // rt_exit_critical();
  154. LOG_D("f:%s;l:%d. T:%s; State:%d", __FUNCTION__, __LINE__, thread->name, stat);
  155. switch(stat)
  156. {
  157. case RT_THREAD_RUNNING:
  158. eReturn = eRunning;
  159. break;
  160. case RT_THREAD_READY:
  161. eReturn = eReady;
  162. break;
  163. case RT_THREAD_SUSPEND:
  164. eReturn = eSuspended;
  165. break;
  166. case RT_THREAD_CLOSE:
  167. eReturn = eDeleted;
  168. break;
  169. default:
  170. eReturn = 7; /* unknown stat */
  171. LOG_E("error task status!");
  172. break;
  173. }
  174. return eReturn;
  175. } /*lint !e818 xTask cannot be a pointer to const because it is a typedef. */
  176. #endif /* INCLUDE_eTaskGetState */
  177. /*-----------------------------------------------------------*/
  178. #if ( INCLUDE_uxTaskPriorityGet == 1 )
  179. UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask )
  180. {
  181. rt_uint8_t perio;
  182. rt_thread_t thread = (rt_thread_t)xTask;
  183. if (thread == NULL) thread = rt_thread_self();
  184. RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
  185. perio = RT_REVERT_PRIORITY - thread->init_priority;
  186. LOG_D("f:%s;l:%d.pri:%d; thread:%s", __FUNCTION__, __LINE__, perio, thread->name);
  187. return (UBaseType_t)perio;
  188. }
  189. #endif /* INCLUDE_uxTaskPriorityGet */
  190. /*-----------------------------------------------------------*/
  191. #if ( INCLUDE_uxTaskPriorityGet == 1 )
  192. UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask )
  193. {
  194. rt_uint8_t perio;
  195. rt_thread_t thread = (rt_thread_t)xTask;
  196. if (thread == NULL) thread = rt_thread_self();
  197. RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
  198. perio = RT_REVERT_PRIORITY - thread->init_priority;
  199. LOG_D("f:%s;l:%d.pri:%d", __FUNCTION__, __LINE__, perio);
  200. return (UBaseType_t)perio;
  201. }
  202. #endif /* INCLUDE_uxTaskPriorityGet */
  203. /*-----------------------------------------------------------*/
  204. #if ( INCLUDE_vTaskPrioritySet == 1 )
  205. void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority )
  206. {
  207. int rt_priority = RT_REVERT_PRIORITY - uxNewPriority;
  208. rt_thread_t thread = (rt_thread_t)xTask;
  209. RT_ASSERT(uxNewPriority < configMAX_PRIORITIES);
  210. if (thread == NULL) thread = rt_thread_self();
  211. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  212. LOG_D("set priority -> %d", rt_priority);
  213. rt_thread_control(thread, RT_THREAD_CTRL_CHANGE_PRIORITY, &rt_priority);
  214. }
  215. #endif /* INCLUDE_vTaskPrioritySet */
  216. /*-----------------------------------------------------------*/
  217. #if ( INCLUDE_vTaskSuspend == 1 )
  218. void vTaskSuspend( TaskHandle_t xTaskToSuspend )
  219. {
  220. rt_thread_t thread = (rt_thread_t)xTaskToSuspend;
  221. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  222. if (thread == NULL)
  223. thread = rt_thread_self();
  224. rt_thread_suspend(thread);
  225. rt_schedule();
  226. }
  227. #endif /* INCLUDE_vTaskSuspend */
  228. /*-----------------------------------------------------------*/
  229. #if ( INCLUDE_vTaskSuspend == 1 )
  230. void vTaskResume( TaskHandle_t xTaskToResume )
  231. {
  232. rt_thread_t thread = (rt_thread_t)xTaskToResume;
  233. RT_ASSERT(thread != RT_NULL);
  234. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  235. rt_thread_resume(thread);
  236. rt_schedule();
  237. }
  238. #endif /* INCLUDE_vTaskSuspend */
  239. /*-----------------------------------------------------------*/
  240. #if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
  241. BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )
  242. {
  243. rt_thread_t thread = (rt_thread_t)xTaskToResume;
  244. RT_ASSERT(thread != RT_NULL);
  245. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  246. rt_thread_resume(thread);
  247. rt_schedule();
  248. return pdTRUE;
  249. }
  250. #endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */
  251. /*-----------------------------------------------------------*/
  252. void vTaskStartScheduler( void )
  253. {
  254. xSchedulerRunning=pdTRUE;
  255. // LOG_I("f:%s;l:%d.Will start scheduler.", __FUNCTION__, __LINE__);
  256. // xPortStartScheduler();
  257. // rt_system_scheduler_start();
  258. }
  259. /*-----------------------------------------------------------*/
  260. void vTaskSuspendAll( void )
  261. {
  262. LOG_D("f:%s;l:%d.vTaskSuspendAll.", __FUNCTION__, __LINE__);
  263. if( xSchedulerRunning != pdFALSE )
  264. rt_enter_critical();
  265. else
  266. {
  267. LOG_E("f:%s;l:%d.[ERROR].", __FUNCTION__, __LINE__);
  268. }
  269. }
  270. /*----------------------------------------------------------*/
  271. BaseType_t xTaskResumeAll( void )
  272. {
  273. LOG_D("f:%s;l:%d.xTaskResumeAll.", __FUNCTION__, __LINE__);
  274. if( xSchedulerRunning != pdFALSE )
  275. rt_exit_critical();
  276. else
  277. {
  278. LOG_E("f:%s;l:%d.[ERROR].", __FUNCTION__, __LINE__);
  279. }
  280. return pdTRUE;
  281. }
  282. /*-----------------------------------------------------------*/
  283. TickType_t xTaskGetTickCount( void )
  284. {
  285. LOG_D("f:%s;l:%d.xTaskGetTickCount.", __FUNCTION__, __LINE__);
  286. return (TickType_t)rt_tick_get();
  287. }
  288. TickType_t xTaskGetTickCountFromISR( void )
  289. {
  290. LOG_D("f:%s;l:%d.xTaskGetTickCountFromISR.", __FUNCTION__, __LINE__);
  291. return (TickType_t)rt_tick_get();
  292. }
  293. /*-----------------------------------------------------------*/
  294. UBaseType_t uxTaskGetNumberOfTasks( void )
  295. {
  296. struct rt_object_information *information;
  297. UBaseType_t thread_num = 0;
  298. LOG_D("f:%s;l:%d.get_thread_num.", __FUNCTION__, __LINE__);
  299. /* enter critical */
  300. rt_enter_critical();
  301. information = rt_object_get_information(RT_Object_Class_Thread);
  302. if (information)
  303. {
  304. struct rt_list_node *node = RT_NULL;
  305. for (node = information->object_list.next;
  306. node != &(information->object_list);
  307. node = node->next)
  308. {
  309. thread_num ++;
  310. }
  311. }
  312. /* leave critical */
  313. rt_exit_critical();
  314. LOG_D("f:%s;l:%d.thread_num:%d:%d", __FUNCTION__, __LINE__, thread_num, uxCurrentNumberOfTasks);
  315. return thread_num;
  316. }
  317. /*-----------------------------------------------------------*/
  318. #if ( INCLUDE_pcTaskGetTaskName == 1 )
  319. char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  320. {
  321. rt_thread_t thread = (rt_thread_t)(xTaskToQuery);
  322. if (thread == NULL)
  323. thread = rt_thread_self();
  324. if (thread == NULL)
  325. {
  326. LOG_E("f:%s;l:%d.[ERROR]", __FUNCTION__, __LINE__);
  327. RT_ASSERT(0);
  328. }
  329. return thread->name;;
  330. }
  331. #endif /* INCLUDE_pcTaskGetTaskName */
  332. /*-----------------------------------------------------------*/
  333. /* This conditional compilation should use inequality to 0, not equality to 1.
  334. This is to ensure vTaskStepTick() is available when user defined low power mode
  335. implementations require configUSE_TICKLESS_IDLE to be set to a value other than
  336. 1. */
  337. #if ( configUSE_TICKLESS_IDLE != 0 )
  338. /* RT-Thread TODO */
  339. void vTaskStepTick( const TickType_t xTicksToJump )
  340. {
  341. /* Correct the tick count value after a period during which the tick
  342. was suppressed. Note this does *not* call the tick hook function for
  343. each stepped tick. */
  344. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  345. rt_tick_set(rt_tick_get() + xTicksToJump);
  346. }
  347. #endif /* configUSE_TICKLESS_IDLE */
  348. /*----------------------------------------------------------*/
  349. /* RT-Thread TODO */
  350. BaseType_t xTaskIncrementTick( void )
  351. {
  352. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  353. rt_tick_increase();
  354. return pdTRUE;
  355. }
  356. /*-----------------------------------------------------------*/
  357. void vTaskSwitchContext( void )
  358. {
  359. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  360. rt_schedule();
  361. }
  362. /*-----------------------------------------------------------*/
  363. #if configUSE_TICKLESS_IDLE != 0
  364. eSleepModeStatus eTaskConfirmSleepModeStatus( void )
  365. {
  366. /* RT-Thread TODO*/
  367. return eAbortSleep;
  368. }
  369. #endif /* configUSE_TICKLESS_IDLE */
  370. /*-----------------------------------------------------------*/
  371. #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
  372. UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
  373. {
  374. rt_ubase_t free_space = 0;
  375. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  376. rt_thread_t thread = (rt_thread_t)xTask;
  377. if (thread == NULL)
  378. thread = rt_thread_self();
  379. if (thread == NULL)
  380. {
  381. LOG_E("f:%s;l:%d.", __FUNCTION__, __LINE__);
  382. RT_ASSERT(0);
  383. }
  384. {
  385. rt_uint8_t *ptr;
  386. #if defined(ARCH_CPU_STACK_GROWS_UPWARD)
  387. ptr = (rt_uint8_t *)thread->stack_addr + thread->stack_size - 1;
  388. while (*ptr == '#')ptr --;
  389. free_space = thread->stack_size - (rt_ubase_t)ptr + (rt_ubase_t)thread->stack_addr;
  390. #else
  391. ptr = (rt_uint8_t *)thread->stack_addr;
  392. while (*ptr == '#')ptr ++;
  393. free_space = (rt_ubase_t) ptr + (rt_ubase_t) thread->stack_addr;
  394. goto __continue;
  395. #endif
  396. }
  397. __continue:
  398. free_space /= ( uint32_t ) sizeof( StackType_t );
  399. LOG_D("f:%s;l:%d; free_space:%d", __FUNCTION__, __LINE__, free_space);
  400. return free_space;
  401. }
  402. #endif /* INCLUDE_uxTaskGetStackHighWaterMark */
  403. /*-----------------------------------------------------------*/
  404. #if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )
  405. TaskHandle_t xTaskGetCurrentTaskHandle( void )
  406. {
  407. // LOG_I("f:%s;l:%d.", __FUNCTION__, __LINE__);
  408. // LOG_I("xTaskGetCurrentTaskHandle, current Task: %*.s", RT_NAME_MAX, rt_thread_self()->name);
  409. return rt_thread_self();
  410. }
  411. #endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */
  412. /*-----------------------------------------------------------*/
  413. #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
  414. /* TODO: temporary placed here */
  415. #include <stdbool.h>
  416. bool is_in_exception(void)
  417. {
  418. extern bool IsSystemEnterException;
  419. return IsSystemEnterException;
  420. }
  421. BaseType_t xTaskGetSchedulerState( void )
  422. {
  423. BaseType_t xReturn = taskSCHEDULER_NOT_STARTED;
  424. extern bool is_in_exception(void);
  425. if (is_in_exception() == true)
  426. {
  427. return xReturn;
  428. }
  429. if( xSchedulerRunning != pdFALSE )
  430. {
  431. if (rt_critical_level() == 0)
  432. {
  433. xReturn = taskSCHEDULER_RUNNING;
  434. }
  435. else
  436. {
  437. xReturn = taskSCHEDULER_SUSPENDED;
  438. }
  439. }
  440. return xReturn;
  441. }
  442. #endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */
  443. /*-----------------------------------------------------------*/
  444. #if ( portCRITICAL_NESTING_IN_TCB == 1 )
  445. void vTaskEnterCritical( void ) /* Not run */
  446. {
  447. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  448. vPortCPUAcquireMutex( mux );
  449. if( xSchedulerRunning != pdFALSE )
  450. rt_enter_critical();
  451. }
  452. #endif /* portCRITICAL_NESTING_IN_TCB */
  453. /*-----------------------------------------------------------*/
  454. #if ( portCRITICAL_NESTING_IN_TCB == 1 )
  455. void vTaskExitCritical( void )
  456. {
  457. LOG_D("f:%s;l:%d.", __FUNCTION__, __LINE__);
  458. vPortCPUReleaseMutex( mux );
  459. if( xSchedulerRunning != pdFALSE )
  460. rt_exit_critical();
  461. }
  462. #endif /* portCRITICAL_NESTING_IN_TCB */
  463. /*-----------------------------------------------------------*/
  464. #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
  465. void vTaskList( char * pcWriteBuffer )
  466. {
  467. /* RT-Thread TODO */
  468. #warning "TODO"
  469. // int32_t buf_size = uxTaskGetNumberOfTasks() * (configMAX_TASK_NAME_LEN + 18);
  470. LOG_E("f:%s;l:%d.", __FUNCTION__, __LINE__);
  471. /* Make sure the write buffer does not contain a string. */
  472. *pcWriteBuffer = 0x00;
  473. // rt_strncpy(pcWriteBuffer, "RT-Thread TODO", buf_size);
  474. // pcWriteBuffer[buf_size - 1] = 0x00;
  475. }
  476. #endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */
  477. /*----------------------------------------------------------*/
  478. #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
  479. void vTaskGetRunTimeStats( char *pcWriteBuffer )
  480. {
  481. /* RT-Thread TODO */
  482. #warning "TODO"
  483. // int32_t buf_size = uxTaskGetNumberOfTasks() * (configMAX_TASK_NAME_LEN + 20);
  484. LOG_E("f:%s;l:%d.", __FUNCTION__, __LINE__);
  485. /* Make sure the write buffer does not contain a string. */
  486. *pcWriteBuffer = 0x00;
  487. // rt_strncpy(pcWriteBuffer, "RT-Thread TODO", buf_size);
  488. // pcWriteBuffer[buf_size - 1] = 0x00;
  489. }
  490. #endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */
  491. /*-----------------------------------------------------------*/
  492. #if ( configGENERATE_RUN_TIME_STATS == 1 )
  493. void vTaskClearTaskRunTimeCounter( void )
  494. {
  495. #warning "TODO"
  496. /* RT-Thread TODO */
  497. LOG_E("f:%s;l:%d.", __FUNCTION__, __LINE__);
  498. }
  499. #endif /* configGENERATE_RUN_TIME_STATS */
  500. UBaseType_t uxTaskGetBottomOfStack(TaskHandle_t xTaskHandle)
  501. {
  502. rt_ubase_t stack_end_p = 0;
  503. rt_thread_t thread = (rt_thread_t)xTaskHandle;
  504. if (thread == NULL) thread = rt_thread_self();
  505. #if defined(ARCH_CPU_STACK_GROWS_UPWARD)
  506. stack_end_p = (rt_ubase_t)((rt_uint8_t *)thread->stack_addr + thread->stack_size - 1);
  507. #else
  508. stack_end_p = (rt_ubase_t)(thread->stack_addr);
  509. #endif
  510. LOG_D("f:%s;l:%d; stack_end_p:%p", __FUNCTION__, __LINE__, stack_end_p);
  511. return stack_end_p;
  512. }
  513. void *uxTaskGetEventListItemContainer(TaskHandle_t xTaskHandle) /* TODO */
  514. {
  515. #if 0
  516. TCB_t *pxTCB;
  517. pxTCB = ( xTaskHandle == NULL )? ( TCB_t * ) pxCurrentTCB : ( TCB_t * ) ( xTaskHandle );
  518. return ( pxTCB->xEventListItem.pvContainer );
  519. #else
  520. // rt_thread_t thread;
  521. LOG_E("f:%s;l:%d.", __FUNCTION__, __LINE__);
  522. return NULL;
  523. #endif
  524. }
  525. /*-----------------------------------------------------------*/