OpenCores
URL https://opencores.org/ocsvn/ccsds_rxtxsoc/ccsds_rxtxsoc/trunk

Subversion Repositories ccsds_rxtxsoc

[/] [ccsds_rxtxsoc/] [trunk/] [ccsds_tx_coder_convolutional.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zguig52
---- Design Name: ccsds_tx_coder_convolutional
2
---- Version: 1.0.0
3
---- Description:
4
---- Convolutional coder
5
-------------------------------
6
---- Author(s):
7
---- Guillaume REMBERT
8
-------------------------------
9
---- Licence:
10
---- MIT
11
-------------------------------
12
---- Changes list:
13
---- 2017/01/15: initial release
14
-------------------------------
15
-- TODO: puncturation + input rate /= 1
16
 
17
-- libraries used
18
library ieee;
19
use ieee.std_logic_1164.all;
20
use work.ccsds_rxtx_functions.all;
21
use work.ccsds_rxtx_types.all;
22
 
23
--=============================================================================
24
-- Entity declaration for ccsds_tx / unitary tx convolutional coder inputs and outputs
25
--=============================================================================
26
entity ccsds_tx_coder_convolutional is
27
  generic(
28
    constant CCSDS_TX_CODER_CONV_CONNEXION_VECTORS: std_logic_vector_array := ("1111001", "1011011");
29
    constant CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE: integer := 7; -- in bits
30
    constant CCSDS_TX_CODER_CONV_DATA_BUS_SIZE: integer; -- in bits
31
    constant CCSDS_TX_CODER_CONV_OPERATING_MODE: integer := 1; -- 0=streaming / 1=truncated (reset state when new frame) //TODO: terminated trellis + tailbiting
32
    constant CCSDS_TX_CODER_CONV_OUTPUT_INVERSION: boolean_array := (false, true);
33
    constant CCSDS_TX_CODER_CONV_RATE_OUTPUT: integer := 2; -- in bits/operation
34
    constant CCSDS_TX_CODER_CONV_SEED: std_logic_vector := "000000"
35
  );
36
  port(
37
    -- inputs
38
    clk_i: in std_logic;
39
    dat_i: in std_logic_vector(CCSDS_TX_CODER_CONV_DATA_BUS_SIZE-1 downto 0);
40
    dat_val_i: in std_logic;
41
    rst_i: in std_logic;
42
    -- outputs
43
    bus_o: out std_logic;
44
    dat_o: out std_logic_vector(CCSDS_TX_CODER_CONV_DATA_BUS_SIZE*CCSDS_TX_CODER_CONV_RATE_OUTPUT-1 downto 0);
45
    dat_val_o: out std_logic
46
  );
47
end ccsds_tx_coder_convolutional;
48
 
49
--=============================================================================
50
-- architecture declaration / internal components and connections
51
--=============================================================================
52
architecture rtl of ccsds_tx_coder_convolutional is
53
-- internal constants
54
  type connexion_vectors_array is array(CCSDS_TX_CODER_CONV_RATE_OUTPUT-1 downto 0) of std_logic_vector(CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-1 downto 0);
55
  signal connexion_vectors: connexion_vectors_array;
56
  constant connexion_vectors_array_size: integer := CCSDS_TX_CODER_CONV_CONNEXION_VECTORS'length;
57
  constant output_inversion_array_size: integer := CCSDS_TX_CODER_CONV_OUTPUT_INVERSION'length;
58
-- internal variable signals
59
  signal coder_busy: std_logic := '0';
60
  signal coder_memory: std_logic_vector(CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-2 downto 0) := CCSDS_TX_CODER_CONV_SEED;
61
-- components instanciation and mapping
62
  begin
63
    bus_o <= coder_busy;
64
    CONNEXION_VECTORS_GENERATOR: for vector_counter in 0 to CCSDS_TX_CODER_CONV_RATE_OUTPUT-1 generate
65
      connexion_vectors(CCSDS_TX_CODER_CONV_RATE_OUTPUT-1-vector_counter) <= convert_std_logic_vector_array_to_std_logic_vector(CCSDS_TX_CODER_CONV_CONNEXION_VECTORS, vector_counter);
66
    end generate CONNEXION_VECTORS_GENERATOR;
67
 
68
-- presynthesis checks
69
     CHKCODERP0 : if (CCSDS_TX_CODER_CONV_SEED'length /= CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-1) generate
70
      process
71
      begin
72
        report "ERROR: SEED SIZE HAS TO BE EQUAL TO CONSTRAINT SIZE - 1" severity failure;
73
              wait;
74
      end process;
75
    end generate CHKCODERP0;
76
     CHKCODERP1 : if (connexion_vectors_array_size /= CCSDS_TX_CODER_CONV_RATE_OUTPUT) generate
77
      process
78
      begin
79
        report "ERROR: CONNEXION VECTORS ARRAY SIZE HAS TO BE EQUAL TO OUTPUT RATE : " & integer'image(connexion_vectors_array_size) severity failure;
80
              wait;
81
      end process;
82
    end generate CHKCODERP1;
83
     CHKCODERP2 : if (output_inversion_array_size /= CCSDS_TX_CODER_CONV_RATE_OUTPUT) generate
84
      process
85
      begin
86
        report "ERROR: OUTPUT INVERSION ARRAY HAS TO BE EQUAL TO OUTPUT RATE" severity failure;
87
              wait;
88
      end process;
89
    end generate CHKCODERP2;
90
 
91
-- internal processing
92
    --=============================================================================
93
    -- Begin of coderp
94
    -- Convolutional encode bits based on connexion vectors
95
    --=============================================================================
96
    -- read: rst_i, dat_i, dat_val_i
97
    -- write: dat_o, dat_val_o, coder_busy
98
    -- r/w:
99
    CODERP: process (clk_i)
100
    variable coder_data_pointer: integer range -1 to (CCSDS_TX_CODER_CONV_DATA_BUS_SIZE-1) := -1;
101
    variable coder_data: std_logic_vector(CCSDS_TX_CODER_CONV_DATA_BUS_SIZE-1 downto 0) := (others => '0');
102
    variable coder_atomic_result: std_logic := '0';
103
    begin
104
      -- on each clock rising edge
105
      if rising_edge(clk_i) then
106
        -- reset signal received
107
        if (rst_i = '1') then
108
--          dat_o <= (others => '0');
109
          dat_val_o <= '0';
110
          coder_memory <= CCSDS_TX_CODER_CONV_SEED;
111
          coder_data_pointer := -1;
112
          coder_atomic_result := '0';
113
          coder_busy <= '0';
114
        else
115
          case coder_data_pointer is
116
            -- no current computation
117
            when -1 =>
118
              dat_val_o <= '0';
119
              -- reset on new frame behaviour
120
              if (CCSDS_TX_CODER_CONV_OPERATING_MODE = 1) then
121
                coder_memory <= CCSDS_TX_CODER_CONV_SEED;
122
              end if;
123
              -- store data
124
              if (dat_val_i = '1') then
125
                coder_data := dat_i;
126
                coder_busy <= '1';
127
                coder_data_pointer := CCSDS_TX_CODER_CONV_DATA_BUS_SIZE-1;
128
              else
129
                -- nothing to be done
130
                coder_busy <= '0';
131
              end if;
132
            -- processing
133
            when others =>
134
              coder_busy <= '1';
135
              dat_val_o <= '0';
136
              -- shift memory
137
              coder_memory <= coder_memory(CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-3 downto 0) & coder_data(coder_data_pointer);
138
              -- compute output
139
              for i in CCSDS_TX_CODER_CONV_RATE_OUTPUT-1 downto 0 loop
140
                if (connexion_vectors(i)(CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-1) = '1') then
141
                  coder_atomic_result := coder_data(coder_data_pointer);
142
                else
143
                  coder_atomic_result := '0';
144
                end if;
145
                for j in CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-2 downto 0 loop
146
                  if (connexion_vectors(i)(j) = '1') then
147
                    coder_atomic_result := coder_atomic_result xor coder_memory(CCSDS_TX_CODER_CONV_CONSTRAINT_SIZE-2-j);
148
                  end if;
149
                end loop;
150
                if (CCSDS_TX_CODER_CONV_OUTPUT_INVERSION(CCSDS_TX_CODER_CONV_RATE_OUTPUT-1-i) = true) then
151
                  dat_o(coder_data_pointer*CCSDS_TX_CODER_CONV_RATE_OUTPUT+i) <= not(coder_atomic_result);
152
                else
153
                  dat_o(coder_data_pointer*CCSDS_TX_CODER_CONV_RATE_OUTPUT+i) <= coder_atomic_result;
154
                end if;
155
              end loop;
156
              -- output is computed
157
              if (coder_data_pointer = 0) then
158
                coder_busy <= '0';
159
                dat_val_o <= '1';
160
              end if;
161
              coder_data_pointer := coder_data_pointer - 1;
162
          end case;
163
        end if;
164
      end if;
165
    end process;
166
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.