From e694009e2a37f4a77770c8b9dde2e0a9e9a42570 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 22 Aug 2014 08:46:34 -0600 Subject: Add support for statically allocated watchdog timer structures --- nuttx/sched/wdog/wd_cancel.c | 14 +++++------ nuttx/sched/wdog/wd_create.c | 6 ++--- nuttx/sched/wdog/wd_delete.c | 6 +++-- nuttx/sched/wdog/wd_gettime.c | 4 ++-- nuttx/sched/wdog/wd_initialize.c | 4 ++-- nuttx/sched/wdog/wd_start.c | 44 +++++++++++++++++----------------- nuttx/sched/wdog/wdog.h | 52 ---------------------------------------- 7 files changed, 40 insertions(+), 90 deletions(-) (limited to 'nuttx/sched/wdog') diff --git a/nuttx/sched/wdog/wd_cancel.c b/nuttx/sched/wdog/wd_cancel.c index 9749eccb6..1a53801d4 100644 --- a/nuttx/sched/wdog/wd_cancel.c +++ b/nuttx/sched/wdog/wd_cancel.c @@ -91,16 +91,16 @@ int wd_cancel(WDOG_ID wdog) { - wdog_t *curr; - wdog_t *prev; - irqstate_t saved_state; - int ret = ERROR; + FAR struct wdog_s *curr; + FAR struct wdog_s *prev; + irqstate_t state; + int ret = ERROR; /* Prohibit timer interactions with the timer queue until the * cancellation is complete */ - saved_state = irqsave(); + state = irqsave(); /* Make sure that the watchdog is initialized (non-NULL) and is still * active. @@ -114,7 +114,7 @@ int wd_cancel(WDOG_ID wdog) */ prev = NULL; - curr = (wdog_t*)g_wdactivelist.head; + curr = (FAR struct wdog_s *)g_wdactivelist.head; while ((curr) && (curr != wdog)) { @@ -168,6 +168,6 @@ int wd_cancel(WDOG_ID wdog) ret = OK; } - irqrestore(saved_state); + irqrestore(state); return ret; } diff --git a/nuttx/sched/wdog/wd_create.c b/nuttx/sched/wdog/wd_create.c index 2e71ceac7..ce1ca56ed 100644 --- a/nuttx/sched/wdog/wd_create.c +++ b/nuttx/sched/wdog/wd_create.c @@ -92,7 +92,7 @@ WDOG_ID wd_create (void) { - FAR wdog_t *wdog; + FAR struct wdog_s *wdog; irqstate_t state; /* These actions must be atomic with respect to other tasks and also with @@ -113,7 +113,7 @@ WDOG_ID wd_create (void) * count of free timers all with interrupts disabled. */ - wdog = (FAR wdog_t*)sq_remfirst(&g_wdfreelist); + wdog = (FAR struct wdog_s *)sq_remfirst(&g_wdfreelist); DEBUGASSERT(g_wdnfree > 0); g_wdnfree--; irqrestore(state); @@ -139,7 +139,7 @@ WDOG_ID wd_create (void) /* We do not require that interrupts be disabled to do this. */ irqrestore(state); - wdog = (FAR wdog_t *)kmalloc(sizeof(wdog_t)); + wdog = (FAR struct wdog_s *)kmalloc(sizeof(struct wdog_s)); /* Did we get one? */ diff --git a/nuttx/sched/wdog/wd_delete.c b/nuttx/sched/wdog/wd_delete.c index b13ed427e..2bd16fe48 100644 --- a/nuttx/sched/wdog/wd_delete.c +++ b/nuttx/sched/wdog/wd_delete.c @@ -132,9 +132,11 @@ int wd_delete(WDOG_ID wdog) sched_kfree(wdog); } - /* This was a pre-allocated timer. */ + /* This was a pre-allocated timer. This function should not be called for + * statically allocated timers. + */ - else + else if (!WDOG_ISSTATIC(wdog)) { /* Put the timer back on the free list and increment the count of free * timers, all with interrupts disabled. diff --git a/nuttx/sched/wdog/wd_gettime.c b/nuttx/sched/wdog/wd_gettime.c index e9d85d077..52547d985 100644 --- a/nuttx/sched/wdog/wd_gettime.c +++ b/nuttx/sched/wdog/wd_gettime.c @@ -98,10 +98,10 @@ int wd_gettime(WDOG_ID wdog) * that we are looking for */ - wdog_t *curr; + FAR struct wdog_s *curr; int delay = 0; - for (curr = (wdog_t*)g_wdactivelist.head; curr; curr = curr->next) + for (curr = (FAR struct wdog_s *)g_wdactivelist.head; curr; curr = curr->next) { delay += curr->lag; if (curr == wdog) diff --git a/nuttx/sched/wdog/wd_initialize.c b/nuttx/sched/wdog/wd_initialize.c index eba4ebacd..23242b6bf 100644 --- a/nuttx/sched/wdog/wd_initialize.c +++ b/nuttx/sched/wdog/wd_initialize.c @@ -83,7 +83,7 @@ uint16_t g_wdnfree; * in the pool is a configuration item. */ -static FAR wdog_t g_wdpool[CONFIG_PREALLOC_WDOGS]; +static struct wdog_s g_wdpool[CONFIG_PREALLOC_WDOGS]; /************************************************************************ * Private Functions @@ -114,7 +114,7 @@ static FAR wdog_t g_wdpool[CONFIG_PREALLOC_WDOGS]; void wd_initialize(void) { - FAR wdog_t *wdog = g_wdpool; + FAR struct wdog_s *wdog = g_wdpool; int i; /* Initialize watchdog lists */ diff --git a/nuttx/sched/wdog/wd_start.c b/nuttx/sched/wdog/wd_start.c index 608b1445c..25d829409 100644 --- a/nuttx/sched/wdog/wd_start.c +++ b/nuttx/sched/wdog/wd_start.c @@ -115,22 +115,22 @@ typedef void (*wdentry4_t)(int argc, uint32_t arg1, uint32_t arg2, static inline void wd_expiration(void) { - FAR wdog_t *wdog; + FAR struct wdog_s *wdog; /* Check if the watchdog at the head of the list is ready to run */ - if (((FAR wdog_t*)g_wdactivelist.head)->lag <= 0) + if (((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0) { /* Process the watchdog at the head of the list as well as any * other watchdogs that became ready to run at this time */ while (g_wdactivelist.head && - ((FAR wdog_t*)g_wdactivelist.head)->lag <= 0) + ((FAR struct wdog_s *)g_wdactivelist.head)->lag <= 0) { /* Remove the watchdog from the head of the list */ - wdog = (FAR wdog_t*)sq_remfirst(&g_wdactivelist); + wdog = (FAR struct wdog_s *)sq_remfirst(&g_wdactivelist); /* If there is another watchdog behind this one, update its * its lag (this shouldn't be necessary). @@ -138,7 +138,7 @@ static inline void wd_expiration(void) if (g_wdactivelist.head) { - ((FAR wdog_t*)g_wdactivelist.head)->lag += wdog->lag; + ((FAR struct wdog_s *)g_wdactivelist.head)->lag += wdog->lag; } /* Indicate that the watchdog is no longer active. */ @@ -227,13 +227,13 @@ static inline void wd_expiration(void) int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) { - va_list ap; - FAR wdog_t *curr; - FAR wdog_t *prev; - FAR wdog_t *next; - int32_t now; - irqstate_t saved_state; - int i; + va_list ap; + FAR struct wdog_s *curr; + FAR struct wdog_s *prev; + FAR struct wdog_s *next; + int32_t now; + irqstate_t state; + int i; /* Verify the wdog */ @@ -249,7 +249,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) * the critical section is established. */ - saved_state = irqsave(); + state = irqsave(); if (WDOG_ISACTIVE(wdog)) { wd_cancel(wdog); @@ -309,7 +309,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) else { now = 0; - prev = curr = (FAR wdog_t*)g_wdactivelist.head; + prev = curr = (FAR struct wdog_s *)g_wdactivelist.head; /* Advance to positive time */ @@ -342,17 +342,17 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) /* Insert the new watchdog in the list */ - if (curr == (FAR wdog_t*)g_wdactivelist.head) + if (curr == (FAR struct wdog_s *)g_wdactivelist.head) { /* Insert the watchdog at the head of the list */ - sq_addfirst((FAR sq_entry_t*)wdog, &g_wdactivelist); + sq_addfirst((FAR sq_entry_t *)wdog, &g_wdactivelist); } else { /* Insert the watchdog in mid- or end-of-queue */ - sq_addafter((FAR sq_entry_t*)prev, (FAR sq_entry_t*)wdog, + sq_addafter((FAR sq_entry_t *)prev, (FAR sq_entry_t *)wdog, &g_wdactivelist); } @@ -394,7 +394,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) sched_timer_resume(); #endif - irqrestore(saved_state); + irqrestore(state); return OK; } @@ -426,7 +426,7 @@ int wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry, int argc, ...) #ifdef CONFIG_SCHED_TICKLESS unsigned int wd_timer(int ticks) { - FAR wdog_t *wdog; + FAR struct wdog_s *wdog; int decr; /* Check if there are any active watchdogs to process */ @@ -435,7 +435,7 @@ unsigned int wd_timer(int ticks) { /* Get the watchdog at the head of the list */ - wdog = (FAR wdog_t*)g_wdactivelist.head; + wdog = (FAR struct wdog_s *)g_wdactivelist.head; #ifndef CONFIG_SCHED_TICKLESS_ALARM /* There is logic to handle the case where ticks is greater than @@ -462,7 +462,7 @@ unsigned int wd_timer(int ticks) /* Return the delay for the next watchdog to expire */ return g_wdactivelist.head ? - ((FAR wdog_t*)g_wdactivelist.head)->lag : 0; + ((FAR struct wdog_s *)g_wdactivelist.head)->lag : 0; } #else @@ -474,7 +474,7 @@ void wd_timer(void) { /* There are. Decrement the lag counter */ - --(((FAR wdog_t*)g_wdactivelist.head)->lag); + --(((FAR struct wdog_s *)g_wdactivelist.head)->lag); /* Check if the watchdog at the head of the list is ready to run */ diff --git a/nuttx/sched/wdog/wdog.h b/nuttx/sched/wdog/wdog.h index 63d0d1584..6ee640867 100644 --- a/nuttx/sched/wdog/wdog.h +++ b/nuttx/sched/wdog/wdog.h @@ -51,63 +51,11 @@ /************************************************************************ * Pre-processor Definitions ************************************************************************/ -/* Configuration ********************************************************/ - -#ifndef CONFIG_PREALLOC_WDOGS -# define CONFIG_PREALLOC_WDOGS 32 -#endif - -#ifndef CONFIG_WDOG_INTRESERVE -# if CONFIG_PREALLOC_WDOGS > 16 -# define CONFIG_WDOG_INTRESERVE 4 -# elif CONFIG_PREALLOC_WDOGS > 8 -# define CONFIG_WDOG_INTRESERVE 2 -# else -# define CONFIG_WDOG_INTRESERVE 1 -# endif -#endif - -#if CONFIG_WDOG_INTRESERVE >= CONFIG_PREALLOC_WDOGS -# error CONFIG_WDOG_INTRESERVE >= CONFIG_PREALLOC_WDOGS -#endif - -/* Watchdog Definitions *************************************************/ -/* Flag bits for the flags field of struct wdog_s */ - -#define WDOGF_ACTIVE (1 << 0) /* Watchdog is actively timing */ -#define WDOGF_ALLOCED (1 << 1) /* 0:Pre-allocated, 1:Allocated */ - -#define WDOG_SETACTIVE(w) do { (w)->flags |= WDOGF_ACTIVE; } while (0) -#define WDOG_SETALLOCED(w) do { (w)->flags |= WDOGF_ALLOCED; } while (0) - -#define WDOG_CLRACTIVE(w) do { (w)->flags &= ~WDOGF_ACTIVE; } while (0) -#define WDOG_CLRALLOCED(w) do { (w)->flags &= ~WDOGF_ALLOCED; } while (0) - -#define WDOG_ISACTIVE(w) (((w)->flags & WDOGF_ACTIVE) != 0) -#define WDOG_ISALLOCED(w) (((w)->flags & WDOGF_ALLOCED) != 0) /************************************************************************ * Public Type Declarations ************************************************************************/ -/* This is the watchdog structure. The WDOG_ID is a pointer to a - * watchdog structure. - */ - -struct wdog_s -{ - FAR struct wdog_s *next; /* Support for singly linked lists. */ - wdentry_t func; /* Function to execute when delay expires */ -#ifdef CONFIG_PIC - FAR void *picbase; /* PIC base address */ -#endif - int lag; /* Timer associated with the delay */ - uint8_t flags; /* See WDOGF_* definitions above */ - uint8_t argc; /* The number of parameters to pass */ - uint32_t parm[CONFIG_MAX_WDOGPARMS]; -}; -typedef struct wdog_s wdog_t; - /************************************************************************ * Public Variables ************************************************************************/ -- cgit v1.2.3