From f8efe433350165f4049ba0c48368d32a3242737d Mon Sep 17 00:00:00 2001 From: RobMeades Date: Thu, 4 Apr 2024 16:22:55 +0100 Subject: [PATCH] Initial changes after review. Test: 1 2 4.1 4.2 4.3.0 4.3.1 4.4.0 4.4.1 5.1.0 5.1.1 5.2.0 5.2.1 5.3 5.4 6.1.0 6.1.1 6.2.0 6.2.1 7 8 --- ble/src/u_ble_sps_intmod.c | 22 +++++-------------- common/at_client/src/u_at_client.c | 6 +++-- common/at_client/test/u_at_client_test_data.c | 20 ++++++++--------- common/geofence/test/u_geofence_test.c | 4 ++-- .../src/u_short_range_edm_stream.c | 1 - .../common/mutex_debug/u_mutex_debug.c | 8 +++---- wifi/test/u_wifi_captive_portal_test.c | 2 +- 7 files changed, 27 insertions(+), 36 deletions(-) diff --git a/ble/src/u_ble_sps_intmod.c b/ble/src/u_ble_sps_intmod.c index 672e053e..5ab05bee 100644 --- a/ble/src/u_ble_sps_intmod.c +++ b/ble/src/u_ble_sps_intmod.c @@ -1234,17 +1234,12 @@ int32_t uBleSpsSend(uDeviceHandle_t devHandle, int32_t channel, const char *pDat return (int32_t)U_ERROR_COMMON_INVALID_PARAMETER; } - int32_t startTimeMs = uPortGetTickTimeMs(); int32_t errorCode = (int32_t)U_ERROR_COMMON_SUCCESS; spsConnection_t *pSpsConn = pGetSpsConn(spsConnHandle); if (pSpsConn->spsState == SPS_STATE_CONNECTED) { - uint32_t timeout = pSpsConn->dataSendTimeoutMs; - int32_t time = startTimeMs; - - // Note: this loop is constructed slightly differently to usual - // and so can't use uTimeoutExpiredMs() but it - // _does_ perform tick time comparisons in a wrap-safe manner - while ((bytesLeftToSend > 0) && (time - startTimeMs < timeout)) { + uint32_t timeoutMs = pSpsConn->dataSendTimeoutMs; + uTimeoutStart_t timeoutStart = uTimeoutStart(); + while ((bytesLeftToSend > 0) && !uTimeoutExpiredMs(timeoutStart, timeoutMs)) { int32_t bytesToSendNow = bytesLeftToSend; int32_t maxDataLength = pSpsConn->mtu - U_BLE_PDU_HEADER_SIZE; @@ -1258,12 +1253,10 @@ int32_t uBleSpsSend(uDeviceHandle_t devHandle, int32_t channel, const char *pDat // again later if we are out of credits. (void)uPortSemaphoreTryTake(pSpsConn->txCreditsSemaphore, 0); if (pSpsConn->txCredits == 0) { - int32_t timeoutLeft = timeout - (time - startTimeMs); - if (timeoutLeft < 0) { - timeoutLeft = 0; - } + uint32_t elapsedMs = uTimeoutElapsedMs(timeoutStart); + uint32_t timeoutLeftMs = (elapsedMs >= timeoutMs) ? 0 : timeoutMs - elapsedMs; // We are out of credits, wait for more - if (uPortSemaphoreTryTake(pSpsConn->txCreditsSemaphore, timeoutLeft) != 0) { + if (uPortSemaphoreTryTake(pSpsConn->txCreditsSemaphore, timeoutLeftMs) != 0) { uPortLog("U_BLE_SPS: SPS timed out waiting for new TX credits!\n"); break; } @@ -1282,9 +1275,6 @@ int32_t uBleSpsSend(uDeviceHandle_t devHandle, int32_t channel, const char *pDat errorCode = (int32_t)U_ERROR_COMMON_UNKNOWN; break; } - if (bytesLeftToSend > 0) { - time = uPortGetTickTimeMs(); - } } } diff --git a/common/at_client/src/u_at_client.c b/common/at_client/src/u_at_client.c index bd47fd87..4db6e2f9 100644 --- a/common/at_client/src/u_at_client.c +++ b/common/at_client/src/u_at_client.c @@ -2774,6 +2774,7 @@ static uAtClientHandle_t clientAdd(const uAtClientStreamHandle_t *pStream, bool receiveBufferIsMalloced = false; uDeviceSerial_t *pDeviceSerial; int32_t errorCode = -1; + uTimeoutStart_t timeoutStart; U_PORT_MUTEX_LOCK(gMutex); @@ -2805,6 +2806,7 @@ static uAtClientHandle_t clientAdd(const uAtClientStreamHandle_t *pStream, (uPortMutexCreate(&(pClient->urcPermittedMutex)) == 0)) { // Set all the non-zero initial values before we set // the event handlers which might call us + timeoutStart = uTimeoutStart(); pClient->newSendNextTime = true; pClient->stream = *pStream; pClient->atTimeoutMs = U_AT_CLIENT_DEFAULT_TIMEOUT_MS; @@ -2817,10 +2819,10 @@ static uAtClientHandle_t clientAdd(const uAtClientStreamHandle_t *pStream, clearError(pClient); // This will also set stopTag setScope(pClient, U_AT_CLIENT_SCOPE_NONE); - pClient->lastTxTime = uTimeoutStart(); + pClient->lastTxTime = timeoutStart; pClient->urcMaxStringLength = U_AT_CLIENT_INITIAL_URC_LENGTH; pClient->maxRespLength = U_AT_CLIENT_MAX_LENGTH_INFORMATION_RESPONSE_PREFIX; - pClient->lastResponseStop = uTimeoutStart(); + pClient->lastResponseStop = timeoutStart; // Set up the buffer and its protection markers pClient->pReceiveBuffer->dataBufferSize = receiveBufferSize - U_AT_CLIENT_BUFFER_OVERHEAD_BYTES; diff --git a/common/at_client/test/u_at_client_test_data.c b/common/at_client/test/u_at_client_test_data.c index 2cbe2f9e..667147fb 100644 --- a/common/at_client/test/u_at_client_test_data.c +++ b/common/at_client/test/u_at_client_test_data.c @@ -872,7 +872,6 @@ static int32_t handleReadOnError(uAtClientHandle_t atClientHandle, int32_t lastError; uint64_t uint64; uTimeoutStart_t timeoutStart; - int32_t durationMs; const uAtClientTestEchoError_t *pError; #if !U_CFG_ENABLE_LOGGING @@ -942,21 +941,22 @@ static int32_t handleReadOnError(uAtClientHandle_t atClientHandle, } // The errors should be returned within the guard times - durationMs = uTimeoutElapsedMs(timeoutStart); if (lastError == 0) { - if (durationMs < pError->timeMinMs) { - U_TEST_PRINT_LINE_X("reads took %d ms when a minimum of %d ms was" - " expected.", index + 1, durationMs, - pError->timeMinMs); + if (uTimeoutExpiredMs(timeoutStart, pError->timeMinMs) { + U_TEST_PRINT_LINE_X("reads took %u ms when a minimum of %d ms was" + " expected.", index + 1, + uTimeoutElapsedMs(timeoutStart), + pError->timeMinMs); lastError = 6; } } if (lastError == 0) { - if (durationMs > pError->timeMaxMs) { - U_TEST_PRINT_LINE_X("reads took %d ms when a maximum of %d ms" - " was expected.", index + 1, durationMs, - pError->timeMaxMs); + if (uTimeoutExpiredMs(timeoutStop.timeoutStart, pError->timeMaxMs) { + U_TEST_PRINT_LINE_X("reads took %u ms when a maximum of %d ms" + " was expected.", index + 1, + uTimeoutElapsedMs(timeoutStart), + pError->timeMaxMs); lastError = 7; } } diff --git a/common/geofence/test/u_geofence_test.c b/common/geofence/test/u_geofence_test.c index f157489a..7a4283b4 100644 --- a/common/geofence/test/u_geofence_test.c +++ b/common/geofence/test/u_geofence_test.c @@ -858,10 +858,10 @@ U_PORT_TEST_FUNCTION("[geofence]", "geofenceBasic") } if (t > 0) { uPortLog(U_TEST_PREFIX_A "testing %d shape(s) (%d edge(s)) against %d point(s)," - " %d times each (print time excluded), averaged %u us per point", + " %d times each (print time excluded), averaged %u ms per point", (char) (x + 0x41), numShapes, numEdges, pTestData->numPoints, sizeof(gTestParameters) / sizeof(gTestParameters[0]), - (uTimeoutElapsedSeconds(timeoutStart) / + (uTimeoutElapsedMs(timeoutStart) / (pTestData->numPoints * sizeof(gTestParameters) / sizeof(gTestParameters[0])))); if (numFailedCalculations > 0) { uPortLog(" AND %d CALCULATION(S) FAILED.\n", numFailedCalculations); diff --git a/common/short_range/src/u_short_range_edm_stream.c b/common/short_range/src/u_short_range_edm_stream.c index 1e9984eb..09bb38ef 100644 --- a/common/short_range/src/u_short_range_edm_stream.c +++ b/common/short_range/src/u_short_range_edm_stream.c @@ -23,7 +23,6 @@ #endif //lint -efile(766, ctype.h) -#include "limits.h" // INT32_MAX #include "stddef.h" // NULL, size_t etc. #include "stdint.h" // int32_t etc. #include "stdbool.h" diff --git a/port/platform/common/mutex_debug/u_mutex_debug.c b/port/platform/common/mutex_debug/u_mutex_debug.c index 3773e7b4..e01d0b51 100644 --- a/port/platform/common/mutex_debug/u_mutex_debug.c +++ b/port/platform/common/mutex_debug/u_mutex_debug.c @@ -379,7 +379,7 @@ static void watchdogTask(void *pParam) { uMutexInfo_t *pMutexInfo; uMutexFunctionInfo_t *pWaiting; - uTimeoutStart_t called = uTimeoutStart(); + uTimeoutStart_t timeoutStart = uTimeoutStart(); bool callCallback = false; (void) pParam; @@ -418,8 +418,8 @@ static void watchdogTask(void *pParam) pMutexInfo = pMutexInfo->pNext; // Don't call the callback too often though - if (!uTimeoutExpiredMs(called, - U_MUTEX_DEBUG_WATCHDOG_MAX_BARK_SECONDS * 1000)) { + if (!uTimeoutExpiredSeconds(timeoutStart, + U_MUTEX_DEBUG_WATCHDOG_MAX_BARK_SECONDS)) { callCallback = false; } } @@ -429,7 +429,7 @@ static void watchdogTask(void *pParam) if (callCallback) { // Call the callback outside the locks so that it can have them gpWatchdogCallback(gpWatchdogCallbackParam); - called = uTimeoutStart(); + timeoutStart = uTimeoutStart(); } // Sleep until the next go diff --git a/wifi/test/u_wifi_captive_portal_test.c b/wifi/test/u_wifi_captive_portal_test.c index 8f1d585d..1e7634fe 100644 --- a/wifi/test/u_wifi_captive_portal_test.c +++ b/wifi/test/u_wifi_captive_portal_test.c @@ -130,7 +130,7 @@ static uDeviceCfg_t gDeviceCfg = { } }; -static uTimeoutStop_t gTimeoutStop = {0}; +static uTimeoutStop_t gTimeoutStop; /* ---------------------------------------------------------------- * STATIC FUNCTIONS