summaryrefslogtreecommitdiff
path: root/examples/kernel/timer_timeout.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/kernel/timer_timeout.c')
-rw-r--r--examples/kernel/timer_timeout.c122
1 files changed, 61 insertions, 61 deletions
diff --git a/examples/kernel/timer_timeout.c b/examples/kernel/timer_timeout.c
index 80241e53f2..d1a7099e2e 100644
--- a/examples/kernel/timer_timeout.c
+++ b/examples/kernel/timer_timeout.c
@@ -20,94 +20,94 @@ static struct rt_timer timer;
static rt_uint16_t no = 0;
static void timer_timeout(void* parameter)
{
- char buf[32];
- rt_uint32_t length;
+ char buf[32];
+ rt_uint32_t length;
- length = rt_snprintf(buf, sizeof(buf), "message %d", no++);
- rt_mq_send(&mq, &buf[0], length);
+ length = rt_snprintf(buf, sizeof(buf), "message %d", no++);
+ rt_mq_send(&mq, &buf[0], length);
}
/* �߳���ں��� */
static void thread_entry(void* parameter)
{
- char buf[64];
- rt_err_t result;
+ char buf[64];
+ rt_err_t result;
- /* ��ʼ����ʱ�� */
- rt_timer_init(&timer, "timer", /* ��ʱ�������� timer1 */
- timer_timeout, /* ��ʱʱ�ص��Ĵ������� */
- RT_NULL, /* ��ʱ��������ڲ��� */
- 1, /* ��ʱ���ȣ���OS TickΪ��λ����1��OS Tick */
- RT_TIMER_FLAG_PERIODIC); /* �����Զ�ʱ�� */
+ /* ��ʼ����ʱ�� */
+ rt_timer_init(&timer, "timer", /* ��ʱ�������� timer1 */
+ timer_timeout, /* ��ʱʱ�ص��Ĵ������� */
+ RT_NULL, /* ��ʱ��������ڲ��� */
+ 1, /* ��ʱ���ȣ���OS TickΪ��λ����1��OS Tick */
+ RT_TIMER_FLAG_PERIODIC); /* �����Զ�ʱ�� */
- while (1)
- {
- rt_memset(&buf[0], 0, sizeof(buf));
+ while (1)
+ {
+ rt_memset(&buf[0], 0, sizeof(buf));
- /* ����Ϣ�����н�����Ϣ */
- result = rt_mq_recv(&mq, &buf[0], sizeof(buf), 1);
- if (result == RT_EOK)
- {
- rt_kprintf("recv msg: %s\n", buf);
- }
- else if (result == -RT_ETIMEOUT)
- {
- rt_kprintf("recv msg timeout\n");
- }
- }
+ /* ����Ϣ�����н�����Ϣ */
+ result = rt_mq_recv(&mq, &buf[0], sizeof(buf), 1);
+ if (result == RT_EOK)
+ {
+ rt_kprintf("recv msg: %s\n", buf);
+ }
+ else if (result == -RT_ETIMEOUT)
+ {
+ rt_kprintf("recv msg timeout\n");
+ }
+ }
}
int timer_timeout_init()
{
- /* ��ʼ����Ϣ���� */
- rt_mq_init(&mq, "mqt",
- &msg_pool[0], /* �ڴ��ָ��msg_pool */
- 128 - sizeof(void*), /* ÿ����Ϣ�Ĵ�С�� 128 - void* */
- sizeof(msg_pool), /* �ڴ�صĴ�С��msg_pool�Ĵ�С */
- RT_IPC_FLAG_FIFO); /* ����ж���̵߳ȴ������������ȵõ��ķ���������Ϣ */
+ /* ��ʼ����Ϣ���� */
+ rt_mq_init(&mq, "mqt",
+ &msg_pool[0], /* �ڴ��ָ��msg_pool */
+ 128 - sizeof(void*), /* ÿ����Ϣ�Ĵ�С�� 128 - void* */
+ sizeof(msg_pool), /* �ڴ�صĴ�С��msg_pool�Ĵ�С */
+ RT_IPC_FLAG_FIFO); /* ����ж���̵߳ȴ������������ȵõ��ķ���������Ϣ */
- /* �����߳� */
- tid = rt_thread_create("t",
- thread_entry, RT_NULL, /* �߳������thread_entry, ��ڲ�����RT_NULL */
- THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
- if (tid != RT_NULL)
- rt_thread_startup(tid);
- else
- tc_stat(TC_STAT_END | TC_STAT_FAILED);
+ /* �����߳� */
+ tid = rt_thread_create("t",
+ thread_entry, RT_NULL, /* �߳������thread_entry, ��ڲ�����RT_NULL */
+ THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
+ if (tid != RT_NULL)
+ rt_thread_startup(tid);
+ else
+ tc_stat(TC_STAT_END | TC_STAT_FAILED);
- return 0;
+ return 0;
}
#ifdef RT_USING_TC
static void _tc_cleanup()
{
- /* �����������������󣬽������л��������̣߳�����Ӧ�ж� */
- rt_enter_critical();
+ /* �����������������󣬽������л��������̣߳�����Ӧ�ж� */
+ rt_enter_critical();
- /* ɾ���߳� */
- if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
- rt_thread_delete(tid);
+ /* ɾ���߳� */
+ if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE)
+ rt_thread_delete(tid);
- /* ִ����Ϣ���ж������� */
- rt_mq_detach(&mq);
- /* ִ�ж�ʱ������ */
- rt_timer_detach(&timer);
+ /* ִ����Ϣ���ж������� */
+ rt_mq_detach(&mq);
+ /* ִ�ж�ʱ������ */
+ rt_timer_detach(&timer);
- /* ���������� */
- rt_exit_critical();
+ /* ���������� */
+ rt_exit_critical();
- /* ����TestCase״̬ */
- tc_done(TC_STAT_PASSED);
+ /* ����TestCase״̬ */
+ tc_done(TC_STAT_PASSED);
}
int _tc_timer_timeout()
{
- /* ����TestCase�����ص����� */
- tc_cleanup(_tc_cleanup);
- timer_timeout_init();
+ /* ����TestCase�����ص����� */
+ tc_cleanup(_tc_cleanup);
+ timer_timeout_init();
- /* ����TestCase���е��ʱ�� */
- return 100;
+ /* ����TestCase���е��ʱ�� */
+ return 100;
}
/* ����������finsh shell�� */
FINSH_FUNCTION_EXPORT(_tc_timer_timeout, a thread timer testcase);
@@ -115,8 +115,8 @@ FINSH_FUNCTION_EXPORT(_tc_timer_timeout, a thread timer testcase);
/* �û�Ӧ����� */
int rt_application_init()
{
- timer_timeout_init();
+ timer_timeout_init();
- return 0;
+ return 0;
}
#endif