UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
tx-test.c
1 /* firmware.h contains all relevant headers */
2 #include "../firmware.h"
3 
4 #include "inc/hw_memmap.h"
5 #include "driverlib/gpio.h"
6 #include "driverlib/pin_map.h"
7 #include "driverlib/ssi.h"
8 #include "driverlib/sysctl.h"
9 
10 #include "../cc1125/cc1125.h"
11 
12 
13 #define CONFIG_1
15 
16 
17 
18 
19 
20 
21 
23 
24 uint32_t pui32DataTx[10];
25 uint32_t pui32DataRx[10];
26 
27 #define PACKETLEN 100
28 
29 int main(void)
30 {
31 
32  volatile uint32_t ui32Loop;
33 
34  Board_init();
35 
36  //uint8_t rxBuffer[128] = {0};
37 
38  UART_init(UART_GNSS, 500000);
39  UART_putc(UART_GNSS, '\r');
40  UART_putc(UART_GNSS, '\n');
41  for(ui32Loop = 0; ui32Loop < 300000; ui32Loop++) {};
42 
43  UART_putc(UART_GNSS, 'M');
44 
46 
47  // Reset radio
48  // Write registers to radio
49 
50  radio_reset_config(SPI_RADIO_TX, preferredSettings_cw, sizeof(preferredSettings_cw)/sizeof(registerSetting_t));
51  radio_reset_config(SPI_RADIO_RX, preferredSettings, sizeof(preferredSettings)/sizeof(registerSetting_t));
52  /*
53  trxSpiCmdStrobe(radio_id, CC112X_SRES);
54  uint8_t writeByte;
55  for(uint16_t i = 0; i < sizeof(preferredSettings)/sizeof(registerSetting_t); i++) {
56  writeByte = preferredSettings[i].data;
57  cc112xSpiWriteReg(radio_id, preferredSettings[i].addr, &writeByte, 1);
58  }
59  */
60 
61 
62  //UART_puts(UART_GNSS, "DONE");
63  for(ui32Loop = 0; ui32Loop < 3000; ui32Loop++) {};
64 
66  manualCalibration(SPI_RADIO_TX);
67  manualCalibration(SPI_RADIO_RX);
68 
69 
70  for(ui32Loop = 0; ui32Loop < 3000; ui32Loop++) {};
71  //UART_puts(UART_GNSS, "CAL'd");
72  for(ui32Loop = 0; ui32Loop < 30000; ui32Loop++) {};
73 
75  //uint8_t buff[PACKETLEN+1];
76  //buff[0] = PACKETLEN;
77  // Fill rest of buffer with random bytes
78  //for(uint8_t i = 1; i < (PACKETLEN + 1); i++) {
79  // buff[i] = (uint8_t)i; //rand();
80  //}
81 
82 
83  // Loop forever.
84  while(1)
85  {
86 
87 
89  //cc112xSpiWriteTxFifo(RADIO_TX, buff, sizeof(buff));
90 
91  SPI_cmd(SPI_RADIO_RX, CC112X_SRX);
92 
93  // Strobe TX to send packet
94  SPI_cmd(SPI_RADIO_TX, CC112X_STX);
95 
96  while(1){
97  WDT_kick();
98  // Delay for a bit.
99  for(ui32Loop = 0; ui32Loop < 300000; ui32Loop++) {};
100 
101  }
102 
103  /*
104  // Wait for RX. If we dont get anything the WDT will kick
105  // in and we can try again later
106  UART_puts(UART_GNSS, "waiting... ");
107  // Wait for falling edge of GPIO0
108  while(pollRadioGPIO0(RADIO_RX) == 0){};
109  while(pollRadioGPIO0(RADIO_RX) > 0){};
110  UART_puts(UART_GNSS, " flag high ");
111 
112  // Read number of bytes in RX FIFO
113  uint8_t rxBytes, marcState;
114  cc112xSpiReadReg(RADIO_RX, CC112X_NUM_RXBYTES, &rxBytes, 1);
115 
116  // Check that we have bytes in FIFO
117  if(rxBytes != 0) {
118  UART_puts(UART_GNSS, "Got some bytes: ");
119  // Read MARCSTATE to check for RX FIFO error
120  cc112xSpiReadReg(RADIO_RX, CC112X_MARCSTATE, &marcState, 1);
121 
122  // Mask out MARCSTATE bits and check if we have a RX FIFO error
123  if((marcState & 0x1F) == 0x11) { //RX_FIFO_ERROR) {
124  UART_puts(UART_GNSS, "RX FIFO error :(\n");
125  // Flush RX FIFO
126  trxSpiCmdStrobe(RADIO_RX, CC112X_SFRX);
127  } else {
128 
129  // Read n bytes from RX FIFO
130  cc112xSpiReadRxFifo(RADIO_RX, rxBuffer, rxBytes);
131 
132 
133  for (uint8_t i = 0; i < rxBytes; i++)
134  UART_puts(UART_GNSS, (char *)&rxBuffer[i]);
135 
136  // Check CRC ok (CRC_OK: bit7 in second status byte)
137  // This assumes status bytes are appended in RX_FIFO
138  // (PKT_CFG1.APPEND_STATUS = 1)
139  // If CRC is disabled the CRC_OK field will read 1
140  //if(rxBuffer[rxBytes - 1] & 0x80) {
141  //
142  // // Update packet counter
143  // packetCounter++;
144  //}
145  }
146  }
147  else
148  UART_puts(UART_GNSS, "No bytes.:(");
149 
150 */
151  }
152 }
CC1120 register export from SmartRF Studio.
void UART_init(uint8_t uart_num, uint32_t baudrate)
Definition: uart.c:78
int main(void)
Runs all module tests.
Definition: test.c:19
void Board_init(void)
Definition: board.c:13
void WDT_kick(void)
Definition: wdt.c:19
uint8_t SPI_cmd(uint8_t spi_num, uint8_t cmd)
Definition: spi.c:15
void UART_putc(uint8_t uart_num, char c)
Definition: uart.c:121