Skip to content

Commit

Permalink
[u-blox] fixes EHS timing when device locks up while in Power Saving …
Browse files Browse the repository at this point in the history
…Mode
  • Loading branch information
technobly committed Dec 11, 2024
1 parent 6caead0 commit 23f620c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions hal/network/ncp_client/sara/sara_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ const auto UBLOX_NCP_KEEPALIVE_MAX_MISSED = 5;
// const uint32_t UBLOX_NCP_BANDMASK_01_64_R510 = 0x0B0E189F; // Bands 1,2,3,4,5,8,12,13,18,19,20,25,26,28 [all default enabled]
const uint8_t UBLOX_NCP_BANDMASK_65_128_R510 = 0x40; // Band 66,85 enabled, 71 disabled [used as a mask]

const auto UBLOX_NCP_R5_EHS_STD_CLK_T1_MS = 23000; // Standard EHS timing
const auto UBLOX_NCP_R5_EHS_STD_CLK_T2_MS = 2000; // |
const auto UBLOX_NCP_R5_EHS_QTR_CLK_T1_MS = 80000; // 1/4 clock EHS timing
const auto UBLOX_NCP_R5_EHS_QTR_CLK_T2_MS = 5000; // |

// FIXME: for now using a very large buffer
const auto UBLOX_NCP_AT_CHANNEL_RX_BUFFER_SIZE = 4096;
const auto UBLOX_NCP_PPP_CHANNEL_RX_BUFFER_SIZE = 256;
Expand Down Expand Up @@ -205,6 +210,7 @@ int SaraNcpClient::init(const NcpClientConfig& conf) {
lastFirmwareInstallRespCodeR510_ = -1;
waitReadyRetries_ = 0;
sleepNoPPPWrite_ = false;
ehsExtendedTiming_ = false;
registrationTimeout_ = REGISTRATION_TIMEOUT;
resetRegistrationState();
if (modemPowerState()) {
Expand Down Expand Up @@ -1062,8 +1068,8 @@ int SaraNcpClient::waitReady(bool powerOn) {
// Hard reset the modem
modemHardReset(true);
ncpState(NcpState::OFF);
if (++waitReadyRetries_ >= 10) {
waitReadyRetries_ = 10;
if (++waitReadyRetries_ >= 3) {
waitReadyRetries_ = 3;
modemEmergencyHardReset();
}

Expand Down Expand Up @@ -2851,24 +2857,29 @@ int SaraNcpClient::modemEmergencyHardReset() {
return SYSTEM_ERROR_NONE;
}

LOG(TRACE, "Emergency hardware shutdown");
LOG(TRACE, "Emergency hardware shutdown the modem (%s)", ehsExtendedTiming_ ? "EXT" : "STD");
const auto pwrState = modemPowerState();
// We can only reset the modem in the powered state
if (!pwrState) {
LOG(ERROR, "Not powered on");
return SYSTEM_ERROR_INVALID_STATE;
}

const auto t1 = ehsExtendedTiming_ ? UBLOX_NCP_R5_EHS_QTR_CLK_T1_MS : UBLOX_NCP_R5_EHS_STD_CLK_T1_MS;
const auto t2 = ehsExtendedTiming_ ? UBLOX_NCP_R5_EHS_QTR_CLK_T2_MS : UBLOX_NCP_R5_EHS_STD_CLK_T2_MS;

ehsExtendedTiming_ = !ehsExtendedTiming_; // toggle between timing each time EHS is called

// Low held on power pin
hal_gpio_write(UBPWR, 0);
HAL_Delay_Milliseconds(500);
// Low held on reset pin
hal_gpio_write(UBRST, 0);
// Release power pin after 23s (23.5)
HAL_Delay_Milliseconds(23000);
HAL_Delay_Milliseconds(t1);
hal_gpio_write(UBPWR, 1);
// Release reset pin after 1.5s (2s)
HAL_Delay_Milliseconds(2000);
HAL_Delay_Milliseconds(t2);
hal_gpio_write(UBRST, 1);

ncpPowerState(NcpPowerState::TRANSIENT_ON);
Expand Down
1 change: 1 addition & 0 deletions hal/network/ncp_client/sara/sara_ncp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class SaraNcpClient: public CellularNcpClient {
int lastFirmwareInstallRespCodeR510_ = 0;
int waitReadyRetries_ = 0;
bool sleepNoPPPWrite_ = false;
bool ehsExtendedTiming_ = false;

system_tick_t lastWindow_ = 0;
size_t bytesInWindow_ = 0;
Expand Down

0 comments on commit 23f620c

Please sign in to comment.