Commit e99e6c88 authored by Damien George's avatar Damien George
Browse files

stmhal: Move flash storage idle tick handler from TIM3 to SysTick.

Using SysTick to do the counting and dispatch of the flash storage idle
handler is more efficient than requiring a dedicated hardware timer.
No new counter is needed, just the existing uwTick variable.  The
processing is not actually done in the SysTick IRQ, it is deferred to
the flash IRQ (which runs at lower priority).
parent 3cfb02f1
......@@ -269,10 +269,15 @@ void SysTick_Handler(void) {
// work properly.
SysTick->CTRL;
// Right now we just have the DMA controllers to process during this
// interrupt and we use a custom dispatch handler. If this needs to
// Right now we have the storage and DMA controllers to process during
// this interrupt and we use custom dispatch handlers. If this needs to
// be generalised in the future then a dispatch table can be used as
// follows: ((void(*)(void))(systick_dispatch[uwTick & 0xf]))();
if (STORAGE_IDLE_TICK(uwTick)) {
NVIC->STIR = FLASH_IRQn;
}
if (DMA_IDLE_ENABLED() && DMA_IDLE_TICK(uwTick)) {
dma_idle_handler(uwTick);
}
......
......@@ -26,6 +26,9 @@
#define FLASH_BLOCK_SIZE (512)
#define STORAGE_SYSTICK_MASK (0x1ff) // 512ms
#define STORAGE_IDLE_TICK(tick) (((tick) & STORAGE_SYSTICK_MASK) == 0)
void storage_init(void);
uint32_t storage_get_block_size(void);
uint32_t storage_get_block_count(void);
......
......@@ -148,9 +148,6 @@ TIM_HandleTypeDef TIM3_Handle;
TIM_HandleTypeDef TIM5_Handle;
TIM_HandleTypeDef TIM6_Handle;
// Used to divide down TIM3 and periodically call the flash storage IRQ
STATIC uint32_t tim3_counter = 0;
#define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(MP_STATE_PORT(pyb_timer_obj_all))
STATIC uint32_t timer_get_source_freq(uint32_t tim_id);
......@@ -159,7 +156,6 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback);
STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback);
void timer_init0(void) {
tim3_counter = 0;
for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) {
MP_STATE_PORT(pyb_timer_obj_all)[i] = NULL;
}
......@@ -256,13 +252,6 @@ TIM_HandleTypeDef *timer_tim6_init(uint freq) {
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if (htim == &TIM3_Handle) {
USBD_CDC_HAL_TIM_PeriodElapsedCallback();
// Periodically raise a flash IRQ for the flash storage controller
if (tim3_counter++ >= 500 / USBD_CDC_POLLING_INTERVAL) {
tim3_counter = 0;
NVIC->STIR = FLASH_IRQn;
}
} else if (htim == &TIM5_Handle) {
servo_timer_irq_callback();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment