void LLWU_Init(void){ printf("[LLWU_Init] LLWU initialize routine \n\n"); //enable wakeup pin enable NMI - PTA4 - WUPE3 LLWU_PE1 |= (LLWU_PE1_WUPE3(2)| LLWU_PE1_WUPE2(2)| LLWU_PE1_WUPE1(2) |LLWU_PE1_WUPE0(2)); LLWU_PE2 |= (LLWU_PE2_WUPE7(2)| LLWU_PE2_WUPE6(2)| LLWU_PE2_WUPE5(2) |LLWU_PE2_WUPE4(2)); LLWU_PE3 |= (LLWU_PE3_WUPE11(2)| LLWU_PE3_WUPE10(2)| LLWU_PE3_WUPE9(2) |LLWU_PE3_WUPE8(2)); LLWU_PE4 |= (LLWU_PE4_WUPE15(2)| LLWU_PE4_WUPE14(2)| LLWU_PE4_WUPE13(2) |LLWU_PE4_WUPE12(2)); printf("[LLWU_Init] modules 3,2,1,0 enabled; LLWU PE1 = %#02X \r\n", (LLWU_PE1) ); printf("[LLWU_Init] modules 7,6,5,4 enabled; LLWU PE2 = %#02X \r\n", (LLWU_PE2) ); printf("[LLWU_Init] modules 11,10,9,8 enabled; LLWU PE3 = %#02X \r\n", (LLWU_PE3) ); printf("[LLWU_Init] modules 15,14,13,12 enabled; LLWU PE4 = %#02X \r\n", (LLWU_PE4) ); //falling edge on all pins LLWU_CS = 0x07; //enable reset filter printf("[LLWU_Init]enable reset filter enabled; LLWU_CS = %#02X \r\n", (LLWU_CS) ); //LLWU_M5IF // enable all modules to wakeup from low power modes LLWU_ME |= (LLWU_ME_WUME7_MASK |LLWU_ME_WUME6_MASK |LLWU_ME_WUME5_MASK \ |LLWU_ME_WUME4_MASK |LLWU_ME_WUME3_MASK |LLWU_ME_WUME2_MASK \ |LLWU_ME_WUME1_MASK | LLWU_ME_WUME0_MASK); printf("[LLWU_Init]All modules enabled; LLWU ME = %#02X \r\n", (LLWU_ME) ); NVICISER0 = NVIC_ISER_SETENA_MASK; //enable llwu interrupts in the NVIC }
void llwu_configure(unsigned int pin_en, unsigned char rise_fall, unsigned char module_en ) { uint8 temp; temp = LLWU_PE1; if( pin_en & 0x0001) { LLWU_Info("\n\r Invalid LLWU configured pin PTE1/SCI1_RX/I2C1_SCL /SPI1_SIN"); } if( pin_en & 0x0002) { LLWU_Info("\n\r Invalid LLWU configured pin PTE2/SPI1_SCK/SDHC0_DCLK"); } if( pin_en & 0x0004) { LLWU_Info("\n\r Invalid LLWU configured pin PTE4/SPI1_PCS0/SDHC0_D3"); } if( pin_en & 0x0008) { LLWU_Info("\n\r Invalid LLWU configured pin PTA4/FTM0_CH1/NMI/EZP_CS"); } LLWU_PE1 = temp; temp = LLWU_PE2; if( pin_en & 0x0010) { LLWU_Info("\n\r Invalid LLWU configured pin PTA13/FTM1_CH1 /FTM1_QD_PHB"); } if( pin_en & 0x0020) { temp |= LLWU_PE2_WUPE5(rise_fall); LLWU_Info("\n\r LLWU configured pins PTB0/I2C0_SCL/FTM1_CH0/FTM1_QD_PHA is LLWU wakeup source "); LLWU_F1 |= LLWU_F1_WUF5_MASK; // write one to clear the flag } if( pin_en & 0x0040) { temp |= LLWU_PE2_WUPE6(rise_fall); LLWU_Info("\n\r LLWU configured pins PTC1/SCI1_RTS/FTM0_CH0 is LLWU wakeup source "); LLWU_F1 |= LLWU_F1_WUF6_MASK; // write one to clear the flag } if( pin_en & 0x0080) { temp |= LLWU_PE2_WUPE7(rise_fall); LLWU_Info("\n\r LLWU configured pins PTC3/SCI1_RX/FTM0_CH2 is LLWU wakeup source "); LLWU_F1 |= LLWU_F1_WUF7_MASK; // write one to clear the flag } LLWU_PE2 = temp; temp = LLWU_PE3; if( pin_en & 0x0100) { temp |= LLWU_PE3_WUPE8(rise_fall); LLWU_Info("\n\r LLWU configured pins PTC4/SPI0_PCS0/FTM0_CH3 is LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF8_MASK; // write one to clear the flag } if( pin_en & 0x0200) { temp |= LLWU_PE3_WUPE9(rise_fall); LLWU_Info("\n\r LLWU configured pins PTC5/SPI0_SCK/I2S0_RXD0 is LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF9_MASK; // write one to clear the flag } if( pin_en & 0x0400) { temp |= LLWU_PE3_WUPE10(rise_fall); LLWU_Info("\n\r LLWU configured pins PTC6/PDB0_EXTRG to be an LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF10_MASK; // write one to clear the flag } if( pin_en & 0x0800) { temp |= LLWU_PE3_WUPE11(rise_fall); LLWU_Info("\n\r LLWU configured pins PTC11/I2S0_RXD1 to be an LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF11_MASK; // write one to clear the flag } LLWU_PE3 = temp; temp = LLWU_PE4; if( pin_en & 0x1000) { temp |= LLWU_PE4_WUPE12(rise_fall); LLWU_Info("\n\r LLWU configured pins PTD0/SPI0_PCS0/SCI2_RTS to be an LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF12_MASK; // write one to clear the flag } if( pin_en & 0x2000) { temp |= LLWU_PE4_WUPE13(rise_fall); LLWU_Info("\n\r LLWU configured pins PTD2/SCI2_RX to be an LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF13_MASK; // write one to clear the flag } if( pin_en & 0x4000) { temp |= LLWU_PE4_WUPE14(rise_fall); LLWU_Info("\n\r LLWU configured pins PTD4/SCI0_RTS/FTM0_CH4/EWM_IN is LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF14_MASK; // write one to clear the flag } if( pin_en & 0x8000) { temp |= LLWU_PE4_WUPE15(rise_fall); LLWU_Info("\n\r LLWU configured pins PTD6/SCI0_RX/FTM0_CH6/FTM0_FLT0 is LLWU wakeup source "); LLWU_F2 |= LLWU_F2_WUF15_MASK; // write one to clear the flag } LLWU_PE4 = temp; if (module_en == 0){ LLWU_ME = 0; }else { LLWU_ME |= module_en; //Set up more modules to wakeup up LLWU_Info("\n\r LLWU configured modules as LLWU wakeup sources = 0x%02X,",(LLWU_ME)); } } // End LLWU Configuration
/******************************************************************************* * * llwu_configure - * * description: Set up the LLWU for wakeup of the MCU from LLS and VLLSx modes * from the selected pin or module. * * inputs: pin_en - indicates the wakeup pin is enabled. * rise_fall - 0x00 = External input disabled as wakeup * 0x01 - External input enabled as rising edge detection * 0x02 - External input enabled as falling edge detection * 0x03 - External input enabled as any edge detection * module_en - indicates the wakeup module is enabled. *******************************************************************************/ void llwu_configure(uint32_t pin_en, uint8_t rise_fall, uint32_t module_en ) { llwu_clear_flags(); if (pin_en != 0) { //------------------------------------------------ LLWU_PE1 = 0; if (pin_en & LLWU_PIN_26) { LLWU_PE1 |= LLWU_PE1_WUPE0(rise_fall); } if (pin_en & LLWU_PIN_33) { LLWU_PE1 |= LLWU_PE1_WUPE3(rise_fall); } //------------------------------------------------ LLWU_PE2 = 0; if( pin_en & LLWU_PIN_4) { LLWU_PE2 |= LLWU_PE2_WUPE4(rise_fall); } if( pin_en & LLWU_PIN_16) { //TSI enabled LLWU_PE2 |= LLWU_PE2_WUPE5(rise_fall); } if( pin_en & LLWU_PIN_22) {// TSI ensbled LLWU_PE2 |= LLWU_PE2_WUPE6(rise_fall); } if( pin_en & LLWU_PIN_9) { LLWU_PE2 |= LLWU_PE2_WUPE7(rise_fall); } //------------------------------------------------ LLWU_PE3 = 0; if( pin_en & LLWU_PIN_10) { LLWU_PE3 |= LLWU_PE3_WUPE8(rise_fall); } if( pin_en & LLWU_PIN_13) { LLWU_PE3 |= LLWU_PE3_WUPE9(rise_fall); } if( pin_en & LLWU_PIN_11) { LLWU_PE3 |= LLWU_PE3_WUPE10(rise_fall); } if( pin_en & LLWU_PIN_30) { LLWU_PE3 |= LLWU_PE3_WUPE11(rise_fall); } //------------------------------------------------ LLWU_PE4 = 0; if( pin_en & LLWU_PIN_2) { LLWU_PE4 |= LLWU_PE4_WUPE12(rise_fall); } if( pin_en & LLWU_PIN_7) { LLWU_PE4 |= LLWU_PE4_WUPE13(rise_fall); } if( pin_en & LLWU_PIN_6) { LLWU_PE4 |= LLWU_PE4_WUPE14(rise_fall); } if( pin_en & LLWU_PIN_21) { LLWU_PE4 |= LLWU_PE4_WUPE15(rise_fall); } } if (module_en != 0) { //------------------------------------------------ LLWU_ME = 0; if( module_en & LLWU_LPTMR_MOD) { BITBAND_U8(LLWU_ME, WUME0_BIT) = 1; //LLWU_ME |= LLWU_ME_WUME0_MASK; } if( module_en & LLWU_CMP0_MOD) { BITBAND_U8(LLWU_ME, WUME1_BIT) = 1; //LLWU_ME |= LLWU_ME_WUME1_MASK; } if( module_en & LLWU_CMP1_MOD) { BITBAND_U8(LLWU_ME, WUME2_BIT) = 1; //LLWU_ME |= LLWU_ME_WUME2_MASK; } if( module_en & LLWU_TSI_MOD) { BITBAND_U8(LLWU_ME, WUME4_BIT) = 1; //LLWU_ME |= LLWU_ME_WUME4_MASK; } if( module_en & LLWU_RTCA_MOD) { BITBAND_U8(LLWU_ME, WUME5_BIT) = 1; //LLWU_ME |= LLWU_ME_WUME5_MASK; } if( module_en & LLWU_RTCS_MOD) { BITBAND_U8(LLWU_ME, WUME7_BIT) = 1; //LLWU_ME |= LLWU_ME_WUME7_MASK; } return; } }
/* function: llwu_configure description: Set up the LLWU for wakeup the MCU from LLS and VLLSx modes from the selected pin or module. inputs: pin_en - unsigned integer, bit position indicates the pin is enabled. More than one bit can be set to enable more than one pin at a time. rise_fall - 0x00 = External input disabled as wakeup 0x01 - External input enabled as rising edge detection 0x02 - External input enabled as falling edge detection 0x03 - External input enablge as any edge detection module_en - unsigned char, bit position indicates the module is enabled. More than one bit can be set to enabled more than one module for example: if bit 0 and 1 need to be enabled as rising edge detect call this routine with pin_en = 0x0003 and rise_fall = 0x02 Note: to set up one set of pins for rising and another for falling, 2 calls to this function are required, 1st for rising then the second for falling. */ void llwu_configure(unsigned int pin_en, unsigned char rise_fall, unsigned char module_en ) { uint8_t temp; temp = LLWU_PE1; if( pin_en & 0x0001) { temp |= LLWU_PE1_WUPE0(rise_fall); // LLWU configured pins PTE1/UART1_RX/I2C1_SCL /SPI1_SIN to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF0_MASK; // write one to clear the flag } if( pin_en & 0x0002) { temp |= LLWU_PE1_WUPE1(rise_fall); // LLWU configured pins PTE2/SPI1_SCK/SDHC0_DCLK to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF1_MASK; // write one to clear the flag } if( pin_en & 0x0004) { temp |= LLWU_PE1_WUPE2(rise_fall); // LLWU configured pins PTE4/SPI1_PCS0/SDHC0_D3 to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF2_MASK; // write one to clear the flag } if( pin_en & 0x0008) { temp |= LLWU_PE1_WUPE3(rise_fall); // LLWU configured pins PTA4/FTM0_CH1/NMI/EZP_CS to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF3_MASK; // write one to clear the flag } LLWU_PE1 = temp; temp = LLWU_PE2; if( pin_en & 0x0010) { temp |= LLWU_PE2_WUPE4(rise_fall); // LLWU configured pins PTA13/FTM1_CH1 /FTM1_QD_PHB to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF4_MASK; // write one to clear the flag } if( pin_en & 0x0020) { temp |= LLWU_PE2_WUPE5(rise_fall); // LLWU configured pins PTB0/I2C0_SCL/FTM1_CH0/FTM1_QD_PHA to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF5_MASK; // write one to clear the flag } if( pin_en & 0x0040) { temp |= LLWU_PE2_WUPE6(rise_fall); // LLWU configured pins PTC1/UART1_RTS/FTM0_CH0 to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF6_MASK; // write one to clear the flag } if( pin_en & 0x0080) { temp |= LLWU_PE2_WUPE7(rise_fall); // LLWU configured pins PTC3/UART1_RX/FTM0_CH2 to be an LLWU wakeup source LLWU_F1 |= LLWU_F1_WUF7_MASK; // write one to clear the flag } LLWU_PE2 = temp; temp = LLWU_PE3; if( pin_en & 0x0100) { temp |= LLWU_PE3_WUPE8(rise_fall); // LLWU configured pins PTC4/SPI0_PCS0/FTM0_CH3 to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF8_MASK; // write one to clear the flag } if( pin_en & 0x0200) { temp |= LLWU_PE3_WUPE9(rise_fall); // LLWU configured pins PTC5/SPI0_SCK/I2S0_RXD0 to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF9_MASK; // write one to clear the flag } if( pin_en & 0x0400) { temp |= LLWU_PE3_WUPE10(rise_fall); // LLWU configured pins PTC6/PDB0_EXTRG to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF10_MASK; // write one to clear the flag } if( pin_en & 0x0800) { temp |= LLWU_PE3_WUPE11(rise_fall); // LLWU configured pins PTC11/I2S0_RXD1 to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF11_MASK; // write one to clear the flag } LLWU_PE3 = temp; temp = LLWU_PE4; if( pin_en & 0x1000) { temp |= LLWU_PE4_WUPE12(rise_fall); // LLWU configured pins PTD0/SPI0_PCS0/UART2_RTS to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF12_MASK; // write one to clear the flag } if( pin_en & 0x2000) { temp |= LLWU_PE4_WUPE13(rise_fall); // LLWU configured pins PTD2/UART2_RX to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF13_MASK; // write one to clear the flag } if( pin_en & 0x4000) { temp |= LLWU_PE4_WUPE14(rise_fall); // LLWU configured pins PTD4/UART0_RTS/FTM0_CH4/EWM_IN to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF14_MASK; // write one to clear the flag } if( pin_en & 0x8000) { temp |= LLWU_PE4_WUPE15(rise_fall); // LLWU configured pins PTD6/UART0_RX/FTM0_CH6/FTM0_FLT0 to be an LLWU wakeup source LLWU_F2 |= LLWU_F2_WUF15_MASK; // write one to clear the flag } LLWU_PE4 = temp; LLWU_ME = module_en; //Set up modules to wakeup up }
void llwu_configure(unsigned int pin_en, unsigned char rise_fall, unsigned char module_en ) { uint8 temp; SIM_SCGC4 |= SIM_SCGC4_LLWU_MASK; // used on rev 1.4 of P2 temp = LLWU_PE1; if( pin_en & 0x0001) { temp |= LLWU_PE1_WUPE0(rise_fall); printf(" LLWU configured pins PTA4 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF0_MASK; // write one to clear the flag } if( pin_en & 0x0002) { temp |= LLWU_PE1_WUPE1(rise_fall); printf(" LLWU configured pins PTA5 is wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF1_MASK; // write one to clear the flag } if( pin_en & 0x0004) { temp |= LLWU_PE1_WUPE2(rise_fall); printf(" LLWU configured pins PTA6 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF2_MASK; // write one to clear the flag } if( pin_en & 0x0008) { temp |= LLWU_PE1_WUPE3(rise_fall); printf(" LLWU configured pins PTA7 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF3_MASK; // write one to clear the flag } LLWU_PE1 = temp; temp = LLWU_PE2; if( pin_en & 0x0010) { temp |= LLWU_PE2_WUPE4(rise_fall); printf(" LLWU configured pins PTB0 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF4_MASK; // write one to clear the flag } if( pin_en & 0x0020) { temp |= LLWU_PE2_WUPE5(rise_fall); printf(" LLWU configured pins PTB2 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF5_MASK; // write one to clear the flag } if( pin_en & 0x0040) { temp |= LLWU_PE2_WUPE6(rise_fall); printf(" LLWU configured pins PTB4 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF6_MASK; // write one to clear the flag } if( pin_en & 0x0080) { temp |= LLWU_PE2_WUPE7(rise_fall); printf(" LLWU configured pins PTA0 is LLWU wakeup source \n"); LLWU_F1 |= LLWU_F1_WUF7_MASK; // write one to clear the flag } LLWU_PE2 = temp; /* // temp = LLWU_PE3; if( pin_en & 0x0100) { temp |= LLWU_PE3_WUPE8(rise_fall); printf(" LLWU configured pins PTC4/SPI0_PCS0/FTM0_CH3 is LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF8_MASK; // write one to clear the flag } if( pin_en & 0x0200) { temp |= LLWU_PE3_WUPE9(rise_fall); printf(" LLWU configured pins PTC5/SPI0_SCK/I2S0_RXD0 is LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF9_MASK; // write one to clear the flag } if( pin_en & 0x0400) { temp |= LLWU_PE3_WUPE10(rise_fall); printf(" LLWU configured pins PTC6/PDB0_EXTRG to be an LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF10_MASK; // write one to clear the flag } if( pin_en & 0x0800) { temp |= LLWU_PE3_WUPE11(rise_fall); printf(" LLWU configured pins PTC11/I2S0_RXD1 to be an LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF11_MASK; // write one to clear the flag } // LLWU_PE3 = temp; // temp = LLWU_PE4; if( pin_en & 0x1000) { temp |= LLWU_PE4_WUPE12(rise_fall); printf(" LLWU configured pins PTD0/SPI0_PCS0/SCI2_RTS to be an LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF12_MASK; // write one to clear the flag } if( pin_en & 0x2000) { temp |= LLWU_PE4_WUPE13(rise_fall); printf(" LLWU configured pins PTD2/SCI2_RX to be an LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF13_MASK; // write one to clear the flag } if( pin_en & 0x4000) { temp |= LLWU_PE4_WUPE14(rise_fall); printf(" LLWU configured pins PTD4/SCI0_RTS/FTM0_CH4/EWM_IN is LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF14_MASK; // write one to clear the flag } if( pin_en & 0x8000) { temp |= LLWU_PE4_WUPE15(rise_fall); printf(" LLWU configured pins PTD6/SCI0_RX/FTM0_CH6/FTM0_FLT0 is LLWU wakeup source \n"); // LLWU_F2 |= LLWU_F2_WUF15_MASK; // write one to clear the flag } // LLWU_PE4 = temp; */ if (module_en == 0){ LLWU_ME = 0; }else { LLWU_ME |= module_en; //Set up more modules to wakeup up } printf("LLWU PE1 = 0x%02X, ", (LLWU_PE1)) ; printf("LLWU PE2 = 0x%02X\n", (LLWU_PE2)) ; // printf("LLWU PE3 = 0x%02X, ", (LLWU_PE3)) ; // printf("LLWU PE4 = 0x%02X\n", (LLWU_PE4)) ; printf("LLWU ME = 0x%02X, ", (LLWU_ME)) ; printf("LLWU F1 = 0x%02X\n", (LLWU_F1)) ; // printf("LLWU F2 = 0x%02X, ", (LLWU_F2)) ; printf("LLWU F3 = 0x%02X\n", (LLWU_F3)) ; printf("LLWU FILT1 = 0x%02X, ", (LLWU_FILT1)) ; printf("LLWU FILT2 = 0x%02X\n", (LLWU_FILT2)) ; //function ends }