FreeBASIC  0.91.0
io_serial.c File Reference
#include "../fb.h"
#include <dos.h>
#include <pc.h>
#include <go32.h>
#include <dpmi.h>
Include dependency graph for io_serial.c:

Go to the source code of this file.

Data Structures

struct  irq_props_t
 
struct  buffer_t
 
struct  comm_props_t
 
struct  DOS_SERIAL_INFO
 

Macros

#define ICU_BASE   0x20
 
#define ICU_OCW2   (ICU_BASE + 0)
 
#define ICU_MASK   (ICU_BASE + 1)
 
#define UART_RBR   0x00 /* DLAB = 0 - Receive Buffer*/
 
#define UART_THR   0x00 /* DLAB = 0 - Transmit Hold */
 
#define UART_IER   0x01 /* interrupt enable register */
 
#define UART_IIR   0x02 /* interrupt ID register */
 
#define UART_FCR   0x02 /* FIFO control register */
 
#define UART_LCR   0x03 /* line control / data format */
 
#define UART_MCR   0x04 /* modem control register */
 
#define UART_LSR   0x05 /* line status register */
 
#define UART_MSR   0x06 /* modem status register */
 
#define UART_SCR   0x07 /* scratch register */
 
#define UART_DL_LSB   0x00 /* DLAB = 1 */
 
#define UART_DL_MSB   0x01 /* DLAB = 1 */
 
#define LCR_DLAB   0x80
 
#define MCR_OUT2   8
 
#define MCR_OUT1   4
 
#define MCR_RTS   2
 
#define MCR_DTR   1
 
#define IER_SINP   8
 
#define IER_EBRK   4
 
#define IER_TBE   2
 
#define IER_RXRD   1
 
#define FLAG_KEEP_DTR   1
 
#define FLAG_SUPPRESS_RTS   2
 
#define UART_IS_NONE   0
 
#define UART_IS_8250   1
 
#define UART_IS_16450   2
 
#define UART_IS_16550   3
 
#define UART_IS_16550A   4
 
#define DEFAULT_BUFFERSIZE   2048
 
#define MAX_BUFFERSIZE   0x40000000
 
#define COMM_CHECKED_CHIPTYPE   1
 
#define COMM_HAVE_BUFFER   2
 
#define FIRST_IRQ   3
 
#define IRQ_COUNT   5
 
#define LAST_IRQ   (FIRST_IRQ+IRQ_COUNT-1)
 
#define MAX_COMM   4
 
#define COMM_PROPS(n)   &comm_props[n-1]
 
#define IRQ_PROPS(n)   &irq_props[n-FIRST_IRQ]
 
#define ENABLE()   enable()
 
#define DISABLE()   disable()
 

Functions

static int UART_detect_chiptype (unsigned int baseaddr)
 
static int UART_set_baud (unsigned int baseaddr, int baud)
 
static int UART_set_data_format (unsigned int baseaddr, int parity, int data, int stop)
 
static int comm_isr (unsigned irq)
 
static int comm_init (int com_num, unsigned int baseaddr, int irq)
 
static void comm_exit (int com_num)
 
static void comm_handler_irq_3 (void)
 
static void comm_handler_irq_4 (void)
 
static void comm_handler_irq_5 (void)
 
static void comm_handler_irq_6 (void)
 
static void comm_handler_irq_7 (void)
 
static int comm_init_irq (irq_props_t *ip)
 
static void comm_exit_irq (irq_props_t *ip)
 
int comm_open (int com_num, int baud, int parity, int data, int stop, int txbufsize, int rxbufsize, int flags, int irq)
 
int comm_close (int com_num)
 
int comm_putc (int com_num, int ch)
 
int comm_getc (int com_num)
 
int comm_bytes_remaining (int com_num)
 
static unsigned int next_pow2 (unsigned int n)
 
static void BUFFER_reset (buffer_t *buf)
 
