求助一下,我在调试社区代码里面的hwtimer_test时,遇到了一个很奇怪的问题:
进入MSH后,首次运行hwtimer_test时正常的,用例中的rt_thread_delay能够正常的delay延迟。但是当我第二次运行时,发现rt_thread_delay不能延时了。后面通过debug发现,在系统刚启动时查看list_thread状态,显示由tshell和idle线程,其中tshell是running状态,idle为ready状态,是正常的。在运行一次hwtimer命令后,再去查看list_thread发现idle线程状态有异常,idle被close掉了,并且线程的name也变化了。怀疑是踩内存了。但是目前我对这个问题没有了进一步的思路,发出来大家看下有没有什么思路能够提供给我的。。。下图是log
hwtimer_test代码如下:
rt-thread/examples/test/hwtimer_test.c
@cndabai
cndabai Remove C Style Command Shell
Latest commit 221da7f on 23 Aug
History
3 contributors
@heyuanjie87@mysterywolf@cndabai
111 lines (93 sloc) 2.71 KB
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <finsh.h>
#ifdef RT_USING_HWTIMER
#define TIMER "timer0"
static rt_err_t timer_timeout_cb(rt_device_t dev, rt_size_t size)
{
rt_kprintf("enter hardware timer isr\n");
return 0;
}
int hwtimer(void)
{
rt_err_t err;
rt_hwtimerval_t val;
rt_device_t dev = RT_NULL;
rt_tick_t tick;
rt_hwtimer_mode_t mode;
int freq = 10000;
int t = 5;
if ((dev = rt_device_find(TIMER)) == RT_NULL)
{
rt_kprintf("No Device: %s\n", TIMER);
return -1;
}
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
{
rt_kprintf("Open %s Fail\n", TIMER);
return -1;
}
/* 时间测量 */
/* 计数时钟设置(默认1Mhz或支持的最小计数频率) */
err = rt_device_control(dev, HWTIMER_CTRL_FREQ_SET, &freq);
if (err != RT_EOK)
{
rt_kprintf("Set Freq=%dhz Fail\n", freq);
goto EXIT;
}
/* 周期模式 */
mode = HWTIMER_MODE_PERIOD;
err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode);
tick = rt_tick_get();
rt_kprintf("Start Timer> Tick: %d\n", tick);
/* 设置定时器超时值并启动定时器 */
val.sec = t;
val.usec = 0;
rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec);
if (rt_device_write(dev, 0, &val, sizeof(val)) != sizeof(val))
{
rt_kprintf("SetTime Fail\n");
goto EXIT;
}
rt_kprintf("Sleep %d sec\n", t);
rt_thread_delay(t*RT_TICK_PER_SECOND);
/* 停止定时器 */
err = rt_device_control(dev, HWTIMER_CTRL_STOP, RT_NULL);
rt_kprintf("Timer Stoped\n");
/* 读取计数 */
rt_device_read(dev, 0, &val, sizeof(val));
rt_kprintf("Read: Sec = %d, Usec = %d\n", val.sec, val.usec);
/* 定时执行回调函数 -- 单次模式 */
/* 设置超时回调函数 */
rt_device_set_rx_indicate(dev, timer_timeout_cb);
/* 单次模式 */
mode = HWTIMER_MODE_PERIOD;
err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode);
/* 设置定时器超时值并启动定时器 */
val.sec = t;
val.usec = 0;
rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec);
if (rt_device_write(dev, 0, &val, sizeof(val)) != sizeof(val))
{
rt_kprintf("SetTime Fail\n");
goto EXIT;
}
/* 等待回调函数执行 */
rt_thread_delay((t + 1)*RT_TICK_PER_SECOND);
EXIT:
err = rt_device_close(dev);
rt_kprintf("Close %s\n", TIMER);
return err;
}
#ifdef RT_USING_FINSH
MSH_CMD_EXPORT(hwtimer, "Test hardware timer");
#endif
#endif /* RT_USING_HWTIMER */
© 2021 GitHub, Inc.
Terms
Privacy
Security
Status
Docs
Contact GitHub
Pricing
API
Training
Blog
About
Loading complete