Top Banner
DSP C5000 DSP C5000 Chapter 7 Chapter 7 DSP BIOS DSP BIOS Copyright © 2003 Texas Instruments. All rights reserve Copyright © 2003 Texas Instruments. All rights reserve
92

DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

Mar 26, 2015

Download

Documents

Hayden Sandoval
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

DSP C5000DSP C5000

Chapter 7Chapter 7DSP BIOSDSP BIOS

Copyright © 2003 Texas Instruments. All rights reserved.Copyright © 2003 Texas Instruments. All rights reserved.

Page 2: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 2 Copyright © 2003 Texas Instruments. All rights reserved.

Real-time schedulerReal-time schedulerPreemptive thread management kernelPreemptive thread management kernel

Real-time analysis toolsAllows application to run uninterrupted while displaying Allows application to run uninterrupted while displaying debug datadebug data

Real-time data exchange (RTDX)Allows two-way communication (target Allows two-way communication (target host) while host) whiletarget is runningtarget is running

Programming of DSP peripherals Programming of DSP peripherals Graphical input to peripheral initialization through Chip Graphical input to peripheral initialization through Chip Support Library (CSL)Support Library (CSL)

DSP BIOS Offers the Following:DSP BIOS Offers the Following:

Page 3: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 3 Copyright © 2003 Texas Instruments. All rights reserved.

DSP/BIOS Configuration ToolDSP/BIOS Configuration Tool

Configures SystemConfigures System Creates and defines objects Creates and defines objects

(ex. IDL)(ex. IDL) Configure hardware Configure hardware

interrupts and creates interrupts and creates interrupt vectorsinterrupt vectors

Configures memory and Configures memory and creates linker command filecreates linker command file

Calculates estimated data Calculates estimated data and minimum stack size and minimum stack size neededneeded

Creating a New Creating a New Configuration FileConfiguration File

Page 4: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 4 Copyright © 2003 Texas Instruments. All rights reserved.

Files Generated by the Configuration ToolFiles Generated by the Configuration Tool

program.cdbprogram.cdb

programcfg.h##programcfg.h##

programcfg.s##programcfg.s##

programcfg.cmdprogramcfg.cmd

Configuration database fileConfiguration database fileSaveSave

Allocated at link timeAllocated at link time

programcfg_c.cprogramcfg_c.c

programcfg.hprogramcfg.h

Page 5: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 5 Copyright © 2003 Texas Instruments. All rights reserved.

File ExtensionsFile Extensions

prog.cprog.c

Compiler/Compiler/AssemblerAssembler

progcfg.h##progcfg.h##progcfg.s##progcfg.s## progcfg.cmdprogcfg.cmd

prog.hprog.hprog.cmdprog.cmd(optional)(optional)

progcfg.objprogcfg.obj

mod.hmod.h

LinkerLinker

prog.asmprog.asm

prog.objprog.obj

prog.cdbprog.cdb

user.libuser.lib*.lib*.lib

prog.outprog.out

Page 6: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 6 Copyright © 2003 Texas Instruments. All rights reserved.

Startup SequenceStartup Sequence

interrupt enable bits OFFinterrupt enable bits OFF

““other” initializationother” initialization

BIOS_reset()BIOS_reset()

interrupt flag bits OFFinterrupt flag bits OFF

vector table pointer initializedvector table pointer initialized

BIOS_init()BIOS_init()do hardware initializationdo hardware initialization

enableenable individual individual interrupts interrupts

returnreturn

main()main()

HWI_startup()HWI_startup() enables HWI enables HWI

start DSP/BIOS schedulerstart DSP/BIOS scheduler

BIOS_start()BIOS_start()

interrupt enablesinterrupt enablesinterrupt flagsinterrupt flags

global int enableglobal int enable

IMRIMR

IFRIFR

INTMINTM

C5000C5000

system codesystem code user codeuser code

Page 7: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 7 Copyright © 2003 Texas Instruments. All rights reserved.

Startup SequenceStartup Sequence Initialize the DSP and the hardwareInitialize the DSP and the hardware

The software stack pointer, memory wait states, memory The software stack pointer, memory wait states, memory configuration registersconfiguration registers

This is part of the boot.c file that is part of the DSP/BIOS libraryThis is part of the boot.c file that is part of the DSP/BIOS library

BIOS_init( ) is called automaticallyBIOS_init( ) is called automatically Initializes DSP/BIOS modulesInitializes DSP/BIOS modules

main()main() System initialization that needs to be performedSystem initialization that needs to be performed Enable selected interrupts before interrupts are enabled globallyEnable selected interrupts before interrupts are enabled globally Must return to complete the program initialization!!!!Must return to complete the program initialization!!!!

BIOS_start( ) is called automaticallyBIOS_start( ) is called automatically Start DSP/BIOSStart DSP/BIOS Enables interrupts globallyEnables interrupts globally

Drops into the DSP/BIOS “background loop”Drops into the DSP/BIOS “background loop” Initializes communication with the host for real-time analysisInitializes communication with the host for real-time analysis

Page 8: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 8 Copyright © 2003 Texas Instruments. All rights reserved.

Real-time SystemsReal-time Systems

Systems that respond in a Systems that respond in a correctcorrect and and timelytimely way way to eventsto events

Events are occurrences that cause a non-Events are occurrences that cause a non-sequential change in the sequential change in the software flow of controlsoftware flow of control Driven by hardware and software eventsDriven by hardware and software events

Interrupt signalsInterrupt signals IF-THEN and CASE statements IF-THEN and CASE statements

Real-time SystemReal-time Systeminputsinputs outputsoutputs

Page 9: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 9 Copyright © 2003 Texas Instruments. All rights reserved.

Real-time Systems attributesReal-time Systems attributes

Events driven:Events driven: Synchronous (end of internal timer counting).Synchronous (end of internal timer counting). Asynchronous (ADC or DAC interrupt).Asynchronous (ADC or DAC interrupt).

Time constrained:Time constrained: Hard (Hard (Critical deadlines, catastrophic). Critical deadlines, catastrophic). Soft (Soft (Non-critical deadlines, non-catastrophic)Non-critical deadlines, non-catastrophic)..

Concurrency:Concurrency: Processing more than one event apparently Processing more than one event apparently

“simultaneously” to meet deadlines“simultaneously” to meet deadlines Means: Preemption & multi-tasking.Means: Preemption & multi-tasking.

Deterministic & reliable:Deterministic & reliable: Will always have the same behaviour Will always have the same behaviour within a within a

known response time.known response time.

Page 10: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 10 Copyright © 2003 Texas Instruments. All rights reserved.

Audio ExampleAudio Example

For this system to function properly, theFor this system to function properly, thefilter needs to calculate the filter needs to calculate the correctcorrect output output beforebefore the next sample arrivesthe next sample arrives

What events drive this system?What events drive this system? Receive and Transmit InterruptsReceive and Transmit Interrupts

Asynchronous Event - could happen at different points in codeAsynchronous Event - could happen at different points in code

Polling of Receive and Transmit conditionsPolling of Receive and Transmit conditions Synchronous Event - always happens at the same place in codeSynchronous Event - always happens at the same place in code

Audio FilterAudio FilterSampleSample SampleSample

Page 11: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 11 Copyright © 2003 Texas Instruments. All rights reserved.

TI DSPTI DSP

Real-time System RequirementsReal-time System Requirements

FilterFilter

AArunningrunning

idleidle

TimeTime 11 22 33 5544 66 7700

PeriodPeriod ComputeCompute CPU UsageCPU Usage

Routine Routine AA:: 22 22 ss 11 11 ss (50%)(50%)

Period = 1/fPeriod = 1/fss

Deadline!Deadline!

Page 12: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 12 Copyright © 2003 Texas Instruments. All rights reserved.

TI DSPTI DSP

Adding new function (new task)Adding new function (new task)

DTMFDTMF

FilterFilter Previous RequirementPrevious Requirement DSP filters audio signalDSP filters audio signal

New RequirementNew Requirement Add DTMF functionAdd DTMF function DTMF is independent of filterDTMF is independent of filter Issues:Issues:

Do we have enough bandwidth (MIPS)?Do we have enough bandwidth (MIPS)? Will one routine conflict with the other?Will one routine conflict with the other? How do we create the compound system?How do we create the compound system?

Page 13: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 13 Copyright © 2003 Texas Instruments. All rights reserved.

System Implementation ConsiderationsSystem Implementation Considerations

DTMFDTMF

FilterFilter

mainmain{{while(1)while(1){{

}}}}

One method: put each algo into an One method: put each algo into an endless loop under mainendless loop under main

Problems:Problems:

What if algorithms run at What if algorithms run at differing rates? (eg: our filter differing rates? (eg: our filter runs ~ 44 KHz and the DTMF runs ~ 44 KHz and the DTMF algo ~ 8 KHz)algo ~ 8 KHz)

What if one algorithm What if one algorithm overshadows another, starving it overshadows another, starving it for recognition or delaying it’s for recognition or delaying it’s response beyond the limits of the response beyond the limits of the system?system?

