USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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