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

📄 scib_api.c

📁 atmel c5122 USB C51程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*C**************************************************************************
* NAME:         scib_api.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      c5122-scib-usb-hid-2_4_0      
* REVISION:     1.15     
*----------------------------------------------------------------------------
* PURPOSE: 
* This file contains a list of function use by T=0 and T=1 libraty.
* for send and receive data from the card with a dedicate slot
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h"
#include "scib_api.h"
#include "lib_sc/scib_api/scib_api.h"
/*_____ M A C R O S ________________________________________________________*/

/*_____ D E F I N I T I O N S ______________________________________________*/
/*V**************************************************************************
* NAME: ast_slot
*----------------------------------------------------------------------------
* PURPOSE: 
* Array of description slot interface smart card 
* For all scib this structure describe the current status slot (power,
* card present, speed communication,...)
*****************************************************************************/
scib_st_slot _MemType_ ast_slot[MAX_NUMBER_SLOT];

/*V**************************************************************************
* NAME: uc_error
*----------------------------------------------------------------------------
* PURPOSE: 
* status error hard ware uart scib hard, if =0 no error
* this variable is modified by interrupt
*****************************************************************************/
volatile Uchar _MemType_ uc_error;

/*V**************************************************************************
* NAME: uc_transmit
*----------------------------------------------------------------------------
* PURPOSE: 
* Boolean indicate and block scib uart hard this variable is use by interrupt
*****************************************************************************/
volatile Uchar _MemType_ uc_transmit;

/*V**************************************************************************
* NAME: puc_buffer_rx
*----------------------------------------------------------------------------
* PURPOSE: 
* pointer address buffer reception for the uart scib hard (variable use by 
* interrupt)
*****************************************************************************/
volatile Uchar  *  puc_buffer_rx;

/*V**************************************************************************
* NAME: us_size_rx
*----------------------------------------------------------------------------
* PURPOSE: 
* size data received by SCIB hard (variable use by interrupt)
*****************************************************************************/
volatile Uint16 _MemType_ us_size_rx;

/*V**************************************************************************
* NAME: us_size_buffer_rx_max
*----------------------------------------------------------------------------
* PURPOSE: 
* Size max buffer de reception 
*****************************************************************************/
volatile Uint16 _MemType_ us_size_buffer_rx_max;

/*V**************************************************************************
* NAME: puc_buffer_tx
*----------------------------------------------------------------------------
* PURPOSE: 
* pointer address buffer transmission for the SCIB hard (variable use by 
* interrupt)
*****************************************************************************/
volatile Uchar * puc_buffer_tx;

/*V**************************************************************************
* NAME: us_size_tx
*----------------------------------------------------------------------------
* PURPOSE: 
* Size buffer send to the smart card with the SCIB hard
*****************************************************************************/
volatile Uint16 _MemType_ us_size_tx;

/*V**************************************************************************
* NAME: us_slot_debounce
*----------------------------------------------------------------------------
* PURPOSE: 
* Counter for debounce mouvement card in the SCIB hard
*****************************************************************************/
Uint16 _MemType_ us_slot_debounce;

/*V**************************************************************************
* NAME: b_first_byte_ATR
*----------------------------------------------------------------------------
* PURPOSE: 
* tag fist byte in atr
*****************************************************************************/
volatile bit b_first_byte_ATR;

volatile bit b_rx_over_run ;
bit b_lod_bgt ;

extern code st_set_parameter_T0   parameter_T0_default; 
extern code Uchar auc_Di[];




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

