#include "base/delay.h"
#include "stdbool.h"
#include "rtthread.h"




typedef struct{
  rt_tick_t tick_start;
}self_def;




static self_def g_self;

void delay_wait_start(void)
{
  g_self.tick_start=rt_tick_get();
}


void delay_wait_untill_ms(uint32_t nms)
{
  rt_tick_t tick_end;
  rt_tick_t diff;
  if(g_self.tick_start==0){
    delay_wait_start();
  }
  while(1){
    tick_end=rt_tick_get();
    diff=tick_end-g_self.tick_start;
    if(diff>=nms){
      break;
    }
    rt_thread_mdelay(1);
  }
  g_self.tick_start=0;
}


//此函数已在别处实现
//void delay_us(uint32_t nus)
//{		
//}

void delay_ms(uint32_t nms)
{	
		while(nms > 0)
		{
			nms--;
			delay_us(1000);	//普通方式延时,此时ucos无法启动调度.
		}
		
}
void delay_nop(uint32_t nop)
{
	while(nop > 0)
	{
		nop--;
		__NOP();
	}
}




































