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

Subversion Repositories yac

[/] [yac/] [trunk/] [rtl/] [vhdl/] [cordic_iterative_int.vhd] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 feddischso
----------------------------------------------------------------------------
2
----                                                                    ----
3
----  File           : cordic_iterative_int.vhd                         ----
4
----  Project        : YAC (Yet Another CORDIC Core)                    ----
5
----  Creation       : Feb. 2014                                        ----
6
----  Limitations    :                                                  ----
7
----  Synthesizer    :                                                  ----
8
----  Target         :                                                  ----
9
----                                                                    ----
10
----  Author(s):     : Christian Haettich                               ----
11
----  Email          : feddischson@opencores.org                        ----
12
----                                                                    ----
13
----                                                                    ----
14
-----                                                                  -----
15
----                                                                    ----
16
----  Description                                                       ----
17
----        VHDL implementation of YAC                                  ----
18
----                                                                    ----
19
----                                                                    ----
20
----                                                                    ----
21
-----                                                                  -----
22
----                                                                    ----
23
----  TODO                                                              ----
24
----        Some documentation and function description                 ----
25
----        Optimization                                                ----
26
----                                                                    ----
27
----                                                                    ----
28
----                                                                    ----
29
----------------------------------------------------------------------------
30
----                                                                    ----
31
----                  Copyright Notice                                  ----
32
----                                                                    ----
33
---- This file is part of YAC - Yet Another CORDIC Core                 ----
34
---- Copyright (c) 2014, Author(s), All rights reserved.                ----
35
----                                                                    ----
36
---- YAC is free software; you can redistribute it and/or               ----
37
---- modify it under the terms of the GNU Lesser General Public         ----
38
---- License as published by the Free Software Foundation; either       ----
39
---- version 3.0 of the License, or (at your option) any later version. ----
40
----                                                                    ----
41
---- YAC is distributed in the hope that it will be useful,             ----
42
---- but WITHOUT ANY WARRANTY; without even the implied warranty of     ----
43
---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  ----
44
---- Lesser General Public License for more details.                    ----
45
----                                                                    ----
46
---- You should have received a copy of the GNU Lesser General Public   ----
47
---- License along with this library. If not, download it from          ----
48
---- http://www.gnu.org/licenses/lgpl                                   ----
49
----                                                                    ----
50
----------------------------------------------------------------------------
51
 
52
 
53
 
54
library ieee;
55
library std;
56
use std.textio.all;
57
use ieee.std_logic_1164.ALL;
58
use ieee.numeric_std.ALL;
59
use ieee.std_logic_textio.all; -- I/O for logic types
60
use work.cordic_pkg.ALL;
61
use ieee.math_real.ALL;
62
 
63
entity cordic_iterative_int is
64
generic(
65
   XY_WIDTH    : natural := 12;
66
   A_WIDTH     : natural := 12;
67
   GUARD_BITS  : natural :=  2;
68
   RM_GAIN     : natural :=  4
69
       );
70
port(
71
   clk, rst  : in  std_logic;
72
   en        : in  std_logic;
73
   start     : in  std_logic;
74
   done      : out std_logic;
75
   mode_i    : in  std_logic_vector( 4-1 downto 0 );
76
   x_i       : in  std_logic_vector( XY_WIDTH-1  downto 0 );
77
   y_i       : in  std_logic_vector( XY_WIDTH-1  downto 0 );
78
   a_i       : in  std_logic_vector( A_WIDTH+2-1 downto 0 );
79
   x_o       : out std_logic_vector( XY_WIDTH+GUARD_BITS-1  downto 0 );
80
   y_o       : out std_logic_vector( XY_WIDTH+GUARD_BITS-1  downto 0 );
81
   a_o       : out std_logic_vector( A_WIDTH+2-1 downto 0 )
82
    );
83
end entity cordic_iterative_int;
84
 
85
 
86
architecture BEHAVIORAL of cordic_iterative_int is
87
 
88
   -- log2( max-iteration )
89
   constant L2_MAX_I    : natural := 8;
90
 
91
   constant MAX_A_WIDTH : natural := 34;
92
 
93
   -- Internal angle width
94
   constant A_WIDTH_I : natural := A_WIDTH+2;
