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

传真(Fax)编程

开发平台:

C/C++

  1. ##############################################################################
  2. #                                                                            #
  3. # IAR MSP430 C/EC++ Compiler V2.10A/W32                23/Apr/2007  18:04:11 #
  4. # Copyright 1996-2003 IAR Systems. All rights reserved.                      #
  5. #                                                                            #
  6. #    __rt_version  =  1                                                      #
  7. #    __double_size =  32                                                     #
  8. #    __reg_r4      =  free                                                   #
  9. #    __reg_r5      =  free                                                   #
  10. #    __pic         =  no                                                     #
  11. #    Source file   =  E:projectFaxProgramVson_Bryan_Fax_Conexant_070423 #
  12. #                     filesFlashBadBlockProcess.c                           #
  13. #    Command line  =  -I "C:Program FilesIAR SystemsEmbedded Workbench    #
  14. #                     3.2430INC" -I "C:Program FilesIAR                 #
  15. #                     SystemsEmbedded Workbench 3.2430INCCLIB" -lCN     #
  16. #                     E:projectFaxProgramVson_Bryan_Fax_Conexant_070423 #
  17. #                     DebugList -lA E:projectFaxProgramVson_Bryan_Fax_ #
  18. #                     Conexant_070423DebugList -o                         #
  19. #                     E:projectFaxProgramVson_Bryan_Fax_Conexant_070423 #
  20. #                     DebugObj -z2 --no_cse --no_unroll --no_inline        #
  21. #                     --no_code_motion --debug -e                            #
  22. #                     E:projectFaxProgramVson_Bryan_Fax_Conexant_070423 #
  23. #                     filesFlashBadBlockProcess.c                           #
  24. #    List file     =  E:projectFaxProgramVson_Bryan_Fax_Conexant_070423 #
  25. #                     DebugListFlashBadBlockProcess.lst                    #
  26. #    Object file   =  E:projectFaxProgramVson_Bryan_Fax_Conexant_070423 #
  27. #                     DebugObjFlashBadBlockProcess.r43                     #
  28. #                                                                            #
  29. #                                                                            #
  30. ##############################################################################
  31. E:projectFaxProgramVson_Bryan_Fax_Conexant_070423filesFlashBadBlockProcess.c
  32.       1          /***************************************
  33.       2          Program:     FlashBadBlockProcess
  34.       3          Author:      Bryan Cai
  35.       4          Date:        2006.12.02
  36.       5          ***************************************/
  37.       6          
  38.       7          #include "includeH.h"
  39.                                     In segment DATA16_AN, at 0x28
  40.       unsigned char const volatile __data P2IN
  41.                         P2IN:
  42.       000000                        DS8 1
  43.                                     In segment DATA16_AN, at 0x29
  44.       unsigned char volatile __data P2OUT
  45.                         P2OUT:
  46.       000000                        DS8 1
  47.                                     In segment DATA16_AN, at 0x30
  48.       unsigned char const volatile __data P5IN
  49.                         P5IN:
  50.       000000                        DS8 1
  51.                                     In segment DATA16_AN, at 0x32
  52.       unsigned char volatile __data P5DIR
  53.                         P5DIR:
  54.       000000                        DS8 1
  55.       8          
  56.                                     In segment CODE, align 2, keep-with-next
  57.       9          void CheckInvalidBlock(void)
  58.                         CheckInvalidBlock:
  59.      10          {
  60.       000000   0A12                 PUSH.W  R10
  61.       000002   0B12                 PUSH.W  R11
  62.       000004   0812                 PUSH.W  R8
  63.       000006   0912                 PUSH.W  R9
  64.       000008   0612                 PUSH.W  R6
  65.       00000A   0712                 PUSH.W  R7
  66.       00000C   0412                 PUSH.W  R4
  67.       00000E   0512                 PUSH.W  R5
  68.       000010   2183                 SUB.W   #0x2, SP
  69.      11            unsigned int wPageAddress=0, wBlockAddress=1,
  70.       000012   0743                 MOV.W   #0x0, R7
  71.       000014   1A43                 MOV.W   #0x1, R10
  72.      12                         wByteCnt=0;
  73.       000016   0B43                 MOV.W   #0x0, R11
  74.      13           unsigned char ucFlashWriteData=0,ucFlashReadData=0,
  75.       000018   4443                 MOV.B   #0x0, R4
  76.       00001A   4543                 MOV.B   #0x0, R5
  77.      14                         ucRxIndex=0,ucGeneralCnt=0,
  78.       00001C   4843                 MOV.B   #0x0, R8
  79.       00001E   C1430000             MOV.B   #0x0, 0x0(SP)
  80.      15                         ucBadBlockCnt=0,ucRxBufFullCnt=0;
  81.       000022   4943                 MOV.B   #0x0, R9
  82.       000024   4643                 MOV.B   #0x0, R6
  83.      16             
  84.      17           ZERO_ADDRESS();
  85.       000026   B012....             CALL    #ZERO_ADDRESS
  86.      18           ERASE_ONE_BLOCK();   // Erase block 0
  87.       00002A   B012....             CALL    #ERASE_ONE_BLOCK
  88.      19           for (wBlockAddress=1;wBlockAddress<1024;wBlockAddress++)
  89.       00002E   1A43                 MOV.W   #0x1, R10
  90.                         ??CheckInvalidBlock_5:
  91.       000030   3A900004             CMP.W   #0x400, R10
  92.       000034   DC2C                 JC      ??CheckInvalidBlock_6
  93.      20           {
  94.      21              wPageAddress=wBlockAddress<<6;
  95.       000036   0C4A                 MOV.W   R10, R12
  96.       000038   B012....             CALL    #?ShiftLeft16_6
  97.       00003C   074C                 MOV.W   R12, R7
  98.      22              ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  99.       00003E   C247....             MOV.B   R7, &ROW_ADDRESS_LOW
  100.      23              ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  101.       000042   0E47                 MOV.W   R7, R14
  102.       000044   8E10                 SWPB    R14
  103.       000046   3EF0FF00             AND.W   #0xff, R14
  104.       00004A   C24E....             MOV.B   R14, &ROW_ADDRESS_HIGH
  105.      24              ERASE_ONE_BLOCK();
  106.       00004E   B012....             CALL    #ERASE_ONE_BLOCK
  107.      25             for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,wPageAddress++)
  108.       000052   C1430000             MOV.B   #0x0, 0x0(SP)
  109.                         ??CheckInvalidBlock_4:
  110.       000056   F19040000000         CMP.B   #0x40, 0x0(SP)
  111.       00005C   C52C                 JC      ??CheckInvalidBlock_7
  112.      26             {
  113.      27              ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  114.       00005E   C247....             MOV.B   R7, &ROW_ADDRESS_LOW
  115.      28              ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  116.       000062   0E47                 MOV.W   R7, R14
  117.       000064   8E10                 SWPB    R14
  118.       000066   3EF0FF00             AND.W   #0xff, R14
  119.       00006A   C24E....             MOV.B   R14, &ROW_ADDRESS_HIGH
  120.      29              ucFlashWriteData=0xff;
  121.       00006E   7443                 MOV.B   #0xff, R4
  122.      30              //PROGRAM_ONE_PAGE(ucFlashWriteData);
  123.      31          //COMMAND
  124.      32           COMMAND_VAL=0x00; //#0X00
  125.       000070   C243....             MOV.B   #0x0, &COMMAND_VAL
  126.      33           COMMAND_LATCH_INTO();
  127.       000074   B012....             CALL    #COMMAND_LATCH_INTO
  128.      34          //ADDRESS
  129.      35           ADDRESS_VALUE=COLUMN_ADDRESS_LOW; //#0X00
  130.       000078   D242........         MOV.B   &COLUMN_ADDRESS_LOW, &ADDRESS_VALUE
  131.      36           ADDRESS_LATCH_INTO();
  132.       00007E   B012....             CALL    #ADDRESS_LATCH_INTO
  133.      37          
  134.      38           ADDRESS_VALUE=COLUMN_ADDRESS_HIGH; //#0X00
  135.       000082   D242........         MOV.B   &COLUMN_ADDRESS_HIGH, &ADDRESS_VALUE
  136.      39           ADDRESS_LATCH_INTO();
  137.       000088   B012....             CALL    #ADDRESS_LATCH_INTO
  138.      40          
  139.      41           ADDRESS_VALUE=ROW_ADDRESS_LOW; //#0X00
  140.       00008C   D242........         MOV.B   &ROW_ADDRESS_LOW, &ADDRESS_VALUE
  141.      42           ADDRESS_LATCH_INTO();
  142.       000092   B012....             CALL    #ADDRESS_LATCH_INTO
  143.      43          
  144.      44           ADDRESS_VALUE=ROW_ADDRESS_HIGH; //#0X00
  145.       000096   D242........         MOV.B   &ROW_ADDRESS_HIGH, &ADDRESS_VALUE
  146.      45           ADDRESS_LATCH_INTO();
  147.       00009C   B012....             CALL    #ADDRESS_LATCH_INTO
  148.      46           FLASH_CON_PORT_OUT &= ~ALE;
  149.       0000A0   E2C32900             BIC.B   #0x2, &0x29
  150.      47          
  151.      48           COMMAND_VAL=0X30;
  152.       0000A4   F2403000....         MOV.B   #0x30, &COMMAND_VAL
  153.      49           COMMAND_LATCH_INTO();
  154.       0000AA   B012....             CALL    #COMMAND_LATCH_INTO
  155.      50           //ATcmdDelay();
  156.      51           //for(wGeneralCnt=0;wGeneralCnt<0xff;wGeneralCnt++); //delay
  157.      52           while((FLASH_CON_PORT_IN & RB)==0);
  158.                         ??CheckInvalidBlock_0:
  159.       0000AE   F2B020002800         BIT.B   #0x20, &0x28
  160.       0000B4   FC2B                 JNC     ??CheckInvalidBlock_0
  161.      53            DATA_PORT_IN_INITIAL;
  162.       0000B6   C2433200             MOV.B   #0x0, &0x32
  163.      54            for(wByteCnt=0;wByteCnt<2112;wByteCnt++)
  164.       0000BA   0B43                 MOV.W   #0x0, R11
  165.                         ??CheckInvalidBlock_1:
  166.       0000BC   3B904008             CMP.W   #0x840, R11
  167.       0000C0   2F2C                 JC      ??CheckInvalidBlock_8
  168.      55            {
  169.      56                 FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  170.       0000C2   F2C010002900         BIC.B   #0x10, &0x29
  171.      57               ucFlashReadData=DATA_PORT_IN;
  172.       0000C8   55423000             MOV.B   &0x30, R5
  173.      58               FLASH_CON_PORT_OUT |= RE;
  174.       0000CC   F2D010002900         BIS.B   #0x10, &0x29
  175.      59                 if (ucFlashReadData!=ucFlashWriteData)
  176.       0000D2   4594                 CMP.B   R4, R5
  177.       0000D4   2324                 JEQ     ??CheckInvalidBlock_9
  178.      60                 {
  179.      61            
  180.      62                if (ucBadBlockCnt++<128)
  181.       0000D6   4E49                 MOV.B   R9, R14
  182.       0000D8   5943                 MOV.B   #0x1, R9
  183.       0000DA   495E                 ADD.B   R14, R9
  184.       0000DC   7E908000             CMP.B   #0x80, R14
  185.       0000E0   112C                 JC      ??CheckInvalidBlock_10
  186.      63                {
  187.      64                 aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff;      //low 8 byte
  188.       0000E2   4E48                 MOV.B   R8, R14
  189.       0000E4   3EF0FF00             AND.W   #0xff, R14
  190.       0000E8   CE4A....             MOV.B   R10, aucUartRxBuf(R14)
  191.       0000EC   5853                 ADD.B   #0x1, R8
  192.      65                   aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
  193.       0000EE   4F48                 MOV.B   R8, R15
  194.       0000F0   3FF0FF00             AND.W   #0xff, R15
  195.       0000F4   0E4A                 MOV.W   R10, R14
  196.       0000F6   8E10                 SWPB    R14
  197.       0000F8   3EF0FF00             AND.W   #0xff, R14
  198.       0000FC   CF4E....             MOV.B   R14, aucUartRxBuf(R15)
  199.       000100   5853                 ADD.B   #0x1, R8
  200.       000102   0E3C                 JMP     ??CheckInvalidBlock_8
  201.      66                }//if
  202.      67                else
  203.      68                {
  204.      69                    COLUMN_ADDRESS_LOW=0X00;
  205.                         ??CheckInvalidBlock_10:
  206.       000104   C243....             MOV.B   #0x0, &COLUMN_ADDRESS_LOW
  207.      70                         COLUMN_ADDRESS_HIGH=0X00;
  208.       000108   C243....             MOV.B   #0x0, &COLUMN_ADDRESS_HIGH
  209.      71                         ROW_ADDRESS_LOW=ucRxBufFullCnt;
  210.       00010C   C246....             MOV.B   R6, &ROW_ADDRESS_LOW
  211.      72                         ROW_ADDRESS_HIGH=0X00;
  212.       000110   C243....             MOV.B   #0x0, &ROW_ADDRESS_HIGH
  213.      73                    PROGRAM_256_BYTE();
  214.       000114   B012....             CALL    #PROGRAM_256_BYTE
  215.      74                    ucRxBufFullCnt++;
  216.       000118   5653                 ADD.B   #0x1, R6
  217.       00011A   023C                 JMP     ??CheckInvalidBlock_8
  218.      75                }//else
  219.      76                break;   
  220.      77                }//if unequal
  221.      78          
  222.      79             }//for next byte
  223.                         ??CheckInvalidBlock_9:
  224.       00011C   1B53                 ADD.W   #0x1, R11
  225.       00011E   CE3F                 JMP     ??CheckInvalidBlock_1
  226.      80           if (ucFlashReadData!=ucFlashWriteData){break;}//next block
  227.                         ??CheckInvalidBlock_8:
  228.       000120   4594                 CMP.B   R4, R5
  229.       000122   6220                 JNE     ??CheckInvalidBlock_7
  230.      81             
  231.      82              ucFlashWriteData=0x00;
  232.       000124   4443                 MOV.B   #0x0, R4
  233.      83              PROGRAM_ONE_PAGE(ucFlashWriteData);
  234.       000126   4C44                 MOV.B   R4, R12
  235.       000128   B012....             CALL    #PROGRAM_ONE_PAGE
  236.      84          //COMMAND
  237.      85           COMMAND_VAL=0x00; //#0X00
  238.       00012C   C243....             MOV.B   #0x0, &COMMAND_VAL
  239.      86           COMMAND_LATCH_INTO();
  240.       000130   B012....             CALL    #COMMAND_LATCH_INTO
  241.      87          //ADDRESS
  242.      88           ADDRESS_VALUE=COLUMN_ADDRESS_LOW; //#0X00
  243.       000134   D242........         MOV.B   &COLUMN_ADDRESS_LOW, &ADDRESS_VALUE
  244.      89           ADDRESS_LATCH_INTO();
  245.       00013A   B012....             CALL    #ADDRESS_LATCH_INTO
  246.      90          
  247.      91           ADDRESS_VALUE=COLUMN_ADDRESS_HIGH; //#0X00
  248.       00013E   D242........         MOV.B   &COLUMN_ADDRESS_HIGH, &ADDRESS_VALUE
  249.      92           ADDRESS_LATCH_INTO();
  250.       000144   B012....             CALL    #ADDRESS_LATCH_INTO
  251.      93          
  252.      94           ADDRESS_VALUE=ROW_ADDRESS_LOW; //#0X00
  253.       000148   D242........         MOV.B   &ROW_ADDRESS_LOW, &ADDRESS_VALUE
  254.      95           ADDRESS_LATCH_INTO();
  255.       00014E   B012....             CALL    #ADDRESS_LATCH_INTO
  256.      96          
  257.      97           ADDRESS_VALUE=ROW_ADDRESS_HIGH; //#0X00
  258.       000152   D242........         MOV.B   &ROW_ADDRESS_HIGH, &ADDRESS_VALUE
  259.      98           ADDRESS_LATCH_INTO();
  260.       000158   B012....             CALL    #ADDRESS_LATCH_INTO
  261.      99           FLASH_CON_PORT_OUT &=~ ALE;
  262.       00015C   E2C32900             BIC.B   #0x2, &0x29
  263.     100          
  264.     101           COMMAND_VAL=0X30;
  265.       000160   F2403000....         MOV.B   #0x30, &COMMAND_VAL
  266.     102           COMMAND_LATCH_INTO();
  267.       000166   B012....             CALL    #COMMAND_LATCH_INTO
  268.     103           //ATcmdDelay();
  269.     104           //for(wGeneralCnt=0;wGeneralCnt<0xff;wGeneralCnt++); //delay
  270.     105           while((FLASH_CON_PORT_IN & RB)==0);
  271.                         ??CheckInvalidBlock_2:
  272.       00016A   F2B020002800         BIT.B   #0x20, &0x28
  273.       000170   FC2B                 JNC     ??CheckInvalidBlock_2
  274.     106            DATA_PORT_IN_INITIAL; //MCU INPUT,MCU READ A DATA
  275.       000172   C2433200             MOV.B   #0x0, &0x32
  276.     107            for(wByteCnt=0;wByteCnt<2112;wByteCnt++)
  277.       000176   0B43                 MOV.W   #0x0, R11
  278.                         ??CheckInvalidBlock_3:
  279.       000178   3B904008             CMP.W   #0x840, R11
  280.       00017C   2F2C                 JC      ??CheckInvalidBlock_11
  281.     108            {
  282.     109                   FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  283.       00017E   F2C010002900         BIC.B   #0x10, &0x29
  284.     110           ucFlashReadData=DATA_PORT_IN;
  285.       000184   55423000             MOV.B   &0x30, R5
  286.     111           FLASH_CON_PORT_OUT |= RE;
  287.       000188   F2D010002900         BIS.B   #0x10, &0x29
  288.     112               
  289.     113                 if (ucFlashReadData!=ucFlashWriteData)
  290.       00018E   4594                 CMP.B   R4, R5
  291.       000190   2324                 JEQ     ??CheckInvalidBlock_12
  292.     114                 {
  293.     115                if (ucBadBlockCnt++<128)
  294.       000192   4E49                 MOV.B   R9, R14
  295.       000194   5943                 MOV.B   #0x1, R9
  296.       000196   495E                 ADD.B   R14, R9
  297.       000198   7E908000             CMP.B   #0x80, R14
  298.       00019C   112C                 JC      ??CheckInvalidBlock_13
  299.     116                {
  300.     117                 aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff;      //low 8 byte
  301.       00019E   4E48                 MOV.B   R8, R14
  302.       0001A0   3EF0FF00             AND.W   #0xff, R14
  303.       0001A4   CE4A....             MOV.B   R10, aucUartRxBuf(R14)
  304.       0001A8   5853                 ADD.B   #0x1, R8
  305.     118                   aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
  306.       0001AA   4F48                 MOV.B   R8, R15
  307.       0001AC   3FF0FF00             AND.W   #0xff, R15
  308.       0001B0   0E4A                 MOV.W   R10, R14
  309.       0001B2   8E10                 SWPB    R14
  310.       0001B4   3EF0FF00             AND.W   #0xff, R14
  311.       0001B8   CF4E....             MOV.B   R14, aucUartRxBuf(R15)
  312.       0001BC   5853                 ADD.B   #0x1, R8
  313.       0001BE   0E3C                 JMP     ??CheckInvalidBlock_11
  314.     119                }//if
  315.     120                else
  316.     121                {
  317.     122                    COLUMN_ADDRESS_LOW=0X00;
  318.                         ??CheckInvalidBlock_13:
  319.       0001C0   C243....             MOV.B   #0x0, &COLUMN_ADDRESS_LOW
  320.     123                         COLUMN_ADDRESS_HIGH=0X00;
  321.       0001C4   C243....             MOV.B   #0x0, &COLUMN_ADDRESS_HIGH
  322.     124                         ROW_ADDRESS_LOW=ucRxBufFullCnt;
  323.       0001C8   C246....             MOV.B   R6, &ROW_ADDRESS_LOW
  324.     125                         ROW_ADDRESS_HIGH=0X00;
  325.       0001CC   C243....             MOV.B   #0x0, &ROW_ADDRESS_HIGH
  326.     126                    PROGRAM_256_BYTE();
  327.       0001D0   B012....             CALL    #PROGRAM_256_BYTE
  328.     127                    ucRxBufFullCnt++;
  329.       0001D4   5653                 ADD.B   #0x1, R6
  330.       0001D6   023C                 JMP     ??CheckInvalidBlock_11
  331.     128                }//else 
  332.     129                break;  
  333.     130                }//if unequal
  334.     131          
  335.     132            }//for next byte
  336.                         ??CheckInvalidBlock_12:
  337.       0001D8   1B53                 ADD.W   #0x1, R11
  338.       0001DA   CE3F                 JMP     ??CheckInvalidBlock_3
  339.     133            if (ucFlashReadData!=ucFlashWriteData){break;}//next block
  340.                         ??CheckInvalidBlock_11:
  341.       0001DC   4594                 CMP.B   R4, R5
  342.       0001DE   0420                 JNE     ??CheckInvalidBlock_7
  343.     134           }//for next page 
  344.       0001E0   D1530000             ADD.B   #0x1, 0x0(SP)
  345.       0001E4   1753                 ADD.W   #0x1, R7
  346.       0001E6   373F                 JMP     ??CheckInvalidBlock_4
  347.     135            _NOP();
  348.                         ??CheckInvalidBlock_7:
  349.       0001E8   0343                 NOP
  350.     136            }//for next block
  351.       0001EA   1A53                 ADD.W   #0x1, R10
  352.       0001EC   213F                 JMP     ??CheckInvalidBlock_5
  353.     137           if (ucBadBlockCnt!=0)
  354.                         ??CheckInvalidBlock_6:
  355.       0001EE   4993                 CMP.B   #0x0, R9
  356.       0001F0   0B24                 JEQ     ??CheckInvalidBlock_14
  357.     138           {
  358.     139             COLUMN_ADDRESS_LOW=0X00;
  359.       0001F2   C243....             MOV.B   #0x0, &COLUMN_ADDRESS_LOW
  360.     140             COLUMN_ADDRESS_HIGH=0X00;
  361.       0001F6   C243....             MOV.B   #0x0, &COLUMN_ADDRESS_HIGH
  362.     141             ROW_ADDRESS_LOW=ucRxBufFullCnt;//first block
  363.       0001FA   C246....             MOV.B   R6, &ROW_ADDRESS_LOW
  364.     142             ROW_ADDRESS_HIGH=0X00;
  365.       0001FE   C243....             MOV.B   #0x0, &ROW_ADDRESS_HIGH
  366.     143             PROGRAM_256_BYTE();
  367.       000202   B012....             CALL    #PROGRAM_256_BYTE
  368.     144             ucRxBufFullCnt++;
  369.       000206   5653                 ADD.B   #0x1, R6
  370.     145           }
  371.     146          }
  372.                         ??CheckInvalidBlock_14:
  373.       000208   2153                 ADD.W   #0x2, SP
  374.       00020A   3040....             BR      #?Epilogue8
  375.     147          /*
  376.     148          void CheckInvalidBlockForNewFlash(void) //64*256Bytes=2^14 bytes
  377.     149          {
  378.     150           unsigned int wPageAddress=0, wBlockAddress=0;
  379.     151           unsigned char ucBadBlockCnt=0,ucRxIndex=0,
  380.     152                         ucRxBufFullCnt=0,ucFlashReadData,
  381.     153                         ucGeneralCnt;
  382.     154          
  383.     155          
  384.     156           COLUMN_ADDRESS_LOW=0X00;   //check "FF" at the column address 2048 of 
  385.     157           COLUMN_ADDRESS_HIGH=0X08;  //the 1st and 2nd page in the block
  386.     158           while (!(wBlockAddress++==1023))
  387.     159           {
  388.     160           wPageAddress=wBlockAddress<<6;
  389.     161           ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  390.     162           ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  391.     163           for (ucGeneralCnt=0;ucGeneralCnt<2;ucGeneralCnt++,wPageAddress++)
  392.     164           {
  393.     165          //COMMAND
  394.     166             COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
  395.     167             COMMAND_LATCH_INTO();
  396.     168          //ADDRESS
  397.     169             ADDRESS_VALUE=COLUMN_ADDRESS_LOW;
  398.     170             ADDRESS_LATCH_INTO();
  399.     171          
  400.     172             ADDRESS_VALUE=COLUMN_ADDRESS_HIGH;
  401.     173             ADDRESS_LATCH_INTO();
  402.     174          
  403.     175             ADDRESS_VALUE=wPageAddress & 0xff; //ROW_ADDRESS_LOW; a bug of Dec. 07,2006
  404.     176             ADDRESS_LATCH_INTO();
  405.     177          
  406.     178             ADDRESS_VALUE=(wPageAddress>>8) & 0xff;
  407.     179             ADDRESS_LATCH_INTO();
  408.     180             FLASH_CON_PORT_OUT &=~ ALE;
  409.     181          
  410.     182             COMMAND_VAL=0X30;
  411.     183             COMMAND_LATCH_INTO();
  412.     184             //ATcmdDelay();
  413.     185             while((FLASH_CON_PORT_IN & RB)==0);
  414.     186             DATA_PORT_IN_INITIAL;
  415.     187             FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  416.     188             ucFlashReadData=DATA_PORT_IN;
  417.     189             FLASH_CON_PORT_OUT |= RE;
  418.     190               if (0xff != ucFlashReadData)
  419.     191                {
  420.     192                if (ucBadBlockCnt++<128)
  421.     193                {
  422.     194                 aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff;      //low 8 byte
  423.     195                   aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
  424.     196                }//if
  425.     197                else
  426.     198                {
  427.     199                       COLUMN_ADDRESS_LOW=0X00;
  428.     200                         COLUMN_ADDRESS_HIGH=0X00;
  429.     201                         ROW_ADDRESS_LOW=ucRxBufFullCnt;
  430.     202                         ROW_ADDRESS_HIGH=0X00;
  431.     203                    PROGRAM_256_BYTE();
  432.     204                    ucRxBufFullCnt++;
  433.     205                }//else
  434.     206                break;  //first page or second page   
  435.     207                }//if
  436.     208               //else
  437.     209                //ROW_ADDRESS_LOW++;  //next page-->2nd page in the block //a bug of Dec. 07,2006
  438.     210             }//for
  439.     211           }//while
  440.     212          
  441.     213           if (ucBadBlockCnt!=0)
  442.     214           {
  443.     215             COLUMN_ADDRESS_LOW=0X00;
  444.     216             COLUMN_ADDRESS_HIGH=0X00;
  445.     217             ROW_ADDRESS_LOW=ucRxBufFullCnt;//first block
  446.     218             ROW_ADDRESS_HIGH=0X00;
  447.     219             PROGRAM_256_BYTE();
  448.     220          
  449.     221             ucRxBufFullCnt++;
  450.     222           }
  451.     223          
  452.     224           FlashFormat();
  453.     225          
  454.     226          } 
  455.     227          */
  456.     228          
  457.                                     In segment CODE, align 2, keep-with-next
  458.     229          unsigned int CalNextPageAddress(unsigned int wCurrentPageAddress)
  459.                         CalNextPageAddress:
  460.     230          {
  461.       000000   0A12                 PUSH.W  R10
  462.       000002   0B12                 PUSH.W  R11
  463.       000004   0812                 PUSH.W  R8
  464.       000006   0912                 PUSH.W  R9
  465.       000008   0612                 PUSH.W  R6
  466.       00000A   0712                 PUSH.W  R7
  467.       00000C   094C                 MOV.W   R12, R9
  468.     231              unsigned char ucGeneralCnt=0,ucRxIndex=0,ucBadBlockCnt=0;
  469.       00000E   4743                 MOV.B   #0x0, R7
  470.       000010   4A43                 MOV.B   #0x0, R10
  471.       000012   4643                 MOV.B   #0x0, R6
  472.     232              unsigned int  wBlockAddress=0,wNextPageAddress=0;
  473.       000014   0B43                 MOV.W   #0x0, R11
  474.       000016   0843                 MOV.W   #0x0, R8
  475.     233                        
  476.     234              wNextPageAddress=wCurrentPageAddress;
  477.       000018   0849                 MOV.W   R9, R8
  478.     235              wBlockAddress=wCurrentPageAddress>>6;              
  479.       00001A   0C49                 MOV.W   R9, R12
  480.       00001C   B012....             CALL    #?ShiftRight16u_6
  481.       000020   0B4C                 MOV.W   R12, R11
  482.     236              if (wCurrentPageAddress%64==0)
  483.       000022   0C49                 MOV.W   R9, R12
  484.       000024   3E404000             MOV.W   #0x40, R14
  485.       000028   B012....             CALL    #?DivMod16u
  486.       00002C   0E93                 CMP.W   #0x0, R14
  487.       00002E   8820                 JNE     ??CalNextPageAddress_2
  488.     237              {
  489.     238                 for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,ROW_ADDRESS_LOW++)
  490.       000030   4743                 MOV.B   #0x0, R7
  491.                         ??CalNextPageAddress_1:
  492.       000032   77904000             CMP.B   #0x40, R7
  493.       000036   842C                 JC      ??CalNextPageAddress_2
  494.     239                {
  495.     240                   READ_256_BYTE();
  496.       000038   B012....             CALL    #READ_256_BYTE
  497.     241                   for (ucRxIndex=0,ucBadBlockCnt=0;ucBadBlockCnt<128;ucBadBlockCnt++)
  498.       00003C   4A43                 MOV.B   #0x0, R10
  499.       00003E   4643                 MOV.B   #0x0, R6
  500.                         ??CalNextPageAddress_0:
  501.       000040   76908000             CMP.B   #0x80, R6
  502.       000044   3E2C                 JC      ??CalNextPageAddress_3
  503.     242                   {
  504.     243                     if (aucUartRxBuf[ucRxIndex]==(wBlockAddress & 0xff) 
  505.     244                          && aucUartRxBuf[ucRxIndex+1]==((wBlockAddress>>8) & 0xff))
  506.       000046   4E4A                 MOV.B   R10, R14
  507.       000048   3EF0FF00             AND.W   #0xff, R14
  508.       00004C   4F4B                 MOV.B   R11, R15
  509.       00004E   7FF3                 AND.B   #0xff, R15
  510.       000050   CE9F....             CMP.B   R15, aucUartRxBuf(R14)
  511.       000054   1220                 JNE     ??CalNextPageAddress_4
  512.       000056   3F40....             MOV.W   #aucUartRxBuf, R15
  513.       00005A   4E4A                 MOV.B   R10, R14
  514.       00005C   3EF0FF00             AND.W   #0xff, R14
  515.       000060   0F5E                 ADD.W   R14, R15
  516.       000062   0E4B                 MOV.W   R11, R14
  517.       000064   8E10                 SWPB    R14
  518.       000066   3EF0FF00             AND.W   #0xff, R14
  519.       00006A   CF9E0100             CMP.B   R14, 0x1(R15)
  520.       00006E   0520                 JNE     ??CalNextPageAddress_4
  521.     245                         {wNextPageAddress=wCurrentPageAddress+64; break;}
  522.       000070   3E404000             MOV.W   #0x40, R14
  523.       000074   0E59                 ADD.W   R9, R14
  524.       000076   084E                 MOV.W   R14, R8
  525.       000078   243C                 JMP     ??CalNextPageAddress_3
  526.     246                     if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  527.     247                        aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  528.                         ??CalNextPageAddress_4:
  529.       00007A   4E4A                 MOV.B   R10, R14
  530.       00007C   3EF0FF00             AND.W   #0xff, R14
  531.       000080   FE93....             CMP.B   #0xff, aucUartRxBuf(R14)
  532.       000084   1B20                 JNE     ??CalNextPageAddress_5
  533.       000086   3E40....             MOV.W   #aucUartRxBuf, R14
  534.       00008A   4F4A                 MOV.B   R10, R15
  535.       00008C   3FF0FF00             AND.W   #0xff, R15
  536.       000090   0E5F                 ADD.W   R15, R14
  537.       000092   FE930100             CMP.B   #0xff, 0x1(R14)
  538.       000096   1220                 JNE     ??CalNextPageAddress_5
  539.       000098   3E40....             MOV.W   #aucUartRxBuf, R14
  540.       00009C   4F4A                 MOV.B   R10, R15
  541.       00009E   3FF0FF00             AND.W   #0xff, R15
  542.       0000A2   0E5F                 ADD.W   R15, R14
  543.       0000A4   FE930200             CMP.B   #0xff, 0x2(R14)
  544.       0000A8   0920                 JNE     ??CalNextPageAddress_5
  545.       0000AA   3E40....             MOV.W   #aucUartRxBuf, R14
  546.       0000AE   4F4A                 MOV.B   R10, R15
  547.       0000B0   3FF0FF00             AND.W   #0xff, R15
  548.       0000B4   0E5F                 ADD.W   R15, R14
  549.       0000B6   FE930300             CMP.B   #0xff, 0x3(R14)
  550.       0000BA   0324                 JEQ     ??CalNextPageAddress_3
  551.     248                        {break;}
  552.     249                     ucRxIndex+=2;
  553.                         ??CalNextPageAddress_5:
  554.       0000BC   6A53                 ADD.B   #0x2, R10
  555.     250                   }//for
  556.       0000BE   5653                 ADD.B   #0x1, R6
  557.       0000C0   BF3F                 JMP     ??CalNextPageAddress_0
  558.     251                   if (aucUartRxBuf[ucRxIndex++]==(wBlockAddress & 0xff) 
  559.     252                          && aucUartRxBuf[ucRxIndex++]==((wBlockAddress>>8) & 0xff))
  560.                         ??CalNextPageAddress_3:
  561.       0000C2   4E4A                 MOV.B   R10, R14
  562.       0000C4   5A43                 MOV.B   #0x1, R10
  563.       0000C6   4A5E                 ADD.B   R14, R10
  564.       0000C8   3EF0FF00             AND.W   #0xff, R14
  565.       0000CC   4F4B                 MOV.B   R11, R15
  566.       0000CE   7FF3                 AND.B   #0xff, R15
  567.       0000D0   CE9F....             CMP.B   R15, aucUartRxBuf(R14)
  568.       0000D4   1120                 JNE     ??CalNextPageAddress_6
  569.       0000D6   4F4A                 MOV.B   R10, R15
  570.       0000D8   5A43                 MOV.B   #0x1, R10
  571.       0000DA   4A5F                 ADD.B   R15, R10
  572.       0000DC   3FF0FF00             AND.W   #0xff, R15
  573.       0000E0   0E4B                 MOV.W   R11, R14
  574.       0000E2   8E10                 SWPB    R14
  575.       0000E4   3EF0FF00             AND.W   #0xff, R14
  576.       0000E8   CF9E....             CMP.B   R14, aucUartRxBuf(R15)
  577.       0000EC   0520                 JNE     ??CalNextPageAddress_6
  578.     253                         {wNextPageAddress=wCurrentPageAddress+64; break;}
  579.       0000EE   3E404000             MOV.W   #0x40, R14
  580.       0000F2   0E59                 ADD.W   R9, R14
  581.       0000F4   084E                 MOV.W   R14, R8
  582.       0000F6   243C                 JMP     ??CalNextPageAddress_2
  583.     254                   if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  584.     255                        aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  585.                         ??CalNextPageAddress_6:
  586.       0000F8   4E4A                 MOV.B   R10, R14
  587.       0000FA   3EF0FF00             AND.W   #0xff, R14
  588.       0000FE   FE93....             CMP.B   #0xff, aucUartRxBuf(R14)
  589.       000102   1A20                 JNE     ??CalNextPageAddress_7
  590.       000104   3E40....             MOV.W   #aucUartRxBuf, R14
  591.       000108   4F4A                 MOV.B   R10, R15
  592.       00010A   3FF0FF00             AND.W   #0xff, R15
  593.       00010E   0E5F                 ADD.W   R15, R14
  594.       000110   FE930100             CMP.B   #0xff, 0x1(R14)
  595.       000114   1120                 JNE     ??CalNextPageAddress_7
  596.       000116   3E40....             MOV.W   #aucUartRxBuf, R14
  597.       00011A   4F4A                 MOV.B   R10, R15
  598.       00011C   3FF0FF00             AND.W   #0xff, R15
  599.       000120   0E5F                 ADD.W   R15, R14
  600.       000122   FE930200             CMP.B   #0xff, 0x2(R14)
  601.       000126   0820                 JNE     ??CalNextPageAddress_7
  602.       000128   3E40....             MOV.W   #aucUartRxBuf, R14
  603.       00012C   3AF0FF00             AND.W   #0xff, R10
  604.       000130   0E5A                 ADD.W   R10, R14
  605.       000132   FE930300             CMP.B   #0xff, 0x3(R14)
  606.       000136   0424                 JEQ     ??CalNextPageAddress_2
  607.     256                        {break;}
  608.     257                }//for
  609.                         ??CalNextPageAddress_7:
  610.       000138   5753                 ADD.B   #0x1, R7
  611.       00013A   D253....             ADD.B   #0x1, &ROW_ADDRESS_LOW
  612.       00013E   793F                 JMP     ??CalNextPageAddress_1
  613.     258              }//if
  614.     259              return wNextPageAddress;
  615.                         ??CalNextPageAddress_2:
  616.       000140   0C48                 MOV.W   R8, R12
  617.       000142   3040....             BR      #?Epilogue6
  618.     260          }
  619.     261          /*******************
  620.     262          unsigned int CalNextBlockAddress(unsigned int wCurrentBlockAddress)
  621.     263          {
  622.     264              unsigned char ucGeneralCnt=0,ucRxIndex=0,ucBadBlockCnt=0;
  623.     265              unsigned int  wBlockAddress=0,wNextBlockAddress=0;
  624.     266                        
  625.     267              wNextBlockAddress=wCurrentBlockAddress;              
  626.     268              for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,ROW_ADDRESS_LOW++)
  627.     269                {
  628.     270                   
  629.     271                   READ_256_BYTE();
  630.     272                   for (ucRxIndex=0,ucBadBlockCnt=0;ucBadBlockCnt<128;ucBadBlockCnt++)
  631.     273                   {
  632.     274                     if (aucUartRxBuf[ucRxIndex++]==(wBlockAddress & 0xff) 
  633.     275                          && aucUartRxBuf[ucRxIndex++]==((wBlockAddress>>8) & 0xff))
  634.     276                         {wNextBlockAddress=wCurrentBlockAddress+1; break;}
  635.     277                     if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  636.     278                        aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  637.     279                        {break;}
  638.     280                   }//for
  639.     281                   if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF && 
  640.     282                        aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
  641.     283                        {break;}
  642.     284                }//for
  643.     285               return wNextBlockAddress;
  644.     286          } 
  645.     287          *******************************/ 
  646.                                     In segment CODE, align 2, keep-with-next
  647.     288          void FlashFormat(void)
  648.                         FlashFormat:
  649.     289          {
  650.       000000   0A12                 PUSH.W  R10
  651.       000002   0B12                 PUSH.W  R11
  652.     290                    unsigned int wBlockAddress=0,wPageAddress=0;
  653.       000004   0A43                 MOV.W   #0x0, R10
  654.       000006   0B43                 MOV.W   #0x0, R11
  655.     291                    for (wBlockAddress=1;wBlockAddress<1024;wBlockAddress++)
  656.       000008   1A43                 MOV.W   #0x1, R10
  657.                         ??FlashFormat_0:
  658.       00000A   3A900004             CMP.W   #0x400, R10
  659.       00000E   102C                 JC      ??FlashFormat_1
  660.     292                   {
  661.     293                           wPageAddress=wBlockAddress<<6;
  662.       000010   0C4A                 MOV.W   R10, R12
  663.       000012   B012....             CALL    #?ShiftLeft16_6
  664.       000016   0B4C                 MOV.W   R12, R11
  665.     294                     ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  666.       000018   C24B....             MOV.B   R11, &ROW_ADDRESS_LOW
  667.     295                     ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  668.       00001C   0E4B                 MOV.W   R11, R14
  669.       00001E   8E10                 SWPB    R14
  670.       000020   3EF0FF00             AND.W   #0xff, R14
  671.       000024   C24E....             MOV.B   R14, &ROW_ADDRESS_HIGH
  672.     296                     ERASE_ONE_BLOCK();
  673.       000028   B012....             CALL    #ERASE_ONE_BLOCK
  674.     297                   }
  675.       00002C   1A53                 ADD.W   #0x1, R10
  676.       00002E   ED3F                 JMP     ??FlashFormat_0
  677.     298          } 
  678.                         ??FlashFormat_1:
  679.       000030   3B41                 POP.W   R11
  680.       000032   3A41                 POP.W   R10
  681.       000034   3041                 RET
  682.    Maximum stack usage in bytes:
  683.      Function                CSTACK
  684.      --------                ------
  685.      CalNextPageAddress         14
  686.        -> READ_256_BYTE         14
  687.      CheckInvalidBlock          20
  688.        -> ZERO_ADDRESS          20
  689.        -> ERASE_ONE_BLOCK       20
  690.        -> ERASE_ONE_BLOCK       20
  691.        -> COMMAND_LATCH_INTO    20
  692.        -> ADDRESS_LATCH_INTO    20
  693.        -> ADDRESS_LATCH_INTO    20
  694.        -> ADDRESS_LATCH_INTO    20
  695.        -> ADDRESS_LATCH_INTO    20
  696.        -> COMMAND_LATCH_INTO    20
  697.        -> PROGRAM_256_BYTE      20
  698.        -> PROGRAM_ONE_PAGE      20
  699.        -> COMMAND_LATCH_INTO    20
  700.        -> ADDRESS_LATCH_INTO    20
  701.        -> ADDRESS_LATCH_INTO    20
  702.        -> ADDRESS_LATCH_INTO    20
  703.        -> ADDRESS_LATCH_INTO    20
  704.        -> COMMAND_LATCH_INTO    20
  705.        -> PROGRAM_256_BYTE      20
  706.        -> PROGRAM_256_BYTE      20
  707.      FlashFormat                 6
  708.        -> ERASE_ONE_BLOCK        6
  709.    Segment part sizes:
  710.      Function/Label     Bytes
  711.      --------------     -----
  712.      P2IN                  1
  713.      P2OUT                 1
  714.      P5IN                  1
  715.      P5DIR                 1
  716.      CheckInvalidBlock   526
  717.      CalNextPageAddress  326
  718.      FlashFormat          54
  719.  
  720.  906 bytes in segment CODE
  721.    4 bytes in segment DATA16_AN
  722.  
  723.  906 bytes of CODE memory
  724.    0 bytes of DATA memory (+ 4 bytes shared)
  725. Errors: none
  726. Warnings: none