CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problems with High-priority Interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andysan



Joined: 01 Oct 2004
Posts: 2

View user's profile Send private message

Problems with High-priority Interrupt
PostPosted: Fri Dec 17, 2004 2:42 am     Reply with quote

Could anyone with experience tell me what is wrong with my piece of code?
I got this error message:
Error[126] C:\\interrupt_file.c : Invalid ORG range

I have tried reading on the net but Sad nothing won't work.

My code:
void test_interrupt(int* packet_ptr)
{
int i = 0;
char c;

RCIF = 0;
c = serial_getch();
if (c == START_STRING)
packet_ptr[0] = c;

packet_ptr[i] = c;
i++;

if (c == END_STRING)
{
full_packet = 1;
}

#asm
retfie 1
#endasm

}

#ORG 0x08,0x0A
void Int_Handler_High(void)
{
if (RCIF = 1) //USART Receive Interrupt Flag bit test_interrupt(packet_buffer);
}

//***********************************************************
// MAIN
//***********************************************************
void main(void)
{
……
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Dec 17, 2004 3:41 am     Reply with quote

A number of problems.

Because you have tried to use a fast return from interrupt I am assuming you are using an 18F series PIC.

You do not need to install your own high priority interrupt handler via the vectors unless you have multiple high priority interrupts.
Code:
#int_rda FAST
void Int_Handler_High(void)
// .. rest of handler here
// if you are using the lastest compiler you do not need
// to add the following as this bug has been fixed
 #asm
retfie 1
#endasm


Your original code did a call and then a fast return from within the call. This would have broken the return stack (your program would crash). Make sure you do not call a function in the high priority interrupt handler that you also have called either in the mainline or the low priority handler.

Although I have implied you can use C code in the high priority interrupt handler, I am skeptical about doing so as you, not the compiler, are responsilbe for saving and restoring registers that could be changed by the high priority handler. Because the registers and memory locations used could change with each flavour (version) of the compiler this is a potential support nightmare. For this reason I suggest using assembler only in the high priority handler.

The following two lines do the same thing

Code:
packet_ptr[0] = c;

packet_ptr[i] = c;


There is no point in incrementing I as it is a local variable that is initialised to zero on entry and is not used after incremented. I suspect you ment to have i defined and initialised as a global variable elsewhere and you probably also intended the code to look like this:

Code:
if (c == START_STRING)
     i = 0;

packet_ptr[i] = c;
i++;

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Fri Dec 17, 2004 11:26 am     Reply with quote

Also, using arrays will require to save some registers. I think FSR's, but you should inspect the generated asm to find them.

If you search for my previous posts, you will see a lot of fast interrupt problems that are solved now.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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