1 |
2 |
zguig52 |
-------------------------------
|
2 |
|
|
---- Project: EurySPACE CCSDS RX/TX with wishbone interface
|
3 |
|
|
---- Design Name: ccsds_rxtx_functions
|
4 |
|
|
---- Version: 1.0.0
|
5 |
|
|
---- Description:
|
6 |
|
|
---- TO BE DONE
|
7 |
|
|
-------------------------------
|
8 |
|
|
---- Author(s):
|
9 |
|
|
---- Guillaume Rembert
|
10 |
|
|
-------------------------------
|
11 |
|
|
---- Licence:
|
12 |
|
|
---- MIT
|
13 |
|
|
-------------------------------
|
14 |
|
|
---- Changes list:
|
15 |
|
|
---- 2015/12/28: initial release
|
16 |
|
|
---- 2016/10/20: added reverse_std_logic_vector function + rework sim_generate_random_std_logic_vector for > 32 bits vectors
|
17 |
|
|
---- 2016/11/17: added convert_boolean_to_std_logic function
|
18 |
|
|
---- 2017/01/15: added convert_std_logic_vector_array_to_std_logic_vector
|
19 |
|
|
-------------------------------
|
20 |
|
|
|
21 |
|
|
-- libraries used
|
22 |
|
|
library ieee;
|
23 |
|
|
use ieee.std_logic_1164.all;
|
24 |
|
|
use ieee.numeric_std.all;
|
25 |
|
|
use ieee.math_real.all;
|
26 |
|
|
use work.ccsds_rxtx_types.all;
|
27 |
|
|
|
28 |
|
|
package ccsds_rxtx_functions is
|
29 |
|
|
-- synthetizable functions
|
30 |
|
|
function convert_boolean_to_std_logic(input: in boolean) return std_logic;
|
31 |
|
|
function convert_std_logic_vector_array_to_std_logic_vector(std_logic_vector_array_in: in std_logic_vector_array; current_row: in integer) return std_logic_vector;
|
32 |
|
|
function reverse_std_logic_vector (input: in std_logic_vector) return std_logic_vector;
|
33 |
|
|
-- simulation / testbench only functions
|
34 |
|
|
function convert_std_logic_vector_to_hexa_ascii(input: in std_logic_vector) return string;
|
35 |
|
|
procedure sim_generate_random_std_logic_vector(vector_size : in integer; seed1 : inout positive; seed2 : inout positive; result : out std_logic_vector);
|
36 |
|
|
end ccsds_rxtx_functions;
|
37 |
|
|
|
38 |
|
|
package body ccsds_rxtx_functions is
|
39 |
|
|
|
40 |
|
|
function convert_boolean_to_std_logic(input: in boolean) return std_logic is
|
41 |
|
|
begin
|
42 |
|
|
if (input = true) then
|
43 |
|
|
return '1';
|
44 |
|
|
else
|
45 |
|
|
return '0';
|
46 |
|
|
end if;
|
47 |
|
|
end convert_boolean_to_std_logic;
|
48 |
|
|
|
49 |
|
|
function convert_std_logic_vector_array_to_std_logic_vector(std_logic_vector_array_in: in std_logic_vector_array; current_row: in integer) return std_logic_vector is
|
50 |
|
|
variable result: std_logic_vector(std_logic_vector_array_in'range(2));
|
51 |
|
|
begin
|
52 |
|
|
for i in std_logic_vector_array_in'range(2) loop
|
53 |
|
|
result(i) := std_logic_vector_array_in(current_row, i);
|
54 |
|
|
-- report "Read: " & std_logic'image(std_logic_vector_array_in(current_row, i)) severity note;
|
55 |
|
|
end loop;
|
56 |
|
|
return result;
|
57 |
|
|
end;
|
58 |
|
|
|
59 |
|
|
function reverse_std_logic_vector (input: in std_logic_vector) return std_logic_vector is
|
60 |
|
|
variable result: std_logic_vector(input'range);
|
61 |
|
|
alias output: std_logic_vector(input'REVERSE_RANGE) is input;
|
62 |
|
|
begin
|
63 |
|
|
for vector_pointer in output'range loop
|
64 |
|
|
result(vector_pointer) := output(vector_pointer);
|
65 |
|
|
end loop;
|
66 |
|
|
return result;
|
67 |
|
|
end;
|
68 |
|
|
|
69 |
|
|
function convert_std_logic_vector_to_hexa_ascii(input: in std_logic_vector) return string is
|
70 |
|
|
constant words_number: integer := input'length/4;
|
71 |
|
|
variable result: string(words_number-1 downto 0);
|
72 |
|
|
variable word: std_logic_vector(3 downto 0);
|
73 |
|
|
begin
|
74 |
|
|
for vector_word_pointer in words_number-1 downto 0 loop
|
75 |
|
|
word := input((vector_word_pointer+1)*4-1 downto vector_word_pointer*4);
|
76 |
|
|
case word is
|
77 |
|
|
when "0000" =>
|
78 |
|
|
result(vector_word_pointer) := '0';
|
79 |
|
|
when "0001" =>
|
80 |
|
|
result(vector_word_pointer) := '1';
|
81 |
|
|
when "0010" =>
|
82 |
|
|
result(vector_word_pointer) := '2';
|
83 |
|
|
when "0011" =>
|
84 |
|
|
result(vector_word_pointer) := '3';
|
85 |
|
|
when "0100" =>
|
86 |
|
|
result(vector_word_pointer) := '4';
|
87 |
|
|
when "0101" =>
|
88 |
|
|
result(vector_word_pointer) := '5';
|
89 |
|
|
when "0110" =>
|
90 |
|
|
result(vector_word_pointer) := '6';
|
91 |
|
|
when "0111" =>
|
92 |
|
|
result(vector_word_pointer) := '7';
|
93 |
|
|
when "1000" =>
|
94 |
|
|
result(vector_word_pointer) := '8';
|
95 |
|
|
when "1001" =>
|
96 |
|
|
result(vector_word_pointer) := '9';
|
97 |
|
|
when "1010" =>
|
98 |
|
|
result(vector_word_pointer) := 'a';
|
99 |
|
|
when "1011" =>
|
100 |
|
|
result(vector_word_pointer) := 'b';
|
101 |
|
|
when "1100" =>
|
102 |
|
|
result(vector_word_pointer) := 'c';
|
103 |
|
|
when "1101" =>
|
104 |
|
|
result(vector_word_pointer) := 'd';
|
105 |
|
|
when "1110" =>
|
106 |
|
|
result(vector_word_pointer) := 'e';
|
107 |
|
|
when "1111" =>
|
108 |
|
|
result(vector_word_pointer) := 'f';
|
109 |
|
|
when others =>
|
110 |
|
|
result(vector_word_pointer) := '?';
|
111 |
|
|
end case;
|
112 |
|
|
-- report "Converted " & integer'image(to_integer(resize(unsigned(word),16))) & " to " & result(vector_word_pointer) severity note;
|
113 |
|
|
end loop;
|
114 |
|
|
return result;
|
115 |
|
|
end;
|
116 |
|
|
|
117 |
|
|
procedure sim_generate_random_std_logic_vector(vector_size : in integer; seed1 : inout positive; seed2 : inout positive; result : out std_logic_vector) is
|
118 |
|
|
variable rand: real := 0.0;
|
119 |
|
|
variable temp: std_logic_vector(31 downto 0);
|
120 |
|
|
begin
|
121 |
|
|
if (vector_size < 32) then
|
122 |
|
|
uniform(seed1, seed2, rand);
|
123 |
|
|
rand := rand*(2**(real(vector_size))-1.0);
|
124 |
|
|
result := std_logic_vector(to_unsigned(integer(rand),vector_size));
|
125 |
|
|
else
|
126 |
|
|
uniform(seed1, seed2, rand);
|
127 |
|
|
for vector_pointer in 0 to vector_size-1 loop
|
128 |
|
|
uniform(seed1, seed2, rand);
|
129 |
|
|
rand := rand*(2**(real(31))-1.0);
|
130 |
|
|
temp := std_logic_vector(to_unsigned(integer(rand),32));
|
131 |
|
|
result(vector_pointer) := temp(0);
|
132 |
|
|
end loop;
|
133 |
|
|
end if;
|
134 |
|
|
end sim_generate_random_std_logic_vector;
|
135 |
|
|
end ccsds_rxtx_functions;
|