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 259

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 196 jshamlet
-- "1_1111_1101" (0x1FD) RX Buffer END
37 201 jshamlet
-- "1_1111_1110" (0x0FE) RX Checksum Status***
38
-- "1_1111_1111" (0x1FF) RX Length   Status****
39 192 jshamlet
--
40 201 jshamlet
-- *    Address 0xFE reports the SDLC bit clock status and updates on changes.
41
--      1) If BClk_Okay = '0' (Bitclock is NOT present), the field will report
42
--          0x00. Otherwise, it will report 0xFF if the bitclock is present.
43
--      2) Writing any value to the register will cause the controller to
44
--         silently reset the clock status without causing an interrupt.
45 199 jshamlet
--
46 201 jshamlet
-- **   This location serves as the control/status register for transmit
47
--      1) Writing a value between 1 and 253 will trigger the transmit engine,
48
--          using the write value as the packet length.
49
--      2) Values 0x00, 0xFE, or 0xFF are invalid, and will be ignored.
50
--      3) This value will change from the user written value to 0xFF once the
51
--          packet is transmitted to indicate the transmission is complete.
52 199 jshamlet
--
53 201 jshamlet
-- ***  This location serves as the status register for receive checksum test
54
--      1) A value of 0x00 indicates the CRC did NOT match, while a value
55
--         of 0xFF indicates that the recieved CRC matches the calculated CRC.
56
--
57
-- **** This location serves as the status register for the receive
58
--      1) This value is only updated on reception of a full frame, indicated
59
--          by a start followed by a stop flag. Incomplete frames are ignored.
60 204 jshamlet
--      2) If too many bytes are received (buffer overflow), a value of
61 201 jshamlet
--          ERR_LENGTH is written.
62 224 jshamlet
--
63
-- Revision History
64
-- Author          Date     Change
65
------------------ -------- ---------------------------------------------------
66
-- Seth Henry      04/16/20 Revision block added
67 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
68 192 jshamlet
 
69
library ieee;
70
  use ieee.std_logic_1164.all;
71
  use ieee.std_logic_unsigned.all;
72
  use ieee.std_logic_arith.all;
73
 
74
library work;
75
  use work.open8_pkg.all;
76
 
77
library work;
78
  use work.sdlc_serial_pkg.all;
79
 
80
entity o8_sdlc_if is
81
generic(
82
  Poly_Init                  : std_logic_vector(15 downto 0) := x"0000";
83
  Set_As_Master              : boolean := true;
84
  Clock_Offset               : integer := 6;
85 224 jshamlet
  BitClock_Frequency         : real := 500000.0;
86
  Clock_Frequency            : real := 100000000.0;
87 192 jshamlet
  Address                    : ADDRESS_TYPE
88
);
89
port(
90 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
91 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
92 192 jshamlet
  Rd_Data                    : out DATA_TYPE;
93
  Interrupt                  : out std_logic;
94
  -- Serial IO
95
  SDLC_In                    : in  std_logic;
96
  SDLC_SClk                  : in  std_logic;
97
  SDLC_MClk                  : out std_logic;
98
  SDLC_Out                   : out std_logic
99
);
100
end entity;
101
 
102
architecture behave of o8_sdlc_if is
103
 
104 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
105
  alias Reset                is Open8_Bus.Reset;
106
 
107 192 jshamlet
  constant Base_Addr         : std_logic_vector(15 downto 9)
108
                               := Address(15 downto 9);
109
 
110 223 jshamlet
  alias CPU_Upper_Addr       is Open8_Bus.Address(15 downto 9);
111 205 jshamlet
  signal Base_Addr_Match     : std_logic := '0';
112 192 jshamlet
 
113 244 jshamlet
  alias  DP_A_Addr           is Open8_Bus.Address(8 downto 0);
114 205 jshamlet
  signal DP_A_Wr_En          : std_logic := '0';
115 223 jshamlet
  alias  DP_A_Wr_Data        is Open8_Bus.Wr_Data;
116 244 jshamlet
  signal DP_A_Rd_En_d        : std_logic := '0';
117
  signal DP_A_Rd_En_q        : std_logic := '0';
118 205 jshamlet
  signal DP_A_Rd_Data        : DATA_TYPE := OPEN8_NULLBUS;
119 192 jshamlet
 
120 196 jshamlet
  constant Reg_Sub_Addr      : std_logic_vector(8 downto 1) := x"7F";
121 223 jshamlet
  alias Reg_Upper_Addr       is Open8_Bus.Address(8 downto 1);
122
  alias Reg_Lower_Addr       is Open8_Bus.Address(0);
123 196 jshamlet
 
124
  signal Reg_Addr            : std_logic_vector(8 downto 1) := (others => '0');
125 205 jshamlet
  signal Reg_Sel             : std_logic     := '0';
126 244 jshamlet
  signal Reg_Wr_En_d         : std_logic     := '0';
127
  signal Reg_Wr_En_q         : std_logic     := '0';
128 205 jshamlet
  signal Reg_Clk_Sel         : std_logic     := '0';
129
  signal Reg_TxS_Sel         : std_logic     := '0';
130 196 jshamlet
 
131 205 jshamlet
  signal DP_B_Addr           : std_logic_vector(8 downto 0) := (others => '0');
132
  signal DP_B_Wr_Data        : DATA_IN_TYPE  := x"00";
133
  signal DP_B_Wr_En          : std_logic     := '0';
134
  signal DP_B_Rd_Data        : DATA_IN_TYPE  := x"00";
135 192 jshamlet
 
136 202 jshamlet
  signal DP_Port0_Addr       : DATA_IN_TYPE  := x"00";
137
  signal DP_Port0_RWn        : std_logic     := '0';
138
  signal DP_Port0_WrData     : DATA_IN_TYPE  := x"00";
139
  signal DP_Port0_RdData     : DATA_IN_TYPE  := x"00";
140
  signal DP_Port0_Req        : std_logic     := '0';
141
  signal DP_Port0_Ack        : std_logic     := '0';
142
 
143
  signal DP_Port1_Addr       : DATA_IN_TYPE  := x"00";
144
  signal DP_Port1_RWn        : std_logic     := '0';
145
  signal DP_Port1_WrData     : DATA_IN_TYPE  := x"00";
146
  signal DP_Port1_RdData     : DATA_IN_TYPE  := x"00";
147
  signal DP_Port1_Req        : std_logic     := '0';
148
  signal DP_Port1_Ack        : std_logic     := '0';
149
 
150 205 jshamlet
  signal BClk_RE             : std_logic     := '0';
151
  signal BClk_FE             : std_logic     := '0';
152 202 jshamlet
  signal BClk_Okay           : std_logic     := '0';
153 192 jshamlet
 
154 202 jshamlet
  signal TX_Wr_En            : std_logic     := '0';
155
  signal TX_Wr_Flag          : std_logic     := '0';
156
  signal TX_Wr_Data          : DATA_IN_TYPE  := x"00";
157
  signal TX_Req_Next         : std_logic     := '0';
158 192 jshamlet
 
159 202 jshamlet
  signal TX_CRC_Clr          : std_logic     := '0';
160
  signal TX_CRC_En           : std_logic     := '0';
161
  signal TX_CRC_Data         : CRC_OUT_TYPE  := x"0000";
162
  signal TX_CRC_Valid        : std_logic     := '0';
163 192 jshamlet
 
164 202 jshamlet
  signal TX_Interrupt        : std_logic     := '0';
165 192 jshamlet
 
166 202 jshamlet
  signal RX_Valid            : std_logic     := '0';
167
  signal RX_Flag             : std_logic     := '0';
168
  signal RX_Data             : DATA_IN_TYPE;
169
  signal RX_Idle             : std_logic     := '0';
170 192 jshamlet
 
171 202 jshamlet
  signal RX_Frame_Start      : std_logic     := '0';
172
  signal RX_Frame_Stop       : std_logic     := '0';
173
  signal RX_Frame_Valid      : std_logic     := '0';
174
  signal RX_Frame_Data       : DATA_IN_TYPE  := x"00";
175 192 jshamlet
 
176 202 jshamlet
  signal RX_CRC_Valid        : std_logic     := '0';
177
  signal RX_CRC_Data         : CRC_OUT_TYPE  := x"0000";
178
 
179
  signal RX_Interrupt        : std_logic     := '0';
180
 
181 192 jshamlet
begin
182
 
183 202 jshamlet
-- ***************************************************************************
184
-- *          Open8 Bus Interface and Control Register Detection             *
185
-- ***************************************************************************
186
 
