|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2006-2013 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +// math.h required for floating point operations for baud rate calculation |
| 17 | +#include <math.h> |
| 18 | +#include <stdio.h> |
| 19 | +#include <string.h> |
| 20 | +#include <stdlib.h> |
| 21 | +#include "mbed_assert.h" |
| 22 | + |
| 23 | +#include "serial_api.h" |
| 24 | +#include "cmsis.h" |
| 25 | +#include "pinmap.h" |
| 26 | +#include "mbed_error.h" |
| 27 | +#include "gpio_api.h" |
| 28 | + |
| 29 | +/****************************************************************************** |
| 30 | + * INITIALIZATION |
| 31 | + ******************************************************************************/ |
| 32 | +#define UART_NUM 2 |
| 33 | + |
| 34 | +// http://dev.ti.com/tirex/content/simplelink_cc32xx_sdk_1_40_00_03/docs/tidrivers/doxygen/html/_u_a_r_t_c_c32_x_x_8h.html |
| 35 | + |
| 36 | +static const PinMap PinMap_UART_TX[] = { |
| 37 | + {PIN_01, UART_1, 0}, |
| 38 | + {PIN_03, UART_0, 0}, |
| 39 | + {PIN_07, UART_1, 0}, |
| 40 | + {PIN_16, UART_1, 0}, |
| 41 | + {PIN_53, UART_0, 0}, |
| 42 | + {PIN_55, UART_1, 0}, |
| 43 | + {PIN_58, UART_1, 0}, |
| 44 | + {PIN_62, UART_0, 0}, |
| 45 | + {NC, NC, 0} |
| 46 | +}; |
| 47 | + |
| 48 | +static const PinMap PinMap_UART_RX[] = { |
| 49 | + {PIN_02, UART_1, 0}, |
| 50 | + {PIN_04, UART_0, 0}, |
| 51 | + {PIN_08, UART_1, 0}, |
| 52 | + {PIN_17, UART_1, 0}, |
| 53 | + {PIN_45, UART_0, 0}, |
| 54 | + {PIN_45, UART_1, 0}, |
| 55 | + {PIN_57, UART_0, 0}, |
| 56 | + {PIN_57, UART_1, 0}, |
| 57 | + {PIN_59, UART_1, 0}, |
| 58 | + {NC, NC, 0} |
| 59 | +}; |
| 60 | + |
| 61 | +static const PinMap PinMap_UART_RTS[] = { |
| 62 | + {PIN_50, UART_0, 0}, |
| 63 | + {PIN_50, UART_1, 0}, |
| 64 | + {PIN_52, UART_0, 0}, |
| 65 | + {PIN_61, UART_0, 0}, |
| 66 | + {PIN_62, UART_0, 0}, |
| 67 | + {PIN_62, UART_1, 0}, |
| 68 | + {NC, NC, 0} |
| 69 | +}; |
| 70 | + |
| 71 | +static const PinMap PinMap_UART_CTS[] = { |
| 72 | + {PIN_50, UART_0, 0}, |
| 73 | + {PIN_61, UART_0, 0}, |
| 74 | + {PIN_61, UART_1, 0}, |
| 75 | + {NC, NC, 0} |
| 76 | +}; |
| 77 | + |
| 78 | +static uart_irq_handler irq_handler; |
| 79 | + |
| 80 | +int stdio_uart_inited = 0; |
| 81 | +serial_t stdio_uart; |
| 82 | + |
| 83 | +struct serial_global_data_s { |
| 84 | + uint32_t serial_irq_id; |
| 85 | + gpio_t sw_rts, sw_cts; |
| 86 | + uint8_t count, rx_irq_set_flow, rx_irq_set_api; |
| 87 | +}; |
| 88 | + |
| 89 | +static struct serial_global_data_s uart_data[UART_NUM]; |
| 90 | + |
| 91 | +void serial_init(serial_t *obj, PinName tx, PinName rx) { |
| 92 | + int is_stdio_uart = 0; |
| 93 | + |
| 94 | + // determine the UART to use |
| 95 | + UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); |
| 96 | + UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); |
| 97 | + UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); |
| 98 | + MBED_ASSERT((int)uart != NC); |
| 99 | + |
| 100 | + // TODO |
| 101 | +} |
| 102 | + |
| 103 | +void serial_free(serial_t *obj) { |
| 104 | + uart_data[obj->index].serial_irq_id = 0; |
| 105 | +} |
| 106 | + |
| 107 | +// serial_baud |
| 108 | +// set the baud rate, taking in to account the current SystemFrequency |
| 109 | +void serial_baud(serial_t *obj, int baudrate) { |
| 110 | + // TODO |
| 111 | +} |
| 112 | + |
| 113 | +void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { |
| 114 | + // TODO |
| 115 | +} |
| 116 | + |
| 117 | +/****************************************************************************** |
| 118 | + * INTERRUPTS HANDLING |
| 119 | + ******************************************************************************/ |
| 120 | +void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { |
| 121 | + // TODO |
| 122 | +} |
| 123 | + |
| 124 | +static void serial_irq_set_internal(serial_t *obj, SerialIrq irq, uint32_t enable) { |
| 125 | + // TODO |
| 126 | +} |
| 127 | + |
| 128 | +void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { |
| 129 | + // TODO |
| 130 | +} |
| 131 | + |
| 132 | +static void serial_flow_irq_set(serial_t *obj, uint32_t enable) { |
| 133 | + // TODO |
| 134 | +} |
| 135 | + |
| 136 | +/****************************************************************************** |
| 137 | + * READ/WRITE |
| 138 | + ******************************************************************************/ |
| 139 | +int serial_getc(serial_t *obj) { |
| 140 | + // TODO |
| 141 | + return 1; |
| 142 | +} |
| 143 | + |
| 144 | +void serial_putc(serial_t *obj, int c) { |
| 145 | + // TODO |
| 146 | +} |
| 147 | + |
| 148 | +int serial_readable(serial_t *obj) { |
| 149 | + // TODO |
| 150 | + return 1; |
| 151 | +} |
| 152 | + |
| 153 | +int serial_writable(serial_t *obj) { |
| 154 | + // TODO |
| 155 | + return 1; |
| 156 | +} |
| 157 | + |
| 158 | +void serial_clear(serial_t *obj) { |
| 159 | + // TODO |
| 160 | +} |
| 161 | + |
| 162 | +void serial_pinout_tx(PinName tx) { |
| 163 | + pinmap_pinout(tx, PinMap_UART_TX); |
| 164 | +} |
| 165 | + |
| 166 | +void serial_break_set(serial_t *obj) { |
| 167 | + // TODO |
| 168 | +} |
| 169 | + |
| 170 | +void serial_break_clear(serial_t *obj) { |
| 171 | + // TODO |
| 172 | +} |
| 173 | + |
| 174 | +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) { |
| 175 | + // TODO |
| 176 | +} |
0 commit comments