You are on page 1of 2

C-Language Programming for DSP

T
he C programming language has the executable code directly into a DSP tar-
become the language of choice for get environment and then use debug
many engineering applications, software to start it running and control ex-
especially digital signal processing. The C ecution. Running code on “the real thing”
language is extremely portable, compact, has the advantages of using actual hard-
and lends itself well to structured pro- ware for input/output data and in
gramming techniques. It has been ported evaluating real-time performance.
to virtually every major programming
platform and is the predominant system Standard I/O
programming language for the major oper- A fundamental aspect of the C language
ating systems used today. is that it contains no environment-specific
Programmers familiar with the C lan- input or output resources. Therefore, each
guage on PC or UNIX platforms should be incarnation of a C compiler requires a stan-
aware of some key differences between C dard I/O library tailored specifically for
programming for general-purpose work- each operating environment.
stations and C programming for DSPs. During debugging and development it
Areas of attention include differences may be required that standard I/O be redi-
between native and cross compilers, simu- rected to the host. In this case, the I/O
lators, I/O library support, run-time function must accommodate a communica-
libraries, linkers, and memory modules. tion link from target to host. Whatever the
The major difference in C compilers for link, the collection of standard I/O library
DSP, as compared to typical C compilers functions must be chosen to support the
found in most workstations, is that the object desired operation.
code produced does not execute on the host In complex DSP environments utilizing an
Programming in C for digital CPU, but rather on the DSP chip in the target operating system executing on the DSP, an
signal processing applications board. This type of C compiler is called a abstract path may exist between target and
has moved into widespread use cross compiler. The more conventional C host, often involving several layers of calls.
and many powerful tools have compiler which produces code for the host
been developed to assist the CPU is known as a native compiler. Run-time Libraries
programmer. By first under- The reason that cross compilers are so The C language itself contains no inher-
standing some of the basic much more appropriate than native compilers ent routines for the many math functions,
concepts and special consider- for DSP is that virtually no DSP processor string operations, and memory management
ations involved, the experience environment can come close to providing all tasks required by all DSP applications.
can be extremely rewarding. of the supporting I/O resources available on Instead, as with the standard I/O functions,
As the software tools strive even the most modest workstation. the ANSI C standard defines a set of run-
to keep pace with the rapid Since the DSP code produced by the time library functions to be supplied as part
development of powerful new cross compiler cannot execute on the host of a C compiler package.
DSP devices, the mastery of CPU, there are two methods of testing and Most DSP C compilers incorporate an
special programming skills will developing DSP code. extensive set of run-time library functions,
continue to be an exciting and First, the DSP processor can be simulated including trigonometric and transcendental
dynamic process. by a host program known as a simulator. functions; range limit functions for different
The simulator closely mimics the operation types of variables supported; string manipu-
of the DSP chip so that executable DSP ob- lation functions; data type declaration
ject code is processed as it would be by the functions; and time functions handling
DSP chip. Memory and I/O is also simu- seconds to years with calendar notations.
lated so that the DSP target environment is The run-time libraries are often written as
matched as closely as possible. Simulators very efficient assembly language routines,
can be very useful for developing algorithms optimized to take advantage of the special
and for developing program flow and architectural features of the target DSP.
integrity.
However, this rather sterile environment DSP Libraries
insulates the programmer from the hard- The need to extend the scope of the run-
ware-specific features of the target board time libraries to include more exotic and
which often represent some of the most powerful routines common to DSP applica-
critical aspects of application development, tions is satisfied by a class of routines
usually dealing with I/O. called DSP libraries. They include vector
As an alternative to simulation or as the and matrix arithmetic operations, FFTs,
next step after simulation, one can move [Continued on next page]

Pentek, Inc. One Park Way ◆ Upper Saddle River ◆ New Jersey 07458
www.pentek.com 1
Tel: 201.818.5900 ◆ Fax: 201.818.5904 ◆ Email: info@pentek.com
digital filtering routines, windowing func- Initialized code sections can be allocated
tions, and image processing routines. to RAM or ROM, while the uninitialized
These functions allow the DSP code de- sections must be allocated to RAM. This
veloper to work at a much higher level and allocation is handled by the linker which
alleviate the burden of reinventing com- processes all the relocatable object files
mon signal processing tasks. In some cases, from the assembler, the run-time library
however, the routines involve trade-offs in functions, standard I/O and DSP library
execution speed vs. ease of use. Custom functions. The linker allocates code sections
versions of these functions can be easily from each of these structures into larger, ho-
substituted in these cases. mogenous regions of the same type.
Some of these library functions are The final result is a single file divided
supplied with the C compiler and some are into sections for each code type, each with
Text Editor C Source Code available from third party vendors. a header specifying where that section is to
be placed when loaded into the hardware
Board Support Libraries target memory space.
Board Support
Cross The Board Support Libraries offer a fast
Libraries
Compiler
and tested approach to programming hard- Host-to-Target Links
ware. Functions provided within these One of the most challenging aspects of
Standard libraries allow the programmer to access the DSP code development is establishing an
I/O Libraries Cross
Assembler hardware at different architectural levels. easy-to-use method of communication
Run-time For example, a board support library between the host workstation and the target
Libraries written for a 16-channel A/D interface may DSP board. There are many different
Linker include high-level functions such as combinations of host/target environments
DSP
Libraries
reset_all_A/Ds(), or initialize_board() which which involve the use of bus adapters,
program the global settings of the board. Ethernet adapters, emulators, embedded
Pentek offers ReadyFlow Board Support board level host processors, integral card
Debugger Loader
Libraries, a collection of high-level C-callable cages and backplanes, as well as many one-
functions, to simplify system development. of-a-kind interfaces.
This problem is often complicated by hav-
Host-to-Target
Link
DSP Memory Models ing multiple DSP processors on one board,
An important consideration when using multiple target DSP boards, or even multiple
a C compiler optimized for DSP applications card cages full of target DSP boards. What-
Target is its linker and memory model. Most com- ever the arrangement, in order for the
DSP Board
pilers, such as the TI C Compiler, produce loader to execute successfully, the host
an intermediate assembly language output must be able to access each DSP target
file. The assembly language file is then memory environment.
DSP programming is a processed by an assembler to produce a To solve this problem, Pentek has
multistep operation. relocatable object file. developed SwiftNet, a universal, bidirec-
One advantage of the intermediate tional communication protocol between
assembly language phase is that it allows host and target.
inspection and modification of the assem-
bly code, often necessary for debugging Debuggers
target hardware/software interactions. As stated earlier, one of the most powerful
In conventional native C compilers run- tools for code development is the interactive
ning on a host system, all memory sections debugger. With this approach, once the object
are typically allocated to one region of code has been loaded into the target DSP
system RAM. However, a C compiler for memory, the user can start, monitor, and
DSP must be capable of carefully allocating control the execution of the processor.
these sections of code to the many different This requires an even more powerful
kinds of memory typically found on DSP kind of host-to-target link than the one neces-
target boards—fast SRAM, slower DRAM, sary for the loader. In addition to accessing
external ROM, and nonvolatile RAM. There target memory, the host must be able to ex-
are also many kinds of hardware devices amine all internal CPU registers, access other
which can be addressed like memory, includ- hardware resources on the target board, set
ing registers, FIFOs, counters, and UARTs. breakpoints, single step through instructions,
and, in general, manipulate the target DSP in
many different ways. ❏

Pentek, Inc. One Park Way ◆ Upper Saddle River ◆ New Jersey 07458
www.pentek.com 2
Tel: 201.818.5900 ◆ Fax: 201.818.5904 ◆ Email: info@pentek.com

You might also like