Finding the next in round-robin scheduling by bit twiddling

前端 未结 9 1720
日久生厌
日久生厌 2021-02-02 02:46

Consider the following problem. You have a bit-string that represents the current scheduled slave in one-hot encoding. For example, \"00000100\" (with the leftmost bit being #7

9条回答
  •  遇见更好的自我
    2021-02-02 02:54

    The following solution works for any number of slaves (K), and is O(n) in your FPGA. For each bit in the field, you will require three logic gates and two inverters. I tested out the concept with a basic logic simulator, and it works.

    The chain of logic gates between current and mask essentially creates a priority system that favors bits "lower down" in the chain. This chain is looped at the ends, but the current bits are used to break the chain.

    To visualize the operation, imagine that bit 3 is set in the current field, and follow the signal downwards in the diagram. The logical one at bit 3 places a logical zero at the input to the first AND gate, which guarantees that the output of that AND gate will also be zero (this is where the OR-gate chain is broken). The zero at the output of the first AND gate places a one at the input to the second AND gate. This makes bit 2 of next directly dependent on bit 2 of mask.

    Now, the chain of OR gates comes into play.

    If bit 2 of mask was set, the logical output of the OR gate directly to the left of it will also be a one, which will place a logical one at the input to the AND gate below bit 2 of current (which will be zero, since only one bit in current can be set at a time). The logical one at the output of the top AND gate places a logical zero at the input of the bottom AND gate, thus setting bit 1 of next equal to zero.

    If bit 2 of mask was not set, both inputs to the OR gate would be zero, so the output of the AND gate below bit 2 of current would be a zero, placing a one at the input to the bottom AND gate, and therefore making bit 1 of next dependent on bit 1 of mask.

    This logic follows the chain of OR gates "up" the bits, looping around from the left side back over to the right, ensuring that only one bit in next can be set to a one. The loop stops once it makes its way back to bit 3 of current, as a result of that bit being set. This prevents the circuit from staying in a perpetual loop.

    I have no experience with Verilog or VHDL, so I'll leave the actual code up to you and the rest of stackoverflow.

    alt text http://img145.imageshack.us/img145/5125/bitshifterlogicdiagramkn7.jpg

    notes:

    1. This solution is only partial. It will still require some kind of latching mechanism to hold the bit fields.
    2. Keep in mind that as you increase the number of bits, the time required for the gate voltages to settle will also increase.
    3. There will have to be some logic in place to handle the case where the current field is equal to zero. See this stackoverflow question.

提交回复
热议问题