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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_sdlc_if.vhd] - Blame information for rev 192

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 192 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_sdlc_if
25
-- Description:  Provides a full memory-mapped SDLC stack with automatic CRC16
26
--                Checksum insertion and integrity checking.
27
--
28
-- Transmit Memory Map
29
-- "0_0000_0000" (0x000) TX Buffer START
30
-- "0_1111_1101" (0x0FD) TX Buffer END
31
-- "0_1111_1110" (0x0FE) Clock Status*
32
-- "0_1111_1111" (0x0FF) TX Length / Status**
33
--
34
-- Receive Memory Map
35
-- "1_0000_0000" (0x100) RX Buffer START
36
-- "1_1111_1110" (0x1FE) RX Buffer END
37
-- "1_1111_1111" (0x1FF) RX Length / Status
38
--
39
-- * Address 0xFE reports the SDLC bit clock status and updates on changes. If
40
--    the bit clock goes away (BClk_Okay = '0'), the field will report 0x00.
41
--    otherwise it will report 0xFF. Note that the CPU can overwrite this
42
--    location, at which point the status will be invalid.
43
--
44
-- ** This location serves as the control/status register for the interface
45
--    1) Writing 0x00 will reset the clock status flag in 0xFE without
46
--        triggering an interrupt.
47
--    2) Writing a value between 1 and 253 will trigger the transmit engine,
48
--        using the write value as the packet length.
49
--    3) Writing 0xFE or 0xFF will be ignored by the engine.
50
--    4) This value will change from the user written value to 0xFF once the
51
--        packet is transmitted.
52
--
53
 
54
library ieee;
55
  use ieee.std_logic_1164.all;
56
  use ieee.std_logic_unsigned.all;
57
  use ieee.std_logic_arith.all;
58
 
59
library work;
60
  use work.open8_pkg.all;
61
 
62
library work;
63
  use work.sdlc_serial_pkg.all;
64
 
65
entity o8_sdlc_if is
66
generic(
67
  Poly_Init                  : std_logic_vector(15 downto 0) := x"0000";
68
  Set_As_Master              : boolean := true;
69
  Clock_Offset               : integer := 6;
70
  BitClock_Freq              : real := 500000.0;
71
  Sys_Freq                   : real := 100000000.0;
72
  Reset_Level                : std_logic := '1';
73
  Address                    : ADDRESS_TYPE
74
);
75
port(
76
  Clock                      : in  std_logic;
77
  Reset                      : in  std_logic;
78
  --
79
  Bus_Address                : in  ADDRESS_TYPE;
80
  Wr_Enable                  : in  std_logic;
81
  Wr_Data                    : in  DATA_TYPE;
82
  Rd_Enable                  : in  std_logic;
83
  Rd_Data                    : out DATA_TYPE;
84
  Interrupt                  : out std_logic;
85
  -- Serial IO
86
  SDLC_In                    : in  std_logic;
87
  SDLC_SClk                  : in  std_logic;
88
  SDLC_MClk                  : out std_logic;
89
  SDLC_Out                   : out std_logic
90
);
91
end entity;
92
 
93
architecture behave of o8_sdlc_if is
94
 
95
  -- Connect the CPU to the dual-port memory
96
  constant Base_Addr         : std_logic_vector(15 downto 9)
97
                               := Address(15 downto 9);
98
 
99
  alias RAM_Upper_Addr       is Bus_Address(15 downto 9);
100
  alias RAM_Lower_Addr       is Bus_Address(8 downto 0);
101
 
102
  signal RAM_Addr_Match      : std_logic := '0';
103
  signal RAM_Wr_En           : std_logic := '0';
104
  signal RAM_Rd_En           : std_logic := '0';
105
  signal Rd_Data_i           : DATA_TYPE := OPEN8_NULLBUS;
106
 
107
  constant Reg_Sub_Addr      : std_logic_vector(8 downto 0) :=
108
                               conv_std_logic_vector(255,9);
109
 
110
  signal Reg_Addr            : std_logic_vector(8 downto 0) := (others => '0');
111
  signal Reg_Wr_En           : std_logic := '0';
112
  signal Reg_Updated         : std_logic := '0';
113
  -- Connect the serial engine to the dual-port memory
114
  signal DP_Addr             : std_logic_vector(8 downto 0) := (others => '0');
115
  signal DP_Wr_Data          : DATA_IN_TYPE := x"00";
