⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.h

📁 手机底层驱动程序
💻 H
字号:
#ifndef __UART_H__
#define __UART_H__

#include "bspUsart.h"
#include "USB_VSP.h"

typedef unsigned char  SYS_BOOL;

typedef unsigned char  SYS_UWORD8;
typedef signed   char  SYS_WORD8;

typedef unsigned short SYS_UWORD16;
typedef          short SYS_WORD16;

typedef unsigned long  SYS_UWORD32;

typedef enum {
    TR_BAUD_9600 = 0,
    TR_BAUD_19200,
    TR_BAUD_28800,
    TR_BAUD_38400,
    TR_BAUD_57600,    
    TR_BAUD_115200
} T_tr_Baudrate;

#define BUFFER_SIZE (2048) /* In bytes. */
#define FIFO_SIZE    (64) /* In bytes. */

#define STX                  0x02
#define DLE                  0x10
#define NUMBER_OF_TR_UART (1)

#define USB_UART_ID	0
/*--------------------------------------------------------------
 Name: UA_Init    
 Description: Initializes the module and the UART.
 Parameter: 
          uart_id : UART id.
          baudrate: baud rate selected.
          callback: user's function called characters are received.   
 Return: None          
//--------------------------------------------------------------*/
void UA_Init (T_tr_UartId uart_id,
              T_tr_Baudrate baudrate,
              void (callback_function (void)));

/*--------------------------------------------------------------
 Name: UA_ReadNChars 
 Description: Reads N characters from the RX buffer.
 Parameter: 
          uart_id      : UART id.
          buffer       : buffer address where the characters are copied.
          chars_to_read: number of characters to read.
 Return: The number of bytes read.         
//--------------------------------------------------------------*/
SYS_UWORD32 UA_ReadNChars (T_tr_UartId uart_id,
                           char *buffer,
                           SYS_UWORD32 chars_to_read);

/*--------------------------------------------------------------
 Name: UA_ReadNBytes 
 Description: Reads and destuff N bytes from the RX buffer. 
 Parameter: 
          uart_id      : UART id.
          buffer       : buffer address where the bytes are copied.
          chars_to_read: number of bytes to read.
          BspViking_Tsp_Llif_Spi_ClockEdge    activeClockEdge      
 Return: The number of bytes read.        
//--------------------------------------------------------------*/

SYS_UWORD32 UA_ReadNBytes (T_tr_UartId uart_id,
                           char *buffer,
                           SYS_UWORD32 bytes_to_read,
                           SYS_BOOL *eof_detected);

/*--------------------------------------------------------------
 Name: UA_WriteNChars    
 Description: Writes N characters in the TX FIFO. 
 Parameter: 
          uart_id       : UART id.
          buffer        : buffer address from which characters are
                          written.
          bytes_to_write: number of bytes to write. 
Return: Number of bytes written.         
//--------------------------------------------------------------*/
SYS_UWORD32 UA_WriteNChars (T_tr_UartId uart_id,
                            char *buffer,
                            SYS_UWORD32 chars_to_write);

/*******************************************************************************
 *
 *                           UA_EncapsulateNChars
 * 
 * Purpose  : Writes N characters in the TX FIFO in encapsulating them with 2
 *            STX bytes (one at the beginning and one at the end).
 *
 * Arguments: In : uart_id       : UART id.
 *                 buffer        : buffer address from which characters are
 *                                 written.
 *                 chars_to_write: number of chars to write.
 *            Out: none
 *
 * Returns  : Number of chars written.
 *
 * Warning: Parameters are not verified.
 *
 ******************************************************************************/

SYS_UWORD32 UA_EncapsulateNChars (T_tr_UartId uart_id,
                                  char *buffer,
                                  SYS_UWORD32 chars_to_write);

/*--------------------------------------------------------------
 Name: UA_WriteNBytes     
 Description:  Writes N bytes in the TX FIFO in encapsulating with 2 STX bytes
               at the beginning and the end of the frame, and in making byte
               stuffing. Used for FRAMING_PROTOCOL
 Parameter: 
  	    uart_id       : UART id.
           buffer        : buffer address from which bytes are
                           written.
           bytes_to_write: number of bytes to write.
 Return: None          
//--------------------------------------------------------------*/
SYS_UWORD32 UA_WriteNBytes (T_tr_UartId uart_id, 
                            SYS_UWORD8 *buffer, 
                            SYS_UWORD32 bytes_to_write);
                
