完成部分对上通信,出现转发耗时较长

This commit is contained in:
起床就犯困 2025-03-04 18:04:30 +08:00
parent 5142a3d77d
commit 432fa9ba62
18 changed files with 12552 additions and 9558 deletions

View File

@ -3,6 +3,10 @@
{
"file": "App/hardwareDriver/Inc/HD_GPIO.h",
"encoding": "gbk"
},
{
"file": "App/application/Src/upUartParse.c",
"encoding": "gbk"
}
]
}

View File

@ -10,6 +10,7 @@ typedef struct _queueUartSendInfo{
uint32_t length; //数据长度
uint8_t *data; //数据
} queueUartSendInfo;
#define queueUartSendInfoSize sizeof(queueUartSendInfo)
/* 分时复用485存入队列中的数据格式 */
typedef struct _queueTimeShareSendInfo{
@ -17,6 +18,7 @@ typedef struct _queueTimeShareSendInfo{
uint32_t length; //数据长度
uint8_t *data; //数据
} queueTimeShareSendInfo;
#define queueTimeShareSendInfoSize sizeof(queueTimeShareSendInfo)
extern QueueHandle_t J1_485_Queue;
extern QueueHandle_t J2_485_Queue;

View File

@ -0,0 +1,9 @@
#ifndef APP_UART_PARSE_
#define APP_UART_PARSE_
#include "uart_dev.h"
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
void upwardUartDataAnalysis(device_handle device);
#endif

View File

@ -1,24 +1,40 @@
#include "stdio.h"
#include "freerotsTask.h"
#include "uart_dev.h"
#include "FM_GPIO.h"
#include "FM_ADC.h"
#include "queueUart.h"
#include "upUartParse.h"
#include "stdio.h"
#define Common_TASK_PRIO 5
#define Common_STK_SIZE 256
#define Common_TASK_PRIO 2
#define Common_STK_SIZE 512
#define Transmit_TASK_PRIO 5
#define Transmit_TASK_PRIO 4
#define Transmit_STK_SIZE 256
TaskHandle_t CommonTask_Handler;
TaskHandle_t TransmitTask_Handler;
uint8_t data[20] = "hello world\n";
#define UpReceive_TASK_PRIO 3
#define UpReceive_STK_SIZE 256
void common_Task(void *pvParameters)
#define DownReceive_TASK_PRIO 3
#define DownReceive_STK_SIZE 256
/* 任务句柄 */
static TaskHandle_t CommonTask_Handler;
static TaskHandle_t TransmitTask_Handler;
static TaskHandle_t UpReceive_Handler;
static TaskHandle_t DownReceive_Handler;
/**
* @brief
* @param
* @retval
*/
static void common_Task(void *pvParameters)
{
// writePwrCtrlState(Android_PwrCtrl, PwrCtrlOpen);
// proportionalInt();
@ -31,31 +47,80 @@ void common_Task(void *pvParameters)
// }
while (1) {
uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
if (Buff == NULL) {
log_error("Memory allocation failed\n");
return;
}
// uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
// if (Buff == NULL) {
// log_error("Memory allocation failed\n");
// return;
// }
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
sendBuff->length = sizeof("hello world\n");
sendBuff->data = Buff + sizeof(queueUartSendInfo);
strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
// queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
// sendBuff->length = sizeof("hello world\n");
// sendBuff->data = Buff + sizeof(queueUartSendInfo);
// strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
xQueueSend(upward_uart_Queue, &Buff, 10);
vTaskDelay(1000);
// xQueueSend(upward_uart_Queue, &Buff, 10);
// log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
// USARTx_SendStr_Len(USART3, "hello world\n", sizeof("hello world\n"));
// uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
// if (Buff == NULL) {
// log_error("Memory allocation failed\n");
// return;
// }
// queueTimeShareSendInfo *sendBuff = (queueTimeShareSendInfo *)Buff;
// sendBuff->length = sizeof("hello world\n");
// sendBuff->data = Buff + sizeof(queueTimeShareSendInfo);
// sendBuff->connectPort = connectJ0;
// strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
// xQueueSend(J5_0_485_Queue, &Buff, 10);
vTaskDelay(2000);
}
}
void transmit_Task(void *pvParameters)
/**
* @brief
* @param
* @retval
*/
static void transmit_Task(void *pvParameters)
{
while (1) {
uartQueueSend();
/* ÑÓʱÈý¸öϵͳ½ÚÅÄ */
vTaskDelay(3);
}
}
/**
* @brief su806发送来的数据
* @param
* @retval
*/
static void UpReceive_Task(void *pvParameters)
{
while (1) {
upwardUartDataAnalysis(g_Upward_uart5_handle);
vTaskDelay(20);
}
}
/**
* @brief
* @param
* @retval
*/
static void DownReceive_Task(void *pvParameters)
{
while (1) {
vTaskDelay(1000);
}
}
/**
* @brief Æô¯
* @param
@ -64,10 +129,10 @@ void transmit_Task(void *pvParameters)
void startApp(void)
{
Init_Upward_uart(115200);
Init_J5_0_485(9600);
FM_GPIO_Init();
FM_ADC_Init();
uartQueueInit();
/* create task */
@ -85,6 +150,20 @@ void startApp(void)
(UBaseType_t )Transmit_TASK_PRIO,
(TaskHandle_t* )&TransmitTask_Handler);
xTaskCreate((TaskFunction_t )UpReceive_Task,
(const char* )"UpReceiveTask",
(uint16_t )UpReceive_STK_SIZE,
(void* )NULL,
(UBaseType_t )UpReceive_TASK_PRIO,
(TaskHandle_t* )&UpReceive_Handler);
xTaskCreate((TaskFunction_t )DownReceive_Task,
(const char* )"DownReceiveTask",
(uint16_t )DownReceive_STK_SIZE,
(void* )NULL,
(UBaseType_t )DownReceive_TASK_PRIO,
(TaskHandle_t* )&DownReceive_Handler);
vTaskStartScheduler();
}

