UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
mem_download.c
1 
2 // mem_download
3 //
4 // Suzanna Lucarotti (c) 13/9/2017
5 //
6 // for use with the UoS3 Cubesat
7 //
8 // tests downloading the various memory on the chip for SEE/Camera image/data downloading
9 
10 
11 #include "../firmware.h"
12 
13 #include "inc/hw_memmap.h"
14 #include "inc/hw_types.h"
15 
16 #include "driverlib/gpio.h"
17 #include "driverlib/pin_map.h"
18 #include "driverlib/sysctl.h"
19 
20 #include <stdlib.h>
21 #include <stdarg.h>
22 
23 #define GPS_SERIAL UART_GNSS
24 #define CAM_SERIAL UART_CAMERA
25 
26 #define DEBUG_SERIAL GPS_SERIAL
27 
28  // the useful hardware constants (only used here so not moved away as yet)
29 
31  // the actual main code
33 
34 unsigned int UART_getw(long int serial)
35  {
36  char c1=UART_getc(serial),c2=UART_getc(serial);
37  return c1|(c2<<8);
38  }
39 
40 unsigned int UART_getw4(long int serial)
41  {
42  char c1=UART_getc(serial),c2=UART_getc(serial),c3=UART_getc(serial),c4=UART_getc(serial);
43  return c1|(c2<<8)|(c3<<16)|(c4<<24);
44  }
45 
46 
47 void packet_send (char *start_addr, unsigned int len)
48  {
49  // send byte data from a given address and send down serial line DEBUG_SERIAL
50  // will hang processor if address wrong
51  // lets put a CRC check on the packet
52  // for CRC gonna use xor initially for speed of implementation
53 
54  UART_putc(DEBUG_SERIAL,'@');
55 
56  //start_addr=0;len=8;
57 
58  unsigned char x=0;
59  for (char *addr=start_addr;addr<start_addr+len;addr++)
60  {
61  unsigned int s_addr= (int) start_addr;
62  // UART_putc(DEBUG_SERIAL,s_addr&255);
63  // UART_putc(DEBUG_SERIAL,s_addr>>8);
64  // UART_putc(DEBUG_SERIAL,len&255);
65  // UART_putc(DEBUG_SERIAL,len>>8);
66 
67 
68  char c=*addr; // this may make the compiler scream, but we need to see it
69  UART_putc(DEBUG_SERIAL,c);
70  x=x ^ c;
71  }
72  UART_putc(DEBUG_SERIAL,'@');
73  UART_putc(DEBUG_SERIAL,x); // write the check byte
74 
75  }
76 
77 
78 int main(void)
79 {
80  Board_init(); // start the board
81  WDT_kick(); // kick the watchdog
82 
83 // UART at 115200, unreliable at 9600
84 
85  UART_init(DEBUG_SERIAL, 115200); UART_puts(DEBUG_SERIAL,"\n\rMEM_DEBUG\n\r");
86 
87  while(1) // infinite loop
88  {
89 /* char c;
90  char *start_addr=0x4000;
91  char *end_addr=start_addr+256;
92  for (char *addr=start_addr;addr<end_addr;addr++)
93  {
94  c=*addr; // this may make the compiler scream, but we need to see it
95  UART_putc(DEBUG_SERIAL,c);
96  }
97  UART_puts(DEBUG_SERIAL,"\n\rThat was that\n\r");
98  */
99  for (unsigned int wdt_kicker=100000;wdt_kicker>0;wdt_kicker--) // repeat this to kick wdt at correct time.
100  {
101  char c=0; // echo back to sending port
102  if (UART_getc_nonblocking(DEBUG_SERIAL,&c))
103  {
104  if (c=='@') // message from requestor for address dump
105  {
106  // UART_puts(DEBUG_SERIAL,"\r\nreceived request for address\n\r");
107  char *ad=UART_getw4(DEBUG_SERIAL);
108  unsigned int len=UART_getw(DEBUG_SERIAL);
109  // UART_putstr(DEBUG_SERIAL,"\r\nrequested address : ",ad," requested length :");
110  // UART_putstr(DEBUG_SERIAL,NULL,len,"\r\n");
111  packet_send(ad,len);
112  }
113  // else
114  // UART_putc(DEBUG_SERIAL,'.');
115  }
116  }
117  WDT_kick();
118  }
119 }
120 
121 
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
char UART_getc(uint8_t uart_num)
Definition: uart.c:113
int main(void)
Runs all module tests.
Definition: test.c:19
void UART_puts(uint8_t uart_num, char *str)
Definition: uart.c:129
void Board_init(void)
Definition: board.c:13
void WDT_kick(void)
Definition: wdt.c:19
void UART_putc(uint8_t uart_num, char c)
Definition: uart.c:121