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/lib/state.c | |
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/lib/state.c')
-rw-r--r-- | firmware/octoclock/lib/state.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/firmware/octoclock/lib/state.c b/firmware/octoclock/lib/state.c index 2adab6fc4..0dbcc6ece 100644 --- a/firmware/octoclock/lib/state.c +++ b/firmware/octoclock/lib/state.c @@ -83,20 +83,27 @@ void prefer_external(void){ LEDs_Off(); } -bool is_ext_ref_present(void){ - volatile uint8_t prev = (PINE & (1<<DDE7)); - volatile uint8_t now; +static uint8_t prev_PE7 = 0; +static uint32_t timer0_num_overflows = 0; - for(uint16_t i = 1; i < 512; i++){ - now = (PINE & (1<<DDE7)); - if(prev != now) return true; +ISR(TIMER0_OVF_vect){ + global_gps_present = (PIND & (1<<DDD4)); + + // Every ~1/10 second + if(!(timer0_num_overflows % 610)){ + prev_PE7 = (PINE & (1<<DDE7)); + + if(get_switch_pos() == UP) prefer_internal(); + else prefer_external(); + + global_ext_ref_is_present = false; } - return false; -} + if(!global_ext_ref_is_present){ + global_ext_ref_is_present = (prev_PE7 != (PINE & (1<<DDE7))); + } -bool is_gps_present(void){ - return (PIND & (1<<DDD4)); + timer0_num_overflows++; } ref_t which_ref(void){ @@ -108,11 +115,6 @@ ref_t which_ref(void){ return global_which_ref; } -void check_what_is_present(void){ - global_ext_ref_is_present = is_ext_ref_present(); - global_gps_present = is_gps_present(); -} - switch_pos_t get_switch_pos(void){ uint8_t portC = PINC; |