Académique Documents
Professionnel Documents
Culture Documents
************************************************************************************
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
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.
ConstructTransmitPacket
Takes in a packet type and returns true
6
UART3_TXStart
Function to initiate transmit process to PIC. Takes in nothing and returns true
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
End of PIC_UARTService