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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 #include <ao_sample_profile.h>
22 struct stm_exception {
36 struct stm_exception *ex;
38 asm("mov %0,sp" : "=&r" (ex));
41 ao_sample_profile_point(ex->pc, stm_tim11.cnt, (ex->psr & 0xff) != 0);
45 ao_sample_profile_timer_start(void)
51 /* Turn on timer 11 */
52 stm_tim11.cr1 = ((0 << STM_TIM1011_CR1_CKD) |
53 (0 << STM_TIM1011_CR1_ARPE) |
54 (1 << STM_TIM1011_CR1_URS) |
55 (0 << STM_TIM1011_CR1_UDIS) |
56 (1 << STM_TIM1011_CR1_CEN));
58 /* Turn on timer 10 */
59 stm_tim10.cr1 = ((0 << STM_TIM1011_CR1_CKD) |
60 (0 << STM_TIM1011_CR1_ARPE) |
61 (1 << STM_TIM1011_CR1_URS) |
62 (0 << STM_TIM1011_CR1_UDIS) |
63 (1 << STM_TIM1011_CR1_CEN));
68 ao_sample_profile_timer_stop(void)
74 #if AO_APB2_PRESCALER > 1
75 #define TIMER_91011_SCALER 2
77 #define TIMER_91011_SCALER 1
80 #define TIMER_10kHz ((AO_PCLK2 * TIMER_91011_SCALER) / 10000)
81 #define TIMER_1kHz ((AO_PCLK2 * TIMER_91011_SCALER) / 1000)
84 ao_sample_profile_timer_init(void)
86 /* Turn on power for timer 10 and 11 */
87 stm_rcc.apb2enr |= (1 << STM_RCC_APB2ENR_TIM10EN) | (1 << STM_RCC_APB2ENR_TIM11EN);
89 /* Timer 10 is the 1kHz interrupt */
91 stm_tim10.psc = TIMER_10kHz;
95 /* Enable timer 10 update interrupt */
96 stm_tim10.dier = (1 << STM_TIM1011_DIER_UIE);
98 /* Poke timer to reload values */
99 stm_tim10.egr |= (1 << STM_TIM1011_EGR_UG);
101 /* Timer 11 is the 1kHz counter */
103 stm_tim11.psc = TIMER_1kHz;
104 stm_tim11.arr = 0xffff;
107 /* Disable interrupts for timer 11 */
110 /* Poke timer to reload values */
111 stm_tim11.egr |= (1 << STM_TIM1011_EGR_UG);
114 stm_nvic_set_enable(STM_ISR_TIM10_POS);
115 stm_nvic_set_priority(STM_ISR_TIM10_POS, AO_STM_NVIC_HIGH_PRIORITY);