huangcm
2025-04-07 511b111543524704f6182b374e489f5d0e51db8c
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
// SPDX-License-Identifier: GPL-2.0+
/*
 * (C) Copyright 2018-2020
 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
 * wangwei <wangwei@allwinnertech.com>
 *
 */
 
#include <common.h>
#include <config.h>
#include <command.h>
#include <asm/arch/timer.h>
 
DECLARE_GLOBAL_DATA_PTR;
 
 
struct timer_list timer0_t;
struct timer_list timer1_t;
static int timer_test_flag[2];
 
 
static  void  timer0_test_func(void *p)
{
   struct timer_list *timer_t;
 
   timer_t = (struct timer_list *)p;
   debug("timer number = %d\n", timer_t->timer_num);
   printf("this is timer test\n");
 
   del_timer(timer_t);
   timer_test_flag[0] = 0;
 
   return;
}
 
int do_timer_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
   int  base_count = 1000;
 
   if(timer_test_flag[0])
   {
       printf("can not test timer 0 now\n");
 
       return -1;
   }
 
   if(argc == 2)
   {
       base_count = simple_strtol(argv[1], NULL, 10);
   }
   timer0_t.data = (unsigned long)&timer0_t;
   timer0_t.expires = base_count;
   timer0_t.function = timer0_test_func;
 
   init_timer(&timer0_t);
   add_timer(&timer0_t);
   timer_test_flag[0] = 1;
 
   return 0;
}
 
 
U_BOOT_CMD(
   timer_test, 2, 0, do_timer_test,
   "do a timer and int test",
   "[delay time]"
);
 
static  void  timer1_test_func(void *p)
{
   struct timer_list *timer_t;
 
   timer_t = (struct timer_list *)p;
   debug("timer number = %d\n", timer_t->timer_num);
   printf("this is timer test\n");
 
   del_timer(timer_t);
   timer_test_flag[1] = 0;
 
   return;
}
 
 
int do_timer_test1(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
   int  base_count = 1000;
 
   if(timer_test_flag[1])
   {
       printf("can not test timer 1 now\n");
 
       return -1;
   }
 
   if(argc == 2)
   {
       base_count = simple_strtol(argv[1], NULL, 10);
   }
   timer1_t.data = (unsigned long)&timer1_t;
   timer1_t.expires = base_count;
   timer1_t.function = timer1_test_func;
 
   init_timer(&timer1_t);
   add_timer(&timer1_t);
 
   timer_test_flag[1] = 1;
 
   return 0;
}
 
 
U_BOOT_CMD(
   timer_test1, 2, 0, do_timer_test1,
   "do a timer and int test",
   "[delay time]"
);