Sie sind auf Seite 1von 6

Pseudo Code for communicationsSM.

c
FUNCTION: InitCommunication takes a priority number, returns true Set Set Set Set the ack line to input the strobe line to input data lines 0, 1, and 2 to input message pins to empty

Initialize MyPriority with the passed in parameter Set the CurrentState to Idle return true

FUNCTION: PostCommunication takes an event, returns a boolean run and return ES_PostToService with parameter passed in event parameter

FUNCTION: RunCommunication takes an event, returns an event Initialize ReturnEvent Set ReturnEvent event type to ES_NO_EVENT Based on the value of CurrentState: CurrentState is Idle if ThisEvent.EventType is ES_STROBE_RISE run readData run assertAck set NextState to WatiForStrobeFall if ThisEvent.EventType is ES_SEND_REQUEST Set savedNewData to ThisEvent.EventParam if the strobe line is low run startTimer run sendEvent with parameter savedNewData set NextState to WaitforAck else set NextState to WaitingtoReceive

CurrentState is WaitForStrobeFall if ThisEvent.EventType is ES_STROBE_FALL run deassertAck run postReceeivedData set NextState to Idle if ThisEvent.EventType is ES_SEND_REQUEST run starttimer run sendEvent run postReceivedData run deassertAck set NextState to WaitforAck CurrentState is WaitforAck if ThisEvent.EventType is ES_ACK_RISE run deassertDataAndStrobe set NextState to Idle if ThisEvent.EventType is ES_TIMEOUT initialize RepostEvent set RepostEvent.EventType to ES_SEND_REQUEST set RepostEvent.EventType to savedNewData run deassertDataAndStrobe for one C32, run PostCommunication with parameter RepostEvent set NextState to Idle CurrentState is WaitingtoReceive if ThisEvent.EventType is ES_STROBE_RISE run readData run assertAck set NextState to WaitingtoSend CurrentState is WaitingtoSend if ThisEvent.EventType is ES_STROBE_FALL run deassertAck run postReceivedData run startTimer run sendEvent with parameter savedNewData set NextState to WaitforAck set CurrentState to NextState return ReturnEvent

FUNCTION: QueryCommunication 2

Takes no parameters, returns TemplateState_t Return CurrentState

Private Functions FUNCTION: readData Takes nothing, returns nothing Read data in from ports M2, M3, and M4 Bit-shift message_pins down 2

FUNCTION: assertAck Takes nothing, returns nothing Set ack line to output Set ack pin to high

FUNCTION: deassertAck Takes nothing, returns nothing Set ack pin to low Set akc line to input

FUNCTION: startTimer Takes nothing, returns nothing run ES_Timer_InitTimer with parameters 1, 20

FUNCTION: postReceivedData Takes nothing, returns nothing Initialize SimultaneousEvent Initialize SendEvent Initialize outputMessage to empty Based on the state of message_pins message_pins is START_BUTTON_PRESS if checkStartButtonS is true set SimlutaneousEvent.EventType to ES_STARGBUTTON_PRESSED_S 3

run PostGame with SimlutaneousEvent parameter set outputMessage to START_BUTTON_PRESS_S message_pins is START_BUTTON_PRESS_S set SimultaneousEvent.EventType to ES_STARTBUTTON_PRESSED_S run PostGame with SimlutaneousEvent parameter message_pins is HADES_IR_DETECT if QueryGame() is HadesShootingFast and QueryGame() is HadesShootingSlow set SimlutaneousEvent.EventType to ES_IR_DETECT_S run PostGame with parameter SimlutaneousEvent set outputMessage to IR_DETECT_S message_pins is FLAME_IR_DETECT if checkFlameIRSensorsS() is true and QueryGame() is TorchLighting set SimultaneousEvent.EventType to ES_JOYSTICKS_FORWARD_S run PostGame with parameter SimultaneousEvent set outputMessage to JOYSTICK_FORWARD_S message_pins is IR_DETECT_S set SimultaneousEvent.EventType to ES_IR_DETECT_S run PostGame with parameter SimultaneousEvent message_pins is JOYSTICK_CHANGE if checkJoystickHigh() is True SimultaneousEvent.EventType is ES_JOYSTICKS_FORWAD_S run PostGame with parameter SimultaneousEvent set outputMessage to JOYSTICK_FORWARD_S message_pines is JOYSTICK_STOP set SimultaneousEvent.EventType to ES_JOYSTICKS_STOP run PostGame with parameter SimultaneousEvent if outputMessage is not EMPTY set SendEvent.EventType to ES_SEND_REQEST set SendEvent.EventParameter to outputMessage run PostCommunication with parameter SendEvent

FUNCTION: sendEvent takes int message, returns nothing set strobe line to output set data lines to output

Based on the state of message message is START_BUTTON_PRESS set all data lines low message set set set message set set set message set set set message set set set message set set set message set set set message set set set is START_BUTTON_PRESS_S data pin 0 high data pin 1 low data pin 2 low is FLAME_IR_DETECT data pin 0 low data pin 1 high data pin 2 low is IR_DETECT_S data pin 0 high data pin 1 high data pin 2 low is JOYSTICK_CHANGE data pin 0 low data pin 1 low data pin 2 high is JOYSTICK_STOP data pin 0 high data pin 1 low data pin 2 high is JOYSTICK_FORWARD_S data pin 0 low data pin 1 high data pin 2 high is HADES_IR_DETECT data pin 0 high data pin 1 high data pin 2 high

set strobe pin high

FUNCTION: deassertDataAndStrobe Takes nothing, returns nothing

stop timer 1 set strobe pin low set strobe line to input set all data lines to input

Das könnte Ihnen auch gefallen