BLDC control on ATAVRMC303 with ATxMega128A1
ushell_task.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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. More...
 
U8 mystrncmp (U8 *str1, U8 code *str2, U8 i)
 compares two strings located in flash code area. More...
 
void parse_cmd (void)
 decodes full command line into command type and arguments More...
 
void print_msg (U8 code *str)
 Display an ASCII code string. More...
 
void ushell_task (void)
 Entry point of the explorer task management. More...
 
void ushell_task_init (void)
 This function initializes the hardware/software ressources required for ushell task. More...
 

Variables

volatile Bool ushell_active
 

Macro Definition Documentation

◆ ABORT_CHAR

#define ABORT_CHAR   CTRL_C

Definition at line 40 of file ushell_task.h.

Referenced by build_cmd().

◆ BKSPACE_CHAR

#define BKSPACE_CHAR   0x08

Definition at line 39 of file ushell_task.h.

Referenced by build_cmd().

◆ CMD_BACKWARD

#define CMD_BACKWARD   0x05

Definition at line 27 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_FORWARD

#define CMD_FORWARD   0x04

Definition at line 26 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_GET_ID

#define CMD_GET_ID   0x07

Definition at line 29 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_GET_STATUS0

#define CMD_GET_STATUS0   0x08

Definition at line 30 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_GET_STATUS1

#define CMD_GET_STATUS1   0x09

Definition at line 31 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_HELP

#define CMD_HELP   0x01

Definition at line 23 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_NONE

#define CMD_NONE   0x00

Definition at line 22 of file ushell_task.h.

Referenced by ushell_task(), and ushell_task_init().

◆ CMD_RUN

#define CMD_RUN   0x02

Definition at line 24 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_SET_SPEED

#define CMD_SET_SPEED   0x06

Definition at line 28 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CMD_STOP

#define CMD_STOP   0x03

Definition at line 25 of file ushell_task.h.

Referenced by parse_cmd(), and ushell_task().

◆ CR

#define CR   0x0D

Definition at line 35 of file ushell_task.h.

Referenced by build_cmd().

◆ CTRL_C

#define CTRL_C   0x03

Definition at line 38 of file ushell_task.h.

◆ CTRL_Q

#define CTRL_Q   0x11

Definition at line 37 of file ushell_task.h.

◆ LF

#define LF   0x0A

Definition at line 36 of file ushell_task.h.

◆ MSG_ER_CMD_NOT_FOUND

#define MSG_ER_CMD_NOT_FOUND   "Unknown Command"

Definition at line 57 of file ushell_task.h.

◆ MSG_HELP

#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 58 of file ushell_task.h.

◆ MSG_PROMPT

#define MSG_PROMPT   "\r>"

Definition at line 55 of file ushell_task.h.

◆ MSG_WELCOME

#define MSG_WELCOME   "\rATMEL Motor Control Interface"

Definition at line 56 of file ushell_task.h.

◆ QUIT_APPEND

#define QUIT_APPEND   CTRL_Q

Definition at line 41 of file ushell_task.h.

◆ STR_BACKWARD

#define STR_BACKWARD   "bw"

Definition at line 48 of file ushell_task.h.

◆ STR_FORWARD

#define STR_FORWARD   "fw"

Definition at line 47 of file ushell_task.h.

◆ STR_GET_ID

#define STR_GET_ID   "gi"

Definition at line 50 of file ushell_task.h.

◆ STR_GET_STATUS0

#define STR_GET_STATUS0   "g0"

Definition at line 51 of file ushell_task.h.

◆ STR_GET_STATUS1

#define STR_GET_STATUS1   "g1"

Definition at line 52 of file ushell_task.h.

◆ STR_HELP

#define STR_HELP   "help"

Definition at line 46 of file ushell_task.h.

◆ STR_RUN

#define STR_RUN   "ru"

Definition at line 44 of file ushell_task.h.

◆ STR_SET_SPEED

#define STR_SET_SPEED   "ss"

Definition at line 49 of file ushell_task.h.

◆ STR_STOP

#define STR_STOP   "st"

Definition at line 45 of file ushell_task.h.

Function Documentation

◆ build_cmd()

void build_cmd ( void  )

get the full command line to be interpreted.

Parameters
none
Returns
none

Definition at line 161 of file ushell_task.c.

References ABORT_CHAR, BKSPACE_CHAR, cmd_str, CR, i_str, parse_cmd(), and uart_putchar.

Referenced by ushell_task().

162 {
163 U8 c;
164 
165  if (uart_test_hit()) //Something new of the UART ?
166  {
167  c=uart_getchar();
168  switch (c)
169  {
170  case CR:
171  cmd_str[i_str]=0; //Add NULL char
172  parse_cmd(); //Decode the command
173  i_str=0;
174  break;
175  case ABORT_CHAR: //^c abort cmd
176  i_str=0;
177  printf("\r#");
178  break;
179  case BKSPACE_CHAR: //backspace
180  if(i_str>0)
181  {
182  uart_putchar(c);
183  uart_putchar(' ');
184  uart_putchar(c);
185  }
186  if(i_str>=1)
187  {
188  i_str--;
189  }
190  break;
191 
192  default:
193  cmd_str[i_str++]=c; //append to cmd line
194  break;
195  }
196  }
197 }
#define ABORT_CHAR
Definition: ushell_task.h:40
static U8 i_str
Definition: ushell_task.c:37
#define uart_putchar
Definition: config.h:85
#define CR
Definition: ushell_task.h:35
#define BKSPACE_CHAR
Definition: ushell_task.h:39
void parse_cmd(void)
decodes full command line into command type and arguments
Definition: ushell_task.c:209
static U8 cmd_str[26]
Definition: ushell_task.c:36
Here is the call graph for this function:

◆ mystrncmp()

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.

Referenced by parse_cmd().

286 {
287  U8 j;
288  for(j=0;j<=i;j++)
289  {
290 #ifndef __GNUC__
291  if(*str1!=*str2)
292 #else
293 // if( pgm_read_byte_near((unsigned int)str1) != pgm_read_byte_near((unsigned int)str2))
294  if( *str1 != pgm_read_byte_near((unsigned int)str2))
295 
296 #endif
297  {
298  return FALSE;
299  }
300  str1++;str2++;
301  }
302  return TRUE;
303 }

◆ parse_cmd()

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 209 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, i_str, 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, and str_stop.

Referenced by build_cmd().

