diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-08-21 13:33:40 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-08-21 13:33:40 +0000 |
commit | 78b866e0a7046a893025fe1304064f255e37c411 (patch) | |
tree | 259b7140402d9a34768380ff0fdd5fa8a7e7bdfe /os/hal/platforms/STM32 | |
parent | 371ef2afb5b7045d8293dd5a393a7783b025f8a8 (diff) | |
download | ChibiOS-78b866e0a7046a893025fe1304064f255e37c411.tar.gz ChibiOS-78b866e0a7046a893025fe1304064f255e37c411.tar.bz2 ChibiOS-78b866e0a7046a893025fe1304064f255e37c411.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6192 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/STM32')
-rw-r--r-- | os/hal/platforms/STM32/TIMv1/st_lld.c | 23 | ||||
-rw-r--r-- | os/hal/platforms/STM32/TIMv1/st_lld.h | 92 |
2 files changed, 87 insertions, 28 deletions
diff --git a/os/hal/platforms/STM32/TIMv1/st_lld.c b/os/hal/platforms/STM32/TIMv1/st_lld.c index eb97866cd..45367878a 100644 --- a/os/hal/platforms/STM32/TIMv1/st_lld.c +++ b/os/hal/platforms/STM32/TIMv1/st_lld.c @@ -26,6 +26,29 @@ #if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
+/* The following checks and settings are unusually done here because the
+ file st.h needs to not have external dependencies. In this case there
+ would be a dependency on osal.h and mcuconf.h.*/
+#if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) && !STM32_HAS_TIM2
+#error "TIM2 not present in the selected device"
+#endif
+
+#if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) && !STM32_TIM2_IS_32BITS
+#error "TIM2 is not a 32 bits timer"
+#endif
+
+/**
+ * @name Configuration options
+ * @{
+ */
+/**
+ * @brief SysTick timer IRQ priority.
+ */
+#if !defined(STM32_ST_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_ST_IRQ_PRIORITY 8
+#endif
+/** @} */
+
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
diff --git a/os/hal/platforms/STM32/TIMv1/st_lld.h b/os/hal/platforms/STM32/TIMv1/st_lld.h index 09f95bd9e..882472cb2 100644 --- a/os/hal/platforms/STM32/TIMv1/st_lld.h +++ b/os/hal/platforms/STM32/TIMv1/st_lld.h @@ -17,6 +17,8 @@ /**
* @file STM32/st_lld.h
* @brief ST Driver subsystem low level driver header.
+ * @details This header is designed to be include-able without having to
+ * include other files from the HAL.
*
* @addtogroup ST
* @{
@@ -25,8 +27,7 @@ #ifndef _ST_LLD_H_
#define _ST_LLD_H_
-#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
-
+#include "stm32_registry.h"
#include "stm32_tim.h"
/*===========================================================================*/
@@ -37,35 +38,10 @@ /* Driver pre-compile time settings. */
/*===========================================================================*/
-/**
- * @name Configuration options
- * @{
- */
-/**
- * @brief SysTick timer IRQ priority.
- */
-#if !defined(STM32_ST_IRQ_PRIORITY) || defined(__DOXYGEN__)
-#define STM32_ST_IRQ_PRIORITY 8
-#endif
-/** @} */
-
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
-#if !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \
- !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING)
-#error "invalid OSAL_ST_MODE setting in osal.h"
-#endif
-
-#if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) && !STM32_HAS_TIM2
-#error "TIM2 not present in the selected device"
-#endif
-
-#if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) && !STM32_TIM2_IS_32BITS
-#error "TIM2 is not a 32 bits timer"
-#endif
-
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
@@ -90,7 +66,67 @@ extern "C" { /* Driver inline functions. */
/*===========================================================================*/
-#endif /* OSAL_ST_MODE != OSAL_ST_MODE_NONE */
+/**
+ * @brief Returns the time counter value.
+ *
+ * @return The counter value.
+ *
+ * @notapi
+ */
+static inline systime_t st_lld_get_counter(void) {
+
+ return (systime_t)(STM32_TIM2->CNT);
+}
+
+/**
+ * @brief Starts the alarm.
+ * @note Makes sure that no spurious alarms are triggered after
+ * this call.
+ *
+ * @param[in] time the time to be set for the first alarm
+ *
+ * @notapi
+ */
+static inline void st_lld_start_alarm(systime_t time) {
+
+ STM32_TIM2->CCR[0] = time;
+ STM32_TIM2->SR = 0;
+ STM32_TIM2->DIER = STM32_TIM_DIER_CC1IE;
+}
+
+/**
+ * @brief Stops the alarm interrupt.
+ *
+ * @notapi
+ */
+static inline void st_lld_stop_alarm(void) {
+
+ STM32_TIM2->DIER = 0;
+}
+
+/**
+ * @brief Sets the alarm time.
+ *
+ * @param[in] time the time to be set for the next alarm
+ *
+ * @notapi
+ */
+static inline void st_lld_set_alarm(systime_t time) {
+
+ STM32_TIM2->CCR[0] = (uint32_t)time;
+}
+
+/**
+ * @brief Returns the current alarm time.
+ *
+ * @return The currently set alarm time.
+ *
+ * @notapi
+ */
+static inline systime_t st_lld_get_alarm(void) {
+
+ return (systime_t)STM32_TIM2->CCR[0];
+}
#endif /* _ST_LLD_H_ */
|