shell.c File Reference

#include "includes.h"

Go to the source code of this file.

Data Structures

struct  ARGUMENT_CONTROL

Defines

#define DEBUG_COMMAND   0
#define ShellIdleState   0
#define ShellInitial0State   1
#define ShellInitial1State   2
#define ShellInitial2State   3
#define ShellWaitCommandState   4
#define ShellDispatchState   5
#define ShellExecuteState   6
#define ShellExecuteStopState   7
#define ExecuteIdleState   0
#define ExecuteStartState   1
#define ExecuteRunState   2
#define ItemInfo   0
#define ItemHelp   1
#define ARGUMENT_ARGV_MAX   10
#define ARGUMENT_INDEX_MAX   250
#define DEBUG_SHELL_DUMP   0
#define DEBUG_SHELL_KEY   0
#define DEBUG_SHELL_DONE   0
#define ArgumentIdleState   0
#define ArgumentInitialState   1
#define ArgumentRxState   2
#define MeetEscKey   0x01
#define HasEscXkey   0x02
#define HasPageDown   0x04
#define ArgumentSearchState   0
#define ArgumentGoThroughState   1
#define ArgumentDoneState   2

Functions

void ShellInitial (void)
void ShellSvc (void)
BOOL ShellStatusCheck (void)
void ShellArgumentInitial (void)
void ShellArgumentSvc (void)
void ShellArgumentParser (void)
INT8U ShellArgumentCheck (void)
void ShellArgumentExecute (unsigned char **Argv, unsigned char Argc)
void ShellArgumentReset (void)
void ShellArgumentBs (void)
void ShellArgumentDel (void)
void ShellArgumentKeyPut (unsigned char Data)
void ShellArgumentIns (void)
void ShellArgumentHome (void)
void ShellArgumentEnd (void)
void ShellArgumentPageUp (void)
void ShellArgumentPageDown (void)
void ShellArgumentArrowUp (void)
void ShellArgumentArrowDown (void)
void ShellArgumentArrowLeft (void)
void ShellArgumentArrowRight (void)

Variables

INT8U info [] = "info"
INT8U help [] = "help"
INT8UShellCommand []
INT8U Temp8u
INT16U Temp16u1
INT16U Temp16u2
INT32U Temp32u
SHELL_CONTROL ShellCtrl
ARGUMENT_CONTROL ArgumentCtrl
INT32U Address
INT32U Length
INT8U LineByteCounter
INT8U LineCounter


Define Documentation

#define ARGUMENT_ARGV_MAX   10

Definition at line 44 of file shell.c.

#define ARGUMENT_INDEX_MAX   250

Definition at line 45 of file shell.c.

#define ArgumentDoneState   2

Definition at line 356 of file shell.c.

#define ArgumentGoThroughState   1

Definition at line 355 of file shell.c.

#define ArgumentIdleState   0

Definition at line 63 of file shell.c.

#define ArgumentInitialState   1

Definition at line 64 of file shell.c.

#define ArgumentRxState   2

Definition at line 65 of file shell.c.

#define ArgumentSearchState   0

Definition at line 354 of file shell.c.

#define DEBUG_COMMAND   0

Definition at line 11 of file shell.c.

#define DEBUG_SHELL_DONE   0

Definition at line 61 of file shell.c.

#define DEBUG_SHELL_DUMP   0

Definition at line 59 of file shell.c.

#define DEBUG_SHELL_KEY   0

Definition at line 60 of file shell.c.

#define ExecuteIdleState   0

Definition at line 22 of file shell.c.

#define ExecuteRunState   2

Definition at line 24 of file shell.c.

#define ExecuteStartState   1

Definition at line 23 of file shell.c.

#define HasEscXkey   0x02

Definition at line 68 of file shell.c.

#define HasPageDown   0x04

Definition at line 69 of file shell.c.

#define ItemHelp   1

Definition at line 28 of file shell.c.

#define ItemInfo   0

Definition at line 27 of file shell.c.

#define MeetEscKey   0x01

Definition at line 67 of file shell.c.

#define ShellDispatchState   5

Definition at line 18 of file shell.c.

#define ShellExecuteState   6

