libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
timer_common_f0234.c
Go to the documentation of this file.
1/** @addtogroup timer_file
2
3*/
4
5/*
6 * This file is part of the libopencm3 project.
7 *
8 * Copyright (C) 2010 Edward Cheeseman <evbuilder@users.sourceforge.org>
9 * Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com>
10 *
11 * This library is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/**@{*/
26
28
29/*---------------------------------------------------------------------------*/
30/** @brief Set Input Polarity
31
32The timer channel must be set to input capture mode.
33
34@param[in] timer_peripheral Unsigned int32. Timer register address base
35@param[in] ic ::tim_ic_id. Input Capture channel designator.
36@param[in] pol ::tim_ic_pol. Input Capture polarity control.
37*/
38
39void timer_ic_set_polarity(uint32_t timer_peripheral, enum tim_ic_id ic,
40 enum tim_ic_pol pol)
41{
42 /* Clear CCxP and CCxNP to zero. For both edge trigger both fields are
43 * set. Case 10 is invalid.
44 */
45 TIM_CCER(timer_peripheral) &= ~(0xa << (ic * 4));
46 switch (pol) {
47 case TIM_IC_RISING: /* 00 */
48 break;
49 case TIM_IC_BOTH: /* 11 */
50 TIM_CCER(timer_peripheral) |= (0xa << (ic * 4));
51 break;
52 case TIM_IC_FALLING: /* 01 */
53 TIM_CCER(timer_peripheral) |= (0x2 << (ic * 4));
54 }
55}
56/**@}*/
57
58
#define TIM_CCER(tim_base)
tim_ic_id
Input Capture channel designators.
void timer_ic_set_polarity(uint32_t timer_peripheral, enum tim_ic_id ic, enum tim_ic_pol pol)
Set Input Polarity.
tim_ic_pol
Input Capture input polarity.
@ TIM_IC_FALLING
@ TIM_IC_RISING
@ TIM_IC_BOTH