DSP C5000
Chapter 7
DSP BIOS
Copyright © 2003 Texas Instruments. All rights reserved.
DSP BIOS Offers the Following:

Real-time scheduler
Preemptive thread management kernel

Real-time analysis tools
Allows application to run uninterrupted while displaying
debug data

Real-time data exchange (RTDX)
Allows two-way communication (target  host) while
target is running

Programming of DSP peripherals
Graphical input to peripheral initialization through Chip
Support Library (CSL)
ESIEE, Slide 2
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS Configuration Tool
Creating a New
Configuration File

Configures System




Creates and defines objects
(ex. IDL)
Configure hardware
interrupts and creates
interrupt vectors
Configures memory and
creates linker command file
Calculates estimated data
and minimum stack size
needed
ESIEE, Slide 3
Copyright © 2003 Texas Instruments. All rights reserved.
Files Generated by the Configuration Tool
Configuration database file
Save
program.cdb
programcfg.h##
programcfg.s##
programcfg.cmd
programcfg_c.c
programcfg.h
Allocated at link time
ESIEE, Slide 4
Copyright © 2003 Texas Instruments. All rights reserved.
File Extensions
prog.h
prog.c
prog.asm
progcfg.s##
progcfg.obj
mod.h
progcfg.h##
prog.cmd
(optional)
progcfg.cmd
Linker
prog.out
Compiler/
Assembler
prog.obj
ESIEE, Slide 5
prog.cdb
user.lib
*.lib
Copyright © 2003 Texas Instruments. All rights reserved.
Startup Sequence
BIOS_reset()
system code
user code
interrupt enable bits OFF
“other” initialization
BIOS_init()
interrupt flag bits OFF
vector table pointer initialized
main()
do hardware initialization
enable individual interrupts
return
BIOS_start()
HWI_startup() enables HWI
start DSP/BIOS scheduler
ESIEE, Slide 6
interrupt enables
interrupt flags
C5000
IMR
IFR
global int enable
INTM
Copyright © 2003 Texas Instruments. All rights reserved.
Startup Sequence

Initialize the DSP and the hardware



BIOS_init( ) is called automatically





Start DSP/BIOS
Enables interrupts globally
Drops into the DSP/BIOS “background loop”

ESIEE, Slide 7
System initialization that needs to be performed
Enable selected interrupts before interrupts are enabled globally
Must return to complete the program initialization!!!!
BIOS_start( ) is called automatically


Initializes DSP/BIOS modules
main()


The software stack pointer, memory wait states, memory
configuration registers
This is part of the boot.c file that is part of the DSP/BIOS library
Initializes communication with the host for real-time analysis
Copyright © 2003 Texas Instruments. All rights reserved.
Real-time Systems


Systems that respond in a correct and timely way
to events
Events are occurrences that cause a nonsequential change in the software flow of control

Driven by hardware and software events


Interrupt signals
IF-THEN and CASE statements
inputs
ESIEE, Slide 8
Real-time System
outputs
Copyright © 2003 Texas Instruments. All rights reserved.
Real-time Systems attributes

Events driven:



Time constrained:




Processing more than one event apparently
“simultaneously” to meet deadlines
Means: Preemption & multi-tasking.
Deterministic & reliable:

ESIEE, Slide 9
Hard (Critical deadlines, catastrophic).
Soft (Non-critical deadlines, non-catastrophic).
Concurrency:


Synchronous (end of internal timer counting).
Asynchronous (ADC or DAC interrupt).
Will always have the same behaviour within a
known response time.
Copyright © 2003 Texas Instruments. All rights reserved.
Audio Example


For this system to function properly, the
filter needs to calculate the correct output before
the next sample arrives
What events drive this system?

Receive and Transmit Interrupts


Asynchronous Event - could happen at different points in code
Polling of Receive and Transmit conditions

Synchronous Event - always happens at the same place in code
Sample
ESIEE, Slide 10
Audio Filter
Sample
Copyright © 2003 Texas Instruments. All rights reserved.
Real-time System Requirements
Filter
Routine A:
Period
Compute
CPU Usage
22 s
11 s
(50%)
Period = 1/fs
running
A
idle
TI DSP
Deadline!
Time
ESIEE, Slide 11
0
1
2
3
4
5
6
7
Copyright © 2003 Texas Instruments. All rights reserved.
Adding new function (new task)
Filter
DTMF
TI DSP
ESIEE, Slide 12
Previous Requirement
 DSP filters audio signal
New Requirement
 Add DTMF function
 DTMF is independent of filter
 Issues:
 Do we have enough bandwidth (MIPS)?
 Will one routine conflict with the other?
 How do we create the compound system?
