working implementation with gfx syscalls
This commit is contained in:
parent
65602895a5
commit
c2a27f3e7c
4 changed files with 39 additions and 281 deletions
|
@ -1,6 +1,7 @@
|
||||||
GFXSRC += $(GFXLIB)/src/gfile/fatfs/src/ff.c \
|
GFXSRC += $(GFXLIB)/src/gfile/fatfs/src/ff.c \
|
||||||
$(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_diskio.c \
|
$(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_diskio.c \
|
||||||
$(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_syscall.c
|
$(GFXLIB)/src/gfile/fatfs/src/syscall.c
|
||||||
|
|
||||||
|
|
||||||
GFXINC += $(GFXLIB)/src/gfile/fatfs/src
|
GFXINC += $(GFXLIB)/src/gfile/fatfs/src
|
||||||
|
|
||||||
|
|
|
@ -1,236 +0,0 @@
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2013 */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* 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 module to the FatFs module with a defined API. */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include "diskio.h" /* FatFs lower layer API */
|
|
||||||
#include "usbdisk.h" /* Example: USB drive control */
|
|
||||||
#include "atadrive.h" /* Example: ATA drive control */
|
|
||||||
#include "sdcard.h" /* Example: MMC/SDC contorl */
|
|
||||||
|
|
||||||
/* Definitions of physical drive number for each media */
|
|
||||||
#define ATA 0
|
|
||||||
#define MMC 1
|
|
||||||
#define USB 2
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Inidialize a Drive */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DSTATUS disk_initialize (
|
|
||||||
BYTE pdrv /* Physical drive nmuber (0..) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DSTATUS stat;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
switch (pdrv) {
|
|
||||||
case ATA :
|
|
||||||
result = ATA_disk_initialize();
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return stat;
|
|
||||||
|
|
||||||
case MMC :
|
|
||||||
result = MMC_disk_initialize();
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return stat;
|
|
||||||
|
|
||||||
case USB :
|
|
||||||
result = USB_disk_initialize();
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return stat;
|
|
||||||
}
|
|
||||||
return STA_NOINIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Get Disk Status */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DSTATUS disk_status (
|
|
||||||
BYTE pdrv /* Physical drive nmuber (0..) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DSTATUS stat;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
switch (pdrv) {
|
|
||||||
case ATA :
|
|
||||||
result = ATA_disk_status();
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return stat;
|
|
||||||
|
|
||||||
case MMC :
|
|
||||||
result = MMC_disk_status();
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return stat;
|
|
||||||
|
|
||||||
case USB :
|
|
||||||
result = USB_disk_status();
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return stat;
|
|
||||||
}
|
|
||||||
return STA_NOINIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Read Sector(s) */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
DRESULT disk_read (
|
|
||||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
|
||||||
BYTE *buff, /* Data buffer to store read data */
|
|
||||||
DWORD sector, /* Sector address (LBA) */
|
|
||||||
UINT count /* Number of sectors to read (1..128) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DRESULT res;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
switch (pdrv) {
|
|
||||||
case ATA :
|
|
||||||
// translate the arguments here
|
|
||||||
|
|
||||||
result = ATA_disk_read(buff, sector, count);
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
case MMC :
|
|
||||||
// translate the arguments here
|
|
||||||
|
|
||||||
result = MMC_disk_read(buff, sector, count);
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
case USB :
|
|
||||||
// translate the arguments here
|
|
||||||
|
|
||||||
result = USB_disk_read(buff, sector, count);
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
return RES_PARERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
/* Write Sector(s) */
|
|
||||||
/*-----------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if _USE_WRITE
|
|
||||||
DRESULT disk_write (
|
|
||||||
BYTE pdrv, /* Physical drive nmuber (0..) */
|
|
||||||
const BYTE *buff, /* Data to be written */
|
|
||||||
DWORD sector, /* Sector address (LBA) */
|
|
||||||
UINT count /* Number of sectors to write (1..128) */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DRESULT res;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
switch (pdrv) {
|
|
||||||
case ATA :
|
|
||||||
// translate the arguments here
|
|
||||||
|
|
||||||
result = ATA_disk_write(buff, sector, count);
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
case MMC :
|
|
||||||
// translate the arguments here
|
|
||||||
|
|
||||||
result = MMC_disk_write(buff, sector, count);
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
case USB :
|
|
||||||
// translate the arguments here
|
|
||||||
|
|
||||||
result = USB_disk_write(buff, sector, count);
|
|
||||||
|
|
||||||
// translate the reslut code here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
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 */
|
|
||||||
)
|
|
||||||
{
|
|
||||||
DRESULT res;
|
|
||||||
int result;
|
|
||||||
|
|
||||||
switch (pdrv) {
|
|
||||||
case ATA :
|
|
||||||
// pre-process here
|
|
||||||
|
|
||||||
result = ATA_disk_ioctl(cmd, buff);
|
|
||||||
|
|
||||||
// post-process here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
case MMC :
|
|
||||||
// pre-process here
|
|
||||||
|
|
||||||
result = MMC_disk_ioctl(cmd, buff);
|
|
||||||
|
|
||||||
// post-process here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
|
|
||||||
case USB :
|
|
||||||
// pre-process here
|
|
||||||
|
|
||||||
result = USB_disk_ioctl(cmd, buff);
|
|
||||||
|
|
||||||
// post-process here
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
return RES_PARERR;
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -5,7 +5,6 @@
|
||||||
#ifndef _FFCONF
|
#ifndef _FFCONF
|
||||||
#define _FFCONF 8051 /* Revision ID */
|
#define _FFCONF 8051 /* Revision ID */
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------/
|
/*---------------------------------------------------------------------------/
|
||||||
/ Functions and Buffer Configurations
|
/ Functions and Buffer Configurations
|
||||||
/---------------------------------------------------------------------------*/
|
/---------------------------------------------------------------------------*/
|
||||||
|
@ -189,9 +188,12 @@
|
||||||
/ with file lock control. This feature uses bss _FS_LOCK * 12 bytes. */
|
/ with file lock control. This feature uses bss _FS_LOCK * 12 bytes. */
|
||||||
|
|
||||||
|
|
||||||
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
|
#define _FS_REENTRANT 1 /* 0:Disable or 1:Enable */
|
||||||
|
#if _FS_REENTRANT
|
||||||
|
#include "gfx.h"
|
||||||
|
#endif
|
||||||
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time tick */
|
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time tick */
|
||||||
#define _SYNC_t HANDLE /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */
|
#define _SYNC_t gfxSem /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */
|
||||||
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
|
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
|
||||||
/
|
/
|
||||||
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
|
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
|
||||||
|
|
|
@ -1,67 +1,57 @@
|
||||||
/*
|
/*
|
||||||
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
* This file is subject to the terms of the GFX License. If a copy of
|
||||||
|
* the license was not distributed with this file, you can obtain one at:
|
||||||
|
*
|
||||||
|
* http://ugfx.org/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
#include "gfx.h"
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
/* Sample code of OS dependent controls for FatFs R0.08b */
|
|
||||||
/* (C)ChaN, 2011 */
|
|
||||||
/*------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include "ch.h"
|
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
|
|
||||||
#if _FS_REENTRANT
|
#if _FS_REENTRANT
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Static array of Synchronization Objects */
|
/* Static array of Synchronization Objects */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
static Semaphore ff_sem[_VOLUMES];
|
static gfxSem ff_sem[_VOLUMES];
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Create a Synchronization Object */
|
/* Create a Synchronization Object */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj) {
|
int ff_cre_syncobj(BYTE vol, _SYNC_t *sobj)
|
||||||
|
{
|
||||||
|
*sobj = ff_sem[vol];
|
||||||
|
gfxSemInit(sobj, 1, MAX_SEMAPHORE_COUNT);
|
||||||
|
|
||||||
*sobj = &ff_sem[vol];
|
return 1;
|
||||||
chSemInit(*sobj, 1);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Delete a Synchronization Object */
|
/* Delete a Synchronization Object */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
int ff_del_syncobj(_SYNC_t sobj) {
|
int ff_del_syncobj(_SYNC_t sobj)
|
||||||
|
{
|
||||||
|
gfxSemDestroy( (gfxSem*)&sobj );
|
||||||
|
|
||||||
chSemReset(sobj, 0);
|
return 1;
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Request Grant to Access the Volume */
|
/* Request Grant to Access the Volume */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
int ff_req_grant(_SYNC_t sobj) {
|
int ff_req_grant(_SYNC_t sobj)
|
||||||
|
{
|
||||||
msg_t msg = chSemWaitTimeout(sobj, (systime_t)_FS_TIMEOUT);
|
if (gfxSemWait( (gfxSem*)&sobj, (delaytime_t)_FS_TIMEOUT) )
|
||||||
return msg == RDY_OK;
|
return TRUE;
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Release Grant to Access the Volume */
|
/* Release Grant to Access the Volume */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
void ff_rel_grant(_SYNC_t sobj) {
|
void ff_rel_grant(_SYNC_t sobj)
|
||||||
|
{
|
||||||
chSemSignal(sobj);
|
gfxSemSignal( (gfxSem*)&sobj );
|
||||||
}
|
}
|
||||||
#endif /* _FS_REENTRANT */
|
#endif /* _FS_REENTRANT */
|
||||||
|
|
||||||
|
@ -69,16 +59,17 @@ void ff_rel_grant(_SYNC_t sobj) {
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Allocate a memory block */
|
/* Allocate a memory block */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
void *ff_memalloc(UINT size) {
|
void *ff_memalloc(UINT size)
|
||||||
|
{
|
||||||
return chHeapAlloc(NULL, size);
|
return gfxAlloc( (size_t)size );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
/* Free a memory block */
|
/* Free a memory block */
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
void ff_memfree(void *mblock) {
|
void ff_memfree(void *mblock)
|
||||||
|
{
|
||||||
chHeapFree(mblock);
|
gfxFree(mblock);
|
||||||
}
|
}
|
||||||
#endif /* _USE_LFN == 3 */
|
#endif /* _USE_LFN == 3 */
|
||||||
|
|
Loading…
Add table
Reference in a new issue