Definition at line 19 of file shell.c.

#define ShellExecuteStopState   7

Definition at line 20 of file shell.c.

#define ShellIdleState   0

Definition at line 13 of file shell.c.

#define ShellInitial0State   1

Definition at line 14 of file shell.c.

#define ShellInitial1State   2

Definition at line 15 of file shell.c.

#define ShellInitial2State   3

Definition at line 16 of file shell.c.

#define ShellWaitCommandState   4

Definition at line 17 of file shell.c.


Function Documentation

void ShellArgumentArrowDown ( void   ) 

Definition at line 537 of file shell.c.

00537                                  {
00538     #if(DEBUG_SHELL_KEY==1)
00539         DebugStringPrint("\r\n key_arrow_down");
00540     #endif
00541 }

void ShellArgumentArrowLeft ( void   ) 

Definition at line 543 of file shell.c.

00543                                  {
00544     #if(DEBUG_SHELL_KEY==1)
00545         DebugStringPrint("\r\n key_arrow_left");
00546     #endif
00547     if(ArgumentCtrl.Index==0){;}
00548     else{
00549         ArgumentCtrl.Index--;
00550     }
00551 }

void ShellArgumentArrowRight ( void   ) 

Definition at line 553 of file shell.c.

00553                                   {
00554     #if(DEBUG_SHELL_KEY==1)
00555         DebugStringPrint("\r\n key_arrow_right");
00556     #endif
00557     if(ArgumentCtrl.Index==ArgumentCtrl.Put){;}
00558     else{
00559         if(ArgumentCtrl.Index<ArgumentCtrl.Put) ArgumentCtrl.Index++;
00560     }
00561 }

void ShellArgumentArrowUp ( void   ) 

Definition at line 531 of file shell.c.

00531                                {
00532     #if(DEBUG_SHELL_KEY==1)
00533         DebugStringPrint("\r\n key_arrow_up");
00534     #endif
00535 }

void ShellArgumentBs ( void   ) 

Definition at line 425 of file shell.c.

00425                           {
00426     unsigned char i;
00427     #if(DEBUG_SHELL_KEY==1)
00428         DebugStringPrint("\r\n key_bs");
00429     #endif
00430     if(ArgumentCtrl.Put==ArgumentCtrl.Index){
00431         if(ArgumentCtrl.Put==0){;}
00432         else{
00433             ArgumentCtrl.Put--;
00434             ArgumentCtrl.Index--;
00435         }
00436     }
00437     else{
00438         if(ArgumentCtrl.Index==0){;}
00439         else{
00440             ArgumentCtrl.Index--;
00441             ArgumentCtrl.Put--;
00442             i=ArgumentCtrl.Index;
00443             for(;i<=ArgumentCtrl.Put;i++){
00444                 ArgumentCtrl.Data[i]=ArgumentCtrl.Data[i+1];
00445             }
00446         }
00447     }
00448 }

INT8U ShellArgumentCheck ( void   ) 

Definition at line 408 of file shell.c.

00408                               {
00409     if(ArgumentCtrl.HasInput==TRUE) return TRUE;
00410     else return FALSE;
00411 }

void ShellArgumentDel ( void   ) 

Definition at line 450 of file shell.c.

00450                            {
00451     unsigned char i;
00452     #if(DEBUG_SHELL_KEY==1)
00453         DebugStringPrint("\r\n key_del");
00454     #endif
00455     if(ArgumentCtrl.Put==ArgumentCtrl.Index){;} // nothing to delete
00456     else{                                           // xxxxyyyy -> xxxyyyy
00457        ArgumentCtrl.Put--;
00458        i=ArgumentCtrl.Index;
00459        for(;i<=ArgumentCtrl.Put;i++){
00460            ArgumentCtrl.Data[i]=ArgumentCtrl.Data[i+1];
00461        }
00462     }
00463 }

void ShellArgumentEnd ( void   ) 

Definition at line 512 of file shell.c.

00512                            {
00513     #if(DEBUG_SHELL_KEY==1)
00514         DebugStringPrint("\r\n key_end");
00515     #endif
00516     ArgumentCtrl.Index=ArgumentCtrl.Put;
00517 }

