Skip to content

Commit 67a7cdd

Browse files
committed
Fix rtos implementation
Signed-off-by: Cervenka Dusan <[email protected]>
1 parent c73fda4 commit 67a7cdd

File tree

6 files changed

+78
-21
lines changed

6 files changed

+78
-21
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_mbed.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,21 @@ void Semaphore::put(void)
218218
m_sem->release();
219219
}
220220

221-
bool Semaphore::get(uint32_t timeout)
221+
bool Semaphore::get(uint32_t usecs)
222222
{
223-
m_count = m_sem->wait(timeout);
223+
if (usecs != kWaitForever)
224+
{
225+
if (usecs > 0U)
226+
{
227+
usecs /= 1000U;
228+
if (usecs == 0U)
229+
{
230+
usecs = 1U;
231+
}
232+
}
233+
}
234+
235+
m_count = m_sem->wait(usecs);
224236
return (m_count < 0);
225237
}
226238

erpc_c/port/erpc_threading_threadx.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,21 @@ 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+
if (usecs != kWaitForever)
262+
{
263+
if (usecs > 0U)
264+
{
265+
usecs /= 1000U;
266+
if (usecs == 0U)
267+
{
268+
usecs = 1U;
269+
}
270+
}
271+
}
272+
273+
UINT status = tx_semaphore_get(&m_sem, usecs);
262274
return (status == TX_SUCCESS);
263275
}
264276

erpc_c/port/erpc_threading_win32.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,21 @@ 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+
if (usecs != kWaitForever)
200+
{
201+
if (usecs > 0U)
202+
{
203+
usecs /= 1000U;
204+
if (usecs == 0U)
205+
{
206+
usecs = 1U;
207+
}
208+
}
209+
}
210+
211+
DWORD ret = WaitForSingleObject(m_sem, usecs);
200212
m_mutex.lock();
201213
--m_count;
202214
m_mutex.unlock();

erpc_c/port/erpc_threading_zephyr.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,21 @@ 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+
if (usecs != kWaitForever)
136+
{
137+
if (usecs > 0U)
138+
{
139+
usecs /= 1000U;
140+
if (usecs == 0U)
141+
{
142+
usecs = 1U;
143+
}
144+
}
145+
}
146+
147+
return (k_sem_take(&m_sem, usecs) == 0);
136148
}
137149

138150
int Semaphore::getCount(void) const

0 commit comments

Comments
 (0)