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

📄 lla.c

📁 代码在ti的c67系列单片机上实现了完整的TCPIP协议栈
💻 C
字号:
//--------------------------------------------------------------------------
// Ip Stack
//--------------------------------------------------------------------------
// LLA.C
//
// Link Level Address Object
//
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stkmain.h>

//--------------------------------------------------------------------
// LLANew()
//
// Create
//--------------------------------------------------------------------
HANDLE LLANew()
{
    LLA *pl;

    if( !(pl = mmAlloc(sizeof(LLA))) )
    {
        DbgPrintf(DBG_WARN,"LLANew: OOM");
        ExecLowResource();
        return(0);
    }

    // Initialize type
    pl->Type = HTYPE_LLA;

    // Initialize refcnt
    pl->RefCount = 1;

    return( (HANDLE)pl );
}

//--------------------------------------------------------------------
// LLADeRef()
//
// DeReferences LLA handle, and frees it if the ref count reaches zero
//--------------------------------------------------------------------
void LLADeRef( HANDLE h )
{
    LLA* pl = (LLA *)h;

#ifdef _STRONG_CHECKING
    if( pl->Type != HTYPE_LLA )
    {
        DbgPrintf(DBG_ERROR,"LLADeRef: HTYPE %04x",pl->Type);
        return;
    }
#endif

    // Standard DeRef
    if( pl->RefCount != 65535 )
    {
        if( pl->RefCount > 1 )
            pl->RefCount--;                // Deref one count
        else
        {
            pl->Type = 0;                  // Kill type for debug
            mmFree( pl );
        }
    }
}

//--------------------------------------------------------------------
// LLASet()
//
// Set LLA parameters
//--------------------------------------------------------------------
void LLASet( HANDLE h, uint Type, uint Size, UINT8 *pbData )
{
    LLA *pl = (LLA *)h;

#ifdef _STRONG_CHECKING
    if( pl->Type != HTYPE_LLA )
    {
        DbgPrintf(DBG_ERROR,"LLASet: HTYPE %04x",pl->Type);
        return;
    }
#endif

    pl->AddrType = Type;
    pl->AddrLen  = Size;
    mmCopy( pl->bData, pbData, MAXLLA );
}

//--------------------------------------------------------------------
// LLAGetData()
//
// Copies the LLA address into the supplied pointer
//--------------------------------------------------------------------
void LLAGetData( HANDLE h, uint wExpSize, UINT8 *pbData )
{
    LLA *pl = (LLA *)h;

#ifdef _STRONG_CHECKING
    if( pl->Type != HTYPE_LLA )
    {
        DbgPrintf(DBG_ERROR,"LLAGetData: HTYPE %04x",pl->Type);
        return;
    }
#endif

    if( wExpSize > MAXLLA )
        wExpSize = MAXLLA;

    mmCopy( pbData, pl->bData, wExpSize );
}

#ifdef _STRONG_CHECKING
//--------------------------------------------------------------------
// LLAGetType()
//
// Get the address type
//--------------------------------------------------------------------
uint LLAGetType( HANDLE h )
{
    LLA *pl = (LLA *)h;

    if( pl->Type != HTYPE_LLA )
    {
        DbgPrintf(DBG_ERROR,"LLAGetType: HTYPE %04x",pl->Type);
        return( 0 );
    }

    return( pl->AddrType );
}

//--------------------------------------------------------------------
// LLAGetLength()
//
// Get the address length
//--------------------------------------------------------------------
uint LLAGetLength( HANDLE h )
{
    LLA *pl = (LLA *)h;

    if( pl->Type != HTYPE_LLA )
    {
        DbgPrintf(DBG_ERROR,"LLAGetLength: HTYPE %04x",pl->Type);
        return( 0 );
    }

    return( pl->AddrLen );
}
#endif

⌨️ 快捷键说明

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