mailbox資料傳送和接收的過程

2021-08-08 11:32:59 字數 1750 閱讀 2198

我們知道在client 在通過mbox_send_message給controller傳送資料的時候必須指定channel。例如下面的code

dc_sync->mbox =

(&dc_sync->cl, 0);

/* populate data packet */

/* sp.abc = 123; etc */

/* send message to remote in blocking mode */

mbox_send_message(dc_sync->mbox, &sp);

/* at this point 'sp' has been sent */

目前kernel提供了兩種方法得到mailbox的channel

struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,const char *name);

struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index);

使用完成後呼叫mbox_free_channel 釋放channel,這樣別人就可以繼續使用這個channel

void mbox_free_channel(struct mbox_chan *chan); /* may sleep */

其中mbox_request_channel_byname是mbox_request_channel的乙個包裝。所以這裡直接看看mbox_request_channel

struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)

}以之前的arm_mhu.c 中定義的mbox_chan_ops為例

static const struct mbox_chan_ops mhu_ops = ;

static int mhu_startup(struct mbox_chan *chan)

return 0;

}這個中斷函式如下:

當client 給controller 通過mbox_send_message傳送資料後,arm_mhu 會產生乙個中斷給cotroller。

static irqreturn_t mhu_rx_interrupt(int irq, void *p)

void mbox_chan_received_data(struct mbox_chan *chan, void *mssg)

controller接收資料的flow 清楚了,再看看client是如何呼叫mbox_send_message 傳送資料的

mbox_send_message->msg_submit

if (chan->cl->tx_prepare)

chan->cl->tx_prepare(chan->cl, data);

/* try to submit a message to the mbox controller */

err = chan->mbox->ops->send_data(chan, data);

if (!err)

最終還是呼叫controll而的send_data 傳送資料,本例controller的send_data函式為mhu_send_data

static int mhu_send_data(struct mbox_chan *chan, void *data)

socket資料的接收和傳送

linux 不區分套接字檔案和普通檔案,使用 write 可以向套接字中寫入資料,使用 read 可以從套接字中讀取資料。前面我們說過,兩台計算機之間的通訊相當於兩個套接字之間的通訊,在伺服器端用 write 向套接字寫入資料,客戶端就能收到,然後再使用 read 從套接字中讀取出來,就完成了一次通...

LWIP 資料接收和傳送

在znyq的sdk例程中,main中主迴圈傳送接收,其中接收為 xemacif input echo netif 查詢xemacit input 函式裡 在echo.c裡有receive的處理函式recv callback 資料接收 tcp recved tpcb,p len 其中的tcp recv...

socket傳送和接收資料

1 sendbuf sendtext sendstream 幾乎所有的通訊控制項都會提供上面的3個方法。首先看看sendbuf function tcustomwinsocket.sendbuf var buf count integer integer varerrorcode integer b...