Vous êtes sur la page 1sur 2

1 PIC_UARTService

************************************************************************************
Pseudo-code for the PIC_UART service
Initializes asynchronous communication between the TIVA and the PIC at 9600 baud
rate using the UART 3 module, and then posts events to the PIC to turn the lift
fan ON/OFF.

InitPIC_UARTService
Takes a priority number, returns true

// Initialize Defferal Queue


// Initialize the MyPriority variable with the passed in parameter.
// Initialize UART module 3 using InitUART3 function
// Post the initial transition event to this services queue
// Return true if post was successful
End of InitPIC_UARTService

PostPIC_UARTService
Create PostPIC_UARTService

RunPIC_UARTService
The parameter it takes in will be ThisEvent and the parameter field of
ThisEvent will be the time that the event occurred. Returns ES_NO_Event.

// Create an event to return


// Define any function-level variables
// Set NextState to CurrentState
// Based on the state of the CurrentState, choose one of the following blocks of
code
// If case is InitTransmit
// If event is ES_INIT
// Change current state to Waiting
// Endif
// If case is Waiting
// If event is EV_ToggleLift
// Set packet type based on passed in parameter
// Call on ConstructTransmitPacket and pass in packet type
// If ConstructTransmitPacket returns true
// Reset bytes sent
// Call on UART3_TXStart function
// Set current state to UART3_Transmitting
// Endif
// Endif
// If case is is UART3_Transmitting
// If transmission ends (EV_UART3TransmitComplete)
// Reset state to Waiting
// Endif
// Endif
// Return ES_NO_EVENT
End of RunPIC_UARTService

ConstructTransmitPacket
Takes in a packet type and returns true

// Set bool PacketConstructed to false


// Switch on packet type
// If packet type is FAN_ON
// Update data size depending on packet type
// Add in packet byte (should be 0x0B for ON)
// Set PacketConstructed to true
// Else if packet type is FAN_OFF
// Update data size depending on packet type
// Add in packet byte (should be 0x0A for OFF)
// Set PacketConstructed to true
// Endif
// Return PacketConstructed
End of ConstructTransmitPacket

6
UART3_TXStart
Function to initiate transmit process to PIC. Takes in nothing and returns true

// If TXFE is set, FIFO is empty and we can transfer a byte


// Write new byte out using UART_O_DR register
// Increment index
// Return true
// Else we cannot transfer a byte so return false
// Endif
End of UART3_TXStart

InitUART3
Initializes UART 3 module, which uses PC6 and PC7.

// Enable the clock to UART3 module using the RCGCUART (run time gating
clock control) register
// Wait for the UART to be ready using the PRUART (peripheral ready register)
// Enable the clock to the appropriate GPIO module (Port D) via the RCGCGPIO
// Correct pins for UART3 are PC6: RX, PC7: TX
// Wait for the GPIO port clock to be ready (PRGPIO)
// Configure GPIO pins for RX/TX/drive-level/drive-type
// Enable pins as digital
// Set RX line as input
// Set TX line as output
// Select the Alternate function for the UART pins (AFSEL)
// Configure the PMCn fields in the GPIOPCTL register to assign the UART pins
// (write a 1 to each position corresponding to a UART3 pin)
// Disable the UART by clearing the UARTEN bit in the UARTCTL register (it is
disabled out of reset so this is a formality)
// Configure baud rate to be 9600:
// Write the integer portion of the baud rate to the UARTIBRD register (260)
// Write the fractional portion of the BRD to the UARTFBRD register
(the decimal remainder*64 + 0.5) (27)
// Write the desired serial parameters to the UARTLCRH register:
number of stop bits, word length, parity
// 1 stop bit is the default
// Set word length to be 8 bits by writing 0x3 to WLEN bits (<6:5>)
// Leave stick parity select as default of 0
// Configure the UART operation using the UARTCTL register:
// Do nothing because RXE and TXE are already enabled, and HSE comes out
of reset as 0
// TX interrupt also comes out of reset as set to fire whenever a new byte
can be loaded, which is correct
// Enable the UART by setting the UARTEN bit in the UARTCTL register
// Clear any pending RX interrupt then initialize UART TX and RX interrupts
// Enable NVIC (bit 59 overall, so bit 27 of EN1)
// Enable global interrupts in case this has not been done elsewhere
// Return true
End of InitUART3

UART3_TXRX_ISR
Responds to both transmit and receive flags from the UART3 pins

// If we were brought here because of a transmit flag, do transmit ISR


// Clear the TX interrupt by setting TXIC in UARTICR
// If we still have bytes to send
// Write new data to register (UARTDR: UART data register)
// Increment number of bytes sent
// Else
// Clear byte index
// Post EV_TX_COMPLETE to this service
// Endif
// Else we were brought here by a receive flag, so do receive ISR
// Clear the RX interrupt by setting the RXIC bit
// Do nothing since we do not need to receive information from the PIC
// Endif
End of UART3_TXRX_ISR

End of PIC_UARTService

Vous aimerez peut-être aussi