National Instruments 320571-01 Car Stereo System User Manual


 
Getting Started with the NI-DSP Interface Utilities Chapter 2
Part 4: NI-DSP Interface Utilities 2-4 NI-DSP SRM for LabVIEW for Windows
Return a 16-bit short integer error code–Every function should return an integer error code. A list of error codes
that the existing DSP Library returns is given in Appendix A, Error Codes. If any of these error codes are used,
ATDSP.h should be included at the beginning of your source code. A function that completes with no error
should return noError or zero.
Use the memory management routines–Perform any dynamic onboard memory allocation using the functions
Alloc_Mem and Free_Mem, described in the next section.
DSP Board Memory Management
To write your own customized DSP routines that become integrated with the DSP Library, you need some lower
level memory management routines. Two onboard calls are included with the DSP Library to dynamically allocate
and deallocate onboard memory–Alloc_Mem and Free_Mem. Use these functions instead of the standard C
routines malloc and free.
Call the function Alloc_Mem whenever your routines require memory space. Alloc_Mem attempts to allocate
memory of the requested size (in bytes) in any available memory bank. If the requested buffer size (in bytes) is not a
multiple of four, the allocation routines ensure alignment to the nearest radix 4 boundary >= NumBytes. This is to
guarantee memory alignment on 4-byte addresses. For example, if you request the allocation of a buffer of size
1,021, 1,022, 1,023 or 1,024 bytes, then the allocation routines allocate 1,024 bytes in all four cases. The allocation
routines first attempt to allocate the buffer in on-chip memory (all DSP boards have 4 kilobytes of on-chip memory).
If the routine fails, the allocation routine tries to allocate the buffer in onboard memory (DSP boards have between
256 kilobytes and 1.5 megabytes of onboard memory). The function and input parameters for Alloc_Mem are
defined as follows:
void * Alloc_Mem(size)
long size;
where size is the requested block size in bytes.
Alloc_Mem returns a pointer to the allocated buffer or returns NULL if the allocation failed.
Call the function Free_Mem when you deallocate memory buffers. Use this function instead of the standard C
function free. The function and input parameters for Free_Mem are defined as follows:
short Free_Mem(ptr)
long ptr;
where ptr is the address of the buffer to be deallocated.
Free_Mem deallocates the buffer pointed to by ptr if that buffer was allocated previously using Alloc_Mem.
Free_Mem returns NULL if deallocation succeeded and returns an error code if deallocation did not succeed.
Each of the NI-DSP Analysis VIs call a function that is part of the DSP Library that resides on the board. Your own
custom functions can call any of the DSP Library functions included in the NIDSP.fnc file described later in this
chapter. The DSP functions that you can call from your own functions are prototyped in Part 4, Chapter 3, DSP
Board Function Overview.
Note for Assembly Language Programmers: If you are using WE DSP32C assembly language, each function
must accept and return C-style parameters and preserve all
registers used in the WE DSP32C environment. For example, the
function parameters are pushed onto the stack from right to left and
the return value is placed in Register r1. Refer to the WE DSP32C
C Language Compiler Library Reference Manual for details.