read result of DSPI receiver fifo only after transfer has been finished completely (check with status register)
This commit is contained in:
@@ -193,7 +193,7 @@ static int select(void) /* 1:OK, 0:Timeout */
|
|||||||
/*
|
/*
|
||||||
* Control SPI module (Platform dependent)
|
* Control SPI module (Platform dependent)
|
||||||
*/
|
*/
|
||||||
static void power_on (void) /* Enable SSP module */
|
static void power_on(void) /* Enable SSP module */
|
||||||
{
|
{
|
||||||
MCF_PAD_PAR_DSPI = 0x1fff; /* configure all DSPI GPIO pins for DSPI usage */
|
MCF_PAD_PAR_DSPI = 0x1fff; /* configure all DSPI GPIO pins for DSPI usage */
|
||||||
|
|
||||||
@@ -233,8 +233,7 @@ static void power_on (void) /* Enable SSP module */
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static
|
static void power_off (void) /* Disable SPI function */
|
||||||
void power_off (void) /* Disable SPI function */
|
|
||||||
{
|
{
|
||||||
select(); /* Wait for card ready */
|
select(); /* Wait for card ready */
|
||||||
deselect();
|
deselect();
|
||||||
@@ -244,20 +243,19 @@ void power_off (void) /* Disable SPI function */
|
|||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* Receive a data packet from the MMC */
|
/* Receive a data packet from the MMC */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
static
|
static int rcvr_datablock(uint8_t *buff, uint32_t btr)
|
||||||
int rcvr_datablock ( /* 1:OK, 0:Error */
|
|
||||||
uint8_t *buff, /* Data buffer */
|
|
||||||
uint32_t btr /* Data block length (byte) */
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
uint8_t token;
|
uint8_t token;
|
||||||
uint32_t target = MCF_SLT_SCNT(0) - (400 * 1000L * 132);
|
uint32_t target = MCF_SLT_SCNT(0) - (200 * 1000L * 132);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This loop will take a time. Insert rot_rdq() here for multitask envilonment.
|
||||||
|
*/
|
||||||
do { /* Wait for DataStart token in timeout of 200ms */
|
do { /* Wait for DataStart token in timeout of 200ms */
|
||||||
token = xchg_spi(0xFF);
|
token = xchg_spi(0xFF);
|
||||||
/* This loop will take a time. Insert rot_rdq() here for multitask envilonment. */
|
|
||||||
} while ((token == 0xFF) && MCF_SLT_SCNT(0) > target);
|
} while ((token == 0xFF) && MCF_SLT_SCNT(0) > target);
|
||||||
if(token != 0xFE) return 0; /* Function fails if invalid DataStart token or timeout */
|
|
||||||
|
if (token != 0xFE) return 0; /* Function fails if invalid DataStart token or timeout */
|
||||||
|
|
||||||
rcvr_spi_multi(buff, btr); /* Store trailing data to the buffer */
|
rcvr_spi_multi(buff, btr); /* Store trailing data to the buffer */
|
||||||
xchg_spi(0xFF); xchg_spi(0xFF); /* Discard CRC */
|
xchg_spi(0xFF); xchg_spi(0xFF); /* Discard CRC */
|
||||||
@@ -272,15 +270,10 @@ int rcvr_datablock ( /* 1:OK, 0:Error */
|
|||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
#if _USE_WRITE
|
#if _USE_WRITE
|
||||||
static
|
static int xmit_datablock(const uint8_t *buff, uint8_t token)
|
||||||
int xmit_datablock ( /* 1:OK, 0:Failed */
|
|
||||||
const uint8_t *buff, /* Ponter to 512 byte data to be sent */
|
|
||||||
uint8_t token /* Token */
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
uint8_t resp;
|
uint8_t resp;
|
||||||
|
|
||||||
|
|
||||||
if (!wait_ready(500)) return 0; /* Wait for card ready */
|
if (!wait_ready(500)) return 0; /* Wait for card ready */
|
||||||
|
|
||||||
xchg_spi(token); /* Send token */
|
xchg_spi(token); /* Send token */
|
||||||
@@ -289,6 +282,7 @@ int xmit_datablock ( /* 1:OK, 0:Failed */
|
|||||||
xchg_spi(0xFF); xchg_spi(0xFF); /* Dummy CRC */
|
xchg_spi(0xFF); xchg_spi(0xFF); /* Dummy CRC */
|
||||||
|
|
||||||
resp = xchg_spi(0xFF); /* Receive data resp */
|
resp = xchg_spi(0xFF); /* Receive data resp */
|
||||||
|
|
||||||
if ((resp & 0x1F) != 0x05) /* Function fails if the data packet was not accepted */
|
if ((resp & 0x1F) != 0x05) /* Function fails if the data packet was not accepted */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user