generated from Template/H563ZI-HAL-CMake-Template
加入了消息队列,线程是可以正常运行的,rx接收任务一直运行不成功,暂时放弃
This commit is contained in:
@@ -59,11 +59,11 @@ extern "C" {
|
||||
extern TX_QUEUE ble_tx_queue;
|
||||
extern TX_EVENT_FLAGS_GROUP system_events;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t msg_type; // 1=λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,2=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
char data[128];
|
||||
}BLE_Message; // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ <20><><EFBFBD>ݽṹ
|
||||
//typedef struct
|
||||
//{
|
||||
//// uint32_t msg_type; // 应该使用 int --- 4字节
|
||||
// char data[128];
|
||||
//}BLE_Message; //
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
/* ȫ<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
/* ȫ<>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
TX_EVENT_FLAGS_GROUP system_events;
|
||||
MotorCommand current_motor_cmd = {0,0};
|
||||
@@ -66,8 +66,13 @@ UCHAR ble_tx_stack[BLE_TX_THREAD_STACK_SIZE];
|
||||
|
||||
TX_QUEUE ble_tx_queue;
|
||||
#define BLE_TX_QUEUE_LEN 10
|
||||
BLE_Message ble_tx_queue_buffer[BLE_TX_QUEUE_LEN];
|
||||
//ULONG ble_tx_queue_buffer[BLE_TX_QUEUE_LEN]; // 一定要是ULONG类型 之前使用的是BLE_Message
|
||||
|
||||
#define BLE_TX_MSG_LEN 64
|
||||
#define BLE_TX_QUEUE_LEN 10
|
||||
|
||||
__attribute__((aligned(4)))
|
||||
ULONG ble_tx_queue_buffer[BLE_TX_QUEUE_LEN * ((BLE_TX_MSG_LEN + sizeof(ULONG) - 1) / sizeof(ULONG))];
|
||||
|
||||
//
|
||||
|
||||
@@ -90,7 +95,7 @@ BLE_Message ble_tx_queue_buffer[BLE_TX_QUEUE_LEN];
|
||||
UINT App_ThreadX_Init(VOID *memory_ptr)
|
||||
{
|
||||
HCBle_SendData("进入 App_ThreadX_Init\r\n");
|
||||
|
||||
// HCBle_SendData("%d",sizeof(ULONG));
|
||||
UINT status;
|
||||
|
||||
// === 创建 BLE RX 线程 ===
|
||||
@@ -111,20 +116,24 @@ UINT App_ThreadX_Init(VOID *memory_ptr)
|
||||
ble_tx_stack, BLE_TX_THREAD_STACK_SIZE,
|
||||
BLE_TX_THREAD_PRIORITY, BLE_TX_THREAD_PRIORITY,
|
||||
TX_NO_TIME_SLICE, TX_AUTO_START);
|
||||
|
||||
if (status != TX_SUCCESS) {
|
||||
HCBle_SendData("❌ BLE TX 线程创建失败,错误码=%d\r\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
// === 创建 BLE TX 消息队列 ===
|
||||
// status = tx_queue_create(&ble_tx_queue, "BLE TX Queue",
|
||||
// sizeof(ULONG),
|
||||
// ble_tx_queue_buffer,
|
||||
// sizeof(ble_tx_queue_buffer));
|
||||
// if (status != TX_SUCCESS) {
|
||||
// HCBle_SendData("❌ BLE TX 消息队列创建失败,错误码=%d\r\n", status);
|
||||
// return status;
|
||||
// }
|
||||
status = tx_queue_create(&ble_tx_queue, "BLE TX Queue",
|
||||
(BLE_TX_MSG_LEN + sizeof(ULONG) - 1) / sizeof(ULONG),
|
||||
ble_tx_queue_buffer,
|
||||
sizeof(ble_tx_queue_buffer));
|
||||
|
||||
|
||||
if (status != TX_SUCCESS) {
|
||||
HCBle_SendData("❌ BLE TX 消息队列创建失败,错误码=%d\r\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
HCBle_SendData("✅ BLE RX/TX 线程和队列初始化完成\r\n");
|
||||
|
||||
@@ -140,7 +149,7 @@ UINT App_ThreadX_Init(VOID *memory_ptr)
|
||||
void MX_ThreadX_Init(void)
|
||||
{
|
||||
/* USER CODE BEGIN Before_Kernel_Start */
|
||||
|
||||
HCBle_InitEventFlags(); // 这必须在任何使用前调用一次
|
||||
/* USER CODE END Before_Kernel_Start */
|
||||
|
||||
tx_kernel_enter();
|
||||
@@ -151,7 +160,7 @@ void MX_ThreadX_Init(void)
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
#ifdef TEST //Ŀǰ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>
|
||||
#ifdef TEST //Ŀǰ<C4BF><C7B0><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>
|
||||
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
@@ -177,11 +186,7 @@ void main_control_thread_entry(ULONG thread_input)
|
||||
Buzzer_Close();
|
||||
Shake_Motor_Close();
|
||||
|
||||
// 发送报警到手机
|
||||
BLE_Message msg;
|
||||
msg.msg_type = 2;
|
||||
snprintf(msg.data, sizeof(msg.data), "#{\"alert\":\"Obstacle detected!\"}\n");
|
||||
tx_queue_send(&ble_tx_queue, &msg, TX_WAIT_FOREVER);
|
||||
|
||||
}
|
||||
|
||||
// 处理蓝牙控制指令
|
||||
|
||||
@@ -103,7 +103,7 @@ int main(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
// HCBle_InitDMAReception();
|
||||
// HAL_Delay(200);
|
||||
|
||||
// GPS_Init();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
MX_ThreadX_Init();
|
||||
|
||||
Reference in New Issue
Block a user