187 192 jshamlet
  -- This decode needs to happen immediately, to give the RAM a chance to
188
  --  do the lookup before we have to set Rd_Data
189 205 jshamlet
  Base_Addr_Match            <= '1' when Base_Addr = CPU_Upper_Addr else '0';
190 244 jshamlet
  Reg_Wr_En_d                <= Base_Addr_Match and
191
                                Open8_Bus.Wr_En and
192
                                Write_Qual;
193 192 jshamlet
 
194 250 jshamlet
  DP_A_Wr_En                 <= Base_Addr_Match and
195 244 jshamlet
                                Open8_Bus.Wr_En and
196
                                Write_Qual;
197
 
198
  DP_A_Rd_En_d               <= Base_Addr_Match and Open8_Bus.Rd_En;
199
 
200 206 jshamlet
  CPU_IF_proc: process( Reset, Clock )
201 192 jshamlet
  begin
202
    if( Reset = Reset_Level )then
203
      Reg_Addr               <= (others => '0');
204 244 jshamlet
      Reg_Wr_En_q            <= '0';
205 196 jshamlet
      Reg_Clk_Sel            <= '0';
206
      Reg_TxS_Sel            <= '0';
207 244 jshamlet
      DP_A_Rd_En_q           <= '0';
208 192 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
209 206 jshamlet
      Interrupt              <= '0';
210 192 jshamlet
    elsif( rising_edge(Clock) )then
211 196 jshamlet
      Reg_Addr               <= Reg_Upper_Addr;
212
      Reg_Sel                <= Reg_Lower_Addr;
213 244 jshamlet
      Reg_Wr_En_q            <= Reg_Wr_En_d;
214 192 jshamlet
 
215 196 jshamlet
      Reg_Clk_Sel            <= '0';
216
      Reg_TxS_Sel            <= '0';
217 192 jshamlet
      if( Reg_Addr = Reg_Sub_Addr )then
218 244 jshamlet
        Reg_Clk_Sel          <= Reg_Wr_En_q and not Reg_Sel;
219
        Reg_TxS_Sel          <= Reg_Wr_En_q and Reg_Sel;
220 192 jshamlet
      end if;
221
 
222 244 jshamlet
      DP_A_Rd_En_q           <= DP_A_Rd_En_d;
223 192 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
224 244 jshamlet
      if( DP_A_Rd_En_q = '1' )then
225 205 jshamlet
        Rd_Data              <= DP_A_Rd_Data;
226 192 jshamlet
      end if;
227 206 jshamlet
 
228
      Interrupt              <= RX_Interrupt or TX_Interrupt;
229 192 jshamlet
    end if;
230
  end process;
231
 
232 202 jshamlet
-- ***************************************************************************
233
-- *                     Shared Dual-Port Memory                             *
234
-- ***************************************************************************
235
 
236 200 jshamlet
  U_RAM : entity work.sdlc_dp512b_ram
237 192 jshamlet
  port map(
238
    clock                    => Clock,
239 205 jshamlet
    address_a                => DP_A_Addr,
240
    address_b                => DP_B_Addr,
241
    data_a                   => DP_A_Wr_Data,
242
    data_b                   => DP_B_Wr_Data,
243
    wren_a                   => DP_A_Wr_En,
244
    wren_b                   => DP_B_Wr_En,
245
    q_a                      => DP_A_Rd_Data,
246
    q_b                      => DP_B_Rd_Data
247 192 jshamlet
  );
248
 
249 202 jshamlet
-- ***************************************************************************
250
-- *                     Memory Arbitration                                  *
251
-- ***************************************************************************
252
 
253
  U_ARB : entity work.sdlc_serial_arbfsm
254
  generic map(
255
    Reset_Level              => Reset_Level
256
  )
