1 | void EPMP_Init(void)
|
2 | {
|
3 | /* Note: When using the EPMP to access external RAM or Flash, PMA0-PMA16 will only access a range of
|
4 | 256K RAM. To increase this range enable higher Address lines.
|
5 | */
|
6 | ANSDbits.ANSD7 = 0; // PMD15
|
7 | ANSDbits.ANSD6 = 0; // PMD14
|
8 | ANSFbits.ANSF0 = 0; // PMD11
|
9 |
|
10 | ANSBbits.ANSB15 = 0; // PMA0
|
11 | ANSBbits.ANSB14 = 0; // PMA1
|
12 | ANSGbits.ANSG9 = 0; // PMA2
|
13 | ANSBbits.ANSB13 = 0; // PMA10
|
14 | ANSBbits.ANSB12 = 0; // PMA11
|
15 | ANSBbits.ANSB11 = 0; // PMA12
|
16 | ANSBbits.ANSB10 = 0; // PMA13
|
17 | ANSAbits.ANSA7 = 0; // PMA17
|
18 | ANSGbits.ANSG6 = 0; // PMA18
|
19 |
|
20 | PMCON1bits.ADRMUX = 0; // address is not multiplexed
|
21 | PMCON1bits.MODE = 3; // master mode
|
22 | PMCON1bits.CSF = 0; // PMCS1 pin used for chip select 1, PMCS2 pin used for chip select 2
|
23 | PMCON1bits.ALP = 1; // set address latch strobes to high active level (for sn74lvc16373)
|
24 | PMCON1bits.ALMODE = 1; // "smart" address strobes are not used
|
25 | PMCON1bits.BUSKEEP = 0; // bus keeper is not used
|
26 |
|
27 | #if defined (GFX_EPMP_CS1_BASE_ADDRESS)
|
28 | #ifdef USE_DOUBLE_BUFFERING
|
29 | PMCS1BS = ((DWORD)GFX_BUFFER1>>8); // CS1 start address
|
30 | PMCON3 |= 0x0003; // PMA16 - PMA17 address lines are enabled
|
31 | #else
|
32 | PMCS1BS = (GFX_EPMP_CS1_BASE_ADDRESS>>8); // CS1 start address
|
33 | PMCON3 |= 0x0001; // PMA16 address line is enabled
|
34 | #endif //USE_DOUBLE_BUFFERING
|
35 |
|
36 | PMCS1CFbits.CSDIS = 0; // enable CS
|
37 | PMCS1CFbits.CSP = EPMPCS1_CS_POLARITY; // CS1 polarity
|
38 | PMCS1CFbits.BEP = EPMPCS1_BE_POLARITY; // byte enable polarity
|
39 | PMCS1CFbits.WRSP = EPMPCS1_WR_POLARITY; // write strobe polarity
|
40 | PMCS1CFbits.RDSP = EPMPCS1_RD_POLARITY; // read strobe polarity
|
41 | PMCS1CFbits.CSPTEN = 1; // enable CS port
|
42 | PMCS1CFbits.SM = 0; // read and write strobes on separate lines
|
43 | PMCS1CFbits.PTSZ = 2; // data bus width is 16-bit
|
44 |
|
45 | PMCS1MDbits.ACKM = 0; // PMACK is not used
|
46 |
|
47 | // The device timing parameters. Set the proper timing
|
48 | // according to the device used (the timing macros are defined in the hardware profile)
|
49 | PMCS1MDbits.DWAITB = EPMPCS1_DWAITB; // access time 1 Tcy
|
50 | PMCS1MDbits.DWAITM = EPMPCS1_DWAITM;
|
51 | PMCS1MDbits.DWAITE = EPMPCS1_DWAITE;
|
52 | PMCS1MDbits.AMWAIT = EPMPCS1_AMWAIT; // Note: adjust this delay for slower devices
|
53 |
|
54 | #else
|
55 | PMCS1CFbits.CSDIS = 1; // disable CS1 functionality
|
56 | #endif //#if defined (GFX_EPMP_CS1_BASE_ADDRESS)
|
57 |
|
58 | #if defined (GFX_EPMP_CS2_BASE_ADDRESS)
|
59 |
|
60 | PMCS2BS = (GFX_EPMP_CS2_BASE_ADDRESS>>8); // CS2 start address
|
61 |
|
62 | PMCS2CFbits.CSDIS = 0; // enable CS
|
63 |
|
64 | PMCS2CFbits.CSP = EPMPCS2_CS_POLARITY; // CS2 polarity
|
65 | PMCS2CFbits.BEP = EPMPCS2_BE_POLARITY; // byte enable polarity
|
66 | PMCS2CFbits.WRSP = EPMPCS2_WR_POLARITY; // write strobe polarity
|
67 | PMCS2CFbits.RDSP = EPMPCS2_RD_POLARITY; // read strobe polarity
|
68 | PMCS2CFbits.CSPTEN = 1; // enable CS port
|
69 | PMCS2CFbits.SM = 0; // read and write strobes on separate lines
|
70 | PMCS2CFbits.PTSZ = 2; // data bus width is 16-bit
|
71 |
|
72 | PMCS2MDbits.ACKM = 0; // PMACK is not used
|
73 |
|
74 | // The device timing parameters. Set the proper timing
|
75 | // according to the device used (the timing macros are defined in the hardware profile)
|
76 | PMCS2MDbits.DWAITB = EPMPCS2_DWAITB; // access time 1 Tcy
|
77 | PMCS2MDbits.DWAITM = EPMPCS2_DWAITM;
|
78 | PMCS2MDbits.DWAITE = EPMPCS2_DWAITE;
|
79 | PMCS2MDbits.AMWAIT = EPMPCS2_AMWAIT; // Note: adjust this delay for slower devices
|
80 |
|
81 |
|
82 | #else
|
83 | PMCS2CFbits.CSDIS = 1; // disable CS2 functionality
|
84 | #endif //#if defined (GFX_EPMP_CS2_BASE_ADDRESS)
|
85 |
|
86 | PMCON2bits.RADDR = 0xFF; // set CS2 end address
|
87 | PMCON4 = 0xFFFF; // PMA0 - PMA15 address lines are enabled
|
88 |
|
89 |
|
90 | PMCON3bits.PTWREN = 1; // enable write strobe port
|
91 | PMCON3bits.PTRDEN = 1; // enable read strobe port
|
92 | PMCON3bits.PTBE0EN = 1; // enable byte enable port
|
93 | PMCON3bits.PTBE1EN = 1; // enable byte enable port
|
94 | PMCON3bits.AWAITM = 0; // set address latch pulses width to 1/2 Tcy
|
95 | PMCON3bits.AWAITE = 0; // set address hold time to 1/4 Tcy
|
96 |
|
97 | DelayMs(100);
|
98 |
|
99 | PMCON2bits.MSTSEL = 3; // select EPMP bypass mode (for Graphics operation)
|
100 | PMCON1bits.PMPEN = 1; // enable the module
|
101 |
|
102 | DelayMs(100);
|
103 |
|
104 | }
|