Free VHDL library

  • Main Page
  • Related Pages
  • Design Unit List
  • Files
  • File List

lpp_uart/APB_UART.vhd

Go to the documentation of this file.
00001 ------------------------------------------------------------------------------
00002 --  This file is a part of the LPP VHDL IP LIBRARY
00003 --  Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS
00004 --
00005 --  This program is free software; you can redistribute it and/or modify
00006 --  it under the terms of the GNU General Public License as published by
00007 --  the Free Software Foundation; either version 3 of the License, or
00008 --  (at your option) any later version.
00009 --
00010 --  This program is distributed in the hope that it will be useful,
00011 --  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 --  GNU General Public License for more details.
00014 --
00015 --  You should have received a copy of the GNU General Public License
00016 --  along with this program; if not, write to the Free Software
00017 --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00018 ------------------------------------------------------------------------------
00019 --                    Author : Martin Morlot
00020 --                     Mail : martin.morlot@lpp.polytechnique.fr
00021 ------------------------------------------------------------------------------
00022 library ieee;
00023 use ieee.std_logic_1164.all;
00024 library grlib;
00025 use grlib.amba.all;
00026 use grlib.stdlib.all;
00027 use grlib.devices.all;
00028 library lpp;
00029 use lpp.lpp_amba.all;
00030 use lpp.apb_devices_list.all;
00031 use lpp.lpp_uart.all;
00032 
00035 
00036 entity APB_UART is
00037   generic (
00038     pindex   : integer := 0;
00039     paddr    : integer := 0;
00040     pmask    : integer := 16#fff#;
00041     pirq     : integer := 0;
00042     abits    : integer := 8;
00043     Data_sz  : integer := 8);
00044   port (
00045     clk     : in  std_logic;
00046     rst     : in  std_logic;
00047     apbi    : in  apb_slv_in_type;
00048     apbo    : out apb_slv_out_type;
00049     TXD    :   out std_logic;
00050     RXD    :   in  std_logic
00051     );
00052 end APB_UART;
00053 
00054 
00055 architecture ar_APB_UART of APB_UART is
00056 
00057 constant REVISION : integer := 1;
00058 
00059 constant pconfig : apb_config_type := (
00060   0 => ahb_device_reg (VENDOR_LPP, LPP_UART, 0, REVISION, 0),
00061   1 => apb_iobar(paddr, pmask));
00062 
00063 signal NwData   : std_logic;
00064 signal ACK      : std_logic;
00065 signal Capture  : std_logic;
00066 signal Send     : std_logic;
00067 signal Sended   : std_logic;
00068 
00069 type UART_ctrlr_Reg is record
00070      UART_Cfg  : std_logic_vector(2 downto 0);
00071      UART_Wdata : std_logic_vector(7 downto 0);
00072      UART_Rdata : std_logic_vector(7 downto 0);
00073      UART_BTrig : std_logic_vector(11 downto 0);
00074 end record;
00075 
00076 signal Rec : UART_ctrlr_Reg;
00077 signal Rdata     : std_logic_vector(31 downto 0);
00078 signal temp_ND : std_logic;
00079 
00080 begin
00081 
00082 Capture <= Rec.UART_Cfg(0);
00083 Rec.UART_Cfg(1) <= Sended;
00084 Rec.UART_Cfg(2) <= NwData;
00085 
00086 
00087     COM0 : UART
00088         generic map (Data_sz)
00089         port map (clk,rst,TXD,RXD,Capture,NwData,ACK,Send,Sended,Rec.UART_BTrig,Rec.UART_Rdata,Rec.UART_Wdata);
00090 
00091 
00092     process(rst,clk)
00093     begin
00094         if(rst='0')then
00095             Rec.UART_Wdata <=  (others => '0');
00096             
00097 
00098         elsif(clk'event and clk='1')then
00099            temp_ND <= NwData;
00100             if(NwData='1' and temp_ND='1')then
00101                 ACK <= '1';
00102             else
00103                 ACK <= '0';
00104             end if;
00105 
00106     --APB Write OP
00107             if (apbi.psel(pindex) and apbi.penable and apbi.pwrite) = '1' then
00108                 case apbi.paddr(7 downto 2) is
00109                     when "000000" =>
00110                         Rec.UART_Cfg(0) <= apbi.pwdata(0);
00111                     when "000001" =>
00112                         Rec.UART_Wdata(7 downto 0) <= apbi.pwdata(7 downto 0);
00113                         Send <= '1';
00114                     when others =>
00115                         null;
00116                 end case;
00117             else
00118                 Send <= '0';
00119             end if;
00120 
00121     --APB READ OP
00122             if (apbi.psel(pindex) and (not apbi.pwrite)) = '1' then
00123                 case apbi.paddr(7 downto 2) is
00124                     when "000000" =>
00125                         Rdata(3 downto 0) <= "000" & Rec.UART_Cfg(0);
00126                         Rdata(7 downto 4) <= "000" & Rec.UART_Cfg(1);
00127                         Rdata(11 downto 8) <= "000" & Rec.UART_Cfg(2);
00128                         Rdata(19 downto 12) <= X"EE";
00129                         Rdata(31 downto 20) <= Rec.UART_BTrig;
00130                     when "000001" =>
00131                         Rdata(31 downto 8) <= X"EEEEEE";     
00132                         Rdata(7 downto 0) <= Rec.UART_Wdata;
00133                     when "000010" =>
00134                         Rdata(31 downto 8) <= X"EEEEEE";
00135                         Rdata(7 downto 0) <= Rec.UART_Rdata;
00136                     when others =>
00137                         Rdata <= (others => '0');
00138                 end case;
00139             end if;
00140 
00141         end if;
00142         apbo.pconfig <= pconfig;
00143     end process;
00144 
00145     apbo.prdata     <=   Rdata when apbi.penable = '1';
00146 
00147 end ar_APB_UART;

© Copyright 2011 LPP-CNRS | Design by Alexis Jeandet