/** @file sys_pmu.h
*   @brief System Pmu Header File
*   @date 01.October.2010
*   @version 1.01.000
*   
*   This file contains:
*   - Pmu Interface Functions
*   .
*   which are relevant for the performance monitor unit driver.
*/

/* (c) Texas Instruments 2010, All rights reserved. */

#ifndef __SYS_PMU_H__
#define __SYS_PMU_H__

/* USER CODE BEGIN (0) */
/* USER CODE END */

/** @def pmuCOUNTER0
*   @brief pmu event counter 0
*
*   Alias for pmu event counter 0
*/
#define pmuCOUNTER0 0x00000001U

/** @def pmuCOUNTER1
*   @brief pmu event counter 1
*
*   Alias for pmu event counter 1
*/
#define pmuCOUNTER1 0x00000002U


/** @def pmuCYCLE_COUNTER
*   @brief pmu cycle counter
*
*   Alias for pmu event counter
*/
#define pmuCYCLE_COUNTER 0x80000000U

/** @enum pmuEvent
*   @brief pmu event
*
*   Alias for pmu event counter increment source
*/

enum pmuEvent
{
	SOFTWARE_INCREMENT 				=0x0,
	INSTRUCTION_CACHE_MISS 				=0x1,
	INSTRUCTION_TLB_MISS				=0x2, 
	DATA_CACHE_MISS 				=0x3,
	DATA_CACHE_ACCESS				=0x4, 														
	DATA_MICRO_TLB_MISS				=0x5 ,													
	DATA_READ					=0x6, 															
	DATA_WRITES					=0x7, 
	INSTRUCTION_EXECUTED				=0x8, 														
	EXCEPTION_TAKEN	 				=0x9,
	EXCEPTION_RETURNS 				=0xA,										
	CHANGE_CONTEXT_ID 				=0xB,										
	SOFTWARE_CHANGE_OF_PC 				=0xC,									
	IMMEDIATE_BRANCH 				=0xD,
	PROCEDURE_RETURN				=0xE,		
	UNALIGNED 					=0xf	,
	BRANCH_MISPREDICTED_OR_NOT_PREDICTED 		=0x10	,								
	CYCLE_COUNT 					=0x11	,										
	PREDICTABLE_BRANCHES 				=0x12	,									
	DATA_MEM_ACCESS					=0x13	,
	INST_CACHE_ACCESS				=0x14	,
	DATA_CACHE_EVICTION				=0x15	,
	IRQ_EXECPTION_TAKEN				=0x86	,
	FIQ_EXECPTION_TAKEN				=0x87	,
	EXTERNAL_MEM_ACCESS				=0xC0	,
	NON_CACHEABLE_EXT_MEM_REQ			=0xC1	,
	LINEFILL_BECAUSE_PREFETCH			=0xC2	,
	PREFETCH_LINEFILL_DROP				=0xC3	,
	ENTERING_READ_ALLOCATE_MODE			=0xC4	,
	READ_ALLOCATE_MODE				=0xC5	,
	ETM_EXT_OUT0					=0xC7	,
	ETM_EXT_OUT1					=0xC8	,
	DATA_WRITE_STALLS_PIPELINE_BECAUSE_STORE_BUFFER_FULL 	=0xC9	
		
};

/** @fn void _pmuInit_(void)
*   @brief Initialize Perfprmance Monitor Unit
*/
void _pmuInit_(void);

/** @fn void _pmuEnableCountersGlobal_(void)
*   @brief Enable and reset cycle counter and all 3 event counters
*/
void _pmuEnableCountersGlobal_(void);

/** @fn void _pmuDisableCountersGlobal_(void)
*   @brief Disable cycle counter and all 3 event counters
*/
void _pmuDisableCountersGlobal_(void);

/** @fn void _pmuResetCycleCounter_(void)
*   @brief Reset cycle counter
*/
void _pmuResetCycleCounter_(void);

/** @fn void _pmuResetEventCounters_(void)
*   @brief Reset event counters 0-2
*/
void _pmuResetEventCounters_(void);

/** @fn void _pmuResetCounters_(void)
*   @brief Reset cycle counter and event counters 0-2
*/
void _pmuResetCounters_(void);

/** @fn void _pmuStartCounters_(unsigned counters)
*   @brief Starts selected counters
*   @param[in] counters - Counter mask
*/
void _pmuStartCounters_(unsigned counters);

/** @fn void _pmuStopCounters_(unsigned counters)
*   @brief Stops selected counters
*   @param[in] counters - Counter mask
*/
void _pmuStopCounters_(unsigned counters);

/** @fn void _pmuSetCountEvent_(unsigned counter, unsigned event)
*   @brief Set event counter count event
*   @param[in] counter - Counter select 0..2
*   @param[in] event   - Count event
*/
void _pmuSetCountEvent_(unsigned counter, unsigned event);

/** @fn unsigned _pmuGetCycleCount_(void)
*   @brief Returns current cycle counter value
*
*   @return cycle count.
*/
unsigned _pmuGetCycleCount_(void);

/** @fn unsigned _pmuGetEventCount_(unsigned counter)
*   @brief Returns current event counter value
*   @param[in] counter - Counter select 0..2
*
*   @return event counter count.
*/
unsigned _pmuGetEventCount_(unsigned counter);

/** @fn unsigned _pmuGetOverflow_(void)
*   @brief Returns current overflow register and clear flags
*
*   @return overflow flags.
*/
unsigned _pmuGetOverflow_(void);

/** @fn void _pmuUserEnable_(void)
*   @brief Enable access to PMU from user mode
*/
void _pmuUserEnable_(void);

//void perf_set(long evt0,long evt1 ,long evt2 ,long evt3 ,long evt4 ,long evt5 ,long evt6 ,long evt7 );

#endif
