2014-12-22 12:35:05 +01:00
|
|
|
#ifndef UART_APP_H
|
|
|
|
#define UART_APP_H
|
|
|
|
|
|
|
|
#include "uart_register.h"
|
|
|
|
#include "eagle_soc.h"
|
2019-07-23 06:22:38 +02:00
|
|
|
#include <stdint.h>
|
2015-10-08 04:33:15 +02:00
|
|
|
#include "os_type.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
#define RX_BUFF_SIZE 0x100
|
|
|
|
#define TX_BUFF_SIZE 100
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FIVE_BITS = 0x0,
|
|
|
|
SIX_BITS = 0x1,
|
|
|
|
SEVEN_BITS = 0x2,
|
|
|
|
EIGHT_BITS = 0x3
|
|
|
|
} UartBitsNum4Char;
|
|
|
|
|
|
|
|
typedef enum {
|
2015-12-14 20:17:04 +01:00
|
|
|
ONE_STOP_BIT = 0x1,
|
|
|
|
ONE_HALF_STOP_BIT = 0x2,
|
|
|
|
TWO_STOP_BIT = 0x3
|
2014-12-22 12:35:05 +01:00
|
|
|
} UartStopBitsNum;
|
|
|
|
|
|
|
|
typedef enum {
|
2015-12-14 20:17:04 +01:00
|
|
|
NONE_BITS = 0x2,
|
|
|
|
ODD_BITS = 1,
|
|
|
|
EVEN_BITS = 0
|
2014-12-22 12:35:05 +01:00
|
|
|
} UartParityMode;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
STICK_PARITY_DIS = 0,
|
2015-12-14 20:17:04 +01:00
|
|
|
STICK_PARITY_EN = 1
|
2014-12-22 12:35:05 +01:00
|
|
|
} UartExistParity;
|
|
|
|
|
|
|
|
typedef enum {
|
2015-02-10 15:39:50 +01:00
|
|
|
BIT_RATE_300 = 300,
|
|
|
|
BIT_RATE_600 = 600,
|
|
|
|
BIT_RATE_1200 = 1200,
|
|
|
|
BIT_RATE_2400 = 2400,
|
|
|
|
BIT_RATE_4800 = 4800,
|
|
|
|
BIT_RATE_9600 = 9600,
|
2014-12-22 12:35:05 +01:00
|
|
|
BIT_RATE_19200 = 19200,
|
2017-01-04 12:31:47 +01:00
|
|
|
BIT_RATE_31250 = 31250,
|
2014-12-22 12:35:05 +01:00
|
|
|
BIT_RATE_38400 = 38400,
|
|
|
|
BIT_RATE_57600 = 57600,
|
|
|
|
BIT_RATE_74880 = 74880,
|
2015-02-10 15:39:50 +01:00
|
|
|
BIT_RATE_115200 = 115200,
|
|
|
|
BIT_RATE_230400 = 230400,
|
|
|
|
BIT_RATE_256000 = 256000,
|
|
|
|
BIT_RATE_460800 = 460800,
|
|
|
|
BIT_RATE_921600 = 921600,
|
|
|
|
BIT_RATE_1843200 = 1843200,
|
|
|
|
BIT_RATE_3686400 = 3686400,
|
2014-12-22 12:35:05 +01:00
|
|
|
} UartBautRate;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NONE_CTRL,
|
|
|
|
HARDWARE_CTRL,
|
|
|
|
XON_XOFF_CTRL
|
|
|
|
} UartFlowCtrl;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
EMPTY,
|
|
|
|
UNDER_WRITE,
|
|
|
|
WRITE_OVER
|
|
|
|
} RcvMsgBuffState;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32 RcvBuffSize;
|
|
|
|
uint8 *pRcvMsgBuff;
|
|
|
|
uint8 *pWritePos;
|
|
|
|
uint8 *pReadPos;
|
|
|
|
uint8 TrigLvl; //JLU: may need to pad
|
|
|
|
RcvMsgBuffState BuffState;
|
|
|
|
} RcvMsgBuff;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32 TrxBuffSize;
|
|
|
|
uint8 *pTrxBuff;
|
|
|
|
} TrxMsgBuff;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BAUD_RATE_DET,
|
|
|
|
WAIT_SYNC_FRM,
|
|
|
|
SRCH_MSG_HEAD,
|
|
|
|
RCV_MSG_BODY,
|
|
|
|
RCV_ESC_CHAR,
|
|
|
|
} RcvMsgState;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UartBautRate baut_rate;
|
|
|
|
UartBitsNum4Char data_bits;
|
|
|
|
UartExistParity exist_parity;
|
|
|
|
UartParityMode parity; // chip size in byte
|
|
|
|
UartStopBitsNum stop_bits;
|
|
|
|
UartFlowCtrl flow_ctrl;
|
|
|
|
RcvMsgBuff rcv_buff;
|
|
|
|
TrxMsgBuff trx_buff;
|
|
|
|
RcvMsgState rcv_state;
|
|
|
|
int received;
|
|
|
|
int buff_uart_no; //indicate which uart use tx/rx buffer
|
|
|
|
} UartDevice;
|
|
|
|
|
2016-12-11 20:35:04 +01:00
|
|
|
typedef struct {
|
|
|
|
UartBautRate baut_rate;
|
|
|
|
UartBitsNum4Char data_bits;
|
|
|
|
UartExistParity exist_parity;
|
2019-02-17 19:26:29 +01:00
|
|
|
UartParityMode parity;
|
2016-12-11 20:35:04 +01:00
|
|
|
UartStopBitsNum stop_bits;
|
|
|
|
} UartConfig;
|
|
|
|
|
2016-10-18 03:56:38 +02:00
|
|
|
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input, uint8 *flag_input);
|
2016-12-11 20:35:04 +01:00
|
|
|
UartConfig uart_get_config(uint8 uart_no);
|
2015-11-28 23:51:01 +01:00
|
|
|
void uart0_alt(uint8 on);
|
2014-12-22 12:35:05 +01:00
|
|
|
void uart0_sendStr(const char *str);
|
|
|
|
void uart0_putc(const char c);
|
|
|
|
void uart0_tx_buffer(uint8 *buf, uint16 len);
|
|
|
|
void uart_setup(uint8 uart_no);
|
|
|
|
STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
|
2016-09-21 03:38:12 +02:00
|
|
|
void uart_set_alt_output_uart0(void (*fn)(char));
|
2014-12-22 12:35:05 +01:00
|
|
|
#endif
|
|
|
|
|