aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-07-29 14:31:13 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-07-29 14:31:13 +0000
commitca4b2f91b7a24abeb6ea7fa43c1816397fb966c4 (patch)
tree47a6abadc7e6d1c31a2b9c182335559a35e45d2c /os
parent1ae1099ef072fd5fa5d1fde1e73c8c1df8d8d2f4 (diff)
downloadChibiOS-ca4b2f91b7a24abeb6ea7fa43c1816397fb966c4.tar.gz
ChibiOS-ca4b2f91b7a24abeb6ea7fa43c1816397fb966c4.tar.bz2
ChibiOS-ca4b2f91b7a24abeb6ea7fa43c1816397fb966c4.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6039 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/kernel/include/ch.h2
-rw-r--r--os/kernel/include/chstats.h5
-rw-r--r--os/kernel/include/chsys.h89
-rw-r--r--os/kernel/include/chtm.h92
-rw-r--r--os/kernel/src/chstats.c17
-rw-r--r--os/kernel/src/chsys.c7
-rw-r--r--os/kernel/src/chtm.c101
7 files changed, 171 insertions, 142 deletions
diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h
index e30ddd515..d2a29ac0c 100644
--- a/os/kernel/include/ch.h
+++ b/os/kernel/include/ch.h
@@ -108,9 +108,9 @@ typedef struct thread thread_t;
#include "chconf.h"
#include "chtypes.h"
#include "chdebug.h"
+#include "chcore.h"
#include "chtm.h"
#include "chstats.h"
-#include "chcore.h"
#include "chsys.h"
#include "chvt.h"
#include "chthreads.h"
diff --git a/os/kernel/include/chstats.h b/os/kernel/include/chstats.h
index a94a84814..dee5c9bec 100644
--- a/os/kernel/include/chstats.h
+++ b/os/kernel/include/chstats.h
@@ -39,6 +39,10 @@
/* Module pre-compile time settings. */
/*===========================================================================*/
+#if !CH_CFG_USE_TM
+#error "CH_DBG_STATISTICS requires CH_CFG_USE_TM"
+#endif
+
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
@@ -84,6 +88,7 @@ extern kernel_stats_t kernel_stats;
#ifdef __cplusplus
extern "C" {
#endif
+ void _stats_init(void);
#ifdef __cplusplus
}
#endif
diff --git a/os/kernel/include/chsys.h b/os/kernel/include/chsys.h
index 3dc6623e9..0fd07b96b 100644
--- a/os/kernel/include/chsys.h
+++ b/os/kernel/include/chsys.h
@@ -101,20 +101,99 @@
/** @} */
/**
+ * @name Time conversion utilities for the realtime counter
+ * @{
+ */
+/**
+ * @brief Seconds to realtime counter.
+ * @details Converts from seconds to realtime counter cycles.
+ * @note The result is rounded upward to the next tick boundary.
+ *
+ * @param[in] freq realtime counter operating frequency
+ * @param[in] sec number of seconds
+ * @return The number of cycles.
+ *
+ * @api
+ */
+#define S2RTV(freq, sec) ((freq) * (sec))
+
+/**
+ * @brief Milliseconds to realtime counter.
+ * @details Converts from milliseconds to realtime counter cycles.
+ * @note The result is rounded upward to the next tick boundary.
+ *
+ * @param[in] freq realtime counter operating frequency
+ * @param[in] msec number of milliseconds
+ * @return The number of cycles.
+ *
+ * @api
+ */
+#define MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
+
+/**
+ * @brief Microseconds to realtime counter.
+ * @details Converts from microseconds to realtime counter cycles.
+ * @note The result is rounded upward to the next tick boundary.
+ *
+ * @param[in] freq realtime counter operating frequency
+ * @param[in] usec number of microseconds
+ * @return The number of cycles.
+ *
+ * @api
+ */
+#define US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
+
+/**
+ * @brief Realtime counter cycles to seconds.
+ * @details Converts from realtime counter cycles number to seconds.
+ *
+ * @param[in] freq realtime counter operating frequency
+ * @param[in] n number of cycles
+ * @return The number of seconds.
+ *
+ * @api
+ */
+#define RTC2S(freq, n) (rtcnt_t)((n) / (freq))
+
+/**
+ * @brief Realtime counter cycles to milliseconds.
+ * @details Converts from realtime counter cycles number to milliseconds.
+ *
+ * @param[in] freq realtime counter operating frequency
+ * @param[in] n number of cycles
+ * @return The number of milliseconds.
+ *
+ * @api
+ */
+#define RTC2MS(freq, n) ((n) / ((freq) / 1000UL))
+
+/**
+ * @brief Realtime counter cycles to microseconds.
+ * @details Converts from realtime counter cycles number to microseconds.
+ *
+ * @param[in] freq realtime counter operating frequency
+ * @param[in] n number of cycles
+ * @return The number of microseconds.
+ *
+ * @api
+ */
+#define RTC2US(freq, n) ((n) / ((freq) / 1000000UL))
+/** @} */
+
+/**
* @brief Returns the current value of the system real time counter.
* @note This function can be called from any context.
- * @note If the port does not support a realtime counter then this
- * function returns the system time.
*
* @return The value of the system realtime counter of
- * type rtcnt_t.
+ * type rtcnt_t. If the port does not support a
+ * realtime counter then zero is returned.
*
- * @special
+ * @xclass
*/
#if CH_PORT_SUPPORTS_RT || defined(__DOXYGEN__)
#define chSysGetRealtimeCounterX() (rtcnt_t)port_rt_get_counter_value()
#else
-#define chSysGetRealtimeCounterX() (rtcnt_t)chVTGetSystemTimeX()
+#define chSysGetRealtimeCounterX() 0
#endif
/*===========================================================================*/
diff --git a/os/kernel/include/chtm.h b/os/kernel/include/chtm.h
index a7500a26b..bd1d73dd9 100644
--- a/os/kernel/include/chtm.h
+++ b/os/kernel/include/chtm.h
@@ -45,6 +45,10 @@
/* Derived constants and error checks. */
/*===========================================================================*/
+#if !CH_PORT_SUPPORTS_RT
+#error "CH_CFG_USE_TM requires CH_PORT_SUPPORTS_RT"
+#endif
+
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
@@ -69,80 +73,6 @@ typedef struct {
/* Module macros. */
/*===========================================================================*/
-/**
- * @name Time conversion utilities for the realtime counter
- * @{
- */
-/**
- * @brief Seconds to realtime counter.
- * @details Converts from seconds to realtime counter cycles.
- * @note The result is rounded upward to the next tick boundary.
- *
- * @param[in] sec number of seconds
- * @return The number of cycles.
- *
- * @api
- */
-#define S2RTV(freq, sec) ((freq) * (sec))
-
-/**
- * @brief Milliseconds to realtime counter.
- * @details Converts from milliseconds to realtime counter cycles.
- * @note The result is rounded upward to the next tick boundary.
- *
- * @param[in] msec number of milliseconds
- * @return The number of cycles.
- *
- * @api
- */
-#define MS2RTC(freq, msec) (rtcnt_t)((((freq) + 999UL) / 1000UL) * (msec))
-
-/**
- * @brief Microseconds to realtime counter.
- * @details Converts from microseconds to realtime counter cycles.
- * @note The result is rounded upward to the next tick boundary.
- *
- * @param[in] usec number of microseconds
- * @return The number of cycles.
- *
- * @api
- */
-#define US2RTC(freq, usec) (rtcnt_t)((((freq) + 999999UL) / 1000000UL) * (usec))
-
-/**
- * @brief Realtime counter cycles to seconds.
- * @details Converts from realtime counter cycles number to seconds.
- *
- * @param[in] n number of cycles
- * @return The number of seconds.
- *
- * @api
- */
-#define RTC2S(freq, n) (rtcnt_t)((n) / (freq))
-
-/**
- * @brief Realtime counter cycles to milliseconds.
- * @details Converts from realtime counter cycles number to milliseconds.
- *
- * @param[in] n number of cycles
- * @return The number of milliseconds.
- *
- * @api
- */
-#define RTC2MS(freq, n) ((n) / ((freq) / 1000UL))
-
-/**
- * @brief Realtime counter cycles to microseconds.
- * @details Converts from realtime counter cycles number to microseconds.
- *
- * @param[in] n number of cycles
- * @return The number of microseconds.
- *
- * @api
- */
-#define RTC2US(freq, n) ((n) / ((freq) / 1000000UL))
-/** @} */
-
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -150,12 +80,14 @@ typedef struct {
#ifdef __cplusplus
extern "C" {
#endif
- void _rt_init(void);
- bool chRTIsCounterWithin(rtcnt_t start, rtcnt_t end);
- void chRTPolledDelay(rtcnt_t cycles);
- void chRTTimeMeasurementObjectInit(time_measurement_t *tmp);
- NOINLINE void chRTTimeMeasurementStartX(time_measurement_t *tmp);
- NOINLINE void chRTTimeMeasurementStopX(time_measurement_t *tmp);
+ void _tm_init(void);
+ bool chTMIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end);
+ void chTMPolledDelayX(rtcnt_t cycles);
+ void chTMObjectInit(time_measurement_t *tmp);
+ NOINLINE void chTMStartX(time_measurement_t *tmp);
+ NOINLINE void chTMStopX(time_measurement_t *tmp);
+ NOINLINE void chTMChainToX(time_measurement_t *tmp1,
+ time_measurement_t *tmp2);
#ifdef __cplusplus
}
#endif
diff --git a/os/kernel/src/chstats.c b/os/kernel/src/chstats.c
index 1decf8f16..9d69e0023 100644
--- a/os/kernel/src/chstats.c
+++ b/os/kernel/src/chstats.c
@@ -20,9 +20,9 @@
/**
* @file chstats.c
- * @brief Real Time Counter and Measurement module code.
+ * @brief Statistics module code.
*
- * @addtogroup realtime_counter
+ * @addtogroup statistics
* @details Statistics services.
* @{
*/
@@ -60,6 +60,19 @@ kernel_stats_t kernel_stats;
/* Module exported functions. */
/*===========================================================================*/
+/**
+ * @brief Initializes the statistics module.
+ *
+ * @init
+ */
+void _stats_init(void) {
+
+ kernel_stats.nirq = 0;
+ kernel_stats.nctxswc = 0;
+ chTMObjectInit(&kernel_stats.isr);
+ chTMObjectInit(&kernel_stats.critical);
+}
+
#endif /* CH_DBG_STATISTICS */
/** @} */
diff --git a/os/kernel/src/chsys.c b/os/kernel/src/chsys.c
index 91761b66b..0727532ee 100644
--- a/os/kernel/src/chsys.c
+++ b/os/kernel/src/chsys.c
@@ -105,8 +105,8 @@ void chSysInit(void) {
port_init();
_scheduler_init();
_vt_init();
-#if CH_CFG_USE_RT
- _rt_init();
+#if CH_CFG_USE_TM
+ _tm_init();
#endif
#if CH_CFG_USE_MEMCORE
_core_init();
@@ -114,6 +114,9 @@ void chSysInit(void) {
#if CH_CFG_USE_HEAP
_heap_init();
#endif
+#if CH_DBG_STATISTICS
+ _stats_init();
+#endif
#if CH_DBG_ENABLE_TRACE
_trace_init();
#endif
diff --git a/os/kernel/src/chtm.c b/os/kernel/src/chtm.c
index a42223da3..0ae2dfeda 100644
--- a/os/kernel/src/chtm.c
+++ b/os/kernel/src/chtm.c
@@ -48,7 +48,7 @@
/*===========================================================================*/
/**
- * @brief Subsystem calibration value.
+ * @brief Measurement calibration value.
*/
static rtcnt_t measurement_offset;
@@ -56,25 +56,35 @@ static rtcnt_t measurement_offset;
/* Module local functions. */
/*===========================================================================*/
+static inline void tm_stop(time_measurement_t *tmp, rtcnt_t now) {
+
+ tmp->last = now - tmp->last - measurement_offset;
+ tmp->cumulative += tmp->last;
+ if (tmp->last > tmp->worst)
+ tmp->worst = tmp->last;
+ else if (tmp->last < tmp->best)
+ tmp->best = tmp->last;
+}
+
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/**
- * @brief Initializes the realtime counter unit.
+ * @brief Initializes the time measurement unit.
*
* @init
*/
-void _rt_init(void) {
+void _tm_init(void) {
time_measurement_t tm;
/* Time Measurement subsystem calibration, it does a null measurement
and calculates the call overhead which is subtracted to real
measurements.*/
measurement_offset = 0;
- chRTTimeMeasurementObjectInit(&tm);
- chRTTimeMeasurementStartX(&tm);
- chRTTimeMeasurementStopX(&tm);
+ chTMObjectInit(&tm);
+ chTMStartX(&tm);
+ chTMStopX(&tm);
measurement_offset = tm.last;
}
@@ -85,61 +95,34 @@ void _rt_init(void) {
* of the realtime counter wrapping to zero on overflow.
* @note When start==end then the function returns always true because the
* whole time range is specified.
- * @note This function can be called from any context.
- *
- * @par Example 1
- * Example of a guarded loop using the realtime counter. The loop implements
- * a timeout after one second.
- * @code
- * rtcnt_t start = chSysGetRealtimeCounterX();
- * rtcnt_t timeout = start + S2RTC(RTCCLK, 1);
- * while (my_condition) {
- * if (!chTMIsCounterWithin(start, timeout)
- * return TIMEOUT;
- * // Do something.
- * }
- * // Continue.
- * @endcode
- *
- * @par Example 2
- * Example of a loop that lasts exactly 50 microseconds.
- * @code
- * rtcnt_t start = chSysGetRealtimeCounterX();
- * rtcnt_t timeout = start + US2RTC(RTCCLK, 50);
- * while (chTMIsCounterWithin(start, timeout)) {
- * // Do something.
- * }
- * // Continue.
- * @endcode
*
+ * @param[in] cnt the counter value to be tested
* @param[in] start the start of the time window (inclusive)
* @param[in] end the end of the time window (non inclusive)
* @retval true current time within the specified time window.
* @retval false current time not within the specified time window.
*
- * @special
+ * @xclass
*/
-bool chTMIsCounterWithin(rtcnt_t start, rtcnt_t end) {
- rtcnt_t now = chSysGetRealtimeCounterX();
+bool chTMIsCounterWithinX(rtcnt_t cnt, rtcnt_t start, rtcnt_t end) {
- return end > start ? (now >= start) && (now < end) :
- (now >= start) || (now < end);
+ return end > start ? (cnt >= start) && (cnt < end) :
+ (cnt >= start) || (cnt < end);
}
/**
* @brief Polled delay.
* @note The real delay is always few cycles in excess of the specified
* value.
- * @note This function can be called from any context.
*
* @param[in] cycles number of cycles
*
- * @special
+ * @xclass
*/
-void chTMPolledDelay(rtcnt_t cycles) {
+void chTMPolledDelayX(rtcnt_t cycles) {
rtcnt_t start = chSysGetRealtimeCounterX();
rtcnt_t end = start + cycles;
- while (chRTIsCounterWithin(start, end))
+ while (chTMIsCounterWithinX(chSysGetRealtimeCounterX(), start, end))
;
}
@@ -161,11 +144,10 @@ void chTMObjectInit(time_measurement_t *tmp) {
/**
* @brief Starts a measurement.
* @pre The @p time_measurement_t structure must be initialized.
- * @note This function can be invoked from any context.
*
* @param[in,out] tmp pointer to a @p TimeMeasurement structure
*
- * @special
+ * @xclass
*/
NOINLINE void chTMStartX(time_measurement_t *tmp) {
@@ -175,23 +157,38 @@ NOINLINE void chTMStartX(time_measurement_t *tmp) {
/**
* @brief Stops a measurement.
* @pre The @p time_measurement_t structure must be initialized.
- * @note This function can be invoked from any context.
*
* @param[in,out] tmp pointer to a @p time_measurement_t structure
*
- * @special
+ * @xclass
*/
NOINLINE void chTMStopX(time_measurement_t *tmp) {
- rtcnt_t now = chSysGetRealtimeCounterX();
- tmp->last = now - tmp->last - measurement_offset;
- tmp->cumulative += tmp->last;
- if (tmp->last > tmp->worst)
- tmp->worst = tmp->last;
- else if (tmp->last < tmp->best)
- tmp->best = tmp->last;
+ tm_stop(tmp, chSysGetRealtimeCounterX());
}
#endif /* CH_CFG_USE_TM */
+/**
+ * @brief Stops a measurement and chains to the next one using the same time
+ * stamp.
+ *
+ * @param[in,out] tmp1 pointer to the @p time_measurement_t structure to be
+ * stopped
+ * @param[in,out] tmp2 pointer to the @p time_measurement_t structure to be
+ * started
+ *
+ *
+ * @xclass
+ */
+NOINLINE void chTMChainToX(time_measurement_t *tmp1,
+ time_measurement_t *tmp2) {
+
+ /* Starts new measurement.*/
+ tmp2->last = chSysGetRealtimeCounterX();
+
+ /* Stops previous measurement using the same time stamp.*/
+ tm_stop(tmp1, tmp2->last);
+}
+
/** @} */