95 3 feddischso
<<<<<<< HEAD
96 4 feddischso
<<<<<<< HEAD
97
=======
98
>>>>>>> Updated C and RTL model as well as the documentation
99 2 feddischso
 
100
 
101
   constant SQRT2_REAL  : real    := 1.4142135623730951454746218587388284504413604;
102
   constant PI_REAL     : real    := 3.1415926535897931159979634685441851615905762;
103
   constant PI          : integer := natural( PI_REAL    * real( 2**( A_WIDTH-1 ) ) + 0.5 );
104
   constant PI_H        : integer := natural( PI_REAL    * real( 2**( A_WIDTH-2 ) ) + 0.5 );
105
   constant SQRT2       : integer := natural( SQRT2_REAL * real( 2**( XY_WIDTH-1 ) ) + 0.5 );
106
   constant XY_MAX      : integer := natural( 2**( XY_WIDTH-1)-1);
107
 
108 4 feddischso
<<<<<<< HEAD
109 3 feddischso
=======
110
 
111
   constant PI_REAL : real    := 3.1415926535897931159979634685441851615905762;
112
   constant PI      : integer := natural( PI_REAL * real( 2**( A_WIDTH-1 ) ) + 0.5 );
113
   constant PI_H    : integer := natural( PI_REAL * real( 2**( A_WIDTH-2 ) ) + 0.5 );
114
>>>>>>> initial commit
115 4 feddischso
=======
116
>>>>>>> Updated C and RTL model as well as the documentation
117 2 feddischso
 
118
   constant XY_WIDTH_G : natural := XY_WIDTH + GUARD_BITS;
119
 
120
 
121
 
122
   type state_st is( ST_IDLE, ST_INIT, ST_ROTATE, ST_RM_GAIN, ST_DONE );
123
   type state_t is record
124
      st       : state_st;
