SOEM-Ethercat源代码解析一(数据类型定义)

广大的朋友们,今天我们一起来看Ethercat主站源代码,进入源码的世界。

/**
  * Simple Open EtherCAT Master Library
  * 通用类型和EtherCAT定义
  */

#ifndef _EC_TYPE_H
#define _EC_TYPE_H

#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

/** Define Little or Big endian target */
/*定义通讯为小端模式*/
#define EC_LITTLE_ENDIAN

/** define EC_VER1 if version 1 default context and functions are needed
 * comment if application uses only ecx_ functions and own context */
/*使用V1版本上下文函数*/
#define EC_VER1

/** return value general error */
/*通用错误返回值*/
#define EC_ERROR           -3

/** return value no frame returned */
/*无数据帧返回*/
#define EC_NOFRAME         -1

/** return value unknown frame received */
/*无法识别的数据包接收*/
#define EC_OTHERFRAME      -2

/** maximum EtherCAT frame length in bytes */
/*最大ethercat数据包长度*/
#define EC_MAXECATFRAME    1518

/** maximum EtherCAT LRW frame length in bytes */
/*最大EtherCAT LRW数据包长度*/
/* MTU - Ethernet header - length - datagram header - WCK - FCS */
#define EC_MAXLRWDATA      (EC_MAXECATFRAME - 14 - 2 - 10 - 2 - 4)

/** size of DC datagram used in first LRW frame */
/*在首帧LRW数据包中DC同步数据帧大小*/
#define EC_FIRSTDCDATAGRAM 20

/** standard frame buffer size in bytes */
/*标准数据帧缓冲大小*/
#define EC_BUFSIZE         EC_MAXECATFRAME

/** datagram type EtherCAT */
/*EtherCAT 数据包类型*/
#define EC_ECATTYPE        0x1000

/** number of frame buffers per channel (tx, rx1 rx2) */
/*每通道(tx, rx1 rx2)数据包缓存数量*/
#define EC_MAXBUF          16

/** timeout value in us for tx frame to return to rx */
/*发送数据包到接收数据包超时时间*/
#define EC_TIMEOUTRET      2000

/** timeout value in us for safe data transfer, max. triple retry */
/*安全数据发送超时时间,最大尝试发送三次*/
#define EC_TIMEOUTRET3     (EC_TIMEOUTRET * 3)

/** timeout value in us for return "safe" variant (f.e. wireless) */
/*safe 变体返回超时时间(us)*/
#define EC_TIMEOUTSAFE     20000

/** timeout value in us for EEPROM access */
/*EEPROM 操作-超时时间(us)*/
#define EC_TIMEOUTEEP      20000

/** timeout value in us for tx mailbox cycle */
/*tx邮箱循环超时时间(us)*/
#define EC_TIMEOUTTXM      20000

/** timeout value in us for rx mailbox cycle */
/*rx邮箱循环超时时间(us)*/
#define EC_TIMEOUTRXM      700000

/** timeout value in us for check statechange */
/*状态切换检测超时时间(us)*/
#define EC_TIMEOUTSTATE    2000000

/** size of EEPROM bitmap cache */
/*EEPROM 位缓冲大小*/
#define EC_MAXEEPBITMAP    128

/** size of EEPROM cache buffer */
/*EEPROM 缓冲缓存大小-4096*/
#define EC_MAXEEPBUF       EC_MAXEEPBITMAP << 5

/** default number of retries if wkc <= 0 */
/*默认尝试次数-3次*/
#define EC_DEFAULTRETRIES  3

/*数据数据宏定义*/
/* General types */
typedef uint8_t             boolean;    //无符号8位作为bool类型
#define TRUE                1
#define FALSE               0
typedef int8_t              int8;       //有符号8位
typedef int16_t             int16;      //有符号16位
typedef int32_t             int32;      //有符号32位
typedef uint8_t             uint8;      //无符号8位
typedef uint16_t            uint16;     //无符号16位
typedef uint32_t            uint32;     //无符号32位
typedef int64_t             int64;      //有符号64位
typedef uint64_t            uint64;     //无符号64位
typedef float               float32;    //单浮点
typedef double              float64;    //双浮点

