ushell_task.c File Reference

#include "config.h"
#include "ushell_task.h"
#include "ascii.h"
#include "uart/uart_lib.h"
#include "mc_interface.h"
#include "mc_drv.h"

Include dependency graph for ushell_task.c:

Go to the source code of this file.

Functions

void build_cmd (void)
 get the full command line to be interpreted.
void convert_param1 (void)
 convert param1 to binaire.
void convert_param2 (void)
 convert param2 to binaire.
U16 debug_get_value1 (void)
U16 debug_get_value2 (void)
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_hex16 (U16 value)
 Display an U16 with hexa form.
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

static U8 cmd
static U8 cmd_str [26]
static U8 cmd_type
static U8 i_str = 0
U8 code msg_er_cmd_not_found [] = MSG_ER_CMD_NOT_FOUND
U8 code msg_help [] = MSG_HELP
U8 code msg_prompt [] = MSG_PROMPT
U8 code msg_welcome [] = MSG_WELCOME
static U16 par_str1 [8]
static U16 par_str2 [8]
static U16 param1
static U16 param2
S16 speed_error
 Error calculation.
U8 code str_backward [] = STR_BACKWARD
U8 code str_forward [] = STR_FORWARD
U8 code str_get_id [] = STR_GET_ID
U8 code str_get_status0 [] = STR_GET_STATUS0
U8 code str_get_status1 [] = STR_GET_STATUS1
U8 code str_help [] = STR_HELP
U8 code str_run [] = STR_RUN
U8 code str_set_speed [] = STR_SET_SPEED
U8 code str_stop [] = STR_STOP
volatile Bool ushell_active = FALSE


Function Documentation

void build_cmd ( void   ) 

get the full command line to be interpreted.

Parameters:
none 
Returns:
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 }

Here is the call graph for this function:

void convert_param1 ( void   ) 

convert param1 to binaire.

Parameters:
none 
Returns:
none

Definition at line 339 of file ushell_task.c.

References ascii_to_bin(), par_str1, and param1.

Referenced by ushell_task().

00340 {
00341    U8 i = 0;
00342    param1 = 0;
00343    while ( par_str1[i] != 0 )
00344    {
00345       param1 = param1 << 4;
00346       param1 = param1 + ascii_to_bin(par_str1[i]);
00347       i++;
00348    }
00349 }

Here is the call graph for this function:

void convert_param2 ( void   ) 

convert param2 to binaire.

Parameters:
none 
Returns:
none

Definition at line 356 of file ushell_task.c.

References ascii_to_bin(), par_str2, and param2.

00357 {
00358    U8 i = 0;
00359    param2 = 0;
00360    while ( par_str2[i] != 0 )
00361    {
00362       param2 = param2 << 4;
00363       param2 = param2 + ascii_to_bin(par_str2[i]);
00364       i++;
00365    }
00366 }

Here is the call graph for this function:

U16 debug_get_value1 ( void   ) 

U16 debug_get_value2 ( void   ) 

U8 mystrncmp ( U8 str1,
U8 code *  str2,
U8  i 
)

compares two strings located in flash code area.

Parameters:
*str1 
*str2 
Returns:
status: TRUE for ok, FALSE if strings are not equal

Definition at line 285 of file ushell_task.c.

References FALSE, and TRUE.

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

Parameters:
none 
Returns:
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 }

Here is the call graph for this function:

void print_hex16 ( U16  value  ) 

Display an U16 with hexa form.

Parameters:
 
Returns:
none

Definition at line 373 of file ushell_task.c.

References bin_to_ascii(), and uart_putchar().

Referenced by ushell_task().

