Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[u-blox][r510] fixes EHS timing when modem locks up while in Power Saving mode #2850

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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