📄 uartutil.h
字号:
/************************************************************************************
* Includes the UART Utils.
*
* (c) Copyright 2006, Freescale Semiconductor, Inc. All rights reserved.
*
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*
* Last Inspected:15.08.2006
* Last Tested:15.08.2006
*
************************************************************************************/
#ifndef _UART_UTIL_H_
#define _UART_UTIL_H_
#include "Uart_Interface.h"
/************************************************************************************
*************************************************************************************
* Private macros
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Private prototypes
*************************************************************************************/
/************************************************************************************
*************************************************************************************
* Private type definitions
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Private functions
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Public macros
*************************************************************************************
************************************************************************************/
/* Enable the Uart Utils module*/
#define gEnableUartUtil_c TRUE
/*Enable just the Uart Utils Tx functions*/
#define gEnableUartUtilTxFunctions_c TRUE
/* Enable just the Uart Utils Rx functions*/
#define gEnableUartUtilRxFunctions_c TRUE
/*list of possible baudrates for UartUtil module */
#define Baudrate_1200 gUARTBaudRate1200_c
#define Baudrate_2400 gUARTBaudRate2400_c
#define Baudrate_4800 gUARTBaudRate4800_c
#define Baudrate_9600 gUARTBaudRate9600_c
#define Baudrate_19200 gUARTBaudRate19200_c
#define Baudrate_38400 gUARTBaudRate38400_c
#define Baudrate_57600 gUARTBaudRate57600_c
#define Baudrate_115200 gUARTBaudRate115200_c
/* Set the Uart Baud Rate*/
#define gDefaultUartUtilBaudRate_c Baudrate_19200
/* The Cirular List length and the Packet length */
/* If the Circular Tx List is full and the user try to make a transmission,
the data will be lost; be careful how you choose the Circular Tx list length
for your needs and do not sent more than gUartCircListTxLen_c bytes using
consecutive prints */
#define gUartCircListTxLen_c 512
/*Maximum number of bytes which can be included in one MCPS data packet*/
#define gFullPacketLength_c 80
/* Define the Message length */
/* A message is defined as a sequence of caracters (up to gMessageLength_c) delimited by \r\n */
#define gMessageLength_c 15
/************************************************************************************
*************************************************************************************
* Public type definitions
*************************************************************************************
************************************************************************************/
/* If you have to print a hex number you can choose between
BigEndian=1/LittleEndian=0, newline, commas or spaces (between bytes) */
enum {
gPrtHexBigEndian_c = 1<<0,
gPrtHexNewLine_c = 1<<1,
gPrtHexCommas_c = 1<<2,
gPrtHexSpaces_c = 1<<3
};
/************************************************************************************
*************************************************************************************
* Public memory declarations
*************************************************************************************
************************************************************************************/
/************************************************************************************
*************************************************************************************
* Public functions
*************************************************************************************
************************************************************************************/
/************************************************************************************
* Function that initializes UART interface (i.e. UART) and set the baud rate.
*
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
void UartUtil_Init(uint16_t cBaudRate);
/************************************************************************************
* Function that prints out a string on the UART interface. String needs to be
* 0-terminated.
* If the Circular Tx List is full and the user called this function the
* data will be lost. Try to see if a transmission is pending before
* sending data or do not sent more than gUartCircListTxLen_c bytes using
* consecutive UartUtil_Print.
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
void UartUtil_Print(char * pString);
/************************************************************************************
* The UartUtil_ConfigureStopMode(bool_t enterStopMode) function will configure
* the UART before the MCU enters stop mode or after is exist stop mode based on
* boolean variable enterStopMode.
* Before entering stop mode the Rx line is placed in idle mode.
* After coming out of stop mode the functionality of the UART is restored
* ( enable Rx line ).
*
* Interface assumptions:
* enterStopMode
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
void UartUtil_ConfigureStopMode(bool_t enterStopMode);
/************************************************************************************
* Function that prints out one byte on the UART interface as a hexdecimal string.
* E.g. the byte 0x5E is printed as the string "5E". It is up to the user to add
* decorations before or after the string is printed.
* Example:
* UartUtil_Print("Number is: 0x");
* UartUtil_PrintHex(0x5E,1,0);
* UartUtil_Print("\r\n");
* This will result in "Number is 0x5E" being printed over the UART with line shift.
*
* Interface assumptions:
* None
*
* Return value:
* None
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
void UartUtil_PrintHex(uint8_t *hex, uint8_t len, uint8_t flags);
/************************************************************************************
* Function that sends data to the UART from the supplied buffer.
* If the Circular Tx List is full and the user called this function the
* data will be lost. Try to see if a transmission is pending before
* sending data or do not sent more than gUartCircListTxLen_c bytes using
* consecutive UartUtil_Tx.
*
* Interface assumptions:
* None
*
* Return value:
* Number of bytes copied to the buffer
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
void UartUtil_Tx(uint8_t * pData, uint8_t length);
/************************************************************************************
* Function that check if the data is pending to be sent.
*
* Interface assumptions:
* None
*
* Return value:
* TRUE if the data is not pending, else FALSE ( data is pending ).
*
* Revision history:
* date Author Comments
* ------ ------- --------
* 160806 Aliciuc Created
*
************************************************************************************/
uint8_t UartUtil_IsNotPendingTx(void);
/******************************************************************************
* The UartUtil_CheckIdle(void) function will check if UART TX buffer is empty and .
* no characters are pending for transmission.
*
* Interface assumptions:
* None
*
* Return value:
* TRUE: Buffer empty and no characters pending to be sent;
* FALSE: Buffer not empty or characters pending to be sent;
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
bool_t UartUtil_CheckIdle(void);
/************************************************************************************
* Function that copies data received from the UART to the supplied buffer. A timeout
* ( gUART_RxTimeout_c = 100 ms from Uart module) ensures that this function will
* return if no data or only a partial buffer is available within a short time frame.
*
* Interface assumptions:
* None
*
* Return value:
* Number of bytes copied to the buffer
*
* Revision history:
* date Author Comments
* ------ ------ --------
* 110806 Aliciuc Created
*
************************************************************************************/
uint8_t UartUtil_Poll(uint8_t * pBuffer);
/************************************************************************************
* Function that copies one message received from the UART to the supplied buffer.
* A message is defined as a sequence of caracters (up to gMessageLength_c) delimited by \r\n.
*
*
* Interface assumptions:
* None
*
* Return value:
* Number of bytes copied to the buffer
*
* Revision history:
* date Author Comments
* ------ ------- --------
* 150806 Aliciuc Created
*
************************************************************************************/
uint8_t UartUtil_PollMessage(uint8_t * pBuffer);
#endif /* _UART_UTIL_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -