⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 advance.c

📁 LCD programming in eCos.
💻 C
字号:
//============================================================================
//        Include
//============================================================================

#include <stdio.h>
#include <cyg/hal/drv_api.h>
#include <cyg/kernel/kapi.h>
#include <cyg/infra/cyg_type.h>
#include <cyg/infra/diag.h>
#include <cyg/io/rtc/fie702x_rtc.h>
#include <cyg/io/lcd/fie702x_lcd.h>
#include "RTCSystem.h"
#include "LCDSystem.h"
#include "FontSystem.h"

#define STACKSIZE 	(65536)
#define NUM(x)		(sizeof(x)/sizeof(x[0]))

//============================================================================
//        Global Variables
//============================================================================

cyg_io_handle_t lcd_handle, rtc_handle;
cyg_flag_t frame_go;

//============================================================================
//        System
//============================================================================

void Frame(CYG_ADDRESS);
void Display(CYG_ADDRESS);

typedef void fun(CYG_ADDRWORD);

typedef struct _eCos_thread {
    char         *name;
    fun          *entry;
    int          prio;
    cyg_handle_t t;
    cyg_thread   t_obj;
    char         stack[STACKSIZE];
} eCos_thread;

eCos_thread _thread[] = {
	{"Count frame", Frame, 10},
	{"Display", Display, 11},
};

void Frame (CYG_ADDRESS data)
{	
	while (1)
	{
		cyg_thread_delay(5);
		
		// display one frame
		API_LCD_dsiplay_Frame(lcd_handle);
	}
}

char image[(320*240*3)/2];

/* clear Frame buffers*/void LCD_clear_Buffer (char *buf){	// clear as green	memset(buf, 35, 320*240);	memset(buf + 320*240, 212, (320*240/4));	memset(buf + 320*240 + (320*240/4), 144, (320*240/4));}

void Display (CYG_ADDRESS data)
{	
	int err;
	char char_tmp[255];
	int i;
	RTC_Time time;
	int display_time, display_sec, display_min;
	int sel;
	char *Y_p;
	
	err = cyg_io_lookup( "/dev/rtc", &rtc_handle );

	if (ENOERR != err) 
	{
		printf("Can't open '%s'\n", "/dev/rtc");
	}
	
	err = cyg_io_lookup( "/dev/lcd", &lcd_handle );

	if (ENOERR != err) 
	{
		printf("Can't open '%s'\n", "/dev/lcd");
	}


	API_LCD_start(lcd_handle);
	
	API_LCD_set_FrameRate(lcd_handle, 20);
	
	LCD_clear_Buffer(image);
	
	while (1)
	{
		for (i = 0; i < 20; i ++)
		{	
			// get frame base. if no one, sleep...
			sel = API_LCD_get_InvalidFrame(lcd_handle);				Y_p = API_LCD_get_Y_Base(lcd_handle, sel);

			// clear count
			API_Font_display_8x8String("                                        ", 0, 0, image);

			// draw count		
			sprintf(char_tmp, "%d", i);
			char_tmp[2] = '\0';
			API_Font_display_8x8String(char_tmp, 16*i, 0, image);
			
			// display real time
			API_RTC_get_Time(rtc_handle, &time);		

			sprintf(char_tmp, "RTC -> %02d:%02d\n", time.minute, time.second);
			char_tmp[12] = '\0';
			API_Font_display_8x8String(char_tmp, 0, 32, image);
			
			// display estimated time
			display_time = API_LCD_get_DisplayTime(lcd_handle) / 1000;			
			display_sec = display_time % 60;
			display_min = display_time / 60;			
			sprintf(char_tmp, "Estimated -> %02d:%02d\n", display_min, display_sec);

			char_tmp[18] = '\0';
			API_Font_display_8x8String(char_tmp, 0, 48, image);
			
			// write to display frame
			memcpy(Y_p, image, 320*240);
			API_LCD_valid_Frame(lcd_handle);
		}
	}
}

/* start eCOs
*/
void cyg_user_start(void)
{
	int i;
	eCos_thread *nx;
	
	printf("SYSTEM START.\n");
	
	nx = &_thread[0];
	for (i = 0;  i < NUM(_thread);  i++, nx++) {
		cyg_thread_create(nx->prio,
			  	  nx->entry,
			  	  (cyg_addrword_t)NULL,
			  	  nx->name,
			  	  (void *)nx->stack, STACKSIZE,
			  	  &nx->t,
			  	  &nx->t_obj);
		cyg_thread_resume(nx->t);
	}
	
	cyg_flag_init(&frame_go);
	
	printf("SYSTEM THREADS STARTED!\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -