📄 r2d_inits.c
字号:
/**
@file: r2d_inits.c
@author Christophe Favergeon
@version 0.1
Purpose: Initializations routines for R2D
*/
/*
Date Modification
------------------------------------
03/05/2002 Create
(C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
*/
#include "general.h"
#ifndef _INNOVATION_EMULATOR_
#include "rvm_gen.h"
#include "rvm_ext_priorities.h"
#include "rvm_use_id_list.h"
#endif
#include "r2d_config.h"
#include "r2d.h"
#include "r2d_i.h"
#include "r2d_env.h"
#include "r2d_independance_layer.h"
#include "r2d_messages.h"
#ifndef _INNOVATION_EMULATOR_
#include "uwire.h"
#endif
#ifndef _WINDOWS
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned int size_t;
#endif
#endif
#ifndef _WINDOWS
void *memcpy(void *s1, const void *s2, register size_t n);
void *memmove(void *s1, const void *s2, size_t n);
#endif
extern T_R2D_ERROR r2d_font_init(void);
extern void r2d_font_clean(void);extern void r2d_core(UINT32 param);
/* global memory bank ID */
extern T_RVF_MB_ID r2d_mb_id;
/* Global standard graphical context */
extern T_R2D_GC_PTR r2d_g_lcd_gc;
extern T_R2D_GC_PTR r2d_g_sublcd_gc;
#if (R2D_ASM == R2D_ON)
extern T_RVF_MUTEX * r2d_g_blit_mutex;
extern UINT32 r2d_g_old_foreground_pixelvalue;
extern UINT32 r2d_g_old_background_pixelvalue;
#endif
extern T_RVF_MUTEX * r2d_g_global_mutex;
#if (R2D_REFRESH == R2D_VERTICAL)
extern UINT32 r2d_lcd_memory_words[(((R2D_WIDTH*R2D_MWHEIGHT)+1)<<R2D_LONGSIZE_FACTOR)];
/* Robert.Chen add, for sub LCD framebuffer, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
extern UINT32 r2d_sublcd_memory_words[(((R2D_WIDTH*R2D_MWHEIGHT)+1)<<R2D_LONGSIZE_FACTOR)];
#endif
#else /* R2D_VERTICAL */
extern UINT32 r2d_lcd_memory_words[(((R2D_MWWIDTH*R2D_HEIGHT)+1)<<R2D_LONGSIZE_FACTOR)];
/* Robert.Chen add, for sub LCD framebuffer, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
extern UINT32 r2d_sublcd_memory_words[(((R2D_MWWIDTH*R2D_HEIGHT)+1)<<R2D_LONGSIZE_FACTOR)];
#endif
#endif /* R2D_VERTICAL */
extern INT16 r2d_update_ul_x,r2d_update_ul_y,r2d_update_br_x,r2d_update_br_y;
extern void r2d_reinit_update_region(void);
void (*IND_r2d_reinit_update_region)(void)=r2d_reinit_update_region;
extern T_R2D_FONT_DESCRIPTION *r2d_g_font_configuration;
#ifndef _INNOVATION_EMULATOR_
#if (R2D_EMBEDDED_LCD == R2D_PC_COLOR_LCD)
#include "LCDs/ColorPC/r2d_task_init_i.c"
#endif
#if (R2D_EMBEDDED_LCD == R2D_MIRRORED_LCD)
#include "LCDs/Simple/r2d_task_init_i.c"
#endif
#if (R2D_EMBEDDED_LCD == R2D_CUSTOMER_LCD)
#include "LCDs/Customer/r2d_task_init_i.c"
#endif
#if (R2D_EMBEDDED_LCD == R2D_HORIZONTAL_LCD)
#include "LCDs/Horizontal/r2d_task_init_i.c"
#endif
#if (R2D_EMBEDDED_LCD == R2D_SIMPLE_LCD)
#include "LCDs/Simple/r2d_task_init_i.c"
#endif
#if (R2D_EMBEDDED_LCD == R2D_BOARD_COLOR_LCD)
#include "LCDs/ColorBoard/r2d_task_init_i.c"
#endif
#if (R2D_EMBEDDED_LCD == R2D_BOARD_DSAMPLE)
#include "LCDs/D_Sample/r2d_task_init_i.c"
#endif
#endif
#ifndef _INNOVATION_EMULATOR_
UINT32 r2d_get_memory_bank_size()
{
return(R2D_MB_PRIM_SIZE);
}
#endif
#ifdef _INNOVATION_EMULATOR_
static r2d_refresh_task_init(void)
{
}
static r2d_refresh_task_kill(void)
{
}
static void r2d_dithering_init()
{
R2D_MALLOC(r2d_mb_id,UINT32,sizeof(UINT32)*4,r2d_g_dithering_matrix);
r2d_g_dithering_matrix[0]=0;
r2d_g_dithering_matrix[1]=2;
r2d_g_dithering_matrix[2]=3;
r2d_g_dithering_matrix[3]=1;
}
#endif
////////////////////////////////////////
//
// Software entity initialization
// Allocate the LCD framebuffer and dithering matrix
// Clear the framebuffer to 0
// (Which does not mean intensity 0 since the meaning
// of 0 is dependent on the LCD).
static void r2d_lcd_init()
{
UINT16 length;
UINT32 *p;
/* for main LCD */
R2D_MALLOC(r2d_mb_id,T_R2D_FRAMEBUFFER,sizeof(T_R2D_FRAMEBUFFER),r2d_g_framebuffer);
if ( r2d_g_framebuffer != NULL )
{
// length+1 is used instead of length because in the refresh loop
// one may need to read one word past the end of the real datas
#if (R2D_REFRESH == R2D_VERTICAL)
// Column is contiguous in memory
length = R2D_WIDTH * R2D_MWHEIGHT;
r2d_g_framebuffer->p_memory_words=r2d_lcd_memory_words;
// No deletion at the end since memory_word is NOT a dynamical object
r2d_g_framebuffer->refcount=-1;
// 0 is a special LCD kind : size of the framebuffer and is hardcoded to quick pixel generation
r2d_g_framebuffer->kind = 0;
r2d_g_framebuffer->p_frame_buffer_end = r2d_g_framebuffer->p_memory_words+length;
r2d_g_framebuffer->width = R2D_WIDTH;
r2d_g_framebuffer->height = R2D_HEIGHT;
#else /* R2D_VERTICAL */
// Line is contiguous in memory
length = R2D_HEIGHT * R2D_MWWIDTH;
r2d_g_framebuffer->p_memory_words = r2d_lcd_memory_words;
r2d_g_framebuffer->refcount = -1;
// 0 is a special LCD kind : size of the framebuffer and is hardcoded to quick pixel generation
r2d_g_framebuffer->kind = 0;
r2d_g_framebuffer->p_frame_buffer_end = r2d_g_framebuffer->p_memory_words+length;
r2d_g_framebuffer->width = R2D_WIDTH;
r2d_g_framebuffer->height = R2D_HEIGHT;
#endif
}
IND_r2d_reinit_update_region();
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
R2D_MALLOC(r2d_mb_id, T_R2D_FRAMEBUFFER, sizeof(T_R2D_FRAMEBUFFER), r2d_g_subframebuffer);
if ( r2d_g_subframebuffer != NULL )
{
// length+1 is used instead of length because in the refresh loop
// one may need to read one word past the end of the real datas
#if (R2D_REFRESH == R2D_VERTICAL)
// Column is contiguous in memory
length = R2D_WIDTH * R2D_MWHEIGHT;
r2d_g_subframebuffer->p_memory_words = r2d_sublcd_memory_words;
// No deletion at the end since memory_word is NOT a dynamical object
r2d_g_subframebuffer->refcount = -1;
// 0 is a special LCD kind : size of the framebuffer and is hardcoded to quick pixel generation
r2d_g_subframebuffer->kind = 0;
r2d_g_subframebuffer->p_frame_buffer_end = r2d_g_subframebuffer->p_memory_words+length;
r2d_g_subframebuffer->width = R2D_WIDTH;
r2d_g_subframebuffer->height = R2D_HEIGHT;
#else /* R2D_VERTICAL */
// Line is contiguous in memory
length = R2D_HEIGHT * R2D_MWWIDTH;
r2d_g_subframebuffer->p_memory_words = r2d_sublcd_memory_words;
r2d_g_subframebuffer->refcount = -1;
// 0 is a special LCD kind : size of the framebuffer and is hardcoded to quick pixel generation
r2d_g_subframebuffer->kind = 0;
r2d_g_subframebuffer->p_frame_buffer_end = r2d_g_subframebuffer->p_memory_words + length;
r2d_g_subframebuffer->width = R2D_WIDTH;
r2d_g_subframebuffer->height = R2D_HEIGHT;
#endif
}
#endif
/* Robert.Chen add end, for sub LCD, 2003-12-13 */
}
T_RVM_RETURN r2d_cleanup()
{
/*
** free all memory buffer previously allocated.
** DO NOT SEND MESSAGES
*/
r2d_refresh_task_kill();
#if (R2D_ASM == R2D_ON)
rvf_delete_mutex(r2d_g_blit_mutex);
R2D_FREE(r2d_g_blit_mutex);
#endif
rvf_delete_mutex(r2d_g_global_mutex);
R2D_FREE(r2d_g_global_mutex);
r2d_release_context(r2d_g_lcd_gc);
r2d_release_framebuffer(r2d_g_framebuffer);
#if R2D_SUBLCD_SUPPORT /* Robert.Chen add left code */
r2d_release_context(r2d_g_sublcd_gc); /* for subLCD memory release */
r2d_release_framebuffer(r2d_g_subframebuffer); /* 2003-12-13 */
#endif /* add end */
R2D_FREE(r2d_g_dithering_matrix);
R2D_FREE(r2d_g_font_configuration);
return(RV_OK);
}
/******************************************************************************
* Function : xxx_init
*
* Description : This function is called by the RV manager to initialize the
* xxx SWE before creating the task and calling xxx_start.
*
* Parameters : None
*
* Return : T_RVM_RETURN
*
* History : 0.1 (20-August-2000)
*
*
******************************************************************************/
T_RVM_RETURN r2d_initializations(void)
{
/*
** Put local SWE initialization here
*/
T_R2D_ERROR err;
r2d_lcd_init();
if (r2d_g_framebuffer == NULL)
goto r2d_init_error;
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
if (r2d_g_subframebuffer == NULL)
goto r2d_init_error;
#endif
/* Robert.Chen add end */
r2d_dithering_init();
if ( r2d_g_dithering_matrix==NULL )
{
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
goto r2d_init_error;
}
R2D_MALLOC(r2d_mb_id, T_R2D_FONT_DESCRIPTION,
sizeof(T_R2D_FONT_DESCRIPTION)*36, r2d_g_font_configuration);
if ( r2d_g_font_configuration == NULL )
{
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
goto r2d_init_error;
}
err=r2d_font_init();
if ( err!=R2D_OK )
{
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
goto r2d_init_error;
}
r2d_g_default_font_framebuffer=r2d_g_font_configuration[R2D_MEDIUM_SYSTEM_NORMAL].framebuffer;
r2d_g_default_font_metrics=r2d_g_font_configuration[R2D_MEDIUM_SYSTEM_NORMAL].metrics;
r2d_g_default_font_table=r2d_g_font_configuration[R2D_MEDIUM_SYSTEM_NORMAL].table;
r2d_refresh_task_init();
r2d_g_lcd_gc = r2d_new_lcd_context(r2d_mb_id);
if ( r2d_g_lcd_gc==NULL )
{
r2d_font_clean();
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
goto r2d_init_error;
}
/* Robert.Chen add, for init sub LCD graphical context handle, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_g_sublcd_gc = r2d_new_context(r2d_mb_id, r2d_g_subframebuffer);
if ( r2d_g_sublcd_gc == NULL )
{
r2d_font_clean();
r2d_release_framebuffer(r2d_g_framebuffer);
r2d_release_framebuffer(r2d_g_subframebuffer);
R2D_FREE(r2d_g_dithering_matrix);
goto r2d_init_error;
}
#endif
/* end of init sub LCD gc handle */
r2d_g_event_was_sent = FALSE;
r2d_g_refresh_disabled = FALSE;
#if (R2D_ASM == R2D_ON)
R2D_MALLOC(r2d_mb_id,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),r2d_g_blit_mutex);
if ( r2d_g_blit_mutex==NULL )
{
r2d_font_clean();
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
goto r2d_init_error;
}
err=rvf_initialize_mutex(r2d_g_blit_mutex);
if ( err!=RVF_OK )
{
R2D_FREE(r2d_g_blit_mutex);
r2d_font_clean();
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
goto r2d_init_error;
}
// Mode of initial asm blit rect
r2d_g_old_mode=R2D_COPY_MODE;
r2d_g_old_use_foreground=FALSE;
r2d_g_old_srcdst=R2D_LCDLCD;
r2d_g_old_foreground_pixelvalue=((T_R2D_GC*)r2d_g_lcd_gc)->foreground_pixel_value;
r2d_g_old_background_pixelvalue=((T_R2D_GC*)r2d_g_lcd_gc)->background_pixel_value;
#endif
R2D_MALLOC(r2d_mb_id,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),r2d_g_global_mutex);
if ( r2d_g_global_mutex==NULL )
{
r2d_font_clean();
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
#if (R2D_ASM == R2D_ON)
rvf_delete_mutex(r2d_g_blit_mutex);
R2D_FREE(r2d_g_blit_mutex);
#endif
goto r2d_init_error;
}
err=rvf_initialize_mutex(r2d_g_global_mutex);
if ( err!=RVF_OK )
{
R2D_FREE(r2d_g_global_mutex);
r2d_font_clean();
r2d_release_framebuffer(r2d_g_framebuffer);
/* Robert.Chen add, for sub LCD, 2003-12-13 */
#if R2D_SUBLCD_SUPPORT
r2d_release_framebuffer(r2d_g_subframebuffer);
#endif
R2D_FREE(r2d_g_dithering_matrix);
#if (R2D_ASM == R2D_ON)
rvf_delete_mutex(r2d_g_blit_mutex);
R2D_FREE(r2d_g_blit_mutex);
#endif
goto r2d_init_error;
}
return RV_OK;
r2d_init_error: return RV_MEMORY_ERR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -