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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_scale_conv.vhd] - Blame information for rev 318

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

Line No. Rev Author Line
1 318 jshamlet
-- Copyright (c)2023 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_scale_conv
25
-- Description: Performs the operation ACC = [(A*B)/C] + D, returning a 33-bit
26
--               value. Optionally converts this value into packed BCD format.
27
--
28
-- Note1: Operands A,B are 16-bit values. The output from this step is a 32-bit
29
--         value, which can be divided by Operand C, with the result added to
30
--         Operand D. Both operand C and D are 32-bit values.
31
-- Note2: If the operation type is '1', or SIGNED, then operand A,B, and D
32
--         will be treated as SIGNED values, while operand C remains UNSIGNED
33
--        If the operation type is '0', or UNSIGNED, all operands will be
34
--         treated as UNSIGNED values.
35
-- Note3: Setting Operand C to 0 or 1 will skip the division step. This
36
--         resolves the issue of divide by 0, as 0 will be treated as 1, as
37
--         well as saving time if the division isn't required.
38
--
39
-- Register Map:
40
-- Offset  Bitfield Description                        Read/Write
41
--   0x00  AAAAAAAA Operand A, Lower Byte                 RW
42
--   0x01  AAAAAAAA Operand A, Upper Byte                 RW
43
--   0x02  AAAAAAAA Operand B, Lower Byte                 RW
44
--   0x03  AAAAAAAA Operand B, Upper Byte                 RW
45
--   0x04  AAAAAAAA Operand C, Byte 0                     RW
46
--   0x05  AAAAAAAA Operand C, Byte 1                     RW
47
--   0x06  AAAAAAAA Operand C, Byte 2                     RW
48
--   0x07  AAAAAAAA Operand C, Byte 3                     RW
49
--   0x08  AAAAAAAA Operand D, Byte 0                     RW
50
--   0x09  AAAAAAAA Operand D, Byte 1                     RW
51
--   0x0A  AAAAAAAA Operand D, Byte 2                     RW
52
--   0x0B  AAAAAAAA Operand D, Byte 3                     RW
53
 
54
--   0x10  AAAAAAAA Accumulator, Byte 0                   R0
55
--   0x11  AAAAAAAA Accumulator, Byte 1                   R0
56
--   0x12  AAAAAAAA Accumulator, Byte 2                   R0
57
--   0x13  AAAAAAAA Accumulator, Byte 3                   R0
58
--   0x14  A------- Accumulator, Sign / Bit 32            R0
59
 
60
--   0x18  AAAAAAAA BCD Data, Digits 1,0                  RO
61
--   0x19  AAAAAAAA BCD Data, Digits 3,2                  RO
62
--   0x1A  AAAAAAAA BCD Data, Digits 5,4                  RO
63
--   0x1B  AAAAAAAA BCD Data, Digits 7,6                  RO
64
--   0x1C  AAAAAAAA BCD Data, Digits 9,8                  RO
65
--   0x1D  A------- BCD Data, Sign [pos (0), neg (1)]     R0
66
 
67
--   0x1F  C-----BA Control/Status                        RW
68
--                   A = Operation Type:
69
--                       Unsigned (0) / Signed (1)
70
--                   B = BCD conversion (if set) (WR)*
71
--                       BCD result valid if set (RD)
72
--                   C = Conversion Status (1 = busy)
73
--
74
-- Note4: Setting bit 1 TRUE will enable the packed BCD conversion system
75
--         at the cost of ~3.5uS per conversion. If the most recent result
76
--         was converted, reading this bit will return a '1' to indicate
77
--         that the data is "fresh", or matches the raw result data.
78
--        Setting this bit FALSE will allow a new math operation to occur
79
--         WITHOUT altering the last BCD conversion, but will set this bit to
80
--         0 on read to indicate that the BCD value is "stale", or no longer
81
--         matches the raw result data.
82
--
83
-- Revision History
84
-- Author          Date     Change
85
------------------ -------- ---------------------------------------------------
86
-- Seth Henry      04/10/23 Initial Design
87
 
88
library ieee;
89
use ieee.std_logic_1164.all;
90
use ieee.std_logic_signed.all;
91
use ieee.std_logic_arith.all;
92
use ieee.std_logic_misc.all;
93
 
