IPC

概述

IPC 为核间通信模块,提供不同内核间消息收发功能。

功能特性

IPC 基础核间通信,提供以下功能:

  • 基础核间消息,使用 soft irq + share memory。

  • ipc mailbox 地址申请。

  • share memory malloc。

  • share memory free。

  • 所有 ipc 均为单向发送,ipc 本身不支持同步方式。

资源依赖

  • 总开启核数量(使用 ipc 的核)。

  • share memory 的管理 core(Master core)。

用法流程

  • master core 初始化 ipc 及 in mailbox(根据开启的 core 数量)。

  • 注册入 mailbox 地址区域, 将控制区域地址传参到其他 core。

  • 其他 core 启动后,检查 master core 是否有 in box,如有,说明已开启 ipc 功能。

  • 向 master core 发送 ipc,申请 mailbox。

  • master 根据开启 core 数量申请 share memory 空间,并将其挂载至 ipc 控制区域中。

  • 如有多个 core,则重复 3-5 流程。

参考示例

/examples/ipc_demo

API 介绍

Defines

CONFIG_IPC_MAILBOX_SIZE

Typedefs

typedef struct mailbox wq_ipc_mailbox_t

Mailbox heaader.

typedef struct ipc_ctrl wq_ipc_ctrl_t

IPC mailbox control. Record the mailbox addresses of all cores.

typedef WQ_RET (*wq_ipc_handler)(WQ_CORES src_core, uint16_t src_port, void *data, size_t len)
typedef void (*wq_ipc_search_done_cb)(const char *name, WQ_CORES core, uint16_t port)

Functions

wq_ipc_ctrl_t *wq_ipc_get_ctrl(void)
WQ_RET wq_ipc_send_msg(WQ_CORES dst_core, uint16_t dst_port, uint16_t src_port, const void *payload, uint16_t len)

Main method for send ipc message to other core.

参数:
  • dst_core -- [in] Destination core that message send to.

  • dst_port -- [in] Destination port at destination core.

  • src_port -- [in] Source port that initiate this transfer, the port will give to the destination port handler Can be use to send response message.

  • payload -- [in] Message body.

  • len -- [in] message body length.

返回:

WQ_RET Send state::WQ_RET

uint16_t wq_ipc_register_port(const char *name, wq_ipc_handler handler)

Register a port on current core, if a message send to this port, handler will be invoke.

参数:
  • name -- [in] Port name that could be search by other core.

  • handler -- [in] If reveice a message on this port, handler will be invoke.

返回:

uint16_t Port num.

uint16_t wq_ipc_register_local_port(wq_ipc_handler handler)

Register a port on current core, if a message send to this port, handler will be invoke.

Same like

参见

wq_ipc_register_port but the port could only use at local cpu to receive ipc message, and can't be searched by other core.

参数:

handler -- [in] If reveice a message on this port, handler will be invoke.

返回:

uint16_t Port num.

WQ_RET wq_ipc_search_port(const char *name, WQ_CORES *core, uint16_t *port, uint32_t timeout)

To search special port by name.

参见

WQ_RET

参数:
  • name -- [in] Port name str, 1 - 16 bytes, must end with '\0'. If the length exceeds 16, only the first 15 are valid.

  • core -- [out] The core that have a port using same name.

  • port -- [out] The port using same this name.

  • timeout -- [in] The time in millisecond to wait for search done.

返回:

WQ_RET search result

WQ_RET wq_ipc_search_port_with_cb(const char *name, wq_ipc_search_done_cb cb)

To search special port by name with callback.

参见

WQ_RET

备注

This API can not be called in ISR context or CRITICAL context

参数:
  • name -- [in] Port name str, 1 - 16 bytes, must end with '\0'. If the length exceeds 16, only the first 15 are valid.

  • cb -- [in] Search done callback

返回:

WQ_RET search result

WQ_RET wq_ipc_init(wq_ipc_ctrl_t *ctrl)

Initialize the ipc module.

参数:

ctrl -- [in] mailbox ctrl pointer for slave.

返回:

WQ_RET result::WQ_RET

struct mailbox
#include <ipc.h>

Mailbox heaader.

Public Members

uint32_t size

size of the mailbox

uint16_t w

write index

uint16_t r

read index

uint8_t data[]

ring data buffer

struct ipc_ctrl
#include <ipc.h>

IPC mailbox control. Record the mailbox addresses of all cores.

Public Members

uint32_t magic

Magic for valid check

wq_ipc_mailbox_t *mailbox[WQ_CORES_EN_MAX][WQ_CORES_EN_MAX - 1]

mailbox addresses

struct list_head ipc_named_port_list