Spihsm
Spihsm
Module
TopHSMTemplate.c
Revision
2.0.1
Description
This is a template for the top level Hierarchical state machine
Notes
History
When Who What/Why
-------------- --- --------
02/20/17 14:30 jec updated to remove sample of consuming an event. We
always want to return ES_NO_EVENT at the top level
unless there is a non-recoverable error at the
framework level
02/03/16 15:27 jec updated comments to reflect small changes made in '14 & '15
converted unsigned char to bool where appropriate
spelling changes on true (was True) to match standard
removed local var used for debugger visibility in 'C32
removed Microwave specific code and replaced with generic
02/08/12 01:39 jec converted from MW_MasterMachine.c
02/06/12 22:02 jec converted to Gen 2 Events and Services Framework
02/13/10 11:54 jec converted During functions to return Event_t
so that they match the template
02/21/07 17:04 jec converted to pass Event_t to Start...()
02/20/07 21:37 jec converted to use enumerated type for events
02/21/05 15:03 jec Began Coding
****************************************************************************/
/*----------------------------- 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 "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ssi.h"
#include "inc/hw_nvic.h"
#include "inc/hw_gpio.h"
#include "inc/hw_timer.h"
#include "inc/hw_sysctl.h"
#include "termio.h"
#include "ISR.h"
#include "TopHSMTemplate.h"
#include "MotorService.h"
#include "HSMTemplate.h"
#include "MasterHSM.h"
#include "Loading.h"
#include "Unloading.h"
/*----------------------------- Module Defines ----------------------------*/
#define QueryTime 2
#define COM_Timer 1
#define ONE_SEC 1000
#define BitsPerNibble 4
#define TicksPerMS 40000
Parameters
uint8_t : the priorty of this service
Returns
boolean, False if error in initialization, True otherwise
Description
Saves away the priority, and starts
the top level state machine
Notes
Author
J. Edward Carryer, 02/06/12, 22:06
****************************************************************************/
bool InitMasterSM(uint8_t Priority)
{
ES_Event_t ThisEvent;
ThisEvent.EventType = ES_ENTRY;
// InitInputCapturePeriod();
//InitPeriodicInt();
// STEP 4: Program the GPIO to use the alternate functions on the SSI pins
HWREG(GPIO_PORTA_BASE + GPIO_O_AFSEL) |= (BIT2HI | BIT3HI | BIT4HI | BIT5HI);
// STEP 5: Set mux position in GPIOPCTL to select the SSI use of the pins
// --------> Since, we want to use Bits 2,3,4 & 5 ; we will write similar statement
as we wrote in PWM or TIMER PCTL
// From page 1351 of the Data Sheet; to map SSI to those data pins, we need an mux
value of 2
// 0xff0000ff -> clear off the bits associated with bits 2,3,4 & 5
// And then we shift the value of 2 for mux by 2,3,4 & 5 corresponding to the ports
HWREG(GPIO_PORTA_BASE + GPIO_O_PCTL) = (HWREG(GPIO_PORTA_BASE + GPIO_O_PCTL) &
0xff0000ff)
+ (2 << (2 * BitsPerNibble)) + (2 << (3 * BitsPerNibble)) +
(2 << (4 * BitsPerNibble)) + (2 << (5 * BitsPerNibble));
// STEP 7: Program the required data directions on the port lines (PA2, PA3, PA5
as outputs)
HWREG(GPIO_PORTA_BASE + GPIO_O_DIR) |= (BIT2HI | BIT3HI | BIT5HI);
// STEP 8: If using SPI mode 3, program the pull-up on the clock line PA2 (We are
going to use PA2)
HWREG(GPIO_PORTA_BASE + GPIO_O_PUR) |= BIT2HI;
// STEP 10: Make sure that the SSI is disabled before programming mode bits (Page
972)
// Could have written: HWREG(SSI0_BASE+SSI_O_CR1) &= SSI_CR1_SSE;
HWREG(SSI0_BASE + SSI_O_CR1) &= (~SSI_CR1_SSE);//HWREG(SSI0_BASE+SSI_O_CR1) &=
BIT1LO;
// STEP 11: Select master mode (MS) & TXRIS indicating End of Transmit (EOT)
HWREG(SSI0_BASE + SSI_O_CR1) &= (~SSI_CR1_MS); // HWREG(SSI0_BASE+SSI_O_CR1) |=
BIT1HI; // Selecting Slave mode| Could have written HWREG(SSIO_BASE_SSI_O_CR1) |=
~SSI_CR1_MS
HWREG(SSI0_BASE + SSI_O_CR1) |= SSI_CR1_EOT; // HWREG(SSI0_BASE+SSI_O_CR1) |=
BIT4LO; // Selecting EOT| Could have written HWREG(SSIO_BASE_SSI_O_CR1) &=
~SSI_CR1_EOT
// STEP 12: Configure the SSI clock source to the system clock (Page 984)
HWREG(SSI0_BASE + SSI_O_CC) &= (~SSI_CC_CS_M);//HWREG(SSI0_BASE+SSI_O_CC) =
SSI_CC_CS_SYSPLL;
// STEP 13: Configure the clock pre-scaler: max frequency 917 kHz
// In class we calculated that we wanted a freqeuncey < 0.9 MHz
// Let's choose 40MHz / 50 = 0.8 MHz
HWREG(SSI0_BASE + SSI_O_CPSR) = HWREG(SSI0_BASE + SSI_O_CPSR) & (0xFFFFFF00) +
50;//HWREG(SSI0_BASE+SSI_O_CPSR) = 50;
//Configure clock rate (SCR), phase & polarity (SPH, SPO), mode (FRF), data size
(DSS)
HWREG(SSI0_BASE + SSI_O_CR0) = (HWREG(SSI0_BASE + SSI_O_CR0) & (~SSI_CR0_SCR_M))
+ (199 << 8);
//Configure SPH = 1 because data is captured at the second edge
HWREG(SSI0_BASE + SSI_O_CR0) |= SSI_CR0_SPH;
//Configure SPO = 1 because idle state is high
HWREG(SSI0_BASE + SSI_O_CR0) |= SSI_CR0_SPO;
//Freescale SPI Mode
HWREG(SSI0_BASE + SSI_O_CR0) = ((HWREG(SSI0_BASE + SSI_O_CR0) & (~SSI_CR0_FRF_M))
|
SSI_CR0_FRF_MOTO);
//Sending 8 bit data between command generator & TIVA
HWREG(SSI0_BASE + SSI_O_CR0) |= SSI_CR0_DSS_8;
/* // STEP 14: Configure clock rate (SCR), phase & polarity (SPH, SPO), mode (FRF),
data size (DSS)
// Mode 3: SPO = 1 , SPH = 1
HWREG(SSI0_BASE+SSI_O_CR0) |= (SSI_CR0_SPH | SSI_CR0_SPO | SSI_CR0_DSS_8);
*/
// STEP 15: Locally enable interrupts (TXIM in SSIIM) -> Unmasked
/*******************************************************************************
********************************************/
StartMasterSM(ThisEvent);
return true;
}
/****************************************************************************
Function
PostMasterSM
Parameters
ES_Event_t 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_t ThisEvent)
{
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
Function
RunMasterSM
Parameters
ES_Event: the event to process
Returns
ES_Event: an event to return
Description
the run function for the top level state machine
Notes
uses nested switch/case to implement the machine.
Author
J. Edward Carryer, 02/06/12, 22:09
****************************************************************************/
ES_Event_t RunMasterSM(ES_Event_t CurrentEvent)
{
bool MakeTransition = false;/* are we making a state transition? */
MasterState_t NextState = CurrentState;
ES_Event_t EntryEventKind = { ES_ENTRY, 0 }; // default to normal entry to new
state
ES_Event_t ReturnEvent = { ES_NO_EVENT, 0 }; // assume no error
switch (CurrentState)
{
case WAITINGINSPI: // If current state is state one
{ // Execute During function for state one. ES_ENTRY & ES_EXIT
are
// processed here allow the lowere level state machines to
re-map
// or consume the event
CurrentEvent = DuringWaitinginSPI(CurrentEvent);
//process any events
default:
{}
break;
}
// If we are making a state transition
if (MakeTransition == true)
{
// Execute exit function for current state
CurrentEvent.EventType = ES_EXIT;
RunMasterSM(CurrentEvent);
/****************************************************************************
Function
StartMasterSM
Parameters
ES_Event CurrentEvent
Returns
nothing
Description
Does any required initialization for this state machine
Notes
Author
J. Edward Carryer, 02/06/12, 22:15
****************************************************************************/
void StartMasterSM(ES_Event_t CurrentEvent)
{
// if there is more than 1 state to the top level machine you will need
// to initialize the state variable
CurrentState = WAITINGINSPI;
// now we need to let the Run function init the lower level state machines
// use LocalEvent to keep the compiler from complaining about unused var
RunMasterSM(CurrentEvent);
return;
}
/***************************************************************************
private functions
***************************************************************************/
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
// run any lower level state machine
// ReturnEvent = RunLowerLevelSM(Event);
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if ((Event.EventType == ES_TIMEOUT) && (Event.EventParam == COM_Timer))
{
// Query the command generator
printf("\n\rRegistering");
// STEP 17: Enable Interrupt
HWREG(SSI0_BASE + SSI_O_IM) |= SSI_IM_TXIM;
// Start by sending a Query
if (Count == 0)
{
if (Teamstate == 0)
{
printf("\n\rSending 0x10");
HWREG(SSI0_BASE + SSI_O_DR) = 0x10;
}
else
{
HWREG(SSI0_BASE + SSI_O_DR) = 0x01;
printf("\n\rSending 0x01");
}
ES_Timer_InitTimer(COM_Timer, QueryTime);
Count = 1;
ReturnEvent.EventType = ES_NO_EVENT;
}
else if (Count == 1)
{
printf("\n\rSending 1st 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
ES_Timer_InitTimer(COM_Timer, QueryTime);
ReturnEvent.EventType = ES_NO_EVENT;
Count = 2;
}
else if (Count == 2)
{
printf("\n\rSending 2nd 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
Count = 0;
ReturnEvent.EventType = ES_EOT;
}
//Decide what the next state will be
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if (Event.EventType == ES_RECEIVED)
{
if (GeneratorCommand[0] == 0x00)
{
if (GeneratorCommand[1] == 0xFF)
{
GameStatus = GeneratorCommand[2] & (BIT0HI);
if (LastCommandAck != GameStatus)
{
switch (GameStatus)
{
case 0x00:
{
printf("\n\r********************NotAcknowledged*****************************");
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_ERROR;
} break;
case 0x01:
{
printf("\n\r*****************************Acknowledged***************************
**");
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_DECODED;
} break;
case 0x02:
{
printf("\n\r*****************************GameOver*****************************")
;
ReturnEvent.EventType = ES_DECODED;
} break;
default:
{
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_DECODED; //Decide what the next state
will be
} break;
}
}
else
{
ReturnEvent.EventType = ES_ERROR;
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
}
LastCommandAck = GameStatus;
}
}
else
{
printf("\n\rError");
}
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if ((Event.EventType == ES_TIMEOUT) && (Event.EventParam == COM_Timer))
{
// Query the command generator
// printf("\n\rRegistering");
// STEP 17: Enable Interrupt
HWREG(SSI0_BASE + SSI_O_IM) |= SSI_IM_TXIM;
// Start by sending a Query
if (Count == 0)
{
//printf("\n\rSending 0xD2");
HWREG(SSI0_BASE + SSI_O_DR) = 0xD2;
ES_Timer_InitTimer(COM_Timer, QueryTime);
Count = 1;
ReturnEvent.EventType = ES_NO_EVENT;
}
else if (Count == 1)
{
//printf("\n\rSending 1st 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
ES_Timer_InitTimer(COM_Timer, QueryTime);
ReturnEvent.EventType = ES_NO_EVENT;
Count = 2;
}
else if (Count == 2)
{
//printf("\n\rSending 2nd 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
Count = 0;
ReturnEvent.EventType = ES_EOT;
}
//Decide what the next state will be
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if (Event.EventType == ES_RECEIVED)
{
if (GeneratorCommand[0] == 0x00)
{
if (GeneratorCommand[1] == 0xFF)
{
Team = GeneratorCommand[2] & (BIT0HI);
switch (Team)
{
case 0x01:
{
printf("\n\r********************SouthTeam*****************************");
} break;
case 0x00:
{
printf("\n\r*****************************NorthTeam*****************************"
);
} break;
}
Colour = (GeneratorCommand[2] & (BIT0HI | BIT2HI | BIT3HI)) >> 1;
switch (Colour)
{
case 0x00:
{
printf("\n\r********************Red*****************************");
} break;
case 0x01:
{
printf("\n\r*****************************Orange*****************************");
} break;
case 0x02:
{
printf("\n\r********************Blue*****************************");
} break;
case 0x03:
{
printf("\n\r*****************************Green*****************************");
} break;
case 0x04:
{
printf("\n\r********************Yellow*****************************");
} break;
case 0x05:
{
printf("\n\r*****************************Pink*****************************");
} break;
}
printf("\n\r********************1000*****************************");
Period = 1000;
} break;
case 0x01:
{
printf("\n\r*****************************947*****************************");
Period = 947;
} break;
case 0x02:
{
printf("\n\r********************893*****************************");
Period = 893;
} break;
case 0x03:
{
printf("\n\r*****************************840*****************************");
Period = 840;
} break;
case 0x04:
{
printf("\n\r********************787*****************************");
Period = 787;
} break;
case 0x05:
{
printf("\n\r*****************************733*****************************");
Period = 733;
} break;
case 0x06:
{
printf("\n\r********************680*****************************");
Period = 680;
} break;
case 0x07:
{
printf("\n\r*****************************627*****************************");
Period = 627;
} break;
case 0x08:
{
printf("\n\r*****************************573*****************************");
Period = 573;
} break;
case 0x09:
{
printf("\n\r*****************************520*****************************");
Period = 520;
} break;
case 10:
{
printf("\n\r*****************************467*****************************");
Period = 467;
} break;
case 11:
{
printf("\n\r*****************************413*****************************");
Period = 413;
} break;
case 12:
{
printf("\n\r*****************************360*****************************");
Period = 360;
} break;
case 13:
{
printf("\n\r*****************************307*****************************");
Period = 307;
} break;
case 14:
{
printf("\n\r*****************************253*****************************");
Period = 253;
} break;
case 15:
{
printf("\n\r*****************************200*****************************");
Period = 200;
} break;
default:
printf("Error - Frequency is %d", Frequency);
}
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_DECODED;
}
}
else
{
ReturnEvent.EventType = ES_ERROR;
printf("\n\rError");
}
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if ((Event.EventType == ES_TIMEOUT) && (Event.EventParam == COM_Timer))
{
// Query the command generator
// printf("\n\rRegistering");
// STEP 17: Enable Interrupt
HWREG(SSI0_BASE + SSI_O_IM) |= SSI_IM_TXIM;
// Start by sending a Query
if (Count == 0)
{
//printf("\n\rSending 0x78");
// printf("Beacon Value is %d",QueryPeriodW3TA()*25/1000);
// printf("Current Left Value is %d",QuerySpeedLeft());
// printf("Current Right Value is %d",QuerySpeedRight());
HWREG(SSI0_BASE + SSI_O_DR) = 0x78;
ES_Timer_InitTimer(COM_Timer, QueryTime);
Count = 1;
ReturnEvent.EventType = ES_NO_EVENT;
}
else if (Count == 1)
{
//printf("\n\rSending 1st 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
ES_Timer_InitTimer(COM_Timer, QueryTime);
ReturnEvent.EventType = ES_NO_EVENT;
Count = 2;
}
else if (Count == 2)
{
//printf("\n\rSending 2nd 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
Count = 0;
ReturnEvent.EventType = ES_EOT;
}
//Decide what the next state will be
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{}
else
// do the 'during' function for this state
{
if (Event.EventType == ES_RECEIVED)
{
if (GeneratorCommand[0] == 0x00)
{
if (GeneratorCommand[1] == 0xFF)
{
EastStatus = (GeneratorCommand[2] & ((BIT2HI | BIT3HI | BIT4HI))) >> 2;
WestStatus = (GeneratorCommand[2] & ((BIT5HI | BIT6HI | BIT7HI))) >> 5;
GameStatus = GeneratorCommand[2] & (BIT0HI | BIT1HI);
//printf("\n\rEast Status is %d", QueryEast());
printf( "\n\rEast Status is %d", EastStatus);
printf( "\n\rWest Status is %d", WestStatus);
//printf("\n\rGenerator Command is %d", GeneratorCommand[2]);
printf( "\n\rColour Status is %d", Colour);
//printf("\n\rWest Status is %d", QueryWest());
//printf("\n\rTeam Status is %d", QueryTeam());
if (LastCommand != GameStatus)
{
switch (GameStatus)
{
case 0x00:
{
printf("\n\r********************Waiting4Start*****************************");
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_DECODED;
} break;
case 0x01:
{
printf("\n\r*****************************CleaningUp*****************************
");
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_DECODED;
NextEvent.EventType = ES_START;
ES_PostAll(NextEvent);
} break;
case 0x02:
{
printf("\n\r*****************************GameOver*****************************")
;
ReturnEvent.EventType = ES_DECODED;
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
NextEvent.EventType = ES_GAMEOVER;
ES_PostAll(NextEvent);
} break;
default:
{
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
ReturnEvent.EventType = ES_DECODED; //Decide what the next state
will be
} break;
}
}
else
{
ReturnEvent.EventType = ES_DECODED;
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
}
LastCommand = GameStatus;
}
}
else
{
ReturnEvent.EventType = ES_ERROR;
}
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if ((Event.EventType == ES_TIMEOUT) && (Event.EventParam == COM_Timer))
{
// Query the command generator
// printf("\n\rRegistering");
// STEP 17: Enable Interrupt
HWREG(SSI0_BASE + SSI_O_IM) |= SSI_IM_TXIM;
// Start by sending a Query
if (Count == 0)
{
//printf("\n\rSending 0x10");
HWREG(SSI0_BASE + SSI_O_DR) = 0xB4;
ES_Timer_InitTimer(COM_Timer, QueryTime);
Count = 1;
ReturnEvent.EventType = ES_NO_EVENT;
}
else if (Count == 1)
{
//printf("\n\rSending 1st 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
ES_Timer_InitTimer(COM_Timer, QueryTime);
ReturnEvent.EventType = ES_NO_EVENT;
Count = 2;
}
else if (Count == 2)
{
//printf("\n\rSending 2nd 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
Count = 0;
ReturnEvent.EventType = ES_EOT;
}
//Decide what the next state will be
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
// run any lower level state machine
// ReturnEvent = RunLowerLevelSM(Event);
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
if ((Event.EventType == ES_TIMEOUT) && (Event.EventParam == COM_Timer))
{
// Query the command generator
// printf("\n\rRegistering");
// STEP 17: Enable Interrupt
HWREG(SSI0_BASE + SSI_O_IM) |= SSI_IM_TXIM;
// Start by sending a Query
if (Count == 0)
{
//printf("\n\rSending 0x10");
HWREG(SSI0_BASE + SSI_O_DR) = 0x69;
ES_Timer_InitTimer(COM_Timer, QueryTime);
Count = 1;
ReturnEvent.EventType = ES_NO_EVENT;
}
else if (Count == 1)
{
//printf("\n\rSending 1st 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
ES_Timer_InitTimer(COM_Timer, QueryTime);
ReturnEvent.EventType = ES_NO_EVENT;
Count = 2;
}
else if (Count == 2)
{
//printf("\n\rSending 2nd 0");
HWREG(SSI0_BASE + SSI_O_DR) = 0x00;
Count = 0;
ReturnEvent.EventType = ES_EOT;
}
//Decide what the next state will be
}
}
// return either Event, if you don't want to allow the lower level machine
// to remap the current event, or ReturnEvent if you do want to allow it.
return ReturnEvent;
}
// after that start any lower level machines that run in this state
//StartLowerLevelSM( Event );
// repeat the StartxxxSM() functions for concurrent state machines
// on the lower level
}
else if (Event.EventType == ES_EXIT)
{
// on exit, give the lower levels a chance to clean up first
//RunLowerLevelSM(Event);
// repeat for any concurrently running state machines
// now do any local exit functionality
}
else
// do the 'during' function for this state
{
// run any lower level state machine
// ReturnEvent = RunLowerLevelSM(Event);
void CommandGeneratorResponse(void)
{
ES_Event_t ReturnEvent;
//printf("\n\rReceived");
//Disable the Interrupt
HWREG(SSI0_BASE + SSI_O_IM) &= (~SSI_IM_TXIM);
ReturnEvent.EventType = ES_RECEIVED;
GeneratorCommand[0] = HWREG(SSI0_BASE + SSI_O_DR);
GeneratorCommand[1] = HWREG(SSI0_BASE + SSI_O_DR);
GeneratorCommand[2] = HWREG(SSI0_BASE + SSI_O_DR);
GeneratorCommand[3] = HWREG(SSI0_BASE + SSI_O_DR);
GeneratorCommand[4] = HWREG(SSI0_BASE + SSI_O_DR);
printf( "\n\rGenerator Command [0]Value is %d", GeneratorCommand[0]);
printf( "\n\rGenerator Command [1]Value is %d", GeneratorCommand[1]);
printf( "\n\rGenerator Command [2]Value is %d", GeneratorCommand[2] & (BIT0HI |
BIT1HI));
//printf( "\n\rGenerator Command [3]Value is %d", GeneratorCommand[3] & (BIT0HI
| BIT1HI));
//printf( "\n\rGenerator Command [4]Value is %d", GeneratorCommand[4] & (BIT0HI
| BIT1HI));
PostMasterSM(ReturnEvent);
}
uint16_t Receive(void)
{
uint16_t data = HWREG(SSI0_BASE + SSI_O_DR);
return data;
}
bool QueryEast()
{
if (Colour == EastStatus)
{
return true;
}
else
{
return false;
}
}
bool QueryWest()
{
if (Colour == WestStatus)
{
return true;
}
else
{
return false;
}
}
uint8_t QueryColour()
{
return Colour;
}
uint32_t QueryFrequency()
{
return 600;
}
uint8_t QueryTeam()
{
return Team;
}