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

📄 gm82c765.c

📁 基于dsp的软驱控制源程序
💻 C
字号:
#include "f2407_c.h"
#include "gm82c765b.h" 
#include "Delay.h"
#include "partion.h"
/**************************************************/ 
/*             8255 Registers Defines             */
#define CTL_8255 portE003 
ioport unsigned portE003; /*8255 Control Register*/
#define PA_8255 portE000
ioport unsigned portE000; /*8255 PA Data Register*/
#define PB_8255 portE001
ioport unsigned portE001; /*8255 PB Data Register*/
#define PC_8255 portE002
ioport unsigned portE002; /*8255 PC Data Register*/
/***************************************************/
/**************************************************/ 
/*             GM82C765B Registers Defines        */
#define REG_GM  portC000
ioport unsigned portC000;
#define OPRREG_GM  port8000
ioport unsigned port8000;
#define CTLREG_GM  portA000
ioport unsigned portA000; 

#define MSTREG_GM  0x0070
#define DATREG_GM  0x0073
/**************************************************/
inline int Initial8255()
{
   	CTL_8255=0x0089; /* mode 0,PA PB output, PC input */
   	PB_8255=MSTREG_GM;
}
/**************************************************/
int InitialGM() /*Enter the PC AT mode */
{
   char mstreg; 
   PB_8255=MSTREG_GM;
   mstreg=REG_GM&0xff;
   OPRREG_GM=0x0000;/*Select the Operation Register*/        
   CTLREG_GM=0x0000;/*Write the Control Register*/
   return 0;
}
/**************************************************************************/
/*int FormatATrack()
{
	char command[6]={0x4d,0x00,0x02,0x09,0x54,0x00};
	char mstreg;    
	char result[7];
	int i,j;
	MotorOn();
	if(SendCommandToGM(command,6)!=0x00)
   	{
   		MotorOff();
   		return -1; 
   	}
   	Delay4mS();
   	PB_8255=MSTREG_GM;
   	for(i=0;i<0x09;++i)                    
   	{               
   		for(j=0;j<4;++j)
   		{
   			mstreg=REG_GM&0xff;
   			if(mstreg==0xb0)
   			{
   		  		PB_8255=DATREG_GM;
   		  		REG_GM=60;
   		  		PB_8255=MSTREG_GM;
   			}
   			else
   			{ 
   				--j;
   			}
   		}	
   	}
   	if(ReadResultFromGM(result,7)==0x80)
    {
        MotorOff();
    	return -1;
    }
    MotorOff();
    return 0; 
   	
}*/ 
/**************************************************************************/
int SenseInterrupt(void)
{
	char command=0x08;
	char result[2];
	char mstreg;
    if(SendCommandToGM(&command,1)!=0x00)
   		return -1;
   	PB_8255=MSTREG_GM;
    while(1)
    {
    	mstreg=REG_GM&0xff;
    	if(!(mstreg&0x20))
    		break;
    }
    if(ReadResultFromGM(result,2)==0x80)
    	return -1;
    MotorOff();
    return 0;  
}
/**************************************************************************/
int SenseDriverStatus(void)
{
   	char command[2]={0x04,0x00};
   	char result;
   	char mstreg;
   	MotorOn();
   	if(SendCommandToGM(command,2)!=0x00)
   	{		
   		MotorOff();
   		return -1;
   	}
   	PB_8255=MSTREG_GM;
  	Delay4mS();
    if(ReadResultFromGM(&result,1)==0x80)
    {	
    	MotorOff();
    	return -1;
    }
    MotorOff();
    return result;   		
}
/**************************************************************************/
void MotorOn()
{
	OPRREG_GM=0x0035;
	Delay4mS();
} 
/**************************************************************************/
void MotorOff()
{    
	OPRREG_GM=0x0004;
	Delay4mS();
}
/**************************************************************************/
int Seek(int newcylinder)
{
	char command[3];
	command[0]=0x0f;
	command[1]=0x04;
	command[2]=newcylinder;
	MotorOn();
	if(SendCommandToGM(command,3)!=0)
	{
		MotorOff();
		return -1;
	}
	return 0;
	
}
/**************************************************************************/
int WriteData(int cylinder,int head,int sector,int numberofsector,/*Sector Parameter*/
				char *data,int datalength/*Data Buffer Parameter*/)
{
    char command[9];
   	char result[7];
   	int i, mstreg=0;
   	command[0]=0x45;
   	command[1]=0x00+head*4;
   	command[2]=cylinder;
   	command[3]=head;
   	command[4]=sector;
   	command[5]=numberofsector;
   	command[6]=0x09;
   	command[7]=0x1b;
   	command[8]=0xff;
   	MotorOn();
   	if(SendCommandToGM(command,9)!=0x00)
   	{
   		MotorOff();
   		return -1;
   	}	
   	PB_8255=MSTREG_GM;
   	for(i=0;i<datalength;++i)
   	{
   	    mstreg=REG_GM&0xff;
   		if(mstreg==0xb0)
   		{
   		  	PB_8255=DATREG_GM;
   		  	if(i%2)
   		  	{	
   		  		REG_GM=*(data+i/2);
   		  		
   		  	}
   		  	else
   		  	{
   		  		*(data+i/2)>>=8;
   		  		REG_GM=*(data+i/2);
   		  	}
   		  	PB_8255=MSTREG_GM;
   		}
   		else
   		{ 
   			--i;
   		}
   		if(mstreg==0xD0)
   			break;
   	}  
	while(1)
	{
		mstreg=REG_GM&0xff;
		if(mstreg==0xD0)
			break;
	}	
    if(ReadResultFromGM(result,7)!=0)
    {             
    	MotorOff();
    	return -1;	
    }
    MotorOff();
    return 0;
}				 
/**************************************************************************/
int ReadData(int cylinder,int head,int sector,int numberofsector,/*Sector Parameter*/
				char *data,int datalength/*Data Buffer Parameter*/)
{
    char command[9];
   	char result[7];
   	int i, mstreg=0;
   	command[0]=0xc6;
   	command[1]=0x00+head*4;
   	command[2]=cylinder;
   	command[3]=head;
   	command[4]=sector;
   	command[5]=numberofsector;
   	command[6]=0x12;
   	command[7]=0x1b;
   	command[8]=0xff;
   	MotorOn();
   	if(SendCommandToGM(command,9)!=0x00)
   	{
   		MotorOff();
   		return -1;
   	}	
   	PB_8255=MSTREG_GM;
   	for(i=0;i<datalength;++i)
   	{
   	    mstreg=REG_GM&0xff;
   		if(mstreg==0xf0)
   		{
   		  	PB_8255=DATREG_GM;
   		  	if(i%2)
   		  	{	
   		  		*(data+i/2)<<=8;
   		  		*(data+i/2)+=REG_GM&0xff;
   		  	}
   		  	else
   		  	{
   		  		*(data+i/2)=REG_GM&0xff;
   		  	}
   		  	PB_8255=MSTREG_GM;
   		}
   		else
   		{ 
   			--i;
   		}
   		if((mstreg&0xf0)==0xD0)
   			break;
   	}  
	while(1)
	{
		mstreg=REG_GM&0xff;
		if((mstreg&0xf0)==0xD0)
			break;
	}
    if(ReadResultFromGM(result,7)!=0)
    {
    	MotorOff();
    	return -1;	
    }
    MotorOff();
    return 0;
}
/************************************************/
int Specify()
{
	char command[3]={0x0003,0x00df,0x0003};
	MotorOn();
	if(SendCommandToGM(command,3)!=0)
	{
		MotorOff();
		return -1;
	} 
	MotorOff();
	return 0;
	
}
/****************************************************/
int Recalibrate()
{
	
	char command[2]={0x0007,0x0000};
	MotorOn();
	if(SendCommandToGM(command,2)!=0)
	{
		MotorOff();
		return -1;
	}
	return 0;
}
/****************************************************/
int ReadID(void)
{
  	int i;
  	char command[2]={0x4a,0x00};
  	char result[7];                                                     
  	char mstreg;
  	MotorOn();
  	if(SendCommandToGM(command,2)!=0)
   		return -1;
    PB_8255=MSTREG_GM;
    Delay4mS();
    while(1)
    {
    	mstreg=REG_GM&0xff;
    	if(!(mstreg&0x20))
    		break;
    }
    if(ReadResultFromGM(result,7)==0x80)
    	return -1;
    MotorOff();
    return 0;
}
/***************************************************/ 
int SendCommandToGM(char *command,int comlength)
{
	int i;
	char mstreg,errCause;   
   	PB_8255=MSTREG_GM;/*Select the Master Status Register*/
   	mstreg=REG_GM&0x00ff;
   	if(mstreg&0x0010)
   	{
   		 return -1;
   	}
 
   	for(i=0;i<comlength;++i)
   	{
   		PB_8255=MSTREG_GM;/*Select the Master Status Register*/
   		while(1)
   		{   		
   			mstreg=REG_GM&0x00ff; 
   			if(mstreg&0x0080)
   			{
   				if(mstreg&0x0040)
   				{
   					PB_8255=DATREG_GM;
   					errCause=REG_GM&0xff;
   					return errCause;
   				}
   				else
   				{
   					break;
   				} 
   			} 	
   		}
   		PB_8255=DATREG_GM;/*Select the Data Register*/
   		REG_GM=*(command+i);   			
   	}
   	return 0;
}
/****************************************************/
int ReadResultFromGM(char *result,int reslength)
{
	int i;
	char mstreg,errCause;   
   	for(i=0;i<reslength;++i)
   	{
   		PB_8255=MSTREG_GM;/*Select the Master Status Register*/
   		while(1)
   		{   		
    		mstreg=REG_GM&0x00ff; 
   			if(mstreg&0x0080)
   			{
   				if(mstreg&0x0040)
   				{
                    break;
   				}
   				else
   				{   
   				   	PB_8255=DATREG_GM;
   					errCause=REG_GM&0xff;
   					return errCause;
   					
   				} 
   			} 	
   		}
   		PB_8255=DATREG_GM;/*Select the Data Register*/
   		*(result+i)=REG_GM&0xff;   			
   	}
   	return 0;
}
/***********************************************************/   	 
interrupt void nothing()
{
	while(1);
}

⌨️ 快捷键说明

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