current_v/Inc/o2_sensor.h
2025-12-31 08:21:43 +08:00

105 lines
2.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : o2_sensor.h
* @brief : 氧浓度传感器头文件
* @version : 1.0
* @changelog : version 1.0 初始版本 2025.11.13
******************************************************************************
* @attention
*
* Copyright (c) 2025 Yuwell Software Danyang.Jiangsu.China
* THIS SOFTWARE is licensed under the Mulan PSL v1.
* can use this software according to the terms and conditions of the Mulan PSL v1.
* You may obtain a copy of Mulan PSL v1 at:
* http://license.coscl.org.cn/MulanPSL
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v1 for more details.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __O2_SENSOR_H
#define __O2_SENSOR_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "fm33lg0xx_fl.h"
#include "fm33lg0xx_queue.h"
#include "fm33lg0xx_event.h"
/* 对硬件使用进行配置 */
#define O2_SENSOR_USED_UART_NUM UART5
#define CHECK_TRANS_DONE while(FL_UART_IsActiveFlag_TXShiftBuffEmpty(O2_SENSOR_USED_UART_NUM) != FL_SET){};
#define OXG_UART_TRANS_BYTE(x) FL_UART_WriteTXBuff(O2_SENSOR_USED_UART_NUM, x);CHECK_TRANS_DONE;
// 状态机的状态定义(内部使用)
typedef enum
{
O2_STATE_WAIT_HEADER1, // 等待帧头第1字节0x16
O2_STATE_WAIT_HEADER2, // 等待帧头第2字节0x09
O2_STATE_WAIT_HEADER3, // 等待帧头第3字节0x01
O2_STATE_RECV_DATA, // 接收后续数据字节
O2_STATE_CHECK_FRAME // 校验帧完整性
} RecvState;
// 先定义协议中涉及的枚举/类型
typedef enum
{
O2_FRAME_IDLE = 0, // 空闲状态
O2_FRAME_RECEIVING, // 接收中
O2_FRAME_COMPLETE, // 接收完成(可解析)
O2_FRAME_ERROR // 帧错误
} O2FrameState;
typedef struct
{
struct{
uint8_t DF[8];
uint8_t CheckSum;
}O2_raw_data;
uint16_t o2_concentration; // 等于真实值乘以10
uint16_t o2_flow; // 等于真实值乘以10 单位L/min
uint16_t o2_temperature;
RecvState receive_state;
O2FrameState frame_state;
uint32_t fault_count;
}O2SensorData;
/************************** 对外导出的API函数 *************************/
void oxg_sensor_init(void);
void oxg_sensor_task(void);
void UART5_IRQHandler(void);
#ifdef __cplusplus
}
#endif
#endif /* __O2_SENSOR_H */
/************************ (C) COPYRIGHT Yuwell *****END OF FILE****/