OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_serlcd_tx.vhd] - Blame information for rev 334

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 331 jshamlet
-- Copyright (c)2013, 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_serlcd_tx
25
-- Description:  Provides a client for sending data to a SPI attached LCD
26
--
27
-- Register Map
28
-- Address  Function
29
-- Offset  Bitfield Description                        Read/Write
30
-- 0x0     AAAAAAAA LCD Register Write                 (Read-Write*)
31
-- 0x1     AAAAAAAA LCD Data Write                     (Read-Write*)
32
-- 0x2     AAAAAAAA LCD Rearm Init Timer               (Read-Write*)
33
-- 0x3     AAAAAAAA LCD Backlight                      (Read-Write)
34
--
35
-- Note: Reading any offset will report the interface status
36
--         CBA      C: TX Ready Status (interface is IDLE)
37
--                  B: SPI SDO status (raw reading of SPI SDO line)
38
--                  A: IO Timeout > 0 (Set if IO timer expired)
39
--
40
-- Revision History
41
-- Author          Date     Change
42
------------------ -------- ---------------------------------------------------
43
-- Seth Henry      04/16/20 Revision block added
44
-- Seth Henry      05/18/20 Added write qualification input
45
 
46
library ieee;
47
use ieee.std_logic_1164.all;
48
use ieee.std_logic_unsigned.all;
49
use ieee.std_logic_arith.all;
50
use ieee.std_logic_misc.all;
51
 
52
library work;
53
  use work.open8_pkg.all;
54
 
55
entity o8_serlcd_tx is
56
generic(
57
  Address                    : ADDRESS_TYPE
58
);
59
port(
60
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
61
  Write_Qual                 : in  std_logic := '1';
62
  Rd_Data                    : out DATA_TYPE;
63
  Interrupt                  : out std_logic;
64
  --
65
  SPI_CLK                    : out std_logic;
66
  SPI_SDI                    : out std_logic;
67
  SPI_SDO                    : in  std_logic
68
);
69
end entity;
70
 
71
architecture behave of o8_serlcd_tx is
72
 
73
  alias Clock                is Open8_Bus.Clock;
74
  alias Reset                is Open8_Bus.Reset;
75
 
76
  constant User_Addr         : std_logic_vector(15 downto 2)
77
                               := Address(15 downto 2);
78
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
79
  signal Addr_Match          : std_logic;
80
 
81
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
82
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
83
  signal Wr_En_d             : std_logic := '0';
84
  signal Wr_En_q             : std_logic := '0';
85
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
86
  signal Wr_Data_q           : DATA_TYPE := x"00";
87
  signal Rd_En_d             : std_logic := '0';
88
  signal Rd_En_q             : std_logic := '0';
89
 
90
  signal Reg_Addr            : std_logic_vector(1 downto 0) := (others => '0');
91
  signal Reg_Data            : std_logic_vector(7 downto 0) := (others => '0');
92
  signal Reg_Valid           : std_logic := '0';
93
  signal Tx_Ready            : std_logic := '0';
94
 
95
-- Data Format
96
-- <A1><A0><D7><D6><D5><D4><D3><D2><D1><D0>
97
 
98
  type IO_STATES is ( INIT, IDLE, SETUP, RISING, HOLD, FALLING, IF_WAIT );
99
  signal io_state            : IO_STATES;
100
 
101
  signal tx_buffer           : std_logic_vector(10 downto 0);
102
  alias  ADDR                is tx_buffer(10 downto 9);
103
  alias  DATA                is tx_buffer(8 downto 1);
104
  alias  RUNOUT              is tx_buffer(0);
105
 
106
  signal bit_cnt             : std_logic_vector(3 downto 0) := (others => '0');
107
  constant VEC_LEN           : integer := tx_buffer'length - 1;
108
  constant BITS              : std_logic_vector(3 downto 0) :=
109
                                conv_std_logic_vector(VEC_LEN,4);
110
 
111
  signal snh_tmr             : std_logic_vector(2 downto 0) := (others => '0');
112
 
113
  signal SPI_SDO_q           : std_logic_vector(2 downto 0) := "000";
114
 
115
  signal TX_Clk              : std_logic := '0';
116
  signal TX_Out              : std_logic := '0';
117
 
118
begin
119
 
120
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
121
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En and Write_Qual;
122
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
123
 
124
  SPI_CLK                    <= TX_Clk;
125
  SPI_SDI                    <= TX_Out;
126
 
127
  io_reg: process( Clock, Reset )
128
  begin
129
    if( Reset = Reset_Level )then
130
      Reg_Sel_q              <= "00";
131
      Wr_En_q                <= '0';
132
      Wr_Data_q              <= x"00";
133
      Rd_En_q                <= '0';
134
      Rd_Data                <= OPEN8_NULLBUS;
135
 
136
      Reg_Addr               <= (others => '0');
137
      Reg_Data               <= x"00";
138
      Reg_Valid              <= '0';
139
    elsif( rising_edge( Clock ) )then
140
      Reg_Sel_q              <= Reg_Sel_d;
141
 
142
      Wr_En_q                <= Wr_En_d;
143
      Wr_Data_q              <= Wr_Data_d;
144
 
145
      Reg_Valid              <= '0';
146
      if( Wr_En_q = '1' )then
147
        Reg_Addr             <= Reg_Sel_q;
148
        Reg_Data             <= Wr_Data_q;
149
        Reg_Valid            <= '1';
150
      end if;
151
 
152
      Rd_En_q                <= Rd_En_d;
153
      Rd_Data                <= OPEN8_NULLBUS;
154
      if( Rd_En_q = '1' )then
155
        Rd_Data(7)           <= Tx_Ready;
156
      end if;
157
    end if;
158
  end process;
159
 
160
  tx_proc: process( Clock, Reset )
161
  begin
162
    if( Reset = Reset_Level )then
163
      io_state               <= INIT;
164
      tx_buffer              <= (others => '0');
165
      bit_cnt                <= (others => '0');
166
      snh_tmr                <= (others => '0');
167
      TX_Clk                 <= '0';
168
      TX_Out                 <= '0';
169
      Tx_Ready               <= '0';
170
      Interrupt              <= '0';
171
      SPI_SDO_q              <= (others => '1');
172
    elsif( rising_edge(Clock) )then
173
      TX_Clk                 <= '1';
174
      TX_Out                 <= tx_buffer(conv_integer(bit_cnt));
175
      SPI_SDO_q              <= SPI_SDO_q(1 downto 0) & to_X01(SPI_SDO);
176
      Tx_Ready               <= '0';
177
      Interrupt              <= '0';
178
 
179
      case( io_state )is
180
        when INIT =>
181
          if( or_reduce(SPI_SDO_q) = '0' )then
182
            io_state         <= IDLE;
183
          end if;
184
 
185
        when IDLE =>
186
          Tx_Ready           <= '1';
187
          bit_cnt            <= (others => '0');
188
          snh_tmr            <= (others => '1');
189
          if( Reg_Valid = '1' )then
190
            ADDR             <= Reg_Addr;
191
            DATA             <= Reg_Data;
192
            bit_cnt          <= BITS;
193
            io_state         <= FALLING;
194
          end if;
195
 
196
        when SETUP =>
197
          TX_Clk             <= '0';
198
          snh_tmr            <= snh_tmr - 1;
199
          if( snh_tmr = 0 )then
200
            io_state         <= RISING;
201
          end if;
202
 
203
        when RISING =>
204
          snh_tmr            <= (others => '1');
205
          io_state           <= HOLD;
206
 
207
        when HOLD =>
208
          snh_tmr            <= snh_tmr - 1;
209
          if( snh_tmr = 0 )then
210
            bit_cnt          <= bit_cnt - or_reduce(bit_cnt);
211
            io_state         <= FALLING;
212
          end if;
213
 
214
        when FALLING =>
215
          TX_Clk             <= '0';
216
          snh_tmr            <= (others => '1');
217
          io_state           <= SETUP;
218
          if( bit_cnt = 0 )then
219
            TX_Clk           <= '1';
220
            io_state         <= IF_WAIT;
221
          end if;
222
 
223
        when IF_WAIT =>
224
          if( or_reduce(SPI_SDO_q) = '0' )then
225
            Interrupt        <= '1';
226
            io_state         <= IDLE;
227
          end if;
228
 
229
        when others =>
230
          null;
231
 
232
      end case;
233
    end if;
234
  end process;
235
 
236
end architecture;

powered by: WebSVN 2.1.0

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