Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec-tests / vhdl_json / vhdl_files / 2-exportOK / cnes_guidelines / rule / data / CNE_04800_good.vhd @ 2051e520

History | View | Annotate | Download (4.71 KB)

1
-------------------------------------------------------------------------------------------------
2
-- Company   : CNES
3
-- Author    : Mickael Carl (CNES)
4
-- Copyright : Copyright (c) CNES. 
5
-- Licensing : GNU GPLv3
6
-------------------------------------------------------------------------------------------------
7
-- Version         : V1
8
-- Version history : 
9
--    V1 : 2015-04-20 : Mickael Carl (CNES): Creation
10
-------------------------------------------------------------------------------------------------
11
-- File name          : CNE_04800_good.vhd
12
-- File Creation date : 2015-04-20
13
-- Project name       : VHDL Handbook CNES Edition 
14
-------------------------------------------------------------------------------------------------
15
-- Softwares             :  Microsoft Windows (Windows 7) - Editor (Eclipse + VEditor)
16
-------------------------------------------------------------------------------------------------
17
-- Description : Handbook example: Finite State Machine two processes based: good example
18
--
19
-- Limitations : This file is an example of the VHDL handbook made by CNES. It is a stub aimed at
20
--               demonstrating good practices in VHDL and as such, its design is minimalistic.
21
--               It is provided as is, without any warranty.
22
--               This example is compliant with the Handbook version 1.
23
--
24
-------------------------------------------------------------------------------------------------
25
-- Naming conventions: 
26
--
27
-- i_Port: Input entity port
28
-- o_Port: Output entity port
29
-- b_Port: Bidirectional entity port
30
-- g_My_Generic: Generic entity port
31
--
32
-- c_My_Constant: Constant definition 
33
-- t_My_Type: Custom type definition
34
--
35
-- My_Signal_n: Active low signal
36
-- v_My_Variable: Variable
37
-- sm_My_Signal: FSM signal
38
-- pkg_Param: Element Param coming from a package
39
--
40
-- My_Signal_re: Rising edge detection of My_Signal
41
-- My_Signal_fe: Falling edge detection of My_Signal
42
-- My_Signal_rX: X times registered My_Signal signal
43
--
44
-- P_Process_Name: Process
45
--
46
-------------------------------------------------------------------------------------------------
47

    
48
library IEEE;
49
use IEEE.std_logic_1164.all;
50
use IEEE.numeric_std.all;
51

    
52
entity CNE_04800_good is
53
   port  (
54
      i_Clock     : in std_logic;   -- Clock input
55
      i_Reset_n   : in std_logic;   -- Reset input
56
      i_Start     : in std_logic;   -- Start counter signal
57
      i_Stop      : in std_logic    -- Stop counter signal
58
   );
59
end CNE_04800_good;
60

    
61
--CODE
62
architecture Behavioral of CNE_04800_good is
63
   constant c_Length    : std_logic_vector(3 downto 0) := (others => '1'); -- How long we should count
64
   type t_state         is (init, loading, enabled, finished);             -- Enumerated type for state encoding
65
   signal sm_State      : t_state;                                         -- State signal
66
   signal sm_Next_State : t_state;                                         -- Next state
67
   signal Raz        : std_logic;                                       -- Load the length value and initialize the counter
68
   signal Enable     : std_logic;                                       -- Counter enable signal
69
   signal Length     : std_logic_vector(3 downto 0);                    -- Counter length for counting
70
   signal End_Count  : std_logic;                                       -- End signal of counter
71
begin
72
   Counter:pkg_Counter
73
   port map (
74
      i_Clock     => i_Clock,
75
      i_Reset_n   => i_Reset_n,
76
      i_Raz       => Raz,
77
      i_Enable    => Enable,
78
      i_Length    => Length,
79
      o_Done      => End_Count
80
   );
81
   
82
   -- FSM process controlling the counter. Start or stop it in function of the input (i_Start & i_Stop), 
83
   -- load the length value, and wait for it to finish
84
   
85
   -- Process registration
86
   P_FSM_State_Reg:process(i_Reset_n, i_Clock)
87
   begin
88
      if (i_Reset_n='0') then
89
         sm_State <= init;
90
      elsif (rising_edge(i_Clock)) then
91
            sm_State <= sm_Next_State;
92
      end if;
93
   end process;
94
   
95
   -- Outputs assertion
96
   P_FSM_Output:process(sm_State, i_Start, i_Stop, End_Count)
97
   begin
98
      Raz <= '0';
99
      Enable <= '0';
100
      Length <= c_Length;  -- Set the length value
101
      
102
      case sm_State is
103
         when init =>
104
            sm_Next_State <= loading;
105
         when loading =>
106
            -- Load the counter and initialize it
107
            Raz <= '1';
108
            sm_Next_State <= enabled;
109
         when enabled =>
110
            -- Start or stop counting depending on inputs until it finishes
111
            if (End_Count='0') then
112
               Enable <= i_Start xor not i_Stop;
113
               sm_Next_State <= enabled;
114
            else
115
               sm_Next_State <= finished;
116
            end if;
117
         when others =>
118
            sm_Next_State <= init;
119
      end case;
120
   end process;
121
end Behavioral;
122
--CODE