/*--------------------------------------------------------------------------- * Setup the hardware *---------------------------------------------------------------------------*/ static void prvSetupHardware( void ) { prvInitPort00(); #if WATCHDOG != WTC_NONE InitWatchdog(); #endif }
void main(void) { //--- CPU Initialization InitSysCtrl(); // Initialize the CPU (FILE: SysCtrl.c) InitGpio(); // Initialize the shared GPIO pins (FILE: Gpio.c) InitPieCtrl(); // Initialize and enable the PIE (FILE: PieCtrl.c) InitWatchdog(); // Initialize the Watchdog Timer (FILE: WatchDog.c) //--- Peripheral Initialization InitAdc(); // Initialize the ADC (FILE: Adc.c) InitEPwm(); // Initialize the EPwm (FILE: EPwm.c) int d; for (d = 0; d < SIN_DEFINITION; d++) { sinValues[d] = (int)(fabs(sin(d * 180.f / SIN_DEFINITION * 2 * PI / 360)) * SIN_AMPLITUDE) + LOWER_HYSTERESIS_BAND; } // Variable Initialization asm (" ESTOP0"); // Emulator Halt instruction int i = 0; //--- Enable global interrupts // Enable global interrupts and realtime debug asm("DBGM"); asm(" CLRC INTM"); //--- Main Loop while(D) // endless loop - wait for an interrupt { i ++; if (i == 600) { EPwm1Regs.AQSFRC.bit.ACTSFA = 1; // What to do when One-Time Software Forced Event is invoked // 00 Does nothing (action disabled) // 01 Clear (low) // 10 Set (high) // 11 Toggle EPwm1Regs.AQSFRC.bit.OTSFA = 1; // Invoke One-Time Software Forced Event on Output A EPwm1Regs.AQSFRC.bit.ACTSFB = 2; // What to do when One-Time Software Forced Event is invoked // 00 Does nothing (action disabled) // 01 Clear (low) // 10 Set (high) // 11 Toggle EPwm1Regs.AQSFRC.bit.OTSFB = 1; // Invoke One-Time Software Forced Event on Output A i = 0; } } //--- Main Loop while(1) // endless loop - wait for an interrupt { asm(" NOP"); } } //end of main()
static void prvSetupHardware( void ) { /* Initialise the port used by the LEDs. */ vParTestInitialise(); /* See watchdog.h for definitions relating to the watchdog use. */ #if WATCHDOG != WTC_NONE InitWatchdog(); #endif }
static void prvSetupHardware( void ) { /* Allow all interrupt levels. */ __set_il( mainINTERRUPT_LEVELS ); /* Initialise interrupts. */ InitIrqLevels(); /* Initialise the ports used by the LEDs. */ vParTestInitialise(); /* If we are going to use the watchdog, then initialise it now. */ #if WATCHDOG != WTC_NONE InitWatchdog(); #endif }
int main(int argc, char** argv) { //Initializations InitCLK(); InitGPIO(); InitDAC(); InitSPI(); InitTimer0(); InitWatchdog(); //Setup interrupts PEIE = 1; GIE = 1; SPI_CS = CS_IDLE; //must be changed! SSPCON1bits.SSPEN=0; // Disable SPI Port //PORTCbits.RC5 = 0; //Set MOSI low //PORTCbits.RC3 = 0; //Set SCK low PORTCbits.PORTC = LATCbits.LATC & 0xD7; //set MOSI and SCK low while(1) { SPI_CS = CS_IDLE; //hands off mode for testing the launcher //Check if beacon has been launched CheckDisconnect(); //DONE+TESTED if(playbackFlag&&!MEM_ACCESS) { PlaybackMode(); playbackFlag = 0; } //Transmit message if(transmitFlag) //DONE+TESTED TransmitMode(); //DONE+TESTED //Go back to sleep, wait for interrupts Hibernate(); } return (EXIT_SUCCESS); }
int main(void) { // Configure the system clock. // The system clock is 168Mhz. RCC_HSEConfig(RCC_HSE_ON); // ENABLE HSE (HSE = 8Mhz) while(!RCC_WaitForHSEStartUp()); // Wait for HSE to stabilize SystemCoreClockUpdate(); RCC_PCLK1Config(RCC_HCLK_Div4); // Set APB1=42Mhz (168/4) // Initialize peripheral modules InitCAN(); InitGPIO(); InitButtons(); InitEXTI(); InitNVIC(); InitTim(); InitSystick(); InitWatchdog(); /* Check if the IWDG reset has occoured */ /*if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) == SET){ GPIOA->ODR |= GPIO_Pin_6; //temp action RCC_ClearFlag(); }*/ while(1) { if(clk10msWheel == COMPLETE){ TxWheelrpm(); clk10msWheel = RESTART; } checkButtons(); LED_SetState(LED_GREEN, (GPIOE->IDR & BUTTON_START_GPIO_PIN) ? DISABLE : ENABLE); LED_SetState(LED_RED, (GPIOE->IDR & BUTTON_STOP_GPIO_PIN) ? ENABLE : DISABLE); } }
void main(void) { IFR = 0x0000; IER = 0x0000; DisableWatchdog(); InitSysParameters(); // Initialization of system parameters InitSysTimer(); // Initialization of system timer #if (USE_TEST1_PIN) TEST_1_INI(); TEST_1_OFF(); #endif #if (USE_TEST2_PIN) TEST_2_INI(); TEST_2_OFF(); #endif InitWatchdog(); // Initialization of watchdog InitXWatchdog(); // Initialization of extern watchdog InitIndicators(); // InitSwitches(); InitKeyboard(); SetTimer(T_LED, T_LED_D); // Set Timers SetTimer(T_SEC, T_SEC_D); SetTimer(T_SWT, T_SWT_D); PieCtrlRegs.PIEACK.all = 0xFFFF; // Enables PIE to drive a pulse into the CPU EINT; // Enable Interrupts at the CPU level //--- Enable interrupts //SetDBGIER(IER); // Configure the DBGIER for realtime debug //asm(" CLRC INTM, DBGM"); // Enable global interrupts and realtime debug TimeDev.second = 0; TimeDev.minute = 0; TimeDev.hour = 0; TimeDev.date = 0; EnableWatchdog(); //-------------------------------------------------------------------------------------------------- for(;;) // Main loop { ServiceWatchdog(); // Reset Watchdog //-------------------------------------------------------------------------------------------------- //----------------------------------------------// Time intervals if(CheckTimer(T_SEC)) { SetTimer(T_SEC, T_SEC_D); if (++TimeDev.second > 59) { TimeDev.second = 0; if (++TimeDev.minute > 59) { TimeDev.minute = 0; if (++TimeDev.hour > 23) { TimeDev.hour = 0; TimeDev.date++; } } } } //-------------------------------------------------------------------------------------------------- //----------------------------------------------// Indication if(CheckTimer(T_LED)) { Debug[0]++; SetTimer(T_LED, T_LED_D); //----------------------------------------------// Signaling the state of the system // ControlLedWork(TOGGLE); // LED indicates normal work of the system //ControlIndicatorPower(TOGGLE); // Indication of connection to the power line //----------------------------------------------// Signaling presence of errors /*if (FlagDev.bit.ERR) { ControlLedError(TOGGLE); //ControlIndicatorError(TOGGLE); } else { ControlLedError(OFF); //ControlIndicatorError(OFF); }*/ #if (USE_INDICATOR1) //----------------------------------------------// Indication of the device working // in the converter mode /*if (FlagDev.bit.WORK) { ControlIndicatorWork(ON); } else { ControlIndicatorWork(OFF); }*/ #endif #if (USE_INDICATOR2) //----------------------------------------------// Indication of the presence of communication // with the control device /*if (!ErrorDev.bit.CTR) { ControlIndicatorLink(ON); } else { ControlIndicatorLink(OFF); }*/ #endif } if(CheckTimer(T_SWT)) { #if (USE_SWT1) if (CheckButtonStop() && !CheckButtonStart()) { FlagDev.bit.STOP = 1; } #endif #if (USE_SWT2) if (CheckButtonStart() && !CheckButtonStop()) { FlagDev.bit.PUSK = 1; } #endif #if (USE_SWT3) if (CheckButtonReset()) { FlagDev.bit.RESET = 1; } #endif #if (USE_ONB_BUT1) if (CheckButtonOnboard1()) { ControlLedOnboard3(ON); } else { ControlLedOnboard3(OFF); } #endif #if (USE_KBRD) CheckKeyboard(); if(KeyboardStat.bit.BUT1) { ControlLedWork(ON); Debug[1] = 1; } else { ControlLedWork(OFF); Debug[1] = 0; } if(KeyboardStat.bit.BUT2) { ControlLedError(ON); Debug[2] = 1; } else { ControlLedError(OFF); Debug[2] = 0; } if(KeyboardStat.bit.BUT4) { ControlLedOnboard3(ON); Debug[3] = 1; } else { ControlLedOnboard3(OFF); Debug[3] = 0; } if(KeyboardStat.bit.BUT5) { ControlLedOnboard4(ON); Debug[4] = 1; } else { ControlLedOnboard4(OFF); Debug[4] = 0; } #endif } //-------------------------------------------------------------------------------------------------- } }
int main(int argc, char** argv) { //Initializations InitCLK(); InitGPIO(); InitADC(); //InitSPI(); InitTimer0(); InitTimer1(); InitWatchdog(); InitUART(); //Initialize UART module unsigned char periodicCounter = MIN_PERIOD; gpsIndex = 0; INTCONbits.GIE = 1; ToggleSleepGPS(); //Turn GPS on SetupGPS(); //Setup Lat/Long recording PORTBbits.PORTB = LATBbits.LATB & 0xDF; //turn red LED off PORTBbits.PORTB = LATBbits.LATB | 0x10; //turn green LED on __delay_ms(100); PORTBbits.PORTB = LATBbits.LATB & 0xEF; //turn green LED off SPI_CS = CS_IDLE;//prerecord while(1){ //PRE_RECORD FUNCTION //InitSPI(); //Start-up SPI again //PreRecordMode(); //SSPCON1bits.SSPEN=0; // Disable SPI Port //PORTCbits.RC5 = 0; //Set MOSI low //SPI_CS = CS_IDLE;//prerecord //__delay_ms(5); SPI_CS = CS_IDLE; //Check Flags if(PORTAbits.RA1) { //Strobe LED PORTBbits.RB0 = 1; __delay_ms(100); PORTBbits.RB0 = 0; } if(recordFlag) { RecordMode(); recordFlag = 0; __delay_ms(500); //trying to get gps to not hangup } //Not recording, Update the GPS if(gpsTimeoutState==0) UpdateGPS(); //tell GPS to send an update else if(gpsTimeoutState==1) { ToggleSleepGPS(); gpsTimeoutState = 2; } else if(gpsTimeoutState==2) { ToggleSleepGPS(); gpsTimeoutState = 3; } else if(gpsTimeoutState==3) { __delay_ms(1000); gpsTimeoutState = 0; } else { gpsTimeoutState = 0; } if(gpsInvalidFlag) //turn on red LED if invalid message { PORTBbits.PORTB = LATBbits.LATB | 0x20; //turn red LED on PORTBbits.PORTB = LATBbits.LATB & 0xEF; //turn green LED off __delay_ms(250); PORTBbits.PORTB = LATBbits.LATB & 0xDF; //turn red LED off if(periodicCounter < MAX_PERIOD) periodicCounter++; } else //turn on green LED if valid message { PORTBbits.PORTB = LATBbits.LATB | 0x10; //turn green LED on PORTBbits.PORTB = LATBbits.LATB & 0xDF; //turn red LED off __delay_ms(250); PORTBbits.PORTB = LATBbits.LATB & 0xEF; //turn green LED off periodicCounter = MIN_PERIOD; } if(!recordFlag) { if(PORTAbits.RA1) //check strobe GoToSleep(MIN_PERIOD); else if(gpsInvalidFlag) GoToSleep(periodicCounter); else { ToggleSleepGPS(); //Turn GPS off Hibernate(); ToggleSleepGPS(); //Turn GPS on } } } return (EXIT_SUCCESS); }