From patchwork Tue May 18 10:07:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 12309 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1EAE0C31FF for ; Tue, 18 May 2021 10:09:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF3AD68923; Tue, 18 May 2021 12:09:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ipvv506i"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30B8F68918 for ; Tue, 18 May 2021 12:09:12 +0200 (CEST) Received: by mail-wr1-x435.google.com with SMTP id j14so7804056wrq.5 for ; Tue, 18 May 2021 03:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pc4bXwGv6lhgm9H31iNKrGOKtTpaANgZvy51COpEY2A=; b=ipvv506irWktLmwQdw3/pZsiiSKvDUwI6Tr9eKOROdV2zZ2NgG0BvW+bPZrceLq0RL LNEP7uwEKERQuAu0UDXqxgWQHsD3i75SRVQwV5ifdZ4/prDd5lNf4kCfG39yymiWYNm7 LCXC+K+TeWIEr7CMT1ofK0jU4mQ4UyFh3rVncPp0Brz3qy0fNth/UxzqH96mu2VquVLS CtKxPgbc/AkrBgINXMzEWk9fywX2VtW2GEsUe/TA4U7bnixm6ufbo27+LEX0+H8LW7O/ uYRLPhK6KptYoTB3kceFU08jULYB1g9tpl6NUnfgH/44DM8SRwxbjpSyg05Bj1Nf5HKL l0BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pc4bXwGv6lhgm9H31iNKrGOKtTpaANgZvy51COpEY2A=; b=MgihViYRqUXSMgeTMMhfFybbreDYdhazSCCBguYn64m5vqYy9nf86SzkAtk40aVLtc UMl0RoMC1B1TG11FNgxEW3GuFABcnkS0Jo85EWsdyWKtUR8hUNKkErLCRSr11C+pFAQy 43Yz2BJRmS4orgFhlYMBQjL2WzNlTmwDB0F7FgH2uiaDjqWKqVgAQnlUJ6j3EtmGuO1W OGfvFnXNQzzXm5b2J/DJ+wkCvDLcbd0KCe2QeHrmSGVT+zzPps8Z1PUTnqmjcn7cM22r cv/q6I8+d/YdPX984De8K2RZYIJn11y02YA4jx8ykwS/3ge6WLHRp1Ok/57Cp9E6ItNE fpUA== X-Gm-Message-State: AOAM532AtT663BtuYkMnZLVe+hh73PS1Ot3JK3Hfit1kUXZW6SBwogj/ ke2kO/kLq2Dlhs9xqPasXOjsMxdVZIpCRQ== X-Google-Smtp-Source: ABdhPJz39hxjWULjwuwYawdOPhgcgxRFR7wsgKwphQK6Ncs8t1vQk03hsItTBgM5d0VfvnPthyb5Qg== X-Received: by 2002:a5d:6804:: with SMTP id w4mr5983183wru.363.1621332551493; Tue, 18 May 2021 03:09:11 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:34e4:187b:f2:ed28]) by smtp.gmail.com with ESMTPSA id o11sm6566682wrq.93.2021.05.18.03.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 03:09:10 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Tue, 18 May 2021 11:07:03 +0100 Message-Id: <20210518100706.578526-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210518100706.578526-1-naush@raspberrypi.com> References: <20210518100706.578526-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] ipa: raspberrypi: Add helper macros for std::chrono::duration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" A new RPiController::Duration typedef is defined to represent a std::chrono::duration type with double precision nanosecond timebase that will be used throughout. This minimises the loss of precision when converting timebases. A function for returning the duration count in any timebase is also provided. An operator << overload is define to help with displaying RPiController::Duration value in stream objects. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/controller/duration.hpp | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/ipa/raspberrypi/controller/duration.hpp diff --git a/src/ipa/raspberrypi/controller/duration.hpp b/src/ipa/raspberrypi/controller/duration.hpp new file mode 100644 index 000000000000..98aa3d78f52f --- /dev/null +++ b/src/ipa/raspberrypi/controller/duration.hpp @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2021, Raspberry Pi (Trading) Limited + * + * duration.hpp - Helper macros for std::chrono::duration handling. + */ +#pragma once + +#include +#include +#include + +namespace RPiController { + +using Duration = std::chrono::duration; + +// Helper to convert and return the count of any std::chrono::duration type to +// another timebase. Use a double rep type to try and preserve precision. +template +static constexpr double DurationValue(T const &d) +{ + return std::chrono::duration_cast>(d).count(); +}; + +static inline std::ostream &operator<<(std::ostream &os, const Duration &duration) +{ + std::streamsize ss = os.precision(); + os << std::fixed << std::setprecision(2) << DurationValue(duration) << " us"; + os << std::setprecision(ss) << std::defaultfloat; + return os; +} + +} // namespace RPiController