Make stk_read function usable
This function used to return the raw current value, but that exposes the prescaling used internaly
This commit is contained in:
parent
432310a52d
commit
34fb4dac76
11
drv/stk.c
11
drv/stk.c
@ -21,6 +21,7 @@ static volatile struct STK* regs = (struct STK*)STK_BASE_ADDRESS;
|
||||
//--local variables-------------------------------------------------------------
|
||||
|
||||
static StkCallback callback;
|
||||
static uint32_t prescaler;
|
||||
|
||||
|
||||
//--public functions------------------------------------------------------------
|
||||
@ -32,10 +33,12 @@ uint32_t stk_configure(uint32_t period_us, StkCallback cb)
|
||||
struct RccClocks clocks;
|
||||
rcc_get_clocks(&clocks);
|
||||
|
||||
uint32_t reload = period_us * (clocks.ahb_freq / 1000000 / 8);
|
||||
uint32_t prescaler = (clocks.ahb_freq / 1000000 / 8);
|
||||
uint32_t reload = period_us * prescaler;
|
||||
if (reload < 1) {
|
||||
//period is too small, try using the non-prescaled clock
|
||||
reload = period_us * (clocks.ahb_freq / 1000000);
|
||||
prescaler *= 8;
|
||||
reload = period_us * prescaler;
|
||||
if (reload < 1) {
|
||||
//period is still too small
|
||||
return 1;
|
||||
@ -71,9 +74,9 @@ void stk_stop(void)
|
||||
reg_reset(regs->CTRL, STK_CTRL_ENABLE);
|
||||
}
|
||||
|
||||
uint32_t stk_read(void)
|
||||
uint32_t stk_read_us(void)
|
||||
{
|
||||
return regs->VAL.word & 0x00FFFFFF;
|
||||
return (regs->VAL.word & 0x00FFFFFF) / prescaler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -46,9 +46,9 @@ void stk_start(void);
|
||||
void stk_stop(void);
|
||||
|
||||
/**
|
||||
* Read the current value of the timer's counter
|
||||
* Read the current value of the timer's counter in µs
|
||||
*/
|
||||
uint32_t stk_read(void);
|
||||
uint32_t stk_read_us(void);
|
||||
|
||||
|
||||
#endif //_STK_H_
|
||||
|
||||
@ -73,7 +73,7 @@ void task_start_scheduler(void)
|
||||
stk_start();
|
||||
__asm("wfi");
|
||||
stk_stop();
|
||||
uint32_t stk_delay = stk_read();
|
||||
uint32_t stk_delay = stk_read_us();
|
||||
if (stk_delay != 0) {
|
||||
delay = stk_delay;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user