void ShellArgumentExecute ( unsigned char **  Argv,
unsigned char  Argc 
)

Definition at line 414 of file shell.c.

00414                                                                   {
00415 
00416 }

void ShellArgumentHome ( void   ) 

Definition at line 505 of file shell.c.

00505                             {
00506     #if(DEBUG_SHELL_KEY==1)
00507         DebugStringPrint("\r\n key_home");
00508     #endif
00509     ArgumentCtrl.Index=0;
00510 }

void ShellArgumentInitial ( void   ) 

Definition at line 185 of file shell.c.

void ShellArgumentIns ( void   ) 

Definition at line 497 of file shell.c.

00497                            {
00498     #if(DEBUG_SHELL_KEY==1)
00499         DebugStringPrint("\r\n key_ins");
00500     #endif
00501     //if(ArgumentCtrl.Insert==TRUE) ArgumentCtrl.Insert=FALSE;
00502     //else ArgumentCtrl.Insert=TRUE;
00503 }

void ShellArgumentKeyPut ( unsigned char  Data  ) 

Definition at line 465 of file shell.c.

00465                                             {
00466     unsigned char i;
00467 
00468     if(ArgumentCtrl.Put==ArgumentCtrl.Index){
00469         ArgumentCtrl.Data[ArgumentCtrl.Index]=Data;
00470         if(ArgumentCtrl.Put<250){
00471             ArgumentCtrl.Put++;
00472             ArgumentCtrl.Index++;
00473         }
00474     }
00475     else{
00476         if(Data==0x0d){
00477             ArgumentCtrl.Data[ArgumentCtrl.Put]=Data;
00478         }
00479         else{
00480             if(ArgumentCtrl.Insert==TRUE){
00481                 i=ArgumentCtrl.Put;
00482                 for(;i>=ArgumentCtrl.Index;i--){
00483                     ArgumentCtrl.Data[i+1]=ArgumentCtrl.Data[i];
00484                 }
00485                 ArgumentCtrl.Data[ArgumentCtrl.Index]=Data;
00486                 if(ArgumentCtrl.Put<250) ArgumentCtrl.Put++;
00487                 ArgumentCtrl.Index++;
00488             }
00489             else{
00490                 ArgumentCtrl.Data[ArgumentCtrl.Index]=Data;
00491                 ArgumentCtrl.Index++;
00492             }
00493         }
00494     }
00495 }

void ShellArgumentPageDown ( void   ) 

Definition at line 525 of file shell.c.

00525                                 {
00526     #if(DEBUG_SHELL_KEY==1)
00527         DebugStringPrint("\r\n key_page_down");
00528     #endif
00529 }

void ShellArgumentPageUp ( void   ) 

Definition at line 519 of file shell.c.

00519                               {
00520     #if(DEBUG_SHELL_KEY==1)
00521         DebugStringPrint("\r\n key_page_up");
00522     #endif
00523 }

void ShellArgumentParser ( void   ) 

Definition at line 357 of file shell.c.

00357                               {
00358     unsigned char Index;
00359     unsigned char State;
00360     unsigned char Status;
00361     //unsigned char i;
00362     //unsigned char **ppArgv;
00363 
00364     Index=0;
00365     Status=0;
00366     ArgumentCtrl.Argc=0;
00367     State=ArgumentSearchState;
00368     while(1){
00369         switch(State){
00370             case ArgumentSearchState:
00371                 if(ArgumentCtrl.Data[Index]==0x20){;}       // " "
00372                 else if(ArgumentCtrl.Data[Index]==0x0d){  // enter key
00373                     ArgumentCtrl.Data[Index]=0;
00374                     ArgumentCtrl.Data[Index+1]=0x0d;
00375                     State=ArgumentDoneState;
00376                 }
00377                 else{
00378                     ArgumentCtrl.pArgv[ArgumentCtrl.Argc]=&ArgumentCtrl.Data[Index];
00379                     ArgumentCtrl.Argc++;
00380                     State=ArgumentGoThroughState;
00381                 }
00382                 break;
00383             case ArgumentGoThroughState:
00384                 if(ArgumentCtrl.Data[Index]==0x0d){
00385                     ArgumentCtrl.Data[Index]=0;
00386                     ArgumentCtrl.Data[Index+1]=0x0d;
00387                     State=ArgumentDoneState;
00388                 }
00389                 else if(ArgumentCtrl.Data[Index]==0x20){
00390                     ArgumentCtrl.Data[Index]=0;
00391                     State=ArgumentSearchState;
00392                 }
00393                 break;
00394             case ArgumentDoneState:
00395                 if(ArgumentCtrl.Put==250){ // too many input
00396                     ShellArgumentReset();
00397                     return;
00398                 }
00399                 ArgumentCtrl.HasInput=TRUE;
00400                 return;
00401                 //if(ArgumentCtrl.Argc!=0) ShellArgumentExecute(&ArgumentCtrl.pArgv,ArgumentCtrl.Argc);
00402                 //break;
00403         }
00404         Index++;
00405     }
00406 }

void ShellArgumentReset ( void   ) 

Definition at line 418 of file shell.c.

00418                              {
00419     ArgumentCtrl.Index=0;
00420     ArgumentCtrl.Put=0;
00421     ArgumentCtrl.Argc=0;
00422     ArgumentCtrl.HasInput=FALSE;
00423 }

void ShellArgumentSvc ( void   ) 

Definition at line 195 of file shell.c.

00195                            {
00196     unsigned char Data;
00197 
00198     switch(ArgumentCtrl.State){
00199         case ArgumentIdleState:
00200             break;
00201         case ArgumentRxState:
00202             if(Uart1RxBufferCheck()==BUFFER_EMPTY) return;
00203             Data=Uart1RxBufferGet();
00204             // process special keys
00205             if(Data==ASCII_ESC){
00206                 ArgumentCtrl.Status=0;
00207                 ArgumentCtrl.Status=MeetEscKey;
00208                 return;
00209             }
00210             else if(ArgumentCtrl.Status==MeetEscKey){
00211                 if(Data==0x5b){
00212                     ArgumentCtrl.Status=HasEscXkey;
00213                     return;
00214                 }
00215                 else{
00216                     ArgumentCtrl.Status=0; // meet single esc key, not a special key
00217                 }
00218             }
00219             else if(ArgumentCtrl.Status==HasEscXkey){
00220                 switch(Data){
00221                     case KEY_HOME:
00222                         ShellArgumentHome();
00223                         ArgumentCtrl.Status=0;
00224                         return;
00225                     case KEY_END:
00226                         ShellArgumentEnd();
00227                         ArgumentCtrl.Status=0;
00228                         return;
00229                     case KEY_PAGE_UP:
00230                         ShellArgumentPageUp();
00231                         ArgumentCtrl.Status=0;
00232                         return;
00233                     case KEY_PAGE_DOWN:
00234                         ArgumentCtrl.Status=HasPageDown;
00235                         return;
00236                     case KEY_LEFT_ARROW:
00237                         ShellArgumentArrowLeft();
00238                         ArgumentCtrl.Status=0;
00239                         return;
00240                     case KEY_RIGHT_ARROW:
00241                         ShellArgumentArrowRight();
00242                         ArgumentCtrl.Status=0;
00243                         return;
00244                     case KEY_UP_ARROW:
00245                         ShellArgumentArrowUp();
00246                         ArgumentCtrl.Status=0;
00247                         return;
00248                     case KEY_DOWN_ARROW:
00249                         ShellArgumentArrowDown();
00250                         ArgumentCtrl.Status=0;
00251                         return;
00252                     default:
00253                         ArgumentCtrl.Status=0;
00254                         return; // skip this code no matter what it is
00255                 }
00256                 //ArgumentCtrl.Status=0;
00257             }
00258             else if(ArgumentCtrl.Status==HasPageDown){
00259                 if(Data==0x4a){
00260                     ShellArgumentPageDown();
00261                     ArgumentCtrl.Status=0;
00262                     return;
00263                 }
00264                 ArgumentCtrl.Status=0;
00265             }
00266             switch(Data){
00267                 case  ASCII_NUL: // ^@
00268                     break;
00269                 case  ASCII_SOH: // ^A
00270                     break;
00271                 case  ASCII_STX: // ^B
00272                     break;
00273                 case  ASCII_ETX: // ^C
00274                     break;
00275                 case  ASCII_EOT: // ^D
00276                     break;
00277                 case  ASCII_ENQ: // ^E
00278                     break;
00279                 case  ASCII_ACK: // ^F
00280                     break;
00281                 case  ASCII_BEL: // ^G
00282                     break;
00283                 case  ASCII_BS:  // ^H
00284                     ShellArgumentBs();
00285                     //HidPs2KeyDispatch(Data);
00286                     //GuiTextBufferPut(Data);
00287                     break;
00288                 case  ASCII_HT:  // ^I
00289                     break;
00290                 case  ASCII_LF:  // ^J
00291                     break;
00292                 case  ASCII_VT:  // ^K
00293                     break;
00294                 case  ASCII_FF:  // ^L
00295                     break;
00296                 case  ASCII_CR:  // ^M
00297                     ShellArgumentKeyPut(Data);
00298                     //HidPs2KeyDispatch(Data);
00299                     //GuiTextBufferPut(Data);
00300                     ShellArgumentParser();
00301                     //ArgumentCtrl.Index=0;
00302                     //ArgumentCtrl.Put=0;
00303                     break;
00304                 case  ASCII_SO:  // ^N
00305                     break;
00306                 case  ASCII_SI:  // ^O
00307                     break;
00308                 case  ASCII_DLE: // ^P
00309                     break;
00310                 case  ASCII_DC1: // ^Q
00311                     break;
00312                 case  ASCII_DC2: // ^R
00313                     break;
00314                 case  ASCII_DC3: // ^S
00315                     break;
00316                 case  ASCII_DC4: // ^T
00317                     break;
00318                 case  ASCII_NAK: // ^U
00319                     break;
00320                 case  ASCII_SYN: // ^V
00321                     break;
00322                 case  ASCII_ETB: // ^W
00323                     break;
00324                 case  ASCII_CAN: // ^X
00325                     break;
00326                 case  ASCII_EM:  // ^Y
00327                     break;
00328                 case  ASCII_SUB: // ^Z
00329                     break;
00330                 //case  ASCII_ESC: // ^[
00331                 //    break;
00332                 case  ASCII_FS:   /* ^\  */
00333                     break;
00334                 case  ASCII_GS:  // ^]
00335                     break;
00336                 case  ASCII_RS:  // ^^
00337                     break;
00338                 case  ASCII_US:  // ^_
00339                     break;
00340                 case  ASCII_DEL: //
00341                     ShellArgumentDel();
00342                     break;
00343                 default:
00344                     if((Data>=0x20)&&(Data<=0x7e)){
00345                         ShellArgumentKeyPut(Data);
00346                         //HidPs2KeyDispatch(Data);
00347                         //GuiTextBufferPut(Data);
00348                     }
00349                     break;
00350             }
00351     }
00352 }

void ShellInitial ( void   ) 

Definition at line 75 of file shell.c.

00075                        {
00076     ShellCtrl.State=ShellInitial0State;
00077     ShellCtrl.Timer=0;
00078     ShellArgumentInitial();
00079 }

BOOL ShellStatusCheck ( void   ) 

Definition at line 180 of file shell.c.

00180                            {
00181     if(ShellCtrl.State>=ShellWaitCommandState) return TRUE;
00182     else return FALSE;
00183 }

void ShellSvc ( void   ) 

Definition at line 81 of file shell.c.

00081                    {
00082     INT8U i;
00083     INT16U j,k;
00084     INT8U Argc;
00085     INT8U *pData;
00086     INT8U **ppArgv;    // pointer of pArgv
00087     //void (*GotoStart)(void);
00088 
00089     switch(ShellCtrl.State){
00090         case ShellIdleState:
00091             break;
00092         case ShellInitial0State:
00093             ShellArgumentInitial();
00094             ShellCtrl.State=ShellInitial1State;
00095             break;
00096         case ShellInitial1State:
00097             DebugStringPrint("\r\n********************");
00098             DebugStringPrint("\r\n Hello,I am PIC18F87J10.");
00099             DebugStringPrint("\r\n********************");
00100             DebugStringPrint("\r\nPIC:>");
00101             //ShellCtrl.State=ShellIdleState;
00102             ShellCtrl.State=ShellWaitCommandState;
00103             break;
00104         case ShellInitial2State:
00105             ShellArgumentSvc();
00106             break;
00107         case ShellWaitCommandState:
00108             ShellArgumentSvc();
00109             if(ShellArgumentCheck()==TRUE) ShellCtrl.State=ShellDispatchState;
00110             break;
00111         case ShellDispatchState:
00112             Argc=ArgumentCtrl.Argc;
00113             ppArgv=(unsigned char **)&ArgumentCtrl.pArgv;
00114             if(Argc>0){
00115                 for(i=0;;i++){
00116                     if(ShellCommand[i]==(INT8U *)0){
00117                         DebugStringPrint("\r\n command not found");
00118                         break;
00119                     }
00120                     if(strcmp((char *)ArgumentCtrl.pArgv[0],(char *)ShellCommand[i])==0){
00121                         ShellCtrl.ExecuteItem=i;
00122                         ShellCtrl.ExecuteState=ExecuteStartState;
00123                         ShellCtrl.State=ShellExecuteState;
00124                         //ShellCtrl.State=ShellExecuteStopState;
00125                         return;
00126                     }
00127                 }
00128             }
00129             DebugStringPrint("\r\nPIC:>");
00130             ShellArgumentReset();
00131             ShellCtrl.State=ShellWaitCommandState;
00132             break;
00133         case ShellExecuteState:
00134             switch(ShellCtrl.ExecuteItem){
00135                 case ItemInfo:
00136                     switch(ShellCtrl.ExecuteState){
00137                         case ExecuteIdleState:
00138                             ShellCtrl.State=ShellExecuteStopState;
00139                             break;
00140                         case ExecuteStartState:
00141                             DebugStringPrint("\r\n system infomation");
00142                             DebugStringPrint("\r\n mcu:   PIC18F87J10");
00143                             DebugStringPrint("\r\n sdram: 3936");
00144                             DebugStringPrint("\r\n flash: 128k");
00145                             ShellCtrl.ExecuteState=ExecuteIdleState;
00146                             break;
00147                     }
00148                     break;
00149                 case ItemHelp:
00150                     switch(ShellCtrl.ExecuteState){
00151                         case ExecuteIdleState:
00152                             ShellCtrl.State=ShellExecuteStopState;
00153                             break;
00154                         case ExecuteStartState:
00155                             DebugStringPrint("\r\n command list:");
00156                             DebugStringPrint("\r\n info");
00157                             DebugStringPrint("\r\n help");
00158                             ShellCtrl.ExecuteState=ExecuteRunState;
00159                             break;
00160                         case ExecuteRunState:
00161                             ShellCtrl.ExecuteState=ExecuteIdleState;
00162                             break;
00163                     }
00164                     break; 
00165                 default:
00166                     ShellCtrl.State=ShellExecuteStopState;
00167                     break;
00168             }
00169             break;
00170         case ShellExecuteStopState:
00171             DebugStringPrint("\r\nPIC:>");
00172             ShellArgumentReset();
00173             ShellCtrl.State=ShellWaitCommandState;
00174             break;
00175         default:
00176             break;
00177     }
00178 }


Variable Documentation

Definition at line 72 of file shell.c.

Definition at line 71 of file shell.c.

INT8U help[] = "help"

Definition at line 31 of file shell.c.

INT8U info[] = "info"

Definition at line 30 of file shell.c.

Definition at line 72 of file shell.c.

Definition at line 73 of file shell.c.

Definition at line 73 of file shell.c.

Initial value:

{
info,
help,
(INT8U *)0
}

Definition at line 32 of file shell.c.

Definition at line 42 of file shell.c.

Definition at line 39 of file shell.c.

Definition at line 39 of file shell.c.

Definition at line 40 of file shell.c.

Definition at line 38 of file shell.c.


Generated on Tue Jul 7 20:39:55 2009 for A SIMPLE APPLICATION FOR PIC18F87J10 by  doxygen 1.5.9