想做机械加工和橡胶生意怎么做网站,常州高端网站制作公司排名,电商网站建设费用预算,如何做网站系统上一篇文章我们将了嵌入式系统注册声卡的过程#xff1a;https://blog.csdn.net/qq_37659294/article/details/104748747
这篇文章我们以打开一个声卡的播放节点为例#xff0c;讲解一下在APP调用open时#xff0c;最终会如何调用到硬件相关的函数。 在上一篇文章最后我们说…上一篇文章我们将了嵌入式系统注册声卡的过程https://blog.csdn.net/qq_37659294/article/details/104748747
这篇文章我们以打开一个声卡的播放节点为例讲解一下在APP调用open时最终会如何调用到硬件相关的函数。 在上一篇文章最后我们说过当应用程序open设备文件/dev/snd/pcmCxDxpcontrolC0和pcmCxDxc也类似这里我们以pcmCxDxp为例时会进入snd_fops的open回调函数该open函数以次设备号为索引从snd_minors全局数组中取出当初注册conrol、pcm设备时填充的snd_minor结构体然后从snd_minor结构中取出control、pcm设备的f_ops并且把file-f_op替换为pcm设备的f_ops紧接着调用pcm设备的f_ops-open()也就是snd_pcm_f_ops[0]的snd_pcm_playback_open。后面我们根据文件句柄操作这个设备节点时就都是调用这个f_ops里的函数。
static const struct file_operations snd_fops
{.owner THIS_MODULE,.open snd_open,.llseek noop_llseek,
};static int snd_open(struct inode *inode, struct file *file)
{unsigned int minor iminor(inode);struct snd_minor *mptr NULL;const struct file_operations *old_fops;int err 0;if (minor ARRAY_SIZE(snd_minors))return -ENODEV;mutex_lock(sound_mutex);mptr snd_minors[minor]; //根据次设备号找到对应的snd_minor结构体if (mptr NULL) {mptr autoload_device(minor);if (!mptr) {mutex_unlock(sound_mutex);return -ENODEV;}}old_fops file-f_op;file-f_op fops_get(mptr-f_ops); //把file-f_op替换为pcm设备的f_ops if (file-f_op NULL) {file-f_op old_fops;err -ENODEV;}mutex_unlock(sound_mutex);if (err 0)return err;if (file-f_op-open) { //调用pcm设备的f_ops-open()err file-f_op-open(inode, file);if (err) {fops_put(file-f_op);file-f_op fops_get(old_fops);}}fops_put(old_fops);return err;
}真正和硬件相关的函数是我们在platform和codec部分放入对应链表且后来又在machine部分根据dai_link实例化的那四个结构体s3c24xx_i2s_dai、samsung_asoc_platform、uda134x_dai、soc_codec_dev_uda134x里的函数所以snd_pcm_f_ops[0]的snd_pcm_playback_open函数又会最终调用到这些硬件相关的操作下面是调用的过程
2. /dev/snd/pcmC0D0p 对应的file_operations是snd_pcm_f_ops[0]
open : snd_pcm_playback_opensnd_pcm_opensnd_pcm_open_filestruct snd_pcm_substream *substream;snd_pcm_open_substreamsnd_pcm_attach_substreamsubstream-private_data pcm-private_data;err snd_pcm_hw_constraints_init(substream);snd_mask_anysnd_interval_any......err substream-ops-open(substream) // substream-ops : snd_pcm_ops结构体soc_pcm_open依次调用cpu_dai, dma, codec_dai, machine的open或startup函数如uda134x_startup、dma_openstruct snd_soc_pcm_runtime *rtd substream-private_data;struct snd_soc_dai *cpu_dai rtd-cpu_dai;ret cpu_dai-driver-ops-startup(substream, cpu_dai);...
①在《ASOC注册过程》这篇文章的第⑦点中我们提到一点soc_new_pcm函数里有一个(snd_pcm)pcm-private_data rtd;后面我们APP调用程序的时候会从pcm-private_data取出rtdrtd里有对应我们开发板的cpu_dai、codec_dai...。
现在在snd_pcm_attach_substream函数里我们就把这个rtd取出来放到了substream-private_data。
②在《ASOC注册过程》这篇文章的第⑥点内核给card-rtd-ops结构体里的函数指针赋值并把card-rtd-ops的地址赋给substream-ops。
现在我们调用substream-ops-open(substream)也就是调用snd_pcm_ops结构体里的soc_pcm_open函数。
③在前面第①点中我们已经把rtdrtd里有对应我们开发板的cpu_dai、codec_dai...取出来放到了substream-private_data在soc_pcm_open函数里我们通过substream-private_data调用硬件相关的函数如cpu_dai, dma, codec_dai的open或startup函数。