From f52c062a19563a76960eef4b535327909b6059b9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 15 Aug 2015 08:56:56 +0000 Subject: Fixed bug #629. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8214 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/nil/src/nil.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'os/nil/src') diff --git a/os/nil/src/nil.c b/os/nil/src/nil.c index 9254acbc0..7d3dab9ce 100644 --- a/os/nil/src/nil.c +++ b/os/nil/src/nil.c @@ -306,6 +306,50 @@ void chSysRestoreStatusX(syssts_t sts) { } } +#if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__) +/** + * @brief Realtime window test. + * @details This function verifies if the current realtime counter value + * lies within the specified range or not. The test takes care + * of the realtime counter wrapping to zero on overflow. + * @note When start==end then the function returns always true because the + * whole time range is specified. + * @note This function is only available if the port layer supports the + * option @p PORT_SUPPORTS_RT. + * + * @param[in] cnt the counter value to be tested + * @param[in] start the start of the time window (inclusive) + * @param[in] end the end of the time window (non inclusive) + * @retval true current time within the specified time window. + * @retval false current time not within the specified time window. + * + * @xclass + */ +bool chSysIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) { + + return (bool)((cnt - start) < (end - start)); +} + +/** + * @brief Polled delay. + * @note The real delay is always few cycles in excess of the specified + * value. + * @note This function is only available if the port layer supports the + * option @p PORT_SUPPORTS_RT. + * + * @param[in] cycles number of cycles + * + * @xclass + */ +void chSysPolledDelayX(rtcnt_t cycles) { + rtcnt_t start = chSysGetRealtimeCounterX(); + rtcnt_t end = start + cycles; + + while (chSysIsCounterWithinX(chSysGetRealtimeCounterX(), start, end)) { + } +} +#endif /* PORT_SUPPORTS_RT == TRUE */ + /** * @brief Makes the specified thread ready for execution. * -- cgit v1.2.3