Technical discussions about Freescale Microcontrollers: M68HC11. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Hey guys, another question here. This one might be kind of tricky because I've looked around for the answer but haven't been successful. I'd like to know if there is a way to reset an assembly program at run-time using assembly code? By reset I mean essentially have to go to the ORG line where it all started initially. I'm not sure if this is dependent on what type of board is being used, but I would assume that the code would be similar, if not same, since its the same language. Thanks for any ideas on this one! :) |
|
|
|
----- Original Message ----- From: "nimish_sudan" <> To: < > Hey guys, another question here. This one might be kind of tricky > because I've looked around for the answer but haven't been > successful. I'd like to know if there is a way to reset an assembly > program at run-time using assembly code? By reset I mean essentially > have to go to the ORG line where it all started initially. I'm not > sure if this is dependent on what type of board is being used, but I > would assume that the code would be similar, if not same, since its > the same language. Thanks for any ideas on this one! :) Try this code which uses the Clock Monitor to cause a reset: sei ;disable interrupts tpa ;\ anda #$7F ; >enable STOP instruction tap ;/ ldx #REGS bset [OPTION,x,#CME. ;stop the clock, forcing a CMF Stop stop ;This command causes a CMF res bra Stop ;just in case of XIRQ escaping |
|
|
|
Thanks for the quick reply Tony! I tried the code, but I was unsuccessful. Its probably because I am new to assembly and have not mastered it like you. :) Could you please go into a little detail and explain how/why you have done what you have done? What are the values of Option and CME in the following line? And should the bracket be closed or not? >bset [OPTION,x,#CME. ;stop the clock, Thanks again for the quick reply. Much appreciated! --- In , "Tony Papadimitriou" <tonyp@m...> > Try this code which uses the Clock Monitor to cause a reset: > > sei ;disable interrupts > > tpa ;\ > anda #$7F ; >enable STOP instruction > tap ;/ > ldx #REGS > bset [OPTION,x,#CME. ;stop the clock, forcing a > CMF > Stop stop ;This command causes a CMF > res > bra Stop ;just in case of > XIRQ escaping > tonyp@a... |
|
----- Original Message ----- From: "nimish_sudan" <> To: < > Thanks for the quick reply Tony! I tried the code, but I was > unsuccessful. Its probably because I am new to assembly and have not > mastered it like you. :) Could you please go into a little detail > and explain how/why you have done what you have done? What are the > values of Option and CME in the following line? And should the > bracket be closed or not? > >bset [OPTION,x,#CME. ;stop the clock, The symbols REGS, OPTION, and CME. must be defined with EQU somewhere before this code begins. The "[" syntax is for my ASM11 assembler but even without the "[" it works OK. All it says, is to use the low byte of the value (which it does anyway, but will give a warning). REGS is normally $1000 but it really depends on your hardware (MCU and/or external memory requiring a move of the registers to another page). OPTION is $1039 (or REGS+$39) for the E series, and again, it depends on the particular MCU. CME. is the bit mask for the CME (Clock Monitor Enable) bit in the OPTION register. For E series, this is %00001000 The idea with this code is to stop the clock of the MCU and have it reset based on that condition. The reset is as real as it gets. It's not the same as simply JMP-ing to the start of your code. > Thanks again for the quick reply. Much appreciated! |
|
|
|
Hey Tony, Thanks for the explanation. Just another quick question. Does this reset only work when you're running the program from the EEPROM? Right now I'm NOT using the EEPROM and it just seems to stop execution (and not restart from the top) where the code is in my program. Thanks again! --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "nimish_sudan" <nimish_sudan@y...> > To: < > > Thanks for the quick reply Tony! I tried the code, but I was > > unsuccessful. Its probably because I am new to assembly and have not > > mastered it like you. :) Could you please go into a little detail > > and explain how/why you have done what you have done? What are the > > values of Option and CME in the following line? And should the > > bracket be closed or not? > > > >bset [OPTION,x,#CME. ;stop the clock, > > The symbols REGS, OPTION, and CME. must be defined with EQU somewhere before > this code begins. The "[" syntax is for my ASM11 assembler but even without the > "[" it works OK. All it says, is to use the low byte of the value (which it > does anyway, but will give a warning). > > REGS is normally $1000 but it really depends on your hardware (MCU and/or > external memory requiring a move of the registers to another page). > OPTION is $1039 (or REGS+$39) for the E series, and again, it depends on the > particular MCU. > CME. is the bit mask for the CME (Clock Monitor Enable) bit in the OPTION > register. For E series, this is %00001000 > > The idea with this code is to stop the clock of the MCU and have it reset based > on that condition. The reset is as real as it gets. It's not the same as > simply JMP-ing to the start of your code. > > > Thanks again for the quick reply. Much appreciated! > > tonyp@a... |
|
----- Original Message ----- From: "nimish_sudan" <> To: < > Thanks for the explanation. Just another quick question. Does > this reset only work when you're running the program from the > EEPROM? Right now I'm NOT using the EEPROM and it just seems to stop > execution (and not restart from the top) where the code is in my > program. Thanks again! Not only for EEPROM, it works regardless! Maybe you forgot to initialize the CMF vector with the same value as the RESET vector? |
|
|
|
Tony, As before, you're probably right. :) What value should these vectors be initialized to? This is what I have: BEG EQU $1000 OPTION EQU 39 CME EQU 8 ... ... SEI LDX #BEG BSET OPTION,X #CME TPA ANDA #$7F TAP NOP STOPME STOP BRA STOPME ... Thank again for the fast response! --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "nimish_sudan" <nimish_sudan@y...> > To: < > > Thanks for the explanation. Just another quick question. Does > > this reset only work when you're running the program from the > > EEPROM? Right now I'm NOT using the EEPROM and it just seems to stop > > execution (and not restart from the top) where the code is in my > > program. Thanks again! > > Not only for EEPROM, it works regardless! > > Maybe you forgot to initialize the CMF vector with the same value as the RESET > vector? > > tonyp@a... |
|
|
|
----- Original Message ----- From: "nimish_sudan" <> To: < > Tony, > As before, you're probably right. :) What value should these > vectors be initialized to? This is what I have: > OPTION EQU 39 Make that a hex value, $39 The CMF vector is the one right before reset (at address $FFFC). You can initialize it as you do for the reset vector. Example: ORG $FFFC DW Start ;CMF vector DW Start ;RESET vector > Thank again for the fast response! |