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

📄 mbm29dl640e_flash.s

📁 FreeScale DragonBall SZ LCD driver samples code
💻 S
字号:
;***************************************************************
; File Name: 	MBM29DL640E_FLASH.S
; Descriptions: Flash Program for MBM29DL640E
; Updated by: 	Shark Wu
; Date: 		10/25/2001
;***************************************************************

;
; Code to copy data from memory into Fujitsu MBM29DL640E flash.
; It assumes 1 flash chip in word mode.
; This code assumes a top-boot device.  It also assumes
; that the starting flash address is at the beginning
; of a sector.
;

FLASH_BASE		.equ		$04000000


	.section .flashinit
	.extern ___FBUF_START
	.extern ___FBUF_END
	.extern ___FLASH_START
	.global	copy_to_flash
copy_to_flash:

	;
	; Set up registers:
	;	a0 - flash image source start addr (in RAM)
	;	a1 - flash image source end addr (in RAM)
	; 	a2 - flash image dest addr (in FLASH)
	;

	move.l		#___FBUF_START,a0		; source addr of flash image
	move.l		#___FBUF_END,a1			; end addr of source flash image
	move.l		#___FLASH_START,a2		; dest addr of flash image
	
	move.l		#$555*2,d1				; load command offset 1 to d1
	move.l		#$2aa*2,d2				; load command offset 2 to d2


	;
	; Erase the next sector.  Each sector must be erased before it
	; can be programmed.
	;
	
erase_loop:
	cmp.l		a0,a1					; if done copying, verify
	ble			do_compare
	
	move.l		a2,d0
	and.l		#$ff800000,d0			; calc. base addr of current chip
	move.l		d0,a3
	
	move.w		#$aa,(d1.l,a3)			; unlock step 1
	move.w		#$55,(d2.l,a3)			; unlock step 2
	move.w		#$80,(d1.l,a3)			; sector erase setup
	move.w		#$aa,(d1.l,a3)			; unlock step 1
	move.w		#$55,(d2.l,a3)			; unlock step 2
	move.w		#$30,(a2)				; erase current sector
erase_verify_loop:
	move.w		(a2),d0					; check sector data
	cmp.w		#$ffff,d0				; erased?
	bne.s		erase_verify_loop		; if not, keep checking


do_program:
	; Get the sector size, which depends on the sector offset.
	; This code assumes a top-boot device.  It also assumes
	; that the starting flash address is at the beginning
	; of a sector.

	move.l		a2,d0
	sub.l		a3,d0					; get offset of sector
	cmp.l	#$00010000,d0	  			; is it sa8 or higher?
	bge.s	check_sa134					; if so, do more tests
	bra	size_8k							; otherwise, size is 8K	
	
check_sa134
	cmp.l	#$007f0000,d0     			; is it sa134 or higher?
	bge.s	size_8k						; if so, size is 8K	
	bra	size_64k						; otherwise, size is 64K		

size_8k
	move.l	#$00002000,d0	  			; otherwise, size is 8K
	bra	program_loop

size_64k
	move.l	#$00010000,d0	  			; otherwise, size is 64K
	bra	program_loop
	
program_loop:
	
	move.w		#$aa,(d1.l,a3)			; unlock step 1
	move.w		#$55,(d2.l,a3)			; unlock step 2
	move.w		#$a0,(d1.l,a3)			; program command
	
	move.w		(a0),d3
	move.w		d3,(a2)					; write data to flash
program_verify_loop:
	cmp.w		(a2),d3					; data written?
	bne.s		program_verify_loop		; if not, wait

	add.l		#2,a0					; next word
	add.l		#2,a2					; next word

	cmp.l		a0,a1					; done copying?
	ble.s		do_compare				; if so, verify

	sub.l		#2,d0					; next word
	beq			erase_loop				; if end of sector, erase next
	bra.s		program_loop			; otherwise, copy next word
	

	; Verify that the flash contents were written correctly.
do_compare:
	move.l		#___FBUF_START,a0		; source addr of flash image
	move.l		#___FBUF_END,a1			; end addr of source flash image
	move.l		#___FLASH_START,a2		; dest addr of flash image

compare_loop:
	cmp.w		(a0)+,(a2)+
	bne			prog_fail
	
	cmp.l		a0,a1					; is entire image verified?
	bgt			compare_loop			; if not, repeat
	
	trap		#0						; done
	nop

prog_fail:
	trap		#1						; failed
	nop
	

⌨️ 快捷键说明

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