/client_v4_1/Test/PortingKitTest/Archive/DeviceTests/HAL/AuxTests/Automated/Drivers/RAM/RAM_Test.cpp

# · C++ · 491 lines · 381 code · 63 blank · 47 comment · 66 complexity · 887941e3cb58006831cf32f545d55a0e MD5 · raw file

  1. /*********************************************************************/
  2. /* #includes */
  3. /*********************************************************************/
  4. #include "..\..\..\..\common\AutoTestProtocol.h"
  5. struct RAMTest
  6. {
  7. public:
  8. /*************************************************************/
  9. /* functions */
  10. /*************************************************************/
  11. static void Set32(UINT32 Address, UINT32 Value)
  12. {
  13. volatile UINT32 *Pt;
  14. Pt = (UINT32 *)Address;
  15. *Pt = Value;
  16. }
  17. static void Set16(UINT32 Address, UINT16 Value)
  18. {
  19. volatile UINT16 *Pt;
  20. Pt = (UINT16 *)Address;
  21. *Pt = Value;
  22. }
  23. static void Set8(UINT32 Address, UINT8 Value)
  24. {
  25. volatile UINT8 *Pt;
  26. Pt = (UINT8 *)Address;
  27. *Pt = Value;
  28. }
  29. static BOOL CheckSet32(UINT32 Address,UINT32 MySet,UINT32 MyCheck)
  30. {
  31. volatile UINT32 *Pt;
  32. UINT32 Temp;
  33. BOOL result;
  34. result = TRUE;
  35. Pt = (UINT32 *)Address;
  36. Temp = *Pt;
  37. if (Temp != MyCheck)
  38. {
  39. result = FALSE;
  40. HalTest_print_info("Error at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
  41. }
  42. else
  43. {
  44. //printf("OK at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
  45. }
  46. if (MySet)
  47. {
  48. Set32(Address,MySet);
  49. }
  50. return result;
  51. }
  52. static BOOL CheckSet16(UINT32 Address,UINT16 MySet,UINT16 MyCheck)
  53. {
  54. volatile UINT16 *Pt;
  55. UINT16 Temp;
  56. BOOL result;
  57. result = TRUE;
  58. Pt = (UINT16 *)Address;
  59. Temp = *Pt;
  60. if (Temp != MyCheck)
  61. {
  62. result = FALSE;
  63. HalTest_print_info("Error at memory location %08x: Set to %04x Read as %04x\r\n",Address,MyCheck,Temp);
  64. }
  65. else
  66. {
  67. //printf("OK at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
  68. }
  69. if (MySet)
  70. {
  71. Set16(Address,MySet);
  72. }
  73. return result;
  74. }
  75. static BOOL CheckSet8(UINT32 Address,UINT8 MySet,UINT8 MyCheck)
  76. {
  77. volatile UINT8 *Pt;
  78. UINT8 Temp;
  79. BOOL result;
  80. result = TRUE;
  81. Pt = (UINT8 *)Address;
  82. Temp = *Pt;
  83. if (Temp != MyCheck)
  84. {
  85. result = FALSE;
  86. HalTest_print_info("Error at memory location %08x: Set to %02x Read as %02x\r\n",Address,MyCheck,Temp);
  87. }
  88. else
  89. {
  90. //printf("OK at memory location %08x: Set to %08x Read as %08x\r\n",Address,MyCheck,Temp);
  91. }
  92. if (MySet)
  93. {
  94. Set8(Address,MySet);
  95. }
  96. return result;
  97. }
  98. static BOOL MemoryWalkingAddress(UINT32 Start, UINT32 Stop)
  99. {
  100. BOOL result;
  101. UINT32 cursor;
  102. UINT32 i;
  103. UINT32 j;
  104. result = TRUE;
  105. //set all to 0...
  106. for (cursor = Start; cursor < Stop; cursor+=4)
  107. {
  108. Set32(cursor,0x00000000);
  109. }
  110. //check 0 and set address
  111. for (cursor = Start; cursor < Stop; cursor+=4)
  112. {
  113. result = result & CheckSet32(cursor,cursor,0x00000000);
  114. }
  115. //check address and set Antiaddress
  116. for (cursor = Start; cursor < Stop; cursor+=4)
  117. {
  118. result = result & CheckSet32(cursor,0xffffffff - cursor,cursor);
  119. }
  120. //check antiaddress
  121. for (cursor = Start; cursor < Stop; cursor+=4)
  122. {
  123. result = result & CheckSet32(cursor,0,0xffffffff - cursor);
  124. }
  125. return result;
  126. }
  127. static BOOL MemoryWalkingAddress16(UINT32 Start, UINT32 Stop)
  128. {
  129. BOOL result;
  130. UINT32 cursor;
  131. UINT32 i;
  132. UINT32 j;
  133. result = TRUE;
  134. //set all to 0...
  135. for (cursor = Start; cursor < Stop; cursor+=2)
  136. {
  137. Set16(cursor,0x0000);
  138. }
  139. //check 0 and set address
  140. for (cursor = Start; cursor < Stop; cursor+=2)
  141. {
  142. result = result & CheckSet16(cursor,(UINT16)cursor,0x0000);
  143. }
  144. //check address and set Antiaddress
  145. for (cursor = Start; cursor < Stop; cursor+=2)
  146. {
  147. result = result & CheckSet16(cursor,(UINT16)(0xffffffff - cursor),(UINT16)cursor);
  148. }
  149. //check antiaddress
  150. for (cursor = Start; cursor < Stop; cursor+=2)
  151. {
  152. result = result & CheckSet16(cursor,0,(UINT16)(0xffffffff - cursor));
  153. }
  154. return result;
  155. }
  156. static BOOL MemoryWalkingAddress8(UINT32 Start, UINT32 Stop)
  157. {
  158. BOOL result;
  159. UINT32 cursor;
  160. UINT32 i;
  161. UINT32 j;
  162. result = TRUE;
  163. //set all to 0...
  164. for (cursor = Start; cursor < Stop; cursor+=1)
  165. {
  166. Set8(cursor,0x0000);
  167. }
  168. //check 0 and set address
  169. for (cursor = Start; cursor < Stop; cursor+=1)
  170. {
  171. result = result & CheckSet8(cursor,(UINT8)cursor,0x00);
  172. }
  173. //check address and set Antiaddress
  174. for (cursor = Start; cursor < Stop; cursor+=1)
  175. {
  176. result = result & CheckSet8(cursor,(UINT8)(0xffffffff - cursor),(UINT8)cursor);
  177. }
  178. //check antiaddress
  179. for (cursor = Start; cursor < Stop; cursor+=1)
  180. {
  181. result = result & CheckSet8(cursor,0,(UINT8)(0xffffffff - cursor));
  182. }
  183. return result;
  184. }
  185. static BOOL MemoryAlternate(UINT32 Start, UINT32 Stop)
  186. {
  187. BOOL result;
  188. UINT32 cursor;
  189. UINT32 i;
  190. UINT32 j;
  191. result = TRUE;
  192. i = 0;
  193. //set alternate
  194. for (cursor = Start; cursor < Stop; cursor+=4)
  195. {
  196. i++;
  197. if (i & 0x1)
  198. Set32(cursor,0x55555555);
  199. else
  200. Set32(cursor,0xAAAAAAAA);
  201. }
  202. i = 0;
  203. //check alternate
  204. for (cursor = Start; cursor < Stop; cursor+=4)
  205. {
  206. i++;
  207. if (i & 0x1)
  208. result = result & CheckSet32(cursor,0xAAAAAAAA,0x55555555);
  209. else
  210. result = result & CheckSet32(cursor,0x55555555,0xAAAAAAAA);
  211. }
  212. //check alternate
  213. i = 0;
  214. for (cursor = Start; cursor < Stop; cursor+=4)
  215. {
  216. i++;
  217. if (i & 0x1)
  218. result = result & CheckSet32(cursor,0,0xAAAAAAAA);
  219. else
  220. result = result & CheckSet32(cursor,0,0x55555555);
  221. }
  222. return result;
  223. }
  224. static BOOL MemoryWalk_1( UINT32 start_addr )
  225. {
  226. BOOL result = FALSE;
  227. volatile UINT32 WordSave;
  228. volatile UINT32 *MyPointer, Value;
  229. volatile UINT32 Cursor,Counter;
  230. UINT32 i,j;
  231. result = TRUE;
  232. // order is important here if we have interrupts on IRQs might modify RAM areas after we save
  233. {
  234. SmartPtr_IRQ irq;
  235. // this routine cannot call any functions until memory word is restored!
  236. // The functions might live in RAM being tested
  237. Cursor = start_addr;
  238. Counter = 0;
  239. MyPointer = (UINT32 *)Cursor;
  240. while(Cursor < (SRAM1_MEMORY_Base + SRAM1_MEMORY_Size) && Cursor != (UINT32)MemoryWalk_1)
  241. {
  242. Counter ++;
  243. WordSave = *MyPointer;
  244. if( Cursor % 0x1000 == 0 )
  245. hal_fprintf( STREAM_LCD, "\r0x%08x", Cursor );
  246. //here run the test
  247. //STEP 1: SET memory to all 0s
  248. *MyPointer = 0x00000000;
  249. if (0x00000000 != *MyPointer)
  250. {
  251. HalTest_print_info("Cannot set to all 0s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
  252. result = FALSE;
  253. }
  254. i = 0x00000001;
  255. j = 1;
  256. while(j < 33)
  257. {
  258. *MyPointer = i;
  259. if (i != *MyPointer)
  260. result = FALSE;
  261. i = i + i;
  262. j++;
  263. }
  264. // Zero
  265. *MyPointer = 0xffffffff;
  266. if (0xffffffff != *MyPointer)
  267. {
  268. HalTest_print_info("Cannot set to all 1s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
  269. result = FALSE;
  270. }
  271. i = 0x00000001;
  272. j = 1;
  273. while(j < 33)
  274. { Value = 0xffffffff - i;
  275. *MyPointer = Value;
  276. if (Value != *MyPointer)
  277. result = FALSE;
  278. i = i + i;
  279. j++;
  280. //printf("%08x %08x\r\n",Value, Cursor);
  281. }
  282. //STEP 1: SET memory to be anti-address
  283. Value = 0xffffffff - Cursor;
  284. *MyPointer = Value;
  285. if (Value != *MyPointer)
  286. {
  287. HalTest_print_info("Cannot set memory location %08x to its anti - address(%08x). It is %08x\r\n",Cursor, Value, *MyPointer);
  288. result = FALSE;
  289. }
  290. //Restore the memory content
  291. *MyPointer = WordSave;
  292. //Increment the cursor-pointer
  293. Cursor += sizeof(UINT32);
  294. MyPointer = (UINT32*)Cursor;
  295. }
  296. }
  297. HalTest_print_info("Performed Walking One on each bit of RAM (till %08x). There were %d memory locations.\r\n",Cursor, Counter*sizeof(UINT32));
  298. if (result)
  299. {
  300. HalTest_print_info("Test Passes\r\n");
  301. }
  302. Events_WaitForEvents(0, 200);
  303. return result;
  304. }
  305. static BOOL MemoryWalk_2( UINT32 start_addr )
  306. {
  307. BOOL result = FALSE;
  308. volatile UINT32 WordSave;
  309. volatile UINT32 *MyPointer, Value;
  310. volatile UINT32 Cursor,Counter;
  311. UINT32 i,j;
  312. result = TRUE;
  313. // order is important here if we have interrupts on IRQs might modify RAM areas after we save
  314. {
  315. SmartPtr_IRQ irq;
  316. // this routine cannot call any functions until memory word is restored!
  317. // The functions might live in RAM being tested
  318. Cursor = start_addr;
  319. Counter = 0;
  320. MyPointer = (UINT32 *)Cursor;
  321. while(Cursor < (SRAM1_MEMORY_Base+SRAM1_MEMORY_Size) && Cursor != (UINT32)MemoryWalk_2)
  322. {
  323. Counter ++;
  324. WordSave = *MyPointer;
  325. if( Cursor % 0x1000 == 0 )
  326. hal_fprintf( STREAM_LCD, "\r0x%08x", Cursor );
  327. //here run the test
  328. //STEP 1: SET memory to all 0s
  329. *MyPointer = 0x00000000;
  330. if (0x00000000 != *MyPointer)
  331. {
  332. HalTest_print_info("Cannot set to all 0s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
  333. result = FALSE;
  334. }
  335. i = 0x00000001;
  336. j = 1;
  337. while(j < 33)
  338. {
  339. *MyPointer = i;
  340. if (i != *MyPointer)
  341. result = FALSE;
  342. i = i + i;
  343. j++;
  344. }
  345. // Zero
  346. *MyPointer = 0xffffffff;
  347. if (0xffffffff != *MyPointer)
  348. {
  349. HalTest_print_info("Cannot set to all 1s memory location %08x. It is %08x\r\n",Cursor, *MyPointer);
  350. result = FALSE;
  351. }
  352. i = 0x00000001;
  353. j = 1;
  354. while(j < 33)
  355. { Value = 0xffffffff - i;
  356. *MyPointer = Value;
  357. if (Value != *MyPointer)
  358. result = FALSE;
  359. i = i + i;
  360. j++;
  361. //printf("%08x %08x\r\n",Value, Cursor);
  362. }
  363. //STEP 1: SET memory to be anti-address
  364. Value = 0xffffffff - Cursor;
  365. *MyPointer = Value;
  366. if (Value != *MyPointer)
  367. {
  368. HalTest_print_info("Cannot set memory location %08x to its anti - address(%08x). It is %08x\r\n",Cursor, Value, *MyPointer);
  369. result = FALSE;
  370. }
  371. //Restore the memory content
  372. *MyPointer = WordSave;
  373. //Increment the cursor-pointer
  374. Cursor += sizeof(UINT32);
  375. MyPointer = (UINT32*)Cursor;
  376. }
  377. }
  378. HalTest_print_info("Performed Walking One on each bit of RAM (till %08x). There were %d memory locations.\r\n",Cursor, Counter*sizeof(UINT32));
  379. if (result)
  380. {
  381. HalTest_print_info("Test Passes\r\n");
  382. }
  383. Events_WaitForEvents(0, 200);
  384. return result;
  385. }
  386. static BOOL ApplicationEntryPoint()
  387. {
  388. BOOL bRet = TRUE;
  389. HalTest_print_info("RAM Test\r\n");
  390. HalTest_print_info("Ram Start: 0x%08x\r\n", SRAM1_MEMORY_Base );
  391. HalTest_print_info("Ram Size : 0x%08x\r\n", SRAM1_MEMORY_Size );
  392. //SRAM1_MEMORY_Base
  393. //SRAM1_MEMORY_Size
  394. // are we in RAM??
  395. if( ((UINT32)MemoryWalk_1 < (SRAM1_MEMORY_Base + SRAM1_MEMORY_Size)) &&
  396. ((UINT32)MemoryWalk_1 >= (SRAM1_MEMORY_Base )) )
  397. {
  398. if( (UINT32)MemoryWalk_1 < (UINT32)MemoryWalk_2 )
  399. {
  400. bRet &= MemoryWalk_2( SRAM1_MEMORY_Base );
  401. bRet &= MemoryWalk_1( (UINT32)MemoryWalk_2 );
  402. }
  403. else
  404. {
  405. bRet &= MemoryWalk_1( SRAM1_MEMORY_Base );
  406. bRet &= MemoryWalk_2( (UINT32)MemoryWalk_1 );
  407. }
  408. }
  409. else // not in ram
  410. {
  411. bRet &= MemoryWalk_1( SRAM1_MEMORY_Base );
  412. }
  413. HalTest_print_info("Doing RAM WalkTest\r\n");
  414. HalTest_print_info("WalkAddress");
  415. bRet &= Report(MemoryWalkingAddress(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
  416. HalTest_print_info("WalkAlternate");
  417. bRet &= Report(MemoryAlternate(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
  418. HalTest_print_info("WalkAddress");
  419. bRet &= Report(MemoryWalkingAddress(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
  420. HalTest_print_info("WalkAlternate");
  421. bRet &= Report(MemoryAlternate(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
  422. HalTest_print_info("WalkAddress16");
  423. bRet &= Report(MemoryWalkingAddress16(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
  424. HalTest_print_info("WalkAddress8");
  425. bRet &= Report(MemoryWalkingAddress8(SRAM1_MEMORY_Base+SRAM1_MEMORY_Size/2,SRAM1_MEMORY_Size/1024));
  426. return bRet;
  427. }
  428. };