/* ************************ Standby Functions ***********************************/ void EnterStandby() { //Low Power Mode is configured to be STANDBY1 DL_SYSCTL_setPowerPolicySTANDBY1(); //I2C_0_INST->GPRCM.CLKCFG = (1<<8) | (0xA9 << 24); DL_I2C_disableController(I2C_0_INST);// Disable the I2C controller DL_I2C_disablePower(I2C_0_INST); // Disable the power for I2C controller DL_Timer_disablePower(TIMER_1_INST); // Disable power for the TIMER 1 DL_ADC12_disableConversions(ADC12_0_INST); // Disable the ADC conversions DL_ADC12_disablePower(ADC12_0_INST); // +6 uA due to ADC, even after disabling power DL_VREF_disableInternalRef(VREF); // Disable the interenal ADC reference voltage DL_VREF_disablePower(VREF);// Diable the power for internal ADC reference voltage DL_UART_disable(UART_0_INST); // Disable the UART0 DL_UART_Main_disablePower(UART_0_INST); // +75uA (max), Disable the power for the UART0 } void ExitStandby() { while (DL_SYSCTL_getClockStatus() & DL_SYSCTL_CLK_STATUS_MCLK_SOURCE_LFCLK); while (DL_SYSCTL_getClockStatus() & DL_SYSCTL_CLK_STATUS_FCL_ON); //Configured to be SLEEP0 DL_SYSCTL_setPowerPolicyRUN0SLEEP0(); //DL_GPIO_reset(GPIOA); DL_TimerG_reset(TIMER_0_INST); DL_TimerG_reset(TIMER_1_INST); DL_I2C_reset(I2C_0_INST); // Reset the I2C_0 DL_UART_Main_reset(UART_0_INST); // Reset the UART0 DL_ADC12_reset(ADC12_0_INST); // Reset the ADC12_0 DL_VREF_reset(VREF); // Reset the ADC internal voltage referene DL_I2C_enablePower(I2C_0_INST); // Enable power for I2C0 DL_ADC12_enableConversions(ADC12_0_INST); // enable the ADC12_0 conversion DL_ADC12_enablePower(ADC12_0_INST); // Enable power for ADC12_0 DL_VREF_enablePower(VREF); // Enable power for TIMER1 DL_UART_Main_enablePower(UART_0_INST); // Enable power for TIMER1 DL_Timer_enablePower(TIMER_1_INST); // Enable power for TIMER1 DL_TimerG_reset(TIMER_1_INST); // Reset the TIMER1 DL_I2C_enableController(I2C_0_INST); // Enable the I2C controller DL_UART_enable(UART_0_INST); // enable the UART0 DL_VREF_enableInternalRef(VREF); // Enable the ADC interenal voltage reference SYSCFG_DL_I2C_0_init(); // initlization for I2C_0 SYSCFG_DL_TIMER_1_init();// Initialization for TIMER_1 SYSCFG_DL_UART_0_init();// Initialization for UART0 SYSCFG_DL_ADC12_0_init(); // Initialization for ADC12_0 SYSCFG_DL_VREF_init(); // ADC internal voltage refence Initialization } /* ************************ End - Standby Functions ***********************************/ int main(void) { int8_t l_ret; // return varaible for AFE init fucntion uint32_t l_CalibFlag = 0; // factory calibration flag gSdLibBlueLedEnable=true; gSdLibNoOfOnSamples=5; gSdLibNoOfCycles=3; //#ifdef PRINT_NEED_UART_WRITE char l_send_byte[50]; //#endif SYSCFG_DL_init(); //Configured to be SLEEP0 DL_SYSCTL_setPowerPolicyRUN0SLEEP0(); // Interrupts used are enabled here NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN); // For Stand by NVIC_EnableIRQ(TIMER_1_INST_INT_IRQN); // For RI Indication NVIC_EnableIRQ(TIMER_2_INST_INT_IRQN); // For Pulse Width NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN); #if 0 // ******** Very importent Change , Previously it is acts as one of pre-request // for standby entering DL_SYSCTL_enableSleepOnExit(); #endif #if 1 // For MCU bootup and sync with I2C for(uint8_t dlycnt = 0; dlycnt<1;dlycnt++){ delay_cycles(160000); // 20ms (Approx) } #endif DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_RI_LED_PIN); gHalCheckADC = false; gHalCheckmem0ADC = false; gHalCheckmem1ADC = false; gSdLibCsaMin = SDLIB_LED_A_DACMIN; // LEDA AMUX minimum threshold gSdLibCsaMax = SDLIB_LED_A_DACMAX; // LEDA AMUX maximum threshold gSdLibCsbMin = SDLIB_LED_B_DACMIN; // LEDB AMUX minimum threshold gSdLibCsbMax = SDLIB_LED_B_DACMAX;// LEDB AMUX maximum threshold // DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN); // For Checking PA26 #ifdef UART_TEST // For Checking UART /* Optional delay to ensure UART TX is idle before starting transmission */ delay_cycles(UART_TX_DELAY); while (1) { delay_cycles(UART_TX_DELAY); /* Fills TX FIFO with data and transmits the data */ DL_UART_Main_fillTXFIFO(UART_0_INST, &txPacket[0], UART_PACKET_SIZE); /* Wait until all bytes have been transmitted and the TX FIFO is empty */ while (DL_UART_Main_isBusy(UART_0_INST)) ; } #endif // End - For Checking UART // TPS8804 Initialization and Configuration #ifdef PRINT_NEED_UART_WRITE UART_write("Welcome to smoke detector\0"); #endif // Pre-request for Standby mode EnterStandby(); DL_TimerG_startCounter(TIMER_0_INST); while (1) { //SmokeAlertFun(); #ifdef ENABLE_STANDBY __WFI(); #endif SmokeAlertFun(); } return 0; } // Smoke Monitoring void SmokeAlertFun(){ int8_t l_ret=0; #ifdef ENABLE_STANDBY DL_TimerG_stopCounter(TIMER_0_INST); g_ClockStatus = DL_SYSCTL_getClockStatus(); ExitStandby(); #endif #ifdef PRINT_NEED_UART_WRITE //UART_write("\n Exit from Standby\0"); #endif #ifdef ENABLE_STANDBY //SmokeDetLib_AfeEnable(); // Enable AFE Blocks (Except MCU LDO) //if (ret < 0) { // error in AFE Init // return -1; //} // Enable AFE Blocks (Except MCU LDO) **** #endif // **************************** Smoke Monitoring Start ********************* // LED Blinking DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_LD1_LED1_PIN); DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_LD1_LED2_PIN); delay_cycles(3200000); // 10ms (Approx) when blinking out of standby mode 4MHz //delay_cycles(42000); // 10ms (Approx) when blinking in standby mode 32KHz DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_LD1_LED1_PIN); DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_LD1_LED2_PIN); // **************************** Smoke Monitoring End ********************* //SmokeDetLib_AfeDisable(); // Disable AFE Blocks (Except MCU LDO) // For Standby mode of 5Sec DL_Timer_setLoadValue(TIMER_0_INST, TIMER_0_INST_LOAD_VALUE); // 5 Sec Timer Value EnterStandby(); DL_TimerG_startCounter(TIMER_0_INST); }