Clear Filters
Clear Filters

How to Create Custom Get Set Functions in Embedded Coder ?

8 views (last 30 days)
Want to generate a customized Get Set Function for the below mentioned example:
//Example: Application.c
void appFunc()
{
uint8_T tempData;
Get_TempData_Sts( &var );
tempData=var*2;
Set_TempData( tempData);
}
//////////////////////////// External C- Code ////////////////////
static uint8_T sendData;
sendData =3;
static uint8_T recieveData;
void Get_TempData_Sts( uint8_T * Value )
{
*Value = sendData;
}
void Set_TempData( uint8_T Value_t )
{
recieveData = Value_t;
}
Currently Get Set Function which i found with Embedded COder Help page is without argument as mentione below:
Get_TempData_Sts();
or *Get_TempData();
I Want Get Set function to be Generated via Embedded Coder as mentioned below :
Get_TempData_Sts( &var ); // Get Function
Set_TempData( tempData); // Set Function

Answers (1)

Anavi Somani
Anavi Somani on 17 Jul 2023
Hi Abhimanyu, yo can check this modiefied code once.
void appFunc()
{
uint8_T tempData;
Get_TempData_Sts(&var);
tempData = var * 2;
Set_TempData(tempData);
}
//////////////////////////// External C- Code ////////////////////
static uint8_T sendData;
static uint8_T recieveData;
void Get_TempData_Sts(uint8_T* Value)
{
*Value = sendData;
}
void Set_TempData(uint8_T Value_t)
{
recieveData = Value_t;
}
In this modified code, the Get_TempData_Sts function now accepts a pointer to a uint8_T variable as an argument. This allows the function to store the value of sendData in the variable passed as an argument.
Similarly, the Set_TempData function now takes a uint8_T value as an argument. This allows the function to set the value of recieveData to the provided argument.
With these modifications, you can call the functions as Get_TempData_Sts(&var) to get the value of sendData and Set_TempData(tempData) to set the value of recieveData.
Let me know if this helps.
  4 Comments
AbhimanyuSingh
AbhimanyuSingh on 18 Jul 2023
Thanks Anavi for the Steps,
I followed the same steps earlier and again as per your suggestion, but I am not getting expected out come :
This is what I am getting
# *Get_TempData() = 2.0 * *Get_TempData_Sts(); % While Selecting Access Mode as Pointer
Whereas I am expecting like this :
Get_TempData_Sts(&var);
Set_TempData(2.0 * var );
Can You please elaborate how you were able to generate function call in application function, And also how you generated these functions ?
void Get_TempData_Sts(double *var) {
}
void Set_TempData(double tempData) {
}
This is my implementation:
MaVo
MaVo on 7 Jun 2024
Edited: MaVo on 28 Jun 2024 at 8:47
Hello,
I did encounter the same issue. I also wanted to access the pointer arguement within a function as the signal to acces via an inport block. The currently implemented options within embedded coder do not allow this.
The Embbed Coder can only evaluate the return value of a function. The return type can be accessed directly or via pointer and that's about it. You can select this in within the Embedded Coder Dictionary for a Custom Storage Class
The function prototype which appears later in the generated C-Code looks like this.
In the Pseudecode Get Function you can see, that only the return value is assigned as a pointer, not the arguement, which remains empty.
If you want to access the pointer function arguement of a C-function currently the only choice is to parse the C-function that is referenced in your model Config under Configuration -> Code Generation -> Custom Code within the "Include headers" and "Source files" tabs and then use the C-Caller Block within Simulink.
If the source and header files have been parsed successfully (check MATLAB console output after applying the Config), you can access your C-function within a drop down menu in the block properties.
for a C-function of the following type, the C-Caller changes it's interface.
% argument: value - pointer of type float32
% return : out - uint8
% C-Code function prototype
uint8 myfun(float32 *value)
C Caller standard Interface:
C Caller with pointer arguement in function and return value:
As you can see the value represented by a pointer has a bidirectional access. You can read and write to it at the same time. Whereas the return arguement only appears as an outport.
If I had a wish towards a future improvement of the embedded coder, then it would the possibility to access pointer function arguements with several options how to embedded these signal(s) within the Simulink signal propagation. For the example above, it would be suitable to access both output signals via an Bus Object with elements "value" and "out", which would also automatically set the Data Type of the Inport to the matching Bus Object. Within the C-Code there could be a wrapper function (funout2struct) that does the signal handling and provides the signals as a struct to the "step_function()".
typedef struct BusObject
{
float32 value;
uint8 out;
};
BusObject funout2struct()
{
BusObject tmp;
tmp.out = myfun(&tmp.value);
return tmp
}

Sign in to comment.

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!