Commit 893f965a authored by Martin Vítek's avatar Martin Vítek

Add inteligent and better working handling of RX status

parent 9d1d3082
......@@ -114,15 +114,15 @@ void Debug::frame(const ethernet_frame &frame)
void Debug::tx_status(const ENC28J60_namespace::tx_status_vector& status, bool simple/*= true*/)
{
debug.info("Status vector: ");
debug.info("TX status vector: ");
if (simple)
{
uart.send("\t\tTransmit byte count: ");
uart.send("\t\tTransmit bytes count: ");
uart.send_dec(status.bit.tx_byte_count);
uart.send_new_line();
uart.send("\t\tTransmit done: ");
uart.send("\t\tTransmit done: ");
uart.send(status.bit.done ? "True" : "False");
uart.send_new_line();
......@@ -219,6 +219,26 @@ void Debug::tx_status(const ENC28J60_namespace::tx_status_vector& status, bool s
uart.send_new_line();
}
void Debug::rx_status(const ENC28J60_namespace::rx_status_vector& status, bool simple/*= true*/)
{
debug.info("RX status vector: ");
if (simple)
{
uart.send("\t\tReceived bytes count: ");
uart.send_dec(status.bit.rx_byte_count);
uart.send_new_line();
uart.send("\t\tTransmit done: ");
uart.send(status.bit.received_ok ? "True" : "False");
uart.send_new_line();
return;
}
//TODO: implement debug of all fields
}
void Debug::adc()
{
/*
......
......@@ -45,6 +45,7 @@ class Debug
void reg(const char* name, const uint16_t value);
void frame(const ethernet_frame &frame);
void tx_status(const ENC28J60_namespace::tx_status_vector& status, bool simple= true);
void rx_status(const ENC28J60_namespace::rx_status_vector& status, bool simple= true);
void adc();
};
......
......@@ -241,22 +241,16 @@ namespace ENC28J60_namespace
//There is new packet in RX buffer
if (read_control_register(EPKTCNT))
{
/*
uart.transmit_string("Packet count: ");
uart.transmit_dec32(read_control_register(EPKTCNT));
uart.transmit_new_line();
*/
//TODO: next_packet_pointer is not necessary
uint16_t next_packet_pointer;
uint32_t status_vector;
rx_status_vector status;
//Go to start of packet
write_control_register(ERDPTL, eth_rx_packet_start&0xFF);
write_control_register(ERDPTH, eth_rx_packet_start>>8);
read_buffer_memory(next_packet_pointer);
read_buffer_memory(status_vector);
read_buffer_memory(status.vector, 4);
//Save address of next packet
eth_rx_packet_start = next_packet_pointer;
......@@ -264,36 +258,45 @@ namespace ENC28J60_namespace
/*
uart.transmit_string("Next packet pointer: ");
uart.transmit_hex16(next_packet_pointer);
uart.transmit_new_line();
uart.transmit_string("Status vector: ");
uart.transmit_dec32(status_vector&0xFFFF);
uart.transmit_new_line();
*/
//If there was CRC or length or out of range error
if (status_vector & ((1<<20) | (1<<21) | (1<<22)))
debug.rx_status(status);
//CRC error
if (status.bit.crc_error)
{
//Decrement packet count
//bit_field_set_in_register(ECON2, PKTDEC_bm);
bit_field_set_in_register(ECON2, PKTDEC_bm);
debug.error("CRC or length or large packet error");
debug.error("Mishmash CRC (packet was dropped)");
//return false;
return false;
}
//Packet was not received OK (CRC or symbol error)
/*if (!(status_vector & (1<<23)))
//Length check error
if (status.bit.length_check_error)
{
//Decrement packet count
bit_field_set_in_register(ECON2, PKTDEC_bm);
debug.error("Packet was not received OK");
debug.error("Length field doesn't correspond with rx bytes");
return false;
}*/
}
//Packet wasn't received ok
if (!status.bit.received_ok)
{
//Decrement packet count
bit_field_set_in_register(ECON2, PKTDEC_bm);
debug.error("Packet isn't OK");
return false;
}
frame.payload.length = (status_vector&0xFFFF) - 18; //Payload length including padding
frame.payload.length = (status.bit.rx_byte_count) - 18; //Payload length including padding
//Destination address
read_buffer_memory(frame.dest_address, 6);
......@@ -308,7 +311,8 @@ namespace ENC28J60_namespace
read_buffer_memory(frame.payload.data, frame.payload.length);
//CRC
read_buffer_memory(frame.crc);
//TODO: Who needs CRC?
//read_buffer_memory(frame.crc);
//Free space in buffer - set read pointer to next packet pointer
//Fix from errata, issue 14 - ERXRDPT must be only odd value (and packets starts at even address)
......
......@@ -46,10 +46,25 @@ namespace ENC28J60_namespace
{
uint8_t vector[4];
#pragma pack(1)
struct
{
uint16_t rx_byte_count;
bool long_drop_event :1;
bool reserved0 :1;
bool carrier_event_previosly_seen :1;
bool reserved1 :1;
bool crc_error :1;
bool length_check_error :1;
bool length_out_of_range :1;
bool received_ok :1;
bool multicast :1;
bool broadcast :1;
bool dribble_nibble :1;
bool control_frame :1;
bool pause_control_frame :1;
bool unknown_optcode :1;
bool VLAN_tagged_frame :1;
bool zero :1;
} bit;
};
#pragma pack(pop)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment