Skip to content

Commit

Permalink
Merge pull request RIOT-OS#5155 from OlegHahm/diskio_cleanup
Browse files Browse the repository at this point in the history
doc diskio: RIOTized style and added doxygen
  • Loading branch information
PeterKietzmann committed Mar 30, 2016
2 parents 230e105 + 0925737 commit 3fa8a26
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 137 deletions.
8 changes: 4 additions & 4 deletions cpu/lpc2387/asmfunc.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
@ Fast Block Copy (declared in diskio.h)
@-----------------------------------------------------------@

.global Copy_un2al
.global copy_un2al
.arm
Copy_un2al:
copy_un2al:
STMFD SP!, {R4-R8}
ANDS IP, R1, #3
BEQ lb_align
Expand Down Expand Up @@ -46,9 +46,9 @@ lb_align:
BX LR


.global Copy_al2un
.global copy_al2un
.arm
Copy_al2un:
copy_al2un:
STMFD SP!, {R4-R8}
ANDS IP, R0, #3
BEQ sb_align
Expand Down
92 changes: 46 additions & 46 deletions cpu/lpc2387/mci/lpc2387-mci.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extern unsigned long xtimer_now(void);
---------------------------------------------------------------------------*/

static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */
static volatile diskio_sta_t Stat = DISKIO_STA_NOINIT; /* Disk status */

static unsigned short CardRCA; /* Assigned RCA */
static unsigned char CardType, /* Card type flag */
Expand Down Expand Up @@ -363,7 +363,7 @@ static void power_off(void)
PINSEL4 &= ~((BIT22 | BIT23) | (BIT24 | BIT25) | (BIT26 | BIT27));
// Pins should be now configured as standard input (see board_init.c if you accidentally reconfigured them)

Stat |= STA_NOINIT;
Stat |= DISKIO_STA_NOINIT;
}


Expand Down Expand Up @@ -523,13 +523,13 @@ static void bswap_cp(unsigned char *dst, const unsigned long *src)
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
DSTATUS MCI_initialize(void)
diskio_sta_t mci_initialize(void)
{
unsigned int cmd, n;
unsigned long resp[4];
unsigned char ty;

if (Stat & STA_NODISK) {
if (Stat & DISKIO_STA_NODISK) {
return Stat; /* No card in the socket */
}

Expand Down Expand Up @@ -666,12 +666,12 @@ DSTATUS MCI_initialize(void)

MCI_CLOCK = (MCI_CLOCK & 0xF00) | 0x200 | (PCLK / MCLK_RW / 2 - 1); /* Set MCICLK = MCLK_RW, power-save mode */

Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
Stat &= ~DISKIO_STA_NOINIT; /* Clear DISKIO_STA_NOINIT */
return Stat;

di_fail:
power_off();
Stat |= STA_NOINIT; /* Set STA_NOINIT */
Stat |= DISKIO_STA_NOINIT; /* Set DISKIO_STA_NOINIT */
return Stat;
}

Expand All @@ -682,7 +682,7 @@ DSTATUS MCI_initialize(void)
/* Get Disk Status */
/*-----------------------------------------------------------------------*/

DSTATUS MCI_status(void)
diskio_sta_t mci_status(void)
{
return Stat;
}
Expand All @@ -699,25 +699,25 @@ DSTATUS MCI_status(void)
* @param sector Start sector number (LBA)
* @param count Sector count (1..127)
*/
DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
diskio_result_t mci_read(unsigned char *buff, unsigned long sector, unsigned char count)
{
unsigned long resp;
unsigned int cmd;

if (count < 1 || count > 127) {
return RES_PARERR; /* Check parameter */
return DISKIO_RES_PARERR; /* Check parameter */
}

if (Stat & STA_NOINIT) {
return RES_NOTRDY; /* Check drive status */
if (Stat & DISKIO_STA_NOINIT) {
return DISKIO_RES_NOTRDY; /* Check drive status */
}

if (!(CardType & CT_BLOCK)) {
sector *= 512; /* Convert LBA to byte address if needed */
}

if (!wait_ready(500)) {
return RES_ERROR; /* Make sure that card is tran state */
return DISKIO_RES_ERROR; /* Make sure that card is tran state */
}

ready_reception(count, 512); /* Ready to receive data blocks */
Expand All @@ -738,7 +738,7 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
break; /* Abort if any error has occured */
}

Copy_al2un(buff, DmaBuff[rp], 512); /* Pop an block */
copy_al2un(buff, DmaBuff[rp], 512); /* Pop an block */

XferRp = rp = (rp + 1) % N_BUF; /* Next DMA buffer */

Expand All @@ -756,7 +756,7 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)

stop_transfer(); /* Close data path */

return count ? RES_ERROR : RES_OK;
return count ? DISKIO_RES_ERROR : DISKIO_RES_OK;
}


