#if defined(__PIC24F__)
#include <p24Fxxxx.h>
#endif
#include "pmp.h"



#ifdef _PPI_PMP_V1

/******************************************************************************
 * Function:        PMPSetAddress
 *
 * PreCondition:    None
 *
 * Input:           16-bit value to be written to external device
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        
 * 					
 * Note:			Use in MASTER mode 1 or 2, MODE[1:0] = 10, 11 
 *****************************************************************************/
void PMPSetAddress(WORD address)
{
	static const unsigned int addrsMask[]={0x0000FFFF,
										   0x00003FFF,
										   0x00007FFF,
										   0x00003FFF};
	unsigned int cs;
	
	cs =  (PMADDR & BIT_CS2_CS1_ON) >> 14;
	address = address & addrsMask[cs]	;
	PMADDR = (PMADDR & BIT_CS2_CS1_ON) + address;
}

/* end of file */
#else
#warning "Does not build on this target"
#endif
