iLLD_TC29x  1.0
Ifx_Shell.h
Go to the documentation of this file.
1 /**
2  * \file Ifx_Shell.h
3  * \brief Shell functions.
4  * \ingroup library_srvsw_sysse_comm_shell
5  *
6  * \version iLLD_1_0_0_11_0
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  * \defgroup library_srvsw_sysse_comm_shell Shell
25  * This module implements the Shell functions.
26  * \ingroup library_srvsw_sysse_comm
27  *
28  */
29 
30 #ifndef IFX_SHELL_H
31 #define IFX_SHELL_H 1
32 //----------------------------------------------------------------------------------------
33 #include "StdIf/IfxStdIf_DPipe.h"
34 //----------------------------------------------------------------------------------------
35 #define IFX_SHELL_NULL_CHAR '\0'
36 
37 #define IFX_SHELL_CMD_HISTORY_SIZE (10) /**<\brief Number of commands to store in history */
38 #define IFX_SHELL_CMD_LINE_SIZE (128) /**<\brief max command line IFX_SHELL_CMD_LINE_SIZE - 1 */
39 
40 #ifndef IFX_SHELL_COMMAND_LISTS
41 #define IFX_SHELL_COMMAND_LISTS (1) /**<\brief Number of command lists */
42 #endif
43 
44 #ifndef IFX_SHELL_PROMPT
45 #define IFX_SHELL_PROMPT "Shell>" /**<\brief Shell prompt */
46 #endif
47 
48 /** \brief Marker for end of command list */
49 #define IFX_SHELL_COMMAND_LIST_END {0, 0, 0, 0}
50 
51 /** \brief Marker for end of syntax list */
52 #define IFX_SHELL_SYNTAX_LIST_END {0, 0}
53 
54 /** \brief Signifies no item in use in command history list */
55 #define IFX_SHELL_CMD_HISTORY_NO_ITEM (-1)
56 //----------------------------------------------------------------------------------------
57 /** \brief Result code definition used after each executed Shell command */
58 typedef enum
59 {
65 
66 /** \brief Definition of a callback function which handles a Shell command */
67 typedef boolean (*Ifx_Shell_Call)(pchar args, void *data, IfxStdIf_DPipe *io);
68 
69 /** \brief Shell command object */
70 typedef struct
71 {
74  void *data;
77 
78 /** \brief Command line editing state */
79 typedef struct
80 {
81  char *cmdStr; /**< \brief Pointer to current string containing command line as so far processed */
82  Ifx_SizeT cursor; /**< \brief Pointer to variable containing position of cursor in so-far-processed command line */
83  Ifx_SizeT length; /**< \brief Pointer to variable containing total length of command line */
84  boolean historyAdd; /**< \brief If TRUE, when Enter is pressed, the current cmdLine should be added to the command history (in parent) */
85  Ifx_SizeT historyItem; /**< \brief Item ID in command history list, or IFX_SHELL_CMD_HISTORY_NO_ITEM if not using list (e.g. new command) */
87 
88 /** \brief Shell command processing state */
89 typedef enum
90 {
91  IFX_SHELL_CMD_STATE_NORMAL, /**< \brief Normal - no special sequences being processed */
92  IFX_SHELL_CMD_STATE_ESCAPE, /**< \brief Escape character has been pressed */
93  IFX_SHELL_CMD_STATE_ESCAPE_BRACKET, /**< \brief ESC [ pressed */
94  IFX_SHELL_CMD_STATE_ESCAPE_BRACKET_NUMBER /**< \brief ESC [ (number) pressed */
96 
97 /** \brief Shell protocol configuration */
98 typedef struct
99 {
100  boolean (*start)(void *protocol, IfxStdIf_DPipe *io);
101  void (*execute)(void *protocol);
102  void (*onStart)(void *protocol, void *data);
103  void *onStartData;
104  void *object;
105  boolean started;
107 
108 /** \brief Shell control flags */
109 typedef struct
110 {
111  uint16 showPrompt : 1;
112  uint16 enabled : 1;
113  uint16 sendResultCode : 1;
114  uint16 echo : 1;
115  uint16 echoError : 1;
117 
118 /** \brief internal Shell run-time data */
119 typedef struct
120 {
121  char echo[2];
122  char inputbuffer[IFX_SHELL_CMD_LINE_SIZE + 1];
127 
128 /**
129  * \brief Shell object definition
130  */
131 typedef struct
132 {
133  IfxStdIf_DPipe *io; /**< \brief Pointer to IfxStdIf_DPipe object used by the Shell */
134 
135  Ifx_Shell_Flags control; /**< \brief control flags */
136 
137  /** \brief Array of pointers to the history entries */
138  char *cmdHistory[IFX_SHELL_CMD_HISTORY_SIZE];
139 
140  /** \brief Current status of command line editing (saves passing many parameters around) */
142 
143  Ifx_Shell_Runtime locals; /**< \brief Runtime data */
144 
145  /** \brief Array of pointers to command list. The pointed location shall be constant
146  * during Shell lifetime, e.g. stored in non-volatile memory or as global variable */
148 
149  Ifx_Shell_Protocol protocol; /**< \brief Protocol handler data */
150 } Ifx_Shell;
151 
152 /**
153  * \brief Shell configuration.
154  */
155 typedef struct
156 {
157  IfxStdIf_DPipe *standardIo; /**<\brief Pointer to a IfxStdIf_DPipe object used by the Shell */
158  boolean echo; /**<\brief Specifies whether each command shall be echoed back to user */
159  boolean showPrompt; /**<\brief Specifies whether the IFX_SHELL_PROMPT shall be displayed after each command */
160  boolean sendResultCode; /**<\brief Specifies whether the Ifx_Shell_ResultCode shall be sent to user */
161  const Ifx_Shell_Command *commandList[IFX_SHELL_COMMAND_LISTS]; /**< \brief Specifies pointer to the command list */
162  Ifx_Shell_Protocol protocol; /**<\brief Configuration for the Ifx_Shell_Protocol */
164 
165 typedef struct
166 {
170 
171 //----------------------------------------------------------------------------------------
172 /** \addtogroup library_srvsw_sysse_comm_shell
173  * \{ */
174 
175 /** \name Basic functionality
176  * \{ */
177 
178 /** Set the config default parameter
179  *
180  * \param config Pointer to the configuration structure to be initialized
181  */
183 
184 /**
185  * \brief Initialize the shell
186  * \param shell Pointer to the \ref Ifx_Shell object
187  * \param config Pointer to the configuration structure
188  */
189 IFX_EXTERN boolean Ifx_Shell_init(Ifx_Shell *shell, const Ifx_Shell_Config *config);
190 
191 /**
192  * \brief Deinitialise the shell
193  * \param shell Pointer to the \ref Ifx_Shell object
194  */
196 
197 /**
198  * \brief Clear the receive buffer and enable the shell
199  * \param shell Pointer to the \ref Ifx_Shell object
200  */
202 
203 /**
204  * \brief Disable the shell
205  * \param shell Pointer to the \ref Ifx_Shell object
206  */
208 
209 /**
210  * \brief Process the shell.
211  *
212  * This function shall be called within a loop or periodic timer to guarantee the correct
213  * processing of the incoming/received data.
214  *
215  * \param shell Pointer to the \ref Ifx_Shell object
216  */
218 
219 /** \} */
220 //----------------------------------------------------------------------------------------
221 /** \name Parsing functions
222  * \{ */
223 
224 /**
225  * \brief Within the context of Shell.call, skip the whitespaces of the args string.
226  * \param args Pointer to the original string
227  * \return Pointer to the string after skipping the whitespaces
228  */
230 
231 /**
232  * \brief Match string pointed by the *argsPtr with a given token
233  * \param argsPtr Pointer to the argument null-terminated string
234  * \param token Pointer to the token string to match
235  * \retval TRUE if the given token match with the string pointed by argsPtr
236  */
237 IFX_EXTERN boolean Ifx_Shell_matchToken(pchar *argsPtr, pchar token);
238 
239 /**
240  * \brief Parse a token
241  * \param argsPtr Pointer to the argument null-terminated string
242  * \param tokenBuffer Pointer to the value storage
243  * \param bufferLength Maximum parsing length
244  */
245 IFX_EXTERN boolean Ifx_Shell_parseToken(pchar *argsPtr, char *tokenBuffer, int bufferLength);
246 
247 /**
248  * \brief Parse an address
249  * \param argsPtr Pointer to the argument null-terminated string
250  * \param address Pointer to the value storage
251  */
252 IFX_EXTERN boolean Ifx_Shell_parseAddress(pchar *argsPtr, void **address);
253 
254 /**
255  * \brief Parse a signed 32-bit integer value
256  * \param argsPtr Pointer to the argument null-terminated string
257  * \param value Pointer to the value storage
258  */
259 IFX_EXTERN boolean Ifx_Shell_parseSInt32(pchar *argsPtr, sint32 *value);
260 
261 /**
262  * \brief Parse an unsigned 32-bit integer value
263  * \param argsPtr Pointer to the argument null-terminated string
264  * \param value Pointer to the value storage
265  * \param hex if TRUE, hex parsing will be done, else decimal parsing
266  */
267 IFX_EXTERN boolean Ifx_Shell_parseUInt32(pchar *argsPtr, uint32 *value, boolean hex);
268 
269 /**
270  * \brief Parse a signed 64-bit integer value
271  * \param argsPtr Pointer to the argument null-terminated string
272  * \param value Pointer to the value storage
273  */
274 IFX_EXTERN boolean Ifx_Shell_parseSInt64(pchar *argsPtr, sint64 *value);
275 
276 /**
277  * \brief Parse an unsigned 64-bit integer value
278  * \param argsPtr Pointer to the argument null-terminated string
279  * \param value Pointer to the value storage
280  * \param hex if TRUE, hex parsing will be done, else decimal parsing
281  */
282 IFX_EXTERN boolean Ifx_Shell_parseUInt64(pchar *argsPtr, uint64 *value, boolean hex);
283 
284 /**
285  * \brief Parse a 64-bit (double precision) floating-point value
286  * \param argsPtr Pointer to the argument null-terminated string
287  * \param value Pointer to the value storage
288  */
289 IFX_EXTERN boolean Ifx_Shell_parseFloat64(pchar *argsPtr, float64 *value);
290 
291 /**
292  * \brief Parse a 32-bit (single precision) floating-point value
293  * \param argsPtr Pointer to the argument null-terminated string
294  * \param value Pointer to the value storage
295  */
296 IFX_EXTERN boolean Ifx_Shell_parseFloat32(pchar *argsPtr, float32 *value);
297 
298 /** \} */
299 //----------------------------------------------------------------------------------------
300 /** \name Command list functions
301  * \{ */
302 
303 /**
304  * \brief Find command in commandList
305  * \param commandList Pointer to the first entry of an array of \ref Ifx_Shell_Command
306  * \param commandLine Pointer to null-terminated string containings the command to search.
307  * \param args Pointer to the argument null-terminated string
308  */
309 IFX_EXTERN const Ifx_Shell_Command *Ifx_Shell_commandFind(const Ifx_Shell_Command *commandList, pchar commandLine, pchar *args);
310 
311 /**
312  * \brief Implementation of \ref Ifx_Shell_Call. Show the help menu from single command list.
313  * \param prefix Prefix for each command in the commandList
314  * \param commandList Pointer to an array of Ifx_Shell_Command
315  * \param io Pointer to the IfxStdIf_DPipe object
316  */
317 IFX_EXTERN boolean Ifx_Shell_showHelpSingle(pchar prefix, const void *commandList, IfxStdIf_DPipe *io);
318 
319 /**
320  * \brief Implementation of \ref Ifx_Shell_Call. Show the help menu and list of commands.
321  * \param args The argument null-terminated string
322  * \param shellPtr Pointer to a Shell object
323  * \param io Pointer to \ref IfxStdIf_DPipe object
324  */
325 IFX_EXTERN boolean Ifx_Shell_showHelp(pchar args, void *shellPtr, IfxStdIf_DPipe *io);
326 
328 
329 /** \} */
330 //----------------------------------------------------------------------------------------
331 /** \name Sub protocol functions
332  * \{ */
333 
334 /**
335  * \brief Implementation of \ref Ifx_Shell_Call. Start the \ref ShellBb protocol.
336  * \param args The argument null-terminated string
337  * \param data Pointer to \ref Ifx_Shell object
338  * \param io Pointer to \ref IfxStdIf_DPipe object
339  */
340 IFX_EXTERN boolean Ifx_Shell_protocolStart(pchar args, void *data, IfxStdIf_DPipe *io);
341 
342 /**
343  * \brief Implementation of \ref Ifx_Shell_Call. Start the \ref ShellBb protocol.
344  * \param args The argument null-terminated string
345  * \param data Pointer to \ref Ifx_Shell object
346  * \param io Pointer to \ref IfxStdIf_DPipe object
347  */
348 IFX_EXTERN boolean Ifx_Shell_bbProtocolStart(pchar args, void *data, IfxStdIf_DPipe *io);
349 
350 /** \} */
351 //----------------------------------------------------------------------------------------
352 /** \} */
353 
354 #endif