linux mailbox模型【转】

摘要:
转移自:https://www.cnblogs.com/chencesc/p/8655400.html1、在设备树中写入方法二。邮箱框架(driver/mailbox/mailbox.c)structmbox_控制器{structdevice*dev;//当探测由特定邮箱驱动时,将赋值dev=&pdev-˃devconststructmbox.chan_o

转自:https://www.cnblogs.com/chencesc/p/8655400.html

一.device tree中的写法

二. mailbox框架 (driver/mailbox/mailbox.c)

复制代码
struct mbox_controller {
    struct device *dev;                                      // 特定mailbox驱动probe时赋值 dev = &pdev->dev
    const struct mbox_chan_ops *ops;                         // mailbox channel需要实现的功能函数
    struct mbox_chan *chans;                                 // mailbox channel指针数组
    int num_chans;                                           // mailbox channel个数
    bool txdone_irq;                        // 通过中断来判断上次传输是否完成
    bool txdone_poll;                        // 通过poll机制来判断上次传输是否完成
    unsigned txpoll_period;                                  // POLL 周期, 以ms计
    struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox,
                      const struct of_phandle_args *sp);     // 获取特定channel的回调函数
    /* Internal to API */
    struct hrtimer poll_hrt;
    struct list_head node;
};

struct mbox_chan { struct mbox_controller *mbox; // contronller指针 unsigned txdone_method; struct mbox_client *cl; // client指针 struct completion tx_complete; // void *active_req; unsigned msg_count, msg_free; void *msg_data[MBOX_TX_QUEUE_LEN]; spinlock_t lock; /* Serialise access to the channel */ void *con_priv; };

struct mbox_chan_ops { int (*send_data)(struct mbox_chan *chan, void *data); // 发送数据(需要last data sent) int (*startup)(struct mbox_chan *chan); // 特定mailbox 启动 void (*shutdown)(struct mbox_chan *chan); // 特定mailbox 关闭 bool (*last_tx_done)(struct mbox_chan *chan); // 如果TXDONE_BY_POLL 该回调会被使用 bool (*peek_data)(struct mbox_chan *chan); // 检测是否有数据 };

struct mbox_client { struct device *dev; // client 设备 bool tx_block; // block until last data is all transmitted unsigned long tx_tout; // max block period for timeout bool knows_txdone; // txdone 回调,如果controller已经有txdone,则该配置无效 void (*rx_callback)(struct mbox_client *cl, void *mssg); // 收到数据 void (*tx_prepare)(struct mbox_client *cl, void *mssg);    // 准备数据 void (*tx_done)(struct mbox_client *cl, void *mssg, int r); // 检测txdone };
复制代码

三. mailbox client 流程

通过mbox_request_channel_byname 根据"mbox-names"申请channel

创建mbox设备

通过mbox设备的write read 函数访问controller

其中write 通过调用mbox_send_message,

    add_to_rbuf拷贝msg到chan->msg_data[MAX = 20]

    msg_submit读取msg_data[idx],放到tx_prepare中,调用具体驱动的send message写寄存器

其中read 通过irq驱动

    irq读取寄存器得到消息,调用mailbox.c中的mbox_chan_received_data,再调用client的rx_callback将得到的数据放到client->rx_buffer中

四. mailbox driver流程

配置controller属性:

  申请chan,配置chan个数

  配置of_xlate回调,获取chan

  配置chan_ops

  配置txdone判断方式

通过mailbox_controller_register 注册controller

五. 总结

driver 通过mbox_controller_register 注册controller

client 通过mbox_request_channel调用driver->startup

client 通过mbox_send_message调用driver->send_data,并等待txdone

driver 收到remote的中断读取数据调用mbox_chan_received_data将数据放到 client->rx_buffer中

免责声明:文章转载自《linux mailbox模型【转】》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ios开发--常用宏定义(部分转)K最短路问题(单源点最短路径+A*算法)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Vue中进行断点调试的两种方式(使用外部浏览器和VsCode Debug for Chrome 插件)

但是在Vue中如果想要进行调试时,如果是在js中调试的话,可以直接添加一个debugger,然后在浏览器中打开检查进行断点调试。比如:在Vue页面中,点击搜索按钮时搜索会触发handleQuery方法resetQuery(){this.resetForm;this.handleQuery();},其中调用了请求查询数据的方法handleQuery(){thi...

C#使用FFmpeg的总结

上一篇文章提到FFmpeg解决了项目中的视频和语音问题,并表示C#和FFmpeg必须提到两个类库。最后,选择了FFmpeg.AutoGen,它可以通过API更好地控制灵活性,更好地满足您的个人需求。6、 C#FFmpeg使用SDL2实现rtmp播放器7。C#FFmpeg本地mp3,mp4文件播放8。C#FFmpeg在保存到本地文件时播放rtmp视频。...

PHP是怎么运行的

严格来说,与PHP相关的过程不需要手动启动。它们与Apache启动一起运行。当然,如果需要重新启动PHP服务,可以手动重新启动PHP。最后,它被移交给PHP内核的ZendEngine进行顺序执行。PHP在开始执行后将经历两个主要阶段:处理请求之前的开始阶段和请求之后的结束阶段。PHP的结束阶段分为两个阶段:禁用模块和关闭模块。...

.NET5 ABP框架(一)

授权-ABP可以以声明的方式检查权限。如果发生异常,ABP将自动记录并向客户机返回适当的结果。默认情况下,ABP使用Log4Net写入日志。当然,我们也可以通过修改配置来使用其他日志框架。除了本示例中显示的ABP的优点之外,ABP还提供了一个健壮的基础架构和应用程序模型。...

ArchLinux安装英伟达显卡驱动

Optimus manager qt Install novausudopacman-Sxf86-video novau右键单击导航栏上的Intel图标,选择列表中的设置功能,单击左侧的Optimus,然后在右侧窗口中选择nouveau作为切换方法。右键单击导航栏上的Intel图标以选择要使用的图形卡类型。在我选择Nvidia显卡后,您需要注销并再次登录才能...