CS485 Sylabus

### Implementing the CRC scheme in hardware

• Implementing the CRC division algorithm with hardware

• An important advantage of CRC codes is:

• The "divide" algorithm used in the CRC can be easily implemented with cheap hardware:

 Shift-register (actually: D-flipflops)       and          XOR circuits

• Shift registers

• Shift-register circuit:

 1 bit shift register = a circuit with that copies the input value to its output during the time that the clock signal changes from 0 ⇒ 1 (or from 1 ⇒ 0)

• You can see the behavior of a serie of shift-register in this demo:

 ``` /home/cs455001/demo/Logic-Sim/shift-register ```

• XOR circuit

• XOR circuit:

• XOR circuit = a circuit with 2 inputs and one output

• The XOR function is as follows:

 ``` 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0 ```

• You can see the behavior of the XOR circuit in this demo:

 ``` /home/cs455001/demo/Logic-Sim/xor ```

• Hardware CRC implementation

• How to create a circuit that compute the CRC code for a given generator polynomial:

• Let

 N = length of the generator polynomial

• Use (N−1) D-flipflops (= shift registers) to store the remainder of the division.

• Start by

• Putting (N−1) Dffs in a row.

• Connect the output of the ith Dff to the input of the i+1th Dff

Example: (N = 4 or N−1 = 3)

• The input of the first Dff will receive the message one bit at a time:

• We must modify the circuit as follows:

• Read the CRC generator polynomial in the reverse order.

 In this step, you will only use N−1 bits of the CRC generator polynomial

• For bit i in the (reversed ordered) CRC generator polynomial do:

• if bit i = 1, then:

• Change the direct connection to the input of the Dff (shift register) to an XOR gate

 I.e.: insert an XOR circuit before the ith Dff

• Connect the output of the last Dff as the second input of the new XOR circuit

 I.e.: the output of the last Dff is fed back into the ith Dff)

It's much easier to see and example (I'll do it in class)

• Example: compute circuit for generator polynomial 1001

• N = 4

Put the 3 Dffs in a row.

Connect the output of the ith Dff to the input of the i+1th Dff:

• Example: compute circuit for generator polynomial 1101

• N = 4

Put the 3 Dffs in a row.

Connect the output of the ith Dff to the input of the i+1th Dff:

• Computing the CRC with the hardware implementation

• How to compute the CRC for an input message:

• Reset all the Dffs (memory elements) to ZERO

 Toggle key 'a' to ONE to clear the shift registers Toggle key 'a' back to ZERO (blank cell) so you can run the circuit

• Present the first bit of the message

• Use key 0 to set it to the value of the first bit (0 or 1)

• The input bits are presented from left to right:

 ``` Message: 101010 Present the bits as follows: 1 0 1 0 1 0 ```

• Give the compute circuit a clock signal

 You must toggle the key 1 twice

• Present the second bit of the message (see above)
• Give the compute circuit another clock signal (see above)

• And so on, until all bits in the message are processed

Note:

 Remember that the sender must append N−1 ZERO (0) bits to the input message These N−1 ZERO (0) bits must be processed also !!

• After processing all bits:

• Sender:

 Remainder of the "division" = values of the shift registers read in the reverse order

 If remainder of the "division" = all 0's, then accept the message Otherwise, reject the message

• Example Program: (Circuit for generator polynomial 1101)

How to use it:

 Run: /home/cs455001/demo/Logic-Sim/CRC1 Make a = 0 (blank) to run circuit Toggle 0:Input to the next bit in input Press 1:Clk to give circuit a clock signal (2 toggles per input bit).

This is a logic-sim program from my CS355 class...

Example:

 ``` 00011 ---------------- 1101 / 10001000 1101 ---- (XOR) 1011 1101 ---- (XOR) 1100 1101 ---- (XOR) 000100 <---- remainder = 100 ```

Do this:

 Toggle 2 to run circuit Toggle 0 (input) to 1, then toggle 1 (clock twice) Toggle 0 (input) to 0, then toggle 1 (clock twice) Toggle 0 (input) to 0, then toggle 1 (clock twice) Toggle 0 (input) to 0, then toggle 1 (clock twice) Toggle 0 (input) to 1, then toggle 1 (clock twice) Toggle 0 (input) to 0, then toggle 1 (clock twice) Toggle 0 (input) to 0, then toggle 1 (clock twice) Toggle 0 (input) to 0, then toggle 1 (clock twice) Read the bits backwards: 100