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

📄 scib_api.h

📁 atmel c5122 USB C51程序
💻 H
字号:
/*H**************************************************************************
* NAME:         scib_api.h         
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      c5122-scib-usb-hid-2_4_0      
* REVISION:     1.18     
*----------------------------------------------------------------------------
* PURPOSE: 
* include file for scib_api.c file                                     
*****************************************************************************/
#ifndef SCIB_API_H
#define SCIB_API_H

/*_____ I N C L U D E S ____________________________________________________*/
#include "lib_mcu\scib\scib_lib.h"

/*_____ M A C R O S ________________________________________________________*/

/* {for Langdoc } */

/*C**************************************************************************
* NAME: SC_0_VOLT,SC_1_8_VOLT,SC_3_VOLT,SC_5_VOLT
*----------------------------------------------------------------------------
* PURPOSE: 
* Define value smart card power
****************************************************************************/
#define SC_0_VOLT       0x00 
#define SC_1_8_VOLT     (Uchar)MSK_SCICR_VCARD0
#define SC_3_VOLT       (Uchar)MSK_SCICR_VCARD1
#define SC_5_VOLT       (Uchar)(MSK_SCICR_VCARD1|MSK_SCICR_VCARD0)
                           
/*C**************************************************************************
* NAME: MAX_WAIT_POWER_UP
*----------------------------------------------------------------------------
* PURPOSE: 
* Initial counter wait loop for power smart card 
****************************************************************************/
#define MAX_WAIT_POWER_UP 0x50  

/*C**************************************************************************
* NAME: MAX_SIZE_ATR
*----------------------------------------------------------------------------
* PURPOSE: 
* Max size string ATR 
****************************************************************************/
#define MAX_SIZE_ATR      36

/*C**************************************************************************
* NAME: DEFAULT_ETU
*----------------------------------------------------------------------------
* PURPOSE: 
* Default laps etu in micro sec en function of FCLK_SCIB (if FCLK_SCIB=4Mhz then etu =93us 
*****************************************************************************/
#define DEFAULT_ETU    (((Uint32)372*(Uint32)1000)/(Uint32)FCLK_SCIB)  /* default laps etu 93us*/

/*C**************************************************************************
* NAME: SCIB_100_MS
*----------------------------------------------------------------------------
* PURPOSE: 
* wait env 100 ms with etu = 93us
****************************************************************************/
#define SCIB_100_MS         ((Uint32)100000/DEFAULT_ETU) //100000ms 1070 etu  

/*C**************************************************************************
* NAME: SCIB_10_MS
*----------------------------------------------------------------------------
* PURPOSE: 
* wait env 10 ms with etu = 93us
****************************************************************************/
#define SCIB_10_MS         ((Uint32)10000/DEFAULT_ETU) //10000ms 107 etu   

/*C**************************************************************************
* NAME: SCIB_3_MS
*----------------------------------------------------------------------------
* PURPOSE: 
* wait env 3 ms with etu = 93us
****************************************************************************/
#define SCIB_3_MS         ((Uint32)3000/DEFAULT_ETU) //3000us 32 etu 


/*C**************************************************************************
* NAME: ISO_400_CYCLE
*----------------------------------------------------------------------------
* PURPOSE: 
* wait env 10 ms with etu = 93us
****************************************************************************/
#define ISO_400_CYCLE      ((Uint32)40000/(Uint32)372)  //107 etu   

/*C**************************************************************************
* NAME: ISO_40000_CYCLE
*----------------------------------------------------------------------------
* PURPOSE: 
* wait env 30 ms with etu = 93us   
****************************************************************************/
#define ISO_40000_CYCLE    ((Uint32)43000/(Uint32)372) //335   

/*C**************************************************************************
* NAME: ISO_9600_ETU
*----------------------------------------------------------------------------
* PURPOSE: 
* wait 9600 etu + 10 % error tools EMV
****************************************************************************/
#define ISO_9600_ETU       10200 

/*C**************************************************************************
* NAME:  MAX_ATR_ETU_DURATION
*----------------------------------------------------------------------------
* PURPOSE: 
* wait 19200 etu + 400 error tools EMV ATR time out max envirron 1.8 sec
****************************************************************************/
#define MAX_ATR_ETU_DURATION       20400 //19200+... for error tools EMV

/*C**************************************************************************
* NAME:  MAX_ATR_ETU_DURATION
*----------------------------------------------------------------------------
* PURPOSE: 
* max atr duration in ms
****************************************************************************/
#define MAX_ATR_LAPS_DURATION       (Uint16)(((Uint16)MAX_ATR_ETU_DURATION*(Uint16)DEFAULT_ETU)/(Uint16)1000)

/*C**************************************************************************
* NAME: ERR_
*----------------------------------------------------------------------------
* PURPOSE: 
* define SCIB error code
****************************************************************************/
#define ERR_POWER_UP        0xFB  /*error Vcardok not ok */
#define ERR_SC_MUTE         0xFE  /*error smart card mute */
#define ERR_BAD_ATR         0xF8  /*bad ATR return by the smart card */
#define ERR_PROCEDURE_BYTE  0xF4  /*answer smart card not ISO */
#define ERR_PARITY          0xFD  /*error parity */
#define ERR_OVER_RUN        0xFC  /*error overun */
#define ERR_UNKNOW          0xC0  /* error not implemented */ 
#define ERR_BAD_NAD         0xC1  /* bad nad in T=1 */



