bsp.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. //all board's low level init is here
  25. void bsp_init(void){
  26. wdog_start(4);
  27. shark_rtc_init();
  28. enable_mcu_power();
  29. system_clock_config(); //after dcdc open, MCU can run on full speed
  30. SystemCoreClockUpdate();
  31. gpio_init();
  32. set_log_level(MOD_SYSTEM, L_debug);
  33. shark_uart_init(SHARK_UART0);
  34. #if (CONFIG_BOARD_TYPE==SHARK_BOARD_SP700)
  35. shark_uart_init(SHARK_UART1);
  36. #endif
  37. AT24CXX_Init();
  38. AUX_VOL_OPEN(0);
  39. gpio_key_init();
  40. }
  41. void systick_close(void)
  42. {
  43. SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
  44. }
  45. void systick_open(void)
  46. {
  47. SysTick_Config(SystemCoreClock / 1000);
  48. }
  49. char* bsp_get_fversion(void){
  50. return (char *)iap_fw_version;
  51. }
  52. /* timeout:1-25 */
  53. void wdog_start(int timeout){
  54. #if CONFIG_DEBUG == 0
  55. /* enable IRC40K */
  56. rcu_osci_on(RCU_IRC40K);
  57. /* wait till IRC40K is ready */
  58. while(SUCCESS != rcu_osci_stab_wait(RCU_IRC40K)){
  59. }
  60. /* confiure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */
  61. fwdgt_config(timeout*40000UL/256, FWDGT_PSC_DIV256);
  62. /* after 4 seconds to generate a reset */
  63. fwdgt_enable();
  64. #endif
  65. }
  66. void wdog_reload(void){
  67. #if CONFIG_DEBUG == 0
  68. fwdgt_counter_reload();
  69. #endif
  70. }
  71. void wdog_set_timeout(int timeout)
  72. {
  73. #if CONFIG_DEBUG == 0
  74. /* enable write access to FWDGT_PSC,and FWDGT_RLD */
  75. FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
  76. FWDGT_RLD = RLD_RLD(timeout*40000UL/256);
  77. /* reload the counter */
  78. FWDGT_CTL = FWDGT_KEY_RELOAD;
  79. #endif
  80. }