2018-03-20 05:03 AM
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?
#callback2018-03-20 06:34 AM
>>Is it possible?
Sure, the way you have the call defined at the moment it expects a 32-bit parameter.
If you want the data in the array with the callback, you'd likely want to use a structure, and array that.
Think you want
void
callback_HELLO
(uint8_t data)rather than the pointer.
2018-03-20 08:26 AM
I call this function, when I receive data on uart.
void UART_generate_call_back(uint8_t *input_buffer)
{
UART_HandlerTable[input_buffer[0]](input_buffer[0]);
}
I have uart data in input_buffer. And this datas I would like to send by parameter to callback function.
So how to modificate this function, to send array data as parameter?
UART_HandlerTable[input_buffer[0]](input_buffer[0]);
And here I would like to work with send datas.
void
callback_HELLO
(uint8_t *data){
/* do something with data */
usart_puts('\r\nHello world\r\n');
}
2018-03-20 09:00 AM
It is currently sending the first character in the buffer, if you want it to send the pointer, then do that instead
typedef void (*InterruptHandler)(uint8_t *data);
..
UART_HandlerTable[input_buffer[0]](input_buffer); // Send the pointer
..
void
callback_HELLO
(uint8_t *data)typedef void (*InterruptHandler) (uint8_t data);
..
UART_HandlerTable[input_buffer[0]](input_buffer[0]); // Send the char
..
void
callback_HELLO
(uint8_t data)2018-03-20 09:23 AM
Of course. I will try it tomorrow. It's look like very good.
:(
Thank you.