1 |
221 |
olivier.gi |
#ifndef TIMERA_H
|
2 |
|
|
#define TIMERA_H
|
3 |
|
|
|
4 |
|
|
#include <in430.h>
|
5 |
|
|
|
6 |
|
|
//----------------------------------------------------------
|
7 |
|
|
// AVAILABLE FUNCTIONS
|
8 |
|
|
//----------------------------------------------------------
|
9 |
|
|
|
10 |
|
|
void ta_wait_no_lpm(unsigned int);
|
11 |
|
|
void ta_wait(unsigned int);
|
12 |
|
|
|
13 |
|
|
// Base clock period definitions (in ns)
|
14 |
|
|
//#define VERILOG_SIMULATION
|
15 |
|
|
#define DCO_CLK_PERIOD 20
|
16 |
|
|
#define LFXT_CLK_PERIOD 10240
|
17 |
|
|
|
18 |
|
|
// Time definitions (base clock of 10us period)
|
19 |
|
|
#define WT_20US ( 20000/LFXT_CLK_PERIOD)+1
|
20 |
|
|
#define WT_50US ( 50000/LFXT_CLK_PERIOD)+1
|
21 |
|
|
#ifdef VERILOG_SIMULATION
|
22 |
|
|
#define WT_100US WT_50US
|
23 |
|
|
#define WT_200US WT_50US
|
24 |
|
|
#define WT_500US WT_50US
|
25 |
|
|
#define WT_1MS WT_50US
|
26 |
|
|
#define WT_2MS WT_50US
|
27 |
|
|
#define WT_5MS WT_50US
|
28 |
|
|
#define WT_10MS WT_50US
|
29 |
|
|
#define WT_20MS WT_50US
|
30 |
|
|
#define WT_50MS WT_50US
|
31 |
|
|
#define WT_100MS WT_50US
|
32 |
|
|
#define WT_200MS WT_50US
|
33 |
|
|
#define WT_500MS WT_50US
|
34 |
|
|
#else
|
35 |
|
|
#define WT_100US ( 100000/LFXT_CLK_PERIOD)+1
|
36 |
|
|
#define WT_200US ( 200000/LFXT_CLK_PERIOD)+1
|
37 |
|
|
#define WT_500US ( 500000/LFXT_CLK_PERIOD)+1
|
38 |
|
|
#define WT_1MS ( 1000000/LFXT_CLK_PERIOD)+1
|
39 |
|
|
#define WT_2MS ( 2000000/LFXT_CLK_PERIOD)+1
|
40 |
|
|
#define WT_5MS ( 5000000/LFXT_CLK_PERIOD)+1
|
41 |
|
|
#define WT_10MS ( 10000000/LFXT_CLK_PERIOD)+1
|
42 |
|
|
#define WT_20MS ( 20000000/LFXT_CLK_PERIOD)+1
|
43 |
|
|
#define WT_50MS ( 50000000/LFXT_CLK_PERIOD)+1
|
44 |
|
|
#define WT_100MS (100000000/LFXT_CLK_PERIOD)+1
|
45 |
|
|
#define WT_200MS (200000000/LFXT_CLK_PERIOD)+1
|
46 |
|
|
#define WT_500MS (500000000/LFXT_CLK_PERIOD)+1
|
47 |
|
|
#endif
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
//----------------------------------------------------------
|
51 |
|
|
// TIMER A REGISTERS
|
52 |
|
|
//----------------------------------------------------------
|
53 |
|
|
#define TACTL (*(volatile unsigned int *) 0x0160)
|
54 |
|
|
#define TAR (*(volatile unsigned int *) 0x0170)
|
55 |
|
|
#define TACCTL0 (*(volatile unsigned int *) 0x0162)
|
56 |
|
|
#define TACCR0 (*(volatile unsigned int *) 0x0172)
|
57 |
|
|
#define TACCTL1 (*(volatile unsigned int *) 0x0164)
|
58 |
|
|
#define TACCR1 (*(volatile unsigned int *) 0x0174)
|
59 |
|
|
#define TACCTL2 (*(volatile unsigned int *) 0x0166)
|
60 |
|
|
#define TACCR2 (*(volatile unsigned int *) 0x0176)
|
61 |
|
|
#define TAIV (*(volatile unsigned int *) 0x012E)
|
62 |
|
|
|
63 |
|
|
//--------------------------------------------------
|
64 |
|
|
// TIMER A REGISTER FIELD MAPPING
|
65 |
|
|
//--------------------------------------------------
|
66 |
|
|
|
67 |
|
|
// Alternate register names
|
68 |
|
|
#define CCTL0 TACCTL0
|
69 |
|
|
#define CCTL1 TACCTL1
|
70 |
|
|
#define CCR0 TACCR0
|
71 |
|
|
#define CCR1 TACCR1
|
72 |
|
|
|
73 |
|
|
// Bit-masks
|
74 |
|
|
#define TASSEL1 (0x0200) /* Timer A clock source select 1 */
|
75 |
|
|
#define TASSEL0 (0x0100) /* Timer A clock source select 0 */
|
76 |
|
|
#define ID1 (0x0080) /* Timer A clock input divider 1 */
|
77 |
|
|
#define ID0 (0x0040) /* Timer A clock input divider 0 */
|
78 |
|
|
#define MC1 (0x0020) /* Timer A mode control 1 */
|
79 |
|
|
#define MC0 (0x0010) /* Timer A mode control 0 */
|
80 |
|
|
#define TACLR (0x0004) /* Timer A counter clear */
|
81 |
|
|
#define TAIE (0x0002) /* Timer A counter interrupt enable */
|
82 |
|
|
#define TAIFG (0x0001) /* Timer A counter interrupt flag */
|
83 |
|
|
|
84 |
|
|
#define MC_0 (0x0000) /* Timer A mode control: 0 - Stop */
|
85 |
|
|
#define MC_1 (0x0010) /* Timer A mode control: 1 - Up to CCR0 */
|
86 |
|
|
#define MC_2 (0x0020) /* Timer A mode control: 2 - Continous up */
|
87 |
|
|
#define MC_3 (0x0030) /* Timer A mode control: 3 - Up/Down */
|
88 |
|
|
#define ID_0 (0x0000) /* Timer A input divider: 0 - /1 */
|
89 |
|
|
#define ID_1 (0x0040) /* Timer A input divider: 1 - /2 */
|
90 |
|
|
#define ID_2 (0x0080) /* Timer A input divider: 2 - /4 */
|
91 |
|
|
#define ID_3 (0x00C0) /* Timer A input divider: 3 - /8 */
|
92 |
|
|
#define TASSEL_0 (0x0000) /* Timer A clock source select: 0 - TACLK */
|
93 |
|
|
#define TASSEL_1 (0x0100) /* Timer A clock source select: 1 - ACLK */
|
94 |
|
|
#define TASSEL_2 (0x0200) /* Timer A clock source select: 2 - SMCLK */
|
95 |
|
|
#define TASSEL_3 (0x0300) /* Timer A clock source select: 3 - INCLK */
|
96 |
|
|
|
97 |
|
|
#define CM1 (0x8000) /* Capture mode 1 */
|
98 |
|
|
#define CM0 (0x4000) /* Capture mode 0 */
|
99 |
|
|
#define CCIS1 (0x2000) /* Capture input select 1 */
|
100 |
|
|
#define CCIS0 (0x1000) /* Capture input select 0 */
|
101 |
|
|
#define SCS (0x0800) /* Capture sychronize */
|
102 |
|
|
#define SCCI (0x0400) /* Latched capture signal (read) */
|
103 |
|
|
#define CAP (0x0100) /* Capture mode: 1 /Compare mode : 0 */
|
104 |
|
|
#define OUTMOD2 (0x0080) /* Output mode 2 */
|
105 |
|
|
#define OUTMOD1 (0x0040) /* Output mode 1 */
|
106 |
|
|
#define OUTMOD0 (0x0020) /* Output mode 0 */
|
107 |
|
|
#define CCIE (0x0010) /* Capture/compare interrupt enable */
|
108 |
|
|
#define CCI (0x0008) /* Capture input signal (read) */
|
109 |
|
|
#define OUT (0x0004) /* PWM Output signal if output mode 0 */
|
110 |
|
|
#define COV (0x0002) /* Capture/compare overflow flag */
|
111 |
|
|
#define CCIFG (0x0001) /* Capture/compare interrupt flag */
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
#endif
|