generated from Template/H563ZI-HAL-CMake-Template
tx task success,rx dont
This commit is contained in:
@@ -32,13 +32,12 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define BLE_TX_THREAD_STACK_SIZE 2048
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
TX_THREAD ble_tx_thread;
|
||||
UCHAR ble_tx_stack[BLE_TX_THREAD_STACK_SIZE];
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
@@ -101,7 +100,7 @@ VOID tx_application_define(VOID *first_unused_memory)
|
||||
/* USER CODE END App_ThreadX_Init_Error */
|
||||
}
|
||||
/* USER CODE BEGIN App_ThreadX_Init_Success */
|
||||
|
||||
// App_ThreadX_Init(first_unused_memory); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //app_thread_init()<29>ſ<EFBFBD><C5BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/* USER CODE END App_ThreadX_Init_Success */
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,16 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
// BLE define
|
||||
#define BLE_RX_THREAD_STACK_SIZE 2048
|
||||
#define BLE_RX_THREAD_PRIORITY 10
|
||||
|
||||
#define BLE_TX_THREAD_STACK_SIZE 2048
|
||||
#define BLE_TX_THREAD_PRIORITY 10
|
||||
//
|
||||
|
||||
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -48,27 +53,30 @@
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
/* ȫ<>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
TX_QUEUE ble_tx_queue;
|
||||
|
||||
TX_EVENT_FLAGS_GROUP system_events;
|
||||
MotorCommand current_motor_cmd = {0,0};
|
||||
_GPSData gps_data;
|
||||
|
||||
// Ble thread vd
|
||||
TX_THREAD ble_rx_thread;
|
||||
TX_THREAD ble_tx_thread;
|
||||
UCHAR ble_rx_stack[BLE_RX_THREAD_STACK_SIZE];
|
||||
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];
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
#define BLE_TX_QUEUE_DEPTH 4
|
||||
UCHAR ble_tx_queue_buffer[BLE_TX_QUEUE_DEPTH * sizeof(BLE_Message)];
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/* USER CODE END 1 */
|
||||
|
||||
@@ -83,6 +91,42 @@ UINT App_ThreadX_Init(VOID *memory_ptr)
|
||||
{
|
||||
HCBle_SendData("进入 App_ThreadX_Init\r\n");
|
||||
|
||||
UINT status;
|
||||
|
||||
// === 创建 BLE RX 线程 ===
|
||||
status = tx_thread_create(&ble_rx_thread, "BLE RX Thread",
|
||||
ble_rx_task_entry, 0,
|
||||
ble_rx_stack, BLE_RX_THREAD_STACK_SIZE,
|
||||
BLE_RX_THREAD_PRIORITY, BLE_RX_THREAD_PRIORITY,
|
||||
TX_NO_TIME_SLICE, TX_AUTO_START);
|
||||
|
||||
if(status != TX_SUCCESS)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
// === 创建 BLE TX 线程 ===
|
||||
status = tx_thread_create(&ble_tx_thread, "BLE TX Thread",
|
||||
ble_tx_task_entry, 0,
|
||||
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;
|
||||
// }
|
||||
|
||||
HCBle_SendData("✅ BLE RX/TX 线程和队列初始化完成\r\n");
|
||||
|
||||
return TX_SUCCESS;
|
||||
}
|
||||
@@ -110,8 +154,6 @@ void MX_ThreadX_Init(void)
|
||||
#ifdef TEST //Ŀǰ<C4BF><C7B0><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD>
|
||||
|
||||
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
/* USER CODE BEGIN 1 */
|
||||
void main_control_thread_entry(ULONG thread_input)
|
||||
{
|
||||
|
||||
@@ -101,7 +101,7 @@ int main(void)
|
||||
MX_TIM1_Init();
|
||||
MX_TIM8_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
HCBle_InitDMAReception();
|
||||
// HCBle_InitDMAReception();
|
||||
// HAL_Delay(200);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
@@ -115,7 +115,7 @@ int main(void)
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
// HCBle_SendData("#{\"lat\":%.6f,\"lon\":%.6f,\"angle\":%.2f}\n",23.123456, 113.654321, 95.0);
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -148,7 +148,24 @@
|
||||
<Name>-U004200403132511238363431 -O2254 -SF10000 -C0 -A1 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(6BA02477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32H5xx_2M_0800.FLM -FS08000000 -FL0200000 -FP0($$Device:STM32H563ZITx$CMSIS\Flash\STM32H5xx_2M_0800.FLM) -WA0 -WE0 -WVCE4 -WS2710 -WM0 -WP2 -WK0</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>110</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134273076</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>..\fun\HCBle.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\AutoGuideStick\../fun/HCBle.c\110</Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
@@ -170,7 +187,44 @@
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>uart_dma_rx_buf</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ble_rx_ring</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>json_buf[idx++]</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ble_rx_ring.head,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>7</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>uart_dma_rx_buf[last_pos]</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>8</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>json_buf</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>9</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>tx_event_flags_get</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>json_buf[128]</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow2>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
|
||||
Binary file not shown.
@@ -27,10 +27,6 @@ Project File Date: 06/26/2025
|
||||
<h2>Output:</h2>
|
||||
*** Using Compiler 'V6.21', folder: 'D:\keil5\ARM\ARMCLANG\Bin'
|
||||
Build target 'AutoGuideStick'
|
||||
compiling app_azure_rtos.c...
|
||||
linking...
|
||||
Program Size: Code=81692 RO-data=1768 RW-data=16 ZI-data=9352
|
||||
FromELF: creating hex file...
|
||||
"AutoGuideStick\AutoGuideStick.axf" - 0 Error(s), 0 Warning(s).
|
||||
|
||||
<h2>Software Packages used:</h2>
|
||||
@@ -55,7 +51,7 @@ Package Vendor: Keil
|
||||
|
||||
* Component: ARM::CMSIS:CORE@5.6.0
|
||||
Include file: CMSIS/Core/Include/tz_context.h
|
||||
Build Time Elapsed: 00:00:03
|
||||
Build Time Elapsed: 00:00:01
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
Dependencies for Project 'AutoGuideStick', Target 'AutoGuideStick': (DO NOT MODIFY !)
|
||||
CompilerVersion: 6210000::V6.21::ARMCLANG
|
||||
F (startup_stm32h563xx.s)(0x685C2A9A)(--target=arm-arm-none-eabi -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -masm=auto -Wa,armasm,--diag_suppress=A1950W -c
|
||||
|
||||
|
||||
-gdwarf-4 -I ../Core/Inc -I ../AZURE_RTOS/App -I ../Drivers/STM32H5xx_HAL_Driver/Inc -I ../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I ../Middlewares/ST/threadx/common/inc -I ../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I ../Middlewares/ST/threadx/ports/cortex_m33/ac6/inc -I ../Drivers/CMSIS/Include
|
||||
|
||||
-I./RTE/_AutoGuideStick
|
||||
@@ -43,7 +43,7 @@ I (D:\keil5\ARM\ARMCLANG\include\stdio.h)(0x6569B012)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\stdint.h)(0x6569B012)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\cmsis_version.h)(0x683FA4DE)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\cmsis_compiler.h)(0x683FA4DE)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\cmsis_armclang.h)(0x683FA4DE)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\cmsis_armclang.h)(0x683FA4DE)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\mpu_armv8.h)(0x683FA4DE)
|
||||
I (..\Drivers\CMSIS\Device\ST\STM32H5xx\Include\system_stm32h5xx.h)(0x683FA4DE)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h)(0x683FA4DD)
|
||||
@@ -140,7 +140,7 @@ I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim_ex.h)(0x683FA4DD)
|
||||
-ID:/keil5/ARM/PACK/Keil/STM32H5xx_DFP/1.3.0/Drivers/CMSIS/Device/ST/STM32H5xx/Include
|
||||
|
||||
-D__UVISION_VERSION="539" -D_RTE_ -DSTM32H563xx -D_RTE_ -DTX_INCLUDE_USER_DEFINE_FILE -DTX_SINGLE_MODE_NON_SECURE="1" -DUSE_HAL_DRIVER -DSTM32H563xx
|
||||
|
||||
|
||||
-o autoguidestick/gpdma.o -MD)
|
||||
I (..\Core\Inc\main.hc.\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal.h)(0x00000000)
|
||||
I (..\Core\Inc\stm32h5xx_hal_conf.h)(0x685C2A98)
|
||||
@@ -246,7 +246,7 @@ I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim_ex.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_def.h)(0x683FA4DD)
|
||||
I (..\Drivers\CMSIS\Device\ST\STM32H5xx\Include\stm32h5xx.h)(0x683FA4DE)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\math.h)(0x6569B012)
|
||||
I (..\Drivers\CMSIS\Device\ST\STM32H5xx\Include\stm32h563xx.h)(0x683FA4DE)
|
||||
I (..\Drivers\CMSIS\Device\ST\STM32H5xx\Include\stm32h563xx.h)(0x683FA4DE)
|
||||
I (..\Drivers\CMSIS\Include\core_cm33.h)(0x683FA4DE)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\stdint.h)(0x6569B012)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\cmsis_version.h)(0x683FA4DE)
|
||||
@@ -320,7 +320,7 @@ I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim_ex.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim_ex.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_uart.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_uart_ex.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_uart_ex.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_exti.h)(0x683FA4DD)
|
||||
F (../Core/Src/usart.c)(0x685BB8D6)(-xc -std=c11 --target=arm-arm-none-eabi -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -c
|
||||
|
||||
@@ -352,7 +352,7 @@ I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim_ex.h)(0x683FA4DD)
|
||||
I (D:\advance_stick\AutoGuideStick\Drivers\CMSIS\Include\mpu_armv8.h)(0x683FA4DE)
|
||||
I (..\Drivers\CMSIS\Device\ST\STM32H5xx\Include\system_stm32h5xx.h)(0x683FA4DE)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h)(0x683FA4DD)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\stddef.h)(0x6569B012)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\stddef.h)(0x6569B012)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_rcc_ex.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_gpio.h)(0x683FA4DD)
|
||||
I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_gpio_ex.h)(0x683FA4DD)
|
||||
@@ -2070,7 +2070,7 @@ I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
|
||||
|
||||
-o autoguidestick/tx_event_flags_info_get.o -MD)
|
||||
I (..\Middlewares\ST\threadx\common\inc\tx_api.h)(0x683FA4DA)
|
||||
I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
|
||||
I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
|
||||
I (..\Core\Inc\tx_user.he:\keil5\ARM\ARMCLANG\include\stdlib.h)(0x00000000)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\string.h)(0x6569B012)
|
||||
I (..\Middlewares\ST\threadx\common\inc\tx_trace.h)(0x683FA4DA)
|
||||
@@ -2111,9 +2111,9 @@ I (D:\keil5\ARM\ARMCLANG\include\string.h)(0x6569B012)
|
||||
|
||||
-o autoguidestick/tx_event_flags_set.o -MD)
|
||||
I (..\Middlewares\ST\threadx\common\inc\tx_api.h)(0x683FA4DA)
|
||||
I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
|
||||
I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
|
||||
I (..\Core\Inc\tx_user.he:\keil5\ARM\ARMCLANG\include\stdlib.h)(0x00000000)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\string.h)(0x6569B012)
|
||||
I (D:\keil5\ARM\ARMCLANG\include\string.h)(0x6569B012)
|
||||
I (..\Middlewares\ST\threadx\common\inc\tx_trace.h)(0x683FA4DA)
|
||||
I (..\Middlewares\ST\threadx\common\inc\tx_thread.h)(0x683FA4DA)
|
||||
I (..\Middlewares\ST\threadx\common\inc\tx_event_flags.h)(0x683FA4DA)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
111
fun/HCBle.c
111
fun/HCBle.c
@@ -1,6 +1,8 @@
|
||||
#include "HCBle.h"
|
||||
|
||||
/**
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> δ<><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
<EFBFBD><EFBFBD>ʾ: <20><>Ȼ BLE <20>Լ<EFBFBD> GPS<50><53><EFBFBD><EFBFBD>DMA+ UART<52><54><EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ
|
||||
BLE --- DMA + IDLE <20>ж<EFBFBD> ѭ<><D1AD> DMA + <20><><EFBFBD><EFBFBD><EFBFBD>жϴ<D0B6><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UART IDLE
|
||||
GPS --- DMA +<2B>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD> + TC<54>ж<EFBFBD> <20><><EFBFBD>ù̶<C3B9><CCB6><EFBFBD><EFBFBD><EFBFBD> DMA DMA<4D><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
@@ -34,11 +36,17 @@ MotorCommand cmd;
|
||||
LocationData current_location = {0};
|
||||
float imu_angle = 0.0f;
|
||||
|
||||
TX_EVENT_FLAGS_GROUP ble_event_flags;
|
||||
#define BLE_EVENT_DATA_READY 0x01
|
||||
void HCBle_InitEventFlags(void)
|
||||
{ tx_event_flags_create(&ble_event_flags, "BLE Events");}
|
||||
|
||||
//<2F><>ʼ<EFBFBD><CABC>DMA<4D><41><EFBFBD>պ<EFBFBD><D5BA><EFBFBD>
|
||||
void HCBle_InitDMAReception(void)
|
||||
{
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
// HAL_UART_Receive_DMA(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
// HAL_UARTEx_ReceiveToIdle_DMA(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
// ֻ<><D6BB>Ҫֱ<D2AA>Ӵ<EFBFBD><D3B4><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD><DABF>н<EFBFBD><D0BD><EFBFBD>
|
||||
// HAL_UARTEx_RxEventCallback --- <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>
|
||||
}
|
||||
@@ -67,85 +75,89 @@ void HCBle_SendData(char *p,...)
|
||||
// <20><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>һ<EFBFBD><D2BB>DMA
|
||||
|
||||
|
||||
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
{
|
||||
if (huart->Instance == UART4)
|
||||
{
|
||||
|
||||
uint16_t data_len = UART_DMA_RX_BUF_SIZE - __HAL_DMA_GET_COUNTER(huart->hdmarx);
|
||||
for (uint16_t i = 0; i < data_len; i++)
|
||||
for (uint16_t i = 0; i < Size; i++)
|
||||
{
|
||||
ble_rx_ring.buffer[ble_rx_ring.head] = uart_dma_rx_buf[i];
|
||||
ble_rx_ring.head = (ble_rx_ring.head + 1) % RING_BUFFER_SIZE;
|
||||
}
|
||||
// memset(uart_dma_rx_buf, '\0', data_len);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> uart_rx_buf[0..Size-1] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>գ<EFBFBD>HAL<41><4C><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
||||
uint8_t ch = uart_dma_rx_buf[i];
|
||||
uint16_t next_head = (ble_rx_ring.head + 1) % RING_BUFFER_SIZE;
|
||||
|
||||
if (next_head != ble_rx_ring.tail)
|
||||
{
|
||||
ble_rx_ring.buffer[ble_rx_ring.head] = ch;
|
||||
ble_rx_ring.head = next_head;
|
||||
}
|
||||
}
|
||||
|
||||
tx_event_flags_set(&ble_event_flags, BLE_EVENT_DATA_READY, TX_OR);
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart4, uart_dma_rx_buf, UART_DMA_RX_BUF_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD> Json<6F><6E><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD> <20>Լ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8>ֻ<EFBFBD>App
|
||||
|
||||
|
||||
// Json<6F><6E><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD> <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>Thread x <20><><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
|
||||
void HCBle_ExtractAndParseFrame(void)
|
||||
{
|
||||
void HCBle_ExtractAndParseFrame(void) {
|
||||
static char json_buf[128];
|
||||
static int idx = 0;
|
||||
static int in_frame = 0;
|
||||
static int parsing = 0;
|
||||
|
||||
while (ble_rx_ring.tail != ble_rx_ring.head)
|
||||
{
|
||||
while (ble_rx_ring.tail != ble_rx_ring.head) {
|
||||
char c = ble_rx_ring.buffer[ble_rx_ring.tail];
|
||||
ble_rx_ring.tail = (ble_rx_ring.tail + 1) % RING_BUFFER_SIZE;
|
||||
|
||||
// ֡<><D6A1>ʼ<EFBFBD><CABC>#
|
||||
if (!parsing) {
|
||||
if (c == '#') {
|
||||
idx = 0;
|
||||
in_frame = 1;
|
||||
parsing = 1;
|
||||
memset(json_buf, 0, sizeof(json_buf));
|
||||
json_buf[idx++] = c;
|
||||
}
|
||||
else if (in_frame) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx < sizeof(json_buf) - 1) {
|
||||
json_buf[idx++] = c;
|
||||
|
||||
// ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n
|
||||
if (c == '\n') {
|
||||
json_buf[idx] = '\0';
|
||||
|
||||
// ? JSON<4F><4E><EFBFBD><EFBFBD>
|
||||
if (strstr(json_buf, "leftSpeed") && strstr(json_buf, "rightSpeed")) {
|
||||
sscanf(json_buf, "#{\"leftSpeed\":%d,\"rightSpeed\":%d}", &cmd.LeftSpeed, &cmd.RightSpeed);
|
||||
tx_event_flags_set(&system_events,EVENT_BLE_COMMAND_RECEIVED,TX_OR);
|
||||
//SetMotorSpeed(cmd.LeftSpeed, cmd.RightSpeed); <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
HCBle_SendData("<EFBFBD><EFBFBD>=%d, <20><>=%d\r\n", cmd.LeftSpeed, cmd.RightSpeed);
|
||||
int left, right;
|
||||
if (sscanf(json_buf, "#{\"leftSpeed\":%d,\"rightSpeed\":%d}\n", &left, &right) == 2) {
|
||||
HCBle_SendData("? <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>: <20><>=%d, <20><>=%d\r\n", left, right);
|
||||
cmd.LeftSpeed = left;
|
||||
cmd.RightSpeed = right;
|
||||
} else {
|
||||
HCBle_SendData("? JSON<4F><4E>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>: %s\r\n", json_buf);
|
||||
}
|
||||
|
||||
in_frame = 0;
|
||||
parsing = 0;
|
||||
idx = 0;
|
||||
}
|
||||
} else {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
in_frame = 0;
|
||||
parsing = 0;
|
||||
idx = 0;
|
||||
}
|
||||
memset(json_buf, 0, sizeof(json_buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// BLE<4C><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void ble_rx_task_entry(ULONG thread_input)
|
||||
{
|
||||
HCBle_InitDMAReception();
|
||||
HCBle_SendData("BLE RX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
|
||||
|
||||
ULONG actual_flags;
|
||||
|
||||
while (1)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
HCBle_ExtractAndParseFrame(); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>JSON<4F><4E><EFBFBD><EFBFBD>
|
||||
tx_thread_sleep(10); //ÿ10ms<6D><73>ѯ1<D1AF><31>
|
||||
tx_event_flags_get(&ble_event_flags, BLE_EVENT_DATA_READY, TX_OR_CLEAR, &actual_flags, TX_WAIT_FOREVER);
|
||||
|
||||
if (actual_flags & BLE_EVENT_DATA_READY)
|
||||
{
|
||||
HCBle_ExtractAndParseFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,25 +167,10 @@ void ble_rx_task_entry(ULONG thread_input)
|
||||
// current_location.lat, current_location.lon, current_location.angle);
|
||||
void ble_tx_task_entry(ULONG thread_input) {
|
||||
BLE_Message msg;
|
||||
HCBle_SendData("BLE TX <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\r\n");
|
||||
while(1) {
|
||||
HCBle_SendData("fuck");
|
||||
if (tx_queue_receive(&ble_tx_queue, &msg, TX_WAIT_FOREVER) == TX_SUCCESS) {
|
||||
switch (msg.msg_type)
|
||||
{
|
||||
case 1: // <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>λ<EFBFBD>ϱ<EFBFBD>
|
||||
// HCBle_SendData("fuck");
|
||||
HCBle_SendData("#{\"lat\":%.6f,\"lon\":%.6f,\"angle\":%.2f}\n",23.123456, 113.654321, 95.0);
|
||||
break;
|
||||
|
||||
case 2: // ACK <20><><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>
|
||||
HCBle_SendData("%s", msg.data);
|
||||
break;
|
||||
|
||||
default:
|
||||
HCBle_SendData("δ֪<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
tx_thread_sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,4 +45,6 @@ void HCBle_ExtractAndParseFrame(void);
|
||||
|
||||
void ble_rx_task_entry(ULONG thread_input);
|
||||
void ble_tx_task_entry(ULONG thread_input);
|
||||
void HCBle_InitEventFlags(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user