typedef struct
{
    uint32 sec;     /*< Seconds elapsed since the Epoch (Jan 1, 1970) */
    int32 usec;      /*< Microseconds elapsed since last second boundary */
} ec_timet;         /*时间单位结构体*/

typedef struct osal_timer
{
    ec_timet stop_time;
} osal_timert;      /*定时器记录时间结构体*/


/** definition for frame buffers */
/*定义数据包缓存大小*/
typedef uint8 ec_bufT[EC_BUFSIZE];

/*结构体前缀头*/
#if defined(WIN32)
    //结构体前缀
    #ifndef PACKED
        #define PACKED_BEGIN __pragma(pack(push, 1))
        #define PACKED
        #define PACKED_END __pragma(pack(pop))
    #endif

    //函数前缀
    #define OSAL_THREAD_HANDLE HANDLE
    #define OSAL_THREAD_FUNC void
    #define OSAL_THREAD_FUNC_RT void
#elif defined(__linux__)
    //结构体前缀
    #ifndef PACKED
        #define PACKED_BEGIN
        #define PACKED  __attribute__((__packed__))
        #define PACKED_END
    #endif

    //函数前缀
    #define OSAL_THREAD_HANDLE task_t *
    #define OSAL_THREAD_FUNC void
    #define OSAL_THREAD_FUNC_RT void
#else
    //结构体前缀
    #ifndef PACKED
        #define PACKED_BEGIN
        #define PACKED  __attribute__((__packed__))
        #define PACKED_END
    #endif

    //函数前缀
    #define OSAL_THREAD_HANDLE task_t *
    #define OSAL_THREAD_FUNC void
    #define OSAL_THREAD_FUNC_RT void
#endif


/** ethernet header definition */
/*以太网头数据包*/
PACKED_BEGIN
typedef struct PACKED
{
   /** destination MAC 目标地址*/
   uint16  da0,da1,da2;
   /** source MAC  源地址*/
   uint16  sa0,sa1,sa2;
   /** ethernet type 帧类型0x88A4*/
   uint16  etype;
} ec_etherheadert;
PACKED_END

/** ethernet header size */
/*以太网头数据包大小*/
#define ETH_HEADERSIZE      sizeof(ec_etherheadert)

/** EtherCAT datagram header definition */
/*EtherCAT数据包头定义*/
PACKED_BEGIN
typedef struct PACKED
{
   /** length of EtherCAT datagram 数据包长度*/
   uint16  elength;
   /** EtherCAT command, see ec_cmdtype 命令 */
   uint8   command;
   /** index, used in SOEM for Tx to Rx recombination 索引*/
   uint8   index;
   /** ADP 地址区*/
   uint16  ADP;
   /** ADO 地址区*/
   uint16  ADO;
   /** length of data portion in datagram 数据包长度*/
   uint16  dlength;
   /** interrupt, currently unused 中断(未使用)*/
   uint16  irpt;
} ec_comt;
PACKED_END

/** EtherCAT header size */
/*EtherCAT数据包头大小*/
#define EC_HEADERSIZE       sizeof(ec_comt)

/** size of ec_comt.elength item in EtherCAT header */
/*EtherCAT数据包头 长度 大小-2*/
#define EC_ELENGTHSIZE      sizeof(uint16)

/** offset position of command in EtherCAT header */
/*EtherCAT数据包头 子报文起始位置*/
#define EC_CMDOFFSET        EC_ELENGTHSIZE

/** size of workcounter item in EtherCAT datagram */
/*EtherCAT数据包头 WKC计数大小 -2*/
#define EC_WKCSIZE          sizeof(uint16)

/** definition of datagram follows bit in ec_comt.dlength */
/*子报文中后续报文标志位*/
#define EC_DATAGRAMFOLLOWS  (1 << 15)

/** Possible error codes returned. */
/*可能返回的错误*/
typedef enum
{
   /** No error OK状态*/
   EC_ERR_OK         = 0,
   /** Library already initialized. 库已经初始化*/
   EC_ERR_ALREADY_INITIALIZED   =1,
   /** Library not initialized.     库未进行初始化*/
   EC_ERR_NOT_INITIALIZED   =2,
   /** Timeout occured during execution of the function. 执行函数发生超时*/
   EC_ERR_TIMEOUT   =3,
   /** No slaves were found. 未发现从站节点*/
   EC_ERR_NO_SLAVES =4,
   /** Function failed. 函数执行失败*/
   EC_ERR_NOK =5
} ec_err;

/** Possible EtherCAT slave states */
/*EtherCAT 从站运行的状态*/
typedef enum
{
   /** Init state 初始化*/
   EC_STATE_INIT           = 0x01,
   /** Pre-operational. 预操作*/
   EC_STATE_PRE_OP         = 0x02,
   /** Boot state 升级模式*/
   EC_STATE_BOOT            = 0x03,
   /** Safe-operational. 安全模式*/
   EC_STATE_SAFE_OP        = 0x04,
   /** Operational 操作模式*/
   EC_STATE_OPERATIONAL    = 0x08,
   /** Error or ACK error 错误 或者 ACK错误*/
   EC_STATE_ACK            = 0x10,
   EC_STATE_ERROR          = 0x10
} ec_state;

/** Possible buffer states */
/*ECT Buffer状态*/
typedef enum
{
   /** Empty 空*/
   EC_BUF_EMPTY        = 0x00,
   /** Allocated, but not filled 内存分配但未filled*/
   EC_BUF_ALLOC        = 0x01,
   /** Transmitted 发送*/
   EC_BUF_TX           = 0x02,
   /** Received, but not consumed 接收 但未consumed*/
   EC_BUF_RCVD         = 0x03,
   /** Cycle completed 循环完成*/
   EC_BUF_COMPLETE     = 0x04
} ec_bufstate;

/** Ethercat data types */
/*Ethercat 数据类型*/
typedef enum
{
   ECT_BOOLEAN         = 0x0001,
   ECT_INTEGER8        = 0x0002,
   ECT_INTEGER16       = 0x0003,
   ECT_INTEGER32       = 0x0004,
   ECT_UNSIGNED8       = 0x0005,
   ECT_UNSIGNED16      = 0x0006,
   ECT_UNSIGNED32      = 0x0007,
   ECT_REAL32          = 0x0008,
   ECT_VISIBLE_STRING  = 0x0009,
   ECT_OCTET_STRING    = 0x000A,
   ECT_UNICODE_STRING  = 0x000B,
   ECT_TIME_OF_DAY     = 0x000C,
   ECT_TIME_DIFFERENCE = 0x000D,
   ECT_DOMAIN          = 0x000F,
   ECT_INTEGER24       = 0x0010,
   ECT_REAL64          = 0x0011,
   ECT_INTEGER64       = 0x0015,
   ECT_UNSIGNED24      = 0x0016,
   ECT_UNSIGNED64      = 0x001B,
   ECT_BIT1            = 0x0030,
   ECT_BIT2            = 0x0031,
   ECT_BIT3            = 0x0032,
   ECT_BIT4            = 0x0033,
   ECT_BIT5            = 0x0034,
   ECT_BIT6            = 0x0035,
   ECT_BIT7            = 0x0036,
   ECT_BIT8            = 0x0037
} ec_datatype;

