From patchwork Wed Feb 17 14:36:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 62109 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp2992lbl; Wed, 17 Feb 2016 05:38:13 -0800 (PST) X-Received: by 10.140.129.79 with SMTP id 76mr1988819qhb.28.1455716293149; Wed, 17 Feb 2016 05:38:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p59si46165899qge.124.2016.02.17.05.38.12; Wed, 17 Feb 2016 05:38:13 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B63C0619E8; Wed, 17 Feb 2016 13:38:12 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=DsFeDbqQ; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 6CCDB61790; Wed, 17 Feb 2016 13:37:41 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 36DBB61610; Wed, 17 Feb 2016 13:37:33 +0000 (UTC) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by lists.linaro.org (Postfix) with ESMTPS id D06EF615CA for ; Wed, 17 Feb 2016 13:37:31 +0000 (UTC) Received: by mail-lb0-f182.google.com with SMTP id bc4so9520619lbc.2 for ; Wed, 17 Feb 2016 05:37:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OSmhIwi/wSRshAH94bf8feiyHHazGAd2kiaeKSNVlHs=; b=DsFeDbqQOR5aqGOfnEl5AHAaEy8LQOZWT1e5HywTjDR3rDC05sQ0Hiq4aULlDKqyA6 41XJT/oQEou1Ym+/8xLW77NEed4qtkAANheriq93cOYyV4YMLwOZ0SlebAkKI23W/Qov HPapJxmR/DFfZY78wUAyqTK4ZkrsJnss6vCLo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OSmhIwi/wSRshAH94bf8feiyHHazGAd2kiaeKSNVlHs=; b=hQjy62XBBLF5a8GKYNgHEg+mhEEg1G3L+oMJVvFxRur+Di7BfPK2rtTPbU3ynjEFWw i/qKDxCPX0DWfFD/tTltWLAekarPBD+HejqgbBU02C/RFwZoqoiuwvD3rP3VRNKsU0pj OXGYNxsb89q1fRcrAXgZ8oS7A4EbmVflDmj2J+rS8rdIMM/Qndnn9oA9CvXzn6LO22bE nu4vl8MkGfthdNl37QpfNCzkML+SoL14oXYpVRS55UR8Cf/lU9+f7WBfPz/Ytqk6kKQj W3NrRIeyXgYaeh6In5LzrhC5PdsQRfxVUvzlpgjNveTjmhP6SJTk+nUTeTzbI2zAhctH FC7g== X-Gm-Message-State: AG10YOTJ7KMuDGg2f7o9Xx6yYIifqrjLqzzVTjoXscUvV9lV5auVUiF9v7VqNOPMdUyfsIKusdw= X-Received: by 10.112.25.99 with SMTP id b3mr772356lbg.11.1455716250811; Wed, 17 Feb 2016 05:37:30 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id wj2sm215102lbb.5.2016.02.17.05.37.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 05:37:30 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org Date: Wed, 17 Feb 2016 15:36:15 +0100 Message-Id: <1455719777-15879-2-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455719777-15879-1-git-send-email-christophe.milard@linaro.org> References: <1455719777-15879-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT PATCH 1/3] drv: adding byteorder.h X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Christophe Milard --- include/odp/drv/spec/byteorder.h | 176 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 include/odp/drv/spec/byteorder.h diff --git a/include/odp/drv/spec/byteorder.h b/include/odp/drv/spec/byteorder.h new file mode 100644 index 0000000..2543016 --- /dev/null +++ b/include/odp/drv/spec/byteorder.h @@ -0,0 +1,176 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP byteorder + */ + +#ifndef ODPDRV_BYTEORDER_H_ +#define ODPDRV_BYTEORDER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup odpdrv_compiler_optim ODPDRV COMPILER / OPTIMIZATION + * Macros that check byte order and operations for byte order conversion. + * @{ + */ + +/** + * @def ODPDRV_BIG_ENDIAN + * Big endian byte order + * + * @def ODPDRV_LITTLE_ENDIAN + * Little endian byte order + * + * @def ODPDRV_BIG_ENDIAN_BITFIELD + * Big endian bit field + * + * @def ODPDRV_LITTLE_ENDIAN_BITFIELD + * Little endian bit field + * + * @def ODPDRV_BYTE_ORDER + * Selected byte order + */ + +/** + * @typedef odpdrv_u16le_t + * unsigned 16bit little endian + * + * @typedef odpdrv_u16be_t + * unsigned 16bit big endian + * + * @typedef odpdrv_u32le_t + * unsigned 32bit little endian + * + * @typedef odpdrv_u32be_t + * unsigned 32bit big endian + * + * @typedef odpdrv_u64le_t + * unsigned 64bit little endian + * + * @typedef odpdrv_u64be_t + * unsigned 64bit big endian + * + * @typedef odpdrv_u16sum_t + * unsigned 16bit bitwise + * + * @typedef odpdrv_u32sum_t + * unsigned 32bit bitwise + */ + +/* + * Big Endian -> CPU byte order: + */ + +/** + * Convert 16bit big endian to cpu native uint16_t + * @param be16 big endian 16bit + * @return cpu native uint16_t + */ +uint16_t odpdrv_be_to_cpu_16(odpdrv_u16be_t be16); + +/** + * Convert 32bit big endian to cpu native uint32_t + * @param be32 big endian 32bit + * @return cpu native uint32_t + */ +uint32_t odpdrv_be_to_cpu_32(odpdrv_u32be_t be32); + +/** + * Convert 64bit big endian to cpu native uint64_t + * @param be64 big endian 64bit + * @return cpu native uint64_t + */ +uint64_t odpdrv_be_to_cpu_64(odpdrv_u64be_t be64); + +/* + * CPU byte order -> Big Endian: + */ + +/** + * Convert cpu native uint16_t to 16bit big endian + * @param cpu16 uint16_t in cpu native format + * @return big endian 16bit + */ +odpdrv_u16be_t odpdrv_cpu_to_be_16(uint16_t cpu16); + +/** + * Convert cpu native uint32_t to 32bit big endian + * @param cpu32 uint32_t in cpu native format + * @return big endian 32bit + */ +odpdrv_u32be_t odpdrv_cpu_to_be_32(uint32_t cpu32); + +/** + * Convert cpu native uint64_t to 64bit big endian + * @param cpu64 uint64_t in cpu native format + * @return big endian 64bit + */ +odpdrv_u64be_t odpdrv_cpu_to_be_64(uint64_t cpu64); + +/* + * Little Endian -> CPU byte order: + */ + +/** + * Convert 16bit little endian to cpu native uint16_t + * @param le16 little endian 16bit + * @return cpu native uint16_t + */ +uint16_t odpdrv_le_to_cpu_16(odpdrv_u16le_t le16); + +/** + * Convert 32bit little endian to cpu native uint32_t + * @param le32 little endian 32bit + * @return cpu native uint32_t + */ +uint32_t odpdrv_le_to_cpu_32(odpdrv_u32le_t le32); + +/** + * Convert 64bit little endian to cpu native uint64_t + * @param le64 little endian 64bit + * @return cpu native uint64_t + */ +uint64_t odpdrv_le_to_cpu_64(odpdrv_u64le_t le64); + +/* + * CPU byte order -> Little Endian: + */ + +/** + * Convert cpu native uint16_t to 16bit little endian + * @param cpu16 uint16_t in cpu native format + * @return little endian 16bit + */ +odpdrv_u16le_t odpdrv_cpu_to_le_16(uint16_t cpu16); + +/** + * Convert cpu native uint32_t to 32bit little endian + * @param cpu32 uint32_t in cpu native format + * @return little endian 32bit + */ +odpdrv_u32le_t odpdrv_cpu_to_le_32(uint32_t cpu32); + +/** + * Convert cpu native uint64_t to 64bit little endian + * @param cpu64 uint64_t in cpu native format + * @return little endian 64bit + */ +odpdrv_u64le_t odpdrv_cpu_to_le_64(uint64_t cpu64); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif