Sonoma (MAXREFDES14#) Code Documentation V01.00 Isolated EMP (Energy Measurement Processor)

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Macros Pages
MAXREFDES14.c
Go to the documentation of this file.
1
28 /*
29 * Copyright (C) 2012 Maxim Integrated Products, All Rights Reserved.
30 *
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
37 *
38 * The above copyright notice and this permission notice shall be included
39 * in all copies or substantial portions of the Software.
40 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
42 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44 * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
45 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47 * OTHER DEALINGS IN THE SOFTWARE.
48 *
49 * Except as contained in this notice, the name of Maxim Integrated Products
50 * shall not be used except as stated in the Maxim Integrated Products
51 * Branding Policy.
52 *
53 * The mere transfer of this software does not imply any licenses
54 * of trade secrets, proprietary technology, copyrights, patents,
55 * trademarks, maskwork rights, or any other form of intellectual
56 * property whatsoever. Maxim Integrated Products retains all ownership rights.
57 *
58 ***************************************************************************/
75 #include <stdio.h>
76 #include "xparameters.h"
77 #include "platform.h"
78 #include "menu.h"
79 #include "utilities.h"
80 #include "maximDeviceSpecificUtilities.h"
81 #include "MAXREFDES14.h"
82
83 #define MAJOR_REVISION 01
84 #define MINOR_REVISION 00
85
86 // Globals
87 XGpio g_xGpioSevenSegment;
88 unsigned int g_unSevenSegmentValue=0;
89 char g_sInputString[ INPUT_STRING_MAX_SIZE ]; //This string will hold user input from terminal.
90 XGpio g_xGpioPmodPortA;
91 XGpio g_xGpioPmodPortB;
92
93 XGpio g_gpButtons;
94 XGpio g_xGpioLed;
95 u8 g_PmodPortMuxSettings=0;
96
97 int main()
109 {
110 // Variables for the main() function
111 u8 uchInput=0;
112 u8 uchReadWriteOption=0;
113 int nMenuState=0;
114 char sRegInfo[3];
115 u8 uchCount=0;
116 u8 uchRegAddr;
117 u32 uchRegValue;
118 XUartLite Uart;
119
120 // Xilinx provided utility to initialize the hardware/firmware drivers and enable/disable cache
121 init_platform();
122
123 // Clear the Hyperterminal screen by sending printf("\033[2J");
124 menu_cls();
125
126 // Initialize the USB UART on the NEXYS-3 board (used to communicate with Hyperterminal)
127 XUartLite_Initialize(&Uart,DEFAULT_HYPERTERMINAL_UART_ID);
128 XUartLite_ResetFifos(&Uart);
129 delay(100);
130
131 // Toggle the LEDs so that the user knows the board is awake
132 XGpio_Initialize(&g_xGpioLed, XPAR_LEDS_4BITS_DEVICE_ID);
133 XGpio_SetDataDirection(&g_xGpioLed, 1, 0x00000000); // Set the LED peripheral to outputs
134 led_knight_rider(&g_xGpioLed,2);
135
136 // Initialize the GPIO connected to PMOD Ports A..D
137 XGpio_Initialize(&g_xGpioPmodPortA, XPAR_AXI_GPIO_0_DEVICE_ID);
138 XGpio_Initialize(&g_xGpioPmodPortB, XPAR_AXI_GPIO_1_DEVICE_ID);
139 XGpio_SetDataDirection(&g_xGpioPmodPortA, 1, 0x00000000); // Set the GPIO1 to all be outputs
140 XGpio_SetDataDirection(&g_xGpioPmodPortB, 1, 0x00000000); // Set the GPIO1 to all be outputs
141
142 // Configure the PMOD Port Multiplexers for the default PMOD interfaces (ports a,b,c,d)
143 max_configure_PMOD_port(PMOD_PORT_TYPE_SPI,PMOD_PORT_TYPE_SPI,PMOD_PORT_TYPE_GPIO,PMOD_PORT_TYPE_UART);
144
145 // Clear the Screen, and then display the big Maxim banner for about 2 seconds
146 menu_cls();
147 menu_print_maxim_banner_big();
148 printf("Maxim Sonoma (MAXREFDES14#) for the LX9 MicroBoard\r\n");
149 printf("Revision v%d.%d\r\n",MAJOR_REVISION,MINOR_REVISION);
150
151 delay(ABOUT_ONE_SECOND * 3);
152 //print_seven_segment_number(0.0f);
153
154 /* The main menu loop runs infinitely to display an output similar to the following:
155 *
156 * Press a number to select sampling mode:
157 * {0} Read Registers
158 * {1} Write Registers
159 *
160 >>
161
162 The main menu is printed to the screen, and then a blocking call to retrieve a single keypress from the UART is issued.
163 The result of that keypress is used to select the read/write mode
164 */
165 while(1)
166 {
167 switch(nMenuState)
168 {
169 case MAIN_MENU:
170 menu_cls();
171 menu_print_main_menu();
172 do{
173 uchReadWriteOption = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
174
175 xil_printf("%c\r\n\n",uchReadWriteOption);
176 uchReadWriteOption-=48;
177 if(uchReadWriteOption<=1)
178 {
179 nMenuState = MENU_REG_ADDR;
180 }
181 }while(uchReadWriteOption>1);
182 break;
183
184 case MENU_REG_ADDR:
185 xil_printf("Enter the register address in HEX (e.g. 2B)\r\nor press ESC key to go back to the main menu: ");
186 uchRegAddr=0;
187 uchInput=0;
188 for(uchCount=0; ; uchCount++)
189 {
190 sRegInfo[uchCount] = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
191 xil_printf("%c",sRegInfo[uchCount]);
192 if(!(sRegInfo[uchCount]!=0x1B && sRegInfo[uchCount]!=0x0D))
193 break;
194 }
195 if(sRegInfo[uchCount]==0x1B)
196 {
197 sRegInfo[0]=0;
198 nMenuState = MAIN_MENU;
199 break;
200 }
201 sRegInfo[uchCount]='\0';
202 if(uchReadWriteOption==0)
203 nMenuState = MENU_READ_REG;
204 else
205 nMenuState = MENU_WRITE_REG;
206 break;
207
208 case MENU_READ_REG:
209 uchRegAddr = htoi(sRegInfo);
210
211 xil_printf("\n%X\r\n\r\n",read_reg(uchRegAddr));
212
213 nMenuState = MENU_REG_ADDR;
214 break;
215
216
217 case MENU_WRITE_REG:
218 menu_cls();
219 uchRegAddr = htoi(sRegInfo);
220 xil_printf("\r\nEnter the register value in HEX (e.g. ABCD12)\r\nor press ESC key to go back to the main menu: ");
221 for(uchCount=0; ; uchCount++)
222 {
223 sRegInfo[uchCount] = menu_retrieve_keypress(DEFAULT_HYPERTERMINAL_UART_ADDRESS);
224 xil_printf("%c",sRegInfo[uchCount]);
225 if(!(sRegInfo[uchCount]!=0x1B && sRegInfo[uchCount]!=0x0D))
226 break;
227 }
228 if(sRegInfo[uchCount]==0x1B)
229 {
230 sRegInfo[0]=0;
231 nMenuState = MAIN_MENU;
232 break;
233 }
234 sRegInfo[uchCount]='\0';
235 uchRegValue = htoi(sRegInfo);
236 write_reg(uchRegAddr, uchRegValue);
237 xil_printf("\r\nRegister write complete\r\n");
238 delay(ABOUT_ONE_SECOND);
239 nMenuState = MAIN_MENU;
240 break;
241
242 default:
243 xil_printf("Invalid Keypress, please try again\r\n");
244 delay(ABOUT_ONE_SECOND * 5);
245 nMenuState = MAIN_MENU;
246 break;
247 }
248 }
249
250 cleanup_platform();
251 return 0;
252 }