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,10 +714,7 @@ void usb_lld_init(void) {
{
void *wsp = USBD2.wa_pump;
_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);
}
#endif /* CH_DBG_FILL_THREADS */
@ -861,10 +858,16 @@ void usb_lld_start(USBDriver *usbp) {
#if defined(_CHIBIOS_RT_)
/* Creates the data pump thread. Note, it is created only once.*/
if (usbp->tr == NULL) {
usbp->tr = chThdCreateI(usbp->wa_pump, sizeof usbp->wa_pump,
STM32_USB_OTG_THREAD_PRIO,
usb_lld_pump, usbp);
chThdStartI(usbp->tr);
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,
usb_lld_pump,
(void *)usbp
};
usbp->tr = chThdCreateI(&usbpump_descriptor);
chSchRescheduleS();
}
#endif
@ -1286,9 +1289,6 @@ void usb_lld_pump(void *p) {
USBDriver *usbp = (USBDriver *)p;
stm32_otg_t *otgp = usbp->otg;
#if defined(_CHIBIOS_RT_)
chRegSetThreadName("usb_lld_pump");
#endif
osalSysLock();
while (true) {
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
*/
static THD_FUNCTION(shell_thread, p) {
THD_FUNCTION(shellThread, p) {
int n;
BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
@ -217,44 +217,15 @@ void shellExit(msg_t 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.
* @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] line pointer to the line buffer

View File

@ -70,12 +70,8 @@ extern event_source_t shell_terminated;
extern "C" {
#endif
void shellInit(void);
THD_FUNCTION(shellThread, p);
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);
#ifdef __cplusplus
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,17 +34,18 @@
#define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256)
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
size_t n, size;
size_t n, total, largest;
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: mem\r\n");
return;
}
n = chHeapStatus(NULL, &size);
n = chHeapStatus(NULL, &total, &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 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[]) {
@ -56,13 +57,13 @@ static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
chprintf(chp, "Usage: threads\r\n");
return;
}
chprintf(chp, " addr stack prio refs state time\r\n");
chprintf(chp, "stklimit stack addr prio state name\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]);
chprintf(chp, "%08lx %08lx %08lx %4lu %9s %12s\r\n",
(uint32_t)tp->stklimit, (uint32_t)tp->ctx.r13, (uint32_t)tp,
(uint32_t)tp->prio, states[tp->state],
tp->name == NULL ? "" : tp->name);
tp = chRegNextThread(tp);
} while (tp != NULL);
}
@ -209,14 +210,16 @@ int main(void) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
* Normal main() thread activity, spawning shells.
*/
while (true) {
if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE))
shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
if (!shelltp && (SDU2.config->usbp->state == USB_ACTIVE)) {
shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
}
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. */
}
#if 0

View File

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