This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to force the bit order in a struct

Hi,

I saw several structs that you have in your library and I am curious as how you are forcing the alignment, since I want to do the same.

This is one of them:

    typedef union
{
  struct
  {
    uint32_t _reserved0:16;              /*!< bit:  0..15  Reserved */
    uint32_t GE:4;                       /*!< bit: 16..19  Greater than or Equal flags */
    uint32_t _reserved1:7;               /*!< bit: 20..26  Reserved */
    uint32_t Q:1;                        /*!< bit:     27  Saturation condition flag */
    uint32_t V:1;                        /*!< bit:     28  Overflow condition code flag */
    uint32_t C:1;                        /*!< bit:     29  Carry condition code flag */
    uint32_t Z:1;                        /*!< bit:     30  Zero condition code flag */
    uint32_t N:1;                        /*!< bit:     31  Negative condition code flag */
  } b;                                   /*!< Structure used for bit  access */
  uint32_t w;                            /*!< Type      used for word access */
} APSR_Type;

I am trying to implement this but I cannot force the aligment as I want. Do I need some kind of pragma? In your header in case core_cm4.h does not seem to be needed.

This is my struct:

typedef union {
	struct {
		uint16_t			pk_type	:2;	// 00
		uint16_t			prod_num:3;	// 100
		uint16_t			brd_num	:3;	// 011
		uint16_t			sw_maj	:3;	// 000
		uint16_t			sw_min  :5; // 00001
	}				b;
	
	uint16_t 		sh;
	} ps_btn_dev_info_t;
Related