核间通信(IPC)

简介

芯片内集成了多个处理器。核间通信(IPC)硬件在每两个处理器之间建立专用的通信通道。

IPC 为每个处理器提供一组寄存器,并通过中断实现处理器间通信。此外,每个处理器可以独立屏蔽中断以支持轮询模式操作。

IPC 通信数据必须位于公共内存中,该内存不属于 IPC 模块。

特性

RTL8721Dx:
  • 每两个处理器之间 {{IC_PARAM_IPC_CH}} 组 TRx 通道

  • 独立的收发通道

  • 通道独立的中断控制

  • 支持 Rx 通道满中断

  • 支持 Tx 通道空中断

  • 共享内存

框图

IPC 提供了每两个处理器之间的简单通信机制。它可以使用共享 SRAM 向其他 CPU 传输信息。IPC 的系统框图如下所示。

../../_images/ipc_block_diagram.svg

每个处理器的 IPC 子模块结构是相同的。下图总结了 IPC_CPUm 的子模块结构。

../../_images/ipc_submodule.svg

在每两个处理器之间,一个处理器拥有 2 组通信通道,1 组用于通过写入 Tx 数据寄存器向另一个处理器发送数据,另一组用于通过读取 Rx 数据寄存器从另一个处理器接收数据。

除了数据寄存器外,还有中断相关的寄存器。

  • 中断状态寄存器(ISR)用于呈现当前通道 Tx 空或 Rx 满状态变化。

  • 中断屏蔽寄存器(IMR)用于使能 Tx 空或 Rx 满中断。

  • 中断清除寄存器(ICR)用于清除相应的中断状态。

下图展示了从 CPUn 到 CPUm 的消息传输。

../../_images/ipc_module_structure.svg

功能描述

信息收发

在每两个处理器之间,一个处理器有 2 组通道与另一个处理器进行通信。Tx 通道的通道索引与相应的 Rx 通道是一对一映射。

IPC 消息发送映射 显示了从 CPUn 到 CPUm 的 IPC 发送映射,IPC 消息接收映射 显示了接收数据后从 CPUm 到 CPUn 的 IPC 映射。

  • CPUn 的 REG_TX_DATA 供 CPUn 用于向 CPUm 发送数据,一旦向通道 x(x 可以是 0 ~ M,其中 M 表示最大通道索引)写入 1,CPUm 的 REG_RX_DATA 中的相应位将被设置。同时,CPUm 的 REG_ISR 中通道 x 的 Rx 满位将被设置。

  • 向 CPUm 的 REG_ISR 中的通道 x 写入 1 可清除通道 x 的 Rx 满中断,CPUn 的 REG_ISR 中相应的通道 x Tx 空中断位将自动设置。

../../_images/ipc_message_transmitting_mapping.svg

IPC 消息发送映射

../../_images/ipc_message_receive_mapping.svg

IPC 消息接收映射

无握手的 IPC

由于每个处理器都有 Rx 满和 Tx 空中断,这些功能可用于实现消息传输和握手。

无握手的 IPC 消息传输流程 显示了不等待接收方握手的 IPC 中断消息协议,发送端不等待接收端的确认信号。步骤总结在 无握手的 IPC 消息传输步骤 中。它以从 CPUn 到 CPUm 的消息传输为例。

../../_images/ipc_message_transmission_flow_without_handshake.svg

无握手的 IPC 消息传输流程

无握手的 IPC 消息传输步骤

步骤

描述

1

检查 CPUn IPC Tx 数据寄存器中通道 0 的 Tx 数据状态

2

CPUn 将数据写入公共内存

3

向 IPC Tx 数据寄存器中的空闲通道 0 写入 1

4

CPUn IPC Tx 数据寄存器写操作

  • 映射到 CPUm IPC Rx 数据寄存器

  • 清除 CPUn 中断状态寄存器中的 Tx 空中断位

  • 设置 CPUm 中断状态寄存器中的 Rx 满中断位

5

如果在 CPUm 中断屏蔽寄存器中使能了 Rx 满中断,将向 CPUm 生成 Rx 满中断请求。

6

检查 Rx 满通道后,CPUm 从相应的公共内存执行数据读取

7

完成中断处理后,CPUm 向 CPUm 中断状态寄存器写入 1 以清除 Rx 满中断

8

CPUm 中断状态寄存器写操作

  • 清除 CPUm 状态寄存器中的 Rx 满中断状态位

  • 设置 CPUn 状态寄存器中的 Tx 空中断状态位

