From da6a9638144250579d8a2c0eddd21f84709dd71f Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Wed, 27 Dec 2023 18:31:08 +0200 Subject: [PATCH] Add mutex lock/unlock --- src/BlynkRpcConfig.h | 15 ++++- src/BlynkRpcInfra.c | 2 + src/idl/rpc_shim_blynk.h | 120 ++++++++++++++++++++++++++++++-------- src/idl/rpc_shim_client.h | 20 ++++++- src/idl/rpc_shim_hw.h | 32 +++++++--- src/idl/rpc_shim_mcu.h | 10 +++- src/idl/rpc_shim_ncp.h | 10 +++- 7 files changed, 167 insertions(+), 42 deletions(-) diff --git a/src/BlynkRpcConfig.h b/src/BlynkRpcConfig.h index 2830bc2..d3f9c14 100644 --- a/src/BlynkRpcConfig.h +++ b/src/BlynkRpcConfig.h @@ -6,7 +6,7 @@ #endif #if defined(RPC_INPUT_BUFFER) - // Use the specified value + /* OK, use the specified value */ #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) #define RPC_INPUT_BUFFER 256 #elif defined(LINUX) || defined(ESP32) @@ -16,12 +16,23 @@ #endif #if defined(RPC_ENABLE_SMALL_CRC8) - // Use the specified value + /* OK, use the specified value */ #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) #define RPC_ENABLE_SMALL_CRC8 1 #else #define RPC_ENABLE_SMALL_CRC8 0 #endif +/* + * Define global RPC mutex operations, if needed. + * The mutex should be reentrant/recursive. + */ +#if !defined(RPC_MUTEX_LOCK) + #define RPC_MUTEX_LOCK() +#endif +#if !defined(RPC_MUTEX_UNLOCK) + #define RPC_MUTEX_UNLOCK() +#endif + #endif /* BLYNK_RPC_CONFIG_H */ diff --git a/src/BlynkRpcInfra.c b/src/BlynkRpcInfra.c index dd05d96..29fe6f3 100644 --- a/src/BlynkRpcInfra.c +++ b/src/BlynkRpcInfra.c @@ -97,10 +97,12 @@ RpcStatus rpc_wait_result(uint16_t expected_seq, MessageBuffer* buff, uint32_t t } void rpc_run(void) { + RPC_MUTEX_LOCK(); MessageBuffer buff; MessageBuffer_init(&buff, NULL, 0); while (rpc_recv_msg(&buff, 0)) { _rpc_last_rx_time = rpc_system_millis(); rpc_handle_msg(&buff); } + RPC_MUTEX_UNLOCK(); } diff --git a/src/idl/rpc_shim_blynk.h b/src/idl/rpc_shim_blynk.h index 525fbda..562e34b 100644 --- a/src/idl/rpc_shim_blynk.h +++ b/src/idl/rpc_shim_blynk.h @@ -12,10 +12,10 @@ extern "C" { static inline bool rpc_blynk_getNcpVersion(const char** ver) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_GETNCPVERSION); MessageWriter_end(); @@ -31,10 +31,12 @@ bool rpc_blynk_getNcpVersion(const char** ver) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -42,10 +44,10 @@ bool rpc_blynk_getNcpVersion(const char** ver) { static inline bool rpc_blynk_setVendorPrefix(const char* vendor) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_SETVENDORPREFIX); MessageWriter_writeString(vendor); @@ -61,10 +63,12 @@ bool rpc_blynk_setVendorPrefix(const char* vendor) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -72,10 +76,10 @@ bool rpc_blynk_setVendorPrefix(const char* vendor) { static inline bool rpc_blynk_setVendorServer(const char* host) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_SETVENDORSERVER); MessageWriter_writeString(host); @@ -91,10 +95,12 @@ bool rpc_blynk_setVendorServer(const char* host) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -102,10 +108,10 @@ bool rpc_blynk_setVendorServer(const char* host) { static inline bool rpc_blynk_setFirmwareInfo(const char* type, const char* version, const char* build, const char* blynk) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_SETFIRMWAREINFO); MessageWriter_writeString(type); @@ -124,10 +130,12 @@ bool rpc_blynk_setFirmwareInfo(const char* type, const char* version, const char } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -135,10 +143,10 @@ bool rpc_blynk_setFirmwareInfo(const char* type, const char* version, const char static inline bool rpc_blynk_initialize(const char* templateID, const char* templateName) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_INITIALIZE); MessageWriter_writeString(templateID); @@ -155,10 +163,12 @@ bool rpc_blynk_initialize(const char* templateID, const char* templateName) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -166,10 +176,10 @@ bool rpc_blynk_initialize(const char* templateID, const char* templateName) { static inline bool rpc_blynk_getHotspotName(const char** hotspot) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_GETHOTSPOTNAME); MessageWriter_end(); @@ -185,10 +195,12 @@ bool rpc_blynk_getHotspotName(const char** hotspot) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -196,10 +208,10 @@ bool rpc_blynk_getHotspotName(const char** hotspot) { static inline bool rpc_blynk_isConfigured(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_ISCONFIGURED); MessageWriter_end(); @@ -214,10 +226,12 @@ bool rpc_blynk_isConfigured(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -225,10 +239,10 @@ bool rpc_blynk_isConfigured(void) { static inline bool rpc_blynk_configStart(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_CONFIGSTART); MessageWriter_end(); @@ -243,10 +257,12 @@ bool rpc_blynk_configStart(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -254,10 +270,10 @@ bool rpc_blynk_configStart(void) { static inline bool rpc_blynk_configStop(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_CONFIGSTOP); MessageWriter_end(); @@ -272,10 +288,12 @@ bool rpc_blynk_configStop(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -283,10 +301,10 @@ bool rpc_blynk_configStop(void) { static inline bool rpc_blynk_configReset(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_CONFIGRESET); MessageWriter_end(); @@ -301,10 +319,12 @@ bool rpc_blynk_configReset(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -312,10 +332,10 @@ bool rpc_blynk_configReset(void) { static inline bool rpc_blynk_setConfigTimeout(uint16_t timeout) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_SETCONFIGTIMEOUT); MessageWriter_writeUInt16(timeout); @@ -331,10 +351,12 @@ bool rpc_blynk_setConfigTimeout(uint16_t timeout) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -342,10 +364,10 @@ bool rpc_blynk_setConfigTimeout(uint16_t timeout) { static inline bool rpc_blynk_setConfigSkipLimit(uint8_t count) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_SETCONFIGSKIPLIMIT); MessageWriter_writeUInt8(count); @@ -361,10 +383,12 @@ bool rpc_blynk_setConfigSkipLimit(uint8_t count) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -372,10 +396,10 @@ bool rpc_blynk_setConfigSkipLimit(uint8_t count) { static inline bool rpc_blynk_setTime(int64_t time) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_SETTIME); MessageWriter_writeInt64(time); @@ -391,10 +415,12 @@ bool rpc_blynk_setTime(int64_t time) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -402,10 +428,10 @@ bool rpc_blynk_setTime(int64_t time) { static inline bool rpc_blynk_getTime(const char** iso8601, int64_t* time, int16_t* offset, const char** tz_abbr, uint8_t* dst_status) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_GETTIME); MessageWriter_end(); @@ -425,10 +451,12 @@ bool rpc_blynk_getTime(const char** iso8601, int64_t* time, int16_t* offset, con } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -436,10 +464,10 @@ bool rpc_blynk_getTime(const char** iso8601, int64_t* time, int16_t* offset, con static inline bool rpc_blynk_getLocationInfo(const char** lat, const char** lon, const char** olson_id, const char** posix_tz) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_GETLOCATIONINFO); MessageWriter_end(); @@ -458,10 +486,12 @@ bool rpc_blynk_getLocationInfo(const char** lat, const char** lon, const char** } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -469,10 +499,10 @@ bool rpc_blynk_getLocationInfo(const char** lat, const char** lon, const char** static inline bool rpc_blynk_otaUpdateStart(uint16_t chunk) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_OTAUPDATESTART); MessageWriter_writeUInt16(chunk); @@ -488,10 +518,12 @@ bool rpc_blynk_otaUpdateStart(uint16_t chunk) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -499,10 +531,10 @@ bool rpc_blynk_otaUpdateStart(uint16_t chunk) { static inline bool rpc_blynk_otaUpdateGetCRC32(uint32_t* crc) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_OTAUPDATEGETCRC32); MessageWriter_end(); @@ -518,10 +550,12 @@ bool rpc_blynk_otaUpdateGetCRC32(uint32_t* crc) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -529,10 +563,10 @@ bool rpc_blynk_otaUpdateGetCRC32(uint32_t* crc) { static inline bool rpc_blynk_otaUpdateGetMD5(rpc_buffer_t* digest) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_OTAUPDATEGETMD5); MessageWriter_end(); @@ -548,10 +582,12 @@ bool rpc_blynk_otaUpdateGetMD5(rpc_buffer_t* digest) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -559,10 +595,10 @@ bool rpc_blynk_otaUpdateGetMD5(rpc_buffer_t* digest) { static inline bool rpc_blynk_otaUpdateGetSHA256(rpc_buffer_t* digest) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_OTAUPDATEGETSHA256); MessageWriter_end(); @@ -578,10 +614,12 @@ bool rpc_blynk_otaUpdateGetSHA256(rpc_buffer_t* digest) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -589,10 +627,10 @@ bool rpc_blynk_otaUpdateGetSHA256(rpc_buffer_t* digest) { static inline uint8_t rpc_blynk_otaUpdatePrefetch(void) { RpcStatus _rpc_res; - /* Prepare return value */ uint8_t _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_OTAUPDATEPREFETCH); MessageWriter_end(); @@ -607,10 +645,12 @@ uint8_t rpc_blynk_otaUpdatePrefetch(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -618,10 +658,10 @@ uint8_t rpc_blynk_otaUpdatePrefetch(void) { static inline bool rpc_blynk_factoryReset(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_FACTORYRESET); MessageWriter_end(); @@ -636,10 +676,12 @@ bool rpc_blynk_factoryReset(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -647,10 +689,10 @@ bool rpc_blynk_factoryReset(void) { static inline uint8_t rpc_blynk_factoryTestWiFiAP(uint16_t channel) { RpcStatus _rpc_res; - /* Prepare return value */ uint8_t _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_FACTORYTESTWIFIAP); MessageWriter_writeUInt16(channel); @@ -666,10 +708,12 @@ uint8_t rpc_blynk_factoryTestWiFiAP(uint16_t channel) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -677,10 +721,10 @@ uint8_t rpc_blynk_factoryTestWiFiAP(uint16_t channel) { static inline uint8_t rpc_blynk_factoryTestWiFi(const char* ssid, const char* pass, int16_t* rssi) { RpcStatus _rpc_res; - /* Prepare return value */ uint8_t _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_FACTORYTESTWIFI); MessageWriter_writeString(ssid); @@ -698,10 +742,12 @@ uint8_t rpc_blynk_factoryTestWiFi(const char* ssid, const char* pass, int16_t* r } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -709,10 +755,10 @@ uint8_t rpc_blynk_factoryTestWiFi(const char* ssid, const char* pass, int16_t* r static inline uint8_t rpc_blynk_factoryTestConnect(void) { RpcStatus _rpc_res; - /* Prepare return value */ uint8_t _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_FACTORYTESTCONNECT); MessageWriter_end(); @@ -727,10 +773,12 @@ uint8_t rpc_blynk_factoryTestConnect(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -738,10 +786,10 @@ uint8_t rpc_blynk_factoryTestConnect(void) { static inline uint8_t rpc_blynk_getState(void) { RpcStatus _rpc_res; - /* Prepare return value */ uint8_t _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_BLYNK_GETSTATE); MessageWriter_end(); @@ -756,16 +804,19 @@ uint8_t rpc_blynk_getState(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } static inline void rpc_blynk_virtualWrite(uint16_t vpin, rpc_buffer_t value) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_VIRTUALWRITE); MessageWriter_writeUInt16(vpin); @@ -773,11 +824,13 @@ void rpc_blynk_virtualWrite(uint16_t vpin, rpc_buffer_t value) { MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_setProperty(uint16_t vpin, const char* property, rpc_buffer_t value) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_SETPROPERTY); MessageWriter_writeUInt16(vpin); @@ -786,32 +839,38 @@ void rpc_blynk_setProperty(uint16_t vpin, const char* property, rpc_buffer_t val MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_syncAll(void) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_SYNCALL); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_syncVirtual(rpc_buffer_t vpins) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_SYNCVIRTUAL); MessageWriter_writeBinary(vpins); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_logEvent(const char* event_code, const char* description) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_LOGEVENT); MessageWriter_writeString(event_code); @@ -819,54 +878,64 @@ void rpc_blynk_logEvent(const char* event_code, const char* description) { MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_resolveEvent(const char* event_code) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_RESOLVEEVENT); MessageWriter_writeString(event_code); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_resolveAllEvents(const char* event_code) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_RESOLVEALLEVENTS); MessageWriter_writeString(event_code); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_beginGroup(int64_t timestamp) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_BEGINGROUP); MessageWriter_writeInt64(timestamp); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_endGroup(void) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_ENDGROUP); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_blynk_setMetadata(const char* field, const char* value) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_BLYNK_SETMETADATA); MessageWriter_writeString(field); @@ -874,6 +943,7 @@ void rpc_blynk_setMetadata(const char* field, const char* value) { MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } #ifdef __cplusplus diff --git a/src/idl/rpc_shim_client.h b/src/idl/rpc_shim_client.h index 30b34e9..c2036ee 100644 --- a/src/idl/rpc_shim_client.h +++ b/src/idl/rpc_shim_client.h @@ -11,6 +11,7 @@ extern "C" { static inline void rpc_client_blynkVPinChange(uint16_t vpin, rpc_buffer_t param) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_CLIENT_BLYNKVPINCHANGE); MessageWriter_writeUInt16(vpin); @@ -18,38 +19,43 @@ void rpc_client_blynkVPinChange(uint16_t vpin, rpc_buffer_t param) { MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_client_blynkStateChange(uint8_t state) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_CLIENT_BLYNKSTATECHANGE); MessageWriter_writeUInt8(state); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline void rpc_client_processEvent(uint8_t event) { + RPC_MUTEX_LOCK(); /* Send request */ MessageWriter_beginOneway(RPC_UID_CLIENT_PROCESSEVENT); MessageWriter_writeUInt8(event); MessageWriter_end(); /* Oneway => skip response */ + RPC_MUTEX_UNLOCK(); } static inline bool rpc_client_otaUpdateAvailable(const char* filename, uint32_t filesize, const char* fw_type, const char* fw_ver, const char* fw_build) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_CLIENT_OTAUPDATEAVAILABLE); MessageWriter_writeString(filename); @@ -69,10 +75,12 @@ bool rpc_client_otaUpdateAvailable(const char* filename, uint32_t filesize, cons } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -80,10 +88,10 @@ bool rpc_client_otaUpdateAvailable(const char* filename, uint32_t filesize, cons static inline bool rpc_client_otaUpdateWrite(uint32_t offset, rpc_buffer_t chunk, uint32_t crc32) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_CLIENT_OTAUPDATEWRITE); MessageWriter_writeUInt32(offset); @@ -101,10 +109,12 @@ bool rpc_client_otaUpdateWrite(uint32_t offset, rpc_buffer_t chunk, uint32_t crc } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -112,10 +122,10 @@ bool rpc_client_otaUpdateWrite(uint32_t offset, rpc_buffer_t chunk, uint32_t crc static inline bool rpc_client_otaUpdateFinish(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_CLIENT_OTAUPDATEFINISH); MessageWriter_end(); @@ -130,10 +140,12 @@ bool rpc_client_otaUpdateFinish(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -141,6 +153,7 @@ bool rpc_client_otaUpdateFinish(void) { static inline void rpc_client_otaUpdateCancel(void) { RpcStatus _rpc_res; + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_CLIENT_OTAUPDATECANCEL); MessageWriter_end(); @@ -151,6 +164,7 @@ void rpc_client_otaUpdateCancel(void) { _rpc_res = rpc_wait_result(_rpc_seq, &_rsp_buff, RPC_TIMEOUT_DEFAULT); rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return; } diff --git a/src/idl/rpc_shim_hw.h b/src/idl/rpc_shim_hw.h index 304f201..e674b00 100644 --- a/src/idl/rpc_shim_hw.h +++ b/src/idl/rpc_shim_hw.h @@ -12,10 +12,10 @@ extern "C" { static inline bool rpc_hw_setUartBaudRate(uint32_t baud) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_SETUARTBAUDRATE); MessageWriter_writeUInt32(baud); @@ -31,10 +31,12 @@ bool rpc_hw_setUartBaudRate(uint32_t baud) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -42,10 +44,10 @@ bool rpc_hw_setUartBaudRate(uint32_t baud) { static inline bool rpc_hw_initUserButton(uint16_t gpio, bool active_low) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_INITUSERBUTTON); MessageWriter_writeUInt16(gpio); @@ -62,10 +64,12 @@ bool rpc_hw_initUserButton(uint16_t gpio, bool active_low) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -73,10 +77,10 @@ bool rpc_hw_initUserButton(uint16_t gpio, bool active_low) { static inline bool rpc_hw_initLED(uint16_t gpio, bool active_low) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_INITLED); MessageWriter_writeUInt16(gpio); @@ -93,10 +97,12 @@ bool rpc_hw_initLED(uint16_t gpio, bool active_low) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -104,10 +110,10 @@ bool rpc_hw_initLED(uint16_t gpio, bool active_low) { static inline bool rpc_hw_initRGB(uint16_t gpio_r, uint16_t gpio_g, uint16_t gpio_b, bool common_anode) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_INITRGB); MessageWriter_writeUInt16(gpio_r); @@ -126,10 +132,12 @@ bool rpc_hw_initRGB(uint16_t gpio_r, uint16_t gpio_g, uint16_t gpio_b, bool comm } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -137,10 +145,10 @@ bool rpc_hw_initRGB(uint16_t gpio_r, uint16_t gpio_g, uint16_t gpio_b, bool comm static inline bool rpc_hw_initARGB(uint16_t gpio, uint8_t mode, uint8_t count) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_INITARGB); MessageWriter_writeUInt16(gpio); @@ -158,10 +166,12 @@ bool rpc_hw_initARGB(uint16_t gpio, uint8_t mode, uint8_t count) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -169,10 +179,10 @@ bool rpc_hw_initARGB(uint16_t gpio, uint8_t mode, uint8_t count) { static inline bool rpc_hw_setLedBrightness(uint8_t value) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_SETLEDBRIGHTNESS); MessageWriter_writeUInt8(value); @@ -188,10 +198,12 @@ bool rpc_hw_setLedBrightness(uint8_t value) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -199,10 +211,10 @@ bool rpc_hw_setLedBrightness(uint8_t value) { static inline bool rpc_hw_getWiFiMAC(const char** mac) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_GETWIFIMAC); MessageWriter_end(); @@ -218,10 +230,12 @@ bool rpc_hw_getWiFiMAC(const char** mac) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -229,10 +243,10 @@ bool rpc_hw_getWiFiMAC(const char** mac) { static inline bool rpc_hw_getEthernetMAC(const char** mac) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_HW_GETETHERNETMAC); MessageWriter_end(); @@ -248,10 +262,12 @@ bool rpc_hw_getEthernetMAC(const char** mac) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } diff --git a/src/idl/rpc_shim_mcu.h b/src/idl/rpc_shim_mcu.h index abe326b..0340563 100644 --- a/src/idl/rpc_shim_mcu.h +++ b/src/idl/rpc_shim_mcu.h @@ -12,6 +12,7 @@ extern "C" { static inline RpcStatus rpc_mcu_ping(void) { RpcStatus _rpc_res; + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_MCU_PING); MessageWriter_end(); @@ -22,6 +23,7 @@ RpcStatus rpc_mcu_ping(void) { _rpc_res = rpc_wait_result(_rpc_seq, &_rsp_buff, 100); rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_res; } @@ -29,10 +31,10 @@ RpcStatus rpc_mcu_ping(void) { static inline bool rpc_mcu_reboot(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_MCU_REBOOT); MessageWriter_end(); @@ -47,10 +49,12 @@ bool rpc_mcu_reboot(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -58,10 +62,10 @@ bool rpc_mcu_reboot(void) { static inline bool rpc_mcu_hasUID(uint16_t uid) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_MCU_HASUID); MessageWriter_writeUInt16(uid); @@ -77,10 +81,12 @@ bool rpc_mcu_hasUID(uint16_t uid) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } diff --git a/src/idl/rpc_shim_ncp.h b/src/idl/rpc_shim_ncp.h index c33f8f0..547c8a6 100644 --- a/src/idl/rpc_shim_ncp.h +++ b/src/idl/rpc_shim_ncp.h @@ -12,6 +12,7 @@ extern "C" { static inline RpcStatus rpc_ncp_ping(void) { RpcStatus _rpc_res; + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_NCP_PING); MessageWriter_end(); @@ -22,6 +23,7 @@ RpcStatus rpc_ncp_ping(void) { _rpc_res = rpc_wait_result(_rpc_seq, &_rsp_buff, 100); rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_res; } @@ -29,10 +31,10 @@ RpcStatus rpc_ncp_ping(void) { static inline bool rpc_ncp_reboot(void) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_NCP_REBOOT); MessageWriter_end(); @@ -47,10 +49,12 @@ bool rpc_ncp_reboot(void) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } @@ -58,10 +62,10 @@ bool rpc_ncp_reboot(void) { static inline bool rpc_ncp_hasUID(uint16_t uid) { RpcStatus _rpc_res; - /* Prepare return value */ bool _rpc_ret_val; memset(&_rpc_ret_val, 0, sizeof(_rpc_ret_val)); + RPC_MUTEX_LOCK(); /* Send request */ const uint16_t _rpc_seq = MessageWriter_beginInvoke(RPC_UID_NCP_HASUID); MessageWriter_writeUInt16(uid); @@ -77,10 +81,12 @@ bool rpc_ncp_hasUID(uint16_t uid) { } if (MessageBuffer_getError(&_rsp_buff) || MessageBuffer_availableToRead(&_rsp_buff)) { rpc_set_status(_rpc_res = RPC_STATUS_ERROR_RETS_R); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; } rpc_set_status(_rpc_res); + RPC_MUTEX_UNLOCK(); return _rpc_ret_val; }