Copyright © 2003 Texas Instruments. All rights reserved.
System Implementation Considerations
main
{
while(1)
{
Filter

One method: put each algo into an
endless loop under main

Problems:

What if algorithms run at
differing rates? (eg: our filter
runs ~ 44 KHz and the DTMF
algo ~ 8 KHz)

What if one algorithm
overshadows another, starving it
for recognition or delaying it’s
response beyond the limits of the
system?
DTMF
}
}
ESIEE, Slide 13
Copyright © 2003 Texas Instruments. All rights reserved.
Interrupt Driven System - Problem
main
{
while(1);
}
Timer1_ISR
{
A
}
Timer2_ISR
{
B
}
TI DSP
Routine A:
Routine B:
Period
Compute
CPU Usage
22 s
125 s
11 s
33 s
(50%)
(26%)
76%
Missed !
running
y1
A
y2
y3
y4
idle
B
Time
0
1
2
3
4
5
6
7
Only one can run at a time...
There are two elements of CPU loading:
average & instantaneous
ESIEE, Slide 14
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS Scheduling
main
{
return;
}
Timer1_ISR
{
start A;
}
Timer2_ISR
{
start B;
}
DSP/BIOS
A
B
ESIEE, Slide 15
DSP/BIOS provides scheduling:
 Tasks are marked to be run by event processing
or other task.
 Scheduler supervises task running depending on
status (mark to be run), priority, …
running
A
idle
B
Time
0
1
2
3
4
5
6
7
B suspended
Modules written independently
Easier to maintain - Module interaction minimized
Built-in Scheduling - Managed by DSP/BIOS
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS Preemptive Scheduler
Hard Real-time Foreground
Hardware Interrupts
Software Interrupts
Idle
Soft Real-time
ESIEE, Slide 16
1st-TIER RESPONSE
 Sample-by-sample processing
 Microsecond duty cycles
2nd-TIER RESPONSE
 Frame-by-frame processing
 Millisecond duty cycles
Best Effort
Background
Copyright © 2003 Texas Instruments. All rights reserved.
Preemption

The act of changing the flow of control
from one process to another based on
priority


Higher priority always runs
Allows one process to asynchronously
interrupt the execution of the currently
executing process

Concurrent processing
Completed
Inactive
Ready
Posted
Started
Running
Resume
Preempted
ESIEE, Slide 17
Copyright © 2003 Texas Instruments. All rights reserved.
DSP BIOS Scheduler

The Scheduler provides both h/w and s/w interrupt management
DMAC2 INT
SWI Pending
HWI_enter
h/w real-time code
Post s/w interrupt (SWI)
HWI_exit




filter code
SWI
HWI

SWI:
Fast response to interrupts
Minimal context switching
High priority for CPU
Can post SWI
Danger of missing an interrupt
while executing ISR





Latency in response time
Context switch performed
Selectable priority levels
Can post another SWI
Execution managed by
scheduler
Let’s look at a scheduling example...
ESIEE, Slide 18
Copyright © 2003 Texas Instruments. All rights reserved.
Priority Based Thread Scheduling
post3 rtn
HWI 2
A thread may be a:
 subroutine
 ISR
 function
(highest)
post2 rtn
HWI 1
post1
SWI 3
int2
SWI 2
rtn
rtn
rtn
SWI 1
MAIN
IDLE
(lowest)
ESIEE, Slide 19
rtn
int1
User sets the priority...BIOS does the scheduling
How do you set the priorities ?
Copyright © 2003 Texas Instruments. All rights reserved.
Interrupts that Post SWI
HWI_enter
post
HWI_exit
isr
Running
p=2
Ready
p=1
Idle
time


Use HWI_enter and HWI_exit assembly macros
APIs that may affect scheduling:
SWI_andn, SWI_dec, SWI_inc, SWI_or, SWI_post,
PIP_alloc, PIP_free, PIP_get, PIP_put, PRD_tick,
SEM_post
ESIEE, Slide 20
Copyright © 2003 Texas Instruments. All rights reserved.
HWI_enter and HWI_exit

HWI_enter



Saves selected
registers
Sets interrupt mask
to disable/enable
nested interrupts
Informs scheduler
to delay running
newly posted SWI

HWI_exit



Restores selected
registers
Restores interrupt
mask
Returns from
interrupt
These APIs can only be called from assembly.
ESIEE, Slide 21
Copyright © 2003 Texas Instruments. All rights reserved.
Writing an ISR in Assembly(C54x)
SWI_post example
Template ISR with no
scheduling APIs called
.def isr1
.include hwi.h54
.include swi.h54
.def isr1
isr1:
isr1:
;save context (PUSHM)
HWI_enter MASK,IMRDISABLEMASK
;ISR code
SWI_post
;restore context (POPM)
;other ISR code
;return from interrupt
HWI_exit MASKS,IMRRESTOREMASK

ESIEE, Slide 22
Pros/Cons of HWI_enter and HWI_exit
 Easy way to save/restore registers
 Able to call scheduling APIs
 Allows for nested interrupts (preemption)
 Execution overhead
 Callable only from Assembly
Copyright © 2003 Texas Instruments. All rights reserved.
HWI_enter and HWI_exit (C54x)
.include c54.h54
.include hwi.h54
; mask constants
; HWI module definitions
HWI_enter MASK IMRDISABLEMASK
HWI_exit MASK IMRRESTOREMASK
MASK - registers to save/restore
IMRDISABLEMASK, IMRRESTOREMASK -
IMR bits to mask (1s)
or restore (1s)
HWI_enter C54_A|C54_B,0x0008

Saves the A and B accumulators, disables TINT0, all other INTs nested
HWI_enter C54_CNOTPRESERVED,0xFFFF

