schedule_delayed_work

目的是解决spdif播放音频前800ms音频不出的问题。但是spdif信号锁定很差音响就会丢失前面的音频

diff --git a/soc/x2000/spdif/spdif_dma.c b/soc/x2000/spdif/spdif_dma.c
index cc923da..936ff4c 100644
--- a/soc/x2000/spdif/spdif_dma.c
+++ b/soc/x2000/spdif/spdif_dma.c
@@ -13,6 +13,7 @@
 #include <linux/dmaengine.h>
 #include <linux/hrtimer.h>
 #include <linux/err.h>
+#include <linux/workqueue.h>
 
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -64,8 +65,11 @@ struct spdif_dma_data {
     int period_ns;
     unsigned char hrtimer_state;
     struct hrtimer hrtimer;
+    struct delayed_work delayed_work;
 };
 
+DEFINE_SPINLOCK(spdif_dma_lock);
+
 static inline void *m_dma_alloc_coherent(int size)
 {
     dma_addr_t dma_handle;
@@ -98,10 +102,13 @@ static enum hrtimer_restart spdif_hrtimer_callback(struct hrtimer *hrtimer)
     return HRTIMER_RESTART;
 }
 
+static void spdif_dma_start(struct work_struct *work);
+
 static int spdif_dma_pcm_open(struct snd_pcm_substream *substream)
 {
     struct snd_pcm_runtime *runtime = substream->runtime;
     struct spdif_dma_data *spdif_dma;
+    printk("%s %d\n",__func__,__LINE__);
 
     int ret = snd_soc_set_runtime_hwparams(substream, &spdif_pcm_hardware);
     if (ret) {
@@ -134,6 +141,7 @@ static int spdif_dma_pcm_open(struct snd_pcm_substream *substream)
     hrtimer_init(&spdif_dma->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
     spdif_dma->hrtimer.function = spdif_hrtimer_callback;
     spdif_dma->substream = substream;
+    INIT_DELAYED_WORK(&spdif_dma->delayed_work, spdif_dma_start);
 
     runtime->private_data = spdif_dma;
 
@@ -321,24 +329,37 @@ static int spdif_dma_pcm_hw_free(struct snd_pcm_substream *substream)
     return 0;
 }
 
+static void spdif_dma_start(struct work_struct *work)
+{
+    printk("%s %d\n",__func__,__LINE__);
+    unsigned long flags;
+    spin_lock_irqsave(&spdif_dma_lock, flags);
+    struct delayed_work *delayed_work = container_of(work, struct delayed_work, work);
+    struct spdif_dma_data *spdif_dma = container_of(delayed_work, struct spdif_dma_data, delayed_work);
+    audio_dma_start(spdif_dma->dma_dev, spdif_dma->dma_desc);
+    if (spdif_dma->hrtimer_state == State_idle) {
+        hrtimer_forward_now(&spdif_dma->hrtimer,
+                    ns_to_ktime(spdif_dma->period_ns));
+        hrtimer_start_expires(&spdif_dma->hrtimer, HRTIMER_MODE_ABS);
+    }
+
+    spdif_dma->hrtimer_state = State_running;
+    spin_unlock_irqrestore(&spdif_dma_lock, flags);
+}
+
 static int spdif_dma_trigger(struct snd_pcm_substream *substream, int cmd)
 {
     struct snd_pcm_runtime *runtime = substream->runtime;
     struct spdif_dma_data *spdif_dma = runtime->private_data;
     int ret = 0;
+    printk("%s %d\n",__func__,__LINE__);
 
     switch (cmd) {
     case SNDRV_PCM_TRIGGER_START:
     case SNDRV_PCM_TRIGGER_RESUME:
     case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-        audio_dma_start(spdif_dma->dma_dev, spdif_dma->dma_desc);
-        if (spdif_dma->hrtimer_state == State_idle) {
-            hrtimer_forward_now(&spdif_dma->hrtimer,
-                        ns_to_ktime(spdif_dma->period_ns));
-            hrtimer_start_expires(&spdif_dma->hrtimer, HRTIMER_MODE_ABS);
-        }
-
-        spdif_dma->hrtimer_state = State_running;
+        schedule_delayed_work(&spdif_dma->delayed_work, msecs_to_jiffies(500));
+        printk("%s %d\n",__func__,__LINE__);
         break;
     case SNDRV_PCM_TRIGGER_STOP:
     case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -350,10 +371,10 @@ static int spdif_dma_trigger(struct snd_pcm_substream *substream, int cmd)
         ret = -EINVAL;
         break;
     }
-
     return ret;
 }
 
+
 static int debug = 0;
 module_param(debug, int, 0644);

schedule_delayed_work使用相关推荐

  1. schedule_delayed_work()

    工作队列的作用就是把工作推后,交由一个内核线程去执行,更直接的说就是如果您写了一个函数,而您现在不想马上执行它,您想在将来某个时刻去执行它,那您用工作队列准没错.您大概会想到中断也是这样,提供一个中断 ...

  2. schedule_delayed_work()用法

    工作队列 在Linux内核中,对下半部(或者说推后执行的工作)的处理方式有好几种,包括BH(bottom half),软中断,Tasklets和工作队列等等.在2.6内核中,大名鼎鼎的BH处理被废除, ...

  3. schedule_delayed_work 用法详解

    1 声明一个delayed_work DECLARE_DELAYED_WORK(work,work_fun); 2 schedule delayed_work,需要指明延迟时间. schedule_d ...

  4. linux 工作队列之schedule_delayed_work用法

    文章目录 前言 一.定义自己的delayed_work 二.定义在工作队列中被调用的函数 1.在工作队列中被调用的函数原型 2.定义在工作队列中被调用的自己实现的函数 三.初始化数据结构 四.提交任务 ...

  5. I.MX6 bq27441 driver hacking

    /************************************************************************** I.MX6 bq27441 driver hac ...

  6. 【转】android电池(四):电池 电量计(MAX17040)驱动分析篇

    关键词:android 电池  电量计  MAX17040 任务初始化宏 power_supply 平台信息: 内核:linux2.6/linux3.0 系统:android/android4.0  ...

  7. 【linux kernel】 中断处理-中断下半部【转】

    转自:http://www.cnblogs.com/embedded-tzp/p/4453987.html 欢迎转载,转载时需保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地 ...

  8. 下半部机制之工作队列

    工作队列是一种不同于软中断和微线程的一种下半部延迟机制.工作队列将工作延迟到一个内核线程中执行,它运行在进程上下文中,它是可调度的,并且可以休眠.通常,如果延迟的工作中需要休眠,就使用工作队列,否则使 ...

  9. linux 中断机制的处理过程

    一.中断的概念 中断是指在CPU正常运行期间,由于内外部事件或由程序预先安排的事件引起的CPU暂时停止正在运行的程序,转而为该内部或外部事件或预先安排的事件服务的程序中去,服务完毕后再返回去继续运行被 ...

最新文章

  1. 对 makefile 中 .PRECIOUS 的学习
  2. java 安装多版本_一台电脑安装多个版本的jdk
  3. dbms_java_java实现DBMS
  4. C语言高级技术之--游戏属性修改器(背景故事)
  5. java 泛型应用,通用返回类,泛型方法,泛型静态方法
  6. [转载]url带中文参数显示乱码的问题
  7. Eclips下运行helloworld,弹出手机模拟器上什么也没有
  8. Eclipse中对一个项目进行复制粘贴为一个新项目
  9. Jquery自定义$的名称(自定义变量)
  10. 管理感悟:出了问题先怀疑自己
  11. 【bat批处理脚本命令】bat命令接收用户输入的内容(保姆级图文+实现代码)
  12. 卷积神经网络(CNN)详解
  13. 外贸常用术语_常用外贸术语
  14. 判断串口通信是否正常c语言,串口通信测试方法
  15. acme.sh申请Let‘s encrypt泛域名证书Docker化部署
  16. matlab中输入数学符号,matlab中特殊符号的写法
  17. 第13期《凤凰涅槃,浴火重生!》2月刊
  18. Android开发 系统服务,android 系统服务 开发
  19. springboot+jsp健身房教练课程预约管理系统
  20. IPWorks IPC .NET 2022.0.85 Crack

热门文章

  1. 阿里云轻量应用服务器最新价格表2023版(2核8G/4核8G/4核16G/8核16G/8核32G)
  2. 计算机基础知识之二进制乘法
  3. 2022门座式起重机司机理论题库模拟考试平台操作
  4. 福大软工1816 · 团队现场编程实战(抽奖系统)之 拖鞋旅游队
  5. makefile中wildcard notdir patsubst的简单介绍
  6. 你真的挺有文学才能的,你应该写作
  7. android a标签无法跳转,a标签不能在手机端正常跳转?来看看是不是这么设置的...
  8. iPhone手机5个不可多得的APP,让你的苹果手机更加有逼格
  9. mysql中condition的用法,mybatis的condition使用
  10. json-server常用自定义路由和简单配置