📄 usim.c
字号:
//===============================================================================
//
//
// Property of Texas Instruments
// For Unrestricted Internal Use Only
// Unauthorized reproduction and/or distribution is strictly prohibited.
// This product is protected under copyright law and trade secret law
// as an unpublished work.
// Created 2000, (C) Copyright 2000 Texas Instruments. All rights reserved.
//
// Filename : usim.c
// Date of Generation :8/22/02
//
//===============================================================================
#include "global_types.h"
#include "usim.h"
#include "test.h"
#include "testaccess.h"
#include "UART_IrDA.h"
#include "CRPM.h"
#include "configuration.h"
#include "interrupt_mapping.h"
static int temp[33];
int read_num;
int USIM_FLAG = 0;
//---------------------------------------------------------------------
// NAME : USIM_Initialization_Test
//
// DESCRIPTION : Initialization of USIM registers
//
// PARAMETERS : None
//
// RETURN VALUE: None
//
// LIMITATIONS : None
//---------------------------------------------------------------------
void USIM_IntCfg()
{
IsrRegister(USIM_INT, USIM_InthProcess);
Setgroupbit( INTERRUPT_L2_ILR_1 + (USIM_INT - 32)*4, 0, 8, 0x006 ); // rout to IRQ, LOW LEVEL, PRIORITY IS 1.
//Setgroupbit( INTERRUPT_L2_MIR_1, 1, 1, 0x000 ); // open mpu level 2 int-kb_it.
Setgroupbit( INTERRUPT_L1_ILR_0, 0, 7, 0x002 ); // mpu level 1 IRQ-0, LOW LEVEL, PRI IS 0.
OpenInterrupt(USIM_INT); //open the level 1 IRQ-0
//Setgroupbit( INTERRUPT_L1_MIR , 0, 1, 0x000 ); // open the level 1 IRQ-0.
USIM_USIMMASK_IT_REG = ~(0x10);
}
void USIM_Initialization_Test(void)
{
int i;
int temp;
USIM_USIMCMD_REG |= 0x1; //software reset of the USIM module
for(i=0;i<1000;i++);
USIM_USIMCMD_REG |= 0x1; //software reset of the USIM module
for(i=0;i<1000;i++);
while(1)
{
temp = USIM_USIMCMD_REG;
if((temp & 0x1)==0)
break;
}
//wait for reset over
USIM_USIMCONF1_REG = 0x0; //reset usimconf
USIM_USIMCONF2_REG = 0x0; //reset usimconf
USIM_USIMFIFOS_REG = 0x20e; //fifo triger= 1, enable fifo
USIM_USIMFIFOS_REG |= 0x040; //fifo triger= 3, enable fifo
for(i=0;i<1000;i++);
USIM_USIMFIFOS_REG &= ~(0x040); //fifo triger= 3, enable fifo
USIM_USIMFIFOS_REG |= 0x2000;
for(i=0;i<1000;i++);
USIM_USIMFIFOS_REG &= ~(0x2000);
USIM_USIMCONF2_REG |= 0x0014; //receive mode 13M/4, bypass synchronous and asynchronous card ATR;
USIM_USIMCONF3_REG |= 0x0010; //TDUSIM = (coefficient +1)*8*Tetu
USIM_USIMCMD_REG |= 0x0008; //module clock activated;
USIM_CONF5_REG = 0x0101;
USIM_USIMCONF3_REG = 0x40;
USIM_IntCfg();
}
void USIM_InthProcess()
{
int i;
i = 0;
while(i<read_num)
{
if((USIM_USIMFIFOS_REG & 0x4000) != 0x4000)
{
temp[i] = USIM_USIMDRX_REG;
i++;
}
}
USIM_FLAG = 1;
USIM_USIMIT_REG &= ~(0x0010);
Setgroupbit(0xfffe0018, 0, 1, 1 ); // enable new l2 interrupt
}
//---------------------------------------------------------------------
// NAME : USIM_TestRegistersAccess
//
// DESCRIPTION : Test the access to USIM registers
//
// PARAMETERS : None
//
// RETURN VALUE: None
//
// LIMITATIONS : None
//---------------------------------------------------------------------
void USIM_Automatic_ATR_test(void)
{
int i,coun;
i=0;
coun=0;
read_num = 22;
// USIM_Initialization_Test();
USIM_USIMFIFOS_REG |= 0x040; //reset all fifotx
for(i=0;i<1000;i++);
USIM_USIMFIFOS_REG &= ~(0x040); //release fifotx
USIM_USIMCONF1_REG &= 0x0; //automatic
USIM_USIMCONF1_REG |= 0x60;; //automatic
USIM_USIMCONF2_REG &= ~(0x0002); //transmit rw mode
// USIM_USIMDTX_REG = 0x0055;
for(i=0;i<33;i++)
{
temp[i] = 0;
}
i=0;
USIM_USIMCMD_REG |= 0x0004; //start procedure of USIM card activated;
while(USIM_FLAG == 0);
USIM_FLAG = 0;
/*
while(i<22)
{
coun++;
if((USIM_USIMFIFOS_REG & 0x4000) != 0x4000)
{
temp[i] = USIM_USIMDRX_REG;
i++;
}
if(coun>0x10000)
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");
}
USIM_USIMCONF2_REG = 0x0385;
USIM_CONF5_REG = 0x0196;
// USIM_USIMCONF3_REG = 0x80;
}
void usim_read_rxfifo(unsigned short * read_buf, unsigned int read_count)
{
int i;
i=0;
while(i<read_count)
{
if((USIM_USIMFIFOS_REG & 0x4000) != 0x4000)
{
*(read_buf++) = USIM_USIMDRX_REG & 0x00ff;
i++;
}
}
}
void usim_write_txfifo(unsigned short * write_buf, unsigned int write_count)
{
int i;
for(i=0; i<write_count; i++)
USIM_USIMDTX_REG = *(write_buf++);
while(!(USIM_USIMFIFOS_REG & (0x00080)));
}
void USIM_AccessSelect_test(void)
{
int k,i,number;
int val;
unsigned short tempr[33], tx_buf[10];
k = 0;
USIM_USIMCONF2_REG |= 0x0002; //transmit mode
USIM_USIMCMD_REG |= 0x0004; //start procedure of USIM card activated;
USIM_USIMFIFOS_REG |=0x0040; //reset all fifotx
for(i=0;i<1000;i++);
USIM_USIMFIFOS_REG &= ~(0x0040); //release all fifotx
USIM_USIMFIFOS_REG |=0x2000; //reset all fiforx
for(i=0;i<1000;i++);
USIM_USIMFIFOS_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;
read_num = 1;
usim_write_txfifo(tx_buf, 5);
USIM_USIMCONF2_REG &= ~(0x0002); //read mode
while(USIM_FLAG == 0);
USIM_FLAG = 0;
for(i=0;i<read_num+1;i++)
{
tempr[i] = temp[i] & 0xff;
}
// usim_read_rxfifo(tempr,1);
if(tempr[0] == tx_buf[1])
{
UART_Printf(UART2,"UICC has received right command :0x%x \n",tempr[0]);
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);
usim_write_txfifo(tx_buf, 2);
read_num = 2;
USIM_USIMCONF2_REG &= ~(0x0002); //read mode
while(USIM_FLAG == 0);
USIM_FLAG = 0;
for(i=0;i<read_num+1;i++)
{
tempr[i+1] = temp[i] & 0xff;
}
// usim_read_rxfifo(&tempr[1],2);
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;
usim_write_txfifo(tx_buf, 5);
read_num = number;
USIM_USIMCONF2_REG &= ~(0x0002); //read mode
while(USIM_FLAG == 0);
USIM_FLAG = 0;
for(i=0;i<read_num+1;i++)
{
tempr[i+3] = temp[i] & 0xff;
}
// usim_read_rxfifo(&temp[3],number);
number=number+3;
if(tempr[number-1]==0x0 && tempr[number-2]==0x90)
{
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");
}
else
{
UART_Printf(UART2,"error!!!!\n\r");
}
}
else
{
UART_Printf(UART2,"error!!!!\n\r");
}
}
void USIM_Access_test1(void)
{
int k,i,number;
int val;
unsigned short tempr[33], tx_buf[10];
k = 0;
USIM_USIMCONF2_REG |= 0x0002; //transmit mode
USIM_USIMCMD_REG |= 0x0004; //start procedure of USIM card activated;
USIM_USIMFIFOS_REG |=0x0040; //reset all fifotx
for(i=0;i<1000;i++);
USIM_USIMFIFOS_REG &= ~(0x0040); //release all fifotx
USIM_USIMFIFOS_REG |=0x2000; //reset all fiforx
for(i=0;i<1000;i++);
USIM_USIMFIFOS_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;
usim_write_txfifo(tx_buf, 5);
USIM_USIMCONF2_REG &= ~(0x0002); //read mode
usim_read_rxfifo(tempr,1);
if(tempr[0] == tx_buf[1])
{
UART_Printf(UART2,"UICC has received right command :0x%x",tempr);
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);
usim_write_txfifo(tx_buf, 2);
USIM_USIMCONF2_REG &= ~(0x0002); //read mode
usim_read_rxfifo(&tempr[1],2);
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;
usim_write_txfifo(tx_buf, 5);
USIM_USIMCONF2_REG &= ~(0x0002); //read mode
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 usim_test(void)
{
int i,sel;
unsigned short val ;
Neptune_VRSIM_2V8();
UART_Printf(UART2,"Please select the Voltage of USIM:\r\n");
UART_Printf(UART2,"1 : 1V8, 2:2V8\r\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,"==========================================\r\n");
UART_Printf(UART2," USIM Test Menu\r\n");
UART_Printf(UART2,"==========================================\r\n");
UART_Printf(UART2,"0 : Return upper menu \r\n");
UART_Printf(UART2,"1 : Initialize USIM controller\r\n");
UART_Printf(UART2,"2 : USIM_Automatic_ATR\r\n");
UART_Printf(UART2,"3 : USIM Access_Select test\r\n");
UART_Printf(UART2,"4 : USIM Access test1\r\n");
UART_Printf(UART2,"5 : USIM Power ON\n");
UART_Printf(UART2,"6 : USIM Power Off\n");
UART_Printf(UART2,"------------------------------------------\n\r");
UART_Printf(UART2,"Please Enter your choice: \r\n ");
val = UART_GetNum(UART2);
UART_Printf(UART2,"\n\r");
switch (val)
{
case 0:
{
break;
}
case 1:
{
USIM_Initialization_Test();
break;
}
case 2:
{
USIM_Automatic_ATR_test();
break;
}
case 3:
{
USIM_AccessSelect_test();
break;
}
case 4:
{
USIM_Access_test1();
break;
}
case 5:
{
UART_Printf(UART2,"Please select the Voltage of USIM:\n");
UART_Printf(UART2,"1 : 1V8, 2:2V8\n");
sel = UART_GetNum(UART2);
if(sel==1)
Neptune_VRSIM_1V8();
else
Neptune_VRSIM_2V8();
break;
}
case 6:
{
triton_VRSIM_OFF();
break;
}
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -