Updated demos using the shell.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3094 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2011-06-28 06:54:35 +00:00
parent ddc9ded3f0
commit 7bdd564b9d
11 changed files with 109 additions and 138 deletions

View File

@ -62,7 +62,7 @@ CSRC = $(PORTSRC) \
$(FATFSSRC) \ $(FATFSSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(CHIBIOS)/os/various/shell.c \ $(CHIBIOS)/os/various/shell.c \
$(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/chprintf.c \
main.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global

View File

@ -25,6 +25,7 @@
#include "hal.h" #include "hal.h"
#include "test.h" #include "test.h"
#include "shell.h" #include "shell.h"
#include "chprintf.h"
#include "evtimer.h" #include "evtimer.h"
#include "ff.h" #include "ff.h"
@ -73,8 +74,7 @@ static bool_t mmc_is_protected(void) {
/* Generic large buffer.*/ /* Generic large buffer.*/
uint8_t fbuff[1024]; uint8_t fbuff[1024];
static FRESULT scan_files(char *path) static FRESULT scan_files(BaseChannel *chp, char *path) {
{
FRESULT res; FRESULT res;
FILINFO fno; FILINFO fno;
DIR dir; DIR dir;
@ -92,14 +92,15 @@ static FRESULT scan_files(char *path)
continue; continue;
fn = fno.fname; fn = fno.fname;
if (fno.fattrib & AM_DIR) { if (fno.fattrib & AM_DIR) {
siprintf(&path[i], "/%s", fn); path[i++] = '/';
res = scan_files(path); strcpy(&path[i], fn);
res = scan_files(chp, path);
if (res != FR_OK) if (res != FR_OK)
break; break;
path[i] = 0; path[i] = 0;
} }
else { else {
iprintf("%s/%s\r\n", path, fn); chprintf(chp, "%s/%s\r\n", path, fn);
} }
} }
} }
@ -115,20 +116,16 @@ static FRESULT scan_files(char *path)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size; size_t n, size;
char buf[52];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: mem"); chprintf(chp, "Usage: mem\r\n");
return; return;
} }
n = chHeapStatus(NULL, &size); n = chHeapStatus(NULL, &size);
siprintf(buf, "core free memory : %lu bytes", chCoreStatus()); chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
shellPrintLine(chp, buf); chprintf(chp, "heap fragments : %u\r\n", n);
siprintf(buf, "heap fragments : %lu", n); chprintf(chp, "heap free total : %u bytes\r\n", size);
shellPrintLine(chp, buf);
siprintf(buf, "heap free total : %lu bytes", size);
shellPrintLine(chp, buf);
} }
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
@ -149,21 +146,19 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
"FINAL" "FINAL"
}; };
Thread *tp; Thread *tp;
char buf[60];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: threads"); chprintf(chp, "Usage: threads\r\n");
return; return;
} }
shellPrintLine(chp, " addr stack prio refs state time"); chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
siprintf(buf, "%8lx %8lx %4u %4i %9s %u", chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13, (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(unsigned int)tp->p_prio, tp->p_refs - 1, (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], (unsigned int)tp->p_time); states[tp->p_state], (uint32_t)tp->p_time);
shellPrintLine(chp, buf);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
} while (tp != NULL); } while (tp != NULL);
} }
@ -173,13 +168,13 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: test"); chprintf(chp, "Usage: test\r\n");
return; return;
} }
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp); TestThread, chp);
if (tp == NULL) { if (tp == NULL) {
shellPrintLine(chp, "out of memory"); chprintf(chp, "out of memory\r\n");
return; return;
} }
chThdWait(tp); chThdWait(tp);
@ -192,25 +187,24 @@ static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: tree"); chprintf(chp, "Usage: tree\r\n");
return; return;
} }
if (!fs_ready) { if (!fs_ready) {
shellPrintLine(chp, "File System not mounted"); chprintf(chp, "File System not mounted\r\n");
return; return;
} }
err = f_getfree("/", &clusters, &fsp); err = f_getfree("/", &clusters, &fsp);
if (err != FR_OK) { if (err != FR_OK) {
shellPrintLine(chp, "FS: f_getfree() failed"); chprintf(chp, "FS: f_getfree() failed\r\n");
return; return;
} }
siprintf((void *)fbuff, chprintf(chp,
"FS: %lu free clusters, %lu sectors per cluster, %lu bytes free", "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
clusters, (uint32_t)MMC_FS.csize, clusters, (uint32_t)MMC_FS.csize,
clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE); clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE);
shellPrintLine(chp, (void *)fbuff);
fbuff[0] = 0; fbuff[0] = 0;
scan_files((char *)fbuff); scan_files(chp, (char *)fbuff);
} }
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
@ -340,8 +334,8 @@ int main(void) {
* Normal main() thread activity, in this demo it does nothing except * Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and listen for events. * sleeping in a loop and listen for events.
*/ */
chEvtRegister(&MMCD1.mmc_inserted_event, &el0, 0); chEvtRegister(&MMCD1.inserted_event, &el0, 0);
chEvtRegister(&MMCD1.mmc_removed_event, &el1, 1); chEvtRegister(&MMCD1.removed_event, &el1, 1);
while (TRUE) { while (TRUE) {
if (!shelltp) if (!shelltp)
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);

View File

@ -62,7 +62,7 @@ CSRC = $(PORTSRC) \
$(FATFSSRC) \ $(FATFSSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(CHIBIOS)/os/various/shell.c \ $(CHIBIOS)/os/various/shell.c \
$(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/chprintf.c \
main.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global

View File

@ -25,6 +25,7 @@
#include "hal.h" #include "hal.h"
#include "test.h" #include "test.h"
#include "shell.h" #include "shell.h"
#include "chprintf.h"
#include "evtimer.h" #include "evtimer.h"
#include "ff.h" #include "ff.h"
@ -73,8 +74,7 @@ static bool_t mmc_is_protected(void) {
/* Generic large buffer.*/ /* Generic large buffer.*/
uint8_t fbuff[1024]; uint8_t fbuff[1024];
static FRESULT scan_files(char *path) static FRESULT scan_files(BaseChannel *chp, char *path) {
{
FRESULT res; FRESULT res;
FILINFO fno; FILINFO fno;
DIR dir; DIR dir;
@ -92,14 +92,15 @@ static FRESULT scan_files(char *path)
continue; continue;
fn = fno.fname; fn = fno.fname;
if (fno.fattrib & AM_DIR) { if (fno.fattrib & AM_DIR) {
siprintf(&path[i], "/%s", fn); path[i++] = '/';
res = scan_files(path); strcpy(&path[i], fn);
res = scan_files(chp, path);
if (res != FR_OK) if (res != FR_OK)
break; break;
path[i] = 0; path[i] = 0;
} }
else { else {
iprintf("%s/%s\r\n", path, fn); chprintf(chp, "%s/%s\r\n", path, fn);
} }
} }
} }
@ -115,20 +116,16 @@ static FRESULT scan_files(char *path)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size; size_t n, size;
char buf[52];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: mem"); chprintf(chp, "Usage: mem\r\n");
return; return;
} }
n = chHeapStatus(NULL, &size); n = chHeapStatus(NULL, &size);
siprintf(buf, "core free memory : %lu bytes", chCoreStatus()); chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
shellPrintLine(chp, buf); chprintf(chp, "heap fragments : %u\r\n", n);
siprintf(buf, "heap fragments : %lu", n); chprintf(chp, "heap free total : %u bytes\r\n", size);
shellPrintLine(chp, buf);
siprintf(buf, "heap free total : %lu bytes", size);
shellPrintLine(chp, buf);
} }
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
@ -149,21 +146,19 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
"FINAL" "FINAL"
}; };
Thread *tp; Thread *tp;
char buf[60];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: threads"); chprintf(chp, "Usage: threads\r\n");
return; return;
} }
shellPrintLine(chp, " addr stack prio refs state time"); chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
siprintf(buf, "%8lx %8lx %4u %4i %9s %u", chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13, (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(unsigned int)tp->p_prio, tp->p_refs - 1, (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], (unsigned int)tp->p_time); states[tp->p_state], (uint32_t)tp->p_time);
shellPrintLine(chp, buf);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
} while (tp != NULL); } while (tp != NULL);
} }
@ -173,13 +168,13 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: test"); chprintf(chp, "Usage: test\r\n");
return; return;
} }
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp); TestThread, chp);
if (tp == NULL) { if (tp == NULL) {
shellPrintLine(chp, "out of memory"); chprintf(chp, "out of memory\r\n");
return; return;
} }
chThdWait(tp); chThdWait(tp);
@ -192,25 +187,24 @@ static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: tree"); chprintf(chp, "Usage: tree\r\n");
return; return;
} }
if (!fs_ready) { if (!fs_ready) {
shellPrintLine(chp, "File System not mounted"); chprintf(chp, "File System not mounted\r\n");
return; return;
} }
err = f_getfree("/", &clusters, &fsp); err = f_getfree("/", &clusters, &fsp);
if (err != FR_OK) { if (err != FR_OK) {
shellPrintLine(chp, "FS: f_getfree() failed"); chprintf(chp, "FS: f_getfree() failed\r\n");
return; return;
} }
siprintf((void *)fbuff, chprintf(chp,
"FS: %lu free clusters, %lu sectors per cluster, %lu bytes free", "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
clusters, (uint32_t)MMC_FS.csize, clusters, (uint32_t)MMC_FS.csize,
clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE); clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE);
shellPrintLine(chp, (void *)fbuff);
fbuff[0] = 0; fbuff[0] = 0;
scan_files((char *)fbuff); scan_files(chp, (char *)fbuff);
} }
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
@ -322,8 +316,8 @@ int main(void) {
* Normal main() thread activity, in this demo it does nothing except * Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and listen for events. * sleeping in a loop and listen for events.
*/ */
chEvtRegister(&MMCD1.mmc_inserted_event, &el0, 0); chEvtRegister(&MMCD1.inserted_event, &el0, 0);
chEvtRegister(&MMCD1.mmc_removed_event, &el1, 1); chEvtRegister(&MMCD1.removed_event, &el1, 1);
while (TRUE) { while (TRUE) {
if (!shelltp) if (!shelltp)
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);

View File

@ -62,8 +62,7 @@ static bool_t mmc_is_protected(void) {return !palReadPad(IOPORT3, GPIOC_MMCWP);}
/* Generic large buffer.*/ /* Generic large buffer.*/
uint8_t fbuff[1024]; uint8_t fbuff[1024];
static FRESULT scan_files(BaseChannel *chp, char *path) static FRESULT scan_files(BaseChannel *chp, char *path) {
{
FRESULT res; FRESULT res;
FILINFO fno; FILINFO fno;
DIR dir; DIR dir;

View File

@ -77,6 +77,7 @@ CSRC = $(PORTSRC) \
$(CHIBIOS)/os/various/evtimer.c \ $(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/syscalls.c \
$(CHIBIOS)/os/various/shell.c \ $(CHIBIOS)/os/various/shell.c \
$(CHIBIOS)/os/various/chprintf.c \
main.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global

View File

@ -26,6 +26,7 @@
#include "test.h" #include "test.h"
#include "shell.h" #include "shell.h"
#include "evtimer.h" #include "evtimer.h"
#include "chprintf.h"
#include "ff.h" #include "ff.h"
@ -138,8 +139,7 @@ static bool_t fs_ready = FALSE;
/* Generic large buffer.*/ /* Generic large buffer.*/
uint8_t fbuff[1024]; uint8_t fbuff[1024];
static FRESULT scan_files(char *path) static FRESULT scan_files(BaseChannel *chp, char *path) {
{
FRESULT res; FRESULT res;
FILINFO fno; FILINFO fno;
DIR dir; DIR dir;
@ -157,21 +157,21 @@ static FRESULT scan_files(char *path)
continue; continue;
fn = fno.fname; fn = fno.fname;
if (fno.fattrib & AM_DIR) { if (fno.fattrib & AM_DIR) {
siprintf(&path[i], "/%s", fn); path[i++] = '/';
res = scan_files(path); strcpy(&path[i], fn);
res = scan_files(chp, path);
if (res != FR_OK) if (res != FR_OK)
break; break;
path[i] = 0; path[i] = 0;
} }
else { else {
iprintf("%s/%s\r\n", path, fn); chprintf(chp, "%s/%s\r\n", path, fn);
} }
} }
} }
return res; return res;
} }
/*===========================================================================*/ /*===========================================================================*/
/* Command line related. */ /* Command line related. */
/*===========================================================================*/ /*===========================================================================*/
@ -181,20 +181,16 @@ static FRESULT scan_files(char *path)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size; size_t n, size;
char buf[52];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: mem"); chprintf(chp, "Usage: mem\r\n");
return; return;
} }
n = chHeapStatus(NULL, &size); n = chHeapStatus(NULL, &size);
siprintf(buf, "core free memory : %u bytes", chCoreStatus()); chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
shellPrintLine(chp, buf); chprintf(chp, "heap fragments : %u\r\n", n);
siprintf(buf, "heap fragments : %u", n); chprintf(chp, "heap free total : %u bytes\r\n", size);
shellPrintLine(chp, buf);
siprintf(buf, "heap free total : %u bytes", size);
shellPrintLine(chp, buf);
} }
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
@ -215,21 +211,19 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
"FINAL" "FINAL"
}; };
Thread *tp; Thread *tp;
char buf[60];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: threads"); chprintf(chp, "Usage: threads\r\n");
return; return;
} }
shellPrintLine(chp, " addr stack prio refs state time"); chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
siprintf(buf, "%8lx %8lx %4u %4i %9s %u", chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13, (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(unsigned int)tp->p_prio, tp->p_refs - 1, (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], (unsigned int)tp->p_time); states[tp->p_state], (uint32_t)tp->p_time);
shellPrintLine(chp, buf);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
} while (tp != NULL); } while (tp != NULL);
} }
@ -239,13 +233,13 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: test"); chprintf(chp, "Usage: test\r\n");
return; return;
} }
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp); TestThread, chp);
if (tp == NULL) { if (tp == NULL) {
shellPrintLine(chp, "out of memory"); chprintf(chp, "out of memory\r\n");
return; return;
} }
chThdWait(tp); chThdWait(tp);
@ -253,30 +247,29 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) { static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) {
FRESULT err; FRESULT err;
DWORD clusters; uint32_t clusters;
FATFS *fsp; FATFS *fsp;
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: tree"); chprintf(chp, "Usage: tree\r\n");
return; return;
} }
if (!fs_ready) { if (!fs_ready) {
shellPrintLine(chp, "File System not mounted"); chprintf(chp, "File System not mounted\r\n");
return; return;
} }
err = f_getfree("/", &clusters, &fsp); err = f_getfree("/", &clusters, &fsp);
if (err != FR_OK) { if (err != FR_OK) {
shellPrintLine(chp, "FS: f_getfree() failed"); chprintf(chp, "FS: f_getfree() failed\r\n");
return; return;
} }
siprintf((void *)fbuff, chprintf(chp,
"FS: %lu free clusters, %lu sectors per cluster, %lu bytes free", "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n",
clusters, (uint32_t)SDC_FS.csize, clusters, (uint32_t)SDC_FS.csize,
clusters * (uint32_t)SDC_FS.csize * (uint32_t)SDC_BLOCK_SIZE); clusters * (uint32_t)SDC_FS.csize * (uint32_t)SDC_BLOCK_SIZE);
shellPrintLine(chp, (void *)fbuff);
fbuff[0] = 0; fbuff[0] = 0;
scan_files((char *)fbuff); scan_files(chp, (char *)fbuff);
} }
static const ShellCommand commands[] = { static const ShellCommand commands[] = {

View File

@ -56,7 +56,7 @@ CSRC = $(PORTSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(CHIBIOS)/os/various/evtimer.c \ $(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/shell.c \ $(CHIBIOS)/os/various/shell.c \
$(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/chprintf.c \
main.c main.c
# C++ sources here. # C++ sources here.

View File

@ -24,26 +24,23 @@
#include "hal.h" #include "hal.h"
#include "test.h" #include "test.h"
#include "shell.h" #include "shell.h"
#include "chprintf.h"
#define SHELL_WA_SIZE THD_WA_SIZE(1024) #define SHELL_WA_SIZE THD_WA_SIZE(1024)
#define TEST_WA_SIZE THD_WA_SIZE(256) #define TEST_WA_SIZE THD_WA_SIZE(256)
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size; size_t n, size;
char buf[52];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: mem"); chprintf(chp, "Usage: mem\r\n");
return; return;
} }
n = chHeapStatus(NULL, &size); n = chHeapStatus(NULL, &size);
siprintf(buf, "core free memory : %i bytes", chCoreStatus()); chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
shellPrintLine(chp, buf); chprintf(chp, "heap fragments : %u\r\n", n);
siprintf(buf, "heap fragments : %i", n); chprintf(chp, "heap free total : %u bytes\r\n", size);
shellPrintLine(chp, buf);
siprintf(buf, "heap free total : %i bytes", size);
shellPrintLine(chp, buf);
} }
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
@ -64,21 +61,19 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
"FINAL" "FINAL"
}; };
Thread *tp; Thread *tp;
char buf[60];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: threads"); chprintf(chp, "Usage: threads\r\n");
return; return;
} }
shellPrintLine(chp, " addr stack prio refs state time"); chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
siprintf(buf, "%8lx %8lx %4u %4i %9s %u", chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp, (uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(unsigned int)tp->p_prio, tp->p_refs - 1, (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], (unsigned int)tp->p_time); states[tp->p_state], (uint32_t)tp->p_time);
shellPrintLine(chp, buf);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
} while (tp != NULL); } while (tp != NULL);
} }
@ -88,13 +83,13 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: test"); chprintf(chp, "Usage: test\r\n");
return; return;
} }
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp); TestThread, chp);
if (tp == NULL) { if (tp == NULL) {
shellPrintLine(chp, "out of memory"); chprintf(chp, "out of memory\r\n");
return; return;
} }
chThdWait(tp); chThdWait(tp);

