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

📄 ovlymgr.c

📁 基于TS201 Sets up a skeleton overlay system in C
💻 C
字号:
//*******************************************************************
//  The OvlyMgr.c file is the overlay manager. When a symbol
//  residing in overlay is referenced, the ovelay manager loads
//  the overlay code and begins execution.  A DMA transfer is
//  performed to load in the memory overlay.
//*******************************************************************

#include <sysreg.h>
#include <builtins.h>
#include <OverlayCDef.h>

#ifdef __ADSPTS201__
	#include <defTS201.h>
#endif
#ifdef __ADSPTS101__
	#include <defTS101.h>
#endif

//************************* Externs *************************************
extern volatile bool OverlayReady;

//  The following constants are defined by the linker.  
//  These constants contain the word size, live locaton 
//  and run location of the overlay functions.	        

extern int ov_word_size_run_1;
extern int ov_word_size_run_2;
extern int ov_word_size_run_3;
extern int ov_word_size_run_4;
extern int ov_word_size_live_1;
extern int ov_word_size_live_2;
extern int ov_word_size_live_3;
extern int ov_word_size_live_4;
extern int ov_startaddress_1;
extern int ov_startaddress_2;
extern int ov_startaddress_3;
extern int ov_startaddress_4;
extern int ov_runtimestartaddress_1;
extern int ov_runtimestartaddress_2;
extern int ov_runtimestartaddress_3;
extern int ov_runtimestartaddress_4;
				     

//********************* Function declares *******************************
void SetTCB0(long DI_Source, long DX_Source, long DY_Source, long DP_Source,
             long DI_Destin, long DX_Destin, long DY_Destin, long DP_Destin);


//************************************************************************
//  		Overlay Manager Function						
//************************************************************************

void OverlayManager(int OverLayID, void (*OverLaySymbolAddress)()) 
{
	asm("_ov_start:");	// debug marker to inform IDDE of start of overlay manager
	/*  Placing the linker constants in an array so the overlay  */
	/*  manager can use the appropriate constant based on the    */
	/*  overlay id.												 */
	
	int liveAddresses[4] = {(int) &ov_startaddress_1, (int) &ov_startaddress_2, (int) &ov_startaddress_3, (int) &ov_startaddress_4};
	int runAddresses[4]  = {(int) &ov_runtimestartaddress_1, (int) &ov_runtimestartaddress_2, (int) &ov_runtimestartaddress_3, (int) &ov_runtimestartaddress_4};
	int runWordSize[4] = {(int) &ov_word_size_run_1, (int) &ov_word_size_run_2, (int) &ov_word_size_run_3, (int) &ov_word_size_run_4};
	int liveWordSize[4] = {(int) &ov_word_size_live_1, (int) &ov_word_size_live_2, (int) &ov_word_size_live_3, (int) &ov_word_size_live_4};

	TCBChain DMA0SourceTCB, DMA0DestinTCB;

	OverLayID = OverLayID - 1; 					// Overlay ID - 1
	
//-------------------------- Setup DMA TCB ------------------------------

//  Get overlay run and live addresses from memory and use to
//  set up the master mode DMA.
												
    DMA0SourceTCB.DP = TCB_EXTMEM | TCB_NORMAL | TCB_INT;
    DMA0SourceTCB.DY = 0;
    DMA0SourceTCB.DX = (liveWordSize[OverLayID] << 16) | 1; //Setup count and modify (modify=1)
    DMA0SourceTCB.DI = liveAddresses[OverLayID]; //Setup address

    
    DMA0DestinTCB.DP = TCB_INTMEM | TCB_NORMAL | TCB_INT;
    DMA0DestinTCB.DY = 0;
    DMA0DestinTCB.DX = (runWordSize[OverLayID] << 16) | 1; //Setup count and modify (modify=1)
    DMA0DestinTCB.DI = runAddresses[OverLayID]; //Setup address

    OverlayReady = false;						// Set to not ready

//------------------------- Start the DMAs ------------------------------

	SetTCB0(DMA0SourceTCB.DI, DMA0SourceTCB.DX, DMA0SourceTCB.DY, DMA0SourceTCB.DP,
            DMA0DestinTCB.DI, DMA0DestinTCB.DX, DMA0DestinTCB.DY, DMA0DestinTCB.DP);

//---------------------- Wait for DMA to complete -----------------------

	while( OverlayReady == false ){};

//  Flush the BTB.

	asm("btbinv;;");

//	Execute the function
	asm("_ov_end:");	// debug marker to inform IDDE of end of overlay manager
	OverLaySymbolAddress();
}

//***********************************************************************
// Setup DMA TCB0 register (DI_Source, DX_Source, DY_Source, DP_Source
//                          DI_Destin, DX_Destin, DY_Destin, DP_Destin)
//***********************************************************************

void SetTCB0(long DI_Source, long DX_Source, long DY_Source, long DP_Source,
             long DI_Destin, long DX_Destin, long DY_Destin, long DP_Destin)
{
    volatile __builtin_quad TCB_Clear, TCB_Set;

    TCB_Clear = __builtin_compose_128((long long)TCB_DISABLE << 32, 0);
    __builtin_sysreg_write4(__DCS0, TCB_Clear); 
    __builtin_sysreg_write4(__DCD0, TCB_Clear); 
    TCB_Set = __builtin_compose_128(((long long)DX_Source << 32) | DI_Source, ((long long)DP_Source << 32) | DY_Source);
    __builtin_sysreg_write4(__DCS0, TCB_Set); 
    TCB_Set = __builtin_compose_128(((long long)DX_Destin << 32) | DI_Destin, ((long long)DP_Destin << 32) | DY_Destin );
    __builtin_sysreg_write4(__DCD0, TCB_Set); 
}

//***********************************************************************
	

⌨️ 快捷键说明

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