//***************************************************************************** // // Uses the fColorWheelPos variable to update the color mix shown on the RGB // // This function is called when system has decided it is time to enter // Hibernate. This will prepare the hibernate peripheral, save the system // state and then enter hibernate mode. // //***************************************************************************** void AppHibernateEnter(void) { // // Alert UART command line users that we are going to hibernate // UARTprintf("Entering Hibernate...\n"); // // Prepare Hibernation Module // HibernateGPIORetentionEnable(); HibernateRTCSet(0); HibernateRTCEnable(); HibernateRTCMatchSet(0, 5); HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); // // Store state information to battery backed memory // since sizeof returns number of bytes we convert to words and force // a rounding up to next whole word. // HibernateDataSet((uint32_t*)&g_sAppState, sizeof(tAppState)/4+1); // // Disable the LED for 100 milliseconds to let user know we are // ready for hibernate and will hibernate on relase of buttons // RGBDisable(); SysCtlDelay(SysCtlClockGet()/3/10); RGBEnable(); // // Wait for wake button to be released prior to going into hibernate // while(g_sAppState.ui32Buttons & RIGHT_BUTTON) { // //Delay for about 300 clock ticks to allow time for interrupts to //sense that button is released // SysCtlDelay(100); } // // Disable the LED for power savings and go to hibernate mode // RGBDisable(); HibernateRequest(); }
/***************************************************** * Function: init_Hibernation * Description: Initialize hibernation module * Input: NONE * Output: NONE *****************************************************/ void init_Hibernation(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // Enable hibernation module HibernateEnableExpClk(SysCtlClockGet()); // Enable clocking to the hibernation module HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE); // Configure the clock source for hibernation module HibernateGPIORetentionEnable(); // Retain GPIO state during hibernation // HibernateRTCEnable(); // Enable the RTC // HibernateRTCSet(0); // Clear the RTC time //HibernateRTCMatchSet(0, HibernateRTCGet() + 5); // Set the match 0 register for 5 seconds from now HibernateWakeSet(HIBERNATE_WAKE_PIN); // Configure to wake on button press or RTC match // HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC // Clear any pending status. // int status = HibernateIntStatus(0); // Clear any pending status HibernateIntClear(status); }
/************************** YOSEMIT XOLALPA ROSALES PROF. VENKI CPE403 TIVAC-LAB06 **************************/ int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x08); SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); HibernateEnableExpClk(SysCtlClockGet()); HibernateGPIORetentionEnable(); SysCtlDelay(64000000); HibernateRTCSet(0); HibernateRTCEnable(); HibernateRTCMatchSet(0,5); HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_3, 0x00); HibernateRequest(); while(1) { } }
int main(void) { char stringbuffer[17]; int distance = 0; // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. ROM_FPUEnable(); ROM_FPULazyStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); //This wasn't clear at all. Note to self, everything needs enabling on this chip. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); ROM_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, WAKEPIN); ROM_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, REEDPIN); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, V5POWER); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, V3POWER); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, SERVO); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); ROM_GPIOPinWrite(GPIO_PORTE_BASE, V3POWER, 0xFF); #ifdef EASYOPEN ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); #endif GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinConfigure(GPIO_PC6_U3RX); GPIOPinConfigure(GPIO_PC7_U3TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), GPSBAUD, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), GPSBAUD, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); ROM_IntEnable(INT_UART3); ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); SysTickPeriodSet(SysCtlClockGet()/10000); SysTickIntRegister(&ServoDriver); SysTickIntEnable(); SysTickEnable(); ROM_IntMasterEnable(); GPIOIntTypeSet(GPIO_PORTA_BASE, REEDPIN, GPIO_FALLING_EDGE); GPIOPinIntClear(GPIO_PORTA_BASE, REEDPIN); GPIOPinIntEnable(GPIO_PORTA_BASE, REEDPIN); IntEnable(INT_GPIOA); // while(1){} /* SysCtlDelay(SysCtlClockGet()/1000);//Make sure the servo is going to get a pulse soon. ROM_GPIOPinWrite(GPIO_PORTE_BASE, V5POWER, 0xFF); //Turn on the 5V power to LCD + servo. SysCtlDelay(SysCtlClockGet()/1000);//Make sure the servo is going to get a pulse soon.*/ EEPROMInit(); initLCD(); LCDCommand(0x0c); #ifdef LOOPBACKUART while(1){} #endif #ifdef FIRSTRUN //First run, sets the eeprom to have as many tries as is desired. EEPROMMassErase(); EEPROMProgram(&initialNumTries,eepromAddress,sizeof(initialNumTries)); LCDWriteText("Setup Complete. ", 0, 0); LCDWriteText("Reflash Firmware", 1, 0); while (1){} //Don't want to do anything else now. #endif EEPROMRead(&numTrieslong,eepromAddress,sizeof(numTrieslong)); // numTries=(int)numTrieslong; // openLock(); // numTrieslong=0; if (numTrieslong > initialNumTries-3) //Has already opened once, so just open as needed if stuck. { openLock(); numTrieslong--; EEPROMProgram(&numTrieslong,eepromAddress,sizeof(numTrieslong)); //Decrement EEPROM counter. } else { distance = getDistance(); if(distance==99999){ //No fix :/ LCDWriteText("Location unknown", 0, 0); LCDWriteText("Take me outside ", 1, 0); SysCtlDelay(SysCtlClockGet()); //Waits 3 seconds. } else if (distance>NEARENOUGH) //Valid fix, too far away. { if ((int)numTrieslong>0) //Any attempts remaining? { usnprintf(stringbuffer,17,"Distance: %4dm ",distance); LCDWriteText(stringbuffer, 0, 0); numTrieslong--; // numTries=(int)numTrieslong; EEPROMProgram(&numTrieslong,eepromAddress,sizeof(numTrieslong)); //Decrement EEPROM counter. usnprintf(stringbuffer,17,"%2d Attempts left",(int)numTrieslong); LCDWriteText(stringbuffer, 1, 0); SysCtlDelay(SysCtlClockGet()*2); } else { LCDWriteText("Oh dear... ", 0, 0); //Not really sure what to do, hopefully this code never runs. LCDWriteText("Opening anyway. ", 1, 0); // numTrieslong=initialNumTries+1; // EEPROMProgram(&numTrieslong,eepromAddress,sizeof(initialNumTries)); //Set to big value SysCtlDelay(10*SysCtlClockGet()/3); openLock(); } } else //Found the location! { openLock(); numTrieslong=initialNumTries+1; //numTries=(int)numTrieslong; EEPROMProgram(&numTrieslong,eepromAddress,sizeof(initialNumTries)); //Lock will now open straight away. } } // BLINK(RED); HibernateEnableExpClk(SysCtlClockGet()); HibernateGPIORetentionEnable(); //Enables GPIO retention after wake from hibernate. HibernateClockSelect(HIBERNATE_CLOCK_SEL_RAW); HibernateWakeSet(HIBERNATE_WAKE_PIN); HibernateIntRegister(&HibernateInterrupt); HibernateIntEnable(HIBERNATE_INT_PIN_WAKE); //BLINK(BLUE); ROM_GPIOPinWrite(GPIO_PORTE_BASE, V5POWER, 0); //GPIO pins keep state on hibernate, so make sure to power everything else down. ROM_GPIOPinWrite(GPIO_PORTE_BASE, V3POWER, 0); //GPIO pins keep state on hibernate, so make sure to power everything else down. ROM_GPIOPinWrite(GPIO_PORTB_BASE, RS|E|D4|D5|D6|D7, 0xFF); //Pull all data pins to LCD high so we're not phantom powering it through ESD diodes. ROM_GPIOPinWrite(GPIO_PORTF_BASE, SERVO, 0xFF); //Likewise for the servo SysCtlDelay(SysCtlClockGet()/6); HibernateRequest();// we want to be looping'n'shit. while(1){} //Lalala, I'm a sleeping right now. }