gonzui


Format: Advanced Search

mtkernel_3/kernel/sysdepend/iote_rx231/hw_setting.cbare sourcepermlink (0.03 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.03
    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/03/31.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: #include <sys/machine.h>
   14: #ifdef IOTE_RX231
   15: 
   16: /*
   17:  *      hw_setting.c (RX231 IoT-Engine)
   18:  *              hardware settings
   19:  */
   20: 
   21: #include "kernel.h"
   22: #include <tm/tmonitor.h>
   23: 
   24: #include "sysdepend.h"
   25: 
   26: /* ------------------------------------------------------------------------ */
   27: /* 
   28:  * Setup register data 
   29:  */
   30: typedef struct {
   31:         UW     addr;
   32:         UW     data;
   33: } T_SETUP_REG;
   34: 
   35: /* 
   36:  * Setup module stop Tadle
   37:  */
   38: LOCAL const T_SETUP_REG mstop_tbl[] = {
   39:         { MSTPCRA, MSTPCRA_INI },
   40:         { MSTPCRB, MSTPCRB_INI },
   41:         { MSTPCRC, MSTPCRC_INI },
   42:         { MSTPCRD, MSTPCRD_INI },
   43:         {0, 0}
   44: };
   45: 
   46: /* 
   47:  * Setup pin functions Tadle
   48:  */
   49: LOCAL const T_SETUP_REG pinfnc_tbl[] = {
   50:         {MPC_PBnPFS(0), 0x0B},         /* PB0 = SCI6.RXD6 */
   51:         {MPC_PBnPFS(1), 0x0B},         /* PB1 = SCI6.TXD6 */
   52: 
   53: #if USE_SDEV_DRV        // Use the sample device driver
   54:         {MPC_P1nPFS(6), 0x0F},         /* P16 = SCL0 */
   55:         {MPC_P1nPFS(7), 0x0F},         /* P17 = SDA0 */
   56:         {MPC_P4nPFS(0), 0x80},         /* P40 = AN000 */
   57:         {MPC_P4nPFS(1), 0x80},         /* P41 = AN001 */
   58:         {MPC_P4nPFS(2), 0x80},         /* P42 = AN002 */
   59: #endif /* USE_SDEV_DRV */
   60: 
   61:         {0, 0}
   62: };
   63: 
   64: /* 
   65:  * Setup port mode Tadle
   66:  */
   67: LOCAL const T_SETUP_REG portmode_tbl[] = {
   68:         {PORTB_PMR, 0x03},             /* Set PB0&PB1 as a peripheral function. */
   69: 
   70: #if USE_SDEV_DRV        // Use the sample device driver
   71:         {PORT1_PMR, 0xC0},             // P16-P17 peripheral function
   72:         {PORT1_ODR1, 0x50},            // P16-O17 open drain
   73:         {PORT4_PMR, 0x00},             /* P40-P42 General-purpose i/o port */
   74:         {PORT4_PDR, 0x00},             /* P40-P42 input port */
   75: #endif /* USE_SDEV_DRV */
   76: 
   77:         {0, 0}
   78: };
   79: 
   80: /*
   81:  * Startup hardware
   82:  */
   83: EXPORT void knl_startup_hw(void)
   84: {
   85:         const T_SETUP_REG      *p;
   86: 
   87:         /* Setup module stop */
   88:         out_h(SYSTEM_PRCR, 0xA502);            /* Disable Register Protect */
   89:         for(p = mstop_tbl; p->addr != 0; p++) {
   90:                 out_w(p->addr, p->data);
   91:         }
   92:         out_h(SYSTEM_PRCR, 0xA500);            /* Enable Register protect */
   93: 
   94:         /* Setup Pin Function */
   95:         out_b(MPC_PWPR, 0);
   96:         out_b(MPC_PWPR, MPC_PWMR_PFSWE);       /* Disable Register Protect */
   97:         for(p = pinfnc_tbl; p->addr != 0; p++) {
   98:                 out_b(p->addr, (UB)p->data);
   99:         }
  100:         out_b(MPC_PWPR, MPC_PWMR_B0WI);                /* Enable Register protect */
  101: 
  102:         /* Setup port mode */
  103:         for(p = portmode_tbl; p->addr != 0; p++) {
  104:                 out_b(p->addr, (UB)p->data);
  105:         }      
  106: 
  107:         startup_clock();                       /* Startup CPU Clock */
  108: }
  109: 
  110: #if USE_SHUTDOWN
  111: /*
  112:  * Shutdown hardware
  113:  */
  114: EXPORT void knl_shutdown_hw( void )
  115: {
  116:         disint();
  117:         shutdown_clock();
  118: 
  119:         while(1);
  120: }
  121: #endif /* USE_SHUTDOWN */
  122: 
  123: /*
  124:  * Re-start hardware
  125:  *      mode = -1            reset and re-start        (Reset -> Boot -> Start)
  126:  *      mode = -2            fast re-start             (Start)
  127:  *      mode = -3            Normal re-start           (Boot -> Start)
  128:  */
  129: EXPORT ER knl_restart_hw( W mode )
  130: {
  131:         switch(mode) {
  132:         case -1: /* Reset and re-start */
  133:                 SYSTEM_MESSAGE("\n<< SYSTEM RESET & RESTART >>\n");
  134:                 return E_NOSPT;
  135:         case -2: /* fast re-start */
  136:                 SYSTEM_MESSAGE("\n<< SYSTEM FAST RESTART >>\n");
  137:                 return E_NOSPT;
  138:         case -3: /* Normal re-start */
  139:                 SYSTEM_MESSAGE("\n<< SYSTEM RESTART >>\n");
  140:                 return E_NOSPT;
  141:         default:
  142:                 return E_PAR;
  143:         }
  144: }
  145: 
  146: 
  147: #endif /* IOTE_RX231 */