210 {
211  U8 i=0;
212  U8 j;
213 
214  //Get command type
215  for(i=0;cmd_str[i]!=' ' && i<=i_str;i++);
216  cmd=TRUE;
217 
218  //Decode command type
219 
220  if ( mystrncmp(cmd_str,str_run,i-1))
221  { cmd_type=CMD_RUN; }
222  else if ( mystrncmp(cmd_str,str_stop,i-1))
223  { cmd_type=CMD_STOP; }
224  else if ( mystrncmp(cmd_str,str_help,i-1))
225  { cmd_type=CMD_HELP; }
226  else if ( mystrncmp(cmd_str,str_forward,i-1))
227  { cmd_type=CMD_FORWARD; }
228  else if ( mystrncmp(cmd_str,str_backward,i-1))
230  else if ( mystrncmp(cmd_str,str_set_speed,i-1))
232  else if ( mystrncmp(cmd_str,str_get_id,i-1))
233  { cmd_type=CMD_GET_ID; }
234  else if ( mystrncmp(cmd_str,str_get_status0,i-1))
236  else if ( mystrncmp(cmd_str,str_get_status1,i-1))
238  else
239  {
240  if(i_str)
241  {
243  }
245  cmd=FALSE;
246  return;
247  }
248 
249  //Get first arg (if any)
250  if(++i<i_str)
251  {
252  j=0;
253  for(;(cmd_str[i]!=' ')&&(i<i_str);i++)
254  {
255  LSB(par_str1[j])=cmd_str[i];
256  MSB(par_str1[j])=0;
257  j++;
258  }
259  LSB(par_str1[j])=0;MSB(par_str1[j])=0;
260  }
261  else { return; }
262 
263  //Get second arg (if any)
264  if(++i<i_str)
265  {
266  j=0;
267  for(;(cmd_str[i]!=' ')&&(i<i_str);i++)
268  {
269  LSB(par_str2[j])=cmd_str[i];
270  MSB(par_str2[j])=0;
271  j++;
272  }
273  LSB(par_str2[j])=0;MSB(par_str2[j])=0;
274  }
275  else { return; }
276 
277 }
U8 code str_get_id[]
Definition: ushell_task.c:47
U8 code str_run[]
Definition: ushell_task.c:41
U8 code str_get_status0[]
Definition: ushell_task.c:48
#define CMD_STOP
Definition: ushell_task.h:25
#define CMD_SET_SPEED
Definition: ushell_task.h:28
static U8 i_str
Definition: ushell_task.c:37
U8 code str_backward[]
Definition: ushell_task.c:45
#define CMD_GET_STATUS0
Definition: ushell_task.h:30
U8 code msg_prompt[]
Definition: ushell_task.c:51
U8 mystrncmp(U8 *str1, U8 code *str2, U8 i)
compares two strings located in flash code area.
Definition: ushell_task.c:285
void print_msg(U8 code *str)
Display an ASCII code string.
Definition: ushell_task.c:310
static U8 cmd_type
Definition: ushell_task.c:31
#define CMD_HELP
Definition: ushell_task.h:23
#define CMD_GET_STATUS1
Definition: ushell_task.h:31
U8 code str_forward[]
Definition: ushell_task.c:44
#define CMD_RUN
Definition: ushell_task.h:24
U8 code str_stop[]
Definition: ushell_task.c:42
static U16 par_str2[8]
Definition: ushell_task.c:33
#define CMD_BACKWARD
Definition: ushell_task.h:27
U8 code str_get_status1[]
Definition: ushell_task.c:49
#define CMD_FORWARD
Definition: ushell_task.h:26
static U8 cmd_str[26]
Definition: ushell_task.c:36
U8 code str_help[]
Definition: ushell_task.c:43
#define CMD_GET_ID
Definition: ushell_task.h:29
static U16 par_str1[8]
Definition: ushell_task.c:32
static U8 cmd
Definition: ushell_task.c:30
U8 code str_set_speed[]
Definition: ushell_task.c:46
U8 code msg_er_cmd_not_found[]
Definition: ushell_task.c:54
Here is the call graph for this function:

◆ print_msg()

void print_msg ( U8 code *  str)

Display an ASCII code string.

Parameters
*strpointer to string located in flash area
Returns
none

Definition at line 310 of file ushell_task.c.

References uart_putchar.

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

311 {
312 U8 c;
313 #ifndef __GNUC__
314  c=*str++;
315  while(c!=0)
316  {
317  uart_putchar(c);
318  c=*str++;
319  }
320 #else // AVRGCC does not support point to PGM space
321  c=pgm_read_byte_near((unsigned int)str++);
322  while(c!=0)
323  {
324  uart_putchar(c);
325  c=pgm_read_byte_near((unsigned int)str++);
326  }
327 #endif
328 
329 }
#define uart_putchar
Definition: config.h:85

◆ ushell_task()

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 93 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(), 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, SOFT_ID, uart_putchar, and ushell_active.

Referenced by main().

