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 <ddk/device.h> 8 #include <fuchsia/hardware/rtc/c/fidl.h> 9 #include <zircon/compiler.h> 10 11 __BEGIN_CDECLS 12 13 // Basic validation that |rtc| has reasonable values. Does not check leap year. 14 bool rtc_is_invalid(const fuchsia_hardware_rtc_Time* rtc); 15 16 // Computes seconds (Unix epoch) to |rtc|. Does not validate. Does not handle times 17 // earlier than 2000/1/1T00:00:00. 18 uint64_t seconds_since_epoch(const fuchsia_hardware_rtc_Time* rtc); 19 void seconds_to_rtc(uint64_t seconds, fuchsia_hardware_rtc_Time* rtc); 20 21 // Validates and cleans what an RTC device |dev| returns. If the device returns 22 // nonsensical values, it sets |rtc| to 2018/1/1T00:00:00. 23 void sanitize_rtc(void* ctx, fuchsia_hardware_rtc_Time* rtc, 24 zx_status_t (*rtc_get)(void*, fuchsia_hardware_rtc_Time*), 25 zx_status_t (*rtc_set)(void*, const fuchsia_hardware_rtc_Time*)); 26 27 // Utility binary-coded-decimal routines. 28 uint8_t to_bcd(uint8_t binary); 29 uint8_t from_bcd(uint8_t bcd); 30 31 __END_CDECLS 32