[Horus] Cosmetics

This commit is contained in:
Bertrand Songis
2016-02-20 19:15:22 +01:00
parent f926b85611
commit fe3efb9483
6 changed files with 92 additions and 102 deletions
+54 -64
View File
@@ -66,7 +66,7 @@ int ff_del_syncobj (_SYNC_t mutex)
/* Inidialize a Drive */
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0..) */
BYTE drv /* Physical drive nmuber (0..) */
)
{
DSTATUS stat = 0;
@@ -76,8 +76,8 @@ DSTATUS disk_initialize (
{
stat |= STA_NOINIT;
}
/*-------------------------- SD Init ----------------------------- */
/*-------------------------- SD Init ----------------------------- */
if (SD_Init() != SD_OK)
{
TRACE("SD_Init() failed");
@@ -87,23 +87,23 @@ DSTATUS disk_initialize (
return(stat);
}
DWORD scratch[BLOCK_SIZE / 4] __DMA;
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
BYTE drv /* Physical drive nmuber (0..) */
)
{
DSTATUS stat = 0;
if (SD_Detect() != SD_PRESENT)
stat |= STA_NODISK;
// STA_NOTINIT - Subsystem not initailized
// STA_PROTECTED - Write protected, MMC/SD switch if available
return(stat);
}
@@ -113,28 +113,23 @@ uint32_t sdReadRetries = 0;
/* Read Sector(s) */
DRESULT disk_read (
BYTE drv, /* 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..255) */
BYTE drv, /* 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..255) */
)
{
DRESULT res = RES_OK;
SD_Error Status;
// TRACE("disk_read %d %p %10d %d", drv, buff, sector, count);
if (SD_Detect() != SD_PRESENT) {
TRACE("SD_Detect() != SD_PRESENT");
return RES_NOTRDY;
}
if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer
{
TRACE("DMA Alignment failure, align buffer");
DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack
if ((DWORD)buff < 0x20000000 || (DWORD)buff >= 0x20030000 || ((DWORD)buff & 3)) {
while(count--) {
res = disk_read(drv, (BYTE *)scratch, sector++, 1);
@@ -198,63 +193,58 @@ DRESULT disk_read (
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
UINT count /* Number of sectors to write (1..255) */
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
UINT count /* Number of sectors to write (1..255) */
)
{
SD_Error Status;
DRESULT res = RES_OK;
SD_Error Status;
DRESULT res = RES_OK;
// TRACE("disk_write %d %p %10d %d", drv, buff, sector, count);
if (SD_Detect() != SD_PRESENT)
return(RES_NOTRDY);
// TRACE("disk_write %d %p %10d %d", drv, buff, sector, count);
if ((DWORD)buff & 3) // DMA Alignment failure, do single up to aligned buffer
{
DWORD scratch[BLOCK_SIZE / 4]; // Alignment assured, you'll need a sufficiently big stack
if (SD_Detect() != SD_PRESENT)
return(RES_NOTRDY);
while(count--)
{
memcpy(scratch, buff, BLOCK_SIZE);
if ((DWORD)buff < 0x20000000 || (DWORD)buff >= 0x20030000 || ((DWORD)buff & 3)) {
while(count--) {
memcpy(scratch, buff, BLOCK_SIZE);
res = disk_write(drv, (BYTE *)scratch, sector++, 1);
res = disk_write(drv, (BYTE *)scratch, sector++, 1);
if (res != RES_OK)
break;
if (res != RES_OK)
break;
buff += BLOCK_SIZE;
}
buff += BLOCK_SIZE;
}
return(res);
}
return(res);
}
if (count == 1) {
Status = SD_WriteBlock((uint8_t *)buff, sector, BLOCK_SIZE); // 4GB Compliant
}
else {
Status = SD_WriteMultiBlocks((uint8_t *)buff, sector, BLOCK_SIZE, count); // 4GB Compliant
}
if (count == 1) {
Status = SD_WriteBlock((uint8_t *)buff, sector, BLOCK_SIZE); // 4GB Compliant
}
else {
Status = SD_WriteMultiBlocks((uint8_t *)buff, sector, BLOCK_SIZE, count); // 4GB Compliant
}
if (Status == SD_OK)
{
SDTransferState State;
if (Status == SD_OK)
{
SDTransferState State;
Status = SD_WaitWriteOperation(); // Check if the Transfer is finished
Status = SD_WaitWriteOperation(); // Check if the Transfer is finished
while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
while((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK))
res = RES_ERROR;
}
else {
res = RES_ERROR;
}
if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK))
res = RES_ERROR;
}
else {
res = RES_ERROR;
}
// TRACE("result=%d", res);
return res;
// TRACE("result=%d", res);
return res;
}
#endif /* _READONLY */
@@ -265,9 +255,9 @@ DRESULT disk_write (
/* Miscellaneous Functions */
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;