/* * @Descripttion: 应用层,每100ms更新屏幕显示 处理完毕 * @version: * @Author: Joe * @Date: 2021-11-19 15:36:28 * @LastEditors: Joe * @LastEditTime: 2021-11-19 21:55:03 */ #include #include #include #include "rpm.h" #include "env.h" #define DBG_TAG "rpm" #define DBG_LVL DBG_INFO #include #define UART_NAME "uart3" #define RPM_TX_THREAD_PRIORITY 18 /* 定义设备控制块 */ static rt_device_t serial; /* 串口设备句柄 */ static rt_thread_t rpm_tx_thread = RT_NULL; /* 线程入口 */ static void rpm_tx_thread_entry(void* parameter) { rt_uint8_t buf[10]; buf[0] = FRAME_1; buf[1] = FRAME_2; buf[6] = FRAME_2; buf[7] = FRAME_1; while(1) { buf[2] = S.FWlkRpm>>8; buf[3] = S.FWlkRpm; buf[4] = Set.FWlkRpm>>8; buf[5] = Set.FWlkRpm; rt_device_write(serial,0,buf,8); rt_thread_mdelay(100); } } /**************************************** * param_init *函数功能 : 参数初始化 *参数描述 : 无 *返回值 : 无 ****************************************/ static void rpm_param_init(void) { } /**************************************** * uart_config *函数功能 : 串口配置初始化 *参数描述 : 无 *返回值 : 无 ****************************************/ static void uart_config(void) { struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /* 初始化配置参数 */ //串口4:RS232 /* step1:查找串口设备 */ serial = rt_device_find(UART_NAME); //查找编程口设备 if (serial) { LOG_I("find %s OK", UART_NAME); } else { LOG_E("find %s failed!", UART_NAME); } /* step2:修改串口配置参数 */ config.baud_rate = BAUD_RATE_115200; //修改波特率为 115200 config.data_bits = DATA_BITS_8; //数据位 8 config.stop_bits = STOP_BITS_1; //停止位 1 config.bufsz = 128; //修改缓冲区 buff size 为 128 config.parity = PARITY_NONE; //偶校验位 /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */ rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config); /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */ /* 以中断接收及轮询发送模式打开串口设备 */ rt_device_open(serial, RT_DEVICE_FLAG_INT_RX); // /* 设置接收回调函数 */ // rt_device_set_rx_indicate(serial, uart_callback); } /**************************************** * uart4_parse_init *函数功能 : 配置初始化 *参数描述 : 无 *返回值 : 无 ****************************************/ int rpm_init(void) { uart_config();//配置初始化 rpm_param_init(); //参数初始化 //创建线程 rpm_tx_thread = /* 线程控制块指针 */ rt_thread_create( "display_tx", /* 线程名字 */ rpm_tx_thread_entry, /* 线程入口函数 */ RT_NULL, /* 线程入口函数参数 */ 2048, /* 线程栈大小 */ RPM_TX_THREAD_PRIORITY, /* 线程的优先级 */ 20); /* 线程时间片 */ /* 启动线程,开启调度 */ if (rpm_tx_thread != RT_NULL) { rt_thread_startup(rpm_tx_thread); LOG_I("rpm_tx_thread create."); } return RT_EOK; } INIT_APP_EXPORT(rpm_init);