⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc33booter.asm

📁 TMS320VC33的应用程序 、TMS320VC33的应用程序
💻 ASM
字号:
********************************************************************************
* AD.ASM	v1.00					                           			       *
* 版权(c)	2000-   	北京合众达电子技术有限责任公司		                   *
* 设计者:	 刘宁							                                   *
********************************************************************************
                         .copy "VC33.inc" 
                         .copy "bootloader.inc" 
	                     
******************************************************************************
*                        Bootloader function                                 *
*     it's function is that loading the user code from the Flash to sram     *
*     the boot loader have  four steps :                                     *
*     the first step is that configing the memory width;                     *
*     the second step is that configing the rigester of strb;                *
*     the third step has three factors.                                      *
*          the first is the destination address for the first bock code;     *
*          the second is the long size of the first bock;                    *
*          the third is the code of the first bock code;                     *
*     if you have the second bock code ,you can do with is as the third step *
*     a zero is write to the end of the table of the bootloader.this can tell*
*     the cpu that the bootloader is over ,you can start to run the code from*
*     the first code of the first block.                                     *
******************************************************************************
bootmemw        .set   020h
bootstrb        .set   01E8H
STACK_SIZE	    .set   80H
Flash_5555		.set	5555H
Flash_2AAA		.set	2AAAH

Flash_sa0		.set	0000H
Flash_sa1		.set	0001H
*...
Flash_sa127		.set	007FH
Flash_ba0		.set	0000H
Flash_ba1		.set	0001H
Flash_ba2		.set	0002H
Flash_ba3		.set	0003H
Flash_ba4		.set	0004H
Flash_ba5		.set	0005H
Flash_ba6		.set	0006H
Flash_ba7		.set	0007H 
;mmr             .set    800000h
     
                        
                .data
flashbase       .word   01000h   ;the bootloader table base address
vc33bmr         .word   C3x_MMR
chiperase       .word   05555h
chipecom        .word   00100010h
vectoradd       .word   00809fc0h
chipalong       .word   0003ffffh 
mmr             .word   800000h   
bootmmr         .word   410000h
bcint00         .word   _c_int00
;bdaend          .word   da_end
;bdata           .word   SYSINIT 
stack_addr      .word   stack        ;address of stack
Flash_base	    .word	00000000H
Flash_poll	    .word	00800080H
Flash_blank	    .word	0FFFFFFFFH
Flash_AA	    .word	00AA00AAH
Flash_55	    .word	00550055H
Flash_PROG	    .word	00A000A0H
Flash_ERASE	    .word	00800080H
Flash_SE	    .word	00300030H
Flash_BE	    .word	00500050H
Flash_CE	    .word	00100010H
Flash_SSIZE	    .word	00000800H-1
Flash_BSIZE	    .word	00008000H-1
Flash_CSIZE	    .word	00040000H-1

stack      .usect  ".fstack",STACK_SIZE 

                .sect  ".vc33booter"                         

bootmain:    LDP flashbase
             LDI     @stack_addr,SP    ;load the address into SP
             AND 0,IE
             XOR IF,IF
             PUSH  R0
             PUSHF R0
             PUSH  AR0 
             LDI @vc33bmr,AR0
             LDI (INT_RDY+WAIT_7+BANK_8M),R0
             STI R0,*+AR0(PBCR) ;为系统加入7个等待
             PUSH AR0
             PUSHF R0
             PUSH R0
             
*flash erase
             LDI @chiperase,AR2  ;chip erase command
             LDI @chipecom,R2     ;all chip is erased
             LDI @chipalong,R3   ;the flash's longth
             CALL flasheasm      ;erase the chip
             ADDI 0,R0
             BZ  bootstart  
             b   $
                           
*this is the first step of the boot:
*configing the memory width
bootstart:   LDI bootmemw,R2
             LDI @flashbase,AR2 ;the address is 0x1000h
             CALL flashwasm     ;write to the first word of the bootloader table 
             

*this is the second step of boot:
*write the strb register to the second address of the flash
             LDI bootstrb,R2    ;strb rigister 
             CALL flashwasm     ;write to the second word of the bootloader table                          

*this is the third step of the boot: 

*1.write the size of the _c_int00 block  
             LDI 1dh,R2
             CALL flashwasm     ;write the size of the _c_int00 block

*1.write the destination address of the _c_int00
             LDI @bootmmr,R2
             ADDI 1f7H ,R2
             CALL flashwasm     ;write the destination of the _c_int00 block                        

*1.write the code of the _c_int00 block to flash
             LDI @mmr,R2
             ADDI 1F7H ,R2 ;the source address(code)
             LDI 1ch,R3 
             CALL flashawm       ;writ the code 
             
*2.write the size  of the .vector block         
             LDI 0Bh,R2   		;_main block longth            
             CALL flashwasm     ;write the size of the _c_int00 block

