Commit 1054c5b8 authored by Martin Vítek's avatar Martin Vítek

Add tx_status_vector

parent bed94236
......@@ -48,15 +48,11 @@ bool ARP_class::search(const uint8_t (&IP)[4], uint8_t (&MAC)[6])
return false;
}
void ARP_class::assembly_request(const uint8_t (&IP)[4], ethernet_frame& frame)
void ARP_class::assembly_request(const uint8_t (&IP)[4], ethernet_payload& payload)
{
arp_packet* arp = (arp_packet*)frame.payload.data;
arp_packet* arp = (arp_packet*)payload.data;
memcpy(frame.dest_address, broadcast_mac, 6);
memcpy(frame.src_address, my_mac, 6);
frame.type_length = __htons(ARP);
frame.payload.length = sizeof(arp_packet);
payload.length = sizeof(arp_packet);
arp->hw_type = __htons(ETHERNET);
arp->protocol_type = __htons(IPV4);
......@@ -79,9 +75,14 @@ void ARP_class::assembly_request(const uint8_t (&IP)[4], ethernet_frame& frame)
memcpy(arp->IP_target, IP, 4);
}
bool ARP_class::decode(uint8_t* payload)
void ARP_class::assembly_reply(const uint8_t (&IP)[4], ethernet_payload& payload)
{
//TODO: implementation
}
bool ARP_class::decode(ethernet_payload& payload)
{
arp_packet* arp = (arp_packet*)payload;
arp_packet* arp = (arp_packet*)payload.data;
if (arp->hw_type != __htons(ETHERNET)) return false;
if (arp->protocol_type != __htons(IPV4)) return false;
......
#pragma once
#pragma pack(1)
#include <cstdint>
......@@ -10,7 +11,6 @@ struct arp_cache_item
uint8_t IP[4];
};
#pragma pack(1)
struct arp_packet
{
uint16_t hw_type;
......@@ -72,8 +72,8 @@ class ARP_class
bool get(const uint8_t (&IP)[4], uint8_t (&MAC)[6]);
bool search(const uint8_t (&IP)[4], uint8_t (&MAC)[6]);
void assembly_request(const uint8_t (&IP)[4], ethernet_frame& frame);
void assembly_reply(const uint8_t (&IP)[4], uint8_t* payload); //TODO: ARP reply
bool decode(uint8_t* payload);
void assembly_request(const uint8_t (&IP)[4], ethernet_payload& payload);
void assembly_reply(const uint8_t (&IP)[4], ethernet_payload& payload);
bool decode(ethernet_payload& payload);
};
......@@ -21,7 +21,7 @@ namespace ENC28J60_namespace
): ENC28J60_SPI(spi, cs_port, cs_bit, irq_port, irq_bit),
mac(mac)
{
test_RXEN_corruption();
//test_RXEN_corruption();
}
void ENC28J60::init()
......@@ -209,24 +209,27 @@ namespace ENC28J60_namespace
//Reset transmit logic - fix for errata, issue 12
bit_field_set_in_register(ECON1, TXRST_bm);
bit_field_clear_in_register(ECON1, TXRST_bm);
bit_field_clear_in_register(EIR, TXERIF_bm |TXIF_bm);
bit_field_clear_in_register(EIR, TXERIF_bm | TXIF_bm);
//Start transmission
bit_field_set_in_register(ECON1, TXRTS_bm);
//Wait for end of transmission
while (read_control_register(ECON1) & TXRTS_bm) ;;
//while (read_control_register(ECON1) & TXRTS_bm) ;;
//It is more reliable to check EIR.TXIF
while (read_control_register(EIR) & TXIF_bm) ;;
//Check, if it was successful
//TODO: check for abort reason
if (read_control_register(ESTAT) & TXABRT_bm) debug.error("TX was not successful");
else debug.info("TX was successful");
//Read back status vector
write_control_register(ERDPTL, (end_address+1)&0xFF);
write_control_register(ERDPTH, (end_address+1)>>8);
uint8_t buffer[7];
read_buffer_memory(buffer, 7);
/*
tx_status_vector status;
read_buffer_memory(status.vector, 7);
debug.info("Status vector: ");
......@@ -235,87 +238,87 @@ namespace ENC28J60_namespace
for (uint8_t i = 0; i < 7; i++)
{
//uart.send("0x");
uart.send_binary8(buffer[i]);
uart.send_binary8(status.vector[i]);
uart.send(' ');
}
uart.send_new_line();
uart.send("Transmit byte count: ");
uart.send_dec(__ntohs((uint16_t)buffer[0]<<8 | buffer[1]));
uart.send_dec(status.bit.tx_byte_count);
uart.send_new_line();
uart.send("Transmit collision count: ");
uart.send_dec(buffer[2]>>4);
uart.send_dec(status.bit.collision_count);
uart.send_new_line();
uart.send("Transmit CRC error: ");
uart.send(buffer[2] & (1<<3) ? "True" : "False");
uart.send(status.bit.crc_error ? "True" : "False");
uart.send_new_line();
uart.send("Transmit length check error: ");
uart.send(buffer[2] & (1<<2) ? "True" : "False");
uart.send(status.bit.lenght_check_error ? "True" : "False");
uart.send_new_line();
uart.send("Transmit length out of range: ");
uart.send(buffer[2] & (1<<1) ? "True" : "False");
uart.send(status.bit.length_out_of_range ? "True" : "False");
uart.send_new_line();
uart.send("Transmit done: ");
uart.send(buffer[2] & (1<<0) ? "True" : "False");
uart.send(status.bit.done ? "True" : "False");
uart.send_new_line();
uart.send("Packet was multicast: ");
uart.send(buffer[3] & (1<<7) ? "True" : "False");
uart.send(status.bit.multicast ? "True" : "False");
uart.send_new_line();
uart.send("Packet was broadcast: ");
uart.send(buffer[3] & (1<<6) ? "True" : "False");
uart.send(status.bit.broadcast ? "True" : "False");
uart.send_new_line();
uart.send("Packet was deferred: ");
uart.send(buffer[3] & (1<<5) ? "True" : "False");
uart.send(status.bit.packet_deferred ? "True" : "False");
uart.send_new_line();
uart.send("Packet was exessive deferred: ");
uart.send(buffer[3] & (1<<4) ? "True" : "False");
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(buffer[3] & (1<<3) ? "True" : "False");
uart.send(status.bit.aborted_max_collisions ? "True" : "False");
uart.send_new_line();
uart.send("Late collision: ");
uart.send(buffer[3] & (1<<2) ? "True" : "False");
uart.send(status.bit.late_collision ? "True" : "False");
uart.send_new_line();
uart.send("Transmit giant: ");
uart.send(buffer[3] & (1<<1) ? "True" : "False");
uart.send(status.bit.giant ? "True" : "False");
uart.send_new_line();
uart.send("Transmit underrun: ");
uart.send(buffer[3] & (1<<0) ? "True" : "False");
uart.send(status.bit.underrun ? "True" : "False");
uart.send_new_line();
uart.send("Total bytes transmitted on wire: ");
uart.send_dec((uint16_t)buffer[4]<<8 | buffer[5]);
uart.send_dec(status.bit.bytes_transmited_on_wire);
uart.send_new_line();
uart.send("Packet was control frame: ");
uart.send(buffer[6] & (1<<7) ? "True" : "False");
uart.send(status.bit.control_frame ? "True" : "False");
uart.send_new_line();
uart.send("Packet was pause control frame: ");
uart.send(buffer[6] & (1<<6) ? "True" : "False");
uart.send(status.bit.pause_control_frame ? "True" : "False");
uart.send_new_line();
uart.send("Backpressure applied: ");
uart.send(buffer[6] & (1<<5) ? "True" : "False");
uart.send(status.bit.backpressure_applied ? "True" : "False");
uart.send_new_line();
uart.send("Packet was VLAN tagged: ");
uart.send(buffer[6] & (1<<4) ? "True" : "False");
uart.send_new_line();
uart.send(status.bit.VLAN_tagged_frame ? "True" : "False");
uart.send_new_line();*/
}
bool ENC28J60::rx_frame_blocking(ethernet_frame &frame)
......
#pragma once
#pragma pack(1)
#include <cstdint>
#include <cstddef>
......@@ -12,6 +13,49 @@
namespace ENC28J60_namespace
{
/*
union tx_status_vector
{
uint8_t vector[7];
struct
{
uint16_t tx_byte_count :16;
uint8_t collision_count :4;
bool crc_error :1;
bool lenght_check_error :1;
bool length_out_of_range :1;
bool done :1;
bool multicast :1;
bool broadcast :1;
bool packet_deferred :1;
bool packet_exessive_deferred :1;
bool aborted_max_collisions :1;
bool late_collision :1;
bool giant :1;
bool underrun :1;
uint16_t bytes_transmited_on_wire :16;
bool control_frame :1;
bool pause_control_frame :1;
bool backpressure_applied :1;
bool VLAN_tagged_frame :1;
uint8_t zeros :4;
} bit;
};*/
/*
union rx_status_vector
{
uint8_t vector[4];
#pragma pack(1)
struct
{
} bit;
};
*/
class ENC28J60: public ENC28J60_SPI
{
private:
......
......@@ -26,6 +26,7 @@ enum ETHERNET_FRAME_TYPE
//TODO: others ethernet frame types
};
#pragma pack(1)
struct ethernet_payload
{
uint8_t data[1500];
......
#include "sam.h"
#include <cstdint>
#include "NixieClock.h"
#include "Time.h"
#include "USART.h"
......@@ -36,3 +38,42 @@ void SERCOM1_Handler()
{
uart.interrupt_handler();
}
void HardFault_Handler()
{
__asm volatile (
" movs r0,#4 \n"
" movs r1, lr \n"
" tst r0, r1 \n"
" beq _MSP \n"
" mrs r0, psp \n"
" b _HALT \n"
"_MSP: \n"
" mrs r0, msp \n"
"_HALT: \n"
" ldr r1,[r0,#20] \n"
" bkpt #0 \n"
);
//uint32_t scr = SCB->SCR;
//uint32_t shcsr = SCB->SHCSR;
while(true);
}
void NMI_Handler()
{
while(true);
}
void SVC_Handler()
{
while (true);
}
void PendSV_Handler()
{
while (true);
}
\ No newline at end of file
......@@ -87,10 +87,15 @@ int main(void)
ethernet_frame arp_frame;
ARP_class arp(my_mac);
arp.assembly_request({192, 168, 1, 1}, arp_frame.payload);
arp.assembly_request({192, 168, 1, 1}, arp_frame);
memcpy(arp_frame.dest_address, broadcast_mac, 6);
memcpy(arp_frame.src_address, my_mac, 6);
arp_frame.type_length = __htons(ARP);
debug.frame(arp_frame);
//debug.frame(arp_frame);
sys.delay_ms(1000);
sys.delay_ms(1000);
......@@ -161,7 +166,7 @@ int main(void)
if (eth.rx_frame_blocking(arp_frame))
{
//debug.frame(arp_frame);
arp.decode(arp_frame.payload.data);
arp.decode(arp_frame.payload);
}
......
......@@ -137,10 +137,12 @@
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.level>Optimize (-O1)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
<armgcc.compiler.warnings.ExtraWarnings>True</armgcc.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
......@@ -152,11 +154,12 @@
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.compiler.directories.IncludePaths>
<armgcccpp.compiler.optimization.level>Optimize for size (-Os)</armgcccpp.compiler.optimization.level>
<armgcccpp.compiler.optimization.level>Optimize (-O1)</armgcccpp.compiler.optimization.level>
<armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>
<armgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</armgcccpp.compiler.optimization.DebugLevel>
<armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings>
<armgcccpp.compiler.warnings.ExtraWarnings>True</armgcccpp.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.miscellaneous.OtherFlags>-std=c++14</armgcccpp.compiler.miscellaneous.OtherFlags>
<armgcccpp.linker.general.AdditionalSpecs>Use syscall stubs (--specs=nosys.specs)</armgcccpp.linker.general.AdditionalSpecs>
<armgcccpp.linker.libraries.Libraries>
......
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