Page 14: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 14 Copyright © 2003 Texas Instruments. All rights reserved.

TI DSPTI DSP

Interrupt Driven System - ProblemInterrupt Driven System - Problem

PeriodPeriod ComputeCompute CPU UsageCPU Usage

Routine Routine AA:: 22 22 ss 11 11 ss (50%)(50%)Routine Routine BB:: 125 125 ss 33 33 ss (26%)(26%)

76%76%

TimeTime 11 22 33 5544 66 7700

BB

AArunningrunning

idleidle

yy11 yy22 yy33 yy44

Missed !Missed !

mainmain{{while(1);while(1);

}}

Timer1_ISRTimer1_ISR{{

}}

Timer2_ISRTimer2_ISR{{

}}BB

AA

There are There are twotwo elements of CPU loading: elements of CPU loading: average & instantaneousaverage & instantaneous

Only one can run at a time...Only one can run at a time...

Page 15: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 15 Copyright © 2003 Texas Instruments. All rights reserved.

AArunningrunning

idleidle

TimeTime 11 22 33 5544 66 7700

DSP/BIOS SchedulingDSP/BIOS Scheduling

BB

AA

mainmain{{return;return;

}}Timer1_ISRTimer1_ISR{{ start A;start A;}}

Timer2_ISRTimer2_ISR{{ start B;start B;}}

BB

DSP/BIOS provides scheduling:DSP/BIOS provides scheduling: Tasks are marked to be run by event processing Tasks are marked to be run by event processing

or other task.or other task. Scheduler supervises task running depending on Scheduler supervises task running depending on

status (mark to be run), priority, …status (mark to be run), priority, …

Modules written independentlyModules written independentlyEasier to maintain - Module interaction minimizedEasier to maintain - Module interaction minimizedBuilt-in Scheduling - Managed by DSP/BIOSBuilt-in Scheduling - Managed by DSP/BIOS

DSP/BIOSDSP/BIOSB suspendedB suspended

Page 16: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 16 Copyright © 2003 Texas Instruments. All rights reserved.

DSP/BIOS Preemptive SchedulerDSP/BIOS Preemptive Scheduler

Hardware InterruptsHardware Interrupts

Software InterruptsSoftware Interrupts

IdleIdle

ForegroundForeground

BackgroundBackground

Hard Real-timeHard Real-time

Soft Real-timeSoft Real-time

2nd-TIER RESPONSE2nd-TIER RESPONSE Frame-by-frameFrame-by-frame processing processing Millisecond duty cyclesMillisecond duty cycles

2nd-TIER RESPONSE2nd-TIER RESPONSE Frame-by-frameFrame-by-frame processing processing Millisecond duty cyclesMillisecond duty cycles

1st-TIER RESPONSE1st-TIER RESPONSE Sample-by-sampleSample-by-sample processing processing Microsecond duty cyclesMicrosecond duty cycles

1st-TIER RESPONSE1st-TIER RESPONSE Sample-by-sampleSample-by-sample processing processing Microsecond duty cyclesMicrosecond duty cycles

Best EffortBest EffortBest EffortBest Effort

Page 17: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 17 Copyright © 2003 Texas Instruments. All rights reserved.

PreemptionPreemption The act of changing the flow of control The act of changing the flow of control

from one process to another based on from one process to another based on prioritypriority Higher priority always runsHigher priority always runs Allows one process to asynchronously Allows one process to asynchronously

interrupt the execution of the currently interrupt the execution of the currently executing processexecuting process Concurrent processingConcurrent processing

PreemptedPreempted

CompletedCompleted

PostedPosted

StartedStarted

InactiveInactive ReadyReady RunningRunningResumeResume

Page 18: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 18 Copyright © 2003 Texas Instruments. All rights reserved.

DSP BIOS SchedulerDSP BIOS Scheduler

Fast response to interruptsFast response to interrupts Minimal context switchingMinimal context switching High priority for CPUHigh priority for CPU Can post SWICan post SWI Danger of missing an Danger of missing an

interrupt while executing ISRinterrupt while executing ISR

Latency in response timeLatency in response time Context switch performedContext switch performed Selectable priority levelsSelectable priority levels Can post another SWICan post another SWI Execution managed by Execution managed by

schedulerscheduler

DMAC2 INTDMAC2 INT

HWI_enterHWI_enter

h/w real-time codeh/w real-time code

PostPost s/w interrupt ( s/w interrupt (SWISWI))

HWI_exitHWI_exit

SWI:SWI:

filter codefilter code

SWI PendingSWI Pending

The The SchedulerScheduler provides both h/w and s/w interrupt management provides both h/w and s/w interrupt management

HWIHWI SWISWI

Let’s look at a scheduling example...Let’s look at a scheduling example...

Page 19: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 19 Copyright © 2003 Texas Instruments. All rights reserved.

Priority Based Thread SchedulingPriority Based Thread Scheduling

HWI 2HWI 2

HWI 1HWI 1

SWI 3SWI 3

SWI 2SWI 2

SWI 1SWI 1

MAINMAIN

IDLEIDLE

int1

rtnrtn

post2post2 rtnrtn

int2

post3post3 rtnrtn

post1post1 rtnrtn

rtnrtn

rtnrtn

User sets the priority...BIOS does the schedulingUser sets the priority...BIOS does the scheduling

subroutinesubroutine ISRISR functionfunction

A A threadthread may be a: may be a:

How do you set the priorities ?How do you set the priorities ?

(highest)(highest)

(lowest)(lowest)

Page 20: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 20 Copyright © 2003 Texas Instruments. All rights reserved.

Interrupts that Post SWIInterrupts that Post SWI

isrisrisrisr

p = 2p = 2p = 2p = 2

p = 1p = 1p = 1p = 1

IdleIdleIdleIdle

Use HWI_enter and HWI_exit assembly macrosUse HWI_enter and HWI_exit assembly macros APIs that may affect scheduling: APIs that may affect scheduling:

SWI_andn, SWI_dec, SWI_inc, SWI_or, SWI_post,SWI_andn, SWI_dec, SWI_inc, SWI_or, SWI_post,

PIP_alloc, PIP_free, PIP_get, PIP_put, PRD_tick,PIP_alloc, PIP_free, PIP_get, PIP_put, PRD_tick,

SEM_postSEM_post

time time

RunningRunning

ReadyReady

postpost HWI_exitHWI_exitHWI_enterHWI_enter

Page 21: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 21 Copyright © 2003 Texas Instruments. All rights reserved.

HWI_enter and HWI_exitHWI_enter and HWI_exit

HWI_enterHWI_enter Saves selected Saves selected

registersregisters Sets interrupt mask Sets interrupt mask

to disable/enable to disable/enable nested interruptsnested interrupts

Informs scheduler Informs scheduler to delay running to delay running newly posted SWInewly posted SWI

HWI_exitHWI_exit Restores selected Restores selected

registersregisters Restores interrupt Restores interrupt

maskmask Returns from Returns from

interruptinterrupt

These APIs can only be called from assembly.These APIs can only be called from assembly.

Page 22: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 22 Copyright © 2003 Texas Instruments. All rights reserved.

Writing an ISR in AssemblyWriting an ISR in Assembly(C54x)(C54x)

.def isr1.def isr1

isr1:isr1:

;save context (PUSHM);save context (PUSHM)

;ISR code;ISR code

;restore context (POPM);restore context (POPM)

;return from interrupt;return from interrupt

Template ISR with no Template ISR with no scheduling APIs calledscheduling APIs called

.include hwi.h54.include hwi.h54

.include swi.h54.include swi.h54

.def isr1.def isr1

isr1:isr1:

HWI_enter MASK,IMRDISABLEMASKHWI_enter MASK,IMRDISABLEMASK

SWI_postSWI_post

;other ISR code ;other ISR code

HWI_exit MASKS,IMRRESTOREMASKHWI_exit MASKS,IMRRESTOREMASK

SWI_post exampleSWI_post example

Pros/Cons of HWI_enter and HWI_exitPros/Cons of HWI_enter and HWI_exit Easy way to save/restore registersEasy way to save/restore registers Able to call scheduling APIsAble to call scheduling APIs Allows for nested interrupts (preemption)Allows for nested interrupts (preemption) Execution overheadExecution overhead Callable only from AssemblyCallable only from Assembly

Page 23: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 23 Copyright © 2003 Texas Instruments. All rights reserved.

HWI_enter and HWI_exit HWI_enter and HWI_exit (C54x)(C54x)

MASK - registers to save/restoreMASK - registers to save/restore

IMRDISABLEMASK, IMRRESTOREMASK - IMRDISABLEMASK, IMRRESTOREMASK - IMR bits to mask (1s) IMR bits to mask (1s)

or restore (1s)or restore (1s)

HWI_enter MASK IMRDISABLEMASKHWI_enter MASK IMRDISABLEMASK

