stm32之C语言问题求解~~~

2019-03-23 15:20发布

这是野火stm32之USB DEVICE章节的源程序,小弟初学,很多不懂,恳请大神指教~~~
uint8_t        EPindex;
DEVICE_INFO *pInformation;
DEVICE_PROP *pProperty;
uint16_t        SaveState ;
uint16_t  wInterrupt_Mask;
DEVICE_INFO        Device_Info;
USER_STANDARD_REQUESTS  *pUser_Standard_Requests;

void USB_Init(void)
{
  pInformation = &Device_Info;
  pInformation->ControlState = 2;
  pProperty = &Device_Property;//pProperty是定义的DEVICE_PROP类型结构体指针,而Device_Property是DEVICE_PROP类型的结构体
  pUser_Standard_Requests = &User_Standard_Requests;
  /* Initialize devices one by one */
  pProperty->Init();//将pProperty指针指向该结构体的首地址
}                            //问题1:请问大神:这里把函数指针赋值给函数,是把指针MASS_Init传递给函数void(*Init)(void),我这样理解正确吗?
                              //问题2:那接下来,还会把MASS_RESET赋值给void(*Reset)(void)吗?也就是说,它是会执行完整个_DEVICE_PROP结构体中的所有成员吗?为什么啊?


typedef struct _DEVICE_PROP
{
  void (*Init)(void);       //函数指针是指向函数的指针变量,它的本质就是一个指针
  void (*Reset)(void);       /* Reset routine of this device */

  /* Device dependent process after the status stage */
  void (*Process_Status_IN)(void);
  void (*Process_Status_OUT)(void);

  /* Procedure of process on setup stage of a class specified request with data stage */
  /* All class specified requests with data stage are processed in Class_Data_Setup
   Class_Data_Setup()
    responses to check all special requests and fills ENDPOINT_INFO
    according to the request
    If IN tokens are expected, then wLength & wOffset will be filled
    with the total transferring bytes and the starting position
    If OUT tokens are expected, then rLength & rOffset will be filled
    with the total expected bytes and the starting position in the buffer

    If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT

   CAUTION:
    Since GET_CONFIGURATION & GET_INTERFACE are highly related to
    the individual classes, they will be checked and processed here.
  */
  RESULT (*Class_Data_Setup)(uint8_t RequestNo);

  /* Procedure of process on setup stage of a class specified request without data stage */
  /* All class specified requests without data stage are processed in Class_NoData_Setup
   Class_NoData_Setup
    responses to check all special requests and perform the request

   CAUTION:
    Since SET_CONFIGURATION & SET_INTERFACE are highly related to
    the individual classes, they will be checked and processed here.
  */
  RESULT (*Class_NoData_Setup)(uint8_t RequestNo);

  /*Class_Get_Interface_Setting
   This function is used by the file usb_core.c to test if the selected Interface
   and Alternate Setting (uint8_t Interface, uint8_t AlternateSetting) are supported by
   the application.
   This function is writing by user. It should return "SUCCESS" if the Interface
   and Alternate Setting are supported by the application or "UNSUPPORT" if they
   are not supported. */

  RESULT  (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);

  uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
  uint8_t* (*GetConfigDescriptor)(uint16_t Length);
  uint8_t* (*GetStringDescriptor)(uint16_t Length);

  /* This field is not used in current library version. It is kept only for
   compatibility with previous versions */
  void* RxEP_buffer;

  uint8_t MaxPacketSize;

}DEVICE_PROP;

DEVICE_PROP Device_Property =
  {
    MASS_init,
    MASS_Reset,
    MASS_Status_In,
    MASS_Status_Out,
    MASS_Data_Setup,
    MASS_NoData_Setup,
    MASS_Get_Interface_Setting,
    MASS_GetDeviceDescriptor,
    MASS_GetConfigDescriptor,
    MASS_GetStringDescriptor,
    0,
           0x40 /*MAX PACKET SIZE*/
  };


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。