Cosmetics
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -18,7 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../opentx.h"
|
||||
#include "opentx.h"
|
||||
|
||||
void getModelPath(char * path, const char * filename)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -25,8 +25,8 @@
|
||||
/* are platform dependent. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "../opentx.h"
|
||||
#include "../FatFs/diskio.h"
|
||||
#include "opentx.h"
|
||||
#include "diskio.h"
|
||||
|
||||
/* Definitions for MMC/SDC command */
|
||||
#define CMD0 (0) /* GO_IDLE_STATE */
|
||||
@@ -73,9 +73,9 @@
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
|
||||
|
||||
Module Private Functions
|
||||
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
static volatile
|
||||
@@ -145,7 +145,7 @@ int wait_ready (void) /* 1:OK, 0:Timeout */
|
||||
do
|
||||
if (rcvr_spi() == 0xFF) return 1;
|
||||
while (Timer2);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ void power_on (void)
|
||||
#endif
|
||||
//PORTB = 0b10110101; // Enable drivers
|
||||
//DDRB = 0b11000111;
|
||||
|
||||
|
||||
SPCR = 0x52; // Enable SPI function in mode 0
|
||||
SPSR = 0x00; // G: was 0x01; // SPI 2x mode
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void power_off (void)
|
||||
SPCR = 0; /* Disable SPI function */
|
||||
// DDRB = 0b11000000; /* Disable drivers */
|
||||
// PORTB = 0b10110000;
|
||||
|
||||
|
||||
// PORTE |= 0x80; /* Socket power off */
|
||||
Stat |= STA_NOINIT;
|
||||
}
|
||||
@@ -233,14 +233,14 @@ int rcvr_datablock (
|
||||
)
|
||||
{
|
||||
BYTE token;
|
||||
|
||||
|
||||
|
||||
|
||||
Timer1 = 20;
|
||||
do { /* Wait for data packet in timeout of 200ms */
|
||||
token = rcvr_spi();
|
||||
} while ((token == 0xFF) && Timer1);
|
||||
if(token != 0xFE) return 0; /* If not valid data token, retutn with error */
|
||||
|
||||
|
||||
do { /* Receive the data block into buffer */
|
||||
rcvr_spi_m(buff++);
|
||||
rcvr_spi_m(buff++);
|
||||
@@ -249,7 +249,7 @@ int rcvr_datablock (
|
||||
} while (btr -= 4);
|
||||
rcvr_spi(); /* Discard CRC */
|
||||
rcvr_spi();
|
||||
|
||||
|
||||
return 1; /* Return with success */
|
||||
}
|
||||
|
||||
@@ -266,10 +266,10 @@ int xmit_datablock (
|
||||
)
|
||||
{
|
||||
BYTE resp, wc;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!wait_ready()) return 0;
|
||||
|
||||
|
||||
xmit_spi(token); /* Xmit data token */
|
||||
if (token != 0xFD) { /* Is data token */
|
||||
wc = 0;
|
||||
@@ -283,7 +283,7 @@ int xmit_datablock (
|
||||
if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -300,18 +300,18 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
|
||||
)
|
||||
{
|
||||
BYTE n, res;
|
||||
|
||||
|
||||
|
||||
|
||||
if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */
|
||||
cmd &= 0x7F;
|
||||
res = send_cmd(CMD55, 0);
|
||||
if (res > 1) return res;
|
||||
}
|
||||
|
||||
|
||||
/* Select the card and wait for ready */
|
||||
deselect();
|
||||
if (!select()) return 0xFF;
|
||||
|
||||
|
||||
/* Send command packet */
|
||||
xmit_spi(0x40 | cmd); /* Start + Command index */
|
||||
xmit_spi((BYTE)(arg >> 24)); /* Argument[31..24] */
|
||||
@@ -322,23 +322,23 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */
|
||||
if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */
|
||||
if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */
|
||||
xmit_spi(n);
|
||||
|
||||
|
||||
/* Receive command response */
|
||||
if (cmd == CMD12) rcvr_spi(); /* Skip a stuff byte when stop reading */
|
||||
n = 10; /* Wait for a valid response in timeout of 10 attempts */
|
||||
do
|
||||
res = rcvr_spi();
|
||||
while ((res & 0x80) && --n);
|
||||
|
||||
|
||||
return res; /* Return with the response value */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
|
||||
|
||||
Public Functions
|
||||
|
||||
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
@@ -351,15 +351,15 @@ DSTATUS disk_initialize (
|
||||
)
|
||||
{
|
||||
BYTE n, cmd, ty, ocr[4];
|
||||
|
||||
|
||||
|
||||
|
||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||
if (Stat & STA_NODISK) return Stat; /* No card in the socket */
|
||||
|
||||
|
||||
power_on(); /* Force socket power on */
|
||||
FCLK_SLOW();
|
||||
for (n = 10; n; n--) rcvr_spi(); /* 80 dummy clocks */
|
||||
|
||||
|
||||
ty = 0;
|
||||
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
|
||||
Timer1 = 100; /* Initialization timeout of 1000 msec */
|
||||
@@ -385,14 +385,14 @@ DSTATUS disk_initialize (
|
||||
}
|
||||
CardType = ty;
|
||||
deselect();
|
||||
|
||||
|
||||
if (ty) { /* Initialization succeded */
|
||||
Stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
|
||||
FCLK_FAST();
|
||||
} else { /* Initialization failed */
|
||||
power_off();
|
||||
}
|
||||
|
||||
|
||||
return Stat;
|
||||
}
|
||||
|
||||
@@ -425,9 +425,9 @@ DRESULT disk_read (
|
||||
{
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
|
||||
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
|
||||
|
||||
|
||||
if (count == 1) { /* Single block read */
|
||||
if ((send_cmd(CMD17, sector) == 0) /* READ_SINGLE_BLOCK */
|
||||
&& rcvr_datablock(buff, 512))
|
||||
@@ -443,7 +443,7 @@ DRESULT disk_read (
|
||||
}
|
||||
}
|
||||
deselect();
|
||||
|
||||
|
||||
return count ? RES_ERROR : RES_OK;
|
||||
}
|
||||
|
||||
@@ -463,9 +463,9 @@ DRESULT disk_write (
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
if (Stat & STA_PROTECT) return RES_WRPRT;
|
||||
|
||||
|
||||
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
|
||||
|
||||
|
||||
if (count == 1) { /* Single block write */
|
||||
if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
|
||||
&& xmit_datablock(buff, 0xFE))
|
||||
@@ -483,7 +483,7 @@ DRESULT disk_write (
|
||||
}
|
||||
}
|
||||
deselect();
|
||||
|
||||
|
||||
return count ? RES_ERROR : RES_OK;
|
||||
}
|
||||
|
||||
@@ -502,12 +502,12 @@ DRESULT disk_ioctl (
|
||||
DRESULT res;
|
||||
BYTE n, csd[16], *ptr = (BYTE*)buff;
|
||||
WORD csize;
|
||||
|
||||
|
||||
|
||||
|
||||
if (drv) return RES_PARERR;
|
||||
|
||||
|
||||
res = RES_ERROR;
|
||||
|
||||
|
||||
if (ctrl == CTRL_POWER) {
|
||||
switch (ptr[0]) {
|
||||
case 0: /* Sub control code (POWER_OFF) */
|
||||
@@ -524,7 +524,7 @@ DRESULT disk_ioctl (
|
||||
}
|
||||
else {
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
|
||||
switch (ctrl) {
|
||||
case CTRL_SYNC : /* Make sure that no pending write process. Do not remove this or written sector might not left updated. */
|
||||
if (select()) {
|
||||
@@ -532,7 +532,7 @@ DRESULT disk_ioctl (
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
|
||||
if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
|
||||
if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */
|
||||
@@ -546,12 +546,12 @@ DRESULT disk_ioctl (
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case GET_SECTOR_SIZE : /* Get R/W sector size (WORD) */
|
||||
*(WORD*)buff = 512;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
|
||||
case GET_BLOCK_SIZE : /* Get erase block size in unit of sector (DWORD) */
|
||||
if (CardType & CT_SD2) { /* SDv2? */
|
||||
if (send_cmd(ACMD13, 0) == 0) { /* Read SD status */
|
||||
@@ -573,31 +573,31 @@ DRESULT disk_ioctl (
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case MMC_GET_TYPE : /* Get card type flags (1 byte) */
|
||||
*ptr = CardType;
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
|
||||
case MMC_GET_CSD : /* Receive CSD as a data block (16 bytes) */
|
||||
if (send_cmd(CMD9, 0) == 0 /* READ_CSD */
|
||||
&& rcvr_datablock(ptr, 16))
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
|
||||
case MMC_GET_CID : /* Receive CID as a data block (16 bytes) */
|
||||
if (send_cmd(CMD10, 0) == 0 /* READ_CID */
|
||||
&& rcvr_datablock(ptr, 16))
|
||||
res = RES_OK;
|
||||
break;
|
||||
|
||||
|
||||
case MMC_GET_OCR : /* Receive OCR as an R3 resp (4 bytes) */
|
||||
if (send_cmd(CMD58, 0) == 0) { /* READ_OCR */
|
||||
for (n = 4; n; n--) *ptr++ = rcvr_spi();
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case MMC_GET_SDSTAT : /* Receive SD statsu as a data block (64 bytes) */
|
||||
if (send_cmd(ACMD13, 0) == 0) { /* SD_STATUS */
|
||||
rcvr_spi();
|
||||
@@ -605,14 +605,14 @@ DRESULT disk_ioctl (
|
||||
res = RES_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
|
||||
deselect();
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user