diff --git a/firmware/ec/.cproject b/firmware/ec/.cproject index 7fa4929253..6dd1176437 100644 --- a/firmware/ec/.cproject +++ b/firmware/ec/.cproject @@ -42,7 +42,7 @@ - + @@ -52,6 +52,7 @@ + diff --git a/firmware/ec/.settings/org.eclipse.core.resources.prefs b/firmware/ec/.settings/org.eclipse.core.resources.prefs index bcaa2bd97f..92a1f668cc 100755 --- a/firmware/ec/.settings/org.eclipse.core.resources.prefs +++ b/firmware/ec/.settings/org.eclipse.core.resources.prefs @@ -20,6 +20,8 @@ encoding//Debug/src/Devices/uart/subdir_rules.mk=UTF-8 encoding//Debug/src/Devices/uart/subdir_vars.mk=UTF-8 encoding//Debug/src/comm/subdir_rules.mk=UTF-8 encoding//Debug/src/comm/subdir_vars.mk=UTF-8 +encoding//Debug/src/console/subdir_rules.mk=UTF-8 +encoding//Debug/src/console/subdir_vars.mk=UTF-8 encoding//Debug/src/devices/i2c/subdir_rules.mk=UTF-8 encoding//Debug/src/devices/i2c/subdir_vars.mk=UTF-8 encoding//Debug/src/devices/ocmp_wrappers/subdir_rules.mk=UTF-8 diff --git a/firmware/ec/OpenCellular.cfg b/firmware/ec/OpenCellular.cfg index ba7308d578..ef1f168a8c 100644 --- a/firmware/ec/OpenCellular.cfg +++ b/firmware/ec/OpenCellular.cfg @@ -15,6 +15,7 @@ var Tcp = xdc.useModule('ti.ndk.config.Tcp'); var Icmp = xdc.useModule('ti.ndk.config.Icmp'); var DhcpClient = xdc.useModule('ti.ndk.config.DhcpClient'); var Event = xdc.useModule('ti.sysbios.knl.Event'); +var Telnet = xdc.useModule('ti.ndk.config.Telnet'); /* * Default value is family dependent. For example, Linux systems often only * support a minimum period of 10000 us and multiples of 10000 us. @@ -196,7 +197,7 @@ BIOS.assertsEnabled = true; /* * Specify default heap size for BIOS. */ -BIOS.heapSize = 102400; +BIOS.heapSize = 32000; /* * A flag to determine if xdc.runtime sources are to be included in a custom @@ -471,7 +472,7 @@ Task.idleTaskStackSize = 512; */ Task.numPriorities = 16; - +Task.common$.namedInstance = true; /* ================ Text configuration ================ */ var Text = xdc.useModule('xdc.runtime.Text'); @@ -568,6 +569,7 @@ m3Hwi0Params.instance.name = "m3Hwi0"; m3Hwi0Params.enableInt = false; Program.global.m3Hwi0 = m3Hwi.create(73, "&UART4IntHandler", m3Hwi0Params); */ + /* var m3Hwi1Params = new m3Hwi.Params(); m3Hwi1Params.instance.name = "m3Hwi1"; @@ -578,7 +580,8 @@ Program.global.m3Hwi1 = m3Hwi.create(60, "&uDMAIntHandler", m3Hwi1Params); /*var m3Hwi2Params = new m3Hwi.Params(); m3Hwi2Params.instance.name = "m3Hwi2"; m3Hwi2Params.enableInt = false; -Program.global.m3Hwi2 = m3Hwi.create(61, "&uDMAErrorHandler", m3Hwi2Params);*/ +Program.global.m3Hwi2 = m3Hwi.create(61, "&uDMAErrorHandler", m3Hwi2Params); +*/ /* WatchDog */ var m3Hwi0Params = new m3Hwi.Params(); m3Hwi0Params.instance.name = "m3Hwi0"; @@ -586,10 +589,13 @@ m3Hwi0Params.enableInt = false; Program.global.m3Hwi0 = m3Hwi.create(34, "&WatchdogIntHandler", m3Hwi0Params); /* UART3 */ + var m3Hwi0Params = new m3Hwi.Params(); m3Hwi0Params.instance.name = "m3Hwi0"; m3Hwi0Params.enableInt = false; Program.global.m3Hwi0 = m3Hwi.create(72, "&UART3IntHandler", m3Hwi0Params); + + /* ================ Application Specific Instances ================ */ /* ================ NDK configuration ================ */ var Ndk = xdc.loadPackage('ti.ndk.config'); @@ -618,4 +624,8 @@ Global.normTaskPriLevel = 8; Global.highTaskPriLevel = 9; Global.kernTaskPriLevel = 11; var Ip = xdc.module('ti.ndk.config.Ip'); -Ip.autoIp = true; +Ip.autoIp = false; +var telnet0Params = new Telnet.Params(); +telnet0Params.callBackFxn = "&ConsoleOpen"; +var telnet0 = Telnet.create(telnet0Params); +Ip.address = "192.168.1.2"; diff --git a/firmware/ec/inc/common/global_header.h b/firmware/ec/inc/common/global_header.h index 987ce906f6..e3c3efe9d0 100644 --- a/firmware/ec/inc/common/global_header.h +++ b/firmware/ec/inc/common/global_header.h @@ -14,6 +14,8 @@ #define _FW_REV_BUGFIX_ 0 #define _FW_REV_TAG_ __COMMIT_HASH__ +#define xstr(a) str(a) +#define str(a) #a /* xdc/runtime/System.h is poorly written so this must be included first */ #include diff --git a/firmware/ec/inc/devices/at45db.h b/firmware/ec/inc/devices/at45db.h index ba6cbd291a..0a0dfd64c9 100644 --- a/firmware/ec/inc/devices/at45db.h +++ b/firmware/ec/inc/devices/at45db.h @@ -29,7 +29,7 @@ typedef void (*AT45DB_CallbackFn)(AT45DB_Event evt, uint16_t value, typedef struct AT45DB_Cfg { SPI_Dev dev; OcGpio_Pin *pin_alert; - const char *fileName[5]; + const char *fileName[32]; uint8_t noOfFiles; } AT45DB_Cfg; diff --git a/firmware/ec/inc/interfaces/uartdma.h b/firmware/ec/inc/interfaces/uartdma.h index c4979dee86..964da0f252 100644 --- a/firmware/ec/inc/interfaces/uartdma.h +++ b/firmware/ec/inc/interfaces/uartdma.h @@ -23,8 +23,11 @@ #define OCUARTDMATX_TASK_PRIORITY 7 #define OCUARTDMATX_TASK_STACK_SIZE 2048 -#define UART_TXBUF_SIZE 128 -#define UART_RXBUF_SIZE 128 +#define AP_CON_UARTDMA_TASK_PRIORITY 8 +#define AP_CONUARTDMA_TASK_STACK_SIZE 4096 + +#define UART_TXBUF_SIZE 256 +#define UART_RXBUF_SIZE 1024 /***************************************************************************** * HANDLE DECLARATIONS diff --git a/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_GBC.c b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_GBC.c index 3a3beb9ac9..e607394849 100644 --- a/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_GBC.c +++ b/firmware/ec/platform/oc-sdr/schema/cfg/OC_CONNECT_GBC.c @@ -75,8 +75,8 @@ AT45DB_Dev gbc_spi_flash_memory = { .chip_select = &(OcGpio_Pin){ &ec_io, OC_EC_FLASH_nCS }, }, .pin_alert = NULL, - .fileName = { "alertLog", "configLog", "bootLog" }, - .noOfFiles = 3, + .fileName = { "alertLog", "configLog", "apConsoleLogs", "ecLogs" }, + .noOfFiles = 4, }, .obj = {}, }; diff --git a/firmware/ec/src/bigbrother.c b/firmware/ec/src/bigbrother.c index 4f7975f3db..f7f4cedd91 100644 --- a/firmware/ec/src/bigbrother.c +++ b/firmware/ec/src/bigbrother.c @@ -313,9 +313,14 @@ static void bigborther_spwan_task(void) usb_tx_createtask(); // P - 04 /*UART task*/ +#ifndef SERIAL_LOGGING + ap_console_createtask(); +#endif + +#ifdef SERIAL_BRIDGE uartdma_rx_createtask(); uartdma_tx_createtask(); - +#endif /* Gossiper*/ gossiper_createtask(); // P - 06 diff --git a/firmware/ec/src/console/console.c b/firmware/ec/src/console/console.c new file mode 100644 index 0000000000..3e69dd6b58 --- /dev/null +++ b/firmware/ec/src/console/console.c @@ -0,0 +1,478 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * */ +/* + * ======== console.c ======== + * + * Example router console + * + */ + +#include +#include <_stack.h> +#include <_oskern.h> +#include "console.h" + +char *VerStr = "OpenCellular EC Console."; + +static void console( HANDLE hCon, PSA pClient ); +static char *StrBusy = "\nConsole is busy\n\n"; +static char *StrError = "\nCould not spawn console\n\n"; +static char Password[32] = {0}; + +/*------------------------------------------------------------------------- */ +/* Console IO */ +/* The following routines form a basic standard IO for console functions */ +/*------------------------------------------------------------------------- */ +#define INMAX 32 +static char InBuf[INMAX]; +static int InIdx = 0; +static int InCnt = 0; +static SOCKET scon = INVALID_SOCKET; +static HANDLE hConsole = 0; + +/*-------------------------------------------------------------- */ +/* ConPrintf() */ +/* Formatted print to console output */ +/*-------------------------------------------------------------- */ +int ConPrintf(const char *format, ...) +{ + va_list ap; + char buffer[256]; + int size; + + va_start(ap, format); + size = NDK_vsprintf(buffer, (char *)format, ap); + va_end(ap); + + send( scon, buffer, size, 0 ); + return( size ); +} + +/*-------------------------------------------------------------- */ +/* ConPrintIPN */ +/* Quick routine to print out an IPN addr */ +/*-------------------------------------------------------------- */ +void ConPrintIPN( IPN IPAddr ) +{ + IPAddr = htonl( IPAddr ); + ConPrintf( "%d.%d.%d.%d", + (UINT8)((IPAddr>>24)&0xFF), (UINT8)((IPAddr>>16)&0xFF), + (UINT8)((IPAddr>>8)&0xFF), (UINT8)(IPAddr&0xFF) ); +} + +/*-------------------------------------------------------------- */ +/* ConGetCh() */ +/* Read a character from console input */ +/*-------------------------------------------------------------- */ +char ConGetCh() +{ + char c; + struct timeval timeout; + + /* Configure our console timeout to be 5 minutes */ + timeout.tv_sec = 5 * 60; + timeout.tv_usec = 0; + + while( 1 ) + { + while( !InCnt ) + { + fd_set ibits; + int cnt; + + FD_ZERO(&ibits); + FD_SET(scon, &ibits); + + /* Wait for io */ + cnt = fdSelect( (int)scon, &ibits, 0, 0, &timeout ); + if( cnt <= 0 ) + goto abort_console; + + /* Check for input data */ + if( FD_ISSET(scon, &ibits) ) + { + /* We have characters to input */ + cnt = (int)recv( scon, InBuf, INMAX, 0 ); + if( cnt > 0 ) + { + InIdx = 0; + InCnt = cnt; + } + /* If the socket was closed or error, major abort */ + if( !cnt || (cnt<0 && fdError()!=EWOULDBLOCK) ) + goto abort_console; + } + } + + InCnt--; + c = InBuf[InIdx++]; + + if( c != '\n' ) + return( c ); + } + +abort_console: + ConsoleClose(); + + fdClose( scon ); + TaskExit(); + + return(0); +} + +/*-------------------------------------------------------------- */ +/* ConGetString() */ +/* Read a string from console input (with various echo options) */ +/*-------------------------------------------------------------- */ +int ConGetString( char *buf, int max, int echo ) +{ + int idx=0, eat=0; + char c; + + while( idx < (max-1) ) + { + c = ConGetCh(); + + /* Eat char if we're eating */ + if( eat ) + { + if( eat == 27 && c == 79 ) + eat = 1; + else + eat = 0; + continue; + } + + /* Start eating if this is an extended char */ + if( !c ) + { + eat = 255; + continue; + } + + /* Start eating if this is an escape code */ + if( c == 27 ) + { + eat = 27; + continue; + } + + /* Back up on backspace */ + if( c == 8 ) + { + if( idx ) + { + idx--; + ConPrintf("%c %c",8,8); + } + continue; + } + + /* Return on CR */ + if( c == '\r' ) + break; + + buf[idx++] = c; + if( echo == CGSECHO_INPUT ) + ConPrintf("%c",c); + else if( echo == CGSECHO_PASSWORD ) + ConPrintf("*"); + } + + buf[idx] = 0; + return( idx ); +} + +/*-------------------------------------------------------------- */ +/* ConGetIP() */ +/* Prompt for and read an IP adress from console input */ +/*-------------------------------------------------------------- */ +IPN ConGetIP() +{ + int haveit = 0; + char c,str[32]; + IPN IPTmp; + + while( !haveit ) + { + ConPrintf("Enter IP as x.x.x.x : "); + ConGetString( str, 20, CGSECHO_INPUT ); + IPTmp = inet_addr( str ); + ConPrintf("\nYou Entered "); + ConPrintIPN( IPTmp ); + ConPrintf("\nIs this correct (y/n)\n"); + + do { c=ConGetCh(); } + while( c != 'y' && c !='Y' && c != 'N' && c != 'n' ); + + if( c=='Y' || c=='y' ) + haveit = 1; + } + return( IPTmp ); +} + +/*--------------------------------------------------------------------- */ +/* ConsoleOpen() */ +/* Launch a console connection to the speicified client */ +/* Returns local socket, or INVALID_SOCKET on error */ +/*--------------------------------------------------------------------- */ +SOCKET ConsoleOpen( PSA pClient ) +{ + HANDLE fd1, fd2; + + // Create the local pipe - abort on error + if( pipe( &fd1, &fd2 ) != 0 ) + return( INVALID_SOCKET ); + + /* If an instance is already running, abort */ + if( hConsole ) + { + /* If the console is already running, return a quick message and */ + /* close the pipe. */ + send( fd2, StrBusy, strlen(StrBusy), 0 ); + fdClose( fd2 ); + } + else + { + /* Create the console thread */ + hConsole = TaskCreate( console, "Console", OS_TASKPRINORM, 0x1000, + (UINT32)fd2, (UINT32)pClient, 0 ); + + /* Close the pipe and abort on an error */ + if( !hConsole ) + { + send( fd2, StrError, strlen(StrError), 0 ); + fdClose( fd2 ); + } + } + + /* Return the local fd */ + return( fd1 ); +} + +/*--------------------------------------------------------------------- */ +/* ConsoleClose() */ +/* Close the console task when active */ +/*--------------------------------------------------------------------- */ +void ConsoleClose() +{ + HANDLE hTmp; + + if( hConsole ) + { + hTmp = hConsole; + hConsole = 0; + + /* Close the console socket session. This will cause */ + /* the console app thread to terminate with socket */ + /* error. */ + fdCloseSession( hTmp ); + } +} + +void ConCmdEcho( int ntok, char *tok1, char *tok2 ) +{ + ConPrintf("%s %s\n",tok1, tok2); +} + +void ConCmdName( ) +{ + ConPrintf("OpenCellular SDR {ConnectOne} \n"); +} +/*--------------------------------------------------------------------- */ +/* console() */ +/* This is the main console task. */ +/* Arg1 = IP Addr, Arg2 = UDP Foreign Port */ +/*--------------------------------------------------------------------- */ +static void console( SOCKET sCon, PSA pClient ) +{ + uint tmp; + char tstr[80]; + char *tok[10]; + int i,logon=0; + + fdOpenSession( TaskSelf() ); + + /* Get our socket */ + scon = sCon; + + /* New console connection */ + { + PSA_IN pClient_in = (PSA_IN)pClient; + openCellular_banner(); + ConPrintf( VerStr ); + ConPrintf("\nWelcome to OC EC CLI : "); + ConPrintIPN( pClient_in->sin_addr.s_addr ); + ConPrintf(":%d\n", htons( pClient_in->sin_port ) ); + } + + /* Just for fun, ask for a password */ + for( tmp=0; tmp<3; tmp++ ) + { + if( !strlen(Password) ) + break; + ConPrintf("\nPassword: "); + ConGetString( tstr, 32, CGSECHO_PASSWORD ); + if( !strcmp(tstr, Password) ) + break; + ConPrintf("\nInvalid login\n"); + } + if( tmp >= 3 ) + logon = 0; + else + { + ConPrintf("\n\nWelcome to the console program.\n"); + ConPrintf("Enter '?' or 'help' for a list of commands.\n\n"); + logon = 1; + } + + /* Start the console command loop */ + while( logon ) + { + /* Get a command string */ + ConPrintf(">"); + ConGetString( tstr, 80, CGSECHO_INPUT ); + ConPrintf("\n"); + + /* Break the string down into tokens */ + tmp = 0; + i = 0; + tok[0] = tstr; + while( tstr[i] && tmp < 10 ) + { + if( tstr[i] == ' ' ) + { + tstr[i] = 0; + if( ++tmp < 10 ) + tok[tmp] = tstr+i+1; + } + i++; + } + /* We terminated due to a NULL, then we have one more token */ + if( tmp < 10 ) + tmp++; + + /* Process the command */ + if( i ) + { + if( *tok[0] == '?' || !stricmp( tok[0], "help" ) ) + { + ConPrintf( VerStr ); + ConPrintf("\n[Help Command]\n\nThe basic commands are:\n"); + ConPrintf(" saymyname - Returns the device name.\n"); + ConPrintf(" bye - Logoff the console\n"); + ConPrintf(" echo - Perform echo test\n"); + ConPrintf(" help - Displays this message\n"); + ConPrintf(" nslookup - Lookup hostname or IP address\n"); + ConPrintf(" pswd - Change console password\n"); + ConPrintf(" ping - Test echo request\n"); + ConPrintf(" quit - Logoff the console\n"); + ConPrintf(" reboot - Reboot system (terminates session)\n"); + ConPrintf(" resetAP - Reset Application processor)\n"); + ConPrintf(" showRoute - Maintain route table\n"); + ConPrintf(" shutdownNDK - Shutdown stack (terminates session)\n"); + ConPrintf(" showSocket - Print socket table\n"); + ConPrintf(" showNDKStat - Print internal stack statistics\n"); + ConPrintf(" showIPaddr - Configuration of IPAddress\n"); + ConPrintf(" showLogs - Display EC logs.\n"); + ConPrintf(" showConsoleLogs - Display AP boot logs.\n"); + ConPrintf(" showAlerts - Display EC Alerts.\n"); + ConPrintf(" showTaskStats - Display EC Task.\n"); + ConPrintf(" showMessageQueueStats - Display EC Message Queues.\n"); + ConPrintf(" showMem - Display memory status\n"); + ConPrintf(" uploadFirmware - Display memory status\n"); + ConPrintf("\nSome commands have additional help information. For example\n"); + ConPrintf("entering 'route' gives more information on the route command.\n\n"); + } + else if( !stricmp( tok[0], "bye" ) || !stricmp( tok[0], "quit" ) ) + logon = 0; + else if( !stricmp( tok[0], "saymyname" ) ) + ConCmdName( ); + else if( !stricmp( tok[0], "showRoute" ) ) + ConCmdRoute( tmp-1, tok[1], tok[2], tok[3], tok[4] ); + else if( !stricmp( tok[0], "showNDKStat" ) ) + ConCmdStat( tmp-1, tok[1] ); + else if( !stricmp( tok[0], "nslookup" ) ) + ConCmdLookup( tmp-1, tok[1] ); + else if( !stricmp( tok[0], "ping" ) ) + ConCmdPing( tmp-1, tok[1], tok[2] ); + else if( !stricmp( tok[0], "echo" ) ) + ConCmdEcho( tmp-1, tok[1], tok[2] ); + else if( !stricmp( tok[0], "showSocket" ) ) + ConCmdSocket( tmp-1, tok[1] ); + else if( !stricmp( tok[0], "showIPaddr" ) ) + ConCmdIPAddr ( tmp-1, tok[1], tok[2], tok[3], tok[4] ); + else if( !stricmp( tok[0], "reboot" ) ) + NC_NetStop(1); + else if( !stricmp( tok[0], "resetAP" ) ) + util_reset_ap(1); + else if( !stricmp( tok[0], "shutdown" ) ) + NC_NetStop(0); + else if( !stricmp( tok[0], "showMem" ) ) + _mmCheck( MMCHECK_MAP, &ConPrintf ); + else if( !stricmp( tok[0], "pswd" ) ) + { + if( tmp<2 || strlen(tok[1]) > 31 ) + ConPrintf("Usage: pswd newpassword\n\n"); + else + { + strcpy(Password,tok[1]); + ConPrintf("Console password is now '%s'\n\n",Password); + } + } + else if( !stricmp( tok[0], "showLogs" ) ) + util_show_ec_logs(tmp-1, tok[1]); + else if( !stricmp( tok[0], "showConsoleLogs" ) ) + util_show_ap_console_logs(); + else if( !stricmp( tok[0], "showAlerts" ) ) + util_show_ec_alerts(tmp-1, tok[1]); + else if( !stricmp( tok[0], "showTaskStats" ) ) + util_show_task_stat(); + else if( !stricmp( tok[0], "showMessageQueueStats" ) ) + util_show_msg_queue_stat( ); + else if( !stricmp( tok[0], "uploadFirmware" ) ) + util_load_file( tmp-1, tok[1], tok[2]); + else + ConPrintf("Invalid command - Enter '?' or 'help' for a list of commands.\n"); + } + } + + /* Close the console */ + ConPrintf("\nGoodbye\n"); + + /* Close console thread */ + ConsoleClose(); + + fdClose( scon ); + TaskExit(); +} + diff --git a/firmware/ec/src/console/console.h b/firmware/ec/src/console/console.h new file mode 100644 index 0000000000..9d242ddb35 --- /dev/null +++ b/firmware/ec/src/console/console.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2012-2015, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * */ +/* + * ======== console.h ======== + * + * Example router console include + * + */ + +#ifndef _CONSOLE_H +#define _CONSOLE_H + +/* Functions Defined in Console routines */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* CONSOLE.C */ +extern SOCKET ConsoleOpen( PSA pSinClient ); +extern void ConsoleClose(); + +/* The folloing io routines are used by console functions */ +extern int ConPrintf(const char *format, ...); +extern void ConPrintIPN( IPN dwIP ); +extern char ConGetCh(); +extern int ConGetString( char *buf, int max, int echo ); +#define CGSECHO_NONE 0 +#define CGSECHO_INPUT 1 +#define CGSECHO_PASSWORD 2 +extern IPN ConGetIP(); + +/* CONROUTE.C */ +extern void ConCmdRoute( int ntok, char *tok1, char *tok2, + char *tok3, char *tok4 ); + +/* CONACCT.C */ +extern void ConCmdAcct( int ntok, char *tok1, char *tok2, + char *tok3, char *tok4 ); + +/* CONNAT.C */ +extern void ConCmdNat( int ntok, char *, char *, char *, char *, char * ); + +/* CONSTAT.C */ +extern void ConCmdStat( int ntok, char *tok1 ); + +/* CONDNS.C */ +extern void ConCmdLookup( int ntok, char *tok1 ); +extern int ConStrToIPN( char *str, IPN *pIPN ); + +/* CONPING.C */ +extern void ConCmdPing( int ntok, char *tok1, char *tok2 ); + +/* CONECHO.C */ +extern void ConCmdEcho( int ntok, char *tok1, char *tok2 ); + +/* CONSOCK.C */ +extern void ConCmdSocket( int ntok, char *tok1 ); + +/* CONTFTP.C */ +extern void ConCmdTFTP( int ntok, char *tok1, char *tok2 ); + +/* CONTEST.C */ +extern void ConCmdTest( int ntok, char *tok1, char *tok2 ); + +/* VLAN Support is available only if NIMU support is available. */ +extern void ConCmdVLAN( int ntok, char *tok1, char *tok2, char *tok3, char* tok4 ); +extern void ConCmdIPAddr( int ntok, char *tok1, char *tok2, char *tok3, char* tok4 ); + +#ifdef _INCLUDE_IPv6_CODE +extern void ConCmdIPv6(int ntok, char *tok1, char *tok2, char *tok3, char* tok4, char* tok5, char* tok6, char* tok7); +extern void ConCmdPing6 ( int ntok, char *tok1, char *tok2 ); +extern void ConCmdLookupIPv6( int ntok, char *tok1 ); +extern void ConIPv6DisplayIPAddress (IP6N address); +#endif + +/* CONLLI.C */ +void ConCmdLLI( int ntok, char *tok1, char *tok2, char *tok3 ); + +#ifdef __cplusplus +} +#endif /* extern "C" */ + +#endif /* _CONSOLE_H */ diff --git a/firmware/ec/src/console/oc_telnet_util.c b/firmware/ec/src/console/oc_telnet_util.c new file mode 100644 index 0000000000..b3d65ff40e --- /dev/null +++ b/firmware/ec/src/console/oc_telnet_util.c @@ -0,0 +1,251 @@ +/* + * oc_telnet_util.c + * + * Created on: Apr 26, 2019 + * Author: vthakur + */ + +#include +#include <_stack.h> +#include "console.h" +#include +/*------------------------------------------------------------------------- */ +/* ConCmdTFTP() */ +/* Function to perform TFTP */ +/*------------------------------------------------------------------------- */ + +#include +#include +#include +#include + +#include "inc/common/global_header.h" +#include "src/filesystem/fs_wrapper.h" + +void openCellular_banner(void) +{ + ConPrintf( + "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"); + ConPrintf( + "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"); + ConPrintf( + "|||| |||| |||| ||||| |||||| |||| |||| |||| ||||||||| ||||||||| |||| |||| ||||||||| |||| ||||\n"); + ConPrintf( + "|||| |||| |||| |||| |||| |||||||||| | ||||| |||| ||||||||| ||||||||| ||||||||| ||||||||| |||| |||| ||||||||| |||| |||| |||| ||||\n"); + ConPrintf( + "|||| |||| |||| |||| |||| |||||||||| || |||| |||| ||||||||| ||||||||| ||||||||| ||||||||| |||| |||| ||||||||| |||| |||| |||| ||||\n"); + ConPrintf( + "|||| |||| |||| |||| ||||| ||| ||| |||| ||||||||| |||| ||||||||| ||||||||| |||| |||| ||||||||| |||| ||||\n"); + ConPrintf( + "|||| |||| |||| |||||||||| |||||||||| |||| || |||| ||||||||| ||||||||| ||||||||| ||||||||| |||| |||| ||||||||| |||| |||| || ||||||\n"); + ConPrintf( + "|||| |||| |||| |||||||||| |||||||||| ||||| | |||| ||||||||| ||||||||| ||||||||| ||||||||| |||| |||| ||||||||| |||| |||| ||| |||||\n"); + ConPrintf( + "|||| |||| |||||||||| ||||| |||||| |||| |||| |||| |||| |||| |||| |||| |||| |||| |||| ||||\n"); + ConPrintf( + "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"); + ConPrintf( + "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n"); + ConPrintf("\nOCWare v" xstr(_FW_REV_MAJOR_) "." xstr(_FW_REV_MINOR_) "." xstr(_FW_REV_BUGFIX_) "-" xstr(_FW_REV_TAG_) "\n"); + ConPrintf("Build Date: " __DATE__ " " __TIME__ "\n\n"); +} +void __dumpTask(Task_Handle task) +{ + Task_Stat stat; + + Task_stat(task, &stat); + ConPrintf("0x%08x: %32s %12d %12d %12d %12d\n", task, Task_Handle_name(task), stat.priority, + stat.mode, stat.stackSize, stat.used); +} + +void __listTasks() +{ + Task_Object * task; + Int i; + + for (i = 0; i < Task_Object_count(); i++) { + task = Task_Object_get(NULL, i); + __dumpTask(task); + } + + task = Task_Object_first(); + while (task) { + __dumpTask(task); + task = Task_Object_next(task); + } +} + +void __dumpSemaphore(Task_Handle task) +{ + Task_Stat stat; + + Task_stat(task, &stat); + ConPrintf("0x%08x: %32s %12d %12d %12d %12d\n", task, Task_Handle_name(task), stat.priority, + stat.mode, stat.stackSize, stat.used); +} + +void __dumpQueue(Queue_Object* queue) +{ + ConPrintf("0x%08 %32s %32s\n",queue, Queue_Handle_name(queue), (((Queue_empty(queue)==true)==true)?"Empty":"Elements pending for processing.")); +} + +void __listMessageQueue() +{ + Queue_Object * queue; + Int i; + + for (i = 0; i < Queue_Object_count(); i++) { + queue = Queue_Object_get(NULL, i); + __dumpQueue(queue); + } + + queue = Queue_Object_first(); + while (queue) { + __dumpQueue(queue); + queue = Queue_Object_next(queue); + } +} + +void __listSemaphore() +{ + Task_Object * task; + Int i; + + for (i = 0; i < Task_Object_count(); i++) { + task = Task_Object_get(NULL, i); + __dumpTask(task); + } + + task = Task_Object_first(); + while (task) { + __dumpTask(task); + task = Task_Object_next(task); + } +} + +/*------------------------------------------------------------------------- */ +/* __load_file */ +/*------------------------------------------------------------------------- */ +static void __load_file( IPN IPAddr, char *File ) +{ + int rc; + char *buffer; + UINT16 ErrorCode; + UINT32 Size; + + buffer = mmAlloc(3000); + if( !buffer ) + { + ConPrintf("\nFailed allocating temp buffer\n"); + return; + } + + Size = 3000; + rc = NtTftpRecv( IPAddr, File, buffer, &Size, &ErrorCode ); + + if( rc >= 0 ) + { + UINT32 i; + int c; + + ConPrintf("\nFile Retrieved: Size is %d\n",Size); + + if( !rc ) + Size = 3000; + + ConPrintf("\nDisplay (%d bytes) (y/n)\n",Size); + do { c=ConGetCh(); } + while( c != 'y' && c !='Y' && c != 'N' && c != 'n' ); + if( c=='Y' || c=='y' ) + for( i=0; iSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if( pTftp->Sock == INVALID_SOCKET ) + { + rc = TFTPERROR_SOCKET; + goto ABORT; + } + + /* Initialize the bind the local address */ + bzero( &pTftp->tmpaddr, sizeof(struct sockaddr_in) ); + pTftp->tmpaddr.sin_family = AF_INET; + + /* Assign local name to the unnamed socket */ + /* Do not care about local Host Address or Port (both 0) */ + /* If no error, bind returns 0 */ + if( bind( pTftp->Sock, (PSA)&pTftp->tmpaddr, sizeof(pTftp->tmpaddr) ) < 0 ) + { + rc = TFTPERROR_SOCKET; + goto ABORT; + } + + /* Set the socket IO timeout */ + timeout.tv_sec = TFTP_SOCK_TIMEOUT; + timeout.tv_usec = 0; + if( setsockopt( pTftp->Sock, SOL_SOCKET, SO_SNDTIMEO, + &timeout, sizeof(timeout)) < 0 ) + { + rc = TFTPERROR_SOCKET; + goto ABORT; + } + if( setsockopt( pTftp->Sock, SOL_SOCKET, SO_RCVTIMEO, + &timeout, sizeof(timeout)) < 0 ) + { + rc = TFTPERROR_SOCKET; + goto ABORT; + } + + /* Initialize the foreign address - we don't use "connect", since */ + /* the peer port will change. We use sendto() */ + bzero( &pTftp->peeraddr, sizeof(struct sockaddr_in) ); + pTftp->peeraddr.sin_family = AF_INET; + pTftp->peeraddr.sin_addr.s_addr = pTftp->PeerAddress; + pTftp->peeraddr.sin_port = htons(PORT_TFTP); + rc = 0; + +ABORT: + return(rc); +} + +/* + * tftpRRQBuild() + * Build an initial file request packet + */ +static void tftpRRQBuild(TFTP *pTftp) +{ + struct tftphdr *RRQ_Packet; + static char *pszOctet = "octet"; + char *pRRQ_Data; + + RRQ_Packet = (struct tftphdr *)pTftp->PacketBuffer; + + /* A request packet consists of an opcode (RRQ) followed */ + /* by a NULL terminated filename and mode ("octet") */ + + /* Opcode = RRQ */ + RRQ_Packet->opcode = htons(RRQ); + + /* Get a pointer to the rest of the packet */ + pRRQ_Data = (char *)&RRQ_Packet->block; + + /* Copy NULL terminated filename string to request */ + /* increment data pointer by length of Filename (and terminating '0') */ + strcpy(pRRQ_Data, pTftp->szFileName); + pRRQ_Data += strlen(pTftp->szFileName) + 1; + + /* Copy NULL terminated mode string to request */ + /* increment data pointer by length of mode (and terminating '0') */ + strcpy(pRRQ_Data, pszOctet); + pRRQ_Data += strlen(pszOctet) + 1; + + /* calculate length of packet */ + pTftp->Length = (int)(pRRQ_Data - (char *)RRQ_Packet); + + return; +} + +/* + * tftpACKBuild() + * Bluild TFTP block ACK packet + */ +static void tftpACKBuild(TFTP *pTftp) +{ + struct tftphdr *ACK_Packet; + + ACK_Packet = (struct tftphdr *)pTftp->PacketBuffer; + + ACK_Packet->opcode = htons(ACK); + + /* Build the rest of the ACK packet */ + + /* Block Number */ + ACK_Packet->block = htons( pTftp->NextBlock ); + + /* Set length of packet */ + pTftp->Length = 4; /* Opcode + Block */ +} + +/* + * tftpSend() + * Send pre-built packet to peer + */ +static int tftpSend( TFTP *pTftp) +{ + int rc = 0; + int BytesSent; + + BytesSent = sendto(pTftp->Sock, pTftp->PacketBuffer, + (int)pTftp->Length, 0,(struct sockaddr *)&pTftp->peeraddr, + sizeof(pTftp->peeraddr)); + + if ( BytesSent != (int)pTftp->Length ) + rc = TFTPERROR_SOCKET; + + return(rc); +} + +/* + * tftpReadPacket() + * Read a data packet from the peer socket + * Sets bytes read to ZERO on a timeout + */ +static int tftpReadPacket( TFTP *pTftp ) +{ + int rc = 0; + int addrLength; + struct tftphdr *ReadBuffer; + INT32 BytesRead; + UINT32 TimeStart; + + ReadBuffer = (struct tftphdr *)pTftp->PacketBuffer; + TimeStart = llTimerGetTime(0); + +RETRY: + /* Don't allow stray traffic to keep us alive */ + if( (TimeStart+TFTP_SOCK_TIMEOUT) <= llTimerGetTime(0) ) + { + BytesRead = 0; + goto ABORT; + } + + /* Attempt to read data */ + addrLength = sizeof(pTftp->tmpaddr); + BytesRead = recvfrom( pTftp->Sock, ReadBuffer, DATA_SIZE, 0, + (struct sockaddr *)&pTftp->tmpaddr, &addrLength ); + + /* Handle read errors first */ + if( BytesRead < 0 ) + { + /* On a timeout error, ABORT with no error */ + /* Else report error */ + if( fdError() == EWOULDBLOCK ) + BytesRead = 0; + else + rc = TFTPERROR_SOCKET; + goto ABORT; + } + + /* If this packet is not from our peer, retry */ + if( pTftp->tmpaddr.sin_addr.s_addr != pTftp->PeerAddress ) + goto RETRY; + + /* If the peer port is NOT TFTP, then it must match our expected */ + /* peer. */ + if( pTftp->peeraddr.sin_port != htons(PORT_TFTP) ) + { + if( pTftp->tmpaddr.sin_port != pTftp->peeraddr.sin_port ) + goto RETRY; + } + +ABORT: + pTftp->Length = (UINT32)BytesRead; /* Store number of bytes read */ + return(rc); +} + +/* + * tftpFlushPackets() + * Flush all input from socket + */ +static void tftpFlushPackets(TFTP *pTftp) +{ + int bytesread; + + /* Sleep for a second */ + TaskSleep( 1000 ); + + do + { + bytesread = recv( pTftp->Sock, pTftp->PacketBuffer, + DATA_SIZE, MSG_DONTWAIT ); + } while( bytesread > 0 ); +} + +/* + * tftpReSync() + * + * Attempt to ReSync a failed transfer + */ +int tftpReSync( TFTP *pTftp ) +{ + int rc = 0; + + /* Fluch pending input packets */ + tftpFlushPackets( pTftp ); + + /* Abort if too many Sync errors */ + pTftp->MaxSyncError--; + if( pTftp->MaxSyncError == 0 ) + { + rc = TFTPERROR_FAILED; + goto ABORT; /* Too Many Sync Errors */ + } + + /* Back up expected block */ + pTftp->NextBlock--; + + /* Resend last packet - if we're on block ZERO, resend the initial */ + /* request. */ + if( !pTftp->NextBlock ) + tftpRRQBuild( pTftp ); + else + tftpACKBuild( pTftp ); + + /* Send the packet */ + rc = tftpSend( pTftp ); + if( rc < 0 ) + goto ABORT; + + pTftp->NextBlock++; /* Increment next expected BLOCK */ + +ABORT: + return(rc); +} + +/* + * tftpProcessPacket() + * + * Processes a data packet obtained from ReadPacket() + * + * Returns: + * 1 - Operation Complete + * 0 - Operation Progressing + * <0 - Error Condition + */ +static int tftpProcessPacket( TFTP *pTftp ) +{ + int rc = 0, done = 0; + UINT16 OpCode; + UINT16 ServerBlock; + UINT32 CopySize; + struct tftphdr *ReadBuffer; + + ReadBuffer = (struct tftphdr *)pTftp->PacketBuffer; + + /* Check for a bad packet - resynch on error */ + if( !pTftp->Length ) + return( tftpReSync( pTftp ) ); + + OpCode = (UINT16) ntohs(ReadBuffer->opcode); + switch (OpCode) + { + case ERROR : + /* Copy the error code */ + pTftp->ErrorCode = (UINT16) ntohs(ReadBuffer->block); + + /* If the buffer is large enough, copy the error message */ + pTftp->Length -= TFTP_HEADER; /* Get payload length */ + + /* Copy file data if room left in buffer is large enough */ + if( pTftp->BufferSize >= pTftp->Length ) + { + bcopy( ReadBuffer->data, pTftp->Buffer, (int)pTftp->Length ); + pTftp->BufferUsed = pTftp->Length; + } + else + pTftp->BufferUsed = 0; + + rc = TFTPERROR_ERRORREPLY; + break; + + case DATA : + /* Received Data, verify BLOCK correct */ + ServerBlock = (UINT16) ntohs(ReadBuffer->block); + + /* If this is not the block we're expecting, resync */ + if (pTftp->NextBlock != ServerBlock) + { + rc = tftpReSync( pTftp ); + pTftp->Length = 0; + break; + } + + /* If this is the first block, reset our port number. */ + if( pTftp->NextBlock == 1 ) + pTftp->peeraddr.sin_port = pTftp->tmpaddr.sin_port; /* Update TID */ + + /* Block is for me! */ + pTftp->MaxSyncError = MAX_SYNC_TRIES; /* reset Sync Counter */ + pTftp->Length -= TFTP_HEADER; /* Get payload length */ + CopySize = CopySize; /* Copy length */ + pTftp->FileSize += CopySize; /* Track the file length */ + + if( (pTftp->BufferUsed+CopySize)BufferSize) + { + //Copy the data from buffer to Flash. + + //Send data to External flash. + + + //Set buffer used bytes to zero + pTftp->BufferUsed = 0; + } + /* Copy file data if room left in buffer is large enough */ + if( pTftp->BufferSize > pTftp->BufferUsed ) + { + if( (pTftp->BufferSize - pTftp->BufferUsed) < CopySize) + CopySize = pTftp->BufferSize - pTftp->BufferUsed; + + if( CopySize ) + { + /* Add it to our receive buffer */ + bcopy( ReadBuffer->data, (pTftp->Buffer+pTftp->BufferUsed), + (int)CopySize ); + + /* Track the number of bytes used */ + pTftp->BufferUsed += CopySize; + } + } + + /* If we received a partial block, we're done */ + if( pTftp->Length < SEGSIZE ) + done = 1; + + /* Need to acknowledge this block */ + tftpACKBuild( pTftp ); + rc = tftpSend( pTftp ); + if( rc < 0 ) + break; + + /* Increment next expected BLOCK */ + pTftp->NextBlock++; + + /* Our done flag is the return code on success */ + rc = done; + break; + + default: + rc = TFTPERROR_FAILED; + break; + } + + return(rc); +} + +/* tftpGetFile() */ +/* Called to receive a file using TFTP. Called with TFTP parameter */ +/* structure initialized. */ +/* Returns: */ +/* 1 - If file was sucessfully transferred */ +/* 0 - If the file was transferred but too large for the buffer */ +/* <0 - Error */ +static int tftpGetFile( TFTP *pTftp ) +{ + int rc = 0; + + /* Build the request packet */ + tftpRRQBuild( pTftp ); + + /* Send the request packet */ + rc = tftpSend( pTftp ); + if( rc < 0 ) + goto ABORT; + + /* Now look for response packets */ + pTftp->MaxSyncError = MAX_SYNC_TRIES; /* set sync error counter */ + pTftp->NextBlock = 1; /* first block expected is "1" */ + + for(;;) + { + /* Try and get a reply packet */ + rc = tftpReadPacket( pTftp ); + if( rc < 0 ) + goto ABORT; + + /* Process the reply packet */ + rc = tftpProcessPacket( pTftp ); + if( rc < 0 ) + goto ABORT; + + /* If done, break out of loop */ + if( rc == 1 ) + break; + } + + /* If the receive buffer was too small, return 0, else return 1 */ + if( pTftp->BufferUsed < pTftp->FileSize ) + rc = 0; + else + rc = 1; + +ABORT: + return(rc); +} + +/* int NtTftpRecv() */ +/* Retrieve a file using TFTP */ +/* Return Conditions: */ +/* In the following cases, FileSize is set to the actual file size: */ +/* 1 - If file was sucessfully transferred */ +/* 0 - If the file was transferred but too large for the buffer */ +/* In the following cases, FileSize is set to the actual number of */ +/* bytes copied. */ +/* <0 - Error */ +/* TFTPERROR_ERRORCODE: TFTP server error code. The error code */ +/* is written to pErrorCode, and an error message is */ +/* written to FileBuffer. The length of the error message */ +/* is written to FileSize. */ +int NtTftpRecv( UINT32 TftpIP, char *szFileName, char *FileBuffer, + UINT32 *FileSize, UINT16 *pErrorCode ) +{ + TFTP *pTftp; + int rc; /* Return Code */ + + /* Quick parameter validation */ + if( !szFileName || !FileSize || (*FileSize != 0 && !FileBuffer) ) + return( TFTPERROR_BADPARAM ); + + /* Malloc Parameter Structure */ + if( !(pTftp = mmAlloc( sizeof(TFTP) )) ) + return( TFTPERROR_RESOURCES ); + + /* Initialize parameters to "NULL" */ + bzero( pTftp, sizeof(TFTP) ); + pTftp->Sock = INVALID_SOCKET; + + /* Malloc Packet Data Buffer */ + if( !(pTftp->PacketBuffer = mmAlloc( DATA_SIZE )) ) + { + rc = TFTPERROR_RESOURCES; + goto ABORT; + } + + /* store IP in network byte order */ + pTftp->PeerAddress = TftpIP; + + /* Setup initial socket */ + rc = tftpSocketSetup( pTftp ); + if( rc < 0 ) + goto ABORT; + + /* Socket now registered and available for use. Get the data */ + pTftp->szFileName = szFileName; + pTftp->Buffer = FileBuffer; + pTftp->BufferSize = *FileSize; /* Do not read more than can fit in file */ + + /* Get the requested file */ + rc = tftpGetFile( pTftp ); + if( rc < 0 ) + { + /* ERROR CONDITION */ + + /* Set the "FileSize" to the actual number of bytes copied */ + *FileSize = pTftp->BufferUsed; + + /* If the ErrorCode pointer is valid, copy it */ + if( pErrorCode ) + *pErrorCode = pTftp->ErrorCode; + } + else + { + /* SUCCESS CONDITION */ + + /* Set the "FileSize" to the file size (regardless of bytes copied) */ + *FileSize = pTftp->FileSize; + } + +ABORT: + if( pTftp->Sock != INVALID_SOCKET ) + fdClose( pTftp->Sock ); + if( pTftp->PacketBuffer ) + mmFree( pTftp->PacketBuffer ); + mmFree( pTftp ); + + return(rc); +} + diff --git a/firmware/ec/src/console/tftp.h b/firmware/ec/src/console/tftp.h new file mode 100644 index 0000000000..b0e9f91f9a --- /dev/null +++ b/firmware/ec/src/console/tftp.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2012-2015, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * */ +/* + * ======== tftp.h ======== + * + * TFTP includes + * + */ + +#ifndef _TFTP_H_ +#define _TFTP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Trivial File Transfer Protocol */ +#define SEGSIZE 512 /* data segment size */ + +/* TFTP Packet types. */ +#define RRQ 1 /* read request */ +#define WRQ 2 /* write request */ +#define DATA 3 /* data packet */ +#define ACK 4 /* acknowledgement */ +#define ERROR 5 /* error code */ + +struct tftphdr +{ + short opcode; /* packet type */ + short block; /* block # */ + char data[1]; /* data or error string */ +}; + +/* Error codes. */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ + +#ifdef __cplusplus +} +#endif /* extern "C" */ + +#endif diff --git a/firmware/ec/src/console/tftpinc.h b/firmware/ec/src/console/tftpinc.h new file mode 100644 index 0000000000..df220cc7e2 --- /dev/null +++ b/firmware/ec/src/console/tftpinc.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2012-2015, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * */ +/* + * ======== tftpinc.h ======== + * + * TFTP include + * + */ + +#ifndef _TFTPINC_H +#define _TFTPINC_H + +#include +#include <_stack.h> +#include "tftp.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define TFTP_HEADER 4 +#define DATA_SIZE (SEGSIZE + TFTP_HEADER) /* SEGSIZE declared in TFTP.H as 512 */ +#define PORT_TFTP 69 + +/* structure of a TFTP instance */ +typedef struct _tftp +{ + IPN PeerAddress; /* Peer address supplied by caller */ + char *szFileName; /* Filename supplied by caller */ + char *Buffer; /* Buffer supplied by caller */ + UINT32 BufferSize; /* Buffer size supplied by caller */ + SOCKET Sock; /* Socket used for transfer */ + char *PacketBuffer; /* Packet Buffer */ + UINT32 Length; /* Length of packet send and reveive */ + UINT32 BufferUsed; /* Amount of "Buffer" used */ + UINT32 FileSize; /* Size of specified file */ + UINT16 NextBlock; /* Next expected block */ + UINT16 ErrorCode; /* TFTP error code from server */ + int MaxSyncError; /* Max SYNC errors remaining */ + struct sockaddr_in tmpaddr; /* inaddr for RECV */ + struct sockaddr_in peeraddr; /* inaddr for SEND */ + +#ifdef _INCLUDE_IPv6_CODE + IP6N Peer6Address; /* Peer address supplied by caller */ + struct sockaddr_in6 tmp6addr; /* inaddr for RECV */ + struct sockaddr_in6 peer6addr; /* inaddr for SEND */ +#endif +} TFTP; + +#define MAX_SYNC_TRIES 4 /* Max retries */ +#define TFTP_SOCK_TIMEOUT 10 /* Packet Timeout in Seconds */ + +#ifdef __cplusplus +} +#endif /* extern "C" */ + +#endif diff --git a/firmware/ec/src/filesystem/fs_wrapper.c b/firmware/ec/src/filesystem/fs_wrapper.c index 3f8029f249..938c72d856 100644 --- a/firmware/ec/src/filesystem/fs_wrapper.c +++ b/firmware/ec/src/filesystem/fs_wrapper.c @@ -46,6 +46,8 @@ #define READ_SIZE 256 #define WRITE_SIZE 256 +#define CONSOLE_BUFFER 256 + extern OCSubsystem *ss_reg[SUBSYSTEM_COUNT]; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" @@ -257,6 +259,72 @@ bool fs_wrapper_data_read(FILESystemStruct *fileSysStruct) return true; } +void fs_console(FILESystemStruct *fileSysStruct) +{ + char printdata[CONSOLE_BUFFER] = {'\0'}; + uint16_t printCount = 0; + uint16_t tmpCount = 0; + uint16_t iter = 0; + uint8_t check = 0; + file.cache.buffer = 0; /* make buffer zero to avoid fail, might be a bug with filesystem */ + if (lfs_file_open(&lfs, &file, fileSysStruct->fileName, + LFS_O_RDONLY) == LFS_ERR_OK) { + int32_t file_size = fs_wrapper_get_fileSize(fileSysStruct->fileName); + LOGGER_DEBUG("FS:: File %s reading %d bytes.\n",fileSysStruct->fileName,file_size); + while(file_size >= 0) { + if (lfs_file_read(&lfs, &file, printdata, CONSOLE_BUFFER) == CONSOLE_BUFFER) { + printCount = 0; + check = 0; + //Need to something like read line and print it in serial console + while(printCount fileName,CONSOLE_BUFFER); + } + file_size-=CONSOLE_BUFFER; + } + } else { + LOGGER_ERROR("FS:: File %s opening failed.\n",fileSysStruct->fileName); + } +} + +void fs_write(FILESystemStruct *fileSysStruct) +{ + if ( (fileSysStruct->fileSize + fileSysStruct->frameSize) > + fileSysStruct->maxFileSize) { + if (lfs_remove(&lfs, fileSysStruct->fileName)) { + fileSysStruct->fileSize = 0; + LOGGER_DEBUG("FS:: File %s at max size. Deletion of file success.\n",fileSysStruct->fileName); + } else { + LOGGER_ERROR("FS:: File %s at max size. Deletion of file failed.\n",fileSysStruct->fileName); + } + } + + if (lfs_file_open(&lfs, &file, fileSysStruct->fileName, + LFS_O_RDWR | LFS_O_APPEND) == LFS_ERR_OK) { + if (lfs_file_write(&lfs, &file, fileSysStruct->pMsg, + fileSysStruct->frameSize) == + fileSysStruct->frameSize) { + fileSysStruct->fileSize += fileSysStruct->frameSize; + LOGGER_DEBUG("FS:: File %s write success with %d bytes.\n",fileSysStruct->fileName,fileSysStruct->frameSize); + if (lfs_file_close(&lfs, &file) != LFS_ERR_OK) { + LOGGER_DEBUG("FS:: File %s didn't close successfully \n"); + } + } + } else { + LOGGER_ERROR("FS:: File %s opening failed.\n",fileSysStruct->fileName); + } + return true; +} + /***************************************************************************** ** FUNCTION NAME : fs_wrapper_data_write ** @@ -378,12 +446,20 @@ static bool fs_wrapper_msgHandler(FILESystemStruct *fileSysStruct) { switch (fileSysStruct->operation) { case WRITE_FLAG: - fs_wrapper_data_write(fileSysStruct); - Semaphore_post(semFSwriteMsg); + if(strcmp(fileSysStruct->fileName,"apConsoleLogs") == 0 ) + { + fs_write(fileSysStruct); + } else { + fs_wrapper_data_write(fileSysStruct); + Semaphore_post(semFSwriteMsg); + } break; case READ_FLAG: fs_wrapper_data_read(fileSysStruct); break; + case CONSOLE_LOG: + fs_console(fileSysStruct); + break; default: break; } @@ -440,13 +516,30 @@ void fs_wrapper_fileSystem_init(UArg arg0, UArg arg1) ((AT45DB_Dev *)arg0)->cfg.fileName[index], LFS_O_CREAT | LFS_O_EXCL) == LFS_ERR_OK) { LOGGER_DEBUG( - "FS:: File created successfully in flash(at45db) memory \n"); + "FS:: File %s created successfully in flash(at45db) memory \n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); if (lfs_file_close(&lfs, &file) == LFS_ERR_OK) { - LOGGER_DEBUG("FS:: File closed successfully \n"); + LOGGER_DEBUG("FS:: File %s closed successfully \n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); } } else { + if(strcmp(((AT45DB_Dev *)arg0)->cfg.fileName[index],"apConsoleLogs") == 0) { + if (!(lfs_remove(&lfs, ((AT45DB_Dev *)arg0)->cfg.fileName[index]))) { + LOGGER_DEBUG("FS:: File %s deletion success.\n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); + } else { + LOGGER_ERROR("FS:: File %s deletion failed.\n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); + } + + if (lfs_file_open(&lfs, &file, + ((AT45DB_Dev *)arg0)->cfg.fileName[index], + LFS_O_CREAT | LFS_O_EXCL) == LFS_ERR_OK) { + LOGGER_DEBUG( + "FS:: File %s created successfully in flash(at45db) memory \n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); + if (lfs_file_close(&lfs, &file) == LFS_ERR_OK) { + LOGGER_DEBUG("FS:: File %s closed successfully \n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); + } + } + } LOGGER_DEBUG( - "FS:: File already exist in flash(at45db) memory \n"); + "FS:: File %s already exist in flash(at45db) memory \n",((AT45DB_Dev *)arg0)->cfg.fileName[index]); } index++; } diff --git a/firmware/ec/src/filesystem/fs_wrapper.h b/firmware/ec/src/filesystem/fs_wrapper.h index c02d475198..5a0f1ae479 100644 --- a/firmware/ec/src/filesystem/fs_wrapper.h +++ b/firmware/ec/src/filesystem/fs_wrapper.h @@ -29,6 +29,7 @@ #define NO_OF_ALERT_FILES 8 #define READ_FLAG 0 #define WRITE_FLAG 1 +#define CONSOLE_LOG 2 Semaphore_Handle semFilesysMsg; Semaphore_Struct semFSstruct; @@ -50,11 +51,12 @@ Queue_Handle fsTxMsgQueue; typedef struct FILESystemStruct { char *fileName; - uint8_t frameSize; + uint32_t frameSize; uint8_t noOfFiles; void *pMsg; - uint16_t maxFileSize; + uint32_t maxFileSize; uint8_t operation; + uint32_t fileSize; } FILESystemStruct; int fs_wrapper_get_fileSize(const char *path); diff --git a/firmware/ec/src/interfaces/UART/uartdma.c b/firmware/ec/src/interfaces/UART/uartdma.c index 7de6609898..baf045f7dd 100644 --- a/firmware/ec/src/interfaces/UART/uartdma.c +++ b/firmware/ec/src/interfaces/UART/uartdma.c @@ -14,6 +14,7 @@ #include "common/inc/global/ocmp_frame.h" #include "inc/interfaces/uartdma.h" #include "inc/common/global_header.h" +#include "src/filesystem/fs_wrapper.h" #include #include @@ -36,6 +37,7 @@ /* Semaphore */ Semaphore_Handle semUART; Semaphore_Handle semUARTTX; +Semaphore_Handle semAPConsole; /* Queue object */ Queue_Struct uartRxMsg; @@ -50,6 +52,8 @@ static Char ocUARTDMATaskStack[OCUARTDMA_TASK_STACK_SIZE]; Task_Struct ocUARTDMATxTask; static Char ocUARTDMATxTaskStack[OCUARTDMATX_TASK_STACK_SIZE]; +Task_Struct AP_CON_UARTDMATask; +static Char AP_CON_UARTDMATaskStack[AP_CONUARTDMA_TASK_STACK_SIZE]; /***************************************************************************** * The transmit and receive buffers used for the UART transfers. There is one * transmit buffer and a pair of recieve ping-pong buffers. @@ -59,6 +63,7 @@ static uint8_t ui8RxBufA[UART_RXBUF_SIZE]; static uint8_t ui8RxBufB[UART_RXBUF_SIZE]; static uint8_t ui8uartdmaRxBuf[UART_RXBUF_SIZE]; +static uint8_t testBuffer[56000]; /***************************************************************************** * The control table used by the uDMA controller. This table must be aligned * to a 1024 byte boundary. @@ -116,7 +121,8 @@ void UART3IntHandler(void) /*Preparing message to send to UART RX Queue*/ memset(ui8uartdmaRxBuf, '\0', UART_RXBUF_SIZE); memcpy(ui8uartdmaRxBuf, ui8RxBufA, sizeof(ui8RxBufA)); - Semaphore_post(semUART); + Semaphore_post(semAPConsole); + //uDMAChannelEnable(UDMA_CHANNEL_ADC2); } /*Alternate Buffer*/ @@ -128,7 +134,8 @@ void UART3IntHandler(void) /*Preparing message to send to UART RX Queue*/ memset(ui8uartdmaRxBuf, '\0', UART_RXBUF_SIZE); memcpy(ui8uartdmaRxBuf, ui8RxBufB, sizeof(ui8RxBufB)); - Semaphore_post(semUART); + Semaphore_post(semAPConsole); + //uDMAChannelEnable(UDMA_CHANNEL_ADC2); } } @@ -207,6 +214,27 @@ void ConfigureUART(void) GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5); } +/***************************************************************************** + * Configure the UART and its pins. This must be called before UARTprintf(). + *****************************************************************************/ +void ap_configure_UART(void) +{ + LOGGER_DEBUG( + "UARTDMACTR:INFO::Configuring UART interface for communication.\n"); + + /* Enable the GPIO Peripheral used by the UART.*/ + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); + + /* Enable UART3 */ + SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); + SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART3); + + /* Configure GPIO Pins for UART mode.*/ + GPIOPinConfigure(GPIO_PA4_U3RX); + GPIOPinConfigure(GPIO_PA5_U3TX); + GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5); +} + /**************************************************************************** * * Initializes the UART4 peripheral and sets up the TX and RX uDMA channels. @@ -376,7 +404,22 @@ void InitUART3Transfer(void) * Intialize UART uDMA for the data transfer. This will initialise both Tx and * Rx Channel associated with UART Tx and Rx ****************************************************************************/ -void uartdma_init(void) +void uartDMAinterface_init(void) +{ + LOGGER_DEBUG("UARTDMACTR:INFO::Starting uDMA initialization.\n"); + SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); + SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); + IntEnable(INT_UDMAERR); + uDMAEnable(); + uDMAControlBaseSet(pui8ControlTable); + InitUART3Transfer(); +} + +/***************************************************************************** + * Intialize UART uDMA for the data transfer. This will initialise both Tx and + * Rx Channel associated with UART Tx and Rx + ****************************************************************************/ +void ap_console_dma_init(void) { LOGGER_DEBUG("UARTDMACTR:INFO::Starting uDMA intilaization.\n"); SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); @@ -390,26 +433,20 @@ void uartdma_init(void) /***************************************************************************** * Initialize the UART with DMA interface. ****************************************************************************/ -void uartDMAinterface_init(void) +void ap_console_if_init(void) { /*UART RX Semaphore */ - LOGGER_DEBUG("UARTDMACTR:INFO:: uartDMA interface intialization.\n"); - semUART = Semaphore_create(0, NULL, NULL); - if (semUART == NULL) { - LOGGER_ERROR("UARTDMACTR:ERROR::UART RX Semaphore creation failed.\n"); + LOGGER_DEBUG("UARTDMACTR:INFO:: AP uartDMA interface intialization.\n"); + semAPConsole = Semaphore_create(0, NULL, NULL); + if (semAPConsole == NULL) { + LOGGER_ERROR("UARTDMACTR:ERROR::AP UART RX Semaphore creation failed.\n"); } - /*UART OCMP RX Message Queue*/ - uartRxMsgQueue = Util_constructQueue(&uartRxMsg); - LOGGER_DEBUG( - "UARTDMACTR:INFO::Constructing message Queue 0x%x for UART RX OCMP Messages.\n", - uartRxMsgQueue); - /* Configure UART */ - ConfigureUART(); + ap_configure_UART(); /* Initialize UART */ - uartdma_init(); + ap_console_dma_init(); LOGGER_DEBUG("UARTDMACTR:INFO::Waiting for OCMP UART RX messgaes....!!!\n"); } @@ -560,8 +597,6 @@ void uartdma_rx_createtask(void) taskParams.stack = &ocUARTDMATaskStack; taskParams.priority = OCUARTDMA_TASK_PRIORITY; Util_create_task(&taskParams, &uartdma_rx_taskfxn, true); - //Task_construct(&ocUARTDMATask, (Task_FuncPtr)uartdma_rx_taskfxn, - // &taskParams, NULL); LOGGER_DEBUG("UARTDMACTRl:INFO::Creating UART DMA task function.\n"); } @@ -584,7 +619,103 @@ void uartdma_tx_createtask(void) taskParams.stack = &ocUARTDMATxTaskStack; taskParams.priority = OCUARTDMATX_TASK_PRIORITY; Util_create_task(&taskParams, &uartdma_tx_taskfxn, true); - //Task_construct(&ocUARTDMATxTask, (Task_FuncPtr)uartdma_tx_taskfxn, - // &taskParams, NULL); LOGGER_DEBUG("UARTDMACTRl:INFO::Creating UART DMA TX task function.\n"); } + +/***************************************************************************** + * ap_console_taskfxn -Handles the UART received data. + ****************************************************************************/ +static void ap_console_taskfxn(UArg arg0, UArg arg1) +{ + // Initialize application + ap_console_if_init(); + static int i = 0; + uint32_t offset = 0; + // Application main loop + while (true) { + if (Semaphore_pend(semAPConsole, BIOS_WAIT_FOREVER)) { + offset = i*UART_RXBUF_SIZE; + if(offset >54000) + { + LOGGER_DEBUG("FS::END Received packet %d total size %d\n",i , offset); + }else { + memcpy(testBuffer+offset,ui8uartdmaRxBuf,UART_RXBUF_SIZE); + i++; + LOGGER_DEBUG("FS:: Received packet %d total size %d\n",i , offset); + } + + /* LOGGER_DEBUG("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", + *(ui8uartdmaRxBuf+0),*(ui8uartdmaRxBuf+1),*(ui8uartdmaRxBuf+2),*(ui8uartdmaRxBuf+3),*(ui8uartdmaRxBuf+4),*(ui8uartdmaRxBuf+5),*(ui8uartdmaRxBuf+6),*(ui8uartdmaRxBuf+7),*(ui8uartdmaRxBuf+8),*(ui8uartdmaRxBuf+9), + *(ui8uartdmaRxBuf+10),*(ui8uartdmaRxBuf+11),*(ui8uartdmaRxBuf+12),*(ui8uartdmaRxBuf+13),*(ui8uartdmaRxBuf+14),*(ui8uartdmaRxBuf+15),*(ui8uartdmaRxBuf+16),*(ui8uartdmaRxBuf+17),*(ui8uartdmaRxBuf+18),*(ui8uartdmaRxBuf+19), + *(ui8uartdmaRxBuf+20),*(ui8uartdmaRxBuf+21),*(ui8uartdmaRxBuf+22),*(ui8uartdmaRxBuf+23),*(ui8uartdmaRxBuf+24),*(ui8uartdmaRxBuf+25),*(ui8uartdmaRxBuf+66),*(ui8uartdmaRxBuf+27),*(ui8uartdmaRxBuf+2),*(ui8uartdmaRxBuf+29)); + */ +#if 0 //Send data to File system task. + FILESystemStruct fileSysStruct = { + "apConsoleLogs", UART_RXBUF_SIZE, + 1, ui8uartdmaRxBuf, + 100000, WRITE_FLAG, 0 + }; + uint8_t *payload = malloc(sizeof(FILESystemStruct)); + if(payload) { + memcpy(payload,&fileSysStruct,sizeof(fileSysStruct)); + Util_enqueueMsg(fsRxMsgQueue, semFilesysMsg, payload); + } else { + LOGGER_DEBUG("Console logs writing failed.\n"); + } + Util_enqueueMsg(fsRxMsgQueue, semFilesysMsg, (uint8_t *)&fileSysStruct); +#endif +#if 0 + /* Reset Uart DMA if the SOF is not equal to 0X55 */ + if (ui8uartdmaRxBuf[0] != OCMP_MSG_SOF) { + resetUARTDMA(); + } else { + /* OCMP UART RX Messgaes */ + uint8_t *pWrite = NULL; + pWrite = (uint8_t *)malloc(sizeof(OCMPMessageFrame) + + OCMP_FRAME_MSG_LENGTH); + if (pWrite != NULL) { + memset(pWrite, '\0', UART_RXBUF_SIZE); + memcpy(pWrite, ui8uartdmaRxBuf, UART_RXBUF_SIZE); +#if 0 + uint8_t i = 0; + LOGGER_DEBUG("UARTDMACTR:INFO:: UART RX BUFFER:\n"); + for( i = 0; i < UART_RXBUF_SIZE; i++) + { + LOGGER_DEBUG("0x%x ",ui8uartdmaRxBuf[i]); + } + LOGGER_DEBUG("\n"); +#endif + Util_enqueueMsg(gossiperRxMsgQueue, semGossiperMsg, pWrite); + } else { + LOGGER_ERROR( + "UARTDMACTR:ERROR:: No memory left for Msg Length %d.\n", + UART_RXBUF_SIZE); + } + } +#endif + } + + } +} + +/****************************************************************************** + ** FUNCTION NAME : ap_console_createtask + ** + ** DESCRIPTION : Task creation function for the UARTDMA RX for AP console + ** + ** ARGUMENTS : None + ** + ** RETURN TYPE : None + ** + ******************************************************************************/ +void ap_console_createtask(void) +{ + Task_Params taskParams; + Task_Params_init(&taskParams); + taskParams.instance->name="AP_CONSOLE_UARTDMA_t"; + taskParams.stackSize = AP_CONUARTDMA_TASK_STACK_SIZE; + taskParams.stack = &AP_CON_UARTDMATaskStack; + taskParams.priority = AP_CON_UARTDMA_TASK_PRIORITY; + Util_create_task(&taskParams, &ap_console_taskfxn, true); + LOGGER_DEBUG("UARTDMACTRl:INFO::Creating Console UART DMA RX task function.\n"); +} diff --git a/firmware/ec/src/main.c b/firmware/ec/src/main.c index 4ea8d16961..abca81b3e9 100644 --- a/firmware/ec/src/main.c +++ b/firmware/ec/src/main.c @@ -16,8 +16,6 @@ #include #include -#define xstr(a) str(a) -#define str(a) #a //***************************************************************************** // FUNCTION DECLARATIONS diff --git a/firmware/ec/src/subsystem/gpp/gpp.c b/firmware/ec/src/subsystem/gpp/gpp.c index 1abb558466..f93352cc9e 100644 --- a/firmware/ec/src/subsystem/gpp/gpp.c +++ b/firmware/ec/src/subsystem/gpp/gpp.c @@ -65,7 +65,9 @@ bool gpp_pmic_control(Gpp_gpioCfg *driver, uint8_t control) //ebmp_init(driver); //SysCtlDelay(100); OcGpio_write(&driver->pin_ap_12v_onoff, true); - SysCtlDelay(100); + LOGGER_DEBUG("GPP:INFO:: GPP task on sleep mode.\n"); + //Task_sleep(90000); + LOGGER_DEBUG("GPP:INFO:: GPP task outoff sleep mode.\n"); if (gpp_check_core_power(driver)) { // OcGpio_write(&cfg->pin_ec_reset_to_proc, true); diff --git a/firmware/ec/src/subsystem/sys/sys.c b/firmware/ec/src/subsystem/sys/sys.c index 0638687eba..536e24fa8c 100644 --- a/firmware/ec/src/subsystem/sys/sys.c +++ b/firmware/ec/src/subsystem/sys/sys.c @@ -29,8 +29,8 @@ #include #include -#define OCFS_TASK_PRIORITY 1 -#define OCFS_TASK_STACK_SIZE 4096 +#define OCFS_TASK_PRIORITY 8 +#define OCFS_TASK_STACK_SIZE 8096 Task_Struct ocFSTask; Char ocFSTaskStack[OCFS_TASK_STACK_SIZE];