如何使用枚举类型来分配寄存器

时间:2012-08-06 03:25:27

标签: c

我无法理解下面代码的目的。当我读取octeon的sdk时,用于分配寄存器的枚举类型如何?我怎样才能使用cvmx_fau_reg_64_t?

/*************************  FAU allocation ********************************/
/* The fetch and add registers are allocated here.  They are arranged
    in order of descending size so that all alignment constraints are
    automatically met.
    The enums are linked so that the following enum continues allocating
    where the previous one left off, so the numbering within each
    enum always starts with zero.  The macros take care of the address
    increment size, so the values entered always increase by 1.
    FAU registers are accessed with byte addresses. */

#define CVMX_FAU_REG_64_ADDR(x) ((x <<3) + CVMX_FAU_REG_64_START)
typedef enum
{
    CVMX_FAU_REG_64_START          = 0, 
    CVMX_FAU_REG_64_END            = CVMX_FAU_REG_64_ADDR(0),
} cvmx_fau_reg_64_t;

#define CVMX_FAU_REG_32_ADDR(x) ((x <<2) + CVMX_FAU_REG_32_START)
typedef enum
{
    CVMX_FAU_REG_32_START          = CVMX_FAU_REG_64_END,
    CVMX_FAU_REG_32_END            = CVMX_FAU_REG_32_ADDR(0),
} cvmx_fau_reg_32_t;

#define CVMX_FAU_REG_16_ADDR(x) ((x <<1) + CVMX_FAU_REG_16_START)
typedef enum
{
    CVMX_FAU_REG_16_START          = CVMX_FAU_REG_32_END,
    CVMX_FAU_REG_16_END            = CVMX_FAU_REG_16_ADDR(0),
} cvmx_fau_reg_16_t;

#define CVMX_FAU_REG_8_ADDR(x) ((x) + CVMX_FAU_REG_8_START)
typedef enum {
    CVMX_FAU_REG_8_START           = CVMX_FAU_REG_16_END,
    CVMX_FAU_REG_8_END             = CVMX_FAU_REG_8_ADDR(0),
} cvmx_fau_reg_8_t;

/* The name CVMX_FAU_REG_AVAIL_BASE is provided to indicate the first available
   FAU address that is not allocated in cvmx-config.h. This is 64 bit aligned. */
#define CVMX_FAU_REG_AVAIL_BASE ((CVMX_FAU_REG_8_END + 0x7) & (~0x7ULL))
#define CVMX_FAU_REG_END (2048)

2 个答案:

答案 0 :(得分:0)

在C中,枚举类型与有符号整数数据类型类似。这是你应该如何使用cvmx_fau_reg_64_t

cvmx_fau_reg_64_t myRegister;

myRegister=CVMX_FAU_REG_64_START;

//Do something with the *myRegister* variable

myRegister=CVMX_FAU_REG_64_END;

答案 1 :(得分:0)

Cavium OCTEON FAU寄存器实际上受到一系列特殊存储器的支持,这些存储器被强制为Atomic,通过标签操作并通过IOBDMA进行访问。

因此,您只需指定注册号和尺寸。您应该使用cvmx-fau API,如cvmx_fau_fetch_and_add64(fau_reg_64_t reg,value)或类似的Add,Increment。 OCTEON架构将使用标签操作和IOBDMA总线保证所有读/写都是 Atomic

您的代码应该只选择并引用特定的FAU索引,并决定将它们用于64/32/16/8位值/计数器。其余的都是通过SDK提供的FAU功能

cvmx-config可以为您定义最初的几个,然后您可以在代码中添加更多(如果需要)。这些将在FAU_AVAIL_BASE之后。

在任何时候都不应该直接定义/操作/取消重新定位这些内存位置。这些不像正常的64/32位变量或指针。

Paxym

相关问题