Forums

Assembly Help with ADSP-TS201

Started by jjli...@hotmail.com August 27, 2008
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
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
"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
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
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
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.
On Aug 29, 11:51&#2013266080;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) > > { > > &#2013266080; irq3_ran = 1; > > } > > > void main(void) > > { > > &#2013266080; interruptf(SIGIRQ3, my_isr); > > &#2013266080; ... > > &#2013266080; while (1); > > &#2013266080; { > > &#2013266080; &#2013266080; if (irq3_ran) > &#2013266080;> &#2013266080; &#2013266080; { > > &#2013266080; &#2013266080; &#2013266080; irq3_ran = 0; > > &#2013266080; &#2013266080; &#2013266080; do_whatever(); > &#2013266080;> &#2013266080; &#2013266080; } > > &#2013266080; } > > } > > -- > Jim Thomas &#2013266080; &#2013266080; &#2013266080; &#2013266080; &#2013266080; &#2013266080;Principal Applications Engineer &#2013266080;Bittware, Inc > jtho...@bittware.com &#2013266080;http://www.bittware.com&#2013266080; &#2013266080;(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