|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
restart_cause() returning 16 (not defined in 24FJ256GA106.h) |
Posted: Thu Aug 19, 2021 11:25 am |
|
|
Code: | // Constants passed into RESTART_CAUSE() are:
#define RESTART_POWER_UP 0
#define RESTART_BROWNOUT 1
#define RESTART_WATCHDOG 4
#define RESTART_SOFTWARE 6
#define RESTART_MCLR 7
#define RESTART_ILLEGAL_OP 14
#define RESTART_TRAP_CONFLICT 15 |
Anyone know what restart cause 16 is? It is not listed in the PIC24 header file.
Thanks... _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9236 Location: Greensville,Ontario
|
|
Posted: Thu Aug 19, 2021 1:56 pm |
|
|
Don't know but I'd be reading the datasheet of the PIC..mind you after the first 500-600 pages my mind would be a tad blurry.... |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Aug 19, 2021 2:38 pm |
|
|
temtronic wrote: | Don't know but I'd be reading the datasheet of the PIC..mind you after the first 500-600 pages my mind would be a tad blurry.... |
The data sheet gives them as bits, and it looks like the CCS call is returning the bit number. Convenient.
Code: | RESTART_POWER_UP 0 -- bit 0 (POR)
RESTART_BROWNOUT 1 -- bit 1 (BOW)
RESTART_WATCHDOG 4 -- bit 4 (WDTO)
RESTART_SOFTWARE 6 -- bit 6 (SWR/RESET)
RESTART_MCLR 7 -- bit 7 (MCLR)
RESTART_ILLEGAL_OP 14 -- bit 14 (IOPUWR)
RESTART_TRAP_CONFLICT 15 -- bit 15 (TRAPR) |
16 is, therefore, invalid.
Dunno! _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19534
|
|
Posted: Fri Aug 20, 2021 12:17 am |
|
|
The CCS code, scans through the set bits, and returns the number of the bit
it sees. It loads a '1' into the top bit of the register at the start of the
rotation. So if _no restart cause_ is seen, it will return 16 (on the DSPIC's).
The point is that getting 16, implies the code has jumped to the test,
without setting any restart bit.
So if (for instance), you coded as:
Code: |
void main(void)
{
int cause;
while(TRUE)
{
cause=restart_cause();
printf("Case was &d", cause);
} //and loop back to the test
}
|
You will get the expected cause (probably 0 the first time), and then
a sequence of 16's.
So 16, is actually 'a restart has not occurred'. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Aug 20, 2021 7:01 am |
|
|
Ttelmah wrote: | You will get the expected cause (probably 0 the first time), and then
a sequence of 16's.
So 16, is actually 'a restart has not occurred'. |
That is interesting. I only run that code at the top of my main(). I wonder what else could make my main() restart. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19534
|
|
Posted: Fri Aug 20, 2021 8:15 am |
|
|
The obvious thing would be something like a return instruction, when a
zero value has been pushed onto the stack.
You can jump to any location in memory, or return to any location.
Provided the stack doesn't underflow you can go anywhere..... |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Aug 20, 2021 8:34 am |
|
|
Ttelmah wrote: | The obvious thing would be something like a return instruction, when a
zero value has been pushed onto the stack.
You can jump to any location in memory, or return to any location.
Provided the stack doesn't underflow you can go anywhere..... |
Ah, a 0 is the GOTO vector. I’ll keep an eye out. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19534
|
|
Posted: Fri Aug 20, 2021 9:47 am |
|
|
Have a global variable declared that is not initialised.
Then in your restart_cause test code, if it is a restart from power up, set
this to zero.
Then through you code at different points, set it to different values.
When you get the 16, see what is in this variable. It'll tell you where the
code got to, which can narrow down where the problem is. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|