7.5.9 IPC 使用指南
此章节着重说明 MCU 侧的相关使用说明,更多的 IPC 的原理和使用可以查阅 IPC模块介绍 章节。
使用限制说明
- 在使用 Ipc_MDMA_SendMsg 接口发送数据时, 需要保证数据 buffer 地址16字节对齐。
- 发送功能通过轮询方式查看 dma 状态,因此使用发送功能前必须关闭 DMA 中断(释放的代码默认已关闭);使用接收功能时,DMA 中断和 IPC 中断配置成相同的优先级,避免相互打断。
- Ipc Mdma 发送通道只有两个,单核或多核多任务发送时,建议使用自旋锁或者关中断方式控制 DMA 资源抢占。
- IPC 多核发送或接收基于 Instance 分配,不支持基于 Channel 分配。
- IPC 初始化需要在 DMA 模块初始化后再调用。
- MCU IPC 配置需要核对端 IPC 配置保持一致。包括 Instance 控制段与 data 段地址,Channel 的数量与 ID,Buffer 数据,Buffer 大小,两端配置不一致会导致 IPC 通信失败。
- Instance cfg 中的 receive_coreid 配置,需要明确该 Instance 是工作在 MCU0还是 MCU1,工作在 MCU1即配置为 Ipc_Receive_Core1,该项配置错误会导致 IPC 通信失败。
- Instance 工作在哪个 MCU 上,IPC 中断即在哪个 MCU 上进行使能。如果在多核上都使能,可能出现中断被其他核抢占导致 IPC 通信失败。
IPC 配置相关
一个 IPC 实例有一个或多个 channel,同一个实例共享一个中断,因此一个 IPC 只能在 MCU0或 MCU1其中一个系统上使能。
当 MCU1使用 IPC 时,需要配置两部分内容。
- 需要配置回调函数,作用是 IPC 接收到 notify 信号时触发中断进入回调函数进行处理。当然客户可自行定制 当传输数据错误时的回调函数。下文以 Instance0为例介绍。
static Ipc_ChannelConfigType Ipc_ShmInstance0CfgChannel[8] = {
{
.ChannelId = 0,
.ChannelData = {
.NumPools = 1,
.PoolCfg = Ipc_ShmIpcInstance_0CfgIpcChannel_0BufPool,
.RxCallback = IpcTp_InsCan_RxCallback,
.RxCallbackArg = (NULL_PTR),
.TxErrCallback = DefaultTxErrCallback,
.TxErrCallbackArg = (NULL_PTR),
},
},
......
};
- 设置 receive_coreid。如果是在 MCU1上,则需要"receive_coreid=Ipc_Receive_Core1"。同时需要保障 MCU0关于 IPC 设置相同。
- MCU0文件地址:/mcu/Config/McalCdd/gen_s100_sip_B/Ipc/src/Ipc_Cfg.c
- MCU1文件地址:/mcu/Config/McalCdd/gen_s100_sip_B_mcu1/Ipc/src/Ipc_Cfg.c
Ipc_InstanceConfigType Ipc_ShmCfgInstances0 = {
.Ipc_InstanceId = 0U,
.Ipc_ChannelNum = 8U,
.LocalCtlAddr = 0xcdd9e00,
.RemoteCtlAddr = 0xcdd9400,
.CtlShmSize = 0xa00,
.LocalDataAddr = 0xb4080000,
.RemoteDataAddr = 0xb4000000,
.DataShmSize = 0x80000,
.SendDmaChanIdx = 0xffU,
.Async = (TRUE),
.HwInfo = {
.Ipc_HwId = CPU_IPC0,/**< the id of the Hardware */
.RecvIrqUsed = (TRUE),/**< Whether to use Recv interrupt */
.SendMboxId = 0,/**< the mailbox id */
.RecvMboxId = 16,/**< the mailbox id */
.RemoteIrq = 16,
.LocalIrq = 0,
.UseMDMA = (TRUE),
},
.Ipc_ChannelConfigPtr = Ipc_ShmInstance0CfgChannel,
.receive_coreid = Ipc_Receive_Core1,
};
IPC 使用情况
| MCU IPC Instance | Using Module | Interrupt Func | Opposite End |
|---|---|---|---|
| Ipc_ShmCfgInstances0~8 | User | ISR(Ipc_CpuIpc0Ch0Isr): Ipc_Driver_CpuIpc0ChxIsr() (x=0..8) | Acore instance0~8 |
| Ipc_ShmCfgInstances0/4 | canhal | — | Acore instance0/4 |
| Ipc_ShmCfgInstances5 | 外置 RTC | — | Acore instance5 |
| Ipc_ShmCfgInstances7 | ipcbox | — | Acore instance7 |
| Ipc_ShmCfgInstances8 | mcu1 boot | — | Acore instance8 |
| Ipc_PrivShmCfgInstance0 | Crypto | ISR(Ipc_HsmIpc1Ch4Isr): Ipc_Driver_HSMIpc1Ch4Isr() | HSM |
| Ipc_PrivShmCfgInstance1 | HSM DIAG | ISR(Ipc_HsmIpc1Ch5Isr): Ipc_Driver_HSMIpc1Ch5Isr() | HSM |
| Ipc_PrivShmCfgInstance3 | TimeSync | ISR(Ipc_CpuIpc0Ch10Isr): Ipc_Driver_CpuIpc0Ch10Isr() | Acore Instance10 |
| Ipc_PrivShmCfgInstance4 | Ota | ISR(Ipc_CpuIpc0Ch11Isr): Ipc_Driver_CpuIpc0Ch11Isr() | Acore Instance11 |
| Ipc_PrivShmCfgInstance5 | QGA | ISR(Ipc_CpuIpc0Ch12Isr): Ipc_Driver_CpuIpc0Ch12Isr() | Acore Instance12 |
| Housekeeping | Housekeeping | ISR(Ipc_CpuIpc0Ch15Isr): Housekeeping_IrqHandler() | Acore Housekeeping |
| scmi | scmi | ISR(Ipc_CpuIpc1Ch0Isr): ScmiIpc_Irq0Handler() ISR(Ipc_CpuIpc1Ch1Isr): ScmiIpc_Irq1Handler() ISR(Ipc_CpuIpc1Ch2Isr): ScmiIpc_Irq2Handler() | Acore scmi |
| MCU IPC Instance | Using Module | Interrupt Func | Opposite End |
|---|---|---|---|
| Ipc_ShmCfgInstances0~7 | User | ISR(Ipc0_ChxIsr): Ipc_Driver_MCUIpc0ChxIsr() (x = 0..7) | Acore instance0~7 |
| Ipc_ShmCfgInstances0 / 4 | canhal | — | Acore instance0/4 |
| Ipc_ShmCfgInstances5 | 外置 RTC | — | Acore instance5 |
| Ipc_ShmCfgInstances7 | ipcbox | — | Acore instance7 |
| Ipc_ShmCfgInstances8~15 | User | ISR(Ipc1_ChxIsr): Ipc_Driver_MCUIpc1ChxIsr() (x = 0..7) | Acore instance8~15 (except 8 & 10) |
| Ipc_ShmCfgInstance8 | mcu1 boot | — | Acore instance8 |
| Ipc_ShmCfgInstance10 | timesync | — | Acore instance10 |
| Ipc_PrivShmCfgInstance0 | Crypto | ISR(Ipc_HsmIpc3Ch4Isr): Ipc_Driver_HSMIpc3Ch4Isr() | HSM |
| Ipc_PrivShmCfgInstance1 | HSM Diag | ISR(Ipc_HsmIpc3Ch5Isr): Ipc_Driver_HSMIpc3Ch5Isr() | HSM |
| Ipc_PrivShmCfgInstance2 | Ota | ISR(Ipc0_Ch8Isr): Ipc_Driver_MCUIpc0Ch8Isr() | Acore instance50 |
| Ipc_PrivShmCfgInstance3 | QGA | ISR(Ipc0_Ch9Isr): Ipc_Driver_MCUIpc0Ch9Isr() | Acore instance51 |
| Housekeeping | Housekeeping | ISR(Ipc2_Ch3Isr): Housekeeping_IrqHandler() | Acore Housekeeping |
应用 sample
提示
所运行的应用程序 sample 均运行于 Acore 侧,并与 MCU1进行通信,因此在使用前需运行 MCU1的系统.
运行方式: MCU1启动步骤