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 /* mbed Microcontroller Library
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2006-2013 ARM Limited
<> 144:ef7eb2e8f9f7 3 *
<> 144:ef7eb2e8f9f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 144:ef7eb2e8f9f7 5 * you may not use this file except in compliance with the License.
<> 144:ef7eb2e8f9f7 6 * You may obtain a copy of the License at
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 144:ef7eb2e8f9f7 9 *
<> 144:ef7eb2e8f9f7 10 * Unless required by applicable law or agreed to in writing, software
<> 144:ef7eb2e8f9f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 144:ef7eb2e8f9f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 144:ef7eb2e8f9f7 13 * See the License for the specific language governing permissions and
<> 144:ef7eb2e8f9f7 14 * limitations under the License.
<> 144:ef7eb2e8f9f7 15 */
<> 144:ef7eb2e8f9f7 16 #ifndef MBED_SERIALBASE_H
<> 144:ef7eb2e8f9f7 17 #define MBED_SERIALBASE_H
<> 144:ef7eb2e8f9f7 18
<> 144:ef7eb2e8f9f7 19 #include "platform.h"
<> 144:ef7eb2e8f9f7 20
<> 144:ef7eb2e8f9f7 21 #if DEVICE_SERIAL
<> 144:ef7eb2e8f9f7 22
<> 144:ef7eb2e8f9f7 23 #include "Stream.h"
<> 144:ef7eb2e8f9f7 24 #include "Callback.h"
<> 144:ef7eb2e8f9f7 25 #include "serial_api.h"
<> 144:ef7eb2e8f9f7 26
<> 144:ef7eb2e8f9f7 27 #if DEVICE_SERIAL_ASYNCH
<> 144:ef7eb2e8f9f7 28 #include "CThunk.h"
<> 144:ef7eb2e8f9f7 29 #include "dma_api.h"
<> 144:ef7eb2e8f9f7 30 #endif
<> 144:ef7eb2e8f9f7 31
<> 144:ef7eb2e8f9f7 32 namespace mbed {
<> 144:ef7eb2e8f9f7 33
<> 144:ef7eb2e8f9f7 34 /** A base class for serial port implementations
<> 144:ef7eb2e8f9f7 35 * Can't be instantiated directly (use Serial or RawSerial)
<> 144:ef7eb2e8f9f7 36 *
<> 144:ef7eb2e8f9f7 37 * @Note Synchronization level: Set by subclass
<> 144:ef7eb2e8f9f7 38 */
<> 144:ef7eb2e8f9f7 39 class SerialBase {
<> 144:ef7eb2e8f9f7 40
<> 144:ef7eb2e8f9f7 41 public:
<> 144:ef7eb2e8f9f7 42 /** Set the baud rate of the serial port
<> 144:ef7eb2e8f9f7 43 *
<> 144:ef7eb2e8f9f7 44 * @param baudrate The baudrate of the serial port (default = 9600).
<> 144:ef7eb2e8f9f7 45 */
<> 144:ef7eb2e8f9f7 46 void baud(int baudrate);
<> 144:ef7eb2e8f9f7 47
<> 144:ef7eb2e8f9f7 48 enum Parity {
<> 144:ef7eb2e8f9f7 49 None = 0,
<> 144:ef7eb2e8f9f7 50 Odd,
<> 144:ef7eb2e8f9f7 51 Even,
<> 144:ef7eb2e8f9f7 52 Forced1,
<> 144:ef7eb2e8f9f7 53 Forced0
<> 144:ef7eb2e8f9f7 54 };
<> 144:ef7eb2e8f9f7 55
<> 144:ef7eb2e8f9f7 56 enum IrqType {
<> 144:ef7eb2e8f9f7 57 RxIrq = 0,
<> 144:ef7eb2e8f9f7 58 TxIrq
<> 144:ef7eb2e8f9f7 59 };
<> 144:ef7eb2e8f9f7 60
<> 144:ef7eb2e8f9f7 61 enum Flow {
<> 144:ef7eb2e8f9f7 62 Disabled = 0,
<> 144:ef7eb2e8f9f7 63 RTS,
<> 144:ef7eb2e8f9f7 64 CTS,
<> 144:ef7eb2e8f9f7 65 RTSCTS
<> 144:ef7eb2e8f9f7 66 };
<> 144:ef7eb2e8f9f7 67
<> 144:ef7eb2e8f9f7 68 /** Set the transmission format used by the serial port
<> 144:ef7eb2e8f9f7 69 *
<> 144:ef7eb2e8f9f7 70 * @param bits The number of bits in a word (5-8; default = 8)
<> 144:ef7eb2e8f9f7 71 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
<> 144:ef7eb2e8f9f7 72 * @param stop The number of stop bits (1 or 2; default = 1)
<> 144:ef7eb2e8f9f7 73 */
<> 144:ef7eb2e8f9f7 74 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
<> 144:ef7eb2e8f9f7 75
<> 144:ef7eb2e8f9f7 76 /** Determine if there is a character available to read
<> 144:ef7eb2e8f9f7 77 *
<> 144:ef7eb2e8f9f7 78 * @returns
<> 144:ef7eb2e8f9f7 79 * 1 if there is a character available to read,
<> 144:ef7eb2e8f9f7 80 * 0 otherwise
<> 144:ef7eb2e8f9f7 81 */
<> 144:ef7eb2e8f9f7 82 int readable();
<> 144:ef7eb2e8f9f7 83
<> 144:ef7eb2e8f9f7 84 /** Determine if there is space available to write a character
<> 144:ef7eb2e8f9f7 85 *
<> 144:ef7eb2e8f9f7 86 * @returns
<> 144:ef7eb2e8f9f7 87 * 1 if there is space to write a character,
<> 144:ef7eb2e8f9f7 88 * 0 otherwise
<> 144:ef7eb2e8f9f7 89 */
<> 144:ef7eb2e8f9f7 90 int writeable();
<> 144:ef7eb2e8f9f7 91
<> 144:ef7eb2e8f9f7 92 /** Attach a function to call whenever a serial interrupt is generated
<> 144:ef7eb2e8f9f7 93 *
<> 144:ef7eb2e8f9f7 94 * @param func A pointer to a void function, or 0 to set as none
<> 144:ef7eb2e8f9f7 95 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
<> 144:ef7eb2e8f9f7 96 */
<> 144:ef7eb2e8f9f7 97 void attach(Callback<void()> func, IrqType type=RxIrq);
<> 144:ef7eb2e8f9f7 98
<> 144:ef7eb2e8f9f7 99 /** Attach a member function to call whenever a serial interrupt is generated
<> 144:ef7eb2e8f9f7 100 *
<> 144:ef7eb2e8f9f7 101 * @param obj pointer to the object to call the member function on
<> 144:ef7eb2e8f9f7 102 * @param method pointer to the member function to be called
<> 144:ef7eb2e8f9f7 103 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
<> 144:ef7eb2e8f9f7 104 */
<> 144:ef7eb2e8f9f7 105 template<typename T>
<> 144:ef7eb2e8f9f7 106 void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {
<> 144:ef7eb2e8f9f7 107 attach(Callback<void()>(obj, method), type);
<> 144:ef7eb2e8f9f7 108 }
<> 144:ef7eb2e8f9f7 109
<> 144:ef7eb2e8f9f7 110 /** Attach a member function to call whenever a serial interrupt is generated
<> 144:ef7eb2e8f9f7 111 *
<> 144:ef7eb2e8f9f7 112 * @param obj pointer to the object to call the member function on
<> 144:ef7eb2e8f9f7 113 * @param method pointer to the member function to be called
<> 144:ef7eb2e8f9f7 114 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
<> 144:ef7eb2e8f9f7 115 */
<> 144:ef7eb2e8f9f7 116 template<typename T>
<> 144:ef7eb2e8f9f7 117 void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) {
<> 144:ef7eb2e8f9f7 118 attach(Callback<void()>(obj, method), type);
<> 144:ef7eb2e8f9f7 119 }
<> 144:ef7eb2e8f9f7 120
<> 144:ef7eb2e8f9f7 121 /** Generate a break condition on the serial line
<> 144:ef7eb2e8f9f7 122 */
<> 144:ef7eb2e8f9f7 123 void send_break();
<> 144:ef7eb2e8f9f7 124
<> 144:ef7eb2e8f9f7 125 protected:
<> 144:ef7eb2e8f9f7 126
<> 144:ef7eb2e8f9f7 127 /** Acquire exclusive access to this serial port
<> 144:ef7eb2e8f9f7 128 */
<> 144:ef7eb2e8f9f7 129 virtual void lock(void);
<> 144:ef7eb2e8f9f7 130
<> 144:ef7eb2e8f9f7 131 /** Release exclusive access to this serial port
<> 144:ef7eb2e8f9f7 132 */
<> 144:ef7eb2e8f9f7 133 virtual void unlock(void);
<> 144:ef7eb2e8f9f7 134
<> 144:ef7eb2e8f9f7 135 public:
<> 144:ef7eb2e8f9f7 136
<> 144:ef7eb2e8f9f7 137 #if DEVICE_SERIAL_FC
<> 144:ef7eb2e8f9f7 138 /** Set the flow control type on the serial port
<> 144:ef7eb2e8f9f7 139 *
<> 144:ef7eb2e8f9f7 140 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
<> 144:ef7eb2e8f9f7 141 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
<> 144:ef7eb2e8f9f7 142 * @param flow2 the second flow control pin (CTS for RTSCTS)
<> 144:ef7eb2e8f9f7 143 */
<> 144:ef7eb2e8f9f7 144 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
<> 144:ef7eb2e8f9f7 145 #endif
<> 144:ef7eb2e8f9f7 146
<> 144:ef7eb2e8f9f7 147 static void _irq_handler(uint32_t id, SerialIrq irq_type);
<> 144:ef7eb2e8f9f7 148
<> 144:ef7eb2e8f9f7 149 #if DEVICE_SERIAL_ASYNCH
<> 144:ef7eb2e8f9f7 150
<> 144:ef7eb2e8f9f7 151 /** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
<> 144:ef7eb2e8f9f7 152 *
<> 144:ef7eb2e8f9f7 153 * @param buffer The buffer where received data will be stored
<> 144:ef7eb2e8f9f7 154 * @param length The buffer length in bytes
<> 144:ef7eb2e8f9f7 155 * @param callback The event callback function
<> 144:ef7eb2e8f9f7 156 * @param event The logical OR of TX events
<> 144:ef7eb2e8f9f7 157 */
<> 144:ef7eb2e8f9f7 158 int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
<> 144:ef7eb2e8f9f7 159
<> 144:ef7eb2e8f9f7 160 /** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
<> 144:ef7eb2e8f9f7 161 *
<> 144:ef7eb2e8f9f7 162 * @param buffer The buffer where received data will be stored
<> 144:ef7eb2e8f9f7 163 * @param length The buffer length in bytes
<> 144:ef7eb2e8f9f7 164 * @param callback The event callback function
<> 144:ef7eb2e8f9f7 165 * @param event The logical OR of TX events
<> 144:ef7eb2e8f9f7 166 */
<> 144:ef7eb2e8f9f7 167 int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
<> 144:ef7eb2e8f9f7 168
<> 144:ef7eb2e8f9f7 169 /** Abort the on-going write transfer
<> 144:ef7eb2e8f9f7 170 */
<> 144:ef7eb2e8f9f7 171 void abort_write();
<> 144:ef7eb2e8f9f7 172
<> 144:ef7eb2e8f9f7 173 /** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
<> 144:ef7eb2e8f9f7 174 *
<> 144:ef7eb2e8f9f7 175 * @param buffer The buffer where received data will be stored
<> 144:ef7eb2e8f9f7 176 * @param length The buffer length in bytes
<> 144:ef7eb2e8f9f7 177 * @param callback The event callback function
<> 144:ef7eb2e8f9f7 178 * @param event The logical OR of RX events
<> 144:ef7eb2e8f9f7 179 * @param char_match The matching character
<> 144:ef7eb2e8f9f7 180 */
<> 144:ef7eb2e8f9f7 181 int read(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
<> 144:ef7eb2e8f9f7 182
<> 144:ef7eb2e8f9f7 183 /** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
<> 144:ef7eb2e8f9f7 184 *
<> 144:ef7eb2e8f9f7 185 * @param buffer The buffer where received data will be stored
<> 144:ef7eb2e8f9f7 186 * @param length The buffer length in bytes
<> 144:ef7eb2e8f9f7 187 * @param callback The event callback function
<> 144:ef7eb2e8f9f7 188 * @param event The logical OR of RX events
<> 144:ef7eb2e8f9f7 189 * @param char_match The matching character
<> 144:ef7eb2e8f9f7 190 */
<> 144:ef7eb2e8f9f7 191 int read(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
<> 144:ef7eb2e8f9f7 192
<> 144:ef7eb2e8f9f7 193 /** Abort the on-going read transfer
<> 144:ef7eb2e8f9f7 194 */
<> 144:ef7eb2e8f9f7 195 void abort_read();
<> 144:ef7eb2e8f9f7 196
<> 144:ef7eb2e8f9f7 197 /** Configure DMA usage suggestion for non-blocking TX transfers
<> 144:ef7eb2e8f9f7 198 *
<> 144:ef7eb2e8f9f7 199 * @param usage The usage DMA hint for peripheral
<> 144:ef7eb2e8f9f7 200 * @return Zero if the usage was set, -1 if a transaction is on-going
<> 144:ef7eb2e8f9f7 201 */
<> 144:ef7eb2e8f9f7 202 int set_dma_usage_tx(DMAUsage usage);
<> 144:ef7eb2e8f9f7 203
<> 144:ef7eb2e8f9f7 204 /** Configure DMA usage suggestion for non-blocking RX transfers
<> 144:ef7eb2e8f9f7 205 *
<> 144:ef7eb2e8f9f7 206 * @param usage The usage DMA hint for peripheral
<> 144:ef7eb2e8f9f7 207 * @return Zero if the usage was set, -1 if a transaction is on-going
<> 144:ef7eb2e8f9f7 208 */
<> 144:ef7eb2e8f9f7 209 int set_dma_usage_rx(DMAUsage usage);
<> 144:ef7eb2e8f9f7 210
<> 144:ef7eb2e8f9f7 211 protected:
<> 144:ef7eb2e8f9f7 212 void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
<> 144:ef7eb2e8f9f7 213 void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
<> 144:ef7eb2e8f9f7 214 void interrupt_handler_asynch(void);
<> 144:ef7eb2e8f9f7 215 #endif
<> 144:ef7eb2e8f9f7 216
<> 144:ef7eb2e8f9f7 217 protected:
<> 144:ef7eb2e8f9f7 218 SerialBase(PinName tx, PinName rx);
<> 144:ef7eb2e8f9f7 219 virtual ~SerialBase() {
<> 144:ef7eb2e8f9f7 220 }
<> 144:ef7eb2e8f9f7 221
<> 144:ef7eb2e8f9f7 222 int _base_getc();
<> 144:ef7eb2e8f9f7 223 int _base_putc(int c);
<> 144:ef7eb2e8f9f7 224
<> 144:ef7eb2e8f9f7 225 #if DEVICE_SERIAL_ASYNCH
<> 144:ef7eb2e8f9f7 226 CThunk<SerialBase> _thunk_irq;
<> 144:ef7eb2e8f9f7 227 event_callback_t _tx_callback;
<> 144:ef7eb2e8f9f7 228 event_callback_t _rx_callback;
<> 144:ef7eb2e8f9f7 229 DMAUsage _tx_usage;
<> 144:ef7eb2e8f9f7 230 DMAUsage _rx_usage;
<> 144:ef7eb2e8f9f7 231 #endif
<> 144:ef7eb2e8f9f7 232
<> 144:ef7eb2e8f9f7 233 serial_t _serial;
<> 144:ef7eb2e8f9f7 234 Callback<void()> _irq[2];
<> 144:ef7eb2e8f9f7 235 int _baud;
<> 144:ef7eb2e8f9f7 236
<> 144:ef7eb2e8f9f7 237 };
<> 144:ef7eb2e8f9f7 238
<> 144:ef7eb2e8f9f7 239 } // namespace mbed
<> 144:ef7eb2e8f9f7 240
<> 144:ef7eb2e8f9f7 241 #endif
<> 144:ef7eb2e8f9f7 242
<> 144:ef7eb2e8f9f7 243 #endif