added prescaler for 16 bit pwm in LPC1347 target

Fork of mbed-dev by mbed official

Committer:
JojoS
Date:
Sat Sep 10 15:32:04 2016 +0000
Revision:
147:ba84b7dc41a7
Parent:
144:ef7eb2e8f9f7
added prescaler for 16 bit timers (solution as in LPC11xx), default prescaler 31 for max 28 ms period time

Who changed what in which revision?

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