📄 hal_uart.h
字号:
/*********************************************************************
Filename: hal_uart.h
Revised: $Date: 2005/04/29 01:36:04 $
Revision: $Revision$
Description:
This file contains the interface to the UART Service.
Notes:
Copyright (c) 2006 by Texas Instruments, Inc.
All Rights Reserved. Permission to use, reproduce, copy, prepare
derivative works, modify, distribute, perform, display or sell this
software and/or its documentation for any purpose is prohibited
without the express written consent of Texas Instruments, Inc.
*********************************************************************/
#ifndef HAL_UART_H
#define HAL_UART_H
#ifdef __cplusplus
extern "C"
{
#endif
/***************************************************************************************************
* INCLUDES
***************************************************************************************************/
#include "hal_board.h"
/***************************************************************************************************
* MACROS
***************************************************************************************************/
/***************************************************************************************************
* CONSTANTS
***************************************************************************************************/
/* UART Ports */
/*
Serial Port Baudrate Settings
Have to match with baudrate table
*/
#define HAL_UART_BR_1200 0x00
#define HAL_UART_BR_2400 0x01
#define HAL_UART_BR_4800 0x02
#define HAL_UART_BR_9600 0x03
#define HAL_UART_BR_19200 0x04
#define HAL_UART_BR_31250 0x05
#define HAL_UART_BR_38400 0x06
#define HAL_UART_BR_57600 0x07
#define HAL_UART_BR_115200 0x08
/* Frame Format constant */
/* Stop Bits */
#define HAL_UART_ONE_STOP_BIT 0x00
#define HAL_UART_TWO_STOP_BITS 0x01
/* Parity settings */
#define HAL_UART_NO_PARITY 0x00
#define HAL_UART_EVEN_PARITY 0x01
#define HAL_UART_ODD_PARITY 0x02
/* Character Size */
#define HAL_UART_8_BITS_PER_CHAR 0x00
#define HAL_UART_9_BITS_PER_CHAR 0x01
/* Flow control */
#define HAL_UART_FLOW_OFF 0x00
#define HAL_UART_FLOW_ON 0x01
/* Ports */
#define HAL_UART_PORT_0 0x00
#define HAL_UART_PORT_1 0x01
#define HAL_UART_PORT_MAX 0x02
/* UART Status */
#define HAL_UART_SUCCESS 0x00
#define HAL_UART_UNCONFIGURED 0x01
#define HAL_UART_NOT_SUPPORTED 0x02
#define HAL_UART_MEM_FAIL 0x03
#define HAL_UART_BAUDRATE_ERROR 0x04
/* UART Events */
#define HAL_UART_RX_FULL 0x01
#define HAL_UART_RX_ABOUT_FULL 0x02
#define HAL_UART_RX_TIMEOUT 0x04
#define HAL_UART_TX_FULL 0x08
/***************************************************************************************************
* TYPEDEFS
***************************************************************************************************/
typedef void (*halUARTCBack_t) (uint8 port, uint8 event);
typedef struct
{
uint16 bufferHead;
uint16 bufferTail;
uint16 maxBufSize;
uint8 *pBuffer;
}halUARTBufControl_t;
typedef struct
{
bool configured;
uint8 baudRate;
bool flowControl;
uint16 flowControlThreshold;
uint8 idleTimeout;
halUARTBufControl_t rx;
halUARTBufControl_t tx;
bool intEnable;
uint32 rxChRvdTime;
halUARTCBack_t callBackFunc;
}halUARTCfg_t;
typedef union
{
bool paramCTS;
bool paramRTS;
bool paramDSR;
bool paramDTR;
bool paramCD;
bool paramRI;
uint16 baudRate;
bool flowControl;
bool flushControl;
}halUARTIoctl_t;
/***************************************************************************************************
* GLOBAL VARIABLES
***************************************************************************************************/
/***************************************************************************************************
* FUNCTIONS - API
***************************************************************************************************/
/*
* Initialize UART at the startup
*/
extern void HalUARTInit ( void );
/*
* Open a port based on the configuration
*/
extern uint8 HalUARTOpen ( uint8 port, halUARTCfg_t *config );
/*
* Close a port
*/
extern void HalUARTClose ( uint8 port );
/*
* Read a buffer from the UART
*/
extern uint16 HalUARTRead ( uint8 port, uint8 *pBuffer, uint16 length );
/*
* Write a buff to the uart *
*/
extern uint16 HalUARTWrite ( uint8 port, uint8 *pBuffer, uint16 length );
/*
* Write a buffer to the UART
*/
extern uint8 HalUARTIoctl ( uint8 port, uint8 cmd, halUARTIoctl_t *pIoctl );
/*
* This to support polling
*/
extern void HalUARTPoll( void );
/*
* Return the number of bytes in the Rx buffer
*/
extern uint16 Hal_UART_RxBufLen ( uint8 port );
/*
* Return the number of bytes in the Tx buffer
*/
extern uint16 Hal_UART_TxBufLen ( uint8 port );
/*
* This enable/disable flow control
*/
extern void Hal_UART_FlowControlSet ( uint8 port, bool status );
/*
* Initialize hardware for UART
*/
extern uint8 HalUART_HW_Init(uint8 port);
/***************************************************************************************************
***************************************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -