📄 ic_card.c
字号:
/*==============================================================================*//* file name : ic_card.c (ic card devic driver function) *//* compiler : SPARC-RTEMS-GCC *//* author : mr.zhou *//* copyright : ORBITA Co.,Ltd. All Right Reserved.At 2005-9-2 *//*==============================================================================*/#include"ic_card.h"BYTE ic_RF_flag = FALSE; //Receive finished flagBYTE ic_TE_flag = FALSE; //Transfer finished flagBYTE ic_ATRO1_flag = FALSE; //Time over 19200BYTE ic_ATRO2_flag = FALSE; //Time over 9600 when you printf info at interrupt function,It will cause over timeBYTE ic_WWTO_flag = FALSE;BYTE ic_BWTO_flag = FALSE;BYTE ic_CWTO_flag = FALSE;BYTE ic_TTO_flag = FALSE;BYTE ic_RTO_flag = FALSE;BYTE ic_NATR_flag = FALSE;BYTE ic_CPCH_flag = FALSE;BYTE ic_RE_flag = FALSE;BYTE ic0_CPST_flag = FALSE;BYTE ic1_CPST_flag = FALSE;BYTE temp_data[20]={0x0},iii=0, data_buf[60];APDU_STRUCT apdu; extern void Delay(int count); void card_release(BYTE ic_unit){ _Set_Reg_Value(ic_unit?IC1_ENABLE_REG:IC0_ENABLE_REG ,DISABLE); Set_Gpio_Data_Reg(GPI0_DATA,ic_unit?IC_CARD1_OUT:IC_CARD0_OUT,DISABLE);}/****************************************************************//* FUNCTION : IC1_IntSvr_Fun *//* when the 29th bit of second interrupt register was true; *//* It will come into this function; *//* Description: *//* Parameters: *//* none *//* Return: *//* none *//* Syntax: *//* void IC1_IntSvr_Fun(void) *//****************************************************************/void IC1_IntSvr_Fun(void) { DWORD temp_state_reg=0x0; BYTE data=0x0; DWORD pri_mask,sec_mask,pri_clear,sec_clear; _Get_Reg_Value(pri_mask,INT_MASK_REG); _Get_Reg_Value(sec_mask,SEC_INT_MASK_REG); _Get_Reg_Value(pri_clear,INT_CLEAR_REG); _Get_Reg_Value(sec_clear,SEC_INT_CLEAR_REG); Set_Interrupt_Bit(PRI_INT_CLEAR,INT_VECTOR_10,ENABLE); //clear pri interrupt 10 Set_Interrupt_Bit(SEC_INT_CLEAR,IC_CARD_1_INT,ENABLE); //clear second interrupt for IC_CARD_1_INT _Set_Reg_Value(INT_MASK_REG ,DISABLE); _Set_Reg_Value(SEC_INT_MASK_REG ,DISABLE); _Get_Reg_Value(temp_state_reg,IC1_STATE_REG); if ( temp_state_reg & 0x01) { ic_RF_flag =TRUE; } // Finish receive a byte; if ( temp_state_reg & 0x02) { ic_TE_flag =TRUE;} // Finish transfer a byte; if ( temp_state_reg & 0x04) { ic_ATRO1_flag =TRUE; } if ( temp_state_reg & 0x08) { ic_ATRO2_flag =TRUE; }; if ( temp_state_reg & 0x10) { ic_WWTO_flag =TRUE;} if ( temp_state_reg & 0x20) { ic_BWTO_flag =TRUE; printf("\nBWTO"); } if ( temp_state_reg & 0x40) { ic_CWTO_flag =TRUE; printf("\nCWTO"); } if ( temp_state_reg & 0x80) { ic_TTO_flag =TRUE; printf("\nTTO"); } if ( temp_state_reg & 0x100) { ic_RTO_flag =TRUE; printf("\nRTO\n"); } if ( temp_state_reg & 0x200) { ic_NATR_flag =TRUE;} // printf("\nNATR"); } if (temp_state_reg & 0x400) { if(temp_state_reg&0x800) { ic1_CPST_flag =TRUE ; printf("\nCPST:card inserted!\n"); } else { ic1_CPST_flag =FALSE ; printf("\nCPST:card removed!\n"); } } if ( temp_state_reg & 0x1000) { ic_RE_flag =TRUE ; printf("\nRE\n"); } _Set_Reg_Value(INT_CLEAR_REG ,pri_clear); _Set_Reg_Value(SEC_INT_CLEAR_REG,sec_clear); _Set_Reg_Value(INT_MASK_REG ,pri_mask); //open first level interrupt _Set_Reg_Value(SEC_INT_MASK_REG ,sec_mask); //open second level interrupt Set_Interrupt_Bit(PRI_INT_MASK,INT_VECTOR_10,ENABLE); Set_Interrupt_Bit(SEC_INT_MASK,IC_CARD_1_INT,ENABLE); return;}/*************************************************************//* FUNCTION : IC0_IntSvr_Fun *//* when the 30th bit of second interrupt register was true; */ /* It will come into this function; *//* Description: */ /* Parameters: *//* none *//* Return: *//* none *//* Syntax: *//* void IC0_IntSvr_Fun(void) *//*************************************************************/void IC0_IntSvr_Fun(void) // IC Card 0 Interrupt Service Function{ DWORD temp_state_reg=0x0; DWORD pri_mask,sec_mask,pri_clear,sec_clear; _Get_Reg_Value(pri_mask,INT_MASK_REG); _Get_Reg_Value(sec_mask,SEC_INT_MASK_REG); _Get_Reg_Value(pri_clear,INT_CLEAR_REG); _Get_Reg_Value(sec_clear,SEC_INT_CLEAR_REG); Set_Interrupt_Bit(PRI_INT_CLEAR,INT_VECTOR_10,ENABLE); Set_Interrupt_Bit(SEC_INT_CLEAR,IC_CARD_0_INT,ENABLE); _Set_Reg_Value(INT_MASK_REG ,DISABLE); _Set_Reg_Value(SEC_INT_MASK_REG ,DISABLE); _Get_Reg_Value(temp_state_reg,IC0_STATE_REG); // Finish receive a byte; if ( temp_state_reg & 0x01) { ic_RF_flag =TRUE; } if ( temp_state_reg & 0x02) // Finish transfer a byte; { ic_TE_flag =TRUE; } if ( temp_state_reg & 0x04) { ic_ATRO1_flag =TRUE; } //printf("\nATRO1\n"); } if ( temp_state_reg & 0x08) { ic_ATRO2_flag =TRUE;}; // printf("\nATRO2\n"); } if ( temp_state_reg & 0x10) { ic_WWTO_flag =TRUE;} // printf("\nWWTO"); } if ( temp_state_reg & 0x20) { ic_BWTO_flag =TRUE; printf("\nBWTO"); } if ( temp_state_reg & 0x40) { ic_CWTO_flag =TRUE; printf("\nCWTO"); } if ( temp_state_reg & 0x80) { ic_TTO_flag =TRUE; printf("\nTTO"); } if ( temp_state_reg & 0x100) { ic_RTO_flag =TRUE; printf("\nRTO\n"); } if ( temp_state_reg & 0x200) { ic_NATR_flag =TRUE; printf("\nNATR"); } if (temp_state_reg & 0x400) { if(temp_state_reg&0x800) ic1_CPST_flag =TRUE ; else ic1_CPST_flag =FALSE ; printf("\nCPST\n"); } if (temp_state_reg & 0x1000) { ic_RE_flag =TRUE ; printf("\nRE\n"); } _Set_Reg_Value(INT_CLEAR_REG ,pri_clear); _Set_Reg_Value(SEC_INT_CLEAR_REG,sec_clear); _Set_Reg_Value(INT_MASK_REG ,pri_mask); //open first level interrupt _Set_Reg_Value(SEC_INT_MASK_REG ,sec_mask); //open second level interrupt Set_Interrupt_Bit(PRI_INT_MASK,INT_VECTOR_10,ENABLE); Set_Interrupt_Bit(SEC_INT_MASK,IC_CARD_0_INT,ENABLE); return;}/************************************************************//* FUNCTION : Second_IntSrv_Fun *//* Description: *//* This is a service function of second interrupt. *//* Parameters: *//* int irq_handle *//* Return: *//* none *//* Syntax: *//* void Second_IntSrv_Fun(int irq_handle) */ /************************************************************/void Second_IntSrv_Fun(int irq_handle) //INT Vector 10 service function{ DWORD temp_secpend; _Get_Reg_Value(temp_secpend,SEC_INT_MASK_REG); if (temp_secpend & IC_CARD_0_INT) //30 vector ic card 0 interrupt { IC0_IntSvr_Fun(); } if (temp_secpend & IC_CARD_1_INT) //29 vector ic card 1 interrupt { IC1_IntSvr_Fun(); } if (temp_secpend & IC_CARD_2_INT) //28 vector ic card 2 interrupt { //IC1_IntSvr_Fun(); } }/************************************************************//* FUNCTION : Check_Icard_Exist *//* Description: *//* In this function we'll check: *//* 1.Check card is conductor or not; *//* 2.Check card is exist or not; *//* 3.Check card gpio port is value or not; *//* Parameters: *//* none *//* Return: */ /* none *//* Syntax: *//* void Check_Icard_Exist(void) *//************************************************************/Ulong Check_Icard_Exist(BYTE ic_unit){ Ulong temp_str,temp_data,return_value=ERROR; if(ic_unit == IC0_CARD) { Set_Gpio_Direct_Reg(GPI0_DIRECT,IC_CARD0_PRES,DISABLE); _Get_Reg_Value(temp_data,GPI0_DATA_REG); if(temp_data&IC_CARD0_PRES) //Check isn't conductor;like sheet iron return_value=OK; else { printf("\nERROR:IC card %d is not exist!\n",ic_unit); return_value=ERROR; } } else if(ic_unit == IC1_CARD) { Set_Gpio_Direct_Reg(GPI0_DIRECT,IC_CARD1_PRES,DISABLE); _Get_Reg_Value(temp_data,GPI0_DATA_REG); if(temp_data&IC_CARD1_PRES) return_value=OK; else { printf("\nERROR:IC card %d is not exist!\n",ic_unit); return_value=ERROR; } } if(return_value==OK) { if(ic_unit == IC0_CARD) { _Get_Reg_Value(temp_str,IC0_STATE_REG); temp_str = temp_str & 0x800; //check ic card is exist or not; if(temp_str == 0x800) return_value=OK; else { printf("\nERROR:IC card %d is not exist!\n",ic_unit); return_value=ERROR; } } else if(ic_unit == IC1_CARD) { _Get_Reg_Value(temp_str,IC1_STATE_REG); temp_str = temp_str & 0x800; if(temp_str ==0x800) return_value=OK; else { printf("\nERROR:IC card %d is not exist!\n",ic_unit); return_value=ERROR; } } } if(return_value==OK) { if(ic_unit == IC0_CARD) { _Get_Reg_Value(temp_data,GPI0_DATA_REG); temp_data = temp_data & IC_CARD0_OUT; if(temp_data == IC_CARD0_OUT) //check ic card is io port is open or not; return_value= OK; else { printf("\nERROR:IC card %d gpio not open!\n",ic_unit); return_value=ERROR; } } else if(ic_unit == IC1_CARD) { _Get_Reg_Value(temp_data,GPI0_DATA_REG); temp_data = temp_data & IC_CARD1_OUT; if(temp_data == IC_CARD1_OUT) { return_value= OK; } else { printf("\nERROR:IC card %d gpio not open!\n",ic_unit); return_value= ERROR; } } } if(return_value == OK) printf("\nOK:IC card %d is normal!\n",ic_unit); return return_value;}Ulong Check_Ic_Card(){ Ulong return_value=ERROR; return_value = Check_Icard_Exist(IC0_CARD);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -