Assembly Help with ADSP-TS201

This is a discussion on Assembly Help with ADSP-TS201 within the DSP forums in Other Technologies category; Hello, I'm having a problem with some Assembly code for the ADSP- TS201. When I step through the code it seems to work, but if I let the processor run it enters the function but doesn't return back in the proper instruction. Here is my code: // Poll_IRQ(int IRQx) // for example: Poll_IRQ(INT_IRQ3_P) void Poll_IRQ(int IRQx) { /* clear interrupt request */ asm ( "#include<defts201.h>;; "); asm ( "Poll_IRQ: xr0 = ILATH;; "); asm ( " xr1 = J4;; "); asm ( " bitest r0 by r1;; "); asm ( " if XSEQ, jump Poll_IRQ;; "); // loop until this ...

Go Back   Application Development Forum > Other Technologies > DSP

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 08:01 PM
jjlindula@hotmail.com
Guest
 
Default Assembly Help with ADSP-TS201

Hello, I'm having a problem with some Assembly code for the ADSP-
TS201. When I step through the code it seems to work, but if I let the
processor run it enters the function but doesn't return back in the
proper instruction.

Here is my code:

// Poll_IRQ(int IRQx)
// for example: Poll_IRQ(INT_IRQ3_P)

void Poll_IRQ(int IRQx)
{
/* clear interrupt request */
asm ( "#include<defts201.h>;; ");
asm ( "Poll_IRQ: xr0 = ILATH;; ");
asm ( " xr1 =
J4;; ");
asm ( " bitest r0 by r1;; ");
asm ( " if XSEQ, jump Poll_IRQ;; "); // loop
until this bit is set
asm ( " nop;nop;nop;; ");
asm ( " xr0 = bclr r0 by r1;; ");
asm ( " ILATCLH = xr0;; "); // clear Interrupt n bit
asm ( " nop;nop;nop;; ");



IRQx++;

}

If anyone is an Assembly guru with the TS201 and see's my problem,
please let me know.

Thanks,
joe
Reply With Quote
  #2  
Old 08-28-2008, 03:28 PM
Darol Klawetter
Guest
 
Default Re: Assembly Help with ADSP-TS201

On Aug 27, 7:01 pm, "jjlind...@hotmail.com" <jjlind...@hotmail.com>
wrote:
> Hello, I'm having a problem with some Assembly code for the ADSP-
> TS201. When I step through the code it seems to work, but if I let the
> processor run it enters the function but doesn't return back in the
> proper instruction.
>
> Here is my code:
>
> // Poll_IRQ(int IRQx)
> // for example: Poll_IRQ(INT_IRQ3_P)
>
> void Poll_IRQ(int IRQx)
> {
> /* clear interrupt request */
> asm ( "#include<defts201.h>;; ");
> asm ( "Poll_IRQ: xr0 = ILATH;; ");
> asm ( " xr1 =
> J4;; ");
> asm ( " bitest r0 by r1;; ");
> asm ( " if XSEQ, jump Poll_IRQ;; "); // loop
> until this bit is set
> asm ( " nop;nop;nop;; ");
> asm ( " xr0 = bclr r0 by r1;; ");
> asm ( " ILATCLH = xr0;; "); // clear Interrupt n bit
> asm ( " nop;nop;nop;; ");
>
> IRQx++;
>
> }
>
> If anyone is an Assembly guru with the TS201 and see's my problem,
> please let me know.
>
> Thanks,
> joe


Hi Joe,

I haven't used the TS201, but I've noticed that you're accessing some
of the processor registers in your assembly code. If those registers
are being used by the C-compiler, then you corrupting them. Generally,
you should "push" register values to the stack at the beginning of the
assembly code and then "pop" them off the stack afterwards to restore
the original values.

Darol Klawetter

Reply With Quote
  #3  
Old 08-28-2008, 08:30 PM
Randy Yates
Guest
 
Default Re: Assembly Help with ADSP-TS201

"jjlindula@hotmail.com" <jjlindula@hotmail.com> writes:

> Hello, I'm having a problem with some Assembly code for the ADSP-
> TS201. When I step through the code it seems to work, but if I let the
> processor run it enters the function but doesn't return back in the
> proper instruction.
>
> Here is my code:
>
> // Poll_IRQ(int IRQx)
> // for example: Poll_IRQ(INT_IRQ3_P)
>
> void Poll_IRQ(int IRQx)
> {
> /* clear interrupt request */
> asm ( "#include<defts201.h>;; ");
> asm ( "Poll_IRQ: xr0 = ILATH;; ");
> asm ( " xr1 =
> J4;; ");
> asm ( " bitest r0 by r1;; ");
> asm ( " if XSEQ, jump Poll_IRQ;; "); // loop
> until this bit is set
> asm ( " nop;nop;nop;; ");
> asm ( " xr0 = bclr r0 by r1;; ");
> asm ( " ILATCLH = xr0;; "); // clear Interrupt n bit
> asm ( " nop;nop;nop;; ");
>
>
>
> IRQx++;
>
> }
>
> If anyone is an Assembly guru with the TS201 and see's my problem,
> please let me know.


In addition to the problem with hosing registers xr0 and xr1 that Darol
pointed out, why do you think J4 has any meaningful state? It is also a
"scratch" register that could be used in any manner by compiler in
the parent C function.
--
% Randy Yates % "So now it's getting late,
%% Fuquay-Varina, NC % and those who hesitate
%%% 919-577-9882 % got no one..."
%%%% <yates@ieee.org> % 'Waterfall', *Face The Music*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #4  
Old 08-28-2008, 08:39 PM
Randy Yates
Guest
 
Default Re: Assembly Help with ADSP-TS201

Randy Yates <yates@ieee.org> writes:
> [...]
> why do you think J4 has any meaningful state?


Nevermind! I just realized j4 is the the first passed argument if the
type is int.

But..., have you considered the possibility that you're simply not
getting the interrupt you're polling for?
--
% Randy Yates % "Rollin' and riding and slippin' and
%% Fuquay-Varina, NC % sliding, it's magic."
%%% 919-577-9882 %
%%%% <yates@ieee.org> % 'Living' Thing', *A New World Record*, ELO
http://www.digitalsignallabs.com
Reply With Quote
  #5  
Old 08-29-2008, 09:27 AM
Jim Thomas
Guest
 
Default Re: Assembly Help with ADSP-TS201

Darol Klawetter wrote:
> On Aug 27, 7:01 pm, "jjlind...@hotmail.com" <jjlind...@hotmail.com>
> wrote:
>> Hello, I'm having a problem with some Assembly code for the ADSP-
>> TS201. When I step through the code it seems to work, but if I let the
>> processor run it enters the function but doesn't return back in the
>> proper instruction.
>>
>> Here is my code:
>>
>> // Poll_IRQ(int IRQx)
>> // for example: Poll_IRQ(INT_IRQ3_P)
>>
>> void Poll_IRQ(int IRQx)
>> {
>> /* clear interrupt request */
>> asm ( "#include<defts201.h>;; ");
>> asm ( "Poll_IRQ: xr0 = ILATH;; ");
>> asm ( " xr1 =
>> J4;; ");
>> asm ( " bitest r0 by r1;; ");
>> asm ( " if XSEQ, jump Poll_IRQ;; "); // loop
>> until this bit is set
>> asm ( " nop;nop;nop;; ");
>> asm ( " xr0 = bclr r0 by r1;; ");
>> asm ( " ILATCLH = xr0;; "); // clear Interrupt n bit
>> asm ( " nop;nop;nop;; ");
>>
>> IRQx++;
>>
>> }
>>
>> If anyone is an Assembly guru with the TS201 and see's my problem,
>> please let me know.
>>
>> Thanks,
>> joe

>
> Hi Joe,
>
> I haven't used the TS201, but I've noticed that you're accessing some
> of the processor registers in your assembly code. If those registers
> are being used by the C-compiler, then you corrupting them. Generally,
> you should "push" register values to the stack at the beginning of the
> assembly code and then "pop" them off the stack afterwards to restore
> the original values.
>
> Darol Klawetter
>


Also, you might be well served by looking at the __builtin_sysreg_read()
hook. That way you can leave the assembly behind and do all your work
in C, something like this (untested) code fragment:

void poll_irq(int irq)
do
{
int ilath;

ilath = __builtin_sysreg_read(__ILATH);
} while ((ilath & irq) == 0);

But a better question is... why don't you just install an interrupt
handler? You should probably not be clearing ILATH either. An isr with
an RTI will do that for you. Interrupts can be hard sometimes, but
there are probably a lot easier than what you're attempting here. I
recommend you use them as they were intended. If you really want to
poll, try something like this:

#include <signal.h>
#include <sysreg.h>
#include <defts201.h>

static int irq3_ran = 0;
void my_isr(int sig)
{
irq3_ran = 1;
}

void main(void)
{
interruptf(SIGIRQ3, my_isr);
...
while (!irq3_ran)
{
irq3_ran = 0;
do_whatever();
}
}

--
Jim Thomas Principal Applications Engineer Bittware, Inc
jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536
A pessimist is an optimist with experience
Reply With Quote
  #6  
Old 08-29-2008, 02:51 PM
Jim Thomas
Guest
 
Default Re: Assembly Help with ADSP-TS201

Jim Thomas wrote:

Code corrections:

> #include <signal.h>
> #include <sysreg.h>
> #include <defts201.h>
>
> static int irq3_ran = 0;
> void my_isr(int sig)
> {
> irq3_ran = 1;
> }
>
> void main(void)
> {
> interruptf(SIGIRQ3, my_isr);
> ...
> while (1);
> {
> if (irq3_ran)
> {
> irq3_ran = 0;
> do_whatever();
> }
> }
> }
>



--
Jim Thomas Principal Applications Engineer Bittware, Inc
jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536
Visualize whirled peas.
Reply With Quote
  #7  
Old 09-03-2008, 09:58 AM
jjlindula@hotmail.com
Guest
 
Default Re: Assembly Help with ADSP-TS201

On Aug 29, 11:51*am, Jim Thomas <jtho...@bittware.com> wrote:
> Jim Thomas wrote:
>
> Code corrections:
>
>
>
>
>
> > #include <signal.h>
> > #include <sysreg.h>
> > #include <defts201.h>

>
> > static int irq3_ran = 0;
> > void my_isr(int sig)
> > {
> > * irq3_ran = 1;
> > }

>
> > void main(void)
> > {
> > * interruptf(SIGIRQ3, my_isr);
> > * ...
> > * while (1);
> > * {
> > * * if (irq3_ran)

> *> * * {
> > * * * irq3_ran = 0;
> > * * * do_whatever();

> *> * * }
> > * }
> > }

>
> --
> Jim Thomas * * * * * *Principal Applications Engineer *Bittware, Inc
> jtho...@bittware.com *http://www.bittware.com* *(603) 226-0404 x536
> Visualize whirled peas.


Hello all, thank you for responding to my post. I've made an attempt
to fix the function:

void Poll_IRQ(unsigned int IRQ)
{


// clear interrupt request
asm volatile ("#include<defts201.h>;;"
"Poll_IRQ: "\
"\n\txr0 = ILATH;; "
"xr1 = %0;; "
"_PollIRQ: xr2 = ILATH;;"
"bitest r2 by r1;; "
"if xseq, jump _PollIRQ;"
" nop;nop;nop;;"
"xr0 = bclr r0 by r1;;"
"ILATCLH = xr0;;"

: // no outputs

: "j" (IRQ)

: "xr1", // clobbers:
"xr0", // clobbers:
"xr2", // clobbers:
"xstat"); // clobbers:






IRQ++;
IRQ--;
}

I seems to work with errors but I like the idea of using the builtins
functions.

Thanks everyone!

joe
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:09 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.