When writing DSP sub-functions, you may use some variables. It is best not to use arrays with large data volumes, because when DSP runs the sub-function program, the local variables involved have a temporary storage area in the memory, but DSP cannot identify whether there are other program segments in this area, which may cause the array to be truncated midway, some data to be wrong or the program to run incorrectly.
Solutions:
1. Define global variables directly and allocate a certain memory address in the main program;
2. Use pointers to pass variables, and do not define new variables in sub-functions;
3. Use the function *UTIL_allocMem(Uint32size) to allocate memory blocks in sub-functions.
// Allocatememory from the ad-hoc heap
void*UTIL_allocMem(Uint32 size)
{
void *cPtr;
Uint32 size_temp;
// Ensure word boundaries
size_temp = ((size + 4) >> 2 )<< 2;
if((currMemPtr + size_temp) > ((Uint32)&EXTERNAL_RAM_END))
{
return NULL;
}
cPtr = (void *) (((U int32)&EXTERNAL_RAM_START) + currMemPtr);
currMemPtr += size_temp;
return cPtr;
}
|