53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
|
#ifndef _BSP_TIMER_H
|
||
|
#define _BSP_TIMER_H
|
||
|
|
||
|
#include <stdint.h>
|
||
|
|
||
|
typedef struct __attribute((__packed__)) {
|
||
|
volatile uint32_t mtime; // 0x0:0
|
||
|
volatile uint32_t mtimeh; // 0x4:0
|
||
|
volatile uint32_t mtimecmp; // 0x8:0
|
||
|
volatile uint32_t mtimecmph; // 0xc:0
|
||
|
} mtimer_t;
|
||
|
|
||
|
#ifndef APB_BUS
|
||
|
typedef struct __attribute((__packed__)) {
|
||
|
volatile uint16_t count;
|
||
|
} prescaler_t;
|
||
|
|
||
|
typedef struct __attribute((__packed__)) {
|
||
|
volatile uint16_t clk_en; // 0x0:0, 0->always, 1->prescaler
|
||
|
volatile uint16_t clr_en; // 0x2:0, 0->on overflow
|
||
|
volatile uint32_t limit; // 0x4:0, upper limit of counter
|
||
|
volatile uint32_t timer_value; // 0x8:0 current timer value
|
||
|
} timer_a_t;
|
||
|
|
||
|
#else
|
||
|
|
||
|
typedef struct __attribute((__packed__)) {
|
||
|
volatile uint32_t LIMIT;
|
||
|
} prescaler_t;
|
||
|
|
||
|
typedef struct __attribute((__packed__)) {
|
||
|
volatile uint32_t CLEARS_TICKS; // 0x0/0:0->always, 1->prescaler; 16:0->on overflow
|
||
|
volatile uint32_t LIMIT; // 0x4/0 upper limit of counter
|
||
|
volatile uint32_t VALUE; // 0x8/0 current timer value
|
||
|
} timer_a_t;
|
||
|
|
||
|
inline void prescaler_init(prescaler_t* reg){
|
||
|
(void)reg;
|
||
|
}
|
||
|
|
||
|
inline void timer_init(timer_a_t *reg){
|
||
|
reg->CLEARS_TICKS = 0;
|
||
|
reg->VALUE = 0;
|
||
|
}
|
||
|
|
||
|
inline void mtimer_init(mtimer_t *reg){
|
||
|
reg->mtimecmph = UINT32_MAX;
|
||
|
reg->mtimecmp = UINT32_MAX;
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
#endif /* _BSP_TIMER_H */
|