git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8918 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
Giovanni Di Sirio 2016-02-21 08:26:57 +00:00
parent 951efe320c
commit adcc516668
34 changed files with 293 additions and 862 deletions

View File

@ -28,6 +28,8 @@
#ifndef _CHCONF_H_ #ifndef _CHCONF_H_
#define _CHCONF_H_ #define _CHCONF_H_
#define _CHIBIOS_RT_CONF_
/*===========================================================================*/ /*===========================================================================*/
/** /**
* @name System timers settings * @name System timers settings
@ -360,9 +362,16 @@
* @details If enabled then the context switch circular trace buffer is * @details If enabled then the context switch circular trace buffer is
* activated. * activated.
* *
* @note The default is @p FALSE. * @note The default is @p CH_DBG_TRACE_MASK_NONE.
*/ */
#define CH_DBG_ENABLE_TRACE FALSE #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_NONE
/**
* @brief Trace buffer entries.
* @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
* different from @p CH_DBG_TRACE_MASK_NONE.
*/
#define CH_DBG_TRACE_BUFFER_SIZE 128
/** /**
* @brief Debug option, stack checks. * @brief Debug option, stack checks.
@ -427,10 +436,6 @@
/** /**
* @brief Threads finalization hook. * @brief Threads finalization hook.
* @details User finalization code added to the @p chThdExit() API. * @details User finalization code added to the @p chThdExit() API.
*
* @note It is inserted into lock zone.
* @note It is also invoked when the threads simply return in order to
* terminate.
*/ */
#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ #define CH_CFG_THREAD_EXIT_HOOK(tp) { \
/* Add threads finalization code here.*/ \ /* Add threads finalization code here.*/ \
@ -444,6 +449,20 @@
/* Context switch code here.*/ \ /* Context switch code here.*/ \
} }
/**
* @brief ISR enter hook.
*/
#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
/* IRQ prologue code here.*/ \
}
/**
* @brief ISR exit hook.
*/
#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
/* IRQ epilogue code here.*/ \
}
/** /**
* @brief Idle thread enter hook. * @brief Idle thread enter hook.
* @note This hook is invoked within a critical zone, no OS functions * @note This hook is invoked within a critical zone, no OS functions
@ -451,6 +470,7 @@
* @note This macro can be used to activate a power saving mode. * @note This macro can be used to activate a power saving mode.
*/ */
#define CH_CFG_IDLE_ENTER_HOOK() { \ #define CH_CFG_IDLE_ENTER_HOOK() { \
/* Idle-enter code here.*/ \
} }
/** /**
@ -460,6 +480,7 @@
* @note This macro can be used to deactivate a power saving mode. * @note This macro can be used to deactivate a power saving mode.
*/ */
#define CH_CFG_IDLE_LEAVE_HOOK() { \ #define CH_CFG_IDLE_LEAVE_HOOK() { \
/* Idle-leave code here.*/ \
} }
/** /**
@ -488,6 +509,15 @@
/* System halt code here.*/ \ /* System halt code here.*/ \
} }
/**
* @brief Trace hook.
* @details This hook is invoked each time a new record is written in the
* trace buffer.
*/
#define CH_CFG_TRACE_HOOK(tep) { \
/* Trace code here.*/ \
}
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -28,6 +28,8 @@
#ifndef _CHCONF_H_ #ifndef _CHCONF_H_
#define _CHCONF_H_ #define _CHCONF_H_
#define _CHIBIOS_RT_CONF_
/*===========================================================================*/ /*===========================================================================*/
/** /**
* @name System timers settings * @name System timers settings
@ -360,9 +362,16 @@
* @details If enabled then the context switch circular trace buffer is * @details If enabled then the context switch circular trace buffer is
* activated. * activated.
* *
* @note The default is @p FALSE. * @note The default is @p CH_DBG_TRACE_MASK_NONE.
*/ */
#define CH_DBG_ENABLE_TRACE FALSE #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_NONE
/**
* @brief Trace buffer entries.
* @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
* different from @p CH_DBG_TRACE_MASK_NONE.
*/
#define CH_DBG_TRACE_BUFFER_SIZE 128
/** /**
* @brief Debug option, stack checks. * @brief Debug option, stack checks.
@ -427,10 +436,6 @@
/** /**
* @brief Threads finalization hook. * @brief Threads finalization hook.
* @details User finalization code added to the @p chThdExit() API. * @details User finalization code added to the @p chThdExit() API.
*
* @note It is inserted into lock zone.
* @note It is also invoked when the threads simply return in order to
* terminate.
*/ */
#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ #define CH_CFG_THREAD_EXIT_HOOK(tp) { \
/* Add threads finalization code here.*/ \ /* Add threads finalization code here.*/ \
@ -444,6 +449,20 @@
/* Context switch code here.*/ \ /* Context switch code here.*/ \
} }
/**
* @brief ISR enter hook.
*/
#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
/* IRQ prologue code here.*/ \
}
/**
* @brief ISR exit hook.
*/
#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
/* IRQ epilogue code here.*/ \
}
/** /**
* @brief Idle thread enter hook. * @brief Idle thread enter hook.
* @note This hook is invoked within a critical zone, no OS functions * @note This hook is invoked within a critical zone, no OS functions
@ -451,6 +470,7 @@
* @note This macro can be used to activate a power saving mode. * @note This macro can be used to activate a power saving mode.
*/ */
#define CH_CFG_IDLE_ENTER_HOOK() { \ #define CH_CFG_IDLE_ENTER_HOOK() { \
/* Idle-enter code here.*/ \
} }
/** /**
@ -460,6 +480,7 @@
* @note This macro can be used to deactivate a power saving mode. * @note This macro can be used to deactivate a power saving mode.
*/ */
#define CH_CFG_IDLE_LEAVE_HOOK() { \ #define CH_CFG_IDLE_LEAVE_HOOK() { \
/* Idle-leave code here.*/ \
} }
/** /**
@ -488,6 +509,15 @@
/* System halt code here.*/ \ /* System halt code here.*/ \
} }
/**
* @brief Trace hook.
* @details This hook is invoked each time a new record is written in the
* trace buffer.
*/
#define CH_CFG_TRACE_HOOK(tep) { \
/* Trace code here.*/ \
}
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -28,6 +28,8 @@
#ifndef _CHCONF_H_ #ifndef _CHCONF_H_
#define _CHCONF_H_ #define _CHCONF_H_
#define _CHIBIOS_RT_CONF_
/*===========================================================================*/ /*===========================================================================*/
/** /**
* @name System timers settings * @name System timers settings
@ -360,9 +362,16 @@
* @details If enabled then the context switch circular trace buffer is * @details If enabled then the context switch circular trace buffer is
* activated. * activated.
* *
* @note The default is @p FALSE. * @note The default is @p CH_DBG_TRACE_MASK_NONE.
*/ */
#define CH_DBG_ENABLE_TRACE FALSE #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_NONE
/**
* @brief Trace buffer entries.
* @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
* different from @p CH_DBG_TRACE_MASK_NONE.
*/
#define CH_DBG_TRACE_BUFFER_SIZE 128
/** /**
* @brief Debug option, stack checks. * @brief Debug option, stack checks.
@ -427,10 +436,6 @@
/** /**
* @brief Threads finalization hook. * @brief Threads finalization hook.
* @details User finalization code added to the @p chThdExit() API. * @details User finalization code added to the @p chThdExit() API.
*
* @note It is inserted into lock zone.
* @note It is also invoked when the threads simply return in order to
* terminate.
*/ */
#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ #define CH_CFG_THREAD_EXIT_HOOK(tp) { \
/* Add threads finalization code here.*/ \ /* Add threads finalization code here.*/ \
@ -444,6 +449,20 @@
/* Context switch code here.*/ \ /* Context switch code here.*/ \
} }
/**
* @brief ISR enter hook.
*/
#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
/* IRQ prologue code here.*/ \
}
/**
* @brief ISR exit hook.
*/
#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
/* IRQ epilogue code here.*/ \
}
/** /**
* @brief Idle thread enter hook. * @brief Idle thread enter hook.
* @note This hook is invoked within a critical zone, no OS functions * @note This hook is invoked within a critical zone, no OS functions
@ -451,6 +470,7 @@
* @note This macro can be used to activate a power saving mode. * @note This macro can be used to activate a power saving mode.
*/ */
#define CH_CFG_IDLE_ENTER_HOOK() { \ #define CH_CFG_IDLE_ENTER_HOOK() { \
/* Idle-enter code here.*/ \
} }
/** /**
@ -460,6 +480,7 @@
* @note This macro can be used to deactivate a power saving mode. * @note This macro can be used to deactivate a power saving mode.
*/ */
#define CH_CFG_IDLE_LEAVE_HOOK() { \ #define CH_CFG_IDLE_LEAVE_HOOK() { \
/* Idle-leave code here.*/ \
} }
/** /**
@ -488,6 +509,15 @@
/* System halt code here.*/ \ /* System halt code here.*/ \
} }
/**
* @brief Trace hook.
* @details This hook is invoked each time a new record is written in the
* trace buffer.
*/
#define CH_CFG_TRACE_HOOK(tep) { \
/* Trace code here.*/ \
}
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -91,7 +91,7 @@ include $(CHIBIOS)/os/hal/ports/SPC5/SPC560Dxx/platform.mk
include $(CHIBIOS)/os/hal/osal/nil/osal.mk include $(CHIBIOS)/os/hal/osal/nil/osal.mk
# RTOS files (optional). # RTOS files (optional).
include $(CHIBIOS)/os/nil/nil.mk include $(CHIBIOS)/os/nil/nil.mk
include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/nil/test.mk include $(CHIBIOS)/test/nil/test.mk

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC560B60.ld LDSCRIPT= $(STARTUPLD)/SPC560B60.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -187,15 +132,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/startup/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC560D40.ld LDSCRIPT= $(STARTUPLD)/SPC560D40.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size, largest;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: mem\r\n");
return;
}
n = chHeapStatus(NULL, &size, &largest);
chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
chprintf(chp, "heap free largest: %u bytes\r\n", largest);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->ctx.sp,
(uint32_t)tp->prio, states[tp->state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -187,15 +132,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC560P50.ld LDSCRIPT= $(STARTUPLD)/SPC560P50.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -187,15 +132,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC563M64.ld LDSCRIPT= $(STARTUPLD)/SPC563M64.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -170,15 +115,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC564A80.ld LDSCRIPT= $(STARTUPLD)/SPC564A80.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -170,15 +115,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC56EC74.ld LDSCRIPT= $(STARTUPLD)/SPC56EC74.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -187,15 +132,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -94,6 +94,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk include $(CHIBIOS)/os/common/ports/e200/compilers/GCC/mk/port.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/SPC56EL60_LSM.ld LDSCRIPT= $(STARTUPLD)/SPC56EL60_LSM.ld
@ -107,9 +109,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(SHELLSRC) \
$(CHIBIOS)/os/various/shell.c \
main.c main.c
# C++ sources here. # C++ sources here.
@ -120,7 +121,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -21,63 +21,8 @@
#include "chprintf.h" #include "chprintf.h"
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.sp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
states[tp->p_state]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -187,15 +132,14 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity. * Normal main() thread activity, spawning shells.
*/ */
while (true) { while (true) {
if (!shelltp) thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); NORMALPRIO + 1, shellThread,
else if (chThdTerminatedX(shelltp)) { (void *)&shell_cfg1);
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp); /* Waiting termination. */
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdFreeToHeap(shelltp); /* Returning memory to heap. */
}
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }
return 0; return 0;