257
  port map(
258
    Clock                    => Clock,
259
    Reset                    => Reset,
260
    --
261 205 jshamlet
    DP_Addr                  => DP_B_Addr,
262
    DP_Wr_Data               => DP_B_Wr_Data,
263
    DP_Wr_En                 => DP_B_Wr_En,
264
    DP_Rd_Data               => DP_B_Rd_Data,
265
    --
266 202 jshamlet
    DP_Port0_Addr            => DP_Port0_Addr,
267
    DP_Port0_RWn             => DP_Port0_RWn,
268
    DP_Port0_WrData          => DP_Port0_WrData,
269
    DP_Port0_RdData          => DP_Port0_RdData,
270
    DP_Port0_Req             => DP_Port0_Req,
271
    DP_Port0_Ack             => DP_Port0_Ack,
272
    --
273
    DP_Port1_Addr            => DP_Port1_Addr,
274
    DP_Port1_RWn             => DP_Port1_RWn,
275
    DP_Port1_WrData          => DP_Port1_WrData,
276
    DP_Port1_RdData          => DP_Port1_RdData,
277
    DP_Port1_Req             => DP_Port1_Req,
278 205 jshamlet
    DP_Port1_Ack             => DP_Port1_Ack
279 202 jshamlet
  );
280
 
281
-- ***************************************************************************
282
-- *                        Serial BitClock                                  *
283
-- ***************************************************************************
284
 
285 192 jshamlet
  U_BCLK : entity work.sdlc_serial_clk
286
  generic map(
287
    Set_As_Master            => Set_As_Master,
288 224 jshamlet
    BitClock_Freq            => BitClock_Frequency,
289 192 jshamlet
    Reset_Level              => Reset_Level,
290 224 jshamlet
    Sys_Freq                 => Clock_Frequency
291 192 jshamlet
  )
292
  port map(
293
    Clock                    => Clock,
294
    Reset                    => Reset,
295
    --
296
    BClk_In                  => SDLC_SClk,
297
    BClk_Out                 => SDLC_MClk,
298
    BClk_FE                  => BClk_FE,
299
    BClk_RE                  => BClk_RE,
300
    BClk_Okay                => BClk_Okay
301
  );
302
 
303 202 jshamlet
-- ***************************************************************************
304
-- *                     Serial Transmit Path                                *
305
-- ***************************************************************************
306
 
307
  U_TXFSM: entity work.sdlc_serial_txfsm
308 192 jshamlet
  generic map(
309
    Reset_Level              => Reset_Level
310
  )
311
  port map(
312
    Clock                    => Clock,
313
    Reset                    => Reset,
314
    --
315
    BClk_Okay                => BClk_Okay,
316
    --
317 196 jshamlet
    Reg_Clk_Sel              => Reg_Clk_Sel,
318
    Reg_TxS_Sel              => Reg_TxS_Sel,
319 192 jshamlet
    --
320 202 jshamlet
    DP_Port0_Addr            => DP_Port0_Addr,
321
    DP_Port0_RWn             => DP_Port0_RWn,
322
    DP_Port0_WrData          => DP_Port0_WrData,
323
    DP_Port0_RdData          => DP_Port0_RdData,
324
    DP_Port0_Req             => DP_Port0_Req,
325
    DP_Port0_Ack             => DP_Port0_Ack,
326 192 jshamlet
    --
327
    TX_Wr_En                 => TX_Wr_En,
328
    TX_Wr_Flag               => TX_Wr_Flag,
329
    TX_Wr_Data               => TX_Wr_Data,
330
    TX_Req_Next              => TX_Req_Next,
331
    --
332
    TX_CRC_Clr               => TX_CRC_Clr,
333
    TX_CRC_En                => TX_CRC_En,
334
    TX_CRC_Data              => TX_CRC_Data,
335
    TX_CRC_Valid             => TX_CRC_Valid,
336
    --
337 202 jshamlet
    TX_Interrupt             => TX_Interrupt
338
  );
339
 
340
  U_TX_CRC : entity work.sdlc_crc16_ccitt
341
  generic map(
342
    Poly_Init                => Poly_Init,
343
    Reset_Level              => Reset_Level
344
  )
345
  port map(
346
    Clock                    => Clock,
347
    Reset                    => Reset,
348 192 jshamlet
    --
349 202 jshamlet
    Clear                    => TX_CRC_Clr,
350
    Wr_En                    => TX_CRC_En,
351
    Wr_Data                  => TX_Wr_Data,
352 192 jshamlet
    --
353 202 jshamlet
    CRC16_Valid              => TX_CRC_Valid,
354
    CRC16_Out                => TX_CRC_Data
355 192 jshamlet
  );
356
 
357
  U_TX_SER : entity work.sdlc_serial_tx
358
  generic map(
359
    Reset_Level              => Reset_Level
360
  )
