You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

142 lines
3.2 KiB

#ifndef __HWSERIAL_H__
#define __HWSERIAL_H__
#include <stddef.h>
#include <stdint.h>
#include "config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define TX_BUFFER_SIZE 128
#define RX_BUFFER_SIZE 256
struct serial;
#define SERIAL_STOPBITS_1 (0x0)
#define SERIAL_STOPBITS_0_5 (0x1000)
#define SERIAL_STOPBITS_2 (0x2000)
#define SERIAL_STOPBITS_1_5 (0x3000)
#define SERIAL_PARITY_NO (0x0000)
#define SERIAL_PARITY_EVEN (0x0400)
#define SERIAL_PARITY_ODD (0x0600)
void serial_setup(struct serial *uart, int baudrate, int databits, int stopbits);
void serial_reconfigure(struct serial *uart, int baudrate, int databits, int stopbits, int parity);
void serial_close(struct serial *uart);
size_t serial_send_buffered(struct serial *uart, const uint8_t* data, size_t num_bytes);
size_t serial_send_blocking(struct serial *uart, const uint8_t *data, size_t num);
size_t serial_recv_buffered(struct serial *uart, uint8_t* data, size_t max_bytes);
size_t serial_recv_blocking(struct serial *uart, uint8_t* data, size_t max_bytes);
int serial_getchar(struct serial *uart);
int serial_peekchar(struct serial *uart);
int serial_rx_size(struct serial *uart);
void serial_rx_buffer_clear(struct serial *uart);
void serial_tx_buffer_clear(struct serial *uart);
size_t serial_send_buffer_space(struct serial *uart);
/* USART1 */
#if (TARGET_HAS_USART1)
#ifndef TARGET_USART1_RX_BUFFER_SIZE
#define TARGET_USART1_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART1_TX_BUFFER_SIZE
#define TARGET_USART1_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial0;
#endif
/* USART2 */
#if (TARGET_HAS_USART2)
#ifndef TARGET_USART2_RX_BUFFER_SIZE
#define TARGET_USART2_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART2_TX_BUFFER_SIZE
#define TARGET_USART2_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial1;
#endif
/* USART3 */
#if (TARGET_HAS_USART3)
#ifndef TARGET_USART3_RX_BUFFER_SIZE
#define TARGET_USART3_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART3_TX_BUFFER_SIZE
#define TARGET_USART3_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial2;
#endif
/* UART4 */
#if (TARGET_HAS_USART4)
#ifndef TARGET_USART4_RX_BUFFER_SIZE
#define TARGET_USART4_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART4_TX_BUFFER_SIZE
#define TARGET_USART4_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial3;
#endif
/* UART5 */
#if (TARGET_HAS_USART5)
#ifndef TARGET_USART5_RX_BUFFER_SIZE
#define TARGET_USART5_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART5_TX_BUFFER_SIZE
#define TARGET_USART5_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial4;
#endif
/* USART6 */
#if (TARGET_HAS_USART6)
#ifndef TARGET_USART6_RX_BUFFER_SIZE
#define TARGET_USART6_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART6_TX_BUFFER_SIZE
#define TARGET_USART6_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial5;
#endif
/* UART7 */
#if (TARGET_HAS_USART7)
#ifndef TARGET_USART7_RX_BUFFER_SIZE
#define TARGET_USART7_RX_BUFFER_SIZE RX_BUFFER_SIZE
#endif
#ifndef TARGET_USART7_TX_BUFFER_SIZE
#define TARGET_USART7_TX_BUFFER_SIZE TX_BUFFER_SIZE
#endif
extern struct serial serial6;
#endif
#ifdef __cplusplus
}
#endif
#endif