内核mailbox

只罗列增加取走消息:

static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
{
    int idx;
    unsigned long flags;

    spin_lock_irqsave(&chan->lock, flags);

    /* See if there is any space left */
    if (chan->msg_count == MBOX_TX_QUEUE_LEN) {
        spin_unlock_irqrestore(&chan->lock, flags);
        return -ENOBUFS;
    }

    idx = chan->msg_free;
    chan->msg_data[idx] = mssg;
    chan->msg_count++;

    if (idx == MBOX_TX_QUEUE_LEN - 1)
        chan->msg_free = 0;
    else
        chan->msg_free++;

    spin_unlock_irqrestore(&chan->lock, flags);

    return idx;
}

static void msg_submit(struct mbox_chan *chan)
{
    unsigned count, idx;
    unsigned long flags;
    void *data;
    int err;

    spin_lock_irqsave(&chan->lock, flags);

    if (!chan->msg_count || chan->active_req)
        goto exit;

    count = chan->msg_count;
    idx = chan->msg_free;
    if (idx >= count)
        idx -= count;
    else
        idx += MBOX_TX_QUEUE_LEN - count;

    data = chan->msg_data[idx];

    /* Try to submit a message to the MBOX controller */
    err = chan->mbox->ops->send_data(chan, data);
    if (!err) {
        chan->active_req = data;
        chan->msg_count--;
    }
exit:
    spin_unlock_irqrestore(&chan->lock, flags);
}

 

转载于:https://www.cnblogs.com/vedic/p/10773939.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值