/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

/*!
 *\file
 *\brief
 *		 Hardware Abstraction Layer functions for accessing Metroam Hardware
 */

#ifndef __MR_HAL_H__
#define __MR_HAL_H__

/******************************************************************************
* Include Files
******************************************************************************/
#include <api_oam_sdk/common/registers/inc/mr_registers.h>
#include "egl_types.h"

/******************************************************************************
* Define Constants for Indirect Memory Access
******************************************************************************/
#define IND_ACC_INIT_MASK	(0x80000000)
#define IND_READ_MASK		(0x00000000)
#define IND_WRITE_MASK		(0x08000000)
#define IND_MAX_POLL		(200)

/******************************************************************************
* Enumerated data type for selection of indirect memories in the MetRoam Device
******************************************************************************/
typedef enum indirectRamEnum {
	PKT_STORE_SEL				= 0,
	PROBE_STORE_SEL				= 1,
	XCONN_STORE_SEL				= 2,
	RMEP_ERR_STORE_SEL			= 3,
	RX_LMEP_MAP_SEL				= 4,
	CPU_SYS_CAPT_FIFO_SEL		= 5,
	RMEP_RAM_SEL				= 6,
	XCONN_RAM_SEL				= 7,
	RMEP_ERR_RAM_SEL			= 8,
	TX_LMEP_MAP_SEL				= 9,
	EXT_SRAM_SEL				= 10,
	CARRMAC_SEL					= 11,
	SYSMAC_SEL					= 12,
	RX_CARR_DATA_FIFO_SEL		= 13,
	LINE_STATS_RAM_SEL			= 14,
	CPU_SYS_CAPT_INFO_FIFO_SEL	= 15,
	VLAN_INFO_RAM_SEL			= 16,
	LBM_STORE_SEL				= 17,
	LBR_RAM_SEL					= 18,
	MC_LBR_STORE_SEL			= 19,
	PORT_MAC_RAM_SEL			= 20,
	PM_DB_RAM_SEL				= 22,
	TX_LB_RAM_SEL				= 24,
	TLV_RAM_SEL					= 25,
	CPU_CAPT_FIFO_SEL			= 26,
	CPU_CAPT_INFO_FIFO_SEL		= 27,
	POLICER_CFG_RAM_SEL			= 28,
	POLICER_CTXT_RAM_SEL		= 29,
	POLICER_STATS_RAM_SEL		= 30,
	CPU_SYS_TX_RAM_SEL			= 31
} indirectRamSel_t;

#define	RMEP_MAP_RAM_SEL	(RX_LMEP_MAP_SEL)	//!< The RMEP_MAP and RX_LMEP share the same RAM
#define	PM_STATS_RAM_SEL	(EXT_SRAM_SEL)		//!< The PM_STATS is relocated to EXT_SRAM

#ifdef CPP
	extern "C" {
#endif

/******************************************************************************
* Define Function prototypes for the HAL API functions
******************************************************************************/
/*!
 *\brief
 * Initialise the HAL for the MetRoam device.
 *
 * This function must be called before any other calls to other HAL functions in
 * order to allocate the required Mutex and acquire a log handle. <br>
 * May safely be called multiple times, initialisation will be performed only
 * on the first instance.
 *
 */
void mrHalInit(uint32_t);

/*!
 *\brief
 * Read the 32-bit value of a register in the MetRoam device.
 *
 *\param[in]	regAddr		The offset to the register within the MetRoam device.
 *\param[out]	*rdData		pointer to the where the newly read value will be placed.
 */
void mrHalRegRead(uint16_t regAddr, uint32_t *rdData);

/*!
 *\brief
 * Write a new 32-bit value to an indirectly accessed memory in the MetRoam device.
 *
 *\param[in]	regAddr		The offset to the register within the MetRoam device.
 *\param[out]	wrData		The new 32-bit value to write.
 */
void mrHalRegWrite(uint16_t regAddr, uint32_t wrData);

/*!
 *\brief
 * Read the 32-bit value from an indirectly accessed memory in the MetRoam device.
 *
 *\param[in]	regAddr		The (dword) offset from the start of the selected memory.
 *\param[in]	selRam		Select which memory within the MetRoam device.
 *\param[out]	*rdData		pointer to the where the newly read value will be placed.
 */
void mrHalRamRead(uint32_t ramAddr, indirectRamSel_t selRam, uint32_t *rdData);

/*!
 *\brief
 * Write a new 32-bit value to an indirectly accessed memory in the MetRoam device.
 *
 *\param[in]	regAddr		The (dword) offset from the start of the selected memory.
 *\param[in]	selRam		Select which memory within the MetRoam device.
 *\param[out]	wrData		The new 32-bit value to write.
 */
void mrHalRamWrite(uint32_t ramAddr, indirectRamSel_t selRam, uint32_t wrData);
#ifdef CPP
	}
#endif

#endif
