Files
stc32g128k/Drivers/rf.h
edisondeng 4a89aef71e fix(rf): true single-edge P3.6 trigger + pull-down, restore edge decode
Root cause found via datasheet: PxIM0/PxIM1 has no dual-edge mode, only
falling/rising/low-level/high-level. (IM1=1,IM0=1) was actually
high-level interrupt, refiring continuously for the whole high-pulse
duration (confirmed by scope: no real HF noise, and edge_count=0 when
P3.6 grounded). Fix: start in rising-edge mode, software-toggle to the
opposite edge on every trigger (ping-pong) to emulate true dual-edge
triggering, feeding exact edge direction into the incremental decode
state machine (no glitch filter needed). Also switch P3.6 idle bias
from pull-up to pull-down, since floating-high under the old high-level
mode caused the interrupt-storm boot issue; removed the now-conflicting
pull-up restore in Wakeup_Restore().
2026-07-31 16:39:06 +08:00

77 lines
3.4 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.

#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 P3.6 (RF_RX_DATA) 单边沿触发中断处理,由 main.c 的 Port3_Isr 在每次电平跳变时调用
* @details 硬件 PxIM1/PxIM0 只支持下降沿/上升沿/低电平/高电平四选一,没有真正的"双边沿"模式;
* 本函数在每次触发后都会立即把 P3IM0 翻转到相反边沿(乒乓切换),模拟出双边沿触发的效果,
* 并据此驱动内部的三态增量解码状态机 (空闲搜索 -> 同步头确认 -> 逐位收集),凑齐 24 位后
* 把结果写入内部标志供 EV1527_Decode() 非阻塞取用。全程不做任何阻塞等待。
*/
void RF_HandleEdgeInterrupt(void);
/**
* @brief 非阻塞地检查一次 EV1527 射频信号是否已解码完成
* @param out_addr 输出参数指针:若解码成功,将写入解析得到的 20 位发送地址 (即 24 位帧除去 4 位数据位后的剩余高 20 位)
* @param out_data 输出参数指针:若解码成功,将写入解析出的 4 位命令状态数据码 (例如报警/SOS等)
* @return bit 1-本次调用取到了一帧新解码出的有效数据0-当前尚无新结果
* @note 真正的解码工作已经在 P3.6 边沿中断 (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: 打印边沿解码状态机的简易运行计数器 (当前状态/位索引/成功帧数/放弃次数)
*/
void RF_PrintDebugCounters(void);
#endif // __RF_H__