Windows Embedded CE 6.0 Developer Guide for Exar PCI UARTs

 

Revision: 1.0 – April 2007.

 

The Windows Embedded CE 6.0 driver support for Exar’s PCI UART family of devices (XR17C152/154/158, XR17D152/154/158 and XR17V252/254/258) is achieved by 3 sets of .dlls, viz, xrpci.dll, xrserial.dll and xrisr.dll. (In Windows CE, the drivers contain the extension as .dll.) This package supports any number of cards.

 

Xrpci.dll:

This is a kind of class driver which loads for the PCI card and depending on the device like 0x152, 0x154, 0x158, 0x252, 0x254 and 0x258 loads the required number of  xrserial.dll, each per port available and also requests and allocates the required memory and interrupt resources for each port. The initialization of this driver thus loads the xrserial.dll and the de-initialization closes and clears all the resources that were acquired during the init.

 

Xrserial.dll:

This driver is loaded for each port in the card as a separate instance with unique resources and memory area. This driver follows the standard Windows CE serial interface with standard MDD (Model Device Driver) interface exposed to the user level and has Exar specific Platform Dependent Driver interface that is specific to Exar UARTs. This driver connects or attaches the ISR for its System Interrupt. Thus each xrserial.dll driver will load its own instance of xrisr.dll.

 

Xrisr.dll:

This is the Interrupt Service Routine driver for the UARTs. This driver follows the same conventions of CE’s standard ISR driver.

 

Implementation through Microsoft Visual Studio 2005 integrated with Platform Builder CE 6.0:

The developer should follow these steps for incorporating the driver into his platform. These steps are tested with Microsoft Visual Studio 2005.

Create XRPCI driver in your existing platform project:

  1. Select "Project->Add New Subproject …" with your project opened in Microsoft Visual Studio 2005.
  2. In the resulting "Windows Embedded CE Subproject Wizard", select "WCE Dynamic-Link Library" under ‘Available Templates’.
  3. Type "XRPCI" in the "Subproject name" edit box, then click ‘Next’ button.
  4. In the next step, select "An empty subproject" radio button and click ‘Finish’ button.
  5. Copy all the 5 xrpci.xxx files from Exar provided "XRPCI" folder into newly created “XRPCI” folder under your project. (Replace Visual Studio generated existing xrpci.bib, xrpci.def and xrpci.reg files with Exar supplied xrpci.bib, xrpci.def and xrpci.reg files.)
  6. Select "Solution Explorer" of your project. Expand XRPCI subproject under “Subprojects”. Right click on “Include Files” folder and select "Add->Existing Item" from the drop-down menu. In the subsequent "Open" dialog box, choose xrpci folder under your project and select xrpci.h and click ‘Add’ button.
  7. Similar to the above step, add xrpci.c to “Source files” folder.
  8. Right click on "XRPCI" subproject in the same “Solution Explorer” view and select "Properties" from the drop-down menu. In the resulting dialog box select "C/C++" tab. Select "Include Directories" section and add "$(_WINCEROOT)\public\common\ddk\inc; $(_WINCEROOT)\public\common\oak\inc;" to it. Then click OK.
  9. Right click on "XRPCI" Subproject and select "Build " to build xrpci.dll driver.

 

Create XRISR driver in the platform:

  1. Select "Project->Add New Subproject …" in Microsoft Visual Studio 2005.
  2. In the resulting "Windows Embedded CE Subproject Wizard", select "WCE Dynamic-Link Library" under ‘Available Templates’.
  3. Type "XRISR" in the "Subproject name" edit box, then click ‘Next’ button.
  4. In the next step, select "An empty subproject" radio button and click ‘Finish’ button.
  5. Copy all the 4 files from Exar provided "XRISR" folder into newly created “XRISR” folder under your project. (Replace Visual Studio generated existing xrisr.bib and xrisr.def files with Exar supplied xrisr.bib and xrisr.def files.)
  6. Select "Solution Explorer" of your project. Expand XRISR subproject under “Subprojects”. Right click on “Include Files” folder and select "Add->Existing Item" from the drop-down menu. In the subsequent "Open" dialog box, choose XRISR folder under your project and select xrisr.h and click ‘Add’ button.
  7. Similar to the above step, add xrisr.c to “Source files” folder.
  8. Right click on "XRISR" subproject in the same “Solution Explorer” view and select "Properties" from the drop-down menu. In the resulting dialog box select "C/C++" tab. Select "Include Directories" section and add "$(_WINCEROOT)\public\common\ddk\inc; $(_WINCEROOT)\public\common\oak\inc;" to it.
  9. Select "DLL Entry Point" section in the same tab and type "DllEntry" in it.
  10. Select "Link" tab in the same dialog box. Select "Additional Libraries" section and append " $(_PROJECTROOT)\cesysgen\oak\lib\$(_CPUINDPATH)\ddk_io.lib". (Space " " is the separator between the entries.) Then click OK.
  11. Right click on "XRISR" Subproject and select "Build" to build xrisr.dll driver.

 

