dcml_adjust_rtl.vhd
上传用户:sztwq510
上传日期:2007-04-20
资源大小:209k
文件大小:7k
源码类别:

VHDL/FPGA/Verilog

开发平台:

Matlab

  1. -------------------------------------------------------------------------------
  2. --                                                                           --
  3. --          X       X   XXXXXX    XXXXXX    XXXXXX    XXXXXX      X          --
  4. --          XX     XX  X      X  X      X  X      X  X           XX          --
  5. --          X X   X X  X         X      X  X      X  X          X X          --
  6. --          X  X X  X  X         X      X  X      X  X         X  X          --
  7. --          X   X   X  X          XXXXXX   X      X   XXXXXX      X          --
  8. --          X       X  X         X      X  X      X         X     X          --
  9. --          X       X  X         X      X  X      X         X     X          --
  10. --          X       X  X      X  X      X  X      X         X     X          --
  11. --          X       X   XXXXXX    XXXXXX    XXXXXX    XXXXXX      X          --
  12. --                                                                           --
  13. --                                                                           --
  14. --                       O R E G A N O   S Y S T E M S                       --
  15. --                                                                           --
  16. --                            Design & Consulting                            --
  17. --                                                                           --
  18. -------------------------------------------------------------------------------
  19. --                                                                           --
  20. --         Web:           http://www.oregano.at/                             --
  21. --                                                                           --
  22. --         Contact:       mc8051@oregano.at                                  --
  23. --                                                                           --
  24. -------------------------------------------------------------------------------
  25. --                                                                           --
  26. --  MC8051 - VHDL 8051 Microcontroller IP Core                               --
  27. --  Copyright (C) 2001 OREGANO SYSTEMS                                       --
  28. --                                                                           --
  29. --  This library is free software; you can redistribute it and/or            --
  30. --  modify it under the terms of the GNU Lesser General Public               --
  31. --  License as published by the Free Software Foundation; either             --
  32. --  version 2.1 of the License, or (at your option) any later version.       --
  33. --                                                                           --
  34. --  This library is distributed in the hope that it will be useful,          --
  35. --  but WITHOUT ANY WARRANTY; without even the implied warranty of           --
  36. --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        --
  37. --  Lesser General Public License for more details.                          --
  38. --                                                                           --
  39. --  Full details of the license can be found in the file LGPL.TXT.           --
  40. --                                                                           --
  41. --  You should have received a copy of the GNU Lesser General Public         --
  42. --  License along with this library; if not, write to the Free Software      --
  43. --  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  --
  44. --                                                                           --
  45. -------------------------------------------------------------------------------
  46. --
  47. --
  48. --         Author:                 Roland H鰈ler
  49. --
  50. --         Filename:               dcml_adjust_rtl.vhd
  51. --
  52. --         Date of Creation:       Mon Aug  9 12:14:48 1999
  53. --
  54. --         Version:                $Revision: 1.4 $
  55. --
  56. --         Date of Latest Version: $Date: 2002/01/07 12:17:44 $
  57. --
  58. --
  59. --         Description: Combinational design to calculate the decimal
  60. --                      representation (BCD) of a data bus.
  61. --
  62. --
  63. --
  64. --
  65. -------------------------------------------------------------------------------
  66. architecture rtl of dcml_adjust is
  67. begin  -- rtl
  68.   p_calc_adjst: process (data_i, cy_i)
  69.     variable v_cy     : std_logic_vector((DWIDTH-1)/4 downto 0);
  70.     variable v_nxtcy  : std_logic;
  71.     variable v_tmpda  : unsigned(DWIDTH downto 0);
  72.     variable v_tmpda1 : unsigned(4 downto 0);
  73.     variable v_compvl : unsigned(3 downto 0);
  74.   begin  -- process p_calc_adjst
  75.     v_tmpda(DWIDTH-1 downto 0) := unsigned(data_i);
  76.     v_tmpda(DWIDTH) := '0';
  77.     v_cy := cy_i;
  78.     v_nxtcy := '0';
  79.     for i in 0 to (DWIDTH-1)/4 loop      
  80.       if DWIDTH-i*4 <= 4 then
  81.         -- Calculate the decimal adjustment of the last nibble/rest of bits
  82.         v_compvl := conv_unsigned(0,4);
  83.         v_compvl(DWIDTH-1-i*4 downto 0) := v_tmpda(DWIDTH-1 downto i*4);
  84.         if (v_cy(i) = '1') or (v_compvl > conv_unsigned(9,4)) then
  85.           if DWIDTH-i*4 > 2 then
  86.             v_tmpda(DWIDTH downto i*4) := v_tmpda(DWIDTH-1 downto i*4) +
  87.                        conv_unsigned(6,v_tmpda(DWIDTH downto i*4)'LENGTH);
  88.           else
  89.             v_tmpda(DWIDTH downto i*4) := v_tmpda(DWIDTH-1 downto i*4) +
  90.                        conv_unsigned(2,v_tmpda(DWIDTH downto i*4)'LENGTH);
  91.           end if;
  92.         end if;
  93.         -- An already set intermediate carry flag must not be lost.
  94.         v_cy(i) := v_tmpda(DWIDTH) or v_cy(i);
  95.       else
  96.         -- Calculate the decimal adjustment of all nibbles, but the last one.
  97.         v_compvl := v_tmpda(i*4+3 downto i*4);
  98.         v_tmpda1 := conv_unsigned(0,5);
  99.         if (v_cy(i) = '1') or (v_compvl > conv_unsigned(9,4)) then
  100.           for j in i to (DWIDTH-1)/4 loop
  101.             if DWIDTH-1 > j*4+3 then
  102.               -- Calculate all subsequent nibbles from the actual position up
  103.               -- to the one before the last.
  104.               if j=i then
  105.                 v_tmpda1 := v_tmpda(j*4+3 downto j*4) +
  106.                             conv_unsigned(6,5);
  107.                 v_nxtcy := v_tmpda1(4);
  108.                 v_tmpda(j*4+3 downto j*4) := v_tmpda1(3 downto 0);
  109.               else
  110.                 v_tmpda1 := v_tmpda(j*4+3 downto j*4) +
  111.                             conv_unsigned(v_nxtcy,5);
  112.                 v_nxtcy := v_tmpda1(4);
  113.                 v_tmpda(j*4+3 downto j*4) := v_tmpda1(3 downto 0);
  114.               end if;
  115.               -- An already set intermediate carry flag must not be lost.
  116.               v_cy(j) := v_tmpda1(4) or v_cy(j);
  117.             else
  118.               -- Calculate the last nibble.
  119.               if j=i then              
  120.                 v_tmpda(DWIDTH downto j*4) := v_tmpda(DWIDTH-1 downto j*4) +
  121.                            conv_unsigned(6,v_tmpda(DWIDTH downto j*4)'LENGTH);
  122.               else
  123.                 v_tmpda(DWIDTH downto j*4) := v_tmpda(DWIDTH-1 downto j*4) +
  124.                      conv_unsigned(v_nxtcy,v_tmpda(DWIDTH downto j*4)'LENGTH);
  125.               end if;
  126.               -- An already set intermediate carry flag must not be lost.
  127.               v_cy(j) := v_tmpda(DWIDTH) or v_cy(j);
  128.             end if;
  129.           end loop;  -- j
  130.         end if;
  131.       end if;
  132.     end loop;  -- i
  133.     -- Generate outputs
  134.     cy_o <= v_cy(v_cy'HIGH);
  135.     data_o <= std_logic_vector(v_tmpda(DWIDTH-1 downto 0));
  136.   end process p_calc_adjst;
  137. end rtl;