/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { /* Chip errata */ CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); /* Ensure core frequency has been updated */ SystemCoreClockUpdate(); /* Init LCD with no voltage boost */ SegmentLCD_Init(oldBoost); /* Setup RTC to generate an interrupt every minute */ rtcSetup(); /* Setup GPIO with interrupts to serve the pushbuttons */ gpioSetup(); /* Main function loop */ clockLoop(); return 0; }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { /* Chip errata */ CHIP_Init(); /* Ensure core frequency has been updated */ SystemCoreClockUpdate(); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); /* Init LCD with no voltage boost */ SegmentLCD_Init(oldBoost); /* Setup RTC to generate an interrupt every minute */ rtcSetup(); /* Enable GPIO clock */ CMU_ClockEnable(cmuClock_GPIO, true); /* Setup GPIO interrupt to set the time */ gpioSetup(); /* Main function loop */ //clockLoop(); main_loop(); return 0; }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { /* Chip errata */ CHIP_Init(); gpioSetup(); SegmentLCD_Init(false); //init the segment lcd, bool used to check if power supply i low rtcSetup(); leTimerSetup(); leTimerTurnOff(); /* Infinite loop */ while (1) { EMU_EnterEM2(true); } }
/****************************************************************************** * @brief Main function * *****************************************************************************/ int main( void ) { /* Initialize chip - handle erratas */ CHIP_Init(); /* Initialize the temperature compensated calendar */ Clock_Init_TypeDef initialCalendar = CLOCK_INIT_DEFAULT; initialCalendar.rtcCountsPerSec = RTC_COUNTS_PER_SEC; initialCalendar.tempCompInterval = TC_INTERVAL; clockInit(&initialCalendar); /* Initialize user interface */ uiInit(); /* Setup RTC */ rtcSetup(); /* ---------- Eternal while loop ---------- */ while (1) { /* Update display */ if ( doDisplayUpdate ) { /* Clear doDisplayUpdate flag */ doDisplayUpdate = false; /* Get current time and write to display */ time_t currentTime; time( ¤tTime ); uiDisplay( ¤tTime ); } /* Perform temperature compensation */ if ( doTemperatureCompensation ) { /* Clear doTemperatureCompensation flag */ doTemperatureCompensation = false; clockDoTemperatureCompensation(); } /* Sleep while waiting for interrupt */ EMU_EnterEM2(false); } }
/**************************************************************************//** * @brief Toggle a GPIO pin automatically at the given frequency. * * @param[in] gpioPort GPIO port number of GPIO ping to toggle. * @param[in] gpioPin GPIO pin number. * * @return EMSTATUS code of the operation. *****************************************************************************/ EMSTATUS PAL_GpioPinAutoToggle (unsigned int gpioPort, unsigned int gpioPin, unsigned int frequency) { EMSTATUS status = EMSTATUS_OK; /* Store GPIO pin data. */ gpioPortNo = gpioPort; gpioPinNo = gpioPin; /* Setup GPIO pin. */ GPIO_PinModeSet((GPIO_Port_TypeDef)gpioPort, gpioPin, gpioModePushPull, 0 ); /* Setup RTC to generate interrupts at given frequency. */ rtcSetup(frequency); return status; }
/**************************************************************************//** * @brief Toggle a GPIO pin automatically at the given frequency. * * @param[in] gpioPort GPIO port number of GPIO ping to toggle. * @param[in] gpioPin GPIO pin number. * * @return EMSTATUS code of the operation. *****************************************************************************/ EMSTATUS PAL_GpioPinAutoToggle (unsigned int gpioPort, unsigned int gpioPin, unsigned int frequency) { EMSTATUS status = EMSTATUS_OK; #ifdef INCLUDE_PAL_GPIO_PIN_AUTO_TOGGLE_HW_ONLY #if defined( BSP_STK_2010 ) /* We only support auto HW toggling on GPIO port E pin 10 on Zero STK. */ if ( (gpioPortE != gpioPort) || (10 != gpioPin) ) #elif defined( BSP_STK_2011 ) /* We only support auto HW toggling on GPIO port F pin 3 on Happy STK. */ if ( (gpioPortF != gpioPort) || (3 != gpioPin) ) #elif defined( BSP_STK_2500 ) /* We only support auto HW toggling on GPIO port D pin 13 on Pearl STK. */ if ( (gpioPortD != gpioPort) || (13 != gpioPin) ) #else #error "Illegal display auto-toggle setup." #endif { status = PAL_EMSTATUS_INVALID_PARAM; } else { /* Setup PRS to drive the GPIO pin which is connected to the display com inversion pin (EXTCOMIN) using the RTC COMP0 signal or RTCC CCV1 signal as source. */ #if defined(PAL_CLOCK_RTCC) uint32_t source = PRS_CH_CTRL_SOURCESEL_RTCC; uint32_t signal = PRS_CH_CTRL_SIGSEL_RTCCCCV1; #else uint32_t source = PRS_CH_CTRL_SOURCESEL_RTC; uint32_t signal = PRS_CH_CTRL_SIGSEL_RTCCOMP0; #endif /* Enable PRS clock */ CMU_ClockEnable(cmuClock_PRS, true); /* Set up PRS to trigger from an RTC compare match */ PRS_SourceAsyncSignalSet(LCD_AUTO_TOGGLE_PRS_CH, source, signal); /* This outputs the PRS pulse on the EXTCOMIN pin */ #if defined(_SILICON_LABS_32B_PLATFORM_2) LCD_AUTO_TOGGLE_PRS_ROUTELOC(); PRS->ROUTEPEN |= LCD_AUTO_TOGGLE_PRS_ROUTEPEN; #else PRS->ROUTE = ( PRS->ROUTE & ~_PRS_ROUTE_LOCATION_MASK ) | LCD_AUTO_TOGGLE_PRS_ROUTE_LOC; PRS->ROUTE |= LCD_AUTO_TOGGLE_PRS_ROUTE_PEN; #endif } #else /* Store GPIO pin data. */ gpioPortNo = gpioPort; gpioPinNo = gpioPin; #endif if (EMSTATUS_OK == status) { /* Setup GPIO pin. */ GPIO_PinModeSet((GPIO_Port_TypeDef)gpioPort, gpioPin, gpioModePushPull, 0 ); #if defined(PAL_CLOCK_RTCC) /* Setup RTCC to to toggle PRS or generate interrupts at given frequency. */ rtccSetup(frequency); #else /* Setup RTC to to toggle PRS or generate interrupts at given frequency. */ rtcSetup(frequency); #endif } return status; }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Setup and pin configurations clkSetup(); directionSetup(); timerA0Setup(); boardSetup(); rtcSetup(); initUART(); pinGSM(); // clkDebug(); readDip(); // test V4Stop(); V5Stop(); // Sensor variables int sensorValue = 0; int sensorData[LengthOfSensordata] = {0}; char dataEnable = 0; // != 0 if the vector is filled ones int dataPosition = 0; int overflowCount = 0; char alarm = '0'; // Parameters (From and to the flash) int lowerThresholds = readFlashLowTolerance(); int upperThresholds = readFlashHighTolerance(); int normalLvl = readFlashSensorOffset(); // Default higth over the water lvl // GSM decision variable char execution = '0'; char disableAlarmFlag = '0'; // Disable = 1 // RTC variable time offset1 = 1 min unsigned int rtcOffsetH = 0xFC6C; unsigned int rtcOffsetL = 0x78FF; __enable_interrupt(); while(1) { V5Start(); _no_operation(); char c = '0'; if(loop2Mode == '1' || startMode == '1') { // Power on the GSM regulator V4Start(); // Enable power to GSMJa if(P8IN &= BIT4) { c = checkAT(); if(c =='0') pwrOnOff(); } else { pwrOnOff(); Delay(); c = '0'; } } sensorValue = mainFunctionSensor(sensorData, LengthOfSensordata, &dataPosition, &dataEnable, &overflowCount); if (loop2Mode == '1' || startMode == '1') { // wait for connection and check if SMS unsigned int count = 0; while(!(P8IN &= BIT4) || count < 40000) { count++; __delay_cycles(100); } if(c == '0') c = checkAT(); if(c == '0') { V4Stop(); Delay(); Delay(); V5Start(); V4Start(); if(P8IN &= BIT4) { c = checkAT(); if(c =='0') pwrOnOff(); } else { pwrOnOff(); Delay(); } } initGSM(); execution = readSMS(); if (execution == '0') { // Nothing _no_operation();// test } else if (execution == 'S') { // Status report responseStatus("STATUS i ", (normalLvl-sensorValue)); deleteSMS(); } else if (execution == 'N') { // Confirm Nr change responseNrChange("Nummerlista uppdaterad i "); deleteSMS(); } else if (execution == 'L') { // Confirm changed normal level normalLvl = readFlashSensorOffset(); responseLvlChange("Offset i ", normalLvl); deleteSMS(); } else if (execution == 'T') { // Confirm changed thresholds lowerThresholds = readFlashLowTolerance(); upperThresholds = readFlashHighTolerance(); responseThChange("Toleranser i ", lowerThresholds, upperThresholds); deleteSMS(); } else if (execution == 'E') { // Enable SMS sendSMS("Modulen har blivit aktiverad i "); disableAlarmFlag = '0'; deleteSMS(); } else if (execution == 'D') { // Disable SMS sendSMS("Modulen har blivit inaktiverad i"); disableAlarmFlag = '1'; deleteSMS(); } else if (execution == 'A') { // Disable SMS with when alarm sendSMS("Larmet stoppat"); deleteSMS(); disableAlarmFlag = '1'; // Reseted when the lvl goes back to normal. } else { /* Nothing */ } } // if the GSM mode disable turn off the power if (loop2Mode != '1' && startMode != '1') { V5Stop(); V4Stop(); } if (dataEnable != 0 && overflowCount == 0) { // Process the sensor value alarm = evaluateData(sensorValue, normalLvl, upperThresholds, lowerThresholds, &rtcOffsetH, &rtcOffsetL, &timerAlarmFlag); } else if (overflowCount > 10) { // Alarm overflow (Problem om man minskar RTC och något ligger ivägen!!!!) alarm = 'O'; } else {} if (alarm != '0') { if (loop2Mode != '1' && startMode != '1' && disableAlarmFlag != '1' && timerAlarmFlag == '1') startGSMmodule(); if(loop2Mode == '1' && startMode == '1' && disableAlarmFlag != '1' && timerAlarmFlag == '1') { c = checkAT(); if(c == '0') startGSMmodule(); } if (alarm == '+') { // Alarm for high water lvl if (disableAlarmFlag != '1' && timerAlarmFlag == '1') { sendAlarm("Hog vattenniva i ", (normalLvl-sensorValue)); timerAlarmFlag = '0'; } } else if (alarm == '-') { // Alarm for low water lvl if (disableAlarmFlag != '1' && timerAlarmFlag == '1') { sendAlarm("Lag vattenniva i ", (normalLvl-sensorValue)); timerAlarmFlag = '0'; } } else if (alarm == 'O' && timerAlarmFlag == '1') { // Alarm for overflow sendSMS("Sensor kan vara ur funktion i "); timerAlarmFlag = '0'; } else {} if (loop2Mode != '1' && startMode != '1' && timerAlarmFlag == '1') { V5Stop(); V4Stop(); } } else if (alarm == '0' && timerAlarmFlag == '1') { // return to normal mode disableAlarmFlag = '0'; // RTC for Repeat alarm // Send sms } rtcStart(rtcOffsetH, rtcOffsetL); } }