Windows & Linux API interface code for PCI/PCIe UARTs drivers



Similar documents
EEPROM PROGRAMMING FOR PCIe UARTs

USB Stick Driver Installation Instructions

BSP for Windows* Embedded Compact* 7 and Windows* Embedded Compact 2013 for Mobile Intel 4th Generation Core TM Processors and Intel 8 Series Chipset

Future Technology Devices International Ltd. USB NMC-2.5m. USB to USB Null Modem Cable. Datasheet

SP490/491 Full Duplex RS-485 Transceivers

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

ALL-USB-RS422/485. User Manual. USB to Serial Converter RS422/485. ALLNET GmbH Computersysteme Alle Rechte vorbehalten

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

AN10860_1. Contact information. NXP Semiconductors. LPC313x NAND flash data and bad block management

CP2110-EK CP2110 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup

Internal LVDS Dynamic Backlight Brightness Control

How to Use WinUSB to Communicate with a USB Device

Software User Guide UG-461

AN220 USB DRIVER CUSTOMIZATION

Application Note AN0008. Data Logging Extension. For. Venus 8 GPS Receiver

The Secrets of RS-485 Half-duplex Communication

Freescale MQX USB Device User Guide

AN10811 Programming SPI flash on EA3131 boards Rev May 2009 Application note Document information Info Content Keywords Abstract

1-Port R422/485 Serial PCIe Card

RN-XV-RD2 Evaluation Board

SUDT AccessPort TM Advanced Terminal / Monitor / Debugger Version 1.37 User Manual

USB I/O Programming Manual

USB - FPGA MODULE (PRELIMINARY)

Device Management API for Windows* and Linux* Operating Systems

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

Device Management API for Windows* and Linux* Operating Systems

Future Technology Devices International Ltd. USB-Key. Datasheet

AN220 USB DRIVER CUSTOMIZATION

ELAN DIGITAL SYSTEMS LTD. SL232 PC- CARD USER S GUIDE

Introduction to PCI Express Positioning Information

Configuring CoreNet Platform Cache (CPC) as SRAM For Use by Linux Applications

2-port RS-422 / 485 Universal PCI

AN2328 Application note

The care and feeding of Pythons at the Redmond Zoo. (Using Micro Python and pyboard with Windows)

Industrial Multi-port Serial Cards

How To Fix An Lmx9838 Bluetooth Serial Port Module With Bluetooth (Bluetooth 2) From A Bluetooth Bluetooth 4.2 Device With A Bluembee 2.2 Module

PCI Express SATA / esata 6Gb/s RAID Card User Manual

CAM-VGA100 User Manual

Table of Contents. Overview Features Applications Hardware requirement Card dimensions Software Installation...

IOActive Security Advisory

BIT COMMANDER. Serial RS232 / RS485 to Ethernet Converter

LINDY ELECTRONICS LIMITED & LINDY-ELEKTRONIK GMBH - SECOND EDITION

Intel Retail Client Manager Audience Analytics

USB to RS-422/485 Serial Adapter

STIM202 Evaluation Kit

Old Company Name in Catalogs and Other Documents

XID ERRORS. vr352 May XID Errors

Data Transfer between Serial Link and TCP/IP Link Using ez80f91 MCU

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Intel Platform Controller Hub EG20T

AN1754 APPLICATION NOTE

NVIDIA GRID 2.0 ENTERPRISE SOFTWARE

Future Technology Devices International Ltd. Mac OS X Installation Guide

Cypress CY7C64225 USB-to-UART Setup Guide Version 1.3

Future Technology Devices International Ltd

Using NSM for Event Notification. Abstract. with DM3, R4, and Win32 Devices

PCI-SIG ENGINEERING CHANGE NOTICE

PSoC Programmer Release Notes

AN10866 LPC1700 secondary USB bootloader

Future Technology Devices International Ltd

WiFiPerf User Guide 1.5

PSoC Programmer Release Notes

PMS. Energy management and monitoring software. Installation and operation instructions

Current Cost Data Cable User Guide. Installing and configuring the data cable

LAN9514/LAN9514i. USB 2.0 Hub and 10/100 Ethernet Controller PRODUCT FEATURES PRODUCT PREVIEW. Highlights. Target Applications.

Installing Service Pack Updater Archive for CodeWarrior Tools (Windows and Linux) Quick Start

Gigabit Ethernet Packet Capture. User s Guide

DTM for Hilscher PROFINET IO-Controller Devices

Using the RS232 serial evaluation boards on a USB port

Creating Overlay Networks Using Intel Ethernet Converged Network Adapters

Virtual COM Port Driver Installation Manual

Technical Note. TN_147 Java D2xx for Android

