0% found this document useful (0 votes)
46 views12 pages

Gamesm

This document contains the code for a game state machine. It defines various states like Uninitialized, SelectingPipe, and WaterFlowing. It also defines constants like timer intervals. The InitGameSM function initializes hardware pins and the state machine. RunGameSM is the state machine function that processes events and transitions between states like starting timers when transitioning from Uninitialized to SelectingPipe state.

Uploaded by

api-438010548
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)
46 views12 pages

Gamesm

This document contains the code for a game state machine. It defines various states like Uninitialized, SelectingPipe, and WaterFlowing. It also defines constants like timer intervals. The InitGameSM function initializes hardware pins and the state machine. RunGameSM is the state machine function that processes events and transitions between states like starting timers when transitioning from Uninitialized to SelectingPipe state.

Uploaded by

api-438010548
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/ 12

/*

GAME_STATE_MACHINE

This state machine incorporates part of the game except the scoring

First Version: Nov 15, Thursday

Data private to the module:


MyPriority

States:
PseudoState_Game
Uninitialized
SelectingPipe
WaterFlowing
IRRead
WaitforReset

Intaking Events:

Hardware events:
IR_N0_CONNECTION
IR_CONNECTION

Other Service Events:


START_GAME

Internal Events:
ACTIVATE_RANDOM_PIPE

TIMEOUT_EVENTS
PIPE_TIMER_TIMEOUT
SCORE_TIMER_TIMEOUT

Posting Events:

*/

/*----------------------------- Include Files -----------------------------*/


// Basic includes for a program using the Events and Services Framework
#include "GameSM.h"
#include "ControlSM.h"
#include "ScoringSM.h"
#include "SoundSM.h"

/*

****************************************

REMOVE

*/
#include "SR_HillAndMotor.h"

// Hardware
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"

// Event & Services Framework


#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_DeferRecall.h"
#include "ES_ShortTimer.h"

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

/*----------------------------- Module Defines ----------------------------*/


// define constants for the states for this machine
// and any other local defines
//#define PIPE_TIMER 1

//#define SCORE_TIME uint16_t 100000

#define MAX_DIFFICULTY 100


#define GET_MSB_IN_LSB(x) ((x & 0x80) >> 7)

#define ONE_SEC 976


#define HALF_SEC (ONE_SEC / 2)
#define THIRTY_SEC (ONE_SEC * 30)
#define TENTH_SEC (ONE_SEC / 10)
#define FIFTEENTH_SEC (ONE_SEC / 15)
#define TWENTIETH_SEC (ONE_SEC / 20)

//Define for Decoder output


#define DECODE_A0_PORT_HI BIT4HI
#define DECODE_A0_PORT_LO BIT4LO
#define DECODE_A1_PORT_HI BIT5HI
#define DECODE_A1_PORT_LO BIT5LO
#define DECODE_A2_PORT_HI BIT6HI
#define DECODE_A2_PORT_LO BIT6LO
#define DECODE_E3_PORT_HI BIT7HI
#define DECODE_E3_PORT_LO BIT7LO

//Define for IR Inputs Port E bits 1 - 5


#define IR_PIPE1HI BIT1HI
#define IR_PIPE1LO BIT1LO
#define IR_PIPE2HI BIT2HI
#define IR_PIPE2LO BIT2LO
#define IR_PIPE3HI BIT3HI
#define IR_PIPE3LO BIT3LO
#define IR_PIPE4HI BIT4HI
#define IR_PIPE4LO BIT4LO
#define IR_PIPE5HI BIT5HI
#define IR_PIPE5LO BIT5LO

//Define for SR Pipe Control


#define SR_PIPE_SD_HI BIT0HI
#define SR_PIPE_SD_LO BIT0LO
#define SR_PIPE_SCLK_HI BIT1HI
#define SR_PIPE_SCLK_LO BIT1LO
#define SR_PIPE_RCLK_HI BIT2HI
#define SR_PIPE_RCLK_LO BIT2LO

//Define for Port C and E use


//#define LEAF_SYSCTL_PRGPIO SYSCTL_PRGPIO_R3
#define PIPES_GPIO_BASE GPIO_PORTC_BASE //Decoder
#define PIPES_IR_GPIO_BASE GPIO_PORTE_BASE //IR Input
#define PIPES_SR_GPIO_BASE GPIO_PORTB_BASE //Pipe SR

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


/* prototypes for private functions for this machine, things like during
functions, entry & exit functions.They should be functions relevant to the
behavior of this state machine
*/
static bool CheckIRConnection(void);
//static void ActivatePipeLED(uint8_t PipeNumber);
static void SRPipe_Init(void);
//static void SRPipe_Write(uint8_t NewValue);
//PipeWrite and ActivatePipeLED will be used by the VisualBlastSM

/*---------------------------- Module Variables ---------------------------*/


// everybody needs a state variable, you may need others as well
static uint8_t MyPriority;
static GameSM_States_t CurrentState;
static int PipeTimeMultiplier;
static int pipeTime; //stores the pipe timer
count based on the difficulty level
static int WaterFlowTime = TWENTIETH_SEC; // timer for water flow
static int random_pipe_index;
static uint16_t SCORE_TIME = (uint16_t)50000;

/****************************************************************************
Function
InitGameSM

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
****************************************************************************/
bool InitGameSM(uint8_t Priority)
{
MyPriority = Priority;
printf("Initializing GameSM \n\r");

//initialize the hardware pins if any


/*
Initialize the hardware pin to read the analog input

*/

// set up port C and Port E by enabling the peripheral clock, waiting for the
// peripheral to be ready and setting the direction of PE1-PE5 as input and
PC4 to PC7 as output

HWREG(SYSCTL_RCGCGPIO) |= BIT4HI; //Activating Port E


//Waiting for Port E to activate
while ((HWREG(SYSCTL_PRGPIO) & SYSCTL_PRGPIO_R4) != SYSCTL_PRGPIO_R4)
{}
HWREG(SYSCTL_RCGCGPIO) |= BIT2HI; //Activating Port C
//Waiting for Port C to activate
while ((HWREG(SYSCTL_PRGPIO) & SYSCTL_PRGPIO_R2) != SYSCTL_PRGPIO_R2)
{}

//Defining BIT1 to BIT5 of Port E to act as an digital inputs


HWREG(GPIO_PORTE_BASE + GPIO_O_DEN) |= (IR_PIPE1HI | IR_PIPE2HI | IR_PIPE3HI |
IR_PIPE4HI | IR_PIPE5HI);
HWREG(GPIO_PORTE_BASE + GPIO_O_DIR) &= (IR_PIPE1LO & IR_PIPE2LO & IR_PIPE3LO &
IR_PIPE4LO & IR_PIPE5LO);
//Defining BIT4 to BIT7 of Port C to act as an digital outputs
HWREG(GPIO_PORTC_BASE + GPIO_O_DEN) |= (DECODE_A0_PORT_HI | DECODE_A1_PORT_HI
| DECODE_A2_PORT_HI | DECODE_E3_PORT_HI);
HWREG(GPIO_PORTC_BASE + GPIO_O_DIR) |= (DECODE_A0_PORT_HI | DECODE_A1_PORT_HI
| DECODE_A2_PORT_HI | DECODE_E3_PORT_HI);

//setting current state as the pseudo state


CurrentState = PseudoState_Game;

//initializing the short timer


ES_ShortTimerInit(MyPriority, SHORT_TIMER_UNUSED);

//Initializing SRPipe
SRPipe_Init();

ES_Event_t ThisEvent;
ThisEvent.EventType = ES_INIT;
if (ES_PostToService(MyPriority, ThisEvent) == true)
{
return true;
}
else
{
return false;
}
}

/****************************************************************************
Function
PostGameSM

Parameters
ES_Event_t 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
****************************************************************************/
bool PostGameSM(ES_Event_t ThisEvent)
{
return ES_PostToService(MyPriority, ThisEvent);
}

/****************************************************************************
Function
RunGameSM

Parameters
ES_Event_t : the event from its service queue to process in this State
Machine
Types of ES_Event_t:

Returns
ES_Event_t, ES_NO_EVENT if no error ES_ERROR otherwise

Description
Runs InGame state machine
Notes

Author
J. Edward Carryer, 01/15/12, 15:23
****************************************************************************/
ES_Event_t RunGameSM(ES_Event_t ThisEvent)
{
ES_Event_t ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no errors

//if not in the InGame state from ControlSM, no point being here in the GameSM
if (getControlSM_State() != InGame)
{
printf("\r \n Not in Game state for now");

//not posting any reset, just going to the Uninitialized state if not in the
InGame sate in ControlSM
CurrentState = Uninitialized_Game;
}

switch (CurrentState)
{
case PseudoState_Game: // If current state is initial Psedudo State
{
if (ThisEvent.EventType == ES_INIT) // only respond to ES_Init
{
// this is where you would put any actions associated with the
// transition from the initial pseudo-state into the actual
// initial state

// now put the machine into the actual initial state


puts("\r \n PseudoState_Game --> Uninitialized");
CurrentState = Uninitialized_Game;
}
}
break;

case Uninitialized_Game:
{
if (ThisEvent.EventType == START_GAME)
{
//actions
/*
Send ACTIVATE_RANDOM_PIPE back to this service
Set Pipe timer
Set score timer
initialize the random pipe
*/

puts("\r \n Post ACTIVATE_RANDOM_PIPE to this service");


ES_Event_t PostingEvent;
PostingEvent.EventType = ACTIVATE_RANDOM_PIPE;
PostGameSM(PostingEvent);

//setting shorttimer for the score timer - channel A


//not required to set. Can directly start
//puts("\r \n Starting short timer on Channel A");
//ES_ShortTimerStart(TIMER_A, SCORE_TIME);

//setting pipe timer based on difficulty stoed as the event_param in


start_game
int difficulty_level = ThisEvent.EventParam;
PipeTimeMultiplier = MAX_DIFFICULTY - difficulty_level;
pipeTime = PipeTimeMultiplier * FIFTEENTH_SEC;
//ES_Timer_SetTimer(PIPE_TIMER, pipeTime);
printf("\r \n Pipe time set to %d for difficulty: %d", pipeTime,
difficulty_level);

random_pipe_index = 0;

puts("\r \n Uninitialized --> SelectingPipe");


CurrentState = SelectingPipe;
}
}
break;

case SelectingPipe:
{
if (ThisEvent.EventType == ACTIVATE_RANDOM_PIPE) //Leaf removed
{
//actions
/*
Select a Random Pipe and the events now will be based on that
Start Pipe Timer
Start Score Timer
Start Pipe Lights for the selected pipe
*/
random_pipe_index = rand() % 5 + 1; //pipes from 1-5
//random_pipe_index = 4 + 1; checking pipe 5
printf("\r \n %d pipe selected", random_pipe_index);

ES_Timer_InitTimer(PIPE_TIMER, pipeTime);
ES_ShortTimerStart(TIMER_A, SCORE_TIME);
//restarting the water flow timer
ES_Timer_InitTimer(WATER_FLOW_TIMER, WaterFlowTime);

puts( "\r \n Started Pipe timer and short timer");

//Calls ActivateRandomPipe function


puts( "\r \n Glow LED on the pipe with the random pipe index");
ActivatePipeLED(random_pipe_index);

//Calls SRPipe to write a 0 and activate all lights


SRPipe_Write(0);
puts( "\r \n Glow LED on the pipe with the random pipe index");

puts( "\r \n SelectingPipe --> WaterFlowing");


CurrentState = WaterFlowing;
}
else if (ThisEvent.EventType == MARIO_END) //MARIO has reached the end.
Timer off
{
//Turning off all pipes
ActivatePipeLED(0);
puts("\r \n SelectingPipe --> WaitForReset");
CurrentState = WaitForReset;
}
else if ((ThisEvent.EventType == LEAF_RESET) || (ThisEvent.EventType ==
INACTIVE_RESET))
{
//Turning off all pipes
ActivatePipeLED(0);
puts("\r \n SelectingPipe --> Uninitialized");
CurrentState = Uninitialized_Game;
}
}
break;

case WaterFlowing:
{
if (ThisEvent.EventType == ES_SHORT_TIMEOUT) //Score timer timeout
{
//actions
/*
Reset score timer -- not required. Will just directly start it

*/
puts("\r \n WaterFlowing --> IRRead");
CurrentState = IRRead;

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

REMOVE THIS PRINT. IT IS JUST FOR SR2 HillAndMotor Value Testing

*/
uint8_t Value = SR_HillAndMotor_GetCurrentRegister();
printf("\r \n %d", Value);

//POST check score event to IRRead


ES_Event_t PostingEvent;
PostingEvent.EventType = SCORE_CHECK;
PostGameSM(PostingEvent);
}
else if ((ThisEvent.EventType == ES_TIMEOUT) && (ThisEvent.EventParam ==
PIPE_TIMER))
{
//actions
/*
ResetScoreTimer -- not required
Reset pipe timer -- not required
send ACTIVATE_RANDOM_PIPE
*/
puts("\r \n Posting ACTIVATE_RANDOM_PIPE to this service");
ES_Event_t PostingEvent;
PostingEvent.EventType = ACTIVATE_RANDOM_PIPE;
PostGameSM(PostingEvent);
ActivatePipeLED(0);

puts("\r \n WaterFlowing --> SelectingPipe");


CurrentState = SelectingPipe;
}
else if ((ThisEvent.EventType == ES_TIMEOUT) && (ThisEvent.EventParam ==
WATER_FLOW_TIMER))
{
//actions
/*
Write a random value to the SR from 0 to 31 and return to the same state
send ACTIVATE_RANDOM_PIPE
*/
int random_pipe_glow = rand() % 32;
SRPipe_Write(random_pipe_glow);

//restart timer
ES_Timer_InitTimer(WATER_FLOW_TIMER, WaterFlowTime);

CurrentState = WaterFlowing;
}
else if (ThisEvent.EventType == MARIO_END) //MARIO has reached the end.
Timer off
{
//actions
//Turning off all pipes
ActivatePipeLED(0);
puts("\r \n WaterFlowing--> WaitForReset");
CurrentState = WaitForReset;
}
else if ((ThisEvent.EventType == LEAF_RESET) || (ThisEvent.EventType ==
INACTIVE_RESET))
{
//Turning off all pipes
ActivatePipeLED(0);
puts("\r \n WaterFlowing--> Uninitialized");
CurrentState = Uninitialized_Game;
}
}
break;

case IRRead:
{
if (ThisEvent.EventType == MARIO_END) //Leaf removed
{
//actions
//Turning off all pipes
ActivatePipeLED(0);
puts("\r \n IRRead--> WaitForReset");
CurrentState = WaitForReset;
}
else if ((ThisEvent.EventType == LEAF_RESET) || (ThisEvent.EventType ==
INACTIVE_RESET))
{
//Turning off all pipes
ActivatePipeLED(0);
puts("\r \n IRRead --> Uninitialized");
CurrentState = Uninitialized_Game;
}
else if (ThisEvent.EventType == SCORE_CHECK)
{
//deterministic non-blocking internal check for transitioning back to
the WaterFlowing state
if (CheckIRConnection())
{
//puts("\r \n No Bucket Placed");
//actions
/*
Start score timer
play the bad sound
Reset and start the inactivity timer
*/
//puts("\r \n Posting SCORE_DEC to ScoringSM");
ES_Event_t PostingEvent;
PostingEvent.EventType = SCORE_DEC;
PostScoringSM(PostingEvent);

ES_ShortTimerStart(TIMER_A, SCORE_TIME);

//puts("\r \n Playing Bad Sound");


ES_Event_t SoundEvent;
SoundEvent.EventType = SOUND_PLAY;
SoundEvent.EventParam = 1;
PostSoundSM(SoundEvent);

//ES_Timer_InitTimer(INACTIVE_TIMER, THIRTY_SEC);

//puts("\r \n IRRead --> WaterFlowing");


CurrentState = WaterFlowing;
}
else if (!CheckIRConnection())
{
//puts("\r \n Bucket Placed");
//actions
/*
Start score timer
play the bad sound
Restart the inactivity timer
*/
ES_ShortTimerStart(TIMER_A, SCORE_TIME);
//puts("\r \n Playing Good Sound");
ES_Event_t SoundEvent;
SoundEvent.EventType = SOUND_PLAY;
SoundEvent.EventParam = 0;
PostSoundSM(SoundEvent);
ES_Timer_InitTimer(INACTIVE_TIMER, THIRTY_SEC);

//puts("\r \n IRRead --> WaterFlowing");


CurrentState = WaterFlowing;
}
}
}
break;

case WaitForReset:
{
if ((ThisEvent.EventType == LEAF_RESET) || (ThisEvent.EventType ==
INACTIVE_RESET))
{
//actions

puts("\r \n WaitForReset --> Uninitialized");


CurrentState = Uninitialized_Game;
}
}
break;
}

return ReturnEvent;
}

static bool CheckIRConnection(void)


{
//Returns true if no IR detected, and false for IR detection
//uses the static variable rando_pipe_index to check for the required IR
connection
//Reads Port E. Bits 1 to 5 (corresponding each bit number for a single pipe)

//Predefines the Return Value if there is no IR sensor


bool ReturnValue = true;
switch (random_pipe_index)
{
case 1:
{
//Reads IR Sensor 1 to check if there is a connection break
if ((HWREG(PIPES_IR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) & IR_PIPE1HI))
{
ReturnValue = false;
}
}
break;
case 2:
{
//Reads IR Sensor 2 to check if there is a connection break
if ((HWREG(PIPES_IR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) & IR_PIPE2HI))
{
ReturnValue = false;
}
}
break;
case 3:
{
//Reads IR Sensor 3 to check if there is a connection break
if ((HWREG(PIPES_IR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) & IR_PIPE3HI))
{
ReturnValue = false;
}
}
break;
case 4:
{
//Reads IR Sensor 4 to check if there is a connection break
if ((HWREG(PIPES_IR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) & IR_PIPE4HI))
{
ReturnValue = false;
}
}
break;
case 5:
{
//Reads IR Sensor 5 to check if there is a connection break
if ((HWREG(PIPES_IR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) & IR_PIPE5HI))
{
ReturnValue = false;
}
}
break;
}
return ReturnValue;
}

