AnsweredAssumed Answered

Queue Data Struct

Question asked by Sandro Bastos on Apr 29, 2015
Latest reply on Apr 30, 2015 by Sandro Bastos

Hello everybody,

 

I am trying to use Queue Data Struct in order to implement an alarm history.

The documentation is quite poor and there is not an example.

When I enqueue the second element, I get an 0x1d (29) error code that I could not find its mean anywhere.

After, for example, enqueue 10 elements, the queue size is correct (=10).

When I read the '_queue_head', that should be the first element enqueued, I get the last one (tail).

Then I keep going with '_queue_next' and all elements are the same, i.e. the last one (tail).

 

A simple code I implemented (based upon MFS code) just to test the feature:

 

#include <mqx.h>

#include <fio.h>

 

typedef struct _mfs_drive_struct

{

    uint32_t            DATA_START_SECTOR;

    QUEUE_STRUCT        HANDLE_LIST;

    uint32_t            FAT_TYPE;

} _MFS_DRIVE_STRUCT,    *_MFS_DRIVE_STRUCT_PTR;

 

/*

** file handle as defined by MFS

*/

typedef struct _mfs_handle

{

   QUEUE_ELEMENT_STRUCT   HEADER_PTR;

 

   long             LOCATION;

   long             SIZE;

   uint32_t         VALID;

 

} _MFS_HANDLE, * _MFS_HANDLE_PTR;

 

void _test_queue()

{

    _MFS_DRIVE_STRUCT ds;

    _MFS_DRIVE_STRUCT_PTR    drive_ptr=&ds;

    _MFS_HANDLE_PTR            handle;

    _MFS_HANDLE                hp, q_error;

    _MFS_HANDLE_PTR            handle_ptr=&hp;

    _MFS_HANDLE_PTR            next_handle;

 

    _queue_init(&drive_ptr->HANDLE_LIST, 0);

 

    for(int i = 0; i < 10; i++)

    {

        handle_ptr->SIZE = i*5;

        _queue_enqueue( &drive_ptr->HANDLE_LIST, (QUEUE_ELEMENT_STRUCT_PTR) handle_ptr);

        printf("erro=0x%02x\n", _queue_test   (&drive_ptr->HANDLE_LIST, (void*)&q_error));

    }

  

    next_handle =  (_MFS_HANDLE_PTR) _queue_head(&drive_ptr->HANDLE_LIST);

    printf("head: %d\n", next_handle->SIZE);

    while ( next_handle )

    {

        next_handle =  (_MFS_HANDLE_PTR) _queue_next(&drive_ptr->HANDLE_LIST, (QUEUE_ELEMENT_STRUCT_PTR) next_handle);

        printf("next: %d\n", next_handle->SIZE);

    }

}

 

Bruno Castelucci

Karina Valencia Aguilar

David Seymour

Flavio Caduda

Fernanda Prata

Outcomes