diff options
-rw-r--r-- | demos/ARMCM0-STM32F051-DISCOVERY/chconf.h | 6 | ||||
-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 | ||||
-rw-r--r-- | os/rt/ports/ARMCMx/devices/STM32F0xx/systick.h | 33 |
6 files changed, 174 insertions, 52 deletions
diff --git a/demos/ARMCM0-STM32F051-DISCOVERY/chconf.h b/demos/ARMCM0-STM32F051-DISCOVERY/chconf.h index fb153b410..3ab29fcae 100644 --- a/demos/ARMCM0-STM32F051-DISCOVERY/chconf.h +++ b/demos/ARMCM0-STM32F051-DISCOVERY/chconf.h @@ -41,7 +41,7 @@ * setting also defines the system tick time unit.
*/
#if !defined(CH_CFG_ST_FREQUENCY) || defined(__DOXYGEN__)
-#define CH_CFG_ST_FREQUENCY 1000
+#define CH_CFG_ST_FREQUENCY 10000
#endif
/**
@@ -62,7 +62,7 @@ * this value.
*/
#if !defined(CH_CFG_TIMEDELTA) || defined(__DOXYGEN__)
-#define CH_CFG_TIMEDELTA 0
+#define CH_CFG_TIMEDELTA 2
#endif
/**
@@ -441,7 +441,7 @@ * tickless mode.
*/
#if !defined(CH_DBG_THREADS_PROFILING) || defined(__DOXYGEN__)
-#define CH_DBG_THREADS_PROFILING TRUE
+#define CH_DBG_THREADS_PROFILING FALSE
#endif
/** @} */
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_ */
diff --git a/os/rt/ports/ARMCMx/devices/STM32F0xx/systick.h b/os/rt/ports/ARMCMx/devices/STM32F0xx/systick.h index 585eecd61..e61926c7e 100644 --- a/os/rt/ports/ARMCMx/devices/STM32F0xx/systick.h +++ b/os/rt/ports/ARMCMx/devices/STM32F0xx/systick.h @@ -19,16 +19,23 @@ */
/**
- * @file STM32F30x/systick.h
+ * @file ARMCMx/systick.h
* @brief System timer header file.
*
- * @addtogroup STM32F30X_TIMER
+ * @addtogroup ARMCMx_SYSTICK
* @{
*/
#ifndef _SYSTICK_H_
#define _SYSTICK_H_
+#if defined(CH_PORT_DO_NOT_USE_ST)
+#include "systick_ext.h"
+
+#else /* !defined(CH_PORT_DO_NOT_USE_ST) */
+
+#include "st.h"
+
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
@@ -66,7 +73,7 @@ */
static inline systime_t port_timer_get_time(void) {
- return TIM2->CNT;
+ return stGetCounter();
}
/**
@@ -80,11 +87,7 @@ static inline systime_t port_timer_get_time(void) { */
static inline void port_timer_start_alarm(systime_t time) {
- chDbgAssert((TIM2->DIER & 2) == 0, "already started");
-
- TIM2->CCR1 = time;
- TIM2->SR = 0;
- TIM2->DIER = 2; /* CC1IE */
+ stStartAlarm(time);
}
/**
@@ -94,9 +97,7 @@ static inline void port_timer_start_alarm(systime_t time) { */
static inline void port_timer_stop_alarm(void) {
- chDbgAssert((TIM2->DIER & 2) != 0, "not started");
-
- TIM2->DIER = 0;
+ stStopAlarm();
}
/**
@@ -108,9 +109,7 @@ static inline void port_timer_stop_alarm(void) { */
static inline void port_timer_set_alarm(systime_t time) {
- chDbgAssert((TIM2->DIER & 2) != 0, "not started");
-
- TIM2->CCR1 = time;
+ stSetAlarm(time);
}
/**
@@ -122,11 +121,11 @@ static inline void port_timer_set_alarm(systime_t time) { */
static inline systime_t port_timer_get_alarm(void) {
- chDbgAssert((TIM2->DIER & 2) != 0, "not started");
-
- return TIM2->CCR1;
+ return stGetAlarm();
}
+#endif /* !defined(CH_PORT_DO_NOT_USE_ST) */
+
#endif /* _SYSTICK_H_ */
/** @} */
|