The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

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