HWI_exit MASK IMRRESTOREMASKHWI_exit MASK IMRRESTOREMASK

.include c54.h54 ; mask constants.include c54.h54 ; mask constants

.include hwi.h54 ; HWI module definitions.include hwi.h54 ; HWI module definitions

HWI_enter C54_A|C54_B,0x0008HWI_enter C54_A|C54_B,0x0008 Saves the A and B accumulators, disables TINT0, all other INTs Saves the A and B accumulators, disables TINT0, all other INTs

nestednested

HWI_enter C54_CNOTPRESERVED,0xFFFFHWI_enter C54_CNOTPRESERVED,0xFFFF

Saves C “Save on Call” registers, disables all nested interruptsSaves C “Save on Call” registers, disables all nested interrupts

Page 24: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 24 Copyright © 2003 Texas Instruments. All rights reserved.

Hardware Interrupt DispatcherHardware Interrupt Dispatcher

Automatically includes HWI_enter and exit Automatically includes HWI_enter and exit via a stub functionvia a stub function

Can be used with ISR’s written in CCan be used with ISR’s written in C

Page 25: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 25 Copyright © 2003 Texas Instruments. All rights reserved.

Int i; /*global var*/Int i; /*global var*/

{{

HWI_enter(MASKS)HWI_enter(MASKS)

i++;i++;

SWI_post(&swiAudio)SWI_post(&swiAudio)

HWI_exit(MASKS)HWI_exit(MASKS)

}}

void isr1(void)void isr1(void)

Writing an ISR in CWriting an ISR in C

ISR can be purely in C if no scheduling APIs are ISR can be purely in C if no scheduling APIs are calledcalled Declare as Declare as interrupt void isr1(void)interrupt void isr1(void)

Don’t use Don’t use interruptinterrupt keyword if calling with keyword if calling with HWI_enter and HWI_exit ISR!HWI_enter and HWI_exit ISR! HWI_exitHWI_exit does a return from interrupt does a return from interrupt

Page 26: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 26 Copyright © 2003 Texas Instruments. All rights reserved.

HARDWARE INTERRUPTHARDWARE INTERRUPT

IDLEIDLE

minpriminpri

maxprimaxpri

1515

XXXX

XXXX

DSP/BIOS (SWI) Software InterruptsDSP/BIOS (SWI) Software Interrupts

Defer hardware interrupt Defer hardware interrupt service routines to software service routines to software interruptsinterrupts

PreemptivePreemptive Priority 0-14Priority 0-14

Context SwitchContext Switch Automatic for SWIAutomatic for SWI

Single stack model (Application Single stack model (Application Stack)Stack)

Adding priority levels will Adding priority levels will increase stack size requirementsincrease stack size requirements

Page 27: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 27 Copyright © 2003 Texas Instruments. All rights reserved.

fxnfxn

arg0arg0

arg1arg1

prioritypriority

mailboxmailbox

fxnfxn

arg0arg0

arg1arg1

prioritypriority

mailboxmailbox

fxnfxn

arg0arg0

arg1arg1

prioritypriority

mailboxmailbox

FIRFIR

FFTFFT

C funcC func

ASM funcASM func

SWI_objSWI_obj

SWI_objSWI_obj

SWI_objSWI_obj CommonCommon.stack.stack

Software Interrupt ObjectsSoftware Interrupt Objects

SWI_Obj (example)SWI_Obj (example) Pointer to a functionPointer to a function Arg0 and Arg1Arg0 and Arg1 PriorityPriority Initial Bit/Count Initial Bit/Count

valuevalue Will cover laterWill cover later

All interrupts run All interrupts run on a common stackon a common stack Stores local Stores local

variablesvariables Nested function callsNested function calls

Page 28: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 28 Copyright © 2003 Texas Instruments. All rights reserved.

Scheduling Rules and SWI APIScheduling Rules and SWI API

isrisrisrisr

p = 1p = 1p = 1p = 1

p = 1p = 1p = 1p = 1

IdleIdleIdleIdle

p = 2p = 2p = 2p = 2

time time

Highest PriorityHighest Priority

Lowest PriorityLowest Priority

RunningRunning

ReadyReady

postpost

postpost

SWI_post()SWI_post() Unconditionally post a software interruptUnconditionally post a software interrupt

Software interrupt is posted in the ready stateSoftware interrupt is posted in the ready state

Page 29: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 29 Copyright © 2003 Texas Instruments. All rights reserved.

DSP/BIOS Software Interrupt MailboxDSP/BIOS Software Interrupt Mailbox

Used to conditionally or unconditionally Used to conditionally or unconditionally post software interruptpost software interrupt

Can be used as a counter or a bit fieldCan be used as a counter or a bit field Set a bit to notify how SWI was postedSet a bit to notify how SWI was posted Allows multiple conditions to be met before Allows multiple conditions to be met before

a SWI can runa SWI can run Allows to monitor missed SWIAllows to monitor missed SWI

Mailbox is an int value (16 bits for C5000)Mailbox is an int value (16 bits for C5000)

SWI_inc SWI_inc incrementsincrements the mailbox and the mailbox and postsposts SWI C SWI C The Mailbox is reset when SWI C runsThe Mailbox is reset when SWI C runs Use Use SWI_getmbox()SWI_getmbox() to get previous mailbox value to get previous mailbox value

(must be 1)(must be 1)

Page 30: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 30 Copyright © 2003 Texas Instruments. All rights reserved.

Calling DSP/BIOS API from AssemblyCalling DSP/BIOS API from Assembly(C54x)(C54x)

.include swi.h54 ; SWI module definitions.include swi.h54 ; SWI module definitions

; Setup preconditions and save context; Setup preconditions and save context

stm _swiAudio,ar2 ; argument to SWI_post stm _swiAudio,ar2 ; argument to SWI_post

SWI_postSWI_post

retret ; return ; return

Example: Void SWI_post(SWI_Obj *swi);Example: Void SWI_post(SWI_Obj *swi); Preconditions: Preconditions: cpl = ovm = c16 = frct = cmpt = 0cpl = ovm = c16 = frct = cmpt = 0

dp = GBL_A_SYSPAGEdp = GBL_A_SYSPAGEar2 = address of SWI Objectar2 = address of SWI Objectintm = 0 (if outside an ISR)intm = 0 (if outside an ISR)

Post conditions: Post conditions: nonenone Modifies: Modifies: ag, ah, al, ar0, ar2, ar3, ar4, ar5, bg, ag, ah, al, ar0, ar2, ar3, ar4, ar5, bg,

bh, bl, c, dp, t, tcbh, bl, c, dp, t, tc

Page 31: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 31 Copyright © 2003 Texas Instruments. All rights reserved.

Counting Events: SWI_dec()Counting Events: SWI_dec()HWIHWI

SPSP BufferBuffer

SWI_dec(&SWI)SWI_dec(&SWI)

SWI BSWI B

SWI_dec() decrements the SWI_dec() decrements the mailboxmailbox value value SWI is posted if mailbox = 0SWI is posted if mailbox = 0 Set the initial mailbox value in the SWI’s propertiesSet the initial mailbox value in the SWI’s properties Mailbox is resets to initial value when SWI runsMailbox is resets to initial value when SWI runs

1111MailboxMailbox

Page 32: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 32 Copyright © 2003 Texas Instruments. All rights reserved.

Who Called: SWI_orWho Called: SWI_or

SWI ASWI A

SWI BSWI B

SWI CSWI C

SWI DSWI D

SWI SUBSWI SUB

switch(mailbox)switch(mailbox){{ case 1: {do this}case 1: {do this}

case 2: {do this}case 2: {do this}case 4: {do this}case 4: {do this}case 8: {do this}case 8: {do this} }}

SWI_or() sets a bit in the mailbox SWI_or() sets a bit in the mailbox andand posts the SWI posts the SWI Use SWI_getmbox() to read the mailbox and determine Use SWI_getmbox() to read the mailbox and determine

which routine posted the instance of the SWIwhich routine posted the instance of the SWI Mailbox is reset when SWI runsMailbox is reset when SWI runs

SWI_or(1)SWI_or(1)

SWI_or(2)SWI_or(2)

SWI_or(4)SWI_or(4)

SWI_or(8)SWI_or(8)

Int mailbox;Int mailbox;mailbox = SWI_getmbox();mailbox = SWI_getmbox();

Page 33: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 33 Copyright © 2003 Texas Instruments. All rights reserved.

Handling Conditions: SWI_andnHandling Conditions: SWI_andn

Adaptive FilterAdaptive FilterswiGetDataswiGetData

swiAdaptswiAdapt

swiFilterswiFilter

MailboxMailbox

1111

SWI_andn(1)SWI_andn(1)

00SWI_andn(2)SWI_andn(2) 00

Note: SWI_andn => mailboxNote: SWI_andn => mailbox ANDAND ( ( NOTNOT MASK ) MASK )

