Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bitfields vs masks for SFRs
#2
The is currently no MISRA "preferred" route for access to SFRs so the choice is down to the organisation, project or individual.

If you are confident that your compiler vendor has mapped the bitfield structure onto the SFR correctly then you might wish to use this access mechanism, deviating Rule 18.4 for these SFRs. However, you would need to be sure that the size of accesses that the compiler makes are compatible with the processor manufacturer's specification for the SFR. For example, if you have an SFR that occupies 2 bytes and you want to access a single bit field in that SFR then, provided your machine is byte-addressable, the compiler could access just the byte that contains the field, or the whole SFR. Whether this affects the behaviour of your program or not will depend on the SFR in question.

If you are explicit over the size of the SFR access then you have more control over the situation and are less likely to modify the machine state inadvertently.
Posted by and on behalf of the MISRA C Working Group
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)