MAXREFDES71# Code Documentation  V01.00
MAXREFDES71# 2-Channel Analog Input/Analog Output
 All Data Structures Files Functions Variables Macros Pages
MAXREFDES71.c
Go to the documentation of this file.
1 
29 /*
30  * Copyright (C) 2012 Maxim Integrated Products, Inc., All Rights Reserved.
31  *
32  * Permission is hereby granted, free of charge, to any person obtaining a
33  * copy of this software and associated documentation files (the "Software"),
34  * to deal in the Software without restriction, including without limitation
35  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
36  * and/or sell copies of the Software, and to permit persons to whom the
37  * Software is furnished to do so, subject to the following conditions:
38  *
39  * The above copyright notice and this permission notice shall be included
40  * in all copies or substantial portions of the Software.
41  *
42  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
43  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45  * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
46  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
47  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
48  * OTHER DEALINGS IN THE SOFTWARE.
49  *
50  * Except as contained in this notice, the name of Maxim Integrated Products
51  * shall not be used except as stated in the Maxim Integrated Products
52  * Branding Policy.
53  *
54  * The mere transfer of this software does not imply any licenses
55  * of trade secrets, proprietary technology, copyrights, patents,
56  * trademarks, maskwork rights, or any other form of intellectual
57  * property whatsoever. Maxim Integrated Products retains all ownership rights.
58  *
59  ***************************************************************************/
76 #include "xparameters.h" /* EDK generated parameters */
77 #include "stdio.h"
78 #include "platform.h"
79 #include "menu.h"
80 #include "utilities.h"
82 #include "MAXREFDES71.h"
83 #include "axi_millbrae.h"
84 
85 #define MAJOR_REVISION 01
86 #define MINOR_REVISION 00
87 
88 
89 // Globals
90 char g_sInputString[ INPUT_STRING_MAX_SIZE ]; //This string will hold user input from terminal.
91  XGpio g_xGpioLed;
93 char g_tempString[32];
94 
95 u8 font[1024] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x00, NUL
96  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x01, SOH
97  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x02, STX
98  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x03, ETX
99  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x03, EOT
100  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x05, ENQ
101  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x06, ACK
102  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x07, BEL
103  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x08, BS
104  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x09, HT
105  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0A, LF
106  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0B, VT
107  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0C, FF
108  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0D, CR
109  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0E, SO
110  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x0F, SI
111  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x10, DLE
112  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x11, DC1
113  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x12, DC2
114  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x13, DC3
115  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x13, DC4
116  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x15, NAK
117  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x16, SYN
118  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x17, ETB
119  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x18, CAN
120  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x19, EM
121  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1A, SUB
122  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1B, ESC
123  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1C, FS
124  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1D, GS
125  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1E, RS
126  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x1F, US
127  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 0x20, space
128  0x00,0x00,0x00,0x5f,0x00,0x00,0x00,0x00, // 0x21, !
129  0x00,0x00,0x03,0x00,0x03,0x00,0x00,0x00, // 0x22, "
130  0x64,0x3c,0x26,0x64,0x3c,0x26,0x24,0x00, // 0x23, #
131  0x26,0x49,0x49,0x7f,0x49,0x49,0x32,0x00, // 0x23, $
132  0x42,0x25,0x12,0x08,0x24,0x52,0x21,0x00, // 0x25, %
133  0x20,0x50,0x4e,0x55,0x22,0x58,0x28,0x00, // 0x26, &
134  0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00, // 0x27, '
135  0x00,0x00,0x1c,0x22,0x41,0x00,0x00,0x00, // 0x28, (
136  0x00,0x00,0x00,0x41,0x22,0x1c,0x00,0x00, // 0x29, )
137  0x00,0x15,0x15,0x0e,0x0e,0x15,0x15,0x00, // 0x2A, *
138  0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00, // 0x2B, +
139  0x00,0x00,0x00,0x50,0x30,0x00,0x00,0x00, // 0x2C, ,
140  0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00, // 0x2D, -
141  0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, // 0x2E, .
142  0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00, // 0x2F, /
143  0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, // 0x30, 0
144  0x00,0x00,0x41,0x7f,0x40,0x00,0x00,0x00, // 0x31, 1
145  0x00,0x42,0x61,0x51,0x49,0x6e,0x00,0x00, // 0x32, 2
146  0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00, // 0x33, 3
147  0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x00, // 0x33, 4
148  0x00,0x27,0x49,0x49,0x49,0x71,0x00,0x00, // 0x35, 5
149  0x00,0x3c,0x4a,0x49,0x48,0x70,0x00,0x00, // 0x36, 6
150  0x00,0x43,0x21,0x11,0x0d,0x03,0x00,0x00, // 0x37, 7
151  0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, // 0x38, 8
152  0x00,0x06,0x09,0x49,0x29,0x1e,0x00,0x00, // 0x39, 9
153  0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00, // 0x3A, :
154  0x00,0x00,0x00,0x52,0x30,0x00,0x00,0x00, // 0x3B, //
155  0x00,0x00,0x08,0x14,0x14,0x22,0x00,0x00, // 0x3C, <
156  0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00, // 0x3D, =
157  0x00,0x00,0x22,0x14,0x14,0x08,0x00,0x00, // 0x3E, >
158  0x00,0x02,0x01,0x59,0x05,0x02,0x00,0x00, // 0x3F, ?
159  0x3e,0x41,0x5d,0x55,0x4d,0x51,0x2e,0x00, // 0x40, @
160  0x40,0x7c,0x4a,0x09,0x4a,0x7c,0x40,0x00, // 0x41, A
161  0x41,0x7f,0x49,0x49,0x49,0x49,0x36,0x00, // 0x42, B
162  0x1c,0x22,0x41,0x41,0x41,0x41,0x22,0x00, // 0x43, C
163  0x41,0x7f,0x41,0x41,0x41,0x22,0x1c,0x00, // 0x44, D
164  0x41,0x7f,0x49,0x49,0x5d,0x41,0x63,0x00, // 0x45, E
165  0x41,0x7f,0x49,0x09,0x1d,0x01,0x03,0x00, // 0x46, F
166  0x1c,0x22,0x41,0x49,0x49,0x3a,0x08,0x00, // 0x47, G
167  0x41,0x7f,0x08,0x08,0x08,0x7f,0x41,0x00, // 0x48, H
168  0x00,0x41,0x41,0x7F,0x41,0x41,0x00,0x00, // 0x49, I
169  0x30,0x40,0x41,0x41,0x3F,0x01,0x01,0x00, // 0x4A, J
170  0x41,0x7f,0x08,0x0c,0x12,0x61,0x41,0x00, // 0x4B, K
171  0x41,0x7f,0x41,0x40,0x40,0x40,0x60,0x00, // 0x4C, L
172  0x41,0x7f,0x42,0x0c,0x42,0x7f,0x41,0x00, // 0x4D, M
173  0x41,0x7f,0x42,0x0c,0x11,0x7f,0x01,0x00, // 0x4E, N
174  0x1c,0x22,0x41,0x41,0x41,0x22,0x1c,0x00, // 0x4F, O
175  0x41,0x7f,0x49,0x09,0x09,0x09,0x06,0x00, // 0x50, P
176  0x0c,0x12,0x21,0x21,0x61,0x52,0x4c,0x00, // 0x51, Q
177  0x41,0x7f,0x09,0x09,0x19,0x69,0x46,0x00, // 0x52, R
178  0x66,0x49,0x49,0x49,0x49,0x49,0x33,0x00, // 0x53, S
179  0x03,0x01,0x41,0x7f,0x41,0x01,0x03,0x00, // 0x54, T
180  0x01,0x3f,0x41,0x40,0x41,0x3f,0x01,0x00, // 0x55, U
181  0x01,0x0f,0x31,0x40,0x31,0x0f,0x01,0x00, // 0x56, V
182  0x01,0x1f,0x61,0x14,0x61,0x1f,0x01,0x00, // 0x57, W
183  0x41,0x41,0x36,0x08,0x36,0x41,0x41,0x00, // 0x58, X
184  0x01,0x03,0x44,0x78,0x44,0x03,0x01,0x00, // 0x59, Y
185  0x43,0x61,0x51,0x49,0x45,0x43,0x61,0x00, // 0x5A, Z
186  0x00,0x00,0x7f,0x41,0x41,0x00,0x00,0x00, // 0x5B, [
187  0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x00, // 0x5C,
188  0x00,0x00,0x41,0x41,0x7f,0x00,0x00,0x00, // 0x5D, ]
189  0x00,0x04,0x02,0x01,0x01,0x02,0x04,0x00, // 0x5E, ^
190  0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00, // 0x5F, _
191  0x00,0x01,0x02,0x00,0x00,0x00,0x00,0x00, // 0x60, `
192  0x00,0x34,0x4a,0x4a,0x4a,0x3c,0x40,0x00, // 0x61, a
193  0x00,0x41,0x3f,0x48,0x48,0x48,0x30,0x00, // 0x62. b
194  0x00,0x3c,0x42,0x42,0x42,0x24,0x00,0x00, // 0x63, c
195  0x00,0x30,0x48,0x48,0x49,0x3f,0x40,0x00, // 0x63, d
196  0x00,0x3c,0x4a,0x4a,0x4a,0x2c,0x00,0x00, // 0x65, e
197  0x00,0x00,0x48,0x7e,0x49,0x09,0x00,0x00, // 0x66, f
198  0x00,0x26,0x49,0x49,0x49,0x3f,0x01,0x00, // 0x67, g
199  0x41,0x7f,0x48,0x04,0x44,0x78,0x40,0x00, // 0x68, h
200  0x00,0x00,0x44,0x7d,0x40,0x00,0x00,0x00, // 0x69, i
201  0x00,0x00,0x40,0x44,0x3d,0x00,0x00,0x00, // 0x6A, j
202  0x41,0x7f,0x10,0x18,0x24,0x42,0x42,0x00, // 0x6B, k
203  0x00,0x40,0x41,0x7f,0x40,0x40,0x00,0x00, // 0x6C, l
204  0x42,0x7e,0x02,0x7c,0x02,0x7e,0x40,0x00, // 0x6D, m
205  0x42,0x7e,0x44,0x02,0x42,0x7c,0x40,0x00, // 0x6E, n
206  0x00,0x3c,0x42,0x42,0x42,0x3c,0x00,0x00, // 0x6F, o
207  0x00,0x41,0x7f,0x49,0x09,0x09,0x06,0x00, // 0x70, p
208  0x00,0x06,0x09,0x09,0x49,0x7f,0x41,0x00, // 0x71, q
209  0x00,0x42,0x7e,0x44,0x02,0x02,0x04,0x00, // 0x72, r
210  0x00,0x64,0x4a,0x4a,0x4a,0x36,0x00,0x00, // 0x73, s
211  0x00,0x04,0x3f,0x44,0x44,0x20,0x00,0x00, // 0x73, t
212  0x00,0x02,0x3e,0x40,0x40,0x22,0x7e,0x40, // 0x75, u
213  0x02,0x0e,0x32,0x40,0x32,0x0e,0x02,0x00, // 0x76, v
214  0x02,0x1e,0x62,0x18,0x62,0x1e,0x02,0x00, // 0x77, w
215  0x42,0x62,0x14,0x08,0x14,0x62,0x42,0x00, // 0x78, x
216  0x01,0x43,0x45,0x38,0x05,0x03,0x01,0x00, // 0x79, y
217  0x00,0x46,0x62,0x52,0x4a,0x46,0x62,0x00, // 0x7A, z
218  0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00, // 0x7B, {
219  0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00, // 0x7C, |
220  0x00,0x00,0x00,0x41,0x36,0x08,0x00,0x00, // 0x7D, }
221  0x00,0x18,0x08,0x08,0x10,0x10,0x18,0x00, // 0x7E, ~
222  0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55 // 0x7F, DEL
223  };
224 
225 u32 g_unSampleSize = 65536;
227 
228 
229 int main(void)
240 {
241  // Variables for the main() function
242  u8 uchInput=0;
243  int nMenuState=0; // Go to Channel Select Menu First
244 
245  u16 auSamplesCh1[1048576]; //stores the samples
246  u16 auSamplesCh2[1048576]; //stores the samples
247  u32 unNumberOfSamplesReceived;
248 
249  char tempString[30];
250 
251  // Xilinx provided utility to initialize the hardware/firmware drivers and enable/disable cache
252  init_platform();
253 
254  // Clear the Hyperterminal screen by sending printf("\033[2J");
255  menu_cls();
256 
257  // Toggle the LEDs so that the user knows the board is awake
258  XGpio_Initialize(&g_xGpioLed, XPAR_AXI_GPIO_LED_DEVICE_ID);
259  XGpio_SetDataDirection(&g_xGpioLed, 1, 0x00000000); // Set the LED peripheral to outputs
261 
262  // Initialize the OLED Data structure, the underlying hardware, ...
263  // ...and pass a pointer to the active 8x8 pixel font
265 
266  // Print Welcome Message on OLED
268  sprintf(tempString,"MAXIM INTEGRATED");
269  printfToOLED(0,0,tempString);
270  sprintf(tempString,"REFERENCE DESIGN");
271  printfToOLED(0,1,tempString);
272  sprintf(tempString,"Revision %02d.%02d\r\n",MAJOR_REVISION,MINOR_REVISION);
273  printfToOLED(0,2,tempString);
274  sprintf(tempString, " ");
275  printfToOLED(0,3,tempString);
276 
277  // Clear the Screen, and then display the big Maxim banner for about 2 seconds
278  menu_cls();
280  printf("Maxim MAXREFDES71# for the ZedBoard\r\n");
281  printf("Revision v%d.%d\r\n",MAJOR_REVISION,MINOR_REVISION);
282 
283  delay(ABOUT_ONE_SECOND * 3);
284 
285  /* The main menu loop runs infinitely to display an output similar to the following:
286  *
287  * Press a number to select sampling mode:
288  * {0} ADC Conversion
289  * {1} Signal Replication
290  *
291  >>
292 
293  The main menu is printed to the screen, and then a blocking call to retrieve a single keypress from the UART is issued.
294  The result of that keypress is used to select the sampling mode
295  */
296  while(1)
297  {
298  int nSelectedMode;
299  int nSelectedChannel;
300  int nSelectedRepRate;
301  switch(nMenuState)
302  {
303  case MAIN_MENU:
304  menu_cls();
306  do{
308  printf("%c",uchInput);
309  if(uchInput<=1)
310  {
311  if(uchInput==0)
312  {
313  nMenuState = ADC_MENU;
314  }
315  else
316  {
317  nMenuState = REP_RATE_MENU;
318  }
319  }
320  }while(uchInput>1);
321  break;
322  case REP_RATE_MENU:
323  menu_cls();
325  do{
327  printf("%c",uchInput);
328  nSelectedRepRate=uchInput;
329  }while(uchInput>4);
330  signal_replication(nSelectedRepRate);
331  nMenuState = MAIN_MENU;
332  break;
333 
334  case ADC_MENU:
335  menu_cls();
337  do{
339  printf("%c",uchInput);
340  if(uchInput<=1)
341  {
342  nMenuState = MENU_CHANNEL;
343  if(uchInput==0)
344  {
345  nSelectedMode = START_CONTINUOUS_SAMPLING;
346  }
347  else
348  {
349  nSelectedMode = MENU_SAMPLE_SPEED;
350  }
351  }
352  }while(uchInput>1);
353  break;
354 
355  case MENU_CHANNEL:
356  menu_cls();
358  do{
360  printf("%c",uchInput);
361  if(uchInput<=8)
362  {
363  nMenuState = nSelectedMode;
364  nSelectedChannel=uchInput;
365  }
366  }while(uchInput>8);
367  break;
368 
369  case MENU_SAMPLE_SPEED:
370  menu_cls();
372  do{
374  printf("%c",uchInput);
375  if(uchInput<=5)
376  {
377  g_nSampleRate=uchInput;
378  }
379  }while(uchInput>5);
380  nMenuState = MENU_SAMPLE_SIZE;
381  break;
382 
383  case MENU_SAMPLE_SIZE:
384  menu_cls();
386  do{
388  printf("%c",uchInput);
389  if(uchInput<=3)
390  {
391  if(uchInput==0)
392  g_unSampleSize=65536;
393  else if(uchInput==1)
394  g_unSampleSize=131072;
395  else if(uchInput==2)
396  g_unSampleSize=524288;
397  else
398  g_unSampleSize=1048576;
399  }
400  }while(uchInput>3);
401  nMenuState = START_BLOCK_SAMPLING;
402  break;
403 
405  menu_cls();
406  continuous_sampling(nSelectedChannel);
407  nMenuState=MAIN_MENU;
408  break;
409 
411  menu_cls();
412  printf("Press the ESC key to stop sampling\n\n");
413  printf("Sampling...\n");
414  unNumberOfSamplesReceived=start_sampling(g_unSampleSize, g_nSampleRate, auSamplesCh1, auSamplesCh2);
415  printf("Done sampling. Data are stored in the \"Samples\" array\n");
416  printf("Do you want to read the sampled data? (Y/N) \n>>");
417  do{
418 
420  printf("%c",uchInput);
421  nMenuState=MAIN_MENU;
422  if(uchInput=='y' || uchInput=='Y')
423  {
424  u32 i;
425  menu_cls();
426  printf("Press the ESC key to stop reading back the data\n\n");
428  if(nSelectedChannel<2)
429  {
430  u16 *auSamples;
431  if(nSelectedChannel==0)
432  auSamples=auSamplesCh1;
433  else if(nSelectedChannel==1)
434  auSamples=auSamplesCh2;
435  printf("Channel %i\n", nSelectedChannel);
436  for(i=0; i<unNumberOfSamplesReceived; i++)
437  {
438  if(uchInput==0x1B)
439  break;
440  if((Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x2C) & 0x02) == 0)
441  {
442  uchInput = Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x30); // read the FIFO (only the LSB is valid).
443  if(uchInput==0x1B)
444  break;
445  }
446  printf("%i\n", auSamples[i]);
447  }
448  }
449  else
450  {
451  printf("Ch 1, Ch 2\n");
452  for(i=0; i<unNumberOfSamplesReceived; i++)
453  {
454  if(uchInput==0x1B)
455  break;
456  if((Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x2C) & 0x02) == 0)
457  {
458  uchInput = Xil_In32(XPAR_PS7_UART_1_BASEADDR+0x30); // read the FIFO (only the LSB is valid).
459  if(uchInput==0x1B)
460  break;
461  }
462  printf("%i, %i\n", auSamplesCh1[i], auSamplesCh2[i]);
463  }
464  }
465 
466  if(i!=unNumberOfSamplesReceived) //if the Escape key is pressed before the for loop is finished
467  break; //go back to the main menu
468  printf("End of samples. Press any key to go back to the main menu\n");
469  nMenuState=MAIN_MENU;
471  break;
472  }
473  }while(uchInput!='n' && uchInput!='y' && uchInput!='Y' && uchInput!='N');
474 
475  break;
476 
477  default:
478  printf("Invalid Keypress, please try again\r\n");
479  delay(ABOUT_ONE_SECOND * 5);
480  nMenuState = MAIN_MENU;
481  break;
482  }
483  }
484 
486  return 0;
487 }