Lab Exercise:
Circular Buffers and the 'C542
This exercise introduces the use of circular buffers using the algebraic assembly language of the TI TMS320C542 ( 'C542). You will need to use the 'C542 kits in the lab along with the C54x Code Explorer software. You will also need to use the dskplasm assembler to generate .obj files that could be downloaded to the 'C542 kit thru Code Explorer.
Using the assembler
The c:\dskplus\demos\delay directory contains 3 assembly language files:
- delay.asm
- dly_ac01.asm, and
- dly_vecs.asm .
Copy these files to some other directory of your own. Assemble delay.asm from a DOS prompt:
dskplasm delay(If the path variable has not been properly set up by autoexec.bat, you may need to supply the full path: c:\dskplus\dskplasm delay. ).
The assembler generates a corresponding file delay.obj which could be downloaded to the 'C542 using Code Explorer. Verify that this file has been generated.
Examine the delay.asm file. The lines
.copy "dly_vecs.asm"and
.copy "dly_ac01.asm"instruct the assembler to include the two other assembly language files. Hence, there is no need to explicitly invoke the assembler on them.
The Delay Program
The delay program starts by performing some initializations. Among others, the line
call AC01INITinvokes code in dly_ac01.asm for initializing the analog interface. After the initializations, interrupts are enabled and the program goes into an infinite loop that does nothing:
hangloose: nop goto hanglooseInfinite loops such as this one should be expected of any embedded software not running on top of a real-time operating system or RTOS (Such software is in effect the RTOS). Since interrupts are enabled, this infinite loop is interrupted regularly by the receive interrupt which results in the following routine in delay.asm being executed:
receive: a = #0 ; load A with zero a = trcv ; load A with TDM receive from AIC *ar1+% = a ; store present value a = *ar1 ; load delayed value tdxr = a ; send A to TDM transmit register return_enable ; Return and Enable interruptsThis routine is associated with the receive interrupt thru the following code in dly_vecs.asm (which is in turn included in delay.asm):
trint dgoto receive ;58; TDM receive interrupt nop nop nopThe delay program continuously stores samples of sound into a buffer and sends the oldest available sample to the transmitter. The sample sent to the transmitter will be overwritten by the next incoming sample.
Be able to explain in detail how the circular buffer is managed.
Running an application
Invoke Code Explorer. ( Start >> Programs >> Code Explorer >> C54x Code Explorer or click the Code Explorer icon on the desktop if it's there.)
Choose the appropriate parallel port (The default will probably work.) then load the delay.obj code using
File >> Load Program
on the Code Explorer menu. Use Debug >> Run ( or press F5 or click on Run button) to run the code.
Whatever you speak into the microphone is delayed by about 0.22 seconds.
Circular Addressing
The algebraic instruction set of the'C54 is documented in
TMS320C54x DSP: Algebraic Instruction Set (Reference Set, volume 3).
Information regarding use of circular addressing on the 'C542 is available on pages 3-18, 3-20, and 5-15 to 5-18 of
TMS320C54x DSP: CPU and Peripherals (Reference Set, volume 1).
Insert the following settings in delay.asm, right after the settings for buffer and length.
buffer2 .set const1 length2 .set const2where const1 and const2 are the constants assigned to you for this exercise. [parameter assignments]
Also insert the following code right after the instruction
sp = #0ffaha few lines after the start label:
;******** insert the following code ********** B = #100h AR2 = #const1 BK = #const2 loop: *AR2+% = B B -= #1 if (BGT) goto loop nop nop nop ;***********************************************Again, replace const1 and const2 with the constants assigned to you for this exercise. [parameter assignments]
Assemble the code, load the resulting .obj file, and step thru it using Debug>>Step Over (or by pressing F10 or by clicking on the Step Over button;). Use View>>Memory and View>>CPU Registers from the Code Explorer menu to monitor changes.
Be able to explain everything the inserted code does.
Some notes:
- The # in B = #100h indicates immediate addressing
- the * in the statement *AR2+% = B indicates indirect addressing, similar to indirection or dereferencing of pointers in C/C++
- the + in the statement *AR2+% = B indicates autoincrement
- the % in the statement *AR2+% = B indicates circular addressing
- "if (BGT)" translates to "if the B register is greater than 0"
This page has been accessed
times since December 3, 2002.