xQueueReceive program block

dudisor wrote on Tuesday, December 03, 2013:

Hi all,

I’m new to FreeRTOS.
Try to use version 7.6.0 ported to atmega128 atxmega128A1 and CodevisionAVR.
The demo does not work. I managed to reduce the problem to a simple program:

When creating a reading queue task, the program fails, the LEDs stop flashing. Without reading queue task, the led4 flashes 5 times and then stops because the queue is full and led0 toggle every 1 sec.

If I set priority 0 for the task vReadQueue, led4 and led5 light up and stay lit and led0 not flashes. Timer intrerrupt is triggering, and program is stuck in file list.c, function: void vListInsert( xList * const pxList, xListItem * const pxNewListItem ) in the for loop.


		for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM.  This is checked and valid. */
		{
			/* There is nothing to do here, we are just iterating to the
			wanted insertion position. */

                    // here it loops forever

		}


I tried demo port AVR_ATMega323_WinAVR modified for ATmega128 and WinAVR and it does not work to.

#define mainLED_TASK_PRIORITY   1
#define mainTEST_QUEUE_PRIORITY 2

#define mainTIMP0 ( portTickType ) 1000 / portTICK_RATE_MS 
#define mainTIMP_Q_WRITE  ( portTickType ) 500 / portTICK_RATE_MS
#define mainTIMP_Q_READ   ( portTickType ) 0xffff
#define mainNO_DELAY  ( portTickType ) 0  

//definitii prototipuri
static void vLed0( void *pvParameters );

void vWriteQueue( void *pvParameters );
void vReadQueue( void *pvParameters );
void setTestQueue(char prioritate);

static xQueueHandle xCoada;
//xSemaphoreHandle xSemaphore;


void main(void)
{
  vParTestInitialise();

  /* Create the tasks defined within this file. */  
  
  xTaskCreate( vLed0, ( signed char * )"led0", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );   
 
  //vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
  //vAltStartComTestTasks( mainCOM_TEST_PRIORITY, 38400, led6 );
    
  setTestQueue(mainTEST_QUEUE_PRIORITY);

  vTaskStartScheduler();

  while (1) 
  {
   ; //nu trebuie sa ajunga aici;
  }
}

void setTestQueue(char prioritate)
{
  xCoada=xQueueCreate(5, sizeof(char));
  //xSemaphore=xSemaphoreCreateBinary();
  
  xTaskCreate( vWriteQueue, ( signed char * ) "QProdNB", configMINIMAL_STACK_SIZE, NULL, prioritate - 1, ( xTaskHandle * ) NULL );
  
  /* -- next task, if it is created, block all program --  */
  xTaskCreate( vReadQueue, ( signed char * ) "QConsNB", configMINIMAL_STACK_SIZE, NULL, prioritate, ( xTaskHandle * ) NULL );
  /* ---------------------------  */
}

void vWriteQueue( void *pvParameters )
{
  portTickType xLastWakeTime;
  char c=0;
  // Initialise the xLastWakeTime variable with the current time.
  xLastWakeTime = xTaskGetTickCount();
  
  for( ;; )
  {
    c++;   
    //if( xSemaphoreGive( xSemaphore ) == pdPASS )
    if( xQueueSend(xCoada, &c, mainNO_DELAY ) == pdPASS )
    {
      vParTestToggleLED(led4);
    }
    vTaskDelayUntil( &xLastWakeTime, ( portTickType ) 333 / portTICK_RATE_MS );  
  }
}

void vReadQueue( void *pvParameters )
{
  char c=0;
  for( ;; )
  { 
    //if( xSemaphoreTake( xSemaphore, ( portTickType ) 10 / portTICK_RATE_MS ) == pdPASS )
    if( xQueueReceive(xCoada, &c, portMAX_DELAY ) == pdPASS )    // <-- Here get stuck
    {
      vParTestToggleLED(led5);
    }
  }
}

