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

📄 scib_lib.c

📁 atmel c5122 USB C51程序
💻 C
📖 第 1 页 / 共 4 页
字号:
#else
  /*CPU_CLOCK = 8MHz, CP_PLL = 96MHz, CK_ISO = 96/(2*(48-36)) = 4MHz*/
  SCICLK = clk;
#endif

}

/*F**************************************************************************
* NAME: scib_hw_init_card_det  
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* init the card detection with the external IRQ1
*****************************************************************************
* NOTE: 
*****************************************************************************/
void scib_hw_init_card_det()
{
  /*set CPLEV*/
  ISEL |= (MSK_ISEL_CPLEV); 

  EX1=1;
  ISEL |= MSK_ISEL_PRESEN;

  // Macro Waiting time
  SCSR &= ~0x20;
}



/*F**************************************************************************
* NAME: scib_hw_set_etu 
*----------------------------------------------------------------------------
* PARAMS: uc_FiDi: Di (LSB 3-0)
* 						 Fi (MSB 7-4)
* return: TRUE if speed authorized
*			 FALSE if speep not authorized
*----------------------------------------------------------------------------
* PURPOSE: 
* configuration of the smard card clock
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: this function set SCETU0,SCETU1, COMP register
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Uchar scib_hw_set_etu(Uchar uc_FiDi)
{
  Uchar uc_Di;
  Uint16 us_Fi;
  Union16 us_etu;

  uc_Di = auc_Di[uc_FiDi & 0x0F];

  if (!uc_Di)
    return ERR_UNKNOW;

  us_Fi = aus_Fi[uc_FiDi>>4];
  if (!us_Fi)
      return ERR_UNKNOW;

  us_etu.w = (Uint16)( us_Fi / uc_Di);
   
#ifdef APDU_MODE  
  if (us_etu.w< MAX_SPEED_Fi_Di)
      return ERR_UNKNOW;  
#endif  

  Scib_hw_set_SCRS();
  SCETU0 = us_etu.b[1];

  /* Sets ETU registers bits 7-0*/
  /*set only bits ETU10 ETU9 ETU8 (not COMP) */
  SCETU1 = us_etu.b[0] & (~MSK_SCETU1_COMP);

  if ( (us_Fi%uc_Di) >  (uc_Di/2) )
    SCETU1 |= MSK_SCETU1_COMP;

  


  return 0 ;
}

/*F**************************************************************************
* NAME: scib_hw_store_guard_time 
*----------------------------------------------------------------------------
* PARAMS: uc_gt0: SCGT0 (guard time LSB 7-0)
*  uc_gt1: SCGT1 (guard time MSB 8)
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* configuration of the smard card guard time
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_store_guard_time(Union16 gt)
{
  Scib_hw_set_SCRS();

  /* Sets GUARD TIME registers */
  SCGT0 = gt.b[1];
  SCGT1 = gt.b[0];
}

/*F**************************************************************************
* NAME: scib_hw_store_waiting_time 
*----------------------------------------------------------------------------
* PARAMS: udw_timeout: SCWT0 register, LSB 7-0
*  udw_timeout: SCWT1 register, LSB 15-8
*  udw_timeout: SCWT2 register, LSB 23-16 
*  udw_timeout: SCWT3 register, LSB 31-24 
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* configuration of the smard card waiting time
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_store_waiting_time(Union32 udw_timeout)
{
   Scib_hw_clear_SCRS();

   /* Sets WAITING TIME registers */
   SCWT0 = udw_timeout.b[3];
   SCWT1 = udw_timeout.b[2];
   SCWT3 = udw_timeout.b[0];
   SCWT2 = udw_timeout.b[1];
}

/*F**************************************************************************
* NAME: scib_test_scri 
*----------------------------------------------------------------------------
* PARAMS: none
* return: TRUE	if UART completes a character reception
* FALSE	cleared by hardware   
*----------------------------------------------------------------------------
* PURPOSE: 
* test of SCRI bit (smart card receive interrupt)
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Uchar scib_hw_test_scri(void)
{
  Scib_hw_clear_SCRS();
  if((SCIIR & MSK_SCIIR_SCRI) == MSK_SCIIR_SCRI)
    return (TRUE);
  else
    return (FALSE);
}

/*F**************************************************************************
* NAME: scib_hw_test_scti 
*----------------------------------------------------------------------------
* PARAMS: none
* return: TRUE if  SCTI = 1
*         FALSE if SCTI = 0  
*----------------------------------------------------------------------------
* PURPOSE: 
* return the value of the bit SCTI in SCIIR register  
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Uchar scib_hw_test_scti(void)
{
  Scib_hw_clear_SCRS();
  if((SCIIR & MSK_SCIIR_SCTI) == MSK_SCIIR_SCTI)
    return (TRUE);
  else
    return (FALSE);
}

/*F**************************************************************************
* NAME: scib_hw_test_scpe 
*----------------------------------------------------------------------------
* PARAMS: none
* return: TRUE if  SCTI = 1
*         FALSE if SCTI = 0  
*----------------------------------------------------------------------------
* PURPOSE: 
* return the value of the bit SCTI in SCIIR register  
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Uchar scib_hw_test_scpe(void)
{
  Scib_hw_clear_SCRS(); 
  return (SCISR & MSK_SCISR_SCPE);
}

/*F**************************************************************************
* NAME: scib_hw_cardvcc_off 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* reset the bit CARDVCC in SCCON  
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_cardvcc_off(void)
{
  Scib_hw_clear_SCRS();
  SCCON &=(~MSK_SCCON_CARDVCC);
}

/*F**************************************************************************
* NAME: scib_hw_cardvcc_on 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* set the bit CARDVCC in SCCON
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_cardvcc_on(void)
{
  Scib_hw_clear_SCRS();
  SCCON |= MSK_SCCON_CARDVCC;
}

/*F**************************************************************************
* NAME: scib_hw_cardvcc_on 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* set the bit CARDVCC in SCCON
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_volt_config(Uchar uc_voltage)
{
  Scib_hw_set_SCRS();

  /* select power voltage */
  SCICR &= ~ (MSK_SCICR_VCARD1|MSK_SCICR_VCARD0);
  SCICR |= uc_voltage;
}

/*F**************************************************************************
* NAME: scib_hw_cardrst_on 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* set the bit CARDRST in SCCON
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_cardrst_on(void)
{
  Scib_hw_clear_SCRS();
  SCCON |= MSK_SCCON_CARDRST;
}

/*F**************************************************************************
* NAME: scib_hw_cardrst_off 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* reset the bit CARDRST in SCCON
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_cardrst_off(void)
{
  Scib_hw_clear_SCRS();
  SCCON &= (~MSK_SCCON_CARDRST);
}

/*F**************************************************************************
* NAME: scib_hw_cardclk_on 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* set the bit CLK in SCCON
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_cardclk_on(void)
{
  Scib_hw_clear_SCRS();
  SCCON |= (MSK_SCCON_CLK);

⌨️ 快捷键说明

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