94
library work;
95
use work.open8_pkg.all;
96
use work.open8_cfg.all;
97
 
98
entity o8_scale_conv is
99
generic(
100
  Address                    : ADDRESS_TYPE
101
);
102
port(
103
  -- Bus IF Interface
104
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
105
  Write_Qual                 : in  std_logic;
106
  Rd_Data                    : out DATA_TYPE;
107
  Interrupt                  : out std_logic
108
);
109
end entity;
110
 
111
architecture behave of o8_scale_conv is
112
 
113
  -- Bus Interface Signals
114
 
115
  alias Clock                is Open8_Bus.Clock;
116
  alias Reset                is Open8_Bus.Reset;
117
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
118
 
119
  constant User_Addr         : std_logic_vector(15 downto 5) :=
120
                                Address(15 downto 5);
121
 
122
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 5);
123
  signal Addr_Match          : std_logic := '0';
124
 
125
  alias  Reg_Sel_d           is Open8_Bus.Address(4 downto 0);
126
  signal Reg_Sel_q           : std_logic_vector(4 downto 0) := (others => '0');
127
  signal Wr_En_d             : std_logic := '0';
128
  signal Wr_En_q             : std_logic := '0';
129
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
130
  signal Wr_Data_q           : DATA_TYPE := x"00";
131
  signal Rd_En_d             : std_logic := '0';
132
  signal Rd_En_q             : std_logic := '0';
133
 
134
  -- Operands A, B, and C are 16-bit with sign-extension, or 17-bit values
135
  constant OPER_ABC_WIDTH    : integer := 17;
136
 
137
  signal OperandA            : signed(OPER_ABC_WIDTH - 1 downto 0) :=
138
                                 (others => '0');
139
  alias  OperandA_LB         is OperandA(7 downto 0);
140
  alias  OperandA_UB         is OperandA(15 downto 8);
141
  alias  OperandA_S          is OperandA(15);
142
  alias  OperandA_SX         is OperandA(OPER_ABC_WIDTH - 1 downto 16);
143
 
144
  signal OperandB            : signed(OPER_ABC_WIDTH - 1 downto 0) :=
145
                                 (others => '0');
146
  alias  OperandB_LB         is OperandB(7 downto 0);
147
  alias  OperandB_UB         is OperandB(15 downto 8);
148
  alias  OperandB_S          is OperandB(15);
149
  alias  OperandB_SX         is OperandB(OPER_ABC_WIDTH - 1 downto 16);
150
 
151
  -- The product will, by definition, be twice as wide as the input operands
152
 
153
  constant MULT_WIDTH        : integer := 2*OPER_ABC_WIDTH;
154
  signal Product_AB          : signed(MULT_WIDTH - 1 downto 0) :=
155
                                 (others => '0');
156
 
157
  -- The divider only needs a single bit for sign extension, so drop one
158
  --  bit from the multiplier width
159
  constant DIVIDER_WIDTH     : integer := MULT_WIDTH - 1;
160
  alias  Operand_AB          is Product_AB(DIVIDER_WIDTH - 1 downto 0);
161
 
162
  signal OperandC            : signed(DIVIDER_WIDTH - 1 downto 0) :=
163
                                 (others => '0');
164
  alias  OperandC_B0         is OperandC(7 downto 0);
165
  alias  OperandC_B1         is OperandC(15 downto 8);
166
  alias  OperandC_B2         is OperandC(23 downto 16);
167
  alias  OperandC_B3         is OperandC(31 downto 24);
168
  alias  OperandC_SX         is OperandC(DIVIDER_WIDTH - 1 downto 32);
169
 
170
  signal OperandABC          : signed(DIVIDER_WIDTH - 1 downto 0) :=
171
                                 (others => '0');
172
 
173
  signal OperandD            : signed(DIVIDER_WIDTH - 1 downto 0) :=
174
                                 (others => '0');
175
 
176
  alias  OperandD_B0         is OperandD(7 downto 0);
177
  alias  OperandD_B1         is OperandD(15 downto 8);
178
  alias  OperandD_B2         is OperandD(23 downto 16);
179
  alias  OperandD_B3         is OperandD(31 downto 24);
180
  alias  OperandD_S          is OperandD(31);
