summaryrefslogtreecommitdiffstatshomepage
path: root/cc3200/fatfs/src
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-01-29 15:15:16 +1100
committerDamien George <damien.p.george@gmail.com>2017-01-30 12:26:07 +1100
commit56506fd64a40f9c5ea97888245df6f2cb8b20744 (patch)
tree152a6a95d1f3393e0b8b535e2a8f6f7a18692fd2 /cc3200/fatfs/src
parent6eafa544865a5d6dcb18f9161f7a18bd4fb6229f (diff)
downloadmicropython-56506fd64a40f9c5ea97888245df6f2cb8b20744.tar.gz
micropython-56506fd64a40f9c5ea97888245df6f2cb8b20744.zip
cc3200: Convert to use new VFS sub-system and new ooFatFs library.
Diffstat (limited to 'cc3200/fatfs/src')
-rw-r--r--cc3200/fatfs/src/diskio.c209
-rw-r--r--cc3200/fatfs/src/drivers/sd_diskio.c3
-rw-r--r--cc3200/fatfs/src/drivers/sflash_diskio.c3
-rw-r--r--cc3200/fatfs/src/ffconf.c93
-rw-r--r--cc3200/fatfs/src/option/syscall.c150
5 files changed, 4 insertions, 454 deletions
diff --git a/cc3200/fatfs/src/diskio.c b/cc3200/fatfs/src/diskio.c
deleted file mode 100644
index 74bc6a0d52..0000000000
--- a/cc3200/fatfs/src/diskio.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*-----------------------------------------------------------------------*/
-/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
-/*-----------------------------------------------------------------------*/
-/* If a working storage control module is available, it should be */
-/* attached to the FatFs via a glue function rather than modifying it. */
-/* This is an example of glue functions to attach various exsisting */
-/* storage control modules to the FatFs module with a defined API. */
-/*-----------------------------------------------------------------------*/
-#include <stdint.h>
-#include <stdbool.h>
-
-#include "py/mpconfig.h"
-#include "py/runtime.h"
-#include "py/obj.h"
-#include "lib/fatfs/ff.h"
-#include "lib/fatfs/diskio.h" /* FatFs lower layer API */
-#include "sflash_diskio.h" /* Serial flash disk IO API */
-#include "sd_diskio.h" /* SDCARD disk IO API */
-#include "inc/hw_types.h"
-#include "inc/hw_ints.h"
-#include "inc/hw_memmap.h"
-#include "rom_map.h"
-#include "prcm.h"
-#include "pybrtc.h"
-#include "timeutils.h"
-#include "pybsd.h"
-#include "moduos.h"
-
-
-/*-----------------------------------------------------------------------*/
-/* Get Drive Status */
-/*-----------------------------------------------------------------------*/
-
-DSTATUS disk_status (
- BYTE pdrv /* Physical drive nmuber to identify the drive */
-)
-{
- if (pdrv == PD_FLASH) {
- return sflash_disk_status();
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- if (mount_obj->writeblocks[0] == MP_OBJ_NULL) {
- return STA_PROTECT;
- }
- return 0;
- }
- }
- return STA_NODISK;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Inidialize a Drive */
-/*-----------------------------------------------------------------------*/
-
-DSTATUS disk_initialize (
- BYTE pdrv /* Physical drive nmuber to identify the drive */
-)
-{
- if (pdrv == PD_FLASH) {
- if (RES_OK != sflash_disk_init()) {
- return STA_NOINIT;
- }
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- if (mount_obj->writeblocks[0] == MP_OBJ_NULL) {
- return STA_PROTECT;
- }
- return 0;
- }
- }
- return STA_NODISK;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Read Sector(s) */
-/*-----------------------------------------------------------------------*/
-
-DRESULT disk_read (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- BYTE *buff, /* Data buffer to store read data */
- DWORD sector, /* Sector address in LBA */
- UINT count /* Number of sectors to read */
-)
-{
- if (pdrv == PD_FLASH) {
- return sflash_disk_read(buff, sector, count);
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- // optimization for the built-in sd card device
- if (mount_obj->device == (mp_obj_t)&pybsd_obj) {
- return sd_disk_read(buff, sector, count);
- }
- mount_obj->readblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
- mount_obj->readblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, buff);
- return mp_obj_get_int(mp_call_method_n_kw(2, 0, mount_obj->readblocks));
- }
- // nothing mounted
- return RES_ERROR;
- }
- return RES_PARERR;
-}
-
-/*-----------------------------------------------------------------------*/
-/* Write Sector(s) */
-/*-----------------------------------------------------------------------*/
-
-#if _USE_WRITE
-DRESULT disk_write (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- const BYTE *buff, /* Data to be written */
- DWORD sector, /* Sector address in LBA */
- UINT count /* Number of sectors to write */
-)
-{
- if (pdrv == PD_FLASH) {
- return sflash_disk_write(buff, sector, count);
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- // optimization for the built-in sd card device
- if (mount_obj->device == (mp_obj_t)&pybsd_obj) {
- return sd_disk_write(buff, sector, count);
- }
- mount_obj->writeblocks[2] = MP_OBJ_NEW_SMALL_INT(sector);
- mount_obj->writeblocks[3] = mp_obj_new_bytearray_by_ref(count * 512, (void *)buff);
- return mp_obj_get_int(mp_call_method_n_kw(2, 0, mount_obj->writeblocks));
- }
- // nothing mounted
- return RES_ERROR;
- }
- return RES_PARERR;
-}
-#endif
-
-
-/*-----------------------------------------------------------------------*/
-/* Miscellaneous Functions */
-/*-----------------------------------------------------------------------*/
-
-#if _USE_IOCTL
-DRESULT disk_ioctl (
- BYTE pdrv, /* Physical drive nmuber (0..) */
- BYTE cmd, /* Control code */
- void *buff /* Buffer to send/receive control data */
-)
-{
- if (pdrv == PD_FLASH) {
- switch (cmd) {
- case CTRL_SYNC:
- return sflash_disk_flush();
- case GET_SECTOR_COUNT:
- *((DWORD*)buff) = SFLASH_SECTOR_COUNT;
- return RES_OK;
- case GET_SECTOR_SIZE:
- *((DWORD*)buff) = SFLASH_SECTOR_SIZE;
- return RES_OK;
- case GET_BLOCK_SIZE:
- *((DWORD*)buff) = 1; // high-level sector erase size in units of the block size
- return RES_OK;
- }
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(pdrv))) {
- switch (cmd) {
- case CTRL_SYNC:
- if (mount_obj->sync[0] != MP_OBJ_NULL) {
- mp_call_method_n_kw(0, 0, mount_obj->sync);
- }
- return RES_OK;
- case GET_SECTOR_COUNT:
- // optimization for the built-in sd card device
- if (mount_obj->device == (mp_obj_t)&pybsd_obj) {
- *((DWORD*)buff) = sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512);
- } else {
- *((DWORD*)buff) = mp_obj_get_int(mp_call_method_n_kw(0, 0, mount_obj->count));
- }
- return RES_OK;
- case GET_SECTOR_SIZE:
- *((DWORD*)buff) = SD_SECTOR_SIZE; // Sector size is fixed to 512 bytes, as with SD cards
- return RES_OK;
- case GET_BLOCK_SIZE:
- *((DWORD*)buff) = 1; // high-level sector erase size in units of the block size
- return RES_OK;
- }
- }
- // nothing mounted
- return RES_ERROR;
- }
- return RES_PARERR;
-}
-#endif
-
-#if !_FS_READONLY && !_FS_NORTC
-DWORD get_fattime (
- void
-)
-{
- timeutils_struct_time_t tm;
- timeutils_seconds_since_2000_to_struct_time(pyb_rtc_get_seconds(), &tm);
-
- return ((tm.tm_year - 1980) << 25) | ((tm.tm_mon) << 21) |
- ((tm.tm_mday) << 16) | ((tm.tm_hour) << 11) |
- ((tm.tm_min) << 5) | (tm.tm_sec >> 1);
-}
-#endif
-
diff --git a/cc3200/fatfs/src/drivers/sd_diskio.c b/cc3200/fatfs/src/drivers/sd_diskio.c
index c20969bfb8..0a1379181b 100644
--- a/cc3200/fatfs/src/drivers/sd_diskio.c
+++ b/cc3200/fatfs/src/drivers/sd_diskio.c
@@ -39,11 +39,12 @@
#include "py/mpconfig.h"
#include "py/mphal.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
#include "hw_types.h"
#include "hw_memmap.h"
#include "hw_ints.h"
#include "rom_map.h"
-#include "diskio.h"
#include "sd_diskio.h"
#include "sdhost.h"
#include "pin.h"
diff --git a/cc3200/fatfs/src/drivers/sflash_diskio.c b/cc3200/fatfs/src/drivers/sflash_diskio.c
index 7fb2c97a75..1cfd41fb7c 100644
--- a/cc3200/fatfs/src/drivers/sflash_diskio.c
+++ b/cc3200/fatfs/src/drivers/sflash_diskio.c
@@ -4,8 +4,9 @@
#include "py/mpconfig.h"
#include "py/obj.h"
+#include "lib/oofatfs/ff.h"
+#include "lib/oofatfs/diskio.h"
#include "simplelink.h"
-#include "diskio.h"
#include "sflash_diskio.h"
#include "debug.h"
#include "modnetwork.h"
diff --git a/cc3200/fatfs/src/ffconf.c b/cc3200/fatfs/src/ffconf.c
deleted file mode 100644
index 71ef6a40b9..0000000000
--- a/cc3200/fatfs/src/ffconf.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * This file is part of the Micro Python project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2013, 2014 Damien P. George
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include <string.h>
-
-#include "py/mpstate.h"
-#include "lib/fatfs/ff.h"
-#include "lib/fatfs/ffconf.h"
-#include "lib/fatfs/diskio.h"
-#include "moduos.h"
-
-#if _FS_RPATH
-extern BYTE ff_CurrVol;
-#endif
-
-STATIC bool check_path(const TCHAR **path, const char *mount_point_str, mp_uint_t mount_point_len) {
- if (strncmp(*path, mount_point_str, mount_point_len) == 0) {
- if ((*path)[mount_point_len] == '/') {
- *path += mount_point_len;
- return true;
- } else if ((*path)[mount_point_len] == '\0') {
- *path = "/";
- return true;
- }
- }
- return false;
-}
-
-// "path" is the path to lookup; will advance this pointer beyond the volume name.
-// Returns logical drive number (-1 means invalid path).
-int ff_get_ldnumber (const TCHAR **path) {
- if (!(*path)) {
- return -1;
- }
-
- if (**path != '/') {
- #if _FS_RPATH
- return ff_CurrVol;
- #else
- return -1;
- #endif
- }
-
- if (check_path(path, "/flash", 6)) {
- return PD_FLASH;
- }
- else {
- for (mp_uint_t i = 0; i < MP_STATE_PORT(mount_obj_list).len; i++) {
- os_fs_mount_t *mount_obj = ((os_fs_mount_t *)(MP_STATE_PORT(mount_obj_list).items[i]));
- if (check_path(path, mount_obj->path, mount_obj->pathlen)) {
- return mount_obj->vol;
- }
- }
- }
-
- return -1;
-}
-
-void ff_get_volname(BYTE vol, TCHAR **dest) {
- if (vol == PD_FLASH) {
- memcpy(*dest, "/flash", 6);
- *dest += 6;
- } else {
- os_fs_mount_t *mount_obj;
- if ((mount_obj = osmount_find_by_volume(vol))) {
- memcpy(*dest, mount_obj->path, mount_obj->pathlen);
- *dest += mount_obj->pathlen;
- }
- }
-}
diff --git a/cc3200/fatfs/src/option/syscall.c b/cc3200/fatfs/src/option/syscall.c
deleted file mode 100644
index 1ada97bd43..0000000000
--- a/cc3200/fatfs/src/option/syscall.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*------------------------------------------------------------------------*/
-/* Sample code of OS dependent controls for FatFs */
-/* (C)ChaN, 2014 */
-/*------------------------------------------------------------------------*/
-
-#include "ff.h"
-
-
-#if _FS_REENTRANT
-/*------------------------------------------------------------------------*/
-/* Create a Synchronization Object */
-/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to create a new
-/ synchronization object, such as semaphore and mutex. When a 0 is returned,
-/ the f_mount() function fails with FR_INT_ERR.
-*/
-
-int ff_cre_syncobj ( /* !=0:Function succeeded, ==0:Could not create due to any error */
- BYTE vol, /* Corresponding logical drive being processed */
- _SYNC_t *sobj /* Pointer to return the created sync object */
-)
-{
- int ret;
-
-//
-// *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
-// ret = (int)(*sobj != INVALID_HANDLE_VALUE);
-
-// *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */
-// ret = 1; /* The initial value of the semaphore must be 1. */
-
-// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
-// ret = (int)(err == OS_NO_ERR);
-
- vSemaphoreCreateBinary( (*sobj) ); /* FreeRTOS */
- ret = (int)(*sobj != NULL);
-
- return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Delete a Synchronization Object */
-/*------------------------------------------------------------------------*/
-/* This function is called in f_mount() function to delete a synchronization
-/ object that created with ff_cre_syncobj function. When a 0 is returned,
-/ the f_mount() function fails with FR_INT_ERR.
-*/
-
-int ff_del_syncobj ( /* !=0:Function succeeded, ==0:Could not delete due to any error */
- _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
-)
-{
- int ret;
-
-
-// ret = CloseHandle(sobj); /* Win32 */
-
-// ret = 1; /* uITRON (nothing to do) */
-
-// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
-// ret = (int)(err == OS_NO_ERR);
-
- vSemaphoreDelete(sobj); /* FreeRTOS */
- ret = 1;
-
- return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Request Grant to Access the Volume */
-/*------------------------------------------------------------------------*/
-/* This function is called on entering file functions to lock the volume.
-/ When a 0 is returned, the file function fails with FR_TIMEOUT.
-*/
-
-int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
- _SYNC_t sobj /* Sync object to wait */
-)
-{
- int ret;
-
-// ret = (int)(WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
-
-// ret = (int)(wai_sem(sobj) == E_OK); /* uITRON */
-
-// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
-// ret = (int)(err == OS_NO_ERR);
-
- ret = (int)(xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
-
- return ret;
-}
-
-
-
-/*------------------------------------------------------------------------*/
-/* Release Grant to Access the Volume */
-/*------------------------------------------------------------------------*/
-/* This function is called on leaving file functions to unlock the volume.
-*/
-
-void ff_rel_grant (
- _SYNC_t sobj /* Sync object to be signaled */
-)
-{
-// ReleaseMutex(sobj); /* Win32 */
-
-// sig_sem(sobj); /* uITRON */
-
-// OSMutexPost(sobj); /* uC/OS-II */
-
- xSemaphoreGive(sobj); /* FreeRTOS */
-}
-
-#endif
-
-
-
-
-#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
-/*------------------------------------------------------------------------*/
-/* Allocate a memory block */
-/*------------------------------------------------------------------------*/
-/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
-*/
-
-void* ff_memalloc ( /* Returns pointer to the allocated memory block */
- UINT msize /* Number of bytes to allocate */
-)
-{
- return pvPortMalloc(msize); /* Allocate a new memory block with POSIX API */
-}
-
-
-/*------------------------------------------------------------------------*/
-/* Free a memory block */
-/*------------------------------------------------------------------------*/
-
-void ff_memfree (
- void* mblock /* Pointer to the memory block to free */
-)
-{
- vPortFree(mblock); /* Discard the memory block with POSIX API */
-}
-
-#endif