36 #include <px4_platform_common/log.h> 38 #if defined(__PX4_NUTTX) && !defined(CONFIG_SCHED_INSTRUMENTATION) 39 # error watchdog support requires CONFIG_SCHED_INSTRUMENTATION 54 if (
system_load.initialized && watchdog_data.logger_main_task_index >= 0
55 && watchdog_data.logger_writer_task_index >= 0) {
57 const system_load_taskinfo_s &log_writer_task =
system_load.tasks[watchdog_data.logger_writer_task_index];
59 if (log_writer_task.valid) {
69 if (log_writer_task.curr_start_time > watchdog_data.ready_to_run_timestamp) {
70 watchdog_data.ready_to_run_timestamp = log_writer_task.curr_start_time;
74 uint8_t current_state = log_writer_task.tcb->task_state;
76 if (current_state != TSTATE_TASK_READYTORUN
77 || (watchdog_data.last_state != TSTATE_TASK_READYTORUN && current_state == TSTATE_TASK_READYTORUN)) {
78 watchdog_data.ready_to_run_timestamp = now;
81 watchdog_data.last_state = current_state;
83 #if 0 // for debugging 87 static uint64_t max_time = 0;
89 if (now - watchdog_data.ready_to_run_timestamp > max_time) {
90 max_time = now - watchdog_data.ready_to_run_timestamp;
95 if (++counter > 300) {
96 PX4_ERR(
"max time in ready: %i ms", (
int)max_time / 1000);
103 if (now - watchdog_data.ready_to_run_timestamp > 1_s) {
109 param.sched_priority = SCHED_PRIORITY_MAX;
111 if (
system_load.tasks[watchdog_data.logger_main_task_index].valid) {
112 sched_setparam(
system_load.tasks[watchdog_data.logger_main_task_index].tcb->pid, ¶m);
115 sched_setparam(log_writer_task.tcb->pid, ¶m);
118 watchdog_data.logger_main_task_index = -1;
124 watchdog_data.logger_main_task_index = -1;
139 const pthread_t pid_logger_writer = writer_thread;
145 if (
system_load.tasks[i].tcb->pid == pid_logger_writer) {
146 watchdog_data.logger_writer_task_index = i;
149 if (
system_load.tasks[i].tcb->pid == pid_logger_main) {
150 watchdog_data.logger_main_task_index = i;
157 if (watchdog_data.logger_writer_task_index == -1 ||
158 watchdog_data.logger_main_task_index == -1) {
161 PX4_ERR(
"watchdog init failed");
void watchdog_initialize(const pid_t pid_logger_main, const pthread_t writer_thread, watchdog_data_t &watchdog_data)
Initialize the watchdog, fill in watchdog_data.
bool watchdog_update(watchdog_data_t &watchdog_data)
Update the watchdog and trigger it if necessary.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
struct system_load_s system_load
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).