]> granicus.if.org Git - esp-idf/commitdiff
sdspi: handle delayed R1 responses for data read commands
authorIvan Grokhotkov <ivan@espressif.com>
Thu, 8 Feb 2018 17:57:48 +0000 (01:57 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Fri, 30 Mar 2018 10:49:42 +0000 (18:49 +0800)
components/driver/sdspi_host.c

index 74cc24c2440423973fbcfa63807846c4501dc2a4..ef8d62770346a2153f3da5dd511b4b9076b8b061 100644 (file)
@@ -575,8 +575,9 @@ static esp_err_t start_command_read_blocks(int slot, sdspi_hw_cmd_t *cmd,
 {\r
     bool need_stop_command = rx_length > SDSPI_MAX_DATA_LEN;\r
     spi_transaction_t* t_command = get_transaction(slot);\r
+    const int cmd_extra_bytes = 8;\r
     *t_command = (spi_transaction_t) {\r
-        .length = (SDSPI_CMD_R1_SIZE + 8) * 8,\r
+        .length = (SDSPI_CMD_R1_SIZE + cmd_extra_bytes) * 8,\r
         .tx_buffer = cmd,\r
         .rx_buffer = cmd,\r
     };\r
@@ -587,9 +588,21 @@ static esp_err_t start_command_read_blocks(int slot, sdspi_hw_cmd_t *cmd,
     release_transaction(slot);\r
 \r
     uint8_t* cmd_u8 = (uint8_t*) cmd;\r
-    size_t pre_scan_data_size = 8;\r
+    size_t pre_scan_data_size = cmd_extra_bytes;\r
     uint8_t* pre_scan_data_ptr = cmd_u8 + SDSPI_CMD_R1_SIZE;\r
 \r
+    /* R1 response is delayed by 1-8 bytes from the request.\r
+     * This loop searches for the response and writes it to cmd->r1.\r
+     */\r
+    while ((cmd->r1 & SD_SPI_R1_NO_RESPONSE) != 0 && pre_scan_data_size > 0) {\r
+        cmd->r1 = *pre_scan_data_ptr;\r
+        ++pre_scan_data_ptr;\r
+        --pre_scan_data_size;\r
+    }\r
+    if (cmd->r1 & SD_SPI_R1_NO_RESPONSE) {\r
+        ESP_LOGD(TAG, "no response token found");\r
+        return ESP_ERR_TIMEOUT;\r
+    }\r
 \r
     while (rx_length > 0) {\r
         size_t extra_data_size = 0;\r