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

📄 scib_lib.c

📁 atmel c5122 USB C51程序
💻 C
📖 第 1 页 / 共 4 页
字号:
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_disable_parity_error()
{
  Scib_hw_set_SCRS();
  SCIER &= ~ MSK_SCIER_ESCPI;
}

/*F**************************************************************************
* NAME: scib_hw_direct_conv 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
* reset the bit convention
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_direct_conv()
{
  /*DIRECT CONVENTION*/
  Scib_hw_set_SCRS();
  SCICR &= (~MSK_SCICR_CONV);
}



/*F**************************************************************************
* NAME: scib_hw_inverse_conv 
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
*  sets the bit convention
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_inverse_conv()
{
  /*INVERSE CONVENTION*/
  Scib_hw_set_SCRS();
  SCICR |= MSK_SCICR_CONV; 
}

/*F**************************************************************************
* NAME: scib_hw_set_conv
*----------------------------------------------------------------------------
* PARAMS: convention 0 = direct, 1 = inverse
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
*  sets the bit convention
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_set_conv(Uchar uc_conv)
{
   if (uc_conv & 0x2)  
      scib_inverse_conv();
   else
      scib_direct_conv();
}

/*F**************************************************************************
* NAME: scib_hw_reset_uart
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
*  this function clear and set the UART mode for reset Tx, Rx after timeout
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void scib_hw_reset_uart (void)
{
  Scib_hw_set_SCRS();  
  SCICR &= ~ MSK_SCICR_UART;
  SCICR &= (~MSK_SCICR_WTEN);
  SCICR |= MSK_SCICR_UART;

}



/*F**************************************************************************
* NAME: scib_hw_atr_config 
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
* PARAMS:  
*----------------------------------------------------------------------------
* PURPOSE: 
* after a reset detection, this function configures the
* reader to receive the ATR (Answer To Reset) 
*****************************************************************************
* NOTE: This is an old function. Do not use this function.
*****************************************************************************/
void scib_hw_atr_config(void)
{
  Scib_set_SCRS();
  SCICR = (MSK_SCICR_VCARD0 | MSK_SCICR_VCARD1); //(MSK_SCICR_CREP|MSK_SCICR_CONV); /* bit3=UART=1 -> driven by smart card UART , bits4 &5 : Vacrd=5V */
 
  scib_hw_cardvcc_on();

  /*WAIT VCARDOK = 1 on silicium*/
  Scib_clear_SCRS();

  while(MSK_SCISR_VCARDOK == (SCISR & MSK_SCISR_VCARDOK));

  Scib_set_SCRS();
  SCICR |= MSK_SCICR_UART;

  scib_hw_cardio_on(); 

  scib_hw_cardclk_on();
}


#ifdef SCIB_USE_TIMER1
/*F**************************************************************************
* NAME: stop_timer1_etu
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
*  This function stop the timer 1 in etu
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void stop_timer1_etu(void)
{
  // stop timer 1 if it is already running
  TR1 = 0;
}

/*F**************************************************************************
* NAME: start_timer1_etu
*----------------------------------------------------------------------------
* PARAMS: none
* return: none
*----------------------------------------------------------------------------
* PURPOSE: 
*  This function start the timer 1 in etu
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
void start_timer1_etu(Uint16 us_laps_etu)
{
  Uint32 ul_laps_us;
  Uint32 ul_laps_t1;
  Uint16 us_counter_timer_end;

  //compute laps in micro sec
  ul_laps_us = (Uint32)us_laps_etu * (Uint32)DEFAULT_ETU;

  //compute T1 laps in micro sec
  ul_laps_t1 = (Uint32)((6000 * 65536)/FCLK_TIMER);

  //compute loop overflow
  us_timer_count = (Uint16)(ul_laps_us / ul_laps_t1);

  //compute last in micro sec
  us_counter_timer_end  = (Uint16)((Uint32)ul_laps_us % (Uint32)ul_laps_t1);

  //compute last for register
  u16_timer_last_count.w = (Uint16)(65536 - (Uint16)((Uint32)((Uint32)us_counter_timer_end * (Uint32)FCLK_TIMER)/(Uint32)6000 ));

  //initialise timer 1
  if (us_timer_count)
  {
    TL1 = 0;
    TH1 = 0;
  }
  else
  {
    TL1 = u16_timer_last_count.b[1] ;
    TH1 = u16_timer_last_count.b[0] ;
  }
// clear all timer1 
  TMOD &= 0x0f;
  // select timer1 mode 1 and options
  TMOD |= 0x10;

  //Set_timer1_x1_mode(); // timer1 always in x1 mode, even if x2 mode is set for std clk.
  TR1=1;
  ET1=1;
}


/*F**************************************************************************
* NAME: Timer0_interrupt
*----------------------------------------------------------------------------
* PARAMS:
* return:   none
*----------------------------------------------------------------------------
* PURPOSE: 
* This function is the interrupt program for the timer 1.
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
Interrupt (void Timer1_interrupt(void),IRQ_T1)
{
  // stop timer 1
  TR1=0;
  if (us_timer_count==0xFFFF)
  {
    /* disable IT RX,TX,Timeout*/
    Scib_hw_set_SCRS();
    SCIER &= ~ (MSK_SCIER_ESCTI | MSK_SCIER_ESCTBI | MSK_SCIER_ESCWT | MSK_SCIER_ESCRI) ;
    Scib_hw_set_status_error(MSK_SCIIR_SCWTI);

  }
  else 
  {
    us_timer_count--;
    if (!(us_timer_count))
    {
      // reload for the last IT
      TL1 = u16_timer_last_count.b[1] ;
      TH1 = u16_timer_last_count.b[0] ; 
    }
    //Set_timer1_x1_mode(); // timer1 always in x1 mode, even if x2 mode is set for std clk.
    TR1=1;
    ET1=1;
  }
}
#endif
 


