uartutil.c
来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 155 行
C
155 行
/* uartutil.c
Copyright 1997 by InterNiche Technologies.
Copyright 1996 by NetPort Software
7/20/96 - Created for NAT DOS demo. John Bartas @ NetPort Software
8/28/97 - Modefied to support raw uart (no modem) as a comline driver -JB-
*/
#include "ipport.h"
#ifdef USE_COMPORT /* whole file can be ifdeffed away */
#include "comline.h"
#include "winuart.h"
#ifdef USE_PPP
#include "ppp_port.h"
#include "../mppp/mppp.h"
#endif /* USE_PPP */
/* define inp() and outp() UART register IO primitives */
#ifndef inp
#define inp(r) (u_char)_inp(r)
#endif
#ifndef outp
#define outp(r,v) _outp(r,v)
#endif
/* the uart's "ln_" routines are needed for direct connections */
int units = 0; /* Assigned units on first come basis */
#ifdef USE_COMPORT
int
ln_uinit(struct com_line * line)
{
int comport;
int unit;
int err;
struct com_win * com;
if(line->ln_state != LN_INITIAL)
{
dtrap(); /* don't call this multiple times */
return 0; /* return OK anyway... */
}
unit = units++; /* assign this line next unit */
err = uart_init(unit); /* open Uart and assign comport */
if(err)
return err; /* report hardware failures */
comport = comport_map[unit]; /* get assigned comport index */
com = &com_ports[comport]; /* get windows com structure */
com->uart_open = TRUE;
com->uart_unit = unit;
com->p_line = line;
line->ln_state = LN_INITIAL;
return 0;
}
/* ln_uconnect() - the comline ln_connect routine for the PC UART */
int
ln_uconnect(struct com_line * line)
{
int err;
struct com_win * com;
int unit = line->lower_unit;
int comport = comport_map[unit];
/* get the com port struct and make sure it's up */
com = &com_ports[comport];
if(line->ln_state == LN_INITIAL)
{
err = ln_uinit(line);
if(err)
return err; /* report hardware failures */
}
line->ln_state = LN_CONNECTED;
#ifdef USE_PPP
/* Indicate to PPP that lower link is now up */
ppp_lowerup((M_PPP)(line->upper_unit), LCP_STATE);
#endif /* USE_PPP */
return 0;
}
/* some routines to map PC uart to InterNiche "line" interface */
int
ln_udisconnect(LINEP line)
{
line->ln_state = LN_DISCONNECTED;
return 0;
}
int
ln_uputc(LINEP line, int byte)
{
return(uart_putc(line->lower_unit, (u_char)byte));
}
/* uart_check() - the uart receive "task". This simply picks up any
bytes which arrived at the UART and hands them to the line receiver.
This is on of those "superloop" spinners which need to be called
when the system is idle...
*/
void
uart_check()
{
int unit;
struct com_win * com;
int uchr;
for(unit = 0; unit < MAXUNITS; unit++)
{
com = &com_ports[ comport_map[unit] ];
if(com->uart_open != unit - 1) /* uart not set up ? */
continue;
if(com->p_line == NULL)
continue;
for(;;)
{
if(com->p_line->ln_getc)
{
uchr = uart_getc(unit); /* check for rx char */
if(uchr == -1) /* no (more) chars, done with this unit */
break;
com->p_line->ln_getc(com->p_line, uchr);
}
else
{
dtrap(); /* p_line has no input routine */
}
}
}
}
#endif /* USE_COMPORT */
#endif /* USE_COMPORT - whole file can be ifdeffed away */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?