Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP



Similar documents
Using C to Access Data Stored in Program Memory on the TMS320C54x DSP

SDLS068A DECEMBER 1972 REVISED OCTOBER Copyright 2001, Texas Instruments Incorporated

Using Code Coverage and Multi-event Profiler in Code Composer Studio v2.3 for Robustness and Efficiency Analyses

Floating Point C Compiler: Tips and Tricks Part I

Motor Speed Measurement Considerations When Using TMS320C24x DSPs

CUSTOM GOOGLE SEARCH PRO. User Guide. User Guide Page 1

Filter Design in Thirty Seconds

Controlling TAS5026 Volume After Error Recovery

SN54165, SN54LS165A, SN74165, SN74LS165A PARALLEL-LOAD 8-BIT SHIFT REGISTERS

Designing Gain and Offset in Thirty Seconds

TMS320C67x FastRTS Library Programmer s Reference

Managing Code Development Using CCS Project Manager

Binary Search Algorithm on the TMS320C5x

Standard Linear & Logic Semiconductor Marking Guidelines

How To Close The Loop On A Fully Differential Op Amp

TI and ibiquity Introduce Industry s Lowest Cost Single-Chip AM/FM and HD Radio Baseband John Gardner Digital Radio Marketing Manager

Data sheet acquired from Harris Semiconductor SCHS067B Revised July 2003

Data sheet acquired from Harris Semiconductor SCHS087D Revised October 2003

Design Note DN304. Cebal CCxxxx Development Tools USB Driver Installation Guide By Åsmund B. Bø. Keywords. 1 Introduction

IMPORT/EXPORT CUSTOMER REVIEWS. User Guide. User Guide Page 1

Using the Scripting Utility in the Code Composer Studio Integrated Development Environment

August 2001 PMP Low Power SLVU051

SEO Suite Pro. User Guide

Current-Transformer Phase-Shift Compensation and Calibration

Pressure Transducer to ADC Application

Wireless Subwoofer TI Design Tests

1. Installation Instructions

Data sheet acquired from Harris Semiconductor SCHS020C Revised October 2003

Application Report. 1 Description of the Problem. Jeff Falin... PMP Portable Power Applications ABSTRACT

Design Note DN004. Folded Dipole Antenna for CC25xx By Audun Andersen. Keywords. 1 Introduction CC2500 CC2550 CC2510 CC2511

SEO Meta Templates. Magento Extension. User Guide. SEO Meta Templates

Multi-Transformer LED TV Power User Guide. Anderson Hsiao

Application Note AN107

Important Notice. All company and brand products and service names are trademarks or registered trademarks of their respective holders.

Monitoring TMS320C240 Peripheral Registers in the Debugger Software

THE RIGHT-HALF-PLANE ZERO --A SIMPLIFIED EXPLANATION

LM5030 LM5030 Application: DC - DC Converter Utilizing the Push-Pull Topology

EDI s x32 MCM-L SRAM Family: Integrated Memory Solution for TMS320C3x DSPs


Code Composer Studio Getting Started Guide

APPLICATION NOTE BUILDING A QAM MODULATOR USING A GC2011 DIGITAL FILTER CHIP

IMPORT/EXPORT COUPON/SHOPPING CART RULES. User Guide. User Guide Page 1

IMPORT / EXPORT PRODUCTS

Texas Instruments. FB PS LLC Test Report HVPS SYSTEM AND APPLICATION TEAM REVA

Motorola 8- and 16-bit Embedded Application Binary Interface (M8/16EABI)

6 Output With 1 kω in Series Between the Output and Analyzer Output With RC Low-Pass Filter (1 kω and 4.7 nf) in Series Between the Output

EDI s x32 MCM-L SRAM Family: Integrated Memory Solution for TMS320C4x DSPs

News Extension 2.2 User Guide

TVP5146 SCART and OSD


PCIe XMC x8 Lane Adapter

Evaluating the complex configuration options of the Texas Instruments advanced fuel gauges can be

