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
This commit is contained in:
gdisirio 2012-01-04 08:46:11 +00:00
parent b799bdc5c5
commit efa92aaed2
11 changed files with 218 additions and 0 deletions

View File

@ -52,6 +52,46 @@
#include "serial_usb.h" #include "serial_usb.h"
#include "rtc.h" #include "rtc.h"
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/**
* @brief Returns the current value of the system free running counter.
* @note This is an optional service that could not be implemented in
* all HAL implementations.
*
* @return The value of the system free running counter.
*
* @api
*/
#define halGetCounterValue() hal_lld_get_counter_value()
/**
* @brief Realtime counter frequency.
*
* @return The realtime counter frequency of type halclock_t.
*
* @api
*/
#define halGetCounterFrequency() hal_lld_get_counter_frequency()
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -67,6 +67,9 @@ void hal_lld_init(void) {
SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk; SysTick_CTRL_TICKINT_Msk;
/* DWT cycle counter enable.*/
DWT_CTRL |= DWT_CTRL_CYCCNTENA;
#if defined(STM32_DMA_REQUIRED) #if defined(STM32_DMA_REQUIRED)
dmaInit(); dmaInit();
#endif #endif

View File

@ -102,10 +102,43 @@
/* Driver data structures and types. */ /* 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. */ /* 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. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -71,6 +71,9 @@ void hal_lld_init(void) {
SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk; SysTick_CTRL_TICKINT_Msk;
/* DWT cycle counter enable.*/
DWT_CTRL |= DWT_CTRL_CYCCNTENA;
#if STM32_PVD_ENABLE #if STM32_PVD_ENABLE
/* Programmable voltage detector initialization */ /* Programmable voltage detector initialization */
PWR->CR |= PWR_CR_PVDE | (STM32_PLS & STM32_PLS_MASK); PWR->CR |= PWR_CR_PVDE | (STM32_PLS & STM32_PLS_MASK);

View File

@ -1320,10 +1320,43 @@
/* Driver data structures and types. */ /* 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. */ /* 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. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -71,6 +71,9 @@ void hal_lld_init(void) {
SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk; SysTick_CTRL_TICKINT_Msk;
/* DWT cycle counter enable.*/
DWT_CTRL |= DWT_CTRL_CYCCNTENA;
#if STM32_PVD_ENABLE #if STM32_PVD_ENABLE
/* Programmable voltage detector initialization */ /* Programmable voltage detector initialization */
PWR->CR |= PWR_CR_PVDE | (STM32_PLS & STM32_PLS_MASK); PWR->CR |= PWR_CR_PVDE | (STM32_PLS & STM32_PLS_MASK);

View File

@ -1340,10 +1340,43 @@
/* Driver data structures and types. */ /* 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. */ /* 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. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -68,6 +68,9 @@ void hal_lld_init(void) {
SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk; SysTick_CTRL_TICKINT_Msk;
/* DWT cycle counter enable.*/
DWT_CTRL |= DWT_CTRL_CYCCNTENA;
#if defined(STM32_DMA_REQUIRED) #if defined(STM32_DMA_REQUIRED)
dmaInit(); dmaInit();
#endif #endif

View File

@ -971,10 +971,43 @@
/* Driver data structures and types. */ /* 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. */ /* 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. */ /* External declarations. */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -191,6 +191,9 @@ typedef struct {
#define AIRCR_PRIGROUP_MASK (0x7U << 8) #define AIRCR_PRIGROUP_MASK (0x7U << 8)
#define AIRCR_PRIGROUP(n) ((n##U) << 8) #define AIRCR_PRIGROUP(n) ((n##U) << 8)
/**
* @brief Structure representing the FPU I/O space.
*/
typedef struct { typedef struct {
IOREG32 unused1[1]; IOREG32 unused1[1];
IOREG32 FPCCR; IOREG32 FPCCR;
@ -225,6 +228,35 @@ typedef struct {
#define FPDSCR_FZ (0x1U << 24) #define FPDSCR_FZ (0x1U << 24)
#define FPDSCR_RMODE(n) ((n##U) << 22) #define FPDSCR_RMODE(n) ((n##U) << 22)
/**
* @brief Structure representing the DWT I/O space.
*/
typedef struct {
IOREG32 CTRL;
IOREG32 CYCCNT;
IOREG32 CPICNT;
IOREG32 EXCCNT;
IOREG32 SLEEPCNT;
IOREG32 LSUCNT;
IOREG32 FOLDCNT;
IOREG32 PCSR;
} CMx_DWT;
/**
* @brief DWT peripheral base address.
*/
#define DWTBase ((CMx_DWT *)0xE0001000U)
#define DWT_CTRL (DWTBase->CTRL)
#define DWT_CYCCNT (DWTBase->CYCCNT)
#define DWT_CPICNT (DWTBase->CPICNT)
#define DWT_EXCCNT (DWTBase->EXCCNT)
#define DWT_SLEEPCNT (DWTBase->SLEEPCNT)
#define DWT_LSUCNT (DWTBase->LSUCNT)
#define DWT_FOLDCNT (DWTBase->FOLDCNT)
#define DWT_PCSR (DWTBase->PCSR)
#define DWT_CTRL_CYCCNTENA (0x1U << 0)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -79,6 +79,8 @@
- FIX: Fixed SYSCFG clock not started in STM32L1/F4 HALs (bug 3449139). - FIX: Fixed SYSCFG clock not started in STM32L1/F4 HALs (bug 3449139).
- FIX: Fixed wrong definitions in STM32L-Discovery board file (bug 3449076). - FIX: Fixed wrong definitions in STM32L-Discovery board file (bug 3449076).
- OPT: Improved the exception exit code in the GCC Cortex-Mx ports. - OPT: Improved the exception exit code in the GCC Cortex-Mx ports.
- NEW: Addred to the HAL driver the handling of an abstract realtime free
running counter, added the capability to all the STM32 HALs.
- NEW: Modified ARM and ARMCMx build rules to allow parallel build. Now the - NEW: Modified ARM and ARMCMx build rules to allow parallel build. Now the
log outputs one dummy compilation command in order to allow paths discovery log outputs one dummy compilation command in order to allow paths discovery
by Eclipse. by Eclipse.