0% found this document useful (0 votes)
99 views

Spihsm

Uploaded by

api-438120791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Spihsm

Uploaded by

api-438120791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

/****************************************************************************

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

/*---------------------------- Module Functions ---------------------------*/


static ES_Event_t DuringStateOne(ES_Event_t Event);
static ES_Event_t DuringWaitinginSPI(ES_Event_t Event);
static ES_Event_t DuringReg(ES_Event_t Event);
static ES_Event_t DuringAck(ES_Event_t Event);
static ES_Event_t DuringGti(ES_Event_t Event);
static ES_Event_t DuringTI(ES_Event_t Event);
static ES_Event_t DuringGgs(ES_Event_t Event);
static ES_Event_t DuringGS(ES_Event_t Event);
static ES_Event_t DuringGetScore(ES_Event_t Event);
static ES_Event_t DuringScore(ES_Event_t Event);
static ES_Event_t DuringGR(ES_Event_t Event);
static ES_Event_t DuringRecycle(ES_Event_t Event);
/*---------------------------- Module Variables ---------------------------*/
// everybody needs a state variable, though if the top level state machine
// is just a single state container for orthogonal regions, you could get
// away without it
static MasterState_t CurrentState;
// with the introduction of Gen2, we need a module level Priority var as well
static uint8_t MyPriority;

static uint16_t GeneratorCommand[5];


static uint16_t LastCommand = 0xFF;
static uint16_t LastCommandAck = 0xFF;

static uint8_t GameStatus;


static uint8_t EastStatus;
static uint8_t WestStatus;
static uint8_t Colour;
static uint32_t Frequency;
static uint32_t Period;
static uint8_t Team;
static uint8_t Count = 0;
static uint8_t Teamstate;

/*------------------------------ Module Code ------------------------------*/


/****************************************************************************
Function
InitMasterSM

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;

MyPriority = Priority; // save our priority

ThisEvent.EventType = ES_ENTRY;

// InitInputCapturePeriod();
//InitPeriodicInt();

// Start the Master State machine


/*******************************************************************************
************************************/
/********************************************
in here you write your initialization code
*******************************************/
// INITIALIZATION SEQUENCE - For reference; refer to Last Page of Pre-Lecture Notes
& Section 15 of TIVA DataSheet
// STEP 1: Enable the clock to the GPIO port
HWREG(SYSCTL_RCGCGPIO) |= BIT0HI;

// STEP 2: Enable the clock to SSI module


HWREG(SYSCTL_RCGCSSI) |= BIT0HI;

// STEP 3: Wait for the GPIO port to be ready


while ((HWREG(SYSCTL_PRGPIO) & SYSCTL_PRGPIO_R0) != SYSCTL_PRGPIO_R0)
{}

// List of Alternate functions


// PA2 - SSI0Clock (Clock) | PA3 - SSI0Fss (Frame Select/ Slave Select Line)| PA4
- SSI0Rx (Receive) | PA5 - SSI0Tx (Transmit) (Page 965 TIVA Datasheet)

// 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 6: Program the port lines for digital I/O


HWREG(GPIO_PORTA_BASE + GPIO_O_DEN) |= (BIT2HI | BIT3HI | BIT4HI | BIT5HI);

// 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);

// Program PA4 as input for receiving


HWREG(GPIO_PORTA_BASE + GPIO_O_DIR) &= BIT4LO;

// 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 9: Wait for the SSI0 to be ready (Similar to PWM Routine


while ((HWREG(SYSCTL_PRSSI) & SYSCTL_PRSSI_R0) != SYSCTL_PRSSI_R0)
{}

// 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

HWREG(SSI0_BASE + SSI_O_IM) |= SSI_IM_TXIM;


// STEP 16: Make sure that the SSI is enabled for operation
// Could have also written HWREG(SSI0_BASE+SSI_O_CR1) |= BIT1HI

HWREG(SSI0_BASE + SSI_O_CR1) |= SSI_CR1_SSE;


/*
// STEP 17: Enable the NVIC interrupt for the SSI when starting to transmit
// Page no: 104 Row # 23
HWREG(NVIC_EN0) |= BIT7HI;

// Start by sending a Query


HWREG(SSI0_BASE + SSI_O_DR) = Test;*/
//Start timer to query the command generator after an initial delay
//Initialize the CurrentState variable to waiting
//Enable NVIC for Interrupt
HWREG(NVIC_EN0) |= BIT7HI;
HWREG(NVIC_PRI2) |= (BIT5HI | BIT7HI);
Teamstate = HWREG(GPIO_PORTD_BASE + (GPIO_O_DATA + ALL_BITS)) & BIT7HI;
//Global Init Interrupt
__enable_irq();
//printf("Interrupts enabled");
ES_Timer_InitTimer(COM_Timer, ONE_SEC);

/*******************************************************************************
********************************************/

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

if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active


