AnsweredAssumed Answered

Callback function with parameter?

Question asked by Pilous Droip on Mar 20, 2018
Latest reply on Mar 20, 2018 by Pilous Droip

Hello friends.

 

I create callback function for uart:

typedef void (*InterruptHandler) (uint32_t uart_interrupt);
   InterruptHandler UART_HandlerTable[MaxInterrupt];

   extern void UART_callback(uint32_t InterruptID, InterruptHandler Handler);

 

And callback function:

void UART_callback(uint32_t InterruptID, InterruptHandler Handler)
{
   UART_HandlerTable[InterruptID] = Handler;
}

 

And when I receive data from uart I generate callback function:

void UART_generate_call_back(uint8_t *input_buffer)
{
   UART_HandlerTable[input_buffer[0]](input_buffer[0]);

}

 

And in main I use this:

void callback_HELLO();

 

int main(void)
{

UART_callback( 0x01, (InterruptHandler)callback_HELLO );

 

   while (1)
   {

   }

}

 

void callback_HELLO()
{
   usart_puts("\r\nHello world\r\n");
}

 

Now, it is working very good. 

 

But how to add parameter to callback function?

 

For example. I receive message, this message I analyze and I need hand over some data.

 

So I need modificate this function to return *data to callback.

void UART_generate_call_back(uint8_t *input_buffer, uint8_t *data)
{
   UART_HandlerTable[input_buffer[0]](input_buffer[0]);

}

 

 

So how to get data to callback function? And in main I would like get data.

void callback_HELLO(uint8_t *data)
{

       /* do something with data */
   usart_puts("\r\nHello world\r\n");
}

 

Is it posible?

Outcomes