__interrupt void RTC_A_ISR(void) #endif { sTime.second++; if (sTime.second == 60) sTime.second = 0; static u8 button_lock_counter = 0; //gibbons TODO: need to put these just in the 1-sec interrupt section? static u8 button_beep_counter = 0; #ifdef CONFIG_CW u8 CW_Message[] = "NOON\0"; #endif switch (RTCIV) { case RTC_RT0PSIFG: // Interval timer (16384Hz - 128Hz interrupts (binary powers) ) // gibbons TODO: put stopwatch 1/100 sec interrupt here? break; case RTC_RT1PSIFG: // Interval timer (64Hz - 0.5Hz interrupts (binary powers) ) break; case RTC_RTCRDYIFG: // RTC registers ready and safe to read (Use this for 1-sec update) // Add 1 second to stored (global) time, update sTime.drawFlag appropriately clock_tick(); // Set clock update flag display.flag.update_time = 1; // While SimpliciTI stack operates or BlueRobin searches, freeze system state //pfs #ifdef ELIMINATE_BLUEROBIN if (is_rf()) #else if (is_rf() || is_bluerobin_searching()) #endif { // SimpliciTI automatic timeout if (sRFsmpl.timeout == 0) { simpliciti_flag |= SIMPLICITI_TRIGGER_STOP; } else { sRFsmpl.timeout--; } // Exit from LPM3 on RETI _BIC_SR_IRQ(LPM3_bits); return; } // ------------------------------------------------------------------- // Service modules that require 1/min processing if (sTime.drawFlag >= 2) { // Measure battery voltage to keep track of remaining battery life request.flag.voltage_measurement = 1; // Check if alarm needs to be turned on //check_alarm(); //gibbons TODO: remove } // ------------------------------------------------------------------- // Service active modules that require 1/s processing #ifdef CONFIG_EGGTIMER if (sEggtimer.state == EGGTIMER_RUN) { eggtimer_tick(); // Subtract 1 second from eggtimer's count } if (sEggtimer.state == EGGTIMER_ALARM) { // no "else if" intentional // Decrement alarm duration counter if (sEggtimer.duration-- > 0) { request.flag.eggtimer_buzzer = 1; } else { stop_eggtimer_alarm(); // Set state to Stop and reset duration } } #endif // Generate alarm signal if (sAlarm.state == ALARM_ON) { // Decrement alarm duration counter if (sAlarm.duration-- > 0) { request.flag.alarm_buzzer = 1; } else { stop_alarm(); } } #ifdef CONFIG_PROUT if (is_prout()) prout_tick(); #endif #ifdef CONFIG_VARIO if(is_vario()) vario_tick(); #endif #ifdef CONFIG_STRENGTH // One more second gone by. if(is_strength()) { strength_tick(); } #endif // Do a temperature measurement each second while menu item is active if (is_temp_measurement()) request.flag.temperature_measurement = 1; // Do a pressure measurement each second while menu item is active #ifdef CONFIG_ALTITUDE if (is_altitude_measurement()) { // Countdown altitude measurement timeout while menu item is active sAlt.timeout--; // Stop measurement when timeout has elapsed if (sAlt.timeout == 0) { stop_altitude_measurement(); // Show ---- m/ft display_chars(LCD_SEG_L1_3_0, (u8*)"----", SEG_ON); // Clear up/down arrow display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF); display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF); } // In case we missed the IRQ due to debouncing, get data now if ((PS_INT_IN & PS_INT_PIN) == PS_INT_PIN) request.flag.altitude_measurement = 1; } #endif #ifdef FEATURE_PROVIDE_ACCEL // Count down timeout if (is_acceleration_measurement()) { // Countdown acceleration measurement timeout sAccel.timeout--; // Stop measurement when timeout has elapsed if (sAccel.timeout == 0) as_stop(); // If DRDY is (still) high, request data again if ((AS_INT_IN & AS_INT_PIN) == AS_INT_PIN) request.flag.acceleration_measurement = 1; } #endif //pfs #ifndef ELIMINATE_BLUEROBIN // If BlueRobin transmitter is connected, get data from API if (is_bluerobin()) get_bluerobin_data(); #endif // If battery is low, decrement display counter if (sys.flag.low_battery) { if (sBatt.lobatt_display-- == 0) { message.flag.prepare = 1; message.flag.type_lobatt = 1; sBatt.lobatt_display = BATTERY_LOW_MESSAGE_CYCLE; } } // If a message has to be displayed, set display flag if (message.all_flags) { if (message.flag.prepare) { message.flag.prepare = 0; message.flag.show = 1; } else if (message.flag.erase) // message cycle is over, so erase it { message.flag.erase = 0; message.flag.block_line1 = 0; message.flag.block_line2 = 0; display.flag.full_update = 1; } } // ------------------------------------------------------------------- // Check idle timeout, set timeout flag if (sys.flag.idle_timeout_enabled) { if (sTime.last_activity > 0) { if (--sTime.last_activity == 0) sys.flag.idle_timeout = 1; //setFlag(sysFlag_g, SYS_TIMEOUT_IDLE); } } // ------------------------------------------------------------------- // Detect continuous button high states if (BUTTON_STAR_IS_PRESSED && BUTTON_UP_IS_PRESSED) { if (button_beep_counter++ > LEFT_BUTTON_LONG_TIME) { // Toggle no_beep buttons flag sys.flag.no_beep = ~sys.flag.no_beep; // Show "beep / nobeep" message synchronously with next second tick message.flag.prepare = 1; if (sys.flag.no_beep) message.flag.type_no_beep_on = 1; else message.flag.type_no_beep_off = 1; // Reset button beep counter button_beep_counter = 0; } } else if (BUTTON_NUM_IS_PRESSED && BUTTON_DOWN_IS_PRESSED) // Trying to lock/unlock buttons? { if (button_lock_counter++ > LEFT_BUTTON_LONG_TIME) { // Toggle lock / unlock buttons flag sys.flag.lock_buttons = ~sys.flag.lock_buttons; // Show "buttons are locked/unlocked" message synchronously with next second tick message.flag.prepare = 1; if (sys.flag.lock_buttons) message.flag.type_locked = 1; else message.flag.type_unlocked = 1; // Reset button lock counter button_lock_counter = 0; } } else // Trying to create a long button press? { // Reset button lock counter button_lock_counter = 0; if (BUTTON_STAR_IS_PRESSED) { sButton.star_timeout++; // Check if button was held low for some seconds if (sButton.star_timeout > LEFT_BUTTON_LONG_TIME) { button.flag.star_long = 1; sButton.star_timeout = 0; } } else { sButton.star_timeout = 0; } if (BUTTON_NUM_IS_PRESSED) { sButton.num_timeout++; // Check if button was held low for some seconds if (sButton.num_timeout > LEFT_BUTTON_LONG_TIME) { button.flag.num_long = 1; sButton.num_timeout = 0; } } else { sButton.num_timeout = 0; } } // Exit from LPM3 on RETI _BIC_SR_IRQ(LPM3_bits); //gibbons TODO: move this to other interrupts from the RTC? break; case RTC_RTCTEVIFG: // Interval alarm event (min or hour changed, or rollover to midnight or noon) (choose one) // Minute, hour, noon, or midnight rollover beep (same beep as button press, at least for now) #ifdef CONFIG_TIMECHIME #ifdef CONFIG_CW CW_Send_String(CW_Message); #else start_buzzer(1, CONV_MS_TO_TICKS(20), CONV_MS_TO_TICKS(150)); #endif if (RTC_Toggle_12Hr) RTCCTL01 ^= 0x0100; // Toggle Time EVent between noon and midnight #endif break; case RTC_RTCAIFG: // User-configurable alarm event // Indicate that alarm is on sAlarm.state = ALARM_ON; break; } //gibbons: TODO: Remove this old code? (Associated with Timer0_A0 1-sec ISR) // Disable IE //TA0CCTL0 &= ~CCIE; // Reset IRQ flag //TA0CCTL0 &= ~CCIFG; // Add 1 sec to TACCR0 register (IRQ will be asserted at 0x7FFF and 0xFFFF = 1 sec intervals) //TA0CCR0 += 32768; //gibbons TODO: Should this perhaps be (32768 - 1) ? // Enable IE //TA0CCTL0 |= CCIE; }
__interrupt void TIMER0_A0_ISR(void) #endif { static u8 button_lock_counter = 0; static u8 button_beep_counter = 0; // Disable IE TA0CCTL0 &= ~CCIE; // Reset IRQ flag TA0CCTL0 &= ~CCIFG; // Add 1 sec to TACCR0 register (IRQ will be asserted at 0x7FFF and 0xFFFF = 1 sec intervals) TA0CCR0 += 32768; // Enable IE TA0CCTL0 |= CCIE; // Add 1 second to global time clock_tick(); // Set clock update flag display.flag.update_time = 1; // While SimpliciTI stack operates or BlueRobin searches, freeze system state //pfs #ifdef ELIMINATE_BLUEROBIN if (is_rf()) #else if (is_rf() || is_bluerobin_searching()) #endif { // SimpliciTI automatic timeout if (sRFsmpl.timeout == 0) { simpliciti_flag |= SIMPLICITI_TRIGGER_STOP; } else { sRFsmpl.timeout--; } // Exit from LPM3 on RETI _BIC_SR_IRQ(LPM3_bits); return; } // ------------------------------------------------------------------- // Service modules that require 1/min processing if (sTime.drawFlag >= 2) { // Measure battery voltage to keep track of remaining battery life request.flag.voltage_measurement = 1; // Check if alarm needs to be turned on check_alarm(); } // ------------------------------------------------------------------- // Service active modules that require 1/s processing // Generate alarm signal if (sAlarm.state == ALARM_ON) { // Decrement alarm duration counter if (sAlarm.duration-- > 0) { request.flag.buzzer = 1; } else { sAlarm.duration = ALARM_ON_DURATION; stop_alarm(); } } #ifdef CONFIG_PROUT if (is_prout()) prout_tick(); #endif #ifdef CONFIG_CONTROL if (is_control()) control_tick(); #endif #ifdef CONFIG_VARIO if(is_vario()) vario_tick(); #endif #ifdef CONFIG_STRENGTH // One more second gone by. if(is_strength()) { strength_tick(); } #endif // Do a temperature measurement each second while menu item is active if (is_temp_measurement()) request.flag.temperature_measurement = 1; // Do a pressure measurement each second while menu item is active #ifdef CONFIG_ALTITUDE if (is_altitude_measurement()) { // Countdown altitude measurement timeout while menu item is active sAlt.timeout--; // Stop measurement when timeout has elapsed if (sAlt.timeout == 0) { stop_altitude_measurement(); // Show ---- m/ft display_chars(LCD_SEG_L1_3_0, (u8*)"----", SEG_ON); // Clear up/down arrow display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF); display_symbol(LCD_SYMB_ARROW_DOWN, SEG_OFF); } // In case we missed the IRQ due to debouncing, get data now if ((PS_INT_IN & PS_INT_PIN) == PS_INT_PIN) request.flag.altitude_measurement = 1; } #endif #ifdef FEATURE_PROVIDE_ACCEL // Count down timeout if (is_acceleration_measurement()) { // Countdown acceleration measurement timeout sAccel.timeout--; // Stop measurement when timeout has elapsed if (sAccel.timeout == 0) as_stop(); // If DRDY is (still) high, request data again if ((AS_INT_IN & AS_INT_PIN) == AS_INT_PIN) request.flag.acceleration_measurement = 1; } #endif //pfs #ifndef ELIMINATE_BLUEROBIN // If BlueRobin transmitter is connected, get data from API if (is_bluerobin()) get_bluerobin_data(); #endif // If battery is low, decrement display counter if (sys.flag.low_battery) { if (sBatt.lobatt_display-- == 0) { message.flag.prepare = 1; message.flag.type_lobatt = 1; sBatt.lobatt_display = BATTERY_LOW_MESSAGE_CYCLE; } } // If a message has to be displayed, set display flag if (message.all_flags) { if (message.flag.prepare) { message.flag.prepare = 0; message.flag.show = 1; } else if (message.flag.erase) // message cycle is over, so erase it { message.flag.erase = 0; message.flag.block_line1 = 0; message.flag.block_line2 = 0; display.flag.full_update = 1; } } // ------------------------------------------------------------------- // Check idle timeout, set timeout flag if (sys.flag.idle_timeout_enabled) { if (sTime.system_time - sTime.last_activity > INACTIVITY_TIME) sys.flag.idle_timeout = 1; //setFlag(sysFlag_g, SYS_TIMEOUT_IDLE); } // ------------------------------------------------------------------- // Detect continuous button high states if (BUTTON_STAR_IS_PRESSED && BUTTON_UP_IS_PRESSED) { if (button_beep_counter++ > LEFT_BUTTON_LONG_TIME) { // Toggle no_beep buttons flag sys.flag.no_beep = ~sys.flag.no_beep; // Show "beep / nobeep" message synchronously with next second tick message.flag.prepare = 1; if (sys.flag.no_beep) message.flag.type_no_beep_on = 1; else message.flag.type_no_beep_off = 1; // Reset button beep counter button_beep_counter = 0; } } else if (BUTTON_NUM_IS_PRESSED && BUTTON_DOWN_IS_PRESSED) // Trying to lock/unlock buttons? { if (button_lock_counter++ > LEFT_BUTTON_LONG_TIME) { // Toggle lock / unlock buttons flag sys.flag.lock_buttons = ~sys.flag.lock_buttons; // Show "buttons are locked/unlocked" message synchronously with next second tick message.flag.prepare = 1; if (sys.flag.lock_buttons) message.flag.type_locked = 1; else message.flag.type_unlocked = 1; // Reset button lock counter button_lock_counter = 0; } } else // Trying to create a long button press? { // Reset button lock counter button_lock_counter = 0; if (BUTTON_STAR_IS_PRESSED) { sButton.star_timeout++; // Check if button was held low for some seconds if (sButton.star_timeout > LEFT_BUTTON_LONG_TIME) { button.flag.star_long = 1; sButton.star_timeout = 0; } } else { sButton.star_timeout = 0; } if (BUTTON_NUM_IS_PRESSED) { sButton.num_timeout++; // Check if button was held low for some seconds if (sButton.num_timeout > LEFT_BUTTON_LONG_TIME) { button.flag.num_long = 1; sButton.num_timeout = 0; } } else { sButton.num_timeout = 0; } } // Exit from LPM3 on RETI _BIC_SR_IRQ(LPM3_bits); }