-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathHDLC.h
More file actions
95 lines (79 loc) · 3.68 KB
/
Copy pathHDLC.h
File metadata and controls
95 lines (79 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef HDLC_H
#define HDLC_H
/*
* HDLC Frame Detection Refer ITU-T Rec Q.921 $2
*/
/****************************************************************************/
/* MODULES USED */
/****************************************************************************/
/****************************************************************************/
/* DEFINITIONS AND MACROS */
/****************************************************************************/
#define TRUE 1
#define FALSE 0
#define MIN_HDLC_FR_LEN 5 /* Minimum HDLC frame length Allowed */
#define MAX_HDLC_FR_LEN 900 /* Maximum HDLC frame length Allowed */
#define MAX_HDLC_FR_LEN_WITH_STUF (MAX_HDLC_FR_LEN*(4/3)) /* HDLC frame length + Stuffing bits */
/****************************************************************************/
/* TYPEDEFS AND STRUCTURES */
/****************************************************************************/
/* HDLC FSM States */
typedef enum hdlc_fr_detect_states
{
FLAG_SEARCH = 6543, /* looking for flag state */
FLAG_SYNC_EST, /* flag sync established state */
FRAME_RX, /* receiving frame state */
MAX_HDLC_FR_DETECT_STATE
}hdlc_fr_detect_states_e;
/* HDLC Error Codes */
typedef enum hdlc_fr_detect_errors
{
NO_ERR = 55555,
INVALID_FR_LEN,
CRC_MISMATCH,
MAX_HDLC_FR_DETECT_ERRORS
}hdlc_fr_detect_errors_e;
/* context for hdlc link */
typedef struct hdlc_ch_ctxt
{
hdlc_fr_detect_states_e state; /* HDLC frame detection state */
hdlc_fr_detect_errors_e err_type; /* error type received */
unsigned short fr_bit_cnt; /* number of bits received between opening and closing flags (working copy)*/
unsigned short ready_fr_bit_cnt; /* number of bits received between opening and closing flags (copy for caller)*/
unsigned char flag_pos_ctr; /* counter for flag matching index in flag_lookup table */
unsigned char rec_bits; /* stores last 8 bits received */
unsigned char frame_ready; /* flag to signal a ready frame */
unsigned char frame[MAX_HDLC_FR_LEN_WITH_STUF]; /* stores frame received (working copy)*/
unsigned char ready_fr[MAX_HDLC_FR_LEN_WITH_STUF]; /* stores frame received (copy for caller)*/
void (*callback)(unsigned char *fr, unsigned short len, int offset);
}hdlc_ch_ctxt_t;
/****************************************************************************/
/* EXPORTED VARIABLES */
/****************************************************************************/
#ifndef HDLC_C
#endif //HDLC_C
/****************************************************************************/
/* EXPORTED FUNCTIONS */
/****************************************************************************/
/*
* HDLC frame detection algorithm.
*
* inp8 - Byte from HDLC input Stream.
* offset - Stream Offset (Application Specific)
* hdlc_ch_ctxt - HDLC Link Context
*/
void HDLC(unsigned char inp8, int offset, hdlc_ch_ctxt_t *hdlc_ch_ctxt);
/*
* Intializes HDLC frame detection algorithm context.
*
* hdlc_ch_ctxt - HDLC Link Context
* cb - Application Callback on frame detection
* fr - HDLC frame detected on link
* len - HDLC frame length
* offset - Stream Offset
*/
void HDLC_init(hdlc_ch_ctxt_t *hdlc_ch_ctxt, void (*cb)(unsigned char *fr, unsigned short len, int offset));
#endif //HDLC_H
/****************************************************************************/
/* EOF */
/****************************************************************************/