You are on page 1of 3

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

Module
LEDs.c
Revision
1.0.1
Description
This is a template file for implementing a simple service under the
Gen2 Events and Services Framework.
Notes
History
When Who
--------------------
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include <stdio.h>
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_Port.h"
#include "ES_DeferRecall.h"
#include "ES_Timers.h"
#include "termio.h"
#include "BITDEFS.h" // standard bit definitions to make things more readable

// the headers to access the GPIO subsystem


#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_pwm.h"
#include "inc/hw_timer.h"
#include "inc/hw_nvic.h"

// the headers to access the TivaWare Library


#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"

// headers from service files


//#include "SPISerice.h"
//#include "DCMotorService.h"
#include "LEDs.h"

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


//#define BitsPerNibble 4

//Time define
//#define TicksPerMS 40000 //use system clock
//#define OneShotTimeout 100 * TicksPerMS // 100 ms
//#define PeriodMinTicks 10000
//#define PeriodMaxTicks 45000

//Red LED : PB2


//Blue LED: PB3
//Game Indicator: PF4
//Team setting: PF3
#define RED 1
#define BLUE 0
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this service.They should be functions
relevant to the behavior of this service
*/

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


// with the introduction of Gen2, we need a module level Priority variable

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

void InitLEDs(void)
{
//Init TEAM LEDs
//Initialize PB2 - PB3 to be digital outputs
HWREG(SYSCTL_RCGCGPIO)|= SYSCTL_RCGCGPIO_R1; // Port B
while ((HWREG(SYSCTL_RCGCGPIO) & SYSCTL_RCGCGPIO_R1) != SYSCTL_RCGCGPIO_R1);
HWREG(GPIO_PORTB_BASE+GPIO_O_DEN)|= ( BIT2HI | BIT3HI );
HWREG(GPIO_PORTB_BASE+GPIO_O_DIR)|= ( BIT2HI | BIT3HI );
//Turn off LEDs at initialization by writing LO to BIT2 and BIT3
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT2LO;
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT3LO;

//Init Game Indicator LED


//Initialize PF4 to be digital outputs
HWREG(SYSCTL_RCGCGPIO)|= SYSCTL_RCGCGPIO_R5; // Port F
while ((HWREG(SYSCTL_RCGCGPIO) & SYSCTL_RCGCGPIO_R5) != SYSCTL_RCGCGPIO_R5);
HWREG(GPIO_PORTF_BASE+GPIO_O_DEN)|= BIT4HI; //digital
HWREG(GPIO_PORTF_BASE+GPIO_O_DIR)|= BIT4HI; //output
//Turn off LEDs at initialization by writing LO to BIT4
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT4LO;

//Init Team setting


//Initialize PF3 to be digital input
HWREG(GPIO_PORTF_BASE+GPIO_O_DEN)|= BIT3HI; //digital
HWREG(GPIO_PORTF_BASE+GPIO_O_DIR)&= BIT3LO; //input

void TurnOffLEDs(void){
//Turn off LEDs by writing LO to PB2, PB3 & PF4
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT2LO;
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT3LO;
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &= BIT4LO;
}

void TurnOnRLED(void){
//Turn on Red LED by writing HI to PB2
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT2HI;
}

void TurnOnBLED(void){
//Turn on Blue LED by writing HI to PB3
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT3HI;
}

void TurnOnYLED(void){
//Turn on game indicator LED by writing HI to PF4
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |= BIT4HI;
}

int GetTeamColor(void){
//read PF3
//if PF3 is HI, return RED (1), otherwise return BLUE (0)
if( (HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) & BIT3HI) == BIT3HI) return
RED;
return BLUE;
}
/*------------------------------- Footnotes -------------------------------*/
/*------------------------------ End of file ------------------------------*/

You might also like