I'm using llc_mmcsd.c from biospsp 3.00.01.00 on a C6746, using a custom board. I need to read from SD card, and in some cases to an unaligned memory address. But then LLC_mmcsdRead fails, and reads into one, two or three bytes before my actual buffer.
I changed the code to:
if ((Uint32)buf % sizeof(Uint32) == 0)
{
// Aligned buffer, fast read: 32 bits at a time
Uint32* readBuf = (Uint32 *) buf;
for (i = 0; i < (numBytes / FIFO_WIDTH_IN_BYTES); i++)
{
*readBuf = regs->MMCDRR;
readBuf++;
}
}
else
{
// Unaligned memory. Slow path: just 8 bits at a time
Uint8* readBuf = (Uint8 *) buf;
Uint32 val;
for (i = 0; i < (numBytes / FIFO_WIDTH_IN_BYTES); i++)
{
val = regs->MMCDRR;
*readBuf++ = (val >> 0) & 0xFF;
*readBuf++ = (val >> 8) & 0xFF;
*readBuf++ = (val >> 16) & 0xFF;
*readBuf++ = (val >> 24) & 0xFF;
}
}
That works for me, but feels a bit ugly. Is there a better way? And in any case, I think the original code needs a patch.
Regards,
Michiel