/** Ethercat command types */
/*Ethercat 命令类型*/
typedef enum 
{
   /** No operation 空命令*/
   EC_CMD_NOP          = 0x00,
   /** Auto Increment Read 自增读取*/
   EC_CMD_APRD,
   /** Auto Increment Write 自增写入*/
   EC_CMD_APWR,
   /** Auto Increment Read Write 自增读写*/
   EC_CMD_APRW,
   /** Configured Address Read 配置Alisa读取*/
   EC_CMD_FPRD,
   /** Configured Address Write 配置Alisa写入*/
   EC_CMD_FPWR,
   /** Configured Address Read Write 配置Alisa读写*/
   EC_CMD_FPRW,
   /** Broadcast Read 广播读取*/
   EC_CMD_BRD,
   /** Broaddcast Write 广播写入*/
   EC_CMD_BWR,
   /** Broadcast Read Write 广播读写*/
   EC_CMD_BRW,
   /** Logical Memory Read 逻辑内存读*/
   EC_CMD_LRD,
   /** Logical Memory Write 逻辑内存写*/
   EC_CMD_LWR,
   /** Logical Memory Read Write 逻辑内存读写*/
   EC_CMD_LRW,
   /** Auto Increment Read Mulitple Write 自增都多写*/
   EC_CMD_ARMW,
   /** Configured Read Mulitple Write 配置都多写*/
   EC_CMD_FRMW
   /** Reserved */
} ec_cmdtype;

/** Ethercat EEprom command types */
/*Ethercat EEprom命令类型*/
typedef enum 
{
   /** No operation 无操作*/
   EC_ECMD_NOP         = 0x0000,
   /** Read 读*/
   EC_ECMD_READ        = 0x0100,
   /** Write 写*/
   EC_ECMD_WRITE       = 0x0201,
   /** Reload 加载*/
   EC_ECMD_RELOAD      = 0x0300
} ec_ecmdtype;

/*EEprom state */
/** EEprom state machine read size EEprom状态设备读取大小*/
#define EC_ESTAT_R64    0x0040
/** EEprom state machine busy flag EEprom状态设备忙标志*/
#define EC_ESTAT_BUSY   0x8000
/** EEprom state machine error flag mask EEprom状态设备错误标志掩码*/
#define EC_ESTAT_EMASK  0x7800
/** EEprom state machine error acknowledge EEprom状态设备错误应答*/
#define EC_ESTAT_NACK   0x2000

/* Ethercat SSI (Slave Information Interface) *从站信息接口/

/** Start address SII sections in Eeprom 在Eeprom中起始SSI地址段*/
#define ECT_SII_START   0x0040

enum
{
   /** SII category strings SSI目录字符串*/
   ECT_SII_STRING      = 10,
   /** SII category general SSI目录通用*/
   ECT_SII_GENERAL     = 30,
   /** SII category FMMU SSI目录FMMU*/
   ECT_SII_FMMU        = 40,
   /** SII category SM  SSI目录SM*/
   ECT_SII_SM          = 41,
   /** SII category PDO SSI目录PDO*/
   ECT_SII_PDO         = 50
};

/** Item offsets in SII general section 在SSI通用段中项配置 */
enum
{
   ECT_SII_MANUF       = 0x0008,
   ECT_SII_ID          = 0x000a,
   ECT_SII_REV         = 0x000c,
   ECT_SII_BOOTRXMBX   = 0x0014,
   ECT_SII_BOOTTXMBX   = 0x0016,
   ECT_SII_MBXSIZE     = 0x0019,
   ECT_SII_TXMBXADR    = 0x001a,
   ECT_SII_RXMBXADR    = 0x0018,
   ECT_SII_MBXPROTO    = 0x001c
};

