Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor10915371091537 Using the Shell Commands Anchor10953791095379To use shell commands, four files, in addition to the generic file system files, must be included in the build:anchor10953801095380

  • fs_shell.c

...

...

  • fs_shell.h

...

  • shell.c (located in \Micrium\Software\uC-Shell\Source)

...

  • shell.h (located in \Micrium\Software\uC-Shell\Source)

...

10915431091543The file fs_shell.h and shell.h must also be #included in any application or header files initialize µC/Shell or handle shell commands. The shell command configuration file (fs_shell_cfg.h) should be copied to your application directory and modified. The following directories must be on the project include path:anchor10915441091544

  • \Micrium\Software\uC-FS\Cmd

...

  • \Micrium\Software\uC-Shell\Source

...

µC/Shell with the µC/FS shell commands is initialized in Listing F-1"Initializing µC/Shell". The file system initialization (FS_Init()) function should have previously been called.anchor

Code Block

...

language

...

1092253
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
1092253
cpp

...

{

{
    CPU_BOOLEAN  ok;
ok =

    ok = Shell_Init();
if

    if (ok == DEF_FAIL)
{ return
 {
        return (DEF_FAIL);
} ok =

    }
    
    ok = FSShell_Init();
if

    if (ok == DEF_FAIL)
{ return
 {
        return (DEF_FAIL;
} return

    }
    return (DEF_OK);
}
titleInitializing µC/Shell
CPU_BOOLEAN  App_ShellInit (void)
Anchor
10922541092254
Anchor
10922551092255
Anchor
10922561092256
Anchor
10922571092257
Anchor
10922581092258
Anchor
10922591092259
Anchor
10922601092260
Anchor
10922611092261
Anchor
10922621092262
Anchor
10922631092263
Anchor
10922641092264
Anchor
10922651092265
Anchor
10922661092266

...


}

It’s assumed that the application will create a task to receive input from a terminal; this task should be written as shown in Listing F-2"Executing shell commands & handling shell output".anchor

Code Block

...

language

...

void
HTML Table
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10922831092283
cpp

...

{ CPU_CHAR

{
    CPU_CHAR          cmd_line[MAX_CMD_LEN];

    SHELL_ERR
err;
         err;
    SHELL_CMD_PARAM   cmd_param;

    CPU_CHAR          cwd_path[FS_CFG_FULL_ NAME_LEN +
1u];   /* Init cmd param (see Note #1). */
 1u];
 
                                                  (1)
    Str_Copy(&cwd_path[0], (CPU_CHAR *)"\\");

    cmd_param.pcur_working_dir = (void *)cwd_path[0];

    cmd_param.pout_opt         = (void *)0;
  while

 
    while (DEF_TRUE)
{
 {
        App_ShellIn(cmd_line, MAX_CMD_LEN);
/* Rd cmd (see Note #2). */ /* Exec cmd (see Note #3). */
       (2)
                                                  (3)
        Shell_Exec(cmd_line, App_ShellOut, &cmd_param, &err);
switch

        switch (err)
{ case
 {
            case SHELL_ERR_CMD_NOT_FOUND:
case

            case SHELL_ERR_CMD_SEARCH:
case

            case SHELL_ERR_ARG_TBL_FULL:

                 App_ShellOut("Command not found\r\n", 19, cmd_param.pout_opt);
break; default: break; } } }   /*

                 break;
            default:
                 break;
        }    
    }
}
 
/*
**************************************************************************************
*

*                                    App_ShellIn()

*******************************************************************************
1
*******

*/

CPU_INT16S  App_ShellIn (CPU_CHAR
*pbuf, CPU_INT16U buf_len) { /* $$$$ Store line from terminal/command line into ‘pbuf’; return length of line. */ } /*
    *pbuf,       
                         CPU_INT16U   buf_len)
{
    /* $$$$ Store line from terminal/command line into 'pbuf'; return length of line. */
}
/*
**************************************************************************************
*

*                                    App_ShellOut()

*******************************************************************************
1
*******

*/

CPU_INT16S  App_ShellOut (CPU_CHAR
*pbuf, CPU_INT16U buf_len, void *popt) { /* $$$$ Output ‘pbuf’ data on terminal/command line; return nbr bytes tx’d. */ }
titleExecuting shell commands & handling shell output
void  App_ShellTask (void *p_arg)
Anchor
10922841092284
Anchor
10922851092285
Anchor
10922861092286
Anchor
10922871092287
Anchor
10922881092288
Anchor
10924051092405
Anchor
10922891092289
Anchor
10922901092290
Anchor
10922911092291
Anchor
10922921092292
Anchor
10922931092293
Anchor
10924121092412
Anchor
10922941092294
Anchor
10922951092295
Anchor
10922961092296
Anchor
10922971092297
Anchor
10922981092298
Anchor
10922991092299
Anchor
10923001092300
Anchor
10923011092301
Anchor
10923021092302
Anchor
10923031092303
Anchor
10923041092304
Anchor
10923051092305
Anchor
10923061092306
Anchor
10923071092307
Anchor
10923591092359
Anchor
10923081092308
Anchor
10923091092309
Anchor
10923101092310
Anchor
10923111092311
Anchor
10923121092312
Anchor
10923131092313
Anchor
10923141092314
Anchor
10923151092315
Anchor
10923161092316
Anchor
10923171092317
Table Row (tr)
Table Cell (td)
Anchor
10924251092425
Anchor
10923831092383
Anchor
10923841092384
Anchor
10923851092385
Anchor
10923861092386
Anchor
10923871092387
Anchor
10923881092388
Anchor
10923891092389
Anchor
10923901092390
Anchor
10923911092391
Anchor
10923921092392

...

    *pbuf,
                          CPU_INT16U   buf_len,
                          void        *popt)
{
    /* $$$$ Output 'pbuf' data on terminal/command line;  return nbr bytes tx'd. */
}


Panel
bgColor#f0f0f0

(1) The SHELL_CMD_PARAM structure that will be passed to Shell_Exec() must be initialized. The pcur_working_dir member must be assigned a pointer to a string of at

...

least FS_SHELL_CFG_MAX_PATH_LEN

...

 characters. This string must have been initialized to the default working directory path; if the root directory, “\”.

...

(2) The next command, ending with a newline, should be read from the command line.

...

(3) The received command should be executed

...

with Shell_Exec(). If the command is a valid command, the appropriate command function will be called. For example, the command

...

fs_

...

lswill result

...

in FSShell_ls()

...

 in fs_shell.c

...

 being called. FSShell_ls()

...

 will then print the entries in the working directory to the command line with the output

...

function App_ShellOut(), passed as the second argument

...

of Shell_Exec().