-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstring_stream_pack.vhd
100 lines (98 loc) · 3.45 KB
/
string_stream_pack.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
----------------------------------------------------------------------------------------
-- GDB_RSP_Debug for VexRiscV Project
-- (c) Bernhard Lang, Hochschule Osnabrueck
----------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
package string_stream is
constant MsgLen: integer := 300;
function SetMessage(constant message: string) return string;
procedure Send_String(
constant command : in string;
variable message : inout string;
signal Clk : in std_logic;
signal out_valid : out std_logic;
signal out_last : out std_logic;
signal out_data : out std_logic_vector(7 downto 0);
signal out_ready : in std_logic
);
procedure Receive_String(
variable response : out string;
signal Clk : in std_logic;
signal in_valid : in std_logic;
signal in_last : in std_logic;
signal in_data : in std_logic_vector(7 downto 0);
signal in_ready : out std_logic
);
end package;
library ieee;
use ieee.numeric_std.all;
package body string_stream is
----------------------------------------------------------------------------
function SetMessage(constant message: string) return string is
variable m: string(1 to MsgLen) := (others=>' ');
begin
m(message'range) := message;
return m;
end;
----------------------------------------------------------------------------
procedure Send_String(
constant command : in string;
variable message : inout string;
signal Clk : in std_logic;
signal out_valid : out std_logic;
signal out_last : out std_logic;
signal out_data : out std_logic_vector(7 downto 0);
signal out_ready : in std_logic
) is
begin
message := (message'range =>' ');
out_valid <= '0';
out_last <= '0';
out_data <= x"00";
wait until rising_edge(Clk);
for i in command'range loop
out_valid <= '1';
if i=command'right then out_last<='1'; else out_last<='0'; end if;
out_data <= std_logic_vector(to_unsigned(character'pos(command(i)),8));
wait until rising_edge(Clk) and out_ready='1';
end loop;
message := SetMessage(command);
out_valid <= '0';
out_last <= '0';
out_data <= x"00";
wait until rising_edge(Clk);
message := (message'range =>' ');
end procedure;
----------------------------------------------------------------------------
procedure Receive_String(
variable response : out string;
signal Clk : in std_logic;
signal in_valid : in std_logic;
signal in_last : in std_logic;
signal in_data : in std_logic_vector(7 downto 0);
signal in_ready : out std_logic
) is
variable index: integer;
variable char: character;
variable resp: string(response'range);
begin
response := (response'range =>' ');
index := 1;
in_ready <= '1';
loop
wait until rising_edge(Clk) and in_valid='1';
char := character'val(to_integer(unsigned(in_data)));
resp(index) := char;
exit when in_last='1';
if index<MsgLen then index := index+1;
else report "Receive_String: response to short" severity error;
end if;
end loop;
response(1 to index) := resp(1 to index);
in_ready <= '0';
wait until rising_edge(Clk);
response := (response'range =>' ');
end procedure;
----------------------------------------------------------------------------
end package body;