system.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 the system
  62. * Initialize the psr and vbr.
  63. * @param None
  64. * @return None
  65. */
  66. void SystemInit(void)
  67. {
  68. __set_VBR((uint32_t) & (irq_vectors));
  69. #if defined(CONFIG_SEPARATE_IRQ_SP) && !defined(CONFIG_KERNEL_NONE)
  70. /* 801 not supported */
  71. __set_Int_SP((uint32_t)&g_top_irqstack);
  72. __set_CHR(__get_CHR() | CHR_ISE_Msk);
  73. VIC->TSPR = 0xFF;
  74. #endif
  75. __set_CHR(__get_CHR() | CHR_IAE_Msk);
  76. /* Clear active and pending IRQ */
  77. VIC->IABR[0] = 0x0;
  78. VIC->ICPR[0] = 0xFFFFFFFF;
  79. #ifdef CONFIG_KERNEL_NONE
  80. __enable_excp_irq();
  81. #endif
  82. //csi_coret_config(g_system_clock / CONFIG_SYSTICK_HZ, SYS_TICK_IRQn); //10ms
  83. //#ifndef CONFIG_KERNEL_NONE
  84. csi_vic_enable_irq(SYS_TICK_IRQn);
  85. //#endif
  86. }