View File

@ -99,7 +99,7 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/common/startup/ARMCMx/cmsis_os/cmsis_os.mk include $(CHIBIOS)/os/common/ports/ARMCMx/cmsis_os/cmsis_os.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld

View File

@ -102,6 +102,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
ifeq ($(USE_MAPLEMINI_BOOTLOADER),1) ifeq ($(USE_MAPLEMINI_BOOTLOADER),1)
@ -120,9 +122,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/various/shell.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(SHELLSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
usbcfg.c main.c usbcfg.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
@ -154,7 +155,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -31,58 +31,6 @@
/*===========================================================================*/ /*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: threads\r\n");
return;
}
chprintf(chp, " addr stack prio refs state\r\n");
tp = chRegFirstThread();
do {
chprintf(chp, "%08lx %08lx %4lu %4lu %9s\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]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
@ -125,9 +73,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
} }
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{"write", cmd_write}, {"write", cmd_write},
{NULL, NULL} {NULL, NULL}
}; };
@ -162,7 +107,6 @@ static __attribute__((noreturn)) THD_FUNCTION(Thread1, arg) {
* Application entry point. * Application entry point.
*/ */
int __attribute__((noreturn)) main(void) { int __attribute__((noreturn)) main(void) {
thread_t *shelltp = NULL;
/* /*
* System initializations. * System initializations.
@ -201,15 +145,15 @@ int __attribute__((noreturn)) main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity, in this demo it does nothing except * Normal main() thread activity, spawning shells.
* sleeping in a loop and check the button state.
*/ */
while (true) { while (true) {
if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) if (SDU1.config->usbp->state == USB_ACTIVE) {
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
else if (chThdTerminatedX(shelltp)) { NORMALPRIO + 1, shellThread,
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ (void *)&shell_cfg1);
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
} }
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }

View File

@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk
include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk
@ -116,10 +118,8 @@ CSRC = $(STARTUPSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(FATFSSRC) \ $(FATFSSRC) \
$(CHIBIOS)/os/various/evtimer.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(SHELLSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
$(CHIBIOS)/os/various/shell.c \
usbcfg.c main.c usbcfg.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
@ -151,8 +151,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(FATFSINC) \ $(STREAMSINC) $(SHELLINC) $(FATFSINC)
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various
# #
# Project, sources and paths # Project, sources and paths

View File

@ -154,58 +154,6 @@ static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
/*===========================================================================*/ /*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\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]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
FRESULT err; FRESULT err;
@ -235,9 +183,6 @@ static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
} }
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{"tree", cmd_tree}, {"tree", cmd_tree},
{NULL, NULL} {NULL, NULL}
}; };
@ -251,6 +196,8 @@ static const ShellConfig shell_cfg1 = {
/* Main and generic code. */ /* Main and generic code. */
/*===========================================================================*/ /*===========================================================================*/
static thread_t *shelltp = NULL;
/* /*
* Card insertion event. * Card insertion event.
*/ */
@ -282,6 +229,18 @@ static void RemoveHandler(eventid_t id) {
fs_ready = FALSE; fs_ready = FALSE;
} }
/*
* Shell exit event.
*/
static void ShellHandler(eventid_t id) {
(void)id;
if (chThdTerminatedX(shelltp)) {
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
shelltp = NULL;
}
}
/* /*
* Green LED blinker thread, times are in milliseconds. * Green LED blinker thread, times are in milliseconds.
*/ */
@ -300,12 +259,12 @@ static THD_FUNCTION(Thread1, arg) {
* Application entry point. * Application entry point.
*/ */
int main(void) { int main(void) {
static thread_t *shelltp = NULL;
static const evhandler_t evhndl[] = { static const evhandler_t evhndl[] = {
InsertHandler, InsertHandler,
RemoveHandler RemoveHandler,
ShellHandler
}; };
event_listener_t el0, el1; event_listener_t el0, el1, el2;
/* /*
* System initializations. * System initializations.
@ -349,17 +308,17 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity, in this demo it does nothing except * Normal main() thread activity, handling SD card events and shell
* sleeping in a loop and listen for events. * start/exit.
*/ */
chEvtRegister(&inserted_event, &el0, 0); chEvtRegister(&inserted_event, &el0, 0);
chEvtRegister(&removed_event, &el1, 1); chEvtRegister(&removed_event, &el1, 1);
chEvtRegister(&shell_terminated, &el2, 2);
while (true) { while (true) {
if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) {
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
else if (chThdTerminatedX(shelltp)) { NORMALPRIO + 1, shellThread,
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ (void *)&shell_cfg1);
shelltp = NULL; /* Triggers spawning of a new shell. */
} }
chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500))); chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500)));
} }