void ActivatePipeLED(uint8_t PipeNumber)


{
//This function will send to the decoder the number of the pipe its going to
activate, or 0 to turn off all pipes
//Recieves the pipe number index or 0
//No return value
//Reference: Port C, bits 4 to 7 will be used
//Decoder Assignment: Bit 4 to 6: A0,A1,A2 Bit 7: E3
switch (PipeNumber)
{
case 0:
{
//Defaults pipe select to 111, sets decoder enable bit to low
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (DECODE_A0_PORT_HI |
DECODE_A1_PORT_HI | DECODE_A2_PORT_HI);
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (DECODE_E3_PORT_LO);
}
break;
case 1:
{
//Turns on pipe 1, sends 000 to decoder select, and sends high to enable
bit
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (DECODE_A0_PORT_LO &
DECODE_A1_PORT_LO & DECODE_A2_PORT_LO);
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (DECODE_E3_PORT_HI);
}
break;
case 2:
{
//Turns on pipe 2, sends 001 to decoder select, and sends high to enable
bit
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (DECODE_A1_PORT_LO &
DECODE_A2_PORT_LO);
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (DECODE_A0_PORT_HI |
DECODE_E3_PORT_HI);
}
break;
case 3:
{
//Turns on pipe 3, sends 010 to decoder select, and sends high to enable
bit
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (DECODE_A0_PORT_LO &
DECODE_A2_PORT_LO);
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (DECODE_A1_PORT_HI |
DECODE_E3_PORT_HI);
}
break;
case 4:
{
//Turns on pipe 5, sends 011 to decoder select, and sends high to enable
bit
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (DECODE_A2_PORT_LO);
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (DECODE_A0_PORT_HI |
DECODE_A1_PORT_HI | DECODE_E3_PORT_HI);
}
break;
case 5:
{
//Turns on pipe 5, sends 100 to decoder select, and sends high to enable
bit
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (DECODE_A0_PORT_LO &
DECODE_A1_PORT_LO);
HWREG(PIPES_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (DECODE_A2_PORT_HI |
DECODE_E3_PORT_HI);
}
break;
}
}

static void SRPipe_Init(void)


{
// set up port B by enabling the peripheral clock, waiting for the
// peripheral to be ready and setting the direction
// of PB0, PB1 & PB2 to output

HWREG(SYSCTL_RCGCGPIO) |= BIT1HI; //Activating Port B


//Waiting for Port b to activate
while ((HWREG(SYSCTL_PRGPIO) & SYSCTL_PRGPIO_R1) != SYSCTL_PRGPIO_R1)
{}
//Defining BIT0, 1, and 2 of Port B to act as an digital Output
HWREG(PIPES_SR_GPIO_BASE + GPIO_O_DEN) |= (SR_PIPE_SD_HI | SR_PIPE_SCLK_HI |
SR_PIPE_RCLK_HI);
HWREG(PIPES_SR_GPIO_BASE + GPIO_O_DIR) |= (SR_PIPE_SD_HI | SR_PIPE_SCLK_HI |
SR_PIPE_RCLK_HI);
// start with the data & sclk lines low and the RCLK line high
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (SR_PIPE_SD_LO &
SR_PIPE_SCLK_LO);
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (SR_PIPE_RCLK_HI);
}

void SRPipe_Write(uint8_t NewValue)


{
uint8_t LSB;
// LocalRegisterImage = NewValue; // save a local copy

// lower the register clock


HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (SR_PIPE_RCLK_LO);
// shift out the data while pulsing the serial clock
for (int i = 0; i < 8; i++)
{
// Isolate the MSB of NewValue, put it into the LSB position and output to
port
LSB = GET_MSB_IN_LSB(NewValue);
if (LSB == 0)
{
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (SR_PIPE_SD_LO);
}
else
{
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (SR_PIPE_SD_HI);
}
// raise SCLK
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (SR_PIPE_SCLK_HI);
// lower SCLK
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) &= (SR_PIPE_SCLK_LO);
// finish looping through bits in NewValue
NewValue = NewValue << 1;
}
// raise the register clock to latch the new data
HWREG(PIPES_SR_GPIO_BASE + (GPIO_O_DATA + ALL_BITS)) |= (SR_PIPE_RCLK_HI);
}

You might also like