Search code examples
device-driverioctl

(Linux Style) Ioctl code, Hard to understand


I'm using infini** chip.

In their Basic Code, every [XXX_ioctl].c code It has below code at upper parts.
(XXX means the driver I want to use. )

typedef void (*PFUNCTION)(void); 

#define FUNCTION_COUNT 5

struct IoctlInterface {
    uint8_t count;
    PFUNCTION functionArray[FUNCTION_COUNT]; //function pointer array
} __STATIC const XxxInterface = {
    FUNCTION_COUNT,
    {
        (PFUNCTION) IFX_XXX_Open,
        (PFUNCTION) IFX_XXX_Close,
        (PFUNCTION) IFX_XXX_Ioctl,
        (PFUNCTION) IFX_XXX_CancleIO,
        (PFUNCTION) IFX_XXX_DriverInit,
    }
};

I know that struct IoctlInterface has member array[5], which return type is function pointer. But, what is the following means?

__STATIC const XxxInterface = {
FUNCTION_COUNT,
{
    (PFUNCTION) IFX_XXX_Open,
    (PFUNCTION) IFX_XXX_Close,
    (PFUNCTION) IFX_XXX_Ioctl,
    (PFUNCTION) IFX_XXX_CancleIO,
    (PFUNCTION) IFX_XXX_DriverInit,
}
};

Thanks ahead.

※ If this post violates the technical secrets of the chip, I will delete it immediately.


Solution

  • I think you probably need to read up a little bit more about C. However, in this part you are simply declaring a (probably) global (probably) static variable called XxxInterface of type IoctlInterface and filling in the members of the struct.

    __STATIC const XxxInterface = {
    FUNCTION_COUNT,
    {
        (PFUNCTION) IFX_XXX_Open,
        (PFUNCTION) IFX_XXX_Close,
        (PFUNCTION) IFX_XXX_Ioctl,
        (PFUNCTION) IFX_XXX_CancleIO,
        (PFUNCTION) IFX_XXX_DriverInit,
    }
    };