6626的RTC使用

yangzh · 220次点击 · 5个月前

6626的RTC的初始化和使用方法

  1. 初始化配置 

     

rtc_tm_t set_tm;
rtc_tm_t alarm_tm;

static void rtc_second_cb(const rtc_tm_t *tm)
{
    om_printf("second cb\r\n");
}

/**
 *******************************************************************************
 * @brief alarm interrupt callback
 *
 * @param[in] event    Alarm event
 * @param[in] tm       Pointer to current time
 *
 *******************************************************************************
 */
static void rtc_alarm_cb(rtc_alarm_event_t event, const rtc_tm_t *tm)
{
    if (event == RTC_ALARM_EVENT0)
    {
        alarm_tm.tm_sec = tm->tm_sec + 2;
        drv_rtc_alarm_set(OM_RTC, RTC_ALARM_EVENT0, &alarm_tm);
        om_printf("alarm  event0\r\n");
        om_printf("rtc tm=%d,%d,%d,%d,%d,%d,%d\r\n",tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tm->tm_wday);
              
    }
    else if (event == RTC_ALARM_EVENT1)
    {
        om_printf("alarm  event1\r\n");
    }
    else if (event == RTC_ALARM_EVENT2)
    {
        om_printf("alarm  event2\r\n");
    }
}

/*******************************************************************************
 * PUBLIC FUNCTIONS
 */
/**
 *******************************************************************************
 * @brief example of using rtc second and alarm function
 *        1. "second cb" will be printed every second
 *        2. "alarm event[n]" will be printed after 2s, 5s, 9s from the beginning
 *
 *******************************************************************************
 */
void example_rtc(void)
{

    set_tm.tm_year = 2023 - 1900; // years from 1900
    set_tm.tm_mon = 6 - 1;        // months [0, 11]
    set_tm.tm_mday = 28;          // day [1, 31]
    set_tm.tm_hour = 10;          // hours [0, 23]
    set_tm.tm_min = 51;           // min [0, 59]
    set_tm.tm_sec = 10;           // sec [0, 59]
    set_tm.tm_wday = 3;           // wday [0, 6]

    memcpy(&alarm_tm, &set_tm, sizeof(rtc_tm_t));

    drv_rtc_init(OM_RTC);

    drv_rtc_register_second_isr_callback(OM_RTC, rtc_second_cb);
    drv_rtc_register_alarm_isr_callback(OM_RTC, rtc_alarm_cb);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_SECOND_INT, NULL);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_ALARM, (void *)RTC_ALARM_EVENT0);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_ALARM, (void *)RTC_ALARM_EVENT1);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_ALARM, (void *)RTC_ALARM_EVENT2);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_ALARM_INT, (void *)RTC_ALARM_EVENT0);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_ALARM_INT, (void *)RTC_ALARM_EVENT1);
    //    drv_rtc_control(OM_RTC, RTC_CONTROL_ENABLE_ALARM_INT, (void *)RTC_ALARM_EVENT2);

    alarm_tm.tm_sec += 2;
    drv_rtc_alarm_set(OM_RTC, RTC_ALARM_EVENT0, &alarm_tm);
    alarm_tm.tm_sec += 3;
    drv_rtc_alarm_set(OM_RTC, RTC_ALARM_EVENT1, &alarm_tm);
    alarm_tm.tm_sec += 4;
    drv_rtc_alarm_set(OM_RTC, RTC_ALARM_EVENT2, &alarm_tm);

    // start signal
    drv_rtc_timer_set(OM_RTC, &set_tm);
}

2.

__RAM_CODES("APP")
int main(void)
{
    struct ob_stack_param param = {
        .max_connection = OB_LE_HOST_CONNECTION_NB,
        .max_ext_adv_set = OB_LE_HOST_ADV_SET_NUM,
        .max_att_mtu = OB_LE_HOST_ATT_MTU,
        .max_gatt_serv_num = OB_LE_HOST_MAX_GATT_SERV_NUM,
        .max_gatt_write_cache = OB_LE_HOST_ATT_WRITE_CACHE_SIZE,
        .smp_sc_support = OB_LE_HOST_SC_PAIRING,
    };

    drv_wdt_init(0);
    board_init();
    hardware_init();
    drv_rf_init();
    evt_init();
    evt_timer_init();
    shell_init(NULL);
    nvds_init(0);
    omble_init(&param);

    app_adv_init();
    app_sec_init();
    service_common_init();
    app_onmicro_dfu_init();
    ancs_client_init();
    //app_media_hid_init();
    app_tspp_init();
    app_wechat_lite_init();

    uint32_t address, length;
    uint16_t crc16;
    mbr_read_part(PART_TYPE_APP, &address, &length, &crc16);
    OM_LOG_DEBUG("running(%d): 0x%08X, len: %d, crc: 0x%04X\n", drv_pmu_reboot_reason(), address, length, crc16);
    OM_LOG_DEBUG("temperature=%dC\n", (int)drv_adc_control(ADC_CONTROL_READ_TEMPERATURE, NULL));

    // simple event timer
    evt_timer_set(&evt_timer_0, 2000, EVT_TIMER_REPEAT, evt_timer_0_handler, NULL);

    example_rtc();

3.打印输出

  image.png          

被收藏 0  ∙  0 赞  
加入收藏
点赞
0 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站