209 lines
8.6 KiB
C
209 lines
8.6 KiB
C
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
|
|
|
/*=======Test Runner Used To Run Each Test Below=====*/
|
|
#define RUN_TEST(TestFunc, TestLineNum) \
|
|
{ \
|
|
Unity.CurrentTestName = #TestFunc; \
|
|
Unity.CurrentTestLineNumber = TestLineNum; \
|
|
Unity.NumberOfTests++; \
|
|
if (TEST_PROTECT()) { \
|
|
setUp(); \
|
|
TestFunc(); \
|
|
} \
|
|
if (TEST_PROTECT()) { \
|
|
tearDown(); \
|
|
} \
|
|
UnityConcludeTest(); \
|
|
}
|
|
|
|
/*=======Automagically Detected Files To Include=====*/
|
|
#include "unity.h"
|
|
#include <setjmp.h>
|
|
#include <stdio.h>
|
|
#include <dma.h>
|
|
#include "set_dma/set_dma.h"
|
|
|
|
/*======= Functions This Runner Calls=====*/
|
|
#include <Driver_GPDMA.h>
|
|
|
|
uint8_t ch = 1;
|
|
extern uint32_t src_buf[MAX_LEN];
|
|
extern uint32_t dst_buf[MAX_LEN];
|
|
|
|
void setUp(void)
|
|
{
|
|
/* This is run before EACH TEST */
|
|
dma_initialize();
|
|
set_dma_mem_init(TOTAL_BYTES);
|
|
}
|
|
|
|
void tearDown(void)
|
|
{
|
|
dma_uninitialize();
|
|
set_dma_mem_uninit(TOTAL_BYTES);
|
|
}
|
|
|
|
void test_dma_memcpy_is_ok(void)
|
|
{
|
|
// 正常传输
|
|
uint32_t src_addr = (uint32_t)src_buf;
|
|
uint32_t dst_addr = (uint32_t)dst_buf;
|
|
uint32_t total_bytes = TOTAL_BYTES;
|
|
TEST_ASSERT_EQUAL(true, set_dma_memcpy(src_addr, dst_addr, total_bytes, DMA_CACHE_SYNC_AUTO));
|
|
TEST_ASSERT_EQUAL(true, set_dma_memcpy(src_addr+2, dst_addr+2, total_bytes-2, DMA_CACHE_SYNC_AUTO));
|
|
TEST_ASSERT_EQUAL(true, set_dma_memcpy(src_addr+1, dst_addr+1, total_bytes-1, DMA_CACHE_SYNC_AUTO));
|
|
}
|
|
|
|
void test_dma_configure(void)
|
|
{
|
|
uint8_t ch, ch_sel;
|
|
// 测试 DMA 配置
|
|
for (ch = 0; ch < DMA_NUMBER_OF_CHANNELS; ch++) // DMA_NUMBER_OF_CHANNELS
|
|
{
|
|
// DMA configure 0: src/dst addr WORD aligned
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_polling(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_16, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
//DMA configure 1: src/dst addr WORD aligned
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_16, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 2: src/dst addr HALFWORD aligned
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_HALFWORD, DMA_BSIZE_16, DMA_WIDTH_HALFWORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 3: src/dst addr BYTE aligned
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_BYTE, DMA_BSIZE_16, DMA_WIDTH_BYTE, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 7: dst BYTE aligned, burst_size = 64
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_16, DMA_WIDTH_BYTE, DMA_BSIZE_64, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 8: src BYTE aligned, burst_size = 64
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_BYTE, DMA_BSIZE_64, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 9: src/dst addr decrease
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_16, DMA_WIDTH_WORD, DMA_BSIZE_16, true, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 10: burst size 1
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_1, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// // DMA configure 11: burst size 4
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_4, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 12: burst size 8
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_8, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 13: burst size 32
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_32, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 14: burst size 64
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_64, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// // DMA configure 15: burst size 128
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_128, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 16: burst size 256
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_256, DMA_WIDTH_WORD, DMA_BSIZE_16, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 17: burst size 32 (dst)
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure(&ch_sel, DMA_WIDTH_WORD, DMA_BSIZE_16, DMA_WIDTH_WORD, DMA_BSIZE_32, false, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 18: Src Gather
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_srcgather(&ch_sel, DMA_CACHE_SYNC_AUTO));
|
|
|
|
// DMA configure 19: Dst Scatter
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_dstscatter(&ch_sel, DMA_CACHE_SYNC_AUTO));
|
|
} // end for ch
|
|
}
|
|
|
|
void test_dma_suspend_resume(void)
|
|
{
|
|
uint8_t ch, ch_sel;
|
|
|
|
for (ch = 0; ch < DMA_NUMBER_OF_CHANNELS; ch++) // DMA_NUMBER_OF_CHANNELS
|
|
{
|
|
// DMA configure 21: initially SUSP only
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_suspen(&ch_sel, DMA_CACHE_SYNC_AUTO, true));
|
|
|
|
// // DMA configure 22: SUSP + Enable
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_suspen(&ch_sel, DMA_CACHE_SYNC_AUTO, false));
|
|
|
|
// DMA configure 23: Disable channel only
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_dis(&ch_sel, DMA_CACHE_SYNC_AUTO, true));
|
|
|
|
// DMA configure 24: Start Xfer, and then SUSP only
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_suspresm(&ch_sel, DMA_CACHE_SYNC_AUTO, true));
|
|
|
|
// DMA configure 25: Start Xfer, and then SUSP & Resume
|
|
ch_sel = ch;
|
|
TEST_ASSERT_EQUAL(true, set_dma_configure_suspresm(&ch_sel, DMA_CACHE_SYNC_AUTO, false));
|
|
}
|
|
}
|
|
|
|
void test_dma_channel_enable(void)
|
|
{
|
|
TEST_ASSERT_EQUAL(0, dma_channel_enable(ch));
|
|
TEST_ASSERT_EQUAL(-1, dma_channel_enable(DMA_NUMBER_OF_CHANNELS));
|
|
}
|
|
|
|
void test_dma_channel_disable(void)
|
|
{
|
|
// 测试使能 DMA 通道
|
|
TEST_ASSERT_EQUAL(0, dma_channel_disable(ch, 0));
|
|
TEST_ASSERT_EQUAL(-1, dma_channel_disable(DMA_NUMBER_OF_CHANNELS, 0));
|
|
}
|
|
|
|
void test_dma_channel_is_enabled(void)
|
|
{
|
|
// 测试超出范围
|
|
TEST_ASSERT_EQUAL(false, dma_channel_is_enabled(DMA_NUMBER_OF_CHANNELS));
|
|
// 测试通道是否使能
|
|
TEST_ASSERT_EQUAL(false, dma_channel_is_enabled(ch));
|
|
}
|
|
|
|
void test_dma_channel_get_status(void)
|
|
{
|
|
// 测试通道状态
|
|
TEST_ASSERT_EQUAL(0, dma_channel_get_status(ch));
|
|
}
|
|
|
|
/*=======Test Reset Option=====*/
|
|
void resetTest(void);
|
|
void resetTest(void)
|
|
{
|
|
tearDown();
|
|
setUp();
|
|
}
|
|
|
|
/*=======MAIN=====*/
|
|
int main(void)
|
|
{
|
|
UnityBegin("test/derivers/dma/test_dma.c");
|
|
RUN_TEST(test_dma_memcpy_is_ok, __LINE__);
|
|
RUN_TEST(test_dma_configure, __LINE__);
|
|
RUN_TEST(test_dma_channel_enable, __LINE__);
|
|
RUN_TEST(test_dma_channel_disable, __LINE__);
|
|
RUN_TEST(test_dma_channel_is_enabled, __LINE__);
|
|
RUN_TEST(test_dma_channel_get_status, __LINE__);
|
|
RUN_TEST(test_dma_suspend_resume, __LINE__);
|
|
return (UnityEnd());
|
|
}
|