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 273

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

powered by: WebSVN 2.1.0

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