image.png


  1. TX 링버퍼 전역 변수들
#define TX_BUF_SZ 512
static uint8_t tx_buf[TX_BUF_SZ];
static volatile uint16_t tx_head = 0;
static volatile uint16_t tx_tail = 0;
static volatile uint8_t tx_busy = 0;
static volatile uint32_t tx_ovf = 0;

static uint8_t tx_it_byte;
  1. tx_rb_push() : 링버퍼에 1바이트 넣기
static void tx_rb_push(uint8_t b){
    uint16_t next = (uint16_t)((tx_head + 1) % TX_BUF_SZ);
    if(next == tx_tail) { tx_ovf++; return; }
    tx_buf[tx_head] = b;
    tx_head = next;
}
  1. tx_rb_pop() : 링버퍼에서 1바이트 빼기
static int tx_rb_pop(uint8_t *out){
    if(tx_tail == tx_head) return 0;
    *out = tx_buf[tx_tail];
    tx_tail = (uint16_t)((tx_tail + 1) % TX_BUF_SZ);
    return 1;
}