Page 1 of 1

Internal Error in ISR

Posted: 04 July 2008, 15:06 PM
by pjc30943
I'm just trying out manual ISRs.
As a test I have

Code: Select all

ISR INT0()
	putpin loopTogglePin, zxOutputToggle
end ISR
but recieve a simple "Internal Error: an error occurred while building test.zxb", exit code 1.

Anyone have thoughts on what's going on?

[EDIT: 1280n]

Re: Internal Error in ISR

Posted: 05 July 2008, 20:21 PM
by dkinzer
pjc30943 wrote: recieve a simple "Internal Error: an error occurred while building test.zxb", exit code 1.
It could be caused by using an older version of the ZBasic compiler. You need v2.5.0 or later.

Also, add the compiler option --verbose to the top of the project file. That will cause the output from the backend compiler and linker to be displayed in the IDE's output window. You should get more definitive error information from that.

Posted: 07 July 2008, 12:11 PM
by pjc30943
Verbose flag added. The entire result is posted below for completeness, though (I would think) only the last three or four are of consequence. Based on the output, can code (used elsewhere) use INT0, even if it's not called? Based on what I know of the compiler's intelligence, that seems unlikely...
[EDIT: No need to answer the last thought, of INT0 not being allowed elsewhere: I commented out all references, with no change.]

Code: Select all

