236 lines
11 KiB
C
Executable File
236 lines
11 KiB
C
Executable File
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#include "os_types.h"
|
|
#include "os_mem_api.h"
|
|
#include "dbg_io.h"
|
|
#include "iot_diag.h"
|
|
#include "iot_io.h"
|
|
#include "ahb_hw.h"
|
|
#include "cpu.h"
|
|
#include "math.h"
|
|
#include "apb_dma.h"
|
|
#include "dma_sw.h"
|
|
#include <math.h>
|
|
|
|
#include "iot_sw_dma_api.h"
|
|
|
|
#define SW_DMA_LOG2 (1 << 1)
|
|
#define SW_DMA_EXP2 (1 << 2)
|
|
#define SW_DMA_INVR (1 << 6)
|
|
|
|
#define TEST_CASE_ALL ( SW_DMA_LOG2 | SW_DMA_EXP2| SW_DMA_INVR )
|
|
|
|
#define SW_DMA_TEST_CASE (TEST_CASE_ALL)
|
|
|
|
desc_sw_t input_descls[2];
|
|
desc_sw_t output_descls[2];
|
|
|
|
float output_buf[512] = {0};
|
|
float output_cpu[512] = {0};
|
|
float sw_out[512] = {0};
|
|
float output_min = 0;
|
|
float output_max = 0;
|
|
float output_sum = 0;
|
|
uint32_t output_index = 0;
|
|
int32_t sw_int[512] = {0};
|
|
|
|
volatile uint8_t g_sw_dma_done = 0;
|
|
|
|
float input_float_512[] = {
|
|
0.23467,0.123671,0.30809,12312.123,3,6,6,4,11,8,5,3,4,12,-9,0,8,16,33,10,64,53,50,86,94,153,96,169,161,75,255,140,237,420,376,366,398,449,529,466,436,714,741,698,853,1003,832,1054,933,1264,1378,1126,1521,1531,1575,1303,1283,1232,798,651,926,1326,1081,738,675,835,501,626,378,214,520,-328,-590,-973,-910,-864,-1422,-1457,-2618,-2505,-2845,-2937,-2924,-3949,-3812,-3866,-3861,-4391,-5123,-4357,-5302,-5279,-5514,-6363,-6553,-6502,-6552,-8196,-7717,-8082,-6694,-7123,-9027,-8134,-8843,-9073,-8122,-8210,-8603,-8250,-9866,-9880,-10076,-11688,-12243,-12179,-12011,-11782,-11492,-11498,-11083,-10389,-11062,-11534,-11300,-11335,-10973,-12649,-12634,-11037,-10638,-10945,-10530,-9796,-9971,-10586,-11211,-9543,-10683,-11520,-9592,-9493,-12024,-13512,-9928,-10654,-11815,-10440,-11616,-12379,-12642,-12759,-11761,-9389,-9700,-10015,-9177,-9334,-10198,-8623,-7577,-8765,-7214,-8171,-7741,-6971,-5770,-5729,-5008,-4617,-4306,-1040,-1484,-703,-1505,-1158,1435,541,2363,91,920,3149,3913,2437,942,3129,2670,959,964,3005,5750,5486,5810,6235,7360,8696,10144,10796,10948,10590,7159,10067,10832,8598,9986,10444,9856,8420,10248,10392,7024,9399,10074,11076,9709,9091,13028,11542,11904,12706,11094,10904,15128,15831,13651,10680,9701,13411,10192,7632,4161,4732,4289,5541,8836,3517,5455,3300,3989,3081,4456,3203,3665,1605,-344,2297,-459,5751,3107,1151,7259,4956,6457,3114,4153,7499,4845,6807,6460,6113,10954,10950,10370,8983,8632,11732,8736,8039,6655,8139,7673,5720,5256,3994,7294,4780,3523,2383,-793,-565,225,450,-787,1122,560,-558,-780,-1001,3773,1439,3644,1982,878,1971,-1092,2831,3257,1298,1726,5376,4929,5660,7450,1908,6339,4736,2936,4595,3953,9013,6912,6985,9921,11099,10340,10998,9842,7696,9151,8314,7878,8622,9064,8241,7811,11028,10967,11948,11031,12561,11554,12133,13992,16833,19181,15084,16063,18008,15762,16887,17032,15699,17311,18127,17401,19378,18230,15602,16636,17241,19131,20105,21856,21834,21652,20925,19821,21560,21372,19529,19800,19324,20169,19691,18500,20170,18918,18245,17718,18904,17699,16580,16273,14400,14051,12937,13238,11713,12634,12245,11196,10168,8747,9811,6692,5128,5402,4111,5046,5090,2992,3217,3174,2925,3138,2196,1870,2523,1434,754,789,365,-630,-1242,-829,-472,-1142,-1248,-573,-926,-1069,-1050,-1262,-2293,-2363,-2176,-1566,-2027,-1750,-1750,-3137,-2688,-2000,-2303,-2683,-1881,-2164,-1346,-1625,-1261,-1207,-1337,-1025,-1879,-758,-884,-909,-1046,-1176,-346,-421,-349,-1100,-1227,-871,-884,-859,-643,-219,-229,-190,-370,-164,-434,-672,-596,-314,-733,-610,-247,-681,-535,-410,-779,-592,-560,-527,-480,-837,-455,-547,-571,-470,-654,-603,-525,-531,-586,-564,-434,-381,-317,-166,-267,-236,-257,-218,-121,-144,-143,-175,-125,-110,-107,-123,-157,-146,-92,-66,-49,-66,-51,-43,-34,-24,-20,-12,-7,-6,-3,-1,0,
|
|
};
|
|
int32_t input_real_512[] = {
|
|
0,0,0,1,3,6,6,4,11,8,5,3,4,12,-9,0,8,16,33,10,64,53,50,86,94,153,96,169,161,75,255,140,237,420,376,366,398,449,529,466,436,714,741,698,853,1003,832,1054,933,1264,1378,1126,1521,1531,1575,1303,1283,1232,798,651,926,1326,1081,738,675,835,501,626,378,214,520,-328,-590,-973,-910,-864,-1422,-1457,-2618,-2505,-2845,-2937,-2924,-3949,-3812,-3866,-3861,-4391,-5123,-4357,-5302,-5279,-5514,-6363,-6553,-6502,-6552,-8196,-7717,-8082,-6694,-7123,-9027,-8134,-8843,-9073,-8122,-8210,-8603,-8250,-9866,-9880,-10076,-11688,-12243,-12179,-12011,-11782,-11492,-11498,-11083,-10389,-11062,-11534,-11300,-11335,-10973,-12649,-12634,-11037,-10638,-10945,-10530,-9796,-9971,-10586,-11211,-9543,-10683,-11520,-9592,-9493,-12024,-13512,-9928,-10654,-11815,-10440,-11616,-12379,-12642,-12759,-11761,-9389,-9700,-10015,-9177,-9334,-10198,-8623,-7577,-8765,-7214,-8171,-7741,-6971,-5770,-5729,-5008,-4617,-4306,-1040,-1484,-703,-1505,-1158,1435,541,2363,91,920,3149,3913,2437,942,3129,2670,959,964,3005,5750,5486,5810,6235,7360,8696,10144,10796,10948,10590,7159,10067,10832,8598,9986,10444,9856,8420,10248,10392,7024,9399,10074,11076,9709,9091,13028,11542,11904,12706,11094,10904,15128,15831,13651,10680,9701,13411,10192,7632,4161,4732,4289,5541,8836,3517,5455,3300,3989,3081,4456,3203,3665,1605,-344,2297,-459,5751,3107,1151,7259,4956,6457,3114,4153,7499,4845,6807,6460,6113,10954,10950,10370,8983,8632,11732,8736,8039,6655,8139,7673,5720,5256,3994,7294,4780,3523,2383,-793,-565,225,450,-787,1122,560,-558,-780,-1001,3773,1439,3644,1982,878,1971,-1092,2831,3257,1298,1726,5376,4929,5660,7450,1908,6339,4736,2936,4595,3953,9013,6912,6985,9921,11099,10340,10998,9842,7696,9151,8314,7878,8622,9064,8241,7811,11028,10967,11948,11031,12561,11554,12133,13992,16833,19181,15084,16063,18008,15762,16887,17032,15699,17311,18127,17401,19378,18230,15602,16636,17241,19131,20105,21856,21834,21652,20925,19821,21560,21372,19529,19800,19324,20169,19691,18500,20170,18918,18245,17718,18904,17699,16580,16273,14400,14051,12937,13238,11713,12634,12245,11196,10168,8747,9811,6692,5128,5402,4111,5046,5090,2992,3217,3174,2925,3138,2196,1870,2523,1434,754,789,365,-630,-1242,-829,-472,-1142,-1248,-573,-926,-1069,-1050,-1262,-2293,-2363,-2176,-1566,-2027,-1750,-1750,-3137,-2688,-2000,-2303,-2683,-1881,-2164,-1346,-1625,-1261,-1207,-1337,-1025,-1879,-758,-884,-909,-1046,-1176,-346,-421,-349,-1100,-1227,-871,-884,-859,-643,-219,-229,-190,-370,-164,-434,-672,-596,-314,-733,-610,-247,-681,-535,-410,-779,-592,-560,-527,-480,-837,-455,-547,-571,-470,-654,-603,-525,-531,-586,-564,-434,-381,-317,-166,-267,-236,-257,-218,-121,-144,-143,-175,-125,-110,-107,-123,-157,-146,-92,-66,-49,-66,-51,-43,-34,-24,-20,-12,-7,-6,-3,-1,0,
|
|
};
|
|
|
|
void IRAM_ATTR dma_test_handler(int vector, int status)
|
|
{
|
|
(void)vector;
|
|
|
|
if (status & 8) {
|
|
g_sw_dma_done = 1;
|
|
}
|
|
}
|
|
|
|
void sw_dma_test(void *dest, void *src, uint16_t total_len, uint8_t op)
|
|
{
|
|
uint8_t *d = (uint8_t *) dest;
|
|
uint8_t *s = (uint8_t *) src;
|
|
|
|
|
|
#if 1
|
|
uint32_t fp_op = DMA_FP_CFG(1, 0, 0, 0, op, 1);
|
|
DMA_MAKE_SW_DESC(&input_descls[0], s, fp_op, total_len,
|
|
1, 0, 0, DESC_OWNER_DMA, 0);
|
|
#endif
|
|
|
|
DMA_MAKE_SW_DESC(&output_descls[0], d, 0, total_len,
|
|
1, 0, 0, DESC_OWNER_DMA, 0);
|
|
|
|
g_sw_dma_done = 0;
|
|
|
|
dma_sw_start(0, output_descls, input_descls);
|
|
|
|
volatile uint32_t *reg = (volatile uint32_t *) 0x0130010c; //DMA_SW_RF_BASEADDR
|
|
volatile uint32_t *clr = (volatile uint32_t *) 0x01300118;
|
|
while(1) {
|
|
if (*reg & 8) {
|
|
// clear
|
|
*clr = 0xffffffff;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
void dma_float_test()
|
|
{
|
|
uint32_t i = 0;
|
|
for(i = 0; i < 512; i++) {
|
|
//sw_out[i] = sqrtf(input_float_512[i]);
|
|
//sw_out[i] = log2f(input_float_512[i]);
|
|
//sw_out[i] = exp2f(input_float_512[i]);
|
|
//sw_out[i] = (float) input_real_512[i];
|
|
}
|
|
|
|
sw_dma_test(output_buf, input_float_512, 512*4, 6);
|
|
iot_printf("test : %f\n", output_buf[0]);
|
|
|
|
}
|
|
|
|
void dma_test_init()
|
|
{
|
|
dma_sw_init(DMA_SW_TYPE_POLL);
|
|
|
|
dma_sw_open(0, (dma_int_handler)dma_test_handler, NULL);
|
|
}
|
|
|
|
void dma_api_test()
|
|
{
|
|
#if (SW_DMA_TEST_CASE & SW_DMA_INVR) // 1/x
|
|
; // iot_printf("test inverse root\n");
|
|
iot_dma_sw_cfg(output_buf, input_float_512, 512*4, DMA_FP_INVR, NULL);
|
|
|
|
iot_dma_sw_start(0);
|
|
iot_printf("\r\n-----------------------------------------------------------------------\n");
|
|
iot_printf("inverse sw dma output:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
if (i%20 == 0)
|
|
iot_printf("\n");
|
|
iot_printf("0x%08x ", output_buf[i]);
|
|
output_cpu[i] = 1/input_float_512[i];
|
|
}
|
|
iot_printf("\r\ninverse sw output:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
if (i%20 == 0)
|
|
iot_printf("\n");
|
|
iot_printf("0x%08x ", output_cpu[i]);
|
|
}
|
|
#endif
|
|
|
|
#if (SW_DMA_TEST_CASE & SW_DMA_LOG2) // log2
|
|
iot_printf("test log2:\n");
|
|
iot_dma_sw_cfg(output_buf, input_float_512, 512*4, DMA_FP_LOG2, NULL);
|
|
|
|
iot_dma_sw_start(0);
|
|
|
|
iot_printf("log2 sw dma output:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
if (i%20 == 0)
|
|
iot_printf("\n");
|
|
iot_printf("0x%08x ", output_buf[i]);
|
|
sw_out[i] = log2f(input_float_512[i]);
|
|
}
|
|
iot_printf("\r\nlog2 sw output:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
if (i%20 == 0)
|
|
iot_printf("\n");
|
|
iot_printf("0x%08x ", sw_out[i]);
|
|
}
|
|
#endif
|
|
|
|
#if (SW_DMA_TEST_CASE & SW_DMA_EXP2) // log2
|
|
iot_printf("test exp2:\n");
|
|
iot_dma_sw_cfg(output_buf, input_float_512, 512*4, DMA_FP_EXP2, NULL);
|
|
|
|
iot_dma_sw_start(0);
|
|
|
|
iot_printf("exp2 sw dma output:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
if (i%20 == 0)
|
|
iot_printf("\n");
|
|
iot_printf("0x%08x ", output_buf[i]);
|
|
sw_out[i] = exp2f(input_float_512[i]);
|
|
}
|
|
iot_printf("\r\nexp2 sw output:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
if (i%20 == 0)
|
|
iot_printf("\n");
|
|
iot_printf("0x%08x ", sw_out[i]);
|
|
}
|
|
#endif
|
|
|
|
|
|
return;
|
|
}
|
|
|
|
void dma_api_test_1()
|
|
{
|
|
#if 1 // log2
|
|
iot_printf("test log2\n");
|
|
iot_dma_sw_cfg(output_buf, input_float_512, 512*4, DMA_FP_LOG2, NULL);
|
|
iot_dma_sw_start(0);
|
|
iot_fp_ctrl_t fp_ctrl = {0};
|
|
fp_ctrl.abs_ena = DMA_ABS_DIS;
|
|
fp_ctrl.fac_cfg = DMA_FAC_IN_MUL;
|
|
fp_ctrl.fac_val = logf(2);
|
|
iot_dma_sw_cfg(sw_out, input_float_512, 512*4, DMA_FP_LOG2, &fp_ctrl);
|
|
|
|
iot_dma_sw_start(0);
|
|
|
|
iot_printf("origin log2:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
iot_printf("0x%08x ", output_buf[i]);
|
|
}
|
|
iot_printf("factor log2:\n");
|
|
for(uint32_t i = 0; i < 512; i++) {
|
|
iot_printf("0x%08x ", sw_out[i]);
|
|
}
|
|
#endif
|
|
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
dbg_uart_init();
|
|
|
|
; //iot_printf("\n-------SW DMA FLOAT TEST---------\n");
|
|
|
|
dma_test_init();
|
|
|
|
iot_dma_sw_init(0);
|
|
|
|
while(1) {
|
|
//dma_float_test();
|
|
dma_api_test();
|
|
//dma_api_test_1();
|
|
}
|
|
|
|
iot_printf("\n-------SW DMA FLOAT TEST FINISH---------\n");
|
|
|
|
return 0;
|
|
}
|