@@ -84,3 +84,111 @@ Samples
8484=======
8585
8686 - :zephyr:code-sample: `ipc-icmsg `
87+
88+ Detailed Protocol Specification
89+ ===============================
90+
91+ The ICMsg uses two shared memory regions and two MBOX channels.
92+ The region and channel pair are used to transfer messages in one direction.
93+ The other pair is symmetric and transfers messages in the opposite direction.
94+ For this reason, the specification below focuses on one such pair.
95+ The other pair is identical.
96+
97+ The ICMsg provides just one endpoint per instance.
98+
99+ Shared Memory Region Organization
100+ ---------------------------------
101+
102+ If data caching is enabled, the shared memory region provided to ICMsg must be aligned according to the cache requirement.
103+ If cache is not enabled, the required alignment is 4 bytes.
104+
105+ The shared memory region is entirely used by a single FIFO.
106+ It contains read and write indexes followed by the data buffer.
107+ The detailed structure is contained in the following table:
108+
109+ .. list-table ::
110+ :header-rows: 1
111+
112+ * - Field name
113+ - Size (bytes)
114+ - Byte order
115+ - Description
116+ * - ``rd_idx ``
117+ - 4
118+ - little‑endian
119+ - Index of the first incoming byte in the ``data `` field.
120+ * - ``padding ``
121+ - depends on cache alignment
122+ - n/a
123+ - Padding added to align ``wr_idx `` to the cache alignment.
124+ * - ``wr_idx ``
125+ - 4
126+ - little‑endian
127+ - Index of the byte after the last incoming byte in the ``data `` field.
128+ * - ``data ``
129+ - everything to the end of the region
130+ - n/a
131+ - Circular buffer containing actual bytes to transfer.
132+
133+ This is usual FIFO with a circular buffer:
134+
135+ * The Indexes (``rd_idx `` and ``wr_idx ``) are wrapped around when they reach the end of the ``data `` buffer.
136+ * The FIFO is empty if ``rd_idx == wr_idx ``.
137+ * The FIFO has one byte less capacity than the ``data `` buffer length.
138+
139+ Packets
140+ -------
141+
142+ Packets are sent over the FIFO described in the above section.
143+ One packet can be wrapped around if it occurs at the end of the FIFO buffer.
144+
145+ The following is the packet structure:
146+
147+ .. list-table ::
148+ :header-rows: 1
149+
150+ * - Field name
151+ - Size (bytes)
152+ - Byte order
153+ - Description
154+ * - ``len ``
155+ - 2
156+ - big‑endian
157+ - Length of the ``data `` field.
158+ * - ``reserved ``
159+ - 2
160+ - n/a
161+ - Reserved for the future use.
162+ It must be 0 for the current protocol version.
163+ * - ``data ``
164+ - ``len ``
165+ - n/a
166+ - Packet data.
167+ * - ``padding ``
168+ - 0‑3
169+ - n/a
170+ - Padding is added to align the total packet size to 4 bytes.
171+
172+ The packet send procedure is the following:
173+
174+ #. Check if the packet fits into the buffer.
175+ #. Write the packet to ``data `` FIFO buffer starting at ``wr_idx ``.
176+ Wrap it if needed.
177+ #. Write a new value of the ``wr_idx ``.
178+ #. Notify the receiver over the MBOX channel.
179+
180+ Initialization
181+ --------------
182+
183+ The initialization sequence is the following:
184+
185+ #. Set the ``wr_idx `` and ``rd_idx `` to zero.
186+ #. Push a single packet to FIFO containing magic data: ``45 6d 31 6c 31 4b 30 72 6e 33 6c 69 34 ``.
187+ The MBOX is not used yet.
188+ #. Initialize the MBOX.
189+ #. Repeat the notification over the MBOX channel using some interval, for example, 1 ms.
190+ #. Wait for an incoming packet containing the magic data.
191+ It will arrive over the other pair (shared memory region and MBOX).
192+ #. Stop repeating the MBOX notification.
193+
194+ After this, the ICMsg is bound, and it is ready to transfer packets.
0 commit comments