You are on page 1of 6

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

Header file for Music module


based on the Gen2 Events and Services Framework
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
#ifndef Music_H
#define Music_H
// Public Function Prototypes
void InitMusic(void);
void ResetMusic(void);
void PlayFirst(void);
void PlaySecond(void);
#endif
//#define test
/****************************************************************************
Module
Music.c
Description
Service module for play music by sending command to SD card reading module
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this service
*/
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
// 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
#include
#include
#include

"driverlib/sysctl.h"
"driverlib/gpio.h"
"driverlib/interrupt.h"
"utils/uartstdio.h"

// the header to get the timing functions


#include "ES_Port.h"
#include "termio.h"
#include "EnablePA25_PB23_PD7_PF0.h"
#include "PWMTiva.h"

#include "GeneralBase.h"
#include "Music.h"
/*----------------------------- Module Defines ----------------------------*/
// the port used to control music port
#define MusicPort 'B'
// the reset pin for music module
#define ResetPin BIT0HI
// the data pin for music module
#define DataPin BIT1HI
// the CK pin for music module
#define CKPin BIT2HI
#define ALL_BITS (0xff<<2)
#define clrScrn()
printf("\x1b[2J")
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this machine.They should be functions
relevant to the behavior of this state machine
*/
void MusicPulse(char, uint8_t);
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
InitMusic
Parameters
nothing
Returns
nothing
Description
initialize all IO pins needed to control music module
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void InitMusic(void)
{
// Activate the system clock
InitSystemClock(MusicPort);
// Set all music pins to IO
InitPinIO(MusicPort,ResetPin|DataPin|CKPin);
// Set all music pins to Output
InitPinDir(MusicPort,ResetPin|DataPin|CKPin,1);
}
/****************************************************************************
Function
ResetMusic
Parameters
nothing
Returns
nothing

Description
Reset the music module by sending reset command
Note: can only be used in initialization since blocking code included
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void ResetMusic(void)
{
// write the reset pin low
write(MusicPort,ResetPin,0);
// wait 10 mS
delay(10);
// write the reset pin high
write(MusicPort,ResetPin,1);
// wait 300 mS
delay(300);
}
/****************************************************************************
Function
MusicPulse
Parameters
Take 2 parameters, first is the port character with upper case,
second is the pin number indicated by a 8 bits number with
corresponding digit as hi
Returns
nothing
Description
Create a pulse output the corresponding pin
Note: the only difference between this function and pulse function in
general base module
is this function create a 200 uS pulse rather than 20 uS
Final Editing: Dongao Yang 11/25/2014
****************************************************************************/
void MusicPulse(char port, uint8_t pin)
{
// if port is B
if (port == 'B')
{
// write this pin high
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) |= pin;
// wait 200 uS
pause(200);
// write this pin low
HWREG(GPIO_PORTB_BASE+(GPIO_O_DATA+ALL_BITS)) &= ~pin;
// wait 200 uS
pause(200);
}
// if port is C
else if(port == 'C')
{
// write this pin high

HWREG(GPIO_PORTC_BASE+(GPIO_O_DATA+ALL_BITS)) |= pin;
// wait 200 uS
pause(200);
// write this pin low
HWREG(GPIO_PORTC_BASE+(GPIO_O_DATA+ALL_BITS)) &= ~pin;
// wait 200 uS
pause(200);
}
// if port is D
else if(port == 'D')
{
// write this pin high
HWREG(GPIO_PORTD_BASE+(GPIO_O_DATA+ALL_BITS)) |=
// wait 200 uS
pause(200);
// write this pin low
HWREG(GPIO_PORTD_BASE+(GPIO_O_DATA+ALL_BITS)) &=
// wait 200 uS
pause(200);
}
// if port is E
else if(port == 'E')
{
// write this pin high
HWREG(GPIO_PORTE_BASE+(GPIO_O_DATA+ALL_BITS)) |=
// wait 200 uS
pause(200);
// write this pin low
HWREG(GPIO_PORTE_BASE+(GPIO_O_DATA+ALL_BITS)) &=
// wait 200 uS
pause(200);
}
// if port is F
else if(port == 'F')
{
// write this pin high
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) |=
// wait 200 uS
pause(200);
// write this pin low
HWREG(GPIO_PORTF_BASE+(GPIO_O_DATA+ALL_BITS)) &=
// wait 200 uS
pause(200);
}
else
{
//print the error message
puts("Error: you indicate a wrong port for pulse
}

pin;

~pin;

pin;

~pin;

pin;

~pin;

\n");

}
/****************************************************************************
Function
PlayFirst
Parameters
nothing

Returns
nothing
Description
Play the first music recored in SD card, file name: 0000
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void PlayFirst(void)
{
// set CK pin low
write(MusicPort,CKPin,0);
// wait 5 mS
delay(5);
// for loop 15 times
for(int i =0; i<15; i++)
{
// set DATA to low
write(MusicPort,DataPin,0);
// pulse CK pin
MusicPulse(MusicPort,CKPin);
}
// set DATA low
write(MusicPort,DataPin,0);
// pulse CK pin
MusicPulse(MusicPort,CKPin);
// set DATA pin high
write(MusicPort,DataPin,1);
// set CK pin high
write(MusicPort,CKPin,1);
}
/****************************************************************************
Function
PlaySecond
Parameters
nothing
Returns
nothing
Description
Play the first music recored in SD card, file name: 0001
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void PlaySecond(void)
{
// set CK pin low
write(MusicPort,CKPin,0);
// wait 5 mS
delay(5);
// for loop 15 times
for(int i =0; i<15; i++)
{
// set DATA to low
write(MusicPort,DataPin,0);
// pulse CK pin

MusicPulse(MusicPort,CKPin);
}
// set DATA pin high
write(MusicPort,DataPin,1);
// pulse CK pin
MusicPulse(MusicPort,CKPin);
// set DATA pin high
write(MusicPort,DataPin,1);
// set CK pin high
write(MusicPort,CKPin,1);
}
// test harness
#ifdef test
int main(void)
{
_HW_Timer_Init(ES_Timer_RATE_1mS);
TERMIO_Init();
clrScrn();
PortFunctionInit();
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
| SYSCTL_XTAL_16MHZ);
PWM_TIVA_Init();
PWM_TIVA_SetFreq(50, 0);
PWM_TIVA_SetFreq(50, 1);
PWM_TIVA_SetPulseWidth(800,0);
puts("this is the test harness for music: \n");
InitMusic();
ResetMusic();
while(1)
{
PlayFirst();
getchar();
PlaySecond();
getchar();
}
return 0;
}
#endif

You might also like