summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/drivers/serial/serial_tty.c63
-rw-r--r--components/lwp/lwp.c29
-rw-r--r--components/lwp/terminal/terminal.h5
3 files changed, 66 insertions, 31 deletions
diff --git a/components/drivers/serial/serial_tty.c b/components/drivers/serial/serial_tty.c
index 36692a9300..f75123eba2 100644
--- a/components/drivers/serial/serial_tty.c
+++ b/components/drivers/serial/serial_tty.c
@@ -404,3 +404,66 @@ static int _tty_workqueue_init(void)
return RT_EOK;
}
INIT_PREV_EXPORT(_tty_workqueue_init);
+
+static rt_err_t _match_tty_iter(struct rt_object *obj, void *data)
+{
+ rt_device_t target = *(rt_device_t *)data;
+ rt_device_t device = rt_container_of(obj, struct rt_device, parent);
+ if (device->type == RT_Device_Class_Char)
+ {
+ lwp_tty_t tp;
+ if (rt_strncmp(obj->name, "tty"TTY_NAME_PREFIX,
+ sizeof("tty"TTY_NAME_PREFIX) - 1) == 0)
+ {
+ struct serial_tty_context *softc;
+
+ tp = rt_container_of(device, struct lwp_tty, parent);
+ softc = tty_softc(tp);
+
+ if (&softc->parent->parent == target)
+ {
+ /* matched, early return */
+ *(rt_device_t *)data = device;
+ return 1;
+ }
+ }
+ }
+
+ return RT_EOK;
+}
+
+/**
+ * @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 int _default_console_setup(void)
+{
+ rt_err_t rc;
+ rt_device_t bakdev;
+ rt_device_t ttydev;
+
+ bakdev = rt_console_get_device();
+ if (!bakdev)
+ {
+ return -RT_ENOENT;
+ }
+
+ ttydev = bakdev;
+ rt_object_for_each(RT_Object_Class_Device, _match_tty_iter, &ttydev);
+
+ if (ttydev != bakdev)
+ {
+ LOG_I("Using /dev/%.*s as default console", RT_NAME_MAX, ttydev->parent.name);
+ lwp_console_register_backend(ttydev, LWP_CONSOLE_LOWEST_PRIOR);
+ rc = RT_EOK;
+ }
+ else
+ {
+ rc = -RT_EINVAL;
+ }
+
+ return rc;
+}
+
+INIT_COMPONENT_EXPORT(_default_console_setup);
diff --git a/components/lwp/lwp.c b/components/lwp/lwp.c
index 87629cc890..c33bbfdc5f 100644
--- a/components/lwp/lwp.c
+++ b/components/lwp/lwp.c
@@ -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);
diff --git a/components/lwp/terminal/terminal.h b/components/lwp/terminal/terminal.h
index df0dc04128..69ed66d5ff 100644
--- a/components/lwp/terminal/terminal.h
+++ b/components/lwp/terminal/terminal.h
@@ -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);