From e91d1ed0bddf58059680fadb5113aa08374fa38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 14 Jan 2020 21:26:58 +0100 Subject: [PATCH] start reworking driver to preferred code style --- .gitignore | 8 +++++++ fatfs/shimatta_sdio_driver/shimatta_sdio.c | 27 ++++++++++++---------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index b1bb22d..72cdc63 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,11 @@ Debug *.user.* *.lss *.d +stm32f4-sdio.cflags +stm32f4-sdio.config +stm32f4-sdio.creator +stm32f4-sdio.cxxflags +stm32f4-sdio.files +stm32f4-sdio.includes + + diff --git a/fatfs/shimatta_sdio_driver/shimatta_sdio.c b/fatfs/shimatta_sdio_driver/shimatta_sdio.c index 218011c..288fa34 100644 --- a/fatfs/shimatta_sdio_driver/shimatta_sdio.c +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio.c @@ -80,7 +80,6 @@ volatile uint32_t debug_timeout; volatile int debug_acmd = 0; DSTATUS SDIO_initialize(){ int timeout = 0x3000; - int i; CMD8_RESP_t res8; ACMD41_RESP_t resa41; uint8_t hcs_flag = 0; @@ -383,20 +382,24 @@ void SDIO_wait_cmd_sent() { SDIO->ICR |= SDIO_ICR_CMDSENTC; } -int /*__attribute__((noinline)) __attribute__((optimize("O0")))*/ SDIO_get_response(uint8_t expectedCMD, uint8_t typeOfAns, uint32_t *responseBuffer) { +int SDIO_get_response(uint8_t expected_command, uint8_t type_of_answer, uint32_t *response_buffer) { uint32_t sdio_status; /* Wait until command isn't active anymore */ while (SDIO->STA & SDIO_STA_CMDACT); - //Wait for error or success + + /* Wait for error or success */ while (1) { sdio_status = SDIO->STA; - if (sdio_status & SDIO_STA_CMDREND) break; //Correct Respone Received - if ((sdio_status & SDIO_STA_CMDSENT) && (typeOfAns == NO_ANS)) break; // No response required + + /* Check if a valid response was received */ + if (sdio_status & SDIO_STA_CMDREND) + break; + if ((sdio_status & SDIO_STA_CMDSENT) && (type_of_answer == NO_ANS)) break; // No response required //Exclude ACMD41 and CMD2 from valid CRC check if ((sdio_status & SDIO_STA_CCRCFAIL)) { - if(expectedCMD == 0xff) { + if(expected_command == 0xff) { break; } else { return -CCRCFAIL; @@ -408,16 +411,16 @@ int /*__attribute__((noinline)) __attribute__((optimize("O0")))*/ SDIO_get_respo return -CTIMEOUT; } //Valid Respone Received - if (((SDIO->RESPCMD & SDIO_RESPCMD_RESPCMD) != expectedCMD) && (expectedCMD != 0xff)) + if (((SDIO->RESPCMD & SDIO_RESPCMD_RESPCMD) != expected_command) && (expected_command != 0xff)) return -CNOTEXPETED; //Not the expected respose //If case of a correct Response - *(responseBuffer++) = SDIO->RESP1; + *(response_buffer++) = SDIO->RESP1; //Long response. - if (typeOfAns == LONG_ANS) { - *(responseBuffer++) = SDIO->RESP2; - *(responseBuffer++) = SDIO->RESP3; - *(responseBuffer++) = SDIO->RESP4; + if (type_of_answer == LONG_ANS) { + *(response_buffer++) = SDIO->RESP2; + *(response_buffer++) = SDIO->RESP3; + *(response_buffer++) = SDIO->RESP4; } return 0;