Currently I'm using the following code for the FIFO reading at it works well for my needs. As I mentioned before - it is optimized for huge data blocks transfers like MSD implementation and probably is not the best in other particular cases.
Code: Select all
static inline void otg_fifo_read_to_buffer(volatile uint32_t *fifop,
uint8_t *buf,
size_t n,
size_t max) {
uint32_t w;
size_t cnt = n;
while(cnt)
{
w = *fifop;
if(cnt <= 4)
{
/* Slower but it happens just once! */
while(cnt)
{
*buf++ = (uint8_t)w;
w >>= 8;
cnt--;
}
if(n > max)
{
/* When this happens??? */
n -= max;
while(n)
{
w = *fifop;
if(n <= 4)
break;
else
n -= 4;
}
}
}
else
{
*((uint32_t *)buf) = w;
cnt -= 4;
buf += 4;
}
}
}