AnsweredAssumed Answered

generate callback function

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

Hello friends.

 

I have uart. And I need generate callback function.

 

For example. I send from PC 0x01 and I need generate call back function "HelloWorld". Send 0x02 generate "SunShine".

 

So I receive char in interrupt:

void UART4_IRQHandler(void)
{

   if (LL_USART_IsActiveFlag_RTO(UART4))
   {
      LL_USART_ClearFlag_RTO(UART4); 

      UART_generate_call_back(dma_rx_buff);

      /* here clear flags, .........*/

   }

}

 

/* here is my definitions */

#define    FIRST_CALL         0x01

#define    SECOND_CALL    0x02

 

function generate call back:

void UART_generate_call_back(uint8_t *input_buffer)
{
   if(input_buffer[0] == 0x01)
      UART_HandlerTable(FIRST_CALL);
   if(input_buffer[0] == 0x02)
      UART_HandlerTable(SECOND_CALL);

}

 

and my function to generate callback:

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

 

 

other function and declaration:

typedef void (*InterruptHandler) (uint32_t uart_interrupt);
InterruptHandler UART_HandlerTable;

 

And in my main:

void HelloWorld();

void SunShine();

 

int main(void)
{
   /* init system clock */
   SystemClock_Config();
   /* Init UART5 and DMA1 */
   MX_UART4_Init();
   /* Init LED */
   InitLed();

 

   UART_callback( FIRST_CALL, (InterruptHandler)HelloWorld);

   UART_callback( SECOND_CALL, (InterruptHandler)SunShine);

 

   while (1)
   {

      LL_mDelay(1);

      time++;
      if(time == 500)
      {
         LL_GPIO_TogglePin(MCU_LED_PORT, MCU_LED_PIN);
         time = 0;
      }
}

 

void HelloWorld()
{
   usart_puts("Hello world\r\n");
}

 

void SunShine()

{

   usart_puts("Sunshine\r\n");

}

 

And when I send 0x01 by UART callback function isn't working.

 

Any idea, what is wrong?

Outcomes