View File

@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F103xE.ld LDSCRIPT= $(STARTUPLD)/STM32F103xE.ld
@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/various/shell.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(SHELLSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
usbcfg.c main.c usbcfg.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
@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -31,58 +31,6 @@
/*===========================================================================*/ /*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: threads\r\n");
return;
}
chprintf(chp, " addr stack prio refs state\r\n");
tp = chRegFirstThread();
do {
chprintf(chp, "%08lx %08lx %4lu %4lu %9s\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]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ /* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
@ -125,9 +73,6 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
} }
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{"write", cmd_write}, {"write", cmd_write},
{NULL, NULL} {NULL, NULL}
}; };
@ -162,7 +107,6 @@ static THD_FUNCTION(Thread1, arg) {
* Application entry point. * Application entry point.
*/ */
int main(void) { int main(void) {
thread_t *shelltp = NULL;
/* /*
* System initializations. * System initializations.
@ -201,15 +145,15 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Normal main() thread activity, in this demo it does nothing except * Normal main() thread activity, spawning shells.
* sleeping in a loop and check the button state.
*/ */
while (true) { while (true) {
if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) if (SDU1.config->usbp->state == USB_ACTIVE) {
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
else if (chThdTerminatedX(shelltp)) { NORMALPRIO + 1, shellThread,
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ (void *)&shell_cfg1);
shelltp = NULL; /* Triggers spawning of a new shell. */ chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
} }
chThdSleepMilliseconds(1000); chThdSleepMilliseconds(1000);
} }

View File

@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
@ -113,10 +115,9 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(STREAMSSRC) \
$(SHELLSRC) \
$(CHIBIOS)/os/various/devices_lib/accel/lis302dl.c \ $(CHIBIOS)/os/various/devices_lib/accel/lis302dl.c \
$(CHIBIOS)/os/various/shell.c \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
usbcfg.c main.c usbcfg.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
@ -148,8 +149,8 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/various/devices_lib/accel \ $(STREAMSINC) $(SHELLINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(CHIBIOS)/os/various/devices_lib/accel
# #
# Project, sources and paths # Project, sources and paths

View File

@ -29,63 +29,8 @@
/*===========================================================================*/ /*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: threads\r\n");
return;
}
chprintf(chp, " addr stack prio refs state\r\n");
tp = chRegFirstThread();
do {
chprintf(chp, "%08lx %08lx %4lu %4lu %9s\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]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -220,7 +165,6 @@ static THD_FUNCTION(Thread1, arg) {
* Application entry point. * Application entry point.
*/ */
int main(void) { int main(void) {
thread_t *shelltp = NULL;
/* /*
* System initializations. * System initializations.
@ -300,24 +244,16 @@ int main(void) {
NORMALPRIO + 10, Thread1, NULL); NORMALPRIO + 10, Thread1, NULL);
/* /*
* Normal main() thread activity, in this demo it just performs * Normal main() thread activity, spawning shells.
* a shell respawn upon its termination.
*/ */
while (true) { while (true) {
if (!shelltp) { if (SDU1.config->usbp->state == USB_ACTIVE) {
if (SDU1.config->usbp->state == USB_ACTIVE) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
/* Spawns a new shell.*/ NORMALPRIO + 1, shellThread,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); (void *)&shell_cfg1);
} chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
} }
else { chThdSleepMilliseconds(1000);
/* If the previous shell exited.*/
if (chThdTerminatedX(shelltp)) {
/* Recovers memory of the previous shell.*/
chThdRelease(shelltp);
shelltp = NULL;
}
}
chThdSleepMilliseconds(500);
} }
} }

