Allow NSH date command with no RTC. This command is useful without an RTC too. Also, this permits testing on the simulator which never has an RTC

This commit is contained in:
Gregory Nutt 2015-04-11 12:13:18 -06:00
parent c341e06e84
commit 23075e0b30
8 changed files with 25 additions and 21 deletions

View File

@ -179,8 +179,8 @@ config NSH_DISABLE_CMP
config NSH_DISABLE_DATE
bool "Disable date"
default n
depends on RTC
default n if RTC
default y if !RTC
config NSH_DISABLE_DD
bool "Disable dd"

View File

@ -42,7 +42,7 @@ include $(APPDIR)/Make.defs
ASRCS =
CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_script.c
CSRCS += nsh_command.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c
CSRCS += nsh_envcmds.c nsh_dbgcmds.c
CSRCS += nsh_timcmds.c nsh_envcmds.c nsh_dbgcmds.c
ifeq ($(CONFIG_NFILE_STREAMS),0)
CSRCS += nsh_stdsession.c
@ -69,10 +69,6 @@ CSRCS += nsh_routecmds.c
endif
endif
ifeq ($(CONFIG_RTC),y)
CSRCS += nsh_timcmds.c
endif
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
CSRCS += nsh_mntcmds.c
endif

View File

@ -343,8 +343,7 @@ o cp <source-path> <dest-path>
o date [-s "MMM DD HH:MM:SS YYYY"]
Show or set the current date and time. This command is only supported
if the platform supported RTC hardware (CONFIG_RTC=y).
Show or set the current date and time.
Only one format is used both on display and when setting the date/time:
MMM DD HH:MM:SS YYYY. For example,

View File

@ -848,7 +848,7 @@ void nsh_usbtrace(void);
int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif

View File

@ -140,7 +140,7 @@ static const struct cmdmap_s g_cmdmap[] =
# endif
#endif
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
{ "date", cmd_date, 1, 3, "[-s \"MMM DD HH:MM:SS YYYY\"]" },
#endif

View File

@ -240,7 +240,7 @@ static inline int ls_specialdir(const char *dir)
static int ls_handler(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
FAR struct dirent *entryp, FAR void *pvarg)
{
unsigned int lsflags = (unsigned int)pvarg;
unsigned int lsflags = (unsigned int)((uintptr_t)pvarg);
int ret;
/* Check if any options will require that we stat the file */
@ -995,19 +995,22 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* file
*/
ret = ls_handler(vtbl, fullpath, NULL, (void*)lsflags);
ret = ls_handler(vtbl, fullpath, NULL, (FAR void *)((uintptr_t)lsflags));
}
else
{
/* List the directory contents */
nsh_output(vtbl, "%s:\n", fullpath);
ret = foreach_direntry(vtbl, "ls", fullpath, ls_handler, (void*)lsflags);
ret = foreach_direntry(vtbl, "ls", fullpath, ls_handler,
(FAR void*)((uintptr_t)lsflags));
if (ret == OK && (lsflags & LSFLAGS_RECURSIVE) != 0)
{
/* Then recurse to list each directory within the directory */
ret = foreach_direntry(vtbl, "ls", fullpath, ls_recursive, (void*)lsflags);
ret = foreach_direntry(vtbl, "ls", fullpath, ls_recursive,
(FAR void *)((uintptr_t)lsflags));
}
}

View File

@ -365,7 +365,7 @@ static pthread_addr_t nsh_child(pthread_addr_t arg)
dbg("BG %s complete\n", carg->argv[0]);
nsh_releaseargs(carg);
return (void*)ret;
return (pthread_addr_t)((uintptr_t)ret);
}
#endif

View File

@ -65,7 +65,7 @@
* Private Data
****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
static FAR const char * const g_datemontab[] =
{
"jan", "feb", "mar", "apr", "may", "jun",
@ -85,7 +85,7 @@ static FAR const char * const g_datemontab[] =
* Name: date_month
****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
static inline int date_month(FAR const char *abbrev)
{
int i;
@ -105,7 +105,7 @@ static inline int date_month(FAR const char *abbrev)
* Name: date_gettime
****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name)
{
static const char format[] = "%b %d %H:%M:%S %Y";
@ -139,7 +139,7 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *nam
* Name: date_settime
****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name,
FAR char *newtime)
{
@ -178,6 +178,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{
goto errout_bad_parm;
}
tm.tm_mday = (int)result;
/* Get the hours */
@ -193,6 +194,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{
goto errout_bad_parm;
}
tm.tm_hour = (int)result;
/* Get the minutes */
@ -208,6 +210,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{
goto errout_bad_parm;
}
tm.tm_min = (int)result;
/* Get the seconds */
@ -223,6 +226,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{
goto errout_bad_parm;
}
tm.tm_sec = (int)result;
/* And finally the year */
@ -238,6 +242,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
{
goto errout_bad_parm;
}
tm.tm_year = (int)result - 1900;
/* Convert this to the right form, then set the timer */
@ -251,6 +256,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name
nsh_output(vtbl, g_fmtcmdfailed, name, "clock_settime", NSH_ERRNO);
return ERROR;
}
return OK;
errout_bad_parm:
@ -267,7 +273,7 @@ errout_bad_parm:
* Name: cmd_date
****************************************************************************/
#if defined (CONFIG_RTC) && !defined(CONFIG_NSH_DISABLE_DATE)
#ifndef CONFIG_NSH_DISABLE_DATE
int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
FAR char *newtime = NULL;