#include "config.h"#include "compiler.h"
Go to the source code of this file.
Defines | |
| #define | ABORT_CHAR CTRL_C |
| #define | BKSPACE_CHAR 0x08 |
| #define | CMD_BACKWARD 0x05 |
| #define | CMD_FORWARD 0x04 |
| #define | CMD_GET_ID 0x07 |
| #define | CMD_GET_STATUS0 0x08 |
| #define | CMD_GET_STATUS1 0x09 |
| #define | CMD_HELP 0x01 |
| #define | CMD_NONE 0x00 |
| #define | CMD_RUN 0x02 |
| #define | CMD_SET_SPEED 0x06 |
| #define | CMD_STOP 0x03 |
| #define | CR 0x0D |
| #define | CTRL_C 0x03 |
| #define | CTRL_Q 0x11 |
| #define | LF 0x0A |
| #define | MSG_ER_CMD_NOT_FOUND "Unknown Command" |
| #define | MSG_HELP "\r\ru : run\r\st : stop\r\fw : forward\r\bw : backward\r\ss : set speed\r\gi : get id\" |
| #define | MSG_PROMPT "\r>" |
| #define | MSG_WELCOME "\rATMEL Motor Control Interface" |
| #define | QUIT_APPEND CTRL_Q |
| #define | STR_BACKWARD "bw" |
| #define | STR_FORWARD "fw" |
| #define | STR_GET_ID "gi" |
| #define | STR_GET_STATUS0 "g0" |
| #define | STR_GET_STATUS1 "g1" |
| #define | STR_HELP "help" |
| #define | STR_RUN "ru" |
| #define | STR_SET_SPEED "ss" |
| #define | STR_STOP "st" |
Functions | |
| void | build_cmd (void) |
| get the full command line to be interpreted. | |
| U8 | mystrncmp (U8 *str1, U8 code *str2, U8 i) |
| compares two strings located in flash code area. | |
| void | parse_cmd (void) |
| decodes full command line into command type and arguments | |
| void | print_msg (U8 code *str) |
| Display an ASCII code string. | |
| void | ushell_task (void) |
| Entry point of the explorer task management. | |
| void | ushell_task_init (void) |
| This function initializes the hardware/software ressources required for ushell task. | |
Variables | |
| volatile Bool | ushell_active |
| #define ABORT_CHAR CTRL_C |
| #define BKSPACE_CHAR 0x08 |
| #define CMD_BACKWARD 0x05 |
| #define CMD_FORWARD 0x04 |
| #define CMD_GET_ID 0x07 |
| #define CMD_GET_STATUS0 0x08 |
| #define CMD_GET_STATUS1 0x09 |
| #define CMD_HELP 0x01 |
| #define CMD_NONE 0x00 |
| #define CMD_RUN 0x02 |
| #define CMD_SET_SPEED 0x06 |
| #define CMD_STOP 0x03 |
| #define CR 0x0D |
| #define CTRL_C 0x03 |
Definition at line 41 of file ushell_task.h.
| #define CTRL_Q 0x11 |
Definition at line 40 of file ushell_task.h.
| #define LF 0x0A |
Definition at line 39 of file ushell_task.h.
| #define MSG_ER_CMD_NOT_FOUND "Unknown Command" |
Definition at line 60 of file ushell_task.h.
| #define MSG_HELP "\r\ru : run\r\st : stop\r\fw : forward\r\bw : backward\r\ss : set speed\r\gi : get id\" |
Definition at line 61 of file ushell_task.h.
| #define MSG_PROMPT "\r>" |
Definition at line 58 of file ushell_task.h.
| #define MSG_WELCOME "\rATMEL Motor Control Interface" |
Definition at line 59 of file ushell_task.h.
| #define QUIT_APPEND CTRL_Q |
Definition at line 44 of file ushell_task.h.
| #define STR_BACKWARD "bw" |
Definition at line 51 of file ushell_task.h.
| #define STR_FORWARD "fw" |
Definition at line 50 of file ushell_task.h.
| #define STR_GET_ID "gi" |
Definition at line 53 of file ushell_task.h.
| #define STR_GET_STATUS0 "g0" |
Definition at line 54 of file ushell_task.h.
| #define STR_GET_STATUS1 "g1" |
Definition at line 55 of file ushell_task.h.
| #define STR_HELP "help" |
Definition at line 49 of file ushell_task.h.
| #define STR_RUN "ru" |
Definition at line 47 of file ushell_task.h.
| #define STR_SET_SPEED "ss" |
Definition at line 52 of file ushell_task.h.
| #define STR_STOP "st" |
Definition at line 48 of file ushell_task.h.
| void build_cmd | ( | void | ) |
get the full command line to be interpreted.
| none |
Definition at line 159 of file ushell_task.c.
References ABORT_CHAR, BKSPACE_CHAR, cmd_str, CR, i_str, parse_cmd(), uart_getchar(), uart_putchar(), and uart_test_hit().
Referenced by ushell_task().
00160 { 00161 U8 c; 00162 00163 if (uart_test_hit()) //Something new of the UART ? 00164 { 00165 c=uart_getchar(); 00166 switch (c) 00167 { 00168 case CR: 00169 cmd_str[i_str]=0; //Add NULL char 00170 parse_cmd(); //Decode the command 00171 i_str=0; 00172 break; 00173 case ABORT_CHAR: //^c abort cmd 00174 i_str=0; 00175 printf("\r#"); 00176 break; 00177 case BKSPACE_CHAR: //backspace 00178 if(i_str>0) 00179 { 00180 uart_putchar(c); 00181 uart_putchar(' '); 00182 uart_putchar(c); 00183 } 00184 if(i_str>=1) 00185 { 00186 i_str--; 00187 } 00188 break; 00189 00190 default: 00191 cmd_str[i_str++]=c; //append to cmd line 00192 break; 00193 } 00194 } 00195 }
compares two strings located in flash code area.
| *str1 | ||
| *str2 |
Definition at line 285 of file ushell_task.c.
Referenced by parse_cmd().
00287 { 00288 U8 j; 00289 for(j=0;j<=i;j++) 00290 { 00291 #ifndef __GNUC__ 00292 if(*str1!=*str2) 00293 #else 00294 if( *str1 != pgm_read_byte_near((unsigned int)str2)) 00295 #endif 00296 { 00297 return FALSE; 00298 } 00299 str1++;str2++; 00300 } 00301 return TRUE; 00302 }
| void parse_cmd | ( | void | ) |
decodes full command line into command type and arguments
This function allows to set the cmd_type to the command type decoded with its respective arguments par_str1 and par_str2
| none |
Definition at line 207 of file ushell_task.c.
References cmd, CMD_BACKWARD, CMD_FORWARD, CMD_GET_ID, CMD_GET_STATUS0, CMD_GET_STATUS1, CMD_HELP, CMD_RUN, CMD_SET_SPEED, CMD_STOP, cmd_str, cmd_type, FALSE, i_str, LSB, MSB, msg_er_cmd_not_found, msg_prompt, mystrncmp(), par_str1, par_str2, print_msg(), str_backward, str_forward, str_get_id, str_get_status0, str_get_status1, str_help, str_run, str_set_speed, str_stop, and TRUE.
Referenced by build_cmd().
00208 { 00209 U8 i=0; 00210 U8 j; 00211 00212 //Get command type 00213 for(i=0;cmd_str[i]!=' ' && i<=i_str;i++); 00214 cmd=TRUE; 00215 00216 //Decode command type 00217 if ( mystrncmp(cmd_str,str_run,i-1)) 00218 { cmd_type=CMD_RUN; } 00219 else if ( mystrncmp(cmd_str,str_stop,i-1)) 00220 { cmd_type=CMD_STOP; } 00221 else if ( mystrncmp(cmd_str,str_help,i-1)) 00222 { cmd_type=CMD_HELP; } 00223 else if ( mystrncmp(cmd_str,str_forward,i-1)) 00224 { cmd_type=CMD_FORWARD; } 00225 else if ( mystrncmp(cmd_str,str_backward,i-1)) 00226 { cmd_type=CMD_BACKWARD; } 00227 else if ( mystrncmp(cmd_str,str_set_speed,i-1)) 00228 { cmd_type=CMD_SET_SPEED; } 00229 else if ( mystrncmp(cmd_str,str_get_id,i-1)) 00230 { cmd_type=CMD_GET_ID; } 00231 else if ( mystrncmp(cmd_str,str_get_status0,i-1)) 00232 { cmd_type=CMD_GET_STATUS0; } 00233 else if ( mystrncmp(cmd_str,str_get_status1,i-1)) 00234 { cmd_type=CMD_GET_STATUS1; } 00235 else 00236 { 00237 if(i_str) 00238 { 00239 print_msg(msg_er_cmd_not_found); 00240 } 00241 print_msg(msg_prompt); 00242 cmd=FALSE; 00243 return; 00244 } 00245 00246 //Get first arg (if any) 00247 if(++i<i_str) 00248 { 00249 j=0; 00250 for(;(cmd_str[i]!=' ')&&(i<i_str);i++) 00251 { 00252 LSB(par_str1[j])=cmd_str[i]; 00253 MSB(par_str1[j])=0; 00254 j++; 00255 } 00256 LSB(par_str1[j])=0;MSB(par_str1[j])=0; 00257 } 00258 else { return; } 00259 00260 //Get second arg (if any) 00261 if(++i<i_str) 00262 { 00263 j=0; 00264 for(;(cmd_str[i]!=' ')&&(i<i_str);i++) 00265 { 00266 LSB(par_str2[j])=cmd_str[i]; 00267 MSB(par_str2[j])=0; 00268 j++; 00269 } 00270 LSB(par_str2[j])=0;MSB(par_str2[j])=0; 00271 } 00272 else { return; } 00273 00274 }
| void print_msg | ( | U8 code * | str | ) |
Display an ASCII code string.
| *str,: | pointer to string located in flash area |
Definition at line 312 of file ushell_task.c.
References uart_putchar().
Referenced by parse_cmd(), ushell_task(), and ushell_task_init().
00314 { 00315 U8 c; 00316 #ifndef __GNUC__ 00317 c=*str++; 00318 while(c!=0) 00319 { 00320 uart_putchar(c); 00321 c=*str++; 00322 } 00323 #else // AVRGCC does not support point to PGM space 00324 c=pgm_read_byte_near((unsigned int)str++); 00325 while(c!=0) 00326 { 00327 uart_putchar(c); 00328 c=pgm_read_byte_near((unsigned int)str++); 00329 } 00330 #endif 00331 00332 }
| void ushell_task | ( | void | ) |
Entry point of the explorer task management.
This function links perform ushell task decoding to access file system functions.
| none |
Definition at line 90 of file ushell_task.c.
References BOARD_ID, build_cmd(), CCW, cmd, CMD_BACKWARD, CMD_FORWARD, CMD_GET_ID, CMD_GET_STATUS0, CMD_GET_STATUS1, CMD_HELP, CMD_NONE, CMD_RUN, CMD_SET_SPEED, CMD_STOP, cmd_type, convert_param1(), FALSE, mc_disable_during_inrush(), mci_backward(), mci_direction, mci_forward(), mci_get_measured_current(), mci_get_measured_speed(), mci_run(), mci_run_stop, mci_set_ref_speed(), mci_stop(), msg_er_cmd_not_found, msg_help, msg_prompt, param1, print_hex16(), print_msg(), REV_ID, SOFT_ID, TRUE, uart_putchar(), and ushell_active.
Referenced by main().
00091 { 00092 U8 status = 0; 00093 00094 if(cmd==FALSE) 00095 { 00096 build_cmd(); 00097 } 00098 else 00099 { 00100 switch (cmd_type) 00101 { 00102 case CMD_HELP: 00103 print_msg(msg_help); 00104 break; 00105 case CMD_RUN: 00106 mci_run(); 00107 break; 00108 case CMD_STOP: 00109 mci_stop(); 00110 break; 00111 case CMD_FORWARD: 00112 mci_forward(); 00113 break; 00114 case CMD_BACKWARD: 00115 mci_backward(); 00116 break; 00117 case CMD_SET_SPEED: 00118 convert_param1(); 00119 mc_disable_during_inrush(); 00120 mci_set_ref_speed((U8)param1); 00121 break; 00122 case CMD_GET_ID: 00123 print_hex16(BOARD_ID); 00124 uart_putchar(' '); 00125 print_hex16(SOFT_ID); 00126 uart_putchar(' '); 00127 print_hex16(REV_ID); 00128 break; 00129 case CMD_GET_STATUS0: 00130 status = 0; 00131 if (mci_direction == CCW) {status |= (1<<3);} 00132 if (mci_run_stop == TRUE) {status |= (1<<2);} 00133 print_hex16(status); 00134 uart_putchar(' '); 00135 print_hex16(mci_get_measured_speed()); 00136 uart_putchar(' '); 00137 print_hex16(mci_get_measured_current()); 00138 ushell_active = TRUE; 00139 break; 00140 case CMD_GET_STATUS1: 00141 print_hex16(0xDEA); 00142 uart_putchar(' '); 00143 print_hex16(0x123); 00144 break; 00145 default: //Unknown command 00146 print_msg(msg_er_cmd_not_found); 00147 } 00148 cmd_type=CMD_NONE; 00149 cmd=FALSE; 00150 print_msg(msg_prompt); 00151 } 00152 }
| void ushell_task_init | ( | void | ) |
This function initializes the hardware/software ressources required for ushell task.
| none |
Definition at line 69 of file ushell_task.c.
References cmd, CMD_NONE, cmd_type, FALSE, msg_prompt, msg_welcome, print_msg(), and uart_init().
Referenced by main().
00070 { 00071 uart_init(); 00072 print_msg(msg_welcome); 00073 print_msg(msg_prompt); 00074 cmd=FALSE; 00075 cmd_type=CMD_NONE; 00076 }
| volatile Bool ushell_active |
1.5.7.1