DSPRelated.com
Forums

Using C-declared Variables in Assembly Code

Started by emespina September 29, 2007
Hi,

I'm currently working on a project on the 56F8013 DSP. I have
implemented all my codes in C to make code sharing and maintenance
easier.

However, I would like to use Fast Interrupts and only Assemble codes
are allowed within the ISR.

My problem now is how to access the variables that I have declared in C
within the ISR. I have started to go thru the documentations to see
how this is done. But, any leads will be greatly appreciated!

Regards,
Evan
You must define the variables are the globe varliables

#define ADC_Addr 0xf080
#define PWM_Addr 0xf040

asm void ISR_ADC_End_of_Scan(void);

int gVar = 100;

void main(void)
{
/* Write your local variable definition here */
int Var =5;
PE_low_level_init();
asm
{
move.w gVar, Y0;
move.w Var, X0;
move.w X0, gVar;
}

/************************************/
/* Initialize fast interrupt reg */
/************************************/

asm (swap SHADOWS);
asm (moveu.w #ADC_Addr,R0); //Initialize ADC address
asm (moveu.w #(PWM_Addr+6),R1); //Initialize PWM
value reg address
asm (moveu.w #0x0,N);
asm (moveu.w #0xffff,M01);
asm (swap SHADOWS);

/* Write your code here */

for(;;) {}

}

//#pragma interrupt alignsp
//#pragma optimization_level 4
asm void ISR_Fast_ADC_End_of_Scan(void)
{

// setRegBits(ADC_ADSTAT,2048); /* Clear EOSI flag */

bfset #0x0800,X:(R0+6) /* Clear EOSI flag */

/*Assembly Example*/
move.w gVar, Y0;
move.w X0, gVar;

frtid //fast interrupt return with Delay
move.w x:(R1)+,y0 //update PWM0 duty cycle
move.w x:(R1)-,y0 //update PWM1 duty cycle

/* Add illegal instruction for debugging trick to
flag improper execution */
illegal
}
--- emespina wrote:

> Hi,
>
> I'm currently working on a project on the 56F8013
> DSP. I have
> implemented all my codes in C to make code sharing
> and maintenance
> easier.
>
> However, I would like to use Fast Interrupts and
> only Assemble codes
> are allowed within the ISR.
>
> My problem now is how to access the variables that I
> have declared in C
> within the ISR. I have started to go thru the
> documentations to see
> how this is done. But, any leads will be greatly
> appreciated!
>
> Regards,
> Evan