Driver with callback function

1.5k views Asked by At

I have been working on some embedded software. This software is divided into two main parts. The first one is the application software and the second one is some system software. The system software consists of set of drivers and RTOS. I have been developing the application part and I have been using the prepared drivers. Among the drivers there are also drivers for CAN communication. One of the functions has the following interface

result_t can_set_receive_callback (can_receive_callback_t cb);

Along with this function there is also following definition of pointer to function

typedef void (*can_receive_callback_t) (can_message_t msg);

I have problem to understand how to use the driver function. I know that I have to define some function with following interface

void my_function (can_message_t m);

I also know that the function defined above is so called callback function. But I don't know why I have to define the callback function.

Why is it not possible to simply call the driver function without no function pointer passed as an argument?

Does it mean that callback function defined by me "says" how to process the received messages? What is the information which is unknown for the drivers developer?

I meant that the receiving messages are processed by prepared interrupt service routines but none of the mentioned functions looks like an ISR.

Can anybody refer me to some good document where this type of work with drivers is described? Thanks a lot.

1

There are 1 answers

3
LPs On BEST ANSWER

OSI model speaking Drivers are supposed to manage the communication on the physical level.

So the driver perform communication device activation, configuration, read, write etc. to manage the HW to communicate on your bus (CAN).

Data link layer is responsible for managing the "protocol" of data sent and received on the bus.

So the driver developer require data link layer developer to set functions that will be called (callbacks) when a specific event is triggered by physyal layer.

In other words, in your specific case, you must set a callback that manage received data based on your protocol with its peculiarity (structure, timings, etc...)