{
switch (CurrentEvent.EventType)
{
case ES_TIMEOUT: //If event is event one
{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to Registering");
ES_Timer_InitTimer(COM_Timer, ONE_SEC);
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;
// repeat state pattern as required for other states

case REGISTERING: // 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 = DuringReg(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_EOT: //If event is event one
{ // Execute action function for state one :
event one
NextState = ACKNOWLEDGING; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to Acknowledging");
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;

case ES_ERROR: //If event is event one


{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to Reg");
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case ACKNOWLEDGING: // 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 = DuringAck(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_DECODED: //If event is event one
{ // Execute action function for state one :
event one
NextState = GETTEAMINFO; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to GettingTI");
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;

case ES_ERROR: //If event is event one


{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// printf("\n\rSwitching to Reg1");
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case GETTEAMINFO: // 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 = DuringGti(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_EOT: //If event is event one
{ // Execute action function for state one : event
one
NextState = TEAMINFO; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to TI");
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case TEAMINFO:// 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 = DuringTI(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_DECODED: //If event is event one
{ // Execute action function for state one :
event one
NextState = GETGAMESTATUS; //Decide what the next state will be
// printf("\n\rSwitching to GetGS");
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;

case ES_ERROR: //If event is event one


{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to Reg");
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case GETGAMESTATUS: // 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 = DuringGgs(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_EOT: //If event is event one
{ // Execute action function for state one : event
one
NextState = GAMESTATUS; //Decide what the next state will be
// printf("\n\rSwitching to GameStatus");
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case GAMESTATUS: // 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 = DuringGS(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_DECODED: //If event is event one
{ // Execute action function for state one :
event one
NextState = GETGAMESTATUS; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
// printf("\n\rSwitching to GetGameStatus1");
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;

case ES_ERROR: //If event is event one


{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// printf("\n\rSwitching to Reg");
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

/* case GETSCORE: // 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 = DuringGetScore(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_EOT: //If event is event one
{ // Execute action function for state one : event
one
NextState = SCORE; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case SCORE: // 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 = DuringScore(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_DECODED: //If event is event one
{ // Execute action function for state one
: event one
NextState = GETGAMESTATUS; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;

case ES_ERROR: //If event is event one


{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case GETRECYCLE: // 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 = DuringGR(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_EOT: //If event is event one
{ // Execute action function for state one : event
one
NextState = RECYCLE; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;

case RECYCLE: // 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 = DuringRecycle(CurrentEvent);
//process any events
if (CurrentEvent.EventType != ES_NO_EVENT) //If an event is active
{
switch (CurrentEvent.EventType)
{
case ES_DECODED: //If event is event one
{ // Execute action function for state one
: event one
NextState = GETGAMESTATUS; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;

case ES_ERROR: //If event is event one


{ // Execute action function for state one :
event one
NextState = REGISTERING; //Decide what the next state will be
// for internal transitions, skip changing MakeTransition
MakeTransition = true; //mark that we are taking a transition
// if transitioning to a state with history change kind of entry
EntryEventKind.EventType = ES_ENTRY_HISTORY;
}
break;
// repeat cases as required for relevant events
}
}
}
break;*/

default:
{}
break;
}
// If we are making a state transition
if (MakeTransition == true)
{
// Execute exit function for current state
CurrentEvent.EventType = ES_EXIT;
RunMasterSM(CurrentEvent);

CurrentState = NextState; //Modify state variable


// Execute entry function for new state
// this defaults to ES_ENTRY
RunMasterSM(EntryEventKind);
}
// in the absence of an error the top level state machine should
// always return ES_NO_EVENT, which we initialized at the top of func
return ReturnEvent;
}

/****************************************************************************
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
***************************************************************************/

static ES_Event_t DuringWaitinginSPI(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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);

// repeat for any concurrent lower level machines

// do any activity that is repeated as long as we are in this state


}
// 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;
}

static ES_Event_t DuringReg(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

static ES_Event_t DuringAck(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption
ES_Event_t NextEvent; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

static ES_Event_t DuringGti(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

static ES_Event_t DuringTI(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption
ES_Event_t NextEvent;

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

Frequency = (GeneratorCommand[2] & (BIT4HI | BIT5HI | BIT6HI | BIT7HI))


>> 4;
switch (Frequency)
{
case 0x00:
{

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;
}

static ES_Event_t DuringGgs(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

static ES_Event_t DuringGS(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption
ES_Event_t NextEvent;

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

/*static ES_Event_t DuringGetScore(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

static ES_Event_t DuringScore(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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);

// repeat for any concurrent lower level machines

// do any activity that is repeated as long as we are in this state


}
// 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;
}

static ES_Event_t DuringGR(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption
// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events
if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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;
}

static ES_Event_t DuringRecycle(ES_Event_t Event)


{
ES_Event_t ReturnEvent = Event; // assme no re-mapping or comsumption

// process ES_ENTRY, ES_ENTRY_HISTORY & ES_EXIT events


if ((Event.EventType == ES_ENTRY) ||
(Event.EventType == ES_ENTRY_HISTORY))
{
// implement any entry actions required for this state machine

// 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);

// repeat for any concurrent lower level machines

// do any activity that is repeated as long as we are in this state


}
// 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;
}*/

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;
}

You might also like