I'm implementing a small Zigbee library for Atmel's XMEGA devices. The Zigbee radio communicates with the MCU using the internal USART.
When I started writing the library I was using the simple approach of a fixed array along with interrupts for received data. Once I had the complete command (I know I have a complete command because the Zigbee states the frame length - minus the starting delimiter and checksum at the end), I set a flag in the interrupt service routine and copied the array into another array in my main().
Once I had the array copied, another routine ZBProcessFrame takes over and parses the frame and takes appropriate action.
The potential issue with this approach is that while I'm copying the array another message could come and change this shared variable.
By reading online, it seems I can either switch off my interrupts while copying the array or I should use a circular buffer, as then I can avoid copying the array entirely. I've successfully implemented a 32 byte circular buffer but now my issue is, how do I tell where the actual data began and how many bytes have come since the starting delimiter. My ISR only has the following:
ISR(Receiver Interrupt)
{
ring->add(USART_Data);
}
Should I check for the starting delimiter here and set a flag incase there's a valid command here? The main() can then look at the flag continuously and if raised, it implies there's a valid command present.
Is this a valid approach or should I look for an alternative?