This module manages a command shell on COM1.
Definition in file com1shell.c.
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "serial.h"
#include "supervisor.h"
#include "fs_com.h"
#include "fsaccess.h"
#include "shell.h"
#include "com1shell.h"
#include "tracedump.h"
Go to the source code of this file.
Defines | |
#define | COM1SHELL_BAUDRATE ( ( unsigned portLONG ) 57600 ) |
Baud rate used by the serial port 1. | |
#define | COM1SHELL_MAX_CMDLINE_LEN (MAX_CMD_LEN + 2 * MAX_FILE_PATH_LENGTH) |
#define | COM1SHELL_MSG_BANNER "\x0C\r\n---------- ATMEL AVR32 Shell ----------\r\n" |
Messages printed on the COM1 port. | |
#define | COM1SHELL_MSG_LINETOOLONG "\r\nLine too long!\r\n" |
#define | COM1SHELL_MSG_PROMPT "$>" |
#define | COM1SHELL_NO_BLOCK ( ( portTickType ) 0 ) |
#define | COM1SHELL_RX_BLOCK_TIME ( ( portTickType ) 0xffff ) |
#define | COM1SHELL_RX_SHORT_BLOCK_TIME ( ( portTickType ) 1 ) |
#define | COM1SHELL_RXBUFFER_LEN ( ( unsigned portLONG ) 64 ) |
COM Port1 buffers length. | |
#define | COM1SHELL_STACK_SIZE 384 |
#define | COM1SHELL_TXBUFFER_LEN ( ( unsigned portLONG ) 32 ) |
#define | MAX_CMD_LEN 32 |
Functions | |
signed portBASE_TYPE | com1shell_GetChar (signed portCHAR *pcByte) |
Get a char from the COM1 port. | |
static | portTASK_FUNCTION (vCom1ShellTask, pvParameters) |
static signed portBASE_TYPE | prvGetChar (signed portCHAR *pcByte, portTickType xBlockTime) |
Get a char from the COM1 port. | |
static unsigned portCHAR | prvGetCmdLine (void) |
Get a command line. | |
void | v_com1shell_mount_local_drive (void) |
Mount default local drive 'a:'. | |
void | v_com1shell_stopResources (void) |
Stop the com1shell module resources. | |
void | vcom1shell_PrintMsg (const signed portCHAR *pcString) |
Print a string to the COM1 port. | |
void | vcom1shell_PutChar (signed portCHAR cByte) |
Put a char to the COM1 port. | |
void | vStartCom1Shell (unsigned portBASE_TYPE uxPriority) |
eStatus | xCom1Shell_GetStatus (void) |
Return the status of the COM1 shell module. | |
Variables | |
static signed portCHAR | acStringCmd [COM1SHELL_MAX_CMDLINE_LEN+1] |
signed short | sCom1ShellNavId |
xTaskHandle | xCom1ShellHndl = NULL |
static eStatus | xCom1ShellStatus = SYS_STATUS_STARTUP |
static xComPortHandle | xComPort1Hndl = NULL |
#define COM1SHELL_BAUDRATE ( ( unsigned portLONG ) 57600 ) |
Baud rate used by the serial port 1.
Definition at line 102 of file com1shell.c.
Referenced by portTASK_FUNCTION().
#define COM1SHELL_MAX_CMDLINE_LEN (MAX_CMD_LEN + 2 * MAX_FILE_PATH_LENGTH) |
The max length of a cmd line.
Definition at line 87 of file com1shell.c.
Referenced by prvGetCmdLine().
#define COM1SHELL_MSG_BANNER "\x0C\r\n---------- ATMEL AVR32 Shell ----------\r\n" |
Messages printed on the COM1 port.
Definition at line 108 of file com1shell.c.
Referenced by portTASK_FUNCTION().
#define COM1SHELL_MSG_LINETOOLONG "\r\nLine too long!\r\n" |
Brief description of the module. This module is in charge of a command line shell on COM1.
Detailled description of the module. Creation of one task that is in charge of getting a command line from COM1, launching the execution of the command and giving feedback of this execution to COM1.
Definition at line 81 of file com1shell.c.
Referenced by prvGetCmdLine().
#define COM1SHELL_MSG_PROMPT "$>" |
#define COM1SHELL_NO_BLOCK ( ( portTickType ) 0 ) |
#define COM1SHELL_RX_BLOCK_TIME ( ( portTickType ) 0xffff ) |
#define COM1SHELL_RX_SHORT_BLOCK_TIME ( ( portTickType ) 1 ) |
Definition at line 98 of file com1shell.c.
#define COM1SHELL_RXBUFFER_LEN ( ( unsigned portLONG ) 64 ) |
COM Port1 buffers length.
Definition at line 104 of file com1shell.c.
Referenced by portTASK_FUNCTION().
#define COM1SHELL_STACK_SIZE 384 |
#define COM1SHELL_TXBUFFER_LEN ( ( unsigned portLONG ) 32 ) |
#define MAX_CMD_LEN 32 |
The max length of a cmd name.
Definition at line 85 of file com1shell.c.
signed portBASE_TYPE com1shell_GetChar | ( | signed portCHAR * | pcByte | ) |
Get a char from the COM1 port.
pcByte | Output. The char received from the COM1 port. |
Definition at line 298 of file com1shell.c.
References COM1SHELL_RX_BLOCK_TIME, xComPort1Hndl, and xUsartGetChar().
Referenced by prv_GetChar_From_Requester_Stream().
00299 { 00300 return( xUsartGetChar( xComPort1Hndl, pcByte, COM1SHELL_RX_BLOCK_TIME ) ); 00301 }
static portTASK_FUNCTION | ( | vCom1ShellTask | , | |
pvParameters | ||||
) | [static] |
Definition at line 173 of file com1shell.c.
References acStringCmd, COM1SHELL_BAUDRATE, COM1SHELL_MSG_BANNER, COM1SHELL_RXBUFFER_LEN, COM1SHELL_TXBUFFER_LEN, prvGetCmdLine(), sCom1ShellNavId, serCOM1, Shell_exec(), SHELL_EXECSTATUS_OK, SYS_MODID_COM1SHELL, SYS_STATUS_DOWN, SYS_STATUS_RUNNING, vcom1shell_PrintMsg(), xCom1ShellStatus, xComPort1Hndl, and xUsartInit().
00174 { 00175 signed portCHAR *pcStringReply = NULL; 00176 eExecStatus xExeStatus; 00177 00178 00179 /* Just to stop compiler warnings. */ 00180 ( void ) pvParameters; 00181 00182 /* Initialize the COM1 port. */ 00183 xComPort1Hndl = xUsartInit( serCOM1, COM1SHELL_BAUDRATE, 00184 COM1SHELL_RXBUFFER_LEN, COM1SHELL_TXBUFFER_LEN ); 00185 if(xComPort1Hndl == 0) 00186 { 00187 xCom1ShellStatus = SYS_STATUS_DOWN; 00188 vTaskDelete(NULL); // Kill this task. 00189 } 00190 00191 xCom1ShellStatus = SYS_STATUS_RUNNING; 00192 00193 vcom1shell_PrintMsg((signed portCHAR *)COM1SHELL_MSG_BANNER); 00194 00195 for(;;) 00196 { 00197 // 1) Get the command. 00198 if(prvGetCmdLine() == 0) 00199 continue; 00200 00201 // 2) Execute the command. 00202 xExeStatus = Shell_exec(acStringCmd, SYS_MODID_COM1SHELL, sCom1ShellNavId, &pcStringReply); 00203 00204 // 3) Print the response. 00205 if( NULL != pcStringReply ) 00206 vcom1shell_PrintMsg(pcStringReply); 00207 if( ( NULL != pcStringReply ) && ( SHELL_EXECSTATUS_OK == xExeStatus ) ) 00208 vPortFree(pcStringReply); 00209 } 00210 }
static signed portBASE_TYPE prvGetChar | ( | signed portCHAR * | pcByte, | |
portTickType | xBlockTime | |||
) | [static] |
Get a char from the COM1 port.
Definition at line 307 of file com1shell.c.
References xComPort1Hndl, and xUsartGetChar().
Referenced by prvGetCmdLine().
00308 { 00309 return( xUsartGetChar( xComPort1Hndl, pcByte, xBlockTime ) ); 00310 }
static unsigned portCHAR prvGetCmdLine | ( | void | ) | [static] |
Get a command line.
Definition at line 218 of file com1shell.c.
References ABORT_CHAR, acStringCmd, BKSPACE_CHAR, COM1SHELL_MAX_CMDLINE_LEN, COM1SHELL_MSG_LINETOOLONG, COM1SHELL_MSG_PROMPT, COM1SHELL_RX_BLOCK_TIME, CR, LF, prvGetChar(), vcom1shell_PrintMsg(), and vcom1shell_PutChar().
Referenced by portTASK_FUNCTION().
00219 { 00220 signed portCHAR c; 00221 unsigned portCHAR idx = 0; 00222 00223 00224 vcom1shell_PrintMsg( (signed portCHAR *)COM1SHELL_MSG_PROMPT ); 00225 while( idx < COM1SHELL_MAX_CMDLINE_LEN ) 00226 { 00227 if ( prvGetChar( &c, COM1SHELL_RX_BLOCK_TIME ) == pdTRUE ) 00228 { 00229 switch (c) 00230 { 00231 case LF: 00232 vcom1shell_PutChar(CR); // Add CR 00233 vcom1shell_PutChar(c); // LF 00234 acStringCmd[idx] = '\0'; // Add NUL char 00235 return(idx); 00236 case CR: 00237 vcom1shell_PutChar(c); // CR 00238 vcom1shell_PutChar(LF); // Add CR 00239 acStringCmd[idx] = '\0'; // Add NUL char 00240 return(idx); 00241 case ABORT_CHAR: // ^c abort cmd 00242 idx = 0; 00243 vcom1shell_PutChar(LF); // Add LF 00244 vcom1shell_PrintMsg( (signed portCHAR *)COM1SHELL_MSG_PROMPT ); 00245 break; 00246 case BKSPACE_CHAR: // Backspace 00247 if (idx > 0) 00248 { 00249 vcom1shell_PrintMsg( (signed portCHAR *)"\b \b" ); 00250 idx--; 00251 } 00252 break; 00253 default: 00254 vcom1shell_PutChar(c); // Echo 00255 acStringCmd[idx++] = c; // Append to cmd line 00256 break; 00257 } 00258 } 00259 } 00260 vcom1shell_PrintMsg( (signed portCHAR *)COM1SHELL_MSG_LINETOOLONG ); 00261 return(0); 00262 }
void v_com1shell_mount_local_drive | ( | void | ) |
Mount default local drive 'a:'.
Definition at line 316 of file com1shell.c.
References LUN_ID_AT45DBX_MEM, and sCom1ShellNavId.
Referenced by prv_v_leave_maintenance_mode(), and vStartCom1Shell().
00317 { 00318 fsaccess_take_mutex(); 00319 nav_select( sCom1ShellNavId ); // Select the COM1SHELL navigator. 00320 nav_drive_set(LUN_ID_AT45DBX_MEM); 00321 nav_partition_mount(); 00322 fsaccess_give_mutex(); 00323 }
void v_com1shell_stopResources | ( | void | ) |
Stop the com1shell module resources.
Definition at line 158 of file com1shell.c.
References vSerialClose(), and xComPort1Hndl.
Referenced by e_syscmds_reboot().
00159 { 00160 vSerialClose( xComPort1Hndl ); 00161 }
void vcom1shell_PrintMsg | ( | const signed portCHAR * | pcString | ) |
Print a string to the COM1 port.
pcString | Input. The string to print. |
Definition at line 270 of file com1shell.c.
References usUsartPutString(), and xComPort1Hndl.
Referenced by portTASK_FUNCTION(), prv_Print_String_To_Requester_Stream(), prvGetCmdLine(), and v_shell_Print_String_To_Requester_Stream().
00271 { 00272 unsigned portSHORT usRemainChar = 0; 00273 unsigned portSHORT usMsgLen = strlen((const portCHAR * )pcString); 00274 00275 if(usMsgLen==0) 00276 return; 00277 usRemainChar = usMsgLen; 00278 do { 00279 usRemainChar = usUsartPutString( xComPort1Hndl, 00280 (const signed portCHAR *)(pcString + usMsgLen - usRemainChar), 00281 usRemainChar ); 00282 }while( usRemainChar ); 00283 }
void vcom1shell_PutChar | ( | signed portCHAR | cByte | ) |
Put a char to the COM1 port.
cByte | Input. The char to print. |
Definition at line 289 of file com1shell.c.
References COM1SHELL_NO_BLOCK, xComPort1Hndl, and xUsartPutChar().
Referenced by prv_PutChar_To_Requester_Stream(), and prvGetCmdLine().
00290 { 00291 xUsartPutChar( xComPort1Hndl, cByte, COM1SHELL_NO_BLOCK); 00292 }
void vStartCom1Shell | ( | unsigned portBASE_TYPE | uxPriority | ) |
Start the COM1 shell module.
uxPriority | The priority base of the COM1 shell tasks. |
Definition at line 137 of file com1shell.c.
References COM1SHELL_STACK_SIZE, sCom1ShellNavId, SYS_STATUS_DOWN, SYS_STATUS_STARTUP, v_com1shell_mount_local_drive(), xCom1ShellHndl, and xCom1ShellStatus.
Referenced by portTASK_FUNCTION().
00138 { 00139 xCom1ShellStatus = SYS_STATUS_STARTUP; 00140 00141 /* Get a File System navigator for COM1SHELL. */ 00142 fsaccess_take_mutex(); 00143 sCom1ShellNavId = fsaccess_alloc_nav_id(); 00144 fsaccess_give_mutex(); 00145 00146 /* Try to mount local drive */ 00147 v_com1shell_mount_local_drive(); 00148 00149 /* Spawn the shell task. */ 00150 if( xTaskCreate( vCom1ShellTask, ( const signed portCHAR * ) "SH", 00151 COM1SHELL_STACK_SIZE, NULL, uxPriority, &xCom1ShellHndl ) != pdPASS ) 00152 xCom1ShellStatus = SYS_STATUS_DOWN; 00153 }
eStatus xCom1Shell_GetStatus | ( | void | ) |
Return the status of the COM1 shell module.
Definition at line 167 of file com1shell.c.
References xCom1ShellStatus.
00168 { 00169 return xCom1ShellStatus; 00170 }
signed portCHAR acStringCmd[COM1SHELL_MAX_CMDLINE_LEN+1] [static] |
The cmd line string.
Definition at line 125 of file com1shell.c.
Referenced by portTASK_FUNCTION(), and prvGetCmdLine().
signed short sCom1ShellNavId |
COM1 shell navigator ID.
Definition at line 121 of file com1shell.c.
Referenced by portTASK_FUNCTION(), v_com1shell_mount_local_drive(), and vStartCom1Shell().
xTaskHandle xCom1ShellHndl = NULL |
COM1 shell task handle.
Definition at line 118 of file com1shell.c.
Referenced by vStartCom1Shell().
eStatus xCom1ShellStatus = SYS_STATUS_STARTUP [static] |
The COM1 shell module status.
Definition at line 112 of file com1shell.c.
Referenced by portTASK_FUNCTION(), vStartCom1Shell(), and xCom1Shell_GetStatus().
xComPortHandle xComPort1Hndl = NULL [static] |
Definition at line 115 of file com1shell.c.
Referenced by com1shell_GetChar(), portTASK_FUNCTION(), prvGetChar(), v_com1shell_stopResources(), vcom1shell_PrintMsg(), and vcom1shell_PutChar().