修复一个ipc传输的bug
This commit is contained in:
@@ -371,6 +371,11 @@ static msg_tag_t ipc_wait(ipc_t *ipc, thread_t *th, entry_frame_t *f, msg_tag_t
|
||||
tag = th->msg.tag;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
preemption();
|
||||
tag = th->msg.tag;
|
||||
}
|
||||
spinlock_set(&ipc->lock, status);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
#define MD_RTU_USED_OS 0 ///< Whether modbus RTU USES an operating system
|
||||
|
||||
#define MD_STRICT_MODE 0 ///< Strict mode
|
||||
#define MD_FRAME_INTERVAL_TIME 5 ///< Ms
|
||||
|
||||
#define MD_RTU_CRC16_FAST_MODE 1 ///< CRC check mode configuration
|
||||
|
||||
///< Configuration related to the slave
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ typedef union mk_sd
|
||||
};
|
||||
} mk_sd_t;
|
||||
#define mk_sd_init_raw(val) ((mk_sd_t){.raw = val})
|
||||
#define mk_sd_init3(h, f) ((mk_sd_t){.hd = h, .fd = f})
|
||||
#define mk_sd_init2(h, f) ((mk_sd_t){.hd = h, .fd = f})
|
||||
#define mk_sd_get_hd(sd) ((obj_handler_t)((sd).hd))
|
||||
#define mk_sd_get_fd(sd) ((int)((sd).fd))
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ sd_t fs_open(const char *path, int flags, int mode)
|
||||
}
|
||||
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t rpc_path = {
|
||||
.data = path,
|
||||
.len = strlen(path) + 1,
|
||||
.data = &path[ret],
|
||||
.len = strlen(&path[ret]) + 1,
|
||||
};
|
||||
rpc_int_t rpc_flags = {
|
||||
.data = flags,
|
||||
@@ -58,7 +58,7 @@ sd_t fs_open(const char *path, int flags, int mode)
|
||||
return msg_tag_get_val(tag);
|
||||
}
|
||||
|
||||
return msg_tag_get_val(tag);
|
||||
return mk_sd_init2(hd, msg_tag_get_val(tag)).raw;
|
||||
}
|
||||
int fs_read(sd_t _fd, void *buf, size_t len)
|
||||
{
|
||||
|
||||
@@ -38,12 +38,12 @@ static obj_handler_t find_hd(const char *path, int *split_pos)
|
||||
{
|
||||
if (ns_cli_cache.cache[i].path[0] != 0)
|
||||
{
|
||||
char *new_str = strstr(ns_cli_cache.cache[i].path, path);
|
||||
if (new_str && (new_str == ns_cli_cache.cache[i].path))
|
||||
char *new_str = strstr(path, ns_cli_cache.cache[i].path);
|
||||
if (new_str && (new_str == path))
|
||||
{
|
||||
if (split_pos)
|
||||
{
|
||||
*split_pos = (int)(new_str - ns_cli_cache.cache[i].path);
|
||||
*split_pos = (int)(strlen(ns_cli_cache.cache[i].path));
|
||||
}
|
||||
return ns_cli_cache.cache[i].hd;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ static obj_handler_t find_hd(const char *path, int *split_pos)
|
||||
}
|
||||
return HANDLER_INVALID;
|
||||
}
|
||||
static bool_t reg_hd(const char *path, obj_handler_t hd)
|
||||
static bool_t reg_hd(const char *path, obj_handler_t hd, int split_inx)
|
||||
{
|
||||
int i = 0;
|
||||
int empty = -1;
|
||||
@@ -59,7 +59,8 @@ static bool_t reg_hd(const char *path, obj_handler_t hd)
|
||||
{
|
||||
if (ns_cli_cache.cache[i].path[0] == 0)
|
||||
{
|
||||
strcpy(ns_cli_cache.cache[i].path, path);
|
||||
strncpy(ns_cli_cache.cache[i].path, path, split_inx);
|
||||
ns_cli_cache.cache[i].path[split_inx] = 0;
|
||||
ns_cli_cache.cache[i].hd = hd;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -103,7 +104,7 @@ int ns_query(const char *path, obj_handler_t *svr_hd)
|
||||
if (newfd != HANDLER_INVALID)
|
||||
{
|
||||
*svr_hd = newfd;
|
||||
return 0;
|
||||
return inx;
|
||||
}
|
||||
|
||||
newfd = handler_alloc();
|
||||
@@ -114,8 +115,8 @@ int ns_query(const char *path, obj_handler_t *svr_hd)
|
||||
}
|
||||
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t rpc_path = {
|
||||
.data = &path[inx],
|
||||
.len = strlen(&path[inx]) + 1,
|
||||
.data = path,
|
||||
.len = strlen(path) + 1,
|
||||
};
|
||||
rpc_obj_handler_t_t rpc_svr_hd = {
|
||||
.data = newfd,
|
||||
@@ -129,7 +130,7 @@ int ns_query(const char *path, obj_handler_t *svr_hd)
|
||||
handler_free(newfd);
|
||||
return msg_tag_get_val(tag);
|
||||
}
|
||||
if (reg_hd(path, newfd) == FALSE)
|
||||
if (reg_hd(path, newfd, msg_tag_get_val(tag)) == FALSE)
|
||||
{
|
||||
printf("The client service cache is full.\n");
|
||||
handler_free_umap(newfd);
|
||||
|
||||
@@ -46,124 +46,9 @@ RPC_GENERATION_OP2(ns_t, NS_QUERY_OP, query,
|
||||
return ret;
|
||||
}
|
||||
|
||||
// RPC_GENERATION_DISPATCH2(ns_t, NS_QUERY_OP, query,
|
||||
// rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
// rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd)
|
||||
msg_tag_t ns_t_query_dispatch(ns_t *obj, msg_tag_t tag, ipc_msg_t *ipc_msg)
|
||||
{
|
||||
rpc_array_uint32_t_uint8_t_32_t var0;
|
||||
rpc_obj_handler_t_t var1;
|
||||
size_t op_val;
|
||||
uint8_t *value = (uint8_t *)(ipc_msg->msg_buf);
|
||||
int off = 0;
|
||||
rpc_var_rpc_array_uint32_t_uint8_t_32_t_init(&var0);
|
||||
rpc_var_rpc_obj_handler_t_t_init(&var1);
|
||||
op_val = *((typeof(((uint16_t)1)) *)value);
|
||||
if (op_val != ((uint16_t)1))
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (-100)});
|
||||
}
|
||||
off += sizeof(typeof(((uint16_t)1)));
|
||||
off = rpc_align(off, __alignof(typeof(((uint16_t)1))));
|
||||
do
|
||||
{
|
||||
if (1 == 1)
|
||||
{
|
||||
if (1 == 1 || 1 == 4)
|
||||
{
|
||||
int ret = rpc_svr_buf_to_msg_rpc_array_uint32_t_uint8_t_32_t(&var0, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (2 == 1)
|
||||
{
|
||||
if (4 == 1 || 4 == 4)
|
||||
{
|
||||
int ret = rpc_svr_buf_to_msg_rpc_obj_handler_t_t(&var1, (uint8_t *)(value), off, tag.msg_buf_len * (sizeof(void *)));
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
short ret_val = ns_t_query_op(obj, &var0, &var1);
|
||||
if (ret_val < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret_val)});
|
||||
}
|
||||
off = 0;
|
||||
int off_map = 0;
|
||||
do
|
||||
{
|
||||
if (1 == 1)
|
||||
{
|
||||
if (1 == 2 || 1 == 4)
|
||||
{
|
||||
int ret = rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(&var0, (uint8_t *)(value), off);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (2 == 1)
|
||||
{
|
||||
if (4 == 2 || 4 == 4)
|
||||
{
|
||||
int ret = rpc_svr_msg_to_buf_rpc_obj_handler_t_t(&var1, (uint8_t *)(value), off);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (1 == 2)
|
||||
{
|
||||
if (1 == 2 || 1 == 4)
|
||||
{
|
||||
int ret = rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(&var0, (uint8_t *)(ipc_msg->map_buf), off_map);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off_map = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
do
|
||||
{
|
||||
if (2 == 2)
|
||||
{
|
||||
if (4 == 2 || 4 == 4)
|
||||
{
|
||||
int ret = rpc_svr_msg_to_buf_rpc_obj_handler_t_t(&var1, (uint8_t *)(ipc_msg->map_buf), off_map);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = (0), .map_buf_len = (0), .prot = (ret)});
|
||||
}
|
||||
off_map = ret;
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
return ((msg_tag_t){.flags = (0), .msg_buf_len = ((((off) / ((sizeof(void *)))) + (((off) % ((sizeof(void *)))) ? 1 : 0))), .map_buf_len = ((((off_map) / ((sizeof(void *)))) + (((off_map) % ((sizeof(void *)))) ? 1 : 0))), .prot = (ret_val)});
|
||||
}
|
||||
RPC_GENERATION_DISPATCH2(ns_t, NS_QUERY_OP, query,
|
||||
rpc_ref_array_uint32_t_uint8_t_32_t, rpc_array_uint32_t_uint8_t_32_t, RPC_DIR_IN, RPC_TYPE_DATA, path,
|
||||
rpc_obj_handler_t_t, rpc_obj_handler_t_t, RPC_DIR_INOUT, RPC_TYPE_BUF, cli_hd)
|
||||
RPC_DISPATCH2(ns_t, typeof(NS_REGISTER_OP), NS_REGISTER_OP, register, NS_QUERY_OP, query)
|
||||
|
||||
void ns_init(ns_t *ns)
|
||||
|
||||
@@ -286,97 +286,8 @@ RPC_TYPE_DEF_ALL(int) //!< 定义所有的
|
||||
* @brief 定义一个32字节长度的数组
|
||||
*
|
||||
*/
|
||||
// RPC_ARRAY_DEF(uint32_t, uint8_t, 32)
|
||||
typedef struct rpc_array_uint32_t_uint8_t_32
|
||||
{
|
||||
uint32_t len;
|
||||
uint8_t data[32];
|
||||
} rpc_array_uint32_t_uint8_t_32_t;
|
||||
static inline int rpc_svr_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(rpc_array_uint32_t_uint8_t_32_t *d, uint8_t *buf, int len)
|
||||
{
|
||||
if (rpc_align(len, __alignof(d->len)) > 96)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len = rpc_align(len, __alignof(d->len));
|
||||
*((typeof(d->len) *)(&buf[len])) = d->len;
|
||||
if (rpc_align(len, __alignof(d->data[0]) + d->len * sizeof(d->data[0])) > 96)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len += sizeof(d->len);
|
||||
len = rpc_align(len, __alignof(d->data[0]));
|
||||
for (int i = 0; i < d->len * sizeof(d->data[0]); i++)
|
||||
{
|
||||
buf[i + len] = ((uint8_t *)(d->data))[i];
|
||||
}
|
||||
len += d->len * sizeof(d->data[0]);
|
||||
return len;
|
||||
}
|
||||
static inline int rpc_svr_buf_to_msg_rpc_array_uint32_t_uint8_t_32_t(rpc_array_uint32_t_uint8_t_32_t *d, uint8_t *buf, int len, int max)
|
||||
{
|
||||
if (rpc_align(len, __alignof(d->len)) > max)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len = rpc_align(len, __alignof(d->len));
|
||||
d->len = *((typeof(d->len) *)(&buf[len]));
|
||||
if (rpc_align(len, __alignof(d->data[0]) + d->len * sizeof(d->data[0])) > max)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len += sizeof(d->len);
|
||||
len = rpc_align(len, __alignof(d->data[0]));
|
||||
for (int i = 0; i < d->len * sizeof(d->data[0]); i++)
|
||||
{
|
||||
((uint8_t *)(d->data))[i] = buf[i + len];
|
||||
}
|
||||
len += d->len * sizeof(d->data[0]);
|
||||
return len;
|
||||
}
|
||||
static inline int rpc_cli_msg_to_buf_rpc_array_uint32_t_uint8_t_32_t(rpc_array_uint32_t_uint8_t_32_t *d, uint8_t *buf, int len)
|
||||
{
|
||||
if (rpc_align(len, __alignof(d->len)) > 96)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len = rpc_align(len, __alignof(d->len));
|
||||
*((typeof(d->len) *)(&buf[len])) = d->len;
|
||||
if (rpc_align(len, __alignof(d->data[0]) + d->len * sizeof(d->data[0])) > 96)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len += sizeof(d->len);
|
||||
len = rpc_align(len, __alignof(d->data[0]));
|
||||
for (int i = 0; i < d->len * sizeof(d->data[0]); i++)
|
||||
{
|
||||
buf[i + len] = ((uint8_t *)(d->data))[i];
|
||||
}
|
||||
len += d->len * sizeof(d->data[0]);
|
||||
return len;
|
||||
}
|
||||
static inline int rpc_cli_buf_to_msg_rpc_array_uint32_t_uint8_t_32_t(rpc_array_uint32_t_uint8_t_32_t *d, uint8_t *buf, int len, int max)
|
||||
{
|
||||
if (rpc_align(len, __alignof(d->len)) > max)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len = rpc_align(len, __alignof(d->len));
|
||||
d->len = *((typeof(d->len) *)(&buf[len]));
|
||||
if (rpc_align(len, __alignof(d->data[0]) + d->len * sizeof(d->data[0])) > max)
|
||||
{
|
||||
return -1024;
|
||||
}
|
||||
len += sizeof(d->len);
|
||||
len = rpc_align(len, __alignof(d->data[0]));
|
||||
for (int i = 0; i < d->len * sizeof(d->data[0]); i++)
|
||||
{
|
||||
((uint8_t *)(d->data))[i] = buf[i + len];
|
||||
}
|
||||
len += d->len * sizeof(d->data[0]);
|
||||
return len;
|
||||
}
|
||||
static inline void rpc_var_rpc_array_uint32_t_uint8_t_32_t_init(rpc_array_uint32_t_uint8_t_32_t *d) {}
|
||||
RPC_ARRAY_DEF(uint32_t, uint8_t, 32)
|
||||
|
||||
/**
|
||||
* @brief 引用类型的数组定义,数组的数据来自其它地方
|
||||
*
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "MDM_RTU_APP.h"
|
||||
#include "e180-zg120.h"
|
||||
#include "timer.h"
|
||||
#include "sysinfo.h"
|
||||
#include <assert.h>
|
||||
|
||||
void music2_send_bytes(u8 *bytes, int len)
|
||||
@@ -45,6 +46,7 @@ void drv_init(void)
|
||||
init_uart4(115200);
|
||||
ext_input_check();
|
||||
wk2xx_hw_init();
|
||||
rs485_init();
|
||||
Wk_DeInit(1);
|
||||
Wk_DeInit(2);
|
||||
Wk_DeInit(3);
|
||||
@@ -53,7 +55,6 @@ void drv_init(void)
|
||||
Wk_Init(2);
|
||||
Wk_Init(3);
|
||||
Wk_Init(4);
|
||||
rs485_init();
|
||||
Wk_SetBaud(1, B115200);
|
||||
Wk_SetBaud(2, B115200);
|
||||
Wk_SetBaud(3, B115200);
|
||||
@@ -62,8 +63,12 @@ void drv_init(void)
|
||||
spl0601_init();
|
||||
LCD_init();
|
||||
|
||||
if (sys_info_read() < 0)
|
||||
{
|
||||
sys_info_save();
|
||||
bluetooth_set_CP(0, "02");
|
||||
bluetooth_set_CP(1, "02");
|
||||
}
|
||||
|
||||
bluetooth_init_cfg(0, usart2_send_bytes);
|
||||
bluetooth_init_cfg(1, music2_send_bytes);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "u_queue.h"
|
||||
#include "u_log.h"
|
||||
#include "u_env.h"
|
||||
#include "u_sleep.h"
|
||||
#include "e180-zg120.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -530,6 +531,7 @@ static void wait_pack(int wait_timeout)
|
||||
last_tick = sys_read_tick();
|
||||
last_len = q_queue_len(q);
|
||||
}
|
||||
// u_sleep_ms(1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ void SPI2_Init(void)
|
||||
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // 串行同步时钟的空闲状态为高电平
|
||||
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; // 串行同步时钟的第二个跳变沿(上升或下降)数据被采样
|
||||
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; // 定义波特率预分频的值:波特率预分频值为256
|
||||
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; // 定义波特率预分频的值:波特率预分频值为256
|
||||
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // 指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
|
||||
SPI_InitStructure.SPI_CRCPolynomial = 7; // CRC值计算的多项式
|
||||
SPI_Init(SPI2, &SPI_InitStructure); // 根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
|
||||
|
||||
@@ -21,7 +21,7 @@ void sys_info_unlock(void)
|
||||
|
||||
int sys_info_save(void)
|
||||
{
|
||||
int fd = fs_open("/sys_info.bin", O_CREAT | O_WRONLY, 0777);
|
||||
int fd = fs_open("/mnt/sys_info.bin", O_CREAT | O_WRONLY, 0777);
|
||||
if (fd < 0)
|
||||
{
|
||||
return fd;
|
||||
@@ -40,7 +40,7 @@ int sys_info_save(void)
|
||||
}
|
||||
int sys_info_read(void)
|
||||
{
|
||||
int fd = fs_open("/sys_info.bin", O_CREAT | O_RDONLY, 0777);
|
||||
int fd = fs_open("/mnt/sys_info.bin", O_CREAT | O_RDONLY, 0777);
|
||||
if (fd < 0)
|
||||
{
|
||||
return fd;
|
||||
|
||||
@@ -20,6 +20,7 @@ typedef struct
|
||||
|
||||
uint8_t netID;
|
||||
uint8_t devID;
|
||||
int init_val;
|
||||
} uapp_sys_info_t;
|
||||
|
||||
extern uapp_sys_info_t sys_info;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "u_hd_man.h"
|
||||
#include "u_local_thread.h"
|
||||
#include "u_sleep.h"
|
||||
#include "MDM_RTU_Serial.h"
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
static obj_handler_t irq_obj;
|
||||
@@ -23,19 +24,19 @@ void init_uart5(u32 baudRate)
|
||||
USART_InitTypeDef USART_InitStructure = {0};
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); // 使能GPIOC时钟
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE); // 使能GPIOC时钟
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); // 使能串口3时钟
|
||||
|
||||
USART_DeInit(UART5);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 设置PA2为复用推挽输出
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // 设置PA3为浮空输入
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
GPIO_SetBits(GPIOC, GPIO_Pin_10);
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
GPIO_SetBits(GPIOD, GPIO_Pin_2);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudRate; // 设置串口波特率为115200
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 字长为8位数据格式
|
||||
@@ -75,8 +76,8 @@ static void *UART5_IRQHandler(void *arg)
|
||||
{
|
||||
USART_ClearITPendingBit(UART5, USART_IT_RXNE); // 清除中断标志
|
||||
uint8_t data = USART_ReceiveData(UART5);
|
||||
// queue_push(data);
|
||||
// uart5_send_byte(data);
|
||||
|
||||
MDMSerialRecvByte(data);
|
||||
}
|
||||
uirq_ack(irq_obj, UART5_IRQn);
|
||||
}
|
||||
@@ -89,7 +90,7 @@ void uart5_send_byte(u8 byte)
|
||||
while (USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET)
|
||||
;
|
||||
USART_SendData(UART5, byte);
|
||||
while (USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET)
|
||||
while (USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET)
|
||||
;
|
||||
}
|
||||
void uart5_send_bytes(u8 *bytes, int len)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "spi2.h"
|
||||
#include "delay.h"
|
||||
#include "wk2xx.h"
|
||||
#include "MDM_RTU_Serial.h"
|
||||
#include <assert.h>
|
||||
// #include "MDM_RTU_Serial.h"
|
||||
static obj_handler_t irq_obj;
|
||||
@@ -100,7 +101,7 @@ static void *exti_12_irq(void *arg)
|
||||
recv_len = wk_RxChars(4, wk_recv_buf[3]);
|
||||
for (int i = 0; i < recv_len; i++)
|
||||
{
|
||||
// MDMSerialRecvByte(wk_recv_buf[3][i]);TODO:
|
||||
MDMSerialRecvByte(wk_recv_buf[3][i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
#include "hmi_lcd_process.h"
|
||||
#include "stm32_sys.h"
|
||||
// #include "tim3.h"
|
||||
#include "sysinfo.h"
|
||||
// #include "save_info.h"
|
||||
#include "led.h"
|
||||
#include "relay.h"
|
||||
#include "music_control.h"
|
||||
|
||||
@@ -54,7 +54,7 @@ void MDMInitSerial(void *obj, uint32 baud, uint8 dataBits, uint8 stopBit, uint8
|
||||
/*Hardware initialization*/
|
||||
assert(baud == 9600);
|
||||
Wk_SetBaud(WK_UART_NUM1, B9600);
|
||||
init_uart5(B9600);
|
||||
init_uart5(baud);
|
||||
}
|
||||
/*******************************************************
|
||||
*
|
||||
@@ -121,4 +121,5 @@ void MDMSerialSendBytes(uint8 *bytes, uint16 num)
|
||||
wk_TxChars(WK_UART_NUM1, num, bytes);
|
||||
// 等待发送完成
|
||||
wk_wait_tx_done(WK_UART_NUM1);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@
|
||||
#include "auto_close.h"
|
||||
#include "u_str.h"
|
||||
#include "e180-zg120.h"
|
||||
#include "MDM_RTU_APP.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main(int argc, char *args[])
|
||||
{
|
||||
printf("argc:%d args[0]:%s\n", argc, args[0]);
|
||||
drv_init();
|
||||
u_sleep_ms(100);
|
||||
sys_info_read();
|
||||
drv_init();
|
||||
// sys_info.devID = 12;
|
||||
// sys_info_save();
|
||||
// sys_info.devID = 0;
|
||||
@@ -48,8 +48,9 @@ int main(int argc, char *args[])
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
MDM_RTU_Loop();
|
||||
user_spl0601_get();
|
||||
temps_cal();
|
||||
temp_cal();
|
||||
UpdateUI();
|
||||
usart2_loop();
|
||||
io_ctrl_loop();
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include "adc.h"
|
||||
#include "temp_cal.h"
|
||||
#include "sysinfo.h"
|
||||
#include "u_sys.h"
|
||||
#include "relay.h"
|
||||
#include <math.h>
|
||||
|
||||
#define TEMP_ADJUST_TIMES 6000 // ms
|
||||
// Rt = R *EXP(B*(1/T1-1/T2))
|
||||
// 这里T1和T2指的是K度即开尔文温度,K度=273.15(绝对温度)+摄氏度;其中T2=(273.15+25)
|
||||
// Rt 是热敏电阻在T1温度下的阻值;
|
||||
@@ -79,3 +81,24 @@ void temps_cal(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
static u32 temp_adjust_tick_last_update = 0;
|
||||
void temp_cal(void)
|
||||
{
|
||||
|
||||
temps_cal(); // 计算温度值 8路
|
||||
|
||||
// 调温处理
|
||||
// 温度处理
|
||||
if (sys_read_tick() - temp_adjust_tick_last_update >= TEMP_ADJUST_TIMES)
|
||||
{
|
||||
temp_adjust_tick_last_update = sys_read_tick();
|
||||
if ((int)(sys_info.temp[0]) > sys_info.target_val)
|
||||
{
|
||||
relay_ctrl(5, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
relay_ctrl(5, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,4 @@
|
||||
#define TEMP_MAX_VAL 100
|
||||
#define TEMP_MIN_VAL -40
|
||||
|
||||
void temps_cal(void);
|
||||
void temp_cal(void);
|
||||
|
||||
@@ -68,11 +68,11 @@ int namespace_query(const char *path, obj_handler_t *hd)
|
||||
{
|
||||
if (ns.ne_list[i].hd != HANDLER_INVALID)
|
||||
{
|
||||
char *split_str = strstr(ns.ne_list[i].path, path);
|
||||
if (split_str && (split_str == ns.ne_list[i].path))
|
||||
char *split_str = strstr(path, ns.ne_list[i].path);
|
||||
if (split_str && (split_str == path))
|
||||
{
|
||||
*hd = ns.ne_list[i].hd;
|
||||
return (int)(split_str - ns.ne_list[i].path);
|
||||
return (int)(strlen(ns.ne_list[i].path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ set(CMAKE_SIZE "${CROSS_COMPILE}size" CACHE PATH "" FORCE)
|
||||
|
||||
|
||||
# -mfloat-abi=soft -u _printf_float
|
||||
set(CMAKE_C_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g -lc -lrdimon -msoft-float -u _printf_float \
|
||||
set(CMAKE_C_FLAGS "-mcpu=cortex-m3 -mthumb -O0 -g3 -lc -lrdimon -msoft-float -u _printf_float \
|
||||
-std=gnu11 -ffunction-sections -fdata-sections -fno-builtin \
|
||||
-nostartfiles -nodefaultlibs -nostdlib -nostdinc -Xlinker \
|
||||
--gc-sections -fno-stack-protector \
|
||||
|
||||
Reference in New Issue
Block a user