hdlc-interface #6
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
8
.idea/Display_Avr_3.iml
generated
Normal file
8
.idea/Display_Avr_3.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="CPP_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Display_Avr_3.iml" filepath="$PROJECT_DIR$/.idea/Display_Avr_3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
60
hdlc/hdlc.c
Normal file
60
hdlc/hdlc.c
Normal file
@ -0,0 +1,60 @@
|
||||
#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;
|
||||
}
|
43
hdlc/hdlc.h
Normal file
43
hdlc/hdlc.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef DISPLAY_AVR_3_HDLC_H
|
||||
#define DISPLAY_AVR_3_HDLC_H
|
||||
|
||||
#define HDLC_MRU 256
|
||||
// HDLC constants --- RFC 1662
|
||||
#define HDLC_FLAG_SOF 0x7e // Flag
|
||||
#define HDLC_CONTROL_ESCAPE 0x7d // Control Escape octet
|
||||
#define HDLC_ESCAPE_BIT 0x20 // Transparency modifier octet (XOR bit)
|
||||
#define HDLC_CRC_INIT_VAL 0xffff
|
||||
#define HDLC_CRC_MAGIC_VAL 0xf0b8
|
||||
#define HDLC_CRC_POLYNOMIAL 0x8408
|
||||
#define HDLC_UI_CMD 0x03 // Unnumbered Information with payload
|
||||
#define HDLC_FINAL_FLAG 0x10 // F flag
|
||||
#define HDLC_POLL_FLAG 0x10 // P flag
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HDLC_SOF_WAIT,
|
||||
HDLC_DATARX,
|
||||
HDLC_PROC_ESC,
|
||||
} hdlc_state_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t own_addr;
|
||||
uint8_t src_addr;
|
||||
uint8_t dest_addr;
|
||||
uint8_t ctrl;
|
||||
uint8_t *p_tx_frame; // tx frame buffer
|
||||
uint8_t *p_rx_frame; // rx frame buffer
|
||||
uint8_t *p_payload; // payload pointer
|
||||
uint16_t rx_frame_index;
|
||||
uint16_t rx_frame_fcs;
|
||||
hdlc_state_t state;
|
||||
} hdlc_t;
|
||||
|
||||
|
||||
void hdlc_init(void);
|
||||
|
||||
void hdlc_process_rx_frame(uint8_t *buf, uint16_t len);
|
||||
void hdlc_tx_frame(const uint8_t *txbuffer, uint8_t len);
|
||||
|
||||
#endif //DISPLAY_AVR_3_HDLC_H
|
Loading…
Reference in New Issue
Block a user