/** Mailbox types definitions */
/*邮箱类型定义*/
enum
{
   /** Error mailbox type 错误邮箱类型*/
   ECT_MBXT_ERR        = 0x00,
   /** ADS over EtherCAT mailbox type AOE协议*/
   ECT_MBXT_AOE,
   /** Ethernet over EtherCAT mailbox type EOE协议*/
   ECT_MBXT_EOE,
   /** CANopen over EtherCAT mailbox type COE协议*/
   ECT_MBXT_COE,
   /** File over EtherCAT mailbox type FOE协议*/
   ECT_MBXT_FOE,
   /** Servo over EtherCAT mailbox type SOE协议*/
   ECT_MBXT_SOE,
   /** Vendor over EtherCAT mailbox type VOE协议*/
   ECT_MBXT_VOE        = 0x0f
};

/** CoE mailbox types */
/*COE 邮箱类型*/
enum
{
   ECT_COES_EMERGENCY  = 0x01,
   ECT_COES_SDOREQ,
   ECT_COES_SDORES,
   ECT_COES_TXPDO,
   ECT_COES_RXPDO,
   ECT_COES_TXPDO_RR,
   ECT_COES_RXPDO_RR,
   ECT_COES_SDOINFO
};

/** CoE SDO commands */
/*COE SDO命令*/
enum
{
   ECT_SDO_DOWN_INIT    = 0x21,
   ECT_SDO_DOWN_EXP     = 0x23,
   ECT_SDO_DOWN_INIT_CA = 0x31,
   ECT_SDO_UP_REQ       = 0x40,
   ECT_SDO_UP_REQ_CA    = 0x50,
   ECT_SDO_SEG_UP_REQ   = 0x60,
   ECT_SDO_ABORT        = 0x80
};

/** CoE Object Description commands */
/*COE对象字典描述命令*/
enum
{
   ECT_GET_ODLIST_REQ  = 0x01,
   ECT_GET_ODLIST_RES  = 0x02,
   ECT_GET_OD_REQ      = 0x03,
   ECT_GET_OD_RES      = 0x04,
   ECT_GET_OE_REQ      = 0x05,
   ECT_GET_OE_RES      = 0x06,
   ECT_SDOINFO_ERROR   = 0x07
};

/** FoE opcodes */
/*FOE操作码命令*/
enum
{
   ECT_FOE_READ        = 0x01,
   ECT_FOE_WRITE,
   ECT_FOE_DATA,
   ECT_FOE_ACK,
   ECT_FOE_ERROR,
   ECT_FOE_BUSY
};

/** SoE opcodes */
/*SOE操作码命令*/
enum
{
   ECT_SOE_READREQ     = 0x01,
   ECT_SOE_READRES,
   ECT_SOE_WRITEREQ,
   ECT_SOE_WRITERES,
   ECT_SOE_NOTIFICATION,
   ECT_SOE_EMERGENCY
};