static int BUFFER_alloc (buffer_t *buf, int size)
 
static void BUFFER_free (buffer_t *buf)
 
static int BUFFER_putc (buffer_t *buf, int ch)
 
static void end_BUFFER_putc (void)
 
static int BUFFER_getc (buffer_t *buf)
 
static void end_BUFFER_getc (void)
 
void end_comm_handler_irq_3 (void)
 
void end_comm_handler_irq_4 (void)
 
void end_comm_handler_irq_5 (void)
 
void end_comm_handler_irq_6 (void)
 
void end_comm_handler_irq_7 (void)
 
static void end_comm_isr (void)
 
static void comm_init_addref (void)
 
static void comm_init_release (void)
 
int fb_SerialOpen (FB_FILE *handle, int iPort, FB_SERIAL_OPTIONS *options, const char *pszDevice, void **ppvHandle)
 
int fb_SerialGetRemaining (FB_FILE *handle, void *pvHandle, fb_off_t *pLength)
 
int fb_SerialWrite (FB_FILE *handle, void *pvHandle, const void *data, size_t length)
 
int fb_SerialRead (FB_FILE *handle, void *pvHandle, void *data, size_t *pLength)
 
int fb_SerialClose (FB_FILE *handle, void *pvHandle)
 

Variables

static int comm_init_count = 0
 
static irq_props_t irq_props [IRQ_COUNT]
 
static comm_props_t comm_props [MAX_COMM]
 

Macro Definition Documentation

#define COMM_CHECKED_CHIPTYPE   1

Definition at line 54 of file io_serial.c.

#define COMM_HAVE_BUFFER   2

Definition at line 55 of file io_serial.c.

#define COMM_PROPS (   n)    &comm_props[n-1]

Definition at line 64 of file io_serial.c.

#define DEFAULT_BUFFERSIZE   2048

Definition at line 51 of file io_serial.c.

#define DISABLE ( )    disable()

Definition at line 144 of file io_serial.c.

#define ENABLE ( )    enable()

Definition at line 143 of file io_serial.c.

#define FIRST_IRQ   3

Definition at line 58 of file io_serial.c.

#define FLAG_KEEP_DTR   1

Definition at line 41 of file io_serial.c.

#define FLAG_SUPPRESS_RTS   2

Definition at line 42 of file io_serial.c.

#define ICU_BASE   0x20

Definition at line 10 of file io_serial.c.

#define ICU_MASK   (ICU_BASE + 1)

Definition at line 12 of file io_serial.c.

#define ICU_OCW2   (ICU_BASE + 0)

Definition at line 11 of file io_serial.c.

#define IER_EBRK   4

Definition at line 36 of file io_serial.c.

#define IER_RXRD   1

Definition at line 38 of file io_serial.c.

#define IER_SINP   8

Definition at line 35 of file io_serial.c.

#define IER_TBE   2

Definition at line 37 of file io_serial.c.

#define IRQ_COUNT   5

Definition at line 59 of file io_serial.c.

#define IRQ_PROPS (   n)    &irq_props[n-FIRST_IRQ]

Definition at line 65 of file io_serial.c.

#define LAST_IRQ   (FIRST_IRQ+IRQ_COUNT-1)

Definition at line 60 of file io_serial.c.

#define LCR_DLAB   0x80

Definition at line 28 of file io_serial.c.

#define MAX_BUFFERSIZE   0x40000000

Definition at line 52 of file io_serial.c.

#define MAX_COMM   4

Definition at line 62 of file io_serial.c.

#define MCR_DTR   1

Definition at line 33 of file io_serial.c.

#define MCR_OUT1   4

Definition at line 31 of file io_serial.c.

#define MCR_OUT2   8

Definition at line 30 of file io_serial.c.

#define MCR_RTS   2

Definition at line 32 of file io_serial.c.

#define UART_DL_LSB   0x00 /* DLAB = 1 */

Definition at line 25 of file io_serial.c.

#define UART_DL_MSB   0x01 /* DLAB = 1 */

Definition at line 26 of file io_serial.c.

#define UART_FCR   0x02 /* FIFO control register */

Definition at line 19 of file io_serial.c.

#define UART_IER   0x01 /* interrupt enable register */

Definition at line 17 of file io_serial.c.

#define UART_IIR   0x02 /* interrupt ID register */

Definition at line 18 of file io_serial.c.

#define UART_IS_16450   2

Definition at line 47 of file io_serial.c.

#define UART_IS_16550   3

Definition at line 48 of file io_serial.c.

#define UART_IS_16550A   4

Definition at line 49 of file io_serial.c.

#define UART_IS_8250   1

Definition at line 46 of file io_serial.c.

#define UART_IS_NONE   0

Definition at line 45 of file io_serial.c.

#define UART_LCR   0x03 /* line control / data format */

Definition at line 20 of file io_serial.c.

#define UART_LSR   0x05 /* line status register */

Definition at line 22 of file io_serial.c.

#define UART_MCR   0x04 /* modem control register */

Definition at line 21 of file io_serial.c.

#define UART_MSR   0x06 /* modem status register */

Definition at line 23 of file io_serial.c.

#define UART_RBR   0x00 /* DLAB = 0 - Receive Buffer*/

Definition at line 15 of file io_serial.c.

#define UART_SCR   0x07 /* scratch register */

Definition at line 24 of file io_serial.c.

#define UART_THR   0x00 /* DLAB = 0 - Transmit Hold */

Definition at line 16 of file io_serial.c.

Function Documentation

static int BUFFER_alloc ( buffer_t buf,
int  size 
)
static

Definition at line 212 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void BUFFER_free ( buffer_t buf)
static

Definition at line 231 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static int BUFFER_getc ( buffer_t buf)
static

Definition at line 256 of file io_serial.c.

Here is the caller graph for this function:

static int BUFFER_putc ( buffer_t buf,
int  ch 
)
static

Definition at line 243 of file io_serial.c.

Here is the caller graph for this function:

static void BUFFER_reset ( buffer_t buf)
static

Definition at line 202 of file io_serial.c.

Here is the caller graph for this function:

int comm_bytes_remaining ( int  com_num)

Definition at line 884 of file io_serial.c.

Here is the caller graph for this function:

int comm_close ( int  com_num)

Definition at line 832 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void comm_exit ( int  com_num)
static

Definition at line 701 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void comm_exit_irq ( irq_props_t ip)
static

Definition at line 587 of file io_serial.c.

Here is the caller graph for this function:

int comm_getc ( int  com_num)

Definition at line 873 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void comm_handler_irq_3 ( void  )
static

Definition at line 396 of file io_serial.c.

Here is the caller graph for this function:

static void comm_handler_irq_4 ( void  )
static

Definition at line 397 of file io_serial.c.

Here is the caller graph for this function:

static void comm_handler_irq_5 ( void  )
static

Definition at line 398 of file io_serial.c.

Here is the caller graph for this function:

static void comm_handler_irq_6 ( void  )
static

Definition at line 399 of file io_serial.c.

Here is the caller graph for this function:

static void comm_handler_irq_7 ( void  )
static

Definition at line 400 of file io_serial.c.

Here is the caller graph for this function:

static int comm_init ( int  com_num,
unsigned int  baseaddr,
int  irq 
)
static

Definition at line 596 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void comm_init_addref ( void  )
static

Definition at line 493 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static int comm_init_irq ( irq_props_t ip)
static

Definition at line 546 of file io_serial.c.

Here is the caller graph for this function:

static void comm_init_release ( void  )
static

Definition at line 519 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static int comm_isr ( unsigned  irq)
static

Definition at line 404 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int comm_open ( int  com_num,
int  baud,
int  parity,
int  data,
int  stop,
int  txbufsize,
int  rxbufsize,
int  flags,
int  irq 
)

