system.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file system.c
  18. * @brief CSI Device System Source File
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #include <csi_config.h>
  23. #include "csi_core.h"
  24. #include "wm_regs.h"
  25. #include "wm_cpu.h"
  26. extern int32_t g_top_irqstack;
  27. extern uint32_t csi_coret_get_load(void);
  28. extern uint32_t csi_coret_get_value(void);
  29. static void _mdelay(void)
  30. {
  31. uint32_t load = csi_coret_get_load();
  32. uint32_t start = csi_coret_get_value();
  33. uint32_t cur;
  34. uint32_t cnt;
  35. tls_sys_clk sysclk;
  36. tls_sys_clk_get(&sysclk);
  37. cnt = sysclk.cpuclk * 1000;
  38. while (1) {
  39. cur = csi_coret_get_value();
  40. if (start > cur) {
  41. if (start - cur >= cnt) {
  42. return;
  43. }
  44. } else {
  45. if (load - cur + start > cnt) {
  46. return;
  47. }
  48. }
  49. }
  50. }
  51. void mdelay(uint32_t ms)
  52. {
  53. if (ms == 0) {
  54. return;
  55. }
  56. while (ms--) {
  57. _mdelay();
  58. }
  59. }
  60. /**
  61. * @brief initialize c++ constructor
  62. * @param None
  63. * @return None
  64. */
  65. extern int __dtor_end__;
  66. extern int __ctor_end__;
  67. extern int __ctor_start__;
  68. typedef void (*func_ptr)(void);
  69. __attribute__((weak)) void cxx_system_init(void)
  70. {
  71. func_ptr *p;
  72. for (p = (func_ptr *)&__ctor_end__ -1; p >= (func_ptr *)&__ctor_start__; p--)
  73. {
  74. (*p)();
  75. }
  76. }
  77. /**
  78. * @brief initialize the system
  79. * Initialize the psr and vbr.
  80. * @param None
  81. * @return None
  82. */
  83. void SystemInit(void)
  84. {
  85. __set_VBR((uint32_t) & (irq_vectors));
  86. #if defined(CONFIG_SEPARATE_IRQ_SP) && !defined(CONFIG_KERNEL_NONE)
  87. /* 801 not supported */
  88. __set_Int_SP((uint32_t)&g_top_irqstack);
  89. __set_CHR(__get_CHR() | CHR_ISE_Msk);
  90. VIC->TSPR = 0xFF;
  91. #endif
  92. __set_CHR(__get_CHR() | CHR_IAE_Msk);
  93. /* Clear active and pending IRQ */
  94. VIC->IABR[0] = 0x0;
  95. VIC->ICPR[0] = 0xFFFFFFFF;
  96. #ifdef CONFIG_KERNEL_NONE
  97. __enable_excp_irq();
  98. #endif
  99. /*c++ variable init*/
  100. cxx_system_init();
  101. //csi_coret_config(g_system_clock / CONFIG_SYSTICK_HZ, SYS_TICK_IRQn); //10ms
  102. //#ifndef CONFIG_KERNEL_NONE
  103. csi_vic_enable_irq(SYS_TICK_IRQn);
  104. //#endif
  105. }