This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Struct problems

First off, I am fairly new to chip level programming!

I am using a SILabs C8051F330 and I am having trouble in the compilation
of some libraries that I need to use that were given by Texas Instruments to
implement a SPI interface to one of their wireless chips. Anyway, the library
uses many structures to handle the comm back and forth with their product.

An example of one is the following:

typedef struct {
    uint32_t rfChMask                : 20; ///< New dynamic RF channel mask to be used by WASPM
    uint32_t reserved0               : 12; ///< Reserved
} EHIF_CMD_NWM_SET_RF_CH_MASK_PARAM_T;

I get many errors all of this type:

ERROR C155 IN LINE 480 OF FILE_DEFS.H: 'rfChMask': char/int required for fields

Any suggestions are greatly appreciated!
Thanks

  • If the Keil C51 compiler can't handle (unsigned) long as data type for bit fields, then you haven't much options but to rewrite the code so you manually shift in the two field values into a single uint32_t variable and use that one instead.

    But the interesting thing: If C51 doesn't support uint32_t bit fields - what compile was that library written for?

  • So are you asking me or telling me that KEIL C51 compiler does NOT handle these type of structures?

    According to TI, the library was originally written using IAR compiler. I was using KEIL because of other projects we had already compiled using it.

    Again, thanks for your help!

  • Thanks for the information. The stdint definition for uint32_t is unsigned long int.
    So that's got to be the issue.

    Thanks

  • Note that IAR make compilers for a huge range of chips - maybe they were referring to an IAR compiler where int is 32 bits?

    The 'C' language standard specifies only 'int', 'unsigned int' or 'signed int' as the base for fields - so Keil C51 is giving an extension by allowing 'char'

    Maybe this "IAR" compiler allow 32-bit fields as an extension...?

    In the words of K&R:

    "Almost everything about fields is implementation-dependent"

  • Based on the error message, I'm making the conclusion that Keil C51 only supports (unsigned) char and int as data types for bit fields.

    At the same time, I know that an int in C51 is 16-bit, in which case I have to assume that a uint32_t is a unsigned long int - a data type the error message claims isn't supported.

    I can very well understand why C51 don't want to support it - the processor is 8-bit, so it requires library helper functions or lots of inlined assembler instructions to work with 32-bit integers. And it doesn't get easier with 32-bit bit fields, since the individual bit fields need not be aligned on bytes. Live is so trivial when the compiler can implement the bit manipulation natively, by operating on a single full-size register. Just think about taking a value larger than what fits in any register, and then shift it more steps than what fits in any register, before storing the value in a variable that is 4 times the size of a basic processor register. Obviously possible, but costing a lot in a tiny processor with normally limited code space.