Amulets & Armor  v1.02
Open Source Game
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Functions
COMIO

Serial IO Driver. More...

Data Structures

struct  T_PortBuffer
 
struct  T_PortInfo
 

Macros

#define COM_END_LIST   0xFFFF
 
#define COM_PORT_FLAGS_ENABLED   0x4000
 
#define COM_PORT_IN_USE   0x8000
 
#define COM_REG_BAUD_DIV_HIGH_BYTE   1
 
#define COM_REG_BAUD_DIV_LOW_BYTE   0
 
#define COM_REG_INTERRUPT_ENABLE   1
 
#define COM_REG_INTERRUPT_ID   2
 
#define COM_REG_LINE_CONTROL   3
 
#define COM_REG_LINE_STATUS   5
 
#define COM_REG_MODEM_CONTROL   4
 
#define COM_REG_MODEM_STATUS   6
 
#define COM_REG_RECEIVE   0
 
#define COM_REG_TRANSMIT   0
 
#define END_OF_INTERRUPT   0x20
 
#define PIC_CONTROL_REG   0x20
 
#define PIC_MASK   0x21
 

Functions

T_void ActivateInterrupt (T_byte8 ioInterrupt, T_word16 ioAddress)
 
E_Boolean COMIO_CheckCarrier (T_COMPort port)
 
T_void COMIO_ClearReceiveBuffer (T_COMPort port)
 
T_void COMIO_ClearSendBuffer (T_COMPort port)
 
T_void COMIO_Close (T_COMPort port)
 
T_void COMIO_DisablePort (T_COMPort port)
 
T_void COMIO_EnablePort (T_COMPort port)
 
E_Boolean COMIO_GetEnableStatus (T_COMPort port)
 
T_word16 COMIO_GetReceiveCount (T_COMPort port)
 
T_word16 COMIO_GetSendCount (T_COMPort port)
 
T_void COMIO_Initialize (T_void)
 
T_COMPort COMIO_Open (T_word16 io_address, T_byte8 io_interrupt)
 
T_word16 COMIO_ReceiveByte (T_COMPort port)
 
T_word16 COMIO_ReceiveData (T_COMPort port, T_word16 count, T_byte8 *buffer)
 
T_word16 COMIO_SendByte (T_COMPort port, T_byte8 data)
 
T_word16 COMIO_SendData (T_COMPort port, T_word16 count, T_byte8 *buffer)
 
T_void COMIO_SetBaudRate (T_COMPort port, T_COMBaudRate baud)
 
T_void COMIO_SetControl (T_COMPort port, E_COMBitLength bit_length, E_COMStopBit stop_bit, E_COMParity parity)
 
T_void COMIO_SetTypePort (T_COMPort port, E_COMPortType type)
 
T_void DeactivateInterrupt (T_byte8 ioInterrupt, T_word16 ioAddress)
 
T_void HandleInterrupt (T_byte8 ioInterrupt)
 

Detailed Description

Serial IO Driver.

See Also
http://www.amuletsandarmor.com/AALicense.txt

Macro Definition Documentation

#define COM_END_LIST   0xFFFF
#define COM_PORT_FLAGS_ENABLED   0x4000
#define COM_PORT_IN_USE   0x8000
#define COM_REG_BAUD_DIV_HIGH_BYTE   1
#define COM_REG_BAUD_DIV_LOW_BYTE   0
#define COM_REG_INTERRUPT_ENABLE   1
#define COM_REG_INTERRUPT_ID   2
#define COM_REG_LINE_CONTROL   3
#define COM_REG_LINE_STATUS   5
#define COM_REG_MODEM_CONTROL   4
#define COM_REG_MODEM_STATUS   6
#define COM_REG_RECEIVE   0
#define COM_REG_TRANSMIT   0
#define END_OF_INTERRUPT   0x20
#define PIC_CONTROL_REG   0x20
#define PIC_MASK   0x21

Function Documentation

T_void ActivateInterrupt ( T_byte8  ioInterrupt,
T_word16  ioAddress 
)

ActivateInterrupt is used to turn on an interrupt that was originally inactive. This routine MUST NOT be called when an interrupt handler is already active.

NOTE: None really.

Parameters
ioInterrupt– Level of interrupt to activate
ioAddress– Hardware IO address
E_Boolean COMIO_CheckCarrier ( T_COMPort  port)

You can check for if a modem is connected by checking the carrier signal of the modem. This routine will return TRUE if the given port has a carrier signal, or else it will return FALSE.

Parameters
port– Valid communications port.
Returns
TRUE = Carrier found FALSE = Carrier not found
T_void COMIO_ClearReceiveBuffer ( T_COMPort  port)

COMIO_ClearReceiveBuffer initializes the read buffer of a port to be that of an empty buffer. It does not actually zero out the buffer, but all indexes are zeroed.

NOTE: Using this routine should only be done when the port is not enabled. If it is, no telling what will happen. I've included a DebugCheck to make sure this is not the case.

Parameters
port– Port to have its receive buffer zeroed. The port must be in use and disabled.
T_void COMIO_ClearSendBuffer ( T_COMPort  port)

COMIO_ClearSendBuffer initializes the send buffer of a port to be that of an empty buffer. It does not actually zero out the buffer, but all indexes are zeroed.

NOTE: Using this routine should only be done when the port is not enabled. If it is, no telling what will happen. I've included a DebugCheck to make sure this is not the case.

Parameters
port– Port to have its receive buffer zeroed. The port must be in use and disabled.
T_void COMIO_Close ( T_COMPort  port)

COMIO_Close does the shutting down of a port. It will make sure that the interrupt list is updated and buffers in memory are removed. You should make a call to COMIO_DisablePort before you call this routine.

NOTE: This routine assumes you are done with the port, but it does not actually stop the interrupts from occuring.

Parameters
port– Port needing to be closed. The port must be in use to be closed (as well as valid).
T_void COMIO_DisablePort ( T_COMPort  port)

Turn on a port that has already been opened (and perhaps previously was disabled). Enabling a port allows it to send and receive data.

NOTE: I'm not really sure if there are any problems.

Parameters
port– Port to enable The port I'm getting should be a valid number.
T_void COMIO_EnablePort ( T_COMPort  port)

Turn on a port that has already been opened (and perhaps previously was disabled). Enabling a port allows it to send and receive data.

NOTE: Hmmm ... let me think about that one.

Parameters
port– Port to enable Would it be too much to assume that the port is valid? Probably so.
E_Boolean COMIO_GetEnableStatus ( T_COMPort  port)

Should you forget, you may wish to sometimes find out if a port is active or inactive. A call to this routine will return a TRUE if the port is active or a FALSE if it is inactive.

Parameters
port– Port to check enable status
Returns
TRUE = port is enabled FALSE = port is disabled
T_word16 COMIO_GetReceiveCount ( T_COMPort  port)

To help determine if you want to read from the receive buffer, you can use this function to tell you how many bytes are there. If it is zero, then the buffer is empty.

NOTE: None. Just make sure we keep those _disable and _enable lines.

Parameters
port– Port to check receive buffer
Returns
Number of bytes in buffer
T_word16 COMIO_GetSendCount ( T_COMPort  port)

GetSendCount is mainly to see how full the input buffer is for a single port. Use this routine to determine how many bytes are still needing to be sent out by the port.

NOTE: None. Just make sure we keep those _disable and _enable lines.

Parameters
port– Port to check send buffer
Returns
Number of bytes in buffer
T_void COMIO_Initialize ( T_void  )

Initialize all the important global variables used by the COMIO package.

NOTE: I don't think there are any.

T_COMPort COMIO_Open ( T_word16  io_address,
T_byte8  io_interrupt 
)

COMIO_Open is the routine that opens up a communication port on the PC computer given the PC I/O address (e.g. 0x03E8) and the interrupt tied to that port (e.g. interrupt level 3). A communications port identifier used by the rest of these routines is returned. Also, the returned port is in disable mode and needs a call to COMIO_EnablePort to active it.

NOTE: COMIO_Open does not check if the given address and interrupt is valid (except for the allowable ranges). Should a invalid numbers be used, no error may be returned. Also, COMIO_Open does not currently check to see if it is has already created a port with the same address and interrupt.

