system_mb9bf50x.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /************************************************************************/
  2. /* (C) Fujitsu Semiconductor Europe GmbH */
  3. /* */
  4. /* The following software deliverable is intended for and must only be */
  5. /* used for reference and in an evaluation laboratory environment. */
  6. /* It is provided on an as-is basis without charge and is subject to */
  7. /* alterations. */
  8. /* It is the user’s obligation to fully test the software in its */
  9. /* environment and to ensure proper functionality, qualification and */
  10. /* compliance with component specifications. */
  11. /* */
  12. /* In the event the software deliverable includes the use of open */
  13. /* source components, the provisions of the governing open source */
  14. /* license agreement shall apply with respect to such software */
  15. /* deliverable. */
  16. /* FSEU does not warrant that the deliverables do not infringe any */
  17. /* third party intellectual property right (IPR). In the event that */
  18. /* the deliverables infringe a third party IPR it is the sole */
  19. /* responsibility of the customer to obtain necessary licenses to */
  20. /* continue the usage of the deliverable. */
  21. /* */
  22. /* To the maximum extent permitted by applicable law FSEU disclaims all */
  23. /* warranties, whether express or implied, in particular, but not */
  24. /* limited to, warranties of merchantability and fitness for a */
  25. /* particular purpose for which the deliverable is not designated. */
  26. /* */
  27. /* To the maximum extent permitted by applicable law, FSEU's liability */
  28. /* is restricted to intention and gross negligence. */
  29. /* FSEU is not liable for consequential damages. */
  30. /* */
  31. /* (V1.4) */
  32. /************************************************************************/
  33. #include "mb9bf506r.h"
  34. /*
  35. * 80MHz : Master Clock
  36. */
  37. const uint32_t SystemFrequency = 80000000UL;
  38. uint32_t SysFreHCLK = 80000000UL; /* HCLK = MasterClock / 1 */
  39. uint32_t SysFrePCLK0 = 40000000UL; /* PCLK0 = HCLK / 2 */
  40. uint32_t SysFrePCLK1 = 40000000UL; /* PCLK1 = HCLK / 2 */
  41. uint32_t SysFrePCLK2 = 40000000UL; /* PCLK2 = HCLK / 2 */
  42. uint32_t SysFreTPIU = 0UL; /* TPIUCLK : Disable */
  43. /*
  44. * Prototype of internal function
  45. */
  46. static void ClockInit(void);
  47. static void HwwdtDisable(void);
  48. /*
  49. * Setup the microcontroller system
  50. */
  51. void SystemInit (void)
  52. {
  53. HwwdtDisable(); /* Disable Hardware Watchdog */
  54. ClockInit(); /* Initialize Clock */
  55. }
  56. /*
  57. * Initialize Clock
  58. */
  59. static void ClockInit(void)
  60. {
  61. /*set Main clock stabilization
  62. wait time to 2ms*/
  63. FM3_CRG->CSW_TMR = 0x79;
  64. /*Enable Main Oscilator*/
  65. FM3_CRG->SCM_CTL |= 1<<1;
  66. /*Wait stabilization end*/
  67. while(!(FM3_CRG->SCM_STR & 0x02));
  68. /* sub CLK enable */
  69. //FM3_CRG->SCM_CTL |= 0x08;
  70. //while(!(FM3_CRG->SCM_STR & 0x08));
  71. /*Set PLL stabilization
  72. wait time to 512uS*/
  73. FM3_CRG->PSW_TMR |= 2;
  74. /*Set PLL to 80MHz*/
  75. FM3_CRG->PLL_CTL1 = 0; /*K = 1, M=1*/
  76. FM3_CRG->PLL_CTL2 = 19; /*N = 20*/
  77. /*Enable PLL*/
  78. FM3_CRG->SCM_CTL |= 0x10;
  79. /*Set bus prescalers*/
  80. FM3_CRG->BSC_PSR = 0; /*Base clock Prescaler 1:1*/
  81. FM3_CRG->APBC0_PSR |= 1; /*APB0 clock Prescaler 1:2*/
  82. FM3_CRG->APBC1_PSR |= 1; /*APB1 clock Prescaler 1:2*/
  83. FM3_CRG->APBC2_PSR |= 1; /*APB2 clock Prescaler 1:2*/
  84. /*Wait PLL stabilizatoin end*/
  85. while(!(FM3_CRG->SCM_STR & 0x10));
  86. /*Select PLL for main clock*/
  87. FM3_CRG->SCM_CTL |= 2<<5;
  88. /*Wait PLL to be connected*/
  89. while((FM3_CRG->SCM_STR & 0xe0) != 0x40);
  90. }
  91. /*
  92. * Stop HW Watchdog Timer
  93. */
  94. static void HwwdtDisable(void)
  95. {
  96. /* UnLock (except WDG_CTL) */
  97. FM3_HWWDT->WDG_LCK = 0x1ACCE551;
  98. /* UnLock (WDG_CTL) */
  99. FM3_HWWDT->WDG_LCK = 0xE5331AAE;
  100. /* Disable WDG */
  101. FM3_HWWDT->WDG_CTL = 0x00;
  102. }