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

This commit is contained in:
Giovanni Di Sirio 2016-02-19 16:32:09 +00:00
parent 6865ddcce5
commit 4f3674f5f2
10 changed files with 48 additions and 66 deletions

View File

@ -714,9 +714,6 @@ void usb_lld_init(void) {
{ {
void *wsp = USBD2.wa_pump; void *wsp = USBD2.wa_pump;
_thread_memfill((uint8_t *)wsp, _thread_memfill((uint8_t *)wsp,
(uint8_t *)wsp + sizeof(thread_t),
CH_DBG_THREAD_FILL_VALUE);
_thread_memfill((uint8_t *)wsp + sizeof(thread_t),
(uint8_t *)wsp + sizeof (USBD2.wa_pump), (uint8_t *)wsp + sizeof (USBD2.wa_pump),
CH_DBG_STACK_FILL_VALUE); CH_DBG_STACK_FILL_VALUE);
} }
@ -861,10 +858,16 @@ void usb_lld_start(USBDriver *usbp) {
#if defined(_CHIBIOS_RT_) #if defined(_CHIBIOS_RT_)
/* Creates the data pump thread. Note, it is created only once.*/ /* Creates the data pump thread. Note, it is created only once.*/
if (usbp->tr == NULL) { if (usbp->tr == NULL) {
usbp->tr = chThdCreateI(usbp->wa_pump, sizeof usbp->wa_pump, thread_descriptor_t usbpump_descriptor = {
"usb_pump",
THD_WORKING_AREA_BASE(usbp->wa_pump),
THD_WORKING_AREA_END(usbp->wa_pump),
STM32_USB_OTG_THREAD_PRIO, STM32_USB_OTG_THREAD_PRIO,
usb_lld_pump, usbp); usb_lld_pump,
chThdStartI(usbp->tr); (void *)usbp
};
usbp->tr = chThdCreateI(&usbpump_descriptor);
chSchRescheduleS(); chSchRescheduleS();
} }
#endif #endif
@ -1286,9 +1289,6 @@ void usb_lld_pump(void *p) {
USBDriver *usbp = (USBDriver *)p; USBDriver *usbp = (USBDriver *)p;
stm32_otg_t *otgp = usbp->otg; stm32_otg_t *otgp = usbp->otg;
#if defined(_CHIBIOS_RT_)
chRegSetThreadName("usb_lld_pump");
#endif
osalSysLock(); osalSysLock();
while (true) { while (true) {
usbep_t ep; usbep_t ep;

View File

@ -133,7 +133,7 @@ static bool cmdexec(const ShellCommand *scp, BaseSequentialStream *chp,
* *
* @param[in] p pointer to a @p BaseSequentialStream object * @param[in] p pointer to a @p BaseSequentialStream object
*/ */
static THD_FUNCTION(shell_thread, p) { THD_FUNCTION(shellThread, p) {
int n; int n;
BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel; BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
const ShellCommand *scp = ((ShellConfig *)p)->sc_commands; const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
@ -217,44 +217,15 @@ void shellExit(msg_t msg) {
chThdExitS(msg); chThdExitS(msg);
} }
/**
* @brief Spawns a new shell.
* @pre @p CH_CFG_USE_HEAP and @p CH_CFG_USE_DYNAMIC must be enabled.
*
* @param[in] scp pointer to a @p ShellConfig object
* @param[in] size size of the shell working area to be allocated
* @param[in] prio priority level for the new shell
* @return A pointer to the shell thread.
* @retval NULL thread creation failed because memory allocation.
*
* @api
*/
#if CH_CFG_USE_HEAP && CH_CFG_USE_DYNAMIC
thread_t *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio) {
return chThdCreateFromHeap(NULL, size, prio, shell_thread, (void *)scp);
}
#endif
/**
* @brief Create statically allocated shell thread.
*
* @param[in] scp pointer to a @p ShellConfig object
* @param[in] wsp pointer to a working area dedicated to the shell thread stack
* @param[in] size size of the shell working area
* @param[in] prio priority level for the new shell
* @return A pointer to the shell thread.
*
* @api
*/
thread_t *shellCreateStatic(const ShellConfig *scp, void *wsp,
size_t size, tprio_t prio) {
return chThdCreateStatic(wsp, size, prio, shell_thread, (void *)scp);
}
/** /**
* @brief Reads a whole line from the input channel. * @brief Reads a whole line from the input channel.
* @note Input chars are echoed on the same stream object with the
* following exceptions:
* - DEL and BS are echoed as BS-SPACE-BS.
* - CR is echoed as CR-LF.
* - 0x4 is echoed as "^D".
* - Other values below 0x20 are not echoed.
* .
* *
* @param[in] chp pointer to a @p BaseSequentialStream object * @param[in] chp pointer to a @p BaseSequentialStream object
* @param[in] line pointer to the line buffer * @param[in] line pointer to the line buffer

View File

@ -70,12 +70,8 @@ extern event_source_t shell_terminated;
extern "C" { extern "C" {
#endif #endif
void shellInit(void); void shellInit(void);
THD_FUNCTION(shellThread, p);
void shellExit(msg_t msg); void shellExit(msg_t msg);
#if CH_CFG_USE_HEAP && CH_CFG_USE_DYNAMIC
thread_t *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio);
#endif
thread_t *shellCreateStatic(const ShellConfig *scp, void *wsp,
size_t size, tprio_t prio);
bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size); bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -524,6 +524,8 @@
/* Port-specific settings (override port settings defaulted in chcore.h). */ /* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/ /*===========================================================================*/
#define CORTEX_VTOR_INIT 0x00200000U
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -524,6 +524,8 @@
/* Port-specific settings (override port settings defaulted in chcore.h). */ /* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/ /*===========================================================================*/
#define CORTEX_VTOR_INIT 0x00200000U
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -524,6 +524,8 @@
/* Port-specific settings (override port settings defaulted in chcore.h). */ /* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/ /*===========================================================================*/
#define CORTEX_VTOR_INIT 0x00200000U
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -524,6 +524,8 @@
/* Port-specific settings (override port settings defaulted in chcore.h). */ /* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/ /*===========================================================================*/
#define CORTEX_VTOR_INIT 0x00200000U
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -524,6 +524,8 @@
/* Port-specific settings (override port settings defaulted in chcore.h). */ /* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/ /*===========================================================================*/
#define CORTEX_VTOR_INIT 0x00200000U
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */

View File

@ -34,17 +34,18 @@
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) { static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size; size_t n, total, largest;
(void)argv; (void)argv;
if (argc > 0) { if (argc > 0) {
chprintf(chp, "Usage: mem\r\n"); chprintf(chp, "Usage: mem\r\n");
return; return;
} }
n = chHeapStatus(NULL, &size); n = chHeapStatus(NULL, &total, &largest);
chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX()); chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX());
chprintf(chp, "heap fragments : %u\r\n", n); chprintf(chp, "heap fragments : %u\r\n", n);
chprintf(chp, "heap free total : %u bytes\r\n", size); chprintf(chp, "heap free total : %u bytes\r\n", total);
chprintf(chp, "heap free largest: %u bytes\r\n", largest);
} }
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
@ -56,13 +57,13 @@ static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
chprintf(chp, "Usage: threads\r\n"); chprintf(chp, "Usage: threads\r\n");
return; return;
} }
chprintf(chp, " addr stack prio refs state time\r\n"); chprintf(chp, "stklimit stack addr prio state name\r\n");
tp = chRegFirstThread(); tp = chRegFirstThread();
do { do {
chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n", chprintf(chp, "%08lx %08lx %08lx %4lu %9s %12s\r\n",
(uint32_t)tp, (uint32_t)tp->p_ctx.r13, (uint32_t)tp->stklimit, (uint32_t)tp->ctx.r13, (uint32_t)tp,
(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1), (uint32_t)tp->prio, states[tp->state],
states[tp->p_state]); tp->name == NULL ? "" : tp->name);
tp = chRegNextThread(tp); tp = chRegNextThread(tp);
} while (tp != NULL); } while (tp != NULL);
} }
@ -209,14 +210,16 @@ 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 && (SDU2.config->usbp->state == USB_ACTIVE)) if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE)) {
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
}
else if (chThdTerminatedX(shelltp)) { else if (chThdTerminatedX(shelltp)) {
chThdRelease(shelltp); /* Recovers memory of the previous shell. */ chThdWait(shelltp);
chHeapFree(chthdGetStackLimitX(shelltp));
shelltp = NULL; /* Triggers spawning of a new shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */
} }
#if 0 #if 0

View File

@ -524,6 +524,8 @@
/* Port-specific settings (override port settings defaulted in chcore.h). */ /* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/ /*===========================================================================*/
#define CORTEX_VTOR_INIT 0x00200000U
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */ /** @} */