Dynamic memory allocation

Forum related to ERIKA Enterprise and RT-Druid version 3

Moderator: paolo.gai

Post Reply
Mohamed Hssairi
Newbie
Posts: 9
Joined: Tue Jun 18, 2019 2:15 pm

Dynamic memory allocation

Post by Mohamed Hssairi » Tue Jul 30, 2019 10:52 am

hello,

How to use dynamic memory allocation with Erika 3 on TriCore, I'am using Infineon Tricore AURIX build with RT-Druid.

I was trying for almost a week to use malloc, but it's seems that the memory allocation is not happening.
Am I missing something or what, did I need to add something to the oil file.
I'am really struggling with this guys and am running out of time.

I will explain to you what I'am working on, so I created 4 tasks:
-Sender1, Sender2, Sender3
-TaskLogger
The Senders tasks they want to send message to the TaskLogger, where the TaskLogger will display the message on the terminal so I created a chained list contain all the messages when the task logger will read the messages from the list and display them on the terminal.
This is the function responsible of the insertion into the list.

static void printf_t(List *list, char *pmessage, int sizemsg)
{

/*Creating the new t_logger_msg*/
t_logger_msg *newmsg = (t_logger_msg *) malloc(sizeof(t_logger_msg));
newmsg->pmessage = (char *) malloc((sizemsg+1) * sizeof(char));
newmsg->size = (int) malloc(sizeof(int));
strcpy(newmsg->pmessage, pmessage);
newmsg->size = sizemsg;
newmsg->next = NULL;
if (list->First != NULL) /* if the list is not empty */
{
t_logger_msg *ActuelMsg = list->Last;
ActuelMsg->next = newmsg;
list->Last = newmsg;
}
else /*if the list is empty*/
{
list->First = newmsg;
list->Last = newmsg;
}
}

And those are my structures:

/************************************************************************************************
*
* Structure
*
**********************************************************************************************/
typedef struct t_logger_msg t_logger_msg;
struct t_logger_msg
{
char * pmessage;
int size;
t_logger_msg* next;
};

/**************************************************************************************************************/
/*Another structure to control the entire linked list.*/

typedef struct List List;
struct List
{
t_logger_msg *First;
t_logger_msg *Last;
};

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Dynamic memory allocation

Post by e.guidieri » Tue Jul 30, 2019 1:20 pm

Hi,

If you are using the Hightec compiler you should look at this thread:

malloc using

And since you are in hurry you should already have done that.

Errico

Mohamed Hssairi
Newbie
Posts: 9
Joined: Tue Jun 18, 2019 2:15 pm

Re: Dynamic memory allocation

Post by Mohamed Hssairi » Tue Jul 30, 2019 2:45 pm

e.guidieri wrote:
Tue Jul 30, 2019 1:20 pm
Hi,

If you are using the Hightec compiler you should look at this thread:

malloc using

And since you are in hurry you should already have done that.

Errico
Thank you for your respond, but i'am using the GCC compiler also i couldn't find the linker file in my project folder.

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Dynamic memory allocation

Post by e.guidieri » Tue Jul 30, 2019 4:28 pm

Hi,

AFAIK the only GCC compiler for TriCore ISA is provided by Hightec, so I think that you are using it. Maybe do you call it 'Free entry toolchain'?

the linker file is located in erika/mk folder (path relative to the .oil file) after the pull, roughly speaking, you can find the linker file there after you start to see the library files starting to compile.

Regards,
Errico

Post Reply