Skip to content

I2C API is mixing two incompatible definitions of bit-fields #4009

@zephyrbot

Description

@zephyrbot

Reported by Piotr Mienkowski:

Zephyr's I2C API contains the following construct

union dev_config {
    u32_t raw;
    struct __bits {
        u32_t        use_10_bit_addr : 1;
        u32_t        speed : 3;
        u32_t        is_master_device : 1;
        u32_t        reserved : 26;
    } bits;
};

This is incorrect. C99 §6.7.2.1, paragraph 10 says: "The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined.". I.e. - using union dev_config as an example - compiler is free to map use_10_bit_addr either to MSB or to LSB. The two methods of specifying bit fields are not equivalent and should not be mixed.

(Imported from Jira ZEP-2579)

Metadata

Metadata

Assignees

Labels

area: APIChanges to public APIsarea: I2CbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions