CG_system.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. *******************************************************************************
  3. * Copyright(C) NEC Electronics Corporation 2010
  4. * All rights reserved by NEC Electronics Corporation.
  5. * This program should be used on your own responsibility.
  6. * NEC Electronics Corporation assumes no responsibility for any losses
  7. * incurred by customers or third parties arising from the use of this file.
  8. *
  9. * This device driver was created by Applilet3 for V850ES/Jx3
  10. * 32-Bit Single-Chip Microcontrollers
  11. * Filename: CG_system.c
  12. * Abstract: This file implements device driver for System module.
  13. * APIlib: Applilet3 for V850ES/Jx3 V2.01 [20 Apr 2010]
  14. * Device: uPD70F3746
  15. * Compiler: IAR Systems ICCV850
  16. * Creation date: 6/26/2010
  17. *******************************************************************************
  18. */
  19. /*
  20. *******************************************************************************
  21. ** Include files
  22. *******************************************************************************
  23. */
  24. #include "CG_macrodriver.h"
  25. #include "CG_system.h"
  26. /* Start user code for include. Do not edit comment generated here */
  27. /* End user code. Do not edit comment generated here */
  28. #include "CG_userdefine.h"
  29. /*
  30. *******************************************************************************
  31. ** Global define
  32. *******************************************************************************
  33. */
  34. /* Start user code for global. Do not edit comment generated here */
  35. /* End user code. Do not edit comment generated here */
  36. void clock_pll_mode(void)
  37. {
  38. /* CPU operation clock selection */
  39. /* Set PLL mode. */
  40. PLLCTL = 0x03; /* bit 1: CPU clock selection (PLL mode/clock-through mode selection) */
  41. /* 1: PLL mode, 0: Clock-through mode */
  42. __asm("_loop: set1 1,0xF82C[r0]"); //__IO_REG8_BIT( PLLCTL, 0xFFFFF82C, __READ_WRITE )
  43. __asm(" tst1 1,0xF82C[r0]"); //__IO_REG8_BIT( PLLCTL, 0xFFFFF82C, __READ_WRITE )
  44. __asm(" bz _loop");
  45. return;
  46. }
  47. void clock_pcc_mode(void)
  48. {
  49. /* DMA is forcibly terminated in this sample since DMA transfer must be terminated
  50. before data is set to a special register. */
  51. if(TC0 == 0 && E00 == 1){ /* DMA0 transfer judgment */
  52. INIT0 = 1; /* DMA0 forcible termination */
  53. }
  54. if(TC1 == 0 && E11 == 1){ /* DMA1 transfer judgment */
  55. INIT1 = 1; /* DMA1 forcible termination */
  56. }
  57. if(TC2 == 0 && E22 == 1){ /* DMA2 transfer judgment */
  58. INIT2 = 1; /* DMA2 forcible termination */
  59. }
  60. if(TC3 == 0 && E33 == 1){ /* DMA3 transfer judgment */
  61. INIT3 = 1; /* DMA3 forcible termination */
  62. }
  63. /* The PCC register is a special register. Data can be written to this register only in a combination of specific sequences. */
  64. /* bit 1, bit 0: Clock selection, 11: fxx/8, 10: fxx/4, 01: fxx/2, 00: fxx */
  65. /* Clock selection: fxx */
  66. __asm("mov 0x00, r10"); /* Set general-purpose register data to be set to special register. */
  67. __asm("st.b r10, 0xF1FC[r0]"); /* Write to PRCMD register. */ //__IO_REG8(PRCMD, 0xFFFFF1FC, __WRITE)
  68. __asm("st.b r10, 0xF828[r0]"); /* Set PCC register. */ //__IO_REG8_BIT(PCC, 0xFFFFF828, __READ_WRITE)
  69. __asm("nop"); /* Insert five or more NOP instructions. */
  70. __asm("nop");
  71. __asm("nop");
  72. __asm("nop");
  73. __asm("nop");
  74. return;
  75. }
  76. /*
  77. **-----------------------------------------------------------------------------
  78. **
  79. ** Abstract:
  80. ** This function initializes the clock generator module.
  81. **
  82. ** Parameters:
  83. ** None
  84. **
  85. ** Returns:
  86. ** None
  87. **
  88. **-----------------------------------------------------------------------------
  89. */
  90. void CLOCK_Init(void)
  91. {
  92. DI(); /* Maskable interrupt disabled */
  93. do{
  94. clock_pll_mode(); /* PLL mode setting function */
  95. clock_pcc_mode(); /* PCC register setting function */
  96. }while(PRERR); /* Written in correct sequence? */
  97. }
  98. /* Start user code for adding. Do not edit comment generated here */
  99. /* End user code. Do not edit comment generated here */