SWI_andn() clears a bit in the SWI_andn() clears a bit in the mailboxmailbox value value SWI is posted if mailbox = 0SWI is posted if mailbox = 0 Set the initial mailbox value in the SWI’s propertiesSet the initial mailbox value in the SWI’s properties Mailbox is resets to initial value when SWI runsMailbox is resets to initial value when SWI runs

Page 34: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 34 Copyright © 2003 Texas Instruments. All rights reserved.

Posting SWIs - A SummaryPosting SWIs - A Summary

Always postAlways post SWI_orSWI_or SWI_incSWI_inc

Post if mailbox = 0Post if mailbox = 0 SWI_andnSWI_andn SWI_decSWI_dec

SWI_postSWI_post

Mailbox isMailbox isa bitmaska bitmask

Mailbox is Mailbox is a countera counter N/AN/A

Use SWI_getmbox() to read Use SWI_getmbox() to read the mailboxthe mailbox

Set initial value of the mailboxSet initial value of the mailbox in the SWI’s properties in the SWI’s properties

Mailbox is reset when SWI runsMailbox is reset when SWI runs

Page 35: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 35 Copyright © 2003 Texas Instruments. All rights reserved.

Clock ManagerClock Manager

Timer ServicesTimer Services

CPU clockCPU clockraterate 44 Hi-resHi-res

ClockClock NN Low-resLow-resClockClock

max clockmax clockraterate

timertimercountercounter

timertimerperiodperiod

SystemSystemTickTick

interruptinterrupt

The Clock Manager configures:The Clock Manager configures: Period of the system tick - Period of the system tick - Timer PeriodTimer Period Functions that run as part of the timer ISR - Functions that run as part of the timer ISR - CLK_ObjectsCLK_Objects

DSP/BIOS configures a CLK Object, DSP/BIOS configures a CLK Object, PRD_clockPRD_clock, to manage, to manage A low and a high resolution time stampA low and a high resolution time stamp

Periodic FunctionsPeriodic Functions

Page 36: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 36 Copyright © 2003 Texas Instruments. All rights reserved.

f1(t)f1(t)

P1P1

P2P2

P3P3

P4P4

f2(t)f2(t)

f3(t)f3(t)

f4(t)f4(t)

TimerTimerInterruptInterrupt DSP/BIOSDSP/BIOS

PRD_tick()PRD_tick()PRD_clockPRD_clock PRD_swiPRD_swi

/ P/ P

Periodic Function ManagerPeriodic Function Manager PRD_clock will conditionally trigger the DSP/BIOS central PRD_clock will conditionally trigger the DSP/BIOS central

dispatcher via PRD_tickdispatcher via PRD_tick DSP/BIOS central dispatcher runs a software interrupt DSP/BIOS central dispatcher runs a software interrupt

called PRD_swicalled PRD_swi PRD_swi contains a list of periodic processes in a table PRD_swi contains a list of periodic processes in a table

PRD_swi will select the periodic functions to run based on PRD_swi will select the periodic functions to run based on the periodthe period Run at the same priority - FIFORun at the same priority - FIFO

Page 37: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 37 Copyright © 2003 Texas Instruments. All rights reserved.

Periodic ObjectsPeriodic Objects PeriodPeriod is the # of system ticks in which object’s is the # of system ticks in which object’s

function will runfunction will run FunctionFunction is the routine you want to executed is the routine you want to executed TypeType defines the nature of the periodic function defines the nature of the periodic function

Continuous vs. One-shotContinuous vs. One-shot

TimerTimerInterruptInterrupt

DSP/BIOSDSP/BIOS

PRD_tick()PRD_tick()PRD_swiPRD_swi

/ P/ P

PRD_clockPRD_clock

prdFunc1prdFunc1PeriodPeriod 44FunctionFunction func1()func1()TypeType continuouscontinuous

prdFunc2prdFunc2PeriodPeriod 99FunctionFunction func2()func2()TypeType continuouscontinuous

Page 38: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 38 Copyright © 2003 Texas Instruments. All rights reserved.

Continuous Periodic FunctionsContinuous Periodic Functions

Call the function Call the function everyevery N ticks N ticks Triggered by the system tickTriggered by the system tick

Timer interrupt orTimer interrupt or Periodic interrupt that calls PRD_tick()Periodic interrupt that calls PRD_tick()

func1()func1()

ticktick

11 22 33 44 55 66 77 88 99 1010

func1()func1() func2()func2()

prdFunc1prdFunc1PeriodPeriod 44FunctionFunction func1()func1()TypeType continuouscontinuous

prdFunc2prdFunc2PeriodPeriod 99FunctionFunction func2()func2()TypeType continuouscontinuous

Execution timelineExecution timeline

Page 39: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 39 Copyright © 2003 Texas Instruments. All rights reserved.

Communication TechniquesCommunication Techniques

Global variablesGlobal variables Can corrupt global data while preemptedCan corrupt global data while preempted

Queues (linked list)Queues (linked list) Useful for first-in, first-out sequencingUseful for first-in, first-out sequencing

Buffering of data using shared memoryBuffering of data using shared memory Time-relative bufferingTime-relative buffering

Useful for time-relative data transferred or for slow dataUseful for time-relative data transferred or for slow data Double or ping-pong bufferingDouble or ping-pong buffering

Ring or circular bufferingRing or circular buffering Use queues to pass pointers to arrays of data buffers in Use queues to pass pointers to arrays of data buffers in

memorymemory

Process 0Process 0 Process 1Process 1

Page 40: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 40 Copyright © 2003 Texas Instruments. All rights reserved.

QueueQueue

Simple data structure for basic Simple data structure for basic communicationcommunication

Useful for first-in, first-out processingUseful for first-in, first-out processing Manages a linked list of elementsManages a linked list of elements Includes atomic and non-atomic APIsIncludes atomic and non-atomic APIs Allows insertion and deletion anywhere Allows insertion and deletion anywhere

in the Queuein the Queue Elements can be any data structureElements can be any data structure

Must include QUE_ElemMust include QUE_Elem

Page 41: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 41 Copyright © 2003 Texas Instruments. All rights reserved.

Data PipesData Pipes

I/O building blocks between processes (and I/O building blocks between processes (and interrupts)interrupts)

A pipe object has 2 sides - writer and readerA pipe object has 2 sides - writer and reader Built-in notify functions are used to synchronize Built-in notify functions are used to synchronize Queued data buffers are allocated at link timeQueued data buffers are allocated at link time

Divided into a fixed number of frames of a particular sizeDivided into a fixed number of frames of a particular size nframesnframes framesizeframesize

SoftwareSoftware Interrupt Interrupt

PIP buffersPIP buffersSoftwareSoftware Interrupt Interrupt

Page 42: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 42 Copyright © 2003 Texas Instruments. All rights reserved.

MultitaskingMultitasking

Hardware InterruptsHardware Interrupts

Software InterruptsSoftware Interrupts

MultitaskingMultitasking

IdleIdle

ForegroundForeground

BackgroundBackground

Hard Real-timeHard Real-time

Soft Real-timeSoft Real-time

Page 43: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 43 Copyright © 2003 Texas Instruments. All rights reserved.

READY

RUNNING

BLOCKEDTERMINATEDTask suspendsTask exits

Task is readied

Task is deleted

Task is deleted

Preemption

Task Control Block ModelTask Control Block Model

TSK_exit()TSK_exit()

TSK_delete()TSK_delete()

TSK_sleep()TSK_sleep()

TSK_tick()TSK_tick()

TSK_delete()TSK_delete()

TSK_yield()TSK_yield()

DSP/BIOS StartupDSP/BIOS Startup

SEM_post()SEM_post()

SEM_pend()SEM_pend()

TSK_setpri()TSK_setpri()

Page 44: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 44 Copyright © 2003 Texas Instruments. All rights reserved.

Not dependent on ANot dependent on A

Not dependent on ANot dependent on A

Semaphores and PrioritySemaphores and Priority

BBBB

AAAA

Both B and C depend on ABoth B and C depend on A B pends on the semaphore first, then CB pends on the semaphore first, then C When A posts, B runs first because it pended firstWhen A posts, B runs first because it pended first Semaphores use a FIFO Queue for pending tasks!Semaphores use a FIFO Queue for pending tasks!

SEM_SEM_pend(semObj)pend(semObj)block!block!

SEM_postSEM_post(semObj)(semObj) preempted!preempted!

Precondition for B and CPrecondition for B and C

Depends on ADepends on APriority=1Priority=1

Priority=1Priority=1

time time

CCCC

SEM_SEM_pend(semObj)pend(semObj)block!block!

Priority=2Priority=2

interruptinterrupt

Page 45: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 45 Copyright © 2003 Texas Instruments. All rights reserved.

MBX_postMBX_post MBX_pendMBX_pendtask0task0

task1task1

task2task2

task3task3

task4task4

Mailbox APIMailbox API

MBX_post MBX_post Copies a message into a bufferCopies a message into a buffer Block if mailbox is full or if another writer Block if mailbox is full or if another writer

is waitingis waiting MBX_pendMBX_pend

