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 204

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

powered by: WebSVN 2.1.0

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