#ifdef DYNAMIC_CODE_MANAGER
#if defined(DCM_SCAT_CODE1_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE1$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE1$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE1$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE2_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE2$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE2$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE2$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE3_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE3$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE3$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE3$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE4_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE4$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE4$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE4$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE5_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE5$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE5$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE5$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE6_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE6$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE6$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE6$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE7_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE7$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE7$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE7$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE8_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE8$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE8$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE8$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE9_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE9$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE9$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE9$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE10_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE10$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE10$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE10$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE11_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE11$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE11$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE11$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE12_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE12$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE12$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE12$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE13_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE13$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE13$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE13$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE14_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE14$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE14$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE14$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE15_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE15$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE15$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE15$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE16_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE16$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE16$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE16$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE17_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE17$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE17$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE17$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE18_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE18$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE18$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE18$$ZI$$Length;
#endif
#if defined(DCM_SCAT_CODE19_AVAILABLE)
extern kal_uint32 Load$$DYNAMIC_CODE19$$Base;
extern kal_uint32 Image$$DYNAMIC_CODE19$$Length;
extern kal_uint32 Image$$DYNAMIC_CODE19$$ZI$$Length;
#endif
/* Although introducing compiler warning,
"C2564W: extended constant initialiser used",
but code size saved, and readibility improved.
Base, RO-length, ZI-length */
static const kal_uint32 DCM_linker_symbols_by_dynamic_code_id[DYNAMIC_CODE_NUM * 3] = {
/* DYNCMIC_CODE1 */
#if defined(DCM_SCAT_CODE1_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE1$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE1$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE1$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE2 */
#if defined(DCM_SCAT_CODE2_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE2$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE2$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE2$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE3 */
#if defined(DCM_SCAT_CODE3_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE3$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE3$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE3$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE4 */
#if defined(DCM_SCAT_CODE4_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE4$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE4$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE4$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE5 */
#if defined(DCM_SCAT_CODE5_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE5$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE5$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE5$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE6 */
#if defined(DCM_SCAT_CODE6_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE6$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE6$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE6$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE7 */
#if defined(DCM_SCAT_CODE7_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE7$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE7$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE7$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE8 */
#if defined(DCM_SCAT_CODE8_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE8$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE8$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE8$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE9 */
#if defined(DCM_SCAT_CODE9_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE9$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE9$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE9$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNCMIC_CODE10 */
#if defined(DCM_SCAT_CODE10_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE10$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE10$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE10$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE11 */
#if defined(DCM_SCAT_CODE11_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE11$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE11$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE11$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE12 */
#if defined(DCM_SCAT_CODE12_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE12$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE12$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE12$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE13 */
#if defined(DCM_SCAT_CODE13_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE13$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE13$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE13$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE14 */
#if defined(DCM_SCAT_CODE14_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE14$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE14$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE14$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE15 */
#if defined(DCM_SCAT_CODE15_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE15$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE15$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE15$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE16 */
#if defined(DCM_SCAT_CODE16_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE16$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE16$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE16$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE17 */
#if defined(DCM_SCAT_CODE17_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE17$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE17$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE17$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE18 */
#if defined(DCM_SCAT_CODE18_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE18$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE18$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE18$$ZI$$Length,
#else
0,0,0,
#endif
/* DYNAMIC_CODE19 */
#if defined(DCM_SCAT_CODE19_AVAILABLE)
(kal_uint32)&Load$$DYNAMIC_CODE19$$Base,
(kal_uint32)&Image$$DYNAMIC_CODE19$$Length,
(kal_uint32)&Image$$DYNAMIC_CODE19$$ZI$$Length,
#else
0,0,0,
#endif
};
static kal_int32 current_dynamic_code_id[DCM_TARGET_NUM] = {
DYNAMIC_CODE_NONE,
#if defined(DCM_TARGET_ADDRESS2)
DYNAMIC_CODE_NONE,
#endif
#if defined(DCM_TARGET_ADDRESS3)
DYNAMIC_CODE_NONE,
#endif
};
static const kal_uint32 *DCM_target_pool_addr[DCM_TARGET_NUM] = {
(kal_uint32*) DCM_TARGET_ADDRESS1,
#if defined(DCM_TARGET_ADDRESS2)
(kal_uint32*) DCM_TARGET_ADDRESS2,
#endif
#if defined(DCM_TARGET_ADDRESS3)
(kal_uint32*) DCM_TARGET_ADDRESS3,
#endif
};
static const kal_uint32 DCM_target_pool_size[DCM_TARGET_NUM] = {
DCM_TARGET_SIZE1,
#if defined(DCM_TARGET_ADDRESS2)
DCM_TARGET_SIZE2,
#endif
#if defined(DCM_TARGET_ADDRESS3)
DCM_TARGET_SIZE3,
#endif
};
/*************************************************************************
* don't modify anything behind this line ; unless bug fix
**************************************************************************/
static const kal_int32 DCM_pool_by_dynamic_code_id[DYNAMIC_CODE_NUM] = {
DCM_TARGET_CONFIGURE
};
/*************************************************************************
* FUNCTION
* DCM_Load
*
* DESCRIPTION
* Dynamic code manager for relocate code into the overlay TCM region
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void DCM_Load( kal_int32 dynamic_code_id, kal_uint32 **remaining_buf, kal_uint32 *buf_size )
{
kal_uint32 *src_ptr=0, *dst_ptr;
kal_uint32 code_size=0, zi_size=0;
kal_int32 pool_id;
kal_int32 temp;
/* invalid code id --- query available address & length */
if( dynamic_code_id < 0 || dynamic_code_id >= DYNAMIC_CODE_NUM )
{
if( remaining_buf != (kal_uint32**)0)
{
for( pool_id=0; pool_id < DCM_TARGET_NUM; pool_id++)
{
if (current_dynamic_code_id[pool_id] == DYNAMIC_CODE_NONE)
{
*remaining_buf = (kal_uint32*) DCM_target_pool_addr[pool_id];
*buf_size = DCM_target_pool_size[pool_id];
return;
}
}
/* In first version, it's single pool and there was an assert check for
* current_dynamic_code_id == DYNAMIC_CODE_NONE
* before addr&size query by invalid code id.
* To sync the API behavior, there should be an assert here
*/
#define NO_AVAILABLE_POOL 0
ASSERT(NO_AVAILABLE_POOL);
}
return;
}
else
{
/* valid code id --- check source exists and check target pool already occupied */
pool_id = DCM_pool_by_dynamic_code_id[dynamic_code_id];
pool_id--; /* SEE Also : DCM_TARGET_CONFIGURE definiation */
#define DCM_SOURCE_NOT_EXISTS 0
if (pool_id < 0 || pool_id >= DCM_TARGET_NUM)
ASSERT(DCM_SOURCE_NOT_EXISTS);
#define DCM_POOL_OCCUPIED 0
if (current_dynamic_code_id[pool_id] != DYNAMIC_CODE_NONE)
EXT_ASSERT( DCM_POOL_OCCUPIED,
(kal_uint32)current_dynamic_code_id[pool_id],
(kal_uint32)dynamic_code_id,
(kal_uint32)pool_id);
}
/* setup src address, length */
src_ptr = (kal_uint32 *) DCM_linker_symbols_by_dynamic_code_id[ dynamic_code_id * 3 + 0 ];
code_size = DCM_linker_symbols_by_dynamic_code_id[ dynamic_code_id * 3 + 1 ];
zi_size = DCM_linker_symbols_by_dynamic_code_id[ dynamic_code_id * 3 + 2 ];
#define DCM_CHECK_FOUR_BYTE_ALIGN 0
EXT_ASSERT( ((kal_uint32)src_ptr&3)==0 && (code_size&3)==0 && (zi_size&3)==0, /
(kal_uint32)src_ptr, (kal_uint32)code_size, (kal_uint32)zi_size);
dst_ptr = (kal_uint32*) DCM_target_pool_addr[pool_id];
temp = DCM_target_pool_size[pool_id] - code_size - zi_size;
/* Move code from flash into ISRAM/TCM */
while ( code_size > 0 )
{
*dst_ptr++ = *src_ptr++;
code_size -= 4;
}
/* Clean ZI data area */
while( zi_size > 0 )
{
*dst_ptr++ = 0;
zi_size -= 4;
}
if( remaining_buf != (kal_uint32**)0)
{
*remaining_buf = dst_ptr;
*buf_size = temp;
}
/* clean the remaining buffer */
while ( temp > 0 )
{
*dst_ptr++ = 0;
temp -= 4;
}
current_dynamic_code_id[pool_id] = dynamic_code_id;
}
/*************************************************************************
* FUNCTION
* DCM_Unload
*
* DESCRIPTION
* Terminate the usage of DCM
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void DCM_Unload( kal_int32 dynamic_code_id )
{
if( dynamic_code_id < 0 || dynamic_code_id >= DYNAMIC_CODE_NUM )
{
/* do-nothing */
}
else
{
current_dynamic_code_id[DCM_pool_by_dynamic_code_id[dynamic_code_id] - 1] = DYNAMIC_CODE_NONE;
/* SEE Also : DCM_TARGET_CONFIGURE definiation */
}
}
/*************************************************************************
* FUNCTION
* DCM_Isloaded
*
* DESCRIPTION
* query if the DCM code already loaded
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool DCM_Isloaded( kal_int32 dynamic_code_id )
{
if( dynamic_code_id < 0 || dynamic_code_id >= DYNAMIC_CODE_NUM )
{
return KAL_FALSE;
}
else if ( current_dynamic_code_id[DCM_pool_by_dynamic_code_id[dynamic_code_id] - 1] == dynamic_code_id )
{
return KAL_TRUE;
}
return KAL_FALSE;
}
/*************************************************************************
* FUNCTION
* DCM_IsAvailable
*
* DESCRIPTION
* query if the DCM pool for the dynamic_code_id is free
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool DCM_IsAvailable( kal_int32 dynamic_code_id )
{
if( dynamic_code_id < 0 || dynamic_code_id >= DYNAMIC_CODE_NUM )
{
return KAL_FALSE;
}
else if ( current_dynamic_code_id[DCM_pool_by_dynamic_code_id[dynamic_code_id] - 1] == DYNAMIC_CODE_NONE )
{
return KAL_TRUE;
}
return KAL_FALSE;
}
#endif /* DYNAMIC_CODE_MANAGER */