source: rtems-docs/eng/coding-doxygen.rst @ 1ff876a

5
Last change on this file since 1ff876a was ef19112, checked in by Sebastian Huber <sebastian.huber@…>, on 04/03/19 at 09:12:24

eng: Rework Doxygen guidelines

Update #3704.

  • Property mode set to 100644
File size: 9.1 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 2019 embedded brains GmbH
4
5Doxygen Guidelines
6==================
7
8Group Names
9-----------
10
11Doxygen group names shall use
12`CamelCase <https://en.wikipedia.org/wiki/Camel_case>`_.
13In the RTEMS source code, CamelCase is rarely used, so this makes it easier to
14search and replace Doxygen groups.  It avoids ambiguous references to
15functions, types, defines, macros, and groups.  All groups shall have an
16``RTEMS`` prefix.  This makes it possible to include the RTEMS files with
17Doxygen comments in a larger project without name conflicts.
18
19.. code:: c
20
21    /**
22     * @defgroup RTEMSScoreThread
23     *
24     * @ingrop RTEMSScore
25     *
26     * ...
27     */
28
29Use Groups
30----------
31
32Every file, function declaration, type definition, typedef, define, macro and
33global variable declaration shall belong to at least one Doxygen group.  Use
34``@defgroup`` and ``@addtogroup`` with ``@{`` and ``@}`` brackets to add
35members to a group.  A group shall be defined at most once.  Each group shall
36be documented with an ``@brief`` description and an optional detailed
37description.  The ``@brief`` description shall use
38`Title Case <https://en.wikipedia.org/wiki/Letter_case#Title_Case>`_.
39Use grammatically correct sentences for the detailed descriptions.
40
41.. code:: c
42
43    /**
44     * @defgroup RTEMSScoreThread
45     *
46     * @ingrop RTEMSScore
47     *
48     * @brief Thread Handler
49     *
50     * ...
51     *
52     * @{
53     */
54
55     ... declarations, defines ...
56
57     /** @} */
58
59.. code:: c
60
61    /**
62     * @addtogroup RTEMSScoreThread
63     *
64     * @{
65     */
66
67     ... declarations, defines ...
68
69     /** @} */
70
71Files
72-----
73
74Each source or header file shall have an ``@file`` block at the top of the
75file.  The ``@file`` block should precede the license header separated by one
76blank line.  This placement reduces the chance of merge conflicts in imported
77third-party code.  The ``@file`` block shall be put into a group with
78``@ingroup GroupName``.  The ``@file`` block should have an ``@brief``
79description and a detailed description if it is considered helpful.  Use
80``@brief @copybrief GroupName`` as a default to copy the ``@brief`` description
81from the corresponding group and omit the detailed description.
82
83.. code:: c
84
85    /**
86     * @file
87     *
88     * @ingroup RTEMSScoreThread
89     *
90     * @brief @copybrief RTEMSScoreThread
91     */
92
93.. code:: c
94
95    /**
96     * @file
97     *
98     * @ingroup RTEMSScoreThread
99     *
100     * @brief Some helpful brief description.
101     *
102     * Some helpful detailed description.
103     */
104
105Type Definitions
106----------------
107
108Each type defined in a header file shall be documented with an ``@brief``
109description and an optional detailed description.  Each type member shall be
110documented with an ``@brief`` description and an optional detailed description.
111Use grammatically correct sentences for the detailed descriptions.
112
113.. code:: c
114
115    /**
116     * @brief The information structure used to manage each API class of objects.
117     *
118     * If objects for the API class are configured, an instance of this structure
119     * is statically allocated and pre-initialized by OBJECTS_INFORMATION_DEFINE()
120     * through <rtems/confdefs.h>.  The RTEMS library contains a statically
121     * allocated and pre-initialized instance for each API class providing zero
122     * objects, see OBJECTS_INFORMATION_DEFINE_ZERO().
123     */
124    typedef struct {
125      /**
126       * @brief This is the maximum valid ID of this object API class.
127       *
128       * This member is statically initialized and provides also the object API,
129       * class and multiprocessing node information.
130       *
131       * It is used by _Objects_Get() to validate an object ID.
132       */
133      Objects_Id maximum_id;
134
135      ... more members ...
136    } Objects_Information;
137
138Function Declarations
139---------------------
140
141Each function declaration or function-like macros in a header file shall be
142documented with an ``@brief`` description and an optional detailed description.
143Use grammatically correct sentences for the brief and detailed descriptions.
144Each parameter shall be documented with an ``@param`` entry.  List the
145``@param`` entries in the order of the function parameters.  For *non-const
146pointer* parameters
147
148* use ``@param[out]``, if the referenced object is modified by the function, or
149
150* use ``@param[in, out]``, if the referenced object is read and modified by the
151  function.
152
153For other parameters (e.g. *const pointer* and *scalar* parameters) do not use
154the ``[in]``, ``[out]`` or ``[in, out]`` parameter specifiers.  Each return
155value or return value range shall be documented with an ``@retval`` entry.
156Document the most common return value first.  Use a placeholder name for value
157ranges, e.g. ``pointer`` in the ``_Workspace_Allocate()`` example below.  In
158case the function returns only one value, then use ``@return``, e.g. use
159``@retval`` only if there are at least two return values or return value
160ranges.  Use grammatically correct sentences for the parameter and return value
161descriptions.
162
163.. code:: c
164
165    /**
166     * @brief Sends a message to the message queue.
167     *
168     * This directive sends the message buffer to the message queue indicated by
169     * ID.  If one or more tasks is blocked waiting to receive a message from this
170     * message queue, then one will receive the message.  The task selected to
171     * receive the message is based on the task queue discipline algorithm in use
172     * by this particular message queue.  If no tasks are waiting, then the message
173     * buffer will be placed at the rear of the chain of pending messages for this
174     * message queue.
175     *
176     * @param id The message queue ID.
177     * @param buffer The message content buffer.
178     * @param size The size of the message.
179     *
180     * @retval RTEMS_SUCCESSFUL Successful operation.
181     * @retval RTEMS_INVALID_ID Invalid message queue ID.
182     * @retval RTEMS_INVALID_ADDRESS The message buffer pointer is @c NULL.
183     * @retval RTEMS_INVALID_SIZE The message size is larger than the maximum
184     *   message size of the message queue.
185     * @retval RTEMS_TOO_MANY The new message would exceed the message queue limit
186     *   for pending messages.
187     */
188    rtems_status_code rtems_message_queue_send(
189      rtems_id    id,
190      const void *buffer,
191      size_t      size
192    );
193
194.. code:: c
195
196    /**
197     * @brief Receives a message from the message queue
198     *
199     * This directive is invoked when the calling task wishes to receive a message
200     * from the message queue indicated by ID. The received message is to be placed
201     * in the buffer. If no messages are outstanding and the option set indicates
202     * that the task is willing to block, then the task will be blocked until a
203     * message arrives or until, optionally, timeout clock ticks have passed.
204     *
205     * @param id The message queue ID.
206     * @param[out] buffer The buffer for the message content.  The buffer must be
207     *   large enough to store maximum size messages of this message queue.
208     * @param[out] size The size of the message.
209     * @param option_set The option set, e.g. RTEMS_NO_WAIT or RTEMS_WAIT.
210     * @param timeout The number of ticks to wait if the RTEMS_WAIT is set.  Use
211     *   RTEMS_NO_TIMEOUT to wait indefinitely.
212     *
213     * @retval RTEMS_SUCCESSFUL Successful operation.
214     * @retval RTEMS_INVALID_ID Invalid message queue ID.
215     * @retval RTEMS_INVALID_ADDRESS The message buffer pointer or the message size
216     *   pointer is @c NULL.
217     * @retval RTEMS_TIMEOUT A timeout occurred and no message was received.
218     */
219    rtems_status_code rtems_message_queue_receive(
220      rtems_id        id,
221      void           *buffer,
222      size_t         *size,
223      rtems_option    option_set,
224      rtems_interval  timeout
225    );
226
227.. code:: c
228
229    /**
230     * @brief Allocates a memory block of the specified size from the workspace.
231     *
232     * @param size The size of the memory block.
233     *
234     * @retval pointer The pointer to the memory block.  The pointer is at least
235     *   aligned by CPU_HEAP_ALIGNMENT.
236     * @retval NULL No memory block with the requested size is available in the
237     *   workspace.
238     */
239    void *_Workspace_Allocate( size_t size );
240
241.. code:: c
242
243    /**
244     * @brief Rebalances the red-black tree after insertion of the node.
245     *
246     * @param[in, out] the_rbtree The red-black tree control.
247     * @param[in, out] the_node The most recently inserted node.
248     */
249    void _RBTree_Insert_color(
250      RBTree_Control *the_rbtree,
251      RBTree_Node    *the_node
252    );
253
254.. code:: c
255
256    /**
257     * @brief Builds an object ID from its components.
258     *
259     * @param the_api The object API.
260     * @param the_class The object API class.
261     * @param node The object node.
262     * @param index The object index.
263     *
264     * @return Returns the object ID constructed from the arguments.
265     */
266    #define _Objects_Build_id( the_api, the_class, node, index )
267
268Header File Examples
269--------------------
270
271The
272`<rtems/score/thread.h> <https://git.rtems.org/rtems/tree/cpukit/include/rtems/score/thread.h>`_
273and
274`<rtems/score/threadimpl.h> <https://git.rtems.org/rtems/tree/cpukit/include/rtems/score/threadimpl.h>`_
275header files are a good example of how header files should be documented.
Note: See TracBrowser for help on using the repository browser.