/*F**************************************************************************
* NAME: scib_seach_byte_atr
*----------------------------------------------------------------------------
* PARAMS: puc_atr : address start atr
*         uc_letter : number letter 0 for A, 1 for B, 2, for C and 4 for D
*         uc_i_letter : index letter
* return: 0 if letter not exit else index of letter in atr
*----------------------------------------------------------------------------
* PURPOSE: this function seach a byte in the ATR buffer
* 
*----------------------------------------------------------------------------
* EXAMPLE: scib_seach_byte_atr (puc_atr, 1, 2)
*          seach byte TB2 in atr
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Uchar scib_seach_byte_atr ( Uchar * puc_atr, Uchar uc_letter, Uchar  uc_i_letter)
{
  Uchar uc_i_TDx;
  Uchar uc_TDx;
  Uchar uc_nb_letter;
  
  
  uc_nb_letter = 0;
  uc_i_TDx = 0;
  
  if (uc_i_letter!=0)
  { 
    while ((uc_i_letter-1) != uc_i_TDx)
    {
      uc_TDx =	puc_atr [uc_nb_letter +1];
      
      /* if not other TD */
      if ((uc_TDx & 0x80) == 0)
        return 0 ;
      
      uc_nb_letter += nb_byte_in_td (uc_TDx);
      
      uc_i_TDx ++;	
    };
  }
  
  uc_TDx = puc_atr [uc_nb_letter +1];
  
 {
    Uchar uc_lettre_tmp = 0;
    while (uc_lettre_tmp!=uc_letter)
    {
      if (  uc_TDx & (0x10<<uc_lettre_tmp) )
        uc_nb_letter++;           
      uc_lettre_tmp++;
    }    
    if (  uc_TDx & (0x10<<uc_letter) )
    {
      return (uc_nb_letter + 2);
    }
  }
  return 0 ;
}

/*F**************************************************************************
* NAME: scib_api_card_in 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* This function set bit presence card in slot data SCIB hard  
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_api_card_in(void)
{
  ast_slot[0].uc_smart_card |= MASK_CARD_PRESENT;
}


/*F**************************************************************************
* NAME: scib_api_card_out 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* external interrupt 1 function
* This function clear bit present card in slot data SCIB hard and change
* voltage in slot data SCIB hard 
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_api_card_out(void)
{
  ast_slot[0].uc_smart_card &= ~MASK_CARD_PRESENT;
  ast_slot[0].uc_voltage = SC_0_VOLT;
}


/*F**************************************************************************
* NAME: scib_api_card_mvt 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* This function set set bit mouvement card in slot data SCIB hard
* and set the counter debounce uc_slot_debounce at the max  value  
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_api_card_mvt(void)
{
  ast_slot[0].uc_smart_card |= MASK_CARD_MVT;
  us_slot_debounce = MAX_DEBOUNCE;    
}


/*F**************************************************************************
* NAME: scib_api_store_rx_datas 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* This function manage the uart SCIB hard for the Rx 
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS:  IF received 
*****************************************************************************/
void scib_api_store_rx_datas(void)
{

  Scib_dma_write(Scib_getchar());      //*puc_buffer_rx = SCRBUF ;

  /* Store Datas */
  if (++us_size_rx<(us_size_buffer_rx_max))
  {
    puc_buffer_rx ++;      
  }
  else
  {
   // manage overwrite data the 2 lasts byte SW1 SW2 is store
    if (us_size_rx>us_size_buffer_rx_max)
      b_rx_over_run = 1;
  }

}




/*F**************************************************************************
* NAME: scib_api_init
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* initialize variable scib at the default value (slot descriptor)
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: this function is call at the init of module scib
*****************************************************************************/
void scib_api_init (void)
{
  ast_slot[0].parameter.stT0.bmFindexDindex = parameter_T0_default.bmFindexDindex;
  ast_slot[0].parameter.stT0.bmTCCKST0 = parameter_T0_default.bmTCCKST0;
  ast_slot[0].parameter.stT0.bGuardTimeT0 = parameter_T0_default.bGuardTimeT0;
  ast_slot[0].parameter.stT0.bClockStop = parameter_T0_default.bClockStop;
  ast_slot[0].uc_voltage = SC_0_VOLT;

  ast_slot[0].uc_smart_card = MASK_CARD_MVT ;
  /*init the counter for the debouncing*/
  us_slot_debounce = MAX_DEBOUNCE;     
}   




⌨️ 快捷键说明

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