FlashBadBlockProcess.s43
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:26k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1.         NAME FlashBadBlockProcess
  2.         RTMODEL "__double_size", "32"
  3.         RTMODEL "__pic", "no"
  4.         RTMODEL "__reg_r4", "free"
  5.         RTMODEL "__reg_r5", "free"
  6.         RTMODEL "__rt_version", "1"
  7.         RSEG CSTACK:DATA:SORT:NOROOT(1)
  8.         EXTERN ?Epilogue8
  9.         EXTERN ZERO_ADDRESS
  10.         FUNCTION ZERO_ADDRESS,0202H
  11.         EXTERN ERASE_ONE_BLOCK
  12.         FUNCTION ERASE_ONE_BLOCK,0202H
  13.         EXTERN ?ShiftLeft16_6
  14.         EXTERN ROW_ADDRESS_LOW
  15.         EXTERN ROW_ADDRESS_HIGH
  16.         EXTERN COMMAND_VAL
  17.         EXTERN COMMAND_LATCH_INTO
  18.         FUNCTION COMMAND_LATCH_INTO,0202H
  19.         EXTERN COLUMN_ADDRESS_LOW
  20.         EXTERN ADDRESS_VALUE
  21.         EXTERN ADDRESS_LATCH_INTO
  22.         FUNCTION ADDRESS_LATCH_INTO,0202H
  23.         EXTERN COLUMN_ADDRESS_HIGH
  24.         EXTERN aucUartRxBuf
  25.         EXTERN PROGRAM_256_BYTE
  26.         FUNCTION PROGRAM_256_BYTE,0202H
  27.         EXTERN PROGRAM_ONE_PAGE
  28.         FUNCTION PROGRAM_ONE_PAGE,0202H
  29.         EXTERN ?Epilogue6
  30.         EXTERN ?ShiftRight16u_6
  31.         EXTERN ?DivMod16u
  32.         EXTERN READ_256_BYTE
  33.         FUNCTION READ_256_BYTE,0202H
  34.         EXTERN ?longjmp_r4
  35.         EXTERN ?longjmp_r5
  36.         EXTERN ?setjmp_r4
  37.         EXTERN ?setjmp_r5
  38.         PUBWEAK ?setjmp_save_r4
  39.         PUBWEAK ?setjmp_save_r5
  40.         PUBLIC CalNextPageAddress
  41.         FUNCTION CalNextPageAddress,021203H
  42.         LOCFRAME CSTACK, 14, STACK
  43.         PUBLIC CheckInvalidBlock
  44.         FUNCTION CheckInvalidBlock,021203H
  45.         LOCFRAME CSTACK, 20, STACK
  46.         PUBLIC FlashFormat
  47.         FUNCTION FlashFormat,021203H
  48.         LOCFRAME CSTACK, 6, STACK
  49.         PUBWEAK P2IN
  50.         PUBWEAK P2OUT
  51.         PUBWEAK P5DIR
  52.         PUBWEAK P5IN
  53.         
  54.         CFI Names cfiNames0
  55.         CFI StackFrame CFA SP DATA
  56.         CFI Resource PC:16, SP:16, SR:16, R4:16, R5:16, R6:16, R7:16, R8:16
  57.         CFI Resource R9:16, R10:16, R11:16, R12:16, R13:16, R14:16, R15:16
  58.         CFI EndNames cfiNames0
  59.         
  60.         CFI Common cfiCommon0 Using cfiNames0
  61.         CFI CodeAlign 2
  62.         CFI DataAlign 2
  63.         CFI ReturnAddress PC CODE
  64.         CFI CFA SP+2
  65.         CFI PC Frame(CFA, -2)
  66.         CFI SR Undefined
  67.         CFI R4 SameValue
  68.         CFI R5 SameValue
  69.         CFI R6 SameValue
  70.         CFI R7 SameValue
  71.         CFI R8 SameValue
  72.         CFI R9 SameValue
  73.         CFI R10 SameValue
  74.         CFI R11 SameValue
  75.         CFI R12 Undefined
  76.         CFI R13 Undefined
  77.         CFI R14 Undefined
  78.         CFI R15 Undefined
  79.         CFI EndCommon cfiCommon0
  80.         
  81. // E:projectFaxProgramVson_Bryan_Fax_Conexant_070423filesFlashBadBlockProcess.c
  82. //    1 /***************************************
  83. //    2 Program:     FlashBadBlockProcess
  84. //    3 Author:      Bryan Cai
  85. //    4 Date:        2006.12.02
  86. //    5 ***************************************/
  87. //    6 
  88. //    7 #include "includeH.h"
  89.         ASEGN DATA16_AN:DATA:NOROOT,028H
  90. // unsigned char const volatile __data P2IN
  91. P2IN:
  92.         DS8 1
  93.         ASEGN DATA16_AN:DATA:NOROOT,029H
  94. // unsigned char volatile __data P2OUT
  95. P2OUT:
  96.         DS8 1
  97.         ASEGN DATA16_AN:DATA:NOROOT,030H
  98. // unsigned char const volatile __data P5IN
  99. P5IN:
  100.         DS8 1
  101.         ASEGN DATA16_AN:DATA:NOROOT,032H
  102. // unsigned char volatile __data P5DIR
  103. P5DIR:
  104.         DS8 1
  105. //    8 
  106.         RSEG CODE:CODE:NOROOT(1)
  107. //    9 void CheckInvalidBlock(void)
  108. CheckInvalidBlock:
  109.         CFI Block cfiBlock0 Using cfiCommon0
  110.         CFI Function CheckInvalidBlock
  111. //   10 {
  112.         FUNCALL CheckInvalidBlock, ZERO_ADDRESS
  113.         LOCFRAME CSTACK, 20, STACK
  114.         FUNCALL CheckInvalidBlock, ERASE_ONE_BLOCK
  115.         LOCFRAME CSTACK, 20, STACK
  116.         FUNCALL CheckInvalidBlock, ERASE_ONE_BLOCK
  117.         LOCFRAME CSTACK, 20, STACK
  118.         FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
  119.         LOCFRAME CSTACK, 20, STACK
  120.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  121.         LOCFRAME CSTACK, 20, STACK
  122.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  123.         LOCFRAME CSTACK, 20, STACK
  124.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  125.         LOCFRAME CSTACK, 20, STACK
  126.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  127.         LOCFRAME CSTACK, 20, STACK
  128.         FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
  129.         LOCFRAME CSTACK, 20, STACK
  130.         FUNCALL CheckInvalidBlock, PROGRAM_256_BYTE
  131.         LOCFRAME CSTACK, 20, STACK
  132.         FUNCALL CheckInvalidBlock, PROGRAM_ONE_PAGE
  133.         LOCFRAME CSTACK, 20, STACK
  134.         FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
  135.         LOCFRAME CSTACK, 20, STACK
  136.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  137.         LOCFRAME CSTACK, 20, STACK
  138.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  139.         LOCFRAME CSTACK, 20, STACK
  140.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  141.         LOCFRAME CSTACK, 20, STACK
  142.         FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
  143.         LOCFRAME CSTACK, 20, STACK
  144.         FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
  145.         LOCFRAME CSTACK, 20, STACK
  146.         FUNCALL CheckInvalidBlock, PROGRAM_256_BYTE
  147.         LOCFRAME CSTACK, 20, STACK
  148.         FUNCALL CheckInvalidBlock, PROGRAM_256_BYTE
  149.         LOCFRAME CSTACK, 20, STACK
  150. PUSH.W R10
  151.         CFI R10 Frame(CFA, -4)
  152.         CFI CFA SP+4
  153. PUSH.W R11
  154.         CFI R11 Frame(CFA, -6)
  155.         CFI CFA SP+6
  156. PUSH.W R8
  157.         CFI R8 Frame(CFA, -8)
  158.         CFI CFA SP+8
  159. PUSH.W R9
  160.         CFI R9 Frame(CFA, -10)
  161.         CFI CFA SP+10
  162. PUSH.W R6
  163.         CFI R6 Frame(CFA, -12)
  164.         CFI CFA SP+12
  165. PUSH.W R7
  166.         CFI R7 Frame(CFA, -14)
  167.         CFI CFA SP+14
  168. PUSH.W R4
  169.         CFI R4 Frame(CFA, -16)
  170.         CFI CFA SP+16
  171. PUSH.W R5
  172.         CFI R5 Frame(CFA, -18)
  173.         CFI CFA SP+18
  174. SUB.W #0x2, SP
  175.         CFI CFA SP+20
  176. //   11   unsigned int wPageAddress=0, wBlockAddress=1,
  177. MOV.W #0x0, R7
  178. MOV.W #0x1, R10
  179. //   12                wByteCnt=0;
  180. MOV.W #0x0, R11
  181. //   13  unsigned char ucFlashWriteData=0,ucFlashReadData=0,
  182. MOV.B #0x0, R4
  183. MOV.B #0x0, R5
  184. //   14                ucRxIndex=0,ucGeneralCnt=0,
  185. MOV.B #0x0, R8
  186. MOV.B #0x0, 0x0(SP)
  187. //   15                ucBadBlockCnt=0,ucRxBufFullCnt=0;
  188. MOV.B #0x0, R9
  189. MOV.B #0x0, R6
  190. //   16    
  191. //   17  ZERO_ADDRESS();
  192. CALL #ZERO_ADDRESS
  193. //   18  ERASE_ONE_BLOCK();   // Erase block 0
  194. CALL #ERASE_ONE_BLOCK
  195. //   19  for (wBlockAddress=1;wBlockAddress<1024;wBlockAddress++)
  196. MOV.W #0x1, R10
  197. ??CheckInvalidBlock_5:
  198. CMP.W #0x400, R10
  199. JC ??CheckInvalidBlock_6
  200. //   20  {
  201. //   21     wPageAddress=wBlockAddress<<6;
  202. MOV.W R10, R12
  203. CALL #?ShiftLeft16_6
  204. MOV.W R12, R7
  205. //   22     ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  206. MOV.B R7, &ROW_ADDRESS_LOW
  207. //   23     ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  208. MOV.W R7, R14
  209. SWPB R14
  210. AND.W #0xff, R14
  211. MOV.B R14, &ROW_ADDRESS_HIGH
  212. //   24     ERASE_ONE_BLOCK();
  213. CALL #ERASE_ONE_BLOCK
  214. //   25    for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,wPageAddress++)
  215. MOV.B #0x0, 0x0(SP)
  216. ??CheckInvalidBlock_4:
  217. CMP.B #0x40, 0x0(SP)
  218. JC ??CheckInvalidBlock_7
  219. //   26    {
  220. //   27     ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  221. MOV.B R7, &ROW_ADDRESS_LOW
  222. //   28     ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  223. MOV.W R7, R14
  224. SWPB R14
  225. AND.W #0xff, R14
  226. MOV.B R14, &ROW_ADDRESS_HIGH
  227. //   29     ucFlashWriteData=0xff;
  228. MOV.B #0xff, R4
  229. //   30     //PROGRAM_ONE_PAGE(ucFlashWriteData);
  230. //   31 //COMMAND
  231. //   32  COMMAND_VAL=0x00; //#0X00
  232. MOV.B #0x0, &COMMAND_VAL
  233. //   33  COMMAND_LATCH_INTO();
  234. CALL #COMMAND_LATCH_INTO
  235. //   34 //ADDRESS
  236. //   35  ADDRESS_VALUE=COLUMN_ADDRESS_LOW; //#0X00
  237. MOV.B &COLUMN_ADDRESS_LOW, &ADDRESS_VALUE
  238. //   36  ADDRESS_LATCH_INTO();
  239. CALL #ADDRESS_LATCH_INTO
  240. //   37 
  241. //   38  ADDRESS_VALUE=COLUMN_ADDRESS_HIGH; //#0X00
  242. MOV.B &COLUMN_ADDRESS_HIGH, &ADDRESS_VALUE
  243. //   39  ADDRESS_LATCH_INTO();
  244. CALL #ADDRESS_LATCH_INTO
  245. //   40 
  246. //   41  ADDRESS_VALUE=ROW_ADDRESS_LOW; //#0X00
  247. MOV.B &ROW_ADDRESS_LOW, &ADDRESS_VALUE
  248. //   42  ADDRESS_LATCH_INTO();
  249. CALL #ADDRESS_LATCH_INTO
  250. //   43 
  251. //   44  ADDRESS_VALUE=ROW_ADDRESS_HIGH; //#0X00
  252. MOV.B &ROW_ADDRESS_HIGH, &ADDRESS_VALUE
  253. //   45  ADDRESS_LATCH_INTO();
  254. CALL #ADDRESS_LATCH_INTO
  255. //   46  FLASH_CON_PORT_OUT &= ~ALE;
  256. BIC.B #0x2, &0x29
  257. //   47 
  258. //   48  COMMAND_VAL=0X30;
  259. MOV.B #0x30, &COMMAND_VAL
  260. //   49  COMMAND_LATCH_INTO();
  261. CALL #COMMAND_LATCH_INTO
  262. //   50  //ATcmdDelay();
  263. //   51  //for(wGeneralCnt=0;wGeneralCnt<0xff;wGeneralCnt++); //delay
  264. //   52  while((FLASH_CON_PORT_IN & RB)==0);
  265. ??CheckInvalidBlock_0:
  266. BIT.B #0x20, &0x28
  267. JNC ??CheckInvalidBlock_0
  268. //   53   DATA_PORT_IN_INITIAL;
  269. MOV.B #0x0, &0x32
  270. //   54   for(wByteCnt=0;wByteCnt<2112;wByteCnt++)
  271. MOV.W #0x0, R11
  272. ??CheckInvalidBlock_1:
  273. CMP.W #0x840, R11
  274. JC ??CheckInvalidBlock_8
  275. //   55   {
  276. //   56        FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  277. BIC.B #0x10, &0x29
  278. //   57      ucFlashReadData=DATA_PORT_IN;
  279. MOV.B &0x30, R5
  280. //   58      FLASH_CON_PORT_OUT |= RE;
  281. BIS.B #0x10, &0x29
  282. //   59        if (ucFlashReadData!=ucFlashWriteData)
  283. CMP.B R4, R5
  284. JEQ ??CheckInvalidBlock_9
  285. //   60        {
  286. //   61   
  287. //   62       if (ucBadBlockCnt++<128)
  288. MOV.B R9, R14
  289. MOV.B #0x1, R9
  290. ADD.B R14, R9
  291. CMP.B #0x80, R14
  292. JC ??CheckInvalidBlock_10
  293. //   63       {
  294. //   64        aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff;      //low 8 byte
  295. MOV.B R8, R14
  296. AND.W #0xff, R14
  297. MOV.B R10, aucUartRxBuf(R14)
  298. ADD.B #0x1, R8
  299. //   65          aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
  300. MOV.B R8, R15
  301. AND.W #0xff, R15
  302. MOV.W R10, R14
  303. SWPB R14
  304. AND.W #0xff, R14
  305. MOV.B R14, aucUartRxBuf(R15)
  306. ADD.B #0x1, R8
  307. JMP ??CheckInvalidBlock_8
  308. //   66       }//if
  309. //   67       else
  310. //   68       {
  311. //   69           COLUMN_ADDRESS_LOW=0X00;
  312. ??CheckInvalidBlock_10:
  313. MOV.B #0x0, &COLUMN_ADDRESS_LOW
  314. //   70                COLUMN_ADDRESS_HIGH=0X00;
  315. MOV.B #0x0, &COLUMN_ADDRESS_HIGH
  316. //   71                ROW_ADDRESS_LOW=ucRxBufFullCnt;
  317. MOV.B R6, &ROW_ADDRESS_LOW
  318. //   72                ROW_ADDRESS_HIGH=0X00;
  319. MOV.B #0x0, &ROW_ADDRESS_HIGH
  320. //   73           PROGRAM_256_BYTE();
  321. CALL #PROGRAM_256_BYTE
  322. //   74           ucRxBufFullCnt++;
  323. ADD.B #0x1, R6
  324. JMP ??CheckInvalidBlock_8
  325. //   75       }//else
  326. //   76       break;   
  327. //   77       }//if unequal
  328. //   78 
  329. //   79    }//for next byte
  330. ??CheckInvalidBlock_9:
  331. ADD.W #0x1, R11
  332. JMP ??CheckInvalidBlock_1
  333. //   80  if (ucFlashReadData!=ucFlashWriteData){break;}//next block
  334. ??CheckInvalidBlock_8:
  335. CMP.B R4, R5
  336. JNE ??CheckInvalidBlock_7
  337. //   81    
  338. //   82     ucFlashWriteData=0x00;
  339. MOV.B #0x0, R4
  340. //   83     PROGRAM_ONE_PAGE(ucFlashWriteData);
  341. MOV.B R4, R12
  342. CALL #PROGRAM_ONE_PAGE
  343. //   84 //COMMAND
  344. //   85  COMMAND_VAL=0x00; //#0X00
  345. MOV.B #0x0, &COMMAND_VAL
  346. //   86  COMMAND_LATCH_INTO();
  347. CALL #COMMAND_LATCH_INTO
  348. //   87 //ADDRESS
  349. //   88  ADDRESS_VALUE=COLUMN_ADDRESS_LOW; //#0X00
  350. MOV.B &COLUMN_ADDRESS_LOW, &ADDRESS_VALUE
  351. //   89  ADDRESS_LATCH_INTO();
  352. CALL #ADDRESS_LATCH_INTO
  353. //   90 
  354. //   91  ADDRESS_VALUE=COLUMN_ADDRESS_HIGH; //#0X00
  355. MOV.B &COLUMN_ADDRESS_HIGH, &ADDRESS_VALUE
  356. //   92  ADDRESS_LATCH_INTO();
  357. CALL #ADDRESS_LATCH_INTO
  358. //   93 
  359. //   94  ADDRESS_VALUE=ROW_ADDRESS_LOW; //#0X00
  360. MOV.B &ROW_ADDRESS_LOW, &ADDRESS_VALUE
  361. //   95  ADDRESS_LATCH_INTO();
  362. CALL #ADDRESS_LATCH_INTO
  363. //   96 
  364. //   97  ADDRESS_VALUE=ROW_ADDRESS_HIGH; //#0X00
  365. MOV.B &ROW_ADDRESS_HIGH, &ADDRESS_VALUE
  366. //   98  ADDRESS_LATCH_INTO();
  367. CALL #ADDRESS_LATCH_INTO
  368. //   99  FLASH_CON_PORT_OUT &=~ ALE;
  369. BIC.B #0x2, &0x29
  370. //  100 
  371. //  101  COMMAND_VAL=0X30;
  372. MOV.B #0x30, &COMMAND_VAL
  373. //  102  COMMAND_LATCH_INTO();
  374. CALL #COMMAND_LATCH_INTO
  375. //  103  //ATcmdDelay();
  376. //  104  //for(wGeneralCnt=0;wGeneralCnt<0xff;wGeneralCnt++); //delay
  377. //  105  while((FLASH_CON_PORT_IN & RB)==0);
  378. ??CheckInvalidBlock_2:
  379. BIT.B #0x20, &0x28
  380. JNC ??CheckInvalidBlock_2
  381. //  106   DATA_PORT_IN_INITIAL; //MCU INPUT,MCU READ A DATA
  382. MOV.B #0x0, &0x32
  383. //  107   for(wByteCnt=0;wByteCnt<2112;wByteCnt++)
  384. MOV.W #0x0, R11
  385. ??CheckInvalidBlock_3:
  386. CMP.W #0x840, R11
  387. JC ??CheckInvalidBlock_11
  388. //  108   {
  389. //  109          FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  390. BIC.B #0x10, &0x29
  391. //  110  ucFlashReadData=DATA_PORT_IN;
  392. MOV.B &0x30, R5
  393. //  111  FLASH_CON_PORT_OUT |= RE;
  394. BIS.B #0x10, &0x29
  395. //  112      
  396. //  113        if (ucFlashReadData!=ucFlashWriteData)
  397. CMP.B R4, R5
  398. JEQ ??CheckInvalidBlock_12
  399. //  114        {
  400. //  115       if (ucBadBlockCnt++<128)
  401. MOV.B R9, R14
  402. MOV.B #0x1, R9
  403. ADD.B R14, R9
  404. CMP.B #0x80, R14
  405. JC ??CheckInvalidBlock_13
  406. //  116       {
  407. //  117        aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff;      //low 8 byte
  408. MOV.B R8, R14
  409. AND.W #0xff, R14
  410. MOV.B R10, aucUartRxBuf(R14)
  411. ADD.B #0x1, R8
  412. //  118          aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
  413. MOV.B R8, R15
  414. AND.W #0xff, R15
  415. MOV.W R10, R14
  416. SWPB R14
  417. AND.W #0xff, R14
  418. MOV.B R14, aucUartRxBuf(R15)
  419. ADD.B #0x1, R8
  420. JMP ??CheckInvalidBlock_11
  421. //  119       }//if
  422. //  120       else
  423. //  121       {
  424. //  122           COLUMN_ADDRESS_LOW=0X00;
  425. ??CheckInvalidBlock_13:
  426. MOV.B #0x0, &COLUMN_ADDRESS_LOW
  427. //  123                COLUMN_ADDRESS_HIGH=0X00;
  428. MOV.B #0x0, &COLUMN_ADDRESS_HIGH
  429. //  124                ROW_ADDRESS_LOW=ucRxBufFullCnt;
  430. MOV.B R6, &ROW_ADDRESS_LOW
  431. //  125                ROW_ADDRESS_HIGH=0X00;
  432. MOV.B #0x0, &ROW_ADDRESS_HIGH
  433. //  126           PROGRAM_256_BYTE();
  434. CALL #PROGRAM_256_BYTE
  435. //  127           ucRxBufFullCnt++;
  436. ADD.B #0x1, R6
  437. JMP ??CheckInvalidBlock_11
  438. //  128       }//else 
  439. //  129       break;  
  440. //  130       }//if unequal
  441. //  131 
  442. //  132   }//for next byte
  443. ??CheckInvalidBlock_12:
  444. ADD.W #0x1, R11
  445. JMP ??CheckInvalidBlock_3
  446. //  133   if (ucFlashReadData!=ucFlashWriteData){break;}//next block
  447. ??CheckInvalidBlock_11:
  448. CMP.B R4, R5
  449. JNE ??CheckInvalidBlock_7
  450. //  134  }//for next page 
  451. ADD.B #0x1, 0x0(SP)
  452. ADD.W #0x1, R7
  453. JMP ??CheckInvalidBlock_4
  454. //  135   _NOP();
  455. ??CheckInvalidBlock_7:
  456. NOP
  457. //  136   }//for next block
  458. ADD.W #0x1, R10
  459. JMP ??CheckInvalidBlock_5
  460. //  137  if (ucBadBlockCnt!=0)
  461. ??CheckInvalidBlock_6:
  462. CMP.B #0x0, R9
  463. JEQ ??CheckInvalidBlock_14
  464. //  138  {
  465. //  139    COLUMN_ADDRESS_LOW=0X00;
  466. MOV.B #0x0, &COLUMN_ADDRESS_LOW
  467. //  140    COLUMN_ADDRESS_HIGH=0X00;
  468. MOV.B #0x0, &COLUMN_ADDRESS_HIGH
  469. //  141    ROW_ADDRESS_LOW=ucRxBufFullCnt;//first block
  470. MOV.B R6, &ROW_ADDRESS_LOW
  471. //  142    ROW_ADDRESS_HIGH=0X00;
  472. MOV.B #0x0, &ROW_ADDRESS_HIGH
  473. //  143    PROGRAM_256_BYTE();
  474. CALL #PROGRAM_256_BYTE
  475. //  144    ucRxBufFullCnt++;
  476. ADD.B #0x1, R6
  477. //  145  }
  478. //  146 }
  479. ??CheckInvalidBlock_14:
  480. ADD.W #0x2, SP
  481.         CFI CFA SP+18
  482. BR #?Epilogue8
  483.         CFI EndBlock cfiBlock0
  484. //  147 /*
  485. //  148 void CheckInvalidBlockForNewFlash(void) //64*256Bytes=2^14 bytes
  486. //  149 {
  487. //  150  unsigned int wPageAddress=0, wBlockAddress=0;
  488. //  151  unsigned char ucBadBlockCnt=0,ucRxIndex=0,
  489. //  152                ucRxBufFullCnt=0,ucFlashReadData,
  490. //  153                ucGeneralCnt;
  491. //  154 
  492. //  155 
  493. //  156  COLUMN_ADDRESS_LOW=0X00;   //check "FF" at the column address 2048 of 
  494. //  157  COLUMN_ADDRESS_HIGH=0X08;  //the 1st and 2nd page in the block
  495. //  158  while (!(wBlockAddress++==1023))
  496. //  159  {
  497. //  160  wPageAddress=wBlockAddress<<6;
  498. //  161  ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  499. //  162  ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  500. //  163  for (ucGeneralCnt=0;ucGeneralCnt<2;ucGeneralCnt++,wPageAddress++)
  501. //  164  {
  502. //  165 //COMMAND
  503. //  166    COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
  504. //  167    COMMAND_LATCH_INTO();
  505. //  168 //ADDRESS
  506. //  169    ADDRESS_VALUE=COLUMN_ADDRESS_LOW;
  507. //  170    ADDRESS_LATCH_INTO();
  508. //  171 
  509. //  172    ADDRESS_VALUE=COLUMN_ADDRESS_HIGH;
  510. //  173    ADDRESS_LATCH_INTO();
  511. //  174 
  512. //  175    ADDRESS_VALUE=wPageAddress & 0xff; //ROW_ADDRESS_LOW; a bug of Dec. 07,2006
  513. //  176    ADDRESS_LATCH_INTO();
  514. //  177 
  515. //  178    ADDRESS_VALUE=(wPageAddress>>8) & 0xff;
  516. //  179    ADDRESS_LATCH_INTO();
  517. //  180    FLASH_CON_PORT_OUT &=~ ALE;
  518. //  181 
  519. //  182    COMMAND_VAL=0X30;
  520. //  183    COMMAND_LATCH_INTO();
  521. //  184    //ATcmdDelay();
  522. //  185    while((FLASH_CON_PORT_IN & RB)==0);
  523. //  186    DATA_PORT_IN_INITIAL;
  524. //  187    FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  525. //  188    ucFlashReadData=DATA_PORT_IN;
  526. //  189    FLASH_CON_PORT_OUT |= RE;
  527. //  190      if (0xff != ucFlashReadData)
  528. //  191       {
  529. //  192       if (ucBadBlockCnt++<128)
  530. //  193       {
  531. //  194        aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff;      //low 8 byte
  532. //  195          aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
  533. //  196       }//if
  534. //  197       else
  535. //  198       {
  536. //  199              COLUMN_ADDRESS_LOW=0X00;
  537. //  200                COLUMN_ADDRESS_HIGH=0X00;
  538. //  201                ROW_ADDRESS_LOW=ucRxBufFullCnt;
  539. //  202                ROW_ADDRESS_HIGH=0X00;
  540. //  203           PROGRAM_256_BYTE();
  541. //  204           ucRxBufFullCnt++;
  542. //  205       }//else
  543. //  206       break;  //first page or second page   
  544. //  207       }//if
  545. //  208      //else
  546. //  209       //ROW_ADDRESS_LOW++;  //next page-->2nd page in the block //a bug of Dec. 07,2006
  547. //  210    }//for
  548. //  211  }//while
  549. //  212 
  550. //  213  if (ucBadBlockCnt!=0)
  551. //  214  {
  552. //  215    COLUMN_ADDRESS_LOW=0X00;
  553. //  216    COLUMN_ADDRESS_HIGH=0X00;
  554. //  217    ROW_ADDRESS_LOW=ucRxBufFullCnt;//first block
  555. //  218    ROW_ADDRESS_HIGH=0X00;
  556. //  219    PROGRAM_256_BYTE();
  557. //  220 
  558. //  221    ucRxBufFullCnt++;
  559. //  222  }
  560. //  223 
  561. //  224  FlashFormat();
  562. //  225 
  563. //  226 } 
  564. //  227 */
  565. //  228 
  566.         RSEG CODE:CODE:NOROOT(1)
  567. //  229 unsigned int CalNextPageAddress(unsigned int wCurrentPageAddress)
  568. CalNextPageAddress:
  569.         CFI Block cfiBlock1 Using cfiCommon0
  570.         CFI Function CalNextPageAddress
  571. //  230 {
  572.         FUNCALL CalNextPageAddress, READ_256_BYTE
  573.         LOCFRAME CSTACK, 14, STACK
  574. PUSH.W R10
  575.         CFI R10 Frame(CFA, -4)
  576.         CFI CFA SP+4
  577. PUSH.W R11
  578.         CFI R11 Frame(CFA, -6)
  579.         CFI CFA SP+6
  580. PUSH.W R8
  581.         CFI R8 Frame(CFA, -8)
  582.         CFI CFA SP+8
  583. PUSH.W R9
  584.         CFI R9 Frame(CFA, -10)
  585.         CFI CFA SP+10
  586. PUSH.W R6
  587.         CFI R6 Frame(CFA, -12)
  588.         CFI CFA SP+12
  589. PUSH.W R7
  590.         CFI R7 Frame(CFA, -14)
  591.         CFI CFA SP+14
  592. MOV.W R12, R9
  593. //  231     unsigned char ucGeneralCnt=0,ucRxIndex=0,ucBadBlockCnt=0;
  594. MOV.B #0x0, R7
  595. MOV.B #0x0, R10
  596. MOV.B #0x0, R6
  597. //  232     unsigned int  wBlockAddress=0,wNextPageAddress=0;
  598. MOV.W #0x0, R11
  599. MOV.W #0x0, R8
  600. //  233               
  601. //  234     wNextPageAddress=wCurrentPageAddress;
  602. MOV.W R9, R8
  603. //  235     wBlockAddress=wCurrentPageAddress>>6;              
  604. MOV.W R9, R12
  605. CALL #?ShiftRight16u_6
  606. MOV.W R12, R11
  607. //  236     if (wCurrentPageAddress%64==0)
  608. MOV.W R9, R12
  609. MOV.W #0x40, R14
  610. CALL #?DivMod16u
  611. CMP.W #0x0, R14
  612. JNE ??CalNextPageAddress_2
  613. //  237     {
  614. //  238        for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,ROW_ADDRESS_LOW++)
  615. MOV.B #0x0, R7
  616. ??CalNextPageAddress_1:
  617. CMP.B #0x40, R7
  618. JC ??CalNextPageAddress_2
  619. //  239       {
  620. //  240          READ_256_BYTE();
  621. CALL #READ_256_BYTE
  622. //  241          for (ucRxIndex=0,ucBadBlockCnt=0;ucBadBlockCnt<128;ucBadBlockCnt++)
  623. MOV.B #0x0, R10
  624. MOV.B #0x0, R6
  625. ??CalNextPageAddress_0:
  626. CMP.B #0x80, R6
  627. JC ??CalNextPageAddress_3
  628. //  242          {
  629. //  243            if (aucUartRxBuf[ucRxIndex]==(wBlockAddress & 0xff) 
  630. //  244                 && aucUartRxBuf[ucRxIndex+1]==((wBlockAddress>>8) & 0xff))
  631. MOV.B R10, R14
  632. AND.W #0xff, R14
  633. MOV.B R11, R15
  634. AND.B #0xff, R15
  635. CMP.B R15, aucUartRxBuf(R14)
  636. JNE ??CalNextPageAddress_4
  637. MOV.W #aucUartRxBuf, R15
  638. MOV.B R10, R14
  639. AND.W #0xff, R14
  640. ADD.W R14, R15
  641. MOV.W R11, R14
  642. SWPB R14
  643. AND.W #0xff, R14
  644. CMP.B R14, 0x1(R15)
  645. JNE ??CalNextPageAddress_4
  646. //  245                {wNextPageAddress=wCurrentPageAddress+64; break;}
  647. MOV.W #0x40, R14
  648. ADD.W R9, R14
  649. MOV.W R14, R8
  650. JMP ??CalNextPageAddress_3
  651. //  246            if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  652. //  247               aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  653. ??CalNextPageAddress_4:
  654. MOV.B R10, R14
  655. AND.W #0xff, R14
  656. CMP.B #0xff, aucUartRxBuf(R14)
  657. JNE ??CalNextPageAddress_5
  658. MOV.W #aucUartRxBuf, R14
  659. MOV.B R10, R15
  660. AND.W #0xff, R15
  661. ADD.W R15, R14
  662. CMP.B #0xff, 0x1(R14)
  663. JNE ??CalNextPageAddress_5
  664. MOV.W #aucUartRxBuf, R14
  665. MOV.B R10, R15
  666. AND.W #0xff, R15
  667. ADD.W R15, R14
  668. CMP.B #0xff, 0x2(R14)
  669. JNE ??CalNextPageAddress_5
  670. MOV.W #aucUartRxBuf, R14
  671. MOV.B R10, R15
  672. AND.W #0xff, R15
  673. ADD.W R15, R14
  674. CMP.B #0xff, 0x3(R14)
  675. JEQ ??CalNextPageAddress_3
  676. //  248               {break;}
  677. //  249            ucRxIndex+=2;
  678. ??CalNextPageAddress_5:
  679. ADD.B #0x2, R10
  680. //  250          }//for
  681. ADD.B #0x1, R6
  682. JMP ??CalNextPageAddress_0
  683. //  251          if (aucUartRxBuf[ucRxIndex++]==(wBlockAddress & 0xff) 
  684. //  252                 && aucUartRxBuf[ucRxIndex++]==((wBlockAddress>>8) & 0xff))
  685. ??CalNextPageAddress_3:
  686. MOV.B R10, R14
  687. MOV.B #0x1, R10
  688. ADD.B R14, R10
  689. AND.W #0xff, R14
  690. MOV.B R11, R15
  691. AND.B #0xff, R15
  692. CMP.B R15, aucUartRxBuf(R14)
  693. JNE ??CalNextPageAddress_6
  694. MOV.B R10, R15
  695. MOV.B #0x1, R10
  696. ADD.B R15, R10
  697. AND.W #0xff, R15
  698. MOV.W R11, R14
  699. SWPB R14
  700. AND.W #0xff, R14
  701. CMP.B R14, aucUartRxBuf(R15)
  702. JNE ??CalNextPageAddress_6
  703. //  253                {wNextPageAddress=wCurrentPageAddress+64; break;}
  704. MOV.W #0x40, R14
  705. ADD.W R9, R14
  706. MOV.W R14, R8
  707. JMP ??CalNextPageAddress_2
  708. //  254          if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  709. //  255               aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  710. ??CalNextPageAddress_6:
  711. MOV.B R10, R14
  712. AND.W #0xff, R14
  713. CMP.B #0xff, aucUartRxBuf(R14)
  714. JNE ??CalNextPageAddress_7
  715. MOV.W #aucUartRxBuf, R14
  716. MOV.B R10, R15
  717. AND.W #0xff, R15
  718. ADD.W R15, R14
  719. CMP.B #0xff, 0x1(R14)
  720. JNE ??CalNextPageAddress_7
  721. MOV.W #aucUartRxBuf, R14
  722. MOV.B R10, R15
  723. AND.W #0xff, R15
  724. ADD.W R15, R14
  725. CMP.B #0xff, 0x2(R14)
  726. JNE ??CalNextPageAddress_7
  727. MOV.W #aucUartRxBuf, R14
  728. AND.W #0xff, R10
  729. ADD.W R10, R14
  730. CMP.B #0xff, 0x3(R14)
  731. JEQ ??CalNextPageAddress_2
  732. //  256               {break;}
  733. //  257       }//for
  734. ??CalNextPageAddress_7:
  735. ADD.B #0x1, R7
  736. ADD.B #0x1, &ROW_ADDRESS_LOW
  737. JMP ??CalNextPageAddress_1
  738. //  258     }//if
  739. //  259     return wNextPageAddress;
  740. ??CalNextPageAddress_2:
  741. MOV.W R8, R12
  742. BR #?Epilogue6
  743.         CFI EndBlock cfiBlock1
  744. //  260 }
  745. //  261 /*******************
  746. //  262 unsigned int CalNextBlockAddress(unsigned int wCurrentBlockAddress)
  747. //  263 {
  748. //  264     unsigned char ucGeneralCnt=0,ucRxIndex=0,ucBadBlockCnt=0;
  749. //  265     unsigned int  wBlockAddress=0,wNextBlockAddress=0;
  750. //  266               
  751. //  267     wNextBlockAddress=wCurrentBlockAddress;              
  752. //  268     for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,ROW_ADDRESS_LOW++)
  753. //  269       {
  754. //  270          
  755. //  271          READ_256_BYTE();
  756. //  272          for (ucRxIndex=0,ucBadBlockCnt=0;ucBadBlockCnt<128;ucBadBlockCnt++)
  757. //  273          {
  758. //  274            if (aucUartRxBuf[ucRxIndex++]==(wBlockAddress & 0xff) 
  759. //  275                 && aucUartRxBuf[ucRxIndex++]==((wBlockAddress>>8) & 0xff))
  760. //  276                {wNextBlockAddress=wCurrentBlockAddress+1; break;}
  761. //  277            if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  762. //  278               aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  763. //  279               {break;}
  764. //  280          }//for
  765. //  281          if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  766. //  282               aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  767. //  283               {break;}
  768. //  284       }//for
  769. //  285      return wNextBlockAddress;
  770. //  286 } 
  771. //  287 *******************************/ 
  772.         RSEG CODE:CODE:NOROOT(1)
  773. //  288 void FlashFormat(void)
  774. FlashFormat:
  775.         CFI Block cfiBlock2 Using cfiCommon0
  776.         CFI Function FlashFormat
  777. //  289 {
  778.         FUNCALL FlashFormat, ERASE_ONE_BLOCK
  779.         LOCFRAME CSTACK, 6, STACK
  780. PUSH.W R10
  781.         CFI R10 Frame(CFA, -4)
  782.         CFI CFA SP+4
  783. PUSH.W R11
  784.         CFI R11 Frame(CFA, -6)
  785.         CFI CFA SP+6
  786. //  290           unsigned int wBlockAddress=0,wPageAddress=0;
  787. MOV.W #0x0, R10
  788. MOV.W #0x0, R11
  789. //  291           for (wBlockAddress=1;wBlockAddress<1024;wBlockAddress++)
  790. MOV.W #0x1, R10
  791. ??FlashFormat_0:
  792. CMP.W #0x400, R10
  793. JC ??FlashFormat_1
  794. //  292          {
  795. //  293                  wPageAddress=wBlockAddress<<6;
  796. MOV.W R10, R12
  797. CALL #?ShiftLeft16_6
  798. MOV.W R12, R11
  799. //  294            ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  800. MOV.B R11, &ROW_ADDRESS_LOW
  801. //  295            ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  802. MOV.W R11, R14
  803. SWPB R14
  804. AND.W #0xff, R14
  805. MOV.B R14, &ROW_ADDRESS_HIGH
  806. //  296            ERASE_ONE_BLOCK();
  807. CALL #ERASE_ONE_BLOCK
  808. //  297          }
  809. ADD.W #0x1, R10
  810. JMP ??FlashFormat_0
  811. //  298 } 
  812. ??FlashFormat_1:
  813. POP.W R11
  814.         CFI R11 SameValue
  815.         CFI CFA SP+4
  816. POP.W R10
  817.         CFI R10 SameValue
  818.         CFI CFA SP+2
  819. RET
  820.         CFI EndBlock cfiBlock2
  821.         RSEG CODE:CODE:NOROOT(1)
  822. ?setjmp_save_r4:
  823. REQUIRE ?setjmp_r4
  824. REQUIRE ?longjmp_r4
  825.         RSEG CODE:CODE:NOROOT(1)
  826. ?setjmp_save_r5:
  827. REQUIRE ?setjmp_r5
  828. REQUIRE ?longjmp_r5
  829.         END
  830. // 
  831. // 906 bytes in segment CODE
  832. //   4 bytes in segment DATA16_AN
  833. // 
  834. // 906 bytes of CODE memory
  835. //   0 bytes of DATA memory (+ 4 bytes shared)
  836. //
  837. //Errors: none
  838. //Warnings: none