/*C**************************************************************************
* NAME: MASK_CARD_
*----------------------------------------------------------------------------
* PURPOSE: 
* Mask bit for presence card and mouvement card
****************************************************************************/
#define MASK_CARD_PRESENT  0x01
#define MASK_CARD_MVT      0x02

#define Scib_dma_write(c)       (*puc_buffer_rx=(c))
#define Scib_dma_read()         (*puc_buffer_tx)



/*_____ D E C L A R A T I O N S ____________________________________________*/


/*V**************************************************************************
* NAME: st_set_parameter_T0
*----------------------------------------------------------------------------
* PURPOSE: 
* This structure contain the description in T=0 a slot card :
* bmFindexDindex = value speed com smart card = TA1 
* bmTCCKST0 = bit 1 : define convention direct or inverse 
* bGuardTimeT0 = value Guart time in T=0
* bWaitingIntegerT0 = value waiting time 
* bClockStop = value status clock stop define for futur use
*****************************************************************************/
typedef struct 
{  
   Uchar bmFindexDindex;
   Uchar bmTCCKST0;
   Uchar bGuardTimeT0;
   Uchar bWaitingIntegerT0;
   Uchar bClockStop;
}st_set_parameter_T0;

/*V**************************************************************************
* NAME: st_set_parameter_T1
*----------------------------------------------------------------------------
* PURPOSE: 
* This structure contain the description in T=1 a slot card :
* bmFindexDindex = value speed com smart card = TA1 
* bmTCCKST1 = bit 1 define convention direct or inverse 
*             bit 0 : type checksum CRC or LRC
* bGuardTimeT1 = value Guart time in T=1
* bmWaitingIntegersT1 = value timeout BWI,CWI 
* bClockStop = value status clock stop define for futur use
* bIFSC = size IFSC 
* bNadValue = Nad Value 
*****************************************************************************/
typedef struct 
{  
   Uchar bmFindexDindex;      /* value speed com smart card = TA1 */
   Uchar bmTCCKST1;           /* bit 1 : define convention direct or inverse */
                              /* bit 0 : type checksum CRC or LRC*/
   Uchar bGuardTimeT1;        /* value Guart time in T=1*/
   Uchar bmWaitingIntegersT1; /* value timeout BWI,CWI */
   Uchar bClockStop;          /* value status clock stop define for futur use*/
   Uchar uc_IFSC;               /* size IFSC */
   Uchar bNadValue;           /* Nad Value */
}st_set_parameter_T1;

/*V**************************************************************************
* NAME: ust_set_parameter
*----------------------------------------------------------------------------
* PURPOSE: 
* This union merge data structure T=0 and T=1
*****************************************************************************/
typedef union 
{  
  st_set_parameter_T0 stT0;
  st_set_parameter_T1 stT1;
}ust_set_parameter;


/*V**************************************************************************
* NAME: scib_st_slot
*----------------------------------------------------------------------------
* PURPOSE: 
* Main description status slot : 
* parameter = parameter card (value speed, timeout,...
* uc_first_exchange = bool firt exchange
* uc_smart_card = status card : card present bit 0 card mouvement bit 1
* uc_voltage = current power voltage smart card 
* u32_CWT = timeout CWT 
*****************************************************************************/
typedef struct scib_st_slot
{
  ust_set_parameter parameter; /* parameter card (value speed, timeout,...*/
  Uchar uc_first_exchange;     /* bool for store firt exchange */
  Uchar  uc_smart_card;        /* status card present and mouvement */
  Uchar  uc_voltage;           /* status current voltage */
  Union32 u32_CWT;             /* timeout CWT */
  Uchar  uc_first_apdu;         /* first exchange apdu */ 
  Uchar  uc_pcb;               /* pcb*/
  Uchar  uc_togglebitRxTx;      
}scib_st_slot;




/*_____ D E C L A R A T I O N S ____________________________________________*/

extern scib_st_slot _MemType_ ast_slot[MAX_NUMBER_SLOT];
extern Uint16 us_slot_debounce;



void scib_atr_config(void);
Uchar scib_test_end_tr(void);
Uchar scib_receive_test(Uchar uc_data_size);
void scib_receive_data(Uchar *uc_data_address, Uchar uc_data_size);
void scib_start_wt(Uint32 dw_timeout);

void scib_send_string_pol(Uchar *uc_data_to_send, Uchar uc_data_length);
void scib_card_init_rx(Uchar * puc_buffer, Uint16 us_size_buffer,Uint32 dw_BWT, Uint32 dw_CWT );
Uchar scib_card_wait_rx(Uint16 us_data_length);
void scib_api_init (void);
void  scib_set_and_wait (Uint32 dw_laps);
Uchar scib_card_send_tx (Uint16 us_size);
Uchar scib_exit_on_error(scib_st_slot * pst_slot);
Uchar scib_seach_byte_atr ( Uchar * puc_atr, Uchar uc_letter, Uchar uc_i_letter);
Uchar nb_byte_in_td (Uchar uc_TDx);
void scib_set_etu_timer (Uint32 dw_laps);
#endif  /* SCIB_API_H */


⌨️ 快捷键说明

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