#ifdef DCDC_INIT_PROCEDURE
/*F**************************************************************************
* NAME: scib_hw_start_dcdc
*----------------------------------------------------------------------------
* PARAMS: none
* return: OK if VCARD OK and DC/DC initialization procedure OK
*         KO        
*----------------------------------------------------------------------------
* PURPOSE: 
*  
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE: 
*----------------------------------------------------------------------------
* REQUIREMENTS: 
*****************************************************************************/
bit scib_hw_start_dcdc(void)
{
  Byte boost= 0x00;
  scib_hw_cardclk_off();
  scib_hw_cardrst_off(); 
  scib_hw_cardvcc_on();                 /*set the bit CARDVCC in SCCON*/

  // MODE bit management
  // reset MODE bit: regul mode 
  DCCKPS |= 0x80;

  // Check CVCC voltage 
  Scib_hw_set_SCRS();

  // check if self or not
  #ifndef DCDC_NOSELF
  if(SC_5_VOLT == (SCICR & SC_5_VOLT))
  {
    // set MODE bit: pump mode 
    DCCKPS &= 0x7F;
  }
  #endif

  do
  {
    Scib_hw_clear_and_scicr(~MSK_SCICR_UART);
    DCCKPS &= ~MSK_DCCKPS_BOOST;        /* set BOST[1:0] to 00 = normal,not necessary here?*/
    DCCKPS |= (boost << 4);             /*increment BOOST*/
    
    scib_set_etu_timer (SCIB_3_MS);     /*set 3ms timeout */
    do
    {
      if ( scib_hw_vcard_ok() && scib_hw_card_there() ) 
      {
        DCCKPS &= ~MSK_DCCKPS_BOOST;    /* set BOST[1:0] to 00 = normal */
        scib_dis_wait_time_count();
        Scib_hw_clear_status_error(MSK_SCIIR_SCWTI);//uc_error &= ~ MSK_SCIIR_SCWTI;          
        return OK;                      /*if VCARD_OK then return OK*/
      }
    }while (!scib_hw_vcard_ok() && (  uc_error == 0));   //else if VCARD KO and 3MS timeout expired
    scib_dis_wait_time_count();
    uc_error &= ~ MSK_SCIIR_SCWTI;
    
  }while (boost++ < 3 );

  scib_set_and_wait (SCIB_100_MS);      /* For EMV 100MS for VCARD OK, warning : DC/DC init proc  *
                                         * can be 3*3MS=10MS max, wich can be a problem.          */
  if ( scib_hw_vcard_ok() && scib_hw_card_there() ) 
  {
    DCCKPS &= ~MSK_DCCKPS_BOOST;        /* set BOST[1:0] to 00 = normal */
    scib_dis_wait_time_count();
    Scib_hw_clear_status_error(MSK_SCIIR_SCWTI);//uc_error &= ~ MSK_SCIIR_SCWTI;        
    return OK;                          /*if VCARD_OK then return OK*/
  }
  return KO;                            /* else DC/DC converter initialization failure */
}
#endif

⌨️ 快捷键说明

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