⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defs.h

📁 基于ARM7的直流电机的驱动,还有FLASH驱动,LCD驱动等
💻 H
字号:
/*
 *	描述:C语言类型和常量定义头文件(ARM处理器)。
 *	作者:余康华
 *  日期:2005-11-4 14:39
 *
 *	COPYRIGHT (C) 2005 HUIYUAN ELECTRONIC CORP. LTD.
 */
#ifndef __DEFS_H__
#define	__DEFS_H__

#include <stdarg.h>
#include <avt.h>
#include <avtcpu.h>

#undef NULL
#define NULL	0

#ifndef TRUE
#define	TRUE	1
#define	FALSE	0
#endif


typedef unsigned char	UCHAR;
typedef unsigned short	USHORT;
typedef unsigned int	UINT;
typedef unsigned long	ULONG;
typedef char			BOOL;

#define min(a,b)		((a) > (b) ? (b) : (a))
#define max(a,b)		((a) < (b) ? (b) : (a))
#define MKWORD(a,b)		((USHORT)(a) | ((USHORT)(b) << 8))

// Cluster number
typedef unsigned int	CLNO;
static  ULONG   speed;


struct tm {
  int tm_sec;   /* seconds after the minute, 0 to 60
                   (0 - 60 allows for the occasional leap second) */
  int tm_min;   /* minutes after the hour, 0 to 59 */
  int tm_hour;  /* hours since midnight, 0 to 23 */
  int tm_mday;  /* day of the month, 1 to 31 */
  int tm_mon;   /* months since January, 0 to 11 */
  int tm_year;  /* years since 1900 */
  int tm_wday;  /* days since Sunday, 0 to 6 */
  int tm_yday;  /* days since January 1, 0 to 365 */
  int tm_isdst; /* Daylight Savings Time flag */
};

#define	FILE_BEGIN	0
#define	FILE_CUR	1
#define FILE_END	2

#define	DRIVE_MOUNT	1

#define	MAX_FILE_SIZE	0x180000

struct _DRIVE;
typedef int	 (*CALLBACK)(struct _DRIVE *, ULONG, UCHAR *);

// 驱动器结构体
typedef struct _DRIVE {
	struct _MASS_STOR *ms;
	CALLBACK	ReadSector;
	CALLBACK	WriteSector;
	void		(*Sync)(struct _DRIVE *);
	void		(*Sync2)(struct _DRIVE *, UINT st);
	// FAT文件系统变量
	UINT		Sectors;
	CLNO		FatStart;
	CLNO		RootStart;
	CLNO		DataStart;
	USHORT		Flags;
	UINT		RootEntries;
	ULONG		Fat1;
	ULONG		Fat2;
	ULONG		FatEnd;
	UINT		ClusterSizeShift;
	UINT		ClusterSize;
	ULONG		NumClusters;
	ULONG		NumSectors;
	UINT		FatLength;
	UINT		SectorsPerCluster;
	UINT		SectorsPerClusterShift;
	UINT		BytesPerSectorShift;
	UINT		BytesPerSector;
	UINT		Ref;
	UINT		sm;
	int		Fat32;
	UINT		Connected;
	UINT		fatst;
	UINT		fatgoal;
	UCHAR		tmpbuf[512];
	UCHAR		fatbuf[512];
} DRIVE;

#define	MENU_MAIN	0
#define MENU_QUERY	1
#define MENU_REPORT	2
#define MENU_SAVE	3

#define	TRB_MAX	512

typedef struct _TRB {
	struct _TRB	*Next;
	ULONG	Number;
	UCHAR	RcvCnt;
	UCHAR	Year;
	UCHAR	Month;
	UCHAR	Day;
	UCHAR	Hour;
	UCHAR	Min;
	UCHAR	Sec;
	UCHAR	Code;
	UCHAR	SubCode;
	UCHAR	Saved;
} TRB;

#define ZC	(const char *)1
#define PX	(const char *)2
#define BH	(const char *)3
#define ZD	(const char *)4
#define DZG	(const char *)5
#define FZ	(const char *)6
#define QY	(const char *)7
#define SB	(const char *)8
#define GK	(const char *)9

// LCD 显示数据
typedef struct _LCD_TRBS {
	UINT	JC[17];
	UCHAR	ZouChe;
	UCHAR	FuZhu;
	UCHAR	QianYin;
	UCHAR	PiXian;
	UCHAR	BaoHu;
	UCHAR	DianZiGui;
	UCHAR	GongKuang;	// 25 I, 26 II
	UCHAR	ShouBing;	// 16 *-10, 17 7-10, 41 0
	UCHAR	QianHou;	// 18 前, 19 后
	UCHAR	ZhiQian;	// 20 制, 21 牵
} LCD_TRBS;

