bool InitDisarmFSM ( uint8_t Priority ) { ES_Event ThisEvent; PortFunctionInit(); //initialize pins PA2-5, PB2-3, PD7, PF0 as GPIO initTapeSensors(); //initialize tape sensor initPhototransistor(); //initialize phototransisor initMotors(); //initialize motors initializeServos(); //initialize servo motors LEDShiftRegInit(); //initialize LED shift register LCDInit(); //initialize LCD display InitAdafruitAudioPortLines(); //initialize audio initArmedLine(); MyPriority = Priority; CurrentState = Armed; ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else // if initialization failed { return false; } }
bool InitGameplay(uint8_t Priority) { MyPriority = Priority; // initialize servo ServoInit(); SetFlagsInactive(); // initialize audio AudioControlInit(); ExternalLineInit(); // set currentState to INIT currentState = INIT; ES_Event ThisEvent; ThisEvent.EventType = ES_INIT; // post ES_INIT to itself if (ES_PostToService(MyPriority, ThisEvent) == true) { return true; } else { return false; } }
/**************************************************************************** Function InitCannonControlService Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise ****************************************************************************/ bool InitCannonControlService ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; GPIO_Init(CANNONANGLE_SYSCTL, CANNONANGLE_BASE, CANNON_DIRECTION_PIN, OUTPUT); GPIO_Clear(CANNONANGLE_BASE, CANNON_DIRECTION_PIN); //Initialize Our Input Captures for Encoder InitInputCapture(CANNON_ENCODER_INTERRUPT_PARAMATERS); //Initialize Periodic Interrupt for Control Laws InitPeriodic(CANNON_CONTROL_INTERRUPT_PARAMATERS); //Start the Cannon at Rest setTargetCannonSpeed(0); //Set Hopper to proper position SetPWM_Hopper(HOPPER_DEFAULT_DUTY); // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
/**************************************************************************** Function InitEncoderService Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, initializes TIVA pins, sets up init capture, starts RPM timer ****************************************************************************/ bool InitEncoderService ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; // Setup init capture InitInputCapturePeriod( ); // Setup periodic timer InitPeriodicInt( ); // Start RPM timer ES_Timer_InitTimer(RPMtimer, RPMtime); // Post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
/**************************************************************************** Function InitTemplateFSM Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, sets up the initial transition and does any other required initialization for this state machine Notes Author J. Edward Carryer, 10/23/11, 18:55 ****************************************************************************/ bool InitPlayerTransmitSM ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; // put us into the Initial PseudoState CurrentState = Sleep; CurrentSubState = Send_Delim; // post the initial transition event ThisEvent.EventType = ES_INIT; InitTxSCI(); //InitTxSPI(); InitTxPorts(); InitTxTimers(); //ES_Timer_InitTimer(1, 195); transmitFlag = 0; responseCounter = 0; addr = 0; commActive = 0; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
bool InitLidarService( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; Init_LidarCapture(); _HW_Timer_Init(ES_Timer_RATE_1mS); //ES_Timer_InitTimer(AD_TIMER, 100); ThisEvent.EventType = ES_INIT; CurrentLidarState = InitLidar; HWREG(SYSCTL_RCGCGPIO) |= SYSCTL_RCGCGPIO_R4; HWREG(GPIO_PORTE_BASE+GPIO_O_DEN) |= BIT2HI; // Set PE2 as output pin HWREG(GPIO_PORTE_BASE+GPIO_O_DIR) |= BIT2HI; // Write 1 to PE2, this will not trigger the measurement HWREG(GPIO_PORTE_BASE+(GPIO_O_DATA + ALL_BITS)) |= BIT2HI; // PE1 to power up the Lidar 3.3V HWREG(GPIO_PORTE_BASE+GPIO_O_DEN) |= BIT1HI; HWREG(GPIO_PORTE_BASE+GPIO_O_DIR) |= BIT1HI; HWREG(GPIO_PORTE_BASE+(GPIO_O_DATA + ALL_BITS)) |= BIT1HI; TriggerLow = false; Period = 0; printf("Initialization done\n\r"); if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
/**************************************************************************** Function InitDCMotor Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, sets all the necessary bits for input capture output compare, PWM setup and enabling interrupts. Author J. Edward Carryer, 01/16/12, 10:00 ****************************************************************************/ bool InitDCMotor ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; /* Turn on Port U for PWM outputs */ MOTOR_PORT_ADDRESS |= (MOTOR_1_DIR | MOTOR_2_DIR | MOTOR_1_PWM | MOTOR_2_PWM); /* Initialize Registers for PWM Capability */ PWME |= _S12_PWME0 | _S12_PWME1; //Enable PWM 0,1 PWMPOL |= (_S12_PPOL0 | _S12_PPOL1); //Set Output Polarity LO PWMCLK |= (_S12_PCLK0 | _S12_PCLK1); //Enable Clock A Scaling PWMPRCLK &= ~(_S12_PCKA2|_S12_PCKA1|_S12_PCKA0);//Set A Clock prescale /1 PWMSCLA = 4; //Clock Scaler PWMCAE &= ~_S12_CAE0; //Set to Left Align PWMCAE |= _S12_CAE1; //Set to Center Align MODRR |= _S12_MODRR0 | _S12_MODRR1; //Port U Mapping - Pin(s) 0,1 to PWM /* Set Period/Initial Duty Cycle/Initial Dir */ PWMPER0 = 100; //Set PWM freq to 30 kHz PWMPER1 = 50; PWMDTY0 = 0; PWMDTY1 = 0; MOTOR_PORT &= ~MOTOR_1_DIR & ~MOTOR_2_DIR; ES_InitDeferralQueueWith( DeferralQueue, ARRAY_SIZE(DeferralQueue) ); ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) return true; else return false; }
//PostCamera bool PostCamera(ES_Event thisEvent) { //Takes an Event, returns a bool. //Post the event to the Camera queue using ES_PostToService. //Return the value outputted by ES_PostToService. return ES_PostToService(MyPriority, thisEvent); //End of PostCamera }
/**************************************************************************** Function InitGridlinq Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Initializes the UART and Pins necessary for communication ****************************************************************************/ bool InitGridlinq ( uint8_t Priority ) { MyPriority = Priority; CurrentState = Detached; InitUART(); // post the initial transition event ES_Event ThisEvent = {ES_INIT,0}; return ES_PostToService(MyPriority, ThisEvent); }
/** * @Function InitRoachFSM(uint8_t Priority) * @param Priority - internal variable to track which event queue to use * @return TRUE or FALSE * @brief This will get called by the framework at the beginning of the code * execution. It will post an ES_INIT event to the appropriate event * queue, which will be handled inside RunRoachFSM function. * Returns TRUE if successful, FALSE otherwise * @author Gabriel H Elkaim, 2013.09.26 15:33 */ uint8_t InitMotorYFSM(uint8_t Priority) { //printf("InitMotorYFSM\n"); MyPriority = Priority; // put us into the Initial PseudoState CurrentState = InitQState; // post the initial transition event if (ES_PostToService(MyPriority, INIT_EVENT) == TRUE) { return TRUE; } else { return FALSE; } }
/** * @Function InitExitHSM(uint8_t Priority) * @param Priority - internal variable to track which event queue to use * @return TRUE or FALSE * @brief This will get called by the framework at the beginning of the code * execution. It will post an ES_INIT event to the appropriate event * queue, which will be handled inside RunExitFSM function. Remember * to rename this to something appropriate. * Returns TRUE if successful, FALSE otherwise * @author J. Edward Carryer, 2011.10.23 19:25 */ uint8_t InitExitHSM(uint8_t Priority) { MyPriority = Priority; // put us into the Initial PseudoState CurrentState = Exit_Init; // post the initial transition event if (ES_PostToService(MyPriority, INIT_EVENT) == TRUE) { return TRUE; } else { return FALSE; } }
/** * @Function InitKeyboardInput(uint8_t Priority) * @param Priority - internal variable to track which event queue to use * @return TRUE or FALSE * @brief this initializes the keyboard input system which * Returns TRUE if successful, FALSE otherwise * @author Max Dunne , 2013.09.26 */ uint8_t InitKeyboardInput(uint8_t Priority) { ES_Event ThisEvent; MyPriority = Priority; // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService(MyPriority, ThisEvent) == TRUE) { return TRUE; } else { return FALSE; } }
//------------------------------------------------------------------------------ // ES FUNCTIONS //------------------------------------------------------------------------------ uint8_t InitBeaconService(uint8_t Priority) { ES_Event ThisEvent; MyPriority = Priority; //Initialize relevant hardware IO_PortsSetPortInputs(BEACON_PORT, BEACON_PIN); // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService(MyPriority, ThisEvent) == TRUE) { return TRUE; } else { return FALSE; } }
boolean InitLabFSM ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; // put us into the Initial PseudoState CurrentState = InitPState; // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == True) { return True; }else { return False; } }
/**************************************************************************** Function InitAdafruitAudioService Parameters uint8_t : the priority of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, and does any other required initialization for this service Notes ****************************************************************************/ bool InitAdafruitAudioService ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; InitAdafruitAudioPortLines(); // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
/**************************************************************************** Function InitTemplateService Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, and does any other required initialization for this service Notes Author J. Edward Carryer, 01/16/12, 10:00 ****************************************************************************/ bool InitTemplateService ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; /******************************************** in here you write your initialization code *******************************************/ // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
/** * @Function InitTemplateService(uint8_t Priority) * @param Priority - internal variable to track which event queue to use * @return TRUE or FALSE * @brief This will get called by the framework at the beginning of the code * execution. It will post an ES_INIT event to the appropriate event * queue, which will be handled inside RunTemplateService function. Remember * to rename this to something appropriate. * Returns TRUE if successful, FALSE otherwise * @author J. Edward Carryer, 2011.10.23 19:25 */ uint8_t InitTestBumpService(uint8_t Priority) { ES_Event ThisEvent; MyPriority = Priority; // in here you write your initialization code // this includes all hardware and software initialization // that needs to occur. // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService(MyPriority, ThisEvent) == TRUE) { return TRUE; } else { return FALSE; } }
/**************************************************************************** Function InitIRemitter Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, and does any other required initialization for this service Notes Author J. Edward Carryer, 01/16/12, 10:00 ****************************************************************************/ bool InitIRemitter ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; //Init pins as digital outputs and OFF IRemitter_ADDRESS |= IRemitter_PIN; IRemitter_PORT &= ~IRemitter_PIN; ReloadLED_ADDRESS |= ReloadLED_PIN; ReloadLED_PORT &= ~ReloadLED_PIN; // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) return true; else return false; }
/**************************************************************************** Function InitPhotoTransistorService Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise ****************************************************************************/ bool InitPhotoTransistorService ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; InitInputCapture(PHOTOTRANSISTOR_INTERRUPT_PARAMATERS); disableCaptureInterrupt(PHOTOTRANSISTOR_INTERRUPT_PARAMATERS); // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) { return true; }else { return false; } }
/** * @Function InitTestTapeServiceService(uint8_t Priority) * @param Priority - internal variable to track which event queue to use * @return TRUE or FALSE * @brief This will get called by the framework at the beginning of the code * execution. It will post an ES_INIT event to the appropriate event * queue, which will be handled inside RunTestTapeServiceService function. Remember * to rename this to something appropriate. * Returns TRUE if successful, FALSE otherwise * @author J. Edward Carryer, 2011.10.23 19:25 */ uint8_t InitTestTapeService(uint8_t Priority) { ES_Event ThisEvent; MyPriority = Priority; // in here you write your initialization code // this includes all hardware and software initialization // that needs to occur. Dagobot_SetLED(1); //setting LEDS for digital for (ind = 0; ind < 100; ind++) currentTapeState[ind] = 0x00; // post the initial transition event ThisEvent.EventType = ES_INIT; if (ES_PostToService(MyPriority, ThisEvent) == TRUE) { return TRUE; } else { return FALSE; } }
/**************************************************************************** Function InitJSRcommand Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, and does any other required initialization for this service Notes Author J. Edward Carryer, 01/16/12, 10:00 ****************************************************************************/ bool InitJSRcommand ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; // post the initial transition event DDRS |= BIT7HI; // To control SS line manually RED_DARK_ADDRESS &= ~RED_DARK_PIN; // Set pin as input RED_DARK_PORT &= ~RED_DARK_PIN; //Set button low InitSPI(); readFrom = 4;// Looking for the 4th command from JSR InitVariables(); QueryCommand = STATUS_QUERY; ES_Timer_InitTimer(JSRtimer, 3); // Start JSRtimer for 2ms. ThisEvent.EventType = ES_INIT; if (ES_PostToService( MyPriority, ThisEvent) == true) return true; else return false; }
/**************************************************************************** Function PostMasterSM Parameters ES_Event ThisEvent , the event to post to the queue Returns boolean False if the post operation failed, True otherwise Description Posts an event to this state machine's queue Notes Author J. Edward Carryer, 10/23/11, 19:25 ****************************************************************************/ bool PostMasterSM( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }
/** * @Function PostRoachFSM(ES_Event ThisEvent) * @param ThisEvent - the event (type and param) to be posted to queue * @return TRUE or FALSE * @brief This function is a wrapper to the queue posting function, and its name * will be used inside ES_Configure to point to which queue events should * be posted to. Returns TRUE if successful, FALSE otherwise * @author Gabriel H Elkaim, 2013.09.26 15:33 */ uint8_t PostMotorYFSM(ES_Event ThisEvent) { return ES_PostToService(MyPriority, ThisEvent); }
/**************************************************************************** Function PostAdafruitAudioService Parameters EF_Event ThisEvent ,the event to post to the queue Returns bool false if the Enqueue operation failed, true otherwise Description Posts an event to this state machine's queue Notes ****************************************************************************/ bool PostAdafruitAudioService( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }
/**************************************************************************** Function PostJSRcommand Parameters EF_Event ThisEvent ,the event to post to the queue Returns bool false if the Enqueue operation failed, true otherwise Description Posts an event to this state machine's queue Notes Author J. Edward Carryer, 10/23/11, 19:25 ****************************************************************************/ bool PostJSRcommand( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }
/**************************************************************************** Function PostPhotoTransistorService Parameters EF_Event ThisEvent ,the event to post to the queue Returns bool false if the Enqueue operation failed, true otherwise ****************************************************************************/ bool PostPhotoTransistorService( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }
/** * @Function PostKeyboardInput(ES_Event ThisEvent) * @param ThisEvent - the event (type and param) to be posted to queue * @return TRUE or FALSE * @brief Used to post events to keyboard input * Returns TRUE if successful, FALSE otherwise * @author Max Dunne , 2013.09.26 */ uint8_t PostKeyboardInput(ES_Event ThisEvent) { return ES_PostToService(MyPriority, ThisEvent); }
bool PostLidarService( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }
/**************************************************************************** Function PostStatusPAC Parameters ES_Event ThisEvent , the event to post to the queue Returns boolean False if the post operation failed, True otherwise Description Posts an event to this state machine's queue Notes Author J. Edward Carryer, 10/23/11, 19:25 ****************************************************************************/ bool PostStatusPAC( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }
/**************************************************************************** Function PostMasterSM Parameters ES_Event ThisEvent , the event to post to the queue Returns boolean False if the post operation failed, True otherwise Description Posts an event to this state machine's queue Notes Author J. Edward Carryer, 10/23/11, 19:25 ****************************************************************************/ boolean PostTankSM( ES_Event ThisEvent ) { return ES_PostToService( MyPriority, ThisEvent); }