1// Copyright 2018 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#pragma once 6 7#include <zircon/compiler.h> 8#include <zircon/device/rtc.h> 9#include <ddk/device.h> 10 11__BEGIN_CDECLS 12 13// Basic validation that |rtc| has reasonable values. Does not check leap year. 14bool rtc_is_invalid(const rtc_t* rtc); 15 16// Computes seconds (Unix epoch) to |rtc|. Does not validate. Does not handle times 17// earlier than 2000/1/1T00:00:00. 18uint64_t seconds_since_epoch(const rtc_t* rtc); 19 20// Validates and cleans what an RTC device |dev| returns. If the device returns 21// nonsensical values, it sets |rtc| to 2018/1/1T00:00:00. 22void sanitize_rtc(void* ctx, zx_protocol_device_t* dev, rtc_t* rtc); 23 24// Utility binary-coded-decimal routines. 25uint8_t to_bcd(uint8_t binary); 26uint8_t from_bcd(uint8_t bcd); 27 28__END_CDECLS 29