1.优化设备根设备。

This commit is contained in:
MacRsh
2023-12-21 16:38:05 +08:00
parent e33aeca4da
commit 0b29f94ebe
2 changed files with 26 additions and 33 deletions

View File

@@ -86,7 +86,7 @@ class MDK5:
exist_paths = inc_path.text.split(';')
if path not in exist_paths:
inc_path.text += f";{path}"
log_print('info', "include %s" % path)
log_print('info', "include %s" % path)
def add_include_paths(self, paths):
for path in paths:
@@ -154,10 +154,11 @@ class MDK5:
# Get c files
files = []
for root, dirs, fs in os.walk(path):
for f in fs:
if f.endswith(".c") or f.endswith(".cpp") or f.endswith(".cxx"):
file = os.path.relpath(os.path.join(root, f), self.path)
files.append(file)
if root == path:
for f in fs:
if f.endswith(".c") or f.endswith(".cpp") or f.endswith(".cxx"):
file = os.path.relpath(os.path.join(root, f), self.path)
files.append(file)
# Fix name
name = os.path.relpath(path, self.path).replace('\\', '/').replace("../", "")
# Add group
@@ -180,7 +181,7 @@ class MDK5:
if gnu_node is not None:
if gnu_node.text != gnu_text:
gnu_node.text = gnu_text
log_print('info', "use GNU")
log_print('info', "use GNU")
def save(self):
self.tree.write(self.file, pretty_print=True, encoding="utf-8", xml_declaration=True)
@@ -372,8 +373,9 @@ if __name__ == '__main__':
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--menuconfig", action="store_true", help="Run menuconfig")
parser.add_argument("-mdk", "--mdk", action="store_true", help="Build with MDK")
parser.add_argument("-ecl", "--eclipse", action="store_true", help="Build with Eclipse")
group = parser.add_mutually_exclusive_group()
group.add_argument("-mdk", "--mdk", action="store_true", help="Build with MDK")
group.add_argument("-ecl", "--eclipse", action="store_true", help="Build with Eclipse")
parser.add_argument("-lic", "--license", action="store_true", help="Show license")
args = parser.parse_args()

View File

@@ -59,14 +59,9 @@ static int dev_register_child(struct mr_dev *parent, struct mr_dev *child, const
/* Insert the device into the child list */
child->magic = MR_MAGIC_NUMBER;
strncpy(child->name, name, MR_CFG_NAME_MAX);
child->parent = parent;
mr_list_insert_before(&parent->clist, &child->list);
/* The virtual root device is not used as the actual parent device */
if (dev_is_root(parent) == MR_FALSE)
{
child->parent = parent;
}
/* Enable interrupt */
mr_interrupt_enable();
return MR_EOK;
@@ -153,8 +148,8 @@ static struct mr_dev *dev_find_by_path(struct mr_dev *parent, const char *path)
#ifdef MR_USING_RDWR_CTL
static int dev_lock_take(struct mr_dev *dev, int take, int set)
{
/* Continue iterating */
if (dev->parent != MR_NULL)
/* Continue iterating until reach the root device */
if (dev_is_root(dev->parent) != MR_TRUE)
{
int ret = dev_lock_take(dev->parent, take, set);
if (ret != MR_EOK)
@@ -176,8 +171,8 @@ static int dev_lock_take(struct mr_dev *dev, int take, int set)
static void dev_lock_release(struct mr_dev *dev, int release)
{
/* Continue iterating */
if (dev->parent != MR_NULL)
/* Continue iterating until reach the root device */
if (dev_is_root(dev->parent) != MR_TRUE)
{
dev_lock_release(dev->parent, release);
}
@@ -211,8 +206,8 @@ static int dev_open(struct mr_dev *dev, int oflags)
/* Check whether the device is opened */
if (dev->ref_count == 0)
{
/* Continue iterating */
if (dev->parent != NULL)
/* Continue iterating until reach the root device */
if (dev_is_root(dev->parent) != MR_TRUE)
{
int ret = dev_open(dev->parent, oflags);
if (ret != MR_EOK)
@@ -251,8 +246,8 @@ static int dev_close(struct mr_dev *dev)
/* Check whether the device needs to be closed */
if (dev->ref_count == 0)
{
/* Continue iterating */
if (dev->parent != NULL)
/* Continue iterating until reach the root device */
if (dev_is_root(dev->parent) != MR_TRUE)
{
int ret = dev_close(dev->parent);
if (ret != MR_EOK)
@@ -547,22 +542,18 @@ int mr_dev_get_path(struct mr_dev *dev, char *buf, size_t bufsz)
if (dev->parent != MR_NULL)
{
ret = mr_dev_get_path(dev->parent, buf, bufsz);
} else
{
ret = snprintf(buf, bufsz, MR_ROOT_DEV_NAME);
if (ret < 0)
{
return ret;
}
}
/* Check memory */
if (ret < 0)
/* Check whether the buffer is enough */
if ((bufsz - ret) <= (strlen(dev->name) + 1))
{
return MR_ENOMEM;
}
/* If the space is sufficient, continue to obtain the path */
if ((bufsz - ret) > strlen(dev->name))
{
ret += snprintf(buf + ret, bufsz - ret, "/%s", dev->name);
}
ret += snprintf(buf + ret, bufsz - ret, "/%s", dev->name);
return ret;
}