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

📄 d12.c

📁 modem卡驱动程序源码 DSP+Mp3+USB+FAT12 这是我去年做的有关DSP+Mp3+USB+FAT12的所有源程序。 dsp用的是ti5416。 祝大家好运!
💻 C
字号:


#include "D12.h"
#include "general.h"
/*++

Copyright (c) 2004 GoldInfo Technology Co., Ltd.

Module Name:

        D12.c

Abstract:

        Module related to D12 chip register operate,this is D12 module

Environment:

        ccs2.0 IDE

Revision History:

        02/5/20014      Mikal   created

--*/
//*****************************************************************************













//*****************************************************************************
/*++

Routine Description:

        process The control function for read the D12 Chip ID 

Arguments:

        none

Return Value:

        none

--*/
UWord16 D12_ReadChipID(void)
{

	UWord16 i,j;

	outportb(K_D12_COMMAND, 0x0Fd);
	
	i=inportb();
	j=inportb();
	i += (j<<8);
	
	return(i);

}




//*****************************************************************************
/*++

Routine Description:

        process The control function for reading  the interrupt register 

Arguments:

        none

Return Value:

        none

--*/

UWord16 D12_ReadInterruptRegister(void)
{
	UWord16 b1;
	UWord16 j;

	outportb(K_D12_COMMAND, 0xF4);//read the interrupt register
	
	b1 = inportb();
	j = inportb();

	j <<= 8;
	j += b1;

	return j;
}






//*****************************************************************************
/*++

Routine Description:

        process The control function for Setting Address

Arguments:

        none

Return Value:

        none

--*/
void D12_SetAddressEnable(UWord16 bAddress, UWord16 bEnable)
{


	outportb(K_D12_COMMAND, 0xD0); //input the command
	
	if(bEnable)
		bAddress |= 0x80;
		
	outportb(K_D12_DATA, bAddress); //set the address
 

}




//*****************************************************************************
/*++

Routine Description:

        process D12 chip  endpoint status
Arguments:

        none

Return Value:

        none

--*/
void D12_SetEndpointEnable(UCHAR bEnable)
{


	outportb(K_D12_COMMAND, 0xD8);  //input the command
	if(bEnable)
		outportb(K_D12_DATA, 1);   //set endpoint enable
	else
		outportb(K_D12_DATA, 0);   //set endpoint disable


}



//*****************************************************************************
/*++

Routine Description:

        process The control function for mode selecting 

Arguments:

        none

Return Value:

        none

--*/

void D12_SetMode(UCHAR bConfig, UCHAR bClkDiv)
{


	outportb(K_D12_COMMAND, 0xF3);  //  set the mode 
	
	outportb(K_D12_DATA, bConfig);
	
	outportb(K_D12_DATA, bClkDiv);


}




//*****************************************************************************
/*++

Routine Description:

        process The control function for setting DMA mode

Arguments:

        none

Return Value:

        none

--*/
void D12_SetDMA(UCHAR bMode)
{

	outportb(K_D12_COMMAND, 0xFB);  //set DMA mode 
	outportb(K_D12_DATA, bMode);


}





//*****************************************************************************
/*++

Routine Description:

        process The control function for selecting the endpoint 

Arguments:

        none

Return Value:

        none

--*/

UCHAR D12_SelectEndpoint(UCHAR bEndp)
{
	UCHAR c;

	outportb(K_D12_COMMAND, bEndp); //endpoint selecting 
	c = inportb();

	return c;
}



//*****************************************************************************
/*++

Routine Description:

        process The control function for doing with the Transaction status 

Arguments:

        none

Return Value:

        none

--*/
UWord16 D12_ReadLastTransactionStatus(UWord16 bEndp)
{
	outportb(K_D12_COMMAND, 0x40 + bEndp); // do with the Transaction status
	
	return inportb();
	
}



//*****************************************************************************
/*++

Routine Description:

        process The control function for reading  endpoint status

Arguments:

        none

Return Value:

        none

--*/

UWord16 D12_ReadEndpointStatus(UCHAR bEndp)
{
	UWord16 c;

	outportb(K_D12_COMMAND, 0x80 + bEndp); // read endpoint status
	c = inportb();

	return c;
}



//*****************************************************************************
/*++

Routine Description:

        process The control function for setting endpoint status

Arguments:

        none

Return Value:

        none

--*/
void D12_SetEndpointStatus(UCHAR bEndp, UCHAR bStalled)
{


	outportb(K_D12_COMMAND, 0x40 + bEndp);//set endpoint status
	
	outportb(K_D12_DATA, bStalled);


}



//*****************************************************************************
/*++

Routine Description:

        process The control function for setting send resume 

Arguments:

        none

Return Value:

        none

--*/
void D12_SendResume(void)
{
	outportb(K_D12_COMMAND, 0xF6);// set send resume
}




//*****************************************************************************
/*++

Routine Description:

        process The control function for reading  current frame number

Arguments:

        none

Return Value:

        none

--*/
unsigned short D12_ReadCurrentFrameNumber(void)
{
	unsigned short i,j;

	outportb(K_D12_COMMAND, 0xF5); //read current frame number
	i= inportb();
	j = inportb();

	i += (j<<8);

	return i;
}



//*****************************************************************************
/*++

Routine Description:

        process The control function for reading  the endpoint data
Arguments:

        none

Return Value:

        none

--*/
UWord16 D12_ReadEndpoint(UWord16 endp, UWord16 len, UWord16 * buf)
{
	UWord16 i, j;

	outportb(K_D12_COMMAND, endp);
	if((inportb() & K_D12_FULLEMPTY) == 0) 
	{

		return 0;
	}

	outportb(K_D12_COMMAND, 0xF0); // read the buffer 
	j = inportb();               // the first byte is invalid
	j = inportb();

	if(j > len)
		j = len;

	for(i=0; i<j; i++)
		*(buf+i) = inportb();

	outportb(K_D12_COMMAND, 0xF2);


	return j;
}





//*****************************************************************************
/*++

Routine Description:

        process The control function for writting  the endpoint data 

Arguments:

        none

Return Value:

        none

--*/
UWord16 D12_WriteEndpoint(UWord16 endp, UWord16 len, UWord16 * buf)
{
	UWord16 i;



	outportb(K_D12_COMMAND, endp);
	i = inportb();

	outportb(K_D12_COMMAND, 0xF0);
	outportb(K_D12_DATA, 0);
	outportb(K_D12_DATA, len);

	for(i=0; i<len; i++)
		outportb(K_D12_DATA, *(buf+i));

	outportb(K_D12_COMMAND, 0xFA);

  

	return len;
}



//*****************************************************************************
/*++

Routine Description:

        process The control function for set the endpoint acknowledge  

Arguments:

        none

Return Value:

        none

--*/
void D12_AcknowledgeEndpoint(UCHAR endp)
{
	outportb(K_D12_COMMAND, endp);
	outportb(K_D12_COMMAND, 0xF1);
	
	if(endp == 0)
		outportb(K_D12_COMMAND, 0xF2);
}




//*****************************************************************************
/*++

Routine Description:

        process The control function for writing data to D12 chip 

Arguments:

        none

Return Value:

        none

--*/
void outportb(UWord16 ComandOrData, UWord16 Data)
{

      if(ComandOrData==1)
      {  
         DataOut=Data  ;
         outportCommd();
        
      }
        
      if(ComandOrData==0)
      {
         DataOut=Data  ;
         outportData();
         
      }  

}


//*****************************************************************************
/*++

Routine Description:

        process The control function for reading  the  data from the D12 chip

Arguments:

        none

Return Value:

        none

--*/
UWord16 inportb(void)
{
     UWord16   i;
     
     inportAsm();
     
	 i=DataIn;
	 
	 return (i) ;
}

/*******************************************************************/

⌨️ 快捷键说明

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