Академический Документы
Профессиональный Документы
Культура Документы
c Pseudocode
Definitions
AUDIOPORT, the definition for the port being used
Definitions for the Data, Shift, and Register pins
Definitions specifying the Data, Shift, and Register pins both high and
low
TRACKX specifies the uint32_t for track X. X takes on values 1-18
Module Level Variables
uint8_t MyPriority to store priority number
boolean noInterrupts to make a track not interruptible
Helper functions
SR_Write3Bytes to specify all the states of the shift register (SR) pins
for the desired track
SR_Shift1Byte, to write one byte at a time to the shift registers
SR_StoreAllBytes, to set the SR outputs to the current state of the inte
rnal pins
InitializeAudio
Accepts a service priority number, returns True
Set the module level variable recording priority equal to the passed in p
arameter
Initialize the port clock
Wait until the port clock is initialized to continue
Enable Data, Shift, and Register pins as digital I/O pins
Enable Data, Shift, and Register pins as outputs
Return True
End InitalizeAudio
PostAudioService
Accepts an ES_Event type event, returns True if the event is successfull
y posted, false otherwise
Post the passed-in event to the audio service using its posting function
Return True if the event is successfully posted, false otherwise
End PostAudioService
RunAudio
Accepts an ES_Event type event, returns an event with type of no event,
which assumes no error
Create a variable to store the appropriate track number to play in respo
nse to event
Create a variable to store a second track number to play
If the event is an ES_OPEN event (curtain opened)
Track to play 1 is the theme
Else If the event is an ES_WIND event (windmill blown)
Track to play 1 is wind sound effect
Else If the event is an ES_LIGHTNING event (windmill blown fast enough)
Track to play 1 is a lightning sound effect
Make the track not interruptible by setting the module level boo
lean noInterrupts True
Set a time to wait to kill the track (in ms)
Set the kill track timer with this time
Else If the event is an ES_GROW event (wind scene is over)
Track to play 1 is a heavy rain sound effect
Track to play 2 is a light, fading rain sound effect
Set a time to wait before beginning a second track
Set the second track timer with this time
Else If the event is an ES_PLANTGROWN event (plant has grown)
Track to play 1 is a plant growing sound effect
Set a time to wait to kill the track (in ms)
Call the SRWrite1Byte function, passing in the third byte to send to the
shift registers
Call the StoreAllBytes() function, which sets all SR pin outputs to the c
urrent pin states
End SR_Write3Bytes
SR_Shift1Byte
Accepts a uint32_t specifying a byte to send, returns nothing
Declare a loop variable to represent the number of bits already passed to the SR
s
Save a local copy of the passed in byte. Save a uint32_t as a uint8_t t
o isolate 8 LSBs to send.
Turn the Register pin low before writing data to the SRs
For the loop variable less than 9, starting at 1, incremented by 1 each
loop
Shift the MSB to the LSB position
If the LSB is zero
Set the Data pin low
If the LSB is one
Set the Data pin high
End if
Set the shift pin high and then low to shift in the value on the
data pin
Shift the local copy bits to the left by one, to get a new MSB
End for loop
End SR_Shift1Byte
SR_StoreAllBytes
Accepts nothing, returns nothing
Turn the Register pin high to set SR output pins to the current internal
pin states
End SR_StoreAllBytes
End of Audio.c Pseudocode