初步完成主从mcu软件设计,未调试
This commit is contained in:
parent
4f7d2bd49b
commit
31bfb45fd1
|
@ -142,7 +142,8 @@
|
|||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/App/tools}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/App/tools/RingQueue}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/App/functionalModule/Inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/App/application/Inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/App/application/Host/Inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/App/application/Slave/Inc}""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.systempaths.2011720354" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.systempaths" useByScannerDiscovery="true" valueType="includePath"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files.542153928" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
|
||||
|
|
|
@ -30,5 +30,21 @@
|
|||
<arguments>1.0-name-matches-false-false-*.wvproj</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<name>App/application/Host/Inc</name>
|
||||
<type>6</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-slaveFreerotsTask.h</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
<filter>
|
||||
<name>App/application/Host/Src</name>
|
||||
<type>6</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-slaveFreerotsTask.c</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef _APP_HOST_BUS_IDLE_DETECTION_H_
|
||||
#define _APP_HOST_BUS_IDLE_DETECTION_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "event_groups.h"
|
||||
#include "semphr.h"
|
||||
|
||||
extern SemaphoreHandle_t J0_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J2_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J4_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J6_IDLESemaphore;
|
||||
|
||||
void hostIdleInit(void);
|
||||
|
||||
void J0_485_IN_IDLE(void);
|
||||
void J2_485_IN_IDLE(void);
|
||||
void J4_485_IN_IDLE(void);
|
||||
void J6_485_IN_IDLE(void);
|
||||
|
||||
void J0_485_IN_RXNE(void);
|
||||
void J2_485_IN_RXNE(void);
|
||||
void J4_485_IN_RXNE(void);
|
||||
void J6_485_IN_RXNE(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef APP_HOST_FREERTOS_TASK_H_
|
||||
#define APP_HOST_FREERTOS_TASK_H_
|
||||
|
||||
#include "pDebug.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
void hostStartApp(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _APP_HOST_MCU_COMM_H_
|
||||
#define _APP_HOST_MCU_COMM_H_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
void hostFrameDataAnalyze(uint8_t *buff, uint8_t dataLen);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef _APP_HOST_MCU_DATA_PARSE_H_
|
||||
#define _APP_HOST_MCU_DATA_PARSE_H_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
#include "hostQueueUart.h"
|
||||
|
||||
void hostMcuUartDataAnalysis(device_handle device);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef APP_HOST_PARAMETER_H_
|
||||
#define APP_HOST_PARAMETER_H_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
//通过该格式存入flash中
|
||||
typedef struct _configInfo {
|
||||
uint32_t J1_485_Baud; //与J1_485通信波特率
|
||||
uint32_t J3_485_Baud; //与J3_485通信波特率
|
||||
uint32_t J5_485_Baud; //与J5_485通信波特率
|
||||
uint32_t J7_485_Baud; //与J7_485通信波特率
|
||||
uint32_t J8_485_Baud; //与J8_485通信波特率
|
||||
uint32_t J9_485_Baud; //与J9_485通信波特率
|
||||
|
||||
uint16_t crc; //crc校验
|
||||
} hostConfigInfo;
|
||||
|
||||
void readHostConfigParameter(void);
|
||||
// void writeConfigParameter(configInfo inConfigInfo);
|
||||
|
||||
float getPwrOnVoltage(void);
|
||||
void setPwrOnVoltage(float Voltage);
|
||||
float getWorkCurrent(void);
|
||||
void setWorkCurrent(float Curr);
|
||||
float getWorkVoltage(void);
|
||||
void setWorkVoltage(float Voltage);
|
||||
float getBoardTemperature(void);
|
||||
void setBoardTemperature(float Temperature);
|
||||
uint32_t getJ0_485_Baud(void);
|
||||
void setJ0_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ2_485_Baud(void);
|
||||
void setJ2_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ4_485_Baud(void);
|
||||
void setJ4_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ6_485_Baud(void);
|
||||
void setJ6_485_Baud(uint32_t Baud);
|
||||
uint32_t getLora_Uart_Baud(void);
|
||||
void setLora_Uart_Baud(uint32_t Baud);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#ifndef _APP_HOST_QUEUE_UART_H_
|
||||
#define _APP_HOST_QUEUE_UART_H_
|
||||
|
||||
#include "pDebug.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
/* 存入队列中的数据格式 */
|
||||
typedef struct _hostQueueUartSendInfo{
|
||||
uint32_t length; //数据长度
|
||||
uint8_t *data; //数据
|
||||
} hostQueueUartSendInfo;
|
||||
#define hostQueueUartSendInfoSize sizeof(hostQueueUartSendInfo)
|
||||
|
||||
extern QueueHandle_t J0_485_Queue;
|
||||
extern QueueHandle_t J2_485_Queue;
|
||||
extern QueueHandle_t J4_485_Queue;
|
||||
extern QueueHandle_t J6_485_Queue;
|
||||
extern QueueHandle_t lora_uart_Queue;
|
||||
extern QueueHandle_t su806_uart_Queue;
|
||||
extern QueueHandle_t hostMcu_uart_Queue;
|
||||
|
||||
uint8_t hostUartInterruptSend(device_handle device, uint8_t *data, uint16_t len);
|
||||
|
||||
void hostUartSendInit(void);
|
||||
|
||||
void hostBinarySemaphoreFreeMemory(void);
|
||||
|
||||
void J0QueueSend(void);
|
||||
void J2QueueSend(void);
|
||||
void J4QueueSend(void);
|
||||
void J6QueueSend(void);
|
||||
void LoraQueueSend(void);
|
||||
void Su806QueueSend(void);
|
||||
void HostMcuQueueSend(void);
|
||||
|
||||
void J0_485_IN_TXE(void);
|
||||
void J2_485_IN_TXE(void);
|
||||
void J4_485_IN_TXE(void);
|
||||
void J6_485_IN_TXE(void);
|
||||
void Lora_uart_IN_TXE(void);
|
||||
void Su806_uart_IN_TXE(void);
|
||||
void hostMcu_uart_IN_TXE(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _APP_HOST_RECV_SLAVE_DATA_PARSE_H_
|
||||
#define _APP_HOST_RECV_SLAVE_DATA_PARSE_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
void hostRecvSlaveDataParse(device_handle device);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _APP_HOST_SENSOR_DATA_PARSE_H_
|
||||
#define _APP_HOST_SENSOR_DATA_PARSE_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
void J0_SensorDataAnalysis(void);
|
||||
void J2_SensorDataAnalysis(void);
|
||||
void J4_SensorDataAnalysis(void);
|
||||
void J6_SensorDataAnalysis(void);
|
||||
void Lora_SensorDataAnalysis(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
void startApp(void);
|
||||
void slaveStartApp(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,124 @@
|
|||
|
||||
#include "hostBusIdleDetection.h"
|
||||
|
||||
static TimerHandle_t J0_485_Swtmr = NULL;
|
||||
static TimerHandle_t J2_485_Swtmr = NULL;
|
||||
static TimerHandle_t J4_485_Swtmr = NULL;
|
||||
static TimerHandle_t J6_485_Swtmr = NULL;
|
||||
|
||||
static void J0_485_tmrCallback(void* parameter);
|
||||
static void J2_485_tmrCallback(void* parameter);
|
||||
static void J4_485_tmrCallback(void* parameter);
|
||||
static void J6_485_tmrCallback(void* parameter);
|
||||
|
||||
// 创建二值信号量
|
||||
SemaphoreHandle_t J0_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J2_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J4_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J6_IDLESemaphore = NULL;
|
||||
|
||||
#define softwareDelay (30 / (1000 / configTICK_RATE_HZ))
|
||||
|
||||
void hostIdleInit(void)
|
||||
{
|
||||
J0_485_Swtmr = xTimerCreate((const char*)"J0Timer",
|
||||
softwareDelay, //延时
|
||||
(UBaseType_t )pdFALSE, //单次模式
|
||||
(void *)1, //为每个计时器分配一个索引的唯一ID
|
||||
(TimerCallbackFunction_t)J0_485_tmrCallback); //回调函数
|
||||
|
||||
J2_485_Swtmr = xTimerCreate((const char*)"J2Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J2_485_tmrCallback);
|
||||
|
||||
J4_485_Swtmr = xTimerCreate((const char*)"J4Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J4_485_tmrCallback);
|
||||
|
||||
J6_485_Swtmr = xTimerCreate((const char*)"J6Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J6_485_tmrCallback);
|
||||
|
||||
J0_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J0_IDLESemaphore);
|
||||
J2_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J2_IDLESemaphore);
|
||||
J4_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J4_IDLESemaphore);
|
||||
J6_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J6_IDLESemaphore);
|
||||
}
|
||||
|
||||
void J0_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J0_IDLESemaphore, 0);
|
||||
}
|
||||
void J2_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J2_IDLESemaphore, 0);
|
||||
}
|
||||
void J4_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J4_IDLESemaphore, 0);
|
||||
}
|
||||
void J6_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J6_IDLESemaphore, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J0_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J0_485_Swtmr, 0);
|
||||
}
|
||||
void J2_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J2_485_Swtmr, 0);
|
||||
}
|
||||
void J4_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J4_485_Swtmr, 0);
|
||||
}
|
||||
void J6_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J6_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J0_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J0_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J0_IDLESemaphore, 0);
|
||||
}
|
||||
void J2_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J2_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J2_IDLESemaphore, 0);
|
||||
}
|
||||
void J4_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J4_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J4_IDLESemaphore, 0);
|
||||
}
|
||||
void J6_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J6_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J6_IDLESemaphore, 0);
|
||||
}
|
||||
|
|
@ -0,0 +1,337 @@
|
|||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "FM_ADC.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
#include "hostFreerotsTask.h"
|
||||
#include "hostBusIdleDetection.h"
|
||||
#include "hostMcuComm.h"
|
||||
#include "hostMcuDataParse.h"
|
||||
#include "hostRecvSlaveDataParse.h"
|
||||
#include "hostSensorDataParse.h"
|
||||
#include "hostQueueUart.h"
|
||||
#include "hostParameter.h"
|
||||
|
||||
/* 发送任务 */
|
||||
#define J0_Transmit_TASK_PRIO 7
|
||||
#define J0_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J0_TransmitTask_Handler;
|
||||
static void J0_transmit_Task(void *pvParameters);
|
||||
#define J2_Transmit_TASK_PRIO 7
|
||||
#define J2_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J2_TransmitTask_Handler;
|
||||
static void J2_transmit_Task(void *pvParameters);
|
||||
#define J4_Transmit_TASK_PRIO 7
|
||||
#define J4_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J4_TransmitTask_Handler;
|
||||
static void J4_transmit_Task(void *pvParameters);
|
||||
#define J6_Transmit_TASK_PRIO 7
|
||||
#define J6_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J6_TransmitTask_Handler;
|
||||
static void J6_transmit_Task(void *pvParameters);
|
||||
#define Lora_Transmit_TASK_PRIO 7
|
||||
#define Lora_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t Lora_TransmitTask_Handler;
|
||||
static void Lora_transmit_Task(void *pvParameters);
|
||||
#define Su806_Transmit_TASK_PRIO 7
|
||||
#define Su806_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t Su806_TransmitTask_Handler;
|
||||
static void Su806_transmit_Task(void *pvParameters);
|
||||
#define HostMcu_Transmit_TASK_PRIO 7
|
||||
#define HostMcu_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t HostMcu_TransmitTask_Handler;
|
||||
static void HostMcu_transmit_Task(void *pvParameters);
|
||||
|
||||
/* 释放内存任务 */
|
||||
#define hostFreeMemory_TASK_PRIO 8
|
||||
#define hostFreeMemory_STK_SIZE 64
|
||||
static TaskHandle_t hostFreeMemory_Handler;
|
||||
static void hostFreeMemory_Task(void *pvParameters);
|
||||
|
||||
/* 解析任务 */
|
||||
#define hostMcuDataParse_TASK_PRIO 5
|
||||
#define hostMcuDataParse_STK_SIZE 512
|
||||
static TaskHandle_t hostMcuDataParse_Handler;
|
||||
static void hostMcuDataParse_Task(void *pvParameters);
|
||||
|
||||
#define hostSensorDataParse_TASK_PRIO 5
|
||||
#define hostSensorDataParse_STK_SIZE 512
|
||||
static TaskHandle_t hostSensorDataParse_Handler;
|
||||
static void hostSensorDataParse_Task(void *pvParameters);
|
||||
|
||||
#define hostRecvSlaveDataParse_TASK_PRIO 5
|
||||
#define hostRecvSlaveDataParse_STK_SIZE 512
|
||||
static TaskHandle_t hostRecvSlaveDataParse_Handler;
|
||||
static void hostRecvSlaveDataParse_Task(void *pvParameters);
|
||||
|
||||
/* 数据采集任务 */
|
||||
#define dataCollection_TASK_PRIO 4
|
||||
#define dataCollection_STK_SIZE 128
|
||||
static TaskHandle_t dataCollection_Handler;
|
||||
static void dataCollection_Task(void *pvParameters);
|
||||
|
||||
/* 其他任务 */
|
||||
#define hostOther_TASK_PRIO 2
|
||||
#define hostOther_STK_SIZE 128
|
||||
static TaskHandle_t hostOther_Handler;
|
||||
static void hostOther_Task(void *pvParameters);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将数据发送
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J0_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J0QueueSend();
|
||||
}
|
||||
}
|
||||
void J2_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J2QueueSend();
|
||||
}
|
||||
}
|
||||
void J4_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J4QueueSend();
|
||||
}
|
||||
}
|
||||
void J6_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J6QueueSend();
|
||||
}
|
||||
}
|
||||
void Lora_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
LoraQueueSend();
|
||||
}
|
||||
}
|
||||
void Su806_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
Su806QueueSend();
|
||||
}
|
||||
}
|
||||
void HostMcu_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
HostMcuQueueSend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 释放内存任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostFreeMemory_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
hostBinarySemaphoreFreeMemory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析su806传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostMcuDataParse_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
hostMcuUartDataAnalysis(g_Su806_handle);
|
||||
vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析传感器传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostSensorDataParse_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J0_SensorDataAnalysis();
|
||||
J2_SensorDataAnalysis();
|
||||
J4_SensorDataAnalysis();
|
||||
J6_SensorDataAnalysis();
|
||||
Lora_SensorDataAnalysis();
|
||||
vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析从mcu传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostRecvSlaveDataParse_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
hostRecvSlaveDataParse(g_Mcu_handle);
|
||||
vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 数据采集任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void dataCollection_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
setBoardTemperature(getTemperature());
|
||||
setWorkVoltage(getInVoltage());
|
||||
setWorkCurrent(getInCurrent());
|
||||
setPwrOnVoltage(getSOCPwrOnVoltage());
|
||||
vTaskDelay(500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 其他任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostOther_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostStartApp(void)
|
||||
{
|
||||
HostMcu_GPIO_Init();
|
||||
readHostConfigParameter();
|
||||
HostMcu_uartBuf_Init(256, 256, 256, 1024);
|
||||
Init_J0_485(getJ0_485_Baud());
|
||||
Init_J2_485(getJ2_485_Baud());
|
||||
Init_J4_485(getJ4_485_Baud());
|
||||
Init_J6_485(getJ6_485_Baud());
|
||||
Init_Lora_Uart(getLora_Uart_Baud());
|
||||
Init_Mcu_Uart(115200);
|
||||
Init_Su806_Uart(115200);
|
||||
|
||||
FM_ADC_Init();
|
||||
proportionalInt();
|
||||
|
||||
applyDataBuffer();
|
||||
hostUartSendInit();
|
||||
hostIdleInit();
|
||||
HostMcu_485DE_Read();
|
||||
|
||||
/* create task */
|
||||
xTaskCreate((TaskFunction_t )J0_transmit_Task,
|
||||
(const char* )"J0TransmitTask",
|
||||
(uint16_t )J0_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J0_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J0_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J2_transmit_Task,
|
||||
(const char* )"J2TransmitTask",
|
||||
(uint16_t )J2_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J2_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J2_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J4_transmit_Task,
|
||||
(const char* )"J4TransmitTask",
|
||||
(uint16_t )J4_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J4_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J4_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J6_transmit_Task,
|
||||
(const char* )"J6TransmitTask",
|
||||
(uint16_t )J6_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J6_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J6_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )Lora_transmit_Task,
|
||||
(const char* )"LoraTransmitTask",
|
||||
(uint16_t )Lora_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )Lora_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&Lora_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )Su806_transmit_Task,
|
||||
(const char* )"Su806TransmitTask",
|
||||
(uint16_t )Su806_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )Su806_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&Su806_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )HostMcu_transmit_Task,
|
||||
(const char* )"HostMcuTransmitTask",
|
||||
(uint16_t )HostMcu_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )HostMcu_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&HostMcu_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )hostFreeMemory_Task,
|
||||
(const char* )"hostFreeMemoryTask",
|
||||
(uint16_t )hostFreeMemory_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )hostFreeMemory_TASK_PRIO,
|
||||
(TaskHandle_t* )&hostFreeMemory_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )hostMcuDataParse_Task,
|
||||
(const char* )"hostMcuDataTask",
|
||||
(uint16_t )hostMcuDataParse_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )hostMcuDataParse_TASK_PRIO,
|
||||
(TaskHandle_t* )&hostMcuDataParse_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )hostSensorDataParse_Task,
|
||||
(const char* )"hostSensorDataTask",
|
||||
(uint16_t )hostSensorDataParse_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )hostSensorDataParse_TASK_PRIO,
|
||||
(TaskHandle_t* )&hostSensorDataParse_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )hostRecvSlaveDataParse_Task,
|
||||
(const char* )"hostRecvSlaveDataTask",
|
||||
(uint16_t )hostRecvSlaveDataParse_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )hostRecvSlaveDataParse_TASK_PRIO,
|
||||
(TaskHandle_t* )&hostRecvSlaveDataParse_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )dataCollection_Task,
|
||||
(const char* )"dataCollectionTask",
|
||||
(uint16_t )dataCollection_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )dataCollection_TASK_PRIO,
|
||||
(TaskHandle_t* )&dataCollection_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )hostOther_Task,
|
||||
(const char* )"hostOtherTask",
|
||||
(uint16_t )hostOther_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )hostOther_TASK_PRIO,
|
||||
(TaskHandle_t* )&hostOther_Handler);
|
||||
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
|
|
@ -0,0 +1,581 @@
|
|||
|
||||
#include "hostMcuComm.h"
|
||||
#include "hostQueueUart.h"
|
||||
#include "hostParameter.h"
|
||||
|
||||
#include "uart_dev.h"
|
||||
#include "FM_GPIO.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
/* 配置文件数据类型表 */
|
||||
enum {
|
||||
workCurrent = 0x0000,
|
||||
workVoltage = 0x0001,
|
||||
workTemperature = 0x0002,
|
||||
J1_Power = 0x0003,
|
||||
J2_Power = 0x0004,
|
||||
J3_Power = 0x0005,
|
||||
J4_Power = 0x0006,
|
||||
J5_Power = 0x0007,
|
||||
J6_Power = 0x0008,
|
||||
J7_Power = 0x0009,
|
||||
J8_Power = 0x000A,
|
||||
J9_Power = 0x000B,
|
||||
/* (1字节)对智能模块通信波特率(00H:不使用该串口, 01H:4800;02H:9600;03H:19200;04H:38400;05H:57600;06H:115200) */
|
||||
J0_485_Communication_Baud_Rate = 0x000C,
|
||||
J2_485_Communication_Baud_Rate = 0x000D,
|
||||
J4_485_Communication_Baud_Rate = 0x000E,
|
||||
J6_485_Communication_Baud_Rate = 0x000F,
|
||||
Lora_uart_Communication_Baud_Rate = 0x0010,
|
||||
};
|
||||
|
||||
|
||||
/* 寄存器解析 */
|
||||
static uint16_t ReadRegisterWorkCurrent(void *pMsg);
|
||||
static uint16_t ReadRegisterWorkVoltage(void *pMsg);
|
||||
static uint16_t ReadRegisterWorkTemperature(void *pMsg);
|
||||
static uint16_t ReadRegisterJ1_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ2_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ3_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ4_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ5_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ6_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ7_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ8_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ9_Power(void *pMsg);
|
||||
static uint16_t ReadRegisterJ0Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ2Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ4Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ6Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterLoraBaud(void *pMsg);
|
||||
|
||||
static uint16_t WriteRegisterJ1_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ2_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ3_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ4_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ5_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ6_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ7_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ8_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ9_Power(void *pMsg);
|
||||
static uint16_t WriteRegisterJ0Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ2Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ4Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ6Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterLoraBaud(void *pMsg);
|
||||
|
||||
/* 寄存器处理表 */
|
||||
typedef uint16_t (*RegProcFunc)(void*);
|
||||
typedef struct _SL_RegProcTable{
|
||||
uint32_t regId;
|
||||
RegProcFunc pRegProc;
|
||||
}SL_RegProcTable;
|
||||
|
||||
/* 读取寄存器处理表 */
|
||||
SL_RegProcTable m_host_RegTblR[] =
|
||||
{
|
||||
{workCurrent, ReadRegisterWorkCurrent},
|
||||
{workVoltage, ReadRegisterWorkVoltage},
|
||||
{workTemperature, ReadRegisterWorkTemperature},
|
||||
{J1_Power, ReadRegisterJ1_Power},
|
||||
{J2_Power, ReadRegisterJ2_Power},
|
||||
{J3_Power, ReadRegisterJ3_Power},
|
||||
{J4_Power, ReadRegisterJ4_Power},
|
||||
{J5_Power, ReadRegisterJ5_Power},
|
||||
{J6_Power, ReadRegisterJ6_Power},
|
||||
{J7_Power, ReadRegisterJ7_Power},
|
||||
{J8_Power, ReadRegisterJ8_Power},
|
||||
{J9_Power, ReadRegisterJ9_Power},
|
||||
{J0_485_Communication_Baud_Rate, ReadRegisterJ0Baud},
|
||||
{J2_485_Communication_Baud_Rate, ReadRegisterJ2Baud},
|
||||
{J4_485_Communication_Baud_Rate, ReadRegisterJ4Baud},
|
||||
{J6_485_Communication_Baud_Rate, ReadRegisterJ6Baud},
|
||||
{Lora_uart_Communication_Baud_Rate, ReadRegisterLoraBaud},
|
||||
};
|
||||
|
||||
/* 写入寄存器处理表 */
|
||||
SL_RegProcTable m_host_RegTblW[] =
|
||||
{
|
||||
{J1_Power, WriteRegisterJ1_Power},
|
||||
{J2_Power, WriteRegisterJ2_Power},
|
||||
{J3_Power, WriteRegisterJ3_Power},
|
||||
{J4_Power, WriteRegisterJ4_Power},
|
||||
{J5_Power, WriteRegisterJ5_Power},
|
||||
{J6_Power, WriteRegisterJ6_Power},
|
||||
{J7_Power, WriteRegisterJ7_Power},
|
||||
{J8_Power, WriteRegisterJ8_Power},
|
||||
{J9_Power, WriteRegisterJ9_Power},
|
||||
{J0_485_Communication_Baud_Rate, WriteRegisterJ0Baud},
|
||||
{J2_485_Communication_Baud_Rate, WriteRegisterJ2Baud},
|
||||
{J4_485_Communication_Baud_Rate, WriteRegisterJ4Baud},
|
||||
{J6_485_Communication_Baud_Rate, WriteRegisterJ6Baud},
|
||||
{Lora_uart_Communication_Baud_Rate, WriteRegisterLoraBaud},
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 读取工作电流
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterWorkCurrent(void *pMsg)
|
||||
{
|
||||
return (uint16_t)(getWorkCurrent() * 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取工作电压
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterWorkVoltage(void *pMsg)
|
||||
{
|
||||
return (uint16_t)(getWorkVoltage() * 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取工作温度
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterWorkTemperature(void *pMsg)
|
||||
{
|
||||
return (uint16_t)(getBoardTemperature() * 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J1电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ1_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J1_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J2电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ2_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J2_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J3电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ3_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J3_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J4电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ4_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J4_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J5电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ5_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J5_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J6电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ6_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J6_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J7电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ7_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J7_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J8电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ8_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J8_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J9电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ9_Power(void *pMsg)
|
||||
{
|
||||
return readPwrCtrlState(J9_PwrCtrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J0通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ0Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ0_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J2通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ2Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ2_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J4通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ4Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ4_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J6通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ6Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ6_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J6通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterLoraBaud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getLora_Uart_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J1电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ1_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J1_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J2电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ2_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J2_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J3电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ3_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J3_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J4电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ4_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J4_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J5电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ5_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J5_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J6电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ6_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J6_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J7电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ7_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J7_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J8电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ8_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J8_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J9电源开关状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ9_Power(void *pMsg)
|
||||
{
|
||||
writePwrCtrlState(J9_PwrCtrl, (uint8_t)(*(uint16_t *)pMsg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J0通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ0Baud(void *pMsg)
|
||||
{
|
||||
setJ0_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J0_485(getJ0_485_Baud());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J2通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ2Baud(void *pMsg)
|
||||
{
|
||||
setJ2_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J2_485(getJ2_485_Baud());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J4通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ4Baud(void *pMsg)
|
||||
{
|
||||
setJ4_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J4_485(getJ4_485_Baud());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J6通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ6Baud(void *pMsg)
|
||||
{
|
||||
setJ6_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J6_485(getJ6_485_Baud());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J6通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterLoraBaud(void *pMsg)
|
||||
{
|
||||
setLora_Uart_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J6_485(getLora_Uart_Baud());
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取一帧数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static void hostMcuReadRegister(uint8_t *buff, uint8_t dataLen)
|
||||
{
|
||||
uint16_t Register_Start_Address = (buff[6] << 8) | buff[7];
|
||||
uint16_t Register_Number = (buff[8] << 8) | buff[9];
|
||||
|
||||
/* 初始化发送内存 */
|
||||
//系统内存不足,丢去当前包
|
||||
uint32_t tempLen = 13 + 2 * Register_Number + hostQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 13 + 2 * Register_Number;
|
||||
sendBuff->data = Buff + hostQueueUartSendInfoSize;
|
||||
|
||||
uint8_t *replay_pack = sendBuff->data;
|
||||
/* 起始标志 */
|
||||
*(replay_pack) = 'S';
|
||||
*(replay_pack + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = HostMcu;
|
||||
|
||||
/* 回复字节长度 */
|
||||
replay_pack += 1;
|
||||
*(replay_pack) = (uint8_t)((sendBuff->length - 6) >> 8);
|
||||
*(replay_pack + 1) = (uint8_t)(sendBuff->length - 6);
|
||||
|
||||
/* 功能码 */
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = SL_Function_Code_Read_Register;
|
||||
|
||||
/* 读取寄存器起始地址 */
|
||||
replay_pack += 1;
|
||||
*(replay_pack) = buff[6];
|
||||
*(replay_pack + 1) = buff[7];
|
||||
|
||||
/* 回复字节长度 */
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = (uint8_t)((sendBuff->length - 13) >> 8);
|
||||
*(replay_pack + 1) = (uint8_t)(sendBuff->length - 13);
|
||||
|
||||
/* 回复数据内容 */
|
||||
/* 读取数据 */
|
||||
for ( uint16_t pos = 0; pos < Register_Number; pos++) {
|
||||
for (uint16_t var = 0; var < sizeof(m_host_RegTblR) / sizeof(SL_RegProcTable); var++) {
|
||||
if (m_host_RegTblR[var].regId == (Register_Start_Address + pos)) {
|
||||
uint16_t temp = m_host_RegTblR[var].pRegProc(NULL);
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = (uint8_t)(temp >> 8);
|
||||
*(replay_pack + 1) = (uint8_t)(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 校验位 */
|
||||
replay_pack += 2;
|
||||
uint16_t crc_temp = modebusCrc(sendBuff->data, sendBuff->length - 3);
|
||||
*replay_pack = (uint8_t)(crc_temp >> 8);
|
||||
replay_pack += 1;
|
||||
*replay_pack = (uint8_t)crc_temp;
|
||||
|
||||
/* 结束标志 */
|
||||
replay_pack += 1;
|
||||
*replay_pack = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(hostMcu_uart_Queue)) {
|
||||
xQueueSend(hostMcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 写入一帧数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static void hostMcuWriteRegister(uint8_t *buff, uint8_t dataLen)
|
||||
{
|
||||
uint16_t Register_Start_Address = (buff[6] << 8) | buff[7];
|
||||
uint16_t Register_Number = (buff[8] << 8) | buff[9];
|
||||
|
||||
/* 将数据写入到寄存器中 */
|
||||
for ( uint16_t pos = 0; pos < Register_Number; pos++) {
|
||||
for (uint16_t i = 0; i < sizeof(m_host_RegTblW) / sizeof(SL_RegProcTable); i++) {
|
||||
if (m_host_RegTblW[i].regId == (Register_Start_Address + pos)) {
|
||||
uint16_t data = buff[10 + 2 * pos] << 8 | buff[10 + 2 * pos + 1];
|
||||
m_host_RegTblW[i].pRegProc(&data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 后续将数据存入配置文件中 */
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostFrameDataAnalyze(uint8_t *buff, uint8_t dataLen)
|
||||
{
|
||||
uint16_t crc = (buff[dataLen - 4] << 8) | buff[dataLen - 3];
|
||||
if (crc != modebusCrc(buff, dataLen - 3)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buff[5] == SL_Function_Code_Read_Register) {
|
||||
hostMcuReadRegister(buff, dataLen);
|
||||
}
|
||||
else if (buff[5] == SL_Function_Code_Write_Register) {
|
||||
hostMcuWriteRegister(buff, dataLen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,298 @@
|
|||
|
||||
#include "hostMcuDataParse.h"
|
||||
#include "hostMcuComm.h"
|
||||
|
||||
|
||||
static void stateMachine(void);
|
||||
|
||||
/* 状态机函数 */
|
||||
static uint8_t analysisWait(void);
|
||||
static uint8_t analysisStartFlagSL(void);
|
||||
static uint8_t analysisPortSL(void);
|
||||
static uint8_t analysisLengthSL(void);
|
||||
static uint8_t analysisEndFlagSL(void);
|
||||
|
||||
/**
|
||||
* @brief 状态机函数
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void stateMachine(void)
|
||||
{
|
||||
if (state == wait) {
|
||||
if (analysisWait() == TRUE) {
|
||||
su806UartRxTime = xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
|
||||
else if (state == startFlagSL) {
|
||||
analysisStartFlagSL();
|
||||
}
|
||||
|
||||
else if (state == portSL) {
|
||||
analysisPortSL();
|
||||
}
|
||||
|
||||
else if (state == lengthSL) {
|
||||
analysisLengthSL();
|
||||
}
|
||||
|
||||
else if (state == endFlagSL) {
|
||||
analysisEndFlagSL();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 wait
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define waitMaxLen 2
|
||||
uint8_t analysisWait(void)
|
||||
{
|
||||
if (su806RxBufferIndex >= 2) {
|
||||
/* 透传数据帧包头 */
|
||||
if (su806RxBuffer[0] == 'S' && su806RxBuffer[1] == 'L') {
|
||||
// log_info("startFlagSL\n");
|
||||
state = startFlagSL;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (su806RxBufferIndex < waitMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
state = wait;
|
||||
su806RxBufferIndex--;
|
||||
memcpy(su806RxBuffer, su806RxBuffer + 1, su806RxBufferIndex);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 startFlagSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
uint8_t analysisStartFlagSL(void)
|
||||
{
|
||||
/* 校验端口号 */
|
||||
if (su806RxBuffer[2] < 13) {
|
||||
// log_info("portSL\n");
|
||||
state = portSL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// log_error("portSL %d \n", gw485RxBuffer[2]);
|
||||
state = wait;
|
||||
su806RxBufferIndex--;
|
||||
memcpy(su806RxBuffer, su806RxBuffer + 1, su806RxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 portSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define PortSLMaxLen 5
|
||||
uint8_t analysisPortSL(void)
|
||||
{
|
||||
/* 解析数据包的度 */
|
||||
if (su806RxBufferIndex >= PortSLMaxLen) {
|
||||
uint32_t tempLen = 0;
|
||||
tempLen = (su806RxBuffer[3] << 8) | su806RxBuffer[4];
|
||||
|
||||
if (tempLen <= 1024) {
|
||||
// log_info("lengthSL\n");
|
||||
state = lengthSL;
|
||||
frameLength = 6 + tempLen;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (su806RxBufferIndex < PortSLMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// log_error("lengthSL %d \n", (gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
||||
|
||||
state = wait;
|
||||
su806RxBufferIndex--;
|
||||
memcpy(su806RxBuffer, su806RxBuffer + 1, su806RxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 lengthSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define LengthSLMaxLen frameLength
|
||||
uint8_t analysisLengthSL(void)
|
||||
{
|
||||
/* 解析帧尾 */
|
||||
if (su806RxBufferIndex >= LengthSLMaxLen) {
|
||||
if (su806RxBuffer[LengthSLMaxLen - 1] == 0x17) {
|
||||
// log_info("endFlagSL\n");
|
||||
state = endFlagSL;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (su806RxBufferIndex < LengthSLMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
// log_info("endFlagSL %d\n", gw485RxBuffer[LengthSLMaxLen - 1]);
|
||||
|
||||
state = wait;
|
||||
su806RxBufferIndex--;
|
||||
memcpy(su806RxBuffer, su806RxBuffer + 1, su806RxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 状态 endFlagSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
uint8_t analysisEndFlagSL(void)
|
||||
{
|
||||
uint32_t tempLen = 0;
|
||||
tempLen = (su806RxBuffer[3] << 8) | su806RxBuffer[4];
|
||||
|
||||
if (su806RxBuffer[2] == HostMcu) {
|
||||
hostFrameDataAnalyze(su806RxBuffer, su806RxBufferIndex);
|
||||
su806RxBufferIndex = 0;
|
||||
state = wait;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//系统内存不足,丢去当前包
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
goto err;
|
||||
}
|
||||
uint8_t *Buff;
|
||||
|
||||
/* 对于从mcu处理的数据,原封不动的发送到从mcu上 */
|
||||
if (su806RxBuffer[2] == J1
|
||||
|| su806RxBuffer[2] == J3
|
||||
|| su806RxBuffer[2] == J5
|
||||
|| su806RxBuffer[2] == J7
|
||||
|| su806RxBuffer[2] == J8
|
||||
|| su806RxBuffer[2] == J9
|
||||
|| su806RxBuffer[2] == SlaveMcu) {
|
||||
|
||||
Buff = (uint8_t *)pvPortMalloc(tempLen + hostQueueUartSendInfoSize + 6);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = tempLen + 6;
|
||||
sendBuff->data = Buff + hostQueueUartSendInfoSize;
|
||||
memcpy((char *)sendBuff->data, (char *)su806RxBuffer, tempLen + 6);
|
||||
|
||||
if (uxQueueSpacesAvailable(hostMcu_uart_Queue)) {
|
||||
xQueueSend(hostMcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
|
||||
Buff = (uint8_t *)pvPortMalloc(tempLen + hostQueueUartSendInfoSize);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = tempLen;
|
||||
sendBuff->data = Buff + hostQueueUartSendInfoSize;
|
||||
memcpy((char *)sendBuff->data, (char *)&su806RxBuffer[5], tempLen);
|
||||
|
||||
|
||||
/* 通过不同的端口将数据发送到不同的地方 */
|
||||
if (su806RxBuffer[2] == J0) {
|
||||
if (uxQueueSpacesAvailable(J0_485_Queue)) {
|
||||
xQueueSend(J0_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (su806RxBuffer[2] == J2) {
|
||||
if (uxQueueSpacesAvailable(J2_485_Queue)) {
|
||||
xQueueSend(J2_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (su806RxBuffer[2] == J4) {
|
||||
if (uxQueueSpacesAvailable(J4_485_Queue)) {
|
||||
xQueueSend(J4_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (su806RxBuffer[2] == J6) {
|
||||
if (uxQueueSpacesAvailable(J6_485_Queue)) {
|
||||
xQueueSend(J6_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (su806RxBuffer[2] == Lora) {
|
||||
if (uxQueueSpacesAvailable(lora_uart_Queue)) {
|
||||
xQueueSend(lora_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
|
||||
err:
|
||||
//清零buff
|
||||
state = wait;
|
||||
su806RxBufferIndex = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解析智能模块发送来的数据
|
||||
* @param device 用于接收智能模块发送来的数据的串口设备
|
||||
* @retval
|
||||
*/
|
||||
void hostMcuUartDataAnalysis(device_handle device)
|
||||
{
|
||||
/* 每次函数最多执行10ms */
|
||||
static uint32_t tickstart = 0U;
|
||||
tickstart = xTaskGetTickCount();
|
||||
|
||||
/* 2S未解析出来一帧数据,将数据清零 */
|
||||
if (getTickDiff(su806UartRxTime) >= tick_2S) {
|
||||
su806UartRxTime = xTaskGetTickCount();
|
||||
su806RxBufferIndex = 0;
|
||||
state = wait;
|
||||
}
|
||||
|
||||
while (uart_dev_char_present(device) == 1 && ((xTaskGetTickCount() - tickstart) < 5)) {
|
||||
su806RxBuffer[su806RxBufferIndex++] = uart_dev_in_char(device);
|
||||
stateMachine();
|
||||
}
|
||||
|
||||
if (uart_dev_char_present(device) != 1 && state != wait) {
|
||||
stateMachine();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
#include "slaveParameter.h"
|
||||
|
||||
typedef struct _parameterInfo {
|
||||
float pwrOnVoltage; //安卓模块工作电压
|
||||
float WorkCurrent; //工作电流
|
||||
float WorkVoltage; //工作电压
|
||||
float Temperature; //温度
|
||||
|
||||
uint32_t J0_485_Baud; //与J0_485通信波特率
|
||||
uint32_t J2_485_Baud; //与J2_485通信波特率
|
||||
uint32_t J4_485_Baud; //与J4_485通信波特率
|
||||
uint32_t J6_485_Baud; //与J6_485通信波特率
|
||||
uint32_t Lora_Uart_Baud; //与lora通信波特率
|
||||
}hostParameterInfo;
|
||||
|
||||
static hostParameterInfo hostParameter = {0};
|
||||
|
||||
#define configSize (sizeof(configInfo))
|
||||
|
||||
/**
|
||||
* @brief 读取配置文件参数
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void readHostConfigParameter(void)
|
||||
{
|
||||
/* 使用默认参数 */
|
||||
hostParameter.J0_485_Baud = 9600;
|
||||
hostParameter.J2_485_Baud = 9600;
|
||||
hostParameter.J4_485_Baud = 9600;
|
||||
hostParameter.J6_485_Baud = 9600;
|
||||
hostParameter.Lora_Uart_Baud = 9600;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到pwrOn电压
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
float getPwrOnVoltage(void)
|
||||
{
|
||||
return hostParameter.pwrOnVoltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置工作电流
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setPwrOnVoltage(float Voltage)
|
||||
{
|
||||
hostParameter.pwrOnVoltage = Voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到工作电流
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
float getWorkCurrent(void)
|
||||
{
|
||||
return hostParameter.WorkCurrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置工作电流
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setWorkCurrent(float Curr)
|
||||
{
|
||||
hostParameter.WorkCurrent = Curr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到工作电压
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
float getWorkVoltage(void)
|
||||
{
|
||||
return hostParameter.WorkVoltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置工作电压
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setWorkVoltage(float Voltage)
|
||||
{
|
||||
hostParameter.WorkVoltage = Voltage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到温度
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
float getBoardTemperature(void)
|
||||
{
|
||||
return hostParameter.Temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置温度
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setBoardTemperature(float Temperature)
|
||||
{
|
||||
hostParameter.Temperature = Temperature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J0通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ0_485_Baud(void)
|
||||
{
|
||||
return hostParameter.J0_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J0通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ0_485_Baud(uint32_t Baud)
|
||||
{
|
||||
hostParameter.J0_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J2通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ2_485_Baud(void)
|
||||
{
|
||||
return hostParameter.J2_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J2通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ2_485_Baud(uint32_t Baud)
|
||||
{
|
||||
hostParameter.J2_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J4通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ4_485_Baud(void)
|
||||
{
|
||||
return hostParameter.J4_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J4通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ4_485_Baud(uint32_t Baud)
|
||||
{
|
||||
hostParameter.J4_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J6通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ6_485_Baud(void)
|
||||
{
|
||||
return hostParameter.J6_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J4通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ6_485_Baud(uint32_t Baud)
|
||||
{
|
||||
hostParameter.J6_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对Lora通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getLora_Uart_Baud(void)
|
||||
{
|
||||
return hostParameter.Lora_Uart_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置Lora通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setLora_Uart_Baud(uint32_t Baud)
|
||||
{
|
||||
hostParameter.Lora_Uart_Baud = Baud;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,416 @@
|
|||
|
||||
#include "hostQueueUart.h"
|
||||
#include "hostBusIdleDetection.h"
|
||||
|
||||
#include "FM_GPIO.h"
|
||||
|
||||
#include "semphr.h"
|
||||
|
||||
|
||||
/* 队列中每个消息的大小 */
|
||||
#define QUEUE_SIZE 4
|
||||
|
||||
/* 485队列的长度 */
|
||||
#define rs485QueueLength 5
|
||||
#define mcuUartQueueLength 10
|
||||
#define loraQueueLength 5
|
||||
#define su806QueueLength 10
|
||||
|
||||
|
||||
/* 各个通讯口的队列 */
|
||||
QueueHandle_t J0_485_Queue = NULL;
|
||||
QueueHandle_t J2_485_Queue = NULL;
|
||||
QueueHandle_t J4_485_Queue = NULL;
|
||||
QueueHandle_t J6_485_Queue = NULL;
|
||||
QueueHandle_t lora_uart_Queue = NULL;
|
||||
QueueHandle_t su806_uart_Queue = NULL;
|
||||
QueueHandle_t hostMcu_uart_Queue = NULL;
|
||||
|
||||
/* 创建二值信号量 */
|
||||
static SemaphoreHandle_t J0_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J2_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J4_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J6_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t lora_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t su806_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t hostMcu_FreeMemorySemaphore = NULL;
|
||||
// 创建队列集
|
||||
static QueueSetHandle_t hostBinarySemaphoreSet = NULL;
|
||||
/* 创建二值信号量 */
|
||||
static SemaphoreHandle_t J0_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J2_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J4_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J6_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t lora_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t su806_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t hostMcu_sendOverSemaphore = NULL;
|
||||
|
||||
/* 通过该结构体接收对应的数据用来发送,结束后通过该结构体,释放数据的内存 */
|
||||
typedef struct _hostQueueSendDataInfo {
|
||||
hostQueueUartSendInfo *J0_485_data;
|
||||
hostQueueUartSendInfo *J2_485_data;
|
||||
hostQueueUartSendInfo *J4_485_data;
|
||||
hostQueueUartSendInfo *J6_485_data;
|
||||
hostQueueUartSendInfo *lora_uart_data;
|
||||
hostQueueUartSendInfo *su806_uart_data;
|
||||
hostQueueUartSendInfo *hostMcu_uart_data;
|
||||
} hostQueueSendDataInfo;
|
||||
static hostQueueSendDataInfo hostQueueSendData;
|
||||
|
||||
/**
|
||||
* @brief 初始化串口发送使用到的队列和释放内存所使用的信号量
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostUartSendInit(void)
|
||||
{
|
||||
/* 初始化队列 */
|
||||
J0_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J2_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J4_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J6_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
lora_uart_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
su806_uart_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
hostMcu_uart_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
|
||||
/* 初始化释放内存二值变量 */
|
||||
J0_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J2_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J4_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J6_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
lora_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
su806_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
hostMcu_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
// 初始化队列集
|
||||
hostBinarySemaphoreSet = xQueueCreateSet(7);
|
||||
// 将二值信号量添加到队列集中
|
||||
xQueueAddToSet(J0_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
xQueueAddToSet(J2_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
xQueueAddToSet(J4_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
xQueueAddToSet(J6_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
xQueueAddToSet(lora_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
xQueueAddToSet(su806_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
xQueueAddToSet(hostMcu_FreeMemorySemaphore, hostBinarySemaphoreSet);
|
||||
|
||||
/* 发送完成信号量 */
|
||||
J0_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J0_sendOverSemaphore);
|
||||
J2_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J2_sendOverSemaphore);
|
||||
J4_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J4_sendOverSemaphore);
|
||||
J6_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J6_sendOverSemaphore);
|
||||
lora_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(lora_sendOverSemaphore);
|
||||
su806_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(su806_sendOverSemaphore);
|
||||
hostMcu_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(hostMcu_sendOverSemaphore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J0队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J0QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J0_485_Queue, hostQueueSendData.J0_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J0_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J0_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_J1_handle, hostQueueSendData.J0_485_data->data
|
||||
, hostQueueSendData.J0_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J2队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J2QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J2_485_Queue, hostQueueSendData.J2_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J2_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J2_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_J2_handle, hostQueueSendData.J2_485_data->data
|
||||
, hostQueueSendData.J2_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J4队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J4QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J4_485_Queue, hostQueueSendData.J4_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J4_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J4_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_J4_handle, hostQueueSendData.J2_485_data->data
|
||||
, hostQueueSendData.J4_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J6队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J6QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J6_485_Queue, hostQueueSendData.J6_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J6_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J6_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_J6_handle, hostQueueSendData.J6_485_data->data
|
||||
, hostQueueSendData.J6_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从lora队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void LoraQueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(lora_uart_Queue, hostQueueSendData.lora_uart_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(lora_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_Lora_handle, hostQueueSendData.lora_uart_data->data
|
||||
, hostQueueSendData.lora_uart_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从su806队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Su806QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(su806_uart_Queue, hostQueueSendData.su806_uart_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(su806_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_Su806_handle, hostQueueSendData.su806_uart_data->data
|
||||
, hostQueueSendData.su806_uart_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从hostMcu队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void HostMcuQueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(hostMcu_uart_Queue, hostQueueSendData.hostMcu_uart_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(hostMcu_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
hostUartInterruptSend(g_Mcu_handle, hostQueueSendData.hostMcu_uart_data->data
|
||||
, hostQueueSendData.hostMcu_uart_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通过二值信号量释放中断发送数据的内存
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void hostBinarySemaphoreFreeMemory(void)
|
||||
{
|
||||
// 等待队列集中的事件
|
||||
QueueSetMemberHandle_t xActivatedMember = xQueueSelectFromSet(hostBinarySemaphoreSet, portMAX_DELAY);
|
||||
|
||||
if (xActivatedMember == J0_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.J0_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ0_485;
|
||||
// 处理二值信号量事件
|
||||
xSemaphoreTake(J0_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J0_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J2_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.J2_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ2_485;
|
||||
xSemaphoreTake(J2_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J2_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J4_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.J4_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ4_485;
|
||||
xSemaphoreTake(J4_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J4_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J6_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.J6_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ6_485;
|
||||
xSemaphoreTake(J6_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J6_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == lora_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.lora_uart_data);
|
||||
xSemaphoreTake(lora_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(lora_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == su806_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.su806_uart_data);
|
||||
xSemaphoreTake(su806_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(su806_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == hostMcu_FreeMemorySemaphore) {
|
||||
vPortFree(hostQueueSendData.hostMcu_uart_data);
|
||||
xSemaphoreTake(hostMcu_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(hostMcu_sendOverSemaphore);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通过中断发送
|
||||
* @param device 设备
|
||||
data 指向数据的指针
|
||||
len 数据长度
|
||||
* @retval 0:成功
|
||||
*/
|
||||
uint8_t hostUartInterruptSend(device_handle device, uint8_t *data, uint16_t len)
|
||||
{
|
||||
/* 指向数据 */
|
||||
uart_device_info *dev = (uart_device_info *)device;
|
||||
dev->uart_send_data.data = data;
|
||||
dev->uart_send_data.count = 0;
|
||||
dev->uart_send_data.len = len;
|
||||
|
||||
/* 开始发送 */
|
||||
if (device == g_J0_handle) {
|
||||
xSemaphoreTake(J0_sendOverSemaphore, 0);
|
||||
writeJ0_485;
|
||||
USART_ITConfig(J0_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(J0_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_J2_handle) {
|
||||
xSemaphoreTake(J2_sendOverSemaphore, 0);
|
||||
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_J4_handle) {
|
||||
xSemaphoreTake(J4_sendOverSemaphore, 0);
|
||||
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_J6_handle) {
|
||||
xSemaphoreTake(J6_sendOverSemaphore, 0);
|
||||
writeJ6_485;
|
||||
USART_ITConfig(J6_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(J6_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_Mcu_handle) {
|
||||
xSemaphoreTake(hostMcu_sendOverSemaphore, 0);
|
||||
USART_ITConfig(Mcu_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(Mcu_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_Lora_handle) {
|
||||
xSemaphoreTake(lora_sendOverSemaphore, 0);
|
||||
USART_ITConfig(Lora_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(Lora_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_Su806_handle) {
|
||||
xSemaphoreTake(su806_sendOverSemaphore, 0);
|
||||
USART_ITConfig(Su806_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(Su806_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 数据发送完成后用于清除内存
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J0_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J0_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J2_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J2_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J4_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J4_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J6_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J6_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void Lora_uart_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(lora_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void Su806_uart_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(su806_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void hostMcu_uart_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(hostMcu_FreeMemorySemaphore, 0);
|
||||
}
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
|
||||
#include "stdio.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "hostRecvSlaveDataParse.h"
|
||||
#include "hostQueueUart.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
static void slaveStateMachine(void);
|
||||
|
||||
/* 状态机函数 */
|
||||
static uint8_t slaveAnalysisWait(void);
|
||||
static uint8_t slaveAnalysisStartFlagSL(void);
|
||||
static uint8_t slaveAnalysisPortSL(void);
|
||||
static uint8_t slaveAnalysisLengthSL(void);
|
||||
static uint8_t slaveAnalysisEndFlagSL(void);
|
||||
|
||||
|
||||
/* 状态机状态机变量 */
|
||||
uartStateMachine slaveState = wait;
|
||||
|
||||
/**
|
||||
* @brief 状态机函数
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveStateMachine(void)
|
||||
{
|
||||
if (slaveState == wait) {
|
||||
if (slaveAnalysisWait() == TRUE) {
|
||||
mcuUartRxTime = xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
|
||||
else if (slaveState == startFlagSL) {
|
||||
slaveAnalysisStartFlagSL();
|
||||
}
|
||||
|
||||
else if (slaveState == portSL) {
|
||||
slaveAnalysisPortSL();
|
||||
}
|
||||
|
||||
else if (slaveState == lengthSL) {
|
||||
slaveAnalysisLengthSL();
|
||||
}
|
||||
|
||||
else if (slaveState == endFlagSL) {
|
||||
slaveAnalysisEndFlagSL();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 wait
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define waitMaxLen 2
|
||||
uint8_t slaveAnalysisWait(void)
|
||||
{
|
||||
if (mcuUartRxBufferIndex >= 2) {
|
||||
/* 透传数据帧包头 */
|
||||
if (mcuUartRxBuffer[0] == 'S' && mcuUartRxBuffer[1] == 'L') {
|
||||
// log_info("startFlagSL\n");
|
||||
state = startFlagSL;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mcuUartRxBufferIndex < waitMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 startFlagSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
uint8_t slaveAnalysisStartFlagSL(void)
|
||||
{
|
||||
/* 校验端口号 */
|
||||
if (mcuUartRxBuffer[2] < 13) {
|
||||
// log_info("portSL\n");
|
||||
state = portSL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// log_error("portSL %d \n", gw485RxBuffer[2]);
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 portSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define PortSLMaxLen 5
|
||||
uint8_t slaveAnalysisPortSL(void)
|
||||
{
|
||||
/* 解析数据包的度 */
|
||||
if (mcuUartRxBufferIndex >= PortSLMaxLen) {
|
||||
uint32_t tempLen = 0;
|
||||
tempLen = (mcuUartRxBuffer[3] << 8) | mcuUartRxBuffer[4];
|
||||
|
||||
if (tempLen <= 1024) {
|
||||
// log_info("lengthSL\n");
|
||||
state = lengthSL;
|
||||
frameLength = 6 + tempLen;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mcuUartRxBufferIndex < PortSLMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// log_error("lengthSL %d \n", (gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
||||
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 lengthSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define LengthSLMaxLen frameLength
|
||||
uint8_t slaveAnalysisLengthSL(void)
|
||||
{
|
||||
/* 解析帧尾 */
|
||||
if (mcuUartRxBufferIndex >= LengthSLMaxLen) {
|
||||
if (mcuUartRxBuffer[LengthSLMaxLen - 1] == 0x17) {
|
||||
// log_info("endFlagSL\n");
|
||||
state = endFlagSL;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mcuUartRxBufferIndex < LengthSLMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
// log_info("endFlagSL %d\n", gw485RxBuffer[LengthSLMaxLen - 1]);
|
||||
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 endFlagSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
uint8_t slaveAnalysisEndFlagSL(void)
|
||||
{
|
||||
uint16_t tempLen = ((mcuUartRxBuffer[3] << 8) | mcuUartRxBuffer[4]) + 6;
|
||||
|
||||
//系统内存不足,丢去当前包
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
//清零buff
|
||||
state = wait;
|
||||
su806RxBufferIndex = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen + hostQueueUartSendInfoSize);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = tempLen;
|
||||
sendBuff->data = Buff + hostQueueUartSendInfoSize;
|
||||
memcpy((char *)sendBuff->data, (char *)su806RxBuffer, tempLen);
|
||||
|
||||
|
||||
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
|
||||
xQueueSend(su806_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hostRecvSlaveDataParse(device_handle device)
|
||||
{
|
||||
/* 每次函数最多执行10ms */
|
||||
static uint32_t tickstart = 0U;
|
||||
tickstart = xTaskGetTickCount();
|
||||
|
||||
/* 2S未解析出来一帧数据,将数据清零 */
|
||||
if (getTickDiff(mcuUartRxTime) >= tick_2S) {
|
||||
mcuUartRxTime = xTaskGetTickCount();
|
||||
mcuUartRxBufferIndex = 0;
|
||||
state = wait;
|
||||
}
|
||||
|
||||
while (uart_dev_char_present(device) == 1 && ((xTaskGetTickCount() - tickstart) < 5)) {
|
||||
mcuUartRxBuffer[mcuUartRxBufferIndex++] = uart_dev_in_char(device);
|
||||
slaveStateMachine();
|
||||
}
|
||||
|
||||
if (uart_dev_char_present(device) != 1 && state != wait) {
|
||||
slaveStateMachine();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,361 @@
|
|||
|
||||
#include "hostSensorDataParse.h"
|
||||
#include "hostQueueUart.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief 接收J0口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J0_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J0_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J0_handle) == 1)
|
||||
&& (maxdataLen > J0_485RxBufferIndex)) {
|
||||
J0_485RxBuffer[J0_485RxBufferIndex++] = uart_dev_in_char(g_J0_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J0_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J0_485RxBufferIndex + hostQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J0_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J0_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J0;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J0_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J0_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J0_485RxBuffer, J0_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J0_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
|
||||
xQueueSend(su806_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J0_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J2口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J2_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J2_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J2_handle) == 1)
|
||||
&& (maxdataLen > J2_485RxBufferIndex)) {
|
||||
J2_485RxBuffer[J2_485RxBufferIndex++] = uart_dev_in_char(g_J2_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J2_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J2_485RxBufferIndex + hostQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J2_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J2_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J2;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J2_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J2_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J2_485RxBuffer, J2_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J2_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
|
||||
xQueueSend(su806_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J2_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J4口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J4_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J4_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J4_handle) == 1)
|
||||
&& (maxdataLen > J4_485RxBufferIndex)) {
|
||||
J4_485RxBuffer[J4_485RxBufferIndex++] = uart_dev_in_char(g_J4_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J4_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J4_485RxBufferIndex + hostQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J4_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J4_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J4;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J4_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J4_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J4_485RxBuffer, J4_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J4_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
|
||||
xQueueSend(su806_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J4_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J6口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J6_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J6_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J6_handle) == 1)
|
||||
&& (maxdataLen > J6_485RxBufferIndex)) {
|
||||
J6_485RxBuffer[J6_485RxBufferIndex++] = uart_dev_in_char(g_J6_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J6_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J6_485RxBufferIndex + hostQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J6_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J6_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J6;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J6_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J6_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J6_485RxBuffer, J6_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J6_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
|
||||
xQueueSend(su806_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J6_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收Lora口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Lora_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (loraRxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_Lora_handle) == 1)
|
||||
&& (maxdataLen > loraRxBufferIndex)) {
|
||||
loraRxBuffer[loraRxBufferIndex++] = uart_dev_in_char(g_Lora_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((loraRxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + loraRxBufferIndex + hostQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
loraRxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
hostQueueUartSendInfo *sendBuff = (hostQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + loraRxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(hostQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = Lora;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(loraRxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(loraRxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)loraRxBuffer, loraRxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += loraRxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(su806_uart_Queue)) {
|
||||
xQueueSend(su806_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
loraRxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "slaveFreerotsTask.h"
|
||||
|
||||
// #include "HD_Flash.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "uart_dev.h"
|
||||
#include "FM_ADC.h"
|
||||
|
||||
#include "parameter.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Æô¶¯
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveStartApp(void)
|
||||
{
|
||||
SlaveMcu_GPIO_Init();
|
||||
readConfigParameter();
|
||||
SlaveMcu_uartBuf_Init(256, 1024);
|
||||
Init_J1_485(getJ1_485_Baud());
|
||||
Init_J3_485(getJ1_485_Baud());
|
||||
Init_J5_485(getJ1_485_Baud());
|
||||
Init_J7_485(getJ1_485_Baud());
|
||||
Init_J8_485(getJ1_485_Baud());
|
||||
Init_J9_485(getJ1_485_Baud());
|
||||
Init_Mcu_Uart(115200);
|
||||
proportionalInt();
|
||||
FM_ADC_Init();
|
||||
|
||||
while (1) {
|
||||
|
||||
};
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef APP_BUS_IDLE_DETECTION_H_
|
||||
#define APP_BUS_IDLE_DETECTION_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "event_groups.h"
|
||||
|
||||
|
||||
|
||||
#ifdef RS485BUSIDLE1
|
||||
void softwareTimeInit(void);
|
||||
|
||||
void J1_485_IN_IDLE(void);
|
||||
void J2_485_IN_IDLE(void);
|
||||
void J3_485_IN_IDLE(void);
|
||||
void J4_485_IN_IDLE(void);
|
||||
void J5_0_485_IN_IDLE(void);
|
||||
|
||||
void J1_485_IN_RXNE(void);
|
||||
void J2_485_IN_RXNE(void);
|
||||
void J3_485_IN_RXNE(void);
|
||||
void J4_485_IN_RXNE(void);
|
||||
void J5_0_485_IN_RXNE(void);
|
||||
#endif
|
||||
|
||||
uint8_t getRs485State(device_handle device);
|
||||
uint8_t getUartState(device_handle device);
|
||||
|
||||
|
||||
#endif
|
|
@ -1,20 +0,0 @@
|
|||
#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);
|
||||
|
||||
// void downSensorDataAnalysis(device_handle device);
|
||||
|
||||
|
||||
uint32_t getTickDiff(uint32_t lastTick);
|
||||
|
||||
void J1_SensorDataAnalysis(void);
|
||||
void J2_SensorDataAnalysis(void);
|
||||
void J3_SensorDataAnalysis(void);
|
||||
void J4_SensorDataAnalysis(void);
|
||||
void J5_0_SensorDataAnalysis(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -1,41 +0,0 @@
|
|||
#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
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef APP_QUEUE_UART_H_
|
||||
#define APP_QUEUE_UART_H_
|
||||
|
||||
#include "pDebug.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
|
||||
/* 存入队列中的数据格式 */
|
||||
typedef struct _queueUartSendInfo{
|
||||
uint32_t length; //数据长度
|
||||
uint8_t *data; //数据
|
||||
} queueUartSendInfo;
|
||||
#define queueUartSendInfoSize sizeof(queueUartSendInfo)
|
||||
|
||||
/* 分时复用485存入队列中的数据格式 */
|
||||
typedef struct _queueTimeShareSendInfo{
|
||||
uint8_t connectPort; //发送的端口
|
||||
uint32_t length; //数据长度
|
||||
uint8_t *data; //数据
|
||||
} queueTimeShareSendInfo;
|
||||
#define queueTimeShareSendInfoSize sizeof(queueTimeShareSendInfo)
|
||||
|
||||
extern QueueHandle_t J1_485_Queue;
|
||||
extern QueueHandle_t J2_485_Queue;
|
||||
extern QueueHandle_t J3_485_Queue;
|
||||
extern QueueHandle_t J4_485_Queue;
|
||||
extern QueueHandle_t J5_0_485_Queue;
|
||||
extern QueueHandle_t upward_uart_Queue;
|
||||
extern QueueSetHandle_t uart_Queue;
|
||||
|
||||
void uartQueueInit(void);
|
||||
void uartQueueSend(void);
|
||||
void binarySemaphoreInit(void);
|
||||
void binarySemaphoreFreeMemory(void);
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
#ifndef APP_UART_PARSE_
|
||||
#define APP_UART_PARSE_
|
||||
|
||||
#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);
|
||||
void upwardUartDataAnalysis(device_handle device);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _APP_SLAVE_485_DATA_PARSE_H_
|
||||
#define _APP_SLAVE_485_DATA_PARSE_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
void J1_SensorDataAnalysis(void);
|
||||
void J3_SensorDataAnalysis(void);
|
||||
void J5_SensorDataAnalysis(void);
|
||||
void J7_SensorDataAnalysis(void);
|
||||
void J8_SensorDataAnalysis(void);
|
||||
void J9_SensorDataAnalysis(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
#ifndef _APP_SLAVE_BUS_IDLE_DETECTION_H_
|
||||
#define _APP_SLAVE_BUS_IDLE_DETECTION_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "event_groups.h"
|
||||
#include "semphr.h"
|
||||
|
||||
extern SemaphoreHandle_t J1_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J3_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J5_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J7_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J8_IDLESemaphore;
|
||||
extern SemaphoreHandle_t J9_IDLESemaphore;
|
||||
|
||||
void slaveIdleInit(void);
|
||||
|
||||
void J1_485_IN_IDLE(void);
|
||||
void J3_485_IN_IDLE(void);
|
||||
void J5_485_IN_IDLE(void);
|
||||
void J7_485_IN_IDLE(void);
|
||||
void J8_485_IN_IDLE(void);
|
||||
void J9_485_IN_IDLE(void);
|
||||
|
||||
void J1_485_IN_RXNE(void);
|
||||
void J3_485_IN_RXNE(void);
|
||||
void J5_485_IN_RXNE(void);
|
||||
void J7_485_IN_RXNE(void);
|
||||
void J8_485_IN_RXNE(void);
|
||||
void J9_485_IN_RXNE(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef APP_FREERTOS_TASK_H_
|
||||
#define APP_FREERTOS_TASK_H_
|
||||
|
||||
#include "pDebug.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
void slaveStartApp(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _APP_SLAVE_MCU_COMM_H_
|
||||
#define _APP_SLAVE_MCU_COMM_H_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
void slaveFrameDataAnalyze(uint8_t *buff, uint8_t dataLen);
|
||||
|
||||
|
||||
# endif
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _APP_SLAVE_MCU_DATA_PARSE_H_
|
||||
#define _APP_SLAVE_MCU_DATA_PARSE_H_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
#include "slaveQueueUart.h"
|
||||
|
||||
// void slaveMcuDataParse(void);
|
||||
void slaveMcuUartDataAnalysis(device_handle device);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef APP_SLAVE_PARAMETER_H_
|
||||
#define APP_SLAVE_PARAMETER_H_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
//通过该格式存入flash中
|
||||
typedef struct _configInfo {
|
||||
uint32_t J1_485_Baud; //与J1_485通信波特率
|
||||
uint32_t J3_485_Baud; //与J3_485通信波特率
|
||||
uint32_t J5_485_Baud; //与J5_485通信波特率
|
||||
uint32_t J7_485_Baud; //与J7_485通信波特率
|
||||
uint32_t J8_485_Baud; //与J8_485通信波特率
|
||||
uint32_t J9_485_Baud; //与J9_485通信波特率
|
||||
|
||||
uint16_t crc; //crc校验
|
||||
} slaveConfigInfo;
|
||||
|
||||
void readSlaveConfigParameter(void);
|
||||
// void writeConfigParameter(configInfo inConfigInfo);
|
||||
|
||||
uint32_t getJ1_485_Baud(void);
|
||||
void setJ1_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ3_485_Baud(void);
|
||||
void setJ3_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ5_485_Baud(void);
|
||||
void setJ5_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ7_485_Baud(void);
|
||||
void setJ7_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ8_485_Baud(void);
|
||||
void setJ8_485_Baud(uint32_t Baud);
|
||||
uint32_t getJ9_485_Baud(void);
|
||||
void setJ9_485_Baud(uint32_t Baud);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
#ifndef APP_SLAVE_QUEUE_UART_H_
|
||||
#define APP_SLAVE_QUEUE_UART_H_
|
||||
|
||||
#include "pDebug.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
/* 存入队列中的数据格式 */
|
||||
typedef struct _slaveQueueUartSendInfo{
|
||||
uint32_t length; //数据长度
|
||||
uint8_t *data; //数据
|
||||
} slaveQueueUartSendInfo;
|
||||
#define slaveQueueUartSendInfoSize sizeof(slaveQueueUartSendInfo)
|
||||
|
||||
extern QueueHandle_t J1_485_Queue;
|
||||
extern QueueHandle_t J3_485_Queue;
|
||||
extern QueueHandle_t J5_485_Queue;
|
||||
extern QueueHandle_t J7_485_Queue;
|
||||
extern QueueHandle_t J8_485_Queue;
|
||||
extern QueueHandle_t J9_485_Queue;
|
||||
extern QueueHandle_t mcu_uart_Queue;
|
||||
|
||||
uint8_t slaveUartInterruptSend(device_handle device, uint8_t *data, uint16_t len);
|
||||
|
||||
void slaveUartSendInit(void);
|
||||
|
||||
void J1QueueSend(void);
|
||||
void J3QueueSend(void);
|
||||
void J5QueueSend(void);
|
||||
void J7QueueSend(void);
|
||||
void J8QueueSend(void);
|
||||
void J9QueueSend(void);
|
||||
void slaveMcuQueueSend(void);
|
||||
|
||||
void binarySemaphoreFreeMemory(void);
|
||||
|
||||
void J1_485_IN_TXE(void);
|
||||
void J3_485_IN_TXE(void);
|
||||
void J5_485_IN_TXE(void);
|
||||
void J7_485_IN_TXE(void);
|
||||
void J8_485_IN_TXE(void);
|
||||
void J9_485_IN_TXE(void);
|
||||
void slaveMcu_uart_IN_TXE(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,428 @@
|
|||
|
||||
#include "slave485DataParse.h"
|
||||
#include "slaveQueueUart.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
/**
|
||||
* @brief 接收J1口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J1_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J1_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J1_handle) == 1)
|
||||
&& (maxdataLen > J1_485RxBufferIndex)) {
|
||||
J1_485RxBuffer[J1_485RxBufferIndex++] = uart_dev_in_char(g_J1_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J1_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J1_485RxBufferIndex + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J1_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J1_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(slaveQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J1;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J1_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J1_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J1_485RxBuffer, J1_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J1_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J1_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J3口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J3_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J3_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J3_handle) == 1)
|
||||
&& (maxdataLen > J3_485RxBufferIndex)) {
|
||||
J3_485RxBuffer[J3_485RxBufferIndex++] = uart_dev_in_char(g_J3_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J3_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J3_485RxBufferIndex + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J3_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J3_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(slaveQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J3;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J3_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J3_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J3_485RxBuffer, J3_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J3_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J3_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J5口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J5_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J5_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J5_handle) == 1)
|
||||
&& (maxdataLen > J5_485RxBufferIndex)) {
|
||||
J5_485RxBuffer[J5_485RxBufferIndex++] = uart_dev_in_char(g_J5_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J5_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J5_485RxBufferIndex + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J5_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J5_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(slaveQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J5;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J5_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J5_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J5_485RxBuffer, J5_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J5_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J5_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J7口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J7_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J7_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J7_handle) == 1)
|
||||
&& (maxdataLen > J7_485RxBufferIndex)) {
|
||||
J7_485RxBuffer[J7_485RxBufferIndex++] = uart_dev_in_char(g_J7_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J7_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J7_485RxBufferIndex + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J7_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J7_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(slaveQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J7;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J7_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J7_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J7_485RxBuffer, J7_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J7_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J7_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J8口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J8_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J8_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J8_handle) == 1)
|
||||
&& (maxdataLen > J8_485RxBufferIndex)) {
|
||||
J8_485RxBuffer[J8_485RxBufferIndex++] = uart_dev_in_char(g_J8_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J8_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J8_485RxBufferIndex + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J8_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J8_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(slaveQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J8;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J8_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J8_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J8_485RxBuffer, J8_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J8_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J8_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J9口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J9_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J9_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J9_handle) == 1)
|
||||
&& (maxdataLen > J9_485RxBufferIndex)) {
|
||||
J9_485RxBuffer[J9_485RxBufferIndex++] = uart_dev_in_char(g_J9_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J9_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J9_485RxBufferIndex + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J9_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J9_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(slaveQueueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = J9;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J9_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J9_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J9_485RxBuffer, J9_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J9_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J9_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
|
||||
#include "slaveBusIdleDetection.h"
|
||||
#include "semphr.h"
|
||||
|
||||
|
||||
static TimerHandle_t J1_485_Swtmr = NULL;
|
||||
static TimerHandle_t J3_485_Swtmr = NULL;
|
||||
static TimerHandle_t J5_485_Swtmr = NULL;
|
||||
static TimerHandle_t J7_485_Swtmr = NULL;
|
||||
static TimerHandle_t J8_485_Swtmr = NULL;
|
||||
static TimerHandle_t J9_485_Swtmr = NULL;
|
||||
|
||||
static void J1_485_tmrCallback(void* parameter);
|
||||
static void J3_485_tmrCallback(void* parameter);
|
||||
static void J5_485_tmrCallback(void* parameter);
|
||||
static void J7_485_tmrCallback(void* parameter);
|
||||
static void J8_485_tmrCallback(void* parameter);
|
||||
static void J9_485_tmrCallback(void* parameter);
|
||||
|
||||
// 创建二值信号量
|
||||
SemaphoreHandle_t J1_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J3_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J5_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J7_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J8_IDLESemaphore = NULL;
|
||||
SemaphoreHandle_t J9_IDLESemaphore = NULL;
|
||||
|
||||
|
||||
|
||||
/* 设置延时时间为30mS */
|
||||
#define softwareDelay (30 / (1000 / configTICK_RATE_HZ))
|
||||
|
||||
/*
|
||||
* @brief 初始化所有用于空闲检测的软件定时器和二值变量
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void slaveIdleInit(void)
|
||||
{
|
||||
J1_485_Swtmr = xTimerCreate((const char*)"J1Timer",
|
||||
softwareDelay, //延时
|
||||
(UBaseType_t )pdFALSE, //单次模式
|
||||
(void *)1, //为每个计时器分配一个索引的唯一ID
|
||||
(TimerCallbackFunction_t)J1_485_tmrCallback); //回调函数
|
||||
|
||||
J3_485_Swtmr = xTimerCreate((const char*)"J3Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J3_485_tmrCallback);
|
||||
|
||||
J5_485_Swtmr = xTimerCreate((const char*)"J5Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J5_485_tmrCallback);
|
||||
|
||||
J7_485_Swtmr = xTimerCreate((const char*)"J7Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J7_485_tmrCallback);
|
||||
|
||||
J8_485_Swtmr = xTimerCreate((const char*)"J8Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J8_485_tmrCallback);
|
||||
|
||||
J9_485_Swtmr = xTimerCreate((const char*)"J9Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J9_485_tmrCallback);
|
||||
|
||||
J1_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J1_IDLESemaphore);
|
||||
J3_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J3_IDLESemaphore);
|
||||
J5_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J5_IDLESemaphore);
|
||||
J7_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J7_IDLESemaphore);
|
||||
J8_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J8_IDLESemaphore);
|
||||
J9_IDLESemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J9_IDLESemaphore);
|
||||
}
|
||||
|
||||
void J1_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J1_IDLESemaphore, 0);
|
||||
}
|
||||
void J3_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J3_IDLESemaphore, 0);
|
||||
}
|
||||
void J5_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J5_IDLESemaphore, 0);
|
||||
}
|
||||
void J7_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J7_IDLESemaphore, 0);
|
||||
}
|
||||
void J8_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J8_IDLESemaphore, 0);
|
||||
}
|
||||
void J9_485_tmrCallback(void* parameter)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J9_IDLESemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @brief 空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J1_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J1_485_Swtmr, 0);
|
||||
}
|
||||
void J3_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J3_485_Swtmr, 0);
|
||||
}
|
||||
void J5_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J5_485_Swtmr, 0);
|
||||
}
|
||||
void J7_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J7_485_Swtmr, 0);
|
||||
}
|
||||
void J8_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J8_485_Swtmr, 0);
|
||||
}
|
||||
void J9_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J9_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J1_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J1_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J1_IDLESemaphore, 0);
|
||||
}
|
||||
void J3_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J3_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J3_IDLESemaphore, 0);
|
||||
}
|
||||
void J5_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J5_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J5_IDLESemaphore, 0);
|
||||
}
|
||||
void J7_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J7_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J7_IDLESemaphore, 0);
|
||||
}
|
||||
void J8_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J8_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J8_IDLESemaphore, 0);
|
||||
}
|
||||
void J9_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J9_485_Swtmr, 0);
|
||||
xSemaphoreTakeFromISR(J9_IDLESemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "slaveFreerotsTask.h"
|
||||
|
||||
// #include "HD_Flash.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "uart_dev.h"
|
||||
#include "FM_ADC.h"
|
||||
|
||||
#include "slaveParameter.h"
|
||||
#include "slaveBusIdleDetection.h"
|
||||
#include "slaveMcuDataParse.h"
|
||||
#include "slaveQueueUart.h"
|
||||
#include "slave485DataParse.h"
|
||||
|
||||
/* 发送任务 */
|
||||
#define J1_Transmit_TASK_PRIO 7
|
||||
#define J1_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J1_TransmitTask_Handler;
|
||||
static void J1_transmit_Task(void *pvParameters);
|
||||
#define J3_Transmit_TASK_PRIO 7
|
||||
#define J3_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J3_TransmitTask_Handler;
|
||||
static void J3_transmit_Task(void *pvParameters);
|
||||
#define J5_Transmit_TASK_PRIO 7
|
||||
#define J5_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J5_TransmitTask_Handler;
|
||||
static void J5_transmit_Task(void *pvParameters);
|
||||
#define J7_Transmit_TASK_PRIO 7
|
||||
#define J7_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J7_TransmitTask_Handler;
|
||||
static void J7_transmit_Task(void *pvParameters);
|
||||
#define J8_Transmit_TASK_PRIO 7
|
||||
#define J8_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J8_TransmitTask_Handler;
|
||||
static void J8_transmit_Task(void *pvParameters);
|
||||
#define J9_Transmit_TASK_PRIO 7
|
||||
#define J9_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t J9_TransmitTask_Handler;
|
||||
static void J9_transmit_Task(void *pvParameters);
|
||||
#define slaveMcu_Transmit_TASK_PRIO 7
|
||||
#define slaveMcu_Transmit_STK_SIZE 64
|
||||
static TaskHandle_t slaveMcu_TransmitTask_Handler;
|
||||
static void slaveMcu_transmit_Task(void *pvParameters);
|
||||
|
||||
/* 释放内存任务 */
|
||||
#define slaveFreeMemory_TASK_PRIO 8
|
||||
#define slaveFreeMemory_STK_SIZE 64
|
||||
static TaskHandle_t slaveFreeMemory_Handler;
|
||||
static void slaveFreeMemory_Task(void *pvParameters);
|
||||
|
||||
/* 解析任务 */
|
||||
#define slaveMcuDataParse_TASK_PRIO 5
|
||||
#define slaveMcuDataParse_STK_SIZE 512
|
||||
static TaskHandle_t slaveMcuDataParse_Handler;
|
||||
static void slaveMcuDataParse_Task(void *pvParameters);
|
||||
|
||||
#define slave485DataParse_TASK_PRIO 5
|
||||
#define slave485DataParse_STK_SIZE 512
|
||||
static TaskHandle_t slave485DataParse_Handler;
|
||||
static void slave485DataParse_Task(void *pvParameters);
|
||||
|
||||
/* 其他任务 */
|
||||
#define slaveOther_TASK_PRIO 3
|
||||
#define slaveOther_STK_SIZE 64
|
||||
static TaskHandle_t slaveOther_Handler;
|
||||
static void slaveOther_Task(void *pvParameters);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将数据发送
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J1_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J1QueueSend();
|
||||
}
|
||||
}
|
||||
void J3_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J3QueueSend();
|
||||
}
|
||||
}
|
||||
void J5_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J5QueueSend();
|
||||
}
|
||||
}
|
||||
void J7_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J7QueueSend();
|
||||
}
|
||||
}
|
||||
void J8_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J8QueueSend();
|
||||
}
|
||||
}
|
||||
void J9_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J9QueueSend();
|
||||
}
|
||||
}
|
||||
void slaveMcu_transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
slaveMcuQueueSend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 数据发送完成后,将申请存放数据的内存释放
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveFreeMemory_Task(void *pvParameters)
|
||||
{
|
||||
while(1) {
|
||||
binarySemaphoreFreeMemory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析主mcu发送来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveMcuDataParse_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
slaveMcuUartDataAnalysis(g_Mcu_handle);
|
||||
vTaskDelay(10);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析传感器发送来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slave485DataParse_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
J1_SensorDataAnalysis();
|
||||
J3_SensorDataAnalysis();
|
||||
J5_SensorDataAnalysis();
|
||||
J7_SensorDataAnalysis();
|
||||
J8_SensorDataAnalysis();
|
||||
J9_SensorDataAnalysis();
|
||||
vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 其他的一些任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveOther_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveStartApp(void)
|
||||
{
|
||||
SlaveMcu_GPIO_Init();
|
||||
readSlaveConfigParameter();
|
||||
SlaveMcu_uartBuf_Init(256, 1024);
|
||||
Init_J1_485(getJ1_485_Baud());
|
||||
Init_J3_485(getJ3_485_Baud());
|
||||
Init_J5_485(getJ5_485_Baud());
|
||||
Init_J7_485(getJ7_485_Baud());
|
||||
Init_J8_485(getJ8_485_Baud());
|
||||
Init_J9_485(getJ9_485_Baud());
|
||||
Init_Mcu_Uart(115200);
|
||||
|
||||
applyDataBuffer();
|
||||
slaveUartSendInit();
|
||||
slaveIdleInit();
|
||||
SlaveMcu_485DE_Read();
|
||||
|
||||
/* create task */
|
||||
xTaskCreate((TaskFunction_t )J1_transmit_Task,
|
||||
(const char* )"J1TransmitTask",
|
||||
(uint16_t )J1_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J1_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J1_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J3_transmit_Task,
|
||||
(const char* )"J3TransmitTask",
|
||||
(uint16_t )J3_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J3_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J3_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J5_transmit_Task,
|
||||
(const char* )"J5TransmitTask",
|
||||
(uint16_t )J5_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J5_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J5_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J7_transmit_Task,
|
||||
(const char* )"J7TransmitTask",
|
||||
(uint16_t )J7_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J7_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J7_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J8_transmit_Task,
|
||||
(const char* )"J8TransmitTask",
|
||||
(uint16_t )J8_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J8_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J8_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )J9_transmit_Task,
|
||||
(const char* )"J9TransmitTask",
|
||||
(uint16_t )J9_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )J9_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&J9_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )slaveMcu_transmit_Task,
|
||||
(const char* )"slaveMcuTransmitTask",
|
||||
(uint16_t )slaveMcu_Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )slaveMcu_Transmit_TASK_PRIO,
|
||||
(TaskHandle_t* )&slaveMcu_TransmitTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )slaveFreeMemory_Task,
|
||||
(const char* )"slaveFreeMemoryTask",
|
||||
(uint16_t )slaveFreeMemory_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )slaveFreeMemory_TASK_PRIO,
|
||||
(TaskHandle_t* )&slaveFreeMemory_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )slaveMcuDataParse_Task,
|
||||
(const char* )"slaveMcuDataParse",
|
||||
(uint16_t )slaveMcuDataParse_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )slaveMcuDataParse_TASK_PRIO,
|
||||
(TaskHandle_t* )&slaveMcuDataParse_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )slave485DataParse_Task,
|
||||
(const char* )"slave485DataParse",
|
||||
(uint16_t )slave485DataParse_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )slave485DataParse_TASK_PRIO,
|
||||
(TaskHandle_t* )&slave485DataParse_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )slaveOther_Task,
|
||||
(const char* )"slaveOtherTask",
|
||||
(uint16_t )slaveOther_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )slaveOther_TASK_PRIO,
|
||||
(TaskHandle_t* )&slaveOther_Handler);
|
||||
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,320 @@
|
|||
|
||||
#include "slaveMcuComm.h"
|
||||
#include "slaveQueueUart.h"
|
||||
#include "slaveParameter.h"
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "mcu_common.h"
|
||||
|
||||
/* 配置文件数据类型表 */
|
||||
enum {
|
||||
/* (1字节)对智能模块通信波特率(00H:不使用该串口, 01H:4800;02H:9600;03H:19200;04H:38400;05H:57600;06H:115200) */
|
||||
J1_485_Communication_Baud_Rate = 0x0001,
|
||||
J3_485_Communication_Baud_Rate = 0x0002,
|
||||
J5_485_Communication_Baud_Rate = 0x0003,
|
||||
J7_485_Communication_Baud_Rate = 0x0004,
|
||||
J8_485_Communication_Baud_Rate = 0x0005,
|
||||
J9_485_Communication_Baud_Rate = 0x0006,
|
||||
};
|
||||
|
||||
/* 寄存器解析 */
|
||||
static uint16_t ReadRegisterJ1Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ3Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ5Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ7Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ8Baud(void *pMsg);
|
||||
static uint16_t ReadRegisterJ9Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ1Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ3Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ5Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ7Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ8Baud(void *pMsg);
|
||||
static uint16_t WriteRegisterJ9Baud(void *pMsg);
|
||||
|
||||
|
||||
/* 寄存器处理表 */
|
||||
typedef uint16_t (*RegProcFunc)(void*);
|
||||
typedef struct _SL_RegProcTable{
|
||||
uint32_t regId;
|
||||
RegProcFunc pRegProc;
|
||||
}SL_RegProcTable;
|
||||
|
||||
/* 读取寄存器处理表 */
|
||||
SL_RegProcTable g_RegTblR[] =
|
||||
{
|
||||
{J1_485_Communication_Baud_Rate, ReadRegisterJ1Baud},
|
||||
{J3_485_Communication_Baud_Rate, ReadRegisterJ3Baud},
|
||||
{J5_485_Communication_Baud_Rate, ReadRegisterJ5Baud},
|
||||
{J7_485_Communication_Baud_Rate, ReadRegisterJ7Baud},
|
||||
{J8_485_Communication_Baud_Rate, ReadRegisterJ8Baud},
|
||||
{J9_485_Communication_Baud_Rate, ReadRegisterJ9Baud},
|
||||
};
|
||||
|
||||
/* 写入寄存器处理表 */
|
||||
SL_RegProcTable g_RegTblW[] =
|
||||
{
|
||||
{J1_485_Communication_Baud_Rate, WriteRegisterJ1Baud},
|
||||
{J3_485_Communication_Baud_Rate, WriteRegisterJ3Baud},
|
||||
{J5_485_Communication_Baud_Rate, WriteRegisterJ5Baud},
|
||||
{J7_485_Communication_Baud_Rate, WriteRegisterJ7Baud},
|
||||
{J8_485_Communication_Baud_Rate, WriteRegisterJ8Baud},
|
||||
{J9_485_Communication_Baud_Rate, WriteRegisterJ9Baud},
|
||||
};
|
||||
|
||||
static void SlaveMcuReadRegister(uint8_t *buff, uint8_t dataLen)
|
||||
{
|
||||
uint16_t Register_Start_Address = (buff[6] << 8) | buff[7];
|
||||
uint16_t Register_Number = (buff[8] << 8) | buff[9];
|
||||
|
||||
/* 初始化发送内存 */
|
||||
//系统内存不足,丢去当前包
|
||||
uint32_t tempLen = 13 + 2 * Register_Number + slaveQueueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = 13 + 2 * Register_Number;
|
||||
sendBuff->data = Buff + slaveQueueUartSendInfoSize;
|
||||
|
||||
uint8_t *replay_pack = sendBuff->data;
|
||||
/* 起始标志 */
|
||||
*(replay_pack) = 'S';
|
||||
*(replay_pack + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = SlaveMcu;
|
||||
|
||||
/* 回复字节长度 */
|
||||
replay_pack += 1;
|
||||
*(replay_pack) = (uint8_t)((sendBuff->length - 6) >> 8);
|
||||
*(replay_pack + 1) = (uint8_t)(sendBuff->length - 6);
|
||||
|
||||
/* 功能码 */
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = SL_Function_Code_Read_Register;
|
||||
|
||||
/* 读取寄存器起始地址 */
|
||||
replay_pack += 1;
|
||||
*(replay_pack) = buff[6];
|
||||
*(replay_pack + 1) = buff[7];
|
||||
|
||||
/* 回复字节长度 */
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = (uint8_t)((sendBuff->length - 13) >> 8);
|
||||
*(replay_pack + 1) = (uint8_t)(sendBuff->length - 13);
|
||||
|
||||
/* 回复数据内容 */
|
||||
/* 读取数据 */
|
||||
for ( uint16_t pos = 0; pos < Register_Number; pos++) {
|
||||
for (uint16_t var = 0; var < sizeof(g_RegTblR) / sizeof(SL_RegProcTable); var++) {
|
||||
if (g_RegTblR[var].regId == (Register_Start_Address + pos)) {
|
||||
uint16_t temp = g_RegTblR[var].pRegProc(NULL);
|
||||
replay_pack += 2;
|
||||
*(replay_pack) = (uint8_t)(temp >> 8);
|
||||
*(replay_pack + 1) = (uint8_t)(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 校验位 */
|
||||
replay_pack += 2;
|
||||
uint16_t crc_temp = modebusCrc(sendBuff->data, sendBuff->length - 3);
|
||||
*replay_pack = (uint8_t)(crc_temp >> 8);
|
||||
replay_pack += 1;
|
||||
*replay_pack = (uint8_t)crc_temp;
|
||||
|
||||
/* 结束标志 */
|
||||
replay_pack += 1;
|
||||
*replay_pack = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(mcu_uart_Queue)) {
|
||||
xQueueSend(mcu_uart_Queue, &Buff, 10);
|
||||
}
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
|
||||
static void SlaveMcuWriteRegister(uint8_t *buff, uint8_t dataLen)
|
||||
{
|
||||
uint16_t Register_Start_Address = (buff[6] << 8) | buff[7];
|
||||
uint16_t Register_Number = (buff[8] << 8) | buff[9];
|
||||
|
||||
/* 将数据写入到寄存器中 */
|
||||
for ( uint16_t pos = 0; pos < Register_Number; pos++) {
|
||||
for (uint16_t i = 0; i < sizeof(g_RegTblW) / sizeof(SL_RegProcTable); i++) {
|
||||
if (g_RegTblW[i].regId == (Register_Start_Address + pos)) {
|
||||
uint16_t data = buff[10 + 2 * pos] << 8 | buff[10 + 2 * pos + 1];
|
||||
g_RegTblW[i].pRegProc(&data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 后续将数据存入配置文件中 */
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void slaveFrameDataAnalyze(uint8_t *buff, uint8_t dataLen)
|
||||
{
|
||||
uint16_t crc = (buff[dataLen - 4] << 8) | buff[dataLen - 3];
|
||||
if (crc != modebusCrc(buff, dataLen - 3)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buff[5] == SL_Function_Code_Read_Register) {
|
||||
SlaveMcuReadRegister(buff, dataLen);
|
||||
}
|
||||
else if (buff[5] == SL_Function_Code_Write_Register) {
|
||||
SlaveMcuWriteRegister(buff, dataLen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J1波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ1Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ1_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J3波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ3Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ3_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J5波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ5Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ5_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J7波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ7Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ7_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J8波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ8Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ8_485_Baud());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取J9波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t ReadRegisterJ9Baud(void *pMsg)
|
||||
{
|
||||
return baudConversionConfig(getJ9_485_Baud());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 设置端口1波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ1Baud(void *pMsg)
|
||||
{
|
||||
setJ1_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J1_485(getJ1_485_Baud());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置端口3波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ3Baud(void *pMsg)
|
||||
{
|
||||
setJ3_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J3_485(getJ3_485_Baud());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 设置端口1波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ5Baud(void *pMsg)
|
||||
{
|
||||
setJ5_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J5_485(getJ5_485_Baud());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置端口7波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ7Baud(void *pMsg)
|
||||
{
|
||||
setJ7_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J7_485(getJ7_485_Baud());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置端口8波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ8Baud(void *pMsg)
|
||||
{
|
||||
setJ8_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J8_485(getJ8_485_Baud());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置端口9波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t WriteRegisterJ9Baud(void *pMsg)
|
||||
{
|
||||
setJ9_485_Baud(configConversionBaud(*(uint16_t *)pMsg));
|
||||
Init_J9_485(getJ9_485_Baud());
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,286 @@
|
|||
|
||||
#include "slaveMcuDataParse.h"
|
||||
#include "slaveMcuComm.h"
|
||||
|
||||
static void stateMachine(void);
|
||||
|
||||
/* 状态机函数 */
|
||||
static uint8_t analysisWait(void);
|
||||
static uint8_t analysisStartFlagSL(void);
|
||||
static uint8_t analysisPortSL(void);
|
||||
static uint8_t analysisLengthSL(void);
|
||||
static uint8_t analysisEndFlagSL(void);
|
||||
|
||||
/**
|
||||
* @brief 状态机函数
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void stateMachine(void)
|
||||
{
|
||||
if (state == wait) {
|
||||
if (analysisWait() == TRUE) {
|
||||
mcuUartRxTime = xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
|
||||
else if (state == startFlagSL) {
|
||||
analysisStartFlagSL();
|
||||
}
|
||||
|
||||
else if (state == portSL) {
|
||||
analysisPortSL();
|
||||
}
|
||||
|
||||
else if (state == lengthSL) {
|
||||
analysisLengthSL();
|
||||
}
|
||||
|
||||
else if (state == endFlagSL) {
|
||||
analysisEndFlagSL();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 状态 wait
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define waitMaxLen 2
|
||||
uint8_t analysisWait(void)
|
||||
{
|
||||
if (mcuUartRxBufferIndex >= 2) {
|
||||
/* 透传数据帧包头 */
|
||||
if (mcuUartRxBuffer[0] == 'S' && mcuUartRxBuffer[1] == 'L') {
|
||||
// log_info("startFlagSL\n");
|
||||
state = startFlagSL;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mcuUartRxBufferIndex < waitMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 startFlagSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
uint8_t analysisStartFlagSL(void)
|
||||
{
|
||||
/* 校验端口号 */
|
||||
if (mcuUartRxBuffer[2] < 13) {
|
||||
// log_info("portSL\n");
|
||||
state = portSL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// log_error("portSL %d \n", gw485RxBuffer[2]);
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 portSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define PortSLMaxLen 5
|
||||
uint8_t analysisPortSL(void)
|
||||
{
|
||||
/* 解析数据包的度 */
|
||||
if (mcuUartRxBufferIndex >= PortSLMaxLen) {
|
||||
uint32_t tempLen = 0;
|
||||
tempLen = (mcuUartRxBuffer[3] << 8) | mcuUartRxBuffer[4];
|
||||
|
||||
if (tempLen <= 1024) {
|
||||
// log_info("lengthSL\n");
|
||||
state = lengthSL;
|
||||
frameLength = 6 + tempLen;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mcuUartRxBufferIndex < PortSLMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// log_error("lengthSL %d \n", (gw485RxBuffer[3] << 8) | gw485RxBuffer[4]);
|
||||
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 lengthSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
#define LengthSLMaxLen frameLength
|
||||
uint8_t analysisLengthSL(void)
|
||||
{
|
||||
/* 解析帧尾 */
|
||||
if (mcuUartRxBufferIndex >= LengthSLMaxLen) {
|
||||
if (mcuUartRxBuffer[LengthSLMaxLen - 1] == 0x17) {
|
||||
// log_info("endFlagSL\n");
|
||||
state = endFlagSL;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (mcuUartRxBufferIndex < LengthSLMaxLen) {
|
||||
return FALSE;
|
||||
}
|
||||
// log_info("endFlagSL %d\n", gw485RxBuffer[LengthSLMaxLen - 1]);
|
||||
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex--;
|
||||
memcpy(mcuUartRxBuffer, mcuUartRxBuffer + 1, mcuUartRxBufferIndex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 状态 endFlagSL
|
||||
* @param
|
||||
* @retval 0:解析失败
|
||||
1:解析成功
|
||||
*/
|
||||
uint8_t analysisEndFlagSL(void)
|
||||
{
|
||||
uint32_t tempLen = 0;
|
||||
tempLen = (mcuUartRxBuffer[3] << 8) | mcuUartRxBuffer[4];
|
||||
|
||||
if (mcuUartRxBuffer[2] == SlaveMcu) {
|
||||
slaveFrameDataAnalyze(mcuUartRxBuffer, mcuUartRxBufferIndex);
|
||||
mcuUartRxBufferIndex = 0;
|
||||
state = wait;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//系统内存不足,丢去当前包
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 对于不同通端口,传输的结构体不同 */
|
||||
uint8_t *Buff;
|
||||
|
||||
Buff = (uint8_t *)pvPortMalloc(tempLen + slaveQueueUartSendInfoSize);
|
||||
slaveQueueUartSendInfo *sendBuff = (slaveQueueUartSendInfo *)Buff;
|
||||
sendBuff->length = tempLen;
|
||||
sendBuff->data = Buff + slaveQueueUartSendInfoSize;
|
||||
memcpy((char *)sendBuff->data, (char *)&mcuUartRxBuffer[5], tempLen);
|
||||
|
||||
|
||||
/* 通过不同的端口将数据发送到不同的地方 */
|
||||
if (mcuUartRxBuffer[2] == J1) {
|
||||
if (uxQueueSpacesAvailable(J1_485_Queue)) {
|
||||
xQueueSend(J1_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (mcuUartRxBuffer[2] == J3) {
|
||||
if (uxQueueSpacesAvailable(J3_485_Queue)) {
|
||||
xQueueSend(J3_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (mcuUartRxBuffer[2] == J5) {
|
||||
if (uxQueueSpacesAvailable(J5_485_Queue)) {
|
||||
xQueueSend(J5_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (mcuUartRxBuffer[2] == J7) {
|
||||
if (uxQueueSpacesAvailable(J7_485_Queue)) {
|
||||
xQueueSend(J7_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (mcuUartRxBuffer[2] == J8) {
|
||||
if (uxQueueSpacesAvailable(J8_485_Queue)) {
|
||||
xQueueSend(J8_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
else if (mcuUartRxBuffer[2] == J9) {
|
||||
if (uxQueueSpacesAvailable(J9_485_Queue)) {
|
||||
xQueueSend(J9_485_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列中无空间,释放内存,退出 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
}
|
||||
|
||||
err:
|
||||
//清零buff
|
||||
state = wait;
|
||||
mcuUartRxBufferIndex = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 解析智能模块发送来的数据
|
||||
* @param device 用于接收智能模块发送来的数据的串口设备
|
||||
* @retval
|
||||
*/
|
||||
void slaveMcuUartDataAnalysis(device_handle device)
|
||||
{
|
||||
/* 每次函数最多执行10ms */
|
||||
static uint32_t tickstart = 0U;
|
||||
tickstart = xTaskGetTickCount();
|
||||
|
||||
/* 2S未解析出来一帧数据,将数据清零 */
|
||||
if (getTickDiff(mcuUartRxTime) >= tick_2S) {
|
||||
mcuUartRxTime = xTaskGetTickCount();
|
||||
mcuUartRxBufferIndex = 0;
|
||||
state = wait;
|
||||
}
|
||||
|
||||
while (uart_dev_char_present(device) == 1 && ((xTaskGetTickCount() - tickstart) < 5)) {
|
||||
mcuUartRxBuffer[mcuUartRxBufferIndex++] = uart_dev_in_char(device);
|
||||
stateMachine();
|
||||
}
|
||||
|
||||
if (uart_dev_char_present(device) != 1 && state != wait) {
|
||||
stateMachine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
#include "slaveParameter.h"
|
||||
|
||||
typedef struct _parameterInfo {
|
||||
uint32_t J1_485_Baud; //与J1_485通信波特率
|
||||
uint32_t J3_485_Baud; //与J3_485通信波特率
|
||||
uint32_t J5_485_Baud; //与J5_485通信波特率
|
||||
uint32_t J7_485_Baud; //与J7_485通信波特率
|
||||
uint32_t J8_485_Baud; //与J8_485通信波特率
|
||||
uint32_t J9_485_Baud; //与J9_485通信波特率
|
||||
} slaveParameterInfo;
|
||||
|
||||
static slaveParameterInfo slaveParameter = {0};
|
||||
|
||||
#define configSize (sizeof(configInfo))
|
||||
|
||||
/**
|
||||
* @brief 读取配置文件参数
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void readSlaveConfigParameter(void)
|
||||
{
|
||||
/* 使用默认参数 */
|
||||
slaveParameter.J1_485_Baud = 9600;
|
||||
slaveParameter.J3_485_Baud = 9600;
|
||||
slaveParameter.J5_485_Baud = 9600;
|
||||
slaveParameter.J7_485_Baud = 9600;
|
||||
slaveParameter.J8_485_Baud = 9600;
|
||||
slaveParameter.J9_485_Baud = 9600;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J1通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ1_485_Baud(void)
|
||||
{
|
||||
return slaveParameter.J1_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J1通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ1_485_Baud(uint32_t Baud)
|
||||
{
|
||||
slaveParameter.J1_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J3通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ3_485_Baud(void)
|
||||
{
|
||||
return slaveParameter.J3_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J3通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ3_485_Baud(uint32_t Baud)
|
||||
{
|
||||
slaveParameter.J3_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J5通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ5_485_Baud(void)
|
||||
{
|
||||
return slaveParameter.J5_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J5通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ5_485_Baud(uint32_t Baud)
|
||||
{
|
||||
slaveParameter.J5_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J7通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ7_485_Baud(void)
|
||||
{
|
||||
return slaveParameter.J7_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J7通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ7_485_Baud(uint32_t Baud)
|
||||
{
|
||||
slaveParameter.J7_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J8通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ8_485_Baud(void)
|
||||
{
|
||||
return slaveParameter.J8_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J8通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ8_485_Baud(uint32_t Baud)
|
||||
{
|
||||
slaveParameter.J8_485_Baud = Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到对J9通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getJ9_485_Baud(void)
|
||||
{
|
||||
return slaveParameter.J9_485_Baud;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置J9通信波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setJ9_485_Baud(uint32_t Baud)
|
||||
{
|
||||
slaveParameter.J9_485_Baud = Baud;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,430 @@
|
|||
|
||||
#include "slaveQueueUart.h"
|
||||
#include "uart_dev.h"
|
||||
#include "slaveBusIdleDetection.h"
|
||||
|
||||
#include "FM_GPIO.h"
|
||||
|
||||
#include "semphr.h"
|
||||
|
||||
/* 队列中每个消息的大小 */
|
||||
#define QUEUE_SIZE 4
|
||||
|
||||
/* 485队列的长度 */
|
||||
#define rs485QueueLength 5
|
||||
#define mcuUartQueueLength 10
|
||||
|
||||
/* 各个通讯口的队列 */
|
||||
QueueHandle_t J1_485_Queue = NULL;
|
||||
QueueHandle_t J3_485_Queue = NULL;
|
||||
QueueHandle_t J5_485_Queue = NULL;
|
||||
QueueHandle_t J7_485_Queue = NULL;
|
||||
QueueHandle_t J8_485_Queue = NULL;
|
||||
QueueHandle_t J9_485_Queue = NULL;
|
||||
QueueHandle_t mcu_uart_Queue = NULL;
|
||||
|
||||
/* 创建二值信号量 */
|
||||
static SemaphoreHandle_t J1_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J3_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J5_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J7_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J8_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t J9_FreeMemorySemaphore = NULL;
|
||||
static SemaphoreHandle_t slaveMcu_uart_FreeMemorySemaphore = NULL;
|
||||
// 创建队列集
|
||||
static QueueSetHandle_t slaveBinarySemaphoreSet = NULL;
|
||||
/* 创建二值信号量 */
|
||||
static SemaphoreHandle_t J1_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J3_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J5_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J7_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J8_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t J9_sendOverSemaphore = NULL;
|
||||
static SemaphoreHandle_t slaveMcu_uart_sendOverSemaphore = NULL;
|
||||
|
||||
|
||||
/* 通过该结构体接收对应的数据用来发送,结束后通过该结构体,释放数据的内存 */
|
||||
typedef struct _slaveQueueSendDataInfo {
|
||||
slaveQueueUartSendInfo *J1_485_data;
|
||||
slaveQueueUartSendInfo *J3_485_data;
|
||||
slaveQueueUartSendInfo *J5_485_data;
|
||||
slaveQueueUartSendInfo *J7_485_data;
|
||||
slaveQueueUartSendInfo *J8_485_data;
|
||||
slaveQueueUartSendInfo *J9_485_data;
|
||||
slaveQueueUartSendInfo *mcu_uart_data;
|
||||
} slaveQueueSendDataInfo;
|
||||
static slaveQueueSendDataInfo slaveQueueSendData;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化串口发送使用到的队列和释放内存所使用的信号量
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveUartSendInit(void)
|
||||
{
|
||||
/* 初始化队列 */
|
||||
J1_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J3_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J5_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J7_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J8_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
J9_485_Queue = xQueueCreate(rs485QueueLength, QUEUE_SIZE);
|
||||
mcu_uart_Queue = xQueueCreate(mcuUartQueueLength, QUEUE_SIZE);
|
||||
|
||||
/* 初始化释放内存二值变量 */
|
||||
J1_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J3_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J5_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J7_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J8_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
J9_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
slaveMcu_uart_FreeMemorySemaphore = xSemaphoreCreateBinary();
|
||||
// 初始化队列集
|
||||
slaveBinarySemaphoreSet = xQueueCreateSet(7);
|
||||
// 将二值信号量添加到队列集中
|
||||
xQueueAddToSet(J1_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
xQueueAddToSet(J3_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
xQueueAddToSet(J5_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
xQueueAddToSet(J7_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
xQueueAddToSet(J8_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
xQueueAddToSet(J9_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
xQueueAddToSet(slaveMcu_uart_FreeMemorySemaphore, slaveBinarySemaphoreSet);
|
||||
|
||||
/* 发送完成信号量 */
|
||||
J1_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J1_sendOverSemaphore);
|
||||
J3_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J3_sendOverSemaphore);
|
||||
J5_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J5_sendOverSemaphore);
|
||||
J7_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J7_sendOverSemaphore);
|
||||
J8_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J8_sendOverSemaphore);
|
||||
J9_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(J9_sendOverSemaphore);
|
||||
slaveMcu_uart_sendOverSemaphore = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(slaveMcu_uart_sendOverSemaphore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J1队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J1QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J1_485_Queue, slaveQueueSendData.J1_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J1_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J1_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_J1_handle, slaveQueueSendData.J1_485_data->data
|
||||
, slaveQueueSendData.J1_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J3队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J3QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J3_485_Queue, slaveQueueSendData.J3_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J3_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J3_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_J3_handle, slaveQueueSendData.J3_485_data->data
|
||||
, slaveQueueSendData.J3_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J5队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J5QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J5_485_Queue, slaveQueueSendData.J5_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J5_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J5_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_J5_handle, slaveQueueSendData.J5_485_data->data
|
||||
, slaveQueueSendData.J5_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J7队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J7QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J7_485_Queue, slaveQueueSendData.J7_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J7_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J7_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_J7_handle, slaveQueueSendData.J7_485_data->data
|
||||
, slaveQueueSendData.J7_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J8队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J8QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J8_485_Queue, slaveQueueSendData.J8_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J8_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J8_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_J8_handle, slaveQueueSendData.J8_485_data->data
|
||||
, slaveQueueSendData.J8_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从J9队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J9QueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(J9_485_Queue, slaveQueueSendData.J9_485_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(J9_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 总线空闲 */
|
||||
if (xSemaphoreTake(J9_IDLESemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_J9_handle, slaveQueueSendData.J9_485_data->data
|
||||
, slaveQueueSendData.J9_485_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从slaveMcu队列中取出数据,并完成发送,无数据或不满足发送条件时,处于阻塞状态
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void slaveMcuQueueSend(void)
|
||||
{
|
||||
/* 有数据需要发送 */
|
||||
if (xQueueReceive(mcu_uart_Queue, slaveQueueSendData.mcu_uart_data, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
/* 上次数据发送完成 */
|
||||
if (xSemaphoreTake(slaveMcu_uart_sendOverSemaphore, portMAX_DELAY) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
slaveUartInterruptSend(g_Mcu_handle, slaveQueueSendData.mcu_uart_data->data
|
||||
, slaveQueueSendData.mcu_uart_data->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 数据发送完成后用于清除内存
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J1_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J1_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J3_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J3_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J5_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J5_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J7_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J7_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J8_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J8_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void J9_485_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(J9_FreeMemorySemaphore, 0);
|
||||
}
|
||||
void slaveMcu_uart_IN_TXE(void)
|
||||
{
|
||||
xSemaphoreGiveFromISR(slaveMcu_uart_FreeMemorySemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 通过二值信号量释放中断发送数据的内存
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void binarySemaphoreFreeMemory(void)
|
||||
{
|
||||
// 等待队列集中的事件
|
||||
QueueSetMemberHandle_t xActivatedMember = xQueueSelectFromSet(slaveBinarySemaphoreSet, portMAX_DELAY);
|
||||
|
||||
if (xActivatedMember == J1_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.J1_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ1_485;
|
||||
// 处理二值信号量事件
|
||||
xSemaphoreTake(J1_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J1_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J3_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.J3_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ3_485;
|
||||
xSemaphoreTake(J3_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J3_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J5_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.J5_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ5_485;
|
||||
xSemaphoreTake(J5_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J5_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J7_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.J7_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ7_485;
|
||||
xSemaphoreTake(J7_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J7_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J8_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.J8_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ8_485;
|
||||
xSemaphoreTake(J8_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J8_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J9_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.J9_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ9_485;
|
||||
xSemaphoreTake(J9_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(J9_sendOverSemaphore);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == slaveMcu_uart_FreeMemorySemaphore) {
|
||||
vPortFree(slaveQueueSendData.mcu_uart_data);
|
||||
xSemaphoreTake(slaveMcu_uart_FreeMemorySemaphore, 0);
|
||||
xSemaphoreGive(slaveMcu_uart_sendOverSemaphore);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通过中断发送
|
||||
* @param device 设备
|
||||
data 指向数据的指针
|
||||
len 数据长度
|
||||
* @retval 0:成功
|
||||
1:上次数据还未发送完成
|
||||
0xFF:错误
|
||||
*/
|
||||
uint8_t slaveUartInterruptSend(device_handle device,uint8_t *data, uint16_t len)
|
||||
{
|
||||
/* 指向数据 */
|
||||
uart_device_info *dev = (uart_device_info *)device;
|
||||
dev->uart_send_data.data = data;
|
||||
dev->uart_send_data.count = 0;
|
||||
dev->uart_send_data.len = len;
|
||||
|
||||
/* 开始发送 */
|
||||
if (device == g_J1_handle) {
|
||||
xSemaphoreTake(J1_sendOverSemaphore, 0);
|
||||
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_J3_handle) {
|
||||
xSemaphoreTake(J3_sendOverSemaphore, 0);
|
||||
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_J5_handle) {
|
||||
xSemaphoreTake(J5_sendOverSemaphore, 0);
|
||||
writeJ5_485;
|
||||
USART_ITConfig(J5_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(J5_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_J7_handle) {
|
||||
xSemaphoreTake(J7_sendOverSemaphore, 0);
|
||||
writeJ7_485;
|
||||
USART_ITConfig(J7_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(J7_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_J8_handle) {
|
||||
xSemaphoreTake(J8_sendOverSemaphore, 0);
|
||||
writeJ8_485;
|
||||
USART_ITConfig(J8_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(J8_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_J9_handle) {
|
||||
xSemaphoreTake(J9_sendOverSemaphore, 0);
|
||||
writeJ9_485;
|
||||
USART_ITConfig(J9_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(J9_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
else if (device == g_Mcu_handle) {
|
||||
xSemaphoreTake(slaveMcu_uart_sendOverSemaphore, 0);
|
||||
USART_ITConfig(Mcu_USART, USART_IT_TXE, ENABLE);
|
||||
USART_SendData(Mcu_USART, dev->uart_send_data.data[dev->uart_send_data.count++]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,220 +0,0 @@
|
|||
#include "busIdleDetection.h"
|
||||
|
||||
|
||||
#ifdef RS485BUSIDLE1
|
||||
#include "uart_dev.h"
|
||||
|
||||
/* 通过软件定时器的方式来完成 */
|
||||
static TimerHandle_t J1_485_Swtmr = NULL;
|
||||
static TimerHandle_t J2_485_Swtmr = NULL;
|
||||
static TimerHandle_t J3_485_Swtmr = NULL;
|
||||
static TimerHandle_t J4_485_Swtmr = NULL;
|
||||
static TimerHandle_t J5_0_485_Swtmr = NULL;
|
||||
|
||||
static void J1_485_tmrCallback(void* parameter);
|
||||
static void J2_485_tmrCallback(void* parameter);
|
||||
static void J3_485_tmrCallback(void* parameter);
|
||||
static void J4_485_tmrCallback(void* parameter);
|
||||
static void J5_0_485_tmrCallback(void* parameter);
|
||||
|
||||
#define softwareDelay (30 / (1000 / configTICK_RATE_HZ))
|
||||
|
||||
/*
|
||||
* @brief 初始化所有的软件定时器
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void softwareTimeInit(void)
|
||||
{
|
||||
J1_485_Swtmr = xTimerCreate((const char*)"J1Timer",
|
||||
softwareDelay, //延时
|
||||
(UBaseType_t )pdFALSE, //单次模式
|
||||
(void *)1, //为每个计时器分配一个索引的唯一ID
|
||||
(TimerCallbackFunction_t)J1_485_tmrCallback); //回调函数
|
||||
|
||||
J2_485_Swtmr = xTimerCreate((const char*)"J2Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)2,
|
||||
(TimerCallbackFunction_t)J2_485_tmrCallback);
|
||||
|
||||
J3_485_Swtmr = xTimerCreate((const char*)"J3Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)3,
|
||||
(TimerCallbackFunction_t)J3_485_tmrCallback);
|
||||
|
||||
J4_485_Swtmr = xTimerCreate((const char*)"J4Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)4,
|
||||
(TimerCallbackFunction_t)J4_485_tmrCallback);
|
||||
|
||||
J5_0_485_Swtmr = xTimerCreate((const char*)"J5_0Timer",
|
||||
softwareDelay,
|
||||
(UBaseType_t )pdFALSE,
|
||||
(void *)5,
|
||||
(TimerCallbackFunction_t)J5_0_485_tmrCallback);
|
||||
}
|
||||
|
||||
void J1_485_tmrCallback(void* parameter)
|
||||
{
|
||||
setBUSIDLEFlag(g_J1_uart6_handle, 0);
|
||||
}
|
||||
|
||||
void J2_485_tmrCallback(void* parameter)
|
||||
{
|
||||
setBUSIDLEFlag(g_J2_uart7_handle, 0);
|
||||
}
|
||||
|
||||
void J3_485_tmrCallback(void* parameter)
|
||||
{
|
||||
setBUSIDLEFlag(g_J3_usart2_handle, 0);
|
||||
}
|
||||
|
||||
void J4_485_tmrCallback(void* parameter)
|
||||
{
|
||||
setBUSIDLEFlag(g_J4_uart8_handle, 0);
|
||||
}
|
||||
|
||||
void J5_0_485_tmrCallback(void* parameter)
|
||||
{
|
||||
setBUSIDLEFlag(g_J5_0_usart3_handle, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J1_485空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J1_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J1_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J2_485空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J2_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J2_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J3_485空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J3_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J3_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J4_485空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J4_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J4_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J5_0_485空闲中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J5_0_485_IN_IDLE(void)
|
||||
{
|
||||
xTimerStartFromISR(J5_0_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J1_485空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J1_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J1_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J2_485空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J2_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J2_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J3_485空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J3_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J3_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J4_485空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J4_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J4_485_Swtmr, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief J5_0_485空闲中断后,第一次进入接收中断内容
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J5_0_485_IN_RXNE(void)
|
||||
{
|
||||
xTimerStopFromISR(J5_0_485_Swtmr, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @brief 得到串口能否发送
|
||||
* @param
|
||||
* @retval 0 能发送
|
||||
1 不能发送
|
||||
0xFF 错误
|
||||
*/
|
||||
uint8_t getRs485State(device_handle device)
|
||||
{
|
||||
#ifdef RS485BUSIDLE1
|
||||
#ifdef UARTINTERRUPTSEND
|
||||
return (getUartSendState(device) || getBUSIDLEFlag(device));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t getUartState(device_handle device)
|
||||
{
|
||||
#ifdef UARTINTERRUPTSEND
|
||||
return getUartSendState(device);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1,390 +0,0 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "downUartParse.h"
|
||||
#include "upUartParse.h"
|
||||
#include "queueUart.h"
|
||||
|
||||
// /* 1秒的节拍数 */
|
||||
// #define tick_1S configTICK_RATE_HZ
|
||||
|
||||
// /* 状态机 */
|
||||
// typedef enum {
|
||||
// wait = 0, /* 串口状态机初始状态 */
|
||||
// startFlag, /* 接收到帧头 */
|
||||
// // address, /* 设备地址 */
|
||||
// functionCode, /* 接收到功能码 */
|
||||
// dataLen, /* 接收到数据长度 */
|
||||
// crcCheckBitGW, /* 接收到校验位 */
|
||||
// endFlagGW, /* 接收到帧尾 */
|
||||
// } uartStateMachine;
|
||||
|
||||
|
||||
/* 储存gw485数据 */
|
||||
static uint8_t J1_485RxBuffer[128];
|
||||
static uint16_t J1_485RxBufferIndex = 0;
|
||||
static uint8_t J2_485RxBuffer[128];
|
||||
static uint16_t J2_485RxBufferIndex = 0;
|
||||
static uint8_t J3_485RxBuffer[128];
|
||||
static uint16_t J3_485RxBufferIndex = 0;
|
||||
static uint8_t J4_485RxBuffer[128];
|
||||
static uint16_t J4_485RxBufferIndex = 0;
|
||||
static uint8_t J5_0_485RxBuffer[128];
|
||||
static uint16_t J5_0_485RxBufferIndex = 0;
|
||||
|
||||
/* 100ms */
|
||||
#define delayTick 50
|
||||
#define maxdataLen 100
|
||||
|
||||
/**
|
||||
* @brief 接收J1口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J1_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J1_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J1_uart6_handle) == 1)
|
||||
&& (maxdataLen > J1_485RxBufferIndex)) {
|
||||
J1_485RxBuffer[J1_485RxBufferIndex++] = uart_dev_in_char(g_J1_uart6_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J1_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
uint32_t tempLen = 6 + J1_485RxBufferIndex + queueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J1_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J1_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(queueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = 1;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J1_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J1_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J1_485RxBuffer, J1_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J1_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(upward_uart_Queue)) {
|
||||
xQueueSend(upward_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
/* 发送完成或遇到问题,将buff中的数据清零 */
|
||||
J1_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J2口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J2_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J2_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J2_uart7_handle) == 1)
|
||||
&& (maxdataLen > J2_485RxBufferIndex)) {
|
||||
J2_485RxBuffer[J2_485RxBufferIndex++] = uart_dev_in_char(g_J2_uart7_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J2_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
|
||||
uint32_t tempLen = 6 + J2_485RxBufferIndex + queueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J2_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J2_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(queueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = 2;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J2_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J2_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J2_485RxBuffer, J2_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J2_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(upward_uart_Queue)) {
|
||||
xQueueSend(upward_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
J2_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J3口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J3_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J3_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J3_usart2_handle) == 1)
|
||||
&& (maxdataLen > J3_485RxBufferIndex)) {
|
||||
J3_485RxBuffer[J3_485RxBufferIndex++] = uart_dev_in_char(g_J3_usart2_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J3_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
|
||||
uint32_t tempLen = 6 + J3_485RxBufferIndex + queueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J3_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J3_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(queueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = 3;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J3_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J3_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J3_485RxBuffer, J3_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J3_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(upward_uart_Queue)) {
|
||||
xQueueSend(upward_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
J3_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J4口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J4_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J4_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J4_uart8_handle) == 1)
|
||||
&& (maxdataLen > J4_485RxBufferIndex)) {
|
||||
J4_485RxBuffer[J4_485RxBufferIndex++] = uart_dev_in_char(g_J4_uart8_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J4_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
|
||||
uint32_t tempLen = 6 + J4_485RxBufferIndex + queueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J4_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J4_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(queueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = 4;
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J4_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J4_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J4_485RxBuffer, J4_485RxBufferIndex);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J4_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(upward_uart_Queue)) {
|
||||
xQueueSend(upward_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
J4_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 接收J5_0口传来的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J5_0_SensorDataAnalysis(void)
|
||||
{
|
||||
static uint32_t tick;
|
||||
|
||||
if (J5_0_485RxBufferIndex == 0) {
|
||||
tick = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
/* 单次进入最多6ms(3个时钟周期),串口中有数据 */
|
||||
uint32_t nowTick = xTaskGetTickCount();
|
||||
while ((getTickDiff(nowTick) < 3)
|
||||
&& (uart_dev_char_present(g_J5_0_usart3_handle) == 1)
|
||||
&& (maxdataLen > J5_0_485RxBufferIndex)) {
|
||||
J5_0_485RxBuffer[J5_0_485RxBufferIndex++] = uart_dev_in_char(g_J5_0_usart3_handle);
|
||||
}
|
||||
|
||||
/* 当时间到达或者数据量到达,就打包发送给智能模块 */
|
||||
if ((J5_0_485RxBufferIndex >= maxdataLen) || (getTickDiff(tick) > delayTick)) {
|
||||
|
||||
uint32_t tempLen = 6 + J5_0_485RxBufferIndex + queueUartSendInfoSize;
|
||||
if (xPortGetFreeHeapSize() < tempLen + 1024) {
|
||||
J5_0_485RxBufferIndex = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *Buff = (uint8_t *)pvPortMalloc(tempLen);
|
||||
queueUartSendInfo *sendBuff = (queueUartSendInfo *)Buff;
|
||||
sendBuff->length = 6 + J5_0_485RxBufferIndex;
|
||||
sendBuff->data = Buff + sizeof(queueUartSendInfo);
|
||||
uint8_t *send = sendBuff->data;
|
||||
|
||||
/* 起始标志 */
|
||||
*send = 'S';
|
||||
*(send + 1) = 'L';
|
||||
|
||||
/* 端口号 */
|
||||
send += 2;
|
||||
*send = getConnectPort();
|
||||
|
||||
/* 数据包长度 */
|
||||
send += 1;
|
||||
*send = (uint8_t)(J5_0_485RxBufferIndex >> 8);
|
||||
*(send + 1) = (uint8_t)(J5_0_485RxBufferIndex);
|
||||
|
||||
/* 数据包 */
|
||||
send += 2;
|
||||
memcpy((char *)send, (char *)J5_0_485RxBuffer, J5_0_485RxBufferIndex + 1);
|
||||
|
||||
/* 结束标志 */
|
||||
send += J5_0_485RxBufferIndex;
|
||||
*send = 0x17;
|
||||
|
||||
/* 队列中有空间,则将发送数据 */
|
||||
if (uxQueueSpacesAvailable(upward_uart_Queue)) {
|
||||
xQueueSend(upward_uart_Queue, &Buff, 10);
|
||||
}
|
||||
/* 队列无空间,将数据丢弃 */
|
||||
else {
|
||||
vPortFree(Buff);
|
||||
}
|
||||
|
||||
J5_0_485RxBufferIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
|
||||
#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 "flash.h"
|
||||
#include "parameter.h"
|
||||
#include "busIdleDetection.h"
|
||||
#include "downUartParse.h"
|
||||
|
||||
|
||||
#define Common_TASK_PRIO 2
|
||||
#define Common_STK_SIZE 512
|
||||
|
||||
#define Transmit_TASK_PRIO 7
|
||||
#define Transmit_STK_SIZE 256
|
||||
|
||||
#define UpReceive_TASK_PRIO 5
|
||||
#define UpReceive_STK_SIZE 256
|
||||
|
||||
#define DownReceive_TASK_PRIO 4
|
||||
#define DownReceive_STK_SIZE 1024
|
||||
|
||||
#define FreeMemory_TASK_PRIO 5
|
||||
#define FreeMemory_STK_SIZE 256
|
||||
|
||||
/* 任务句柄 */
|
||||
static TaskHandle_t CommonTask_Handler;
|
||||
static TaskHandle_t TransmitTask_Handler;
|
||||
static TaskHandle_t UpReceive_Handler;
|
||||
static TaskHandle_t DownReceive_Handler;
|
||||
static TaskHandle_t FreeMemory_Handler;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 喂狗等任务在其中进行
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static void common_Task(void *pvParameters)
|
||||
{
|
||||
// writePwrCtrlState(Android_PwrCtrl, PwrCtrlOpen);
|
||||
// proportionalInt();
|
||||
// while(1) {
|
||||
// // printf("task1 entry\r\n");
|
||||
// printf_adc_data();
|
||||
// USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
|
||||
// uartInterruptSend(g_Upward_uart5_handle, data, 12);
|
||||
// vTaskDelay(1000);
|
||||
// }
|
||||
|
||||
uint16_t HeapSizeNum = 0;
|
||||
uint16_t LedNum = 0;
|
||||
|
||||
/* 用于绝对延时 */
|
||||
TickType_t xLastWakeTime;
|
||||
const TickType_t xFrequency = 100; // 50 个滴答,即200mS
|
||||
// 初始化 xLastWakeTime
|
||||
xLastWakeTime = xTaskGetTickCount();
|
||||
|
||||
|
||||
|
||||
while (1) {
|
||||
// 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);
|
||||
// memcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
|
||||
|
||||
// xQueueSend(upward_uart_Queue, &Buff, 10);
|
||||
|
||||
|
||||
|
||||
|
||||
// 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;
|
||||
// memcpy((char *)sendBuff->data, "hello world\n", sizeof("hello world\n"));
|
||||
|
||||
// xQueueSend(J5_0_485_Queue, &Buff, 10);
|
||||
|
||||
|
||||
/* 每200ms获取一下数据 */
|
||||
setWorkCurrent(getInCurrent());
|
||||
setWorkVoltage(getInVoltage());
|
||||
|
||||
/* 当内存碎片过多时,后续可以在其中处理 */
|
||||
if (HeapSizeNum++ == 25) {
|
||||
HeapSizeNum = 0;
|
||||
log_info("xPortGetFreeHeapSize : %d",xPortGetFreeHeapSize());
|
||||
// log_info("getRs485State : %d\n", getRs485State(g_J5_0_usart3_handle));
|
||||
// log_info("getUartSendState : %d\n", getUartSendState(g_J5_0_usart3_handle));
|
||||
// log_info("getBUSIDLEFlag : %d\n", getBUSIDLEFlag(g_J5_0_usart3_handle));
|
||||
}
|
||||
|
||||
if (LedNum++ == 3) {
|
||||
LedNum = 0;
|
||||
ledToggle();
|
||||
}
|
||||
|
||||
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||
// vTaskDelay(200);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将数据发送
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static void transmit_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
uartQueueSend();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
J1_SensorDataAnalysis();
|
||||
J2_SensorDataAnalysis();
|
||||
J3_SensorDataAnalysis();
|
||||
J4_SensorDataAnalysis();
|
||||
J5_0_SensorDataAnalysis();
|
||||
vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 通过条件变量通知来释放内存
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static void FreeMemory_Task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
// vTaskDelay(1000);
|
||||
binarySemaphoreFreeMemory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 启动
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void startApp(void)
|
||||
{
|
||||
// printf("RCC->RSTSCKR = %08x \r\n", RCC->RSTSCKR);
|
||||
// RCC->RSTSCKR |= 1<<24;
|
||||
|
||||
/* 初始化flash,读取配置文件 */
|
||||
Flash_Init();
|
||||
readConfigParameter();
|
||||
|
||||
FM_GPIO_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();
|
||||
binarySemaphoreInit();
|
||||
softwareTimeInit();
|
||||
|
||||
Delay_Ms(1000);
|
||||
set_485_Read();
|
||||
|
||||
writePwrCtrlState(Android_PwrCtrl, GPIO_SET);
|
||||
// writePwrCtrlState(J1_PwrCtrl, GPIO_SET);
|
||||
|
||||
/* create task */
|
||||
xTaskCreate((TaskFunction_t )common_Task,
|
||||
(const char* )"commonTask",
|
||||
(uint16_t )Common_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(UBaseType_t )Common_TASK_PRIO,
|
||||
(TaskHandle_t* )&CommonTask_Handler);
|
||||
|
||||
xTaskCreate((TaskFunction_t )transmit_Task,
|
||||
(const char* )"transmitTask",
|
||||
(uint16_t )Transmit_STK_SIZE,
|
||||
(void* )NULL,
|
||||
(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);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
#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 = 115200;
|
||||
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;
|
||||
}
|
|
@ -1,311 +0,0 @@
|
|||
|
||||
#include "queueUart.h"
|
||||
#include "uart_dev.h"
|
||||
#include "busIdleDetection.h"
|
||||
#include "semphr.h"
|
||||
|
||||
/* 队列中每个消息的大小 */
|
||||
#define QUEUE_SIZE 4
|
||||
|
||||
/* 各个通讯口的队列 */
|
||||
QueueHandle_t J1_485_Queue = NULL;
|
||||
QueueHandle_t J2_485_Queue = NULL;
|
||||
QueueHandle_t J3_485_Queue = NULL;
|
||||
QueueHandle_t J4_485_Queue = NULL;
|
||||
QueueHandle_t J5_0_485_Queue = NULL;
|
||||
QueueHandle_t upward_uart_Queue = NULL;
|
||||
/* 队列集 */
|
||||
QueueSetHandle_t uart_Queue = NULL;
|
||||
|
||||
QueueSetMemberHandle_t xActivatedMemberUartQueue;
|
||||
|
||||
/* 通过该结构体接收对应的数据用来发送,结束后通过该结构体,释放数据的内存 */
|
||||
typedef struct _queueRecvDataInfo {
|
||||
queueUartSendInfo *J1_485_data;
|
||||
queueUartSendInfo *J2_485_data;
|
||||
queueUartSendInfo *J3_485_data;
|
||||
queueUartSendInfo *J4_485_data;
|
||||
queueUartSendInfo *upward_uart_data;
|
||||
queueTimeShareSendInfo *J5_0_485_data;
|
||||
} queueRecvDataInfo;
|
||||
static queueRecvDataInfo queueRecvData;
|
||||
|
||||
/**
|
||||
* @brief 初始化串口发送的队列
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void uartQueueInit(void)
|
||||
{
|
||||
/* 初始化队列 */
|
||||
J1_485_Queue = xQueueCreate(5, QUEUE_SIZE);
|
||||
// if (NULL == J1_485_Queue) {
|
||||
// log_error("creat J1_485_Queue error\n");
|
||||
// }
|
||||
|
||||
J2_485_Queue = xQueueCreate(5, QUEUE_SIZE);
|
||||
// if (NULL == J2_485_Queue) {
|
||||
// log_error("creat J2_485_Queue error\n");
|
||||
// }
|
||||
|
||||
J3_485_Queue = xQueueCreate(5, QUEUE_SIZE);
|
||||
// if (NULL == J3_485_Queue) {
|
||||
// log_error("creat J3_485_Queue error\n");
|
||||
// }
|
||||
|
||||
J4_485_Queue = xQueueCreate(5, QUEUE_SIZE);
|
||||
// if (NULL == J4_485_Queue) {
|
||||
// log_error("creat J4_485_Queue error\n");
|
||||
// }
|
||||
|
||||
J5_0_485_Queue = xQueueCreate(10, QUEUE_SIZE);
|
||||
// if (NULL == J5_0_485_Queue) {
|
||||
// log_error("creat J5_0_485_Queue error\n");
|
||||
// }
|
||||
|
||||
upward_uart_Queue = xQueueCreate(10, QUEUE_SIZE);
|
||||
// if (NULL == upward_uart_Queue) {
|
||||
// log_error("creat upward_uart_Queue error\n");
|
||||
// }
|
||||
|
||||
|
||||
/* 将队列都放入队列集中 */
|
||||
uart_Queue = xQueueCreateSet(6);
|
||||
xQueueAddToSet(J1_485_Queue, uart_Queue);
|
||||
xQueueAddToSet(J2_485_Queue, uart_Queue);
|
||||
xQueueAddToSet(J3_485_Queue, uart_Queue);
|
||||
xQueueAddToSet(J4_485_Queue, uart_Queue);
|
||||
xQueueAddToSet(J5_0_485_Queue, uart_Queue);
|
||||
xQueueAddToSet(upward_uart_Queue, uart_Queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从队列中取出数据,发送函数
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void uartQueueSend(void)
|
||||
{
|
||||
/* 用于判定是否延时 */
|
||||
static uint8_t flag = 0;
|
||||
|
||||
/* 查看队列集中是否有数据 */
|
||||
xActivatedMemberUartQueue = xQueueSelectFromSet(uart_Queue, portMAX_DELAY);
|
||||
|
||||
/* 查看Upward_uart5中有无数据 */
|
||||
if (!getUartState(g_Upward_uart5_handle)) {
|
||||
/* 处理接收到的数据 */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 查看J1_485中有无数据 */
|
||||
if (!getRs485State(g_J1_uart6_handle)) {
|
||||
/* 处理接收到的数据 */
|
||||
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);
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 查看J2_485中有无数据 */
|
||||
if (!getRs485State(g_J2_uart7_handle)) {
|
||||
/* 处理接收到的数据 */
|
||||
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);
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 查看J3_485中有无数据 */
|
||||
if (!getRs485State(g_J3_usart2_handle)) {
|
||||
/* 处理接收到的数据 */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 查看J4_485中有无数据 */
|
||||
if (!getRs485State(g_J4_uart8_handle)) {
|
||||
/* 处理接收到的数据 */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 查看J5_0_485中有无数据 */
|
||||
if (!getRs485State(g_J5_0_usart3_handle)) {
|
||||
/* 处理接收到的数据 */
|
||||
if (xQueueReceive(J5_0_485_Queue, &queueRecvData.J5_0_485_data, 0) == pdTRUE) {
|
||||
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);
|
||||
uartInterruptSend(g_J5_0_usart3_handle, queueRecvData.J5_0_485_data->data
|
||||
, queueRecvData.J5_0_485_data->length);
|
||||
flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* 没有数据发送则延时 */
|
||||
if (!flag) {
|
||||
/* 延时三个系统节拍 */
|
||||
vTaskDelay(3);
|
||||
log_info("getRs485State : %d\n", getRs485State(g_J5_0_usart3_handle));
|
||||
}
|
||||
flag = 0;
|
||||
}
|
||||
|
||||
#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);
|
||||
vTaskDelay(1);
|
||||
readJ1_485;
|
||||
setJ1_485_SendState(0);
|
||||
// 处理二值信号量事件
|
||||
xSemaphoreTake(J1_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J2_BinarySemaphore) {
|
||||
vPortFree(queueRecvData.J2_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ2_485;
|
||||
setJ2_485_SendState(0);
|
||||
xSemaphoreTake(J2_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J3_BinarySemaphore) {
|
||||
vPortFree(queueRecvData.J3_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ3_485;
|
||||
setJ3_485_SendState(0);
|
||||
xSemaphoreTake(J3_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J4_BinarySemaphore) {
|
||||
vPortFree(queueRecvData.J4_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ4_485;
|
||||
setJ4_485_SendState(0);
|
||||
xSemaphoreTake(J4_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
else if (xActivatedMember == J5_0_BinarySemaphore) {
|
||||
vPortFree(queueRecvData.J5_0_485_data);
|
||||
vTaskDelay(1);
|
||||
readJ5_0_485;
|
||||
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 数据发送完成后用于清除
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void J1_485_IN_TXE(void)
|
||||
{
|
||||
// vPortFree(queueRecvData.J1_485_data);
|
||||
xSemaphoreGiveFromISR(J1_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
void J2_485_IN_TXE(void)
|
||||
{
|
||||
// vPortFree(queueRecvData.J2_485_data);
|
||||
xSemaphoreGiveFromISR(J2_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
void J3_485_IN_TXE(void)
|
||||
{
|
||||
// vPortFree(queueRecvData.J3_485_data);
|
||||
xSemaphoreGiveFromISR(J3_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
void J4_485_IN_TXE(void)
|
||||
{
|
||||
// vPortFree(queueRecvData.J4_485_data);
|
||||
xSemaphoreGiveFromISR(J4_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
void J5_0_485_IN_TXE(void)
|
||||
{
|
||||
// vPortFree(queueRecvData.J5_0_485_data);
|
||||
xSemaphoreGiveFromISR(J5_0_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
|
||||
void Upward_USART_IN_TXE(void)
|
||||
{
|
||||
// vPortFree(queueRecvData.upward_uart_data);
|
||||
xSemaphoreGiveFromISR(upward_BinarySemaphore, 0);
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -4,10 +4,13 @@
|
|||
#include "HD_ADC.h"
|
||||
|
||||
void FM_ADC_Init(void);
|
||||
void printf_adc_data(void);
|
||||
void proportionalInt(void);
|
||||
float getSOCPwrOnVoltage(void);
|
||||
float getInCurrent(void);
|
||||
float getInVoltage(void);
|
||||
float getTemperature(void);
|
||||
|
||||
void printf_adc_data(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -22,7 +22,39 @@ typedef enum _pwrCtrlState{
|
|||
PwrCtrlOpen
|
||||
}pwrCtrlState;
|
||||
|
||||
void FM_GPIO_Init(void);
|
||||
#define readJ0_485 HD_GPIO_Write(J0De_GPIO_PROT, J0De_GPIO_PIN, read);
|
||||
#define readJ1_485 HD_GPIO_Write(J1De_GPIO_PROT, J1De_GPIO_PIN, read);
|
||||
#define readJ2_485 HD_GPIO_Write(J2De_GPIO_PROT, J2De_GPIO_PIN, read);
|
||||
#define readJ3_485 HD_GPIO_Write(J3De_GPIO_PROT, J3De_GPIO_PIN, read);
|
||||
#define readJ4_485 HD_GPIO_Write(J4De_GPIO_PROT, J4De_GPIO_PIN, read);
|
||||
#define readJ5_485 HD_GPIO_Write(J5De_GPIO_PROT, J5De_GPIO_PIN, read);
|
||||
#define readJ6_485 HD_GPIO_Write(J6De_GPIO_PROT, J6De_GPIO_PIN, read);
|
||||
#define readJ7_485 HD_GPIO_Write(J7De_GPIO_PROT, J7De_GPIO_PIN, read);
|
||||
#define readJ8_485 HD_GPIO_Write(J8De_GPIO_PROT, J8De_GPIO_PIN, read);
|
||||
#define readJ9_485 HD_GPIO_Write(J9De_GPIO_PROT, J9De_GPIO_PIN, read);
|
||||
|
||||
#define writeJ0_485 HD_GPIO_Write(J0De_GPIO_PROT, J0De_GPIO_PIN, write);
|
||||
#define writeJ1_485 HD_GPIO_Write(J1De_GPIO_PROT, J1De_GPIO_PIN, write);
|
||||
#define writeJ2_485 HD_GPIO_Write(J2De_GPIO_PROT, J2De_GPIO_PIN, write);
|
||||
#define writeJ3_485 HD_GPIO_Write(J3De_GPIO_PROT, J3De_GPIO_PIN, write);
|
||||
#define writeJ4_485 HD_GPIO_Write(J4De_GPIO_PROT, J4De_GPIO_PIN, write);
|
||||
#define writeJ5_485 HD_GPIO_Write(J5De_GPIO_PROT, J5De_GPIO_PIN, write);
|
||||
#define writeJ6_485 HD_GPIO_Write(J6De_GPIO_PROT, J6De_GPIO_PIN, write);
|
||||
#define writeJ7_485 HD_GPIO_Write(J7De_GPIO_PROT, J7De_GPIO_PIN, write);
|
||||
#define writeJ8_485 HD_GPIO_Write(J8De_GPIO_PROT, J8De_GPIO_PIN, write);
|
||||
#define writeJ9_485 HD_GPIO_Write(J9De_GPIO_PROT, J9De_GPIO_PIN, write);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void HostMcu_GPIO_Init(void);
|
||||
void HostMcu_485DE_Read(void);
|
||||
void SlaveMcu_GPIO_Init(void);
|
||||
void SlaveMcu_485DE_Read(void);
|
||||
|
||||
void feedDog(void);
|
||||
void writePwrCtrlState(uint8_t type, uint8_t State);
|
||||
uint8_t readPwrCtrlState(uint8_t type);
|
||||
|
@ -30,4 +62,8 @@ void startResetAndroidModule(void);
|
|||
void stopResetAndroidModule(void);
|
||||
void ledToggle(void);
|
||||
|
||||
#endif
|
||||
void FM_MCU_Init(void);
|
||||
uint8_t getMCU(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
#ifndef FM_FLASH_H_
|
||||
#define FM_FLASH_H_
|
||||
|
||||
#include "ch32v30x.h"
|
||||
#include "HD_Flash.h"
|
||||
// #include "w25q256.h"
|
||||
|
||||
void Flash_Init(void);
|
||||
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);
|
||||
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
|
||||
void erase_Sector_Flash(uint32_t secpos);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -6,12 +6,6 @@
|
|||
#include "comm_types.h"
|
||||
#include "ring_queue.h"
|
||||
|
||||
/* 是否使用中断发送,后期可能改为DMA发送 */
|
||||
#define UARTINTERRUPTSEND
|
||||
|
||||
/* 是否使用空闲中断,后期可以改为其他方式判断总线空闲中断 */
|
||||
#define RS485BUSIDLE1
|
||||
|
||||
#define ASCII_CHAR_BACKSPACE 0x08 /* '\b' */
|
||||
#define ASCII_CHAR_CHARACTER_TABULATION 0x09 /* '\t' */
|
||||
#define ASCII_CHAR_LINE_FEED 0x0A /* '\n' */
|
||||
|
@ -20,21 +14,22 @@
|
|||
#define ASCII_CHAR_CARRIAGE_RETURN 0x0D /* '\r' */
|
||||
|
||||
typedef enum{
|
||||
J1_485_INDEX = 6,
|
||||
J2_485_INDEX = 7,
|
||||
J3_485_INDEX = 2,
|
||||
J4_485_INDEX = 8,
|
||||
J5_0_485_INDEX = 3,
|
||||
Upward_UART_INDEX = 5,
|
||||
J01_485_INDEX = 0,
|
||||
J23_485_INDEX = 1,
|
||||
J45_485_INDEX = 2,
|
||||
J67_485_INDEX = 3,
|
||||
J8_485_INDEX = 4,
|
||||
J9_485_INDEX = 5,
|
||||
Lora_UART_INDEX = 6,
|
||||
Su806_UART_INDEX = 7,
|
||||
MCU_UART_INDEX = 8,
|
||||
}uartIndex_e;
|
||||
|
||||
typedef struct _uartSendInfo {
|
||||
uint8_t *data; //指向数据
|
||||
#ifdef UARTINTERRUPTSEND
|
||||
uint16_t count; //已经发送数据字节个数
|
||||
uint16_t len; //数据长度
|
||||
#endif
|
||||
}uartSendInfo;
|
||||
} uartSendInfo;
|
||||
|
||||
/* UART 驱动数据结构,对应一个uart设备 */
|
||||
typedef struct _uart_device_info{
|
||||
|
@ -43,74 +38,101 @@ typedef struct _uart_device_info{
|
|||
uint32_t uart_baudrate;
|
||||
RingQueue uart_ring_queue;
|
||||
uartSendInfo uart_send_data;
|
||||
}uart_device_info;
|
||||
} uart_device_info;
|
||||
|
||||
typedef uint32_t device_handle;
|
||||
extern device_handle g_J1_uart6_handle;
|
||||
extern device_handle g_J2_uart7_handle;
|
||||
extern device_handle g_J3_usart2_handle;
|
||||
extern device_handle g_J4_uart8_handle;
|
||||
extern device_handle g_J5_0_usart3_handle;
|
||||
extern device_handle g_Upward_uart5_handle;
|
||||
extern device_handle g_J0_handle;
|
||||
extern device_handle g_J1_handle;
|
||||
extern device_handle g_J2_handle;
|
||||
extern device_handle g_J3_handle;
|
||||
extern device_handle g_J4_handle;
|
||||
extern device_handle g_J5_handle;
|
||||
extern device_handle g_J6_handle;
|
||||
extern device_handle g_J7_handle;
|
||||
extern device_handle g_J8_handle;
|
||||
extern device_handle g_J9_handle;
|
||||
extern device_handle g_Mcu_handle;
|
||||
extern device_handle g_Su806_handle;
|
||||
extern device_handle g_Lora_handle;
|
||||
|
||||
uint8_t uart_dev_in_char(device_handle device);
|
||||
int uart_dev_char_present(device_handle device);
|
||||
|
||||
void HostMcu_uartBuf_Init(int32_t rs485BufLen, int32_t loraBufLen, int32_t mcuBufLen, int32_t su806BufLen);
|
||||
void SlaveMcu_uartBuf_Init(int32_t rs485BufLen, int32_t mcuBufLen);
|
||||
void Init_J0_485(uint32_t baud);
|
||||
void Init_J1_485(uint32_t baud);
|
||||
void Init_J2_485(uint32_t baud);
|
||||
void Init_J3_485(uint32_t baud);
|
||||
void Init_J4_485(uint32_t baud);
|
||||
void Init_J5_0_485(uint32_t baud);
|
||||
void Init_Upward_uart(uint32_t baud);
|
||||
void Init_J5_485(uint32_t baud);
|
||||
void Init_J6_485(uint32_t baud);
|
||||
void Init_J7_485(uint32_t baud);
|
||||
void Init_J8_485(uint32_t baud);
|
||||
void Init_J9_485(uint32_t baud);
|
||||
void Init_Mcu_Uart(uint32_t baud);
|
||||
void Init_Su806_Uart(uint32_t baud);
|
||||
void Init_Lora_Uart(uint32_t baud);
|
||||
void uartIT_Init(void);
|
||||
|
||||
void J0_Interrupt();
|
||||
void J1_Interrupt();
|
||||
void J2_Interrupt();
|
||||
void J3_Interrupt();
|
||||
void J4_Interrupt();
|
||||
void J5_Interrupt();
|
||||
void J6_Interrupt();
|
||||
void J7_Interrupt();
|
||||
void J8_Interrupt();
|
||||
void J9_Interrupt();
|
||||
// void Host_Interrupt();
|
||||
// void Slave_Interrupt();
|
||||
void Mcu_Interrupt();
|
||||
void Su806_Interrupt();
|
||||
void Lora_Interrupt();
|
||||
|
||||
/* 0为主mcu,非0为从mcu */
|
||||
extern uint8_t getMCU(void);
|
||||
|
||||
|
||||
uint8_t getUartSendState(device_handle device);
|
||||
|
||||
#ifdef UARTINTERRUPTSEND
|
||||
extern void J0_485_IN_TXE(void);
|
||||
extern void J1_485_IN_TXE(void);
|
||||
extern void J2_485_IN_TXE(void);
|
||||
extern void J3_485_IN_TXE(void);
|
||||
extern void J4_485_IN_TXE(void);
|
||||
extern void J5_0_485_IN_TXE(void);
|
||||
extern void Upward_USART_IN_TXE(void);
|
||||
uint8_t uartInterruptSend(device_handle device, uint8_t *data, uint16_t len);
|
||||
#endif
|
||||
extern void J5_485_IN_TXE(void);
|
||||
extern void J6_485_IN_TXE(void);
|
||||
extern void J7_485_IN_TXE(void);
|
||||
extern void J8_485_IN_TXE(void);
|
||||
extern void J9_485_IN_TXE(void);
|
||||
extern void Lora_uart_IN_TXE(void);
|
||||
// extern void Mcu_uart_IN_TXE(void);
|
||||
extern void hostMcu_uart_IN_TXE(void);
|
||||
extern void slaveMcu_uart_IN_TXE(void);
|
||||
extern void Su806_uart_IN_TXE(void);
|
||||
|
||||
#ifdef RS485BUSIDLE1
|
||||
extern void J0_485_IN_IDLE(void);
|
||||
extern void J1_485_IN_IDLE(void);
|
||||
extern void J2_485_IN_IDLE(void);
|
||||
extern void J3_485_IN_IDLE(void);
|
||||
extern void J4_485_IN_IDLE(void);
|
||||
extern void J5_0_485_IN_IDLE(void);
|
||||
extern void J5_485_IN_IDLE(void);
|
||||
extern void J6_485_IN_IDLE(void);
|
||||
extern void J7_485_IN_IDLE(void);
|
||||
extern void J8_485_IN_IDLE(void);
|
||||
extern void J9_485_IN_IDLE(void);
|
||||
|
||||
extern void J0_485_IN_RXNE(void);
|
||||
extern void J1_485_IN_RXNE(void);
|
||||
extern void J2_485_IN_RXNE(void);
|
||||
extern void J3_485_IN_RXNE(void);
|
||||
extern void J4_485_IN_RXNE(void);
|
||||
extern void J5_0_485_IN_RXNE(void);
|
||||
|
||||
uint8_t getBUSIDLEFlag(device_handle device);
|
||||
// uint8_t getSoftwareIDLEFlag(device_handle device);
|
||||
void setBUSIDLEFlag(device_handle device, uint8_t state);
|
||||
// void setSoftwareIDLEFlag(device_handle device, uint8_t state);
|
||||
#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连接到哪个端口 */
|
||||
typedef enum _connectPortEnum {
|
||||
connectJ0 = 0,
|
||||
connectJ5 = 5,
|
||||
connectJ6,
|
||||
connectJ7,
|
||||
connectJ8,
|
||||
connectJ9,
|
||||
} connectPortEnum;
|
||||
void setConnectPort(uint8_t port);
|
||||
uint8_t getConnectPort(void);
|
||||
|
||||
extern void J5_485_IN_RXNE(void);
|
||||
extern void J6_485_IN_RXNE(void);
|
||||
extern void J7_485_IN_RXNE(void);
|
||||
extern void J8_485_IN_RXNE(void);
|
||||
extern void J9_485_IN_RXNE(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "FM_ADC.h"
|
||||
|
||||
/* adc采集转换的比例 */
|
||||
|
@ -12,6 +11,7 @@ static float P_In_Current;
|
|||
/* 参考电压的大小 */
|
||||
#define referenceVoltage 3.3f
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将采集的adc进行校准
|
||||
* @param val 采集的adc数据
|
||||
|
@ -26,6 +26,7 @@ static uint16_t Get_ConversionVal(int16_t val)
|
|||
return (val + Calibrattion_Val);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化adc
|
||||
* @param
|
||||
|
@ -38,19 +39,6 @@ void FM_ADC_Init(void)
|
|||
startAdcCapture();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ´òÓ¡adcÉú³ÉµÄÊý¾Ý
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void printf_adc_data(void)
|
||||
{
|
||||
printf("adc : %d, %d, %d\n", adcData[0], adcData[1], adcData[2]);
|
||||
printf("getSOCPwrOnVoltage: %d\n", (int)(getSOCPwrOnVoltage() * 1000.0f));
|
||||
printf("getInCurrent: %d\n", (int)(getInCurrent() * 1000.0f));
|
||||
printf("getInVoltage: %d\n", (int)(getInVoltage() * 1000.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化转换的比例
|
||||
* @param
|
||||
|
@ -70,7 +58,7 @@ void proportionalInt(void)
|
|||
*/
|
||||
float getSOCPwrOnVoltage(void)
|
||||
{
|
||||
return (Get_ConversionVal(adcData[0]) * P_PwrOn_Voltage);
|
||||
return (Get_ConversionVal(adcData[PwrOnNum]) * P_PwrOn_Voltage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +68,7 @@ float getSOCPwrOnVoltage(void)
|
|||
*/
|
||||
float getInCurrent(void)
|
||||
{
|
||||
return (Get_ConversionVal(adcData[1]) * P_In_Current);
|
||||
return (Get_ConversionVal(adcData[CurrentNum]) * P_In_Current);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,5 +78,29 @@ float getInCurrent(void)
|
|||
*/
|
||||
float getInVoltage(void)
|
||||
{
|
||||
return (Get_ConversionVal(adcData[2]) * P_In_Voltage);
|
||||
}
|
||||
return (Get_ConversionVal(adcData[VoltageNum]) * P_In_Voltage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到网关盒子中的温度
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
float getTemperature(void)
|
||||
{
|
||||
return (Get_ConversionVal(adcData[TemperatureNum]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打印adc生成的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void printf_adc_data(void)
|
||||
{
|
||||
printf("adc : %d, %d, %d, %d\n", adcData[0], adcData[1], adcData[2], adcData[3]);
|
||||
printf("getSOCPwrOnVoltage: %d\n", (int)(getSOCPwrOnVoltage() * 1000.0f));
|
||||
printf("getInCurrent: %d\n", (int)(getInCurrent() * 1000.0f));
|
||||
printf("getInVoltage: %d\n", (int)(getInVoltage() * 1000.0f));
|
||||
printf("getTemperature: %d\n", (int)(getTemperature() * 1000.0f));
|
||||
}
|
||||
|
|
|
@ -1,20 +1,85 @@
|
|||
|
||||
#include "FM_GPIO.h"
|
||||
|
||||
|
||||
static uint8_t mcuFlag = 0;
|
||||
/**
|
||||
* @brief 初始化GPIO
|
||||
* @param
|
||||
* @retval
|
||||
* @brief 初始化判断主从mcu.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void FM_GPIO_Init(void)
|
||||
void FM_MCU_Init(void)
|
||||
{
|
||||
HD_GPIO_Init();
|
||||
mcuFlag = mcu_GPIO_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 喂狗
|
||||
* @param
|
||||
* @retval
|
||||
* @brief 主mcu的io初始化.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint8_t getMCU(void)
|
||||
{
|
||||
return mcuFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 主mcu的io初始化.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void HostMcu_GPIO_Init(void)
|
||||
{
|
||||
PwrCtrl_GPIO_Init();
|
||||
Android_GPIO_Init();
|
||||
WDI_GPIO_Init();
|
||||
LED_GPIO_Init();
|
||||
Host485De_GPIO_Init();
|
||||
ctrlSlave_GPIO_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将主mcu的485读写引脚全部设置为写.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void HostMcu_485DE_Read(void)
|
||||
{
|
||||
HD_GPIO_Write(J0De_GPIO_PROT, J0De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J2De_GPIO_PROT, J2De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J4De_GPIO_PROT, J4De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J6De_GPIO_PROT, J6De_GPIO_PIN, read);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从mcu的io初始化.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void SlaveMcu_GPIO_Init(void)
|
||||
{
|
||||
WDI_GPIO_Init();
|
||||
Slave485De_GPIO_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将从mcu的485读写引脚全部设置为读.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void SlaveMcu_485DE_Read(void)
|
||||
{
|
||||
HD_GPIO_Write(J1De_GPIO_PROT, J1De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J3De_GPIO_PROT, J3De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J5De_GPIO_PROT, J5De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J7De_GPIO_PROT, J7De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J8De_GPIO_PROT, J8De_GPIO_PIN, read);
|
||||
HD_GPIO_Write(J9De_GPIO_PROT, J9De_GPIO_PIN, read);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 喂狗.
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void feedDog(void)
|
||||
{
|
||||
|
@ -23,10 +88,10 @@ void feedDog(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 电源输出状态设置
|
||||
* @brief 设置电源控制引脚状态.
|
||||
* @param type 电源输出接口
|
||||
state 输出状态
|
||||
* @retval
|
||||
* @retval
|
||||
*/
|
||||
void writePwrCtrlState(uint8_t type, uint8_t State)
|
||||
{
|
||||
|
@ -54,7 +119,7 @@ void writePwrCtrlState(uint8_t type, uint8_t State)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 读取电源输出状态
|
||||
* @brief 读取电源控制引脚状态.
|
||||
* @param type 电源输出接口
|
||||
* @retval state 输出状态
|
||||
0xFF 输入类型错误
|
||||
|
@ -117,3 +182,4 @@ void ledToggle(void)
|
|||
HD_GPIO_Write(LED_GPIO_PROT, LED_GPIO_PIN
|
||||
, !(HD_OutputGPIO_Read(LED_GPIO_PROT, LED_GPIO_PIN)));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
#include "flash.h"
|
||||
|
||||
/**
|
||||
* @brief flash初始化
|
||||
* @param
|
||||
*/
|
||||
void Flash_Init(void)
|
||||
{
|
||||
SPI_Flash_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取flash中的数据
|
||||
* @param pBuffer 保存读取的数据
|
||||
* @param ReadAddr 读取数据的位置
|
||||
* @param NumByteToRead 读取数据的长度
|
||||
*/
|
||||
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
||||
{
|
||||
SPI_Flash_Read(pBuffer, ReadAddr, NumByteToRead);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将数据写入到flash中
|
||||
* @param pBuffer 要写入的数据
|
||||
* @param ReadAddr 要写入数据的位置
|
||||
* @param NumByteToRead 要写入数据的长度
|
||||
*/
|
||||
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
SPI_Flash_Write(pBuffer, WriteAddr, NumByteToWrite);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 清除flash中secpos扇区的数据
|
||||
*
|
||||
*/
|
||||
void erase_Sector_Flash(uint32_t secpos)
|
||||
{
|
||||
SPI_Flash_Erase_Sector(secpos);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -10,6 +10,7 @@ extern int16_t Calibrattion_Val;
|
|||
#define PwrOnNum 0
|
||||
#define CurrentNum 1
|
||||
#define VoltageNum 2
|
||||
#define TemperatureNum 3
|
||||
|
||||
void HD_ADC_InIt(void);
|
||||
void ADC_DMA_Init(void);
|
||||
|
|
|
@ -5,94 +5,13 @@
|
|||
* Author: 34509
|
||||
*/
|
||||
|
||||
#ifndef HARDWARE_SPI_FLASH_H_
|
||||
#define HARDWARE_SPI_FLASH_H_
|
||||
#ifndef HARDWARE_FLASH_H_
|
||||
#define HARDWARE_FLASH_H_
|
||||
|
||||
#include "ch32v30x.h"
|
||||
|
||||
uint8_t readFlash(uint32_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
|
||||
uint8_t writeFlash(uint32_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
|
||||
|
||||
/*****************************************
|
||||
|
||||
*@Note
|
||||
|
||||
Winbond W25Qxx SPIFLASH
|
||||
|
||||
pins:
|
||||
|
||||
CS ¡ª¡ª PA15(SPI3_NSS)
|
||||
|
||||
DO ¡ª¡ª PB4(SPI3_MISO)
|
||||
|
||||
WP ¡ª¡ª 3.3V
|
||||
|
||||
DI ¡ª¡ª PB5(SPI3_MOSI)
|
||||
|
||||
CLK ¡ª¡ª PB3(SPI3_SCK)
|
||||
|
||||
HOLD ¡ª¡ª 3.3V
|
||||
|
||||
*******************************************/
|
||||
#define RCC_APB2Periph_GPIOX RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB
|
||||
#define RCC_APB1Periph_SPIX RCC_APB1Periph_SPI3
|
||||
|
||||
#define CS_PIN GPIO_Pin_15
|
||||
#define CS_GPIO GPIOA
|
||||
|
||||
#define DO_PIN GPIO_Pin_4
|
||||
#define DO_GPIO GPIOB
|
||||
|
||||
#define DI_PIN GPIO_Pin_5
|
||||
#define DI_GPIO GPIOB
|
||||
|
||||
#define CLK_PIN GPIO_Pin_3
|
||||
#define CLK_GPIO GPIOB
|
||||
|
||||
#define SPIX SPI3
|
||||
|
||||
/* Winbond SPI Falsh ID */
|
||||
#define W25Q80 0XEF13
|
||||
#define W25Q16 0XEF14
|
||||
#define W25Q32 0XEF15
|
||||
#define W25Q64 0XEF16
|
||||
#define W25Q128 0XEF17
|
||||
|
||||
|
||||
|
||||
/* Winbond SPIFalsh Instruction List Ö¸Áî±í */
|
||||
#define W25X_WriteEnable 0x06
|
||||
#define W25X_WriteDisable 0x04
|
||||
#define W25X_ReadStatusReg 0x05
|
||||
#define W25X_WriteStatusReg 0x01
|
||||
#define W25X_ReadData 0x03
|
||||
#define W25X_FastReadData 0x0B
|
||||
#define W25X_FastReadDual 0x3B
|
||||
#define W25X_PageProgram 0x02
|
||||
#define W25X_BlockErase 0xD8
|
||||
#define W25X_SectorErase 0x20
|
||||
#define W25X_ChipErase 0xC7
|
||||
#define W25X_PowerDown 0xB9
|
||||
#define W25X_ReleasePowerDown 0xAB
|
||||
#define W25X_DeviceID 0xAB
|
||||
#define W25X_ManufactDeviceID 0x90
|
||||
#define W25X_JedecDeviceID 0x9F
|
||||
|
||||
void SPI_Flash_Init(void);
|
||||
u8 SPI_ReadWriteByte(u8 TxData);
|
||||
u8 SPI_Flash_ReadSR(void);
|
||||
void SPI_FLASH_Write_SR(u8 sr);
|
||||
void SPI_Flash_Wait_Busy(void);
|
||||
void SPI_FLASH_Write_Enable(void);
|
||||
void SPI_FLASH_Write_Disable(void);
|
||||
u16 SPI_Flash_ReadID(void);
|
||||
void SPI_Flash_Erase_Sector(u32 Dst_Addr);
|
||||
void SPI_Flash_Read(u8* pBuffer,u32 ReadAddr,u16 size);
|
||||
void SPI_Flash_Write_Page(u8* pBuffer,u32 WriteAddr,u16 size);
|
||||
void SPI_Flash_Write_NoCheck(u8* pBuffer,u32 WriteAddr,u16 size);
|
||||
void SPI_Flash_Write(u8* pBuffer,u32 WriteAddr,u16 size);
|
||||
void SPI_Flash_Erase_Chip(void);
|
||||
void SPI_Flash_PowerDown(void);
|
||||
void SPI_Flash_WAKEUP(void);
|
||||
|
||||
void SPI_Flash_TEST(void);
|
||||
|
||||
#endif /* HARDWARE_SPI_FLASH_H_ */
|
||||
|
|
|
@ -36,8 +36,35 @@
|
|||
#define WDI_GPIO_PIN GPIO_Pin_13
|
||||
|
||||
/* LEDÒý½Å */
|
||||
#define LED_GPIO_PROT GPIOB
|
||||
#define LED_GPIO_PIN GPIO_Pin_8
|
||||
#define LED_GPIO_PROT GPIOC
|
||||
#define LED_GPIO_PIN GPIO_Pin_9
|
||||
|
||||
/* 485读写控制引脚 */
|
||||
#define J0De_GPIO_PROT GPIOC
|
||||
#define J0De_GPIO_PIN GPIO_Pin_8
|
||||
#define J1De_GPIO_PROT GPIOC
|
||||
#define J1De_GPIO_PIN GPIO_Pin_8
|
||||
#define J2De_GPIO_PROT GPIOC
|
||||
#define J2De_GPIO_PIN GPIO_Pin_7
|
||||
#define J3De_GPIO_PROT GPIOC
|
||||
#define J3De_GPIO_PIN GPIO_Pin_7
|
||||
#define J4De_GPIO_PROT GPIOC
|
||||
#define J4De_GPIO_PIN GPIO_Pin_6
|
||||
#define J5De_GPIO_PROT GPIOC
|
||||
#define J5De_GPIO_PIN GPIO_Pin_6
|
||||
#define J6De_GPIO_PROT GPIOD
|
||||
#define J6De_GPIO_PIN GPIO_Pin_15
|
||||
#define J7De_GPIO_PROT GPIOD
|
||||
#define J7De_GPIO_PIN GPIO_Pin_15
|
||||
#define J8De_GPIO_PROT GPIOD
|
||||
#define J8De_GPIO_PIN GPIO_Pin_14
|
||||
#define J9De_GPIO_PROT GPIOD
|
||||
#define J9De_GPIO_PIN GPIO_Pin_13
|
||||
|
||||
/* 控制从mcu复位 */
|
||||
#define ctrlSlave_GPIO_PROT GPIOD
|
||||
#define ctrlSlave_GPIO_PIN GPIO_Pin_0
|
||||
|
||||
|
||||
#define GPIOTypeDef GPIO_TypeDef
|
||||
#define GPIOPin uint16_t
|
||||
|
@ -48,12 +75,21 @@ typedef enum {
|
|||
GPIO_SET
|
||||
}BitOperation;
|
||||
|
||||
#define write GPIO_SET
|
||||
#define read GPIO_RESET
|
||||
|
||||
uint8_t mcu_GPIO_Init(void);
|
||||
|
||||
void PwrCtrl_GPIO_Init(void);
|
||||
void Android_GPIO_Init(void);
|
||||
void WDI_GPIO_Init(void);
|
||||
void LED_GPIO_Init(void);
|
||||
void Host485De_GPIO_Init(void);
|
||||
void Slave485De_GPIO_Init(void);
|
||||
void ctrlSlave_GPIO_Init(void);
|
||||
|
||||
void HD_GPIO_Init(void);
|
||||
void HD_GPIO_Write(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin, BitOperation BitVal);
|
||||
uint8_t HD_InputGPIO_Read(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin);
|
||||
uint8_t HD_OutputGPIO_Read(GPIOTypeDef *GPIOx, GPIOPin GPIO_Pin);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,104 +3,46 @@
|
|||
|
||||
#include "ch32v30x.h"
|
||||
|
||||
// #define uart4_enable
|
||||
#define J0_USART USART3
|
||||
#define J1_USART USART3
|
||||
#define J2_USART UART4
|
||||
#define J3_USART UART4
|
||||
#define J4_USART UART5
|
||||
#define J5_USART UART5
|
||||
#define J6_USART UART6
|
||||
#define J7_USART UART6
|
||||
#define J8_USART UART8
|
||||
#define J9_USART UART7
|
||||
// #define Host_USART USART2
|
||||
// #define Slave_USART USART2
|
||||
#define Mcu_USART USART2
|
||||
#define Su806_USART UART8
|
||||
#define Lora_USART UART7
|
||||
|
||||
void uart2Init(int baud);
|
||||
void uart3Init(int baud);
|
||||
void uart4Init(int baud);
|
||||
void uart5Init(int baud);
|
||||
void uart6Init(int baud);
|
||||
void uart7Init(int baud);
|
||||
void uart8Init(int baud);
|
||||
|
||||
#define J1_USART UART6
|
||||
#define J2_USART UART7
|
||||
#define J3_USART USART2
|
||||
#define J4_USART UART8
|
||||
#define J5_0_USART USART3
|
||||
#define Upward_USART UART5
|
||||
void setIDLE(USART_TypeDef *USARTx, FunctionalState state);
|
||||
void setTXE(USART_TypeDef *USARTx, FunctionalState state);
|
||||
|
||||
/* 串口6 PE5 */
|
||||
#define J1_DE_PROT GPIOE
|
||||
#define J1_DE_PIN GPIO_Pin_5
|
||||
|
||||
/* 串口7 PE6 */
|
||||
#define J2_DE_PROT GPIOE
|
||||
#define J2_DE_PIN GPIO_Pin_6
|
||||
|
||||
/* 串口2 PA1 */
|
||||
#define J3_DE_PROT GPIOA
|
||||
#define J3_DE_PIN GPIO_Pin_1
|
||||
|
||||
/* 串口8 PE5 */
|
||||
#define J4_DE_PROT GPIOB
|
||||
#define J4_DE_PIN GPIO_Pin_0
|
||||
|
||||
/* 串口3 分时复用 */
|
||||
/*
|
||||
| A - B - C - YX |
|
||||
| 0 - 0 - 0 - J0 |
|
||||
| 0 - 0 - 1 - J5 |
|
||||
| 0 - 1 - 0 - J6 |
|
||||
| 0 - 1 - 1 - J7 |
|
||||
| 1 - 0 - 0 - J8 |
|
||||
| 1 - 0 - 1 - J9 |
|
||||
*/
|
||||
#define J5_0_DE_PROT GPIOD
|
||||
#define J5_0_DE_PIN GPIO_Pin_8
|
||||
#define J5_0_A_PROT GPIOD
|
||||
#define J5_0_A_PIN GPIO_Pin_9
|
||||
#define J5_0_B_PROT GPIOD
|
||||
#define J5_0_B_PIN GPIO_Pin_10
|
||||
#define J5_0_C_PROT GPIOD
|
||||
#define J5_0_C_PIN GPIO_Pin_11
|
||||
|
||||
#define write485 Bit_SET
|
||||
#define read485 Bit_RESET
|
||||
|
||||
|
||||
void set_485_Read(void);
|
||||
|
||||
/* J1_UART6 */
|
||||
void J1_485_Init(uint32_t baud);
|
||||
#define readJ1_485 GPIO_WriteBit(J1_DE_PROT, J1_DE_PIN, read485);
|
||||
#define writeJ1_485 GPIO_WriteBit(J1_DE_PROT, J1_DE_PIN, write485);
|
||||
|
||||
/* J2_UART7 */
|
||||
void J2_485_Init(uint32_t baud);
|
||||
#define readJ2_485 GPIO_WriteBit(J2_DE_PROT, J2_DE_PIN, read485);
|
||||
#define writeJ2_485 GPIO_WriteBit(J2_DE_PROT, J2_DE_PIN, write485);
|
||||
|
||||
/* J3_USART2 */
|
||||
void J3_485_Init(uint32_t baud);
|
||||
#define readJ3_485 GPIO_WriteBit(J3_DE_PROT, J3_DE_PIN, read485);
|
||||
#define writeJ3_485 GPIO_WriteBit(J3_DE_PROT, J3_DE_PIN, write485);
|
||||
|
||||
/* J4_UART8 */
|
||||
void J4_485_Init(uint32_t baud);
|
||||
#define readJ4_485 GPIO_WriteBit(J4_DE_PROT, J4_DE_PIN, read485);
|
||||
#define writeJ4_485 GPIO_WriteBit(J4_DE_PROT, J4_DE_PIN, write485);
|
||||
|
||||
/* J0-5_USART3 */
|
||||
void J5_0_485_Init(uint32_t baud);
|
||||
#define readJ5_0_485 GPIO_WriteBit(J5_0_DE_PROT, J5_0_DE_PIN, read485);
|
||||
#define writeJ5_0_485 GPIO_WriteBit(J5_0_DE_PROT, J5_0_DE_PIN, write485);
|
||||
void USART_CONNET_J0(void);
|
||||
void USART_CONNET_J5(void);
|
||||
void USART_CONNET_J6(void);
|
||||
void USART_CONNET_J7(void);
|
||||
void USART_CONNET_J8(void);
|
||||
void USART_CONNET_J9(void);
|
||||
|
||||
#ifdef uart4_enable
|
||||
/* LORA_UART4 */
|
||||
void LORA_UART4_Init(uint32_t baud);
|
||||
#endif
|
||||
|
||||
/* Upward_UART5 */
|
||||
void Upward_UART5_Init(uint32_t baud);
|
||||
|
||||
extern void J3_Interrupt();
|
||||
extern void J5_0_Interrupt();
|
||||
extern void Upward_Interrupt();
|
||||
extern void J0_Interrupt();
|
||||
extern void J1_Interrupt();
|
||||
extern void J2_Interrupt();
|
||||
extern void J3_Interrupt();
|
||||
extern void J4_Interrupt();
|
||||
extern void J5_Interrupt();
|
||||
extern void J6_Interrupt();
|
||||
extern void J7_Interrupt();
|
||||
extern void J8_Interrupt();
|
||||
extern void J9_Interrupt();
|
||||
extern void Mcu_Interrupt();
|
||||
extern void Su806_Interrupt();
|
||||
extern void Lora_Interrupt();
|
||||
|
||||
void USARTx_SendByte(USART_TypeDef* pUSARTx, uint8_t data);
|
||||
void USARTx_SendStr_Len(USART_TypeDef* pUSARTx, char *str, int len);
|
||||
|
||||
#endif /* HARDWARE_RS485_UART_H_ */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
/* adc校准值 */
|
||||
int16_t Calibrattion_Val = 0;
|
||||
#define adcNum 3
|
||||
#define adcNum 4
|
||||
/* 通过dma将adc采集的数据存入 */
|
||||
uint16_t adcData[adcNum] = {0};
|
||||
|
||||
|
@ -18,18 +18,22 @@ void HD_ADC_InIt(void)
|
|||
GPIO_InitTypeDef GPIO_InitStructure={0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE );
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE );
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE );
|
||||
RCC_ADCCLKConfig(RCC_PCLK2_Div4);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
ADC_DeInit(ADC1);
|
||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||
|
@ -89,8 +93,9 @@ void startAdcCapture(void)
|
|||
|
||||
/* 设置转换顺序 */
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_239Cycles5);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 2, ADC_SampleTime_239Cycles5);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 3, ADC_SampleTime_239Cycles5);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 2, ADC_SampleTime_239Cycles5);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 3, ADC_SampleTime_239Cycles5);
|
||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 4, ADC_SampleTime_239Cycles5);
|
||||
|
||||
/* 使能ADC的dma请求 */
|
||||
ADC_DMACmd(ADC1, ENABLE);
|
||||
|
|
|
@ -7,450 +7,54 @@
|
|||
#include "HD_Flash.h"
|
||||
#include "pDebug.h"
|
||||
|
||||
/* Global Variable */
|
||||
uint8_t SPI_FLASH_BUF[4096];
|
||||
|
||||
void delay_us(uint32_t us) {
|
||||
volatile uint32_t cycles = us * SystemCoreClock / 4000000; // 根据实测调整
|
||||
while (cycles--) {
|
||||
__asm__ volatile ("nop"); // 防止循环被优化
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Init
|
||||
* Description : Configuring the SPI for operation flash.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Init(void)
|
||||
uint8_t readFlash(uint32_t* pBuffer,uint32_t ReadAddr,uint16_t dataLen)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
SPI_InitTypeDef SPI_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOX, ENABLE );
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPIX, ENABLE );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = CS_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(CS_GPIO, &GPIO_InitStructure);
|
||||
GPIO_SetBits(CS_GPIO, CS_PIN); //CS引脚PA15置高电平
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = CLK_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(CLK_GPIO, &GPIO_InitStructure );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = DO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
|
||||
GPIO_Init(DO_GPIO, &GPIO_InitStructure );
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = DI_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(DI_GPIO, &GPIO_InitStructure );
|
||||
|
||||
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI通讯方向为双线全双工方式
|
||||
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设置SPI为主机端模式
|
||||
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //设置SPI通讯的数据帧大小为8位
|
||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //设置SPI的时钟极性为高电平
|
||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //设置SPI的时钟相位为在SCK的偶数边沿采集数据
|
||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //设置NSS引脚(即片选引脚)的使用模式为软件模式
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //设置波特率分频因子为4分频
|
||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //设置数据传输为高位数据在前
|
||||
SPI_InitStructure.SPI_CRCPolynomial = 7; //SPI的CRC校验中多项式的值
|
||||
SPI_Init(SPIX, &SPI_InitStructure); //初始化SPI
|
||||
|
||||
SPI_Cmd(SPIX, ENABLE); //使能SPI3外设
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPIX_ReadWriteByte
|
||||
* Description : SPIX read or write one byte.
|
||||
* Input : TxData: write one byte data.
|
||||
* Return : Read one byte data.
|
||||
*******************************************************************************/
|
||||
u8 SPI_ReadWriteByte(u8 TxData)
|
||||
{
|
||||
u8 i=0;
|
||||
while (SPI_I2S_GetFlagStatus(SPIX, SPI_I2S_FLAG_TXE) == RESET) //等待发送缓冲区为空,TXE事件
|
||||
{
|
||||
i++;
|
||||
if(i>200)return 0;
|
||||
}
|
||||
SPI_I2S_SendData(SPIX, TxData); //写入数据寄存器,把要写入的数据写入发送缓冲区,即通过外设SPI1发送一个数据
|
||||
i=0;
|
||||
while (SPI_I2S_GetFlagStatus(SPIX, SPI_I2S_FLAG_RXNE) == RESET) //等待接收缓冲区非空,RXNE事件
|
||||
{
|
||||
i++;
|
||||
if(i>200)return 0;
|
||||
}
|
||||
return SPI_I2S_ReceiveData(SPIX); //读取数据寄存器,获取接收缓冲区数据,即返回SPI1最近接收到的数据
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_ReadSR
|
||||
* Description : Read W25Qxx status register.
|
||||
* ——BIT7 6 5 4 3 2 1 0
|
||||
* ——SPR RV TB BP2 BP1 BP0 WEL BUSY
|
||||
* Input : None
|
||||
* Return : byte: status register value.
|
||||
*******************************************************************************/
|
||||
u8 SPI_Flash_ReadSR(void)
|
||||
{
|
||||
u8 byte=0;
|
||||
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0); //PA2=0,使能片选信号
|
||||
SPI_ReadWriteByte(W25X_ReadStatusReg); //发送读状态寄存器命令
|
||||
byte=SPI_ReadWriteByte(0Xff); //读取一个字节
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1); //取消片选信号
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_FLASH_Write_SR
|
||||
* Description : Write W25Qxx status register.
|
||||
* Input : sr:status register value.
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_FLASH_Write_SR(u8 sr)
|
||||
{
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_WriteStatusReg); //发送写状态寄存器命令
|
||||
SPI_ReadWriteByte(sr); //写入一个字节
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Wait_Busy
|
||||
* Description : Wait flash free.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Wait_Busy(void)
|
||||
{
|
||||
while((SPI_Flash_ReadSR()&0x01)==0x01); //等待FLASH空闲
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_FLASH_Write_Enable
|
||||
* Description : Enable flash write.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_FLASH_Write_Enable(void)
|
||||
{
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_WriteEnable); //发送写使能
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_FLASH_Write_Disable
|
||||
* Description : Disable flash write.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_FLASH_Write_Disable(void)
|
||||
{
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_WriteDisable); //发送写禁止指令
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_ReadID
|
||||
* Description : Read flash ID.
|
||||
* Input : None
|
||||
* Return : Temp: FLASH ID.
|
||||
*******************************************************************************/
|
||||
u16 SPI_Flash_ReadID(void)
|
||||
{
|
||||
u16 Temp = 0;
|
||||
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_ManufactDeviceID); //发送读取ID命令
|
||||
SPI_ReadWriteByte(0x00);
|
||||
SPI_ReadWriteByte(0x00);
|
||||
SPI_ReadWriteByte(0x00);
|
||||
Temp|=SPI_ReadWriteByte(0xFF)<<8;
|
||||
Temp|=SPI_ReadWriteByte(0xFF);
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
|
||||
return Temp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Erase_Sector
|
||||
* Description : Erase one sector(4Kbyte).
|
||||
* Input : Dst_Addr: 0 —— 2047
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Erase_Sector(u32 Dst_Addr)
|
||||
{
|
||||
Dst_Addr*=4096;
|
||||
SPI_FLASH_Write_Enable();
|
||||
SPI_Flash_Wait_Busy();
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_SectorErase); //发送扇区擦除指令
|
||||
SPI_ReadWriteByte((u8)((Dst_Addr)>>16)); //发送24bit地址
|
||||
SPI_ReadWriteByte((u8)((Dst_Addr)>>8));
|
||||
SPI_ReadWriteByte((u8)Dst_Addr);
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
SPI_Flash_Wait_Busy(); //等待擦除完成
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Read
|
||||
* Description : Read data from flash.
|
||||
* Input : pBuffer:
|
||||
* ReadAddr:Initial address(24bit).
|
||||
* size: Data length.
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Read(u8* pBuffer,u32 ReadAddr,u16 size)
|
||||
{
|
||||
u16 i;
|
||||
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_ReadData); //发送读取命令
|
||||
SPI_ReadWriteByte((u8)((ReadAddr)>>16)); //发送24bit地址
|
||||
SPI_ReadWriteByte((u8)((ReadAddr)>>8));
|
||||
SPI_ReadWriteByte((u8)ReadAddr);
|
||||
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
pBuffer[i] = SPI_ReadWriteByte(0XFF); //循环读数
|
||||
}
|
||||
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Write_Page
|
||||
* Description : Write data by one page.
|
||||
* Input : pBuffer:
|
||||
* WriteAddr:Initial address(24bit).
|
||||
* size:Data length.
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Write_Page(u8* pBuffer,u32 WriteAddr,u16 size)
|
||||
{
|
||||
u16 i;
|
||||
|
||||
SPI_FLASH_Write_Enable();
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_PageProgram); //发送写页命令
|
||||
SPI_ReadWriteByte((u8)((WriteAddr)>>16)); //发送24bit地址
|
||||
SPI_ReadWriteByte((u8)((WriteAddr)>>8));
|
||||
SPI_ReadWriteByte((u8)WriteAddr);
|
||||
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
SPI_ReadWriteByte(pBuffer[i]); //循环写数
|
||||
for (int i = 0; i < dataLen; i++) {
|
||||
*(pBuffer + i) = *(uint32_t*)(ReadAddr + 4 * i);
|
||||
}
|
||||
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
SPI_Flash_Wait_Busy(); //等待写入结束
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Write_NoCheck
|
||||
* Description : Write data to flash.(need Erase)
|
||||
* All data in address rang is 0xFF.
|
||||
* Input : pBuffer:
|
||||
* WriteAddr: Initial address(24bit).
|
||||
* size: Data length.
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Write_NoCheck(u8* pBuffer,u32 WriteAddr,u16 size)
|
||||
|
||||
/*
|
||||
* @brief 将数据写入flash的某个闪存页,WriteAddr必须为某个页的开头
|
||||
* @param pBuffer 要写入的数据
|
||||
WriteAddr 要写入的地址
|
||||
NumByteToWrite 要写入的长度
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
uint8_t writeFlash(uint32_t* pBuffer,uint32_t WriteAddr, uint16_t NumByteToWrite)
|
||||
{
|
||||
u16 pageremain;
|
||||
|
||||
pageremain=256-WriteAddr%256; //单页剩余的字节数
|
||||
|
||||
if(size<=pageremain)pageremain=size; //不大于256个字节
|
||||
|
||||
while(1)
|
||||
{
|
||||
SPI_Flash_Write_Page(pBuffer,WriteAddr,pageremain);
|
||||
|
||||
if(size==pageremain)
|
||||
{
|
||||
break; //写入结束了
|
||||
}
|
||||
else
|
||||
{
|
||||
pBuffer+=pageremain;
|
||||
WriteAddr+=pageremain;
|
||||
size-=pageremain; //减去已经写入了的字节数
|
||||
|
||||
if(size>256)pageremain=256; //一次可以写入256个字节
|
||||
else pageremain=size; //不够256个字节了
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Write
|
||||
* Description : Write data to flash.(no need Erase)
|
||||
* Input : pBuffer:
|
||||
* WriteAddr: Initial address(24bit).
|
||||
* size: Data length.
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Write(u8* pBuffer,u32 WriteAddr,u16 size)
|
||||
{
|
||||
u32 secpos;
|
||||
u16 secoff;
|
||||
u16 secremain;
|
||||
u16 i;
|
||||
|
||||
secpos=WriteAddr/4096; //扇区地址
|
||||
secoff=WriteAddr%4096; //在扇区内的便宜
|
||||
secremain=4096-secoff; //扇区剩余空间大小
|
||||
|
||||
if(size<=secremain)secremain=size; //不大于4096个字节
|
||||
|
||||
while(1)
|
||||
{
|
||||
SPI_Flash_Read(SPI_FLASH_BUF,secpos*4096,4096); //读出整个扇区的内容
|
||||
|
||||
for(i=0;i<secremain;i++) //校验数据
|
||||
{
|
||||
if(SPI_FLASH_BUF[secoff+i]!=0XFF)break; //需要擦除
|
||||
}
|
||||
|
||||
if(i<secremain) //需要擦除
|
||||
{
|
||||
SPI_Flash_Erase_Sector(secpos); //擦除这个扇区
|
||||
|
||||
for(i=0;i<secremain;i++) //复制
|
||||
{
|
||||
SPI_FLASH_BUF[i+secoff]=pBuffer[i];
|
||||
}
|
||||
|
||||
SPI_Flash_Write_NoCheck(SPI_FLASH_BUF,secpos*4096,4096); //写入整个扇区
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SPI_Flash_Write_NoCheck(pBuffer,WriteAddr,secremain); //写已经擦除了的,直接写入扇区剩余空间
|
||||
}
|
||||
|
||||
if(size==secremain)
|
||||
{
|
||||
break; //写入结束
|
||||
}
|
||||
else
|
||||
{
|
||||
secpos++; //扇区地址增1
|
||||
secoff=0; //偏移位置为0
|
||||
|
||||
pBuffer+=secremain; //指针偏移
|
||||
WriteAddr+=secremain; //写地址偏移
|
||||
size-=secremain; //字节数递减
|
||||
|
||||
if(size>4096)
|
||||
{
|
||||
secremain=4096; //下一个扇区还是写不完
|
||||
}
|
||||
else
|
||||
{
|
||||
secremain=size; //下一个扇区可以写完了
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_Erase_Chip
|
||||
* Description : Erase all FLASH pages.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_Erase_Chip(void)
|
||||
{
|
||||
SPI_FLASH_Write_Enable();
|
||||
SPI_Flash_Wait_Busy();
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_ChipErase); //发送片擦除指令
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
SPI_Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_PowerDown
|
||||
* Description : Enter power down mode.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_PowerDown(void)
|
||||
{
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_PowerDown); //发送进入断电模式之灵
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
delay_us(3);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SPI_Flash_WAKEUP
|
||||
* Description : Power down wake up.
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SPI_Flash_WAKEUP(void)
|
||||
{
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 0);
|
||||
SPI_ReadWriteByte(W25X_ReleasePowerDown); //发送断电唤醒指令
|
||||
GPIO_WriteBit(CS_GPIO, CS_PIN, 1);
|
||||
delay_us(3);
|
||||
}
|
||||
|
||||
void SPI_Flash_TEST(void)
|
||||
{
|
||||
const int SIZE = 100;
|
||||
u8 TEXT_Buf[100] = "hello world \n";
|
||||
u8 datap[SIZE];
|
||||
u16 Flash_Model;
|
||||
SPI_Flash_Init();
|
||||
Flash_Model = SPI_Flash_ReadID();
|
||||
log_info("SPI_Flash_ReadID = %x \n", Flash_Model);
|
||||
switch(Flash_Model)
|
||||
{
|
||||
case W25Q80:
|
||||
log_info("W25Q80 OK!\r\n");
|
||||
break;
|
||||
case W25Q16:
|
||||
log_info("W25Q16 OK!\r\n");
|
||||
break;
|
||||
case W25Q32:
|
||||
log_info("W25Q32 OK!\r\n");
|
||||
break;
|
||||
case W25Q64:
|
||||
log_info("W25Q64 OK!\r\n");
|
||||
break;
|
||||
case W25Q128:
|
||||
log_info("W25Q128 OK!\r\n");
|
||||
break;
|
||||
default:
|
||||
log_info("Fail!\r\n");
|
||||
break;
|
||||
/* 擦除某个闪存页 */
|
||||
int ret = FLASH_ROM_ERASE(WriteAddr, 256);
|
||||
if (ret != FLASH_COMPLETE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_info("Start Erase W25Qxx....\r\n");
|
||||
SPI_Flash_Erase_Sector(0);
|
||||
log_info("W25Qxx Erase Finished!\r\n");
|
||||
uint32_t buf[64] = {0};
|
||||
memcpy(buf, pBuffer, (NumByteToWrite / 4));
|
||||
|
||||
delay_us(500);
|
||||
log_info("Start Write W25Qxx....\r\n");
|
||||
SPI_Flash_Write((u8*)TEXT_Buf,0,SIZE);
|
||||
log_info("W25Qxx Write Finished!\r\n");
|
||||
ret = FLASH_ROM_WRITE(WriteAddr, buf, 256);
|
||||
if (ret != FLASH_COMPLETE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
delay_us(500);
|
||||
log_info("Start Read W25Qxx....\r\n");
|
||||
SPI_Flash_Read(datap,0x0,SIZE);
|
||||
log_info("READ:%s\r\n", datap );
|
||||
|
||||
// FLASH_Unlock();
|
||||
// for (int i = 0; i < NumByteToWrite; i++) {
|
||||
// ret = FLASH_ProgramOptionByteData((uint32_t)((uint8_t *)WriteAddr + 1), *(pBuffer + i));
|
||||
// if (ret != FLASH_COMPLETE) {
|
||||
// FLASH_Lock();
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
// FLASH_Lock();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,24 +1,39 @@
|
|||
#include "HD_GPIO.h"
|
||||
|
||||
void HD_GPIO_Init(void)
|
||||
|
||||
/**
|
||||
* @brief 初始化主从mcu判断引脚,并返回主从引脚信息
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint8_t mcu_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/* 安卓模块电源使能引脚,默认不使能 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_PwrCtrl_GPIO_PIN;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
|
||||
return HD_InputGPIO_Read(GPIOE, GPIO_Pin_4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化端口电源控制引脚
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void PwrCtrl_GPIO_Init(void)
|
||||
{
|
||||
/* 电源控制引脚,默认不开启电源 */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J1_PwrCtrl_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(GPIO_PwrCtrl_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(GPIO_PwrCtrl_GPIO_PROT, GPIO_PwrCtrl_GPIO_PIN, Bit_RESET);
|
||||
|
||||
/* 复位安卓模块引脚,默认低电平 */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_PwrKey_GPIO_PIN;
|
||||
GPIO_Init(GPIO_PwrKey_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(GPIO_PwrKey_GPIO_PROT, GPIO_PwrKey_GPIO_PIN, Bit_RESET);
|
||||
|
||||
/* 电源控制引脚,默认不开启电源 */
|
||||
GPIO_InitStructure.GPIO_Pin = J1_PwrCtrl_GPIO_PIN;
|
||||
GPIO_Init(J1_PwrCtrl_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J1_PwrCtrl_GPIO_PROT, J1_PwrCtrl_GPIO_PIN, Bit_RESET);
|
||||
|
||||
|
@ -53,19 +68,153 @@ void HD_GPIO_Init(void)
|
|||
GPIO_InitStructure.GPIO_Pin = J9_PwrCtrl_GPIO_PIN;
|
||||
GPIO_Init(J9_PwrCtrl_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J9_PwrCtrl_GPIO_PROT, J9_PwrCtrl_GPIO_PIN, Bit_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 安卓模块控制引脚初始化
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Android_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
|
||||
/* 安卓模块电源使能引脚,默认不使能 */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_PwrCtrl_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(GPIO_PwrCtrl_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(GPIO_PwrCtrl_GPIO_PROT, GPIO_PwrCtrl_GPIO_PIN, Bit_RESET);
|
||||
|
||||
/* 复位安卓模块引脚,默认低电平 */
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_PwrKey_GPIO_PIN;
|
||||
GPIO_Init(GPIO_PwrKey_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(GPIO_PwrKey_GPIO_PROT, GPIO_PwrKey_GPIO_PIN, Bit_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 喂狗引脚初始化
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void WDI_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
|
||||
/* 喂狗引脚 */
|
||||
GPIO_InitStructure.GPIO_Pin = WDI_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(WDI_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(WDI_GPIO_PROT, WDI_GPIO_PIN, Bit_SET);
|
||||
|
||||
/* LED引脚 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief led灯引脚初始化
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void LED_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = LED_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(LED_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(LED_GPIO_PROT, LED_GPIO_PIN, Bit_SET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 主机485读写控制引脚初始化
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Host485De_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J0De_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(J0De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J0De_GPIO_PROT, J0De_GPIO_PIN, write);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J2De_GPIO_PIN;
|
||||
GPIO_Init(J2De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J2De_GPIO_PROT, J2De_GPIO_PIN, write);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J4De_GPIO_PIN;
|
||||
GPIO_Init(J4De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J4De_GPIO_PROT, J4De_GPIO_PIN, write);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J6De_GPIO_PIN;
|
||||
GPIO_Init(J6De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J6De_GPIO_PROT, J6De_GPIO_PIN, write);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从机485读写控制引脚初始化
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Slave485De_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J1De_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(J1De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J1De_GPIO_PROT, J1De_GPIO_PIN, write);
|
||||
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J3De_GPIO_PIN;
|
||||
GPIO_Init(J3De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J3De_GPIO_PROT, J3De_GPIO_PIN, write);
|
||||
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J5De_GPIO_PIN;
|
||||
GPIO_Init(J5De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J5De_GPIO_PROT, J5De_GPIO_PIN, write);
|
||||
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J7De_GPIO_PIN;
|
||||
GPIO_Init(J7De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J7De_GPIO_PROT, J7De_GPIO_PIN, write);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J8De_GPIO_PIN;
|
||||
GPIO_Init(J8De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J8De_GPIO_PROT, J8De_GPIO_PIN, write);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = J9De_GPIO_PIN;
|
||||
GPIO_Init(J9De_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(J9De_GPIO_PROT, J9De_GPIO_PIN, write);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化控制从mcu复位引脚
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void ctrlSlave_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = ctrlSlave_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(ctrlSlave_GPIO_PROT, &GPIO_InitStructure);
|
||||
GPIO_WriteBit(ctrlSlave_GPIO_PROT, ctrlSlave_GPIO_PIN, Bit_SET);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ÉèÖÃIOÊä³öµçƽ
|
||||
* @param GPIOx
|
||||
|
|
|
@ -2,161 +2,22 @@
|
|||
|
||||
void USART2_IRQHandler(void) __attribute__((interrupt()));
|
||||
void USART3_IRQHandler(void) __attribute__((interrupt()));
|
||||
#ifdef uart4_enable
|
||||
// void UART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void UART4_IRQHandler(void) __attribute__((interrupt()));
|
||||
#endif
|
||||
void UART5_IRQHandler(void) __attribute__((interrupt()));
|
||||
void UART6_IRQHandler(void) __attribute__((interrupt()));
|
||||
void UART7_IRQHandler(void) __attribute__((interrupt()));
|
||||
void UART8_IRQHandler(void) __attribute__((interrupt()));
|
||||
|
||||
#define write Bit_SET
|
||||
#define read Bit_RESET
|
||||
|
||||
|
||||
/*
|
||||
* @brief 设置所有485状态为读
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void set_485_Read(void)
|
||||
/**
|
||||
* @brief 初始化串口2
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart2Init(int baud)
|
||||
{
|
||||
readJ1_485;
|
||||
readJ2_485;
|
||||
readJ3_485;
|
||||
readJ4_485;
|
||||
readJ5_0_485;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 初始化UART6对应的J1_485,默认为接收
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J1_485_Init(uint32_t baud)
|
||||
{
|
||||
/* 初始化DE引脚 */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = J1_DE_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(J1_DE_PROT, &GPIO_InitStructure);
|
||||
// readJ1_485;
|
||||
writeJ1_485;
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART6 TX --> PC0 RX --> PC1 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART6, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC0为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PC1为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART6, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART6_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART6, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(UART6, USART_IT_IDLE, ENABLE);
|
||||
|
||||
USART_Cmd(UART6,ENABLE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @brief 初始化UART7对应的J2_485,默认为接收,电源关闭状态
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J2_485_Init(uint32_t baud)
|
||||
{
|
||||
/* 初始化DE引脚 */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = J2_DE_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(J2_DE_PROT, &GPIO_InitStructure);
|
||||
// readJ2_485;
|
||||
writeJ2_485;
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART7 TX --> PC2 RX --> PC3 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART7, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC2为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PC3为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART7, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART7_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART7, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(UART7, USART_IT_IDLE, ENABLE);
|
||||
|
||||
USART_Cmd(UART7,ENABLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 初始化USART2对应的J3_485,默认为接收,电源关闭状态
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J3_485_Init(uint32_t baud)
|
||||
{
|
||||
/* 初始化DE引脚 */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = J3_DE_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(J3_DE_PROT, &GPIO_InitStructure);
|
||||
// readJ3_485;
|
||||
writeJ3_485;
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
|
@ -188,29 +49,234 @@ void J3_485_Init(uint32_t baud)
|
|||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);
|
||||
|
||||
USART_Cmd(USART2,ENABLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 初始化UART8对应的J4_485,默认为接收,电源关闭状态
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J4_485_Init(uint32_t baud)
|
||||
/**
|
||||
* @brief 初始化串口3
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart3Init(int baud)
|
||||
{
|
||||
/* 初始化DE引脚 */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
GPIO_InitStructure.GPIO_Pin = J4_DE_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(J4_DE_PROT, &GPIO_InitStructure);
|
||||
// readJ4_485;
|
||||
writeJ4_485;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* USART3 TX --> PB10 RX --> PB11 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PB10为复用推挽输出
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PB11为浮空输入
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(USART3, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //抢占优先级为1
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为1
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(USART3,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化串口4
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart4Init(int baud)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART4 TX --> PC10 RX --> PC11 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC10为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PC11为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART4, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(UART4,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化串口5
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart5Init(int baud)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART5 TX --> PC12 RX --> PD2 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC12为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PD2为浮空输入
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART5, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(UART5,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化串口6
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart6Init(int baud)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART6 TX --> PC0 RX --> PC1 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART6, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC0为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PC1为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART6, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART6_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART6, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(UART6,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化串口7
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart7Init(int baud)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART7 TX --> PC2 RX --> PC3 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART7, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC2为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PC3为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART7, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART7_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART7, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(UART7,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化串口8
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*/
|
||||
void uart8Init(int baud)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
|
@ -242,348 +308,75 @@ void J4_485_Init(uint32_t baud)
|
|||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART8, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(UART8, USART_IT_IDLE, ENABLE);
|
||||
|
||||
USART_Cmd(UART8,ENABLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 初始话USART3用于控制J5-0共6个485接口,设置控制的485为J0,电源全部关闭
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void J5_0_485_Init(uint32_t baud)
|
||||
/**
|
||||
* @brief 设置空闲中断状态
|
||||
* @param USARTx 波特率
|
||||
state 状态
|
||||
* @retval
|
||||
*/
|
||||
void setIDLE(USART_TypeDef *USARTx, FunctionalState state)
|
||||
{
|
||||
/* 初始化DE引脚 */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
|
||||
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(J5_0_DE_PROT, &GPIO_InitStructure);
|
||||
// readJ5_0_485;
|
||||
writeJ5_0_485;
|
||||
// writeJ5_0_485;
|
||||
GPIO_InitStructure.GPIO_Pin = J5_0_A_PIN;
|
||||
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = J5_0_B_PIN;
|
||||
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = J5_0_C_PIN;
|
||||
GPIO_Init(J5_0_DE_PROT, &GPIO_InitStructure);
|
||||
USART_CONNET_J0();
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* USART3 TX --> PB10 RX --> PB11 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PB10为复用推挽输出
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PB11为浮空输入
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(USART3, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //抢占优先级为1
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级为1
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
|
||||
// USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
|
||||
|
||||
USART_Cmd(USART3,ENABLE);
|
||||
}
|
||||
/*
|
||||
* Function Name : USART_CONNET_J0
|
||||
* Description : 控制串口3连接J0对应的485.
|
||||
* Input : None
|
||||
* Return : None
|
||||
**/
|
||||
void USART_CONNET_J0(void)
|
||||
{
|
||||
GPIO_WriteBit(J5_0_A_PROT, J5_0_A_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_B_PROT, J5_0_B_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_C_PROT, J5_0_C_PIN, Bit_RESET);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : USART_CONNET_J5
|
||||
* Description : 控制串口3连接J5对应的485.
|
||||
* Input : None
|
||||
* Return : None
|
||||
**/
|
||||
void USART_CONNET_J5(void)
|
||||
{
|
||||
GPIO_WriteBit(J5_0_A_PROT, J5_0_A_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_B_PROT, J5_0_B_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_C_PROT, J5_0_C_PIN, Bit_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : USART_CONNET_J6
|
||||
* Description : 控制串口3连接J6对应的485.
|
||||
* Input : None
|
||||
* Return : None
|
||||
**/
|
||||
void USART_CONNET_J6(void)
|
||||
{
|
||||
GPIO_WriteBit(J5_0_A_PROT, J5_0_A_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_B_PROT, J5_0_B_PIN, Bit_SET);
|
||||
GPIO_WriteBit(J5_0_C_PROT, J5_0_C_PIN, Bit_RESET);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : USART_CONNET_J7
|
||||
* Description : 控制串口3连接J7对应的485.
|
||||
* Input : None
|
||||
* Return : None
|
||||
**/
|
||||
void USART_CONNET_J7(void)
|
||||
{
|
||||
GPIO_WriteBit(J5_0_A_PROT, J5_0_A_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_B_PROT, J5_0_B_PIN, Bit_SET);
|
||||
GPIO_WriteBit(J5_0_C_PROT, J5_0_C_PIN, Bit_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : USART_CONNET_J8
|
||||
* Description : 控制串口3连接J8对应的485.
|
||||
* Input : None
|
||||
* Return : None
|
||||
**/
|
||||
void USART_CONNET_J8(void)
|
||||
{
|
||||
GPIO_WriteBit(J5_0_A_PROT, J5_0_A_PIN, Bit_SET);
|
||||
GPIO_WriteBit(J5_0_B_PROT, J5_0_B_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_C_PROT, J5_0_C_PIN, Bit_RESET);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : USART_CONNET_J9
|
||||
* Description : 控制串口3连接J9对应的485.
|
||||
* Input : None
|
||||
* Return : None
|
||||
**/
|
||||
void USART_CONNET_J9(void)
|
||||
{
|
||||
GPIO_WriteBit(J5_0_A_PROT, J5_0_A_PIN, Bit_SET);
|
||||
GPIO_WriteBit(J5_0_B_PROT, J5_0_B_PIN, Bit_RESET);
|
||||
GPIO_WriteBit(J5_0_C_PROT, J5_0_C_PIN, Bit_SET);
|
||||
USART_ITConfig(USARTx, USART_IT_IDLE, state);
|
||||
}
|
||||
|
||||
|
||||
#ifdef uart4_enable
|
||||
/*
|
||||
* @brief 初始化UART4对应的LORA串口
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void LORA_UART4_Init(uint32_t baud)
|
||||
/**
|
||||
* @brief 设置中断发送状态
|
||||
* @param USARTx 波特率
|
||||
state 状态
|
||||
* @retval
|
||||
*/
|
||||
void setTXE(USART_TypeDef *USARTx, FunctionalState state)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART4 TX --> PC10 RX --> PC11 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC10为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PC11为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART4, &USART_InitStructure);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
|
||||
|
||||
USART_Cmd(UART4,ENABLE);
|
||||
USART_ITConfig(USARTx, USART_IT_TXE, state);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @brief 初始化UART5对应的对上串口
|
||||
* @param baud 波特率
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void Upward_UART5_Init(uint32_t baud)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* UART5 TX --> PC12 RX --> PD2 */
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //设置PC12为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PD2为浮空输入
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baud;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_Init(UART5, &USART_InitStructure);
|
||||
|
||||
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级为3
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
|
||||
|
||||
USART_Cmd(UART5,ENABLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
J3_Interrupt();
|
||||
Mcu_Interrupt();
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
J5_0_Interrupt();
|
||||
J0_Interrupt();
|
||||
J1_Interrupt();
|
||||
}
|
||||
|
||||
#ifdef uart4_enable
|
||||
void UART4_IRQHandler(void)
|
||||
{
|
||||
|
||||
J2_Interrupt();
|
||||
J3_Interrupt();
|
||||
}
|
||||
#endif
|
||||
|
||||
void UART5_IRQHandler(void)
|
||||
{
|
||||
Upward_Interrupt();
|
||||
J4_Interrupt();
|
||||
J5_Interrupt();
|
||||
}
|
||||
|
||||
void UART6_IRQHandler(void)
|
||||
{
|
||||
J1_Interrupt();
|
||||
J6_Interrupt();
|
||||
J7_Interrupt();
|
||||
}
|
||||
|
||||
void UART7_IRQHandler(void)
|
||||
{
|
||||
J2_Interrupt();
|
||||
J9_Interrupt();
|
||||
Lora_Interrupt();
|
||||
}
|
||||
|
||||
void UART8_IRQHandler(void)
|
||||
{
|
||||
J4_Interrupt();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @brief 发送一个字符
|
||||
* @param pUSARTx 串口
|
||||
data 字符
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void USARTx_SendByte(USART_TypeDef* pUSARTx, uint8_t data)
|
||||
{
|
||||
while(USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET) /* waiting for sending finish */
|
||||
{
|
||||
}
|
||||
USART_SendData(pUSARTx, data);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief 发送字符串
|
||||
* @param pUSARTx 串口
|
||||
data 字符
|
||||
len 发送字符串的长度
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void USARTx_SendStr_Len(USART_TypeDef* pUSARTx, char *str, int len)
|
||||
{
|
||||
if (pUSARTx == J1_USART) {
|
||||
writeJ1_485;
|
||||
} else if (pUSARTx == J2_USART) {
|
||||
writeJ2_485;
|
||||
} else if (pUSARTx == J3_USART) {
|
||||
writeJ3_485;
|
||||
} else if (pUSARTx == J4_USART) {
|
||||
writeJ4_485;
|
||||
} else if (pUSARTx == J5_0_USART) {
|
||||
writeJ5_0_485;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
USARTx_SendByte(pUSARTx, str[i]);
|
||||
}
|
||||
|
||||
if (pUSARTx == J1_USART) {
|
||||
readJ1_485;
|
||||
} else if (pUSARTx == J2_USART) {
|
||||
readJ2_485;
|
||||
} else if (pUSARTx == J3_USART) {
|
||||
readJ3_485;
|
||||
} else if (pUSARTx == J4_USART) {
|
||||
readJ4_485;
|
||||
} else if (pUSARTx == J5_0_USART) {
|
||||
readJ5_0_485;
|
||||
}
|
||||
J8_Interrupt();
|
||||
Su806_Interrupt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
|
||||
#include "mcu_common.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
|
||||
|
||||
/* 储存解析时的数据 */
|
||||
uint8_t *mcuUartRxBuffer;
|
||||
uint16_t mcuUartRxBufferIndex = 0;
|
||||
uint8_t *J0_485RxBuffer;
|
||||
uint16_t J0_485RxBufferIndex = 0;
|
||||
uint8_t *J1_485RxBuffer;
|
||||
uint16_t J1_485RxBufferIndex = 0;
|
||||
uint8_t *J2_485RxBuffer;
|
||||
uint16_t J2_485RxBufferIndex = 0;
|
||||
uint8_t *J3_485RxBuffer;
|
||||
uint16_t J3_485RxBufferIndex = 0;
|
||||
uint8_t *J4_485RxBuffer;
|
||||
uint16_t J4_485RxBufferIndex = 0;
|
||||
uint8_t *J5_485RxBuffer;
|
||||
uint16_t J5_485RxBufferIndex = 0;
|
||||
uint8_t *J6_485RxBuffer;
|
||||
uint16_t J6_485RxBufferIndex = 0;
|
||||
uint8_t *J7_485RxBuffer;
|
||||
uint16_t J7_485RxBufferIndex = 0;
|
||||
uint8_t *J8_485RxBuffer;
|
||||
uint16_t J8_485RxBufferIndex = 0;
|
||||
uint8_t *J9_485RxBuffer;
|
||||
uint16_t J9_485RxBufferIndex = 0;
|
||||
uint8_t *su806RxBuffer;
|
||||
uint16_t su806RxBufferIndex = 0;
|
||||
uint8_t *loraRxBuffer;
|
||||
uint16_t loraRxBufferIndex = 0;
|
||||
|
||||
/* 计时参数,2秒后没解析出一帧数据,丢掉当前数据 */
|
||||
uint32_t mcuUartRxTime = 0;
|
||||
uint32_t su806UartRxTime = 0;
|
||||
|
||||
/* 状态机状态机变量 */
|
||||
uartStateMachine state = wait;
|
||||
|
||||
/* 帧长度 */
|
||||
uint16_t frameLength = 0;
|
||||
|
||||
#define hostMcuUartBufferLen 280
|
||||
#define slaveMcuUartBufferLen 1100
|
||||
#define su806BufferLen 1100
|
||||
#define rs485BufferLen 280
|
||||
#define loraBufferLen 280
|
||||
|
||||
uint8_t applyDataBuffer(void)
|
||||
{
|
||||
/* 从mcu */
|
||||
if (getMCU()) {
|
||||
mcuUartRxBuffer = pvPortMalloc(slaveMcuUartBufferLen);
|
||||
J1_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J3_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J5_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J7_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J8_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J9_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
|
||||
}
|
||||
/* 主mcu */
|
||||
else {
|
||||
mcuUartRxBuffer = pvPortMalloc(hostMcuUartBufferLen);
|
||||
su806RxBuffer = pvPortMalloc(su806BufferLen);
|
||||
J0_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J2_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J4_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
J6_485RxBuffer = pvPortMalloc(rs485BufferLen);
|
||||
loraRxBuffer = pvPortMalloc(loraBufferLen);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到两次获取节拍的差值
|
||||
* @param lastTick 上次获取的节拍值
|
||||
* @retval
|
||||
*/
|
||||
uint32_t getTickDiff(uint32_t lastTick)
|
||||
{
|
||||
int64_t temp;
|
||||
temp = xTaskGetTickCount() - lastTick;
|
||||
|
||||
/* 节拍值超过最大值后重新计数 */
|
||||
if (temp < 0) {
|
||||
temp = portMAX_DELAY - lastTick + xTaskGetTickCount();
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 用于波特率转化为传递的值
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
int baudConversionConfig(int baud)
|
||||
{
|
||||
if (baud == 4800) {
|
||||
return 0x0001;
|
||||
}
|
||||
else if (baud == 9600) {
|
||||
return 0x0002;
|
||||
}
|
||||
else if (baud == 19200) {
|
||||
return 0x0003;
|
||||
}
|
||||
else if (baud == 38400) {
|
||||
return 0x0004;
|
||||
}
|
||||
else if (baud == 57600) {
|
||||
return 0x0005;
|
||||
}
|
||||
else if (baud == 115200) {
|
||||
return 0x0006;
|
||||
}
|
||||
return 0x0002;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 用于传递的值转化为波特率
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
int configConversionBaud(int config)
|
||||
{
|
||||
if (config == 0x0001) {
|
||||
return 4800;
|
||||
}
|
||||
else if (config == 0x0002) {
|
||||
return 9600;
|
||||
}
|
||||
else if (config == 0x0003) {
|
||||
return 19200;
|
||||
}
|
||||
else if (config == 0x0004) {
|
||||
return 38400;
|
||||
}
|
||||
else if (config == 0x0005) {
|
||||
return 57600;
|
||||
}
|
||||
else if (config == 0x0006) {
|
||||
return 115200;
|
||||
}
|
||||
return 9600;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 用于modebus16crc校验
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
uint16_t modebusCrc(uint8_t *arr_buff, uint8_t len)
|
||||
{
|
||||
unsigned short crc = 0xFFFF;
|
||||
unsigned char i, j;
|
||||
for ( j = 0; j < len; j++){
|
||||
crc=crc ^ *arr_buff++;
|
||||
for (i=0; i<8; i++){
|
||||
if((crc&0x0001) >0){
|
||||
crc=crc>>1;
|
||||
crc=crc^ 0xa001;
|
||||
}else{
|
||||
crc=crc>>1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#ifndef __COMMON_ENUM_
|
||||
#define __COMMON_ENUM_
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
typedef enum {
|
||||
J0 = 0,
|
||||
J1 = 1,
|
||||
J2 = 2,
|
||||
J3 = 3,
|
||||
J4 = 4,
|
||||
J5 = 5,
|
||||
J6 = 6,
|
||||
J7 = 7,
|
||||
J8 = 8,
|
||||
J9 = 9,
|
||||
Lora = 10,
|
||||
HostMcu = 11,
|
||||
SlaveMcu = 12,
|
||||
} portEnum;
|
||||
|
||||
/* 功能码 */
|
||||
enum {
|
||||
SL_Function_Code_Read_Register = 0x30, /* 读寄存器数据 */
|
||||
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
|
||||
};
|
||||
|
||||
/* 状态机 */
|
||||
typedef enum {
|
||||
wait = 0, /* 串口状态机初始状态 */
|
||||
startFlagSL, /* 接收到帧头 */
|
||||
portSL, /* 接收到端口号 */
|
||||
lengthSL, /* 接收到数据包的长度 */
|
||||
endFlagSL, /* 接收到帧尾 */
|
||||
} uartStateMachine;
|
||||
|
||||
/* 2秒的节拍数 */
|
||||
#define tick_2S (configTICK_RATE_HZ * 2)
|
||||
/* 100ms */
|
||||
#define delayTick 50
|
||||
#define maxdataLen 100
|
||||
|
||||
extern uint8_t *mcuUartRxBuffer;
|
||||
extern uint16_t mcuUartRxBufferIndex;
|
||||
extern uint8_t *J0_485RxBuffer;
|
||||
extern uint16_t J0_485RxBufferIndex;
|
||||
extern uint8_t *J1_485RxBuffer;
|
||||
extern uint16_t J1_485RxBufferIndex;
|
||||
extern uint8_t *J2_485RxBuffer;
|
||||
extern uint16_t J2_485RxBufferIndex;
|
||||
extern uint8_t *J3_485RxBuffer;
|
||||
extern uint16_t J3_485RxBufferIndex;
|
||||
extern uint8_t *J4_485RxBuffer;
|
||||
extern uint16_t J4_485RxBufferIndex;
|
||||
extern uint8_t *J5_485RxBuffer;
|
||||
extern uint16_t J5_485RxBufferIndex;
|
||||
extern uint8_t *J6_485RxBuffer;
|
||||
extern uint16_t J6_485RxBufferIndex;
|
||||
extern uint8_t *J7_485RxBuffer;
|
||||
extern uint16_t J7_485RxBufferIndex;
|
||||
extern uint8_t *J8_485RxBuffer;
|
||||
extern uint16_t J8_485RxBufferIndex;
|
||||
extern uint8_t *J9_485RxBuffer;
|
||||
extern uint16_t J9_485RxBufferIndex;
|
||||
extern uint8_t *su806RxBuffer;
|
||||
extern uint16_t su806RxBufferIndex;
|
||||
extern uint8_t *loraRxBuffer;
|
||||
extern uint16_t loraRxBufferIndex;
|
||||
extern uint32_t mcuUartRxTime;
|
||||
extern uint32_t su806UartRxTime;
|
||||
extern uartStateMachine state;
|
||||
extern uint16_t frameLength;
|
||||
|
||||
uint8_t applyDataBuffer(void);
|
||||
|
||||
uint16_t modebusCrc(uint8_t *arr_buff, uint8_t len);
|
||||
int baudConversionConfig(int baud);
|
||||
int configConversionBaud(int config);
|
||||
uint32_t getTickDiff(uint32_t lastTick);
|
||||
|
||||
|
||||
#endif
|
|
@ -18,6 +18,16 @@
|
|||
"parentLogicPath": "",
|
||||
"type": "file",
|
||||
"name": "*.wvproj"
|
||||
},
|
||||
{
|
||||
"parentLogicPath": "App/application/Host/Inc",
|
||||
"type": "file",
|
||||
"name": "slaveFreerotsTask.h"
|
||||
},
|
||||
{
|
||||
"name": "slaveFreerotsTask.c",
|
||||
"parentLogicPath": "App/application/Host/Src",
|
||||
"type": "file"
|
||||
}
|
||||
],
|
||||
"projectName": "CH32V303-FreeRTOS",
|
||||
|
@ -166,7 +176,8 @@
|
|||
"${project}/App/tools",
|
||||
"${project}/App/tools/RingQueue",
|
||||
"${project}/App/functionalModule/Inc",
|
||||
"${project}/App/application/Inc"
|
||||
"${project}/App/application/Host/Inc",
|
||||
"${project}/App/application/Slave/Inc"
|
||||
],
|
||||
"include_system_paths": [],
|
||||
"include_files": []
|
||||
|
|
|
@ -11,9 +11,12 @@ MEMORY
|
|||
CH32V30x_D8 - CH32V303CB-CH32V303RB
|
||||
*/
|
||||
/**/
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
|
||||
/* FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
*/
|
||||
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
|
||||
/* CH32V30x_D8C - CH32V307VC-CH32V307WC-CH32V307RC-CH32V305CC
|
||||
CH32V30x_D8 - CH32V303VC-CH32V303RC
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
### 测试
|
||||
|
||||
串口中断发送通过测试
|
||||
|
||||
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()));
|
||||
> ```
|
||||
>
|
||||
> 其他中断同上,由硬件压栈变为软件压栈
|
||||
|
|
@ -101,9 +101,10 @@
|
|||
#define configTICK_RATE_HZ ( ( TickType_t ) 500 )
|
||||
// #define configMAX_PRIORITIES ( 15 )
|
||||
#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 configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 )
|
||||
// #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 12 * 1024 ) )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 24 * 1024 ) )
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 45 * 1024 ) )
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
|
@ -126,7 +127,8 @@
|
|||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
#define configTIMER_QUEUE_LENGTH 4
|
||||
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE )
|
||||
// #define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE )
|
||||
#define configTIMER_TASK_STACK_DEPTH 16
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "freerotsTask.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "hostFreerotsTask.h"
|
||||
#include "slaveFreerotsTask.h"
|
||||
|
||||
|
||||
|
||||
|
@ -40,8 +42,15 @@ int main(void)
|
|||
printf("SystemClk:%d\r\n", SystemCoreClock);
|
||||
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
|
||||
printf("FreeRTOS Kernel Version:%s\r\n", tskKERNEL_VERSION_NUMBER);
|
||||
|
||||
startApp();
|
||||
|
||||
FM_MCU_Init();
|
||||
|
||||
if (getMCU()) {
|
||||
slaveStartApp();
|
||||
}
|
||||
else {
|
||||
hostStartApp();
|
||||
}
|
||||
|
||||
while(1) {
|
||||
printf("shouldn't run at here!!\n");
|
||||
|
|
|
@ -17,4 +17,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
App/tools/RingQueue/%.o: ../App/tools/RingQueue/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
Binary file not shown.
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
|
@ -17,4 +17,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
Core/%.o: ../Core/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
|
@ -17,4 +17,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
Debug/%.o: ../Debug/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
|
@ -24,6 +24,6 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
FreeRTOS/portable/GCC/RISC-V/%.o: ../FreeRTOS/portable/GCC/RISC-V/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
FreeRTOS/portable/GCC/RISC-V/%.o: ../FreeRTOS/portable/GCC/RISC-V/%.S
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -x assembler-with-cpp -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Startup" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
Binary file not shown.
|
@ -17,4 +17,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
FreeRTOS/portable/MemMang/%.o: ../FreeRTOS/portable/MemMang/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
|
@ -35,4 +35,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
FreeRTOS/%.o: ../FreeRTOS/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -92,4 +92,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
Peripheral/src/%.o: ../Peripheral/src/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
|
@ -37,8 +37,11 @@ User/main.o: ../User/main.c \
|
|||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include/mpu_wrappers.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include/task.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include/list.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc/freerotsTask.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/pDebug.h
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc/FM_GPIO.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc/HD_GPIO.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc/hostFreerotsTask.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/pDebug.h \
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc/slaveFreerotsTask.h
|
||||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug/debug.h:
|
||||
|
||||
|
@ -116,6 +119,12 @@ d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include/task.h:
|
|||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include/list.h:
|
||||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc/freerotsTask.h:
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc/FM_GPIO.h:
|
||||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc/HD_GPIO.h:
|
||||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc/hostFreerotsTask.h:
|
||||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/pDebug.h:
|
||||
|
||||
d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc/slaveFreerotsTask.h:
|
||||
|
|
Binary file not shown.
|
@ -23,4 +23,4 @@ OBJS += \
|
|||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
User/%.o: ../User/%.c
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
@ riscv-none-embed-gcc -march=rv32imacxw -mabi=ilp32 -msmall-data-limit=8 -msave-restore -fmax-errors=20 -Os -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -g -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Debug" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Core" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/User" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/Peripheral/inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/include" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/Common" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/GCC/RISC-V/chip_specific_extensions/RV32I_PFIC_no_extensions" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/FreeRTOS/portable/MemMang" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/hardwareDriver/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/tools/RingQueue" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/functionalModule/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Host/Inc" -I"d:/psx/su806/2.software/mcu_git/CH32V303-FreeRTOS/App/application/Slave/Inc" -std=gnu99 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
|
||||
|
|
|
@ -17,9 +17,11 @@ RM := rm -rf
|
|||
-include Debug/subdir.mk
|
||||
-include Core/subdir.mk
|
||||
-include App/tools/RingQueue/subdir.mk
|
||||
-include App/tools/subdir.mk
|
||||
-include App/hardwareDriver/Src/subdir.mk
|
||||
-include App/functionalModule/Src/subdir.mk
|
||||
-include App/application/Src/subdir.mk
|
||||
-include App/application/Slave/Src/subdir.mk
|
||||
-include App/application/Host/Src/subdir.mk
|
||||
-include subdir.mk
|
||||
-include objects.mk
|
||||
|
||||
|
|
|
@ -23,9 +23,11 @@ SECONDARY_SIZE :=
|
|||
|
||||
# Every subdirectory with source files must be described here
|
||||
SUBDIRS := \
|
||||
App/application/Src \
|
||||
App/application/Host/Src \
|
||||
App/application/Slave/Src \
|
||||
App/functionalModule/Src \
|
||||
App/hardwareDriver/Src \
|
||||
App/tools \
|
||||
App/tools/RingQueue \
|
||||
Core \
|
||||
Debug \
|
||||
|
|
Loading…
Reference in New Issue