9

自动清除 CPUm IPC Rx 数据寄存器和 CPUn IPC Tx 数据寄存器中的通道 0 位

有握手的 IPC

有握手的 IPC 消息传输流程 显示了等待接收方握手的 IPC 中断消息协议,发送端等待接收端的确认信号。步骤总结在 有握手的 IPC 消息传输步骤 中。它以从 CPUn 到 CPUm 的消息传输为例。

../../_images/ipc_message_transmission_flow_with_handshake.svg

有握手的 IPC 消息传输流程

有握手的 IPC 消息传输步骤

步骤

描述

1

检查 CPUn IPC Tx 数据寄存器中通道 0 的 Tx 数据状态

2

CPUn 将数据写入公共内存

3

向 IPC Tx 数据寄存器中的空闲通道 0 写入 1

4

CPUn IPC Tx 数据寄存器写操作

  • 映射到 CPUm IPC Rx 数据寄存器

  • 设置 CPUm 中断状态寄存器中的 Rx 满中断位

5

如果在 CPUm 中断屏蔽寄存器中使能了 Rx 满中断,将向 CPUm 生成 Rx 满中断请求。

6

检查 Rx 满通道后,CPUm 从相应的公共内存执行数据读取

7

完成中断处理后,CPUm 向 CPUm 中断状态寄存器写入 1 以清除 Rx 满中断

8

IPC 中断状态寄存器写操作

  • 清除 CPUm 状态寄存器中的 Rx 满中断状态位

  • 设置 CPUn 状态寄存器中的 Tx 空中断状态位

9

自动清除 CPUm IPC Rx 数据寄存器和 CPUn IPC Tx 数据寄存器中的通道 0 位

10

如果在 CPUn 中断屏蔽寄存器中使能了 Tx 空中断,CPUn 状态寄存器中 Tx 空位的设置将向 CPUn 生成 Tx 空中断

11

CPUn 向 CPUn 中断状态寄存器写入 1 以清除 Tx 空中断

硬件信号量

概览

硬件信号量用于互斥机制。它可以通过原子操作被核心访问。

传统上,软件使用信号量需要三个步骤:读取 -> 写入 -> 读取。

  1. CPU 的第一次读取操作是轮询当前信号量以检查它是否被占用。

  2. 如果该信号量是空闲的,CPU 将通过写入来竞争它。

  3. 最后的读取操作是检查 CPU 是否已经占用了该信号量,因为可能有多个 CPU 或线程同时写入以竞争同一个信号量。

上述原本由软件执行的流程现已交由硬件处理。下图说明了硬件信号量机制。

../../_images/ipc_hardware_semaphore_mechanism.svg
  • 地址映射负责将 N 位信号量状态映射到 N x 4 地址空间,其中 N 表示硬件信号量的总数。

  • 读取设置逻辑负责在接收到读取请求后确定要读取的信号量状态。如果相应的信号量寄存器为 0,读取设置逻辑将首先设置信号量寄存器,然后向读取请求返回 0。

  • 写入清除逻辑负责在接收到写入请求后将信号量的状态清除为 0。

  • 信号量寄存器有 N 位,寄存器中的每一位代表一个信号量。该寄存器可以直接读取,也可以通过地址映射寄存器读取/写入。

    • 如果通过地址映射寄存器读取信号量寄存器,一次只能读取 1bit 的状态,并且当该 bit 为 0 时会同步设置该位。

    • 如果直接读取信号量寄存器,读取不会改变信号量的状态,并且可以一次读取所有 N 位。

RTL8721Dx:

N 等于 {{IC_PARAM_IPC_SEMA}}

地址映射

如果通过地址映射的基地址可以获取和释放 semaphore 寄存器的 bit[0],那么 bit[1] 可以通过(基地址 + 4)相应地获取和释放。因此整个访问窗口的地址范围从 0 到(N x 4 - 1),其中 N 是硬件 semaphore 的总数。

获取流程

如果软件想要请求 semaphore 0,它可以直接读取访问窗口寄存器的基地址。

  • 当硬件接收到读取请求时,如果该位为 0,硬件将设置该位并同步返回 0。此时,软件将认为获取流程成功。

  • 当硬件接收到读取请求时,如果该位为 1,硬件将直接返回 1。此时,软件将认为获取流程失败。

释放流程

如果软件想要释放 semaphore 0,它可以直接写入访问窗口寄存器的基地址。硬件在接收到写命令后将清除该位。

查询流程

如果软件想要查询 semaphore 状态,它可以直接读取 semaphore 寄存器(不通过地址映射)。此操作仅返回 semaphore 状态,但不会改变它。

寄存器

RTL8721Dx:

Base Address:

  • IPC0_REG : 0x41014000

  • IPC1_REG : 0x41014080

Name

Address offset

Access

Description

REG_IPC_DATA

000h

R/W

Take NP's IPC as an example to describe the function of IPC's internal registers. The REG_TX_DATA is used to transmit message from NP to AP. (The logic cannot be generated automatically.)

REG_IPC_ISR

004h

R/W

This register is used to record Tx empty.

REG_IPC_IMR

008h

R/W

REG_IPC_ICR

00Ch

R/W

This register can ensure that the software can manually clear the Tx register in an emergency.

REG_IPC_SEM_0

010h

R

REG_IPC_SEM_1

014h

R

REG_IPC_DUMMY

018h

R/W

REG_IPC_DATA

  • Name: Tx_Rx Register

  • Size: 32

  • Address offset: 000h

  • Read/write access: R/W

Take NP's IPC as an example to describe the function of IPC's internal registers. The REG_TX_DATA is

used to transmit message from NP to AP. (The logic cannot be generated automatically.)

31:16 TX0_DATA 15:0 RX0_DATA

Bit

Symbol

Access

INI

Description

31:16

TX0_DATA

R/W

0x0

After preparing descriptor, data and corresponding memory.

  • 1: Writing 1 to the Tx data register (tx0_data) channel x bit, and the data will be mapped to the CPU0's RX data register (rx0_data) channel x bit. And the corresponding Rx full status bit in REG_ISR_CPU0 will be set.

  • 0: Writing 0 has no effect.

If the corresponding Rx full status bit in REG_ISR_CPU0 (e.g. isr_rx0_full_status6) is cleared, the corresponding bit in tx0_data will be cleaned automatically.

15:0

RX0_DATA

R

0x0

Rx data automatically maps data from tx0_data of CPU0

REG_IPC_ISR

  • Name: Interrupt Empty Full Status Register

  • Size: 32

  • Address offset: 004h

  • Read/write access: R/W

This register is used to record Tx empty.

31 ISR_TX0_EMPTY_STATUS15 30 ISR_TX0_EMPTY_STATUS14 29 ISR_TX0_EMPTY_STATUS13 28 ISR_TX0_EMPTY_STATUS12 27 ISR_TX0_EMPTY_STATUS11 26 ISR_TX0_EMPTY_STATUS10 25 ISR_TX0_EMPTY_STATUS9 24 ISR_TX0_EMPTY_STATUS8 23 ISR_TX0_EMPTY_STATUS7 22 ISR_TX0_EMPTY_STATUS6 21 ISR_TX0_EMPTY_STATUS5 20 ISR_TX0_EMPTY_STATUS4 19 ISR_TX0_EMPTY_STATUS3 18 ISR_TX0_EMPTY_STATUS2 17 ISR_TX0_EMPTY_STATUS1 16 ISR_TX0_EMPTY_STATUS0 15 ISR_RX0_FULL_STATUS15 14 ISR_RX0_FULL_STATUS14 13 ISR_RX0_FULL_STATUS13 12 ISR_RX0_FULL_STATUS12 11 ISR_RX0_FULL_STATUS11 10 ISR_RX0_FULL_STATUS10 9 ISR_RX0_FULL_STATUS9 8 ISR_RX0_FULL_STATUS8 7 ISR_RX0_FULL_STATUS7 6 ISR_RX0_FULL_STATUS6 5 ISR_RX0_FULL_STATUS5 4 ISR_RX0_FULL_STATUS4 3 ISR_RX0_FULL_STATUS3 2 ISR_RX0_FULL_STATUS2 1 ISR_RX0_FULL_STATUS1 0 ISR_RX0_FULL_STATUS0

Bit

Symbol

Access

INI

Description

31

ISR_TX0_EMPTY_STATUS15

R/W

0x0

Refer to the description of isr_tx0_empty_status0

30

ISR_TX0_EMPTY_STATUS14

R/W

0x0

Refer to the description of isr_tx0_empty_status0

29

ISR_TX0_EMPTY_STATUS13

R/W

0x0

Refer to the description of isr_tx0_empty_status0

28

ISR_TX0_EMPTY_STATUS12

