bsp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #define ALARM_TEST 1
  22. #ifndef CONFIG_DEBUG
  23. #define CONFIG_DEBUG 0
  24. #endif
  25. #if 0
  26. void test_fmc_flash(void){
  27. uint8_t data[128];
  28. fmc_erase_image(50 * 1024);
  29. fmc_start_read_image();
  30. for(int i = 0; i < sizeof(data); i++){
  31. data[i] = i;
  32. }
  33. int count = 50;
  34. while(count-- >= 0) {
  35. for(int i = 0; i < sizeof(data); i++){
  36. data[i] = i;
  37. }
  38. fmc_write_image(data, sizeof(data));
  39. memset(data, 0, sizeof(data));
  40. fmc_read_image(data, sizeof(data));
  41. for(int i = 0; i < sizeof(data); i++){
  42. if (data[i] != (uint8_t)i){
  43. sys_debug("");
  44. }
  45. }
  46. }
  47. }
  48. #endif
  49. //all board's low level init is here
  50. void bsp_init(void){
  51. wdog_start(4);
  52. shark_rtc_init();
  53. enable_mcu_power();
  54. system_clock_config(); //after dcdc open, MCU can run on full speed
  55. SystemCoreClockUpdate();
  56. gpio_init();
  57. set_log_level(MOD_SYSTEM, L_debug);
  58. shark_uart_init(SHARK_UART0);
  59. #if (CONFIG_BOARD_TYPE==SHARK_BOARD_SP700)
  60. shark_uart_init(SHARK_UART1);
  61. #endif
  62. AT24CXX_Init();
  63. AUX_VOL_OPEN(0);
  64. gpio_key_init();
  65. }
  66. void systick_close(void)
  67. {
  68. SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
  69. }
  70. void systick_open(void)
  71. {
  72. SysTick_Config(SystemCoreClock / 1000);
  73. }
  74. char* bsp_get_fversion(void){
  75. return (char *)iap_fw_version;
  76. }
  77. /* timeout:1-25 */
  78. void wdog_start(int timeout){
  79. #if CONFIG_DEBUG == 0
  80. /* enable IRC40K */
  81. rcu_osci_on(RCU_IRC40K);
  82. /* wait till IRC40K is ready */
  83. while(SUCCESS != rcu_osci_stab_wait(RCU_IRC40K)){
  84. }
  85. /* confiure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */
  86. fwdgt_config(timeout*40000UL/256, FWDGT_PSC_DIV256);
  87. /* after 4 seconds to generate a reset */
  88. fwdgt_enable();
  89. #endif
  90. }
  91. void wdog_reload(void){
  92. #if CONFIG_DEBUG == 0
  93. fwdgt_counter_reload();
  94. #endif
  95. }
  96. void wdog_set_timeout(int timeout)
  97. {
  98. #if CONFIG_DEBUG == 0
  99. /* enable write access to FWDGT_PSC,and FWDGT_RLD */
  100. FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
  101. FWDGT_RLD = RLD_RLD(timeout*40000UL/256);
  102. /* reload the counter */
  103. FWDGT_CTL = FWDGT_KEY_RELOAD;
  104. #endif
  105. }