Hi i use SW reset command in my code. after reset, PC is set to address 0x0000. unfortunately at this address i can't find nor main{} neither JMP to main. which are the tools i can use (startup.a51 or others) in order to direct the program on address 0x0000 to main{}?
direct the code to main{} in address 0x0000 makes me assune you are using 'C'
startup jumps to autogenerated code that "stuff all variables with initial values specified" which then jumps to main()
if you do not muck around deleting files and stuff this just works
i use SW reset command in my code.
That's a very common idea, and just as commonly a really bad one.
If you need a reset, do yourself a favour and perform the real one, not some cheap knock-off. Jumping to start-of-code is not a reset; it often doesn't even come usefully close.
The state of just about everything will be different from what it is when the hardware comes up out of an actual, proper HW reset. You'll likely spend more on finding and cleaning up all those differences than you would on just getting a proper reset to be executed. Traditionally one just lets the watchdog starve on purpose. If you don't have a watchdog, maybe you let this be the lesson that teaches why that's a bad idea.
Thank you Eric and Hans-Bernhard for your replies I continued on with my investigation and the issue is a bit more complicated. Both of you indeed directed to my findings. i use a watchdog, but a tailored one. by reaching the time limit of the watchdog (PCA ISR) i use the watchdog ISR to save RAM data to the FLASH memory and invoke the SW reset. from inside the watchdog ISR i call to save to FLASH memory function (which calls some other functions). when i call this function, for some reason, the SW reset brings the PC to address 0x0003. if i omit the call to save to FLASH memory function the SW reset is done properly and brings the PC to address 0x0000. i assume this is due to the fact i use different register banks in the function (and the other functions it calls) and in the ISR. although i'm not sure why this should afect the SW reset i'll try to turn memory save function to be "reentrent". Hans-Bernhard, you mentioned something about differences between SW reset and HW reset. do you have some tips on that? thanks M.
WHICH CHIP?
SILAB C8051F931
i use a watchdog, but a tailored one. No, you don't. That mechanism you describe is not a watchdog. It's just timer ISR that does some work. A watchdog is a timer (internal or external), that upon running out does exactly one thing: cause a bona fide reset of the CPU.
from inside the watchdog ISR i call to save to FLASH memory function (which calls some other functions).
Do not call complicated functions from inside an 8051 CPU's ISR. That's almost worse than trying to emulate a reset in SW. If you have to do it, you still have to be extremely careful about how you handle register banks around this.
And you really can't "return" out of an ISR into any kind of SW reset. You'll still have the "currently inside interrupt" flag of the CPU core active. That's one of those differences between the actual reset state and what you can reach just by jumping to zero which I warned you about. One down, countless many to go...
OK i got it. i'll take your advice and try another way around. thanks.
SILAB C8051F931 has a software reset bit use it also the chip has a watchdog
thanks for your input. when i wrote "i use SW reset command" i set the SW reset bit. the problem with the watchdog mechanism is one can't make any action prior the watchdog reset. in my case i'd like to save some parameters to FLASH prior reset. that's why i don't use it.
the problem with the watchdog mechanism is one can't make any action prior the watchdog reset.
Doing other actions in the watchdog ISR is wrong on two counts: first of all, doing time-consuming things or calling other functions from inside an 8051 ISR is a fat big no-no. Second, those particular things you're talking about are a bad idea to do once a watchdog has timed out.
If the watchdog has to bite, that's your last and only sign that your application, and all of its state variables, are seriously corrupted already. Saving that corrupt state to flash will only make matters worse, not better. Don't do that.