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  * 2009-01-05     Bernard      the first version
9  * 2014-04-27     Bernard      make code cleanup.
10  */
11 
12 #include <board.h>
13 #include <rtthread.h>
14 
15 #include "peri_driver.h"
16 
17 #define INIT_STACK_SIZE     512
18 #define LED_STACK_SIZE      256
19 
20 #ifndef RT_USING_HEAP
21 /* if there is not enable heap, we should use static thread and stack. */
22 
23 rt_align(8)
24 static rt_uint8_t led_stack[LED_STACK_SIZE];
25 static struct rt_thread led_thread;
26 #endif
27 
28 static int led_app();
29 
main(void)30 int main(void)
31 {
32     rt_kprintf("Hello RT-Thread!\n");
33 
34     while(1)
35     {
36         rt_thread_mdelay(1000);
37     }
38 
39     return 0;
40 }
41 
42 /*******************************************************************************
43 * Function Name  : assert_failed
44 * Description    : Reports the name of the source file and the source line number
45 *                  where the assert error has occurred.
46 * Input          : - file: pointer to the source file name
47 *                  - line: assert error line source number
48 * Output         : None
49 * Return         : None
50 *******************************************************************************/
assert_failed(uint8_t * file,uint32_t line)51 void assert_failed(uint8_t* file, uint32_t line)
52 {
53     rt_kprintf("\n\r Wrong parameter value detected on\r\n");
54     rt_kprintf("       file  %s\r\n", file);
55     rt_kprintf("       line  %d\r\n", line);
56 
57     while (1) ;
58 }
59 
rt_led_thread_entry(void * parameter)60 void rt_led_thread_entry(void *parameter)
61 {
62     /* Initialize GPIO */
63     Chip_GPIO_Init(LPC_GPIO_PORT);
64     Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 7, 1);
65     Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true);
66 
67     while (1)
68     {
69         Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, true);
70         rt_thread_delay(RT_TICK_PER_SECOND / 2);
71 
72         Chip_GPIO_PinSetState(LPC_GPIO_PORT, 0, 7, false);
73         rt_thread_delay(RT_TICK_PER_SECOND / 2);
74     }
75 }
76 
led_app()77 static int led_app()
78 {
79     rt_thread_t tid;
80 
81 #ifdef RT_USING_HEAP
82     tid = rt_thread_create("led",
83         rt_led_thread_entry, RT_NULL,
84         LED_STACK_SIZE, RT_THREAD_PRIORITY_MAX/3, 20);
85 #else
86     {
87 
88         rt_err_t result;
89 
90         tid = &led_thread;
91         result = rt_thread_init(tid, "led", rt_led_thread_entry, RT_NULL,
92                                 led_stack, sizeof(led_stack), RT_THREAD_PRIORITY_MAX / 4, 20);
93         RT_ASSERT(result == RT_EOK);
94     }
95 #endif
96     if (tid != RT_NULL)
97         rt_thread_startup(tid);
98 
99     return 0;
100 }
101