summaryrefslogtreecommitdiff
path: root/contrib/patches/chibios-2.6.1-shell.patch
blob: 9e5a7acae8d9181f25d18afac9ee6ccfa553073c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Index: os/various/shell.c
===================================================================
--- os/various/shell.c	(Revision 6402)
+++ os/various/shell.c	(Arbeitskopie)
@@ -135,10 +135,11 @@
  * @return              Termination reason.
  * @retval RDY_OK       terminated by command.
  * @retval RDY_RESET    terminated by reset condition on the I/O channel.
+ *
+ * @notapi
  */
 static msg_t shell_thread(void *p) {
   int n;
-  msg_t msg = RDY_OK;
   BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
   const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
   char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
@@ -190,16 +191,15 @@
       }
     }
   }
-  /* Atomically broadcasting the event source and terminating the thread,
-     there is not a chSysUnlock() because the thread terminates upon return.*/
-  chSysLock();
-  chEvtBroadcastI(&shell_terminated);
-  chThdExitS(msg);
-  return 0; /* Never executed.*/
+  shellExit(RDY_OK);
+  /* Never executed, silencing a warning.*/
+  return 0;
 }
 
 /**
  * @brief   Shell manager initialization.
+ *
+ * @api
  */
 void shellInit(void) {
 
@@ -207,6 +207,24 @@
 }
 
 /**
+ * @brief   Terminates the shell.
+ * @note    Must be invoked from the command handlers.
+ * @note    Does not return.
+ *
+ * @param[in] msg       shell exit code
+ *
+ * @api
+ */
+void shellExit(msg_t msg) {
+
+  /* Atomically broadcasting the event source and terminating the thread,
+     there is not a chSysUnlock() because the thread terminates upon return.*/
+  chSysLock();
+  chEvtBroadcastI(&shell_terminated);
+  chThdExitS(msg);
+}
+
+/**
  * @brief   Spawns a new shell.
  * @pre     @p CH_USE_MALLOC_HEAP and @p CH_USE_DYNAMIC must be enabled.
  *
@@ -215,6 +233,8 @@
  * @param[in] prio      priority level for the new shell
  * @return              A pointer to the shell thread.
  * @retval NULL         thread creation failed because memory allocation.
+ *
+ * @api
  */
 #if CH_USE_HEAP && CH_USE_DYNAMIC
 Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio) {
@@ -247,6 +267,8 @@
  * @return              The operation status.
  * @retval TRUE         the channel was reset or CTRL-D pressed.
  * @retval FALSE        operation successful.
+ *
+ * @api
  */
 bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
   char *p = line;
Index: os/various/shell.h
===================================================================
--- os/various/shell.h	(Revision 6402)
+++ os/various/shell.h	(Arbeitskopie)
@@ -70,6 +70,7 @@
 extern "C" {
 #endif
   void shellInit(void);
+  void shellExit(msg_t msg);
   Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio);
   Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
                             size_t size, tprio_t prio);