/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ /* Timer module for Chrome EC operating system */ #include #include "task.h" #include "timer.h" #include "atomic.h" #include "board.h" #include "console.h" #include "uart.h" #include "registers.h" #include "util.h" #define US_PER_SECOND 1000000 /* Divider to get microsecond for the clock */ #define CLOCKSOURCE_DIVIDER (CPU_CLOCK/US_PER_SECOND) /* high word of the 64-bit timestamp counter */ static volatile uint32_t clksrc_high; /* bitmap of currently running timers */ static uint32_t timer_running = 0; /* deadlines of all timers */ static timestamp_t timer_deadline[TASK_ID_COUNT]; static uint32_t next_deadline = 0xffffffff; void __hw_clock_event_set(uint32_t deadline) { /* set the match on the deadline */ LM4_TIMER_TAMATCHR(W0) = 0xffffffff - deadline; /* Set the match interrupt */ LM4_TIMER_IMR(W0) |= 0x10; } void __hw_clock_event_clear(void) { /* Disable the match interrupt */ LM4_TIMER_IMR(W0) &= ~0x10; } static uint32_t __hw_clock_source_read(void) { return 0xffffffff - LM4_TIMER_TAV(W0); } static void expire_timer(task_id_t tskid) { /* we are done with this timer */ atomic_clear(&timer_running, 1<