1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2017-09-14 Haley the first version
9 */
10
11 #include <rtthread.h>
12
13 #ifdef RT_USING_FINSH
14 #include <finsh.h>
15 #include <shell.h>
16 #endif
17
18 #include "led.h"
19
20 static rt_uint8_t led_stack[ 512 ];
21 static struct rt_thread led_thread;
22
led_thread_entry(void * parameter)23 static void led_thread_entry(void* parameter)
24 {
25 unsigned int count=0;
26
27 while (1)
28 {
29 /* led1 on */
30 #ifndef RT_USING_FINSH
31 rt_kprintf("led on, count : %d\r\n",count);
32 #endif
33 count++;
34 rt_hw_led_on(0);
35 rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
36
37 /* led1 off */
38 #ifndef RT_USING_FINSH
39 rt_kprintf("led off\r\n");
40 #endif
41 rt_hw_led_off(0);
42 rt_thread_delay( RT_TICK_PER_SECOND/2 );
43 }
44 }
45
main(void)46 int main(void)
47 {
48 rt_err_t result;
49
50 /* init led thread */
51 result = rt_thread_init(&led_thread,
52 "led",
53 led_thread_entry,
54 RT_NULL,
55 (rt_uint8_t*)&led_stack[0],
56 sizeof(led_stack),
57 RT_THREAD_PRIORITY_MAX/3,
58 5);
59 if (result == RT_EOK)
60 {
61 rt_thread_startup(&led_thread);
62 }
63
64 return 0;
65 }
66
67 /*@}*/
68