Free timers when modules de-init

This commit is contained in:
Lucian Copeland 2020-07-22 13:58:57 -04:00
parent dc6902a33e
commit 138189bad1
9 changed files with 16 additions and 17 deletions

View File

@ -5,6 +5,5 @@ build-*/
# Reference files
#####################
ref/
_working*
.gdb_history

View File

@ -116,6 +116,10 @@ bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
return !(claimed_pins[pin_port] & 1<<pin_number);
}
bool pin_number_is_resettable(uint8_t pin_port, uint8_t pin_number) {
return !(never_reset_pins[pin_port] & 1<<pin_number);
}
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {

View File

@ -45,6 +45,7 @@ void reset_all_pins(void);
void reset_pin_number(uint8_t pin_port, uint8_t pin_number);
void claim_pin(const mcu_pin_obj_t* pin);
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number);
bool pin_number_is_resettable(uint8_t pin_port, uint8_t pin_number)
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number);
GPIO_TypeDef * pin_port(uint8_t pin_port);
uint16_t pin_mask(uint8_t pin_number);

View File

@ -244,7 +244,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
//if reserved timer has no active channels, we can disable it
if (!reserved_tim[self->tim->tim_index - 1]) {
tim_frequencies[self->tim->tim_index - 1] = 0x00;
tim_clock_disable(1 << (self->tim->tim_index - 1));
stm_peripherals_timer_free(self->handle.Instance);
}
}

View File

@ -186,14 +186,13 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
return;
}
//Remove pulsein slot from shared array
HAL_NVIC_DisableIRQ(self->irq);
_objs[self->pin->number] = NULL;
reset_pin_number(self->pin->port, self->pin->number);
self->pin = NULL;
refcount--;
if (refcount == 0) {
tim_clock_disable(1<< stm_peripherals_timer_get_index(tim_handle.Instance));
stm_peripherals_timer_free(tim_handle.Instance);
}
}

View File

@ -152,7 +152,7 @@ void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) {
refcount--;
if (refcount == 0) {
tim_clock_disable(1<< stm_peripherals_timer_get_index(tim_handle.Instance));
stm_peripherals_timer_free(tim_handle.Instance);
}
}

View File

@ -34,20 +34,23 @@
extern void _PM_IRQ_HANDLER(void);
void *common_hal_rgbmatrix_timer_allocate() {
return stm_peripherals_find_timer();
TIM_TypeDef * timer = stm_peripherals_find_timer();
stm_peripherals_timer_reserve(timer);
return timer;
}
void common_hal_rgbmatrix_timer_enable(void* ptr) {
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
TIM_TypeDef *tim = (TIM_TypeDef*)ptr;
HAL_NVIC_EnableIRQ(stm_peripherals_timer_get_irqnum(tim));
}
void common_hal_rgbmatrix_timer_disable(void* ptr) {
TIM_TypeDef *tim = (TIM_TypeDef*)ptr;
tim->DIER &= ~TIM_DIER_UIE;
HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
}
void common_hal_rgbmatrix_timer_free(void* ptr) {
TIM_TypeDef *tim = (TIM_TypeDef*)ptr;
stm_peripherals_timer_free(tim);
common_hal_rgbmatrix_timer_disable(ptr);
// TODO(jepler) properly handle resource allocation including never-reset
}

View File

@ -233,6 +233,7 @@ void stm_peripherals_timer_set_callback(void(*callback)(void), TIM_TypeDef * tim
void stm_peripherals_timer_free(TIM_TypeDef * instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
HAL_NVIC_DisableIRQ(irq_map[tim_idx]);
stm_timer_callback[tim_idx] = NULL;
tim_clock_disable(1 << tim_idx);
stm_timer_reserved[tim_idx] = false;

View File

@ -24,14 +24,6 @@
* THE SOFTWARE.
*/
// typedef struct {
// TIM_TypeDef * timer;
// bool reserved;
// bool never_reset;
// void (*stm_timer_callback)(void);
// size_t irq;
// } stm_timer_t;
#include <stdint.h>
#include "py/mphal.h"
#include "peripherals/periph.h"