Amulets & Armor
v1.02
Open Source Game
|
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 |
Serial IO Driver.
#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 |
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.
ioInterrupt | – Level of interrupt to activate |
ioAddress | – Hardware IO address |
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.
port | – Valid communications 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.
port | – Port to have its receive buffer zeroed. The port must be in use and disabled. |
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.
port | – Port to have its receive buffer zeroed. The port must be in use and disabled. |
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.
port | – Port needing to be closed. The port must be in use to be closed (as well as valid). |
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.
port | – Port to enable The port I'm getting should be a valid number. |
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.
port | – Port to enable Would it be too much to assume that the port is valid? Probably so. |
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.
port | – Port to check enable status |
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.
port | – Port to check receive buffer |
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.
port | – Port to check send buffer |
Initialize all the important global variables used by the COMIO package.
NOTE: I don't think there are any.
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.
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 |
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.
port | – Port to read from receive buffer. |
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.
port | – Port to send byte out through |
data | – character to send |
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.
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.
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.
port | – Port to change type of |
type | – Type to change port to |
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.
ioInterrupt | – Level of interrupt to deactivate |
ioAddress | – IO address |
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.
ioInterrupt | – Level of interrupt to handle |
extern T_word32 hit_count ; hit_count++ ;