@@ -530,6 +530,61 @@ rt_err_t rt_thread_delay(rt_tick_t tick)
530530}
531531RTM_EXPORT (rt_thread_delay );
532532
533+ /**
534+ * This function will let current thread delay util (*tick + inc_tick).
535+ *
536+ * @param tick the tick of last wakeup.
537+ * @param inc_tick the increment tick
538+ *
539+ * @return RT_EOK
540+ */
541+ rt_err_t rt_thread_delay_util (rt_tick_t * tick , rt_tick_t inc_tick )
542+ {
543+ register rt_base_t level ;
544+ struct rt_thread * thread ;
545+
546+ /* set to current thread */
547+ thread = rt_thread_self ();
548+ RT_ASSERT (thread != RT_NULL );
549+ RT_ASSERT (rt_object_get_type ((rt_object_t )thread ) == RT_Object_Class_Thread );
550+
551+ /* disable interrupt */
552+ level = rt_hw_interrupt_disable ();
553+
554+ if (rt_tick_get () - * tick < inc_tick )
555+ {
556+ * tick = rt_tick_get () - * tick + inc_tick ;
557+
558+ /* suspend thread */
559+ rt_thread_suspend (thread );
560+
561+ /* reset the timeout of thread timer and start it */
562+ rt_timer_control (& (thread -> thread_timer ), RT_TIMER_CTRL_SET_TIME , tick );
563+ rt_timer_start (& (thread -> thread_timer ));
564+
565+ /* enable interrupt */
566+ rt_hw_interrupt_enable (level );
567+
568+ rt_schedule ();
569+
570+ /* get the wakeup tick */
571+ * tick = rt_tick_get ();
572+
573+ /* clear error number of this thread to RT_EOK */
574+ if (thread -> error == - RT_ETIMEOUT )
575+ {
576+ thread -> error = RT_EOK ;
577+ }
578+ }
579+ else
580+ {
581+ rt_hw_interrupt_enable (level );
582+ }
583+
584+ return RT_EOK ;
585+ }
586+ RTM_EXPORT (rt_thread_delay_util );
587+
533588/**
534589 * This function will let current thread delay for some milliseconds.
535590 *
0 commit comments