Display_Avr_3/hdlc/hdlc.c
2023-05-08 14:47:51 +03:00

60 lines
1.7 KiB
C

#include "hdlc.h"
#include <string.h>
#include "setup.h"
__weak void uart_putchar(char ch)
{
// implement function to send character via UART
}
static hdlc_t hdlc;
// Static buffer allocations
static uint8_t _hdlc_rx_frame[HDLC_MRU]; // rx frame buffer allocation
static uint8_t _hdlc_tx_frame[HDLC_MRU]; // tx frame buffer allocation
static uint8_t _hdlc_payload[HDLC_MRU]; // payload buffer allocation
/** Приватная функция для отправки байтов по uart */
static void hdlc_tx_byte(uint8_t byte)
{
uart_putchar((char)byte);
}
/* инициализация конечного автомата HDLC, указателей буфера и переменных состояния */
void hdlc_init(void)
{
hdlc.rx_frame_index = 0;
hdlc.rx_frame_fcs = HDLC_CRC_INIT_VAL;
hdlc.p_rx_frame = _hdlc_rx_frame;
memset(hdlc.p_rx_frame, 0, HDLC_MRU);
hdlc.p_tx_frame = _hdlc_tx_frame;
memset(hdlc.p_tx_frame, 0, HDLC_MRU);
hdlc.p_payload = _hdlc_payload;
memset(hdlc.p_payload, 0, HDLC_MRU);
hdlc.state = HDLC_SOF_WAIT;
hdlc.own_addr = SETUP_OWNADDRESS;
}
//Эта функция должна вызываться при получении нового символа через UART
static void hdlc_esc_tx_byte(uint8_t byte)
{
if((byte == HDLC_CONTROL_ESCAPE) || (byte == HDLC_FLAG_SOF))
{
hdlc_tx_byte(HDLC_CONTROL_ESCAPE);
byte ^= HDLC_ESCAPE_BIT;
hdlc_tx_byte(byte);
}
else
hdlc_tx_byte(byte);
}
void hdlc_process_rx_frame(uint8_t *buf, uint16_t len){
return;
}
void hdlc_tx_frame(const uint8_t *txbuffer, uint8_t len){
return;
}