|
30 | 30 | #include "compiler_hints.h"
|
31 | 31 | #include "cpu.h"
|
32 | 32 | #include "periph/timer.h"
|
33 |
| -#include "periph_conf.h" |
34 |
| -#include "periph_cpu.h" |
35 | 33 |
|
36 | 34 | /**
|
37 | 35 | * @brief Interrupt context for each configured timer
|
@@ -114,8 +112,8 @@ int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
|
114 | 112 | for (unsigned i = 0; i < timer_query_channel_numof(dev); i++) {
|
115 | 113 | msptimer->CCTL[i] = 0;
|
116 | 114 | }
|
117 |
| - /* start the timer in continuous mode */ |
118 |
| - msptimer->CTL = ctl | TXMC_CONT; |
| 115 | + |
| 116 | + timer_start(dev); |
119 | 117 | return 0;
|
120 | 118 | }
|
121 | 119 |
|
@@ -157,14 +155,39 @@ void timer_start(tim_t dev)
|
157 | 155 | {
|
158 | 156 | assume((unsigned)dev < TIMER_NUMOF);
|
159 | 157 | msp430_timer_t *msptimer = timer_conf[dev].timer;
|
| 158 | + /* acquire clock */ |
| 159 | + switch (timer_conf[dev].clock_source) { |
| 160 | + case TIMER_CLOCK_SOURCE_SUBMAIN_CLOCK: |
| 161 | + msp430_clock_acquire(MSP430_CLOCK_SUBMAIN); |
| 162 | + break; |
| 163 | + case TIMER_CLOCK_SOURCE_AUXILIARY_CLOCK: |
| 164 | + msp430_clock_acquire(MSP430_CLOCK_AUXILIARY); |
| 165 | + break; |
| 166 | + default: |
| 167 | + /* external clock source, safe to disable internal clocks */ |
| 168 | + break; |
| 169 | + } |
160 | 170 | msptimer->CTL |= TXMC_CONT;
|
161 | 171 | }
|
162 | 172 |
|
163 | 173 | void timer_stop(tim_t dev)
|
164 | 174 | {
|
165 | 175 | assume((unsigned)dev < TIMER_NUMOF);
|
166 | 176 | msp430_timer_t *msptimer = timer_conf[dev].timer;
|
167 |
| - msptimer->CTL &= ~(TXMC_MASK); |
| 177 | + msptimer->CTL &= ~(TXMC_CONT); |
| 178 | + |
| 179 | + /* release clock */ |
| 180 | + switch (timer_conf[dev].clock_source) { |
| 181 | + case TIMER_CLOCK_SOURCE_SUBMAIN_CLOCK: |
| 182 | + msp430_clock_release(MSP430_CLOCK_SUBMAIN); |
| 183 | + break; |
| 184 | + case TIMER_CLOCK_SOURCE_AUXILIARY_CLOCK: |
| 185 | + msp430_clock_release(MSP430_CLOCK_AUXILIARY); |
| 186 | + break; |
| 187 | + default: |
| 188 | + /* external clock source, nothing to release */ |
| 189 | + break; |
| 190 | + } |
168 | 191 | }
|
169 | 192 |
|
170 | 193 | __attribute__((pure))
|
|
0 commit comments