181
  alias  OperandD_SX         is OperandD(DIVIDER_WIDTH - 1 downto 32);
182
 
183
  signal Accumulator         : signed(DIVIDER_WIDTH - 1 downto 0) :=
184
                                 (others => '0');
185
 
186
  alias  RAW_Data_B0         is Accumulator(7 downto 0);
187
  alias  RAW_Data_B1         is Accumulator(15 downto 8);
188
  alias  RAW_Data_B2         is Accumulator(23 downto 16);
189
  alias  RAW_Data_B3         is Accumulator(31 downto 24);
190
  alias  RAW_Sign_MSB        is Accumulator(32);
191
 
192
  -- Conversion control signals
193
 
194
  type CONV_STATES is ( IDLE,
195
                        MULT_WAIT,
196
                        DIV_START, DIV_WAIT, DIV_SKIP,
197
                        ACCUM_WAIT,
198
                        DAA_INIT,  DAA_NEGATE,
199
                        DAA_STEP1, DAA_WAIT1,
200
                        DAA_STEP2, DAA_WAIT2,
201
                        DAA_STEP3, DAA_WAIT3,
202
                        DAA_STEP4, DAA_WAIT4,
203
                        DAA_STEP5, DAA_WAIT5,
204
                        DAA_STEP6, DAA_WAIT6,
205
                        DAA_STEP7, DAA_WAIT7,
206
                        DAA_STEP8, DAA_WAIT8,
207
                        DAA_STEP9, DAA_WAIT9,
208
                        DAA_DONE  );
209
 
210
  signal Conv_State     : CONV_STATES := IDLE;
211
 
212
  signal CNV_En              : std_logic := '0';
213
  signal DAA_En              : std_logic := '0';
214
  signal CNV_Busy            : std_logic := '0';
215
 
216
  signal CNV_Mode            : std_logic := '0';
217
 
218
  constant CNV_SIGNED        : std_logic := '1';
219
  constant CNV_UNSIGNED      : std_logic := '0';
220
 
221
  signal CNV_Done            : std_logic := '0';
222
 
223
  -- Decimal adjust / BCD conversion signals
224
 
225
  signal DAA_Valid           : std_logic := '0';
226
 
227
  constant DAA_ST1_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
228
                                 conv_std_logic_vector(1000000000,DIVIDER_WIDTH);
229
 
230
  constant DAA_ST2_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
231
                                 conv_std_logic_vector(100000000,DIVIDER_WIDTH);
232
 
233
  constant DAA_ST3_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
234
                                 conv_std_logic_vector(10000000,DIVIDER_WIDTH);
235
 
236
  constant DAA_ST4_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
237
                                 conv_std_logic_vector(1000000,DIVIDER_WIDTH);
238
 
239
  constant DAA_ST5_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
240
                                 conv_std_logic_vector(100000,DIVIDER_WIDTH);
241
 
242
  constant DAA_ST6_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
243
                                 conv_std_logic_vector(10000,DIVIDER_WIDTH);
244
 
245
  constant DAA_ST7_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
246
                                 conv_std_logic_vector(1000,DIVIDER_WIDTH);
247
 
248
  constant DAA_ST8_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
249
                                 conv_std_logic_vector(100,DIVIDER_WIDTH);
250
 
251
  constant DAA_ST9_DIV       : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
252
                                 conv_std_logic_vector(10,DIVIDER_WIDTH);
253
 
254
  signal DAA_Next            : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
255
                                (others => '0');
256
 
257
  signal DAA_Sign            : std_logic := '0';
258
 
259
  signal DAA_Buffer          : std_logic_vector(39 downto 0) := (others => '0');
260
 
261
  alias  DAA_Data_B0         is DAA_Buffer(7 downto 0);
262
  alias  DAA_Data_B1         is DAA_Buffer(15 downto 8);
263
  alias  DAA_Data_B2         is DAA_Buffer(23 downto 16);
264
  alias  DAA_Data_B3         is DAA_Buffer(31 downto 24);
265
  alias  DAA_Data_B4         is DAA_Buffer(39 downto 32);
266
 
267
  alias  DAA_Digit_0         is DAA_Buffer( 3 downto 0);
268
  alias  DAA_Digit_1         is DAA_Buffer( 7 downto 4);
