Ejemplo n.º 1
0
Archivo: main.c Proyecto: dazuo78/TBall
/**
  * @brief EXTI line detection callbacks
  * @param GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == SC_OFF_PIN)
  {
    /* Toggle LED2..4 */
    BSP_LED_Toggle(LED2);
    BSP_LED_Toggle(LED3);
    BSP_LED_Toggle(LED4);
    
    if (CardInserted == 0)
    {
      /* Smartcard detected */
      CardInserted = 1;
    
      /* Enable CMDVCC */
      SC_PowerCmd(ENABLE);
      
      /* Reset the card */
      SC_Reset(GPIO_PIN_RESET);
    }
    else
    {
      /* Smartcard removed */
      CardInserted = 0;

      /* Enable CMDVCC */
      SC_PowerCmd(DISABLE);
    }
  }
  else
  {
    /* Smartcard removed */
    CardInserted = 0;
  }
}
Ejemplo n.º 2
0
/**
  * @brief  This function handles External lines 9 to 5 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI9_5_IRQHandler(void)
{
  if(Get_SmartCardStatus() == 0)
  { 
    if(EXTI_GetITStatus(EXTI_Line8) != RESET)
    {
      /* Clear the EXTI Line 8 */  
      EXTI_ClearITPendingBit(EXTI_Line8);
    }
    if(EXTI_GetITStatus(EXTI_Line7) != RESET)
    {
      /* SEL function */
      Set_SELStatus();
      /* Clear the EXTI Line 7 */  
      EXTI_ClearITPendingBit(EXTI_Line7);
    }
  }
  else if(Get_SmartCardStatus() == 1)
  {
    if(EXTI_GetITStatus(SC_EXTI) != RESET)
    {
      /* Clear SC EXTIT Line Pending Bit */
      EXTI_ClearITPendingBit(SC_EXTI);

      /* Smartcard detected */
      Set_CardInserted();

      /* Power ON the card */
      SC_PowerCmd(ENABLE);

      /* Reset the card */
      SC_Reset(Bit_RESET);
    }
  }
  if(EXTI_GetITStatus(EXTI_Line8) != RESET)
  {
    /* Clear the EXTI Line 8 */
    EXTI_ClearITPendingBit(EXTI_Line8);
  }
}
Ejemplo n.º 3
0
/**
  * @brief  This function handles the smartcard detection interrupt request.
  * @param  None
  * @retval None
  */
void SC_OFF_EXTI_IRQHandler(void)
{
  if(EXTI_GetITStatus(SC_OFF_EXTI_LINE) != RESET)
  {
    /* Clear EXTI Line Pending Bit */
    EXTI_ClearITPendingBit(SC_OFF_EXTI_LINE);

    /* Toggle LED1..4 */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);
    
    /* Smartcard detected */
    CardInserted = 1;

    /* Enable CMDVCC */
    SC_PowerCmd(ENABLE);

    /* Reset the card */
    SC_Reset(Bit_RESET);
  }
}
Ejemplo n.º 4
0
Archivo: sc_itf.c Proyecto: caozoux/arm
/**
  * @brief  Configure the CMDVCC state for right detection of Card Insertion
  * @param  None 
  * @retval None
  */
void SC_ConfigDetection (void)
{
  EXTI_InitTypeDef EXTI_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable GPIO clock */
  RCC_AHBPeriphClockCmd(SC_OFF_GPIO_CLK | SC_CMDVCC_GPIO_CLK | 
                        SC_3_5V_GPIO_CLK | SC_RESET_GPIO_CLK, ENABLE);

  /* Enable SYSCFG clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  /* Configure Smartcard CMDVCC pin */
  GPIO_InitStructure.GPIO_Pin = SC_CMDVCC_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(SC_CMDVCC_GPIO_PORT, &GPIO_InitStructure);

  /* Configure Smartcard Reset pin */
  GPIO_InitStructure.GPIO_Pin = SC_RESET_PIN;
  GPIO_Init(SC_RESET_GPIO_PORT, &GPIO_InitStructure);

  /* Configure Smartcard 3/5V pin */
  GPIO_InitStructure.GPIO_Pin = SC_3_5V_PIN;
  GPIO_Init(SC_3_5V_GPIO_PORT, &GPIO_InitStructure);

  /* Select 5V */ 
  SC_VoltageConfig(SC_VOLTAGE_5V);

  /* Disable CMDVCC */
  SC_PowerCmd(DISABLE);

  /* Set RSTIN HIGH */  
  SC_Reset(Bit_SET);
    						                                
  /* Configure Smartcard OFF pin */
  GPIO_InitStructure.GPIO_Pin = SC_OFF_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(SC_OFF_GPIO_PORT, &GPIO_InitStructure);
  
  /* Configure EXTI line connected to Smartcard OFF Pin */
  SYSCFG_EXTILineConfig(SC_OFF_EXTI_PORT_SOURCE, SC_OFF_EXTI_PIN_SOURCE);

  EXTI_ClearITPendingBit(SC_OFF_EXTI_LINE);
  
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_Line = SC_OFF_EXTI_LINE;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

  /* Clear the SC_OFF_EXTI_IRQn Pending Bit */
  NVIC_ClearPendingIRQ(SC_OFF_EXTI_IRQn);
  NVIC_InitStructure.NVIC_IRQChannel = SC_OFF_EXTI_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure); 
    
}