Hi All!
I have problems with pointing data in queue.
I have got two task and one queue
intnertask communication based on the following structre:
typedef struct MesNode_
{
char* message;
size_t size;
} MesNode;
And I have some problems with receiving- I receive unknown strings which got from ram(but after the first right)
Shortly, the code:
#define configTOTAL_HEAP_SIZE ((size_t)102400)// ((size_t)98304)//
#define BUFFER_SIZE 4096// 11264 //2048
#define Middle_BUFFER_SIZE 1024
/* Definitions for thread1 */
osThreadId_t thread1;
const osThreadAttr_t uartM3gProc_attributes = {
.name = "thread1",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for thread2 */
osThreadId_t thread2;
const osThreadAttr_t TCPProc_attributes = {
.name = "thread2",
.stack_size = 256 * 8,//4,//384 * 10,//8,//4,
.priority = (osPriority_t) osPriorityHigh,//osPriorityNormal,
};
/* Definitions for logging */
osThreadId_t loggingHandle2;
const osThreadAttr_t logging2_attributes = {
.name = "logging2",
.stack_size = 256 * 16,
.priority = (osPriority_t) osPriorityNormal,//,
};
void thread1(void *argument)
{
for(;;)
{
if(req_enable >=2)
{
mss = msgNode->size;
if(uxQueueSpacesAvailable(quMsgLogHandle)!=0)
{xQueueSendToBack(quMsgLogHandle, &msgNode, NULL);
vTaskResume(loggingHandle2);}
}
osDelay(10);
}
}
void thread2(void *argument)
{
for(;;)
{
if(req_enable >=2)
{
if(uxQueueSpacesAvailable(quMsgLogHandle)!=0)
{
xQueueSendToBack(qu2, &msgNode, NULL);
vTaskResume(loggingHandle2);
}
}
osDelay(10);
void startLogging2(void *argument)
{
char CR[4] = {"\r\n"};
osMessageQueueId_t qu2 = quMsgLogHandle;//quTCPHandle;
FILINFO* fin;
FRESULT res1;
FSIZE_t fz;
UBaseType_t availb;
portBASE_TYPE resq;
for(;;)
{
MessageNode msgNode;
while(uxQueueMessagesWaiting( qu2 )!= 0)
{
resq = xQueueReceive(qu2, &msgNode, 100);//100 );//portMAX_DELAY);
if(resq == pdPASS)
{
res1 = f_open(&fil, stringfln, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
fz = f_size(&fil);
if( !(fz < (Max_fsize - BUFFER_SIZE)))
{
fnumber++;
snprintf(stringfln, sizeof(stringfln), "%s/%d.txt",dirname, fnumber);
res1 = f_open(&fil, stringfln, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
}else
snprintf(stringfln, sizeof(stringfln), "%s/%d.txt",dirname, fnumber);
if(res1 == FR_OK)
{
f_lseek(&fil, f_size(&fil));
f_puts(CR, &fil);
f_lseek(&fil, f_size(&fil));
res1 = f_write(&fil,msgNode.message,mss, NULL);
mss = 0;
f_close(&fil);
asm("NOP");
vTaskSuspend(NULL);
}
}
}
osDelay(10);
}
}
}
}
And in debug I have got the following sequence of data:
Send thread1
mNode.message
Details:0x20002748 <ucHeap+1336> “string1”
Default:0x20002748 <ucHeap+1336> “string2”
Decimal:536880968
Hex:0x20002748
Binary:100000000000000010011101001000
Octal:04000023510
receive log thread
Name : mNode.message
Details:0x20005534 <ucHeap+13092> “unknownstring1”
Default:0x20005534 <ucHeap+13092> “unknownstring2”
Decimal:536892724
Hex:0x20005534
Binary:100000000000000101010100110100
Octal:04000052464
send thread1
Name : mNode.message
Details:0x20002780 <ucHeap+1392> “string3”
Default:0x20002780 <ucHeap+1392> “string4”
Decimal:536881024
Hex:0x20002780
Binary:100000000000000010011110000000
Octal:04000023600
send thread1
Name : mNode.message
Details:0x200027b8 <ucHeap+1448> “string5”
Default:0x200027b8 <ucHeap+1448> “string6”
Decimal:536881080
Hex:0x200027b8
Binary:100000000000000010011110111000
send thread1
Name : mNode.message
Details:0x20005600 <ucHeap+13296> “string7”…
Default:0x20005600 <ucHeap+13296> “string8”…
Decimal:536892928
Hex:0x20005600
Binary:100000000000000101011000000000
Octal:04000053000
send thread2
Name : mNode.message
Details:0x200027f0 <ucHeap+1504> “string9”
Default:0x200027f0 <ucHeap+1504> “string10”
Decimal:536881136
Hex:0x200027f0
Binary:100000000000000010011111110000
Octal:04000023760
Octal:04000023670
receive log thread
Name : mNode.message
Details:0x20005534 <ucHeap+13092> “unknownstring3”
Default:0x20005534 <ucHeap+13092> “unknownstring4”
Decimal:536892724
Hex:0x20005534
Binary:100000000000000101010100110100
Octal:04000052464
Please somebody explain in what the problem can be