system.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 the system
  35. * Initialize the psr and vbr.
  36. * @param None
  37. * @return None
  38. */
  39. void SystemInit(void)
  40. {
  41. int i;
  42. /* enable mstatus FS */
  43. #if ((CONFIG_CPU_E906F==1) || (CONFIG_CPU_E906FD==1))
  44. uint32_t mstatus = __get_MSTATUS();
  45. mstatus |= (1 << 13);
  46. __set_MSTATUS(mstatus);
  47. #endif
  48. /* enable mxstatus THEADISAEE */
  49. uint32_t mxstatus = __get_MXSTATUS();
  50. mxstatus |= (1 << 22);
  51. /* enable mxstatus MM */
  52. #if ((CONFIG_CPU_E906==1) || (CONFIG_CPU_E906F==1) || (CONFIG_CPU_E906FD==1))
  53. mxstatus |= (1 << 15);
  54. #endif
  55. __set_MXSTATUS(mxstatus);
  56. /* get interrupt level from info */
  57. CLIC->CLICCFG = (((CLIC->CLICINFO & CLIC_INFO_CLICINTCTLBITS_Msk) >> CLIC_INFO_CLICINTCTLBITS_Pos) << CLIC_CLICCFG_NLBIT_Pos);
  58. for (i = 0; i < 64; i++)
  59. {
  60. CLIC->CLICINT[i].IP = 0;
  61. CLIC->CLICINT[i].ATTR = 1; /* use vector interrupt */
  62. }
  63. /* tspend use positive interrupt */
  64. CLIC->CLICINT[Machine_Software_IRQn].ATTR = 0x3;
  65. csi_dcache_enable();
  66. csi_icache_enable();
  67. drv_irq_enable(Machine_Software_IRQn);
  68. _system_init_for_kernel();
  69. }