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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [rtl/] [verilog/] [periph/] [omsp_timerA.v] - Blame information for rev 103

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25 34 olivier.gi
// *File Name: omsp_timerA.v
26 2 olivier.gi
// 
27
// *Module Description:
28
//                       Timer A top-level
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 103 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
37
//----------------------------------------------------------------------------
38 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
39
`else
40 23 olivier.gi
`include "openMSP430_defines.v"
41 103 olivier.gi
`endif
42 2 olivier.gi
 
43 34 olivier.gi
module  omsp_timerA (
44 2 olivier.gi
 
45
// OUTPUTs
46
    irq_ta0,                        // Timer A interrupt: TACCR0
47
    irq_ta1,                        // Timer A interrupt: TAIV, TACCR1, TACCR2
48
    per_dout,                       // Peripheral data output
49
    ta_out0,                        // Timer A output 0
50
    ta_out0_en,                     // Timer A output 0 enable
51
    ta_out1,                        // Timer A output 1
52
    ta_out1_en,                     // Timer A output 1 enable
53
    ta_out2,                        // Timer A output 2
54
    ta_out2_en,                     // Timer A output 2 enable
55
 
56
// INPUTs
57
    aclk_en,                        // ACLK enable (from CPU)
58
    dbg_freeze,                     // Freeze Timer A counter
59
    inclk,                          // INCLK external timer clock (SLOW)
60
    irq_ta0_acc,                    // Interrupt request TACCR0 accepted
61
    mclk,                           // Main system clock
62
    per_addr,                       // Peripheral address
63
    per_din,                        // Peripheral data input
64
    per_en,                         // Peripheral enable (high active)
65
    per_wen,                        // Peripheral write enable (high active)
66
    puc,                            // Main system reset
67
    smclk_en,                       // SMCLK enable (from CPU)
68
    ta_cci0a,                       // Timer A capture 0 input A
69
    ta_cci0b,                       // Timer A capture 0 input B
70
    ta_cci1a,                       // Timer A capture 1 input A
71
    ta_cci1b,                       // Timer A capture 1 input B
72
    ta_cci2a,                       // Timer A capture 2 input A
73
    ta_cci2b,                       // Timer A capture 2 input B
74
    taclk                           // TACLK external timer clock (SLOW)
75
);
76
 
77
// OUTPUTs
78
//=========
79
output              irq_ta0;        // Timer A interrupt: TACCR0
80
output              irq_ta1;        // Timer A interrupt: TAIV, TACCR1, TACCR2
81
output       [15:0] per_dout;       // Peripheral data output
82
output              ta_out0;        // Timer A output 0
83
output              ta_out0_en;     // Timer A output 0 enable
84
output              ta_out1;        // Timer A output 1
85
output              ta_out1_en;     // Timer A output 1 enable
86
output              ta_out2;        // Timer A output 2
87
output              ta_out2_en;     // Timer A output 2 enable
88
 
89
// INPUTs
90
//=========
91
input               aclk_en;        // ACLK enable (from CPU)
92
input               dbg_freeze;     // Freeze Timer A counter
93
input               inclk;          // INCLK external timer clock (SLOW)
94
input               irq_ta0_acc;    // Interrupt request TACCR0 accepted
95
input               mclk;           // Main system clock
96
input         [7:0] per_addr;       // Peripheral address
97
input        [15:0] per_din;        // Peripheral data input
98
input               per_en;         // Peripheral enable (high active)
99
input         [1:0] per_wen;        // Peripheral write enable (high active)
100
input               puc;            // Main system reset
101
input               smclk_en;       // SMCLK enable (from CPU)
102
input               ta_cci0a;       // Timer A capture 0 input A
103
input               ta_cci0b;       // Timer A capture 0 input B
104
input               ta_cci1a;       // Timer A capture 1 input A
105
input               ta_cci1b;       // Timer A capture 1 input B
106
input               ta_cci2a;       // Timer A capture 2 input A
107
input               ta_cci2b;       // Timer A capture 2 input B
108
input               taclk;          // TACLK external timer clock (SLOW)
109
 
110
 
111
//=============================================================================
112
// 1)  PARAMETER DECLARATION
113
//=============================================================================
114
 
115
// Register addresses
116
parameter           TACTL      = 9'h160;
117
parameter           TAR        = 9'h170;
118
parameter           TACCTL0    = 9'h162;
119
parameter           TACCR0     = 9'h172;
120
parameter           TACCTL1    = 9'h164;
121
parameter           TACCR1     = 9'h174;
122
parameter           TACCTL2    = 9'h166;
123
parameter           TACCR2     = 9'h176;
124
parameter           TAIV       = 9'h12E;
125
 
126
 
127
// Register one-hot decoder
128
parameter           TACTL_D    = (512'h1 << TACTL);
129
parameter           TAR_D      = (512'h1 << TAR);
130
parameter           TACCTL0_D  = (512'h1 << TACCTL0);
131
parameter           TACCR0_D   = (512'h1 << TACCR0);
132
parameter           TACCTL1_D  = (512'h1 << TACCTL1);
133
parameter           TACCR1_D   = (512'h1 << TACCR1);
134
parameter           TACCTL2_D  = (512'h1 << TACCTL2);
135
parameter           TACCR2_D   = (512'h1 << TACCR2);
136
parameter           TAIV_D     = (512'h1 << TAIV);
137
 
138
 
139
//============================================================================
140
// 2)  REGISTER DECODER
141
//============================================================================
142
 
143
// Register address decode
144
reg  [511:0]  reg_dec;
145
always @(per_addr)
146
  case ({per_addr,1'b0})
147
    TACTL  :     reg_dec  =  TACTL_D;
148
    TAR    :     reg_dec  =  TAR_D;
149
    TACCTL0:     reg_dec  =  TACCTL0_D;
150
    TACCR0 :     reg_dec  =  TACCR0_D;
151
    TACCTL1:     reg_dec  =  TACCTL1_D;
152
    TACCR1 :     reg_dec  =  TACCR1_D;
153
    TACCTL2:     reg_dec  =  TACCTL2_D;
154
    TACCR2 :     reg_dec  =  TACCR2_D;
155
    TAIV   :     reg_dec  =  TAIV_D;
156
    default:     reg_dec  =  {512{1'b0}};
157
  endcase
158
 
159
// Read/Write probes
160
wire         reg_write =  |per_wen   & per_en;
161
wire         reg_read  = ~|per_wen   & per_en;
162
 
163
// Read/Write vectors
164
wire [511:0] reg_wr    = reg_dec & {512{reg_write}};
165
wire [511:0] reg_rd    = reg_dec & {512{reg_read}};
166
 
167
 
168
//============================================================================
169
// 3) REGISTERS
170
//============================================================================
171
 
172
// TACTL Register
173
//-----------------   
174
reg   [9:0] tactl;
175
 
176
wire        tactl_wr = reg_wr[TACTL];
177
wire        taclr    = tactl_wr & per_din[`TACLR];
178
wire        taifg_set;
179
wire        taifg_clr;
180
 
181
always @ (posedge mclk or posedge puc)
182
  if (puc)           tactl <=  10'h000;
183
  else if (tactl_wr) tactl <=  ((per_din[9:0] & 10'h3f3) | {9'h000, taifg_set}) & {9'h1ff, ~taifg_clr};
184
  else               tactl <=  (tactl                    | {9'h000, taifg_set}) & {9'h1ff, ~taifg_clr};
185
 
186
 
187
// TAR Register
188
//-----------------   
189
reg  [15:0] tar;
190
 
191
wire        tar_wr = reg_wr[TAR];
192
 
193
wire        tar_clk;
194
wire        tar_clr;
195
wire        tar_inc;
196
wire        tar_dec;
197
wire [15:0] tar_add  = tar_inc ? 16'h0001 :
198
                       tar_dec ? 16'hffff : 16'h0000;
199
wire [15:0] tar_nxt  = tar_clr ? 16'h0000 : (tar+tar_add);
200
 
201
always @ (posedge mclk or posedge puc)
202
  if (puc)                         tar <=  16'h0000;
203
  else if  (tar_wr)                tar <=  per_din;
204
  else if  (taclr)                 tar <=  16'h0000;
205
  else if  (tar_clk & ~dbg_freeze) tar <=  tar_nxt;
206
 
207
 
208
// TACCTL0 Register
209
//------------------   
210
reg  [15:0] tacctl0;
211
 
212
wire        tacctl0_wr = reg_wr[TACCTL0];
213
wire        ccifg0_set;
214
wire        cov0_set;
215
 
216
always @ (posedge mclk or posedge puc)
217
  if (puc)             tacctl0  <=  16'h0000;
218
  else if (tacctl0_wr) tacctl0  <=  ((per_din & 16'hf9f7) | {14'h0000, cov0_set, ccifg0_set}) & {15'h7fff, ~irq_ta0_acc};
219
  else                 tacctl0  <=  (tacctl0              | {14'h0000, cov0_set, ccifg0_set}) & {15'h7fff, ~irq_ta0_acc};
220
 
221
wire        cci0;
222
reg         scci0;
223
wire [15:0] tacctl0_full = tacctl0 | {5'h00, scci0, 6'h00, cci0, 3'h0};
224
 
225
 
226
// TACCR0 Register
227
//------------------   
228
reg  [15:0] taccr0;
229
 
230
wire        taccr0_wr = reg_wr[TACCR0];
231
wire        cci0_cap;
232
 
233
always @ (posedge mclk or posedge puc)
234
  if (puc)            taccr0 <=  16'h0000;
235
  else if (taccr0_wr) taccr0 <=  per_din;
236
  else if (cci0_cap)  taccr0 <=  tar;
237
 
238
 
239
// TACCTL1 Register
240
//------------------   
241
reg  [15:0] tacctl1;
242
 
243
wire        tacctl1_wr = reg_wr[TACCTL1];
244
wire        ccifg1_set;
245
wire        ccifg1_clr;
246
wire        cov1_set;
247
 
248
always @ (posedge mclk or posedge puc)
249
  if (puc)             tacctl1 <=  16'h0000;
250
  else if (tacctl1_wr) tacctl1 <=  ((per_din & 16'hf9f7) | {14'h0000, cov1_set, ccifg1_set}) & {15'h7fff, ~ccifg1_clr};
251
  else                 tacctl1 <=  (tacctl1              | {14'h0000, cov1_set, ccifg1_set}) & {15'h7fff, ~ccifg1_clr};
252
 
253
wire        cci1;
254
reg         scci1;
255
wire [15:0] tacctl1_full = tacctl1 | {5'h00, scci1, 6'h00, cci1, 3'h0};
256
 
257
 
258
// TACCR1 Register
259
//------------------   
260
reg  [15:0] taccr1;
261
 
262
wire        taccr1_wr = reg_wr[TACCR1];
263
wire        cci1_cap;
264
 
265
always @ (posedge mclk or posedge puc)
266
  if (puc)            taccr1 <=  16'h0000;
267
  else if (taccr1_wr) taccr1 <=  per_din;
268
  else if (cci1_cap)  taccr1 <=  tar;
269
 
270
 
271
// TACCTL2 Register
272
//------------------   
273
reg  [15:0] tacctl2;
274
 
275
wire        tacctl2_wr = reg_wr[TACCTL2];
276
wire        ccifg2_set;
277
wire        ccifg2_clr;
278
wire        cov2_set;
279
 
280
always @ (posedge mclk or posedge puc)
281
  if (puc)             tacctl2 <=  16'h0000;
282
  else if (tacctl2_wr) tacctl2 <=  ((per_din & 16'hf9f7) | {14'h0000, cov2_set, ccifg2_set}) & {15'h7fff, ~ccifg2_clr};
283
  else                 tacctl2 <=  (tacctl2              | {14'h0000, cov2_set, ccifg2_set}) & {15'h7fff, ~ccifg2_clr};
284
 
285
wire        cci2;
286
reg         scci2;
287
wire [15:0] tacctl2_full = tacctl2 | {5'h00, scci2, 6'h00, cci2, 3'h0};
288
 
289
 
290
// TACCR2 Register
291
//------------------   
292
reg  [15:0] taccr2;
293
 
294
wire        taccr2_wr = reg_wr[TACCR2];
295
wire        cci2_cap;
296
 
297
always @ (posedge mclk or posedge puc)
298
  if (puc)            taccr2 <=  16'h0000;
299
  else if (taccr2_wr) taccr2 <=  per_din;
300
  else if (cci2_cap)  taccr2 <=  tar;
301
 
302
 
303
// TAIV Register
304
//------------------   
305
 
306
wire [3:0] taiv = (tacctl1[`TACCIFG] & tacctl1[`TACCIE]) ? 4'h2 :
307
                  (tacctl2[`TACCIFG] & tacctl2[`TACCIE]) ? 4'h4 :
308
                  (tactl[`TAIFG]     & tactl[`TAIE])     ? 4'hA :
309
                                                           4'h0;
310
 
311
assign     ccifg1_clr = (reg_rd[TAIV] | reg_wr[TAIV]) & (taiv==4'h2);
312
assign     ccifg2_clr = (reg_rd[TAIV] | reg_wr[TAIV]) & (taiv==4'h4);
313
assign     taifg_clr  = (reg_rd[TAIV] | reg_wr[TAIV]) & (taiv==4'hA);
314
 
315
 
316
//============================================================================
317
// 4) DATA OUTPUT GENERATION
318
//============================================================================
319
 
320
// Data output mux
321
wire [15:0] tactl_rd   = {6'h00, tactl}  & {16{reg_rd[TACTL]}};
322
wire [15:0] tar_rd     = tar             & {16{reg_rd[TAR]}};
323
wire [15:0] tacctl0_rd = tacctl0_full    & {16{reg_rd[TACCTL0]}};
324
wire [15:0] taccr0_rd  = taccr0          & {16{reg_rd[TACCR0]}};
325
wire [15:0] tacctl1_rd = tacctl1_full    & {16{reg_rd[TACCTL1]}};
326
wire [15:0] taccr1_rd  = taccr1          & {16{reg_rd[TACCR1]}};
327
wire [15:0] tacctl2_rd = tacctl2_full    & {16{reg_rd[TACCTL2]}};
328
wire [15:0] taccr2_rd  = taccr2          & {16{reg_rd[TACCR2]}};
329
wire [15:0] taiv_rd    = {12'h000, taiv} & {16{reg_rd[TAIV]}};
330
 
331
wire [15:0] per_dout   =  tactl_rd   |
332
                          tar_rd     |
333
                          tacctl0_rd |
334
                          taccr0_rd  |
335
                          tacctl1_rd |
336
                          taccr1_rd  |
337
                          tacctl2_rd |
338
                          taccr2_rd  |
339
                          taiv_rd;
340
 
341
 
342
//============================================================================
343
// 5) Timer A counter control
344
//============================================================================
345
 
346
// Clock input synchronization (TACLK & INCLK)
347
//-----------------------------------------------------------
348
reg  [2:0] taclk_s;
349
 
350
always @ (posedge mclk or posedge puc)
351
  if (puc) taclk_s <=  3'b000;
352
  else     taclk_s <=  {taclk_s[1:0], taclk};
353
 
354
wire taclk_en = taclk_s[1] & ~taclk_s[2];
355
 
356
 
357
reg  [2:0] inclk_s;
358
 
359
always @ (posedge mclk or posedge puc)
360
  if (puc) inclk_s <=  3'b000;
361
  else     inclk_s <=  {inclk_s[1:0], inclk};
362
 
363
wire inclk_en = inclk_s[1] & ~inclk_s[2];
364
 
365
 
366
// Timer clock input mux
367
//-----------------------------------------------------------
368
 
369
wire sel_clk = (tactl[`TASSELx]==2'b00) ? taclk_en :
370
               (tactl[`TASSELx]==2'b01) ?  aclk_en :
371
               (tactl[`TASSELx]==2'b10) ? smclk_en : inclk_en;
372
 
373
 
374
// Generate update pluse for the counter (<=> divided clock)
375
//-----------------------------------------------------------
376
reg [2:0] clk_div;
377
 
378
assign    tar_clk = sel_clk & ((tactl[`TAIDx]==2'b00) ?  1'b1         :
379
                               (tactl[`TAIDx]==2'b01) ?  clk_div[0]   :
380
                               (tactl[`TAIDx]==2'b10) ? &clk_div[1:0] :
381
                                                        &clk_div[2:0]);
382
 
383
always @ (posedge mclk or posedge puc)
384
  if (puc)                                   clk_div <=  3'h0;
385
  else if  (tar_clk | taclr)                 clk_div <=  3'h0;
386
  else if ((tactl[`TAMCx]!=2'b00) & sel_clk) clk_div <=  clk_div+3'h1;
387
 
388
 
389
// Time counter control signals
390
//-----------------------------------------------------------
391
 
392
assign  tar_clr   = ((tactl[`TAMCx]==2'b01) & (tar>=taccr0))         |
393
                    ((tactl[`TAMCx]==2'b11) & (taccr0==16'h0000));
394
 
395
assign  tar_inc   =  (tactl[`TAMCx]==2'b01) | (tactl[`TAMCx]==2'b10) |
396
                    ((tactl[`TAMCx]==2'b11) & ~tar_dec);
397
 
398
reg tar_dir;
399
always @ (posedge mclk or posedge puc)
400
  if (puc)                            tar_dir <=  1'b0;
401
  else if (taclr)                     tar_dir <=  1'b0;
402
  else if (tactl[`TAMCx]==2'b11)
403
    begin
404
       if (tar_clk & (tar==16'h0001)) tar_dir <=  1'b0;
405
       else if       (tar>=taccr0)    tar_dir <=  1'b1;
406
    end
407
  else                                tar_dir <=  1'b0;
408
 
409
assign tar_dec = tar_dir | ((tactl[`TAMCx]==2'b11) & (tar>=taccr0));
410
 
411
 
412
//============================================================================
413
// 6) Timer A comparator
414
//============================================================================
415
 
416
wire equ0 = (tar_nxt==taccr0) & (tar!=taccr0);
417
wire equ1 = (tar_nxt==taccr1) & (tar!=taccr1);
418
wire equ2 = (tar_nxt==taccr2) & (tar!=taccr2);
419
 
420
 
421
//============================================================================
422
// 7) Timer A capture logic
423
//============================================================================
424
 
425
// Input selection
426
//------------------
427
assign cci0 = (tacctl0[`TACCISx]==2'b00) ? ta_cci0a :
428
              (tacctl0[`TACCISx]==2'b01) ? ta_cci0b :
429
              (tacctl0[`TACCISx]==2'b10) ?     1'b0 : 1'b1;
430
 
431
assign cci1 = (tacctl1[`TACCISx]==2'b00) ? ta_cci1a :
432
              (tacctl1[`TACCISx]==2'b01) ? ta_cci1b :
433
              (tacctl1[`TACCISx]==2'b10) ?     1'b0 : 1'b1;
434
 
435
assign cci2 = (tacctl2[`TACCISx]==2'b00) ? ta_cci2a :
436
              (tacctl2[`TACCISx]==2'b01) ? ta_cci2b :
437
              (tacctl2[`TACCISx]==2'b10) ?     1'b0 : 1'b1;
438
 
439
// Register CCIx for synchronization and edge detection
440
reg [2:0] cci_s;
441
always @ (posedge mclk or posedge puc)
442
  if (puc) cci_s <=  3'h0;
443
  else     cci_s <=  {cci2, cci1, cci0};
444
reg [2:0] cci_ss;
445
always @ (posedge mclk or posedge puc)
446
  if (puc) cci_ss <=  3'h0;
447
  else     cci_ss <=  cci_s;
448
reg [2:0] cci_sss;
449
always @ (posedge mclk or posedge puc)
450
  if (puc) cci_sss <=  3'h0;
451
  else     cci_sss <=  cci_ss;
452
 
453
 
454
// Generate SCCIx
455
//------------------
456
 
457
always @ (posedge mclk or posedge puc)
458
  if (puc)                 scci0 <=  1'b0;
459
  else if (tar_clk & equ0) scci0 <=  cci_ss[0];
460
 
461
always @ (posedge mclk or posedge puc)
462
  if (puc)                 scci1 <=  1'b0;
463
  else if (tar_clk & equ1) scci1 <=  cci_ss[1];
464
 
465
always @ (posedge mclk or posedge puc)
466
  if (puc)                 scci2 <=  1'b0;
467
  else if (tar_clk & equ2) scci2 <=  cci_ss[2];
468
 
469
 
470
// Capture mode
471
//------------------
472
wire cci0_evt = (tacctl0[`TACMx]==2'b00) ? 1'b0                  :
473
                (tacctl0[`TACMx]==2'b01) ? ( cci_ss[0] & ~cci_sss[0]) :   // Rising edge
474
                (tacctl0[`TACMx]==2'b10) ? (~cci_ss[0] &  cci_sss[0]) :   // Falling edge
475
                                           ( cci_ss[0] ^  cci_sss[0]);    // Both edges
476
 
477
wire cci1_evt = (tacctl1[`TACMx]==2'b00) ? 1'b0                  :
478
                (tacctl1[`TACMx]==2'b01) ? ( cci_ss[1] & ~cci_sss[1]) :   // Rising edge
479
                (tacctl1[`TACMx]==2'b10) ? (~cci_ss[1] &  cci_sss[1]) :   // Falling edge
480
                                           ( cci_ss[1] ^  cci_sss[1]);    // Both edges
481
 
482
wire cci2_evt = (tacctl2[`TACMx]==2'b00) ? 1'b0                  :
483
                (tacctl2[`TACMx]==2'b01) ? ( cci_ss[2] & ~cci_sss[2]) :   // Rising edge
484
                (tacctl2[`TACMx]==2'b10) ? (~cci_ss[2] &  cci_sss[2]) :   // Falling edge
485
                                           ( cci_ss[2] ^  cci_sss[2]);    // Both edges
486
 
487
// Event Synchronization
488
//-----------------------
489
 
490
reg cci0_evt_s;
491
always @ (posedge mclk or posedge puc)
492
  if (puc)           cci0_evt_s <=  1'b0;
493
  else if (tar_clk)  cci0_evt_s <=  1'b0;
494
  else if (cci0_evt) cci0_evt_s <=  1'b1;
495
 
496
reg cci1_evt_s;
497
always @ (posedge mclk or posedge puc)
498
  if (puc)           cci1_evt_s <=  1'b0;
499
  else if (tar_clk)  cci1_evt_s <=  1'b0;
500
  else if (cci1_evt) cci1_evt_s <=  1'b1;
501
 
502
reg cci2_evt_s;
503
always @ (posedge mclk or posedge puc)
504
  if (puc)           cci2_evt_s <=  1'b0;
505
  else if (tar_clk)  cci2_evt_s <=  1'b0;
506
  else if (cci2_evt) cci2_evt_s <=  1'b1;
507
 
508
reg cci0_sync;
509
always @ (posedge mclk or posedge puc)
510
  if (puc) cci0_sync <=  1'b0;
511
  else     cci0_sync <=  (tar_clk & cci0_evt_s) | (tar_clk & cci0_evt & ~cci0_evt_s);
512
 
513
reg cci1_sync;
514
always @ (posedge mclk or posedge puc)
515
  if (puc) cci1_sync <=  1'b0;
516
  else     cci1_sync <=  (tar_clk & cci1_evt_s) | (tar_clk & cci1_evt & ~cci1_evt_s);
517
 
518
reg cci2_sync;
519
always @ (posedge mclk or posedge puc)
520
  if (puc) cci2_sync <=  1'b0;
521
  else     cci2_sync <=  (tar_clk & cci2_evt_s) | (tar_clk & cci2_evt & ~cci2_evt_s);
522
 
523
 
524
// Generate final capture command
525
//-----------------------------------
526
 
527
assign cci0_cap  = tacctl0[`TASCS] ? cci0_sync : cci0_evt;
528
assign cci1_cap  = tacctl1[`TASCS] ? cci1_sync : cci1_evt;
529
assign cci2_cap  = tacctl2[`TASCS] ? cci2_sync : cci2_evt;
530
 
531
 
532
// Generate capture overflow flag
533
//-----------------------------------
534
 
535
reg  cap0_taken;
536
wire cap0_taken_clr = reg_rd[TACCR0] | (tacctl0_wr & tacctl0[`TACOV] & ~per_din[`TACOV]);
537
always @ (posedge mclk or posedge puc)
538
  if (puc)                 cap0_taken <=  1'b0;
539
  else if (cci0_cap)       cap0_taken <=  1'b1;
540
  else if (cap0_taken_clr) cap0_taken <=  1'b0;
541
 
542
reg  cap1_taken;
543
wire cap1_taken_clr = reg_rd[TACCR1] | (tacctl1_wr & tacctl1[`TACOV] & ~per_din[`TACOV]);
544
always @ (posedge mclk or posedge puc)
545
  if (puc)                 cap1_taken <=  1'b0;
546
  else if (cci1_cap)       cap1_taken <=  1'b1;
547
  else if (cap1_taken_clr) cap1_taken <=  1'b0;
548
 
549
reg  cap2_taken;
550
wire cap2_taken_clr = reg_rd[TACCR2] | (tacctl2_wr & tacctl2[`TACOV] & ~per_din[`TACOV]);
551
always @ (posedge mclk or posedge puc)
552
  if (puc)                 cap2_taken <=  1'b0;
553
  else if (cci2_cap)       cap2_taken <=  1'b1;
554
  else if (cap2_taken_clr) cap2_taken <=  1'b0;
555
 
556
 
557
assign cov0_set = cap0_taken & cci0_cap & ~reg_rd[TACCR0];
558
assign cov1_set = cap1_taken & cci1_cap & ~reg_rd[TACCR1];
559
assign cov2_set = cap2_taken & cci2_cap & ~reg_rd[TACCR2];
560
 
561
 
562
//============================================================================
563
// 8) Timer A output unit
564
//============================================================================
565
 
566
// Output unit 0
567
//-------------------
568
reg  ta_out0;
569
 
570
wire ta_out0_mode0 = tacctl0[`TAOUT];                // Output
571
wire ta_out0_mode1 = equ0 ?  1'b1    : ta_out0;      // Set
572
wire ta_out0_mode2 = equ0 ? ~ta_out0 :               // Toggle/Reset
573
                     equ0 ?  1'b0    : ta_out0;
574
wire ta_out0_mode3 = equ0 ?  1'b1    :               // Set/Reset
575
                     equ0 ?  1'b0    : ta_out0;
576
wire ta_out0_mode4 = equ0 ? ~ta_out0 : ta_out0;      // Toggle
577
wire ta_out0_mode5 = equ0 ?  1'b0    : ta_out0;      // Reset
578
wire ta_out0_mode6 = equ0 ? ~ta_out0 :               // Toggle/Set
579
                     equ0 ?  1'b1    : ta_out0;
580
wire ta_out0_mode7 = equ0 ?  1'b0    :               // Reset/Set
581
                     equ0 ?  1'b1    : ta_out0;
582
 
583
wire ta_out0_nxt   = (tacctl0[`TAOUTMODx]==3'b000) ? ta_out0_mode0 :
584
                     (tacctl0[`TAOUTMODx]==3'b001) ? ta_out0_mode1 :
585
                     (tacctl0[`TAOUTMODx]==3'b010) ? ta_out0_mode2 :
586
                     (tacctl0[`TAOUTMODx]==3'b011) ? ta_out0_mode3 :
587
                     (tacctl0[`TAOUTMODx]==3'b100) ? ta_out0_mode4 :
588
                     (tacctl0[`TAOUTMODx]==3'b101) ? ta_out0_mode5 :
589
                     (tacctl0[`TAOUTMODx]==3'b110) ? ta_out0_mode6 :
590
                                                     ta_out0_mode7;
591
 
592
always @ (posedge mclk or posedge puc)
593
  if (puc)                                         ta_out0 <=  1'b0;
594
  else if ((tacctl0[`TAOUTMODx]==3'b001) & taclr)  ta_out0 <=  1'b0;
595
  else if (tar_clk)                                ta_out0 <=  ta_out0_nxt;
596
 
597
assign  ta_out0_en = ~tacctl0[`TACAP];
598
 
599
 
600
// Output unit 1
601
//-------------------
602
reg  ta_out1;
603
 
604
wire ta_out1_mode0 = tacctl1[`TAOUT];                // Output
605
wire ta_out1_mode1 = equ1 ?  1'b1    : ta_out1;      // Set
606
wire ta_out1_mode2 = equ1 ? ~ta_out1 :               // Toggle/Reset
607
                     equ0 ?  1'b0    : ta_out1;
608
wire ta_out1_mode3 = equ1 ?  1'b1    :               // Set/Reset
609
                     equ0 ?  1'b0    : ta_out1;
610
wire ta_out1_mode4 = equ1 ? ~ta_out1 : ta_out1;      // Toggle
611
wire ta_out1_mode5 = equ1 ?  1'b0    : ta_out1;      // Reset
612
wire ta_out1_mode6 = equ1 ? ~ta_out1 :               // Toggle/Set
613
                     equ0 ?  1'b1    : ta_out1;
614
wire ta_out1_mode7 = equ1 ?  1'b0    :               // Reset/Set
615
                     equ0 ?  1'b1    : ta_out1;
616
 
617
wire ta_out1_nxt   = (tacctl1[`TAOUTMODx]==3'b000) ? ta_out1_mode0 :
618
                     (tacctl1[`TAOUTMODx]==3'b001) ? ta_out1_mode1 :
619
                     (tacctl1[`TAOUTMODx]==3'b010) ? ta_out1_mode2 :
620
                     (tacctl1[`TAOUTMODx]==3'b011) ? ta_out1_mode3 :
621
                     (tacctl1[`TAOUTMODx]==3'b100) ? ta_out1_mode4 :
622
                     (tacctl1[`TAOUTMODx]==3'b101) ? ta_out1_mode5 :
623
                     (tacctl1[`TAOUTMODx]==3'b110) ? ta_out1_mode6 :
624
                                                     ta_out1_mode7;
625
 
626
always @ (posedge mclk or posedge puc)
627
  if (puc)                                         ta_out1 <=  1'b0;
628
  else if ((tacctl1[`TAOUTMODx]==3'b001) & taclr)  ta_out1 <=  1'b0;
629
  else if (tar_clk)                                ta_out1 <=  ta_out1_nxt;
630
 
631
assign  ta_out1_en = ~tacctl1[`TACAP];
632
 
633
 
634
// Output unit 2
635
//-------------------
636
reg  ta_out2;
637
 
638
wire ta_out2_mode0 = tacctl2[`TAOUT];                // Output
639
wire ta_out2_mode1 = equ2 ?  1'b1    : ta_out2;      // Set
640
wire ta_out2_mode2 = equ2 ? ~ta_out2 :               // Toggle/Reset
641
                     equ0 ?  1'b0    : ta_out2;
642
wire ta_out2_mode3 = equ2 ?  1'b1    :               // Set/Reset
643
                     equ0 ?  1'b0    : ta_out2;
644
wire ta_out2_mode4 = equ2 ? ~ta_out2 : ta_out2;      // Toggle
645
wire ta_out2_mode5 = equ2 ?  1'b0    : ta_out2;      // Reset
646
wire ta_out2_mode6 = equ2 ? ~ta_out2 :               // Toggle/Set
647
                     equ0 ?  1'b1    : ta_out2;
648
wire ta_out2_mode7 = equ2 ?  1'b0    :               // Reset/Set
649
                     equ0 ?  1'b1    : ta_out2;
650
 
651
wire ta_out2_nxt   = (tacctl2[`TAOUTMODx]==3'b000) ? ta_out2_mode0 :
652
                     (tacctl2[`TAOUTMODx]==3'b001) ? ta_out2_mode1 :
653
                     (tacctl2[`TAOUTMODx]==3'b010) ? ta_out2_mode2 :
654
                     (tacctl2[`TAOUTMODx]==3'b011) ? ta_out2_mode3 :
655
                     (tacctl2[`TAOUTMODx]==3'b100) ? ta_out2_mode4 :
656
                     (tacctl2[`TAOUTMODx]==3'b101) ? ta_out2_mode5 :
657
                     (tacctl2[`TAOUTMODx]==3'b110) ? ta_out2_mode6 :
658
                                                     ta_out2_mode7;
659
 
660
always @ (posedge mclk or posedge puc)
661
  if (puc)                                         ta_out2 <=  1'b0;
662
  else if ((tacctl2[`TAOUTMODx]==3'b001) & taclr)  ta_out2 <=  1'b0;
663
  else if (tar_clk)                                ta_out2 <=  ta_out2_nxt;
664
 
665
assign  ta_out2_en = ~tacctl2[`TACAP];
666
 
667
 
668
//============================================================================
669
// 9) Timer A interrupt generation
670
//============================================================================
671
 
672
 
673
assign   taifg_set   = tar_clk & (((tactl[`TAMCx]==2'b01) & (tar==taccr0))                  |
674
                                  ((tactl[`TAMCx]==2'b10) & (tar==16'hffff))                |
675
                                  ((tactl[`TAMCx]==2'b11) & (tar_nxt==16'h0000) & tar_dec));
676
 
677
assign   ccifg0_set  = tacctl0[`TACAP] ? cci0_cap : (tar_clk &  ((tactl[`TAMCx]!=2'b00) & equ0));
678
assign   ccifg1_set  = tacctl1[`TACAP] ? cci1_cap : (tar_clk &  ((tactl[`TAMCx]!=2'b00) & equ1));
679
assign   ccifg2_set  = tacctl2[`TACAP] ? cci2_cap : (tar_clk &  ((tactl[`TAMCx]!=2'b00) & equ2));
680
 
681
 
682
wire     irq_ta0    = (tacctl0[`TACCIFG] & tacctl0[`TACCIE]);
683
 
684
wire     irq_ta1    = (tactl[`TAIFG]     & tactl[`TAIE])     |
685
                      (tacctl1[`TACCIFG] & tacctl1[`TACCIE]) |
686
                      (tacctl2[`TACCIFG] & tacctl2[`TACCIE]);
687
 
688
 
689 34 olivier.gi
endmodule // omsp_timerA
690 2 olivier.gi
 
691 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
692
`else
693 33 olivier.gi
`include "openMSP430_undefines.v"
694 103 olivier.gi
`endif

powered by: WebSVN 2.1.0

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