0

I am working on a project using a CC2532 which is based on an 8051 core. I am using SDCC as the compiler.

I am needing to create a list of strings, and add, remove, append, list elements.

Are there any simple open-source/free libraries that are light enough to use in an MCU?

I found SimCList and SGLIB, but they seem overkill, I am wondering if someone knows of a simpler/lighter alternative. I just need (add,remove,list,size) functions. No need for it to be circular just a simple FIFO list. I have a total of 4K RAM. The number of list elements will be a max of 20.

jelipito
  • 171
  • 2
  • 2
  • 12
  • If you need FIFO only wouldn't software stack be better? For ths you need only an array large enough for max. members and a stack pointer. For scalars (integers, floats, pointers) adding and removing is just `*--stackptr = x` and `x = *stackptr++`. – Vovanium Jan 28 '13 at 13:28
  • @Vovanium Jelipito wants a *queue* (FIFO) not a stack (LIFO). – kmkaplan Jan 28 '13 at 14:37

1 Answers1

1

Simple lists are very straight forward to implement so you may be better served doing it yourself. If you want you can extract the files include/proto/exec.h, include/exec/nodes.h, include/exec/lists.h, lib/NewList.c and lib/List.c from a library I wrote a long time ago for a simple implementation. You can use NewList to initialize an empty FIFO, AddTail to add nodes to your FIFO, RemHead to remove nodes from your FIFO. The size function would look like:

unsigned int size(struct List *list)
{
    unsigned int res = 0;
    struct Node *node = list->lh_Head;
    while (node->ln_Succ != NULL) {
        res++;
        node = node->ln_Succ;
    }
    return res;
}

Note that the test for end of list is node->ln_Succ != NULL unlike many other list frameworks. This is in fact a redo of the Amiga list system.

Should I copy the all code for list handling here?

kmkaplan
  • 18,655
  • 4
  • 51
  • 65
  • thanks, yes i'll give it a shot. how you destroy/free an element ? i am not that familiar with it yet – jelipito Jan 28 '13 at 19:12
  • The library does *not* do memory management. It means you still have to do the `malloc`/`free` dance yourself. – kmkaplan Jan 28 '13 at 20:28