aboutsummaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-08-15 08:49:20 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-08-15 08:49:20 +0000
commit698e37b41c08fd2a3b250ba3d0737c942af14f19 (patch)
tree657f39fa3024e373a0e143f9d3ec718a5c53a893 /demos
parente2868efe1609e3371a6e75bdd78d35db57e7c246 (diff)
downloadChibiOS-698e37b41c08fd2a3b250ba3d0737c942af14f19.tar.gz
ChibiOS-698e37b41c08fd2a3b250ba3d0737c942af14f19.tar.bz2
ChibiOS-698e37b41c08fd2a3b250ba3d0737c942af14f19.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3236 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos')
-rw-r--r--demos/Posix-GCC/Makefile1
-rw-r--r--demos/Posix-GCC/main.c64
-rw-r--r--demos/Win32-MinGW/Makefile1
-rw-r--r--demos/Win32-MinGW/main.c32
4 files changed, 76 insertions, 22 deletions
diff --git a/demos/Posix-GCC/Makefile b/demos/Posix-GCC/Makefile
index 3a8b43c90..55fa40fb7 100644
--- a/demos/Posix-GCC/Makefile
+++ b/demos/Posix-GCC/Makefile
@@ -72,6 +72,7 @@ SRC = ${PORTSRC} \
${PLATFORMSRC} \
$(BOARDSRC) \
${CHIBIOS}/os/various/shell.c \
+ ${CHIBIOS}/os/various/chprintf.c \
main.c
# List ASM source files here
diff --git a/demos/Posix-GCC/main.c b/demos/Posix-GCC/main.c
index adfcf6925..543386a85 100644
--- a/demos/Posix-GCC/main.c
+++ b/demos/Posix-GCC/main.c
@@ -24,6 +24,7 @@
#include "hal.h"
#include "test.h"
#include "shell.h"
+#include "chprintf.h"
#define SHELL_WA_SIZE THD_WA_SIZE(4096)
#define CONSOLE_WA_SIZE THD_WA_SIZE(4096)
@@ -35,24 +36,76 @@ static Thread *cdtp;
static Thread *shelltp1;
static Thread *shelltp2;
-void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
+static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
+ size_t n, size;
+
+ (void)argv;
+ if (argc > 0) {
+ chprintf(chp, "Usage: mem\r\n");
+ return;
+ }
+ n = chHeapStatus(NULL, &size);
+ chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
+ chprintf(chp, "heap fragments : %u\r\n", n);
+ chprintf(chp, "heap free total : %u bytes\r\n", size);
+}
+
+static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
+ static const char *states[] = {
+ "READY",
+ "CURRENT",
+ "SUSPENDED",
+ "WTSEM",
+ "WTMTX",
+ "WTCOND",
+ "SLEEPING",
+ "WTEXIT",
+ "WTOREVT",
+ "WTANDEVT",
+ "SNDMSGQ",
+ "SNDMSG",
+ "WTMSG",
+ "WTQUEUE",
+ "FINAL"
+ };
+ Thread *tp;
+
+ (void)argv;
+ if (argc > 0) {
+ chprintf(chp, "Usage: threads\r\n");
+ return;
+ }
+ chprintf(chp, " addr stack prio refs state time\r\n");
+ tp = chRegFirstThread();
+ do {
+ chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
+ (uint32_t)tp, (uint32_t)tp->p_ctx.esp,
+ (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
+ states[tp->p_state], (uint32_t)tp->p_time);
+ tp = chRegNextThread(tp);
+ } while (tp != NULL);
+}
+
+static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
Thread *tp;
(void)argv;
if (argc > 0) {
- shellPrintLine(chp, "Usage: test");
+ chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp);
if (tp == NULL) {
- shellPrintLine(chp, "out of memory");
+ chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = {
+ {"mem", cmd_mem},
+ {"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL}
};
@@ -76,9 +129,10 @@ static msg_t console_thread(void *arg) {
(void)arg;
while (!chThdShouldTerminate()) {
- puts((char *)chMsgWait());
+ Thread *tp = chMsgWait();
+ puts((char *)chMsgGet(tp));
fflush(stdout);
- chMsgRelease(RDY_OK);
+ chMsgRelease(tp, RDY_OK);
}
return 0;
}
diff --git a/demos/Win32-MinGW/Makefile b/demos/Win32-MinGW/Makefile
index 652c60b44..73e938d44 100644
--- a/demos/Win32-MinGW/Makefile
+++ b/demos/Win32-MinGW/Makefile
@@ -72,6 +72,7 @@ SRC = ${PORTSRC} \
${PLATFORMSRC} \
$(BOARDSRC) \
${CHIBIOS}/os/various/shell.c \
+ ${CHIBIOS}/os/various/chprintf.c \
main.c
# List ASM source files here
diff --git a/demos/Win32-MinGW/main.c b/demos/Win32-MinGW/main.c
index 8540afed5..a735dfa0c 100644
--- a/demos/Win32-MinGW/main.c
+++ b/demos/Win32-MinGW/main.c
@@ -22,6 +22,7 @@
#include "hal.h"
#include "test.h"
#include "shell.h"
+#include "chprintf.h"
#define SHELL_WA_SIZE THD_WA_SIZE(4096)
#define CONSOLE_WA_SIZE THD_WA_SIZE(4096)
@@ -35,20 +36,16 @@ static Thread *shelltp2;
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size;
- char buf[52];
(void)argv;
if (argc > 0) {
- shellPrintLine(chp, "Usage: mem");
+ chprintf(chp, "Usage: mem\r\n");
return;
}
n = chHeapStatus(NULL, &size);
- sprintf(buf, "core free memory : %i bytes", chCoreStatus());
- shellPrintLine(chp, buf);
- sprintf(buf, "heap fragments : %i", n);
- shellPrintLine(chp, buf);
- sprintf(buf, "heap free total : %i bytes", size);
- shellPrintLine(chp, buf);
+ chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
+ chprintf(chp, "heap fragments : %u\r\n", n);
+ chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
@@ -63,25 +60,26 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
"WTEXIT",
"WTOREVT",
"WTANDEVT",
+ "SNDMSGQ",
"SNDMSG",
"WTMSG",
+ "WTQUEUE",
"FINAL"
};
Thread *tp;
- char buf[60];
(void)argv;
if (argc > 0) {
- shellPrintLine(chp, "Usage: threads");
+ chprintf(chp, "Usage: threads\r\n");
return;
}
- shellPrintLine(chp, " addr stack prio refs state time");
+ chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread();
do {
- sprintf(buf, "%8p %8p %4i %4i %9s %i",
- tp, tp->p_ctx.esp, tp->p_prio, tp->p_refs - 1,
- states[tp->p_state], tp->p_time);
- shellPrintLine(chp, buf);
+ chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
+ (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
+ (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
+ states[tp->p_state], (uint32_t)tp->p_time);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
@@ -91,13 +89,13 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
- shellPrintLine(chp, "Usage: test");
+ chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp);
if (tp == NULL) {
- shellPrintLine(chp, "out of memory");
+ chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);