Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions include/filesys/block/sdmm_vfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <stdint.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>

vfs_file_t *
_sdmm_open(int pclk, int pss, int pdi, int pdo)
{
int r;
int drv = 0;
struct __using("filesys/block/sdmm.cc") *SDMM;
unsigned long long pmask;
vfs_file_t *handle;

SDMM = _gc_alloc_managed(sizeof(*SDMM));

#ifdef _DEBUG
__builtin_printf("sdmm_open: using pins: %d %d %d %d\n", pclk, pss, pdi, pdo);
#endif
pmask = (1ULL << pclk) | (1ULL << pss) | (1ULL << pdi) | (1ULL << pdo);
if (!_usepins(pmask)) {
_gc_free(SDMM);
_seterror(EBUSY);
return 0;
}
SDMM->f_pinmask = pmask;
r = SDMM->disk_setpins(drv, pclk, pss, pdi, pdo);
if (r == 0)
r = SDMM->disk_initialize(0);
if (r != 0) {
#ifdef _DEBUG
__builtin_printf("sd card initialize: result=[%d]\n", r);
_waitms(1000);
#endif
goto cleanup_and_out;
}
handle = _get_vfs_file_handle();
if (!handle) goto cleanup_and_out;

handle->flags = O_RDWR;
handle->bufmode = _IONBF;
handle->state = _VFS_STATE_INUSE | _VFS_STATE_WROK | _VFS_STATE_RDOK;
handle->read = &SDMM->v_read;
handle->write = &SDMM->v_write;
handle->close = &SDMM->v_close;
handle->ioctl = &SDMM->v_ioctl;
handle->flush = &SDMM->v_flush;
handle->lseek = &SDMM->v_lseek;
handle->putcf = &SDMM->v_putc;
handle->getcf = &SDMM->v_getc;
return handle;
cleanup_and_out:
_freepins(pmask);
_gc_free(SDMM);
_seterror(EIO);
return 0;
}

struct vfs *
_vfs_open_sdcardx(int pclk, int pss, int pdi, int pdo)
{
vfs_file_t *handle;
struct vfs *result;

handle = _sdmm_open(pclk, pss, pdi, pdo);
if (!handle) return 0;
result = _vfs_open_fat_handle(handle);
if (!result) {
/* go ahead and close the handle */
handle->close(handle);
}
return result;
}

struct vfs *
_vfs_open_sdcard()
{
return _vfs_open_sdcardx(61, 60, 59, 58);
}

74 changes: 0 additions & 74 deletions include/filesys/fatfs/fatfs_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,6 @@
#include <fcntl.h>
#include "ff.h"

vfs_file_t *
_sdmm_open(int pclk, int pss, int pdi, int pdo)
{
int r;
int drv = 0;
struct __using("filesys/block/sdmm.cc") *SDMM;
unsigned long long pmask;
vfs_file_t *handle;

SDMM = _gc_alloc_managed(sizeof(*SDMM));

#ifdef _DEBUG
__builtin_printf("sdmm_open: using pins: %d %d %d %d\n", pclk, pss, pdi, pdo);
#endif
pmask = (1ULL << pclk) | (1ULL << pss) | (1ULL << pdi) | (1ULL << pdo);
if (!_usepins(pmask)) {
_gc_free(SDMM);
_seterror(EBUSY);
return 0;
}
SDMM->f_pinmask = pmask;
r = SDMM->disk_setpins(drv, pclk, pss, pdi, pdo);
if (r == 0)
r = SDMM->disk_initialize(0);
if (r != 0) {
#ifdef _DEBUG
__builtin_printf("sd card initialize: result=[%d]\n", r);
_waitms(1000);
#endif
goto cleanup_and_out;
}
handle = _get_vfs_file_handle();
if (!handle) goto cleanup_and_out;

handle->flags = O_RDWR;
handle->bufmode = _IONBF;
handle->state = _VFS_STATE_INUSE | _VFS_STATE_WROK | _VFS_STATE_RDOK;
handle->read = &SDMM->v_read;
handle->write = &SDMM->v_write;
handle->close = &SDMM->v_close;
handle->ioctl = &SDMM->v_ioctl;
handle->flush = &SDMM->v_flush;
handle->lseek = &SDMM->v_lseek;
handle->putcf = &SDMM->v_putc;
handle->getcf = &SDMM->v_getc;
return handle;
cleanup_and_out:
_freepins(pmask);
_gc_free(SDMM);
_seterror(EIO);
return 0;
}

struct vfs *
_vfs_open_sdcardx(int pclk, int pss, int pdi, int pdo)
{
vfs_file_t *handle;
struct vfs *result;

handle = _sdmm_open(pclk, pss, pdi, pdo);
if (!handle) return 0;
result = _vfs_open_fat_handle(handle);
if (!result) {
/* go ahead and close the handle */
handle->close(handle);
}
return result;
}

struct vfs *
_vfs_open_sdcard()
{
return _vfs_open_sdcardx(61, 60, 59, 58);
}

struct vfs *
_vfs_open_fat_handle(vfs_file_t *fhandle)
Expand Down
8 changes: 5 additions & 3 deletions include/libc.a
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#define DIR struct _dir
#define DIRENT struct dirent

/* filesys/block/sdmm_vfs.c */
_FILE *_sdmm_open(int pclk, int pss, int pdi, int pdo) __fromfile("filesys/block/sdmm_vfs.c");
struct vfs *_vfs_open_sdcard(void) __fromfile("filesys/block/sdmm_vfs.c");
struct vfs *_vfs_open_sdcardx(int pclk, int pss, int pdi, int pdo) __fromfile("filesys/block/sdmm_vfs.c");

/* filesys/fatfs/fatfs_vfs.c */
_FILE *_sdmm_open(int pclk, int pss, int pdi, int pdo) __fromfile("filesys/fatfs/fatfs_vfs.c");
struct vfs *_vfs_open_fat_handle(_FILE *fhandle) __fromfile("filesys/fatfs/fatfs_vfs.c");
struct vfs *_vfs_open_fat_file(const char *name) __fromfile("filesys/fatfs/fatfs_vfs.c");
struct vfs *_vfs_open_sdcard(void) __fromfile("filesys/fatfs/fatfs_vfs.c");
struct vfs *_vfs_open_sdcardx(int pclk, int pss, int pdi, int pdo) __fromfile("filesys/fatfs/fatfs_vfs.c");

/* filesys/fs9p/fs9p_vfs.c */
struct vfs *_vfs_open_host(void) __fromfile("filesys/fs9p/fs9p_vfs.c");
Expand Down
4 changes: 2 additions & 2 deletions include/sys/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ struct vfs *_vfs_open_fat_handle(vfs_file_t *handle) _IMPL("filesys/fatfs/fatfs_
struct vfs *_vfs_open_fat_file(const char *name) _IMPL("filesys/fatfs/fatfs_vfs.c");

/* legacy calls */
struct vfs *_vfs_open_sdcard(void) _IMPL("filesys/fatfs/fatfs_vfs.c");
struct vfs *_vfs_open_sdcardx(int pclk = 61, int pss = 60, int pdi = 59, int pdo = 58) _IMPL("filesys/fatfs/fatfs_vfs.c");
struct vfs *_vfs_open_sdcard(void) _IMPL("filesys/block/sdmm_vfs.c");
struct vfs *_vfs_open_sdcardx(int pclk = 61, int pss = 60, int pdi = 59, int pdo = 58) _IMPL("filesys/block/sdmm_vfs.c");

/* parallax file system */
struct vfs *_vfs_open_parallaxfs(void) _IMPL("filesys/parallax/parallaxfs_vfs.c");
Expand Down