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 206

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

powered by: WebSVN 2.1.0

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