static void vLed0( void *pvParameters )
{
  portTickType xLastWakeTime;
  
  // Initialise the xLastWakeTime variable with the current time.
  xLastWakeTime = xTaskGetTickCount();
  
  for( ;; )
  {
    vTaskDelayUntil( &xLastWakeTime, mainTIMP0 );  
    vParTestToggleLED(led0);
  }
}

my FreeRTOSconfig.h file:

/* Call stack size for 1 task */
#define configCALL_STACK_SIZE 32

#define configUSE_PREEMPTION                    1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE                 0
#define configCPU_CLOCK_HZ                      ( ( unsigned portLONG ) 14745600 )
#define configTICK_RATE_HZ                      ( ( portTickType ) 250 )
#define configMAX_PRIORITIES                    ( ( unsigned portBASE_TYPE ) 4 )
#define configMINIMAL_STACK_SIZE                ( ( unsigned portSHORT ) 65 + configCALL_STACK_SIZE )
#define configTOTAL_HEAP_SIZE                   ( (size_t ) ( 1500 ) )
#define configMAX_TASK_NAME_LEN                 ( 8 )
#define configUSE_16_BIT_TICKS                  1
#define configIDLE_SHOULD_YIELD                 1
#define configUSE_MUTEXES                       0
#define configUSE_RECURSIVE_MUTEXES             0
#define configUSE_COUNTING_SEMAPHORES           0
#define configQUEUE_REGISTRY_SIZE               10
#define configUSE_QUEUE_SETS                    0
#define configUSE_TIME_SLICING                  1
#define configUSE_NEWLIB_REENTRANT              0


/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 		0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )


/* Hook function related definitions. */
#define configUSE_IDLE_HOOK                     0
#define configUSE_TICK_HOOK                     0
#define configCHECK_FOR_STACK_OVERFLOW          0
#define configUSE_MALLOC_FAILED_HOOK            0


/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS           0
#define configUSE_TRACE_FACILITY                0
#define configUSE_STATS_FORMATTING_FUNCTIONS    0


/* Software timer related definitions. */
#define configUSE_TIMERS                        0
#define configTIMER_TASK_PRIORITY               3
#define configTIMER_QUEUE_LENGTH                10
#define configTIMER_TASK_STACK_DEPTH            configMINIMAL_STACK_SIZE

/* Interrupt nesting behaviour configuration. */
#define configKERNEL_INTERRUPT_PRIORITY         3
#define configMAX_SYSCALL_INTERRUPT_PRIORITY    3
#define configMAX_API_CALL_INTERRUPT_PRIORITY   3


/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */

/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet                1
#define INCLUDE_uxTaskPriorityGet               1
#define INCLUDE_vTaskDelete                     1
#define INCLUDE_vTaskSuspend                    0
#define INCLUDE_xResumeFromISR                  0
#define INCLUDE_vTaskDelayUntil                 1
#define INCLUDE_vTaskDelay                      1
#define INCLUDE_xTaskGetSchedulerState          0
#define INCLUDE_xTaskGetCurrentTaskHandle       0
#define INCLUDE_uxTaskGetStackHighWaterMark     0
#define INCLUDE_xTaskGetIdleTaskHandle          0
#define INCLUDE_xTimerGetTimerDaemonTaskHandle  0
#define INCLUDE_pcTaskGetTaskName               0
#define INCLUDE_eTaskGetState                   0

Any help is appreciated.

Thanks in advance,
Adrian

rtel wrote on Tuesday, December 03, 2013:

Note there is no official XMega port (there is an AVR and a MegaAVR, but not an XMega), so the first thing to ask is, where did you get the code from?

If you wrote it yourself or obtained it from somebody else then it is difficult for us to support you directly. There are however some XMega ports in the FreeRTOS Interactive site, which is where contributed code lives: http://interactive.freertos.org if you got the code from there then it is possible the contributor will be able to help you.

If on the other hand you are trying to use the AVR or MegaAVR code from the FreeRTOS distribution, then that is not going to work on an XMega part.

Regards.

dudisor wrote on Tuesday, December 03, 2013:

Sorry, I meant ATmega128.

I try to port also on atxmega128A and I mistyped.