#include <otSerial.h>
#include <otTimer.h>
#include <otPrintfLite.h>
#include <otMalloc.h>
#include <otDMA.h>
#define LEN 65536
bool done = false;
U32 st, et;
FAST_CODE_1 void dmaCallback()
{
et = TimerGetCounts(TIMER0);
done = true;
}
void setup()
{
UartEnableSignals(UART0);
UartSetBaud(UART0, 115200);
setStdout(UART0);
_initMalloc();
TimerSetAsCounter(TIMER0);
TimerEnable(TIMER0, true);
DelayMs(2000);
}
void loop()
{
U32 * src, * dst;
printf("Start DMA test\n");
DmaSetInterruptService(DMA_CH_0, dmaCallback);
src = (U32 *) _malloc(sizeof(U32) * LEN);
dst = (U32 *) _malloc(sizeof(U32) * LEN);
st = TimerGetCounts(TIMER0);
for(U32 i = 0; i < LEN; i++)
src[i] = i;
et = TimerGetCounts(TIMER0);
printf("Memory fill elapsed time: %u uS\n", ElapsedTimeUs(st, et));
st = TimerGetCounts(TIMER0);
DmaMove(DMA_CH_0, src, dst, LEN, DMA_DWORD);
while(!done) DelayUs(100);
printf("DMA transfer elapsed time: %u uS\n", ElapsedTimeUs(st, et));
st = TimerGetCounts(TIMER0);
for(U32 i = 0; i < LEN; i++)
if(dst[i] != i)
{
printf("Compare fail at [%d]\n", i);
goto end;
}
et = TimerGetCounts(TIMER0);
printf("Memory verify elapsed time: %u uS\n", ElapsedTimeUs(st, et));
printf("Test OK\n");
DmaEnableInterrupt(DMA_CH_0, false);
end:
DelayMs(10);
IDLE;
}