From: batt Date: Mon, 12 Apr 2010 21:33:34 +0000 (+0000) Subject: LPC2xxx: add timer support. X-Git-Tag: 2.5.0~489 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=62c64455f33dd53639f04d35014ef5e50f9acd50;p=bertos.git LPC2xxx: add timer support. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3419 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/arm/drv/timer_arm.h b/bertos/cpu/arm/drv/timer_arm.h index 60b096cc..2b4f2510 100644 --- a/bertos/cpu/arm/drv/timer_arm.h +++ b/bertos/cpu/arm/drv/timer_arm.h @@ -41,6 +41,8 @@ #if CPU_ARM_AT91 #include "timer_at91.h" +#elif CPU_ARM_LPC2 + #include "timer_lpc2.h" /*#elif Add other ARM families here */ #else #error Unknown CPU diff --git a/bertos/cpu/arm/drv/timer_lpc2.c b/bertos/cpu/arm/drv/timer_lpc2.c new file mode 100644 index 00000000..cd4ac56a --- /dev/null +++ b/bertos/cpu/arm/drv/timer_lpc2.c @@ -0,0 +1,81 @@ +/** + * \file + * + * + * \author Francesco Sacchi + * + * \brief Low-level timer module for LPC2xxx (implementation). + * + * notest:arm + */ +#include "cfg/cfg_timer.h" +#include // BV() +#include // BV() + +#include +#include +#include "timer_lpc2.h" + +/** HW dependent timer initialization */ +#if (CONFIG_TIMER == TIMER0_COMPARE0) + #define TIMER0_ID 4 + void timer_hw_init(void) + { + /* Power on timer0 */ + PCONP |= BV(1); + + /* Set TIMER0 clk to CPU_FREQ */ + PCLKSEL0 &= ~0x0C; + PCLKSEL0 |= 0x04; + + /* reset prescaler counter */ + T0PR = 0; + + /* Set match register 0 */ + T0MR0 = TIMER_HW_CNT; + /* IRQ and reset counter on compare match 0 */ + T0MCR &= ~0x03; + T0MCR |= 0x03; + /* Reset timer0 counter and prescaler */ + T0TCR = 0x02; + + vic_setVector(TIMER0_ID, timer_handler); + vic_enable(TIMER0_ID); + + /* Start timer0 */ + T0TCR = 0x01; + } + + +#else + #error Unimplemented value for CONFIG_TIMER +#endif /* CONFIG_TIMER */ + diff --git a/bertos/cpu/arm/drv/timer_lpc2.h b/bertos/cpu/arm/drv/timer_lpc2.h new file mode 100644 index 00000000..7a796406 --- /dev/null +++ b/bertos/cpu/arm/drv/timer_lpc2.h @@ -0,0 +1,103 @@ +/** + * \file + * + * + * \author Francesco Sacchi + * + * \brief Low-level timer module for NXP LPC2xxx (interface). + */ + +#ifndef DRV_LPC2_TIMER_H +#define DRV_LPC2_TIMER_H + +#include /* CPU_FREQ */ + +#include "cfg/cfg_timer.h" /* CONFIG_TIMER */ +#include /* uint8_t */ +#include /* BV */ + +#include + +/** + * \name Values for CONFIG_TIMER. + * + * Select which hardware timer interrupt to use for system clock and softtimers. + * + * $WIZ$ timer_select = "TIMER0_COMPARE0", "TIMER_DEFAULT" + */ +#define TIMER0_COMPARE0 0 ///< System timer on Timer0 Compare match0 + +#define TIMER_DEFAULT TIMER0_COMPARE0 ///< Default system timer + +/* + * Hardware dependent timer initialization. + */ +#if (CONFIG_TIMER == TIMER0_COMPARE0) + ISR_PROTO_CONTEXT_SWITCH(timer_handler); + #define DEFINE_TIMER_ISR DECLARE_ISR_CONTEXT_SWITCH(timer_handler) + + #define TIMER_TICKS_PER_SEC 1000 + #define TIMER_HW_CNT (CPU_FREQ / TIMER_TICKS_PER_SEC - 1) + + /** Frequency of the hardware high-precision timer. */ + #define TIMER_HW_HPTICKS_PER_SEC (CPU_FREQ) + + /** Type of time expressed in ticks of the hardware high-precision timer */ + typedef uint32_t hptime_t; + #define SIZEOF_HPTIME_T 4 + + INLINE void timer_hw_irq(void) + { + /* Reset The match0 irq flag */ + T0IR = 0x01; + /* Signal the VIC we have completed the ISR */ + VICVectAddr = 0; + } + + INLINE bool timer_hw_triggered(void) + { + return true; + } + + INLINE hptime_t timer_hw_hpread(void) + { + return T0TC; + } + +#else + + #error Unimplemented value for CONFIG_TIMER +#endif /* CONFIG_TIMER */ + +void timer_hw_init(void); + + +#endif /* DRV_LPC2_TIMER_H */ diff --git a/bertos/cpu/arm/io/arm.h b/bertos/cpu/arm/io/arm.h index 5690c317..62cb4113 100644 --- a/bertos/cpu/arm/io/arm.h +++ b/bertos/cpu/arm/io/arm.h @@ -45,6 +45,8 @@ #if CPU_ARM_AT91 #include "at91.h" +#elif CPU_ARM_LPC2 + #include "lpc23xx.h" /*#elif Add other ARM families here */ #else #error Unknown CPU diff --git a/bertos/drv/timer.c b/bertos/drv/timer.c index 4ace035c..dfc27aef 100644 --- a/bertos/drv/timer.c +++ b/bertos/drv/timer.c @@ -345,9 +345,6 @@ DEFINE_TIMER_ISR TIMER_STROBE_ON; - /* Perform hw IRQ handling */ - timer_hw_irq(); - /* Update the master ms counter */ ++_clock; @@ -358,6 +355,9 @@ DEFINE_TIMER_ISR timer_poll(&timers_queue); #endif + /* Perform hw IRQ handling */ + timer_hw_irq(); + TIMER_STROBE_OFF; }