Skip to content

Commit 8d202cb

Browse files
carlescufijhedberg
authored andcommitted
doc: coding style: Introduce a naming conventions section
Add a new section with Zephyr-wide naming conventions, as well as a first rule for C code: area prefixes. Signed-off-by: Carles Cufi <[email protected]>
1 parent e8c6695 commit 8d202cb

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

doc/contribute/style/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Coding Style Guidelines
77
.. toctree::
88
:maxdepth: 1
99

10+
naming.rst
1011
code.rst
1112
cmake.rst
1213
devicetree.rst

doc/contribute/style/naming.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _naming_conventions:
2+
3+
Naming conventions
4+
##################
5+
6+
This section describes the naming conventions adopted by the Zephyr
7+
Project, for each individual programming language or tool used in it.
8+
9+
C Code naming conventions
10+
*************************
11+
12+
The naming conventions in this section apply to C source and header files,
13+
as stated in each individual sub-section.
14+
15+
Public symbol prefixes
16+
======================
17+
18+
All :term:`public APIs <public API>` in Zephyr must be prefixed according
19+
to the area or subsystem they belong to. Examples of area or subsystem prefixes
20+
are provided below for reference.
21+
22+
* ``k_`` for the kernel
23+
* ``sys_`` for system-wide code and features
24+
* ``net_`` for the networking subsystem
25+
* ``bt_`` for the Bluetooth subsystem
26+
* ``i2c_`` for the I2C controller subsystem

doc/glossary.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ Glossary of Terms
107107
architecture to implement an interrupt vector table. The IDT is used
108108
to determine the correct response to interrupts and exceptions.
109109

110+
internal API
111+
Any internal function, structure or macro defined anywhere in the Zephyr
112+
source tree. Internal APIs are intended to "extend" Zephyr, and are to be
113+
used only between certain :term:`software components <software
114+
component>`, usually in-tree but in some cases out-of-tree (e.g. adding an
115+
out-of-tree architecture or driver). Applications must not invoke
116+
internal APIs outside their own scope. The context where the API is
117+
called or implemented is well defined. For example, functions prefixed
118+
with ``arch_`` are intended for use by the Zephyr kernel to invoke
119+
architecture-specific code. Internal APIs are mostly kept stable, but with
120+
fewer guarantees than :term:`public APIs <public API>`.
121+
110122
ISR
111123
(Interrupt Service Routine) Also known as an interrupt handler, an ISR
112124
is a callback function whose execution is triggered by a hardware
@@ -127,6 +139,22 @@ Glossary of Terms
127139
Power gating reduces power consumption by shutting off areas of an
128140
integrated circuit that are not in use.
129141

142+
private API
143+
Any function, structure or macro defined anywhere in the Zephyr source
144+
tree which are only intended for consumption inside the
145+
:term:`software component` where they are defined. Private APIs may change
146+
at any time and must not be used by code outside the corresponding
147+
software component.
148+
149+
public API
150+
Any function, structure or macro defined inside the ``include/zephyr``
151+
folder that is not explicitly marked as private. Public APIs are intended
152+
for consumption by any and all in-tree or out-of-tree :term:`software
153+
components <software component>`. Public APIs cannot be modified without
154+
following the provisions described in the :ref:`API lifecycle
155+
<api_lifecycle>` section, which means they provide guarantees that they
156+
will remain stable over time.
157+
130158
SoC
131159
A `System on a chip`_, that is, an integrated circuit that contains at
132160
least one :term:`CPU cluster` (in turn with at least one :term:`CPU core`),
@@ -140,6 +168,11 @@ Glossary of Terms
140168
A number of different :term:`SoCs <SoC>` that share similar characteristics and
141169
features, and that the vendor typically names and markets together.
142170

171+
software component
172+
A software component is a self-contained, modular, and replaceable part of
173+
the Zephyr source code. A driver, a subsystem or an applications are all
174+
examples of software components present in Zephyr.
175+
143176
subsystem
144177
A subsystem refers to a logically distinct part of the operating system
145178
that handles specific functionality or provides certain services.

0 commit comments

Comments
 (0)