Create XRSERIAL driver in the platform:

  1. Select "Project->Add New Subproject …" in Microsoft Visual Studio 2005.
  2. In the resulting "Windows Embedded CE Subproject Wizard", select "WCE Dynamic-Link Library" under ‘Available Templates’.
  3. Type "XRSERIAL" in the "Subproject name" edit box, then click ‘Next’ button.
  4. In the next step, select "An empty subproject" radio button and click ‘Finish’ button.
  5. Copy all the 8 files from Exar provided "XRSERIAL" folder into newly created “XRSERIAL” folder under your project. (Replace Visual Studio generated existing xrserial.bib and xrserial.def files with Exar supplied xrserial.bib and xrserial.def files.)
  6. Select "Solution Explorer" of your project. Expand XRSERIAL subproject under “Subprojects”. Right click on “Include Files” folder and select "Add->Existing Item" from the drop-down menu. In the subsequent "Open" dialog box, choose XRSERIAL folder under your project and select all the three .h files
  7. Similar to the above step, add xrmdd.c, xrcom16550.c and xrser16550.c to “Source files” folder.
  8. Right click on "XRSERIAL" project in the same “Solution Explorer” view and select "Settings..." from the drop-down menu. In the resulting dialog box select "C/C++" tab. Select "Additional Macro Definitions" section and append ", -DUSE_NEW_SERIAL_MODEL" to the existing entry. (Comma "," is the separator between macros.)
  9. Select "Include Directories" section and add "$(_WINCEROOT)\public\common\ddk\inc; $(_WINCEROOT)\public\common\oak\inc;" to it.
  10. Select "Link" tab in the same dialog box. Select "Additional Libraries" section and append " $(_PROJECTROOT)\cesysgen\oak\lib\$(_CPUINDPATH)\ceddk.lib". (Space " " is the separator between the entries.) Then click OK.
  11. Right click on "XRSERIAL" Subproject and select "Build" to build xrserial.dll driver.

 

NOTE:

  1. In xrpci.c of “XRPCI” folder “static DWORD dwDeviceArrayIndex = 1” starts with 1 as our platform’s motherboard’s embedded serial port’s DeviceArrayIndex has value 0. The developer needs to check this with his/her project.reg settings, and this should not collide with any other serial devices.
  2. For 17v25x parts, the default clock rate is set to 24MHz in xrser16550.c file. If you are using 14.7456MHz for 17v25x devices, comment “#define CLK_RATE 24000000” and uncomment “#define CLK_RATE 14745600” line.

 

If all the above steps are done successfully, the platform can be built by “Build Solution” option in Visual Studio or by any other Build method that you always do to build Windows Embedded CE 6.0 project. With this newly created CE 6.0 image file, the system will find the Exar card and all the ports should be enumerated. User should check the registry to check the “COMx:” for the proper value to open the ports through CreateFile API in the user level application. To check whether the ports are working are not, the user can use the Exar supplied xrCEgui.exe tool.

 

 

IOCTL support in driver for special features:

 

Windows CE 6.0 PCI UART Driver set has support for special features in the form of IOCTLs, which can be accessed from applications using Windows CE API, DeviceIoControl. The supported IOCTLs are;

 

IOCTL_XR17C15X_ENABLE_HWFLOWCONTROL

IOCTL_XR17C15X_DISABLE_HWFLOWCONTROL

IOCTL_XR17C15X_ENABLE_SWFLOWCONTROL        

IOCTL_XR17C15X_DISABLE_SWFLOWCONTROL

IOCTL_XR17C15X_ENABLE_IR                                        

IOCTL_XR17C15X_DISABLE_IR               

IOCTL_XR17C15X_ENABLE_SLEEPMODE

IOCTL_XR17C15X_DISABLE_SLEEPMODE

IOCTL_XR17C15X_ENABLE_INTERNAL_LOOPBACK

IOCTL_XR17C15X_DISABLE_INTERNAL_LOOPBACK

