On 9/8/2016 3:35 PM, Charles Steinkuehler wrote: > On 9/8/2016 12:41 PM, William Hermans wrote: >> >> It has long been programing technique to use DATAOUT |= BITx to set a >> register >> bit DATAOUT &= (~BITx) to clear a register bit, or something like if(DATAOUT >> & >> BITx){} or if((DATAOUT &BITx) == 0 or 1) to read a bit from a register. > > Yes, it has. But those short-hand snippits of C code are hiding an > implicit read-modify-write cycle: > > DATAOUT |= BITx > > ...turns into: > > Read : <temp> = DATAOUT > Modify: <temp> = <temp> | BITx > Write : DATAOUT = <temp> > > ...where <temp> is probably a CPU register (unless your C compiler is > _really_ bad!). But if you use the set/clear registers it's just: > > Write : SETDATAOUT = BITx
Oh...while we're on the subject, there's one more significant reason the set/clear registers are helpful even if you're not worried about multi-threaded operation: They're *FAST* The ARM core on the BBB is running at 1 GHz, but the I/O is only running at about 100 MHz. So that simple DATAOUT |= BITx stalls the CPU until the system can provide the current value of DATAOUT to the processor core, which likely takes a couple hundred nanoseconds (based on the time it takes for the PRU to read a GPIO register). The write, however, is very fast (for both the set/clear case and for writing directly to DATAOUT). Writes are posted and the ARM has weak memory ordering, so as long as you're not saturating the on-chip interconnect fabric, the write will appear to complete instantly, the ARM core will carry on executing instructions, and about 100 nS later the GPIO register will update with the new value once the write transaction has worked it's way through the on-chip interconnect fabric. -- Charles Steinkuehler char...@steinkuehler.net -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/66e45786-85b9-2302-bef4-3213f6848a8d%40steinkuehler.net. For more options, visit https://groups.google.com/d/optout.