EL4121 Embedded System / mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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