system.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-08-20 zx.chen CSI Device System Source File
  9. */
  10. #include <csi_config.h>
  11. #include <soc.h>
  12. #include <csi_core.h>
  13. #include <drv_irq.h>
  14. #ifndef CONFIG_SYSTICK_HZ
  15. #define CONFIG_SYSTICK_HZ 100
  16. #endif
  17. int g_system_clock = IHS_VALUE;
  18. extern int32_t g_top_irqstack;
  19. extern void irq_vectors_init(void);
  20. extern void mm_heap_initialize(void);
  21. int SystemCoreClock = IHS_VALUE; /* System Core Clock Frequency */
  22. extern int __Vectors;
  23. void SystemCoreClockUpdate(void)
  24. {
  25. SystemCoreClock = IHS_VALUE;
  26. }
  27. static void _system_init_for_kernel(void)
  28. {
  29. irq_vectors_init();
  30. csi_coret_config(drv_get_sys_freq() / CONFIG_SYSTICK_HZ, CORET_IRQn); //10ms
  31. drv_irq_enable(CORET_IRQn);
  32. }
  33. /**
  34. * @brief initialize system map
  35. * @param None
  36. * @return None
  37. */
  38. void systemmap_config(void)
  39. {
  40. csi_sysmap_config_region(0, 0x20000000, SYSMAP_SYSMAPCFG_B_Msk | SYSMAP_SYSMAPCFG_C_Msk);
  41. csi_sysmap_config_region(1, 0x40000000, SYSMAP_SYSMAPCFG_B_Msk | SYSMAP_SYSMAPCFG_C_Msk);
  42. csi_sysmap_config_region(2, 0x50000000, SYSMAP_SYSMAPCFG_SO_Msk);
  43. csi_sysmap_config_region(3, 0x50700000, SYSMAP_SYSMAPCFG_B_Msk | SYSMAP_SYSMAPCFG_C_Msk);
  44. csi_sysmap_config_region(4, 0x60000000, SYSMAP_SYSMAPCFG_SO_Msk);
  45. csi_sysmap_config_region(5, 0x80000000, SYSMAP_SYSMAPCFG_B_Msk | SYSMAP_SYSMAPCFG_C_Msk);
  46. csi_sysmap_config_region(6, 0x90000000, SYSMAP_SYSMAPCFG_B_Msk | SYSMAP_SYSMAPCFG_C_Msk);
  47. csi_sysmap_config_region(7, 0xf0000000, SYSMAP_SYSMAPCFG_SO_Msk);
  48. }
  49. /**
  50. * @brief initialize the system
  51. * Initialize the psr and vbr.
  52. * @param None
  53. * @return None
  54. */
  55. void SystemInit(void)
  56. {
  57. int i;
  58. #if ((CONFIG_CPU_E902 != 1) && (CONFIG_CPU_E902M != 1))
  59. systemmap_config();
  60. #endif
  61. /* enable mstatus FS */
  62. #if (__riscv_flen)
  63. uint32_t mstatus = __get_MSTATUS();
  64. mstatus |= (1 << 13);
  65. __set_MSTATUS(mstatus);
  66. #endif
  67. /* enable mxstatus THEADISAEE */
  68. uint32_t mxstatus = __get_MXSTATUS();
  69. mxstatus |= (1 << 22);
  70. /* enable mxstatus MM */
  71. #if ((CONFIG_CPU_E906==1) || (CONFIG_CPU_E906F==1) || (CONFIG_CPU_E906FD==1))
  72. mxstatus |= (1 << 15);
  73. #endif
  74. __set_MXSTATUS(mxstatus);
  75. /* get interrupt level from info */
  76. CLIC->CLICCFG = (((CLIC->CLICINFO & CLIC_INFO_CLICINTCTLBITS_Msk) >> CLIC_INFO_CLICINTCTLBITS_Pos) << CLIC_CLICCFG_NLBIT_Pos);
  77. for (i = 0; i < 64; i++)
  78. {
  79. CLIC->CLICINT[i].IP = 0;
  80. CLIC->CLICINT[i].ATTR = 1; /* use vector interrupt */
  81. }
  82. /* tspend use positive interrupt */
  83. CLIC->CLICINT[Machine_Software_IRQn].ATTR = 0x3;
  84. #if ((CONFIG_CPU_E902 != 1) && (CONFIG_CPU_E902M != 1))
  85. csi_dcache_enable();
  86. #endif
  87. csi_icache_enable();
  88. drv_irq_enable(Machine_Software_IRQn);
  89. _system_init_for_kernel();
  90. }