*2.write the destination address of the .vector
             LDI @vectoradd,R2
             CALL flashwasm     ;write the destination of the _c_int00 block                        

*2.write the code of the .vector block to flash
			 LDI @vectoradd,R2  ;the source address(code)     
             LDI 0ah,R3         ;.vector block longth
             CALL flashawm      ;writ the code
             
*3.write the size  of the .data block         
           	               ;.data block longth 
             LDI 16h,R2        
             CALL flashwasm     ;write the size of the .data block

*3.write the destination address of the .data
             LDI @bootmmr,R2
             ADDI 23aH ,R2
             CALL flashwasm     ;write the destination of the .data block                        

*3.write the code of the .data block to flash
			 LDI @bootmmr,R2
             ADDI 23aH ,R2 ;the source address(code)     
             LDI 15H,R3  ;.data block longth     
             CALL flashawm  ;writ the code   
*4.write the size of .cinit block
             LDI 26h,R2        
             CALL flashwasm  
*4.write the destination address of the .cinit block
             LDI @mmr,R2
             ADDI 400H ,R2
             CALL flashwasm  
*4.write the code of the .cinit block
             LDI @mmr,R2
             ADDI 400H ,R2             
             LDI 25H,R3
             CALL flashawm  
*5.write the size of .text block
             LDI 23Ah,R2        
             CALL flashwasm  
*5.write the destination of the .text block
             LDI @bootmmr,R2
             ADDI 00H ,R2
             CALL flashwasm
*5.write the code of the .text block
             LDI @bootmmr,R2
             ADDI 00H ,R2             
             LDI 239H,R3
             CALL flashawm    
*the fourth step of boot is 
*write the zero to the end of the bootloader
             LDI 0,R2
             CALL flashwasm ;write the end of the code               
bootmain_end:
             B $
*the codes under this line are call by asm laungue.           		 
*********************************************************************************
*																				*
* 函数定义:flasheasm						   									*
* 功  能:Flash扇区/块/整片擦除操作,并校验是否擦除干净						*
*																				*                              	
* 入口参数:AR2	  ---- 地址addr													*
*		       扇区擦除:	扇区号(每个扇区2K,扇区号Amsb~A11)				*
*		       块擦除:	块号(每个块32K,块号Amsb~A15)						*
*		       整片擦除:	5555H												*
*		       Amsb:	A16,Flash用SST39VF200时								*
*		       		A17,Flash用SST39VF400时(缺省)							*
*		      		A18,Flash用SST39VF800时									*
*		       Flash定位在存储空间000000H~01FFFFH/03FFFFH(缺省)/07FFFFH		*
*		       地址addr为从0开始的偏移地址,而非Flash的绝对地址					*
*      R2	  ---- 操作类型type												*
*		       扇区擦除:30H													*
*		       块擦除:  50H													*
*		       整片擦除:10H													*
*      R3	  ---- 长度length												*
*		       扇区/块/整片的长度												*
* 出口参数:R0	  ---- 擦除标志													*
*		       未擦干净:01H													*
*		       已擦干净:00H													*
* 资源使用:AR1,AR2,R2														*
*																				*
*********************************************************************************
           		 
flasheasm:      PUSH	AR1
		        PUSH	AR0
		        PUSH	R1
		        PUSHF	R1
easm_process:	LDI	@Flash_base,AR1
		        LDI	@Flash_base,AR0
		        ADDI	Flash_5555,AR1		; AR1 = 005555H
				ADDI	Flash_2AAA,AR0		; AR2 = 002AAAH
		
				LDI	@Flash_AA,R1
				STI	R1,*AR1			; 00AA00AAH -> (005555H)
				LDI	@Flash_55,R1
				STI	R1,*AR0			; 00550055H -> (002AAAH)
				LDI	@Flash_ERASE,R1
				STI	R1,*AR1			; 00800080H -> (005555H)
				LDI	@Flash_AA,R1
				STI	R1,*AR1			; 00AA00AAH -> (005555H)
				LDI	@Flash_55,R1
				STI	R1,*AR0			; 00550055H -> (002AAAH)
				STI	R2,*AR2			; type -> (addr)
			
easm_poll:		LDI	*AR0,R1
				NOP
				NOP
				XOR	@Flash_blank,R1
				AND	@Flash_poll,R1
				BNZ	easm_poll		; 查询擦除是否完成?
		
				CMPI	@Flash_CE,R0		; 操作类型为整片擦除?
				LDIEQ	@Flash_base,AR0		; 整片擦除时:Flash的基地址装入AR0
				LDI	R3,AR1
            	LDI 01000h,AR0
easm_verify:    LDI	*AR0++,R1
				CMPI	@Flash_blank,R1
				DBEQ	AR1,easm_verify
				LDI	0,R0			    ; 置擦除干净标志
				LDI *-AR0(5),R1
				CMPI	@Flash_blank,R1
				LDINE	1,R0			; 置未擦除干净标志

