1337 views|0 replies

2015

Posts

0

Resources
The OP
 

Processing flow of CPU card programming [Copy link]

When the single-chip microcomputer control circuit detects that a CPU card has been inserted, the processing flow is as follows: 1), Power on and reset the card 2), Select the main file on the card to be operated 3), Power on and reset the ESAM module 4) Select the main file of the ESAM module to be operated 5) If the read and write permissions of the file are free, you can now read and write the file. If you have read and write permissions, you need to go through internal and external authentication before reading and writing the file. 6), Internal authentication between card and ESAM 7), External authentication between card and ESAM 8), Read (write) permissioned files. 2.1 Port Configuration Here are the microcontroller port definitions related to the CPU card and ESAM module used in the program. 2.1.1.端口定义


#define P3_7EsamPower BIT7 //ESAM上电


#define P4_4EsamSDA BIT4 //ESAM数据端


#define P4_5EsamRST BIT5 //ESAM复位


#define P3_2CardSDA BIT2 //卡数据端


#define P3_4CardRst BIT4 //卡复位


#define P3_5CardInsChk BIT5 //卡插入检测


#define P3_6CardPower BIT6 //卡上电


#define PJ_1MCLK BIT1 // MCLK,卡和ESAM的SCL信号输入端


在程序中经常要对端口的输入输出和电平高低状况进行改变,MSP430单片机不能对端口进行位操作,为了操作方便将端口的各种状态用宏定义进行规范,这样可以简化程序中队端口的操作,并且使程序可读性强,便于移植。


例如下面定义的CardPowerInput,直接从字面理解即为CPU卡的商店管脚作为输入口,而CardPowerOutputHigh意为卡上电端口输出高电平。这样不仅直观,而且避免了在程序中直接对端口进行配置。


//卡SDA管脚宏定义


#define CardSDAOutput P3DIR|=P3_2CardSDA


#define CardSDAInput P3DIR&=~P3_2CardSDA


#define CardSDAOutputHigh P3OUT|=P3_2CardSDA


#define CardSDAOutputLow P3OUT&=~P3_2CardSDA


#define CardSDAInputCheck P3IN&P3_2CardSDA


//卡复位管脚宏定义


#define CardRSTOutput P3DIR|=P3_4CardRst


#define CardRSTInput P3DIR&=~P3_4CardRst


#define CardRSTOutputHighP3OUT|=P3_4CardRst


#define CardRSTOutputLow P3OUT&=~P3_4CardRst


#define CardRSTInputCheck P3IN&P3_4CardRst


//卡上电管脚宏定义


#define CardPowerOutput P3DIR|=P3_6CardPower


#define CardPowerInput P3DIR&=~P3_6CardPower


#define CardPowerOutputHigh P3OUT|=P3_6CardPower


#define CardPowerOutputLow P3OUT&=~P3_6CardPower


#define CardPowerInputCheck P3IN&P3_6CardPower


//卡插入管脚宏定义


#define CardInsertCheckOutput P3DIR|=P3_5CardInsChk


#define CardInsertCheckInput P3DIR&=~P3_5CardInsChk


#define CardInsertCheckOutputHigh P3OUT|=P3_5CardInsChk


#define CardInsertCheckOutputLow P3OUT&=~P3_5CardInsChk


#define CardInsertCheck P3IN&P3_5CardInsChk


//Esam SDA管脚宏定义


#define EsamSDAOutput P4DIR|=P4_4EsamSDA


#define EsamSDAInput P4DIR&=~P4_4EsamSDA


#define EsamSDAOutputHigh P4OUT|=P4_4EsamSDA


#define EsamSDAOutputLow P4OUT&=~P4_4EsamSDA


#define EsamSDAInputCheckP4IN&P4_4EsamSDA


//Esam 复位管脚宏定义


#define EsamRSTOutput P4DIR|=P4_5EsamRST


#define EsamRSTInput P4DIR&=~P4_5EsamRST


#define EsamRSTOutputHigh P4OUT|=P4_5EsamRST


#define EsamRSTOutputLow P4OUT&=~P4_5EsamRST


#define EsamRSTInputCheck P4IN&P4_5EsamRST


//Esam 上电管脚宏定义


#define EsamPowerOutput P3DIR|=P3_7EsamPower


#define EsamPowerInput P3DIR&=~P3_7EsamPower


#define EsamPowerOutputHigh P3OUT|=P3_7EsamPower


#define EsamPowerOutputLow P3OUT&=~P3_7EsamPower


#define EsamPowerInputCheck P3IN&P3_7EsamPower


//MCLK管脚宏定义


#define MCLKOutput PJDIR|=PJ_1MCLK


#define MCLKInput PJDIR&=~PJ_1MCLK


#define MCLKOutputHigh PJOUT|=PJ_1MCLK


#define MCLKOutputLow PJOUT&=~PJ_1MCLK


#define MCLKInputCheck PJIN&PJ_1MCLK


#define MCLKSEL PJSEL|=PJ_1MCLK


