/*-----------------------------------------------------------------------*/\r
\r
#include <string.h>\r
+#include <time.h>\r
+#include <sys/time.h>\r
#include "diskio.h" /* FatFs lower layer API */\r
#include "ffconf.h"\r
#include "ff.h"\r
-#include "sdmmc_cmd.h"\r
-#include "esp_log.h"\r
-#include <time.h>\r
-#include <sys/time.h>\r
\r
-static const char* TAG = "ff_diskio";\r
-static ff_diskio_impl_t * s_impls[_VOLUMES];\r
-static sdmmc_card_t* s_cards[_VOLUMES] = { NULL };\r
-static bool s_impls_initialized = false;\r
+static ff_diskio_impl_t * s_impls[_VOLUMES] = { NULL };\r
\r
#if _MULTI_PARTITION /* Multiple partition configuration */\r
PARTITION VolToPart[] = {\r
{\r
assert(pdrv < _VOLUMES);\r
\r
- if (!s_impls_initialized) {\r
- s_impls_initialized = true;\r
- memset(s_impls, 0, _VOLUMES * sizeof(ff_diskio_impl_t*));\r
- }\r
-\r
if (s_impls[pdrv]) {\r
ff_diskio_impl_t* im = s_impls[pdrv];\r
s_impls[pdrv] = NULL;\r
| (WORD)(tmr->tm_min << 5)\r
| (WORD)(tmr->tm_sec >> 1);\r
}\r
-\r
-DSTATUS ff_sdmmc_initialize (BYTE pdrv)\r
-{\r
- return 0;\r
-}\r
-\r
-DSTATUS ff_sdmmc_status (BYTE pdrv)\r
-{\r
- return 0;\r
-}\r
-\r
-DRESULT ff_sdmmc_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count)\r
-{\r
- sdmmc_card_t* card = s_cards[pdrv];\r
- assert(card);\r
- esp_err_t err = sdmmc_read_sectors(card, buff, sector, count);\r
- if (err != ESP_OK) {\r
- ESP_LOGE(TAG, "sdmmc_read_blocks failed (%d)", err);\r
- return RES_ERROR;\r
- }\r
- return RES_OK;\r
-}\r
-\r
-DRESULT ff_sdmmc_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)\r
-{\r
- sdmmc_card_t* card = s_cards[pdrv];\r
- assert(card);\r
- esp_err_t err = sdmmc_write_sectors(card, buff, sector, count);\r
- if (err != ESP_OK) {\r
- ESP_LOGE(TAG, "sdmmc_write_blocks failed (%d)", err);\r
- return RES_ERROR;\r
- }\r
- return RES_OK;\r
-}\r
-\r
-DRESULT ff_sdmmc_ioctl (BYTE pdrv, BYTE cmd, void* buff)\r
-{\r
- sdmmc_card_t* card = s_cards[pdrv];\r
- assert(card);\r
- switch(cmd) {\r
- case CTRL_SYNC:\r
- return RES_OK;\r
- case GET_SECTOR_COUNT:\r
- *((uint32_t*) buff) = card->csd.capacity;\r
- return RES_OK;\r
- case GET_SECTOR_SIZE:\r
- *((uint32_t*) buff) = card->csd.sector_size;\r
- return RES_OK;\r
- case GET_BLOCK_SIZE:\r
- return RES_ERROR;\r
- }\r
- return RES_ERROR;\r
-}\r
-\r
-void ff_diskio_register_sdmmc(BYTE pdrv, sdmmc_card_t* card)\r
-{\r
- static const ff_diskio_impl_t sdmmc_impl = {\r
- .init = &ff_sdmmc_initialize,\r
- .status = &ff_sdmmc_status,\r
- .read = &ff_sdmmc_read,\r
- .write = &ff_sdmmc_write,\r
- .ioctl = &ff_sdmmc_ioctl\r
- };\r
- s_cards[pdrv] = card;\r
- ff_diskio_register(pdrv, &sdmmc_impl);\r
-}\r
-\r
--- /dev/null
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "diskio.h"
+#include "ffconf.h"
+#include "ff.h"
+#include "sdmmc_cmd.h"
+#include "esp_log.h"
+
+static sdmmc_card_t* s_cards[_VOLUMES] = { NULL };
+
+static const char* TAG = "diskio_sdmmc";
+
+DSTATUS ff_sdmmc_initialize (BYTE pdrv)
+{
+ return 0;
+}
+
+DSTATUS ff_sdmmc_status (BYTE pdrv)
+{
+ return 0;
+}
+
+DRESULT ff_sdmmc_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
+{
+ sdmmc_card_t* card = s_cards[pdrv];
+ assert(card);
+ esp_err_t err = sdmmc_read_sectors(card, buff, sector, count);
+ if (err != ESP_OK) {
+ ESP_LOGE(TAG, "sdmmc_read_blocks failed (%d)", err);
+ return RES_ERROR;
+ }
+ return RES_OK;
+}
+
+DRESULT ff_sdmmc_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
+{
+ sdmmc_card_t* card = s_cards[pdrv];
+ assert(card);
+ esp_err_t err = sdmmc_write_sectors(card, buff, sector, count);
+ if (err != ESP_OK) {
+ ESP_LOGE(TAG, "sdmmc_write_blocks failed (%d)", err);
+ return RES_ERROR;
+ }
+ return RES_OK;
+}
+
+DRESULT ff_sdmmc_ioctl (BYTE pdrv, BYTE cmd, void* buff)
+{
+ sdmmc_card_t* card = s_cards[pdrv];
+ assert(card);
+ switch(cmd) {
+ case CTRL_SYNC:
+ return RES_OK;
+ case GET_SECTOR_COUNT:
+ *((uint32_t*) buff) = card->csd.capacity;
+ return RES_OK;
+ case GET_SECTOR_SIZE:
+ *((uint32_t*) buff) = card->csd.sector_size;
+ return RES_OK;
+ case GET_BLOCK_SIZE:
+ return RES_ERROR;
+ }
+ return RES_ERROR;
+}
+
+void ff_diskio_register_sdmmc(BYTE pdrv, sdmmc_card_t* card)
+{
+ static const ff_diskio_impl_t sdmmc_impl = {
+ .init = &ff_sdmmc_initialize,
+ .status = &ff_sdmmc_status,
+ .read = &ff_sdmmc_read,
+ .write = &ff_sdmmc_write,
+ .ioctl = &ff_sdmmc_ioctl
+ };
+ s_cards[pdrv] = card;
+ ff_diskio_register(pdrv, &sdmmc_impl);
+}
+
// Licensed under the Apache License, Version 2.0 (the "License");\r
// you may not use this file except in compliance with the License.\r
// You may obtain a copy of the License at\r
-\r
+//\r
// http://www.apache.org/licenses/LICENSE-2.0\r
//\r
// Unless required by applicable law or agreed to in writing, software\r
// limitations under the License.\r
\r
#include <string.h>\r
-#include "diskio.h" /* FatFs lower layer API */\r
+#include "diskio.h"\r
#include "ffconf.h"\r
#include "ff.h"\r
-#include "sdmmc_cmd.h"\r
#include "esp_log.h"\r
-#include <time.h>\r
-#include <sys/time.h>\r
-\r
#include "diskio_spiflash.h"\r
#include "wear_levelling.h"\r
\r
static const char* TAG = "ff_diskio_spiflash";\r
-#ifndef MAX_FF_WL_DRIVES\r
-#define MAX_FF_WL_DRIVES 8\r
-#endif // MAX_FF_WL_DRIVES\r
\r
-wl_handle_t ff_wl_handles[MAX_FF_WL_DRIVES] = {\r
- WL_INVALID_HANDLE,\r
- WL_INVALID_HANDLE,\r
+wl_handle_t ff_wl_handles[_VOLUMES] = {\r
WL_INVALID_HANDLE,\r
WL_INVALID_HANDLE,\r
- WL_INVALID_HANDLE,\r
- WL_INVALID_HANDLE,\r
- WL_INVALID_HANDLE,\r
- WL_INVALID_HANDLE\r
};\r
\r
DSTATUS ff_wl_initialize (BYTE pdrv)\r
\r
esp_err_t ff_diskio_register_wl_partition(BYTE pdrv, wl_handle_t flash_handle)\r
{\r
- if (pdrv >= MAX_FF_WL_DRIVES) return ESP_FAIL; \r
+ if (pdrv >= _VOLUMES) {\r
+ return ESP_ERR_INVALID_ARG;\r
+ }\r
static const ff_diskio_impl_t wl_impl = {\r
.init = &ff_wl_initialize,\r
.status = &ff_wl_status,\r
\r
BYTE ff_diskio_get_pdrv_wl(wl_handle_t flash_handle)\r
{\r
- for (int i=0 ; i< MAX_FF_WL_DRIVES ; i++)\r
- {\r
- if (flash_handle == ff_wl_handles[i])\r
- {\r
+ for (int i = 0; i < _VOLUMES; i++) {\r
+ if (flash_handle == ff_wl_handles[i]) {\r
return i;\r
}\r
}\r
- return -1;\r
+ return 0xff;\r
}\r