AnsweredAssumed Answered

Program Flash - when to reset watchdog

Question asked by Mikkel Bjerring on Feb 2, 2011
Latest reply on Apr 2, 2012 by bigmac

Hi all

 

I'm in the process of changing one of our older products and in that process I'm planning to enable the watchdog. My problem is that I get a watchdog timeout when my program erase/write the flash

 

the erase and write routines looks like they are directly take from the HCS08 Family Reference Manual and looks like the following


 

FlashErase1:psha             lda     #(mFPVIOL+mFACCERR) ;mask            sta     FSTAT               ;abort any command and clear errors            lda     #mPageErase         ;$40 mask pattern for page erase command            bsr     DoOnStack           ;finish command from ram-based sub            ais     #1            rts                         ;Z = 0 means there was an error;*********************************************************************DoOnStack:  pshx            pshh                        ;save pointer to flash            psha                        ;save command on stack            ldhx    #SpSubEnd           ;point at last byte to move to stackSpMoveLoop: lda     ,x                  ;read from flash            psha                        ;move onto stack            aix     #-1                 ;next byte to move            cphx    #SpSub-1            ;past end?            bne     SpMoveLoop          ;loop till whole sub on stack            tsx                         ;tsx=stack på indexreg.point to sub on stack            tpa                         ;move CCR to A for testing            and     #$08                ;check the I mask            bne     I_set               ;skip if I already set            sei                         ;block interrupts while FLASH busy            lda     SpSubSize+6,sp      ;preload data for command            jsr     ,x                  ;execute the sub on the stack            cli                         ;ok to clear I mask now            bra     I_cont              ;continue to stack de-allocationI_set:      lda     SpSubSize+6,sp      ;preload data for command            jsr     ,x                  ;execute the sub on the stackI_cont:     ais     #low(SpSubSize+3)   ;deallocate sub body + H:X + command                                        ;H:X flash pointer OK from SpSub            lsla                        ;A=00 & Z=1 unless PVIOL or ACCERR            rts                         ;to flash where DoOnStack was called ;*********************************************************************SpSub:      ldhx    low(SpSubSize+4),sp      ;get flash address from stack            sta     0,x                 ;write to flash; latch addr and data            lda     SpSubSize+3,sp      ;get flash command            sta     FCMD                ;write the flash command            lda     #mFCBEF             ;mask to initiate command            sta     FSTAT               ;[pwpp] register command            nop                         ;[p] want min 4~ from w cycle to rChkDone:    lda     FSTAT               ;[prpp] so FCCF is valid            lsla                        ;FCCF now in MSB            bpl     ChkDone             ;loop if FCCF = 0SpSubEnd:   rts          SpSubSize   equ     *- (SpSub)            ;back into DoOnStack in flash ;*********************************************************************FlashProg1: psha                        ;temporarily save entry data            lda     #(mFPVIOL+mFACCERR) ;mask            sta     FSTAT               ;abort any command and clear errors            lda     #mByteProg          ;mask pattern for byte prog command            bsr     DoOnStack           ;execute prog code from stack RAM            ais     #1                  ;deallocate data location from stack            rts                         ;Z = 0 means there was an error;*********************************************************************

 

 


so my problem is where do I "feed the dog"  in this routine so it dont timeout (it need to be feed every 23ms) I guess it needs to be in the subroutine that run in the RAM but I can't really figure out where

 

hope someone of you can help

 

best regards

Mikkel

Outcomes