116
  signal DP_Wr_En            : std_logic := '0';
117
  signal DP_Rd_Data          : DATA_IN_TYPE := x"00";
118
 
119
  signal BClk_RE             : std_logic := '0';
120
  signal BClk_FE             : std_logic := '0';
121
 
122
  signal TX_Wr_En            : std_logic := '0';
123
  signal TX_Wr_Flag          : std_logic := '0';
124
  signal TX_Wr_Data          : DATA_IN_TYPE := x"00";
125
  signal TX_Req_Next         : std_logic := '0';
126
 
127
  signal TX_CRC_Clr          : std_logic := '0';
128
  signal TX_CRC_En           : std_logic := '0';
129
  signal TX_CRC_Data         : CRC_OUT_TYPE := x"0000";
130
  alias  TX_CRC_Data_LB      is TX_CRC_Data(7 downto 0);
131
  alias  TX_CRC_Data_UB      is TX_CRC_Data(15 downto 8);
132
  signal TX_CRC_Valid        : std_logic := '0';
133
 
134
  signal RX_Valid            : std_logic := '0';
135
  signal RX_Flag             : std_logic := '0';
136
  signal RX_Data             : DATA_IN_TYPE := x"00";
137
  signal RX_Idle             : std_logic := '0';
138
 
139
  signal RX_CRC_Clr          : std_logic := '0';
140
  signal RX_CRC_En           : std_logic := '0';
141
  signal RX_CRC_Data         : CRC_OUT_TYPE := x"0000";
142
  signal RX_CRC_Valid        : std_logic := '0';
143
 
144
  signal BClk_Okay           : std_logic := '0';
145
 
146
begin
147
 
148
  -- This decode needs to happen immediately, to give the RAM a chance to
149
  --  do the lookup before we have to set Rd_Data
150
  RAM_Addr_Match             <= '1' when Base_Addr = RAM_Upper_Addr else '0';
151
  RAM_Wr_En                  <= RAM_Addr_Match and Wr_Enable;
152
 
153
  CPU_RAM_proc: process( Reset, Clock )
154
  begin
155
    if( Reset = Reset_Level )then
156
      Reg_Addr               <= (others => '0');
157
      Reg_Wr_En              <= '0';
158
      Reg_Updated            <= '0';
159
      RAM_Rd_En              <= '0';
160
      Rd_Data                <= OPEN8_NULLBUS;
161
    elsif( rising_edge(Clock) )then
162
      Reg_Addr               <= RAM_Lower_Addr;
163
      Reg_Wr_En              <= RAM_Addr_Match and Wr_Enable;
164
 
165
      Reg_Updated            <= '0';
166
      if( Reg_Addr = Reg_Sub_Addr )then
167
        Reg_Updated          <= Reg_Wr_En;
168
      end if;
169
 
170
      RAM_Rd_En              <= RAM_Addr_Match and Rd_Enable;
171
      Rd_Data                <= OPEN8_NULLBUS;
172
      if( RAM_Rd_En = '1' )then
173
        Rd_Data              <= Rd_Data_i;
174
      end if;
175
    end if;
176
  end process;
177
 
178
  U_RAM : entity work.ram_dp512b_core
179
  port map(
180
    clock                    => Clock,
181
    address_a                => RAM_Lower_Addr,
182
    address_b                => DP_Addr,
183
    data_a                   => Wr_Data,
184
    data_b                   => DP_Wr_Data,
185
    wren_a                   => RAM_Wr_En,
186
    wren_b                   => DP_Wr_En,
187
    q_a                      => Rd_Data_i,
188
    q_b                      => DP_Rd_Data
189
  );
190
 
191
  U_BCLK : entity work.sdlc_serial_clk
192
  generic map(
193
    Set_As_Master            => Set_As_Master,
194
    BitClock_Freq            => BitClock_Freq,
195
    Reset_Level              => Reset_Level,
196
    Sys_Freq                 => Sys_Freq
197
  )
198
  port map(
199
    Clock                    => Clock,
200
    Reset                    => Reset,
201
    --
202
    BClk_In                  => SDLC_SClk,
203
    BClk_Out                 => SDLC_MClk,
204
    BClk_FE                  => BClk_FE,
205
    BClk_RE                  => BClk_RE,
206
    BClk_Okay                => BClk_Okay
207
  );
208
 
209
  U_CTRL : entity work.sdlc_serial_ctrl
