30b34147622e48e21465c3cd9940da48c31553b4
[calu.git] / cpu / src / extension_7seg_pkg.vhd
1 library IEEE;
2 use IEEE.std_logic_1164.all;
3 use IEEE.numeric_std.all;
4
5 use work.common_pkg.all;
6 use work.extension_pkg.all;
7
8 package extension_7seg_pkg is
9
10         constant SEGMENT_G : std_logic_vector(0 to 6) := "0000001";
11         constant SEGMENT_F : std_logic_vector(0 to 6) := "0000010";
12         constant SEGMENT_E : std_logic_vector(0 to 6) := "0000100";
13         constant SEGMENT_D : std_logic_vector(0 to 6) := "0001000";
14         constant SEGMENT_C : std_logic_vector(0 to 6) := "0010000";
15         constant SEGMENT_B : std_logic_vector(0 to 6) := "0100000";
16         constant SEGMENT_A : std_logic_vector(0 to 6) := "1000000";
17
18         constant DIGIT_0 : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_B or SEGMENT_C or SEGMENT_D or SEGMENT_E or SEGMENT_F;
19         constant DIGIT_1 : std_logic_vector(0 to 6) := SEGMENT_B or SEGMENT_C;
20         constant DIGIT_2 : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_B or SEGMENT_G or SEGMENT_E or SEGMENT_D;
21         constant DIGIT_3 : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_B or SEGMENT_C or SEGMENT_D or SEGMENT_G;
22         constant DIGIT_4 : std_logic_vector(0 to 6) := SEGMENT_B or SEGMENT_C or SEGMENT_G or SEGMENT_F;        
23         constant DIGIT_5 : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_F or SEGMENT_G or SEGMENT_C or SEGMENT_D;
24         constant DIGIT_6 : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_F or SEGMENT_E or SEGMENT_D or SEGMENT_C or SEGMENT_G;
25         constant DIGIT_7 : std_logic_vector(0 to 6) := SEGMENT_A or DIGIT_1;
26         constant DIGIT_8 : std_logic_vector(0 to 6) := SEGMENT_G or DIGIT_0;
27         constant DIGIT_9 : std_logic_vector(0 to 6) := SEGMENT_B or DIGIT_5;
28         constant DIGIT_A : std_logic_vector(0 to 6) := DIGIT_1 or SEGMENT_A or SEGMENT_G or SEGMENT_E or SEGMENT_F;
29         constant DIGIT_B : std_logic_vector(0 to 6) := SEGMENT_F or SEGMENT_E or SEGMENT_D or SEGMENT_C or SEGMENT_G;
30         constant DIGIT_C : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_F or SEGMENT_E or SEGMENT_D;
31         constant DIGIT_D : std_logic_vector(0 to 6) := SEGMENT_B or SEGMENT_G or SEGMENT_E or SEGMENT_D or SEGMENT_C;
32         constant DIGIT_E : std_logic_vector(0 to 6) := DIGIT_C or SEGMENT_G;
33         constant DIGIT_F : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_F or SEGMENT_E or SEGMENT_G;
34         constant DIGIT_MINUS : std_logic_vector(0 to 6) := SEGMENT_G;
35         constant DIGIT_CLEAR : std_logic_vector(0 to 6) := SEGMENT_A or SEGMENT_B or SEGMENT_C or SEGMENT_D or SEGMENT_E or SEGMENT_F or SEGMENT_G;
36         
37         subtype sseg_digit is std_logic_vector(4 downto 0);
38
39         type sseg_state_rec is record
40                 digit0 : std_logic_vector(0 to 6);
41                 digit1 : std_logic_vector(0 to 6);
42                 digit2 : std_logic_vector(0 to 6);
43                 digit3 : std_logic_vector(0 to 6);
44         end record;
45         
46         function digit_decode(value : sseg_digit) return std_logic_vector;
47         
48         component extension_7seg
49         
50         generic(
51                         RESET_VALUE : std_logic
52                 );
53         port(
54                 --System inputs
55                         sys_clk : in std_logic;
56                         sys_res_n : in std_logic;
57                 -- general extension interface                  
58                         ext_reg  : in extmod_rec;
59 --                      data_out : out gp_register_t;
60                 --Control input
61 --                      val : in std_logic_vector(4 downto 0);
62 --                      pos : in std_logic_vector(1 downto 0);
63 --                      act : std_logic;
64                 --Output
65                         o_digit0 : out std_logic_vector(0 to 6);
66                         o_digit1 : out std_logic_vector(0 to 6);
67                         o_digit2 : out std_logic_vector(0 to 6);
68                         o_digit3 : out std_logic_vector(0 to 6)
69                 );
70         end component extension_7seg;
71         
72 end extension_7seg_pkg;
73
74 package body extension_7seg_pkg is
75         
76         function digit_decode(value : sseg_digit) return std_logic_vector is
77         
78         begin
79                 case value is
80                         when "00000" => return DIGIT_0;
81                         when "00001" => return DIGIT_1;
82                         when "00010" => return DIGIT_2;
83                         when "00011" => return DIGIT_3;
84                         when "00100" => return DIGIT_4;
85                         when "00101" => return DIGIT_5;
86                         when "00110" => return DIGIT_6;
87                         when "00111" => return DIGIT_7;
88                         when "01000" => return DIGIT_8;
89                         when "01001" => return DIGIT_9;
90                         when "01010" => return DIGIT_A;
91                         when "01011" => return DIGIT_B;
92                         when "01100" => return DIGIT_C;
93                         when "01101" => return DIGIT_D;
94                         when "01110" => return DIGIT_E;
95                         when "01111" => return DIGIT_F;
96                         when "10000" => return "1111111";
97                         --when "11111" => return DIGIT_MINUS;
98                         when OTHERS => return DIGIT_CLEAR;
99                 end case;
100         
101         end function digit_decode;
102
103 end extension_7seg_pkg;