125
      mode     : std_logic_vector( mode_i'range );
126
      x        : signed( XY_WIDTH_G     -1 downto 0 );
127
      y        : signed( XY_WIDTH_G     -1 downto 0 );
128
      x_sh     : signed( XY_WIDTH_G     -1 downto 0 );
129
      y_sh     : signed( XY_WIDTH_G     -1 downto 0 );
130
      x_sum    : signed( XY_WIDTH_G     -1 downto 0 );
131
      y_sum    : signed( XY_WIDTH_G     -1 downto 0 );
132
      a        : signed( A_WIDTH_I      -1 downto 0 );
133
      a_tmp    : signed( A_WIDTH_I      -1 downto 0 );
134
      ylst     : signed( XY_WIDTH_G     -1 downto 0 );
135
      alst     : signed( A_WIDTH_I      -1 downto 0 );
136
      i        : signed( L2_MAX_I       -1 downto 0 );
137
      do_shift : std_logic;
138
      done     : std_logic;
139
      repeate  : std_logic;
140
   end record state_t;
141
   signal state : state_t;
142
 
143
 
144
   ---------------------------------------
145
   -- Auto-generated function 
146
   -- by matlab (see c_octave/cordic_iterative_code.m)
147
   function angular_lut( n : integer; mode : std_logic_vector; ANG_WIDTH : natural ) return signed is
148
      variable result : signed( ANG_WIDTH-1 downto 0 );
149
      variable temp : signed( MAX_A_WIDTH-1 downto 0 );
150
         begin
151
         if mode = VAL_MODE_CIR then
152
            case n is
153
               when 0 => temp := "0110010010000111111011010101000100";   -- -1843415740
154
               when 1 => temp := "0011101101011000110011100000101011";  -- -312264661
155
               when 2 => temp := "0001111101011011011101011111100100";  -- 2104350692
156
               when 3 => temp := "0000111111101010110111010100110101";  -- 1068201269
157
               when 4 => temp := "0000011111111101010101101110110111";  -- 536173495
158
               when 5 => temp := "0000001111111111101010101011011101";  -- 268348125
159
               when 6 => temp := "0000000111111111111101010101010110";  -- 134206806
160
               when 7 => temp := "0000000011111111111111101010101010";  -- 67107498
161
               when 8 => temp := "0000000001111111111111111101010101";  -- 33554261
162
               when 9 => temp := "0000000000111111111111111111101010";  -- 16777194
163
               when 10 => temp := "0000000000011111111111111111111101";         -- 8388605
164
               when others => temp := to_signed( 2**(MAX_A_WIDTH-1-n), MAX_A_WIDTH );
165
            end case;
166
         elsif mode = VAL_MODE_HYP then
167
            case n is
168
               when 1 => temp := "0100011001001111101010011110101010";  -- 423536554
169
               when 2 => temp := "0010000010110001010111011111010100";  -- -2100987948
170
               when 3 => temp := "0001000000010101100010010001110010";  -- 1079387250
171
               when 4 => temp := "0000100000000010101011000100010101";  -- 537571605
172
               when 5 => temp := "0000010000000000010101010110001000";  -- 268522888
173
               when 6 => temp := "0000001000000000000010101010101100";  -- 134228652
174
               when 7 => temp := "0000000100000000000000010101010101";  -- 67110229
175
               when 8 => temp := "0000000010000000000000000010101010";  -- 33554602
176
               when 9 => temp := "0000000001000000000000000000010101";  -- 16777237
177
               when 10 => temp := "0000000000100000000000000000000010";         -- 8388610
178
               when others => temp := to_signed( 2**(MAX_A_WIDTH-1-n), MAX_A_WIDTH );
179
            end case;
180
         elsif mode = VAL_MODE_LIN then
181
            temp := ( others => '0' );
182
            temp( temp'high-1-n downto 0  ) := ( others => '1' );
183
         end if;
184
      result := temp( temp'high downto temp'high-result'length+1 );
185
      return result;
186
   end function angular_lut;
187
   ---------------------------------------
188
 
189
 
190
   function repeat_hyperbolic_it( i : integer ) return boolean is
191
      variable res : boolean;
192
   begin
193
      case i is
194
         when 5         => res := true;
195
         when 14        => res := true;
196
         when 41        => res := true;
197
         when 122       => res := true;
198
         when others    => res := false;
199
      end case;
200
      return res;
201
   end;
202
 
203
begin
204
 
205
 
206
   ST : process( clk, rst )
207
      variable sign : std_logic;
208
    begin
209
 
210
      if clk'event and clk = '1' then
211
         if rst = '1' then
212
             state <= (    st       => ST_IDLE,
213
                           x        => ( others => '0' ),
214
                           y        => ( others => '0' ),
215
                           x_sh     => ( others => '0' ),
216
                           y_sh     => ( others => '0' ),
217
                           x_sum    => ( others => '0' ),
218
                           y_sum    => ( others => '0' ),
219
                           a        => ( others => '0' ),
220
                           a_tmp    => ( others => '0' ),
221
                           ylst     => ( others => '0' ),
222
                           alst     => ( others => '0' ),
223
                           mode     => ( others => '0' ),
224
                           i        => ( others => '0' ),
225
                           done     => '0',
226
                           do_shift => '0',
227
                           repeate  => '0'
228
                           );
229
 
230
         elsif en = '1' then
231
 
232
            if state.st = ST_IDLE and start = '1' then
233
               state.st       <= ST_INIT;
234
               state.mode     <= mode_i;
235
               state.x        <= resize( signed( x_i ), state.x'length );
236
               state.y        <= resize( signed( y_i ), state.y'length );
237
               state.a        <= resize( signed( a_i ), state.a'length );
238
               state.i        <= ( others => '0' );
239
 
240 3 feddischso
<<<<<<< HEAD
241 4 feddischso
<<<<<<< HEAD
242 2 feddischso
            elsif state.st = ST_INIT then
243
               -- 
244
               -- initialization state
245
               --    -> do initial rotation (alignment)
246
               --    -> check special situations / miss-configurations (TODO)
247
               --
248
 
249 3 feddischso
=======
250
            -- 
251
            -- initialization state
252
            --    -> do initial rotation (alignment)
253
            --    -> check special situations / miss-configurations (TODO)
254
            --
255
            elsif state.st = ST_INIT then
256
>>>>>>> initial commit
257 4 feddischso
=======
258
            elsif state.st = ST_INIT then
259
               -- 
260
               -- initialization state
261
               --    -> do initial rotation (alignment)
262
               --    -> check special situations / miss-configurations (TODO)
263
               --
264
 
265
>>>>>>> Updated C and RTL model as well as the documentation
266 2 feddischso
               state.st       <= ST_ROTATE;
267
               state.do_shift <= '1';
268
 
269
 
270 3 feddischso
<<<<<<< HEAD
271 4 feddischso
<<<<<<< HEAD
272 2 feddischso
               if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
273
                  -- if we do a hyperbolic rotation, we start with 1
274 3 feddischso
=======
275
               -- if we do a hyperbolic rotation, we start with 1
276
               if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
277
>>>>>>> initial commit
278 4 feddischso
=======
279
               if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
280
                  -- if we do a hyperbolic rotation, we start with 1
281
>>>>>>> Updated C and RTL model as well as the documentation
282 2 feddischso
                  state.i(0) <= '1';
283
               end if;
284
 
285
 
286
 
287
 
288 3 feddischso
<<<<<<< HEAD
289 4 feddischso
<<<<<<< HEAD
290 2 feddischso
               if     state.mode( I_FLAG_VEC_ROT ) = '0'
291
                  and state.mode( 1 downto 0 )   =  VAL_MODE_CIR  then
292
                  -- circular vector mode
293
 
294
                  if state.a < - PI_H then
295
                     -- move from third quadrant to first
296
                     state.a <= state.a + PI;
297
                     state.x <= - state.x;
298
                     state.y <= - state.y;
299
                  elsif state.a > PI_H then
300
                     -- move from second quadrant to fourth
301 3 feddischso
=======
302
               -- circular vector mode
303
               if     state.mode( FLAG_VEC_ROT ) = '0'
304 4 feddischso
=======
305
               if     state.mode( I_FLAG_VEC_ROT ) = '0'
306
>>>>>>> Updated C and RTL model as well as the documentation
307 3 feddischso
                  and state.mode( 1 downto 0 )   =  VAL_MODE_CIR  then
308 4 feddischso
                  -- circular vector mode
309 3 feddischso
 
310
                  if state.a < - PI_H then
311 4 feddischso
                     -- move from third quadrant to first
312 3 feddischso
                     state.a <= state.a + PI;
313
                     state.x <= - state.x;
314
                     state.y <= - state.y;
315
                  elsif state.a > PI_H then
316 4 feddischso
<<<<<<< HEAD
317 3 feddischso
>>>>>>> initial commit
318 4 feddischso
=======
319
                     -- move from second quadrant to fourth
320
>>>>>>> Updated C and RTL model as well as the documentation
321 2 feddischso
                     state.a <= state.a - PI;
322
                     state.x <= - state.x;
323
                     state.y <= - state.y;
324
                  end if;
325
 
326 3 feddischso
<<<<<<< HEAD
327 4 feddischso
<<<<<<< HEAD
328 2 feddischso
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
329
                   and state.mode( 1 downto 0 )   = VAL_MODE_CIR then
330
                  -- circular rotation mode
331
 
332
                  if state.x = 0 and state.y = 0 then
333
                     -- zero-input
334
                     state.a  <= ( others => '0' );
335
                     state.y  <= ( others => '0' );
336
                     state.st <= ST_DONE;
337
 
338
                  elsif state.x = XY_MAX and state.y = XY_MAX then
339
                     -- all-max 1
340
                     state.a  <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
341
                     state.x  <= to_signed( SQRT2, state.x'length );
342
                     state.y  <= (others => '0' );
343
                     state.st <= ST_DONE;
344
                  elsif state.x = -XY_MAX and state.y = -XY_MAX then
345
                     -- all-max 2
346
                     state.a  <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI;
347
                     state.x  <= to_signed( SQRT2, state.x'length );
348
                     state.y  <= (others => '0' );
349
                     state.st <= ST_DONE;
350
                  elsif state.x = XY_MAX and state.y = -XY_MAX then
351
                     -- all-max 3
352
                     state.a  <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
353
                     state.x  <= to_signed( SQRT2, state.x'length );
354
                     state.y  <= (others => '0' );
355
                     state.st <= ST_DONE;
356
                  elsif state.x = -XY_MAX and state.y = XY_MAX then
357
                     -- all-max 4
358
                     state.a  <= PI-  resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
359
                     state.x  <= to_signed( SQRT2, state.x'length );
360
                     state.y  <= (others => '0' );
361
                     state.st <= ST_DONE;
362
 
363
                  elsif state.x = 0 and state.y > 0 then
364
                     -- fixed rotation of pi/2
365
                     state.a  <= to_signed( PI_H, state.a'length );
366
                     state.x  <= state.y;
367
                     state.y  <= ( others => '0' );
368
                     state.st<= ST_DONE;
369
                  elsif state.x = 0 and state.y < 0 then
370
                     -- fixed rotation of -pi/2
371
                     state.a  <= to_signed( -PI_H, state.a'length );
372
                     state.x  <= -state.y;
373
                     state.y  <= ( others => '0' );
374
                     state.st<= ST_DONE;
375
 
376
                  elsif state.x < 0 and state.y >= 0 then
377
                     -- move from second quadrant to fourth
378
                     state.x <= - state.x;
379
                     state.y <= - state.y;
380
                     state.a <= to_signed(  PI, state.a'length );
381
                  elsif state.x < 0 and state.y < 0 then
382
                     -- move from third quadrant to first
383
                     state.x <= - state.x;
384
                     state.y <= - state.y;
385
                     state.a <= to_signed( -PI, state.a'length );
386
                  else
387
                     state.a <= ( others => '0' );
388
                  end if;
389
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
390
                   and state.mode( 1 downto 0 )   = VAL_MODE_LIN then
391
                  -- linear rotation mode
392
                  if state.x < 0 then
393
                     state.x <= - state.x;
394
                     state.y <= - state.y;
395
                  end if;
396
                  state.a <= to_signed( 0, state.a'length );
397 3 feddischso
=======
398
               -- circular rotation mode
399
               elsif   state.mode( FLAG_VEC_ROT ) = '1'
400 4 feddischso
=======
401
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
402
>>>>>>> Updated C and RTL model as well as the documentation
403 3 feddischso
                   and state.mode( 1 downto 0 )   = VAL_MODE_CIR then
404 4 feddischso
                  -- circular rotation mode
405 2 feddischso
 
406 4 feddischso
                  if state.x = 0 and state.y = 0 then
407
                     -- zero-input
408
                     state.a  <= ( others => '0' );
409
                     state.y  <= ( others => '0' );
410
                     state.st <= ST_DONE;
411
 
412
                  elsif state.x = XY_MAX and state.y = XY_MAX then
413
                     -- all-max 1
414
                     state.a  <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
415
                     state.x  <= to_signed( SQRT2, state.x'length );
416
                     state.y  <= (others => '0' );
417
                     state.st <= ST_DONE;
418
                  elsif state.x = -XY_MAX and state.y = -XY_MAX then
419
                     -- all-max 2
420
                     state.a  <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI;
421
                     state.x  <= to_signed( SQRT2, state.x'length );
422
                     state.y  <= (others => '0' );
423
                     state.st <= ST_DONE;
424
                  elsif state.x = XY_MAX and state.y = -XY_MAX then
425
                     -- all-max 3
426
                     state.a  <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
427
                     state.x  <= to_signed( SQRT2, state.x'length );
428
                     state.y  <= (others => '0' );
429
                     state.st <= ST_DONE;
430
                  elsif state.x = -XY_MAX and state.y = XY_MAX then
431
                     -- all-max 4
432
                     state.a  <= PI-  resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
433
                     state.x  <= to_signed( SQRT2, state.x'length );
434
                     state.y  <= (others => '0' );
435
                     state.st <= ST_DONE;
436
 
437
                  elsif state.x = 0 and state.y > 0 then
438
                     -- fixed rotation of pi/2
439
                     state.a  <= to_signed( PI_H, state.a'length );
440
                     state.x  <= state.y;
441
                     state.y  <= ( others => '0' );
442
                     state.st<= ST_DONE;
443
                  elsif state.x = 0 and state.y < 0 then
444
                     -- fixed rotation of -pi/2
445
                     state.a  <= to_signed( -PI_H, state.a'length );
446
                     state.x  <= -state.y;
447
                     state.y  <= ( others => '0' );
448
                     state.st<= ST_DONE;
449
 
450
                  elsif state.x < 0 and state.y >= 0 then
451
                     -- move from second quadrant to fourth
452 3 feddischso
                     state.x <= - state.x;
453
                     state.y <= - state.y;
454
                     state.a <= to_signed(  PI, state.a'length );
455
                  elsif state.x < 0 and state.y < 0 then
456 4 feddischso
                     -- move from third quadrant to first
457 3 feddischso
                     state.x <= - state.x;
458
                     state.y <= - state.y;
459
                     state.a <= to_signed( -PI, state.a'length );
460
                  else
461
                     state.a <= ( others => '0' );
462
                  end if;
463 4 feddischso
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
464 3 feddischso
                   and state.mode( 1 downto 0 )   = VAL_MODE_LIN then
465 4 feddischso
<<<<<<< HEAD
466 3 feddischso
 
467
                     if state.x < 0 then
468
                        state.x <= - state.x;
469
                        state.y <= - state.y;
470
                     end if;
471
                     state.a <= to_signed( 0, state.a'length );
472
>>>>>>> initial commit
473 4 feddischso
=======
474
                  -- linear rotation mode
475
                  if state.x < 0 then
476
                     state.x <= - state.x;
477
                     state.y <= - state.y;
478
                  end if;
479
                  state.a <= to_signed( 0, state.a'length );
480
>>>>>>> Updated C and RTL model as well as the documentation
481 3 feddischso
 
482 2 feddischso
               end if;
483
 
484
 
485
 
486
 
487
 
488
            --
489
            -- rotation state
490
            --
491
            -- Each rotation takes 
492
            --           two steps: in the first step, the shifting is
493
            --                      done, in the second step, the
494
            --                      shift-result is added/subtracted
495
            -- 
496
            --
497
            --
498
            elsif state.st = ST_ROTATE then
499
 
500
               -- get the sign
501 3 feddischso
<<<<<<< HEAD
502 4 feddischso
<<<<<<< HEAD
503 2 feddischso
               if state.mode( I_FLAG_VEC_ROT )  = '0' then
504 3 feddischso
=======
505
               if state.mode( FLAG_VEC_ROT )  = '0' then
506
>>>>>>> initial commit
507 4 feddischso
=======
508
               if state.mode( I_FLAG_VEC_ROT )  = '0' then
509
>>>>>>> Updated C and RTL model as well as the documentation
510 2 feddischso
                  if state.a < 0 then
511
                     sign := '0';
512
                  else
513
                     sign := '1';
514
                  end if;
515
               else
516
                  if state.y < 0 then
517
                     sign := '1';
518
                  else
519
                     sign := '0';
520
                  end if;
521
               end if;
522
 
523
 
524
 
525
               if state.do_shift = '1' then
526
                  -- get the angle, do the shifting and set the right angle
527
 
528
                  if sign = '1' then
529
 
530
                     -- circular case
531
                     if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
532
 
533
                        state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH), A_WIDTH_I );
534
                        state.y_sh  <= - SHIFT_RIGHT( state.y, to_integer( state.i ) );
535
 
536
                     -- hyperbolic case
537
                     elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
538
 
539
                        state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH), A_WIDTH_I );
540
                        state.y_sh  <= SHIFT_RIGHT( state.y, to_integer( state.i ) );
541
 
542
                     -- linear case
543
                     else
544
 
545
                        state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH  ), A_WIDTH_I ) ;
546
                        state.y_sh  <= ( others => '0' );
547
 
548
                     end if;
549
                     state.x_sh <=   SHIFT_RIGHT( state.x, to_integer( state.i ) );
550
 
551
                  else
552
 
553
                     -- circular case
554
                     if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
555
 
556
                        state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
557
                        state.y_sh  <= SHIFT_RIGHT( state.y, to_integer( state.i ) );
558
 
559
                     -- hyperbolic case
560
                     elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
561
 
562
                        state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
563
                        state.y_sh  <= - SHIFT_RIGHT( state.y, to_integer( state.i ) );
564
 
565
                     -- linear case
566
                     else
567
 
568
                        state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) ;
569
                        state.y_sh  <= ( others => '0' );
570
 
571
                     end if;
572
                     state.x_sh <= - SHIFT_RIGHT( state.x, to_integer( state.i ) );
573
 
574
                  end if;
575
                  state.do_shift <= '0';
576
 
577
                  -- abort condition
578 3 feddischso
<<<<<<< HEAD
579 4 feddischso
<<<<<<< HEAD
580 2 feddischso
                  if(   state.mode( I_FLAG_VEC_ROT ) = '0' and
581
                        state.a = 0 ) then
582
                     state.st <= ST_RM_GAIN;
583
                     state.i  <= ( others => '0' );
584
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '0' and
585
                        state.a = state.alst ) then
586
                     state.st <= ST_RM_GAIN;
587
                     state.i  <= ( others => '0' );
588
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
589
                        state.y = 0 ) then
590
                     state.st <= ST_RM_GAIN;
591
                     state.i  <= ( others => '0' );
592
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
593 3 feddischso
=======
594
                  if(   state.mode( FLAG_VEC_ROT ) = '0' and
595
                        ( state.a = 0 or state.a = -1 ) ) then
596 4 feddischso
=======
597
                  if(   state.mode( I_FLAG_VEC_ROT ) = '0' and
598
                        state.a = 0 ) then
599
>>>>>>> Updated C and RTL model as well as the documentation
600 3 feddischso
                     state.st <= ST_RM_GAIN;
601
                     state.i  <= ( others => '0' );
602 4 feddischso
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '0' and
603
                        state.a = state.alst ) then
604 3 feddischso
                     state.st <= ST_RM_GAIN;
605
                     state.i  <= ( others => '0' );
606 4 feddischso
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
607
                        state.y = 0 ) then
608 3 feddischso
                     state.st <= ST_RM_GAIN;
609
                     state.i  <= ( others => '0' );
610 4 feddischso
<<<<<<< HEAD
611 3 feddischso
                  elsif(   state.mode( FLAG_VEC_ROT ) = '1' and
612
>>>>>>> initial commit
613 4 feddischso
=======
614
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
615
>>>>>>> Updated C and RTL model as well as the documentation
616 2 feddischso
                        ( state.y = state.ylst ) ) then
617
                     state.st <= ST_RM_GAIN;
618
                     state.i  <= ( others => '0' );
619
                  end if;
620
 
621
                  state.ylst  <= state.y;
622
                  state.alst  <= state.a;
623
 
624
 
625
               else
626
                  state.x <= state.x + state.y_sh;
627
                  state.y <= state.y + state.x_sh;
628
                  state.a <= state.a + state.a_tmp;
629
                  if VAL_MODE_HYP = state.mode( 1 downto 0 )         and
630
                     state.repeate = '0'                             and
631
                     repeat_hyperbolic_it( to_integer( state.i ) )   then
632
                     state.repeate <= '1';
633
                  else
634
                     state.repeate  <= '0';
635
                     state.i        <= state.i+1;
636
                  end if;
637
                  state.do_shift <= '1';
638
               end if;
639
 
640
 
641
 
642
 
643
 
644
            --
645
            -- removal of the cordic gain
646
            --
647
            elsif state.st = ST_RM_GAIN then
648
               -- we need RM_GAIN+1 cycles to 
649
               -- calculate the RM_GAIN steps
650
               if state.i = (RM_GAIN) then
651
                 state.st   <= ST_DONE;
652
                 state.done <= '1';
653
                   state.i <= ( others => '0' );
654
               else
655
                   state.i  <= state.i + 1;
656
               end if;
657
 
658
               if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
659
                  mult_0_61( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN );
660
                  mult_0_61( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN );
661
               elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
662
                  mult_0_21( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN );
663
                  mult_0_21( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN );
664
               else
665
                  -- TODO  merge ST_DONE and state.done
666
                  state.done <= '1';
667
                  state.st    <= ST_DONE;
668
                  state.x_sum <= state.x;
669
                  state.y_sum <= state.y;
670
               end if;
671
 
672
 
673
            elsif state.st = ST_DONE then
674
               state.st    <= ST_IDLE;
675
               state.done  <= '0';
676
            end if;
677
            -- end states
678
 
679
 
680
 
681
         end if;
682
         -- end ena
683
 
684
 
685
      end if;
686
      -- end clk
687
 
688
   end process;
689
   done        <=                   state.done   ;
690
   x_o         <= std_logic_vector( state.x_sum );
691
   y_o         <= std_logic_vector( state.y_sum );
692
   a_o         <= std_logic_vector( state.a );
693
 
694
end architecture BEHAVIORAL;
695
 
696
 
697
 

powered by: WebSVN 2.1.0

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