mbed

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

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