1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date        Author    Email                    Notes
8  * 2022-04-16  Kevin.Liu kevin.liu.mchp@gmail.com First Release
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 "atmel_start.h"
19 #include <hal_gpio.h>
20 
21 #ifdef SAM_CAN_EXAMPLE
22 #include "can_demo.h"
23 #endif
24 
25 #ifdef SAM_I2C_EXAMPLE
26 #include "i2c_demo.h"
27 #endif
28 
29 #ifdef SAM_ADC_EXAMPLE
30 #include "adc_demo.h"
31 #endif
32 
33 static rt_uint8_t led_stack[ 512 ];
34 static struct rt_thread led_thread;
35 
led_thread_entry(void * parameter)36 static void led_thread_entry(void* parameter)
37 {
38     unsigned int count=0;
39 
40     while (1)
41     {
42         /* toggle led */
43 #ifndef RT_USING_FINSH
44         rt_kprintf("led toggle, count : %d\r\n",count);
45 #endif
46         count++;
47         gpio_toggle_pin_level(LED0);
48         rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
49     }
50 }
51 
main(void)52 int main(void)
53 {
54     rt_err_t result;
55 
56     /* initialize led thread */
57     result = rt_thread_init(&led_thread,
58                             "led",
59                             led_thread_entry,
60                             RT_NULL,
61                             (rt_uint8_t*)&led_stack[0],
62                             sizeof(led_stack),
63                             RT_THREAD_PRIORITY_MAX/3,
64                             5);
65     if (result == RT_EOK)
66     {
67         rt_thread_startup(&led_thread);
68     }
69 
70 #ifdef SAM_CAN_EXAMPLE
71     can_demo_run();
72 #endif
73 
74 #ifdef SAM_I2C_EXAMPLE
75     i2c_demo_run();
76 #endif
77 
78 #ifdef SAM_ADC_EXAMPLE
79     adc_demo_run();
80 #endif
81 
82     return 0;
83 }
84 
85 /*@}*/
86