In embedded systems you have read only and write only registers. How are the two type distinguished in the produced netlist?
How one builds a flop which you can only write to and not read from?
embeddedregisterverilogvhdl
In embedded systems you have read only and write only registers. How are the two type distinguished in the produced netlist?
How one builds a flop which you can only write to and not read from?
Best Answer
It's all about how the registers are connected to the bus:
If you leave out the part of the hardware that can read the register then your register is write-only. Similarly if you leave out the part of the hardware that can write to the register then it's read-only.
Sometimes it makes sense to have only one "direction" of data flow. Think of a DAC or an ADC data path.
Also, sometimes it makes sense to have the same address return something other than the data you've written to it. Think of most common microcontrollers; their peripherals tend to have a single address that is a "command" for writes and a "status" for reads.
Another example would be interrupt flags: you read the interrupt register to see which peripheral interrupted the program, then write a '1' to the same bit to clear the interrupt flag. One way to realize that is as follows:
Here you can see that I'm setting a flag to whatever is in bit position 0 in the write case (and I don't care about whatever else they may have written), while in the read case I'm building up a status word made up of individual bits that the peripheral is driving.
aside: I am also explicitly maintaining
clear_int
at zero in the read case. It's just good coding practice to make sure that all signals are assigned in all code paths in HDL. At best not doing so makes for sloppy code. At worst you can infer latches. Note that I do something similar withwb_dat_o
before I even enter the register access case.Keep in mind that these are only examples to illustrate the point, and that a well-written program will be described more carefully and thoroughly. Also keep in mind that it's 8am here and I haven't had my coffee yet. :-)