| 253 |
Kevin |
1 |
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
|
|
|
2 |
/* ------------------------------------------------------------ */
|
|
|
3 |
/* PIC32 Configuration Settings */
|
|
|
4 |
/* ------------------------------------------------------------ */
|
|
|
5 |
/* Oscillator Settings */
|
|
|
6 |
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits
|
|
|
7 |
#pragma config POSCMOD = EC // Primary Oscillator Configuration
|
|
|
8 |
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
|
|
|
9 |
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
|
|
|
10 |
#pragma config FPLLODIV = DIV_1 // PLL Output Divider
|
|
|
11 |
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (timers/UART/SPI/I2C)
|
|
|
12 |
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable
|
|
|
13 |
/* Clock Control Settings */
|
|
|
14 |
#pragma config IESO = OFF // Internal/External Clock Switch Over
|
|
|
15 |
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection
|
|
|
16 |
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin
|
|
|
17 |
/* USB Settings */
|
|
|
18 |
#pragma config UPLLEN = ON // USB PLL Enable
|
|
|
19 |
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider
|
|
|
20 |
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection
|
|
|
21 |
#pragma config FUSBIDIO = OFF // USB USID Selection
|
|
|
22 |
/* Other Peripheral Device Settings */
|
|
|
23 |
#pragma config FWDTEN = OFF // Watchdog Timer Enable
|
|
|
24 |
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1048.576s)
|
|
|
25 |
#pragma config FSRSSEL = PRIORITY_7 // SRS Interrupt Priority
|
|
|
26 |
#pragma config FCANIO = OFF // CAN I/O Pin Select (default/alternate)
|
|
|
27 |
#pragma config FETHIO = ON // Ethernet I/O Pin Select (default/alternate)
|
|
|
28 |
#pragma config FMIIEN = OFF // Ethernet MII/RMII select (OFF=RMII)
|
|
|
29 |
/* Code Protection Settings */
|
|
|
30 |
#pragma config CP = OFF // Code Protect
|
|
|
31 |
#pragma config BWP = OFF // Boot Flash Write Protect
|
|
|
32 |
#pragma config PWP = OFF // Program Flash Write Protect
|
|
|
33 |
/* Debug Settings */
|
|
|
34 |
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (on-board debugger)
|
|
|
35 |
/* ------------------------------------------------------------ */
|
|
|
36 |
// </editor-fold>
|
|
|
37 |
|
|
|
38 |
#include "defines.h"
|
|
|
39 |
#include "ETHERNET.h"
|
|
|
40 |
|
|
|
41 |
void Delay_MS(uint32_t delay_ms) {
|
|
|
42 |
// Delays the CPU for the given amount of time.
|
|
|
43 |
// Note: Watch out for integer overflow! (max delay_ms = 107374) ??
|
|
|
44 |
uint32_t delay = delay_ms * MS_TO_CT_TICKS;
|
|
|
45 |
uint32_t startTime = ReadCoreTimer();
|
|
|
46 |
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
void Delay_US(uint32_t delay_us) {
|
|
|
50 |
// Delays the CPU for the given amount of time.
|
|
|
51 |
// Note: Watch out for integer overflow!
|
|
|
52 |
uint32_t delay = delay_us * US_TO_CT_TICKS;
|
|
|
53 |
uint32_t startTime = ReadCoreTimer();
|
|
|
54 |
while ((uint32_t)(ReadCoreTimer() - startTime) < delay) {};
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
int main(void) {
|
|
|
58 |
/* -------------------- BEGIN INITIALIZATION --------------------- */
|
|
|
59 |
|
|
|
60 |
// Configure the target for maximum performance at 80 MHz.
|
|
|
61 |
// Note: This overrides the peripheral clock to 80Mhz regardless of config
|
|
|
62 |
SYSTEMConfigPerformance(CPU_CLOCK_HZ);
|
|
|
63 |
|
|
|
64 |
// Configure the interrupts for multiple vectors
|
|
|
65 |
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
|
|
|
66 |
|
|
|
67 |
// Set all analog I/O pins to digital
|
|
|
68 |
AD1PCFGSET = 0xFFFF;
|
|
|
69 |
|
|
|
70 |
// Enable the watchdog timer with windowed mode disabled
|
|
|
71 |
// WDT prescaler set to 1048576 (1048.576s) (see config bits)
|
|
|
72 |
// WDTCON = 0x00008000;
|
|
|
73 |
|
|
|
74 |
LED1_TRIS = 0;
|
|
|
75 |
LED2_TRIS = 0;
|
|
|
76 |
LED3_TRIS = 0;
|
|
|
77 |
LED4_TRIS = 0;
|
|
|
78 |
LED1_LAT = 0;
|
|
|
79 |
LED2_LAT = 0;
|
|
|
80 |
LED3_LAT = 0;
|
|
|
81 |
LED4_LAT = 0;
|
|
|
82 |
|
|
|
83 |
ETH_DATA eth_data;
|
|
|
84 |
|
|
|
85 |
ETH_Init(ð_data, NULL, NULL);
|
|
|
86 |
|
|
|
87 |
uint8_t buffer[3000] = {0};
|
|
|
88 |
buffer[0] = 0xAA;
|
|
|
89 |
buffer[2017] = 0xBB;
|
|
|
90 |
buffer[2018] = 0xCC;
|
|
|
91 |
buffer[2999] = 0xDD;
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
ETH_MAC_ADDRESS dest = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
|
|
95 |
ETH_MAC_ADDRESS src = {0x00, 0x18, 0x3E, 0x00, 0xD7, 0xEB};
|
|
|
96 |
|
|
|
97 |
// ETH_Write_Packet(dest, src, 2018, buffer);
|
|
|
98 |
|
|
|
99 |
ETH_Write_Packet(dest, src, 2018, buffer);
|
|
|
100 |
ETH_Write_Packet(dest, src, 2018, buffer);
|
|
|
101 |
ETH_Write_Packet(dest, src, 2018, buffer);
|
|
|
102 |
ETH_Write_Packet(dest, src, 2018, buffer);
|
|
|
103 |
|
|
|
104 |
while (1) {
|
|
|
105 |
uint8_t queue = ETH_Recv_Queue();
|
|
|
106 |
if (queue != 0) {
|
|
|
107 |
LED1_LAT = 1;
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
}
|
|
|
112 |
|