diff options
author | Nicholas Corgan <nick.corgan@ettus.com> | 2014-08-15 12:57:10 -0700 |
---|---|---|
committer | Nicholas Corgan <nick.corgan@ettus.com> | 2014-08-20 09:42:26 -0700 |
commit | 2de96cd57c3f19bfa778ccad280ad19170af0967 (patch) | |
tree | 88e5235bbbc1df0dd5d6ce1883203a09f3e07ea3 /firmware/octoclock/include | |
parent | 9fb6c2919ad9e7e736c837186861b362ba80cdfa (diff) | |
download | uhd-2de96cd57c3f19bfa778ccad280ad19170af0967.tar.gz uhd-2de96cd57c3f19bfa778ccad280ad19170af0967.tar.bz2 uhd-2de96cd57c3f19bfa778ccad280ad19170af0967.zip |
OctoClock: bugfixes/improvements
* Fixed Ethernet initialization problem
* Improved external reference detection
* Added gratuitous ARP, sent upon power-up
* Tweaked host-side timing for initialization and firmware burning
* Fixed logic for dealing with firmware incompatibility
* Misc efficiency/reliability improvements to firmware's network code
Diffstat (limited to 'firmware/octoclock/include')
-rw-r--r-- | firmware/octoclock/include/debug.h | 23 | ||||
-rw-r--r-- | firmware/octoclock/include/net/eth_mac_addr.h | 2 | ||||
-rw-r--r-- | firmware/octoclock/include/network.h | 20 | ||||
-rw-r--r-- | firmware/octoclock/include/octoclock.h | 21 | ||||
-rw-r--r-- | firmware/octoclock/include/state.h | 8 |
5 files changed, 45 insertions, 29 deletions
diff --git a/firmware/octoclock/include/debug.h b/firmware/octoclock/include/debug.h index 3b89140f6..ee0618bc6 100644 --- a/firmware/octoclock/include/debug.h +++ b/firmware/octoclock/include/debug.h @@ -18,7 +18,8 @@ #ifndef _DEBUG_H_ #define _DEBUG_H_ -#if DEBUG +//Only expose these macros to the firmware, and only if specified +#if defined(DEBUG) && !defined(__BOOTLOADER__) #include <avr/pgmspace.h> #include <stdbool.h> @@ -41,17 +42,17 @@ #define DEBUG_LOG_CHAR_ARR(arr,len) DEBUG_LOG_CHAR_ARR_NNL(arr,len); \ DEBUG_LOG(" ") -#define DEBUG_LOG_MAC(mac_addr) DEBUG_LOG_HEX_NNL(mac_addr.addr[0]); \ +#define DEBUG_LOG_MAC(mac_addr) DEBUG_LOG_HEX_NNL(mac_addr[0]); \ DEBUG_LOG_NNL(":"); \ - DEBUG_LOG_HEX_NNL(mac_addr.addr[1]); \ + DEBUG_LOG_HEX_NNL(mac_addr[1]); \ DEBUG_LOG_NNL(":"); \ - DEBUG_LOG_HEX_NNL(mac_addr.addr[2]); \ + DEBUG_LOG_HEX_NNL(mac_addr[2]); \ DEBUG_LOG_NNL(":"); \ - DEBUG_LOG_HEX_NNL(mac_addr.addr[3]); \ + DEBUG_LOG_HEX_NNL(mac_addr[3]); \ DEBUG_LOG_NNL(":"); \ - DEBUG_LOG_HEX_NNL(mac_addr.addr[4]); \ + DEBUG_LOG_HEX_NNL(mac_addr[4]); \ DEBUG_LOG_NNL(":"); \ - DEBUG_LOG_HEX(mac_addr.addr[5]); + DEBUG_LOG_HEX(mac_addr[5]); #define DEBUG_LOG_IP(ip_addr) DEBUG_LOG_BYTE_NNL(ip4_addr1(&ip_addr)); \ DEBUG_LOG_NNL("."); \ @@ -62,7 +63,12 @@ DEBUG_LOG_BYTE(ip4_addr4(&ip_addr)); #define DEBUG_LOG_SHORT(num) DEBUG_LOG_HEX_NNL(((uint8_t*)&num)[1]); \ - DEBUG_LOG_HEX_NNL(((uint8_t*)&num)[0]); + DEBUG_LOG_HEX(((uint8_t*)&num)[0]); + +#define DEBUG_LOG_INT(num) DEBUG_LOG_HEX_NNL(((uint8_t*)&num)[3]); \ + DEBUG_LOG_HEX(((uint8_t*)&num)[2]); \ + DEBUG_LOG_HEX(((uint8_t*)&num)[1]); \ + DEBUG_LOG_HEX(((uint8_t*)&num)[0]); #else @@ -81,6 +87,7 @@ #define DEBUG_LOG_MAC(mac_addr) #define DEBUG_LOG_IP(ip_addr) #define DEBUG_LOG_SHORT(num) +#define DEBUG_LOG_INT(num) #endif diff --git a/firmware/octoclock/include/net/eth_mac_addr.h b/firmware/octoclock/include/net/eth_mac_addr.h index cb6fb234b..0c790aa4f 100644 --- a/firmware/octoclock/include/net/eth_mac_addr.h +++ b/firmware/octoclock/include/net/eth_mac_addr.h @@ -22,8 +22,10 @@ // Ethernet MAC address +#pragma pack(push,1) typedef struct { uint8_t addr[6]; } eth_mac_addr_t; +#pragma pack(pop) #endif /* INCLUDED_ETH_MAC_ADDR_H */ diff --git a/firmware/octoclock/include/network.h b/firmware/octoclock/include/network.h index 69c1dcf42..83e398bc5 100644 --- a/firmware/octoclock/include/network.h +++ b/firmware/octoclock/include/network.h @@ -41,6 +41,15 @@ #define ntohl(n) htonl(n) +#define _MAC_ADDR(mac_addr,a,b,c,d,e,f) mac_addr[0] = a; \ + mac_addr[1] = b; \ + mac_addr[2] = c; \ + mac_addr[3] = d; \ + mac_addr[4] = e; \ + mac_addr[5] = f; + +#define _MAC_SET_EQUAL(mac_addr1,mac_addr2) for(uint8_t i = 0; i < 6; i++) mac_addr1[i] = mac_addr2[i]; + #define _IP(a,b,c,d) (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | ((uint32_t)d << 0)) #define _IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12) #define _IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f) @@ -60,11 +69,7 @@ #define _IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (_IPH_TTL(hdr) << 8))) #define _IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) -// Global network values -eth_mac_addr_t octoclock_mac_addr; -struct ip_addr octoclock_ip_addr; -struct ip_addr octoclock_dr_addr; -struct ip_addr octoclock_netmask; +bool using_network_defaults; // Ethernet I/O buffers uint8_t buf_in[512]; @@ -76,9 +81,6 @@ static const uint32_t default_ip = _IP(192,168,10,3); static const uint32_t default_dr = _IP(192,168,10,1); static const uint32_t default_netmask = _IP(255,255,255,0); -static const uint8_t blank_eeprom_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -static const uint8_t default_mac[6] = {0x00, 0x80, 0x2F, 0x11, 0x22, 0x33}; - typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); @@ -93,6 +95,8 @@ void send_udp_pkt(int src_port, struct socket_address dst, void handle_eth_packet(size_t recv_len); +void network_check(void); + void network_init(void); #endif /* INCLUDED_NETWORK_H */ diff --git a/firmware/octoclock/include/octoclock.h b/firmware/octoclock/include/octoclock.h index 3c6254eba..849ab7f96 100644 --- a/firmware/octoclock/include/octoclock.h +++ b/firmware/octoclock/include/octoclock.h @@ -27,14 +27,25 @@ #define F_CPU 12500000UL /* - * Working with the AVR timer + * Timer 0 (8-bit) + * * Set prescaler to 8 + * * Enable overflow interrupt + * * Set timer to 0 */ -// Prescaler: 1024, Timer: 0 -#define TIMER_INIT() TCCR1B = (1 << CS12) | (1 << CS10); \ +#define TIMER0_INIT() TCCR0 = (1 << CS01); \ + TIMSK |= (1 << TOIE0); \ + TCNT0 = 0; +/* + * Timer 1 (16-bit) + * * Set prescaler to 1024 + * * Enable overflow interrupt + * * Set timer to 0 + */ +#define TIMER1_INIT() TCCR1B = (1 << CS12) | (1 << CS10); \ + TIMSK |= (1<<TOIE1); \ TCNT1 = 0; -#define TENTH_SECOND 13 -#define FIVE_SECONDS 61035 +#define TIMER1_ONE_SECOND ((uint32_t)(12207)) // Locations of OctoClock information in EEPROM #define OCTOCLOCK_EEPROM_MAC_ADDR 0 diff --git a/firmware/octoclock/include/state.h b/firmware/octoclock/include/state.h index b11cae397..9734948cf 100644 --- a/firmware/octoclock/include/state.h +++ b/firmware/octoclock/include/state.h @@ -27,8 +27,6 @@ static ref_t global_which_ref = NO_REF; static bool global_gps_present = false; static bool global_ext_ref_is_present = false; -volatile uint8_t ext_ref_buf[1024]; - void led(LEDs which, int turn_it_on); void LEDs_off(void); @@ -39,14 +37,8 @@ void prefer_internal(void); void prefer_external(void); -bool is_ext_ref_present(void); - -bool is_gps_present(void); - ref_t which_ref(void); -void check_what_is_present(void); - switch_pos_t get_switch_pos(void); #endif /* _STATE_H_ */ |