00374 {
00375    U8 c;
00376    U8 d4;
00377    U8 d3;
00378    U8 d2;
00379    U8 d1;
00380 
00381    d4 = (U16)(value >> 12) & 0x0F;
00382    d3 = (U16)(value >> 8) & 0x0F;
00383    d2 = (U16)(value >> 4) & 0x0F;
00384    d1 = (U16)(value) & 0x0F;
00385 
00386    if (d4 != 0)
00387    {
00388       c = bin_to_ascii(d4);
00389       uart_putchar(c);
00390 
00391       c = bin_to_ascii(d3);
00392       uart_putchar(c);
00393 
00394       c = bin_to_ascii(d2);
00395       uart_putchar(c);
00396    }
00397    else
00398    {
00399       if (d3 != 0)
00400       {
00401          c = bin_to_ascii(d3);
00402          uart_putchar(c);
00403 
00404          c = bin_to_ascii(d2);
00405          uart_putchar(c);
00406       }
00407       else
00408       {
00409          if (d2 != 0)
00410          {
00411             c = bin_to_ascii(d2);
00412             uart_putchar(c);
00413          }
00414       }
00415    }
00416 
00417    c = bin_to_ascii(d1);
00418    uart_putchar(c);
00419 }

Here is the call graph for this function:

void print_msg ( U8 code *  str  ) 

Display an ASCII code string.

Parameters:
*str,: pointer to string located in flash area
Returns:
none

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 }

Here is the call graph for this function:

void ushell_task ( void   ) 

Entry point of the explorer task management.

This function links perform ushell task decoding to access file system functions.

Parameters:
none 
Returns:
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 }

Here is the call graph for this function:

void ushell_task_init ( void   ) 

This function initializes the hardware/software ressources required for ushell task.

Parameters:
none 
Returns:
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 }

Here is the call graph for this function:


Variable Documentation

U8 cmd [static]

Definition at line 33 of file ushell_task.c.

Referenced by parse_cmd(), ushell_task(), and ushell_task_init().

U8 cmd_str[26] [static]

Definition at line 39 of file ushell_task.c.

Referenced by build_cmd(), and parse_cmd().

U8 cmd_type [static]

Definition at line 34 of file ushell_task.c.

Referenced by parse_cmd(), ushell_task(), and ushell_task_init().

U8 i_str = 0 [static]

Definition at line 40 of file ushell_task.c.

Referenced by build_cmd(), and parse_cmd().

U8 code msg_er_cmd_not_found[] = MSG_ER_CMD_NOT_FOUND

Definition at line 57 of file ushell_task.c.

Referenced by parse_cmd(), and ushell_task().

U8 code msg_help[] = MSG_HELP

Definition at line 56 of file ushell_task.c.

Referenced by ushell_task().

U8 code msg_prompt[] = MSG_PROMPT

Definition at line 54 of file ushell_task.c.

Referenced by parse_cmd(), ushell_task(), and ushell_task_init().

U8 code msg_welcome[] = MSG_WELCOME

Definition at line 55 of file ushell_task.c.

Referenced by ushell_task_init().

U16 par_str1[8] [static]

Definition at line 35 of file ushell_task.c.

Referenced by convert_param1(), and parse_cmd().

U16 par_str2[8] [static]

Definition at line 36 of file ushell_task.c.

Referenced by convert_param2(), and parse_cmd().

U16 param1 [static]

Definition at line 37 of file ushell_task.c.

Referenced by convert_param1(), and ushell_task().

U16 param2 [static]

Definition at line 38 of file ushell_task.c.

Referenced by convert_param2().

Error calculation.

Definition at line 54 of file mc_control.c.

Referenced by mc_control_speed().

U8 code str_backward[] = STR_BACKWARD

Definition at line 48 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_forward[] = STR_FORWARD

Definition at line 47 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_get_id[] = STR_GET_ID

Definition at line 50 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_get_status0[] = STR_GET_STATUS0

Definition at line 51 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_get_status1[] = STR_GET_STATUS1

Definition at line 52 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_help[] = STR_HELP

Definition at line 46 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_run[] = STR_RUN

Definition at line 44 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_set_speed[] = STR_SET_SPEED

Definition at line 49 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_stop[] = STR_STOP

Definition at line 45 of file ushell_task.c.

Referenced by parse_cmd().

volatile Bool ushell_active = FALSE

Definition at line 42 of file ushell_task.c.

Referenced by main(), and ushell_task().


Generated on Wed Oct 22 15:04:01 2008 for AVR172 : Atmel BLDC control on ATAVRMC310 with ATmega32M1 by  doxygen 1.5.7.1