/*****************************************************************************
Copyright(c) 2005 Analog Devices, Inc.  All Rights Reserved. This software is 
proprietary and confidential to Analog Devices, Inc. and its licensors.
******************************************************************************

$RCSfile: JPEGImageEdgeDetection_Heap.c,v $
$Revision: 1.1 $
$Date: 2007/05/22 18:37:56 $

Project:	BlackfinSDK (JPEG Image Edge Detection)
Title:		heap services for JPEG Image Edge Detection
Author(s):	dwu
Revised by: bmk

Description:
			Function to set up the heaps for edge detection on JPEG image

References:
			None

******************************************************************************
Tab Setting:			4

Target Processor:		ADSP-BF5xx
Target Tools Revision:	ADSP VisualDSP++ v4.5
******************************************************************************

Modification History:
====================
$Log: JPEGImageEdgeDetection_Heap.c,v $
Revision 1.1  2007/05/22 18:37:56  gstephan
Creating VDSP 5.00 release folder.  Created from the head copy of
VDSP 4.50 release folder.

Revision 1.3  2006/11/03 07:11:18  bmk
SDK 2.0  files - Initial Entry

Revision 1.1  2006/07/25 08:09:09  bmk
initial entry


*****************************************************************************/

#pragma default_section(CODE, "sdram0_bank1") 

#include <JPEGImageEdgeDetection_System.h>

static int heapid = 0; 

extern int ldf_heap_space;
extern int ldf_heap_length;
extern void ldf_slow_heap_space;
extern size_t ldf_slow_heap_length;
extern void ldf_fast_heap_space;
extern size_t ldf_fast_heap_length;

extern void ldf_stack_space;
extern size_t ldf_stack_length;


int setup_heap(void *at, size_t bytes) 
{ 
   int index; 

   if ( (index = heap_install(at,bytes,++heapid)) == -1) {
#ifdef ADI_MMSK_EXTRA_INFO		// Extra debug information        
        printf(("Failed to initialize heap with userid %d\n",heapid)); 
#endif        
        exit(EXIT_FAILURE); 
   } 
   return index; 
} 


int InstallCodecHeaps(void)
{	
    int temp;

#ifdef ADI_MMSK_EXTRA_INFO		// Extra debug information

	printf("stack is installed in L1 memory");
	printf("---> starting at 0x%x, size %d kbytes\n", &ldf_stack_space, (int)&ldf_stack_length/1024 );
	printf("installing fast heap in non-cacheable L1 memory");
	
#endif

	temp = setup_heap( &ldf_slow_heap_space, (size_t)&ldf_slow_heap_length);

#ifdef ADI_MMSK_EXTRA_INFO		// Extra debug information

	printf("---> index 0, starting at 0x%x, size %d kbytes\n", &ldf_heap_space, (int)&ldf_heap_length/1024 );
	printf("installing slow heap in cacheable external memory");	
	printf("---> index %d, starting at 0x%x, size %d kbytes\n", temp, &ldf_slow_heap_space, (int)&ldf_slow_heap_length/1024);
	printf("installing fast heap in non-cacheable L1 memory");
	
#endif

	temp = setup_heap( &ldf_fast_heap_space, (size_t)&ldf_fast_heap_length);
	
#ifdef ADI_MMSK_EXTRA_INFO		// Extra debug information
	
	printf("---> index %d, starting at 0x%x, size %d kbytes\n", temp, &ldf_fast_heap_space, (int)&ldf_fast_heap_length/1024);

#endif
		
	return temp;
}


