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_profile.h>
21 static void ao_profile_test(void)
26 for (i = 0; i < 20; i++) {
27 ticks[i] = ao_profile_tick();
30 for (i = 0; i < 19; i++)
31 printf ("%d\n", ticks[i+1] - ticks[i]);
34 static const struct ao_cmds ao_profile_cmds[] = {
35 { ao_profile_test, "P\0Test profile counter" },
39 void ao_profile_init(void)
41 /* Turn on timer 2 and 4 */
42 stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM2EN) |
43 (1 << STM_RCC_APB1ENR_TIM4EN);
52 stm_tim4.cr2 = ((0 << STM_TIM234_CR2_TI1S) |
53 (STM_TIM234_CR2_MMS_UPDATE << STM_TIM234_CR2_MMS) |
54 (0 << STM_TIM234_CR2_CCDS));
56 stm_tim4.smcr = ((0 << STM_TIM234_SMCR_ETP) |
57 (0 << STM_TIM234_SMCR_ECE) |
58 (STM_TIM234_SMCR_ETPS_OFF << STM_TIM234_SMCR_ETPS) |
59 (STM_TIM234_SMCR_ETF_NONE << STM_TIM234_SMCR_ETF) |
60 (0 << STM_TIM234_SMCR_MSM) |
61 (STM_TIM234_SMCR_TS_ITR3 << STM_TIM234_SMCR_TS) |
62 (0 << STM_TIM234_SMCR_OCCS) |
63 (STM_TIM234_SMCR_SMS_DISABLE << STM_TIM234_SMCR_SMS));
70 stm_tim4.arr = 0xffff;
72 /* tim2 is slaved to tim4 */
74 stm_tim2.cr2 = ((0 << STM_TIM234_CR2_TI1S) |
75 (STM_TIM234_CR2_MMS_ENABLE << STM_TIM234_CR2_MMS) |
76 (0 << STM_TIM234_CR2_CCDS));
77 stm_tim2.smcr = ((0 << STM_TIM234_SMCR_ETP) |
78 (0 << STM_TIM234_SMCR_ECE) |
79 (STM_TIM234_SMCR_ETPS_OFF << STM_TIM234_SMCR_ETPS) |
80 (STM_TIM234_SMCR_ETF_NONE << STM_TIM234_SMCR_ETF) |
81 (0 << STM_TIM234_SMCR_MSM) |
82 (STM_TIM234_SMCR_TS_ITR3 << STM_TIM234_SMCR_TS) |
83 (0 << STM_TIM234_SMCR_OCCS) |
84 (STM_TIM234_SMCR_SMS_EXTERNAL_CLOCK << STM_TIM234_SMCR_SMS));
89 stm_tim2.arr = 0xffff;
91 /* Start your timers */
93 stm_tim2.cr1 = ((STM_TIM234_CR1_CKD_1 << STM_TIM234_CR1_CKD) |
94 (0 << STM_TIM234_CR1_ARPE) |
95 (STM_TIM234_CR1_CMS_EDGE | STM_TIM234_CR1_CMS) |
96 (STM_TIM234_CR1_DIR_UP << STM_TIM234_CR1_DIR) |
97 (0 << STM_TIM234_CR1_OPM) |
98 (0 << STM_TIM234_CR1_URS) |
99 (0 << STM_TIM234_CR1_UDIS) |
100 (1 << STM_TIM234_CR1_CEN));
102 stm_tim4.cr1 = ((STM_TIM234_CR1_CKD_1 << STM_TIM234_CR1_CKD) |
103 (0 << STM_TIM234_CR1_ARPE) |
104 (STM_TIM234_CR1_CMS_EDGE | STM_TIM234_CR1_CMS) |
105 (STM_TIM234_CR1_DIR_UP << STM_TIM234_CR1_DIR) |
106 (0 << STM_TIM234_CR1_OPM) |
107 (1 << STM_TIM234_CR1_URS) |
108 (0 << STM_TIM234_CR1_UDIS) |
109 (1 << STM_TIM234_CR1_CEN));
111 ao_cmd_register(&ao_profile_cmds[0]);