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_I2C_EXAMPLE
22 #include "i2c_demo.h"
23 #endif
24
25 #ifdef SAM_ADC_EXAMPLE
26 #include "adc_demo.h"
27 #endif
28
29 static rt_uint8_t led_stack[ 512 ];
30 static struct rt_thread led_thread;
31
led_thread_entry(void * parameter)32 static void led_thread_entry(void* parameter)
33 {
34 unsigned int count=0;
35
36 while (1)
37 {
38 /* toggle led */
39 #ifndef RT_USING_FINSH
40 rt_kprintf("led toggle, count : %d\r\n",count);
41 #endif
42 count++;
43 gpio_toggle_pin_level(LED0);
44 rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
45 }
46 }
47
main(void)48 int main(void)
49 {
50 rt_err_t result;
51
52 /* initialize led thread */
53 result = rt_thread_init(&led_thread,
54 "led",
55 led_thread_entry,
56 RT_NULL,
57 (rt_uint8_t*)&led_stack[0],
58 sizeof(led_stack),
59 RT_THREAD_PRIORITY_MAX/3,
60 5);
61 if (result == RT_EOK)
62 {
63 rt_thread_startup(&led_thread);
64 }
65
66 #ifdef SAM_I2C_EXAMPLE
67 i2c_demo_run();
68 #endif
69
70 #ifdef SAM_ADC_EXAMPLE
71 adc_demo_run();
72 #endif
73
74 return 0;
75 }
76
77 /*@}*/
78