IOCTL_XR17C15X_ENABLE_AUTORS485

IOCTL_XR17C15X_DISABLE_AUTORS485

IOCTL_XR17C15X_CONFIG_REG_READ            

IOCTL_XR17C15X_CONFIG_REG_WRITE

 

The sample code to use these IOCTLs in an application:

 

Step 1: Include the declarations below in an appropriate header file.

 

// All Windows CE specific EXAR IOCTL codes and the related data types are defined here

// the IOCTL index starts from 50 (in pegdser.h the last ioctl index ends at 25)

#define IOCTL_XR17C15X_ENABLE_HWFLOWCONTROL                    CTL_CODE(FILE_DEVICE_SERIAL_PORT,50,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_DISABLE_HWFLOWCONTROL                   CTL_CODE(FILE_DEVICE_SERIAL_PORT,51,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_ENABLE_SWFLOWCONTROL                     CTL_CODE(FILE_DEVICE_SERIAL_PORT,52,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_DISABLE_SWFLOWCONTROL                    CTL_CODE(FILE_DEVICE_SERIAL_PORT,53,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_ENABLE_IR                                                     CTL_CODE(FILE_DEVICE_SERIAL_PORT,54,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_DISABLE_IR                                                    CTL_CODE(FILE_DEVICE_SERIAL_PORT,55,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_ENABLE_SLEEPMODE                                  CTL_CODE(FILE_DEVICE_SERIAL_PORT,56,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_DISABLE_SLEEPMODE                                 CTL_CODE(FILE_DEVICE_SERIAL_PORT,57,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_ENABLE_INTERNAL_LOOPBACK             CTL_CODE(FILE_DEVICE_SERIAL_PORT,58,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_DISABLE_INTERNAL_LOOPBACK             CTL_CODE(FILE_DEVICE_SERIAL_PORT,59,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_ENABLE_AUTORS485                                   CTL_CODE(FILE_DEVICE_SERIAL_PORT,60,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_DISABLE_AUTORS485                                  CTL_CODE(FILE_DEVICE_SERIAL_PORT,61,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_CONFIG_REG_READ                                                 CTL_CODE(FILE_DEVICE_SERIAL_PORT,62,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define IOCTL_XR17C15X_CONFIG_REG_WRITE                                               CTL_CODE(FILE_DEVICE_SERIAL_PORT,63,METHOD_BUFFERED,FILE_ANY_ACCESS)

 

typedef struct          /* Software Flow Control Enable Options*/

{

            BOOL custom; /* if YES, please specify Xon/Xoff chars */

            BYTE One_or_Two_Char;      /* if 1 - and custom-Yes, specify Xon1 and Xoff1 chars. If 2 and custom-Yes, specify both Xon1/Xoff1 and Xon2 and Xon2 */

            BYTE Xon1;

            BYTE Xoff1;

            BYTE Xon2;

            BYTE Xoff2;

} SW_FLOW_CONTROL_PARAMS;

 

typedef struct

{

    unsigned char            bReg;

            unsigned char    bData;

 

} CONFIG_WRITE, *PCONFIG_WRITE;

 

 

Step 2: Include the below code in an appropriate C/C++ file

 

