stkarm/include/timer.h

67 lines
1.6 KiB
C
Raw Normal View History

2019-01-06 16:33:02 +00:00
#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;
TimerModule* module;
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);
};
/* Vector of system's timers */
extern Timer timer[];
}
#endif