I wrote an assembly function which is called by a task in DSP/BIOS. I also have HWI from McASP enabled. I wrote HWI handler in C and I'm using HWI dispatcher. I noticed that there is some stack corruption which is caused by interrupt. I found out that this error happens when I am using stack in assembly function like this: STDW .D2T1 A27:A26,*--B15[1] STDW .D2T1 A29:A28,*--B15[1] STDW .D2T1 A31:A30,*--B15[1] ;assembly function body LDDW .D2T1 *B15++[1],A31:A30LDDW .D2T1 *B15++[1],A29:A28LDDW .D2T1 *B15++[1],A27:A26 When I'm disabling interrupts during LDDW from stack there are no errors when I've changed stack operations like this: ADDK -32,B15 STDW .D2T1 A27:A26,*+B15(8) STDW .D2T1 A29:A28,*+B15(16) STDW .D2T1 A31:A30,*+B15(24 ;assembly function body LDDW .D2T1 *+B15(24),A31:A30 LDDW .D2T1 *+B15(16),A29:A28 LDDW .D2T1 *+B15(8),A27:A26 ADDK 32,B15 There are no errors in that case. Is there some straightforward explanation for that? What is wrong with gradual stack incrementation at the end of asm function (that's where error occurs).
So when does the assembly function get called? Does your HWI handler make a call to your assembly function?
---------------------------------------------------------------------------------------------------------
Please click the Verify Answer button on this post if it answers your question.---------------------------------------------------------------------------------------------------------
Sorry for being imprecise.
HWI function is written in C. It's handled by HWI dispatcher. HWI is an interrupt from McASP so it's triggered based on sampling rate (96kHz). In my application I have also task which calls assembler function and this assembler function handles stack in two ways as i discribed previously.
My task is in forever loop so it runs and is interrupted by HWI after a while there is stack corruption when method 1 is used for stack handling.
Let me make sure I understand the scenario. The assembly function you mentioned is only being called from within the task, right? When you say there is stack corruption, are you referring to corruption of the system stack or of the task stack?
I mean the corruption of task stack.
Ah, I think I see it now. I just looked at the compiler guide:
spru187n page 170 Even though the compiler guarantees a doubleword alignment of the stack and the stackpointer (SP) points to the next free location in the stack space, there is only enoughguaranteed room to store one 32-bit word at that location. The called function mustallocate space to store the doubleword.
Even though the compiler guarantees a doubleword alignment of the stack and the stackpointer (SP) points to the next free location in the stack space, there is only enoughguaranteed room to store one 32-bit word at that location. The called function mustallocate space to store the doubleword.
The processor is expecting to be able to write to whatever location is pointed to by B15. You are doing the PUSH using a pre-decrement. Therefore B15 is not pointing to the next FREE location, but rather to the last used location. When you get interrupted the HWI is going to blow away whatever is at the location being pointed to.
In the case where you did decremented the stack by 32 bytes, you filled up 24 of those bytes. Therefore B15 was pointing to an unused location which is the correct usage of the stack.
Side note -- why are you preserving registers A26-A31? Those are "save on call" registers as shown in Section 8.3 of that same doc. Therefore those functions would be saved by the C function calling your assembly function and you are free to use them without preserving them.
Brad
A few additional thoughts:
So really the only option is to do it with adding/subtracting a fixed offset, which happens to be exactly how the compiler guide says to do it...