SmartAudio/lichee/brandy/u-boot-2014.07/common/cmd_sunxi_timer.c

127 lines
2.1 KiB
C

#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];
int do_delay_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
tick_printf("delay 1000ms\n");
__msdelay(1000);
tick_printf("delay test end\n");
tick_printf("delay 1000ms\n");
__usdelay(1000 * 1000);
tick_printf("delay test end\n");
return 0;
}
U_BOOT_CMD(
delay_test, 2, 0, do_delay_test,
"do a delay test",
"NULL"
);
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]"
);