Atmel START project -- receiving in async USART, without warnings

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have defined an async USART and I am using it successfully.

However, I have a warning in the receive callback function.

 

Here is an example of my problem, using the USART as an echo.

void rx_cb_USART_DBG(const struct usart_async_descriptor *const io_descriptor){
    
    if(usart_async_is_rx_not_empty(io_descriptor)){
        uint8_t ch;
        //echo.  a way to see that the board is alive
        io_read(&io_descriptor->io,&ch,1);
        
        io_write(&io_descriptor->io,&ch,1); // echo
    }
}

 

This gives a warning on both the io_read and the io_write, 

Warning        passing argument 1 of 'io_read' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]   

 

 

If I use:

void rx_cb_USART_DBG(const struct usart_async_descriptor *const io_descriptor){
    
    if(usart_async_is_rx_not_empty(io_descriptor)){
        uint8_t ch;
        //echo.  a way to see that the board is alive
        io_read(io_descriptor,&ch,1);
        
        io_write(io_descriptor,&ch,1); // echo
    }
}

(which works because the 'io' member is the first member of the usart_async_descriptor), I get the warning:
Warning        passing argument 1 of 'io_read' from incompatible pointer type [-Wincompatible-pointer-types]

 

Now, I could directly read from the io descriptor of USART_DBG (global defined bythe generated code), retrieving it with usart_async_get_io_descriptor.  But, since the callback function receives the  usart_async_descriptor as a parameter it seems incorrect to then retrieve the character without using that (could technically retrieve the character from a different USART, even by mistake, when you know, from the parameter, where you received the message).

 

How should this be done?

 

Thank you.