/********************************************/
/*Parallel Master Port Configuration Code   */
/*dsPIC33CK512MP608                         */
/********************************************/

#include "xc.h"

#include "MainMotion.h"

void dsPIC33_PMP_Init(void)
{
    //BUSY - BUSYL
    //Since we are in slave mode we must pull BUSY
    //  high to allow writes to the port
    TRISEbits.TRISE1 = 0;
    PORTEbits.RE1 = 1;

    //INT pin from SRAM
    TRISBbits.TRISB2 = 1;
    ANSELBbits.ANSELB2 = 0;
    
    // /CS1 - /OE
    TRISBbits.TRISB5 = 0;
    PORTBbits.RB5 = 1;

    PMCONbits.ON = 0;
    
    //PMWR port is enabled
    PMCONbits.PTWREN = 1;
    
    //PMRD port is enabled
    PMCONbits.PTRDEN = 1;
    
    //Host Mode 2 (PMCSx, PMRD, PMWR, PMA[x:0], PMD[7:0] and PMD[8:15])
    PMMODEbits.MODE = 2;
    
    //Data Setup to Read/Write Strobe Wait States bits
    PMMODEbits.WAITB = 0;
            
    //Data Hold After Read/Write Strobe Wait States bits
    PMMODEbits.WAITM = 0;
    PMMODEbits.WAITE = 1;
    
    PMAEN = 0x3ff;
    PMCONbits.ON = 1;

    return;    
}

