linux mailbox模型

一.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中

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值