mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /**
elessair 0:f269e3021894 2 ******************************************************************************
elessair 0:f269e3021894 3 * @file timer.h
elessair 0:f269e3021894 4 * @brief (API) Public header of Timer driver
elessair 0:f269e3021894 5 * @internal
elessair 0:f269e3021894 6 * @author ON Semiconductor
elessair 0:f269e3021894 7 * $Rev: 3725 $
elessair 0:f269e3021894 8 * $Date: 2015-09-14 14:36:27 +0530 (Mon, 14 Sep 2015) $
elessair 0:f269e3021894 9 ******************************************************************************
elessair 0:f269e3021894 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
elessair 0:f269e3021894 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
elessair 0:f269e3021894 12 * under limited terms and conditions. The terms and conditions pertaining to the software
elessair 0:f269e3021894 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
elessair 0:f269e3021894 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
elessair 0:f269e3021894 15 * if applicable the software license agreement. Do not use this software and/or
elessair 0:f269e3021894 16 * documentation unless you have carefully read and you agree to the limited terms and
elessair 0:f269e3021894 17 * conditions. By using this software and/or documentation, you agree to the limited
elessair 0:f269e3021894 18 * terms and conditions.
elessair 0:f269e3021894 19 *
elessair 0:f269e3021894 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
elessair 0:f269e3021894 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
elessair 0:f269e3021894 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
elessair 0:f269e3021894 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
elessair 0:f269e3021894 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
elessair 0:f269e3021894 25 * @endinternal
elessair 0:f269e3021894 26 *
elessair 0:f269e3021894 27 * @ingroup timer
elessair 0:f269e3021894 28 *
elessair 0:f269e3021894 29 * @details
elessair 0:f269e3021894 30 *
elessair 0:f269e3021894 31 * <h1> General description </h1>
elessair 0:f269e3021894 32 * <p>
elessair 0:f269e3021894 33 * The APB Timer module is a 16-bit down counter with a selectable <b>prescaler</b>.
elessair 0:f269e3021894 34 * <b>Prescaler</b> values can be selected from 1 to 1024.
elessair 0:f269e3021894 35 * (<b>prescaler</b> extends the range of the timer at the expense of precision)
elessair 0:f269e3021894 36 * The Timer provides two modes of operation being <b>free running</b> and <b>periodic</b>.
elessair 0:f269e3021894 37 * In <b>free running</b> mode, when the counter reaches zero it is decremented to 0xFFFF
elessair 0:f269e3021894 38 * and no interrupt is generated.
elessair 0:f269e3021894 39 * In <b>periodic</b>, when the counter reaches zero it is decremented to load value
elessair 0:f269e3021894 40 * and an interruption is generated.
elessair 0:f269e3021894 41 * </p>
elessair 0:f269e3021894 42 *
elessair 0:f269e3021894 43 */
elessair 0:f269e3021894 44
elessair 0:f269e3021894 45 #ifndef TIMER_H_
elessair 0:f269e3021894 46 #define TIMER_H_
elessair 0:f269e3021894 47
elessair 0:f269e3021894 48 #ifdef __cplusplus
elessair 0:f269e3021894 49 extern "C" {
elessair 0:f269e3021894 50 #endif
elessair 0:f269e3021894 51
elessair 0:f269e3021894 52 //#include "driver.h"
elessair 0:f269e3021894 53 #include "us_ticker_api.h"
elessair 0:f269e3021894 54 #include "clock.h"
elessair 0:f269e3021894 55 #include "timer_map.h"
elessair 0:f269e3021894 56 #include "types.h"
elessair 0:f269e3021894 57 #include "cmsis_nvic.h"
elessair 0:f269e3021894 58
elessair 0:f269e3021894 59 /* Miscellaneous I/O and control operations codes */
elessair 0:f269e3021894 60 #define TIMER_IOCTL_GET_LOAD 1 /**< <b>Ioctl request code</b>: Getting load value. */
elessair 0:f269e3021894 61 #define TIMER_IOCTL_SET_LOAD 2 /**< <b>Ioctl request code</b>: Seting load value. */
elessair 0:f269e3021894 62 #define TIMER_IOCTL_GET_VALUE 3 /**< <b>Ioctl request code</b>: Getting current timer value. */
elessair 0:f269e3021894 63
elessair 0:f269e3021894 64 /* Timer control bits */
elessair 0:f269e3021894 65 #define TIMER_ENABLE_BIT 0x1
elessair 0:f269e3021894 66 #define TIMER_PRESCALE_BIT_POS 0x2
elessair 0:f269e3021894 67 #define TIMER_MODE_BIT_POS 0x6
elessair 0:f269e3021894 68 #define TIMER_ENABLE_BIT_POS 0x7
elessair 0:f269e3021894 69
elessair 0:f269e3021894 70 /* Options defines */
elessair 0:f269e3021894 71 // TODO (MIV): put this in an enumerated value
elessair 0:f269e3021894 72 typedef enum {
elessair 0:f269e3021894 73 CLK_DIVIDER_1 = 0,
elessair 0:f269e3021894 74 CLK_DIVIDER_2 = 3,
elessair 0:f269e3021894 75 CLK_DIVIDER_8 = 4,
elessair 0:f269e3021894 76 CLK_DIVIDER_16 = 1,
elessair 0:f269e3021894 77 CLK_DIVIDER_32 = 5,
elessair 0:f269e3021894 78 CLK_DIVIDER_128 = 6,
elessair 0:f269e3021894 79 CLK_DIVIDER_256 = 2,
elessair 0:f269e3021894 80 CLK_DIVIDER_1024 = 7
elessair 0:f269e3021894 81 } ClockDivider;
elessair 0:f269e3021894 82
elessair 0:f269e3021894 83 #define TIME_MODE_FREE_RUNNING 0x0
elessair 0:f269e3021894 84 #define TIME_MODE_PERIODIC 0x1
elessair 0:f269e3021894 85
elessair 0:f269e3021894 86 typedef void (*timer_irq_handlers_t)(void) ;
elessair 0:f269e3021894 87
elessair 0:f269e3021894 88 /** Options to be passed when opening a timer device instance.*/
elessair 0:f269e3021894 89 typedef struct timer_options {
elessair 0:f269e3021894 90 TimerReg_pt membase; /**< Memory base for the device's registers. */
elessair 0:f269e3021894 91 uint8_t irq; /**< IRQ number of the IRQ associated to the device. */
elessair 0:f269e3021894 92 boolean mode; /**< Timer mode:
elessair 0:f269e3021894 93 * - 0 = Free Run mode (no interrupt generation)
elessair 0:f269e3021894 94 * <b> # timer duration = (65535 + 1) * prescaler * peripheral clock (PCLK) period </b>
elessair 0:f269e3021894 95 * - 1 = Periodic mode (interrupt generation)
elessair 0:f269e3021894 96 * <b> # timer duration = (load + 1) * prescaler * peripheral clock (PCLK) period </b> */
elessair 0:f269e3021894 97 uint8_t prescale; /**< Timer prescaler: from 1 to 1024.
elessair 0:f269e3021894 98 * - CLK_DIVIDER_1 = clock not divided
elessair 0:f269e3021894 99 * - CLK_DIVIDER_2 = clock is divided by 2
elessair 0:f269e3021894 100 * - CLK_DIVIDER_8 = clock is divided by 8
elessair 0:f269e3021894 101 * - CLK_DIVIDER_16 = clock is divided by 16
elessair 0:f269e3021894 102 * - CLK_DIVIDER_32 = clock is divided by 32
elessair 0:f269e3021894 103 * - CLK_DIVIDER_128 = clock is divided by 128
elessair 0:f269e3021894 104 * - CLK_DIVIDER_256 = clock is divided by 256
elessair 0:f269e3021894 105 * - CLK_DIVIDER_1024 = clock is divided by 1024 */
elessair 0:f269e3021894 106 uint16_t load; /**< Timer load: from 0 to 65535. */
elessair 0:f269e3021894 107 timer_irq_handlers_t handler; /**< Timer handler or call-back */
elessair 0:f269e3021894 108 } timer_options_t, *timer_options_pt;
elessair 0:f269e3021894 109
elessair 0:f269e3021894 110 /** Interrupt handler for timer devices; to be called from an actual ISR.
elessair 0:f269e3021894 111 * @param membase Memory base for the device's registers
elessair 0:f269e3021894 112 */
elessair 0:f269e3021894 113 void fTimerHandler(TimerReg_pt membase);
elessair 0:f269e3021894 114
elessair 0:f269e3021894 115 extern void us_timer_isr(void);
elessair 0:f269e3021894 116 extern void us_ticker_isr(void);
elessair 0:f269e3021894 117
elessair 0:f269e3021894 118 #ifdef __cplusplus
elessair 0:f269e3021894 119 }
elessair 0:f269e3021894 120 #endif
elessair 0:f269e3021894 121
elessair 0:f269e3021894 122 #endif /* TIMER_H_ */