驱动调试接口-debugfs

  • 创建目录
spidev->root_dir = debugfs_create_dir(SPIDEV, NULL);
  • 在目录下创建文件节点
 spidev->debug_level = debugfs_create_file("debug_level",
                                0664, spidev->root_dir, spidev, &debug_level_ops);
        if (spidev->debug_level == NULL) {
                dev_err(&spi->dev, "debugfs create debug_level failed\n");
                ret = -EINVAL;
                goto create_err;
        }

  • file_operations的实现
static int debug_level_open(struct inode *inode, struct file *file)
{
        return single_open(file, debug_level_show, inode->i_private);
}

static ssize_t debug_level_write(struct file *file,
                                const char __user *buffer, size_t count, loff_t *ppos)
{
    unsigned int level = 0;
    struct seq_file *seq = file->private_data;
        struct spidev_data *spidev = seq->private;
        struct spi_device *spi = spidev->spi;

    level = simple_strtoul(buffer, NULL, 10);

        if (level < SPI_DEBUG_LEVEL_MIN)
                spidev->level = SPI_DEBUG_LEVEL_MIN;
        else if (level > SPI_DEBUG_LEVEL_MAX)
                spidev->level = SPI_DEBUG_LEVEL_MAX;
        else
                spidev->level = level;

        dev_info(&spi->dev, "debug_level = %d\n", spidev->level);

    return count;
}

static struct file_operations debug_level_ops = {
        .owner   = THIS_MODULE,
        .open    = debug_level_open,
        .read    = seq_read,
        .write   = debug_level_write,
        .llseek  = seq_lseek,
        .release = single_release,
};         

工作队列的实现:

  • 初始化一个工作队列,包括了实现函数.
      for (i = 0; i < WORK_COUNT; i++)
                INIT_WORK(&spidev->work[i], rx_assemble_work);
  • 将消息放入到工作队列中
      if (!queue_work(spidev->work_queue, &spidev->work[index++]))                              
                dev_err(&spidev->spi->dev, "queue_work failed index = %d\n", index);

        index %= WORK_COUNT;

  • 空闲时间调用工作队列
static void rx_assemble_work(struct work_struct *work)

你可能感兴趣的:(嵌入式,驱动,linux)