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

📄 init.c

📁 基于USB2.0芯片 ISP1581 的扫描仪固件源码,USB驱动模块
💻 C
字号:
//***********************************************************************
//									     								                  *  
//                P H I L I P S   P R O P R I E T A R Y          		   *
//                                                                      *
//          COPYRIGHT (c)   1999 BY PHILIPS SINGAPORE (APIC).    		   *
//                    --  ALL RIGHTS RESERVED  --                 		*	
//                                                                      *
// 	File Name	:       Init.c                                        *
// 	Author		:       Albert Goh					 					      *
// 	Created		:      	3 March 2000                               	*
//                  	                                                   *
//***********************************************************************
//***********************************************************************
//                                                                      *
// Init.c is the initialization of the device attached and also the D14 *
// It will initialize the various variables and component.            	*
//                                                                      *
//***********************************************************************
//***********************************************************************
//                                                                      *
//  Module History														            *
//  **************														            *
//																		                  *
//  Date   	Version			Author				Changes					      *
//  ====	=======			======				=======					         *
//  030300	  0.1 			Albert				Created    				      *     
//  290303    0.2         Sriram Paulraj     modification of Init_Main()*
//                                                                      *
//***********************************************************************

//***********************************************************************
//*																		               *
//*	                     Include Files Definition						   *
//*																		               *
//***********************************************************************

#include "standard.h"
#include "Kernel.h"
#include "D14.h"

//***********************************************************************
//*																		               *
//*	                 External Variable Definition					 	   *
//*																		               *
//***********************************************************************

extern void Start_mSEC_Timer(Data);
extern void Start_SEC_Timer(Data);
extern KERNEL Kernel_Flag;
extern USB_INT_FLAG	USB_Int_Flag;
extern USB_DEVICE USB_Device;
extern UI Temp,PIO_Count;
extern UC Device_Config_Value;
extern UC idata Endpt_FIFO[64];
extern void DMA_Init(void);
extern ULI bytecount;
extern UC Address_Count;
extern UC xdata Address[20];

//***********************************************************************
//*																		               *
//*	                 Prototype Routine Definition					 	   *
//*																		               *
//***********************************************************************

void Init_D14_SFR(void);
void Init_Endpoint(void);

void Init_Main(void);
void Init_8051(void);
void Init_D14(void);

//***********************************************************************
//*																		               *
//*	                     Variable Definition 							      *
//*																		               *
//***********************************************************************

TIMER Timer;
DATA_SWAP	idata	Data_Swap;
DMA_INT_FLAG	DMA_Int_Flag;

UI	count;
UC	Device_Config_Value;
UC 	Type;

UI	idata	Init_Count;

volatile D14_CNTRL_REG	xdata	D14_Cntrl_Reg	_at_	0x0000;

D14_CNTRL_REG xdata *D14_Cntrl_Ptr = &D14_Cntrl_Reg;


//***********************************************************************
//*										    							               *
//*	Routine 	: Init_Main                                       		   *
//*	Input		: None              									            *
//*	Output	: None                                					      *
//*	Function	: To initialize the D14 and the 8051        			      *
//*																		               *
//***********************************************************************

void Init_Main(void)
{

   //disable ISP1581 chip select
   ISP1581_CS = 1;
   bytecount = 0;
   PIO_Count = 64;

   //read in external DMA controller 
   //mode and setting
   Type = 0; // sri Oct 29, 2003
   
   switch(Type & 0x07)
   {
   
      case  1  :
      case  3  :
      case  5  :
                  USB_Device.BITS.DMA_Test_Mode = MDMA_Test;
                  break;

      case  0  :
      case  2  :
      case  4  :
            	   USB_Device.BITS.DMA_Test_Mode = GDMA_Test;
                  break;
                  
      default  :  
                  Type = 0;
	               USB_Device.BITS.DMA_Test_Mode = PIO_Test;
                  break;
   }

	//Initialize the 8051
   Init_8051();							
										
	//Enable ISP1581
   ISP1581_CS = 0;							
         
   do
   {
      //reset ISP1581                  
      ISP1581_RESET = 0;
      Start_mSEC_Timer(10);
      ISP1581_RESET = 1;
      Start_mSEC_Timer(100);
                  
      if(D14_Cntrl_Ptr->D14_CHIP_ID_MBYTE == 0x81 &&
         D14_Cntrl_Ptr->D14_CHIP_ID_MSB == 0x15)
         break;

   }while(1);

   //reset DMA controller         
	DMA_Reset = 0;			
   
   //stop DMA  controller
	// sri DMA_Start = GDMA_Stop;

   //initialize internal variables
	USB_Int_Flag.VALUE = 0;
	DMA_Int_Flag.VALUE = 0;
	Kernel_Flag.VALUE = 0;

	//Set device to default state and set
   //HS FS LED to full speed
   Kernel_Flag.BITS.HS_FS_State = FULL_SPEED;
   HS_FS_LED = HIGH_SPEED;

	//Initialize the D14
   Init_D14();				

}




//***********************************************************************
//*										    							               *
//*	Routine 	: Init 8051                                        		*
//*	Input		: 8051 Special Function Register   				            *
//*	Output	: None                                  					   *
//*	Function	: To initialize 8051                        			      *
//*																		               *
//***********************************************************************

