read result of DSPI receiver fifo only after transfer has been finished completely (check with status register)

This commit is contained in:
Markus Fröschle
2013-05-13 14:21:35 +00:00
parent 73b3185497
commit 1874686b84

View File

@@ -193,7 +193,7 @@ static int select(void) /* 1:OK, 0:Timeout */
/*
* 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 */
@@ -233,8 +233,7 @@ static void power_on (void) /* Enable SSP module */
}
static
void power_off (void) /* Disable SPI function */
static void power_off (void) /* Disable SPI function */
{
select(); /* Wait for card ready */
deselect();
@@ -244,20 +243,19 @@ void power_off (void) /* Disable SPI function */
/*-----------------------------------------------------------------------*/
/* Receive a data packet from the MMC */
/*-----------------------------------------------------------------------*/
static
int rcvr_datablock ( /* 1:OK, 0:Error */
uint8_t *buff, /* Data buffer */
uint32_t btr /* Data block length (byte) */
)
static int rcvr_datablock(uint8_t *buff, uint32_t btr)
{
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 */
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);
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 */
xchg_spi(0xFF); xchg_spi(0xFF); /* Discard CRC */
@@ -272,15 +270,10 @@ int rcvr_datablock ( /* 1:OK, 0:Error */
/*-----------------------------------------------------------------------*/
#if _USE_WRITE
static
int xmit_datablock ( /* 1:OK, 0:Failed */
const uint8_t *buff, /* Ponter to 512 byte data to be sent */
uint8_t token /* Token */
)
static int xmit_datablock(const uint8_t *buff, uint8_t token)
{
uint8_t resp;
if (!wait_ready(500)) return 0; /* Wait for card ready */
xchg_spi(token); /* Send token */
@@ -289,6 +282,7 @@ int xmit_datablock ( /* 1:OK, 0:Failed */
xchg_spi(0xFF); xchg_spi(0xFF); /* Dummy CRC */
resp = xchg_spi(0xFF); /* Receive data resp */
if ((resp & 0x1F) != 0x05) /* Function fails if the data packet was not accepted */
return 0;
}