mbed-dev-f303

Committer:
abe5b02d-a2d4-4fe9-818e-c4e57c809ea4
Date:
Tue Jun 14 09:21:18 2022 +0000
Revision:
0:bdf663c61a82
lib

Who changed what in which revision?

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