Texas Instruments TMS320 User Manual page 187

Dsp/bios v5.40
Hide thumbs Also See for TMS320:
Table of Contents

Advertisement

5.1.4
Allocating Memory Dynamically
5.1.4.1 Memory Allocation with the MEM Module
Example 5-3. Using MEM_alloc for System-Level Storage
Example 5-4. Allocating an Array of Structures
DSP/BIOS provides functions in two modules for dynamic memory allocation:
MEM and BUF. The MEM module allocates variable-size blocks of memory.
The BUF module allocates fixed-size buffers from buffer pools.
Basic storage allocation may be handled using 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.
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.
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.
typedef struct Obj {
Int
field1;
Int
field2;
Ptr
objArr;
} Obj;
objArr = MEM_alloc(SRAM, sizeof(Obj) * ARRAYLEN, 0);
Memory and Low-level Functions
Memory Management
5-5

Advertisement

Table of Contents
loading

Table of Contents