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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_avnet_lx9microbard/] [rtl/] [verilog/] [openmsp430/] [periph/] [omsp_timerA.v] - Blame information for rev 200

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

Line No. Rev Author Line
1 157 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2009 , Olivier Girard
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions
6
// are met:
7
//     * Redistributions of source code must retain the above copyright
8
//       notice, this list of conditions and the following disclaimer.
9
//     * Redistributions in binary form must reproduce the above copyright
10
//       notice, this list of conditions and the following disclaimer in the
11
//       documentation and/or other materials provided with the distribution.
12
//     * Neither the name of the authors nor the names of its contributors
13
//       may be used to endorse or promote products derived from this software
14
//       without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE
27
//
28
//----------------------------------------------------------------------------
29
//
30
// *File Name: omsp_timerA.v
31
// 
32
// *Module Description:
33
//                       Timer A top-level
34
//
35
// *Author(s):
36
//              - Olivier Girard,    olgirard@gmail.com
37
//
38
//----------------------------------------------------------------------------
39
// $Rev: 103 $
40
// $LastChangedBy: olivier.girard $
41
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
42
//----------------------------------------------------------------------------
43
`ifdef OMSP_TA_NO_INCLUDE
44
`else
45
`include "omsp_timerA_defines.v"
46
`endif
47
 
48
module  omsp_timerA (
49
 
50
// OUTPUTs
51
    irq_ta0,                        // Timer A interrupt: TACCR0
52
    irq_ta1,                        // Timer A interrupt: TAIV, TACCR1, TACCR2
53
    per_dout,                       // Peripheral data output
54
    ta_out0,                        // Timer A output 0
55
    ta_out0_en,                     // Timer A output 0 enable
56
    ta_out1,                        // Timer A output 1
57
    ta_out1_en,                     // Timer A output 1 enable
58
    ta_out2,                        // Timer A output 2
59
    ta_out2_en,                     // Timer A output 2 enable
60
 
61
// INPUTs
62
    aclk_en,                        // ACLK enable (from CPU)
63
    dbg_freeze,                     // Freeze Timer A counter
64
    inclk,                          // INCLK external timer clock (SLOW)
65
    irq_ta0_acc,                    // Interrupt request TACCR0 accepted
66
    mclk,                           // Main system clock
67
    per_addr,                       // Peripheral address
68
    per_din,                        // Peripheral data input
69
    per_en,                         // Peripheral enable (high active)
70
    per_we,                         // Peripheral write enable (high active)
71
    puc_rst,                        // Main system reset
72
    smclk_en,                       // SMCLK enable (from CPU)
73
    ta_cci0a,                       // Timer A capture 0 input A
74
    ta_cci0b,                       // Timer A capture 0 input B
75
    ta_cci1a,                       // Timer A capture 1 input A
76
    ta_cci1b,                       // Timer A capture 1 input B
77
    ta_cci2a,                       // Timer A capture 2 input A
78
    ta_cci2b,                       // Timer A capture 2 input B
79
    taclk                           // TACLK external timer clock (SLOW)
80
);
81
 
82
// OUTPUTs
83
//=========
84
output              irq_ta0;        // Timer A interrupt: TACCR0
85
output              irq_ta1;        // Timer A interrupt: TAIV, TACCR1, TACCR2
86
output       [15:0] per_dout;       // Peripheral data output
87
output              ta_out0;        // Timer A output 0
88
output              ta_out0_en;     // Timer A output 0 enable
89
output              ta_out1;        // Timer A output 1
90
output              ta_out1_en;     // Timer A output 1 enable
91
output              ta_out2;        // Timer A output 2
92
output              ta_out2_en;     // Timer A output 2 enable
93
 
94
// INPUTs
95
//=========
96
input               aclk_en;        // ACLK enable (from CPU)
97
input               dbg_freeze;     // Freeze Timer A counter
98
input               inclk;          // INCLK external timer clock (SLOW)
99
input               irq_ta0_acc;    // Interrupt request TACCR0 accepted
100
input               mclk;           // Main system clock
101
input        [13:0] per_addr;       // Peripheral address
102
input        [15:0] per_din;        // Peripheral data input
103
input               per_en;         // Peripheral enable (high active)
104
input         [1:0] per_we;         // Peripheral write enable (high active)
105
input               puc_rst;        // Main system reset
106
input               smclk_en;       // SMCLK enable (from CPU)
107
input               ta_cci0a;       // Timer A capture 0 input A
108
input               ta_cci0b;       // Timer A capture 0 input B
109
input               ta_cci1a;       // Timer A capture 1 input A
110
input               ta_cci1b;       // Timer A capture 1 input B
111
input               ta_cci2a;       // Timer A capture 2 input A
112
input               ta_cci2b;       // Timer A capture 2 input B
113
input               taclk;          // TACLK external timer clock (SLOW)
114
 