View File

@ -99,6 +99,8 @@ include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F429xI.ld LDSCRIPT= $(STARTUPLD)/STM32F429xI.ld
@ -113,9 +115,8 @@ CSRC = $(STARTUPSRC) \
$(PLATFORMSRC) \ $(PLATFORMSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/various/shell.c \ $(STREAMSSRC) \
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \ $(SHELLSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
usbcfg.c main.c usbcfg.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
@ -147,7 +148,7 @@ ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various $(STREAMSINC) $(SHELLINC)
# #
# Project, sources and paths # Project, sources and paths

View File

@ -60,63 +60,8 @@ static THD_FUNCTION(Thread2, arg) {
/*===========================================================================*/ /*===========================================================================*/
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048) #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *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", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size);
}
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
static const char *states[] = {CH_STATE_NAMES};
thread_t *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, "%08lx %08lx %4lu %4lu %9s\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]);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
thread_t *tp;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: test\r\n");
return;
}
tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
TestThread, chp);
if (tp == NULL) {
chprintf(chp, "out of memory\r\n");
return;
}
chThdWait(tp);
}
static const ShellCommand commands[] = { static const ShellCommand commands[] = {
{"mem", cmd_mem},
{"threads", cmd_threads},
{"test", cmd_test},
{NULL, NULL} {NULL, NULL}
}; };
@ -133,7 +78,6 @@ static const ShellConfig shell_cfg1 = {
* Application entry point. * Application entry point.
*/ */
int main(void) { int main(void) {
thread_t *shelltp = NULL;
/* /*
* System initializations. * System initializations.
@ -175,24 +119,16 @@ int main(void) {
NORMALPRIO + 10, Thread2, NULL); NORMALPRIO + 10, Thread2, NULL);
/* /*
* Normal main() thread activity, in this demo it just performs * Normal main() thread activity, spawning shells.
* a shell respawn upon its termination.
*/ */
while (true) { while (true) {
if (!shelltp) { if (SDU1.config->usbp->state == USB_ACTIVE) {
if (SDU1.config->usbp->state == USB_ACTIVE) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
/* Spawns a new shell.*/ NORMALPRIO + 1, shellThread,
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); (void *)&shell_cfg1);
} chThdWait(shelltp); /* Waiting termination. */
chThdFreeToHeap(shelltp); /* Returning memory to heap. */
} }
else { chThdSleepMilliseconds(1000);
/* If the previous shell exited.*/
if (chThdTerminatedX(shelltp)) {
/* Recovers memory of the previous shell.*/
chThdRelease(shelltp);
shelltp = NULL;
}
}
chThdSleepMilliseconds(500);
} }
} }

