mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
SAMA5: Add oneshot max_delay method
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user