Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

FreeRTOs with "error.h" ...

Posted by debugasm on November 29, 2017

Hi,

I use FreeRTOs v9.0.0 with Lwip v1.4.1 and socket thread uses "error.h" with error variable to get fault connection, timeout, ecc.

The question:

(1) The "error" variable is FreeRTOs Thread safe or reentrant ?

(2) How check if "error" is visible only for thread and not overwritten by other threads ?

Thanks very much.

debugasm


FreeRTOs with "error.h" ...

Posted by rtel on November 29, 2017

Sorry, don't know, that is part of lwiP not FreeRTOS.


FreeRTOs with "error.h" ...

Posted by debugasm on November 30, 2017

Hi,

Sorry, don't know, that is part of lwiP not FreeRTOS.

You are right, but FreeRTOs is also used with "libc" that provides "errno", perhaps one possibility is to modify the "geterrno" and "seterrno" routines to write the error in a task variable using "configNUMTHREADLOCALSTORAGEPOINTERS".

I can try to implement it.

Thanks.

debugasm


FreeRTOs with "error.h" ...

Posted by heinbali01 on November 30, 2017

That's indeed the way to go.

When defining configNUM_THREAD_LOCAL_STORAGE_POINTERS, a number of objects can be stored in the task's context.

This object has the size of a pointer, but it does not have to be a pointer. An integer may be casted and stored as a pointer.

The FreeRTOS+FAT library already uses 3 of these storage pointers, one of the to stored the last errno seen. Another pointer stores the CWD (current working directory).

Here are the two access functions:

~~~ /* The errno is stored in a thread local buffer. */ static portINLINE void stdioSETERRNO( int iErrno ) { vTaskSetThreadLocalStoragePointer( NULL, ffconfigCWDTHREADLOCALINDEX, ( void * ) ( iErrno ) ); }

static portINLINE int stdioGET_ERRNO( void ) { void *pvResult;

pvResult = pvTaskGetThreadLocalStoragePointer( ( TaskHandle_t )NULL, ffconfigCWD_THREAD_LOCAL_INDEX );
return ( int ) pvResult;

} ~~~

I know that in some environments errno has an instance per thread in some magic way, but I don't think that it will work together with FreeRTOS.

Regards,


FreeRTOs with "error.h" ...

Posted by debugasm on November 30, 2017

Hi,

I know that in some environments errno has an instance per thread in some magic way, but I don't think that it will work together with FreeRTOS.

The Lwip have a routine to set "errno", I just need to modify this function to use FreeRTOs. It should not be difficult.

Thanks very much.

debugasm


FreeRTOs with "error.h" ...

Posted by heinbali01 on November 30, 2017

Not everyone appreciates C++, but you could make a nice little class for errno.

~~~ class CErrno { public: operator int() { void *pvResult;

    pvResult = pvTaskGetThreadLocalStoragePointer( ( TaskHandle_t )NULL, ffconfigCWD_THREAD_LOCAL_INDEX );
    return ( int ) pvResult;
}
int operator =(int aValue)
{
    vTaskSetThreadLocalStoragePointer( NULL, ffconfigCWD_THREAD_LOCAL_INDEX, ( void * ) ( aValue ) );
    return aValue;
}

};

CErrno myErrno; ~~~

Now the same instance of myErrno can be used by any task:

~~~~ myErrno = 0; /* call function */ if( myErrno == 2 ) { } ~~~~


FreeRTOs with "error.h" ...

Posted by thomask on December 2, 2017

Hein Tibosch wrote: > I know that in some environments errno has an instance per thread in some magic way, > but I don't think that it will work together with FreeRTOS.

debugasm wrote: > The Lwip have a routine to set "errno", I just need to modify this function to use FreeRTOs.

If you are using newlib, you only have to set

configUSENEWLIBREENTRANT to 1

in your FreeRTOSConfig.h

In newlib,"errno" and other global variables like "stdout" are defined as macros and will actually point to a task local reent structure. On single core systems, there's just a pointer called "impureptr" that is updated by FreeRTOS on task switch (see task.c).


FreeRTOs with "error.h" ...

Posted by heinbali01 on December 3, 2017

If you are using newlib, you only have to set configUSE_NEWLIB_REENTRANT to 1 in your FreeRTOSConfig.h

Oops, yes, I had seen it but as I rarely use newlib, I forgot about it.

Thanks for this explanation.


FreeRTOs with "error.h" ...

Posted by debugasm on December 4, 2017

I use Xilinx SDK that use "libc". I don't have found a way to compile "newlibc" and use it in this environment. So I was building a new library to be used with FreeRTOs usable even in debugging unlike other libraries.

Why does FreeRTOS team not develop an internal library like "Micrium μc / os-xxx", which integrates the main libraries and then free themselves from external bookcases ?


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


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner