UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
demo_cw.c
1 /* firmware.h contains all relevant headers */
2 #include "../firmware.h"
3 
4 #include <stdio.h>
5 
6 static const registerSetting_t preferredSettings_cw[]=
7 {
8  {CC112X_IOCFG3, 0x59},
9  {CC112X_IOCFG2, 0x13},
10  {CC112X_IOCFG1, 0xB0},
11  {CC112X_IOCFG0, 0x06},
12  {CC112X_SYNC_CFG1, 0x08},
13  {CC112X_DEVIATION_M, 0xB4},
14  {CC112X_MODCFG_DEV_E, 0x0A},
15  {CC112X_DCFILT_CFG, 0x1C},
16  {CC112X_PREAMBLE_CFG1, 0x00},
17  {CC112X_FREQ_IF_CFG, 0x35},
18  {CC112X_IQIC, 0xC6},
19  {CC112X_CHAN_BW, 0x10},
20  {CC112X_MDMCFG1, 0x06},
21  {CC112X_MDMCFG0, 0x05},
22  {CC112X_SYMBOL_RATE2, 0x40},
23  {CC112X_SYMBOL_RATE1, 0x62},
24  {CC112X_SYMBOL_RATE0, 0x4E},
25  {CC112X_AGC_REF, 0x20},
26  {CC112X_AGC_CS_THR, 0x19},
27  {CC112X_AGC_CFG1, 0xA9},
28  {CC112X_AGC_CFG0, 0xCF},
29  {CC112X_FIFO_CFG, 0x00},
30  {CC112X_SETTLING_CFG, 0x03},
31  {CC112X_FS_CFG, 0x1B},
32  {CC112X_PKT_CFG2, 0x05},
33  {CC112X_PKT_CFG1, 0x00},
34  {CC112X_PKT_CFG0, 0x20},
35  {CC112X_PA_CFG2, 0x34},
36  {CC112X_PA_CFG0, 0x7E},
37  {CC112X_IF_MIX_CFG, 0x00},
38  {CC112X_FREQOFF_CFG, 0x22},
39  {CC112X_CFM_DATA_CFG, 0x01},
40  {CC112X_FREQ2, 0x5A},
41  {CC112X_FREQ1, 0xEF},
42  {CC112X_FREQ0, 0xFF},
43  {CC112X_IF_ADC0, 0x05},
44  {CC112X_FS_DIG1, 0x00},
45  {CC112X_FS_DIG0, 0x5F},
46  {CC112X_FS_CAL0, 0x0E},
47  {CC112X_FS_DIVTWO, 0x03},
48  {CC112X_FS_DSM0, 0x33},
49  {CC112X_FS_DVC0, 0x17},
50  {CC112X_FS_PFD, 0x50},
51  {CC112X_FS_PRE, 0x6E},
52  {CC112X_FS_REG_DIV_CML, 0x14},
53  {CC112X_FS_SPARE, 0xAC},
54  {CC112X_XOSC5, 0x0E},
55  {CC112X_XOSC3, 0xC7},
56  {CC112X_XOSC1, 0x07},
57  {CC112X_SERIAL_STATUS, 0x08},
58 };
59 
60 #define UART_INTERFACE UART_CAMERA
61 
62 static double freq = 145.5;
63 static double pwr = 10.0;
64 
65 static uint8_t buffer[17] = "UOS3 UOS3 UOS3 k\0";
66 static uint32_t buffer_length = 16;
67 
68 static void cw_tone_on(void)
69 {
70  uint8_t pwr_reg;
71 
72  radio_reset_config(SPI_RADIO_TX, preferredSettings_cw, sizeof(preferredSettings_cw)/sizeof(registerSetting_t));
73  manualCalibration(SPI_RADIO_TX);
74 
75  radio_set_freq_f(SPI_RADIO_TX, &freq);
76 
77  radio_set_pwr_f(SPI_RADIO_TX, &pwr, &pwr_reg);
78 
79  SPI_cmd(SPI_RADIO_TX, CC112X_STX);
80 
81  LED_on(LED_B);
82 }
83 
84 static void cw_tone_off(void)
85 {
86  radio_reset_config(SPI_RADIO_TX, preferredSettings_cw, sizeof(preferredSettings_cw)/sizeof(registerSetting_t));
87 
88  LED_off(LED_B);
89 }
90 
91 int main(void)
92 {
93  char output[100];
94 
95  Board_init();
96 
97  UART_init(UART_INTERFACE, 9600);
98  UART_puts(UART_INTERFACE, "\r\nCW Radio Demo\r\n");
99 
100  sprintf(output,"Freq: %.3fMHz, Power: %+.1fdBmW\r\n", freq, pwr);
101  UART_puts(UART_INTERFACE, output);
102 
103  while(1)
104  {
105  sprintf(output,"Sending Beacon :\"%s\"\r\n", buffer);
106  UART_puts(UART_INTERFACE, output);
107 
108  Packet_cw_transmit_buffer(buffer, buffer_length, cw_tone_on, cw_tone_off);
109  UART_puts(UART_INTERFACE, "Sent.\r\n");
110 
111  Delay_ms(3000);
112  }
113 }
void Delay_ms(uint32_t milliseconds)
Definition: delay.c:19
void UART_init(uint8_t uart_num, uint32_t baudrate)
Definition: uart.c:78
void LED_off(uint8_t led_num)
Definition: led.c:20
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
uint8_t SPI_cmd(uint8_t spi_num, uint8_t cmd)
Definition: spi.c:15
void LED_on(uint8_t led_num)
Definition: led.c:15