My Kernel v0.1.0
Time keeping

Macros

#define HZ   CLOCK_PER_SECOND
 The frequency used for the timer (in Hz)
 

Functions

void timer_start (u32 frequency)
 Start the global timekeeping timer. More...
 
static clock_t timer_gettick (void)
 
static bool timer_tick (void)
 Increment the timekeeping timer's tick count. More...
 
static time_t timer_get_ms (void)
 
static time_t timer_get_us (void)
 
static time_t timer_get_ns (void)
 
static void clock_get_time (struct timespec *time)
 Fill a timespec structure with the current time of the day. More...
 
void timer_wait_ms (time_t)
 Wait a certain amount of miliseconds. More...
 

Variables

volatile clock_t timer_ticks_counter
 This is where we keep track of the number of intervals reported by the timer. More...
 
volatile u32 timer_kernel_frequency
 Frequency of the global timekeeping timer.
 
#define SEC_TO_TICKS(_time)   SEC((_time) * HZ)
 Compute the number of ticks in a given time frame.
 
#define MS_TO_TICKS(_time)   MS_TO_SEC(SEC_TO_TICKS(_time))
 Compute the number of ticks in a given time frame.
 
#define US_TO_TICKS(_time)   US_TO_SEC(SEC_TO_TICKS(_time))
 Compute the number of ticks in a given time frame.
 
#define NS_TO_TICKS(_time)   NS_TO_SEC(SEC_TO_TICKS(_time))
 Compute the number of ticks in a given time frame.
 
#define TICKS_TO_SEC(_ticks)   SEC((_ticks) / HZ)
 Convert a number of ticks into a regular time unit.
 
#define TICKS_TO_MS(_ticks)   MS(TICKS_TO_SEC(_ticks))
 Convert a number of ticks into a regular time unit.
 
#define TICKS_TO_US(_ticks)   US(TICKS_TO_SEC(_ticks))
 Convert a number of ticks into a regular time unit.
 
#define TICKS_TO_NS(_ticks)   NS(TICKS_TO_SEC(_ticks))
 Convert a number of ticks into a regular time unit.
 

Detailed Description

Time

Timer

Any interaction done with the timer should be done through the functions defined inside this header.

Function Documentation

◆ clock_get_time()

static void clock_get_time ( struct timespec *  time)
inlinestatic

FIXME: Change this to use the system's clock once clock_settime(). For now we'll use the system's timer instead.

◆ timer_get_ms()

static time_t timer_get_ms ( void  )
inlinestatic
Returns
the number of miliseconds elapsed since startup.

◆ timer_get_ns()

static time_t timer_get_ns ( void  )
inlinestatic
Returns
the number of nanoseconds elapsed since startup.

◆ timer_get_us()

static time_t timer_get_us ( void  )
inlinestatic
Returns
the number of microseconds elapsed since startup.

◆ timer_gettick()

static clock_t timer_gettick ( void  )
inlinestatic
Returns
the number of timer intervals elapsed since startup

◆ timer_start()

void timer_start ( u32  frequency)
Parameters
frequencyThe timer's frequency (Hz)

◆ timer_tick()

static bool timer_tick ( void  )
inlinestatic
Returns
true if an overflow occured.

◆ timer_wait_ms()

void timer_wait_ms ( time_t  ms)
Warning
Calls to this function are blocking

Variable Documentation

◆ timer_ticks_counter

volatile clock_t timer_ticks_counter
extern

This MUST be incremented EACH time we recieve an interrupt from the global timer.