[1833] | 1 | //Xilinx SDK includes |
---|
| 2 | #include "xparameters.h" |
---|
| 3 | #include "stdio.h" |
---|
| 4 | #include "xsysmon.h" |
---|
| 5 | #include "xtmrctr.h" |
---|
| 6 | #include "xio.h" |
---|
| 7 | |
---|
| 8 | //WARP includes |
---|
| 9 | #include "w3_userio.h" |
---|
| 10 | #include "w3_ad_controller.h" |
---|
| 11 | #include "w3_clock_controller.h" |
---|
| 12 | #include "w3_iic_eeprom.h" |
---|
| 13 | #include "radio_controller.h" |
---|
| 14 | |
---|
| 15 | //Define standard macros for pcore base addresses and device IDs |
---|
| 16 | // XPAR_ names will change with instance names in hardware |
---|
| 17 | #define USERIO_BASEADDR XPAR_W3_USERIO_0_BASEADDR |
---|
| 18 | #define RC_BASEADDR XPAR_RADIO_CONTROLLER_0_BASEADDR |
---|
| 19 | #define AD_BASEADDR XPAR_W3_AD_CONTROLLER_0_BASEADDR |
---|
| 20 | #define CLK_BASEADDR XPAR_W3_CLOCK_CONTROLLER_0_BASEADDR |
---|
| 21 | #define EEPROM_BASEADDR XPAR_W3_IIC_EEPROM_0_BASEADDR |
---|
| 22 | #define DRAM_BASEADDR XPAR_DDR3_2GB_SODIMM_MPMC_BASEADDR |
---|
| 23 | #define TIMER_FREQ XPAR_XPS_TIMER_0_CLOCK_FREQ_HZ |
---|
| 24 | #define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | //Global variable definitions |
---|
| 28 | XTmrCtr TimerCounter; /* The instance of the Tmrctr Device */ |
---|
| 29 | |
---|
| 30 | int w3_node_init(); |
---|
| 31 | void userio_example(); |
---|
| 32 | void usleep(u32 duration); |
---|
| 33 | |
---|
| 34 | int main() { |
---|
| 35 | int status; |
---|
| 36 | |
---|
| 37 | xil_printf(" \f"); |
---|
| 38 | xil_printf("WARP v3 Template Project - On Board Peripherals\n"); |
---|
| 39 | |
---|
| 40 | status = w3_node_init(); |
---|
| 41 | if(status != 0) { |
---|
| 42 | xil_printf("Error in w3_node_init()! Exiting\n"); |
---|
| 43 | return -1; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | xil_printf("Board serial number: W3-a-%05d\n\n", w3_eeprom_readSerialNum(EEPROM_BASEADDR)); |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * User code goes here. As an example, |
---|
| 50 | * we provide a userio_example() function |
---|
| 51 | * that loops through 256 values and displays |
---|
| 52 | * them on the LEDs and hexadecimal displays |
---|
| 53 | * of the board. |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | xil_printf("Running User I/O Example\n"); |
---|
| 57 | userio_example(); |
---|
| 58 | |
---|
| 59 | return 0; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void userio_example() { |
---|
| 63 | int i; |
---|
| 64 | xil_printf("\tCurrent Count: 0x "); |
---|
| 65 | for(i=0; i<256; i++) { |
---|
| 66 | userio_write_hexdisp_left(USERIO_BASEADDR, i>>4); |
---|
| 67 | userio_write_hexdisp_right(USERIO_BASEADDR, i%16); |
---|
| 68 | userio_write_leds_green(USERIO_BASEADDR, i>>4); |
---|
| 69 | userio_write_leds_red(USERIO_BASEADDR, i%16); |
---|
| 70 | |
---|
| 71 | xil_printf("\b\b%02x", i); |
---|
| 72 | |
---|
| 73 | usleep(250000); |
---|
| 74 | } |
---|
| 75 | xil_printf("\n"); |
---|
| 76 | return; |
---|
| 77 | |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | int w3_node_init() { |
---|
| 81 | |
---|
| 82 | int status; |
---|
| 83 | XTmrCtr *TmrCtrInstancePtr = &TimerCounter; |
---|
| 84 | int ret = XST_SUCCESS; |
---|
| 85 | |
---|
| 86 | microblaze_enable_exceptions(); |
---|
| 87 | |
---|
| 88 | //Initialize the AD9512 clock buffers (RF reference and sampling clocks) |
---|
| 89 | status = clk_init(CLK_BASEADDR, 2); |
---|
| 90 | if(status != XST_SUCCESS) { |
---|
| 91 | xil_printf("w3_node_init: Error in clk_init (%d)\n", status); |
---|
| 92 | ret = XST_FAILURE; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | //Initialize the AD9963 ADCs/DACs |
---|
| 96 | ad_init(AD_BASEADDR, 2); |
---|
| 97 | if(status != XST_SUCCESS) { |
---|
| 98 | xil_printf("w3_node_init: Error in ad_init (%d)\n", status); |
---|
| 99 | ret = XST_FAILURE; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | //Initialize the radio_controller core and MAX2829 transceivers |
---|
| 103 | status = radio_controller_init(RC_BASEADDR, (RC_RFA | RC_RFB), 1, 1); |
---|
| 104 | if(status != XST_SUCCESS) { |
---|
| 105 | xil_printf("w3_node_init: Error in radioController_initialize (%d)\n", status); |
---|
| 106 | ret = XST_FAILURE; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | //Initialize the EEPROM read/write core |
---|
| 110 | iic_eeprom_init(EEPROM_BASEADDR, 0x64); |
---|
| 111 | if(status != XST_SUCCESS) { |
---|
| 112 | xil_printf("w3_node_init: Error in IIC_EEPROM_init (%d)\n", status); |
---|
| 113 | ret = XST_FAILURE; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /* |
---|
| 117 | * Initialize the timer counter so that it's ready to use, |
---|
| 118 | * specify the device ID that is generated in xparameters.h |
---|
| 119 | */ |
---|
| 120 | status = XTmrCtr_Initialize(TmrCtrInstancePtr, TMRCTR_DEVICE_ID); |
---|
| 121 | if (status != XST_SUCCESS) { |
---|
| 122 | xil_printf("w3_node_init: Error in XtmrCtr_Initialize (%d)\n", status); |
---|
| 123 | ret = XST_FAILURE; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * Perform a self-test to ensure that the hardware was built |
---|
| 128 | * correctly, use the 1st timer in the device (0) |
---|
| 129 | */ |
---|
| 130 | status = XTmrCtr_SelfTest(TmrCtrInstancePtr, 0); |
---|
| 131 | if (status != XST_SUCCESS) { |
---|
| 132 | ret = XST_FAILURE; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | // Set timer 0 to into a "count down" mode |
---|
| 136 | XTmrCtr_SetOptions(TmrCtrInstancePtr, 0, (XTC_DOWN_COUNT_OPTION)); |
---|
| 137 | |
---|
| 138 | return ret; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | void usleep(u32 duration){ |
---|
| 142 | XTmrCtr *TmrCtrInstancePtr = &TimerCounter; |
---|
| 143 | XTmrCtr_SetResetValue(TmrCtrInstancePtr,0,duration*(TIMER_FREQ/1000000)); |
---|
| 144 | |
---|
| 145 | XTmrCtr_Start(TmrCtrInstancePtr,0); |
---|
| 146 | |
---|
| 147 | volatile u8 isExpired = 0; |
---|
| 148 | while(isExpired!=1){ |
---|
| 149 | isExpired = XTmrCtr_IsExpired(TmrCtrInstancePtr,0); |
---|
| 150 | } |
---|
| 151 | XTmrCtr_Reset(TmrCtrInstancePtr,0); |
---|
| 152 | return; |
---|
| 153 | } |
---|
| 154 | |
---|