[PATCH 2/3] or1ksim: work-around to make or1ksim tick timer accurate.
Hesham ALMatary
heshamelmatary at gmail.com
Fri Sep 5 15:11:29 UTC 2014
This patch avoids unexpected behavior when initializing tick timer registers.
Initializing these registers fires unexpected exceptions and interrupts even
though RTEMS has not enabled interrupts yet. So, a little long interval added
to allow RTEMS to finish the remaining initialization work before running the
application. The tick timer interval is adjusted to reflect an accurate
timing for RTEMS applications.
---
c/src/lib/libbsp/or1k/or1ksim/clock/clockdrv.c | 39 ++++++++++++++++++++------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/c/src/lib/libbsp/or1k/or1ksim/clock/clockdrv.c b/c/src/lib/libbsp/or1k/or1ksim/clock/clockdrv.c
index 3877fe0..6b95d96 100644
--- a/c/src/lib/libbsp/or1k/or1ksim/clock/clockdrv.c
+++ b/c/src/lib/libbsp/or1k/or1ksim/clock/clockdrv.c
@@ -24,7 +24,7 @@
#include <rtems/score/or1k-utility.h>
/* The number of clock cycles before generating a tick timer interrupt. */
-#define TTMR_NUM_OF_CLOCK_TICKS_INTERRUPT 0xFFED9
+#define TTMR_NUM_OF_CLOCK_TICKS_INTERRUPT 0x09ED9
#define OR1KSIM_CLOCK_CYCLE_TIME_NANOSECONDS 10
/* This prototype is added here to Avoid warnings */
@@ -62,19 +62,40 @@ static void or1ksim_clock_handler_install(proc_ptr new_isr, proc_ptr old_isr)
}
static void or1ksim_clock_initialize(void)
-{
- uint32_t sr;
-
- or1ksim_clock_at_tick();
+{
+ uint32_t TTMR;
- /* Enable tick timer */
- sr = _OR1K_mfspr(CPU_OR1K_SPR_SR);
- sr |= CPU_OR1K_SPR_SR_TEE;
- _OR1K_mtspr(CPU_OR1K_SPR_SR, sr);
+ /* For TTMR register,
+ * The least significant 28 bits are the number of clock cycles
+ * before generating a tick timer interrupt. While the most
+ * significant 4 bits are used for mode configuration, tick timer
+ * interrupt enable and pending interrupts status.
+ */
+
+ /* FIXME: Long interval should pass since initializing the tick timer
+ * registers fires exceptions dispite interrupts has not been enabled yet.
+ */
+ TTMR = (CPU_OR1K_SPR_TTMR_MODE_RESTART | CPU_OR1K_SPR_TTMR_IE |
+ (0xFFED9 & CPU_OR1K_SPR_TTMR_TP_MASK)
+ ) & ~(CPU_OR1K_SPR_TTMR_IP);
+
+ _OR1K_mtspr(CPU_OR1K_SPR_TTMR, TTMR);
+ _OR1K_mtspr(CPU_OR1K_SPR_TTCR, 0);
}
static void or1ksim_clock_cleanup(void)
{
+ uint32_t sr;
+
+ sr = _OR1K_mfspr(CPU_OR1K_SPR_SR);
+
+ /* Disable tick timer exceptions */
+ _OR1K_mtspr(CPU_OR1K_SPR_SR, (sr & ~CPU_OR1K_SPR_SR_IEE)
+ & ~CPU_OR1K_SPR_SR_TEE);
+
+ /* Invalidate tick timer config registers */
+ _OR1K_mtspr(CPU_OR1K_SPR_TTCR, 0);
+ _OR1K_mtspr(CPU_OR1K_SPR_TTMR, 0);
}
/*
--
1.9.3
More information about the devel
mailing list