From efa92aaed21cbaa80f4bc88a0ef9bb6bbb7aa3ee Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 4 Jan 2012 08:46:11 +0000 Subject: Realtime counter support in the generic HAL driver and implementations for al STM32 devices, others will follow. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3723 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32F2xx/hal_lld.c | 3 +++ os/hal/platforms/STM32F2xx/hal_lld.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'os/hal/platforms/STM32F2xx') diff --git a/os/hal/platforms/STM32F2xx/hal_lld.c b/os/hal/platforms/STM32F2xx/hal_lld.c index 2b3894bdd..2344d161f 100644 --- a/os/hal/platforms/STM32F2xx/hal_lld.c +++ b/os/hal/platforms/STM32F2xx/hal_lld.c @@ -71,6 +71,9 @@ void hal_lld_init(void) { SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk; + /* DWT cycle counter enable.*/ + DWT_CTRL |= DWT_CTRL_CYCCNTENA; + #if STM32_PVD_ENABLE /* Programmable voltage detector initialization */ PWR->CR |= PWR_CR_PVDE | (STM32_PLS & STM32_PLS_MASK); diff --git a/os/hal/platforms/STM32F2xx/hal_lld.h b/os/hal/platforms/STM32F2xx/hal_lld.h index 528d4dec2..280cbea43 100644 --- a/os/hal/platforms/STM32F2xx/hal_lld.h +++ b/os/hal/platforms/STM32F2xx/hal_lld.h @@ -1320,10 +1320,43 @@ /* Driver data structures and types. */ /*===========================================================================*/ +/** + * @brief Type representing a system clock frequency. + */ +typedef uint32_t halclock_t; + +/** + * @brief Type of the realtime free counter value. + */ +typedef uint32_t halrtcnt_t; + /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ +/** + * @brief Returns the current value of the system free running counter. + * @note This service is implemented by returning the content of the + * DWT_CYCCNT register. + * + * @return The value of the system free running counter of + * type halrtcnt_t. + * + * @notapi + */ +#define hal_lld_get_counter_value() DWT_CYCCNT + +/** + * @brief Realtime counter frequency. + * @note The DWT_CYCCNT register is incremented directly by the system + * clock so this function returns STM32_SYSCLK. + * + * @return The realtime counter frequency of type halclock_t. + * + * @notapi + */ +#define hal_lld_get_counter_frequency() STM32_SYSCLK + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ -- cgit v1.2.3