setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #include "asm/includes.h"
  2. //#include "asm/ldo.h"
  3. //#include "asm/cache.h"
  4. #include "asm/wdt.h"
  5. #include "asm/debug.h"
  6. #include "asm/efuse.h"
  7. #include "asm/power/p33.h"
  8. #include "asm/efuse.h"
  9. #include "system/task.h"
  10. #include "timer.h"
  11. #include "app_config.h"
  12. #include "gpio.h"
  13. //#include "power_manage.h"
  14. //
  15. #define LOG_TAG_CONST SETUP
  16. #define LOG_TAG "[SETUP]"
  17. #define LOG_ERROR_ENABLE
  18. #define LOG_DEBUG_ENABLE
  19. #define LOG_INFO_ENABLE
  20. /* #define LOG_DUMP_ENABLE */
  21. #define LOG_CLI_ENABLE
  22. #include "debug.h"
  23. //extern void dv15_dac_early_init(u8 ldo_sel, u8 pwr_sel, u32 dly_msecs);
  24. //
  25. extern void sys_timer_init(void);
  26. extern void tick_timer_init(void);
  27. extern u32 reset_source_dump(void);
  28. extern u8 power_reset_source_dump(void);
  29. extern void exception_irq_handler(void);
  30. int __crc16_mutex_init();
  31. extern int __crc16_mutex_init();
  32. #define DEBUG_SINGAL_IDLE(x) //if (x) IO_DEBUG_1(A, 7) else IO_DEBUG_0(A, 7)
  33. #define DEBUG_SINGAL_1S(x) //if (x) IO_DEBUG_1(A, 6) else IO_DEBUG_0(A, 6)
  34. #if (defined CONFIG_DEBUG_ENABLE) || (defined CONFIG_DEBUG_LITE_ENABLE)
  35. void debug_uart_init(const struct uart_platform_data *data);
  36. #endif
  37. #if 0
  38. ___interrupt
  39. void exception_irq_handler(void)
  40. {
  41. ___trig;
  42. exception_analyze();
  43. log_flush();
  44. while (1);
  45. }
  46. #endif
  47. /*
  48. * 此函数在cpu0上电后首先被调用,负责初始化cpu内部模块
  49. *
  50. * 此函数返回后,操作系统才开始初始化并运行
  51. *
  52. */
  53. #if 0
  54. static void early_putchar(char a)
  55. {
  56. if (a == '\n') {
  57. UT2_BUF = '\r';
  58. __asm_csync();
  59. while ((UT2_CON & BIT(15)) == 0);
  60. }
  61. UT2_BUF = a;
  62. __asm_csync();
  63. while ((UT2_CON & BIT(15)) == 0);
  64. }
  65. void early_puts(char *s)
  66. {
  67. do {
  68. early_putchar(*s);
  69. } while (*(++s));
  70. }
  71. #endif
  72. void cpu_assert_debug()
  73. {
  74. #ifdef CONFIG_DEBUG_ENABLE
  75. log_flush();
  76. local_irq_disable();
  77. while (1);
  78. #else
  79. P3_PCNT_SET0 = 0xac;
  80. cpu_reset();
  81. #endif
  82. }
  83. void timer(void *p)
  84. {
  85. /* DEBUG_SINGAL_1S(1); */
  86. sys_timer_dump_time();
  87. /* DEBUG_SINGAL_1S(0);*/
  88. }
  89. void app_bank_init()
  90. {
  91. #ifdef CONFIG_CODE_BANK_ENABLE
  92. extern void bank_syscall_entry();
  93. request_irq(IRQ_SYSCALL_IDX, 3, bank_syscall_entry, 0);
  94. extern void load_common_code();
  95. load_common_code();
  96. #endif
  97. }
  98. static void (*uart_db_irq_handler_callback)(u8 *packet, u32 size);
  99. extern void uart_dev_set_irq_handler_hook(void *uart_irq_hook);
  100. static void uart_db_irq_handler_hook(u8 *rbuf, u32 len)
  101. {
  102. if (len) {
  103. log_info("uart_rx_data %d:", len);
  104. put_buf(rbuf, len);
  105. }
  106. if (uart_db_irq_handler_callback) {
  107. uart_db_irq_handler_callback(rbuf, len);
  108. }
  109. }
  110. void uart_db_regiest_recieve_callback(void *rx_cb)
  111. {
  112. uart_db_irq_handler_callback = rx_cb;
  113. }
  114. u32 stack_magic[4] sec(.stack_magic);
  115. u32 stack_magic0[4] sec(.stack_magic0);
  116. void memory_init(void);
  117. void setup_arch()
  118. {
  119. #if TCFG_CHARGE_ENABLE
  120. //防止LDOIN先上电,VBAT后上电导致的VDC12过压(越靠前调用越好)
  121. extern void power_enter_charge_mode(void);
  122. power_enter_charge_mode();
  123. #endif
  124. //asm("trigger ");
  125. JL_UART0->CON0 |= BIT(2); //use lp waiting, must set Tx pending Enable
  126. memory_init();
  127. memset(stack_magic, 0x5a, sizeof(stack_magic));
  128. memset(stack_magic0, 0x5a, sizeof(stack_magic0));
  129. //P11 系统必须提前打开
  130. p11_init();
  131. wdt_init(WDT_4S);
  132. /* wdt_close(); */
  133. clk_voltage_init(TCFG_CLOCK_MODE, SYSVDD_VOL_SEL_126V);
  134. clk_early_init(TCFG_CLOCK_SYS_SRC, TCFG_CLOCK_OSC_HZ, TCFG_CLOCK_SYS_HZ);
  135. tick_timer_init();
  136. /*interrupt_init();*/
  137. #if (defined CONFIG_DEBUG_ENABLE) || (defined CONFIG_DEBUG_LITE_ENABLE)
  138. debug_uart_init(NULL);
  139. #if TCFG_UART0_RX_PORT != NO_CONFIG_PORT
  140. JL_UART0->CON0 &= ~BIT(2); //disable Tx pending Enable
  141. uart_dev_set_irq_handler_hook(uart_db_irq_handler_hook);
  142. #if TCFG_LOWPOWER_LOWPOWER_SEL
  143. /*需要关闭POWERDOWN,否则接收会丢数据*/
  144. #error "need define TCFG_LOWPOWER_LOWPOWER_SEL 0 !!!!!!"
  145. #endif
  146. #endif
  147. #ifdef CONFIG_DEBUG_ENABLE
  148. log_early_init(1024);
  149. #endif
  150. #endif
  151. log_i("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  152. log_i(" setup_arch %s %s", __DATE__, __TIME__);
  153. log_i("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
  154. clock_dump();
  155. efuse_dump();
  156. reset_source_dump();
  157. /* power_reset_source_dump(); */
  158. //Register debugger interrupt
  159. /* request_irq(0, 2, exception_irq_handler, 0); */
  160. request_irq(1, 2, exception_irq_handler, 0);
  161. sys_timer_init();
  162. debug_init();
  163. /* sys_timer_add(NULL, timer, 1 * 1000); */
  164. __crc16_mutex_init();
  165. }
  166. /*-----------------------------------------------------------*/