Biped_Main_2legs.c: In function 'zf_Main':
Biped_Main_2legs.c:46: warning: cast from pointer to integer of different size
Biped_Main_2legs.c:48: warning: cast from pointer to integer of different size
Biped_Main_2legs.c:50: warning: cast from pointer to integer of different size
Biped_Main_2legs.c:52: warning: cast from pointer to integer of different size
Biped_Main_2legs.c:54: warning: cast from pointer to integer of different size
Biped_Main_2legs.c:57: warning: cast from pointer to integer of different size
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_header_2legs.c -o Biped_header_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_IO_routines_2legs.c -o Biped_IO_routines_2legs.o
Biped_IO_routines_2legs.c: In function 'zf_putDACs':
Biped_IO_routines_2legs.c:33: warning: passing argument 3 of 'cmdSPI' from incompatible pointer type
Biped_IO_routines_2legs.c: In function 'zf_encoderTask':
Biped_IO_routines_2legs.c:51: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:74: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:98: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:100: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:124: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:126: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:150: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:152: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:177: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:179: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:203: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:205: warning: cast from pointer to integer of different size
Biped_IO_routines_2legs.c:246: warning: cast from pointer to integer of different size
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_joint_controllers_2legs.c -o biped_joint_controllers_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_user_IO_2legs.c -o biped_user_IO_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_Test_Routines_2legs.c -o Biped_Test_Routines_2legs.o
Biped_Test_Routines_2legs.c: In function 'zf_monitorEncoders':
Biped_Test_Routines_2legs.c:8: warning: cast from pointer to integer of different size
Biped_Test_Routines_2legs.c:9: warning: cast from pointer to integer of different size
Biped_Test_Routines_2legs.c:11: warning: cast from pointer to integer of different size
Biped_Test_Routines_2legs.c:12: warning: cast from pointer to integer of different size
Biped_Test_Routines_2legs.c:14: warning: cast from pointer to integer of different size
Biped_Test_Routines_2legs.c:15: warning: cast from pointer to integer of different size
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_utils_2legs.c -o biped_utils_2legs.o
biped_utils_2legs.c: In function 'zf_initCPU':
biped_utils_2legs.c:106: warning: cast from pointer to integer of different size
biped_utils_2legs.c:107: warning: cast from pointer to integer of different size
biped_utils_2legs.c:111: warning: cast from pointer to integer of different size
biped_utils_2legs.c:112: warning: cast from pointer to integer of different size
biped_utils_2legs.c:116: warning: cast from pointer to integer of different size
biped_utils_2legs.c:117: warning: cast from pointer to integer of different size
biped_utils_2legs.c:121: warning: cast from pointer to integer of different size
biped_utils_2legs.c:122: warning: cast from pointer to integer of different size
biped_utils_2legs.c:126: warning: cast from pointer to integer of different size
biped_utils_2legs.c:127: warning: cast from pointer to integer of different size
biped_utils_2legs.c:131: warning: cast from pointer to integer of different size
biped_utils_2legs.c:132: warning: cast from pointer to integer of different size
biped_utils_2legs.c:136: warning: cast from pointer to integer of different size
biped_utils_2legs.c:137: warning: cast from pointer to integer of different size
biped_utils_2legs.c:141: warning: cast from pointer to integer of different size
biped_utils_2legs.c:142: warning: cast from pointer to integer of different size
biped_utils_2legs.c:146: warning: cast from pointer to integer of different size
biped_utils_2legs.c:147: warning: cast from pointer to integer of different size
biped_utils_2legs.c:151: warning: cast from pointer to integer of different size
biped_utils_2legs.c:152: warning: cast from pointer to integer of different size
biped_utils_2legs.c:156: warning: cast from pointer to integer of different size
biped_utils_2legs.c:157: warning: cast from pointer to integer of different size
biped_utils_2legs.c:161: warning: cast from pointer to integer of different size
biped_utils_2legs.c:162: warning: cast from pointer to integer of different size
biped_utils_2legs.c:166: warning: cast from pointer to integer of different size
biped_utils_2legs.c:167: warning: cast from pointer to integer of different size
biped_utils_2legs.c:171: warning: cast from pointer to integer of different size
biped_utils_2legs.c:172: warning: cast from pointer to integer of different size
biped_utils_2legs.c:176: warning: cast from pointer to integer of different size
biped_utils_2legs.c:177: warning: cast from pointer to integer of different size
biped_utils_2legs.c:181: warning: cast from pointer to integer of different size
biped_utils_2legs.c:182: warning: cast from pointer to integer of different size
biped_utils_2legs.c:186: warning: cast from pointer to integer of different size
biped_utils_2legs.c:187: warning: cast from pointer to integer of different size
biped_utils_2legs.c:191: warning: cast from pointer to integer of different size
biped_utils_2legs.c:192: warning: cast from pointer to integer of different size
biped_utils_2legs.c:196: warning: cast from pointer to integer of different size
biped_utils_2legs.c:197: warning: cast from pointer to integer of different size
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_obsolete_functions_2legs.c -o biped_obsolete_functions_2legs.o
avr-gcc -o biped_2legs.i1 -mmcu=atmega1280 -L"C:/Program Files/ZBasic/zxlib" -Wl,-T,"C:/Program Files/ZBasic/zxlib/zx_avr5.lds" -u rtc_ISR -u int0_ISR -u int1_ISR -u int2_ISR -u int3_ISR -u int4_ISR -u int5_ISR -u int6_ISR -u int7_ISR -u pcint0_ISR -u pcint1_ISR -u pcint2_ISR -u anaComp_ISR Biped_Main_2legs.o Biped_header_2legs.o Biped_IO_routines_2legs.o biped_joint_controllers_2legs.o biped_user_IO_2legs.o Biped_Test_Routines_2legs.o biped_utils_2legs.o biped_obsolete_functions_2legs.o  -lzx1280n -lm
C:/Program Files/ZBasic/zxlib\libzx1280n.a(int0_ISR.o): In function `__vector_1':
(.text+0x0): multiple definition of `__vector_1'
Biped_IO_routines_2legs.o:C:\Program Files\ZBasic\zx_XfhlAB/Biped_IO_routines_2legs.c:37: first defined here
make: *** [biped_2legs.i1] Error 1
make: Leaving directory `C:/Program Files/ZBasic/zx_XfhlAB'
Biped Test Routines 2legs.bas:506: Warning(8): subroutine will never return
biped utils 2legs.bas:184: Warning(8): subroutine will never return
Internal Error: an error occurred while building biped 2legs.zxb
>Exit code: 1

Posted: 07 July 2008, 12:37 PM
by dkinzer
pjc30943 wrote:Verbose flag added. The entire result is posted below
The presence of all of the warnings causes me some concern. That may be indicative of a separate issue that needs to be explored.

The main issue is that the compiler thinks that there are two ISRs for INT0.

Code: Select all

C:/Program Files/ZBasic/zxlib\libzx1280n.a(int0_ISR.o): In function `__vector_1':
(.text+0x0): multiple definition of `__vector_1'
Biped_IO_routines_2legs.o:C:\Program Files\ZBasic\zx_XfhlAB/Biped_IO_routines_2legs.c:37: first defined here 
The module int0_ISR.o is from the ZX Library. That is being pulled in because the compiler thinks that it is needed - a call to WaitForInterrupt() I would think. If the compiler can determine exactly which ISR is required for WaitForInterrupt(), it will only include that one. Otherwise, it includes all of the possible ISRs that might be required for the full range of parameters permitted by WaitForInterrupt().

Can you send me the code for this application? I'd like to look into this in more detail.

Posted: 07 July 2008, 12:57 PM
by pjc30943
You are right, the WaitForInterrupt() routines were causing the error, despite them using different INTs. For example, I comment out

Code: Select all

waitforinterrupt zxPinRisingEdge, WaitInt6
and it compiles.

Odd that the compiler can't determine that this uses INT6.

Posted: 07 July 2008, 14:45 PM
by dkinzer
pjc30943 wrote:Odd that the compiler can't determine that this uses INT6.
Indeed. There was a logic error in the compiler code that ended up including all of the ISRs related to WaitForInterrupt() even though it could tell that only INT6 was needed.

I've posted an experimental update to the compiler, v2.5.4, that corrects this problem. Included in the .zip file is an updated zxlib.h that should eliminate the warnings. Be sure that the zxlib.h file gets put in the zxlib subdirectory of the ZBasic installation directory. Using the option to "Extract Using Folder Names" or something similar on your unzipping utility will likely produce the desired result.

Posted: 07 July 2008, 15:31 PM
by pjc30943
Thank you Don for the quick solution. That fixed the error message.

Back to the ISRs: is it the case that by defining the ISR routine, as coded above, interrupts of that type are automatically enabled? This is, from the documentation, no initialization (by the user) is required, but is taken care of during compilation.

The code above fails to toggle a pin, or debug a character if I add that into the sub, despite verification that a changing signal is going into D.0 (pin for INT0). Having a character sent takes a long time, and is thus bad practice inside an ISR, but it's temporary, for testing only.

Posted: 07 July 2008, 16:40 PM
by dkinzer
pjc30943 wrote:That fixed the error message.
Are the warnings gone as well?
pjc30943 wrote:s it the case that by defining the ISR routine, as coded above, interrupts of that type are automatically enabled?
No, it is not. When you define an ISR, all that happens is that the ISR code you provide is included in the downloadable image and the vector for that interrupt points to the ISR. (For each interrupt, unless an ISR is provided, either by you or automatically by the ZBasic compiler, the vector points to a default ISR that causes a reset.) If you do provide an ISR, you also have to supply code that configures the related I/O registers as you want them in order to cause the interrupt to occur.

There is a way to provide an ISR that replaces (overrides) an ISR that would normally be provided automatically by ZBasic. However, writing such an ISR usually requires some knowledge of internal ZX run-time data structures in order for it to work properly.

pjc30943 wrote:This is, from the documentation, no initialization (by the user) is required, but is taken care of during compilation.
It sounds like the documentation could be made more clear. Reference, please?

Posted: 07 July 2008, 17:03 PM
by pjc30943
dkinzer wrote:Are the warnings gone as well?
The warnings remain. I'm not sure which are legitimate (aside from the normal VM-type warnings of statements not being executed, etc)
dkinzer wrote:No, it is not. When you define an ISR, all that happens is that the ISR code you provide is included in the downloadable image and the vector for that interrupt points to the ISR...

Ah, that's clear now.
dkinzer wrote:Reference, please?
The documentation is fine, and was not at fault...
I just didn't see anything relating to the question; and when the section for EnableInt() (pg.92, section 4.4, Executing Blocks of Code Atomically) showed interrupts being manually disabled first, I (wrongly) assumed the compiler enables by default those interrupts which have ISRs defined for them.
But these are obviously just fragments of code, and not indicative of what goes on in the rest of the program...

Posted: 07 July 2008, 17:47 PM
by dkinzer
pjc30943 wrote:The warnings remain. I'm not sure which are legitimate (aside from the normal VM-type warnings of statements not being executed, etc)
They're all legitimate but only one is due to the way that you wrote your code. The warnings like the two below should have been eliminated by the changes in zxlib.h.

Code: Select all

warning: cast from pointer to integer of different size 
warning: passing argument 3 of 'cmdSPI' from incompatible pointer
When I compile your code here I get just one warning about a routine never returning. If you wish, you can suppress this warning using the #pragma warning construct.

Check the timestamp of the file {ZBasic install directory}/zxlib/zxlib.h - it should have today's date. If not, copy the one from the .zip file referenced above over it.
pjc30943 wrote:the section for EnableInt()
The DisableInt()/EnableInt() calls deal with globally disabling/enabling interrupts. This allows sequences of code to execute without being interrupted by anything. Even when interrupts are globally enabled, the individual interrupts (e.g. USART receive, timer overflow, pin change interrupt, etc.) need to be configured and separately enabled. Some of the interrupts (e.g. external interrupts) have several different modes of operation. The compiler has no way, of course, of knowing how you might want a particular interrupt configured or when you might want it enabled.

Posted: 08 July 2008, 12:56 PM
by pjc30943
When I compile your code here I get just one warning about a routine never returning. If you wish, you can suppress this warning using the #pragma warning construct.
Okay, thanks.
Check the timestamp of the file {ZBasic install directory}/zxlib/zxlib.h - it should have today's date. If not, copy the one from the .zip file referenced above over it.
It is the new version, but the warnings still abound. I'll recopy the file and check again.

EDIT: It was a user error--I accidentally had the folder in zxlib as well. The warnings are indeed gone.

Posted: 17 July 2008, 11:45 AM
by pjc30943
EDIT: again it was caused by waitForInterrupt()'s which used the same interrupt numbers--but it was in a sub that wasn't called. The errors vanished after I commented out those lines.
--------------------------------------------------------------------------------

I changed some variable names, and what I thought to be unrelated code, and now get the following ISR issues again, arising from multiple definitions of certain interrupts. Most likely it is my mistake; I'll search for the cause.
This is using 2.5.5.

Code: Select all

>"C:\Program Files\ZBasic\zbasic.exe"  --target-device=ZX1281e --directory="C:\Program Files\ZBasic/" --project="biped 2legs.pjt"
make: Entering directory `C:/Program Files/ZBasic/zx_uech6N'
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_Main_2legs.c -o Biped_Main_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_header_2legs.c -o Biped_header_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_IO_routines_2legs.c -o Biped_IO_routines_2legs.o
Biped_IO_routines_2legs.c: In function '__vector_3':
Biped_IO_routines_2legs.c:333: warning: 'zv_timerEnd' may be used uninitialized in this function
Biped_IO_routines_2legs.c:332: warning: 'zv_timerStart' may be used uninitialized in this function
Biped_IO_routines_2legs.c: In function '__vector_2':
Biped_IO_routines_2legs.c:316: warning: 'zv_timerEnd' may be used uninitialized in this function
Biped_IO_routines_2legs.c:315: warning: 'zv_timerStart' may be used uninitialized in this function
Biped_IO_routines_2legs.c: In function '__vector_1':
Biped_IO_routines_2legs.c:299: warning: 'zv_timerEnd' may be used uninitialized in this function
Biped_IO_routines_2legs.c:298: warning: 'zv_timerStart' may be used uninitialized in this function
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_joint_controllers_2legs.c -o biped_joint_controllers_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_user_IO_2legs.c -o biped_user_IO_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct Biped_Test_Routines_2legs.c -o Biped_Test_Routines_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_utils_2legs.c -o biped_utils_2legs.o
avr-gcc -c -Dzx1280n -mmcu=atmega1280 -std=gnu99 -fgnu89-inline -gdwarf-2 -Os -I"C:/Program Files/ZBasic/zxlib" -I. -Wall -Wstrict-prototypes -funsigned-char -fpack-struct biped_obsolete_functions_2legs.c -o biped_obsolete_functions_2legs.o
avr-gcc -o biped_2legs.i1 -mmcu=atmega1280 -L"C:/Program Files/ZBasic/zxlib" -Wl,-T,"C:/Program Files/ZBasic/zxlib/zx_avr5.lds" -u rtc_ISR -u int1_ISR -u int2_ISR -u int3_ISR Biped_Main_2legs.o Biped_header_2legs.o Biped_IO_routines_2legs.o biped_joint_controllers_2legs.o biped_user_IO_2legs.o Biped_Test_Routines_2legs.o biped_utils_2legs.o biped_obsolete_functions_2legs.o  -lzx1280n -lm
C:/Program Files/ZBasic/zxlib\libzx1280n.a(int1_ISR.o): In function `__vector_2':
(.text+0x0): multiple definition of `__vector_2'
Biped_IO_routines_2legs.o:C:\Program Files\ZBasic\zx_uech6N/Biped_IO_routines_2legs.c:314: first defined here
C:/Program Files/ZBasic/zxlib\libzx1280n.a(int2_ISR.o): In function `__vector_3':
(.text+0x0): multiple definition of `__vector_3'
Biped_IO_routines_2legs.o:C:\Program Files\ZBasic\zx_uech6N/Biped_IO_routines_2legs.c:331: first defined here
make: *** [biped_2legs.i1] Error 1
make: Leaving directory `C:/Program Files/ZBasic/zx_uech6N'
Biped Test Routines 2legs.bas:63: Warning(8): subroutine will never return
biped utils 2legs.bas:187: Warning(8): subroutine will never return
Internal Error: an error occurred while building biped 2legs.zxb
>Exit code: 1

Posted: 17 July 2008, 12:01 PM
by dkinzer
Send me the code again that exhibits the problem and I'll see what's going on.