7/11/2024

What is ctypesCallback.py in Efi/Apps /EfiPy2Sample/

 Background

At the beginning of porting ctypes to EFI environment, there are some validation programs. This is one of them to be used to test CFUNCTYPE if it works or not.

Test point

This script is mainly to declare a c types structure which is used for EFI protocol including member function pointer (EFIPY2_CFUNCTYPE1) and unsigned integer.

This statement is CFUNCTYPE check point.

Status = EfiPy2SampleProtocol.P1Func1 (20, None)

Procedure - python callback function by ctypes

1. Declaire python function (EfiPy2cFunc1 or EfiPy2cFunc2) for callback from ctypes.Structure object.

def EfiPy2cFunc1 (Val1, Val2):

  print ("   EfiPy2cFunc1 Val1:", Val1)

  return 0

2. Create EFIPY2_CFUNCTYPE1 from ctypes.CFUNCTYPE with the same with EfiPy2cFunc1 input/output interface.

EFIPY2_CFUNCTYPE1 = ctypes.CFUNCTYPE (

     ctypes.c_uint64,                 # Return value.

     ctypes.c_uint64,                 # first parameter.

     ctypes.POINTER(ctypes.c_uint32)  # second parameter.

     )

3. And assign an object P1 which is EFIPY2_CFUNCTYPE1 object has callback EfiPy2cFunc1.

P1 = EFIPY2_CFUNCTYPE1 (EfiPy2cFunc1)

Procedure - ctypes structure object with member EFIPY2_CFUNCTYPE1

1. This is ctypes structure EFIPY2_SAMPLEPROTOCOL_CLASS which can be used for EFI protocol
#
# Protocol Structure
#
class EFIPY2_SAMPLEPROTOCOL_CLASS (ctypes.Structure):
  _fields_ = [("P1Func1", EFIPY2_CFUNCTYPE1),
              ("P1Val",   ctypes.c_uint32),
              # ("P1Func2", EFIPY2_CFUNCTYPE2)
             ]
2. Create EFIPY2_SAMPLEPROTOCOL_CLASS's object
EfiPy2SampleProtocol = EFIPY2_SAMPLEPROTOCOL_CLASS (P1, 3)

Go for run

This is the content in previous section Test Point

Status = EfiPy2SampleProtocol.P1Func1 (20, None)

No comments:

Post a Comment