109 lines
3.1 KiB
C
109 lines
3.1 KiB
C
|
/****************************************************************************
|
||
|
|
||
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||
|
|
||
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||
|
be copied by any method or incorporated into another program without
|
||
|
the express written consent of Aerospace C.Power. This Information or any portion
|
||
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||
|
liability for its use in any way and conveys no license or title under
|
||
|
any patent or copyright and makes no representation or warranty that this
|
||
|
Information is free from patent or copyright infringement.
|
||
|
|
||
|
****************************************************************************/
|
||
|
|
||
|
#ifndef _APP_UART_H_
|
||
|
#define _APP_UART_H_
|
||
|
|
||
|
#include "app_flash.h"
|
||
|
#include "app_types.h"
|
||
|
#include "app_common.h"
|
||
|
|
||
|
/* the buffer size for uart receive frame */
|
||
|
#define UART_RCV_BUF_LEN (1024)
|
||
|
/* cache uart recv buffer */
|
||
|
#define UART_BUF_MAX_LEN (800)
|
||
|
/* uart recv data timeout, clearn. unit is ms */
|
||
|
#define UART_RECV_TIMEOUT (1000)
|
||
|
|
||
|
typedef struct _uart_handle_buffer {
|
||
|
/* buffer handle */
|
||
|
uint16_t handle;
|
||
|
/* buffer length */
|
||
|
uint16_t buff_len;
|
||
|
/* run time */
|
||
|
uint32_t boot_tm;
|
||
|
/* temp buffer */
|
||
|
uint8_t *buff_tmp;
|
||
|
} uart_handle_buffer;
|
||
|
|
||
|
/**
|
||
|
* @brief app_uart_is_valid() - check uart param is valid.
|
||
|
*
|
||
|
* @param [in] baudrate: baud rate.
|
||
|
* @param [in] data_bits: data bits:5,6,7,8.
|
||
|
* @param [in] stop_bits: stop bits:1,1.5,2.
|
||
|
* @param [in] parity: parity,NONE:0, ODD:1,EVEN:2.
|
||
|
* @param [in] thresholdvalue: threshold value,20-1000.
|
||
|
*
|
||
|
* @return true: succeeded;
|
||
|
* @return false: failed;
|
||
|
*/
|
||
|
uint8_t app_uart_is_valid(uint32_t baudrate, uint8_t data_bits,
|
||
|
uint8_t stop_bits, uint8_t parity, uint32_t thresholdvalue);
|
||
|
|
||
|
/**
|
||
|
* @brief app_uart_tx() - send data to uart.
|
||
|
*
|
||
|
* @param [in] hdl: uart handle.
|
||
|
* @param [in] data: data will be send uart.
|
||
|
* @param [in] data_length: data length.
|
||
|
*
|
||
|
* @return 0: succeeded;
|
||
|
* @return others: failed;
|
||
|
*/
|
||
|
uint16_t app_uart_tx(iot_uart_h hdl, uint8_t *data, uint16_t data_length);
|
||
|
|
||
|
/**
|
||
|
* @brief app_uart_buf_clear() - clearn buffer.
|
||
|
*
|
||
|
* @param None.
|
||
|
*
|
||
|
* @return None.
|
||
|
*/
|
||
|
void app_uart_buf_clear(void);
|
||
|
|
||
|
/**
|
||
|
* @brief app_get_uart_buf_info() - get golbal uart info.
|
||
|
*
|
||
|
* @param None.
|
||
|
*
|
||
|
* @return uart info, point to g_uart_buffer;
|
||
|
*/
|
||
|
uart_handle_buffer *app_get_uart_buf_info(void);
|
||
|
|
||
|
/**
|
||
|
* @brief app_uart_reassign_pin() - set uart port tx/rx pin before iot_uart_open.
|
||
|
*
|
||
|
* @param [in] port: open port, see IOT_UART_PORTXXX,as IOT_UART_PORT0.
|
||
|
* @param [in] rx_pin: define uart rx pin.
|
||
|
* @param [in] tx_pin: define uart tx pin.
|
||
|
*
|
||
|
* @return 0: succeeded;
|
||
|
* @return others: failed;
|
||
|
*/
|
||
|
uint8_t app_uart_reassign_pin(uint8_t port, uint8_t rx_pin, uint8_t tx_pin);
|
||
|
|
||
|
/**
|
||
|
* @brief app_uart_init() - uart init.
|
||
|
*
|
||
|
* @param [out] uart_handle: open uart, return handle.
|
||
|
*
|
||
|
* @return 0: succeeded;
|
||
|
* @return others: failed;
|
||
|
*/
|
||
|
uint16_t app_uart_init(iot_uart_h *uart_handle);
|
||
|
|
||
|
#endif /* _APP_UART_H_ */
|