fft

Dependencies:   BSP_DISCO_F746NG SDFileSystem_Warning_Fixed

Committer:
MikamiUitOpen
Date:
Sun Oct 09 10:11:14 2016 +0000
Revision:
0:3e46577dc273
1

Who changed what in which revision?

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