task_snapshot.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "sdkconfig.h"
  8. #include "freertos/FreeRTOS.h"
  9. #include "freertos/task.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #if CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT || defined __DOXYGEN__
  14. /**
  15. * @brief Task Snapshot structure
  16. *
  17. * - Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
  18. * - We need this structure because TCB_t is defined (hidden) in tasks.c.
  19. */
  20. typedef struct xTASK_SNAPSHOT
  21. {
  22. void *pxTCB; /*!< Address of the task control block. */
  23. StackType_t *pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */
  24. StackType_t *pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
  25. pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
  26. } TaskSnapshot_t;
  27. /**
  28. * @brief Iterate over all tasks in the system
  29. *
  30. * - This function can be used to iterate over every task in the system
  31. * - The first call to this function must set pxTask to NULL
  32. * - When all functions have been iterated, this function will return NULL.
  33. * - This function is only available when CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is set to 1.
  34. *
  35. * @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
  36. * does not acquire any locks.
  37. * @param pxTask Handle of the previous task (or NULL on the first call of this function)
  38. * @return TaskHandle_t Handle of the next task (or NULL when all tasks have been iterated over)
  39. */
  40. TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask );
  41. /**
  42. * @brief Fill a TaskSnapshot_t structure for specified task.
  43. *
  44. * - This function is used by the panic handler to get the snapshot of a particular task.
  45. * - This function is only available when CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is set to 1.
  46. *
  47. * @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
  48. * does not acquire any locks.
  49. * @param[in] pxTask Task's handle
  50. * @param[out] pxTaskSnapshot Snapshot of the task
  51. * @return pdTRUE if operation was successful else pdFALSE
  52. */
  53. BaseType_t vTaskGetSnapshot( TaskHandle_t pxTask, TaskSnapshot_t *pxTaskSnapshot );
  54. /**
  55. * @brief Fill an array of TaskSnapshot_t structures for every task in the system
  56. *
  57. * - This function is used by the panic handler to get a snapshot of all tasks in the system
  58. * - This function is only available when CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is set to 1.
  59. *
  60. * @note This function should only be called when FreeRTOS is no longer running (e.g., during a panic) as this function
  61. * does not acquire any locks.
  62. * @param[out] pxTaskSnapshotArray Array of TaskSnapshot_t structures filled by this function
  63. * @param[in] uxArrayLength Length of the provided array
  64. * @param[out] pxTCBSize Size of the a task's TCB structure
  65. * @return UBaseType_t
  66. */
  67. UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArrayLength, UBaseType_t * const pxTCBSize );
  68. #endif // CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT || defined __DOXYGEN__
  69. #ifdef __cplusplus
  70. }
  71. #endif