This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can I install a list?

How can I install a list in a ARM controller?

typedef struct {
        volatile unsigned int *p_NextHdr;                       volatile unsigned int *p_PrevHdr;                       volatile unsigned int *p_data;
}*Hdr;

*p_NextHdr: ptr to the next list element
*p_PrevHdr: ptr to the previous list element
*p_data: ptr to the buffer (for this list element)

Hdr HdrPtr;

// ptr to the struct

At the beginning:

*p_NextHdr = *p_PrevHdr = *p_data = NULL;

But how can I install a few list elements? Could you tell me the next steps I have to do? How can I allocate storage for the struct?

best regards
Ingo

Parents
  • ok that means I use the list as a array and allocate the storage for e.g. 100 structs

    struct my_entry my_array[100];
    

    and then I'm able to say

    my_array[5].field = 5;
    

    But it is often not needed to be able to traverse a list foward and backward.

    My list includes some header information for the incoming data over the ethernet. So the list includes the number of refernces to the buffer, the pointer to the buffer as well as some flags... So the list is only the header of the buffer.

    I don't know if it is the best way to install a list - or if there's another better way to do that.

    best regards
    Ingo

Reply
  • ok that means I use the list as a array and allocate the storage for e.g. 100 structs

    struct my_entry my_array[100];
    

    and then I'm able to say

    my_array[5].field = 5;
    

    But it is often not needed to be able to traverse a list foward and backward.

    My list includes some header information for the incoming data over the ethernet. So the list includes the number of refernces to the buffer, the pointer to the buffer as well as some flags... So the list is only the header of the buffer.

    I don't know if it is the best way to install a list - or if there's another better way to do that.

    best regards
    Ingo

Children
  • number of list elements with the struct data:

    struct data *Header[NB_ETH_RX_PACKETS];
    

    ptr to the tail and the start of the list

    struct data *HdrEnd;
    struct RxData *HdrBegin;
    

    struct data

    typedef struct data {
            volatile unsigned int Data;
            struct RxData *p_NextHdr;
            struct RxData *p_PrevHdr;
    } *Hdr;
    

    Hdr p_HdrLisPtr;

    init pointers at the beginning:

    HdrBegin->p_PrevHdr = HdrEnd->p_PrevHdr = HdrBegin;                  /* */
            HdrBegin->p_NextHdr = HdrEnd->p_NextHdr = HdrBufEnd;                  /* */
            p_HdrLisPtr = HdrBegin;
    

    so now I should be able to install some list elements in a for-loop (for i=0; i<8; i++)

    Header[i]->Data = i;
    
    
                    // element in liste eintragen
                    Header[i]->p_PrevHdr = p_HdrLisPtr;                                                          /* */
                    Header[i]->p_NextHdr = p_HdrLisPtr->p_NextHdr;                                    /* */
                    p_HdrLisPtr->p_NextHdr->p_PrevHdr = Header[i];                                    /* */
                    p_HdrLisPtr->p_NextHdr = Header[i];
    

    Are there any mistakes?

    Ingo