diff --git a/arch/arm/src/sama5/sam_oneshot.c b/arch/arm/src/sama5/sam_oneshot.c index d9917071e1d..b8836069823 100644 --- a/arch/arm/src/sama5/sam_oneshot.c +++ b/arch/arm/src/sama5/sam_oneshot.c @@ -222,6 +222,32 @@ int sam_oneshot_initialize(struct sam_oneshot_s *oneshot, int chan, return OK; } +/**************************************************************************** + * Name: sam_oneshot_max_delay + * + * Description: + * Return the maximum delay supported by the one shot timer (in + * microseconds). + * + * Input Parameters: + * oneshot Caller allocated instance of the oneshot state structure. This + * structure must have been previously initialized via a call to + * sam_oneshot_initialize(); + * usec The location in which to return the maximum delay. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int sam_oneshot_max_delay(struct sam_oneshot_s *oneshot, uint64_t *usec) +{ + DEBUGASSERT(oneshot != NULL && usec != NULL); + *usec = (0xffffull * USEC_PER_SEC) / (uint64_t)sam_tc_divfreq(oneshot->tch); + return OK; +} + /**************************************************************************** * Name: sam_oneshot_start * diff --git a/arch/arm/src/sama5/sam_oneshot.h b/arch/arm/src/sama5/sam_oneshot.h index cc5c6976137..15431882fc0 100644 --- a/arch/arm/src/sama5/sam_oneshot.h +++ b/arch/arm/src/sama5/sam_oneshot.h @@ -131,6 +131,27 @@ extern "C" int sam_oneshot_initialize(struct sam_oneshot_s *oneshot, int chan, uint16_t resolution); +/**************************************************************************** + * Name: sam_oneshot_max_delay + * + * Description: + * Return the maximum delay supported by the one shot timer (in + * microseconds). + * + * Input Parameters: + * oneshot Caller allocated instance of the oneshot state structure. This + * structure must have been previously initialized via a call to + * sam_oneshot_initialize(); + * usec The location in which to return the maximum delay. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int sam_oneshot_max_delay(struct sam_oneshot_s *oneshot, uint64_t *usec); + /**************************************************************************** * Name: sam_oneshot_start * diff --git a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c index 4a22cc9855d..e9737ea167d 100644 --- a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c @@ -172,12 +172,23 @@ static void sam_oneshot_handler(void *arg) static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts) { - DEBUGASSERT(lower != NULL && ts != NULL); + FAR struct sam_oneshot_lowerhalf_s *priv = + (FAR struct sam_oneshot_lowerhalf_s *)lower; + uint64_t usecs; + int ret; -#warning Missing logic - ts->tv_sec = INT_MAX; - ts->tv_nsec = LONG_MAX; - return -ENOSYS; + DEBUGASSERT(priv != NULL && ts != NULL); + ret = sam_oneshot_max_delay(&priv->oneshot, &usecs); + if (ret >= 0) + { + uint64_t sec = usecs / 1000000; + usecs -= 1000000 * sec; + + ts->tv_sec = (time_t)sec; + ts->tv_nsec = (long)(usecs * 1000); + } + + return ret; } /**************************************************************************** @@ -333,4 +344,4 @@ FAR struct oneshot_lowerhalf_s *oneshot_initialize(int chan, } return &priv->lh; -} \ No newline at end of file +} diff --git a/arch/arm/src/samv7/sam_oneshot.c b/arch/arm/src/samv7/sam_oneshot.c index bc9c23b515e..9a20ec17a76 100644 --- a/arch/arm/src/samv7/sam_oneshot.c +++ b/arch/arm/src/samv7/sam_oneshot.c @@ -223,6 +223,32 @@ int sam_oneshot_initialize(struct sam_oneshot_s *oneshot, int chan, return OK; } +/**************************************************************************** + * Name: sam_oneshot_max_delay + * + * Description: + * Return the maximum delay supported by the one shot timer (in + * microseconds). + * + * Input Parameters: + * oneshot Caller allocated instance of the oneshot state structure. This + * structure must have been previously initialized via a call to + * sam_oneshot_initialize(); + * usec The location in which to return the maximum delay. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned + * on failure. + * + ****************************************************************************/ + +int sam_oneshot_max_delay(struct sam_oneshot_s *oneshot, uint64_t *usec) +{ + DEBUGASSERT(oneshot != NULL && usec != NULL); + *usec = (0xffffull * USEC_PER_SEC) / (uint64_t)sam_tc_divfreq(oneshot->tch); + return OK; +} + /**************************************************************************** * Name: sam_oneshot_start * @@ -491,30 +517,4 @@ int sam_oneshot_cancel(struct sam_oneshot_s *oneshot, return OK; } -/**************************************************************************** - * Name: sam_oneshot_max_delay - * - * Description: - * Return the maximum delay supported by the one shot timer (in - * microseconds). - * - * Input Parameters: - * oneshot Caller allocated instance of the oneshot state structure. This - * structure must have been previously initialized via a call to - * sam_oneshot_initialize(); - * usec The location in which to return the maximum delay. - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned - * on failure. - * - ****************************************************************************/ - -int sam_oneshot_max_delay(struct sam_oneshot_s *oneshot, uint64_t *usec) -{ - DEBUGASSERT(oneshot && usec); - *usec = (0xffffull * USEC_PER_SEC) / (uint64_t)sam_tc_divfreq(oneshot->tch); - return OK; -} - #endif /* CONFIG_SAMV7_ONESHOT */