#ifndef _delay_h
#define _delay_h

/* 外部调用:
    delay_init(72);    //系统主频, 单位为MHZ, 仅对 SYSTICK_DELAY 有效
    delay_ms(1000);
*/

//#include "stm32f10x.h"
#include "sys.h"

#define SOFT_DELAY        //纯软件延时
//#define SYSTICK_DELAY    //系统定时器延时
//#define TIMER_DELAY            //定时器延时

#ifdef TIMER_DELAY

#define TIMER_DELAY                                    TIM4
#define TIMER_DELAY_PERIOD                    1000
#define TIMER_DELAY_PRESCALER                72
#define TIMER_DELAY_CLOCK                        RCC_APB1Periph_TIM4
#define TIMER_DELAY_IRQ_HANDLER            TIM4_IRQHandler

#define TIMER_DELAY_PREEMPTION_PRIORITY        2
#define TIMER_DELAY_SUB_PRIORITY                    2
#define TIMER_DELAY_IRQ_CHANNEL                        TIM4_IRQn

static __IO u16    counter_delay_ms;
#endif

#if 0
void Dly1us ( unsigned int DelayVal );
void Dly10us ( unsigned int DelayVal );
void Dly100us ( unsigned int DelayVal );

extern unsigned int SystemClockFreq;
#define DLY_PARA_COMST	(SystemClockFreq/8500000)	//延时参数
#define DLY_CALL_COMST	(6)							//调用耗时，自定义

#define delayUs(x) { unsigned int _dcnt; \
      _dcnt=(x*DLY_PARA_COMST-DLY_CALL_COMST); \
      while(_dcnt-- > 0) \
      { continue; }\
     }

#define  delay_us(us)   delayUs(us)
#define  delay_ms(ms)   delay_us(ms*1000)
#else
void delay_init ( u8 SYSCLK );
void delay_us ( u32 Number );
void delay_ms ( u16 Number );
#endif
#endif  /* end delay.h */
