/****************************************************************************** Copyright (C), 2001-2012, Texas Instrument. ****************************************************************************** File Name : KeyStone_common.h Version : Initial Draft Author : Zhan Created : 2012/10/30 Last Modified : Description : KeyStone_common.c header file, KeyStone common miscellaneous functions and definitions Function List : History : 1.Date : 2010-12-12 Author : Brighton Feng Modification: Created file 2.Date : 2012/10/6 Author : Brighton Feng Modification : For memory protection configuration 3.Date : 2014-12-8 Author : Brighton Feng Modification : Add common device, CPU, interrupt initialization functions. Print device information including device type, speed grade, boot mode, required voltage, ID�� Add EDMA enable/disable functions. To support square wave generation by timer. ******************************************************************************/ #ifndef _KEYSTONE_COMMON_H_ #define _KEYSTONE_COMMON_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*----------------------PLL registers definition----------------*/ #define PLLCTL0_PLLD_SHIFT (0) #define PLLCTL0_PLLD_MASK (0x3F<>4) | 0x80000000) /*max number in two numbers*/ #define MAX(a, b) (a>b?a:b) /*min number in two numbers*/ #define MIN(a, b) (a0xFFFF*4) byteCnt= 0xFFFF*4; if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2 { CACHE_invL1d((void *)blockPtr, byteCnt, CACHE_WAIT); CSL_XMC_invalidatePrefetchBuffer(); } else if((Uint32)blockPtr>=0x10000000) //DDR or other cores { CACHE_invL2((void *)blockPtr, byteCnt, CACHE_WAIT); CSL_XMC_invalidatePrefetchBuffer(); } _mfence(); _mfence(); #if CACHE_DISABLE_INT /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations Issue" described in errata of some devices*/ asm(" nop 8"); asm(" nop 8"); _restore_interrupts(uiOldGIE); //restore interrupt #endif } static inline void WritebackCache(void * blockPtr, Uint32 byteCnt) { if(byteCnt>0xFFFF*4) byteCnt= 0xFFFF*4; if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2 { CACHE_wbL1d((void *)blockPtr, byteCnt, CACHE_WAIT); } else if((Uint32)blockPtr>=0x10000000) //DDR or other cores { CACHE_wbL2((void *)blockPtr, byteCnt, CACHE_WAIT); } _mfence(); _mfence(); } static inline void WritebackAllCache(void * blockPtr) { if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2 { CACHE_wbAllL1d(CACHE_WAIT);; } else if((Uint32)blockPtr>=0x10000000) //DDR or other cores { CACHE_wbAllL2(CACHE_WAIT); } _mfence(); _mfence(); } static inline void WritebackInvalidCache(void * blockPtr, Uint32 byteCnt) { #if CACHE_DISABLE_INT /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations Issue" described in errata of some devices*/ Uint32 uiOldGIE= _disable_interrupts(); #endif if(byteCnt>0xFFFF*4) byteCnt= 0xFFFF*4; if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2 { CACHE_wbInvL1d((void *)blockPtr, byteCnt, CACHE_WAIT); CSL_XMC_invalidatePrefetchBuffer(); } else if((Uint32)blockPtr>=0x10000000) //DDR or other cores { CACHE_wbInvL2((void *)blockPtr, byteCnt, CACHE_WAIT); CSL_XMC_invalidatePrefetchBuffer(); } _mfence(); _mfence(); #if CACHE_DISABLE_INT /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations Issue" described in errata of some devices*/ asm(" nop 8"); asm(" nop 8"); _restore_interrupts(uiOldGIE); //restore interrupt #endif } static inline void WritebackInvalidAllCache(void * blockPtr) { #if CACHE_DISABLE_INT /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations Issue" described in errata of some devices*/ Uint32 uiOldGIE= _disable_interrupts(); #endif if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2 { CACHE_wbInvAllL1d(CACHE_WAIT);//CACHE_invL1d((void *)blockPtr, byteCnt, CACHE_WAIT); CSL_XMC_invalidatePrefetchBuffer(); } else if((Uint32)blockPtr>=0x10000000) //DDR or other cores { //CACHE_invL2((void *)blockPtr, byteCnt, CACHE_WAIT); CACHE_wbInvAllL2(CACHE_WAIT); CSL_XMC_invalidatePrefetchBuffer(); } _mfence(); _mfence(); #if CACHE_DISABLE_INT /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations Issue" described in errata of some devices*/ asm(" nop 8"); asm(" nop 8"); _restore_interrupts(uiOldGIE); //restore interrupt #endif } static inline unsigned int SWAP_ENDIAN(unsigned int byte_index) { #ifdef _BIG_ENDIAN return ((byte_index&0xFFFFFFFC)+(3-byte_index&3)); #else return byte_index; #endif } static inline void KeyStone_CIC_clear_system_event(CSL_CPINTCRegs* cpIntcRegs, int input_event_num) { volatile Uint32 dummy_value; /*clear input interrupts events*/ cpIntcRegs->STATUS_CLR_INDEX_REG= input_event_num; /*dummy read to make sure the previous write data land into the register*/ dummy_value= cpIntcRegs->STATUS_CLR_INDEX_REG; } static inline void KeyStone_CIC_disable_host_int(CSL_CPINTCRegs* cpIntcRegs, int host_int_num) { volatile Uint32 dummy_value; /* Disable the host interrupt */ cpIntcRegs->HINT_ENABLE_CLR_INDEX_REG = host_int_num; /*dummy read to make sure the previous write data land into the register*/ dummy_value= cpIntcRegs->HINT_ENABLE_CLR_INDEX_REG; } static inline void KeyStone_CIC_enable_host_int(CSL_CPINTCRegs* cpIntcRegs, int host_int_num) { volatile Uint32 dummy_value; /* Enable the host interrupt */ cpIntcRegs->HINT_ENABLE_SET_INDEX_REG = host_int_num; /*dummy read to make sure the previous write data land into the register*/ dummy_value= cpIntcRegs->HINT_ENABLE_SET_INDEX_REG; } static inline void KeyStone_CIC_event_map(CSL_CPINTCRegs* cpIntcRegs, int input_event_num, int out_num) { /*Map input event to output*/ cpIntcRegs->CH_MAP[SWAP_ENDIAN(input_event_num)]= out_num; /*clear input interrupts events*/ cpIntcRegs->STATUS_CLR_INDEX_REG= input_event_num; /*enable input interrupts events*/ cpIntcRegs->ENABLE_SET_INDEX_REG= input_event_num; /*enable output*/ cpIntcRegs->HINT_ENABLE_SET_INDEX_REG= out_num; } typedef enum { DUAL_NYQUIST_EVM = 0, C6670_EVM, C6678_EVM, TCI6614_EVM, C6657_EVM, UNKNOWN }TDSP_Board_Type; extern TDSP_Board_Type gDSP_board_type; static inline TDSP_Board_Type KeyStone_Get_dsp_board_type() { Uint32 deviceID= gpBootCfgRegs->DEVICE_ID_REG0&0x0FFFFFFF; gDSP_board_type= UNKNOWN; if(0x0009D02F == deviceID) gDSP_board_type= DUAL_NYQUIST_EVM; if(0x0B94102F == deviceID) { gDSP_board_type= C6670_EVM; //DSP_Board_Type= DUAL_NYQUIST_EVM; } if(0x0009E02F == deviceID) gDSP_board_type= C6678_EVM; if(0x0B96202F == deviceID) gDSP_board_type= TCI6614_EVM; if(0x0B97A02F == deviceID) gDSP_board_type= C6657_EVM; return gDSP_board_type; } static inline Uint32 KeyStone_Get_DSP_Number() { TDSP_Board_Type DSP_Board_Type= KeyStone_Get_dsp_board_type(); if(DUAL_NYQUIST_EVM==DSP_Board_Type) { /*Nyquist EVM use boot configure pin 4 and 5 to identify DSPs*/ return (( gpBootCfgRegs->BOOT_REG0 >> (3+1) ) & 0x03); } /*if use DNUM to differentiate DSPs for two DSPs test, the program must be run on core 0 of DSP 0 and core 1 of DSP1*/ return DNUM; } /*clear all interrupt flag/status, setup ISTP to begining of LL2*/ extern void CPU_interrupt_init(); /*enable interrupt to CPU: IER |= uiIER_en_mask; GIE=1*/ extern void CPU_interrupt_enable(Uint32 uiIER_en_mask); //get device speed grade from the EFUSE register extern void KeyStone_get_device_speed_grade(); /*Get device information including device type, boot mode, endian information, speed grade, required voltage...*/ extern void KeyStone_get_device_info(); /*common initialization for internal modules in K2 device. enable memory protection interrupts, EDC for MSMC RAM*/ extern void KeyStone_common_device_init(); /* enable TSC, EDC for local RAM; clear cache; protect L1 as cache */ extern void KeyStone_common_CPU_init(); #endif