giomba
92e1e261e7
Proper interrupt handlers for timers (and new peripherals can use them too). Improved interrupt enabling. Improved timer interrupts and fixed minor bugs.
71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#ifndef TIMER_H
|
|
#define TIMER_H
|
|
|
|
#include <stdint.h>
|
|
|
|
namespace Timer {
|
|
/* Timer peripheral (with common registers) */
|
|
uint32_t* const TMR_PERIPHERAL_BASE = (uint32_t*)(0x01c20c00);
|
|
struct Peripheral {
|
|
uint32_t TMR_IRQ_EN_REG;
|
|
uint32_t TMR_IRQ_STA_REG;
|
|
};
|
|
|
|
/* Timer modules array */
|
|
uint32_t* const TMR_MODULE_BASE = (uint32_t*)(0x01c20c10);
|
|
struct TimerModule {
|
|
uint32_t TMR_CTLR_REG;
|
|
uint32_t TMR_INTV_VALUE_REG;
|
|
uint32_t TMR_CUR_VALUE_REG;
|
|
};
|
|
enum Mode {
|
|
CONTINUOUS = 0,
|
|
SINGLE = 1
|
|
};
|
|
enum Prescaler { /* maybe PRESCALERx = log2(x) */
|
|
PRESCALER_1 = 0,
|
|
PRESCALER_2 = 1,
|
|
PRESCALER_4 = 2,
|
|
PRESCALER_8 = 3,
|
|
PRESCALER_16 = 4,
|
|
PRESCALER_32 = 5,
|
|
PRESCALER_64 = 6,
|
|
PRESCALER_128 = 7
|
|
|
|
};
|
|
enum ClockSource {
|
|
LS_OSC = 0, /* Low speed OSC */
|
|
OSC24M = 1, /* OSC24M */
|
|
PLL66 = 2 /* PLL6/6 */
|
|
};
|
|
|
|
Peripheral* const peripheral = (Peripheral* const)(TMR_PERIPHERAL_BASE);
|
|
|
|
class Timer {
|
|
private:
|
|
uint8_t n; /* Timer module number (0-5) */
|
|
uint16_t src; /* Timer interrupt source line (54-57, 99-100) */
|
|
TimerModule* module; /* Timer module MMIO config registers */
|
|
public:
|
|
/* Initialize class instance as timer n
|
|
* where n is found on Allwinner datasheet */
|
|
Timer(uint8_t n);
|
|
/* Prepare timer */
|
|
void set(uint32_t interval, Mode mode, Prescaler prescaler, ClockSource source);
|
|
/* Reload and start timer */
|
|
void start(void);
|
|
/* Stop timer */
|
|
void stop(void);
|
|
};
|
|
|
|
/* Interrupt handler */
|
|
extern void handler(const uint8_t cpuID, const uint16_t interruptID);
|
|
|
|
/* Vector of system's timers */
|
|
extern Timer timer[];
|
|
|
|
}
|
|
|
|
#endif
|
|
|