gonzui


Format: Advanced Search

tkernel_2/monitor/hwdepend/tef_em1d/src/sio.cbare sourcepermlink (0.00 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 TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      sio.c
   17:  *
   18:  *       serial port I/O
   19:  */
   20: 
   21: #include "hwdepend.h"
   22: 
   23: EXPORT  W        ConPort;       /* console port number */
   24: EXPORT  UW       ConPortBps;   /* console port commnication speed (bps) */
   25: 
   26: LOCAL   SIOCB     SIO;                /* serial port control block */
   27: 
   28: /*
   29:  * initialize serial port
   30:  *       port    console port number (0 - )
   31:  *              when it is -1, it means there is no console.
   32:  *       speed   communication speed (bps)
   33:  */
   34: EXPORT ER initSIO( W port, W speed )
   35: {
   36:         const CFGSIO   *cp;
   37:         ER     err;
   38: 
   39:         if ( port >= N_ConfigSIO ) port = 0; /* invalid value is turned into a default value. */
   40: 
   41:         memset(&SIO, 0, sizeof(SIO));
   42:         ConPort    = port;
   43:         ConPortBps = speed;
   44: 
   45:         if ( port < 0 ) return E_OK; /* no console */
   46: 
   47:         /* initialize hardware */
   48:         cp = &ConfigSIO[port];
   49:         err = (*cp->initsio)(&SIO, cp, speed);
   50:         if ( err < E_OK ) goto err_ret;
   51: 
   52:         return E_OK;
   53: 
   54: err_ret:
   55:         /* if there was an error, treat it as no console */
   56:         memset(&SIO, 0, sizeof(SIO));
   57:         ConPort = -1;
   58:         return err;
   59: }
   60: 
   61: /*
   62:  * serial port I/O
   63:  */
   64: EXPORT void putSIO( UB c )
   65: {
   66:         if ( SIO.put != NULL ) (*SIO.put)(&SIO, c);
   67: }
   68: 
   69: /*
   70:  * serial port input (with buffering)
   71:  *       tmo     timeout (milliseconds)
   72:  *              You can not wait forever.
   73:  *       return value       >= 0 : character code
   74:  *                 -1 : timeout
   75:  *       receive error is ignored
   76:  */
   77: EXPORT W getSIO( W tmo )
   78: {
   79:         return ( SIO.get != NULL )? (*SIO.get)(&SIO, tmo): -1;
   80: }