application.c 5.0 KB
Newer Older
淡漠想敏's avatar
淡漠想敏 已提交
1
/*
mysterywolf's avatar
mysterywolf 已提交
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
淡漠想敏's avatar
淡漠想敏 已提交
3
 *
mysterywolf's avatar
mysterywolf 已提交
4
 * SPDX-License-Identifier: Apache-2.0
淡漠想敏's avatar
淡漠想敏 已提交
5 6 7 8 9 10 11 12
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-01-05     Bernard      the first version
 * 2013-07-12     aozima       update for auto initial.
 */

/**
mysterywolf's avatar
mysterywolf 已提交
13
 * @addtogroup
淡漠想敏's avatar
淡漠想敏 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 */
/*@{*/

#include <board.h>
#include <rtthread.h>

#ifdef RT_USING_DFS
/* dfs filesystem:ELM filesystem init */
#include <dfs_elm.h>
/* dfs Filesystem APIs */
#include <dfs_fs.h>
#endif

#ifdef RT_USING_RTGUI
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/driver.h>
#include <rtgui/calibration.h>
#endif


#ifdef RT_USING_RTGUI
rt_bool_t cali_setup(void)
{
    rt_kprintf("cali setup entered\n");
    return RT_FALSE;
}

void cali_store(struct calibration_data *data)
{
    rt_kprintf("cali finished (%d, %d), (%d, %d)\n",
               data->min_x,
               data->max_x,
               data->min_y,
               data->max_y);
}
#endif /* RT_USING_RTGUI */

void rt_init_thread_entry(void* parameter)
{
55

淡漠想敏's avatar
淡漠想敏 已提交
56 57 58 59 60
    #ifdef RT_USING_MODULE
    rt_system_module_init();
#endif

#ifdef RT_USING_FINSH
61 62
    /* initialize finsh */
    finsh_system_init();
mysterywolf's avatar
mysterywolf 已提交
63
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
64
    finsh_set_device(RT_CONSOLE_DEVICE_NAME);
淡漠想敏's avatar
淡漠想敏 已提交
65
#endif
66
#endif
淡漠想敏's avatar
淡漠想敏 已提交
67 68

#ifdef RT_USING_LWIP
69 70 71
    /* initialize lwip stack */
    /* register ethernetif device */
    eth_system_device_init();
淡漠想敏's avatar
淡漠想敏 已提交
72

73 74 75
    /* initialize lwip system */
    lwip_system_init();
    rt_kprintf("TCP/IP initialized!\n");
淡漠想敏's avatar
淡漠想敏 已提交
76 77 78
#endif

#ifdef RT_USING_DFS
79 80
    /* initialize the device file system */
    dfs_init();
淡漠想敏's avatar
淡漠想敏 已提交
81 82

#ifdef RT_USING_DFS_ELMFAT
83 84
    /* initialize the elm chan FatFS file system*/
    elm_init();
淡漠想敏's avatar
淡漠想敏 已提交
85 86 87
#endif

#if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP)
88 89
    /* initialize NFSv3 client file system */
    nfs_init();
淡漠想敏's avatar
淡漠想敏 已提交
90 91 92
#endif

#ifdef RT_USING_DFS_YAFFS2
93
    dfs_yaffs2_init();
淡漠想敏's avatar
淡漠想敏 已提交
94 95 96
#endif

#ifdef RT_USING_DFS_UFFS
97
    dfs_uffs_init();
淡漠想敏's avatar
淡漠想敏 已提交
98 99 100
#endif

#ifdef RT_USING_DFS_JFFS2
101
    dfs_jffs2_init();
淡漠想敏's avatar
淡漠想敏 已提交
102 103 104
#endif

#ifdef RT_USING_DFS_ROMFS
105
    dfs_romfs_init();
淡漠想敏's avatar
淡漠想敏 已提交
106 107 108
#endif

#ifdef RT_USING_DFS_RAMFS
109
    dfs_ramfs_init();
淡漠想敏's avatar
淡漠想敏 已提交
110 111 112
#endif

#ifdef RT_USING_DFS_DEVFS
113
    devfs_init();
淡漠想敏's avatar
淡漠想敏 已提交
114 115 116 117
#endif
#endif /* end of RT_USING_DFS */

#ifdef RT_USING_RTGUI
118
    rtgui_system_server_init();
淡漠想敏's avatar
淡漠想敏 已提交
119 120 121
#endif

#ifdef RT_USING_USB_HOST
122
    rt_usb_host_init();
淡漠想敏's avatar
淡漠想敏 已提交
123 124 125
#endif

#ifdef  RT_USING_FINSH
mysterywolf's avatar
mysterywolf 已提交
126
#if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
淡漠想敏's avatar
淡漠想敏 已提交
127
    finsh_set_device(RT_CONSOLE_DEVICE_NAME);
128
#endif
淡漠想敏's avatar
淡漠想敏 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
#endif  /* RT_USING_FINSH */

    /* Filesystem Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
    /* 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 initialzation failed!\n");
#endif  /* RT_USING_DFS */

#ifdef RT_USING_RTGUI
    {
        extern void rt_hw_lcd_init();
        extern void rtgui_touch_hw_init(void);

        rt_device_t lcd;

        /* init lcd */
        rt_hw_lcd_init();

        /* init touch panel */
        rtgui_touch_hw_init();

        /* find lcd device */
        lcd = rt_device_find("lcd");

        /* set lcd device as rtgui graphic driver */
        rtgui_graphic_set_device(lcd);

#ifndef RT_USING_COMPONENTS_INIT
        /* init rtgui system server */
        rtgui_system_server_init();
#endif

        calibration_set_restore(cali_setup);
        calibration_set_after(cali_store);
        calibration_init();
    }
#endif /* #ifdef RT_USING_RTGUI */
}



ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t led_stack[ 512 ];
static struct rt_thread led_thread;
static void led_thread_entry(void* parameter)
{
    unsigned int count=0;

//    rt_hw_led_init();

    while (1)
    {
        /* led1 on */
#ifndef RT_USING_FINSH
        rt_kprintf("led on, count : %d\r\n",count);
#endif
        count++;

        rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */

        /* led1 off */
#ifndef RT_USING_FINSH
        rt_kprintf("led off\r\n");
#endif
        rt_thread_delay( RT_TICK_PER_SECOND/2 );
    }
}
int rt_application_init(void)
{
    rt_thread_t init_thread;
    #if 1
        rt_err_t result;
    /* 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);
    }

         #endif
#if (RT_THREAD_PRIORITY_MAX == 32)
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   1024, 8, 20);
#else
    init_thread = rt_thread_create("init",
                                   rt_init_thread_entry, RT_NULL,
                                   2048, 80, 20);
#endif

    if (init_thread != RT_NULL)
        rt_thread_startup(init_thread);

    return 0;
}

/*@}*/