Tool/software: TI-RTOS
Hey,
I really don't know if it's a C problem or ti rtos problem. (I am not that familliar with C)
I am trying to read UART from the user and put in an array.
when the message exceeds a certain amount of bytes I allocate more bytes (dynamically of course)
Here is my code:
System_printf("Start of Task1 \n");\
UART_Handle handle;
UART_Params params;
// Init UART and specify non-default parameters
UART_Params_init(¶ms);
params.baudRate = 115200;
params.writeDataMode = UART_DATA_BINARY;
params.readDataMode = UART_DATA_BINARY;
//params.readCallback = readCallback;
// Open the UART and initiate the first read
handle = UART_open(Board_UART, ¶ms);
int bytesOfMessage = 10;
UChar* message;
UChar* tempMessage;
message = malloc( bytesOfMessage * sizeof(UChar));
int i = 0;
while(true)
{
int rxBytes = UART_read(handle, rxBuf, 1);
//System_printf("%d \n", rxBuf[0]);
if(rxBuf[0] != 13)
{
message[i] = rxBuf[0];
i++;
int l = 1;
if(i == bytesOfMessage)
{
System_printf("first Message: \n");
for(l=0;l<bytesOfMessage;l++)
{
//System_printf("%c",message[l]);
}
System_printf("End of first Message\n");
bytesOfMessage += 10;
//message = realloc(message, bytesOfMessage * sizeof(UChar));
tempMessage = (UChar*)realloc(message, bytesOfMessage * sizeof(UChar));
message = tempMessage;
tempMessage = NULL;
System_printf("Message2 %d: \n", bytesOfMessage);
for(l=0;l<bytesOfMessage;l++)
{
//System_printf("%c", message[l]);
}
System_printf("End of second Message\n");
}
UART_write(handle, rxBuf, rxBytes);
}
else
{
rxBuf[0] = '\r';
rxBuf[1] = '\n';
rxBuf[2] = 'n';
rxBuf[3] = 'e';
rxBuf[4] = 'w';
UART_write(handle, rxBuf, 5);
}
}
The first realloc works just fine.
The second one is stuck. I think there is enough memory.
Maybe somebody knows why this is happening to me?
Tomer.