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 263

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 263 jshamlet
  TX_Interrupt               : out std_logic;
94
  RX_Interrupt               : out std_logic;
95 192 jshamlet
  -- Serial IO
96
  SDLC_In                    : in  std_logic;
97
  SDLC_SClk                  : in  std_logic;
98
  SDLC_MClk                  : out std_logic;
99
  SDLC_Out                   : out std_logic
100
);
101
end entity;
102
 
103
architecture behave of o8_sdlc_if is
104
 
105 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
106
  alias Reset                is Open8_Bus.Reset;
107
 
108 192 jshamlet
  constant Base_Addr         : std_logic_vector(15 downto 9)
109
                               := Address(15 downto 9);
110
 
111 223 jshamlet
  alias CPU_Upper_Addr       is Open8_Bus.Address(15 downto 9);
112 205 jshamlet
  signal Base_Addr_Match     : std_logic := '0';
113 192 jshamlet
 
114 244 jshamlet
  alias  DP_A_Addr           is Open8_Bus.Address(8 downto 0);
115 205 jshamlet
  signal DP_A_Wr_En          : std_logic := '0';
116 223 jshamlet
  alias  DP_A_Wr_Data        is Open8_Bus.Wr_Data;
117 244 jshamlet
  signal DP_A_Rd_En_d        : std_logic := '0';
118
  signal DP_A_Rd_En_q        : std_logic := '0';
119 205 jshamlet
  signal DP_A_Rd_Data        : DATA_TYPE := OPEN8_NULLBUS;
120 192 jshamlet
 
121 196 jshamlet
  constant Reg_Sub_Addr      : std_logic_vector(8 downto 1) := x"7F";
122 223 jshamlet
  alias Reg_Upper_Addr       is Open8_Bus.Address(8 downto 1);
123
  alias Reg_Lower_Addr       is Open8_Bus.Address(0);
124 196 jshamlet
 
125
  signal Reg_Addr            : std_logic_vector(8 downto 1) := (others => '0');
126 205 jshamlet
  signal Reg_Sel             : std_logic     := '0';
127 244 jshamlet
  signal Reg_Wr_En_d         : std_logic     := '0';
128
  signal Reg_Wr_En_q         : std_logic     := '0';
129 205 jshamlet
  signal Reg_Clk_Sel         : std_logic     := '0';
130
  signal Reg_TxS_Sel         : std_logic     := '0';
131 196 jshamlet
 
132 205 jshamlet
  signal DP_B_Addr           : std_logic_vector(8 downto 0) := (others => '0');
133
  signal DP_B_Wr_Data        : DATA_IN_TYPE  := x"00";
134
  signal DP_B_Wr_En          : std_logic     := '0';
135
  signal DP_B_Rd_Data        : DATA_IN_TYPE  := x"00";
136 192 jshamlet
 
137 202 jshamlet
  signal DP_Port0_Addr       : DATA_IN_TYPE  := x"00";
138
  signal DP_Port0_RWn        : std_logic     := '0';
139
  signal DP_Port0_WrData     : DATA_IN_TYPE  := x"00";
140
  signal DP_Port0_RdData     : DATA_IN_TYPE  := x"00";
141
  signal DP_Port0_Req        : std_logic     := '0';
142
  signal DP_Port0_Ack        : std_logic     := '0';
143
 
144
  signal DP_Port1_Addr       : DATA_IN_TYPE  := x"00";
145
  signal DP_Port1_RWn        : std_logic     := '0';
146
  signal DP_Port1_WrData     : DATA_IN_TYPE  := x"00";
147
  signal DP_Port1_RdData     : DATA_IN_TYPE  := x"00";
148
  signal DP_Port1_Req        : std_logic     := '0';
149
  signal DP_Port1_Ack        : std_logic     := '0';
150
 
151 205 jshamlet
  signal BClk_RE             : std_logic     := '0';
152
  signal BClk_FE             : std_logic     := '0';
153 202 jshamlet
  signal BClk_Okay           : std_logic     := '0';
154 192 jshamlet
 
155 202 jshamlet
  signal TX_Wr_En            : std_logic     := '0';
156
  signal TX_Wr_Flag          : std_logic     := '0';
157
  signal TX_Wr_Data          : DATA_IN_TYPE  := x"00";
158
  signal TX_Req_Next         : std_logic     := '0';
159 192 jshamlet
 
160 202 jshamlet
  signal TX_CRC_Clr          : std_logic     := '0';
161
  signal TX_CRC_En           : std_logic     := '0';
162
  signal TX_CRC_Data         : CRC_OUT_TYPE  := x"0000";
163
  signal TX_CRC_Valid        : std_logic     := '0';
164 192 jshamlet
 
165 202 jshamlet
  signal RX_Valid            : std_logic     := '0';
166
  signal RX_Flag             : std_logic     := '0';
167
  signal RX_Data             : DATA_IN_TYPE;
168
  signal RX_Idle             : std_logic     := '0';
169 192 jshamlet
 
170 202 jshamlet
  signal RX_Frame_Start      : std_logic     := '0';
171
  signal RX_Frame_Stop       : std_logic     := '0';
172
  signal RX_Frame_Valid      : std_logic     := '0';
173
  signal RX_Frame_Data       : DATA_IN_TYPE  := x"00";
174 192 jshamlet
 
175 202 jshamlet
  signal RX_CRC_Valid        : std_logic     := '0';
176
  signal RX_CRC_Data         : CRC_OUT_TYPE  := x"0000";
177
 
178 192 jshamlet
begin
179
 
180 202 jshamlet
-- ***************************************************************************
181
-- *          Open8 Bus Interface and Control Register Detection             *
182
-- ***************************************************************************
183
 
184 192 jshamlet
  -- This decode needs to happen immediately, to give the RAM a chance to
185
  --  do the lookup before we have to set Rd_Data
186 205 jshamlet
  Base_Addr_Match            <= '1' when Base_Addr = CPU_Upper_Addr else '0';
187 244 jshamlet
  Reg_Wr_En_d                <= Base_Addr_Match and
188
                                Open8_Bus.Wr_En and
189
                                Write_Qual;
190 192 jshamlet
 
191 250 jshamlet
  DP_A_Wr_En                 <= Base_Addr_Match and
192 244 jshamlet
                                Open8_Bus.Wr_En and
193
                                Write_Qual;
194
 
195
  DP_A_Rd_En_d               <= Base_Addr_Match and Open8_Bus.Rd_En;
196
 
197 206 jshamlet
  CPU_IF_proc: process( Reset, Clock )
198 192 jshamlet
  begin
199
    if( Reset = Reset_Level )then
200
      Reg_Addr               <= (others => '0');
201 244 jshamlet
      Reg_Wr_En_q            <= '0';
202 196 jshamlet
      Reg_Clk_Sel            <= '0';
203
      Reg_TxS_Sel            <= '0';
204 244 jshamlet
      DP_A_Rd_En_q           <= '0';
205 192 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
206
    elsif( rising_edge(Clock) )then
207 196 jshamlet
      Reg_Addr               <= Reg_Upper_Addr;
208
      Reg_Sel                <= Reg_Lower_Addr;
209 244 jshamlet
      Reg_Wr_En_q            <= Reg_Wr_En_d;
210 192 jshamlet
 
211 196 jshamlet
      Reg_Clk_Sel            <= '0';
212
      Reg_TxS_Sel            <= '0';
213 192 jshamlet
      if( Reg_Addr = Reg_Sub_Addr )then
214 244 jshamlet
        Reg_Clk_Sel          <= Reg_Wr_En_q and not Reg_Sel;
215
        Reg_TxS_Sel          <= Reg_Wr_En_q and Reg_Sel;
216 192 jshamlet
      end if;
217
 
218 244 jshamlet
      DP_A_Rd_En_q           <= DP_A_Rd_En_d;
219 192 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
220 244 jshamlet
      if( DP_A_Rd_En_q = '1' )then
221 205 jshamlet
        Rd_Data              <= DP_A_Rd_Data;
222 192 jshamlet
      end if;
223
    end if;
224
  end process;
225
 
226 202 jshamlet
-- ***************************************************************************
227
-- *                     Shared Dual-Port Memory                             *
228
-- ***************************************************************************
229
 
230 200 jshamlet
  U_RAM : entity work.sdlc_dp512b_ram
231 192 jshamlet
  port map(
232
    clock                    => Clock,
233 205 jshamlet
    address_a                => DP_A_Addr,
234
    address_b                => DP_B_Addr,
235
    data_a                   => DP_A_Wr_Data,
236
    data_b                   => DP_B_Wr_Data,
237
    wren_a                   => DP_A_Wr_En,
238
    wren_b                   => DP_B_Wr_En,
239
    q_a                      => DP_A_Rd_Data,
240
    q_b                      => DP_B_Rd_Data
241 192 jshamlet
  );
242
 
243 202 jshamlet
-- ***************************************************************************
244
-- *                     Memory Arbitration                                  *
245
-- ***************************************************************************
246
 
247
  U_ARB : entity work.sdlc_serial_arbfsm
