rpm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * @Descripttion:
  3. 应用层,每100ms更新屏幕显示
  4. 处理完毕
  5. * @version:
  6. * @Author: Joe
  7. * @Date: 2021-11-19 15:36:28
  8. * @LastEditors: Joe
  9. * @LastEditTime: 2021-11-19 21:55:03
  10. */
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include <board.h>
  14. #include "rpm.h"
  15. #include "env.h"
  16. #define DBG_TAG "rpm"
  17. #define DBG_LVL DBG_INFO
  18. #include <rtdbg.h>
  19. #define UART_NAME "uart3"
  20. #define RPM_TX_THREAD_PRIORITY 18
  21. /* 定义设备控制块 */
  22. static rt_device_t serial; /* 串口设备句柄 */
  23. static rt_thread_t rpm_tx_thread = RT_NULL;
  24. /* 线程入口 */
  25. static void rpm_tx_thread_entry(void* parameter)
  26. {
  27. rt_uint8_t buf[10];
  28. buf[0] = FRAME_1;
  29. buf[1] = FRAME_2;
  30. buf[6] = FRAME_2;
  31. buf[7] = FRAME_1;
  32. while(1)
  33. {
  34. buf[2] = S.FWlkRpm>>8;
  35. buf[3] = S.FWlkRpm;
  36. buf[4] = Set.FWlkRpm>>8;
  37. buf[5] = Set.FWlkRpm;
  38. rt_device_write(serial,0,buf,8);
  39. rt_thread_mdelay(100);
  40. }
  41. }
  42. /****************************************
  43. * param_init
  44. *函数功能 : 参数初始化
  45. *参数描述 : 无
  46. *返回值 : 无
  47. ****************************************/
  48. static void rpm_param_init(void)
  49. {
  50. }
  51. /****************************************
  52. * uart_config
  53. *函数功能 : 串口配置初始化
  54. *参数描述 : 无
  55. *返回值 : 无
  56. ****************************************/
  57. static void uart_config(void)
  58. {
  59. struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /* 初始化配置参数 */
  60. //串口4:RS232
  61. /* step1:查找串口设备 */
  62. serial = rt_device_find(UART_NAME); //查找编程口设备
  63. if (serial)
  64. {
  65. LOG_I("find %s OK", UART_NAME);
  66. }
  67. else
  68. {
  69. LOG_E("find %s failed!", UART_NAME);
  70. }
  71. /* step2:修改串口配置参数 */
  72. config.baud_rate = BAUD_RATE_115200; //修改波特率为 115200
  73. config.data_bits = DATA_BITS_8; //数据位 8
  74. config.stop_bits = STOP_BITS_1; //停止位 1
  75. config.bufsz = 128; //修改缓冲区 buff size 为 128
  76. config.parity = PARITY_NONE; //偶校验位
  77. /* step3:控制串口设备。通过控制接口传入命令控制字,与控制参数 */
  78. rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
  79. /* step4:打开串口设备。以中断接收及轮询发送模式打开串口设备 */
  80. /* 以中断接收及轮询发送模式打开串口设备 */
  81. rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
  82. // /* 设置接收回调函数 */
  83. // rt_device_set_rx_indicate(serial, uart_callback);
  84. }
  85. /****************************************
  86. * uart4_parse_init
  87. *函数功能 : 配置初始化
  88. *参数描述 : 无
  89. *返回值 : 无
  90. ****************************************/
  91. int rpm_init(void)
  92. {
  93. uart_config();//配置初始化
  94. rpm_param_init(); //参数初始化
  95. //创建线程
  96. rpm_tx_thread = /* 线程控制块指针 */
  97. rt_thread_create( "display_tx", /* 线程名字 */
  98. rpm_tx_thread_entry, /* 线程入口函数 */
  99. RT_NULL, /* 线程入口函数参数 */
  100. 2048, /* 线程栈大小 */
  101. RPM_TX_THREAD_PRIORITY, /* 线程的优先级 */
  102. 20); /* 线程时间片 */
  103. /* 启动线程,开启调度 */
  104. if (rpm_tx_thread != RT_NULL)
  105. {
  106. rt_thread_startup(rpm_tx_thread);
  107. LOG_I("rpm_tx_thread create.");
  108. }
  109. return RT_EOK;
  110. }
  111. INIT_APP_EXPORT(rpm_init);