/** Ethercat registers */
/*Ethercat寄存器*/
enum 
{
   ECT_REG_TYPE        = 0x0000,
   ECT_REG_PORTDES     = 0x0007,
   ECT_REG_ESCSUP      = 0x0008,
   ECT_REG_STADR       = 0x0010,
   ECT_REG_ALIAS       = 0x0012,
   ECT_REG_DLCTL       = 0x0100,
   ECT_REG_DLPORT      = 0x0101,
   ECT_REG_DLALIAS     = 0x0103,
   ECT_REG_DLSTAT      = 0x0110,
   ECT_REG_ALCTL       = 0x0120,
   ECT_REG_ALSTAT      = 0x0130,
   ECT_REG_ALSTATCODE  = 0x0134,
   ECT_REG_PDICTL      = 0x0140,
   ECT_REG_IRQMASK     = 0x0200,
   ECT_REG_RXERR       = 0x0300,
   ECT_REG_FRXERR      = 0x0308,
   ECT_REG_EPUECNT     = 0x030C,
   ECT_REG_PECNT       = 0x030D,
   ECT_REG_PECODE      = 0x030E,
   ECT_REG_LLCNT       = 0x0310,
   ECT_REG_WDCNT       = 0x0442,
   ECT_REG_EEPCFG      = 0x0500,
   ECT_REG_EEPCTL      = 0x0502,
   ECT_REG_EEPSTAT     = 0x0502,
   ECT_REG_EEPADR      = 0x0504,
   ECT_REG_EEPDAT      = 0x0508,
   ECT_REG_FMMU0       = 0x0600,
   ECT_REG_FMMU1       = ECT_REG_FMMU0 + 0x10,
   ECT_REG_FMMU2       = ECT_REG_FMMU1 + 0x10,
   ECT_REG_FMMU3       = ECT_REG_FMMU2 + 0x10,
   ECT_REG_SM0         = 0x0800,
   ECT_REG_SM1         = ECT_REG_SM0 + 0x08,
   ECT_REG_SM2         = ECT_REG_SM1 + 0x08,
   ECT_REG_SM3         = ECT_REG_SM2 + 0x08,
   ECT_REG_SM0STAT     = ECT_REG_SM0 + 0x05,
   ECT_REG_SM1STAT     = ECT_REG_SM1 + 0x05,
   ECT_REG_SM1ACT      = ECT_REG_SM1 + 0x06,
   ECT_REG_SM1CONTR    = ECT_REG_SM1 + 0x07,
   ECT_REG_DCTIME0     = 0x0900,
   ECT_REG_DCTIME1     = 0x0904,
   ECT_REG_DCTIME2     = 0x0908,
   ECT_REG_DCTIME3     = 0x090C,
   ECT_REG_DCSYSTIME   = 0x0910,
   ECT_REG_DCSOF       = 0x0918,
   ECT_REG_DCSYSOFFSET = 0x0920,
   ECT_REG_DCSYSDELAY  = 0x0928,
   ECT_REG_DCSYSDIFF   = 0x092C,
   ECT_REG_DCSPEEDCNT  = 0x0930,
   ECT_REG_DCTIMEFILT  = 0x0934,
   ECT_REG_DCCUC       = 0x0980,
   ECT_REG_DCSYNCACT   = 0x0981,
   ECT_REG_DCSTART0    = 0x0990,
   ECT_REG_DCCYCLE0    = 0x09A0,
   ECT_REG_DCCYCLE1    = 0x09A4
};

/** standard SDO Sync Manager Communication Type 标准SDO同步管理通讯地址0X1COO*/
#define ECT_SDO_SMCOMMTYPE      0x1c00

/** standard SDO PDO assignment 标准SDO分配PDO对象*/
#define ECT_SDO_PDOASSIGN       0x1c10

/** standard SDO RxPDO assignment 标准SDO配置RxPDO队列*/
#define ECT_SDO_RXPDOASSIGN     0x1c12

/** standard SDO TxPDO assignment 标准SDO配置TxPDO队列*/
#define ECT_SDO_TXPDOASSIGN     0x1c13

/** Ethercat packet type Ethercat数据包类型*/
#define ETH_P_ECAT              0x88A4

/** Error types 错误类型*/
typedef enum
{
   EC_ERR_TYPE_SDO_ERROR        = 0,
   EC_ERR_TYPE_EMERGENCY        = 1,
   EC_ERR_TYPE_PACKET_ERROR     = 3,
   EC_ERR_TYPE_SDOINFO_ERROR    = 4,
   EC_ERR_TYPE_FOE_ERROR        = 5,
   EC_ERR_TYPE_FOE_BUF2SMALL    = 6,
   EC_ERR_TYPE_FOE_PACKETNUMBER = 7,
   EC_ERR_TYPE_SOE_ERROR        = 8,
   EC_ERR_TYPE_MBX_ERROR        = 9
} ec_err_type;

