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

📄 svar20.asm

📁 TMS320F206的在线写FLASH的源程序
💻 ASM
字号:
BASE .set 300h ;Base address for variables
;can be changed to relocate
;variable space in RAM.
BASE_0 .set BASE+0 ;Scratch pad registers.
BASE_1 .set BASE+1 ;
BASE_2 .set BASE+2 ;
BASE_3 .set BASE+3 ;
BASE_4 .set BASE+4 ;
BASE_5 .set BASE+5 ;
BASE_6 .set BASE+6 ;
SPAD1 .set BASE+7 ;
SPAD2 .set BASE+8 ;
FL_ADRS .set BASE+10 ;Flash load address.
FL_DATA .set BASE+11 ;Flash load data.
ERROR .set BASE+15 ;Error flag register.
*Variables for ERASE and CLEAR
RPG_CNT .set BASE+12 ;Program pulse count.
FL_ST .set BASE+13 ;Flash start addr/Seg Cntrl Reg.
FL_END .set BASE+14 ;Flash end address.

*CONSTANTS
*
*********************************************************
*Conditional assembly variable for F24X vs F206. *
*If F24X = 1, then assemble for F24X; otherwise, *
*assemble for F206. *
*********************************************************
F24X .set 0 ;Assemble for F206
;F24X .set 1 ;Assemble for F24X
***********************************************
* Delay variables for CLEAR,ERASE and PROGRAM *
***********************************************
D5 .set 0 ;5 us delay
D10 .set 1 ;10 us delay
D100 .set 19 ;100 us delay
D5K .set 999 ;5 ms delay
D7K .set 1399 ;7 ms delay
*************************************************************
*DLOOP constant proportional to CLKOUT1 *
*Calculate DLOOP in decimal using the following equation: *
* DLOOP=FLOOR{(5us/tCLKOUT1)–6}; *
*Examples *
*a. @ 15 MHz, DLOOP= 69; *
*b. @ 9.8304 MHz, DLOOP= 43; *
*c. @ 16.384 MHz, DLOOP= 75; *
**************************************************************
;DLOOP .set 14 ;5–us delay loop @ 4.032 MIPs
;DLOOP .set 19 ;5–us delay loop @ 5 MIPs
;DLOOP .set 44 ;5–us delay loop @ 10 MIPs
;DLOOP .set 75 ;5–us delay loop @ 16.384 MIPs
;DLOOP .set 94 ;5–us delay loop @ 20 MIPs
*************************
* On–chip I/O registers *
*************************
F_ACCESS0 .set 0FFE0h ;F206 ACCESS CNTRL REGISTER 0.
F_ACCESS1 .set 0FFE1h ;F206 ACCESS CNTRL REGISTER 1.
PMST .set 0FFE4h ;Defines SARAM in PM/DM and MP/MC bit.
F24X_ACCS .set 0FF0Fh ;F240 ACCESS CNTRL REGISTER.
;–––––––––––––––––––––––––––––––––––––––––––
;Register Declarations for F240 Peripherals |
;–––––––––––––––––––––––––––––––––––––––––––
;Watch–Dog(WD)/Real Time Int(RTI)/Phase–Locked Loop (PLL)
;Registers
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RTI_CNTR .set 07021h ;RTI Counter reg
WD_CNTR .set 07023h ;WD Counter reg
WD_KEY .set 07025h ;WD Key reg
RTI_CNTL .set 07027h ;RTI Control reg
WD_CNTL .set 07029h ;WD Control reg
PLL_CNTL1 .set 0702Bh ;PLL control reg 1
PLL_CNTL2 .set 0702Dh ;PLL control reg 2 


**********************************************************
VARS: .usect "PRG_data",16    
PARMS: .usect "PRG_parm",10
PROTECT .set PARMS ;Segment enable bits. *
**********************************************************
***Parameters needed for Programming algorithm. ***
**********************************************************
PRG_bufaddr .set PARMS+1 ;Address of buffer for *
;program data. *
PRG_paddr .set PARMS+2 ;First flash address 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. *
**********************************************************
         .sect "fl_wrt"
*********************************************************
** First, erase flash1 by invoking the clear and erase *
** algorithms. *
** Note: three parameters must be initialized before *
** calling the algorithms. *
*********************************************************
PROG:     LDP #PARMS
          SPLK #0,ERS_COUNT ;Set erase fail count to 0.
**********Put parameters where they belong.**********
          SPLK #0ff00h,PROTECT
          SPLK #04000h,SEG_ST
          SPLK #07FFFh,SEG_END  
          ;b     ers_done
***********First clear flash ************
ers_loop:
          ;CALL GCLR ;Clear flash.
          ;LACL ERROR ;Check for CLEAR error
          ;BCND ers_error,neq ;If error, then hard fail.
***********Next erase flash ************   
          LDP #6
          LACC  WTPROGFLG 
          SUB   #5555H
          BCND  prg_error,NEQ
          LDP #PARMS 
          splk #04000h,PRG_paddr
          splk #28H,PRG_length
          CALL GERS ;Erase flash.
          LACL ERROR ;Check for CLEAR error
          BCND depletion,neq ;If error, then try
;flash–write.
          B ers_done ;Else, no errors erasing.
depletion:LDP #6
          LACC  WTPROGFLG 
          SUB   #5555H
          BCND  prg_error,NEQ
          LDP #PARMS
          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 has 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 SARAM locations are initialized. **
**********************************************************

**********************************************************
** Now that the data to be programmed is ready, the **
** programming algorithm is invoked. Note that four **
** parameters must be initialized before calling the **
** algorithm. **
**********************************************************
          LDP #6
          LACC  WTPROGFLG 
          SUB   #5555H
          BCND  prg_error,NEQ
          LDP #PARMS
**********Put parameters where they belong.**********
          splk #0ff00h,PROTECT
          splk #10c0h,PRG_bufaddr
          splk #04000h,PRG_paddr
          splk #28H,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 has 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.          

⌨️ 快捷键说明

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