drivers/staging/led/led.c: In function 'rf_detect_sync_header':
drivers/staging/led/led.c:244:12: error: invalid storage class for function 'rf_decode_data_bits'
static int rf_decode_data_bits(struct rf_decoder_state *state, uint32_t pulse_width, int level)
^~~~~~~~~~~~~~~~~~~
drivers/staging/led/led.c: In function 'rf_decode_data_bits':
drivers/staging/led/led.c:285:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
uint32_t low_duration = pulse_width; // 低电平持续时间
^~~~~~~~
drivers/staging/led/led.c: In function 'rf_detect_sync_header':
drivers/staging/led/led.c:244:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
static int rf_decode_data_bits(struct rf_decoder_state *state, uint32_t pulse_width, int level)
^~~~~~
drivers/staging/led/led.c:323:12: error: invalid storage class for function 'rf_data_decode'
static int rf_data_decode(struct rf_decoder_state *state)
^~~~~~~~~~~~~~
drivers/staging/led/led.c:364:20: error: invalid storage class for function 'rf_data_irq_handler'
static irqreturn_t rf_data_irq_handler(int irq, void *dev_id)
^~~~~~~~~~~~~~~~~~~
drivers/staging/led/led.c:375:12: error: invalid storage class for function 'rf_open'
static int rf_open(struct inode *inode, struct file *file)
^~~~~~~
drivers/staging/led/led.c:415:16: error: invalid storage class for function 'rf_read'
static ssize_t rf_read(struct file *file, char __user *buf, size_t len, loff_t *offset)
^~~~~~~
drivers/staging/led/led.c:446:16: error: invalid storage class for function 'rf_write'
static ssize_t rf_write(struct file *file, const char __user *buf, size_t len, loff_t *offset)
^~~~~~~~
drivers/staging/led/led.c:452:12: error: invalid storage class for function 'rf_close'
static int rf_close(struct inode *inode, struct file *file)
^~~~~~~~
drivers/staging/led/led.c:466:21: error: invalid storage class for function 'rf_poll'
static unsigned int rf_poll(struct file *file, poll_table *wait)
^~~~~~~
drivers/staging/led/led.c:481:13: error: initializer element is not constant
.open = rf_open,
^~~~~~~
drivers/staging/led/led.c:481:13: note: (near initialization for 'rf_file_operations.open')
drivers/staging/led/led.c:482:13: error: initializer element is not constant
.read = rf_read,
^~~~~~~
drivers/staging/led/led.c:482:13: note: (near initialization for 'rf_file_operations.read')
drivers/staging/led/led.c:483:14: error: initializer element is not constant
.write = rf_write,
^~~~~~~~
drivers/staging/led/led.c:483:14: note: (near initialization for 'rf_file_operations.write')
drivers/staging/led/led.c:484:16: error: initializer element is not constant
.release = rf_close,
^~~~~~~~
drivers/staging/led/led.c:484:16: note: (near initialization for 'rf_file_operations.release')
drivers/staging/led/led.c:485:13: error: initializer element is not constant
.poll = rf_poll,
^~~~~~~
drivers/staging/led/led.c:485:13: note: (near initialization for 'rf_file_operations.poll')
drivers/staging/led/led.c:488:19: error: invalid storage class for function 'rf_init'
static int __init rf_init(void)
^~~~~~~
drivers/staging/led/led.c:570:20: error: invalid storage class for function 'rf_exit'
static void __exit rf_exit(void)
^~~~~~~
In file included from drivers/staging/led/led.c:1:0:
drivers/staging/led/led.c:591:13: error: initializer element is not constant
module_init(rf_init);
^
./include/linux/init.h:218:50: note: in definition of macro '___define_initcall'
__attribute__((__section__(#__sec ".init"))) = fn;
^~
./include/linux/init.h:251:30: note: in expansion of macro '__define_initcall'
#define device_initcall(fn) __define_initcall(fn, 6)
^~~~~~~~~~~~~~~~~
./include/linux/init.h:256:24: note: in expansion of macro 'device_initcall'
#define __initcall(fn) device_initcall(fn)
^~~~~~~~~~~~~~~
./include/linux/module.h:87:24: note: in expansion of macro '__initcall'
#define module_init(x) __initcall(x);
^~~~~~~~~~
drivers/staging/led/led.c:591:1: note: in expansion of macro 'module_init'
module_init(rf_init);
^~~~~~~~~~~
drivers/staging/led/led.c:592:13: error: initializer element is not constant
module_exit(rf_exit);
^
./include/linux/init.h:259:50: note: in definition of macro '__exitcall'
static exitcall_t __exitcall_##fn __exit_call = fn
^~
drivers/staging/led/led.c:592:1: note: in expansion of macro 'module_exit'
module_exit(rf_exit);
^~~~~~~~~~~
./include/linux/init.h:259:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
static exitcall_t __exitcall_##fn __exit_call = fn
^
./include/linux/module.h:99:24: note: in expansion of macro '__exitcall'
#define module_exit(x) __exitcall(x);
^~~~~~~~~~
drivers/staging/led/led.c:592:1: note: in expansion of macro 'module_exit'
module_exit(rf_exit);
^~~~~~~~~~~
In file included from ./include/linux/module.h:18:0,
from drivers/staging/led/led.c:2:
./include/linux/moduleparam.h:24:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
static const char __UNIQUE_ID(name)[] \
^
./include/linux/module.h:161:32: note: in expansion of macro '__MODULE_INFO'
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)
^~~~~~~~~~~~~
./include/linux/module.h:215:34: note: in expansion of macro 'MODULE_INFO'
#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)
^~~~~~~~~~~
drivers/staging/led/led.c:594:1: note: in expansion of macro 'MODULE_LICENSE'
MODULE_LICENSE("GPL");
^~~~~~~~~~~~~~
In file included from drivers/staging/led/led.c:2:0:
./include/linux/module.h:268:22: error: expected declaration or statement at end of input
static const struct module_version_attribute \
^
drivers/staging/led/led.c:597:1: note: in expansion of macro 'MODULE_VERSION'
MODULE_VERSION("1.3");
^~~~~~~~~~~~~~
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/poll.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/device.h>
#include <linux/timer.h>
#include <linux/jiffies.h>
#include <linux/kfifo.h>
#include <linux/ktime.h>
#define COUNT 1
#define RF_DATA_GPIO 137 // RF数据输入引脚
#define dev_name "rf_decoder"
// 433MHz RF解码参数
#define RF_SYNC_CODE_MAX_SCALE 60
#define RF_SYNC_CODE_MIN_SCALE 20
#define RF_SYNC_CODE_TYPICAL_SCALE 32
#define RF_DATA_CODE_MAX_SCALE 6
#define RF_DATA_CODE_MIN_SCALE 2
#define RF_DATA_CODE_TYPICAL_SCALE 3
// 时间参数(单位:微秒)
#define RF_REPEAT_DATA_TIME 2000000 // 2秒去重时间
#define RF_SYNC_HIGH_MIN 200 // 同步头高电平最小宽度200us
#define RF_SYNC_HIGH_MAX 8000 // 同步头高电平最大宽度800us
#define RF_BIT_MIN_WIDTH 200 // 数据位最小宽度200us
#define RF_BIT_MAX_WIDTH 2000 // 数据位最大宽度2ms
#define UINT32_MAX ((uint32_t)0xFFFFFFFF)
// 数据位解码比例参数(使用整数运算避免浮点)
#define RATIO_1_MIN_NUMERATOR 15 // 1.5 = 15/10
#define RATIO_1_MIN_DENOMINATOR 10
#define RATIO_1_MAX_NUMERATOR 50 // 5.0 = 50/10
#define RATIO_1_MAX_DENOMINATOR 10
#define RATIO_0_MIN_NUMERATOR 2 // 0.2 = 2/10
#define RATIO_0_MIN_DENOMINATOR 10
#define RATIO_0_MAX_NUMERATOR 67 // 0.67 = 67/100
#define RATIO_0_MAX_DENOMINATOR 100
// 环形缓冲区大小
#define RF_RX_FIFO_SIZE 256
static dev_t rf_device_id;
static struct cdev rf_cdev;
static struct class *rf_class;
// RF解码状态结构体
struct rf_decoder_state {
// 解码状态标志
uint8_t bit_rx_sync; // 是否接收到同步头
uint8_t bit_rx_status; // 当前电平状态
uint8_t bit_rx_decode; // 正在解码数据
uint8_t uc_rec_count; // 接收数据位计数
// 同步头检测状态
uint8_t sync_phase; // 同步头检测阶段: 0=等待高电平, 1=等待低电平
uint32_t sync_high_time; // 同步头高电平时间
uint32_t sync_low_time; // 同步头di电平时间
// 时间记录
uint32_t rx_time_us; // 上次接收时间
uint32_t rx_old_data; // 上次接收的数据(用于去重)
// 数据缓冲区
uint32_t rx_shift; // 移位寄存器
uint32_t rx_long; // 长按数据
// 电平时间记录
uint32_t last_pulse_width; // 上次脉冲宽度
uint32_t last_edge_time; // 上次边沿时间
uint32_t last_level; // 上次电平状态
// FIFO缓冲区
struct kfifo rx_data_fifo; // 接收数据FIFO
unsigned char *fifo_buffer; // FIFO缓冲区指针
// 同步保护
spinlock_t lock;
wait_queue_head_t read_queue;
};
static struct rf_decoder_state rf_decoder;
// 获取32位微秒时间
u32 get_32bit_usec_ktime(void)
{
ktime_t kt = ktime_get();
return (u32)ktime_to_us(kt);
}
// 专门处理32位时间差计算的函数
static uint32_t time_diff_32(uint32_t newer, uint32_t older)
{
if (newer >= older) {
return newer - older;
} else {
// 处理溢出情况
return (UINT32_MAX - older) + newer + 1;
}
}
// 重置解码状态
static void rf_reset_state(struct rf_decoder_state *state)
{
state->bit_rx_sync = 1; // 等待同步头
state->sync_phase = 0; // 同步头检测阶段0: 等待高电平
state->sync_high_time = 0; // 清空同步头高电平时间
state->sync_low_time = 0; // 清空同步头di电平时间
state->bit_rx_decode = 0;
state->uc_rec_count = 0;
state->rx_shift = 0;
state->last_pulse_width = 0;
state->last_level = gpio_get_value(RF_DATA_GPIO);
}
// 数据接收完成处理
static int rf_complete_data_reception(struct rf_decoder_state *state)
{
uint32_t current_time = get_32bit_usec_ktime();
unsigned long flags;
printk(KERN_INFO "RF: Received 24 bits: 0x%08X\n", state->rx_shift);
// 去重处理
if ((state->rx_old_data != state->rx_shift) ||
((current_time - state->rx_time_us) > RF_REPEAT_DATA_TIME)) {
state->rx_time_us = current_time;
state->rx_old_data = state->rx_shift;
// 将解码数据写入FIFO
spin_lock_irqsave(&state->lock, flags);
if (kfifo_avail(&state->rx_data_fifo) >= sizeof(uint32_t)) {
kfifo_in(&state->rx_data_fifo,
(unsigned char *)&state->rx_shift, sizeof(uint32_t));
wake_up_interruptible(&state->read_queue);
printk(KERN_INFO "RF: 🎯 Decoded data: 0x%08X\n", state->rx_shift);
} else {
printk(KERN_WARNING "RF: ⚠️ RX FIFO full, data dropped: 0x%08X\n",
state->rx_shift);
}
spin_unlock_irqrestore(&state->lock, flags);
} else {
printk(KERN_DEBUG "RF: 🔄 Duplicate data ignored: 0x%08X\n", state->rx_shift);
}
// 重置状态,等待下一个同步头
rf_reset_state(state);
return 0;
}
// 使用整数运算检查比例(避免浮点运算)
static int check_ratio(uint32_t high_time, uint32_t low_time,
uint32_t min_num, uint32_t min_denom,
uint32_t max_num, uint32_t max_denom)
{
// 检查 high_time/low_time 是否在 [min_num/min_denom, max_num/max_denom] 范围内
// 使用乘法避免除法,避免浮点运算
// 检查 high_time * min_denom >= low_time * min_num
if (high_time * min_denom < low_time * min_num) {
return 0;
}
// 检查 high_time * max_denom <= low_time * max_num
if (high_time * max_denom > low_time * max_num) {
return 0;
}
// 检查 low_time < max_num
if (low_time < 8000) {
return 0;
}
return 1;
}
// 同步头检测
static int rf_detect_sync_header(struct rf_decoder_state *state, uint32_t pulse_width, int level)
{
if (level == 1) {
state->sync_low_time = pulse_width; // 记录di电平shijian
if (check_ratio(state->sync_low_time, state->sync_high_time,
RF_SYNC_CODE_MIN_SCALE, 1,
RF_SYNC_CODE_MAX_SCALE, 1)) {
// 同步头检测成功
printk(KERN_DEBUG "RF: Sync header detected:succeed");
state->bit_rx_sync = 0;
return 1;
}else
{
if (state->sync_high_time >= RF_SYNC_HIGH_MIN && state->sync_high_time <= RF_SYNC_HIGH_MAX) {
state->sync_high_time = pulse_width; // 保存高电平持续时间
}
printk(KERN_DEBUG "RF: state->sync_low_time:%u ,state->sync_high_time:%u\n\n",state->sync_low_time,state->sync_high_time);
return 0;
}
/* if (state->sync_phase == 0) {
// 阶段0: 等待高电平开始(上升沿)
} else if (state->sync_phase == 1) {
// 阶段1: 等待高电平结束(下降沿)
if (level == 0) {
uint32_t high_duration = time_diff_32(get_32bit_usec_ktime(), state->sync_high_time);
// 检查高电平持续时间
if (high_duration >= RF_SYNC_HIGH_MIN && high_duration <= RF_SYNC_HIGH_MAX) {
state->sync_high_time = high_duration;
state->sync_phase = 2;
}
}
} else if (state->sync_phase == 2) {
// 阶段2: 等待低电平结束(上升沿)
if (level == 1) {
uint32_t low_duration = pulse_width; // 这个pulse_width是低电平持续时间
// 检查低电平时间是否为高电平时间的20-60倍
if (check_ratio(low_duration, state->sync_high_time,
RF_SYNC_CODE_MIN_SCALE, 1,
RF_SYNC_CODE_MAX_SCALE, 1)) {
// 同步头检测成功
printk(KERN_DEBUG "RF: Sync header detected:succeed");
state->bit_rx_sync = 0;
return 1;
}
}
}*/
return 0;
}
// 数据位解码
static int rf_decode_data_bits(struct rf_decoder_state *state, uint32_t pulse_width, int level)
{
static uint32_t bit_start_time = 0;
uint32_t current_time;
uint32_t duration;
current_time = get_32bit_usec_ktime();
if (state->last_level == level) {
// 电平没有变化,不应该发生
printk(KERN_DEBUG "RF: Unexpected level change\n");
return -1;
}
if (level == 1) {
// 上升沿:低电平结束,记录低电平持续时间
duration = pulse_width; // pulse_width是低电平持续时间
// 检查数据位宽度是否合理
if (duration < RF_BIT_MIN_WIDTH || duration > RF_BIT_MAX_WIDTH) {
printk(KERN_DEBUG "RF: Invalid bit width - low: %u\n", duration);
rf_reset_state(state);
return -1;
}
// 记录位开始时间(高电平开始)
bit_start_time = current_time;
state->last_level = 1;
} else {
// 下降沿:高电平结束,记录高电平持续时间
duration = time_diff_32(current_time, bit_start_time);
// 检查数据位宽度是否合理
if (duration < RF_BIT_MIN_WIDTH || duration > RF_BIT_MAX_WIDTH) {
printk(KERN_DEBUG "RF: Invalid bit width - high: %u\n", duration);
rf_reset_state(state);
return -1;
}
// 使用整数运算检查高低电平比例来判断是0还是1
// 注意:这里我们检查的是高电平持续时间与低电平持续时间的比例
uint32_t low_duration = pulse_width; // 低电平持续时间
if (check_ratio(duration, low_duration,
RATIO_1_MIN_NUMERATOR, RATIO_1_MIN_DENOMINATOR,
RATIO_1_MAX_NUMERATOR, RATIO_1_MAX_DENOMINATOR)) {
// 逻辑1:高电平时间较长
state->rx_shift = (state->rx_shift << 1) | 1;
state->uc_rec_count++;
printk(KERN_DEBUG "RF: Bit %d: 1 (H:%uus L:%uus)\n",
state->uc_rec_count, duration, low_duration);
} else if (check_ratio(low_duration, duration,
RATIO_0_MIN_NUMERATOR, RATIO_0_MIN_DENOMINATOR,
RATIO_0_MAX_NUMERATOR, RATIO_0_MAX_DENOMINATOR)) {
// 逻辑0:低电平时间较长
state->rx_shift = (state->rx_shift << 1);
state->uc_rec_count++;
printk(KERN_DEBUG "RF: Bit %d: 0 (H:%uus L:%uus)\n",
state->uc_rec_count, duration, low_duration);
} else {
// 无效数据位,重新同步
printk(KERN_DEBUG "RF: Invalid bit ratio, resync (H:%u L:%u)\n",
duration, low_duration);
rf_reset_state(state);
return -1;
}
// 检查是否接收完24位数据
if (state->uc_rec_count >= 24) {
return rf_complete_data_reception(state);
}
state->last_level = 0;
}
return 0;
}
// 解码函数
static int rf_data_decode(struct rf_decoder_state *state)
{
uint32_t current_time;
int level;
uint32_t pulse_width;
// 在函数开头声明所有变量,符合C90标准
current_time = get_32bit_usec_ktime();
level = gpio_get_value(RF_DATA_GPIO);
// 如果是第一次调用,初始化时间
if (state->last_edge_time == 0) {
state->last_edge_time = current_time;
state->last_level = level;
return -1;
}
// 计算脉冲宽度
pulse_width = time_diff_32(current_time, state->last_edge_time);
state->last_edge_time = current_time;
// 添加合理性检查 - 过滤异常脉冲
if (pulse_width > 100000) { // 100ms最大限制
printk(KERN_DEBUG "RF: Pulse width too large: %u us, resetting\n", pulse_width);
rf_reset_state(state);
return -1;
}
// 状态机处理
if (state->bit_rx_sync) {
// 同步头检测模式
return rf_detect_sync_header(state, pulse_width, level);
} else {
// 数据接收模式
return rf_decode_data_bits(state, pulse_width, level);
}
return 0;
}
// 中断处理函数
static irqreturn_t rf_data_irq_handler(int irq, void *dev_id)
{
struct rf_decoder_state *state = (struct rf_decoder_state *)dev_id;
// 在中断上下文中进行基础解码
rf_data_decode(state);
return IRQ_HANDLED;
}
// 文件操作函数
static int rf_open(struct inode *inode, struct file *file)
{
int ret;
int irq;
// 请求GPIO
ret = gpio_request(RF_DATA_GPIO, "rf_data");
if (ret < 0) {
printk(KERN_ERR "RF: Failed to request GPIO %d\n", RF_DATA_GPIO);
return ret;
}
// 配置为输入模式
ret = gpio_direction_input(RF_DATA_GPIO);
if (ret < 0) {
printk(KERN_ERR "RF: Failed to set GPIO direction\n");
gpio_free(RF_DATA_GPIO);
return ret;
}
// 申请中断 - 双边沿触发
irq = gpio_to_irq(RF_DATA_GPIO);
ret = request_irq(irq, rf_data_irq_handler,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
"rf_data", &rf_decoder);
if (ret < 0) {
printk(KERN_ERR "RF: Failed to request IRQ for GPIO %d, irq %d\n",
RF_DATA_GPIO, irq);
gpio_free(RF_DATA_GPIO);
return ret;
}
// 重置解码状态
rf_reset_state(&rf_decoder);
rf_decoder.last_edge_time = get_32bit_usec_ktime();
printk(KERN_INFO "RF decoder device opened successfully, IRQ: %d\n", irq);
return 0;
}
static ssize_t rf_read(struct file *file, char __user *buf, size_t len, loff_t *offset)
{
unsigned long flags;
int ret;
uint32_t data;
if (len < sizeof(uint32_t)) {
return -EINVAL;
}
// 等待数据可用
if (wait_event_interruptible(rf_decoder.read_queue,
!kfifo_is_empty(&rf_decoder.rx_data_fifo))) {
return -ERESTARTSYS;
}
spin_lock_irqsave(&rf_decoder.lock, flags);
ret = kfifo_out(&rf_decoder.rx_data_fifo, (unsigned char *)&data, sizeof(uint32_t));
spin_unlock_irqrestore(&rf_decoder.lock, flags);
if (ret != sizeof(uint32_t)) {
return -EIO;
}
if (copy_to_user(buf, &data, sizeof(uint32_t))) {
return -EFAULT;
}
return sizeof(uint32_t);
}
static ssize_t rf_write(struct file *file, const char __user *buf, size_t len, loff_t *offset)
{
// 只读设备,不支持写入
return -EPERM;
}
static int rf_close(struct inode *inode, struct file *file)
{
int irq = gpio_to_irq(RF_DATA_GPIO);
// 释放中断
free_irq(irq, &rf_decoder);
// 释放GPIO
gpio_free(RF_DATA_GPIO);
printk(KERN_INFO "RF decoder device closed\n");
return 0;
}
static unsigned int rf_poll(struct file *file, poll_table *wait)
{
unsigned int mask = 0;
poll_wait(file, &rf_decoder.read_queue, wait);
if (!kfifo_is_empty(&rf_decoder.rx_data_fifo)) {
mask |= POLLIN | POLLRDNORM;
}
return mask;
}
static const struct file_operations rf_file_operations = {
.owner = THIS_MODULE,
.open = rf_open,
.read = rf_read,
.write = rf_write,
.release = rf_close,
.poll = rf_poll,
};
static int __init rf_init(void)
{
int ret;
// 初始化RF解码器状态
memset(&rf_decoder, 0, sizeof(rf_decoder));
spin_lock_init(&rf_decoder.lock);
init_waitqueue_head(&rf_decoder.read_queue);
// 初始状态:等待同步头
rf_decoder.bit_rx_sync = 1;
rf_decoder.sync_phase = 0;
rf_decoder.last_edge_time = 0;
// 初始化FIFO缓冲区
rf_decoder.fifo_buffer = kmalloc(RF_RX_FIFO_SIZE, GFP_KERNEL);
if (!rf_decoder.fifo_buffer) {
printk(KERN_ERR "RF: Failed to allocate FIFO buffer\n");
return -ENOMEM;
}
// 初始化FIFO
ret = kfifo_init(&rf_decoder.rx_data_fifo, rf_decoder.fifo_buffer, RF_RX_FIFO_SIZE);
if (ret) {
printk(KERN_ERR "RF: Failed to initialize FIFO\n");
kfree(rf_decoder.fifo_buffer);
return ret;
}
// 创建设备号
ret = alloc_chrdev_region(&rf_device_id, 0, COUNT, dev_name);
if (ret < 0) {
printk(KERN_ERR "RF: Failed to allocate chrdev region\n");
kfifo_free(&rf_decoder.rx_data_fifo);
kfree(rf_decoder.fifo_buffer);
return ret;
}
// 初始化字符设备
cdev_init(&rf_cdev, &rf_file_operations);
rf_cdev.owner = THIS_MODULE;
ret = cdev_add(&rf_cdev, rf_device_id, COUNT);
if (ret < 0) {
printk(KERN_ERR "RF: Failed to add cdev\n");
goto err_cdev;
}
// 创建设备类
rf_class = class_create(THIS_MODULE, "rf_class");
if (IS_ERR(rf_class)) {
ret = PTR_ERR(rf_class);
printk(KERN_ERR "RF: Failed to create class\n");
goto err_class;
}
// 创建设备节点
if (IS_ERR(device_create(rf_class, NULL, rf_device_id, NULL, dev_name))) {
printk(KERN_ERR "RF: Failed to create device\n");
goto err_device;
}
printk(KERN_INFO "RF decoder driver initialized successfully\n");
printk(KERN_INFO "RF parameters:\n");
printk(KERN_INFO " Sync header: High %d-%d us, Low/High ratio: %d-%d\n",
RF_SYNC_HIGH_MIN, RF_SYNC_HIGH_MAX, RF_SYNC_CODE_MIN_SCALE, RF_SYNC_CODE_MAX_SCALE);
printk(KERN_INFO " Bit width: %d-%d us\n", RF_BIT_MIN_WIDTH, RF_BIT_MAX_WIDTH);
printk(KERN_INFO " Data bits: 24\n");
printk(KERN_INFO "Usage: cat /dev/rf_decoder - Read decoded RF data\n");
return 0;
err_device:
class_destroy(rf_class);
err_class:
cdev_del(&rf_cdev);
err_cdev:
unregister_chrdev_region(rf_device_id, COUNT);
kfifo_free(&rf_decoder.rx_data_fifo);
kfree(rf_decoder.fifo_buffer);
return ret;
}
static void __exit rf_exit(void)
{
// 清理设备节点
device_destroy(rf_class, rf_device_id);
class_destroy(rf_class);
// 清理字符设备
cdev_del(&rf_cdev);
unregister_chrdev_region(rf_device_id, COUNT);
// 释放FIFO
kfifo_free(&rf_decoder.rx_data_fifo);
// 释放FIFO缓冲区
if (rf_decoder.fifo_buffer) {
kfree(rf_decoder.fifo_buffer);
}
printk(KERN_INFO "RF decoder driver unloaded\n");
}
module_init(rf_init);
module_exit(rf_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("AWOL");
MODULE_DESCRIPTION("433MHz RF Signal Decoder Driver with interrupt-based reception");
MODULE_VERSION("1.3");
最新发布