Copies a message out of a bufferCopies a message out of a buffer Block if mailbox is empty or if another Block if mailbox is empty or if another

reader is waitingreader is waiting

Page 46: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 46 Copyright © 2003 Texas Instruments. All rights reserved.

Interfacing to MailboxesInterfacing to MailboxesVoid writer(Int id){Void writer(Int id){ MsgObj msg;MsgObj msg; Int i;Int i; for (i=0; ; i++) {for (i=0; ; i++) { msg.id = id;msg.id = id; msg.val = i % NUMMSGS + (Int)('a');msg.val = i % NUMMSGS + (Int)('a'); if ( MBX_post(&mbx, &msg, TIMEOUT) == 0 ){if ( MBX_post(&mbx, &msg, TIMEOUT) == 0 ){ SYS_abort("timeout %s”, TSK_getname());SYS_abort("timeout %s”, TSK_getname());}}}}}}

typedef struct MsgObj {typedef struct MsgObj { Int Int id;id; CharChar val;val;};};

Void reader(Void){Void reader(Void){ MsgObj msg;MsgObj msg; Int i;Int i; for (i=0; ;i++) {for (i=0; ;i++) { if (MBX_pend(&mbx, &msg, TIMEOUT) == 0) {if (MBX_pend(&mbx, &msg, TIMEOUT) == 0) { SYS_abort("timeout %s”, TSK_getname());SYS_abort("timeout %s”, TSK_getname()); }} LOG_printf(&logTrace,"%c from (%d)", msg.val, msg.id);LOG_printf(&logTrace,"%c from (%d)", msg.val, msg.id);}}}}

Page 47: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 47 Copyright © 2003 Texas Instruments. All rights reserved.

SWI vs. TSKSWI vs. TSK

User Name, Error Number,User Name, Error Number, Environment Pointer Environment Pointer NoNo YesYes

Stack ConfigurationStack Configuration Uses the SystemUses the SystemStackStack

Each Task has Each Task has its own Stackits own Stack

Blocking & SuspendingBlocking & Suspending NoNo YesYes

Deleted Prior to CompletionDeleted Prior to Completionby other Threadsby other Threads NoNo YesYes

SWISWI TSKTSK

API InterfaceAPI Interface Assembly and CAssembly and C CC

Page 48: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 48 Copyright © 2003 Texas Instruments. All rights reserved.

Disabling and Enabling InterruptsDisabling and Enabling Interrupts Hardware interruptsHardware interrupts

Atomic FunctionsAtomic Functions

SchedulerScheduler Can be nestedCan be nested

SWI_disable();SWI_disable();

`critical section``critical section`

SWI_enable();SWI_enable();

SWI_disable();SWI_disable();

`critical section``critical section`

SWI_enable();SWI_enable();

oldCSR = HWI_disable();oldCSR = HWI_disable();

`critical section``critical section`

HWI_restore(oldCSR);HWI_restore(oldCSR);

oldCSR = HWI_disable();oldCSR = HWI_disable();

`critical section``critical section`

HWI_restore(oldCSR);HWI_restore(oldCSR);

TSK_disable();TSK_disable();

`critical section``critical section`

TSK_enable();TSK_enable();

TSK_disable();TSK_disable();

`critical section``critical section`

TSK_enable();TSK_enable();

Page 49: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 49 Copyright © 2003 Texas Instruments. All rights reserved.

Built-in Real-Time Analysis ToolsBuilt-in Real-Time Analysis Tools What is “Real-Time” ?What is “Real-Time” ?

Gather data on target (3-10 CPU cycles)Gather data on target (3-10 CPU cycles) Send data during BIOS IDLE (100s of cycles)Send data during BIOS IDLE (100s of cycles) Format data on host (1000s of cycles)Format data on host (1000s of cycles) Data gathering does NOT stop target CPUData gathering does NOT stop target CPU

Software Logic AnalyzerSoftware Logic Analyzer Debug SchedulingDebug Scheduling Tick: specified time periodTick: specified time period based on hardware timer based on hardware timer

Execution GraphExecution Graph

Analyze time NOT Analyze time NOT spent in IDLE spent in IDLE

CPU Load GraphCPU Load Graph

Page 50: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 50 Copyright © 2003 Texas Instruments. All rights reserved.

Built-in Real-Time Analysis ToolsBuilt-in Real-Time Analysis Tools

Profile routines withoutProfile routines without halting the CPU halting the CPU

Statistics ViewStatistics View

Send debug msgs to hostSend debug msgs to host Std Std printfprintf requires: requires: - 27K bytes - 27K bytes - 30K CPU cycles - 30K CPU cycles LOG_printfLOG_printf requires: requires: - 32 bytes - 32 bytes - 30 CPU cycles - 30 CPU cycles

Message LOGMessage LOG

LOG_printf (&trace, “Loopback enabled”);LOG_printf (&trace, “Loopback enabled”);

Page 51: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 51 Copyright © 2003 Texas Instruments. All rights reserved.

??

DSP/BIOS ModulesDSP/BIOS ModulesDSP/BIOS LibraryDSP/BIOS Library

APPLICATION PROGRAM INTERFACEAPPLICATION PROGRAM INTERFACE

LOGLOGCLKCLK HSTHST HWIHWI IDLIDL TRCTRC

PIPPIP PRDPRD RTDXRTDX SWISWISTSSTS

LOGLOG

STSSTS

USER FUNCTIONSUSER FUNCTIONS

func1func1{{

}}

func2func2{{

}}

#include <sts.h>#include <sts.h>

func2func2{{

STS_set(…);STS_set(…);}}

#include <log.h>#include <log.h>

func1func1{{ LOG_printf(...);LOG_printf(...);}}

Page 52: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 52 Copyright © 2003 Texas Instruments. All rights reserved.

Creating and Reference InstancesCreating and Reference Instances Instances are created in Instances are created in

the Configuration Toolthe Configuration Tool Code that creates them is Code that creates them is

in audiocfg.s##in audiocfg.s## Object declaration is in Object declaration is in

mod.h (i.e. log.h)mod.h (i.e. log.h)

FunctionFunction#include <std.h> #include <std.h>

#include <log.h>#include <log.h>

extern far LOG_Obj logTrace1;extern far LOG_Obj logTrace1;

extern far LOG_Obj logTrace2;extern far LOG_Obj logTrace2;

func()func()

{{

LOG_printf( &logTrace1, … );LOG_printf( &logTrace1, … );

LOG_printf( &logTrace2, … );LOG_printf( &logTrace2, … );

}}

Instances must be Instances must be referenced (extern) by files referenced (extern) by files that use themthat use them

Header file is needed for Header file is needed for the declaration of the typethe declaration of the type

Page 53: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 53 Copyright © 2003 Texas Instruments. All rights reserved.

Interface to Statistics AccumulatorsInterface to Statistics Accumulators Count the number of occurrences of an eventCount the number of occurrences of an event

Track the maximum and average for a variableTrack the maximum and average for a variable

Tracking minimum value of a variableTracking minimum value of a variable

Timing events or monitoring incremental differences Timing events or monitoring incremental differences in a valuein a value

STS_add(&stsObj); /* count an event */STS_add(&stsObj); /* count an event */STS_add(&stsObj); /* count an event */STS_add(&stsObj); /* count an event */

STS_add(&stsObj, value); /* track the maximum and STS_add(&stsObj, value); /* track the maximum and average */average */STS_add(&stsObj, value); /* track the maximum and STS_add(&stsObj, value); /* track the maximum and average */average */

STS_add(&stsObj, -value); /* track the minimum *//* track the minimum */STS_add(&stsObj, -value); /* track the minimum *//* track the minimum */

STS_set(&stsObj, CLK_gethtime());

STS_delta(&stsObj, CLK_gethtime()); /* algorithm OR event */

STS_set(&stsObj, CLK_gethtime());

STS_delta(&stsObj, CLK_gethtime()); /* algorithm OR event */

Page 54: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 54 Copyright © 2003 Texas Instruments. All rights reserved.

STS API Effect on STS Object FieldsSTS API Effect on STS Object Fields

STS_add(x)STS_add(x)

CountCount

TotalTotal

MaxMax

Previous*Previous*

STS_set(y)STS_set(y) STS_delta(z)STS_delta(z) STS_resetSTS_reset

+1+1

+x+x

replacedreplacedif x > Maxif x > Max

yy zz

+1+1

+(z-Previous)+(z-Previous)

replaced ifreplaced if(z-Previous)(z-Previous)

> Max> Max

00

00

largestlargestnegativenegativenumbernumber

*Previous field is set using Config tool, STS_set, or STS_delta*Previous field is set using Config tool, STS_set, or STS_delta

Page 55: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 55 Copyright © 2003 Texas Instruments. All rights reserved.

Clock InterfaceClock Interface

CLK_getltime()CLK_getltime() Returns the number of timer interrupts Returns the number of timer interrupts

that have occurredthat have occurred CLK_gethtime()CLK_gethtime()

