Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

xQueuePeek disregards portMAX_DELAY, runs continuously. xQueueReceive works fine.

Posted by softport on June 26, 2017

Hello, I have been working with FreeRtos for the last couple of weeks. I have read 'Mastering the FreeRTOS Real Time Kernel' up to the end of chapter 4, that deals with queues, and also have 'The FreeRTOS Reference Manual 9.0.0' manual. I've been going through the first manual, following the examples and modifying as needed, to work with CubeMX, setup for STM32F4 controller. My IDE is System Workbench for STM32.

This is the first problem I have not been able to solve: xQueuePeek is disregarding portMAX_DELAY, making the task run continuously. There are no errors or warnings before/after compiling. If I replace xQueuePeek with xQueueReceive(with exact same arguments), everything works fine.

The sender task uses xQueueOverwrite(), and osDelay(500). Sending and receiving tasks have the same priority 1. When the receiver uses xQueueReceive(), my output is updated every 0.5 seconds as expected, however when I replace it with xQueuePeek(), the output scrolls continuosly. I am using the rs232 port and connecting with Putty.

I know some FreeRtos functions need special settings in FreeRTOSConfig.h, but I did not see any info on this regarding xQueuePeek, at least nothing more than xQueueReceive would need.

Am I missing something?

Thanks in advance

~~~

// Example adapted from: // Mastering the FreeRTOS Real Time Kernel (#161204) // Section 4.7 'Using a Queue to Create a Mailbox' // Hardware configuration done using STM32CubeMX // Processor: STM32F407VE

include "FreeRTOS.h"
include "task.h"
include "cmsis_os.h"
include "stm32f4xx_hal.h"
include "usart.h"
include "string.h" // memset, used to clear cBuffer
include "stdio.h" // snprntf

// Mailbox handle QueueHandle_t xMailbox;

// Mailbox message typedef struct xExampleStructure { TickTypet xTimeStamp; uint32t ulValue; } Example_t;

// Serial port messages

define serialMAXMSGLEN ( 50 )

char cBuffer[serialMAXMSGLEN]; char sNewLine[5] = "rn";

int main(void) {

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init();

/* Configure the system clock */ SystemClock_Config();

/* Initialize all configured peripherals */ MXGPIOInit(); MXUSART1UART_Init();

/* Call init function for freertos objects (in freertos.c) */ MXFREERTOSInit();

/* Start scheduler */ osKernelStart();

/* We should never get here as control is now taken by the scheduler */ while (1){ }

}

void MXFREERTOSInit(void) {

xTaskCreate( (TaskFunction_t)vUpdateMailbox, "updateMailbox", 128, NULL, 1, NULL );
xTaskCreate( (TaskFunction_t)vReadMailbox, "readMailbox", 128, NULL, 1, NULL );

xMailbox = xQueueCreate( 1, sizeof( Example_t ) );

}

void vUpdateMailbox(void const * argument) { Examplet xData; uint32t ulNewValue = 0;

for(;;){

	xData.ulValue = ulNewValue;
	ulNewValue++;

	xData.xTimeStamp = xTaskGetTickCount();
	xQueueOverwrite( xMailbox, &xData );

	osDelay(500);
}

}

void vReadMailbox(void const * argument) { Examplet pxData; TickTypet xPreviousTimeStamp = 0;

pxData.ulValue = 0;
pxData.xTimeStamp = 0;

/* Infinite loop */
for(;;){

	xPreviousTimeStamp = pxData.xTimeStamp;

	xQueuePeek( xMailbox, &pxData, portMAX_DELAY ); // Does not wait
	//xQueueReceive(xMailbox, &pxData, portMAX_DELAY); // This works

	if( pxData.xTimeStamp > xPreviousTimeStamp ){
		vSendStringAndNumber( "Data received: ", pxData.ulValue);
		vSendStringAndNumber( "Timestamp: ", pxData.xTimeStamp);
	}
	else{
		vSendString( "No new data\r\n");
		vSendStringAndNumber( "Current data: ", pxData.ulValue);
		vSendStringAndNumber( "Timestamp: ", pxData.xTimeStamp);
	}
}

}

// Adapted from basic_io.c void vSendString( const char *pcString ) { vTaskSuspendAll(); { memset(cBuffer, 0, sizeof(cBuffer)); // string.h snprintf(cBuffer, sizeof(cBuffer), "%s", pcString); // stdio.h

	HAL_UART_Transmit(&huart1, (uint8_t *)cBuffer, sizeof(cBuffer), 1000);
}
xTaskResumeAll();

}

void vSendStringAndNumber( const char *pcString, unsigned long ulValue){

vTaskSuspendAll();
{
	memset(cBuffer, 0, sizeof(cBuffer)); // string.h
	snprintf(cBuffer, sizeof(cBuffer), "%s%lu", pcString, ulValue);
	strcat(cBuffer, (char *)sNewLine);

	HAL_UART_Transmit(&huart1, (uint8_t *)cBuffer, sizeof(cBuffer), 1000);
}
xTaskResumeAll();

}

~~~


xQueuePeek disregards portMAX_DELAY, runs continuously. xQueueReceive works fine.

Posted by richarddamon on June 26, 2017

Oncd the peek has detected an item on the queue, your proogram doesn't do anything later to remove it, so it wii continue to be there. The difference between a peek and a receive is that peek leaves the data on the queue, so something later can take it off.


xQueuePeek disregards portMAX_DELAY, runs continuously. xQueueReceive works fine.

Posted by softport on June 26, 2017

Oh dear, that is so obvious, I'm a bit embarassed. Thank you.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists