int wd_gettime(WDOG_ID wdog) { irqstate_t flags; /* Verify the wdog */ flags = irqsave(); if (wdog && WDOG_ISACTIVE(wdog)) { /* Traverse the watchdog list accumulating lag times until we find the wdog * that we are looking for */ FAR struct wdog_s *curr; int delay = 0; for (curr = (FAR struct wdog_s *)g_wdactivelist.head; curr; curr = curr->next) { delay += curr->lag; if (curr == wdog) { irqrestore(flags); return delay; } } } irqrestore(flags); return 0; }
int wd_delete(WDOG_ID wdog) { irqstate_t state; DEBUGASSERT(wdog); /* The following steps are atomic... the watchdog must not be active when * it is being deallocated. */ state = irqsave(); /* Check if the watchdog has been started. */ if (WDOG_ISACTIVE(wdog)) { /* Yes.. stop it */ wd_cancel(wdog); } /* Did this watchdog come from the pool of pre-allocated timers? Or, was * it allocated from the heap? */ if (WDOG_ISALLOCED(wdog)) { /* It was allocated from the heap. Use sched_kfree() to release the * memory. If the timer was released from an interrupt handler, * sched_kfree() will defer the actual deallocation of the memory * until a more appropriate time. * * We don't need interrupts disabled to do this. */ irqrestore(state); sched_kfree(wdog); } /* This was a pre-allocated timer. This function should not be called for * statically allocated timers. */ else if (!WDOG_ISSTATIC(wdog)) { /* Put the timer back on the free list and increment the count of free * timers, all with interrupts disabled. */ sq_addlast((FAR sq_entry_t *)wdog, &g_wdfreelist); g_wdnfree++; DEBUGASSERT(g_wdnfree <= CONFIG_PREALLOC_WDOGS); irqrestore(state); } /* Return success */ return OK; }