Returns the number of high resolution Returns the number of high resolution clock cycles that have occurredclock cycles that have occurred

CLK_countspms()CLK_countspms() Returns the number of timer register ticks Returns the number of timer register ticks

per millisecondper millisecond

Page 56: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 56 Copyright © 2003 Texas Instruments. All rights reserved.

Trace ControlTrace Control Allows the user to enable and disable Allows the user to enable and disable

instrumentation on the targetinstrumentation on the target Limit the effects of instrumentation on program Limit the effects of instrumentation on program

executionexecution Two interfacesTwo interfaces

Host interface Host interface RTA Control PanelRTA Control Panel

User ProgramUser ProgramTRC APITRC API

Page 57: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 57 Copyright © 2003 Texas Instruments. All rights reserved.

Target Trace Control MasksTarget Trace Control Masks

Trace Control MaskTrace Control Mask - declared in trc.h - declared in trc.h

TRC_LOGCLKTRC_LOGCLK LOG timer interruptsLOG timer interruptsTRC_LOGPRDTRC_LOGPRD LOG periodic ticks and PRD functionsLOG periodic ticks and PRD functionsTRC_LOGSWITRC_LOGSWI LOG software interrupt eventsLOG software interrupt eventsTRC_LOGTSKTRC_LOGTSK TSK eventsTSK eventsTRC_STSHWITRC_STSHWI Gather statistics on HWIGather statistics on HWITRC_STSPIPTRC_STSPIP Count number of frames in data pipesCount number of frames in data pipesTRC_STSPRDTRC_STSPRD Gather statistics on PRD function executionGather statistics on PRD function executionTRC_STSSWITRC_STSSWI Gather statistics on SWI executionGather statistics on SWI executionTRC_STSTSKTRC_STSTSK Gather statistics on TSK executionGather statistics on TSK executionTRC_USER0 TRC_USER0 User definedUser definedTRC_USER1 TRC_USER1 User definedUser definedTRC_USER2 TRC_USER2 User definedUser definedTRC_GBLTARG Global targetTRC_GBLTARG Global targetTRC_GBLHOST Global hostTRC_GBLHOST Global host

Trace Control MaskTrace Control Mask - declared in trc.h - declared in trc.h

TRC_LOGCLKTRC_LOGCLK LOG timer interruptsLOG timer interruptsTRC_LOGPRDTRC_LOGPRD LOG periodic ticks and PRD functionsLOG periodic ticks and PRD functionsTRC_LOGSWITRC_LOGSWI LOG software interrupt eventsLOG software interrupt eventsTRC_LOGTSKTRC_LOGTSK TSK eventsTSK eventsTRC_STSHWITRC_STSHWI Gather statistics on HWIGather statistics on HWITRC_STSPIPTRC_STSPIP Count number of frames in data pipesCount number of frames in data pipesTRC_STSPRDTRC_STSPRD Gather statistics on PRD function executionGather statistics on PRD function executionTRC_STSSWITRC_STSSWI Gather statistics on SWI executionGather statistics on SWI executionTRC_STSTSKTRC_STSTSK Gather statistics on TSK executionGather statistics on TSK executionTRC_USER0 TRC_USER0 User definedUser definedTRC_USER1 TRC_USER1 User definedUser definedTRC_USER2 TRC_USER2 User definedUser definedTRC_GBLTARG Global targetTRC_GBLTARG Global targetTRC_GBLHOST Global hostTRC_GBLHOST Global host

Page 58: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 58 Copyright © 2003 Texas Instruments. All rights reserved.

RTDX: Real-Time Data ExchangeRTDX: Real-Time Data Exchange

PCPC TMS320 DSPTMS320 DSP

JTAGJTAG

E M

UE

M U

R T

D X

R

T D

X

US

ER

CO

DE

US

ER

CO

DE

Third PartyThird PartyDisplayDisplay

CCSCCS

RTDX enables non-obtrusive two-way communicationRTDX enables non-obtrusive two-way communicationbetween the host PC and the DSP (during IDLE)between the host PC and the DSP (during IDLE)

Transfer speed limited by JTAG bandwidth (~10 MHz serial),Transfer speed limited by JTAG bandwidth (~10 MHz serial),connection type (parallel vs. XDS) and DSP activity levelconnection type (parallel vs. XDS) and DSP activity level

Transfers made via RTDX calls in DSP application codeTransfers made via RTDX calls in DSP application code

DisplayDisplay

UserUser TITI 3rd Party3rd Party

Page 59: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 61 Copyright © 2003 Texas Instruments. All rights reserved.

Sequence DiagramSequence Diagram

Get handle forGet handle forRTDX channelRTDX channel

RTDX handleRTDX handle

Send some controlSend some controlcommands to DSPcommands to DSP

rtdxToDSP.writertdxToDSP.write

RTDX: Get controlRTDX: Get controlcommandscommands

RTDX: Create InputRTDX: Create InputChannelChannel

InitializationInitialization

VB or OLE VB or OLE applicationapplication

CodeCodeComposerComposer DSPDSP

Create RTDXCreate RTDXConnectionConnection

Send RTDXSend RTDXcommands to DSPcommands to DSP

rtdxCommandHandlerrtdxCommandHandler

rtdxCommandHandlerrtdxCommandHandler

RTDX: Create OutputRTDX: Create OutputChannelChannel

Page 60: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 62 Copyright © 2003 Texas Instruments. All rights reserved.

Why CSL?Why CSL?

Why do we need a Chip Support Why do we need a Chip Support Library (CSL)?Library (CSL)? To support increasingly complex on-chip To support increasingly complex on-chip

peripherals and applicationsperipherals and applications Frees the user from necessity of defining Frees the user from necessity of defining

and maintaining code for peripheral and maintaining code for peripheral configuration and controlconfiguration and control

Provide standard method for accessing and Provide standard method for accessing and controlling peripheralscontrolling peripherals

Page 61: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 63 Copyright © 2003 Texas Instruments. All rights reserved.

CSL IntroductionCSL Introduction

CSL – Chip Support Library CSL – Chip Support Library

Runtime library designed to configure, control, and Runtime library designed to configure, control, and

manage on-chip peripheralsmanage on-chip peripherals

Adapted for both C6000™ and C5000™ DSP Adapted for both C6000™ and C5000™ DSP

platformsplatforms

Written mostly in C, optimized for code size and Written mostly in C, optimized for code size and

speedspeed

Partitioned into scalable/expandable API modulesPartitioned into scalable/expandable API modules

Module granularity is structured such that each Module granularity is structured such that each

peripheral is covered by a single APIperipheral is covered by a single API

Page 62: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 64 Copyright © 2003 Texas Instruments. All rights reserved.

CSL: On-Chip PeripheralsCSL: On-Chip PeripheralsC55x™ DSP ModulesC55x™ DSP Modules

ADCADC

CHIPCHIP

DATDAT

DMADMA

EMIFEMIF

GPIOGPIO

IRQIRQ

I2CI2C

MCBSPMCBSP

PLLPLL

PWRPWR

RTCRTC

USBUSB

WDTIMWDTIM

C54x™ DSP ModulesC54x™ DSP Modules

CHIPCHIP

DAADAA

DATDAT

DMADMA

EBUSEBUS

GPIOGPIO

HPIHPI

IRQIRQ

MCBSPMCBSP

PLLPLL

PWRPWR

UARTUART

WDTIMWDTIM

Page 63: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 65 Copyright © 2003 Texas Instruments. All rights reserved.

CSL FeaturesCSL Features

Standard protocol for programming on-Standard protocol for programming on-chip peripherals:chip peripherals: set of APIs (functions, set of APIs (functions, data types, macros)data types, macros)

Symbolic peripheral description (hardware Symbolic peripheral description (hardware abstraction)abstraction) set of macros for accessing and set of macros for accessing and building register and field valuesbuilding register and field values

Basic resource managementBasic resource management for multi- for multi-resource peripheralsresource peripherals

Integrated into DSP/BIOS™ build:Integrated into DSP/BIOS™ build: CSL CSL Graphic User InterfaceGraphic User Interface

Peripheral ease-of-use:Peripheral ease-of-use: shortened shortened development time, portabilitydevelopment time, portability

Page 64: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 66 Copyright © 2003 Texas Instruments. All rights reserved.

TI Foundation SoftwareTI Foundation Software

Target Board

DSP

CODEC

DIPSwitches

Chip Support Library is Dedicated to the On-Chip Peripherals

Timer

CSL DSP/BIOS™Kernel/Scheduler

DsplibImglib

Drivers

User Application

McBSP EMIF CPU

Page 65: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 67 Copyright © 2003 Texas Instruments. All rights reserved.

CSL Naming ConventionsCSL Naming Conventions All data structures, functions and macros begin All data structures, functions and macros begin

with the capitalized 3–4 letter module/peripheral with the capitalized 3–4 letter module/peripheral name followed by an underscore, name followed by an underscore, PER_PER_ . .(e.g. MCBSP_xxx, DMA_xxx)(e.g. MCBSP_xxx, DMA_xxx)

