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

Subversion Repositories yac

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

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 7 feddischso
 
88 2 feddischso
   -- 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 7 feddischso
<<<<<<< HEAD
98 4 feddischso
=======
99
>>>>>>> Updated C and RTL model as well as the documentation
100 2 feddischso
 
101 7 feddischso
=======
102 2 feddischso
 
103 7 feddischso
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
104
 
105 2 feddischso
   constant SQRT2_REAL  : real    := 1.4142135623730951454746218587388284504413604;
106
   constant PI_REAL     : real    := 3.1415926535897931159979634685441851615905762;
107 7 feddischso
   constant PI          : integer := natural( round( PI_REAL    * real( 2**( A_WIDTH-1  ) ) ) );
108
   constant PI_H        : integer := natural( round( PI_REAL    * real( 2**( A_WIDTH-2  ) ) ) );
109
   constant SQRT2       : integer := natural( round( SQRT2_REAL * real( 2**( XY_WIDTH-1 ) ) ) );
110 2 feddischso
   constant XY_MAX      : integer := natural( 2**( XY_WIDTH-1)-1);
111
 
112 4 feddischso
<<<<<<< HEAD
113 3 feddischso
=======
114
 
115
   constant PI_REAL : real    := 3.1415926535897931159979634685441851615905762;
116
   constant PI      : integer := natural( PI_REAL * real( 2**( A_WIDTH-1 ) ) + 0.5 );
117
   constant PI_H    : integer := natural( PI_REAL * real( 2**( A_WIDTH-2 ) ) + 0.5 );
118
>>>>>>> initial commit
119 4 feddischso
=======
120
>>>>>>> Updated C and RTL model as well as the documentation
121 2 feddischso
 
122
   constant XY_WIDTH_G : natural := XY_WIDTH + GUARD_BITS;
123
 
124
 
125
 
126
   type state_st is( ST_IDLE, ST_INIT, ST_ROTATE, ST_RM_GAIN, ST_DONE );
127
   type state_t is record
128
      st       : state_st;
