(Page 1 of 1 in this chapter)


Chapter 2

Library Overview


2.1 Windows NT
2.2 UnixWare and Solaris

2.1 Windows NT

The CPI library uses standard Windows NT routines to access the TX Series kernel mode device driver. The interface between the library and driver is based on a simple Windows NT file handle. The library opens a channel like a file, reads from and writes to the driver like a file, and closes the channel like a file.

Packets can be received by the host PC asynchronously. Windows NT provides a standard mechanism for receiving unsolicited packets. The library posts read calls to the driver which do not block. The application can then use Windows NT's WaitForSingleObject or WaitforMultipleObjects to determine when those reads complete with a received packet from the TX Series device. The handle to pass to these Windows NT calls can be retrieved using the cpi_wait_obj call. Both Windows NT calls can be told to return immediately by passing 0 in the dwTimeout parameter. This would be the equivalent of polling for packets. The same parameter could be set to INFINITE in which case it would not return until there was a packet (when using WaitForSingleObject) or one of the list of handles had something to report (when using WaitForMultipleObjects).

The device driver buffers packets for registered channels for an inactive read and during packet bursts. However, if the host application cannot process the packets fast enough, and the buffer limit configured is exceeded, the device driver will discard new receives until buffers become available. It is the user's responsibility to determine the appropriate values to configure based on the application requirements.

Note: The user configures both the Number of Channels available for host applications, the default number of receive buffers available for a channel, and the number and size of receive buffers for specific channels. This is accomplished during the installation of the software for the TX Series device. The user can also modify these values at any time by using the CPCFG.EXE program located in the \tektx\soft\util directory. This configuration ability allows the user to specify how much system memory will be allocated by the low level kernel device driver.

2.2 UnixWare and Solaris

The TX Series DPR driver for the UNIX systems (both UnixWare and Solaris) is a STREAMS driver and hence is directly accessed via the standard system calls: open, close, putmsg, getmsg, ioctl, etc. The driver communicates to applications using a specific driver-to-app protocol and hence direct access is not recommended. The CPI library uses a TX_HANDLE type as an object on which all I/O is done. In the UnixWare and Solaris systems, this object, retrieved using cpi_wait_obj, is just a standard UNIX File Descriptor and can be used as such. In particular, packets can be received by the host UnixWare or Solaris system from the TX Series board or boards asynchronously by using either the poll system call or the select system call.

For example if you care to wait on both tty input and packets from a TX Series board your can use poll as follows:

.
        struct pollfd fds[2];
        .
        .

        cpi_init(0, &str);
        mode = CPIM_PORT;
        port = PORT((short)board, (short)chan);

        if ((fd = cpi_open(port, mode, NULL)) < 0)
        {
            < Error handling code >
        }

        for (;;)
        {
            fds[0].fd = 0;          /* fd for standard input */
            fds[0].events = POLLIN;
            fds[0].revents = 0;
            fds[1].fd = fd;         /* TXn000 fd */
            fds[1].events = POLLIN;
            fds[1].revents = 0;

            if (poll(fds, 2, -1) < 0)
            {
                < Error handling code >
            }

            for (i = 0; i < 2; i++)
            {
                if (fds[i].revents & (POLLERR | POLLHUP | POLLNVAL))
                {
                    < Error handling code >
                }

                if (fds[i].revents & POLLIN)
                {
                    /* TXn000 receive */
                    if (fds[i].fd == fd)
                    {
                        if (ret = cpi_get_data(fd,&outbuf,&len))
                        {
                            < Error handling code >
                        }
                        .
                        .
                        < Code to process data >
                        .
                        .
                    }
                    /* Terminal input */
                    else if (fds[i].fd == 0)
                    {
                    }
                }

            } /* for i */

        } /* for ever */



(Page 1 of 1 in this chapter)


tech_support@nmss.com
Copyright © 1999, Natural MicroSystems, Inc. All rights reserved.