Breaking out of usart_read_buffer_job()

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All, 

 

I've got an application running on a  ATSAML21J8B that gets input from the uart in 6 byte chunks and then returns an ack or nack packet.  This works great for the most part if they sending system does what it's supposed to do.  However there are situations that can arise that cause issues.  For instance, if the sender mistakenly sends an invalid 7 byte packet followed by 2 valid 6 byte packets my application will (correctly) resond with 3 nacks and then be in a situation where it has one leftover byte in it's receive buffer.  

 

Any further valid packets sent will always cause a nack and an extraneous byte in the buffer.  My application will then be sitting in the usart_read_buffer_job().  I'd like to use an external interrupt to somehow recover from this error condition, essentially clearing my receive buffer and breaking out of the usart_read_buffer_job() function.  Conceptually, I'm not sure how to approach this problem.  I have a slash and burn solution which is to just reset the processor, but I'd like to avoid this if possible as there is data in the application I'd like to retain after recovering from this condition.  Any thoughts would be appreciated.  Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not get a byte at a time then? Surely the receive is using a FIFO interrupt anyway?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried this, and ran in to the same problem.  The ultimate solution was to disable the receiver in the usart_module data structure and set the remaining_rx_buffer_length field to 0 in my ISR.  This seems to cause it to break out of the functions that were holding me up, the first thing I do after is re-enable the receiver, and every thing seems to work as expected from there.