SD卡防抖


unsigned long start_time;
unsigned long end_time;
BOOL_T bCurrSDINPlugStatus = TRUE;
BOOL_T bCurrSDOUTPlugStatus = TRUE;

#define SDMMC_in_timeout 500
#define SDMMC_out_timeout 100

static vod ms_sdmmc_hotplug(unsigned long data)
{
 struct ms_sdmmc_slot *p_sdmmc_slot = (struct ms_sdmmc_slot *)data;
 SlotEmType eSlot = (SlotEmType)p_sdmmc_slot->slotNo;
 IPEmType eIP = get_IPSlot[eSlot];
 
 if (_GetCardDetect(eSlot)) // insert SD card
 {
  bCurrSDOUTPlugStatus  = TRUE;
  end_time = 0;
  if(start_time = SDMMC_in_timeout)
  {
   start_time ++ ;
   if (bCurrSDINPlugStatus)
   {
    mmc_detect_change(p_sdmmc_slot->mmc,msecs_to_jiffies(500));
    HAL_CARD_SetGPIOIntAttr();
   }
  }else
  {
   start_time ++;
  }
 }else  //remove sd card
 {
  start_time = 0;
  bCurrSDINPlugStatus = TRUE;
  if (end_time = SDMMC_out_timeout)
  {
   end_time ++;
   if (bCurrSDOUTPlugStatus)
   {
    bCurrSDOUTPlugStatus = FALSE;
    if (p_sdmmc_slot->mmc->card)
     mmc_card_set_removed(p_sdmmc_slot->mmc->sdcard);
    HAL_CARD_SetGPIOIntAttr();
   }
  }else if (end_time < SDMMC_out_timeout)
  {
   end_time ++;
  }
 }
 mdelay(1);
 
 if (!gb_ShareCDZIRQSlot[eSlot])
  enable_irq(p_sdmmc_slot->cdzIRQNo);
 
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章