Picproje Elektronik Sitesi

MİKRODENETLEYİCİLER => ARM => Konuyu başlatan: salih18200 - 23 Mayıs 2015, 17:16:01

Başlık: C veya C++ sorusu
Gönderen: salih18200 - 23 Mayıs 2015, 17:16:01
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ı?
Başlık: Ynt: C veya C++ sorusu
Gönderen: yldzelektronik - 23 Mayıs 2015, 17:31:16
Property belli ki bir striptiz işaret eden pointer. Ve pointer strutt elemanlarına . İle değil de -> ile erişilir.
Başlık: Ynt: C veya C++ sorusu
Gönderen: JKramer - 23 Mayıs 2015, 17:39:23
Function pointer diye bakabilirsiniz.
Başlık: Ynt: C veya C++ sorusu
Gönderen: CLR - 23 Mayıs 2015, 17:41:11
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

Başlık: Ynt: C veya C++ sorusu
Gönderen: salih18200 - 23 Mayıs 2015, 18:08:06


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.
Başlık: Ynt: C veya C++ sorusu
Gönderen: CLR - 23 Mayıs 2015, 18:39:52
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. 
Başlık: Ynt: C veya C++ sorusu
Gönderen: salih18200 - 23 Mayıs 2015, 18:46:11
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*/
  };