94 {
95  U8 status = 0;
96 
97  if(cmd==FALSE)
98  {
99  build_cmd();
100  }
101  else
102  {
103  switch (cmd_type)
104  {
105  case CMD_HELP:
107  break;
108  case CMD_RUN:
109  mci_run();
110  break;
111  case CMD_STOP:
112  mci_stop();
113  break;
114  case CMD_FORWARD:
115  mci_forward();
116  break;
117  case CMD_BACKWARD:
118  mci_backward();
119  break;
120  case CMD_SET_SPEED:
121  convert_param1();
123  break;
124  case CMD_GET_ID:
126  uart_putchar(' ');
128  uart_putchar(' ');
130  break;
131  case CMD_GET_STATUS0:
132  status = 0;
133  if (mci_direction == CCW) {status |= (1<<3);}
134  if (mci_run_stop == TRUE) {status |= (1<<2);}
135  print_hex16(status);
136  uart_putchar(' ');
138  uart_putchar(' ');
140  ushell_active = TRUE;
141  break;
142  case CMD_GET_STATUS1:
143  print_hex16(0xDEA);
144  uart_putchar(' ');
145  print_hex16(0x123);
146  break;
147  default: //Unknown command
149  }
151  cmd=FALSE;
153  }
154 }
void convert_param1(void)
convert param1 to binaire.
Definition: ushell_task.c:336
volatile Bool ushell_active
Definition: ushell_task.c:39
void mci_set_speed(U16 speed)
Definition: mc_interface.c:214
U16 mci_get_measured_current(void)
Get the current measured in the motor.
Definition: mc_interface.c:179
#define CMD_STOP
Definition: ushell_task.h:25
#define CMD_SET_SPEED
Definition: ushell_task.h:28
#define CMD_GET_STATUS0
Definition: ushell_task.h:30
#define uart_putchar
Definition: config.h:85
U8 code msg_prompt[]
Definition: ushell_task.c:51
void print_msg(U8 code *str)
Display an ASCII code string.
Definition: ushell_task.c:310
Bool mci_direction
User Input parameter to set motor direction.
Definition: mc_interface.c:20
static U8 cmd_type
Definition: ushell_task.c:31
void mci_stop(void)
mci_stop stop the motor And reset the speed measured value.
Definition: mc_interface.c:81
static U16 param1
Definition: ushell_task.c:34
#define CMD_HELP
Definition: ushell_task.h:23
#define REV_ID
Definition: config.h:78
#define CMD_GET_STATUS1
Definition: ushell_task.h:31
void mci_run(void)
mci_run run the motor with parameter
Definition: mc_interface.c:34
#define CMD_RUN
Definition: ushell_task.h:24
Bool mci_run_stop
User Input parameter to launch or stop the motor.
Definition: mc_interface.c:21
void mci_backward(void)
Definition: mc_interface.c:138
#define CMD_BACKWARD
Definition: ushell_task.h:27
#define BOARD_ID
Definition: config.h:76
#define CMD_FORWARD
Definition: ushell_task.h:26
#define SOFT_ID
Definition: config.h:77
void build_cmd(void)
get the full command line to be interpreted.
Definition: ushell_task.c:161
void mci_forward(void)
Definition: mc_interface.c:128
#define CMD_NONE
Definition: ushell_task.h:22
U8 mci_get_measured_speed(void)
Measured of speed.
Definition: mc_interface.c:169
#define CMD_GET_ID
Definition: ushell_task.h:29
void print_hex16(U16 value)
Display an U16 with hexa form.
Definition: ushell_task.c:370
U8 code msg_help[]
Definition: ushell_task.c:53
static U8 cmd
Definition: ushell_task.c:30
U8 code msg_er_cmd_not_found[]
Definition: ushell_task.c:54
Here is the call graph for this function:

◆ ushell_task_init()

void ushell_task_init ( void  )

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

Parameters
none
Returns
none

/

Definition at line 66 of file ushell_task.c.

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

Referenced by main().

67 {
68 
69  uart_init();
70 
71 #ifdef __GNUC__
72  fdevopen((int (*)(char, FILE*))(uart_putchar),(int (*)(FILE*))uart_getchar); //for printf redirection
73 #endif
74 
77  cmd=FALSE;
79 }
#define uart_putchar
Definition: config.h:85
U8 code msg_prompt[]
Definition: ushell_task.c:51
void print_msg(U8 code *str)
Display an ASCII code string.
Definition: ushell_task.c:310
static U8 cmd_type
Definition: ushell_task.c:31
#define CMD_NONE
Definition: ushell_task.h:22
U8 code msg_welcome[]
Definition: ushell_task.c:52
static U8 cmd
Definition: ushell_task.c:30
Here is the call graph for this function:

Variable Documentation

◆ ushell_active

volatile Bool ushell_active

Definition at line 39 of file ushell_task.c.

Referenced by main(), and ushell_task().