1 | |
---|
2 | #include "xparameters.h" |
---|
3 | #include "stdio.h" |
---|
4 | #include "sleep.h" |
---|
5 | #include "radio_controller_basic.h" |
---|
6 | #include "radio_controller_ext.h" |
---|
7 | #include "radio_controller_adv.h" |
---|
8 | #include "radio_controller_5ghz.h" |
---|
9 | #include "EEPROM.h" |
---|
10 | #include "warp_v4_userio.h" |
---|
11 | #include "xgpio.h" |
---|
12 | |
---|
13 | #define USERIO_BASEADDR XPAR_USERIO_BASEADDR |
---|
14 | #define CAPTURE_PERIOD XPAR_PRNG_USERIOSRC_PLBW_0_MEMMAP_CAPTUREPERIOD |
---|
15 | #define CAPTURED_OUTPUT XPAR_PRNG_USERIOSRC_PLBW_0_MEMMAP_CAPTUREDOUTPUT |
---|
16 | |
---|
17 | void userio_init(); |
---|
18 | int radio_init(); |
---|
19 | void userio_example(); |
---|
20 | |
---|
21 | //Assume a 2-radio kit, with WARP Radio Boards v1.4 in slots 2 and 3 |
---|
22 | unsigned int radios = RADIO2_ADDR | RADIO3_ADDR; |
---|
23 | |
---|
24 | int main() { |
---|
25 | |
---|
26 | print("\f"); |
---|
27 | print("WARP v2 Template Project - Example Application\n"); |
---|
28 | |
---|
29 | userio_init(); |
---|
30 | radio_init(); |
---|
31 | userio_example(); |
---|
32 | |
---|
33 | return 0; |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | //Simple demonstration of the user IO on FPGA Board v2 |
---|
38 | // This function runs forever, reading the user inputs (DIP switch and push buttons) |
---|
39 | // and updating the user outputs (hex displays and LEDs) based on the inputs |
---|
40 | //Remember the "down" button (SW6) is tied to the PPC reset |
---|
41 | void userio_example() { |
---|
42 | |
---|
43 | unsigned int assertedInputs; |
---|
44 | |
---|
45 | u16 capturedValue; |
---|
46 | u8 i,allowPrint; |
---|
47 | |
---|
48 | /* |
---|
49 | * We use allowPrint as a simple software "latch" to avoid unnecessary prints to the UART. |
---|
50 | * When the user presses and holds the "up" pushbutton on the board, this code will print |
---|
51 | * the binary string of the output of the custom core's LFSR. When the user releases the |
---|
52 | * pushbutton, this code will print a series of backspaces to delete the previous print. |
---|
53 | */ |
---|
54 | allowPrint = 1; |
---|
55 | |
---|
56 | /* |
---|
57 | * The CAPTURE_PERIOD definition simply abstracts away the address of the "capturePeriod" |
---|
58 | * register that was created in the underlying custom pcore. XIo_Out32 is a simple macro |
---|
59 | * that Xilinx provides that lets us write values to that memory address. In this function, |
---|
60 | * we write a value that will ensure that the USER I/O LEDs are updated at 10 times per second. |
---|
61 | * Reduce this value to increase the speed of the updates and increase it to slow it down further. |
---|
62 | */ |
---|
63 | XIo_Out32(CAPTURE_PERIOD,8000000-1); |
---|
64 | |
---|
65 | xil_printf("\t Red LEDs ------- ------- Green LEDs\n"); |
---|
66 | xil_printf("\tPRNG Captured Value: "); |
---|
67 | |
---|
68 | /* |
---|
69 | * This while loop will run forever. There is no exit condition to break out of this loop. |
---|
70 | * This loop will continually read from the User I/O core to determine if any pushbuttons |
---|
71 | * are currently being pressed. If so, it triggers a small loop to print out the output |
---|
72 | * of the custom pcore's capturedOutput register. This inner loop is simply to display |
---|
73 | * the output as a binary string. |
---|
74 | */ |
---|
75 | while(1){ |
---|
76 | |
---|
77 | //Read the GPIO inputs; each 1 is a currently-asserted input bit |
---|
78 | assertedInputs = WarpV4_UserIO_PushB(USERIO_BASEADDR) | (WarpV4_UserIO_DipSw(USERIO_BASEADDR) << 4); |
---|
79 | |
---|
80 | if(assertedInputs & USERIO_MASK_PBU){ |
---|
81 | if(allowPrint){ |
---|
82 | capturedValue = XIo_In32(CAPTURED_OUTPUT); |
---|
83 | xil_printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); |
---|
84 | for (i=0;i<16;i++){ |
---|
85 | xil_printf("%d ", (capturedValue>>(15-i))&1); |
---|
86 | } |
---|
87 | allowPrint = 0; |
---|
88 | } |
---|
89 | } else if(!allowPrint) { |
---|
90 | xil_printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); |
---|
91 | xil_printf(" "); |
---|
92 | allowPrint = 1; |
---|
93 | } |
---|
94 | } |
---|
95 | xil_printf("\n"); |
---|
96 | return; |
---|
97 | } |
---|
98 | |
---|
99 | void userio_init() { |
---|
100 | |
---|
101 | //Set all hex displays to auto-map mode |
---|
102 | WarpV4_UserIO_NumberMode_LeftHex(USERIO_BASEADDR); |
---|
103 | WarpV4_UserIO_NumberMode_MiddleHex(USERIO_BASEADDR); |
---|
104 | WarpV4_UserIO_NumberMode_RightHex(USERIO_BASEADDR); |
---|
105 | |
---|
106 | //Set all hex displays to show "0" |
---|
107 | WarpV4_UserIO_WriteNumber_LeftHex(USERIO_BASEADDR, 0, 0); |
---|
108 | WarpV4_UserIO_WriteNumber_MiddleHex(USERIO_BASEADDR, 0, 0); |
---|
109 | WarpV4_UserIO_WriteNumber_RightHex(USERIO_BASEADDR, 0, 0); |
---|
110 | |
---|
111 | //Turn off all user LEDs |
---|
112 | WarpV4_UserIO_Leds(USERIO_BASEADDR, 0); |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | int radio_init() { |
---|
117 | //Initialize the radio transceivers |
---|
118 | WarpRadio_v1_Reset((unsigned int*)XPAR_RADIO_CONTROLLER_0_BASEADDR, 2); |
---|
119 | |
---|
120 | //Set some sane defaults for the MAX2829 transceivers |
---|
121 | WarpRadio_v1_SetCenterFreq2GHz(11, radios); |
---|
122 | WarpRadio_v1_SoftwareTxGainControl(1, radios); |
---|
123 | WarpRadio_v1_SoftwareRxGainControl(1, radios); |
---|
124 | WarpRadio_v1_RxHpSoftControlEnable(radios); |
---|
125 | WarpRadio_v1_RxLpfCornFreqCoarseAdj(1, radios); |
---|
126 | WarpRadio_v1_TxLpfCornFreqCoarseAdj(1, radios); |
---|
127 | |
---|
128 | //Ensure both transceivers are in standby (no Tx or Rx) |
---|
129 | WarpRadio_v1_TxRxDisable(radios); |
---|
130 | |
---|
131 | return 0; |
---|
132 | } |
---|