Definition at line 768 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int comm_putc ( int  com_num,
int  ch 
)

Definition at line 854 of file io_serial.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void end_BUFFER_getc ( void  )
static

Definition at line 267 of file io_serial.c.

static void end_BUFFER_putc ( void  )
static

Definition at line 254 of file io_serial.c.

void end_comm_handler_irq_3 ( void  )

Definition at line 396 of file io_serial.c.

Here is the call graph for this function:

void end_comm_handler_irq_4 ( void  )

Definition at line 397 of file io_serial.c.

Here is the call graph for this function:

void end_comm_handler_irq_5 ( void  )

Definition at line 398 of file io_serial.c.

Here is the call graph for this function:

void end_comm_handler_irq_6 ( void  )

Definition at line 399 of file io_serial.c.

Here is the call graph for this function:

void end_comm_handler_irq_7 ( void  )

Definition at line 400 of file io_serial.c.

Here is the call graph for this function:

static void end_comm_isr ( void  )
static

Definition at line 491 of file io_serial.c.

int fb_SerialClose ( FB_FILE handle,
void *  pvHandle 
)

Definition at line 1038 of file io_serial.c.

Here is the caller graph for this function:

int fb_SerialGetRemaining ( FB_FILE handle,
void *  pvHandle,
fb_off_t pLength 
)

Definition at line 968 of file io_serial.c.

Here is the caller graph for this function:

int fb_SerialOpen ( FB_FILE handle,
int  iPort,
FB_SERIAL_OPTIONS options,
const char *  pszDevice,
void **  ppvHandle 
)

Definition at line 896 of file io_serial.c.

Here is the caller graph for this function:

int fb_SerialRead ( FB_FILE handle,
void *  pvHandle,
void *  data,
size_t *  pLength 
)

Definition at line 1008 of file io_serial.c.

Here is the caller graph for this function:

int fb_SerialWrite ( FB_FILE handle,
void *  pvHandle,
const void *  data,
size_t  length 
)

Definition at line 984 of file io_serial.c.

Here is the caller graph for this function:

static unsigned int next_pow2 ( unsigned int  n)
inlinestatic

Definition at line 190 of file io_serial.c.

Here is the caller graph for this function:

static int UART_detect_chiptype ( unsigned int  baseaddr)
static

Definition at line 269 of file io_serial.c.

Here is the caller graph for this function:

static int UART_set_baud ( unsigned int  baseaddr,
int  baud 
)
static

Definition at line 306 of file io_serial.c.

Here is the caller graph for this function:

static int UART_set_data_format ( unsigned int  baseaddr,
int  parity,
int  data,
int  stop 
)
static

Definition at line 331 of file io_serial.c.

Here is the caller graph for this function:

Variable Documentation

int comm_init_count = 0
static

Definition at line 163 of file io_serial.c.

comm_props_t comm_props[MAX_COMM]
static
Initial value:
= {
{ 0x3f8, 4, 4, 0, 0, 0, 0, 0 },
{ 0x2f8, 3, 3, 0, 0, 0, 0, 0 },
{ 0x3e8, 4, 4, 0, 0, 0, 0, 0 },
{ 0x2e8, 3, 3, 0, 0, 0, 0, 0 }
}

Definition at line 183 of file io_serial.c.

irq_props_t irq_props[IRQ_COUNT]
static
Initial value:
= {
{ 0, 0, 0, 3, 0xb, comm_handler_irq_3 },
{ 0, 0, 0, 4, 0xc, comm_handler_irq_4 },
{ 0, 0, 0, 5, 0xd, comm_handler_irq_5 },
{ 0, 0, 0, 6, 0xe, comm_handler_irq_6 },
{ 0, 0, 0, 7, 0xf, comm_handler_irq_7 }
}

Definition at line 166 of file io_serial.c.