easm_end:		POPF R1
		    	POP	R1
		    	POP	AR0
		    	POP	AR1
   				RETS
		    
*********************************************************************************
*										*
* 函数定义:flash_writes						   		*
* 功  能:将数据data写入addr所指定的Flash单元,并校验写是否正确			*
*										*
* 入口参数:AR2	  ---- 地址addr,Amsb~A0					*
*		       Amsb:	A16,Flash用SST39VF200时				*
*		       		A17,Flash用SST39VF400时(缺省)			*
*		      		A18,Flash用SST39VF800时				*
*		       Flash定位在存储空间000000H~01FFFFH/03FFFFH(缺省)/07FFFFFH	*
*		       地址addr为从0开始的偏移地址,而非Flash的绝对地址		*
*      R2	  ---- 数据data							*
* 出口参数:R0	  ---- 写入标志							*
*		       未写入:01H						*
*		       已写入:00H						*
*      AR0	  ---- AR0++							*
* 资源使用:AR1,AR2,R2								*
*										*
*********************************************************************************                    
flashwasm:		PUSH	AR1
				PUSH	AR0
				PUSH	R1
				PUSHF	R1
wasm_process:	LDI	@Flash_base,AR1
				LDI	@Flash_base,AR0
				ADDI	Flash_5555,AR1		; AR1 = 005555H
				ADDI	Flash_2AAA,AR0		; AR0 = 002AAAH

				LDI	@Flash_AA,R1
				STI	R1,*AR1			; 00AA00AAH -> (005555H)
				LDI	@Flash_55,R1
				STI	R1,*AR0			; 00550055H -> (002AAAH)
				LDI	@Flash_PROG,R1
				STI	R1,*AR1			; 00A000A0H -> (005555H)
				LDI R2,R0
				NOP
				NOP
				STI	R2,*AR2			; data -> (addr)
		        NOP
wasm_poll:		LDI	*AR2,R1
				NOP
				NOP
				XOR	R0,R1
				AND	@Flash_poll,R1
				BNZ	wasm_poll		; 查询写操作是否完成?
		
				XOR	*AR2++,R0		; data = (addr)?
				LDINZ	1,R0			; data ≠ (addr),则置R0=1 
    			
wasm_end:        POPF R1
		   		 POP	R1
		    	 POP	AR0
		   		 POP	AR1 
		   		 RETS
		   		 
*********************************************************************************
*										                                        *
* 函数定义:flashasm						                        		*
* 功  能:将AR1所指向的数据缓冲区中,长度为AR2个的数据写入AR0所指向的Flash单元*
*									                                        	*
* 入口参数:AR2	  ---- 地址addr,Amsb~A0				                    	*
*		       Amsb:	A16,Flash用SST39VF200时			                	*
*		       		A17,Flash用SST39VF400时(缺省)		                	*
*		      		A18,Flash用SST39VF800时			                    	*
*		       Flash定位在存储空间000000H~01FFFFH/03FFFFH(缺省)/07FFFFFH   	*
*		       地址addr为从0开始的偏移地址,而非Flash的绝对地址		            *
*      R2	  ---- 数据缓冲区起始地址ptr					                *
*      R3	  ---- 数据长度lrngth					                        *
* 出口参数:R0	  ---- 写入标志						                           	*
*		       未写入:01H						                                *
*		       已写入:00H					                                 	*
* 资源使用:								                                 	*
*										                                        *
*******************************************************************************
                     
flashawm:       LDI  R2,AR1
                LDI  R3,AR0
flash_wasm1:    LDI  *AR1++,R0
                PUSH	AR1
		        PUSH	AR0
		        PUSH	R1
		        PUSHF	R1
wasm_processm:	LDI	@Flash_base,AR1
				LDI	@Flash_base,AR0
				ADDI	Flash_5555,AR1		; AR1 = 005555H
				ADDI	Flash_2AAA,AR0		; AR0 = 002AAAH

				LDI	@Flash_AA,R1
				STI	R1,*AR1			; 00AA00AAH -> (005555H)
				LDI	@Flash_55,R1
				STI	R1,*AR0			; 00550055H -> (002AAAH)
				LDI	@Flash_PROG,R1
				STI	R1,*AR1			; 00A000A0H -> (005555H)
				STI	R0,*AR2	    	; data -> (addr)
				NOP
				NOP 
				NOP
		
wasm_pollm:	    LDI	*AR2,R1
				NOP
				NOP
				NOP
				XOR	R0,R1
				AND	@Flash_poll,R1
				BNZ	wasm_pollm		; 查询写操作是否完成?
		
				LDI	*AR2++,R1		; data = (addr)?
				XOR R1,R0
				LDINZ	1,R0			; data ≠ (addr),则置R0=1 
wasm_endm:  	POPF R1
		   		POP	R1
		   		POP	AR0
		    	POP	AR1
		    	CMPI 0,R0 
                DBEQ AR0,flash_wasm1	    
           		RETS              
             .end                           
               

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -