//**************************************************************************** // @Module Power Saving Modes // @Filename PS.C // @Project CL2.0.dav //---------------------------------------------------------------------------- // @Controller Infineon XC886CLM-8FF // // @Compiler Keil // // @Codegenerator 1.3 // // @Description: This file contains functions that use the PS module. // //---------------------------------------------------------------------------- // @Date 2025/1/21 08:53:36 // //**************************************************************************** // USER CODE BEGIN (PS_General,1) // USER CODE END //**************************************************************************** // @Project Includes //**************************************************************************** #include "MAIN.H" // USER CODE BEGIN (PS_General,2) // USER CODE END //**************************************************************************** // @Macros //**************************************************************************** // USER CODE BEGIN (PS_General,3) // USER CODE END //**************************************************************************** // @Defines //**************************************************************************** // USER CODE BEGIN (PS_General,4) // USER CODE END //**************************************************************************** // @Typedefs //**************************************************************************** // USER CODE BEGIN (PS_General,5) // USER CODE END //**************************************************************************** // @Imported Global Variables //**************************************************************************** // USER CODE BEGIN (PS_General,6) // USER CODE END //**************************************************************************** // @Global Variables //**************************************************************************** // USER CODE BEGIN (PS_General,7) // USER CODE END //**************************************************************************** // @External Prototypes //**************************************************************************** // USER CODE BEGIN (PS_General,8) // USER CODE END //**************************************************************************** // @Prototypes Of Local Functions //**************************************************************************** // USER CODE BEGIN (PS_General,9) // USER CODE END //**************************************************************************** // @Function void PS_vInit(void) // //---------------------------------------------------------------------------- // @Description This is the initialization function of the Power Saving // function library. It is assumed that the SFRs used by this // library are in their reset state. // // This function does not contain any generated C-code, but it // is possible to insert application specific source lines. // //---------------------------------------------------------------------------- // @Returnvalue None // //---------------------------------------------------------------------------- // @Parameters None // //---------------------------------------------------------------------------- // @Date 2025/1/21 // //**************************************************************************** // USER CODE BEGIN (PS_Init,1) // USER CODE END void PS_vInit(void) { // USER CODE BEGIN (PS_Init,2) // USER CODE END /// Slow Down Clock is 48.00 MHz /// which is 1/4 of the System Clock fSYS /// wake up with reset is selected SFR_PAGE(_su1, noSST); // switch to page1 with out saving /// Pin P0.1 (input) /// - used as wake up pin via RXD_1 from powerdown /// Pin P0.5 (input) /// - used as wake up pin via EXINT0 from powerdown PMCON0 = 0x13; // wakeup control register // ---------- Modules configuration status for PMCON1 reg.---------- /// ADC enabled /// SSC disabled /// CCU enabled /// T2 enabled /// MDU enabled /// CAN enabled /// CDC enabled PMCON1 = 0x02; // Power mode control register 1 SFR_PAGE(_su3, noSST); // switch to page3 with out saving // ---------- Modules configuration status for PMCON2 reg.---------- /// T21 enabled /// UART1 enabled PMCON2 = 0x00; // Power mode control register 2 SFR_PAGE(_su0, noSST); // switch to page0 with out saving IEN0 |= 0x01; // interrupt enable register 0 TCON = 0x01; // Set TCON.IT0 MODPISEL = 0x01; // load peripheral input select reg } // End of function PS_vInit //**************************************************************************** // @Function void PS_vSetPowerDown(void) // //---------------------------------------------------------------------------- // @Description This function invokes the software power down mode by // execution of following steps: // - the external wake-up from software power down remains // disabled // - bit PD in SFR PMCON0 will be set // (this will stop all controller functions) // //---------------------------------------------------------------------------- // @Returnvalue None // //---------------------------------------------------------------------------- // @Parameters None // //---------------------------------------------------------------------------- // @Date 2025/1/21 // //**************************************************************************** void PS_vSetPowerDown(void) { // enter software power down mode STR_PAGE(_su1, _su); // push current SCU page and switch to page1 /// External wake-up enabled /// Wake-up via pin RxD_1 and EXINT0 is selected PMCON0|=0x03; MAIN_vUnlockProtecReg(); // open access to protected register PMCON0 |= 0x04; // set PD MAIN_vlockProtecReg(); // close access to protected register RST_PAGE(_su); // restore the old SCU page } // End of function PS_vSetPowerDown //**************************************************************************** // @Function void PS_vSetSlowDown(void) // //---------------------------------------------------------------------------- // @Description This function activates the slow down mode by setting bit // SD in SFR PMCON0. // Note: DAvE's project settings for the on-chip peripheral // components are only valid for normal clock operation. // During slow down mode the behavior of the peripherals can // differ from these settings due to the reduced clock rate! // //---------------------------------------------------------------------------- // @Returnvalue None // //---------------------------------------------------------------------------- // @Parameters None // //---------------------------------------------------------------------------- // @Date 2025/1/21 // //**************************************************************************** void PS_vSetSlowDown(void) { STR_PAGE(_su1, _su); // push current SCU page and switch to page1 MAIN_vUnlockProtecReg(); // open access to protected register PMCON0 |= 0x08; // set SD MAIN_vlockProtecReg(); // close access to protected register RST_PAGE(_su); // restore the old SCU page } // End of function PS_vSetSlowDown //**************************************************************************** // @Function void PS_vResetSlowDown(void) // //---------------------------------------------------------------------------- // @Description This function terminates the slow down mode by clearing bit // SD in SFR PMCON0. // //---------------------------------------------------------------------------- // @Returnvalue None // //---------------------------------------------------------------------------- // @Parameters None // //---------------------------------------------------------------------------- // @Date 2025/1/21 // //**************************************************************************** void PS_vResetSlowDown(void) { STR_PAGE(_su1, _su); // push current SCU page and switch to page1 MAIN_vUnlockProtecReg(); // open access to protected register PMCON0 &= ~(ubyte)0x08; // clear SD MAIN_vlockProtecReg(); // close access to protected register RST_PAGE(_su); // restore the old SCU page } // End of function PS_vResetSlowDown // USER CODE BEGIN (PS_General,10) // USER CODE END