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 | |
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')
-rw-r--r-- | os/hal/include/st.h | 66 | ||||
-rw-r--r-- | os/hal/osal/chibios/osal.h | 6 | ||||
-rw-r--r-- | os/hal/platforms/STM32/TIMv1/st_lld.c | 23 | ||||
-rw-r--r-- | os/hal/platforms/STM32/TIMv1/st_lld.h | 92 |
4 files changed, 155 insertions, 32 deletions
diff --git a/os/hal/include/st.h b/os/hal/include/st.h index 276ab2649..05d382d93 100644 --- a/os/hal/include/st.h +++ b/os/hal/include/st.h @@ -21,6 +21,8 @@ /**
* @file st.h
* @brief ST Driver macros and structures.
+ * @details This header is designed to be include-able without having to
+ * include other files from the HAL.
*
* @addtogroup ST
* @{
@@ -29,8 +31,6 @@ #ifndef _ST_H_
#define _ST_H_
-#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
-
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
@@ -53,6 +53,66 @@ /* Driver macros. */
/*===========================================================================*/
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Returns the time counter value.
+ * @note This functionality is only available in free running mode, the
+ * behavior in periodic mode is undefined.
+ *
+ * @return The counter value.
+ *
+ * @api
+ */
+#define stGetCounter() st_lld_get_counter()
+
+/**
+ * @brief Starts the alarm.
+ * @note Makes sure that no spurious alarms are triggered after
+ * this call.
+ * @note This functionality is only available in free running mode, the
+ * behavior in periodic mode is undefined.
+ *
+ * @param[in] time the time to be set for the first alarm
+ *
+ * @api
+ */
+#define stStartAlarm(time) st_lld_start_alarm(time)
+
+/**
+ * @brief Stops the alarm interrupt.
+ * @note This functionality is only available in free running mode, the
+ * behavior in periodic mode is undefined.
+ *
+ * @api
+ */
+#define stStopAlarm() st_lld_stop_alarm()
+
+/**
+ * @brief Sets the alarm time.
+ * @note This functionality is only available in free running mode, the
+ * behavior in periodic mode is undefined.
+ *
+ * @param[in] time the time to be set for the next alarm
+ *
+ * @api
+ */
+#define stSetAlarm(time) st_lld_set_alarm(time)
+
+/**
+ * @brief Returns the current alarm time.
+ * @note This functionality is only available in free running mode, the
+ * behavior in periodic mode is undefined.
+ *
+ * @return The currently set alarm time.
+ *
+ * @api
+ */
+#define stGetAlarm() st_lld_get_alarm()
+/** @} */
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -65,8 +125,6 @@ extern "C" { }
#endif
-#endif /* OSAL_ST_MODE != OSAL_ST_MODE_NONE */
-
#endif /* _ST_H_ */
/** @} */
diff --git a/os/hal/osal/chibios/osal.h b/os/hal/osal/chibios/osal.h index d3d2e2b40..937b0f38e 100644 --- a/os/hal/osal/chibios/osal.h +++ b/os/hal/osal/chibios/osal.h @@ -107,6 +107,12 @@ /* Derived constants and error checks. */
/*===========================================================================*/
+#if !(OSAL_ST_MODE == OSAL_ST_MODE_NONE) && \
+ !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \
+ !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING)
+#error "invalid OSAL_ST_MODE setting in osal.h"
+#endif
+
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
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_ */
|