#define	KEY_ENTER	2
#define	KEY_ESC		64
#define KEY_PG		16
#define KEY_UP		8
#define KEY_DOWN	1
#define KEY_LEFT	32
#define KEY_RIGHT	4

extern DRIVE	UsbDsk;
extern DRIVE	NfDsk;

extern UCHAR	CurMenu;
extern LCD_TRBS	LcdTrbs;

extern struct tm	theTime;

ULONG	GetTm(void);
void	getTm(char *str, ULONG tm);

ULONG	FileTime(int fd);
ULONG	GetFileTime(DRIVE *drv, const char *fn);
int		FindFile(DRIVE *drv, const char *fn);
int		DeleteFile(DRIVE *drv, const char *fn);
int		CreateFile(DRIVE *drv, const char *fn, ULONG sz);
UINT	FileLength(int fd);
int		OpenFile(DRIVE *drv, const char *fn);
void	CloseFile(int fd);
ULONG	ReadFile(int fd, void *buf, ULONG sz);
ULONG	WriteFile(int fd, void *buf, ULONG sz);
ULONG	SeekFile(int fd, long offst, int orig);
ULONG	FileTell(int fd);
int		FatFormat(DRIVE *drv);
int		FatUnmount(DRIVE *d);
int		FatMount(DRIVE *d, const char *);
void	*kmalloc(UINT sz);
void	kfree(void *ptr);
char	*strcpy(char *, const char *);
int		memcmp(const void *, const void *, unsigned int);
void	*memset(void *, int, unsigned int);
void	*memcpy(void *, const void *, unsigned int);
void	GetTime(struct tm *);
void	SetTime(struct tm *);
void	UsbSync(void);
void	NfSync(void);
ULONG	mktime(USHORT, USHORT, USHORT, USHORT, USHORT, USHORT);

void	Lcd_Clr(void);
void	Lcd_FillRect(UINT X0, UINT Y0,UINT w , UINT h, UCHAR color);
void	Lcd_NotRect(UINT X0, UINT Y0,UINT w , UINT h);
void	Lcd_Clrxy(UINT X0, UINT Y0,UINT X , UINT Y,UCHAR color);
void	SetPixel(UINT x, UINT y, UCHAR cr);
int		GetPixel(UINT x, UINT y);
void	DrawHorzLine(UINT x1, UINT x2, UINT y, UCHAR c);
void	DrawVertLine(UINT x, UINT y1, UINT y2, UCHAR c);
void	DrawLine(UINT x1, UINT y1, UINT x2, UINT y2, UCHAR color);
void	FillRect(UINT x1, UINT y1, UINT x2, UINT y2, UCHAR c);
void	DrawRect(UINT x1, UINT y1, UINT x2, UINT y2, UCHAR c);
void	DrawBitmap(UINT x, UINT y, UCHAR *bmp);
void	drawbmp(UINT x, UINT y, UCHAR *bmp, UINT sz);
UCHAR	*gunzip(void *pData, ULONG len, ULONG *outlen);
void	ShowLedDigit(UINT x, UINT y, UINT n);
void	ShowLedNumber(UINT x, UINT y, UINT val, UINT w);
void	OutHz(UINT x, UINT y, const char *hz);
void	OutAscii(UINT x, UINT y, char ch);
void	OutString(UINT x, UINT y, const char *str);
void	OutString2(UINT x, UINT y, const char *str);
void	getTm(char *str, ULONG tm);
int		SetTextColor(int);
int		SetBgColor(int);
int		mysprintf(char *, const char *, ...);
int		myvsprintf(char *, const char *, va_list);
void	IntConnect(UINT iva, UINT isa);
void	DbgOut(const char *fmt, ...);
void	__assert(const char *f, int l, const char *expr);
void	bsp_puts(const char *);
int		ReadByte(void);
void	internal_fatal(const char *msg);
void	LockDrive(DRIVE *d);
void	UnlockDrive(DRIVE *d);
void	clrwtd(void);

void	NfReadFile(int fd, ULONG pos, void *buf, UINT sz);
void	NfWriteFile(void *buf, UINT sz);
UINT	NfGetFileTime(int fd);

#if 0
#define DBG	 DbgOut
#define DBG1 DbgOut
#define DBG2 DbgOut
#define DBG3 DbgOut
#define DBG4 DbgOut
#define DBG5 DbgOut
void	*Memset(void *ptr, int c, int sz);
void	*Memcpy(void *dest, const void *src, int sz);
#else

#define DBG(x)
#define DBG1(a,b)
#define DBG2(a,b,c)
#define DBG3(a,b,c,d)
//#define ASSERT(p)  	((void)0)
//#define CHECK_PTR(p) ((void)0)
#define Memset	memset
#define Memcpy	memcpy
#endif

#endif /* __DEFS_H__ */
/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -