Subversion Repositories Code-Repo

Rev

Rev 253 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 253 Rev 254
Line 195... Line 195...
195
    IEC1bits.ETHIE = 1;         // Enable ethernet interrupts
195
    IEC1bits.ETHIE = 1;         // Enable ethernet interrupts
196
 
196
 
197
    INTEnableInterrupts();
197
    INTEnableInterrupts();
198
}
198
}
199
 
199
 
-
 
200
/* Reads from the specified register on the PHY chip */
200
uint16_t ETH_PHY_Read(uint8_t address, uint8_t reg) {
201
uint16_t ETH_PHY_Read(uint8_t address, uint8_t reg) {
201
    EMAC1MADR = reg | (address << 8);
202
    EMAC1MADR = reg | (address << 8);
202
    EMAC1MCMDbits.READ = 1;
203
    EMAC1MCMDbits.READ = 1;
203
    Nop();Nop();Nop();
204
    Nop();Nop();Nop();
204
    while (EMAC1MINDbits.MIIMBUSY);
205
    while (EMAC1MINDbits.MIIMBUSY);
205
    EMAC1MCMDbits.READ = 0;
206
    EMAC1MCMDbits.READ = 0;
206
    return EMAC1MRDD;
207
    return EMAC1MRDD;
207
}
208
}
208
 
209
 
-
 
210
/* Write to the specified register on the PHY chip */
209
void ETH_PHY_Write(uint8_t address, uint8_t reg, uint16_t value) {
211
void ETH_PHY_Write(uint8_t address, uint8_t reg, uint16_t value) {
210
    EMAC1MADR = reg | (address << 8);
212
    EMAC1MADR = reg | (address << 8);
211
    EMAC1MWTD = value;
213
    EMAC1MWTD = value;
212
    Nop();Nop();Nop();
214
    Nop();Nop();Nop();
213
    while (EMAC1MINDbits.MIIMBUSY);
215
    while (EMAC1MINDbits.MIIMBUSY);
214
}
216
}
215
 
217
 
-
 
218
/* Queries the number of pending packets */
216
uint8_t ETH_Recv_Queue(void) {
219
uint8_t ETH_Recv_Queue(void) {
217
    return ETHSTATbits.BUFCNT;
220
    return ETHSTATbits.BUFCNT;
218
}
221
}
219
 
222
 
220
/* Function to read a single packet (<2014 bytes) */
223
/* Function to read a single packet (<2014 bytes) */
Line 227... Line 230...
227
    for (i = 0; i < ETH_RX_DESCRIPTOR_COUNT; i++) {
230
    for (i = 0; i < ETH_RX_DESCRIPTOR_COUNT; i++) {
228
        if ((eth_data->RX_ED_table.descriptor[descriptor_index].EOWN == 0) &&
231
        if ((eth_data->RX_ED_table.descriptor[descriptor_index].EOWN == 0) &&
229
                (eth_data->RX_ED_table.descriptor[descriptor_index].SOP == 1) &&
232
                (eth_data->RX_ED_table.descriptor[descriptor_index].SOP == 1) &&
230
                (eth_data->RX_ED_table.descriptor[descriptor_index].EOP == 1)) {
233
                (eth_data->RX_ED_table.descriptor[descriptor_index].EOP == 1)) {
231
 
234
 
-
 
235
            // Read the packet data values into the buffer
232
            size = eth_data->RX_ED_table.descriptor[descriptor_index].BYTE_COUNT - 18;
236
            size = eth_data->RX_ED_table.descriptor[descriptor_index].BYTE_COUNT - 18;
233
            *length = size;
237
            *length = size;
234
            for (j = 0; j < size - 18; j++) {
238
            for (j = 0; j < size - 18; j++) {
235
                buffer[j] = eth_data->RX_ED_buffer[descriptor_index][j+14];
239
                buffer[j] = eth_data->RX_ED_buffer[descriptor_index][j+14];
236
            }
240
            }
-
 
241
 
237
            
242
            // Reset the descriptors
238
            eth_data->RX_ED_table.descriptor[descriptor_index].SOP = 0;
243
            eth_data->RX_ED_table.descriptor[descriptor_index].SOP = 0;
239
            eth_data->RX_ED_table.descriptor[descriptor_index].EOP = 0;
244
            eth_data->RX_ED_table.descriptor[descriptor_index].EOP = 0;
240
            eth_data->RX_ED_table.descriptor[descriptor_index].EOWN = 1;
245
            eth_data->RX_ED_table.descriptor[descriptor_index].EOWN = 1;
241
 
246
 
242
            eth_data->RX_descriptor_index = (descriptor_index == ETH_RX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;
247
            eth_data->RX_descriptor_index = (descriptor_index == ETH_RX_DESCRIPTOR_COUNT - 1) ? 0 : descriptor_index + 1;