File: timer.vbe

package info (click to toggle)
alliance 5.0-20120515-6
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 70,324 kB
  • ctags: 39,977
  • sloc: ansic: 350,299; vhdl: 34,227; yacc: 27,122; sh: 12,416; cpp: 9,478; makefile: 7,057; lex: 3,684
file content (320 lines) | stat: -rw-r--r-- 12,061 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
-- ### -------------------------------------------------------------- ###
-- #									#
-- # file	: timer.vbe						#
-- # date	: Jul 21 1995						#
-- # version	: v0.1							#
-- #									#
-- # origin	: this description has been developed by CAO-VLSI team	#
-- #		  at MASI laboratory, University Pierre et Marie Curie	#
-- #		  4 Place Jussieu 75252 Paris Cedex 05 - France		#
-- #									#
-- # descr.	: data flow description of a programable timer.		#
-- #		- 7 compteurs 32 bits (6 int. et le reset)		#
-- #		- un registre status					#
-- #		  Fonctionnement: On met le nombre de cycles dans le	#
-- #		  compteur associe, puis on passe le status a 1.	#
-- #              Mis a part le reset qui reste actif seulement un 	#
-- #              cycle, les autre lignes restent a l'etat bas tant	#
-- #              que leur statut est a 1.				#
-- ### -------------------------------------------------------------- ###

entity TIMER is

  port (
    CK      : in    bit                         ;	-- external clock
    FRZ     : in    bit                         ;	-- freeze
    RESET_I : in    bit                         ;	-- reset input
    SEL     : in    bit_vector ( 2 downto 0)    ;	-- register selection
    DATA    : inout mux_vector (31 downto 0) bus;	-- data
    RW      : in    bit                         ;	-- access mode
    E_N     : in    bit                         ;	-- chip enable
    RESET_O : out   bit                         ;	-- reset output (= TIMER_RESET OR RESET_I)
    IRQ_N   : out   bit_vector(5 downto 0)	;       -- interrupt request
    VDD     : in    bit                         ;	--
    VSS     : in    bit                         	--
    );

end;

architecture FUNCTIONAL of TIMER is

  signal NOT_CK   : bit					;

  signal CLK_SX   : bit                                 ;
  -- Status Register
  signal status_r : reg_vector( 6 downto 0) register 	;
  signal status_wen : bit				;
  -- Int Register 0 to 6
  signal reg_0    : reg_vector(31 downto 0) register 	;
  signal reg_1    : reg_vector(31 downto 0) register 	;
  signal reg_2    : reg_vector(31 downto 0) register 	;
  signal reg_3    : reg_vector(31 downto 0) register 	;
  signal reg_4    : reg_vector(31 downto 0) register 	;
  signal reg_5    : reg_vector(31 downto 0) register 	;

  -- Write enable pour reg_0 a reg_5
  signal reg0_wen : bit					;
  signal reg1_wen : bit					;
  signal reg2_wen : bit					;
  signal reg3_wen : bit					;
  signal reg4_wen : bit					;
  signal reg5_wen : bit					;

  -- Decrementation des registres
  signal dec_0    : bit_vector( 31 downto 0)		;
  signal dec_1    : bit_vector( 31 downto 0)		;
  signal dec_2    : bit_vector( 31 downto 0)		;
  signal dec_3    : bit_vector( 31 downto 0)		;
  signal dec_4    : bit_vector( 31 downto 0)		;
  signal dec_5    : bit_vector( 31 downto 0)		;
  signal cry_0    : bit_vector( 32 downto 0)		;
  signal cry_1    : bit_vector( 32 downto 0)		;
  signal cry_2    : bit_vector( 32 downto 0)		;
  signal cry_3    : bit_vector( 32 downto 0)		;
  signal cry_4    : bit_vector( 32 downto 0)		;
  signal cry_5    : bit_vector( 32 downto 0)		;

  signal reset_dec: bit_vector( 31 downto 0)		;
  signal reset_cry: bit_vector( 32 downto 0)		;

  -- Reset register
  signal reset_r  : reg_vector(31 downto 0) register 	;
  signal reset_wen: bit					;
  signal reset    : bit					;

  -- IRQ : Pour visualiser dans le res.pat !!!
  signal IRQ	  : bit_vector(5 downto 0)		;

  signal reg0_in    : bit_vector( 31 downto 0)		;
  signal reg1_in    : bit_vector( 31 downto 0)		;
  signal reg2_in    : bit_vector( 31 downto 0)		;
  signal reg3_in    : bit_vector( 31 downto 0)		;
  signal reg4_in    : bit_vector( 31 downto 0)		;
  signal reg5_in    : bit_vector( 31 downto 0)		;
  signal reg_reset_in    : bit_vector( 31 downto 0)		;
begin

  NOT_CK     <= NOT(CK) ;

  CLK_SX     <= NOT_CK and not FRZ;

  reg0_wen   <= '1' when ((sel(2 downto 0)) = B"000" and (E_N = '0') and (rw = '0') and (status_r(0) = '0')) 
                else '0' ;
  reg1_wen   <= '1' when ((sel(2 downto 0)) = B"001" and (E_N = '0') and (rw = '0') and (status_r(1) = '0')) 
                else '0' ;
  reg2_wen   <= '1' when ((sel(2 downto 0)) = B"010" and (E_N = '0') and (rw = '0') and (status_r(2) = '0')) 
                else '0' ;
  reg3_wen   <= '1' when ((sel(2 downto 0)) = B"011" and (E_N = '0') and (rw = '0') and (status_r(3) = '0')) 
                else '0' ;
  reg4_wen   <= '1' when ((sel(2 downto 0)) = B"100" and (E_N = '0') and (rw = '0') and (status_r(4) = '0')) 
                else '0' ;
  reg5_wen   <= '1' when ((sel(2 downto 0)) = B"101" and (E_N = '0') and (rw = '0') and (status_r(5) = '0')) 
                else '0' ;
  reset_wen  <= '1' when ((sel(2 downto 0)) = B"110" and (E_N = '0') and (rw = '0') and (status_r(6) = '0')) 
                else '0' ;

  status_wen <= '1' when ((sel(2 downto 0)) = B"111" and (E_N = '0') and (rw = '0')) else '0' ;
  
  dec_0 (31 downto 0) <= not reg_0 xor cry_0 (31 downto 0);
  cry_0 (32 downto 1) <=     reg_0 or  cry_0 (31 downto 0);
  cry_0 (0)           <= '0';

  assert (not(reg0_wen))
  report  "====   writing data to reg_0  ===="
  severity WARNING;
     
  with (((status_r(0) = '1') and not(reg_0 = X"00000000")) & reg0_wen & reset) select
      reg0_in <= dec_0 when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reg_0 when others;
 
  count0 : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reg_0 <= guarded reg0_in;
  end block ;
   
  --count00 : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(0) = '1' and not(reg_0 = X"00000000"))
  --begin
  --  reg_0 <= guarded dec_0 ;
  --end block;
  --count01 : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reg0_wen = '1'))
  --begin
  --  reg_0 <= guarded data;
  --end block ;

  dec_1 (31 downto 0) <= not reg_1 xor cry_1 (31 downto 0);
  cry_1 (32 downto 1) <=     reg_1 or  cry_1 (31 downto 0);
  cry_1 (0)           <= '0';
     
  with (((status_r(1) = '1') and not(reg_1 = X"00000000")) & reg1_wen & reset) select
      reg1_in <= dec_1 when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reg_1 when others;
 
  count1 : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reg_1 <= guarded reg1_in;
  end block ;


  --count10 : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(1) = '1' and not(reg_1 = X"00000000"))
  --begin
  --  reg_1 <= guarded dec_1 ;
  --end block;
  --count11 : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reg1_wen = '1'))
  --begin
  --  reg_1 <= guarded data;
  --end block ;

  dec_2 (31 downto 0) <= not reg_2 xor cry_2 (31 downto 0);
  cry_2 (32 downto 1) <=     reg_2 or  cry_2 (31 downto 0);
  cry_2 (0)           <= '0';
     
  with (((status_r(2) = '1') and not(reg_2 = X"00000000")) & reg2_wen & reset) select
      reg2_in <= dec_2 when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reg_2 when others;
 
  count2 : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reg_2 <= guarded reg2_in;
  end block ;

  --count20 : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(2) = '1' and not(reg_2 = X"00000000"))
  --begin
  --  reg_2 <= guarded dec_2 ;
  --end block;
  --count21 : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reg2_wen = '1'))
  --begin
  --  reg_2 <= guarded data;
  --end block ;

  dec_3 (31 downto 0) <= not reg_3 xor cry_3 (31 downto 0);
  cry_3 (32 downto 1) <=     reg_3 or  cry_3 (31 downto 0);
  cry_3 (0)           <= '0';
     
  with (((status_r(3) = '1') and not(reg_3 = X"00000000")) & reg3_wen & reset) select
      reg3_in <= dec_3 when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reg_3 when others;
 
  count3 : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reg_3 <= guarded reg3_in;
  end block ;

  --count30 : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(3) = '1' and not(reg_3 = X"00000000"))
  --begin
  --  reg_3 <= guarded dec_3 ;
  --end block;
  --count31 : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reg3_wen = '1'))
  --begin
  --  reg_3 <= guarded data;
  --end block ;

  dec_4 (31 downto 0) <= not reg_4 xor cry_4 (31 downto 0);
  cry_4 (32 downto 1) <=     reg_4 or  cry_4 (31 downto 0);
  cry_4 (0)           <= '0';
     
  with (((status_r(4) = '1') and not(reg_4 = X"00000000")) & reg4_wen & reset) select
      reg4_in <= dec_4 when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reg_4 when others;
 
  count4 : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reg_4 <= guarded reg4_in;
  end block ;

  --count40 : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(4) = '1' and not(reg_4 = X"00000000"))
  --begin
  --  reg_4 <= guarded dec_4 ;
  --end block;
  --count41 : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reg4_wen = '1'))
  --begin
  --  reg_4 <= guarded data;
  --end block ;

  dec_5 (31 downto 0) <= not reg_5 xor cry_5 (31 downto 0);
  cry_5 (32 downto 1) <=     reg_5 or  cry_5 (31 downto 0);
  cry_5 (0)           <= '0';
     
  with (((status_r(5) = '1') and not(reg_5 = X"00000000")) & reg5_wen & reset) select
      reg5_in <= dec_5 when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reg_5 when others;
 
  count5 : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reg_5 <= guarded reg5_in;
  end block ;

  --count50 : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(5) = '1' and not(reg_5 = X"00000000"))
  --begin
  --  reg_5 <= guarded dec_5 ;
  --end block;
  --count51 : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reg5_wen = '1'))
  --begin
  --  reg_5 <= guarded data;
  --end block ;

  reset_dec (31 downto 0) <= not reset_r xor reset_cry (31 downto 0);
  reset_cry (32 downto 1) <=     reset_r or  reset_cry (31 downto 0);
  reset_cry (0)           <= '0';

  with ((status_r(6) = '1') & reset_wen & reset) select
      reg_reset_in <= reset_dec when B"100",
                  data when B"010",
                  X"00000000" when B"001" | B"011" | B"101" | B"111",
                  reset_r when others;
 
  reset_dec : block  (CLK_SX = '0' and not CLK_SX'STABLE)
  begin
    reset_r <= guarded reg_reset_in;
  end block ;

  --reset_dec : block (CLK_SX = '0' and not CLK_SX'STABLE and status_r(6) = '1')
  --begin
  --  reset_r <= guarded reset_dec ;
  --end block;
  --reset_wri : block  (CLK_SX = '0' and not CLK_SX'STABLE and (reset_wen = '1'))
  --begin
  --  reset_r <= guarded data;
  --end block ;

  -- reset du timer....
  reset <= RESET_I or ((reset_r = X"0000_0000") and (status_r(6) = '1')) ;
  --status_reset : block (CLK_SX = '0' and not CLK_SX'STABLE and status_wen and reset)
  status_reset : block (CLK_SX = '0' and not CLK_SX'STABLE and reset)
  begin
    status_r <= guarded B"0000000" ;
  end block ;

  -- Ecriture du status
  status_write : block (CLK_SX = '0' and not CLK_SX'STABLE and status_wen and not reset)
  begin
    status_r <= guarded data(6 downto 0) ;
  end block ;

  -- Affectation des sorties
  status_read : block ((sel(2 downto 0)) = B"111" and (E_N = '0') and (rw = '1'))
  begin
      data <= guarded (B"0000_0000_0000_0000_0000_0000_0" & status_r) ;
  end block ;
  
  IRQ(0) <= '0' when ((reg_0 = X"0000_0000") and (status_r(0) = '1')) else '1' ;
  IRQ(1) <= '0' when ((reg_1 = X"0000_0000") and (status_r(1) = '1')) else '1' ;
  IRQ(2) <= '0' when ((reg_2 = X"0000_0000") and (status_r(2) = '1')) else '1' ;
  IRQ(3) <= '0' when ((reg_3 = X"0000_0000") and (status_r(3) = '1')) else '1' ;
  IRQ(4) <= '0' when ((reg_4 = X"0000_0000") and (status_r(4) = '1')) else '1' ;
  IRQ(5) <= '0' when ((reg_5 = X"0000_0000") and (status_r(5) = '1')) else '1' ;

  IRQ_N    <= IRQ ;
  RESET_O  <= reset ;
end;