83 lines
2.0 KiB
C
83 lines
2.0 KiB
C
|
|
/**
|
|||
|
|
******************************************************************************
|
|||
|
|
* @file io_monitor.h
|
|||
|
|
* @brief IO状态监控模块头文件
|
|||
|
|
* @author Application Layer
|
|||
|
|
* @version 1.0
|
|||
|
|
******************************************************************************
|
|||
|
|
* @attention
|
|||
|
|
* 本模块实现四路数字输入(DI1-DI4)的状态监控
|
|||
|
|
* 采用定时扫描+软件去抖方式检测IO状态变化
|
|||
|
|
* 状态变化时通过UART2_Print上报
|
|||
|
|
******************************************************************************
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef __IO_MONITOR_H
|
|||
|
|
#define __IO_MONITOR_H
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
extern "C" {
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#include <stdint.h>
|
|||
|
|
#include <stdbool.h>
|
|||
|
|
|
|||
|
|
#define IO_CHANNEL_COUNT 4
|
|||
|
|
#define IO_SCAN_PERIOD_MS 10
|
|||
|
|
#define IO_DEBOUNCE_COUNT 3
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 初始化IO监控模块
|
|||
|
|
* @note 初始化各通道状态,读取初始IO电平
|
|||
|
|
* @param 无
|
|||
|
|
* @retval 无
|
|||
|
|
*/
|
|||
|
|
void IO_Monitor_Init(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief IO监控任务处理函数
|
|||
|
|
* @note 在主循环中调用,每10ms扫描一次IO状态
|
|||
|
|
* 检测到状态变化时自动上报
|
|||
|
|
* @param 无
|
|||
|
|
* @retval 无
|
|||
|
|
*/
|
|||
|
|
void IO_Monitor_Task(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获取指定通道的IO状态
|
|||
|
|
* @note 返回经过去抖处理后的稳定状态
|
|||
|
|
* @param channel: 通道号(0-3对应DI1-DI4)
|
|||
|
|
* @retval 0: LOW, 1: HIGH
|
|||
|
|
*/
|
|||
|
|
uint8_t IO_Monitor_GetState(uint8_t channel);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获取所有IO通道状态
|
|||
|
|
* @note 返回4位状态值,每位对应一个通道
|
|||
|
|
* @param 无
|
|||
|
|
* @retval 状态值 (bit0=DI1, bit1=DI2, bit2=DI3, bit3=DI4)
|
|||
|
|
*/
|
|||
|
|
uint8_t IO_Monitor_GetAllStates(void);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 启用/禁用IO状态变化上报
|
|||
|
|
* @note 禁用后状态变化不会触发上报,但状态仍会更新
|
|||
|
|
* @param enable: true=启用, false=禁用
|
|||
|
|
* @retval 无
|
|||
|
|
*/
|
|||
|
|
void IO_Monitor_EnableReport(bool enable);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 获取IO状态变化次数统计
|
|||
|
|
* @note 用于调试和诊断
|
|||
|
|
* @param channel: 通道号(0-3)
|
|||
|
|
* @retval 该通道的状态变化次数
|
|||
|
|
*/
|
|||
|
|
uint32_t IO_Monitor_GetChangeCount(uint8_t channel);
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#endif
|