⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcm_udpdrv.c

📁 abstract rtos
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifdef __cplusplusextern "C"{#endif #include "syscfg.h"#if( CONFIG_BOARD_GMPU == TRUE || CONFIG_BOARD_EIA == TRUE )#include "aos.h"#include "p2p_include.h"#include "ip/ip_pub.h" #include "socket/sock_pub.h"  #include "socket/sock_err.h"#if( CONFIG_BOARD_EIA == TRUE )#include "cfm/cfm_pub.h"#elif ( CONFIG_BOARD_GMPU == TRUE )#include "db_pub.h"#endif#include "../ker/ssp_msg.h"#include "lcm_q921.h"#include "lcm_udpdrv.h"#if( CONFIG_BOARD_GMPU == TRUE )U32 sst_trunkno_for_ip(U32 ulPeerIP);#endif#define EIA_DRV_MTU 800   #define UDP4EIA_N200 3#define UDP4EIA_T200_LEN 2000#define UDP4EIA_T203_LEN 30000#define MAX_DELAY_PKT_NUM 7#define MAX_DELAY_TIME_IN_TICK 10LCM_PHY_RCV  eia_rcv = NULL;LCM_PHY_RCV  siptrunk_rcv = NULL;EIA_TABLE_S *eia_table = NULL;U32 edrv_rv_task_id = U32_BUTT;U32 m_ulEiaNo       = 2049;U32 m_ulMaxDelayTick = MAX_DELAY_TIME_IN_TICK;U16 g_lcm_rel_udp_port     = U16_BUTT;U16 g_lcm_peer_udp_port    = U16_BUTT;#if( CONFIG_BOARD_GMPU == TRUE )U32 g_lcm_tcp_signal_disable = 0;#endifVOID drv_eia_send( U32 eia_no, struct msg_blk *mb );VOID drv_eia_delay_recv( );VOID edrv_load_config( );#if( CONFIG_BOARD_EIA == TRUE )U32 g_ulLcmLastKeepAliveTick;#endif#define DRV_EIA_DEBUG( fmt, eiano, p1, p2, p3 )\{\    if( U32_BUTT == m_ulEiaNo || (eiano) ==m_ulEiaNo )\    {\        aos_printf( MPE_EDRV, fmt, eiano, p1, p2, p3 );\    }\}#undef ENABLE_DRV_EIA_DEBUG#ifdef ENABLE_DRV_EIA_DEBUG#define DRV_DEBUG_2( fmt, p1, p2 )\    aos_printf( MPE_EDRV, fmt, p1, p2 )#endif#if( CONFIG_BOARD_EIA == TRUE )VOID edrv_keepalive_send( );#endifU32 drv_eia_init( START_ORDER_E order ){    U32 result = AOS_SUCC, i;    AOS_ASSERT( 10 == sizeof( struct eia_msg_hdr ) );    switch( order )    {        case STARTUP_INITIAL:                   g_lcm_rel_udp_port = CONFIG_EIA_UDP_PORT;            g_lcm_peer_udp_port = CONFIG_EIA_UDP_PORT;                            m_ulEiaNo = U16_BUTT;            m_ulMaxDelayTick = MAX_DELAY_TIME_IN_TICK;                        eia_rcv = NULL;            siptrunk_rcv = NULL;            eia_table = aos_smem_alloc( MPE_EDRV, 0, sizeof(EIA_TABLE_S)*DRV_EIA_NUM );            if( NULL == eia_table )            {                return AOS_FAIL;            }                        for( i=0; i < DRV_EIA_NUM; i++ )            {                eia_table[i].status    = FALSE;                eia_table[i].is_rcving = 0;#if( CONFIG_BOARD_GMPU == TRUE )                if( i < MAX_DEV_EIA_NUM )                {                    eia_table[i].is_eia    = 1;                    eia_table[i].port_no   = (U16)i;                }                else                {                    eia_table[i].is_eia    = 0;                    eia_table[i].port_no   = (U16)(i - MAX_DEV_EIA_NUM);                }#else                eia_table[i].is_eia    = 1;                eia_table[i].port_no   = (U16)i;#endif                eia_table[i].is_new_ver   = 0;                eia_table[i].reserv_bit   = 0;                eia_table[i].rx_timestamp = 0;                eia_table[i].rx_serialno  = 0;                eia_table[i].tx_serialno  = 0;                aos_memset( &eia_table[i].addr, 0, sizeof(SOCKADDRIN_S) );                eia_table[i].is_tcp_mode  = 0;                eia_table[i].is_tcp_connected = 0;                eia_table[i].tcpSeq       = 0;                eia_table[i].tcpAck       = 0;#if( CONFIG_BOARD_EIA == TRUE )                eia_table[i].tcpSynCnt    = 0;#endif                msg_que_init(&eia_table[i].rx_delay_que);            }            edrv_rv_task_id = U32_BUTT;#if( CONFIG_BOARD_EIA == TRUE )            g_ulLcmLastKeepAliveTick = 0;#endif                        break;                    case STARTUP_LOAD_DATA:                 result= lcm_add_drv( LCM_DRV_UDP4EIA,                                  EIA_DRV_MTU, (LCM_PHY_SND)drv_eia_send, &eia_rcv );            if( AOS_SUCC != result )            {                return result;            }            result = lcm_set_link_paras( LCM_DRV_UDP4EIA, UDP4EIA_N200, UDP4EIA_T200_LEN, UDP4EIA_T203_LEN );            if( AOS_SUCC != result )            {                return result;            }#if( CONFIG_BOARD_GMPU == TRUE )            result= lcm_add_drv( LCM_DRV_UDP4SIPTRUNK,                                  EIA_DRV_MTU, (LCM_PHY_SND)drv_siptrunk_send, &siptrunk_rcv );            if( AOS_SUCC != result )            {                return result;            }            result = lcm_set_link_paras( LCM_DRV_UDP4SIPTRUNK, UDP4EIA_N200, UDP4EIA_T200_LEN, UDP4EIA_T203_LEN );            if( AOS_SUCC != result )            {                return result;            }#endif            break;        case STARTUP_GO:                        edrv_load_config();                        aos_tick_task_add( MPE_EDRV, drv_eia_delay_recv );                        break;                    default:            break;    }        return result;}VOID drv_udp_send( EIA_TABLE_S *pEia, U32 portno, struct msg_blk *mb ){    struct eia_msg_hdr *headp;    struct new_eia_msg_hdr *new_headp;    U32 h_ms,l_ms,not_ordered;    if( NULL == mb || NULL == mb->data )    {        if( NULL != mb )        {            msg_free( mb );        }                return ;    }    if( (NULL == pEia)      || (FALSE == pEia->status) )    {        goto err_ret;    }    if( pEia->is_new_ver )    {                new_headp = (struct new_eia_msg_hdr*)msg_push( mb, sizeof(struct new_eia_msg_hdr) );        new_headp->msg_type = LCM_MSG;        new_headp->is_new_ver    = 1;        new_headp->resrv_0  = 0;        new_headp->resrv_1  = 1;                    #if( CONFIG_BOARD_GMPU == TRUE )        if( pEia->is_eia )        {            if( 513 != portno )            {                new_headp->eia_no  = 513;            }            else            {                new_headp->eia_no  = 515;            }            new_headp->is_siptrunk = 0;        }        else        {                        new_headp->eia_no  = 0xFFFF;            new_headp->is_siptrunk = 1;        }#else        new_headp->eia_no  = LOCAL_PROCESSOR_ID;        new_headp->is_siptrunk = 0;#endif        new_headp->eia_no = AOS_NTOHS(new_headp->eia_no);                   headp = (struct eia_msg_hdr*)new_headp;    }    else    {                headp = (struct eia_msg_hdr*)msg_push( mb, sizeof(struct eia_msg_hdr) );        headp->msg_type = LCM_MSG;        headp->is_new_ver    = 0;                    #if( CONFIG_BOARD_GMPU == TRUE )        if( pEia->is_eia )        {            if( 513 != portno )            {                headp->eia_no_hi  = (U8)(513>>8);                headp->eia_no_lo  = (U8)(513 & 0xff);            }            else            {                headp->eia_no_hi  = (U8)(515>>8);                headp->eia_no_lo  = (U8)(515& 0xff);            }            headp->is_siptrunk = 0;        }        else        {                        headp->eia_no_hi  = 0xF;            headp->eia_no_lo  = 0xFF;            headp->is_siptrunk = 1;        }#else        headp->eia_no_hi  = (U8)((LOCAL_PROCESSOR_ID & 0xff00)>>8);        headp->eia_no_lo  = (U8)(LOCAL_PROCESSOR_ID & 0xff);        headp->is_siptrunk = 0;#endif    }    aos_time_get_ms( &h_ms, &l_ms );    not_ordered = lcm_is_ui_fram( mb->data );    headp->timestamp  = AOS_HTONL(l_ms);    if( !not_ordered )    {        headp->not_ordered = 0;            headp->tx_serialno= AOS_HTONL(pEia->tx_serialno);        pEia->tx_serialno++;    }    else    {        headp->not_ordered = 1;            headp->tx_serialno= 0;    }#if( CONFIG_BOARD_GMPU == TRUE )    if( pEia->is_tcp_mode )    {        lcm_tcp_rapid_send_to_eth( g_lcm_rel_udp_port, pEia->tcpSeq, pEia->tcpAck, mb, &pEia->addr );        pEia->tcpSeq += mb->len;    }    else    {        lcm_rapid_send_to_eth( g_lcm_rel_udp_port, mb, &pEia->addr );    }#else    lcm_rapid_send_to_eth( g_lcm_rel_udp_port, mb, &pEia->addr );#endif    return;err_ret:    aos_dmem_free( (VOID*)mb->head );    msg_free( mb );}#define MB_TX_SERIALNO(_mb) (((struct eia_msg_hdr*)(_mb)->data)->tx_serialno)VOID drv_udp_recv( EIA_TABLE_S *pEia, U32 eia_no, struct msg_blk *mb ){    struct eia_msg_hdr *headp;    struct msg_blk     *mb_t;    S32                 diff_t, diff_s;        if( NULL == mb || NULL == mb->data )    {        if( NULL != mb )        {            msg_free( mb );        }                return;    }    if( NULL == pEia )    {        goto drv_eia_recv_fail;    }        headp = (struct eia_msg_hdr*)mb->data;        headp->timestamp   = AOS_NTOHL(headp->timestamp);    headp->tx_serialno = AOS_NTOHL(headp->tx_serialno);    if( headp->not_ordered )    {        DRV_EIA_DEBUG( "Not Ordered Direct Recv, eiano=%d, tx_s=%u",eia_no,MB_TX_SERIALNO(mb),0,0 );                if( headp->is_new_ver )        {            msg_pull( mb, sizeof(struct new_eia_msg_hdr) );        }        else        {            msg_pull( mb, sizeof(struct eia_msg_hdr) );        }        if( pEia->is_eia )        {            (*eia_rcv)( LCM_DRV_UDP4EIA, pEia->port_no, mb );        }#if( CONFIG_BOARD_GMPU == TRUE )                else        {            (*siptrunk_rcv)( LCM_DRV_UDP4SIPTRUNK, pEia->port_no, mb );        }#endif                return;    }        *(U32*)mb->tail = aos_tick_get();    diff_s = (S32)(MB_TX_SERIALNO(mb) - pEia->rx_serialno);    if( diff_s < 0 )    {        DRV_EIA_DEBUG( "Edrv:eia %d packet arrived after the latter received,"                "%d packets delay, tx_s=%u", eia_no, -diff_s-1,MB_TX_SERIALNO(mb),0 );               goto drv_eia_recv_fail;    }            if( pEia->is_rcving )    {        diff_t = (S32)(headp->timestamp - pEia->rx_timestamp);                if( diff_t > 0 )        {            pEia->rx_timestamp = headp->timestamp;        }        if(diff_t<0)        {            DRV_EIA_DEBUG( "eiano=%d,at least %d ms delay",eia_no,-diff_t,0,0 );        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -