aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-04 08:46:11 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-04 08:46:11 +0000
commitefa92aaed21cbaa80f4bc88a0ef9bb6bbb7aa3ee (patch)
tree8289e84ce53bd72e8ef1637472430286306222ea /os/hal
parentb799bdc5c5874fdcfc0e9c33cde779c774ada73f (diff)
downloadChibiOS-efa92aaed21cbaa80f4bc88a0ef9bb6bbb7aa3ee.tar.gz
ChibiOS-efa92aaed21cbaa80f4bc88a0ef9bb6bbb7aa3ee.tar.bz2
ChibiOS-efa92aaed21cbaa80f4bc88a0ef9bb6bbb7aa3ee.zip
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
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/include/hal.h40
-rw-r--r--os/hal/platforms/STM32F1xx/hal_lld.c3
-rw-r--r--os/hal/platforms/STM32F1xx/hal_lld.h33
-rw-r--r--os/hal/platforms/STM32F2xx/hal_lld.c3
-rw-r--r--os/hal/platforms/STM32F2xx/hal_lld.h33
-rw-r--r--os/hal/platforms/STM32F4xx/hal_lld.c3
-rw-r--r--os/hal/platforms/STM32F4xx/hal_lld.h33
-rw-r--r--os/hal/platforms/STM32L1xx/hal_lld.c3
-rw-r--r--os/hal/platforms/STM32L1xx/hal_lld.h33
9 files changed, 184 insertions, 0 deletions
diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h
index 8d7214325..6c49e2c5c 100644
--- a/os/hal/include/hal.h
+++ b/os/hal/include/hal.h
@@ -53,6 +53,46 @@
#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. */
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32F1xx/hal_lld.c b/os/hal/platforms/STM32F1xx/hal_lld.c
index 1be870fcd..0f2d490d6 100644
--- a/os/hal/platforms/STM32F1xx/hal_lld.c
+++ b/os/hal/platforms/STM32F1xx/hal_lld.c
@@ -67,6 +67,9 @@ void hal_lld_init(void) {
SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk;
+ /* DWT cycle counter enable.*/
+ DWT_CTRL |= DWT_CTRL_CYCCNTENA;
+
#if defined(STM32_DMA_REQUIRED)
dmaInit();
#endif
diff --git a/os/hal/platforms/STM32F1xx/hal_lld.h b/os/hal/platforms/STM32F1xx/hal_lld.h
index 64cf0165c..4e1ca3f35 100644
--- a/os/hal/platforms/STM32F1xx/hal_lld.h
+++ b/os/hal/platforms/STM32F1xx/hal_lld.h
@@ -102,10 +102,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. */
/*===========================================================================*/
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. */
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32F4xx/hal_lld.c b/os/hal/platforms/STM32F4xx/hal_lld.c
index 38d46177e..d9bf8374e 100644
--- a/os/hal/platforms/STM32F4xx/hal_lld.c
+++ b/os/hal/platforms/STM32F4xx/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/STM32F4xx/hal_lld.h b/os/hal/platforms/STM32F4xx/hal_lld.h
index b43122936..953a7af45 100644
--- a/os/hal/platforms/STM32F4xx/hal_lld.h
+++ b/os/hal/platforms/STM32F4xx/hal_lld.h
@@ -1340,10 +1340,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. */
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32L1xx/hal_lld.c b/os/hal/platforms/STM32L1xx/hal_lld.c
index aecff7be1..54d67b9d0 100644
--- a/os/hal/platforms/STM32L1xx/hal_lld.c
+++ b/os/hal/platforms/STM32L1xx/hal_lld.c
@@ -68,6 +68,9 @@ void hal_lld_init(void) {
SysTick_CTRL_ENABLE_Msk |
SysTick_CTRL_TICKINT_Msk;
+ /* DWT cycle counter enable.*/
+ DWT_CTRL |= DWT_CTRL_CYCCNTENA;
+
#if defined(STM32_DMA_REQUIRED)
dmaInit();
#endif
diff --git a/os/hal/platforms/STM32L1xx/hal_lld.h b/os/hal/platforms/STM32L1xx/hal_lld.h
index fce1a80f6..4bbe2fe76 100644
--- a/os/hal/platforms/STM32L1xx/hal_lld.h
+++ b/os/hal/platforms/STM32L1xx/hal_lld.h
@@ -971,10 +971,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. */
/*===========================================================================*/