DSPRelated.com
Forums

Help Regarding Circular Buffer in ASM....

Started by malli_1729 September 16, 2008
Hi!

Iam New to Assembly language Programming....Iam Just trying to learn it..
I want to implement a circular buffer in assembly language.......
I can't able to find the Implementaion details of Circular Buffer..i
mean in manuals i have seen info about I,B,L,M registers and Linear
addressing,Circular Addressing etc....
But i didn't found any psuedo code for that............

i can't able to implement a simple Circular buffer also.......For
ex..A Moving Average FIR filter

My problem is if i have a circular Buffer i can initialise the B,I,L,M
registers correspondingly..but i don't know whether the LOOP will
automatically continue or else we need to write the LOOP
explicitly........

I don't know whether i explained my problem clearly or not......if
can't understand i can explain more breifly...

THANK U..
WAITING FOR REPLY........
On Tue, 16 Sep 2008, malli_1729 wrote:

> Hi!
>
> Iam New to Assembly language Programming....Iam Just trying to learn it..
> I want to implement a circular buffer in assembly language.......
> I can't able to find the Implementaion details of Circular Buffer..i
> mean in manuals i have seen info about I,B,L,M registers and Linear
> addressing,Circular Addressing etc....
> But i didn't found any psuedo code for that............
>
> i can't able to implement a simple Circular buffer also.......For
> ex..A Moving Average FIR filter

Check out the applications books on ADI's web site:
http://www.analog.com/static/imported-files/processor_manuals_legacy/56546799ADSP_21000_Family_Applications_Handbook_Vol.1.0.pdf
http://www.analog.com/en/embedded-processing-dsp/blackfin/processors/code-examples/Blackfin_Code_Examples/resources/fca.html

>
> My problem is if i have a circular Buffer i can initialise the B,I,L,M
> registers correspondingly..but i don't know whether the LOOP will
> automatically continue or else we need to write the LOOP
> explicitly........

It needs to be expicit. Check out the code examples in the second link.
Good luck and have fun!

Patience, persistence, truth,
Dr. mike
Hi!
>
>Iam New to Assembly language Programming....Iam Just trying to learn it..
>I want to implement a circular buffer in assembly language.......
>I can't able to find the Implementaion details of Circular Buffer..i
>mean in manuals i have seen info about I,B,L,M registers and Linear
>addressing,Circular Addressing etc....
>But i didn't found any psuedo code for that............
>
>i can't able to implement a simple Circular buffer also.......For
>ex..A Moving Average FIR filter
>
>My problem is if i have a circular Buffer i can initialise the B,I,L,M
>registers correspondingly..but i don't know whether the LOOP will
>automatically continue or else we need to write the LOOP
>explicitly........
>
>I don't know whether i explained my problem clearly or not......if
>can't understand i can explain more breifly...
>
>THANK U..
>WAITING FOR REPLY........
>
Hi !

Iam just updating the message .......,
The Index register should be incremented explicitly.....I have just written a small example code but iam getting into Problems when iam running the code...
I just want to see how the Index register is increamenting for that only i have written this code
.section L1_data;

.byte2 in[] = 0x1,0x2,0x3,0x4;
.align 2;
.byte2 fil[] = 0x8,0x6,0x4,0x2;

.section program;

//I want to define 2 Circular Buffers one for IN and for Filter
.global _main;
_main:

p0.l = lo(in); //P0 Poionted to input
p0.h = hi(in);

p1.l = lo(fil); //P1 Poionted to Filter
p1.h = hi(fil);
i0 = p0; //Circular Buffer For input
b0 = p0;
l0 = 0x4;
m0 = 0x2;
//p1 += 4;
i1 = p1; //Circular Buffer For Filter
b1 = p1;
l1 = 0x4;
m1 = 0x2;
p3 = 0x8;
a0=0;
a1=0;
LSETUP(sss,eee) LC0 = p3;
sss: r1 = [I0++m0];
r2 = [I1++m0];
// r3 = r1.l *r2.l;
a0 += r1.l * r2.l,a1 += r1.h * r2.h;

