/**********************************************************************

Copyright(c) Analog Devices, Inc. All Rights Reserved. 

This software is proprietary and confidential.  By using this software 
you agree to the terms of the associated Analog Devices License Agreement.  

$RCSfile: filesystem.c,v $
$Revision: 1.2 $
$Date: 2008/06/06 06:11:48 $

Description:
	Initialises ADI File System Service

******************************************************************************

Include files

*****************************************************************************/
//#define _DEBUG_ALLOC_
/* Personalized Memory Allocation Routines */
//#if defined(_DEBUG_ALLOC_)
//#include "adi_dbgmem.h"
//#endif


#include <services/fss/adi_fss.h> 
#include "mediaplayer.h"
/*******************************************************************
* Device Driver headers
*   Add all relevant headers
*******************************************************************/

/* File Sytem Drivers 
 * ******************
*/

/* FAT12/16/32 FSD driver */

/* instruct the compiler to include code for FSD def from the header. 
 * comment out the following line and add your own configuration if 
 * required */
 /* FAT12/16/32 FSD driver */
#define _ADI_FAT_DEFAULT_DEF_
#include <drivers/fsd/fat/adi_fat.h>
//#include <drivers/fsd/fat/adi_fat.h>

/* Physical Interface Device Drivers 
 * *********************************
*/

/* Only MOAB supports HDD and SD Card media*/
#if defined(__ADSP_MOAB__)
/* ATAPI interface */
#define _ADI_ATAPI_DEFAULT_DEF_
#include <drivers/pid/atapi/adi_atapi.h>

/* SDH interface */
#define _ADI_SDH_DEFAULT_DEF_
#include <drivers/pid/sdh/adi_sdh.h>
#endif

/* USB interface */
#define _ADI_USB_DEFAULT_DEF_
#include <drivers/pid/usb/adi_usb.h>

#include <heapinfo.h>

int init_fss(void);

/*********************************************************************

    Function:       InitFileSystem
    Description:    Initialises File System Service

*********************************************************************/

int init_fss(void) 
{
    u32 Result = ADI_DEV_RESULT_SUCCESS;

    /*******************************************************************
    * Customized heaps for General, fat and atapi 'cache' type data
    *******************************************************************/
//#if 0    
//	int GeneralHeapID   = heap_lookup(1);
	int GeneralHeapID   = 1;

    /*******************************************************************
    * command table for the FAT driver
    *******************************************************************/
    static ADI_DEV_CMD_VALUE_PAIR ADI_FAT_ConfigTable [] = {
            { ADI_FSS_CMD_SET_CACHE_HEAP_ID,   (void*)0 },
            { ADI_DEV_CMD_END,                 NULL     },
    };
    ADI_FAT_ConfigTable[0].Value = (void*)GeneralHeapID;

    /*******************************************************************
    * definition structure for FAT driver - exported to application
    *******************************************************************/
    static ADI_FSS_DEVICE_DEF ADI_FAT_Def = {
        0,                                      /* N/A for FSD drivers                    */
        &ADI_FAT_EntryPoint,                    /* Entry Points for FAT Driver            */
        ADI_FAT_ConfigTable,                    /* Command Table to configure FAT driver  */
        NULL,                                   /* Critical region data                   */
        ADI_DEV_DIRECTION_BIDIRECTIONAL,        /* Direction (RW file system)             */
        NULL
    };
	
    /*******************************************************************
    * Configuration table to initialize the FSS
    *******************************************************************/
    ADI_FSS_CMD_VALUE_PAIR adi_fss_Config[] = 
    {
//        { ADI_FSS_CMD_SET_NUMBER_CACHE_BLOCKS,      (void*)4                        },
        { ADI_FSS_CMD_SET_NUMBER_CACHE_BLOCKS,      (void*)2                        },
//        { ADI_FSS_CMD_SET_NUMBER_CACHE_SUB_BLOCKS,  (void*)1                        },
        { ADI_FSS_CMD_SET_GENERAL_HEAP_ID,          (void*)GeneralHeapID            },
        
        /* Add Media Devices - one command per type of Media Device Present */

        //{ ADI_FSS_CMD_ADD_DRIVER,                   (void*)&ADI_ATAPI_Def           },
        { ADI_FSS_CMD_ADD_DRIVER,                   (void*)&ADI_USB_Def             },
#if defined(__ADSP_MOAB__)        
        { ADI_FSS_CMD_ADD_DRIVER,                   (void*)&ADI_SDH_Def             },
        { ADI_FSS_CMD_ADD_DRIVER,                   (void*)&ADI_ATAPI_Def           },
#endif
        /* Add File Systems - one command per type of File System Present */
        { ADI_FSS_CMD_ADD_DRIVER,                   (void*)&ADI_FAT_Def             },
        
        /* DMA and Device Manager Handles */
        { ADI_FSS_CMD_SET_DMA_MGR_HANDLE,           (void*)adi_dma_ManagerHandle    },
        { ADI_FSS_CMD_SET_DEV_MGR_HANDLE,           (void*)adi_dev_ManagerHandle    },
        { ADI_FSS_CMD_SET_DCB_MGR_HANDLE,           (void*)adi_dcb_QueueHandle      },
        
        /* Command Table Terminator */
        { ADI_FSS_CMD_END,                          (void*)NULL                     }
    };
    
    /* Initialise the file system service */
    Result = adi_fss_Init ( adi_fss_Config );

    /* Add to CRT device table - which will make it the default */
    add_devtab_entry( &adi_fss_entry );
//#endif   
    return (Result);
}

/*****/
