Skip to content

Commit

Permalink
Initial changes after review.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RobMeades committed Apr 4, 2024
1 parent 8b2e457 commit f8efe43
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
22 changes: 6 additions & 16 deletions ble/src/u_ble_sps_intmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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();
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions common/at_client/src/u_at_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions common/at_client/test/u_at_client_test_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/geofence/test/u_geofence_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion common/short_range/src/u_short_range_edm_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions port/platform/common/mutex_debug/u_mutex_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wifi/test/u_wifi_captive_portal_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static uDeviceCfg_t gDeviceCfg = {
}
};

static uTimeoutStop_t gTimeoutStop = {0};
static uTimeoutStop_t gTimeoutStop;

/* ----------------------------------------------------------------
* STATIC FUNCTIONS
Expand Down

0 comments on commit f8efe43

Please sign in to comment.