ESIEE, Slide 23
Saves C “Save on Call” registers, disables all nested interrupts
Copyright © 2003 Texas Instruments. All rights reserved.
Hardware Interrupt Dispatcher

Automatically includes HWI_enter and exit
via a stub function

Can be used with ISR’s written in C
ESIEE, Slide 24
Copyright © 2003 Texas Instruments. All rights reserved.
Writing an ISR in C
Int i; /*global var*/
void isr1(void)
{
HWI_enter(MASKS)
i++;
SWI_post(&swiAudio)
HWI_exit(MASKS)
}

ISR can be purely in C if no scheduling APIs are
called

Declare as interrupt void isr1(void)
 Don’t use interrupt keyword if calling with
HWI_enter and HWI_exit ISR!
 HWI_exit does a return from interrupt
ESIEE, Slide 25
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS (SWI) Software Interrupts


Defer hardware interrupt
service routines to software
interrupts
Preemptive


maxpri
XXXX
Priority 0-14
15
Context Switch

XXXX
Automatic for SWI


ESIEE, Slide 26
HARDWARE INTERRUPT
Single stack model (Application
Stack)
Adding priority levels will
increase stack size requirements
minpri
IDLE
Copyright © 2003 Texas Instruments. All rights reserved.
Software Interrupt Objects

SWI_Obj (example)




Pointer to a function
Arg0 and Arg1
Priority
Initial Bit/Count
value


SWI_obj
SWI_obj
Will cover later
All interrupts run
on a common stack


ESIEE, Slide 27
Stores local
variables
Nested function calls
SWI_obj
fxn
arg0
arg1
priority
mailbox
fxn
arg0
arg1
priority
mailbox
fxn
arg0
arg1
priority
mailbox
FIR
C func
FFT
Common
.stack
ASM func
Copyright © 2003 Texas Instruments. All rights reserved.
Scheduling Rules and SWI API
Highest Priority
post
isr
p=2
Running
p=1
Ready
p=1
post
Idle
Lowest Priority
time
SWI_post()
Unconditionally
Software
ESIEE, Slide 28
post a software interrupt
interrupt is posted in the ready state
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS Software Interrupt Mailbox


Used to conditionally or unconditionally
post software interrupt
Can be used as a counter or a bit field






Set a bit to notify how SWI was posted
Allows multiple conditions to be met before
a SWI can run
Allows to monitor missed SWI
SWI_inc increments the mailbox and posts SWI C
The Mailbox is reset when SWI C runs
Use SWI_getmbox() to get previous mailbox value
(must be 1)

ESIEE, Slide 29
Mailbox is an int value (16 bits for C5000)
Copyright © 2003 Texas Instruments. All rights reserved.
Calling DSP/BIOS API from Assembly(C54x)

Example: Void SWI_post(SWI_Obj *swi);



Preconditions:
cpl = ovm = c16 = frct = cmpt = 0
dp = GBL_A_SYSPAGE
ar2 = address of SWI Object
intm = 0 (if outside an ISR)
Post conditions: none
Modifies:
ag, ah, al, ar0, ar2, ar3, ar4, ar5, bg,
bh, bl, c, dp, t, tc
.include swi.h54
; SWI module definitions
; Setup preconditions and save context
stm
_swiAudio,ar2 ; argument to SWI_post
SWI_post
ret
ESIEE, Slide 30
; return
Copyright © 2003 Texas Instruments. All rights reserved.
Counting Events: SWI_dec()
HWI
SP
Buffer
SWI_dec(&SWI)
SWI B
Mailbox




11
SWI_dec() decrements the mailbox value
SWI is posted if mailbox = 0
Set the initial mailbox value in the SWI’s properties
Mailbox is resets to initial value when SWI runs
ESIEE, Slide 31
Copyright © 2003 Texas Instruments. All rights reserved.
Who Called: SWI_or
SWI A
SWI B
SWI C
SWI D



SWI_or(1)
SWI_or(2)
SWI_or(4)
SWI_or(8)
SWI SUB
Int mailbox;
mailbox = SWI_getmbox();
switch(mailbox)
{
case 1: {do this}
case 2: {do this}
case 4: {do this}
case 8: {do this}
}
SWI_or() sets a bit in the mailbox and posts the SWI
Use SWI_getmbox() to read the mailbox and determine
which routine posted the instance of the SWI
Mailbox is reset when SWI runs
ESIEE, Slide 32
Copyright © 2003 Texas Instruments. All rights reserved.
Handling Conditions: SWI_andn
Adaptive Filter
swiGetData
SWI_andn(1)
swiFilter
Mailbox
swiAdapt
SWI_andn(2)
01 01
Note: SWI_andn => mailbox AND ( NOT MASK )




SWI_andn() clears a bit in the mailbox value
SWI is posted if mailbox = 0
Set the initial mailbox value in the SWI’s properties
Mailbox is resets to initial value when SWI runs
ESIEE, Slide 33
Copyright © 2003 Texas Instruments. All rights reserved.
Posting SWIs - A Summary
Mailbox is
a bitmask