129
      mode     : std_logic_vector( mode_i'range );
130
      x        : signed( XY_WIDTH_G     -1 downto 0 );
131
      y        : signed( XY_WIDTH_G     -1 downto 0 );
132
      x_sh     : signed( XY_WIDTH_G     -1 downto 0 );
133
      y_sh     : signed( XY_WIDTH_G     -1 downto 0 );
134
      x_sum    : signed( XY_WIDTH_G     -1 downto 0 );
135
      y_sum    : signed( XY_WIDTH_G     -1 downto 0 );
136
      a        : signed( A_WIDTH_I      -1 downto 0 );
137
      a_tmp    : signed( A_WIDTH_I      -1 downto 0 );
138
      ylst     : signed( XY_WIDTH_G     -1 downto 0 );
139
      alst     : signed( A_WIDTH_I      -1 downto 0 );
140
      i        : signed( L2_MAX_I       -1 downto 0 );
141
      do_shift : std_logic;
142
      repeate  : std_logic;
143
   end record state_t;
144
   signal state : state_t;
145
 
146
 
147 7 feddischso
 
148 2 feddischso
   ---------------------------------------
149
   -- Auto-generated function 
150
   -- by matlab (see c_octave/cordic_iterative_code.m)
151
   function angular_lut( n : integer; mode : std_logic_vector; ANG_WIDTH : natural ) return signed is
152
      variable result : signed( ANG_WIDTH-1 downto 0 );
153
      variable temp : signed( MAX_A_WIDTH-1 downto 0 );
154
         begin
155
         if mode = VAL_MODE_CIR then
156
            case n is
157
               when 0 => temp := "0110010010000111111011010101000100";   -- -1843415740
158
               when 1 => temp := "0011101101011000110011100000101011";  -- -312264661
159
               when 2 => temp := "0001111101011011011101011111100100";  -- 2104350692
160
               when 3 => temp := "0000111111101010110111010100110101";  -- 1068201269
161
               when 4 => temp := "0000011111111101010101101110110111";  -- 536173495
162
               when 5 => temp := "0000001111111111101010101011011101";  -- 268348125
163
               when 6 => temp := "0000000111111111111101010101010110";  -- 134206806
164
               when 7 => temp := "0000000011111111111111101010101010";  -- 67107498
165
               when 8 => temp := "0000000001111111111111111101010101";  -- 33554261
166
               when 9 => temp := "0000000000111111111111111111101010";  -- 16777194
167
               when 10 => temp := "0000000000011111111111111111111101";         -- 8388605
168
               when others => temp := to_signed( 2**(MAX_A_WIDTH-1-n), MAX_A_WIDTH );
169
            end case;
170
         elsif mode = VAL_MODE_HYP then
171
            case n is
172
               when 1 => temp := "0100011001001111101010011110101010";  -- 423536554
173
               when 2 => temp := "0010000010110001010111011111010100";  -- -2100987948
174
               when 3 => temp := "0001000000010101100010010001110010";  -- 1079387250
175
               when 4 => temp := "0000100000000010101011000100010101";  -- 537571605
176
               when 5 => temp := "0000010000000000010101010110001000";  -- 268522888
177
               when 6 => temp := "0000001000000000000010101010101100";  -- 134228652
178
               when 7 => temp := "0000000100000000000000010101010101";  -- 67110229
179
               when 8 => temp := "0000000010000000000000000010101010";  -- 33554602
180
               when 9 => temp := "0000000001000000000000000000010101";  -- 16777237
181
               when 10 => temp := "0000000000100000000000000000000010";         -- 8388610
182
               when others => temp := to_signed( 2**(MAX_A_WIDTH-1-n), MAX_A_WIDTH );
183
            end case;
184
         elsif mode = VAL_MODE_LIN then
185
            temp := ( others => '0' );
186
            temp( temp'high-1-n downto 0  ) := ( others => '1' );
187
         end if;
188
      result := temp( temp'high downto temp'high-result'length+1 );
189
      return result;
190
   end function angular_lut;
191
   ---------------------------------------
192
 
193
 
194
   function repeat_hyperbolic_it( i : integer ) return boolean is
195
      variable res : boolean;
196
   begin
197
      case i is
198
         when 5         => res := true;
199
         when 14        => res := true;
200
         when 41        => res := true;
201
         when 122       => res := true;
202
         when others    => res := false;
203
      end case;
204
      return res;
205
   end;
206
 
207
begin
208
 
209
 
210
   ST : process( clk, rst )
211
      variable sign : std_logic;
212
    begin
213
 
214
      if clk'event and clk = '1' then
215
         if rst = '1' then
216
             state <= (    st       => ST_IDLE,
217
                           x        => ( others => '0' ),
218
                           y        => ( others => '0' ),
219
                           x_sh     => ( others => '0' ),
220
                           y_sh     => ( others => '0' ),
221
                           x_sum    => ( others => '0' ),
222
                           y_sum    => ( others => '0' ),
223
                           a        => ( others => '0' ),
224
                           a_tmp    => ( others => '0' ),
225
                           ylst     => ( others => '0' ),
226
                           alst     => ( others => '0' ),
227
                           mode     => ( others => '0' ),
228
                           i        => ( others => '0' ),
229
                           do_shift => '0',
230
                           repeate  => '0'
231
                           );
232 7 feddischso
 
233 2 feddischso
         elsif en = '1' then
234 7 feddischso
 
235 2 feddischso
            if state.st = ST_IDLE and start = '1' then
236
               state.st       <= ST_INIT;
237
               state.mode     <= mode_i;
238
               state.x        <= resize( signed( x_i ), state.x'length );
239
               state.y        <= resize( signed( y_i ), state.y'length );
240
               state.a        <= resize( signed( a_i ), state.a'length );
241
               state.i        <= ( others => '0' );
242 7 feddischso
<<<<<<< HEAD
243 2 feddischso
 
244 3 feddischso
<<<<<<< HEAD
245 4 feddischso
<<<<<<< HEAD
246 2 feddischso
            elsif state.st = ST_INIT then
247
               -- 
248
               -- initialization state
249
               --    -> do initial rotation (alignment)
250
               --    -> check special situations / miss-configurations (TODO)
251
               --
252
 
253 3 feddischso
=======
254
            -- 
255
            -- initialization state
256
            --    -> do initial rotation (alignment)
257
            --    -> check special situations / miss-configurations (TODO)
258
            --
259
            elsif state.st = ST_INIT then
260
>>>>>>> initial commit
261 4 feddischso
=======
262 7 feddischso
=======
263
               state.alst     <= ( others => '0' );
264
               state.ylst     <= ( others => '0' );
265
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
266 4 feddischso
            elsif state.st = ST_INIT then
267
               -- 
268
               -- initialization state
269
               --    -> do initial rotation (alignment)
270
               --    -> check special situations / miss-configurations (TODO)
271
               --
272
 
273
>>>>>>> Updated C and RTL model as well as the documentation
274 2 feddischso
               state.st       <= ST_ROTATE;
275
               state.do_shift <= '1';
276
 
277
 
278 3 feddischso
<<<<<<< HEAD
279 4 feddischso
<<<<<<< HEAD
280 7 feddischso
<<<<<<< HEAD
281 2 feddischso
               if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
282
                  -- if we do a hyperbolic rotation, we start with 1
283 3 feddischso
=======
284
               -- if we do a hyperbolic rotation, we start with 1
285
               if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
286
>>>>>>> initial commit
287 4 feddischso
=======
288
               if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
289
                  -- if we do a hyperbolic rotation, we start with 1
290
>>>>>>> Updated C and RTL model as well as the documentation
291 2 feddischso
                  state.i(0) <= '1';
292
               end if;
293
 
294
 
295
 
296
 
297 3 feddischso
<<<<<<< HEAD
298 4 feddischso
<<<<<<< HEAD
299 2 feddischso
               if     state.mode( I_FLAG_VEC_ROT ) = '0'
300 7 feddischso
=======
301
              if state.mode( 1 downto 0 ) = VAL_MODE_HYP then
302
                 -- if we do a hyperbolic rotation, we start with 1
303
                 state.i(0) <= '1';
304
              end if;
305
 
306
 
307
 
308
              if state.mode( I_FLAG_VEC_ROT ) = '1' and state.y = 0 then
309
                     -- zero-input
310
                     state.x_sum  <= state.x;
311
                     state.y_sum  <= state.y;
312
                     state.a      <= ( others => '0' );
313
                     state.st     <= ST_DONE;
314
 
315
              elsif state.mode( I_FLAG_VEC_ROT ) = '0' and state.a = 0 then
316
                     -- nothing to do, a is zero
317
                     state.x_sum  <= state.x;
318
                     state.y_sum  <= state.y;
319
                     state.st     <= ST_DONE;
320
 
321
              elsif     state.mode( I_FLAG_VEC_ROT ) = '0'
322
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
323 2 feddischso
                  and state.mode( 1 downto 0 )   =  VAL_MODE_CIR  then
324
                  -- circular vector mode
325
 
326
                  if state.a < - PI_H then
327
                     -- move from third quadrant to first
328
                     state.a <= state.a + PI;
329
                     state.x <= - state.x;
330
                     state.y <= - state.y;
331
                  elsif state.a > PI_H then
332
                     -- move from second quadrant to fourth
333 3 feddischso
=======
334
               -- circular vector mode
335
               if     state.mode( FLAG_VEC_ROT ) = '0'
336 4 feddischso
=======
337
               if     state.mode( I_FLAG_VEC_ROT ) = '0'
338
>>>>>>> Updated C and RTL model as well as the documentation
339 3 feddischso
                  and state.mode( 1 downto 0 )   =  VAL_MODE_CIR  then
340 4 feddischso
                  -- circular vector mode
341 3 feddischso
 
342
                  if state.a < - PI_H then
343 4 feddischso
                     -- move from third quadrant to first
344 3 feddischso
                     state.a <= state.a + PI;
345
                     state.x <= - state.x;
346
                     state.y <= - state.y;
347
                  elsif state.a > PI_H then
348 4 feddischso
<<<<<<< HEAD
349 3 feddischso
>>>>>>> initial commit
350 4 feddischso
=======
351
                     -- move from second quadrant to fourth
352
>>>>>>> Updated C and RTL model as well as the documentation
353 2 feddischso
                     state.a <= state.a - PI;
354
                     state.x <= - state.x;
355
                     state.y <= - state.y;
356
                  end if;
357
 
358 3 feddischso
<<<<<<< HEAD
359 4 feddischso
<<<<<<< HEAD
360 2 feddischso
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
361
                   and state.mode( 1 downto 0 )   = VAL_MODE_CIR then
362
                  -- circular rotation mode
363
 
364
                  if state.x = 0 and state.y = 0 then
365
                     -- zero-input
366
                     state.a  <= ( others => '0' );
367
                     state.y  <= ( others => '0' );
368
                     state.st <= ST_DONE;
369
 
370
                  elsif state.x = XY_MAX and state.y = XY_MAX then
371
                     -- all-max 1
372
                     state.a  <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
373
                     state.x  <= to_signed( SQRT2, state.x'length );
374
                     state.y  <= (others => '0' );
375
                     state.st <= ST_DONE;
376
                  elsif state.x = -XY_MAX and state.y = -XY_MAX then
377
                     -- all-max 2
378
                     state.a  <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI;
379
                     state.x  <= to_signed( SQRT2, state.x'length );
380
                     state.y  <= (others => '0' );
381
                     state.st <= ST_DONE;
382
                  elsif state.x = XY_MAX and state.y = -XY_MAX then
383
                     -- all-max 3
384
                     state.a  <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
385
                     state.x  <= to_signed( SQRT2, state.x'length );
386
                     state.y  <= (others => '0' );
387
                     state.st <= ST_DONE;
388
                  elsif state.x = -XY_MAX and state.y = XY_MAX then
389
                     -- all-max 4
390
                     state.a  <= PI-  resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
391
                     state.x  <= to_signed( SQRT2, state.x'length );
392
                     state.y  <= (others => '0' );
393
                     state.st <= ST_DONE;
394
 
395
                  elsif state.x = 0 and state.y > 0 then
396
                     -- fixed rotation of pi/2
397
                     state.a  <= to_signed( PI_H, state.a'length );
398
                     state.x  <= state.y;
399
                     state.y  <= ( others => '0' );
400
                     state.st<= ST_DONE;
401
                  elsif state.x = 0 and state.y < 0 then
402
                     -- fixed rotation of -pi/2
403
                     state.a  <= to_signed( -PI_H, state.a'length );
404
                     state.x  <= -state.y;
405
                     state.y  <= ( others => '0' );
406
                     state.st<= ST_DONE;
407
 
408
                  elsif state.x < 0 and state.y >= 0 then
409
                     -- move from second quadrant to fourth
410
                     state.x <= - state.x;
411
                     state.y <= - state.y;
412
                     state.a <= to_signed(  PI, state.a'length );
413
                  elsif state.x < 0 and state.y < 0 then
414
                     -- move from third quadrant to first
415
                     state.x <= - state.x;
416
                     state.y <= - state.y;
417
                     state.a <= to_signed( -PI, state.a'length );
418
                  else
419
                     state.a <= ( others => '0' );
420
                  end if;
421
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
422
                   and state.mode( 1 downto 0 )   = VAL_MODE_LIN then
423
                  -- linear rotation mode
424
                  if state.x < 0 then
425
                     state.x <= - state.x;
426
                     state.y <= - state.y;
427
                  end if;
428
                  state.a <= to_signed( 0, state.a'length );
429 3 feddischso
=======
430
               -- circular rotation mode
431
               elsif   state.mode( FLAG_VEC_ROT ) = '1'
432 4 feddischso
=======
433
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
434
>>>>>>> Updated C and RTL model as well as the documentation
435 3 feddischso
                   and state.mode( 1 downto 0 )   = VAL_MODE_CIR then
436 4 feddischso
                  -- circular rotation mode
437 2 feddischso
 
438 7 feddischso
                  if state.y = 0 then
439 4 feddischso
                     -- zero-input
440 7 feddischso
                     state.x_sum  <= state.x;
441
                     state.y_sum  <= state.y;
442
                     state.a      <= ( others => '0' );
443
                     state.st     <= ST_DONE;
444 4 feddischso
 
445
                  elsif state.x = XY_MAX and state.y = XY_MAX then
446
                     -- all-max 1
447 7 feddischso
                     state.x_sum  <= to_signed( SQRT2, state.x'length );
448
                     state.y_sum  <= (others => '0' );
449
                     state.a      <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
450
                     state.st     <= ST_DONE;
451 4 feddischso
                  elsif state.x = -XY_MAX and state.y = -XY_MAX then
452
                     -- all-max 2
453 7 feddischso
                     state.x_sum  <= to_signed( SQRT2, state.x'length );
454
                     state.y_sum  <= (others => '0' );
455
                     state.a      <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI;
456
                     state.st     <= ST_DONE;
457 4 feddischso
                  elsif state.x = XY_MAX and state.y = -XY_MAX then
458
                     -- all-max 3
459 7 feddischso
                     state.x_sum  <= to_signed( SQRT2, state.x'length );
460
                     state.y_sum  <= (others => '0' );
461
                     state.a      <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
462
                     state.st     <= ST_DONE;
463 4 feddischso
                  elsif state.x = -XY_MAX and state.y = XY_MAX then
464
                     -- all-max 4
465 7 feddischso
                     state.x_sum  <= to_signed( SQRT2, state.x'length );
466
                     state.y_sum  <= (others => '0' );
467
                     state.a      <= PI-  resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
468
                     state.st     <= ST_DONE;
469 4 feddischso
 
470
                  elsif state.x = 0 and state.y > 0 then
471
                     -- fixed rotation of pi/2
472 7 feddischso
                     state.x_sum  <= state.y;
473
                     state.y_sum  <= ( others => '0' );
474
                     state.a      <= to_signed( PI_H, state.a'length );
475
                     state.st     <= ST_DONE;
476 4 feddischso
                  elsif state.x = 0 and state.y < 0 then
477
                     -- fixed rotation of -pi/2
478 7 feddischso
                     state.x_sum  <= -state.y;
479
                     state.y_sum  <= ( others => '0' );
480
                     state.a      <= to_signed( -PI_H, state.a'length );
481
                     state.st     <= ST_DONE;
482 4 feddischso
 
483
                  elsif state.x < 0 and state.y >= 0 then
484
                     -- move from second quadrant to fourth
485 3 feddischso
                     state.x <= - state.x;
486
                     state.y <= - state.y;
487
                     state.a <= to_signed(  PI, state.a'length );
488
                  elsif state.x < 0 and state.y < 0 then
489 4 feddischso
                     -- move from third quadrant to first
490 3 feddischso
                     state.x <= - state.x;
491
                     state.y <= - state.y;
492
                     state.a <= to_signed( -PI, state.a'length );
493
                  else
494
                     state.a <= ( others => '0' );
495
                  end if;
496 4 feddischso
               elsif   state.mode( I_FLAG_VEC_ROT ) = '1'
497 3 feddischso
                   and state.mode( 1 downto 0 )   = VAL_MODE_LIN then
498 4 feddischso
<<<<<<< HEAD
499 3 feddischso
 
500
                     if state.x < 0 then
501
                        state.x <= - state.x;
502
                        state.y <= - state.y;
503
                     end if;
504
                     state.a <= to_signed( 0, state.a'length );
505
>>>>>>> initial commit
506 4 feddischso
=======
507
                  -- linear rotation mode
508 7 feddischso
 
509 4 feddischso
                  if state.x < 0 then
510
                     state.x <= - state.x;
511
                     state.y <= - state.y;
512
                  end if;
513
                  state.a <= to_signed( 0, state.a'length );
514
>>>>>>> Updated C and RTL model as well as the documentation
515 3 feddischso
 
516 2 feddischso
               end if;
517
 
518
 
519
 
520
 
521
 
522
            --
523
            -- rotation state
524
            --
525
            -- Each rotation takes 
526
            --           two steps: in the first step, the shifting is
527
            --                      done, in the second step, the
528
            --                      shift-result is added/subtracted
529
            -- 
530
            --
531
            --
532
            elsif state.st = ST_ROTATE then
533
 
534
               -- get the sign
535 3 feddischso
<<<<<<< HEAD
536 4 feddischso
<<<<<<< HEAD
537 2 feddischso
               if state.mode( I_FLAG_VEC_ROT )  = '0' then
538 3 feddischso
=======
539
               if state.mode( FLAG_VEC_ROT )  = '0' then
540
>>>>>>> initial commit
541 4 feddischso
=======
542
               if state.mode( I_FLAG_VEC_ROT )  = '0' then
543
>>>>>>> Updated C and RTL model as well as the documentation
544 2 feddischso
                  if state.a < 0 then
545
                     sign := '0';
546
                  else
547
                     sign := '1';
548
                  end if;
549
               else
550
                  if state.y < 0 then
551
                     sign := '1';
552
                  else
553
                     sign := '0';
554
                  end if;
555
               end if;
556
 
557
 
558
 
559
               if state.do_shift = '1' then
560 7 feddischso
                  state.do_shift <= '0';
561 2 feddischso
 
562 7 feddischso
                  -- get the angle, do the shifting and set the correct angle
563
 
564 2 feddischso
                  if sign = '1' then
565
 
566
                     -- circular case
567
                     if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
568
 
569
                        state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH), A_WIDTH_I );
570
                        state.y_sh  <= - SHIFT_RIGHT( state.y, to_integer( state.i ) );
571
 
572
                     -- hyperbolic case
573
                     elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
574
 
575
                        state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH), A_WIDTH_I );
576
                        state.y_sh  <= SHIFT_RIGHT( state.y, to_integer( state.i ) );
577
 
578
                     -- linear case
579
                     else
580
 
581
                        state.a_tmp <= resize( - angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH  ), A_WIDTH_I ) ;
582
                        state.y_sh  <= ( others => '0' );
583
 
584
                     end if;
585
                     state.x_sh <=   SHIFT_RIGHT( state.x, to_integer( state.i ) );
586
 
587
                  else
588
 
589
                     -- circular case
590
                     if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
591
 
592
                        state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
593
                        state.y_sh  <= SHIFT_RIGHT( state.y, to_integer( state.i ) );
594
 
595
                     -- hyperbolic case
596
                     elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
597
 
598
                        state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I );
599
                        state.y_sh  <= - SHIFT_RIGHT( state.y, to_integer( state.i ) );
600
 
601
                     -- linear case
602
                     else
603
 
604
                        state.a_tmp <= resize( angular_lut( to_integer( state.i ), state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) ;
605
                        state.y_sh  <= ( others => '0' );
606
 
607
                     end if;
608
                     state.x_sh <= - SHIFT_RIGHT( state.x, to_integer( state.i ) );
609
 
610
                  end if;
611
 
612
                  -- abort condition
613 3 feddischso
<<<<<<< HEAD
614 4 feddischso
<<<<<<< HEAD
615 2 feddischso
                  if(   state.mode( I_FLAG_VEC_ROT ) = '0' and
616
                        state.a = 0 ) then
617
                     state.st <= ST_RM_GAIN;
618
                     state.i  <= ( others => '0' );
619
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '0' and
620
                        state.a = state.alst ) then
621
                     state.st <= ST_RM_GAIN;
622
                     state.i  <= ( others => '0' );
623
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
624
                        state.y = 0 ) then
625
                     state.st <= ST_RM_GAIN;
626
                     state.i  <= ( others => '0' );
627
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
628 3 feddischso
=======
629
                  if(   state.mode( FLAG_VEC_ROT ) = '0' and
630
                        ( state.a = 0 or state.a = -1 ) ) then
631 4 feddischso
=======
632
                  if(   state.mode( I_FLAG_VEC_ROT ) = '0' and
633
                        state.a = 0 ) then
634
>>>>>>> Updated C and RTL model as well as the documentation
635 3 feddischso
                     state.st <= ST_RM_GAIN;
636
                     state.i  <= ( others => '0' );
637 4 feddischso
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '0' and
638
                        state.a = state.alst ) then
639 3 feddischso
                     state.st <= ST_RM_GAIN;
640
                     state.i  <= ( others => '0' );
641 4 feddischso
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
642
                        state.y = 0 ) then
643 3 feddischso
                     state.st <= ST_RM_GAIN;
644
                     state.i  <= ( others => '0' );
645 4 feddischso
<<<<<<< HEAD
646 3 feddischso
                  elsif(   state.mode( FLAG_VEC_ROT ) = '1' and
647
>>>>>>> initial commit
648 4 feddischso
=======
649
                  elsif(   state.mode( I_FLAG_VEC_ROT ) = '1' and
650
>>>>>>> Updated C and RTL model as well as the documentation
651 2 feddischso
                        ( state.y = state.ylst ) ) then
652
                     state.st <= ST_RM_GAIN;
653
                     state.i  <= ( others => '0' );
654
                  end if;
655
 
656
                  state.ylst  <= state.y;
657
                  state.alst  <= state.a;
658
 
659
 
660
               else
661
                  state.x <= state.x + state.y_sh;
662
                  state.y <= state.y + state.x_sh;
663
                  state.a <= state.a + state.a_tmp;
664
                  if VAL_MODE_HYP = state.mode( 1 downto 0 )         and
665
                     state.repeate = '0'                             and
666
                     repeat_hyperbolic_it( to_integer( state.i ) )   then
667
                     state.repeate <= '1';
668
                  else
669
                     state.repeate  <= '0';
670
                     state.i        <= state.i+1;
671
                  end if;
672
                  state.do_shift <= '1';
673
               end if;
674
 
675
 
676
 
677
 
678 7 feddischso
 
679 2 feddischso
            --
680
            -- removal of the cordic gain
681
            --
682
            elsif state.st = ST_RM_GAIN then
683
               -- we need RM_GAIN+1 cycles to 
684
               -- calculate the RM_GAIN steps
685
               if state.i = (RM_GAIN) then
686
                 state.st   <= ST_DONE;
687
                   state.i <= ( others => '0' );
688
               else
689
                   state.i  <= state.i + 1;
690
               end if;
691
 
692
               if state.mode( 1 downto 0 ) = VAL_MODE_CIR then
693
                  mult_0_61( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN );
694
                  mult_0_61( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN );
695
               elsif state.mode( 1 downto 0 ) = VAL_MODE_HYP then
696
                  mult_0_21( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN );
697
                  mult_0_21( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN );
698
               else
699
                  state.st    <= ST_DONE;
700
                  state.x_sum <= state.x;
701
                  state.y_sum <= state.y;
702
               end if;
703
 
704
 
705
            elsif state.st = ST_DONE then
706
               state.st    <= ST_IDLE;
707
            end if;
708
            -- end states
709
 
710
 
711
 
712
         end if;
713
         -- end ena
714
 
715
 
716
      end if;
717
      -- end clk
718
 
719
   end process;
720 7 feddischso
   done        <= '1' when state.st = ST_DONE else '0';
721 2 feddischso
   x_o         <= std_logic_vector( state.x_sum );
722
   y_o         <= std_logic_vector( state.y_sum );
723
   a_o         <= std_logic_vector( state.a );
724
 
725
end architecture BEHAVIORAL;
726
 
727
 
728
 

powered by: WebSVN 2.1.0

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