[platform][zynq] update timer code to take tick from target

This commit is contained in:
Travis Geiselbrecht
2014-05-02 20:21:10 -07:00
parent 98647aeff7
commit 1930cb3abd
5 changed files with 20 additions and 8 deletions

View File

@@ -39,7 +39,7 @@ void platform_early_init(void)
arm_gic_init(); arm_gic_init();
/* initialize the timer block */ /* initialize the timer block */
platform_init_timer(); platform_init_timer(TIMER_CLOCK_FREQ);
} }
void platform_init(void) void platform_init(void)

View File

@@ -24,7 +24,7 @@
#define __PLATFORM_P_H #define __PLATFORM_P_H
void platform_init_interrupts(void); void platform_init_interrupts(void);
void platform_init_timer(void); void platform_init_timer(uint32_t freq);
#endif #endif

View File

@@ -34,7 +34,7 @@
#include "platform_p.h" #include "platform_p.h"
/* driver for cortex-a9's private timer */ /* driver for cortex-a9's private timer */
#define LOCAL_TRACE 1 #define LOCAL_TRACE 0
#define TIMREG(reg) (*REG32(PRIV_TIMER_BASE + (reg))) #define TIMREG(reg) (*REG32(PRIV_TIMER_BASE + (reg)))
@@ -42,6 +42,10 @@
#define TIMER_COUNTER (0x04) #define TIMER_COUNTER (0x04)
#define TIMER_CONTROL (0x08) #define TIMER_CONTROL (0x08)
#define TIMER_ISR (0x0c) #define TIMER_ISR (0x0c)
#define WDOG_LOAD (0x20)
#define WDOG_COUNTER (0x24)
#define WDOG_CONTROL (0x28)
#define WDOG_ISR (0x2c)
#define GTIMREG(reg) (*REG32(GLOBAL_TIMER_BASE + (reg))) #define GTIMREG(reg) (*REG32(GLOBAL_TIMER_BASE + (reg)))
@@ -53,13 +57,11 @@
#define GTIMER_COMPARE_HI (0x14) #define GTIMER_COMPARE_HI (0x14)
#define GTIMER_INCREMENT (0x18) #define GTIMER_INCREMENT (0x18)
// XXX pull from someplace better
#define TIMER_INPUT_CLOCK (325000000)
static platform_timer_callback t_callback; static platform_timer_callback t_callback;
static volatile uint ticks = 0; static volatile uint ticks = 0;
static lk_time_t periodic_interval; static lk_time_t periodic_interval;
static uint32_t timer_freq;
uint64_t get_global_val(void) uint64_t get_global_val(void)
{ {
@@ -88,7 +90,7 @@ status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg
// disable timer // disable timer
TIMREG(TIMER_CONTROL) = 0; TIMREG(TIMER_CONTROL) = 0;
TIMREG(TIMER_LOAD) = (((uint64_t)TIMER_INPUT_CLOCK * interval) / 1000); TIMREG(TIMER_LOAD) = (((uint64_t)timer_freq * interval) / 1000);
TIMREG(TIMER_CONTROL) = (1<<2) | (1<<1) | (1<<0); // irq enable, autoreload, enable TIMREG(TIMER_CONTROL) = (1<<2) | (1<<1) | (1<<0); // irq enable, autoreload, enable
unmask_interrupt(CPU_PRIV_TIMER); unmask_interrupt(CPU_PRIV_TIMER);
@@ -120,6 +122,8 @@ static enum handler_return platform_tick(void *arg)
{ {
ticks++; ticks++;
LTRACE;
TIMREG(TIMER_ISR) = 1; // ack the irq TIMREG(TIMER_ISR) = 1; // ack the irq
if (t_callback) { if (t_callback) {
@@ -129,11 +133,17 @@ static enum handler_return platform_tick(void *arg)
} }
} }
void platform_init_timer(void) void platform_init_timer(uint32_t freq)
{ {
/* disable timer */ /* disable timer */
TIMREG(TIMER_CONTROL) = 0; TIMREG(TIMER_CONTROL) = 0;
/* kill the watchdog */
TIMREG(WDOG_CONTROL) = 0;
/* save the timer frequency for later calculations */
timer_freq = freq;
register_int_handler(CPU_PRIV_TIMER, &platform_tick, NULL); register_int_handler(CPU_PRIV_TIMER, &platform_tick, NULL);
} }

View File

@@ -11,6 +11,7 @@ GLOBAL_INCLUDES += \
$(LOCAL_DIR)/include $(LOCAL_DIR)/include
GLOBAL_DEFINES += \ GLOBAL_DEFINES += \
TIMER_CLOCK_FREQ=325000000
MODULE_SRCS += \ MODULE_SRCS += \
$(LOCAL_DIR)/target.c \ $(LOCAL_DIR)/target.c \

View File

@@ -10,6 +10,7 @@ PLATFORM := zynq
MODULES += \ MODULES += \
GLOBAL_DEFINES += \ GLOBAL_DEFINES += \
TIMER_CLOCK_FREQ=100000000
#include make/module.mk #include make/module.mk