/******************************************************************************* * Function Name: Timer_Interrupt ******************************************************************************** * * Summary: * Handles the Interrupt Service Routine for the WDT timer. * It is called from common WDT ISR located in BLE component. * *******************************************************************************/ void Timer_Interrupt(void) { if(CySysWdtGetInterruptSource() & WDT_INTERRUPT_SOURCE) { static uint8 led = LED_OFF; /* Blink LED to indicate that device advertises */ if(CYBLE_STATE_ADVERTISING == CyBle_GetState()) { led ^= LED_OFF; Advertising_LED_Write(led); } /* Indicate that timer is raised to the main loop */ mainTimer++; /* Clears interrupt request */ CySysWdtClearInterrupt(WDT_INTERRUPT_SOURCE); } }
/***************************************************************************** * Function Name: _Watchdog_Handler() ****************************************************************************** * Summary: * Watchdog interrupt routine. * * Parameters: * None. * * Return: * None. * * Note: * *****************************************************************************/ void _Watchdog_Handler(void) { // If the Interrupt source is Counter 0 match, then process. if(CySysWdtGetInterruptSource() & CY_SYS_WDT_COUNTER0_INT) { // Clear Watchdog Interrupt from Counter 0. CySysWdtClearInterrupt(CY_SYS_WDT_COUNTER0_INT); /********************************************************************/ /********************************************************************/ // Unlock the WDT registers for modification. CySysWdtUnlock(); // Disable Counter 0 to allow modifications. CySysWdtDisable(CY_SYS_WDT_COUNTER0_MASK); // Reset Counter 0 and give ~3 LFCLK cycles to take effect. CySysWdtResetCounters(CY_SYS_WDT_COUNTER0_RESET); CyDelayUs(WATCHDOG_REG_UPDATE_WAIT_TIME); // Write the Counter 0 match value for 20 millisecond and give // ~3 LFCLK cycles to take effect. CySysWdtWriteMatch(CY_SYS_WDT_COUNTER0, WATCHDOG_COUNTER0_PERIOD); CyDelayUs(WATCHDOG_REG_UPDATE_WAIT_TIME); // Enable Watchdog Counter 0. CySysWdtEnable(CY_SYS_WDT_COUNTER0_MASK); // Lock Watchdog to prevent any further change. CySysWdtLock(); } // If the Interrupt source is Counter 1 match, then process. else if(CySysWdtGetInterruptSource() & CY_SYS_WDT_COUNTER1_INT) { // Clear Watchdog Interrupt from Counter 0. CySysWdtClearInterrupt(CY_SYS_WDT_COUNTER1_INT); /********************************************************************/ // Stores the previous state of the BLE module. static uint8 previousState = 0xFF; // If in advertising mode, flash the LED. if(CyBle_GetState() == CYBLE_STATE_ADVERTISING) { previousState = CYBLE_STATE_ADVERTISING; if(_LED_Green_On) _LED_TurnOffLED(TRUE); else _LED_TurnOnLED(TRUE); } // If state changed, turn all the LEDs off. if (CyBle_GetState() != previousState) _LED_TurnOffLED(TRUE); // If disconnected, turn all the LEDs off. else if(CyBle_GetState() == CYBLE_STATE_DISCONNECTED) { previousState = CYBLE_STATE_DISCONNECTED; _LED_TurnOffLED(TRUE); } // If connected, turn the LED on. else if(CyBle_GetState() == CYBLE_STATE_CONNECTED) { previousState = CYBLE_STATE_CONNECTED; _LED_TurnOffLED(FALSE); _LED_TurnOnLED(TRUE); } /********************************************************************/ // Unlock the WDT registers for modification. CySysWdtUnlock(); // Disable Counter 1 to allow modifications. CySysWdtDisable(CY_SYS_WDT_COUNTER1_MASK); // Reset Counter 1 and give ~3 LFCLK cycles to take effect. CySysWdtResetCounters(CY_SYS_WDT_COUNTER1_RESET); CyDelayUs(WATCHDOG_REG_UPDATE_WAIT_TIME); // Write the Counter 1 match value for 500 millisecond and give // ~3 LFCLK cycles to take effect. CySysWdtWriteMatch(CY_SYS_WDT_COUNTER1, WATCHDOG_COUNTER1_PERIOD); CyDelayUs(WATCHDOG_REG_UPDATE_WAIT_TIME); // Enable Watchdog Counter 1. CySysWdtEnable(CY_SYS_WDT_COUNTER1_MASK); // Lock Watchdog to prevent any further change. CySysWdtLock(); } }