Changeset 34 for trunk/firmware/App/SES/Core/Tasks
- Timestamp:
- Oct 15, 2026, 2:21:26 PM (3 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/firmware/App/SES/Core/Tasks/Src/sdmmcTask.cpp
r33 r34 12 12 #endif 13 13 14 enum class SdCardState 15 { 16 NotPresent, 17 Inserted, 18 Initialized, 19 Deinitialized, 20 Error 21 }; 22 23 constexpr unsigned SD_PRESENCE_SCAN_RATE_ms = 50U; 14 24 constexpr unsigned MEDIA_CLOSED = 1U; 15 25 constexpr unsigned MEDIA_OPENED = 0U; … … 19 29 FX_MEDIA sdio_disk; // Define FileX global data structures 20 30 static UINT media_status; 31 static SdCardState sdCurrentState = SdCardState::NotPresent; 32 static SdCardState sdLastState = SdCardState::NotPresent; 21 33 22 34 23 35 void StartSDMMCTask(void* arg) 24 36 { 25 UINT sd_status = FX_SUCCESS; 37 static int insertionDetectionCnt, extractionDetectionCnt; 38 39 while(1) 40 { 41 switch(sdCurrentState) 42 { 43 case SdCardState::NotPresent: 44 if (HAL_GPIO_ReadPin(SD_PRESENCE_GPIO_Port, SD_PRESENCE_Pin) == SD_PRESENT) 45 { 46 extractionDetectionCnt = 0; 47 if (insertionDetectionCnt > (1000U / SD_PRESENCE_SCAN_RATE_ms)) 48 { // Here we can be sure that SD-card is really present 49 if (sdLastState == SdCardState::NotPresent) 50 { 51 sdLastState = sdCurrentState = SdCardState::Inserted; 52 printf("SD-card was inserted\n"); 53 } 54 } 55 else 56 ++insertionDetectionCnt; 57 } 58 else 59 { 60 insertionDetectionCnt = 0; 61 printf("SD-card extraction detected\n"); 62 } 63 break; 64 65 case SdCardState::Inserted: 66 if (HAL_GPIO_ReadPin(SD_PRESENCE_GPIO_Port, SD_PRESENCE_Pin) == SD_NOT_PRESENT) 67 { 68 extractionDetectionCnt = 0; 69 if (insertionDetectionCnt > (1000U / SD_PRESENCE_SCAN_RATE_ms)) 70 { // Here we can be sure that SD-card is really present 71 if (sdLastState == SdCardState::NotPresent) 72 { 73 sdLastState = sdCurrentState = SdCardState::Inserted; 74 printf("SD-card was inserted\n"); 75 } 76 } 77 else 78 ++insertionDetectionCnt; 79 } 80 else 81 { 82 insertionDetectionCnt = 0; 83 printf("SD-card extraction detected\n"); 84 } 85 break; 86 87 case SdCardState::Initialized: 88 break; 89 90 case SdCardState::Deinitialized: 91 break; 92 93 case SdCardState::Error: 94 break; 95 } 96 osDelay(SD_PRESENCE_SCAN_RATE_ms); 97 } 98 99 /*UINT sd_status = FX_SUCCESS; 26 100 fx_system_initialize(); // Initialize FileX 27 101 … … 36 110 { 37 111 Error_Handler(); 38 } 112 }*/ 39 113 40 114 41 115 while(1) 42 116 { 43 HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);44 117 osDelay(1000U); 45 printf("Programm is running at %u MHz\n", SystemCoreClock / 1000000U);46 47 118 } 48 119 }
Note:
See TracChangeset
for help on using the changeset viewer.
