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

📄 iekc64_uart.h

📁 一个小的测试程序
💻 H
字号:

#ifndef _IEK_UART_H_
#define _IEK_UART_H_

#include <csl_stdinc.h>
#include <csl_mcbsp.h>

#include "iekc64.h"
#include "iekc64_error.h"



#ifdef __cplusplus
extern "C" {
#endif

/*=======================================================================*//*!
\defgroup UART UART - Uart port manager

	\brief This module provides an unified API for serial port : RS232.

	<b> How does it work </b>

		The UART - RS232 module acquires and plays frame according to the configuration defined 
		in IEKC64_UART_CONFIG structure. You must use the default configuration, 
		IEKC64_UART_STRUCT_DEFAULT, to initialize your own configuration but the 
		fields RxBufferSize, TxBufferSize, pRxBuffer and pTxBuffer must be set 
		before calling the UART_open() function.
		The default configuration structure field description is:

<small>
   dwSize = sizeof(IEKC64_UART_CONFIG) <br>
   BaudRate = UART_19200BDS <br>
   Parity = UART_NO_PARITY <br>
   RxBufferSize = 0 <br>
   TxBufferSize = 0 <br>
   pRxBuffer = NULL <br>
   pTxBuffer = NULL <br>
</small>
		
		For both, receive and transmit, Bytes are allocated contiguously in input and output FIFO
		respectively allocated by the user before openning the module.
		
		
	<b> Openning the module</b>
		
		You open the module by calling the UART_open() function. This function
		initializes the hardware and the software with the parameters given in the
		IEKC64_UART_CONFIG structure that you must fill before the call.
		
	<b> Start serial acquisition/restitution </b>
	
		You start the module by calling the UART_start() function. This function
		starts interrupt management.
		
	<b> Getting a frame</b>

		UART_read() the user provides the pointer and the size to the next frame
		to read from input FIFO.
	
	<b> Sending a frame</b>

		UART_write() the user provides the pointer and the size to the next frame
		to be send to output FIFO.
		
	<b> Getting elements in input FIFO </b>
	
		UART_getReadCount() get bytes number in input FIFO.
		
	<b> Getting elements in output FIFO</b>
	
		UART_getWriteCount() get bytes number in output FIFO.
	
	<b> Stop RS232 </b>

		UART_stop() will allow the serial acquisition/restitution to be paused. After a 
		UART_stop, acquisition/restitution can be re-started with the same parameters 
		with UART_start().
	
	<b> Close RS232 </b>

		UART_free() closes all interupts used with the RS232 serial communication
					
   
</P>*//*==============================================================*//*@{*/

/*--------------------------------------------------------------------------*/
/*! Defines the FIFOs sizes values 
*/
typedef enum
{
	//! \Select FIFO size to 16Bytes
	UART_16B = 16,
	//! \Select FIFO size to 32Bytes
	UART_32B = 32,
	//! \Select FIFO size to 64Bytes
	UART_64B = 64,
	//! \Select FIFO size to 128Bytes
	UART_128B = 128,
	//! \Select FIFO size to 256Bytes
	UART_256B = 256,
	//! \Select FIFO size to 512Bytes
	UART_512B = 512,
	//! \Select FIFO size to 1KBytes
	UART_1KB = 1024,
	//! \Select FIFO size to 2KBytes
	UART_2KB = 2048,
	//! \Select FIFO size to 4KBytes
	UART_4KB = 4096,
	//! \Select FIFO size to 8KBytes
	UART_8KB = 8192,
	//! \Select FIFO size to 16KBytes
	UART_16KB = 16384

}IEKC64_UART_BUFFER_SIZE;
/*--------------------------------------------------------------------------*/
/*! Defines the UART baud rate
*/
typedef enum
{
  //! \Select baud rate to 1200b/s
  UART_1200BDS = 0,
  //! \Select baud rate to 2400b/s
  UART_2400BDS,
  //! \Select baud rate to 4800b/s
  UART_4800BDS,
  //! \Select baud rate to 9600b/s
  UART_9600BDS,
  //! \Select baud rate to 19200b/s
  UART_19200BDS,
  //! \Select baud rate to 38400b/s
  UART_38400BDS,
  //! \Select baud rate to 57600b/s
  UART_57600BDS,
  //! \Select baud rate to 115200b/s
  UART_115200BDS
} 
IEKC64_UART_BAUDRATE;


/*--------------------------------------------------------------------------*/
/*! Defines the UART Configuration (all field have to be filled)
*/
typedef struct
{

	/*! This field must contains the IEKC64_UART_CONFIG structure size 
	*/
	Uint32 dwSize;

   //! \Select UART baud rate
   Uint32 BaudRate : 3;    /* 000 =   9600 bauds */
                           /* 001 =  19200 bauds */
                           /* 010 =  28800 bauds */
                           /* 011 =  38400 bauds */
                           /* 100 =  57600 bauds */
                           /* 101 =  76800 bauds */
                           /* 110 = 115200 bauds */
                           /* 111 = 115200 bauds */
   //! \Select UART Parity bit
   Uint32 Parity : 2;      /* 00 = no parity bit */
                           /* 01 = odd parity bit */
                           /* 10 = no parity bit */
                           /* 11 = even parity bit */
    //! \Select UART input FIFO size
   IEKC64_UART_BUFFER_SIZE	RxBufferSize;
   //! \Select UART output FIFO size
   IEKC64_UART_BUFFER_SIZE	TxBufferSize;
   //! \Select UART input FIFO address
   Uint8 *pRxBuffer;
   //! \Select UART output FIFO address
   Uint8 *pTxBuffer;
   
}IEKC64_UART_CONFIG;

/*--------------------------------------------------------------------------*/
/*! Defines the UART Parity
*/
typedef enum 
{
   //! \Select no parity bit
   UART_NO_PARITY = 0,      /* 00 = no parity bit  */
   //! \Select odd parity bit
   UART_ODD_PARITY = 1,      /* 01 = odd parity bit */
   //! \Select no parity bit
   UART_WITHOUT_PARITY = 2, /* 10 = no parity bit  */
   //! \Select even parity bit
   UART_EVEN_PARITY = 3    /* 11 = even parity bit   */
}IEKC64_UART_PARITY;


/*--------------------------------------------------------------------------*/
/*! This varaible contains the UART default configuration
*/
extern const IEKC64_UART_CONFIG IEKC64_UART_CONFIG_DEFAULT;

enum IEKC64_UART_STATUS
{
	//! Generic error code
	IEKC64_UART_ERR	  						= IEKC64_ERR_CODE( IEKC64_UART,  1 ),
  //! Invalid audio configuration structure size	
	IEKC64_UART_ERR_CFG_SIZE				= IEKC64_ERR_CODE( IEKC64_UART,  2 )
};
// function prototypes
/*--------------------------------------------------------------------------*/
/*! Initializes the UART module
 
	\param dwpConfiguration a pointer on an UART configuration structure
				
	\return	An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
				Otherwise it holds an error code. The status code can be tested by
				the IEKC64_SUCCESS(return code) macro that is true is the value
				represents a successful call.
				
				
	\b Example: 
	\verbatim
	IEKC64_UART_CONFIG			uartcfg = IEKC64_UART_STRUCT_DEFAULT;
	IEKC64_STATUS		status;

	//board intialisation
	...
	
	// Configuration
	uartcfg.BaudRate = UART_57600BDS;
	uartcfg.Parity = UART_NO_PARITY;
	uartcfg.RxBufferSize = BUFFER_SIZE_TEST;
	uartcfg.TxBufferSize = BUFFER_SIZE_TEST;
	uartcfg.pRxBuffer = MyRXBuffer;
	uartcfg.pTxBuffer = MyTXBuffer;
	
	status = UART_open(&uartcfg);
	\endverbatim

*/
IEKC64_STATUS UART_open(IEKC64_UART_CONFIG *dwpConfiguration);

/*--------------------------------------------------------------------------*/
/*! Starts the UART module
 
	
	\return	An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
				Otherwise it holds an error code. The status code can be tested by
				the IEKC64_SUCCESS(return code) macro that is true is the value
				represents a successful call.

*/
IEKC64_STATUS UART_start(void);


/*--------------------------------------------------------------------------*/
/*! Stops UART module
 

	\return	An IEKC64_STATUS. If the call succeeds, the value will be IEKC64_OK.
				Otherwise it holds an error code. The status code can be tested by
				the IEKC64_SUCCESS(return code) macro that is true is the value
				represents a successful call.
	
*/
IEKC64_STATUS UART_stop(void);

/*--------------------------------------------------------------------------*/
/*! Receives data with the UART module
 

	\param pAddr
				A pointer to the frame to be acquired

	\param SizeofFrame
				Size of the frame to be acquired


	\return	Uint32
				number of Bytes copy from input FIFO to pAddr

*/
Uint32 UART_read(Uint8* pAddr, Uint32 SizeofFrame);

/*--------------------------------------------------------------------------*/
/*! Sends data with the UART module
 
	\param pAddr
				A pointer to the frame to be sent

	\param SizeofFrame
				Size of the frame to be sent

	\return	Uint32
				number of Bytes copy from pAddr to output FIFO
	
*/
Uint32 UART_write(Uint8 *pAddr, Uint32 SizeofFrame);
/*--------------------------------------------------------------------------*/
/*! Gets the number of Bytes present in input FIFO 

	\return	Uint32
				number of Bytes present in input FIFO
	
*/
Uint32 UART_getReadCount(void);

/*--------------------------------------------------------------------------*/
/*! Gets the number of Bytes present in the output FIFO 

	\return	Uint32
				number of Bytes present in output FIFO
	
*/
Uint32 UART_getWriteCount(void);

/*--------------------------------------------------------------------------*/
/*! Gets the Uart Status

	\return	Status 	\li 0			Ok !
							\li 0x1		RX overrun error
							\li 0x4		Parity error
							\li 0x10	Full error
	
*/
Uint32 UART_getStatus(void);

/*@}*//* end of group UART */

#ifdef __cplusplus
}
#endif

#endif /* ifndef _IEK_UART_H_ */

⌨️ 快捷键说明

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