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

📄 vikingiiusim.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
字号:
//---------------------------------------------------------------------
// NAME        : USIM_Initialization_Test
//
// DESCRIPTION : Initialization of USIM registers
//
// PARAMETERS  : None
//
// RETURN VALUE: None
//
// LIMITATIONS : None
//---------------------------------------------------------------------
#include "vikingII.h"
#include "UART_IrDA.h"

void VIKING_USIM_Initialization_Test(void)
{	
	int i;
	int temp;

	VIKING_USIM_USIMCMD_REG|= 0x1;    //software reset of the USIM module
	for(i=0;i<1000;i++);
	VIKING_USIM_USIMCMD_REG |= 0x1;    //software reset of the USIM module
	for(i=0;i<1000;i++);
	while(1)
	{	
		temp = VIKING_USIM_USIMCMD_REG;
		if((temp & 0x1)==0)
		break;
	}
	     //wait for reset over
	VIKING_USIM_USIMCONF1_REG = 0x0;       //reset usimconf
	VIKING_USIM_USIMCONF2_REG = 0x0;       //reset usimconf
	VIKING_USIM_FIFOS_REG |= 0x1E0e;     //fifo triger= 3, enable fifo
	VIKING_USIM_FIFOS_REG |= 0x040;     // reset tx fifo
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x040);     //release tx fifo
	VIKING_USIM_FIFOS_REG |= 0x2000;       //0x1000;  reset rx fifo
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x2000);          //~(0x1000); release rx fifo
	VIKING_USIM_USIMCONF2_REG |= 0x0014;        //receive mode 13M/4, bypass synchronous and asynchronous card ATR;
	VIKING_USIM_CONF3_REG |= 0x0010;        //TDUSIM = (coefficient +1)*8*Tetu
	VIKING_USIM_USIMCMD_REG |= 0x0008;          //module clock activated;
	VIKING_USIM_CONF5_REG = 0x0101;
	VIKING_USIM_CONF3_REG = 0x40;
}

//---------------------------------------------------------------------
// NAME        : USIM_TestRegistersAccess
//
// DESCRIPTION : Test the access to USIM registers
//
// PARAMETERS  : None
//
// RETURN VALUE: None
//
// LIMITATIONS : None
//---------------------------------------------------------------------
void VIKING_USIM_Automatic_ATR_test(void)
{
	int i,j,coun,temp[33];
	i=0,j=0;
	coun=0;
	VIKING_USIM_Initialization_Test();
	VIKING_USIM_FIFOS_REG |= 0x040;     //reset all fifotx 
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x040);     //release fifotx

	VIKING_USIM_USIMCONF1_REG &= 0x0;     //automatic
	VIKING_USIM_USIMCONF1_REG |= 0x60;;     //automatic
	VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //transmit rw mode
//	USIM_USIMDTX_REG = 0x0055;
	for(i=0;i<33;i++)
	{
	temp[i] = 0;
	}
	i=0;
	VIKING_USIM_USIMCMD_REG |= 0x0004;  //start procedure of USIM card activated;
	while(i<22)
	{	
		coun++;
		if((VIKING_USIM_FIFOS_REG & 0x4000) != 0x4000)
		{
			temp[i] = VIKING_USIM_DRX_REG;
			i++;
		}
		if(coun>0xf0000)
			break;
	}
	if(temp[0]==0x13b||temp[0]==0x13f)
	{
		UART_Printf(UART2,"ATR of USIM is right!\n");
		UART_Printf(UART2,"ATR of USIM is :");
		for(i=0;i<22;i++)
		{
			UART_Printf(UART2,"0x%x ",temp[i]);
		}
		UART_Printf(UART2,"\n\r");

	}
	else
	{
		UART_Printf(UART2,"ATR of USIM is error!\n");
	
	}


	VIKING_USIM_USIMCONF2_REG = 0x0385;
	VIKING_USIM_CONF5_REG = 0x0196;
//	USIM_USIMCONF3_REG = 0x80;
}



