Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. package StringP is
  4. function to_char (data : in std_logic) return character;
  5. function to_char (data : in std_logic_vector(3 downto 0)) return character;
  6. function to_string (data : in std_logic) return string;
  7. function to_string (data : in std_logic_vector) return string;
  8. end package StringP;
  9. package body StringP is
  10. function to_char (data : in std_logic) return character is
  11. begin
  12. case data is
  13. when 'U' => return 'U';
  14. when 'X' => return 'X';
  15. when '0' => return '0';
  16. when '1' => return '1';
  17. when 'Z' => return 'Z';
  18. when 'W' => return 'W';
  19. when 'L' => return 'L';
  20. when 'H' => return 'H';
  21. when '-' => return '-';
  22. end case;
  23. end to_char;
  24. function to_char (data : in std_logic_vector(3 downto 0)) return character is
  25. begin
  26. case data is
  27. when x"0" => return '0';
  28. when x"1" => return '1';
  29. when x"2" => return '2';
  30. when x"3" => return '3';
  31. when x"4" => return '4';
  32. when x"5" => return '5';
  33. when x"6" => return '6';
  34. when x"7" => return '7';
  35. when x"8" => return '8';
  36. when x"9" => return '9';
  37. when x"A" => return 'A';
  38. when x"B" => return 'B';
  39. when x"C" => return 'C';
  40. when x"D" => return 'D';
  41. when x"E" => return 'E';
  42. when x"F" => return 'F';
  43. when others => return 'X';
  44. end case;
  45. end to_char;
  46. function to_string (data : in std_logic) return string is
  47. variable str : string(1 to 1);
  48. begin
  49. str(1) := to_char(data);
  50. return str;
  51. end function to_string;
  52. function to_string (data : in std_logic_vector) return string is
  53. variable v_str : string (1 to data'length);
  54. variable v_str_index : positive := 1;
  55. begin
  56. for i in data'range loop
  57. v_str(v_str_index) := to_char(data(i));
  58. v_str_index := v_str_index + 1;
  59. end loop;
  60. return v_str;
  61. end function to_string;
  62. end package body StringP;