Parameters
io_address– I/O address for port to allocate
io_interrupt– Interrupt level for port io_address is in the range of 0x200 - 0x400 io_interrupt is in the range of 0-7
Returns
Returns a com port identifier T_COMPort is a value of 0-(COM_MAX_PORTS-1) Also, the initial port has not been enabled.
T_word16 COMIO_ReceiveByte ( T_COMPort  port)

When you need one byte from a port, call this routine. It will check to see if there is a byte in the buffer, and if there is, will return it. If there is not, it will return with COM_ERROR_EMPTY_BUFFER.

NOTE: Note that this routine does not sit and wait for a byte to appear in the read buffer. Therefore, the calling routine must always take the responsibility of considering a time out condition.

Parameters
port– Port to read from receive buffer.
Returns
if 0-255, byte read
otherwise, COM_ERROR_EMPTY_BUFFER
T_word16 COMIO_ReceiveData ( T_COMPort  port,
T_word16  count,
T_byte8 buffer 
)
T_word16 COMIO_SendByte ( T_COMPort  port,
T_byte8  data 
)

COMIO_SendByte is the basic routine to send one byte over the com port that you give. If the buffer is full, you will get an error of COM_ERROR_FULL_BUFFER.

NOTE: If the buffer is full when you try to send it, the routine does not wait until it is empty. It is up to the calling routine to consider this case.

Parameters
port– Port to send byte out through
data– character to send
Returns
Returns either COM_ERROR_NO_ERROR or COM_ERROR_EMPTY_BUFFER
T_word16 COMIO_SendData ( T_COMPort  port,
T_word16  count,
T_byte8 buffer 
)
T_void COMIO_SetBaudRate ( T_COMPort  port,
T_COMBaudRate  baud 
)

Before a port can be used effectively, it needs the correct baud rate to be set. COMIO_SetBaudRate sets the baud to one of the specified enumerated baud rates.

Parameters
port– Valid port to change baud rate
baud– Baud rate to go to. baud ranges from 300 to 38400 (any bigger and we can't handle it) port is a valid port
T_void COMIO_SetControl ( T_COMPort  port,
E_COMBitLength  bit_length,
E_COMStopBit  stop_bit,
E_COMParity  parity 
)

COMIO_SetControl sets the bit length, stop bits, and parity of the port given.

NOTE: This had not be called while the port is active. Unpredictable results will occur.

Parameters
port– Port to change control
bit_length– Number of bits per transfer
stop_bit– Number of stop bits at end
parity– Type of parity checking (if any)
T_void COMIO_SetTypePort ( T_COMPort  port,
E_COMPortType  type 
)

Set the type of modem that we will be using. Currently only a couple types are used. The default modem is the 8250. This routine should only be called before the modem is enabled.

Parameters
port– Port to change type of
type– Type to change port to
T_void DeactivateInterrupt ( T_byte8  ioInterrupt,
T_word16  ioAddress 
)

DeactivateInterrupt is used to turn off an interrupt that was originally active. This routine MUST NOT be called when an interrupt handler is already inactive.

Parameters
ioInterrupt– Level of interrupt to deactivate
ioAddress– IO address
T_void HandleInterrupt ( T_byte8  ioInterrupt)

COMIO_InterruptXXX are the 8 interrupts for the different interrupt levels that can be received by the PC. I don't think commenting each interrupt would be useful since they all do the same thing. When active, each interrupt calls the interrupt handler with the number of the interrupt level. When done, it returns by chaining to the standard interrupt handler.

NOTE: If several modems/devices are on the same interrupt level, the handler is going to get called and this might slow down operations more than we would like. However, it will take specialized hardware to do it differently. HandleInterrupt is the main routine that does ALL of the byte transactions for input and output of the ports. When called, it is given an interrupt level that was called. Using this interrupt level, HandleInterrupt will go through a list of devices and check if those devices are interrupting. It will do whatever service(s) are being asked for in order of the list.

NOTE: If two devices ask for an interrupt simultaneously, the first interrupt will do both, the second interrupt will do neither. But this is not really a fallacy since the alternative is to have two interrupts with one device (out of the two) being served.

Parameters
ioInterrupt– Level of interrupt to handle

extern T_word32 hit_count ; hit_count++ ;