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.

TMS320C5505 bitfields and structure over registers



Hi everyone ,

I want to be able to put a bitfield over my different register on my c5505 but i can't seem to find the information I am looking. First of all, on the C5505, in a bit field, does it has to be the LSB first or de the MSB first i.e

struct Example {

unsigned int BIT0 : 1;

unsigned int BIT1_3 : 3;

...

};

or

struct Example {

unsigned int BIT1_3 : 3;

unsigned int BIT 0 :1;

};

Secondly, how do I put my structure over my module register (right now i am trying to do the SPI part)

I've seen litterature about other DSP/uC from TI but i can't find the information I want from the PDF available (at least,  for the many i read) but if it's like the other uC/DSP, I would assume that first, I need to define my bitfield/structure and make a volatile instance of it ( i.e volatile struct Example myexample) and then , with pragma code , assign the address I want to the structure in the memory map . Am I right or am I way out ?

Thanks

  • I usually write my code to the lowest level, just as you seem to be attempting.  However, with the TMS320VC55x, I started out using the CSL (Chip Support Library), and have found it to make this sort of thing fairly easy.

    If you look at the header files in the CSL for various peripherals, you will see C code that defines macros for nearly all of the registers.  For the few exceptions that I have found (with the rare C5506), I just mimic the CSL code and fill in the differing values.

    The CSL has macros to create an entire word from bit fields for a register so that you can assign everything at once, but there are also macros which allow you to update a single bit field without disturbing other bit fields.  I think that the folks at TI have actually avoided bitfield structs as in your example, but they effectively accomplish the same thing.  My hunch is that the method they use is compatible with their compiler, and hopefully generates the most efficient assembly for the processor.

    There are also documents about the C compiler, and other documents with recommendations on how to optimize your code.  You should read all of those to make sure you're aware of the ramifications of rolling your own code.  They document the keywords in their C variant which allow addressing of I/O registers, which are not part of the normal memory map.

  • Thanks for the response Brian,

    I finally found the document I needed to perform that. Finally , I didnt have to change the linker.

    Basically, I've declared my bitfield

    typedef struct{

    [...]

    unsigned int bit4-9 : 10;

    [...]

    }StructName;

    And then I've declared a pointer type of that structure type on the structure , Including the ioport in the definition


    volatile struct ioport StructName *MyStructure = 0x3000 ;

    and it worked.

    So i will stick with that for now as it's the result I wanted.

  • Hi,

    This sounds like something that I'd might like to do, however did you ever verify if there are any data alignment issues, and if or how the compiler generates efficient bit manipulation code in the end ? Just wondering if you had any issues with this perhaps that you may wish to share with the forum ?

    Cheers, Mike

  • With the method described in my last post, I don't have any problem with the data alignment. Every bit fields act as they should. As for the generated code from the compiler, I haven't checked into that.  So right now, to get your answer, you'll have to find out yourself, sorry.

    Jeph

  • No probs. thanks !

  • I do that like you.But it has errors.

    codes:

     

    typedef union {

     Uint16 byte;

     struct{

       Uint16 BIT0        :1;                                      

       Uint16 BIT1        :1;                                   

       Uint16 BIT2        :1;                                    

       Uint16 BIT3        :1;                                     

       Uint16 BIT4        :1;                                  

       Uint16 BIT5        :1;                                     

       Uint16 BIT6        :1;                                      

       Uint16 BIT7        :1;                                    

       Uint16 BIT8        :1;                                     

       Uint16 BIT9        :1;                                     

       Uint16 BIT10        :1;                                       

       Uint16 BIT11        :1;                                      

       Uint16 BIT12        :1;                                      

       Uint16 BIT13        :1;                                      

       Uint16 BIT14        :1;                                      

       Uint16 BIT15        :1;                                      

       }byte_bit;   

    }  OUT;

     

      volatile union ioport  OUT   *GPIO_DATAOUT0 = 0x1c0a;      ///36

      volatile union ioport  OUT   *GPIO_DATAOUT1 = 0x1c0b;    ////37

     

     

    errors:

     

    "..\fun.h", line 36: error: expected either a definition or a tag name

    "..\fun.h", line 37: error: expected either a definition or a tag name