/*
    ####             #    #     # #
    #   #            #    #       #          The FreeWare C library for 
    #   #  ##   ###  #  # #     # ###             RISC OS machines
    #   # #  # #     # #  #     # #  #   ___________________________________
    #   # ####  ###  ##   #     # #  #                                      
    #   # #        # # #  #     # #  #    Please refer to the accompanying
    ####   ### ####  #  # ##### # ###    documentation for conditions of use
    ________________________________________________________________________

    File:    Serial.h
    Author:  Copyright  1993 Jason Howat
    Version: 1.10 (12 Dec 1993)
    Purpose: Serial-SWI interfaces.
*/


#ifndef __Desk_Serial_h
#define __Desk_Serial_h

#ifdef __cplusplus
extern "C" {
#endif


#ifndef __Desk_Core_h
	#include "Desk.Core.h"
#endif


/* The Desk_serial_rate enumeration defines the values to be used when
 * reading/setting baud rates with Desk_Serial_Get?xRate/Desk_Serial_Set?xRate.
 */
typedef enum
{
  Desk_serial_9600BAUD = 0,
  Desk_serial_75BAUD,
  Desk_serial_150BAUD,
  Desk_serial_300BAUD,
  Desk_serial_1200BAUD,
  Desk_serial_2400BAUD,
  Desk_serial_4800BAUD,
/*Desk_serial_9600BAUD, */
  Desk_serial_19200BAUD = 8,
  Desk_serial_50BAUD,
  Desk_serial_110BAUD,
  Desk_serial_134_5BAUD,
  Desk_serial_600BAUD,
  Desk_serial_1800BAUD,
  Desk_serial_3600BAUD,
  Desk_serial_7200BAUD
} Desk_serial_rate;


/* The following #defines describe the meaning of the bits in the word used
 * by Desk_Serial_GetStatust/Desk_Serial_SetStatus.
 */
#define Desk_serial_USEXONXOFF               0x00000001   
#define Desk_serial_IGNOREDCDBIT             0x00000002
#define Desk_serial_IGNOREDSRBIT             0x00000004
#define Desk_serial_DTROFF                   0x00000008
#define Desk_serial_IGNORECTSBIT             0x00000010
#define Desk_serial_DONTUSERTSFLOWCONTROL    0x00000020
#define Desk_serial_SUPPRESSINPUT            0x00000040
#define Desk_serial_RTSHIGH                  0x00000080
#define Desk_serial_XOFFRECEIVED             0x00010000
#define Desk_serial_XOFFSENT                 0x00020000
#define Desk_serial_DCDHIGH                  0x00040000
#define Desk_serial_NOCARRIER                0x00040000
#define Desk_serial_DSRHIGH                  0x00080000
#define Desk_serial_RIHIGH                   0x00100000
#define Desk_serial_CTSHIGH                  0x00200000
#define Desk_serial_XOFFSENTMANUALLY         0x00400000
#define Desk_serial_SPACEINRECEIVEBUFFER     0x00800000


/* The following #defines describe the meaning of the bits in the word used
 * by Desk_Serial_GetFormat/Desk_Serial_SetFormat.
 */
#define Desk_serial_8BITWORD         0x00000000
#define Desk_serial_7BITWORD         0x00000001    
#define Desk_serial_6BITWORD         0x00000002
#define Desk_serial_5BITWORD         0x00000003
#define Desk_serial_1STOPBIT         0x00000000
#define Desk_serial_2STOPBITS        0x00000004
#define Desk_serial_NOPARITY         0x00000000
#define Desk_serial_PARITY           0x00000008
#define Desk_serial_ODDPARITY        0x00000000
#define Desk_serial_EVENPARITY       0x00000010
#define Desk_serial_MARKPARITY       0x00000020
#define Desk_serial_SPACEPARITY      0x00000030


extern void	Desk_Serial_Activate(void);
/*
 * This function simply does an Desk_OS_Byte 2, 2 to enable the serial drivers.
 */


extern void	Desk_Serial_Deactivate(void);
/*
 * This function simply does an Desk_OS_Byte 2, 0 to disable the serial drivers.
 */


extern int Desk_Serial_GetStatus(void);
/*
 * This function returns the current status of the serial port as given by
 * Desk_OS_SerialOp 0.
 */


extern void	Desk_Serial_SetStatus(int Desk_eor_mask, int Desk_and_mask);
/*
 * This function sets the current state of the serial port as given by
 * Desk_OS_SerialOp 0.
 */


extern int Desk_Serial_GetFormat(void);
/*
 * This function returns the current format used for transmission/reception
 * of characters on the serial line.
 */


extern void	Desk_Serial_SetFormat(int format);
/*
 * This function sets the format to use for transmission/reception of
 * characters on the serial line.
 */


extern Desk_serial_rate Desk_Serial_GetTxRate(void);
/*
 * This function returns the current speed used for transmission
 * of characters on the serial line.
 */

extern Desk_serial_rate Desk_Serial_GetRxRate(void);
/*
 * This function returns the current speed used for reception
 * of characters on the serial line.
 */


extern void	Desk_Serial_SetTxRate(Desk_serial_rate rate);
/*
 * This function sets the speed to use for transmission of
 * characters on the serial line.
 */

extern void	Desk_Serial_SetRxRate(Desk_serial_rate rate);
/*
 * This function sets the speed to use for reception of
 * characters on the serial line.
 */


extern int Desk_Serial_GetByte(void);
/*
 * Reads a byte from the serial input buffer if one is available, otherwise
 * returns -1.
 */


extern Desk_bool Desk_Serial_PutByte(int c);
/*
 * Inserts a byte to be transmitted into the serial output buffer if there
 * is room.  Returns Desk_bool_TRUE if unable to send byte.
 */


extern void	Desk_Serial_SendBreak(int length);
/*
 * Transmits a break of the specified length.
 */


extern void Desk_Serial_NonZeroPollWordOnReceive(int Desk_pollword_value,
                                            void *pollword);
/*
 * This function installs a piece of code on the InsV vector to monitor the
 * insertion of characters into the serial input buffer.  It will modify the
 * supplied pollword to the given value whenever an insertion occurs.  Also,
 * an atexit function is registered to remove the vector claimant and the
 * RMA based code.
 */

  
#ifdef __cplusplus
}
#endif

  
#endif
