FreeRTOS osMessageQueueGet перестает вытаскивать данные из очереди и вытаскивает мусор
10.01.2022, 23:24. Показов 1123. Ответов 0
Есть задача, которая перилдически считывает данные с сенсора Start_MPU6050, и записывает их в очередь, есть вторая задача, Start_LCD в которой я жду данных из очереди и если они есть, вывожу их на экран. В начале данные берутся из очереди нормальные(я проверял, именно вытягиваются из очереди неправильные данные, а записываются правильные), и отображается все корректно, но при 10-20 итерациях в очереди появляется мусор, и то мусор появляется на экране.
очередь работающая некорректно:
| C | 1
| osMessageQueueGet(MPU6050_Gyro_QueueHandle, &mpu6050_gyro_meg, 0, osWaitForever); |
|
| C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
| void Start_MPU6050(void *argument)
{
/* USER CODE BEGIN Start_MPU6050 */
/* Infinite loop */
MPU6050_t MPU6050;
MPU6050ACCQUEUE msg_acc;
MPU6050GYROQUEUE msg_gyro;
MPU6050TEMPQUEUE msg_temp;
//char mpu6050_gyro_x_y_z[30];
char mpu6050_acc[20] = {0};
char mpu6050_gyro[20] = {0};
char mpu6050_temp[10] = {0};
osDelay(500);
MPU6050_Init(&hi2c2);
osDelay(500);
//uint8_t pissition = 0;
for(;;)
{
int i = 0;
uint8_t start_pissition = 1;
char mpu6050_buf[10] = {0};
memset(msg_acc.mpu6050_acc_x_y_z, 0, sizeof(msg_acc.mpu6050_acc_x_y_z));
memset(msg_gyro.mpu6050_gyro_x_y_z, 0, sizeof(msg_gyro.mpu6050_gyro_x_y_z));
memset(msg_temp.mpu6050_temp, 0, sizeof(msg_temp.mpu6050_temp));
MPU6050_Read_All(&hi2c2, &MPU6050); // Writr data in MPU6050 struct
////////////////// ACCELERATION
// X
sprintf(mpu6050_buf ,"%f" ,MPU6050.Ax);
strcat(mpu6050_acc, "X");
// Read only first digits
i = 0;
uint8_t j = 0;
do{
i++;
}while(mpu6050_acc[i] != '\0');
do{
mpu6050_acc[i] = mpu6050_buf[j];
i++;
j++;
}while(j <= 3); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
// Y
sprintf(mpu6050_buf ,"%f" ,MPU6050.Ay);
strcat(mpu6050_acc, " Y");
// findings end of string
i = 0;
do{
i++;
}while(mpu6050_acc[i] != '\0');
j = 0;
do{
mpu6050_acc[i] = mpu6050_buf[j];
i++;
j++;
}while(j<=3); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
// Z
sprintf(mpu6050_buf ,"%f" ,MPU6050.Az);
strcat(mpu6050_acc, " Z");
// findings end of string
i = 0;
do{
i++;
}while(mpu6050_acc[i] != '\0');
j = 0;
do{
mpu6050_acc[i] = mpu6050_buf[j];
i++;
j++;
}while(j<=3); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
// Write in the acc queue
strcat(msg_acc.mpu6050_acc_x_y_z, mpu6050_acc);
memset(mpu6050_acc, 0, sizeof(mpu6050_acc));
osMessageQueuePut(MPU6050_Acc_QueueHandle, &msg_acc, 0, osWaitForever);
////////////////// GYRO
memset(mpu6050_gyro, 0, sizeof(mpu6050_gyro));
// X
sprintf(mpu6050_buf ,"%f" ,MPU6050.Gx);
strcat(mpu6050_gyro, "X");
// Read only first digits
i = 0;
j = 0;
do{
i++;
}while(mpu6050_gyro[i] != '\0');
do{
mpu6050_gyro[i] = mpu6050_buf[j];
i++;
j++;
}while(j <= 3); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
// Y
sprintf(mpu6050_buf ,"%f" ,MPU6050.Gy);
strcat(mpu6050_gyro, " Y");
// findings end of string
i = 0;
do{
i++;
}while(mpu6050_gyro[i] != '\0');
j = 0;
do{
mpu6050_gyro[i] = mpu6050_buf[j];
i++;
j++;
}while(j<=3); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
// Z
sprintf(mpu6050_buf ,"%f" ,MPU6050.Gz);
strcat(mpu6050_gyro, " Z");
// findings end of string
i = 0;
do{
i++;
}while(mpu6050_gyro[i] != '\0');
j = 0;
do{
mpu6050_gyro[i] = mpu6050_buf[j];
i++;
j++;
}while(j<=3); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
if(mpu6050_gyro[2] != '\0')
{
int gggggg = 9999;
}
// Write in the acc queue
strcat(msg_gyro.mpu6050_gyro_x_y_z, mpu6050_gyro);
memset(mpu6050_gyro, 0, sizeof(mpu6050_gyro));
if(msg_gyro.mpu6050_gyro_x_y_z[2] != '\0')
{
int gggggg = 9999;
}
osMessageQueuePut(MPU6050_Gyro_QueueHandle, &msg_gyro, 0, osWaitForever);
////////////////// TEMPERATURE
sprintf(mpu6050_buf ,"%f" ,MPU6050.Temperature);
strcat(mpu6050_temp, "T ");
// Read only first digits
i = 0;
do{
i++;
}while(mpu6050_temp[i] != '\0');
j = 0;
do{
mpu6050_temp[i] = mpu6050_buf[j];
i++;
j++;
}while(j <= 4); // Read only first digits
memset(mpu6050_buf, 0, sizeof(mpu6050_buf));
// Write in the acc queue
strcat(msg_temp.mpu6050_temp, mpu6050_temp);
memset(mpu6050_temp, 0, sizeof(mpu6050_temp));
osMessageQueuePut(MPU6050_Temp_QueueHandle, &msg_temp, 0, osWaitForever);
osDelay(1000);
}
/* USER CODE END Start_MPU6050 */
} |
|
Задача ожидающая данных из очереди mpu6050_gyro_meg.mpu6050_gyro_x_y_z
Я знаю, что так ждать данных из очереди не правильно, потому что шедуллер будет ждать данных из каждой очереди, и задача будет тормозить.
| C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| void Start_LCD(void *argument)
{
/* USER CODE BEGIN Start_LCD */
/* Infinite loop */
BME280QUEUE bme280_meg;
MPU6050ACCQUEUE mpu6050_acc_meg;
MPU6050GYROQUEUE mpu6050_gyro_meg;
MPU6050TEMPQUEUE mpu6050_temperature_meg;
MS5611QUEUE ms6050_temperature_and_pressure_meg;
// Init LCD
TFT9341_ini(240, 320);
TFT9341_SetRotation(3);
TFT9341_SetTextColor(TFT9341_WHITE);
TFT9341_SetBackColor(TFT9341_BLUE);
TFT9341_FillScreen(TFT9341_BLUE);
// Init names sensors
TFT9341_String_DMA(2,30, "1.RTC ");
TFT9341_String_DMA(2,45, "2.AM2302");
TFT9341_String_DMA(2,60, "3.BME280");
TFT9341_String_DMA(2,75, "4.MPU6050a");
TFT9341_String_DMA(2,90, "5.MPU6050g");
TFT9341_String_DMA(2,105, "6.MPU6050t");
TFT9341_String_DMA(2,120, "7.L883");
TFT9341_String_DMA(2,135, "8.MS5611");
TFT9341_String_DMA(2,150, "8.APDS9960");
TFT9341_String_DMA(2,165, "9.ADC");
for(;;)
{
// Waiting on BME280 data in queue
osMessageQueueGet(BME280_QueueHandle, &bme280_meg, 0, osWaitForever);
TFT9341_String(120, 60, bme280_meg.bme280_temperature_and_humidity);
// Waiting on MPU6050 Acc data in queue
osMessageQueueGet(MPU6050_Acc_QueueHandle, &mpu6050_acc_meg, 0, osWaitForever);
TFT9341_String_DMA(120,75, mpu6050_acc_meg.mpu6050_acc_x_y_z);
// Waiting on MPU6050 Gyro data in queue
osMessageQueueGet(MPU6050_Gyro_QueueHandle, &mpu6050_gyro_meg, 0, osWaitForever); // ??????
TFT9341_String_DMA(120,90, mpu6050_gyro_meg.mpu6050_gyro_x_y_z);
if(mpu6050_gyro_meg.mpu6050_gyro_x_y_z[2] != '\0')
{
int gggggg = 9999;
}
// Waiting on MPU6050 Temperature data in queue
osMessageQueueGet(MPU6050_Temp_QueueHandle, &mpu6050_temperature_meg, 0, osWaitForever);
TFT9341_String_DMA(120,105, mpu6050_temperature_meg.mpu6050_temp);
// Waiting on MS5611 temperature and pressure data in queue
osMessageQueueGet(MS5611_mag_QueueHandle, &ms6050_temperature_and_pressure_meg, 0, osWaitForever);
TFT9341_String_DMA(120,135, ms6050_temperature_and_pressure_meg.MS5611_mag_x_y_z_temp_and_pressure);
osDelay(100);
}
/* USER CODE END Start_LCD */
} |
|
| C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
| typedef struct
{
char mpu6050_acc_x_y_z[30];
}MPU6050ACCQUEUE;
typedef struct
{
char mpu6050_gyro_x_y_z[30];
}MPU6050GYROQUEUE;
typedef struct
{
char mpu6050_temp[10];
}MPU6050TEMPQUEUE;
/* Definitions for LCD */
osThreadId_t LCDHandle;
uint32_t LCDBuffer[ 1024 ];
osStaticThreadDef_t LCDControlBlock;
const osThreadAttr_t LCD_attributes = {
.name = "LCD",
.cb_mem = &LCDControlBlock,
.cb_size = sizeof(LCDControlBlock),
.stack_mem = &LCDBuffer[0],
.stack_size = sizeof(LCDBuffer),
.priority = (osPriority_t) osPriorityLow,
};
/* Definitions for MPU6050 */
osThreadId_t MPU6050Handle;
uint32_t MPU6050Buffer[ 500 ];
osStaticThreadDef_t MPU6050ControlBlock;
const osThreadAttr_t MPU6050_attributes = {
.name = "MPU6050",
.cb_mem = &MPU6050ControlBlock,
.cb_size = sizeof(MPU6050ControlBlock),
.stack_mem = &MPU6050Buffer[0],
.stack_size = sizeof(MPU6050Buffer),
.priority = (osPriority_t) osPriorityLow,
};
/* Definitions for MPU6050_Acc_Queue */
osMessageQueueId_t MPU6050_Acc_QueueHandle;
uint8_t MPU6050_QueueBuffer[ 1 * sizeof( MPU6050ACCQUEUE ) ];
osStaticMessageQDef_t MPU6050_QueueControlBlock;
const osMessageQueueAttr_t MPU6050_Acc_Queue_attributes = {
.name = "MPU6050_Acc_Queue",
.cb_mem = &MPU6050_QueueControlBlock,
.cb_size = sizeof(MPU6050_QueueControlBlock),
.mq_mem = &MPU6050_QueueBuffer,
.mq_size = sizeof(MPU6050_QueueBuffer)
};
/* Definitions for MPU6050_Gyro_Queue */
osMessageQueueId_t MPU6050_Gyro_QueueHandle;
uint8_t MPU6050_Gyro_QueueBuffer[ 1 * sizeof( MPU6050GYROQUEUE ) ];
osStaticMessageQDef_t MPU6050_Gyro_QueueControlBlock;
const osMessageQueueAttr_t MPU6050_Gyro_Queue_attributes = {
.name = "MPU6050_Gyro_Queue",
.cb_mem = &MPU6050_Gyro_QueueControlBlock,
.cb_size = sizeof(MPU6050_Gyro_QueueControlBlock),
.mq_mem = &MPU6050_Gyro_QueueBuffer,
.mq_size = sizeof(MPU6050_Gyro_QueueBuffer)
};
/* Definitions for MPU6050_Temp_Queue */
osMessageQueueId_t MPU6050_Temp_QueueHandle;
uint8_t MPU6050_Temp_QueueBuffer[ 1 * sizeof( MPU6050TEMPQUEUE ) ];
osStaticMessageQDef_t MPU6050_Temp_QueueControlBlock;
const osMessageQueueAttr_t MPU6050_Temp_Queue_attributes = {
.name = "MPU6050_Temp_Queue",
.cb_mem = &MPU6050_Temp_QueueControlBlock,
.cb_size = sizeof(MPU6050_Temp_QueueControlBlock),
.mq_mem = &MPU6050_Temp_QueueBuffer,
.mq_size = sizeof(MPU6050_Temp_QueueBuffer)
}; |
|
0
|