/*--------------------------------------------------------------
 Name: UA_WriteChar   
 Description: Writes a character in the TX FIFO.
 Parameter: 
          uart: UART id.   
	   char character
 Return: None          
//--------------------------------------------------------------*/
void UA_WriteChar (T_tr_UartId uart_id,
                   char character);

/*--------------------------------------------------------------
 Name: UA_WriteString    
 Description: Writes a null terminated string in the TX FIFO.
 Parameter: 
          uart_id: UART id.
          buffer : buffer address from which characters are written.
 Return: None          
//--------------------------------------------------------------*/
void UA_WriteString (T_tr_UartId uart_id,
                     char *buffer);

/*--------------------------------------------------------------
 Name: UA_EnterSleep    
 Description: enable UART sleep mode.
 Parameter: 
          T_tr_UartId uart_id   
 Return: None          
//--------------------------------------------------------------*/
SYS_BOOL UA_EnterSleep (T_tr_UartId uart_id);

/*--------------------------------------------------------------
 Name: UA_WakeUp   
 Description: Wakes up UART after Deep Sleep.
 Parameter: 
          T_tr_UartId uart_id
 Return: None          
//--------------------------------------------------------------*/
void UA_WakeUp (T_tr_UartId uart_id);

/*--------------------------------------------------------------
 Name: bsp_Usart_rxCallback   
 Description: Copies data from BSP_USART buffer to RX buffer
 Parameter: 
           irq                :  if irq set to TRUE otherwise FALSE 
           reinstallPtr       :  Reinstall pointer for reinstall after each thresh-hold 
           cb                 :  Circular buffer for data manupulation.  
           numBytesAvailable  :  Number of byte availabe in circular buffer. 
           state              :  which state the UART is. 
           CommPort           :  which UART. 
 Return: None          
//--------------------------------------------------------------*/
static BspUsart_ResultCode
bsp_Usart_rxCallback( Uint16                  irq,
                                    BspUsart_ReInstallMode *reinstallPtr, 
                                    BspUtil_CircBuf_Handle cb,                                    
                                    Uint16 	               numBytesAvailable, 
                                    BspUsart_State         state,
                                    BspUsart_Id            CommPort );

unsigned 
bsp_USB_rxCallback_pco(void);

SYS_UWORD32 UA_EncapsulateNChars (T_tr_UartId uart_id,
								char *buffer,
								SYS_UWORD32 chars_to_write);

extern unsigned
LOCALtoUSB_Write(
	unsigned iPort,
	unsigned char *pBuffer,
	unsigned nBuffer
	);

extern unsigned
LOCALtoUSB_Read(
	unsigned iPort,
	unsigned char *pBuffer,
	unsigned nBuffer
	);

extern unsigned
LOCALtoUSB_IsPortReady(
	unsigned iPort
	);

extern unsigned
LOCALtoUSB_GetBufferSizeToRead(
	unsigned iPort
	);

/* MCCI USBSERI API includes */
static void * pUSBDeviceObject = NULL;

extern void *
USB_OpenDevice(
	unsigned		/*instance*/
	);

extern void
USB_CloseDevice(
	void *			/*hPort returned by USB_OpenDevice*/
	);

extern unsigned short
USB_Read(
	void *			/*hPort*/,
	unsigned char *		/*pBuffer*/,
	unsigned short		/*nBuffer*/
	);

extern unsigned short
USB_Write(
	void *			/*hPort*/,
	const unsigned char *	/*pBuffer*/,
	unsigned short		/*dataSize*/
	);

extern int
USB_EnableRxDataFlow(
	void *			/*hPort*/,
	int			/*bool: enable*/
	);

extern unsigned
USB_QueryDtrRts(
	void *			/*hPort*/
	);

extern unsigned short
USB_QueryFreeTxSpace(
	void *			/*hPort*/
	);

extern void
USB_SetClearModemStatus(
	void *			/*hPort*/,
	unsigned int		/*mask*/,
	unsigned int		/*state*/
	);

#endif /* __UART_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -