This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C5515: Can I change the HWAFFT headers to use Uint16 pointers instead?

Part Number: TMS320C5515

The HWAFFT interface provided by the code accompanying SPRABB6B looks like this:

Uint16 hwafft_8pts(
    Int32 *data,
    Int32 *scratch,
    Uint16 fft_flag,
    Uint16 scale_flag
);

As the documentation points out, the format of the data is real/imaginary interleaved 16-bit signed integers. Each 32-bit unit corresponds to a single complex value.

However, for the purposes of further signal processing, it would be very convenient to simply keep an interleaved Uint16 array, rather than have to mask and shift values into, and out of, 32-bit values in the FFT data arrays.

I can't just pass Uint16 pointers to the functions as declared in the header files, because that would be undefined behaviour in C, and I don't see anything in the compiler manual to say I can do that. But I don't know enough about the ROM implementation/TI calling conventions to know if I can change the header file declarations to take Uint16 pointers. Will doing that affect how the hwafft implementation in ROM behaves? Is it a dangerous thing to do, that might work now but might break unpredictably later?

  • Hi Jason,

    If you make your own FFT implementation you are free to make any changes but when you are using functions calling and using HWAFFT ROM code implementation structures changing of variable's type can provoke unexpected behavior. If somewhere in the HWAFFT implementation code is called increment of pointer to Int32 variable but you change its type to Uint16 pointer increment will point to different address.
    Therefore I suggest you to keep the variable types unchanged.

    Regards,
    Tsvetolin Shulev
  • Does the HWAFFT implementation know what the C data type was though? It's already compiled, so does it not just increment by a fixed amount?

    Otherwise, is there a way to avoid all the extra copying and shifting eg. if I'm reading audio data from I2S via DMA, it would be faster to read the data straight into the HWAFFT data buffer. But with things as they are, I have to read them into a separate buffer, loop over and do the shifting and copying, and then call the FFT. This seems likes it's negating the point of hardware acceleration to make things faster.

  • Ofcourse the HWAFFT implementation has no idea for your code but I can not guarantee that you will not have any issues. Therefore you can test and share the results when using Uint16.

    Regards,
    Tsvetolin Shulev
  • Cvetolin Shulev-XID said:
    Ofcourse the HWAFFT implementation has no idea for your code but I can not guarantee that you will not have any issues. Therefore you can test and share the results when using Uint16.

    I'm extremely reluctant to just try something and see in an embedded C project, since C is a standardised language with undefined behaviour. I've seen a lot of code go wrong when a compiler is updated because the previous version relied on behaviour that was actually undefined.

    The issue here though is that there is no C code for the HWAFFT. It exists only as machine code in the ROM on the C5515. The only C involved is the header file, which relates the calling conventions of C (and TI's compiler) to the binary interface used by the HWAFFT. If that calling convention/ABI doesn't make the distinction between a Uint32* and Uint16*, then the header file can simply be changed with no consequence. But I don't know enough about those two things to say.

    Ultimately I'm using the HWAFFT for speed and power optimisations, but if I need to copy and shift data around to use it, and it cancels out the gains, there's not really any point to using a chip with a HWAFFT on it.