28
28
* \addtogroup group_result Result Type
29
29
* \ingroup group_abstraction
30
30
* \{
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
38
48
*/
39
49
40
- #pragma once
50
+ #if !defined(CY_RESULT_H )
51
+ #define CY_RESULT_H
41
52
42
53
#include <stdint.h>
43
54
44
55
#if defined(__cplusplus )
45
56
extern "C" {
46
57
#endif
47
58
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
+ */
49
65
typedef uint32_t cy_rslt_t ;
50
66
51
- /** Result value indicating success */
67
+ /** @ref cy_rslt_t return value indicating success */
52
68
#define CY_RSLT_SUCCESS ((cy_rslt_t)0x00000000U)
53
69
54
70
/** \cond INTERNAL */
55
71
/** Mask for the bit at position "x" */
56
72
#define CY_BIT_MASK (x ) ((1U << (x)) - 1U)
57
73
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)
62
74
/** Bit position of the result type */
63
75
#define CY_RSLT_TYPE_POSITION (16U)
64
76
/** Bit width of the result type */
@@ -67,86 +79,126 @@ typedef uint32_t cy_rslt_t;
67
79
#define CY_RSLT_MODULE_POSITION (18U)
68
80
/** Bit width of the module identifier */
69
81
#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)
70
86
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)
75
87
/** Mask for the result type */
76
88
#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)
77
93
78
94
/** \endcond */
79
95
80
96
/**
81
- * \addtogroup group_result_fields
82
97
* \{
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.
84
100
*/
85
101
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
+ */
89
106
#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
+ */
91
111
#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)
92
117
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
+ */
94
126
#define CY_RSLT_CREATE (type , module , code ) \
95
127
((((module) & CY_RSLT_MODULE_MASK) << CY_RSLT_MODULE_POSITION) | \
96
128
(((code) & CY_RSLT_CODE_MASK) << CY_RSLT_CODE_POSITION) | \
97
129
(((type) & CY_RSLT_TYPE_MASK) << CY_RSLT_TYPE_POSITION))
98
130
99
- /** \} group_result_fields */
131
+ /** \} fields */
100
132
101
133
/**
102
- * \addtogroup group_result_severity
103
134
* \{
135
+ *@name Result Types
104
136
*/
105
137
106
- /** Informational-only result */
138
+ /** @brief The result code is informational-only */
107
139
#define CY_RSLT_TYPE_INFO (0U)
108
- /** Warning result */
140
+ /** @brief The result code is a warning */
109
141
#define CY_RSLT_TYPE_WARNING (1U)
110
- /** Error result */
142
+ /** @brief The result code is an error */
111
143
#define CY_RSLT_TYPE_ERROR (2U)
112
- /** Fatal error result */
144
+ /** @brief The result code is a fatal error */
113
145
#define CY_RSLT_TYPE_FATAL (3U)
114
146
115
- /** \} group_result_severity */
147
+ /** \} severity */
116
148
117
149
/**
118
- * \addtogroup group_result_modules
119
150
* \{
151
+ @name Modules
152
+ @anchor anchor_modules
120
153
* Defines codes to identify the module from which an error originated.
121
154
* For some large libraries, a range of module codes is defined here;
122
155
* see the library documentation for values corresonding to individual modules.
123
156
*/
124
157
/**** 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)
129
162
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)
132
165
/** Module identifier for board support package */
133
- #define CY_RSLT_MODULE_ABSTRACTION_BSP (0x0180U)
166
+ #define CY_RSLT_MODULE_ABSTRACTION_BSP (0x0180U)
134
167
/** Module identifier for file system abstraction */
135
- #define CY_RSLT_MODULE_ABSTRACTION_FS (0x0181U)
168
+ #define CY_RSLT_MODULE_ABSTRACTION_FS (0x0181U)
136
169
/** Module identifier for resource abstraction */
137
- #define CY_RSLT_MODULE_ABSTRACTION_RESOURCE (0x0182U)
170
+ #define CY_RSLT_MODULE_ABSTRACTION_RESOURCE (0x0182U)
138
171
/** Module identifier for rtos abstraction */
139
- #define CY_RSLT_MODULE_ABSTRACTION_OS (0x0183U)
172
+ #define CY_RSLT_MODULE_ABSTRACTION_OS (0x0183U)
140
173
/** 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)
142
184
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)
145
191
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 */
147
197
148
198
#ifdef __cplusplus
149
199
}
150
200
#endif
151
201
202
+ #endif /* CY_RESULT_H */
203
+
152
204
/** \} group_result */
0 commit comments