SPRADC3 june   2023 AM2431 , AM2432 , AM2434 , AM2631 , AM2631-Q1 , AM2632 , AM2632-Q1 , AM2634 , AM2634-Q1 , AM263P4 , AM3351 , AM3352 , AM3354 , AM3356 , AM3357 , AM3358 , AM3358-EP , AM3359 , AM4372 , AM4376 , AM4377 , AM4378 , AM4379 , AM5706 , AM5708 , AM5716 , AM5718 , AM5718-HIREL , AM5726 , AM5728 , AM5729 , AM5746 , AM5748 , AM5749 , AM6411 , AM6412 , AM6421 , AM6422 , AM6441 , AM6442 , AM6526 , AM6528 , AM6546 , AM6548

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction to 8b-10b Line Coding
  5. 2PRU Implementation for Data Transmitting and Receiving
    1. 2.1 Encoding and Decoding Data
    2. 2.2 PRU Module Interface and GPIO Mode
    3. 2.3 PRU GPIO Shift-out and Shift-in Mode for Communication
    4. 2.4 Three-channel Peripheral Interface for Communication
    5. 2.5 LVDS and M-LVDS Interface
  6. 3System Solution With CRC Module and Over-head Optimization
    1. 3.1 PRU CRC16/32 Module
    2. 3.2 Encode and Decode Over-head Optimization
  7. 4Verification
  8. 5Summary
  9. 6References

Encoding and Decoding Data

Typically, there are four tables written into the memory in advance, including an encoding 5b-6b table, encoding 3b-4b table, decoding 6b-5b table, and decoding 4b-3b table. Data has to be encoded using a look-up table (LUT) prior to transmission and decoded with the LUT after receiving. To demonstrate encoding and decoding data, the Sitara™ AM243x LaunchPad™ development kit is selected as the device for verification. The HW_WR_REG8 function can be used to put the four tables into PRU Dynamic Random Access Memory (DRAM) with different offset addresses using the C code of the Arm® core project, see also the following code.

uint32_t enc_5b6b = CSL_PRU_ICSSG0_DRAM1_SLV_RAM_BASE + ENC_5B6B_OFFS;
uint32_t enc_3b4b = CSL_PRU_ICSSG0_DRAM1_SLV_RAM_BASE + ENC_3B4B_OFFS;
uint32_t dec_5b6b = CSL_PRU_ICSSG0_DRAM0_SLV_RAM_BASE + DEC_5B6B_OFFS;
uint32_t dec_3b4b = CSL_PRU_ICSSG0_DRAM0_SLV_RAM_BASE + DEC_3B4B_OFFS;
    //Encoding LUTs (input MSB first, output LSB first)
    //LUT 5b/6b encoding
HW_WR_REG8(enc_5b6b + 0x00, 0x18);
...
    //LUT 3b/4b encoding
HW_WR_REG8(enc_3b4b + 0x00, 0x04);
...
    //Decoding LUTs (input LSB first, output MSB first)
    //LUT 6b/5b decoding
HW_WR_REG8(dec_5b6b + 0x00, INVAL);
...
    //LUT 4b/3b decoding
HW_WR_REG8(dec_3b4b + 0x00, INVAL);
...

Data can be encoded by the LUT in a PRU firmware project using load byte burst (LBBO) instruction. The LBBO instruction is used to read a block of data from memory into the register file. The REG_TMP11 register stores the LUT header address and REG_ENC register stores the original data and encoded data. See the following code of encode 8-bit data (0x34):

Ldi REG_ENC.b0, 0x14                       ;raw data 5b LSB
ldi REG_TMP11, (PDMEM00+LUT_5b6b_ENC)      ; TEMP11 for 5b/6b LUT header
lbbo &REG_ENC.b3, REG_TMP11, REG_ENC.b0, 1 ; FNC.b0 for original 5 bit -data, ENC.b3 for encoded 6 bit
ldi REG_ENC.b1, 0x01                       ; raw data 3b MSB
ldi REG_TMP11, (PDMEM00+LUT_3b4b_ENC)      ; TEMP11 for 3b/4b LUT header
lbbo &REG_ENC.b2, REG_TMP11, REG_ENC.b1, 1 ; FNC.b1 for original 3 bit -data, ENC.b2 for encoded 4 bit

The lower five bits of 0x34 is 0x14 and these bits load immediately into byte 0 of REG_ENC. After the LUT, the six encoded bits are written into byte 3 of REG_ENC. The higher three bits of 0x34 is 0x01 and these bits load immediately into byte 1 of REG_ENC. After LUT, the four encoded bits are written into the byte 2 of REG_ENC.

Figure 2-1 shows the REG_ENC register distribution for the original data and encoded data.

GUID-20230606-SS0I-XT0X-SWXL-VD39BWMT8CPF-low.svg Figure 2-1 REG_ENC Encoding Register Distribution

The decoding process is nearly identical to the encoding process. The decoding process also uses LBBO instructions with the LUT for decoding after receiving the encoded data. The REG_TMP11 register stores the LUT header address and the REG_DEC register stores the encoded data and decoded data.

The six encoded bits are received and moved into byte 1 of REG_DEC. After the LUT, the five decoded bits are written into the byte 2 of REG_DEC. The higher four bits are received and moved into byte 0 of REG_DEC. After LUT, the three decoded bits are written into byte 3 of REG_DEC. To combine the 10 bits of data from two bytes of the register into eight bits of data, byte 3 of REG_DEC needs to be shift left by five bits and logically added with byte 2 of REG_DEC. The final decoded eight bits of data is stored in byte 0 of REG_DEC. The following code shows the decoding process.

ldi REG_TMP11, (PDMEM00+LUT_5b6b_DEC)      ; TEMP11 for 5b/6b LUT header
lbbo &REG_DEC.b2, REG_TMP11, REG_DEC.b1, 1 ; decode 6b
ldi REG_TMP11, (PDMEM00+LUT_3b4b_DEC)      ; TEMP11 for 3b/4b LUT header
lbbo &REG_DEC.b3, REG_TMP11, REG_DEC.b0, 1 ; decode 4b
lsl REG_DEC.b3, REG_DEC.b3, 5              ; shift left 5 bit
add REG_DEC, REG_DEC.b2, REG_DEC.b3        ; combine to 8 bit data

Figure 2-2 shows the REG_DEC register distribution for encoded data and decoded data.

GUID-20230606-SS0I-L142-PHLT-WVJDXV9QLWLH-low.svg Figure 2-2 REG_DEC Decoding Register Distribution