Function alias for IDF [Resolved]

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

Function alias for IDF [Resolved]

Postby Victoria Nope » Fri Dec 04, 2020 10:24 pm

Hello,

I would like to make my own function names (aliases) for certain functions of the framework (including those of FreeRTOS). I mean, for example making a header file with alias definitions where I would do something like (myaliases.h):

Code: Untitled.c Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "timer.h"

#define vTaskDelay MyTaskDelay // FreeRTOS function
#define timer_set_counter_value MyTimerSetCounterValue // IDF function

And use it in my code like:

Code: Untitled.c Select all

...
#include "myaliases.h"

void app_main() {
MyTaskDelay(1000);
MyTimerSetCounterValue(0, 0, 100);
}

This ends up on build with the compilator message:

error: implicit declaration of function 'MyTaskDelay'; did you mean 'vTaskDelay'? [-Werror=implicit-function-declaration]

I have found this answer, but as I could read elsewhere, it's not a good idea to mess with the FreeRTOSConfig.h config file, which is reasonable. What's more, it would be just for FreeRTOS functions but I would like to make aliases for IDF in general.

How can I achieve that? Or should I configure the compiler somehow to stop treating this warning as error? And if so, how and would that be safe for the framework itself?

Thank you
Have a nice day

P.S. for the questions why the heck you want to do this is the answer "because I want" ;)
P.P.S. I know I could wrap them inside inline functions, but I'm looking for a simple way (like shown above) which will alias only the function name

Stay safe!
Last edited by Victoria Nope on Tue Dec 22, 2020 5:57 am, edited 1 time in total.

Dazza0
Espressif staff
Espressif staff
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: Function alias for IDF

Postby Dazza0 » Sun Dec 06, 2020 5:26 pm

This:

Code: Untitled.c Select all


#define vTaskDelay MyTaskDelay // FreeRTOS function
is supposed to be this:

Code: Untitled.c Select all


#define MyTaskDelay vTaskDelay // FreeRTOS function
You probably also want to make your function aliases have arguments as described in GCC Macro Arguments

Code: Untitled.c Select all


#define MyTaskDelay(xTicksToDelay) vTaskDelay(xTicksToDelay) // FreeRTOS function

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

Re: Function alias for IDF

Postby Victoria Nope » Mon Dec 07, 2020 3:21 am

1. Solution 1

Aha, thank you very much! That works. Interesting that in the example they use it vice versa...

2. Solution 2

That led me to try also another way pointed in this answer. Even the VS Code editor shows the Code Insight hint with the aliased parameters and their data types (which for the #define way does not). For example:

myaliases.h

Code: Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "timer.h"

void MyTaskDelay(const TickType_t MyTicksToDelay) asm ("vTaskDelay");
esp_err_t MyTimerSetCounterValue(timer_group_t MyGroupNum, timer_idx_t MyTimerNum, uint64_t MyLoadVal) asm ("timer_set_counter_value");
main.c

Code: Select all

#include <stdio.h>
#include "myaliases.h"
 
void app_main() {
    MyTaskDelay(1000);
    MyTimerSetCounterValue(0, 0, 100);
}
Use of asm label I've spotted even by these deprecated functions (except for a few data types in other headers) in the esp_heap_alloc_caps.h. So I assume it's fine.

3. Bonus reading

How are asm labeled functions called?

Who is online

Users browsing this forum: Applebot, Bytespider and 1 guest