libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
timer_common.c
Go to the documentation of this file.
1/** @addtogroup timer_file TIMER peripheral API
2 * @ingroup peripheral_apis
3 */
4/*
5 * This file is part of the libopencm3 project.
6 *
7 * Copyright (C) 2015 Kuldeep Singh Dhaka <kuldeepdhaka9@gmail.com>
8 *
9 * This library is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22
24
25/**@{*/
26
27#define HAS_DEAD_TIME_INSERTION(timer) (timer == TIMER0)
28
29/**
30 * Start timer
31 * @param[in] timer Timer (use TIMERx)
32 */
33void timer_start(uint32_t timer)
34{
36}
37
38/**
39 * Stop timer
40 * @param[in] timer Timer (use TIMERx)
41 */
42void timer_stop(uint32_t timer)
43{
45}
46
47/** Clock division factor
48 * @param[in] timer Timer (use TIMERx)
49 * @param[in] presc Factor (use TIMER_CTRL_PRESC_DIV*)
50 * @note output-clock = input-clock / @a presc
51 */
52void timer_set_clock_prescaler(uint32_t timer, uint32_t presc)
53{
54 TIMER_CTRL(timer) = (TIMER_CTRL(timer) & ~TIMER_CTRL_PRESC_MASK)
55 | TIMER_CTRL_PRESC(presc);
56}
57
58/**
59 * Start timer top value
60 * the timer reload after it reaches top value
61 * @param[in] timer Timer (use TIMERx)
62 * @param[in] top Top value
63 */
64void timer_set_top(uint32_t timer, uint32_t top)
65{
66 TIMER_TOP(timer) = top;
67}
68
69/**@}*/
#define TIMER_CTRL(base)
Definition: timer_common.h:29
#define TIMER_CMD(base)
Definition: timer_common.h:30
#define TIMER_TOP(base)
Definition: timer_common.h:36
#define TIMER_CTRL_PRESC(v)
Definition: timer_common.h:75
#define TIMER_CMD_START
Definition: timer_common.h:141
#define TIMER_CMD_STOP
Definition: timer_common.h:140
void timer_set_top(uint32_t timer, uint32_t top)
Start timer top value the timer reload after it reaches top value.
Definition: timer_common.c:64
void timer_set_clock_prescaler(uint32_t timer, uint32_t presc)
Clock division factor.
Definition: timer_common.c:52
void timer_start(uint32_t timer)
Start timer.
Definition: timer_common.c:33
void timer_stop(uint32_t timer)
Stop timer.
Definition: timer_common.c:42