zoukankan      html  css  js  c++  java
  • Python这样写C语言的结构体

    C语言版本

    typedef struct _VSI_FLASH_INIT_CONFIG
    {
        uint32_t	page_size;
        uint32_t	page_num;
        uint8_t	write_enable[8];
        uint8_t	read_status[8];
        uint8_t	chip_erase[8];
        uint8_t	write_data[8];
        uint8_t	read_data[8];
        uint8_t	first_cmd[8];
        uint8_t	busy_bit;
        uint8_t	busy_mask;
        uint8_t	addr_bytes;
        uint8_t	addr_shift;
        uint8_t	init_flag;
    }VSI_FLASH_INIT_CONFIG,*PVSI_FLASH_INIT_CONFIG;
    
    typedef struct _VSI_MW_INIT_CONFIG{
        int8_t   MW_START;
        int8_t   ORG;
        int32_t  SIZE;
        int8_t   MWIndex;		   
        int16_t  MWAddr;
        struct{
            int8_t EW_DISABLE;
            int8_t WRITE_ALL;
            int8_t ERASE_ALL;
            int8_t EW_ENABLE;
        }CC_CMD; //Control Codes
        struct{
            int8_t CONTROL;
            int8_t WRITE;
            int8_t READ;
            int8_t ERASE;
        }OP_CMD; //Operations
    }VSI_MW_INIT_CONFIG,*PVSI_MW_INIT_CONFIG;
    

    用Python写

    class VSI_FLASH_INIT_CONFIG(Structure):
        _fields_ = [("page_size", c_int),
                    ("page_num", c_int),
                    ("write_enable", c_ubyte*8),
                    ("read_status", c_ubyte*8),
                    ("chip_erase", c_ubyte*8),
                    ("write_data", c_ubyte*8),
                    ("read_data", c_ubyte*8),
                    ("first_cmd", c_ubyte*8),
                    ("busy_bit", c_ubyte),
                    ("busy_mask", c_ubyte),
                    ("addr_bytes", c_ubyte),
                    ("addr_shift", c_ubyte),
                    ("init_flag", c_ubyte)
                    ];
                    
    class VSI_MW_INIT_CONFIG(Structure):
        _fields_ = [("MW_START", c_ubyte),
                    ("ORG", c_ubyte),
                    ("SIZE", c_int),
                    ("MWIndex", c_ubyte),
                    ("MWAddr", c_ushort),
                    ];
        class CC_CMD(Structure):
            _fields_ = [("EW_DISABLE", c_ubyte),
                        ("WRITE_ALL", c_ubyte),
                        ("ERASE_ALL", c_ubyte),
                        ("EW_ENABLE", c_ubyte),
                        ];
        class OP_CMD(Structure):
            _fields_= [("CONTROL", c_ubyte),
                       ("WRITE", c_ubyte),
                       ("READ", c_ubyte),
                       ("ERASE", c_ubyte)
                       ];
    
    
  • 相关阅读:
    kubernetes的设计理念
    kubernetes整体架构
    kubernetes的起源
    云原生有未来吗?
    cloud native
    kata containers
    go特性
    开源在线分析诊断工具Arthas(阿尔萨斯)--总结
    javaAgent介绍
    oracle函数操作
  • 原文地址:https://www.cnblogs.com/tjhd/p/13947403.html
Copyright © 2011-2022 走看看