task #5

Merged
Steins7 merged 35 commits from task into dev 2024-08-04 18:30:16 +00:00
3 changed files with 10 additions and 7 deletions
Showing only changes of commit 34fb4dac76 - Show all commits

View File

@ -21,6 +21,7 @@ static volatile struct STK* regs = (struct STK*)STK_BASE_ADDRESS;
//--local variables------------------------------------------------------------- //--local variables-------------------------------------------------------------
static StkCallback callback; static StkCallback callback;
static uint32_t prescaler;
//--public functions------------------------------------------------------------ //--public functions------------------------------------------------------------
@ -32,10 +33,12 @@ uint32_t stk_configure(uint32_t period_us, StkCallback cb)
struct RccClocks clocks; struct RccClocks clocks;
rcc_get_clocks(&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) { if (reload < 1) {
//period is too small, try using the non-prescaled clock //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) { if (reload < 1) {
//period is still too small //period is still too small
return 1; return 1;
@ -71,9 +74,9 @@ void stk_stop(void)
reg_reset(regs->CTRL, STK_CTRL_ENABLE); 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;
} }

View File

@ -46,9 +46,9 @@ void stk_start(void);
void stk_stop(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_ #endif //_STK_H_

View File

@ -73,7 +73,7 @@ void task_start_scheduler(void)
stk_start(); stk_start();
__asm("wfi"); __asm("wfi");
stk_stop(); stk_stop();
uint32_t stk_delay = stk_read(); uint32_t stk_delay = stk_read_us();
if (stk_delay != 0) { if (stk_delay != 0) {
delay = stk_delay; delay = stk_delay;
} }