269
  alias  DAA_Digit_2         is DAA_Buffer(11 downto 8);
270
  alias  DAA_Digit_3         is DAA_Buffer(15 downto 12);
271
  alias  DAA_Digit_4         is DAA_Buffer(19 downto 16);
272
  alias  DAA_Digit_5         is DAA_Buffer(23 downto 20);
273
  alias  DAA_Digit_6         is DAA_Buffer(27 downto 24);
274
  alias  DAA_Digit_7         is DAA_Buffer(31 downto 28);
275
  alias  DAA_Digit_8         is DAA_Buffer(35 downto 32);
276
  alias  DAA_Digit_9         is DAA_Buffer(39 downto 36);
277
 
278
  -- Integer divide unit signals
279
 
280
  signal Div_Enable          : std_logic := '0';
281
  signal Div_Busy            : std_logic := '0';
282
 
283
  signal Dividend            : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
284
                                 (others => '0');
285
 
286
  signal Divisor             : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
287
                                 (others => '0');
288
 
289
  signal Quotient            : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
290
                                 (others => '0');
291
 
292
  signal Remainder           : std_logic_vector(DIVIDER_WIDTH - 1 downto 0) :=
293
                                 (others => '0');
294
 
295
begin
296
 
297
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
298
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En and Write_Qual;
299
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
300
 
301
  reg_proc: process( Clock, Reset )
302
  begin
303
    if( Reset = Reset_Level )then
304
      Reg_Sel_q              <= (others => '0');
305
      Wr_En_q                <= '0';
306
      Wr_Data_q              <= x"00";
307
      Rd_En_q                <= '0';
308
      Rd_Data                <= OPEN8_NULLBUS;
309
 
310
      OperandA               <= (others => '0');
311
      OperandB               <= (others => '0');
312
      OperandC               <= (others => '0');
313
      OperandD               <= (others => '0');
314
 
315
      CNV_En                 <= '0';
316
      DAA_En                 <= '0';
317
      CNV_Mode               <= '0';
318
      CNV_Busy               <= '0';
319
 
320
      Interrupt              <= '0';
321
 
322
    elsif( rising_edge(Clock) )then
323
      Reg_Sel_q              <= Reg_Sel_d;
324
 
325
      Wr_En_q                <= Wr_En_d;
326
      Wr_Data_q              <= Wr_Data_d;
327
 
328
      CNV_En                 <= '0';
329
 
330
      if( Wr_En_q = '1' )then
331
        case( Reg_Sel_q )is
332
          when "00000" =>
333
            OperandA_LB      <= signed(Wr_Data_q);
334
          when "00001" =>
335
            OperandA_UB      <= signed(Wr_Data_q);
336
          when "00010" =>
337
            OperandB_LB      <= signed(Wr_Data_q);
338
          when "00011" =>
339
            OperandB_UB      <= signed(Wr_Data_q);
340
          when "00100" =>
341
            OperandC_B0      <= signed(Wr_Data_q);
342
          when "00101" =>
343
            OperandC_B1      <= signed(Wr_Data_q);
344
          when "00110" =>
345
            OperandC_B2      <= signed(Wr_Data_q);
346
          when "00111" =>
347
            OperandC_B3      <= signed(Wr_Data_q);
348
          when "01000" =>
349
            OperandD_B0      <= signed(Wr_Data_q);
350
          when "01001" =>
351
            OperandD_B1      <= signed(Wr_Data_q);
352
          when "01010" =>
353
            OperandD_B2      <= signed(Wr_Data_q);
354
          when "01011" =>
355
            OperandD_B3      <= signed(Wr_Data_q);
356
 
357
          when "11111" =>
358
            CNV_Mode         <= Wr_Data_q(0);
359
            DAA_En           <= Wr_Data_q(1);
360
            CNV_En           <= '1';
361
            CNV_Busy         <= '1';
362
          when others => null;
363
        end case;
364
      end if;
365
 
366
      Interrupt              <= '0';
367
      if( CNV_Done = '1' )then
368
        CNV_Busy             <= '0';
369
        Interrupt            <= '1';
370
      end if;
371
 
372
      OperandA_SX            <= (others => '0');
373
      OperandB_SX            <= (others => '0');
