📄 240.asm
字号:
.include "svar20.h" ;Variable declarations
.ref GCLR ;References clear algo.
.ref GPGMJ ;References program algo.
.ref GERS ;References erase algo.
.ref FLWS ;References flash–write algo.
;**Parameters used by flash algorithms.
.def _c_int0
.def PRG_bufaddr, PRG_paddr
.def PRG_length, PARMS
.def SEG_ST,SEG_END,PROTECT
;**F240 Register definitions
RTICR .set 07027h ;RTI Control Register
WDCR .set 07029h ;WD Control Register
CKCR0 .set 0702Bh ;Clock Control Register 0
CKCR1 .set 0702Dh ;Clock Control Register 1
SYSSR .set 0701Ah ;System Module Status Register
DP_PF1 .set 224 ;page 1 of peripheral file
;(7000h/80h)
*************************************************************
VARS: .usect "PRG_data",16 ;This is an uninitialized data *
;section required by the standard *
;flash algos for temporary *
;variables. Pointers to this *
;space are hardcoded in SVAR20.H, *
;and variables are init’d at *
;run time. *
*************************************************************
PARMS: .usect "PRG_parm",10 ;This is an uninitialized data *
;section that is used for *
;temporary variables and for *
;passing parameters to the flash *
;algorithms. *
*************************************************************
PROTECT .set PARMS ;Segment enable bits. *
**************************************************************
***** Parameters needed for Programming algorithm. ***
*************************************************************
PRG_bufaddr .set PARMS+1 ;Addr of buffer for pgm data. *
PRG_paddr .set PARMS+2 ;1st flash addr to program. *
PRG_length .set PARMS+3 ;Length of block to program. *
*************************************************************
*** Parameters needed for CLEAR, ERASE, and FLW algorithms. **
*************************************************************
SEG_ST .set PARMS+4 ;Segment start address. *
SEG_END .set PARMS+5 ;Segment end address. *
*************************************************************
**** Other misc variables. ****
*************************************************************
ERS_COUNT .set PARMS+6 ;Used for erase fail count. *
*************************************************************
.text
*************************************************************
** First, initialize the key F240 registers for use with *
** the EVM. *
*************************************************************
_c_int0
;Set Data Page pointer to page 1 of the
;peripheral frame
LDP #DP_PF1 ;Page DP_PF1 includes WET through *
;EINT frames
;initialize WDT registers
SPLK #06Fh, WDCR ;clear WDFLAG, Disable WDT
;(if Vpp=5V), set WDT
;for 1 second overflow (max)
SPLK #07h, RTICR ;clear RTI Flag,
;set RTI for 1 second overflow
;(max)
;EVM 10–MHz oscillator settings.
;(XTAL2 open, OSCBYP_=GND)
SPLK #00B1h,CKCR1 ;CLKIN(OSC)=10MHz,
;Mult by 2, Div by 1.
SPLK #00C3h,CKCR0 ;CLKMD=PLL Enable,SYSCLK=CPUCLK/2
;Clear reset flag bits in SYSSR
;(PORRST, PLLRST, ILLRST, SWRST, WDRST)
LACL SYSSR ;ACCL <= SYSSR
AND #00FFh ;Clear upper 8 bits of SYSSR
SACL SYSSR ;Load new value into SYSSR
**********************************************************
** First, erase flash1 by invoking the clear and erase **
** algorithms. **
** Note: Three parameters must be initialized before **
** calling the algorithms. **
**********************************************************
LDP #PARMS
SPLK #0,ERS_COUNT ;Set erase fail count to 0.
**********Put parameters where they belong.**********
SPLK #0ff00h,PROTECT
SPLK #00000h,SEG_ST
SPLK #03FFFh,SEG_END
***********First, clear flash ************
ers_loop:
CALL GCLR ;Clear flash.
LACL ERROR ;Check for CLEAR/ERASE error
clrerr:
BCND ers_error,neq ;If error, then hard fail.
***********Next erase flash ************
CALL GERS ;Erase flash.
LACL ERROR ;Check for CLEAR/ERASE error
BCND depletion,neq ;If error, then try Flash–write.
B ers_done ;Else, no errors erasing.
depletion:
LACL ERS_COUNT ;Get erase fail count.
ADD #1 ;Increment fail count.
SACL ERS_COUNT ;Save new count.
SUB #10 ;CHECK for max of 10.
BCND ers_error,GT ;If ers_cout>10 then hard fail.
CALL FLWS ;Else, try to recover from
;depletion.
LACL ERROR ;Check for FLASH–WRITE error.
BCND ers_error,neq ;If couldn’t recover, then hard
;fail.
B ers_loop ;Else, Try erase again.
ers_error:
**************************************************************
** If here, then an unrecoverable error occurred during **
** erase. **
** In an actual application, the system takes some action **
** to indicate that service is required. **
**************************************************************
B ers_error ;Error while erasing.
ers_done:
**********************************************************
** If here, then flash is erased and ready to be **
** reprogrammed. **
** This is a good place in the example to set a **
** breakpoint so that erasure can be verified (i.e., **
** all flash bits should be 1). **
**********************************************************
**************************************************************
** At this point, an actual application fills a buffer with **
** the data to be programmed. To simulate this in the **
** example, three DARAM locations are initialized. **
**************************************************************
LAR AR1, #0380h ;Using last 128 words of B1 DARAM
;as buffer.
MAR *,AR1
SPLK #088AAh,*+ ;Use dummy data for buffer.
SPLK #05555h,*+
SPLK #088AAh,*
**************************************************************
** Now that the data to be programmed is ready, the **
** programming algorithm is invoked. Note: Four parameters **
** must be initialized before calling the algorithm. **
**************************************************************
LDP #PARMS
**********Put parameters where they belong.**********
splk #0ff00h,PROTECT
splk #0380h,PRG_bufaddr
splk #00000h,PRG_paddr
splk #3,PRG_length
***********Next, program flash************
CALL GPGMJ ;Program flash from buffer.
LACL ERROR ;Check for program error.
BCND prg_error,neq ;If error then clear ACC.
B prg_done ;Else, No errors programming.
prg_error:
**********************************************************
** If here, then an error occurred during programming. **
** In an actual application, the system takes some **
** action to indicate that service is required. **
**********************************************************
B prg_error ;Error while programming.
prg_done:
**********************************************************
** If here, then flash has been successfully programmed. *
**********************************************************
B prg_done ;Done programming.
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -