optimize Shell Cmd ShowBus using node

This commit is contained in:
Liu_Weichao 2021-05-08 10:56:14 +08:00
parent 872f8bc9ca
commit d59964e87f
1 changed files with 46 additions and 50 deletions

View File

@ -654,7 +654,7 @@ static char *const bus_type_str[] =
"Unknown"
};
static DriverType showBusFindDriver(struct Bus *bus)
static DriverType ShowBusFindDriver(struct Bus *bus)
{
struct Driver *driver = NONE;
@ -670,9 +670,12 @@ static DriverType showBusFindDriver(struct Bus *bus)
long ShowBus(void)
{
ListGetNext_t find_arg;
DoubleLinklistType *obj_list[LIST_FIND_OBJ_NR];
DoubleLinklistType *next = (DoubleLinklistType*)NONE;
BusType bus;
DriverType driver;
HardwareDevType device;
DoubleLinklistType *bus_node = NONE;
DoubleLinklistType *bus_head = &bus_linklist;
int i = 0;
int dev_cnt, maxlen;
@ -682,8 +685,6 @@ long ShowBus(void)
const char *item_name_2 = "dev_name";
const char *item_cnt = "cnt";
ListFindManagelistInit(&find_arg, Cmpt_KindN_Bus, obj_list, sizeof(obj_list)/sizeof(obj_list[0]));
KPrintf(" %-15s%-15s%-15s%-15s%-20s\n", item_type, item_name_0, item_name_1, item_name_2, item_cnt);
maxlen = 65;
while (i < maxlen) {
@ -695,22 +696,18 @@ long ShowBus(void)
}
}
bus_node = bus_head->node_next;
do
{
next = ListGetNext(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++) {
struct Bus *bus;
bus = SYS_DOUBLE_LINKLIST_ENTRY(obj_list[i], struct Bus, bus_link);
bus = SYS_DOUBLE_LINKLIST_ENTRY(bus_node, struct Bus, bus_link);
if (bus) {
KPrintf("%s", " ");
KPrintf("%-15s%-15s",
bus_type_str[bus->bus_type],
bus->bus_name);
DriverType driver = showBusFindDriver(bus);
driver = ShowBusFindDriver(bus);
if (driver) {
KPrintf("%-15s", driver->drv_name);
@ -719,13 +716,13 @@ long ShowBus(void)
}
if (bus->haldev_cnt) {
DoubleLinklistType *node = NONE;
DoubleLinklistType *head = &bus->bus_devlink;
DoubleLinklistType *dev_node = NONE;
DoubleLinklistType *dev_head = &bus->bus_devlink;
node = head->node_next;
dev_node = dev_head->node_next;
dev_cnt = 1;
while (node != head) {
HardwareDevType device = SYS_DOUBLE_LINKLIST_ENTRY(node, struct HardwareDev, dev_link);
while (dev_node != dev_head) {
device = SYS_DOUBLE_LINKLIST_ENTRY(dev_node, struct HardwareDev, dev_link);
if (1 == dev_cnt) {
if (device) {
@ -742,16 +739,15 @@ long ShowBus(void)
}
}
dev_cnt++;
node = node->node_next;
dev_node = dev_node->node_next;
}
} else {
KPrintf("\n");
}
}
bus_node = bus_node->node_next;
}
}
}
while (next != (DoubleLinklistType*)NONE);
while (bus_node != bus_head);
return 0;
}