gonzui


Format: Advanced Search

mtkernel_3/lib/libtm/sysdepend/iote_rx231/tm_com.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.04
    4:  *
    5:  *    Copyright (C) 2006-2021 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.2.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2021/05/17.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *    tm_com.c
   16:  *    T-Monitor Communication low-level device driver (RX231 IoT-Engine)
   17:  */
   18: 
   19: #include <tk/tkernel.h>
   20: #include <sys/sysdef.h>
   21: 
   22: #if USE_TMONITOR
   23: #include "../../libtm.h"
   24: 
   25: #ifdef IOTE_RX231
   26: #if TM_COM_SERIAL_DEV
   27: 
   28: #define INTNO_TXI6      226
   29: #define INTNO_RXI6      227
   30: 
   31: #define PCLK            (27000000UL)              /* P Clock(24MHz) */
   32: #define ICLK            (54000000UL)              /* I Clock(48MHz) */
   33: #define RS_BAUD_RATE    (115200)           /* 115.2kbps */
   34: 
   35: #define SCI6_SMR        (0x008A0C0UL)          /* Serial mode register */
   36: #define SCI6_BRR        (0x008A0C1UL)          /* Bit rate register */
   37: #define SCI6_SCR        (0x008A0C2UL)          /* Serial control register */
   38: #define SCI6_TDR        (0x008A0C3UL)          /* Transmit data register */
   39: #define SCI6_SSR        (0x008A0C4UL)          /* Serial status register */
   40: #define SCI6_RDR        (0x008A0C5UL)          /* Receive data register */
   41: #define SCI6_SCMR       (0x008A0C6UL)         /* Smartcard mode register */
   42: 
   43: #define SCR_TIE         (0x80)                 /* Transmit interrupt enable */
   44: #define SCR_RIE         (0x40)                 /* Receive interrupt ebable */
   45: #define SCR_TE          (0x20)                  /* Transmit enable */
   46: #define SCR_RE          (0x10)                  /* Receive enable */
   47: 
   48: #define SSR_TDRE        (0x80)                 /* Transmit data empty */
   49: #define SSR_RDRF        (0x40)                 /* Receive data full */
   50: #define SSR_ERR         (0x38)                 /* Error */
   51: 
   52: EXPORT  void     tm_snd_dat( const UB* buf, INT size )
   53: {
   54:         UB     *b;
   55: 
   56:         for( b = (UB *)buf; size > 0; size--, b++ ){
   57:                 while( (in_b(SCI6_SSR) & SSR_TDRE) == 0);
   58:                 out_b( SCI6_TDR, *b );
   59:         }
   60: }
   61: 
   62: EXPORT  void     tm_rcv_dat( UB* buf, INT size )
   63: {
   64:         UB     ssr;
   65: 
   66:         for( ; size > 0; size--, buf++ ){
   67:                 while(1) {
   68:                         ssr = in_b(SCI6_SSR);
   69:                         if( (ssr & SSR_RDRF) != 0) {
   70:                                 *buf = in_b( SCI6_RDR );
   71:                                 break;
   72:                         } else if( ssr & SSR_ERR ) { /* check Communication error */
   73:                                 out_b( SCI6_SSR, ssr & ~SSR_ERR);
   74:                         }
   75:                 }
   76:         }
   77: }
   78: 
   79: EXPORT  void     tm_com_init(void)
   80: {
   81:         _UW    dly;
   82: 
   83:         /* Initialize SCI6 */
   84:         out_b(SCI6_SCR, 0x00);                         // TE = 0 RE = 0
   85:         out_b(SCI6_SCMR, 0xF2);                                // LSB first
   86:         out_b(SCI6_SMR, 0x00);                         // Data8 Stop1
   87:         out_b(SCI6_BRR, (PCLK / (64 / 2 * RS_BAUD_RATE)) - 1); // 115.2kbps
   88: 
   89:         dly = ICLK/5/RS_BAUD_RATE;
   90:         while ((dly--) != 0) ;
   91: 
   92:         out_b(SCI6_SCR, 0x30);                         // TE = 1 RE = 1
   93: }
   94: 
   95: #endif /* TM_COM_SERIAL_DEV */
   96: #endif /* IOTE_RX231 */
   97: #endif /* USE_TMONITOR */