Hi,
We are using the watchdog of MQX 4.2 to detect crashes or halted tasks but I would like to know what information is available when the watchdog error function is called.
We are creating the watchdog using
if(_watchdog_create_component(BSP_TIMER_INTERRUPT_VECTOR, handle_watchdog_expiry) != MQX_OK)
{
printf("\nError creating watchdog component.");
_task_block();
}
where handle_watchdog_expiry is defined as
void handle_watchdog_expiry(void* td_ptr)
{
printf("Expired task 0x%P\n\r", td_ptr);
// Trig the hardware WDT
while(1);
}
The declaration follows the function pointer type definition
typedef void (_CODE_PTR_ WATCHDOG_ERROR_FPTR)(void *);
used in
extern _mqx_uint _watchdog_create_component(_mqx_uint, WATCHDOG_ERROR_FPTR);
When I print the parameter given as a void pointer, I cannot find anything into the code to match the task to.
Is it possible to cast the void pointer into some struct from which useful information could be obtained?
If not, how can I use the pointer to match to a task?
Thanks
Solved! Go to Solution.
Hi Rudy
MQX watchdog component provides a software watchdog for each task. If a single task starves or runs beyond certain timing constraints, the watchdong provides a way to detect the problem. Initially, the task starts its watchdog with a specific time value, and if the task fails to stop or restart the watchdog before that time expires, MQX calls a processor-unique, application-supplied expiry function that can initiate error recovery.
From the td_ptr, it is a pointer to the task descriptor of the task, it contains various information about the state of the task.
typedef struct td_struct
{
/*!
* \brief A pointer to the next TD in the queue (for whatever queue this
* task is currently in).
*
* This field MUST be the first field in the TD.
*/
struct td_struct *TD_NEXT;
/*!
* \brief A pointer to the previous TD in the queue (for whatever queue this
* task is currently in).
*/
struct td_struct *TD_PREV;
/*! \brief The current state that this task is in. */
_mqx_uint STATE;
/*! \brief The Task id of the task that this task descriptor represents. */
_task_id TASK_ID;
/*! \brief The Start of the Stack. */
void *STACK_BASE;
/*!
* \brief If the task is blocked, then this is a pointer to the task's current
* stack value, otherwise it is a pointer to the task's stack at the time of
* the last block.
*/
void *STACK_PTR;
/*! \brief The other end of the Stack. */
void *STACK_LIMIT;
/*! \brief The Ready Queue upon which to place the task, when it is ready to run. */
struct ready_q_struct *MY_QUEUE;
...
...
}
you can get task id by this function
_task_id _task_get_id_from_td(void * td_ptr);
Regards
Daniel
Hi Rudy
MQX watchdog component provides a software watchdog for each task. If a single task starves or runs beyond certain timing constraints, the watchdong provides a way to detect the problem. Initially, the task starts its watchdog with a specific time value, and if the task fails to stop or restart the watchdog before that time expires, MQX calls a processor-unique, application-supplied expiry function that can initiate error recovery.
From the td_ptr, it is a pointer to the task descriptor of the task, it contains various information about the state of the task.
typedef struct td_struct
{
/*!
* \brief A pointer to the next TD in the queue (for whatever queue this
* task is currently in).
*
* This field MUST be the first field in the TD.
*/
struct td_struct *TD_NEXT;
/*!
* \brief A pointer to the previous TD in the queue (for whatever queue this
* task is currently in).
*/
struct td_struct *TD_PREV;
/*! \brief The current state that this task is in. */
_mqx_uint STATE;
/*! \brief The Task id of the task that this task descriptor represents. */
_task_id TASK_ID;
/*! \brief The Start of the Stack. */
void *STACK_BASE;
/*!
* \brief If the task is blocked, then this is a pointer to the task's current
* stack value, otherwise it is a pointer to the task's stack at the time of
* the last block.
*/
void *STACK_PTR;
/*! \brief The other end of the Stack. */
void *STACK_LIMIT;
/*! \brief The Ready Queue upon which to place the task, when it is ready to run. */
struct ready_q_struct *MY_QUEUE;
...
...
}
you can get task id by this function
_task_id _task_get_id_from_td(void * td_ptr);
Regards
Daniel
You are welcome and thank you for your update.
Regards
Daniel