View File

@ -140,7 +140,7 @@
* *
* @note The default is @p TRUE. * @note The default is @p TRUE.
*/ */
#define CH_CFG_USE_TM TRUE #define CH_CFG_USE_TM FALSE
/** /**
* @brief Threads registry APIs. * @brief Threads registry APIs.

View File

@ -88,10 +88,10 @@ osStatus osKernelInitialize(void) {
chSysInit(); chSysInit();
chThdSetPriority(HIGHPRIO); chThdSetPriority(HIGHPRIO);
chPoolObjectInit(&sempool, sizeof(semaphore_t), chCoreAlloc); chPoolObjectInit(&sempool, sizeof(semaphore_t), chCoreAllocAligned);
chPoolLoadArray(&sempool, semaphores, CMSIS_CFG_NUM_SEMAPHORES); chPoolLoadArray(&sempool, semaphores, CMSIS_CFG_NUM_SEMAPHORES);
chPoolObjectInit(&timpool, sizeof(virtual_timer_t), chCoreAlloc); chPoolObjectInit(&timpool, sizeof(virtual_timer_t), chCoreAllocAligned);
chPoolLoadArray(&timpool, timers, CMSIS_CFG_NUM_TIMERS); chPoolLoadArray(&timpool, timers, CMSIS_CFG_NUM_TIMERS);
return osOK; return osOK;
@ -136,7 +136,7 @@ osStatus osThreadTerminate(osThreadId thread_id) {
implemented using the registry.*/ implemented using the registry.*/
chThdExit(0); chThdExit(0);
} }
chThdTerminate(thread_id); chEvtSignal((thread_t *)thread_id, CH_EVENT_TERMINATE);
chThdWait((thread_t *)thread_id); chThdWait((thread_t *)thread_id);
return osOK; return osOK;
@ -154,17 +154,17 @@ osStatus osThreadSetPriority(osThreadId thread_id, osPriority newprio) {
/* Changing priority.*/ /* Changing priority.*/
#if CH_CFG_USE_MUTEXES #if CH_CFG_USE_MUTEXES
oldprio = (osPriority)tp->p_realprio; oldprio = (osPriority)tp->realprio;
if ((tp->p_prio == tp->p_realprio) || ((tprio_t)newprio > tp->p_prio)) if ((tp->prio == tp->realprio) || ((tprio_t)newprio > tp->prio))
tp->p_prio = (tprio_t)newprio; tp->prio = (tprio_t)newprio;
tp->p_realprio = (tprio_t)newprio; tp->realprio = (tprio_t)newprio;
#else #else
oldprio = tp->p_prio; oldprio = tp->prio;
tp->p_prio = (tprio_t)newprio; tp->prio = (tprio_t)newprio;
#endif #endif
/* The following states need priority queues reordering.*/ /* The following states need priority queues reordering.*/
switch (tp->p_state) { switch (tp->state) {
#if CH_CFG_USE_MUTEXES | \ #if CH_CFG_USE_MUTEXES | \
CH_CFG_USE_CONDVARS | \ CH_CFG_USE_CONDVARS | \
(CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \ (CH_CFG_USE_SEMAPHORES && CH_CFG_USE_SEMAPHORES_PRIORITY) | \
@ -183,13 +183,13 @@ osStatus osThreadSetPriority(osThreadId thread_id, osPriority newprio) {
#endif #endif
/* Re-enqueues tp with its new priority on the queue.*/ /* Re-enqueues tp with its new priority on the queue.*/
queue_prio_insert(queue_dequeue(tp), queue_prio_insert(queue_dequeue(tp),
(threads_queue_t *)tp->p_u.wtobjp); (threads_queue_t *)tp->u.wtobjp);
break; break;
#endif #endif
case CH_STATE_READY: case CH_STATE_READY:
#if CH_DBG_ENABLE_ASSERTS #if CH_DBG_ENABLE_ASSERTS
/* Prevents an assertion in chSchReadyI().*/ /* Prevents an assertion in chSchReadyI().*/
tp->p_state = CH_STATE_CURRENT; tp->state = CH_STATE_CURRENT;
#endif #endif
/* Re-enqueues tp with its new priority on the ready list.*/ /* Re-enqueues tp with its new priority on the ready list.*/
chSchReadyI(queue_dequeue(tp)); chSchReadyI(queue_dequeue(tp));
@ -261,7 +261,7 @@ int32_t osSignalSet(osThreadId thread_id, int32_t signals) {
int32_t oldsignals; int32_t oldsignals;
syssts_t sts = chSysGetStatusAndLockX(); syssts_t sts = chSysGetStatusAndLockX();
oldsignals = (int32_t)thread_id->p_epending; oldsignals = (int32_t)thread_id->epending;
chEvtSignalI((thread_t *)thread_id, (eventmask_t)signals); chEvtSignalI((thread_t *)thread_id, (eventmask_t)signals);
chSysRestoreStatusX(sts); chSysRestoreStatusX(sts);
@ -276,8 +276,8 @@ int32_t osSignalClear(osThreadId thread_id, int32_t signals) {
chSysLock(); chSysLock();
m = thread_id->p_epending & (eventmask_t)signals; m = thread_id->epending & (eventmask_t)signals;
thread_id->p_epending &= ~(eventmask_t)signals; thread_id->epending &= ~(eventmask_t)signals;
chSysUnlock(); chSysUnlock();
@ -453,7 +453,7 @@ void *osPoolCAlloc(osPoolId pool_id) {
void *object; void *object;
object = chPoolAllocI((memory_pool_t *)pool_id); object = chPoolAllocI((memory_pool_t *)pool_id);
memset(object, 0, pool_id->mp_object_size); memset(object, 0, pool_id->object_size);
return object; return object;
} }

View File

@ -502,7 +502,7 @@ static inline osStatus osThreadYield(void) {
*/ */
static inline osPriority osThreadGetPriority(osThreadId thread_id) { static inline osPriority osThreadGetPriority(osThreadId thread_id) {
return thread_id->p_prio; return thread_id->prio;
} }
/** /**

View File

@ -1,4 +1,4 @@
# List of the ChibiOS/RT CMSIS RTOS wrapper. # List of the ChibiOS/RT CMSIS RTOS wrapper.
CMSISRTOSSRC = ${CHIBIOS}/os/rt/ports/ARMCMx/cmsis_os/cmsis_os.c CMSISRTOSSRC = ${CHIBIOS}/os/common/ports/ARMCMx/cmsis_os/cmsis_os.c
CMSISRTOSINC = ${CHIBIOS}/os/rt/ports/ARMCMx/cmsis_os CMSISRTOSINC = ${CHIBIOS}/os/common/ports/ARMCMx/cmsis_os

View File

@ -78,13 +78,15 @@ namespace chibios_rt {
chSysHalt("invoked unimplemented method stop()"); chSysHalt("invoked unimplemented method stop()");
} }
#if CH_CFG_USE_EVENTS
void ThreadReference::requestTerminate(void) { void ThreadReference::requestTerminate(void) {
chDbgAssert(thread_ref != NULL, chDbgAssert(thread_ref != NULL,
"not referenced"); "not referenced");
chThdTerminate(thread_ref); chEvtSignal(thread_ref, CH_EVENT_TERMINATE);
} }
#endif
#if CH_CFG_USE_WAITEXIT #if CH_CFG_USE_WAITEXIT
msg_t ThreadReference::wait(void) { msg_t ThreadReference::wait(void) {
@ -196,10 +198,12 @@ namespace chibios_rt {
chThdExitS(msg); chThdExitS(msg);
} }
#if CH_CFG_USE_EVENTS
bool BaseThread::shouldTerminate(void) { bool BaseThread::shouldTerminate(void) {
return chThdShouldTerminateX(); return (chEvtGetEventsX() & CH_EVENT_TERMINATE) != 0;
} }
#endif
void BaseThread::sleep(systime_t interval){ void BaseThread::sleep(systime_t interval){