/** Struct to retrieve errors. 记录错误结构体*/
typedef struct
{
   /** Time at which the error was generated. 错误发生时间*/
   ec_timet Time;
   /** Signal bit, error set but not read 报警发生信号*/
   boolean     Signal;
   /** Slave number that generated the error 发生错误的从站节点*/
   uint16      Slave;
   /** CoE SDO index that generated the error 发生错误的COE地址*/
   uint16      Index;
   /** CoE SDO subindex that generated the error 发生错误的COE子地址*/
   uint8       SubIdx;
   /** Type of error 发生错误类型*/
   ec_err_type Etype;
   union
   {
      /** General abortcode 错误终止码*/
      int32   AbortCode;
      /** Specific error for Emergency mailbox 紧急时间指定错误码*/
      struct
      {
         uint16  ErrorCode;
         uint8   ErrorReg;
         uint8   b1;
         uint16  w1;
         uint16  w2;
      };
   };
} ec_errort;

/** Helper macros 常用元操作宏*/
/** Macro to make a word from 2 bytes 两字节组装word宏*/
#define MK_WORD(msb, lsb)   ((((uint16)(msb))<<8) | (lsb))

/** Macro to get hi byte of a word 取高字节位宏 (((w) >> 8) & 0x00ff ) */
#define HI_BYTE(w)          ((w) >> 8)

/** Macro to get low byte of a word 取低字节宏*/
#define LO_BYTE(w)          ((w) & 0x00ff)

/** Macro to swap hi and low byte of a word 高低字节交换宏*/
#define SWAP(w)             ((((w)& 0xff00) >> 8) | (((w) & 0x00ff) << 8))

/** Macro to get hi word of a dword 取低字宏*/
#define LO_WORD(l)          ((l) & 0xffff)

/** Macro to get hi word of a dword 取高字宏*/
#define HI_WORD(l)          ((l) >> 16)

/** 内存地址对齐宏*/
#define get_unaligned(ptr) \
  ({ __typeof__(*(ptr)) __tmp; memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })

#define put_unaligned32(val, ptr)        \
  (memcpy((ptr), &(val), 4))

#define put_unaligned64(val, ptr)        \
  (memcpy((ptr), &(val), 8))

/** 大小端转换操作宏*/
#if !defined(EC_BIG_ENDIAN) && defined(EC_LITTLE_ENDIAN)

  #define htoes(A) (A)
  #define htoel(A) (A)
  #define htoell(A) (A)
  #define etohs(A) (A)
  #define etohl(A) (A)
  #define etohll(A) (A)

#elif !defined(EC_LITTLE_ENDIAN) && defined(EC_BIG_ENDIAN)

  #define htoes(A) ((((uint16)(A) & 0xff00) >> 8) | \
                    (((uint16)(A) & 0x00ff) << 8))
  #define htoel(A) ((((uint32)(A) & 0xff000000) >> 24) | \
                    (((uint32)(A) & 0x00ff0000) >> 8)  | \
                    (((uint32)(A) & 0x0000ff00) << 8)  | \
                    (((uint32)(A) & 0x000000ff) << 24))
  #define htoell(A) ((((uint64)(A) & (uint64)0xff00000000000000ULL) >> 56) | \
                     (((uint64)(A) & (uint64)0x00ff000000000000ULL) >> 40) | \
                     (((uint64)(A) & (uint64)0x0000ff0000000000ULL) >> 24) | \
                     (((uint64)(A) & (uint64)0x000000ff00000000ULL) >> 8)  | \
                     (((uint64)(A) & (uint64)0x00000000ff000000ULL) << 8)  | \
                     (((uint64)(A) & (uint64)0x0000000000ff0000ULL) << 24) | \
                     (((uint64)(A) & (uint64)0x000000000000ff00ULL) << 40) | \
                     (((uint64)(A) & (uint64)0x00000000000000ffULL) << 56))

  #define etohs  htoes
  #define etohl  htoel
  #define etohll htoell

#else

  #error "Must define one of EC_BIG_ENDIAN or EC_LITTLE_ENDIAN"

#endif

#ifdef __cplusplus
}
#endif

#endif /* _EC_TYPE_H */

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值