Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[component][driver]init dm serial naming framework in a separate phase #8971

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions components/drivers/serial/serial_dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <rtatomic.h>
#include <drivers/serial_dm.h>

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);

Expand All @@ -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

Expand All @@ -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;
Expand Down
Loading