[update] Dynamic change console

This commit is contained in:
thread-liu 2020-10-13 15:10:55 +08:00
parent 8edb7c316a
commit 01bdb2c86e
2 changed files with 38 additions and 8 deletions

View File

@ -12,20 +12,20 @@
#include <rtdevice.h>
#include <board.h>
/* defined the LD8 pin: PD11 */
#define LED8_PIN GET_PIN(D, 11)
/* defined the LD7 pin: PH7 */
#define LED7_PIN GET_PIN(H, 7)
int main(void)
{
int count = 1;
/* set LD8 pin mode to output */
rt_pin_mode(LED8_PIN, PIN_MODE_OUTPUT);
/* set LD7 pin mode to output */
rt_pin_mode(LED7_PIN, PIN_MODE_OUTPUT);
while (count++)
{
rt_pin_write(LED8_PIN, PIN_HIGH);
rt_pin_write(LED7_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(LED8_PIN, PIN_LOW);
rt_pin_write(LED7_PIN, PIN_LOW);
rt_thread_mdelay(500);
}

View File

@ -235,8 +235,6 @@ int rt_hw_openamp_init(void)
rt_hw_openamp_register(&dev_openamp, "openamp", 0, NULL);
rt_console_set_device("openamp");
return RT_EOK;
}
INIT_PREV_EXPORT(rt_hw_openamp_init);
@ -289,4 +287,36 @@ static int creat_openamp_thread(void)
}
INIT_APP_EXPORT(creat_openamp_thread);
#ifdef FINSH_USING_MSH
static int console(int argc, char **argv)
{
rt_err_t result = RT_EOK;
if (argc > 1)
{
if (!strcmp(argv[1], "set"))
{
rt_kprintf("console change to %s\n", argv[2]);
rt_console_set_device(argv[2]);
finsh_set_device(argv[2]);
}
else
{
rt_kprintf("Unknown command. Please enter 'console' for help\n");
result = -RT_ERROR;
}
}
else
{
rt_kprintf("Usage: \n");
rt_kprintf("console set <name> - change console by name\n");
result = -RT_ERROR;
}
return result;
}
MSH_CMD_EXPORT(console, set console name);
#endif /* FINSH_USING_MSH */
#endif