4 ms·
http://www.emulator101.com/logical-operations.html http://www.emulator101.com/logical-operations.html /* Example 2: turn on one LED on the control panel */
by lin0tune 8y ago
http://www.emulator101.com/logical-operations.html http://www.emulator101.com/logical-operations.html
/* Example 2: turn on one LED on the control panel */
char * LED_pointer = (char *) 0x2089;
char led = *LED_pointer;
led = led | 0x40; //set LED controlled by bit 6
*LED_pointer = led;
Really?
- deleted 8y ago[deleted]
- teraflop 8y agoWhat's wrong with that? If you're writing code for pedagogical purposes, it doesn't necessarily need to be as concise as possible.
- monocasa 8y agoIn fact, in my firmware writing style, I tend to separate MMIO accesses from mutation to make it clear when those bus accesses occur.
- simias 8y agoI know some people who object to one-line read-modify-write of hardware registers, the idea being that glancing at the code the non-atomicity of the operation might be lost. I also generally don't use raw volatile pointers directly when dealing with hardware registers, too easy to forget a "volatile" somewhere and have the code behave erratically. I always use tiny read32/write32 wrappers instead.
- kstenerud 8y agoAbsolutely. Modern compilers are trivially able to inline such operations, so there's no reason not to make your intentions and separation of operations crystal clear. After all, you're going to read the code a lot more often than you'll write it.
- planteen 8y agoYes and read/write barriers are also sometimes necessary, to prevent re-ordering by the compiler and processor.
- sigjuice 8y agoYes, wrappers are the way to go. e.g. Linux kernel
- monocasa 8y agoYou have to be careful though in some cases. For instance, if you read two MMIO registers in a one liner, there's no way to guarantee the ordering between them.
- CobrastanJorji 8y agoYes really. It's example code written for the sole purpose of being read by people for educational purposes. As long as you understand the basics of pointers, it's really easy to read. Why are you mad at it?