Application Note Dialogic Diva Media Boards

Dialogic System Release 6.0 PCI for Windows

Virtual COM Port Driver Installation Manual

UPSMON PRO Linux --- User Manual

TTL-232R-3V3 USB to TTL Serial Converter Cable

Windows CE 6.0 APEX ZF

The Secrets of Flow Control in Serial Communication

AN4156 Application note

BIOS Update Release Notes

RN-WIFLY-EVAL-UM. WiFly Evaluation Kit Roving Networks. All rights reserved. RN-WIFLY-EVAL-UM Version 1.32r 10/9/2012 USER MANUAL

GEVPlayer. Quick Start Guide

Intel Server Board S5000PALR Intel Server System SR1500ALR

KM Metering Inc. EKM Dash User Manual. EKM Metering Inc. (831)

PCI IDE Controller. Specification. Revision 1.0

Ways to Use USB in Embedded Systems

FT4232H Mini Module. USB Hi-Speed FT4232H Evaluation Module. Datasheet

VM0808H HDMI Matrix Switch RS-232 Control Tool V User Manual

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

FT2232H Mini Module. USB Hi-Speed FT2232H Evaluation Module. Datasheet

End-User troubleshooting guide For Sentinel SuperPro/UltraPro and Sentinel Hardware Keys

BASLER ACE QUICK INSTALLATION GUIDE

Wake on LAN Hardware Implementation Utilizing the Intel EP80579 Integrated Processor Product Line

Intel Server Board S3420GPV

Interfacing an HTML Form to the ez80f91 MCU

AN335 USB DRIVER INSTALLATION UTILITY. 1. Description. 2. Installation Install Package

Using the WAGO PROFINET Coupler as Remote I/O with a Siemens S7 PLC

How to Configure Intel Ethernet Converged Network Adapter-Enabled Virtual Functions on VMware* ESXi* 5.1

SIM900_Custom Application Building Tutorial_Application Note_V1.00

Transcription:

Windows & Linux API interface code for PCI/PCIe UARTs drivers 1.0 INTRODUCTION PCI and PCIe UARTs will work with standard serial COM ports APIs. However, for advanced features such as Auto RS-485 Half-duplex flow control and controlling MPIOs, special APIs are necessary. This application note will discuss the Windows and Linux software API codes to control the MPIOs and Auto RS-485 Half-duplex flow control. 2.0 WINDOWS API INTERFACE CODE Exar s PCI/PCIe UART drivers should be first installed for corresponding Windows OS. Then refer to the following sections. 2.1 CONTROLLING MPIOS The following steps show the method to control the MPIOs. 2.1.1 Header definition file The definitions shown in Figure 1 below needs to be added to the header file. FIGURE 1. DEFINITION IN THE HEADER FILE #include <winioctl.h> #define FILE_DEVICE_XRPORT 0x00008005 #define XRPORT_IOCTL_INDEX 0x805 #define IOCTL_XRPORT_READ_CONFIG_REG CTL_CODE(FILE_DEVICE_XRPORT, \ XRPORT_IOCTL_INDEX + 8, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) #define IOCTL_XRPORT_WRITE_CONFIG_REG CTL_CODE(FILE_DEVICE_XRPORT, \ XRPORT_IOCTL_INDEX + 9, \ METHOD_BUFFERED, \ FILE_ANY_ACCESS) typedef struct { BYTE breg; BYTE bdata; } CONFIG_WRITE, *PCONFIG_WRITE; 1

2.1.2 Application source code functions The functions shown in Figure 2 below needs to be added to the application source code. FIGURE 2. FUNCTIONS IN THE SOURCE CODE // include the header file which has the above defines // The application should supply breg in the range of // 0x00-0x13 respectively for 0x80-0x93 // Driver appends the CONFIG REG BASE 0x80 to this register BOOL cfgwrite( BYTE breg, BYTE bvalue) { BOOL Status; DWORD cbreturned; CONFIG_WRITE cfgwrite; cfgwrite.breg = breg; cfgwrite.bdata = bvalue; Status = DeviceIoControl( m_hporthandle, //handle that you got from CreateFile (DWORD) IOCTL_XRPORT_WRITE_CONFIG_REG, &cfgwrite, sizeof(config_write), NULL, 0, &cbreturned, 0); if (!Status) { MessageBox("Error in Writing...!", "Error", MB_OK MB_ICONERROR); } return Status;} BOOL cfgread( BYTE breg, BYTE *pbvalue ) { BOOL Status; DWORD cbreturned; Status = DeviceIoControl( m_hporthandle, //handle that you got from CreateFile IOCTL_XRPORT_READ_CONFIG_REG, &breg, sizeof(byte), pbvalue, sizeof(byte), &cbreturned, 0); if (!Status) { MessageBox("Error in Reading...!", "Error", MB_OK MB_ICONERROR); } return Status;} 2

