change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jasper_lee 0:b16d94660a33 1 /* mbed Microcontroller Library
Jasper_lee 0:b16d94660a33 2 * Copyright (c) 2006-2013 ARM Limited
Jasper_lee 0:b16d94660a33 3 *
Jasper_lee 0:b16d94660a33 4 * Licensed under the Apache License, Version 2.0 (the "License");
Jasper_lee 0:b16d94660a33 5 * you may not use this file except in compliance with the License.
Jasper_lee 0:b16d94660a33 6 * You may obtain a copy of the License at
Jasper_lee 0:b16d94660a33 7 *
Jasper_lee 0:b16d94660a33 8 * http://www.apache.org/licenses/LICENSE-2.0
Jasper_lee 0:b16d94660a33 9 *
Jasper_lee 0:b16d94660a33 10 * Unless required by applicable law or agreed to in writing, software
Jasper_lee 0:b16d94660a33 11 * distributed under the License is distributed on an "AS IS" BASIS,
Jasper_lee 0:b16d94660a33 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Jasper_lee 0:b16d94660a33 13 * See the License for the specific language governing permissions and
Jasper_lee 0:b16d94660a33 14 * limitations under the License.
Jasper_lee 0:b16d94660a33 15 */
Jasper_lee 0:b16d94660a33 16 #ifndef MBED_SERIALBASE_H
Jasper_lee 0:b16d94660a33 17 #define MBED_SERIALBASE_H
Jasper_lee 0:b16d94660a33 18
Jasper_lee 0:b16d94660a33 19 #include "platform.h"
Jasper_lee 0:b16d94660a33 20
Jasper_lee 0:b16d94660a33 21 #if DEVICE_SERIAL
Jasper_lee 0:b16d94660a33 22
Jasper_lee 0:b16d94660a33 23 #include "Stream.h"
Jasper_lee 0:b16d94660a33 24 #include "FunctionPointer.h"
Jasper_lee 0:b16d94660a33 25 #include "serial_api.h"
Jasper_lee 0:b16d94660a33 26
Jasper_lee 0:b16d94660a33 27 namespace mbed {
Jasper_lee 0:b16d94660a33 28
Jasper_lee 0:b16d94660a33 29 /** A base class for serial port implementations
Jasper_lee 0:b16d94660a33 30 * Can't be instantiated directly (use Serial or RawSerial)
Jasper_lee 0:b16d94660a33 31 */
Jasper_lee 0:b16d94660a33 32 class SerialBase {
Jasper_lee 0:b16d94660a33 33
Jasper_lee 0:b16d94660a33 34 public:
Jasper_lee 0:b16d94660a33 35 /** Set the baud rate of the serial port
Jasper_lee 0:b16d94660a33 36 *
Jasper_lee 0:b16d94660a33 37 * @param baudrate The baudrate of the serial port (default = 9600).
Jasper_lee 0:b16d94660a33 38 */
Jasper_lee 0:b16d94660a33 39 void baud(int baudrate);
Jasper_lee 0:b16d94660a33 40
Jasper_lee 0:b16d94660a33 41 enum Parity {
Jasper_lee 0:b16d94660a33 42 None = 0,
Jasper_lee 0:b16d94660a33 43 Odd,
Jasper_lee 0:b16d94660a33 44 Even,
Jasper_lee 0:b16d94660a33 45 Forced1,
Jasper_lee 0:b16d94660a33 46 Forced0
Jasper_lee 0:b16d94660a33 47 };
Jasper_lee 0:b16d94660a33 48
Jasper_lee 0:b16d94660a33 49 enum IrqType {
Jasper_lee 0:b16d94660a33 50 RxIrq = 0,
Jasper_lee 0:b16d94660a33 51 TxIrq
Jasper_lee 0:b16d94660a33 52 };
Jasper_lee 0:b16d94660a33 53
Jasper_lee 0:b16d94660a33 54 enum Flow {
Jasper_lee 0:b16d94660a33 55 Disabled = 0,
Jasper_lee 0:b16d94660a33 56 RTS,
Jasper_lee 0:b16d94660a33 57 CTS,
Jasper_lee 0:b16d94660a33 58 RTSCTS
Jasper_lee 0:b16d94660a33 59 };
Jasper_lee 0:b16d94660a33 60
Jasper_lee 0:b16d94660a33 61 /** Set the transmission format used by the serial port
Jasper_lee 0:b16d94660a33 62 *
Jasper_lee 0:b16d94660a33 63 * @param bits The number of bits in a word (5-8; default = 8)
Jasper_lee 0:b16d94660a33 64 * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
Jasper_lee 0:b16d94660a33 65 * @param stop The number of stop bits (1 or 2; default = 1)
Jasper_lee 0:b16d94660a33 66 */
Jasper_lee 0:b16d94660a33 67 void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
Jasper_lee 0:b16d94660a33 68
Jasper_lee 0:b16d94660a33 69 /** Determine if there is a character available to read
Jasper_lee 0:b16d94660a33 70 *
Jasper_lee 0:b16d94660a33 71 * @returns
Jasper_lee 0:b16d94660a33 72 * 1 if there is a character available to read,
Jasper_lee 0:b16d94660a33 73 * 0 otherwise
Jasper_lee 0:b16d94660a33 74 */
Jasper_lee 0:b16d94660a33 75 int readable();
Jasper_lee 0:b16d94660a33 76
Jasper_lee 0:b16d94660a33 77 /** Determine if there is space available to write a character
Jasper_lee 0:b16d94660a33 78 *
Jasper_lee 0:b16d94660a33 79 * @returns
Jasper_lee 0:b16d94660a33 80 * 1 if there is space to write a character,
Jasper_lee 0:b16d94660a33 81 * 0 otherwise
Jasper_lee 0:b16d94660a33 82 */
Jasper_lee 0:b16d94660a33 83 int writeable();
Jasper_lee 0:b16d94660a33 84
Jasper_lee 0:b16d94660a33 85 /** Attach a function to call whenever a serial interrupt is generated
Jasper_lee 0:b16d94660a33 86 *
Jasper_lee 0:b16d94660a33 87 * @param fptr A pointer to a void function, or 0 to set as none
Jasper_lee 0:b16d94660a33 88 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
Jasper_lee 0:b16d94660a33 89 */
Jasper_lee 0:b16d94660a33 90 void attach(void (*fptr)(void), IrqType type=RxIrq);
Jasper_lee 0:b16d94660a33 91
Jasper_lee 0:b16d94660a33 92 /** Attach a member function to call whenever a serial interrupt is generated
Jasper_lee 0:b16d94660a33 93 *
Jasper_lee 0:b16d94660a33 94 * @param tptr pointer to the object to call the member function on
Jasper_lee 0:b16d94660a33 95 * @param mptr pointer to the member function to be called
Jasper_lee 0:b16d94660a33 96 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
Jasper_lee 0:b16d94660a33 97 */
Jasper_lee 0:b16d94660a33 98 template<typename T>
Jasper_lee 0:b16d94660a33 99 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
Jasper_lee 0:b16d94660a33 100 if((mptr != NULL) && (tptr != NULL)) {
Jasper_lee 0:b16d94660a33 101 _irq[type].attach(tptr, mptr);
Jasper_lee 0:b16d94660a33 102 serial_irq_set(&_serial, (SerialIrq)type, 1);
Jasper_lee 0:b16d94660a33 103 }
Jasper_lee 0:b16d94660a33 104 }
Jasper_lee 0:b16d94660a33 105
Jasper_lee 0:b16d94660a33 106 /** Generate a break condition on the serial line
Jasper_lee 0:b16d94660a33 107 */
Jasper_lee 0:b16d94660a33 108 void send_break();
Jasper_lee 0:b16d94660a33 109
Jasper_lee 0:b16d94660a33 110 #if DEVICE_SERIAL_FC
Jasper_lee 0:b16d94660a33 111 /** Set the flow control type on the serial port
Jasper_lee 0:b16d94660a33 112 *
Jasper_lee 0:b16d94660a33 113 * @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
Jasper_lee 0:b16d94660a33 114 * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
Jasper_lee 0:b16d94660a33 115 * @param flow2 the second flow control pin (CTS for RTSCTS)
Jasper_lee 0:b16d94660a33 116 */
Jasper_lee 0:b16d94660a33 117 void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
Jasper_lee 0:b16d94660a33 118 #endif
Jasper_lee 0:b16d94660a33 119
Jasper_lee 0:b16d94660a33 120 static void _irq_handler(uint32_t id, SerialIrq irq_type);
Jasper_lee 0:b16d94660a33 121
Jasper_lee 0:b16d94660a33 122 protected:
Jasper_lee 0:b16d94660a33 123 SerialBase(PinName tx, PinName rx);
Jasper_lee 0:b16d94660a33 124 virtual ~SerialBase() {
Jasper_lee 0:b16d94660a33 125 }
Jasper_lee 0:b16d94660a33 126
Jasper_lee 0:b16d94660a33 127 int _base_getc();
Jasper_lee 0:b16d94660a33 128 int _base_putc(int c);
Jasper_lee 0:b16d94660a33 129
Jasper_lee 0:b16d94660a33 130 serial_t _serial;
Jasper_lee 0:b16d94660a33 131 FunctionPointer _irq[2];
Jasper_lee 0:b16d94660a33 132 int _baud;
Jasper_lee 0:b16d94660a33 133 };
Jasper_lee 0:b16d94660a33 134
Jasper_lee 0:b16d94660a33 135 } // namespace mbed
Jasper_lee 0:b16d94660a33 136
Jasper_lee 0:b16d94660a33 137 #endif
Jasper_lee 0:b16d94660a33 138
Jasper_lee 0:b16d94660a33 139 #endif