-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.c
106 lines (90 loc) · 3.08 KB
/
serial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//********************************************************
//
// serial.c
//
// Support for displaying helicopter metrics via serial communication
// via 115200 baud rate
//
// Author: P.J. Bones UCECE
// Modified from uartDemo.c by: Tom Rizzi, Euan Robinson, Satwik Meravanage
// Last modified: 21 May 2021
//
//********************************************************
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/debug.h"
#include "driverlib/pin_map.h"
#include "utils/ustdlib.h"
#include "stdio.h"
#include "stdlib.h"
#include "serial.h"
#include "yaw.h"
#include "flightStates.h"
//********************************************************
// Globals to module
//********************************************************
char statusStr[MAX_STR_LEN + 1];
//********************************************************
// initSerial - 8 bits, 1 stop bit, no parity
//********************************************************
void initSerial(void)
{
//
// Enable GPIO port A which is used for UART0 pins.
//
SysCtlPeripheralEnable(UART_USB_PERIPH_UART);
SysCtlPeripheralEnable(UART_USB_PERIPH_GPIO);
//
// Select the alternate (UART) function for these pins.
//
GPIOPinTypeUART(UART_USB_GPIO_BASE, UART_USB_GPIO_PINS);
GPIOPinConfigure (GPIO_PA0_U0RX);
GPIOPinConfigure (GPIO_PA1_U0TX);
UARTConfigSetExpClk(UART_USB_BASE, SysCtlClockGet(), BAUD_RATE,
UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE);
UARTFIFOEnable(UART_USB_BASE);
UARTEnable(UART_USB_BASE);
}
//**********************************************************************
// Transmit a string via UART0
//**********************************************************************
void UARTSend (char *pucBuffer)
{
// Loop while there are more characters to send.
while(*pucBuffer)
{
// Write the next character to the UART Tx FIFO.
UARTCharPut(UART_USB_BASE, *pucBuffer);
pucBuffer++;
}
}
//**********************************************************************
// Transmit the current data values via serial
//**********************************************************************
void sendData(int32_t actualAltitude, int32_t desiredAltitude, uint32_t actualYaw,
uint32_t desiredYaw, uint32_t mainDuty, uint32_t tailDuty, uint8_t state)
{
// Send a newline
usprintf(statusStr, "-----------------\n\r");
UARTSend (statusStr);
// Send yaw
usprintf (statusStr, "Yaw: %3d [%3d] \n\r", actualYaw, desiredYaw);
UARTSend (statusStr);
// Send altitude
usprintf(statusStr, "Alt: %3d%% [%3d]\n\r", actualAltitude, desiredAltitude);
UARTSend (statusStr);
// Send main duty cycle
usprintf(statusStr, "M: %3d%% T: %3d%% \n\r", mainDuty, tailDuty);
UARTSend (statusStr);
// Send tail duty cycle
usprintf(statusStr, "Mode: %s\n\r", getStateStr(state));
UARTSend (statusStr);
}