UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
uart_passthrough_hex.c
1 
2 // UART passthrough code
3 //
4 // Suzanna Lucarotti (c) 11/8/2017
5 //
6 // for use with the UoS3 Cubesat
7 //
8 //provides debugging of hex numbers coming back from port, with serial in
9 // when connected through a terminal
10 
11 
12 #include "../firmware.h"
13 
14 #include "inc/hw_memmap.h"
15 #include "inc/hw_types.h"
16 
17 #include "driverlib/gpio.h"
18 #include "driverlib/pin_map.h"
19 #include "driverlib/sysctl.h"
20 
21 #include <stdlib.h>
22 #include <stdarg.h>
23 
24 #define GPS_SERIAL UART_GNSS
25 #define CAM_SERIAL UART_CAMERA
26 
27 #define DEBUG_PORT GPS_SERIAL
28 #define NORMAL_PORT CAM_SERIAL
29 
31  // the actual main code
33 
34 int main(void)
35 {
36  Board_init(); // start the board
37  setupwatchdoginterrupt();
38 
39 // UART at 115200, unreliable at 9600
40 
41  UART_init(CAM_SERIAL, 115200);
42  UART_init(GPS_SERIAL, 115200);
43 
44  UART_puts(DEBUG_PORT,"\n\rreset\n\r");
45 
46  while(1) // infinite loop
47  {
48  char buffer[4];
49 
50  char c; // echo back to sending port
51  if (UART_getc_nonblocking(DEBUG_PORT,&c)) {UART_putc_nonblocking(NORMAL_PORT,c); } // input
52  if (UART_getc_nonblocking(NORMAL_PORT,&c)) {//UART_putc_nonblocking(GPS_SERIAL,c);
53  int w=snprintf(buffer,4,"%x",c); //itoa(c,buffer,16);
54  if (w==1) {buffer[1]=buffer[0];buffer[1]='0';}
55  UART_putc_nonblocking(DEBUG_PORT,'.');
56  // UART_putc_nonblocking(DEBUG_PORT,'[');
57  UART_putc_nonblocking(DEBUG_PORT,buffer[0]);
58  UART_putc_nonblocking(DEBUG_PORT,buffer[1]);
59  if (c==0) UART_putc_nonblocking(DEBUG_PORT,'\n');
60  if (c==0) UART_putc_nonblocking(DEBUG_PORT,'\r');
61  // UART_putb(DEBUG_PORT,buffer,2); // using this instead slows it down, not slowing down means odd behaviour, unmatched brackets etc
62  // UART_putc_nonblocking(DEBUG_PORT,']');
63  } //output
64 
65  }
66 }
67 
68 
void UART_init(uint8_t uart_num, uint32_t baudrate)
Definition: uart.c:78
bool UART_getc_nonblocking(uint8_t uart_num, char *c)
Definition: uart.c:145
int main(void)
Runs all module tests.
Definition: test.c:19
bool UART_putc_nonblocking(uint8_t uart_num, char c)
Definition: uart.c:163
void UART_puts(uint8_t uart_num, char *str)
Definition: uart.c:129
void Board_init(void)
Definition: board.c:13