void VIKING_usim_read_rxfifo(unsigned short * read_buf, unsigned int read_count)
{
    int i;
   	i=0;
	while(i<read_count)
	{
		if((VIKING_USIM_FIFOS_REG & 0x4000) != 0x4000)
		{
			*(read_buf++) = VIKING_USIM_DRX_REG & 0x00ff;
			i++;
		} 
	}
}

void VIKING_usim_write_txfifo(unsigned short * write_buf, unsigned int write_count)
{   

 	int i;
    for(i=0; i<write_count; i++)
		VIKING_USIM_DTX_REG = *(write_buf++);
	while(!(VIKING_USIM_FIFOS_REG & (0x00080)));

}



void VIKING_USIM_AccessSelect_test(void)
{
	int k,i,number;
	int val;
    unsigned short tempr[33], tx_buf[10];
	
	k = 0;
	VIKING_USIM_USIMCONF2_REG |= 0x0002;     //transmit  mode
	VIKING_USIM_USIMCMD_REG |= 0x0004;  //start procedure of USIM card activated;
	VIKING_USIM_FIFOS_REG |=0x0040;    //reset all fifotx 
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x0040);   //release all fifotx

	VIKING_USIM_FIFOS_REG |=0x2000;    //reset all fiforx 
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x2000);   //release all fiforx
	
	for(i=0;i<33;i++)
	{
		tempr[i] = 0;
	}

	tx_buf[0] = 0xa0;
	tx_buf[1] = 0xa4;
	tx_buf[2] = 0x00;
	tx_buf[3] = 0x00;
	tx_buf[4] = 0x02;


	VIKING_usim_write_txfifo(tx_buf, 5);
	VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //read  mode
	VIKING_usim_read_rxfifo(tempr,1);
	if(tempr[0] == tx_buf[1])
	{
		UART_Printf(UART2,"UICC has received right command :0x%x \n",tempr[0]);
		VIKING_USIM_USIMCONF2_REG |= 0x0002;     //transmit  mode
	  	UART_Printf(UART2,"Please Enter your choice file:(example:0x2f00) \n ");   
		val = UART_GetNum(UART2);


		tx_buf[0] = 0xFF & (val >>8);
		tx_buf[1] = (0xFF & val);
		VIKING_usim_write_txfifo(tx_buf, 2);
		VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //read  mode
		VIKING_usim_read_rxfifo(&tempr[1],2);

		VIKING_USIM_USIMCONF2_REG |= 0x0002;     //transmit  mode
		tx_buf[0] = 0xA0;
		tx_buf[1] = 0xC0;
		tx_buf[2] = 0x00;
		tx_buf[3] = 0x00;
		tx_buf[4] = 0xff&tempr[2];
		number = 0xff&tempr[2]+3;
		VIKING_usim_write_txfifo(tx_buf, 5);
		VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //read  mode
		VIKING_usim_read_rxfifo(&tempr[3],number);

		number=number+3;
		UART_Printf(UART2,"Response of USIM is [%d],:", number);
		for(i=0;i<number;i++)
		{
			UART_Printf(UART2,"0x%x ",tempr[i]);
		}
		UART_Printf(UART2,"\n\r");
		i++;
	}
	else
	{
		UART_Printf(UART2,"error!!!!\n\r");
	}

}

