diff --git a/DEVELOPMENT_PRINCIPLES.md b/DEVELOPMENT_PRINCIPLES.md index 97c658f7..a1d7e26a 100644 --- a/DEVELOPMENT_PRINCIPLES.md +++ b/DEVELOPMENT_PRINCIPLES.md @@ -61,10 +61,20 @@ Since the commit messages are our only change documentation, and since Github is - when merging a PR, try to stick to squash-merges or rebase-merges, rather than plain-old merges of a branch, - if a customer makes a PR to the public `ubxlib` repo, bring it in as follows: - - make sure that the customer PR is a single commit (ask them to squash it and re-push if it is not), + - if the customer PR is NEITHER (a) a single commit, NOR (b) made up of nice discrete/sensible changes that would make sense to any other customer, then ask them to squash it into a nice clean single commit and re-push, - pull the PR into a branch of `ubxlib_priv` so that you can throw it at the test system to prove that it is all good, - make sure that `ubxlib` `master` is up to date with `ubxlib_priv` `master` (i.e. push `ubxlib_priv` `master` to `ubxlib` `master`, which should always be possible, see above), - do a rebase-merge of the customer PR into `ubxlib` `master` (i.e. directly, not going via `ubxlib_priv`), - - pull `ubxlib` `master` back into `ubxlib_priv` `master` (i.e. with the latest `ubxlib_priv` `master` on your machine, pull `ubxlib` `master` and then push that to `ubxlib_priv` `master`). - -The only exception to the above is when there has been active work on the `ubxlib_priv` `development` branch and that is ready to be brought into `master`: this should be brought into `ubxlib_priv` `master` through a normal (i.e. non-rebase, non-squash) merge since it will likely be a _very_ large commit of disparate things that will not be describable when in one big blob. \ No newline at end of file + - pull `ubxlib` `master` back into `ubxlib_priv` `master` (i.e. with the latest `ubxlib_priv` `master` checked-out on your machine, pull `ubxlib` `master` and then push that to `ubxlib_priv` `master`). + +The only exception to the above is when there has been active work on the `ubxlib_priv` `development` branch and that is ready to be brought into `master`: this should be brought into `ubxlib_priv` `master` through a normal (i.e. non-rebase, non-squash) merge since it will likely be a _very_ large commit of disparate things that will not be describable when in one big blob. + +As an aside, if `master` moves on underneath a branch **THAT YOU ALONE** are working on, please do a `rebase` of that development branch onto `master`, rather then merging the changes from `master` onto your branch, (i.e. checkout `master` locally, pull the latest `master` and then `rebase` your branch onto `master`); the reason for this is that, otherwise, the merge process can be confused and end up thinking that you intend to remove things that have just been added in the `master` branch. If you share the branch with someone else, i.e. you are not working on it alone, then take care because rebasing obviously changes history; it may still be the right thing to do, 'cos the ground has indeed moved underneath you, history _has_ changed, but make sure that anyone else who is working on the branch with you is aware of what you have done when you push the branch back to the repo. + +# Beware The Wrap +Embedded systems usually have no better than a 32 bit millisecond tick count, i.e. a signed 32 bit counter that will wrap at `INT32_MAX`, so modulo 2^31, or 2,147,483,648, or about 25 days; the return value of the port layer `uPortGetTickTimeMs()` is an `int32_t` for this reason. + +The systems that `ubxlib` is built into will need to be up for longer than 25 days, so the `ubxlib` code must behave well around such a wrap and, specifically, not unintentionally become stuck for 25 days if the tick counter happens to wrap while the code is waiting on it. Always use the `uPortTickTimeExpired()` or `uPortTickTimeBeyondStop()` functions (see [u_port.h](/port/api/u_port.h)) while waiting for a number of ticks to pass; these are designed to ensure that nothing will get stuck. + +# Be Explicit About Units +Where a number represents a quantity it will have a unit: seconds, milliseconds, nanoseconds, Volts, milliVolts, decibels, decibels relative to one milliWatt (dBm), words (as opposed to bytes), sheep, etc. You may recall the tale of the [Mars Climate Orbiter](https://en.wikipedia.org/wiki/Mars_Climate_Orbiter), a $327 million spacecraft that was lost because the NASA navigation software expected measurements in newton-seconds while their contractor was providing measurements in pound-force seconds, a factor of 4.5 different; where a number represents a quantity, **be explicit** about the unit by including it in the variable/parameter name. For instance, presented with a variable/parameter named `timeout`, you could get things wrong by three orders of magnitude or more when applying that parameter, without realising it; naming it something like `timeoutMs` or `timeoutSeconds` will make the intended usage clear. \ No newline at end of file diff --git a/ble/src/u_ble_sps_intmod.c b/ble/src/u_ble_sps_intmod.c index 770bb92e..23ee49d5 100644 --- a/ble/src/u_ble_sps_intmod.c +++ b/ble/src/u_ble_sps_intmod.c @@ -1239,7 +1239,10 @@ int32_t uBleSpsSend(uDeviceHandle_t devHandle, int32_t channel, const char *pDat uint32_t timeout = pSpsConn->dataSendTimeoutMs; int32_t time = startTime; - while ((bytesLeftToSend > 0) && (time - startTime < timeout)) { + // Note: this loop is constructed slightly differently to usual + // and so can't use uPortTickTimeExpired() but it + // _does_ perform tick time comparisons in a wrap-safe manner + while ((bytesLeftToSend > 0) && (time - startTimeMs < timeout)) { int32_t bytesToSendNow = bytesLeftToSend; int32_t maxDataLength = pSpsConn->mtu - U_BLE_PDU_HEADER_SIZE; diff --git a/cell/src/u_cell.c b/cell/src/u_cell.c index 02192c90..2813b05e 100644 --- a/cell/src/u_cell.c +++ b/cell/src/u_cell.c @@ -37,6 +37,7 @@ #include "u_error_common.h" +#include "u_port.h" #include "u_port_debug.h" #include "u_port_os.h" #include "u_port_heap.h" @@ -297,6 +298,8 @@ int32_t uCellAdd(uCellModuleType_t moduleType, pInstance->pinPwrOn = pinPwrOn; pInstance->pinVInt = pinVInt; pInstance->pinDtrPowerSaving = -1; + pInstance->lastCfunFlipTimeMs = uPortGetTickTimeMs(); + pInstance->lastDtrPinToggleTimeMs = uPortGetTickTimeMs(); for (size_t x = 0; x < sizeof(pInstance->networkStatus) / sizeof(pInstance->networkStatus[0]); x++) { diff --git a/cell/src/u_cell_loc.c b/cell/src/u_cell_loc.c index 51ba93e6..4c3b77ed 100644 --- a/cell/src/u_cell_loc.c +++ b/cell/src/u_cell_loc.c @@ -1780,7 +1780,7 @@ int32_t uCellLocGet(uDeviceHandle_t cellHandle, startTimeMs = uPortGetTickTimeMs(); while ((fixDataStorageBlock.errorCode == (int32_t) U_ERROR_COMMON_TIMEOUT) && (((pKeepGoingCallback == NULL) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, U_CELL_LOC_TIMEOUT_SECONDS * 1000)) || + !uPortTickTimeExpired(startTimeMs, U_CELL_LOC_TIMEOUT_SECONDS * 1000)) || ((pKeepGoingCallback != NULL) && pKeepGoingCallback(cellHandle)))) { // Relax a little uPortTaskBlock(1000); diff --git a/cell/src/u_cell_mqtt.c b/cell/src/u_cell_mqtt.c index f66e7639..478d45b8 100644 --- a/cell/src/u_cell_mqtt.c +++ b/cell/src/u_cell_mqtt.c @@ -1100,8 +1100,8 @@ static int32_t doSaraR4OldSyntaxUmqttQuery(const uCellPrivateInstance_t *pInstan // and don't bother with keepGoingCallback startTimeMs = uPortGetTickTimeMs(); while ((!checkUrcStatusField(pUrcStatus, number)) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_MQTT_LOCAL_URC_TIMEOUT_MS)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_MQTT_LOCAL_URC_TIMEOUT_MS)) { uPortTaskBlock(250); } if (checkUrcStatusField(pUrcStatus, number)) { @@ -1347,8 +1347,8 @@ static int32_t connect(const uCellPrivateInstance_t *pInstance, // take a little while to find out that the connection // has actually been made and hence we wait here for // it to be ready to connect - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->connectedAtMs, - U_CELL_MQTT_CONNECT_DELAY_MILLISECONDS)) { + while (!uPortTickTimeExpired(pInstance->connectedAtMs, + U_CELL_MQTT_CONNECT_DELAY_MILLISECONDS)) { uPortTaskBlock(100); } } @@ -1401,8 +1401,8 @@ static int32_t connect(const uCellPrivateInstance_t *pInstance, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_CONNECT_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -1702,8 +1702,8 @@ static int32_t publish(const uCellPrivateInstance_t *pInstance, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_PUBLISH_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -1809,8 +1809,8 @@ static int32_t subscribe(const uCellPrivateInstance_t *pInstance, errorCodeOrQos = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_SUBSCRIBE_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -1898,8 +1898,8 @@ static int32_t unsubscribe(const uCellPrivateInstance_t *pInstance, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_UNSUBSCRIBE_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -1988,8 +1988,8 @@ static int32_t readMessage(const uCellPrivateInstance_t *pInstance, errorCode = (int32_t) U_ERROR_COMMON_EMPTY; startTimeMs = uPortGetTickTimeMs(); while (!pUrcMessage->messageRead && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -3389,8 +3389,8 @@ int32_t uCellMqttSnRegisterNormalTopic(uDeviceHandle_t cellHandle, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_REGISTER_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -3659,8 +3659,8 @@ int32_t uCellMqttSnSetWillMessaage(uDeviceHandle_t cellHandle, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_WILL_MESSAGE_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); @@ -3735,8 +3735,8 @@ int32_t uCellMqttSnSetWillParameters(uDeviceHandle_t cellHandle, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (((pUrcStatus->flagsBitmap & (1 << U_CELL_MQTT_URC_FLAG_WILL_PARAMETERS_UPDATED)) == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback())) { uPortTaskBlock(1000); diff --git a/cell/src/u_cell_mux.c b/cell/src/u_cell_mux.c index 4242e7ea..a3d54167 100644 --- a/cell/src/u_cell_mux.c +++ b/cell/src/u_cell_mux.c @@ -252,7 +252,7 @@ static int32_t sendEvent(uCellMuxPrivateContext_t *pContext, uPortTaskBlock(U_CFG_OS_YIELD_MS); irqSupported = (errorCode != (int32_t) U_ERROR_COMMON_NOT_IMPLEMENTED) && (errorCode != (int32_t) U_ERROR_COMMON_NOT_SUPPORTED); - } while (irqSupported && !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, delayMs)); + } while (irqSupported && !uPortTickTimeExpired(startTimeMs, delayMs)); if (!irqSupported) { // If IRQ is not supported, just gotta do the normal send @@ -380,7 +380,7 @@ static int32_t serialWriteInnards(struct uDeviceSerial_t *pDeviceSerial, } startTimeMs = uPortGetTickTimeMs(); while ((sizeWritten < sizeBytes) && (sizeOrErrorCode >= 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, + !uPortTickTimeExpired(startTimeMs, U_CELL_MUX_WRITE_TIMEOUT_MS)) { // Encode a chunk as UIH thisChunkSize = sizeBytes - sizeWritten; @@ -394,7 +394,7 @@ static int32_t serialWriteInnards(struct uDeviceSerial_t *pDeviceSerial, if (sizeOrErrorCode >= 0) { lengthWritten = 0; while ((sizeOrErrorCode >= 0) && (lengthWritten < (size_t) sizeOrErrorCode) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, + !uPortTickTimeExpired(startTimeMs, U_CELL_MUX_WRITE_TIMEOUT_MS)) { if (!pChannelContext->traffic.txIsFlowControlledOff) { // Send the data @@ -515,7 +515,7 @@ static int32_t sendCommandCheckResponse(uDeviceSerial_t *pDeviceSerial, // Wait for a response startTimeMs = uPortGetTickTimeMs(); while ((pTraffic->wantedResponseFrameType != U_CELL_MUX_PRIVATE_FRAME_TYPE_NONE) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, timeoutMs)) { uPortTaskBlock(10); } if (pTraffic->wantedResponseFrameType == U_CELL_MUX_PRIVATE_FRAME_TYPE_NONE) { diff --git a/cell/src/u_cell_net.c b/cell/src/u_cell_net.c index 2c0a92da..4dfd8007 100644 --- a/cell/src/u_cell_net.c +++ b/cell/src/u_cell_net.c @@ -749,8 +749,8 @@ static bool keepGoingLocalCb(const uCellPrivateInstance_t *pInstance) keepGoing = pInstance->pKeepGoingCallback(pInstance->cellHandle); } else { if ((pInstance->startTimeMs > 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->startTimeMs, - U_CELL_NET_CONNECT_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(pInstance->startTimeMs, + U_CELL_NET_CONNECT_TIMEOUT_SECONDS * 1000)) { keepGoing = false; } } @@ -770,8 +770,8 @@ static int32_t radioOff(uCellPrivateInstance_t *pInstance) pInstance->profileState = U_CELL_PRIVATE_PROFILE_STATE_SHOULD_BE_DOWN; for (size_t x = 3; (x > 0) && (errorCode < 0); x--) { // Wait for flip time to expire - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastCfunFlipTimeMs, - U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { + while (!uPortTickTimeExpired(pInstance->lastCfunFlipTimeMs, + U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { uPortTaskBlock(1000); } uAtClientLock(atHandle); @@ -1242,8 +1242,8 @@ static int32_t registerNetwork(uCellPrivateInstance_t *pInstance, // Come out of airplane mode and try to register // Wait for flip time to expire first though - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastCfunFlipTimeMs, - U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { + while (!uPortTickTimeExpired(pInstance->lastCfunFlipTimeMs, + U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { uPortTaskBlock(1000); } // Reset the current registration status @@ -1804,8 +1804,8 @@ static int32_t activateContextUpsd(const uCellPrivateInstance_t *pInstance, deviceError.type = U_AT_CLIENT_DEVICE_ERROR_TYPE_NO_ERROR; while (!activated && keepGoingLocalCb(pInstance) && (deviceError.type == U_AT_CLIENT_DEVICE_ERROR_TYPE_NO_ERROR) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_NET_UPSD_CONTEXT_ACTIVATION_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_NET_UPSD_CONTEXT_ACTIVATION_TIME_SECONDS * 1000)) { uAtClientClearError(atHandle); uAtClientResponseStart(atHandle, NULL); activated = (uAtClientErrorGet(atHandle) == 0); @@ -2990,8 +2990,8 @@ int32_t uCellNetScanGetFirst(uDeviceHandle_t cellHandle, bytesRead = -1; innerStartTimeMs = uPortGetTickTimeMs(); while ((bytesRead <= 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(innerStartTimeMs, - U_CELL_NET_SCAN_TIME_SECONDS * 1000) && + !uPortTickTimeExpired(innerStartTimeMs, + U_CELL_NET_SCAN_TIME_SECONDS * 1000) && ((pKeepGoingCallback == NULL) || (pKeepGoingCallback(cellHandle)))) { uAtClientResponseStart(atHandle, "+COPS:"); // We use uAtClientReadBytes() here because the @@ -3148,8 +3148,8 @@ int32_t uCellNetDeepScan(uDeviceHandle_t cellHandle, startTimeMs = uPortGetTickTimeMs(); for (size_t x = U_CELL_NET_DEEP_SCAN_RETRIES + 1; (x > 0) && (errorCodeOrNumber < 0) && keepGoing && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_NET_DEEP_SCAN_TIME_SECONDS * 1000); + !uPortTickTimeExpired(startTimeMs, + U_CELL_NET_DEEP_SCAN_TIME_SECONDS * 1000); x--) { number = 0; errorCodeOrNumber = (int32_t) U_ERROR_COMMON_TIMEOUT; @@ -3166,8 +3166,8 @@ int32_t uCellNetDeepScan(uDeviceHandle_t cellHandle, // want to be able to stop the command part way through, // hence the AT handling code below is more complex than usual. while ((errorCodeOrNumber == (int32_t) U_ERROR_COMMON_TIMEOUT) && keepGoing && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_NET_DEEP_SCAN_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_NET_DEEP_SCAN_TIME_SECONDS * 1000)) { if (uAtClientResponseStart(atHandle, NULL) == 0) { // See if we have a line errorCodeOrNumber = parseDeepScanLine(atHandle, &cell); diff --git a/cell/src/u_cell_private.c b/cell/src/u_cell_private.c index f1c3a9f6..d8c0d27f 100644 --- a/cell/src/u_cell_private.c +++ b/cell/src/u_cell_private.c @@ -819,8 +819,8 @@ int32_t uCellPrivateCFunOne(uCellPrivateInstance_t *pInstance) // Set powered-up mode if it wasn't already if (errorCodeOrMode != 1) { // Wait for flip time to expire - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastCfunFlipTimeMs, - U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { + while (!uPortTickTimeExpired(pInstance->lastCfunFlipTimeMs, + U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { uPortTaskBlock(1000); } uAtClientLock(atHandle); @@ -844,8 +844,8 @@ void uCellPrivateCFunMode(uCellPrivateInstance_t *pInstance, uAtClientHandle_t atHandle = pInstance->atHandle; // Wait for flip time to expire - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastCfunFlipTimeMs, - U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { + while (!uPortTickTimeExpired(pInstance->lastCfunFlipTimeMs, + U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { uPortTaskBlock(1000); } uAtClientLock(atHandle); @@ -1453,8 +1453,8 @@ void uCellPrivateSetPinDtr(uCellPrivateInstance_t *pInstance, bool doNotPowerSav if (!doNotPowerSave) { targetState = !targetState; } - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastDtrPinToggleTimeMs, - U_CELL_PWR_UART_POWER_SAVING_DTR_HYSTERESIS_MS)) { + while (!uPortTickTimeExpired(pInstance->lastDtrPinToggleTimeMs, + U_CELL_PWR_UART_POWER_SAVING_DTR_HYSTERESIS_MS)) { uPortTaskBlock(U_CELL_PRIVATE_DTR_PIN_HYSTERESIS_INTERVAL_MS); } if (uPortGpioSet(pInstance->pinDtrPowerSaving, targetState) == 0) { diff --git a/cell/src/u_cell_pwr.c b/cell/src/u_cell_pwr.c index 2ea3ca2b..96a37126 100644 --- a/cell/src/u_cell_pwr.c +++ b/cell/src/u_cell_pwr.c @@ -1116,8 +1116,8 @@ static int32_t moduleConfigure(uCellPrivateInstance_t *pInstance, if (andRadioOff) { // Switch the radio off until commanded to connect // Wait for flip time to expire - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastCfunFlipTimeMs, - U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { + while (!uPortTickTimeExpired(pInstance->lastCfunFlipTimeMs, + U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { uPortTaskBlock(1000); } uAtClientLock(atHandle); @@ -1146,8 +1146,8 @@ static void waitForPowerOff(uCellPrivateInstance_t *pInstance, int32_t startTimeMs = uPortGetTickTimeMs(); while (!moduleIsOff && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - pInstance->pModule->powerDownWaitSeconds * 1000) && + !uPortTickTimeExpired(startTimeMs, + pInstance->pModule->powerDownWaitSeconds * 1000) && ((pKeepGoingCallback == NULL) || pKeepGoingCallback(pInstance->cellHandle))) { if (pInstance->pinVInt >= 0) { // If we have a VInt pin then wait until that @@ -2160,8 +2160,8 @@ int32_t uCellPwrReboot(uDeviceHandle_t cellHandle, if (pInstance != NULL) { uPortLog("U_CELL_PWR: rebooting.\n"); // Wait for flip time to expire - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->lastCfunFlipTimeMs, - U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { + while (!uPortTickTimeExpired(pInstance->lastCfunFlipTimeMs, + U_CELL_PRIVATE_AT_CFUN_FLIP_DELAY_SECONDS * 1000)) { uPortTaskBlock(1000); } // Sleep is no longer available @@ -2323,7 +2323,7 @@ int32_t uCellPwrResetHard(uDeviceHandle_t cellHandle, int32_t pinReset) // We have rebooted pInstance->rebootIsRequired = false; startTimeMs = uPortGetTickTimeMs(); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, resetHoldMilliseconds)) { + while (!uPortTickTimeExpired(startTimeMs, resetHoldMilliseconds)) { uPortTaskBlock(100); } // Set the pin back to the "non RESET" state diff --git a/cell/src/u_cell_sock.c b/cell/src/u_cell_sock.c index 43ad976b..3ca4b73d 100644 --- a/cell/src/u_cell_sock.c +++ b/cell/src/u_cell_sock.c @@ -1984,15 +1984,15 @@ int32_t uCellSockGetHostByName(uDeviceHandle_t cellHandle, // we're on LENA-R8 then allow one retry. startTimeMs = uPortGetTickTimeMs(); while (((atError < 0) || (bytesRead <= 0)) && - (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_SOCK_DNS_SHOULD_RETRY_MS) || + (!uPortTickTimeExpired(startTimeMs, + U_CELL_SOCK_DNS_SHOULD_RETRY_MS) || ((pInstance->pModule->moduleType == U_CELL_MODULE_TYPE_LENA_R8) && (tries < 2)))) { if (pInstance->pModule->moduleType == U_CELL_MODULE_TYPE_SARA_R422) { // SARA-R422 can get upset if UDNSRN is sent very quickly // after a connection is made so we add a short delay here - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pInstance->connectedAtMs, - U_CELL_SOCK_SARA_R422_DNS_DELAY_MILLISECONDS)) { + while (!uPortTickTimeExpired(pInstance->connectedAtMs, + U_CELL_SOCK_SARA_R422_DNS_DELAY_MILLISECONDS)) { uPortTaskBlock(100); } } diff --git a/cell/src/u_cell_time.c b/cell/src/u_cell_time.c index 6c2970e5..103b9525 100644 --- a/cell/src/u_cell_time.c +++ b/cell/src/u_cell_time.c @@ -729,8 +729,8 @@ int32_t uCellTimeSyncCellEnable(uDeviceHandle_t cellHandle, startTimeMs = uPortGetTickTimeMs(); errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; while ((pContext->errorCode == INT_MIN) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_SYNC_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_SYNC_TIME_SECONDS * 1000)) { uPortTaskBlock(1000); } if (pContext->errorCode != INT_MIN) { @@ -792,8 +792,8 @@ int32_t uCellTimeSyncCellDisable(uDeviceHandle_t cellHandle) startTimeMs = uPortGetTickTimeMs(); errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; while ((pContext->errorCode != (int32_t) U_ERROR_COMMON_CANCELLED) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_SYNC_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_SYNC_TIME_SECONDS * 1000)) { uPortTaskBlock(1000); } if (pContext->errorCode != INT_MIN) { diff --git a/cell/test/u_cell_cfg_test.c b/cell/test/u_cell_cfg_test.c index 2922b834..80f530ca 100644 --- a/cell/test/u_cell_cfg_test.c +++ b/cell/test/u_cell_cfg_test.c @@ -157,7 +157,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_geofence_test.c b/cell/test/u_cell_geofence_test.c index de2b04af..e850b3d9 100644 --- a/cell/test/u_cell_geofence_test.c +++ b/cell/test/u_cell_geofence_test.c @@ -176,7 +176,7 @@ static bool keepGoingCallback(uDeviceHandle_t cellHandle) bool keepGoing = true; U_PORT_TEST_ASSERT(cellHandle == gHandles.cellHandle); - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_http_test.c b/cell/test/u_cell_http_test.c index 51e84d38..d998648b 100644 --- a/cell/test/u_cell_http_test.c +++ b/cell/test/u_cell_http_test.c @@ -183,7 +183,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -297,7 +297,7 @@ static bool waitCheckHttpResponse(int32_t timeoutSeconds, U_TEST_PRINT_LINE("waiting up to %d second(s) for response to request type %s...", timeoutSeconds, pHttpRequestTypeStr(requestType)); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutSeconds * 1000) && + while (!uPortTickTimeExpired(startTimeMs, timeoutSeconds * 1000) && !pCallbackData->called) { uPortTaskBlock(100); } diff --git a/cell/test/u_cell_info_test.c b/cell/test/u_cell_info_test.c index 6efb5872..14fcbcf6 100644 --- a/cell/test/u_cell_info_test.c +++ b/cell/test/u_cell_info_test.c @@ -119,7 +119,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_loc_test.c b/cell/test/u_cell_loc_test.c index 4356d8d9..5388f746 100644 --- a/cell/test/u_cell_loc_test.c +++ b/cell/test/u_cell_loc_test.c @@ -248,7 +248,7 @@ static bool keepGoingCallback(uDeviceHandle_t param) (void) param; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_mqtt_test.c b/cell/test/u_cell_mqtt_test.c index 6920d4d2..4a00ecd3 100644 --- a/cell/test/u_cell_mqtt_test.c +++ b/cell/test/u_cell_mqtt_test.c @@ -162,7 +162,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_mux_test.c b/cell/test/u_cell_mux_test.c index 82548594..32ae8b99 100644 --- a/cell/test/u_cell_mux_test.c +++ b/cell/test/u_cell_mux_test.c @@ -226,7 +226,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -383,7 +383,7 @@ static bool httpWaitCheckResponse(int32_t timeoutSeconds, U_TEST_PRINT_LINE("waiting up to %d second(s) for response to HTTP request...", timeoutSeconds); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutSeconds * 1000) && + while (!uPortTickTimeExpired(startTimeMs, timeoutSeconds * 1000) && !pCallbackData->called) { uPortTaskBlock(100); } @@ -787,8 +787,8 @@ U_PORT_TEST_FUNCTION("[cellMux]", "cellMuxMqtt") U_TEST_PRINT_LINE("waiting %d second(s) for message to be sent back...", U_CELL_MUX_TEST_MQTT_RESPONSE_TIMEOUT_MS); while ((gMqttMessagesAvailable == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_MUX_TEST_MQTT_RESPONSE_TIMEOUT_MS)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_MUX_TEST_MQTT_RESPONSE_TIMEOUT_MS)) { uPortTaskBlock(1000); } diff --git a/cell/test/u_cell_net_test.c b/cell/test/u_cell_net_test.c index ac8a89d7..de4cc487 100644 --- a/cell/test/u_cell_net_test.c +++ b/cell/test/u_cell_net_test.c @@ -127,7 +127,7 @@ static bool keepGoingCallback(uDeviceHandle_t cellHandle) gCallbackErrorCode = 1; } - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_ppp_test.c b/cell/test/u_cell_ppp_test.c index a78e8d2b..2cfed0c6 100644 --- a/cell/test/u_cell_ppp_test.c +++ b/cell/test/u_cell_ppp_test.c @@ -140,7 +140,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_pwr_test.c b/cell/test/u_cell_pwr_test.c index 12f9aee2..030c6eed 100644 --- a/cell/test/u_cell_pwr_test.c +++ b/cell/test/u_cell_pwr_test.c @@ -241,7 +241,7 @@ static bool keepGoingCallback(uDeviceHandle_t cellHandle) gCallbackErrorCode = 1; } - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_sock_test.c b/cell/test/u_cell_sock_test.c index ec85a295..8c554d08 100644 --- a/cell/test/u_cell_sock_test.c +++ b/cell/test/u_cell_sock_test.c @@ -459,7 +459,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/cell/test/u_cell_time_test.c b/cell/test/u_cell_time_test.c index bf29b995..fa377ed0 100644 --- a/cell/test/u_cell_time_test.c +++ b/cell/test/u_cell_time_test.c @@ -169,7 +169,7 @@ static bool keepGoingCallback(uDeviceHandle_t unused) (void) unused; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -273,7 +273,7 @@ static bool cellInfoCallback(uDeviceHandle_t cellHandle, } } - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -418,8 +418,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") if (pModule->moduleType == U_CELL_MODULE_TYPE_SARA_R5) { U_PORT_TEST_ASSERT(y == 0); while (!gEvent.synchronised && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gEventCallback is %d.", gEventCallback); @@ -456,8 +456,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") if (pModule->moduleType == U_CELL_MODULE_TYPE_SARA_R5) { U_PORT_TEST_ASSERT(y == 0); while (!gEvent.synchronised && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gEventCallback is %d.", gEventCallback); @@ -496,8 +496,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") !gnssIsInsideCell, 0, eventCallback, &gEventCallback) == 0); while (!gEvent.synchronised && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gEventCallback is %d.", gEventCallback); @@ -506,8 +506,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") printAndCheckEvent(&gEvent, !gnssIsInsideCell); startTimeMs = uPortGetTickTimeMs(); while ((gTimeCallback == INT_MIN) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gTimeCallback is %d.", gTimeCallback); @@ -550,8 +550,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") !uCellLocGnssInsideCell(cellHandle), 0, eventCallback, &gEventCallback) == 0); while (!gEvent.synchronised && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gEventCallback is %d.", gEventCallback); @@ -560,8 +560,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") printAndCheckEvent(&gEvent, !gnssIsInsideCell); startTimeMs = uPortGetTickTimeMs(); while ((gTimeCallback == INT_MIN) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gTimeCallback is %d.", gTimeCallback); @@ -664,8 +664,8 @@ U_PORT_TEST_FUNCTION("[cellTime]", "cellTimeBasic") U_PORT_TEST_ASSERT(uCellTimeEnable(cellHandle, U_CELL_TIME_MODE_EXT_INT_TIMESTAMP, true, 0, eventCallback, &gEventCallback) == 0); while (!gEvent.synchronised && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_CELL_TIME_TEST_GUARD_TIME_SECONDS * 1000)) { uPortTaskBlock(100); } U_TEST_PRINT_LINE("gEventCallback is %d.", gEventCallback); diff --git a/common/at_client/src/u_at_client.c b/common/at_client/src/u_at_client.c index 4128feb1..0cebc25c 100644 --- a/common/at_client/src/u_at_client.c +++ b/common/at_client/src/u_at_client.c @@ -2263,9 +2263,9 @@ static size_t write(uAtClientInstance_t *pClient, while (((pData < pDataEnd) || andFlush) && (pClient->error == U_ERROR_COMMON_SUCCESS)) { lengthToWrite = length - (pData - pDataStart); - if ((pClient->pWakeUp != NULL) && (pClient->lastTxTimeMs >= 0) && - U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pClient->lastTxTimeMs, - pClient->pWakeUp->inactivityTimeoutMs) && + if ((pClient->pWakeUp != NULL) && + uPortTickTimeExpired(pClient->lastTxTimeMs, + pClient->pWakeUp->inactivityTimeoutMs) && (uPortMutexTryLock(pClient->pWakeUp->inWakeUpHandlerMutex, 0) == 0)) { // We have a wake-up handler, the inactivity timeout // has expired and we've managed to lock the wake-up @@ -2448,8 +2448,8 @@ static uPortMutexHandle_t tryLock(uAtClientInstance_t *pClient) pClient->lockTimeMs = uPortGetTickTimeMs(); if (pClient->pActivityPin != NULL) { // If an activity pin is set then switch it on - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pClient->pActivityPin->lastToggleTime, - pClient->pActivityPin->hysteresisMs)) { + while (!uPortTickTimeExpired(pClient->pActivityPin->lastToggleTime, + pClient->pActivityPin->hysteresisMs)) { uPortTaskBlock(U_AT_CLIENT_ACTIVITY_PIN_HYSTERESIS_INTERVAL_MS); } if (uPortGpioSet(pClient->pActivityPin->pin, @@ -2491,8 +2491,8 @@ static void unlockNoDataCheck(uAtClientInstance_t *pClient, if (pClient->pActivityPin != NULL) { // If an activity pin is set then switch it off - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pClient->pActivityPin->lastToggleTime, - pClient->pActivityPin->hysteresisMs)) { + while (!uPortTickTimeExpired(pClient->pActivityPin->lastToggleTime, + pClient->pActivityPin->hysteresisMs)) { uPortTaskBlock(U_AT_CLIENT_ACTIVITY_PIN_HYSTERESIS_INTERVAL_MS); } if (uPortGpioSet(pClient->pActivityPin->pin, @@ -2817,9 +2817,10 @@ static uAtClientHandle_t clientAdd(const uAtClientStreamHandle_t *pStream, clearError(pClient); // This will also set stopTag setScope(pClient, U_AT_CLIENT_SCOPE_NONE); - pClient->lastTxTimeMs = -1; + pClient->lastTxTimeMs = uPortGetTickTimeMs(); pClient->urcMaxStringLength = U_AT_CLIENT_INITIAL_URC_LENGTH; pClient->maxRespLength = U_AT_CLIENT_MAX_LENGTH_INFORMATION_RESPONSE_PREFIX; + pClient->lastResponseStopMs = uPortGetTickTimeMs(); // Set up the buffer and its protection markers pClient->pReceiveBuffer->dataBufferSize = receiveBufferSize - U_AT_CLIENT_BUFFER_OVERHEAD_BYTES; @@ -3260,8 +3261,8 @@ void uAtClientLock(uAtClientHandle_t atHandle) streamMutex = streamLock(pClient); mutexStackPush(&(pClient->lockedStreamMutexStack), streamMutex); if (pClient->pActivityPin != NULL) { - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pClient->pActivityPin->lastToggleTime, - pClient->pActivityPin->hysteresisMs)) { + while (!uPortTickTimeExpired(pClient->pActivityPin->lastToggleTime, + pClient->pActivityPin->hysteresisMs)) { uPortTaskBlock(U_AT_CLIENT_ACTIVITY_PIN_HYSTERESIS_INTERVAL_MS); } // If an activity pin is set then switch it on @@ -3388,11 +3389,10 @@ void uAtClientCommandStart(uAtClientHandle_t atHandle, U_AT_CLIENT_LOCK_CLIENT_MUTEX(pClient); if (pClient->error == U_ERROR_COMMON_SUCCESS) { - // Wait for delay period if required, constructed this way - // to be safe if uPortGetTickTimeMs() wraps + // Wait for delay period if required if (pClient->delayMs > 0) { - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(pClient->lastResponseStopMs, - pClient->delayMs)) { + while (!uPortTickTimeExpired(pClient->lastResponseStopMs, + pClient->delayMs)) { uPortTaskBlock(10); } } @@ -3968,7 +3968,7 @@ int32_t uAtClientWaitCharacter(uAtClientHandle_t atHandle, pClient->numConsecutiveAtTimeouts = 0; } } else { - if (U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, pClient->atTimeoutMs)) { + if (uPortTickTimeExpired(startTimeMs, pClient->atTimeoutMs)) { // If we're stuck, set an error setError(pClient, U_ERROR_COMMON_DEVICE_ERROR); consecutiveTimeout(pClient); diff --git a/common/http_client/src/u_http_client.c b/common/http_client/src/u_http_client.c index 93677800..ac8e9f39 100644 --- a/common/http_client/src/u_http_client.c +++ b/common/http_client/src/u_http_client.c @@ -689,7 +689,7 @@ static int32_t block(volatile uHttpClientContext_t *pContext) // HTTP status code while ((statusCodeOrError == 0) && ((pContext->pKeepGoingCallback == NULL) || pContext->pKeepGoingCallback()) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, pContext->timeoutSeconds * 2 * 1000)) { + !uPortTickTimeExpired(startTimeMs, pContext->timeoutSeconds * 2 * 1000)) { if (uPortSemaphoreTryTake((uPortSemaphoreHandle_t) pContext->semaphoreHandle, 100) == 0) { statusCodeOrError = pContext->statusCodeOrError; } diff --git a/common/http_client/test/u_http_client_test.c b/common/http_client/test/u_http_client_test.c index 26309e8a..d7168b73 100644 --- a/common/http_client/test/u_http_client_test.c +++ b/common/http_client/test/u_http_client_test.c @@ -435,8 +435,8 @@ static int32_t checkResponse(uHttpClientTestOperation_t operation, " %d second(s)...", (pConnection->timeoutSeconds * 2) + U_HTTP_CLIENT_TEST_RESPONSE_TIMEOUT_EXTRA_SECONDS); while (!pCallbackData->called && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, ((pConnection->timeoutSeconds * 2) + - U_HTTP_CLIENT_TEST_RESPONSE_TIMEOUT_EXTRA_SECONDS) * 1000)) { + !uPortTickTimeExpired(startTimeMs, ((pConnection->timeoutSeconds * 2) + + U_HTTP_CLIENT_TEST_RESPONSE_TIMEOUT_EXTRA_SECONDS) * 1000)) { uPortTaskBlock(100); } diff --git a/common/location/src/u_location_private_cloud_locate.c b/common/location/src/u_location_private_cloud_locate.c index de5093d2..099a400a 100644 --- a/common/location/src/u_location_private_cloud_locate.c +++ b/common/location/src/u_location_private_cloud_locate.c @@ -447,7 +447,7 @@ int32_t uLocationPrivateCloudLocate(uDeviceHandle_t devHandle, " location from server...\n"); while ((errorCode == (int32_t) U_ERROR_COMMON_TIMEOUT) && (((pKeepGoingCallback == NULL) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, U_LOCATION_TIMEOUT_SECONDS * 1000)) || + !uPortTickTimeExpired(startTimeMs, U_LOCATION_TIMEOUT_SECONDS * 1000)) || ((pKeepGoingCallback != NULL) && pKeepGoingCallback(devHandle)))) { if (uMqttClientGetUnread(pMqttClientContext) > 0) { z = U_LOCATION_PRIVATE_CLOUD_LOCATE_READ_MESSAGE_LENGTH_BYTES; diff --git a/common/location/test/u_location_test.c b/common/location/test/u_location_test.c index c6cbf228..027970c2 100644 --- a/common/location/test/u_location_test.c +++ b/common/location/test/u_location_test.c @@ -177,7 +177,7 @@ static bool keepGoingCallback(uDeviceHandle_t devHandle) bool keepGoing = true; U_PORT_TEST_ASSERT((gDevHandle == NULL) || (devHandle == gDevHandle)); - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -295,8 +295,8 @@ static bool httpPostCheck(uLocationType_t locationType, success = false; startTimeMs = uPortGetTickTimeMs(); while ((*pHttpStatusCode != 200) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_LOCATION_TEST_HTTP_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_LOCATION_TEST_HTTP_TIMEOUT_SECONDS * 1000)) { uPortTaskBlock(100); } if (*pHttpStatusCode != 200) { @@ -490,7 +490,7 @@ static void testOneShot(uDeviceHandle_t devHandle, " one-shot API...", timeoutMs); while ((gErrorCode == INT_MIN) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, timeoutMs)) { // Location establishment status is only supported for cell locate y = uLocationGetStatus(devHandle); if (locationType == U_LOCATION_TYPE_CLOUD_CELL_LOCATE) { @@ -622,7 +622,7 @@ static void testContinuous(uDeviceHandle_t devHandle, timeoutMs * U_LOCATION_TEST_CFG_CONTINUOUS_COUNT, U_LOCATION_TEST_CFG_CONTINUOUS_COUNT); while ((gCount < U_LOCATION_TEST_CFG_CONTINUOUS_COUNT) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, timeoutMs)) { // Location establishment status is only supported for cell locate y = uLocationGetStatus(devHandle); if (locationType == U_LOCATION_TYPE_CLOUD_CELL_LOCATE) { diff --git a/common/mqtt_client/test/u_mqtt_client_test.c b/common/mqtt_client/test/u_mqtt_client_test.c index b58ee5b5..3c4750e3 100644 --- a/common/mqtt_client/test/u_mqtt_client_test.c +++ b/common/mqtt_client/test/u_mqtt_client_test.c @@ -183,7 +183,7 @@ static bool keepGoingCallback(void) { bool keepGoing = true; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -808,8 +808,8 @@ U_PORT_TEST_FUNCTION("[mqttClient]", "mqttClientSn") U_TEST_PRINT_LINE_MQTTSN("waiting for an unread message indication..."); startTimeMs = uPortGetTickTimeMs(); while ((gNumUnread == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_MQTT_CLIENT_RESPONSE_WAIT_SECONDS * 1000)) { uPortTaskBlock(1000); } diff --git a/common/network/src/u_network_private_cell.c b/common/network/src/u_network_private_cell.c index 8dddedd1..271243e5 100644 --- a/common/network/src/u_network_private_cell.c +++ b/common/network/src/u_network_private_cell.c @@ -83,7 +83,7 @@ static bool keepGoingCallback(uDeviceHandle_t devHandle) if (uDeviceGetInstance(devHandle, &pDevInstance) == 0) { pContext = (uDeviceCellContext_t *) pDevInstance->pContext; if ((pContext == NULL) || - !U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(pContext->stopTimeMs)) { + !uPortTickTimeBeyondStop(pContext->stopTimeMs)) { keepGoing = true; } } diff --git a/common/network/src/u_network_private_wifi.c b/common/network/src/u_network_private_wifi.c index 1bf75918..19c33925 100644 --- a/common/network/src/u_network_private_wifi.c +++ b/common/network/src/u_network_private_wifi.c @@ -250,7 +250,7 @@ static inline int32_t statusQueueWaitForWifiDisabled(const uPortQueueHandle_t qu int32_t timeoutSec) { int32_t startTimeMs = uPortGetTickTimeMs(); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutSec * 1000)) { + while (!uPortTickTimeExpired(startTimeMs, timeoutSec * 1000)) { uStatusMessage_t msg; int32_t errorCode = uPortQueueTryReceive(queueHandle, 1000, &msg); if ((errorCode == (int32_t) U_ERROR_COMMON_SUCCESS) && @@ -266,7 +266,7 @@ static inline int32_t statusQueueWaitForWifiConnected(const uPortQueueHandle_t q int32_t timeoutSec) { int32_t startTimeMs = uPortGetTickTimeMs(); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutSec * 1000)) { + while (!uPortTickTimeExpired(startTimeMs, timeoutSec * 1000)) { uStatusMessage_t msg; int32_t errorCode = uPortQueueTryReceive(queueHandle, 1000, &msg); if ((errorCode == (int32_t) U_ERROR_COMMON_SUCCESS) && @@ -284,7 +284,7 @@ static inline int32_t statusQueueWaitForNetworkUp(const uPortQueueHandle_t queue U_WIFI_STATUS_MASK_IPV4_UP | U_WIFI_STATUS_MASK_IPV6_UP; uint32_t lastNetStatusMask = 0; int32_t startTimeMs = uPortGetTickTimeMs(); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutSec * 1000)) { + while (!uPortTickTimeExpired(startTimeMs, timeoutSec * 1000)) { uStatusMessage_t msg; int32_t errorCode = uPortQueueTryReceive(queueHandle, 1000, &msg); if (errorCode == (int32_t) U_ERROR_COMMON_SUCCESS) { diff --git a/common/network/test/u_network_test.c b/common/network/test/u_network_test.c index 9f44fe46..6b934d1f 100644 --- a/common/network/test/u_network_test.c +++ b/common/network/test/u_network_test.c @@ -345,7 +345,7 @@ static bool keepGoingCallback(uDeviceHandle_t devHandle) bool keepGoing = true; U_PORT_TEST_ASSERT(devHandle == gDevHandle); - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/common/security/test/u_security_test.c b/common/security/test/u_security_test.c index bbff425c..b84901da 100644 --- a/common/security/test/u_security_test.c +++ b/common/security/test/u_security_test.c @@ -107,7 +107,7 @@ static bool keepGoingCallback() { bool keepGoing = true; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/common/security/test/u_security_tls_test.c b/common/security/test/u_security_tls_test.c index bd2eed92..10aa96a3 100644 --- a/common/security/test/u_security_tls_test.c +++ b/common/security/test/u_security_tls_test.c @@ -162,7 +162,7 @@ static size_t send(uSockDescriptor_t descriptor, U_TEST_PRINT_LINE("sending %d byte(s) of data...", sizeBytes); startTimeMs = uPortGetTickTimeMs(); while ((sentSizeBytes < sizeBytes) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 10000)) { + !uPortTickTimeExpired(startTimeMs, 10000)) { x = uSockWrite(descriptor, (const void *) pData, sizeBytes - sentSizeBytes); if (x > 0) { @@ -370,7 +370,7 @@ U_PORT_TEST_FUNCTION("[securityTls]", "securityTlsSock") //lint -e{441} Suppress loop variable not found in // condition: we're using time instead for (y = 0; (offset < sizeof(gData) - 1) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 20000); y++) { + !uPortTickTimeExpired(startTimeMs, 20000); y++) { sizeBytes = uSockRead(descriptor, pDataReceived + offset, (sizeof(gData) - 1) - offset); @@ -607,7 +607,7 @@ U_PORT_TEST_FUNCTION("[securityTls]", "securityTlsUdpSock") //lint -e{441} Suppress loop variable not found in // condition: we're using time instead for (y = 0; (offset < sizeof(gData) - 1) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 20000); y++) { + !uPortTickTimeExpired(startTimeMs, 20000); y++) { sizeBytes = uSockRead(descriptor, pDataReceived + offset, (sizeof(gData) - 1) - offset); diff --git a/common/sock/src/u_sock.c b/common/sock/src/u_sock.c index aa4d6417..04f4cc35 100644 --- a/common/sock/src/u_sock.c +++ b/common/sock/src/u_sock.c @@ -1250,8 +1250,8 @@ static int32_t receive(const uSockContainer_t *pContainer, } } while ((negErrnoOrSize < 0) && (pContainer->socket.blocking) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - pContainer->socket.receiveTimeoutMs)); + !uPortTickTimeExpired(startTimeMs, + pContainer->socket.receiveTimeoutMs)); return negErrnoOrSize; } diff --git a/common/sock/test/u_sock_test.c b/common/sock/test/u_sock_test.c index e65d374e..4d71d1b2 100644 --- a/common/sock/test/u_sock_test.c +++ b/common/sock/test/u_sock_test.c @@ -678,7 +678,7 @@ static size_t sendTcp(uSockDescriptor_t descriptor, U_TEST_PRINT_LINE("sending %d byte(s) of TCP data...", sizeBytes); startTimeMs = uPortGetTickTimeMs(); while ((sentSizeBytes < sizeBytes) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 10000)) { + !uPortTickTimeExpired(startTimeMs, 10000)) { x = uSockWrite(descriptor, (const void *) pData, sizeBytes - sentSizeBytes); if (x > 0) { @@ -1245,7 +1245,7 @@ U_PORT_TEST_FUNCTION("[sock]", "sockBasicTcp") //lint -e{441} Suppress loop variable not found in // condition: we're using time instead for (y = 0; (offset < sizeof(gSendData) - 1) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 20000); y++) { + !uPortTickTimeExpired(startTimeMs, 20000); y++) { sizeBytes = uSockRead(descriptor, pDataReceived + offset + U_SOCK_TEST_GUARD_LENGTH_SIZE_BYTES, @@ -1749,7 +1749,7 @@ U_PORT_TEST_FUNCTION("[sock]", "sockLocalPort") //lint -e{441} Suppress loop variable not found in // condition: we're using time instead for (y = 0; (offset < sizeof(gSendData) - 1) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 20000); y++) { + !uPortTickTimeExpired(startTimeMs, 20000); y++) { sizeBytes = uSockRead(descriptor, pDataReceived + offset + U_SOCK_TEST_GUARD_LENGTH_SIZE_BYTES, @@ -2186,7 +2186,7 @@ U_PORT_TEST_FUNCTION("[sock]", "sockUdpEchoNonPingPong") //lint -e{441} Suppress loop variable not found in // condition: we're using time instead for (y = 0; (offset < sizeof(gSendData) - 1) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 15000); y++) { + !uPortTickTimeExpired(startTimeMs, 15000); y++) { z = uSockReceiveFrom(descriptor, NULL, pDataReceived + offset + U_SOCK_TEST_GUARD_LENGTH_SIZE_BYTES, diff --git a/example/mqtt_client/mqtt_main.c b/example/mqtt_client/mqtt_main.c index 20dbde3e..fe8af922 100644 --- a/example/mqtt_client/mqtt_main.c +++ b/example/mqtt_client/mqtt_main.c @@ -343,7 +343,7 @@ U_PORT_TEST_FUNCTION("[example]", "exampleMqttClient") // Wait for us to be notified that our new // message is available on the broker while (!messagesAvailable && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 10000)) { + !uPortTickTimeExpired(startTimeMs, 10000)) { uPortTaskBlock(1000); } diff --git a/gnss/src/u_gnss_dec_ubx_nav_pvt.c b/gnss/src/u_gnss_dec_ubx_nav_pvt.c index d500aabf..f9352086 100644 --- a/gnss/src/u_gnss_dec_ubx_nav_pvt.c +++ b/gnss/src/u_gnss_dec_ubx_nav_pvt.c @@ -31,6 +31,7 @@ #include "stddef.h" // NULL, size_t etc. #include "stdint.h" // int32_t etc. +#include "stdbool.h" #include "time.h" // mktime() #include "u_error_common.h" diff --git a/gnss/src/u_gnss_mga.c b/gnss/src/u_gnss_mga.c index 5b7b1a5b..df63578d 100644 --- a/gnss/src/u_gnss_mga.c +++ b/gnss/src/u_gnss_mga.c @@ -431,8 +431,8 @@ static int32_t ubxMgaSendWaitAck(uGnssPrivateInstance_t *pInstance, } } } while ((ackState == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - pInstance->timeoutMs)); + !uPortTickTimeExpired(startTimeMs, + pInstance->timeoutMs)); if (ackState == 2) { errorCode = (int32_t) U_ERROR_COMMON_SUCCESS; } else if (ackState == 1) { @@ -1102,8 +1102,8 @@ int32_t uGnssMgaGetDatabase(uDeviceHandle_t gnssHandle, errorCodeOrLength = (int32_t) U_ERROR_COMMON_TIMEOUT; startTimeMs = uPortGetTickTimeMs(); while (context.keepGoing && (context.errorCodeOrLength >= 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_GNSS_MGA_DATABASE_READ_TIMEOUT_MS)) { + !uPortTickTimeExpired(startTimeMs, + U_GNSS_MGA_DATABASE_READ_TIMEOUT_MS)) { uPortTaskBlock(250); } if (!context.keepGoing) { diff --git a/gnss/src/u_gnss_pos.c b/gnss/src/u_gnss_pos.c index b751ec45..eaa2d056 100644 --- a/gnss/src/u_gnss_pos.c +++ b/gnss/src/u_gnss_pos.c @@ -312,8 +312,8 @@ static void posGetTask(void *pParameter) while ((taskParameters.pInstance->posTaskFlags & U_GNSS_POS_TASK_FLAG_KEEP_GOING) && (errorCode == (int32_t) U_ERROR_COMMON_TIMEOUT) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_GNSS_POS_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_GNSS_POS_TIMEOUT_SECONDS * 1000)) { // Call posGet() to do the work errorCode = posGet(taskParameters.pInstance, &latitudeX1e7, @@ -481,8 +481,8 @@ int32_t uGnssPosGet(uDeviceHandle_t gnssHandle, errorCode = (int32_t) U_ERROR_COMMON_TIMEOUT; while ((errorCode == (int32_t) U_ERROR_COMMON_TIMEOUT) && (((pKeepGoingCallback == NULL) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_GNSS_POS_TIMEOUT_SECONDS * 1000)) || + !uPortTickTimeExpired(startTimeMs, + U_GNSS_POS_TIMEOUT_SECONDS * 1000)) || ((pKeepGoingCallback != NULL) && pKeepGoingCallback(gnssHandle)))) { // Call posGet() to do the work errorCode = posGet(pInstance, @@ -945,8 +945,8 @@ int32_t uGnssPosGetRrlp(uDeviceHandle_t gnssHandle, char *pBuffer, errorCodeOrLength = (int32_t) U_ERROR_COMMON_TIMEOUT; while ((errorCodeOrLength == (int32_t) U_ERROR_COMMON_TIMEOUT) && (((pKeepGoingCallback == NULL) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_GNSS_POS_TIMEOUT_SECONDS * 1000)) || + !uPortTickTimeExpired(startTimeMs, + U_GNSS_POS_TIMEOUT_SECONDS * 1000)) || ((pKeepGoingCallback != NULL) && pKeepGoingCallback(gnssHandle)))) { numBytes = uGnssPrivateSendReceiveUbxMessage(pInstance, diff --git a/gnss/src/u_gnss_private.c b/gnss/src/u_gnss_private.c index d00cb438..a27f4d60 100644 --- a/gnss/src/u_gnss_private.c +++ b/gnss/src/u_gnss_private.c @@ -323,7 +323,7 @@ static int32_t streamGetFromRingBuffer(uGnssPrivateInstance_t *pInstance, startTimeMs = uPortGetTickTimeMs(); errorCodeOrLength = (int32_t) U_ERROR_COMMON_TIMEOUT; while ((leftToRead > 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, maxTimeMs)) { + !uPortTickTimeExpired(startTimeMs, maxTimeMs)) { if (andRemove) { receiveSize = (int32_t) uRingBufferReadHandle(&(pInstance->ringBuffer), readHandle, @@ -2235,10 +2235,10 @@ int32_t uGnssPrivateStreamFillRingBuffer(uGnssPrivateInstance_t *pInstance, // The first condition below is the "not yet received anything case", guarded by timeoutMs // the second condition below is when we're receiving stuff, guarded by maxTimeMs (((totalReceiveSize == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) || + !uPortTickTimeExpired(startTimeMs, timeoutMs)) || ((receiveSize > 0) && ((maxTimeMs == 0) || - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - maxTimeMs))))); + !uPortTickTimeExpired(startTimeMs, + maxTimeMs))))); } } @@ -2479,7 +2479,7 @@ int32_t uGnssPrivateReceiveStreamMessage(uGnssPrivateInstance_t *pInstance, } while ((((errorCodeOrLength < 0) && (errorCodeOrLength != (int32_t) U_GNSS_ERROR_NACK) && (errorCodeOrLength != (int32_t) U_ERROR_COMMON_NO_MEMORY)) || (discardSize > 0)) && (timeoutMs > 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs) && + !uPortTickTimeExpired(startTimeMs, timeoutMs) && ((pKeepGoingCallback == NULL) || pKeepGoingCallback(pInstance->gnssHandle))); // Read pointer can be unlocked now @@ -2620,7 +2620,7 @@ int32_t uGnssPrivateSendUbxMessage(uGnssPrivateInstance_t *pInstance, (ackBody[1] != (char) messageId) && !((response.id == 0x01) || (response.id == 0x00)) && (uGnssPrivateGetStreamType(pInstance->transportType) >= 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, timeoutMs)) { response.cls = 0x05; response.id = -1; errorCode = receiveUbxMessageStream(pInstance, &response, diff --git a/gnss/src/u_gnss_util.c b/gnss/src/u_gnss_util.c index 72667aff..29f194b0 100644 --- a/gnss/src/u_gnss_util.c +++ b/gnss/src/u_gnss_util.c @@ -177,8 +177,8 @@ int32_t uGnssUtilUbxTransparentSendReceive(uDeviceHandle_t gnssHandle, // Wait for something to start coming back while ((bytesRead < (int32_t) maxResponseLengthBytes) && ((x = uGnssPrivateStreamGetReceiveSize(pInstance)) <= 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - pInstance->timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, + pInstance->timeoutMs)) { // Relax a little uPortTaskBlock(U_GNSS_UTIL_TRANSPARENT_RECEIVE_DELAY_MS); } @@ -186,8 +186,8 @@ int32_t uGnssUtilUbxTransparentSendReceive(uDeviceHandle_t gnssHandle, // Got something; continue receiving until nothing arrives or we time out while ((bytesRead < (int32_t) maxResponseLengthBytes) && ((x = uGnssPrivateStreamGetReceiveSize(pInstance)) > 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - pInstance->timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, + pInstance->timeoutMs)) { if (x > 0) { if (x > ((int32_t) maxResponseLengthBytes) - bytesRead) { x = maxResponseLengthBytes - bytesRead; diff --git a/gnss/test/u_gnss_geofence_test.c b/gnss/test/u_gnss_geofence_test.c index 8b9c7cf5..429269bb 100644 --- a/gnss/test/u_gnss_geofence_test.c +++ b/gnss/test/u_gnss_geofence_test.c @@ -202,7 +202,7 @@ static bool keepGoingCallback(uDeviceHandle_t gnssHandle) bool keepGoing = true; U_PORT_TEST_ASSERT(gnssHandle == gHandles.gnssHandle); - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/gnss/test/u_gnss_info_test.c b/gnss/test/u_gnss_info_test.c index 640581e2..3dfab435 100644 --- a/gnss/test/u_gnss_info_test.c +++ b/gnss/test/u_gnss_info_test.c @@ -295,8 +295,8 @@ U_PORT_TEST_FUNCTION("[gnssInfo]", "gnssInfoTime") U_GNSS_TIME_TEST_TIMEOUT_SECONDS); startTimeMs = uPortGetTickTimeMs(); while ((y < 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_GNSS_TIME_TEST_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_GNSS_TIME_TEST_TIMEOUT_SECONDS * 1000)) { y = uGnssInfoGetTimeUtc(gnssHandle); } if (y > 0) { diff --git a/gnss/test/u_gnss_msg_test.c b/gnss/test/u_gnss_msg_test.c index baa52c19..bee168ef 100644 --- a/gnss/test/u_gnss_msg_test.c +++ b/gnss/test/u_gnss_msg_test.c @@ -198,7 +198,7 @@ static bool keepGoingCallback(uDeviceHandle_t gnssHandle) gCallbackErrorCode = 1; } - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/gnss/test/u_gnss_pos_test.c b/gnss/test/u_gnss_pos_test.c index fecd735a..56c80506 100644 --- a/gnss/test/u_gnss_pos_test.c +++ b/gnss/test/u_gnss_pos_test.c @@ -282,7 +282,7 @@ static bool keepGoingCallback(uDeviceHandle_t gnssHandle) bool keepGoing = true; U_PORT_TEST_ASSERT(gnssHandle == gHandles.gnssHandle); - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } diff --git a/port/api/u_port.h b/port/api/u_port.h index f1d86317..99b822f2 100644 --- a/port/api/u_port.h +++ b/port/api/u_port.h @@ -90,65 +90,6 @@ extern "C" { } \ } -/** Perform a tick timeout check in a way that will behave predictably - * across a tick-counter wrap. The return value of uPortGetTickTimeMs() - * is an int32_t, which will wrap in roughly 25 days. When it does so - * it will go negative, i.e. from INT32_MAX to INT32_MIN. This macro - * performs a timeout comparison with signed modulo-32 arithmetic such - * that: - * - * - if the given time has elapsed since the start time then true is - * returned, - * - if the tick counter has wrapped then true is returned, - * - else false is returned. - * - * This way no timeout comparison will ever get "stuck" if the tick - * counter wraps underneath it; it could, of course, be shorter than - * the requested timeout, but only once every 25 days. - * - * Where you would have had: - * - * ``` - * if (uPortGetTickTimeMs() - startTimeMs > timeoutMs) { - * // Do something because the timeout has expired - * } - * ``` - * - * ...then do this instead: - * - * ``` - * if (U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) { - * // Do something because the timeout has expired - * } - * ``` - * - * If you only have a stop time, not a start time and a timeout, use - * #U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS. - */ -#define U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeInt32Ms, timeoutInt32Ms) \ - (uPortGetTickTimeMs() - (int32_t) (startTimeInt32Ms) > (int32_t) (timeoutInt32Ms)) - -/** Like #U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS but for the case where - * you have a stop time rather than a start time and a timeout. - * Where you would have had: - * - * ``` - * if (uPortGetTickTimeMs() > stopTimeMs) { - * // Do something because we are beyond the stop time - * } - * ``` - * - * ...then call this macro with the stop time instead: - * - * ``` - * if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(stopTimeMs)) { - * // Do something because we are beyond the stop time - * } - * ``` - */ -#define U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(stopTimeInt32Ms) \ - (uPortGetTickTimeMs() - (int32_t) (stopTimeInt32Ms) > 0) - /* ---------------------------------------------------------------- * TYPES * -------------------------------------------------------------- */ @@ -212,6 +153,84 @@ void uPortDeinit(); */ int32_t uPortGetTickTimeMs(); +/** Perform a tick timeout check in a way that will behave predictably + * across a tick-counter wrap. The return value of uPortGetTickTimeMs() + * is an int32_t, which will wrap in roughly 25 days. When it does so + * it will go negative, i.e. from INT32_MAX to INT32_MIN. This macro + * performs a timeout comparison with signed modulo-32 arithmetic such + * that: + * + * - if the given time has elapsed since the start time then true is + * returned, + * - if the tick counter has wrapped then true is returned, + * - else false is returned. + * + * This way no timeout comparison will ever get "stuck" if the tick + * counter wraps underneath it; it could, of course, be shorter than + * the requested timeout, but only once every 25 days. + * + * Where you would have had: + * + * ``` + * if (uPortGetTickTimeMs() - startTimeMs > timeoutMs) { + * // Do something because the timeout has expired + * } + * ``` + * + * ...then do this instead: + * + * ``` + * if (uPortTickTimeExpired(startTimeMs, timeoutMs)) { + * // Do something because the timeout has expired + * } + * ``` + * + * If you only have a stop time, rather than a start time and a timeout, + * use uPortTickTimeBeyondStop() instead. + * + * Note: this function is implemented in the common file + * u_port_tick_time.c, it is not necessary to implement it in + * each individual port layer. + * + * @param startTimeMs the start time in milliseconds, derived + * from uPortGetTickTimeMs(). + * @param timeoutMs the timeout in milliseconds. + * @return true if the current tick time has passed + * the timeout, or if the current tick time + * has wrapped. + */ +bool uPortTickTimeExpired(int32_t startTimeMs, int32_t timeoutMs); + +/** Like uPortTickTimeExpired() but for the case where + * you have a stop time rather than a start time and a timeout. + * Where you would have had: + * + * ``` + * if (uPortGetTickTimeMs() > stopTimeMs) { + * // Do something because we are beyond the stop time + * } + * ``` + * + * ...then call this macro with the stop time instead: + * + * ``` + * if (uPortTickTimeBeyondStop(stopTimeMs)) { + * // Do something because we are beyond the stop time + * } + * ``` + * + * Note: this function is implemented in the common file + * u_port_tick_time.c, it is not necessary to implement it in + * each individual port layer. + * + * @param stopTimeMs the stop time in milliseconds, derived + * from uPortGetTickTimeMs(). + * @return true if the current tick time is greater + * than stopTimeMs or the current tick time + * has wrapped. + */ +bool uPortTickTimeBeyondStop(int32_t stopTimeMs); + /** Get the heap high watermark, the minimum amount of heap * free, ever. * diff --git a/port/platform/arduino/source.txt b/port/platform/arduino/source.txt index 4965c3f8..5b2122d4 100644 --- a/port/platform/arduino/source.txt +++ b/port/platform/arduino/source.txt @@ -123,6 +123,7 @@ common/assert/src/u_assert.c common/geofence/src/u_geofence.c common/geofence/src/dummy/u_geofence_geodesic.c port/u_port_heap.c +port/u_port_tick_time.c port/u_port_resource.c port/u_port_i2c_default.c port/u_port_spi_default.c diff --git a/port/platform/cell_ucpu/r5/app/test/ucpu_uart_test.c b/port/platform/cell_ucpu/r5/app/test/ucpu_uart_test.c index bcf1a7ea..d5e69e74 100644 --- a/port/platform/cell_ucpu/r5/app/test/ucpu_uart_test.c +++ b/port/platform/cell_ucpu/r5/app/test/ucpu_uart_test.c @@ -282,7 +282,7 @@ static void mqttThread(void *thread_input) // Wait for us to be notified that our new // message is available on the broker while (!messagesAvailable && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 20000)) { + !uPortTickTimeExpired(startTimeMs, 20000)) { uPortTaskBlock(1000); } diff --git a/port/platform/cell_ucpu/r5/src/u_port_uart.c b/port/platform/cell_ucpu/r5/src/u_port_uart.c index 68a740b9..3834ef18 100644 --- a/port/platform/cell_ucpu/r5/src/u_port_uart.c +++ b/port/platform/cell_ucpu/r5/src/u_port_uart.c @@ -831,7 +831,7 @@ int32_t uPortUartEventTrySend(int32_t handle, uint32_t eventBitMap, NULL, 0); uPortTaskBlock(U_CFG_OS_YIELD_MS); } while ((errorCode != 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, delayMs)); + !uPortTickTimeExpired(startTimeMs, delayMs)); } } diff --git a/port/platform/common/mutex_debug/u_mutex_debug.c b/port/platform/common/mutex_debug/u_mutex_debug.c index 8cec26eb..0a2a3978 100644 --- a/port/platform/common/mutex_debug/u_mutex_debug.c +++ b/port/platform/common/mutex_debug/u_mutex_debug.c @@ -417,8 +417,8 @@ static void watchdogTask(void *pParam) pMutexInfo = pMutexInfo->pNext; // Don't call the callback too often though - if (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(calledMs, - U_MUTEX_DEBUG_WATCHDOG_MAX_BARK_SECONDS * 1000)) { + if (!uPortTickTimeExpired(calledMs, + U_MUTEX_DEBUG_WATCHDOG_MAX_BARK_SECONDS * 1000)) { callCallback = false; } } diff --git a/port/platform/esp-idf/src/u_port_uart.c b/port/platform/esp-idf/src/u_port_uart.c index b87841b4..d119bf38 100644 --- a/port/platform/esp-idf/src/u_port_uart.c +++ b/port/platform/esp-idf/src/u_port_uart.c @@ -672,7 +672,7 @@ int32_t uPortUartEventTrySend(int32_t handle, uint32_t eventBitMap, (void *) &event); uPortTaskBlock(U_CFG_OS_YIELD_MS); } while ((errorCode != 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, delayMs)); + !uPortTickTimeExpired(startTimeMs, delayMs)); } U_PORT_MUTEX_UNLOCK(gMutex); diff --git a/port/platform/esp-idf/test/u_espidf_ppp_test.c b/port/platform/esp-idf/test/u_espidf_ppp_test.c index ba7bc7b3..d7711824 100644 --- a/port/platform/esp-idf/test/u_espidf_ppp_test.c +++ b/port/platform/esp-idf/test/u_espidf_ppp_test.c @@ -289,7 +289,7 @@ static size_t sendTcp(int32_t sock, const char *pData, size_t sizeBytes) U_TEST_PRINT_LINE("sending %d byte(s) of TCP data...", sizeBytes); startTimeMs = uPortGetTickTimeMs(); while ((sentSizeBytes < sizeBytes) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 10000)) { + !uPortTickTimeExpired(startTimeMs, 10000)) { x = send(sock, (const void *) pData, sizeBytes - sentSizeBytes, 0); if (x > 0) { sentSizeBytes += x; diff --git a/port/platform/nrf5sdk/src/u_port_uart.c b/port/platform/nrf5sdk/src/u_port_uart.c index c082002a..428eeecc 100644 --- a/port/platform/nrf5sdk/src/u_port_uart.c +++ b/port/platform/nrf5sdk/src/u_port_uart.c @@ -988,7 +988,7 @@ int32_t uPortUartEventTrySend(int32_t handle, uint32_t eventBitMap, &event, sizeof(event)); uPortTaskBlock(U_CFG_OS_YIELD_MS); } while ((errorCode != 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, delayMs)); + !uPortTickTimeExpired(startTimeMs, delayMs)); } U_PORT_MUTEX_UNLOCK(gMutex); diff --git a/port/platform/platformio/inc_src.txt b/port/platform/platformio/inc_src.txt index c3db3fdd..b130e77c 100644 --- a/port/platform/platformio/inc_src.txt +++ b/port/platform/platformio/inc_src.txt @@ -79,6 +79,7 @@ port/platform/common/event_queue/u_port_event_queue.c port/clib/u_port_clib_mktime64.c port/u_port_timezone.c port/u_port_heap.c +port/u_port_tick_time.c port/u_port_resource.c port/u_port_i2c_default.c port/u_port_spi_default.c diff --git a/port/platform/stm32cube/src/u_port_i2c.c b/port/platform/stm32cube/src/u_port_i2c.c index 6b5e3816..58b1aba5 100644 --- a/port/platform/stm32cube/src/u_port_i2c.c +++ b/port/platform/stm32cube/src/u_port_i2c.c @@ -243,7 +243,7 @@ static bool waitFlagOk(I2C_TypeDef *pReg, uint32_t flag, bool wait; while ((wait = (U_PORT_HAL_I2C_GET_FLAG(pReg, flag) != status)) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs)) { + !uPortTickTimeExpired(startTimeMs, timeoutMs)) { } return !wait; @@ -261,7 +261,7 @@ static bool waitTransmitOk(I2C_TypeDef *pReg, uint32_t flag, bool ackFailed = false; while ((wait = (U_PORT_HAL_I2C_GET_FLAG(pReg, flag) == RESET)) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, timeoutMs) && + !uPortTickTimeExpired(startTimeMs, timeoutMs) && !ackFailed) { if (U_PORT_HAL_I2C_GET_FLAG(pReg, I2C_FLAG_AF) == SET) { // If there's been an acknowledgement failure, diff --git a/port/platform/stm32cube/src/u_port_uart.c b/port/platform/stm32cube/src/u_port_uart.c index a1a2eac8..a7368f85 100644 --- a/port/platform/stm32cube/src/u_port_uart.c +++ b/port/platform/stm32cube/src/u_port_uart.c @@ -1337,8 +1337,8 @@ int32_t uPortUartWrite(int32_t handle, // was wrong and it's not connected to the right // thing. while (!(txOk = LL_USART_IsActiveFlag_TXE(pReg)) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_PORT_UART_WRITE_TIMEOUT_MS)) {} + !uPortTickTimeExpired(startTimeMs, + U_PORT_UART_WRITE_TIMEOUT_MS)) {} if (txOk) { pDataPtr++; sizeBytes--; @@ -1347,8 +1347,8 @@ int32_t uPortUartWrite(int32_t handle, // Wait for transmission to complete so that we don't // write over stuff the next time while (!LL_USART_IsActiveFlag_TC(pReg) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_PORT_UART_WRITE_TIMEOUT_MS)) {} + !uPortTickTimeExpired(startTimeMs, + U_PORT_UART_WRITE_TIMEOUT_MS)) {} sizeOrErrorCode -= (int32_t) sizeBytes; } @@ -1543,7 +1543,7 @@ int32_t uPortUartEventTrySend(int32_t handle, uint32_t eventBitMap, &event, sizeof(event)); uPortTaskBlock(U_CFG_OS_YIELD_MS); } while ((errorCode != 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, delayMs)); + !uPortTickTimeExpired(startTimeMs, delayMs)); } U_PORT_MUTEX_UNLOCK(gMutex); diff --git a/port/platform/zephyr/src/u_port_ppp.c b/port/platform/zephyr/src/u_port_ppp.c index 6e3136a2..6a3d01e2 100644 --- a/port/platform/zephyr/src/u_port_ppp.c +++ b/port/platform/zephyr/src/u_port_ppp.c @@ -673,8 +673,8 @@ static void pppDetach(uPortPppInterface_t *pPppInterface) // will set gpPppInterface->ipConnected startTimeMs = uPortGetTickTimeMs(); while ((gpPppInterface->ipConnected) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_PORT_PPP_DISCONNECT_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_PORT_PPP_DISCONNECT_TIMEOUT_SECONDS * 1000)) { uPortTaskBlock(250); } pPppInterface->ipConnected = false; @@ -902,8 +902,8 @@ int32_t uPortPppConnect(void *pDevHandle, // will set gpPppInterface->ipConnected startTimeMs = uPortGetTickTimeMs(); while ((!gpPppInterface->ipConnected) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_PORT_PPP_CONNECT_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_PORT_PPP_CONNECT_TIMEOUT_SECONDS * 1000)) { uPortTaskBlock(250); } if (gpPppInterface->ipConnected) { diff --git a/port/platform/zephyr/src/u_port_uart.c b/port/platform/zephyr/src/u_port_uart.c index 4e6ffb8c..ecad52c9 100644 --- a/port/platform/zephyr/src/u_port_uart.c +++ b/port/platform/zephyr/src/u_port_uart.c @@ -858,7 +858,7 @@ int32_t uPortUartEventTrySend(int32_t handle, uint32_t eventBitMap, &event, sizeof(event)); uPortTaskBlock(U_CFG_OS_YIELD_MS); } while ((errorCode != 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, delayMs)); + !uPortTickTimeExpired(startTimeMs, delayMs)); } U_PORT_MUTEX_UNLOCK(gMutex); diff --git a/port/platform/zephyr/test/u_zephyr_ppp_test.c b/port/platform/zephyr/test/u_zephyr_ppp_test.c index d41cda51..2fe35bd8 100644 --- a/port/platform/zephyr/test/u_zephyr_ppp_test.c +++ b/port/platform/zephyr/test/u_zephyr_ppp_test.c @@ -290,7 +290,7 @@ static size_t sendTcp(int32_t sock, const char *pData, size_t sizeBytes) U_TEST_PRINT_LINE("sending %d byte(s) of TCP data...", sizeBytes); startTimeMs = uPortGetTickTimeMs(); while ((sentSizeBytes < sizeBytes) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 10000)) { + !uPortTickTimeExpired(startTimeMs, 10000)) { x = zsock_send(sock, (const void *) pData, sizeBytes - sentSizeBytes, 0); if (x > 0) { sentSizeBytes += x; diff --git a/port/test/u_port_test.c b/port/test/u_port_test.c index ca105096..9d16b6f5 100644 --- a/port/test/u_port_test.c +++ b/port/test/u_port_test.c @@ -3104,7 +3104,7 @@ U_PORT_TEST_FUNCTION("[port]", "portTimers") // values however their relative values should still be correct startTimeMs = uPortGetTickTimeMs(); while ((gTimerParameterValue[2] == 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 10000)) { + !uPortTickTimeExpired(startTimeMs, 10000)) { uPortTaskBlock(100); } U_PORT_TEST_ASSERT((gTimerParameterValue[2] == 1) && (gTimerParameterValue[3] == 3)); @@ -3122,7 +3122,7 @@ U_PORT_TEST_FUNCTION("[port]", "portTimers") // Wait for the periodic timer to expire one more time startTimeMs = uPortGetTickTimeMs(); while ((gTimerParameterValue[3] < 4) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 5000)) { + !uPortTickTimeExpired(startTimeMs, 5000)) { uPortTaskBlock(100); } U_PORT_TEST_ASSERT(gTimerParameterValue[3] == 4); @@ -3231,8 +3231,8 @@ U_PORT_TEST_FUNCTION("[port]", "portCriticalSection") // long time to _prove_ that the critical section has worked //lint -e{441, 550} Suppress loop variable not used in 2nd part of for() for (size_t x = 0; (gVariable == y) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_PORT_TEST_CRITICAL_SECTION_TEST_WAIT_TIME_MS); x++) { + !uPortTickTimeExpired(startTimeMs, + U_PORT_TEST_CRITICAL_SECTION_TEST_WAIT_TIME_MS); x++) { uPortTaskBlock(100); } #endif @@ -3251,8 +3251,8 @@ U_PORT_TEST_FUNCTION("[port]", "portCriticalSection") startTimeMs = uPortGetTickTimeMs(); //lint -e{441, 550} Suppress loop variable not used in 2nd part of for() for (size_t x = 0; (gVariable == y) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_PORT_TEST_CRITICAL_SECTION_TEST_WAIT_TIME_MS); x++) { + !uPortTickTimeExpired(startTimeMs, + U_PORT_TEST_CRITICAL_SECTION_TEST_WAIT_TIME_MS); x++) { uPortTaskBlock(10); } U_PORT_TEST_ASSERT(gVariable != y); diff --git a/port/u_port_tick_time.c b/port/u_port_tick_time.c new file mode 100644 index 00000000..9318cc92 --- /dev/null +++ b/port/u_port_tick_time.c @@ -0,0 +1,65 @@ +/* + * Copyright 2019-2024 u-blox + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** @file + * @brief Implemenation of common wrap-safe tick-timer expiry functions. + */ + +#ifdef U_CFG_OVERRIDE +# include "u_cfg_override.h" // For a customer's configuration override +#endif + +/* ---------------------------------------------------------------- + * INCLUDE FILES + * -------------------------------------------------------------- */ + +#include "stddef.h" // NULL, size_t etc. +#include "stdint.h" // int32_t etc. +#include "stdbool.h" + +#include "u_compiler.h" // U_INLINE + +#include "u_cfg_sw.h" +#include "u_port.h" +#include "u_port_debug.h" + +/* ---------------------------------------------------------------- + * COMPILE-TIME MACROS + * -------------------------------------------------------------- */ + +/* ---------------------------------------------------------------- + * TYPES + * -------------------------------------------------------------- */ + +/* ---------------------------------------------------------------- + * PUBLIC FUNCTIONS + * -------------------------------------------------------------- */ + +// Perform a tick time-out check, relative to start time, taking +// into account wrap. +U_INLINE bool uPortTickTimeExpired(int32_t startTimeMs, + int32_t timeoutMs) +{ + return (uPortGetTickTimeMs() - startTimeMs > timeoutMs); +} + +// Perform a tick timeout check taking into account wrap. +U_INLINE bool uPortTickTimeBeyondStop(int32_t stopTimeMs) +{ + return (uPortGetTickTimeMs() - stopTimeMs > 0); +} + +// End of file diff --git a/port/ubxlib.cmake b/port/ubxlib.cmake index 27db0693..1bd2383b 100644 --- a/port/ubxlib.cmake +++ b/port/ubxlib.cmake @@ -164,6 +164,9 @@ endif() # Default malloc()/free() implementation list(APPEND UBXLIB_SRC ${UBXLIB_BASE}/port/u_port_heap.c) +# Safe tick timeout implementations +list(APPEND UBXLIB_SRC ${UBXLIB_BASE}/port/u_port_tick_time.c) + # Default uPortGetTimezoneOffsetSeconds() implementation list(APPEND UBXLIB_SRC ${UBXLIB_BASE}/port/u_port_timezone.c) diff --git a/port/ubxlib.mk b/port/ubxlib.mk index 161fe105..d93a0539 100644 --- a/port/ubxlib.mk +++ b/port/ubxlib.mk @@ -66,6 +66,9 @@ UBXLIB_PRIVATE_INC += ${UBXLIB_BASE}/common/device/src # Default malloc()/free() implementation SRC_LIST += ${UBXLIB_BASE}/port/u_port_heap.c +# Safe tick timeout implementations +SRC_LIST += ${UBXLIB_BASE}/port/u_port_tick_time.c + # Default uPortGetTimezoneOffsetSeconds() implementation SRC_LIST += ${UBXLIB_BASE}/port/u_port_timezone.c diff --git a/wifi/src/gen2/u_wifi_sock.c b/wifi/src/gen2/u_wifi_sock.c index f04e4abc..df38334b 100644 --- a/wifi/src/gen2/u_wifi_sock.c +++ b/wifi/src/gen2/u_wifi_sock.c @@ -535,7 +535,7 @@ int32_t uWifiSockReceiveFrom(uDeviceHandle_t devHandle, } } int32_t startTimeMs = uPortGetTickTimeMs(); - while (!U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, 5000) && + while (!uPortTickTimeExpired(startTimeMs, 5000) && (dataSizeBytes > 0) && ((res = uWifiSockRead(devHandle, sockHandle, pData, dataSizeBytes)) >= 0)) { tot += res; diff --git a/wifi/src/u_wifi_loc.c b/wifi/src/u_wifi_loc.c index ffd07eae..9bc88dee 100644 --- a/wifi/src/u_wifi_loc.c +++ b/wifi/src/u_wifi_loc.c @@ -650,8 +650,8 @@ int32_t uWifiLocGet(uDeviceHandle_t wifiHandle, startTimeMs = uPortGetTickTimeMs(); while ((pContext->errorCode == (int32_t) U_ERROR_COMMON_TIMEOUT) && (((pKeepGoingCallback == NULL) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_WIFI_LOC_ANSWER_TIMEOUT_SECONDS * 1000)) || + !uPortTickTimeExpired(startTimeMs, + U_WIFI_LOC_ANSWER_TIMEOUT_SECONDS * 1000)) || ((pKeepGoingCallback != NULL) && pKeepGoingCallback(wifiHandle)))) { uPortTaskBlock(250); } diff --git a/wifi/src/u_wifi_sock.c b/wifi/src/u_wifi_sock.c index fdd9c7b7..d1ac3854 100644 --- a/wifi/src/u_wifi_sock.c +++ b/wifi/src/u_wifi_sock.c @@ -1765,8 +1765,8 @@ int32_t uWifiSockAccept(uDeviceHandle_t devHandle, *pRemoteAddress = pClientSock->remoteAddress; return pClientSock->sockHandle; } else if (gUWifiSocketAcceptTimeoutS >= 0) { - if (U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - gUWifiSocketAcceptTimeoutS * 1000)) { + if (uPortTickTimeExpired(startTimeMs, + gUWifiSocketAcceptTimeoutS * 1000)) { return U_ERROR_COMMON_TIMEOUT; } } diff --git a/wifi/test/u_wifi_captive_portal_test.c b/wifi/test/u_wifi_captive_portal_test.c index d9e571fc..9a9858b0 100644 --- a/wifi/test/u_wifi_captive_portal_test.c +++ b/wifi/test/u_wifi_captive_portal_test.c @@ -141,8 +141,8 @@ static bool keepGoingCallback(uDeviceHandle_t devHandle) U_PORT_TEST_ASSERT(devHandle == gDeviceHandle); if ((gStartTimeMs >= 0) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(gStartTimeMs, - U_WIFI_CAPTIVE_PORTAL_TEST_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(gStartTimeMs, + U_WIFI_CAPTIVE_PORTAL_TEST_TIMEOUT_SECONDS * 1000)) { keepGoing = false; } diff --git a/wifi/test/u_wifi_geofence_test.c b/wifi/test/u_wifi_geofence_test.c index 6f84c485..fadd68f8 100644 --- a/wifi/test/u_wifi_geofence_test.c +++ b/wifi/test/u_wifi_geofence_test.c @@ -164,7 +164,7 @@ static bool keepGoingCallback(uDeviceHandle_t param) (void) param; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -315,8 +315,8 @@ U_PORT_TEST_FUNCTION("[wifiGeofence]", "wifiGeofenceBasic") U_PORT_TEST_ASSERT(x == 0); U_TEST_PRINT_LINE("waiting %d second(s) for result...", U_WIFI_GEOFENCE_TEST_TIMEOUT_SECONDS); while ((gErrorCode >= 0) && (gErrorCode < 2) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_WIFI_GEOFENCE_TEST_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_WIFI_GEOFENCE_TEST_TIMEOUT_SECONDS * 1000)) { uPortTaskBlock(250); } // On really fast systems (e.g. Linux machines) it is possible diff --git a/wifi/test/u_wifi_loc_test.c b/wifi/test/u_wifi_loc_test.c index 34f59cba..a56b83e3 100644 --- a/wifi/test/u_wifi_loc_test.c +++ b/wifi/test/u_wifi_loc_test.c @@ -167,7 +167,7 @@ static bool keepGoingCallback(uDeviceHandle_t param) (void) param; - if (U_PORT_TICK_TIME_BEYOND_STOP_OR_WRAP_MS(gStopTimeMs)) { + if (uPortTickTimeBeyondStop(gStopTimeMs)) { keepGoing = false; } @@ -354,8 +354,8 @@ U_PORT_TEST_FUNCTION("[wifiLoc]", "wifiLocBasic") U_PORT_TEST_ASSERT(z == 0); U_TEST_PRINT_LINE("waiting %d second(s) for result...", U_WIFI_LOC_TEST_TIMEOUT_SECONDS); while ((gCallback == INT_MIN) && - !U_PORT_TICK_TIME_EXPIRED_OR_WRAP_MS(startTimeMs, - U_WIFI_LOC_TEST_TIMEOUT_SECONDS * 1000)) { + !uPortTickTimeExpired(startTimeMs, + U_WIFI_LOC_TEST_TIMEOUT_SECONDS * 1000)) { uPortTaskBlock(250); } if (gCallback != 0) {