/*
 * kline_ring.h
 * Lock-free single-producer (ISR) / single-consumer (FSM) ring buffer
 * for UART1 K-Line RX bytes.
 */

#ifndef INC_KLINE_RING_H_
#define INC_KLINE_RING_H_

#include <stdint.h>

#define KLINE_RING_SIZE 64u          /* Must be power of 2 */
#define KLINE_RING_MASK (KLINE_RING_SIZE - 1u)

/* Call once after HAL_UART_Init to start receiving */
void     KLine_Ring_Init(void);

/* Called ONLY from UART1 RxCplt ISR callback */
void     KLine_Ring_ISR_PushByte(uint8_t b);

/* Called from FSM / main context */
uint8_t  KLine_Ring_Available(void);   /* non-zero if at least one byte ready  */
uint8_t  KLine_Ring_Pop(void);         /* pop oldest byte; undefined if empty   */
void     KLine_Ring_Flush(void);       /* discard all pending bytes             */

/* Raw RX staging byte – huart1 DMA/IT target, touched only by HAL + ISR */
extern volatile uint8_t kline_rx_staging;

#endif /* INC_KLINE_RING_H_ */
