S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_helper_endianness_cfg.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
26#ifndef SOPC_HELPER_ENDIANNESS_CFG_H_
27#define SOPC_HELPER_ENDIANNESS_CFG_H_
28
30
32#define SOPC_SWAP_2_BYTES(x) (uint16_t)(((x) & (uint16_t) 0x00FF) << 8 | ((x) & (uint16_t) 0xFF00) >> 8)
33#define SOPC_SWAP_3_BYTES(x) (((x) &0x0000FF) << 16 | ((x) &0x00FF00) | ((x) &0xFF0000) >> 16)
34#define SOPC_SWAP_4_BYTES(x) \
35 (((x) &0x000000FF) << 24 | ((x) &0x0000FF00) << 8 | ((x) &0xFF000000) >> 24 | ((x) &0x00FF0000) >> 8)
36#define SOPC_SWAP_8_BYTES(x) \
37 (((x) &0x00000000000000FF) << 56 | ((x) &0x000000000000FF00) << 40 | ((x) &0x0000000000FF0000) << 24 | \
38 ((x) &0x00000000FF000000) << 8 | ((x) &0xFF00000000000000) >> 56 | ((x) &0x00FF000000000000) >> 40 | \
39 ((x) &0x0000FF0000000000) >> 24 | ((x) &0x000000FF00000000) >> 8)
40#define SOPC_SWAP_2_DWORDS(x) (((x) &0x00000000FFFFFFFF) << 32 | ((x) &0xFFFFFFFF00000000) >> 32)
41
47
49#if SOPC_IS_LITTLE_ENDIAN
50#define SOPC_TO_LITTLE_ENDIAN_16BITS(iu16) (void) (iu16)
51#define SOPC_TO_LITTLE_ENDIAN_32BITS(iu32) (void) (iu32)
52#define SOPC_TO_LITTLE_ENDIAN_64BITS(iu64) (void) (iu64)
53#define SOPC_TO_LITTLE_ENDIAN_FLOAT(fl32) (void) (fl32)
54#define SOPC_TO_LITTLE_ENDIAN_DOUBLE(db64) (void) (db64)
55#else
56#define SOPC_TO_LITTLE_ENDIAN_16BITS(iu16) (iu16) = SOPC_SWAP_2_BYTES(iu16)
57#define SOPC_TO_LITTLE_ENDIAN_32BITS(iu32) (iu32) = SOPC_SWAP_4_BYTES(iu32)
58#define SOPC_TO_LITTLE_ENDIAN_32BITS(iu64) (iu64) = SOPC_SWAP_8_BYTES(iu64)
59#define SOPC_TO_LITTLE_ENDIAN_FLOAT(fl32) (fl32) = SOPC_SWAP_4_BYTES(fl32)
60#define SOPC_TO_LITTLE_ENDIAN_DOUBLE(db64) (db64) = SOPC_SWAP_8_BYTES(db64)
61#endif
62
63#if SOPC_IS_DOUBLE_MIDDLE_ENDIAN
64#undef SOPC_TO_LITTLE_ENDIAN_DOUBLE
65#define SOPC_TO_LITTLE_ENDIAN_DOUBLE(db64) (db64) = SOPC_SWAP_2_DWORDS(db64)
66#endif
67
68#endif /* SOPC_HELPER_ENDIANNESS_CFG_H_ */
Contains the configuration constants used by S2OPC common library. Those constants could be modified ...
void SOPC_Helper_Endianness_Check(void)
Check that machine endianness configured (:SOPC_IS_LITTLE_ENDIAN and SOPC_IS_DOUBLE_MIDDLE_ENDIAN) ma...