|
| 1 | +/* |
| 2 | +Copyright © 2012 [email protected] |
| 3 | +
|
| 4 | + This file is part of SGMII-IP-Core. |
| 5 | + SGMII-IP-Core is free software: you can redistribute it and/or modify |
| 6 | + it under the terms of the GNU General Public License as published by |
| 7 | + the Free Software Foundation, either version 3 of the License, or |
| 8 | + (at your option) any later version. |
| 9 | +
|
| 10 | + SGMII-IP-Core is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + GNU General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU General Public License |
| 16 | + along with SGMII-IP-Core. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +
|
| 18 | +File : |
| 19 | +Description : |
| 20 | +Remarks : |
| 21 | +Revision : |
| 22 | + Date Author Description |
| 23 | +02/09/12 Jefflieu |
| 24 | +*/ |
| 25 | + |
| 26 | +module mDec8b10bMem( |
| 27 | + output reg [7:0] o8_Dout, //HGFEDCBA |
| 28 | + output reg o_Kout, |
| 29 | + output reg o_DErr, |
| 30 | + output reg o_KErr, |
| 31 | + output reg o_DpErr, |
| 32 | + input i_ForceDisparity, |
| 33 | + input i_Disparity, //1 Is negative, 0 is positive |
| 34 | + input [9:0] i10_Din, //abcdeifghj |
| 35 | + output o_Rd, |
| 36 | + input i_Clk, |
| 37 | + input i_ARst_L); |
| 38 | + |
| 39 | + parameter pNEG = 2'b01; |
| 40 | + parameter pPOS = 2'b10; |
| 41 | + parameter pNEU = 2'b00; |
| 42 | + parameter pERR = 2'b11; |
| 43 | + parameter pD = 2'b01; |
| 44 | + parameter pK = 2'b10; |
| 45 | + parameter pDK = 2'b11; |
| 46 | + |
| 47 | + |
| 48 | + reg r_Disp; |
| 49 | + reg [8:0] w9_5bDecode; |
| 50 | + reg [6:0] w7_3bDecode; |
| 51 | + wire w_Disp,w_jDisp,w_iDisp; |
| 52 | + wire w_iDpErr,w_jDpErr; |
| 53 | + wire w_iDErr,w_jDErr; |
| 54 | + wire [7:0] w8_ABCDEFGH; |
| 55 | + wire wa,wb,wc,wd,we,wi,wf,wg,wh,wj; |
| 56 | + wire w_K28; |
| 57 | + reg w_Kx; |
| 58 | + wire w_cdeihj; |
| 59 | + assign w_Disp = i_ForceDisparity?i_Disparity:r_Disp; |
| 60 | + assign {wa,wb,wc,wd,we,wi,wf,wg,wh,wj} = i10_Din; |
| 61 | + |
| 62 | + |
| 63 | + always@(*) |
| 64 | + case(i10_Din[9:4]) |
| 65 | + 6'b011000 : w9_5bDecode <= {5'b00000,pD,pPOS}; |
| 66 | + 6'b100111 : w9_5bDecode <= {5'b00000,pD,pNEG}; |
| 67 | + 6'b100010 : w9_5bDecode <= {5'b10000,pD,pPOS}; |
| 68 | + 6'b011101 : w9_5bDecode <= {5'b10000,pD,pNEG}; |
| 69 | + 6'b010010 : w9_5bDecode <= {5'b01000,pD,pPOS}; |
| 70 | + 6'b101101 : w9_5bDecode <= {5'b01000,pD,pNEG}; |
| 71 | + 6'b110001 : w9_5bDecode <= {5'b11000,pD,pNEU}; |
| 72 | + 6'b001010 : w9_5bDecode <= {5'b00100,pD,pPOS}; |
| 73 | + 6'b110101 : w9_5bDecode <= {5'b00100,pD,pNEG}; |
| 74 | + 6'b101001 : w9_5bDecode <= {5'b10100,pD,pNEU}; |
| 75 | + 6'b011001 : w9_5bDecode <= {5'b01100,pD,pNEU}; |
| 76 | + 6'b111000 : w9_5bDecode <= {5'b11100,pD,pNEG}; |
| 77 | + 6'b000111 : w9_5bDecode <= {5'b11100,pD,pPOS}; |
| 78 | + 6'b000110 : w9_5bDecode <= {5'b00010,pD,pPOS}; |
| 79 | + 6'b111001 : w9_5bDecode <= {5'b00010,pD,pNEG}; |
| 80 | + 6'b100101 : w9_5bDecode <= {5'b10010,pD,pNEU}; |
| 81 | + 6'b010101 : w9_5bDecode <= {5'b01010,pD,pNEU}; |
| 82 | + 6'b110100 : w9_5bDecode <= {5'b11010,pD,pNEU}; |
| 83 | + 6'b001101 : w9_5bDecode <= {5'b00110,pD,pNEU}; |
| 84 | + 6'b101100 : w9_5bDecode <= {5'b10110,pD,pNEU}; |
| 85 | + 6'b011100 : w9_5bDecode <= {5'b01110,pD,pNEU}; |
| 86 | + 6'b101000 : w9_5bDecode <= {5'b11110,pD,pPOS}; |
| 87 | + 6'b010111 : w9_5bDecode <= {5'b11110,pD,pNEG}; |
| 88 | + 6'b011011 : w9_5bDecode <= {5'b00001,pD,pNEG}; |
| 89 | + 6'b100100 : w9_5bDecode <= {5'b00001,pD,pPOS}; |
| 90 | + 6'b100011 : w9_5bDecode <= {5'b10001,pD,pNEU}; |
| 91 | + 6'b010011 : w9_5bDecode <= {5'b01001,pD,pNEU}; |
| 92 | + 6'b110010 : w9_5bDecode <= {5'b11001,pD,pNEU}; |
| 93 | + 6'b001011 : w9_5bDecode <= {5'b00101,pD,pNEU}; |
| 94 | + 6'b101010 : w9_5bDecode <= {5'b10101,pD,pNEU}; |
| 95 | + 6'b011010 : w9_5bDecode <= {5'b01101,pD,pNEU}; |
| 96 | + 6'b111010 : w9_5bDecode <= {5'b11101,pDK,pNEG}; |
| 97 | + 6'b000101 : w9_5bDecode <= {5'b11101,pDK,pPOS}; |
| 98 | + 6'b001100 : w9_5bDecode <= {5'b00011,pD,pPOS}; |
| 99 | + 6'b110011 : w9_5bDecode <= {5'b00011,pD,pNEG}; |
| 100 | + 6'b100110 : w9_5bDecode <= {5'b10011,pD,pNEU}; |
| 101 | + 6'b010110 : w9_5bDecode <= {5'b01011,pD,pNEU}; |
| 102 | + 6'b110110 : w9_5bDecode <= {5'b11011,pDK,pNEG}; |
| 103 | + 6'b001001 : w9_5bDecode <= {5'b11011,pDK,pPOS}; |
| 104 | + |
| 105 | + 6'b001110 : w9_5bDecode <= {5'b00111,pD,pNEU}; |
| 106 | + 6'b001111 : w9_5bDecode <= {5'b00111,pK,pNEG}; |
| 107 | + 6'b110000 : w9_5bDecode <= {5'b00111,pK,pPOS}; |
| 108 | + |
| 109 | + 6'b101110 : w9_5bDecode <= {5'b10111,pDK,pNEG}; |
| 110 | + 6'b010001 : w9_5bDecode <= {5'b10111,pDK,pPOS}; |
| 111 | + 6'b011110 : w9_5bDecode <= {5'b01111,pDK,pNEG}; |
| 112 | + 6'b100001 : w9_5bDecode <= {5'b01111,pDK,pPOS}; |
| 113 | + 6'b101011 : w9_5bDecode <= {5'b11111,pDK,pNEG}; |
| 114 | + 6'b010100 : w9_5bDecode <= {5'b11111,pDK,pPOS}; |
| 115 | + default : w9_5bDecode <= {5'b11111,pERR,pERR}; |
| 116 | + endcase |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + assign w_iDpErr = (w9_5bDecode[1:0]==pNEG && w_Disp==1'b1) | (w9_5bDecode[1:0]==pPOS && w_Disp==1'b0); |
| 121 | + assign w_iDErr = (w9_5bDecode[1:0]==pERR)?1'b1:1'b0; |
| 122 | + assign w_iDisp = (w9_5bDecode[1:0]==pERR||w9_5bDecode[1:0]==pNEU||i10_Din[9:4]==6'b111000||i10_Din[9:4]==6'b000111)?w_Disp:~w9_5bDecode[1]; |
| 123 | + |
| 124 | + assign w_jDpErr = (w7_3bDecode[1:0]==pNEG && w_iDisp==1'b1) | (w7_3bDecode[1:0]==pPOS && w_iDisp==1'b0); |
| 125 | + assign w_jDisp = (w7_3bDecode[1:0]==pERR||w7_3bDecode[1:0]==pNEU||i10_Din[3:0]==4'b1100||i10_Din[3:0]==4'b0011)?w_iDisp:~w_iDisp; |
| 126 | + assign w_jDErr = (w7_3bDecode[1:0]==pERR)?1'b1:1'b0; |
| 127 | + assign w_cdeihj = (~(|{wc,wd,we,wi}))&(wh^wj); |
| 128 | + always@(*) |
| 129 | + case(i10_Din[3:0]) |
| 130 | + 4'b0100 : w7_3bDecode <= {3'b000,pDK,pPOS}; |
| 131 | + 4'b1011 : w7_3bDecode <= {3'b000,pDK,pNEG}; |
| 132 | + 4'b1001 : if(w_cdeihj) |
| 133 | + w7_3bDecode <= {3'b011,pK,pNEU}; |
| 134 | + else |
| 135 | + w7_3bDecode <= {3'b100,pDK,pNEU}; |
| 136 | + 4'b0110 : if(w_cdeihj) |
| 137 | + w7_3bDecode <= {3'b100,pK,pNEU}; |
| 138 | + else |
| 139 | + w7_3bDecode <= {3'b011,pDK,pNEU}; |
| 140 | + 4'b0101 : if(w_cdeihj) |
| 141 | + w7_3bDecode <= {3'b101,pK,pNEU}; |
| 142 | + else |
| 143 | + w7_3bDecode <= {3'b010,pDK,pNEU}; |
| 144 | + 4'b1010 : if(w_cdeihj) |
| 145 | + w7_3bDecode <= {3'b010,pK,pNEU}; |
| 146 | + else |
| 147 | + w7_3bDecode <= {3'b101,pDK,pNEU}; |
| 148 | + 4'b1100 : w7_3bDecode <= {3'b110,pDK,pNEG}; |
| 149 | + 4'b0011 : w7_3bDecode <= {3'b110,pDK,pPOS}; |
| 150 | + 4'b0010 : w7_3bDecode <= {3'b001,pDK,pPOS}; |
| 151 | + 4'b1101 : w7_3bDecode <= {3'b001,pDK,pNEG}; |
| 152 | + //4'b1010 : |
| 153 | + //4'b0101 : |
| 154 | + //4'b0110 : |
| 155 | + //4'b1001 : |
| 156 | + 4'b1110 : w7_3bDecode <= {3'b111,pD,pNEG}; |
| 157 | + 4'b0001 : w7_3bDecode <= {3'b111,pD,pPOS}; |
| 158 | + 4'b0111 : w7_3bDecode <= {3'b111,pDK,pNEG}; |
| 159 | + 4'b1000 : w7_3bDecode <= {3'b111,pDK,pPOS}; |
| 160 | + default : w7_3bDecode <= {3'b111,pERR,pERR}; |
| 161 | + endcase |
| 162 | + |
| 163 | + assign w8_ABCDEFGH = {w9_5bDecode[8:4],w7_3bDecode[6:4]}; |
| 164 | + |
| 165 | + integer I; |
| 166 | + always@(posedge i_Clk or negedge i_ARst_L) |
| 167 | + if(~i_ARst_L) |
| 168 | + begin |
| 169 | + o_DErr <= 1'b1; |
| 170 | + o_DpErr <= 1'b0; |
| 171 | + o_KErr <= 1'b0; |
| 172 | + o_Kout <= 1'b0; |
| 173 | + o8_Dout <= 8'h0; |
| 174 | + r_Disp <= 1'b0; |
| 175 | + end |
| 176 | + else |
| 177 | + begin |
| 178 | + o_DErr <= w_jDErr|w_iDErr; |
| 179 | + o_DpErr <= w_jDpErr|w_iDpErr; |
| 180 | + o_KErr <= ~(|(w9_5bDecode[3:2]&w7_3bDecode[3:2])); |
| 181 | + o_Kout <= ((w9_5bDecode[3:2]==pK)&(w7_3bDecode[3]))|((w9_5bDecode[3:2]==pDK)&(w7_3bDecode[3])&(w7_3bDecode[6:4]==3'b111)); |
| 182 | + r_Disp <= w_jDisp; |
| 183 | + for(I=0;I<8;I=I+1) |
| 184 | + o8_Dout[7-I] <= w8_ABCDEFGH[I]; |
| 185 | + end |
| 186 | + assign o_Rd = r_Disp; |
| 187 | + |
| 188 | +endmodule |
0 commit comments