1 //#include <nuttx/config.h>
2 #include <stdio.h>
3
4 #include "MsTypes.h"
5
6 /****************************************************************************
7 * Definitions
8 ****************************************************************************/
9
10 /****************************************************************************
11 * Private Data
12 ****************************************************************************/
13
14 /****************************************************************************
15 * Public Functions
16 ****************************************************************************/
17
18 /****************************************************************************
19 * user_start
20 ****************************************************************************/
21 #include "stdlib.h"
22 //#include "utopia_core.h"
23 #include "utopia.h"
24 #include "MsTypes.h"
25 #include "MsOS.h"
26 #include "drvMMIO.h"
27 #include <stdio.h>
28 #include "drvBDMA_priv.h"
29 #include <string.h>
30 #include <unistd.h>
31 #include "drvMIU.h"
32
33
34
35
36 // enable or diable the BDMA test app
37 #define BDMA_UTOPIA_TEST
38
39 #ifdef BDMA_UTOPIA_TEST
40 #define BDMA_MEMCOPY_TESTCOUNT (10)
41 #endif
42
43
__aeabi_unwind_cpp_pr1(void)44 void __aeabi_unwind_cpp_pr1(void)
45 {
46 }
47
__aeabi_unwind_cpp_pr0(void)48 void __aeabi_unwind_cpp_pr0(void)
49 {
50 }
51
simulateMsosShmInit(void)52 void simulateMsosShmInit(void)
53 {
54 MsOS_SHM_Init();
55 }
56
57 /*__attribute__((weak)) void AESDMARegisterToUtopia(void)
58 {
59 printf("\nweak\n");
60 }
61 __attribute__((weak)) void DSCMBRegisterToUtopia(void)
62 {
63 printf("\nweak\n");
64 }*/
65
66 #ifdef BDMA_UTOPIA_TEST
BDMA_MemChkSum(MS_U32 Addr,MS_U32 len)67 MS_U32 BDMA_MemChkSum(MS_U32 Addr, MS_U32 len)
68 {
69 MS_U8 *s = (MS_U8 *)MsOS_PA2KSEG1(Addr);
70 MS_U32 idx, val = 0x98765432;
71
72 for (idx = 0; idx < len; idx++)
73 val ^= s[idx];
74
75 return val;
76 }
77 #endif //
78
main(int argc,char * argv[])79 int main(int argc, char *argv[])
80 {
81 // simple test
82 #if 0
83 AESDMARegisterToUtopia();
84 return 0;
85 #endif
86
87
88
89 #if 1
90 MS_U32 bEnable;
91 MS_U32 virtaddr;
92 MS_U32* pVirtaddr;
93 bEnable = 1;
94 void* pAttribute = NULL;
95 int i;
96
97
98 MS_U32 bSegment;
99 bSegment = 1;
100
101 // Below is BDMA variable declare part
102 #ifdef BDMA_UTOPIA_TEST
103 void* pInstantBdma;
104 PBDMA_MEMCOPY_PARAM pMemCpyParam;
105 PBDMA_SEARCH_PARAM pSearchParam;
106 MS_U32 virtual_addr;
107 MS_U8* pbyte;
108 MS_U32 checksum=0;
109 MS_U8 freecounter=0;
110 MS_U32 processid=0;
111 MS_U32 memcopycount=0;
112 MS_U32 u32SearchAddr;
113 #endif
114
115
116 MDrv_MMIO_Init();
117 if(TRUE != MsOS_MPool_Init())
118 {
119 printf("MsOS_MPool_Init fail\n");
120 }
121 MDrv_MIU_SetIOMapBase();
122
123 MsOS_MPool_SetDbgLevel(1);
124 MsOS_MPool_Mapping(0, 0x10000000, 0x10000, 2);
125 MsOS_MPool_Mapping(0, 0x10000000, 0x10000, 0);
126 UtopiaInit();
127
128 virtaddr = MsOS_MPool_PA2KSEG1(0x10000000);
129
130 printf("virtaddr = %x\n", virtaddr);
131 pVirtaddr = (MS_U32 *)virtaddr;
132 #if 1
133 *pVirtaddr = 0x01020304;
134 *(pVirtaddr+1) = 0x05060708;
135 *(pVirtaddr+2) = 0x090A0B0C;
136 *(pVirtaddr+3) = 0x0D0E0F00;
137 #else
138 *pVirtaddr = 0x0BD7B8E4;
139 *(pVirtaddr+1) = 0x284939A7;
140 *(pVirtaddr+2) = 0x8C54998D;
141 *(pVirtaddr+3) = 0x1E2F3F57;
142 #endif
143 MsOS_Dcache_Flush(virtaddr, 4);
144
145 // below is the bdma test code
146 #ifdef BDMA_UTOPIA_TEST
147 processid = (MS_U32)getpid();
148 void** ppModule;
149 printf("\n%s, %d\n", __FUNCTION__, __LINE__); // bob.fu
150 if(UtopiaOpen(MODULE_BDMA, &pInstantBdma, 0, pAttribute) < 0)
151
152 {
153 printf("Open BDMA fail\n");
154 return 0;
155 }
156 // BDMA search pattern test code
157 printf("\n%s, %d\n", __FUNCTION__, __LINE__); // bob.fu
158 pSearchParam = (PBDMA_SEARCH_PARAM)utopia_malloc(sizeof(BDMA_SEARCH_PARAM));
159 pSearchParam->u32Addr = 0x10000000;
160 pSearchParam->u32Len = 0x100;
161 pSearchParam->u32Pattern = 0xABABABAB;
162 pSearchParam->u32ExcluBit = 0;
163 pSearchParam->eDev = E_BDMA_SRCDEV_MIU0;
164 virtual_addr=MsOS_PA2KSEG1(pSearchParam->u32Addr);
165 pbyte = (MS_U8*)virtual_addr;
166 pbyte[16] = 0xAB;
167 pbyte[17] = 0xAB;
168 pbyte[18] = 0xAB;
169 pbyte[19] = 0xAB;
170 u32SearchAddr= UtopiaIoctl(pInstantBdma,MDrv_CMD_BDMA_Search,(MS_U32*)pSearchParam);
171 printf("Search Addr is: %lx\n",u32SearchAddr);
172 utopia_free(pSearchParam);
173
174 // BDMA mem copy test code
175 pMemCpyParam = (PBDMA_MEMCOPY_PARAM)utopia_malloc(sizeof(BDMA_MEMCOPY_PARAM));
176 pMemCpyParam->u32SrcAddr = 0x10000000+(processid%10)*0x100;
177 pMemCpyParam->u32DstAddr = 0x10001000+(processid%10)*0x100;
178 pMemCpyParam->u32Len = 0x80;
179 virtual_addr=MsOS_PA2KSEG1(pMemCpyParam->u32SrcAddr);
180 pbyte = (MS_U8*)virtual_addr;
181 while (1)
182 {
183 for (i=0;i<pMemCpyParam->u32Len;i++)
184 {
185 pbyte[i]=freecounter++;
186 }
187 checksum = BDMA_MemChkSum(pMemCpyParam->u32SrcAddr,pMemCpyParam->u32Len);
188 if(UtopiaIoctl(pInstantBdma,MDrv_CMD_BDMA_MemCopy,(MS_U32*)pMemCpyParam) < 0)
189 {
190 printf("Ioctl BDMA Start fail\n");
191 utopia_free(pMemCpyParam);
192 return 0;
193 }
194 if (checksum == BDMA_MemChkSum(pMemCpyParam->u32DstAddr,pMemCpyParam->u32Len))
195 printf("BDMA Copy OK by Process:%d !!\n,",processid);
196 else
197 printf("BDMA Copy FAIL by Process:%d !!\n",processid);
198 //MsOS_DelayTask(50);
199 memcopycount++;
200 if (memcopycount >= BDMA_MEMCOPY_TESTCOUNT)
201 break;
202 }
203 utopia_free(pMemCpyParam);
204
205 if(UtopiaClose(pInstantBdma) < 0)
206 {
207 printf("close BDMA fail\n");
208 return 0;
209 }
210 // bdma test code end here
211 #endif
212
213 printf("\n%s, %d, utopia2 verifation end\n", __FUNCTION__, __LINE__);
214 return 0;
215 #endif
216 }
217