vtechwin
Reged: Oct 19 2004
Posts: 265
|
|
Hi,
Any idea why following do not complie.
((void (code *) (void)) 0) ();
BAsically i am trying to do a software reset by pointing to reset vector in PROM.
Any help would be great.
VTechwin
|
rasdolin
 
Reged: Oct 17 2003
Posts: 70
Loc: Russia
|
|
Code:
#define POWERUP() (*(void(*)()) 0x0)()
void main(void)
{
...
POWERUP();
...
}
Code:
typedef void (*fptr) (void);
fptr qwe;
void main(void)
{
...
qwe = 0;
qwe();
...
}
|
Dan Henry
Guru
  
Reged: Oct 16 2003
Posts: 4597
Loc: Colorado
|
|
If you are using Keil's C51, why are you asking here?
|
John Payson
  
Reged: Oct 16 2003
Posts: 1336
|
|
My normal approach to doing a software reset is to set the WDT very short, disable interrupts, and do a while(1);
If a faster reset is needed, I believe it's possible to get one by setting the prescalar to the RTCC and then switching the prescalar to the watchdog after it's registered the right number of counts. I don't know that this will work consistently on all PIC variations, however.
|
vtechwin
Reged: Oct 19 2004
Posts: 265
|
|
Very clever.
Dan basically I am migrating from 8051 tool set to RISC PIC architecture. So many things that i know from the old experience now i have to port those to this new architecture. I would appreciate it more if you also tell me your explanation of that RESET function call.
VTechwin
|
Dan Henry
Guru
  
Reged: Oct 16 2003
Posts: 4597
Loc: Colorado
|
|
Quote:
Dan basically I am migrating from 8051 tool set to RISC PIC architecture. So many things that i know from the old experience now i have to port those to this new architecture.
OK, fair enough.
Quote:
I would appreciate it more if you also tell me your explanation of that RESET function call.
With the exception of the C51 "code" keyword (which PICC does not use), it is standard C stuff -- casting an integer constant to a function pointer and then dereference (invoking) it.
- The 8051 starts executing code at 0x0000 after reset is released.
- The PIC starts executing code at 0x0000 after reset is released.
- Remove the "code" keyword and it should compile and provide the functional equivalent for the PIC.
It is bad juju and may not yield the results you expect on either MCU; that is, if you are expecting a post reset-like MCU state. I would call it a software restart, not a reset, since it does nothing to reset the hardware. If you want a real reset, let the WDT do it like John says.
|
vtechwin
Reged: Oct 19 2004
Posts: 265
|
|
Quote:
I would call it a software restart, not a reset, since it does nothing to reset the hardware. If you want a real reset, let the WDT do it like John says.
OK, I get it now. Thanks for the details. One little ambiguity. When the code will RESTART by this method, will it it happen that all the variables will reset in the RAM and will be redeclared/reinitialized just as they did in the very first time? And they will lose their previous states/values. If this is the case then I can use this method to recover from a deadlock without using watchdog timer and hard-reset.
|
Dan Henry
Guru
  
Reged: Oct 16 2003
Posts: 4597
Loc: Colorado
|
|
Generally speaking, yes reinitialized. Persistent data should hold their values.
|
jtemples
Guru
  
Reged: Oct 16 2003
Posts: 2000
Loc: Southern California
|
|
If you're using a PIC18, you can use the reset instruction.
|
Daniel
Reged: Nov 28 2003
Posts: 175
|
|
The following will do:
Code:
((void (*)(void)) NULL)();
There are two problems with this sofware reset:
1 - No problem with the compiler (all your variables will be properly re-initialized), but the hardware registers and peripherals will not be reset. You must initialize them in your startup procedure, without relying on their power-up default. This is "good programming practice" anyway.
2 - There is a simulator issue with MPLAB. The software reset is actually a call to a function, without return. While this is not a real problem in the chip, MPLAB's simulator keeps track of the call-return pairs and will issue a "stack overflow" error after a few runs.
With PIC18, the "reset" instruction will properly reset all the hardware, avoiding these problems.
Happy new year, Daniel
|