page 132,66 ;************************************************************************** ; FLASH.ASM - routine to make user code bootable from a flash eeprom ; ; 1 June 1996 : version 1.0 rlr/jp ; ; copyright (C) Motorola 1996 ; ; execute with: R0 pointing to first word of user code ; R1 containing size of the user's code in WORDS ;************************************************************************** nolist include 'ioequ.asm' list AAR0V EQU $000909 ; value programmed into AAR0 (SRAM Enable) ; (32k words ext. SRAM located at p:$001000-$007FFF) ; compare 9 most significant bits, look for a match with address ; X:0000 0000 0xxx xxx xxxx xxxx, no packing, no muxing, P enabled, ; X and Y disabled, AAR0 pin active low, asynchronous SRAM-type access AAR1V EQU $010811 ; value programmed into AAR1 (FLASH Enable) ; (64k bytes FLASH located at x:$010000-$01FFFF) ; compare 8 most significant bits, look for a match with address ; X:0000 0001 xxxx xxx xxxx xxxx, no packing, no muxing, X enabled, ; P and Y disabled, AAR1 pin active low, asynchronous SRAM-type access BCRV EQU $012581 ; value programmed into BCR ; (12 wait states for AAR1, 1 elsewhere) ;************************************************************************* org p:$0080 main movep #$040001,x:M_PCTL ; MF=2 (34 MHz) movep #AAR0V,x:M_AAR0 ; maps SRAM from p:$0000-$7fff movep #AAR1V,x:M_AAR1 ; set up flash space to be mapped from ; x:$10000 to x:$1ffff (size 65536 bytes) movep #BCRV,x:M_BCR ; 12 wait states in AAR1 domain, ; (360ns cycle time) ; 1 wait state elsewhere ;----- compute the number of sectors to write/read move #>42,x0 clr b r1,a _cmpsec inc b sub x0,a bgt _cmpsec move b0,p:NUM_SEC ;------------------------------------------------------------------------- ; Initialize the loader code with the size of the user's code and ; the address of the user's code. Then write the loader routine ; into the boot sector (the 1st 128-bytes) of the FLASH. ;----- move r0,p:CODE_START ; store the address of the user's code move r1,p:CODE_SIZE ; store the size of the user's code move #BOOT,r0 ; first DSP address to save move #$010000,r2 ; first address of FLASH bsr $71,x0 ; $71 ==> $AA at Flash move x0,x:$15555 ;Atmel needs $5555 move #>$8E,x0 ; $8E ==> $55 at Flash move x0,x:$12AAA ;Atmel needs $2AAA move #>$41,x0 ; $41 ==> $A0 at Flash move x0,x:$15555 ;Atmel needs $5555 ;--- writes are now enabled dor #42,move_code ;move 126 bytes move p:(r0)+,a ;get 3 byte word add a,b ;accumulate checksum move a1,x:(r2)+ ;move low byte to flash lsr #8,a move a1,x:(r2)+ ;move mid byte lsr #8,a move a1,x:(r2)+ ;move high byte move_code ;*** 127th and 128th bytes are 16-bit checksum move b1,x:(r2)+ ;move low byte of checksum to flash lsr #8,b ;get next 8 bits of checksum move b1,x:(r2)+ ;move mid byte of checksum to flash bsr