summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-07-28 15:18:26 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-07-28 15:18:26 +0000
commit666a2aea9bace7462c82972858bb79bebf4e36a6 (patch)
tree52871679f64d7f67529f037fadfeb242b5f2f1ad
parent17d494e95dcdbf313f9bd2b1d8d63886d672f2c2 (diff)
PM update; NSH extension to catch return values
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4987 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rwxr-xr-xapps/ChangeLog.txt2
-rw-r--r--apps/nshlib/nsh_apps.c43
-rw-r--r--apps/nshlib/nsh_parse.c46
-rw-r--r--nuttx/configs/stm3210e-eval/src/up_idle.c11
-rw-r--r--nuttx/configs/stm3210e-eval/src/up_lcd.c6
5 files changed, 83 insertions, 25 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 9edc37c4e7..ee7b8f26a5 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -259,3 +259,5 @@
* apps/modbus: Add CONFIG_MB_TERMIOS. If the driver doesn't support
termios ioctls, then don't bother trying to configure the baud, parity
etc.
+ * apps/nslib: If waitpid() is supported, then NSH not catches the
+ return value from spawned applications.
diff --git a/apps/nshlib/nsh_apps.c b/apps/nshlib/nsh_apps.c
index c6f7509489..eb019f57b2 100644
--- a/apps/nshlib/nsh_apps.c
+++ b/apps/nshlib/nsh_apps.c
@@ -84,7 +84,22 @@
****************************************************************************/
/****************************************************************************
- * Name: nsh_execute
+ * Name: nsh_execapp
+ *
+ * Description:
+ * Attempt to execute the application task whose name is 'cmd'
+ *
+ * Returned Value:
+ * -1 (ERRROR) if the application task corresponding to 'cmd' could not
+ * be started (possibly because it doesn not exist).
+ * 0 (OK) if the application task corresponding to 'cmd' was
+ * and successfully started. If CONFIG_SCHED_WAITPID is
+ * defined, this return value also indicates that the
+ * application returned successful status (EXIT_SUCCESS)
+ * 1 If CONFIG_SCHED_WAITPID is defined, then this return value
+ * indicates that the application task was spawned successfully
+ * but returned failure exit status.
+ *
****************************************************************************/
int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
@@ -103,7 +118,21 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
#ifdef CONFIG_SCHED_WAITPID
if (vtbl->np.np_bg == false)
{
- waitpid(ret, NULL, 0);
+ int rc = 0;
+
+ waitpid(ret, &rc, 0);
+
+ /* We can't return the exact status (nsh has nowhere to put it)
+ * so just pass back zero/nonzero in a fashion that doesn't look
+ * like an error.
+ */
+
+ ret = (rc == 0) ? OK : 1;
+
+ /* TODO: Set the environment variable '?' to a string corresponding
+ * to WEXITSTATUS(rc) so that $? will expand to the exit status of
+ * the most recently executed task.
+ */
}
else
#endif
@@ -111,11 +140,15 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
struct sched_param param;
sched_getparam(0, &param);
nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);
+
+ /* Backgrounded commands always 'succeed' as long as we can start
+ * them.
+ */
+
+ ret = OK;
}
- return OK;
+ return ret;
}
#endif /* CONFIG_NSH_BUILTIN_APPS */
-
-
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index 76cd4664ee..64850eb628 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -67,7 +67,7 @@
#include "nsh_console.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/* Argument list size
@@ -487,6 +487,16 @@ static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
/****************************************************************************
* Name: nsh_execute
+ *
+ * Description:
+ * Exectue the command in argv[0]
+ *
+ * Returned Value:
+ * -1 (ERRROR) if the command was unsuccessful
+ * 0 (OK) if the command was successful
+ * 1 if an application task was spawned successfully, but
+ * returned failure exit status.
+ *
****************************************************************************/
static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
@@ -506,18 +516,20 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
cmd = argv[0];
- /* Try to find a command in the application library.
- */
+ /* Try to find a command in the application library. */
#ifdef CONFIG_NSH_BUILTIN_APPS
- if (nsh_execapp(vtbl, cmd, argv) == OK)
- {
- /* The pre-built application was successfully started -- return OK. */
+ ret = nsh_execapp(vtbl, cmd, argv);
- return OK;
- }
-#endif
+ /* The pre-built application was successfully started -- return OK
+ * or 1 if it returned a non-zero exit status.
+ */
+ if (ret >= 0)
+ {
+ return ret;
+ }
+#endif
/* See if the command is one that we understand */
@@ -1123,6 +1135,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
break;
}
}
+
argv[argc] = NULL;
/* Check if the command should run in background */
@@ -1136,7 +1149,6 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
}
#endif
-
/* Check if the output was re-directed using > or >> */
if (argc > 2)
@@ -1285,6 +1297,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
nsh_release(bkgvtbl);
goto errout;
}
+
nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority);
}
else
@@ -1300,7 +1313,12 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
}
/* Then execute the command in "foreground" -- i.e., while the user waits
- * for the next prompt.
+ * for the next prompt. nsh_execute will return:
+ *
+ * -1 (ERRROR) if the command was unsuccessful
+ * 0 (OK) if the command was successful
+ * 1 if an application task was spawned successfully, but
+ * returned failure exit status.
*/
ret = nsh_execute(vtbl, argc, argv);
@@ -1314,7 +1332,11 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
nsh_undirect(vtbl, save);
}
- if (ret < 0)
+ /* Treat both errors and non-zero return codes as "errors" so that
+ * it is possible to test for non-zero returns in nsh scripts.
+ */
+
+ if (ret != OK)
{
goto errout;
}
diff --git a/nuttx/configs/stm3210e-eval/src/up_idle.c b/nuttx/configs/stm3210e-eval/src/up_idle.c
index b412aa5a99..296b48efcd 100644
--- a/nuttx/configs/stm3210e-eval/src/up_idle.c
+++ b/nuttx/configs/stm3210e-eval/src/up_idle.c
@@ -122,9 +122,8 @@
****************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_RTC_ALARM)
-static volatile bool g_alarmwakeup;
+static volatile bool g_alarmwakeup; /* Wakeup Alarm indicator */
#endif
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -159,7 +158,7 @@ static void up_alarmcb(void)
****************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_RTC_ALARM)
-static void up_alarm_exti(int irq, FAR void *context);
+static int up_alarm_exti(int irq, FAR void *context)
{
up_alarmcb();
return OK;
@@ -175,7 +174,7 @@ static void up_alarm_exti(int irq, FAR void *context);
****************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_RTC_ALARM)
-static void up_exti_cancel(void);
+static void up_exti_cancel(void)
{
(void)stm32_exti_alarm(false, false, false, NULL);
}
@@ -190,7 +189,7 @@ static void up_exti_cancel(void);
****************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_RTC_ALARM)
-static int int up_rtc_alarm(int irq, FAR void *context);
+static int up_rtc_alarm(time_t tv_sec, time_t tv_nsec, bool exti)
{
struct timespec alarmtime;
int ret;
@@ -201,7 +200,7 @@ static int int up_rtc_alarm(int irq, FAR void *context);
{
/* TODO: Make sure that that is no pending EXTI interrupt */
- stm32_exti_alarm(true, true, true, up_alarm_exti);
+ (void)stm32_exti_alarm(true, true, true, up_alarm_exti);
}
/* Configure the RTC alarm to Auto Wake the system */
diff --git a/nuttx/configs/stm3210e-eval/src/up_lcd.c b/nuttx/configs/stm3210e-eval/src/up_lcd.c
index 6f50323ed1..8b832aafb3 100644
--- a/nuttx/configs/stm3210e-eval/src/up_lcd.c
+++ b/nuttx/configs/stm3210e-eval/src/up_lcd.c
@@ -1238,8 +1238,10 @@ static void stm3210e_pm_notify(struct pm_callback_s *cb , enum pm_state_e pmstat
stm3210e_writereg(LCD_REG_59, 0x00); /* Gate scan stop */
}
-// Does this belong here?
- (void)stm3210e_poweroff();
+ else
+ {
+ (void)stm3210e_poweroff();
+ }
}
break;