.text _start: INTM=#1 ; mask interrupts sp=#1000h ;初始化堆栈指针 pmst=#1a0h ;初始化堆栈指pmst,中断向量重定位道200h BSCR=#0800h ; Set Wait States for Bank Switching ; STM #SWWSR_VAL, SWWSR ; Init S/W Wait State Register ;(commented out: power–up default value used) SWWSR=#2000h ;7个等待状态 TCR=#10h ; Stop on–chip timer OVM=#1 ; overflow mode enabled SXM=#1 ; sign extension mode enabled IFR=#0ffffh ; clear pending interrupts (if any) IMR=#0200h ; select host to DSP interrupt INTM=#0 ; enable maskable interrupts loop: xf=1 ;turn off led nop nop nop nop dcall delay_1s nop nop nop nop xf=0 ;turn on led nop nop nop nop dcall delay_1s nop nop nop nop dgoto loop nop nop ************************************************************** ****************delay 1s program***************************** ************************************************************** delay_1s: push(ar6) push(ar7) ar6=#1000 d_wait: ar7=#1000 d_wait1: nop nop nop nop nop nop nop if (*ar7- != 0) dgoto d_wait1 nop nop if (*ar6- != 0) dgoto d_wait nop nop ar7 = pop() ar6 = pop() dreturn nop nop ************************************************************************** * dsp interrupt service routine ************************************************************************** DSP_ISR: ar5=#hostcommand; pointer to host command ar1=#flashaddr ; pointer to flash addr ar2=#flashdata ; pointer to host data ar3=#dspstate ; pointer to dsp statue ar4=#dspresult ; pointer to flash data ************************************************************************** * Bit test host command and process num1 and num2 accordingly ************************************************************************** CHK_BIT0: TC = bit(*ar5,15-0) ; test bit0 of host command if (NTC) dgoto CHK_BIT1 ; if bit0=0 check bit1 nop nop a=*ar1; ar5=a nop nop dcall _WRITEFlash ; program flash a word nop nop *ar3=#0001h dgoto EXIT nop nop CHK_BIT1: TC = bit(*ar5,15-1) ; test bit0 of host command if (NTC) dgoto CHK_BIT2 ; if bit1=0 check bit2 nop nop a=*ar1; nop nop ar2=a nop nop a=*ar2 *ar4=a nop nop *ar3=#0001h dgoto EXIT nop nop CHK_BIT2: TC = bit(*ar5,15-2) ; test bit0 of host command if (NTC) dgoto EXIT ; if bit2=0 then bad host command nop nop dcall _ERASEFlash ; erase the flash chip nop nop *ar3=#0001h dgoto EXIT nop nop ************************************************************************** * DSP_ISR exit point ************************************************************************** EXIT: IFR=#0FFFFh ; clear interrupt flags dreturn_enable nop nop ************************************************************* ****program flash a word ************************************************************* _WRITEFlash: push(ar0) ar0=#(05555H+OFFSET) nop nop *ar0= #0AAAAH ; 周期1(解锁) nop nop ar0=#0AAAAH nop nop *ar0=#05555H ; 周期2(解锁) nop nop ar0=#0d555H nop nop *ar0=#0A0A0H ; 周期3(建立) nop nop a=*ar2 nop nop *ar5=a ; 周期4(编程) nop nop dcall Check_Toggle_Ready ;检测编程是否正确,见Flash的操作检测 nop nop ar0=pop() dreturn nop nop ******************************************************************* **********flash erash,whole chip ******************************************************************* _ERASEFlash: ;擦除宏 push(ar0) push(al) push(ah) push(ag) ar0=#0d555H *ar0=#0AAAAH; 周期1(解锁) nop nop nop nop ar0=#0AAAAH *ar0=#05555H; 周期2(解锁),应该对地址2aaa操作,但2aaa在5402中不可见,所以加一个偏移量8000h nop nop nop nop ar0=#0d555H *ar0=#08080H; 周期3(建立) nop nop nop nop ar0=#0d555H *ar0=#0AAAAH; 周期4(解锁) nop nop nop nop ar0=#0AAAAH *ar0=#05555H; 周期5(解锁) nop nop nop nop ar0=#0d555H *ar0=#01010H; 周期6(片擦除) nop nop nop nop ar0=#2000;;delay 1ms nop nop erase_wait1: nop nop if (*ar0- != 0) dgoto erase_wait1 nop nop a=#0; ar0=#8000h; erase_wait2:;check data polling a=*ar0; nop nop a=a & #0080h nop nop if (aeq) dgoto erase_wait2 nop nop ag=pop() ah=pop() al=pop() ar0=pop() dreturn nop nop ;====================================================================== Check_Toggle_Ready: a=*ar5 ; read a word form the chip nop nop a=a & #0040h ; mask out the TOGGLE bit (DQ6) nop nop CTR_Tog2: b=*ar5 ; read the same word from the chip again nop nop b=b & #0040h ; mask out the TOGGLE bit (DQ6) nop nop a=a-b ; is DQ6 still toggling? nop nop if (aeq) dgoto CTR_Tog3 ; No, then the write operation is done nop nop a=b nop nop dgoto CTR_Tog2 ; YES, then continue checking... nop nop CTR_Tog3: dreturn nop nop ;=======================================================================