97 /*****************************************************************************/ |
97 /*****************************************************************************/ |
98 |
98 |
99 #ifndef __ECRT_H__ |
99 #ifndef __ECRT_H__ |
100 #define __ECRT_H__ |
100 #define __ECRT_H__ |
101 |
101 |
|
102 #ifdef __KERNEL__ |
102 #include <asm/byteorder.h> |
103 #include <asm/byteorder.h> |
103 |
|
104 #ifdef __KERNEL__ |
|
105 #include <linux/types.h> |
104 #include <linux/types.h> |
106 #else |
105 #else |
|
106 #include <stdlib.h> // for size_t |
107 #include <stdint.h> |
107 #include <stdint.h> |
108 #endif |
108 #endif |
109 |
109 |
110 /****************************************************************************** |
110 /****************************************************************************** |
111 * Global definitions |
111 * Global definitions |
1056 if (VAL) *((uint8_t *) (DATA)) |= (1 << (POS)); \ |
1056 if (VAL) *((uint8_t *) (DATA)) |= (1 << (POS)); \ |
1057 else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \ |
1057 else *((uint8_t *) (DATA)) &= ~(1 << (POS)); \ |
1058 } while (0) |
1058 } while (0) |
1059 |
1059 |
1060 /****************************************************************************** |
1060 /****************************************************************************** |
|
1061 * Byte-swapping functions for user space |
|
1062 *****************************************************************************/ |
|
1063 |
|
1064 #ifndef __KERNEL__ |
|
1065 |
|
1066 #if __BYTE_ORDER == __LITTLE_ENDIAN |
|
1067 |
|
1068 #define le16_to_cpu(x) x |
|
1069 #define le32_to_cpu(x) x |
|
1070 |
|
1071 #define cpu_to_le16(x) x |
|
1072 #define cpu_to_le32(x) x |
|
1073 |
|
1074 #elif __BYTE_ORDER == __BIG_ENDIAN |
|
1075 |
|
1076 #define swap16(x) \ |
|
1077 ((uint16_t)( \ |
|
1078 (((uint16_t)(x) & 0x00ffU) << 8) | \ |
|
1079 (((uint16_t)(x) & 0xff00U) >> 8) )) |
|
1080 #define swap32(x) \ |
|
1081 ((uint32_t)( \ |
|
1082 (((uint32_t)(x) & 0x000000ffUL) << 24) | \ |
|
1083 (((uint32_t)(x) & 0x0000ff00UL) << 8) | \ |
|
1084 (((uint32_t)(x) & 0x00ff0000UL) >> 8) | \ |
|
1085 (((uint32_t)(x) & 0xff000000UL) >> 24) )) |
|
1086 |
|
1087 #define le16_to_cpu(x) swap16(x) |
|
1088 #define le32_to_cpu(x) swap32(x) |
|
1089 |
|
1090 #define cpu_to_le16(x) swap16(x) |
|
1091 #define cpu_to_le32(x) swap32(x) |
|
1092 |
|
1093 #endif |
|
1094 |
|
1095 #define le16_to_cpup(x) le16_to_cpu(*((uint16_t *)(x))) |
|
1096 #define le32_to_cpup(x) le32_to_cpu(*((uint32_t *)(x))) |
|
1097 |
|
1098 #endif /* ifndef __KERNEL__ */ |
|
1099 |
|
1100 /****************************************************************************** |
1061 * Read macros |
1101 * Read macros |
1062 *****************************************************************************/ |
1102 *****************************************************************************/ |
1063 |
1103 |
1064 /** Read an 8-bit unsigned value from EtherCAT data. |
1104 /** Read an 8-bit unsigned value from EtherCAT data. |
1065 * |
1105 * |