Conceptual
Login

Naming Register Bits and Sizes

Hardware registers pack several meanings into one word: bit zero means busy, bit seven means interrupts enabled, bits eight to fifteen are a count. Writing those as hand-shifted hexadecimal constants is where off-by-one bit errors come from, so the kernel crate offers macros that build a single-bit mask or a named bit field with its own get and set operations, plus ready-made constants for common sizes like one megabyte. Naming the bits also makes your driver readable against the device's documentation, which is how reviewers check it.

Questions this Concept answers

  • Why does kernel code prefer named bit fields over hand-shifted hexadecimal constants?