?? diti.c
字號(hào):
/* @(#) pSOSystem PowerPC/V2.2.2: drivers/diti.c 2.53 97/10/22 18:43:44 */
/***********************************************************************/
/* */
/* MODULE: diti.c */
/* DATE: 97/10/22 */
/* PURPOSE: Device Independent Terminal Interface. */
/* */
/*---------------------------------------------------------------------*/
/* */
/* Copyright 1994 - 1996, Integrated Systems, Inc. */
/* ALL RIGHTS RESERVED */
/* */
/* Permission is hereby granted to licensees of Integrated Systems, */
/* Inc. products to use or abstract this computer program for the */
/* sole purpose of implementing a product based on Integrated */
/* Systems, Inc. products. No other rights to reproduce, use, */
/* or disseminate this computer program, whether in part or in */
/* whole, are granted. */
/* */
/* Integrated Systems, Inc. makes no representation or warranties */
/* with respect to the performance of this computer program, and */
/* specifically disclaims any responsibility for any damages, */
/* special or consequential, connected with the use of this program. */
/* */
/*---------------------------------------------------------------------*/
/* */
/* */
/* */
/***********************************************************************/
#include <types.h>
#include <psos.h>
#include <drv_intf.h>
#include <pna.h>
#include <gsblk.h>
#include <disi.h>
#include <diti.h>
#include <configs.h>
#include "bsp.h"
#include <bspfuncs.h>
#include <ctype.h>
#include <phile.h>
/*---------------------------------------------------------------------*/
/* Names of the semaphores used by the devices - "n" is replaced by a */
/* decimal digit corresponding to the minor device number that the */
/* semaphore is associated with. */
/*---------------------------------------------------------------------*/
#define READ_NAME "RDAn" /* read access control */
#define WRITE_NAME "WRAn" /* write access control */
#define RXQUE_NAME "RXQn" /* receive que */
#define CANQUE_NAME "CNQn" /* Canononical que */
#define TXCOMP_NAME "TXCn" /* transmit complete */
#define IOCTL_NAME "CTLn" /* I/O control call complete */
#define bzero(pt,statlen) \
{ \
static int n; \
unsigned char *s; \
s = (unsigned char *)pt; \
for(n=1;n<=statlen;n++) \
*(s++)=0; \
}
typedef struct
{
ULONG lid; /* lower reference pointer */
ULONG hdwflags; /* hardware flags returned by */
/* lower driver */
ULONG dflags; /* driver flags */
ULONG rda_id; /* read access semaphore ID */
ULONG wra_id; /* write access semaphore ID */
ULONG rxq_id; /* receive queue ID */
ULONG can_id; /* Canonical queue ID */
ULONG txc_id; /* transmit complete semaphore ID */
ULONG ctl_id; /* I/O control complete semaphore ID */
mblk_t *rdmblk; /* pointer to current read */
/* message block from recv queue */
mblk_t *cnmblk; /* pointer to current read message */
/* block from canonical queue */
mblk_t *echo_mblk; /* mblock pointer used for echo */
mblk_t *rqhead; /* Head of the MBUF's in Recv Q */
mblk_t *rqtail; /* Tail of the MBUF's in Recv Q */
UCHAR *echo_rwprt; /* place to save read/write pointer */
ULONG rdbflg; /* bite wise status of RDMBLK */
UCHAR LineMode; /* Sync/Async */
UCHAR num_open; /* number of opens done */
struct termio termio;
} ChanCfg;
/*---------------------------------------------------------------------*/
/* Baud rate table */
/*---------------------------------------------------------------------*/
const ULONG baud_table[] ={0,
50,
75,
110,
134,
150,
200,
300,
600,
1200,
1800,
2400,
4800,
9600,
19200,
38400};
/*---------------------------------------------------------------------*/
/* Values for DFLAGS. (bit wise flags) */
/*---------------------------------------------------------------------*/
#define OPENED 0x1
#define CONNECTED 0x2
#define WAITING 0x4
#define ABORTED 0x8
/*---------------------------------------------------------------------*/
/* Characters of interest. */
/*---------------------------------------------------------------------*/
#define CEOF 04 /* Control-d */
#define CSTART 021 /* Control-q */
#define CSTOP 023 /* Control-s */
#define EOT CEOF
#define BS 0x08
#define NL 0x0A /* '\n' */
#define CR 0x0D /* '\r' */
#define SPACE 0x20
#define XON CSTART
#define XOFF CSTOP
/*---------------------------------------------------------------------*/
/* Receive buffer size that will be passed to DISI */
/*---------------------------------------------------------------------*/
#define RBUFFSIZE 32
/*---------------------------------------------------------------------*/
/* Term_Init_Done used to check if TermInit has been done. */
/*---------------------------------------------------------------------*/
unsigned long Term_Init_Done;
/*---------------------------------------------------------------------*/
/* This is the array of the data areas of each of the minor devices */
/* present. */
/*---------------------------------------------------------------------*/
static ChanCfg DChanCfg[BSP_SERIAL + 1];
/*---------------------------------------------------------------------*/
/* SysConsole is the channel that is to be used a a console. If a */
/* minor number of 0 is passed in to any of the DICI function calls */
/* the actual channel number used will be SysConsole. */
/* In this way the user may select the channel to be used as standard */
/* input and output. */
/* NOTE: SysConsole is set in sysinit to SC_APP_CONSOLE. */
/*---------------------------------------------------------------------*/
extern int SysConsole;
/*---------------------------------------------------------------------*/
/* Prototypes of functions */
/*---------------------------------------------------------------------*/
void term_dataind(Uid, mblk_t *, unsigned long);
void term_expind(Uid, unsigned long);
void term_datacnf(Uid, mblk_t *, unsigned long);
void term_ctlcnf(Uid, unsigned long);
ULONG opost(UCHAR *, mblk_t *, ULONG, USHORT);
static int doctl(Lid lid, unsigned long cmd,
void *arg, struct ioparms *parms);
/*---------------------------------------------------------------------*/
/* FOREVER used for semaphores to indicate they should wait until */
/* released */
/*---------------------------------------------------------------------*/
#define FOREVER 0
/*---------------------------------------------------------------------*/
/* anchor used to get number of ticks per second */
/*---------------------------------------------------------------------*/
extern NODE_CT *anchor;
/*---------------------------------------------------------------------*/
/* Pointer used to re-initialize the Serial Buffer pool. */
/*---------------------------------------------------------------------*/
extern UCHAR *GSblkBase;
/*---------------------------------------------------------------------*/
/* Prototype for initialization of pMONT port. */
/*---------------------------------------------------------------------*/
void init_pmont_serial(struct ioparms *);
/***********************************************************************/
/* StringCopy: Copy a character string */
/* */
/* INPUTS: destination = ptr to destination string */
/* source = ptr to source string */
/* */
/***********************************************************************/
static void StringCopy(char *destination, char *source)
{
while (*destination++ = *source++);
}
/***********************************************************************/
/* cleanup: Return all system resources because an error occurred */
/* during initialization. */
/* */
/* INPUT: chancfg = pointer to channel's configuration */
/* parameters */
/* NOTE: This is called by TermOPEN() if an error occurs */
/* during open. */
/***********************************************************************/
static void cleanup(ChanCfg *chancfg)
{
sm_delete(chancfg->rda_id);
sm_delete(chancfg->wra_id);
q_delete(chancfg->rxq_id);
q_delete(chancfg->can_id);
sm_delete(chancfg->txc_id);
sm_delete(chancfg->ctl_id);
SerialClose((Lid )chancfg->lid);
}
/***********************************************************************/
/* TermInit: initialize the Terminal Driver. */
/* */
/* NOTE(S): The initialization should only be done once per 'GS'. */
/* The IDLE task's Scratch Pad Registers are used to */
/* track if 'GS' has been done or not. */
/* */
/***********************************************************************/
void TermInit (struct ioparms *parms)
{
int i, p, DoClose;
extern int NumNon_pSOSChan, Non_pSOSChan[];
ULONG rc, imask;
mblk_t *tmblk;
/*---------------------------------------------------------------------*/
/* Set elements of the ioparms structure to their default values. */
/* used - will tell pSOS we're using stack interface */
/* out_retval - is used to pass additional error information to the */
/* user. */
/* err - will contain an error code (0 for success) */
/*---------------------------------------------------------------------*/
parms->used = 1;
parms->out_retval = 0;
parms->err = 0;
rc = ScratchPadTest(IDLE_TID, DRV_INIT_REG, DMAJOR(parms->in_dev));
if (rc == SP_BIT_SET)
return;
if (rc != SP_BIT_NOT_SET)
{
parms->err = rc;
return;
}
if ((rc = ScratchPadSet(IDLE_TID, DRV_INIT_REG, DMAJOR(parms->in_dev)))
!= SP_OK)
{
parms->err = rc;
return;
}
/*---------------------------------------------------------------------*/
/* To insure that this driver is in sync with the lower driver on */
/* warm starts, it must call the lower driver for all ports that it */
/* thinks are open so that the lower driver can clean them up. */
/*---------------------------------------------------------------------*/
for(i = 1; i < (BSP_SERIAL + 1); i++)
{
/*-----------------------------------------------------------------*/
/* The driver does not want to close those ports that have been */
/* opened by a non pSOS element, such as pROBE. NumNon_pSOSPorts */
/* is a variable set during system initialization (before pSOS) to */
/* the number of ports in the Non_pSOSPort list. Non_pSOSPort is a */
/* list of non pSOS ports also created during system */
/* initialization. */
/*-----------------------------------------------------------------*/
DoClose = 1;
for(p = 0; p < NumNon_pSOSChan; p++)
{
if(Non_pSOSChan[p] == i)
{
DoClose = 0;
break;
}
}
if(DoClose)
if(DChanCfg[i].dflags & OPENED && DChanCfg[i].lid)
SerialClose((Lid)(DChanCfg[i].lid));
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -