<< Chapter < Page | Chapter >> Page > |
The following lines of code were borrowed from the C FFT to serve
as an example of arithmetic operations in C. Savethis code in a file called mathex.c and compile this file by typing
c_asm mathex.c
at a command prompt. Look at
the resulting assembly file and investigate the differences betweeneach block. Be sure to reference
page 6-10 of the
compiler user's guide to findout what the state of the FRCT and OVM bits are. Run
this program on the DSP, halt the program, and compare theoutput values in a memory window. Does each block work properly
for all possible values?
int s1, s2;
int t1, t2;
int i1, i2;
int n1 = 16383, n2 = 16382, n3 = 16381, n4 = 16380;
void main(void)
{
/* Code for standard 32-bit hardware, */
/* with x,y limited to 16 bits */
s1 = (n1*n2 + n3*n4) >> 15;
s2 = (n1 + n2) >> 1;
/* Code for TI TMS320C54X series */
t1 = ((long int)(n1*n2) + (long int)(n3*n4)) >> 15;
t2 = ((long int)n1 + (long int)n2) >> 1;
/* Intrinsic code for TMS320C54X series */
i1 = _sadd(_smpy(n1,n2), _smpy(n3,n4));
i2 = _sshl(_sadd(n1, n2),-1);
while(1);
}
A working program can be produced by compiling the C code and
linking assembly modules and the core module. The compilertranslates C code to a relocatable assembly form. The linker
assigns physical addresses on the DSP to the relocatable dataand code segments, resolves
.global
references and links runtime libraries.
The procedure for compiling C code and linking assembly modules
has been automated for you in the batch file
v:\ece420\54x\dsptools\c_asm.bat
. The name of the
first file becomes the name of the executable. Once you havecompleted
lab4main.c
and
c_fft_given.asm
,
type
c_asm lab4main.c c_fft_given.asm
to produce a
lab4main.out
file to be loaded onto the DSP. For the
C FFT type
c_asm lab4main.c lab4fft.c
to produce
lab4main.out
.
Load the output file onto the DSP as usual and confirmthat valid
FFTs are calculated. Once valid output is obtained, measure howmany clock cycles it takes to compute both the assembly and C FFT.
We provide for you in Appendix
D and
E a complete C implementation
of a PSD estimator. The input is an IIR-filtered pseudo-noise (PN)sequence generator and the PSD estimate is based on windowing the
autocorrelation with a rectangular window.The code consists of the files
lab4bmain.c
,
lab4b.h
,
intrinsics.h
,
pn.c
,
iirfilt.c
,
autocorr.c
,
c_fft_given_iirc.asm
, and the previously-given TI FFT
routine. The assembly file
c_fft_given_iirc.asm
differs
from
c_fft_given.asm
in that the window array has been
removed and variables and arrays associated with IIR filtering havebeen added. Note that the multiply functions in the functions are
actually compiler directives contained in
intrinsics.h
.
Make sure you know which ones are used and why; note that
VPO
is not defined by the TI compiler, therefore the
corresponding section of the
#ifdef
statement is not used.
Compile and link these files by issuing
c_asm lab4bmain.c pn.c iirfilt.c autocorr.c
c_fft_given_iirc.asm
at the command line. Load
lab4bmain.out
onto the DSP and
run the code. Make sure that anIIR-filtered PN sequence appears on channel 1 and its PSD estimate
appears on channel 2.
Notification Switch
Would you like to follow the 'Digital signal processing laboratory (ece 420)' conversation and receive update notifications?