📄 ppp_framer.c
字号:
INC_DECODE_ID;
#endif /* PPP_STATUS_REPORT */
return KAL_TRUE;
}
if(status == PFC_STAT_PAUSE)
{ // srouce buffer empty
*decode_state = PFC_DECODE_PAUSE;
PFC_RESET_SRC_BUFFER();
return KAL_FALSE;
}
else
{
#ifdef PPP_STATUS_REPORT
statistic->time_100us = ppp_get_duration_100us(statistic->time_100us);
statistic->data_size = dst->used;
if(GET_DECODE_ID%10 == 9)
ppp_sta_ctx_ptr->is_status_report = PPP_STA_REPORT_SET(PPP_STA_DECODE);
INC_ERR_CNT;
INC_DECODE_ID;
#endif /* PPP_STATUS_REPORT */
// error: 1)dst buffer full 2)FCS error 3)address or control error
// 4)invalid frame
// must reset the decoder
kal_prompt_trace(MOD_PPP,"decode err = %d",status);
*decode_state = PFC_DECODE_ERR;
de_cfg->reset = KAL_TRUE;
// reset destination buffer
dst->used = 0;
dst->end_ptr = dst->cur_ptr;
if(de_cfg->src_len != 0)
{
de_cfg->dst = (kal_uint32)dst->cur_ptr;
de_cfg->dst_len = dst->size;
if(status == PFC_STAT_FCS_ERR)
{
// start to decode remaining src
de_cfg->dset7e = KAL_TRUE;
*decode_state = PFC_DECODE_READY;
}
else
{
// find next 0x7e if src->used != 0
// possible result :
// 1. find 7E and src_len != 0
// 2. find 7E and src_len == 0
// 3. find no 7E and src_len == 0
de_cfg->df7e = KAL_TRUE;
#if defined(MT6228)
status = PFC_DecodeStart(de_cfg);
#else
status = PFC_DecodeStart(id);
#endif
src->used = de_cfg->src_len;
src->cur_ptr = (kal_uint8*)de_cfg->src;
if(status == PFC_STAT_OK && de_cfg->src_len != 0)
{
de_cfg->reset = KAL_FALSE;
de_cfg->df7e = KAL_FALSE;
}
else if(status == PFC_STAT_NOT_0x7E && de_cfg->src_len == 0)
{
*decode_state = PFC_DECODE_FIND_NO_7E;
PFC_RESET_SRC_BUFFER();
return KAL_FALSE;
}
else if(status == PFC_STAT_OK && de_cfg->src_len == 0)
{
PFC_RESET_SRC_BUFFER();
return KAL_FALSE;
}
else
{
ASSERT(0);
}
}
}
else
{
PFC_RESET_SRC_BUFFER();
return KAL_FALSE;
}
}
}
return KAL_FALSE;
}
#endif //defined(MT6228) || defined(MT6229) || defined(MT6230)
//--------------------------------------------------------------------------------//
// test cases
#if defined(PFC_UNIT_TEST)
// for MT6229 PFC driver and general interface unit test
#if 1
#define DONT_CARE 0
#define BUF_LENGTH 3000
#define ENCODE_LEN 100
#define SRC_LENGTH 1500
#define ppp_frame_decode(a,b,c) ppp_frame_decode_hw(a,b,c,0)
#define ppp_frame_encode(a,b,c) ppp_frame_encode_hw(a,b,c,0)
// encode a 1500 bytes into a ppp frame takes 430us
// decode the previous generated ppp frame takes 500us
#if !defined(PFC_UNIT_TEST_ALL) // driver ut
kal_uint8 encode_src[BUF_LENGTH],encode_dst[BUF_LENGTH],decode_dst[BUF_LENGTH],
decode_src[4096];
ppp_buff_head_struct src_e, dst_e, src_d, dst_d;
ahdlc_state_struct state_e, state_d;
#else // general interface ut
kal_uint8 encode_src[2][BUF_LENGTH],encode_dst[2][BUF_LENGTH],decode_dst[2][BUF_LENGTH],
decode_src[2][4096];
ppp_buff_head_struct src_e[2], dst_e[2], src_d[2], dst_d[2];
ahdlc_state_struct state_e[2], state_d[2];
#endif
volatile kal_uint32 time1,time2;
void myGPT3_Init(void)
{
// clear pdn bit of GPT
DRV_Reg(0x80000324) = 1;
// set clock
DRV_Reg(0x80100024) = 0; //0:16k, 1:8k 2: 4K, 3: 2k,4: 1k, 7: 125hz
// start free running
DRV_Reg(0x8010001c) = 1;
}
volatile kal_uint32 GPT3_GetCount(void)
{
volatile kal_uint32 time;
time = DRV_Reg(0x80100020);
return time;
}
kal_uint32 GPT3_TimeDiff(kal_uint32 time1)
{
kal_uint32 time2;
time2 = DRV_Reg(0x80100020);
if(time2 >= time1)
return (time2 - time1);
return (0xffff - time1 + time2);
}
void PFC_test_init()
{
kal_uint32 i,j;
srand(encode_src[5]);
#if !defined(PFC_UNIT_TEST_ALL)
for(i=0;i<BUF_LENGTH;i++)
{
encode_src[i] = rand()% 0xFF;
// encode_src[i] = i%0xff;
decode_src[i] = 0xEE;
encode_dst[i] = 0xEE;
decode_dst[i] = 0xEE;
}
#else
for(j=0;j<2;j++)
for(i=0;i<BUF_LENGTH;i++)
{
encode_src[j][i] = rand()% 0xFF;
// encode_src[i] = i%0xff;
decode_src[j][i] = 0xEE;
encode_dst[j][i] = 0xEE;
decode_dst[j][i] = 0xEE;
}
#endif
}
kal_uint32 compare(kal_uint8 *a, kal_uint8 *b, kal_uint32 len)
{
int i,err=0;
for(i=0;i<len;i++)
{
if(a[i] != b[i])
{
err++;
//dbg_print(" sw hw compare failed at i = %d", i );
}
}
return err;
}
#if !defined(PFC_UNIT_TEST_ALL)
/*
1. encode 1500 random data into a ppp frame
2. decode the encoded ppp frame
3. compare the decode output with the encode source of 1500 bytes
*/
void test_case_1(void)
{
PFC_test_init();
src_e.data_ptr = encode_src;
src_e.cur_ptr = encode_src;
src_e.used = SRC_LENGTH;
src_e.end_ptr = encode_src+SRC_LENGTH;
src_e.protocol = 0xAA;
src_e.size = BUF_LENGTH;
dst_e.data_ptr = encode_dst;
dst_e.cur_ptr = encode_dst;
dst_e.used = 0;
dst_e.end_ptr = encode_dst;
dst_e.protocol = 0xAA;
dst_e.size = BUF_LENGTH;
state_e.is_acfc_tx = KAL_TRUE;
state_e.is_pfc_tx = KAL_TRUE;
state_e.is_update = KAL_TRUE;
state_e.mru = SRC_LENGTH;
state_e.xaccm = 0x1AC;
state_e.raccm = DONT_CARE;
state_e.rfcs = DONT_CARE;
state_e.xfcs = DONT_CARE;
state_e.mtu = DONT_CARE;
time1 = DRV_Reg(0x80100020);
ppp_frame_encode(&dst_e, &src_e, &state_e);
time2 = GPT3_TimeDiff(time1);
src_d.data_ptr = encode_dst;
src_d.cur_ptr = encode_dst;
src_d.used = BUF_LENGTH;
src_d.end_ptr = encode_dst+BUF_LENGTH;
src_d.protocol = 0xAA;
src_d.size = BUF_LENGTH;
dst_d.data_ptr = decode_dst;
dst_d.cur_ptr = decode_dst;
dst_d.used = 0;
dst_d.end_ptr = decode_dst;
dst_d.protocol = 0xAA;
dst_d.size = BUF_LENGTH;
state_d.is_acfc_rx = KAL_TRUE;
state_d.is_pfc_rx = KAL_TRUE;
state_d.is_update = KAL_TRUE;
state_d.mru = SRC_LENGTH;
state_d.xaccm = 0x1AC;
state_d.raccm = DONT_CARE;
state_d.rfcs = DONT_CARE;
state_d.xfcs = DONT_CARE;
state_d.mtu = DONT_CARE;
time1 = GPT3_GetCount();
ppp_frame_decode(&dst_d ,&src_d,&state_d);
time2 = GPT3_TimeDiff(time1);
if(compare(decode_dst, encode_src, SRC_LENGTH))
while(0);
}
/*
1. encode 1500 random data into a ppp frame
2. decode the encoded ppp frame 100 bytes per times. (total 16 times)
3. compare the decode output with the encode source of 1500 bytes
*/
void test_case_2(void)
{
kal_bool is_complete;
kal_uint32 count;
// encode
PFC_test_init();
src_e.data_ptr = encode_src;
src_e.cur_ptr = encode_src;
src_e.used = SRC_LENGTH;
src_e.end_ptr = encode_src+SRC_LENGTH;
src_e.protocol = 0xAA;
src_e.size = BUF_LENGTH;
dst_e.data_ptr = encode_dst;
dst_e.cur_ptr = encode_dst;
dst_e.used = 0;
dst_e.end_ptr = encode_dst;
dst_e.protocol = 0xAA;
dst_e.size = BUF_LENGTH;
state_e.is_acfc_tx = KAL_TRUE;
state_e.is_pfc_tx = KAL_TRUE;
state_e.is_update = KAL_TRUE;
state_e.mru = SRC_LENGTH;
state_e.xaccm = 0x1AC;
state_e.raccm = DONT_CARE;
state_e.rfcs = DONT_CARE;
state_e.xfcs = DONT_CARE;
state_e.mtu = DONT_CARE;
ppp_frame_encode(&dst_e, &src_e, &state_e);
// decode
is_complete = KAL_FALSE;
count = 0;
src_d.data_ptr = encode_dst;
src_d.cur_ptr = encode_dst;
src_d.used = 100;
src_d.end_ptr = encode_dst+BUF_LENGTH;
src_d.protocol = 0xAA;
src_d.size = BUF_LENGTH;
dst_d.data_ptr = decode_dst;
dst_d.cur_ptr = decode_dst;
dst_d.used = 0;
dst_d.end_ptr = decode_dst;
dst_d.protocol = 0xAA;
dst_d.size = BUF_LENGTH;
state_d.is_acfc_tx = KAL_TRUE;
state_d.is_pfc_rx = KAL_TRUE;
state_d.is_update = KAL_TRUE;
state_d.mru = SRC_LENGTH;
state_d.xaccm = 0x1AC;
state_d.raccm = DONT_CARE;
state_d.rfcs = DONT_CARE;
state_d.xfcs = DONT_CARE;
state_d.mtu = DONT_CARE;
while(is_complete == KAL_FALSE)
{
is_complete = ppp_frame_decode(&dst_d ,&src_d,&state_d);
src_d.used = 100;
}
if(compare(decode_dst, encode_src, SRC_LENGTH))
while(0);
}
/*
1. construct a invalid frame(FCS error) (7E 7E)+ valid frame
2. decoder should decode until the valid frame is finished.
*/
void test_case_3(void)
{
kal_bool is_complete;
PFC_test_init();
src_e.data_ptr = encode_src;
src_e.cur_ptr = encode_src;
src_e.used = SRC_LENGTH;
src_e.end_ptr = encode_src+SRC_LENGTH;
src_e.protocol = 0xAA;
src_e.size = BUF_LENGTH;
dst_e.data_ptr = encode_dst;
dst_e.cur_ptr = encode_dst;
dst_e.used = 0;
dst_e.end_ptr = encode_dst;
dst_e.protocol = 0xAA;
dst_e.size = BUF_LENGTH;
state_e.is_acfc_tx = KAL_TRUE;
state_e.is_pfc_tx = KAL_TRUE;
state_e.is_update = KAL_TRUE;
state_e.mru = SRC_LENGTH;
state_e.xaccm = 0x1AC;
state_e.raccm = DONT_CARE;
state_e.rfcs = DONT_CARE;
state_e.xfcs = DONT_CARE;
state_e.mtu = DONT_CARE;
ppp_frame_encode(&dst_e, &src_e, &state_e);
memcpy(decode_src , encode_dst, dst_e.used);
decode_src[300] += 1;
memcpy(decode_src+dst_e.used, encode_dst, dst_e.used);
// decode
is_complete = KAL_FALSE;
src_d.data_ptr = decode_src;
src_d.cur_ptr = decode_src;
src_d.used = 100;
src_d.end_ptr = decode_src+4096;
src_d.protocol = 0xAA;
src_d.size = 4096;
dst_d.data_ptr = decode_dst;
dst_d.cur_ptr = decode_dst;
dst_d.used = 0;
dst_d.end_ptr = decode_dst;
dst_d.protocol = 0xAA;
dst_d.size = BUF_LENGTH;
state_d.is_acfc_rx = KAL_TRUE;
state_d.is_pfc_rx = KAL_TRUE;
state_d.is_update = KAL_TRUE;
state_d.mru = SRC_LENGTH;
state_d.xaccm = 0x1AC;
state_d.raccm = DONT_CARE;
state_d.rfcs = DONT_CARE;
state_d.xfcs = DONT_CARE;
state_d.mtu = DONT_CARE;
while(is_complete == KAL_FALSE)
{
is_complete = ppp_frame_decode(&dst_d ,&src_d,&state_d);
src_d.used = 100;
if(pfc_dcb.status == PFC_STAT_FCS_ERR)
{
kal_uint8 *ptr;
ptr = (kal_uint8*)(src_d.cur_ptr-1);
if(*ptr != 0x7E)
{
ASSERT(0);
// PFC_FAIL_INDICATION();
}
else
{
// PFC_PASS_INDICATION();
}
}
}
/*
while(is_complete == KAL_FALSE)
{
is_complete = ppp_frame_decode(&dst_d ,&src_d,&state_d);
src_d.used = 100;
}
*/
if(compare(decode_dst, encode_src, SRC_LENGTH))
while(0);
}
/*
1. construct a invalid frame(FCS error) (7E)+ valid frame
2. decoder should decode until the valid frame is finished.
*/
void test_case_3_1(void)
{
kal_bool is_complete;
PFC_test_init();
src_e.data_ptr = encode_src;
src_e.cur_ptr = encode_src;
src_e.used = SRC_LENGTH;
src_e.end_ptr = encode_src+SRC_LENGTH;
src_e.protocol = 0xAA;
src_e.size = BUF_LENGTH;
dst_e.data_ptr = encode_dst;
dst_e.cur_ptr = encode_dst;
dst_e.used = 0;
dst_e.end_ptr = encode_dst;
dst_e.protocol = 0xAA;
dst_e.size = BUF_LENGTH;
state_e.is_acfc_tx = KAL_TRUE;
state_e.is_pfc_tx = KAL_TRUE;
state_e.is_update = KAL_TRUE;
state_e.mru = SRC_LENGTH;
state_e.xaccm = 0x1AC;
state_e.raccm = DONT_CARE;
state_e.rfcs = DONT_CARE;
state_e.xfcs = DONT_CARE;
state_e.mtu = DONT_CARE;
ppp_frame_encode(&dst_e, &src_e, &state_e);
memcpy(decode_src , encode_dst, dst_e.used);
decode_src[300] += 1;
memcpy(decode_src+dst_e.used-1, encode_dst, dst_e.used);
// decode
is_complete = KAL_FALSE;
src_d.data_ptr = decode_src;
src_d.cur_ptr = decode_src;
src_d.used = 100;
src_d.end_ptr = decode_src+4096;
src_d.protocol = 0xAA;
src_d.size = 4096;
dst_d.data_ptr = decode_dst;
dst_d.cur_ptr = decode_dst;
dst_d.used = 0;
dst_d.end_ptr = decode_dst;
dst_d.protocol = 0xAA;
dst_d.size = BUF_LENGTH;
state_d.is_acfc_rx = KAL_TRUE;
state_d.is_pfc_rx = KAL_TRUE;
state_d.is_update = KAL_TRUE;
state_d.mru = SRC_LENGTH;
state_d.xaccm = 0x1AC;
state_d.raccm = DONT_CARE;
state_d.rfcs = DONT_CARE;
state_d.xfcs = DONT_CARE;
state_d.mtu = DONT_CARE;
while(is_complete == KAL_FALSE)
{
is_complete = ppp_frame_decode(&dst_d ,&src_d,&state_d);
src_d.used = 100;
if(pfc_dcb.status == PFC_STAT_FCS_ERR)
{
kal_uint8 *ptr;
ptr = (kal_uint8*)(src_d.cur_ptr-1);
if(*ptr != 0x7E)
{
ASSERT(0);
//PFC_FAIL_INDICATION();
}
else
{
//PFC_PASS_INDICATION();
}
}
}
/*
while(is_complete == KAL_FALSE)
{
is_complete = ppp_frame_decode(&dst_d ,&src_d,&state_d);
src_d.used = 100;
}
*/
if(compare(decode_dst, encode_src, SRC_LENGTH))
while(0);
}
/*
1. construct a invalid frame(address control error ) + valid frame
2. decoder should decode until the valid frame is finished.
*/
void test_case_4(void)
{
kal_bool is_complete;
PFC_test_init();
src_e.data_ptr = encode_src;
src_e.cur_ptr = encode_src;
src_e.used = SRC_LENGTH;
src_e.end_ptr = encode_src+SRC_LENGTH;
src_e.protocol = 0xAA;
src_e.size = BUF_LENGTH;
dst_e.data_ptr = encode_dst;
dst_e.cur_ptr = encode_dst;
dst_e.used = 0;
dst_e.end_ptr = encode_dst;
dst_e.protocol = 0xAA;
dst_e.size = BUF_LENGTH;
state_e.is_acfc_tx = KAL_FALSE;
state_e.is_pfc_tx = KAL_FALSE;
state_e.is_update = KAL_TRUE;
state_e.mru = SRC_LENGTH;
state_e.xaccm = 0x1AC;
state_e.raccm = DONT_CARE;
state_e.rfcs = DONT_CARE;
state_e.xfcs = DONT_CARE;
state_e.mtu = DONT_CARE;
ppp_frame_encode(&dst_e, &src_e, &state_e);
memcpy(decode_src , encode_dst, dst_e.used);
decode_src[1] = 0xee; // address field (0xff)
memcpy(decode_src+dst_e.used, encode_dst, dst_e.used);
// decode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -