From adf2b35ec61a5e04e1b1301a2b4c3485e3eba994 Mon Sep 17 00:00:00 2001 From: zms123456 <85141075+zmshahaha@users.noreply.github.com> Date: Tue, 21 May 2024 22:36:20 +0800 Subject: [PATCH] [component][driver]init dm serial naming framework in a separate phase (#8971) init dm serial naming framework in a phase --- components/drivers/serial/serial_dm.c | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/components/drivers/serial/serial_dm.c b/components/drivers/serial/serial_dm.c index c41a1fec16..dc281cd367 100644 --- a/components/drivers/serial/serial_dm.c +++ b/components/drivers/serial/serial_dm.c @@ -11,11 +11,12 @@ #include #include +static int uid_min = -1; +static volatile rt_atomic_t uid = 0; + int serial_dev_set_name(struct rt_serial_device *sdev) { int id = -1; - static int uid_min = -1; - static volatile rt_atomic_t uid = 0; RT_ASSERT(sdev != RT_NULL); @@ -28,20 +29,6 @@ int serial_dev_set_name(struct rt_serial_device *sdev) { id = rt_ofw_get_alias_id(sdev->parent.ofw_node, "uart"); } - - if (uid_min < 0) - { - uid_min = rt_ofw_get_alias_last_id("serial"); - - if (uid_min < 0) - { - uid_min = rt_ofw_get_alias_last_id("uart"); - } - - uid_min = uid_min < 0 ? 0 : (uid_min + 1); - - rt_hw_atomic_store(&uid, uid_min); - } } #endif @@ -53,6 +40,25 @@ int serial_dev_set_name(struct rt_serial_device *sdev) return rt_dm_dev_set_name(&sdev->parent, "uart%u", id); } +static int serial_dm_naming_framework_init(void) +{ +#ifdef RT_USING_OFW + uid_min = rt_ofw_get_alias_last_id("serial"); + + if (uid_min < 0) + { + uid_min = rt_ofw_get_alias_last_id("uart"); + } + + uid_min = uid_min < 0 ? 0 : (uid_min + 1); + + rt_hw_atomic_store(&uid, uid_min); +#endif + + return 0; +} +INIT_PLATFORM_EXPORT(serial_dm_naming_framework_init); + void *serial_base_from_args(char *str) { rt_ubase_t base = 0;