R/W

0x0

Refer to the description of isr_tx0_empty_status0

27

ISR_TX0_EMPTY_STATUS11

R/W

0x0

Refer to the description of isr_tx0_empty_status0

26

ISR_TX0_EMPTY_STATUS10

R/W

0x0

Refer to the description of isr_tx0_empty_status0

25

ISR_TX0_EMPTY_STATUS9

R/W

0x0

Refer to the description of isr_tx0_empty_status0

24

ISR_TX0_EMPTY_STATUS8

R/W

0x0

Refer to the description of isr_tx0_empty_status0

23

ISR_TX0_EMPTY_STATUS7

R/W

0x0

Refer to the description of isr_tx0_empty_status0

22

ISR_TX0_EMPTY_STATUS6

R/W

0x0

Refer to the description of isr_tx0_empty_status0

21

ISR_TX0_EMPTY_STATUS5

R/W

0x0

Refer to the description of isr_tx0_empty_status0

20

ISR_TX0_EMPTY_STATUS4

R/W

0x0

Refer to the description of isr_tx0_empty_status0

19

ISR_TX0_EMPTY_STATUS3

R/W

0x0

Refer to the description of isr_tx0_empty_status0

18

ISR_TX0_EMPTY_STATUS2

R/W

0x0

Refer to the description of isr_tx0_empty_status0

17

ISR_TX0_EMPTY_STATUS1

R/W

0x0

Refer to the description of isr_tx0_empty_status0

16

ISR_TX0_EMPTY_STATUS0

R/W

0x0

Tx channel 0 empty interrupt status of CPU1 transmit to CPU0. If the corresponding Rx full status bit in REG_ISR_CPU0 (e.g. isr_rx0_full_status0) is cleared, the corresponding Tx empty status bit will be set automatically.

It will be cleared by software writing 1.

15

ISR_RX0_FULL_STATUS15

R/W

0x0

Refer to the description of isr_rx0_full_status0

14

ISR_RX0_FULL_STATUS14

R/W

0x0

Refer to the description of isr_rx0_full_status0

13

ISR_RX0_FULL_STATUS13

R/W

0x0

Refer to the description of isr_rx0_full_status0

12

ISR_RX0_FULL_STATUS12

R/W

0x0

Refer to the description of isr_rx0_full_status0

11

ISR_RX0_FULL_STATUS11

R/W

0x0

Refer to the description of isr_rx0_full_status0

10

ISR_RX0_FULL_STATUS10

R/W

0x0

Refer to the description of isr_rx0_full_status0

9

ISR_RX0_FULL_STATUS9

R/W

0x0

Refer to the description of isr_rx0_full_status0

8

ISR_RX0_FULL_STATUS8

R/W

0x0

Refer to the description of isr_rx0_full_status0

7

ISR_RX0_FULL_STATUS7

R/W

0x0

Refer to the description of isr_rx0_full_status0

6

ISR_RX0_FULL_STATUS6

R/W

0x0

Refer to the description of isr_rx0_full_status0

5

ISR_RX0_FULL_STATUS5

R/W

0x0

Refer to the description of isr_rx0_full_status0

4

ISR_RX0_FULL_STATUS4

R/W

0x0

Refer to the description of isr_rx0_full_status0

3

ISR_RX0_FULL_STATUS3

R/W

0x0

Refer to the description of isr_rx0_full_status0

2

ISR_RX0_FULL_STATUS2

R/W

0x0

Refer to the description of isr_rx0_full_status0

1

ISR_RX0_FULL_STATUS1

R/W

0x0

Refer to the description of isr_rx0_full_status0

0

ISR_RX0_FULL_STATUS0

R/W

0x0

Rx channel 0 full interrupt status of CPU1. The corresponding Rx full status bit will be set by CPU0's Tx data register (tx0_data) channel 0.

It will be cleared by software writing 1.

REG_IPC_IMR

  • Name: Interrupt Empty Full Mask Register

  • Size: 32

  • Address offset: 008h

  • Read/write access: R/W

31:16 IMR_TX0_EMPTY_MASK 15:0 IMR_RX0_FULL_MASK

Bit

Symbol

Access

INI

Description

31:16

IMR_TX0_EMPTY_MASK

R/W

0x0

  • 0: Mask Tx Channel x empty interrupt of CPU1 transmit to CPU0

  • 1: Unmask Tx Channel x empty interrupt of CPU1 transmit to CPU0

15:0

