File tree Expand file tree Collapse file tree 5 files changed +28
-19
lines changed Expand file tree Collapse file tree 5 files changed +28
-19
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ class Thread
140
140
/* !
141
141
* @brief This function puts thread to sleep.
142
142
*
143
- * @param[in] usecs Time for sleeping.
143
+ * @param[in] usecs Time for sleeping in [us] .
144
144
*/
145
145
static void sleep (uint32_t usecs);
146
146
@@ -477,12 +477,12 @@ class Semaphore
477
477
/* !
478
478
* @brief This function get semaphore.
479
479
*
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] .
481
481
*
482
482
* @retval true When semaphore got successfully.
483
483
* @retval false When mutex didn't get.
484
484
*/
485
- bool get (uint32_t timeout = kWaitForever );
485
+ bool get (uint32_t usecs = kWaitForever );
486
486
487
487
/* !
488
488
* @brief This function returns semaphore count number.
Original file line number Diff line number Diff line change @@ -264,24 +264,33 @@ void Semaphore::putFromISR(void)
264
264
portYIELD_FROM_ISR (xHigherPriorityTaskWoken);
265
265
}
266
266
267
- bool Semaphore::get (uint32_t timeout )
267
+ bool Semaphore::get (uint32_t usecs )
268
268
{
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 )
275
270
{
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
+ }
277
285
}
286
+ #if configUSE_16_BIT_TICKS
278
287
else
279
288
{
280
- /* Misra condition */
289
+ usecs = portMAX_DELAY;
281
290
}
282
291
#endif
283
292
284
- return (pdTRUE == xSemaphoreTake (m_sem, timeout ));
293
+ return (pdTRUE == xSemaphoreTake (m_sem, (TickType_t)usecs ));
285
294
}
286
295
287
296
int Semaphore::getCount (void ) const
Original file line number Diff line number Diff line change @@ -256,9 +256,9 @@ void Semaphore::put(void)
256
256
tx_semaphore_put (&m_sem);
257
257
}
258
258
259
- bool Semaphore::get (uint32_t timeout )
259
+ bool Semaphore::get (uint32_t usecs )
260
260
{
261
- UINT status = tx_semaphore_get (&m_sem, timeout );
261
+ UINT status = tx_semaphore_get (&m_sem, usecs );
262
262
return (status == TX_SUCCESS);
263
263
}
264
264
Original file line number Diff line number Diff line change @@ -194,9 +194,9 @@ void Semaphore::put(void)
194
194
m_mutex.unlock ();
195
195
}
196
196
197
- bool Semaphore::get (uint32_t timeout )
197
+ bool Semaphore::get (uint32_t usecs )
198
198
{
199
- DWORD ret = WaitForSingleObject (m_sem, timeout );
199
+ DWORD ret = WaitForSingleObject (m_sem, usecs );
200
200
m_mutex.lock ();
201
201
--m_count;
202
202
m_mutex.unlock ();
Original file line number Diff line number Diff line change @@ -130,9 +130,9 @@ void Semaphore::put(void)
130
130
k_sem_give (&m_sem);
131
131
}
132
132
133
- bool Semaphore::get (uint32_t timeout )
133
+ bool Semaphore::get (uint32_t usecs )
134
134
{
135
- return (k_sem_take (&m_sem, timeout / 1000 ) == 0 );
135
+ return (k_sem_take (&m_sem, usecs / 1000 ) == 0 );
136
136
}
137
137
138
138
int Semaphore::getCount (void ) const
You can’t perform that action at this time.
0 commit comments