修改内存释放问题

This commit is contained in:
起床就犯困 2025-03-05 16:27:39 +08:00
parent 432fa9ba62
commit f573a918f3
25 changed files with 15359 additions and 12535 deletions

View File

@ -9,6 +9,8 @@
#ifdef RS485BUSIDLE1 #ifdef RS485BUSIDLE1
void softwareTimeInit(void);
void J1_485_IN_IDLE(void); void J1_485_IN_IDLE(void);
void J2_485_IN_IDLE(void); void J2_485_IN_IDLE(void);
void J3_485_IN_IDLE(void); void J3_485_IN_IDLE(void);

View File

@ -0,0 +1,8 @@
#ifndef APP_DOWN_UART_PARSE_
#define APP_DOWN_UART_PARSE_
#include "uart_dev.h"
extern uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
#endif

View File

@ -0,0 +1,41 @@
#ifndef APP_PARAMETER_H_
#define APP_PARAMETER_H_
#include "flash.h"
#include "upUartParse.h"
#pragma pack(push, 1)
typedef struct _configInfo {
uint32_t upWard_Uart_Baud; //与网关通信波特率
uint32_t J1_485_Baud; //与J1_485通信波特率
uint32_t J2_485_Baud; //与J2_485通信波特率
uint32_t J3_485_Baud; //与J3_485通信波特率
uint32_t J4_485_Baud; //与J4_485通信波特率
uint32_t J5_0_485_Baud; //与J5_0_485通信波特率
uint16_t crc; //crc校验
} configInfo;
#pragma pack(pop)
void readConfigParameter(void);
void writeConfigParameter(configInfo inConfigInfo);
float getWorkCurrent(void);
void setWorkCurrent(float Curr);
float getWorkVoltage(void);
void setWorkVoltage(float Voltage);
float getTemperature(void);
void setTemperature(float Temperature);
uint32_t getUpWard_Uart_Baud(void);
uint32_t getJ1_485_Baud(void);
uint32_t getJ2_485_Baud(void);
uint32_t getJ3_485_Baud(void);
uint32_t getJ4_485_Baud(void);
uint32_t getJ5_0_485_Baud(void);
#endif

View File

@ -30,5 +30,7 @@ extern QueueSetHandle_t uart_Queue;
void uartQueueInit(void); void uartQueueInit(void);
void uartQueueSend(void); void uartQueueSend(void);
void binarySemaphoreInit(void);
void binarySemaphoreFreeMemory(void);
#endif #endif

View File

@ -3,6 +3,30 @@
#include "uart_dev.h" #include "uart_dev.h"
/* 功能码 */
typedef enum {
SL_Function_Code_Read_Register = 0x30, /* 读寄存器数据 */
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
SL_Function_Code_Distribution_Profile = 0xD0, /* 配置文件下发 */
SL_Function_Code_Read_Profile = 0xD1, /* 配置文件读取 */
}SL_MsgFunctionCode;
/* 寄存器地址 */
typedef enum {
GW_Register_WorkCurrent = 0x0000,
GW_Register_WorkVoltage = 0x0001,
GW_Register_Temperature = 0x0002,
GW_Register_Port1_Power = 0x0003,
GW_Register_Port2_Power = 0x0004,
GW_Register_Port3_Power = 0x0005,
GW_Register_Port4_Power = 0x0006,
GW_Register_Port5_Power = 0x0007,
GW_Register_Port6_Power = 0x0008,
GW_Register_Port7_Power = 0x0009,
GW_Register_Port8_Power = 0x000A,
GW_Register_Port9_Power = 0x000B,
}SL_GateWay_MsgRegister;
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len); uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
void upwardUartDataAnalysis(device_handle device); void upwardUartDataAnalysis(device_handle device);

View File

@ -0,0 +1,22 @@
#include "downUartParse.h"
/* 1秒的节拍数 */
#define tick_1S configTICK_RATE_HZ
/* 状态机 */
typedef enum {
wait = 0, /* 串口状态机初始状态 */
startFlag, /* 接收到帧头 */
// address, /* 设备地址 */
functionCode, /* 接收到功能码 */
dataLen, /* 接收到数据长度 */
crcCheckBitGW, /* 接收到校验位 */
endFlagGW, /* 接收到帧尾 */
} uartStateMachine;

View File

@ -8,25 +8,32 @@
#include "FM_ADC.h" #include "FM_ADC.h"
#include "queueUart.h" #include "queueUart.h"
#include "upUartParse.h" #include "upUartParse.h"
#include "flash.h"
#include "parameter.h"
#include "busIdleDetection.h"
#define Common_TASK_PRIO 2 #define Common_TASK_PRIO 2
#define Common_STK_SIZE 512 #define Common_STK_SIZE 512
#define Transmit_TASK_PRIO 4 #define Transmit_TASK_PRIO 7
#define Transmit_STK_SIZE 256 #define Transmit_STK_SIZE 256
#define UpReceive_TASK_PRIO 3 #define UpReceive_TASK_PRIO 5
#define UpReceive_STK_SIZE 256 #define UpReceive_STK_SIZE 256
#define DownReceive_TASK_PRIO 3 #define DownReceive_TASK_PRIO 4
#define DownReceive_STK_SIZE 256 #define DownReceive_STK_SIZE 256
#define FreeMemory_TASK_PRIO 5
#define FreeMemory_STK_SIZE 256
/* ÈÎÎñ¾ä±ú */ /* ÈÎÎñ¾ä±ú */
static TaskHandle_t CommonTask_Handler; static TaskHandle_t CommonTask_Handler;
static TaskHandle_t TransmitTask_Handler; static TaskHandle_t TransmitTask_Handler;
static TaskHandle_t UpReceive_Handler; static TaskHandle_t UpReceive_Handler;
static TaskHandle_t DownReceive_Handler; static TaskHandle_t DownReceive_Handler;
static TaskHandle_t FreeMemory_Handler;
/** /**
@ -46,6 +53,14 @@ static void common_Task(void *pvParameters)
// vTaskDelay(1000); // vTaskDelay(1000);
// } // }
uint16_t HeapSizeNum = 0;
/* 用于绝对延时 */
TickType_t xLastWakeTime;
const TickType_t xFrequency = 100; // 50 个滴答即200mS
// 初始化 xLastWakeTime
xLastWakeTime = xTaskGetTickCount();
while (1) { while (1) {
// uint8_t *Buff = (uint8_t *)pvPortMalloc(200); // uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
// if (Buff == NULL) { // if (Buff == NULL) {
@ -60,7 +75,6 @@ static void common_Task(void *pvParameters)
// xQueueSend(upward_uart_Queue, &Buff, 10); // xQueueSend(upward_uart_Queue, &Buff, 10);
// log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
@ -80,7 +94,20 @@ static void common_Task(void *pvParameters)
// xQueueSend(J5_0_485_Queue, &Buff, 10); // xQueueSend(J5_0_485_Queue, &Buff, 10);
vTaskDelay(2000);
/* 每200ms获取一下数据 */
setWorkCurrent(getInCurrent());
setWorkVoltage(getInVoltage());
/* 当内存碎片过多时,后续可以在其中处理 */
if (HeapSizeNum == 25) {
HeapSizeNum = 0;
log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
}
HeapSizeNum++;
vTaskDelayUntil(&xLastWakeTime, xFrequency);
// vTaskDelay(200);
} }
} }
@ -121,6 +148,19 @@ static void DownReceive_Task(void *pvParameters)
} }
} }
/**
* @brief
* @param
* @retval
*/
static void FreeMemory_Task(void *pvParameters)
{
while (1) {
// vTaskDelay(1000);
binarySemaphoreFreeMemory();
}
}
/** /**
* @brief Æô¯ * @brief Æô¯
* @param * @param
@ -128,12 +168,27 @@ static void DownReceive_Task(void *pvParameters)
*/ */
void startApp(void) void startApp(void)
{ {
Init_Upward_uart(115200); // printf("RCC->RSTSCKR = %08x \r\n", RCC->RSTSCKR);
Init_J5_0_485(9600); // RCC->RSTSCKR |= 1<<24;
/* 初始化flash读取配置文件 */
Flash_Init();
readConfigParameter();
FM_GPIO_Init(); FM_GPIO_Init();
FM_ADC_Init(); FM_ADC_Init();
proportionalInt();
Init_Upward_uart(getUpWard_Uart_Baud());
Init_J1_485(getJ1_485_Baud());
Init_J2_485(getJ2_485_Baud());
Init_J3_485(getJ3_485_Baud());
Init_J4_485(getJ4_485_Baud());
Init_J5_0_485(getJ5_0_485_Baud());
uartQueueInit(); uartQueueInit();
binarySemaphoreInit();
softwareTimeInit();
/* create task */ /* create task */
xTaskCreate((TaskFunction_t )common_Task, xTaskCreate((TaskFunction_t )common_Task,
@ -164,6 +219,14 @@ void startApp(void)
(UBaseType_t )DownReceive_TASK_PRIO, (UBaseType_t )DownReceive_TASK_PRIO,
(TaskHandle_t* )&DownReceive_Handler); (TaskHandle_t* )&DownReceive_Handler);
xTaskCreate((TaskFunction_t )FreeMemory_Task,
(const char* )"FreeMemoryTask",
(uint16_t )FreeMemory_STK_SIZE,
(void* )NULL,
(UBaseType_t )FreeMemory_TASK_PRIO,
(TaskHandle_t* )&FreeMemory_Handler);
vTaskStartScheduler(); vTaskStartScheduler();
} }

View File

@ -0,0 +1,184 @@
#include "parameter.h"
#pragma pack(push, 1)
typedef struct _parameterInfo {
float WorkCurrent; //工作电流
float WorkVoltage; //工作电压
float Temperature; //温度
uint32_t upWard_Uart_Baud; //与网关通信波特率
uint32_t J1_485_Baud; //与J1_485通信波特率
uint32_t J2_485_Baud; //与J2_485通信波特率
uint32_t J3_485_Baud; //与J3_485通信波特率
uint32_t J4_485_Baud; //与J4_485通信波特率
uint32_t J5_0_485_Baud; //与J5_0_485通信波特率
}parameterInfo;
#pragma pack(pop)
static parameterInfo parameter;
#define startConfigAddr 0x00
#define configSize (sizeof(configInfo))
/**
* @brief
* @param
* @retval
*/
void readConfigParameter(void)
{
configInfo tempConfig;
read_Flash((uint8_t *)&tempConfig, startConfigAddr, configSize);
/* 配置文件校验通过 */
if (tempConfig.crc == checkModebusCrc((uint8_t *)&tempConfig, configSize - 2)) {
parameter.J1_485_Baud = tempConfig.J1_485_Baud;
parameter.J2_485_Baud = tempConfig.J2_485_Baud;
parameter.J3_485_Baud = tempConfig.J3_485_Baud;
parameter.J4_485_Baud = tempConfig.J4_485_Baud;
parameter.J5_0_485_Baud = tempConfig.J5_0_485_Baud;
parameter.upWard_Uart_Baud = tempConfig.upWard_Uart_Baud;
}
/* 未通过则使用默认参数 */
else {
parameter.J1_485_Baud = 9600;
parameter.J2_485_Baud = 9600;
parameter.J3_485_Baud = 9600;
parameter.J4_485_Baud = 9600;
parameter.J5_0_485_Baud = 9600;
parameter.upWard_Uart_Baud = 115200;
}
}
/**
* @brief
* @param inConfigInfo
* @retval
*/
void writeConfigParameter(configInfo inConfigInfo)
{
write_Flash((uint8_t *)&inConfigInfo, startConfigAddr, configSize);
}
/**
* @brief
* @param
* @retval
*/
float getWorkCurrent(void)
{
return parameter.WorkCurrent;
}
/**
* @brief
* @param
* @retval
*/
void setWorkCurrent(float Curr)
{
parameter.WorkCurrent = Curr;
}
/**
* @brief
* @param
* @retval
*/
float getWorkVoltage(void)
{
return parameter.WorkVoltage;
}
/**
* @brief
* @param
* @retval
*/
void setWorkVoltage(float Voltage)
{
parameter.WorkVoltage = Voltage;
}
/**
* @brief
* @param
* @retval
*/
float getTemperature(void)
{
return parameter.Temperature;
}
/**
* @brief
* @param
* @retval
*/
void setTemperature(float Temperature)
{
parameter.Temperature = Temperature;
}
/**
* @brief
* @param
* @retval
*/
uint32_t getUpWard_Uart_Baud(void)
{
return parameter.upWard_Uart_Baud;
}
/**
* @brief J1通信波特率
* @param
* @retval
*/
uint32_t getJ1_485_Baud(void)
{
return parameter.J1_485_Baud;
}
/**
* @brief J2通信波特率
* @param
* @retval
*/
uint32_t getJ2_485_Baud(void)
{
return parameter.J2_485_Baud;
}
/**
* @brief J3通信波特率
* @param
* @retval
*/
uint32_t getJ3_485_Baud(void)
{
return parameter.J3_485_Baud;
}
/**
* @brief J4通信波特率
* @param
* @retval
*/
uint32_t getJ4_485_Baud(void)
{
return parameter.J4_485_Baud;
}
/**
* @brief J5_0通信波特率
* @param
* @retval
*/
uint32_t getJ5_0_485_Baud(void)
{
return parameter.J5_0_485_Baud;
}

View File

@ -2,6 +2,7 @@
#include "queueUart.h" #include "queueUart.h"
#include "uart_dev.h" #include "uart_dev.h"
#include "busIdleDetection.h" #include "busIdleDetection.h"
#include "semphr.h"
/* 队列中每个消息的大小 */ /* 队列中每个消息的大小 */
#define QUEUE_SIZE 4 #define QUEUE_SIZE 4
@ -13,12 +14,10 @@ QueueHandle_t J3_485_Queue = NULL;
QueueHandle_t J4_485_Queue = NULL; QueueHandle_t J4_485_Queue = NULL;
QueueHandle_t J5_0_485_Queue = NULL; QueueHandle_t J5_0_485_Queue = NULL;
QueueHandle_t upward_uart_Queue = NULL; QueueHandle_t upward_uart_Queue = NULL;
/* 队列集 */ /* 队列集 */
QueueSetHandle_t uart_Queue = NULL; QueueSetHandle_t uart_Queue = NULL;
/* 查看队列集中是否有数据 */ QueueSetMemberHandle_t xActivatedMemberUartQueue;
QueueSetMemberHandle_t xActivatedMember;
/* 通过该结构体接收对应的数据用来发送,结束后通过该结构体,释放数据的内存 */ /* 通过该结构体接收对应的数据用来发送,结束后通过该结构体,释放数据的内存 */
typedef struct _queueRecvDataInfo { typedef struct _queueRecvDataInfo {
@ -91,7 +90,7 @@ void uartQueueSend(void)
static uint8_t flag = 0; static uint8_t flag = 0;
/* 查看队列集中是否有数据 */ /* 查看队列集中是否有数据 */
xActivatedMember = xQueueSelectFromSet(uart_Queue, portMAX_DELAY); xActivatedMemberUartQueue = xQueueSelectFromSet(uart_Queue, portMAX_DELAY);
/* 查看Upward_uart5中有无数据 */ /* 查看Upward_uart5中有无数据 */
if (!getUartState(g_Upward_uart5_handle)) { if (!getUartState(g_Upward_uart5_handle)) {
@ -148,7 +147,7 @@ void uartQueueSend(void)
/* 处理接收到的数据 */ /* 处理接收到的数据 */
if (xQueueReceive(J5_0_485_Queue, &queueRecvData.J5_0_485_data, 0) == pdTRUE) { if (xQueueReceive(J5_0_485_Queue, &queueRecvData.J5_0_485_data, 0) == pdTRUE) {
setConnectPort(queueRecvData.J5_0_485_data->connectPort); setConnectPort(queueRecvData.J5_0_485_data->connectPort);
log_info("send J5_0 Data : %s , %d\n", queueRecvData.J5_0_485_data->data, queueRecvData.J5_0_485_data->length); // 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 uartInterruptSend(g_J5_0_usart3_handle, queueRecvData.J5_0_485_data->data
, queueRecvData.J5_0_485_data->length); , queueRecvData.J5_0_485_data->length);
flag = 1; flag = 1;
@ -163,8 +162,95 @@ void uartQueueSend(void)
flag = 0; flag = 0;
} }
#ifdef UARTINTERRUPTSEND #ifdef UARTINTERRUPTSEND
// 创建队列集
QueueSetHandle_t BinarySemaphoreSet = NULL;
// 创建二值信号量
SemaphoreHandle_t J1_BinarySemaphore = NULL;
SemaphoreHandle_t J2_BinarySemaphore = NULL;
SemaphoreHandle_t J3_BinarySemaphore = NULL;
SemaphoreHandle_t J4_BinarySemaphore = NULL;
SemaphoreHandle_t J5_0_BinarySemaphore = NULL;
SemaphoreHandle_t upward_BinarySemaphore = NULL;
/**
* @brief 便
* @param
* @retval
*/
void binarySemaphoreInit(void)
{
// 初始化队列集
BinarySemaphoreSet = xQueueCreateSet(6);
// 初始化二值信号量
J1_BinarySemaphore = xSemaphoreCreateBinary();
J2_BinarySemaphore = xSemaphoreCreateBinary();
J3_BinarySemaphore = xSemaphoreCreateBinary();
J4_BinarySemaphore = xSemaphoreCreateBinary();
J5_0_BinarySemaphore = xSemaphoreCreateBinary();
upward_BinarySemaphore = xSemaphoreCreateBinary();
// 将二值信号量添加到队列集中
xQueueAddToSet(J1_BinarySemaphore, BinarySemaphoreSet);
xQueueAddToSet(J2_BinarySemaphore, BinarySemaphoreSet);
xQueueAddToSet(J3_BinarySemaphore, BinarySemaphoreSet);
xQueueAddToSet(J4_BinarySemaphore, BinarySemaphoreSet);
xQueueAddToSet(J5_0_BinarySemaphore, BinarySemaphoreSet);
xQueueAddToSet(upward_BinarySemaphore, BinarySemaphoreSet);
}
/**
* @brief
* @param
* @retval
*/
void binarySemaphoreFreeMemory(void)
{
// 等待队列集中的事件
QueueSetMemberHandle_t xActivatedMember = xQueueSelectFromSet(BinarySemaphoreSet, portMAX_DELAY);
if (xActivatedMember == J1_BinarySemaphore) {
// 执行相关逻辑
vPortFree(queueRecvData.J1_485_data);
setJ1_485_SendState(0);
// 处理二值信号量事件
xSemaphoreTake(J1_BinarySemaphore, 0);
}
else if (xActivatedMember == J2_BinarySemaphore) {
vPortFree(queueRecvData.J2_485_data);
setJ2_485_SendState(0);
xSemaphoreTake(J2_BinarySemaphore, 0);
}
else if (xActivatedMember == J3_BinarySemaphore) {
vPortFree(queueRecvData.J3_485_data);
setJ3_485_SendState(0);
xSemaphoreTake(J3_BinarySemaphore, 0);
}
else if (xActivatedMember == J4_BinarySemaphore) {
vPortFree(queueRecvData.J4_485_data);
setJ4_485_SendState(0);
xSemaphoreTake(J4_BinarySemaphore, 0);
}
else if (xActivatedMember == J5_0_BinarySemaphore) {
vPortFree(queueRecvData.J5_0_485_data);
setJ5_0_485_SendState(0);
xSemaphoreTake(J5_0_BinarySemaphore, 0);
}
else if (xActivatedMember == upward_BinarySemaphore) {
vPortFree(queueRecvData.upward_uart_data);
setUpward_uart_SendState(0);
xSemaphoreTake(upward_BinarySemaphore, 0);
}
}
/** /**
* @brief * @brief
* @param * @param
@ -172,37 +258,43 @@ void uartQueueSend(void)
*/ */
void J1_485_IN_TXE(void) void J1_485_IN_TXE(void)
{ {
vPortFree(queueRecvData.J1_485_data); // vPortFree(queueRecvData.J1_485_data);
xSemaphoreGiveFromISR(J1_BinarySemaphore, 0);
} }
void J2_485_IN_TXE(void) void J2_485_IN_TXE(void)
{ {
vPortFree(queueRecvData.J2_485_data); // vPortFree(queueRecvData.J2_485_data);
xSemaphoreGiveFromISR(J2_BinarySemaphore, 0);
} }
void J3_485_IN_TXE(void) void J3_485_IN_TXE(void)
{ {
vPortFree(queueRecvData.J3_485_data); // vPortFree(queueRecvData.J3_485_data);
xSemaphoreGiveFromISR(J3_BinarySemaphore, 0);
} }
void J4_485_IN_TXE(void) void J4_485_IN_TXE(void)
{ {
vPortFree(queueRecvData.J4_485_data); // vPortFree(queueRecvData.J4_485_data);
xSemaphoreGiveFromISR(J4_BinarySemaphore, 0);
} }
void J5_0_485_IN_TXE(void) void J5_0_485_IN_TXE(void)
{ {
vPortFree(queueRecvData.J5_0_485_data); // vPortFree(queueRecvData.J5_0_485_data);
xSemaphoreGiveFromISR(J5_0_BinarySemaphore, 0);
} }
void Upward_USART_IN_TXE(void) void Upward_USART_IN_TXE(void)
{ {
vPortFree(queueRecvData.upward_uart_data); // vPortFree(queueRecvData.upward_uart_data);
xSemaphoreGiveFromISR(upward_BinarySemaphore, 0);
} }
#endif #endif

View File

@ -10,7 +10,7 @@
#include "FM_GPIO.h" #include "FM_GPIO.h"
#include "FM_ADC.h" #include "FM_ADC.h"
#include "queueUart.h" #include "queueUart.h"
#include "parameter.h"
@ -35,31 +35,6 @@
/* 1分钟的节拍数 */ /* 1分钟的节拍数 */
#define tick_1M (configTICK_RATE_HZ * 60) #define tick_1M (configTICK_RATE_HZ * 60)
/* 功能码 */
typedef enum {
SL_Function_Code_Read_Register = 0x30, /* 读寄存器数据 */
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
SL_Function_Code_Distribution_Profile = 0xD0, /* 配置文件下发 */
SL_Function_Code_Read_Profile = 0xD1, /* 配置文件读取 */
}SL_MsgFunctionCode;
/* 寄存器地址 */
typedef enum {
GW_Register_WorkCurrent = 0x0000,
GW_Register_WorkVoltage = 0x0001,
GW_Register_Temperature = 0x0002,
GW_Register_Port1_Power = 0x0003,
GW_Register_Port2_Power = 0x0004,
GW_Register_Port3_Power = 0x0005,
GW_Register_Port4_Power = 0x0006,
GW_Register_Port5_Power = 0x0007,
GW_Register_Port6_Power = 0x0008,
GW_Register_Port7_Power = 0x0009,
GW_Register_Port8_Power = 0x000A,
GW_Register_Port9_Power = 0x000B,
}SL_GateWay_MsgRegister;
/* 配置文件数据类型表 */ /* 配置文件数据类型表 */
typedef enum { typedef enum {
/* (1字节)对智能模块通信波特率(00H不使用该串口,01H4800;02H9600;03H19200;04H38400;05H57600;06H115200) */ /* (1字节)对智能模块通信波特率(00H不使用该串口,01H4800;02H9600;03H19200;04H38400;05H57600;06H115200) */
@ -136,16 +111,6 @@ static void GW_MsgProcFunc_Distribution_Profile(device_handle device, void *pMsg
static void GW_MsgProcFunc_Read_Profile(device_handle device, void *pMsg, uint32_t MsgLen); static void GW_MsgProcFunc_Read_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
/* 寄存器处理表 */ /* 寄存器处理表 */
typedef uint16_t (*RegProcFunc)(void*); typedef uint16_t (*RegProcFunc)(void*);
typedef struct _SL_RegProcTable{ typedef struct _SL_RegProcTable{
@ -214,7 +179,7 @@ SL_RegProcTable g_RegTblW[] =
*/ */
uint16_t ReadRegisterWorkCurrent(void *pMsg) uint16_t ReadRegisterWorkCurrent(void *pMsg)
{ {
return 0; return (uint16_t)(getWorkCurrent() * 10);
} }
/** /**
@ -224,7 +189,7 @@ uint16_t ReadRegisterWorkCurrent(void *pMsg)
*/ */
uint16_t ReadRegisterWorkVoltage(void *pMsg) uint16_t ReadRegisterWorkVoltage(void *pMsg)
{ {
return 0; return (uint16_t)(getWorkVoltage() * 10);
} }
/** /**
@ -234,7 +199,7 @@ uint16_t ReadRegisterWorkVoltage(void *pMsg)
*/ */
uint16_t ReadRegisterTemperature(void *pMsg) uint16_t ReadRegisterTemperature(void *pMsg)
{ {
return 0; return (uint16_t)(getTemperature() * 10);
} }
/** /**
@ -904,6 +869,11 @@ uint8_t analysisEndFlagSL(void)
uint32_t tempLen = 0; uint32_t tempLen = 0;
tempLen = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4]; tempLen = (gw485RxBuffer[3] << 8) | gw485RxBuffer[4];
//系统内存不足,丢去当前包
if (xPortGetFreeHeapSize() < tempLen + 1024) {
goto err;
}
/* 对于不同通端口,传输的结构体不同 */ /* 对于不同通端口,传输的结构体不同 */
uint8_t *Buff; uint8_t *Buff;
if (gw485RxBuffer[2] > 0 && gw485RxBuffer[2] < 5) { if (gw485RxBuffer[2] > 0 && gw485RxBuffer[2] < 5) {
@ -986,6 +956,7 @@ uint8_t analysisEndFlagSL(void)
} }
} }
err:
//清零buff //清零buff
state = wait; state = wait;
gw485RxBufferIndex = 0; gw485RxBufferIndex = 0;
@ -1013,7 +984,12 @@ void GW_MsgProcFunc_Read_Register(device_handle device,uint8_t *buff, uint16_t b
} }
/* 初始化发送内存 */ /* 初始化发送内存 */
uint8_t *Buff = (uint8_t *)pvPortMalloc(8 + 2 * Register_Number_16 + queueUartSendInfoSize); //系统内存不足,丢去当前包
uint32_t tempLen = 8 + 2 * Register_Number_16 + queueUartSendInfoSize;
if (xPortGetFreeHeapSize() < tempLen + 1024) {
return;
}
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff; queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
sendBuff->length = 8 + 2 * Register_Number_16; sendBuff->length = 8 + 2 * Register_Number_16;
sendBuff->data = Buff + sizeof(queueUartSendInfo); sendBuff->data = Buff + sizeof(queueUartSendInfo);

View File

@ -93,6 +93,13 @@ void setBUSIDLEFlag(device_handle device, uint8_t state);
// void setSoftwareIDLEFlag(device_handle device, uint8_t state); // void setSoftwareIDLEFlag(device_handle device, uint8_t state);
#endif #endif
void setJ1_485_SendState(uint8_t state);
void setJ2_485_SendState(uint8_t state);
void setJ3_485_SendState(uint8_t state);
void setJ4_485_SendState(uint8_t state);
void setJ5_0_485_SendState(uint8_t state);
void setUpward_uart_SendState(uint8_t state);
/* J5_0连接到哪个端口 */ /* J5_0连接到哪个端口 */
typedef enum _connectPortEnum { typedef enum _connectPortEnum {
connectJ0 = 1, connectJ0 = 1,

View File

@ -41,18 +41,18 @@ uint8_t Upward_inBuff[UpwardBuffLen];
#define Upward_uart_Send 0x40 #define Upward_uart_Send 0x40
static uint8_t uartInterruptSendFlag = 0; static uint8_t uartInterruptSendFlag = 0;
// static uint8_t getJ1_485_SendState(void); // // static uint8_t getJ1_485_SendState(void);
static void setJ1_485_SendState(uint8_t state); // static void setJ1_485_SendState(uint8_t state);
// static uint8_t getJ2_485_SendState(void); // // static uint8_t getJ2_485_SendState(void);
static void setJ2_485_SendState(uint8_t state); // static void setJ2_485_SendState(uint8_t state);
// static uint8_t getJ3_485_SendState(void); // // static uint8_t getJ3_485_SendState(void);
static void setJ3_485_SendState(uint8_t state); // static void setJ3_485_SendState(uint8_t state);
// static uint8_t getJ4_485_SendState(void); // // static uint8_t getJ4_485_SendState(void);
static void setJ4_485_SendState(uint8_t state); // static void setJ4_485_SendState(uint8_t state);
// static uint8_t getJ5_0_485_SendState(void); // // static uint8_t getJ5_0_485_SendState(void);
static void setJ5_0_485_SendState(uint8_t state); // static void setJ5_0_485_SendState(uint8_t state);
// static uint8_t getUpward_uart_SendState(void); // // static uint8_t getUpward_uart_SendState(void);
static void setUpward_uart_SendState(uint8_t state); // static void setUpward_uart_SendState(uint8_t state);
#ifdef RS485BUSIDLE1 #ifdef RS485BUSIDLE1
@ -488,7 +488,7 @@ void J3_Interrupt()
uart_device_info *dev = (uart_device_info *)g_J3_usart2_handle; uart_device_info *dev = (uart_device_info *)g_J3_usart2_handle;
if (dev->uart_send_data.count >= dev->uart_send_data.len) { if (dev->uart_send_data.count >= dev->uart_send_data.len) {
USART_ITConfig(J3_USART, USART_IT_TXE, DISABLE); USART_ITConfig(J3_USART, USART_IT_TXE, DISABLE);
setJ3_485_SendState(0); // setJ3_485_SendState(0);
J3_485_IN_TXE(); J3_485_IN_TXE();
readJ3_485; readJ3_485;
return; return;
@ -527,7 +527,7 @@ void J5_0_Interrupt()
uart_device_info *dev = (uart_device_info *)g_J5_0_usart3_handle; uart_device_info *dev = (uart_device_info *)g_J5_0_usart3_handle;
if (dev->uart_send_data.count >= dev->uart_send_data.len) { if (dev->uart_send_data.count >= dev->uart_send_data.len) {
USART_ITConfig(J5_0_USART, USART_IT_TXE, DISABLE); USART_ITConfig(J5_0_USART, USART_IT_TXE, DISABLE);
setJ5_0_485_SendState(0); // setJ5_0_485_SendState(0);
J5_0_485_IN_TXE(); J5_0_485_IN_TXE();
readJ5_0_485; readJ5_0_485;
return; return;
@ -561,7 +561,7 @@ void Upward_Interrupt()
// log_info("%d \n", dev->uart_send_data.count); // log_info("%d \n", dev->uart_send_data.count);
if (dev->uart_send_data.count >= dev->uart_send_data.len) { if (dev->uart_send_data.count >= dev->uart_send_data.len) {
USART_ITConfig(Upward_USART, USART_IT_TXE, DISABLE); USART_ITConfig(Upward_USART, USART_IT_TXE, DISABLE);
setUpward_uart_SendState(0); // setUpward_uart_SendState(0);
Upward_USART_IN_TXE(); Upward_USART_IN_TXE();
return; return;
} }
@ -592,7 +592,7 @@ void J1_Interrupt()
uart_device_info *dev = (uart_device_info *)g_J1_uart6_handle; uart_device_info *dev = (uart_device_info *)g_J1_uart6_handle;
if (dev->uart_send_data.count >= dev->uart_send_data.len) { if (dev->uart_send_data.count >= dev->uart_send_data.len) {
USART_ITConfig(J1_USART, USART_IT_TXE, DISABLE); USART_ITConfig(J1_USART, USART_IT_TXE, DISABLE);
setJ1_485_SendState(0); // setJ1_485_SendState(0);
J1_485_IN_TXE(); J1_485_IN_TXE();
readJ1_485; readJ1_485;
return; return;
@ -631,7 +631,7 @@ void J2_Interrupt()
uart_device_info *dev = (uart_device_info *)g_J2_uart7_handle; uart_device_info *dev = (uart_device_info *)g_J2_uart7_handle;
if (dev->uart_send_data.count >= dev->uart_send_data.len) { if (dev->uart_send_data.count >= dev->uart_send_data.len) {
USART_ITConfig(J2_USART, USART_IT_TXE, DISABLE); USART_ITConfig(J2_USART, USART_IT_TXE, DISABLE);
setJ2_485_SendState(0); // setJ2_485_SendState(0);
J2_485_IN_TXE(); J2_485_IN_TXE();
readJ2_485; readJ2_485;
return; return;
@ -670,7 +670,7 @@ void J4_Interrupt()
uart_device_info *dev = (uart_device_info *)g_J4_uart8_handle; uart_device_info *dev = (uart_device_info *)g_J4_uart8_handle;
if (dev->uart_send_data.count >= dev->uart_send_data.len) { if (dev->uart_send_data.count >= dev->uart_send_data.len) {
USART_ITConfig(J4_USART, USART_IT_TXE, DISABLE); USART_ITConfig(J4_USART, USART_IT_TXE, DISABLE);
setJ4_485_SendState(0); // setJ4_485_SendState(0);
J4_485_IN_TXE(); J4_485_IN_TXE();
readJ4_485; readJ4_485;
return; return;
@ -712,31 +712,37 @@ uint8_t uartInterruptSend(device_handle device,uint8_t *data, uint16_t len)
/* 开始发送 */ /* 开始发送 */
if (device == g_J1_uart6_handle) { if (device == g_J1_uart6_handle) {
setJ1_485_SendState(1);
writeJ1_485; writeJ1_485;
USART_ITConfig(J1_USART, USART_IT_TXE, ENABLE); USART_ITConfig(J1_USART, USART_IT_TXE, ENABLE);
USART_SendData(J1_USART, dev->uart_send_data.data[dev->uart_send_data.count++]); USART_SendData(J1_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
} }
else if (device == g_J2_uart7_handle) { else if (device == g_J2_uart7_handle) {
setJ2_485_SendState(1);
writeJ2_485; writeJ2_485;
USART_ITConfig(J2_USART, USART_IT_TXE, ENABLE); USART_ITConfig(J2_USART, USART_IT_TXE, ENABLE);
USART_SendData(J2_USART, dev->uart_send_data.data[dev->uart_send_data.count++]); USART_SendData(J2_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
} }
else if (device == g_J3_usart2_handle) { else if (device == g_J3_usart2_handle) {
setJ3_485_SendState(1);
writeJ3_485; writeJ3_485;
USART_ITConfig(J3_USART, USART_IT_TXE, ENABLE); USART_ITConfig(J3_USART, USART_IT_TXE, ENABLE);
USART_SendData(J3_USART, dev->uart_send_data.data[dev->uart_send_data.count++]); USART_SendData(J3_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
} }
else if (device == g_J4_uart8_handle) { else if (device == g_J4_uart8_handle) {
setJ4_485_SendState(1);
writeJ4_485; writeJ4_485;
USART_ITConfig(J4_USART, USART_IT_TXE, ENABLE); USART_ITConfig(J4_USART, USART_IT_TXE, ENABLE);
USART_SendData(J4_USART, dev->uart_send_data.data[dev->uart_send_data.count++]); USART_SendData(J4_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
} }
else if (device == g_J5_0_usart3_handle) { else if (device == g_J5_0_usart3_handle) {
setJ5_0_485_SendState(1);
writeJ5_0_485; writeJ5_0_485;
USART_ITConfig(J5_0_USART, USART_IT_TXE, ENABLE); USART_ITConfig(J5_0_USART, USART_IT_TXE, ENABLE);
USART_SendData(J5_0_USART, dev->uart_send_data.data[dev->uart_send_data.count++]); USART_SendData(J5_0_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
} }
else if (device == g_Upward_uart5_handle) { else if (device == g_Upward_uart5_handle) {
setUpward_uart_SendState(1);
USART_ITConfig(Upward_USART, USART_IT_TXE, ENABLE); USART_ITConfig(Upward_USART, USART_IT_TXE, ENABLE);
USART_SendData(Upward_USART, dev->uart_send_data.data[dev->uart_send_data.count++]); USART_SendData(Upward_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
} }

View File

@ -74,7 +74,7 @@
/* user */ /* user */
#define configUSE_QUEUE_SETS 1 #define configUSE_QUEUE_SETS 1
#define configUSE_BINARY_SEMAPHORES 1
/*----------------------------------------------------------- /*-----------------------------------------------------------
* Application specific definitions. * Application specific definitions.
@ -100,7 +100,7 @@
#define configCPU_CLOCK_HZ SystemCoreClock #define configCPU_CLOCK_HZ SystemCoreClock
#define configTICK_RATE_HZ ( ( TickType_t ) 500 ) #define configTICK_RATE_HZ ( ( TickType_t ) 500 )
// #define configMAX_PRIORITIES ( 15 ) // #define configMAX_PRIORITIES ( 15 )
#define configMAX_PRIORITIES ( 5 ) #define configMAX_PRIORITIES ( 10 )
#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 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 ) ( 12 * 1024 ) )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 24 * 1024 ) ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 24 * 1024 ) )

View File

@ -37,7 +37,10 @@ void NMI_Handler(void)
*/ */
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
NVIC_SystemReset(); // NVIC_SystemReset();
printf("mepc:%08x\n",__get_MEPC());
printf("mcause:%08x\n",__get_MCAUSE());
printf("mtval:%08x\n",__get_MTVAL());
while (1) while (1)
{ {
} }

View File

@ -45,5 +45,6 @@ int main(void)
while(1) { while(1) {
printf("shouldn't run at here!!\n"); printf("shouldn't run at here!!\n");
Delay_Ms(1000);
} }
} }

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

Binary file not shown.

View File

@ -97,6 +97,22 @@ uint8_t *Buff = (uint8_t *)pvPortMalloc(200);
## 串口接法流程
串口中断接收数据接收到的数据放入缓冲buff中当前为总线空闲状态时接收到数据后立即总线为繁忙状态并关闭软件定时器
串口发送数据前检查总线空闲状态和上次发送是否完成,总线空闲和上次发送完成,才能发送下次数据
中断发送数据,每发送一次数据则进入中断塞入下次发送的数据,当数据最后一个字节塞入完成后,设置二值信号量
二值信号量在任务中设置为队列集有数据后设置发送完成释放发送数据使用的buff
串口进入空闲中断后,使能软件定时器,定时到达后,设置总线空闲
## 串口接收传感器数据