| 1 |
3 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: wbutohex.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: FPGA library
|
| 6 |
|
|
//
|
| 7 |
|
|
// Purpose: Supports a printable character conversion from a printable
|
| 8 |
|
|
// ASCII character to six bits of valid data. The encoding is
|
| 9 |
|
|
// as follows:
|
| 10 |
|
|
//
|
| 11 |
|
|
// 0-9 -> 0-9
|
| 12 |
|
|
// A-Z -> 10-35
|
| 13 |
|
|
// a-z -> 36-61
|
| 14 |
|
|
// @ -> 62
|
| 15 |
|
|
// % -> 63
|
| 16 |
|
|
//
|
| 17 |
|
|
// Note that decoding is stateless, yet requires one clock.
|
| 18 |
|
|
//
|
| 19 |
|
|
//
|
| 20 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 21 |
|
|
// Gisselquist Technology, LLC
|
| 22 |
|
|
//
|
| 23 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 24 |
|
|
//
|
| 25 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
| 26 |
|
|
//
|
| 27 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 28 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 29 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 30 |
|
|
// your option) any later version.
|
| 31 |
|
|
//
|
| 32 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 33 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 34 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 35 |
|
|
// for more details.
|
| 36 |
|
|
//
|
| 37 |
|
|
// You should have received a copy of the GNU General Public License along
|
| 38 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
| 39 |
|
|
// target there if the PDF file isn't present.) If not, see
|
| 40 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 41 |
|
|
//
|
| 42 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 43 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 44 |
|
|
//
|
| 45 |
|
|
//
|
| 46 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 47 |
|
|
//
|
| 48 |
|
|
//
|
| 49 |
|
|
module wbutohex(i_clk, i_stb, i_byte, o_stb, o_valid, o_hexbits);
|
| 50 |
|
|
input i_clk, i_stb;
|
| 51 |
|
|
input [7:0] i_byte;
|
| 52 |
|
|
output reg o_stb, o_valid;
|
| 53 |
|
|
output reg [5:0] o_hexbits;
|
| 54 |
|
|
|
| 55 |
|
|
always @(posedge i_clk)
|
| 56 |
|
|
o_stb <= i_stb;
|
| 57 |
|
|
|
| 58 |
|
|
always @(posedge i_clk)
|
| 59 |
|
|
begin
|
| 60 |
|
|
// These are the defaults, to be overwridden by the ifs below
|
| 61 |
|
|
o_valid <= 1'b1;
|
| 62 |
|
|
o_hexbits <= 6'h00;
|
| 63 |
|
|
|
| 64 |
|
|
if ((i_byte >= 8'h30)&&(i_byte <= 8'h39)) // A digit
|
| 65 |
|
|
o_hexbits <= { 2'b0, i_byte[3:0] };
|
| 66 |
|
|
else if ((i_byte >= 8'h41)&&(i_byte <= 8'h5a)) // Upper case
|
| 67 |
|
|
o_hexbits <= (i_byte[5:0] - 6'h01 + 6'h0a);// -'A'+10
|
| 68 |
|
|
else if ((i_byte >= 8'h61)&&(i_byte <= 8'h7a))
|
| 69 |
|
|
o_hexbits <= (i_byte[5:0] +6'h03); // -'a'+(10+26)
|
| 70 |
|
|
else if (i_byte == 8'h40) // An '@' sign
|
| 71 |
|
|
o_hexbits <= 6'h3e;
|
| 72 |
|
|
else if (i_byte == 8'h25) // A '%' sign
|
| 73 |
|
|
o_hexbits <= 6'h3f;
|
| 74 |
|
|
else
|
| 75 |
|
|
o_valid <= 1'b0;
|
| 76 |
|
|
end
|
| 77 |
|
|
endmodule
|
| 78 |
|
|
|