Skip to content

Commit c761976

Browse files
committed
commit faf307c (HEAD -> feature/SARA-R510-NCP-FW-update, origin/feature/SARA-R510-NCP-FW-update)
Author: Technobly <[email protected]> Date: Wed Dec 15 16:26:50 2021 -0600 reduce specificity of expected publishEvent calls commit c9d846b Author: Technobly <[email protected]> Date: Wed Dec 15 13:24:25 2021 -0600 update CI unit tests to output verbose logs on failure commit 62c8fd9 Author: Technobly <[email protected]> Date: Tue Dec 14 13:17:39 2021 -0600 addresses final PR comments - Adds SaraNcpFwUpdateLock to make user interfaces thread-safe - Fixes issue with sUrcHandlers not retaining unique pointers - Allows cellular disconnect timeouts to proceed - Adds cellular_lock() before accessing variables used in urcHandlers - Fixes errors with comm. unit_tests caused by some initial code added for ncp_fw_update testing - Moves all NCPFW_LOG statements during SAFE_MODE to NCPFW_LOG_DEBUG to reduce size commit b509fbf Author: Technobly <[email protected]> Date: Fri Dec 10 22:42:52 2021 -0600 adds system_errors and diagnostics commit ac13d10 Author: Technobly <[email protected]> Date: Tue Nov 30 23:20:27 2021 -0600 adds SaraNcpFwUpdate unit tests commit 41f4093 Author: Technobly <[email protected]> Date: Mon Nov 22 23:19:58 2021 -0600 [hal] cellular add/remove urc handler commit 7c0d8f9 Author: Technobly <[email protected]> Date: Mon Nov 15 12:21:38 2021 -0600 skeleton for SaraNcpFwUpdate unit tests commit 5bb6334 Author: Technobly <[email protected]> Date: Fri Oct 29 20:59:23 2021 -0500 addresses most PR comments commit d22aaf6 Author: Technobly <[email protected]> Date: Fri Oct 22 15:13:34 2021 -0500 prevent a dependency issue causing a safe mode loop commit f762226 Author: Technobly <[email protected]> Date: Thu Sep 30 10:36:21 2021 -0500 Implements background modem update checks, Cellular.updateStatus(), Cellular.enableUpdates() commit 3d09a76 Author: Technobly <[email protected]> Date: Wed Sep 29 13:27:24 2021 -0500 rebase and whitespace fixes commit 6c2f5e9 Author: Technobly <[email protected]> Date: Mon Sep 27 10:34:43 2021 -0500 Move modem firmware version check to sara_ncp_client commit ca5cd65 Author: Technobly <[email protected]> Date: Tue Sep 21 17:21:37 2021 -0500 Revert "Remove more R510 FOTA support" This reverts commit 532acce. commit 59b5ec8 Author: Technobly <[email protected]> Date: Mon Sep 20 17:13:28 2021 -0500 Revert "Remove R510 FOTA support" This reverts commit a0b92dd. commit 6ececed Author: Technobly <[email protected]> Date: Fri Sep 17 22:40:41 2021 -0500 Removes System feature FEATURE_NCP_FW_UPDATES and some cleanup commit a78f8c1 Author: Technobly <[email protected]> Date: Fri Sep 10 17:04:29 2021 -0500 Remove R510 support for Gen2 commit 82b8b9f Author: Technobly <[email protected]> Date: Fri Aug 13 09:57:55 2021 -0500 implements System feature FEATURE_NCP_FW_UPDATES and performs NCP FW update in Safe Mode
1 parent 06fe749 commit c761976

37 files changed

+3561
-116
lines changed

ci/unit_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rm -rf .build/*
2222
mkdir -p .build/
2323
cd .build/
2424
cmake $cmake_args ..
25-
make all test coverage
25+
make all test coverage CTEST_OUTPUT_ON_FAILURE=TRUE
2626

2727
cmake_unit_tests=$?
2828

hal/inc/cellular_hal.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,32 @@ cellular_result_t cellular_process(void* reserved, void* reserved1);
265265
/**
266266
* Start NCP FW Update
267267
*/
268-
int cellular_start_ncp_firmware_update(bool update = false, void* reserved = NULL);
268+
int cellular_start_ncp_firmware_update(bool update, void* reserved);
269+
270+
/**
271+
* Get NCP firmware version as a uint32_t
272+
*/
273+
int cellular_get_ncp_firmware_version(uint32_t* version, void* reserved);
274+
275+
/**
276+
* Get modem firmware update status result
277+
*/
278+
int cellular_update_status(void* reserved);
279+
280+
/**
281+
* Enable modem firmware updates (blocking call, requires a pending update)
282+
*/
283+
int cellular_enable_updates(void* reserved);
284+
285+
/**
286+
* Add URC handler
287+
*/
288+
int cellular_add_urc_handler(const char* prefix, hal_cellular_urc_callback_t cb, void* context);
289+
290+
/**
291+
* Remove URC handler
292+
*/
293+
int cellular_remove_urc_handler(const char* prefix);
269294

