how to implement in "Ansi C" a circular buffer with the TMS320F2812? thanks,
how to implement a circular buffer with the TMS320F2812 ?
Started by ●April 13, 2004
Reply by ●April 13, 20042004-04-13
On 13 Apr 2004 05:01:44 -0700, Massimo S, <sebastiani.m@tin.it> wrote:> how to implement in "Ansi C" a circular buffer with the TMS320F2812? > > thanks,You mean something like: { int buffer(1024) /* Code that does something FASCANATING */ if i >1024 i = 0; } But you'd be advised to see if the 'F2812 has any hardware support for circular buffers. I know their 'C3x, 'C4x, and 'C6x architectures all do.
Reply by ●April 13, 20042004-04-13
Massimo S, wrote:> how to implement in "Ansi C" a circular buffer with the TMS320F2812? > > thanks,If you want portable ANSI C, you can do something like : buf[ i & 1023 ] Although without hw support for circular buffers, it'll probably be faster to have two loops, rather than playing modulus/bitwise tricks. Here's an example off the top of my head of ANSI C circular buffering without any modulus or bitwise ops ( Disclaimer: this hasn't been tested, or even compiled ) void fir_filt( float * dst, const float * src, int nsrc, const float * h, int nh, float * cbuf, int * icbuf) { int k; while ( nsrc-- > 0 ) { const float * htmp = h; if ( --(*icbuf) < 0 ) *icbuf = nh-1; cbuf[*icbuf] = *src++; *dst = 0; // This loop handles from the current pos to end of circ buf for ( k = *icbuf ; k < nh ; ++k ) { *dst += cbuf[k] * *htmp++; } // This loop handles from beg. of circ buf to current pos. for ( k=0 ; k < *icbuf ; ++k ) { *dst += cbuf[k] * *htmp++; } ++dst; // Note that htmp is accessed sequentially from 0 to nh-1 // While cbuf is acessed from *icbuf to nh-1, then 0 to *icbuf-1 } }
Reply by ●April 13, 20042004-04-13
Massimo S, wrote:> how to implement in "Ansi C" a circular buffer with the TMS320F2812? > > thanks,ANSI C has no support for hardware circular buffers. You'll need to check your Code Composter documentation to see if they provide a (non-ANSI) one. Just write the assembly -- it's more fun. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●April 13, 20042004-04-13
Tim Wescott <tim@wescottnospamdesign.com> writes:> Massimo S, wrote: > >> how to implement in "Ansi C" a circular buffer with the TMS320F2812? >> thanks, > > ANSI C has no support for hardware circular buffers. You'll need to > check your Code Composter documentation to see if they provide a > (non-ANSI) one. > > Just write the assembly -- it's more fun.Really. "But I wanna write machine-specific C code so it's portable" ... -- % Randy Yates % "Maybe one day I'll feel her cold embrace, %% Fuquay-Varina, NC % and kiss her interface, %%% 919-577-9882 % til then, I'll leave her alone." %%%% <yates@ieee.org> % 'Yours Truly, 2095', *Time*, ELO http://home.earthlink.net/~yatescr
Reply by ●April 13, 20042004-04-13
On 13 Apr 2004 05:01:44 -0700, sebastiani.m@tin.it (Massimo S,) wrote in comp.dsp:> how to implement in "Ansi C" a circular buffer with the TMS320F2812? > > thanks,If your buffer size is a power of 2, Code Composer for the 2812 optimizes away the module operations to bit-wise ANDs even when optimization is not turned on, so: something = x [count++]; count %= 1024; The second line will be turned into a single operation to AND count with 1023 (0x3ff). -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Reply by ●April 14, 20042004-04-14
Jack Klein wrote:> On 13 Apr 2004 05:01:44 -0700, sebastiani.m@tin.it (Massimo S,) wrote > in comp.dsp: > > >>how to implement in "Ansi C" a circular buffer with the TMS320F2812? >> >>thanks, > > > If your buffer size is a power of 2, Code Composer for the 2812 > optimizes away the module operations to bit-wise ANDs even when > optimization is not turned on, so: > > something = x [count++]; > count %= 1024; > > The second line will be turned into a single operation to AND count > with 1023 (0x3ff). >The bitwise-and is still an extra operation inside the loop. If the OP is worried about speed, then he should probably use HW circ buffering or use the two-loop approach I posted earlier (portable & not restricted to powers of 2). -- Mark Borgerding
Reply by ●April 14, 20042004-04-14
On Tue, 13 Apr 2004 20:42:04 -0500, Jack Klein <jackklein@spamcop.net> wrote:> On 13 Apr 2004 05:01:44 -0700, sebastiani.m@tin.it (Massimo S,) wrote > in comp.dsp: > >> how to implement in "Ansi C" a circular buffer with the TMS320F2812? >> >> thanks, > > If your buffer size is a power of 2, Code Composer for the 2812 > optimizes away the module operations to bit-wise ANDs even when > optimization is not turned on, so: > > something = x [count++]; > count %= 1024; > > The second line will be turned into a single operation to AND count > with 1023 (0x3ff). >Does the 2812 have #pragma directives to implement circular and bit-reversed accesses in C as the 'c4x does?
Reply by ●April 15, 20042004-04-15
"U-CDK_CHARLES\\Charles" <"Charles Krug"@cdksystems.com> wrote in message news:<3Ubfc.18674$d8.11872@nwrdny01.gnilink.net>...> On Tue, 13 Apr 2004 20:42:04 -0500, Jack Klein <jackklein@spamcop.net> wrote: > > On 13 Apr 2004 05:01:44 -0700, sebastiani.m@tin.it (Massimo S,) wrote > > in comp.dsp: > > > >> how to implement in "Ansi C" a circular buffer with the TMS320F2812? > >> > >> thanks, > > > > If your buffer size is a power of 2, Code Composer for the 2812 > > optimizes away the module operations to bit-wise ANDs even when > > optimization is not turned on, so: > > > > something = x [count++]; > > count %= 1024; > > > > The second line will be turned into a single operation to AND count > > with 1023 (0x3ff). > > > > Does the 2812 have #pragma directives to implement circular and > bit-reversed accesses in C as the 'c4x does?In the datasheet it doesn't describe any pragmas for the cicular buffer.
Reply by ●April 15, 20042004-04-15
On 15 Apr 2004 00:35:38 -0700, Massimo S, <sebastiani.m@tin.it> wrote:> "U-CDK_CHARLES\\Charles" <"Charles Krug"@cdksystems.com> wrote in message news:<3Ubfc.18674$d8.11872@nwrdny01.gnilink.net>... >> On Tue, 13 Apr 2004 20:42:04 -0500, Jack Klein <jackklein@spamcop.net> wrote: >> > On 13 Apr 2004 05:01:44 -0700, sebastiani.m@tin.it (Massimo S,) wrote >> > in comp.dsp: >> > >> >> how to implement in "Ansi C" a circular buffer with the TMS320F2812? >> >> >> >> thanks, >> > >> > If your buffer size is a power of 2, Code Composer for the 2812 >> > optimizes away the module operations to bit-wise ANDs even when >> > optimization is not turned on, so: >> > >> > something = x [count++]; >> > count %= 1024; >> > >> > The second line will be turned into a single operation to AND count >> > with 1023 (0x3ff). >> > >> >> Does the 2812 have #pragma directives to implement circular and >> bit-reversed accesses in C as the 'c4x does? > > In the datasheet it doesn't describe any pragmas for the cicular buffer.It would be in one of the tools manual, probably one entitled, "Optimizing C Compiler" that goes into the details of the C implementation. At least that was the case for the 'c4x and 'c6x families.






