📄 scib_api.c
字号:
/*F**************************************************************************
* NAME: scib_start_wt
*----------------------------------------------------------------------------
* PARAMS: dw_timeout value of time out in etu
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* Start waiting time counter
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void scib_start_wt(Uint32 dw_timeout)
{
/*modify SCWTx registers */
Union32 udw_timeout;
udw_timeout.dw = dw_timeout;
scib_dis_wait_time_count();
scib_store_waiting_time( udw_timeout);
scib_en_wait_time_inter();
uc_error &= ~ MSK_SCIIR_SCWTI;
/*start counter WTEN=1 */
scib_en_wait_time_count();
}
/*F**************************************************************************
* NAME: scib_send_string_pol
*----------------------------------------------------------------------------
* PARAMS: *uc_data_to_send: address of the string to send,
* uc_data_length: length of the string to send
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* Send a string with polling between each byte
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
/*
void scib_send_string_pol(Uchar *uc_data_to_send, Uchar uc_data_length)
{
Uchar index;
//clear SCRS
Scib_clear_SCRS();
for(index=0;index<uc_data_length;index++)
{
SCTBUF = uc_data_to_send[index];
//test SCTC
while(MSK_SCISR_SCTC != (SCISR & MSK_SCISR_SCTC));
//clear SCTC
SCISR &= (~MSK_SCISR_SCTC);
}
}
*/
/*F**************************************************************************
* NAME: scib_card_int_rx
*----------------------------------------------------------------------------
* PARAMS: puc_buffer = address buffer rx ATR
* us_size_buffer = size max ATR
* dw_BWT = timeout first byte
* dw_CWT = timeout inter byte
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* This function initialise the reception data from smart card
* in power up sequence, This function initialise time the BWT and CWT for ATR
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void scib_card_init_rx( Uchar * puc_buffer, Uint16 us_size_buffer,
Uint32 dw_BWT, Uint32 dw_CWT )
{
Union32 udw_timeout;
/* init Rx variable for interrupt Rx */
us_size_rx = 0;
puc_buffer_rx = puc_buffer ;
scib_en_receiver_inter ();
/* set timeout for reception first byte smart card */
scib_dis_wait_time_count ();
scib_start_wt (dw_BWT);
/* Set mode UART */
Scib_set_SCRS();
//SCICR |= MSK_SCICR_UART;
scib_set_or_scicr(MSK_SCICR_UART);
us_size_buffer_rx_max = us_size_buffer;
/* load a new timeout CWT for other byte recept*/
ast_slot[0].u32_CWT.dw=dw_CWT;
udw_timeout.dw = dw_CWT;
scib_store_waiting_time( udw_timeout);
}
/*F**************************************************************************
* NAME: scib_card_wait_rx
*----------------------------------------------------------------------------
* PARAMS: us_data_length: length of the string receive of the smart card
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* This function wait reception of us_data_length bytes or a error (timeout,.)
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function check the global variable uc_error for stop the wait RX
* or the global variable us_size_rx this variable is update by interrupt SCIB
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Uchar scib_card_wait_rx(Uint16 us_data_length)
{
while ((us_size_rx<us_data_length) && (!(uc_error )));
if (uc_error)
return (KO);
return (OK);
}
/*F**************************************************************************
* NAME: nb_byte_in_td
*----------------------------------------------------------------------------
* PARAMS: uc_TDx : byte TD of ATR
* return: number byte anounced in TD byte
*----------------------------------------------------------------------------
* PURPOSE:
* This function compute the number of byte announced in the byte TDx
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
****************************************************************************/
Uchar nb_byte_in_td (Uchar uc_TDx)
{
Uchar uc_i;
Uchar uc_msk_bit;
Uchar nb_byte;
nb_byte = 0;
uc_msk_bit =0x10 ;
for ( uc_i=0 ; uc_i<4 ; uc_i++ )
{
if (( uc_TDx & uc_msk_bit) != 0)
nb_byte ++;
uc_msk_bit <<=1;
}
return nb_byte;
}
/*F**************************************************************************
* NAME: scib_wait
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
* This function wait a interrupt SCIB timeout
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void scib_wait (void)
{
while ( ( uc_error & (MSK_SCISR_CARDIN | MSK_SCIIR_SCWTI)) == 0);
}
/*F**************************************************************************
* NAME: scib_set_etu_timer
*----------------------------------------------------------------------------
* PARAMS: dw_laps laps a waiting time in etu with etu = DEFAULT_ETU
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
*
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void scib_set_etu_timer (Uint32 dw_laps)
{
Scib_set_and_ien1(~MSK_IEN1_ESCI);
scib_dis_wait_time_count ();
scib_start_wt (dw_laps);
}
/*F**************************************************************************
* NAME: scib_set_and_wait
*----------------------------------------------------------------------------
* PARAMS: dw_laps laps a waiting time in etu with etu = DEFAULT_ETU
* return: none
*----------------------------------------------------------------------------
* PURPOSE:
*
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void scib_set_and_wait (Uint32 dw_laps)
{
scib_set_etu_timer (dw_laps);
scib_wait ();
uc_error &= ~MSK_SCIIR_SCWTI;
}
/*F**************************************************************************
* NAME: scib_card_send_tx
*----------------------------------------------------------------------------
* PARAMS: uc_size size data send
* return: O if OK
*----------------------------------------------------------------------------
* PURPOSE:
* This function send data to the smart card and wait the end of tx.
* The function start the timeout BWT/CWT if SCIB error is detect then exit
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function check the global variable use by interrupt (uc_error,
* us_size_tx)
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Uchar scib_card_send_tx (Uint16 us_size)
{
Uchar uc_first_byte;
uc_transmit = 0;
us_size_tx = us_size;
us_size_tx --;
uc_first_byte = * puc_buffer_tx ++;
Scib_set_SCRS();
/* if 1 byte */
if (us_size==1)
{
Scib_enable_it_transmit_buffer();
Scib_disable_it_empty_buffer();
/*start counter WTEN=1 */
scib_en_wait_time_count();
}
else
{
Scib_enable_it_empty_buffer();
Scib_disable_it_transmit_buffer();
}
// Send First Byte
Scib_clear_SCRS();
Scib_putchar(uc_first_byte); // SCTBUF = uc_first_byte;
/* wait end tx for start timeout CWT */
while ((uc_transmit == 0) && (uc_error==0));
return uc_error;
}
/*_____ E N D O F F I L E _________________________________________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -