Haberler:

Foruma Resim Yükleme ve Boyut Sınırlaması ( ! )  https://bit.ly/2GMFb8H

Ana Menü

C veya C++ sorusu

Başlatan salih18200, 23 Mayıs 2015, 17:16:01

salih18200

Property->GetDeviceDescriptor;

uint8_t* (*GetDeviceDescriptor)(uint16_t Length);

void (*Process_Status_IN)(void);

Yukarıdaki tanımlamalar ve kullanımlar ne olarak geçiyor. Bilgi verebilecek olan var mı?

yldzelektronik

Property belli ki bir striptiz işaret eden pointer. Ve pointer strutt elemanlarına . İle değil de -> ile erişilir.
Kişinin başına gelen hayır Allah'tandır. Kişinin başına gelen şer nefsindendir. Nefislerimizle kendimize zulüm ediyoruz.

JKramer

Function pointer diye bakabilirsiniz.

CLR

1) void (*Process_Status_IN)(void);                                // "fonksiyon pointer"
2) uint8_t* (*GetDeviceDescriptor)(uint16_t Length);       // fonksiyon pointer ama geridönüşüde pointer
3) Property->GetDeviceDescriptor;                                // property adındaki bir pointer'in getdevicedescriptor adında bir fonksiyonu çağırıyor

Yani üçünü de tam olarak anlayabilmen için C'de aşağıdaki konuları bilmen gerekiyor
1) struct nedir nasıl tanımlanır
2) fonksiyon pointer nedir nasıl tanımlanır
3) struct içinde fonksiyon pointer nedir ve nasıl çağırılır

Knowledge and Experience are Power

salih18200

typedef struct _DEVICE_PROP
{
  void (*Init)(void);        /* Initialize the device */
  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);
	
	uint8_t* (*GetFiscalDescriptor)(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 *pProperty;


Yukarıda "DEVICE_PROP"  structer tanımlaması yapılmış ve buradan "*pProperty" türetilmiş.

Aşğıda ki şekildede bir kullanım var.
"pProperty->GetConfigDescriptor;"

"GetConfigDescriptor" bir fonksiyon ise ben bu fonksiyonun tanımlı olduğu yeri bir türlü bulamadım.

CLR

programın içinde bir yerlerde atamıştır. Ya doğrudan fonksiyonun kendisini struct içindeki fonksiyon pointer'a atamıştır veya yine fonksiyon pointer kullanıp, pointer'den pointere'e atamıştır. Yani dolaylı yoldan atamıştır. 
Knowledge and Experience are Power

salih18200

pProperty = &Device_Property;
Atandığı yeri buldum, aynı yöntemle aşağıya kendi özelleştirilmiş fonksiyonlarımı ekleyeceğim.

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*/
  };