View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
Schrodinger's Variable - SOLVED |
Posted: Sat May 12, 2018 12:26 pm |
|
|
I have the following code snippets:
Code: |
fprintf(lcd_putc,"_____________________________DEBUG - WIFI RESET FLAG:%u\r\n",WIFI_RESET_FLAG);
Internet_Manager(); // Manages the connections and upload method |
Where i print the variable "WIFI_RESET_FLAG"... Assume there has been a reset recently so it is 1.
Just as i finish printing it i call "Internet_Manager()"
Then:
Code: | void Internet_Manager()
{
fprintf(lcd_putc,"_____________________________DEBUG - WIFI RESET FLAG:%u\r\n",WIFI_RESET_FLAG);
if(GPRS_ONLY==FALSE) // Default state is WIFI ON
{
if(!WIFI_Upload_Data()) // Try Uploading via WIFI
{ |
As soon as i enter "Internet_manager()" i print the Flag again... and right before the call it was 1 but inside the function its 0.
Assume all is good and i get to call "WIFI_Upload_Data() on the IF statement.
Then:
Code: | int1 WIFI_Upload_Data()
{
fprintf(lcd_putc,"WTF1_____________________________DEBUG - WIFI RESET FLAG:%u\r\n",WIFI_RESET_FLAG);
if(WIFI_RESET_FLAG==FALSE)
{
fprintf(lcd_putc,"WTF2_____________________________DEBUG - WIFI RESET FLAG:%u\r\n",WIFI_RESET_FLAG); |
This IF checks out as TRUE!?!?!?!?!
BUT it gets wierder... as soon as i remove the DEBUG printf Before calling Internet_Manager() the IF fails as WIFI_RESET_FLAG shows FALSE!?!?!?!
So if i print to debug the variable my code works, if i dont print it the code fails.... WTFFFFF?!?!
WIFI_RESET_FLAG is a GLOBAL on the Wifi Dirver....
Internet_Manager() is part of the main application code.
WIFI_Upload_Data() is part of the Wifi Driver.
I appreciate your help.
G _________________ CCS PCM 5.078 & CCS PCH 5.093
Last edited by Gabriel on Mon May 14, 2018 5:48 pm; edited 1 time in total |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat May 12, 2018 12:47 pm |
|
|
I have not updated my compiler yet as per my last post.. FYI.
This is pretty much the same code ive been using for the last 3 years.
This application has some diferences but none that change any of the WIFI functionality.
so im pretty much stuck at this moment. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 12, 2018 4:29 pm |
|
|
First, tell us your PIC and compiler version.
Then look at the .SYM file.
1. See if your flag has the same the address as any other variables.
2. Also, look at the variables that occur just before the address of your flag.
What are they ? Are they possibly a byte value that your code is treating
as a word, and thus your flag is over-written ? Or is it an array, and your
code is accidentally writing beyond the end of the array and over-writing
your flag.
Look at the .LST file.
1. What are the stack levels ? Do the levels used (worst case) exceed the
levels available in the PIC ?
2. What about RAM usage ? Is it near the limits ?
3. Look at the fuse list at the end of the .LST file. Make sure it has
NOXINST (if you're using Pic18F). |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat May 12, 2018 7:07 pm |
|
|
PIC18F87J50
PCH 5.013
69% RAM worst case
The variable in question is a "int1" global.
Its only written to in 2 places, but read across multiple parts of the code.
Will revert back after i look at your suggestions.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Sun May 13, 2018 12:19 am |
|
|
The fix I found was to declare any variables like this to be 'static'.
Examining the .sym was the way to find this.
I must admit I have not seen this on 'recent' versions of the compiler, so I suspect it has been fixed now. However the version being referred to by the original poster is around where I found this. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sun May 13, 2018 10:35 am |
|
|
So, As Per PCM's Suggestions ive been looking at the SYM file.
found the following:
Quote: | 200.0 Button_Pressed
200.1 Long_Button_Press
200.2 doneFlag
200.3 WIFI_RESET_FLAG
200.4 ISR_MODE
200.5 Long_Message
200.6 RX_DONE
200.7 Backlight_Off_Flag |
Looking at the variable before "WIFI_RESET_FLAG" i found the following on the DS18B20 Driver that I got from this forum:
Code: | doneFlag = (lastDiscrep == 0); |
Which seems like an extra '=' . or maybe its a use of the '==' operator that i was not aware of or forgot.
Will compile, test and revert to you again.
Thank you all for your help so far.
G _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sun May 13, 2018 10:42 am |
|
|
Well that didnt work jajajaj the DS18B20 driver failed to recognize any devices on the bus.
Better check that C book for that '==' use. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 13, 2018 10:47 am |
|
|
Gabriel, what do you mean by "revert to you" ?
To me, revert means
1. Go back to the previous compiler version.
2. Go back to the previous code. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Sun May 13, 2018 10:56 am |
|
|
Code: |
doneFlag = (lastDiscrep == 0);
|
Is perfectly reasonable.
It makes 'doneFlag' into the logical result of testing if lastDiscrep is equal to zero. This is what '==' does in C.
The thing to do on the sym, is see if any other variables are mapped at address 200.
The other thing to look at carefully is if you make any use of pointers. It'd be easy for you to accidentally write to the wrong address with these. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sun May 13, 2018 11:08 am |
|
|
Revert to you = Get back to you.
So i have 2 functions on my code that have the EXACT same code, but the function call thats inside after a couple of ifs is what changes.
one is for uploading and the other for downloading data.
Uploading fails, downloading reads the WIFI_RESET_FLAG correctly.
In any case, looking at disassembly listing file:
DOWNLOADING (WORKS):
Code: | 33: int1 WIFI_Download_Data()
34: {
35: if(WIFI_RESET_FLAG==FALSE)
11CE4 0102 MOVLB 0x2
11CE6 B700 BTFSC 0, 0x3, BANKED
11CE8 D016 BRA 0x11d16
36: {
37: if(Connect_to_Cloud())
11CEA 0100 MOVLB 0
11CEC EC15 CALL 0xf82a, 0
11CF0 5201 MOVF 0x1, F, ACCESS
11CF2 E00C BZ 0x11d0c
38: {
39: fprintf(lcd_putc,"WIFI - Initiated Data Download\r\n"); |
UPLOADING (FAILS);
Code: | 17: int1 WIFI_Upload_Data()
18: {
19: if(WIFI_RESET_FLAG==FALSE)
0FDC8 B400 BTFSC 0, 0x2, ACCESS
0FDCA D013 BRA 0xfdf2
20: {
21: if(Connect_to_Cloud())
0FDCC DD2E RCALL 0xf82a
0FDCE 5201 MOVF 0x1, F, ACCESS
0FDD0 E00C BZ 0xfdea
22: {
23: fprintf(lcd_putc,"WIFI - Initiated Data Upload\r\n"); |
There are some clear differences on what each code is doing.
I have to admit, I dont remember my assembly well enough, so im lost.
I kinda get out of this that one code is actually accessing the flag, while the other takes a "Banked" version of it??? which i dont know how to resolve.
G _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Sun May 13, 2018 12:07 pm |
|
|
The second routine is assuming that the bank register is already set to '2'. You'd have to check where it was called from to verify this is the case. However big difference is it is checking bit 2, rather than bit 3. The symbol file shows this as being doneFlag, not WIFI_RESET_FLAG.
Was it working before?.
What has triggered it to go wrong?.
5.012, is an early enough V5 compiler that it did have some significant issues. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon May 14, 2018 2:59 pm |
|
|
So... Following up on this
The was one variable(bit) on that 200 address that was not being used - as per a warning on the compile output file.
I removed the variable and 1 or 2 others that were unused to see if that helped.
(a warning i usually dismiss as i run several versions of the same code for different devices which may or may not use a variable depending on setup...)
obviously the SYM file changed and now i have the following:
Code: | 17: int1 WIFI_Upload_Data()
18: {
19: if(WIFI_RESET_FLAG==FALSE)
0FDDC 0101 MOVLB 0x1
0FDDE B5FF BTFSC 0xff, 0x2, BANKED
0FDE0 D015 BRA 0xfe0c
20: {
21: if(Connect_to_Cloud())
0FDE2 0100 MOVLB 0
0FDE4 DD2C RCALL 0xf83e
0FDE6 5201 MOVF 0x1, F, ACCESS
0FDE8 E00C BZ 0xfe02
22: { |
and
Code: | 33: int1 WIFI_Download_Data()
34: {
35: if(WIFI_RESET_FLAG==FALSE)
11D0E 0101 MOVLB 0x1
11D10 B5FF BTFSC 0xff, 0x2, BANKED
11D12 D016 BRA 0x11d40
36: {
37: if(Connect_to_Cloud())
11D14 0100 MOVLB 0
11D16 EC1F CALL 0xf83e, 0
11D1A 5201 MOVF 0x1, F, ACCESS
11D1C E00C BZ 0x11d36
38: { |
Code: | 1FF.0 Button_Pressed
1FF.1 doneFlag
1FF.2 WIFI_RESET_FLAG
1FF.3 ISR_MODE
1FF.4 Long_Message
1FF.5 RX_DONE
1FF.6 Backlight_Off_Flag
1FF.7 Backlight_State |
The major change was removing that "Long_Button_Pressed" variable
I'm not in a position to test the code, but from the LST file i can see that now both functions indeed access the right bit.
Now that I've "fixed" this leak, i hope another hole does'nt open up elsewhere.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon May 14, 2018 5:48 pm |
|
|
And that's all folks...
I guess unused 1bit variables mess things up when packed in to a byte by the compiler?
... anyways... compiled, tested on hardware, solved.
Thanks for your guidance on this, I would have never figured it out if you all had not pointed me in the right direction.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue May 15, 2018 5:38 am |
|
|
hmm... now IF you have any hair left, I'd like to know IF you could just put a line of code say 'variable.unused_bit=variable.unused_bit;' in your code, would it compile properly?
This way the unused bit IS 'used', though as I type this...hmm will the compiler says 'that does nothing,so I won't code it'?
Jay |
|
|
|