cancel
Showing results for 
Search instead for 
Did you mean: 

USART Buffer: How can I set priorities?

jean
Senior
Posted on August 19, 2014 at 18:04

Hello everybody!

I coded a buffer for my USART output. This is how it looks like:

#define FIFO_BUFFER_SIZE 64
#define BUFFER_MASK (FIFO_BUFFER_SIZE-1)
typedef 
struct
FifoStruct
{
volatile uint8_t data[FIFO_BUFFER_SIZE];
volatile uint8_t read;
volatile uint8_t write;
} Fifo;
void
fifo_init(Fifo* fifo_selected)
{
memset((
void
*)fifo_selected -> data, 0, FIFO_BUFFER_SIZE);
fifo_selected -> read = 0;
fifo_selected -> write = 0;
}
// Add a byte into the selected fifo buffer
uint8_t fifo_bufferIn(Fifo* fifo_selected, uint8_t 
byte
)
{
uint8_t next = ((fifo_selected -> write+1) & BUFFER_MASK);
if
(fifo_selected -> read == next) 
return
0;
fifo_selected -> data[fifo_selected -> write] = 
byte
;
fifo_selected -> write = next;
return
1;
}

When I want to add a byte I do this:

static
Fifo Out_Fifo;
// To add a message in the fifo buffer
void
Send_Byte_USART_fifo(uint8_t data)
{
// put data in the output fifo in order to send it by USART as soon as the peripherial is free
fifo_bufferIn(&Out_Fifo, data);
// enable Transmit Data Register empty interrupt
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
}

My USART is quite slow and I want to add priorities to bytes, in order to send quickly important messages. Only two levels of priority is necessary for my application. Do you know how to achieve that? Thanks a lot!
2 REPLIES 2
Posted on August 19, 2014 at 18:46

Do you know how to achieve that?

Two FIFOs?

Message based buffering, messages queued in two lists.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jean
Senior
Posted on August 20, 2014 at 15:54

Thank you clive, I think this idea is working fine!