00001
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00058
00059 #include <string.h>
00060 #include "FreeRTOS.h"
00061 #include "task.h"
00062
00063
00064 #include "serial.h"
00065
00066 #include "supervisor.h"
00067 #include "serial.h"
00068 #include "fs_com.h"
00069 #include "fsaccess.h"
00070
00071 #include "shell.h"
00072
00073 #include "com1shell.h"
00074
00075 #include "tracedump.h"
00076
00077
00078
00079
00080
00081 #define COM1SHELL_MSG_LINETOOLONG "\r\nLine too long!\r\n"
00082
00083
00085 #define MAX_CMD_LEN 32
00086
00087 #define COM1SHELL_MAX_CMDLINE_LEN (MAX_CMD_LEN + 2 * MAX_FILE_PATH_LENGTH)
00088
00089
00090 #define COM1SHELL_STACK_SIZE 384
00091
00092
00093
00094 #define COM1SHELL_NO_BLOCK ( ( portTickType ) 0 )
00095
00096
00097 #define COM1SHELL_RX_BLOCK_TIME ( ( portTickType ) 0xffff )
00098 #define COM1SHELL_RX_SHORT_BLOCK_TIME ( ( portTickType ) 1 )
00099
00100
00102 #define COM1SHELL_BAUDRATE ( ( unsigned portLONG ) 57600 )
00104 #define COM1SHELL_RXBUFFER_LEN ( ( unsigned portLONG ) 64 )
00105 #define COM1SHELL_TXBUFFER_LEN ( ( unsigned portLONG ) 32 )
00106
00108 #define COM1SHELL_MSG_BANNER "\x0C\r\n---------- ATMEL AVR32 Shell ----------\r\n"
00109 #define COM1SHELL_MSG_PROMPT "$>"
00110
00112 static eStatus xCom1ShellStatus = SYS_STATUS_STARTUP;
00113
00114
00115 static xComPortHandle xComPort1Hndl = NULL;
00116
00118 xTaskHandle xCom1ShellHndl = NULL;
00119
00121 signed short sCom1ShellNavId;
00122
00123
00125 static signed portCHAR acStringCmd[COM1SHELL_MAX_CMDLINE_LEN+1];
00126
00127 static unsigned portCHAR prvGetCmdLine( void );
00128 static signed portBASE_TYPE prvGetChar( signed portCHAR *pcByte,
00129 portTickType xBlockTime );
00130 static portTASK_FUNCTION( vCom1ShellTask, pvParameters );
00131
00132
00137 void vStartCom1Shell( unsigned portBASE_TYPE uxPriority )
00138 {
00139 xCom1ShellStatus = SYS_STATUS_STARTUP;
00140
00141
00142 fsaccess_take_mutex();
00143 sCom1ShellNavId = fsaccess_alloc_nav_id();
00144 fsaccess_give_mutex();
00145
00146
00147 v_com1shell_mount_local_drive();
00148
00149
00150 if( xTaskCreate( vCom1ShellTask, ( const signed portCHAR * ) "SH",
00151 COM1SHELL_STACK_SIZE, NULL, uxPriority, &xCom1ShellHndl ) != pdPASS )
00152 xCom1ShellStatus = SYS_STATUS_DOWN;
00153 }
00154
00158 void v_com1shell_stopResources( void )
00159 {
00160 vSerialClose( xComPort1Hndl );
00161 }
00162
00167 eStatus xCom1Shell_GetStatus( void )
00168 {
00169 return xCom1ShellStatus;
00170 }
00171
00172
00173 static portTASK_FUNCTION( vCom1ShellTask, pvParameters )
00174 {
00175 signed portCHAR *pcStringReply = NULL;
00176 eExecStatus xExeStatus;
00177
00178
00179
00180 ( void ) pvParameters;
00181
00182
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);
00189 }
00190
00191 xCom1ShellStatus = SYS_STATUS_RUNNING;
00192
00193 vcom1shell_PrintMsg((signed portCHAR *)COM1SHELL_MSG_BANNER);
00194
00195 for(;;)
00196 {
00197
00198 if(prvGetCmdLine() == 0)
00199 continue;
00200
00201
00202 xExeStatus = Shell_exec(acStringCmd, SYS_MODID_COM1SHELL, sCom1ShellNavId, &pcStringReply);
00203
00204
00205 if( NULL != pcStringReply )
00206 vcom1shell_PrintMsg(pcStringReply);
00207 if( ( NULL != pcStringReply ) && ( SHELL_EXECSTATUS_OK == xExeStatus ) )
00208 vPortFree(pcStringReply);
00209 }
00210 }
00211
00212
00218 static unsigned portCHAR prvGetCmdLine( void )
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);
00233 vcom1shell_PutChar(c);
00234 acStringCmd[idx] = '\0';
00235 return(idx);
00236 case CR:
00237 vcom1shell_PutChar(c);
00238 vcom1shell_PutChar(LF);
00239 acStringCmd[idx] = '\0';
00240 return(idx);
00241 case ABORT_CHAR:
00242 idx = 0;
00243 vcom1shell_PutChar(LF);
00244 vcom1shell_PrintMsg( (signed portCHAR *)COM1SHELL_MSG_PROMPT );
00245 break;
00246 case BKSPACE_CHAR:
00247 if (idx > 0)
00248 {
00249 vcom1shell_PrintMsg( (signed portCHAR *)"\b \b" );
00250 idx--;
00251 }
00252 break;
00253 default:
00254 vcom1shell_PutChar(c);
00255 acStringCmd[idx++] = c;
00256 break;
00257 }
00258 }
00259 }
00260 vcom1shell_PrintMsg( (signed portCHAR *)COM1SHELL_MSG_LINETOOLONG );
00261 return(0);
00262 }
00263
00264
00265
00266
00270 void vcom1shell_PrintMsg(const signed portCHAR *pcString)
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 }
00284
00285
00289 void vcom1shell_PutChar(signed portCHAR cByte)
00290 {
00291 xUsartPutChar( xComPort1Hndl, cByte, COM1SHELL_NO_BLOCK);
00292 }
00293
00294
00298 signed portBASE_TYPE com1shell_GetChar(signed portCHAR *pcByte)
00299 {
00300 return( xUsartGetChar( xComPort1Hndl, pcByte, COM1SHELL_RX_BLOCK_TIME ) );
00301 }
00302
00303
00307 static signed portBASE_TYPE prvGetChar(signed portCHAR *pcByte, portTickType xBlockTime)
00308 {
00309 return( xUsartGetChar( xComPort1Hndl, pcByte, xBlockTime ) );
00310 }
00311
00312
00316 void v_com1shell_mount_local_drive( void )
00317 {
00318 fsaccess_take_mutex();
00319 nav_select( sCom1ShellNavId );
00320 nav_drive_set(LUN_ID_AT45DBX_MEM);
00321 nav_partition_mount();
00322 fsaccess_give_mutex();
00323 }
00324