I am setting up an UART protocol that allows the communication between 2 boards; A Master board and a Slave board. The communication between them is going to be like this:
Example 1 :
Master [Tx] -- GET_VALUE--> [Rx] Slave
Master [Rx] <-- 0x05 -------- [Tx] Slave
Example 2:
Master [Tx] -- GET_STATUS -----------> [Rx] Slave
Master [Rx] <-- I_AM_BUSY ------------ [Tx] Slave
Example 3:
Master [Tx] -- START_OPERATION --> [Rx] Slave
Master [Rx] <----------ACK------------[Tx] Slave
Data size is 1 Byte for most of data flow between the two card. That's why I am going to use macros to define these commands:
Example:
#define GET_VALUE 0x05
#define START_OPERATION 0x06
etc ...
In addition to these 1-Byte-data, There is only one element that should be transmitted between the two boards that it's size is not 1 Byte. In fact, I am willing to use serialization to transmit a data structure over UART using a circular FIFO buffer
Example:
Master [Tx] -- GET_STRUCTURE ------------> [Rx] Slave
Master [Rx] <----------STRUCTURE------------[Tx] Slave
typedef struct{
uint8_t var1;
uint8_t var2;
uint8_t var3;
}MyStructTypeDef;
Shall be transmitted over UART in this format "variable_name:valueXXX":
var1:123XXXvar2:456XXXvar3:789XXX
XXX is a separator
My question is: If 99% of data flow is 1 Byte sized and only 1% of the data flow is not 1 Byte sized, Should I use circular buffer only to get the structure? Is there a better way to standardize the length of data passed over uart?