📄 sci.h
字号:
* O_NONBLOCK - non-blocking mode
* O_BLOCK - blocking mode (default)
* O_SCI_DISABLE_IN_WAIT - SCI disabled in wait mode
* O_SCI_ENABLE_IN_WAIT - SCI enabled in wait mode (default)
* O_SCI_WAKE_BY_ADDRESS - address mark wake-up
* O_SCI_WAKE_BY_IDLE - idle line wake-up (default)
* O_SCI_WORD_9BIT - 1 start bit, 9 data bits, 1 stop bit
* O_SCI_WORD_8BIT - 1 start bit, 8 data bits, 1 stop bit (default)
* O_SCI_PARITY_NONE - parity function disabled (default)
* O_SCI_PARITY_ODD - odd parity
* O_SCI_PARITY_EVEN - even parity
* O_SCI_7_DATA_BITS_ODD_PARITY - 7 data bits with odd parity
* O_SCI_7_DATA_BITS_EVEN_PARITY - 7 data bits with even parity
* O_SCI_8_DATA_BITS_NO_PARITY - 8 data bits without parity (default)
* O_SCI_8_DATA_BITS_ODD_PARITY - 8 data bits with odd parity
* O_SCI_8_DATA_BITS_EVEN_PARITY - 8 data bits with even parity
* O_SCI_9_DATA_BITS_NO_PARITY - 9 data bits without parity
* O_SCI_TX_INVERTED - inverted mode
* O_SCI_TX_NOT_INVERTED - normal mode (default)
* O_SCI_INVERT_ALL_BITS - O_SCI_TX_INVERTED
* O_SCI_DONT_INVERT_ANY_BITS - O_SCI_TX_NOT_INVERTED
* O_SCI_LOOPBACK_DISABLED - loop operation disabled (default)
* O_SCI_LOOPBACK_ENABLED - loop operation enabled
* O_SCI_LOOPBACK_SINGLE_WIRE_ENABLED - loop operation with single wire enabled
*
* BaudRate - value of baud rate (driver uses as a unsigned long)
*
* Return Value:
* SCI device descriptor if open is successful.
* -1 value if open failed.
*
* Example:
*
* open SCI0 for 8 bit data, no parity, and 115200:
*
* - user application :
*
* handle_t SciFD;
*
* SciFD = open(BSP_DEVICE_NAME_SCI_0, O_SCI_8_DATA_BITS_NO_PARITY, 115200);
*
* open SCI0 for 7 bit data, even parity, and 9600:
*
* - user application :
*
* handle_t SciFD;
*
* SciFD = open(BSP_DEVICE_NAME_SCI_0, O_SCI_7_DATA_BITS_EVEN_PARITY, 9600L);
*
*
* IOCTL
*
* UWord16 ioctl(handle_t hndl, UWord16 Cmd, unsigned long params);
*
* Semantics:
* The SCI driver supports the same commands described for
* sciIoctl (Please see sciIoctl desciption above).
*
* Parameters:
* hndl - SCI Device descriptor returned by "open" call.
* Cmd - Command for driver
* pParams - The pParams is specific to each ioctl command;
* Refer to the ioctl table below to see the ioctl
* command and associated type of parameter.
*
* The parameter pParams is specific to each ioctl command.
* If pParams is not used then NULL should be passed into function.
*
* Return Value:
* Specific to Command
*
* Example:
*
* // Reset SCI
* ioctl(SciFD, SCI_DEVICE_RESET, NULL);
*
*
* WRITE
*
* ssize_t write(handle_t hndl, const void * pBuffer, size_t NBytes);
*
* Semantics:
* The write function writes user buffer out of SCI device. Note that
* the driver treats "pBuffer" as a pointer to a character buffer.
*
* In Blocking mode, "write" waits while all required data is transferred.
*
* In NonBlocking mode, "write" starts the transfer operation and returns
* control to the application. It does not wait while all data is
* transferred via SCI.
*
* The "write" function also enables the transmitter interrupt in
* order to get the transmitter started.
*
*
* Parameters:
* hndl - SCI Device descriptor returned by "open" call.
* pBuffer - Pointer to user buffer (driver uses as a * char).
* NBytes - NBytes (in 8-bit bytes) of the data to be written
* out of SCI device;
*
* Return Value:
* - Actual size (in 8-bit bytes) of the data written
*
* Example:
*
* unsigned char Buffer[10];
*
* // Write to SCI
* write(SciFd, Buffer, sizeof(Buffer));
*
*
* READ
*
* ssize_t read(handle_t hndl, void * pBuffer, size_t NBytes);
*
* Semantics:
* The read function reads data from SCI device and stores
* it in the user's read buffer. Note that the driver treats
* "pBuffer" as a pointer to a character buffer.
*
* In Blocking mode, "read" waits until all data has been
* received.
*
* In NonBlocking mode, "read" returns the actual data that
* has already been received from the SCI device.
*
* Parameters:
* hndl - SCI Device descriptor returned by "open" call.
* pBuffer - Pointer to user buffer. (driver uses as a * char).
* NBytes - NBytes (in 8-bit bytes) of the data to be read
* from SCI device;
*
* Return Value:
* - Actual size (in bytes) of the data read
*
*
* Example:
*
* unsigned char Buffer[10];
*
* // Read from SCI
* read(SciFd, Buffer, sizeof(Buffer));
*
*
* CLOSE
*
* int close(handle_t hndl);
*
* Semantics:
* The close function closes the SCI device by disabling
* all SCI interrupts.
*
* Parameters:
* hndl - SCI Device descriptor returned by "open" call.
*
* Return Value:
* Zero
*
* Example:
*
* // Close SCI device
* close(SciFd);
*
*****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/* ioctl commands */
#define SCI_IOCTLs \
{ \
sciIoctlSCI_DEVICE_RESET, \
sciIoctlSCI_DEVICE_OFF, \
sciIoctlSCI_DEVICE_ON, \
sciIoctlSCI_GET_STATUS, \
sciIoctlSCI_CMD_SEND_BREAK, \
sciIoctlSCI_CMD_WAIT, \
sciIoctlSCI_CMD_WAKEUP, \
sciIoctlSCI_GET_COUNT_READ, \
sciIoctlSCI_GET_COUNT_WRITE, \
sciIoctlSCI_GET_READ_BUFFER_SIZE, \
sciIoctlSCI_GET_WRITE_BUFFER_SIZE \
}
enum io_sci
{
SCI_DEVICE_RESET = IO_OFFSET(io_sInterface, pIoctl[0] ),
SCI_DEVICE_OFF = IO_OFFSET(io_sInterface, pIoctl[1] ),
SCI_DEVICE_ON = IO_OFFSET(io_sInterface, pIoctl[2] ),
SCI_GET_STATUS = IO_OFFSET(io_sInterface, pIoctl[3] ),
SCI_CMD_SEND_BREAK = IO_OFFSET(io_sInterface, pIoctl[4] ),
SCI_CMD_WAIT = IO_OFFSET(io_sInterface, pIoctl[5] ),
SCI_CMD_WAKEUP = IO_OFFSET(io_sInterface, pIoctl[6] ),
SCI_GET_COUNT_READ = IO_OFFSET(io_sInterface, pIoctl[7] ),
SCI_GET_COUNT_WRITE = IO_OFFSET(io_sInterface, pIoctl[8] ),
SCI_GET_READ_BUFFER_SIZE = IO_OFFSET(io_sInterface, pIoctl[9] ),
SCI_GET_WRITE_BUFFER_SIZE = IO_OFFSET(io_sInterface, pIoctl[10] )
};
/*****************************************************************************/
/* API Function prototypes */
/*****************************************************************************/
/* Callback function type */
typedef unsigned long (* tSciCallBackPtr)(volatile register arch_sSCI * pArch, unsigned long param);
extern handle_t sciOpen(const char * pName, int OFlags, unsigned long rawBoudRate);
extern int sciClose(handle_t hndl);
extern ssize_t sciNonBlockRead(handle_t hndl, void * pBuffer, size_t NBytes);
extern ssize_t sciBlockRead( handle_t hndl, void * pBuffer, size_t NBytes );
extern ssize_t sciNonBlockWrite( handle_t hndl, const void * pBuffer, size_t NBytes );
extern ssize_t sciBlockWrite(handle_t hndl, const void * pBuffer, size_t NBytes );
/* defines for open flags */
#define O_SCI_DISABLE_IN_WAIT 0x4000u /* Disable SCI in wait mode */
#define O_SCI_ENABLE_IN_WAIT 0x0000u /* Enable SCI in wait mode */
#define O_SCI_WAKE_BY_ADDRESS 0x0800u /* Address mark wakeup */
#define O_SCI_WAKE_BY_IDLE 0x0000u /* Idle line wakeup */
/* values for data mode of SCI */
/* not supported*/ #define O_SCI_DATA_9BIT 0x1000u
#define O_SCI_DATA_8BIT 0x0000u
#define O_SCI_PARITY_NONE 0x0000u
#define O_SCI_PARITY_ODD 0x0300u
#define O_SCI_PARITY_EVEN 0x0200u
#define O_SCI_7_DATA_BITS_ODD_PARITY (O_SCI_DATA_8BIT | O_SCI_PARITY_ODD)
#define O_SCI_7_DATA_BITS_EVEN_PARITY (O_SCI_DATA_8BIT | O_SCI_PARITY_EVEN)
#define O_SCI_8_DATA_BITS_NO_PARITY (O_SCI_DATA_8BIT | O_SCI_PARITY_NONE)
#define O_SCI_8_DATA_BITS_ODD_PARITY (O_SCI_DATA_9BIT | O_SCI_PARITY_ODD)
#define O_SCI_8_DATA_BITS_EVEN_PARITY (O_SCI_DATA_9BIT | O_SCI_PARITY_EVEN)
#define O_SCI_9_DATA_BITS_NO_PARITY (O_SCI_DATA_9BIT | O_SCI_PARITY_NONE)
#define O_SCI_TX_INVERTED 0x0400u
#define O_SCI_TX_NOT_INVERTED 0x0000u
#define O_SCI_INVERT_ALL_BITS O_SCI_TX_INVERTED
#define O_SCI_DONT_INVERT_ANY_BITS O_SCI_TX_NOT_INVERTED
#define O_SCI_LOOPBACK_DISABLED 0x0000u
#define O_SCI_LOOPBACK_ENABLED 0x8000u
#define O_SCI_LOOPBACK_SINGLE_WIRE_ENABLED 0xA000u
/* values for exception status */
#define SCI_EXCEPTION_OVERRUN_ERROR 0x0800u
#define SCI_EXCEPTION_NOISE_ERROR 0x0400u
#define SCI_EXCEPTION_FRAME_ERROR 0x0200u
#define SCI_EXCEPTION_PARITY_ERROR 0x0100u
#define SCI_EXCEPTION_BUFFER_OVERFLOW 0x0008u
#define SCI_EXCEPTION_ADDRESS_MARK 0x0004u
#define SCI_EXCEPTION_BREAK_SYMBOL 0x0002u
#define SCI_STATUS_WRITE_INPROGRESS 0x0010u
#define SCI_STATUS_EXCEPTION_EXIST 0x0040u
unsigned long sci_getBaudRate( unsigned long BaudRate );
/*********************************************************************
* The driver file is included at the end of this public include
* file instead of the beginning to avoid circular dependency problems.
**********************************************************************/
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -