I have developed a small library called dataframe that takes in a buffer, and encodes it for uart communication. The output of dataframe is passed to the input of the uart tx function. I developed dataframe as its own mini static library so it can be unit tested, so I defined a callback function as its output interface.
My issue is I am currently hooking dataframe's output to the uart tx handler during runtime through the use of a function pointer, called DF_write_cb as shown below:
void main(...){
DF_set_write_callback(Uart_Tx_String, NULL);
...
}
void DF_apply_frame(uint8_t* buff, size_t len)
{
uint16_t calc_fletcher = fletcher16(buff, len);
buff[len] = (calc_fletcher>>0) & 0xFF;
buff[len+1] = (calc_fletcher>>8) & 0xFF;
len+=2;
uint8_t s=DF_START_BYTE;
DF_write_cb(&s, 1);
DF_escape_frame(buff, len);
s=DF_STOP_BYTE;
DF_write_cb(&s, 1);
}
DF_write_cb points to:
bool OPTIMIZE(O3) Uart_Tx_String(uint8_t* string, size_t string_size)
{
if(string == NULL || string_size <= 0)
{
return true;
}
...
...
}
Is there a better way to handle this? I have the knowledge of what function I want dataframe to hand off its processed bytes to at compile time, certainly at link time.
Really, I am searching for a way to tell gcc that "DF_write_cb()" is really "Uart_Tx_String()". I'd like to avoid #define if possible. Is there any configuration methods I am unaware of that would let the compiler or linker substitute "DF_write_cb" with "Uart_Tx_String"? I've seen a few references to static inline but I'm unfamiliar how to set this up.