Application Report. 1 Introduction. 2 Resolution of an A-D Converter. 2.1 Signal-to-Noise Ratio (SNR) Harman Grewal... ABSTRACT

Calculating Gain for Audio Amplifiers

High-Speed Gigabit Data Transmission Across Various Cable Media at Various Lengths and Data Rate

Analysis of Filter Coefficient Precision on LMS Algorithm Performance for G.165/G.168 Echo Cancellation

NVIDIA GRID 2.0 ENTERPRISE SOFTWARE

Adapting the PowerPC 403 ROM Monitor Software for a 512Kb Flash Device

TMS320C3x/C4x Assembly Language Tools User s Guide

Software Development Systems Customer Support Guide

1. Installation Instructions

Analysis Toolkit v1.3 for Code Composer Studio User s Guide

etpu Host Interface by:

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Application Note: AN00141 xcore-xa - Application Development

Application Report SLVA051

December 2002, ver. 1.0 Application Note 285. This document describes the Excalibur web server demonstration design and includes the following topics:

White Paper on Decision of Make vs. Buy of ISM RF Module Written by Bruce Ulrich October 2006

SN28838 PAL-COLOR SUBCARRIER GENERATOR

RETRIEVING DATA FROM THE DDC112

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

APPLICATION BULLETIN

AMC1100: Replacement of Input Main Sensing Transformer in Inverters with Isolated Amplifier

Smart Battery Module with LEDs and Pack Supervisor

Intel RAID Controller Troubleshooting Guide

3. Programming the STM32F4-Discovery

How To Fix An Lmx9838 Bluetooth Serial Port Module With Bluetooth (Bluetooth 2) From A Bluetooth Bluetooth 4.2 Device With A Bluembee 2.2 Module

µa7800 SERIES POSITIVE-VOLTAGE REGULATORS

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

Expedite for Windows Software Development Kit Programming Guide

SatTerm-G SOFTWARE MANUAL FOR A3LA-IG

DUAL MONITOR DRIVER AND VBIOS UPDATE

The C Programming Language course syllabus associate level

ZigBee Sensor Monitor SWRU157D 2008 Low-Power RF

Optical Implementation Using IEEE-1394.b

SN54F157A, SN74F157A QUADRUPLE 2-LINE TO 1-LINE DATA SELECTORS/MULTIPLEXERS

AN3354 Application note

Understanding PIC WEB boards and how to use Microchip's TCP-IP Stack. Rev.A, April Copyright(c) 2008, OLIMEX Ltd, All rights reserved

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

13. Publishing Component Information to Embedded Software

DC/DC LED Lighting Developer s Kit Hardware

How To Make A Two Series Cell Battery Pack Supervisor Module

AN3998 Application note

Signal Conditioning Wheatstone Resistive Bridge Sensors

SN54HC157, SN74HC157 QUADRUPLE 2-LINE TO 1-LINE DATA SELECTORS/MULTIPLEXERS

WHAT DESIGNERS SHOULD KNOW ABOUT DATA CONVERTER DRIFT

HP AppPulse Mobile. Adding HP AppPulse Mobile to Your Android App

Application Report. Jim Patterson... Americas Field Applications

How To Write To An Eeprom Memory On A Flash Memory On An Iphone Or Ipro Memory On Microsoft Flash Memory (Eeprom) On A Microsoft Microsoft Powerbook (Ai) 2.2.2

UM0985 User manual. Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software. Introduction

Transcription:

Application Report SPRA380 April 2002 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP David M. Alter DSP Applications - Semiconductor Group ABSTRACT Efficient utilization of available memory in a TMS320C24x DSP sometimes requires the placement of data in program space memory (as opposed to data space memory). In particular, the on-chip flash (or ROM) in the program space provides a large nonvolatile memory for storing constant arrays, look-up tables, and string tables. However, accessing this data using the C programming language is problematic, since the C-compiler provides no mechanism for accessing program space. This application note presents a C-callable library of six assembly code functions for accessing data in program space memory. These functions work with all members of the C24x DSP generation, including all C/F24x, LC/LF240x, and LC/LF240xA devices. Note: These functions cannot be used to program the on-chip flash memory. Programming the flash requires using one of several different flash programming utilities. These utilities are available on the Texas Instruments (TI) website, www.ti.com. Contents Introduction...2 The Code Download...3 Download Package Contents...3 The PFUNC Code Library...3 Example of PFUNC Library Use...4 Constructing the Program Memory Data Values...5 References...6 Appendix A. PFUNC Function Library Technical Reference...7 Table 1. Table 2. Tables of Code Download Files...3 PFUNC Library Functions...3 TMS320C24x and C24x are trademarks of Texas Instruments. Other trademarks are the property of their respective owners. 1

