ushell_task.c File Reference


Detailed Description

Copyright (c) 2004This file manages the µshell task for file system.

Please read file license.txt for copyright notice.

Version:
1.3 (mc100_bldc_sensorless_0_1_0)
Todo:
Bug:
/

Definition in file ushell_task.c.

#include "config.h"
#include "ushell_task.h"
#include "ascii.h"
#include "lib_mcu/uart/uart_lib.h"
#include "mc_interface.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.
void mci_backward (void)
void mci_forward (void)
void mci_run (void)
 mci_run starts the motor with predefined parameter
void mci_set_speed (U16)
void mci_stop (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


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(), 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                putchar(c);
00181                putchar(' ');
00182                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:

Here is the caller graph for this function:

void convert_param1 ( void   ) 

convert param1 to binaire.

Parameters:
none 
Returns:
none

Definition at line 332 of file ushell_task.c.

References ascii_to_bin(), par_str1, and param1.

Referenced by ushell_task().

00333 {
00334    U8 i = 0;
00335    param1 = 0;
00336    while ( par_str1[i] != 0 )
00337    {
00338       param1 = param1 << 4;
00339       param1 = param1 + ascii_to_bin(par_str1[i]);
00340       i++;
00341    }
00342 }

Here is the call graph for this function:

Here is the caller graph for this function:

void convert_param2 ( void   ) 

convert param2 to binaire.

Parameters:
none 
Returns:
none

Definition at line 349 of file ushell_task.c.

References ascii_to_bin(), par_str2, and param2.

00350 {
00351    U8 i = 0;
00352    param2 = 0;
00353    while ( par_str2[i] != 0 )
00354    {
00355       param2 = param2 << 4;
00356       param2 = param2 + ascii_to_bin(par_str2[i]);
00357       i++;
00358    }
00359 }

Here is the call graph for this function:

void mci_backward ( void   ) 

Definition at line 103 of file mc_interface.c.

References CCW, and mci_direction.

Referenced by ushell_task().

00104 {
00105   mci_direction = CCW;
00106 }

Here is the caller graph for this function:

void mci_forward ( void   ) 

Definition at line 93 of file mc_interface.c.

References CW, and mci_direction.

Referenced by ushell_task().

00094 {
00095   mci_direction = CW;
00096 }

Here is the caller graph for this function:

void mci_run ( void   ) 

mci_run starts the motor with predefined parameter

Parameters:
@pre initialization HW and SW
Postcondition:
New value in Hall variable

Definition at line 196 of file mc_interface.c.

References DUTY_RAMP_UP, mc_motor_init(), mc_ramp_up_init(), mc_regulation_loop(), mc_set_Open_Loop(), mci_run_stop, mci_set_motor_speed(), PSC_Run(), and RUN.

Referenced by ushell_task().

00197 {
00198    mc_motor_init();  // launch initialization of the motor
00199    mci_run_stop = RUN;
00200    mci_set_motor_speed(DUTY_RAMP_UP); /* set a speed for the ramp-up */
00201    mc_set_Open_Loop();      /* set the regulation type */
00202    mc_regulation_loop();    /* execute the regulation one time */
00203    mc_ramp_up_init();
00204    PSC_Run();
00205 }

Here is the call graph for this function:

Here is the caller graph for this function:

void mci_set_speed ( U16   ) 

Definition at line 214 of file mc_interface.c.

References mci_set_motor_speed().

Referenced by ushell_task().

00215 {
00216    mci_set_motor_speed((U8)speed);
00217 }

Here is the call graph for this function:

Here is the caller graph for this function:

void mci_stop ( void   ) 

Definition at line 207 of file mc_interface.c.

References mci_run_stop, PSC_Stop(), and STOP.

Referenced by mc_motor_init(), and ushell_task().

00208 {
00209    PSC_Stop();
00210    mci_run_stop  = STOP;
00211 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 283 of file ushell_task.c.

References FALSE, and TRUE.

Referenced by parse_cmd().

00284 {
00285    U8 j;
00286    for(j=0;j<=i;j++)
00287    {
00288 #ifndef AVRGCC
00289       if(*str1!=*str2)
00290 #else
00291       if( pgm_read_byte_near((unsigned int)str1) != pgm_read_byte_near((unsigned int)str2))
00292 #endif
00293       {
00294          return FALSE;
00295       }
00296       str1++;str2++;
00297    }
00298    return TRUE;
00299 }

Here is the caller graph for this function:

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 
00218    if ( mystrncmp(cmd_str,str_run,i-1))
00219    {  cmd_type=CMD_RUN; }
00220    else if ( mystrncmp(cmd_str,str_stop,i-1))
00221    {  cmd_type=CMD_STOP; }
00222    else if ( mystrncmp(cmd_str,str_help,i-1))
00223    {  cmd_type=CMD_HELP; }
00224    else if ( mystrncmp(cmd_str,str_forward,i-1))
00225    {  cmd_type=CMD_FORWARD; }
00226    else if ( mystrncmp(cmd_str,str_backward,i-1))
00227    {  cmd_type=CMD_BACKWARD; }
00228    else if ( mystrncmp(cmd_str,str_set_speed,i-1))
00229    {  cmd_type=CMD_SET_SPEED; }
00230    else if ( mystrncmp(cmd_str,str_get_id,i-1))
00231    {  cmd_type=CMD_GET_ID; }
00232    else if ( mystrncmp(cmd_str,str_get_status0,i-1))
00233    {  cmd_type=CMD_GET_STATUS0; }
00234    else if ( mystrncmp(cmd_str,str_get_status1,i-1))
00235    {  cmd_type=CMD_GET_STATUS1; }
00236    else
00237    {
00238       if(i_str)
00239       {
00240         print_msg(msg_er_cmd_not_found);
00241       }
00242       print_msg(msg_prompt);
00243       cmd=FALSE;
00244       return;
00245    }
00246 
00247   //Get first arg (if any)
00248    if(++i<i_str)
00249    {
00250       j=0;
00251       for(;(cmd_str[i]!=' ')&&(i<i_str);i++)
00252       {
00253          LSB(par_str1[j])=cmd_str[i];
00254          MSB(par_str1[j])=0;
00255          j++;
00256       }
00257       LSB(par_str1[j])=0;MSB(par_str1[j])=0;
00258    }
00259    else   {  return; }
00260 
00261    //Get second arg (if any)
00262    if(++i<i_str)
00263    {
00264       j=0;
00265       for(;(cmd_str[i]!=' ')&&(i<i_str);i++)
00266       {
00267          LSB(par_str2[j])=cmd_str[i];
00268          MSB(par_str2[j])=0;
00269          j++;
00270       }
00271       LSB(par_str2[j])=0;MSB(par_str2[j])=0;
00272    }
00273    else   { return; }
00274 
00275 }

Here is the call graph for this function:

Here is the caller graph for this function:

void print_hex16 ( U16  value  ) 

Display an U16 with hexa form.

Parameters:
@return none

Definition at line 366 of file ushell_task.c.

References bin_to_ascii().

Referenced by ushell_task().

00367 {
00368    U8 c;
00369    c = (U16)(value >> 12) & 0x0F;
00370    if (c != 0)
00371    {
00372       c = bin_to_ascii(c);
00373       putchar(c);
00374    }
00375 
00376    c = (U16)(value >> 8) & 0x0F;
00377    if (c != 0)
00378    {
00379       c = bin_to_ascii(c);
00380       putchar(c);
00381    }
00382 
00383    c = (U16)(value >> 4) & 0x0F;
00384    if (c != 0)
00385    {
00386       c = bin_to_ascii(c);
00387       putchar(c);
00388    }
00389 
00390    c = (U16)(value) & 0x0F;
00391    c = bin_to_ascii(c);
00392    putchar(c);
00393 }

Here is the call graph for this function:

Here is the caller 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 306 of file ushell_task.c.

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

00307 {
00308 U8 c;
00309 #ifndef AVRGCC
00310    c=*str++;
00311    while(c!=0)
00312    {
00313       putchar(c);
00314       c=*str++;
00315    }
00316 #else    // AVRGCC does not support point to PGM space
00317    c=pgm_read_byte_near((unsigned int)str++);
00318    while(c!=0)
00319    {
00320       putchar(c);
00321       c=pgm_read_byte_near((unsigned int)str++);
00322    }
00323 #endif
00324 
00325 }

Here is the caller 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 94 of file ushell_task.c.

References BOARD_ID, build_cmd(), 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, mci_backward(), mci_direction, mci_forward(), mci_get_measured_current(), mci_get_measured_speed(), mci_run(), mci_run_stop, mci_set_speed(), mci_stop(), msg_er_cmd_not_found, msg_help, msg_prompt, param1, print_hex16(), print_msg(), REV_ID, and SOFT_ID.

Referenced by main().

00095 {
00096    U8 status = 0;
00097 
00098    if(cmd==FALSE)
00099    {
00100       build_cmd();
00101    }
00102    else
00103    {
00104       switch (cmd_type)
00105       {
00106          case CMD_HELP:
00107             print_msg(msg_help);
00108             break;
00109          case CMD_RUN:
00110             mci_run();
00111             break;
00112          case CMD_STOP:
00113             mci_stop();
00114             break;
00115          case CMD_FORWARD:
00116             mci_forward();
00117             break;
00118          case CMD_BACKWARD:
00119             mci_backward();
00120             break;
00121          case CMD_SET_SPEED:
00122             convert_param1();
00123             mci_set_speed(param1);
00124             break;
00125          case CMD_GET_ID:
00126             print_hex16(BOARD_ID);
00127             putchar(' ');
00128             print_hex16(SOFT_ID);
00129             putchar(' ');
00130             print_hex16(REV_ID);
00131             break;
00132          case CMD_GET_STATUS0:
00133             status = (mci_direction<<3)|(mci_run_stop<<2);
00134             print_hex16(status);
00135             putchar(' ');
00136             print_hex16(mci_get_measured_speed());
00137             putchar(' ');
00138             print_hex16(mci_get_measured_current());
00139             break;
00140          case CMD_GET_STATUS1:
00141             print_hex16(0xDEA);
00142             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:

Here is the caller 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 73 of file ushell_task.c.

References cmd, CMD_NONE, cmd_type, FALSE, msg_prompt, msg_welcome, print_msg(), and uart_init().

Referenced by main().

00074 {
00075    uart_init();
00076    print_msg(msg_welcome);
00077    print_msg(msg_prompt);
00078    cmd=FALSE;
00079    cmd_type=CMD_NONE;
00080 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

U8 cmd [static]

Definition at line 39 of file ushell_task.c.

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

U8 cmd_str[26] [static]

Definition at line 45 of file ushell_task.c.

Referenced by build_cmd(), and parse_cmd().

U8 cmd_type [static]

Definition at line 40 of file ushell_task.c.

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

U8 i_str = 0 [static]

Definition at line 46 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 61 of file ushell_task.c.

Referenced by parse_cmd(), and ushell_task().

U8 code msg_help[] = MSG_HELP

Definition at line 60 of file ushell_task.c.

Referenced by ushell_task().

U8 code msg_prompt[] = MSG_PROMPT

Definition at line 58 of file ushell_task.c.

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

U8 code msg_welcome[] = MSG_WELCOME

Definition at line 59 of file ushell_task.c.

Referenced by ushell_task_init().

U16 par_str1[8] [static]

Definition at line 41 of file ushell_task.c.

Referenced by convert_param1(), and parse_cmd().

U16 par_str2[8] [static]

Definition at line 42 of file ushell_task.c.

Referenced by convert_param2(), and parse_cmd().

U16 param1 [static]

Definition at line 43 of file ushell_task.c.

Referenced by convert_param1(), and ushell_task().

U16 param2 [static]

Definition at line 44 of file ushell_task.c.

Referenced by convert_param2().

S16 speed_error

Error calculation.

Definition at line 30 of file mc_control.c.

Referenced by mc_control_speed().

U8 code str_backward[] = STR_BACKWARD

Definition at line 52 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_forward[] = STR_FORWARD

Definition at line 51 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_get_id[] = STR_GET_ID

Definition at line 54 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_get_status0[] = STR_GET_STATUS0

Definition at line 55 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_get_status1[] = STR_GET_STATUS1

Definition at line 56 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_help[] = STR_HELP

Definition at line 50 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_run[] = STR_RUN

Definition at line 48 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_set_speed[] = STR_SET_SPEED

Definition at line 53 of file ushell_task.c.

Referenced by parse_cmd().

U8 code str_stop[] = STR_STOP

Definition at line 49 of file ushell_task.c.

Referenced by parse_cmd().


Generated on Wed Jul 12 16:55:26 2006 for Atmel BLDC Sensorless on ATAVRMC100 by  doxygen 1.4.7