|
|
|
@@ -0,0 +1,78 @@ |
|
|
|
#include "stm32f4xx.h" |
|
|
|
#include "hardware.h" |
|
|
|
#include "ucos_ii.h" |
|
|
|
#include "os.h" |
|
|
|
#include "app_cfg.h" |
|
|
|
#include "sys_cfg.h" |
|
|
|
|
|
|
|
extern OS_EVENT* ModbusReceived; /*接收到modbus请求报文*/ |
|
|
|
extern OS_EVENT* ModbusAssembled; /*modbus响应帧组装完成*/ |
|
|
|
|
|
|
|
/*USART接收空闲中断*/ |
|
|
|
void USART1_IRQHandler(void) |
|
|
|
{ |
|
|
|
OSIntEnter(); /*进入中断*/ |
|
|
|
|
|
|
|
uint32_t temp; |
|
|
|
uint16_t rxLenRemain; |
|
|
|
|
|
|
|
if(USART_GetITStatus(USART1, USART_IT_IDLE) == SET) |
|
|
|
{ |
|
|
|
/*在计算数据长度之前先关闭DMA接收通道,防止计算过程中DMA继续转运数据*/ |
|
|
|
DMA_Cmd(DMA2_Stream2, DISABLE); |
|
|
|
|
|
|
|
/*计算数据长度*/ |
|
|
|
rxLenRemain = DMA_GetCurrDataCounter(DMA2_Stream2); |
|
|
|
ModbusRxLen = MODBUS_RX_BUF_SIZE - rxLenRemain; |
|
|
|
|
|
|
|
if(ModbusRxLen != 0) |
|
|
|
{ |
|
|
|
OSSemPost(ModbusReceived); |
|
|
|
} |
|
|
|
|
|
|
|
/*重启DMA*/ |
|
|
|
DMA_SetCurrDataCounter(DMA2_Stream2, MODBUS_RX_BUF_SIZE); |
|
|
|
DMA_Cmd(DMA2_Stream2, ENABLE); |
|
|
|
|
|
|
|
/*清除IDLE中断标志位*/ |
|
|
|
temp = USART1->SR; |
|
|
|
temp = USART1->DR; |
|
|
|
} |
|
|
|
|
|
|
|
OSIntExit(); /*退出中断*/ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*modbus响应帧发送*/ |
|
|
|
void ModbusSend(uint8_t *txBuf, uint16_t len) |
|
|
|
{ |
|
|
|
/*先关闭DMA发送通道*/ |
|
|
|
DMA_Cmd(DMA2_Stream7, DISABLE); |
|
|
|
|
|
|
|
/*等待DMA关闭*/ |
|
|
|
while (DMA_GetCmdStatus(DMA2_Stream7) != DISABLE); |
|
|
|
|
|
|
|
/*配置发送地址和长度*/ |
|
|
|
DMA_MemoryTargetConfig(DMA2_Stream7, (uint32_t)txBuf, DMA_Memory_0); |
|
|
|
DMA_SetCurrDataCounter(DMA2_Stream7, len); |
|
|
|
|
|
|
|
/*启动 DMA 发送*/ |
|
|
|
DMA_Cmd(DMA2_Stream7, ENABLE); |
|
|
|
} |
|
|
|
|
|
|
|
/*modbus响应帧发送任务*/ |
|
|
|
void AppTaskModbusSend (void *p_arg) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*modbus协议帧解析任务*/ |
|
|
|
void AppTaskModbusParse (void *p_arg) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|