115
 
116
//=============================================================================
117
// 1)  PARAMETER DECLARATION
118
//=============================================================================
119
 
120
// Register base address (must be aligned to decoder bit width)
121
parameter       [14:0] BASE_ADDR  = 15'h0100;
122
 
123
// Decoder bit width (defines how many bits are considered for address decoding)
124
parameter              DEC_WD     =  7;
125
 
126
// Register addresses offset
127
parameter [DEC_WD-1:0] TACTL      = 'h60,
128
                       TAR        = 'h70,
129
                       TACCTL0    = 'h62,
130
                       TACCR0     = 'h72,
131
                       TACCTL1    = 'h64,
132
                       TACCR1     = 'h74,
133
                       TACCTL2    = 'h66,
134
                       TACCR2     = 'h76,
135
                       TAIV       = 'h2E;
136
 
137
// Register one-hot decoder utilities
138
parameter              DEC_SZ     =  (1 << DEC_WD);
139
parameter [DEC_SZ-1:0] BASE_REG   =  {{DEC_SZ-1{1'b0}}, 1'b1};
140
 
141
// Register one-hot decoder
142
parameter [DEC_SZ-1:0] TACTL_D    = (BASE_REG << TACTL),
143
                       TAR_D      = (BASE_REG << TAR),
144
                       TACCTL0_D  = (BASE_REG << TACCTL0),
145
                       TACCR0_D   = (BASE_REG << TACCR0),
146
                       TACCTL1_D  = (BASE_REG << TACCTL1),
147
                       TACCR1_D   = (BASE_REG << TACCR1),
148
                       TACCTL2_D  = (BASE_REG << TACCTL2),
149
                       TACCR2_D   = (BASE_REG << TACCR2),
150
                       TAIV_D     = (BASE_REG << TAIV);
151
 
152
 
153
//============================================================================
154
// 2)  REGISTER DECODER
155
//============================================================================
156
 
157
// Local register selection
158
wire              reg_sel   =  per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
159
 
160
// Register local address
161
wire [DEC_WD-1:0] reg_addr  =  {per_addr[DEC_WD-2:0], 1'b0};
162
 
163
// Register address decode
164
wire [DEC_SZ-1:0] reg_dec   =  (TACTL_D    &  {DEC_SZ{(reg_addr == TACTL   )}})  |
165
                               (TAR_D      &  {DEC_SZ{(reg_addr == TAR     )}})  |
166
                               (TACCTL0_D  &  {DEC_SZ{(reg_addr == TACCTL0 )}})  |
167
                               (TACCR0_D   &  {DEC_SZ{(reg_addr == TACCR0  )}})  |
168
                               (TACCTL1_D  &  {DEC_SZ{(reg_addr == TACCTL1 )}})  |
169
                               (TACCR1_D   &  {DEC_SZ{(reg_addr == TACCR1  )}})  |
170
                               (TACCTL2_D  &  {DEC_SZ{(reg_addr == TACCTL2 )}})  |
171
                               (TACCR2_D   &  {DEC_SZ{(reg_addr == TACCR2  )}})  |
172
                               (TAIV_D     &  {DEC_SZ{(reg_addr == TAIV    )}});
173
 
174
// Read/Write probes
175
wire              reg_write =  |per_we & reg_sel;
176
wire              reg_read  = ~|per_we & reg_sel;
177
 
178
// Read/Write vectors
179
wire [DEC_SZ-1:0] reg_wr    = reg_dec & {512{reg_write}};
180
wire [DEC_SZ-1:0] reg_rd    = reg_dec & {512{reg_read}};
181
 
182
 
183
//============================================================================
184
// 3) REGISTERS
185
//============================================================================
186
 
187
// TACTL Register
188
//-----------------   
189
reg   [9:0] tactl;
190
 
191
wire        tactl_wr = reg_wr[TACTL];
192
wire        taclr    = tactl_wr & per_din[`TACLR];
193
wire        taifg_set;
194
wire        taifg_clr;
195
 
196
always @ (posedge mclk or posedge puc_rst)
197
  if (puc_rst)       tactl <=  10'h000;
198
  else if (tactl_wr) tactl <=  ((per_din[9:0] & 10'h3f3) | {9'h000, taifg_set}) & {9'h1ff, ~taifg_clr};
199
  else               tactl <=  (tactl                    | {9'h000, taifg_set}) & {9'h1ff, ~taifg_clr};
200
 
201
 
202
// TAR Register
203
//-----------------   
204
reg  [15:0] tar;
205
 
206
wire        tar_wr = reg_wr[TAR];
207
 
208
wire        tar_clk;
209
wire        tar_clr;
210
wire        tar_inc;
211
wire        tar_dec;
212
wire [15:0] tar_add  = tar_inc ? 16'h0001 :
213
                       tar_dec ? 16'hffff : 16'h0000;
214
wire [15:0] tar_nxt  = tar_clr ? 16'h0000 : (tar+tar_add);
215
 
216
always @ (posedge mclk or posedge puc_rst)
217
  if (puc_rst)                     tar <=  16'h0000;
218
  else if  (tar_wr)                tar <=  per_din;
219
  else if  (taclr)                 tar <=  16'h0000;
220
  else if  (tar_clk & ~dbg_freeze) tar <=  tar_nxt;
221
 
222
 
223
// TACCTL0 Register
224
//------------------   
225
reg  [15:0] tacctl0;
226
 
227
wire        tacctl0_wr = reg_wr[TACCTL0];
228
wire        ccifg0_set;
229
wire        cov0_set;
230
 
231
always @ (posedge mclk or posedge puc_rst)
232
  if (puc_rst)         tacctl0  <=  16'h0000;
233
  else if (tacctl0_wr) tacctl0  <=  ((per_din & 16'hf9f7) | {14'h0000, cov0_set, ccifg0_set}) & {15'h7fff, ~irq_ta0_acc};
234
  else                 tacctl0  <=  (tacctl0              | {14'h0000, cov0_set, ccifg0_set}) & {15'h7fff, ~irq_ta0_acc};
235
 
236
wire        cci0;
237
reg         scci0;
238
wire [15:0] tacctl0_full = tacctl0 | {5'h00, scci0, 6'h00, cci0, 3'h0};
239
 
240
 
241
// TACCR0 Register
242
//------------------   
243
reg  [15:0] taccr0;
244
 
245
wire        taccr0_wr = reg_wr[TACCR0];
246
wire        cci0_cap;
247
 
248
always @ (posedge mclk or posedge puc_rst)
249
  if (puc_rst)        taccr0 <=  16'h0000;
250
  else if (taccr0_wr) taccr0 <=  per_din;
251
  else if (cci0_cap)  taccr0 <=  tar;
252
 
253
 
254
// TACCTL1 Register
255
//------------------   
256
reg  [15:0] tacctl1;
257
 
258
wire        tacctl1_wr = reg_wr[TACCTL1];
259
wire        ccifg1_set;
260
wire        ccifg1_clr;
261
wire        cov1_set;
262
 
263
always @ (posedge mclk or posedge puc_rst)
264
  if (puc_rst)         tacctl1 <=  16'h0000;
265
  else if (tacctl1_wr) tacctl1 <=  ((per_din & 16'hf9f7) | {14'h0000, cov1_set, ccifg1_set}) & {15'h7fff, ~ccifg1_clr};
266
  else                 tacctl1 <=  (tacctl1              | {14'h0000, cov1_set, ccifg1_set}) & {15'h7fff, ~ccifg1_clr};
267
 
268
wire        cci1;
269
reg         scci1;
270
wire [15:0] tacctl1_full = tacctl1 | {5'h00, scci1, 6'h00, cci1, 3'h0};
271
 
272
 
273
// TACCR1 Register
274
//------------------   
275
reg  [15:0] taccr1;
276
 
277
wire        taccr1_wr = reg_wr[TACCR1];
278
wire        cci1_cap;
279
 
280
always @ (posedge mclk or posedge puc_rst)
281
  if (puc_rst)        taccr1 <=  16'h0000;
282
  else if (taccr1_wr) taccr1 <=  per_din;
283
  else if (cci1_cap)  taccr1 <=  tar;
284
 
285
 
286
// TACCTL2 Register
287
//------------------   
288
reg  [15:0] tacctl2;
289
 
290
wire        tacctl2_wr = reg_wr[TACCTL2];
291
wire        ccifg2_set;
292
wire        ccifg2_clr;
293
wire        cov2_set;
294
 
295
always @ (posedge mclk or posedge puc_rst)
296
  if (puc_rst)         tacctl2 <=  16'h0000;
297
  else if (tacctl2_wr) tacctl2 <=  ((per_din & 16'hf9f7) | {14'h0000, cov2_set, ccifg2_set}) & {15'h7fff, ~ccifg2_clr};
298
  else                 tacctl2 <=  (tacctl2              | {14'h0000, cov2_set, ccifg2_set}) & {15'h7fff, ~ccifg2_clr};
299
 
300
wire        cci2;
301
reg         scci2;
302
wire [15:0] tacctl2_full = tacctl2 | {5'h00, scci2, 6'h00, cci2, 3'h0};
303
 
304
 
305
// TACCR2 Register
306
//------------------   
307
reg  [15:0] taccr2;
308
 
309
wire        taccr2_wr = reg_wr[TACCR2];
310
wire        cci2_cap;
311
 
312
always @ (posedge mclk or posedge puc_rst)
313
  if (puc_rst)        taccr2 <=  16'h0000;
314
  else if (taccr2_wr) taccr2 <=  per_din;
315
  else if (cci2_cap)  taccr2 <=  tar;
316
 
317
 
318
// TAIV Register
319
//------------------   
320
 
321
wire [3:0] taiv = (tacctl1[`TACCIFG] & tacctl1[`TACCIE]) ? 4'h2 :
322
                  (tacctl2[`TACCIFG] & tacctl2[`TACCIE]) ? 4'h4 :
323
                  (tactl[`TAIFG]     & tactl[`TAIE])     ? 4'hA :
324
                                                           4'h0;
325
 
326
assign     ccifg1_clr = (reg_rd[TAIV] | reg_wr[TAIV]) & (taiv==4'h2);
327
assign     ccifg2_clr = (reg_rd[TAIV] | reg_wr[TAIV]) & (taiv==4'h4);
328
assign     taifg_clr  = (reg_rd[TAIV] | reg_wr[TAIV]) & (taiv==4'hA);
329
 
330
 
331
//============================================================================
332
// 4) DATA OUTPUT GENERATION
333
//============================================================================
334
 
335
// Data output mux
336
wire [15:0] tactl_rd   = {6'h00, tactl}  & {16{reg_rd[TACTL]}};
337
wire [15:0] tar_rd     = tar             & {16{reg_rd[TAR]}};
338
wire [15:0] tacctl0_rd = tacctl0_full    & {16{reg_rd[TACCTL0]}};
339
wire [15:0] taccr0_rd  = taccr0          & {16{reg_rd[TACCR0]}};
340
wire [15:0] tacctl1_rd = tacctl1_full    & {16{reg_rd[TACCTL1]}};
341
wire [15:0] taccr1_rd  = taccr1          & {16{reg_rd[TACCR1]}};
342
wire [15:0] tacctl2_rd = tacctl2_full    & {16{reg_rd[TACCTL2]}};
343
wire [15:0] taccr2_rd  = taccr2          & {16{reg_rd[TACCR2]}};
344
wire [15:0] taiv_rd    = {12'h000, taiv} & {16{reg_rd[TAIV]}};
345
 
346
wire [15:0] per_dout   =  tactl_rd   |
347
                          tar_rd     |
348
                          tacctl0_rd |
349
                          taccr0_rd  |
350
                          tacctl1_rd |
351
                          taccr1_rd  |
352
                          tacctl2_rd |
353
                          taccr2_rd  |
354
                          taiv_rd;
355
 
356
 
357
//============================================================================
358
// 5) Timer A counter control
359
//============================================================================
360
 
361
// Clock input synchronization (TACLK & INCLK)
362
//-----------------------------------------------------------
363
wire taclk_s;
364
wire inclk_s;
365
 
366
omsp_sync_cell sync_cell_taclk (
367
    .data_out  (taclk_s),
368
    .data_in   (taclk),
369
    .clk       (mclk),
370
    .rst       (puc_rst)
371
);
372
 
373
omsp_sync_cell sync_cell_inclk (
374
    .data_out  (inclk_s),
375
    .data_in   (inclk),
376
    .clk       (mclk),
377
    .rst       (puc_rst)
378
);
379
 
380
 
381
// Clock edge detection (TACLK & INCLK)
382
//-----------------------------------------------------------
383
 
384
reg  taclk_dly;
385
 
386
always @ (posedge mclk or posedge puc_rst)
387
  if (puc_rst) taclk_dly <=  1'b0;
388
  else         taclk_dly <=  taclk_s;
389
 
390
wire taclk_en = taclk_s & ~taclk_dly;
391
 
392
 
393
reg  inclk_dly;
394
 
395
always @ (posedge mclk or posedge puc_rst)
396
  if (puc_rst) inclk_dly <=  1'b0;
397
  else         inclk_dly <=  inclk_s;
398
 
399
wire inclk_en = inclk_s & ~inclk_dly;
400
 
401
 
402
// Timer clock input mux
403
//-----------------------------------------------------------
404
 
405
wire sel_clk = (tactl[`TASSELx]==2'b00) ? taclk_en :
406
               (tactl[`TASSELx]==2'b01) ?  aclk_en :
407
               (tactl[`TASSELx]==2'b10) ? smclk_en : inclk_en;
408
 
409
 
410
// Generate update pluse for the counter (<=> divided clock)
411
//-----------------------------------------------------------
412
reg [2:0] clk_div;
413
 
414
assign    tar_clk = sel_clk & ((tactl[`TAIDx]==2'b00) ?  1'b1         :
415
                               (tactl[`TAIDx]==2'b01) ?  clk_div[0]   :
416
                               (tactl[`TAIDx]==2'b10) ? &clk_div[1:0] :
417
                                                        &clk_div[2:0]);
418
 
419
always @ (posedge mclk or posedge puc_rst)
420
  if (puc_rst)                               clk_div <=  3'h0;
421
  else if  (tar_clk | taclr)                 clk_div <=  3'h0;
422
  else if ((tactl[`TAMCx]!=2'b00) & sel_clk) clk_div <=  clk_div+3'h1;
423
 
424
 
425
// Time counter control signals
426
//-----------------------------------------------------------
427
 
428
assign  tar_clr   = ((tactl[`TAMCx]==2'b01) & (tar>=taccr0))         |
429
                    ((tactl[`TAMCx]==2'b11) & (taccr0==16'h0000));
430
 
431
assign  tar_inc   =  (tactl[`TAMCx]==2'b01) | (tactl[`TAMCx]==2'b10) |
432
                    ((tactl[`TAMCx]==2'b11) & ~tar_dec);
433
 
434
reg tar_dir;
435
always @ (posedge mclk or posedge puc_rst)
436
  if (puc_rst)                        tar_dir <=  1'b0;
437
  else if (taclr)                     tar_dir <=  1'b0;
438
  else if (tactl[`TAMCx]==2'b11)
439
    begin
440
       if (tar_clk & (tar==16'h0001)) tar_dir <=  1'b0;
441
       else if       (tar>=taccr0)    tar_dir <=  1'b1;
442
    end
443
  else                                tar_dir <=  1'b0;
444
 
445
assign tar_dec = tar_dir | ((tactl[`TAMCx]==2'b11) & (tar>=taccr0));
446
 
447
 
448
//============================================================================
449
// 6) Timer A comparator
450
//============================================================================
451
 
452
wire equ0 = (tar_nxt==taccr0) & (tar!=taccr0);
453
wire equ1 = (tar_nxt==taccr1) & (tar!=taccr1);
454
wire equ2 = (tar_nxt==taccr2) & (tar!=taccr2);
455
 
456
 
457
//============================================================================
458
// 7) Timer A capture logic
459
//============================================================================
460
 
461
// Input selection
462
//------------------
463
assign cci0 = (tacctl0[`TACCISx]==2'b00) ? ta_cci0a :
464
              (tacctl0[`TACCISx]==2'b01) ? ta_cci0b :
465
              (tacctl0[`TACCISx]==2'b10) ?     1'b0 : 1'b1;
466
 
467
assign cci1 = (tacctl1[`TACCISx]==2'b00) ? ta_cci1a :
468
              (tacctl1[`TACCISx]==2'b01) ? ta_cci1b :
469
              (tacctl1[`TACCISx]==2'b10) ?     1'b0 : 1'b1;
470
 
471
assign cci2 = (tacctl2[`TACCISx]==2'b00) ? ta_cci2a :
472
              (tacctl2[`TACCISx]==2'b01) ? ta_cci2b :
473
              (tacctl2[`TACCISx]==2'b10) ?     1'b0 : 1'b1;
474
 
475
// CCIx synchronization
476
wire cci0_s;
477
wire cci1_s;
478
wire cci2_s;
479
 
480
omsp_sync_cell sync_cell_cci0 (
481
    .data_out (cci0_s),
482
    .data_in  (cci0),
483
    .clk      (mclk),
484
    .rst      (puc_rst)
485
);
486
omsp_sync_cell sync_cell_cci1 (
487
    .data_out (cci1_s),
488
    .data_in  (cci1),
489
    .clk      (mclk),
490
    .rst      (puc_rst)
491
);
492
omsp_sync_cell sync_cell_cci2 (
493
    .data_out (cci2_s),
494
    .data_in  (cci2),
495
    .clk      (mclk),
496
    .rst      (puc_rst)
497
);
498
 
499
// Register CCIx for edge detection
500
reg cci0_dly;
501
reg cci1_dly;
502
reg cci2_dly;
503
 
504
always @ (posedge mclk or posedge puc_rst)
505
  if (puc_rst)
506
    begin
507
       cci0_dly <=  1'b0;
508
       cci1_dly <=  1'b0;
509
       cci2_dly <=  1'b0;
510
    end
511
  else
512
    begin
513
       cci0_dly <=  cci0_s;
514
       cci1_dly <=  cci1_s;
515
       cci2_dly <=  cci2_s;
516
    end
517
 
518
 
519
// Generate SCCIx
520
//------------------
521
 
522
always @ (posedge mclk or posedge puc_rst)
523
  if (puc_rst)             scci0 <=  1'b0;
524
  else if (tar_clk & equ0) scci0 <=  cci0_s;
525
 
526
always @ (posedge mclk or posedge puc_rst)
527
  if (puc_rst)             scci1 <=  1'b0;
528
  else if (tar_clk & equ1) scci1 <=  cci1_s;
529
 
530
always @ (posedge mclk or posedge puc_rst)
531
  if (puc_rst)             scci2 <=  1'b0;
532
  else if (tar_clk & equ2) scci2 <=  cci2_s;
533
 
534
 
535
// Capture mode
536
//------------------
537
wire cci0_evt = (tacctl0[`TACMx]==2'b00) ? 1'b0                  :
538
                (tacctl0[`TACMx]==2'b01) ? ( cci0_s & ~cci0_dly) :   // Rising edge
539
                (tacctl0[`TACMx]==2'b10) ? (~cci0_s &  cci0_dly) :   // Falling edge
540
                                           ( cci0_s ^  cci0_dly);    // Both edges
541
 
542
wire cci1_evt = (tacctl1[`TACMx]==2'b00) ? 1'b0                  :
543
                (tacctl1[`TACMx]==2'b01) ? ( cci1_s & ~cci1_dly) :   // Rising edge
544
                (tacctl1[`TACMx]==2'b10) ? (~cci1_s &  cci1_dly) :   // Falling edge
545
                                           ( cci1_s ^  cci1_dly);    // Both edges
546
 
547
wire cci2_evt = (tacctl2[`TACMx]==2'b00) ? 1'b0                  :
548
                (tacctl2[`TACMx]==2'b01) ? ( cci2_s & ~cci2_dly) :   // Rising edge
549
                (tacctl2[`TACMx]==2'b10) ? (~cci2_s &  cci2_dly) :   // Falling edge
550
                                           ( cci2_s ^  cci2_dly);    // Both edges
551
 
552
// Event Synchronization
553
//-----------------------
554
 
555
reg cci0_evt_s;
556
always @ (posedge mclk or posedge puc_rst)
557
  if (puc_rst)       cci0_evt_s <=  1'b0;
558
  else if (tar_clk)  cci0_evt_s <=  1'b0;
559
  else if (cci0_evt) cci0_evt_s <=  1'b1;
560
 
561
reg cci1_evt_s;
562
always @ (posedge mclk or posedge puc_rst)
563
  if (puc_rst)       cci1_evt_s <=  1'b0;
564
  else if (tar_clk)  cci1_evt_s <=  1'b0;
565
  else if (cci1_evt) cci1_evt_s <=  1'b1;
566
 
567
reg cci2_evt_s;
568
always @ (posedge mclk or posedge puc_rst)
569
  if (puc_rst)       cci2_evt_s <=  1'b0;
570
  else if (tar_clk)  cci2_evt_s <=  1'b0;
571
  else if (cci2_evt) cci2_evt_s <=  1'b1;
572
 
573
reg cci0_sync;
574
always @ (posedge mclk or posedge puc_rst)
575
  if (puc_rst) cci0_sync <=  1'b0;
576
  else         cci0_sync <=  (tar_clk & cci0_evt_s) | (tar_clk & cci0_evt & ~cci0_evt_s);
577
 
578
reg cci1_sync;
579
always @ (posedge mclk or posedge puc_rst)
580
  if (puc_rst) cci1_sync <=  1'b0;
581
  else         cci1_sync <=  (tar_clk & cci1_evt_s) | (tar_clk & cci1_evt & ~cci1_evt_s);
582
 
583
reg cci2_sync;
584
always @ (posedge mclk or posedge puc_rst)
585
  if (puc_rst) cci2_sync <=  1'b0;
586
  else         cci2_sync <=  (tar_clk & cci2_evt_s) | (tar_clk & cci2_evt & ~cci2_evt_s);
587
 
588
 
589
// Generate final capture command
590
//-----------------------------------
591
 
592
assign cci0_cap  = tacctl0[`TASCS] ? cci0_sync : cci0_evt;
593
assign cci1_cap  = tacctl1[`TASCS] ? cci1_sync : cci1_evt;
594
assign cci2_cap  = tacctl2[`TASCS] ? cci2_sync : cci2_evt;
595
 
596
 
597
// Generate capture overflow flag
598
//-----------------------------------
599
 
600
reg  cap0_taken;
601
wire cap0_taken_clr = reg_rd[TACCR0] | (tacctl0_wr & tacctl0[`TACOV] & ~per_din[`TACOV]);
602
always @ (posedge mclk or posedge puc_rst)
603
  if (puc_rst)             cap0_taken <=  1'b0;
604
  else if (cci0_cap)       cap0_taken <=  1'b1;
605
  else if (cap0_taken_clr) cap0_taken <=  1'b0;
606
 
607
reg  cap1_taken;
608
wire cap1_taken_clr = reg_rd[TACCR1] | (tacctl1_wr & tacctl1[`TACOV] & ~per_din[`TACOV]);
609
always @ (posedge mclk or posedge puc_rst)
610
  if (puc_rst)             cap1_taken <=  1'b0;
611
  else if (cci1_cap)       cap1_taken <=  1'b1;
612
  else if (cap1_taken_clr) cap1_taken <=  1'b0;
613
 
614
reg  cap2_taken;
615
wire cap2_taken_clr = reg_rd[TACCR2] | (tacctl2_wr & tacctl2[`TACOV] & ~per_din[`TACOV]);
616
always @ (posedge mclk or posedge puc_rst)
617
  if (puc_rst)             cap2_taken <=  1'b0;
618
  else if (cci2_cap)       cap2_taken <=  1'b1;
619
  else if (cap2_taken_clr) cap2_taken <=  1'b0;
620
 
621
 
622
assign cov0_set = cap0_taken & cci0_cap & ~reg_rd[TACCR0];
623
assign cov1_set = cap1_taken & cci1_cap & ~reg_rd[TACCR1];
624
assign cov2_set = cap2_taken & cci2_cap & ~reg_rd[TACCR2];
625
 
626
 
627
//============================================================================
628
// 8) Timer A output unit
629
//============================================================================
630
 
631
// Output unit 0
632
//-------------------
633
reg  ta_out0;
634
 
635
wire ta_out0_mode0 = tacctl0[`TAOUT];                // Output
636
wire ta_out0_mode1 = equ0 ?  1'b1    : ta_out0;      // Set
637
wire ta_out0_mode2 = equ0 ? ~ta_out0 :               // Toggle/Reset
638
                     equ0 ?  1'b0    : ta_out0;
639
wire ta_out0_mode3 = equ0 ?  1'b1    :               // Set/Reset
640
                     equ0 ?  1'b0    : ta_out0;
641
wire ta_out0_mode4 = equ0 ? ~ta_out0 : ta_out0;      // Toggle
642
wire ta_out0_mode5 = equ0 ?  1'b0    : ta_out0;      // Reset
643
wire ta_out0_mode6 = equ0 ? ~ta_out0 :               // Toggle/Set
644
                     equ0 ?  1'b1    : ta_out0;
645
wire ta_out0_mode7 = equ0 ?  1'b0    :               // Reset/Set
646
                     equ0 ?  1'b1    : ta_out0;
647
 
648
wire ta_out0_nxt   = (tacctl0[`TAOUTMODx]==3'b000) ? ta_out0_mode0 :
649
                     (tacctl0[`TAOUTMODx]==3'b001) ? ta_out0_mode1 :
650
                     (tacctl0[`TAOUTMODx]==3'b010) ? ta_out0_mode2 :
651
                     (tacctl0[`TAOUTMODx]==3'b011) ? ta_out0_mode3 :
652
                     (tacctl0[`TAOUTMODx]==3'b100) ? ta_out0_mode4 :
653
                     (tacctl0[`TAOUTMODx]==3'b101) ? ta_out0_mode5 :
654
                     (tacctl0[`TAOUTMODx]==3'b110) ? ta_out0_mode6 :
655
                                                     ta_out0_mode7;
656
 
657
always @ (posedge mclk or posedge puc_rst)
658
  if (puc_rst)                                     ta_out0 <=  1'b0;
659
  else if ((tacctl0[`TAOUTMODx]==3'b001) & taclr)  ta_out0 <=  1'b0;
660
  else if (tar_clk)                                ta_out0 <=  ta_out0_nxt;
661
 
662
assign  ta_out0_en = ~tacctl0[`TACAP];
663
 
664
 
665
// Output unit 1
666
//-------------------
667
reg  ta_out1;
668
 
669
wire ta_out1_mode0 = tacctl1[`TAOUT];                // Output
670
wire ta_out1_mode1 = equ1 ?  1'b1    : ta_out1;      // Set
671
wire ta_out1_mode2 = equ1 ? ~ta_out1 :               // Toggle/Reset
672
                     equ0 ?  1'b0    : ta_out1;
673
wire ta_out1_mode3 = equ1 ?  1'b1    :               // Set/Reset
674
                     equ0 ?  1'b0    : ta_out1;
675
wire ta_out1_mode4 = equ1 ? ~ta_out1 : ta_out1;      // Toggle
676
wire ta_out1_mode5 = equ1 ?  1'b0    : ta_out1;      // Reset
677
wire ta_out1_mode6 = equ1 ? ~ta_out1 :               // Toggle/Set
678
                     equ0 ?  1'b1    : ta_out1;
679
wire ta_out1_mode7 = equ1 ?  1'b0    :               // Reset/Set
680
                     equ0 ?  1'b1    : ta_out1;
681
 
682
wire ta_out1_nxt   = (tacctl1[`TAOUTMODx]==3'b000) ? ta_out1_mode0 :
683
                     (tacctl1[`TAOUTMODx]==3'b001) ? ta_out1_mode1 :
684
                     (tacctl1[`TAOUTMODx]==3'b010) ? ta_out1_mode2 :
685
                     (tacctl1[`TAOUTMODx]==3'b011) ? ta_out1_mode3 :
686
                     (tacctl1[`TAOUTMODx]==3'b100) ? ta_out1_mode4 :
687
                     (tacctl1[`TAOUTMODx]==3'b101) ? ta_out1_mode5 :
688
                     (tacctl1[`TAOUTMODx]==3'b110) ? ta_out1_mode6 :
689
                                                     ta_out1_mode7;
690
 
691
always @ (posedge mclk or posedge puc_rst)
692
  if (puc_rst)                                     ta_out1 <=  1'b0;
693
  else if ((tacctl1[`TAOUTMODx]==3'b001) & taclr)  ta_out1 <=  1'b0;
694
  else if (tar_clk)                                ta_out1 <=  ta_out1_nxt;
695
 
696
assign  ta_out1_en = ~tacctl1[`TACAP];
697
 
698
 
699
// Output unit 2
700
//-------------------
701
reg  ta_out2;
702
 
703
wire ta_out2_mode0 = tacctl2[`TAOUT];                // Output
704
wire ta_out2_mode1 = equ2 ?  1'b1    : ta_out2;      // Set
705
wire ta_out2_mode2 = equ2 ? ~ta_out2 :               // Toggle/Reset
706
                     equ0 ?  1'b0    : ta_out2;
707
wire ta_out2_mode3 = equ2 ?  1'b1    :               // Set/Reset
708
                     equ0 ?  1'b0    : ta_out2;
709
wire ta_out2_mode4 = equ2 ? ~ta_out2 : ta_out2;      // Toggle
710
wire ta_out2_mode5 = equ2 ?  1'b0    : ta_out2;      // Reset
711
wire ta_out2_mode6 = equ2 ? ~ta_out2 :               // Toggle/Set
712
                     equ0 ?  1'b1    : ta_out2;
713
wire ta_out2_mode7 = equ2 ?  1'b0    :               // Reset/Set
714
                     equ0 ?  1'b1    : ta_out2;
715
 
716
wire ta_out2_nxt   = (tacctl2[`TAOUTMODx]==3'b000) ? ta_out2_mode0 :
717
                     (tacctl2[`TAOUTMODx]==3'b001) ? ta_out2_mode1 :
718
                     (tacctl2[`TAOUTMODx]==3'b010) ? ta_out2_mode2 :
719
                     (tacctl2[`TAOUTMODx]==3'b011) ? ta_out2_mode3 :
720
                     (tacctl2[`TAOUTMODx]==3'b100) ? ta_out2_mode4 :
721
                     (tacctl2[`TAOUTMODx]==3'b101) ? ta_out2_mode5 :
722
                     (tacctl2[`TAOUTMODx]==3'b110) ? ta_out2_mode6 :
723
                                                     ta_out2_mode7;
724
 
725
always @ (posedge mclk or posedge puc_rst)
726
  if (puc_rst)                                     ta_out2 <=  1'b0;
727
  else if ((tacctl2[`TAOUTMODx]==3'b001) & taclr)  ta_out2 <=  1'b0;
728
  else if (tar_clk)                                ta_out2 <=  ta_out2_nxt;
729
 
730
assign  ta_out2_en = ~tacctl2[`TACAP];
731
 
732
 
733
//============================================================================
734
// 9) Timer A interrupt generation
735
//============================================================================
736
 
737
 
738
assign   taifg_set   = tar_clk & (((tactl[`TAMCx]==2'b01) & (tar==taccr0))                  |
739
                                  ((tactl[`TAMCx]==2'b10) & (tar==16'hffff))                |
740
                                  ((tactl[`TAMCx]==2'b11) & (tar_nxt==16'h0000) & tar_dec));
741
 
742
assign   ccifg0_set  = tacctl0[`TACAP] ? cci0_cap : (tar_clk &  ((tactl[`TAMCx]!=2'b00) & equ0));
743
assign   ccifg1_set  = tacctl1[`TACAP] ? cci1_cap : (tar_clk &  ((tactl[`TAMCx]!=2'b00) & equ1));
744
assign   ccifg2_set  = tacctl2[`TACAP] ? cci2_cap : (tar_clk &  ((tactl[`TAMCx]!=2'b00) & equ2));
745
 
746
 
747
wire     irq_ta0    = (tacctl0[`TACCIFG] & tacctl0[`TACCIE]);
748
 
749
wire     irq_ta1    = (tactl[`TAIFG]     & tactl[`TAIE])     |
750
                      (tacctl1[`TACCIFG] & tacctl1[`TACCIE]) |
751
                      (tacctl2[`TACCIFG] & tacctl2[`TACCIE]);
752
 
753
 
754
endmodule // omsp_timerA
755
 
756
`ifdef OMSP_TA_NO_INCLUDE
757
`else
758
`include "omsp_timerA_undefines.v"
759
`endif

powered by: WebSVN 2.1.0

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