FlashBadBlockProcess.s43
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:26k
- NAME FlashBadBlockProcess
- RTMODEL "__double_size", "32"
- RTMODEL "__pic", "no"
- RTMODEL "__reg_r4", "free"
- RTMODEL "__reg_r5", "free"
- RTMODEL "__rt_version", "1"
- RSEG CSTACK:DATA:SORT:NOROOT(1)
- EXTERN ?Epilogue8
- EXTERN ZERO_ADDRESS
- FUNCTION ZERO_ADDRESS,0202H
- EXTERN ERASE_ONE_BLOCK
- FUNCTION ERASE_ONE_BLOCK,0202H
- EXTERN ?ShiftLeft16_6
- EXTERN ROW_ADDRESS_LOW
- EXTERN ROW_ADDRESS_HIGH
- EXTERN COMMAND_VAL
- EXTERN COMMAND_LATCH_INTO
- FUNCTION COMMAND_LATCH_INTO,0202H
- EXTERN COLUMN_ADDRESS_LOW
- EXTERN ADDRESS_VALUE
- EXTERN ADDRESS_LATCH_INTO
- FUNCTION ADDRESS_LATCH_INTO,0202H
- EXTERN COLUMN_ADDRESS_HIGH
- EXTERN aucUartRxBuf
- EXTERN PROGRAM_256_BYTE
- FUNCTION PROGRAM_256_BYTE,0202H
- EXTERN PROGRAM_ONE_PAGE
- FUNCTION PROGRAM_ONE_PAGE,0202H
- EXTERN ?Epilogue6
- EXTERN ?ShiftRight16u_6
- EXTERN ?DivMod16u
- EXTERN READ_256_BYTE
- FUNCTION READ_256_BYTE,0202H
- EXTERN ?longjmp_r4
- EXTERN ?longjmp_r5
- EXTERN ?setjmp_r4
- EXTERN ?setjmp_r5
- PUBWEAK ?setjmp_save_r4
- PUBWEAK ?setjmp_save_r5
- PUBLIC CalNextPageAddress
- FUNCTION CalNextPageAddress,021203H
- LOCFRAME CSTACK, 14, STACK
- PUBLIC CheckInvalidBlock
- FUNCTION CheckInvalidBlock,021203H
- LOCFRAME CSTACK, 20, STACK
- PUBLIC FlashFormat
- FUNCTION FlashFormat,021203H
- LOCFRAME CSTACK, 6, STACK
- PUBWEAK P2IN
- PUBWEAK P2OUT
- PUBWEAK P5DIR
- PUBWEAK P5IN
-
- CFI Names cfiNames0
- CFI StackFrame CFA SP DATA
- CFI Resource PC:16, SP:16, SR:16, R4:16, R5:16, R6:16, R7:16, R8:16
- CFI Resource R9:16, R10:16, R11:16, R12:16, R13:16, R14:16, R15:16
- CFI EndNames cfiNames0
-
- CFI Common cfiCommon0 Using cfiNames0
- CFI CodeAlign 2
- CFI DataAlign 2
- CFI ReturnAddress PC CODE
- CFI CFA SP+2
- CFI PC Frame(CFA, -2)
- CFI SR Undefined
- CFI R4 SameValue
- CFI R5 SameValue
- CFI R6 SameValue
- CFI R7 SameValue
- CFI R8 SameValue
- CFI R9 SameValue
- CFI R10 SameValue
- CFI R11 SameValue
- CFI R12 Undefined
- CFI R13 Undefined
- CFI R14 Undefined
- CFI R15 Undefined
- CFI EndCommon cfiCommon0
-
- // E:projectFaxProgramVson_Bryan_Fax_Conexant_070423filesFlashBadBlockProcess.c
- // 1 /***************************************
- // 2 Program: FlashBadBlockProcess
- // 3 Author: Bryan Cai
- // 4 Date: 2006.12.02
- // 5 ***************************************/
- // 6
- // 7 #include "includeH.h"
- ASEGN DATA16_AN:DATA:NOROOT,028H
- // unsigned char const volatile __data P2IN
- P2IN:
- DS8 1
- ASEGN DATA16_AN:DATA:NOROOT,029H
- // unsigned char volatile __data P2OUT
- P2OUT:
- DS8 1
- ASEGN DATA16_AN:DATA:NOROOT,030H
- // unsigned char const volatile __data P5IN
- P5IN:
- DS8 1
- ASEGN DATA16_AN:DATA:NOROOT,032H
- // unsigned char volatile __data P5DIR
- P5DIR:
- DS8 1
- // 8
- RSEG CODE:CODE:NOROOT(1)
- // 9 void CheckInvalidBlock(void)
- CheckInvalidBlock:
- CFI Block cfiBlock0 Using cfiCommon0
- CFI Function CheckInvalidBlock
- // 10 {
- FUNCALL CheckInvalidBlock, ZERO_ADDRESS
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ERASE_ONE_BLOCK
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ERASE_ONE_BLOCK
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, PROGRAM_256_BYTE
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, PROGRAM_ONE_PAGE
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, ADDRESS_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, COMMAND_LATCH_INTO
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, PROGRAM_256_BYTE
- LOCFRAME CSTACK, 20, STACK
- FUNCALL CheckInvalidBlock, PROGRAM_256_BYTE
- LOCFRAME CSTACK, 20, STACK
- PUSH.W R10
- CFI R10 Frame(CFA, -4)
- CFI CFA SP+4
- PUSH.W R11
- CFI R11 Frame(CFA, -6)
- CFI CFA SP+6
- PUSH.W R8
- CFI R8 Frame(CFA, -8)
- CFI CFA SP+8
- PUSH.W R9
- CFI R9 Frame(CFA, -10)
- CFI CFA SP+10
- PUSH.W R6
- CFI R6 Frame(CFA, -12)
- CFI CFA SP+12
- PUSH.W R7
- CFI R7 Frame(CFA, -14)
- CFI CFA SP+14
- PUSH.W R4
- CFI R4 Frame(CFA, -16)
- CFI CFA SP+16
- PUSH.W R5
- CFI R5 Frame(CFA, -18)
- CFI CFA SP+18
- SUB.W #0x2, SP
- CFI CFA SP+20
- // 11 unsigned int wPageAddress=0, wBlockAddress=1,
- MOV.W #0x0, R7
- MOV.W #0x1, R10
- // 12 wByteCnt=0;
- MOV.W #0x0, R11
- // 13 unsigned char ucFlashWriteData=0,ucFlashReadData=0,
- MOV.B #0x0, R4
- MOV.B #0x0, R5
- // 14 ucRxIndex=0,ucGeneralCnt=0,
- MOV.B #0x0, R8
- MOV.B #0x0, 0x0(SP)
- // 15 ucBadBlockCnt=0,ucRxBufFullCnt=0;
- MOV.B #0x0, R9
- MOV.B #0x0, R6
- // 16
- // 17 ZERO_ADDRESS();
- CALL #ZERO_ADDRESS
- // 18 ERASE_ONE_BLOCK(); // Erase block 0
- CALL #ERASE_ONE_BLOCK
- // 19 for (wBlockAddress=1;wBlockAddress<1024;wBlockAddress++)
- MOV.W #0x1, R10
- ??CheckInvalidBlock_5:
- CMP.W #0x400, R10
- JC ??CheckInvalidBlock_6
- // 20 {
- // 21 wPageAddress=wBlockAddress<<6;
- MOV.W R10, R12
- CALL #?ShiftLeft16_6
- MOV.W R12, R7
- // 22 ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- MOV.B R7, &ROW_ADDRESS_LOW
- // 23 ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
- MOV.W R7, R14
- SWPB R14
- AND.W #0xff, R14
- MOV.B R14, &ROW_ADDRESS_HIGH
- // 24 ERASE_ONE_BLOCK();
- CALL #ERASE_ONE_BLOCK
- // 25 for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,wPageAddress++)
- MOV.B #0x0, 0x0(SP)
- ??CheckInvalidBlock_4:
- CMP.B #0x40, 0x0(SP)
- JC ??CheckInvalidBlock_7
- // 26 {
- // 27 ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- MOV.B R7, &ROW_ADDRESS_LOW
- // 28 ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
- MOV.W R7, R14
- SWPB R14
- AND.W #0xff, R14
- MOV.B R14, &ROW_ADDRESS_HIGH
- // 29 ucFlashWriteData=0xff;
- MOV.B #0xff, R4
- // 30 //PROGRAM_ONE_PAGE(ucFlashWriteData);
- // 31 //COMMAND
- // 32 COMMAND_VAL=0x00; //#0X00
- MOV.B #0x0, &COMMAND_VAL
- // 33 COMMAND_LATCH_INTO();
- CALL #COMMAND_LATCH_INTO
- // 34 //ADDRESS
- // 35 ADDRESS_VALUE=COLUMN_ADDRESS_LOW; //#0X00
- MOV.B &COLUMN_ADDRESS_LOW, &ADDRESS_VALUE
- // 36 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 37
- // 38 ADDRESS_VALUE=COLUMN_ADDRESS_HIGH; //#0X00
- MOV.B &COLUMN_ADDRESS_HIGH, &ADDRESS_VALUE
- // 39 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 40
- // 41 ADDRESS_VALUE=ROW_ADDRESS_LOW; //#0X00
- MOV.B &ROW_ADDRESS_LOW, &ADDRESS_VALUE
- // 42 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 43
- // 44 ADDRESS_VALUE=ROW_ADDRESS_HIGH; //#0X00
- MOV.B &ROW_ADDRESS_HIGH, &ADDRESS_VALUE
- // 45 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 46 FLASH_CON_PORT_OUT &= ~ALE;
- BIC.B #0x2, &0x29
- // 47
- // 48 COMMAND_VAL=0X30;
- MOV.B #0x30, &COMMAND_VAL
- // 49 COMMAND_LATCH_INTO();
- CALL #COMMAND_LATCH_INTO
- // 50 //ATcmdDelay();
- // 51 //for(wGeneralCnt=0;wGeneralCnt<0xff;wGeneralCnt++); //delay
- // 52 while((FLASH_CON_PORT_IN & RB)==0);
- ??CheckInvalidBlock_0:
- BIT.B #0x20, &0x28
- JNC ??CheckInvalidBlock_0
- // 53 DATA_PORT_IN_INITIAL;
- MOV.B #0x0, &0x32
- // 54 for(wByteCnt=0;wByteCnt<2112;wByteCnt++)
- MOV.W #0x0, R11
- ??CheckInvalidBlock_1:
- CMP.W #0x840, R11
- JC ??CheckInvalidBlock_8
- // 55 {
- // 56 FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
- BIC.B #0x10, &0x29
- // 57 ucFlashReadData=DATA_PORT_IN;
- MOV.B &0x30, R5
- // 58 FLASH_CON_PORT_OUT |= RE;
- BIS.B #0x10, &0x29
- // 59 if (ucFlashReadData!=ucFlashWriteData)
- CMP.B R4, R5
- JEQ ??CheckInvalidBlock_9
- // 60 {
- // 61
- // 62 if (ucBadBlockCnt++<128)
- MOV.B R9, R14
- MOV.B #0x1, R9
- ADD.B R14, R9
- CMP.B #0x80, R14
- JC ??CheckInvalidBlock_10
- // 63 {
- // 64 aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff; //low 8 byte
- MOV.B R8, R14
- AND.W #0xff, R14
- MOV.B R10, aucUartRxBuf(R14)
- ADD.B #0x1, R8
- // 65 aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
- MOV.B R8, R15
- AND.W #0xff, R15
- MOV.W R10, R14
- SWPB R14
- AND.W #0xff, R14
- MOV.B R14, aucUartRxBuf(R15)
- ADD.B #0x1, R8
- JMP ??CheckInvalidBlock_8
- // 66 }//if
- // 67 else
- // 68 {
- // 69 COLUMN_ADDRESS_LOW=0X00;
- ??CheckInvalidBlock_10:
- MOV.B #0x0, &COLUMN_ADDRESS_LOW
- // 70 COLUMN_ADDRESS_HIGH=0X00;
- MOV.B #0x0, &COLUMN_ADDRESS_HIGH
- // 71 ROW_ADDRESS_LOW=ucRxBufFullCnt;
- MOV.B R6, &ROW_ADDRESS_LOW
- // 72 ROW_ADDRESS_HIGH=0X00;
- MOV.B #0x0, &ROW_ADDRESS_HIGH
- // 73 PROGRAM_256_BYTE();
- CALL #PROGRAM_256_BYTE
- // 74 ucRxBufFullCnt++;
- ADD.B #0x1, R6
- JMP ??CheckInvalidBlock_8
- // 75 }//else
- // 76 break;
- // 77 }//if unequal
- // 78
- // 79 }//for next byte
- ??CheckInvalidBlock_9:
- ADD.W #0x1, R11
- JMP ??CheckInvalidBlock_1
- // 80 if (ucFlashReadData!=ucFlashWriteData){break;}//next block
- ??CheckInvalidBlock_8:
- CMP.B R4, R5
- JNE ??CheckInvalidBlock_7
- // 81
- // 82 ucFlashWriteData=0x00;
- MOV.B #0x0, R4
- // 83 PROGRAM_ONE_PAGE(ucFlashWriteData);
- MOV.B R4, R12
- CALL #PROGRAM_ONE_PAGE
- // 84 //COMMAND
- // 85 COMMAND_VAL=0x00; //#0X00
- MOV.B #0x0, &COMMAND_VAL
- // 86 COMMAND_LATCH_INTO();
- CALL #COMMAND_LATCH_INTO
- // 87 //ADDRESS
- // 88 ADDRESS_VALUE=COLUMN_ADDRESS_LOW; //#0X00
- MOV.B &COLUMN_ADDRESS_LOW, &ADDRESS_VALUE
- // 89 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 90
- // 91 ADDRESS_VALUE=COLUMN_ADDRESS_HIGH; //#0X00
- MOV.B &COLUMN_ADDRESS_HIGH, &ADDRESS_VALUE
- // 92 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 93
- // 94 ADDRESS_VALUE=ROW_ADDRESS_LOW; //#0X00
- MOV.B &ROW_ADDRESS_LOW, &ADDRESS_VALUE
- // 95 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 96
- // 97 ADDRESS_VALUE=ROW_ADDRESS_HIGH; //#0X00
- MOV.B &ROW_ADDRESS_HIGH, &ADDRESS_VALUE
- // 98 ADDRESS_LATCH_INTO();
- CALL #ADDRESS_LATCH_INTO
- // 99 FLASH_CON_PORT_OUT &=~ ALE;
- BIC.B #0x2, &0x29
- // 100
- // 101 COMMAND_VAL=0X30;
- MOV.B #0x30, &COMMAND_VAL
- // 102 COMMAND_LATCH_INTO();
- CALL #COMMAND_LATCH_INTO
- // 103 //ATcmdDelay();
- // 104 //for(wGeneralCnt=0;wGeneralCnt<0xff;wGeneralCnt++); //delay
- // 105 while((FLASH_CON_PORT_IN & RB)==0);
- ??CheckInvalidBlock_2:
- BIT.B #0x20, &0x28
- JNC ??CheckInvalidBlock_2
- // 106 DATA_PORT_IN_INITIAL; //MCU INPUT,MCU READ A DATA
- MOV.B #0x0, &0x32
- // 107 for(wByteCnt=0;wByteCnt<2112;wByteCnt++)
- MOV.W #0x0, R11
- ??CheckInvalidBlock_3:
- CMP.W #0x840, R11
- JC ??CheckInvalidBlock_11
- // 108 {
- // 109 FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
- BIC.B #0x10, &0x29
- // 110 ucFlashReadData=DATA_PORT_IN;
- MOV.B &0x30, R5
- // 111 FLASH_CON_PORT_OUT |= RE;
- BIS.B #0x10, &0x29
- // 112
- // 113 if (ucFlashReadData!=ucFlashWriteData)
- CMP.B R4, R5
- JEQ ??CheckInvalidBlock_12
- // 114 {
- // 115 if (ucBadBlockCnt++<128)
- MOV.B R9, R14
- MOV.B #0x1, R9
- ADD.B R14, R9
- CMP.B #0x80, R14
- JC ??CheckInvalidBlock_13
- // 116 {
- // 117 aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff; //low 8 byte
- MOV.B R8, R14
- AND.W #0xff, R14
- MOV.B R10, aucUartRxBuf(R14)
- ADD.B #0x1, R8
- // 118 aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
- MOV.B R8, R15
- AND.W #0xff, R15
- MOV.W R10, R14
- SWPB R14
- AND.W #0xff, R14
- MOV.B R14, aucUartRxBuf(R15)
- ADD.B #0x1, R8
- JMP ??CheckInvalidBlock_11
- // 119 }//if
- // 120 else
- // 121 {
- // 122 COLUMN_ADDRESS_LOW=0X00;
- ??CheckInvalidBlock_13:
- MOV.B #0x0, &COLUMN_ADDRESS_LOW
- // 123 COLUMN_ADDRESS_HIGH=0X00;
- MOV.B #0x0, &COLUMN_ADDRESS_HIGH
- // 124 ROW_ADDRESS_LOW=ucRxBufFullCnt;
- MOV.B R6, &ROW_ADDRESS_LOW
- // 125 ROW_ADDRESS_HIGH=0X00;
- MOV.B #0x0, &ROW_ADDRESS_HIGH
- // 126 PROGRAM_256_BYTE();
- CALL #PROGRAM_256_BYTE
- // 127 ucRxBufFullCnt++;
- ADD.B #0x1, R6
- JMP ??CheckInvalidBlock_11
- // 128 }//else
- // 129 break;
- // 130 }//if unequal
- // 131
- // 132 }//for next byte
- ??CheckInvalidBlock_12:
- ADD.W #0x1, R11
- JMP ??CheckInvalidBlock_3
- // 133 if (ucFlashReadData!=ucFlashWriteData){break;}//next block
- ??CheckInvalidBlock_11:
- CMP.B R4, R5
- JNE ??CheckInvalidBlock_7
- // 134 }//for next page
- ADD.B #0x1, 0x0(SP)
- ADD.W #0x1, R7
- JMP ??CheckInvalidBlock_4
- // 135 _NOP();
- ??CheckInvalidBlock_7:
- NOP
- // 136 }//for next block
- ADD.W #0x1, R10
- JMP ??CheckInvalidBlock_5
- // 137 if (ucBadBlockCnt!=0)
- ??CheckInvalidBlock_6:
- CMP.B #0x0, R9
- JEQ ??CheckInvalidBlock_14
- // 138 {
- // 139 COLUMN_ADDRESS_LOW=0X00;
- MOV.B #0x0, &COLUMN_ADDRESS_LOW
- // 140 COLUMN_ADDRESS_HIGH=0X00;
- MOV.B #0x0, &COLUMN_ADDRESS_HIGH
- // 141 ROW_ADDRESS_LOW=ucRxBufFullCnt;//first block
- MOV.B R6, &ROW_ADDRESS_LOW
- // 142 ROW_ADDRESS_HIGH=0X00;
- MOV.B #0x0, &ROW_ADDRESS_HIGH
- // 143 PROGRAM_256_BYTE();
- CALL #PROGRAM_256_BYTE
- // 144 ucRxBufFullCnt++;
- ADD.B #0x1, R6
- // 145 }
- // 146 }
- ??CheckInvalidBlock_14:
- ADD.W #0x2, SP
- CFI CFA SP+18
- BR #?Epilogue8
- CFI EndBlock cfiBlock0
- // 147 /*
- // 148 void CheckInvalidBlockForNewFlash(void) //64*256Bytes=2^14 bytes
- // 149 {
- // 150 unsigned int wPageAddress=0, wBlockAddress=0;
- // 151 unsigned char ucBadBlockCnt=0,ucRxIndex=0,
- // 152 ucRxBufFullCnt=0,ucFlashReadData,
- // 153 ucGeneralCnt;
- // 154
- // 155
- // 156 COLUMN_ADDRESS_LOW=0X00; //check "FF" at the column address 2048 of
- // 157 COLUMN_ADDRESS_HIGH=0X08; //the 1st and 2nd page in the block
- // 158 while (!(wBlockAddress++==1023))
- // 159 {
- // 160 wPageAddress=wBlockAddress<<6;
- // 161 ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- // 162 ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
- // 163 for (ucGeneralCnt=0;ucGeneralCnt<2;ucGeneralCnt++,wPageAddress++)
- // 164 {
- // 165 //COMMAND
- // 166 COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
- // 167 COMMAND_LATCH_INTO();
- // 168 //ADDRESS
- // 169 ADDRESS_VALUE=COLUMN_ADDRESS_LOW;
- // 170 ADDRESS_LATCH_INTO();
- // 171
- // 172 ADDRESS_VALUE=COLUMN_ADDRESS_HIGH;
- // 173 ADDRESS_LATCH_INTO();
- // 174
- // 175 ADDRESS_VALUE=wPageAddress & 0xff; //ROW_ADDRESS_LOW; a bug of Dec. 07,2006
- // 176 ADDRESS_LATCH_INTO();
- // 177
- // 178 ADDRESS_VALUE=(wPageAddress>>8) & 0xff;
- // 179 ADDRESS_LATCH_INTO();
- // 180 FLASH_CON_PORT_OUT &=~ ALE;
- // 181
- // 182 COMMAND_VAL=0X30;
- // 183 COMMAND_LATCH_INTO();
- // 184 //ATcmdDelay();
- // 185 while((FLASH_CON_PORT_IN & RB)==0);
- // 186 DATA_PORT_IN_INITIAL;
- // 187 FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
- // 188 ucFlashReadData=DATA_PORT_IN;
- // 189 FLASH_CON_PORT_OUT |= RE;
- // 190 if (0xff != ucFlashReadData)
- // 191 {
- // 192 if (ucBadBlockCnt++<128)
- // 193 {
- // 194 aucUartRxBuf[ucRxIndex++]=wBlockAddress & 0xff; //low 8 byte
- // 195 aucUartRxBuf[ucRxIndex++]=(wBlockAddress>>8) & 0xff; //high 8 byte
- // 196 }//if
- // 197 else
- // 198 {
- // 199 COLUMN_ADDRESS_LOW=0X00;
- // 200 COLUMN_ADDRESS_HIGH=0X00;
- // 201 ROW_ADDRESS_LOW=ucRxBufFullCnt;
- // 202 ROW_ADDRESS_HIGH=0X00;
- // 203 PROGRAM_256_BYTE();
- // 204 ucRxBufFullCnt++;
- // 205 }//else
- // 206 break; //first page or second page
- // 207 }//if
- // 208 //else
- // 209 //ROW_ADDRESS_LOW++; //next page-->2nd page in the block //a bug of Dec. 07,2006
- // 210 }//for
- // 211 }//while
- // 212
- // 213 if (ucBadBlockCnt!=0)
- // 214 {
- // 215 COLUMN_ADDRESS_LOW=0X00;
- // 216 COLUMN_ADDRESS_HIGH=0X00;
- // 217 ROW_ADDRESS_LOW=ucRxBufFullCnt;//first block
- // 218 ROW_ADDRESS_HIGH=0X00;
- // 219 PROGRAM_256_BYTE();
- // 220
- // 221 ucRxBufFullCnt++;
- // 222 }
- // 223
- // 224 FlashFormat();
- // 225
- // 226 }
- // 227 */
- // 228
- RSEG CODE:CODE:NOROOT(1)
- // 229 unsigned int CalNextPageAddress(unsigned int wCurrentPageAddress)
- CalNextPageAddress:
- CFI Block cfiBlock1 Using cfiCommon0
- CFI Function CalNextPageAddress
- // 230 {
- FUNCALL CalNextPageAddress, READ_256_BYTE
- LOCFRAME CSTACK, 14, STACK
- PUSH.W R10
- CFI R10 Frame(CFA, -4)
- CFI CFA SP+4
- PUSH.W R11
- CFI R11 Frame(CFA, -6)
- CFI CFA SP+6
- PUSH.W R8
- CFI R8 Frame(CFA, -8)
- CFI CFA SP+8
- PUSH.W R9
- CFI R9 Frame(CFA, -10)
- CFI CFA SP+10
- PUSH.W R6
- CFI R6 Frame(CFA, -12)
- CFI CFA SP+12
- PUSH.W R7
- CFI R7 Frame(CFA, -14)
- CFI CFA SP+14
- MOV.W R12, R9
- // 231 unsigned char ucGeneralCnt=0,ucRxIndex=0,ucBadBlockCnt=0;
- MOV.B #0x0, R7
- MOV.B #0x0, R10
- MOV.B #0x0, R6
- // 232 unsigned int wBlockAddress=0,wNextPageAddress=0;
- MOV.W #0x0, R11
- MOV.W #0x0, R8
- // 233
- // 234 wNextPageAddress=wCurrentPageAddress;
- MOV.W R9, R8
- // 235 wBlockAddress=wCurrentPageAddress>>6;
- MOV.W R9, R12
- CALL #?ShiftRight16u_6
- MOV.W R12, R11
- // 236 if (wCurrentPageAddress%64==0)
- MOV.W R9, R12
- MOV.W #0x40, R14
- CALL #?DivMod16u
- CMP.W #0x0, R14
- JNE ??CalNextPageAddress_2
- // 237 {
- // 238 for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,ROW_ADDRESS_LOW++)
- MOV.B #0x0, R7
- ??CalNextPageAddress_1:
- CMP.B #0x40, R7
- JC ??CalNextPageAddress_2
- // 239 {
- // 240 READ_256_BYTE();
- CALL #READ_256_BYTE
- // 241 for (ucRxIndex=0,ucBadBlockCnt=0;ucBadBlockCnt<128;ucBadBlockCnt++)
- MOV.B #0x0, R10
- MOV.B #0x0, R6
- ??CalNextPageAddress_0:
- CMP.B #0x80, R6
- JC ??CalNextPageAddress_3
- // 242 {
- // 243 if (aucUartRxBuf[ucRxIndex]==(wBlockAddress & 0xff)
- // 244 && aucUartRxBuf[ucRxIndex+1]==((wBlockAddress>>8) & 0xff))
- MOV.B R10, R14
- AND.W #0xff, R14
- MOV.B R11, R15
- AND.B #0xff, R15
- CMP.B R15, aucUartRxBuf(R14)
- JNE ??CalNextPageAddress_4
- MOV.W #aucUartRxBuf, R15
- MOV.B R10, R14
- AND.W #0xff, R14
- ADD.W R14, R15
- MOV.W R11, R14
- SWPB R14
- AND.W #0xff, R14
- CMP.B R14, 0x1(R15)
- JNE ??CalNextPageAddress_4
- // 245 {wNextPageAddress=wCurrentPageAddress+64; break;}
- MOV.W #0x40, R14
- ADD.W R9, R14
- MOV.W R14, R8
- JMP ??CalNextPageAddress_3
- // 246 if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF &&
- // 247 aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
- ??CalNextPageAddress_4:
- MOV.B R10, R14
- AND.W #0xff, R14
- CMP.B #0xff, aucUartRxBuf(R14)
- JNE ??CalNextPageAddress_5
- MOV.W #aucUartRxBuf, R14
- MOV.B R10, R15
- AND.W #0xff, R15
- ADD.W R15, R14
- CMP.B #0xff, 0x1(R14)
- JNE ??CalNextPageAddress_5
- MOV.W #aucUartRxBuf, R14
- MOV.B R10, R15
- AND.W #0xff, R15
- ADD.W R15, R14
- CMP.B #0xff, 0x2(R14)
- JNE ??CalNextPageAddress_5
- MOV.W #aucUartRxBuf, R14
- MOV.B R10, R15
- AND.W #0xff, R15
- ADD.W R15, R14
- CMP.B #0xff, 0x3(R14)
- JEQ ??CalNextPageAddress_3
- // 248 {break;}
- // 249 ucRxIndex+=2;
- ??CalNextPageAddress_5:
- ADD.B #0x2, R10
- // 250 }//for
- ADD.B #0x1, R6
- JMP ??CalNextPageAddress_0
- // 251 if (aucUartRxBuf[ucRxIndex++]==(wBlockAddress & 0xff)
- // 252 && aucUartRxBuf[ucRxIndex++]==((wBlockAddress>>8) & 0xff))
- ??CalNextPageAddress_3:
- MOV.B R10, R14
- MOV.B #0x1, R10
- ADD.B R14, R10
- AND.W #0xff, R14
- MOV.B R11, R15
- AND.B #0xff, R15
- CMP.B R15, aucUartRxBuf(R14)
- JNE ??CalNextPageAddress_6
- MOV.B R10, R15
- MOV.B #0x1, R10
- ADD.B R15, R10
- AND.W #0xff, R15
- MOV.W R11, R14
- SWPB R14
- AND.W #0xff, R14
- CMP.B R14, aucUartRxBuf(R15)
- JNE ??CalNextPageAddress_6
- // 253 {wNextPageAddress=wCurrentPageAddress+64; break;}
- MOV.W #0x40, R14
- ADD.W R9, R14
- MOV.W R14, R8
- JMP ??CalNextPageAddress_2
- // 254 if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF &&
- // 255 aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
- ??CalNextPageAddress_6:
- MOV.B R10, R14
- AND.W #0xff, R14
- CMP.B #0xff, aucUartRxBuf(R14)
- JNE ??CalNextPageAddress_7
- MOV.W #aucUartRxBuf, R14
- MOV.B R10, R15
- AND.W #0xff, R15
- ADD.W R15, R14
- CMP.B #0xff, 0x1(R14)
- JNE ??CalNextPageAddress_7
- MOV.W #aucUartRxBuf, R14
- MOV.B R10, R15
- AND.W #0xff, R15
- ADD.W R15, R14
- CMP.B #0xff, 0x2(R14)
- JNE ??CalNextPageAddress_7
- MOV.W #aucUartRxBuf, R14
- AND.W #0xff, R10
- ADD.W R10, R14
- CMP.B #0xff, 0x3(R14)
- JEQ ??CalNextPageAddress_2
- // 256 {break;}
- // 257 }//for
- ??CalNextPageAddress_7:
- ADD.B #0x1, R7
- ADD.B #0x1, &ROW_ADDRESS_LOW
- JMP ??CalNextPageAddress_1
- // 258 }//if
- // 259 return wNextPageAddress;
- ??CalNextPageAddress_2:
- MOV.W R8, R12
- BR #?Epilogue6
- CFI EndBlock cfiBlock1
- // 260 }
- // 261 /*******************
- // 262 unsigned int CalNextBlockAddress(unsigned int wCurrentBlockAddress)
- // 263 {
- // 264 unsigned char ucGeneralCnt=0,ucRxIndex=0,ucBadBlockCnt=0;
- // 265 unsigned int wBlockAddress=0,wNextBlockAddress=0;
- // 266
- // 267 wNextBlockAddress=wCurrentBlockAddress;
- // 268 for (ucGeneralCnt=0;ucGeneralCnt<64;ucGeneralCnt++,ROW_ADDRESS_LOW++)
- // 269 {
- // 270
- // 271 READ_256_BYTE();
- // 272 for (ucRxIndex=0,ucBadBlockCnt=0;ucBadBlockCnt<128;ucBadBlockCnt++)
- // 273 {
- // 274 if (aucUartRxBuf[ucRxIndex++]==(wBlockAddress & 0xff)
- // 275 && aucUartRxBuf[ucRxIndex++]==((wBlockAddress>>8) & 0xff))
- // 276 {wNextBlockAddress=wCurrentBlockAddress+1; break;}
- // 277 if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF &&
- // 278 aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
- // 279 {break;}
- // 280 }//for
- // 281 if (aucUartRxBuf[ucRxIndex]==0xFF && aucUartRxBuf[ucRxIndex+1]==0xFF &&
- // 282 aucUartRxBuf[ucRxIndex+2]==0xFF &&aucUartRxBuf[ucRxIndex+3]==0xFF)
- // 283 {break;}
- // 284 }//for
- // 285 return wNextBlockAddress;
- // 286 }
- // 287 *******************************/
- RSEG CODE:CODE:NOROOT(1)
- // 288 void FlashFormat(void)
- FlashFormat:
- CFI Block cfiBlock2 Using cfiCommon0
- CFI Function FlashFormat
- // 289 {
- FUNCALL FlashFormat, ERASE_ONE_BLOCK
- LOCFRAME CSTACK, 6, STACK
- PUSH.W R10
- CFI R10 Frame(CFA, -4)
- CFI CFA SP+4
- PUSH.W R11
- CFI R11 Frame(CFA, -6)
- CFI CFA SP+6
- // 290 unsigned int wBlockAddress=0,wPageAddress=0;
- MOV.W #0x0, R10
- MOV.W #0x0, R11
- // 291 for (wBlockAddress=1;wBlockAddress<1024;wBlockAddress++)
- MOV.W #0x1, R10
- ??FlashFormat_0:
- CMP.W #0x400, R10
- JC ??FlashFormat_1
- // 292 {
- // 293 wPageAddress=wBlockAddress<<6;
- MOV.W R10, R12
- CALL #?ShiftLeft16_6
- MOV.W R12, R11
- // 294 ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- MOV.B R11, &ROW_ADDRESS_LOW
- // 295 ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
- MOV.W R11, R14
- SWPB R14
- AND.W #0xff, R14
- MOV.B R14, &ROW_ADDRESS_HIGH
- // 296 ERASE_ONE_BLOCK();
- CALL #ERASE_ONE_BLOCK
- // 297 }
- ADD.W #0x1, R10
- JMP ??FlashFormat_0
- // 298 }
- ??FlashFormat_1:
- POP.W R11
- CFI R11 SameValue
- CFI CFA SP+4
- POP.W R10
- CFI R10 SameValue
- CFI CFA SP+2
- RET
- CFI EndBlock cfiBlock2
- RSEG CODE:CODE:NOROOT(1)
- ?setjmp_save_r4:
- REQUIRE ?setjmp_r4
- REQUIRE ?longjmp_r4
- RSEG CODE:CODE:NOROOT(1)
- ?setjmp_save_r5:
- REQUIRE ?setjmp_r5
- REQUIRE ?longjmp_r5
- END
- //
- // 906 bytes in segment CODE
- // 4 bytes in segment DATA16_AN
- //
- // 906 bytes of CODE memory
- // 0 bytes of DATA memory (+ 4 bytes shared)
- //
- //Errors: none
- //Warnings: none