rt-thread/bsp/lpc178x/applications/application.c

190 lines
4.0 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
2021-03-17 02:26:35 +08:00
* Copyright (c) 2006-2021, RT-Thread Development Team
2013-01-08 22:40:58 +08:00
*
* SPDX-License-Identifier: Apache-2.0
2013-01-08 22:40:58 +08:00
*
* Change Logs:
* Date Author Notes
* 2010-05-02 Aozima add led function
*/
#include <rtthread.h>
#include <board.h>
#ifdef RT_USING_DFS
/* dfs init */
2017-10-31 16:20:02 +08:00
#include <dfs.h>
2013-01-08 22:40:58 +08:00
/* dfs filesystem:ELM FatFs filesystem init */
#include <dfs_elm.h>
/* dfs Filesystem APIs */
#include <dfs_fs.h>
#endif
#ifdef RT_USING_LWIP
#include <lwip/sys.h>
#include <lwip/api.h>
#include <netif/ethernetif.h>
#endif
#ifdef RT_USING_RTGUI
#include <rtgui/driver.h>
#endif
#ifdef RT_USING_FINSH
#include <shell.h>
#include <finsh.h>
#endif
2013-01-08 22:40:58 +08:00
/* thread phase init */
void rt_init_thread_entry(void *parameter)
{
/* Filesystem Initialization */
#ifdef RT_USING_DFS
{
/* init the device filesystem */
dfs_init();
/* init the elm FAT filesystam*/
elm_init();
/* mount sd card fat partition 1 as root directory */
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
rt_kprintf("File System initialized!\n");
else
rt_kprintf("File System init failed!\n");
}
#endif
/* LwIP Initialization */
#ifdef RT_USING_LWIP
{
extern void lwip_sys_init(void);
extern void lpc17xx_emac_hw_init(void);
eth_system_device_init();
/* register ethernetif device */
lpc17xx_emac_hw_init();
/* init lwip system */
lwip_sys_init();
rt_kprintf("TCP/IP initialized!\n");
}
#endif
#ifdef RT_USING_RTGUI
{
2021-03-17 02:26:35 +08:00
extern void rtgui_system_server_init(void);
extern void application_init(void);
2021-03-17 02:26:35 +08:00
rt_device_t lcd;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* init lcd */
rt_hw_lcd_init();
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* find lcd device */
lcd = rt_device_find("lcd");
if (lcd != RT_NULL)
{
/* set lcd device as rtgui graphic driver */
rtgui_graphic_set_device(lcd);
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* init rtgui system server */
rtgui_system_server_init();
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
/* startup rtgui in demo of RT-Thread/GUI examples */
application_init();
}
2013-01-08 22:40:58 +08:00
}
#endif
#ifdef RT_USING_FINSH
2021-03-17 02:26:35 +08:00
/* initialize finsh */
finsh_system_init();
#endif
2013-01-08 22:40:58 +08:00
}
// init led
#define rt_hw_led_init() LPC_GPIO2->DIR |= 1<<25;
// trun on led n
#define rt_hw_led_on(n) LPC_GPIO2->CLR |= 1<<25;
// trun off led n
#define rt_hw_led_off(n) LPC_GPIO2->SET |= 1<<25;
rt_align(RT_ALIGN_SIZE)
2013-01-08 22:40:58 +08:00
static char thread_led_stack[1024];
struct rt_thread thread_led;
static void rt_thread_entry_led(void* parameter)
{
unsigned int count=0;
rt_hw_led_init();
while (1)
{
/* led on */
#ifndef RT_USING_FINSH
rt_kprintf("led on,count : %d\r\n",count);
#endif
count++;
rt_hw_led_on(1);
/* sleep 0.5 second and switch to other thread */
rt_thread_delay(RT_TICK_PER_SECOND/2);
/* led off */
#ifndef RT_USING_FINSH
rt_kprintf("led off\r\n");
#endif
rt_hw_led_off(1);
rt_thread_delay(RT_TICK_PER_SECOND/2);
}
}
int rt_application_init(void)
{
2021-03-17 02:26:35 +08:00
rt_thread_t tid;
rt_thread_init(&thread_led,
"led",
rt_thread_entry_led,
RT_NULL,
&thread_led_stack[0],
sizeof(thread_led_stack),11,5);
rt_thread_startup(&thread_led);
tid = rt_thread_create("init",
rt_init_thread_entry, RT_NULL,
2048, RT_THREAD_PRIORITY_MAX/3, 20);
if (tid != RT_NULL) rt_thread_startup(tid);
return 0;
2013-01-08 22:40:58 +08:00
}
#if defined(RT_USING_RTGUI) && defined(RT_USING_FINSH)
#include <rtgui/rtgui_server.h>
#include <rtgui/event.h>
#include <rtgui/kbddef.h>
#include <finsh.h>
void key(rt_uint32_t key)
{
2021-03-17 02:26:35 +08:00
struct rtgui_event_kbd ekbd;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
RTGUI_EVENT_KBD_INIT(&ekbd);
ekbd.mod = RTGUI_KMOD_NONE;
ekbd.unicode = 0;
ekbd.key = key;
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
ekbd.type = RTGUI_KEYDOWN;
rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd));
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
rt_thread_delay(2);
2013-01-08 22:40:58 +08:00
2021-03-17 02:26:35 +08:00
ekbd.type = RTGUI_KEYUP;
rtgui_server_post_event((struct rtgui_event*)&ekbd, sizeof(ekbd));
2013-01-08 22:40:58 +08:00
}
FINSH_FUNCTION_EXPORT(key, send a key to gui server);
#endif