Subversion Repositories chibiosIgnition

Rev

Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 3
Line 6... Line 6...
6
 */
6
 */
7
#include "ch.h"
7
#include "ch.h"
8
#include "hal.h"
8
#include "hal.h"
9
#include "hardware.h"
9
#include "hardware.h"
10
 
10
 
-
 
11
uint16_t timerSamples[timerSampleSize];
-
 
12
 
-
 
13
uint8_t timerInIndex;
-
 
14
uint8_t timerOutIndex;
-
 
15
 
-
 
16
 
-
 
17
 
11
void TIM1_UP_IRQHandler(void) {
18
void TIM1_UP_IRQHandler(void) {
12
// we have an interrupt here .
19
// we have an interrupt here .
-
 
20
        if (TIM1->SR & TIM_SR_CC1IF) {
-
 
21
                TIM1->SR &= ~TIM_SR_CC1IF;
-
 
22
                timerSamples[timerInIndex++] = TIM1->CCMR1;
-
 
23
                if (timerInIndex == timerSampleSize) {
-
 
24
                        timerInIndex = 0;
-
 
25
                }
13
 
26
 
14
 
27
        }
15
 
28
 
16
}
29
}
17
 
30
 
18
void initTimer(void) {
31
void initTimer(void) {
19
        rccEnableTIM1(FALSE);
32
        rccEnableTIM1(FALSE);
Line 22... Line 35...
22
                        CORTEX_PRIORITY_MASK(STM32_GPT_TIM1_IRQ_PRIORITY));
35
                        CORTEX_PRIORITY_MASK(STM32_GPT_TIM1_IRQ_PRIORITY));
23
        //gptp->clock = STM32_TIMCLK2;
36
        //gptp->clock = STM32_TIMCLK2;
24
 
37
 
25
        TIM1->CR1 = 0; /* Initially stopped.           */
38
        TIM1->CR1 = 0; /* Initially stopped.           */
26
        TIM1->CR2 = TIM_CR2_CCDS; /* DMA on UE (if any).          */
39
        TIM1->CR2 = TIM_CR2_CCDS; /* DMA on UE (if any).          */
27
        TIM1->PSC = 72; /* Prescaler value.             */
40
        TIM1->PSC = 72 * 3; /* Prescaler value : 3 uS tick timer .             */
28
        TIM1->DIER = 0;
41
        TIM1->DIER = 0;
29
 
42
 
30
}
43
}
31
 
44
 
32
void stopTimer(void) {
45
void stopTimer(void) {
33
        nvicDisableVector(TIM1_UP_IRQn);
46
        nvicDisableVector(TIM1_UP_IRQn);
34
        rccDisableTIM1(FALSE);
47
        rccDisableTIM1(FALSE);
35
}
48
}
36
 
49
 
37
void startTimer(void) {
50
void startTimer(void) {
38
          TIM1->ARR  = 12405;           /* Time constant.               */
51
          TIM1->ARR  = 0xFFFF;                 /* Time constant.               */
39
          TIM1->EGR  = TIM_EGR_UG;             /* Update event.                */
52
          TIM1->EGR  = TIM_EGR_UG;             /* Update event.                */
40
          TIM1->CNT  = 0;                      /* Reset counter.               */
53
          TIM1->CNT  = 0;                      /* Reset counter.               */
41
          /* NOTE: After generating the UG event it takes several clock cycles before
54
          /* NOTE: After generating the UG event it takes several clock cycles before
42
             SR bit 0 goes to 1. This is because the clearing of CNT has been inserted
55
             SR bit 0 goes to 1. This is because the clearing of CNT has been inserted
43
             before the clearing of SR, to give it some time.*/
56
             before the clearing of SR, to give it some time.*/
44
          TIM1->SR   = 0;                      /* Clear pending IRQs (if any). */
57
          TIM1->SR   = 0;                      /* Clear pending IRQs (if any). */
45
          TIM1->DIER = TIM_DIER_UIE;           /* Update Event IRQ enabled.    */
58
          TIM1->DIER = TIM_DIER_UIE;           /* Update Event IRQ enabled.    */
46
          TIM1->CR1  = TIM_CR1_URS | TIM_CR1_CEN;
59
          TIM1->CR1  = TIM_CR1_URS | TIM_CR1_CEN;
-
 
60
 
-
 
61
          TIM1->CCMR1 = 3344;
47
}
62
}