210
  generic map(
211
    Reset_Level              => Reset_Level
212
  )
213
  port map(
214
    Clock                    => Clock,
215
    Reset                    => Reset,
216
    --
217
    BClk_Okay                => BClk_Okay,
218
    --
219
    Reg_Updated              => Reg_Updated,
220
    --
221
    DP_Addr                  => DP_Addr,
222
    DP_Wr_Data               => DP_Wr_Data,
223
    DP_Wr_En                 => DP_Wr_En,
224
    DP_Rd_Data               => DP_Rd_Data,
225
    --
226
    TX_Wr_En                 => TX_Wr_En,
227
    TX_Wr_Flag               => TX_Wr_Flag,
228
    TX_Wr_Data               => TX_Wr_Data,
229
    TX_Req_Next              => TX_Req_Next,
230
    --
231
    TX_CRC_Clr               => TX_CRC_Clr,
232
    TX_CRC_En                => TX_CRC_En,
233
    TX_CRC_Data              => TX_CRC_Data,
234
    TX_CRC_Valid             => TX_CRC_Valid,
235
    --
236
    RX_Valid                 => RX_Valid,
237
    RX_Flag                  => RX_Flag,
238
    RX_Data                  => RX_Data,
239
    RX_Idle                  => RX_Idle,
240
    --
241
    RX_CRC_Clr               => RX_CRC_Clr,
242
    RX_CRC_En                => RX_CRC_En,
243
    RX_CRC_Data              => RX_CRC_Data,
244
    RX_CRC_Valid             => RX_CRC_Valid,
245
    --
246
    Interrupt                => Interrupt
247
  );
248
 
249
  U_TX_SER : entity work.sdlc_serial_tx
250
  generic map(
251
    Reset_Level              => Reset_Level
252
  )
253
  port map(
254
    Clock                    => Clock,
255
    Reset                    => Reset,
256
    --
257
    BClk_FE                  => BClk_FE,
258
    BClk_RE                  => BClk_RE,
259
    BClk_Okay                => BClk_Okay,
260
    --
261
    TX_En                    => TX_Wr_En,
262
    TX_FSS_Flag              => TX_Wr_Flag,
263
    TX_Data                  => TX_Wr_Data,
264
    TX_Req_Next              => TX_Req_Next,
265
    --
266
    Serial_Out               => SDLC_Out
267
  );
268
 
269
  U_TX_CRC : entity work.sdlc_crc16_ccitt
270
  generic map(
271
    Poly_Init                => Poly_Init,
272
    Reset_Level              => Reset_Level
273
  )
274
  port map(
275
    Clock                    => Clock,
276
    Reset                    => Reset,
277
    --
278
    Clear                    => TX_CRC_Clr,
279
    Wr_Data                  => TX_Wr_Data,
280
    Wr_En                    => TX_CRC_En,
281
    --
282
    CRC16_Out                => TX_CRC_Data,
283
    CRC16_Valid              => TX_CRC_Valid
284
  );
285
 
286
  U_RX_SER : entity work.sdlc_serial_rx
287
  generic map(
288
    Set_As_Master            => Set_As_Master,
289
    Clock_Offset             => Clock_Offset,
290
    Reset_Level              => Reset_Level
291
  )
292
  port map(
293
    Clock                    => Clock,
294
    Reset                    => Reset,
295
    --
296
    BClk_RE                  => BClk_RE,
297
    BClk_Okay                => BClk_Okay,
298
    --
299
    Serial_In                => SDLC_In,
300
    --
301
    RX_Valid                 => RX_Valid,
302
    RX_Flag                  => RX_Flag,
303
    RX_Data                  => RX_Data,
304
    RX_Idle                  => RX_Idle
305
  );
306
 
307
  U_RX_CRC : entity work.sdlc_crc16_ccitt
308
  generic map(
309
    Poly_Init                => Poly_Init,
310
    Reset_Level              => Reset_Level
311
  )
312
  port map(
313
    Clock                    => Clock,
314
    Reset                    => Reset,
315
    --
316
    Clear                    => RX_CRC_Clr,
317
    Wr_Data                  => RX_Data,
318
    Wr_En                    => RX_CRC_En,
319
    --
320
    CRC16_Out                => RX_CRC_Data,
321
    CRC16_Valid              => RX_CRC_Valid
322
  );
323
 
324
end architecture;

powered by: WebSVN 2.1.0

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