Always post
SWI_or
Post if mailbox = 0
SWI_andn
Mailbox is
a counter
N/A
SWI_inc SWI_post
SWI_dec
Use SWI_getmbox() to read
the mailbox
Set initial value of the mailbox
in the SWI’s properties
Mailbox is reset when SWI runs
ESIEE, Slide 34
Copyright © 2003 Texas Instruments. All rights reserved.
Timer Services
CPU clock
rate
4
Hi-res
Clock
N
max clock
rate
timer
counter
timer
period
interrupt Low-res
Clock
System
Tick
Clock Manager

The Clock Manager configures:



Period of the system tick - Timer Period
Functions that run as part of the timer ISR - CLK_Objects
DSP/BIOS configures a CLK Object, PRD_clock, to
manage
ESIEE, Slide 35

A low and a high resolution time stamp

Periodic Functions
Copyright © 2003 Texas Instruments. All rights reserved.
Periodic Function Manager

PRD_clock will conditionally trigger the DSP/BIOS central
dispatcher via PRD_tick

DSP/BIOS central dispatcher runs a software interrupt
called PRD_swi
 PRD_swi contains a list of periodic processes in a table

PRD_swi will select the periodic functions to run based on
the period
P1
 Run at the same priority - FIFO
f1(t)
P2
Timer
Interrupt
DSP/BIOS
PRD_clock
PRD_tick()
/P
f2(t)
P3
PRD_swi
f3(t)
P4
f4(t)
ESIEE, Slide 36
Copyright © 2003 Texas Instruments. All rights reserved.
Periodic Objects



Period is the # of system ticks in which object’s
function will run
Function is the routine you want to executed
Type defines the nature of the periodic function

Continuous vs. One-shot
prdFunc1
DSP/BIOS
PRD_tick()
/P
Period
4
Function func1()
Type
continuous
PRD_swi
prdFunc2
Timer
Interrupt
Period
Function
Type
9
func2()
continuous
PRD_clock
ESIEE, Slide 37
Copyright © 2003 Texas Instruments. All rights reserved.
Continuous Periodic Functions


Call the function every N ticks
Triggered by the system tick


Timer interrupt or
Periodic interrupt that calls PRD_tick()
Execution timeline
tick
func1()
1
2
3
4
func1() func2()
5
prdFunc1
Period
4
Function func1()
Type
continuous
ESIEE, Slide 38
6
7
8
9
10
prdFunc2
Period
Function
Type
9
func2()
continuous
Copyright © 2003 Texas Instruments. All rights reserved.
Communication Techniques

Global variables


Can corrupt global data while preempted
Useful for first-in, first-out sequencing
Buffering of data using shared memory

Time-relative buffering



Useful for time-relative data transferred or for slow data
Double or ping-pong buffering
Ring or circular buffering

ESIEE, Slide 39
Process 1
Queues (linked list)


Process 0
Use queues to pass pointers to arrays of data buffers in
memory
Copyright © 2003 Texas Instruments. All rights reserved.
Queue






Simple data structure for basic
communication
Useful for first-in, first-out processing
Manages a linked list of elements
Includes atomic and non-atomic APIs
Allows insertion and deletion anywhere
in the Queue
Elements can be any data structure

ESIEE, Slide 40
Must include QUE_Elem
Copyright © 2003 Texas Instruments. All rights reserved.
Data Pipes
PIP buffers
Software
Interrupt




Software
Interrupt
I/O building blocks between processes (and
interrupts)
A pipe object has 2 sides - writer and reader
Built-in notify functions are used to synchronize
Queued data buffers are allocated at link time

Divided into a fixed number of frames of a particular size


ESIEE, Slide 41
nframes
framesize
Copyright © 2003 Texas Instruments. All rights reserved.
Multitasking
Hardware Interrupts
Hard Real-time
Foreground
Software Interrupts
Multitasking
Soft Real-time
Idle
ESIEE, Slide 42
Background
Copyright © 2003 Texas Instruments. All rights reserved.
Task Control Block Model
DSP/BIOS Startup
READY
Task is deleted
Preemption
TSK_delete()
TSK_yield()
TSK_setpri()
SEM_post()
TSK_tick()
RUNNING
TERMINATED
Task exits
Task is readied
Task suspends
BLOCKED
TSK_exit() TSK_sleep()
SEM_pend()
Task is deleted
TSK_delete()
ESIEE, Slide 43
Copyright © 2003 Texas Instruments. All rights reserved.
Semaphores and Priority
SEM_pend(semObj)
interrupt
block!
Priority=2
Not dependent on A
C
SEM_pend(semObj)
block!
Priority=1
Depends on A
Not dependent on A
B
SEM_post(semObj)
Priority=1
A
preempted!
Precondition for B and C
time




ESIEE, Slide 44
Both B and C depend on A
B pends on the semaphore first, then C
When A posts, B runs first because it pended first
Semaphores use a FIFO Queue for pending tasks!
Copyright © 2003 Texas Instruments. All rights reserved.
Mailbox API
MBX_post



Copies a message into a buffer
Block if mailbox is full or if another writer
is waiting
MBX_pend



