#ifndef _BSP_H
#define _BSP_H

#include "stm32f10x.h"
#include "pro_data.h"

//#define REMOTE //使用远程服务器,注释本行使用本地服务器(调试用)
//#define VERSION_STR PRO_VERSION""__DATE__"-"__TIME__""CONFIG_IDENT_STRING;//版本信息
#define	PRO_VERSION "Pro 1.1.6 "
#define	CONFIG_IDENT_STRING ""

//开关全局中断的宏
#define ENABLE_INT()	__set_PRIMASK(0)//使能全局中断
#define DISABLE_INT()	__set_PRIMASK(1)//禁止全局中断
//同步锁
#define THREAD_LOCK(x)  __set_PRIMASK(x)//开关全局中断;0使能;1禁止

//位带操作
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 

//IO口地址映射
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C 
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C 
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C 

#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808 
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08 
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008 

//IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n)//输出 
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n)
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n)
#define PAin(n)  BIT_ADDR(GPIOA_IDR_Addr,n)//输入 
#define PBin(n)  BIT_ADDR(GPIOB_IDR_Addr,n) 
#define PCin(n)  BIT_ADDR(GPIOC_IDR_Addr,n)

typedef struct//时间结构体
{
	u32 time;
	u16 date;
	u8 sec;
	u8 min;
	u8 hour;
}time_obj;

void BspInit(void);
void Idle(void);
void MemSet(BYTE *p,BYTE val,u32 length);
void MemCopy(BYTE *dst,BYTE *src,u32 length);
void PrintAddr(char *str,u8 *addr);
void PrintHex(u8 *buf,u16 len);
void CopyString(char *dststr,char *srcstr,char *str);
void GetBody(char *dststr,char *srcstr);//获取只是{xxxxxx}的字符
void BubbleSort(u8 *arr, u16 size);//冒泡排序
void NRF_CopyMac(u8 *dstMac,const u8 *srcMac);
BOOL NRF_CmpMac(const u8 *dstMac,const u8 *srcMac);
u8 cal_crc8(u8 *ptr, u8 len);
u8 GetDataLength(char *srcstr,char *str);
u8 Get_Nid(const u8 val);
u16 cal_crc16(u8 *pData, u16 sLen);
u16 GetNumber(char *srcstr,u8 start,u8 byte);//获取number
u32 GetValue(char *srcstr,char *str);
u32 Get_NetworkID(void);

extern time_obj run_time;

#endif
