bsp.c 2.3 KB

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