FreeCalypso > hg > fc-selenite
comparison src/cs/drivers/drv_app/r2d/r2d_inits.c @ 0:b6a5e36de839
src/cs: initial import from Magnetite
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 15 Jul 2018 04:39:26 +0000 |
| parents | |
| children | fdecfb3bd860 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b6a5e36de839 |
|---|---|
| 1 /** | |
| 2 | |
| 3 @file: r2d_inits.c | |
| 4 | |
| 5 @author Christophe Favergeon | |
| 6 | |
| 7 @version 0.1 | |
| 8 | |
| 9 Purpose: Initializations routines for R2D | |
| 10 | |
| 11 */ | |
| 12 | |
| 13 /* | |
| 14 | |
| 15 Date Modification | |
| 16 ------------------------------------ | |
| 17 03/05/2002 Create | |
| 18 | |
| 19 | |
| 20 (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved | |
| 21 */ | |
| 22 | |
| 23 | |
| 24 #include "rv/general.h" | |
| 25 | |
| 26 #include "rvm/rvm_gen.h" | |
| 27 #include "rvm/rvm_ext_priorities.h" | |
| 28 #include "rvm/rvm_use_id_list.h" | |
| 29 | |
| 30 #include "r2d/r2d_pool_size.h" /* Stack & Memory Bank sizes definitions */ | |
| 31 | |
| 32 #include "r2d/r2d_config.h" | |
| 33 #include "r2d/r2d.h" | |
| 34 #include "r2d/r2d_i.h" | |
| 35 #include "r2d/r2d_env.h" | |
| 36 #include "r2d/r2d_independance_layer.h" | |
| 37 #include "r2d/r2d_messages.h" | |
| 38 #include "r2d/uwire.h" | |
| 39 | |
| 40 | |
| 41 #ifndef _WINDOWS | |
| 42 #ifndef _SIZE_T | |
| 43 #define _SIZE_T | |
| 44 typedef unsigned int size_t; | |
| 45 #endif | |
| 46 #endif | |
| 47 | |
| 48 #ifndef _WINDOWS | |
| 49 void *memcpy(void *s1, const void *s2, register size_t n); | |
| 50 void *memmove(void *s1, const void *s2, size_t n); | |
| 51 #endif | |
| 52 | |
| 53 extern T_R2D_ERROR r2d_font_init(void); | |
| 54 extern void r2d_font_clean(void);extern void r2d_core(UINT32 param); | |
| 55 | |
| 56 | |
| 57 /* global memory bank ID */ | |
| 58 extern T_RVF_MB_ID r2d_mb_id; | |
| 59 | |
| 60 /* Global standard graphical context */ | |
| 61 | |
| 62 extern T_R2D_GC_PTR r2d_g_lcd_gc; | |
| 63 | |
| 64 | |
| 65 | |
| 66 #if (R2D_ASM == R2D_ON) | |
| 67 extern T_RVF_MUTEX * r2d_g_blit_mutex; | |
| 68 extern UINT32 r2d_g_old_foreground_pixelvalue; | |
| 69 extern UINT32 r2d_g_old_background_pixelvalue; | |
| 70 #endif | |
| 71 | |
| 72 extern T_RVF_MUTEX * r2d_g_global_mutex; | |
| 73 | |
| 74 | |
| 75 | |
| 76 #if (R2D_REFRESH == R2D_VERTICAL) | |
| 77 extern UINT32 r2d_lcd_memory_words[(((R2D_WIDTH*R2D_MWHEIGHT)+1)<<R2D_LONGSIZE_FACTOR)]; | |
| 78 #else | |
| 79 extern UINT32 r2d_lcd_memory_words[(((R2D_MWWIDTH*R2D_HEIGHT)+1)<<R2D_LONGSIZE_FACTOR)]; | |
| 80 #endif | |
| 81 | |
| 82 extern INT16 r2d_update_ul_x,r2d_update_ul_y,r2d_update_br_x,r2d_update_br_y; | |
| 83 | |
| 84 extern void r2d_reinit_update_region(void); | |
| 85 | |
| 86 void (*IND_r2d_reinit_update_region)(void)=r2d_reinit_update_region; | |
| 87 | |
| 88 extern T_R2D_FONT_DESCRIPTION *r2d_g_font_configuration; | |
| 89 | |
| 90 | |
| 91 #if (R2D_EMBEDDED_LCD == R2D_PC_COLOR_LCD) | |
| 92 #include "r2d/lcds/colorpc/r2d_task_init_i.c" | |
| 93 #endif | |
| 94 | |
| 95 #if (R2D_EMBEDDED_LCD == R2D_PC_CSAMPLE) | |
| 96 #include "r2d/lcds/pc_csample/r2d_task_init_i.c" | |
| 97 #endif | |
| 98 | |
| 99 #if (R2D_EMBEDDED_LCD == R2D_PC_DSAMPLE) | |
| 100 #include "r2d/lcds/pc_dsample/r2d_task_init_i.c" | |
| 101 #endif | |
| 102 | |
| 103 #if (R2D_EMBEDDED_LCD == R2D_MIRRORED_LCD) | |
| 104 #ifdef CONFIG_TARGET_C139 | |
| 105 #include "r2d/lcds/c139/r2d_task_init_i.c" | |
| 106 #else | |
| 107 #include "r2d/lcds/simple/r2d_task_init_i.c" | |
| 108 #endif | |
| 109 #endif | |
| 110 | |
| 111 #if (R2D_EMBEDDED_LCD == R2D_CUSTOMER_LCD) | |
| 112 #include "r2d/lcds/customer/r2d_task_init_i.c" | |
| 113 #endif | |
| 114 | |
| 115 #if (R2D_EMBEDDED_LCD == R2D_HORIZONTAL_LCD) | |
| 116 #include "r2d/lcds/horizontal/r2d_task_init_i.c" | |
| 117 #endif | |
| 118 | |
| 119 #if (R2D_EMBEDDED_LCD == R2D_SIMPLE_LCD) | |
| 120 #include "r2d/lcds/simple/r2d_task_init_i.c" | |
| 121 #endif | |
| 122 | |
| 123 #if (R2D_EMBEDDED_LCD == R2D_BOARD_COLOR_LCD) | |
| 124 #include "r2d/lcds/colorboard/r2d_task_init_i.c" | |
| 125 #endif | |
| 126 | |
| 127 #if (R2D_EMBEDDED_LCD == R2D_BOARD_DSAMPLE) | |
| 128 #include "r2d/lcds/d_sample/r2d_task_init_i.c" | |
| 129 #endif | |
| 130 | |
| 131 #if (R2D_EMBEDDED_LCD == R2D_BOARD_BW_DSAMPLE) | |
| 132 #include "r2d/lcds/bw_d_sample/r2d_task_init_i.c" | |
| 133 #endif | |
| 134 | |
| 135 UINT32 r2d_get_memory_bank_size() | |
| 136 { | |
| 137 return(R2D_MB_PRIM_SIZE); | |
| 138 } | |
| 139 | |
| 140 #if ((!defined DEPENDENCY) && (R2D_MB_PRIM_SIZE != R2D_MB1_SIZE)) | |
| 141 /* If the R2D Memory Bank sizes defined in rvf_pool_size.h differs from */ | |
| 142 /* the one returned by the previous function, compilation is STOPPED. */ | |
| 143 #error R2D Memory Bank size mismatch! | |
| 144 #endif | |
| 145 | |
| 146 | |
| 147 | |
| 148 //////////////////////////////////////// | |
| 149 // | |
| 150 // Software entity initialization | |
| 151 | |
| 152 // Allocate the LCD framebuffer and dithering matrix | |
| 153 // Clear the framebuffer to 0 | |
| 154 // (Which does not mean intensity 0 since the meaning | |
| 155 // of 0 is dependent on the LCD). | |
| 156 | |
| 157 static void r2d_lcd_init(void) | |
| 158 { | |
| 159 UINT16 length; | |
| 160 // UINT32 *p; | |
| 161 T_RVF_RET err; | |
| 162 | |
| 163 | |
| 164 R2D_MALLOC(r2d_mb_id,T_R2D_FRAMEBUFFER,sizeof(T_R2D_FRAMEBUFFER),r2d_g_framebuffer); | |
| 165 | |
| 166 if (r2d_g_framebuffer !=NULL) | |
| 167 { | |
| 168 // length+1 is used instead of length because in the refresh loop | |
| 169 // one may need to read one word past the end of the real datas | |
| 170 #if (R2D_REFRESH==R2D_VERTICAL) | |
| 171 // Column is contiguous in memory | |
| 172 length=R2D_WIDTH*R2D_MWHEIGHT; | |
| 173 //R2D_MALLOC(r2d_mb_id,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),r2d_g_framebuffer->p_memory_words); | |
| 174 r2d_g_framebuffer->p_memory_words=r2d_lcd_memory_words; | |
| 175 | |
| 176 // No deletion at the end since memory_word is NOT a dynamical object | |
| 177 r2d_g_framebuffer->refcount=-1; | |
| 178 | |
| 179 // 0 is a special LCD kind : size of the framebuffer | |
| 180 // is hardcoded to quick pixel generation | |
| 181 r2d_g_framebuffer->kind=0; | |
| 182 r2d_g_framebuffer->p_frame_buffer_end=r2d_g_framebuffer->p_memory_words+length; | |
| 183 r2d_g_framebuffer->width=R2D_WIDTH; | |
| 184 r2d_g_framebuffer->height=R2D_HEIGHT; | |
| 185 #else | |
| 186 // Line is contiguous in memory | |
| 187 length=R2D_HEIGHT*R2D_MWWIDTH; | |
| 188 r2d_g_framebuffer->p_memory_words=r2d_lcd_memory_words; | |
| 189 | |
| 190 r2d_g_framebuffer->refcount=-1; | |
| 191 // 0 is a special LCD kind : size of the framebuffer | |
| 192 // is hardcoded to quick pixel generation | |
| 193 r2d_g_framebuffer->kind=0; | |
| 194 r2d_g_framebuffer->p_frame_buffer_end=r2d_g_framebuffer->p_memory_words+length; | |
| 195 r2d_g_framebuffer->width=R2D_WIDTH; | |
| 196 r2d_g_framebuffer->height=R2D_HEIGHT; | |
| 197 #endif | |
| 198 | |
| 199 R2D_MALLOC(r2d_mb_id,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),r2d_g_framebuffer->mutex); | |
| 200 if (r2d_g_framebuffer->mutex!=NULL) | |
| 201 { | |
| 202 err=rvf_initialize_mutex(r2d_g_framebuffer->mutex); | |
| 203 if (err!=RVF_OK) | |
| 204 { | |
| 205 R2D_FREE(r2d_g_framebuffer->mutex); | |
| 206 R2D_FREE(r2d_g_framebuffer); | |
| 207 r2d_g_framebuffer=NULL; | |
| 208 | |
| 209 } | |
| 210 } | |
| 211 else | |
| 212 { | |
| 213 R2D_FREE(r2d_g_framebuffer); | |
| 214 r2d_g_framebuffer=NULL; | |
| 215 | |
| 216 } | |
| 217 | |
| 218 } | |
| 219 IND_r2d_reinit_update_region(); | |
| 220 | |
| 221 | |
| 222 } | |
| 223 | |
| 224 T_RVM_RETURN r2d_cleanup(void) | |
| 225 { | |
| 226 /* | |
| 227 ** free all memory buffer previously allocated. | |
| 228 ** DO NOT SEND MESSAGES | |
| 229 */ | |
| 230 r2d_refresh_task_kill(); | |
| 231 #if (R2D_ASM == R2D_ON) | |
| 232 rvf_delete_mutex(r2d_g_blit_mutex); | |
| 233 R2D_FREE(r2d_g_blit_mutex); | |
| 234 #endif | |
| 235 rvf_delete_mutex(r2d_g_global_mutex); | |
| 236 R2D_FREE(r2d_g_global_mutex); | |
| 237 r2d_release_context(r2d_g_lcd_gc); | |
| 238 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 239 R2D_FREE(r2d_g_dithering_matrix); | |
| 240 R2D_FREE(r2d_g_font_configuration); | |
| 241 | |
| 242 return(RV_OK); | |
| 243 } | |
| 244 | |
| 245 | |
| 246 | |
| 247 /****************************************************************************** | |
| 248 * Function : xxx_init | |
| 249 * | |
| 250 * Description : This function is called by the RV manager to initialize the | |
| 251 * xxx SWE before creating the task and calling xxx_start. | |
| 252 * | |
| 253 * Parameters : None | |
| 254 * | |
| 255 * Return : T_RVM_RETURN | |
| 256 * | |
| 257 * History : 0.1 (20-August-2000) | |
| 258 * | |
| 259 * | |
| 260 ******************************************************************************/ | |
| 261 T_RVM_RETURN r2d_initializations(void) | |
| 262 { | |
| 263 /* | |
| 264 ** Put local SWE initialization here | |
| 265 */ | |
| 266 | |
| 267 T_R2D_ERROR err; | |
| 268 | |
| 269 r2d_lcd_init(); | |
| 270 if (r2d_g_framebuffer==NULL) | |
| 271 goto r2d_init_error; | |
| 272 | |
| 273 r2d_dithering_init(); | |
| 274 if (r2d_g_dithering_matrix==NULL) | |
| 275 { | |
| 276 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 277 goto r2d_init_error; | |
| 278 } | |
| 279 | |
| 280 R2D_MALLOC(r2d_mb_id,T_R2D_FONT_DESCRIPTION, | |
| 281 sizeof(T_R2D_FONT_DESCRIPTION)*36,r2d_g_font_configuration); | |
| 282 | |
| 283 if (r2d_g_font_configuration ==NULL) | |
| 284 { | |
| 285 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 286 R2D_FREE(r2d_g_dithering_matrix); | |
| 287 goto r2d_init_error; | |
| 288 } | |
| 289 | |
| 290 err=r2d_font_init(); | |
| 291 if (err!=R2D_OK) | |
| 292 { | |
| 293 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 294 R2D_FREE(r2d_g_dithering_matrix); | |
| 295 goto r2d_init_error; | |
| 296 } | |
| 297 | |
| 298 | |
| 299 r2d_g_default_font_framebuffer=r2d_g_font_configuration[R2D_MEDIUM_SYSTEM_NORMAL].framebuffer; | |
| 300 r2d_g_default_font_metrics=r2d_g_font_configuration[R2D_MEDIUM_SYSTEM_NORMAL].metrics; | |
| 301 r2d_g_default_font_table=r2d_g_font_configuration[R2D_MEDIUM_SYSTEM_NORMAL].table; | |
| 302 | |
| 303 r2d_refresh_task_init(); | |
| 304 | |
| 305 r2d_g_lcd_gc=r2d_new_lcd_context(r2d_mb_id); | |
| 306 if (r2d_g_lcd_gc==NULL) | |
| 307 { | |
| 308 r2d_font_clean(); | |
| 309 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 310 R2D_FREE(r2d_g_dithering_matrix); | |
| 311 goto r2d_init_error; | |
| 312 } | |
| 313 | |
| 314 r2d_g_event_was_sent=FALSE; | |
| 315 r2d_g_refresh_disabled=0; | |
| 316 | |
| 317 #if (R2D_ASM == R2D_ON) | |
| 318 | |
| 319 R2D_MALLOC(r2d_mb_id,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),r2d_g_blit_mutex); | |
| 320 if (r2d_g_blit_mutex==NULL) | |
| 321 { | |
| 322 r2d_font_clean(); | |
| 323 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 324 R2D_FREE(r2d_g_dithering_matrix); | |
| 325 goto r2d_init_error; | |
| 326 } | |
| 327 | |
| 328 err=rvf_initialize_mutex(r2d_g_blit_mutex); | |
| 329 if (err!=RVF_OK) | |
| 330 { | |
| 331 R2D_FREE(r2d_g_blit_mutex); | |
| 332 r2d_font_clean(); | |
| 333 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 334 R2D_FREE(r2d_g_dithering_matrix); | |
| 335 goto r2d_init_error; | |
| 336 } | |
| 337 | |
| 338 // Mode of initial asm blit rect | |
| 339 r2d_g_old_mode=R2D_COPY_MODE; | |
| 340 r2d_g_old_use_foreground=FALSE; | |
| 341 r2d_g_old_srcdst=R2D_LCDLCD; | |
| 342 r2d_g_old_foreground_pixelvalue=((T_R2D_GC*)r2d_g_lcd_gc)->foreground_pixel_value; | |
| 343 r2d_g_old_background_pixelvalue=((T_R2D_GC*)r2d_g_lcd_gc)->background_pixel_value; | |
| 344 | |
| 345 #endif | |
| 346 | |
| 347 R2D_MALLOC(r2d_mb_id,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),r2d_g_global_mutex); | |
| 348 if (r2d_g_global_mutex==NULL) | |
| 349 { | |
| 350 r2d_font_clean(); | |
| 351 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 352 R2D_FREE(r2d_g_dithering_matrix); | |
| 353 #if (R2D_ASM == R2D_ON) | |
| 354 rvf_delete_mutex(r2d_g_blit_mutex); | |
| 355 R2D_FREE(r2d_g_blit_mutex); | |
| 356 #endif | |
| 357 goto r2d_init_error; | |
| 358 } | |
| 359 | |
| 360 err=rvf_initialize_mutex(r2d_g_global_mutex); | |
| 361 if (err!=RVF_OK) | |
| 362 { | |
| 363 R2D_FREE(r2d_g_global_mutex); | |
| 364 r2d_font_clean(); | |
| 365 r2d_release_framebuffer(r2d_g_framebuffer); | |
| 366 R2D_FREE(r2d_g_dithering_matrix); | |
| 367 #if (R2D_ASM == R2D_ON) | |
| 368 rvf_delete_mutex(r2d_g_blit_mutex); | |
| 369 R2D_FREE(r2d_g_blit_mutex); | |
| 370 #endif | |
| 371 goto r2d_init_error; | |
| 372 } | |
| 373 | |
| 374 | |
| 375 return RV_OK; | |
| 376 | |
| 377 | |
| 378 r2d_init_error: return RV_MEMORY_ERR; | |
| 379 } | |
| 380 |
