bool UartDev::getChar(char* pInputChar, unsigned int timeout) { if (!pInputChar || !mRxQueue) { return false; } else if (taskSCHEDULER_RUNNING == xTaskGetSchedulerState()) { return xQueueReceive(mRxQueue, pInputChar, timeout); } else { unsigned int timeout_of_char = sys_get_uptime_ms() + timeout; while (! xQueueReceive(mRxQueue, pInputChar, 0)) { if (sys_get_uptime_ms() > timeout_of_char) { return false; } } } return true; }
/// Retrieves a packet from the queue handle with the given timeout. static char wireless_get_queued_pkt(QueueHandle_t qhandle, mesh_packet_t *pkt, const uint32_t timeout_ms) { char ok = 0; if (taskSCHEDULER_RUNNING == xTaskGetSchedulerState()) { ok = xQueueReceive(qhandle, pkt, OS_MS(timeout_ms)); } else { uint64_t timeout_of_char = sys_get_uptime_ms() + timeout_ms; while (! (ok = xQueueReceive(qhandle, pkt, 0))) { if (sys_get_uptime_ms() > timeout_of_char) { break; } } } return ok; }
bool CAN_rx (can_t can, can_msg_t *pCanMsg, uint32_t timeout_ms) { bool ok = false; if (CAN_VALID(can) && pCanMsg) { if (taskSCHEDULER_RUNNING == xTaskGetSchedulerState()) { ok = xQueueReceive(CAN_STRUCT_PTR(can)->rxQ, pCanMsg, OS_MS(timeout_ms)); } else { uint64_t msg_timeout = sys_get_uptime_ms() + timeout_ms; while (! (ok = xQueueReceive(CAN_STRUCT_PTR(can)->rxQ, pCanMsg, 0))) { if (sys_get_uptime_ms() > msg_timeout) { break; } } } } return ok; }
bool CAN_rx (can_t can, can_msg_t *pCanMsg, uint32_t timeout_ms) { bool ok = false; if (CAN_VALID(can) && pCanMsg) { if (taskSCHEDULER_RUNNING == xTaskGetSchedulerState()) { ok = xQueueReceive(g_can_rx_qs[CAN_INDEX(can)], pCanMsg, OS_MS(timeout_ms)); } else { uint64_t msg_timeout = sys_get_uptime_ms() + timeout_ms; while (! (ok = xQueueReceiveFromISR(g_can_rx_qs[CAN_INDEX(can)], pCanMsg, NULL))) { if (sys_get_uptime_ms() > msg_timeout) { break; } } } } return ok; }
static int nrf_driver_get_timer(void *p, int len) { const int ok = (sizeof(uint32_t) == len) && (NULL != p); const uint32_t timerValueMs = (sys_get_uptime_ms() & UINT32_MAX); if (ok) { uint32_t *timer = (uint32_t*)p; *timer = timerValueMs; } return ok; }
bool I2C_Base::transfer(char deviceAddress, char firstReg, char* pData, unsigned int transferSize) { bool status = false; if(mDisableOperation || !pData) { return status; } // If scheduler not running, perform polling transaction if(taskSCHEDULER_RUNNING != xTaskGetSchedulerState()) { i2cKickOffTransfer(deviceAddress, firstReg, pData, transferSize); // Wait for transfer to finish const uint64_t timeout = sys_get_uptime_ms() + I2C_TIMEOUT_MS; while (!xSemaphoreTakeFromISR(mTransferCompleteSignal, NULL)) { if (sys_get_uptime_ms() > timeout) { break; } } status = (0 == mTransaction.error); } else if (xSemaphoreTake(mI2CMutex, OS_MS(I2C_TIMEOUT_MS))) { // Clear potential stale signal and start the transfer xSemaphoreTake(mTransferCompleteSignal, 0); i2cKickOffTransfer(deviceAddress, firstReg, pData, transferSize); // Wait for transfer to finish and copy the data if it was read mode if (xSemaphoreTake(mTransferCompleteSignal, OS_MS(I2C_TIMEOUT_MS))) { status = (0 == mTransaction.error); } xSemaphoreGive(mI2CMutex); } return status; }
/* If FreeRTOS is not running, then we rely on rit service to call this function, * otherwise we rely on FreeRTOS tick hook to provide system timer */ static void hl_periodic_service(void) { const uint32_t timer_ms = sys_get_uptime_ms(); /* If FreeRTOS is running, user should use a dedicated task to call mesh service, * so we will not call it if freertos is running */ if (taskSCHEDULER_RUNNING == xTaskGetSchedulerState()) { m_system_uptime_ms += MS_PER_TICK(); /* We don't need RIT if FreeRTOS is running */ if (sys_rit_running()) { sys_rit_disable(); /* Round up uptime_ms because if ms per tick is 10, then we don't want to * increment this timer by 10 from an odd number because % 10 won't work. */ m_system_uptime_ms = (m_system_uptime_ms / 10) * 10; } } else { m_system_uptime_ms += m_time_per_rit_isr_ms; wireless_service(); /** * Small hack to support interrupts if FreeRTOS is not running : * FreeRTOS API resets our base priority register, then all * interrupts higher priority than IP_SYSCALL will not get locked out. * @see more notes at isr_priorities.h. @see IP_SYSCALL */ __set_BASEPRI(0); } /** * Call SD timer function at 100Hz. * Feed the watchdog too while we're at it. */ if (0 == (timer_ms % 10)) { sd_timerproc(); sys_watchdog_feed(); } }
unsigned int FileLogger::getTimestamp(void) { return sys_get_uptime_ms(); }
/// Resets the timer from this point of time using the previous timeout interval inline void reset(void) { mTargetMs = sys_get_uptime_ms() + mIntervalMs; }
/** * Resets the timer from this point of time. * @param ms The milliseconds at which timer should expire next. */ inline void reset(uint64_t ms) { mIntervalMs = ms; mTargetMs = sys_get_uptime_ms() + ms; }
/// @returns true if the timer has expired inline bool expired(void) { return (0 == mIntervalMs) ? false : ( sys_get_uptime_ms() >= mTargetMs); }
/** * Static function to get the timer value. * This is the only method that is needed by the system. * * @note You can use this method without instantiating an object of the class: * @code * uint64_t timer = SoftTimer::getCurrentTimeMs(); * @endcode * * @returns the current timer value of the system */ static inline uint64_t getCurrentTimeMs(void) { return sys_get_uptime_ms(); }
FRESULT Storage::copy(const char* pExistingFile, const char* pNewFile, unsigned int* pReadTime, unsigned int* pWriteTime, unsigned int* pBytesTransferred) { FRESULT status; FIL srcFile; FIL dstFile; unsigned int readTimeMs = 0; unsigned int writeTimeMs = 0; // Open Existing file if (FR_OK != (status = f_open(&srcFile, pExistingFile, FA_OPEN_EXISTING | FA_READ))) { return status; } // Open new file - overwrite if one exists if (FR_OK != (status = f_open(&dstFile, pNewFile, FA_CREATE_ALWAYS | FA_WRITE))) { f_close(&srcFile); return status; } /* Buffer should be at least he size of the sector */ char buffer[_MAX_SS]; unsigned int bytesRead = 0; unsigned int bytesWritten = 0; unsigned int totalBytesTransferred = 0; for (;;) { unsigned int startTime = sys_get_uptime_ms(); if(FR_OK != (status = f_read(&srcFile, buffer, sizeof(buffer), &bytesRead)) || 0 == bytesRead) { break; } readTimeMs += sys_get_uptime_ms() - startTime; startTime = sys_get_uptime_ms(); if(FR_OK != (status = f_write(&dstFile, buffer, bytesRead, &bytesWritten)) || bytesWritten != bytesRead) { break; } writeTimeMs += sys_get_uptime_ms() - startTime; totalBytesTransferred += bytesRead; } if(0 != pReadTime) { *pReadTime = readTimeMs; } if(0 != pWriteTime) { *pWriteTime = writeTimeMs; } if(0 != pBytesTransferred) { *pBytesTransferred = totalBytesTransferred; } f_close(&srcFile); f_close(&dstFile); return status; }