/*****************************************************************************
** al_setting.h: AL Layer System Setting Header File
**
** Description: the interface of system setting module.
**
** Copyright(c) 2011 Sunmedia Technologies - All Rights Reserved
**
** Author : anlzhao
**
** $Id: al_setting.h 1901 2011-01-22 05:47:03Z liang.wu_c1 $
*****************************************************************************/

#ifndef __AL_SETTING_H__
#define __AL_SETTING_H__

#include "al_basictypes.h"

//#include "nvm_mgr.h"

/*
** Marco define
*/
/* MAX open count of devices at one time*/
#define MAX_DEVICE			(20)
/* MAX count of components in a virtual device */
#define MAX_NUM_COMP		(250)
/* CRC size */
#define CRC_INFO_SIZE		(0)
/* define handle of virtual device */
#define INVAILDHANDLE		(-1)

/* macro define to get the item offset within given structure */
#define SYSTEM_SET_ITEM_OFFSET(type, field) ((UINT32)&(((type *)0)->field))
/* macro define to get the item size within given structure */
#define SYSTEM_SET_ITEM_SIZE(type, field) (sizeof ((type *)0)->field)

#ifdef __cplusplus
	extern "C"{
#endif

typedef al_int32 AL_SETTING_HANDLE;

/*****************************************************************************
** FUNCTION : AL_Setting_Open
**
** DESCRIPTION :
**				This method initializes the user preference component.
**				Notice:This function must be first before any functions
**				are called
**
** PARAMETERS :
**				VirtualDev_Dev_t	- Storage device
**				size_arr	- Array of component sizes
**				addr_arr	- Array of component address
**				num_comp	- No. of components
**				p_stParam	- Device registered functions
**
** RETURN VALUES:
**				AL_SETTING_HANDLE
*****************************************************************************/
AL_SETTING_HANDLE AL_Setting_Open(
	const al_uint16* size_arr, const al_uint32* addr_arr, const al_uint32* tech_arr, al_uint8 num_comp);

/*****************************************************************************
** FUNCTION : AL_Setting_Close
**
** DESCRIPTION :
**				This method terminates the storage device for user
**				preference component, save all data and releases all
**				resources occpied by the technology
**
** PARAMETERS :
**				handle	- handle Storage device
**
** RETURN VALUES:
**				AL_SUCCESS
**				AL_FAILURE
**				AL_INVALID_PARAM
*****************************************************************************/
AL_Return_t AL_Setting_Close(AL_SETTING_HANDLE handle);

/*****************************************************************************
** FUNCTION : AL_Setting_Read
**
** DESCRIPTION :
**				This method gets the specific user setting from certail
**				memory cache asked by the component from memory cache
**
** PARAMETERS :
**				handle	- handle of Storage device
**				user_pref_id- Fixed unique Id assigned to each component
**				offset		- Starting byte position from which data is read
**				num_bytes	- No.of bytes required by the component
**				data		- Data asked for by the calling component
**
** RETURN VALUES:
**				AL_SUCCESS
**				AL_FAILURE
**				AL_INVALID_PARAM
*****************************************************************************/
AL_Return_t AL_Setting_Read(AL_SETTING_HANDLE handle,
	al_uint8 user_pref_id, al_uint32 offset, al_uint16 num_bytes,
	al_void *data);

/*****************************************************************************
** FUNCTION : AL_Setting_ReadDefault
**
** DESCRIPTION :
**				This method gets the default user setting to memory cache
**				Notice:when user_pref_id is equal to 0xFF, it represents
**				reading all default items of certain storage device
**
** PARAMETERS :
**				handle	- handle of Storage device
**				user_pref_id- Fixed unique Id assigned to each component
**				data		- Default Data
**
** RETURN VALUES:
**				AL_SUCCESS
**				AL_FAILURE
**				AL_INVALID_PARAM
*****************************************************************************/
AL_Return_t AL_Setting_ReadDefault(AL_SETTING_HANDLE handle,
	al_uint8 user_pref_id, const al_void *data);

/*****************************************************************************
** FUNCTION : AL_Setting_Write
**
** DESCRIPTION :
**				This method writes the user data into user setting cache
**
** PARAMETERS :
**				handle	- handle of Storage device
**				user_pref_id- Fixed unique Id assigned to each component
**				offset		- Starting position from which data is written
**				num_bytes	- No. of bytes required by the component
**				data		- Data to be written onto cache
**
** RETURN VALUES:
**				AL_SUCCESS
**				AL_FAILURE
**				AL_INVALID_PARAM
*****************************************************************************/
AL_Return_t AL_Setting_Write(AL_SETTING_HANDLE handle,
	al_uint8 user_pref_id, al_uint32 offset, al_uint16 num_bytes,
	const al_void *data);

/*****************************************************************************
** FUNCTION : AL_Setting_Reload
**
** DESCRIPTION :
**				This method retrieves the user setting from actual
**				storage device into memory cache.
**				Notice:when user_pref_id is equal to 0xFF, it represents
**				retrieving all items
**
** PARAMETERS :
**				handle	- handle of Storage device
**				user_pref_id- Fixed unique Id assigned to each component
**
** RETURN VALUES:
**				AL_SUCCESS
**				AL_FAILURE
**				AL_INVALID_PARAM
*****************************************************************************/
AL_Return_t AL_Setting_Reload(AL_SETTING_HANDLE handle,
	al_uint8 user_pref_id);

/*****************************************************************************
** FUNCTION : AL_Setting_Store
**
** DESCRIPTION :
**				This method stores the user setting into actual storage
**				device from memory cache.
**				Notice:when id is equal to 0xFF, it represents
**				to store all items
**
** PARAMETERS :
**				handle	- handle ofStorage device
**				id			- Fixed unique Id assigned to each component
**				item_offset	- component item offset
**				num_bytes	- number of data need to store
**
** RETURN VALUES:
**				AL_SUCCESS
**				AL_FAILURE
**				AL_INVALID_PARAM
*****************************************************************************/
AL_Return_t AL_Setting_Store(AL_SETTING_HANDLE handle,
	al_uint8 user_pref_id, al_uint32 offset, al_uint16 num_bytes);

#ifdef __cplusplus
	}
#endif /* __cplusplus */

#endif /* __AL_SETTING_H__ */

/*****************************************************************************
** $Rev: 1901 $
**
*****************************************************************************/
