The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 171:3a7713b1edbc 1 /**
AnnaBridge 171:3a7713b1edbc 2 ******************************************************************************
AnnaBridge 171:3a7713b1edbc 3 * @file uart_16c550.h
AnnaBridge 171:3a7713b1edbc 4 * @brief Definitions and API for the 16c550 driver.
AnnaBridge 171:3a7713b1edbc 5 * @internal
AnnaBridge 171:3a7713b1edbc 6 * @author ON Semiconductor
AnnaBridge 171:3a7713b1edbc 7 * $Rev: 2607 $
AnnaBridge 171:3a7713b1edbc 8 * $Date: 2013-12-06 18:02:43 +0530 (Fri, 06 Dec 2013) $
AnnaBridge 171:3a7713b1edbc 9 ******************************************************************************
AnnaBridge 171:3a7713b1edbc 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
AnnaBridge 171:3a7713b1edbc 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
AnnaBridge 171:3a7713b1edbc 12 * under limited terms and conditions. The terms and conditions pertaining to the software
AnnaBridge 171:3a7713b1edbc 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
AnnaBridge 171:3a7713b1edbc 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
AnnaBridge 171:3a7713b1edbc 15 * if applicable the software license agreement. Do not use this software and/or
AnnaBridge 171:3a7713b1edbc 16 * documentation unless you have carefully read and you agree to the limited terms and
AnnaBridge 171:3a7713b1edbc 17 * conditions. By using this software and/or documentation, you agree to the limited
AnnaBridge 171:3a7713b1edbc 18 * terms and conditions.
AnnaBridge 171:3a7713b1edbc 19 *
AnnaBridge 171:3a7713b1edbc 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
AnnaBridge 171:3a7713b1edbc 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
AnnaBridge 171:3a7713b1edbc 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
AnnaBridge 171:3a7713b1edbc 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
AnnaBridge 171:3a7713b1edbc 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
AnnaBridge 171:3a7713b1edbc 25 * @endinternal
AnnaBridge 171:3a7713b1edbc 26 *
AnnaBridge 171:3a7713b1edbc 27 * @ingroup uart_16c550
AnnaBridge 171:3a7713b1edbc 28 *
AnnaBridge 171:3a7713b1edbc 29 * @details
AnnaBridge 171:3a7713b1edbc 30 * The driver for the 16c550 UART is a character driver (see char_driver.h).
AnnaBridge 171:3a7713b1edbc 31 * The driver can be accessed via the uart_16c550_driver variable.
AnnaBridge 171:3a7713b1edbc 32 *
AnnaBridge 171:3a7713b1edbc 33 * This file defines the options structure to be passed to the driver when
AnnaBridge 171:3a7713b1edbc 34 * opening a device. The structure depends on the generic uart_options_t
AnnaBridge 171:3a7713b1edbc 35 * options structure for any UART implementation (see uart.h).
AnnaBridge 171:3a7713b1edbc 36 *
AnnaBridge 171:3a7713b1edbc 37 * Any application that uses this driver must define an interrupt handler
AnnaBridge 171:3a7713b1edbc 38 * for the 16C550 interrupt and call the fUart16C550Handler() function from
AnnaBridge 171:3a7713b1edbc 39 * that ISR.
AnnaBridge 171:3a7713b1edbc 40 */
AnnaBridge 171:3a7713b1edbc 41
AnnaBridge 171:3a7713b1edbc 42 #ifndef UART_16C550_H_
AnnaBridge 171:3a7713b1edbc 43 #define UART_16C550_H_
AnnaBridge 171:3a7713b1edbc 44
AnnaBridge 171:3a7713b1edbc 45 #include "architecture.h"
AnnaBridge 171:3a7713b1edbc 46 #include "uart.h"
AnnaBridge 171:3a7713b1edbc 47 #include "uart_16c550_map.h"
AnnaBridge 171:3a7713b1edbc 48 #include "memory_map.h"
AnnaBridge 171:3a7713b1edbc 49 #include "crossbar.h"
AnnaBridge 171:3a7713b1edbc 50 #include "types.h"
AnnaBridge 171:3a7713b1edbc 51 #include "clock.h"
AnnaBridge 171:3a7713b1edbc 52 #include "pad.h"
AnnaBridge 171:3a7713b1edbc 53 #include "serial_api.h"
AnnaBridge 171:3a7713b1edbc 54
AnnaBridge 171:3a7713b1edbc 55 /** A set of options to be passed when opening a 16C550 UART device. */
AnnaBridge 171:3a7713b1edbc 56 typedef struct uart_16c550_options {
AnnaBridge 171:3a7713b1edbc 57 uart_options_t uartOptions; /**< The generic UART options. */
AnnaBridge 171:3a7713b1edbc 58 Uart16C550Reg_pt membase; /**< The memory base for the device's registers. */
AnnaBridge 171:3a7713b1edbc 59 uint8_t irq; /**< The IRQ number of the IRQ associated to the device. */
AnnaBridge 171:3a7713b1edbc 60 } uart_16c550_options_t, *uart_16c550_options_pt;
AnnaBridge 171:3a7713b1edbc 61
AnnaBridge 171:3a7713b1edbc 62 #define UART_NUM 2
AnnaBridge 171:3a7713b1edbc 63
AnnaBridge 171:3a7713b1edbc 64 #define CTS_ASSERT 1
AnnaBridge 171:3a7713b1edbc 65 #define CTS_UNASSERT 0
AnnaBridge 171:3a7713b1edbc 66 #define RTS_ASSERT 1
AnnaBridge 171:3a7713b1edbc 67 #define RTS_UNASSERT 0
AnnaBridge 171:3a7713b1edbc 68
AnnaBridge 171:3a7713b1edbc 69 #define UART_ERROR_INSUFFICIENT_SPACE ((uint8_t)0xF0)
AnnaBridge 171:3a7713b1edbc 70 #define UART_ERROR_TOO_BIG ((uint8_t)0xF1)
AnnaBridge 171:3a7713b1edbc 71
AnnaBridge 171:3a7713b1edbc 72 /** The depth of the hardware FIFOs. */
AnnaBridge 171:3a7713b1edbc 73 #define UART_HW_FIFO_DEPTH 16
AnnaBridge 171:3a7713b1edbc 74
AnnaBridge 171:3a7713b1edbc 75 /** The length of the receive buffer in software. */
AnnaBridge 171:3a7713b1edbc 76 #define UART_RX_BUFFER_LENGTH (1<<8)
AnnaBridge 171:3a7713b1edbc 77 #define UART_TX_BUFFER_LENGTH (1<<8)
AnnaBridge 171:3a7713b1edbc 78
AnnaBridge 171:3a7713b1edbc 79 #define STATUS_INVALID_PARAMETER 0x1
AnnaBridge 171:3a7713b1edbc 80 #define STATUS_SUCCESS 0x1
AnnaBridge 171:3a7713b1edbc 81
AnnaBridge 171:3a7713b1edbc 82 #define UART_LCR_DATALEN_BIT_POS 0
AnnaBridge 171:3a7713b1edbc 83 #define UART_LCR_STPBIT_BIT_POS 2
AnnaBridge 171:3a7713b1edbc 84 #define UART_LCR_PARITY_BIT_POS 3
AnnaBridge 171:3a7713b1edbc 85
AnnaBridge 171:3a7713b1edbc 86 #define UART_FCS_RX_FIFO_RST_BIT_POS 1
AnnaBridge 171:3a7713b1edbc 87 #define UART_FCS_TX_FIFO_RST_BIT_POS 2
AnnaBridge 171:3a7713b1edbc 88
AnnaBridge 171:3a7713b1edbc 89 #define UART_RX_IRQ 0x0
AnnaBridge 171:3a7713b1edbc 90 #define UART_TX_IRQ 0x1
AnnaBridge 171:3a7713b1edbc 91
AnnaBridge 171:3a7713b1edbc 92 #define UART_RX_BUFFER_LEN_MAX 16
AnnaBridge 171:3a7713b1edbc 93
AnnaBridge 171:3a7713b1edbc 94 #define UART_LSR_TX_EMPTY_MASK 0x40
AnnaBridge 171:3a7713b1edbc 95 #define UART_LSR_RX_DATA_READY_MASK 0x01
AnnaBridge 171:3a7713b1edbc 96
AnnaBridge 171:3a7713b1edbc 97 #define UART_IER_TX_EMPTY_MASK 0x02
AnnaBridge 171:3a7713b1edbc 98 #define UART_IER_RX_DATA_READY_MASK 0x01
AnnaBridge 171:3a7713b1edbc 99
AnnaBridge 171:3a7713b1edbc 100 #define UART_DEFAULT_BAUD 9600
AnnaBridge 171:3a7713b1edbc 101
AnnaBridge 171:3a7713b1edbc 102 /** Interrupt handler for 16C550 UART devices; to be called from an actual ISR.
AnnaBridge 171:3a7713b1edbc 103 * @param membase The memory base for the device that corresponds to the IRQ.
AnnaBridge 171:3a7713b1edbc 104 */
AnnaBridge 171:3a7713b1edbc 105 void fUart16C550Handler(Uart16C550Reg_pt membase);
AnnaBridge 171:3a7713b1edbc 106
AnnaBridge 171:3a7713b1edbc 107 /** An externally accessible instance of the UART driver implementation. */
AnnaBridge 171:3a7713b1edbc 108 //extern char_driver_t uart_16c550_driver;
AnnaBridge 171:3a7713b1edbc 109 typedef void (*fUartCallBack)(void);
AnnaBridge 171:3a7713b1edbc 110 //void serial_init(serial_t *obj, PinName tx, PinName rx);
AnnaBridge 171:3a7713b1edbc 111 //extern void fSerialInit(Uart16C550Reg_pt UartRegBase, flow_control_t FlowControl);
AnnaBridge 171:3a7713b1edbc 112 extern void fSerialFree(void);
AnnaBridge 171:3a7713b1edbc 113 extern void fSerialBaud(Uart16C550Reg_pt UartRegBase, uint32_t BaudRate);
AnnaBridge 171:3a7713b1edbc 114 extern void fSerialFormat(Uart16C550Reg_pt UartRegBase, uint8_t DataLen, uint8_t Parity, uint8_t StopBit);
AnnaBridge 171:3a7713b1edbc 115 extern void fSerialIrqSet(Uart16C550Reg_pt UartRegBase, fUartCallBack PtrUartCallBack, uint8_t IrqType, boolean Enable);
AnnaBridge 171:3a7713b1edbc 116 extern uint8_t fSerialGetc(Uart16C550Reg_pt UartRegBase);
AnnaBridge 171:3a7713b1edbc 117 extern void fSerialPutc(Uart16C550Reg_pt UartRegBase, uint8_t c);
AnnaBridge 171:3a7713b1edbc 118 extern boolean fSerialReadable(Uart16C550Reg_pt UartRegBase);
AnnaBridge 171:3a7713b1edbc 119 extern boolean fSerialWritable(Uart16C550Reg_pt UartRegBase);
AnnaBridge 171:3a7713b1edbc 120 extern void fSerialClear(Uart16C550Reg_pt UartRegBase);
AnnaBridge 171:3a7713b1edbc 121 extern void fSerialBreakSet(Uart16C550Reg_pt UartRegBase);
AnnaBridge 171:3a7713b1edbc 122 extern void fSerialBreakClear(Uart16C550Reg_pt UartRegBase);
AnnaBridge 171:3a7713b1edbc 123 extern void fSerialPinoutTx(uint8_t PinNo);
AnnaBridge 171:3a7713b1edbc 124
AnnaBridge 171:3a7713b1edbc 125 extern void Uart1_Irq(void);
AnnaBridge 171:3a7713b1edbc 126 extern void Uart2_Irq(void);
AnnaBridge 171:3a7713b1edbc 127
AnnaBridge 171:3a7713b1edbc 128 #endif /* UART_16C550_H_ */