Calling a C Function from an Interrupt

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

Calling a C Function from an Interrupt

Postby petepoff on Thu Apr 13, 2006 12:32 pm

Can any one post a code example for calling a C function from an interrupt, i.e. timer16_1int.asm? Thanks!
petepoff
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 10
Joined: Mon Aug 01, 2005 12:33 pm

Re: Calling a C Function from an Interrupt

Postby ravo on Thu Apr 13, 2006 9:23 pm

petepoff wrote:Can any one post a code example for calling a C function from an interrupt, i.e. timer16_1int.asm? Thanks!


Hi, it is simple to do it. You must put small code in ASM ( call C function )
In UM ( user module ) interrupt ASM file ( *INT.ASM - for ex.: Counter8_1INT.asm ):
Code: Select all
_UM_ISR: // for example "_Counter8_1_ISR:"
   ;@PSoC_UserCode_BODY@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom code below this banner
   ;---------------------------------------------------
   ;   NOTE: interrupt service routines must preserve
   ;   the values of the A and X CPU registers.

   ljmp _Counter_INT

   ;---------------------------------------------------
   ; Insert your custom code above this banner
   ;---------------------------------------------------
   ;@PSoC_UserCode_END@ (Do not change this line.)

In your main.c, also I must note that you must enable interrupt
with macro M8C_EnableGInt + enable interrupt for the specific UM
The function interrupt routine is here
Code: Select all
#pragma interrupt_handler Counter_INT
void Counter_INT(void)
   {
   // your interrupt routine

   }

I think this will help you,
regards
Radim
User avatar
ravo
The Big Cheese
The Big Cheese
 
Posts: 204
Joined: Thu Oct 21, 2004 2:58 am
Location: Czech rep.

Postby mysorenarayan on Mon Apr 17, 2006 5:08 am

Or just add the following line in main.c

Code: Select all
#pragma interrupt_handler Timer16_1_ISR


The compiler will make sure that the ISR routine written in "C" is excuted instead of "asm". By the by, don't use this method for GPIO interrupts, use the one suggested by Radim.

Regards
NS
User avatar
mysorenarayan
Cheese Wheel
Cheese Wheel
 
Posts: 71
Joined: Mon May 24, 2004 6:30 am
Location: Mysore, India

Postby alager on Mon Apr 17, 2006 2:46 pm

Also make sure that if you follow mysorenarayan's advice you also edit the boot.tpl to make sure that the correct interrupt vector calls your C ISR function.

Code: Select all
   org   24h                      ;PSoC Block DBB01 Interrupt Vector
//    `@INTERRUPT_9`
   ljmp _PeriodicHandler
    reti



Aaron
User avatar
alager
The Big Cheese
The Big Cheese
 
Posts: 506
Joined: Tue Mar 15, 2005 2:26 pm
Location: Peteluma, CA

Postby mysorenarayan on Mon Apr 17, 2006 5:17 pm

Aaron,

I think we need not modify the boot.tpl (except in the case of GPIO interrupt). The only catch here is that you've to name the "C" interrupt as I've suggested. ie., <ModuleName>_ISR in main.c.

If the compiler finds a #pragma interrupt_handler <> directive with the same name as assembly ISR, the assembly code is ignored.

Do check the .lst file generated.

Regards
NS
User avatar
mysorenarayan
Cheese Wheel
Cheese Wheel
 
Posts: 71
Joined: Mon May 24, 2004 6:30 am
Location: Mysore, India


Return to PSoC1 General

Who is online

Users browsing this forum: No registered users and 0 guests