Professional Documents
Culture Documents
Module
TeraMotorService.c
Revision
1.0.1
Description
This is the service to control the movement of terraforming motor
Notes
History
When Who
--------------------
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_Port.h"
#include "ES_Events.h"
#include "ES_Timers.h"
#include "termio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h" // Define PART_TM4C123GH6PM in project
#include "driverlib/gpio.h"
#include "PWM16Tiva.h"
#include "TeraMotorService.h"
#include "Knob.h"
#include "Motor.h"
#include <math.h>
/*----------------------------- Module Defines ----------------------------*/
/* prototypes for private functions for this service.They should be functions
relevant to the behavior of this service
*/
#define ONE_SEC 976
#define TWENTY_SEC (20*ONE_SEC)
#define THIRTY_SEC (30*ONE_SEC)
#define FIFTEEN_SEC (15*ONE_SEC)
#define KNOB_THRES 0.03
/*---------------------------- Module Variables ---------------------------*/
// with the introduction of Gen2, we need a module level Priority variable
static uint8_t MyPriority;
static float LastKnobValue;
static float CurrentKnobValue;
static TeraMotorState_t CurrentState = TeraInitPState;
/****************************************************************************
Function
PostTeraMotor
Parameters
ES_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
****************************************************************************/
bool PostTeraMotor(ES_Event ThisEvent ){
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
Function
Check4Knob
Parameters
ES_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
****************************************************************************/
bool Check4Knob(void){
//assume no event
bool ReturnVal = false;
//get current knob state
CurrentKnobValue = GetKnobValue();
//if there is an event
if(fabs(CurrentKnobValue - LastKnobValue) > KNOB_THRES){
ES_Event ThisEvent;
ThisEvent.EventType = ES_KNOB_TURNED;
//post the event to TeraMotorService, LEDService and PopUpMotorService
ES_PostList01(ThisEvent);
//set ReturnVal to true
ReturnVal = true;
//set LastKnobState to CurrentKnobState
LastKnobValue = CurrentKnobValue;
}
//return ReturnVal
return ReturnVal;
}
/****************************************************************************
Function
RunTeraMotor
Parameters
ES_Event : the event to process
Returns
ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise
Description
add your description here
****************************************************************************/
ES_Event RunTeraMotor( ES_Event ThisEvent ){
ES_Event ReturnEvent;
//assume no errors
ReturnEvent.EventType = ES_NO_EVENT;
//set NextState to CurrentState
TeraMotorState_t NextState = CurrentState;