This repo contains the libraries of Mbed for LPC1549 with following changes: - IAP commands. - EEPROM write and read. - UART write and read (public) - CAN can_s -> LPC_C_CAN0_Type *can

Committer:
gmatarrubia
Date:
Tue Apr 14 15:00:13 2015 +0200
Revision:
0:820a69dfd200
Initial repo. IAP commands, EEPROM write/read, UART write/read, CAN

Who changed what in which revision?

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