Transcript Lecture 08
Lecture 08
From MATLAB to Real Time with TI DSP
1
Hardware and Software Requirements
• MATLAB R2006b with Embedded Target for TI C6000.
• Code Composer Studio (CCS) v3.1
• Texas Instruments DSK6416 hardware.
2
Starting FDATool
• Start MATLAB 7.3.0 R2006b. At the command line, type in “fdatool”.
• The following screen will appear:
3
Designing an FIR Filter Design
• From the “Design Method” part of the screen, click on the “FIR” box
and select “Window”.
• Setting the Filter Coefficients
• Click on the “Design Filter” box when done.
4
Designing an FIR Filter Design
• The frequency response curve of the filter will appear
• It can be seen that for frequencies above 4 kHz, the output amplitude
is reduced by more than 40 dB (100 times).
5
Designing an FIR Filter Design
• Select File -> Save Session As…
• Give the filter a unique name such as “FIR_lowpass_800Hz”.
6
Exporting the Filter To Simulink
• Now for the clever part!
• Select File -> Export to Simulink Model.
7
Exporting the Filter To Simulink
• Realizing the Model:
– Give the block a unique name such as “FIR Lowpass Filter 800 Hz”.
– Click the “Realize Model” box.
8
The New Simulink Model
• The filter we designed using FDATool has been converted to a
Simulink block.
• It has been automatically dropped onto a new Simulink model.
9
Filter Block Parameters
•
•
Double-click on the “Digital Filter” block. The “Numerator coefficients” have
been supplied in “floating-point” format.
This makes them compatible with the Texas Instruments C6000 DSP.
10
Designing a High Pass Filter
•
•
The next step is to design a highpass filter.
At the FDATool window, Select File -> New Session to start the new design.
11
The Highpass Filter Design
• Set the “Response Type” to “Highpass”.
• Notice that the “Filter Specifications” part of the screen changes.
12
Entering the Filter Parameters
• Click on the “Design Filter” box when done.
13
Viewing the Highpass Filter Frequency
Response
• Click on the “Design Filter” box when done.
14
Saving the Finished Highpass Filter Design
•
•
Select File -> Save Session As… and give it a unique name.
“FIR Highpass 800Hz Hamming Window”.
15
Exporting to Simulink
•
•
Select File -> Export to Simulink Model.
Give the block a unique name such as “FIR Highpass Filter 800Hz”.
16
Realizing the Filter Model
• Click on the “Realize Model” button.
17
The Updated Model
•
•
•
Return to Simulink.
The second “Digital Filter” block has been added to the model.
Save the model using a unique name such as “C6416_Audio_FIR_Filter_Design”.
18
Highpass Filter Settings
•
•
•
Double-click on the “FIR Highpass Filter 800 Hz” block.
Again, the “Numerator coefficients” are in “floating-point” form.
Click on “OK”.
19
C6000 Target Preferences
•
•
•
•
Select View -> Library Browser.
Select Embedded Target for TI C6000 DSP.
Highlight “C6000 Target Preferences”.
Drag-and-drop the “C6416DSK” block onto the model.
20
Initialize Target Preferences
•
•
When the “Initialize” window appears, click on the “Yes” box. This sets up the
correct sampling format for the DSK6416.
21
Adding a Demultipexer/Multiplexer
•
•
•
•
•
•
The input from the ADC is in stereo, that is, it contains both left and right audio inputs. In
order to separate the two inputs, a demultiplexer is required.
In the Simulink Library Browser Select "Simulink -> Commonly Used Blocks".
Drag-and-drop a “Demux” block onto the model.
The two mono filter outputs are mono. This is different to the stereo input to the DAC. In
order to make the signals compatible, a multiplexer is required.
In the Simulink Library Browser, select the "Simulink/Commonly Used Blocks",
and drag-and-drop a “Mux” block onto the model.
22
Joining the Blocks
•
•
The blocks need to be joined
We saved this model as "C6416_audio_FIR_Filter_design.mdl".
23
Adding an ADC
•
•
Return to the “C6416 Board Support” Library.
Drag-and-drop an “ADC” block onto the model.
24
Adding a DAC
•
•
Again go to the “C6416 Board Support” Library.
Drag-and-drop an “DAC” block onto the model.
25
Adding a DAC
26
ADC Settings
•
Double-click on the ADC block. Set up the ADC as follows:
27
DAC Settings
•
Double-click on the DAC block. Set up the DAC as follows:
28
The Final Filter Design
•
Join the blocks together
29
Building the Model
•
Select Tools -> Real-Time Workshop -> Build Model.
30
The Completed Model Running on Code
Composer Studio
•
•
Go to Code Composer Studio.
From the folders in the left window, select the source code for the project.
31
Device Drivers
White Paper
DSP/BIOS Device Driver Developer's Guide
32
DSP BIOS Consists Of:
Real-time analysis tools
Allows application to run
uninterrupted while displaying
debug data
Real-time scheduler
Preemptive thread mgmt
kernel
Real-time I/O (Drivers)
Allows two-way
communication between
threads or between
threads and hardware
Life before drivers... 33
Directly Accessing Hardware
DSK6416_AIC23_
Codec
App
McBSP
void audioLoopBack() {
DSK6416_AIC23_CodecHandle hCodec;
short buf[64];
int N;
DSK6416_init();
App writes to hardware
directly using the the specific
target’s BSL functions
Every application needs to be
customized to hardware:
You must change each
instance of DSK6416_xxx to
another function call every
time you port the code
Portability suffers
/* Start the codec */
hCodec = DSK6416_AIC23_openCodec(0, &config);
while () {
for (N = 0; N < 64; N++) {
while (!DSK6416_AIC23_read(hCodec, buf[N]));
while (!DSK6416_AIC23_write(hCodec, buf[N]));
}
}
}
Using drivers… 34
Abstracting Hardware with Drivers
IOM
Codec
App
McBSP
SIO
or
PIP
SWI or
TSK
Device Drivers standardize the interface between
the Application and the H/W
Application programmer only has to know PIP or SIO
(no matter what H/W is connected)
The H/W can be changed without changing the Application
(only need to change IOM included in project)
Therefore, Drivers (SIO/PIP with IOM) insulate the
Application from the hardware’s details
CSL, BSL, and IOM make up ... 35
Using DSP/BIOS PIP Driver
void audioLoopBack() {
// get the full buffer from the receive PIP
PIP_get(&pipRx);
// get the empty buffer from the transmit PIP
PIP_alloc(&pipTx);
// Put the transmit buffer; Free the receive buffer
PIP_put(&pipTx);
PIP_free(&pipRx);
Think of PIP (pipe) as a buffer manager with built-in signaling:
The ‘reader’ gets signaled when data is available
The ‘writer’ gets signaled when the buffer is emptied
Use it from SWI SWI or between SWI hardware
A common interface for all C5000 & C6000 DSP’s
Bottom Line: Application Code never changes even if you change H/W
36
How about a SIO example?
Using SIO Drivers
// Run forever looping-back buffers
for (;;){
// Reclaim full buffer from the input stream
SIO_reclaim(inStream, (Ptr *)&inbuf, NULL))
// Reclaim empty buffer from output stream and reissue
SIO_reclaim(outStream, (Ptr *)&outbuf, NULL)
SIO_issue(outStream, inbuf, nmadus, NULL)
}
// Issue an empty buffer to the input stream
SIO_issue(inStream, inbuf, SIO_bufsize(inStream), NULL)
SIO (Stream I/O) is another DSP/BIOS device driver methodology
Think of issuing and reclaiming buffers from a stream
Bottom Line: Application Code doesn’t change even if hardware does
37
BIOS I/O Models
DSP/BIOS
Thread Types
DSP/BIOS provided
Class Drivers
Mini-Driver
(IOM)
TSK or
SWI
SWI
SIO
PIP
Any mini-driver (IOM) can be used
with any DSP/BIOS I/O model
Application Programmer chooses the preferred class driver
Interface is consistent regardless of which device (mini-driver) connected
Software interface doesn’t change, even if you change the IOM device
38
Driver Developer Kit (DDK) Support
Platform*
Video
Capture /
Display
6711
DSK
External
PCI
EMAC
External
6713
DSK
McBSP
AIC23
6416
TEB
H/W
UART
S/W
UART
Utopia
AD535
6416
VT1420
McASP
(External)
PCM3002
6416
DSK
AIC23
DM642
Beta
Beta
Beta
* We
EVMhave only included C6000 systems in this table AIC23
Beta
AIC23
Provided Royalty Free
Requires CCS v2.2 or greater
Search for “DDK” on the TI website to download
3rd Party
Solution
DDK
v1.0
DDK v1.1
DDK v1.2 (3Q03)
39
Mini-Driver Interface (IOM)
• Maximum Reuse and Portability
– One I/O mini-driver (IOM) interface to support all TI Class
drivers.
• IOM Interface Consists Of:
Functions:
Data Structures:
init function
IOM_mdBindDev
IOM function table
IOM_mdUnBindDev
Dev
IOM_mdControlChan
Global Data
IOM_mdCreateChan
IOM_mdDeleteChan
Channel Params
IOM_mdSubmitChan
Channel Instance Obj.
interrupt routine (isr)
IOM_Packet (aka IOP)
BIOS Device Table
param’s
Pointer
(device inst. obj.)
40
TI Software Foundation Model
DSP/BIOS
Communications
Layer
SIO / PIP
Board Support
Layer
DSK’s BSL
Chip Support
Layer
TI CSL
IOM
41