6 Replies Latest reply on May 16, 2011 9:32 PM by graa

    lcall

    user_4896474

      Hallo,

         

      sometime ago after updating from PSOC designer 5.0 -> PSOC designer 5.1 I noticed that inside xxxINT.asm source (along interrupt ISR routine 'caller') there was an hint suggesting to use lcall and a couple of macro to execyte the actual user interrupt handler routine (for devices such as UARTs or COUNTERS). I tried using this code but I had big problems (i.e. the interrupt routine was not called at all) maybe this suggestion is only valid for asm coding while I was defining the interrupt routines in C language. Is this right?

        • 1. Re: lcall
          graa

          The lcall to a function is not limited to C functions.  You can also call your assembly functions using this method.  When you call C functions, you add an underscore before the function name.  For example, if you have a C function named "MyFunction", you would use "lcall _MyFunction".  Whereas when you call an assembly function, there is no need to add an underscore.

             

           

             

          The reason why the interrupt never gets executed may be because the interrupt is not enabled.  Can you provide the code that does not work?

             

           

             

          Best Regards,

             

          Ganesh

             

          The PSoC Hacker

          • 2. Re: lcall
            user_4896474

            Before the 5.1 update I was already using xjmp to 'call' the C interrupt routine (and I was already prepending the _ on the C function). I checked the code more than once and everything seemed to be ok (of course using xjmp everything worked). Of course I can try again to verify if the problem have been solved and post the code if not.

            • 3. Re: lcall
              user_4896474

              Please consider that I'm using the directive #pragma interrupt_handler signature before C function declaration. May this interfere with lcall and related macros?

              • 4. Re: lcall
                graa

                If you are using the #pragma interrupt handler directive, then you should not use the lcall, instead you should use the ljmp.  The compiler terminates the function with a reti if it is declared as interrupt handler.  if you call this function with lcall and if the function terminates with reti, that will corrupt the stack.  So, if you use lcall, do not declare the function as interrupt handler, or if you declare the function as interrupt handler, use the ljmp instead of lcall.

                Also, if you are going to use lcall to call the function from inside the ISR, use the PRESERVE_CPU_CONTEXT and RESTORE_CPU_CONTEXT macros before and after the lcall.  These macros will preserve all the paging and virtual registers and restore them.  For example, if you have a C function called MyFunction, and you are calling this from a counter ISR.  Then use the below code inside the user code area in the ISR.

                PRESERVE_CPU_CONTEXT
                lcall _MyFunction
                RESTORE_CPU_CONTEXT

                Best Regards,
                Ganesh
                The PSoC Hacker

                • 5. Re: lcall
                  user_4896474

                  What's the benefit from using lcall and stop using xjmp and  #pragma directive?

                  • 6. Re: lcall
                    graa

                    The lcall method takes more CPU cycles than the #pragma interrupt handler as the function has to first return using the ret instruction and then the interrupt returns using the reti instruction.  In case of the #pragma interrupt handler method, the interrupt returns directly from the function itself.

                       

                     

                       

                    Best Regards,

                       

                    Ganesh