Home
TMS320 DSP/BIOS User's Guide
Contents
1. 5 16 Using QUE to Send Messages 5 17 Creating a Stream with SIO create sssssssssssssssseeeneneeeen eene 7 5 Freeing User Held Stream Buffers ssssssssssssessseseee nennen nen Inputting and Outputting Data Buffers sssssssssssessee ene Implementing the Issue Reclaim Streaming Model sess 510 Functions cui nei ric etin dep er dad oet D eva and apre ebd kia Adding an Output Stream to Example 7 5 Using the Issue Reclaim Model sene een emnes Opening a Pair of Virtual Devices ssssssssssseeeeeen enne Data Exchange Through a Pipe Using SIO ctrl to Communicate with a Device ssessssseeeeeee Changing Sample Rate e Re A ed Synchronizing with a Device nennen nnne treten Indicating That a Stream is Reagy seen Polling TWO SIfealms us Using SIO put to Send Data to Multiple Clients Using SIO issue SIO reclaim to Send Data to Multiple Clients Required Statements in dxx h Header File Table of Device Functions ssssssssessessss
2. 0 mbxtest c Use a MBX mailbox to send messages from multiple writer tasks to a single reader task The mailbox reader task and 3 writer tasks are created by the Configuration Tool This example is similar to semtest c The major differ ences MBX is used in place of QUE and SEM the elem field is removed from MsgObj reader task is not higher priority than writer task x reader looks at return value of MBX pend for tim eout kj include lt std h gt include lt log h gt include lt mbx h gt include lt tsk h gt define NUMMSGS 3 number of messages define TIMEOUT 10 typedef struct MsgObj Int id writer task id Char val message value MsgObj Msg Mailbox created with Config Tool extern MBX Obj mbx trace Log created with Config Tool extern LOG Obj trace Void reader Void Void writer Int id e Void main Does nothing Thread Scheduling 4 57 Mailboxes Example 4 14 MBX Example With Two Types of Tasks continued reader Void reader Void MsgObj msg Int i for i20 1 wait for mailbox to be posted by writer if MBX pend amp mbx amp msg TIMEOUT 0 LOG printf amp trace timeout expired for MBX pend break print value
3. 2 20 2 7 Using C with 2 24 2 8 User Functions Called by 2 27 2 9 Calling DSP BIOS APIs from 2 28 2 1 Development Cycle 2 1 Development Cycle 2 2 DSP BIOS supports iterative program development cycles You can create the basic framework for an application and test it with a simulated processing load before the DSP algorithms are in place You can easily change the priorities and types of program threads that perform various functions A sample DSP BIOS development cycle includes the following steps though iteration can occur for any step or group of steps 1 2 Use the Configuration Tool to create objects for your program to use Save the configuration file which generates files to be included when you compile and link your program Write a framework for your program You can use C assembly or a combination of the languages Compile and link the program using a Code Composer Studio makefile ora project Test program behavior using a simulator or initial hardware and the DSP BIOS Analysis Tools You can monitor logs and traces statistics objects timing software interrupts and more Repeat steps 1 5 until the program runs correctly You can add functionality and make changes to the basic program structure When production hardware is ready modify the config
4. Reading a Message from a Mailbox Posting a Message to a Mailbox ecrire nnnm MBX Example With Two Types of Tasks Using the System Clock to Drive a Task Linker Command File C6000 Platform Linker Command File C5000 Platform Using MEM alloc for System Level Storage Allocating an Array of Structures Using MEM free to Free Memory Freeing an Array of Objects niic eese te Ee Lene dtr Le Re e na Ed 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 Examples Memory Allocation C5000 Platform enne nnns 5 8 Memory Allocation C6000 Platform ennemis 5 9 Coding To Halt Program Execution with SYS exit or SYS abort 5 11 Using SYS abort with Optional Data 5 12 Using Handlers in SYS exit esses nennen enne nnns nennen 5 12 Using Multiple SYS NUMHANDLERS sse ener 5 12 DSP BIOS Error Handling Etpa ertt ete Pha et ce bete e EE 5 13 Using doError to Print Error Information esenmn 5 13 Managing QUE Elements Using Queues essen 5 14 Inserting into a Queue Atomically essssessssseseeeeeen eene enne 5 15 Using QUE Functions with Mutual Exclusion
5. 7 7 UE EGGS EE ETT 7 18 7 5 Controlling Streams lt lt eh he 7 23 7 6 Selecting Among Multiple 7 24 7 7 Streaming Data to Multiple Clients 7 25 7 8 Streaming Data Between Target and Host 7 9 Device Driver 7 28 7 10 Streaming DEV Structures 7 30 7 11 Device Driver Initialization 7 33 7 12 Devices 743 Real Time 7 38 Td4 ClosingiDeviEas c aoe mean e cu eee 7 15 Device Control FAG Device Ready 7 17 types of Devices o 7 46 7 1 Overview of Streaming I O and Device Drivers 7 1 Overview of Streaming I O and Device Drivers Figure 7 1 7 2 Chapter 6 describes the device independent I O operations supported by DSP BIOS from the vantage point of an application program Programs indirectly invoke corresponding functions implemented by the driver managing the particular physical device attached to the stream using generic functions provided by the SIO module As depicted in the shaded portion of Figure 7 1 this chapter describes device independent I O in DSP BIOS from the driver s perspective of this interface
6. 1 11 cent OLE ActiveX ae S opening devices Index 5 Index operations HWI objects names 1 12 optimization instrumentation overview P performance O instrumentation real time statistics performance monitoring period Periodic Function Manager 4 68 periodic functions 4 3 suggested use _ 4 4 PIP startup poll rate polling disabled 3 11 portability 1 3 1 13 PRD functions 68 PRD module implicit instrumentation PRD F swi PRD F tick function 1 12 predefined masks 4 17 preemption previous value field printf priorities setting for software interrupts 4 22 program error handling See SYS error halting execution of program analysis program tracing 1 8 program cdb 2 12 2 13 programcfg cmd__ 2 12 2 14 programcfg h 2 12 programcfg h54 2 12 programctg obj 2 13 programcfg s54 2 12 2 14 programcfg c c 2 12 properties current property page 2 3 Ptr Index 6 Q queue QUE module 5 14 Quinn Curtis R rate clock ticks polling refresh realloc real time real time analysis 3 2 See alsoRTA 1 5 Real Time Data Exchange See RTDX real time deadline 4 69 real time I O 7 38 Real Time versus Cyclic Debugging Refresh Window register monitoring registers monitoring in HWI 3 24 saving and restoring 4 19 saving when preempted reserved function names and the Execution G
7. Base value srs set DX4 p STS_delta m Dx3 3 gt Dx tc mE 5 1 T T To T set 2 T Ts Tagi h Time T The online help in the Configuration Tool describes statistics objects and their parameters See STS Module in the TMS320 DSP BIOS API Reference Guide for your platform for information on the STS module API calls Instrumentation APIs 3 3 4 Trace Manager TRC Module The TRC module allows an application to enable and disable the acquisition of analysis data in real time For example the target can use the TRC module to stop or start the acquisition of data when it discovers an anomaly in the application s behavior Control of data gathering is important because it allows you to limit the effects of instrumentation on program behavior ensure that LOG and STS objects contain the necessary information and start or stop recording of events and data values at run time For example by enabling instrumentation when an event occurs you can use a fixed log to store the first n events after you enable the log By disabling tracing when an event occurs you can use a circular log to store the last n events before you disable the log 3 3 4 1 Control of Explicit Instrumentation You can use the TRC module to control explicit instrumentation as shown in this code fragment if TRC query TRC USERO 0 LOG or STS operation Note TRC query returns O if all trace types
8. Software Periodic Signals Functions SWI 14 levels PRD Priority Tasks TSK 15 levels Background Thread IDL Software interrupts have lower priority than hardware interrupts There are 14 priority levels available for software interrupts Software interrupts can be preempted by a higher priority software interrupt or any hardware interrupt Software interrupts cannot block Tasks have lower priority than software interrupts There are 15 task priority levels Tasks can be preempted by any higher priority thread Tasks can block while waiting for resource availability and lower priority threads The background idle loop is the thread with the lowest priority of all It runs in a loop when the CPU is not busy running another thread Thread Scheduling 4 7 Overview of Thread Scheduling 4 1 5 Yielding and Preemption 4 8 The DSP BIOS schedulers run the highest priority thread that is ready to run except in the following cases 1 The thread that is running disables some or all hardware interrupts temporarily with HWI_disable or HWI_enter preventing hardware ISRs from running 2 The thread that is running disables software interrupts temporarily with SWI disable This prevents any higher priority software interrupt from preempting the current thread It does not prevent hardware interrupts from preempting the current thread 1 The thread that is running disables task schedulin
9. release the full frame back to the pipe PIP_put amp writerPipe 6 3 2 Reading Data from a Pipe To read a full frame from a pipe a program should perform the following steps 1 The function should first check the number of full frames available to be read from the pipe To do this the program must check the return value of PIP_getReaderNumFrames This function call returns the number of full frames in a pipe object If the number of full frames is greater than 0 the function then calls PIP_get to get a full frame from the pipe Before returning from the PIP_get call DSP BIOS checks whether there are additional full frames available in the pipe If so the notifyReader function is called at this time Once PIP_get returns the data in the full frame can be read by the application To do this the function needs to know the frame s start address and its size The API function PIP_getReaderAdar returns the address of the beginning of the full frame The API function PIP_getReaderSize returns the number of valid data words in the frame Input Output Overview and Pipes 6 7 Data Pipe Manager PIP Module 5 When the application has finished reading all the data the frame can be returned to the pipe by calling PIP free 6 Calling free causes the notifyWriter function to run This enables the reader thread to notify the writer thread that there is a new empty frame available in the pipe The code fragme
10. siotestl c In this program a task reads data from a DGN sine device and prints the contents of the data buffers to a log buffer The data exchange between the task and the device is done in a device independent fashion using the SIO module APIs The stream in this example follows the SIO STANDARD streaming model and is created using the Configuration Tool C6 ox o ob xk ox include lt std h gt include lt log h gt include lt sio h gt include lt sys h gt include tsk h extern Int IDRAMI MEM segment ID defined by Conf tool extern LOG_Obj trace LOG object created with Conf tool extern SIO_Obj inputStream SIO object created w Conf tool extern TSK_Obj streamTask pre created task SIO Handle input amp inputStream SIO handle used below Void doStreaming Uns nloops function for streamTask main x Void main LOG printf amp trace Start SIO example 1 Example 7 5 Basic SIO Function continued Stream I O Reading and Writing Streams streamTask Ef Int i j nbytes Int buf if status SYS ok for 0 i lt nloops LOG printf amp trace nbytes i o L doStreaming This function is the body of the pre created TSK thread Void doStreaming Uns nloops status SIO staticbuf input Ptr amp buf SYS_abort could
11. Host emulation support On the host PC you write programs in C or assembly that use the DSP BIOS API The Configuration Tool lets you define objects to be used in your program You then compile or assemble and link the program The DSP BIOS Analysis Tools let you test the program on the target device from Code Composer Studio while monitoring CPU load timing logs thread execution and more The term thread is used to refer to any thread of execution i e a hardware interrupt a software interrupt a task an idle function or a periodic function The following sections provide a brief overview of the DSP BIOS components 1 4 DSP BIOS Components 1 2 1 DSP BIOS Real Time Kernel and DSP BIOS is a scalable real time kernel designed for applications that require real time scheduling and synchronization host to target communication or real time instrumentation DSP BIOS provides preemptive multi threading hardware abstraction real time analysis and configuration tools The DSP BIOS API is divided into modules however the CSL is actually a sub component of BIOS with many sub modules of its own For simplicity references to the CSL in this manual use the term CSL module Depending on what modules are configured and used by the application the size of DSP BIOS can range from about 500 to 6500 words of code All the operations within a module begin with the letter codes shown Figure 1 1 For more inform
12. 0 rs Streaming I O and Device Drivers 7 1 This chapter describes issues relating to writing and using device drivers and gives several pro gramming examples 7 1 Overview of Streaming I O and Device Drivers 7 2 Creating and Deleting 5 7 3 Stream I O Reading and Writing Streams 7 4 Stackable 7 5 Controlling Streams liliis eh 7 6 Selecting Among Multiple 5 7 7 Streaming Data to Multiple 7 8 Streaming Data Between Target and 5 7 9 Device Driver 7 10 Streaming DEV 7 11 Device 1 7 12 Opening 7 13 7 14 7 15 7 16 7 17 Contents Real Time 1 pri paraa hh Closing Devices ss sius cel hee eee ree ER EE eee ee Device Device Ready iui se Loa dae PA Roe e d res Typ
13. 2 8 User Functions Called by 5 2 9 Calling DSP BIOS APIs from Instrumentatlon 2 rr eI ee rre DSP BIOS provides both explicit and implicit ways to perform real time program analysis These mechanisms are designed to have minimal impact on the application s real time performance 3 1 Real Time Analysis 0 00 0 ccc ccc cece ence a 3 2 Instrumentation 3 3 Instrumentation APIS 0 000 eee ele 3 4 Implicit DSP BIOS 1 5 3 5 Kernel Object View Debugger 3 6 Instrumentation for Field Testing 3 7 Real Time Data Contents 4 Thread Scheduling a x e OR RR ae E I Hom d This chapter describes the types of threads a DSP BIOS program can use their behavior and their priorities during program execution 4 1 Overview of Thread Scheduling 4 2 Hardware Interrupts Ies 4 3 Software Interrupts ees ses seeded bens dee a eee eee 44 a a EP PERS E Rt Eam dub exced
14. Tasks Unlike many time sharing operating systems that give each task its fair share of the processor DSP BIOS immediately preempts the current task whenever a task of higher priority becomes ready to run The maximum priority level is TSK MAXPRI 15 the minimum priority is TSK MINPRI 1 If the priority is less than O the task is barred from further execution until its priority is raised at a later time by another task If the priority equals TSK MAXPRI the task execution effectively locks out all other program activity except for the handling of hardware interrupts and software interrupts During the course of a program each task s mode of execution can change for a number of reasons Figure 4 11 shows how execution modes change Execution Mode Variations TSK create task is created TSK tick SEM post task is readied TSK_yield preemption TSK_TERMINATED task exits task suspends TSK_BLOCKED TSK_exit TSK sleep ES SEM_pend TSK_delete task is deleted Functions in the TSK SEM and SIO modules alter the execution state of task objects blocking or terminating the currently running task readying a previously suspended task re scheduling the current task and so forth There is one task whose execution mode is TSK_RUNNING If all program tasks are blocked and no hardware or software interrupt is running TSK executes the TSK_idle task whose priority is lower
15. Ptr MEM alloc segid size align Int segid Uns size Uns align The segid parameter identifies the memory segment from which memory is to be allocated This identifier can be an integer or a memory segment name defined in the Configuration Tool The memory block returned by MEM alloc contains at least the number of minimum addressable data units MADUS indicated by the size parameter A minimum addressable unit for a processor is the smallest datum that can be loaded or stored in memory An MADU can be viewed as the number of bits between consecutive memory addresses The number of bits in an MADU varies with different DSP devices for example the MADU for the C5000 platform is a 16 bit word and the MADU for the C6000 platform is an 8 bit byte The memory block returned by MEM alloc starts at an address that is a multiple of the align parameter no alignment constraints are imposed if align is 0 An array of structures might be allocated as shown in Example 5 4 Example 5 4 Allocating an Array of Structures typedef struct Obj Int fieldl Int field2 Ptr objArr 003 objArr MEM alloc SRAM sizeof Obj ARRAYL Many DSP algorithms use circular buffers that can be managed more efficiently on most DSPs if they are aligned on a power of 2 boundary This buffer alignment allows the code to take advantage of circular addressing modes found in many DSPs Memory and Low level Functions 5 5 Memory Manageme
16. Table 4 2 Thread Preemption Thread Posted Enabled HWI Disabled HWI Enabled higher priority SWI Disabled SWI Lower priority SWI Enabled higher priority TSK Disabled TSK Lower priority TSK Thread Running HWI Preempts Waits for reenable Waits Waits Waits Waits SWI Preempts Waits for reenable Preempts Waits for reenable Waits Waits Waits Overview of Thread Scheduling TSK Preempts Waits for reenable Preempts Waits for reenable Preempts Waits for reenable Waits IDL Preempts Waits for reenable Preempts Waits for reenable Preempts Waits for reenable Figure 4 2 shows the execution graph for a scenario in which SWIs and HWIs are enabled the default and a hardware interrupt routine posts a software interrupt whose priority is higher than that of the software interrupt running when the interrupt occurs Also a second hardware interrupt occurs while the first ISR is running The second ISR is held off because the first ISR masks off that is disables the second interrupt during the first ISR Thread Scheduling 4 9 Overview of Thread Scheduling Figure 4 2 Preemption Scenario Events _ lt __ g 4 a 5 o c c e o ce o 2 I IR I E E ma T r T r r Thread priority i i i j i i Li Li Li 1 i 1 Hardware interrupt H H i i 1 Ha
17. Device Independent I O in DSP BIOS Application SIO li ISR Device Unlike other modules your application programs do not issue direct calls to driver functions that manipulate individual device objects managed by the SIO module Instead each driver module exports a specifically named structure of a specific type DEV Fxns which in turn is used by the SIO module to route generic function calls to the proper driver function As illustrated in Table 7 1 each SIO operation calls the appropriate driver function by referencing this table Dxx designates the device specific function which you write for your particular device Table 7 1 Generic I O to Internal Driver Operations Generic I O Operation Overview of Streaming I O and Device Drivers Internal Driver Operation SIO create name mode bufsize attrs SIO delete stream SIO get stream amp buf SIO put stream amp buf nbytes SIO ctrl stream cmd arg SIO idle stream SIO flush stream SIO select streamtab n timeout SIO issue stream buf nbytes arg SIO reclaim stream amp buf amp arg SIO staticbuf stream amp buf Dxx open device name Dxx_close device Dxx_issue device and Dxx_reclaim device Dxx_issue device and Dxx_reclaim device Dxx_ctrl device cmd arg Dxx_idle device FALSE Dxx_idle device TRUE Dxx_ready device sem Dxx_issue device Dxx_reclaim device none
18. These internal driver functions can rely on virtually all of the capabilities supplied by DSP BIOS ranging from the multitasking features of the kernel to the application level services Drivers use the device independent I O interface of DSP BIOS to communicate indirectly with other drivers especially in supporting stackable devices Streaming I O and Device Drivers 7 3 Overview of Streaming I O and Device Drivers Figure 7 2 illustrates the relationship between the device the Dxx device driver and the stream accepting data from the device SIO calls the Dxx functions listed in DEV Fxns the function table for the device Both input and output streams exchange buffers with the device using the atomic queues device todevice and device fromdevice Figure 7 2 Device Driver and Stream Relationship open DEV_Fxns SIO create ctrl S SIO ctrl issue 31 tream SIO get reclaim SIO put todevice m fromdevice SIO DEV FXNS DEV Frame Device Driver Dxx_open Dxx_ctrl Dxx_issue Dxx_reclaim Device For every device driver you need to write Dxx open Dxx idle Dxx input Dxx output Dxx close Dxx ctrl Dxx ready Dxx issue and Dxx reclaim 74 Creating and Deleting Streams 7 2 Creating and Deleting Streams To enable your application to do streaming I O with a device the device must first be added with the Configuration Tool You can add a device
19. 1 Call Dxx reclaim Pend on semaphore until a full 2 Get full bufp from buffer is available on fromdevice m queue fromdevice queue Streaming I O and Device Drivers 7 39 Real Time Figure 7 29 is a template for Dxx issue for a typical terminating device Example 7 29 Template for Dxx issue for a Typical Terminating Device DXX issue ui Int Dxx issue DEV Handle device Dxx Handle objptr Dxx Handle device object if device is not operating in correct mode start the device for correct mode return SYS OK A call to Dxx issue starts the device for the appropriate mode either DEV INPUT or DEV OUTPUT Once the device is known to be started Dxx issue simply returns The actual data handling is performed by an HWI Figure 7 30 is a template for Dxx reclaim for a typical terminating device Example 7 30 Template for Dxx reclaim for a Typical Terminating Device Dxx reclaim Int Dxx reclaim DEV Handle device Dxx_Handle objptr Dxx_Handle device gt object if SEM_pend objptr gt sync device gt timeout return SYS OK 1 SEM pend timed out return SYS ETIMEOUT A call to Dxx reclaim waits for the HWI to place a frame on the device gt fromdevice queue then returns Dxx reclaim calls SEM pend with the timeout value specified at the time
20. SWI dec SWI inc SWI or and SWI post These calls can be used virtually anywhere in the program interrupt service routines periodic functions idle functions or other software interrupt functions When an SWI object is posted the SWI Manager adds it to a list of posted software interrupts that are pending execution Then the SWI Manager checks whether software interrupts are currently enabled If they are not as is the case inside an HWI function the SWI Manager returns control to the current thread If software interrupts are enabled the SWI Manager checks the priority of the posted SWI object against the priority of the thread that is currently running If the thread currently running is the background idle loop or a lower priority SWI the SWI Manager removes the SWI from the list of posted SWI objects and switches the CPU control from the current thread to start execution of the posted SWI function If the thread currently running is an SWI of the same or higher priority the SWI Manager returns control to the current thread and the posted SWI function runs after all other SWls of higher priority or the same priority that were previously posted finish execution Software Interrupts Note Two things to remember about SWI When an SWI starts executing it must run to completion without blocking When called from within an HWI the code sequence calling any of the SWI functions which can trigger or post a software int
21. SYS error SYS printf system clock 4 61 System clock parameters System Log viewing grap System services handling errors SYS module 5 11 system stack 3 30 4 8 T target target executable 2 13 Index 8 task execution state 4 39 name 3 31 previous priority scheduler scheduling stack usage state Task Manager 2 22 task object changing priority task stack overflow checking 4 40 tasks blocked creating 4 34 4 36 creating See TSK_create deleting See TSK_delete execution modes See execution mode hooks 4 41 idle preserving hardware registers 4 42 priority levels scheduling 4 39 task objects 4 34 terminating See TSK exit TSK module thread 1 4 preemption priorities type comparisons threads and the Execution Graph choosing types viewing execution graph viewing states tick marks and the Execution Graph time 3 30 idle 3 20 work 3 20 time marks and the Execution Graph timer interrupt rate timer counter register 4 63 time slicing scheduling 4 44 timing methods total trace state for System Log performance tracing 3 3 TRC module control of implicit instrumentation explicit instrumentation TRC disable constants TRC enable xb constants 3 16 TRUE t 14 TSK create TSK delete 4 35 TSK exit i when automatically called TSK startup 2 22 type casting underscore Uninitialized Variables Memory USER traces user traces user defined logs USERREGS mem
22. Example 7 28 provides a template for Dxx open showing the function s typical features for a terminating device Streaming I O and Device Drivers 7 35 Opening Devices Example 7 28 Typical Features for a Terminating Device 7 36 Int Dxx open DEV Handle device String name Dxx Handle objptr check mode of device to be opened if device gt mode is invalid return SYS EMODE check device id if device gt devid is invalid return SYS ENODEV if device is already open return error if device is in use return SYS EBUSY allocate device specific object objptr MEM alloc 0 sizeof Dxx Obj 0 fill in device specific fields create synchronization semaphore objptr gt sync SEM create 0 NULL initialize ready semaphore for SIO select Dxx ready objptr ready NULL do any other device specific initialization required assign initialized object device object Ptr objptr return SYS OK The first two steps take care of error checking For example a request to open an output only device for input should generate an error message A request to open channel ten on a five channel system should also generate an error message The next step is to determine if the device is already opened In many cases an opened device cannot be re opened
23. LOG printf amp trace Over 90 of task s stack is in use n See the TSK stat and TSK_checkstacks sections in the TMS320 DSP BIOS API Reference Guide for your platform for a description and examples of their use System specific functions can be called for each task create TSK create task delete TSK delete task exit TSK exit or context switch TSK sleep SEM pend etc These functions can be used to extend a task s context beyond the basic processor register set The user definable Create function Delete function Ready function and Exit function configuration properties are described in the reference section for the TSK module in the TMS320 DSP BIOS API Reference Guide for your platform The Switch function is invoked during a task switch if it is not set to the no operation function SYS nop Within this function the application can access both the current and next task handles For example Void Switch function TSK Handle curTask TSK Handle nexTask In this example the function can be used to save or restore additional task context for example external hardware registers to check for task stack overflow or to monitor the time used by each task The function specified as the Switch function is called from within the kernel and can make only those function calls allowed from within a software interrupt handler SWI handler See Functions Callable by Tasks SWI Handlers or Hardware ISHs in the 53
24. Fe SWI_or amp myswi 0x2 myswi is posted myswiFxn is executed o Jofo o fafo myswiFxn Program configuration eventType SWI getmbox switch eventType case 0x1 run processing algorithm 1 case 0x2 run processing algorithm 2 case 0x4 run processing algorithm 3 If the program execution requires that multiple occurrences of the same event must take place before an SWI is posted SWI_dec should be used to post the SWI as shown in Figure 4 8 By configuring the SWI mailbox to be equal to the number of occurrences of the event before the SWI should be posted and calling SWI_dec every time the event occurs the SWI is posted only after its mailbox reaches 0 that is after the event has occurred a number of times equal to the mailbox value Thread Scheduling 4 29 Software Interrupts Figure 4 8 Using SWI dec to Post an SWI Mailbox Value returned by Program configuration value SWI getmbox SWI object myswi Function myswiFxn 2 esa Program execution _ Calls SWI_dec amp myswi 1 myswi is not posted Calls SWI_dec amp myswi 0 myswi is posted SWI manager removes 2 myswi from the posted SWI queue myswiFxn is scheduled for execution myswiFxn starts 2 Y execution 4 3 6 Benefits and Tradeoffs There are two main bene
25. LOG printf amp trace read c from d msg val msg id LOG printf amp trace reader done writer T Void writer Int id MsgObj msg Int i for i20 i NUMMSGS 1 fill in value msg id id msg val i NUMMSGS Int a LOG printf amp trace d writing c Int msg val enqueue message MBX post amp mbx amp msg TIMEOUT what happens if you call TSK yield here TSK yield LOG printf amp trace writer d done id After the program runs review the trace log contents The results should be similar to that shown in Example 4 15 4 58 Mailboxes Figure 4 15 Trace Window Results from Example 4 14 TES 0 writing 0 writing 0 writing 1 writing 2 writing gan oo read a from 0 read h from 0 writer 0 done P oc read c from 0 read a from 1 aac Y eriting Isi unn read a from 2 read b from 1 2 writing ici writer 1 done read b from 2 read uel sagen Rc writer 2 done read i From 2 timeout expired for MBX pend reader done Associated with the mailbox at creation time is a total number of available message slots determined by the mailbox length you specify when you create the mailbox In order to synchronize tasks writing to the mailbox a
26. On the C6000 platform the 32 bit high resolution time is calculated by multiplying the low resolution time that is the interrupt count by the value of the period register and adding the current value of the timer counter register To obtain the value of the high resolution time you can call CLK gethtime from your application code The value of both clock restart at 0 when the maximum 32 bit value is reached On the C54x platform the 32 bit high resolution time is calculated by multiplying the low resolution time that is the interrupt count by the value of the period register and adding the difference between the period register value and the value of the timer counter register To obtain the value of the high resolution time you can call CLK gethtime from your application code The value of the clock restarts at the value in the period register when 0 is reached Other CLK module APIs are CLK getprd which returns the value set for the period register in the Configuration Tool and CLK countspms which returns the number of timer counter register increments or decrements per millisecond Modify the properties of the CLK Manager with the Configuration Tool Figure 4 17 to configure the low resolution clock For example to make the low resolution clock tick every millisecond 001 sec type 1000 in the CLK Manager s Microseconds Int field The Configuration Tool automatically calculates the correct value for the period register You c
27. PRD module In a default configuration the CLK module drives the PRD module L If you are using the default CLK configuration the system clock has the same value as the low resolution time because the PRD_clock CLK object drives the system clock There is no requirement that an on device timer be used as the source of the system clock An external clock for example one driven by a data stream rate can be used instead If you do not want the on device timer to drive the low resolution time use the Configuration Tool to delete the CLK object named PRD_clock If an external clock is used it can call PRD_tick to advance the system clock Another possibility is having an on device peripheral such as the codec that is triggering an interrupt at regular intervals call PRD tick from that interrupt s HWI In this case the resolution of the System call is equal to the frequency of the interrupt that is calling PRD tick Thread Scheduling 4 65 Timers Interrupts and the System Clock 4 8 3 Example System Clock Example 4 15 clktest c shows a simple use of the DSP BIOS functions that use the system clock TSK time and TSK sleep The task labeled task in clktest c sleeps for 1000 ticks before it is awakened by the task scheduler Since no other tasks have been created the program runs the idle functions while task is blocked The program assumes that the system clock is configured and driven by PRD clock This program is included in
28. Since the idle loop manages communication with the host data transfer between the host and the target can now take place Advanced Startup C5500 Platform Only On the C5500 platform the architecture allows the software to reprogram the start of the vector tables 256 bytes in overall length by setting the registers IVPD and IVPH By default the hardware reset loads OxFFFF to both these registers and the reset vector is fetched from location OXFF FF00 To move the vector tables to a different location it is necessary to write the desired address into IVPD and IVPH after the hardware reset and then do a software reset at which time the new values in IVPD and IVPH take effect The macro HWI init loads the configured vector table address into IVPD and IVPH but must be followed by a software reset to actually bring the new IVPD and IVPH into effect DSP BIOS Startup Sequence The C5500 platform also allows for three possible stack modes see Table 2 3 To configure the processor in any of the non default modes the user is required to set bits 28 and 29 to the reset vector location appropriately using the Code Composer Studio debugger tool and then to apply a software reset For more information please see the TMS320C55x DSP CPU Reference Guide Table 2 3 Stack Modes on the C5500 Platform Stack Mode Description Reset Vector Settings 2x16 Fast Return 2x16 Slow Return 1x32 Slow Return Reset default SP SSP indepe
29. This could have catastrophic consequences if one thread preempts the other and as a result PIP_get is called twice before calling free or PIP_get is preempted and called again for the same pipe from a different thread Note As a general rule to avoid recursion you should avoid calling PIP functions as part of notifyReader and notifyWriter If necessary for application efficiency such calls should be protected to prevent reentrancy for the same pipe object and the wrong calling sequence for the PIP APIs Input Output Overview and Pipes 6 11 Host Channel Manager HST Module 6 4 Host Channel Manager HST Module The HST module manages host channel objects which allow an application to stream data between the target and the host Host channels are configured for input or output Input streams read data from the host to the target Output streams transfer data from the target to the host Note HST channel names cannot start with a leading underscore You dynamically bind channels to files on the PC host by right clicking on the Code Composer Studio Host Channel Control Then you start the data transfer for each channel as shown in Example 6 4 Figure 6 4 Binding Channels Host Channel Control Bile Transfer Limit State OB Unbound Input lt unbound gt OB Unbound Output lt unbound gt Each host channel is internally implemented using a pipe object To use a p
30. 1 Input Output Stream ieri titi pe cuite ae ed lente 6 2 Interaction Between Streams and Devices 6 3 The Two Ends ol a PIpe trahe tu 6 4 Binding uade 7 1 Device Independent I O in DSP BIOS seen 7 2 Device Driver and Stream Relationship cccccccccecsesceceesseeeeeeesseeeeeeseseeeenssseaeeess 7 3 How SIO_get Works Em 7 4 Output Trace for Example 7 5 7 5 Results Window for Example 7 6 7 6 The Flow of Empty and Full Frames ssseeennennn enn 7 7 inStreamSrc Properties Dialog 7 8 Sine Wave Output for Example 7 9 enne Contents xiii Figures 7 9 7 10 7 11 7 12 7 13 7 14 7 15 xiv Flow of DEV_STANDARD Streaming Model sse Placing a Data Buffer to a Stream 7 39 Retrieving Buffers from a Stream Stacking and Terminating Devices 2 7 46 Buffer Flow in a Terminating Device sseeeeeenn enn enne 7 47 In Place Stacking 7 47 Copying Stacking Driver Flow nnne nnns nennen 7 48 1 1 1 3 1 4 2 1 2 2 2 3 3 1 3 2 3 3 3 4 4 1 4 2 4 3 4 4 7 1 Tables DSP BIOS Modules D
31. 12 If no message is available that is the mailbox is empty MBX pend blocks In this case the timeout parameter allows the task to wait until a timeout to wait indefinitely or to not wait at all Example 4 12 Reading a Message from a Mailbox Bool MBX pend mbx msg timeout MBX Handle mbx Void msg Uns timeout return after this many system clock ticks Conversely MBX_post is used to post a message to the mailbox as shown in Example 4 13 If no message slots are available that is the mailbox is full MBX post blocks In this case the timeout parameter allows the task to wait until a timeout to wait indefinitely or to not wait at all Thread Scheduling 4 55 Mailboxes Example 4 13 Posting a Message to a Mailbox Bool MBX post mbx msg timeout MBX Handle mbx Void msg Uns timeout return after this many system clock ticks 4 71 MBX Example Example 4 14 provides sample code showing two types of tasks created with the Configuration Tool a single reader task which removes messages from the mailbox and multiple writer tasks which insert messages into the mailbox The resultant trace from Example 4 14 is shown in Figure 4 15 Note When called within an HWI the code sequence calling MBX post must be either wrapped within an HWI enter HWI exit pair or invoked by the HWI dispatcher L Mailboxes Example 4 14 MBX Example With Two Types of Tasks
32. Figure 4 9 Note DSP BIOS splits the specified stack space equally between user data stack memory and system stack memory Tasks Figure 4 9 Right Side of Task Manager Display 3 TSK Task Manager objects by priority C Priority 15 Highest C Priority 14 G Priority 13 G Priority 12 G Priority 11 G Priority 10 G Priority 9 G Priority 8 Priority 7 G Priority 6 G Priority 5 G Priority 4 Priority 3 TSKO TSK2 Priority 2 X TSK G Priority 1 Priority 0 Reserved for the idle task X 5 idee G Priority 1 Suspended tasks To change the priority of a task object drag the task to the folder of the corresponding priority For example to change the priority of TSK1 to 3 select it with the mouse and drag it to the folder labeled Priority 3 You can also change the priority of a task in the Properties window which you can select when you right click on the TSK object pop up menu When you use the Configuration Tool to create tasks of equal priority they are scheduled in the order in which they are listed in the Configuration Tool window Tasks can have up to 16 priority levels The highest level is 15 and the lowest is 0 The priority level of 0 is reserved for the system idle task You cannot sort tasks within a single priority level If you want a task to be created in the suspended mode TSK BLOCKED drag it to the folder labeled Priority 1 For more
33. MISC3 SAVE BY CALLER MASK OFFF7h 0 macro has ensured C convention including SP alignment call DSS cisr HWI exit C55 AR DR SAVE BY CALLER MASK C55 ACC SAVE BY CALLER MASK C55 MISC1 SAVE BY CALLER MASK C55 MISC2 SAVE BY CALLER MASK C55 MISC3 SAVE BY CALLER MASK OFFF7h 0 4 2 4 Registers DSP BIOS registers saved and restored with C functions conform to standard C compiler code For more information either about which registers are saved and restored or by the TMS320 functions conforming to the Texas Instruments C run time model see the optimizing compiler user s guide for your platform Thread Scheduling 4 19 Software Interrupts 4 3 Software Interrupts Software interrupts are patterned after hardware ISRs The SWI module in DSP BIOS provides a software interrupt capability Software interrupts are triggered programmatically through a call to a DSP BIOS API such as SWI post Software interrupts have priorities that are higher than tasks but lower than hardware interrupts The SWI module should not be confused with the SWI instruction that exists on many processors The DSP BIOS SWI module is independent from any processor specific software interrupt features SWI threads are suitable for handling application tasks that occur at slower rates or are subject to less severe real time deadlines than those of hardware interrupts The DSP BIOS APIs that can trigger or post a software interrupt are S
34. Not applicable Streams queues pipes global variables Not applicable No Yes No No None None Notes 1 If you disable the TSK Manager in the Property dialog for the TSK Manager IDL threads use the system stack 2 See section 4 3 7 Saving Registers During Software Interrupt Preemption page 4 31 for a list of which registers are saved 3 HWI objects cannot be created dynamically because they correspond to DSP interrupts However interrupt functions can be changed at run time 4 When a HWI function calls HWI enter it can pass a bitmask that indicates which interrupts to enable while the HWI function runs An enabled interrupt can preempt the HWI function even if the enabled interrupt has a lower priority than the current interrupt Overview of Thread Scheduling 4 1 4 Thread Priorities Figure 4 1 Within DSP BIOS hardware interrupts have the highest priority The Configuration Tool lists HWI objects in order from highest to lowest priority as shown in Figure 4 1 but this priority is not maintained implicitly by DSP BIOS The priority only applies to the order in which multiple interrupts that are ready on a given CPU cycle are serviced by the CPU Hardware interrupts are preempted by another interrupt unless that interrupt is disabled by resetting the GIE bit in the CSR or by setting the corresponding bit in the IER Thread Priorities Hardware Clock Interrupts Functions HWI CLK
35. Post an 4 28 4 7 Using SWI or to Post an ns 4 29 4 8 Using SWI dec to Post an SWI ssssssssssssssseseeeeene ener nnne 4 30 4 9 Right Side of Task Manager Display sse 4 37 4 10 TSK Properties Dialog BOX ssssssssssessseneeeneeeen nennen erster enne nnns 4 38 4 11 Execution Mode Variations 4 39 4 12 Trace Window Results from Example 4 6 seen 4 46 4 13 Execution Graph for Example 4 6 nennen nnns 4 46 4 14 Trace Window Results from Example 4 10 sene 4 54 4 15 Trace Window Results from Example 4 14 seen 4 59 4 16 Interactions Between Two Timing Methods sseen 4 61 4 17 CLK Manager Properties Dialog 4 18 Trace Log Output from Example 4 15 sssssssssssseeeeneenen nnne 4 19 Using Statistics View for a PRD Object 4 20 Execution Graph 4 21 Control Panel Dialog eene nennen nnne nre enne 5 1 Allocating Memory Segments of Different Sizes 5 2 Memory Allocation Trace Window sseeneeennn eene nne 5 3 Trace Window Results from Example 5 18 6
36. The Configuration Tool allows you to set a number of properties for each task and for the TSK Manager itself While it is running a task that was created with the Configuration Tool behaves exactly the same as a task created with TSK create You cannot use the TSK delete function to delete tasks created with the Configuration Tool See section 2 2 4 Creating Objects Using the Configuration Tool page 2 4 for a discussion of the benefits of creating objects with the Configuration Tool The default configuration template defines the TSK idle task which must have the lowest priority It runs the functions defined for the IDL objects when no higher priority task or interrupt is ready 4 4 1 3 Setting Task Properties in the Configuration Tool You can view the default TSK properties by clicking on the TSK Manager Some of these properties include default task priority stack size and stack segment Each time a new TSK object is inserted its priority stack size and stack segment are set to the defaults You can also set these properties individually for each TSK object For a complete description of all TSK properties see TSK Module in the TMS320 DSP BIOS Reference Guide for your platform To change the priority of a task 1 Open the TSK module in the Configuration Tool to view all statically created tasks 2 If you select any task you see its priority in the list of properties on the right side of the window as shown in
37. Timing Methods CLK module drives Other event drives No event drives system clock system clock system clock Default configuration Low resolution time Only low and high CLK manager enabled CLK manager disabled Low resolution time and System clock are the same and system clock are different resolution times available timeouts don t elapse Not possible Only system clock available CLK functions don t run Thread Scheduling No timing method CLK functions don t run timeouts don t elapse 4 61 Timers Interrupts and the System Clock 4 8 1 High and Low Resolution Clocks Using the CLK Manager in the Configuration Tool you can disable or enable DSP BIOS use of an on device timer to drive high and low resolution times on the Clock Manager Properties dialog box as shown in Figure 4 17 which depicts the CLK Manager Properties dialog box for the C54x platform The C6000 platform has multiple general purpose timers whereas the C5400 platform has one general purpose timer On the C6000 the Configuration Tool allows you to select the on device timer that is used by the CLK Manager On all platforms the Configuration Tool allows you to enter the period at which the timer interrupt is triggered See CLK Module in the TMS320 DSP BIOS Reference Guide for your platform for more details about these properties By entering the period of the timer interrupt DSP BIOS automatically sets up the a
38. a value set programmatically with STS set Stores the maximum and total differences As a result the value stored as the maximum is the largest negative or positive difference and the average is the average variation from the specified value 3 You may also set the properties of the corresponding STS object to filter the values of this STS object on the host For example you might want to watch the top of the system stack to see whether the application is exceeding the allocated stack size The top of the system stack is initialized to OXBEEF on the C5000 platform and to OxCOFFEE on the C6000 platform when the program is loaded If this value ever changes the application has either exceeded the allocated stack or some error has caused the application to overwrite the application s stack One way to watch for the allocated stack size being exceeded is to follow these steps 1 Inthe Configuration Tool enable implicit instrumentation on any regularly occurring HWI function Right click on the HWI object select Properties and change the monitor field to Top of SW Stack with STS delta addr as the operation 2 Setthe prev property of the corresponding STS object to OXBEEF on the C5000 platform or to OXCOFFEE on the C6000 platform Implicit DSP BIOS Instrumentation 3 Load your program in Code Composer and use the Statistics View to view the STS object that monitors the stack pointer for this HWI function 4 Run your program A
39. address into AO MVKH _x AO move high 16 bits of _x s address into AO LDW 0 AO load x into AO Application code compiled with any of the large model variants is not affected by the location of static objects If all code that directly references objects created with the Configuration Tool is compiled with any large model option code can reference the objects as ordinary data extern PIP Obj inputObj if PIP getReaderNumFrames amp inputObj The mlO large model option is identical to small model except that all aggregate data is assumed to be far This option causes all static objects to be assumed to be far objects but allows scalar types such as int char long to be accessed as near data As a result the performance degradation for many applications is quite modest 2 2 8 Creating Referencing and Deleting Dynamically Created DSP BIOS Objects You can create many but not all DSP BIOS objects by calling the function XXX create where XXX names a specific module Some objects can only be created in the Configuration Tool Each XXX create function allocates memory for storing the object s internal state information and returns a handle used to reference the newly created object when calling other functions provided by the XXX module Using the Configuration Tool Most XXX create functions accept as their last parameter a pointer to a structure of type XXX Attrs which is used to assign attributes to the newly crea
40. and when the Timer Counter Register was able to be read This is the interrupt latency experienced by the timer interrupt The interrupt latency in the system is at least as large as this value Instrumentation 3 27 Kernel Object View Debugger 3 5 Kernel Object View Debugger The Kernel Object View debug tool allows a view into the current configuration state and status of the DSP BIOS objects currently running on the target To start Kernel Object View in Code Composer Studio software go to DSP BIOS Kernel Object View as shown in Figure 3 14 Figure 3 14 Selecting The Kernel Object View Debugger BIOS CPU Load Graph Execution Graph Host Channel Control Message Log Statistics View RT Control Panel Kernel Object View There are six pages of object data available to you Kernel Tasks Mailboxes Semaphores Memory and Software Interrupts The Kernel Object View can display names that are labels for other items on the target because some labels share memory locations In this case you can see a name that does not match the configuration If a label is not available for a memory location a name is automatically generated and is indicated with angle brackets for example lt task1 gt All pages have a Refresh button and a Disable button in the upper left corner When the Refresh button is clicked on any page it updates all the pages concurrently so that the data remains consistent on all pages If the refresh button is
41. buffer flow of a copying stacking driver Notice that the buffers that come down from the task side of the stream never actually move to the device side of the stream The two buffer pools remain independent This is important since in a copying stacking device the task side buffers can be a different size than the device side buffers Also care is taken to preserve the order of the buffers coming into the device so the SIO ISSUERECLAIM streaming model can be supported Figure 7 15 Copying Stacking Driver Flow i Current E todevice queue fromdevice queue Device 7 outgoing buffer queue Output incoming buffer queue Processing m Uo MB A Processing Issue gt ge T L todevice queue Underlying a fromdevice queue Device 7 48 cmd obj 2 13 bss section 2 9 2 10 c files cdb files cmd files 054 files pinit table 2 21 54 files 2 13 x54 files 2 13 A addressing model 1 14 times gine ene of memory Analysis Touls Cr 8 1 9 3 2 8 18 application program size application ae measuring application size 4 24 Arg assembly header files 2 13 assembly source files 2 13 assertions atomic queue attributes assigning 2 11 autoinit c average B14 register background processes 4 2 background igure suggested use Index BIOS init 222002 BIOS 202221 BIOSR
42. calls SWI disable as follows key SWI disable The corresponding enable function is SWI enable SWI enable key key is a value used by the SWI module to determine if SWI disable has been called more than once This allows nesting of SWI disable SWI enable calls since only the outermost SWI enable call actually enables software interrupts In other words a task can disable and enable software interrupts without having to determine if SWI disable has already been called elsewhere When software interrupts are disabled a posted software interrupt does not run at that time The interrupt is latched in software and runs when software interrupts are enabled and it is the highest priority thread that is read to run Software Interrupts Note An important side effect of SWI disable is that task preemption is also disabled This is because DSP BIOS uses software interrupts internally to manage semaphores and clock ticks L To delete a dynamically created software interrupt use SWI delete The memory associated with swi is freed SWI delete can only be called from the task level Thread Scheduling 4 33 Tasks 4 4 Tasks DSP BIOS task objects are threads that are managed by the TSK module Tasks have higher priority than the idle loop and lower priority than hardware and software interrupts The TSK module dynamically schedules and preempts tasks based on the task s priority level and the task s current execut
43. counting semaphore is created and its count is set to the length of the mailbox When a task does an MBX post operation this count is decremented Another semaphore is created to synchronize the use of reader tasks with the mailbox this counting semaphore is initially set to zero so that reader tasks block on empty mailboxes When messages are posted to the mailbox this semaphore is incremented In Example 4 14 all the tasks have the same priority The writer tasks try to post all their messages but a full mailbox causes each writer to block indefinitely The readers then read the messages until they block on an empty mailbox The cycle is repeated until the writers have exhausted their supply of messages Thread Scheduling 4 59 Mailboxes At this point the readers pend for a period of time according to the following formula and then time out TIM EOUT 1ms clock ticks per millisecond After this timeout occurs the pending reader task continues executing and then concludes At this point it is a good idea to experiment with the relative effects of scheduling order and priority the number of participants the mailbox length and a a a the wait time by combining the following code modifications Creation order or priority of tasks Number of readers and writers Mailbox length parameter MBXLENGTH Add code to handle a writer task timeout Timers Interrupts and the System Clock 4 8 Timers Interrupt
44. create but instead initializes a SEM Obj on the Current stack sem SEM create 0 NULL stream streamtab for i i gt 0 i stream call each device ready function with sem AA if Dxx ready device sem ready 1 if ready wait until at least one device is ready SEM pend sem timeout ready 0 stream streamtab for i i gt 0 i stream Call each device ready function with NULL When this loop is done ready will have a bit set for each ready device if Dxx ready device NULL ready mask mask mask lt lt 1 return ready Device Ready SIO select makes two calls to Dxx ready for each Dxx device The first call is used to register sem with the device and the second call with sem NULL is used to un register sem Each Dxx ready function holds on to sem in its device specific object for example objptr gt ready sem When an I O operation completes that is buffer has been filled or emptied and objptr gt ready is not NULL SEM post is called to post objptr gt ready If at least one device is ready or if SIO select was called with timeout equal to 0 SIO select does not block otherwise SIO select pends on the ready semaphore until at least one device is ready or until the time out has expired Consider the case where a device becomes ready before a time out occurs The ready semap
45. data to be transferred between the host and the target While you are developing a program you can use HST objects to simulate data flow and to test changes made to canned data by program algorithms During early development especially when testing signal processing algorithms the program would explicitly use input channels to access data sets from a file for input for the algorithm and would use output channels to record algorithm output The data saved to a file with the output host channel can be compared with expected results to detect algorithm errors Later in the program development cycle when the algorithm appears sound you can change the HST objects to PIP objects communicating with other threads or I O drivers for production hardware Input Output Overview and Pipes 6 13 Performance Issues 6 4 1 Transfer of HST Data to the Host While the amount of usable bandwidth for real time transfer of data streams to the host ultimately depends on the choice of physical data link the HST Channel interface remains independent of the physical link The HST Manager in the Configuration Tool allows you to choose among the physical connections available The actual data transfer to the host occurs within the idle loop on the C54x platform running at lowest priority On the C55x and C6000 platforms the host PC triggers an interrupt to transfer data to and from the target This interrupt has a higher priority than SWI TSK and IDL fu
46. down modes 5320 54 Code Composer Studio Tutorial Online Help literature number SPRH134 introduces the Code Composer Studio integrated development environment and software tools Of special interest to DSP BIOS users are the Using DSP BIOS lessons 5320 55 Code Composer Studio Tutorial Online Help literature number SPRH097 introduces the Code Composer Studio integrated development environment and software tools Of special interest to DSP BIOS users are the Using DSP BIOS lessons TMS320C6000 Code Composer Studio Tutorial Online Help literature number SPRH125 introduces the Code Composer Studio integrated development environment and software tools Of special interest to DSP BIOS users are the Using DSP BIOS lessons Related Documentation Code Composer Studio Application Program Interface API Reference Guide literature number SPRU321 describes the Code Composer Studio application programming interface which allows you to program custom analysis tools for Code Composer Studio DSP BIOS and TMS320C54x Extended Addressing literature number SPRAS599 provides basic run time services including real time analysis func tions for instrumenting an application clock and periodic functions mod ules and a preemptive scheduler It also describes the far model for extended addressing which is available on the TMS320C54x platform TMS320C6000 Chip Support Library API Reference Guide literature number SPRUA01 contai
47. examples Q F isr Run by an HWI object to provide the low resolution CLK tick Q PRD tick Run by the PRD clock CLK object to manage PRD SWI and system tick 1 PRD swi Triggered by tick to run the PRD functions Q run by the lowest priority SWI object KNL_swi to run the task scheduler if it is enabled This is a C function called KNL run An underscore is used as a prefix because the function is called from assembly code IDL loop Run by the lowest priority TSK object TSK idle to run the IDL functions 1 IDL busy Run by the IDL cpuLoad IDL object to compute the current CPU load Naming Conventions m F dispatch Run by the dispatcher IDL object to gather real time analysis data dataPump Run by the dataPump IDL object to manage the transfer of real time analysis and HST channel data to the host 1 HWI unused Not actually a function name This string is used in the Configuration Tool to mark unused HWI objects Note Your program code should not call any built in functions whose names begin with MOD F These functions are intended to be called only as function parameters specified within the Configuration Tool Symbol names beginning with MOD MOD _ where MOD is any letter code for a DSP BIOS module are reserved for internal use 1 3 4 Data Type Names The DSP BIOS API does not explicitly use the fundamental ty
48. express or implied is granted under any patent right copyright mask work right or other intellectual property right of TI covering or relating to any combination machine or process in which such products or services might be or are used Tl s publication of information regarding any third party s products or services does not constitute Tl s approval license warranty or endorsement thereof Reproduction of information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties conditions limitations and notices Representation or reproduction of this information with alteration voids all warranties provided for an associated product or service is an unfair and deceptive business practice and TI is not responsible nor liable for any such use Resale of Tl s products or services with statements different from or beyond the parameters stated by TI for that products or service voids all express and any implied warranties for the associated TI product or service is an unfair and deceptive business practice and TI is not responsible nor liable for any such use Also see Standard Terms and Conditions of Sale for Semiconductor Products www ti com sc docs stdterms htm Mailing Address Texas Instruments Post Office Box 655303 Dallas Texas 75265 Copyright 2001 Texas Instruments Incorporated Preface Read This First About This Manual
49. implicit HWI instrumentation 1 Open the properties window for any HWI object and choose a register to monitor in the monitor field You can monitor any of the variables shown in Table 3 3 or you can choose to monitor nothing When you choose to monitor a variable the Configuration Tool automatically creates an STS object which stores the statistics for the variable Table 3 3 Variables that can be Monitored with HWI C54x Platform C55x Platform C6000 Platform e Data Value Data Value Data Value Top of system stack Top of system stack Stack pointer Stack pointer Stack Pointer General purpose register General purpose register General purpose register aco real trnO a0 12 b6 ag ar6 im rptc trn1 al a13 b7 ah ar7 pmst ac2 rsa0 2 14 b8 al bg fea ac3 rsal xar1 a3 15 b9 bh fa brco 510 2 4 16 31 b10 ar bk 510 bret sti xara a5 C64x only b11 ar2 st ifrO st2 xar4 a6 bO b12 ati bre t ifr 513 xar5 a7 b1 b13 ard ifr tim imrO 10 6 a8 b2 b14 arb irn imr1 11 7 9 b3 b1 reta t2 10 b4 b16 b31 0 t3 xdp 11 b5 C64x only 2 Setthe operation parameter to the STS operation you want to perform on this value You can perform one of the operations shown in Table 3 4 on the value stored in the variable you select For all these operations the number of times this hardware interrupt has been executed is stored in the cou
50. in the mask passed to it are enabled and is not 0 if any trace types in the mask are disabled L The overhead of this code fragment is just a few instruction cycles if the tested bit is not set If an application can afford the extra program size required for the test and associated instrumentation calls it is very practical to keep this code in the production application simplifying the development process and enabling field diagnostics This is in fact the model used within the DSP BIOS instrumented kernel 3 3 4 2 Control of Implicit Instrumentation The TRC module manages a set of trace bits that control the real time capture of implicit instrumentation data through logs and statistics objects For greater efficiency the target does not store log or statistics information unless tracing is enabled You do not need to enable tracing for messages explicitly written with LOG_printf or LOG_event and statistics added with STS_add or STS delta Instrumentation 3 15 Instrumentation APIs DSP BIOS defines constants for referencing specific trace bits as shown in Figure 3 2 The trace bits allow the target application to control when to start and stop gathering system information This can be important when trying to capture information about a specific event or combination of events Table 3 2 TRC Constants Constant Tracing Enabled Disabled Default TRC LOGCLK Logs low resolution clock interrupts off TRC LOGPRD Logs system t
51. is described in detail in section 2 6 DSP BIOS Startup Sequence page 2 20 the BIOS start function enables the DSP BIOS modules As part of this step the PIP startup function calls the notifyWriter function for each pipe object since at startup all pipes have available empty frames Input Output Overview and Pipes 6 5 Data Pipe Manager PIP Module 6 3 1 6 6 There are no special format or data type requirements for the data to be transferred by a pipe The online help in the Configuration Tool describes data pipe objects and their parameters See PIP Module in the TMS320 DSP BIOS Reference Guide for your platform for information on the PIP module API Writing Data to a Pipe The steps that a program should perform to write data to a pipe are as follows 1 A function should first check the number of empty frames available to be filled with data To do this the program must check the return value of PIP_getWriterNumFrames This function call returns the number of empty frames in a pipe object If the number of empty frames is greater than 0 the function then calls PIP alloc to get an empty frame from the pipe Before returning from the PIP_alloc call DSP BIOS checks whether there are additional empty frames available in the pipe If so the notifyWriter function is called at this time Once PIP alloc returns the empty frame can be used by the application code to store data To do this the function needs to k
52. not acquire static frame itt if nbytes SIO_get input Ptr amp buf lt 0 SYS abort Error reading buffer d i Read d bytes nBuffer d data for j 0 j lt nbytes sizeof Int LOG printf amp trace Sd buf j LOG printf amp trace End SIO example 1 Streaming I O and Device Drivers Stream and Writing Streams Figure 7 4 Output Trace for Example 7 5 Log Name trace Y D Start SIO example 1 1 Read 128 bytes Buffer 0 data 7 3 3 Example Reading and Writing to a Device Example 7 6 adds new SIO operations to the previous one An output stream outputStream has been added with the Configuration Tool streamTask reads buffers from a DGN sine device as before but now it sends the data buffers to outputStream rather than printing the contents to a log buffer The stream outputStream sends the data to a DGN user device called printData Device printData takes the data buffers received and uses the print2log function to display their contents in a log buffer The log buffer is specified by the user in the Configuration Tool Stream and Writing Streams Example 7 6 Adding an Output Stream to Example 7 5 Portion of siotest2 c SIO objects created with conf tool extern far LOG Obj trace extern far SIO Obj inputStream extern far SIO Obj outputStream extern far TSK Ob
53. other header files in any sequence For example include std h finclude tsk h include lt sem h gt include lt prd h gt include lt swi h gt About DSP BIOS 1 11 Naming Conventions DSP BIOS includes a number of modules that are used internally These modules are undocumented and subject to change at any time Header files for these internal modules are distributed as part of DSP BIOS and must be present on your system when compiling and linking DSP BIOS programs 1 3 2 Object Names System objects that are included in the configuration by default typically have names beginning with a 3 or 4 letter code for the module that defines or uses the object For example the default configuration includes a LOG object called LOG system Note Objects you create with the Configuration Tool should use a common naming convention of your choosing You might want to use the module name as a suffix in object names For example a TSK object that encodes data might be called encoderTsk 1 3 3 Operation Names The format for a DSP BIOS API operation name is MOD action where MOD is the letter code for the module that contains the operation and action is the action performed by the operation For example the SWI post function is defined by the SWI module it posts a software interrupt This implementation of the DSP BIOS API also includes several built in functions that are run by various built in objects Here are some
54. pressed while the target is running the target is halted the data is collected and then the target is restarted All changes in displayed data are indicated by red text If a stack overflow is detected the data field containing the peak used value turns red and yellow text flags the error The Disable button allows you to disable the Kernel Object View tool while you single step through code or run through multiple break points Since the tool takes some time to read all of the kernel data you can disable it on occasion to step through to some critical code The tool is enabled by pressing the refresh button or by changing pages to another object view When the tool is disabled Kernel Mode is set to Disabled and will displace other information that may have previously appeared in that field This is shown in Figure 3 15 The six pages of the Kernel Object View are described in the sections that follow Kernel Object View Debugger Figure 3 15 The Disabled Message ERBITSS Mode Target TMS320C62 lt x Emulator Time 0 0 System Stack Start 80002868 0 80002 67 Size 0x400 gt Peak 0x60 3 5 1 Kernel The kernel page select the tab labeled KNL shows system wide information as shown in Figure 3 16 Figure 3 16 The Kernel Page Dialog Box DSP BIOS Kernel Object V KNL 1 TSK MBX SEM MEM Swi f j Application Mode Target TMS320C62XX Emulator Time 0 0 System Stack Sta
55. task is no longer the highest in the system A task can also use TSK yield to yield to other tasks with the same priority A task that yields becomes ready to run A task that is currently TSK BLOCKED transitions to the ready state in response to a particular event completion of an I O operation availability of a shared resource the elapse of a specified period of time and so forth By virtue of becoming TSK READY this task is scheduled for execution according to its priority level and of course this task immediately transitions to the running state if its priority is higher than the currently executing task TSK schedules tasks of equal priority on a first come first served basis 4 4 3 Testing for Stack Overflow 4 40 When a task uses more memory than its stack has been allocated it can write into an area of memory used by another task or data This results in unpredictable and potentially fatal consequences Therefore a means of checking for stack overflow is useful 4 4 4 Task Hooks Tasks Two functions TSK checkstacks and TSK stat can be used to watch stack size The structure returned by TSK stat contains both the size of its stack and the maximum number of MADUS ever used on its stack so this code segment could be used to warn of a nearly full stack TSK Stat statbuf declare buffer TSK stat TSK self amp statbuf call func to get status if statbuf used gt statbuf attrs stacksize 9 10
56. the same routine as many times as the value of the mailbox Figure 4 5 Using SWI inc to Post an SWI Mailbox Value returned by value SWI getmbox SWI object myswi Function myswiFxn 0 Program configuration Program execution Calls SWI inc amp myswi myswi is posted Calls SWI_inc amp myswi myswi is posted again before it is scheduled for execution HN SWI manager removes myswi from the posted SWI queue myswiFxn is scheduled for execution is myswiFxn starts execution myswiFxn is preempted by ISR that calls SWI_inc amp myswi myswi is added to the posted SWI queue PIS te myswiFxn continues execution 4 I myswiFxn e repetitions SWI getmbox while repetitions run SWI routine Thread Scheduling 4 27 Software Interrupts If more than one event must always happen for a given software interrupt to be triggered SWI_andn should be used to post the corresponding SWI object as shown in Figure 4 6 For example if a software interrupt must wait for input data from two different devices before it can proceed its mailbox should have two set bits when the SWI object was created with the Configuration Tool When both routines that provide input data have completed their tasks they should both call SWI with complementary bitmasks that clear eac
57. triggered the processor disables interrupts globally by setting the INTM bit in the status register ST1 and then jumps to the ISR set up in the interrupt vector table The HWI enter macro reenables interrupts by clearing the INTM bit in the ST1 register Before doing so HWI enter selectively disables some interrupts by clearing the appropriate bits in the interrupt mask register IMR The bits that are cleared in the IMR are determined by the IMRDISABLEMASK input parameter passed to the HWI enter macro Hence HWI_enter gives you control to select what interrupts can and cannot preempt the current HWI function Thread Scheduling 4 15 Hardware Interrupts 2 When HWI exit is called you can also provide an IMRRESTOREMASK parameter The bit pattern in the IMRRESTOREMASK determines what interrupts are restored by HWI exit by setting the corresponding bits in the IMR Of the interrupts in IMRRESTOREMASK HWI exit restores only those that were disabled with HWI_enter If upon exiting the ISR you do not wish to restore one of the interrupts that was disabled with HWI enter do not set that interrupt bit in IMRRESTOREMASK in HWI exit HWI exit does not affect the status of interrupt bits that are not in IMRRESTOREMASK The C55x platform can have seven parameters in all the first five specify which CPU registers to save as context and the last two can specify two interrupt mask bitmaps HWI enter and HWI exit both take four parameters on th
58. unique messages and place them on a queue for one reader task The writer tasks call SEM post to indicate that another message has been enqueued The reader task calls SEM pend to wait for messages SEM pend returns only when a message is available on the queue The reader task prints the message using the LOG printf function The three writer tasks reader task semaphore and queues in this example program were created with the Configuration Tool Since this program employs multiple tasks a counting semaphore is used to synchronize access to the queue Figure 4 14 provides a view of the results from Example 4 9 Though the three writer tasks are scheduled first the messages are read as soon as they have been enqueued because the reader s task priority is higher than that of the writer Semaphores Example 4 10 SEM Example Using Three Writer Tasks Semtest c Use a QUE queue and SEM semaphore to send messages from multiple writer tasks to a single reader task The reader task the three writer tasks queues and semaphore are created by the Configuration Tool The MsgObj s are preallocated in main and put on the free queue The writer tasks get free message structures from the free queue write the message and then put the message structure onto the message queue This example builds on quetest c The major differences are one reader and multiple writer tasks SEM pend and SEM post are used to synchr
59. variables from the cinit records Call BIOS init to initialize the modules used by the application BIOS init performs basic module initialization BIOS init invokes the MOD init macro for each DSP BIOS module used by the application BIOS init is generated by the Configuration Tool and is located in the programcfg snn file B init sets up the ISTP and the interrupt selector registers sets the NMIE bit in the IER on the C6000 platform and clears the IFR on all platforms See the HW Module Section in the TMS320 DSP BIOS API Reference Guide for your platform for more information DSP BIOS Startup Sequence Note When configuring an interrupt with the Configuration Tool DSP BIOS plugs in the corresponding ISR interrupt service routine into the appropriate location of the interrupt service table However DSP BIOS does not enable the interrupt bit in IER It is your responsibility to do this at startup or whenever appropriate during the application execution 4 init initializes the host I O channel interface The specifics of this routine depend on the particular implementation used for the host to target link For example in the C6000 platform if RTDX is used HST init enables the bit in IER that corresponds to the hardware interrupt reserved for RTDX B IDL init calculates the idle loop instruction count If the Auto calculate idle loop instruction count box was chosen in the Idle Function Manager in the C
60. within the idle loop The idle loop runs the IDL functions that you configured with the Configuration Tool IDL_loop calls the functions associated with each one of the IDL objects one at a time and then starts over again in a continuous loop The functions are called in the same order in which they were created in the Configuration Tool Therefore an IDL function must run to completion before the next IDL function can start running When the last idle function has completed the idle loop starts the first IDL function again Idle loop functions are often used to poll non real time devices that do not or cannot generate interrupts monitor system status or perform other background activities The idle loop is the thread with lowest priority ina DSP BIOS application The idle loop functions run only when no other hardware interrupts software interrupts or tasks need to run Communication between the target and the DSP BIOS Analysis Tools is performed within the background idle loop This ensures that the DSP BIOS Analysis Tools do not interfere with the program s processing If the target CPU is too busy to perform background processes the DSP BIOS Analysis Tools stop receiving information from the target until the CPU is available By default the idle loop runs the functions for these IDL objects 2 LNK_dataPump manages the transfer of real time analysis data for example LOG and STS data and HST channel data between the target DSP an
61. you can change the RTDX buffer size by right clicking on the RTDX module and selecting Properties Instrumentation 3 41 Real Time Data Exchange 3 7 7 Sending Data From Target to Host or Host to Target The user library interface provides the data types and functions for LY Sending data from the target to the host Sending data from the host to the target The following data types and functions are defined in the header file rtdx h They are available via DSP BIOS or standalone Declaration Macros B RTDX_CreatelnputChannel B RTDX_CreateOutputChannel Functions RTDX channelBusy RTDX disablelnput RTDX disableOutput RTDX enableOutput RTDX enablelnput RTDX read RTDX readNB RTDX sizeoflnput RTDX write Macros RTDX islnputEnabled B RTDX_isOutputEnabled See the 7MS320 DSP BIOS API Reference Guide for your platform for detailed descriptions of all RTDX functions 3 42 Chapter 4 Thread Scheduling This chapter describes the types of threads a DSP BIOS program can use their behavior and their priorities during program execution Topic Page 4 1 Overview of Thread Scheduling 4 2 42 Hardware Interrupts cso 4 11 4 3 Software InterruptS 0 025 cece cece 4 20 AA Tasks p ce eee ee D E 4 34 45 Theldle vedete eSI 4 49 A TMa boxes Aea sere ti ores ee US
62. your production program can retain explicit instrumentation for use with manufacturing tests and field diagnostic tools which can be designed to interact with both implicit and explicit instrumentation 3 7 Real Time Data Exchange Real Time Data Exchange RTDX provides real time continuous visibility into the way DSP applications operate in the real world The RTDX plug ins allow system developers to transfer data between a host computer and DSP devices without interfering with the target application The data can be analyzed and visualized on the host using any OLE automation client This shortens development time by giving you a realistic representation of the way your system actually operates RTDX consists of both target and host components A small RTDX software library runs on the target DSP The DSP application makes function calls to this library s API in order to pass data to or from it This library makes use of a scan based emulator to move data to or from the host platform via a JTAG interface Data transfer to the host occurs in real time while the DSP application is running On the host platform an RTDX host library operates in conjunction with Code Composer Studio Displays and analysis tools communicate with RTDX via an easy to use COM API to obtain the target data and or to send data to the DSP application Designers can use their choice of standard software display packages including LabVIEW from National Instrumen
63. 20 TMS320C54x TMS320C55x TMS320C62x TMS320C64x TMS320C67x TMS320C5000 and TMS320C6000 All other brand or product names are trademarks or registered trademarks of their respective companies or organizations Contents About DSP BIOS rnv ra heirs eR Ei DSP BIOS is a scalable real time kernel It is designed for applications that require real time scheduling and synchronization host to target communication or real time instrumentation DSP BIOS provides preemptive multi threading hardware abstraction real time analysis and configu ration tools 1 1 DSP BIOS Features and Benefits tk PROIN 2 3 2 Q 2 lt 2 m 2 o Program Generation This chapter describes the process of generating programs with DSP BIOS It also explains which files are generated by DSP BIOS components and how they are used 2 1 Development Cycle 2 2 Using the Configuration 2 3 Files Used to Create DSP BIOS Programs 24 Compiling and Linking lt 2 5 Using DSP BIOS with the Run Time Support Library 2 6 DSP BIOS Startup 2 7 Using C with 5 1
64. 20 DSP BIOS Reference Guide for your platform for a list of functions callable from an SWI handler Thread Scheduling 4 41 Tasks The function specified as the Ready function is performed when a task becomes ready to run even though the task might not be allowed to run until other tasks of equal or higher priority block finish or yield This function might be used to examine the scheduling and execution of tasks Like the Switch function the Ready function is called from within the kernel and can only call functions allowed within a software interrupt handler SWI handler There are no real constraints on what functions can be called within the Create function Delete function and Exit function since these are invoked outside the kernel You can set the task hook functions with the Configuration Tool by right clicking on the TSK Manager and selecting Properties from the pop up menu Functions written in C must have the leading underscore 4 4 5 Task Hooks for Extra Context 4 42 Consider for example a system that has special hardware registers say for extended addressing that need to be preserved on a per task basis In Example 4 5 the function doCreate is used to allocate a buffer to maintain these registers on a per task basis doDelete is used to free this buffer and doSwitch is used to save and restore these registers If task objects are created with the Configuration Tool the Switch function should not ass
65. 287 2693364 00 inst 3235 00 inst 2082 75 inst IDL_busyObj 635928 1217 1 0 00191374 Thread Scheduling 4 71 Using the Execution Graph to View Program Execution 4 10 Using the Execution Graph to View Program Execution You can use the Code Composer Studio Execution Graph to see a visual display of thread activity by choosing DSP BIOS Execution Graph 4 10 1 States in the Execution Graph Window The Execution Graph as seen in Figure 4 20 examines the information in the system log LOG system in the Configuration Tool and shows the thread states in relation to the timer interrupt Time and system clock ticks PRD Ticks Figure 4 20 The Execution Graph Window Execution Graph ei PRD swi not ready audioS wi o ready loadPrd Bl running stepPrd Wi done KNL_swi unknown SEM Posts LOG mess Other Threads m PRD Ticks Time Assertions Al mm H White boxes indicate that a thread has been posted and is ready to run Blue green boxes indicate that the host had not yet received any information about the state of this thread at that point in the log Dark blue boxes indicate that a thread is running Bright blue boxes in the Errors row indicate that an error has occurred For example an error is shown when the Execution Graph detects that a thread did not meet its real time deadline It also shows invalid log records which can be caused by the program writing over the system log Double clic
66. 4 55 4 8 Timers Interrupts and the System Clock 4 9 Periodic Function Manager PRD and the System Clock 4 10 Using the Execution Graph to View Program Execution 4 72 4 1 Overview of Thread Scheduling 4 1 Overview of Thread Scheduling 4 1 1 4 2 Many real time DSP applications must perform a number of seemingly unrelated functions at the same time often in response to external events such as the availability of data or the presence of a control signal Both the functions performed and when they are performed are important These functions are called threads Different systems define threads either narrowly or broadly Within DSP BIOS the term is defined broadly to include any independent stream of instructions executed by the DSP A thread is a single point of control that can contain a subroutine an interrupt service routine ISR or a function call DSP BIOS enables your applications to be structured as a collection of threads each of which carries out a modularized function Multithreaded programs run on a single processor by allowing higher priority threads to preempt lower priority threads and by allowing various types of interaction between threads including blocking communication and synchronization Real time application programs organized in such a modular fashion as opposed to a single centralized polling loop for example are easier to design implement and main
67. 9 Periodic Function Manager PRD and the System Clock Many applications need to schedule functions based on I O availability or some other programmed event Other applications can schedule functions based on a real time clock The PRD Manager allows you to create objects that schedule periodic execution of program functions To drive the PRD module DSP BIOS provides a system clock The system clock is a 32 bit counter that ticks every time PRD tick is called You can use the timer interrupt or some other periodic event to call PRD tick and drive the system clock There can be several PRD objects but all are driven by the same system clock The period of each PRD object determines the frequency at which its function is called The period of each PRD object is specified in terms of the system clock time that is in system clock ticks To schedule functions based on certain events use the following procedures Based on a real time clock Put a check mark in the Use CLK Manager to Drive PRD box by right clicking on the PRD Manager and selecting Properties in the Configuration Tool By doing this you are setting the timer interrupt used by the CLK Manager to drive the system clock When you do this a CLK object called PRD_clock is added to the CLK module This object calls PRD tick every time the timer interrupt goes off advancing the system clock by one tick Note When the CLK Manager is used to drive PRD the system clock that dr
68. Clock 4 70 The maximum ready to complete time is a good measure of how close the System is to potential failure The closer a software interrupt s maximum ready to complete time is to its period the more likely it is that the system cannot survive occasional bursts of activity or temporary data dependent increases in computational requirements The maximum ready to complete time is also an indication of how much headroom exists for future product enhancements which invariably require more MIPS Note DSP BIOS does not implicitly measure the amount of time each software interrupt takes to execute This measurement can be determined by running the software interrupt in isolation using either the simulator or the emulator to count the precise number of execution cycles required L It is important to realize even when the sum of the MIPS requirements of all routines in a system is well below the MIPS rating of the DSP the system can not meet its real time deadlines It is not uncommon for a system with a CPU load of less than 7096 to miss its real time deadlines due to prioritization problems The maximum ready to complete times monitored by DSP BIOS however provide an immediate indication when these situations exist When statistics accumulators for software interrupts and periodic objects are enabled the host automatically gathers the count total maximum and average for the following types of statistics SWI Statistic
69. DSP BIOS gives developers of mainstream applications on Texas Instruments TMS320 DSP devices the ability to develop embedded real time software DSP BIOS provides a small firmware real time library and easy to use tools for real time tracing and analysis You should read and become familiar with the 7 5320 DSP BIOS Reference Guide for your platform The API reference guide is a companion volume to this user s guide Before you read this manual you should follow the tutorials TMS320 Using DSP BIOS lessons in the online Code Composer Studio Tutorial and DSP BIOS section of the online help system to get an overview of DSP BIOS This manual discusses various aspects of DSP BIOS in depth and assumes that you have at least a basic understanding of other aspects of DSP BIOS as found in the help systems Notational Conventions This document uses the following conventions 14 Program listings program examples and interactive displays are shown in special typeface Examples use a bold version of the special typeface for emphasis interactive displays use a bold version of the special typeface to distinguish commands that you enter from items that the system displays such as prompts command output error messages etc Here is a sample program listing Void copy HST Obj input HST Obj output PIP Obj in Fout Uns tere Uns size Helated Documentation From Texas Instruments 2 Square brackets and identif
70. E get are used to atomically insert an element at the tail of the queue or remove an element from the head of the queue These functions are atomic in that elements are inserted and removed with interrupts disabled Therefore multiple threads can safely use these two functions to modify a queue without any external synchronization QUE get atomically removes and returns the element from the head of the queue whereas QUE put atomically inserts the element at the tail of the queue In both functions the queue element has type Ptr to avoid unnecessary type casting as shown in Example 5 16 Example 5 16 Queues Inserting into a Queue Atomically get queue E Handle queue p ut queue elem E Handle queue 5 3 2 Other QUE Functions Unlike QUE get and QUE put there are a number of QUE functions that do not disable interrupts when updating the queue These functions must be used in conjunction with some mutual exclusion mechanism if the queues being modified are shared by multiple threads QUE dequeue and QUE enqueue are equivalent to QUE get and QUE put except that they do not disable interrupts when updating the queue QUE head is used to return a pointer to the first element in the queue without removing the element QUE next and QUE prev are used to scan the elements in the queue QUE next returns a pointer to the next element in the queue and QUE prev returns a pointer to the previous element in the queue QUE ins
71. EGS rM segment r 14 1 15 Bool 1 13 boot c 2 20 buffer length buffer size LOG objects 3 4 buffers and devices 7 7 and streams exchanging 7 41 7 8 C C run e 4 17 C calloc an catastrophic failure 4 35 channels Char Chip Support Library circular logs See log class constructor class destructor class methods clear 3 11 CLK default configuration 4 65 CLK functions CLK manager CLK Manager Properties 4 62 CLK module CLK F isr function 1 12 we feodo clktesti c 4 66 clock CLK example 4 66 See also CLK module clock functions 4 3 suggested use Index 1 Index clocks real time vs data driven 4 68 Code Composer Studio debugging capabilities of 1 9 code size compiling components configurations fi ps creating custom See Also custom template files Configuration Tool 1 3j 1 6 2 3 constant constants trace trace enabling 3 16 count 0113 23 See pemaphores CPU oad tale B 19 21 measuring 3 20 tracking 3 12 creating configuration files creatin 3 NES CSL 1 2 Library 1 3 See a ana current value SEI 13 custom template files creating 3 See Also configuration files cyclic debugging D data exchange sequence 7 39 exchanging with devices gathering data analysis data notification functions 6 14 data transfer data types data value monitoring 3 24 debugging 3 28 environment DEV ISSU
72. ERE model DEV STANDARD See standard streaming model development cycle device drivers and synchronization semaphores 7 37 file organization header file object 7 31 standard interface 7 28 AIM See Issue Reclaim streaming Index 2 device drivers continued structures table of functions 7 3 devices closing 7 41 See also Dxx_close SIO_delete communication 7 23 controlling 7 43 See also SIO DEV module DEV Fxns table DEV Handle E DEV _Obj exchanging data 03 frame quoe idling 7 44 Soo also Dxx idle initialization of 33 6 3 interaction with streams See also Dxx ready SIO select See also device drivers typedef structure virtual DSP BIO Analysis Tools 1 8 DSP BIOS tase ools files used by DSP BIOS EAE Tool generated 1 6 Dxx ctrl Dxx_idle code 7 41 7 42 7 43 7 44 Dxx_init Dxx initiating data input 7 38 Dxx issue initializing sample code for a terminating device Dxx open and terminating device 7 35 error checking operation of Dxx ready example code 7 43 dynamic object 7 40 EDATA memory segment EDATA1 memory segment EE environment registers 4 17 EPROG memory segment EPROG 1 memory segment error handling Dxx open 7 36 program errors 5 13 SPOX system services 5 13 Event Log Manager 3 6 3 7 events examples controlling B Dxx issue and terminati
73. Graph system statistics and CPU load are built automatically into a DSP BIOS program to provide implicit instrumentation You can enable different components of DSP BIOS implicit instrumentation by using the RTA Control Panel Analysis Tool in Code Composer as described in section 3 4 4 2 Control of Implicit Instrumentation page 3 15 DSP BIOS instrumentation is efficient when all implicit instrumentation is enabled the CPU load increases less than one percent for a typical application See section 3 2 Instrumentation Performance page 3 3 for details about instrumentation performance 3 4 1 Execution Graph The Execution Graph is a special graph used to display information about SWI PRD TSK SEM and CLK processing You can enable or disable logging for each of these object types at run time using the TRC module API or the RTA Control Panel in the host Semaphore posts on the Execution Graph are controlled by enabling or disabling TSK logging The Execution Graph window as shown in Figure 3 9 shows the Execution Graph information as a graph of the activity of each object Figure 3 9 Execution Graph Window Execution Graph swi not ready audioS wi LJ ready loadPrd Bl running stepPrd il done unknown KNL_swi SEM Posts Other Threads C PRD Ticks Time Assertions LOG_message Wi eror break Al m Implicit DSP BIOS Instrumentation CLK and PRD events are shown to p
74. M MEM Swi Refresh Disable Task s TSK idle 0 80001438 0 0x80001490 writer 800014 8 writer 0 80001B40 writer2 0 80001 98 Ready OxO0000043 000000400 Running OxO00000C0 000000400 Ready OxO00000C0 O00000400 Blocked OxO00000C0 000000400 Blocked OxO00000C0 000000400 The task page fields and other information are as follows Task s The value in this field indicates the number of tasks present in the currently operating system The number of lines of information in the main information field is equal to the value in this field 3 5 3 Mailboxes The Kernel Object View Debugger Name Handle This is the task name and handle The name is taken from the label for statically configured objects and is generated for dynamically created objects The label matches the name in the task manager configuration The handle is the address on the target State The current state of the task Ready Running Blocked or Terminated Priority This is the task s priority as set in the configuration or as set by the API Valid priorities are 0 through 15 Peak Used This is the peak stack usage for the task Since it shows the maximum ever used by the task a warning appears if this value ever matches the Stack Size value in the next column A warning is indicated when this field is red and the text is yellow Stack Size This is the stack size Previous Yes indicates that this task was the
75. P BIOS application as es MT NI NI CPUload 100 MT 100 i a 100 To calculate the CPU load you need to know and the value of N for a chosen time interval T over which the CPU load is being measured The IDL cpuLoad object in the DSP BIOS idle loop updates an STS object IDL busyObj that keeps track of the number of times the IDL loop runs and the time as kept by the DSP BIOS high resolution clock see section 4 8 Timers Interrupts and the System Clock page 4 61 This information is used by the host to calculate the CPU load according to the equation above Instrumentation 3 21 Implicit DSP BIOS Instrumentation The host uploads the STS objects from the target at the polling rate set in the RTA Control Panel Property Page The information contained in IDL_busyObj is used to calculate the CPU load The IDL busyObj count provides a measure of N the number of times the idle loop ran The IDL busyObj maximum is not used in CPU load calculation The IDL busyObj total provides the value T in units of the high resolution clock To calculate the CPU load you still need to know the number of instruction cycles spent in the idle loop When the Auto calculate idle loop instruction count box is checked in the Idle Function Manager in the Configuration Tool DSP BIOS calculates at initialization from BIOS init The host uses the values described for N T l4 and the CPU MIPS to calculate the CPU load as follo
76. P BIOS there are two models that can be used for real time l O the STANDARD streaming model and the DEV_ISSUERECLAIM streaming model Each of these models is described in this section 7 13 1 DEV STANDARD Streaming Model In the DEV STANDARD streaming model SIO get is used to get a non empty buffer from an input stream To accomplish this SIO get first places an empty frame on the device gt todevice queue SIO get then calls Dxx issue which starts the I O and then calls Dxx reclaim pending until a full frame is available on the device gt fromdevice queue This blocking is accomplished by calling SEM pend on the device semaphore objptr gt sync that is posted whenever a buffer is filled Dxx issue calls a low level hardware function to initiate data input When the required amount of data has been received the frame is transferred to device gt fromdevice Typically the hardware device triggers an interrupt when a certain amount of data has been received Dxx handles this interrupt by means of an HWI ISR in Figure 7 9 which accumulates the data and determine if more data is needed for the waiting frame If the HWI determines that the required amount of data has been received the HWI transfers the frame to device gt fromdevice and then call SEM post on the device semaphore This allows the task blocked in Dxx reclaim to continue Dxx reclaim then returns to SIO get which will complete the input operation as illustrated in Figu
77. S FOREVER post count n if there is a buffer currently in use by the HWI SEM pend objptr sync SYS FOREVER post count I stop the device Streaming I O and Device Drivers 7 41 Closing Devices Example 7 31 Closing a Device continued 7 42 Don t simply SEM reset the count here There is a possibility that the HWI had just completed working on a buffer just before we checked and we don t want to mess up the semaphore count while post count gt 0 SEM post objptr sync post count else dev mode DEV INPUT or flush was requested stop the device do standard idling place all frames in fromdevice queue while QUE empty device todevice QUE put device fromdevice QUE get device gt todevice SEM post objptr sync return SYS OK The arguments to Dxx idle are DEV Handle device driver handle Bool flush flush indicator The device parameter is as usual a pointer to a DEV Obj for this instance of the device flush is a boolean parameter that indicates what to do with any pending data while returning the device to its initial state For a device in input mode all pending data is always thrown away since there is no way to force a task to retrieve data from a device Therefore the flu
78. S Features and Benefits 1 2 1 2 DSPJBIOS Components 1 4 1 3 Naming lt 14 For More 1 14 DSP BIOS Features and Benefits 1 1 DSP BIOS Features and Benefits 1 2 DSP BIOS and its Analysis Tool for Code Composer Studio software are designed to minimize memory and CPU requirements on the target This design goal is accomplished in the following ways In All DSP BIOS objects can be created in the Configuration Tool and bound into an executable program image This reduces code size and optimizes internal data structures Instrumentation data such as logs and traces are formatted on the host The APIs are modularized so that only those APIs that are used by the program need to be bound into the executable program The library is optimized to require the smallest possible number of instruction cycles with a significant portion implemented in assembly language Communication between the target and the DSP BIOS Analysis Tools is performed within the background idle loop This ensures that the DSP BIOS Analysis Tools do not interfere with the program s tasks If the target CPU is too busy to perform background tasks the DSP BIOS Analysis Tools stop receiving information from the target until the CPU is available addition the DSP BIOS API provides many options fo
79. SP BIOS Standard Data Types 1 13 Memory Segment Names teeth nnn ennt nnns ennt nnns nnns 1 14 Standard Memory 5 2 2 2 1 16 Methods of Referencing C6000 Global 2 8 Files Not Included in rtsDlos 2 18 Stack Modes on the C5500 Platform sssssssssssssseeeeeen nnns 2 23 Examples of Code size Increases Due to an Instrumented Kernel 3 5 TRG Co stantsi m 3 16 Variables that be Monitored with 3 25 STS Operations and Their Results sess 3 26 Comparison of Thread Characteristics 4 5 Thread Preemptioh cce temere eee eee a ota wd SWI Object Function Differences ssssssssssssseseseeeeeeneen nennen 4 26 CPU Registers Saved During Software Interrupt sess 4 31 Generic I O to Internal Driver Operations sse 7 3 Contents XV Examples 2 1 2 3 2 4 2 5 2 6 3 1 3 2 3 3 4 1 4 2 4 3 4 4 4 5 4 6 47 4 9 4 10 4 11 4 12 4 13 4 14 4 15 5 1 5 2 5 3 5 4 5 5 xvi Creating
80. Studio running Windows 98 or Windows NT version 4 0 RTDX in simulation is supported This document assumes that the reader is familiar with C Visual Basic or Visual C and OLE ActiveX programming 3 7 3 RTDX Flow of Data Code Composer Studio data flow between the host PC and the target TI processor as shown in Figure 3 24 Real Time Data Exchange Figure 3 24 RTDX Data Flow between Host and Target Host Target Code OLE Composer JTAG OLE interface interface User interface automation RTDX host RTDX Target 4 Target DSP client library gt Library m application i optional 3 7 3 1 Target to Host Data Flow To record data on the target you must declare an output channel and write data to it using routines defined in the user interface This data is immediately recorded into an RTDX target buffer defined in the RTDX target library The data in the buffer is then sent to the host via the JTAG interface The RTDX host library receives this data from the JTAG interface and records it The host records the data into either a memory buffer or to an RTDX log file depending on the RTDX host recording mode specified The data can be retrieved by any host application that is an OLE automation client Some typical examples of OLE capable host applications are L4 Visual Basic application
81. TMS320 DSP BIOS User s Guide Literature Number SPRU423 February 2001 PRINTED WITH X TEXAS sov nk INSTRUMENTS Printed 2 IMPORTANT NOTICE Texas Instruments and its subsidiaries Tl reserve the right to make changes to their products or to discontinue any product or service without notice and advise customers to obtain the latest version of relevant information to verify before placing orders that information being relied on is current and complete All products are sold subject to the terms and conditions of sale supplied at the time of order acknowledgment including those pertaining to warranty patent infringement and limitation of liability TI warrants performance of its products to the specifications applicable at the time of sale in accordance with Tl s standard warranty Testing and other quality control techniques are utilized to the extent deems necessary to support this warranty Specific testing of all parameters of each device is not necessarily performed except those mandated by government requirements Customers are responsible for their applications using components In order to minimize risks associated with the customer s applications adequate design and operating safeguards must be provided by the customer to minimize inherent or procedural hazards TI assumes no liability for applications assistance or customer product design TI does not warrant or represent that any license either
82. TMS320 DSP BIOS API Reference Guide for your platform for reference information on the HWI module calls 4 2 2 Disabling and Enabling Hardware Interrupts Within a software interrupt or task you can temporarily disable hardware interrupts during a critical section of processing The HWI disable and HWI enable HWI restore functions are used in pairs to disable and enable interrupts When you call HWI disable interrupts are globally disabled in your application On the C6000 platform HWI disable clears the GIE bit in the control status register CSR On the C5000 platform HWI disable sets the INTM bit in the ST1 register On both platforms this prevents the CPU from taking any maskable hardware interrupt Hardware interrupts therefore operate on a global basis affecting all interrupts as opposed to affecting individual bits in the interrupt enable register To reenable interrupts call HWI enable or HWI restore HWI enable always enables the GIE bit on the C6000 platform or clears the INTM bit in the ST1 register on the C5000 platform while HWI restore restores the value to the state that existed before HWI disable was called Figure 4 1 shows two code examples of regions protected from all interrupts Hardware Interrupts Example 4 1 Code Regions That are Uninterruptible a Assembly Code include hwi h54 HWI disable A disable all interrupts save the old intm value in reg A do some critical operation HWI re
83. The value in this field indicates the number of software interrupts present in the currently operating system The number of lines of information in the main information field is equal to the value in this field Name Handle This is the software interrupt name and handle The name is taken from the label for statically configured objects and is generated for dynamically created objects The label matches the name Instrumentation 3 35 Kernel Object View Debugger in the SWI Manager configuration The handle is the address on the target State This is the software interrupt s current state Valid states are Inactive Ready or Running Priority This is the software interrupt s priority as set in the configuration or during creation Valid priorities are 0 through 15 Mailbox This is the software interrupt s current mailbox value Fxn argO arg1 Fxn Handle This is the software interrupt s function and arguments as set in the configuration or during creation The handle is the address on the target The two function names indicated by the angle brackets that surround the name are functions that are generated by DSP BIOS Instrumentation for Field Testing 3 6 Instrumentation for Field Testing The embedded DSP BIOS run time library and DSP BIOS Analysis Tools support a new generation of testing and diagnostic tools that interact with programs running on production systems Since DSP BIOS instrumentation is so efficient
84. WI andn SWI dec SWI inc SWI or SWI post C O O C The SWI Manager controls the execution of all software interrupts When the application calls one of the APIs above the SWI Manager schedules the function corresponding to the software interrupt for execution To handle all software interrupts in an application the SWI Manager uses SWI objects If a software interrupt is posted it runs only after all pending hardware interrupts have run An SWI routine in progress can be preempted at any time by an HWI the HWI completes before the SWI handler resumes On the other hand SWI handlers always preempt tasks All pending software interrupts run before even the highest priority task is allowed to run In effect an SWI handler is like a task with a priority higher than all ordinary tasks Note Two things to remember about SWI are An SWI handler runs to completion unless it is interrupted by a hardware interrupt or preempted by a higher priority SWI When called within an HWI ISR the code sequence calling any of the SWI functions which can trigger or post a software interrupt must be either wrapped within HWI enter HWI exit pair or invoked by the HWI dispatcher L Software Interrupts 4 3 1 Creating SWI Objects As with many other DSP BIOS objects you can create SWI objects either dynamically with a call to SWI create or statically with the Configuration Tool Software interrupts you create dynamically can
85. WI exit 4 15 HWI restore 4 12 versus HWI enable HWI startup HWI unused and driver functions performance real time I O devices virtua IDATA memor segment 1 14 1 15 identifier IDL manager IDL thread IDL_busyObj IDL_cpuLoad instruction count box IDRAMO memory IDRAM1 memory segment T IER implicit instrumentation initialize See also bss section 2 20 instructions number of 3 11 nsrumeni tion zB explicit explicit vs implicit 6 hardware interrupts implicit 3 16 3 18 b 16 B 18 software vs hardware System Log 5 18 t 13 Index 4 interrupt configuring context and Management 4 14 enabling and disabling E hardware 14 1 keyword 4 11 software software triggering 4 20 interrupt latency 3 27 interrupt service routine interrupt service table 2 21 interrupts inter task srrerronisalion 4 49 IPRAM memory segment 1 15 E memor segment 1 14 1 15 21519 H HWI exit 4 17 Issue Reclaim streaming model 7 6 r7 7 8 7 31 PD 2 22 J JTAG K kernel 1 5 Kernel Object View Kernel Object View debug tool 3 28 KNL_run 1 12 LabVIEW large mode Lglnt 1 13 LgUns linker command file options linker command files 2 13 linker switch linking LNK dataPump LNK dataPump object LNK F dataPump log circular fixed 3 8 LOG module explicit instrumentation implicit instrumentation 3 18 overview LOG printf LOG
86. ace enable USER trace global target enable global host enable When using the Execution Graph turning off automatic polling stops the log from scrolling frequently and gives you time to examine the graph You can use either of these methods to turn off automatic polling Q Right click on the Execution Graph and choose Pause from the shortcut menu Q Right click on the RTA Control Panel and choose Property Page Set the Event Log Execution Graph refresh rate to 0 Click OK You can poll log data from the target whenever you want to update the graph by right clicking on the Execution Graph and choose Refresh Window from the shortcut menu You can choose Refresh Window several times to see additional data The shortcut menu you see when you right click on the graph also allows you to clear the previous data shown on the graph Using the Execution Graph to View Program Execution If you plan to use the Execution Graph and your program has a complex execution sequence you can increase the size of the Execution Graph in the Configuration Tool Right click on the LOG system LOG object and select Properties to increase the buflen property Each log message uses four words so the buflen should be at least the number of events you wantto store multiplied by 4 In the case of the C55x platform the large memory model data pointers are 23 bits in length and all long word access requires even address alignment This results in the log ev
87. address of the format string for example d d The host uses this format string and the two remaining words to format the data for display This minimizes both the time and code space used on the target since the actual printf operation and the code to perform the operation are handled on the host LOG event and LOG printf both operate on logs with interrupts disabled This allows hardware interrupts and other threads of different priorities to write to the same log without having to worry about synchronization Instrumentation APIs Using the RTA Control Panel Properties dialog box as shown in Figure 3 3 you can control how frequently the host polls the target for log information To access the RTA Control Panel select DSP BIOSSRTA Control Panel Right click on the RTA Control Panel and choose the Property Page to set the refresh rate If you set the refresh rate to 0 the host does not poll the target for log information unless you right click on a log window and choose Refresh Window from the pop up menu You can also use the pop up menu to pause and resume polling for log information Figure 3 3 RTA Control Panel Properties Dialog Box RTA Control Panel Properties i RTA Options RTA Control Panel m Message Log Execution Graph Every 1 Seconds Every 1 Seconds Statistics View CPU Load Graph Every 1 Seconds Cancel Log messages shown in a message log window are number
88. aim outStreamB Ptr amp bufA NULL SIO reclaim outStreamC Ptr amp bufA NULL SIO reclaim outStreamD Ptr amp bufA NULL SYS FOREVER Note Using SIO issue to send the same buffer to multiple devices does not work with device drivers that modify the data in the buffer since the buffer is simultaneously being sent to multiple devices For example a stacking device that transforms packed data to unpacked data is modifying the buffer at the same time that another device is outputting the buffer The SIO issue interface provides a method for allowing all communications drivers access to the same buffer of data Each communications device driver which typically uses DMA transfers then transfers this buffer of data concurrently The program does not return from the four SIO reclaims until a buffer is available from all of the streams In summary the SIO issue SIO reclaim functions offer the most efficient method for the simultaneous transmission of data to more than one stream This is not a reciprocal operation the SIO issue SIO reclaim model solves the scatter problem quite efficiently for output but does not accommodate gathering multiple data sources into a single buffer for input Streaming Data Between Target and Host 7 8 Streaming Data Between Target and Host Using the Configuration Tool you can create host channel objects HST objects which allow an application to stream data be
89. ains in effect for the duration of code executed between the HWI enter and HWI exit calls Some typical values for this mask are defined in c62 h62 for example C62 PCC ENABLE You can OR the PCC code and DCC code together to generate CCMASK If you use 0 as CCMASK a default value is used You set this value in the Global Settings Properties in the Configuration Tool by right clicking and selecting Properties CLK F isr which handles one of the on device timer interrupts when the Clock Manager is enabled also uses the default cache value set by the Configuration Tool HWI enter saves the current CSR status before it sets the cache bits as defined by CCMASK HWI exit restores CSR to its value at the interrupted context The predefined masks C62 ABTEMPS and C62 CTEMPS C62x or C64 ABTEMPS and C64 CTEMPS C64x specify all of the C language temporary A B registers and all of the temporary control registers respectively These masks can be used to save the registers that can be freely used by a C function When using the HWI dispatcher on the C6000 platform there is no ability to specify a register set so the registers specified by these masks are all saved and restored For example if your HWI function calls a C function you would use HWI enter C62 ABTEMPS C62 CTEMPS IEMASK CCMASK isr code HWI exit C62 ABTEMPS C62 CTEMPS IEMASK CCMASK HWI enter should be used to save all of the C run time enviro
90. al data access your code can be modified to make sure that it references objects created with the Configuration Tool correctly There are four methods for dealing with this issue These methods are described in the sections following and have the pros and cons as shown in Example 2 1 Table 2 1 Methods of Referencing C6000 Global Objects Declare Use global Objects Compile objects object adjacent with large Method with far pointers to bss model Code works independent of compilation model Yes Yes Yes Yes Code works independent of object placement Yes Yes No Yes C code is portable to other compilers No Yes Yes Yes Size of all statically created objects not limited to 32K Yes Yes No Yes bytes Minimizes size of bss Yes Yes No Yes No No Yes No Minimizes instruction cycles Minimizes storage per object Easy to remember when programming easy to find errors 3 cycles 2 6 cycles 1 cycle 3 cycles No No Yes No 12 bytes 12 bytes 4 bytes 12 bytes Somewhat Error prone Somewhat Yes 2 2 7 1 Referencing Static DSP BIOS Objects in the Small Model C6000 Platform Only 2 8 In the small model all compiled code accesses global data relative to a data page pointer register The register B14 is treated as a read only register by the compiler and is initialized with the starting address of the bss section during program startup Global data is assumed to be at a constant offset from the beginning of the bss sectio
91. also be deleted during program execution To add a new software interrupt with the Configuration Tool create a new SWI object for the SWI Manager in the Configuration Tool In the Property Page of each SWI object you can set the function each software interrupt is to run when the object is triggered by the application The Configuration Tool also allows you to enter two arguments for each SWI function In the Property Page of the SWI Manager you can determine from which memory segment SWI objects are allocated SWI objects are accessed by the SWI Manager when software interrupts are posted and scheduled for execution The online help in the Configuration Tool describes SWI objects and their parameters See SW Module in the TMS320 DSP BIOS API Reference Guide for your platform for reference information on the SWI module calls To create a software interrupt dynamically use a call with this syntax swi SWI create attrs Here swi is the interrupt handle and the variable attrs points to the SWI attributes The SWI attribute structure of type SWI Attrs contains all those elements that can be configured for an SWI using the Configuration Tool attrs can be NULL in which case a default set of attributes is used Typically attrs contains at least a function for the handler Note SWI create can only be called from the task level not from an HWI or another SWI L SWI getattrs can be used to retrieve all the SWI_A
92. ample 7 24 Example 7 24 Opening an Input Terminating Device input SIO create adcl6 SIO INPUT BUFSIZE NULL This sequence of steps illustrates the opening process for an input terminating device 1 Find string matching a prefix of adc16 in DEV devtab device table The associated DEV Device structure contains driver function device ID and device parameters 2 Allocate DEV Obj device object 3 Assign bufsize nbufs segid etc fields in DEV_Obj from parameters and SIO Attrs passed to SIO create 4 Create todevice and fromdevice queues 5 If opened for DEV STANDARD streaming model allocate attrs nbufs buffers of size BUFSIZE and put them on todevice queue 6 Call Dxx open with pointer to new DEV Obj and remaining name string using syntax as shown Status Dxx open device 16 7 Validate fields in Obj pointed to by device 8 Parse string for additional parameters for example 16 kHz 9 Allocate and initialize device specific object 10 Assign device specific object to deviceobject The arguments to Dxx open are shown in Example 7 25 Example 7 25 Arguments to Dxx open DEV Handle device driver handle String name device name Opening Devices The device parameter points to an object of type Obj whose fields have been initialized by SIO create name is the string remaining after the device name has been matched by SIO create using DEV
93. an directly specify the period register value if you put a checkmark in the Directly configure on device timer registers box as shown in Figure 4 17 On the C6000 platform to generate a 1 millisecond 001 sec system clock period on a 160 MIPS processor using the CPU clock 4 to drive the clock the period register value is Period 0 001 sec 160 000 000 cycles per second 4 cycles 40 000 To do the same thing on a C5400 platform with a 40 MIPS processor using the CPU to drive the clock the period register value is Period 0 001 sec 40 000 000 cycles per second 40 000 Timers Interrupts and the System Clock 4 8 2 System Clock Many DSP BIOS functions have a timeout parameter DSP BIOS uses a system clock to determine when these timeouts should expire The system clock tick rate can be driven using either the low resolution time or an external source The TSK sleep function is an example of a function with a timeout parameter After calling this function its timeout expires when a number of ticks equal to the timeout value have passed in the system clock For example if the System clock has a resolution of 1 microsecond and we want the current task to block for 1 millisecond the call should look like this block for 1000 ticks 1 microsecond 1 msec TSK sleep 1000 Note Do not call TSK sleep or SEM pend with a timeout other than 0 or SYS FOREVER if the program is configured without something to drive the
94. an e etg eaa CPU Load Graph Monitoring Stack Pointers C5000 platform Monitoring Stack Pointers C6000 platform Calculating Used Stack Selecting The Kernel Object View Debugger The Disabled Message reece nnne nere The Kernel Page Dialog Box The Task Page Dialog BOX iter The Mailboxes Page Dialog Viewing a List of Tasks Currently Blocked ssssssssssseeeeeee The Semaphores Page Dialog Box sse nen Viewing a List of Tasks Pending Figures 3 22 Memory Page Dialog Box sese 3 34 3 23 Software Interrupts Page Dialog Box sssesssseeeeeeeeenes 3 35 3 24 RTDX Data Flow between Host and Target sss 3 39 4 1 Ilium 4 7 4 2 Preemption 5 eae ad ERE n re aane UE EE 4 10 4 3 Software Interrupt Manager sssssssssssseseeeneneeen nnne n nnne nnns 4 22 4 4 SWI Properties Dialog BOX 2 terrre ric ette DO E 4 23 4 5 Using SWI inc to Post SWI 4 27 4 6 Using SWI andn to
95. and Referencing Dynamic Objects 2 11 Deleting a Dynamic Object esee entente enne nens 2 11 Sample Makefile for a DSP BIOS Program sssssssseeeeeeeneeennns 2 17 Declaring Functions in an Extern C Block sse 2 25 Function Overloading Limitation esesssssseseseeee enne eene 2 25 Wrapper Function for a Class Method sse 2 26 Gathering Information About Differences in Values 3 13 Gathering Information About Differences from Base 3 14 The dle LOOP a 3 21 Code Regions That are Uninterruptible 4 13 Constructing a Minimal ISR on C6000 Platform sss 4 18 HWI Example on C54x Platform sssssssssssssseseeeee ener nnns HWI Example on C55x EA Creating a Task Object Tirne Slice Scheduling nenne tede det Creating and Deleting a Semaphore sss Setting a Timeout with SEM pend entere nennen Signaling a Semaphore with SEM post SEM Example Using Three Writer Tasks Greating a Mailbox etie Eco bU exe
96. ansfer thread and a pipe should only have a single reader and a single writer providing point to point communication Often one end of a pipe is controlled by an HWI and the other end is controlled by an SWI function Pipes can also transfer data between two application threads Host channel objects allow an application to stream data between the target and the host Host channels are statically configured for input or output Each host channel is internally implemented using a data pipe object Input Output Overview and Pipes 6 3 Comparing Pipes and Streams 6 2 Comparing Pipes and Streams DSP BIOS supports two different models for data transfer The pipe model is used by the PIP and HST modules The stream model is used by the SIO and DEV modules Both models require that a pipe or stream have a single reader thread and a single writer thread Both models transfer buffers within the pipe or stream by copying pointers rather than by copying data between buffers In general the pipe model supports low level communication while the stream model supports high level device independent l O Table 6 1 compares the two models in more detail Table 6 1 Comparison of Pipes and Streams 6 4 Pipes PIP and HST Streams SIO and DEV Programmer must create own driver structure Reader and writer can be any thread type or host PC PIP functions are non blocking Program must check to make sure a buffer is available befor
97. aries e g bios a54 rtdx lib rts5401 lib so you do not need to add any of these library files to your project Code Composer Studio software automatically scans all dependencies in your project files adding the necessary DSP BIOS and RTDX header files for your configuration to your project s include folder Figure 2 3 shows a sample project files list Figure 2 3 Sample Code Composer Project Files List GEL files Project Ea VOLUME MAK E E DSP BIDS Config VOLUME CDB 9 Include 9 Libraries 5 28 Source LOAD ASM YOLUME C VOLUMECFG 562 VOLUMECFG CMD Compiling and Linking Programs For details on how to create a Code Composer Studio project and build an executable from it refer to the Code Composer Studio User s Guide or the online help For most DSP BIOS applications the generated linker command file programcfg cmd suffices to describe all memory segments and allocations All DSP BIOS memory segments and objects are handled by this linker command file In addition most commonly used sections such as text bss data etc are already included in programcfg cmd Their locations and sizes when appropriate can be controlled from the MEM Manager in the Configuration Tool Figure 2 4 illustrates the Code Composer Studio properties dialog box In some cases the application can require an additional linker command file app cmd describing application specific sections that are not described in the linker command fil
98. articular host channel the program uses HST_getpipe to get the corresponding pipe object and then transfers data by calling the PIP_get and PIP_free operations for input or PIP_alloc and PIP_put operations for output The code for reading data might look like Example 6 5 Host Channel Manager HST Module Example 6 5 Reading Data Through a Host Channel extern far HST Obj input readFromHost PIP Obj pipe Uns size Ptr addr pipe HST getpipe amp input get a pointer to the host channel s pipe object PIP get pipe get a full frame from the host size PIP_getReaderSize pipe addr PIP_getReaderAddr pipe read data from frame PIP_free pipe release empty frame to the host Each host channel can specify a data notification function to be performed when a frame of data for an input channel or free space for an output channel is available This function is triggered when the host writes or reads a frame of data HST channels treat files as 16 or 32 bit words of raw data depending on the platform The format of the data is application specific and you should verify that the host and the target agree on the data format and ordering For example if you are reading 32 bit integers from the host you need to make sure the host file contains the data in the correct byte order Other than correct byte order there are no special format or data type requirements for
99. at enable and disable logging programmatically using the TRC module operations as described in section 3 4 4 Trace Manager TRC Module page 3 13 Instrumentation 3 7 Instrumentation APIs Fixed The log stores the first messages it receives and stops accepting messages when its message buffer is full As a result a fixed log stores the first events that occur since the log was enabled T Circular The log automatically overwrites earlier messages when its buffer is full As a result a circular log stores the last events that occur You create LOG objects using the Configuration Tool with which you assign properties such as the length and location of the message buffer You can specify the length of each message buffer in words Individual messages use four words of storage in the log s buffer The first word holds a sequence number The remaining three words of the message structure hold event dependent codes and data values supplied as parameters to operations such as LOG event which appends new events to a LOG object As shown in Figure 3 2 LOG buffers are read from the target and stored in a much larger buffer on the host Records are marked empty as they are copied up to the host Figure 3 2 LOG Buffer Sequence 3 8 Target Host LOG object ius 5 clear LOG buffer LOG printf uses the fourth word of the message structure for the offset or
100. ation on the CSL see TMS320C6000 Chip Support Library API Reference Guide literature number SPRU401 Application programs use DSP BIOS by making calls to the API All DSP BIOS modules provide C callable interfaces In addition some of the API modules contain optimized assembly language macros Most C callable interfaces can also be called from assembly language provided that C calling conventions are followed Some of the C interfaces are actually C macros and therefore cannot be used when called from assembly language Refer to the TMS320 DSP BIOS API Reference Guide for your platform for descriptions of the applicable C and assembly languages interfaces for all DSP BIOS modules About DSP BIOS 1 5 DSP BIOS Components Table 1 1 DSP BIOS Moaules Module Description ATM C54 C55 C62 C64 CLK CSL DEV GBL HST HWI IDL LCK LOG MBX MEM PIP PRD QUE RTDX SEM SIO STS SWI SYS TRC TSK Atomic functions written in assembly language Target specific functions platform dependent Clock manager Chip Support Library For more information see the TMS320C6000 Chip Support Library API Reference Guide literature number SPRU401 Device driver interface Global setting manager Host channel manager Hardware interrupt manager Idle function manager Resource lock manager Event log manager Mailbox manager Memory segment manager Buffered pipe manager Periodic function manager Atomic queue manager Real
101. ble hi pri task Void hi pri task Arg id arg Int id ArgToInt id arg while 1 LOG printf amp trace Task d here id SEM pend amp sem SYS FOREVER Void prdfxn0 Void prdfxnl TSK_yield SEM post amp sem Thread Scheduling 4 45 Tasks Figure 4 12 Trace Window Results from Example 4 6 Log Name trace Slice example started Task 4 here Task 1 time isus Task 1 time is us 1 2 Task 1 time is us 2 9 Task 1 time is us Ox3d0 Task 2 time is us 4 Task 2 time is us 0x594 Task 2 time is us Ox65d Task 2 time is us 0x726 Task 3 time is us Ox89b Task 3 time is us 0x967 Task 3 time is us Oxa32 Task 3 time is us Task 1 time is us Oxc 2 Task 1 time is us Oxd3d 0 1 2 3 4 5 6 i 8 3 Cn A oh Figure 4 13 Execution Graph for Example 4 6 not ready 0 ready Bl running Wi done unknown LOG message Bi eror break SEM Posts Dther Threads PRD Ticks Time Assertions 4 46 The Idle Loop 4 5 The Idle Loop The idle loop is the background thread of DSP BIOS which runs continuously when no hardware interrupt service routines software interrupt or tasks are running Any other thread can preempt the idle loop at any point The IDL Manager in the Configuration Tool allows you to insert functions that execute
102. ble block because the call to IDL run is not reentrant Revision History WARNING DO NOT ADD A REVISION HISTORY OR REMOVE THESE 8 LINES These 8 lines will be removed by selfexp rcl selfexp rcl will add 8 new lines which contain Copyright and version stamp We need to make sure the source line numbers match up so that pre built executables can be debugged in CC 7 ude std h ude lt clk h gt ude lt idl h gt ude lt log h gt ude lt sem h gt ude lt swi h gt ude lt tsk h gt ude slicecfg h Void task Arg id arg Void hi pri task Arg id arg counts per us hardware timer counts per microsecond 4 44 Tasks Example 4 6 Time Slice Scheduling continued E Void main LOG printf amp trace Slice example started counts per us countspms 1000 task MA Void task Arg id arg Int id ArgToInt id_arg LgUns time LgUns prevtime The while loop below simulates the work load of the time sharing tasks rd while 1 time CLK_gethtime counts per us print time only every 200 usec if time gt prevtime 200 prevtime time LOG printf amp trace Task d time is us Ox x id Int time check for rollover if prevtime gt time prevtime time pass through idle loop to pump data to the Real Time Analysis tools TSK disable IDL run TSK ena
103. by CLK objects are performed in sequence the context of that ISR Therefore the low resolution clock ticks at the timer interrupt rate and the clock s time is equal to the number of timer interrupts that have occurred To obtain the low resolution time you can call CLK getltime from your application code The CLK functions performed when a timer interrupt occurs are performed in the context of the hardware interrupt that caused the system clock to tick Therefore the amount of processing performed within CLK functions should be minimized and these functions can invoke only DSP BIOS calls that are allowable from within an HWI Note CLK functions should not call enter and HWI exit as these are called internally when DSP BIOS runs CLK F isr Additionally CLK functions should not use the interrupt keyword or the INTERRUPT pragma in C functions Thread Scheduling 4 63 Timers Interrupts and the System Clock The high resolution clock ticks at the same rate the timer counter register is incremented on the C6000 platform and decremented on the C5400 platform Hence the high resolution time is the number of times the timer counter register has been incremented or decremented On the C6000 platform this is equivalent to the number of instruction cycles divided by 4 The CPU clock rate is high therefore the timer counter register can reach the period register value C6000 platform or 0 C5400 platform very quickly
104. c Memory Segment Names C6000 EVM Platform exit Segment Description IPRAM Internal on device program memory IDRAM Internal on device data memory SBSRAM External SBSRAM on CEO SDRAMO External SDRAM on CE2 SDRAM1 External SDRAM on CE3 d Memory Segment Names C6000 DSK Platform qx Segment Description SDRAM External SDRAM You can change the origin size and name of the default memory segments with the exception of IPRAM and IDRAM using the Configuration Tool About DSP BIOS 1 15 Naming Conventions 1 3 6 Standard Memory Segments The Configuration Tool defines standard memory segments and their default allocations as shown in Table 1 4 Table 1 4 Standard Memory Segments a C54x Platform Sections Segment System stack Memory stack IDATA Application Argument Memory args EDATA Application Constants Memory const EDATA BIOS Program Memory bios IPROG BIOS Data Memory sysdata EDATA BIOS Heap Memory IDATA BIOS Startup Code Memory sysinit EPROG b C55x Platform Sections Segment System stack Memory stack System Stack Memory sysstack DATA BIOS Kernel State Memory sysdata DATA BIOS Objects Configuration Memory obj DATA BIOS Program Memory bios PROG en UN Code Memory sysinit gblinit PROG Application Argument Memory args DATA Application Program Memory text PROG BIOS Heap Memory DATA Secondary BIOS Heap Memory DATA1 For More Infor
105. cale DTR Params DTR PRMS 20 Scaling factor NULL NULL Void source Uns nloops function body for sourceTask above Void sink Uns nloops function body for sinkTask above static Void doStreaming SIO Handle input SIO Handle output Uns nloops Stackable Devices Example 7 9 Data Exchange Through a Pipe Device continued Void main LOG_printf amp trace Start SIO example 5 k gource This function forms the body of the sourceTask TSK thread x Void source Uns nloops SIO_Handle input amp inStreamSrc SIO Handle output amp outStreamSrc 7 Do I O doStreaming input output nloops sink This function forms the body of the sinkTask TSK thread xf Void sink Uns nloops SIO Handle input amp inStreamSink SIO Handle output amp outStreamSink PP Dos IYO Sy doStreaming input output nloops LOG printf amp trace End SIO example 45 SYS abort Eror reading buffer d i for i 0 i lt nloops itt if nbytes SIO get input amp buf lt 0 SYS_abort Error reading buffer d i if SIO put output amp buf nbytes lt 0 SYS_abort Error writing buffer d i doStreaming I O function for the sink and source tasks E static Void doStreaming SIO_Handle input SIO_Handle output Uns nloops Ptr buf Int i
106. ce RAMs zero wait state external SRAMs slower DRAMs for bulk data and several others Having explicit control over which memory segment contains a particular block of data is essential to meeting real time constraints in many DSP applications The MEM module does not set or configure hardware registers associated with a DSPs memory subsystem Such configuration is your responsibility and is typically handled by software loading programs or in the case of Code Composer Studio the GEL start up or menu options For example to access external memory on a C6000 platform the External Memory Interface EMIF registers must first be set appropriately before any access The earliest opportunity for EMIF initialization within DSP BIOS would be during the user initialization hook see Global Settings in the TMS320 DSP BIOS API Reference Guide for your platform The MEM functions allocate and free variable sized memory blocks Memory allocation and freeing are non deterministic when using the MEM module since this module maintains a linked list of free blocks for each particular memory segment MEM alloc and MEM free must transverse this linked list when allocating and freeing memory 5 1 1 Configuring Memory Segments 5 2 The templates provided with DSP BIOS define a set of memory segments These segments are somewhat different for each supported DSP board If you are using a hardware platform for which there is no configuration template you nee
107. ce code file is volume c additional assembly source is in load asm and the configuration file is volume cdb This makefile is for use with gmake which is included with the Code Composer Studio software You can find documentation for gmake on the product CD in PDF format Adobe Acrobat Reader is included This makefile and the source and configuration files mentioned are located in the volume2 subdirectory of the tutorial directory of Code Composer Studio distribution CD A typical makefile for compiling and linking a DSP BIOS program is shown in Example 2 3 You can copy an example makefile to your program folder and modify the makefile as necessary Unlike the Code Composer Studio project makefiles allow for multiple linker command files If the application requires additional linker command files you can easily add them to the CMDS variable in the example makefile shown in Example 2 3 However they must always appear after the programcfg cmd linker command file generated by the Configuration Tool Compiling and Linking Programs Example 2 3 Sample Makefile for a DSP BIOS Program Makefile for creation of program named by the PROG variable The following naming conventions are used by this makefile lt prog gt asm C54 assembly language source file lt prog gt obj C54 object file compiled assembled source lt prog gt out C54 executable fully linked program lt prog gt cfg s54 configuration assembly source file generated by Conf
108. ces to the buffer used in I O are updated after each operation Otherwise you are referencing an invalid buffer SIO put uses the same exchange of pointers to swap buffers for an output stream SIO issue and SIO reclaim each move data in only one direction Therefore an SIO issue SIO reclaim pair result in the same swapping of buffer pointers Note A single stream cannot be used by more than one task simultaneously That is only a single task can call SIO get SIO put or SIO issue SIO reclaim at once for each stream in your application Streaming I O and Device Drivers 7 9 Stream and Writing Streams 7 3 2 Example Reading Input Buffers from a Device The program in Example 7 5 illustrates some of the basic SIO functions and provides a straightforward example of reading from a stream For a complete description of the DGN software generator driver see the DGN section in the TMS320 DSP BIOS API Reference Guide for your platform The configuration template for Example 7 5 can be found in the siotest directory of the DSP BIOS distribution A DGN device called sineWave is used as a data generator to the SIO stream inputStream The task streamTask calls the function doStreaming to read the sine data from the inputStream and prints it to the log buffer trace The output for Example 7 5 appears as sine wave data in Figure 7 4 Example 7 5 Basic SIO Functions 7 10
109. ches to the HWI function The enable HWI accumulations check box in the RTA Control Panel must be selected in order for HWI function monitoring to take place If this type of tracing is not enabled the stub function branches to the HWI function without updating the STS object The number of times an interrupt is triggered is recorded in the Count field of the STS object When the stack pointer is monitored the maximum value reflects the maximum position of the top of the system stack when the interrupt occurs This can be useful for determining the system stack size needed by an application To determine the maximum depth of the stack follow these steps see Figure 3 13 1 Using the Configuration Tool right click on the HWI object and select Properties and change the monitor field to Stack Pointer You should also change the operation field to STS add addr and leave the other default settings as they are These changes give you the minimum value of the stack pointer in the maximum field of the STS object This is the top of the stack since the stack grows downward in memory 2 Link your program and use the nmti program which is described in Chapter 2 Utility Programs in the TMS320 DSP BIOS API Reference Guide for your platform to find the address of the end of the system stack Or you can find the address in Code Composer by using a Memory window or the map file to find the address referenced by the GBL stackend symbol This sy
110. cteristics Characteristic HWI SWI TSK IDL Priority Highest 2nd highest 2nd lowest Lowest Number of priority levels Can yield and pend Execution states Scheduler disabled by Posted or made ready to run by Stack used Context saved when preempts other thread DSP dependent No runs to completion except for preemption Inactive ready running HWI disable Interrupt occurs System stack 1 per program Customizable 15 Periodic func tions run at priority of the PRD_swi SWI object Task sched uler runs at lowest priority No runs to completion except for preemption Inactive ready running SWI_disable SWI post SWI andn SWI dec SWI inc SWI or System stack 1 per program Certain registers saved to system stack see Note 2 16 Including 1 for the ID loop Yes Ready running blocked terminated TSK disable TSK create Task stack 1 per task Entire context saved to task stack 1 Should not would prevent PC from getting target information Reagy running Program exit main exits and no other thread is cur rently running Task stack used by default see Note 1 Not applicable Notes 1 If you disable the TSK Manager in the Property dialog for the TSK Manager IDL threads use the system stack 2 See section 4 3 7 Saving Registers During Software Interrupt Preemption page 4 31 for a list of saved registers 3 HWI objects can
111. cution of a software interrupt is recorded in a LOG object called LOG system In addition worst case ready to completion times for software interrupts and overall CPU load are accumulated in STS objects The occurrence of a system tick is also shown in the Execution Graph See section 3 3 4 2 Control of Implicit Instrumentation page 3 15 for more information about what implicit instrumentation can be collected 3 3 2 Event Log Manager LOG Module This module manages LOG objects which capture events in real time while the target program executes You can use the Execution Graph or view user defined logs orchestrated with the Configuration Tool User defined logs contain any information your program stores in them using the LOG event and LOG printf operations You can view messages in these logs in real time with the Message Log as shown in Figure 3 1 To access the Message Log select DSP BIOS Message Log Figure 3 1 Message Log Dialog Box DSP BIOS Message Log OP Log Name trace Y hello world period 1 time 2000 period time 4000 period 1 time 6000 period 1 time 8000 period 1 time 10000 period 1 time 12000 period 1 time 14000 period 1 time 16000 CO OO 74 CD CD E The Execution Graph which is the system log can also be viewed as a graph of the activity for each program component A log can be either fixed or circular This distinction is important in applications th
112. d reader The queue is created by the Configuration Tool For simplicity we use MEM alloc and MEM free to manage the MsgObj structures It would be way more efficient to preallocate a pool of MsgObj s and keep them on a free queue Using the Config Tool create freeQueue Then in main allocate the MsgObj s with MEM alloc and add them to freeQueue with QUE put You can then replace MEM alloc calls with QUE get freeQueue and MEM free with QUE put freeQueue msg A queue can hold an arbitrary number of messages or elements Each message must however be a structure with a QUE Elem as its first field 5 include lt std h gt include lt log h gt include lt mem h gt include lt que h gt include lt sys h gt define NUMMSGS 5 number of messages typedef struct MsgObj QUE_Elem elem first field for QUE Char val message value MsgObj Msg extern QUE Obj queue Trace Log created with the Configuration Tool extern LOG Obj trace Void reader Void writer 0 main Void main Writer must be called before reader to ensure that the queue is non empty for the reader writer reader Memory Low level Functions 5 17 Queues Example 5 18 Using QUE to Send Messages continued Void reader Msg msg Int 15 for i20 lt NUMMSGS i The queue should never be empty if QUE empty amp q
113. d error id Ox x errno LOG error SYS error called string s s The errno parameter to SYS error can be a DSP BIOS error for example SYS EALLOO or a user error errno gt 256 See TMS320 DSP BIOS Reference Guide for your platform for a table of error codes and strings Memory and Low level Functions 5 13 Queues 5 3 Queues The QUE module provides a set of functions to manage a list of QUE elements Though elements can be inserted or deleted anywhere within the list the QUE module is most often used to implement a FIFO list elements are inserted at the tail of the list and removed from the head of the list QUE elements can be any structure whose first field is of type QUE_Elem In Example 5 15 QUE Elem is used by the QUE module to enqueue the structure while the remaining fields contain the actual data to be enqueued QUE create and QUE delete are used to create and delete queues respectively Since QUE queues are implemented as linked lists queues have no maximum size This is also shown in Example 5 15 Example 5 15 Managing QUE Elements Using Queues typedef struct QUE_Elem truct QUE_Elem next truct QUE_Elem prev Elem typedef struct MsgObj QUE_Elem elem Char val 59003 ndle QUE create attrs a UE Attrs attrs UE delete queue E Handle queue 5 3 1 Atomic QUE Functions QUE put and QU
114. d configuration template for this example can be found in the C ti tutorial target siotest folder of the DSP BIOS product where target represents your platform The output for Example 7 7 is the same as found in Example 7 5 Streaming I O and Device Drivers 7 15 Stackable Devices 7 4 Stackable Devices The capabilities of the SIO module play an important role in fostering device independence within DSP BIOS in that logical devices insulate your application programs from the details of designating a particular device For example dac is a logical device name that does not imply any particular DAC hardware The device naming convention adds another dimension to device independent I O that is unique to DSP BIOS the ability to use a single name to denote a stack of devices Note By stacking certain data streaming or message passing devices atop one another you can create virtual I O devices that further insulate your applications from the underlying system hardware Consider as an example a program implementing an algorithm that inputs and outputs a stream of fixed point data using a pair of A D D A converters However the A D D A device can take only the 14 most significant bits of data and the other two bits have to be 0 if you want to scale up the input data Instead of cluttering the program with excess code for data conversion and buffering to satisfy the algorithm s needs we can open a pair of virtual device
115. d the host This is handled using RTDX On the C54x platform the RTDX_dataPump IDL object calls RTDX Poll to transfer data between the target and the host This occurs within the idle loop which runs at the lowest priority On the C55x and C6000 platforms the host PC triggers an interrupt to transfer data to and from the target This interrupt has a higher priority than SWI TSK and IDL functions The actual HWI function runs in a very short time Within the idle loop the LNK_dataPump function does the more time consuming work of preparing the buffers and performing the RTDX calls Only the actual data transfer is done at high priority This data transfer can have a small effect on real time behavior particularly if a large amount of LOG data must be transferred Thread Scheduling 4 47 The Idle Loop 4 48 2 dispatcher is a real time analysis server on the target that accepts commands from DSP BIOS Analysis Tools gathers instrumentation information from the target and uploads it at run time RTA_dispatcher sits at the end of two dedicated HST channels its commands responses are routed from to the host via LNK_dataPump IDL cpuLoad uses an STS object IDL busyObj to calculate the target load The contents of this object are uploaded to the DSP BIOS Analysis Tools through RTA dispatcher to display the CPU load RTDX dataPump calls RTDX Poll on the C5400 platform to transfer data between the target and the host T
116. d to customize the MEM objects and their properties You can customize MEM segments in the following ways 1 Insert a new MEM segment and define its properties For details on MEM object properties see the TMS320 DSP BIOS API Reference Guide for your platform Change the properties of an existing MEM segment Memory Management 2 Delete some MEM segments particularly those that correspond to external memory locations However you must first change any references to that segment made in the properties of other objects and managers To find dependencies on a particular MEM segment right click on that segment and select Show Dependencies from the pop up menu Deleting or renaming the IPRAM and IDRAM C6000 platform or IPROG and IDATA C5000 platform segments is not recommended 1 Rename some MEM segments To rename a segment follow these steps a Remove dependencies to the segment you want to rename To find dependencies on a particular MEM segment right click on that segment and select Show Dependencies from the pop up menu b Rename the segment You can right click on the segment name and choose Rename from the pop up menu to edit the name c Recreate dependencies on this segment as needed by selecting the new segment name in the property dialogs for other objects 5 1 2 Disabling Dynamic Memory Allocation If small code size is important to your application you can reduce code size significantly by removing the capabi
117. de mem h define NALLOCS 2 of allocations from each segment define BUFSIZE 128 size of allocations trace Log created by Configuration Tool extern LOG Obj trace ifdef 54 extern Int IDATA dendif ifdef 55 extern Int DATA Void printmem Int segid Void main Int i Ptr ram NALLOCS LOG_printf amp trace before allocating print initial memory status printmem LOG printf amp trace allocating allocate some memory from each segment for 1 0 i NALLOCS 1 ram i MEM alloc BUFSIZE 0 LOG printf amp trace seg d ptr Ox x ram il LOG printf amp trace after allocating print memory status printmem free memory for 1 0 i NALLOCS 1 MEM free ram i BUFSIZE LOG printf amp trace after freeing print memory status printmem printmem static Void printmem Int segid MEM_Stat statbuf MEM stat segid amp statbuf LOG printf amp trace seg d O Ox x segid statbuf size LOG printf amp trace tU Ox xNtA Ox x statbuf used stat buf length 5 8 Memory Management Note Non pointer type function arguments to LOG printf need explicit type casting to Arg as shown in the following code example LOG printf amp trace Task d Done Arg id l Example 5 8 Memory Allocation C6000 Platform memtest c This program a
118. de from main the readied thread is scheduled to run after the program returns from main and BIOS start finishes executing See the TMS320 DSP BIOS Reference Guide for your platform for more information on a particular DSP BIOS function call The Constraints and Calling Context sections indicates if the API cannot be called from main Chapter 3 Instrumentation DSP BIOS provides both explicit and implicit ways to perform real time program analysis These mechanisms are designed to have minimal impact on the application s real time performance Topic Page 3 1 Real Time Analysis 8 2 3 2 Instrumentation 8 3 3 3 Instrumentation APIs 6 3 4 Implicit DSP BIOS Instrumentation 3 5 Kernel Object View 28 3 6 Instrumentation for Field B 37 3 7 Real Time Data 3 1 Real Time Analysis 3 1 Real Time Analysis Real time analysis is the analysis of data acquired during real time operation of a system The intent is to easily determine whether the system is operating within its design constraints is meeting its performance targets and has room for further development 3 1 1 Real Time Versus Cyclic Debugging The traditional debugging method for sequential so
119. del SIO issue places frames on this queue fromdevice is used to transfer DEV Frame frames from the device In the SIO STANDARD DEV STANDARD streaming model SIO put gets empty frames from this queue and SIO get gets full frames from here In the SIO ISSUERECLAIM DEV ISSUERECLAIM streaming model SIO reclaim retrieves frames from this queue bufsize specifies the physical size of the buffers in the device queues nbufs specifies the number of buffers allocated for this device in the SIO STANDARD streaming model or the maximum number of outstanding buffers in the SIO ISSUERECLAIM streaming model segid specifies the segment from which device buffers were allocated SIO STANDARD mode specifies whether the device is an input DEV INPUT or output DEV OUTPUT device Streaming I O and Device Drivers 7 31 Streaming DEV Structures devid is the device ID params is a generic pointer to any device specific parameters Some devices have additional parameters which are found here objectis a pointer to the device object Most devices create an object that is referenced in successive device operations fxns is a DEV Fxns structure containing the driver s functions This structure is usually a copy of FXNS but it is possible for a driver to dynamically alter these functions in Dxx open timeout specifies the number of system ticks that SIO reclaim will wait for to complete Only the object and fxns field
120. der files for any modules the program uses module h54 DSP BIOS API header files for assembly programs Assembly source files should include the h54 header file for any module the assembly source uses program obj Object file s compiled or assembled from your source file s obj Object files for optional assembly source file s program cdb Configuration file that stores configuration settings This file is created by the Configuration Tool and used by both the Configuration Tool and the DSP BIOS Analysis Tools programcfg h54 Header file generated by the Configuration Tool This header file is included by the programcfg s54 file programcfg s54 Assembly source generated by the Configuration Tool programcfg cmd Linker command file created by the Configuration Tool and used when linking the executable file This file defines DSP BIOS specific link options and object names and generic data sections for DSP programs such as text bss data etc programcfg obj Object file created from the source file generated by the Configuration Tool cmd Optional linker command file s that contains additional sections for your program not defined by the Configuration Tool program out An executable program for the target fully compiled assembled and linked You can load and run this program with Code Composer Studio commands programcfg h File containing declarations of objects created with the Configuration Tool It a
121. device performs in place manipulations on data in buffers The copying stacking device moves the data to another buffer while processing the data Copying is necessary for devices that produce more data than they receive for example an unpacking device or an audio decompression driver or because they require access to the whole buffer to generate output samples and cannot overwrite their input data for example an FFT driver These types of stacking devices require different implementation since the copying device might have to supply its own buffers Figure 7 13 shows the buffer flow of a typical terminating device The interaction with DSP BIOS is relatively simple Its main complexities exist in the code to control and stream data to and from the physical device Types of Devices Figure 7 13 Buffer Flow in a Terminating Device Current Device todevice queue fromdevice queue To From Physical Device Figure 7 14 shows the buffer flow of an in place stacking driver All data processing is done in a single buffer This is a relatively simple device but it is not as general purpose as the copying stacking driver Figure 7 14 In Place Stacking Driver Issue Reclaim Current Device todevice queue fromdevice queue Underlying Device todevice queue fromdevice queue Streaming I O and Device Drivers 7 47 Types of Devices Figure 7 15 shows the
122. e inen 4 5 The ldle Loop ui athena wi DR PE EE EO aede eb er 4 6 Semaphores nae Pe Rex Pew arx dos 4 7 MEloic TP MePCCCP 4 8 Timers Interrupts and the System 4 9 Periodic Function Manager PRD and the System Clock 4 10 Using the Execution Graph to View Program 5 Memory and Low level Functions This chapter describes the low level functions found in the DSP BIOS real time multitasking ker nel These functions are embodied in three software modules MEM which manages allocation of memory SYS which provides miscellaneous system services and QUE which manages queues 5 1 Memory Management s s rrrisisirokas skia CERAR hr 5 2 System Services aa E hn 5 3 QI EEEE wk ae eee EEEE EES 6 Input Output Overview and This chapter provides an overview on data transfer methods and discusses pipes in particular 6 1 ree Sed hea ne we 6 2 Comparing Pipes and 5 lt 6 3 Data Pipe Manager PIP 6 4 Host Channel Manager HST Module 6 5 I O Performance Issues
123. e l designcfg cmd ECTIONS place high performanc fast text Linker Command File C6000 Platform code in on device ram myfastcode lib text myfastcode lib switch gt IPRA all other user switch Rosi pinit user data in bss fara gt gt gt gt gt gt code in off device ram SDRAMO SDRAMO SDRAMO SDRAMO on device ram IDRAM IDRAM Example 5 2 Linker Command File C5000 Platform First include DSP BIOS generated cmd file l designcfg cmd ECTIONS place high performanc fast text code in on device ram myfastcode lib text myfastcode lib switch gt IPROG PAGE 0 all other user text Switch scinits Pines user data in bss shaw gt gt 2 gt gt gt EPROGO EPROGO EPROGO EPROGO device ram 0 code in off PAGI PAGI PAGI PAGI E 0 0 0 on device ram IDA IDA A PAGE 1 A PAGE 1 Memory Management 5 1 4 Allocating Memory Dynamically Basic system level storage allocation is handled by MEM alloc whose parameters specify a memory segment a block size and an alignment as shown in Example 5 3 If the memory request cannot be satisfied MEM alloc returns MEM ILLEGAL Example 5 3 Using MEM alloc for System Level Storage
124. e C6000 platform d d The first two ABMASK and CMASK specify which A B and control registers are to be saved and restored by the ISR The third parameter on the C6000 platform IEMASK is a mask of those interrupts that are to be disabled between the HWI enter HWI exit macro calls When an interrupt is triggered the processor disables interrupts globally by clearing the GIE bit in the control status register CSR and then jumps to the ISR set up in the interrupt service table The HWI enter macro reenables interrupts by setting the GIE in the CSR Before doing so HWI enter selectively disables bits in the interrupt enable register IER determined by the IEMASK parameter Hence HWI enter gives you control to select what interrupts can and cannot preempt the current HWI function When HWI exit is called the bit pattern in the IEMASK determines what interrupts are restored by HWI exit by setting the corresponding bits in the IER Of the interrupts in IEMASK HWI exit restores only those that were disabled with HWI enter If upon exiting the ISR you do not want to restore one of the interrupts that was disabled with HWI enter do not set that interrupt bit in IEMASK in HWI exit HWI exit does not affect the status of interrupt bits that are not in IEMASK Hardware Interrupts 2 The fourth parameter on the C6000 platform CCMASK specifies the value to place in the cache control field of the CSR This cache state rem
125. e generated by the Configuration programcfg cmd Figure 2 4 MEM Module Properties Panel MEM Memory Section Manager Properties Ed System sections Compiler sections Load Address General BIOS sections Reuse startup code space Map Mode Map1 Argument Buffer Size 00004 Stack Size MAUs M00 Segment for DSP BIOS objects SDRAM m Segment for malloc free SDRAM ew Specify User Linker cmd File Cancel gpl Help Program Generation 2 15 Compiling and Linking Programs 2 4 2 Makefiles Note Code Composer Studio software allows only one linker command file per project When both programcfg cmd and app cmd are required by the application the project should use app cmd rather than programcfg cmd as the projects linker command file To include programcfg cmd in the linking process you must add the following line to the beginning of app cmd lprogramcfg cmd This line begins with a dash character and then a lower case L character It is not the numeric one character It is important that this line appear at the beginning so that programcfg cmd is the first linker command file used by the linker and program is the name of the executable program being linked as well as the name of the associated configuration file As an alternative to building your program as a Code Composer Studio project you can use a makefile In the following example the C sour
126. e reading from or writing to the pipe Uses less memory and is generally faster Each pipe owns its own buffers Pipes must be created statically with the Configuration Tool No built in support for stacking devices Using the HST module with pipes is an easy way to handle data transfer between the host and target Provides a more structured approach to device driver creation One end must be handled by a task TSK using SIO calls The other end must be handled by an HWI using Dxx calls SIO put SIO get and SIO reclaim are blocking functions and causes a task to wait until a buffer is available SIO issue is non blocking More flexible generally simpler to use Buffers can be transferred from one stream to another without copying In practice copying is usually necessary anyway because the data is processed Streams can be created either at run time or statically with the Configuration Tool Streams can be opened by name Support is provided for stacking devices A number of device drivers are provided with DSP BIOS Data Pipe Manager PIP Module 6 3 Data Pipe Manager PIP Module Pipes are designed to manage block I O also called stream based or asynchronous I O Each pipe object maintains a buffer divided into a fixed number of fixed length frames specified by the numframes and framesize properties All I O operations on a pipe deal with one frame at a time Although each frame has a fixed l
127. e required stack size grows each time you add a software interrupt priority level Thus giving software interrupts the same priority level is more efficient in terms of stack size than giving each software interrupt a separate priority The default system stack size for the MEM module is 256 words You can change the sizes in the Configuration Tool The estimated sizes required are shown in the status bar at the top of the Configuration Tool Thread Scheduling 4 23 Software Interrupts You can have up to 15 software interrupt priority levels but each level requires a larger system stack If you see a pop up message that says the System stack size is too small to support a new software interrupt priority level increase the Application Stack Size property of the Memory Section Manager Creating the first PRD object creates a new SWI object called PRD swi see section 4 9 Periodic Function Manager PRD and the System Clock page 4 68 for more information on PRD If no SWI objects have been created before the first PRD object is added adding PRD_swi uses the first priority level producing a corresponding increase in the required system stack If the TSK Manager has been enabled the TSK scheduler run by an SWI object named KNL_swi reserves the lowest SWI priority level No other SWI objects can have that priority 4 3 4 Execution of Software Interrupts Software interrupts can be scheduled for execution with a call to SWI
128. e stream Ptr pbuf Uns nbytes Arg arg Int SIO reclaim stream bufp parg SIO Handle stream PUr bufp Arg parg If no buffer is available the stream will block the task until the buffer becomes available or the stream s timeout has elapsed At a basic level the most obvious difference between the standard and Issue Reclaim models is that the Issue Reclaim model separates the notification of a buffer s arrival SIO issue and the waiting for a buffer to become available SIO reclaim So an SIO issue SIO reclaim pair provides the same buffer exchange as calling SIO get or SIO put The Issue Reclaim streaming model provides greater flexibility by allowing the stream client to control the number of outstanding buffers at runtime A client can send multiple buffers to a stream without blocking by using SIO issue The buffers are returned at the client s request by calling SIO reclaim This allows the client to choose how deep to buffer a device and when to block and wait for a buffer The Issue Reclaim streaming model also provides greater determinism in buffer management by guaranteeing that the client s buffers are returned in the order that they were issued This allows a client to use memory from any source for streaming For example if a DSP BIOS task receives a large buffer that task can pass the buffer to the stream in small pieces simply by advancing a pointer through the larger buffer and calling SIO issue f
129. e that an analog to digital converter device a2d has a control operation to change the sample rate The sample rate might be changed to 12 kHz as shown in Example 7 11 Example 7 11 Changing Sample Rate SIO Handle stream stream SIO create a2d SIO ctrl stream DAC RATE 12000 In some situations you can synchronize with an device that is doing buffered I O There are two methods to synchronize with the devices SIO idle and SIO flush Either function leaves the device in the idled state ldling a device means that all buffers are returned to the queues that they were in when the device was initially created That is the device is returned to its initial state and streaming is stopped For an input stream the two functions have the same results all unread input is lost For an output stream SIO idle blocks until all buffered data has been written to the device However SIO flush discards any data that has not already been written SIO flush does not block as shown in Example 7 12 Example 7 12 Synchronizing with a Device Void SIO idle stream SIO Handle stream Void SIO flush stream SIO Handle stream An idle stream does not perform I O with its underlying device Thus a stream can be turned off until further input or output is needed by calling SIO idle or SIO flush Streaming I O and Device Drivers 7 23 Selecting Among Multiple Streams 7 6 Selecting Among Multiple Str
130. eams Example 7 13 The SIO select function allows a single DSP BIOS task to wait until an I O operation can be performed on one or more of a set of SIO streams without blocking For example this mechanism is useful in the following applications Non blocking I O Real time tasks that stream data to a slow device for example a disk file must ensure that SIO put does not block Multitasking In virtually any multitasking application there are daemon tasks that route data from several sources The SIO select mechanism allows a single task to handle all of these sources SIO select is called with an array of streams an array length and a time out value SIO select blocks if timeout is not 0 until one of the streams is ready for I O or the time out expires In either case the mask returned by SIO select indicates which devices are ready for service a 1 in bit j indicates that streamtab j is ready as shown in Example 7 13 Indicating That a Stream is Ready Uns SIO select streamtab nstreams timeout SIO Handle streamtab stream table Uns nstreams number of streams Uns timeout return after this many system clock ticks 7 6 1 Programming Example In Example 7 14 two streams are polled to see if an I O operation will block Example 7 14 Polling Two Streams SIO Handle stream0 SIO Handle streaml SIO Handle streamtab 2 Uns mask streamtab 0 stream0 s
131. ed in the left column of the trace window to indicate the order in which the events occurred These numbers are an increasing sequence starting at O If your log never fills up you can use a smaller log size If a circular log is not long enough or you do not poll the log often enough you may miss some log entries that are overwritten before they are polled In this case you see gaps in the log message numbers You may want to add an additional sequence number to the log messages to make it clear whether log entries are being missed Synchronize Sliders Apply The online help in the Configuration Tool describes LOG objects and their parameters See LOG Module in the TMS320 DSP BIOS API Reference Guide for your platform for information on the LOG module API calls Instrumentation 3 9 Instrumentation APIs 3 3 3 Statistics Object Manager STS Module This module manages statistics objects which store key statistics while a program runs You create individual statistics objects using the Configuration Tool Each STS object accumulates the following statistical information about an arbitrary 32 bit wide data series Count The number of values on the target in an application supplied data series Total The arithmetic sum of the individual data values on the target in this series Maximum The largest value already encountered on the target in this Series Average Using the count and total
132. ed in dxx c This table is used by the SIO module to call specific device driver functions For example SIO put uses this table to find and call Dxx issue Dxx reclaim The table is shown in Example 7 18 Example 7 18 Table of Device Functions DEV Fxns Dxx FXNS Dxx close Dxx ctrl Dxx idle Dxx issue Dxx open Dxx ready Dxx reclaim Streaming I O and Device Drivers 7 29 Streaming DEV Structures 7 10 Streaming DEV Structures The DEV Fxns structure contains pointers to internal driver functions corresponding to generic I O operations as shown in Example 7 19 Example 7 19 The DEV Fxns Structure typedef struct DEV Fxns Int close DEV Handle Int ctrl DEV Handle Uns Arg Int idle DEV Handle Bool Int issue DEV Handle Int open DEV Handle String Bool ready DEV Handle SEM Handle Int reclaim DEV Handle DEV Fxns D evice frames are structures of type DEV Frame used by SIO and device drivers to enqueue dequeue stream buffers as shown in Example 7 20 The device todevice and device fromdevice queues contain elements of this ly pe Example 7 20 The DEV Frame Structure typedef struct DEV Frame QUE Elem link Ptr addr Uns size Arg misc Arg arg DEV Frame Example 7 20 has the following parameters d d a link is used by QUE put and QUE get to enqueue deq
133. efficient because they all run from a single stack IDL Create background functions to perform noncritical housekeeping tasks when no other processing is necessary IDL functions do not typically have hard deadlines Instead they run whenever the system has unused processor time CLK Use CLK functions when you want a function to be triggered directly by a timer interrupt These functions run as HWI functions and should take minimal processing time The default CLK object clock causes a tick for the periodic functions You can add additional CLK objects to run at the same rate However you should minimize the time required to perform all CLK functions because they run as HWI functions PRD Use PRD functions when you want a function to run at a rate based on a multiple of the on device timer s low resolution rate or another event such as an external interrupt These functions run as SWI functions PRD versus SWI All PRD functions run at the same SWI priority so one PRD function cannot preempt another However PRD functions can post lower priority software interrupts for lengthy processing routines This ensures that the PRD_swi software interrupt can preempt those routines when the next system tick occurs and PRD swi is posted again 4 1 3 A Comparison of Thread Characteristics Overview of Thread Scheduling Table 4 1 provides a comparison of the thread types supported by DSP BIOS Table 4 1 Comparison of Thread Chara
134. eing executed in the context of the HWI where PRD tick was called As a result there can be a delay between the time the System tick occurs and the execution of the periodic objects whose periods have expired with the tick If these functions run immediately after the tick you should configure PRD swi to have a high priority with respect to other threads in your application 4 9 2 Interpreting PRD and SWI Statistics Many tasks in a real time system are periodic that is they execute continuously and at regular intervals It is important that such tasks finish executing before it is time for them to run again A failure to complete in this time represents a missed real time deadline While internal data buffering can be used to recover from occasional missed deadlines repeated missed deadlines eventually result in an unrecoverable failure The implicit statistics gathered for SWI functions measure the time from when a software interrupt is ready to run and the time it completes This timing is critical because the processor is actually executing numerous hardware and software interrupts If a software interrupt is ready to execute but must wait too long for other software interrupts to complete the real time deadline is missed Additionally if task starts executing but is interrupted too many times for too long a period of time the real time deadline is also missed Thread Scheduling 4 69 Periodic Function Manager PRD and the System
135. eleted but also when a local object goes out of scope You need to be aware of what type of thread is executing when the class destructor is called and make only those DSP BIOS API calls that are appropriate for that thread For further information on function callability see the TMS320 DSP BIOS API Reference Guide for your platform User Functions Called by DSP BIOS 2 8 User Functions Called by DSP BIOS o User functions called by DSP BIOS objects IDL TSK SWI PIP PRD and CLK objects need to follow specific conventions in order to ensure that registers are used properly and that values are preserved across function calls On the C6x and 55 platforms all user functions called by DSP BIOS objects need to conform to C compiler register conventions for their respective platforms This applies to functions written both in C and assembly languages The compiler distinguishes between C and assembly functions by assuming that all C function names are preceded by an underscore and assembly function names are not preceded by an underscore On the C54x platform this distinction becomes especially important because C and assembly functions conform to two different sets of rules Functions that are preceded by an underscore this includes C functions and any assembly functions whose names are preceded by an underscore must conform to the C compiler conventions On the C54x platform assembly functions functions that are not preceded b
136. ength the application can put a variable amount of data in each frame up to the length of the frame As shown in Figure 6 3 a pipe has two ends The writer end is where the program writes frames of data The reader end is where the program reads frames of data Figure 6 3 The Two Ends of a Pipe Writer Reader 1 PIP alloc 1 PIP get 2 Writes data into allocated frame 2 Reads data from frame just received 3 PIP put runs notifyReader 3 PIP free runs notifyWriter Data notification functions notifyReader and notifyWriter are performed to synchronize data transfer These functions are triggered when a frame of data is read or written to notify the program that a frame is free or data is available These functions are performed in the context of the function that calls PIP free or PIP put They can also be called from the thread that calls PIP get or PIP alloc When PIP get is called DSP BIOS checks whether there are more full frames in the pipe If so the notifyReader function is executed When PIP alloc is called DSP BIOS checks whether there are more empty frames in the pipe If so the notifyWriter function is executed A pipe should have a single reader and a single writer Often one end of a pipe is controlled by an HWI and the other end is controlled by a software interrupt function Pipes can also be used to transfer data within the program between two application threads During program startup which
137. ent buffer size doubling that is eight words Thread Scheduling 4 75 Chapter 5 Memory and Low level Functions This chapter describes the low level functions found in the DSP BIOS real time multitasking kernel These functions are embodied in three software modules MEM which manages allocation of memory SYS which provides miscellaneous system services and QUE which manages queues This chapter also presents several simple example programs that use these modules The system primitives are described in greater detail in Chapter 1 in the TMS320 DSP BIOS Reference Guide for your platform Topic Page 5 1 Memory 5 2 5 25 System Services 5 11 5 3 Queues 5 1 Memory Management 5 1 Memory Management The Memory Section Manager MEM module manages named memory segments that correspond to physical ranges of memory If you want more control over memory segments you can create your own linker command file and include the linker command file created by the Configuration Tool It also provides a set of functions that can be used to dynamically allocate and free variable sized blocks of memory Unlike standard C functions like malloc the MEM functions enable you to specify which segment of memory is used to satisfy a particular request for storage Real time DSP hardware platforms typically contain several different types of memory fast on devi
138. equence you can measure specific value differences or the value difference since the last STS update Example 3 1 shows code for gathering information about differences between specific values Figure 3 6 shows current values when measuring differences from the base value Example 8 1 Gathering Information About Differences in Values STS set amp sts targetValue Tg processing STS delta amp sts currentValue T processing STS delta amp sts currentValue T processing STS delta amp sts currentValue T processing Figure 3 6 Current Value Deltas From One STS set Current value 3 y T2 Ts Z Previous value Time T Delta Current Value x Instrumentation 3 13 Instrumentation APIs Example 3 2 gathers information about a value s difference from a base value Figure 3 7 illustrates the current value when measuring differences from a base value Example 3 2 Gathering Information About Differences from Base Value STS set amp sts baseValue processing STS d STS s processing lta amp sts currentValue t amp sts baseValue e e e STS delta amp sts currentValue e e e STS set amp sts baseValue processing STS delta amp sts currentValue STS set amp sts baseValue processing Figure 3 7 Current Value Deltas from Base Value
139. er SWI functions that are written in assembly must follow C register usage conventions For the C6000 platform they must save and restore any of the registers numbered A10 to A15 and B10 to B15 On the C5000 platform they must save and restore registers ar1 ar6 and ar7 See the optimizing compiler user s guide for your platform for more details on C register conventions An SWI function that modifies the IER register should save it and then restore it before it returns If the SWI function fails to do this the change becomes permanent and any other thread that starts to run or that the program returns to afterwards can inherit the modification to the IER The context is not saved automatically within an HWI function You must use the HWI enter HWI exit macros or the HWI dispatcher to preserve the interrupted context when an HWI function is triggered 4 3 8 Synchronizing SWI Handlers Within an idle loop function task or software interrupt function you can temporarily prevent preemption by a higher priority software interrupt by calling SWI disable which disables all SWI preemption To reenable SWI preemption call SWI enable Software interrupts are enabled or disabled as a group An individual software interrupt cannot be enabled or disabled on its own When DSP BIOS finishes initialization and before the first task is called software interrupts have been enabled If an application wishes to disable software interrupts it
140. eration of devices TMS320C54x Optimizing C Compiler User s Guide literature number SPRU103 describes the C54x C compiler This C compiler accepts ANSI standard C source code and produces TMS320 assembly language source code for the C54x generation of devices TMS320C55x Optimizing C Compiler User s Guide literature number SPRU281 describes the C55x C compiler This C compiler accepts ANSI standard C source code and produces TMS320 assembly language source code for the C55x generation of devices TMS320C6000 Optimizing C Compiler User s Guide literature number SPRU187 describes the C6000 C C compiler and the assembly optimizer This C C compiler accepts ANSI standard C C source code and produc es assembly language source code for the C6000 generation of devices The assembly optimizer helps you optimize your assembly code TMS320C55x Programmer s Guide literature number SPRU376 describes ways to optimize C and assembly code for the TMS320C55x DSPs and includes application program examples TMS320C6000 Programmer s Guide literature number SPRU189 describes the C6000 CPU architecture instruction set pipeline and interrupts for these digital signal processors Read This First V Helated Documentation From Texas Instruments vi TMS320C54x DSP Reference Set Volume 1 CPU and Peripherals literature number SPRU131 describes the TMS320C54x 16 bit fixed point general purpose digital signal processors Covered are its arc
141. errupt must be either wrapped within HWI enter HWI exit pair or invoked by the HWI dispatcher L SWI functions can be preempted by threads of higher priority such as an HWI or an SWI of higher priority However SWI functions cannot block You cannot suspend a software interrupt while it waits for something like a device to be ready If an SWI is posted multiple times before the SWI Manager has removed it from the posted SWI list its SWI function executes only once much like an HWI is executed only once if the hardware interrupt is triggered multiple times before the CPU clears the corresponding interrupt flag bit in the interrupt flag register See section 4 3 5 Using an SWI Object s Mailbox page 4 25 for more information on how to handle SWls that are posted multiple times before they are scheduled for execution Applications should not make any assumptions about the order in which SWI handlers of equal priority are called However an SWI handler can safely post itself or be posted by another interrupt If more than one is pending all SWI handlers are called before any tasks run 4 3 5 Using an SWI Object s Mailbox Each SWI object has a 32 bit mailbox for C6000 and a 16 bit mailbox for C5400 which are used either to determine whether to post the software interrupt or as values that can be evaluated within the SWI function SWI post SWI or and SWI inc post an SWI object unconditionally SWI post does not m
142. ert and QUE remove are used to insert or remove an element from an arbitrary point within the queue Memory and Low level Functions 5 15 Queues Example 5 17 Using QUE Functions with Mutual Exclusion Elements equeue queue Handle queue enqueue queue lem E Handle queue elem Ptr QUE head queue QUE Handle queue Ptr QUE next qelem Ptr qelem Ptr QUE prev qelem Ptr qelem Void QUE insert qelem lem Ptr qelem Ptr elem Void QUE remove qelem Ptr qelem Note Since QUE queues are implemented as doubly linked lists with a header node it is possible for QUE head QUE next or QUE prev to return a pointer to the header node itself for example calling QUE head on an empty queue Be careful not to call QUE remove and remove this header node 5 3 3 QUE Example Example 5 18 uses a QUE queue to send five messages from a writer to a reader task The functions MEM alloc and MEM free are used to allocate and free the MsgObj structures The program in Example 5 18 yields the results shown in Figure 5 3 The writer task uses QUE put to enqueue each of its five messages and then the reader task uses QUE get to dequeue each message Queues Example 5 18 Using QUE to Send Messages 0 quetest c Use a QUE queue to send messages from a writer to a rea
143. es or D6vices iie eub rx Rb Eisen US te B Contents 1 Figures 1 1 1 3 1 4 1 5 2 1 2 2 2 3 2 4 3 2 DSP BIOS Gombponhehls etre teret ete hoc 1 4 Configuration Tool Interface enne nennen nennen nnd 1 7 The DSP BIOS MOnU tren etie eene cessare nnd cas Ee Cu dc 1 8 Code Composer Studio Analysis Tool Panels E DSP BIOS Analysis Tools Toolbar sesssssssssseeeeeneeeene enne 1 10 DSP BIOS Program Creation Files esses 2 12 Sample Code Composer Project Files List 2 14 MEM Module Properties Panel essen eene eee nnns 2 15 Message Log Dialog eee Lee Lect e 3 7 LOG Buffer Sequence 3 8 RTA Control Panel Properties Dialog 3 9 Statistics View Panel ncc sepe t tete sees Lese dtu Target Host Variable Accumulation essen eene enne Current Value Deltas From One 5_5 Current Value Deltas from Base Value RTA Control Panel Dialog BOx ssssssssesesseeeeeen entente nennen ns Execution Graph WIRGOQOW uci tn ett rt nre en ren tte uen d
144. esolve the reference to malloc The run time support library implements printf with breakpoints Depending on how often your application uses printf and the frequency of the calls printf can interfere with RTDX thus affecting real time analysis tools such as the Message Log and Statistics View and preventing these tools from updating This is because the printf breakpoint processing has higher priority processing than RTDX It is therefore recommended to use LOG_printf in place of calls to printf wherever possible within DSP BIOS applications Using DSP BIOS with the Run Time Support Library Note It is recommended to use the DSP BIOS library version of malloc free memalign calloc and realloc within DSP BIOS applications When you are not referencing these functions directly in your application but call another run time support function which references one or more of them add u symbol for example u malloc to your linker options The u linker option introduces a symbol such as malloc as an unresolved symbol into the linker s symbol table This causes the linker to resolve the symbol from the DSP BIOS library rather than the run time support library If in doubt you can examine your map file for information on the library sources of your application Program Generation 2 19 DSP BIOS Startup Sequence 2 6 DSP BIOS Startup Sequence When a DSP BIOS application starts up the calls or instructions in the bo
145. ew software interrupts See interrupts source files space requirements SPOX error conditions 5 13 stack modes 2 23 stack overflow 4 40 stack overflow check stack pointer 3 23 stack size and task objects 4 34 stackable writing standard As model 7 6 7 31 and buffers implementing standardization Start menu startup ain startup sequence static ob jects statistics 19 3 accumulating 3 12 gathering 4 70 performance 3 3 units Statistics Manager 3 10 Statistics Object Manager 8 6 Statistics View std h 1 11 std h header file stream attributes streaming models main description See also Issue Reclaim standard streaming model streams buffer exchange 7 4 buffer management 7 8 7 9 creating SIO create data buffer input data buffer input See also SIO get 7 7 data buffer output data buffer out put also SIO_put 7 7 definition of Index 7 Index streams continued deleting See also SIO delete idle input interaction with devices 6 3 interaction with drivers 6 2 multiple output 6 2 polling 7 24 reading data from selecting among multiple String Uns 1 13 STS module explicit instrumentation 3 10 implicit instrumentation operations on registers overview 25 STS operations 3 26 STS add 3 12 SWI and blocking and preem 22 posting Property window SWI module implicit instrumentation SWI object 4 21 SWI getattrs SWI startup
146. f CSL Chip Support Library E For Help press F1 Estimated Data Size 2864 Est Min Stack Size MAUs 448 7 2 2 6 Ordered Collection View The Ordered Collection View displays the list of objects per module in the order the objects will be executed on the target as seen in Figure 2 1 To view the Ordered Collection View right click on the module name and select Ordered Collection View The following objects can be listed in the Ordered Collection View 2 6 Using the Configuration Tool CLK Clock Manager PRD Periodic Function Manager SWI Software Task Manager TSK Task Manager O IDL Idle Function Manager D D C The order of objects in the Ordered Collection View can be rearranged by dragging and dropping the object into its new position For example if you require the CLKO object to execute immediately after the PRD clock object drag and drop CLKO on top of the clock object The dropped object is placed in the list immediately after the object that it is dropped upon and will execute in that order This is shown in Figure 2 1 2 2 7 Referencing Static DSP BIOS Objects Created with the Configuration Tool Objects created using the Configuration Tool need to be declared using the extern variable declaration and must be defined outside of all function bodies For example extern far PIP Obj inputObj C6000 devices or exte
147. f the value is non zero you can click on the number to see the list of tasks Tasks Posting This is the number of tasks currently blocked waiting to write a message to the mailbox If the value is non zero you can click on the number to see the list of tasks as shown in Figure 3 19 Msg Size This is the size of each message in the processor s minimum adressable data units MADUs This matches the values set during configuration or creation MADUs are equivalent to a 16 bit word in the data address space of the processor on the C54x and C55x platforms and to an 8 bit word on the C6x platforms Segment This is the memory segment number Figure 3 19 Viewing a List of Tasks Currently Blocked DSP BIOS gt Kernel Object View KNL TSK Refresh Disable MBX SEM MEM Swi Mailbox es Click the number to view tasks Name Handle Tasks Pending Tasks Posting Msg Size Segment y z mbx 0x800006FC 2 2 writer 0 8000 Kernel Object View Debugger 3 5 4 Semaphores The semaphores page select the tab labeled SEM shows all semaphore information as illustrated in Figure 3 20 Figure 3 20 The Semaphores Page Dialog Box DSP BIOS Kemel bject View KNL TSK MBX SEM MEM swi Refresh Disable 3 Semaphore s sem O S0000B50 sem 0x80000678 sem2 0 80000 The semaphores page fields and other information are as follows 2 Semaphore s The value in this field
148. fits to using software interrupts instead of hardware interrupts First SWI handlers can execute with all hardware interrupts enabled To understand this advantage recall that a typical HWI modifies a data structure that is also accessed by tasks Tasks therefore need to disable hardware interrupts when they wish to access these data structures in a mutually exclusive way Obviously disabling hardware interrupts always has the potential to degrade the performance of a real time system Conversely if a shared data structure is modified by an SWI handler instead of an HWI mutual exclusion can be achieved by disabling software interrupts while the task accesses the shared data structure SWI disable and SWI enable are described later in this chapter Thus there is no effect on the ability of the system to respond to events in real time using hardware interrupts It often makes sense to break long ISRs into two pieces The HWI takes care of the extremely time critical operation and defers the less critical processing to an SWI handler Software Interrupts The second advantage is that an SWI handler can call some functions that cannot be called from an HWI because an SWI handler is guaranteed not to run while DSP BIOS is updating internal data structures This is an important feature of DSP BIOS and you should become familiar with the table Functions Callable by Tasks SWI Handlers or Hardware ISRs in the TMS320 DSP BIOS Reference G
149. followed by a call to PIP free before PIP get can be called again as shown in Example 6 4 The pipe I O mechanism does not allow consecutive PIP get calls Doing so would overwrite previous descriptor information and produce undetermined results Example 6 4 Using PIP get correct error PIP get PIP get PIP free PIP get PIP get PIP free PIP free PIP free 6 3 4 1 Avoiding Recursion Problems Care should be applied when a pipe s notify function calls PIP APIs for the same pipe Consider the following example A pipe s notifyReader function calls PIP get for the same pipe The pipe s reader is an HWI routine The pipe s writer is an SWI routine Hence the reader has higher priority than the writer Calling PIP get from the notifyReader in this situation can make sense because this allows the application to get the next full buffer ready to be used by the reader the HWI routine as soon as it is available and before the hardware interrupt is triggered again Data Pipe Manager PIP Module The pipe s reader function the HWI routine calls PIP get to read data from the pipe The pipe s writer function the SWI routine calls PIP put Since the call to the notifyReader happens within PIP put in the context of the current routine a call to PIP get also happens from the SWI writer routine Hence in the example described two threads with different priorities call PIP get for the same pipe
150. for any driver included in the product distribution or a user supplied driver To use a stream to perform I O with a device first configure the device in the Configuration Tool Then create the stream object in the Configuration Tool or at runtime with the SIO create function 7 2 1 Creating Streams with the Configuration Tool You can create streams using the Configuration Tool The Configuration Tool allows you to set the stream attributes for each stream and for the SIO Manager itself You cannot use the SIO delete function to delete streams created with the Configuration Tool 7 2 2 Creating and Deleting Streams Dynamically Example 7 1 You can also create a stream at run time with the SIO create function as shown in Example 7 1 Creating a Stream with SIO create SIO Handle SIO create name mode bufsize attrs String name Int mode Uns bufsize SIO Attrs attrs SIO create creates a stream and returns a handle of type SIO Handle SIO create opens the device s specified by name specifying buffers of size bufsize Optional attributes specify the number of buffers the buffer memory segment the streaming model etc The mode parameter is used to specify whether the stream is an input SIO INPUT or output SIO OUTPUT stream Note The parameter name must match the name given to the device in the Configuration Tool preceded by a slash character For example for a device called sine name s
151. for real time statistics it resets the variables on the target This minimizes space requirements on the target while allowing you to keep statistics for long test runs You can specify the buffer size for LOG objects The buffer size affects the program s data size and the time required to upload log data For performance reasons implicit hardware interrupt monitoring is disabled by default When disabled there is no effect on performance When enabled updating the data in statistics objects consumes between 20 and 30 instructions per interrupt for each interrupt monitored Instrumented Versus Non instrumented Kernel It is possible to disable support for the kernel instrumentation by changing the global properties of the application Within the Configuration Tool the Global Settings module has a property called Enable Real Time Analysis By unchecking this checkbox you can achieve optimal code size and execution speed This is accomplished by linking with a DSP BIOS library that does not support the implicit instrumentation However this also has the effect of removing support for DSP BIOS Analysis Tools and explicit instrumentation such as the LOG TRC and STS module APIs The Table 3 1 presents examples of code size increases when working with the instrumented versus non instrumented kernel These figures provide a general idea of the amount of code increase that can be expected when working with the instrumented kernel Tab
152. ftware is to execute the program until an error occurs You then stop the execution examine the program state insert breakpoints and reexecute the program to collect information This kind of cyclic debugging is effective for non real time sequential software However cyclic debugging is rarely as effective in real time systems because real time systems are characterized by continuous operation nondeterministic execution and stringent timing constraints The DSP BIOS instrumentation APIs and the DSP BIOS Analysis Tools are designed to complement cyclic debugging tools to enable you to monitor real time systems as they run This real time monitoring data lets you view the real time system operation so that you can effectively debug and performance tune the system 3 1 2 Software Versus Hardware Instrumentation 3 2 Software monitoring consists of instrumentation code that is part of the target application This code is executed at run time and data about the events of interest is stored in the target system s memory Thus the instrumentation code uses both the computing power and memory of the target system The advantage of software instrumentation is that it is flexible and that no additional hardware is required Unfortunately because the instrumentation is part of the target application performance and program behavior can be affected Without using a hardware monitor you face the problem of finding a balance between program pert
153. full frame that the application got and that is currently reading When PIP_alloc is called the writer counter is decreased by one An empty frame is removed from the writer list and the writer frame descriptor is updated with the information from this frame When the application calls PIP put after filling the frame the reader counter is increased by one and the writer frame descriptor is used by DSP BIOS to add the new full frame to the pipe s reader list Note Every call to PIP alloc must be followed by a call to PIP put before PIP alloc can be called again the pipe I O mechanism does not allow consecutive PIP alloc calls Doing so would overwrite previous descriptor information and would produce undetermined results This is shown in Example 6 3 L Input Output Overview and Pipes 6 9 Data Pipe Manager PIP Module Example 6 3 Using PIP_alloc correct error PIP alloc PIP alloc PIP put PIP alloc PIP alloc PIP put PIP put PIP put Similarly when PIP_get is called the reader counter is decreased by one A full frame is removed from the reader list and the reader frame descriptor is updated with the information from this frame When the application calls PIP free after reading the frame the writer counter is increased by and the reader frame descriptor is used by DSP BIOS to add the new empty frame to the pipe s writer list Hence every call to PIP get must be
154. g temporarily with TSK_disable This prevents any higher priority task from preempting the current task It does not prevent software and hardware interrupts from preempting the current task 1 The highest priority thread is a task that is blocked This occurs if the task calls TSK_sleep LCK_pend MBX_pend or SEM_pend Both hardware and software interrupts can interact with the DSP BIOS task scheduler When a task is blocked it is often because the task is pending on a semaphore which is unavailable Semaphores can be posted from HWIs and SWIs as well as from other tasks If an HWI SWI posts a semaphore to unblock a pending task the processor switches to that task if that task has a higher priority than the currently running task When running either an HWI or SWI DSP BIOS uses a dedicated system interrupt stack called the system stack Each task uses its own private stack Therefore if there are no TSK tasks in the system all threads share the same system stack Because DSP BIOS uses separate stacks for each task both the application and task stacks can be smaller Because the system stack is smaller you can place it in precious fast memory Table 4 2 shows what happens when one type of thread is running top row and another thread becomes ready to run left column The results depend on whether or not the type of thread that is ready to run is enabled or disabled The action shown is that of the thread that is ready to run
155. grams When you save a configuration file for your program with the Configuration Tool the following files are created These files are described below The numeric 62 is applicable to the C62x platform only Replace the 62 in the extensions with 54 55 or 64 depending on your platform C O O C O O program cdb programcfg h54 programcfg s54 programcfg cmd programcfg h programcfg_c c Figure 2 2 shows the files used to create DSP BIOS programs Files you write are represented with a white background generated files are represented with a gray background The word program represents the name of your project or program Figure 2 2 DSP BIOS Program Creation Files asm c or program c cpp optional compile or a assemble include assemble compile program cmd optional generate 2 12 program c Program source file containing the main function You can also have additional c source files and program h files For user functions see section 2 8 User Functions Called by DSP BIOS asm Optional assembly source file s One of these files can contain an assembly language function called main as an alternative to using a C or C function called main Files Used to Create DSP BIOS Programs module h DSP BIOS header files for C or programs Your source files should include std h and the hea
156. h of the bits set in the SWI mailbox default value Hence the software interrupt is posted only when data from both processes is ready Figure 4 6 Using SWI andn to Post an SWI Mailbox Value returned by Program configuration value SWI getmbox SWI object myswi Function myswiFxn we 14 d Program execution Calls ol lo SWI andn amp myswi Ox1 myswi is not posted Calls 0 0JO SWI andn amp myswi 0 2 myswi is posted SWI manager removes oO 1111 myswi from the posted SWI queue myswiFxn is scheduled for execution myswiFxn starts fo 11 execution In some situations the SWI function can call different routines depending on the event that posted it In that case the program can use SWI or to post the SWI object unconditionally when an event happens This is shown in Figure 4 7 The value of the bitmask used by SWI or encodes the event type that triggered the post operation and can be used by the SWI function as a flag that identifies the event and serves to choose the routine to execute Software Interrupts Figure 4 7 Using SWI or to Post an SWI Mailbox Value returned by value SWI getmbox SWI object myswi Function myswiFxn ol ojo execution _ Calls 0 01 SWI or amp myswi 0 1 1 myswi is posted myswiFxn is executed 0 o fofa
157. he C5000 platform and 18 instructions on the C6000 platform Similarly an STS object uses only eight or four words of data memory on the C5000 or C6000 platforms respectively Data filtering formatting and computation of the average is done on the host You can control the polling rate for statistics information with the RTA Control Panel Property Page If you set the polling rate to 0 the host does not poll the target for information about the STS objects unless you right click on the Statistics View window and choose Refresh Window from the pop up menu Instrumentation 3 11 Instrumentation APIs 3 3 3 1 Statistics About Varying Values STS objects can be used to accumulate statistical information about a time series of 32 bit data values For example let P be the pitch detected by an algorithm on the ith frame of audio data An STS object can store summary information about the time series Pj The following code fragment includes the current pitch value in the series of values tracked by the STS object pitch do pitch detection STS add amp stsObj pitch The Statistics View displays the number of values in the series the maximum value the total of all values in the series and the average value 3 3 3 2 Statistics About Time Periods In any real time system there are important time periods Since a period is the difference between successive time values STS provides explicit support for these measurements Fo
158. he amount of code performed by an HWI function If the GIE bit is enabled a hardware interrupt can be preempted by any interrupt that is enabled by the IEMASK If an HWI function calls any of the PIP APIs PIP alloc PIP free PIP get PIP_put the pipe s notifyWriter or notifyReader functions run as part of the HWI context Note The interrupt keyword or INTERRUPT pragma must not be used when HWI objects are used in conjunction with C functions The HWI enter HWI exit macros and the HWI dispatcher contain this functionality and the use of the C modifier can cause catastrophic results 4 2 1 Configuring Interrupts with the Configuration Tool In the DSP BIOS configuration template the HWI Manager contains an HWI object for each hardware interrupt in your DSP Using the HWI Manager in the Configuration Tool you can configure the ISR for each hardware interrupt in the DSP Thread Scheduling 4 11 Hardware Interrupts You need to enter only the name of the ISR that is called in response to a hardware interrupt in the Property Page of the corresponding HWI object in the Configuration Tool DSP BIOS takes care of setting up the interrupt table so that each hardware interrupt is handled by the appropriate ISR The Configuration Tool also allows you to select the memory segment where the interrupt table is located The online help in the Configuration Tool describes HWI objects and their parameters See HWI Module in the
159. he class member function from within the wrapper Program Generation 2 25 Using with DSP BIOS A wrapper function for a class method is shown in Example 2 6 Example 2 6 Wrapper Function for a Class Method Void wrapper SampleClass myObject myObject method Any additional parameters that the class method requires can be passed to the wrapper function 2 7 4 Class Constructors and Destructors Any time that a class object is instantiated the class constructor executes Likewise any time that a class object is deleted the class destructor is called Therefore when writing constructors and destructors you should consider the times at which the functions are expected to execute and tailor them accordingly It is important to consider what type of thread will be running when the class constructor or destructor is invoked Various guidelines apply to which DSP BIOS API functions can be called from different DSP BIOS threads tasks software interrupts and hardware interrupts For example memory allocation APIs such as MEM alloc and MEM calloc cannot be called from within the context of a software interrupt Thus if a particular class is instantiated by a software interrupt its constructor must avoid performing memory allocation Similarly it is important to keep in mind the time at which a class destructor is expected to run Not only does a class destructor execute when an object is explicitly d
160. his occurs only if the DSP has enough free cycles to execute the IDL loop on a regular basis For the C55x and C6000 platforms RTDX is an interrupt driven interface as described for the LNK_dataPump object and there is no RTDX dataPump object 4 6 Semaphores Semaphores DSP BIOS provides a fundamental set of functions for intertask synchronization and communication based upon semaphores Semaphores are often used to coordinate access to a shared resource among a set of competing tasks The SEM module provides functions that manipulate semaphore objects accessed through handles of type SEM Handle SEM objects are counting semaphores that can be used for both task synchronization and mutual exclusion Counting semaphores keep an internal count of the number of corresponding resources available When count is greater than 0 tasks do not block when acquiring a semaphore The functions SEM create and SEM delete are used to create and delete semaphore objects respectively as shown in Example 4 7 You can also use the Configuration Tool to create semaphore objects See section 2 2 8 Creating Referencing and Deleting Dynamically Created DSP BIOS Objects page 2 10 for a discussion of the benefits of creating objects with the Configuration Tool Example 4 7 Creating and Deleting a Semaphore SEM Handle SEM create count attrs Uns count SEM Attrs attrs Void SEM delete sem SEM Handle sem The semapho
161. hitecture internal register structure data and program addressing the instruction pipeline and on chip peripherals Also includes development support information parts lists and design considerations for using the XDS510 emulator TMS320C54x DSP Enhanced Peripherals Ref Set Vol 5 literature number SPRU302 describes the enhanced peripherals available on the TMS320C54x digital signal processors Includes the multi channel buffered serial ports McBSPs direct memory access DMA controller interprocesor communications and the HPI 8 and HPI 16 host port interfaces TMS320C54x DSP Mnemonic Instruction Set Reference Set Volume 2 literature number SPRU172 describes the TMS320C54x digital signal processor mnemonic instructions individually Also includes a summary of instruction set classes and cycles TMS320C54x DSP Reference Set Volume 3 Algebraic Instruction Set literature number SPRU179 describes the TMS320C54x digital signal processor algebraic instructions individually Also includes a summary of instruction set classes and cycles TMS320C6000 Peripherals Reference Guide literature number SPRU190 describes common peripherals available on the TMS320C6000 family of digital signal processors This book includes information on the internal data and program memories the external memory interface EMIF the host port multichannel buffered serial ports direct memory access DMA clocking and phase locked loop PLL and the power
162. hore is posted by whichever device becomes ready first SIO select then calls Dxx ready again for each device this time with sem NULL This has two effects First any additional Dxx device that becomes ready will not post the ready semaphore This prevents devices from posting to a semaphore that no longer exists since the ready semaphore is maintained in the local memory of SIO select Second by polling each device a second time SIO select can determine which devices have become ready since the first call to Dxx ready and set the corresponding bits for those devices in the ready mask Streaming I O and Device Drivers 7 45 Types of Devices 7 17 Types of Devices There are two main types of devices terminating devices and stackable devices Each exports the same device functions but they implement them slightly differently A terminating device is any device that is a data source or sink A stackable device is any device that does not source or sink data but uses the DEV functions to send or receive data to or from another device Refer to Figure 7 12 to see how the stacking and terminating devices fit into a stream Figure 7 12 Stacking and Terminating Devices 7 46 SIO calls DEV calls Stackable Device Terminating Device Within the broad category of stackable devices there are two distinct types These are referred to as in place stacking devices and copying stacking devices The in place stacking
163. hould be sine L Streaming I O and Device Drivers 7 5 Creating and Deleting Streams If you open the stream with the streaming model attrs model set to SIO STANDARD the default buffers of the specified size are allocated and used to prime the stream If you open the stream with the streaming model set to SIO ISSUERECLAIM no stream buffers are allocated since the creator of the stream is expected to supply all necessary buffers SIO delete shown in Example 7 2 closes the associated device s and frees the stream object If the stream was opened using the SIO STANDARD streaming model it also frees all buffers remaining in the stream User held stream buffers must be explicitly freed by the user s code Example 7 2 Freeing User Held Stream Buffers 7 6 Int SIO_delete stream STO_Handle stream Stream and Writing Streams 7 3 Stream l O Reading and Writing Streams There are two models for streaming data in DSP BIOS the standard model and the Issue Reclaim model The standard model provides a simple method for using streams while the Issue Reclaim model provides more control over the stream operation SIO get and SIO put implement the standard stream model as shown in Example 7 3 SIO get is used to input the data buffers SIO get exchanges buffers with the stream The bufp parameter is used to pass the device a buffer and return a different buffer to the application SIO get
164. hreads to Use 4 4 The type and priority level you choose for each thread in an application program has an impact on whether the threads are scheduled on time and executed correctly The Configuration Tool makes it easy to change a thread from one type to another Here are some rules for deciding which type of object to use for each task to be performed by a program SWI TSK versus HWI Perform only critical processing within hardware interrupt service routines HWlIs can run at frequencies approaching 200 kHz Use software interrupts or tasks for events with deadlines around 100 microseconds or more Your HWI functions should post software interrupts or tasks to perform lower priority processing Using lower priority threads minimizes the length of time interrupts are disabled interrupt latency allowing other hardware interrupts to occur SWI versus TSK Use software interrupts if functions have relatively simple interdependencies and data sharing requirements Use tasks if the requirements are more complex While higher priority threads can preempt lower priority threads only tasks can be suspended to wait for another event such as resource availability Tasks also have more options than SWIs when using shared data All input needed by a software interrupt s function should be ready when the program posts the SWI The SWI object s mailbox structure provides a way to determine when resources are available SWIs are more memory
165. i bufC i bufD i bufA i SIO put outStreamA Ptr amp bufA npoints SIO put outStreamB Ptr amp bufB npoints Ptr amp bufC npoints Ptr amp bufD npoints SIO put outStreamC SIO put outStreamD Copying the data wastes CPU cycles and requires more memory since each stream needs buffers If you were double buffering Example 7 15 would require eight buffers two for each stream Example 7 16 illustrates the advantage of SIO issue and SIO reclaim in this situation The application performs no copying and it uses only two buffers In each call SIO issue simply enqueues the buffer pointed to by bufA onto outStream s todevice queue without blocking Since there is no copying or blocking this method greatly reduces the time between having a buffer of data ready for transmission and the time the buffer can be sent to all clients In order to remove the buffers from the output devices corresponding SIO reclaim functions must be called Streaming I O and Device Drivers 7 25 Streaming Data to Multiple Clients Example 7 16 Using SIO issue SIO reclaim to Send Data to Multiple Clients SIO issue outStreamA Ptr bufA npoints NULL SIO issue outStreamB Ptr bufA npoints NULL SIO issue outStreamC Ptr bufA npoints NULL SIO issue outStreamD Ptr bufA npoints NULL SIO reclaim outStreamA Ptr amp bufA NULL SIO recl
166. ially all boxes on the RTA Control Panel are checked by default Figure 3 8 RTA Control Panel Dialog Box RTA Control Panel enable Sw logging enable PRD logging enable CLK logging enable TSK logging enable SWI accumulators enable PRD accumulators enable PIP accumulators enable Hw accumulators enable TSK accumulators enable USERO trace enable USER trace global target enable global host enable L1 From the target code enable and disable trace bits using the TRC_enable and TRC_disable operations respectively For example the following C code disables tracing of log information for software interrupts and periodic functions TRC disable TRC LOGSWI TRC LOGPRD For example in an overnight run you might be looking for a specific circumstance When it occurs your program can perform the following statement to turn off all tracing so that the current instrumentation information is preserved disable GBLTARG Any changes made by the target program to the trace bits are reflected in the RTA Control Panel For example you could cause the target program to disable the tracing of information when an event occurs On the host you can simply wait for the global target enable check box to be cleared and then examine the log Instrumentation 3 17 Implicit DSP BIOS Instrumentation 3 4 Implicit DSP BIOS Instrumentation The instrumentation needed to allow the DSP BIOS Analysis Tools to display the Execution
167. ice 7 20 S siotest5 c In this program two tasks are created that exchange data through a pipe device The source task reads sine wave data from a DGN device through a DTR device stacked on the sine device and then writes it to a pipe device The sink task reads the data from the pipe device and writes it to the printData DGN device The data exchange between the tasks and the devices is done in a device independent fashion using the SIO module APIs The streams in this example follow the SIO STANDARD streaming model and are created with the Configuration Tool X E XXX HH ME include std h include dtr h include log h include mem h include sio h include lt sys h gt include tsk h define BUFSIZE 128 ifdef 62 define SegId IDRAM extern Int IDRAM MEM segment ID defined with conf tool endif ifdef 54 define SegId IDATA extern Int IDATA MEM segment ID defined with conf tool endif ifdef 55 define SegId DATA extern Int DATA MEM segment ID defined with conf tool endif extern LOG Obj trace LOG object created with conf tool extern TSK Obj sourceTask TSK thread objects created via conf tool extern TSK Obj sinkTask extern SIO Obj inStreamSrc SIO streams created via conf tool extern SIO Obj outStreamSrc extern SIO Obj inStreamSink extern SIO Obj outStreamSink Parameters for the stacking device s
168. icks and start of periodic functions off TRC LOGSWI Logs posting start and completion of software interrupt functions off TRC LOGTSK Logs events when a task is made ready starts becomes blocked resumes off execution and terminates This constant also logs semaphore posts TRC STSHWI Gathers statistics on monitored register values within HWIs off TRC STSPIP Counts the number of frames read from or written to data pipe off TRC STSPRD Gathers statistics on the number of ticks elapsed during execution of off periodic functions STSSWI Gathers statistics on number of instruction cycles or time elapsed from post off to completion of software interrupt Gather statistics on length of TSK execution from when a task is made TRC STSTSK ready to run until a call to TSK deltatime is made measured in timer off interrupt units or CLK ticks TRC USERO Enables or disables sets of explicit instrumentation actions You can use and TRC query to check the settings of these bits and either perform or omit off USER calls based on the result DSP BIOS does not use or set these bits Simultaneously starts or stops gathering all enabled types of tracing This bit must be set in order for any implicit instrumentation to be performed This TRO_GBLHOST can be important if you are trying to correlate events of different types This on bit is usually set at run time on the host with the RTA Control Panel TRC_GBLTARG Controls implicit instrumentat
169. ide for your platform The streams in Example 7 9 have also been added using the Configuration Tool The input stream for the sourceTask task is inStreamSrc and has been configured as shown in Figure 7 7 Figure 7 7 inStreamSrc Properties Dialog Box inStreamSrc Properties lt add comments i posses ma s Mace DUTETS I Memon seamen a BONEN aliahnietite Standard Timeout Appi Stackable Devices When you add an SIO stream in the Configuration Tool that uses a stacking device you must first enter a configured terminal device in the Device Control Parameter property box The name of the terminal device must be preceded by a slash character In the example we use sineWave where sineWave is the name of a configured DGN terminal device Then select the stacking device scale from the dropdown list in the Device property The Configuration Tool will not allow you to select a stacking device in Device until a terminal device has been entered in Device Control Parameter The other SIO streams created for Example 7 9 are outStreamSrc output stream for sourceTask inStreamSink input stream for sinkTask and outStreamSink output stream for sinkTask The devices used by these streams are the terminal devices pipO and printData Streaming I O and Device Drivers 7 19 Stackable Devices Example 7 9 Data Exchange Through a Pipe Dev
170. iguration Tool lt prog gt cfg h54 configuration assembly header fil generated by Configuration Tool lt prog gt cfg cmd configuration linker command file generated by Configuration Tool include DIR c5400 bios include c54rules mak Compiler assembler and linker options g enable symbolic debugging CC540PTS g AS54OPTS q quiet run LD540PTS q Every BIOS program must be linked with PROG cfg 054 object resulting from assembling PROG cfg s54 PROG cfg cmd linker command file generated by the Configuration Tool If additional linker command files exist S PROG cfg cmd must appear first PROG volume OBJS 5 PROG cfg obj load obj LIBS CMDS PROG cfg cmd Targets all PROG out PROG out 0875 CMDS PROG cfg obj S PROG cfg h54 PROG 0bj S PROG cfg s54 S PROG cfg h54 PROG cfg cmd echo Error 80 must be manually regenerated echo Open and save PROG cdb within the BIOS Configuration Tool check SQ Clean clean echo removing generated configuration files remove f PROG cfg s54 S PROG cfg h54 S PROG cfg cmd echo removing object files and binaries remove f obj out lst map Program Generation 2 17 Using DSP BIOS with the Run Time Support Library 2 5 Using DSP BIOS with the Run Time Support Library The linker command file generated by the Configuration Tool automatically includes directi
171. indicates the number of semaphores present in the currently operating system The number of lines of information in the main information field is equal to the value in this field 2 Name Handle This is the semaphore name and handle The name is taken from the label for statically configured objects and is generated for dynamically created objects The label matches the name in the SEM Manager configuration The handle is the address on the target Count This is the current semaphore count This is the number of pends that can occur before blocking Tasks Pending This is the current number of tasks pending on the semaphore If the value is non zero you can click on the number to see a list of tasks that are pending as shown in Figure 3 21 Instrumentation 3 33 Kernel Object View Debugger Figure 3 21 Viewing a List of Tasks Pending DSP BIOS gt Kernel Object View KNL TSK MBX SEM swi i 3 Semaphore s semQ 0x80000650 sem 0x80000678 sem2 Ox80000B40 3 5 5 Memory The memory page select the tab labeled MEM shows all memory heap information as illustrated in Figure 3 22 Figure 3 22 The Memory Page Dialog Box Kernel Object View KNL TSK MBX SEM MEM swi 1 Heap s IDRAM 8 Ox7EFS8 0400008000 0 80004000 O S0DOBFFF 0 108 0 0 The memory page fields and other information are as follows Heap s The value in this field indicates the number of hea
172. information on task suspend see Figure 4 10 The Property window for a TSK object shows its numeric priority level from 0 to 15 15 is the highest level You can also set the priority by selecting the priority level from the menu in the Property window as shown in Figure 4 10 Thread Scheduling 4 37 Tasks Figure 4 10 TSK Properties Dialog Box TSKO Properties x General Function Advanced comment add comments here Automatically allocate stack Manually allocated stack ut Stack size MAUs fics Stack Memory Segment SDRAM Priority hoo H Cancel Apply Help 4 4 2 Task Execution States and Scheduling Each TSK task object is always in one of four possible states of execution 1 Running which means the task is the one actually executing on the system s processor 2 Ready which means the task is scheduled for execution subject to processor availability 3 Blocked which means the task cannot execute until a particular event occurs within the system or 4 Terminated which means the task is terminated and does not execute again Tasks are scheduled for execution according to a priority level assigned to the application There can be no more than one running task As a rule no ready task has a priority level greater than that of the currently running task since TSK preempts the running task in favor of the higher priority ready task Figure 4 11 TSK delete task is deleted
173. ion This bit must also be set in order for any implicit on instrumentation to be performed and can only be set by the target program Note Updating Task Statistics If TSK deltatime is not called by a task its statistics will never be updated in the Statistics View even if TSK accumulators are enabled in the RTA Control Panel TSK statistics are handled differently than other statistics because TSK functions typically run an infinite loop that blocks while waiting for other threads In contrast HWI and SWI functions run to completion without blocking Because of this difference DSP BIOS allows programs to identify the beginning of a TSK function s processing loop by calling TSK settime and the end of the loop by calling TSK deltatime Instrumentation APIs You can enable and disable these trace bits in the following ways From the host use the RTA Control Panel as shown in Figure 3 8 This panel allows you to adjust the balance between information gathering and time intrusion at run time By disabling various implicit instrumenta tion types you lose information but reduce the overhead of processing You can control the refresh rate for trace state information by right clicking on the Property Page of the RTA Control Panel If you set the refresh rate to 0 the host does not poll the target for trace state information unless you right click on the RTA Control Panel and choose Refresh Window from the pop up menu Init
174. ion state This ensures that the processor is always given to the highest priority thread that is ready to run There are 15 priority levels available for tasks The lowest priority level 0 is reserved for running the idle loop The TSK module provides a set of functions that manipulate task objects They access TSK object through handles of type TSK Handle The kernel maintains a copy of the processor registers for each task object Each task has its own run time stack for storing local variables as well as for further nesting of function calls Stack size can be specified separately for each TSK object Each stack must be large enough to handle normal subroutine calls as well as a single task preemption context A task preemption context is the context that gets saved when one task preempts another as a result of an interrupt thread readying a higher priority task If the task blocks only those registers that a C function must save are saved to the task stack To find the correct stack size you can make the stack size large and then use Code Composer Studio software to find the stack size actually used All tasks executing within a single program share a common set of global variables accessed according to the standard rules of scope defined for C functions 4 4 1 Creating Tasks You can create TSK objects either dynamically with a call to TSK create or statically with the Configuration Tool Tasks that you create dynamically can a
175. ion with SYS exit or SYS abort Void SYS exit status Int status Void SYS abort format arg String format Arg arg The functions in Example 5 9 terminate execution by calling whatever routine is specified for the Exit function and Abort function properties of the SYS module The default exit function is UTL halt The default abort function is UTL doAbort which logs an error message and calls halt The halt function is defined in the boot c file it loops infinitely with all processor interrupts disabled SYS abort accepts a format string plus an optional set of data values presumably representing a diagnostic message which it passes to the function specified for the Abort function property of the SYS module as shown in Example 5 10 Memory and Low level Functions 5 11 System Services Example 5 10 Using SYS abort with Optional Data Values Example 5 11 Abort function format vargs The single vargs parameter is of type va list and represents the sequence of arg parameters originally passed to SYS abort The function specified for the Abort function property can pass the format and vargs parameters directly to SYS vprintf or SYS vsprintf prior to terminating program execution To avoid the large code overhead of SYS vprintf or SYS vsprintf you can use LOG error instead to simply print the format string SYS exit likewise calls whatever function is bound to the Exit function property passing on its original
176. irst referenced within the rtsbios the run time support library This linker error is avoided by using the x linker option which forces libraries to be searched again in order to resolve undefined references See section 2 5 Using DSP BIOS with the Run Time Support Library for more information 2 7 2 Name Mangling The compiler implements function overloading operator overloading and type safe linking by encoding a function s signature in its link level name The process of encoding the signature into the linkname is referred to as name mangling Name mangling could potentially interfere with a DSP BIOS application since you use function names within the Configuration Tool to refer to functions declared in your C source files To prevent name mangling and thus to make your functions recognizable within the Configuration Tool it is necessary to declare your functions in an extern C block as shown in the code fragment of Example 2 4 Using with DSP BIOS Example 2 4 Declaring Functions in an Extern C Block extern C Void functionl Int function2 This allows you to refer to the functions within the Configuration Tool preceded by an underscore as with other C function names For example if you had an SWI object which should run function1 every time that the SWI posts you would enter function into the function property of that SWI object Functions declared within the extern C block are not s
177. istribution siotest2 c siotest2 cdb dgn print c For more details on how to add and configure a DGN device using the Configuration Tool see the DGN section in the 7MS320 DSP BIOS API Reference Guide for your platform In the output for this example sine wave data appears in the myLog window display Figure 7 5 Results Window for Example 7 6 Log Name 0 1 2 3 4 127 5 8 7 3 4 Example Stream I O using the Issue Reclaim Model Example 7 7 is functionally equivalent to Example 7 6 However the streams are now created using the Issue Reclaim model and the SIO operations to read and write data to a stream are SIO issue and SIO reclaim In this model when streams are created dynamically no buffers are initially allocated so the application must allocate the necessary buffers and provide them to the streams to be used for data I O For static streams you can allocate static buffers with the Configuration Tool by checking the Allocate Static Buffer s check box for the SIO object Stream and Writing Streams Example 7 7 Using the Issue Reclaim Model Ptr Arg Int Prime the stream with a couple of buffers buf MEM 11 1 SIO bufsize input 0 buf MEM ILLEGAL SYS abort Memory allocation error if Issue an empty buffer to the input stream SIO issue input buf SIO bufsize input NULL O SYS abort Er
178. it runs with minimal impact on the application s real time performance The DSP BIOS Analysis Tools are found on their own menu as shown in Figure 1 3 Figure 1 3 The DSP BIOS Menu 1 8 Studio Help 86 CPU Load Graph Execution Graph Host Channel Control Message Log Statistics View RT Control Panel Kermel Object View Unlike traditional debugging which is external to the executing program program analysis requires the target program contain real time instrumentation services By using DSP BIOS APIs and objects developers automatically instrument the target for capturing and uploading real time information to the host through the Code Composer Studio DSP BIOS Analysis Tools Several broad real time program analysis capabilities are provided Program tracing Displaying events written to target logs reflecting dynamic control flow during program execution Performance monitoring Tracking summary statistics that reflect use of target resources such as processor load and timing File streaming Binding target resident I O objects to host files DSP BIOS Components When used in tandem with the other debugging capabilities of Code Composer Studio the DSP BIOS real time Analysis Tools provide critical views into target program behavior during program execution where traditional debugging techniques that stop the target offer little insight Even after the debugger halts the program information already ca
179. ity 0 Reserved when TSK is enabled W KNL_swi PEBEEEPEE P F P P F P P m Software Interrupts 2 change the priority of a SWI object drag the software interrupt to the folder of the corresponding priority For example to change the priority of SWIO to 3 select it with the mouse and drag it to the folder labeled Priority 3 Software interrupts can have up to 15 priority levels The highest level is SWI MAXPRI 14 The lowest is SWI MINPRI 0 The priority level of 0 is reserved for the KNL_swi object which runs the task scheduler See section 4 3 3 Software Interrupt Priorities and Application Stack Size page 4 23 for stack size restrictions You cannot sort software interrupts within a single priority level The Property window for an SWI object shows its numeric priority level from 0 to 14 14 is the highest level You can also set the priority by selecting the priority level from the menu in the Property window as shown in Figure 4 4 Figure 4 4 SWI Properties Dialog Box General comment kadd comments here gt function FXN_F_nop priority mailbox 0 argl 4 3 3 Software Interrupt Priorities and Application Stack Size All threads in DSP BIOS excluding tasks are executed using the same System stack The system stack stores the register context when a software interrupt preempts another thread To allow the maximum number of preemptions that can occur at run time th
180. ives PRD functions ticks at the same rate as the low resolution clock The low resolution and system time coincide Based on I O availability or some other event Remove the check mark from the Use the CLK Manager to Drive PRD box for the PRD Manager Your program should call PRD tick to increment the system clock In this case the resolution of the system clock equals the frequency of the interrupt from which PRD tick is called Periodic Function Manager PRD and the System Clock 4 9 1 Invoking Functions for PRD Objects When PRD tick is called two things can occur d D tick the system clock counter increases by one that is the system clock ticks Q An SWI called PRD swi is posted if the number of ticks that have elapsed is equal to a value that is the greatest power of two among the common denominators of the PRD function periods For example if the periods of three PRD objects are 12 24 and 36 PRD swi runs every four ticks It does not simply run every 12 or 6 ticks because those intervals are not powers of two When a PRD object is created with the Configuration Tool a new SWI object is automatically added called PRD_swi When PRD swi runs its function executes the following type of loop for Loop through period objects if time for a periodic function run that periodic function Hence the execution of periodic functions is deferred to the context of PRD swi rather than b
181. j streamTask SIO Handle input amp inputStream SIO Handle output amp outputStream Void doStreaming Uns nloops Void doStreaming Arg nloops arg Int i nbytes Int b f Long nloops Long nloops arg if SIO staticbuf input Ptr amp buf 0 SYS abort Error reading buffer for i 0 i lt nloops i if nbytes SIO_get input Ptr amp buf lt 0 SYS_abort Error reading buffer d Arg i if SIO_put output Ptr amp buf nbytes lt 0 SYS_abort Error writing buffer d Arg i LOG_printf amp trace End SIO example 2 DGN_print2log User function for the DGN user device printData It takes as an argument the address of the LOG object where the data stream should be printed Void DGN print2log Arg arg Ptr addr Uns nbytes Int d Int buf buf Int addr for i 0 i nbytes sizeof Int 1 LOG printf LOG Obj arg d buf i Cr Note Non pointer type function arguments to log printf need explicit type casting to Arg as shown in the following code example LOG printf amp trace Task d Done Arg id l Streaming I O and Device Drivers 7 13 Stream and Writing Streams The complete source code and configuration template for Example 7 6 can be found in the c ti tutorial target siotest directory of the DSP BIOS product d
182. k on an error to see the details 4 72 Using the Execution Graph to View Program Execution 4 10 2 Threads in the Execution Graph Window The SWI and PRD functions listed in the left column are listed from highest to lowest priority However for performance reasons there is no information in the Execution Graph about hardware interrupt and background threads aside from the CLK ticks which are normally performed by an interrupt Time not spent within an SWI PRD or TSK thread must be within an HWI or IDL thread so this time is shown in the Other Threads row Functions run by PIP notify functions run as part of the thread that called the PIP API The LNK dataPump object runs a function that manages the host s end of an HST Host Channel Manager object This object and other IDL objects run from the IDL background thread and are included in the Other Threads row Note The Time marks and the PRD Ticks are not equally spaced This graph shows a square for each event If many events occur between two Time interrupts or PRD Ticks the distance between the marks is wider than for intervals during which fewer events occurred 4 10 3 Sequence Numbers in the Execution Graph Window The tick marks above the bottom scroll bar in Figure 4 20 show the sequence of events in the Execution Graph Note Circular logs the default for the Execution Graph contain only the most recent n events Normally there are events that a
183. le 3 1 uses as samples two example projects that are shipped with Code Composer Studio software which utilize many of the DSP BIOS features By including DSP BIOS modules the example applications incorporate the instrumentation code Therefore the following numbers are representative of the amount of code size incurred by the instrumentation and are not affected by the size or variations among users applications The first example Slice contains the TSK SEM and PRD modules while the second example Echo uses the PRD and SWI modules Neither example application is specifically designed for minimizing code size For information on DSP BIOS kernel performance benchmarks including a comparison of the instrumented versus non instrumented kernels performances see Application Report SPRA662 DSP BIOS Timing Benchmarks on the TMS320C6000 DSP Instrumentation Performance Table 3 1 Examples of Code size Increases Due to an Instrumented Kernel a Example Slice C54x Platform C55x Platform C6000 Platform Description all sizes in MADUS J Size with non instrumented kernel 12 500 32 000 78 900 Size with instrumented kernel 14 350 33 800 86 600 Size increase with instrumented kernel 1 850 1 800 7 700 b Example Echo C54x Platform C55x Platform C6000 Platform Description all sizes in MADUs J Size with non instrumented kernel 11 600 41 200 68 800 Size with instrumented kernel 13 000 42 800 76 200 Size increase with i
184. lity to dynamically allocate and free memory If you remove this capability your program cannot call any of the MEM functions or any object creation functions such as TSK create You should create all objects that are used by your program with the Configuration Tool To remove the dynamic memory allocation capability put a checkmark in the No Dynamic Memory Heaps box in the Properties dialog for the MEM Manager If dynamic memory allocation is disabled and your program calls a MEM function or indirectly calls a MEM function by calling an object creation function an error occurs If the segid passed to the MEM function is the name of a segment a link error occurs If the segid passed to the MEM function is an integer the MEM function will call SYS error 5 1 3 Defining Segments in Your Own Linker Command File The MEM Manager allows you to select which memory segment contains various types of code and data If you want more control over where these items are stored put a checkmark in the User cmd file for non DSP BIOS segments box in the Properties dialog for the MEM Manager Memory and Low level Functions 5 3 Memory Management You should then create your own linker command file that begins by including the linker command file created by the Configuration Tool For example your own linker command file might look like one of those shown in Example 5 1 or Example 5 2 Example 5 1 First include DSP BIOS generated cmd fil
185. ll DSP BIOS objects created by the Configuration Tool lt program gt cfg h This file can be included by the application s source files to accomplish the DSP BIOS object declarations DSP BIOS for the C54x platform was originally developed for the 16 bit addressing model of the early C54x devices Newer C54x devices incorporate far extended addressing modes and DSP BIOS has been modified to work in this environment See the Application Report DSP BIOS and TMS320C54x Extended Addressing SPRA599 for more information 1 3 5 Memory Segment Names The memory segment names used by DSP BIOS are described in Table 1 3 Table 1 3 Memory Segment Names a C54x Platform Segment Description Internal on device data memory EDATA Primary block of external data memory EDATA1 Secondary block of external data memory not contigu ous with EDATA IPROG Internal on device program memory EPROG Primary block of external program memory Secondary block of external program memory tiguous with EPROG USERREGS Page 0 user memory 28 words BIOSREGS Page 0 reserved registers 4 words VECT Interrupt vector segment Naming Conventions Table 1 3 Memory Segment Names continued b C55x Platform Cr Segment Description IDATA Primary block of data memory Secondary block of data memory not contiguous with DATA1 DATA PROG Program memory VECT DSP Interrupt Vector Table memory segment
186. llocates and frees memory from different memory segments 37 include std h include lt log h gt include lt mem h gt define NALLOCS 2 of allocations from each segment define BUFSIZE 128 size of allocations trace Log created by Configuration Tool extern LOG Obj trace extern Int IDRAM static Void printmem Int segid Void main Int i Ptr ram NALLOCS LOG_printf amp trace before allocating print initial memory status printmem LOG printf amp trace allocating allocate some memory from each segment for 1 0 i NALLOCS 1 ram i MEM alloc BUFSIZE 0 LOG printf amp trace seg d ptr Ox x ram il LOG printf amp trace after allocating print memory status printmem free memory for i 0 i lt NALLOCS itt MEM_free ram i BUFSIZE LOG printf amp trace after freeing print memory status printmem printmem static Void printmem Int segid MEM Stat statbuf MEM stat segid amp statbuf LOG printf amp trace seg d O Ox x segid statbuf size LOG printf amp trace tU Ox xNtA Ox x statbuf used stat buf length Memory Low level Functions 5 9 Memory Management Figure 5 2 Memory Allocation Trace Window Log Name trace before allocating seg 0 0x400 054 Ox3fc allocating seg 0 ptr 01090 seg 0
187. lso be deleted during program execution Tasks 4 4 1 1 Creating and Deleting Tasks Dynamically You can spawn DSP BIOS tasks by calling the function TSK create whose parameters include the address of a C function in which the new task begins its execution The value returned by TSK create is a handle of type TSK Handle which you can then pass as an argument to other TSK functions TSK Handle TSK create fxn attrs arg Fxn fxn TSK AtLr amp attrs Arg arg A task becomes active when it is created and preempts the currently running task if it has a higher priority The memory used by TSK objects and stacks can be reclaimed by calling TSK delete TSK delete removes the task from all internal queues and frees the task object and stack by calling MEM free Any semaphores mailboxes or other resources held by the task are not released Deleting a task that holds such resources is often an application design error although not necessarily so In most cases such resources should be released prior to deleting the task Void TSK delete task TSK Handle task Note Catastrophic failure can occur if you delete a task that owns resources that are needed by other tasks in the system See TSK delete in the TMS320 DSP BIOS Reference Guide for your platform for details L Thread Scheduling 4 35 Tasks 4 4 1 2 Creating Tasks with the Configuration Tool You can also create tasks using the Configuration Tool
188. lso contains the definition of the CSL_xxxx macro where xxxx is the Chip Type property of the Global Settings module programcf c c File containing program code for CSL settings generated automatically when a configuration file is saved It includes the programcfg h file 2 3 1 Files Used by the DSP BIOS Analysis Tools The following files are used by the DSP BIOS Analysis Tools d d program cdb The configuration file provides object names and other program information program out The executable file provides symbol addresses and other program information Program Generation 2 13 Compiling and Linking Programs 2 4 Compiling and Linking Programs 2 4 1 You can build your DSP BIOS executables using a Code Composer Studio project or using your own makefile The Code Composer Studio software includes gmake exe the GNU make utility and sample makefiles for gmake to build the tutorial examples Building With a Code Composer Studio Project When building a DSP BIOS application using a Code Composer Studio project you must add the following files to the project in addition to your own source code files program cdb The configuration file programcfg cmd The linker command file Code Composer Studio software adds programcfg s54 automatically In a DSP BIOS application programcfg cmd is your project s linker command file This file already includes directives for the linker to use the appropriate libr
189. match Recall that SIO create takes the parameters and is called as shown in Example 7 26 Example 7 26 The Parameters of SIO create stream SIO create name mode bufsize attrs The name parameter passed to SIO create is typically a string indicating the device and an additional suffix indicating some particular mode of operation of the device An analog to digital converter might have the base name adc while the sampling frequency might be indicated by a tag such as 16 for 16 kHz The complete name passed to SIO create would be adc16 SIO create identifies the device by using DEV match to match the string adc against the list of configured devices The string remainder 16 would be passed to Dxx open to set the ADC to the correct sampling frequency Dxx_open usually allocates a device specific object that is used to maintain the device state as well as necessary semaphores For a terminating device this object typically has two SEM Handle semaphore handles One is used for synchronizing I O operations for example SIO get SIO put SIO reclaim The other handle is used with SIO select to determine if a device is ready A device object would typically be defined as shown in Example 7 27 Example 7 27 The Dxx Obj Structure typedef struct Dxx Obj SEM Handle Sync synchronize I O SEM Handle ready used with SIO select other device specific fields Dxx obj Dxx Handle
190. mation Table 1 4 Standard Memory Segments continued c C6000 Platform exit Sections Segment System stack memory stack IDRAM Application constants memory const IDRAM Program memory text IPRAM Data memory data IDRAM Startup code memory sysinit IPRAM C initialization records memory cinit IDRAM Uninitialized variables memory bss IDRAM You can change these default allocations by using the MEM Manager in the Configuration Tool For more detail see MEM Module in the TMS320 DSP BIOS API Reference Guide for your platform 1 4 For More Information For more information about the components of DSP BIOS and the modules in the DSP BIOS API see the DSP BIOS section of the online help system the TMS320 DSP BIOS API Reference Guide for your platform or the Using DSP BIOS lessons in the online Code Composer Studio Tutorial About DSP BIOS 1 17 Chapter 2 Program Generation This chapter describes the process of generating programs with DSP BIOS It also explains which files are generated by DSP BIOS components and how they are used Topic Page 21 Development Cycle 2 2 2 2 Using the Configuration 2 3 2 3 Files Used to Create DSP BIOS 2 1 2 4 Compiling and Linking 2 14 2 5 Using DSP BIOS with the Run Time Support Library 2 18 2 6 DSP BIOS Startup Sequence
191. mbol references the top of the stack Instrumentation 3 23 Implicit DSP BIOS Instrumentation 3 Run your program and view the STS object that monitors the stack pointer for this HWI function in the Statistics View window 4 Subtract the minimum value of the stack pointer maximum field in the STS object from the end of the system stack to find the maximum depth of the stack The Kernel Object View displays stack information for all targets See section 3 5 Kernel Object View Debugger Figure 3 13 Calculating Used Stack Depth Low Address gt GBL_stackbeg free SP L Used Stack Configured Stack GBL_stackend High Address used stack depth GBL_stackend min SP STS add addr min SP 3 4 4 Monitoring Variables In addition to counting hardware interrupt occurrences and monitoring the stack pointer you can monitor any register or data value each time a hardware interrupt is triggered This implicit instrumentation can be enabled for any HWI object Such monitoring is not enabled by default The performance of your interrupt processing is not affected unless you enable this type of instrumentation in the Configuration Tool The statistics object is updated each time hardware interrupt processing begins Updating such a statistics object consumes between 20 and 30 instructions per interrupt for each interrupt monitored Implicit DSP BIOS Instrumentation To enable
192. module and choose Properties from the pop up menu This opens the property dialog Change properties as needed For help on the module s properties click Help in the property dialog 2 2 4 Creating Objects Using the Configuration Tool 2 4 Most objects can be created either statically using the Configuration Tool or dynamically by calling the function XXX create This section describes objects created using the Configuration Tool To create objects dynamically see section 2 2 8 Creating Referencing and Deleting Dynamically Created DSP BIOS Objects page 2 10 For typical DSP applications most objects should be created with the Configuration Tool because they are used throughout program execution A number of default objects are automatically defined in the configuration template Creating objects with the Configuration Tool provides the following benefits Improved access within DSP BIOS Analysis Tools The Execution Graph shows the names of objects created with the Configuration Tool In addition you can view statistics only for objects created with the Configuration Tool Reduced code size For a typical module the XXX create and XXX delete functions contain 50 of the code required to implement the module If you avoid using any calls to TSK create and TSK delete the underlying code for these functions is not included in the application program The same is true for other modules By creating objects with the Configuratio
193. n Tool you can dramatically reduce the size of your application program Using the Configuration Tool Note SYS printf is probably the most memory intensive function in DSP BIOS Use the LOG functions instead of SYS printf to make your application smaller Improved run time performance In addition to saving code space avoiding dynamic creation of objects reduces the time your program spends performing system setup Creating objects with the Configuration Tool has the following limitations Objects are created whether or not they are needed You can create objects dynamically if they will be used only as a result of infrequent run time events 1 You cannot delete objects created with the Configuration Tool at run time using the XXX delete functions Note No checks are performed to prevent an XXX delete function from being used on an object created with the Configuration Tool If a program attempts to delete an object that was not created dynamically SYS error is called Follow these steps to create an object using the Configuration Tool 1 Right click on a module and choose Insert XXX where XXX is the name of the module This adds a new object for the module You cannot create an object for the GBL HWI or SYS modules 2 Rename the object Right click on the name and choose Rename from the pop up menu 3 Right click the icon next to the object and choose Properties to open the prope
194. n and this section is assumed to be at most 32K bytes in length Global data therefore can be accessed with a single instruction like the following LDW DP _x A0 load _x into A0 DP B14 Using the Configuration Tool Since objects created with the Configuration Tool are not placed in the bss section you must ensure that application code compiled with the small model references them correctly There are three ways to do this 2 Declare static objects with the far keyword The DSP BIOS compiler supports this common extension to the C language The far keyword in a data declaration indicates that the data is not in the bss section For example to reference a PIP object called inputObj that was created with the Configuration Tool declare the object as follows extern far PIP Obj inputObj if PIP getReaderNumFrames amp inputObj T Create and initialize a global object pointer You can create a global variable that is initialized to the address of the object you want to reference All references to the object must be made using this pointer to avoid the need for the far keyword For example extern PIP Obj inputObj PIP Obj input GinputObj input MUST be a global variable if PIP getReaderNumFrames input Declaring and initializing the global pointer consumes an additional word of data to hold the 32 bit address of the object Also if the pointer is a static or automatic variable this techniq
195. n be managed by a user This model is preemptive and does uire any cooperation which is code by the tasks The tasks are programmed as if they were the only thread running Although DSP BIOS tasks of differing priorities can exist in any given application the time slicing model only applies to tasks of equal priority Figure 4 12 shows the trace window resulting from Example 4 6 while Figure 4 13 shows the execution Example 4 6 Time Slice Scheduling D FF FF FF FF FF Uns incl incl incl incl incl incl incl incl slice c This example utilizes time slice scheduling among three tasks of equal priority A fourth task of higher priority periodically preempts execution A PRD object drives the time slice scheduling Every millisecond the PRD object calls TSK yield which forces the current task to relinquish access to to the CPU The time slicing could also be driven by a CLK object as long as the time slice was the same interval as the clock interrupt or by another hardware interrupt The time slice scheduling is best viewed in the Execution Graph with SWI logging and PRD logging turned off Because a task is always ready to run this program does not spend time in the idle loop Calls to IDL run are added to force the update of the Real Time Analysis tools Calls to IDL run are within a TSK disable TSK ena
196. n must wait for all others to finish executing before it is called again The idle loop runs continuously except when it is preempted by higher priority threads Only functions that do not have hard deadlines should be executed in the idle loop See section 4 5 The Idle Loop page 4 47 for details about the background thread There are several other kinds of functions that can be performed in a DSP BIOS program These are performed within the context of one of the thread types in the previous list 2 Clock CLK functions Triggered at the rate of the on device timer interrupt By default these functions are triggered by a hardware interrupt and are performed as HWI functions See section 4 8 Timers Interrupts and the System Clock page 4 61 for details 2 Periodic PRD functions Performed based on a multiple of either the on device timer interrupt or some other occurrence Periodic functions are a special type of software interrupt See section 4 9 Periodic Function Manager PRD and the System Clock page 4 68 for details m Data notification functions Performed when you use pipes PIP or host channels HST to transfer data The functions are triggered when a frame of data is read or written to notify the writer or reader These functions are performed as part of the context of the function that called PIP alloc PIP get PIP free or PIP put Thread Scheduling 4 3 Overview of Thread Scheduling 4 1 2 Choosing Which Types of T
197. nbytes if SIO staticbuf input amp buf 0 In the output for Example 7 9 scaled sine wave data appears in the myLog window display in Example 7 8 Streaming I O and Device Drivers 7 21 Stackable Devices Figure 7 8 Sine Wave Output for Example 7 9 You can edit sioTestb c and change the scaling factor of the PRMS rebuild the executable and see the differences in the output to myLog A version of Example 7 9 where the streams are created dynamically at runtime by calling SIO create is available in the product distribution siotest4 c siotest4 cdb Controlling Streams 7 5 Controlling Streams A physical device typically requires one or more specialized control signals in order to operate as desired SIO ctrl makes it possible to communicate with the device passing it commands and arguments Since each device admits only specialized commands you need to consult the documentation for each particular device The general calling format is shown in Example 7 10 Example 7 10 Using SIO ctrl to Communicate with a Device Int SIO ctrl stream cmd arg SIO Handle stream Uns Ptr arg The device associated with stream is passed the command represented by the device specific cmd A generic pointer to the command s arguments is also passed to the device The actual control function that is part of the device driver then interprets the command and arguments and acts accordingly Assum
198. nctions The actual ISR function runs in a very short time Within the idle loop the LNK dataPump function does the more time consuming work of preparing the RTDX buffers and performing the RTDX calls Only the actual data transfer is done at high priority This data transfer can have a small effect on real time behavior particularly if a large amount of LOG data must be transferred 6 5 Performance Issues If you are using an HST object the host PC reads or writes data using the function specified by the LNK dataPump object This is a built in IDL object that runs its function as part of the background thread Since background threads have the lowest priority software interrupts and hardware interrupts can preempt data transfer on the C54x platform whereas on the C55x and C6000 platforms the actual data transfer occurs at high priority The polling rates you set in the LOG STS and TRC controls do not control the data transfer rate for HST objects Faster polling rates actually slow the data transfer rate somewhat because LOG STS and TRC data also need to be transferred Chapter 7 Streaming I O and Device Drivers This chapter describes issues relating to writing and using device drivers and gives several programming examples Topic Page 7 1 Overview of Streaming I O and Device Drivers 7 2 7 2 Creating and Deleting Streams 7 3 Stream l O Reading and Writing Streams
199. ndent RETA CFCT used for fast XX00 XXXX 24 bit vector address gt return functionality SP SSP independent e BETA CFCT not used XX01 XXXX 24 bit vector address gt SP SSP synchronized BETA CFCT not used XX02 XXXX 24 bit vector address gt Program Generation 2 23 Using with DSP BIOS 2 7 Using C with DSP BIOS DSP BIOS applications can be written in An understanding of issues regarding C and DSP BIOS can help to make C application development proceed smoothly These issues concern memory management name mangling calling class methods from the Configuration Tool and special considerations for class constructors and destructors 2 7 1 Memory Management The functions new and delete are the C operators for dynamic memory allocation and deallocation Within DSP BIOS applications these operators are reentrant because they are implemented with the DSP BIOS memory management functions MEM alloc and MEM free However memory management functions require that the calling thread obtain a lock to memory before proceeding if the requested lock is already held by another thread blocking results Therefore new and delete should be used by TSK objects only The functions new and delete are defined by the run time support library not the DSP BIOS library Since the DSP BIOS library is searched first some applications can result in a linker error stating that there are undefined symbols that were f
200. nerates code required to declare objects used within the program Q Configuration Tool detects errors earlier by validation properties before the program is even built Logging and statistics for DSP BIOS objects are available at run time without additional programming Additional instrumentation can be programmed as needed Q The DSP BIOS Analysis Tools allow real time monitoring of program behavior DSP BIOS provides a standard API This allows DSP algorithm developers to provide code that can be more easily integrated with other program functions 21 DSP BIOS is integrated within the Code Composer Studio IDE requires no runtime license fees and is fully supported by Texas Instruments DSP BIOS is key a component of Tl s eXpressDSP real time software technology The Chip Support Library CSL provides an easier method of device programming than traditional register programming When you use CSL APIs portability between different DSP platforms with equivalent peripheral devices is simpler and more efficient About DSP BIOS 1 3 DSP BIOS Components 1 2 DSP BIOS Components Figure 1 1 shows the components of DSP BIOS within the program generation and debugging environment of Code Composer Studio Figure 1 1 DSP BIOS Components Target Configuration Tool source files
201. ng device Dxx ready memory management multiple streams 7 24 SIO select system clock 4 66 task hooks for extra context virtual I O devices Excel Microsoft 3 37 executable files 2 13 Execution Graph 2 4 3 7 3 18 execution mode blocked priority leve terminated TSK BLOC TSK READY TSK RUNNIN TSK TERMINAT execution times explicit instrumentation FALSE ar f keyword far extended addressing fast return 2 23 field testing 3 37 file names file streaming 1 8 Index files generated by Configuration Tool 2 12 used by DSP BIOS Analysis Tools 2 13 fragmentation of memory minimizing 5 6 free frequencies typical for HWI vs SWI function names 1 12 2 24 generated files global data 2 8 accessing 2 8 global object pointer 2 9 global properties gmake gmake exe H halting program execution SYS abort SYS exit handle hardware interrupt and SEM post or SEM ipost hardware interrupts counting 4 49 statistics typical frequencies header files 2 13 including 1 11 naming conventions 1 11 host operation 3 27 HST module for instrumentation HST init HWI dispatching parameters _ 4 15 writing Index 3 Index HWI accumulations enable Bad HWI dispatc HWI interrupt triggering HWI interrupts See hardware interrupts HWI ISR and mailboxes HWI module implicit instrumentation HWI disable 4 12 HWI enable 4 12 HWI enter H
202. nment registers before calling any C or DSP BIOS functions HWI exit should be used to restore these registers In addition to saving and restoring the C run time environment registers HWI enter and HWI exit make sure the DSP BIOS scheduler is called only by the outermost interrupt routine if nested interrupts occur If the HWI or another nested HWI triggers an SWI handler with SWI post or readies a higher priority task for example by calling SEM ipost or TSK itick the outermost HWI exit invokes the SWI and TSK schedulers The SWI scheduler services all pending SWI handlers before performing a context switch to a higher priority task if necessary See Functions Callable by Tasks SWI Handlers or Hardware ISHs in the TMS320 DSP BIOS API Reference Guide for your platform for a complete list of functions that can be called by an ISR Thread Scheduling 4 17 Hardware Interrupts Note HWI enter and HWI exit must surround all statements in any DSP BIOS assembly or C language HWIs that reference DSP BIOS functions Using the HWI dispatcher satisfies this requirement Example 4 2 provides assembly language code for constructing a minimal HWI on the C6000 platform when the user has selected not to use the HWI dispatcher Example 4 3 provides a code example on the C54x platform and an example on the C55x is shown in Example 4 4 These examples use HWI enter and give you more precise control Example 4 2 Constructing a Minimal ISR
203. not be created dynamically because they correspond to DSP interrupts However interrupt functions can be changed at run time 4 When a HWI function calls HWI enter it can pass a bitmask that indicates which interrupts to enable while the HWI function runs An enabled interrupt can preempt the HWI function even if the enabled interrupt has a lower priority than the current interrupt Thread Scheduling 4 5 Overview of Thread Scheduling Table 4 1 Characteristic HWI SWI Comparison of Thread Characteristics continued TSK IDL Context saved when blocked Share data with thread via Synchronize with thread via Function hooks Static creation Dynamic creation Dynamically change priority Implicit logging Implicit statistics Not applicable Streams queues pipes global variables Not applicable No Included in default configuration template Yes see Note 3 No see Note 4 None Monitored values Not applicable Streams queues pipes global variables SWI mailbox No Yes Yes Yes Post and completion events Execution time Saves the C regis ter set see opti mizing compiler user s guide for your platform Streams queues pipes locks mailboxes global variables Semaphores mailboxes Yes create delete exit task switch ready Yes Yes Yes Ready start block resume and termination events Execution time
204. now the frame s start address and its size The API function PIP getWriterAddr returns the address of the beginning of the allocated frame The API function PIP_getWriterSize returns the number of words that can be written to the frame The default value for an empty frame is the configured frame size When the frame is full of data it can be returned to the pipe If the number of words written to the frame is less than the frame size the function can specify this by calling the PIP_setWriterSize function Afterwards call PIP put to return the data to the pipe Calling PIP put causes the notifyReader function to run This enables the writer thread to notify the reader thread that there is data available in the pipe to be read The code fragment in Figure 6 1 demonstrates how to write data to a pipe Data Pipe Manager PIP Module Example 6 1 Writing Data to a Pipe extern far PIP Obj writerPipe pipe object created with the Configuration Tool writer Uns size Uns newsize Ptr addr if PIP getWriterNumFrames amp writerPipe gt 0 PIP alloc amp writerPipe allocate an empty frame else return There are no available empty frames addr PIP getWriterAddr amp writerPipe size PIP getWriterSize amp writerPipe fill up the frame optional newsize number of words written to the frame PIP setWriterSize amp writerPipe newsize
205. ns a reference for the Chip Support Library CSL application programming interfaces APIs The CSL is a set of APIs used to configure and control all on chip peripherals Related Documentation You can use the following books to supplement this reference guide The C Programming Language second edition by Brian W Kernighan and Dennis M Ritchie published by Prentice Hall Englewood Cliffs New Jersey 1988 Programming in C Kochan Steve G Hayden Book Company Programming Embedded Systems in C and C by Michael Barr Andy Oram Editor published by O Reilly amp Associates ISBN 1565923545 February 1999 Real Time Systems by Jane W S Liu published by Prentice Hall ISBN 013099651 June 2000 Principles of Concurrent and Distributed Programming Prentice Hall International Series in Computer Science by M Ben Ari published by Prentice Hall ISBN 013711821X May 1990 American National Standard for Information Systems Programming Language C X3 159 1989 American National Standards Institute ANSI standard for C out of print Head This First vii Trademarks Trademarks viii MS DOS Windows and Windows NT are trademarks of Microsoft Corporation The Texas Instruments logo and Texas Instruments are registered trademarks of Texas Instruments Trademarks of Texas Instruments include Tl XDS Code Composer Code Composer Studio Probe Point Code Explorer DSP BIOS RTDX Online DSP Lab BlOSuite SPOX TMS3
206. nstrumented kernel 1 400 1 600 7 400 Instrumentation 3 5 Instrumentation APIs 3 3 Instrumentation APIs Effective instrumentation requires both operations that gather data and operations that control the gathering of data in response to program events DSP BIOS provides the following three API modules for data gathering LOG Event Log Manager Log objects capture information about events in real time System events are captured in the system log You can create additional logs using the Configuration Tool Your program can add messages to any log 4 STS Statistics Object Manager Statistics objects capture count maximum and total values for any variables in real time Statistics about SWI software interrupt PRD period HWI hardware interrupt PIP pipe and TSK task objects can be captured automatically In addition your program can create statistics objects to capture other statistics 2 HST Host Channel Manager The host channel objects described in Chapter 7 Input Output Overview and Pipes allow a program to send raw data streams to the host for analysis LOG and STS provide an efficient way to capture subsets of a real time sequence of events that occur at high frequencies or a statistical summary of data values that vary rapidly The rate at which these events occur or values change may be so high that it is either not possible to transfer the entire sequence to the host due to bandwidth limitations or the o
207. nt If no alignment is necessary align should be 0 MEM s implementation aligns memory on a boundary equal to the number of words required to hold a MEM Header structure even if align has a value of 0 Other values of align cause the memory to be allocated on an align word boundary where align is a power of 2 5 1 5 Freeing Memory MEM_free frees memory obtained with a previous call to MEM_alloc MEM calloc or MEM_valloc The parameters to MEM free segid ptr and size specify a memory segment a pointer and a block size respectively as shown in Example 5 5 The values of these parameters must be the same as those used when allocating the block of storage Example 5 5 Using MEM free to Free Memory Void MEM free segid ptr size Int segid Ptr ptr Uns size Example 5 6 displays a function call which frees the array of objects allocated in Example 5 5 Example 5 6 Freeing an Array of Objects 5 1 6 Getting the Status of a Memory Segment You can use MEM stat to obtain the status of a memory segment in the number of minimum addressable data units MADUS In a manner similar to MEM alloc MEM calloc and MEM valloc refer to Example 5 3 the size used and length values are returned by MEM stat 5 1 7 Reducing Memory Fragmentation 5 6 Repeatedly allocating and freeing blocks of memory can lead to memory fragmentation When this occurs calls to MEM alloc can return MEM ILLEGAL if there is no contiguo
208. nt to continuously obtain and display the data from a DSP application and you don t need to store the data in a log file Note To drain the buffer s and allow data to continuously flow up from the target the OLE automation client must read from each target output channel on a continual basis Failure to comply with this constraint may cause data flow from the target to cease thus reducing the data rate and possibly resulting in channels being unable to obtain data In addition the OLE automation client should open all target output channels on startup to avoid data loss to any of the channels 3 7 5 Special Considerations When Writing Assembly Code The RTDX functionality in the user library interface can be accessed by a target application written in assembly code See TMS320C54x Optimizing Compiler Users Guide TMS320C55x Optimizing Compiler User s Guide or TMS320C6000 Optimizing Compiler User s Guide for information about the C calling conventions run time environment and run time support functions applicable to your platform 3 7 6 Target Buffer Size The RTDX target buffer is used to temporarily store data that is waiting to be transferred to the host You may want to reduce the size of the buffer if you are transferring only a small amount of data Alternately you may need to increase the size of the buffer if you are transferring blocks of data larger than the default buffer size Using the Configuration Tool
209. nt field see Figure 3 5 The max and total values are stored in the STS object on the target The average is computed on the host Instrumentation 3 25 Implicit DSP BIOS Instrumentation Table 3 4 STS Operations and Their Results STS Operation Result STS add addr STS delta addr STS add addr STS delta addr STS add addr STS delta addr Stores maximum and total for the data value or register value Compares the data value or register value to the prev property of the STS object or a value set consistently with STS set and stores the maximum and total differences Negates the data value or register value and stores the maximum and total As a result the value stored as the maximum is the negated minimum value The total and average are the negated total and average values Negates the data value or register value and compares the data value or register value to the prev property of the STS object or a value set programmatically with STS set Stores the maximum and total differences As a result the value stored as the maximum is the negated minimum difference Takes the absolute value of the data value or register value and stores the maximum and total As a result the value stored as the maximum is the largest negative or positive value The average is the average absolute value Compares the absolute value of the register or data value to the prev property of the STS object or
210. nt in Example 6 2 demonstrates how to read data from a pipe Example 6 2 Reading Data from a Pipe extern far PIP Obj readerPipe created with the x Configuration Tool reader Uns size Ptr addr if PIP_getReaderNumFrames amp readerPipe gt 0 PIP_get amp readerPipe get a full frame else return There are no available full frames addr PIP_getReaderAddr amp readerPipe size PIP_getReaderSize amp readerPipe read the data from the frame release the empty frame back to the pipe PIP fr amp readerPipe 6 3 3 Using a Pipe s Notify Functions 6 8 The reader or writer threads of a pipe can operate in a polled mode and directly test the number of full or empty frames available before retrieving the next full or empty frame The examples in section 6 3 1 Writing Data to a Pipe page 6 6 and section 6 3 2 Heading Data from a Pipe page 6 7 demonstrate this type of polled read and write operation When used to buffer real time I O streams written read by a hardware peripheral pipe objects often serve as a data channel between the HWI routine triggered by the peripheral itself and the program function that ultimately reads writes the data In such situations the application can effectively synchronize itself with the underlying I O stream by configuring the pipe s notifyReader notifyWriter function to automatically post a soft
211. ny change to the value at the top of the stack is seen as a non zero total or maximum in the corresponding STS object 3 45 Interrupt Latency gt Interrupt latency is the maximum time between the triggering of an interrupt and when the first instruction of the HWI executes You can measure interrupt latency for the timer interrupt by following the appropriate steps for your platform 1 Configure the HWI TINT object to monitor the tim register 2 Setthe operation parameter to STS add addr 3 Setthe host operation parameter of the HWI TINT STS object to A x B Set A to 1 and B to the value of the PRD Register shown in the global CLK properties list Note It is not possible at this time to calculate interrupt latency for the C5500 platform using DSP BIOS because the 55 timer access is outside data space Configure the HWI object specified by the CPU Interrupt property of the CLK Manager to monitor a Data Value Set the addr parameter to the address of the timer counter register for the on device timer used by the CLK Manager 3 Set the type to unsigned 4 Set the operation parameter to STS_add addr 5 Set the Host Operation parameter of the corresponding STS object HWI INT14 STS to A X B Set A to 4 and B to 0 The STS objects HWI TINT STS C5000 platform or HWI INT14 STS C6000 platform then display the maximum time in instruction cycles between when the timer interrupt was triggered
212. o developers The API Reference Guide is the companion to this user s guide TMS320C5000 DSP BIOS Application Programming Interface API Hefer ence Guide literature number SPRU404 describes the DSP BIOS API func tions which are alphabetized by name In addition there are reference sec tions that describe the overall capabilities of each module and appendices that provide tables that are useful to developers The API Reference Guide is the companion to this user s guide Helated Documentation From Texas Instruments TMS320C54x Assembly Language Tools User s Guide literature number SPRU102 describes the assembly language tools assembler linker and other tools used to develop assembly language code assembler directives macros common object file format and symbolic debugging directives for the C5000 generation of devices TMS320C55x Assembly Language Tools User s Guide literature number SPRU280 describes the assembly language tools assembler linker and other tools used to develop assembly language code assembler directives macros common object file format and symbolic debugging directives for the C5000 generation of devices TMS320C6000 Assembly Language Tools User s Guide literature number SPRU186 describes the assembly language tools assembler linker and other tools used to develop assembly language code assembler directives macros common object file format and symbolic debugging directives for the C5000 gen
213. odify the value of the SWI object mailbox when it is used to post a software interrupt SWI or sets the bits in the mailbox determined by a mask that is passed as a parameter and then posts the software interrupt SWI inc increases the SWI s mailbox value by one before posting the SWI object Thread Scheduling 4 25 Software Interrupts SWI andn and SWI dec post the SWI object only if the value of its mailbox becomes 0 SWI clears the bits in the mailbox determined by a mask passed as a parameter SWI dec decreases the value of the mailbox by one Table 4 3 summarizes the differences between these functions Table 4 3 SWI Object Function Differences Treats Treats Does not Mailbox as Mailbox as Modify Action Bitmask Counter Mailbox Always post SWI or SWI inc SWI post Post if it becomes zero SWI SWI dec The SWI mailbox allows you to have tighter control over the conditions that should cause an SWI function to be posted or the number of times the SWI function should be executed once the software interrupt is posted and scheduled for execution To access the value of its mailbox an SWI function can call SWI getmbox SWI getmbox can be called only from the SWI s object function The value returned by SWI getmbox is the value of the mailbox before the SWI object was removed from the posted SWI queue and the SWI function was scheduled for execution When the SWI Manager removes a
214. ombination For details about configuring device drivers including both custom drivers and the drivers provided with DSP BIOS you need to reference the specific device driver 7 9 1 Typical File Organization Device drivers are usually split into multiple files For example Q dxx h Dxx header file dxx c Dxx functions dxx_asm s optional assembly language functions Most of the device driver code can be written in C The following description of Dxx does not use assembly language However interrupt service routines are usually written in assembly language for efficiency and some hardware control functions also need to be written in assembly language We recommend that you become familiar at this point with the layout of one of the software device drivers such as DGN In particular you should note the following points 4 The header file dxx h typically contains the required statements shown in Example 7 17 in addition to any device specific definitions Device Driver Template Example 7 17 Required Statements in dxx h Header File 2222 22 22 dxx h include lt dev h gt extern DEV_Fxns Dxx FXNS Dxx Params A typedef struct device parameters go here Dxx Params 11 Device parameters such as Dxx Params are specified as properties of the device object in the Configuration Tool The required table of device functions is contain
215. on C6000 Platform 4 18 myclk s62 include hwi h62 macro header file IEMASK set 0 CCMASK Set c62 PCC DISABLE test myclkisr global _myclkisr _myclkisr Save all C run time environment registers HWI enter C62 ABTEMPS C62 CTEMPS IEMASK CCMASK b TON blick P call TSK itick C function mvkl tiret b3 mvkh tiret b3 nop 9 tiret restore saved registers and call DSP BIOS scheduler HWI exit C62 ABTEMPS C62 CTEMPS IEMASK CCMASK end Example 4 3 HWI Example on C54x Platform Hardware Interrupts Calls th M Ne Ne Ne Se e e C ISR code after setting cpl and saving C54_CNOTPRESERVED include hwi h54 macro header file DSS 186 HWI enter C54 CNOTPRESERVED Offf7h Cpl 0 dp GBL_A_SYSPAGE We need to set cpl bit when going to C ssbx cpl nop cpl latency nop Cpl latency call _DSS_cisr rsbx cpl HWI exit precondition nop Cpl latency nop Cpl latency ld GBL A SYSPAGE dp HWI exit C54 CNOTPRESERVED Offf7h Example 4 4 HWI Example on C55x Platform DSS isr DSS isr HWI enter C55 AR DR SAVE BY CALLER C55 ACC SAVE BY CALLER MASK C55 MISC1 SAVE BY CALLER MASK C55 MISC2 SAVE BY CALLER MASK C55
216. on freequeue for 0 i lt NUMMSGS msg i QUE put amp freeQueue msg reader Void reader Msg msg Int i for 0 i lt NUMMSGS NUMWRITERS Wait for semaphore to be posted by writer M SEM pend amp sem SYS FOREVER dequeue message msg QUE get amp msgQueue print value LOG printf amp trace read c from d msg val msg 21d free msg QUE put amp freeQueue msg LOG printf amp trace reader done 4 52 Semaphores Example 4 10 SEM Example Using Three Writer Tasks continued writer Void writer Int id Msg msg Int Lj for i 0 i lt NUMMSGS i Get msg from the free queue Since reader is higher priority and only blocks on sem this queue is never empty Ey if QUE empty amp freeQueue SYS abort Empty free queue Nn msg QUE get amp freeQueue fill in value msg gt id id msg val i amp Oxf LOG printf amp trace d writing vo id msg val enqueue message QUE put amp msgQueue msg post semaphore SEM post amp sem what happens if you call TSK yield here TSK yield LOG printf amp trace writer d done id LOG printf amp trace Note Non pointer type function arguments to LOG printf need explici
217. on to initialize I O SIO reclaim is used to retrieve buffers from the stream This is done by calling Dxx reclaim which blocks until a frame is available on the device gt fromdevice queue This blocking is accomplished by calling SEM pend on the device semaphore objptr gt sync just as for Dxx issue When the device HWI ISR in Figure 7 10 and Figure 7 11 posts to objptr gt sync Dxx reclaim is unblocked and returns to SIO reclaim SIO reclaim then gets the frame from the device gt fromdevice queue and returns the buffer This sequence is shown in Figure 7 10 and Figure 7 11 Figure 7 10 Placing a Data Buffer to a Stream SIO issue outstream bufp nbytes arg Application SIO module Dxx module im 1 Put full bufp on 1 Get next buffer from todevice todevice queue queue and make visible to ISR 2 Call Dxx_issue 2 If first issue enable interrupts SIO reclaim outstream amp bufp parg timeout 2 Get empty bufp from Figure 7 11 1 Call Dxx reclaim E Pend on semaphore until anempty buffer is available on fromdevice queue fromdevice queue SIO issue outstream bufp nbytes arg Retrieving Buffers from a Stream Application SIO module Dxx module lm 1 Put empty bufp on 1 Get next buffer from todevice todevice queue queue and make visible to ISR 2 Call Dxx_issue 2 If first issue enable interrupts SIO reclaim outstream amp bufp parg timeout
218. one running before the current task started Start End This indicates the beginning and end of the stack in memory mailboxes page select the tab labeled MBX shows all mailbox information as illustrated in Figure 3 18 Figure 3 18 The Mailboxes Page Dialog Box DSP BIDS Kemel bject View KNL TSK MBX mbx Ox800006FC Er MEM swi Refresh Disable Mailbox es Click the number to view tasks Name Handle Tasks Pending Taske Posing Mea Size Segment 8 0 mailboxes page fields and other information are as follows Mailbox es The value in this field indicates the number of mailboxes present in the currently operating system The number of lines of information in the main information field is equal to the value in this field Instrumentation 3 81 Kernel Object View Debugger Name Handle This is the mailbox name and handle The name is taken from the label for statically configured objects and is generated for dynamically created objects The label matches the name in the MBX Manager configuration The handle is the address on the target Msgs Max The first number is the current number of messages that the mailbox contains The second number is the maximum number of messages that the mailbox can hold The maximum matches the value set in the configuration Tasks Pending This is the number of tasks currently blocked waiting to read a message from the mailbox I
219. onfiguration Tool IDL init calculates the idle loop instruction count at this point in the startup sequence The idle loop instruction count is used to calibrate the CPU load displayed by the CPU Load Graph see section 3 4 2 The CPU Load page 3 19 Process the pinit table The pinit table consists of pointers to initialization functions For programs class constructors of global objects execute during pinit processing Call your program s main routine After all DSP BIOS modules have completed their initialization procedures your main routine is called This routine can be written in assembly C or a combination Because the C compiler adds an underscore prefix to function names this can be a C or C function called main or an assembly function called main Since neither hardware nor software interrupts are enabled yet you can take care of initialization procedures for your own application such as calling your own hardware initialization routines from the main routine Call BIOS start to start DSP BIOS Like BIOS init BIOS start is also generated by the Configuration Tool and is located in the programcfg s nn file BIOS start is called after the return from your main routine BIOS start is responsible for enabling the DSP BIOS modules and invoking the MOD startup macro for each DSP BIOS module If the TSK Manager is enabled in the Configuration Tool the call to BIOS start does not return For example WB s
220. onize access to the message queue id field was added to MsgObj to specify writer task id Unlike a mailbox a queue can hold an arbitrary number of messages or elements Each message must however be a structure with a QUE Elem as its first field ee eee FF HH HH HF HH HH FH HK include lt std h gt include lt log h gt include lt mem h gt include lt que h gt include lt sem h gt include lt sys h gt include lt tsk h gt include trc h define NUMMSGS 3 number of messages define NUMWRITERS 3 number of writer tasks created with J Config Tool typedef struct MsgObj QUE Elem elem first field for QUE Int writer task id Char val message value MsgObj Msg Void reader Void writer The following semaphore queues and log are created by the Configuration Tool extern SEM Obj sem extern QUE Obj msgQueue extern QUE Obj freeQueue extern LOG Obj trace Thread Scheduling 4 51 Semaphores Example 4 10 SEM Example Using Three Writer Tasks continued main x Void main Int i MsgObj msg Uns mask mask LOGTSK LOGSWI STSSWI TRC_LOGCLK TRC enable TRC GBLHOST TRC GBLTARG mask msg MsgObj MEM alloc 0 NUMMSGS sizeof MsgObj 0 if msg MEM ILLEGAL SYS abort Memory allocation failed n Put all messages
221. ons LY Performing I O with the host Q Running any user routine When the CPU is not doing any of these it is considered idle including when the CPU is in a power save or hardware idle mode To view the CPU Load Graph window as seen in Figure 3 10 select DSP BIOS gt CPU Load Graph Instrumentation 3 19 Implicit DSP BIOS Instrumentation Figure 3 10 CPU Load Graph Window CPU Load Graph Last 8 81 0 0 Peak 8 83 All CPU activity is divided into work time and idle time To measure the CPU load over a time interval T you need to know how much time during that interval was spent doing application work tw how much of it was idle time t From this you can calculate the CPU load as follows ty CPUload T x 100 Since the CPU is always either doing work or in idle it is represented as follows You can rewrite this equation ty w tl You can also express CPU load using instruction cycles rather than time intervals CPUload x 100 Cw Cy CPUload 100 3 4 2 1 Measuring the CPU Load In a DSP BIOS application the CPU is doing work when any of the following are occurring hardware interrupts are serviced software interrupts and periodic functions are run task functions are run user functions are executed from the idle loop HST channels are transferring data to the host Uouovovoeveo ev real time analysis data is uploaded to the DSP BIOS Analysis Tool
222. or each piece This works because each piece of the buffer is guaranteed to come back in the same order it was sent 7 3 1 Buffer Exchange 7 8 An important part of the streaming model in DSP BIOS is buffer exchange To provide efficient I O operations with a low amount of overhead DSP BIOS avoids copying data from one place to another during certain I O operations Instead DSP BIOS uses SIO_ get SIO_put SIO_issue and SIO_reclaim to move buffer pointers to and from the device Figure 7 3 shows a conceptual view of how SIO_ get works Figure 7 3 Stream I O Reading and Writing Streams How SIO_get Works Application Program Device SIO get stream amp bufp Driver Exchange Free Buffer Full Buffer In Figure 7 3 the device driver associated with stream fills a buffer as data becomes available At the same time the application program is processing the current buffer When the application uses SIO get to get the next buffer the new buffer that was filled by the input device is swapped for the buffer passed in This is accomplished by exchanging buffer pointers instead of copying bufsize bytes of data which would be very time consuming Therefore the overhead of SIO get is independent of the buffer size In each case the actual physical buffer has been changed by SIO get The important implication is that you must make sure that any referen
223. or long test runs The Statistics View can optionally filter the data arithmetically before displaying it as shown in Figure 3 5 Figure 3 5 Target Host Variable Accumulation Target Host 4 32 gt 64 gt Previous Accumulate Filter A x B C Display Count Count Count Count Total road Total gt Ax total C gt Total Max clear 0 A x B gt Maximum A x total B ty A C x count odia By clearing the values on the target the host allows the values displayed to be much larger without risking lost data due to values on the target wrapping around to O If polling of STS data is disabled or very infrequent there is a possibility that the STS data wraps around resulting in incorrect information While the host clears the values on the target automatically you can clear the 64 bit objects stored on the host by right clicking on the STS Data window and choosing Clear from the shortcut menu The host read and clear operations are performed with interrupts disabled to allow any thread to update any STS object reliably For example an HWI function can call STS add on an STS object and no data is missing from any STS fields This instrumentation process provides minimal intrusion into the target program A call to STS add requires approximately 20 instructions on t
224. ory segment Index value current 3 13 difference 13 13 previous 3 13 variables monitoring 3 2 watching 3 24 VECT memory segment Visual Basic 3 37 Visual C visual editor Void 1 13 W words data memory 3 3 of code wrapper function 2 25 ag Index 9
225. ot s54 C54x platform or autoinit c and boot snn C6000 and C55x platforms files determine the startup sequence Compiled versions of these files are provided with the bios ann and biosi ann libraries and the source code is available on the distribution disks received with your product The DSP BIOS startup sequence as specified in the source code of the boot files is shown below You should not need to alter the startup sequence 1 Initialize the DSP A DSP BIOS program starts at the C or C environment entry point c intOO The reset interrupt vector is set up to branch to intOO after reset For the C54x platform at the beginning of c intO0O the system stack pointer SP is set up to point to the end of stack Status registers such as 510 and st1 are also initialized At the beginning of c intOO for the C55x platform the data user stack pointer XSP and the system stack pointer XSSP are both set up to point to the bottom of the user and system stacks respectively Additionally the XSP is aligned to an even address boundary For the C6000 platform at the beginning of c intOO the system stack pointer B15 and the global page pointer B14 are set up to point to the end of the stack section and the beginning of bss respectively Control registers such as AMR IER and CSR are also initialized Initialize the bss from the cinit records Once the stacks are set up the initialization routine is called to initialize the
226. patcher contain this functionality and the use of the C modifier can cause catastrophic results Hardware Interrupts Whether called explicitly C55 or by the HWI dispatcher the HWI enter HWI exit macros prepare an ISR to call any C function In particular the ISR is prepared to call any DSP BIOS API function that is allowed to be called from the context of an HWI See Functions Callable by Tasks SWI Handlers or Hardware ISRs in the TMS320 DSP BIOS Reference Guide for your platform for a complete list of these functions Note When using the system HWI dispatcher on the C6000 and 54 platforms the HWI function must not call HWI_enter and HWI exit Regardless of which HWI dispatching method is used DSP BIOS uses the system stack during the execution of both SWIs and HWIs If there are no TSK tasks in the system this system stack is used by all threads If there are TSK tasks each task uses its own private stack Whenever a task is preempted by an SWI or HWI DSP BIOS uses the system stack for the duration of the interrupt thread HWI enter and HWI exit both take two parameters on the C54x platform Q first MASK specifies which CPU registers to be saved and restored by the ISR Q Thesecond parameter of HWI enter and HWI exit on the C54x platform IMRDISABLEMASK is a mask of those interrupts that are to be disabled between the HWI enter and HWI_ exit macro calls When an interrupt is
227. pending SWI object from the posted objects queue its mailbox is reset to its initial value The initial value of the mailbox is set from the Property Page when the SWI object is created with the Configuration Tool If while the SWI function is executing it is posted again its mailbox is updated accordingly However this does not affect the value returned by SWI getmbox while the SWI functions execute That is the mailbox value that SWI getmbox returns is the latched mailbox value when the software interrupt was removed from the list of pending SWIs The SWI s mailbox however is immediately reset after the SWI is removed from the list of pending SWIs and scheduled for execution This gives the application the ability to keep updating the value of the SWI mailbox if a new posting occurs even if the SWI function has not finished its execution For example if an SWI object is posted multiple times before it is removed from the queue of posted 5 15 the SWI Manager schedules its function to execute only once However if an SWI function must always run multiple times when the SWI object is posted multiple times SWI inc should be used to post the SWI as shown in Figure 4 5 Software Interrupts When an SWI has been posted using SWI inc once the SWI Manager calls the corresponding SWI function for execution the SWI function can access the SWI object mailbox to know how many times it was posted before it was scheduled to run and proceed to execute
228. pes of C such as int or char Instead to ensure portability to other processors that support the DSP BIOS API DSP BIOS defines its own standard data types In most cases the standard DSP BIOS types are uppercase versions of the corresponding C types The data types shown in Table 1 2 are defined in the std h header file Table 1 2 DSP BIOS Standard Data Types Type Description Arg Bool Char Int Lglnt LgUns Ptr String Uns Void Type capable of holding both Ptr and Int arguments Boolean value Character value Signed integer value Large signed integer value Large unsigned integer value Generic pointer value Zero terminated X0 sequence array of characters Unsigned integer value Empty type About DSP BIOS 1 13 Naming Conventions Additional data types are defined in std h but are not used by the DSP BIOS API In addition the standard constant NULL 0 is used by DSP BIOS to signify an empty pointer value The constants TRUE 1 and FALSE 0 are used for values of type Bool Object structures used by the DSP BIOS API modules use a naming convention of MOD Obj where MOD is the letter code for the objects module If your program code uses any such objects created by the Configuration Tool it should make an extern declaration for the object For example extern LOG_Obj trace The Configuration Tool automatically generates a C header to file that contains the appropriate declarations for a
229. pplication by using the TRC module and one of the reserved trace masks TRC USERO and TRC USER Log and statistics data are always formatted on the host The average value for an STS object and the CPU load are computed on the host Computations needed to display the Execution Graph are performed on the host LOG STS and TRC module operations are very fast and execute in constant time as shown in the following list LOG printf and LOG event approximately 30 instructions STS add approximately 30 instructions STS delta approximately 40 instructions TRC enable and disable approximately four instructions LOG printf and LOG event approximately 25 instructions STS add approximately 10 instructions STS delta approximately 15 instructions TRC enable and disable approximately four instructions LOG printf and LOG event approximately 32 instructions STS add approximately 18 instructions STS delta approximately 21 instructions TRC enable and disable approximately six instructions Each STS object uses only eight or four words of data memory for the C5000 platform or the C6000 platform respectively This means that the host always transfers the same number of words to upload data from a statistics object Instrumentation 3 3 Instrumentation Performance 3 2 1 3 4 Statistics are accumulated in 32 bit variables on the target and 64 bit variables on the host When the host polls the target
230. ppropriate value for the period register Figure 4 17 CLK Manager Properties Dialog Box CLK Clock Manager Properties x General bject Memory IDATA X Jv Enable Manager v Use high resolution time for internal timings MiGrasecords Iht 000 0 Directly configure on chip timer registers Register fi PRD Register 49999 100000 Timers Interrupts the System Clock When the CLK Manager is enabled on the C6000 platform the timer counter register is incremented every four CPU cycles When the CLK Manager is enabled on the C5400 platform the timer counter is decremented at the following rate where CLKOUT is the DSP clock speed in MIPS see the Global Settings Property dialog in the 7 5320 DSP BIOS API Reference Guide for your platform and TDDR is the value of the timer divide down register as shown in the following equation CLKOUT TDDR 1 When this register reaches 0 on the C5400 platform or the value set for the period register on the C6000 platform the counter is reset On the C5400 it is reset to the value in the period register On the C6000 it is reset to O At this point a timer interrupt occurs When a timer interrupt occurs the HWI object for the selected timer runs the CLK F isr function which causes these events to occur Q The low resolution time is incremented by 1 on the C6000 platform and on the C5000 platform All the functions specified
231. priate to your specific DSP platform If your DSP platform is C6200 based substitute 62 each time you see the designation 54 For example DSP BIOS assembly language API header files for the C6000 platform will have a suffix of h62 For a C5000 DSP platform substitute either 54 or 55 for each occurrence of 54 Also each reference to Code Composer Studio C5000 can be substituted with Code Composer Studio C6000 All identifiers beginning with upper case letters followed by an underscore XXX should be treated as reserved words 1 3 4 Module Header Names Each DSP BIOS module has two header files containing declarations of all constants types and functions made available through that module s interface 2 xxx h DSP BIOS API header files for C programs Your C source files should include std h and the header files for any modules the C functions use 21 xxx h54 DSP BIOS API header files for assembly programs Assembly source files should include the xxx h54 header file for any module the assembly source uses This file contains macro definitions specific to this device Your program must include the corresponding header for each module used in a particular program source file In addition C source files must include std h before any module header files See section 1 3 4 Data Type Names page 1 13 for more information The std h file contains definitions for standard types and constants After including std h you can include the
232. ps present the currently operating system The number of lines of information in the main information field is equal to the value in this field 2 Name This is the memory segment that the heap is allocated from as configured Kernel Object View Debugger Max Contiguous This is the maximum amount of contiguous memory that is free to allocate in the heap Free This is the total amount of memory that is free to allocate in the heap If this value is zero a warning will be given A warning is indicated when this field is red and the text is yellow Size Start End This is the heap size and the starting and ending locations in memory Used This is the amount of memory that is allocated from the heap If this value is equal to the size a warning is given A warning is indicated when this field is red and the text is yellow Segment This is the memory segment 3 5 6 Software Interrupts The software interrupts page select the tab labeled SWI shows all software interrupt information Figure 3 23 The Software Interrupts Page Dialog Box DSP BIOS gt Kernel Object View KNL TSK MBX SEM MEM Swi Refresh Disable 2 Software Interrupt s Name Handle State Priority Mailbox KNL_swi 0x8000002C swiSlice 0 80000058 Ready 0 Inactive 1 swiFxn 0x00000000 Q 00000000 The software interrupts page fields and other information are as follows Software Interrupt s
233. ptr 0 1010 after allocating seg 0 0x400 U 0104 Ox2fc after freeing 10 seg 0 0x400 11 LU 0 4 4 Ox3fc CO CO 7 CD Cl CO P9 The program in Example 5 7 and Example 5 8 gives board dependent results O indicates the original amount of memory U the amount of memory used and A the length in MADUS of the largest contiguous free block of memory The addresses you see are likely to differ from those shown in Example 5 2 System Services 5 2 System Services The SYS module provides a basic set of system services patterned after similar functions normally found in the standard C run time library As a rule DSP BIOS software modules use the services provided by SYS in lieu of similar C library functions Using the Configuration Tool you can specify a customized routine that performs when the program calls one of these SYS functions See the SYS reference section in the TMS320 DSP BIOS Reference Guide for your platform for details 5 2 1 Halting Execution SYS provides two functions as seen in Example 5 9 for halting program execution SYS exit which is used for orderly termination and SYS abort which is reserved for catastrophic situations Since the actions that should be performed when exiting or aborting programs are inherently system dependent you can modify configuration settings to invoke your own routines whenever SYS exit or SYS abort is called Example 5 9 Coding To Halt Program Execut
234. ptured by the host with the DSP BIOS Analysis Tools can provide insight into the sequence of events that led up to the current point of execution Later in the software development cycle when regular debugging techniques become ineffective for attacking problems arising from time dependent interactions the DSP BIOS Analysis Tools have an expanded role as the software counterpart of the hardware logic analyzer Figure 1 4 illustrates several of the DSP BIOS Analysis Tools panels Figure 1 4 Code Composer Studio Analysis Tool Panels DS MI mar karria RU IR TAIEME qE 0 Thebe Dh Ed fae od imm E Ies mie fab Dias Wee eR CS i age au sj MESABHU 3257 STA Crid Pal MIE ELI rong 5 SEM ee ine 783307540 00 HSD EE ee Bu HAO About DSP BIOS 1 9 DSP BIOS Components Figure 1 5 shows the DSP BIOS Analysis Tools toolbar which can be toggled on and off by choosing ViewPlug in ToolbarsSDSP BIOS Figure 1 5 DSP BIOS Analysis Tools Toolbar E Ed 6 Naming Conventions 1 3 Naming Conventions Each DSP BIOS module has a unique name that is used as a prefix for operations functions header files and objects for the module This name is comprised of 3 or more uppercase alphanumerics Throughout this manual 54 represents the two digit numeric appro
235. put and output for DSP BIOS applications are handled by stream pipe and host channel objects Each type of object has its own module for managing data input and output A stream is a channel through which data flows between an application program and an I O device This channel can be read only input or write only output as shown in Figure 6 1 Streams provide a simple and universal interface to all I O devices allowing the application to be completely ignorant of the details of an individual device s operation s il BH BN Application EH Input Program Output An important aspect of stream I O is its asynchronous nature Buffers of data are input or output concurrently with computation While an application is processing the current buffer a new input buffer is being filled and a previous one is being output This efficient management of I O buffers allows streams to minimize copying of data Streams exchange pointers rather than data thus reducing overhead and allowing programs to meet real time constraints more readily Input Output Stream A typical program gets a buffer of input data processes the data and then outputs a buffer of processed data This sequence repeats over and over usually until the program is terminated Digital to analog converters video frame grabbers transducers and DMA channels are just a few examples of common devices The stream module SIO in
236. r example let T be the time taken by an algorithm to process the i frame of data An STS object can store summary information about the time series Tj The following code fragment illustrates the use of gethtime high resolution time STS set and STS delta to track statistical information about the time required to perform an algorithm STS set amp stsObj CLK gethtime algorithm STS delta amp stsObj CLK gethtime STS set saves the value of CLK gethtime as the contents of the previous value field set value in the STS object STS delta subtracts this set value from the new value it is passed The result is the difference between the time recorded before the algorithm started and after it was completed that is the time it took to execute the algorithm STS delta then invokes 5 5 add and passes this result as the new contents of the previous value field to be tracked The host can display the count of times the algorithm was performed the maximum time to perform the algorithm the total time performing the algorithm and the average time The set value is the fourth component of an STS object It is provided to support statistical analysis of a data series that consist of value differences rather than absolute values Instrumentation APIs 3 3 3 3 Statistics About Value Differences Both STS set and STS delta update the contents of the previous value field in an STS object Depending on the call s
237. r program development A program can dynamically create and delete objects that are used in special situations The same program can use both objects created dynamically and objects created with the Configuration Tool The threading model provides thread types for a variety of situations Hardware interrupts software interrupts tasks idle functions and periodic functions are all supported You can control the priorities and blocking characteristics of threads through your choice of thread types Structures to support communication and synchronization between threads are provided These include semaphores mailboxes and resource locks Two I O models are supported for maximum flexibility and power Pipes are used for target host communication and to support simple cases in which one thread writes to the pipe and another reads from the pipe Streams are used for more complex I O and to support device drivers Low level system primitives are provided to make it easier to handle errors create common data structures and manage memory usage The Chip Support Library CSL is a component of DSP BIOS and can be used within a DSP BIOS application DSP BIOS Features and Benefits The DSP BIOS API standardizes DSP programming for a number of TI devices and provides easy to use powerful program development tools These tools reduce the time required to create DSP programs in the following ways Q The Configuration Tool ge
238. ram Software interrupts provide additional priority levels between hardware interrupts and TSKs SWIs handle threads subject to time constraints that preclude them from being run as tasks but whose deadlines are not as severe as those of hardware ISRs Like HWI s SWI s threads always run to completion Software interrupts should be used to schedule events with deadlines of 100 microseconds or SWls allow HWls to defer less critical processing to a lower priority thread minimizing the time the CPU spends inside an interrupt service routine where other HWIs can be disabled See section 4 3 Software Interrupts page 4 20 for details about software interrupts 1 Tasks TSK Tasks have higher priority than the background thread and lower priority than software interrupts Tasks differ from software interrupts in that they can be suspended during execution until necessary resources are available DSP BIOS provides a number of structures that can be used for inter task communication and synchronization These structures include queues semaphores and mailboxes See section 4 4 Tasks page 4 34 for details about tasks 4 Background thread Executes the idle loop IDL at the lowest priority in a DSP BIOS application After main returns a DSP BIOS application calls the startup routine for each DSP BIOS module and then falls into the idle loop The idle loop is a continuous loop that calls all functions for the IDL objects Each functio
239. raph RTA_dispatcher 4 48 RTA F dispatch function 1 13 2 18 8 37 RTDX dataPump rts src run time support library SBSRAM memory segment SDRAMO memory segment 1 15 SDRAM 1 memory segment 1 15 See also startup B20 seed file SEM create SEM delete 4 49 SEM pend SEM post semaphore count 3 33 creating See create deleting See SEM delete signal See SEM post synchronization and device drivers waiting on See SEM pend servo SIO module mapping to driver function table 7 3 SIO create name passed to 7 35 to open devices 7 5 SIO ctrl general calling format 7 23 SIO delete to close devices 7 6 SIO flush to synchronize devices 7 23 SIO get exchanging buffers SIO idle to synchronize devices SIO ISSUERECLAIM See Issue Reclaim streaming model SIO put outputting and exchanging buffers SIO reclaim retrieving buffers 7 39 SIO select and multiple streams calls to Dxx ready 7 45 pseudo code SIO STANDARD See standard streaming model slow return 2 23 small model 12 8 2 10 software interrupt 3 19 and application stack size 4 23 creating deleting 2 33 enabling and disabling 4 32 priority levels 4 24 state software handler SWI handler 4 20 creating and 4 21 synchronizing 4 32 using software interrupts 3 35 4 2 Index benefits and tradeoffs 4 30 setting priorities suggested use e software interrupts page in Kernel Object Vi
240. rdware interrupt2 HM 2 sw A finishes Software interrupt 4 SW A _ 1 4 SM B finishes Software interrupt B SYM B Background Time 9 In Figure 4 2 the low priority software interrupt is asynchronously preempted by the hardware interrupts The first ISR posts a higher priority software interrupt which is executed after both hardware interrupt routines finish executing Hardware Interrupts 4 2 Hardware Interrupts Hardware interrupts handle critical processing that the application must perform in response to external asynchronous events The DSP BIOS HWI module is used to manage hardware interrupts In a typical DSP system hardware interrupts are triggered either by on device peripherals or by devices external to the DSP In both cases the interrupt causes the processor to vector to the ISR address The address to which a DSP BIOS HWI object causes an interrupt to vector can be a user routine or the common system HWI dispatcher Hardware ISRs can be written using assembly language C or a combination of both HWI functions are usually written in assembly language for efficiency To allow an HWI object s function to be written completely in C the system HWI dispatcher should be used All hardware interrupts run to completion If an HWI is posted multiple times before its ISR has a chance to run the ISR runs only one time For this reason you should minimize t
241. re 7 9 Figure 7 9 Flow of DEV STANDARD Streaming Model Application SIO module Dxx module SIO get inStream amp bufp 1 2 Call Dxx issue function 3 Put bufp on todevice queue Call Dxx reclaim function 4 Get next buffer from fromdevice queue 5 Set bufp to point to this buffer 1 Get next buffer from todevice queue and make visible to ISR 2 If first get enable interrupts 3 Pend on semaphore for non empty buffer on fromdevice queue SIO put outStream amp bufp BUFSIZE 1 2 Call Dxx issue function 3 Put bufp on todevice queue Call Dxx reclaim function 4 Get next buffer from fromdevice queue 5 Set bufp to point to this buffer 1 Get next buffer from todevice queue and make visible to ISR 2 If first put enable interrupts 3 Pend on semaphore for empty buffer on fromdevice queue Real Time I O Note that objptr gt sync is a counting semaphore and that tasks do not always block here The value of objptr gt sync represents the number of available frames on the fromdevice queue 7 13 2 DEV_ISSUERECLAIM Streaming Model In the DEV_ISSUERECLAIM streaming model SIO_issue is used to send buffers to a stream To accomplish this SIO_issue first places the frame on the device gt todevice queue It then calls Dxx_issue which starts the I O and returns Dxx issue calls a low level hardware functi
242. re count is initialized to count when it is created In general count is set to the number of resources that the semaphore is synchronizing SEM pend waits for a semaphore If the semaphore count is greater than 0 SEM pend simply decrements the count and returns Otherwise SEM pend waits for the semaphore to be posted by SEM post Note When called within an HWI the code sequence calling SEM post or SEM ipost must be either wrapped within an HWI enter HWI exit pair invoked by the HWI dispatcher L The timeout parameter to SEM_pend as shown in Example 4 8 allows the task to wait until a timeout to wait indefinitely SYS_FOREVER or to not wait at all 0 SEM pend s return value is used to indicate if the semaphore was acquired successfully Thread Scheduling 4 49 Semaphores Example 4 8 Example 4 9 Setting a Timeout with SEM pend Bool SEM pend sem timeout SEM Handle sem Uns timeout return after this many system clock ticks Example 4 9 provides an example of SEM post which is used to signal a semaphore If a task is waiting for the semaphore SEM post removes the task from the semaphore queue and puts it on the ready queue If no tasks are waiting SEM post simply increments the semaphore count and returns Signaling a Semaphore with SEM post Void SEM post sem 4 6 1 SEM Example Example 4 10 provides sample code for three writer tasks which create
243. re not listed in the log because they occur after the host polls the log and are overwritten before the next time the host polls the log The Execution Graph shows a red vertical line and a break in the log sequence numbers at the end of each group of log events it polls L You can view more log events by increasing the size of the log to hold the full sequence of events you want to examine You can also set the RTA Control Panel to log only the events you want to examine Thread Scheduling 4 73 Using the Execution Graph to View Program Execution 4 10 4 RTA Control Panel Settings for Use with the Execution Graph Figure 4 21 4 74 The TRC module allows you to control what events are recorded in the Execution Graph at any given time during the application execution The recording of SWI PRD and CLK events in the Execution Graph can be controlled from the host using the RTA Control Panel as shown in Figure 4 21 DSP BIOS RTA Control Panel in Code Composer Studio software or from the target code through the TRC enable and TRC disable APIs See section 3 3 4 2 Control of Implicit Instrumentation page 3 15 for details on how to control implicit instrumentation RTA Control Panel Dialog Box RT Control Panel enable SWI logging enable PRD logging enable CLK logging enable TSK logging enable SWI accumulators enable PRD accumulators enable PIP accumulators enable Hw accumulators enable TSK accumulators enable USERO tr
244. returns the number of bytes in the input buffer The SIO put function performs the output of data buffers and like SIO get exchanges physical buffers with the stream SIO put takes the number of bytes in the output buffer Example 7 3 Inputting and Outputting Data Buffers Int SIO get stream bufp SIO Handle stream Ptr bufp Int SIO put stream bufp nbytes SIO Handle stream Ptr bufp Uns nbytes Note Since the buffer pointed to by bufp is exchanged with the stream the buffer size memory segment and alignment must correspond to the attributes of stream L SlO_issue and SlO_reclaim are the calls that implement the Issue Reclaim streaming model as shown in Example 7 4 SIO_issue sends a buffer to a stream No buffer is returned and the stream returns control to the task without blocking arg is not interpreted by DSP BIOS but is offered as a service to the stream client arg is passed to each device with the associated buffer data It can be used by the stream client as a method of communicating with the device drivers For example arg could be used to send a time stamp to an output device indicating exactly when the data is to be rendered SIO reclaim requests a stream to return a buffer Streaming I O and Device Drivers 7 7 Stream and Writing Streams Example 7 4 Implementing the Issue Reclaim Streaming Model Int SIO issue stream pbuf nbytes arg SIO Handl
245. rn PIP Obj inputObj C5000 devices The DSP BIOS object is now visible in all functions that follow its definition in the program The Configuration Tool creates these declarations automatically in a file of the form program cfg h where program is the name of your application program This file can be included in your C files that reference the DSP BIOS object Although DSP BIOS itself is compiled using the small model you can compile DSP BIOS applications using either the C6000 compiler s small model or any variation of the large model See the TMS320C6000 Optimizing Compiler User s Guide In fact you can mix compilation models within the application code provided all global data that is accessed by using a displacement relative to B14 is placed no more than 32K bytes away from the beginning of the bss section DSP BIOS uses the bss section to store global data However objects created with the Configuration Tool are not placed in the bss section This maximizes your flexibility in the placement of application data For example the frequently accessed bss can be placed in on device memory while larger less frequently accessed objects can be stored in external memory Program Generation 2 7 Using the Configuration Tool The small model makes assumptions about the placement of global data in order to reduce the number of instruction cycles If you are using the small model the default compilation mode to optimize glob
246. ror issuing buffer d i if buf MEM 11 1 SIO bufsize input 0 if buf MEM ILLEGAL SYS abort Memory allocation error for i 0 i lt nloops i Issue an empty buffer to the input stream if SIO issue input buf SIO bufsize input NULL lt 0 SYS_abort Error issuing buffer d i Reclaim full buffer from the input stream if nbytes SIO reclaim input amp buf amp arg lt 0 SYS_abort Error reclaiming buffer d i Issue full buffer to the output stream if SIO issue output buf nbytes NULL lt 0 SYS_abort Error issuing buffer d i Reclaim empty buffer from the output stream to be reused if SIO reclaim output amp buf amp arg lt 0 SYS_abort Error reclaiming buffer d i Reclaim and delete the buffers used MEM free IDRAM1 buf SIO bufsize input if nbytes SIO reclaim input amp buf amp arg O i E M doIRstreaming xy Void doIRstreaming Uns nloops buf arg i nbytes SYS abort Error reclaiming buffer d i f SIO issue output buf nbytes NULL 0 SYS abort Error issuing buffer d i f SIO reclaim output amp buf amp arg lt 0 SYS abort Error reclaiming buffer d i EM fre e IDRAM1 buf SIO bufsize input The complete source code an
247. rovide a measure of time intervals within the Execution Graph Rather than timestamping each log event which is expensive because of the time required to get the timestamp and the extra log space required the Execution Graph simply records CLK events along with other system events As a result the time scale on the Execution Graph is not linear In addition to SWI TSK SEM PRD and CLK events the Execution Graph shows additional information in the graphical display Assertions are indications that either a real time deadline has been missed or an invalid state has been detected either because the system log has been corrupted or the target has performed an illegal operation The LOG message state which has the color green associated with it appears on the Assertions trace line for LOG message calls made by the user s application Errors generated by internal log calls are shown in red on the Assertions trace line Red boxes on the Assertions trace indicate a break in the information gathered from the System log See section 4 1 5 Yielding and Preemption page 4 8 for details on how to interpret the Execution Graph information in relation to DSP BIOS program execution 3 4 2 The CPU Load The CPU load is defined as the percentage of instruction cycles that the CPU spends doing application work That is the percentage of the total time that the CPU is Running hardware interrupts software interrupts tasks or periodic functi
248. rt 080002800 writer 0 800031 4 0x80002BFF writer 0x8000318C Size 0x400 gt Peak 0x60 The Kernel page fields and other information are as follows 2 Mode The value in this field indicates the current operating mode of the target When Kernel appears it indicates that the program is currently executing inside DSP BIOS while Application indicates that the application is executing Instrumentation 3 29 Kernel Object View Debugger d d 3 5 2 Tasks Target The Target field indicates the target processor and whether it is an emulator or simulator Time This is the current value of the clock that is used for timer functions and alarms for tasks The clock is set up during configuration PRD_clk in CLK Clock Manager This is only used when tasks are enabled in the Task Manager TSK When tasks are disabled the time field remains zero System Stack The four boxes on the right edge indicate system stack information Tasks Blocked with Timers Running This list contains all tasks that are currently blocked and have timers running The timers are used to unblock the tasks in the case that they are not made ready by any other means The tasks are unblocked with a semaphore a message in a mailbox and so on The tasks page select the tab labeled TSK shows all task information as illustrated in Figure 3 17 Figure 3 17 The Task Page Dialog Box Kernel Object View KNL TSK SE
249. rty sheet 4 Change property settings and click OK For help on specific properties click Help in any property sheet Program Generation 2 5 Using the Configuration Tool Note When specifying C functions to be run by various objects add an underscore before the C function name For example type _myfunc to run a C function called myfunc The underscore prefix is necessary because the Configuration Tool creates assembly source and C calling conventions require an underscore before C functions called from assembly 2 2 5 Hierarchy Tree View The Hierarchy Tree View of the Configuration Tool as seen in the left pane of Figure 2 1 displays the instances of objects in alphabetic order Figure 2 1 Configuration Tool Hierarchy and Ordered Collection Views Configuration Tool File Edit View Object Help peal Balm Estimated Data Size 2660 Est Min Stack Size 304 CLK Clock Manager objects by priority System C Execution Order First Instrumentation zi CLK2 5 08 Scheduling i PRD clock gt CLK Clock Manager zi CLKO a CLKO zi ZB ck ib CLK2 8 PRD clock ro PRD Periodic Function Manager HWI Hardware Interrupt Service Routine Manager W Sw Software Interrupt Manager 2 TSK Task Manager IDL Idle Function Manager E Synchronization Input Output la
250. s Implicit DSP BIOS Instrumentation When the CPU is not performing any of those activities it is going through the idle loop executing the IDL cpuLoad function and calling the other DSP BIOS IDL objects In other words the CPU idle time in a DSP BIOS application is the time that the CPU spends doing the routine in Example 3 3 To measure the CPU load in a DSP BIOS application over a time interval T it is sufficient to know how much time was spent going through the loop shown in Figure 3 3 and how much time was spent doing application work Example 3 3 The Idle Loop Idle loop Perform IDL cpuLoad Perform all other IDL functions user or system functions Goto IDL loop Over a period of time T a CPU with M MIPS million instructions per second executes M x T instruction cycles Of those instruction cycles are spent doing application work The rest are spent executing the idle loop shown in Example 3 3 If the number of instruction cycles required to execute this loop once is l4 the total number of instruction cycles spent executing the loop is N x 1 where N is the number of times the loop is repeated over the period T Hence you have total instruction cycles equals work instruction cycles plus idle instruction cycles MT c Nl From this expression you can rewrite Cy as c MT NI 3 4 2 2 Calculating the Application CPU Load Using the previous equations you can calculate the CPU load ina DS
251. s Q Visual applications Lab View L4 Microsoft Excel Typically an RTDX OLE automation client is a display that allows you to visualize the data in a meaningful way 3 7 3 2 Host to Target Data Flow For the target to receive data from the host you must first declare an input channel and request data from it using routines defined in the user interface The request for data is recorded into the RTDX target buffer and sent to the host via the JTAG interface Instrumentation 3 39 Real Time Data Exchange An OLE automation client can send data to the target using the OLE Interface All data to be sent to the target is written to a memory buffer within the RTDX host library When the RTDX host library receives a read request from the target application the data in the host buffer is sent to the target via the JTAG interface The data is written to the requested location on the target in real time The host notifies the RTDX target library when the operation is complete 3 7 3 3 RTDX Target Library User Interface The user interface provides the safest method of exchanging data between a target application and the RTDX host library The data types and functions defined in the user interface handle the following functions Enable a target application to send data to the RTDX host library Enable a target application to request data from the RTDX host library Provide data buffering on the target A copy of your da
252. s and the System Clock DSPs typicaly have one or more on device timers which generate a hardware interrupt at periodic intervals DSP BIOS normally uses one of the available on device timers as the source for its own system clock Using the on device timer hardware present on most TMS320 DSPs the CLK module supports time resolutions close to the single instruction cycle You define the system clock parameters in the DSP BIOS configuration settings In addition to the DSP BIOS system clock you can set up additional clock objects for invoking functions each time a timer interrupt occurs On the C6000 platform you can also define parameters for the CLK module s HWI object since that object is pre configured to use the HWI dispatcher This allows you to manipulate the interrupt mask and cache control mask properties of the CLK ISR DSP BIOS provides two separate timing methods the high and low resolution times and the system clock In the default configuration the low resolution time and the system clock are the same However your program can drive the system clock using some other event such as the availability of data You can disable or enable the CLK Manager s use of the on device timer to drive high and low resolution times You can drive the system clock using the low resolution time some other event or not at all The interactions between these two timing methods are shown in Example 4 16 Figure 4 16 Interactions Between Two
253. s about the period elapsed from the time the software interrupt was posted to its completion m PRD The number of periodic system ticks elapsed from the time the periodic function is ready to run until its completion By definition a periodic function is ready to run when period ticks have occurred where period is the period parameter for this object You can set the units for the SWI completion period by setting CLK Manager parameters This period is measured in instruction cycles if the CLK module s Use high resolution time for internal timings parameter is set to True the default If this CLK parameter is set to False SWI statistics are displayed in units of timer interrupt periods You can also choose milliseconds or microseconds for Statistics Units on the Statistics View Property Page For example if the maximum value for a PRD object increases continuously the object is probably not meeting its real time deadline In fact the maximum value for a PRD object should be less than or equal to the period in system ticks property of this PRD object If the maximum value is greater than the period Figure 4 19 the periodic function has missed its real time deadline Periodic Function Manager PRD and the System Clock Figure 4 19 Using Statistics View for a PRD Object Statistics View i D x PRD swi 1831 71200064 00 inst 102572 00 inst 36872 12 inst KNL_swi 15453 81301080 00 inst 102764 00 inst 5261 18 inst audioS wi 1
254. s should ever be modified by a driver s functions These fields are essentially output parameters of Dxx open Device Driver Initialization 7 11 Device Driver Initialization The driver function table Dxx_FXNS is initialized in dxx c as shown in section 7 10 Streaming DEV Structures page 7 30 Additional initialization is performed by Dxx_init The Dxx module is initialized when other application level modules are initialized Dxx_init typically calls hardware initialization routines and initializes static driver structures as shown in Example 7 22 Example 7 22 Initialization by Dxx init Void Dxx_init Perform hardware initialization Although Dxx_init is required in order to maintain consistency with DSP BIOS configuration and initialization standards there are actually no DSP BIOS requirements for the internal operation of Dxx_init There is in fact no standard for hardware initialization and it can be more appropriate on some systems to perform certain hardware setup operations elsewhere in Dxx such as Dxx_open Therefore on some systems Dxx_init might simply be an empty function Streaming I O and Device Drivers 7 33 Opening Devices 7 12 Opening Devices Dxx open opens device and returns its status seen in Example 7 23 Example 7 23 Opening a Device with Dxx open status Dxx open device name SIO create calls Dxx_open to open a device as seen in Ex
255. s that implicitly perform a series of transformations on the data produced and consumed by the underlying real devices as shown in Example 7 8 Example 7 8 Opening a Pair of Virtual Devices SIO Handle input SIO Handle output Ptr buf Int n buf MEM alloc 0 MAXSIZE 0 input SIO create scale2 a2d SIO INPUT MAXSIZE NULL output SIO create mask2 d2a SIO OUTPUT MAXSIZE NULL while n SIO get input amp buf apply algorithm to contents of buf SIO put output amp buf n SIO delete input SIO delete output Stackable Devices In Example 7 8 the virtual input device scale2 a2d actually comprises a stack of two devices each named according to the prefix of the device name specified in your configuration file 11 scale2 designates a device that transforms a fixed point data stream produced by an underlying device a2d into a stream of scaled fixed point values and 12 a2d designates a device managed by the A D D A device driver that produces a stream of fixed point input from an A D converter The virtual output device mask2 d2a likewise denotes a stack of two devices Figure 7 6 shows the flow of empty and full frames through these virtual source and sink devices as the application program calls the SIO data streaming functions Figure 7 6 The Flow of Empty and Full Frames 7 4 1 Source Device Sink Device SIO get scale2 ma
256. seeeeenn nennen nennen The DEV Exns SIr CtUre ctt The DEV Frame The DEV Handle Structure ccccccccccccsecsessssseceeceeececeecsesseaaesaeceseceseeeseensaaeaeceeeeeeens Initialization eterne eder ecce ti ib e crt desde Opening a Device with Dxx open sssssssssssseeeneeeene nennen nennen nnns nnne enn Opening an Input Terminating Device Arguments to Dxx ODOT Ea The Parameters of SIO create srncie aana aR a sn rsen I 3b Welle Contents xvii Examples 7 28 7 29 7 30 7 31 7 32 7 33 xviii Typical Features for a Terminating Template for Dxx issue for a Typical Terminating Device Template for Dxx reclaim for a Typical Terminating Device Closing a Device Making a Device Ready SIO Select Pseudocode About DSP BIOS DSP BIOS is a scalable real time kernel It is designed for applications that require real time scheduling synchronization host to target communication or real time instrumentation DSP BIOS provides preemptive multi threading hardware abstraction real time analysis and configuration tools Topic Page 1 1 DSP BIO
257. sh parameter has no effect on a device opened for input For a device opened for output however the flush parameter is significant If flush is TRUE any pending data is thrown away If flush is FALSE the Dxx idle function does not return until all pending data has been rendered Device Control 7 15 Device Control Dxx ctrl is called by SIO ctrl to perform a control operation on a device A typical use of Dxx ctrl is to change the contents of a device control register or the sampling rate for an A D or D A device ctrl is called as follows Status Dxx ctrl DEV Handle device Uns cmd Arg arg cmd is a device specific command arg provides an optional command argument Dxx ctrl returns SYS_OK if the control operation was successful otherwise Dxx ctrl returns an error code 7 16 Device Ready Dxx ready is called by SIO select to determine if a device is ready for I O Dxx ready returns TRUE if the device is ready and FALSE if the device is not The device is ready if the next call to retrieve a buffer from the device will not block This usually means that there is at least one available frame on the queue device gt fromdevice when Dxx ready returns as shown in Example 7 32 Refer to section 7 6 Selecting Among Multiple Streams page 7 24 for more information on SIO select Example 7 32 Making a Device Ready Bool Dxx ready DEV Handle dev SEM Handle sem Dxx Handle objptr D
258. sk2 Application Program Example SIO create and Stacking Devices Example 7 9 illustrates two tasks sourceTask and sinkTask that exchange data through a pipe device sourceTask is a writer task that receives data from an input stream attached to a DGN sine device and redirects the data to an output stream attached to a DPI pipe device The input stream also has a stacking device scale on top of the DGN sine device The data stream coming from sine is first processed by the scale device that multiplies each data point by a constant integer value before it is received by sourceTask sinkTask is a reader task that reads the data that sourceTask sent to the DPI pipe device through an input stream and redirects it to a DGN printData device through an output stream Streaming I O and Device Drivers 7 17 Stackable Devices The devices in Example 7 9 have been configured with the Configuration Tool The complete source code and configuration template for Example 7 9 can be found in the c ti tutorial target siotest directory of the DSP BIOS product distribution siotest5 c siotestb cdb dgn print c The devices sineWave and printDat are DGN devices is a DPI device scale is a DTR stacking device For more information on how to add and configure DPI DGN DTR devices see the DPI DGN and DTR drivers description in the TMS320 DSP BIOS API Reference Gu
259. so a request to do so generates an error message If the device can be opened the rest of Dxx open consists of two major operations First the device specific object is initialized based in part on the device params settings passed by SIO create Second this object is attached to device object Dxx open returns SYS OK to SIO create which now has a properly initialized device object Opening Devices The configurable device parameters are used to set the operating parameters of the hardware There are no DSP BIOS constraints on which parameters should be set in Dxx init rather than in Dxx open The object semaphore objptr sync is typically used to signal a task that is pending on the completion of an I O operation For example a task can call SIO put which can block by pending on objptr5sync When the required output is accomplished SEM post is called with objpt2sync This makes a task blocked in Dxx output ready to run DSP BIOS does not impose any special constraints on the use of synchronization semaphores within a device driver The appropriate use of such semaphores depends on the nature of the driver requirements and the underlying hardware The ready semaphore objptr ready is used by Dxx ready which is called by SIO select to determine if a device is available for I O This semaphore is explained in section 4 6 Semaphores page 4 49 Streaming I O and Device Drivers 7 37 Real Time 7 13 Real Time I O In DS
260. status parameter SYS exit first executes a set of handlers registered through the function SYS atexit as described Example 5 11 Using Handlers in SYS exit handlerN status handler2 status handlerl status Exit function status The function SYS atexit provides a mechanism that enables you to stack up to SYS NUMHANDLERS which is set to 8 clean up routines as shown in Example 5 12 The handlers are executed before SYS exit calls the function bound to the Exit function property SYS atexit returns FALSE when its internal stack is full Example 5 12 Using Multiple SYS NUMHANDLERS Bool SYS atexit handler Fxn handler System Services 5 2 2 Handling Errors SYS_error is used to handle DSP BIOS error conditions as shown in Example 5 13 Application programs as well as internal functions use SYS error to handle program errors Example 5 13 DSP BIOS Error Handling Void SYS_error s errno String 5 Uns errno SYS error uses whatever function is bound to the Error function property to handle error conditions The default error function in the configuration template is UTL doError which logs an error message In Example 5 14 Error function can be configured to use doError which uses LOG error to print the error number and associated error string Example 5 14 Using doError to Print Error Information Void doError String s Int errno va list ap LOG error SYS error calle
261. store AO b C Code include hwi h Uns oldmask oldmask HWI disable do some critical operation do not call TSK sleep SEM post etc HWI restore oldmask Using HWI restore instead of HWI enable allows the pair of calls to be nested If the calls are nested the outermost call to HWI disable turns interrupts off and the innermost call to HWI disable does nothing Interrupts are not reenabled until the outermost call to restore Be careful when using HWI enable because this call enables interrupts even if they were already disabled when HWI disable was called Note DSP BIOS kernel calls that can cause task rescheduling for example SEM postand TSK sleep should be avoided within a block surrounded by HWI disable and HWI enable since the interrupts can be disabled for an indeterminate amount of time if a task switch occurs L Thread Scheduling 4 13 Hardware Interrupts 4 2 3 Context and Interrupt Management within Interrupts When a hardware interrupt preempts the function that is currently executing the HWI function must save and restore any registers it uses or modifies DSP BIOS provides the HWI enter assembly macro to save registers and the HWI exit assembly macro to restore registers Using these macros gives the function that was preempted the same context when it resumes running In addition to the register context saving restoring functionality the HWI enter HWI exi
262. system object 4 75 logs objects performance sequence numbers _ 4 73 low resolution times 4 62 MADU mailbox SWl objects 4 25 length memory segment number 8 32 message size messages 3 32 name priority scheduling wait time mailboxes creating See MBX create deleting See MBX delete MBX example 4 5 MBX module 4 55 posting a message to See MBX post reading a message from See MBX pend makefile makefiles malloc map file predefined 1 17 MAU maximum MBX create MBX delete MEM manager Mem manager MEM module MEM alloc MEM free MEM stat memory contiguous freeing management functions 2 18 segment names Index memory management alloc allocating See MEM freeing See MEM free MEM example reducing fragmentation memory page in Kernel View memory segment declare memory alignment of 5 6 message log message numbering 8 9 message slots E Minimum addressable data units minimum addressable unit See MAU MIPS mode continuous 3 41 non continuous multitasking See tasks N name mangling 2 24 2 25 name overloading namespace and device parameters 7 29 and devices naming conventions nmti cher notify function E notifyReader function notify Writer function 6 5 NULL 1 14 O object pre configured 1 8 SWI 4 21 2 13 1 12 object files object names 2 object structures objects deleting Yd c
263. t macros perform the following system level operations ensure the SWI and TSK schedulers are called at the appropriate times disable restore individual interrupts while the ISR executes The HWI enter assembly macro must be called prior to any DSP BIOS API calls that could post or affect a software interrupt or semaphore The HWI exit assembly macro must be called at the very end of the function s code In order to support interrupt routines written completely in C DSP BIOS provides an HWI dispatcher that performs these enter and exit macros for an interrupt routine An HWI can handle context saving and interrupt disabling using this HWI dispatcher or by explicitly calling HWIl enter and HWI exit The Configuration Tool allows you to choose whether the HWI dispatcher is used for individual HWI objects The HWI dispatcher is the preferred method for handling interrupts The HWI dispatcher in effect calls the configured HWI function from within an HWI enter HWI exit macro pair This allows the HWI function to be written completely in C It would in fact cause a system crash were the dispatcher to call a function that contains the HWI enter HWI exit macro pair Using the dispatcher therefore allows for only one instance of the HWI enter and HWI exit code Note The interrupt keyword or INTERRUPT pragma must not be used when HWI objects are used in conjunction with C functions The HWI enter HWI exit macros and the HWI dis
264. t type casting to Arg as shown in the following code example Task d Done Arg id Thread Scheduling 4 53 Semaphores Figure 4 14 Trace Window Results from Example 4 10 4 54 Mailboxes 4 7 Mailboxes The MBX module provides a set of functions to manage mailboxes MBX mailboxes can be used to pass messages from one task to another on the same processor An intertask synchronization enforced by a fixed length shared mailbox can be used to ensure that the flow of incoming messages does not exceed the ability of the system to process those messages The examples given in this section illustrate just such a scheme The mailboxes managed by the MBX module are separate from the mailbox structure contained within a SWI object MBX create and MBX delete are used to create and delete mailboxes respectively You can also use the Configuration Tool to create mailbox objects See section 2 2 8 Creating Referencing and Deleting Dynamically Created DSP BIOS Objects page 2 10 for a discussion of the benefits of creating objects with the Configuration Tool You specify the mailbox length and message size when you create a mailbox as shown in Example 4 11 Example 4 11 Creating a Mailbox MBX Handle MBX create msgsize mbxlength attrs Uns msgsize Uns mbxlength MBX Attrs attrs Void MBX delete mbx MBX Handle mbx MBX pend is used to read a message from a mailbox as shown in Example 4
265. ta Exchange Settings HST Host Channel Manager ZR PIP Buffered Pipe Manager QUE Atomic Queue Manager iU MBX Mailbox Manager amp 25 510 Stream Input and Output Manager m Chip Support Library DMA Resource Manager hDMAO Configuration F to McBSP Well MCBSP Resource Manager Well MCBSP Configuration bd Timer Timer Resource Manager Timer Configuration 1 1 LIE LI NENNEN EN About DSP BIOS 1 7 DSP BIOS Components Using the Configuration Tool DSP BIOS objects can be pre configured and bound into an executable program image Alternately a DSP BIOS program can create and delete objects at run time In addition to minimizing the target memory footprint by eliminating run time code and optimizing internal data structures creating static objects with the Configuration Tool detects errors earlier by validating object properties before program compilation The Configuration Tool generates files that link with code you write See section 2 2 Using the Configuration Tool page 2 3 for details 1 2 3 The DSP BIOS Analysis Tools The DSP BIOS Analysis Tools complement the Code Composer Studio environment by enabling real time program analysis of a DSP BIOS application You can visually monitor a DSP application as
266. ta is stored in a target buffer prior to being sent to the host This action helps ensure the integrity of the data and minimizes real time interference Provide interrupt safety You can call the routines defined in the user interface from within interrupt handlers Ensure correct utilization of the communication mechanism It is a requirement that only one datum at a time can be exchanged between the host and target using the JTAG interface The routines defined in the user interface handle the timing of calls into the lower level interfaces 3 7 3 4 RTDX Host OLE Interface 3 40 The OLE interface describes the methods that enable an OLE automation client to communicate with the RTDX host library The functions defined in the OLE interface Enable an OLE automation client to access the data that was recorded in an RTDX log file or is being buffered by the RTDX Host Library Q Enable an OLE automation client to send data to the target via the RTDX host library Real Time Data Exchange 3 7 4 RTDX Modes The RTDX host library provides the following modes of receiving data from a target application Non continuous The data is written to a log file on the host Noncontinuous mode should be used when you want to capture a finite amount of data and record it in a log file Continuous The data is simply buffered by the RTDX host library it is not written to a log file Continuous mode should be used when you wa
267. tain DSP BIOS provides support for several types of program threads with different priorities Each thread type has different execution and preemption characteristics The thread types from highest to lowest priority are Hardware interrupts HWI which includes CLK functions Q Software interrupts SWI which includes PRD functions 1 Tasks TSK m Background thread IDL These thread types are described briefly in the following section and discussed in more detail in the rest of this chapter Types of Threads The four major types of threads in a DSP BIOS program are 2 Hardware interrupts HWI Triggered in response to external asynchronous events that occur in the DSP environment An HWI function also called an interrupt service routine or ISR is executed after a hardware interrupt is triggered in order to perform a critical task that is subject to a hard deadline HWI functions are the threads with the highest priority in a DSP BIOS application HWIs should be used for application tasks that need to run at frequencies approaching 200 kHz and that need to be completed within deadlines of 2 to 100 microseconds See section 4 2 Hardware Interrupts page 4 11 for details about hardware interrupts Overview of Thread Scheduling Software interrupts SWI Patterned after hardware interrupt HWIs While HWIs are triggered by a hardware interrupt software interrupts are triggered by calling SWI functions from the prog
268. tartup sets up the PRD register enables the bit in the IER C6000 platform or the IMR C5400 platform for the timer chosen in the CLK Manager and finally starts the timer This macro is only expanded if you enable the CLK Manager in the Configuration Tool Program Generation 2 21 DSP BIOS Startup Sequence 2 6 1 PIP startup calls the notifyWriter function for each created pipe object SWI startup enables software interrupts HWI startup enables hardware interrupts by setting the GIE bit in the CSR on the C6000 platform or clearing the INTM bit in the ST1 register on the C5400 platform TSK startup enables the task scheduler and launches the highest priority task that is ready to run If the application has no tasks that are currently ready the TSK idle executes and calls IDL loop Once TSK startup is called the application begins and thus execution does not return from TSK startup or from BIOS start TSK startup runs only if the Task Manager is enabled in the Configuration Tool Execute the idle loop You can enter the idle loop in one of two ways In the first way the Task Manager is enabled The Task scheduler runs TSK idle which calls IDL loop In the second way the Task Manager is disabled and thus the call to BIOS start returns and a call to IDL loop follows By calling IDL loop the boot routine falls into the DSP BIOS idle loop forever At this point hardware and software interrupts can occur and preempt idle execution
269. te file for projects that should take advantage of the appropriate run time library To create a custom template for example to change the DSP MIPS on the C54x platform perform the following steps Modify the steps as appropriate for other DSP BIOS platforms 1 Invoke the Configuration Tool from outside the Code Composer Studio software via Start2Programs Code Composer Studio C5000 Configuration Tool From the File menu choose New In the New window choose c54xx cdb and click OK Set DSP MIPS CLKOUT to 200 and click OK Choose File2Save As In the Save As dialog box navigate to ti c5400 bios include 7 Inthe File Name box type c54x_200 cdb 4 Right click on Global Settings and choose Properties Program Generation 2 3 Using the Configuration Tool 8 9 In the Save as type box choose Seed files cdb and click Save In the Set Description dialog type a description and click OK 10 In the Configuration Tool choose FileExit 2 2 3 Setting Global Properties for a Module 1 When you choose a module by clicking on it the right side of the window shows the current properties for the module If you see a list of priorities instead of a property list right click on the module and choose Property value view If the right side of the window is gray this module has no global properties For help about a module click and then click on the module Right click the icon next to the
270. ted object By convention the object is assigned a set of default values if this parameter is NULL These default values are contained in the constant structure XXX ATTRS listed in the header files enabling you to first initialize a variable of type XXX Attrs and then selectively update its fields with application dependent attribute values before calling XXX create Sample code that creates a dynamic object using the TSK create is shown in Example 2 1 Creating and Referencing Dynamic Objects Example 2 1 include tsk h TSK Attrs attrs TSK Handle task attrs TSK ATTRS attrs name reader attrs priority TSK MINPRI task TSK create Fxn foo amp attrs The XXX create function passes back a handle that is an address to the task s object This handle is can then be passed as an argument when referencing for example deleting the object as shown in Example 2 2 Objects created with XXX create are deleted by calling the function XXX delete This frees the object s internal memory back to the system for later use Use the global constant XXX ATTRS to copy the default values update its fields and pass as the argument to the XXX create function Example 2 2 Deleting a Dynamic Object TSK delete task Dynamically created DSP BIOS objects allow for a program to adapt at runtime Program Generation 2 11 Files Used to Create DSP BIOS Programs 2 3 Files Used to Create DSP BIOS Pro
271. teracts with these different types of devices through drivers managed by the DEV module that use the DSP BIOS programming interface Device drivers are software modules that manage a class of devices For example two common classes are serial ports and parallel ports These modules follow a common interface provided by DEV so stream functions can make generic requests the drivers execute in whatever manner is appropriate for the particular class of devices Figure 6 2 Overview Figure 6 2 depicts the interaction between streams and devices The shaded area illustrates the material covered by this chapter the stream portion of this interaction handled by the SIO module Chapter 7 discusses the DEV module and the relationship of streams with devices Interaction Between Streams and Devices Application HWI Device Data pipes are used to buffer streams of input and output data These data pipes provide a consistent software data structure you can use to drive I O between the DSP device and all kinds of real time peripheral devices There is more overhead with a data pipe than with streams and notification is automatically handled by the pipe manager All I O operations on a pipe deal with one frame at a time although each frame has a fixed length the application can put a variable amount of data in each frame up to the length of the frame Separate pipes should be used for each data tr
272. than all other tasks in the system When a task is preempted by a software or hardware interrupt the task execution mode returned for that task by TSK stat is still TSK_RUNNING because the task will run when the preemption ends Thread Scheduling 4 39 Tasks Note Do not make blocking calls such as SEM pend or TSK sleep from within an IDL function Doing so prevents DSP BIOS Analysis Tools from gathering run time information L When the TSK_RUNNING task transitions to any of the other three states control switches to the highest priority task that is ready to run that is whose mode is TSK READY ATSK RUNNING task transitions to one of the other modes in the following ways 21 The running task becomes TSK TERMINATED by calling TSK exit which is automatically called if and when a task returns from its top level function After all tasks have returned the TSK Manager terminates program execution by calling SYS exit with a status code of 0 The running task becomes TSK BLOCKED when it calls a function for example SEM pend or TSK sleep that causes the current task to suspend its execution tasks can move into this state when they are performing certain I O operations awaiting availability of some shared resource or idling 2 The running task becomes TSK READY and is preempted whenever some other higher priority task becomes ready to run TSK setpri can cause this type of transition if the priority of the current
273. the c ti target examples folder where target represents your platform The trace log output for the code in Example 4 15 would be similar to that shown in Example 4 18 Example 4 15 Using the System Clock to Drive a Task 4 66 fe clktest c include lt std h gt include lt log h gt include lt clk h gt include lt tsk h gt extern LOG_Obj trace In this example a task goes to sleep for 1 sec and prints the time after it wakes up main Void main LOG printf amp trace Void taskFxn Uns ticks LOG printf amp trace Int TSK time LOG printf amp trace Ond ty TSK sleep ticks LOG printf amp trace Int TSK time Clktest example started Wn The time in task is d ticks ticks 1000 CLK countspms CLK getprd Lask going to sleep for 1 sec awake Time is d ticks Timers Interrupts and the System Clock Note Non pointer type function arguments to LOG printf need explicit type casting to Arg as shown in the following code example LOG printf amp trace Task d Done Arg id l Figure 4 18 Trace Log Output from Example 4 15 Log Name trace v 0 clktest example started 1 The time in task is 0 ticks 2 task going to sleep for 1 second 3 awake Time is 1000 ticks Thread Scheduling 4 67 Periodic Function Manager PRD and the System Clock 4
274. the stream is created either by the Configuration Tool or with SIO create with this value If the timeout expires before a buffer becomes available Dxx reclaim returns SYS ETIMEOUT In this situation SIO reclaim does not attempt to get anything from the device gt fromdevice queue SIO reclaim returns SYS ETIMEOUT and does not return a buffer 7 40 Closing Devices 7 14 Closing Devices A device is closed by calling SIO delete which in turn calls Dxx idle and Dxx close Dxx close closes the device after Dxx idle returns the device to its initial state which is the state of the device immediately after it was opened This is shown in Example 7 31 Example 7 31 Closing a Device Dxx idle 96 Int Dxx idle DEV Handle device Bool flush Dxx Handle objptr Dxx Handle device object Uns post count The only time we will wait for all pending data is when the device is in output mode and flush was not requested if device mod DEV OUTPUT amp amp flush first make sure device is started if device is not started amp amp device has received data start the device wait for all output buffers to be consumed by the output HWI We need to maintain a count of how many buffers are returned so we can set the semaphore later AZ post_count 0 while QUE_empty device gt todevice EM_pend objptr gt sync SY
275. the Statistics View Analysis Tool calculates the average on the host Calling the STS_add operation updates the statistics object of the data series being studied For example you might study the pitch and gain in a software interrupt analysis algorithm or the expected and actual error in a closed loop control algorithm DSP BIOS statistics objects are also useful for tracking absolute CPU use of various routines during execution By bracketing appropriate sections of the program with the STS_set and STS delta operations you can gather real time performance statistics about different portions of the application You can view these statistics in real time with the Statistics View as shown in Figure 3 4 To access the Statistics View select DSP BIOS Statistics View Figure 3 4 Statistics View Panel Statistics View Sn loadPrd stepPrd PRD swi KNL_swi audioS wi IDL_busyO bj Count Total Max Average 1931 0 0 0 1 0 0 0 1931 71200064 00 inst 102572 00 inst 35872 12 inst 15453 81301080 00 inst 102764 00 inst 5261 18 inst 1287 2693364 00 inst 3236 00 inst 2092 75 inst 635928 1217 1 0 00191374 Instrumentation APIs Although statistics are accumulated in 32 bit variables on the target they are accumulated in 64 bit variables on the host When the host polls the target for real time statistics it resets the variables on the target This minimizes space requirements on the target while allowing you to keep statistics f
276. time data exchange settings Semaphore manager Stream I O manager Statistics object manager Software interrupt manager System services manager Trace manager Multitasking manager 1 2 2 The DSP BIOS Configuration Tool The Configuration Tool has an interface similar to the Windows Explorer and has multiple roles 2 It lets you set a wide range of parameters used by the DSP BIOS real time library at run time 1 6 DSP BIOS Components 1 It serves as a visual editor for creating run time objects that are used by the target application s DSP BIOS API calls These objects include software interrupts tasks I O streams and event logs You also use this visual editor as shown in Figure 1 2 to set properties for these objects It lets you set parameters for the Chip Support Library CSL and modules See the TMS320C6000 Chip Support Library SPRU401 for more information Figure 1 2 Configuration Tool Interface System Global Settings h MEM Memory Section Manager SYS System Settings le Instrumentation LOG Event Log Manager Bg STS Statistics Object Manager Scheduling zi CLK Clock Manager PAD Periodic Function Manager WV Hardware Interrupt Service Routine Mar W SWI Software Interrupt Manager Task Manager GD IDL Idle Function Manager ge Synchronization SEM Semaphore Manager A LCK Resource Lock Manager Input Output ff RTDX Real Time Da
277. treamtab 1 streaml while mask SIO select streamtab 2 0 0 I O would block do something else if mask amp Ox1 service streamO0 if mask amp 0 2 service 1 Streaming Data to Multiple Clients 7 7 Streaming Data to Multiple Clients A common problem in multiprocessing systems is the simultaneous transmission of a single data buffer to multiple tasks in the system Such multi cast transmission or scattering of data can be done easily with DSP BIOS SIO streams Consider the situation in which a single processor sends data to four client processors Streaming data between processors in this context is somewhat different from streaming data to or from an acquisition device such as an A D converter in that a single buffer of data must go to one or more clients The DSP BIOS SIO functions SIO get SIO put are used for data I O SIO put automatically performs a buffer exchange between the buffer already at the device level and the application buffer As a result the user no longer has control over the buffer since it is enqueued for I O and this I O happens asynchronously at the interrupt level This forces the user to copy data in order to send it to multiple clients This is shown in Example 7 15 Example 7 15 Using SIO put to Send Data to Multiple Clients SIO put inStream Ptr amp bufA npoints fill bufA with data for all data points bufB
278. ts Real Time Graphics Tools from Quinn Curtis 4 Microsoft Excel Alternatively you can develop your own Visual Basic or Visual C applications Instead of focusing on obtaining the data you can concentrate on designing the display to visualize the data in the most meaningful way Instrumentation 3 37 Real Time Data Exchange 3 7 1 RTDX Applications 3 7 2 RTDX Usage RTDX is well suited for a variety of control servo and audio applications For example wireless telecommunications manufacturers can capture the outputs of their vocoder algorithms to check the implementations of speech applications Embedded control systems also benefit from RTDX Hard disk drive designers can test their applications without crashing the drive with improper signals to the servo motor Engine control designers can analyze changing factors like heat and environmental conditions while the control application is running For all of these applications you can select visualization tools that display information in a way that is most meaningful to you RTDX can be used with or without DSP BIOS The target programs in the volume4 hostio1 and hostio2 examples in the c ti tutorial folder tree use RTDX in conjunction with various DSP BIOS modules The examples in the folder tree and the c tiiexamples target rtdx folder tree use RTDX without DSP BIOS RTDX is available with the PC hosted Code Composer
279. ttrs attributes Some of these attributes can change during program execution but typically they contain the values assigned when the object was created SWI getattrs swi attrs Thread Scheduling 4 21 Software Interrupts 4 3 2 Setting Software Interrupt Priorities in the Configuration Tool There are different priority levels among software interrupts You can create as many software interrupts as your memory constraints allow for each priority level You can choose a higher priority for a software interrupt that handles a thread with a shorter real time deadline and a lower priority for a software interrupt that handles a thread with a less critical execution deadline To set software interrupt priorities with the Configuration Tool follow these steps 1 In the Configuration Tool highlight the Software Interrupt Manager Notice SWI objects in the right half of the window shown in Figure 4 3 They are organized by priority in priority level folders If you do not see a list of SWI objects in the right half of the window right click on the SWI Manager then choose View Ordered collection view Figure 4 3 Software Interrupt Manager SWI Software Interrupt Manager objects by priority C Priority 14 Highest G Priority 13 G Priority 12 G Priority 11 Priority 10 riority 9 riority 8 riority 7 riority B riority 5 4 riority 3 W Swit W 513 G Priority 2 G Priority 1 W Swit W swi2 5 28 Prior
280. tween the target and files on the host In DSP BIOS Analysis Tools you bind these channels to host files and start them DSP BIOS includes a host I O module HST that makes it easy to transfer data between the host computer and target program Each host channel is internally implemented using an SIO stream object To use a host channel the program calls getstream to get the corresponding stream handle and then transfers the data using SIO calls on the stream You configure host channels or HST objects for input or output using the Configuration Tool Input channels transfer data from the host to the target and output channels transfer data from the target to the host Streaming I O and Device Drivers 7 27 Device Driver Template 7 9 Device Driver Template Since device drivers interact directly with hardware the low level details of device drivers can vary considerably However all device drivers must present the same interface to SIO In the following sections an example driver template called Dxx is presented The template contains mainly C code for higher level operations and pseudocode for lower level operations Any device driver should adhere to the standard behavior indicated for the Dxx functions You should study the Dxx driver template along with one or more actual drivers You can also refer to the functions in the TMS320 DSP BIOS Reference Guide for your platform where xx denotes any two letter c
281. ubject to name mangling Since function overloading is accomplished through name mangling function overloading has limitations for functions that are called from within the Configuration Tool Only one version of an overloaded function can appear within the extern C block The code in Example 2 5 would result in an error Example 2 5 Function Overloading Limitation extern C Int addNums Int x Int y Int addNums Int x Int y Int z error only one version of addNums is allowed While you can use name overloading in your DSP BIOS applications only one version of the overloaded function can be called from the Configuration Tool Default parameters is a feature that is not available for functions called from the Configuration Tool C allows you to specify default values for formal parameters within the function declaration However a function called from the Configuration Tool must provide parameter values If no values are specified the actual parameter values are undefined 2 7 3 Calling Class Methods from the Configuration Tool Often the function that you want to reference within the Configuration Tool is the member function of a class object It is not possible to call these member functions directly from the Configuration Tool but it is possible to accomplish the same action through wrapper functions By writing a wrapper function which accepts a class instance as a parameter you can invoke t
282. ue fails The following code does not operate as expected when compiled using the small model extern PIP Obj inputObj static PIP_Obj input amp inputObj ERROR if PIP getReaderNumFrames input 2 Place all objects adjacent to bss If all objects are placed at the end of the bss section and the combined length of the objects and the bss data is less than 32K bytes you can reference these objects as if they were allocated within the bss section extern PIP Obj inputObj if PIP getReaderNumFrames amp inputObj Program Generation 2 9 Using the Configuration Tool You can guarantee this placement of objects by using the Configuration Tool as follows a Declare a new memory segment by inserting a MEM object with the MEM Manager and setting its properties i e the base and length or use one of the preexisting data memory MEM objects b Place all objects that are referenced by small model code in this memory segment c Place Uninitialized Variables Memory bss in this same segment by right clicking on the MEM Manager and choosing Properties 2 2 7 2 Referencing Static DSP BIOS Objects in the Large Model C6000 Platform Only In the large model all compiled code accesses data by first loading the entire 32 bit address into an address register and then using the indirect addressing capabilities of the LDW instruction to load the data For example MVKL _x move low 16 bits of _x s
283. ueue SYS abort queue error Mn dequeue message msg QUE get amp queue print value LOG printf amp trace read c msg gt val free msg EM free 0 msg sizeof MsgObj Void writer Msg msg Int for i20 lt NUMMSGS allocate msg msg MEM alloc 0 sizeof MsgObj 0 if msg MEM ILLEGAL SYS abort Memory allocation failed Nn fill in value msg val i a LOG printf amp trace writing c msg val enqueue message QUE put amp queue msg Note Non pointer type function arguments to log printf need explicit type casting to Arg as shown in the following code example LOG printf amp trace Task d Done Arg id Queues Figure 5 3 Trace Window Results from Example 5 18 Memory and Low level Functions 5 19 Chapter 6 Input Output Overview and Pipes This chapter provides an overview on data transfer methods and discusses pipes in particular Topic Page 6 1 WO Overview nee en a 2 6 2 Comparing Pipes and Streams 5 4 6 3 Data Pipe Manager PIP 5 5 6 4 Host Channel Manager HST 5 12 6 5 I O Performance 1550 5 6 14 6 1 VO Overview 6 1 Figure 6 1 6 2 Overview In
284. ueue the frame addr contains the address of the stream buffer size contains the logical size of the stream buffer The logical size can be less than the physical buffer size misc is an extra field which is reserved for use by a device arg is an extra field available for you to associate information with a particular frame of data This field should be preserved by the device Example 7 21 Streaming DEV Structures Device driver functions take a DEV Handle as their first or only parameter followed by any additional parameters The DEV Handle is a pointer to a DEV Obj which is created and initialized by SIO create and passed to Dxx open for additional initialization Among other things a DEV Obj contains pointers to the buffer queues that SIO and the device use to exchange buffers All driver functions take a DEV Handle as their first parameter The DEV Handle Structure typedef DEV Obj DEV Handle typedef struct DEV Obj QUE_Handle todevice QUE_Handle fromdevice Uns bufsize Uns nbufs Int segid Int mode Int devid Ptr params Ptr object DEV_Fxns fxns Uns timeout DEV Obj Example 7 21 has the following parameters todevice is used to transfer Frame frames to the device In the SIO STANDARD DEV STANDARD streaming model SIO put puts full frames on this queue and SIO get puts empty frames here In the SIO ISSUERECLAIM DEV_ISSUERECLAIM streaming mo
285. uide for your platform that lists DSP BIOS functions and the threads from which each function can be called Note SWI handlers can call any DSP BIOS function that does not block For example SEM pend can make a task block so SWI handlers cannot call SEM pend or any function that calls SEM pend for example MEM alloc TSK sleep On the other hand an SWI handler must complete before any blocked task is allowed to run There might be situations where the use of a task might fit better with the overall system design in spite of any additional overhead involved 4 3 7 Saving Registers During Software Interrupt Preemption When a software interrupt preempts another thread DSP BIOS preserves the context of the preempted thread by automatically saving all of the CPU registers shown in Table 4 4 onto the system stack Table 4 4 CPU Registers Saved During Software Interrupt C54x Platform C55x Platform C6000 Platform e e ag ah al 2 ar3 ar4 ar5 ar7 bg bh bk bl brc pmst real rea rptc 0 rsa ac2 rsa0 b16 b31 trn1 a16 a31 5 rsat ead C64x only C64x only st0 brc1 510 2 b0 99 y CSR 511 brs1 511 AMR xar3 t csr st2 xard trn rea0 st3 Your SWI function does not need to save and restore any of these registers even if the SWI function is written in assembly Thread Scheduling 4 31 Software Interrupts Howev
286. uld not be made from the main routine because the BIOS start initialization has not yet run BIOS start is responsible for enabling global interrupts configuring and starting the timer and enabling the schedulers so that DSP BIOS threads can start executing Therefore DSP BIOS calls that are not appropriate from main are APIs which assume hardware interrupts and the timer are enabled or APIs that make scheduling calls that could block execution For example functions such as CLK gethtime and CLK getltime should not be called from main because the timer is not running HWI disable and HWI enable should not be called because hardware interrupts are not globally enabled Potentially blocking calls such as SEM pend or MBX pend should not be called from main because the scheduler is not initialized Scheduling calls such as TSK disable TSK enable SWI disable or SWI enable are also not appropriate within main BIOS init which runs before main is responsible for initialization of the MEM module Therefore it is okay to call dynamic memory allocation functions from main Not only are the MEM module functions allowed MEM alloc MEM free etc but APIs for dynamic creation and deletion of DSP BIOS objects such as TSK create and TSK delete are also allowed While blocking calls are not permitted from main scheduling calls that make a DSP BIOS thread ready to run are permitted These are calls such as SEM post or SWI post If such a call is ma
287. ume as Example 4 5 does that a task s environment is always set by the Create function Example 4 5 Creating a Task Object Tasks define CONTEXTSIZE Void doCreate task TSK Handle task Ptr context context MEM alloc O0 TSK setenv task context Void doDelete task TSK Handle task Ptr context context TSK getenv task MEM free 0 context Void doSwitch from to TSK Handle from TSK Handle to Ptr context static Int first TRUE if first i first FALSE return context TSK getenv from context context TSK getenv to Void doExit Void TSK_Handle usrHandle get task handle usrHandle TSK self hardware registers hardware registers context size of additional context CONTEXTSIZE 0 set task environment get register buffer CONTEXTSIZE get register buffer save registers get register buffer restore registers if needed perform user defined exit steps Note Non pointer type function arguments to LOG printf need explicit type casting to Arg as shown in the following code example LOG printf amp trace Task d Done Arg id Thread Scheduling 4 43 Tasks 4 4 6 Task Yielding for Time Slice Scheduling Exampl not req graph e 4 6 demonstrates an implementation of a time slicing scheduling model that ca
288. uration file to support the production board and test your program on the board Using the Configuration Tool 2 2 Using the Configuration Tool The Configuration Tool is a visual editor with an interface similar to the Windows Explorer It allows you to initialize data structures and set various parameters used by DSP BIOS When you save a file the Configuration Tool creates assembly source and header files and a linker command file to match your settings When you build your application these files are linked with your application programs See the Configuration Tool lessons in the DSP BIOS section of the online help system for more details on using the Configuration Tool 2 2 1 Creating a New Configuration File 1 In the Code Composer Studio program open the Configuration Tool by choosing File2New DSP BIOS Config Alternatively you can open the Configuration Tool outside of the Code Composer Studio program from the Start menu 2 Choose the appropriate template and click OK 2 2 2 Creating a Custom Template You can add a custom template or seed file by creating a configuration file and storing it in your include folder This saves time by allowing you to define configuration settings for your hardware once Then you can reuse the file as a template For example to build DSP BIOS programs for a fixed or floating point DSP you can use the settings provided Or you can instruct the Configuration Tool to create a new custom templa
289. urbation and recording sufficient information Limited instrumentation provides inadequate detail but excessive instrumentation perturbs the measured system to an unacceptable degree DSP BIOS provides a variety of mechanisms that allow you to control precisely the balance between intrusion and information gathered In addition the DSP BIOS instrumentation operations all have fixed short execution times Since the overhead time is fixed the effects of instrumentation are known in advance and can be factored out of measurements Instrumentation Performance 3 2 Instrumentation Performance When all implicit DSP BIOS instrumentation is enabled the CPU load increases less than one percent in a typical application Several techniques have been used to minimize the impact of instrumentation on application performance Instrumentation communication between the target and the host is performed in the background IDL thread which has the lowest priority so communicating instrumentation data does not affect the real time behavior of the application From the host you can control the rate at which the host polls the target You can stop all host interaction with the target if you want to eliminate all unnecessary external interaction with the target The target does not store Execution Graph or implicit statistics information unless tracing is enabled You also have the ability to enable or disable the explicit instrumentation of the a
290. us block of free memory large enough to satisfy the request This occurs even if the total amount of memory in free memory blocks is greater than the amount requested Memory Management To minimize memory fragmentation you can use separate memory segments for allocations of different sizes as shown in Figure 5 1 Figure 5 1 Allocating Memory Segments of Different Sizes Segment Target Memory Allocate small 0 blocks from one segment for messages Allocate large blocks from another segment for streams Note To minimize memory fragmentation allocate smaller equal sized blocks of memory from one memory segment and larger equal sized blocks of memory from a second segment 5 1 8 MEM Example Example 5 7 and Example 5 8 use the functions MEM stat MEM alloc and MEM free to highlight several issues involved with memory allocation Figure 5 2 shows the trace window results from Example 5 7 or Example 5 8 In Example 5 7 and Example 5 8 memory is allocated from IDATA and IDRAM memory using MEM alloc and later freed using MEM free printmem is used to print the memory status to the trace buffer The final values for example after freeing should match the initial values Memory and Low level Functions 5 7 Memory Management Example 5 7 Memory Allocation C5000 Platform memtest c This code allocates frees memory from different memory segments by include std h include log h inclu
291. verhead of transferring this sequence to the host would interfere with program operation DSP BIOS provides the TRC Trace Manager module for controlling the data gathering mechanisms provided by the other modules The TRC module controls which events and statistics are captured either in real time by the target program or interactively through the DSP BIOS Analysis Tools Controlling data gathering is important because it allows you to limit the effects of instrumentation on program behavior ensure that LOG and STS objects contain the necessary information and start or stop recording of events and data values at run time 3 3 1 Explicit versus Implicit Instrumentation 3 6 The instrumentation operations are designed to be called explicitly by the application The LOG module operations allow you to explicitly write messages to any log The STS module operations allow you to store statistics about data variables or system performance The TRC module allows you to enable or disable log and statistics tracing in response to a program event Instrumentation APIs The LOG and STS APIs are also used internally by DSP BIOS to collect information about program execution These internal calls in DSP BIOS routines provide implicit instrumentation support As a result even applications that do not contain any explicit calls to the DSP BIOS instrumentation APIs can be monitored and analyzed using the DSP BIOS Analysis Tools For example the exe
292. ves to search the necessary libraries including a DSP BIOS RTDX and a run time support library The run time support library is created from rts src which contains the source code for the run time support functions These are standard ANSI functions that are not part of the C language such as functions for memory allocation string conversion and string searches A number of memory management functions that are defined within rts src are also defined within the DSP BIOS library These are malloc free memalign calloc and realloc The libraries support different implementations For example the DSP BIOS versions are implemented with the MEM module and therefore make use of the DSP BIOS API calls MEM alloc and MEM free Because the DSP BIOS library provides some of the same functionality found within the run time support library the DSP BIOS linker command file includes a special version of the run time support library called rtsbios that does not include the files shown in Table 2 2 Table 2 2 Files Not Included in rtsbios C54x Platform C55x Platform C6000 Platform memory c memory c memory c autoinit c boot c sysmem c boot c autoinit c boot c In many DSP BIOS projects it is necessary to use the x linker switch in order to force the rereading of libraries For example if printf references malloc and malloc has not already been linked in from the DSP BIOS library it forces the DSP BIOS library to be searched again in order to r
293. ware interrupt that runs the reader writer function Data Pipe Manager PIP Module When the HWI routine finishes filling up reading a frame and calls PIP put PIP free the pipe s notify function can be used to automatically post a software interrupt In this case rather than polling the pipe for frame availability the reader writer function runs only when the software interrupt is triggered that is when frames are available to be read written Such a function would not need to check for the availability of frames in the pipe since it is called only when data is ready As a precaution the function can still check whether frames are ready and if not cause an error condition as in the following example code if PIP getReaderNumFrames amp readerPipe 0 error reader function should not have been posted Hence the notify function of pipe objects can serve as a flow control mechanism to manage I O to other threads and hardware devices 6 3 4 Calling Order for PIP APIs Each pipe object internally maintains a list of empty frames and a counter with the number of empty frames on the writer side of the pipe and a list of full frames and a counter with the number of full frames on the reader side of the pipe The pipe object also contains a descriptor of the current writer frame that is the last frame allocated and currently being filled by the application and the current reader frame that is the last
294. ws NI CPUload 1 grr 190 3 4 3 Hardware Interrupt Count and Maximum Stack Depth You can track the number of times an individual HWI function has been triggered by using the Configuration Tool to set the monitor parameter for an HWI object to monitor the stack pointer An STS object is created automatically for each hardware ISR that is monitored as shown in Figures 3 11 and 3 12 Figure 3 11 Monitoring Stack Pointers C5000 platform Default Configuration Monitoring isr IVT IVT 00 br isr gt ist 00 br isr gt isr 02 br isr gt isr 02 br stub gt stub isr 2n br isr gt 2n br isr gt isr Implicit DSP BIOS Instrumentation Figure 3 12 Monitoring Stack Pointers C6000 platform Default Configuration Monitoring isr IST IST 00 bisr gt iSr 00 bisr 1510 20 b isr isr 20 b stub gt stub isr 20n b isr gt isr 20n b isr isr For hardware interrupts that are not monitored there is no overhead control passes directly to the HWI function For interrupts that are monitored control first passes to a stub function generated by the Configuration Tool This function reads the selected data location passes the value to the selected STS operation and finally bran
295. xx Handle device object register the ready semaphore objptr gt ready sem if device gt mode DEV INPUT amp amp device gt model DEV STANDARD amp amp device is not started start the device return TRUE if device is ready return TRUE if device gt fromdevice has a frame or device won t block If the mode is DEV_INPUT the streaming model is DEV STANDARD If the device has not been started already the device is started This is necessary since in the DEV STANDARD streaming model SIO select can be called by the application before the first call to SIO get Streaming I O and Device Drivers 7 43 Device Ready The device s ready semaphore handle is set to the semaphore handle passed in by SIO select To better understand Dxx ready consider the following details of SIO select SIO select can be summarized in pseudocode as shown in Example 7 33 Example 7 33 SIO Select Pseudocode 7 44 STO select Uns SIO select streamtab n timeout SIO Handle streamtab array of streams Int n number of streams Uns timeout ad passed to SEM pend Int i4 Uns mask 1 used to build ready mask Uns ready 0 bit mask of ready streams SEM Handle sem local semaphore SIO Handle stream pointer into streamtab For efficiency the real SIO select doesn t call SEM
296. y an optional parameter If you use an optional parameter you specify the information within the brackets Unless the square brackets are in a bold typeface do not enter the brackets themselves 21 Throughout this manual 54 can represent the two digit numeric appropriate to your specific DSP platform If your DSP platform is C62x based substitute 62 each time you see the designation 54 For example DSP BIOS assembly language API header files for the C6000 platform will have a suffix of h62 For a C64x or C55x DSP platform substitute either 64 or 55 for each occurrence of 54 Also each reference to Code Composer Studio C5000 can be substituted with Code Composer Studio C6000 depending on your DSP platform 1 Information specific to a particular device is designated with one of the following icons 9 9 Related Documentation From Texas Instruments The following books describe TMS320 devices and related support tools To obtain a copy of any of these TI documents call the Texas Instruments Literature Response Center at 800 477 8924 When ordering please identify the book by its title and literature number TMS320C6000 DSP BIOS Application Programming Interface API Reference Guide literature number SPRU403 describes the DSP BIOS functions which are alphabetized by name In addition there are reference sections that describe the overall capabilities of each module and appendices that provide tables that are useful t
297. y an underscore must conform to the following rules Qj The first argument is passed in register AR2 The second argument is passed in register A The return value is passed in register A Note The above rules do not apply to user functions called by TSK objects All user functions both C and assembly called by TSK objects follow C register conventions L On the 54 platform when a C function or an assembly function whose function name is preceded by an underscore is executing the CPL Compiler Mode bit is required to be set When an assembly function one whose name is not preceded by an underscore begins executing the CPL bit is clear and must be clear upon return For more information on C register conventions see the optimizing compiler user s guide for your platform Program Generation 2 27 2 9 Calling DSP BIOS APIs from Main The main routine in a DSP BIOS application is for user initialization purposes such as configuring a peripheral or enabling individual hardware interrupts It is important to recognize that main does not fall into any of the DSP BIOS threads types HWI SWI TSK or IDL and that when program execution reaches main not all of the DSP BIOS initialization is complete This is because DSP BIOS initialization takes place in two phases during BIOS init which runs before main and during BIOS start which runs after your program returns from main Certain DSP BIOS API calls sho
Download Pdf Manuals
Related Search
Related Contents
deTec4 Core Barriera fotoelettrica di sicurezza Mountain Bike Technical Article Goodman Technical Manual BRK electronic 4120B Smoke Alarm User Manual PICADORA - Westim SpA Manual Español SM BLS-03-BK / WH Manual de Instrucciones - Ficha Tecnica - CE Copyright © All rights reserved.
Failed to retrieve file