levelx_nor_flash_test_cache.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  1. /* Basic NOR flash tests... */
  2. #include <stdio.h>
  3. #include "lx_api.h"
  4. #define DEMO_STACK_SIZE 4096
  5. /* Define the ThreadX object control blocks... */
  6. #ifndef LX_STANDALONE_ENABLE
  7. TX_THREAD thread_0;
  8. #endif
  9. UCHAR thread_0_stack[DEMO_STACK_SIZE];
  10. /* Define LevelX structures. */
  11. LX_NOR_FLASH nor_sim_flash;
  12. ULONG buffer[128];
  13. ULONG readbuffer[128];
  14. UCHAR nor_cache_memory[2048+16+8];
  15. UCHAR nor_cache_memory2[8192];
  16. /* Define LevelX NOR flash simulator prototoypes. */
  17. UINT _lx_nor_flash_simulator_erase_all(VOID);
  18. UINT _lx_nor_flash_simulator_initialize(LX_NOR_FLASH *nor_flash);
  19. /* Define thread prototypes. */
  20. void thread_0_entry(ULONG thread_input);
  21. /* Define main entry point. */
  22. int main()
  23. {
  24. /* Enter the ThreadX kernel. */
  25. #ifndef LX_STANDALONE_ENABLE
  26. tx_kernel_enter();
  27. #else
  28. thread_0_entry(0);
  29. #endif
  30. }
  31. /* Define what the initial system looks like. */
  32. #ifndef LX_STANDALONE_ENABLE
  33. void tx_application_define(void *first_unused_memory)
  34. {
  35. /* Create the main thread. */
  36. tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
  37. thread_0_stack, DEMO_STACK_SIZE,
  38. 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START);
  39. }
  40. #endif
  41. /* Define the test threads. */
  42. void thread_0_entry(ULONG thread_input)
  43. {
  44. ULONG i, j, sector;
  45. UINT status;
  46. ULONG *word_ptr;
  47. /* Erase the simulated NOR flash. */
  48. _lx_nor_flash_simulator_erase_all();
  49. /* Initialize LevelX. */
  50. _lx_nor_flash_initialize();
  51. /* Test 1: Simple write 100 sectors and read 100 sectors. */
  52. printf("Test 1: Simple write-read 100 sectors...........");
  53. lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  54. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  55. lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  56. #endif
  57. #ifdef LX_NOR_ENABLE_MAPPING_BITMAP
  58. if (nor_sim_flash.lx_nor_flash_extended_cache_mapping_bitmap_max_logical_sector != 128)
  59. {
  60. printf("FAILED!\n");
  61. #ifdef BATCH_TEST
  62. exit(1);
  63. #endif
  64. while(1)
  65. {
  66. }
  67. }
  68. #endif
  69. #ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
  70. if (nor_sim_flash.lx_nor_flash_extended_cache_obsolete_count_max_block != 8)
  71. {
  72. printf("FAILED!\n");
  73. #ifdef BATCH_TEST
  74. exit(1);
  75. #endif
  76. while(1)
  77. {
  78. }
  79. }
  80. #endif
  81. /* Write 100 sectors.... */
  82. for (i = 0; i < 100; i++)
  83. {
  84. for (j = 0; j < 128; j++)
  85. buffer[j] = i;
  86. status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
  87. if (status != LX_SUCCESS)
  88. {
  89. printf("FAILED!\n");
  90. #ifdef BATCH_TEST
  91. exit(1);
  92. #endif
  93. while(1)
  94. {
  95. }
  96. }
  97. }
  98. /* Read back 100 sectors... */
  99. for (i = 0; i < 100; i++)
  100. {
  101. status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
  102. if (status != LX_SUCCESS)
  103. {
  104. printf("FAILED!\n");
  105. #ifdef BATCH_TEST
  106. exit(1);
  107. #endif
  108. while(1)
  109. {
  110. }
  111. }
  112. for (j = 0; j < 128; j++)
  113. {
  114. if (buffer[j] != i)
  115. {
  116. printf("FAILED!\n");
  117. #ifdef BATCH_TEST
  118. exit(1);
  119. #endif
  120. while(1)
  121. {
  122. }
  123. }
  124. }
  125. }
  126. #ifdef LX_NOR_ENABLE_MAPPING_BITMAP
  127. for (i = 0; i < 100; i++)
  128. {
  129. if (nor_sim_flash.lx_nor_flash_extended_cache_mapping_bitmap[i>>5] & (ULONG)(1<<(i & 31)) == 0)
  130. {
  131. printf("FAILED!\n");
  132. #ifdef BATCH_TEST
  133. exit(1);
  134. #endif
  135. while(1)
  136. {
  137. }
  138. }
  139. }
  140. #endif
  141. #ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
  142. for (i = 0; i < 8; i++)
  143. {
  144. if(nor_sim_flash.lx_nor_flash_extended_cache_obsolete_count[i] != 0)
  145. {
  146. printf("FAILED!\n");
  147. #ifdef BATCH_TEST
  148. exit(1);
  149. #endif
  150. while(1)
  151. {
  152. }
  153. }
  154. }
  155. #endif
  156. /* Release 100 sectors... */
  157. for (i = 0; i < 100; i++)
  158. {
  159. status = lx_nor_flash_sector_release(&nor_sim_flash, i);
  160. if (status != LX_SUCCESS)
  161. {
  162. printf("FAILED!\n");
  163. #ifdef BATCH_TEST
  164. exit(1);
  165. #endif
  166. while(1)
  167. {
  168. }
  169. }
  170. }
  171. #ifdef LX_NOR_ENABLE_MAPPING_BITMAP
  172. for (i = 0; i < 100; i++)
  173. {
  174. if (nor_sim_flash.lx_nor_flash_extended_cache_mapping_bitmap[i>>5] & (ULONG)(1<<(i & 31)) != 0)
  175. {
  176. printf("FAILED!\n");
  177. #ifdef BATCH_TEST
  178. exit(1);
  179. #endif
  180. while(1)
  181. {
  182. }
  183. }
  184. }
  185. #endif
  186. #ifdef LX_NOR_ENABLE_OBSOLETE_COUNT_CACHE
  187. for (i = 0; i < 6; i++)
  188. {
  189. if(nor_sim_flash.lx_nor_flash_extended_cache_obsolete_count[i] != 15)
  190. {
  191. printf("FAILED!\n");
  192. #ifdef BATCH_TEST
  193. exit(1);
  194. #endif
  195. while(1)
  196. {
  197. }
  198. }
  199. }
  200. if (nor_sim_flash.lx_nor_flash_extended_cache_obsolete_count[6] != 10 || nor_sim_flash.lx_nor_flash_extended_cache_obsolete_count[7] != 0)
  201. {
  202. printf("FAILED!\n");
  203. #ifdef BATCH_TEST
  204. exit(1);
  205. #endif
  206. while(1)
  207. {
  208. }
  209. }
  210. #endif
  211. _lx_nor_flash_close(&nor_sim_flash);
  212. printf("SUCCESS!\n");
  213. /* Test 2: Write same sector 120 times. */
  214. printf("Test 2: Write same sector 120 times.............");
  215. /* Reinitialize... */
  216. _lx_nor_flash_simulator_erase_all();
  217. lx_nor_flash_initialize();
  218. lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  219. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  220. lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  221. #endif
  222. for (j = 0; j < 128; j++)
  223. buffer[j] = 0xFFFFFFFF;
  224. /* Write same sector 120 sectors.... */
  225. for (i = 0; i < 120; i++)
  226. {
  227. for (j = 0; j < 128; j++)
  228. buffer[j] = i;
  229. status = lx_nor_flash_sector_write(&nor_sim_flash, 7, buffer);
  230. if (status != LX_SUCCESS)
  231. {
  232. printf("FAILED!\n");
  233. #ifdef BATCH_TEST
  234. exit(1);
  235. #endif
  236. while(1)
  237. {
  238. }
  239. }
  240. status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
  241. if (status != LX_SUCCESS)
  242. {
  243. printf("FAILED!\n");
  244. #ifdef BATCH_TEST
  245. exit(1);
  246. #endif
  247. while(1)
  248. {
  249. }
  250. }
  251. for (j = 0; j < 128; j++)
  252. {
  253. if (buffer[j] != readbuffer[j])
  254. {
  255. printf("FAILED!\n");
  256. #ifdef BATCH_TEST
  257. exit(1);
  258. #endif
  259. while(1)
  260. {
  261. }
  262. }
  263. }
  264. /* Write other sectors just to have additional sectors to manage. */
  265. if (i == 1)
  266. lx_nor_flash_sector_write(&nor_sim_flash, 1, buffer);
  267. if (i == 16)
  268. lx_nor_flash_sector_write(&nor_sim_flash, 16, buffer);
  269. if (i == 32)
  270. lx_nor_flash_sector_write(&nor_sim_flash, 32, buffer);
  271. if (i == 48)
  272. lx_nor_flash_sector_write(&nor_sim_flash, 48, buffer);
  273. if (i == 64)
  274. lx_nor_flash_sector_write(&nor_sim_flash, 64, buffer);
  275. if (i == 80)
  276. lx_nor_flash_sector_write(&nor_sim_flash, 80, buffer);
  277. if (i == 96)
  278. lx_nor_flash_sector_write(&nor_sim_flash, 96, buffer);
  279. if (i == 112)
  280. lx_nor_flash_sector_write(&nor_sim_flash, 112, buffer);
  281. }
  282. status = lx_nor_flash_defragment(&nor_sim_flash);
  283. status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
  284. if (status != LX_SUCCESS)
  285. {
  286. printf("FAILED!\n");
  287. #ifdef BATCH_TEST
  288. exit(1);
  289. #endif
  290. while(1)
  291. {
  292. }
  293. }
  294. if (readbuffer[0] != 119)
  295. {
  296. printf("FAILED!\n");
  297. #ifdef BATCH_TEST
  298. exit(1);
  299. #endif
  300. while(1)
  301. {
  302. }
  303. }
  304. status = lx_nor_flash_sector_read(&nor_sim_flash, 1, readbuffer);
  305. if (status != LX_SUCCESS)
  306. {
  307. printf("FAILED!\n");
  308. #ifdef BATCH_TEST
  309. exit(1);
  310. #endif
  311. while(1)
  312. {
  313. }
  314. }
  315. if (readbuffer[0] != 1)
  316. {
  317. printf("FAILED!\n");
  318. #ifdef BATCH_TEST
  319. exit(1);
  320. #endif
  321. while(1)
  322. {
  323. }
  324. }
  325. status = lx_nor_flash_sector_read(&nor_sim_flash, 16, readbuffer);
  326. if (status != LX_SUCCESS)
  327. {
  328. printf("FAILED!\n");
  329. #ifdef BATCH_TEST
  330. exit(1);
  331. #endif
  332. while(1)
  333. {
  334. }
  335. }
  336. if (readbuffer[0] != 16)
  337. {
  338. printf("FAILED!\n");
  339. #ifdef BATCH_TEST
  340. exit(1);
  341. #endif
  342. while(1)
  343. {
  344. }
  345. }
  346. status = lx_nor_flash_sector_read(&nor_sim_flash, 32, readbuffer);
  347. if (status != LX_SUCCESS)
  348. {
  349. printf("FAILED!\n");
  350. #ifdef BATCH_TEST
  351. exit(1);
  352. #endif
  353. while(1)
  354. {
  355. }
  356. }
  357. if (readbuffer[0] != 32)
  358. {
  359. printf("FAILED!\n");
  360. #ifdef BATCH_TEST
  361. exit(1);
  362. #endif
  363. while(1)
  364. {
  365. }
  366. }
  367. status = lx_nor_flash_sector_read(&nor_sim_flash, 48, readbuffer);
  368. if (status != LX_SUCCESS)
  369. {
  370. printf("FAILED!\n");
  371. #ifdef BATCH_TEST
  372. exit(1);
  373. #endif
  374. while(1)
  375. {
  376. }
  377. }
  378. if (readbuffer[0] != 48)
  379. {
  380. printf("FAILED!\n");
  381. #ifdef BATCH_TEST
  382. exit(1);
  383. #endif
  384. while(1)
  385. {
  386. }
  387. }
  388. status = lx_nor_flash_sector_read(&nor_sim_flash, 64, readbuffer);
  389. if (status != LX_SUCCESS)
  390. {
  391. printf("FAILED!\n");
  392. #ifdef BATCH_TEST
  393. exit(1);
  394. #endif
  395. while(1)
  396. {
  397. }
  398. }
  399. if (readbuffer[0] != 64)
  400. {
  401. printf("FAILED!\n");
  402. #ifdef BATCH_TEST
  403. exit(1);
  404. #endif
  405. while(1)
  406. {
  407. }
  408. }
  409. status = lx_nor_flash_sector_read(&nor_sim_flash, 80, readbuffer);
  410. if (status != LX_SUCCESS)
  411. {
  412. printf("FAILED!\n");
  413. #ifdef BATCH_TEST
  414. exit(1);
  415. #endif
  416. while(1)
  417. {
  418. }
  419. }
  420. if (readbuffer[0] != 80)
  421. {
  422. printf("FAILED!\n");
  423. #ifdef BATCH_TEST
  424. exit(1);
  425. #endif
  426. while(1)
  427. {
  428. }
  429. }
  430. status = lx_nor_flash_sector_read(&nor_sim_flash, 96, readbuffer);
  431. if (status != LX_SUCCESS)
  432. {
  433. printf("FAILED!\n");
  434. #ifdef BATCH_TEST
  435. exit(1);
  436. #endif
  437. while(1)
  438. {
  439. }
  440. }
  441. if (readbuffer[0] != 96)
  442. {
  443. printf("FAILED!\n");
  444. #ifdef BATCH_TEST
  445. exit(1);
  446. #endif
  447. while(1)
  448. {
  449. }
  450. }
  451. status = lx_nor_flash_sector_read(&nor_sim_flash, 112, readbuffer);
  452. if (status != LX_SUCCESS)
  453. {
  454. printf("FAILED!\n");
  455. #ifdef BATCH_TEST
  456. exit(1);
  457. #endif
  458. while(1)
  459. {
  460. }
  461. }
  462. if (readbuffer[0] != 112)
  463. {
  464. printf("FAILED!\n");
  465. #ifdef BATCH_TEST
  466. exit(1);
  467. #endif
  468. while(1)
  469. {
  470. }
  471. }
  472. status = lx_nor_flash_defragment(&nor_sim_flash);
  473. if (status != LX_SUCCESS)
  474. {
  475. printf("FAILED!\n");
  476. #ifdef BATCH_TEST
  477. exit(1);
  478. #endif
  479. while(1)
  480. {
  481. }
  482. }
  483. /* Point at the simulated NOR flash memory. */
  484. word_ptr = nor_sim_flash.lx_nor_flash_base_address;
  485. status = lx_nor_flash_close(&nor_sim_flash);
  486. if (status != LX_SUCCESS)
  487. {
  488. printf("FAILED!\n");
  489. #ifdef BATCH_TEST
  490. exit(1);
  491. #endif
  492. while(1)
  493. {
  494. }
  495. }
  496. printf("SUCCESS!\n");
  497. /* Test 3: Corrupt block 0, simulate a power interruption during erase of block 0,
  498. after the erase, but before the free bit map and erase count is setup. */
  499. printf("Test 3: Block erase-initialize interrupted......");
  500. word_ptr[0] = 0xFFFFFFFF;
  501. word_ptr[3] = 0xFFFFFFFF;
  502. /* Open the flash and see if we recover properly. */
  503. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  504. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  505. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  506. #endif
  507. if ((status != LX_SUCCESS) ||
  508. (nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) ||
  509. (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
  510. {
  511. printf("FAILED!\n");
  512. #ifdef BATCH_TEST
  513. exit(1);
  514. #endif
  515. while(1)
  516. {
  517. }
  518. }
  519. status = lx_nor_flash_close(&nor_sim_flash);
  520. if (status != LX_SUCCESS)
  521. {
  522. printf("FAILED!\n");
  523. #ifdef BATCH_TEST
  524. exit(1);
  525. #endif
  526. while(1)
  527. {
  528. }
  529. }
  530. /* Corrupt block 0, simulate a power interruption during erase of block 0,
  531. after the erase, and after the free bit map setup, but before erase count is setup. */
  532. word_ptr[0] = 0xFFFFFFFF;
  533. /* Open the flash and see if we recover properly. */
  534. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  535. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  536. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  537. #endif
  538. if ((status != LX_SUCCESS) ||
  539. (nor_sim_flash.lx_nor_flash_free_physical_sectors != 111) ||
  540. (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
  541. {
  542. printf("FAILED!\n");
  543. #ifdef BATCH_TEST
  544. exit(1);
  545. #endif
  546. while(1)
  547. {
  548. }
  549. }
  550. status = lx_nor_flash_close(&nor_sim_flash);
  551. if (status != LX_SUCCESS)
  552. {
  553. printf("FAILED!\n");
  554. #ifdef BATCH_TEST
  555. exit(1);
  556. #endif
  557. while(1)
  558. {
  559. }
  560. }
  561. printf("SUCCESS!\n");
  562. /* Test 4: simulate a power interruption after a new block is allocated but before
  563. anything else can be done. */
  564. printf("Test 4: Power interrupted new block allocation..");
  565. word_ptr[3] = word_ptr[3] & ~((ULONG) 1);
  566. /* Open the flash and see if we recover properly. */
  567. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  568. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  569. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  570. #endif
  571. if ((status != LX_SUCCESS) ||
  572. (nor_sim_flash.lx_nor_flash_free_physical_sectors != 110) ||
  573. (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
  574. {
  575. printf("FAILED!\n");
  576. #ifdef BATCH_TEST
  577. exit(1);
  578. #endif
  579. while(1)
  580. {
  581. }
  582. }
  583. status = lx_nor_flash_close(&nor_sim_flash);
  584. if (status != LX_SUCCESS)
  585. {
  586. printf("FAILED!\n");
  587. #ifdef BATCH_TEST
  588. exit(1);
  589. #endif
  590. while(1)
  591. {
  592. }
  593. }
  594. /* Simulate a power interruption after a new block is allocated but before
  595. anything else can be done. */
  596. word_ptr[(16*128)+3] = 0x7C00;
  597. /* Open the flash and see if we recover properly. */
  598. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  599. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  600. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  601. #endif
  602. if ((status != LX_SUCCESS) ||
  603. (nor_sim_flash.lx_nor_flash_free_physical_sectors != 109) ||
  604. (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
  605. {
  606. printf("FAILED!\n");
  607. #ifdef BATCH_TEST
  608. exit(1);
  609. #endif
  610. while(1)
  611. {
  612. }
  613. }
  614. status = lx_nor_flash_close(&nor_sim_flash);
  615. if (status != LX_SUCCESS)
  616. {
  617. printf("FAILED!\n");
  618. #ifdef BATCH_TEST
  619. exit(1);
  620. #endif
  621. while(1)
  622. {
  623. }
  624. }
  625. /* Simulate a power interruption after a new sector is allocated, after data
  626. had been copied, and the superceeded bit is clear, but before the new entry can be
  627. setup. */
  628. word_ptr[3] = 0x7FFC;
  629. word_ptr[(16*128)+6] = word_ptr[(16*128)+6] & ~((ULONG) 0x40000000);
  630. /* Open the flash and see if we recover properly. */
  631. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  632. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  633. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  634. #endif
  635. if ((status != LX_SUCCESS) ||
  636. (nor_sim_flash.lx_nor_flash_free_physical_sectors != 108) ||
  637. (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
  638. {
  639. printf("FAILED!\n");
  640. #ifdef BATCH_TEST
  641. exit(1);
  642. #endif
  643. while(1)
  644. {
  645. }
  646. }
  647. lx_nor_flash_close(&nor_sim_flash);
  648. /* Simulate a power interruption after a new sector is allocated, after data
  649. had been copied, and the superceeded bit is clear, the new entry is setup, but the old entry
  650. has not been invalidated. */
  651. word_ptr[3] = 0x7FF8;
  652. word_ptr[6] = 0xC0000070;
  653. for (i = 0; i < 128; i++)
  654. {
  655. word_ptr[(3*128)+i] = 0x70;
  656. }
  657. /* Open the flash and see if we recover properly. */
  658. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  659. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  660. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  661. #endif
  662. if ((status != LX_SUCCESS) ||
  663. (nor_sim_flash.lx_nor_flash_free_physical_sectors != 107) ||
  664. (nor_sim_flash.lx_nor_flash_mapped_physical_sectors != 9))
  665. {
  666. printf("FAILED!\n");
  667. #ifdef BATCH_TEST
  668. exit(1);
  669. #endif
  670. while(1)
  671. {
  672. }
  673. }
  674. status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
  675. if (status != LX_SUCCESS)
  676. {
  677. printf("FAILED!\n");
  678. #ifdef BATCH_TEST
  679. exit(1);
  680. #endif
  681. while(1)
  682. {
  683. }
  684. }
  685. if (readbuffer[0] != 119)
  686. {
  687. printf("FAILED!\n");
  688. #ifdef BATCH_TEST
  689. exit(1);
  690. #endif
  691. while(1)
  692. {
  693. }
  694. }
  695. status = lx_nor_flash_sector_read(&nor_sim_flash, 1, readbuffer);
  696. if (status != LX_SUCCESS)
  697. {
  698. printf("FAILED!\n");
  699. #ifdef BATCH_TEST
  700. exit(1);
  701. #endif
  702. while(1)
  703. {
  704. }
  705. }
  706. if (readbuffer[0] != 1)
  707. {
  708. printf("FAILED!\n");
  709. #ifdef BATCH_TEST
  710. exit(1);
  711. #endif
  712. while(1)
  713. {
  714. }
  715. }
  716. status = lx_nor_flash_sector_read(&nor_sim_flash, 16, readbuffer);
  717. if (status != LX_SUCCESS)
  718. {
  719. printf("FAILED!\n");
  720. #ifdef BATCH_TEST
  721. exit(1);
  722. #endif
  723. while(1)
  724. {
  725. }
  726. }
  727. if (readbuffer[0] != 16)
  728. {
  729. printf("FAILED!\n");
  730. #ifdef BATCH_TEST
  731. exit(1);
  732. #endif
  733. while(1)
  734. {
  735. }
  736. }
  737. status = lx_nor_flash_sector_read(&nor_sim_flash, 32, readbuffer);
  738. if (status != LX_SUCCESS)
  739. {
  740. printf("FAILED!\n");
  741. #ifdef BATCH_TEST
  742. exit(1);
  743. #endif
  744. while(1)
  745. {
  746. }
  747. }
  748. if (readbuffer[0] != 32)
  749. {
  750. printf("FAILED!\n");
  751. #ifdef BATCH_TEST
  752. exit(1);
  753. #endif
  754. while(1)
  755. {
  756. }
  757. }
  758. status = lx_nor_flash_sector_read(&nor_sim_flash, 48, readbuffer);
  759. if (status != LX_SUCCESS)
  760. {
  761. printf("FAILED!\n");
  762. #ifdef BATCH_TEST
  763. exit(1);
  764. #endif
  765. while(1)
  766. {
  767. }
  768. }
  769. if (readbuffer[0] != 48)
  770. {
  771. printf("FAILED!\n");
  772. #ifdef BATCH_TEST
  773. exit(1);
  774. #endif
  775. while(1)
  776. {
  777. }
  778. }
  779. status = lx_nor_flash_sector_read(&nor_sim_flash, 64, readbuffer);
  780. if (status != LX_SUCCESS)
  781. {
  782. printf("FAILED!\n");
  783. #ifdef BATCH_TEST
  784. exit(1);
  785. #endif
  786. while(1)
  787. {
  788. }
  789. }
  790. if (readbuffer[0] != 64)
  791. {
  792. printf("FAILED!\n");
  793. #ifdef BATCH_TEST
  794. exit(1);
  795. #endif
  796. while(1)
  797. {
  798. }
  799. }
  800. status = lx_nor_flash_sector_read(&nor_sim_flash, 80, readbuffer);
  801. if (status != LX_SUCCESS)
  802. {
  803. printf("FAILED!\n");
  804. #ifdef BATCH_TEST
  805. exit(1);
  806. #endif
  807. while(1)
  808. {
  809. }
  810. }
  811. if (readbuffer[0] != 80)
  812. {
  813. printf("FAILED!\n");
  814. #ifdef BATCH_TEST
  815. exit(1);
  816. #endif
  817. while(1)
  818. {
  819. }
  820. }
  821. status = lx_nor_flash_sector_read(&nor_sim_flash, 96, readbuffer);
  822. if (status != LX_SUCCESS)
  823. {
  824. printf("FAILED!\n");
  825. #ifdef BATCH_TEST
  826. exit(1);
  827. #endif
  828. while(1)
  829. {
  830. }
  831. }
  832. if (readbuffer[0] != 96)
  833. {
  834. printf("FAILED!\n");
  835. #ifdef BATCH_TEST
  836. exit(1);
  837. #endif
  838. while(1)
  839. {
  840. }
  841. }
  842. status = lx_nor_flash_sector_read(&nor_sim_flash, 112, readbuffer);
  843. if (status != LX_SUCCESS)
  844. {
  845. printf("FAILED!\n");
  846. #ifdef BATCH_TEST
  847. exit(1);
  848. #endif
  849. while(1)
  850. {
  851. }
  852. }
  853. if (readbuffer[0] != 112)
  854. {
  855. printf("FAILED!\n");
  856. #ifdef BATCH_TEST
  857. exit(1);
  858. #endif
  859. while(1)
  860. {
  861. }
  862. }
  863. status = lx_nor_flash_defragment(&nor_sim_flash);
  864. if (status != LX_SUCCESS)
  865. {
  866. printf("FAILED!\n");
  867. #ifdef BATCH_TEST
  868. exit(1);
  869. #endif
  870. while(1)
  871. {
  872. }
  873. }
  874. status = lx_nor_flash_defragment(&nor_sim_flash);
  875. if (status != LX_SUCCESS)
  876. {
  877. printf("FAILED!\n");
  878. #ifdef BATCH_TEST
  879. exit(1);
  880. #endif
  881. while(1)
  882. {
  883. }
  884. }
  885. status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
  886. if (status != LX_SUCCESS)
  887. {
  888. printf("FAILED!\n");
  889. #ifdef BATCH_TEST
  890. exit(1);
  891. #endif
  892. while(1)
  893. {
  894. }
  895. }
  896. if (readbuffer[0] != 119)
  897. {
  898. printf("FAILED!\n");
  899. #ifdef BATCH_TEST
  900. exit(1);
  901. #endif
  902. while(1)
  903. {
  904. }
  905. }
  906. status = lx_nor_flash_sector_read(&nor_sim_flash, 1, readbuffer);
  907. if (status != LX_SUCCESS)
  908. {
  909. printf("FAILED!\n");
  910. #ifdef BATCH_TEST
  911. exit(1);
  912. #endif
  913. while(1)
  914. {
  915. }
  916. }
  917. if (readbuffer[0] != 1)
  918. {
  919. printf("FAILED!\n");
  920. #ifdef BATCH_TEST
  921. exit(1);
  922. #endif
  923. while(1)
  924. {
  925. }
  926. }
  927. status = lx_nor_flash_sector_read(&nor_sim_flash, 16, readbuffer);
  928. if (status != LX_SUCCESS)
  929. {
  930. printf("FAILED!\n");
  931. #ifdef BATCH_TEST
  932. exit(1);
  933. #endif
  934. while(1)
  935. {
  936. }
  937. }
  938. if (readbuffer[0] != 16)
  939. {
  940. printf("FAILED!\n");
  941. #ifdef BATCH_TEST
  942. exit(1);
  943. #endif
  944. while(1)
  945. {
  946. }
  947. }
  948. status = lx_nor_flash_sector_read(&nor_sim_flash, 32, readbuffer);
  949. if (status != LX_SUCCESS)
  950. {
  951. printf("FAILED!\n");
  952. #ifdef BATCH_TEST
  953. exit(1);
  954. #endif
  955. while(1)
  956. {
  957. }
  958. }
  959. if (readbuffer[0] != 32)
  960. {
  961. printf("FAILED!\n");
  962. #ifdef BATCH_TEST
  963. exit(1);
  964. #endif
  965. while(1)
  966. {
  967. }
  968. }
  969. status = lx_nor_flash_sector_read(&nor_sim_flash, 48, readbuffer);
  970. if (status != LX_SUCCESS)
  971. {
  972. printf("FAILED!\n");
  973. #ifdef BATCH_TEST
  974. exit(1);
  975. #endif
  976. while(1)
  977. {
  978. }
  979. }
  980. if (readbuffer[0] != 48)
  981. {
  982. printf("FAILED!\n");
  983. #ifdef BATCH_TEST
  984. exit(1);
  985. #endif
  986. while(1)
  987. {
  988. }
  989. }
  990. status = lx_nor_flash_sector_read(&nor_sim_flash, 64, readbuffer);
  991. if (status != LX_SUCCESS)
  992. {
  993. printf("FAILED!\n");
  994. #ifdef BATCH_TEST
  995. exit(1);
  996. #endif
  997. while(1)
  998. {
  999. }
  1000. }
  1001. if (readbuffer[0] != 64)
  1002. {
  1003. printf("FAILED!\n");
  1004. #ifdef BATCH_TEST
  1005. exit(1);
  1006. #endif
  1007. while(1)
  1008. {
  1009. }
  1010. }
  1011. status = lx_nor_flash_sector_read(&nor_sim_flash, 80, readbuffer);
  1012. if (status != LX_SUCCESS)
  1013. {
  1014. printf("FAILED!\n");
  1015. #ifdef BATCH_TEST
  1016. exit(1);
  1017. #endif
  1018. while(1)
  1019. {
  1020. }
  1021. }
  1022. if (readbuffer[0] != 80)
  1023. {
  1024. printf("FAILED!\n");
  1025. #ifdef BATCH_TEST
  1026. exit(1);
  1027. #endif
  1028. while(1)
  1029. {
  1030. }
  1031. }
  1032. status = lx_nor_flash_sector_read(&nor_sim_flash, 96, readbuffer);
  1033. if (status != LX_SUCCESS)
  1034. {
  1035. printf("FAILED!\n");
  1036. #ifdef BATCH_TEST
  1037. exit(1);
  1038. #endif
  1039. while(1)
  1040. {
  1041. }
  1042. }
  1043. if (readbuffer[0] != 96)
  1044. {
  1045. printf("FAILED!\n");
  1046. #ifdef BATCH_TEST
  1047. exit(1);
  1048. #endif
  1049. while(1)
  1050. {
  1051. }
  1052. }
  1053. status = lx_nor_flash_sector_read(&nor_sim_flash, 112, readbuffer);
  1054. if (status != LX_SUCCESS)
  1055. {
  1056. printf("FAILED!\n");
  1057. #ifdef BATCH_TEST
  1058. exit(1);
  1059. #endif
  1060. while(1)
  1061. {
  1062. }
  1063. }
  1064. if (readbuffer[0] != 112)
  1065. {
  1066. printf("FAILED!\n");
  1067. #ifdef BATCH_TEST
  1068. exit(1);
  1069. #endif
  1070. while(1)
  1071. {
  1072. }
  1073. }
  1074. /* Read in reverse order to see if caching helps! */
  1075. status = lx_nor_flash_sector_read(&nor_sim_flash, 112, readbuffer);
  1076. if (status != LX_SUCCESS)
  1077. {
  1078. printf("FAILED!\n");
  1079. #ifdef BATCH_TEST
  1080. exit(1);
  1081. #endif
  1082. while(1)
  1083. {
  1084. }
  1085. }
  1086. if (readbuffer[0] != 112)
  1087. {
  1088. printf("FAILED!\n");
  1089. #ifdef BATCH_TEST
  1090. exit(1);
  1091. #endif
  1092. while(1)
  1093. {
  1094. }
  1095. }
  1096. status = lx_nor_flash_sector_read(&nor_sim_flash, 96, readbuffer);
  1097. if (status != LX_SUCCESS)
  1098. {
  1099. printf("FAILED!\n");
  1100. #ifdef BATCH_TEST
  1101. exit(1);
  1102. #endif
  1103. while(1)
  1104. {
  1105. }
  1106. }
  1107. if (readbuffer[0] != 96)
  1108. {
  1109. printf("FAILED!\n");
  1110. #ifdef BATCH_TEST
  1111. exit(1);
  1112. #endif
  1113. while(1)
  1114. {
  1115. }
  1116. }
  1117. status = lx_nor_flash_sector_read(&nor_sim_flash, 80, readbuffer);
  1118. if (status != LX_SUCCESS)
  1119. {
  1120. printf("FAILED!\n");
  1121. #ifdef BATCH_TEST
  1122. exit(1);
  1123. #endif
  1124. while(1)
  1125. {
  1126. }
  1127. }
  1128. if (readbuffer[0] != 80)
  1129. {
  1130. printf("FAILED!\n");
  1131. #ifdef BATCH_TEST
  1132. exit(1);
  1133. #endif
  1134. while(1)
  1135. {
  1136. }
  1137. }
  1138. status = lx_nor_flash_sector_read(&nor_sim_flash, 64, readbuffer);
  1139. if (status != LX_SUCCESS)
  1140. {
  1141. printf("FAILED!\n");
  1142. #ifdef BATCH_TEST
  1143. exit(1);
  1144. #endif
  1145. while(1)
  1146. {
  1147. }
  1148. }
  1149. if (readbuffer[0] != 64)
  1150. {
  1151. printf("FAILED!\n");
  1152. #ifdef BATCH_TEST
  1153. exit(1);
  1154. #endif
  1155. while(1)
  1156. {
  1157. }
  1158. }
  1159. status = lx_nor_flash_sector_read(&nor_sim_flash, 48, readbuffer);
  1160. if (status != LX_SUCCESS)
  1161. {
  1162. printf("FAILED!\n");
  1163. #ifdef BATCH_TEST
  1164. exit(1);
  1165. #endif
  1166. while(1)
  1167. {
  1168. }
  1169. }
  1170. if (readbuffer[0] != 48)
  1171. {
  1172. printf("FAILED!\n");
  1173. #ifdef BATCH_TEST
  1174. exit(1);
  1175. #endif
  1176. while(1)
  1177. {
  1178. }
  1179. }
  1180. status = lx_nor_flash_sector_read(&nor_sim_flash, 32, readbuffer);
  1181. if (status != LX_SUCCESS)
  1182. {
  1183. printf("FAILED!\n");
  1184. #ifdef BATCH_TEST
  1185. exit(1);
  1186. #endif
  1187. while(1)
  1188. {
  1189. }
  1190. }
  1191. if (readbuffer[0] != 32)
  1192. {
  1193. printf("FAILED!\n");
  1194. #ifdef BATCH_TEST
  1195. exit(1);
  1196. #endif
  1197. while(1)
  1198. {
  1199. }
  1200. }
  1201. status = lx_nor_flash_sector_read(&nor_sim_flash, 16, readbuffer);
  1202. if (status != LX_SUCCESS)
  1203. {
  1204. printf("FAILED!\n");
  1205. #ifdef BATCH_TEST
  1206. exit(1);
  1207. #endif
  1208. while(1)
  1209. {
  1210. }
  1211. }
  1212. if (readbuffer[0] != 16)
  1213. {
  1214. printf("FAILED!\n");
  1215. #ifdef BATCH_TEST
  1216. exit(1);
  1217. #endif
  1218. while(1)
  1219. {
  1220. }
  1221. }
  1222. status = lx_nor_flash_sector_read(&nor_sim_flash, 1, readbuffer);
  1223. if (status != LX_SUCCESS)
  1224. {
  1225. printf("FAILED!\n");
  1226. #ifdef BATCH_TEST
  1227. exit(1);
  1228. #endif
  1229. while(1)
  1230. {
  1231. }
  1232. }
  1233. if (readbuffer[0] != 1)
  1234. {
  1235. printf("FAILED!\n");
  1236. #ifdef BATCH_TEST
  1237. exit(1);
  1238. #endif
  1239. while(1)
  1240. {
  1241. }
  1242. }
  1243. status = lx_nor_flash_sector_read(&nor_sim_flash, 7, readbuffer);
  1244. if (status != LX_SUCCESS)
  1245. {
  1246. printf("FAILED!\n");
  1247. #ifdef BATCH_TEST
  1248. exit(1);
  1249. #endif
  1250. while(1)
  1251. {
  1252. }
  1253. }
  1254. if (readbuffer[0] != 119)
  1255. {
  1256. printf("FAILED!\n");
  1257. #ifdef BATCH_TEST
  1258. exit(1);
  1259. #endif
  1260. while(1)
  1261. {
  1262. }
  1263. }
  1264. status = lx_nor_flash_sector_release(&nor_sim_flash, 7);
  1265. if (status != LX_SUCCESS)
  1266. {
  1267. printf("FAILED!\n");
  1268. #ifdef BATCH_TEST
  1269. exit(1);
  1270. #endif
  1271. while(1)
  1272. {
  1273. }
  1274. }
  1275. status = lx_nor_flash_sector_release(&nor_sim_flash, 8);
  1276. if (status != LX_SECTOR_NOT_FOUND)
  1277. {
  1278. printf("FAILED!\n");
  1279. #ifdef BATCH_TEST
  1280. exit(1);
  1281. #endif
  1282. while(1)
  1283. {
  1284. }
  1285. }
  1286. status = lx_nor_flash_defragment(&nor_sim_flash);
  1287. if (status != LX_SUCCESS)
  1288. {
  1289. printf("FAILED!\n");
  1290. #ifdef BATCH_TEST
  1291. exit(1);
  1292. #endif
  1293. while(1)
  1294. {
  1295. }
  1296. }
  1297. status = lx_nor_flash_close(&nor_sim_flash);
  1298. if (status != LX_SUCCESS)
  1299. {
  1300. printf("FAILED!\n");
  1301. #ifdef BATCH_TEST
  1302. exit(1);
  1303. #endif
  1304. while(1)
  1305. {
  1306. }
  1307. }
  1308. printf("SUCCESS!\n");
  1309. printf("Test 5: Randow write/read sector................");
  1310. /* Erase the simulated NOR flash. */
  1311. _lx_nor_flash_simulator_erase_all();
  1312. /* Open the flash. */
  1313. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  1314. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  1315. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory, sizeof(nor_cache_memory));
  1316. #endif
  1317. if (status != LX_SUCCESS)
  1318. {
  1319. printf("FAILED!\n");
  1320. #ifdef BATCH_TEST
  1321. exit(1);
  1322. #endif
  1323. while(1)
  1324. {
  1325. }
  1326. }
  1327. /* Write 100 sectors.... */
  1328. for (i = 0; i < 100; i++)
  1329. {
  1330. for (j = 0; j < 128; j++)
  1331. buffer[j] = i;
  1332. status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
  1333. if (status != LX_SUCCESS)
  1334. {
  1335. printf("FAILED!\n");
  1336. #ifdef BATCH_TEST
  1337. exit(1);
  1338. #endif
  1339. while(1)
  1340. {
  1341. }
  1342. }
  1343. }
  1344. /* Read back 100 sectors... */
  1345. for (i = 0; i < 100; i++)
  1346. {
  1347. status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
  1348. if (status != LX_SUCCESS)
  1349. {
  1350. printf("FAILED!\n");
  1351. #ifdef BATCH_TEST
  1352. exit(1);
  1353. #endif
  1354. while(1)
  1355. {
  1356. }
  1357. }
  1358. for (j = 0; j < 128; j++)
  1359. {
  1360. if (buffer[j] != i)
  1361. {
  1362. printf("FAILED!\n");
  1363. #ifdef BATCH_TEST
  1364. exit(1);
  1365. #endif
  1366. while(1)
  1367. {
  1368. }
  1369. }
  1370. }
  1371. }
  1372. /* Now, perform 1000 sector writes to randomly selected sectors, each time
  1373. reading first to make sure the previous contents are valid. */
  1374. for (i = 0; i < 1000; i++)
  1375. {
  1376. /* Pickup random sector. */
  1377. sector = (rand() % 100);
  1378. /* Read that sector. */
  1379. status = lx_nor_flash_sector_read(&nor_sim_flash, sector, buffer);
  1380. if (status != LX_SUCCESS)
  1381. {
  1382. printf("FAILED!\n");
  1383. #ifdef BATCH_TEST
  1384. exit(1);
  1385. #endif
  1386. while(1)
  1387. {
  1388. }
  1389. }
  1390. for (j = 0; j < 128; j++)
  1391. {
  1392. if ((buffer[j] & 0x0000FFFF) != sector)
  1393. {
  1394. printf("FAILED!\n");
  1395. #ifdef BATCH_TEST
  1396. exit(1);
  1397. #endif
  1398. while(1)
  1399. {
  1400. }
  1401. }
  1402. }
  1403. /* Include the itteraction in the buffer to generate a new write. */
  1404. for (j = 0; j < 128; j++)
  1405. {
  1406. buffer[j] = (buffer[j] & 0x0000FFFF) | (i << 16);
  1407. }
  1408. status = lx_nor_flash_sector_write(&nor_sim_flash, sector, buffer);
  1409. if (status != LX_SUCCESS)
  1410. {
  1411. printf("FAILED!\n");
  1412. #ifdef BATCH_TEST
  1413. exit(1);
  1414. #endif
  1415. while(1)
  1416. {
  1417. }
  1418. }
  1419. }
  1420. status = lx_nor_flash_close(&nor_sim_flash);
  1421. if (status != LX_SUCCESS)
  1422. {
  1423. printf("FAILED!\n");
  1424. #ifdef BATCH_TEST
  1425. exit(1);
  1426. #endif
  1427. while(1)
  1428. {
  1429. }
  1430. }
  1431. printf("SUCCESS!\n");
  1432. printf("Test 6: Check lx_nor_flash_extended_cache_entries size................");
  1433. /* Erase the simulated NOR flash. */
  1434. _lx_nor_flash_simulator_erase_all();
  1435. /* Open the flash. */
  1436. status = lx_nor_flash_open(&nor_sim_flash, "sim nor flash", _lx_nor_flash_simulator_initialize);
  1437. #ifndef LX_NOR_DISABLE_EXTENDED_CACHE
  1438. status += lx_nor_flash_extended_cache_enable(&nor_sim_flash, nor_cache_memory2, sizeof(nor_cache_memory2));
  1439. #endif
  1440. if (status != LX_SUCCESS)
  1441. {
  1442. printf("FAILED!\n");
  1443. #ifdef BATCH_TEST
  1444. exit(1);
  1445. #endif
  1446. while(1)
  1447. {
  1448. }
  1449. }
  1450. /* Write 100 sectors.... */
  1451. for (i = 0; i < 100; i++)
  1452. {
  1453. for (j = 0; j < 128; j++)
  1454. buffer[j] = i;
  1455. status = lx_nor_flash_sector_write(&nor_sim_flash, i, buffer);
  1456. if (status != LX_SUCCESS)
  1457. {
  1458. printf("FAILED!\n");
  1459. #ifdef BATCH_TEST
  1460. exit(1);
  1461. #endif
  1462. while(1)
  1463. {
  1464. }
  1465. }
  1466. }
  1467. /* Read back 100 sectors... */
  1468. for (i = 0; i < 100; i++)
  1469. {
  1470. status = lx_nor_flash_sector_read(&nor_sim_flash, i, buffer);
  1471. if (status != LX_SUCCESS)
  1472. {
  1473. printf("FAILED!\n");
  1474. #ifdef BATCH_TEST
  1475. exit(1);
  1476. #endif
  1477. while(1)
  1478. {
  1479. }
  1480. }
  1481. for (j = 0; j < 128; j++)
  1482. {
  1483. if (buffer[j] != i)
  1484. {
  1485. printf("FAILED!\n");
  1486. #ifdef BATCH_TEST
  1487. exit(1);
  1488. #endif
  1489. while(1)
  1490. {
  1491. }
  1492. }
  1493. }
  1494. }
  1495. #ifdef BATCH_TEST
  1496. exit(0);
  1497. #endif
  1498. /* All done! */
  1499. while(1)
  1500. {
  1501. }
  1502. }