/*
 *            Copyright (c) 1998-2000 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *     Module Name: serParam.h
 *         Version: 1.00
 *   Original Date: 03/15/00
 *          Author: Paul Jacobson
 *        Language: Ansi C
 * Compile Options:
 * Compile defines:
 *       Libraries:
 *    Link Options:
 *
 *    Entry Points:
 *
 * Description.
 * =======================================================================
 * This header file contains declarations for the serial device.
 *
 *
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 * 04/12/02  PMJ   Extracted the public portion from netos_serl.h and included 
 *                 here.
 * 08/02/02  PMJ   New and improved serial API with select functionality and better
 *                 modem signals control.  Introducing the RTS Transmission encapsulation
 *                 which can be used for RS-485 half-duplex style communucation.
 * 08/07/02  PMJ   Included POSIX functions ttyname() and isatty().
 *
 */

#ifndef __serParam_h
#define __serParam_h

#include <netosIo.h>
#ifdef __cplusplus
extern "C"
{
#endif

/*  IOCTL commands  */
/**
 * These constants are deprecated and should not be used in new applications.
 * They are used with the deprecated interface to the serial driver.  They
 * are the ioctl codes used by the old serial API to set and get configuration
 * and status information about a port.
 *
 *
 * Unless otherwise specified, the argument for these ioctls is an address.
 *
 * @external
 * @category Serial:deprecatedSerial
 * @since 1.0
 * @name serialIoctls       "Serial ioctls"
 * @deprecated  6.0         This API has been replaced with the termios API
 *
 * @param SIO_BAUD_SET                Get the baud rate of a serial port
 * @param SIO_BAUD_GET                Set the baud rate of a serial port
 * @param SIO_HW_OPTS_SET             Get settings for number of data bits, number of
 *                                    stop bits, parity, and handshaking
 * @param SIO_HW_OPTS_GET             Set settings for number of data bits, number of
 *                                    stop bits, parity, and handshaking
 * @param SIO_TERM_ECHO               <list type="unordered">
 *                                          <item>set the argument to TERM_ECHO_ON to have the driver 
 *                                                echo back every character it receives</item>
 *                                          <item>set the argument to TERM_ECHO_OFF to disable echo</item>
 *                                          <item>set the argument to TERM_ECHO_TRANSLATE to translate
 *                                                echoed \n characters to \r\n</item>
 *                                    </list>
 * @param SIO_TERM_SEND_CR            <list type="unordered">
 *                                          <item>set the argument to TERM_SEND_CR_ON to have the
 *                                                serial driver translate \n characters to \r\n
 *                                                when transmitting them</item>
 *                                          <item>set the argument to TERM_SEND_CR_OFF to disable
 *                                                \n character translation</item>
 *                                    </list>
 * @param SIO_GET_STATUS_DCD          Get the current status of the DCD signal
 * @param SIO_GET_STATUS_CTS          Get the current status of the CTS signal
 * @param SIO_GET_STATUS_DSR          Get the current status of the DSR signal
 * @param SIO_SET_STATE_DTR           Set the state of the DTR signal (argument is 1 or 0)
 * @param SIO_SET_STATE_RTS           Set the state of the RTS signal (argument is 1 or 0)
 * @param SIO_BAUD_ERROR_SET          Set the baud rate for the port
 * @param SIO_BAUD_ERROR_GET          Get the baud rate for the port
 */
#define SIO_BAUD_SET                0x1003
#define SIO_BAUD_GET                0x1004
#define SIO_HW_OPTS_SET             0x1005
#define SIO_HW_OPTS_GET             0x1006
#define SIO_TERM_ECHO               0x100A
#define SIO_TERM_SEND_CR            0x100B
#define SIO_GET_STATUS_DCD          0x100C
#define SIO_GET_STATUS_CTS          0x100D
#define SIO_GET_STATUS_DSR          0x100E
#define SIO_SET_STATE_DTR           0x100F
#define SIO_SET_STATE_RTS           0x1010
#define SIO_BAUD_ERROR_SET          0x1020
#define SIO_BAUD_ERROR_GET          0x1021

#define SIO_GET_STATUS_ERROR        0x1022
#define SIO_CLEAR_STATUS_ERROR      0x1023
#define SIO_WATCH_FOR_EVENTS        0x1024

#define SIO_MODE_SET                0x1007
#define SIO_MODE_GET                0x1008

/* IOCTLs 0x1025 - 0x 0x1031 taken by new serial API */

#define SIO_GET_STATUS_TX_BUFFER    0x1040
#ifdef BSP_ARM9
/* SPI definitions */
#define SIO_SPI                     0x1041
#define SIO_SET_CLOCK_MODE          0x1042  /* SPI: Set the SPI clock mode */
#define SIO_GET_CLOCK_MODE          0x1043  /* SPI: Get the SPI clock mode */
#define SIO_SET_LSB                 0x1044  /* SPI: Set LSB bit ordering */
#define SIO_GET_LSB                 0x1045  /* SPI: Get bit ordering */
#define SIO_SET_CSPOL               0x1046  /* SPI: Set chip select polarity */
#define SIO_GET_CSPOL               0x1047  /* SPI: Get chip select polarity */


/* The four SPI clock modes as defined in the SPI Specification */
#define SIO_SPI_CLOCK_MODE_0        0
#define SIO_SPI_CLOCK_MODE_1        1
#define SIO_SPI_CLOCK_MODE_2        2
#define SIO_SPI_CLOCK_MODE_3        3
#endif

/*  For the old style DTR ioctl */
#define SIO_SET_STATUS_DTR          SIO_SET_STATE_DTR
#define SIO_SET_STATUS_RTS			SIO_SET_STATE_RTS

/*  SIO_BAUD_GET and SIO_BAUD_SET legal options */
/**
 * Baud rate constants to use with SIO_BAUD_GET and SIO_BAUD_SET.
 *
 * @external
 * @category Serial:deprecatedSerial
 * @since 1.0
 * @name baudRates       "Baud Rates"
 * @deprecated  6.0     This API has been replaced with the termios API
 *
 * @param SIO_75_BAUD           75 baud
 * @param SIO_150_BAUD          150 baud
 * @param SIO_300_BAUD          300 baud
 * @param SIO_600_BAUD          600 baud
 * @param SIO_1200_BAUD         1200 baud
 * @param SIO_2400_BAUD         2400 baud
 * @param SIO_4800_BAUD         4800 baud
 * @param SIO_7200_BAUD         7200 baud
 * @param SIO_9600_BAUD         9600 baud
 * @param SIO_14400_BAUD        14400 baud
 * @param SIO_19200_BAUD        19200 baud
 * @param SIO_28800_BAUD        28800 baud
 * @param SIO_38400_BAUD        38400 baud
 * @param SIO_57600_BAUD        57600 baud
 * @param SIO_115200_BAUD       115200 baud
 * @param SIO_230400_BAUD       230400 baud (must use 33.1776 Mhz crystal on NET+50)
 * @param SIO_259200_BAUD       259200 baud (not supported on NS7520, supported NET+50 if 33.1776 Mhz crystal is used)
 * @param SIO_345600_BAUD       345600 baud (not supported on NS7520, supported NET+50 if 33.1776 Mhz crystal is used)
 * @param SIO_518400_BAUD       518400 baud (not supported on NS7520, supported NET+50 if 33.1776 Mhz crystal is used)
 * @param SIO_307200_BAUD       307200 baud (not supported on NS7520)
 * @param SIO_460800_BAUD       460800 baud (not supported on NS7520, supported NET+50 if 44.2368 Mhz crystal is used)
 * @param SIO_691200_BAUD       691200 baud (not supported on NS7520, supported NET+50 if 44.2368 Mhz crystal is used)
 * @param SIO_1036800_BAUD      1036800 baud (not supported on NS7520, supported NET+50 if 33.1776 Mhz crystal is used)
*/
#define SIO_75_BAUD                 75
#define SIO_150_BAUD                150
#define SIO_300_BAUD                300
#define SIO_600_BAUD                600
#define SIO_1200_BAUD               1200
#define SIO_2400_BAUD               2400
#define SIO_4800_BAUD               4800
#define SIO_7200_BAUD               7200
#define SIO_9600_BAUD               9600
#define SIO_14400_BAUD              14400
#define SIO_19200_BAUD              19200
#define SIO_28800_BAUD              28800
#define SIO_38400_BAUD              38400
#define SIO_57600_BAUD              57600
#define SIO_115200_BAUD             115200
#define SIO_230400_BAUD             230400      /* if 44.2368 Mhz */
#define SIO_259200_BAUD             259200      /* if 33.1776 Mhz crystal is used. */
#define SIO_345600_BAUD             345600      /* if 33.1776 Mhz crystal is used */
#define SIO_518400_BAUD             518400      /* if 33.1776 Mhz crystal is used. */
#define SIO_307200_BAUD             307200
#define SIO_460800_BAUD             460800      /* if 44.2368 Mhz */
#define SIO_691200_BAUD             691200      /* if 44.2368 Mhz */
#define SIO_1036800_BAUD            1036800     /* if 33.1776 Mhz crystal is used. */





/*

 * Mercury baud rates.

 */
#ifdef BSP_ARM9
#define SIO_921600_BAUD             921600
#define SIO_1843200_BAUD            1843200
#endif

/**
 * The following should be included in the ioctl option field 
 * for SIO_HW_OPTS_GET and SIO_HW_OPTS_SET.  One selection 
 * from each of the four categories should be included.  
 *
 *
 * @external
 * @category Serial:deprecatedSerial
 * @since 1.0
 * @name hwOptions       "Hardware Options"
 * @deprecated  6.0     This API has been replaced with the termios API
 *
 * @param SIO_NO_HANDSHAKING          No handshaking
 * @param SIO_HW_RTS_CTS_HANDSHAKING  Hardware handshaking using RTS and CTS
 * @param SIO_SW_HANDSHAKING          Software handshaking using XON and XOFF
 * @param SIO_FIVE_BIT_DATA_WIDTH     Five data bits
 * @param SIO_SIX_BIT_DATA_WIDTH      Six data bits
 * @param SIO_SEVEN_BIT_DATA_WIDTH    Seven data bits
 * @param SIO_EIGHT_BIT_DATA_WIDTH    Eight data bits
 * @param SIO_ONE_STOP_BIT            One stop bit
 * @param SIO_TWO_STOP_BITS           Two stop bits
 * @param SIO_NO_PARITY               No parity
 * @param SIO_EVEN_PARITY             Even parity
 * @param SIO_ODD_PARITY              Odd parity
 */
#define SIO_NO_HANDSHAKING          0x0
#define SIO_HW_RTS_CTS_HANDSHAKING  0x1
#define SIO_SW_HANDSHAKING          0x2
#define SIO_FIVE_BIT_DATA_WIDTH     0x0
#define SIO_SIX_BIT_DATA_WIDTH      0x4
#define SIO_SEVEN_BIT_DATA_WIDTH    0x8
#define SIO_EIGHT_BIT_DATA_WIDTH    0xc
#define SIO_ONE_STOP_BIT            0x0
#define SIO_TWO_STOP_BITS           0x20
#define SIO_NO_PARITY               0x0
#define SIO_EVEN_PARITY             0x40
#define SIO_ODD_PARITY              0x80

/**
 * Option values for SIO_TERM_ECHO.
 *
 * @external
 * @category Serial:deprecatedSerial
 * @since 6.0
 * @name termEchoOptions    "SIO_TERM_ECHO Options" 
 *
 * @param TERM_ECHO_OFF               Disable echo
 * @param TERM_ECHO_ON                Echo received data back to sender
 * @param TERM_ECHO_TRANSLATE         Translate echoed \n characters to \r\r.
 */
#define TERM_ECHO_OFF               0
#define TERM_ECHO_ON                1
#define TERM_ECHO_TRANSLATE         2

/**
 * Option values for SIO_TERM_SEND_CR.
 *
 * @external
 * @category Serial:deprecatedSerial
 * @since 6.0
 * @name termSendOptions    "SIO_TERM_SEND_CR Options" 
 *
 * @param TERM_SEND_CR_OFF          Do not translate line end characters when transmitting
 * @param TERM_SEND_CR_ON           Translate \n characters to \n\r when transmitting
 */
#define TERM_SEND_CR_OFF            0
#define TERM_SEND_CR_ON             1

/* Mode Set options -- Note: currently only interrupt/fiq/dma modes
    are supported */
#define SIO_MODE_POLL               1
#define SIO_MODE_INT                2
#define SIO_MODE_DMA                4
#ifdef BSP_ARM9
#define SIO_MODE_SPI                5
#endif
#define SIO_MODE_FIQ		    8


/*  Error conditions    */
#define SIO_ERROR_OVERRUN           1
#define SIO_ERROR_FRAMING           2
#define SIO_ERROR_PARITY            4

/*  Select conditions    */
#define SIO_SELECT_ON_DATA          0x01
#define SIO_SELECT_ON_DCD           0x02
#define SIO_SELECT_ON_DSR           0x04
#define SIO_SELECT_ON_RI            0x08
#define SIO_SELECT_ON_CTS           0x10


/*  Other helpful definitions   */
/*  Select one of the following data bit widths     */
#define SIO_HANDSHAKE_MASK          (SIO_NO_HANDSHAKING | SIO_SW_HANDSHAKING)
#define SIO_DATA_WIDTH_MASK         (SIO_EIGHT_BIT_DATA_WIDTH)
#define SIO_PARITY_MASK             (SIO_EVEN_PARITY | SIO_ODD_PARITY)
#define SIO_STOP_BIT_MASK           (SIO_TWO_STOP_BITS)


/*  RTS transmit encapsulation for RS-485/RS-482 drivers    */
#define SIO_RTS_XMIT_ENCAPSULATION  0x01

/*
 * int isatty(int desc)
 *
 * Does this descriptor refer to an open serial communications terminal? 
 *
 * LEGAL ARGUMENT RANGES:
 *
 *      desc:       a descriptor returned from an open() call or socket() call.
 *
 * RETURNS:
 *
 *  1:                              The descriptor is an open serial communications 
 *                                  port--possibly connected to a terminal.
 *
 *  0:                              The descriptor is not an open serial 
 *                                  communications port, or not a serial port at all.
 */
int isatty(int desc);



/*
 * char *ttyname (int desc)
 *
 * Returns a pointer to the pathname of the terminal device that is open on the
 * desciptor desc, or NULL on error (for example, if the desc is not connected 
 * to a terminal).  
 *
 * NOTE
 *
 *  The return value points to a static memory location and can be overwritten
 *  by the next call to the function.
 *
 * LEGAL ARGUMENT RANGES:
 *
 *      desc:       a descriptor returned from an open() call or socket() call.
 *
 * RETURNS:
 *
 *  non-NULL:                       A pointer to the terminal device name when the 
 *                                  descriptor is an open serial communications port.
 *
 *  NULL:                           The descriptor is not an open serial communications 
 *                                  port, or not a serial port at all.
 */
char *ttyname (int desc);

#ifdef __cplusplus
}
#endif

#endif

