added missing mutex for shared scratch buffer
This commit is contained in:
@@ -223,6 +223,8 @@ static void ini_preamble(IniWriter *iw, const char *filename)
|
||||
iw_comment(iw, "Close the LOCK jumper to save them to Flash.");
|
||||
}
|
||||
|
||||
extern osMutexId mutScratchBufferHandle;
|
||||
|
||||
/**
|
||||
* Write system settings to INI (without section)
|
||||
*/
|
||||
@@ -230,7 +232,11 @@ void settings_build_units_ini(IniWriter *iw)
|
||||
{
|
||||
ini_preamble(iw, "UNITS.INI");
|
||||
|
||||
ureg_build_ini(iw);
|
||||
assert_param(osOK == osMutexWait(mutScratchBufferHandle, 5000));
|
||||
{
|
||||
ureg_build_ini(iw);
|
||||
}
|
||||
assert_param(osOK == osMutexRelease(mutScratchBufferHandle));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
#include "unit.h"
|
||||
#include "resources.h"
|
||||
|
||||
char unit_tmp512[512];
|
||||
char unit_tmp512[UNIT_TMP_LEN];
|
||||
|
||||
// Abort partly inited unit
|
||||
void clean_failed_unit(Unit *unit)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
return E_BAD_UNIT_TYPE; \
|
||||
} while (0)
|
||||
|
||||
extern char unit_tmp512[512]; // temporary static buffer - not expected to be accessed asynchronously
|
||||
extern char unit_tmp512[UNIT_TMP_LEN]; // temporary static buffer - not expected to be accessed asynchronously
|
||||
// TODO add mutex?
|
||||
|
||||
typedef struct unit Unit;
|
||||
|
||||
+38
-29
@@ -431,42 +431,51 @@ uint32_t ureg_get_num_units(void)
|
||||
return (uint32_t) unit_count;
|
||||
}
|
||||
|
||||
extern osMutexId mutScratchBufferHandle;
|
||||
|
||||
/** Deliver message to it's destination unit */
|
||||
void ureg_deliver_unit_request(TF_Msg *msg)
|
||||
{
|
||||
PayloadParser pp = pp_start(msg->data, msg->len, NULL);
|
||||
uint8_t callsign = pp_u8(&pp);
|
||||
uint8_t command = pp_u8(&pp);
|
||||
// we must claim the scratch buffer because it's used by many units internally
|
||||
assert_param(osOK == osMutexWait(mutScratchBufferHandle, 5000));
|
||||
{
|
||||
PayloadParser pp = pp_start(msg->data, msg->len, NULL);
|
||||
uint8_t callsign = pp_u8(&pp);
|
||||
uint8_t command = pp_u8(&pp);
|
||||
|
||||
// highest bit indicates user wants an extra confirmation on success
|
||||
bool confirmed = (bool) (command & 0x80);
|
||||
command &= 0x7F;
|
||||
// highest bit indicates user wants an extra confirmation on success
|
||||
bool confirmed = (bool) (command & 0x80);
|
||||
command &= 0x7F;
|
||||
|
||||
if (callsign == 0 || !pp.ok) {
|
||||
com_respond_error(msg->frame_id, E_MALFORMED_COMMAND);
|
||||
return;
|
||||
}
|
||||
|
||||
UlistEntry *li = ulist_head;
|
||||
while (li != NULL) {
|
||||
Unit *const pUnit = &li->unit;
|
||||
if (pUnit->callsign == callsign && pUnit->status == E_SUCCESS) {
|
||||
error_t rv = pUnit->driver->handleRequest(pUnit, msg->frame_id, command, &pp);
|
||||
|
||||
// send extra SUCCESS confirmation message.
|
||||
// error is expected to have already been reported.
|
||||
if (rv == E_SUCCESS) {
|
||||
if (confirmed) com_respond_ok(msg->frame_id);
|
||||
} else {
|
||||
com_respond_error(msg->frame_id, rv);
|
||||
}
|
||||
return;
|
||||
if (callsign == 0 || !pp.ok) {
|
||||
com_respond_error(msg->frame_id, E_MALFORMED_COMMAND);
|
||||
goto quit;
|
||||
}
|
||||
li = li->next;
|
||||
}
|
||||
|
||||
// Not found
|
||||
com_respond_error(msg->frame_id, E_NO_SUCH_UNIT);
|
||||
UlistEntry *li = ulist_head;
|
||||
while (li != NULL) {
|
||||
Unit *const pUnit = &li->unit;
|
||||
if (pUnit->callsign == callsign && pUnit->status == E_SUCCESS) {
|
||||
error_t rv = pUnit->driver->handleRequest(pUnit, msg->frame_id, command, &pp);
|
||||
|
||||
// send extra SUCCESS confirmation message.
|
||||
// error is expected to have already been reported.
|
||||
if (rv == E_SUCCESS) {
|
||||
if (confirmed) com_respond_ok(msg->frame_id);
|
||||
}
|
||||
else {
|
||||
com_respond_error(msg->frame_id, rv);
|
||||
}
|
||||
goto quit;
|
||||
}
|
||||
li = li->next;
|
||||
}
|
||||
|
||||
// Not found
|
||||
com_respond_error(msg->frame_id, E_NO_SUCH_UNIT);
|
||||
}
|
||||
quit:
|
||||
assert_param(osOK == osMutexRelease(mutScratchBufferHandle));
|
||||
}
|
||||
|
||||
/** Send a response for a unit-list request */
|
||||
|
||||
Reference in New Issue
Block a user