From 03b382d443ff97c3bdbc203ff1cfd76b69e4ebce Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Feb 2016 10:22:11 -0600 Subject: [PATCH] SAM3/4, SAMA5, SAMv7 Tickless: Refuse to call lower-level timer logic if not yet initialized --- arch/arm/src/sam34/sam4cm_freerun.h | 6 ++++++ arch/arm/src/sam34/sam4cm_oneshot.h | 6 ++++++ arch/arm/src/sam34/sam4cm_tickless.c | 17 ++++++++++++++--- arch/arm/src/sama5/sam_freerun.h | 2 ++ arch/arm/src/sama5/sam_oneshot.h | 2 ++ arch/arm/src/sama5/sam_tickless.c | 17 ++++++++++++++--- arch/arm/src/samv7/sam_freerun.h | 2 ++ arch/arm/src/samv7/sam_oneshot.h | 2 ++ arch/arm/src/samv7/sam_tickless.c | 17 ++++++++++++++--- 9 files changed, 62 insertions(+), 9 deletions(-) diff --git a/arch/arm/src/sam34/sam4cm_freerun.h b/arch/arm/src/sam34/sam4cm_freerun.h index da4d56a843..e9266c2195 100644 --- a/arch/arm/src/sam34/sam4cm_freerun.h +++ b/arch/arm/src/sam34/sam4cm_freerun.h @@ -49,6 +49,12 @@ #ifdef CONFIG_SAM34_FREERUN +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define FREERUN_INITIALIZED(s) (((s)->tch) != NULL) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/arm/src/sam34/sam4cm_oneshot.h b/arch/arm/src/sam34/sam4cm_oneshot.h index 78a44d99cb..3c3266b5db 100644 --- a/arch/arm/src/sam34/sam4cm_oneshot.h +++ b/arch/arm/src/sam34/sam4cm_oneshot.h @@ -49,6 +49,12 @@ #ifdef CONFIG_SAM34_ONESHOT +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ONESHOT_INITIALIZED(s) (((s)->tch) != NULL) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/arm/src/sam34/sam4cm_tickless.c b/arch/arm/src/sam34/sam4cm_tickless.c index 48d9a37329..0495241331 100644 --- a/arch/arm/src/sam34/sam4cm_tickless.c +++ b/arch/arm/src/sam34/sam4cm_tickless.c @@ -84,6 +84,7 @@ #include #include +#include #include @@ -247,6 +248,8 @@ void up_timer_initialize(void) PANIC(); } + DEBUGASSERT(ONESHOT_INITIALIZED(&g_tickless.oneshot)); + #ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP /* Get the maximum delay of the one-shot timer in microseconds */ @@ -280,6 +283,8 @@ void up_timer_initialize(void) tclldbg("ERROR: sam_freerun_initialize failed\n"); PANIC(); } + + DEBUGASSERT(FREERUN_INITIALIZED(&g_tickless.freerun)); } /**************************************************************************** @@ -317,7 +322,9 @@ void up_timer_initialize(void) int up_timer_gettime(FAR struct timespec *ts) { - return sam_freerun_counter(&g_tickless.freerun, ts); + return FREERUN_INITIALIZED(&g_tickless.freerun) ? + sam_freerun_counter(&g_tickless.freerun, ts) : + -EAGAIN; } /**************************************************************************** @@ -358,7 +365,9 @@ int up_timer_gettime(FAR struct timespec *ts) int up_timer_cancel(FAR struct timespec *ts) { - return sam_oneshot_cancel(&g_tickless.oneshot, ts); + return ONESHOT_INITIALIZED(&g_tickless.oneshot) ? + sam_oneshot_cancel(&g_tickless.oneshot, ts) : + -EAGAIN; } /**************************************************************************** @@ -388,6 +397,8 @@ int up_timer_cancel(FAR struct timespec *ts) int up_timer_start(FAR const struct timespec *ts) { - return sam_oneshot_start(&g_tickless.oneshot, sam_oneshot_handler, NULL, ts); + return ONESHOT_INITIALIZED(&g_tickless.oneshot) ? + sam_oneshot_start(&g_tickless.oneshot, sam_oneshot_handler, NULL, ts) : + -EAGAIN; } #endif /* CONFIG_SCHED_TICKLESS */ diff --git a/arch/arm/src/sama5/sam_freerun.h b/arch/arm/src/sama5/sam_freerun.h index ce4e783409..22ef8194a8 100644 --- a/arch/arm/src/sama5/sam_freerun.h +++ b/arch/arm/src/sama5/sam_freerun.h @@ -53,6 +53,8 @@ * Pre-processor Definitions ****************************************************************************/ +#define FREERUN_INITIALIZED(s) (((s)->tch) != NULL) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/arm/src/sama5/sam_oneshot.h b/arch/arm/src/sama5/sam_oneshot.h index 5ed433788a..4fefe9fe11 100644 --- a/arch/arm/src/sama5/sam_oneshot.h +++ b/arch/arm/src/sama5/sam_oneshot.h @@ -53,6 +53,8 @@ * Pre-processor Definitions ****************************************************************************/ +#define ONESHOT_INITIALIZED(s) (((s)->tch) != NULL) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/arm/src/sama5/sam_tickless.c b/arch/arm/src/sama5/sam_tickless.c index 64d481649a..a785266a5d 100644 --- a/arch/arm/src/sama5/sam_tickless.c +++ b/arch/arm/src/sama5/sam_tickless.c @@ -84,6 +84,7 @@ #include #include +#include #include @@ -259,6 +260,8 @@ void up_timer_initialize(void) PANIC(); } + DEBUGASSERT(ONESHOT_INITIALIZED(&g_tickless.oneshot)); + #ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP /* Get the maximum delay of the one-shot timer in microseconds */ @@ -292,6 +295,8 @@ void up_timer_initialize(void) tclldbg("ERROR: sam_freerun_initialize failed\n"); PANIC(); } + + DEBUGASSERT(FREERUN_INITIALIZED(&g_tickless.freerun)); } /**************************************************************************** @@ -329,7 +334,9 @@ void up_timer_initialize(void) int up_timer_gettime(FAR struct timespec *ts) { - return sam_freerun_counter(&g_tickless.freerun, ts); + return FREERUN_INITIALIZED(&g_tickless.freerun) ? + sam_freerun_counter(&g_tickless.freerun, ts) : + -EAGAIN; } /**************************************************************************** @@ -370,7 +377,9 @@ int up_timer_gettime(FAR struct timespec *ts) int up_timer_cancel(FAR struct timespec *ts) { - return sam_oneshot_cancel(&g_tickless.oneshot, ts); + return ONESHOT_INITIALIZED(&g_tickless.oneshot) ? + sam_oneshot_cancel(&g_tickless.oneshot, ts) : + -EAGAIN; } /**************************************************************************** @@ -400,6 +409,8 @@ int up_timer_cancel(FAR struct timespec *ts) int up_timer_start(FAR const struct timespec *ts) { - return sam_oneshot_start(&g_tickless.oneshot, sam_oneshot_handler, NULL, ts); + return ONESHOT_INITIALIZED(&g_tickless.oneshot) ? + sam_oneshot_start(&g_tickless.oneshot, sam_oneshot_handler, NULL, ts) : + -EAGAIN; } #endif /* CONFIG_SCHED_TICKLESS */ diff --git a/arch/arm/src/samv7/sam_freerun.h b/arch/arm/src/samv7/sam_freerun.h index 52075b2ecc..27ae59e633 100644 --- a/arch/arm/src/samv7/sam_freerun.h +++ b/arch/arm/src/samv7/sam_freerun.h @@ -53,6 +53,8 @@ * Pre-processor Definitions ****************************************************************************/ +#define FREERUN_INITIALIZED(s) (((s)->tch) != NULL) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/arm/src/samv7/sam_oneshot.h b/arch/arm/src/samv7/sam_oneshot.h index dec668a331..62efde8047 100644 --- a/arch/arm/src/samv7/sam_oneshot.h +++ b/arch/arm/src/samv7/sam_oneshot.h @@ -53,6 +53,8 @@ * Pre-processor Definitions ****************************************************************************/ +#define ONESHOT_INITIALIZED(s) (((s)->tch) != NULL) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/arm/src/samv7/sam_tickless.c b/arch/arm/src/samv7/sam_tickless.c index c8f584ca55..33cbc948c1 100644 --- a/arch/arm/src/samv7/sam_tickless.c +++ b/arch/arm/src/samv7/sam_tickless.c @@ -84,6 +84,7 @@ #include #include +#include #include @@ -268,6 +269,8 @@ void up_timer_initialize(void) PANIC(); } + DEBUGASSERT(ONESHOT_INITIALIZED(&g_tickless.oneshot)); + /* Initialize the free-running timer */ ret = sam_freerun_initialize(&g_tickless.freerun, @@ -278,6 +281,8 @@ void up_timer_initialize(void) tclldbg("ERROR: sam_freerun_initialize failed\n"); PANIC(); } + + DEBUGASSERT(FREERUN_INITIALIZED(&g_tickless.freerun)); } /**************************************************************************** @@ -315,7 +320,9 @@ void up_timer_initialize(void) int up_timer_gettime(FAR struct timespec *ts) { - return sam_freerun_counter(&g_tickless.freerun, ts); + return FREERUN_INITIALIZED(&g_tickless.freerun) ? + sam_freerun_counter(&g_tickless.freerun, ts) : + -EAGAIN; } /**************************************************************************** @@ -356,7 +363,9 @@ int up_timer_gettime(FAR struct timespec *ts) int up_timer_cancel(FAR struct timespec *ts) { - return sam_oneshot_cancel(&g_tickless.oneshot, ts); + return ONESHOT_INITIALIZED(&g_tickless.oneshot) ? + sam_oneshot_cancel(&g_tickless.oneshot, ts) : + -EAGAIN; } /**************************************************************************** @@ -386,6 +395,8 @@ int up_timer_cancel(FAR struct timespec *ts) int up_timer_start(FAR const struct timespec *ts) { - return sam_oneshot_start(&g_tickless.oneshot, sam_oneshot_handler, NULL, ts); + return ONESHOT_INITIALIZED(&g_tickless.oneshot) ? + sam_oneshot_start(&g_tickless.oneshot, sam_oneshot_handler, NULL, ts) : + -EAGAIN; } #endif /* CONFIG_SCHED_TICKLESS */