1 /****************************************************************************
4 * Copyright 2012 Nathael Pajani <nathael.pajani@ed3l.fr>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *************************************************************************** */
21 #ifndef DRIVERS_SERIAL_H
22 #define DRIVERS_SERIAL_H
28 #define SERIAL_CAP_UART (1 << 0)
29 #define SERIAL_CAP_RS485 (1 << 1)
30 #define SERIAL_CAP_IRDA (1 << 2)
31 #define SERIAL_CAP_SMART_CARD (1 << 3)
33 #define SERIAL_MODE_UART SERIAL_CAP_UART
34 #define SERIAL_MODE_RS485 SERIAL_CAP_RS485
35 #define SERIAL_MODE_IRDA SERIAL_CAP_IRDA
36 #define SERIAL_MODE_SMART_CARD SERIAL_CAP_SMART_CARD
39 /* This buffer size is the maximum write size for a serial_printf or a uprintf call.
40 * Previously this value was 64, but it is often too short, so I set it to 96, which
41 * should be OK for most cases. In need of a bigger write buffer, change this value
42 * or perform multiple write calls (better).
44 #define SERIAL_OUT_BUFF_SIZE 96
47 /***************************************************************************** */
50 * Try to send at most "length" characters from "buf" on the requested uart.
51 * Returns -1 on error, or number of characters copied into output buffer, witch
52 * may be less than requested "length"
53 * Possible errors: requested uart does not exists or unable to acquire uart lock.
55 * Warning for Real Time : This implementation will block if there's already a
56 * transmission ongoing.
58 int serial_write(uint32_t uart_num, const char *buf, uint32_t length);
60 /***************************************************************************** */
63 * Wait until all characters have been sent
64 * Returns -1 on error, 0 on success.
65 * Possible errors: requested uart does not exists or unable to acquire uart lock.
67 * Warning for Real Time : This implementation will block if there's already a
68 * transmission ongoing.
70 int serial_flush(uint32_t uart_num);
74 /***************************************************************************** */
75 /* Public access to UART setup */
77 /* Change uart mode to RS485
78 * return -ENODEV when the device does not support RS485 mode.
80 int uart_set_mode_rs485(uint32_t uart_num, uint32_t control, uint8_t addr, uint8_t delay);
82 /* Change uart mode to IRDA
83 * return -ENODEV when the device does not support IrDA mode.
85 int uart_set_mode_irda(uint32_t uart_num, uint32_t control, uint16_t pulse_width);
87 /* Allow any change to the main clock to be forwarded to us */
88 void uart_clk_update(void);
90 /* Do we need to allow setting of other parameters ? (Other than 8n1) */
91 int uart_on(uint32_t uart_num, uint32_t baudrate, void (*rx_callback)(uint8_t));
93 void uart_off(uint32_t uart_num);
97 #endif /* DRIVERS_SERIAL_H */