Skip to content

Commit ebc14b0

Browse files
committed
[example] Sync to latest version.
1 parent 77623e8 commit ebc14b0

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

examples/pm/timer_app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int timer_app_init(void)
4848
return -1;
4949
}
5050
}
51-
INIT_EXPORT_APP(timer_app_init);
51+
INIT_APP_EXPORT(timer_app_init);
5252

5353
#endif /* RT_USING_PM */
5454

examples/test/hwtimer_test.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
static rt_err_t timer_timeout_cb(rt_device_t dev, rt_size_t size)
1010
{
11-
rt_kprintf("HT %d\n", rt_tick_get());
11+
rt_kprintf("enter hardware timer isr\n");
1212

1313
return 0;
1414
}
@@ -35,7 +35,7 @@ int hwtimer(void)
3535
return -1;
3636
}
3737

38-
rt_device_set_rx_indicate(dev, timer_timeout_cb);
38+
/* 时间测量 */
3939
/* 计数时钟设置(默认1Mhz或支持的最小计数频率) */
4040
err = rt_device_control(dev, HWTIMER_CTRL_FREQ_SET, &freq);
4141
if (err != RT_EOK)
@@ -69,12 +69,34 @@ int hwtimer(void)
6969
rt_device_read(dev, 0, &val, sizeof(val));
7070
rt_kprintf("Read: Sec = %d, Usec = %d\n", val.sec, val.usec);
7171

72+
/* 定时执行回调函数 -- 单次模式 */
73+
/* 设置超时回调函数 */
74+
rt_device_set_rx_indicate(dev, timer_timeout_cb);
75+
76+
/* 单次模式 */
77+
mode = HWTIMER_MODE_PERIOD;
78+
err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode);
79+
80+
/* 设置定时器超时值并启动定时器 */
81+
val.sec = t;
82+
val.usec = 0;
83+
rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec);
84+
if (rt_device_write(dev, 0, &val, sizeof(val)) != sizeof(val))
85+
{
86+
rt_kprintf("SetTime Fail\n");
87+
goto EXIT;
88+
}
89+
90+
/* 等待回调函数执行 */
91+
rt_thread_delay((t + 1)*RT_TICK_PER_SECOND);
92+
7293
EXIT:
7394
err = rt_device_close(dev);
7495
rt_kprintf("Close %s\n", TIMER);
7596

7697
return err;
7798
}
78-
79-
FINSH_FUNCTION_EXPORT(hwtimer, "Test hardware timer");
99+
#ifdef FINSH_USING_MSH
100+
MSH_CMD_EXPORT(hwtimer, "Test hardware timer");
80101
#endif
102+
#endif /* RT_USING_HWTIMER */

include/rtdef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef rt_base_t rt_off_t; /**< Type for offset */
7777
#define RT_TRUE 1 /**< boolean true */
7878
#define RT_FALSE 0 /**< boolean fails */
7979

80-
/*@}*/
80+
/**@}*/
8181

8282
/* maximum value of base type */
8383
#define RT_UINT8_MAX 0xff /**< Maxium number of UINT8 */

0 commit comments

Comments
 (0)