void time_update() { if(!update) return; update = false; #if RTC_SRC != RTC_SRC_INTERNAL getRtcTime(); if(timeData.secs == 0 && timeData.mins == 0) tune_play(tuneHour, VOL_HOUR, PRIO_HOUR); #else // Slightly modified code from AVR134 if(++timeData.secs == 60) { timeData.secs = 0; if(++timeData.mins == 60) { timeData.mins = 0; if(++timeData.hour == 24) { byte numDays = time_monthDayCount(timeData.month, timeData.year); timeData.hour = 0; if (++timeData.date == numDays + 1) { timeData.month++; timeData.date = 1; } if (timeData.month == 13) { timeData.month = 1; timeData.year++; if(timeData.year == 100) timeData.year = 0; } if(++timeData.day == 7) timeData.day = 0; } tune_play(tuneHour, VOL_HOUR, PRIO_HOUR); } } #endif debug_printf("%02hhu:%02hhu:%02hhu\n", timeData.hour, timeData.mins, timeData.secs); //debug_printf("T: %hhuC\n",rtc_temp()); }
rtcwake_t time_wake() { #if RTC_SRC != RTC_SRC_INTERNAL getRtcTime(); // Turn on square wave rtc_sqw(RTC_SQW_ON); // update = false; // Check alarms bool userAlarm = rtc_userAlarmState(); bool systemAlarm = rtc_systemAlarmState(); if(userAlarm && systemAlarm) return RTCWAKE_USER_SYSTEM; else if(userAlarm) return RTCWAKE_USER; else if(systemAlarm) return RTCWAKE_SYSTEM; #endif return RTCWAKE_NONE; }
int rmon_set_etherstat_entry (etherstat_entry_t *ptr) { etherstat_entry_t *etherstat_ptr = NULL; etherstat_entry_t etherstat_data; rmon_ifstat_data_t *ifstat_data_ptr = NULL; rmon_ifstat_data_t ifstat_data; rmon_etherstat_start_entry_t *ether_start_ptr = NULL; if (!rmon_update_ifstat_data_entry(&ifstat_data, ptr->if_index)) { return RMON_FAILURE; } etherstat_ptr = rmon_get_etherstat_entry(ptr->stat_index); if (etherstat_ptr) { rmon_update_etherstat_entry(etherstat_ptr, ptr); return RMON_SUCCESS; } etherstat_ptr = rmon_alloc_memory(RMON_ETHERSTAT_ENTRY); assert(etherstat_ptr); rmon_update_etherstat_entry(etherstat_ptr, ptr); assert(atavl_insert(&rmon_etherstat_tree, etherstat_ptr) == ATAVL_OK); /* Now create entry in rmon_etherstat_start_tree */ ether_start_ptr = rmon_alloc_memory(RMON_ETHERSTAT_START_ENTRY); assert(ether_start_ptr); ether_start_ptr->stat_index = ptr->stat_index; memcpy(ether_start_ptr->if_stats, ifstat_data.if_stats, sizeof(ether_start_ptr->if_stats)); getRtcTime(ether_start_ptr->start_date); ether_start_ptr->if_index = ptr->if_index; assert(atavl_insert(&rmon_etherstat_start_tree, ether_start_ptr) == ATAVL_OK); return RMON_SUCCESS; }
}); auto handler = mbus::ObserverHandler{} .withAttach([] (mbus::Entity entity, mbus::Properties properties) { std::cout << "drivers/clocktracker: Found RTC" << std::endl; rtcLane = helix::UniqueLane(COFIBER_AWAIT entity.bind()); foundRtc.trigger(); }); COFIBER_AWAIT root.linkObserver(std::move(filter), std::move(handler)); COFIBER_AWAIT foundRtc.async_wait(); COFIBER_RETURN(); })) COFIBER_ROUTINE(async::result<RtcTime>, getRtcTime(), ([=] { helix::Offer offer; helix::SendBuffer send_req; helix::RecvInline recv_resp; managarm::clock::CntRequest req; req.set_req_type(managarm::clock::CntReqType::RTC_GET_TIME); auto ser = req.SerializeAsString(); auto &&transmit = helix::submitAsync(rtcLane, helix::Dispatcher::global(), helix::action(&offer, kHelItemAncillary), helix::action(&send_req, ser.data(), ser.size(), kHelItemChain), helix::action(&recv_resp)); COFIBER_AWAIT transmit.async_wait(); HEL_CHECK(offer.error()); HEL_CHECK(send_req.error());