From patchwork Fri Jul 3 16:37:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1322523 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Rn/x6PoA; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49z0yX1Z7rz9sRW for ; Sat, 4 Jul 2020 02:38:28 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0CB2081BAE; Fri, 3 Jul 2020 18:37:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Rn/x6PoA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 59B8381B7C; Fri, 3 Jul 2020 18:37:54 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B12B181B65 for ; Fri, 3 Jul 2020 18:37:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x141.google.com with SMTP id o3so10371612ilo.12 for ; Fri, 03 Jul 2020 09:37:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xwSL6tP+2/dNBCSB/CgF5DNWlA13vKLSqPwGCbQbRIQ=; b=Rn/x6PoAjKszrhdK2WJZpHgbO4YzsNV7rh72OkFToNF4r/gSNmPU7sXjmGiI4x3vc8 gUK+1wnRBilPdrjiStqn7Vbbgf4JuUDG9Fs4P8+1un/k0gt7DTb6KhMPVDDqDhQ/s07W bKua2lxj0NmZU8o3QXmi8js+FgZ9htjpEVUw8= 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=xwSL6tP+2/dNBCSB/CgF5DNWlA13vKLSqPwGCbQbRIQ=; b=Z9vsA1x+TS6lDCeUNONJsSpxXgrRJ8EYV6eFvTza833OJ4ntbUrLHT6GLVhguCVPcq Y4R6UXnkSYDY6RnTxetmEwOGeZflHHhn2aiV5UCMO6BllfbqKPjAXJJb998iNoL94R4U SIoNObFYxihJZ306e+4zPLKg8Ulbh5R/3CTPkF0qC3761AMn1hfGz4HxZAwSLmnEY0eo G3ZjcBBMPLQ1PISLTQZ3qqYRnU+RhjIaGKbKIth3/muUJD2QHuLE9gDigN5hcbxcDEmD CA7JSur//dkBV7BggB+cDWOUWwxQ2+Q91BjE5cbf4KDdEtUSMVexrPhmLV5iRgmIZfPZ 0ARA== X-Gm-Message-State: AOAM530NGt/YEv2CIgvQJgZpkF5Zy9oDPFG+ZCwxsC+bKiHZ5X6pDETL 0NRZD2Kkrllj1zyuZ/SiUOhiKQZRmoOrPw== X-Google-Smtp-Source: ABdhPJx8upMmnls598LBGBLuSPx7jQVQZzHCiJ5EBiRk1XfUuRk60hQZvllSLKW7OtWIKzgbJ4t6Sg== X-Received: by 2002:a92:4913:: with SMTP id w19mr17337739ila.185.1593794266395; Fri, 03 Jul 2020 09:37:46 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id d77sm7073733ill.67.2020.07.03.09.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 09:37:46 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Bernhard Messerklinger , Simon Glass Subject: [PATCH v2 5/8] timer: Allow delays with a 32-bit microsecond timer Date: Fri, 3 Jul 2020 10:37:08 -0600 Message-Id: <20200703163711.1658000-5-sjg@chromium.org> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog In-Reply-To: <20200703163711.1658000-1-sjg@chromium.org> References: <20200703163711.1658000-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean The current get_timer_us() uses 64-bit arithmetic. When implementing microsecond-level timeouts, 32-bits is plenty. Add a new function to support this. Signed-off-by: Simon Glass --- (no changes since v1) include/time.h | 11 +++++++++++ lib/time.c | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/include/time.h b/include/time.h index e99f9c8012..434e63b075 100644 --- a/include/time.h +++ b/include/time.h @@ -17,6 +17,17 @@ unsigned long get_timer(unsigned long base); unsigned long timer_get_us(void); uint64_t get_timer_us(uint64_t base); +/** + * get_timer_us_long() - Get the number of elapsed microseconds + * + * This uses 32-bit arithmetic on 32-bit machines, which is enough to handle + * delays of over an hour. + * + *@base: Base time to consider + *@return elapsed time since @base + */ +unsigned long get_timer_us_long(unsigned long base); + /* * timer_test_add_offset() * diff --git a/lib/time.c b/lib/time.c index 65db0f6cda..47f8c84327 100644 --- a/lib/time.c +++ b/lib/time.c @@ -152,6 +152,11 @@ uint64_t __weak get_timer_us(uint64_t base) return tick_to_time_us(get_ticks()) - base; } +unsigned long __weak get_timer_us_long(unsigned long base) +{ + return timer_get_us() - base; +} + unsigned long __weak notrace timer_get_us(void) { return tick_to_time(get_ticks() * 1000);