4646 * 2022-10-16 Bernard add prioceiling feature in mutex
4747 * 2023-04-16 Xin-zheqi redesigen queue recv and send function return real message size
4848 * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
49+ * 2025-06-01 htl5241 fix timer overflow
50+ *
4951 */
5052
5153#include <rtthread.h>
@@ -2567,7 +2569,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
25672569{
25682570 struct rt_thread * thread ;
25692571 rt_base_t level ;
2570- rt_uint32_t tick_delta ;
2572+ rt_uint32_t tick_stamp ;
25712573 rt_err_t ret ;
25722574
25732575 /* parameter check */
@@ -2578,7 +2580,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
25782580 RT_DEBUG_SCHEDULER_AVAILABLE (timeout != 0 );
25792581
25802582 /* initialize delta tick */
2581- tick_delta = 0 ;
2583+ tick_stamp = 0 ;
25822584 /* get current thread */
25832585 thread = rt_thread_self ();
25842586
@@ -2622,7 +2624,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
26222624 if (timeout > 0 )
26232625 {
26242626 /* get the start tick of timer */
2625- tick_delta = rt_tick_get ();
2627+ tick_stamp = rt_tick_get ();
26262628
26272629 LOG_D ("mb_send_wait: start timer of thread:%s" ,
26282630 thread -> parent .name );
@@ -2650,8 +2652,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb,
26502652 /* if it's not waiting forever and then re-calculate timeout tick */
26512653 if (timeout > 0 )
26522654 {
2653- tick_delta = rt_tick_get () - tick_delta ;
2654- timeout -= tick_delta ;
2655+ timeout -= rt_tick_get_delta (tick_stamp );
26552656 if (timeout < 0 )
26562657 timeout = 0 ;
26572658 }
@@ -2846,7 +2847,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
28462847{
28472848 struct rt_thread * thread ;
28482849 rt_base_t level ;
2849- rt_uint32_t tick_delta ;
2850+ rt_uint32_t tick_stamp ;
28502851 rt_err_t ret ;
28512852
28522853 /* parameter check */
@@ -2857,7 +2858,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
28572858 RT_DEBUG_SCHEDULER_AVAILABLE (timeout != 0 );
28582859
28592860 /* initialize delta tick */
2860- tick_delta = 0 ;
2861+ tick_stamp = 0 ;
28612862 /* get current thread */
28622863 thread = rt_thread_self ();
28632864
@@ -2902,7 +2903,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
29022903 if (timeout > 0 )
29032904 {
29042905 /* get the start tick of timer */
2905- tick_delta = rt_tick_get ();
2906+ tick_stamp = rt_tick_get ();
29062907
29072908 LOG_D ("mb_recv: start timer of thread:%s" ,
29082909 thread -> parent .name );
@@ -2930,8 +2931,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo
29302931 /* if it's not waiting forever and then re-calculate timeout tick */
29312932 if (timeout > 0 )
29322933 {
2933- tick_delta = rt_tick_get () - tick_delta ;
2934- timeout -= tick_delta ;
2934+ timeout -= rt_tick_get_delta (tick_stamp );
29352935 if (timeout < 0 )
29362936 timeout = 0 ;
29372937 }
@@ -3382,7 +3382,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
33823382{
33833383 rt_base_t level ;
33843384 struct rt_mq_message * msg ;
3385- rt_uint32_t tick_delta ;
3385+ rt_uint32_t tick_stamp ;
33863386 struct rt_thread * thread ;
33873387 rt_err_t ret ;
33883388
@@ -3402,7 +3402,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
34023402 return - RT_ERROR ;
34033403
34043404 /* initialize delta tick */
3405- tick_delta = 0 ;
3405+ tick_stamp = 0 ;
34063406 /* get current thread */
34073407 thread = rt_thread_self ();
34083408
@@ -3447,7 +3447,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
34473447 if (timeout > 0 )
34483448 {
34493449 /* get the start tick of timer */
3450- tick_delta = rt_tick_get ();
3450+ tick_stamp = rt_tick_get ();
34513451
34523452 LOG_D ("mq_send_wait: start timer of thread:%s" ,
34533453 thread -> parent .name );
@@ -3475,8 +3475,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
34753475 /* if it's not waiting forever and then re-calculate timeout tick */
34763476 if (timeout > 0 )
34773477 {
3478- tick_delta = rt_tick_get () - tick_delta ;
3479- timeout -= tick_delta ;
3478+ timeout -= rt_tick_get_delta (tick_stamp );
34803479 if (timeout < 0 )
34813480 timeout = 0 ;
34823481 }
@@ -3765,7 +3764,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
37653764 struct rt_thread * thread ;
37663765 rt_base_t level ;
37673766 struct rt_mq_message * msg ;
3768- rt_uint32_t tick_delta ;
3767+ rt_uint32_t tick_stamp ;
37693768 rt_err_t ret ;
37703769 rt_size_t len ;
37713770
@@ -3781,7 +3780,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
37813780 RT_DEBUG_SCHEDULER_AVAILABLE (timeout != 0 );
37823781
37833782 /* initialize delta tick */
3784- tick_delta = 0 ;
3783+ tick_stamp = 0 ;
37853784 /* get current thread */
37863785 thread = rt_thread_self ();
37873786 RT_OBJECT_HOOK_CALL (rt_object_trytake_hook , (& (mq -> parent .parent )));
@@ -3826,7 +3825,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
38263825 if (timeout > 0 )
38273826 {
38283827 /* get the start tick of timer */
3829- tick_delta = rt_tick_get ();
3828+ tick_stamp = rt_tick_get ();
38303829
38313830 LOG_D ("set thread:%s to timer list" ,
38323831 thread -> parent .name );
@@ -3855,8 +3854,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
38553854 /* if it's not waiting forever and then re-calculate timeout tick */
38563855 if (timeout > 0 )
38573856 {
3858- tick_delta = rt_tick_get () - tick_delta ;
3859- timeout -= tick_delta ;
3857+ timeout -= rt_tick_get_delta (tick_stamp );
38603858 if (timeout < 0 )
38613859 timeout = 0 ;
38623860 }
0 commit comments