View File

@ -73,7 +73,7 @@ CSRC = $(PORTSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(CHIBIOS)/os/various/shell.c \ $(CHIBIOS)/os/various/shell.c \
$(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/chprintf.c \
main.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global

View File

@ -27,6 +27,7 @@
#include "usb_cdc.h" #include "usb_cdc.h"
#include "shell.h" #include "shell.h"
#include "chprintf.h"
/*===========================================================================*/ /*===========================================================================*/
/* USB related stuff. */ /* USB related stuff. */
@ -318,20 +319,16 @@ static const SerialUSBConfig serusbcfg = {
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
size_t n, size; size_t n, size;
char buf[52];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: mem"); chprintf(chp, "Usage: mem\r\n");
return; return;
} }
n = chHeapStatus(NULL, &size); n = chHeapStatus(NULL, &size);
siprintf(buf, "core free memory : %u bytes", chCoreStatus()); chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
shellPrintLine(chp, buf); chprintf(chp, "heap fragments : %u\r\n", n);
siprintf(buf, "heap fragments : %u", n); chprintf(chp, "heap free total : %u bytes\r\n", size);
shellPrintLine(chp, buf);
siprintf(buf, "heap free total : %u bytes", size);
shellPrintLine(chp, buf);
} }
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
@ -352,21 +349,19 @@ static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
"FINAL" "FINAL"
}; };
Thread *tp; Thread *tp;
char buf[60];
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: threads"); chprintf(chp, "Usage: threads\r\n");
return; return;
} }
shellPrintLine(chp, " addr stack prio refs state time"); chprintf(chp, " addr stack prio refs state time\r\n");
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
siprintf(buf, "%8lx %8lx %4u %4i %9s %u", chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13, (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
(unsigned int)tp->p_prio, tp->p_refs - 1, (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state], (unsigned int)tp->p_time); states[tp->p_state], (uint32_t)tp->p_time);
shellPrintLine(chp, buf);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
} while (tp != NULL); } while (tp != NULL);
} }
@ -376,13 +371,13 @@ static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
shellPrintLine(chp, "Usage: test"); chprintf(chp, "Usage: test\r\n");
return; return;
} }
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(),
TestThread, chp); TestThread, chp);
if (tp == NULL) { if (tp == NULL) {
shellPrintLine(chp, "out of memory"); chprintf(chp, "out of memory\r\n");
return; return;
} }
chThdWait(tp); chThdWait(tp);