PICmicro & dsPIC >> PICmicro & dsPIC

Pages: 1 | 2 | >> (show all)
vtechwin

*

Reged: Oct 19 2004
Posts: 265
code pointer
      #15018 - Thu Dec 23 2004 06:38 AM

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


Post Extras: Print Post   Remind Me!   Notify Moderator  
rasdolin

***

Reged: Oct 17 2003
Posts: 70
Loc: Russia
Re: code pointer [Re: vtechwin]
      #15019 - Thu Dec 23 2004 07:48 AM

Code:

#define POWERUP() (*(void(*)()) 0x0)()
void main(void)
{
    ...
    POWERUP();
    ...
}



Code:

typedef void (*fptr) (void);
fptr qwe;

void main(void)
{
    ...
    qwe = 0;
    qwe();
    ...
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
Dan HenryModerator
Guru
****

Reged: Oct 16 2003
Posts: 4597
Loc: Colorado
Re: code pointer [Re: vtechwin]
      #15022 - Thu Dec 23 2004 09:00 AM

If you are using Keil's C51, why are you asking here?

Post Extras: Print Post   Remind Me!   Notify Moderator  
John Payson

****

Reged: Oct 16 2003
Posts: 1336
Re: code pointer [Re: vtechwin]
      #15024 - Thu Dec 23 2004 01:30 PM

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.


Post Extras: Print Post   Remind Me!   Notify Moderator  
vtechwin

*

Reged: Oct 19 2004
Posts: 265
Re: code pointer [Re: Dan Henry]
      #15028 - Fri Dec 24 2004 12:11 AM

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


Post Extras: Print Post   Remind Me!   Notify Moderator  
Dan HenryModerator
Guru
****

Reged: Oct 16 2003
Posts: 4597
Loc: Colorado
Re: code pointer [Re: vtechwin]
      #15029 - Fri Dec 24 2004 01:06 AM

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.


Post Extras: Print Post   Remind Me!   Notify Moderator  
vtechwin

*

Reged: Oct 19 2004
Posts: 265
Re: code pointer [Re: Dan Henry]
      #15030 - Fri Dec 24 2004 01:36 AM

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.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Dan HenryModerator
Guru
****

Reged: Oct 16 2003
Posts: 4597
Loc: Colorado
Re: code pointer [Re: vtechwin]
      #15035 - Fri Dec 24 2004 11:32 AM

Generally speaking, yes reinitialized. Persistent data should hold their values.

Post Extras: Print Post   Remind Me!   Notify Moderator  
jtemplesModerator
Guru
****

Reged: Oct 16 2003
Posts: 2000
Loc: Southern California
Re: code pointer [Re: vtechwin]
      #15040 - Fri Dec 24 2004 04:23 PM

If you're using a PIC18, you can use the reset instruction.

Post Extras: Print Post   Remind Me!   Notify Moderator  
Daniel

*

Reged: Nov 28 2003
Posts: 175
Re: code pointer [Re: vtechwin]
      #15045 - Sun Dec 26 2004 06:22 AM


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


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1 | 2 | >> (show all)



Extra information
1 registered and 181 anonymous users are browsing this forum.

Moderator:  mikerj, jtemples, jeff, Dan Henry, Andrew L 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 14213

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5