{

                        BOOL Status;

                        DWORD dwIoControlCode;

                        PVOID pInBuffer, pOutBuffer;

                        DWORD nInBufferSize, nOutBufferSize, cbReturned;

                       

                        //

                        // all input/output variables for whole function scope are defined here

                        //

                        SW_FLOW_CONTROL_PARAMS SWFCParams;

                        BOOL bInvert;

                        UCHAR ucTemp1, ucTemp2;

                        CONFIG_WRITE CfgWrite;

                       

                        pInBuffer = pOutBuffer = NULL;

                        nInBufferSize = nOutBufferSize = 0;

 

                        switch(dwIoCtlCodeIndex)

                        {

                                    case 0: //ENABLE_HWFLOWCONTROL

                                    {

                                                dwIoControlCode = IOCTL_XR17C15X_ENABLE_HWFLOWCONTROL;

                                    }

                                    break;

 

                                    case 1: //DISABLE_HWFLOWCONTROL

                                    {

                                                dwIoControlCode = IOCTL_XR17C15X_DISABLE_HWFLOWCONTROL;

                                    }

                                    break;

 

                                    case 2: //ENABLE_SWFLOWCONTROL

                                    {                                             

                                                SWFCParams.custom = TRUE; // FALSE if you want default

SWFCParams.One_or_Two_Char = 2;

                                                SWFCParams.Xoff1 = 0x13;

                                                SWFCParams.Xoff2 = 0x14;

                                                SWFCParams.Xon1 = 0x11;

                                                SWFCParams.Xon2 = 0x12;

 

                                                pInBuffer = &SWFCParams;

                                                nInBufferSize = sizeof(SW_FLOW_CONTROL_PARAMS);

                                                dwIoControlCode = IOCTL_XR17C15X_ENABLE_SWFLOWCONTROL;

                                    }

                                    break;

 

                                    case 3: //DISABLE_SWFLOWCONTROL

                                    {

                                                dwIoControlCode = IOCTL_XR17C15X_DISABLE_SWFLOWCONTROL;

                                    }

                                    break;

 

                                    case 4: //ENABLE_IR

                                    {                                             

                                                bInvert = TRUE; // FALSE if you don't want invert

 

                                                pInBuffer = &bInvert;

                                                nInBufferSize = sizeof(BOOL);

                                                dwIoControlCode = IOCTL_XR17C15X_ENABLE_IR;

                                    }

                                    break;

 

                                    case 5: //DISABLE_IR

                                    {

                                                dwIoControlCode = IOCTL_XR17C15X_DISABLE_IR;

                                    }

                                    break;

 

                                    case 6: //ENABLE_SLEEPMODE

                                    {

// This will put all the channels into sleep

                                                // This operation can only be called from the

                                                // first Channel's COM port handle

                                                dwIoControlCode = IOCTL_XR17C15X_ENABLE_SLEEPMODE;

                                    }

                                    break;

 

                                    case 7: //DISABLE_SLEEPMODE

                                    {

// This will bring out all the channels from sleep

                                                // This operation can only be called from the

                                                // first Channel's COM port handle

                                                dwIoControlCode = IOCTL_XR17C15X_DISABLE_SLEEPMODE;

                                    }

                                    break;

 

                                    case 8: //ENABLE_INTERNAL_LOOPBACK

                                    {

                                                dwIoControlCode = IOCTL_XR17C15X_ENABLE_INTERNAL_LOOPBACK;

                                    }

                                    break;

 

                                    case 9: //DISABLE_INTERNAL_LOOPBACK

                                    {

                                                dwIoControlCode = IOCTL_XR17C15X_DISABLE_INTERNAL_LOOPBACK;

                                    }

                                    break;                         

 

                                    case 10: //PCIUART_CONFIG_REG_READ

                                    {                                             

                                                ucTemp1 =  0x80 to 0x93; // configuration registers offset range is 0x80 to 0x93; provide appropriate register offset

                                                                                               

                                                pInBuffer = &ucTemp1;

                                                pOutBuffer = &ucTemp2;

                                                nInBufferSize = nOutBufferSize = sizeof(UCHAR);

                                                dwIoControlCode = IOCTL_XR17C15X_CONFIG_REG_READ;

                                    }

                                    break;

 

                                    case 11: //PCIUART_CONFIG_REG_WRITE

                                    {                                             

                                                CfgWrite.bReg = 0x80 to 0x93; // configuration registers offset range is 0x80 to 0x93; provide appropriate register offset

                                                CfgWrite.bData = your data to write;

 

                                                pInBuffer = (PVOID)&CfgWrite;

                                                nInBufferSize = sizeof(CONFIG_WRITE);                                          

                                                dwIoControlCode = IOCTL_XR17C15X_CONFIG_REG_WRITE;                                                             

                                    }

                                    break;

 

                                    default:

                                    {

                                                CString str;

                                                str.Format(_T("Error: Invalid IOCTL !!!"));

                                                MessageBox (str, TEXT("Failure"), MB_OK);            

                                    }

                                    break or return;

                        }                     

 

                        Status = DeviceIoControl(        hPort,

                                                                        dwIoControlCode,

                                                                        pInBuffer,

                                                                        nInBufferSize,

                                                                        pOutBuffer,

                                                                        nOutBufferSize,

                                                                        &cbReturned,

                                                                        0);

                        if (!Status)

                        {                     

                                    CString str;

                                    str.Format(_T("Error: This operation failed!!!"));

                                    MessageBox (str, TEXT("Failure"), MB_OK);

                        }

                        else

                        {

                                    // for Config Read we need to do extra work like displaying the data here                                 

                                    if(dwIoControlCode == IOCTL_XR17C15X_CONFIG_REG_READ)

                                    {

                                                ucTemp2 contains the Cnfig Regsiter’s Read data;

                                    }

                        }

            }