61 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "os_types.h"
 | 
						|
#include "dbg_io.h"
 | 
						|
#include "iot_diag.h"
 | 
						|
#include "iot_io.h"
 | 
						|
#include "rtc_mon.h"
 | 
						|
#include "gp_timer.h"
 | 
						|
#include "iot_clock.h"
 | 
						|
 | 
						|
#include "rtc_hw.h"
 | 
						|
 | 
						|
uint32_t rtc_mon_int_process(uint32_t cnt, uint32_t st)
 | 
						|
{
 | 
						|
    static int i=0, j=0;
 | 
						|
    iot_printf("RTC clk variration exceed thresh hold,status: 0x%x cnt: 0x%x\r\n", st, cnt );
 | 
						|
    i++;
 | 
						|
    if(i%20 == 0)
 | 
						|
    {
 | 
						|
        if(j){
 | 
						|
           j=0;
 | 
						|
           rtc_tmr_set_comp(4, 0x20000);
 | 
						|
        }else{
 | 
						|
           rtc_tmr_set_comp(4, 0x50000);
 | 
						|
           j=1;
 | 
						|
        }
 | 
						|
        rtc_tmr_load_set(4, 1);
 | 
						|
    }
 | 
						|
    iot_delay_us(10000);
 | 
						|
    rtc_tmr_load_set(4, 0);
 | 
						|
    rtc_mon_start(1);
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
int IRAM_ATTR main(void)
 | 
						|
{
 | 
						|
    gp_timer_init();
 | 
						|
    gp_timer_set(0, 1*10000000, 1);
 | 
						|
    gp_timer_start(0);
 | 
						|
    dbg_uart_init();
 | 
						|
 | 
						|
    rtc_tmr_set_value(4, 0xffffffff);
 | 
						|
    rtc_tmr_mode_set(4,1);
 | 
						|
    rtc_tmr_set_load_mode(4,0);
 | 
						|
    rtc_tmr_en(4, 1);
 | 
						|
 | 
						|
    rtc_mon_cfg_threshold(0x3f);
 | 
						|
    rtc_mon_cfg_cycle(7);
 | 
						|
    rtc_mon_cfg_type(CONT_MON);
 | 
						|
    rtc_mon_int_init(rtc_mon_int_process);
 | 
						|
    rtc_mon_start(1);
 | 
						|
 | 
						|
    while(1)
 | 
						|
    {
 | 
						|
        iot_delay_us(1000000);
 | 
						|
        iot_printf("RTC MONITOR ...cfg: 0x%x  rtc_tmr0 current cnt:0x%x\r\n", rtc_mon_get_cfg(),rtc_tmr_get_curr_value(4));
 | 
						|
    }
 | 
						|
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
 |