onlinedokumentation

Callbacks

You can define your own functions which can be called from the Kithara driver e.g. when a hardware interrupt is fired. Therefore you register your function as a callback function.

  • Define your Callback-Function:

Error __stdcall callBack(void* pArgs, void* pContext);

As the first parameter always a pointer to user defined data is passed. The second one points to a context structure which depends on the context from which the callback was called e.g. it is a timer callback. You can immediately cast both arguments to the appropriate type.

// User defined data structure
struct CallbackData {   
  uint counter_;
  Handle hEvent_;
};

// User defined callback function
Error _stdcall MyOwnCallBack(void* pArgs, void* pContext) {      

  // Cast the argument
  CallbackData* pData = (CallbackData*)pArgs;                    

  // e.g. the function was called from a timer, 
  // pContext represents a TimerUserContext structure
  TimerUserContext* pTimerContext = (TimerUserContext*)pContext; 
}

  • Create a callback handle with KS_createCallBack

Handle hCallBack;
Error ksError;
ksError = KS_createCallBack(
              &hCallBack,                     // Address of callback handle
              callBack,                       // Callback function
              pArgPtr,                        // Reference parameter to the callback
              KSF_USER_EXEC,                  // Flags, here in application context
              0);                             // Priority value not used

  • The handle hCallBack is for further usage with the Kithara software

If the callback is not needed anymore don't forget to remove it by calling:

ksError = KS_removeCallBack(hCallBack);

Events

In multithreading applications you can't avoid using synchronizing mechanisms like events. The Kithara driver uses special events which also can be set from kernel level.

  • Creating an event is very easy by calling KS_createEvent

// C/C++
Handle hEvent;
ksError = KS_createEvent(
              &hEvent,           // Address of event handle
              "MyEvent",         // Name of event
              0);                // Flags, here 0

  • The handle hEvent represents the event and is for further usage with the Kithara driver
  • To change the status of the event you can use
  1. KS_setEvent
  2. KS_resetEvent
  3. KS_pulseEvent
  • These function can even be called from kernel level.
  • To wait for an event and block a thread you can use KS_waitForEvent:

// C/C++
ksError = KS_waitForEvent(
              hEvent,            // Event handle
              0,                 // Flags
              1000 * ms);        // Time-out value, in 100-ns-units

  • Don't forget to close an event by calling KS_closeEvent