MAXREFDES62# Code Documentation  V01.00
RS-485 Micro PLC
 All Files Functions Variables Macros Pages
main.c
Go to the documentation of this file.
1 
28 /*
29 * Copyright (C) 2012 Maxim Integrated Products, Inc., 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 /* Includes ------------------------------------------------------------------*/
76 #include "stm32f10x.h"
77 #include "stm32f10x_gpio.h"
78 #include "stm32f10x_rcc.h"
79 #include "stm32f10x_usart.h"
80 #include "stm32f10x_spi.h"
81 #include "init_config.h"
82 #include "menu.h"
83 #include "utilities.h"
85 #include <stdio.h>
86 
87 
88 /* Private typedef -----------------------------------------------------------*/
89 /* Private define ------------------------------------------------------------*/
90 #define MAJOR_REVISION 01
91 #define MINOR_REVISION 00
92 /* Private macro -------------------------------------------------------------*/
93 /* Private variables ---------------------------------------------------------*/
94 /* Private function prototypes -----------------------------------------------*/
95 /* Private functions ---------------------------------------------------------*/
96 
105 int main(void)
106 {
107  int n_menu_state=MAIN_MENU;
108  uint8_t uch_first_entry=1;
109  uint8_t uch_input;
110 
111  maxim_gpio_init();
112  maxim_uart_init();
113 
114  // Clear the Screen, and then display the big Maxim banner for about 2 seconds
115  maxim_menu_cls();
117  printf("Maxim MAXREFDES62#\r\n");
118  printf("Revision v%d.%d\r\n",MAJOR_REVISION,MINOR_REVISION);
119 
120  maxim_delay(2*ONE_SECOND); //2 second pause
121 
122  while(1)
123  {
124  switch(n_menu_state)
125  {
126  case MAIN_MENU:
127  maxim_menu_cls();
129  do{
130  if(uch_first_entry==1)
131  {
132  if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET)
133  {
134  maxim_delay(ONE_SECOND); //1 sec pause
135  }
136  if(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET)
137  {
138  maxim_delay(ONE_SECOND); //1 sec pause
139  n_menu_state = MAIN_MENU;
140  break;
141  }
142  }
143  uch_first_entry=0;
144  uch_input = getchar();
145  printf("%c\r\n",uch_input);
146  if(uch_input<='1')
147  {
148  if(uch_input=='0')
149  {
150  n_menu_state = START_CONTINUOUS_KEYPRESS;
151  }
152  else
153  {
154  n_menu_state = START_SEND_FILE;
155  }
156  }
157  }while(uch_input>'1' || uch_input<'0');
158  break;
159 
163  while(uch_input!=0x1B)
164  {
165  uch_input=getchar();
166  if(uch_input==0x1B) //if the input is ESC key
167  n_menu_state = MAIN_MENU;
168  else
169  {
170  if(maxim_keypress_loopback(uch_input)==PASS)
171  printf("\r\nLoopback test PASSED\r\n");
172  else
173  printf("\r\nLoopback test FAILED\r\n");
174  }
175  }
176  break;
177 
178  case START_SEND_FILE:
181  printf("\r\nLoopback test PASSED\r\n");
182  else
183  printf("\r\nLoopback test FAILED\r\n");
184  printf("Press any key to return to the main menu\r\n");
185  getchar();
186  n_menu_state = MAIN_MENU;
187  break;
188 
189 
190  default:
191  printf("\n\rInvalid Keypress, please try again\r\n");
193  n_menu_state = MAIN_MENU;
194  break;
195  }
196  }
197 }
198 
199 #ifdef USE_FULL_ASSERT
200 
208 void assert_failed(uint8_t* file, uint32_t line)
209 {
210  /* User can add his own implementation to report the file name and line number,
211  ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
212 
213  /* Infinite loop */
214  while (1)
215  {
216  }
217 }
218 
219 #endif
220 
229 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/