• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2016, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * @brief
32  *   This file defines the platform diag interface.
33  */
34 
35 #ifndef OPENTHREAD_PLATFORM_DIAG_H_
36 #define OPENTHREAD_PLATFORM_DIAG_H_
37 
38 #include <stddef.h>
39 #include <stdint.h>
40 
41 #include <openthread/error.h>
42 #include <openthread/platform/radio.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @addtogroup plat-factory-diagnostics
50  *
51  * @brief
52  *   This module includes the platform abstraction for diagnostics features.
53  *
54  * @{
55  */
56 
57 /**
58  * Defines the gpio modes.
59  */
60 typedef enum
61 {
62     OT_GPIO_MODE_INPUT  = 0, ///< Input mode without pull resistor.
63     OT_GPIO_MODE_OUTPUT = 1, ///< Output mode.
64 } otGpioMode;
65 
66 /**
67  * Pointer to callback to output platform diag messages.
68  *
69  * @param[in]  aFormat     The format string.
70  * @param[in]  aArguments  The format string arguments.
71  * @param[out] aContext    A pointer to the user context.
72  */
73 typedef void (*otPlatDiagOutputCallback)(const char *aFormat, va_list aArguments, void *aContext);
74 
75 /**
76  * Sets the platform diag output callback.
77  *
78  * @param[in]  aInstance   The OpenThread instance structure.
79  * @param[in]  aCallback   A pointer to a function that is called on outputting diag messages.
80  * @param[in]  aContext    A pointer to the user context.
81  */
82 void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback aCallback, void *aContext);
83 
84 /**
85  * Processes a factory diagnostics command line.
86  *
87  * @param[in]   aInstance       The OpenThread instance for current request.
88  * @param[in]   aArgsLength     The number of arguments in @p aArgs.
89  * @param[in]   aArgs           The arguments of diagnostics command line.
90  *
91  * @retval  OT_ERROR_INVALID_ARGS       The command is supported but invalid arguments provided.
92  * @retval  OT_ERROR_NONE               The command is successfully process.
93  * @retval  OT_ERROR_INVALID_COMMAND    The command is not valid or not supported.
94  */
95 otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]);
96 
97 /**
98  * Enables/disables the factory diagnostics mode.
99  *
100  * @param[in]  aMode  TRUE to enable diagnostics mode, FALSE otherwise.
101  */
102 void otPlatDiagModeSet(bool aMode);
103 
104 /**
105  * Indicates whether or not factory diagnostics mode is enabled.
106  *
107  * @returns TRUE if factory diagnostics mode is enabled, FALSE otherwise.
108  */
109 bool otPlatDiagModeGet(void);
110 
111 /**
112  * Sets the channel to use for factory diagnostics.
113  *
114  * @param[in]  aChannel  The channel value.
115  */
116 void otPlatDiagChannelSet(uint8_t aChannel);
117 
118 /**
119  * Sets the transmit power to use for factory diagnostics.
120  *
121  * @param[in]  aTxPower  The transmit power value.
122  */
123 void otPlatDiagTxPowerSet(int8_t aTxPower);
124 
125 /**
126  * Processes the received radio frame.
127  *
128  * @param[in]   aInstance   The OpenThread instance for current request.
129  * @param[in]   aFrame      The received radio frame.
130  * @param[in]   aError      The received radio frame status.
131  */
132 void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError);
133 
134 /**
135  * Processes the alarm event.
136  *
137  * @param[in]   aInstance   The OpenThread instance for current request.
138  */
139 void otPlatDiagAlarmCallback(otInstance *aInstance);
140 
141 /**
142  * Sets the gpio value.
143  *
144  * @param[in]  aGpio   The gpio number.
145  * @param[in]  aValue  true to set the gpio to high level, or false otherwise.
146  *
147  * @retval OT_ERROR_NONE             Successfully set the gpio.
148  * @retval OT_ERROR_FAILED           A platform error occurred while setting the gpio.
149  * @retval OT_ERROR_INVALID_ARGS     @p aGpio is not supported.
150  * @retval OT_ERROR_INVALID_STATE    Diagnostic mode was not enabled or @p aGpio is not configured as output.
151  * @retval OT_ERROR_NOT_IMPLEMENTED  This function is not implemented or configured on the platform.
152  */
153 otError otPlatDiagGpioSet(uint32_t aGpio, bool aValue);
154 
155 /**
156  * Gets the gpio value.
157  *
158  * @param[in]   aGpio   The gpio number.
159  * @param[out]  aValue  A pointer where to put gpio value.
160  *
161  * @retval OT_ERROR_NONE             Successfully got the gpio value.
162  * @retval OT_ERROR_FAILED           A platform error occurred while getting the gpio value.
163  * @retval OT_ERROR_INVALID_ARGS     @p aGpio is not supported or @p aValue is NULL.
164  * @retval OT_ERROR_INVALID_STATE    Diagnostic mode was not enabled or @p aGpio is not configured as input.
165  * @retval OT_ERROR_NOT_IMPLEMENTED  This function is not implemented or configured on the platform.
166  */
167 otError otPlatDiagGpioGet(uint32_t aGpio, bool *aValue);
168 
169 /**
170  * Sets the gpio mode.
171  *
172  * @param[in]   aGpio   The gpio number.
173  * @param[out]  aMode   The gpio mode.
174  *
175  * @retval OT_ERROR_NONE             Successfully set the gpio mode.
176  * @retval OT_ERROR_FAILED           A platform error occurred while setting the gpio mode.
177  * @retval OT_ERROR_INVALID_ARGS     @p aGpio or @p aMode is not supported.
178  * @retval OT_ERROR_INVALID_STATE    Diagnostic mode was not enabled.
179  * @retval OT_ERROR_NOT_IMPLEMENTED  This function is not implemented or configured on the platform.
180  */
181 otError otPlatDiagGpioSetMode(uint32_t aGpio, otGpioMode aMode);
182 
183 /**
184  * Gets the gpio mode.
185  *
186  * @param[in]   aGpio   The gpio number.
187  * @param[out]  aMode   A pointer where to put gpio mode.
188  *
189  * @retval OT_ERROR_NONE             Successfully got the gpio mode.
190  * @retval OT_ERROR_FAILED           Mode returned by the platform is not implemented in OpenThread or a platform error
191  *                                   occurred while getting the gpio mode.
192  * @retval OT_ERROR_INVALID_ARGS     @p aGpio is not supported or @p aMode is NULL.
193  * @retval OT_ERROR_INVALID_STATE    Diagnostic mode was not enabled.
194  * @retval OT_ERROR_NOT_IMPLEMENTED  This function is not implemented or configured on the platform.
195  */
196 otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode);
197 
198 /**
199  * Set the radio raw power setting for diagnostics module.
200  *
201  * @param[in] aInstance               The OpenThread instance structure.
202  * @param[in] aRawPowerSetting        A pointer to the raw power setting byte array.
203  * @param[in] aRawPowerSettingLength  The length of the @p aRawPowerSetting.
204  *
205  * @retval OT_ERROR_NONE             Successfully set the raw power setting.
206  * @retval OT_ERROR_INVALID_ARGS     The @p aRawPowerSetting is NULL or the @p aRawPowerSettingLength is too long.
207  * @retval OT_ERROR_NOT_IMPLEMENTED  This method is not implemented.
208  */
209 otError otPlatDiagRadioSetRawPowerSetting(otInstance    *aInstance,
210                                           const uint8_t *aRawPowerSetting,
211                                           uint16_t       aRawPowerSettingLength);
212 
213 /**
214  * Get the radio raw power setting for diagnostics module.
215  *
216  * @param[in]      aInstance               The OpenThread instance structure.
217  * @param[out]     aRawPowerSetting        A pointer to the raw power setting byte array.
218  * @param[in,out]  aRawPowerSettingLength  On input, a pointer to the size of @p aRawPowerSetting.
219  *                                         On output, a pointer to the length of the raw power setting data.
220  *
221  * @retval OT_ERROR_NONE             Successfully set the raw power setting.
222  * @retval OT_ERROR_INVALID_ARGS     The @p aRawPowerSetting or @p aRawPowerSettingLength is NULL or
223  *                                   @aRawPowerSettingLength is too short.
224  * @retval OT_ERROR_NOT_FOUND        The raw power setting is not set.
225  * @retval OT_ERROR_NOT_IMPLEMENTED  This method is not implemented.
226  */
227 otError otPlatDiagRadioGetRawPowerSetting(otInstance *aInstance,
228                                           uint8_t    *aRawPowerSetting,
229                                           uint16_t   *aRawPowerSettingLength);
230 
231 /**
232  * Enable/disable the platform layer to use the raw power setting set by `otPlatDiagRadioSetRawPowerSetting()`.
233  *
234  * @param[in]  aInstance The OpenThread instance structure.
235  * @param[in]  aEnable   TRUE to enable or FALSE to disable the raw power setting.
236  *
237  * @retval OT_ERROR_NONE             Successfully enabled/disabled the raw power setting.
238  * @retval OT_ERROR_NOT_IMPLEMENTED  This method is not implemented.
239  */
240 otError otPlatDiagRadioRawPowerSettingEnable(otInstance *aInstance, bool aEnable);
241 
242 /**
243  * Start/stop the platform layer to transmit continuous carrier wave.
244  *
245  * @param[in]  aInstance The OpenThread instance structure.
246  * @param[in]  aEnable   TRUE to enable or FALSE to disable the platform layer to transmit continuous carrier wave.
247  *
248  * @retval OT_ERROR_NONE             Successfully enabled/disabled .
249  * @retval OT_ERROR_INVALID_STATE    The radio was not in the Receive state.
250  * @retval OT_ERROR_NOT_IMPLEMENTED  This method is not implemented.
251  */
252 otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable);
253 
254 /**
255  * Start/stop the platform layer to transmit stream of characters.
256  *
257  * @param[in]  aInstance The OpenThread instance structure.
258  * @param[in]  aEnable   TRUE to enable or FALSE to disable the platform layer to transmit stream.
259  *
260  * @retval OT_ERROR_NONE             Successfully enabled/disabled.
261  * @retval OT_ERROR_INVALID_STATE    The radio was not in the Receive state.
262  * @retval OT_ERROR_NOT_IMPLEMENTED  This function is not implemented.
263  */
264 otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable);
265 
266 /**
267  * Get the power settings for the given channel.
268  *
269  * @param[in]      aInstance               The OpenThread instance structure.
270  * @param[in]      aChannel                The radio channel.
271  * @param[out]     aTargetPower            The target power in 0.01 dBm.
272  * @param[out]     aActualPower            The actual power in 0.01 dBm.
273  * @param[out]     aRawPowerSetting        A pointer to the raw power setting byte array.
274  * @param[in,out]  aRawPowerSettingLength  On input, a pointer to the size of @p aRawPowerSetting.
275  *                                         On output, a pointer to the length of the raw power setting data.
276  *
277  * @retval  OT_ERROR_NONE             Successfully got the target power.
278  * @retval  OT_ERROR_INVALID_ARGS     The @p aChannel is invalid, @aTargetPower, @p aActualPower, @p aRawPowerSetting or
279  *                                    @p aRawPowerSettingLength is NULL or @aRawPowerSettingLength is too short.
280  * @retval  OT_ERROR_NOT_FOUND        The power settings for the @p aChannel was not found.
281  * @retval  OT_ERROR_NOT_IMPLEMENTED  This method is not implemented.
282  */
283 otError otPlatDiagRadioGetPowerSettings(otInstance *aInstance,
284                                         uint8_t     aChannel,
285                                         int16_t    *aTargetPower,
286                                         int16_t    *aActualPower,
287                                         uint8_t    *aRawPowerSetting,
288                                         uint16_t   *aRawPowerSettingLength);
289 
290 /**
291  * @}
292  */
293 
294 #ifdef __cplusplus
295 } // end of extern "C"
296 #endif
297 
298 #endif // OPENTHREAD_PLATFORM_DIAG_H_
299