bsp.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #if defined CONFIG_BOARD_SP700
  8. const char iap_board_name[] __attribute__((at(0x08002800))) = "SP700";
  9. #elif defined CONFIG_BOARD_SP600
  10. const char iap_board_name[] __attribute__((at(0x08002800))) = "SP600";
  11. #endif
  12. const char iap_fw_version[] __attribute__((at(0x08002A00))) = "1.0";
  13. const char iap_fw_name[] __attribute__((at(0x08002C00))) = "App";
  14. #define CONFIG_DEBUG 1
  15. extern void system_clock_config(void);
  16. extern void SystemCoreClockUpdate(void);
  17. #define ALARM_TEST 1
  18. //all board's low level init is here
  19. void bsp_init(void){
  20. wdog_start(4);
  21. shark_rtc_init();
  22. enable_mcu_power();
  23. delay_us(100);
  24. system_clock_config(); //after dcdc open, MCU can run on full speed
  25. SystemCoreClockUpdate();
  26. gpio_init();
  27. shark_uart_init(SHARK_UART0);
  28. shark_uart_init(SHARK_UART1);
  29. AT24CXX_Init();
  30. }
  31. /* timeout:1-25 */
  32. void wdog_start(int timeout){
  33. #if CONFIG_DEBUG == 0
  34. /* enable IRC40K */
  35. rcu_osci_on(RCU_IRC40K);
  36. /* wait till IRC40K is ready */
  37. while(SUCCESS != rcu_osci_stab_wait(RCU_IRC40K)){
  38. }
  39. /* confiure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */
  40. fwdgt_config(timeout*40000UL/256, FWDGT_PSC_DIV256);
  41. /* after 4 seconds to generate a reset */
  42. fwdgt_enable();
  43. #endif
  44. }
  45. void wdog_reload(void){
  46. #if CONFIG_DEBUG == 0
  47. fwdgt_counter_reload();
  48. #endif
  49. }
  50. void wdog_set_timeout(int timeout)
  51. {
  52. #if CONFIG_DEBUG == 0
  53. /* enable write access to FWDGT_PSC,and FWDGT_RLD */
  54. FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
  55. FWDGT_RLD = RLD_RLD(timeout*40000UL/256);
  56. /* reload the counter */
  57. FWDGT_CTL = FWDGT_KEY_RELOAD;
  58. #endif
  59. }