Skip to content

Commit 72f19a1

Browse files
committed
Fix rtos implementation
Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent c73fda4 commit 72f19a1

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

erpc_c/port/erpc_threading.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class Thread
140140
/*!
141141
* @brief This function puts thread to sleep.
142142
*
143-
* @param[in] usecs Time for sleeping.
143+
* @param[in] usecs Time for sleeping in [us].
144144
*/
145145
static void sleep(uint32_t usecs);
146146

@@ -477,12 +477,12 @@ class Semaphore
477477
/*!
478478
* @brief This function get semaphore.
479479
*
480-
* @param[in] timeout Time how long can wait for getting semaphore.
480+
* @param[in] usecs Time how long can wait for getting semaphore in [us].
481481
*
482482
* @retval true When semaphore got successfully.
483483
* @retval false When mutex didn't get.
484484
*/
485-
bool get(uint32_t timeout = kWaitForever);
485+
bool get(uint32_t usecs = kWaitForever);
486486

487487
/*!
488488
* @brief This function returns semaphore count number.

erpc_c/port/erpc_threading_freertos.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,33 @@ void Semaphore::putFromISR(void)
264264
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
265265
}
266266

267-
bool Semaphore::get(uint32_t timeout)
267+
bool Semaphore::get(uint32_t usecs)
268268
{
269-
#if configUSE_16_BIT_TICKS
270-
if (timeout == kWaitForever)
271-
{
272-
timeout = portMAX_DELAY;
273-
}
274-
else if (timeout > (portMAX_DELAY - 1))
269+
if (usecs != kWaitForever)
275270
{
276-
timeout = portMAX_DELAY - 1;
271+
if (usecs > 0U)
272+
{
273+
usecs /= 1000U * portTICK_PERIOD_MS;
274+
if (usecs == 0U)
275+
{
276+
usecs = 1U;
277+
}
278+
#if configUSE_16_BIT_TICKS
279+
else if (usecs > (portMAX_DELAY - 1))
280+
{
281+
usecs = portMAX_DELAY - 1;
282+
}
283+
#endif
284+
}
277285
}
286+
#if configUSE_16_BIT_TICKS
278287
else
279288
{
280-
/* Misra condition */
289+
usecs = portMAX_DELAY;
281290
}
282291
#endif
283292

284-
return (pdTRUE == xSemaphoreTake(m_sem, timeout));
293+
return (pdTRUE == xSemaphoreTake(m_sem, (TickType_t)usecs));
285294
}
286295

287296
int Semaphore::getCount(void) const

erpc_c/port/erpc_threading_threadx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ void Semaphore::put(void)
256256
tx_semaphore_put(&m_sem);
257257
}
258258

259-
bool Semaphore::get(uint32_t timeout)
259+
bool Semaphore::get(uint32_t usecs)
260260
{
261-
UINT status = tx_semaphore_get(&m_sem, timeout);
261+
UINT status = tx_semaphore_get(&m_sem, usecs);
262262
return (status == TX_SUCCESS);
263263
}
264264

erpc_c/port/erpc_threading_win32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ void Semaphore::put(void)
194194
m_mutex.unlock();
195195
}
196196

197-
bool Semaphore::get(uint32_t timeout)
197+
bool Semaphore::get(uint32_t usecs)
198198
{
199-
DWORD ret = WaitForSingleObject(m_sem, timeout);
199+
DWORD ret = WaitForSingleObject(m_sem, usecs);
200200
m_mutex.lock();
201201
--m_count;
202202
m_mutex.unlock();

erpc_c/port/erpc_threading_zephyr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ void Semaphore::put(void)
130130
k_sem_give(&m_sem);
131131
}
132132

133-
bool Semaphore::get(uint32_t timeout)
133+
bool Semaphore::get(uint32_t usecs)
134134
{
135-
return (k_sem_take(&m_sem, timeout / 1000) == 0);
135+
return (k_sem_take(&m_sem, usecs / 1000) == 0);
136136
}
137137

138138
int Semaphore::getCount(void) const

0 commit comments

Comments
 (0)