Timers

class Timers

Easy interface to do operations with timers and their registers.

Summary
TimersEasy interface to do operations with timers and their registers.
timer_dataUtility class that holds pointers to the real registers plus internal registers.
Variables
countPointer to the Timer count register.
controlPointer to the Timer control register.
cyclesCounterInternal counter of cycles.
alreadyStartedIf true, the timer is running.
mMemoryPointer to the memory object of the associated GBA.
mCpuPointer to cpu.
Functions
TimersBuilds the timers handler utility.
GetControlGets the Control register of the timer.
GetPrescalerSelectionIndexGets The prescaler selection index of a timer.
GetPrescalerSelectionGets Prescaler selection.
GetCountUpTimingWhen countup timing is enabled in a timer, when it overflows, it increases the next one value.
GetIRQEnabledGets if interrupts for a timer overflow are enabled.
GetTimerStateRetrieves a timer’s state.
GetCountRetrieves a timer’s counter.
SetToReloadValueSets a timer to its reload value.
OverflowTimerPerforms overflow operation on timer (generates irq if enabled, restarts with reload value, increments successive if countup is enabled).
IdlePerforms idle operations on timers.

timer_data

struct timer_data

Utility class that holds pointers to the real registers plus internal registers.

Summary
Variables
countPointer to the Timer count register.
controlPointer to the Timer control register.
cyclesCounterInternal counter of cycles.
alreadyStartedIf true, the timer is running.
mMemoryPointer to the memory object of the associated GBA.
mCpuPointer to cpu.
Functions
TimersBuilds the timers handler utility.
GetControlGets the Control register of the timer.
GetPrescalerSelectionIndexGets The prescaler selection index of a timer.
GetPrescalerSelectionGets Prescaler selection.
GetCountUpTimingWhen countup timing is enabled in a timer, when it overflows, it increases the next one value.
GetIRQEnabledGets if interrupts for a timer overflow are enabled.
GetTimerStateRetrieves a timer’s state.
GetCountRetrieves a timer’s counter.
SetToReloadValueSets a timer to its reload value.
OverflowTimerPerforms overflow operation on timer (generates irq if enabled, restarts with reload value, increments successive if countup is enabled).
IdlePerforms idle operations on timers.

Variables

count

uint16_t* count

Pointer to the Timer count register.

control

uint16_t* control

Pointer to the Timer control register.

cyclesCounter

int cyclesCounter

Internal counter of cycles.

alreadyStarted

bool alreadyStarted

If true, the timer is running.

mMemory

Memory* mMemory

Pointer to the memory object of the associated GBA.  Used to read timer registers.

mCpu

CPU* mCpu

Pointer to cpu.  Used to generate interrupts.

Functions

Timers

Timers(Memory *mem,
CPU *cpu)

Builds the timers handler utility.

Parameters

memPointer to memory.
cpuPointer to cpu

GetControl

inline int GetControl(int index)

Gets the Control register of the timer.

Parameters

indexThe id of the timer.

Returns

The Control register of the timer.

GetPrescalerSelectionIndex

inline int GetPrescalerSelectionIndex(int index)

Gets The prescaler selection index of a timer.

Parameters

indexThe id of the timer.

Returns

0=F/1, 1=F/64, 2=F/256, 3=F/1024.

GetPrescalerSelection

inline int GetPrescalerSelection(int index)

Gets Prescaler selection.

Parameters

indexThe index of prescaler selection.

Returns

Cycles to increment the timer.

GetCountUpTiming

inline bool GetCountUpTiming(int index)

When countup timing is enabled in a timer, when it overflows, it increases the next one value.

Parameters

indexThe id of the timer.

Returns

True if countup timing is enabled.

GetIRQEnabled

inline bool GetIRQEnabled(int index)

Gets if interrupts for a timer overflow are enabled.

Parameters

indexThe id of the timer.

Returns

True if interrupts are enabled for the given timer.

GetTimerState

inline bool GetTimerState(int index)

Retrieves a timer’s state.

Parameters

indexThe id of the timer.

Returns

True if it is running.

GetCount

inline uint16_t GetCount(int index)

Retrieves a timer’s counter.

Parameters

indexThe id of the timer.

Returns

The counter value.

SetToReloadValue

inline void SetToReloadValue(int index)

Sets a timer to its reload value.

Parameters

indexThe id of the timer.

OverflowTimer

inline void OverflowTimer(int index)

Performs overflow operation on timer (generates irq if enabled, restarts with reload value, increments successive if countup is enabled).

Parameters

indexThe id of the timer.

Idle

inline void Idle(int cyclesCount)

Performs idle operations on timers.

Parameters

cyclesCountThe number of cycles that’s passed since the last call.
class Timers
Easy interface to do operations with timers and their registers.
struct timer_data
Utility class that holds pointers to the real registers plus internal registers.
uint16_t* count
Pointer to the Timer count register.
uint16_t* control
Pointer to the Timer control register.
int cyclesCounter
Internal counter of cycles.
bool alreadyStarted
If true, the timer is running.
Memory* mMemory
Pointer to the memory object of the associated GBA.
CPU* mCpu
Pointer to cpu.
Timers(Memory *mem,
CPU *cpu)
Builds the timers handler utility.
inline int GetControl(int index)
Gets the Control register of the timer.
inline int GetPrescalerSelectionIndex(int index)
Gets The prescaler selection index of a timer.
inline int GetPrescalerSelection(int index)
Gets Prescaler selection.
inline bool GetCountUpTiming(int index)
When countup timing is enabled in a timer, when it overflows, it increases the next one value.
inline bool GetIRQEnabled(int index)
Gets if interrupts for a timer overflow are enabled.
inline bool GetTimerState(int index)
Retrieves a timer’s state.
inline uint16_t GetCount(int index)
Retrieves a timer’s counter.
inline void SetToReloadValue(int index)
Sets a timer to its reload value.
inline void OverflowTimer(int index)
Performs overflow operation on timer (generates irq if enabled, restarts with reload value, increments successive if countup is enabled).
inline void Idle(int cyclesCount)
Performs idle operations on timers.
Close