Graphics framework for GR-PEACH. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE
Dependents: ImageZoomInout_Sample ImageRotaion_Sample ImageScroll_Sample GR-PEACH_LCD_4_3inch_Save_to_USB ... more
ncg_state.c
00001 /****************************************************************************** 00002 * Copyright(c) 2010-2012 Renesas Electronics Corporation. All rights reserved. 00003 * 00004 * brief : NCG State variable control functions. 00005 * 00006 * author : Renesas Electronics Corporation 00007 * 00008 * history: 2010.10.08 00009 * - Created the initial code. 00010 * 2013.05.20 00011 * - Applied to CMSIS-RTOS RTX. 00012 * 2014.12.10 00013 * - Applied to OSPL and RGA. 00014 * 00015 *******************************************************************************/ 00016 00017 /*============================================================================= 00018 * Includes 00019 */ 00020 #include "Project_Config.h" 00021 #include "r_ospl.h" 00022 00023 #include "ncg_defs.h" 00024 #include "ncg_debug.h" 00025 #include "ncg_state.h" 00026 00027 #ifdef RGAH_VERSION 00028 00029 /*============================================================================= 00030 * Internal definitions 00031 */ 00032 00033 #define NCG_MAX_STATE_OBJECTS (1U) 00034 #define NCG_MAX_THREAD_ID (1U) 00035 00036 struct NCG_STATE_T { 00037 r_ospl_thread_id_t id[NCG_MAX_THREAD_ID]; 00038 NCGboolean bInUse; 00039 int32_t flgbit; 00040 NCGuint32 ui32State; 00041 } ; 00042 00043 00044 /*============================================================================= 00045 * Prototyping of internal functions 00046 */ 00047 00048 static NCGint32 ncg_init_states( void ) ; 00049 static NCGuint32 ncg_state_search( NCGvoid *pObj ); 00050 00051 00052 /*============================================================================= 00053 * Private global variables and functions 00054 */ 00055 00056 volatile static struct NCG_STATE_T tStates[NCG_MAX_STATE_OBJECTS]; 00057 00058 static NCGboolean ncg_state_initialized = NCG_FALSE ; 00059 static struct NCG_STATE_T *ncg_last_created_state; 00060 00061 00062 /*============================================================================= 00063 * Global Function 00064 */ 00065 00066 /*---------------------------------------------------------------------------- 00067 NAME : NCGSYS_CreateState 00068 FUNCTION : Create a state control object. 00069 PARAMETERS : ppObj : [OUT] The pointer to the created state control object. 00070 ui32StateID : [IN ] The identifier of the state variable. 00071 RETURN : Error code of the NCG. 00072 ------------------------------------------------------------------------------*/ 00073 NCGint32 00074 NCGSYS_CreateState( 00075 NCGvoid **ppObj, 00076 NCGuint32 ui32StateID ) 00077 { 00078 struct NCG_STATE_T *p_state; 00079 NCGuint32 state_idx; 00080 NCGuint32 thread_idx; 00081 00082 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_CreateState" ); 00083 00084 NCG_UNREFERENCED_PARAMETER(ui32StateID); 00085 00086 if( ppObj == NCG_NULL ) { 00087 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_CreateState(1) invalid ppObj.%s" ) 00088 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00089 NCG_DEBUG_MAKE_MSG_END(); 00090 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00091 return NCG_err_invalid_handle ; 00092 } 00093 00094 if( ncg_state_initialized == NCG_FALSE ) { 00095 ncg_init_states(); 00096 } 00097 00098 p_state = NULL; 00099 for ( state_idx = 0 ; state_idx < NCG_MAX_STATE_OBJECTS ; state_idx++ ) { 00100 if ( tStates[state_idx].bInUse == NCG_FALSE ) { 00101 p_state = (struct NCG_STATE_T *)&tStates[state_idx]; 00102 break ; 00103 } 00104 } 00105 if ( p_state == NULL ) { 00106 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_CreateState(2) Object over flow.%s" ) 00107 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00108 NCG_DEBUG_MAKE_MSG_END(); 00109 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00110 return NCG_err_resource_exceeded ; 00111 } 00112 00113 /* set initial value */ 00114 for ( thread_idx = 1U ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00115 p_state->id[thread_idx] = NULL; 00116 } 00117 p_state->id[0] = R_OSPL_THREAD_GetCurrentId(); /* [0] is current thread id */ 00118 p_state->bInUse = NCG_TRUE ; 00119 p_state->ui32State = 0U ; 00120 00121 *ppObj = ( NCGvoid *)p_state ; 00122 ncg_last_created_state = p_state; 00123 00124 return NCG_no_err ; 00125 } 00126 00127 /*---------------------------------------------------------------------------- 00128 NAME : NCGSYS_DestroyState 00129 FUNCTION : Destroy the given state control object. 00130 PARAMETERS : pObj : [IN ] The pointer to the state control object. 00131 RETURN : Error code of the NCG. 00132 ------------------------------------------------------------------------------*/ 00133 NCGint32 00134 NCGSYS_DestroyState( 00135 NCGvoid *pObj ) 00136 { 00137 volatile struct NCG_STATE_T *p_state; 00138 NCGuint32 state_idx; 00139 NCGuint32 thread_idx; 00140 NCGboolean bDestroyFlg ; 00141 00142 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_DestroyState" ); 00143 00144 p_state = (struct NCG_STATE_T *)pObj; 00145 if( p_state == NCG_NULL ) { 00146 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_DestroyState(1) Failed: pObj is NULL.%s" ) 00147 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00148 NCG_DEBUG_MAKE_MSG_END(); 00149 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00150 return NCG_err_invalid_handle ; 00151 } 00152 00153 state_idx = ncg_state_search( pObj ); 00154 if ( state_idx >= NCG_MAX_STATE_OBJECTS ) { 00155 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_DestroyState(2) Failed: pObj is not found.%s" ) 00156 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00157 NCG_DEBUG_MAKE_MSG_END(); 00158 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00159 return NCG_err_not_found ; 00160 } 00161 00162 if( p_state->bInUse == NCG_FALSE ) { 00163 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_DestroyState(3) Failed: pObj is not used.%s" ) 00164 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00165 NCG_DEBUG_MAKE_MSG_END(); 00166 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00167 return NCG_err_bad_parameter ; 00168 } 00169 00170 /* clear status parameters */ 00171 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00172 p_state->id[thread_idx] = NULL; 00173 } 00174 p_state->bInUse = NCG_FALSE; 00175 p_state->ui32State = 0U; 00176 00177 bDestroyFlg = NCG_TRUE ; 00178 for ( state_idx = 0 ; state_idx < NCG_MAX_STATE_OBJECTS ; state_idx++ ) { 00179 if ( tStates[state_idx].bInUse != NCG_FALSE ) { 00180 bDestroyFlg = NCG_FALSE ; 00181 break ; 00182 } 00183 } 00184 if ( bDestroyFlg != NCG_FALSE ) { 00185 ncg_state_initialized = NCG_FALSE ; 00186 } 00187 return NCG_no_err ; 00188 } 00189 00190 /*---------------------------------------------------------------------------- 00191 NAME : NCGSYS_SetState 00192 FUNCTION : Set the state control object into the given state. 00193 PARAMETERS : pObj : [IN ] The pointer to the state control object. 00194 ui32State : [IN ] The state value to set. 00195 ui32Flags : [IN ] Flags. 00196 RETURN : Error code of the NCG. 00197 ------------------------------------------------------------------------------*/ 00198 NCGint32 00199 NCGSYS_SetState( 00200 NCGvoid *pObj, 00201 NCGuint32 ui32State, 00202 NCGuint32 ui32Flags ) 00203 { 00204 volatile struct NCG_STATE_T *p_state = (volatile struct NCG_STATE_T *)pObj ; 00205 00206 NCGuint32 uiSetMask; 00207 NCGuint32 thread_idx; 00208 00209 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_SetState" ); 00210 00211 if( pObj == NCG_NULL ) { 00212 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(1) Failed:pObj is NULL.%s" ) 00213 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00214 NCG_DEBUG_MAKE_MSG_END(); 00215 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00216 return NCG_err_unknown ; 00217 } 00218 00219 if ( ncg_state_search( pObj ) >= NCG_MAX_STATE_OBJECTS ) { 00220 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(2) Failed: pObj is not found.%s" ) 00221 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00222 NCG_DEBUG_MAKE_MSG_END(); 00223 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00224 return NCG_err_not_found ; 00225 } 00226 00227 p_state = (volatile struct NCG_STATE_T *)pObj; 00228 if ( p_state->bInUse == NCG_FALSE ) { 00229 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(3) Failed: pObj is not used.%s" ) 00230 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00231 NCG_DEBUG_MAKE_MSG_END(); 00232 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00233 return NCG_err_bad_parameter ; 00234 } 00235 00236 uiSetMask = ui32Flags & NCGSYS_STATE_SET_MASK; 00237 switch( uiSetMask ) { 00238 case NCGSYS_STATE_SET_AND : 00239 p_state->ui32State &= ui32State ; 00240 break ; 00241 00242 case NCGSYS_STATE_SET_OR : 00243 p_state->ui32State |= ui32State ; 00244 break ; 00245 00246 case NCGSYS_STATE_SET_SET : 00247 p_state->ui32State = ui32State ; 00248 break ; 00249 00250 default : 00251 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_SetState(5) Failed:ui32Flags (0x%08x).%s" ) 00252 NCG_DEBUG_MAKE_MSG_PARAMETER( ui32Flags ) 00253 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00254 NCG_DEBUG_MAKE_MSG_END(); 00255 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00256 return NCG_err_bad_parameter ; 00257 } 00258 00259 if ( uiSetMask == NCGSYS_STATE_SET_AND ) { 00260 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00261 if ( p_state->id[thread_idx] != NULL ) { 00262 r_ospl_thread_id_t thread = p_state->id[thread_idx]; /* ICCARM Pa082 : volatile's order */ 00263 R_OSPL_EVENT_Clear( thread, p_state->flgbit ); 00264 } 00265 } 00266 } else { 00267 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00268 if ( p_state->id[thread_idx] != NULL ) { 00269 r_ospl_thread_id_t thread = p_state->id[thread_idx]; /* ICCARM Pa082 : volatile's order */ 00270 R_OSPL_EVENT_Set( thread, p_state->flgbit ); 00271 } 00272 } 00273 } 00274 00275 return NCG_no_err ; 00276 } 00277 00278 /*---------------------------------------------------------------------------- 00279 NAME : NCGSYS_GetState 00280 FUNCTION : Get the current state value from the state control object. 00281 PARAMETERS : pObj : [IN ] The pointer to the state control object. 00282 ui32Flags : [IN ] Flags. 00283 RETURN : Error code of the NCG. 00284 ------------------------------------------------------------------------------*/ 00285 NCGuint32 00286 NCGSYS_GetState( 00287 NCGvoid *pObj, 00288 NCGuint32 ui32Flags ) 00289 { 00290 volatile struct NCG_STATE_T *p_state; 00291 00292 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_GetState" ); 00293 00294 NCG_UNREFERENCED_PARAMETER(ui32Flags); 00295 00296 if ( pObj == NCG_NULL ) { 00297 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_GetState(1) Failed: pObj.%s" ) 00298 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00299 NCG_DEBUG_MAKE_MSG_END(); 00300 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00301 return (NCGuint32)NCG_err_unknown ; 00302 } 00303 00304 if ( ncg_state_search( pObj ) >= NCG_MAX_STATE_OBJECTS ) { 00305 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_GetState(2) Failed: pObj is not found.%s" ) 00306 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00307 NCG_DEBUG_MAKE_MSG_END(); 00308 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00309 return (NCGuint32)NCG_err_not_found ; 00310 } 00311 00312 p_state = (volatile struct NCG_STATE_T *)pObj; 00313 if( p_state->bInUse == NCG_FALSE ) { 00314 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_GetState(3) Failed: pObj is not used.%s" ) 00315 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00316 NCG_DEBUG_MAKE_MSG_END(); 00317 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00318 return (NCGuint32)NCG_err_bad_parameter ; 00319 } 00320 return ( NCGuint32 )p_state->ui32State ; 00321 } 00322 00323 /*---------------------------------------------------------------------------- 00324 NAME : NCGSYS_WaitState 00325 FUNCTION : Wait for the state control object to be in the given state. 00326 PARAMETERS : pObj : [IN ] The pointer to the state control object. 00327 ui32State : [IN ] The state value to wait for. 00328 ui32Flags : [IN ] Flags. 00329 ui32Timeout : [IN ] Timeout value in milli seconds. 00330 RETURN : Error code of the NCG. 00331 ------------------------------------------------------------------------------*/ 00332 NCGint32 00333 NCGSYS_WaitState( 00334 NCGvoid *pObj, 00335 NCGuint32 ui32State, 00336 NCGuint32 ui32Flags, 00337 NCGuint32 ui32Timeout ) 00338 { 00339 volatile struct NCG_STATE_T *p_state; 00340 NCGuint32 wait_mode; 00341 NCGuint32 thread_idx; 00342 NCGint32 func_ret; 00343 uint32_t time_out; 00344 errnum_t e; 00345 00346 00347 NCG_DEBUG_PRINT_STRING( "[LOG] NCGSYS_WaitState" ); 00348 00349 p_state = (volatile struct NCG_STATE_T *)pObj; 00350 wait_mode = (ui32Flags & NCGSYS_STATE_WAIT_MASK); 00351 00352 if ( p_state == NCG_NULL ) { 00353 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_WaitState(1) Failed: pObj is NULL.%s" ) 00354 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00355 NCG_DEBUG_MAKE_MSG_END(); 00356 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00357 return NCG_err_unknown ; 00358 } 00359 if ( p_state->bInUse == NCG_FALSE ) { 00360 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_WaitState(2) Failed: pObj.%s" ) 00361 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00362 NCG_DEBUG_MAKE_MSG_END(); 00363 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00364 return NCG_err_unknown ; 00365 } 00366 if (( ui32Timeout != NCG_TIMEOUT_INFINITE ) && ( ui32Timeout > 0x7fffffffU )) { 00367 NCG_DEBUG_MAKE_MSG_START( NCG_G_MASSAGE_BUFF, "[NCG][ERROR]NCGSYS_WaitState(3) Failed: ui32Timeout.%s" ) 00368 NCG_DEBUG_MAKE_MSG_PARAMETER( NCG_CRLF ) 00369 NCG_DEBUG_MAKE_MSG_END(); 00370 NCG_DEBUG_PRINT_MSG( NCG_G_MASSAGE_BUFF ); 00371 return NCG_err_unknown ; 00372 } 00373 00374 if ( ui32Timeout == NCG_TIMEOUT_INFINITE ) { 00375 time_out = R_OSPL_INFINITE; 00376 } else { 00377 time_out = ui32Timeout; 00378 } 00379 00380 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00381 if ( p_state->id[thread_idx] == R_OSPL_THREAD_GetCurrentId() ) { 00382 break; 00383 } 00384 if ( p_state->id[thread_idx] == NULL ) { 00385 /* add thread ID */ 00386 p_state->id[thread_idx] = R_OSPL_THREAD_GetCurrentId(); 00387 break; 00388 } 00389 } 00390 00391 while (1) { 00392 if ( wait_mode == NCGSYS_STATE_WAIT_OR ) { 00393 if ( (p_state->ui32State & ui32State) != 0 ) { 00394 func_ret = NCG_no_err; 00395 break; 00396 } 00397 } else { 00398 /* wait_mode == NCGSYS_STATE_WAIT_AND */ 00399 if ( (p_state->ui32State & ui32State) == ui32State ) { 00400 func_ret = NCG_no_err; 00401 break; 00402 } 00403 } 00404 e = R_OSPL_EVENT_Wait( p_state->flgbit, NULL, time_out ); 00405 IF ( e != 0 ) { 00406 func_ret = NCG_err_unknown; 00407 break; 00408 } 00409 } 00410 00411 for ( thread_idx = 1 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00412 p_state->id[thread_idx] = NULL; 00413 } 00414 00415 return func_ret; 00416 } 00417 00418 00419 /*============================================================================= 00420 * Internal functions 00421 */ 00422 00423 /*---------------------------------------------------------------------------- 00424 NAME : ncg_init_states 00425 FUNCTION : Initialize global variable in NCG state. 00426 PARAMETERS : None. 00427 RETURN : None. 00428 ------------------------------------------------------------------------------*/ 00429 static NCGint32 00430 ncg_init_states( void ) 00431 { 00432 NCGuint32 i ; 00433 NCGuint32 thread_idx; 00434 00435 for( i = 0 ; i < NCG_MAX_STATE_OBJECTS ; i++ ) { 00436 for ( thread_idx = 0 ; thread_idx < NCG_MAX_THREAD_ID ; thread_idx++ ) { 00437 tStates[i].id[thread_idx] = NULL; 00438 } 00439 tStates[i].bInUse = NCG_FALSE ; 00440 tStates[i].flgbit = (int32_t)(1 << i) ; 00441 tStates[ i ].ui32State = 0U ; 00442 } 00443 ncg_state_initialized = NCG_TRUE ; 00444 00445 return NCG_no_err; 00446 } 00447 00448 /*---------------------------------------------------------------------------- 00449 NAME : ncg_state_search 00450 FUNCTION : Search status object. 00451 PARAMETERS : pObj :[IN ] Handle to the status object. 00452 RETURN : Index of the status object. 00453 ------------------------------------------------------------------------------*/ 00454 static NCGuint32 ncg_state_search( 00455 NCGvoid *pObj 00456 ) 00457 { 00458 NCGuint32 state_idx; 00459 00460 for ( state_idx = 0U ; state_idx < NCG_MAX_STATE_OBJECTS ; state_idx++ ) { 00461 if ( pObj == &tStates[state_idx] ) { 00462 break; 00463 } 00464 } 00465 00466 return state_idx; 00467 } 00468 00469 /*---------------------------------------------------------------------------- 00470 NAME : NCGSYS_SetStateEventValue 00471 FUNCTION : Set the value of thread attached event. 00472 PARAMETERS : pObj : [IN ] The pointer to the state control object. 00473 ui32EventValue : [IN ] The value of thread attached event. 00474 RETURN : None. 00475 ------------------------------------------------------------------------------*/ 00476 NCGvoid 00477 NCGSYS_SetStateEventValue( 00478 NCGvoid *pObj, 00479 NCGuint32 ui32EventValue ) 00480 { 00481 volatile struct NCG_STATE_T *p_state = (volatile struct NCG_STATE_T *)pObj ; 00482 00483 p_state->flgbit = ui32EventValue; 00484 } 00485 00486 /*---------------------------------------------------------------------------- 00487 NAME : NCGSYS_GetLastCreatedState 00488 FUNCTION : GetLastCreatedState. 00489 PARAMETERS : None. 00490 RETURN : LastCreatedState. 00491 ------------------------------------------------------------------------------*/ 00492 NCGvoid * 00493 NCGSYS_GetLastCreatedState(void) 00494 { 00495 return (NCGvoid *) ncg_last_created_state; 00496 } 00497 00498 #endif 00499 /* -- end of file -- */
Generated on Tue Jul 12 2022 11:15:02 by 1.7.2