Introduction On TMS320C24x devices, it is sometimes desirable to place data in program space memory rather than in data space memory. In particular, the on-chip flash (or ROM) in the program space provides a large nonvolatile memory for storing constant arrays, look-up tables, and string tables. When working in the C programming language, however, it is not sufficient to simply link the data into the program space, as the C-compiler expects all constants (and variables) to be in data space memory. No mechanism exists in the C-compiler for accessing program space memory, other than at code-initialization time. One method for overcoming this problem is to copy the data from the flash (or ROM) into data space RAM as part of the code-initialization process. This could be done using a custom assembly code routine, or the C-compiler does provide some built-in capability for initializing global and static variables and constants. The C-code could then access the copies of the data in the data space during code execution. The downside of this approach is that each word of data now consumes two words of memory: the original data in the flash, and a copy of the data in data space RAM. Large arrays of constants or string tables can quickly use up the valuable on-chip RAM available in C24x generation DSPs. A better approach is to temporarily copy the value of interest from the flash to data RAM only when it is needed at run time. C-code can then access the temporary copy (e.g., as a local variable located on the software stack), and dispatch the value as required. This approach avoids the double memory usage problem at the expense of using some CPU clock cycles to temporarily copy the data from program memory each time the value is accessed at run time. This application reports utilizes this temporary copy method, and presents a C-callable library of six assembly code functions for accessing data in program memory. A simple C-code example illustrating their usage is also provided. These functions work with all members of the C24x DSP generation, including all C/F24x, LC/LF240x, and LC/LF240xA devices. 2 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

The Code Download Download Package Contents A code download accompanies this application report. This download may be obtained from the Texas Instruments website, www.ti.com. A description of each file in the download is given in Table 1. File Name.pfunc\make.bat.\pfunc\include\pfunc.h.\pfunc\lib\pfunc.lib.\pfunc\src\blkread.asm.\pfunc\src\blkwrite.asm.\pfunc\src\strread.asm.\pfunc\src\strwrite.asm.\pfunc\src\wordread.asm.\pfunc\src\wordwrite.asm.\example\example.mak.\example\main.c.\example\table.asm.\example\lf2407a.cmd.\example\example.map.\example\example.out Table 1. of Code Download Files Windows batch file for building the PFUNC library C language header file for PFUNC library functions the function library source file for PFUNC_blkRead() function source file for PFUNC_blkWrite() function source file for PFUNC_strRead() function source file for PFUNC_strWrite() function source file for PFUNC_wordRead() function source file for PFUNC_wordWrite() function C24x Code Composer v4.1x project file for the example main() function for the example assembly code data table file for the example TMS320LF2407A DSP linker command file for the example.map file from the prebuilt example prebuilt example executable The PFUNC Code Library Six C-callable functions for manipulating data stored in program space memory have been hand-coded in assembly language for efficiency. These functions are listed in Table 2. Table 2. PFUNC Library Functions Function Name PFUNC_blkRead() PFUNC_blkWrite() PFUNC_strRead() PFUNC_strWrite() PFUNC_wordRead() PFUNC_wordWrite() copies a block from program space to data space copies a block from data space to program space copies a string from program space to data space copies a string from data space to program space copies a word from program space to data space copies a word from data space to program space The heart of each function uses the TBLR or TBLW assembly instruction to access the data in program space memory. Each function is described in greater detail in Appendix A of this application report. Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP 3

It is important to understand that the three write functions cannot be used to program the on-chip flash memory of the flash devices in the C24x DSP generation. Programming the flash requires using device-specific flash programming utilities. These utilities are available on the TI website, www.ti.com. The three data write functions listed in Table 2 are mostly included in the library for completeness. There is no internal program RAM on current C24x generation devices that is not dual-mapped into data space, so it is unlikely that one would have much use for the write functions. The only conceivable exception to this would be if an external RAM (or peripheral device) were decoded only in the program space. To facilitate incorporation into the reader s application, the functions have been packaged into a library called pfunc.lib (PFUNC stands for program memory function). The reader should include this library into their Code Composer project. A header file, pfunc.h, which contains a function prototype for each function, has also been provided. This file should be included in the C-source file of any function that will be calling a library function. The libraries have been built using the TMS320C2x/C2xx/C5x Code Generation Tools v7.00 (included in C24x Code Composer v4.1x). Source code has been provided for each function should the user want to modify a function or would like a basis for creating new functions. The provided batch file make.bat can be used to rebuild the PFUNC function library from the source files at a command prompt. The usage is: make yourlib where "yourlib" is the name of the library you wish to create. The author chose the name pfunc.lib, but you may use any name you want. Alternately, you can simply include the modified source file directly into your Code Composer project, and not build a library at all. Example of PFUNC Library Use The.\example directory contains an example of PFUNC function use. In reality, this example does not do much! It is really there just to provide an illustration of the coding needed to use the PFUNC functions. The example may be run on the LF2407 or LF2407A evaluation module (EVM) with a JTAG emulator attached, and C24x Code Composer v4.1x running on the host PC. To use the example program, copy the file.\pfunc\include\pfunc.h into the.\example directory. Then, start Code Composer and load the file example.mak using the Project->Open menu command. You can then build and run the example. 4 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

When the program is run, the Stdout window in Code Composer should show the following: If you encounter difficulties either loading the project or building the code, it is most likely a file path problem. A prebuilt executable file.\example\example.out has been provided which should produce the above Stdout window when run on a LF2407 or LF2407A EVM. Use the File->Load Program menu command in Code Composer to directly load this executable file, and then run the program. Here is what main() does. First, it reads string1 and string2 using the PFUNC_strRead() and PFUNC_blkRead() functions respectively, and prints them both to the Stdout window. Next, it overwrites string1 with the string2, and string2 with string1, using PFUNC_strWrite() and PFUNC_blkwrite(), respectively. It then reads both strings back and prints them to the Stdout window. It next reads the single word at the label "k" using PFUNC_wordRead(), and prints its value to the Stdout window. Finally, it overwrites "k" with a different value using PFUNC_wordWrite(), and then reads it back and prints it to the Stdout window. Note that the temporary arrays (e.g., tmp1[ ] and tmp2[ ]) must be declared of sufficient length to hold the copied program memory strings or blocks. The PFUNC functions do not cross-check source and destination lengths, and will overwrite other data if the destination length is smaller than the source string length or block size. Also, PFUNC_blkRead() and PFUNC_blkWrite() are designed to read blocks of data type int, but here they are being used to read strings (which are blocks of data type char). Therefore, typecasting has been used in the function calls for each. Constructing the Program Memory Data Values The program memory data values are best constructed using assembly language. The file table.asm shows an example of how to do this. This particular example shows two strings and one 16-bit word that are to be stored in program memory. The "table" section is linked to program space memory in the linker command file lf2407a.cmd. The.def directive allows the named labels to be accessed by code in other source files. Additional information on the assembly language elements used may be found in the TMS320C1x/C2x/C2xx/C5x Assembly Language Tools User's Guide (SPRU018). Note that the terminating zero has been manually added to the strings, since termination of strings by a trailing zero (null character) is a C-language convention. The assembler does not automatically add the zero. When non-string data is being declared (e.g., the word at the symbol k), the terminating zero is not used. Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP 5

References 1. TMS320C2x/C2xx/C5x Optimizing C Compiler User's Guide (SPRU024) 2. TMS320F/C24x DSP Controllers Reference Guide: CPU and Instruction Set (SPRU160) 3. TMS320C1x/C2x/C2xx/C5x Assembly Language Tools User's Guide (SPRU018). 6 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

Appendix A. PFUNC Function Library Technical Reference PFUNC_blkRead Function Copies a block of words from program space to data space void PFUNC_blkRead( int *addrprog, int *ptrdata, unsigned int length ); Arguments addrprog source block address in program space ptrdata pointer to data space destination block Return Value None Copies a block of 16-bit words from program space to data space. This function is similar to PFUNC_strRead() except that PFUNC_strRead() uses the terminating null character in a string to mark the end of the block, whereas this function passes the length of the block as a parameter. Example #define N 20 extern int addrprog; int ptrdata[n]; unsigned int length = N; PFUNC_blkRead(&addrProg, ptrdata, length); Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP 7

PFUNC_blkWrite Function Copies a block of words from data space to program space void PFUNC_blkWrite( int *addrprog, int *ptrdata, unsigned int length ); Arguments addrprog destination block address in program space ptrdata pointer to data space source block Return Value None Copies a block of 16-bit words from data space to program space RAM. This function is similar to PFUNC_strWrite() except that PFUNC_strWrite() uses the terminating null character in a string to mark the end of the block, whereas this function passes the length of the block as a parameter. This function cannot be used to write to the on-chip flash memory. Programming the flash requires using one of several different flash programming utilities. These utilities are available on the TI website, www.ti.com. Example #define N 20 extern int addrprog; int ptrdata[n]; unsigned int length = N; PFUNC_blkWrite(&addrProg, ptrdata, length); 8 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

PFUNC_strRead Function Copies a string from program space to data space void PFUNC_strRead( char *addrprog, char *strdata, ); Arguments addrprog source string address in program space strdata pointer to data space destination string Return Value None Copies a string from program space to data space. This function is similar to PFUNC_blkRead except that PFUNC_blkRead passes the length of the block as a parameter, whereas this function uses the terminating null character in a string to mark the end of the block. Example #define N 20 extern char addrprog; char strdata[n]; PFUNC_strRead(&addrProg, strdata); Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP 9

PFUNC_strWrite Function Copies a string from data space to program space void PFUNC_strWrite( char *addrprog, char *strdata, ); Arguments addrprog destination string address in program space strdata pointer to data space source string Return Value None Copies a string from data space to program space. This function is similar to PFUNC_blkWrite except that PFUNC_blkWrite passes the length of the block as a parameter, whereas this function uses the terminating null character in a string to mark the end of the block. This function cannot be used to write to the on-chip flash memory. Programming the flash requires using one of several different flash programming utilities. These utilities are available on the TI website, www.ti.com. Example #define N 20 extern char addrprog; char strdata[n]; PFUNC_strWrite(&addrProg, strdata); 10 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

PFUNC_wordRead Function Copies a word from program space to data space int PFUNC_wordRead( int *addrprog ); Arguments addrprog source word address in program space Return Value worddata destination word in data space Example Copies a single 16-bit word from program space to data space. extern int addrprog; int worddata; worddata = PFUNC_wordRead(&addrProg); Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP 11

PFUNC_wordWrite Function Copies a word from data space to program space void PFUNC_wordWrite( int *addrprog int worddata ); Arguments addrprog destination word address in program space worddata source word in data space Return Value none Copies a single 16-bit word from data space to program space. This function cannot be used to write to the on-chip flash memory. Programming the flash requires using one of several different flash programming utilities. These utilities are available on the TI website, www.ti.com. Example extern int addrprog; int worddata; PFUNC_wordWrite(&addrProg, worddata); 12 Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

IMPORTANT NOTICE Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TI s terms and conditions of sale supplied at the time of order acknowledgment. TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI s standard warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed. TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and applications using TI components. To minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards. TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI. 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. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation. Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements. Mailing Address: Texas Instruments Post Office Box 655303 Dallas, Texas 75265 Copyright 2002, Texas Instruments Incorporated