361
  port map(
362
    Clock                    => Clock,
363
    Reset                    => Reset,
364
    --
365
    BClk_FE                  => BClk_FE,
366
    BClk_RE                  => BClk_RE,
367
    BClk_Okay                => BClk_Okay,
368
    --
369
    TX_En                    => TX_Wr_En,
370
    TX_FSS_Flag              => TX_Wr_Flag,
371
    TX_Data                  => TX_Wr_Data,
372
    TX_Req_Next              => TX_Req_Next,
373
    --
374
    Serial_Out               => SDLC_Out
375
  );
376
 
377 202 jshamlet
-- ***************************************************************************
378
-- *                     Serial Receive Path                                 *
379
-- ***************************************************************************
380 192 jshamlet
 
381
  U_RX_SER : entity work.sdlc_serial_rx
382
  generic map(
383
    Set_As_Master            => Set_As_Master,
384
    Clock_Offset             => Clock_Offset,
385
    Reset_Level              => Reset_Level
386
  )
387
  port map(
388
    Clock                    => Clock,
389
    Reset                    => Reset,
390
    --
391
    BClk_RE                  => BClk_RE,
392
    BClk_Okay                => BClk_Okay,
393
    --
394
    Serial_In                => SDLC_In,
395
    --
396
    RX_Valid                 => RX_Valid,
397
    RX_Flag                  => RX_Flag,
398
    RX_Data                  => RX_Data,
399
    RX_Idle                  => RX_Idle
400
  );
401
 
402 202 jshamlet
  U_RX_PKT : entity work.sdlc_serial_frame
403
  generic map(
404
    Reset_Level              => Reset_Level
405
  )
406
  port map(
407
    Clock                    => Clock,
408
    Reset                    => Reset,
409
    --
410
    RX_Valid                 => RX_Valid,
411
    RX_Flag                  => RX_Flag,
412
    RX_Data                  => RX_Data,
413
    RX_Idle                  => RX_Idle,
414
    --
415
    RX_Frame_Start           => RX_Frame_Start,
416
    RX_Frame_Stop            => RX_Frame_Stop,
417
    RX_Frame_Valid           => RX_Frame_Valid,
418
    RX_Frame_Data            => RX_Frame_Data
419
  );
420
 
421 192 jshamlet
  U_RX_CRC : entity work.sdlc_crc16_ccitt
422
  generic map(
423
    Poly_Init                => Poly_Init,
424
    Reset_Level              => Reset_Level
425
  )
426
  port map(
427
    Clock                    => Clock,
428
    Reset                    => Reset,
429
    --
430 202 jshamlet
    Clear                    => RX_Frame_Start,
431
    Wr_En                    => RX_Frame_Valid,
432
    Wr_Data                  => RX_Frame_Data,
433 192 jshamlet
    --
434 202 jshamlet
    CRC16_Valid              => RX_CRC_Valid,
435
    CRC16_Out                => RX_CRC_Data
436 192 jshamlet
  );
437
 
438 202 jshamlet
  U_RX_FSM : entity work.sdlc_serial_rxfsm
439
  generic map(
440
    Reset_Level              => Reset_Level
441
  )
442
  port map(
443
    Clock                    => Clock,
444
    Reset                    => Reset,
445
    --
446
    BClk_Okay                => BClk_Okay,
447
    --
448
    DP_Port1_Addr            => DP_Port1_Addr,
449
    DP_Port1_RWn             => DP_Port1_RWn,
450
    DP_Port1_WrData          => DP_Port1_WrData,
451
    DP_Port1_RdData          => DP_Port1_RdData,
452
    DP_Port1_Req             => DP_Port1_Req,
453
    DP_Port1_Ack             => DP_Port1_Ack,
454
    --
455
    RX_CRC_Valid             => RX_CRC_Valid,
456
    RX_CRC_Data              => RX_CRC_Data,
457
    --
458
    RX_Frame_Start           => RX_Frame_Start,
459
    RX_Frame_Stop            => RX_Frame_Stop,
460
    RX_Frame_Valid           => RX_Frame_Valid,
461
    RX_Frame_Data            => RX_Frame_Data,
462
    --
463
    RX_Interrupt             => RX_Interrupt
464
  );
465
 
466 192 jshamlet
end architecture;

powered by: WebSVN 2.1.0

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