- while (1)
- {
- if(SDCARD_change)
- {
- SDCARD_change = 0;
- GPIO_SetBits(GPIOB, GPIO_Pin_5);
- //SD卡插入 下降沿 即卡被插入
- if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7) == 0)
- {
- if( rt_device_find("sd0") == RT_NULL)//未加载SD0
- {
- count = sd_remount();
- if(count && rt_device_find("sd0") != RT_NULL)
- {
- // GPIO_SetBits(GPIOB, GPIO_Pin_5);
- USB_sdcard();
- Max_Lun = 1;
- // USB_cable();
- if(dfs_mount("sd0", "/sd", "elm", 0, 0) == 0)
- {
- rt_kprintf("SDCARD mount!\n");
- }
- GPIO_ResetBits(GPIOB, GPIO_Pin_5);
- }
- }
- }//SD卡插入 上升沿 即卡被拔出
- else
- {
- dev = rt_device_find("sd0");
- if(dev != RT_NULL)
- {
- GPIO_SetBits(GPIOB, GPIO_Pin_5);
- dfs_unmount("/sd");
- rt_device_unregister(dev);
- //GPIO_SetBits(GPIOC,GPIO_Pin_6); /* SD card power down */
- Max_Lun = 0;
- rt_kprintf("SDCARD unmount!\n");
- }
- }
- GPIO_ResetBits(GPIOB, GPIO_Pin_5);
- }
- }