-------------->>>>>>>>>>>> r1 = [I0++m0]; //Exception is coming
r2 = [I1++m1];
eee: a0 += r1.l * r2.l,a1 += r1.h * r2.h;
_main.end:

in this code iam getting a "unknown exception occured" exception at the line indicated....
what is the reason i don't know.....
any help...like may be there is any specialway to update the Index register or anyother
Hi,

The length register needs to be set to the number of bytes in your circular
bugger. You have 4 16bit words, so L0 and L1 need to be 8.

Look at the EXCAUSE field in the SEQSTAT register for a code that identifies
the type of exception. RETX will have the address of the instruction that
caused the exception.

We cover this and more in our 3.5 day Blackfin workshop. Check out our
website.

George Kadziolka

Kaztek Systems

www.kaztek.com

From: a... [mailto:a...] On Behalf Of
m...@yahoo.co.in
Sent: Wednesday, September 17, 2008 6:26 AM
To: a...
Subject: [adsp] Re: Help Regarding Circular Buffer in ASM....

Hi!
>
>Iam New to Assembly language Programming....Iam Just trying to learn it..
>I want to implement a circular buffer in assembly language.......
>I can't able to find the Implementaion details of Circular Buffer..i
>mean in manuals i have seen info about I,B,L,M registers and Linear
>addressing,Circular Addressing etc....
>But i didn't found any psuedo code for that............
>
>i can't able to implement a simple Circular buffer also.......For
>ex..A Moving Average FIR filter
>
>My problem is if i have a circular Buffer i can initialise the B,I,L,M
>registers correspondingly..but i don't know whether the LOOP will
>automatically continue or else we need to write the LOOP
>explicitly........
>
>I don't know whether i explained my problem clearly or not......if
>can't understand i can explain more breifly...
>
>THANK U..
>WAITING FOR REPLY........
>
Hi !

Iam just updating the message .......,
The Index register should be incremented explicitly.....I have just written
a small example code but iam getting into Problems when iam running the
code...
I just want to see how the Index register is increamenting for that only i
have written this code

.section L1_data;

.byte2 in[] = 0x1,0x2,0x3,0x4;
.align 2;
.byte2 fil[] = 0x8,0x6,0x4,0x2;

.section program;

//I want to define 2 Circular Buffers one for IN and for Filter
.global _main;
_main:

p0.l = lo(in); //P0 Poionted to input
p0.h = hi(in);

p1.l = lo(fil); //P1 Poionted to Filter
p1.h = hi(fil);

i0 = p0; //Circular Buffer For input
b0 = p0;
l0 = 0x4;
m0 = 0x2;
//p1 += 4;
i1 = p1; //Circular Buffer For Filter
b1 = p1;
l1 = 0x4;
m1 = 0x2;
p3 = 0x8;
a0=0;
a1=0;
LSETUP(sss,eee) LC0 = p3;
sss: r1 = [I0++m0];
r2 = [I1++m0];
// r3 = r1.l *r2.l;
a0 += r1.l * r2.l,a1 += r1.h * r2.h;

-------------->>>>>>>>>>>> r1 = [I0++m0]; //Exception is coming
r2 = [I1++m1];
eee: a0 += r1.l * r2.l,a1 += r1.h * r2.h;
_main.end:

in this code iam getting a "unknown exception occured" exception at the line
indicated....
what is the reason i don't know.....
any help...like may be there is any specialway to update the Index register
or anyother
Hi,

i am having one basic doubt. Suppose if
we have filter tap length ‘nh’ &

no.of samples are ‘nr’ then according to
convolution operation we’ll get

nr+nh-1 outputs. Filter is nothing but
convolution of samples and filter

kernel.

 

Can u see this filter code, which I have
taken from TI’s DSP library

document (spru565a pdg.no 86)

 

x[nr+nh–1] Pointer to input array of
size nr + nh – 1.

h[nh] Pointer to coefficient array of
size nh.

r[nr] Pointer to output array of size
nr. Must be word aligned.

nh Number of coefficients. Must be =5.