In the function in Figure 2, only the first port handle of the card can be used to access the configuration registers. The configuration register value should be in the range of 0x00-0x13 for PCI and 0x00-0x1B for PCIe UARTs. 2.1.3 Function call To access the MPIOs, use this code at the appropriate place in your application. FIGURE 3. FUNCTION CALL HANDLE m_hporthandle; yourfunction() { if ((hporthandle = CreateFile( \\\\.\\COM5, // this should be the first port number of the card. // In your case it may not be COM5 GENERIC_READ GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL )) == ((HANDLE)-1)) { return FALSE; // failure } else { // success } cfgwrite( 0x13, 0x00); // Config reg is offset by 0x80 in the driver, bits set to '0' for output // write to MPIOLVL register (cfgwrite (0x10, value) to control the output levels // or read to read the current output/input levels } 3

2.2 ENABLE RS-485 HALF DUPLEX FLOW CONTROL To enable RS-485 half duplex flow control, the xrapi.h file needs to be included in the project. The xrapi.h file can be found in the folder with the driver source code. FIGURE 4. ENABLE RS-485 HALF-DUPLEX CONTROL MODE After opening and setting up the port using CreateFile and SetCommState, call DeviceIoControl with IOCTL_XRPORT_SET_RS485, as below: //START -- COM_PORT_ENHANCED DWORD cbreturned; portenhanced; portenhanced.rs485 = 1; // 0 for reset if (!DeviceIoControl( m_hporthandle, (DWORD) IOCTL_XRPORT_SET_RS485, &portenhanced, sizeof(com_port_enhanced), NULL, 0, &cbreturned, 0 )) { MessageBox( NULL, "Unable to set RS485", NULL, MB_OK); } //END -- 4

In the Windows 2K/XP (version 4.1.0.0 and newer) and Vista/7 (version 2.2.0.0 and newer) drivers, the RS-485 half-duplex feature can also be enabled (by checking the box next to the RS-485 ) through the properties page (see Figure 5). FIGURE 5. PROPERTIES PAGE 5

3.0 LINUX API INTERFACE CODE The Linux standard serial port driver has support for XR17x15x UARTs in kernel version 2.6.8 and newer (see the "8250_pci.c" file). Exar provides custom drivers for both Linux kernel versions 2.4 and 2.6 for PCI (XR17x15x and XR17V25x) and PCIe (XR17V35x) UARTs. To use some advanced feature like Auto RS-485 half-duplex flow control, custom API codes (see section 3.3 and section 3.4) are necessary. 3.1 LINUX KERNEL VERSION 2.4 If Exar's default Vendor ID and Device ID are used, it is recommended to use the custom driver from Exar s website. If custom Vendor ID and Device ID are used, it is recommended to use the custom driver from Exar s website and modify to the custom Vendor ID and Device ID in the driver. An external EEPROM can be programmed to store the custom Vendor ID and Device ID. 3.2 LINUX KERNEL VERSION 2.6 3.2.1 Linux kernel version 2.6.7 and older If Exar's default Vendor ID and Device ID are used, it is recommended to use the custom driver from Exar s website. If custom Vendor ID and Device ID are used, it is recommended to use custom driver from Exar s website and modify to the custom Vendor ID and Device ID in the driver. An external EEPROM can be programmed to store the custom Vendor ID and Device ID. 3.2.2 Linux kernel version 2.6.8 and newer Linux kernel version 2.6.8 and newer have built-in support for Exar s XR17x15x PCI UARTs (see the "8250_pci.c" file) but do not have support for the XR17V25x and XR17V35x UARTs. 3.2.2.1 XR17x15x If Exar's default Vendor ID and Device ID are used, it is recommended to disable the 8250_pci.c driver, rebuild the kernel and then use the custom drivers from Exar s website. If custom Vendor ID and Device ID are used, it is recommended to use the custom driver from Exar s website and modify to the custom Vendor ID and Device ID in the driver. An external EEPROM can be programmed to store the custom Vendor ID and Device ID. 3.2.2.2 XR17V25x & XR17V35x If Exar's default Vendor ID and Device ID are used, it is recommended to use custom driver from Exar s website. If custom Vendor ID and Device ID are used, it is recommended to use custom driver from Exar s website and modify to the custom Vendor ID and Device ID in the driver. An external EEPROM can be programmed to store the custom Vendor ID and Device ID. See the summary in Table 1. TABLE 1: VID AND DID REQUIREMENTS FOR USING LINUX CUSTOM DRIVERS LINUX KERNEL VERSION DEFAULT EXAR VENDOR ID AND DEVICE ID CUSTOM VENDOR ID AND DEVICE ID XR17x15x XR17V25x & XR17V35x 2.4 2.6.1 -- 2.6.7 Use custom driver from Exar s website 2.6.8 -- latest Disable 8250_pci.c driver, rebuild kernel and then use the rebuilt driver 2.4 2.6.1 -- 2.6.7 Use custom driver from Exar s website without any changes 2.6.8 -- latest Use custom driver from Exar s website and modify VID and DID in custom driver Linux kernel version 2.4 and 2.6 drivers are available for download from Exar s website. If a driver for a specific kernel version is not available, send an email to uarttechsupport@exar.com. 6

3.3 ACCESSING MPIOS To access MPIOs register set, the following code is necessary. For the PCI UARTs, please note that the file handle in the following Figure 6 should be that of the first port of the card. FIGURE 6. ACCESSING MPIOS DESCRIPTION //Accessing MPIO registers from the user space: // define these in the app. /* EXAR ioctls */ //#define FIOQSIZE 0x5460 #define EXAR_READ_REG (FIOQSIZE + 1) #define EXAR_WRITE_REG (FIOQSIZE + 2) struct xrioctl_rw_reg { unsigned char reg; unsigned char regvalue; }; //To read MPIO register: xrioctl_rw_reg input; input. reg = 0x93; //MPIO register address is different from Windows API ioctl(fd, EXAR_READ_REG, &input); // fd is the file handle obtained with 'open' // input.regvalue will have the data read from the reg //To write to MPIO register: xrioctl_rw_reg input; input.reg = 0x93; //MPIO register address is different from Windows API input.regvalue = 0xFF; ioctl(fd, EXAR_WRITE_REG, &input); // fd is the file handle obtained with 'open' 7

3.4 ENABLE AUTO RS-485 MODE To enable auto RS-485 half duplex mode, the following code in Figure 7 is necessary. FIGURE 7. ENABLE AUTO RS-485 MODE //Enabling RS-485 mode from the user space // define these in the app. /* EXAR ioctls */ //#define FIOQSIZE 0x5460 #define EXAR_READ_REG (FIOQSIZE + 1) #define EXAR_WRITE_REG (FIOQSIZE + 2) struct xrioctl_rw_reg { unsigned char reg; unsigned char regvalue; }; //To enable the auto RS-485 mode, the FCTR bit-5 needs to be set to 1 //To write to FCTR register: xrioctl_rw_reg input; input.reg = 0x8; //FCTR register offset address is 0x8; ioctl(fd, EXAR_READ_REG, &input); // fd is the file handle obtained with 'open'; // input.reg value will have the data read from the reg input.regvalue = 0x20; //Set FCTR bit-5 to 1 ioctl(fd, EXAR_WRITE_REG, &input); //fd is the file handle obtained with open //To disable the auto RS-485 mode xrioctl_rw_reg input; input.reg = 0x8; //FCTR register offset address is 0x8; ioctl(fd, EXAR_READ_REG, &input); // fd is the file handle obtained with 'open; //input.reg value will have the data read from the reg input.regvalue &= 0xdf; // clear FCTR bit-5 ioctl(fd, EXAR_WRITE_REG, &input); // fd is the file handle obtained with 'open' 8

4.0 SUPPORT If there are any questions, send them to uarttechsupport@exar.com. APPLICATION NOTE NOTICE EXAR Corporation reserves the right to make changes to the products contained in this publication in order to improve design, performance or reliability. EXAR Corporation assumes no responsibility for the use of any circuits described herein, conveys no license under any patent or other right, and makes no representation that the circuits are free of patent infringement. Charts and schedules contained here in are only for illustration purposes and may vary depending upon a user s specific application. While the information in this publication has been carefully checked; no responsibility, however, is assumed for inaccuracies. EXAR Corporation does not recommend the use of any of its products in life support applications where the failure or malfunction of the product can reasonably be expected to cause failure of the life support system or to significantly affect its safety or effectiveness. Products are not authorized for use in such applications unless EXAR Corporation receives, in writing, assurances to its satisfaction that: (a) the risk of injury or damage has been minimized; (b) the user assumes all such risks; (c) potential liability of EXAR Corporation is adequately protected under the circumstances. Copyright 2011 EXAR Corporation Datasheet December 2011. Send your UART technical inquiry with technical details to hotline: uarttechsupport@exar.com. Reproduction, in part or whole, without the prior written consent of EXAR Corporation is prohibited. 9