tmr.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef TMR_H
00037 #define TMR_H
00038
00039 #include "utils.h"
00040
00041
00042 #define TMR_OFFSET (0x20)
00043 #define TMR_BASE (0x80007000)
00044 #define TMR0_BASE (TMR_BASE)
00045 #define TMR1_BASE (TMR_BASE + TMR_OFFSET*1)
00046 #define TMR2_BASE (TMR_BASE + TMR_OFFSET*2)
00047 #define TMR3_BASE (TMR_BASE + TMR_OFFSET*3)
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 struct TMR_struct {
00060 uint16_t COMP1;
00061 uint16_t COMP2;
00062 uint16_t CAPT;
00063 uint16_t LOAD;
00064 uint16_t HOLD;
00065 uint16_t CNTR;
00066 union {
00067 uint16_t CTRL;
00068 struct TMR_CTRL {
00069 uint16_t OUTPUT_MODE:3;
00070 uint16_t CO_INIT:1;
00071 uint16_t DIR:1;
00072 uint16_t LENGTH:1;
00073 uint16_t ONCE:1;
00074 uint16_t SECONDARY_CNT_SOURCE:2;
00075 uint16_t PRIMARY_CNT_SOURCE:4;
00076 uint16_t COUNT_MODE:3;
00077 } CTRLbits;
00078 };
00079 union {
00080 uint16_t SCTRL;
00081 struct TMR_SCTRL {
00082 uint16_t OEN:1;
00083 uint16_t OPS:1;
00084 uint16_t FORCE:1;
00085 uint16_t VAL:1;
00086 uint16_t EEOF:1;
00087 uint16_t MSTR:1;
00088 uint16_t CAPTURE_MODE:2;
00089 uint16_t INPUT:1;
00090 uint16_t IPS:1;
00091 uint16_t IEFIE:1;
00092 uint16_t IEF:1;
00093 uint16_t TOFIE:1;
00094 uint16_t TOF:1;
00095 uint16_t TCFIE:1;
00096 uint16_t TCF:1;
00097 } SCTRLbits;
00098 };
00099 uint16_t CMPLD1;
00100 uint16_t CMPLD2;
00101 union {
00102 uint16_t CSCTRL;
00103 struct TMR_CSCTRL {
00104 uint16_t CL1:2;
00105 uint16_t CL2:2;
00106 uint16_t TCF1:1;
00107 uint16_t TCF2:1;
00108 uint16_t TCF1EN:1;
00109 uint16_t TCF2EN:1;
00110 uint16_t :5;
00111 uint16_t FILT_EN:1;
00112 uint16_t DBG_EN:2;
00113 } CSCTRLbits;
00114 };
00115
00116 uint16_t reserved[4];
00117
00118 union {
00119 uint16_t ENBL;
00120 struct TMR_ENBL {
00121 union {
00122 struct {
00123 uint16_t ENBL:4;
00124 };
00125 struct {
00126 uint16_t ENBL3:1;
00127 uint16_t ENBL2:1;
00128 uint16_t ENBL1:1;
00129 uint16_t ENBL0:1;
00130 };
00131 };
00132 uint16_t :12;
00133 } ENBLbits;
00134 };
00135 };
00136
00137 static volatile struct TMR_struct * const TMR0 = (void *) (TMR0_BASE);
00138 static volatile struct TMR_struct * const TMR1 = (void *) (TMR1_BASE);
00139 static volatile struct TMR_struct * const TMR2 = (void *) (TMR2_BASE);
00140 static volatile struct TMR_struct * const TMR3 = (void *) (TMR3_BASE);
00141
00142
00143 #define TMR_ADDR(x) ((volatile struct TMR_struct *)(((uint32_t)(x) * TMR_OFFSET) + TMR_BASE))
00144
00145
00146 #define TMR_NUM(x) (((uint32_t)(x) - TMR_BASE) / TMR_OFFSET)
00147
00148
00149
00150
00151
00152 #define TMR_ENABLE_BIT(x) (1 << TMR_NUM(x))
00153
00154 #define TMR0_PIN GPIO_08
00155 #define TMR1_PIN GPIO_09
00156 #define TMR2_PIN GPIO_10
00157 #define TMR3_PIN GPIO_11
00158
00159
00160 #ifndef REG_NO_COMPAT
00161
00162 #define TMR_REGOFF_COMP1 (0x0)
00163 #define TMR_REGOFF_COMP2 (0x2)
00164 #define TMR_REGOFF_CAPT (0x4)
00165 #define TMR_REGOFF_LOAD (0x6)
00166 #define TMR_REGOFF_HOLD (0x8)
00167 #define TMR_REGOFF_CNTR (0xa)
00168 #define TMR_REGOFF_CTRL (0xc)
00169 #define TMR_REGOFF_SCTRL (0xe)
00170 #define TMR_REGOFF_CMPLD1 (0x10)
00171 #define TMR_REGOFF_CMPLD2 (0x12)
00172 #define TMR_REGOFF_CSCTRL (0x14)
00173 #define TMR_REGOFF_ENBL (0x1e)
00174
00175
00176 #define TMR_ENBL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_ENBL))
00177
00178
00179 #define TMR0_COMP1 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_COMP1))
00180 #define TMR0_COMP_UP TMR0_COMP1
00181 #define TMR0_COMP2 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_COMP2))
00182 #define TMR0_COMP_DOWN TMR0_COMP2
00183 #define TMR0_CAPT ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CAPT))
00184 #define TMR0_LOAD ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_LOAD))
00185 #define TMR0_HOLD ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_HOLD))
00186 #define TMR0_CNTR ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CNTR))
00187 #define TMR0_CTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CTRL))
00188 #define TMR0_SCTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_SCTRL))
00189 #define TMR0_CMPLD1 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CMPLD1))
00190 #define TMR0_CMPLD2 ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CMPLD2))
00191 #define TMR0_CSCTRL ((volatile uint16_t *) (TMR0_BASE + TMR_REGOFF_CSCTRL))
00192
00193
00194 #define TMR1_COMP1 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_COMP1))
00195 #define TMR1_COMP_UP TMR1_COMP1
00196 #define TMR1_COMP2 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_COMP2))
00197 #define TMR1_COMP_DOWN TMR1_COMP2
00198 #define TMR1_CAPT ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CAPT))
00199 #define TMR1_LOAD ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_LOAD))
00200 #define TMR1_HOLD ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_HOLD))
00201 #define TMR1_CNTR ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CNTR))
00202 #define TMR1_CTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CTRL))
00203 #define TMR1_SCTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_SCTRL))
00204 #define TMR1_CMPLD1 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CMPLD1))
00205 #define TMR1_CMPLD2 ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CMPLD2))
00206 #define TMR1_CSCTRL ((volatile uint16_t *) (TMR1_BASE + TMR_REGOFF_CSCTRL))
00207
00208
00209 #define TMR2_COMP1 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_COMP1))
00210 #define TMR2_COMP_UP TMR2_COMP1
00211 #define TMR2_COMP2 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_COMP2))
00212 #define TMR2_COMP_DOWN TMR2_COMP2
00213 #define TMR2_CAPT ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CAPT))
00214 #define TMR2_LOAD ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_LOAD))
00215 #define TMR2_HOLD ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_HOLD))
00216 #define TMR2_CNTR ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CNTR))
00217 #define TMR2_CTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CTRL))
00218 #define TMR2_SCTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_SCTRL))
00219 #define TMR2_CMPLD1 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CMPLD1))
00220 #define TMR2_CMPLD2 ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CMPLD2))
00221 #define TMR2_CSCTRL ((volatile uint16_t *) (TMR2_BASE + TMR_REGOFF_CSCTRL))
00222
00223
00224 #define TMR3_COMP1 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_COMP1))
00225 #define TMR3_COMP_UP TMR3_COMP1
00226 #define TMR3_COMP2 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_COMP2))
00227 #define TMR3_COMP_DOWN TMR3_COMP2
00228 #define TMR3_CAPT ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CAPT))
00229 #define TMR3_LOAD ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_LOAD))
00230 #define TMR3_HOLD ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_HOLD))
00231 #define TMR3_CNTR ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CNTR))
00232 #define TMR3_CTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CTRL))
00233 #define TMR3_SCTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_SCTRL))
00234 #define TMR3_CMPLD1 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CMPLD1))
00235 #define TMR3_CMPLD2 ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CMPLD2))
00236 #define TMR3_CSCTRL ((volatile uint16_t *) (TMR3_BASE + TMR_REGOFF_CSCTRL))
00237
00238 #define TMR(num, reg) CAT2(TMR,num,_##reg)
00239
00240 #endif
00241
00242
00243
00244
00245
00246
00247 uint32_t timer_setup_ex(int timer_num, uint32_t rate, int enable_int);
00248
00249
00250
00251
00252
00253
00254 #define timer_setup(timer,rate,enable_int) timer_setup_ex(TMR_NUM(timer), rate, enable_int)
00255
00256 #endif