374
      OperandC_SX            <= (others => '0');
375
      OperandD_SX            <= (others => '0');
376
 
377
      if( CNV_Mode = CNV_SIGNED )then
378
        OperandA_SX          <= (others => OperandA_S);
379
        OperandB_SX          <= (others => OperandB_S);
380
        OperandD_SX          <= (others => OperandD_S);
381
      end if;
382
 
383
      Rd_En_q                <= Rd_En_d;
384
      Rd_Data                <= OPEN8_NULLBUS;
385
      if( Rd_En_q = '1' )then
386
        case( Reg_Sel_q )is
387
          -- Input operands
388
          when "00000" =>
389
            Rd_Data          <= std_logic_vector(OperandA_LB);
390
          when "00001" =>
391
            Rd_Data          <= std_logic_vector(OperandA_UB);
392
          when "00010" =>
393
            Rd_Data          <= std_logic_vector(OperandB_LB);
394
          when "00011" =>
395
            Rd_Data          <= std_logic_vector(OperandB_UB);
396
          when "00100" =>
397
            Rd_Data          <= std_logic_vector(OperandC_B0);
398
          when "00101" =>
399
            Rd_Data          <= std_logic_vector(OperandC_B1);
400
          when "00110" =>
401
            Rd_Data          <= std_logic_vector(OperandC_B2);
402
          when "00111" =>
403
            Rd_Data          <= std_logic_vector(OperandC_B3);
404
          when "01000" =>
405
            Rd_Data          <= std_logic_vector(OperandD_B0);
406
          when "01001" =>
407
            Rd_Data          <= std_logic_vector(OperandD_B1);
408
          when "01010" =>
409
            Rd_Data          <= std_logic_vector(OperandD_B2);
410
          when "01011" =>
411
            Rd_Data          <= std_logic_vector(OperandD_B3);
412
 
413
          -- Raw results
414
          when "10000" =>
415
            Rd_Data          <= std_logic_vector(RAW_Data_B0);
416
          when "10001" =>
417
            Rd_Data          <= std_logic_vector(RAW_Data_B1);
418
          when "10010" =>
419
            Rd_Data          <= std_logic_vector(RAW_Data_B2);
420
          when "10011" =>
421
            Rd_Data          <= std_logic_vector(RAW_Data_B3);
422
          when "10100" =>
423
            Rd_Data(7)       <= RAW_Sign_MSB;
424
 
425
          -- BCD Conversion
426
          when "11000" =>
427
            Rd_Data          <= DAA_Data_B0;
428
          when "11001" =>
429
            Rd_Data          <= DAA_Data_B1;
430
          when "11010" =>
431
            Rd_Data          <= DAA_Data_B2;
432
          when "11011" =>
433
            Rd_Data          <= DAA_Data_B3;
434
          when "11100" =>
435
            Rd_Data          <= DAA_Data_B4;
436
          when "11101" =>
437
            Rd_Data(7)       <= DAA_Sign;
438
 
439
          -- Control/Status
440
          when "11111" =>
441
            Rd_Data(0)       <= CNV_Mode;
442
            Rd_Data(1)       <= DAA_Valid;
443
            Rd_Data(7)       <= CNV_Busy;
444
          when others => null;
445
        end case;
446
      end if;
447
 
448
    end if;
449
  end process;
450
 
451
  Conversion_FSM_proc: process( Clock, Reset )
452
  begin
453
    if( Reset = Reset_Level )then
454
      Conv_State             <= IDLE;
455
      Div_Enable             <= '0';
456
      Dividend               <= (others => '0');
457
      Divisor                <= (others => '0');
458
      OperandABC             <= (others => '0');
459
      Accumulator            <= (others => '0');
460
      DAA_Sign               <= '0';
461
      DAA_Buffer             <= (others => '0');
462
      DAA_Next               <= (others => '0');
463
      CNV_Done               <= '0';
464
    elsif( rising_edge(Clock) )then
465
 
466
      Div_Enable             <= '0';
467
      CNV_Done               <= '0';
468
 
469
      case Conv_State is
470
        when IDLE =>
471
          if( CNV_En = '1' )then
472
            Conv_State       <= MULT_WAIT;
473
          end if;
474
 
475
        when MULT_WAIT =>
