📄 mdmport.c
字号:
/*
* FILENAME: mdmport.c
*
* Copyright 1997- 2001 By InterNiche Technologies Inc. All rights reserved
* Portions Copyright 1996 by NetPort Software.
*
* This file contains the Port dependant portions of modem dialer & login
* code. In practice this rarely needs to be modified.
*
*
* MODULE: MODEM
*
* ROUTINES: dial_delay(), modem_portstat(), hangup(), modem_DCD(),
*
* PORTABLE: usually
*/
#include "mdmport.h"
#ifdef USE_MODEM /* whole file can be ifdeffed out */
#ifdef IN_MENUS
#include "menu.h"
#endif /* IN_MENUS */
#ifdef INCLUDE_NVPARMS
#include "nvparms.h"
#endif /* INCLUDE_NVPARMS */
#ifdef INCLUDE_NVPARMS
struct modem_nvparam modem_nvparms;
extern struct nvparm_format modem_format;
#endif /* INCLUDE_NVPARMS */
#ifdef IN_MENUS
extern int dialer_status(void * pio);
extern int hangup (void * pio);
extern int direct_dial (void * pio);
struct menu_op modem_menu[] = {
"modem", stooges, "Modem Commands",
"hangup", hangup, "hang up (and reset) the modem",
/* the following line is a nice idea and the correct way to do this, however
* the ARM SDT 2.50 C compiler botches the "if defined() && " operation. It
* includes the following line even when PPP_MENU is NOT defined anywhere.
* We have to use two seperate "ifdef" lines to force it to do the right
* thing.
#if defined(USE_PPP) && defined(PPP_MENU) <- breaks ARM C !!!!
*/
#ifdef USE_PPP
#ifdef PPP_MENU
"dialup", direct_dial, "dial up the modem",
#endif /* PPP_MENU */
#endif /* USE_PPP */
#ifdef NET_STATS
"modem", dialer_status, "modem, dialer, and UART info",
#endif
NULL, NULL, NULL,
};
#endif /* IN_MENUS */
/* FUNCTION: prep_modem()
*
* PARAMS: NONE
*
* RETURNS: Error Code or 0 for OK
*/
int prep_modem(void)
{
int e = 0;
#ifdef IN_MENUS
/* install the Modem Commands */
install_menu(&modem_menu[0]);
#endif /* IN_MENUS */
#ifdef INCLUDE_NVPARMS
e = install_nvformat(&modem_format, nv_formats);
if(e)
{
dprintf("unable to install Modem NVPARMS, reconfigure nv_formats[]\n");
dtrap("mdmport 0\n");
}
#else
strcpy(mdm_dial_string, "YOUR_ISP_PHONE\n");
strcpy(mdm_init_string, "AT&D0&C1\n");
#endif /* INCLUDE_NVPARMS */
return e;
}
/* FUNCTION: dial_delay()
*
* Allow task loop to spin for N ticks without
* re-entring dialer code. This may need to be changed for RTOS
* system ports.
*
* PARAM1: unsigned long ticks
*
* RETURNS: void
*/
void
dial_delay(unsigned long ticks)
{
#ifdef SUPERLOOP
unsigned long stoptime;
in_dialcheck++; /* keep tk_yield out of dial_check() */
stoptime = cticks + ticks; /* set time to exit dial_delay() */
while(cticks < stoptime)
tk_yield(); /* let tasks spin until time */
in_dialcheck--;
#else /* not SUPERLOOP, do multitasking version */
TK_SLEEP(ticks); /* let tasking system do the delay */
#endif
}
/* FUNCTION: modem_portstat()
*
* PARAM1: void * pio
* PARAM2: MODEMP modemp
*
* RETURNS: void
*/
/* pointer to per-port UART stats routine */
int (*port_uartstat)(void * pio, int unit) = NULL;
void
modem_portstat(void * pio, MODEMP modemp)
{
#ifdef PC_UART
unshort port;
unshort mask; /* bit values read from MSR */
port = (unshort)ubase + 6;
mask = (u_char)inp(port);
ns_printf(pio, "modem unit %d, DCD(%x): 0x%02x, ", modemp->unit, port, mask);
ns_printf(pio, "Lines(%x): 0x%02x\n", port, mask);
#else /* unsupported UART */
if(port_uartstat) /* did init logic install a stats routine? */
port_uartstat(pio, modemp->unit); /* call it... */
else
ns_printf(pio, "Stats Not implemented for this UART\n");
#endif
}
/* hangup() for use by demo's menu system */
int hangup(void *pio)
{
USE_VOID(pio);
return(modem_hangup(modems[0].upperline));
}
/* FUNCTION: modem_DCD()
*
* Returns TRUE if Carrier detect is down, FALSE if up.
*
* PARAM1: MODEMP modemp
*
* RETURNS: TRUE if Carrier detect is down, FALSE if up.
*/
int
modem_DCD(MODEMP modemp)
{
#ifdef MDM_DCDLINE
return (uart_getDCD(modemp->unit));
#else /* no uart specific MDM_DCDLINE routine provided */
/* stubbed out due to lack of DCD on many UART implementations. */
if(modemp->upperline->ln_state == D_CONNECTED)
return FALSE;
else
return TRUE;
#endif /* MDM_DCDLINE or not... */
}
#ifdef INCLUDE_NVPARMS
/* Please see nvparms.h and nvparms.c regarding the usage of
* the following datatypes and functions.
*/
struct nvparm_info modem_nvformats[] =
{
{"Phone Number: %s\n", NVSTRING, MAX_NVSTRING, \
&modem_nvparms.dial_phone[0], NULL, },
{"Modem Init: %s\n" , NVSTRING, MAX_NVSTRING, \
&modem_nvparms.modem_init[0], NULL, },
};
#define NUMMODEM_FORMATS \
(sizeof(modem_nvformats)/sizeof(struct nvparm_info))
/* FUNCTION: modem_nvset()
*
* PARAM1: NV_FILE * fp
*
* RETURNS: Silent return of 0 for OK
*/
int modem_nvset(NV_FILE * fp)
{
int i = 0;
/* Modem / dialup section */
nv_fprintf(fp, modem_nvformats[i++].pattern, modem_nvparms.dial_phone);
nv_fprintf(fp, modem_nvformats[i++].pattern, modem_nvparms.modem_init);
return 0;
}
struct nvparm_format modem_format =
{
NUMMODEM_FORMATS,
&modem_nvformats[0],
modem_nvset,
NULL
};
#endif /* INCLUDE_NVPARMS */
#endif /* USE_MODEM */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -