Commit 9d1d3082 authored by Martin Vítek's avatar Martin Vítek

Fixed HardFault, add TX status vector debug

parent 1054c5b8
#pragma once
#pragma pack(1)
#include <cstdint>
......@@ -11,6 +10,7 @@ struct arp_cache_item
uint8_t IP[4];
};
#pragma pack(push,1)
struct arp_packet
{
uint16_t hw_type;
......@@ -23,6 +23,7 @@ struct arp_packet
uint8_t MAC_target[6];
uint8_t IP_target[4];
};
#pragma pack(pop)
class ARP_class
{
......
......@@ -7,6 +7,7 @@
#include "ethernet_frame.h"
#include "ADC_class.h"
#include "NixieClock.h"
#include "ENC28J60.h"
USART uart(SERCOM1->USART, 500000);
......@@ -111,6 +112,113 @@ void Debug::frame(const ethernet_frame &frame)
uart.send_new_line();
}
void Debug::tx_status(const ENC28J60_namespace::tx_status_vector& status, bool simple/*= true*/)
{
debug.info("Status vector: ");
if (simple)
{
uart.send("\t\tTransmit byte count: ");
uart.send_dec(status.bit.tx_byte_count);
uart.send_new_line();
uart.send("\t\tTransmit done: ");
uart.send(status.bit.done ? "True" : "False");
uart.send_new_line();
return;
}
uart.send("\t\t");
for (uint8_t i = 0; i < 7; i++)
{
//uart.send("0x");
uart.send_binary8(status.vector[i]);
uart.send(' ');
}
uart.send_new_line();
uart.send("\t\tTransmit byte count: ");
uart.send_dec(status.bit.tx_byte_count);
uart.send_new_line();
uart.send("\t\tTransmit collision count: ");
uart.send_dec(status.bit.collision_count);
uart.send_new_line();
uart.send("\t\tTransmit CRC error: ");
uart.send(status.bit.crc_error ? "True" : "False");
uart.send_new_line();
uart.send("\t\tTransmit length check error: ");
uart.send(status.bit.lenght_check_error ? "True" : "False");
uart.send_new_line();
uart.send("\t\tFrame length/type: ");
uart.send(status.bit.length_out_of_range ? "Type" : "Length");
uart.send_new_line();
uart.send("\t\tTransmit done: ");
uart.send(status.bit.done ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was multicast: ");
uart.send(status.bit.multicast ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was broadcast: ");
uart.send(status.bit.broadcast ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was deferred: ");
uart.send(status.bit.packet_deferred ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was excessive deferred: ");
uart.send(status.bit.packet_exessive_deferred ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was aborted (collisions): ");
uart.send(status.bit.aborted_max_collisions ? "True" : "False");
uart.send_new_line();
uart.send("\t\tLate collision: ");
uart.send(status.bit.late_collision ? "True" : "False");
uart.send_new_line();
uart.send("\t\tTransmit giant: ");
uart.send(status.bit.giant ? "True" : "False");
uart.send_new_line();
uart.send("\t\tTransmit underrun: ");
uart.send(status.bit.underrun ? "True" : "False");
uart.send_new_line();
uart.send("\t\tTotal bytes transmitted on wire: ");
uart.send_dec(status.bit.bytes_transmited_on_wire);
uart.send_new_line();
uart.send("\t\tPacket was control frame: ");
uart.send(status.bit.control_frame ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was pause control frame: ");
uart.send(status.bit.pause_control_frame ? "True" : "False");
uart.send_new_line();
uart.send("\t\tBackpressure applied: ");
uart.send(status.bit.backpressure_applied ? "True" : "False");
uart.send_new_line();
uart.send("\t\tPacket was VLAN tagged: ");
uart.send(status.bit.VLAN_tagged_frame ? "True" : "False");
uart.send_new_line();
}
void Debug::adc()
{
/*
......
......@@ -2,6 +2,7 @@
#include "USART.h"
#include "ethernet_frame.h"
#include "ENC28J60.h"
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
......@@ -43,6 +44,7 @@ class Debug
void reg(const char* name, const uint8_t value);
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 adc();
};
......
......@@ -227,98 +227,11 @@ namespace ENC28J60_namespace
//Read back status vector
write_control_register(ERDPTL, (end_address+1)&0xFF);
write_control_register(ERDPTH, (end_address+1)>>8);
/*
tx_status_vector status;
read_buffer_memory(status.vector, 7);
debug.info("Status vector: ");
uart.send('\t');
for (uint8_t i = 0; i < 7; i++)
{
//uart.send("0x");
uart.send_binary8(status.vector[i]);
uart.send(' ');
}
uart.send_new_line();
uart.send("Transmit byte count: ");
uart.send_dec(status.bit.tx_byte_count);
uart.send_new_line();
uart.send("Transmit collision count: ");
uart.send_dec(status.bit.collision_count);
uart.send_new_line();
uart.send("Transmit CRC error: ");
uart.send(status.bit.crc_error ? "True" : "False");
uart.send_new_line();
uart.send("Transmit length check error: ");
uart.send(status.bit.lenght_check_error ? "True" : "False");
uart.send_new_line();
uart.send("Transmit length out of range: ");
uart.send(status.bit.length_out_of_range ? "True" : "False");
uart.send_new_line();
uart.send("Transmit done: ");
uart.send(status.bit.done ? "True" : "False");
uart.send_new_line();
uart.send("Packet was multicast: ");
uart.send(status.bit.multicast ? "True" : "False");
uart.send_new_line();
uart.send("Packet was broadcast: ");
uart.send(status.bit.broadcast ? "True" : "False");
uart.send_new_line();
uart.send("Packet was deferred: ");
uart.send(status.bit.packet_deferred ? "True" : "False");
uart.send_new_line();
uart.send("Packet was excessive deferred: ");
uart.send(status.bit.packet_exessive_deferred ? "True" : "False");
uart.send_new_line();
uart.send("Packet was aborted (collisions): ");
uart.send(status.bit.aborted_max_collisions ? "True" : "False");
uart.send_new_line();
uart.send("Late collision: ");
uart.send(status.bit.late_collision ? "True" : "False");
uart.send_new_line();
uart.send("Transmit giant: ");
uart.send(status.bit.giant ? "True" : "False");
uart.send_new_line();
uart.send("Transmit underrun: ");
uart.send(status.bit.underrun ? "True" : "False");
uart.send_new_line();
uart.send("Total bytes transmitted on wire: ");
uart.send_dec(status.bit.bytes_transmited_on_wire);
uart.send_new_line();
uart.send("Packet was control frame: ");
uart.send(status.bit.control_frame ? "True" : "False");
uart.send_new_line();
uart.send("Packet was pause control frame: ");
uart.send(status.bit.pause_control_frame ? "True" : "False");
uart.send_new_line();
uart.send("Backpressure applied: ");
uart.send(status.bit.backpressure_applied ? "True" : "False");
uart.send_new_line();
uart.send("Packet was VLAN tagged: ");
uart.send(status.bit.VLAN_tagged_frame ? "True" : "False");
uart.send_new_line();*/
debug.tx_status(status);
}
bool ENC28J60::rx_frame_blocking(ethernet_frame &frame)
......
#pragma once
#pragma pack(1)
#include <cstdint>
#include <cstddef>
......@@ -13,7 +12,7 @@
namespace ENC28J60_namespace
{
/*
#pragma pack(push,1)
union tx_status_vector
{
uint8_t vector[7];
......@@ -41,9 +40,8 @@ namespace ENC28J60_namespace
bool VLAN_tagged_frame :1;
uint8_t zeros :4;
} bit;
};*/
/*
};
union rx_status_vector
{
uint8_t vector[4];
......@@ -54,7 +52,7 @@ namespace ENC28J60_namespace
} bit;
};
*/
#pragma pack(pop)
class ENC28J60: public ENC28J60_SPI
{
......
#pragma once
//#pragma pack(1) - this causes HardFault
#include <stdint.h>
......@@ -26,7 +27,6 @@ enum ETHERNET_FRAME_TYPE
//TODO: others ethernet frame types
};
#pragma pack(1)
struct ethernet_payload
{
uint8_t data[1500];
......
......@@ -75,7 +75,7 @@ int main(void)
eth.print_device_info();
nixie.print_eeprom();
//nixie.print_eeprom();
nixie.get_mac();
uint8_t i = 0;
......@@ -101,6 +101,8 @@ int main(void)
sys.delay_ms(1000);
sys.delay_ms(1000);
sys.delay_ms(1000);
sys.delay_ms(1000);
sys.delay_ms(1000);
eth.tx_frame_blocking(arp_frame);
//eth.tx_frame_blocking(packet);
......
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