Collecting UART received data inside the interrupt

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Keerthy_V
Moderator
Moderator
Moderator
First like given 250 sign-ins 50 solutions authored

 Hi,

   

 

   

Attached code demonstrates how to take the recived data inside UART ISR. Following steps needs to be performed on PD 5.3 for the same.

   

 

   

1. Create a custom UART user module. For that select Tools->User Module Customization Wizard. Select the User module and press Copy. Once the custom user module is created open the template of UARTINT.asm file from the folder where the module is stored.

   

 

   

2. Paste the following marker area just before the reti instruction that is present in the end of UARTINT.asm template file.

   

 

   

 

   

;@PSoC_UserCode_BODY_3@ (Do not change this line.)

   

   ;---------------------------------------------------

   

   ; Insert your custom assembly code below this banner

   

   ;---------------------------------------------------

   

   ;   NOTE: interrupt service routines must preserve

   

   ;   the values of the A and X CPU registers.

   

   

   

   ;---------------------------------------------------

   

   ; Insert your custom assembly code above this banner

   

   ;---------------------------------------------------

   

   

   

   ;---------------------------------------------------

   

   ; Insert a lcall to a C function below this banner

   

   ; and un-comment the lines between these banners

   

   ;---------------------------------------------------

   

   

   

   ;PRESERVE_CPU_CONTEXT

   

   ;lcall _My_C_Function

   

   ;RESTORE_CPU_CONTEXT

   

   

   

   ;---------------------------------------------------

   

   ; Insert a lcall to a C function above this banner

   

   ; and un-comment the lines between these banners

   

   ;---------------------------------------------------

   

   ;@PSoC_UserCode_END@ (Do not change this line.)

   

 

   

3. Place the custom user module,Build the project and open UARTINT.asm file.

   

4. Uncomment the lines 

   

   PRESERVE_CPU_CONTEXT

   

   lcall _My_C_Function

   

   RESTORE_CPU_CONTEXT

   

5. Define the function My_C_Function in the main.c and read the received data inside the function.

   

Please find attached project for your convenience. Thank you. 

   

 

   

Regards,

   

Keerthy

0 Likes
6 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked
        No project attached, use ms internet explorer when attaching a file. Additionally: Regard the leading underscore of the routine-name only in the .asm-file. Bob (with a small window again)   
0 Likes
lock attach
Attachments are accessible only for community members.
Keerthy_V
Moderator
Moderator
Moderator
First like given 250 sign-ins 50 solutions authored
        Bob, Attached is the project. Regards, Keerthy   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

A method that can save some of the precious stack and CPU-usage is:

   

Declare your interrupt handler with the #pragma directive

   

Do not uncomment the PRESERVE and RESTORE-macros

   

Do not "LCALL" your handler, but insert a "LJMP _My_C_Function"

   

Within the handler My_C_Function() avoid calling any other functions.

   

 

   

This way your handler is an interrupt routine itself and the compiler will push only the needed data onto the stack which can increase performance.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Certainly using "ljmp" with #pragma directive has the advantages of stack-save and reduction in ISR execution time.

   

 

   

But one situation where we may have to use "lcall" is possibly this:

   

A few user module interrupt asm files of PSoC Designer have some code even after the user code marker area.

   

In such files, we may have to use "lcall"(along with preserve/restore of CPU registers) when calling routines defined in C.

   

This is because "ljmp" would result in jumping straight out of the interrupt after the C routine(due to the "reti" instruction placed the #pragma interrupt handler), and this would mean that the code following the "ljmp" in the user module asm file would not be executed, leading to unexpected operation of the user module.

   

Examples of files where there is code even after the user code marker area: ADCINCVR's interrupt asm file, UART's interrupt asm file when "Rx command buffer" is enabled etc.

   

 

   

Thanks & Regards,

   

Prem Sai

0 Likes
SampathS_11
Moderator
Moderator
Moderator
250 sign-ins 250 solutions authored 5 questions asked

 This is a method of altering the behaviour of an ISR. This is done by calling another function from within the User Module ISR.  The function that is called from within an ISR need not be an interrupt handler.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

A bit late that last post, but...

   

When you call another routine from within your interrupt handler, the Image>Craft-Compiler is not able to evaluate which registers are used from within that routine. So at entry into the handler all registers will be pushed onto the (small) stack consuming MIPS and RAM.

   

 

   

Bob

0 Likes