gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/console/src/line_drv.hbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2013/03/01.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      line_drv.h   Console/Low level serial I/O driver
   18:  *
   19:  *              Low-level driver common definition : System-independent
   20:  */
   21: 
   22: #include <basic.h>
   23: #include <device/serialio.h>
   24: #include <device/rs.h>
   25: #include <tk/tkernel.h>
   26: #include <tk/util.h>
   27: #include <sys/imalloc.h>
   28: #include <sys/util.h>
   29: #include <libstr.h>
   30: 
   31: #define DEF_INBUFSZ     2048        /* Standard receive-buffer size */
   32: #define MIN_INBUFSZ     256 /* Minimum receive-buffer size */
   33: #define OUBUFSZ         512    /* Send-buffer size:Fixed */
   34: 
   35: /* Error information */
   36: typedef union {
   37:         RsError        c;
   38:         RsStat s;
   39:         ER     w;
   40: } RsErr;
   41: 
   42: /* Flow control status */
   43: typedef struct {
   44:         UB     reqchar:8;  /* Send-request character */
   45:         UW     rsoff:1;    /* Receive-stop status by "RS = OFF" */
   46:         UW     sndxoff:1;  /* Receive-stop status by sending "XOFF" */
   47: } FlowState;
   48: 
   49: /* Controller operation function groups */
   50: struct _L_INFO;
   51: typedef struct {
   52:         ER     (*in)(struct _L_INFO *li, UB *buf, W len, W *alen, W tmout);
   53:         ER     (*out)(struct _L_INFO *li, UB *buf, W len, W *alen, W tmout);
   54:         ER     (*ctl)(struct _L_INFO *li, W kind, UW *arg);
   55:         void   (*up)(struct _L_INFO *li);
   56:         void   (*down)(struct _L_INFO *li);
   57: } SC_FUNC;
   58: 
   59: /* Controller information */
   60: typedef struct {
   61:         SC_FUNC        *fn;           /* Controller operation function groups */
   62:         RsHwConf_16450 c;      /* Port HW configuration */
   63:         UB     fctl;               /* Port HW register information*/
   64:         UB     dt[3];              /* Port HW other information */
   65:         RsMode mode;           /* Default line mode */
   66:         RsFlow flow;           /* Default flow control mode */
   67:         FlowState flowsts;     /* Default flow control state */
   68: } SC_DEFS;
   69: 
   70: /* Serial line management information */
   71: typedef struct _L_INFO {
   72:         SC_DEFS        scdefs;                /* Controller operation function definition */
   73:         UW     suspend:1;  /* 1 when it is a "suspend" status */
   74:         UW     enbint:1;   /* 1 when it is an interrupt-enabled status */
   75: 
   76:         FastMLock lock;                /* Lock for output and input */
   77:         ID     flg;                /* Flag for the input-output interrupt wait */
   78: 
   79:         RsMode mode;           /* Line mode */
   80:         RsFlow flow;           /* Flow control mode */
   81:         FlowState flowsts;     /* Flow control status */
   82: 
   83:         FUNCP  extfn;           /* External function */
   84:         UW     extpar;             /* External function parameter */
   85:         UB     lsts;               /* Current line error status */
   86:         UB     lstshist;   /* Line error history status */
   87:         UB     msts;               /* Current modem status */
   88: 
   89:         UW     in_rptr;    /* Input-buffer read pointer */
   90:         UW     in_wptr;    /* Input-buffer writing pointer */
   91:         UW     in_bufsz;   /* Input-buffer size */
   92:         UB     *in_buf;    /* Top of input-buffer area */
   93: 
   94:         UW     ou_rptr;    /* Output-buffer read pointer */
   95:         UW     ou_wptr;    /* Output-buffer writing pointer */
   96: 
   97:         UW     ou_cnt;             /* Output-data counter */
   98:         UW     ou_len;             /* Output-data size */
   99:         UB     ou_buf[OUBUFSZ];    /* Output-buffer */
  100: } LINE_INFO;
  101: 
  102: #define XOFF_MARGIN     64  /* Remaining size that sends "XOFF" */
  103: #define XON_MARGIN      128  /* Remaining size that send "XON" */
  104: 
  105: /* Send-buffer pointer mask */
  106: #define OU_PTRMASK(p, ptr)      ((ptr) % OUBUFSZ)
  107: 
  108: /* Receive-buffer pointer mask */
  109: #define PTRMASK(p, ptr)         ((ptr) % ((p)->in_bufsz))
  110: 
  111: /* Remaining size of receive-buffer */
  112: #define IN_BUF_REMAIN(p)        ((p->in_rptr >= p->in_wptr) ?          \
  113:                                  (p->in_rptr - p->in_wptr) :                \
  114:                                  (p->in_rptr + p->in_bufsz - p->in_wptr))
  115: 
  116: /* Received size of receive-buffer */
  117: #define IN_BUF_SIZE(p)          ((p->in_wptr >= p->in_rptr) ?           \
  118:                                  (p->in_wptr - p->in_rptr) :                \
  119:                                  (p->in_wptr + p->in_bufsz - p->in_rptr))
  120: 
  121: /* Control code */
  122: #define XOFF            ('S'-'@')
  123: #define XON             ('Q'-'@')
  124: 
  125: /* Return code */
  126: typedef enum {
  127:         RTN_OK         = 0,
  128:         RTN_NONE       = -1,
  129:         RTN_TMOUT      = -2,
  130:         RTN_ABORT      = -3,
  131:         RTN_ERR                = -4
  132: } RTN;
  133: typedef W       WRTN;
  134: 
  135: /* Pattern of control flag */
  136: #define OU_LOCK         17
  137: #define IN_LOCK         16
  138: #define FLG_OU_ABORT    (1 << 3)
  139: #define FLG_OU_NORM     (1 << 2)
  140: #define FLG_IN_ABORT    (1 << 1)
  141: #define FLG_IN_NORM     (1 << 0)
  142: #define FLG_OU_WAIPTN   (FLG_OU_NORM | FLG_OU_ABORT)
  143: #define FLG_IN_WAIPTN   (FLG_IN_NORM | FLG_IN_ABORT)
  144: 
  145: /* Get/Release memory*/
  146: #define Malloc(len)     (void*)Imalloc(len)
  147: #define Free(ptr)       Ifree((void*)(ptr))
  148: 
  149: /* Serial line management information */
  150: IMPORT  W                nPorts;
  151: IMPORT  LINE_INFO        *LineInfo;
  152: IMPORT  W                DebugPort;
  153: 
  154: /* True if it is a debug port */
  155: #define isDebugPort(li)         ( (li) == &LineInfo[DebugPort] )
  156: 
  157: /* Lock */
  158: IMPORT  ER       consMLock(FastMLock *lock, INT no);
  159: IMPORT  ER       consMUnlock(FastMLock *lock, INT no);
  160: IMPORT  ER       consCreateMLock(FastMLock *lock, UB *name);
  161: IMPORT  ER       consDeleteMLock(FastMLock *lock);