476
        -- Skip division if the operand is < 2
477
        Conv_State         <= DIV_SKIP;
478
          if( OperandC > 1 )then
479
            Conv_State       <= DIV_START;
480
          end if;
481
 
482
        when DIV_START =>
483
            Div_Enable       <= '1';
484
            Dividend         <= std_logic_vector(Operand_AB);
485
            Divisor          <= std_logic_vector(OperandC);
486
            if( Div_Busy = '1' )then
487
              Conv_State     <= DIV_WAIT;
488
            end if;
489
 
490
        when DIV_WAIT =>
491
          if( Div_Busy = '0' )then
492
            OperandABC       <= signed(Quotient);
493
            Conv_State       <= ACCUM_WAIT;
494
          end if;
495
 
496
        when DIV_SKIP =>
497
          OperandABC         <= Operand_AB;
498
          Conv_State         <= ACCUM_WAIT;
499
 
500
        when ACCUM_WAIT =>
501
          Conv_State         <= DAA_INIT;
502
          if( DAA_En = '0' )then
503
            DAA_Valid        <= '0';
504
            CNV_Done         <= '1';
505
            Conv_State       <= IDLE;
506
          end if;
507
 
508
        when DAA_INIT =>
509
          DAA_Sign           <= '0';
510
          DAA_Next           <= std_logic_vector(Accumulator);
511
          Conv_State         <= DAA_STEP1;
512
          if( RAW_Sign_MSB = '1' and CNV_Mode = CNV_SIGNED )then
513
            Conv_State       <= DAA_NEGATE;
514
          end if;
515
 
516
        when DAA_NEGATE =>
517
          DAA_Sign           <= '1';
518
          DAA_Next           <= (not DAA_Next) + 1;
519
          Conv_State         <= DAA_STEP1;
520
 
521
         when DAA_STEP1 =>
522
          Dividend           <= DAA_Next;
523
          Divisor            <= DAA_ST1_DIV;
524
          Div_Enable         <= '1';
525
          if( DIV_Busy = '1' )then
526
            Conv_State       <= DAA_WAIT1;
527
          end if;
528
 
529
        when DAA_WAIT1 =>
530
          if( DIV_Busy = '0' )then
531
            DAA_Digit_9      <= Quotient(3 downto 0);
532
            DAA_Next         <= Remainder;
533
            Conv_State       <= DAA_STEP2;
534
          end if;
535
 
536
        when DAA_STEP2 =>
537
          Dividend           <= DAA_Next;
538
          Divisor            <= DAA_ST2_DIV;
539
          Div_Enable         <= '1';
540
          if( DIV_Busy = '1' )then
541
            Conv_State       <= DAA_WAIT2;
542
          end if;
543
 
544
        when DAA_WAIT2 =>
545
          if( DIV_Busy = '0' )then
546
            DAA_Digit_8      <= Quotient(3 downto 0);
547
            DAA_Next         <= Remainder;
548
            Conv_State       <= DAA_STEP3;
549
          end if;
550
 
551
        when DAA_STEP3 =>
552
          Dividend           <= DAA_Next;
553
          Divisor            <= DAA_ST3_DIV;
554
          Div_Enable         <= '1';
555
          if( DIV_Busy = '1' )then
556
            Conv_State       <= DAA_WAIT3;
557
          end if;
558
 
559
        when DAA_WAIT3 =>
560
          if( DIV_Busy = '0' )then
561
            DAA_Digit_7      <= Quotient(3 downto 0);
562
            DAA_Next         <= Remainder;
563
            Conv_State       <= DAA_STEP4;
564
          end if;
565
 
566
        when DAA_STEP4 =>
567
          Dividend           <= DAA_Next;
568
          Divisor            <= DAA_ST4_DIV;
569
          Div_Enable         <= '1';
570
          if( DIV_Busy = '1' )then
571
            Conv_State       <= DAA_WAIT4;
572
          end if;
573
 
574
        when DAA_WAIT4 =>
575
          if( DIV_Busy = '0' )then
576
            DAA_Digit_6      <= Quotient(3 downto 0);
577
            DAA_Next         <= Remainder;
578
            Conv_State       <= DAA_STEP5;
579
          end if;
580
 
581
        when DAA_STEP5 =>
582
          Dividend           <= DAA_Next;
583
          Divisor            <= DAA_ST5_DIV;
584
          Div_Enable         <= '1';
585
          if( DIV_Busy = '1' )then
586
            Conv_State       <= DAA_WAIT5;
587
          end if;
588
 
589
        when DAA_WAIT5 =>
590
          if( DIV_Busy = '0' )then
591
            DAA_Digit_5      <= Quotient(3 downto 0);
592
            DAA_Next         <= Remainder;
593
            Conv_State       <= DAA_STEP6;
594
          end if;
595
 
596
        when DAA_STEP6 =>
597
          Dividend           <= DAA_Next;
598
          Divisor            <= DAA_ST6_DIV;
599
          Div_Enable         <= '1';
600
          if( DIV_Busy = '1' )then
601
            Conv_State       <= DAA_WAIT6;
602
          end if;
603
 
604
        when DAA_WAIT6 =>
605
          if( DIV_Busy = '0' )then
606
            DAA_Digit_4      <= Quotient(3 downto 0);
607
            DAA_Next         <= Remainder;
608
            Conv_State       <= DAA_STEP7;
609
          end if;
610
 
611
        when DAA_STEP7 =>
612
          Dividend           <= DAA_Next;
613
          Divisor            <= DAA_ST7_DIV;
614
          Div_Enable         <= '1';
615
          if( DIV_Busy = '1' )then
616
            Conv_State       <= DAA_WAIT7;
617
          end if;
618
 
619
        when DAA_WAIT7 =>
620
          if( DIV_Busy = '0' )then
621
            DAA_Digit_3      <= Quotient(3 downto 0);
622
            DAA_Next         <= Remainder;
623
            Conv_State       <= DAA_STEP8;
624
          end if;
625
 
626
        when DAA_STEP8 =>
627
          Dividend           <= DAA_Next;
628
          Divisor            <= DAA_ST8_DIV;
629
          Div_Enable         <= '1';
630
          if( DIV_Busy = '1' )then
631
            Conv_State       <= DAA_WAIT8;
632
          end if;
633
 
634
        when DAA_WAIT8 =>
635
          if( DIV_Busy = '0' )then
636
            DAA_Digit_2      <= Quotient(3 downto 0);
637
            DAA_Next         <= Remainder;
638
            Conv_State       <= DAA_STEP9;
639
          end if;
640
 
641
        when DAA_STEP9 =>
642
          Dividend           <= DAA_Next;
643
          Divisor            <= DAA_ST9_DIV;
644
          Div_Enable         <= '1';
645
          if( DIV_Busy = '1' )then
646
            Conv_State        <= DAA_WAIT9;
647
          end if;
648
 
649
        when DAA_WAIT9 =>
650
          if( DIV_Busy = '0' )then
651
            DAA_Digit_1      <= Quotient(3 downto 0);
652
            DAA_Digit_0      <= Remainder(3 downto 0);
653
            Conv_State       <= DAA_DONE;
654
          end if;
655
 
656
        when DAA_DONE =>
657
          DAA_Valid          <= '1';
658
          CNV_Done           <= '1';
659
          Conv_State         <= IDLE;
660
 
661
        when others => null;
662
      end case;
663
 
664
      Product_AB             <= OperandA * OperandB;
665
      Accumulator            <= OperandABC + OperandD;
666
 
667
    end if;
668
  end process;
669
 
670
--  Mult_proc: process( Clock)
671
--  begin
672
--    if( rising_edge(Clock) )then
673
--      Product_AB             <= OperandA * OperandB;
674
--    end if;
675
--  end process;
676
 
677
  U_DIV : entity work.intdiv
678
  generic map(
679
    Div_Width                => DIVIDER_WIDTH,
680
    Reset_Level              => Reset_Level
681
  )
682
  port map(
683
    Clock                    => Clock,
684
    Reset                    => Reset,
685
    --
686
    Enable                   => Div_Enable,
687
    Busy                     => Div_Busy,
688
    --
689
    Dividend                 => Dividend,
690
    Divisor                  => Divisor,
691
    Quotient                 => Quotient,
692
    Remainder                => Remainder
693
  );
694
 
695
end architecture;

powered by: WebSVN 2.1.0

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