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

📄 net_buf.c

📁 从Luminary官方网站下载的LM3S6000系列的UCos+Tcp/IP的源码, 经本人稍微修改后可直接在IAR6.2下编译通过,里面包括了LM3S6000系列的所有外设UART, PWn....
💻 C
📖 第 1 页 / 共 5 页
字号:
*                       the buffer lists in vertical columns represent buffer fragments & the head fragment
*                       of each buffer list is linked horizontally to form the queue of buffer lists.
*
*                       (1) Buffers' 'PrevPrimListPtr' & 'NextPrimListPtr' doubly-link each buffer list's
*                           head buffer to form the queue of buffer lists.
*
*                       (2) Buffer's 'PrevBufPtr'      & 'NextBufPtr'      doubly-link each buffer in a
*                           buffer list.
*
*
*                                                 |                                               |
*                                                 |<--------------- Buffer Queue ---------------->|
*                                                 |                 (see Note #1)                 |
*
*                                                             NextPrimListPtr
*                                                             (see Note #1b1)
*                                                                        |
*                                                                        |
*                      ---          Head of       -------       -------  v    -------       -------
*                       ^            Buffer  ---->|     |------>|     |------>|     |------>|     |
*                       |            Queue        |     |       |     |       |     |       |     |
*                       |                         |     |<------|     |<------|     |<------|     |
*                       |       (see Note #1a)    |     |       |     |  ^    |     |       |     |
*                       |                         |     |       |     |  |    |     |       |     |
*                       |                         -------       -------  |    -------       -------
*                       |                           | ^                  |      | ^
*                       |                           | |       PrevPrimListPtr   | |
*                       |                           v |       (see Note #1b1)   v |
*                       |                         -------                     -------
*                                                 |     |                     |     |
*                Fragments in the                 |     |                     |     |
*                same Buffer List                 |     |                     |     |
*                 (see Note #1b)                  |     |                     |     |
*                                                 |     |                     |     |
*                       |                         -------                     -------
*                       |                           | ^                         | ^
*                       |           NextBufPtr ---> | | <--- PrevBufPtr         | |
*                       |        (see Note #1b2)    v |   (see Note #1b2)       v |
*                       |                         -------                     -------
*                       |                         |     |                     |     |
*                       |                         |     |                     |     |
*                       |                         |     |                     -------
*                       |                         |     |
*                       v                         |     |
*                      ---                        -------
*
*
* Argument(s) : pbuf_q      Pointer to a buffer queue.
*
*               pctr        Pointer to possible error counter.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
*               This function is an INTERNAL network protocol suite function & SHOULD NOT be called by 
*               application function(s).
*
* Note(s)     : (2) #### Buffers are NOT validated for 'Type' or 'USED' before freeing.
*
*                   See also 'NetBuf_Free()  Note #2'.
*
*               (3) Buffers may be referenced by multiple layer(s).  Therefore, the buffers' reference 
*                   counters MUST be checked before freeing the buffer(s).
*
*               (4) Buffers NOT freed are unlinked from other buffer fragment lists & compressed within
*                   their own buffer list.  Ideally, buffer fragment lists SHOULD NEVER be compressed 
*                   but should be unlinked in their entirety.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetBuf_FreeBufQ_PrimList (NET_BUF  *pbuf_q,
                                NET_CTR  *pctr)
{
#if ((NET_CTR_CFG_ERR_EN      == DEF_ENABLED)                    && \
     (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR        cpu_sr;
#endif
    NET_BUF      *pbuf_list;
    NET_BUF      *pbuf_list_next;
    NET_BUF      *pbuf;
    NET_BUF      *pbuf_prev;
    NET_BUF      *pbuf_next;
    NET_BUF_HDR  *pbuf_hdr;


    pbuf_list = pbuf_q;
    while (pbuf_list != (NET_BUF *)0) {                         /* Free ALL buf lists in buf Q.                         */
        pbuf_hdr                  = &pbuf_list->Hdr;
        pbuf_list_next            = (NET_BUF *)pbuf_hdr->NextPrimListPtr;
        pbuf_hdr->PrevPrimListPtr = (void    *)0;
        pbuf_hdr->NextPrimListPtr = (void    *)0;

        pbuf                      = (NET_BUF *)pbuf_list;
        pbuf_prev                 = (NET_BUF *)0;

        while (pbuf  != (NET_BUF *)0) {                         /* Free ALL bufs in buf list.                           */
            pbuf_hdr  = &pbuf->Hdr;
            pbuf_next = (NET_BUF *)pbuf_hdr->NextBufPtr;

#if (NET_DBG_CFG_MEM_CLR_EN == DEF_ENABLED)
            pbuf_hdr->PrevPrimListPtr = (void *)0;
            pbuf_hdr->NextPrimListPtr = (void *)0;
#endif

            if (pbuf_hdr->RefCtr > 1) {                         /* If     buf ref'd by multiple layers (see Note #3), ..*/
                pbuf_hdr->RefCtr--;                             /* .. dec buf ref ctr.                                  */
                pbuf_hdr->PrevBufPtr = (void *)pbuf_prev;
                pbuf_hdr->NextBufPtr = (void *)0;
                if (pbuf_prev != (NET_BUF *)0) {                /* If prev buf non-NULL, ...                            */
                    pbuf_hdr             = &pbuf_prev->Hdr;
                    pbuf_hdr->NextBufPtr = (void *)pbuf;        /* ... set prev buf's next ptr to cur buf.              */
                }
                pbuf_prev = (NET_BUF *)pbuf;                    /* Set cur buf as new prev buf (see Note #4).           */

            } else {                                            /* Else free buf.                                       */
                NetBuf_Free(pbuf);
            }

            if (pctr != (NET_CTR *)0) {                         /* If avail, ...                                        */
                NET_CTR_ERR_INC(*pctr);                         /* ... inc err ctr.                                     */
            }

            pbuf  = pbuf_next;
        }

        pbuf_list = pbuf_list_next;
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      NetBuf_FreeBufQ_SecList()
*
* Description : Free a network buffer queue, organized by the buffers' secondary buffer lists.
*
*               (1) Network buffer queues are implemented as multiply-linked lists :
*
*                   (a) 'pbuf_q' points to the head of the buffer queue.
*
*                   (b) Buffers are multiply-linked to form a queue of buffer lists.  In the diagram below,
*                       the buffer lists in vertical columns represent buffer fragments & the head fragment
*                       of each buffer list is linked horizontally to form the queue of buffer lists.
*
*                       (1) Buffers' 'PrevSecListPtr' & 'NextSecListPtr' doubly-link each buffer list's
*                           head buffer to form the queue of buffer lists.
*
*                       (2) Buffer's 'PrevBufPtr'     & 'NextBufPtr'     doubly-link each buffer in a
*                           buffer list.
*
*
*                                                 |                                               |
*                                                 |<--------------- Buffer Queue ---------------->|
*                                                 |                 (see Note #1)                 |
*
*                                                              NextSecListPtr
*                                                             (see Note #1b1)
*                                                                        |
*                                                                        |
*                      ---          Head of       -------       -------  v    -------       -------
*                       ^            Buffer  ---->|     |------>|     |------>|     |------>|     |
*                       |            Queue        |     |       |     |       |     |       |     |
*                       |                         |     |<------|     |<------|     |<------|     |
*                       |       (see Note #1a)    |     |       |     |  ^    |     |       |     |
*                       |                         |     |       |     |  |    |     |       |     |
*                       |                         -------       -------  |    -------       -------
*                       |                           | ^                  |      | ^
*                       |                           | |        PrevSecListPtr   | |
*                       |                           v |       (see Note #1b1)   v |
*                       |                         -------                     -------
*                                                 |     |                     |     |
*                Fragments in the                 |     |                     |     |
*                same Buffer List                 |     |                     |     |
*                 (see Note #1b)                  |     |                     |     |
*                                                 |     |                     |     |
*                       |                         -------                     -------
*                       |                           | ^                         | ^
*                       |           NextBufPtr ---> | | <--- PrevBufPtr         | |
*                       |        (see Note #1b2)    v |   (see Note #1b2)       v |
*                       |                         -------                     -------
*                       |                         |     |                     |     |
*                       |                         |     |                     |     |
*                       |                         |     |                     -------
*                       |                         |     |
*                       v                         |     |
*                      ---                        -------
*
*
* Argument(s) : pbuf_q          Pointer to a buffer queue.
*
*               pctr            Pointer to possible error counter.
*
*               pfnct_unlink    Pointer to possible unlink funcion.
*
* Return(s)   : none.
*
* Caller(s)   : various.
*
*               This function is an INTERNAL network protocol suite function & SHOULD NOT be called by 
*               application function(s).
*
* Note(s)     : (2) #### Buffers are NOT validated for 'Type' or 'USED' before freeing.
*
*                   See also 'NetBuf_Free()  Note #2'.
*
*               (3) Buffers may be referenced by multiple layer(s).  Therefore, the buffers' reference 
*                   counters MUST be checked before freeing the buffer(s).
*
*               (4) Buffers NOT freed are unlinked from other buffer fragment lists & compressed within
*                   their own buffer list.  Ideally, buffer fragment lists SHOULD NEVER be compressed 
*                   but should be unlinked in their entirety.
*
*               (5) Since buffers' unlink functions are intended to unlink a buffer from a secondary
*                   buffer queue list; the secondary buffer queue list's unlink function MUST be cleared
*                   before freeing the buffer to avoid unlinking the buffer(s) from the secondary buffer
*                   queue list multiple times.
*
*                   See also 'NetBuf_Free()  Note #3'.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetBuf_FreeBufQ_SecList (NET_BUF       *pbuf_q,
                               NET_CTR       *pctr,
                               CPU_FNCT_PTR   pfnct_unlink)
{
#if ((NET_CTR_CFG_ERR_EN      == DEF_ENABLED)                    && \
     (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR        cpu_sr;
#endif
    NET_BUF      *pbuf_list;
    NET_BUF      *pbuf_list_next;
    NET_BUF      *pbuf;
    NET_BUF      *pbuf_prev;
    NET_BUF      *pbuf_next;
    NET_BUF_HDR  *pbuf_hdr;


    pbuf_list = pbuf_q;
    while (pbuf_list   != (NET_BUF *)0) {                       /* Free ALL buf lists in buf Q.                         */
        pbuf_hdr        = &pbuf_list->Hdr;
        pbuf_list_next  = (NET_BUF *)pbuf_hdr->NextSecListPtr;

        pbuf            = (NET_BUF *)pbuf_list;
        pbuf_prev       = (NET_BUF *)0;

        while (pbuf    != (NET_BUF *)0) {                       /* Free ALL bufs in buf list.                           */
            pbuf_hdr    = &pbuf->Hdr;
            pbuf_next   = (NET_BUF *)pbuf_hdr->NextBufPtr;
                                                                /* Clr unlink ptrs (see Note #5).                       */
            if (pbuf_hdr->UnlinkFnctPtr == (CPU_FNCT_PTR)pfnct_unlink) {
                pbuf_hdr->UnlinkFnctPtr  = (CPU_FNCT_PTR)0;
                pbuf_hdr->UnlinkObjPtr   = (void       *)0;
            }

            if (pbuf_hdr->RefCtr > 1) {                         /* If     buf ref'd by multiple layers (see Note #3), ..*/
                pbuf_hdr->RefCtr--;                             /* .. dec buf ref ctr.                                  */
                pbuf_hdr->PrevBufPtr = (void *)pbuf_prev;
                pbuf_hdr->NextBufPtr = (void *)0;
                if (pbuf_prev != (NET_BUF *)0) {                /* If prev buf non-NULL, ...                            */
                    pbuf_hdr             = &pbuf_prev->Hdr;
                    pbuf_hdr->NextBufPtr = (void *)pbuf;        /* ... set prev buf's next ptr to cur buf.              */
                }
                pbuf_prev = (NET_BUF *)pbuf;                    /* Set cur buf as new prev buf (see Note #4).           */

            } else {                                            /* Else free buf.                                       */
                NetBuf_Free(pbuf);
            }

            if (pctr != (NET_CTR *)0) {                         /* If avail, ...                                        */
                NET_CTR_ERR_INC(*pctr);                         /* ... inc err ctr.                                     */
            }

            pbuf  = pbuf_next;
        }

        pbuf_list = pbuf_list_next;
    }
}

⌨️ 快捷键说明

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