📄 cf.h
字号:
//cf.h
//define cf card base address
#define CF_BASE 0x0B000000
/****************** cf card register address definition ****************/
/* (1) ATA data address */
#define DATA *((volatile unsigned short *) (CF_BASE + 0x0010))
/* (2) ATA status address */
#define ERRORREG *((volatile unsigned char *) (CF_BASE + 0x0011))
#define FEATURES *((volatile unsigned char *) (CF_BASE + 0x0011))
/* (3) ATA device sector */
#define SECTOR_COUNT *((volatile unsigned char *) (CF_BASE + 0x0012))
#define SECTOR_NUMBER *((volatile unsigned char *) (CF_BASE + 0x0013))
/* (4) ATA cylinder information */
#define CYLINDER_LOW *((volatile unsigned char *) (CF_BASE + 0x0014))
#define CYLINDER_HIGH *((volatile unsigned char *) (CF_BASE + 0x0015))
/* (5) ATA device information head */
#define DEV_HEAD *((volatile unsigned char *) (CF_BASE + 0x0016))
#define DEV_CONTROL *((volatile unsigned char *) (CF_BASE + 0x000E))
#define ATAALTSTATUS *((volatile unsigned char *) (CF_BASE + 0x000E))
/* (6) ATA status */
#define COMMAND *((volatile unsigned char *) (CF_BASE + 0x0017))
#define ATASTATUS *((volatile unsigned char *) (CF_BASE + 0x0017))
/* define operation code for setting ATA port address*/
#define READ_SECTORS 0x20 /* 0x 0010 0000 */
#define WRITE_SECTORS 0x30 /* 0x 0011 0000 */
#define READ_MULTIPLE 0xC4 /* 0x 1100 0100 */
#define WRITE_MULTIPLE 0xC5 /* 0x 1100 0101 */
#define SET_MULTIPLE 0xC6 /* 0x 1100 0110 */
#define FLUSH_CACHE 0xE7 /* 0x 1110 0111 */
#define IDENTIFY_DEVICE 0xEC /* 0x 1110 1100 */
#define SET_FEATURES 0xEF /* 0x 1110 1111 */
/* ATASTATUS toggle bit */
#define ERRBIT 0x01 /* 0x 0000 0001 */
#define DRQBIT 0x08 /* 0x 0000 1000 */
#define DRDYBIT 0x40 /* 0x 0100 0000 */
#define BSYBIT 0x80 /* 0x 1000 0000 */
/* ATA lba mode for setting DEV_HEAD */
#define LBAMODE 0x40 /* 0x 0100 0000 */
/* while{} loop times : Timeouts for waiting for device ready signals*/
#define LOOPTIME 1000000
struct PartitionTable
{
unsigned char BootId;
unsigned char PartitionType;
unsigned int PartitionFirstSector;
unsigned int PartitionSectorNum;
};
struct BPBTable
{
unsigned short BytePerSector;
unsigned char SectorPerGroup;
unsigned short SectorReserved;
unsigned char FATNum;
unsigned short DFBNum;
unsigned short SectorPerFAT;
unsigned short SectorPerHead;
unsigned short HeadNum;
unsigned int SectorHide;
unsigned int LogicTotalSector;
};
struct FileReg
{
unsigned char FileName[8];
unsigned char FileExt[3];
unsigned char Attrib;
unsigned short LastTime;
unsigned short LastDate;
unsigned short BeginGroup;
unsigned int FileLength;
};
struct FAT16LogicPartition
{
struct BPBTable bpb;
unsigned int FAT1BeginSector;
unsigned int DFTBeginSector;
unsigned int DFTSectors;
unsigned int DATABeginSector;
};
/*********************** may be changed by user *******************/
//define BeginGroup of the file to be created
#define NEWBEGINGRP 2
//define the cluster count of the file to be created
#define CLUSNUMS 625//20 frames,625 rows,1 row(360*4B) occupies 1 cluster
//define the attribute of the file
#define ATTRIB 32
//define parameters of the file to be created
#define NEWYEAR 2005
#define NEWMONTH 3
#define NEWDAY 23
#define NEWHOUR 14
#define NEWMINUTE 29
#define NEWSECOND 48 //only be even
//define the length of the file to be added
#define ADDLENGTH 360*4//1 row video data
//define global variables
unsigned char uRcvBuffer[512],uRcvBuffer1[512];//used for data transfer
extern unsigned char AddFileBuf[ADDLENGTH];//used for the content of the file to be added
unsigned short atadevinfo[256];
static unsigned short errcount = 0;
static unsigned char status = 0;
static unsigned int groupnum = 0;
static struct PartitionTable MBRTable;
extern struct FAT16LogicPartition CPartition;
//static struct FAT16LogicPartition CPartition;
static struct FileReg OperatorFile, myfile, mynewfile, myaddfile;
//unsigned int uError = 0;
unsigned char temp[512];
//unsigned int DFTSectors = 0;//the count of sector which DFT occupis
//define functions
void InitDSP();
unsigned char InitCF();
unsigned char InitMBR();
unsigned char InitCPartition();
unsigned char atadev_get_block(unsigned int lba, unsigned char sector_count, unsigned char* buffer);
unsigned char atadev_put_block(unsigned int lba, unsigned char sector_count, unsigned char* buffer);
unsigned char Check_NoRequest();
unsigned char Check_HaveRequest();
unsigned char Check_DateReady();
unsigned char NewFile();
unsigned char WriteNewDFT();
void cf_init();
unsigned char AddToFile(unsigned int *Ptr_add,unsigned int line_in_cnt);//just can add data to the new created file
unsigned char AddGroup(unsigned int dstgroup,unsigned int ClusNums);
//void cf_irq();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -