added automatic GPIO teardown, remap support to i2c, force error comments in ini if disabled

This commit is contained in:
2018-01-06 18:45:23 +01:00
parent ce895b3238
commit 6756b79ef4
9 changed files with 98 additions and 91 deletions
+8 -10
View File
@@ -73,19 +73,12 @@ error_t rsc_claim(Unit *unit, Resource rsc)
assert_param(rsc < RESOURCE_COUNT);
assert_param(unit != NULL);
dbg("%s claims %s", unit->name, rsc_get_name(rsc));
if (RSC_IS_HELD(global_rscmap, rsc)) {
// this whole branch is just reporting the error
Unit *holder = ureg_get_rsc_owner(rsc);
if (holder == NULL) {
// It must be one of the dummy built-in units
if (RSC_IS_HELD(UNIT_SYSTEM.resources, rsc))
holder = &UNIT_SYSTEM;
else if (RSC_IS_HELD(UNIT_PLATFORM.resources, rsc))
holder = &UNIT_SYSTEM;
}
assert_param(holder != NULL);
dbg("ERROR!! Unit %s failed to claim resource %s, already held by %s!",
@@ -154,6 +147,8 @@ void rsc_free(Unit *unit, Resource rsc)
assert_param(rsc_initialized);
assert_param(rsc < RESOURCE_COUNT);
dbg("Free resource %s", rsc_get_name(rsc));
if (RSC_IS_FREE(global_rscmap, rsc)) return;
// free it in any unit that holds it
@@ -197,7 +192,8 @@ void rsc_free_range(Unit *unit, Resource rsc0, Resource rsc1)
}
/**
* Tear down a unit - release all resources owned by the unit
* Tear down a unit - release all resources owned by the unit.
* Also de-init all GPIOs
*
* @param unit - unit to tear down; free only resources claimed by this unit
*/
@@ -206,6 +202,8 @@ void rsc_teardown(Unit *unit)
assert_param(rsc_initialized);
assert_param(unit != NULL);
deinit_unit_pins(unit);
for (uint32_t i = 0; i < RSCMAP_LEN; i++) {
global_rscmap[i] &= ~unit->resources[i];
unit->resources[i] = 0;
+19 -7
View File
@@ -355,14 +355,22 @@ static void export_unit_do(UlistEntry *li, IniWriter *iw)
iw_section(iw, "%s:%s@%d", pUnit->driver->name, pUnit->name, (int)pUnit->callsign);
if (pUnit->status != E_SUCCESS) {
// special message for failed unit die to resource
if (pUnit->status == E_RESOURCE_NOT_AVAILABLE) {
iw_comment(iw, "!!! %s not available, already held by %s",
rsc_get_name(pUnit->failed_rsc),
rsc_get_owner_name(pUnit->failed_rsc));
} else {
iw_comment(iw, "!!! %s", error_get_message(pUnit->status));
// temporarily force comments ON
bool sc = SystemSettings.ini_comments;
SystemSettings.ini_comments = true;
{
// special message for failed unit die to resource
if (pUnit->status == E_RESOURCE_NOT_AVAILABLE) {
iw_comment(iw, "!!! %s not available, already held by %s",
rsc_get_name(pUnit->failed_rsc),
rsc_get_owner_name(pUnit->failed_rsc));
}
else {
iw_comment(iw, "!!! %s", error_get_message(pUnit->status));
}
iw_cmt_newline(iw);
}
SystemSettings.ini_comments = sc;
}
pUnit->driver->cfgWriteIni(pUnit, iw);
}
@@ -540,5 +548,9 @@ Unit *ureg_get_rsc_owner(Resource resource)
}
li = li->next;
}
if (RSC_IS_HELD(UNIT_SYSTEM.resources, resource)) return &UNIT_SYSTEM;
if (RSC_IS_HELD(UNIT_PLATFORM.resources, resource)) return &UNIT_PLATFORM;
return NULL;
}