init_asrPlatform.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. *
  3. * Copyright (c) 2022 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * @file
  20. * This file provides the function to initialize the ASR platform.
  21. */
  22. #include "AppConfig.h"
  23. #include <lib/support/CHIPPlatformMemory.h>
  24. #include <platform/CHIPDeviceLayer.h>
  25. #include <assert.h>
  26. #include <stdint.h>
  27. #include <string.h>
  28. #include "lega_wlan_api.h"
  29. #include "soc_init.h"
  30. #ifdef CFG_PLF_RV32
  31. #include "asr_flash_kv.h"
  32. #include "asr_pinmux.h"
  33. #include "asr_sec_hw_common.h"
  34. #include "asr_uart.h"
  35. #elif defined CFG_PLF_DUET
  36. #include "duet_flash_kv.h"
  37. #include "duet_pinmux.h"
  38. #include "duet_uart.h"
  39. #include "duet_version.h"
  40. #else
  41. #include "lega_flash_kv.h"
  42. #include "lega_pinmux.h"
  43. #include "lega_uart.h"
  44. #include "lega_version.h"
  45. #endif
  46. #include "lega_ota_utils.h"
  47. #include "lega_rtos_api.h"
  48. #if defined(CFG_PLF_RV32) || defined(CFG_PLF_DUET)
  49. #include "printf_uart.h"
  50. #endif
  51. #include "tcpip.h"
  52. #if (CFG_EASY_LOG_ENABLE == 1)
  53. #include "elog.h"
  54. #include "elog_cfg.h"
  55. #endif
  56. #ifdef CFG_PLF_RV32
  57. #define LEGA_UART0_INDEX UART0_INDEX
  58. #define LEGA_UART1_INDEX UART1_INDEX
  59. #define LEGA_UART2_INDEX UART2_INDEX
  60. #define duet_pinmux_config asr_pinmux_config
  61. #define duet_uart_init printf_uart_init
  62. #define duet_flash_kv_init alto_flash_kv_init
  63. #elif defined CFG_PLF_DUET
  64. #define LEGA_UART0_INDEX DUET_UART0_INDEX
  65. #define LEGA_UART1_INDEX DUET_UART1_INDEX
  66. #define LEGA_UART2_INDEX DUET_UART2_INDEX
  67. #else
  68. #define duet_pinmux_config lega_pinmux_config
  69. #define duet_uart_init lega_uart_init
  70. #define duet_flash_kv_init lega_flash_kv_init
  71. #define UART1_INDEX LEGA_UART1_INDEX
  72. #endif
  73. #define UART1_TX_PIN PAD2
  74. #define UART1_RX_PIN PAD3
  75. #ifdef CFG_PLF_RV32
  76. extern asr_uart_dev_t lega_at_uart;
  77. #elif defined CFG_PLF_DUET
  78. extern duet_uart_dev_t lega_at_uart;
  79. #else
  80. extern lega_uart_dev_t lega_at_uart;
  81. #endif
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. void lega_sram_rf_pta_init(void);
  86. void lega_recovery_phy_fsm_config(void);
  87. void lega_wlan_efuse_read(void);
  88. int lega_wlan_init(void);
  89. void ota_roll_back_pro(void);
  90. int32_t duet_flash_kv_init(void);
  91. void lega_at_cmd_register_all(void);
  92. int lega_at_init(void);
  93. void at_handle_uartirq(char ch);
  94. int asr_security_engine_init();
  95. void at_uart_init(void);
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. void at_uart_init(void)
  100. {
  101. memset(&lega_at_uart, 0, sizeof(lega_at_uart));
  102. lega_at_uart.config.baud_rate = UART_BAUDRATE_115200;
  103. lega_at_uart.config.data_width = DATA_8BIT;
  104. lega_at_uart.config.flow_control = FLOW_CTRL_DISABLED;
  105. lega_at_uart.config.parity = PARITY_NO;
  106. lega_at_uart.config.stop_bits = STOP_1BIT;
  107. lega_at_uart.config.mode = TX_RX_MODE;
  108. lega_at_uart.port = UART1_INDEX;
  109. #if defined CFG_PLF_RV32 || defined CFG_PLF_DUET
  110. duet_pinmux_config(UART1_TX_PIN, PF_UART1);
  111. duet_pinmux_config(UART1_RX_PIN, PF_UART1);
  112. #endif
  113. // register uart callback func for receiving at command
  114. lega_at_uart.priv = (void *) (at_handle_uartirq);
  115. duet_uart_init(&lega_at_uart);
  116. }
  117. void init_asrPlatform(void)
  118. {
  119. // don't run any code before soc_pre_init.
  120. soc_pre_init();
  121. soc_init();
  122. duet_flash_kv_init();
  123. // uart init and register uart for receiving at command
  124. at_uart_init();
  125. // ota roll back,just for flash_remapping
  126. ota_roll_back_pro();
  127. // register uart for printf log, the used uart should be init before.
  128. printf_uart_register(LEGA_UART1_INDEX);
  129. // register uart for at log, the used uart should be init before.
  130. printf2_uart_register(LEGA_UART1_INDEX);
  131. // printf("\napp version: %s\n",LEGA_VERSION_STR);
  132. /* set EasyLogger log format */
  133. #if (CFG_EASY_LOG_ENABLE == 1)
  134. elog_init();
  135. elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  136. elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  137. elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  138. elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  139. elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  140. elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
  141. elog_start();
  142. #endif
  143. #if defined CFG_PLF_RV32 || defined CFG_PLF_DUET
  144. lega_wlan_efuse_read();
  145. lega_sram_rf_pta_init();
  146. lega_recovery_phy_fsm_config();
  147. #endif
  148. asr_security_engine_init();
  149. #if !CONFIG_ENABLE_CHIP_SHELL
  150. lega_at_init();
  151. #endif
  152. lega_at_cmd_register_all();
  153. lega_wlan_init();
  154. tcpip_init(NULL, NULL);
  155. }