Did I break queue.h?

Hi everyone,

I am trying to implement a simple queue in a simple RTC task. My code is as follows:

#define RTC_TASK_PRIORITY        3
#define RTC_TASK_STACK_SIZE      (configMINIMAL_STACK_SIZE)  

#define RTC_TASK_QUEUE_ITEM_SIZE ( sizeof(RTC_Time) )
#define RTC_TASK_QUEUE_LENGTH    ( 2 )

/* Declare the queue(s) */
//StaticQueue_t xRTCQueueBuffer;
StaticQueue_t xRTCTaskQueueBuffer1, xRTCTaskQueueBuffer2;
//QueueHandle_t RTCQueue; //, xRTCTaskQueue1, xRTCTaskQueue2;
QueueHandle_t xRTCTaskQueue1, xRTCTaskQueue2;

/* Allocate memory for the queues' storage */
uint8_t ucRTCTaskQueueStorage1[RTC_TASK_QUEUE_LENGTH
* RTC_TASK_QUEUE_ITEM_SIZE];

uint8_t ucRTCTaskQueueStorage2[RTC_TASK_QUEUE_LENGTH
* RTC_TASK_QUEUE_ITEM_SIZE];

/* Task handle and buffer */
StaticTask_t xRTCTaskBuffer;
StackType_t xRTCTaskStack[RTC_TASK_STACK_SIZE];

    /* Task loop */
    for (;;) {
        if (rtcTaskTick) {
            count++;
            rtcTaskTick = false;

            int prev_second = current_time->second;
            vUpdateCurrentTime();
            if (current_time->second > prev_second) { 

            printf("%04d-%02d-%02d %02d:%02d:%02d\r\n", 
                   current_time->year, current_time->month, current_time->day, current_time->hour, current_time->minute, current_time->second);
            }

            /*Send the updated time incl ten_ms to log tasks */
            BaseType_t xQueueSend(
                QueueHandle_t xRTCTaskQueue1,
                &current_time,
                TickType_t pdMS_TO_TICKS(5)
            );

            /* Send semaphore to UITask every second */


            /* Send the updated time to UITask */ 
            // xQueueSend(xRTCQueue1, &current_time, 0);
        }
    }
}


/* Initialization function */
void vInitRTCTask(void) {

    InitTimer0(16);
    vInitCurrentTime();
    /* Create the queues statically */
     xRTCTaskQueue1 = xQueueCreateStatic(
        RTC_TASK_QUEUE_LENGTH,
        RTC_TASK_QUEUE_ITEM_SIZE, ucRTCTaskQueueStorage1,
        &xRTCTaskQueueBuffer1);
    
    xRTCTaskQueue2 = xQueueCreateStatic(
            RTC_TASK_QUEUE_LENGTH,
            RTC_TASK_QUEUE_ITEM_SIZE, ucRTCTaskQueueStorage2,
            &xRTCTaskQueueBuffer2);

    if (xRTCTaskQueue1 == NULL) { // || xRTCTaskQueue2 == NULL) {
        fprintf(stderr, "Failed to create the RTC task queues.\n");
        return;
    }

    // Create the task statically
    TaskHandle_t xRTCTaskHandle = xTaskCreateStatic(
        vRTCTask,                 // Task function
        "RTC Task",               // Task name
        RTC_TASK_STACK_SIZE,       // Stack size
        (void*)1,                  // Task parameter
        RTC_TASK_PRIORITY,        // Priority
        xRTCTaskStack,            // Stack buffer
        &xRTCTaskBuffer           // Task buffer
    );

    if (xRTCTaskHandle == NULL) {
        fprintf(stderr, "Failed to create the RTC task.\n");
    }
    else {
        // printf("The RTC task was created successfully.\n");
    }
}

Before I added the queue, everything was fine. But after I added it, I have this:
C:\Users\Robert\source\repos\rrss\rcu_sw\freertos\freertos_kernel\include/queue.h:68:47: error: expected declaration specifiers or β€˜β€¦β€™ before β€˜(’ token

Line 68 is:

/* For internal use only. */
#define queueSEND_TO_BACK                     ( ( BaseType_t ) 0 ) // <== Line 68
#define queueSEND_TO_FRONT                    ( ( BaseType_t ) 1 )
#define queueOVERWRITE                        ( ( BaseType_t ) 2 )

Obviously I will never touch the FreeRTOS code. So what can this be? Did I somehow break queue.h with a simple queue?

I am in MCUXpresso with an Arm CM7

Kind regards and thanks,
Robert

Oops, I made a silly mistake. I forgot the variable. I fixed my code as follows:

 /*Send the updated time incl ten_ms to log tasks */
 BaseType_t curTimeSent = xQueueSend(
     xRTCTaskQueue1,
     &current_time,
     TickType_t pdMS_TO_TICKS(5)
 );

However, now I have:

C:\Users\Robert\source\repos\rrss\rcu_sw\freertos\freertos_kernel\include/projdefs.h:42:62: error: expected declaration specifiers or '...' before '(' token

#ifndef pdMS_TO_TICKS
    #define pdMS_TO_TICKS( xTimeInMs )    ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInMs ) * ( uint64_t ) configTICK_RATE_HZ ) / ( uint64_t ) 1000U ) ) // <== Line 42 
#endif

This is really strange: for the compiler to report syntax errors in the FreeRTOS kernel.

This is wrong / not C :wink: Retry after removing the (mistakenly copied) TickType_t.
The resulting confusing error location is a result of C macro magic, unfortunately.

Thanks Hartmut,

I was in a rush and copied from the API signature as you observed.

But it’s really weird that the compiler gives no clue about the real error and redirects to something really far away, like the FreeRTOS kernel, claiming that there are syntax errors there.

Thanks again :see_no_evil:

1 Like