bsp.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "bsp/shark_bsp.h"
  2. #include "bsp/gpio.h"
  3. #include "bsp/uart.h"
  4. #include "bsp/AT24CXX.h"
  5. #include "bsp/shark_rtc.h"
  6. #include "bsp/clock.h"
  7. #include "bsp/fmc_flash.h"
  8. #include "libs/logger.h"
  9. #include "version.h"
  10. #include <string.h>
  11. #if defined CONFIG_BOARD_SP700
  12. const char iap_board_name[] __attribute__((at(0x08002800))) = "SP700";
  13. #elif defined CONFIG_BOARD_SP600
  14. const char iap_board_name[] __attribute__((at(0x08002800))) = "SP600";
  15. #endif
  16. const char iap_fw_version[] __attribute__((at(0x08002A00))) = CONFIG_VERSION;
  17. const char iap_fw_name[] __attribute__((at(0x08002C00))) = "App";
  18. extern void system_clock_config(void);
  19. extern void SystemCoreClockUpdate(void);
  20. extern void gpio_key_init(void);
  21. #ifndef CONFIG_DEBUG
  22. #define CONFIG_DEBUG 0
  23. #endif
  24. static uint32_t reset_source = 0;
  25. //all board's low level init is here
  26. void bsp_init(void){
  27. reset_source = RCU_RSTSCK;
  28. wdog_start(4);
  29. shark_rtc_init();
  30. enable_mcu_power();
  31. system_clock_config(); //after dcdc open, MCU can run on full speed
  32. SystemCoreClockUpdate();
  33. rcu_all_reset_flag_clear();
  34. gpio_init();
  35. set_log_level(MOD_SYSTEM, L_debug);
  36. shark_uart_init(SHARK_UART0);
  37. #if (CONFIG_BOARD_TYPE==SHARK_BOARD_SP700)
  38. shark_uart_init(SHARK_UART1);
  39. #endif
  40. AT24CXX_Init();
  41. AUX_VOL_OPEN(0);
  42. gpio_key_init();
  43. }
  44. uint32_t bsp_get_rst_reson(void){
  45. return reset_source;
  46. }
  47. void systick_close(void)
  48. {
  49. SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
  50. }
  51. void systick_open(void)
  52. {
  53. SysTick_Config(SystemCoreClock / 1000);
  54. }
  55. char* bsp_get_fversion(void){
  56. return (char *)iap_fw_version;
  57. }
  58. /* timeout:1-25 */
  59. void wdog_start(int timeout){
  60. #if CONFIG_DEBUG == 0
  61. /* enable IRC40K */
  62. rcu_osci_on(RCU_IRC40K);
  63. /* wait till IRC40K is ready */
  64. while(SUCCESS != rcu_osci_stab_wait(RCU_IRC40K)){
  65. }
  66. /* confiure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */
  67. fwdgt_config(timeout*40000UL/256, FWDGT_PSC_DIV256);
  68. /* after 4 seconds to generate a reset */
  69. fwdgt_enable();
  70. #endif
  71. }
  72. void wdog_reload(void){
  73. #if CONFIG_DEBUG == 0
  74. fwdgt_counter_reload();
  75. #endif
  76. }
  77. void wdog_set_timeout(int timeout)
  78. {
  79. #if CONFIG_DEBUG == 0
  80. /* enable write access to FWDGT_PSC,and FWDGT_RLD */
  81. FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
  82. FWDGT_RLD = RLD_RLD(timeout*40000UL/256);
  83. /* reload the counter */
  84. FWDGT_CTL = FWDGT_KEY_RELOAD;
  85. #endif
  86. }