void Init_8051(void)
{

   //set to crystal clocking
	//set to timer mode
	//select 16 bit timer
	TMOD = 0x01;

   //initialize the timer scale factor                                                      
	Timer.mSEC_Scale = 2000;
	Timer.Hundred_mSEC_Scale = 20000;

   //reset timer control
	TCON = 0;		    

   //disable all interrupt
	EA = 0;				  

   //disable UART interrupt
	//disable timer 1 overflow interrupt
	//disable external interrupt 1
	//enable timer 0 overflow interrupt
	//enable external interrupt 0
	IE = 0x02;			

   //reset interrupt priority
	IP = 0;				
	PT1 = 1;
	PT0 = 1;

   //enable all interrupt
	EA = 1;				


   //disable all power mode control
   //enable half/doble baud rate 
	PCON = 0x40;	

   RESET_IDE = 0;
}

//***********************************************************************
//*										    							               *
//*	Routine 	: Init D14                                         		*
//*	Input		: ISP1581 SFR                      				            *
//*	Output	: None                                  					   *
//*	Function	: To initialize ISP1581                     			      *
//*																		               *
//***********************************************************************

void Init_D14(void)
{
   
   //call the initialization routine of ISP1581
	Init_D14_SFR();

   //Initialize Endpoint Size
	Init_Endpoint();		

   //initialize internal varaible
	USB_Device.BITS.State = USB_Default;
	Device_Config_Value = 0;
	USB_Device.BITS.Alter_Interface = 0;
	USB_Device.BITS.Big_Endian = On;
	Kernel_Flag.BITS.Tx_Done = 0;

   DMA_Init();

   EX0 = 1;
   
}

//***********************************************************************
//*										    							               *
//*	Routine 	: Init D14 SFR                                     		*
//*	Input		: ISP1581 SFR                      				            *
//*	Output	: None                                  					   *
//*	Function	: To initialize ISP1581                     			      *
//*																		               *
//***********************************************************************

void Init_D14_SFR(void)
{

   	
	//enable Global Interrupt enable
   //enable soft connect and other feature
   //enable wakeup on chip select
   //disable soft connect
  	D14_Cntrl_Reg.D14_MODE.VALUE = 0x8E;
   
   //set all interrupt source to mode 1
   D14_Cntrl_Reg.D14_INT_CONFIG.VALUE = 0x54;			

   //set the interrupt mask register
   if(USB_Device.BITS.DMA_Test_Mode == PIO_Test)
      D14_Cntrl_Reg.D14_INT_ENABLE.VALUE = 0x79CD0000;	
   else
      D14_Cntrl_Reg.D14_INT_ENABLE.VALUE = 0x790D0000;	
   
}


//***********************************************************************
//*										    							               *
//*	Routine 	: Init Endpoint                                    		*
//*	Input		: ISP1581 FIFO                     				            *
//*	Output	: None                                  					   *
//*	Function	: To initialize ISP1581 endpoint FIFO       			      *
//*																		               *
//***********************************************************************

void Init_Endpoint(void)
{
   //check if device in full speed state
   if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
   {

	   //Bulk Out MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
	   D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	
         
		//Bulk In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	

		//Interrupt In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	


		//Interrupt In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	


		//Iso Out MaxPacketSize Endpoint
	
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
	   D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	

		//Iso In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	

		//Interrupt In Endpoint Type

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;


		//Interrupt Out Endpoint Type

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;


		//Bulk Out Endpoint Type

      D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600;


		//Bulk In Endpoint Type

      D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600;


		//Iso Out Endpoint Type
	
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;


		//Iso In Endpoint Type

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

	}

   //check if device in high speed         
	if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
	{
      
		//Bulk Out MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
	   D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	
         
		//Bulk In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	

		//Interrupt In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0002;	


		//Interrupt In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x0002;	


		//Iso Out MaxPacketSize Endpoint
	
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
	   D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	

		//Iso In MaxPacketSize Endpoint

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
      D14_Cntrl_Reg.D14_ENDPT_MAXPKTSIZE.VALUE = 0x4000;	

		//Interrupt In Endpoint Type

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;


		//Interrupt Out Endpoint Type

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1700;


		//Bulk Out Endpoint Type

      D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600;


		//Bulk In Endpoint Type

      D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1600;


		//Iso Out Endpoint Type
	
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;


		//Iso In Endpoint Type

		D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
      D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE = 0x1500;

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 2;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 3;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 6;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

      //enable FIFO
		D14_Cntrl_Reg.D14_ENDPT_INDEX = 7;
		D14_Cntrl_Reg.D14_ENDPT_TYPE.VALUE |= 0x0800;			

	}

   //set to DMA endpoint 1
   //set to Endpoint Index to 2
   //this is to prevent the endpoint index pointing to the same endpoint          
	D14_Cntrl_Reg.D14_DMA_ENDPOINT = 2;		
   D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;

   //enable device and reset the device address
	D14_Cntrl_Reg.D14_ADDRESS.VALUE = 0x80;		

}


























⌨️ 快捷键说明

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