14#error 8254 timer requires TIMER_FREQ >= 19
17#error TIMER_FREQ <= 1000 recommended
46 unsigned high_bit, test_bit;
49 printf (
"Calibrating timer... ");
62 for (test_bit = high_bit >> 1; test_bit != high_bit >> 10; test_bit >>= 1)
244 ASSERT (denom % 1000 == 0);
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
void intr_register_ext(uint8_t vec_no, intr_handler_func *handler, const char *name)
Registers external interrupt VEC_NO to invoke HANDLER, which is named NAME for debugging purposes.
enum intr_level intr_disable(void)
Disables interrupts and returns the previous interrupt status.
enum intr_level intr_get_level(void)
Returns the current interrupt status.
enum intr_level intr_set_level(enum intr_level level)
Enables or disables interrupts as specified by LEVEL and returns the previous interrupt status.
void intr_handler_func(struct intr_frame *)
intr_level
Interrupts on or off?
@ INTR_ON
Interrupts enabled.
int printf(const char *format,...)
Writes formatted output to the console.
void pit_configure_channel(int channel, int mode, int frequency)
Configure the given CHANNEL in the PIT.
signed long long int int64_t
unsigned long long int uint64_t
#define barrier()
Optimization barrier.
void thread_tick(void)
Called by the timer interrupt handler at each timer tick.
void thread_yield(void)
Yields the CPU.
void timer_msleep(int64_t ms)
Sleeps for approximately MS milliseconds.
static void real_time_delay(int64_t num, int32_t denom)
Busy-wait for approximately NUM/DENOM seconds.
int64_t timer_ticks(void)
Returns the number of timer ticks since the OS booted.
static unsigned loops_per_tick
Number of loops per timer tick.
void timer_print_stats(void)
Prints timer statistics.
void timer_udelay(int64_t us)
Sleeps for approximately US microseconds.
int64_t timer_elapsed(int64_t then)
Returns the number of timer ticks elapsed since THEN, which should be a value once returned by timer_...
static int64_t ticks
See [8254] for hardware details of the 8254 timer chip.
void timer_nsleep(int64_t ns)
Sleeps for approximately NS nanoseconds.
void timer_init(void)
Sets up the timer to interrupt TIMER_FREQ times per second, and registers the corresponding interrupt...
static void busy_wait(int64_t loops)
Iterates through a simple loop LOOPS times, for implementing brief delays.
void timer_calibrate(void)
Calibrates loops_per_tick, used to implement brief delays.
static bool too_many_loops(unsigned loops)
Returns true if LOOPS iterations waits for more than one timer tick, otherwise false.
static void real_time_sleep(int64_t num, int32_t denom)
Sleep for approximately NUM/DENOM seconds.
void timer_sleep(int64_t ticks)
Sleeps for approximately TICKS timer ticks.
static intr_handler_func timer_interrupt
void timer_usleep(int64_t us)
Sleeps for approximately US microseconds.
void timer_mdelay(int64_t ms)
Busy-waits for approximately MS milliseconds.
void timer_ndelay(int64_t ns)
Sleeps execution for approximately NS nanoseconds.
#define TIMER_FREQ
Number of timer interrupts per second.