2828* \addtogroup group_result Result Type
2929* \ingroup group_abstraction
3030* \{
31- * Basic function result handling. Defines a simple type for conveying
32- * information about whether something succeeded or details about any issues
33- * that were detected.
34- *
35- * \defgroup group_result_fields Fields
36- * \defgroup group_result_modules Modules
37- * \defgroup group_result_severity Severity
31+ \anchor anchor_general_description
32+ * Defines a type and related utilities for function result handling.
33+ *
34+ * The cy_rslt_t type is a structured bitfield which encodes information
35+ * about result type, the originating module, and a code for the specific
36+ * error (or warning etc). In order to extract these individual fields from
37+ * a cy_rslt_t value, the utility macros @ref CY_RSLT_GET_TYPE, @ref CY_RSLT_GET_MODULE,
38+ * and @ref CY_RSLT_GET_CODE are provided. For example:
39+ * \code
40+ * cy_rslt_t result = cy_hal_do_operation(arg);
41+ * // Will be CY_RSLT_TYPE_INFO, CY_RSLT_TYPE_WARNING, CY_RSLT_TYPE_ERROR, or CY_RSLT_TYPE_FATAL
42+ * uint8_t type = CY_RSLT_GET_TYPE(result)
43+ * // See the "Modules" section for possible values
44+ * uint16_t module_id = CY_RSLT_GET_MODULE(result);
45+ * // Specific error codes are defined by each module
46+ * uint16_t error_code = CY_RSLT_GET_CODE(result);
47+ * \endcode
3848*/
3949
40- #pragma once
50+ #if !defined(CY_RESULT_H )
51+ #define CY_RESULT_H
4152
4253#include <stdint.h>
4354
4455#if defined(__cplusplus )
4556extern "C" {
4657#endif
4758
48- /** Provides the result of an operation as a structured bitfield */
59+ /**
60+ * @brief Provides the result of an operation as a structured bitfield.
61+ *
62+ * See the \ref anchor_general_description "General Description"
63+ * for more details on structure and usage.
64+ */
4965typedef uint32_t cy_rslt_t ;
5066
51- /** Result value indicating success */
67+ /** @ref cy_rslt_t return value indicating success */
5268#define CY_RSLT_SUCCESS ((cy_rslt_t)0x00000000U)
5369
5470/** \cond INTERNAL */
5571/** Mask for the bit at position "x" */
5672#define CY_BIT_MASK (x ) ((1U << (x)) - 1U)
5773
58- /** Bit position of the result code */
59- #define CY_RSLT_CODE_POSITION (0U)
60- /** Bit width of the result code */
61- #define CY_RSLT_CODE_WIDTH (16U)
6274/** Bit position of the result type */
6375#define CY_RSLT_TYPE_POSITION (16U)
6476/** Bit width of the result type */
@@ -67,86 +79,126 @@ typedef uint32_t cy_rslt_t;
6779#define CY_RSLT_MODULE_POSITION (18U)
6880/** Bit width of the module identifier */
6981#define CY_RSLT_MODULE_WIDTH (14U)
82+ /** Bit position of the result code */
83+ #define CY_RSLT_CODE_POSITION (0U)
84+ /** Bit width of the result code */
85+ #define CY_RSLT_CODE_WIDTH (16U)
7086
71- /** Mask for the result code */
72- #define CY_RSLT_CODE_MASK CY_BIT_MASK(CY_RSLT_CODE_WIDTH)
73- /** Mask for the module identifier */
74- #define CY_RSLT_MODULE_MASK CY_BIT_MASK(CY_RSLT_MODULE_WIDTH)
7587/** Mask for the result type */
7688#define CY_RSLT_TYPE_MASK CY_BIT_MASK(CY_RSLT_TYPE_WIDTH)
89+ /** Mask for the module identifier */
90+ #define CY_RSLT_MODULE_MASK CY_BIT_MASK(CY_RSLT_MODULE_WIDTH)
91+ /** Mask for the result code */
92+ #define CY_RSLT_CODE_MASK CY_BIT_MASK(CY_RSLT_CODE_WIDTH)
7793
7894/** \endcond */
7995
8096/**
81- * \addtogroup group_result_fields
8297* \{
83- * Utlity macros for constructing result values and extracting individual fields from existing results.
98+ * @name Fields
99+ * Utility macros for constructing result values and extracting individual fields from existing results.
84100*/
85101
86- /** Get the value of the result code field */
87- #define CY_RSLT_GET_CODE (x ) (((x) >> CY_RSLT_CODE_POSITION) & CY_RSLT_CODE_MASK)
88- /** Get the value of the result type field */
102+ /**
103+ * @brief Get the value of the result type field
104+ * @param x the @ref cy_rslt_t value from which to extract the result type
105+ */
89106#define CY_RSLT_GET_TYPE (x ) (((x) >> CY_RSLT_TYPE_POSITION) & CY_RSLT_TYPE_MASK)
90- /** Get the value of the module identifier field */
107+ /**
108+ * @brief Get the value of the module identifier field
109+ * @param x the @ref cy_rslt_t value from which to extract the module id
110+ */
91111#define CY_RSLT_GET_MODULE (x ) (((x) >> CY_RSLT_MODULE_POSITION) & CY_RSLT_MODULE_MASK)
112+ /**
113+ * @brief Get the value of the result code field
114+ * @param x the @ref cy_rslt_t value from which to extract the result code
115+ */
116+ #define CY_RSLT_GET_CODE (x ) (((x) >> CY_RSLT_CODE_POSITION) & CY_RSLT_CODE_MASK)
92117
93- /** Create a result value from the specified type, module, and result code */
118+ /**
119+ * @brief Create a new @ref cy_rslt_t value that encodes the specified type, module, and result code.
120+ * @param type one of @ref CY_RSLT_TYPE_INFO, @ref CY_RSLT_TYPE_WARNING,
121+ * @ref CY_RSLT_TYPE_ERROR, @ref CY_RSLT_TYPE_FATAL
122+ * @param module Identifies the module where this result originated; see @ref anchor_modules "Modules".
123+ * @param code a module-defined identifier to identify the specific situation that
124+ * this result describes.
125+ */
94126#define CY_RSLT_CREATE (type , module , code ) \
95127 ((((module) & CY_RSLT_MODULE_MASK) << CY_RSLT_MODULE_POSITION) | \
96128 (((code) & CY_RSLT_CODE_MASK) << CY_RSLT_CODE_POSITION) | \
97129 (((type) & CY_RSLT_TYPE_MASK) << CY_RSLT_TYPE_POSITION))
98130
99- /** \} group_result_fields */
131+ /** \} fields */
100132
101133/**
102- * \addtogroup group_result_severity
103134* \{
135+ *@name Result Types
104136*/
105137
106- /** Informational-only result */
138+ /** @brief The result code is informational-only */
107139#define CY_RSLT_TYPE_INFO (0U)
108- /** Warning result */
140+ /** @brief The result code is a warning */
109141#define CY_RSLT_TYPE_WARNING (1U)
110- /** Error result */
142+ /** @brief The result code is an error */
111143#define CY_RSLT_TYPE_ERROR (2U)
112- /** Fatal error result */
144+ /** @brief The result code is a fatal error */
113145#define CY_RSLT_TYPE_FATAL (3U)
114146
115- /** \} group_result_severity */
147+ /** \} severity */
116148
117149/**
118- * \addtogroup group_result_modules
119150* \{
151+ @name Modules
152+ @anchor anchor_modules
120153* Defines codes to identify the module from which an error originated.
121154* For some large libraries, a range of module codes is defined here;
122155* see the library documentation for values corresonding to individual modules.
123156*/
124157/**** DRIVER Module codes: 0x0000 - 0x00FF ****/
125- /** Base identifier for peripheral driver library modules (0x0000 - 0x007F) */
126- #define CY_RSLT_MODULE_DRIVERS_PDL_BASE (0x0000U)
127- /** Base identifier for wireless host driver library modules (0x0080 - 0x00FF) */
128- #define CY_RSLT_MODULE_DRIVERS_WHD_BASE (0x0080U)
158+ /** Base module identifier for peripheral driver library drivers (0x0000 - 0x007F) */
159+ #define CY_RSLT_MODULE_DRIVERS_PDL_BASE (0x0000U)
160+ /** Base module identifier for wireless host driver library modules (0x0080 - 0x00FF) */
161+ #define CY_RSLT_MODULE_DRIVERS_WHD_BASE (0x0080U)
129162
130- /** Base identifier for HAL modules (0x0100 - 0x017F) */
131- #define CY_RSLT_MODULE_ABSTRACTION_HAL_BASE (0x0100U)
163+ /** Base module identifier for HAL drivers (0x0100 - 0x017F) */
164+ #define CY_RSLT_MODULE_ABSTRACTION_HAL_BASE (0x0100U)
132165/** Module identifier for board support package */
133- #define CY_RSLT_MODULE_ABSTRACTION_BSP (0x0180U)
166+ #define CY_RSLT_MODULE_ABSTRACTION_BSP (0x0180U)
134167/** Module identifier for file system abstraction */
135- #define CY_RSLT_MODULE_ABSTRACTION_FS (0x0181U)
168+ #define CY_RSLT_MODULE_ABSTRACTION_FS (0x0181U)
136169/** Module identifier for resource abstraction */
137- #define CY_RSLT_MODULE_ABSTRACTION_RESOURCE (0x0182U)
170+ #define CY_RSLT_MODULE_ABSTRACTION_RESOURCE (0x0182U)
138171/** Module identifier for rtos abstraction */
139- #define CY_RSLT_MODULE_ABSTRACTION_OS (0x0183U)
172+ #define CY_RSLT_MODULE_ABSTRACTION_OS (0x0183U)
140173/** Base identifier for environment abstraction modules (0x0184 - 0x01FF) */
141- #define CY_RSLT_MODULE_ABSTRACTION_ENV (0x0184U)
174+ #define CY_RSLT_MODULE_ABSTRACTION_ENV (0x0184U)
175+
176+ /** Base module identifier for Board Libraries (0x01A0 - 0x01BF) */
177+ #define CY_RSLT_MODULE_BOARD_LIB_BASE (0x01A0U)
178+ /** Module identifier for the Retarget IO Board Library */
179+ #define CY_RSLT_MODULE_BOARD_LIB_RETARGET_IO (0x1A0U)
180+ /** Module identifier for the RGB LED Board Library */
181+ #define CY_RSLT_MODULE_BOARD_LIB_RGB_LED (0x01A1U)
182+ /** Module identifier for the Serial Flash Board Library */
183+ #define CY_RSLT_MODULE_BOARD_LIB_SERIAL_FLASH (0x01A2U)
142184
143- /** Base identifier for Middleware module codes (0x0200 - 0x02FF) */
144- #define CY_RSLT_MODULE_MIDDLEWARE_BASE (0x0200U)
185+ /** Base module identifier for Shield Board Libraries (0x01C0 - 0x01FF) */
186+ #define CY_RSLT_MODULE_BOARD_SHIELD_BASE (0x01C0U)
187+ /** Module identifier for Shield Board CY8CKIT-028-EPD */
188+ #define CY_RSLT_MODULE_BOARD_SHIELD_028_EPD (0x01C0U)
189+ /** Module identifier for Shield Board CY8CKIT-028-TFT */
190+ #define CY_RSLT_MODULE_BOARD_SHIELD_028_TFT (0x01C1U)
145191
146- /** \} group_result_modules */
192+
193+ /** Base module identifier for Middleware Libraries (0x0200 - 0x02FF) */
194+ #define CY_RSLT_MODULE_MIDDLEWARE_BASE (0x0200U)
195+
196+ /** \} modules */
147197
148198#ifdef __cplusplus
149199}
150200#endif
151201
202+ #endif /* CY_RESULT_H */
203+
152204/** \} group_result */
0 commit comments