All data structures begin with a capital letter in All data structures begin with a capital letter in the word immediately following the underscore, the word immediately following the underscore, PER_XxxxPER_Xxxx(e.g. DMA_Config, I2C_Init)(e.g. DMA_Config, I2C_Init)

All functions begin with lowercase letter in the All functions begin with lowercase letter in the word immediately following the underscore, word immediately following the underscore, PER_xxxPER_xxx(e.g. DMA_open, MCBSP_config)(e.g. DMA_open, MCBSP_config)

All macros are in upper case, All macros are in upper case, PER_XXXPER_XXX(e.g. MCBSP_RGETH(…), DMA_ADDRH(…))(e.g. MCBSP_RGETH(…), DMA_ADDRH(…))

Page 66: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 68 Copyright © 2003 Texas Instruments. All rights reserved.

CSL Resource ManagementCSL Resource ManagementData Types and FunctionsData Types and Functions

CSL handle data typeCSL handle data type PER_PER_HandleHandle: pointer to data structure : pointer to data structure

returned from call to returned from call to PERPER_open() for multi-_open() for multi-resource modules (e.g. McBSP, DMA, etc.)resource modules (e.g. McBSP, DMA, etc.)

CSL functionsCSL functions Handle Handle = PER_= PER_open(): open(): allocation of a multi-allocation of a multi-

resource peripheral device. Returns handle resource peripheral device. Returns handle associated to the allocated resource (e.g. associated to the allocated resource (e.g. McBSP port or DMA channel)McBSP port or DMA channel)

Ex: hDma = Ex: hDma = DMA_open(DMA_CHA2,DMA_OPEN_RESET);DMA_open(DMA_CHA2,DMA_OPEN_RESET);

PER_PER_close(Handle): close(Handle): de-allocation of a de-allocation of a previously opened multi-resource devicepreviously opened multi-resource device

Ex: DMA_close(hDma);Ex: DMA_close(hDma);

Page 67: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 69 Copyright © 2003 Texas Instruments. All rights reserved.

CSL ConfigurationCSL Configuration Register-based configurationRegister-based configuration

PERPER_Config_Config: : data structure containing values data structure containing values for all control registers needed to configure the for all control registers needed to configure the peripheralperipheral

PERPER_config([handle], _config([handle], PERPER_Config *config)_Config *config):: configure the peripheral by setting the full values configure the peripheral by setting the full values of memory-map registers.of memory-map registers.

Ex: EMIF_config(&myconfig);Ex: EMIF_config(&myconfig); DMA_config(hDma,&myconfig);DMA_config(hDma,&myconfig);

Parameter-based configurationParameter-based configuration PERPER_Init_Init: : data structure containing functional data structure containing functional

parameters needed to configure the peripheralparameters needed to configure the peripheral PERPER__init(init(PERPER_Init *init)_Init *init) configure the configure the

peripheral via a set of parameters.peripheral via a set of parameters.Ex: I2C_init(&myParams);Ex: I2C_init(&myParams);

Page 68: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 70 Copyright © 2003 Texas Instruments. All rights reserved.

Sample CSL Configuration StructureSample CSL Configuration Structuretypedef struct {typedef struct {

Uint16 dmacsdp;Uint16 dmacsdp;

Uint16 dmaccr;Uint16 dmaccr;

Uint16 dmacicr;Uint16 dmacicr;

DMA_AdrPtr dmacssal;DMA_AdrPtr dmacssal;

Uint16 dmacssau;Uint16 dmacssau;

DMA_AdrPtr dmacdsal;DMA_AdrPtr dmacdsal;

Uint16 dmacdsau;Uint16 dmacdsau;

Uint16 dmacen;Uint16 dmacen;

Uint16 dmacfn;Uint16 dmacfn;

Uint16 dmacfi;Uint16 dmacfi;

Uint16 dmacei;Uint16 dmacei;

} DMA_Config;} DMA_Config;

Page 69: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 71 Copyright © 2003 Texas Instruments. All rights reserved.

Initializing CSL Config StructuresInitializing CSL Config Structures

Creating register masksCreating register masks User generatedUser generated Use Use PER_REG_PER_REG_RMKRMK macros provided by macros provided by

CSLCSL DMA_DMAGCR_RMK(0,0,1)DMA_DMAGCR_RMK(0,0,1)

Use other pre-defined CSL macros such as Use other pre-defined CSL macros such as PERPER_FMK(_FMK(reg,field,val)reg,field,val) to create mask to create mask DMA_FMK(DMAGCR,FREE,1)DMA_FMK(DMAGCR,FREE,1)

Page 70: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 72 Copyright © 2003 Texas Instruments. All rights reserved.

CSL Coding ChecklistCSL Coding Checklist

1.1. Include the appropriate CSL API headers (csl.h, Include the appropriate CSL API headers (csl.h, csl_csl_per.h)per.h)

2.2. Declare and initialize CSL configuration data Declare and initialize CSL configuration data structures and handles (DMA_Config structures and handles (DMA_Config myDmaCfg = {…}; DMA_Handle hDma0;)myDmaCfg = {…}; DMA_Handle hDma0;)

3.3. Call CSL_init() prior to calling or using any Call CSL_init() prior to calling or using any other CSL API functionother CSL API function

4.4. For multi-resource peripherals such as McBSP For multi-resource peripherals such as McBSP and DMA, call and DMA, call PER_PER_open() function to reserve open() function to reserve resource (MCBSP_open(), DMA_open()…)resource (MCBSP_open(), DMA_open()…)

5.5. Call Call PER_PER_config() to configure peripheralconfig() to configure peripheral6.6. Call Call PER_PER_start() to begin peripheral operationstart() to begin peripheral operation7.7. Call Call PER_PER_close() to free resources of multi-close() to free resources of multi-

resource peripheralsresource peripherals

Page 71: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 73 Copyright © 2003 Texas Instruments. All rights reserved.

CSL Example (DMA)CSL Example (DMA)

#include <csl.h>

#include <csl_dma.h>

DMA_Handle hDma0;

DMA_Config dmaCfg0 = { …};

void main() {

CSL_init();

hDma0 = DMA_open(DMA_CHA0, DMA_OPEN_RESET);

DMA_config(hDma0,&dmaCfg0);

DMA_start(hDma0);

while(!(DMA_FGETH(hDma0,DMACSR,FRAME));

// Process data

DMA_close(hDma0);

}

4. Open DMA Channel (returns DMA_Handle to hDma0)

5. Configure Channel (note use of hDma0)

6. Start Transfer

7. Close/Free DMA Channel

3. Initialize Library

2. Declare CSL Data Objects

1. Include Headers

Page 72: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 74 Copyright © 2003 Texas Instruments. All rights reserved.

CSL Compile/Link CheckListCSL Compile/Link CheckList

1.1. Use –dCHIP_XXXX to select the correct Use –dCHIP_XXXX to select the correct target device. (e.g. CHIP_5510PG1_0) target device. (e.g. CHIP_5510PG1_0)

cl55 –dCHIP_5510PG1_0 myFile.ccl55 –dCHIP_5510PG1_0 myFile.c

2.2. For C5000™ DSPs, in a linker command file For C5000™ DSPs, in a linker command file always include .csldata in the SECTIONS always include .csldata in the SECTIONS directive of the linker command file. directive of the linker command file. The .csldata section should be linked into data The .csldata section should be linked into data RAMRAM

3.3. Include the correct library, cslXXXX.lib, (e.g. Include the correct library, cslXXXX.lib, (e.g. csl5510PG1_0.lib)csl5510PG1_0.lib)

Page 73: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 75 Copyright © 2003 Texas Instruments. All rights reserved.

1. Select A Default Configuration Database

Seed

Using the CSL GUIUsing the CSL GUI

Page 74: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 76 Copyright © 2003 Texas Instruments. All rights reserved.

These are the only two elements

needed for CSL configuration

Page 75: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 77 Copyright © 2003 Texas Instruments. All rights reserved.

2. Select target

Page 76: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 78 Copyright © 2003 Texas Instruments. All rights reserved.

Peripheral Configuration

Peripheral Resource Management

3. Expand CSL Tree

Page 77: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 79 Copyright © 2003 Texas Instruments. All rights reserved.

4. Use Configuration Manager to insert a new configuration

object

Page 78: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 80 Copyright © 2003 Texas Instruments. All rights reserved.

Inserted DMA Configuration

Object

Page 79: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 81 Copyright © 2003 Texas Instruments. All rights reserved.

DATA TYPE has pull-down menu

Number of Elements uses input box

Page 80: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 82 Copyright © 2003 Texas Instruments. All rights reserved.

5. Use Properties pages to

set/change configuration parameters

Page 81: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 83 Copyright © 2003 Texas Instruments. All rights reserved.

Scroll bar indicates more

information available

User may choose to

set register values

manually

Page 82: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 84 Copyright © 2003 Texas Instruments. All rights reserved.

Resource Object Properties

6. Select resource object and set its

properties

Page 83: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 85 Copyright © 2003 Texas Instruments. All rights reserved.

The pull-down menu displays all DMA

configuration objects currently defined

Page 84: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 86 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)