IMR_RX0_FULL_MASK

R/W

0x0

  • 0: Mask Rx Channel x full interrupt of CPU1 received from CPU0

  • 1: Unmask Rx Channel x full interrupt of CPU1 received from CPU0

REG_IPC_ICR

  • Name: Clear Tx Register

  • Size: 32

  • Address offset: 00Ch

  • Read/write access: R/W

This register can ensure that the software can manually clear the Tx register in an emergency.

31 ICR_TX0_DATA_CLEAR15 30 ICR_TX0_DATA_CLEAR14 29 ICR_TX0_DATA_CLEAR13 28 ICR_TX0_DATA_CLEAR12 27 ICR_TX0_DATA_CLEAR11 26 ICR_TX0_DATA_CLEAR10 25 ICR_TX0_DATA_CLEAR9 24 ICR_TX0_DATA_CLEAR8 23 ICR_TX0_DATA_CLEAR7 22 ICR_TX0_DATA_CLEAR6 21 ICR_TX0_DATA_CLEAR5 20 ICR_TX0_DATA_CLEAR4 19 ICR_TX0_DATA_CLEAR3 18 ICR_TX0_DATA_CLEAR2 17 ICR_TX0_DATA_CLEAR1 16 ICR_TX0_DATA_CLEAR0 15:0 RSVD0

Bit

Symbol

Access

INI

Description

31

ICR_TX0_DATA_CLEAR15

R/W

0x0

Refer to the description of icr_tx0_data_clear0

30

ICR_TX0_DATA_CLEAR14

R/W

0x0

Refer to the description of icr_tx0_data_clear0

29

ICR_TX0_DATA_CLEAR13

R/W

0x0

Refer to the description of icr_tx0_data_clear0

28

ICR_TX0_DATA_CLEAR12

R/W

0x0

Refer to the description of icr_tx0_data_clear0

27

ICR_TX0_DATA_CLEAR11

R/W

0x0

Refer to the description of icr_tx0_data_clear0

26

ICR_TX0_DATA_CLEAR10

R/W

0x0

Refer to the description of icr_tx0_data_clear0

25

ICR_TX0_DATA_CLEAR9

R/W

0x0

Refer to the description of icr_tx0_data_clear0

24

ICR_TX0_DATA_CLEAR8

R/W

0x0

Refer to the description of icr_tx0_data_clear0

23

ICR_TX0_DATA_CLEAR7

R/W

0x0

Refer to the description of icr_tx0_data_clear0

22

ICR_TX0_DATA_CLEAR6

R/W

0x0

Refer to the description of icr_tx0_data_clear0

21

ICR_TX0_DATA_CLEAR5

R/W

0x0

Refer to the description of icr_tx0_data_clear0

20

ICR_TX0_DATA_CLEAR4

R/W

0x0

Refer to the description of icr_tx0_data_clear0

19

ICR_TX0_DATA_CLEAR3

R/W

0x0

Refer to the description of icr_tx0_data_clear0

18

ICR_TX0_DATA_CLEAR2

R/W

0x0

Refer to the description of icr_tx0_data_clear0

17

ICR_TX0_DATA_CLEAR1

R/W

0x0

Refer to the description of icr_tx0_data_clear0

16

ICR_TX0_DATA_CLEAR0

R/W

0x0

  • 0: Writing 0 has no effect.

  • 1: Clear the Tx data register (tx0_data) channel 0 bit.

15:0

RSVD0

R/W

0x0

REG_IPC_SEM_0

  • Size: 32

  • Address offset: 010h

  • Read/write access: R

31:0 SEM_0_DATA

Bit

Symbol

Access

INI

Description

31:0

SEM_0_DATA

R

0x0

It is used to indicate whether this semaphore is occupied. 0: Not occupied; 1: Occupied.

REG_IPC_SEM_1

  • Size: 32

  • Address offset: 014h

  • Read/write access: R

31:0 SEM_1_DATA

Bit

Symbol

Access

INI

Description

31:0

SEM_1_DATA

R

0x0

It is used to indicate whether this semaphore is occupied. 0: Not occupied; 1: Occupied.

REG_IPC_DUMMY

  • Name: Dummy Register

  • Size: 32

  • Address offset: 018h

  • Read/write access: R/W

31:16 RSVD 15:0 DUMMY

Bit

Symbol

Access

INI

Description

31:16

RSVD

R

-

Reserved

15:0

DUMMY

R/W

0x0

Dummy register