Xyris  0.5
timer.cpp File Reference
#include <Arch/i686/timer.hpp>
#include <Arch/i686/isr.hpp>
+ Include dependency graph for timer.cpp:

Go to the source code of this file.

Macros

#define MAX_CALLBACKS   8
 

Typedefs

typedef void(* voidfunc_t) ()
 

Functions

void timer_init (uint32_t freq)
 
void sleep (uint32_t ms)
 
void timer_register_callback (void(*func)())
 

Variables

volatile uint32_t timer_tick
 

Detailed Description

Programmable Interrupt Timer driver functions.

Author
Keeton Feavel (keeto.nosp@m.nfea.nosp@m.vel@c.nosp@m.edar.nosp@m.ville.nosp@m..edu)
Version
0.3
Date
2019-11-15

Definition in file timer.cpp.

Macro Definition Documentation

◆ MAX_CALLBACKS

#define MAX_CALLBACKS   8

Definition at line 19 of file timer.cpp.

Typedef Documentation

◆ voidfunc_t

typedef void(* voidfunc_t) ()

Definition at line 17 of file timer.cpp.

Function Documentation

◆ sleep()

void sleep ( uint32_t  ms)

Sleeps for a certain length of time.

Parameters
msSleep length in milliseconds

Definition at line 52 of file timer.cpp.

52  {
53  uint32_t start = timer_tick;
54  uint32_t final = start + ms;
55  // Waste CPU cycles like a slob
56  while (timer_tick < final);
57  // Return now that we've waited long enough
58  return;
59 }

◆ timer_init()

void timer_init ( uint32_t  freq)

Initialize the CPU timer with the given frequency.

Sleep Timer Non-Busy Waiting Idea: Create a struct that contains the end time and the callback function pointer that should be called when timer_tick = end After each timer_tick we check our end time and call the function if we're equal.

Definition at line 31 of file timer.cpp.

31  {
32  /* Install the function we just wrote */
34  /* Get the PIT value: hardware clock at 1193180 Hz */
35  uint32_t divisor = 1193180 / freq;
36  uint8_t low = (uint8_t)(divisor & 0xFF);
37  uint8_t high = (uint8_t)((divisor >> 8) & 0xFF);
38  /* Send the command */
42 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ timer_register_callback()

void timer_register_callback ( void(*)()  func)

Definition at line 61 of file timer.cpp.

61  {
62  if (_callback_count < MAX_CALLBACKS - 1) {
63  _callbacks[_callback_count] = func;
64  _callback_count++;
65  }
66 }

Variable Documentation

◆ timer_tick

volatile uint32_t timer_tick

Definition at line 15 of file timer.cpp.

timer_tick
volatile uint32_t timer_tick
Definition: timer.cpp:15
Interrupts::INTERRUPT_0
@ INTERRUPT_0
Definition: isr.hpp:60
Interrupts::registerHandler
void registerHandler(uint8_t interrupt, InterruptHandler_t handler)
Definition: isr.cpp:98
writeByte
void writeByte(uint16_t port, uint8_t data)
Writes a byte (8 bits) to the CPU bus at a given port address.
Definition: ports.cpp:19
MAX_CALLBACKS
#define MAX_CALLBACKS
Definition: timer.cpp:19
TIMER_DATA_PORT
#define TIMER_DATA_PORT
Definition: timer.hpp:16
TIMER_COMMAND_PORT
#define TIMER_COMMAND_PORT
Definition: timer.hpp:15