diff --git a/erpc_c/port/erpc_setup_extensions_freertos.cpp b/erpc_c/port/erpc_setup_extensions_freertos.cpp index b93e4a29e..acdc7674c 100644 --- a/erpc_c/port/erpc_setup_extensions_freertos.cpp +++ b/erpc_c/port/erpc_setup_extensions_freertos.cpp @@ -28,7 +28,7 @@ void erpc::erpc_pre_cb_default(void) (void)s_erpc_call_in_progress->get(s_erpc_call_in_progress->kWaitForever); erpc_assert(s_erpc_call_timer_cb && "If you want use default pre cb action, do not forget call erpc_init_call_progress_detection_default."); - xTimerStart(s_erpc_call_timer_cb, 0); + (void)xTimerStart(s_erpc_call_timer_cb, 0); } void erpc::erpc_post_cb_default(void) diff --git a/erpc_c/port/erpc_threading.h b/erpc_c/port/erpc_threading.h index 1ebe8a240..1f3d66ad3 100644 --- a/erpc_c/port/erpc_threading.h +++ b/erpc_c/port/erpc_threading.h @@ -140,7 +140,7 @@ class Thread /*! * @brief This function puts thread to sleep. * - * @param[in] usecs Time for sleeping. + * @param[in] usecs Time for sleeping in [us]. */ static void sleep(uint32_t usecs); @@ -477,12 +477,12 @@ class Semaphore /*! * @brief This function get semaphore. * - * @param[in] timeout Time how long can wait for getting semaphore. + * @param[in] timeoutUsecs Time how long can wait for getting semaphore in [us]. * * @retval true When semaphore got successfully. * @retval false When mutex didn't get. */ - bool get(uint32_t timeout = kWaitForever); + bool get(uint32_t timeoutUsecs = kWaitForever); /*! * @brief This function returns semaphore count number. diff --git a/erpc_c/port/erpc_threading_freertos.cpp b/erpc_c/port/erpc_threading_freertos.cpp index 42affe272..c99c99779 100644 --- a/erpc_c/port/erpc_threading_freertos.cpp +++ b/erpc_c/port/erpc_threading_freertos.cpp @@ -264,23 +264,33 @@ void Semaphore::putFromISR(void) portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } -bool Semaphore::get(uint32_t timeout) +bool Semaphore::get(uint32_t timeoutUsecs) { -#if configUSE_16_BIT_TICKS - if (timeout == kWaitForever) + if (timeoutUsecs != kWaitForever) { - timeout = portMAX_DELAY; + if (timeoutUsecs > 0U) + { + timeoutUsecs /= 1000U * portTICK_PERIOD_MS; + if (timeoutUsecs == 0U) + { + timeoutUsecs = 1U; + } +#if configUSE_16_BIT_TICKS + else if (timeoutUsecs > (portMAX_DELAY - 1)) + { + timeoutUsecs = portMAX_DELAY - 1; + } +#endif + } } +#if configUSE_16_BIT_TICKS else { - if (timeout > (portMAX_DELAY - 1)) - { - timeout = portMAX_DELAY - 1; - } + timeoutUsecs = portMAX_DELAY; } #endif - return (pdTRUE == xSemaphoreTake(m_sem, timeout / 1000U / portTICK_PERIOD_MS)); + return (pdTRUE == xSemaphoreTake(m_sem, (TickType_t)timeoutUsecs)); } int Semaphore::getCount(void) const diff --git a/erpc_c/port/erpc_threading_mbed.cpp b/erpc_c/port/erpc_threading_mbed.cpp index c93832183..00441b361 100644 --- a/erpc_c/port/erpc_threading_mbed.cpp +++ b/erpc_c/port/erpc_threading_mbed.cpp @@ -218,9 +218,21 @@ void Semaphore::put(void) m_sem->release(); } -bool Semaphore::get(uint32_t timeout) +bool Semaphore::get(uint32_t timeoutUsecs) { - m_count = m_sem->wait(timeout); + if (timeoutUsecs != kWaitForever) + { + if (timeoutUsecs > 0U) + { + timeoutUsecs /= 1000U; + if (timeoutUsecs == 0U) + { + timeoutUsecs = 1U; + } + } + } + + m_count = m_sem->wait(timeoutUsecs); return (m_count < 0); } diff --git a/erpc_c/port/erpc_threading_pthreads.cpp b/erpc_c/port/erpc_threading_pthreads.cpp index 2c5611662..18ba49d38 100644 --- a/erpc_c/port/erpc_threading_pthreads.cpp +++ b/erpc_c/port/erpc_threading_pthreads.cpp @@ -185,7 +185,7 @@ void Semaphore::put(void) ++m_count; } -bool Semaphore::get(uint32_t timeout) +bool Semaphore::get(uint32_t timeoutUsecs) { Mutex::Guard guard(m_mutex); bool retVal = true; @@ -193,7 +193,7 @@ bool Semaphore::get(uint32_t timeout) while (m_count == 0) { - if (timeout == kWaitForever) + if (timeoutUsecs == kWaitForever) { err = pthread_cond_wait(&m_cond, m_mutex.getPtr()); if (err != 0) @@ -204,14 +204,14 @@ bool Semaphore::get(uint32_t timeout) } else { - if (timeout > 0U) + if (timeoutUsecs > 0U) { // Create an absolute timeout time. struct timeval tv; gettimeofday(&tv, NULL); struct timespec wait; - wait.tv_sec = tv.tv_sec + (timeout / sToUs); - wait.tv_nsec = (timeout % sToUs) * 1000U; + wait.tv_sec = tv.tv_sec + (timeoutUsecs / sToUs); + wait.tv_nsec = (timeoutUsecs % sToUs) * 1000U; err = pthread_cond_timedwait(&m_cond, m_mutex.getPtr(), &wait); if (err != 0) { diff --git a/erpc_c/port/erpc_threading_threadx.cpp b/erpc_c/port/erpc_threading_threadx.cpp index d36c0ac93..4599800af 100644 --- a/erpc_c/port/erpc_threading_threadx.cpp +++ b/erpc_c/port/erpc_threading_threadx.cpp @@ -256,9 +256,21 @@ void Semaphore::put(void) tx_semaphore_put(&m_sem); } -bool Semaphore::get(uint32_t timeout) +bool Semaphore::get(uint32_t timeoutUsecs) { - UINT status = tx_semaphore_get(&m_sem, timeout); + if (timeoutUsecs != kWaitForever) + { + if (timeoutUsecs > 0U) + { + timeoutUsecs /= 1000U; + if (timeoutUsecs == 0U) + { + timeoutUsecs = 1U; + } + } + } + + UINT status = tx_semaphore_get(&m_sem, timeoutUsecs); return (status == TX_SUCCESS); } diff --git a/erpc_c/port/erpc_threading_win32.cpp b/erpc_c/port/erpc_threading_win32.cpp index a8665c6cc..459c5b0aa 100644 --- a/erpc_c/port/erpc_threading_win32.cpp +++ b/erpc_c/port/erpc_threading_win32.cpp @@ -194,9 +194,21 @@ void Semaphore::put(void) m_mutex.unlock(); } -bool Semaphore::get(uint32_t timeout) +bool Semaphore::get(uint32_t timeoutUsecs) { - DWORD ret = WaitForSingleObject(m_sem, timeout); + if (timeoutUsecs != kWaitForever) + { + if (timeoutUsecs > 0U) + { + timeoutUsecs /= 1000U; + if (timeoutUsecs == 0U) + { + timeoutUsecs = 1U; + } + } + } + + DWORD ret = WaitForSingleObject(m_sem, timeoutUsecs); m_mutex.lock(); --m_count; m_mutex.unlock(); diff --git a/erpc_c/port/erpc_threading_zephyr.cpp b/erpc_c/port/erpc_threading_zephyr.cpp index 4c475165a..b18c65bf3 100644 --- a/erpc_c/port/erpc_threading_zephyr.cpp +++ b/erpc_c/port/erpc_threading_zephyr.cpp @@ -130,9 +130,21 @@ void Semaphore::put(void) k_sem_give(&m_sem); } -bool Semaphore::get(uint32_t timeout) +bool Semaphore::get(uint32_t timeoutUsecs) { - return (k_sem_take(&m_sem, timeout / 1000) == 0); + if (timeoutUsecs != kWaitForever) + { + if (timeoutUsecs > 0U) + { + timeoutUsecs /= 1000U; + if (timeoutUsecs == 0U) + { + timeoutUsecs = 1U; + } + } + } + + return (k_sem_take(&m_sem, timeoutUsecs) == 0); } int Semaphore::getCount(void) const