[smart] select console device dynamically (#8949)

* [smart] select console device dynamically

- Fixed compiler warning on terminal subsystem for
  `components/lwp/terminal/terminal.h`
- Updated default console setup to dynamically select an appropriate tty
  device based on the configured console device name.

Signed-off-by: Shell <smokewood@qq.com>

* fixup: remove useless codes

---------

Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
Shell
2024-05-17 13:19:00 +08:00
committed by GitHub
parent 3d30b56c86
commit f2d6325b43
6 changed files with 146 additions and 52 deletions
+1 -28
View File
@@ -17,7 +17,7 @@
*/
#define DBG_TAG "lwp"
#define DBG_LVL DBG_WARNING
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#include <rthw.h>
@@ -62,29 +62,6 @@ static const char elf_magic[] = {0x7f, 'E', 'L', 'F'};
extern char working_directory[];
#endif
/**
* @brief The default console is only a backup device with lowest priority.
* It's always recommended to scratch the console from the boot arguments.
* And dont forget to register the device with a higher priority.
*/
static rt_err_t lwp_default_console_setup(void)
{
rt_device_t bakdev = rt_device_find("ttyS0");
rt_err_t rc;
if (bakdev)
{
lwp_console_register_backend(bakdev, LWP_CONSOLE_LOWEST_PRIOR);
rc = RT_EOK;
}
else
{
rc = -RT_EINVAL;
}
return rc;
}
static int lwp_component_init(void)
{
int rc;
@@ -104,10 +81,6 @@ static int lwp_component_init(void)
{
LOG_E("%s: lwp_futex_init() failed", __func__);
}
else if ((rc = lwp_default_console_setup()) != RT_EOK)
{
LOG_E("%s: lwp_default_console_setup() failed", __func__);
}
return rc;
}
INIT_COMPONENT_EXPORT(lwp_component_init);
+2 -3
View File
@@ -212,9 +212,8 @@ void tty_rel_gone(struct lwp_tty *tp);
#define tty_lock_notrecused(tp) (rt_mutex_get_hold(tty_getlock(tp)) == 1)
#define tty_assert_locked(tp) RT_ASSERT(tty_lock_owned(tp))
#define tty_lock_assert(tp, option) \
(((option) == (MA_OWNED | MA_NOTRECURSED)) \
? (tty_lock_owned(tp) && tty_lock_notrecused(tp)) \
: rt_assert_handler("Operation not allowed", __func__, __LINE__))
RT_ASSERT(((option) == (MA_OWNED | MA_NOTRECURSED)) && \
(tty_lock_owned(tp) && tty_lock_notrecused(tp)))
/* System messages. */
int tty_checkoutq(struct lwp_tty *tp);