| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "bsp/shark_bsp.h"
- #include "bsp/gpio.h"
- #include "bsp/uart.h"
- #include "bsp/AT24CXX.h"
- #include "bsp/shark_rtc.h"
- #include "bsp/clock.h"
- #include "bsp/fmc_flash.h"
- #include "libs/logger.h"
- #include "version.h"
- #include <string.h>
- #if defined CONFIG_BOARD_SP700
- const char iap_board_name[] __attribute__((at(0x08002800))) = "SP700";
- #elif defined CONFIG_BOARD_SP600
- const char iap_board_name[] __attribute__((at(0x08002800))) = "SP600";
- #endif
- const char iap_fw_version[] __attribute__((at(0x08002A00))) = CONFIG_VERSION;
- const char iap_fw_name[] __attribute__((at(0x08002C00))) = "App";
- #define CONFIG_DEBUG 1
- extern void system_clock_config(void);
- extern void SystemCoreClockUpdate(void);
- #define ALARM_TEST 1
- #if 0
- void test_fmc_flash(void){
- uint8_t data[128];
- fmc_erase_image(50 * 1024);
- fmc_start_read_image();
- for(int i = 0; i < sizeof(data); i++){
- data[i] = i;
- }
- int count = 50;
- while(count-- >= 0) {
- for(int i = 0; i < sizeof(data); i++){
- data[i] = i;
- }
- fmc_write_image(data, sizeof(data));
- memset(data, 0, sizeof(data));
- fmc_read_image(data, sizeof(data));
- for(int i = 0; i < sizeof(data); i++){
- if (data[i] != (uint8_t)i){
- sys_debug("");
- }
- }
- }
- }
- #endif
- //all board's low level init is here
- void bsp_init(void){
- wdog_start(4);
- shark_rtc_init();
- enable_mcu_power();
- delay_us(100);
- system_clock_config(); //after dcdc open, MCU can run on full speed
- SystemCoreClockUpdate();
- gpio_init();
- shark_uart_init(SHARK_UART0);
- shark_uart_init(SHARK_UART1);
- AT24CXX_Init();
- }
- char* bsp_get_fversion(void){
- return (char *)iap_fw_version;
- }
- /* timeout:1-25 */
- void wdog_start(int timeout){
- #if CONFIG_DEBUG == 0
- /* enable IRC40K */
- rcu_osci_on(RCU_IRC40K);
- /* wait till IRC40K is ready */
- while(SUCCESS != rcu_osci_stab_wait(RCU_IRC40K)){
- }
-
- /* confiure FWDGT counter clock: 40KHz(IRC40K) / 256 = 0.15625 KHz */
- fwdgt_config(timeout*40000UL/256, FWDGT_PSC_DIV256);
- /* after 4 seconds to generate a reset */
- fwdgt_enable();
- #endif
- }
- void wdog_reload(void){
- #if CONFIG_DEBUG == 0
- fwdgt_counter_reload();
- #endif
- }
- void wdog_set_timeout(int timeout)
- {
- #if CONFIG_DEBUG == 0
- /* enable write access to FWDGT_PSC,and FWDGT_RLD */
- FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
- FWDGT_RLD = RLD_RLD(timeout*40000UL/256);
- /* reload the counter */
- FWDGT_CTL = FWDGT_KEY_RELOAD;
- #endif
- }
|