diff --git a/framework/resources.c b/framework/resources.c index bcd985d..5e19876 100644 --- a/framework/resources.c +++ b/framework/resources.c @@ -211,6 +211,7 @@ void rsc_teardown(Unit *unit) assert_param(rsc_initialized); assert_param(unit != NULL); + dbg("Tearing down unit %s", unit->name); deinit_unit_pins(unit); for (uint32_t i = 0; i < RSCMAP_LEN; i++) { diff --git a/framework/unit_registry.c b/framework/unit_registry.c index dda027f..5b90279 100644 --- a/framework/unit_registry.c +++ b/framework/unit_registry.c @@ -42,6 +42,7 @@ static int32_t unit_count = -1; void ureg_add_type(const UnitDriver *driver) { + bool suc = true; assert_param(driver != NULL); assert_param(driver->name != NULL); @@ -57,7 +58,9 @@ void ureg_add_type(const UnitDriver *driver) assert_param(driver->deInit != NULL); assert_param(driver->handleRequest != NULL); - UregEntry *re = malloc_s(sizeof(UregEntry)); + UregEntry *re = calloc_ck(1, sizeof(UregEntry), &suc); + assert_param(suc); + re->driver = driver; re->next = NULL; @@ -108,7 +111,7 @@ Unit *ureg_instantiate(const char *driver_name) while (re != NULL) { if (streq(re->driver->name, driver_name)) { // Create new list entry - UlistEntry *le = malloc_ck(sizeof(UlistEntry), &suc); + UlistEntry *le = calloc_ck(1, sizeof(UlistEntry), &suc); CHECK_SUC(); le->next = NULL; @@ -512,7 +515,7 @@ void ureg_report_active_units(TF_ID frame_id) msglen += count; // one byte per message for the callsign bool suc = true; - uint8_t *buff = malloc_ck(msglen, &suc); + uint8_t *buff = calloc_ck(1, msglen, &suc); if (!suc) { com_respond_error(frame_id, E_OUT_OF_MEM); return; diff --git a/platform/pin_utils.c b/platform/pin_utils.c index 58a623c..0ef321f 100644 --- a/platform/pin_utils.c +++ b/platform/pin_utils.c @@ -263,8 +263,9 @@ uint16_t port_pack(uint16_t spread, uint16_t mask) void deinit_unit_pins(Unit *unit) { - for (uint32_t rsc = R_PA0; rsc <= R_PF0; rsc++) { + for (uint32_t rsc = R_PA0; rsc <= R_PF15; rsc++) { if (RSC_IS_HELD(unit->resources, rsc)) { + dbg("Freeing pin %s", rsc_get_name((Resource)rsc)); GPIO_TypeDef *port = port_periphs[(rsc-R_PA0) / 16]; uint32_t ll_pin = ll_pins[(rsc-R_PA0)%16]; LL_GPIO_SetPinMode(port, ll_pin, LL_GPIO_MODE_ANALOG);