|
|
发表于 2014-5-24 20:43:39
|
显示全部楼层
可以在 https://code.google.com/p/arduino/downloads/list 下载到code
\hardware\arduino\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\SERVICES\DELAY\delay.c
有下面的定义
void delay_ms(unsigned long delay)
{
#if (defined FREERTOS_USED)
vTaskDelay( (portTickType)TASK_DELAY_MS(delay) );
#elif (defined NUTOS_USED)
NutSleep(delay);
#else
cpu_delay_ms(delay, s_fcpu_hz);
#endif
}
在\hardware\arduino\firmwares\wifishield\wifiHD\src\SOFTWARE_FRAMEWORK\DRIVERS\CPU\CYCLE_COUNTER\cycle_counter.h 有下面的代码
#if (defined __GNUC__)
__attribute__((__always_inline__))
#endif
extern __inline__ void cpu_delay_ms(unsigned long delay, unsigned long fcpu_hz)
{
t_cpu_time timer;
cpu_set_timeout( cpu_ms_2_cy(delay, fcpu_hz), &timer);
while( !cpu_is_timeout(&timer) );
}
同样的文件中 有如下定义
//! Structure holding private information, automatically initialized by the
//! cpu_set_timeout() function.
typedef struct
{
//! The cycle count at the begining of the timeout.
unsigned long delay_start_cycle;
//! The cycle count at the end of the timeout.
unsigned long delay_end_cycle;
//! Enable/disable the timout detection
unsigned char timer_state;
#define CPU_TIMER_STATE_STARTED 0
#define CPU_TIMER_STATE_REACHED 1
#define CPU_TIMER_STATE_STOPPED 2
} t_cpu_time;
但是不熟悉 avr 这个代码就看不懂了,建议你自己下载研究一下哈 |
|