2.2.Variable and macro definitions 2.2.1. Card processing result variables unsigned int CardError; This variable defines various abnormal states that occur during the card processing process to indicate at which step the problem occurred, making it easier to find and solve the problem. The following is the definition of each bit of the variable. #define ErrorRSTBIT BIT0 //Card reset error #define ErrorRWBIT BIT1 //Card read and write error #define ErrorPasswBIT BIT2 //Card and Esam internal authentication error #define ErrorCardExtAuthBIT BIT3 //Card external authentication error #define ErrorEsamExtAuthBIT BIT4 //ESAM module external authentication error #define ErrorKeyUpdateBIT BIT5 //Key update error #define ErrorKeyBIT BIT6 //Key comparison error 2.2.2. CPU card communication byte length unsigned char TxAndRxBuff[124]; The data in the card or ESAM reading and writing process is transmitted through this variable. During the processing of the CPU card, a maximum of 124 bytes can be received and sent each time 2.2.3. Card and ESAM file main directory macro definition //Card main directory 3f 01, Esam main directory 3f 00 #define MainDir 0x3f #define CardMainDir 0x01 #define EsamMainDir 0x00 Before operating files on the card or ESAM, you must first select the main directory where the file is located. 2.2.4.Response status word //Response status word SW1, SW2, //The response data of the command executed correctly is SW1SW2=90 00 or SW1SW2=61 00 #define RespondStateByte1 0x90 #define RespondStateByte2 0x00 #define RespondStateByte3 0x61 2.2.5. Data reception result variable //cTxAndRxStatus CPU card receives data correctly #define ReceINSRightBIT BIT0 This variable is used to determine whether the data received from the card or ESAM is correct. 2.2.6. Card (ESAM operation flag variable) This variable is used to indicate whether the operation is performed on the card or the ESAM, and also to indicate whether the verification result of the data from the card or ESAM is correct or not //Variable CardWorkFlag #define CardORESAM BIT0 //0--SAM operation 1--Card operation #define CARDPRO_ERR BIT1 //0--Card read/write operation is normal 1-Card read/write error #define cCheckOrRe BIT2 #define ICXOR BIT6 //Checksum sent by card/ESAM #define MXOR BIT7 //Checksum calculated by CPU #define CheckflagBit BIT5


//命令正确执行的响应数据为SW1SW2=90 00或SW1SW2=61 00


#define RespondStateByte1 0x90


#define RespondStateByte2 0x00


#define RespondStateByte3 0x61


2.2.5. 数据接收结果变量


//cTxAndRxStatus CPU卡接收数据正确标志


#define ReceINSRightBIT BIT0


该变量用以判定从卡或者ESAM接受的数据是否正确。


2.2.6. 卡(ESAM操作标志变量)


此变量用以标明是对卡还是对ESAM进行操作,并且还标明从卡或者ESAM来的数据的校验结果正确与否


//变量CardWorkFlag


#define CardORESAM BIT0 //0--对SAM操作 1--对卡操作


#define CARDPRO_ERR BIT1 //0--读写卡操作正常 1--读写卡错误


#define cCheckOrRe BIT2


#define ICXOR BIT6 //卡/ESAM传来的校验和


#define MXOR BIT7 //CPU计算的校验和


#define CheckflagBit BIT5


//命令正确执行的响应数据为SW1SW2=90 00或SW1SW2=61 00


#define RespondStateByte1 0x90


#define RespondStateByte2 0x00


#define RespondStateByte3 0x61


2.2.5. 数据接收结果变量


//cTxAndRxStatus CPU卡接收数据正确标志


#define ReceINSRightBIT BIT0


该变量用以判定从卡或者ESAM接受的数据是否正确。


2.2.6. 卡(ESAM操作标志变量)


此变量用以标明是对卡还是对ESAM进行操作,并且还标明从卡或者ESAM来的数据的校验结果正确与否


//变量CardWorkFlag


#define CardORESAM BIT0 //0--对SAM操作 1--对卡操作


#define CARDPRO_ERR BIT1 //0--读写卡操作正常 1--读写卡错误


#define cCheckOrRe BIT2


#define ICXOR BIT6 //卡/ESAM传来的校验和


#define MXOR BIT7 //CPU计算的校验和


#define CheckflagBit BIT5Data reception result variable //cTxAndRxStatus CPU card receives data correctly flag #define ReceINSRightBIT BIT0 This variable is used to determine whether the data received from the card or ESAM is correct. 2.2.6. Card (ESAM operation flag variable) This variable is used to indicate whether the operation is performed on the card or the ESAM, and also to indicate whether the verification result of the data from the card or ESAM is correct or not //Variable CardWorkFlag #define CardORESAM BIT0 //0--SAM operation 1--Card operation #define CARDPRO_ERR BIT1 //0--Card read/write operation is normal 1-Card read/write error #define cCheckOrRe BIT2 #define ICXOR BIT6 //Checksum sent by card/ESAM #define MXOR BIT7 //Checksum calculated by CPU #define CheckflagBit BIT5Data reception result variable //cTxAndRxStatus CPU card receives data correctly flag #define ReceINSRightBIT BIT0 This variable is used to determine whether the data received from the card or ESAM is correct. 2.2.6. Card (ESAM operation flag variable) This variable is used to indicate whether the operation is performed on the card or the ESAM, and also to indicate whether the verification result of the data from the card or ESAM is correct or not //Variable CardWorkFlag #define CardORESAM BIT0 //0--SAM operation 1--Card operation #define CARDPRO_ERR BIT1 //0--Card read/write operation is normal 1-Card read/write error #define cCheckOrRe BIT2 #define ICXOR BIT6 //Checksum sent by card/ESAM #define MXOR BIT7 //Checksum calculated by CPU #define CheckflagBit BIT5

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list