270295
#ifdef __cplusplus
271296
}

hal/inc/cellular_hal_constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ typedef int (*_CALLBACKPTR_MDM)(int type, const char* buf, int len, void* param)
3737

3838
typedef void (*_CELLULAR_SMS_CB_MDM)(void* data, int index);
3939

40+
typedef int (*hal_cellular_urc_callback_t)(const char* data, void* context);
41+
4042
#ifdef __cplusplus
4143
// Todo - is storing raw string pointers correct here? These will only be valid
4244
// If they are stored as constants in the application.

hal/inc/hal_dynalib_cellular.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ DYNALIB_FN(BASE_CELL_IDX + 3, hal_cellular, cellular_powered, bool(void*))
9595
#endif // !HAL_PLATFORM_NCP
9696

9797
DYNALIB_FN(BASE_CELL_IDX1 + 0, hal_cellular, cellular_urcs, cellular_result_t(bool, void*))
98+
DYNALIB_FN(BASE_CELL_IDX1 + 1, hal_cellular, cellular_update_status, int(void*))
99+
DYNALIB_FN(BASE_CELL_IDX1 + 2, hal_cellular, cellular_enable_updates, int(void*))
98100

99101
DYNALIB_END(hal_cellular)
100102

hal/inc/hal_platform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@
434434
#define HAL_PLATFORM_NCP_COUNT (0)
435435
#endif // HAL_PLATFORM_NCP_COUNT
436436

437+
#ifndef HAL_PLATFORM_NCP_FW_UPDATE
438+
#define HAL_PLATFORM_NCP_FW_UPDATE (0)
439+
#endif // HAL_PLATFORM_NCP_FW_UPDATE
440+
437441
#ifndef HAL_PLATFORM_WIFI_COMPAT
438442
#define HAL_PLATFORM_WIFI_COMPAT (0)
439443
#endif // HAL_PLATFORM_WIFI_COMPAT

hal/inc/hal_platform_compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@
6868
#define HAL_PLATFORM_NEWLIB (1)
6969
#endif
7070

71+
#ifndef HAL_PLATFORM_NCP
7172
#define HAL_PLATFORM_NCP (0)
73+
#endif // HAL_PLATFORM_NCP
74+
#ifndef HAL_PLATFORM_NCP_AT
7275
#define HAL_PLATFORM_NCP_AT (0)
76+
#endif // HAL_PLATFORM_NCP_AT
7377

7478
#define HAL_PLATFORM_DCT_NO_DEPRECATED (0)
7579

hal/network/ncp/cellular/cellular_hal.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "ifapi.h"
2424

2525
#include "system_network.h" // FIXME: For network_interface_index
26+
#include "spark_wiring_vector.h"
2627

2728
#include "str_util.h"
2829
#include "endian_util.h"
@@ -35,6 +36,8 @@
3536
#include "cellular_enums_hal.h"
3637
#include "cellular_ncp_dev_mapping.h"
3738

39+
#include "ncp_fw_update.h"
40+
3841
#include <limits>
3942

4043
namespace {
@@ -106,6 +109,37 @@ hal_net_access_tech_t fromCellularAccessTechnology(CellularAccessTechnology rat)
106109
}
107110
}
108111

112+
struct CellularHalUrcHandler {
113+
CellularHalUrcHandler(const char* prefix, hal_cellular_urc_callback_t callback, void* context) :
114+
prefix(prefix),
115+
callback(callback),
116+
context(context) {
117+
}
118+
const char* prefix;
119+
hal_cellular_urc_callback_t callback;
120+
void* context;
121+
};
122+
123+
Vector<std::unique_ptr<CellularHalUrcHandler>> sUrcHandlers;
124+
125+
static int commonUrcHandler(AtResponseReader* reader, const char* prefix, void* data) {
126+
auto handler = static_cast<CellularHalUrcHandler*>(data);
127+
128+
const size_t atResponseSize = 64;
129+
std::unique_ptr<char[]> atResponse(new(std::nothrow) char[atResponseSize]);
130+
CHECK_TRUE(atResponse.get(), SYSTEM_ERROR_NO_MEMORY);
131+
132+
const auto n = reader->readLine(atResponse.get(), atResponseSize - 1);
133+
if (n < 0) {
134+
return n;
135+
}
136+
atResponse[n] = '\0';
137+
handler->callback(atResponse.get(), handler->context);
138+
atResponse.reset();
139+
140+
return SYSTEM_ERROR_NONE;
141+
}
142+
109143
} // unnamed
110144

111145
int cellular_on(void* reserved) {
@@ -506,6 +540,43 @@ int cellular_command(_CALLBACKPTR_MDM cb, void* param, system_tick_t timeout_ms,
506540
return mdmTypeToResult(mdmType);
507541
}
508542

543+
int cellular_add_urc_handler(const char* prefix, hal_cellular_urc_callback_t cb, void* context) {
544+
const auto mgr = cellularNetworkManager();
545+
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
546+
const auto client = mgr->ncpClient();
547+
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);
548+
const auto parser = client->atParser();
549+
550+
const NcpClientLock lock(client);
551+
552+
auto entry = std::make_unique<CellularHalUrcHandler>(prefix, cb, context);
553+
CHECK_TRUE(entry, SYSTEM_ERROR_NO_MEMORY);
554+
sUrcHandlers.append(std::move(entry));
555+
auto handler = sUrcHandlers.last().get();
556+
557+
return parser->addUrcHandler(prefix, commonUrcHandler, handler);
558+
}
559+
560+
int cellular_remove_urc_handler(const char* prefix) {
561+
const auto mgr = cellularNetworkManager();
562+
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
563+
const auto client = mgr->ncpClient();
564+
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);
565+
const auto parser = client->atParser();
566+
567+
const NcpClientLock lock(client);
568+
569+
parser->removeUrcHandler(prefix);
570+
for (int i = 0; i < sUrcHandlers.size(); ++i) {
571+
if (strcmp(sUrcHandlers.at(i).get()->prefix, prefix) == 0) {
572+
sUrcHandlers.removeAt(i);
573+
break;
574+
}
575+
}
576+
577+
return SYSTEM_ERROR_NONE;
578+
}
579+
509580
int cellular_data_usage_set(CellularDataHal* data, void* reserved) {
510581
return SYSTEM_ERROR_NOT_SUPPORTED;
511582
}
@@ -608,3 +679,28 @@ int cellular_start_ncp_firmware_update(bool update, void* reserved) {
608679
CHECK(client->startNcpFwUpdate(update));
609680
return SYSTEM_ERROR_NONE;
610681
}
682+
683+
int cellular_get_ncp_firmware_version(uint32_t* version, void* reserved) {
684+
const auto mgr = cellularNetworkManager();
685+
CHECK_TRUE(mgr, SYSTEM_ERROR_UNKNOWN);
686+
const auto client = mgr->ncpClient();
687+
CHECK_TRUE(client, SYSTEM_ERROR_UNKNOWN);
688+
CHECK(client->getNcpFirmwareVersion(version));
689+
return SYSTEM_ERROR_NONE;
690+
}
691+
692+
int cellular_update_status(void* reserved) {
693+
#if HAL_PLATFORM_NCP_FW_UPDATE
694+
return services::SaraNcpFwUpdate::instance()->updateStatus();
695+
#else
696+
return SYSTEM_ERROR_NOT_SUPPORTED;
697+
#endif
698+
}
699+
700+
int cellular_enable_updates(void* reserved) {
701+
#if HAL_PLATFORM_NCP_FW_UPDATE
702+
return services::SaraNcpFwUpdate::instance()->enableUpdates();
703+
#else
704+
return SYSTEM_ERROR_NOT_SUPPORTED;
705+
#endif
706+
}

hal/network/ncp/cellular/cellular_ncp_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class CellularNcpClient: public NcpClient {
133133
virtual int getMtu() = 0;
134134
virtual int urcs(bool enable) = 0;
135135
virtual int startNcpFwUpdate(bool update) = 0;
136+
virtual int getNcpFirmwareVersion(uint32_t* version) = 0;
136137
};
137138

138139
inline CellularNcpClientConfig::CellularNcpClientConfig() :

hal/network/ncp_client/quectel/quectel_ncp_client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,10 @@ int QuectelNcpClient::startNcpFwUpdate(bool update) {
15361536
return 0;
15371537
}
15381538

1539+
int QuectelNcpClient::getNcpFirmwareVersion(uint32_t* version) {
1540+
return 0;
1541+
}
1542+
15391543
void QuectelNcpClient::connectionState(NcpConnectionState state) {
15401544
if (ncpState_ == NcpState::DISABLED) {
15411545
return;

hal/network/ncp_client/quectel/quectel_ncp_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class QuectelNcpClient: public CellularNcpClient {
7474
virtual int getMtu() override;
7575
virtual int urcs(bool enable) override;
7676
virtual int startNcpFwUpdate(bool update) override;
77+
virtual int getNcpFirmwareVersion(uint32_t* version) override;
7778

7879
auto getMuxer() {
7980
return &muxer_;

0 commit comments

Comments
 (0)