忘備録-備忘録

技術的な備忘録

RX210のクロックをPLLに切り替えるプログラム

2015-03-26 07:17:08 | RX210
RX210のクロックをPLLに切り替えるプログラムです。ルネサスエレクトロニクスのサンプルコードを単純化したものです。水晶振動子の発振周波数が20MHzの時にCPUの動作クロックが50MHzとなり周辺機器のクロックが25MHzとなります。

  1. /* RX210 cpuのクロックをPLLに切り替えるプログラム */
  2. /* 水晶振動子の発振周波数が20MHzの時にCPUの動作クロックが50MHzとなり周辺機器のクロックが25MHzとなる。 */
  3.                                                                           
  4. #include "iodefine.h"
  5. #include <machine.h>
  6. void change_oscillation_PLL(void)
  7. {
  8.     unsigned int i;
  9.     /* ---- Enable write protection ---- */
  10.     /* PRCR - Protect Register
  11.     b15:b8 PRKEY - PRC Key Code - A5h
  12.                   (The write value should be A5h to permission writing PRCi bit)
  13.     b7:b4 Reserved - The write value should be 0.
  14.     b3 PRC3 - Protect Bit 3 - Write disabled
  15.     b2 PRC2 - Protect Bit 2 - Write enabled
  16.     b1 PRC1 - Protect Bit 1 - Write enabled
  17.     b0 PRC0 - Protect Bit 0 - Write enabled */
  18.     SYSTEM.PRCR.WORD = 0xA507;
  19.     /* ---- Set the VRCR register ---- */
  20.     SYSTEM.VRCR = 0x00;
  21.     /* ---- Set the main clock oscillator drive capability ---- */
  22.     /* MOFCR - Main Clock Oscillator Forced Oscillation Control Register
  23.     b7 Reserved - The write value should be 0.
  24.     b6 MOSEL - Main Clock Oscillator Switch - Resonator
  25.     b5:b4 MODRV2 - Main Clock Oscillator Drive Capability Switch 2
  26.                       - 16 MHz to 20 MHz
  27.     b3:b1 MODRV - Main Clock Oscillator Drive Capability Switch
  28.                       - 16 MHz to 20 MHz non-lead type ceramic resonator
  29.     b0 Reserved - The write value should be 0. */
  30.     SYSTEM.MOFCR.BYTE = (0x30);    /* Drive capability : 20 MHz crystal resonator */
  31.     /* ---- Set wait time until the main clock oscillator stabilizes ---- */
  32.     /* MOSCWTCR - Main Clock Oscillator Wait Control Register
  33.     b7:b5 Reserved - The write value should be 0.
  34.     b4:b0 MSTS - Main Clock Oscillator Waiting Time
  35.                       - Wait time is 131072 cycles (approx. 6.55 ms). */
  36.     SYSTEM.MOSCWTCR.BYTE = (0x0D);    /* Wait control register : 131072 cycles (approx. 6.55 ms) */
  37.     /* ---- Operate the main clock oscillator ---- */
  38.     /* MOSCCR - Main Clock Oscillator Control Register
  39.     b7:b1 Reserved - The write value should be 0.
  40.     b0 MOSTP - Main Clock Oscillator Stop - Main clock oscillator is operating. */
  41.     SYSTEM.MOSCCR.BYTE = 0x00;
  42.     while (0x00 != SYSTEM.MOSCCR.BYTE)
  43.     {
  44.         /* Confirm that the written value can be read correctly. */
  45.     }
  46.     /* ---- Wait processing for the clock oscillation stabilization ---- */
  47.     for(i=0;i<100;i++) nop();</li>
  48.     /* ---- Set the PLL division ratio and multiplication factor ---- */
  49.     /* PLLCR - PLL Control Register
  50.     b15:b13 Reserved - The write value should be 0.
  51.     b12:b8 STC - Frequency Multiplication Factor Select
  52.                       - Frequency multiplication factor is multiply-by-10.
  53.     b7:b2 Reserved - The write value should be 0.
  54.     b1:b0 PLIDIV - PLL Input Frequency Division Ratio Select
  55.                       - PLL input division ratio is divide-by-2. */
  56.     SYSTEM.PLLCR.WORD = (0x0901);    /* Division ratio and multiplication factor : divide-by-2, multiply-by-10 */
  57.     /* ---- Set wait time until the PLL clock oscillator stabilizes ---- */
  58.     /* PLLWTCR - PLL Wait Control Register
  59.     b7:b5 Reserved - The write value should be 0.
  60.     b4:b0 PSTS - PLL Waiting Time
  61.                       - Wait time is 65536 cycles (approx. 655.36 us). */
  62.     SYSTEM.PLLWTCR.BYTE = (0x09);    /* Wait control register : 65536 cycles (approx. 655.36 us) */
  63.     /* ---- Operate the PLL clock oscillator ---- */
  64.     /* PLLCR2 - PLL Control Register 2
  65.     b7:b1 Reserved - The write value should be 0.
  66.     b0 PLLEN - PLL Stop Control - PLL is operating. */
  67.     SYSTEM.PLLCR2.BYTE = 0x00;
  68.     /* ---- Wait processing for the clock oscillation stabilization ---- */
  69.     for(i=0;i<100;i++) nop();</li>
  70.     /* ---- Set the operating power control mode ---- */
  71.     /* OPCCR - Operating Power Control Register
  72.     b7:b5 Reserved - The write value should be 0.
  73.     b4 OPCMTSF - Operating Power Control Mode Transition Status Flag
  74.     b3 Reserved - The write value should be 0.
  75.     b2:b0 OPCM - Operating Power Control Mode Select - High-speed operating mode */
  76.     SYSTEM.OPCCR.BYTE = (0x00); /* High-speed operating mode */
  77.     while (0 != SYSTEM.OPCCR.BIT.OPCMTSF)
  78.     {
  79.         /* Confirm that the operation power control mode transition completed. */
  80.     }
  81.     /* ---- Set the internal clock division ratio ---- */
  82.     /* SCKCR - System Clock Control Register
  83.     b31:b28 FCK - FlashIF Clock(FCLK) Select - divide-by-4
  84.     b27:b24 ICK - System Clock (ICLK) Select - divide-by-2
  85.     b23 PSTOP1 - BCLK Pin Output Control - disabled. (Fixed high)
  86.     b22:b20 Reserved - The write value should be 0.
  87.     b19:b16 BCK - External Bus Clock (BCLK) Select - divide-by-4
  88.     b15:b12 Reserved - The write value should be 0001b.
  89.     b10:b8 PCLKB - Peripheral Module Clock B(PCLKB) Select - divide-by-4
  90.     b7:b4 Reserved - The write value should be 0001b.
  91.     b3:b0 PCLKD - Peripheral Module Clock D(PCLKD) Select - divide-by-2 */
  92.     SYSTEM.SCKCR.LONG = 0x21821211;    /* ICLK,PCLKD: divide-by-2 PCLKB,BCLK,FCLK: divide-by-4 */
  93.     while (0x21821211 != SYSTEM.SCKCR.LONG)
  94.     {
  95.          /* Confirm that the written value can be read correctly. */
  96.     }
  97.     /* ---- Set the BCLK pin output ---- */
  98.     /* BCKCR - External Bus Clock Control Register
  99.     b7:b1 Reserved - The write value should be 0.
  100.     b0 BCLKDIV - BCLK Pin Output Select - divide-by-2 */
  101.     SYSTEM.BCKCR.BYTE = 0x01;
  102.     while (0x01 != SYSTEM.BCKCR.BYTE)
  103.     {
  104.         /* Confirm that the written value can be read correctly. */
  105.     }
  106.     /* ---- Set the internal clock source ---- */
  107.     /* SCKCR3 - System Clock Control Register 3
  108.     b15:b11 Reserved - The write value should be 0.
  109.     b10:b8 CKSEL - Clock Source Select - PLL circuit is selected.
  110.     b7:b1 Reserved - The write value should be 0. */
  111.     SYSTEM.SCKCR3.WORD = (0x0400);    /* PLL */
  112.     while ((0x0400) != SYSTEM.SCKCR3.WORD)
  113.     {
  114.         /* Confirm that the written value can be read correctly. */
  115.     }
  116.     /* ---- Disable write protection ---- */
  117.     /* PRCR - Protect Register
  118.     b15:b8 PRKEY - PRC Key Code - A5h
  119.                   (The write value should be A5h to permission writing PRCi bit)
  120.     b2 PRC2 - Protect Bit 2 - Write disabled
  121.     b1 PRC1 - Protect Bit 1 - Write disabled
  122.     b0 PRC0 - Protect Bit 0 - Write disabled */
  123.     SYSTEM.PRCR.WORD = 0xA500;
  124. }
  125. void main(void)
  126. {
  127.     unsigned int i;
  128.     change_oscillation_PLL();            //クロックソースPLL
  129.     PORTC.PDR.BYTE = 0xFF;
  130.     PORTC.PODR.BYTE = 0x00;
  131.     PORTA.PDR.BYTE = 0xFF;
  132.     PORTA.PODR.BYTE =0x00;
  133.     PORTB.PDR.BYTE = 0xFF;
  134.     PORTB.PODR.BYTE = 0xFF;
  135.     while(1) {
  136.         PORTC.PODR.BYTE = ~PORTC.PODR.BYTE;
  137.         PORTA.PODR.BYTE = ~PORTA.PODR.BYTE;
  138.         PORTB.PODR.BYTE = ~PORTB.PODR.BYTE;
  139.         for(i=0;i<500000;i++) nop();</li>
  140.     }
  141. }


最新の画像もっと見る

コメントを投稿