application.c 3.4 KB
Newer Older
B
bernard.xiong@gmail.com 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * File      : application.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2009 - 2011, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2011-02-24     Bernard      the first version
 */

/**
 * @addtogroup FM3
 */
/*@{*/

#include <rtthread.h>
21
#include "board.h"
22 23 24 25
#include "led.h"
#include "key.h"
#include "adc.h"
#include "lcd.h"
D
dzzxzz 已提交
26
#include "cpuusage.h"
D
dzzxzz 已提交
27 28

#ifdef RT_USING_RTGUI
29
#include <rtgui/rtgui.h>
30
#include <rtgui/driver.h>
31 32
extern void rtgui_startup();
#endif
33

D
dzzxzz 已提交
34 35 36
struct rt_messagequeue mq;
static char msg_pool[2048];

37 38
void rt_init_thread_entry(void *parameter)
{
39 40
    rt_device_t lcd;  
    
D
dzzxzz 已提交
41
    rt_hw_led_init();
42 43 44
	rt_hw_key_init();
	rt_hw_adc_init();
	rt_hw_lcd_init();      
D
dzzxzz 已提交
45
	rt_hw_cpu_init();
46 47 48
    
	/* re-init device driver */
	rt_device_init_all();
D
dzzxzz 已提交
49 50
	
#ifdef RT_USING_RTGUI
51 52 53 54 55 56
	/* find lcd device */
	lcd = rt_device_find("lcd");    
    
	/* set lcd device as rtgui graphic driver */		
	rtgui_graphic_set_device(lcd);
        
57 58
	/* startup rtgui */
	rtgui_startup();
D
dzzxzz 已提交
59
#else
60
	{
D
dzzxzz 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
	char buf[20] = {'\0'};
    struct lcd_msg msg;
    rt_device_t device;   
    device = rt_device_find("lcd");
	rt_device_control(device, RT_DEVICE_CTRL_LCD_CLEAR_SCR, RT_NULL);
	x = 1;
	y = 1;
	rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "ADC"); 
	x = 1;
	y = 20;
	rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "CPU");
	x = 1;
	y = 40;
	rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, "KEY");
    
    while(1)
    {
        if (rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER) == RT_EOK)
        {
        	switch(msg.type)
    		{
    			case ADC_MSG:
					x = 40;
					y = 1;
					rt_memset(buf, 0, sizeof(buf));
					rt_sprintf(buf, "%04d", msg.adc_value);
					rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); 
					break;
				case CPU_MSG:
					x = 40;
					y = 20;
					rt_memset(buf, 0, sizeof(buf));
					rt_sprintf(buf, "%03d %03d", msg.major, msg.minor);
					rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); 
					break;
				case KEY_MSG:
					x = 40;
					y = 40;
					rt_memset(buf, 0, sizeof(buf));
                    switch(msg.key)
                	{
                		case KEY_DOWN:
							rt_sprintf(buf, "DOWN KEY ");
							break;
						case KEY_UP:
							rt_sprintf(buf, "UP KEY   ");
							break;	
                		case KEY_RIGHT:
							rt_sprintf(buf, "RIGHT KEY");
							break;
						case KEY_LEFT:
							rt_sprintf(buf, "LEFT KEY ");
							break;	
                		case KEY_ENTER:
							rt_sprintf(buf, "ENTER KEY");
							break;
						default:
							rt_sprintf(buf, "NO KEY   ");
							break;								
                	}
					rt_device_control(device, RT_DEVICE_CTRL_LCD_PUT_STRING, buf); 
                    break;                    
    		}
        }
    }
126
	}
127
#endif
128
}
B
bernard.xiong@gmail.com 已提交
129 130 131

int rt_application_init()
{
132 133
    rt_thread_t init_thread;

D
dzzxzz 已提交
134 135
	rt_mq_init(&mq, "mqt", &msg_pool[0], 128 - sizeof(void*), sizeof(msg_pool), RT_IPC_FLAG_FIFO);
	
136 137 138
    init_thread = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 1024, 21, 20);
    if(init_thread != RT_NULL)
        rt_thread_startup(init_thread);
139
    
B
bernard.xiong@gmail.com 已提交
140 141 142 143
    return 0;
}

/*@}*/