void VIKING_USIM_Access_test1(void)
{
	int k,i,number;
	int val;
    unsigned short tempr[33], tx_buf[10];
	
	k = 0;
	VIKING_USIM_USIMCONF2_REG |= 0x0002;     //transmit  mode
	VIKING_USIM_USIMCMD_REG |= 0x0004;  //start procedure of USIM card activated;
	VIKING_USIM_FIFOS_REG |=0x0040;    //reset all fifotx 
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x0040);   //release all fifotx

	VIKING_USIM_FIFOS_REG |=0x2000;    //reset all fiforx 
	for(i=0;i<1000;i++);
	VIKING_USIM_FIFOS_REG &= ~(0x2000);   //release all fiforx
	
	for(i=0;i<33;i++)
	{
		tempr[i] = 0;
	}

	tx_buf[0] = 0xa0;
	tx_buf[1] = 0xa4;
	tx_buf[2] = 0x00;
	tx_buf[3] = 0x00;
	tx_buf[4] = 0x02;


	VIKING_usim_write_txfifo(tx_buf, 5);
	VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //read  mode
	VIKING_usim_read_rxfifo(tempr,1);
	if(tempr[0] == tx_buf[1])
	{
		UART_Printf(UART2,"UICC has received right command :0x%x",tempr);
		VIKING_USIM_USIMCONF2_REG |= 0x0002;     //transmit  mode
	  	UART_Printf(UART2,"Please Enter your choice file:(example:0x2f00) \n ");   
		val = UART_GetNum(UART2);
		
	
		tx_buf[0] = 0xFF & (val >>8);
		tx_buf[1] = (0xFF & val);
		VIKING_usim_write_txfifo(tx_buf, 2);
		VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //read  mode
		VIKING_usim_read_rxfifo(&tempr[1],2);
	
		VIKING_USIM_USIMCONF2_REG |= 0x0002;     //transmit  mode
		tx_buf[0] = 0xA0;
		tx_buf[1] = 0xC0;
		tx_buf[2] = 0x00;
		tx_buf[3] = 0x00;
		tx_buf[4] = 0xff&tempr[2];
		number = 0xff&tempr[2]+3;
		VIKING_usim_write_txfifo(tx_buf, 5);
		VIKING_USIM_USIMCONF2_REG &= ~(0x0002);     //read  mode
		VIKING_usim_read_rxfifo(&tempr[3],number);
	
		number=number+3;
		UART_Printf(UART2,"Response of USIM is [%d],:", number);
		for(i=0;i<number;i++)
		{
			UART_Printf(UART2,"0x%x ",tempr[i]);
		}
		UART_Printf(UART2,"\n\r");
		i++;
	}
	else
	{
		UART_Printf(UART2,"error!!!!\n\r");
	}

}






void VIKING_USIM_TEST()
{
	int i;

	unsigned short val ;

   	UART_Printf(UART2,"Please select the Voltage of USIM:\n");
   	UART_Printf(UART2,"1 : 1V8,  2:2V8\n");
	val = UART_GetNum(UART2);
	if(val==1)
		Neptune_VRSIM_1V8();
	else
		Neptune_VRSIM_2V8();

	val=1;
		
	while(val)
	{
		UART_Printf(UART2,"\n\r");
		UART_Printf(UART2,"==========================================\n");
    	UART_Printf(UART2,"  VIKINGII USIM Test Menu\n");
    	UART_Printf(UART2,"==========================================\n");
	   	UART_Printf(UART2,"0 : Return upper menu \n");
    	UART_Printf(UART2,"1 : Initialize USIM controller\n");
    	UART_Printf(UART2,"2 : USIM_Automatic_ATR\n");
		UART_Printf(UART2,"3 : USIM Access_Select test\n");
		UART_Printf(UART2,"4 : USIM Access test1\n");
    	UART_Printf(UART2,"------------------------------------------\n\r");
  		UART_Printf(UART2,"Please Enter your choice: \n ");   
		val = UART_GetNum(UART2);
    	UART_Printf(UART2,"\n\r");
    
        switch (val)
    	{     		
    		case 0:
    		{
    		  	break;
    		}	
    		case 1:
    		{  
    			VIKING_USIM_Initialization_Test();
			  	break;
    		}   
            case 2:
			{
				VIKING_USIM_Automatic_ATR_test();
				break;
			}
			case 3:
			{
				VIKING_USIM_AccessSelect_test();
				break;			
			}
			case 4:
			{
				VIKING_USIM_Access_test1();
				break;			
			}

			default:
			break;
        }
	}
}

⌨️ 快捷键说明

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