Files
stc32g128k/Drivers/rf.h
edisondeng 29194a4f5d debug(rf): revert to polling EV1527_Decode, ISR does pure edge counting
Diagnostic experiment: restore the commit d8df5d4 polling decode
algorithm/thresholds unchanged, while P3.6 ISR now only increments an
edge counter (no decode state machine). Successful decodes print the
edge-count delta over the decode window to compare against the
EV1527 theoretical 50-edges-per-frame, to validate/refute the
edge-interrupt glitch-noise hypothesis.
2026-07-31 15:53:15 +08:00

77 lines
3.3 KiB
C
Raw 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.

#ifndef __RF_H__
#define __RF_H__
#include "../App/config.h"
#include "stc32g.h"
/* ====== LR690L / EV1527 无线射频编解码驱动接口 ====== */
/**
* @brief 初始化无线射频芯片相关的 GPIO 引脚
* @details 配置 RF_TX_DAT (P3.6) 为推挽输出,配置 RF_TX (P2.0)、RF_RX (P3.7)、SHUT (P2.2) 等引脚,
* 使能 ATR5179 射频前端开关,为无线射频收发建立硬件基础。
*/
void RF_Init(void);
/**
* @brief 配置无线射频收发系统的运行模式
* @param mode 0-休眠模式 (Sleep)1-接收模式 (Rx)2-发射模式 (Tx)
* @details 负责联合调度 SHUT 控制引脚、天线切换使能引脚以及 ATR5179 射频开关:
* - 模式 0 (Sleep): 拉高 SHUT 以关断 LR690L 芯片电源,实现零电流待机。
* - 模式 1 (Rx): 拉低 SHUT 启动 LR690L 芯片,接通天线并配置前端为接收放大状态。
* - 模式 2 (Tx): 切换天线前端开关为发射直通状态,准备调制发送。
*/
void RF_SetMode(u8 mode);
/**
* @brief 按照 EV1527 协议单次调制发送一帧 24 位射频数据
* @param addr 24 位发射源地址
* @param dat 4 位命令状态数据码
* @details 会生成由 1 个同步码 (Sync Code) 和 24 个数据编码(由 addr + dat 组成)组成的完整帧脉冲。
*/
void EV1527_TxFrame(u32 addr, u8 dat);
/**
* @brief 连续多次发送 EV1527 射频帧,防止单帧丢失
* @param addr 24 位源地址
* @param dat 4 位命令状态码
* @details 连续发送多次以保证无线通信在嘈杂噪声环境下的接收可靠性。
*/
void EV1527_Transmit(u32 addr, u8 dat);
/**
* @brief DEBUG 对照实验P3.6 (RF_RX_DATA) 边沿中断处理,由 main.c 的 Port3_Isr 在每次电平跳变时调用
* @details 本实验阶段只做纯边沿计数 (dbg_isr_edge_count++),不参与任何解码逻辑;真正的解码
* 已改回 EV1527_Decode() 内的阻塞轮询实现。用于验证:一次成功轮询解码期间,
* 真实硬件触发的边沿中断次数是否稳定、是否符合 EV1527 协议理论值 (50)。
*/
void RF_HandleEdgeInterrupt(void);
/**
* @brief 阻塞式检测并解码一个合法的 EV1527 射频信号数据帧 (DEBUG 对照实验:恢复自 commit d8df5d4 的轮询实现)
* @param out_addr 输出参数指针:若解码成功,将写入解析得到的 20 位发送地址 (即 24 位帧除去 4 位数据位后的剩余高 20 位)
* @param out_data 输出参数指针:若解码成功,将写入解析出的 4 位命令状态数据码 (例如报警/SOS等)
* @return bit 1-本次调用解码出一帧有效数据0-未检测到合法数据帧 (含超时/校验失败)
* @note 解码成功时会额外通过串口打印本次解码期间 RF_HandleEdgeInterrupt 的边沿计数快照
* (解码前/解码后/差值),用于对照验证。
*/
bit EV1527_Decode(u32 *out_addr, u8 *out_data);
/**
* @brief RF 收发诊断测试功能 (支持发送与接收监听打印)
*/
void RF_DiagnosticMode(char choice);
/**
* @brief 电气回环自检测试 (物理短路 P2.1 与 P3.6 自检)
*/
void Loopback_Test(void);
/**
* @brief DEBUG: 打印 P3.6 边沿中断纯计数快照 (本实验阶段唯一保留的排查计数器)
* @note 排查用,定位问题完成后可以连同 rf.c 里的计数器一起删除
*/
void RF_PrintDebugCounters(void);
#endif // __RF_H__