Copies a message out of a buffer
Block if mailbox is empty or if another
reader is waiting
-
MBX_post
ESIEE, Slide 45
task0
task1
task2
task3
task4
MBX_pend
/
Copyright © 2003 Texas Instruments. All rights reserved.
Interfacing to Mailboxes
Void writer(Int id){
typedef struct MsgObj {
MsgObj
msg;
Int
id;
Int
i;
Char
val;
for (i=0; ; i++) {
};
msg.id = id;
msg.val = i % NUMMSGS + (Int)('a');
if ( MBX_post(&mbx, &msg, TIMEOUT) == 0 ){
SYS_abort("timeout %s”, TSK_getname());
}}}
Void reader(Void){
MsgObj
msg;
Int
i;
for (i=0; ;i++) {
if (MBX_pend(&mbx, &msg, TIMEOUT) == 0) {
SYS_abort("timeout %s”, TSK_getname());
}
LOG_printf(&logTrace,"%c from (%d)", msg.val, msg.id);
}}
ESIEE, Slide 46
Copyright © 2003 Texas Instruments. All rights reserved.
SWI vs. TSK
SWI
TSK
System
Stack Configuration Uses the
Stack
Each Task has
its own Stack
Blocking & Suspending
No
Yes
Deleted Prior to Completion
by other Threads
No
Yes
User Name, Error Number,
Environment Pointer
No
Yes
API Interface Assembly and C
ESIEE, Slide 47
C
Copyright © 2003 Texas Instruments. All rights reserved.
Disabling and Enabling Interrupts

Hardware interrupts
oldCSR = HWI_disable();
`critical section`
HWI_restore(oldCSR);


Scheduler

ESIEE, Slide 48
Atomic Functions
Can be nested
SWI_disable();
TSK_disable();
`critical section`
`critical section`
SWI_enable();
TSK_enable();
Copyright © 2003 Texas Instruments. All rights reserved.
Built-in Real-Time Analysis Tools

What is “Real-Time” ?
Gather data on target (3-10 CPU cycles)
 Send data during BIOS IDLE (100s of cycles)
 Format data on host (1000s of cycles)
 Data gathering does NOT stop target CPU

Execution Graph
Software Logic Analyzer
 Debug Scheduling
 Tick: specified time period
based on hardware timer

CPU Load Graph
 Analyze
time NOT
spent in IDLE
ESIEE, Slide 49
Copyright © 2003 Texas Instruments. All rights reserved.
Built-in Real-Time Analysis Tools
Statistics View

Profile routines without
halting the CPU
Message LOG
Send debug msgs to host
 Std printf requires:
- 27K bytes
- 30K CPU cycles
 LOG_printf requires:
- 32 bytes
- 30 CPU cycles

LOG_printf (&trace, “Loopback enabled”);
ESIEE, Slide 50
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS Modules
DSP/BIOS Library
CLK
HST
PIP
HWI
PRD
IDL
RTDX
LOG
STS
TRC
SWI
?
APPLICATION PROGRAM INTERFACE
USER FUNCTIONS
ESIEE, Slide 51
#include <log.h>
#include <sts.h>
func1
{
LOG_printf(...);
}
func2
{
STS_set(…);
}
Copyright © 2003 Texas Instruments. All rights reserved.
Creating and Reference Instances

Instances are created in
the Configuration Tool

Code that creates them is
in audiocfg.s##

Object declaration is in
mod.h (i.e. log.h)
Function


Instances must be
referenced (extern) by files
that use them
Header file is needed for
the declaration of the type
#include <std.h>
#include <log.h>
extern far LOG_Obj logTrace1;
extern far LOG_Obj logTrace2;
func()
{
LOG_printf( &logTrace1, … );
LOG_printf( &logTrace2, … );
}
ESIEE, Slide 52
Copyright © 2003 Texas Instruments. All rights reserved.
Interface to Statistics Accumulators

Count the number of occurrences of an event
STS_add(&stsObj); /* count an event */

Track the maximum and average for a variable
STS_add(&stsObj, value); /* track the maximum and
average */

Tracking minimum value of a variable
STS_add(&stsObj, -value); /* track the minimum */

Timing events or monitoring incremental differences
in a value
STS_set(&stsObj, CLK_gethtime());
STS_delta(&stsObj, CLK_gethtime()); /* algorithm OR event */
ESIEE, Slide 53
Copyright © 2003 Texas Instruments. All rights reserved.
STS API Effect on STS Object Fields
STS_add(x) STS_set(y) STS_delta(z) STS_reset
y
Previous*
z
Count
+1
+1
0
Total
+x
+(z-Previous)
0
Max
replaced
if x > Max
replaced if
(z-Previous)
> Max
largest
negative
number
*Previous field is set using Config tool, STS_set, or STS_delta
ESIEE, Slide 54
Copyright © 2003 Texas Instruments. All rights reserved.
Clock Interface

CLK_getltime()


CLK_gethtime()


Returns the number of high resolution
clock cycles that have occurred
CLK_countspms()

ESIEE, Slide 55
Returns the number of timer interrupts
that have occurred
Returns the number of timer register ticks
per millisecond
Copyright © 2003 Texas Instruments. All rights reserved.
Trace Control

Allows the user to enable and disable
instrumentation on the target


Limit the effects of instrumentation on program
execution
Two interfaces

Host interface
RTA Control Panel

User Program
TRC API
ESIEE, Slide 56
Copyright © 2003 Texas Instruments. All rights reserved.
Target Trace Control Masks
Trace Control Mask - declared in trc.h
TRC_LOGCLK
TRC_LOGPRD
TRC_LOGSWI
TRC_LOGTSK
TRC_STSHWI
TRC_STSPIP
TRC_STSPRD
TRC_STSSWI
TRC_STSTSK
TRC_USER0
TRC_USER1
TRC_USER2
TRC_GBLTARG
TRC_GBLHOST
ESIEE, Slide 57
LOG timer interrupts
LOG periodic ticks and PRD functions
LOG software interrupt events
TSK events
Gather statistics on HWI
Count number of frames in data pipes
Gather statistics on PRD function execution
Gather statistics on SWI execution
Gather statistics on TSK execution
User defined
User defined
User defined
Global target
Global host
Copyright © 2003 Texas Instruments. All rights reserved.
RTDX: Real-Time Data Exchange

RTDX enables non-obtrusive two-way communication
between the host PC and the DSP (during IDLE)

Transfer speed limited by JTAG bandwidth (~10 MHz serial),
connection type (parallel vs. XDS) and DSP activity level

Transfers made via RTDX calls in DSP application code
PC
User

TI

3rd
Party
Third
Party
CCS
JTAG
RTDX

EMU
Display
USER CODE
TMS320 DSP
Display
ESIEE, Slide 58
Copyright © 2003 Texas Instruments. All rights reserved.
Sequence Diagram
VB or OLE
application
Code
Composer
Initialization
Create RTDX
Connection
DSP
RTDX: Create Input
Channel
RTDX: Create Output
Channel
Get handle for
RTDX channel
RTDX handle
Send RTDX
commands to DSP
Send some control
commands to DSP
rtdxToDSP.write
rtdxCommandHandler
RTDX: Get control
commands
rtdxCommandHandler
ESIEE, Slide 61
Copyright © 2003 Texas Instruments. All rights reserved.
Why CSL?

Why do we need a Chip Support
Library (CSL)?



ESIEE, Slide 62
To support increasingly complex on-chip
peripherals and applications
Frees the user from necessity of defining
and maintaining code for peripheral
configuration and control
Provide standard method for accessing and
controlling peripherals
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Introduction
 CSL –

Runtime library designed to configure, control, and
manage on-chip peripherals

Adapted for both C6000™ and C5000™ DSP
platforms

Written mostly in C, optimized for code size and speed

Partitioned into scalable/expandable API modules

ESIEE, Slide 63
Chip Support Library
Module granularity is structured such that each
peripheral is covered by a single API
Copyright © 2003 Texas Instruments. All rights reserved.
CSL: On-Chip Peripherals
C54x™ DSP Modules
CHIP
DAA
DAT
DMA
EBUS
GPIO
HPI
IRQ
MCBSP
PLL
PWR
UART
WDTIM
ESIEE, Slide 64
C55x™ DSP Modules
ADC
CHIP
DAT
DMA
EMIF
GPIO
IRQ
I2C
MCBSP
PLL
PWR
RTC
USB
WDTIM
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Features
 Standard
protocol for programming onchip peripherals: set of APIs (functions,
data types, macros)
 Symbolic peripheral description (hardware
abstraction) set of macros for accessing and
building register and field values
 Basic resource management for multiresource peripherals
 Integrated into DSP/BIOS™ build: CSL
Graphic User Interface
 Peripheral ease-of-use: shortened
development time, portability
ESIEE, Slide 65
Copyright © 2003 Texas Instruments. All rights reserved.
TI Foundation Software
Chip Support Library is Dedicated to the On-Chip Peripherals
User Application
Drivers
CSL
DSP/BIOS™
Kernel/Scheduler
Timer McBSP EMIF
CPU
DSP
Dsplib
Imglib
CODEC
DIP
Switches
Target Board
ESIEE, Slide 66
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Naming Conventions
 All
data structures, functions and macros begin
with the capitalized 3–4 letter module/peripheral
name followed by an underscore, PER_ .
(e.g. MCBSP_xxx, DMA_xxx)
 All data structures begin with a capital letter in
the word immediately following the underscore,
PER_Xxxx
(e.g. DMA_Config, I2C_Init)
 All functions begin with lowercase letter in the
word immediately following the underscore,
PER_xxx
(e.g. DMA_open, MCBSP_config)
 All macros are in upper case, PER_XXX
(e.g. MCBSP_RGETH(…), DMA_ADDRH(…))
ESIEE, Slide 67
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Resource Management
Data Types and Functions
 CSL handle

data type
PER_Handle: pointer to data structure
returned from call to PER_open() for multiresource modules (e.g. McBSP, DMA, etc.)
 CSL functions

Handle = PER_open(): allocation of a multiresource peripheral device. Returns handle
associated to the allocated resource (e.g.
McBSP port or DMA channel)
Ex: hDma =
DMA_open(DMA_CHA2,DMA_OPEN_RESET);

PER_close(Handle): de-allocation of a
previously opened multi-resource device
Ex: DMA_close(hDma);
ESIEE, Slide 68
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Configuration
 Register-based
configuration
PER_Config: data structure containing values
for all control registers needed to configure the
peripheral
 PER_config([handle], PER_Config *config):
configure the peripheral by setting the full values
of memory-map registers.
Ex: EMIF_config(&myconfig);
DMA_config(hDma,&myconfig);

 Parameter-based
configuration
PER_Init: data structure containing functional
parameters needed to configure the peripheral
 PER_init(PER_Init *init) configure the
peripheral via a set of parameters.
Ex: I2C_init(&myParams);

ESIEE, Slide 69
Copyright © 2003 Texas Instruments. All rights reserved.
Sample CSL Configuration Structure
typedef struct {
Uint16 dmacsdp;
Uint16 dmaccr;
Uint16 dmacicr;
DMA_AdrPtr dmacssal;
Uint16 dmacssau;
DMA_AdrPtr dmacdsal;
Uint16 dmacdsau;
Uint16 dmacen;
Uint16 dmacfn;
Uint16 dmacfi;
Uint16 dmacei;
} DMA_Config;
ESIEE, Slide 70
Copyright © 2003 Texas Instruments. All rights reserved.
Initializing CSL Config Structures

Creating register masks


User generated
Use PER_REG_RMK macros provided by
CSL


Use other pre-defined CSL macros such as
PER_FMK(reg,field,val) to create mask

ESIEE, Slide 71
DMA_DMAGCR_RMK(0,0,1)
DMA_FMK(DMAGCR,FREE,1)
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Coding Checklist
1. Include the appropriate CSL API headers (csl.h,
csl_per.h)
2. Declare and initialize CSL configuration data
structures and handles (DMA_Config
myDmaCfg = {…}; DMA_Handle hDma0;)
3. Call CSL_init() prior to calling or using any
other CSL API function
4. For multi-resource peripherals such as McBSP
and DMA, call PER_open() function to reserve
resource (MCBSP_open(), DMA_open()…)
5. Call PER_config() to configure peripheral
6. Call PER_start() to begin peripheral operation
7. Call PER_close() to free resources of multiresource peripherals
ESIEE, Slide 72
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Example (DMA)
#include <csl.h>
1. Include Headers
#include <csl_dma.h>
2. Declare CSL Data Objects
DMA_Handle hDma0;
DMA_Config dmaCfg0 = { …};
void main() {
3. Initialize Library
4. Open DMA Channel (returns
DMA_Handle to hDma0)
CSL_init();
hDma0 = DMA_open(DMA_CHA0, DMA_OPEN_RESET);
5. Configure Channel
(note use of hDma0)
DMA_config(hDma0,&dmaCfg0);
DMA_start(hDma0);
6. Start Transfer
while(!(DMA_FGETH(hDma0,DMACSR,FRAME));
// Process data
DMA_close(hDma0);
}
ESIEE, Slide 73
7. Close/Free DMA
Channel
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Compile/Link CheckList
1. Use –dCHIP_XXXX to select the correct
target device. (e.g. CHIP_5510PG1_0)
cl55 –dCHIP_5510PG1_0 myFile.c
2. For C5000™ DSPs, in a linker command file
always include .csldata in the SECTIONS
directive of the linker command file. The
.csldata section should be linked into data
RAM
3. Include the correct library, cslXXXX.lib, (e.g.
csl5510PG1_0.lib)
ESIEE, Slide 74
Copyright © 2003 Texas Instruments. All rights reserved.
Using the CSL GUI
1. Select A Default
Configuration Database
Seed
ESIEE, Slide 75
Copyright © 2003 Texas Instruments. All rights reserved.
These are the only two elements
needed for CSL configuration
ESIEE, Slide 76
Copyright © 2003 Texas Instruments. All rights reserved.
2. Select target
ESIEE, Slide 77
Copyright © 2003 Texas Instruments. All rights reserved.
3. Expand CSL Tree
Peripheral
Configuration
Peripheral Resource
Management
ESIEE, Slide 78
Copyright © 2003 Texas Instruments. All rights reserved.
4. Use Configuration
Manager to insert a
new configuration
object
ESIEE, Slide 79
Copyright © 2003 Texas Instruments. All rights reserved.
Inserted DMA
Configuration
Object
ESIEE, Slide 80
Copyright © 2003 Texas Instruments. All rights reserved.
DATA TYPE has
pull-down menu
Number of Elements
uses input box
ESIEE, Slide 81
Copyright © 2003 Texas Instruments. All rights reserved.
5. Use
Properties
pages to
set/change
configuration
parameters
ESIEE, Slide 82
Copyright © 2003 Texas Instruments. All rights reserved.
User may
choose to
set
register
values
manually
ESIEE, Slide 83
Scroll bar
indicates more
information
available
Copyright © 2003 Texas Instruments. All rights reserved.
6. Select resource
object and set its
properties
ESIEE, Slide 84
Resource Object
Properties
Copyright © 2003 Texas Instruments. All rights reserved.
The pull-down menu
displays all DMA
configuration objects
currently defined
ESIEE, Slide 85
Copyright © 2003 Texas Instruments. All rights reserved.
8. Save the new configuration file.
(Note:The base name of the saved
configuration database file determines
the name of the generated files)
ESIEE, Slide 86
Copyright © 2003 Texas Instruments. All rights reserved.
Generated Files
– updated configuration database
containing all inserted objects and all current
property settings
 myprojectcfg.h – extern declaration of all created
objects, definition of CHIP_XXXX, plus #include
of CSL module headers
 myprojectcfg_c.c – definition and initialization of
created objects. Contains function calls to
PER_open,PER_config/PER_init() for preopened/ pre-initialized objects
 myprojectcfg.sXX – defines which DSP/BIOS™
elements are present and provides initialization
for those elements
 myprojectcfg.cmd – linker command file, includes
CSL library and .csldata placement
 myproject.cdb
ESIEE, Slide 87
Copyright © 2003 Texas Instruments. All rights reserved.
myprojectcfg.h
#include <csl_dma.h>
extern DMA_Config dmaCfg0;
extern DMA_Handle hDma0;
extern void CSL_cfgInit();
ESIEE, Slide 88
Copyright © 2003 Texas Instruments. All rights reserved.
myprojectcfg_c.c
DMA_Config dmaCfg0 = {
0x0205,
/* (CSDP) */
0x5060,
/* (CCR)
*/
0x0008,
/* (CICR) */
(DMA_AdrPtr)&src, /* (CSSA_L) */
NULL,
/* (CSSA_U) */
(DMA_AdrPtr)&dst, /* (CSDA_L) */
NULL,
/*
(CSDA_U) */
0x0080,
/* (CEN) */
0x0001,
/* (CFN) */
0x0000,
/* (CFI) */
0x0000
/* (CEI) */
};
DMA_Handle hDma0;
ESIEE, Slide 89
Copyright © 2003 Texas Instruments. All rights reserved.
CSL_cfgInit()
Choosing Pre-Open in CSL GUI
CSL_cfgInit()
results in code generated to call
PER_open function
void
{
…
hDma0 =
DMA_open(DMA_CHA0,DMA_OPEN_RESET);
DMA_config(hDma0, &dmaCfg0);
}
ESIEE, Slide 90
Choosing Pre-Initialization in CSL
GUI results in code to call
PER_config function
Copyright © 2003 Texas Instruments. All rights reserved.
C Source Using GUI-Generated Files
Include generated
“myprojectcfg.h"C header file
#include
#define N
128
Uint16 src[N];
Uint16 dst[N];
void main(void)
{
DMA_start(hDma0);
while
Start DMA
(!DMA_FGETH(hDma0,DMACSR,FRAME));
Free Resource
DMA_close(hDma0);
ESIEE, Slide 91
}
Copyright © 2003 Texas Instruments. All rights reserved.
CSL Macros
Macros for accessing field and register values
Gets the memory address of the specified
PER_ADDR(reg)
peripheral register reg

Returns the value of the specified peripheral
register reg
Writes the value val to the peripheral register reg
PER_RSET(reg,val)
the value of the specified field of the
PER_FGET(reg,field) Returns
register
PER_FSET(reg,field,va Writes the value val to the specified field of the
register
l)
PER_RGET(reg)
Macros for building field and register values
Creates a register value to store in the register
PER_REG_RMK(

fieldmsb ,…, fieldlsb )
PER_FMK(reg, field,
val()
Creates a shifted version of the fieldvalue could
be used by PER_REG _RMK()
Note: Handle-based macros are also available.
ESIEE, Slide 92
Copyright © 2003 Texas Instruments. All rights reserved.
Literature
System Software TMS320C54X

SPRU328
SPRU423
SPRU404

SPRU420

SPRU433


Code Composer Studio User's Guide
TMS320 DSP/BIOS User's Guide
TMS320C5000 DSP/BIOS API Reference
Guide
TMS320C54x Chip Support Library API
User’s Guide
TMS320C55x Chip Support Library API
User’s Guide
Refer to Digital Library on this CD.
ESIEE, Slide 93
Copyright © 2003 Texas Instruments. All rights reserved.
DSP/BIOS Application Notes
SPRA697
SPRA646
SPRA648
SPRA640
SPRA660
SPRA653
SPRA663
SPRA692
SPRA689
SPRA700
SPRA599
SPRA695
SPRA598
SPRA591
ESIEE, Slide 94
How to Get Started with DSP/BIOS II
DSP/BIOS II Technical Overview
Understanding the Functional Enhancements of DSP/BIOS II
and their Utilization in Real-Time DSP Applications
Programming and Debugging Tips for DSP/BIOS
Building DSP/BIOS Programs in UNIX
Understanding Basic DSP/BIOS Features
Benchmarking DSP/BIOS II on the TMS320C54x
DSP/BIOS II Sizing Guidelines for the TMS320C54x DSP
Using DSP/BIOS I/O in Multichannel Systems
Writing Flexible Device Drivers for DSP/BIOS
DSP/BIOS and TMS320C54X Extended Addressing
Real-Time DSP Software Design for a Portable MP3 Player
Using DSP/BIOS
An Audio Example Using DSP/BIOS
DSP/BIOS by Degrees: Using DSP/BIOS in an existing
application
Copyright © 2003 Texas Instruments. All rights reserved.