nr Number of samples to calculate. Must
be a multiple of 4.

 

void DSP_fir_gen(short x[ ], short h[ ],
short r[ ],

int nh, int nr)

{

int i, j, sum;

for (j = 0; j < nr; j++)

{

sum = 0;

for (i = 0; i < nh; i++)

sum += x[i + j] * h[i];

r[j] = sum >> 15;

}

}

Suppose if we configure two ping-pong
buffers, (while mcbsp (or sport) fills one buffer , another buffer can be used
for filtering) for realtime filtering , how can use this filter code.

I mean while shifting from one buffer
to  another buffer  you need to have (filter tap length -1)
history elements  to compute current
output.

Consider this example.

Suppose filter length (nr) is 50.

Required numbers of output samples are
100, then I should pass input array of elements (100+50-1=149).  So I can configure my buffer length 149.

Now my question is while shifting from
first buffer to second buffer we need to copy some number of elements  from first buffer to starting location of
second buffer.

(I think 
we need to copy last (nr-1) elements starting location of your second
buffer)

In that case which location I should
point my input to filter. Can any one help in this regard.

Thanks in Adavance

SVS

Hello SVS,

There are a couple ways to attack this. One is to use a circular buffer
and call the filter for each new sample. For a ping pong, you want to
start the next block at nh+1 into the sample buffer.

Note that the number of input samples is nh + nr - 1. Each output sample
comes from nh samples of input data. So if you have a circular buffer
that is greater than nh samples, you can compute an output sample based on
where the last input came in. The last input marks the end of the sample
buffer - so you start nh samples before that and compute the filter using
circular addressing. The nice thing with that is you don't have to reset
any of the coefficient pointers, they just circle back to the start.

I think it will make more sense if you draw a picture of memory. Then it
will be obvious where the start of the second buffer is as well as the
overlap of the second into the first. A large circular buffer will be
useful for that too.

Patience, persistence, truth,
Dr. mike
On Wed, 24 Sep 2008, rama raju wrote:

>
> Hi,
>
> i am having one basic doubt. Suppose if
> we have filter tap length ‘nh’ &
>
> no.of samples are ‘nr’ then according to
> convolution operation we’ll get
>
> nr+nh-1 outputs. Filter is nothing but
> convolution of samples and filter
>
> kernel.
>
>  
>
> Can u see this filter code, which I have
> taken from TI’s DSP library
>
> document (spru565a pdg.no 86)
>
>  
>
> x[nr+nh–1] Pointer to input array of
> size nr + nh – 1.
>
> h[nh] Pointer to coefficient array of
> size nh.
>
> r[nr] Pointer to output array of size
> nr. Must be word aligned.
>
> nh Number of coefficients. Must be =5.
>
> nr Number of samples to calculate. Must
> be a multiple of 4.
>
>  
>
> void DSP_fir_gen(short x[ ], short h[ ],
> short r[ ],
>
> int nh, int nr)
>
> {
>
> int i, j, sum;
>
> for (j = 0; j < nr; j++)
>
> {
>
> sum = 0;
>
> for (i = 0; i < nh; i++)
>
> sum += x[i + j] * h[i];
>
> r[j] = sum >> 15;
>
> }
>
> }
>
> Suppose if we configure two ping-pong
> buffers, (while mcbsp (or sport) fills one buffer , another buffer can be used
> for filtering) for realtime filtering , how can use this filter code.
>
> I mean while shifting from one buffer
> to  another buffer  you need to have (filter tap length -1)
> history elements  to compute current
> output.
>
> Consider this example.
>
> Suppose filter length (nr) is 50.
>
> Required numbers of output samples are
> 100, then I should pass input array of elements (100+50-1=149).  So I can configure my buffer length 149.
>
> Now my question is while shifting from
> first buffer to second buffer we need to copy some number of elements  from first buffer to starting location of
> second buffer.
>
> (I think 
> we need to copy last (nr-1) elements starting location of your second
> buffer)
>
> In that case which location I should
> point my input to filter. Can any one help in this regard.
>
> Thanks in Adavance
>
> SVS