Page 85: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 87 Copyright © 2003 Texas Instruments. All rights reserved.

Generated FilesGenerated Files

myproject.cdb – myproject.cdb – updated configuration database updated configuration database containing all inserted objects and all current containing all inserted objects and all current property settingsproperty settings

myprojectmyprojectcfg.h – extern declaration of all created cfg.h – extern declaration of all created objects, definition of CHIP_XXXX, plus #include objects, definition of CHIP_XXXX, plus #include of CSL module headersof CSL module headers

myprojectmyprojectcfg_c.c – definition and initialization of cfg_c.c – definition and initialization of created objects. Contains function calls to created objects. Contains function calls to PER_open,PER_config/PER_init() for pre-PER_open,PER_config/PER_init() for pre-opened/ pre-initialized objectsopened/ pre-initialized objects

myprojectmyprojectcfg.sXX – defines which DSP/BIOS™ cfg.sXX – defines which DSP/BIOS™ elements are present and provides initialization elements are present and provides initialization for those elementsfor those elements

myprojectmyprojectcfg.cmd – linker command file, includes cfg.cmd – linker command file, includes CSL library and .csldata placementCSL library and .csldata placement

Page 86: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 88 Copyright © 2003 Texas Instruments. All rights reserved.

myprojectmyprojectcfg.hcfg.h

#include <csl_dma.h>#include <csl_dma.h>

extern DMA_Config dmaCfg0;extern DMA_Config dmaCfg0;

extern DMA_Handle hDma0;extern DMA_Handle hDma0;

extern void CSL_cfgInit();extern void CSL_cfgInit();

Page 87: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 89 Copyright © 2003 Texas Instruments. All rights reserved.

myprojectmyprojectcfg_c.ccfg_c.c

DMA_Config dmaCfg0 = {DMA_Config dmaCfg0 = { 0x0205, /* (CSDP) */0x0205, /* (CSDP) */ 0x5060, /* (CCR) */0x5060, /* (CCR) */ 0x0008, /* (CICR) */0x0008, /* (CICR) */ (DMA_AdrPtr)&src, /* (CSSA_L) */(DMA_AdrPtr)&src, /* (CSSA_L) */ NULL, /* (CSSA_U) */NULL, /* (CSSA_U) */ (DMA_AdrPtr)&dst, /* (CSDA_L) */(DMA_AdrPtr)&dst, /* (CSDA_L) */ NULL, /* (CSDA_U) */NULL, /* (CSDA_U) */ 0x0080, /* (CEN) */0x0080, /* (CEN) */ 0x0001, /* (CFN) */0x0001, /* (CFN) */ 0x0000, /* (CFI) */0x0000, /* (CFI) */ 0x0000 /* (CEI) */0x0000 /* (CEI) */};};DMA_Handle hDma0;DMA_Handle hDma0;

Page 88: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 90 Copyright © 2003 Texas Instruments. All rights reserved.

CSL_cfgInit()CSL_cfgInit()

void CSL_cfgInit()void CSL_cfgInit()

{{

… …

hDma0 = hDma0 = DMA_open(DMA_CHA0,DMA_OPEN_RESET);DMA_open(DMA_CHA0,DMA_OPEN_RESET);

DMA_config(hDma0, &dmaCfg0);DMA_config(hDma0, &dmaCfg0);

}}

Choosing Pre-Open in CSL GUI results in code generated to call

PER_open function

Choosing Pre-Initialization in CSL GUI results in code to call

PER_config function

Page 89: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 91 Copyright © 2003 Texas Instruments. All rights reserved.

C Source Using GUI-Generated FilesC Source Using GUI-Generated Files

#include “myprojectcfg.h"#include “myprojectcfg.h"#define N#define N 128128Uint16 src[N];Uint16 src[N];Uint16 dst[N];Uint16 dst[N];void main(void)void main(void){{ DMA_start(hDma0);DMA_start(hDma0); whilewhile (!(!DMA_FGETH(hDma0,DMACSR,FRAME));DMA_FGETH(hDma0,DMACSR,FRAME));

DMA_close(hDma0); DMA_close(hDma0); }}

Start DMA

Free Resource

Include generated C header file

Page 90: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 92 Copyright © 2003 Texas Instruments. All rights reserved.

CSL MacrosCSL Macros

PERPER_ADDR(reg)_ADDR(reg) Gets the memory address of the specified Gets the memory address of the specified peripheral register regperipheral register reg

PERPER_RGET(reg)_RGET(reg) Returns the value of the specified peripheral Returns the value of the specified peripheral register regregister reg

PERPER_RSET(reg,val)_RSET(reg,val) Writes the value val to the peripheral register Writes the value val to the peripheral register regreg

PERPER_FGET(reg,field)_FGET(reg,field) Returns the value of the specified field of the Returns the value of the specified field of the registerregister

PERPER_FSET(reg,field,va_FSET(reg,field,val)l)

Writes the value val to the specified field of the Writes the value val to the specified field of the registerregister

Macros for accessing field and register values

Macros for building field and register values

PERPER_REG_RMK( fiel_REG_RMK( fieldmsb ,…, fieldlsb )dmsb ,…, fieldlsb )

Creates a register value to store in the registerCreates a register value to store in the register

PERPER_FMK(reg, field, _FMK(reg, field, val()val()

Creates a shifted version of the fieldvalue could Creates a shifted version of the fieldvalue could be used by be used by PERPER_REG _RMK() _REG _RMK()

Note: Handle-based macros are also available.

Page 91: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 93 Copyright © 2003 Texas Instruments. All rights reserved.

LiteratureLiterature

System Software TMS320C54XSystem Software TMS320C54X SPRU328SPRU328 Code Composer Studio User's Guide Code Composer Studio User's Guide SPRU423 SPRU423 TMS320 DSP/BIOS User's Guide TMS320 DSP/BIOS User's Guide SPRU404 SPRU404 TMS320C5000 DSP/BIOS API Reference TMS320C5000 DSP/BIOS API Reference

GuideGuide SPRU420SPRU420 TMS320C54x Chip Support Library TMS320C54x Chip Support Library

API API User’s Guide User’s Guide SPRU433SPRU433 TMS320C55x Chip Support Library TMS320C55x Chip Support Library

API API User’s Guide User’s Guide

Refer to Digital Library on this CD.Refer to Digital Library on this CD.

Page 92: DSP C5000 Chapter 7 DSP BIOS Copyright © 2003 Texas Instruments. All rights reserved.

ESIEE, Slide 94 Copyright © 2003 Texas Instruments. All rights reserved.

DSP/BIOS Application NotesDSP/BIOS Application NotesSPRA697SPRA697 How to Get Started with DSP/BIOS IIHow to Get Started with DSP/BIOS II

SPRA646 SPRA646 DSP/BIOS II Technical OverviewDSP/BIOS II Technical Overview

SPRA648 SPRA648 Understanding the Functional Enhancements of DSP/BIOS II Understanding the Functional Enhancements of DSP/BIOS II and their Utilization in Real-Time DSP and their Utilization in Real-Time DSP

ApplicationsApplications

SPRA640 SPRA640 Programming and Debugging Tips for DSP/BIOSProgramming and Debugging Tips for DSP/BIOS

SPRA660 SPRA660 Building DSP/BIOS Programs in UNIXBuilding DSP/BIOS Programs in UNIX

SPRA653 SPRA653 Understanding Basic DSP/BIOS FeaturesUnderstanding Basic DSP/BIOS Features

SPRA663 SPRA663 Benchmarking DSP/BIOS II on the TMS320C54xBenchmarking DSP/BIOS II on the TMS320C54x

SPRA692SPRA692 DSP/BIOS II Sizing Guidelines for the TMS320C54x DSPDSP/BIOS II Sizing Guidelines for the TMS320C54x DSP

SPRA689 SPRA689 Using DSP/BIOS I/O in Multichannel SystemsUsing DSP/BIOS I/O in Multichannel Systems

SPRA700 SPRA700 Writing Flexible Device Drivers for DSP/BIOSWriting Flexible Device Drivers for DSP/BIOS

SPRA599SPRA599 DSP/BIOS and TMS320C54X Extended AddressingDSP/BIOS and TMS320C54X Extended Addressing

SPRA695 SPRA695 Real-Time DSP Software Design for a Portable MP3 Player Real-Time DSP Software Design for a Portable MP3 Player Using DSP/BIOSUsing DSP/BIOS

SPRA598 SPRA598 An Audio Example Using DSP/BIOSAn Audio Example Using DSP/BIOS

SPRA591 SPRA591 DSP/BIOS by Degrees: Using DSP/BIOS in an existing DSP/BIOS by Degrees: Using DSP/BIOS in an existing applicationapplication