2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include <ao_sample_profile.h>
21 struct stm_exception {
35 struct stm_exception *ex;
37 asm("mov %0,sp" : "=&r" (ex));
40 ao_sample_profile_point(ex->pc, stm_tim11.cnt, (ex->psr & 0xff) != 0);
44 ao_sample_profile_timer_start(void)
50 /* Turn on timer 11 */
51 stm_tim11.cr1 = ((0 << STM_TIM1011_CR1_CKD) |
52 (0 << STM_TIM1011_CR1_ARPE) |
53 (1 << STM_TIM1011_CR1_URS) |
54 (0 << STM_TIM1011_CR1_UDIS) |
55 (1 << STM_TIM1011_CR1_CEN));
57 /* Turn on timer 10 */
58 stm_tim10.cr1 = ((0 << STM_TIM1011_CR1_CKD) |
59 (0 << STM_TIM1011_CR1_ARPE) |
60 (1 << STM_TIM1011_CR1_URS) |
61 (0 << STM_TIM1011_CR1_UDIS) |
62 (1 << STM_TIM1011_CR1_CEN));
67 ao_sample_profile_timer_stop(void)
73 #if AO_APB2_PRESCALER > 1
74 #define TIMER_91011_SCALER 2
76 #define TIMER_91011_SCALER 1
79 #define TIMER_10kHz ((AO_PCLK2 * TIMER_91011_SCALER) / 10000)
80 #define TIMER_1kHz ((AO_PCLK2 * TIMER_91011_SCALER) / 1000)
83 ao_sample_profile_timer_init(void)
85 /* Turn on power for timer 10 and 11 */
86 stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_TIM10EN) | (1 << STM_RCC_APB2ENR_TIM11EN);
88 /* Timer 10 is the 1kHz interrupt */
90 stm_tim10.psc = TIMER_10kHz;
94 /* Enable timer 10 update interrupt */
95 stm_tim10.dier = (1 << STM_TIM1011_DIER_UIE);
97 /* Poke timer to reload values */
98 stm_tim10.egr |= (1 << STM_TIM1011_EGR_UG);
100 /* Timer 11 is the 1kHz counter */
102 stm_tim11.psc = TIMER_1kHz;
103 stm_tim11.arr = 0xffff;
106 /* Disable interrupts for timer 11 */
109 /* Poke timer to reload values */
110 stm_tim11.egr |= (1 << STM_TIM1011_EGR_UG);
113 stm_nvic_set_enable(STM_ISR_TIM10_POS);
114 stm_nvic_set_priority(STM_ISR_TIM10_POS, AO_STM_NVIC_HIGH_PRIORITY);