串口接收的时候出现爆栈
This commit is contained in:
parent
0bf09ca66a
commit
6559f0739a
|
@ -29,8 +29,6 @@
|
|||
/* PD11 */
|
||||
#define TD_USART_C 58
|
||||
|
||||
#define USART3_buffer_len 256
|
||||
|
||||
|
||||
void J5_0_485_Init(uint32_t baud);
|
||||
|
||||
|
|
|
@ -5,17 +5,15 @@
|
|||
* Author: 34509
|
||||
*/
|
||||
#include "J5-0_USART3.h"
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
|
||||
void USART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
|
||||
|
||||
uint8_t USART_Rbuffer_Num = 0;
|
||||
uint8_t USART_Tbuffer_Num = 0;
|
||||
/* 接收缓冲区数组 */
|
||||
uint8_t USART_Rbuffer[USART3_buffer_len];
|
||||
uint8_t USART3_Rbuffer[1] = {0x00};
|
||||
|
||||
/*
|
||||
* Function Name : J5_0_485_Init
|
||||
|
@ -86,8 +84,14 @@ void USART3_IRQHandler(void)
|
|||
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //中断产生
|
||||
{
|
||||
// USART_ClearITPendingBit(USART3,USART_IT_RXNE); //清除中断标志
|
||||
USART_Rbuffer[USART_Rbuffer_Num] = USART_ReceiveData(USART3); //接收数据
|
||||
USART_Rbuffer_Num++;
|
||||
// USART_Rbuffer[USART_Rbuffer_Num] = USART_ReceiveData(USART3); //接收数据
|
||||
// USART_Rbuffer_Num++;
|
||||
USART3_Rbuffer[0] = USART_ReceiveData(USART3); //接收数据
|
||||
uint8_t c = 0;
|
||||
uart_device_info *dev = (uart_device_info *)g_J50RS485_USART3_handle;
|
||||
c = USART3_Rbuffer[0];
|
||||
if(!RingQueueFull(&dev->uart_ring_queue))
|
||||
InRingQueue(&dev->uart_ring_queue, c);
|
||||
}
|
||||
|
||||
// if(USART_GetITStatus(USART3, USART_IT_IDLE) != RESET) //中断产生
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#define SOFTWARE_PROTOCOL_COMMUNICATION_PROTOCOL_H_
|
||||
|
||||
#include "inc/UART.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
|
||||
/* 功能码 */
|
||||
typedef enum
|
||||
|
@ -97,8 +99,8 @@ typedef struct _SL_Mppt_ROReply_pack{
|
|||
uint8_t start_Flag[2]; /* 起始标志 */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
uint8_t function_Code; /* 功能码 */
|
||||
uint8_t write_Register_Number_H; /* 回复字节数长度高八位 */
|
||||
uint8_t write_Register_Number_L; /* 回复字节数长度低八位 */
|
||||
uint8_t reply_Register_Number_H; /* 回复字节数长度高八位 */
|
||||
uint8_t reply_Register_Number_L; /* 回复字节数长度低八位 */
|
||||
uint8_t *content; /* 回复数据内容 */
|
||||
uint8_t check_Bit_H; /* 校验位高八位 */
|
||||
uint8_t check_Bit_L; /* 校验位低八位 */
|
||||
|
@ -159,11 +161,19 @@ typedef struct _SL_Mppt_Recv_pack{
|
|||
uint8_t recv_Data[RECV_LENGTH]; /* 其他部分 */
|
||||
}SL_Mppt_Recv_pack;
|
||||
|
||||
/* 功能码处理函数 */
|
||||
typedef void (*MsgProcFunc)(device_handle device, void*, uint32_t MsgLen);
|
||||
typedef struct _SL_FunctionMsgProcTable{
|
||||
u_int32_t msgId;
|
||||
MsgProcFunc pMsgProc;
|
||||
}SL_FuncionMsgProcTable;
|
||||
|
||||
/* 恢复默认的对齐设置 */
|
||||
#pragma pack(pop)
|
||||
|
||||
extern SL_Mppt_Scan_Broadcast_pack g_Scan_Broadcast_pack;
|
||||
|
||||
|
||||
void read_and_process_uart_data(device_handle device);
|
||||
void send_data(uint8_t *buff);
|
||||
|
||||
#endif /* SOFTWARE_PROTOCOL_COMMUNICATION_PROTOCOL_H_ */
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* mutex.h
|
||||
*
|
||||
* Created on: 2024年5月18日
|
||||
* Author: 34509
|
||||
*/
|
||||
|
||||
#ifndef SOFTWARE_THREAD_COMMUNICATION_MUTEX_H_
|
||||
#define SOFTWARE_THREAD_COMMUNICATION_MUTEX_H_
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
/* 定义互斥量控制块 */
|
||||
/* Rs485数组互斥量 */
|
||||
static rt_mutex_t protocol_mux = RT_NULL;
|
||||
|
||||
|
||||
void mutex_Init(void);
|
||||
|
||||
#endif /* SOFTWARE_THREAD_COMMUNICATION_MUTEX_H_ */
|
|
@ -11,7 +11,9 @@
|
|||
#include "communication_protocol.h"
|
||||
|
||||
|
||||
void UartRecv_thread_Init(void);
|
||||
void Recv_thread_Init(void);
|
||||
void Send_thread_Init(void);
|
||||
|
||||
|
||||
|
||||
#endif /* SOFTWARE_THREAD_RS485_H_ */
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* mutex.h
|
||||
*
|
||||
* Created on: 2024年5月18日
|
||||
* Author: 34509
|
||||
*/
|
||||
|
||||
#ifndef SOFTWARE_THREAD_COMMUNICATION_MUTEX_H_
|
||||
#define SOFTWARE_THREAD_COMMUNICATION_MUTEX_H_
|
||||
|
||||
#include "rtthread.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
/* UartSend队列的格式 */
|
||||
#define UART_MQ_SEND_LENGTH 20
|
||||
typedef struct _SL_UartSend_pack{
|
||||
device_handle device; /* 串口 */
|
||||
rt_uint8_t direction; /* 方向 */
|
||||
rt_uint8_t len; /* 长度 */
|
||||
rt_uint8_t recv_Data[UART_MQ_SEND_LENGTH]; /* 其他部分 */
|
||||
}SL_UartSend_pack;
|
||||
|
||||
typedef enum{
|
||||
up = 0, /* 往智能模块传传输数据 */
|
||||
down = 1, /* 向下往传感器传输数据 */
|
||||
}UartSend_pack_direction;
|
||||
|
||||
extern SL_UartSend_pack MqUartSend_pack;
|
||||
extern rt_mq_t mqSend;
|
||||
|
||||
|
||||
rt_uint8_t Send_mq_Init(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SOFTWARE_THREAD_COMMUNICATION_MUTEX_H_ */
|
|
@ -6,8 +6,9 @@
|
|||
*/
|
||||
|
||||
#include <communication_protocol.h>
|
||||
#include "uart_dev.h"
|
||||
#include "inflash.h"
|
||||
#include <string.h>
|
||||
#include "thread_communication.h"
|
||||
|
||||
SL_Mppt_Scan_Broadcast_pack g_Scan_Broadcast_pack = {
|
||||
.start_Flag = "SL",
|
||||
|
@ -22,6 +23,17 @@ SL_Mppt_Scan_Broadcast_pack g_Scan_Broadcast_pack = {
|
|||
static uint8_t uart_buff[50]={0x00};
|
||||
|
||||
|
||||
/* 静态函数申明 */
|
||||
static void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen);
|
||||
static void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen);
|
||||
|
||||
/* 功能码处理表 */
|
||||
SL_FuncionMsgProcTable g_MsgTbl[] =
|
||||
{
|
||||
{SL_Function_Code_Read_Register, SL_MsgProcFunc_Read_Register},
|
||||
{SL_Function_Code_Registration_request, SL_MsgProcFunc_Registration_request},
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 校验算法
|
||||
* @param
|
||||
|
@ -72,6 +84,44 @@ uint8_t Check_485_bus_busy(device_handle device)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen)
|
||||
{
|
||||
memset(&MqUartSend_pack, 0, sizeof(MqUartSend_pack));
|
||||
MqUartSend_pack.device = device;
|
||||
MqUartSend_pack.direction = up;
|
||||
MqUartSend_pack.len = MsgLen;
|
||||
|
||||
uint8_t *buf = (uint8_t *)pMsg;
|
||||
for (uint8_t var = 0; var < MsgLen; ++var) {
|
||||
MqUartSend_pack.recv_Data[var] = buf[var];
|
||||
}
|
||||
|
||||
/* 发 送 消 息 到 消 息 队 列 中 */
|
||||
if (rt_mq_send(mqSend, &MqUartSend_pack, MsgLen) != RT_EOK) {
|
||||
rt_kprintf("rt_mq_send ERR\n");
|
||||
}
|
||||
}
|
||||
|
||||
void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
|
||||
{
|
||||
memset(&MqUartSend_pack, 0, sizeof(MqUartSend_pack));
|
||||
MqUartSend_pack.device = device;
|
||||
MqUartSend_pack.direction = down;
|
||||
MqUartSend_pack.len = MsgLen;
|
||||
|
||||
uint8_t *buf = (uint8_t *)pMsg;
|
||||
|
||||
for (uint8_t var = 0; var < MsgLen; ++var) {
|
||||
MqUartSend_pack.recv_Data[var] = buf[var];
|
||||
}
|
||||
|
||||
/* 发 送 消 息 到 消 息 队 列 中 */
|
||||
if (rt_mq_send(mqSend, &MqUartSend_pack, MsgLen) != RT_EOK) {
|
||||
rt_kprintf("rt_mq_send ERR\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 匹配起始标志"SL"
|
||||
* @param start_buff 起始标志
|
||||
|
@ -87,6 +137,27 @@ static int Match_Startflag(uint8_t start_buff[2])
|
|||
return 0;
|
||||
}
|
||||
|
||||
///**
|
||||
// * @brief 匹配广播地址
|
||||
// * @param address 地址
|
||||
// * @retval 1 匹配成功
|
||||
// * 0 匹配失败
|
||||
// */
|
||||
//static int Match_Broadcastaddress(uint8_t address[7])
|
||||
//{
|
||||
// if (address[0] == 0xFF && \
|
||||
// address[1] == 0xFF && \
|
||||
// address[2] == 0xFF && \
|
||||
// address[3] == 0xFF && \
|
||||
// address[4] == 0xFF && \
|
||||
// address[5] == 0xFF && \
|
||||
// address[6] == 0xFF) {
|
||||
//
|
||||
// return 1;
|
||||
// }
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
/**
|
||||
* @brief 读取串口数据
|
||||
* @param uart_handle 串口句柄
|
||||
|
@ -96,8 +167,111 @@ static int Match_Startflag(uint8_t start_buff[2])
|
|||
*/
|
||||
static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
|
||||
{
|
||||
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)buff;
|
||||
|
||||
uint32_t offset = 0;
|
||||
uint32_t len = 0;
|
||||
uint8_t r_Flag = 0; /* 读的标志位 */
|
||||
uint8_t flag_run = 0;
|
||||
|
||||
char c = 0;
|
||||
|
||||
buff_size--; //预留一个'\0'位置
|
||||
|
||||
for (; offset < buff_size;){
|
||||
if (ring_queue_length(uart_handle) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
c = uart_dev_in_char(uart_handle);
|
||||
|
||||
buff[offset++] = c;
|
||||
|
||||
/* 匹配起始标志位 */
|
||||
if (offset == sizeof(pack->start_Flag) || (flag_run > 0)) {
|
||||
if (!Match_Startflag(pack->start_Flag)) {
|
||||
memcpy(buff, buff+1, offset-1);
|
||||
offset--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// /* 匹配地址 */
|
||||
// if (offset == (sizeof(pack->start_Flag) + sizeof(pack->address)) || (flag_run > 1)) {
|
||||
// /* 匹配广播地址,设备地址不做匹配 */
|
||||
// if (Match_Broadcastaddress(pack->address)) {
|
||||
// b_Flag = 1;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
/* 匹配功能码 */
|
||||
if ((offset == (sizeof(pack->start_Flag) + sizeof(pack->address) + sizeof(pack->function_Code))) || (flag_run > 2)) {
|
||||
/* 读寄存器数据 */
|
||||
if (pack->function_Code == SL_Function_Code_Read_Register) {
|
||||
r_Flag = 1;
|
||||
}
|
||||
|
||||
/* 注册请求 */
|
||||
else if ((pack->function_Code == SL_Function_Code_Registration_request)) {
|
||||
len = SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE;
|
||||
r_Flag = 0;
|
||||
}
|
||||
|
||||
else {
|
||||
if (flag_run < 2) {
|
||||
flag_run = 2;
|
||||
}
|
||||
r_Flag = 0;
|
||||
memcpy(buff, buff+1, offset-1);
|
||||
offset--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((1 == r_Flag) && (offset == 12)) {
|
||||
SL_Mppt_ROReply_pack *rpack = (SL_Mppt_ROReply_pack *)buff;
|
||||
uint8_t Register_Number = (rpack->reply_Register_Number_H << 8) | rpack->reply_Register_Number_L;
|
||||
len = Register_Number * 2 + SL_MPPT_ROReply_PACK_SIZE - 4;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (offset == len) {
|
||||
/* 读寄存器数据 */
|
||||
if (pack->function_Code == SL_Function_Code_Read_Register) {
|
||||
uint16_t crc_16 = buff[offset - 2] | (buff[offset - 3] << 8);
|
||||
|
||||
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
|
||||
if (flag_run < 3) {
|
||||
flag_run = 3;
|
||||
}
|
||||
memcpy(buff, buff+1, offset-1);
|
||||
offset--;
|
||||
} else {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
SL_Mppt_RegistrationRequest_pack *rpack = (SL_Mppt_RegistrationRequest_pack *)buff;
|
||||
|
||||
uint16_t crc_16 = rpack->check_Bit_L | (rpack->check_Bit_H << 8);
|
||||
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
|
||||
|
||||
if (flag_run < 3) {
|
||||
flag_run = 3;
|
||||
}
|
||||
memcpy(buff, buff+1, offset-1);
|
||||
offset--;
|
||||
|
||||
} else {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,6 +283,11 @@ void FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
|
|||
{
|
||||
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)pMsg;
|
||||
|
||||
for (u_int16_t i = 0; i < sizeof(g_MsgTbl) / sizeof(SL_FuncionMsgProcTable); i++) {
|
||||
if (pack->function_Code == g_MsgTbl[i].msgId) {
|
||||
g_MsgTbl[i].pMsgProc(device, pMsg, MsgLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,8 +297,9 @@ void FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
|
|||
*/
|
||||
void read_and_process_uart_data(device_handle device)
|
||||
{
|
||||
// printf("ring_queue_length = %d \n", ring_queue_length(device));
|
||||
if (ring_queue_length(device) > 10) {
|
||||
if (uart_dev_char_present(device)) {
|
||||
rt_thread_mdelay(30);
|
||||
rt_kprintf("ring_queue_length = %d \n", ring_queue_length(device));
|
||||
memset(uart_buff, 0, sizeof(uart_buff));
|
||||
int ret = uart_read_climate_pack(device, uart_buff, sizeof(uart_buff));
|
||||
if(ret > 0){
|
||||
|
@ -127,3 +307,34 @@ void read_and_process_uart_data(device_handle device)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 发送串口数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
static void send_uart_data(uint8_t *buff)
|
||||
{
|
||||
SL_UartSend_pack *upack = (SL_UartSend_pack *)buff;
|
||||
|
||||
uart_dev_write(upack->device, upack->recv_Data, upack->len);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 发送数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void send_data(uint8_t *buff)
|
||||
{
|
||||
SL_UartSend_pack *upack = (SL_UartSend_pack *)buff;
|
||||
|
||||
if (upack->direction == down) {
|
||||
send_uart_data(buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* mutex.c
|
||||
*
|
||||
* Created on: 2024年5月18日
|
||||
* Author: 34509
|
||||
*/
|
||||
|
||||
#include "mutex.h"
|
||||
|
||||
|
||||
|
||||
void mutex_Init(void)
|
||||
{
|
||||
/* 创建一个互斥量 */
|
||||
protocol_mux = rt_mutex_create("test_mux",RT_IPC_FLAG_PRIO);
|
||||
|
||||
if (protocol_mux != RT_NULL){
|
||||
rt_kprintf("互斥量创建成功!\n\n");
|
||||
}
|
||||
|
||||
}
|
|
@ -6,43 +6,90 @@
|
|||
*/
|
||||
#include <thread.h>
|
||||
#include "uart_dev.h"
|
||||
#include "thread_communication.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* 定义线程控制块指针 */
|
||||
static rt_thread_t UartRecv_thread = RT_NULL;
|
||||
/* 接收线程控制块指针 */
|
||||
static rt_thread_t Recv_thread = RT_NULL;
|
||||
/* 发送线程控制块指针 */
|
||||
static rt_thread_t Send_thread = RT_NULL;
|
||||
|
||||
/* 函数声明 */
|
||||
static void UartRecv_thread_entry(void* parameter);
|
||||
/* 接收线程函数 */
|
||||
static void Recv_thread_entry(void* parameter);
|
||||
/* 发送线程函数 */
|
||||
static void Send_thread_entry(void* parameter);
|
||||
|
||||
|
||||
|
||||
void UartRecv_thread_Init(void)
|
||||
/**
|
||||
* @brief 创建接收线程
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Recv_thread_Init(void)
|
||||
{
|
||||
UartRecv_thread = /* 线程控制块指针 */
|
||||
rt_thread_create( "UartRecv", /* 线程名字 */
|
||||
UartRecv_thread_entry, /* 线程入口函数 */
|
||||
RT_NULL, /* 线程入口函数参数 */
|
||||
512, /* 线程栈大小 */
|
||||
3, /* 线程的优先级 */
|
||||
20); /* 线程时间片 */
|
||||
Recv_thread = /* 线程控制块指针 */
|
||||
rt_thread_create( "Recv", /* 线程名字 */
|
||||
Recv_thread_entry, /* 线程入口函数 */
|
||||
RT_NULL, /* 线程入口函数参数 */
|
||||
256, /* 线程栈大小 */
|
||||
2, /* 线程的优先级 */
|
||||
20); /* 线程时间片 */
|
||||
|
||||
/* 启动线程,开启调度 */
|
||||
if (UartRecv_thread != RT_NULL)
|
||||
rt_thread_startup(UartRecv_thread);
|
||||
if (Recv_thread != RT_NULL) {
|
||||
rt_kprintf("recv");
|
||||
rt_thread_startup(Recv_thread);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 创建发送线程
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Send_thread_Init(void)
|
||||
{
|
||||
Send_thread = /* 线程控制块指针 */
|
||||
rt_thread_create( "send", /* 线程名字 */
|
||||
Send_thread_entry, /* 线程入口函数 */
|
||||
RT_NULL, /* 线程入口函数参数 */
|
||||
256, /* 线程栈大小 */
|
||||
3, /* 线程的优先级 */
|
||||
20); /* 线程时间片 */
|
||||
|
||||
/* 启动线程,开启调度 */
|
||||
if (Send_thread != RT_NULL) {
|
||||
rt_kprintf("send");
|
||||
rt_thread_startup(Send_thread);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void UartRecv_thread_entry(void* parameter)
|
||||
void Recv_thread_entry(void* parameter)
|
||||
{
|
||||
while (1) {
|
||||
if (ring_queue_length(g_J50RS485_USART3_handle) > 1) {
|
||||
rt_thread_mdelay(30);
|
||||
|
||||
}
|
||||
rt_thread_mdelay(100);
|
||||
rt_kprintf("\n 2 \n");
|
||||
read_and_process_uart_data(g_J50RS485_USART3_handle);
|
||||
rt_thread_mdelay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void Send_thread_entry(void* parameter)
|
||||
{
|
||||
uint8_t buff[50];
|
||||
while (1) {
|
||||
rt_kprintf("\n 1 \n");
|
||||
// rt_thread_mdelay(500);
|
||||
memset(buff, 0, sizeof(buff));
|
||||
rt_mq_recv(mqSend, buff, sizeof(buff), RT_WAITING_FOREVER);
|
||||
send_data(buff);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* mutex.c
|
||||
*
|
||||
* Created on: 2024年5月18日
|
||||
* Author: 34509
|
||||
*/
|
||||
|
||||
#include <thread_communication.h>
|
||||
|
||||
|
||||
|
||||
SL_UartSend_pack MqUartSend_pack;
|
||||
|
||||
|
||||
/* 定义消息队列控制块 */
|
||||
rt_mq_t mqSend = RT_NULL;
|
||||
|
||||
|
||||
/**
|
||||
* @brief 串口接收到数据后如果需要发送数据则通过这个队列传输信息给只能模块(本次测试将数据直接通过串口传输)
|
||||
* @param
|
||||
* @retval 1 创建成功
|
||||
* 0 创建失败
|
||||
*/
|
||||
rt_uint8_t Send_mq_Init(void)
|
||||
{
|
||||
mqSend = rt_mq_create("UartSend_mq",/* 消息队列名字 */
|
||||
50, /* 消息的最大长度 */
|
||||
5, /* 消息队列的最大容量 */
|
||||
RT_IPC_FLAG_FIFO);/* 队列模式 FIFO(0x00)*/
|
||||
if (mqSend != RT_NULL)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -28,18 +28,18 @@ device_handle g_J50RS485_USART3_handle;
|
|||
device_handle g_LORA_UART5_handle;
|
||||
|
||||
#define IN_BUFF_SIZE 128
|
||||
//static uint8_t J1RS485_in_buff[IN_BUFF_SIZE];
|
||||
//static uint8_t J2RS485_in_buff[IN_BUFF_SIZE];
|
||||
//static uint8_t J3RS485_in_buff[IN_BUFF_SIZE];
|
||||
//static uint8_t J4RS485_in_buff[IN_BUFF_SIZE];
|
||||
//static uint8_t J50RS485_in_buff[IN_BUFF_SIZE];
|
||||
//static uint8_t LORA_in_buff[IN_BUFF_SIZE];
|
||||
uint8_t J1RS485_in_buff[IN_BUFF_SIZE];
|
||||
uint8_t J2RS485_in_buff[IN_BUFF_SIZE];
|
||||
uint8_t J3RS485_in_buff[IN_BUFF_SIZE];
|
||||
uint8_t J4RS485_in_buff[IN_BUFF_SIZE];
|
||||
uint8_t J50RS485_in_buff[IN_BUFF_SIZE];
|
||||
uint8_t LORA_in_buff[IN_BUFF_SIZE];
|
||||
static uint8_t J1RS485_in_buff[IN_BUFF_SIZE];
|
||||
static uint8_t J2RS485_in_buff[IN_BUFF_SIZE];
|
||||
static uint8_t J3RS485_in_buff[IN_BUFF_SIZE];
|
||||
static uint8_t J4RS485_in_buff[IN_BUFF_SIZE];
|
||||
static uint8_t J50RS485_in_buff[IN_BUFF_SIZE];
|
||||
static uint8_t LORA_in_buff[IN_BUFF_SIZE];
|
||||
//uint8_t J1RS485_in_buff[IN_BUFF_SIZE];
|
||||
//uint8_t J2RS485_in_buff[IN_BUFF_SIZE];
|
||||
//uint8_t J3RS485_in_buff[IN_BUFF_SIZE];
|
||||
//uint8_t J4RS485_in_buff[IN_BUFF_SIZE];
|
||||
//uint8_t J50RS485_in_buff[IN_BUFF_SIZE];
|
||||
//uint8_t LORA_in_buff[IN_BUFF_SIZE];
|
||||
|
||||
//uint8_t rs485_out_buff[100];
|
||||
|
||||
|
|
10
User/start.c
10
User/start.c
|
@ -8,6 +8,8 @@
|
|||
#include <inc/communication_protocol.h>
|
||||
#include <inc/thread.h>
|
||||
#include "inc/uart_dev.h"
|
||||
#include "inc/thread_communication.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@ -21,11 +23,8 @@ void hareware_init()
|
|||
android_PowerCtrl_Open();
|
||||
|
||||
// SPI_Flash_TEST();
|
||||
|
||||
// USARTx_SendStr(J5_0_USART, "This is a test data.\n");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -36,8 +35,9 @@ void hareware_init()
|
|||
void software_init()
|
||||
{
|
||||
uart_dev_init();
|
||||
|
||||
UartRecv_thread_Init();
|
||||
Send_mq_Init();
|
||||
Recv_thread_Init();
|
||||
Send_thread_Init();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
15437
obj/CH32V303_V0.1.lst
15437
obj/CH32V303_V0.1.lst
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -48,7 +48,9 @@ Hardware/src/J5-0_USART3.o: ../Hardware/src/J5-0_USART3.c \
|
|||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/ipc/pipe.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/ipc/poll.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/serial.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/pin.h
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/pin.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Hardware\inc/J5-0_USART3.h:
|
||||
|
||||
|
@ -149,3 +151,7 @@ D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/ipc/poll.h:
|
|||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/serial.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/pin.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h:
|
||||
|
|
Binary file not shown.
|
@ -52,7 +52,8 @@ Software/src/communication_protocol.o: \
|
|||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/pin.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/inflash.h
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/inflash.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread_communication.h
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/communication_protocol.h:
|
||||
|
||||
|
@ -159,3 +160,5 @@ D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h:
|
|||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/inflash.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread_communication.h:
|
||||
|
|
Binary file not shown.
|
@ -7,22 +7,22 @@
|
|||
C_SRCS += \
|
||||
../Software/src/communication_protocol.c \
|
||||
../Software/src/inflash.c \
|
||||
../Software/src/mutex.c \
|
||||
../Software/src/thread.c \
|
||||
../Software/src/thread_communication.c \
|
||||
../Software/src/uart_dev.c
|
||||
|
||||
OBJS += \
|
||||
./Software/src/communication_protocol.o \
|
||||
./Software/src/inflash.o \
|
||||
./Software/src/mutex.o \
|
||||
./Software/src/thread.o \
|
||||
./Software/src/thread_communication.o \
|
||||
./Software/src/uart_dev.o
|
||||
|
||||
C_DEPS += \
|
||||
./Software/src/communication_protocol.d \
|
||||
./Software/src/inflash.d \
|
||||
./Software/src/mutex.d \
|
||||
./Software/src/thread.d \
|
||||
./Software/src/thread_communication.d \
|
||||
./Software/src/uart_dev.d
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,9 @@ Software/src/thread.o: ../Software/src/thread.c \
|
|||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/serial.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/pin.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread_communication.h
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread.h:
|
||||
|
||||
|
@ -158,3 +160,7 @@ D:\psx\su806\git\CH32V303_V0.1\rtthread\components\drivers\include/drivers/pin.h
|
|||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread_communication.h:
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,122 @@
|
|||
Software/src/thread_communication.o: \
|
||||
../Software/src/thread_communication.c \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread_communication.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtthread.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread/rtconfig.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtdebug.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtdef.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtservice.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtm.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\finsh/finsh_api.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Core/core_riscv.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/system_ch32v30x.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/ch32v30x_conf.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_adc.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_bkp.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_can.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_crc.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_dac.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_dbgmcu.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_dma.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_exti.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_flash.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_fsmc.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_gpio.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_i2c.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_iwdg.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_pwr.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_rcc.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_rtc.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_sdio.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_spi.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_tim.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_usart.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_wwdg.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/ch32v30x_it.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Debug/debug.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_misc.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rthw.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/thread_communication.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtthread.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread/rtconfig.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtdebug.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtdef.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtservice.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rtm.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\components\finsh/finsh_api.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software\inc/uart_dev.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Core/core_riscv.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/system_ch32v30x.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/ch32v30x_conf.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_adc.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_bkp.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_can.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_crc.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_dac.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_dbgmcu.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_dma.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_exti.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_flash.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_fsmc.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_gpio.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_i2c.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_iwdg.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_pwr.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_rcc.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_rtc.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_sdio.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_spi.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_tim.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_usart.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_wwdg.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/ch32v30x_it.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Debug/debug.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Peripheral\inc/ch32v30x_misc.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\rtthread\include/rthw.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h:
|
Binary file not shown.
Binary file not shown.
|
@ -51,10 +51,12 @@ User/start.d: ../User/start.c D:\psx\su806\git\CH32V303_V0.1\User/start.h \
|
|||
D:\psx\su806\git\CH32V303_V0.1\Hardware/inc/Flash.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Hardware/inc/UART.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/communication_protocol.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/thread.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/communication_protocol.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/uart_dev.h \
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/thread_communication.h
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\User/start.h:
|
||||
|
||||
|
@ -162,10 +164,14 @@ D:\psx\su806\git\CH32V303_V0.1\Hardware/inc/UART.h:
|
|||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/communication_protocol.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/uart_dev.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/thread.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/communication_protocol.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/uart_dev.h:
|
||||
|
||||
D:\psx\su806\git\CH32V303_V0.1\drivers/RingQueue/ring_queue.h:
|
||||
D:\psx\su806\git\CH32V303_V0.1\Software/inc/thread_communication.h:
|
||||
|
|
BIN
obj/User/start.o
BIN
obj/User/start.o
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue