-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathcmd.c
More file actions
1210 lines (1064 loc) · 37.6 KB
/
Copy pathcmd.c
File metadata and controls
1210 lines (1064 loc) · 37.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2006-04-30 Bernard first implementation
* 2006-05-04 Bernard add list_thread,
* list_sem,
* list_timer
* 2006-05-20 Bernard add list_mutex,
* list_mailbox,
* list_msgqueue,
* list_event,
* list_fevent,
* list_mempool
* 2006-06-03 Bernard display stack information in list_thread
* 2006-08-10 Bernard change version to invoke rt_show_version
* 2008-09-10 Bernard update the list function for finsh syscall
* list and sysvar list
* 2009-05-30 Bernard add list_device
* 2010-04-21 yi.qiu add list_module
* 2012-04-29 goprife improve the command line auto-complete feature.
* 2012-06-02 lgnq add list_memheap
* 2012-10-22 Bernard add MS VC++ patch.
* 2016-06-02 armink beautify the list_thread command
* 2018-11-22 Jesven list_thread add smp support
* 2018-12-27 Jesven Fix the problem that disable interrupt too long in list_thread
* Provide protection for the "first layer of objects" when list_*
* 2020-04-07 chenhui add clear
* 2022-07-02 Stanley Lwin add list command
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
* 2024-02-09 Bernard fix the version command
* 2023-02-25 GuEe-GUI add console
*/
#include <rthw.h>
#include <rtthread.h>
#include <string.h>
#ifdef RT_USING_FINSH
#include <finsh.h>
#define LIST_DFS_OPT_ID 0x100
#define LIST_FIND_OBJ_NR 8
static long clear(void)
{
rt_kprintf("\x1b[2J\x1b[H");
return 0;
}
MSH_CMD_EXPORT(clear, clear the terminal screen);
static long version(void)
{
rt_show_version();
return 0;
}
MSH_CMD_EXPORT(version, show RT-Thread version information);
#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE)
#if !defined(RT_USING_POSIX) && defined(RT_USING_POSIX_STDIO)
#include <posix/stdio.h>
#endif
static int console(int argc, char **argv)
{
rt_device_t dev = RT_NULL;
if (argc > 1)
{
if (!rt_strcmp(argv[1], "set"))
{
if (argc < 3)
{
goto _help;
}
dev = rt_device_find(argv[2]);
if (dev == RT_NULL)
{
rt_kprintf("console: can not find device: %s\n", argv[2]);
return -RT_ERROR;
}
if (rt_console_get_device() != dev)
{
rt_console_set_device(argv[2]);
if (rt_console_get_device() != dev)
{
rt_kprintf("console: can not use device as console: %s\n", argv[2]);
return -RT_ERROR;
}
rt_kprintf("console change to %s\n", argv[2]);
}
else
{
rt_kprintf("console already set to %s\n", argv[2]);
}
#ifdef RT_USING_POSIX
console_set_iodev(dev);
#elif !defined(RT_USING_POSIX_STDIO)
finsh_set_device(argv[2]);
#else
rt_posix_stdio_init();
#endif /* RT_USING_POSIX */
}
else
{
goto _help;
}
}
else
{
goto _help;
}
return RT_EOK;
_help:
rt_kprintf("Usage: \n");
rt_kprintf("console set <name> - change console by name\n");
return -RT_ERROR;
}
MSH_CMD_EXPORT(console, console setting);
#endif /* RT_USING_DEVICE && RT_USING_CONSOLE */
rt_inline void object_split(int len)
{
while (len--) rt_kprintf("-");
}
typedef struct
{
rt_list_t *list;
rt_list_t **array;
rt_uint8_t type;
int nr; /* input: max nr, can't be 0 */
int nr_out; /* out: got nr */
} list_get_next_t;
static void list_find_init(list_get_next_t *p, rt_uint8_t type, rt_list_t **array, int nr)
{
struct rt_object_information *info;
rt_list_t *list;
info = rt_object_get_information((enum rt_object_class_type)type);
list = &info->object_list;
p->list = list;
p->type = type;
p->array = array;
p->nr = nr;
p->nr_out = 0;
}
static rt_list_t *list_get_next(rt_list_t *current, list_get_next_t *arg)
{
int first_flag = 0;
rt_base_t level;
rt_list_t *node, *list;
rt_list_t **array;
struct rt_object_information *info;
int nr;
arg->nr_out = 0;
if (!arg->nr || !arg->type)
{
return (rt_list_t *)RT_NULL;
}
list = arg->list;
info = rt_list_entry(list, struct rt_object_information, object_list);
if (!current) /* find first */
{
node = list;
first_flag = 1;
}
else
{
node = current;
}
level = rt_spin_lock_irqsave(&info->spinlock);
if (!first_flag)
{
struct rt_object *obj;
/* The node in the list? */
obj = rt_list_entry(node, struct rt_object, list);
if ((obj->type & ~RT_Object_Class_Static) != arg->type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
return (rt_list_t *)RT_NULL;
}
}
nr = 0;
array = arg->array;
while (1)
{
node = node->next;
if (node == list)
{
node = (rt_list_t *)RT_NULL;
break;
}
nr++;
*array++ = node;
if (nr == arg->nr)
{
break;
}
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
arg->nr_out = nr;
return node;
}
long list_thread(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
const char *item_title = "thread";
const size_t tcb_strlen = sizeof(void *) * 2 + 2;
const size_t usage_strlen = sizeof(void *) + 1;
int maxlen;
list_find_init(&find_arg, RT_Object_Class_Thread, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
#ifdef RT_USING_SMP
rt_kprintf("%-*.*s cpu bind pri status sp stack size max used left tick error tcb addr usage\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" --- ---- --- ------- ---------- ---------- ------ ---------- -------");
rt_kprintf(" ");
object_split(tcb_strlen);
rt_kprintf(" ");
object_split(usage_strlen);
rt_kprintf("\n");
#else
rt_kprintf("%-*.*s pri status sp stack size max used left tick error tcb addr usage\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" --- ------- ---------- ---------- ------ ---------- -------");
rt_kprintf(" ");
object_split(tcb_strlen);
rt_kprintf(" ");
object_split(usage_strlen);
rt_kprintf("\n");
#endif /*RT_USING_SMP*/
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_thread *thread;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
/* copy info */
rt_spin_unlock_irqrestore(&info->spinlock, level);
thread = (struct rt_thread *)obj;
{
rt_uint8_t stat;
rt_uint8_t *ptr;
#ifdef RT_USING_SMP
/* no synchronization applied since it's only for debug */
if (RT_SCHED_CTX(thread).oncpu != RT_CPU_DETACHED)
rt_kprintf("%-*.*s %3d %3d %4d ", maxlen, RT_NAME_MAX,
thread->parent.name, RT_SCHED_CTX(thread).oncpu,
RT_SCHED_CTX(thread).bind_cpu,
RT_SCHED_PRIV(thread).current_priority);
else
rt_kprintf("%-*.*s N/A %3d %4d ", maxlen, RT_NAME_MAX,
thread->parent.name,
RT_SCHED_CTX(thread).bind_cpu,
RT_SCHED_PRIV(thread).current_priority);
#else
/* no synchronization applied since it's only for debug */
rt_kprintf("%-*.*s %3d ", maxlen, RT_NAME_MAX, thread->parent.name, RT_SCHED_PRIV(thread).current_priority);
#endif /*RT_USING_SMP*/
stat = (RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK);
if (stat == RT_THREAD_READY) rt_kprintf(" ready ");
else if ((stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) rt_kprintf(" suspend");
else if (stat == RT_THREAD_INIT) rt_kprintf(" init ");
else if (stat == RT_THREAD_CLOSE) rt_kprintf(" close ");
else if (stat == RT_THREAD_RUNNING) rt_kprintf(" running");
#if defined(ARCH_CPU_STACK_GROWS_UPWARD)
ptr = (rt_uint8_t *)thread->stack_addr + thread->stack_size - 1;
while (*ptr == '#')ptr --;
rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %s %p",
((rt_ubase_t)thread->sp - (rt_ubase_t)thread->stack_addr),
thread->stack_size,
((rt_ubase_t)ptr - (rt_ubase_t)thread->stack_addr) * 100 / thread->stack_size,
thread->remaining_tick,
rt_strerror(thread->error),
thread);
#ifdef RT_USING_CPU_USAGE_TRACER
rt_kprintf(" %3d%%\n", rt_thread_get_usage(thread));
#else
rt_kprintf(" N/A\n");
#endif
#else
ptr = (rt_uint8_t *)thread->stack_addr;
while (*ptr == '#') ptr ++;
rt_kprintf(" 0x%08x 0x%08x %3d%% 0x%08x %s %p",
thread->stack_size + ((rt_ubase_t)thread->stack_addr - (rt_ubase_t)thread->sp),
thread->stack_size,
(thread->stack_size - ((rt_ubase_t) ptr - (rt_ubase_t) thread->stack_addr)) * 100
/ thread->stack_size,
RT_SCHED_PRIV(thread).remaining_tick,
rt_strerror(thread->error),
thread);
#ifdef RT_USING_CPU_USAGE_TRACER
rt_kprintf(" %3d%%\n", rt_thread_get_usage(thread));
#else
rt_kprintf(" N/A\n");
#endif
#endif
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#ifdef RT_USING_SEMAPHORE
long list_sem(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "semaphore";
list_find_init(&find_arg, RT_Object_Class_Semaphore, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s v suspend thread\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" --- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_semaphore *sem;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
sem = (struct rt_semaphore *)obj;
if (!rt_list_isempty(&sem->parent.suspend_thread))
{
rt_kprintf("%-*.*s %03d %d:",
maxlen, RT_NAME_MAX,
sem->parent.parent.name,
sem->value,
rt_list_len(&sem->parent.suspend_thread));
rt_susp_list_print(&(sem->parent.suspend_thread));
rt_kprintf("\n");
}
else
{
rt_kprintf("%-*.*s %03d %d\n",
maxlen, RT_NAME_MAX,
sem->parent.parent.name,
sem->value,
rt_list_len(&sem->parent.suspend_thread));
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_SEMAPHORE */
#ifdef RT_USING_EVENT
long list_event(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "event";
list_find_init(&find_arg, RT_Object_Class_Event, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s set suspend thread\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---------- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_event *e;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
e = (struct rt_event *)obj;
if (!rt_list_isempty(&e->parent.suspend_thread))
{
rt_kprintf("%-*.*s 0x%08x %03d:",
maxlen, RT_NAME_MAX,
e->parent.parent.name,
e->set,
rt_list_len(&e->parent.suspend_thread));
rt_susp_list_print(&(e->parent.suspend_thread));
rt_kprintf("\n");
}
else
{
rt_kprintf("%-*.*s 0x%08x 0\n",
maxlen, RT_NAME_MAX, e->parent.parent.name, e->set);
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_EVENT */
#ifdef RT_USING_MUTEX
long list_mutex(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "mutex";
list_find_init(&find_arg, RT_Object_Class_Mutex, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s owner hold priority suspend thread \n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" -------- ---- -------- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_mutex *m;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
m = (struct rt_mutex *)obj;
if (!rt_list_isempty(&m->parent.suspend_thread))
{
rt_kprintf("%-*.*s %-8.*s %04d %8d %04d ",
maxlen, RT_NAME_MAX,
m->parent.parent.name,
RT_NAME_MAX,
(m->owner == RT_NULL) ? "(null)" : m->owner->parent.name,
m->hold,
m->priority,
rt_list_len(&m->parent.suspend_thread));
rt_susp_list_print(&(m->parent.suspend_thread));
rt_kprintf("\n");
}
else
{
rt_kprintf("%-*.*s %-8.*s %04d %8d %04d\n",
maxlen, RT_NAME_MAX,
m->parent.parent.name,
RT_NAME_MAX,
(m->owner == RT_NULL) ? "(null)" : m->owner->parent.name,
m->hold,
m->priority,
rt_list_len(&m->parent.suspend_thread));
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_MUTEX */
#ifdef RT_USING_MAILBOX
long list_mailbox(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "mailbox";
list_find_init(&find_arg, RT_Object_Class_MailBox, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s entry size suspend thread\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---- ---- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_mailbox *m;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
m = (struct rt_mailbox *)obj;
if (!rt_list_isempty(&m->parent.suspend_thread))
{
rt_kprintf("%-*.*s %04d %04d %d:",
maxlen, RT_NAME_MAX,
m->parent.parent.name,
m->entry,
m->size,
rt_list_len(&m->parent.suspend_thread));
rt_susp_list_print(&(m->parent.suspend_thread));
rt_kprintf("\n");
}
else
{
rt_kprintf("%-*.*s %04d %04d %d\n",
maxlen, RT_NAME_MAX,
m->parent.parent.name,
m->entry,
m->size,
rt_list_len(&m->parent.suspend_thread));
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_MAILBOX */
#ifdef RT_USING_MESSAGEQUEUE
long list_msgqueue(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "msgqueue";
list_find_init(&find_arg, RT_Object_Class_MessageQueue, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s entry suspend thread\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_messagequeue *m;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
m = (struct rt_messagequeue *)obj;
if (!rt_list_isempty(&m->parent.suspend_thread))
{
rt_kprintf("%-*.*s %04d %d:",
maxlen, RT_NAME_MAX,
m->parent.parent.name,
m->entry,
rt_list_len(&m->parent.suspend_thread));
rt_susp_list_print(&(m->parent.suspend_thread));
rt_kprintf("\n");
}
else
{
rt_kprintf("%-*.*s %04d %d\n",
maxlen, RT_NAME_MAX,
m->parent.parent.name,
m->entry,
rt_list_len(&m->parent.suspend_thread));
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_MESSAGEQUEUE */
#ifdef RT_USING_MEMHEAP
long list_memheap(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "memheap";
list_find_init(&find_arg, RT_Object_Class_MemHeap, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s pool size max used size available size\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---------- ------------- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_memheap *mh;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
mh = (struct rt_memheap *)obj;
rt_kprintf("%-*.*s %-010d %-013d %-05d\n",
maxlen, RT_NAME_MAX,
mh->parent.name,
mh->pool_size,
mh->max_used_size,
mh->available_size);
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_MEMHEAP */
#ifdef RT_USING_MEMPOOL
long list_mempool(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "mempool";
list_find_init(&find_arg, RT_Object_Class_MemPool, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s block total free suspend thread\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---- ---- ---- --------------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_mempool *mp;
int suspend_thread_count;
rt_list_t *node;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
mp = (struct rt_mempool *)obj;
suspend_thread_count = 0;
rt_list_for_each(node, &mp->suspend_thread)
{
suspend_thread_count++;
}
if (suspend_thread_count > 0)
{
rt_kprintf("%-*.*s %04d %04d %04d %d:",
maxlen, RT_NAME_MAX,
mp->parent.name,
mp->block_size,
mp->block_total_count,
mp->block_free_count,
suspend_thread_count);
rt_susp_list_print(&(mp->suspend_thread));
rt_kprintf("\n");
}
else
{
rt_kprintf("%-*.*s %04d %04d %04d %d\n",
maxlen, RT_NAME_MAX,
mp->parent.name,
mp->block_size,
mp->block_total_count,
mp->block_free_count,
suspend_thread_count);
}
}
}
}
while (next != (rt_list_t *)RT_NULL);
return 0;
}
#endif /* RT_USING_MEMPOOL */
long list_timer(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
int maxlen;
const char *item_title = "timer";
list_find_init(&find_arg, RT_Object_Class_Timer, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s periodic timeout activated mode\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" ---------- ---------- ----------- ---------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_timer *timer;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
timer = (struct rt_timer *)obj;
rt_kprintf("%-*.*s 0x%08x 0x%08x ",
maxlen, RT_NAME_MAX,
timer->parent.name,
timer->init_tick,
timer->timeout_tick);
if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)
rt_kprintf("activated ");
else
rt_kprintf("deactivated ");
if (timer->parent.flag & RT_TIMER_FLAG_PERIODIC)
rt_kprintf("periodic\n");
else
rt_kprintf("one shot\n");
}
}
}
while (next != (rt_list_t *)RT_NULL);
rt_kprintf("current tick:0x%08x\n", rt_tick_get());
return 0;
}
#ifdef RT_USING_DEVICE
static char *const device_type_str[RT_Device_Class_Unknown] =
{
"Character Device",
"Block Device",
"Network Interface",
"MTD Device",
"CAN Device",
"RTC",
"Sound Device",
"Graphic Device",
"I2C Bus",
"USB Slave Device",
"USB Host Bus",
"USB OTG Bus",
"SPI Bus",
"SPI Device",
"SDIO Bus",
"PM Pseudo Device",
"Pipe",
"Portal Device",
"Timer Device",
"Miscellaneous Device",
"Sensor Device",
"Touch Device",
"Phy Device",
"Security Device",
"WLAN Device",
"Pin Device",
"ADC Device",
"DAC Device",
"WDT Device",
"PWM Device",
"Bus Device",
};
long list_device(void)
{
rt_base_t level;
list_get_next_t find_arg;
struct rt_object_information *info;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
const char *device_type;
int maxlen;
const char *item_title = "device";
list_find_init(&find_arg, RT_Object_Class_Device, obj_list, sizeof(obj_list) / sizeof(obj_list[0]));
info = rt_list_entry(find_arg.list, struct rt_object_information, object_list);
maxlen = RT_NAME_MAX;
rt_kprintf("%-*.*s type ref count\n", maxlen, maxlen, item_title);
object_split(maxlen);
rt_kprintf(" -------------------- ----------\n");
do
{
next = list_get_next(next, &find_arg);
{
int i;
for (i = 0; i < find_arg.nr_out; i++)
{
struct rt_object *obj;
struct rt_device *device;
obj = rt_list_entry(obj_list[i], struct rt_object, list);
level = rt_spin_lock_irqsave(&info->spinlock);
if ((obj->type & ~RT_Object_Class_Static) != find_arg.type)
{
rt_spin_unlock_irqrestore(&info->spinlock, level);
continue;
}
rt_spin_unlock_irqrestore(&info->spinlock, level);
device = (struct rt_device *)obj;
device_type = "Unknown";
if (device->type < RT_Device_Class_Unknown &&
device_type_str[device->type] != RT_NULL)
{
device_type = device_type_str[device->type];
}
rt_kprintf("%-*.*s %-20s %-8d\n",
maxlen, RT_NAME_MAX,
device->parent.name,
device_type,
device->ref_count);
}