View File

@ -59,7 +59,7 @@ void uartQueueInit(void)
// log_error("creat J4_485_Queue error\n");
// }
J5_0_485_Queue = xQueueCreate(5, QUEUE_SIZE);
J5_0_485_Queue = xQueueCreate(10, QUEUE_SIZE);
// if (NULL == J5_0_485_Queue) {
// log_error("creat J5_0_485_Queue error\n");
// }
@ -87,6 +87,9 @@ void uartQueueInit(void)
*/
void uartQueueSend(void)
{
/* 用于判定是否延时 */
static uint8_t flag = 0;
/* 查看队列集中是否有数据 */
xActivatedMember = xQueueSelectFromSet(uart_Queue, portMAX_DELAY);
@ -96,6 +99,7 @@ void uartQueueSend(void)
if (xQueueReceive(upward_uart_Queue, &queueRecvData.upward_uart_data, 0) == pdTRUE) {
uartInterruptSend(g_Upward_uart5_handle, queueRecvData.upward_uart_data->data
, queueRecvData.upward_uart_data->length);
flag = 1;
}
}
@ -104,7 +108,8 @@ void uartQueueSend(void)
/* 处理接收到的数据 */
if (xQueueReceive(J1_485_Queue, &queueRecvData.J1_485_data, 0) == pdTRUE) {
uartInterruptSend(g_J1_uart6_handle, queueRecvData.J1_485_data->data
, queueRecvData.J1_485_data->length);
, queueRecvData.J1_485_data->length);
flag = 1;
}
}
@ -113,7 +118,8 @@ void uartQueueSend(void)
/* 处理接收到的数据 */
if (xQueueReceive(J2_485_Queue, &queueRecvData.J2_485_data, 0) == pdTRUE) {
uartInterruptSend(g_J2_uart7_handle, queueRecvData.J2_485_data->data
, queueRecvData.J2_485_data->length);
, queueRecvData.J2_485_data->length);
flag = 1;
}
}
@ -123,6 +129,7 @@ void uartQueueSend(void)
if (xQueueReceive(J3_485_Queue, &queueRecvData.J3_485_data, 0) == pdTRUE) {
uartInterruptSend(g_J3_usart2_handle, queueRecvData.J3_485_data->data
, queueRecvData.J3_485_data->length);
flag = 1;
}
}
@ -132,6 +139,7 @@ void uartQueueSend(void)
if (xQueueReceive(J4_485_Queue, &queueRecvData.J4_485_data, 0) == pdTRUE) {
uartInterruptSend(g_J4_uart8_handle, queueRecvData.J3_485_data->data
, queueRecvData.J4_485_data->length);
flag = 1;
}
}
@ -140,11 +148,19 @@ void uartQueueSend(void)
/* 处理接收到的数据 */
if (xQueueReceive(J5_0_485_Queue, &queueRecvData.J5_0_485_data, 0) == pdTRUE) {
setConnectPort(queueRecvData.J5_0_485_data->connectPort);
uartInterruptSend(g_J4_uart8_handle, queueRecvData.J5_0_485_data->data
log_info("send J5_0 Data : %s , %d\n", queueRecvData.J5_0_485_data->data, queueRecvData.J5_0_485_data->length);
uartInterruptSend(g_J5_0_usart3_handle, queueRecvData.J5_0_485_data->data
, queueRecvData.J5_0_485_data->length);
flag = 1;
}
}
/* 没有数据发送则延时 */
if (!flag) {
/* 延时三个系统节拍 */
vTaskDelay(3);
}
flag = 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,9 @@
#include <stdio.h>
#include "pDebug.h"
#include "FreeRTOS.h"
#include "task.h"
device_handle g_J1_uart6_handle;
device_handle g_J2_uart7_handle;
device_handle g_J3_usart2_handle;
@ -487,6 +490,7 @@ void J3_Interrupt()
USART_ITConfig(J3_USART, USART_IT_TXE, DISABLE);
setJ3_485_SendState(0);
J3_485_IN_TXE();
readJ3_485;
return;
}
USART_SendData(J3_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
@ -525,6 +529,7 @@ void J5_0_Interrupt()
USART_ITConfig(J5_0_USART, USART_IT_TXE, DISABLE);
setJ5_0_485_SendState(0);
J5_0_485_IN_TXE();
readJ5_0_485;
return;
}
USART_SendData(J5_0_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
@ -589,6 +594,7 @@ void J1_Interrupt()
USART_ITConfig(J1_USART, USART_IT_TXE, DISABLE);
setJ1_485_SendState(0);
J1_485_IN_TXE();
readJ1_485;
return;
}
USART_SendData(J1_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
@ -627,6 +633,7 @@ void J2_Interrupt()
USART_ITConfig(J2_USART, USART_IT_TXE, DISABLE);
setJ2_485_SendState(0);
J2_485_IN_TXE();
readJ2_485;
return;
}
USART_SendData(J2_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
@ -665,6 +672,7 @@ void J4_Interrupt()
USART_ITConfig(J4_USART, USART_IT_TXE, DISABLE);
setJ4_485_SendState(0);
J4_485_IN_TXE();
readJ4_485;
return;
}
USART_SendData(J4_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
@ -704,22 +712,27 @@ uint8_t uartInterruptSend(device_handle device,uint8_t *data, uint16_t len)
/* 开始发送 */
if (device == g_J1_uart6_handle) {
writeJ1_485;
USART_ITConfig(J1_USART, USART_IT_TXE, ENABLE);
USART_SendData(J1_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
}
else if (device == g_J2_uart7_handle) {
writeJ2_485;
USART_ITConfig(J2_USART, USART_IT_TXE, ENABLE);
USART_SendData(J2_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
}
else if (device == g_J3_usart2_handle) {
writeJ3_485;
USART_ITConfig(J3_USART, USART_IT_TXE, ENABLE);
USART_SendData(J3_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
}
else if (device == g_J4_uart8_handle) {
writeJ4_485;
USART_ITConfig(J4_USART, USART_IT_TXE, ENABLE);
USART_SendData(J4_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
}
else if (device == g_J5_0_usart3_handle) {
writeJ5_0_485;
USART_ITConfig(J5_0_USART, USART_IT_TXE, ENABLE);
USART_SendData(J5_0_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
}
@ -899,7 +912,7 @@ void setConnectPort(uint8_t port)
}
/**
* @brief 线
* @brief
* @param
* @retval
*/

View File

@ -241,14 +241,15 @@ void J5_0_485_Init(uint32_t baud)
GPIO_InitStructure.GPIO_Pin = J5_0_DE_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
readJ5_0_485;
// writeJ5_0_485;
GPIO_InitStructure.GPIO_Pin = J5_0_A_PIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = J5_0_B_PIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = J5_0_C_PIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
USART_CONNET_J0();
USART_InitTypeDef USART_InitStructure;
@ -449,7 +450,7 @@ void Upward_UART5_Init(uint32_t baud)
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //抢占优先级为3
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
@ -531,7 +532,7 @@ void USARTx_SendStr_Len(USART_TypeDef* pUSARTx, char *str, int len)
} else if (pUSARTx == J4_USART) {
writeJ4_485;
} else if (pUSARTx == J5_0_USART) {
writeJ5_0_485;
writeJ5_0_485;
}
for (int i = 0; i < len; i++) {

View File

@ -0,0 +1,42 @@
### 测试
串口中断发送通过测试
spi_flash读写通过测试
对智能模块通信串口,阻塞发送数据通过测试。
### 问题
##### 串口中断
25/02/24
在freerots环境下中断不生效
###### 解决
> 25/02/25
>
> 需要启动freerots任务
>
> 同时中断部分
>
> ```c
> void UART5_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
> ```
>
> 变为
>
> ```c
> void UART5_IRQHandler(void) __attribute__((interrupt()));
> ```
>
> 其他中断同上,由硬件压栈变为软件压栈

View File

@ -99,7 +99,8 @@
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ SystemCoreClock
#define configTICK_RATE_HZ ( ( TickType_t ) 500 )
#define configMAX_PRIORITIES ( 15 )
// #define configMAX_PRIORITIES ( 15 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 256 ) /* Can be as low as 60 but some of the demo tasks that use this constant require it to be higher. */
// #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 12 * 1024 ) )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 24 * 1024 ) )

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

View File

@ -14,13 +14,13 @@ spi_flash读写通过测试
### 问题
##### 串口中断
#### 串口中断
25/02/24
在freerots环境下中断不生效
###### 解决
解决
> 25/02/25
>
@ -40,3 +40,64 @@ spi_flash读写通过测试
>
> 其他中断同上,由硬件压栈变为软件压栈
#### 串口发送的数据不正确
25/02/28
解决
将数据通过队列发送需要将buff的位置移动到起始位置+结构体长度
```c
uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
if (Buff == NULL) {
log_error("Memory allocation failed\n");
return;
}
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
sendBuff->length = sizeof("hello world\n");
sendBuff->data = Buff + sizeof(queueUartSendInfo);
strlcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
// for (int i = 0; i < sizeof("hello world\n"); i++) {
// sendBuff->data[i] = data[i];
// }
// *sendBuff->data = *data;
// *sendBuff->data = 'H';
log_info("dataLen:%d\n", sendBuff->length);
log_info("data:%s\n", sendBuff->data);
xQueueSend(upward_uart_Queue, &Buff, 10);
vTaskDelay(1000);
```
#### 中断中不能分配和释放内存
解决
中断中添加信号量,通知任务来释放。
## 接收解析
#### su806传来的数据
见网关单片机通信协议
#### 传感器传来的数据