Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / fpga / ctrls / serial /

serial_config.vhd

   1  -- serial_config.vhd: Serial constants and types
   2  -- Copyright (C) 2007 Brno University of Technology,
   3  --                    Faculty of Information Technology
   4  -- Author(s): Zdenek Vasicek (xvasic11 AT stud.fit.vutbr.cz)
   5  --
   6  -- LICENSE TERMS
   7  --
   8  -- Redistribution and use in source and binary forms, with or without
   9  -- modification, are permitted provided that the following conditions
  10  -- are met:
  11  -- 1. Redistributions of source code must retain the above copyright
  12  --    notice, this list of conditions and the following disclaimer.
  13  -- 2. Redistributions in binary form must reproduce the above copyright
  14  --    notice, this list of conditions and the following disclaimer in
  15  --    the documentation and/or other materials provided with the
  16  --    distribution.
  17  -- 3. All advertising materials mentioning features or use of this software
  18  --    or firmware must display the following acknowledgement:
  19  --
  20  --      This product includes software developed by the University of
  21  --      Technology, Faculty of Information Technology, Brno and its
  22  --      contributors.
  23  --
  24  -- 4. Neither the name of the Company nor the names of its contributors
  25  --    may be used to endorse or promote products derived from this
  26  --    software without specific prior written permission.
  27  --
  28  -- This software or firmware is provided ``as is'', and any express or implied
  29  -- warranties, including, but not limited to, the implied warranties of
  30  -- merchantability and fitness for a particular purpose are disclaimed.
  31  -- In no event shall the company or contributors be liable for any
  32  -- direct, indirect, incidental, special, exemplary, or consequential
  33  -- damages (including, but not limited to, procurement of substitute
  34  -- goods or services; loss of use, data, or profits; or business
  35  -- interruption) however caused and on any theory of liability, whether
  36  -- in contract, strict liability, or tort (including negligence or
  37  -- otherwise) arising in any way out of the use of this software, even
  38  -- if advised of the possibility of such damage.
  39  --
  40  -- $Id$
  41  --
  42  --
  43  library ieee;
  44  use ieee.std_logic_1164.all;
  45  use ieee.std_logic_arith.all;
  46  
  47  package serial_cfg is
  48  
  49     subtype serial_databit is natural range 5 to 9;
  50  
  51     type serial_speed is (
  52        s1200Bd, s2400Bd, s4800Bd, s9600Bd, s19200Bd, s38400Bd,
  53        s57600Bd, s115200Bd, s230400Bd, s460800Bd, s921600Bd
  54     );
  55  
  56     type serial_parity is (
  57        sParityNone, sParityEven, sParityOdd
  58     );
  59  
  60     subtype serial_stopbit is natural range 1 to 2;
  61  
  62     function clkdiv(constant speed : serial_speed; constant freqmult: positive) return integer;
  63     function log2(constant a : integer) return integer;
  64  
  65  end serial_cfg;
  66  
  67  
  68  package body serial_cfg is
  69  
  70     function clkdiv(constant speed : serial_speed; constant freqmult: positive) return integer is
  71        variable div : integer;
  72     begin
  73        div := 8 / freqmult;
  74        if speed = s921600Bd then return div; end if;
  75        div := div * 2;
  76        if speed = s460800Bd then return div; end if;
  77        div := div * 2;
  78        if speed = s230400Bd then return div; end if;
  79        div := div * 2;
  80        if speed = s115200Bd then return div; end if;
  81        div := div * 2;
  82        if speed = s57600Bd then return div; end if;
  83        div := integer(real(div) * 1.5);
  84        if speed = s38400Bd then return div; end if;
  85        div := div * 2;
  86        if speed = s19200Bd then return div; end if;
  87        div := div * 2;
  88        if speed = s9600Bd then return div; end if;
  89        div := div * 2;
  90        if speed = s4800Bd then return div; end if;
  91        div := div * 2;
  92        if speed = s2400Bd then return div; end if;
  93        div := div * 2;
  94        -- Default is 1200 Bd
  95        return div;
  96     end;
  97  
  98     function log2(constant a : integer) return integer is
  99        variable bits, b : integer;
 100     begin
 101        bits := 0;
 102  
 103        b := 1;
 104        while (b <= a) loop
 105          b := b * 2;
 106          bits := bits + 1;
 107        end loop;
 108  
 109        return bits;
 110     end function;
 111  end serial_cfg;
 112  
Zobrazeno: 679752x Naposledy: 28.6.2022 20:05:12