diff --git a/arch/misoc/src/common/misoc.h b/arch/misoc/src/common/misoc.h index 4726759ea58..1531f3dc7fc 100644 --- a/arch/misoc/src/common/misoc.h +++ b/arch/misoc/src/common/misoc.h @@ -63,6 +63,16 @@ #ifndef __ASSEMBLY__ +/**************************************************************************** + * Name: misoc_timer_initialize + * + * Description: + * Initialize and start the system timer. + * + ****************************************************************************/ + +void misoc_timer_initialize(void); + /**************************************************************************** * Name: up_serialinit * diff --git a/arch/misoc/src/common/misoc_timerisr.c b/arch/misoc/src/common/misoc_timerisr.c index d6d5bfabd61..3de69520bed 100644 --- a/arch/misoc/src/common/misoc_timerisr.c +++ b/arch/misoc/src/common/misoc_timerisr.c @@ -47,10 +47,12 @@ #include #include #include + #include #include #include #include + #include "chip.h" #include "misoc.h" @@ -59,17 +61,26 @@ ****************************************************************************/ /* The desired timer interrupt frequency is provided by the definition - * CLK_TCK (see include/time.h). CLK_TCK defines the desired number of - * system clock ticks per second. That value is a user configurable setting - * that defaults to 100 (100 ticks per second = 10 MS interval). + * CLOCKS_PER_SEC (see include/time.h). CLOCKS_PER_SEC defines the desired + * number of system clock ticks per second. That value is a user + * configurable setting based on CONFIG_USEC_PER_TICK. It defaults to 100 + * (100 ticks per second = 10 MS interval). * - * What clock feeds the timer? What rate does the timer increment by. The - * correct reload value is: + * Given the timer input frequency (Finput). The timer correct reload + * value is: * * reload = Finput / CLOCKS_PER_SEC */ -#warning Missing logic +#define SYSTICK_RELOAD ((SYSTEM_CLOCK_FREQUENCY / CLOCKS_PER_SEC) - 1) + +/* The size of the reload field is 30 bits. Verify that the reload value + * will fit in the reload register. + */ + +#if SYSTICK_RELOAD > 0x3fffffff +# error SYSTICK_RELOAD exceeds the range of the RELOAD register +#endif /**************************************************************************** * Public Functions @@ -107,8 +118,6 @@ int up_timerisr(int irq, void *context) void misoc_timer_initialize(void) { - uint32_t im; - /* Clear event pending */ timer0_ev_pending_write(timer0_ev_pending_read()); @@ -117,11 +126,12 @@ void misoc_timer_initialize(void) timer0_en_write(0); - /* FIX ME, PUT PROPER VALUE */ -#warning Missing logic + /* Setup the timer reload register to generate interrupts at the rate of + * CLOCKS_PER_SEC. + */ - timer0_reload_write(80000); - timer0_load_write(80000); + timer0_reload_write(SYSTICK_RELOAD); + timer0_load_write(SYSTICK_RELOAD); /* Enable timer */ diff --git a/arch/misoc/src/lm32/lm32_initialize.c b/arch/misoc/src/lm32/lm32_initialize.c index 23e6e8fc1f0..dd93cce4b65 100644 --- a/arch/misoc/src/lm32/lm32_initialize.c +++ b/arch/misoc/src/lm32/lm32_initialize.c @@ -72,7 +72,9 @@ void up_initialize(void) /* Initialize the serial driver */ -#warning REVISIT: Here you should all misoc_serial_initialize(). That initializes the entire serial driver, a part of the operation is the uart initialization. - misoc_serial_initialize(); + + /* Initialize the system timer */ + + misoc_timer_initialize(); }