248
  generic map(
249
    Reset_Level              => Reset_Level
250
  )
251
  port map(
252
    Clock                    => Clock,
253
    Reset                    => Reset,
254
    --
255 205 jshamlet
    DP_Addr                  => DP_B_Addr,
256
    DP_Wr_Data               => DP_B_Wr_Data,
257
    DP_Wr_En                 => DP_B_Wr_En,
258
    DP_Rd_Data               => DP_B_Rd_Data,
259
    --
260 202 jshamlet
    DP_Port0_Addr            => DP_Port0_Addr,
261
    DP_Port0_RWn             => DP_Port0_RWn,
262
    DP_Port0_WrData          => DP_Port0_WrData,
263
    DP_Port0_RdData          => DP_Port0_RdData,
264
    DP_Port0_Req             => DP_Port0_Req,
265
    DP_Port0_Ack             => DP_Port0_Ack,
266
    --
267
    DP_Port1_Addr            => DP_Port1_Addr,
268
    DP_Port1_RWn             => DP_Port1_RWn,
269
    DP_Port1_WrData          => DP_Port1_WrData,
270
    DP_Port1_RdData          => DP_Port1_RdData,
271
    DP_Port1_Req             => DP_Port1_Req,
272 205 jshamlet
    DP_Port1_Ack             => DP_Port1_Ack
273 202 jshamlet
  );
274
 
275
-- ***************************************************************************
276
-- *                        Serial BitClock                                  *
277
-- ***************************************************************************
278
 
279 192 jshamlet
  U_BCLK : entity work.sdlc_serial_clk
280
  generic map(
281
    Set_As_Master            => Set_As_Master,
282 224 jshamlet
    BitClock_Freq            => BitClock_Frequency,
283 192 jshamlet
    Reset_Level              => Reset_Level,
284 224 jshamlet
    Sys_Freq                 => Clock_Frequency
285 192 jshamlet
  )
286
  port map(
287
    Clock                    => Clock,
288
    Reset                    => Reset,
289
    --
290
    BClk_In                  => SDLC_SClk,
291
    BClk_Out                 => SDLC_MClk,
292
    BClk_FE                  => BClk_FE,
293
    BClk_RE                  => BClk_RE,
294
    BClk_Okay                => BClk_Okay
295
  );
296
 
297 202 jshamlet
-- ***************************************************************************
298
-- *                     Serial Transmit Path                                *
299
-- ***************************************************************************
300
 
301
  U_TXFSM: entity work.sdlc_serial_txfsm
302 192 jshamlet
  generic map(
303
    Reset_Level              => Reset_Level
304
  )
305
  port map(
306
    Clock                    => Clock,
307
    Reset                    => Reset,
308
    --
309
    BClk_Okay                => BClk_Okay,
310
    --
311 196 jshamlet
    Reg_Clk_Sel              => Reg_Clk_Sel,
312
    Reg_TxS_Sel              => Reg_TxS_Sel,
313 192 jshamlet
    --
314 202 jshamlet
    DP_Port0_Addr            => DP_Port0_Addr,
315
    DP_Port0_RWn             => DP_Port0_RWn,
316
    DP_Port0_WrData          => DP_Port0_WrData,
317
    DP_Port0_RdData          => DP_Port0_RdData,
318
    DP_Port0_Req             => DP_Port0_Req,
319
    DP_Port0_Ack             => DP_Port0_Ack,
320 192 jshamlet
    --
321
    TX_Wr_En                 => TX_Wr_En,
322
    TX_Wr_Flag               => TX_Wr_Flag,
323
    TX_Wr_Data               => TX_Wr_Data,
324
    TX_Req_Next              => TX_Req_Next,
325
    --
326
    TX_CRC_Clr               => TX_CRC_Clr,
327
    TX_CRC_En                => TX_CRC_En,
328
    TX_CRC_Data              => TX_CRC_Data,
329
    TX_CRC_Valid             => TX_CRC_Valid,
330
    --
331 202 jshamlet
    TX_Interrupt             => TX_Interrupt
332
  );
333
 
334
  U_TX_CRC : entity work.sdlc_crc16_ccitt
335
  generic map(
336
    Poly_Init                => Poly_Init,
337
    Reset_Level              => Reset_Level
338
  )
339
  port map(
340
    Clock                    => Clock,
341
    Reset                    => Reset,
342 192 jshamlet
    --
343 202 jshamlet
    Clear                    => TX_CRC_Clr,
344
    Wr_En                    => TX_CRC_En,
345
    Wr_Data                  => TX_Wr_Data,
346 192 jshamlet
    --
347 202 jshamlet
    CRC16_Valid              => TX_CRC_Valid,
348
    CRC16_Out                => TX_CRC_Data
349 192 jshamlet
  );
350
 
351
  U_TX_SER : entity work.sdlc_serial_tx
352
  generic map(
353
    Reset_Level              => Reset_Level
354
  )
355
  port map(
356
    Clock                    => Clock,
357
    Reset                    => Reset,
358
    --
359
    BClk_FE                  => BClk_FE,
360
    BClk_RE                  => BClk_RE,
361
    BClk_Okay                => BClk_Okay,
362
    --
363
    TX_En                    => TX_Wr_En,
364
    TX_FSS_Flag              => TX_Wr_Flag,
365
    TX_Data                  => TX_Wr_Data,
366
    TX_Req_Next              => TX_Req_Next,
367
    --
368
    Serial_Out               => SDLC_Out
369
  );
370
 
371 202 jshamlet
-- ***************************************************************************
372
-- *                     Serial Receive Path                                 *
373
-- ***************************************************************************
374 192 jshamlet
 
375
  U_RX_SER : entity work.sdlc_serial_rx
376
  generic map(
377
    Set_As_Master            => Set_As_Master,
378
    Clock_Offset             => Clock_Offset,
379
    Reset_Level              => Reset_Level
380
  )
381
  port map(
382
    Clock                    => Clock,
383
    Reset                    => Reset,
384
    --
385
    BClk_RE                  => BClk_RE,
386
    BClk_Okay                => BClk_Okay,
387
    --
388
    Serial_In                => SDLC_In,
389
    --
390
    RX_Valid                 => RX_Valid,
391
    RX_Flag                  => RX_Flag,
392
    RX_Data                  => RX_Data,
393
    RX_Idle                  => RX_Idle
394
  );
395
 
396 202 jshamlet
  U_RX_PKT : entity work.sdlc_serial_frame
397
  generic map(
398
    Reset_Level              => Reset_Level
399
  )
400
  port map(
401
    Clock                    => Clock,
402
    Reset                    => Reset,
403
    --
404
    RX_Valid                 => RX_Valid,
405
    RX_Flag                  => RX_Flag,
406
    RX_Data                  => RX_Data,
407
    RX_Idle                  => RX_Idle,
408
    --
409
    RX_Frame_Start           => RX_Frame_Start,
410
    RX_Frame_Stop            => RX_Frame_Stop,
411
    RX_Frame_Valid           => RX_Frame_Valid,
412
    RX_Frame_Data            => RX_Frame_Data
413
  );
414
 
415 192 jshamlet
  U_RX_CRC : entity work.sdlc_crc16_ccitt
416
  generic map(
417
    Poly_Init                => Poly_Init,
418
    Reset_Level              => Reset_Level
419
  )
420
  port map(
421
    Clock                    => Clock,
422
    Reset                    => Reset,
423
    --
424 202 jshamlet
    Clear                    => RX_Frame_Start,
425
    Wr_En                    => RX_Frame_Valid,
426
    Wr_Data                  => RX_Frame_Data,
427 192 jshamlet
    --
428 202 jshamlet
    CRC16_Valid              => RX_CRC_Valid,
429
    CRC16_Out                => RX_CRC_Data
430 192 jshamlet
  );
431
 
432 202 jshamlet
  U_RX_FSM : entity work.sdlc_serial_rxfsm
433
  generic map(
434
    Reset_Level              => Reset_Level
435
  )
436
  port map(
437
    Clock                    => Clock,
438
    Reset                    => Reset,
439
    --
440
    BClk_Okay                => BClk_Okay,
441
    --
442
    DP_Port1_Addr            => DP_Port1_Addr,
443
    DP_Port1_RWn             => DP_Port1_RWn,
444
    DP_Port1_WrData          => DP_Port1_WrData,
445
    DP_Port1_RdData          => DP_Port1_RdData,
446
    DP_Port1_Req             => DP_Port1_Req,
447
    DP_Port1_Ack             => DP_Port1_Ack,
448
    --
449
    RX_CRC_Valid             => RX_CRC_Valid,
450
    RX_CRC_Data              => RX_CRC_Data,
451
    --
452
    RX_Frame_Start           => RX_Frame_Start,
453
    RX_Frame_Stop            => RX_Frame_Stop,
454
    RX_Frame_Valid           => RX_Frame_Valid,
455
    RX_Frame_Data            => RX_Frame_Data,
456
    --
457
    RX_Interrupt             => RX_Interrupt
458
  );
459
 
460 192 jshamlet
end architecture;

powered by: WebSVN 2.1.0

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