Expand All @@ -771,30 +771,30 @@ DRESULT MCI_read(unsigned char *buff, unsigned long sector, unsigned char count)
* @param sector Start sector number (LBA)
* @param count Sector count (1..127)
* */
DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char count)
diskio_result_t mci_write(const unsigned char *buff, unsigned long sector, unsigned char count)
{
unsigned long rc;
unsigned int cmd;
unsigned char wp, xc;

if (count < 1 || count > 127) {
return RES_PARERR; /* Check parameter */
return DISKIO_RES_PARERR; /* Check parameter */
}

if (Stat & STA_NOINIT) {
return RES_NOTRDY; /* Check drive status */
if (Stat & DISKIO_STA_NOINIT) {
return DISKIO_RES_NOTRDY; /* Check drive status */
}

if (Stat & STA_PROTECT) {
return RES_WRPRT; /* Check write protection */
if (Stat & DISKIO_STA_PROTECT) {
return DISKIO_RES_WRPRT; /* Check write protection */
}

if (!(CardType & CT_BLOCK)) {
sector *= 512; /* Convert LBA to byte address if needed */
}

if (!wait_ready(500)) {
return RES_ERROR; /* Make sure that card is tran state */
return DISKIO_RES_ERROR; /* Make sure that card is tran state */
}

if (count == 1) { /* Single block write */
Expand All @@ -805,22 +805,22 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char

if (!send_cmd(cmd, count, 1, &rc) /* Preset number of blocks to write */
|| (rc & 0xC0580000)) {
return RES_ERROR;
return DISKIO_RES_ERROR;
}

cmd = CMD25;
}

if (!send_cmd(cmd, sector, 1, &rc) /* Send a write command */
|| (rc & 0xC0580000)) {
return RES_ERROR;
return DISKIO_RES_ERROR;
}

wp = 0;
xc = count;

do { /* Fill block FIFO */
Copy_un2al(DmaBuff[wp], (unsigned char *)(unsigned int)buff, 512); /* Push a block */
copy_un2al(DmaBuff[wp], (unsigned char *)(unsigned int)buff, 512); /* Push a block */
wp++; /* Next DMA buffer */
count--;
buff += 512; /* Next user buffer address */
Expand All @@ -839,7 +839,7 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
break; /* Abort if block underrun or any MCI error has occured */
}

Copy_un2al(DmaBuff[wp], (unsigned char *)(unsigned int)buff, 512); /* Push a block */
copy_un2al(DmaBuff[wp], (unsigned char *)(unsigned int)buff, 512); /* Push a block */
XferWp = wp = (wp + 1) % N_BUF; /* Next DMA buffer */

if (XferStat & 0xC) {
Expand All @@ -862,7 +862,7 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
send_cmd(CMD12, 0, 1, &rc);
}

return count ? RES_ERROR : RES_OK;
return count ? DISKIO_RES_ERROR : DISKIO_RES_OK;
}
#endif /* _READONLY */

Expand All @@ -873,26 +873,26 @@ DRESULT MCI_write(const unsigned char *buff, unsigned long sector, unsigned char
/* Miscellaneous Functions */
/*-----------------------------------------------------------------------*/

DRESULT MCI_ioctl(
diskio_result_t mci_ioctl(
unsigned char ctrl, /* Control code */
void *buff /* Buffer to send/receive data block */
)
{
DRESULT res;
diskio_result_t res;
unsigned char *ptr = (unsigned char *)buff;
unsigned long resp[4], d, *dp, st, ed;


if (Stat & STA_NOINIT) {
return RES_NOTRDY;
if (Stat & DISKIO_STA_NOINIT) {
return DISKIO_RES_NOTRDY;
}

res = RES_ERROR;
res = DISKIO_RES_ERROR;

switch(ctrl) {
case CTRL_SYNC : /* Make sure that all data has been written on the media */
if (wait_ready(500)) { /* Wait for card enters tarn state */
res = RES_OK;
res = DISKIO_RES_OK;
}

break;
Expand All @@ -908,12 +908,12 @@ DRESULT MCI_ioctl(
*(unsigned long *)buff = d << (b - 9);
}

res = RES_OK;
res = DISKIO_RES_OK;
break;

case GET_SECTOR_SIZE : /* Get sectors on the disk (unsigned short) */
*(unsigned short *)buff = 512;
res = RES_OK;
res = DISKIO_RES_OK;
break;

case GET_BLOCK_SIZE : /* Get erase block size in unit of sectors (unsigned long) */
Expand All @@ -929,7 +929,7 @@ DRESULT MCI_ioctl(
}
}

res = RES_OK;
res = DISKIO_RES_OK;
break;

case CTRL_ERASE_SECTOR : /* Erase a block of sectors */
Expand All @@ -947,7 +947,7 @@ DRESULT MCI_ioctl(
}

if (send_cmd(CMD32, st, 1, resp) && send_cmd(CMD33, ed, 1, resp) && send_cmd(CMD38, 0, 1, resp) && wait_ready(30000)) {
res = RES_OK;
res = DISKIO_RES_OK;
}

break;
Expand All @@ -956,38 +956,38 @@ DRESULT MCI_ioctl(
switch(ptr[0]) {
case 0: /* Sub control code == 0 (POWER_OFF) */
power_off(); /* Power off */
res = RES_OK;
res = DISKIO_RES_OK;
break;

case 1: /* Sub control code == 1 (POWER_GET) */
ptr[1] = (unsigned char)power_status();
res = RES_OK;
res = DISKIO_RES_OK;
break;

default :
res = RES_PARERR;
res = DISKIO_RES_PARERR;
}

break;

case MMC_GET_TYPE : /* Get card type flags (1 byte) */
*ptr = CardType;
res = RES_OK;
res = DISKIO_RES_OK;
break;

case MMC_GET_CSD : /* Get CSD (16 bytes) */
memcpy(buff, &CardInfo[0], 16);
res = RES_OK;
res = DISKIO_RES_OK;
break;

case MMC_GET_CID : /* Get CID (16 bytes) */
memcpy(buff, &CardInfo[16], 16);
res = RES_OK;
res = DISKIO_RES_OK;
break;

case MMC_GET_OCR : /* Get OCR (4 bytes) */
memcpy(buff, &CardInfo[32], 4);
res = RES_OK;
res = DISKIO_RES_OK;
break;

case MMC_GET_SDSTAT : /* Receive SD status as a data block (64 bytes) */
Expand All @@ -1000,8 +1000,8 @@ DRESULT MCI_ioctl(
while ((XferWp == 0) && !(XferStat & 0xC)) {}

if (!(XferStat & 0xC)) {
Copy_al2un((unsigned char *)buff, DmaBuff[0], 64);
res = RES_OK;
copy_al2un((unsigned char *)buff, DmaBuff[0], 64);
res = DISKIO_RES_OK;
}
}
}
Expand All @@ -1012,7 +1012,7 @@ DRESULT MCI_ioctl(
break;

default:
res = RES_PARERR;
res = DISKIO_RES_PARERR;
}

return res;
Expand Down
Loading

0 comments on commit 3fa8a26

Please sign in to comment.