git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6084 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2013-08-06 09:19:19 +00:00
parent d7d1667ccd
commit 04601b760b
5 changed files with 50 additions and 24 deletions

View File

@ -40,8 +40,17 @@
* @details Frequency of the system timer that drives the system ticks. This * @details Frequency of the system timer that drives the system ticks. This
* setting also defines the system tick time unit. * setting also defines the system tick time unit.
*/ */
#if !defined(CH_CFG_FREQUENCY) || defined(__DOXYGEN__) #if !defined(CH_CFG_ST_FREQUENCY) || defined(__DOXYGEN__)
#define CH_CFG_FREQUENCY 10000 #define CH_CFG_ST_FREQUENCY 10000
#endif
/**
* @brief Realtime Counter frequency.
* @details Frequency of the system counter used for realtime delays and
* measurements.
*/
#if !defined(CH_CFG_RTC_FREQUENCY) || defined(__DOXYGEN__)
#define CH_CFG_RTC_FREQUENCY 72000000
#endif #endif
/** /**

View File

@ -95,7 +95,7 @@
/** /**
* @brief Required systick frequency or resolution. * @brief Required systick frequency or resolution.
*/ */
#define OSAL_SYSTICK_FREQUENCY CH_CFG_FREQUENCY #define OSAL_SYSTICK_FREQUENCY CH_CFG_ST_FREQUENCY
/*===========================================================================*/ /*===========================================================================*/
/* Module pre-compile time settings. */ /* Module pre-compile time settings. */
@ -123,6 +123,13 @@ typedef int32_t msg_t;
typedef uint32_t systime_t; typedef uint32_t systime_t;
#endif #endif
#if 0
/**
* @brief Type of realtime counter.
*/
typedef uint32_t rtcnt_t;
#endif
/** /**
* @brief Type of a thread reference. * @brief Type of a thread reference.
*/ */
@ -309,6 +316,20 @@ static inline void osalSysUnlockFromISR(void) {
chSysUnlockFromISR(); chSysUnlockFromISR();
} }
/**
* @brief Polled delay.
* @note The real delay is always few cycles in excess of the specified
* value.
*
* @param[in] cycles number of cycles
*
* @xclass
*/
static inline void osalSysPolledDelayX(rtcnt_t cycles) {
chSysPolledDelayX(cycles);
}
/** /**
* @brief Systick callback for the underlying OS. * @brief Systick callback for the underlying OS.
* @note This callback is only defined if the OSAL requires such a * @note This callback is only defined if the OSAL requires such a

View File

@ -89,7 +89,7 @@ static void adc_lld_vreg_on(ADCDriver *adcp) {
#if STM32_ADC_DUAL_MODE #if STM32_ADC_DUAL_MODE
adcp->adcs->CR = ADC_CR_ADVREGEN_0; adcp->adcs->CR = ADC_CR_ADVREGEN_0;
#endif #endif
halPolledDelay(US2RTT(10)); osalSysPolledDelayX(US2RTC(10));
} }
/** /**

View File

@ -109,75 +109,71 @@
* @details Converts from seconds to realtime counter cycles. * @details Converts from seconds to realtime counter cycles.
* @note The result is rounded upward to the next tick boundary. * @note The result is rounded upward to the next tick boundary.
* *
* @param[in] freq realtime counter operating frequency
* @param[in] sec number of seconds * @param[in] sec number of seconds
* @return The number of cycles. * @return The number of cycles.
* *
* @api * @api
*/ */
#define S2RTV(freq, sec) ((freq) * (sec)) #define S2RTV(sec) (CH_CFG_RTC_FREQUENCY * (sec))
/** /**
* @brief Milliseconds to realtime counter. * @brief Milliseconds to realtime counter.
* @details Converts from milliseconds to realtime counter cycles. * @details Converts from milliseconds to realtime counter cycles.
* @note The result is rounded upward to the next tick boundary. * @note The result is rounded upward to the next tick boundary.
* *
* @param[in] freq realtime counter operating frequency
* @param[in] msec number of milliseconds * @param[in] msec number of milliseconds
* @return The number of cycles. * @return The number of cycles.
* *
* @api * @api
*/ */
#define MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec)) #define MS2RTC(msec) (rtcnt_t)(((CH_CFG_RTC_FREQUENCY + 999UL) / \
1000UL) * (msec))
/** /**
* @brief Microseconds to realtime counter. * @brief Microseconds to realtime counter.
* @details Converts from microseconds to realtime counter cycles. * @details Converts from microseconds to realtime counter cycles.
* @note The result is rounded upward to the next tick boundary. * @note The result is rounded upward to the next tick boundary.
* *
* @param[in] freq realtime counter operating frequency
* @param[in] usec number of microseconds * @param[in] usec number of microseconds
* @return The number of cycles. * @return The number of cycles.
* *
* @api * @api
*/ */
#define US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec)) #define US2RTC(usec) (rtcnt_t)(((CH_CFG_RTC_FREQUENCY + 999999UL) / \
1000000UL) * (usec))
/** /**
* @brief Realtime counter cycles to seconds. * @brief Realtime counter cycles to seconds.
* @details Converts from realtime counter cycles number to seconds. * @details Converts from realtime counter cycles number to seconds.
* *
* @param[in] freq realtime counter operating frequency
* @param[in] n number of cycles * @param[in] n number of cycles
* @return The number of seconds. * @return The number of seconds.
* *
* @api * @api
*/ */
#define RTC2S(freq, n) (rtcnt_t)((n) / (freq)) #define RTC2S(n) (rtcnt_t)(CH_CFG_RTC_FREQUENCY / (freq))
/** /**
* @brief Realtime counter cycles to milliseconds. * @brief Realtime counter cycles to milliseconds.
* @details Converts from realtime counter cycles number to milliseconds. * @details Converts from realtime counter cycles number to milliseconds.
* *
* @param[in] freq realtime counter operating frequency
* @param[in] n number of cycles * @param[in] n number of cycles
* @return The number of milliseconds. * @return The number of milliseconds.
* *
* @api * @api
*/ */
#define RTC2MS(freq, n) ((n) / ((freq) / 1000UL)) #define RTC2MS(n) ((n) / (CH_CFG_RTC_FREQUENCY / 1000UL))
/** /**
* @brief Realtime counter cycles to microseconds. * @brief Realtime counter cycles to microseconds.
* @details Converts from realtime counter cycles number to microseconds. * @details Converts from realtime counter cycles number to microseconds.
* *
* @param[in] freq realtime counter operating frequency
* @param[in] n number of cycles * @param[in] n number of cycles
* @return The number of microseconds. * @return The number of microseconds.
* *
* @api * @api
*/ */
#define RTC2US(freq, n) ((n) / ((freq) / 1000000UL)) #define RTC2US(n) ((n) / (CH_CFG_RTC_FREQUENCY / 1000000UL))
/** @} */ /** @} */
/** /**

View File

@ -41,12 +41,12 @@
/* Derived constants and error checks. */ /* Derived constants and error checks. */
/*===========================================================================*/ /*===========================================================================*/
#if CH_CFG_FREQUENCY <= 0 #if CH_CFG_ST_FREQUENCY <= 0
#error "invalid CH_CFG_FREQUENCY specified" #error "invalid CH_CFG_ST_FREQUENCY specified"
#endif #endif
#if (CH_CFG_TIMEDELTA < 0) || (CH_CFG_TIMEDELTA == 1) #if (CH_CFG_TIMEDELTA < 0) || (CH_CFG_TIMEDELTA == 1)
#error "invalid NIL_CFG_TIMEDELTA specified" #error "invalid CH_CFG_TIMEDELTA specified"
#endif #endif
#if (CH_CFG_TIMEDELTA > 0) && (CH_CFG_TIME_QUANTUM > 0) #if (CH_CFG_TIMEDELTA > 0) && (CH_CFG_TIME_QUANTUM > 0)
@ -125,7 +125,7 @@ struct virtual_timer {
* @api * @api
*/ */
#define S2ST(sec) \ #define S2ST(sec) \
((systime_t)((uint32_t)(sec) * (uint32_t)CH_CFG_FREQUENCY)) ((systime_t)((uint32_t)(sec) * (uint32_t)CH_CFG_ST_FREQUENCY))
/** /**
* @brief Milliseconds to system ticks. * @brief Milliseconds to system ticks.
@ -138,8 +138,8 @@ struct virtual_timer {
* @api * @api
*/ */
#define MS2ST(msec) \ #define MS2ST(msec) \
((systime_t)(((((uint32_t)(msec)) * ((uint32_t)CH_CFG_FREQUENCY) - 1UL) / \ ((systime_t)(((((uint32_t)(msec)) * \
1000UL) + 1UL)) ((uint32_t)CH_CFG_ST_FREQUENCY) - 1UL) / 1000UL) + 1UL))
/** /**
* @brief Microseconds to system ticks. * @brief Microseconds to system ticks.
@ -152,8 +152,8 @@ struct virtual_timer {
* @api * @api
*/ */
#define US2ST(usec) \ #define US2ST(usec) \
((systime_t)(((((uint32_t)(usec)) * ((uint32_t)CH_CFG_FREQUENCY) - 1UL) / \ ((systime_t)(((((uint32_t)(usec)) * \
1000000UL) + 1UL)) ((uint32_t)CH_CFG_ST_FREQUENCY) - 1UL) / 1000000UL) + 1UL))
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/