Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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