Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

in microcontrollers it's very common to see code generated that creates structs for the registers. They will typically output fields that are a full machine word in size (or maybe in some cases as small as a byte), and individual bits will be addressed with bitmasking (ie `my_device.some_reg |= SOME_REG_FLAG_NAME` or `my_device.some_reg &= ~SOME_REG_FLAG_NAME` to clear it). It is sometimes necessary to be thoughtful about batching writes so that certain bits are set before the periferal begins some process. A trivial example would be:

  port_a.data_out |= GPIOA_PIN_1 | GPIOA_PIN_2;
and

  port_a.pin1 = true;
  port_a.pin2 = true;


This is why manufacturers don't do this for volatile register access. You now have bloated, hazard prone code with multiple read-modify-writes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: