2012-12-17 16:21:29 +08:00
|
|
|
/*
|
2021-04-09 10:52:34 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2012-12-17 16:21:29 +08:00
|
|
|
*
|
2021-04-09 10:52:34 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2012-12-17 16:21:29 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2014-07-13 15:17:26 +08:00
|
|
|
* 2014-07-13 xiaonong port for lpc43xx
|
2012-12-17 16:21:29 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2014-07-13 15:17:26 +08:00
|
|
|
#include <board.h>
|
|
|
|
#include <rtdevice.h>
|
|
|
|
#include "drv_led.h"
|
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
|
|
|
#include <shell.h>
|
2012-12-17 16:21:29 +08:00
|
|
|
#endif
|
|
|
|
|
2014-07-13 15:17:26 +08:00
|
|
|
/* thread phase init */
|
|
|
|
void rt_init_thread_entry(void *parameter)
|
2012-12-17 16:21:29 +08:00
|
|
|
{
|
2014-07-13 15:17:26 +08:00
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
/* initialize finsh */
|
|
|
|
finsh_system_init();
|
|
|
|
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
|
2012-12-17 16:21:29 +08:00
|
|
|
#endif
|
2014-07-13 15:17:26 +08:00
|
|
|
}
|
|
|
|
/*the led thread*/
|
|
|
|
ALIGN(RT_ALIGN_SIZE)
|
|
|
|
static rt_uint8_t led_stack[ 512 ];
|
|
|
|
static struct rt_thread led_thread;
|
|
|
|
static void led_thread_entry(void *parameter)
|
|
|
|
{
|
|
|
|
rt_uint8_t led_value = 0;
|
|
|
|
rt_device_t led_dev;
|
|
|
|
rt_led_hw_init();
|
|
|
|
led_dev = rt_device_find("led");
|
|
|
|
if (led_dev == RT_NULL)
|
|
|
|
{
|
|
|
|
rt_kprintf("can not find the led device!\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-12-17 16:21:29 +08:00
|
|
|
while (1)
|
|
|
|
{
|
2014-07-13 15:17:26 +08:00
|
|
|
/* led0 on */
|
|
|
|
led_value = 1;
|
|
|
|
led_dev->write(led_dev, 0, &led_value, 1);
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */
|
|
|
|
|
|
|
|
/* led0 off */
|
|
|
|
led_value = 0;
|
|
|
|
led_dev->write(led_dev, 0, &led_value, 1);
|
|
|
|
rt_thread_delay(RT_TICK_PER_SECOND / 2);
|
2012-12-17 16:21:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-13 15:17:26 +08:00
|
|
|
int rt_application_init(void)
|
2012-12-17 16:21:29 +08:00
|
|
|
{
|
|
|
|
rt_thread_t tid;
|
2014-07-13 15:17:26 +08:00
|
|
|
rt_err_t result;
|
2012-12-17 16:21:29 +08:00
|
|
|
tid = rt_thread_create("init",
|
2014-07-13 15:17:26 +08:00
|
|
|
rt_init_thread_entry, RT_NULL,
|
|
|
|
2048, RT_THREAD_PRIORITY_MAX / 3, 20);
|
|
|
|
if (tid != RT_NULL) rt_thread_startup(tid);
|
|
|
|
/* init led thread */
|
|
|
|
result = rt_thread_init(&led_thread,
|
|
|
|
"led",
|
|
|
|
led_thread_entry,
|
|
|
|
RT_NULL,
|
|
|
|
(rt_uint8_t *)&led_stack[0],
|
|
|
|
sizeof(led_stack),
|
|
|
|
20,
|
|
|
|
5);
|
|
|
|
if (result == RT_EOK)
|
|
|
|
{
|
|
|
|
rt_thread_startup(&led_thread);
|
|
|
|
}
|
|
|
|
return 0;
|
2012-12-17 16:21:29 +08:00
|
|
|
}
|