Esempio n. 1
0
int main(void) {
	setvbuf(stdout, NULL, _IONBF, 0);


	if(!SysLogin()) {
		printf("\n\n\t\t\t\t\033[31m对不起您无权登录本系统请按任意键退出....\033[0m\n");
		getchar();
		exit(0);
	}

	Main_Menu();
	return EXIT_SUCCESS;
}
Esempio n. 2
0
int main(void) {
	setvbuf(stdout, NULL, _IONBF, 0);

/*
	if(!SysLogin()) {
		printf("\n对不起您无权登录本系统请按任意键退出......\n");
		getchar();
		exit(0);
	}*/


	Main_Menu();
	return EXIT_SUCCESS;
}
Esempio n. 3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /* Flash unlock */
  FLASH_Unlock();

  /* Judge STM3210b-LK1 Key2 - PD3 */
  /* Enable GPIOD clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  
  /* Configure PD.00 pin as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Test if Key push-button on STM3210X-EVAL Board is pressed */
  if (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
    if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
    { 
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Esempio n. 4
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xG HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 72 MHz */
  SystemClock_Config();

  /* Initialize Key Button mounted on STM3210E-EVAL RevD board */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Test if Key push-button on STM3210E-EVAL RevD Board is pressed */
  if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET)
  { 
    /* Initialise Flash */
    FLASH_If_Init();
    /* Execute the IAP driver in order to reprogram the Flash */
    IAP_Init();
    /* Display main menu */
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
    if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      JumpToApplication = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      JumpToApplication();
    }
  }

  while (1)
  {}
}
Esempio n. 5
0
int main(void) {
	setvbuf(stdout, NULL, _IONBF, 0);

if(!SysLogin()) {
        system("clear");
		printf("\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\033[31m对不起您无权登录本系统\033[0m\n");
		sleep(2);
        system("clear");
		exit(0);
}
    system("clear");
	printf("\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t    \033[31m登录成功\033[0m\n");
    sleep(2);
	Main_Menu();
	return EXIT_SUCCESS;
}
Esempio n. 6
0
bool StateMenu::Menudraw(Position::H_Pos *h_p, int map_no, int *boss_killed, Hero *hero, Directionkey direction){

	switch (menu_select){
	case MAIN:
		return Main_Menu(h_p, map_no, boss_killed, hero, direction);
	case ST:
		St_Menu(hero, direction);
		break;
	case RE:
		Re_Menu(hero, direction);
		break;
	case PP:
		Pp_Menu(hero, direction);
		break;
	}
	return TRUE;
}
Esempio n. 7
0
int main(void)
{
  //mico_logic_partition_t *partition;
  
  init_clocks();
  init_memory();
  init_architecture();
  init_platform_bootloader();

  mico_set_bootload_ver();
  
  //update();

  enable_protection();

#ifdef MICO_ENABLE_STDIO_TO_BOOT
  if (stdio_break_in() == 1)
    goto BOOT;
#endif
  
  if( MicoShouldEnterBootloader() == false )
    bootloader_start_app( (MicoFlashGetInfo(MICO_PARTITION_APPLICATION))->partition_start_addr );
  /*else if( MicoShouldEnterMFGMode() == true )
    bootloader_start_app( (MicoFlashGetInfo(MICO_PARTITION_APPLICATION))->partition_start_addr );
  else if( MicoShouldEnterATEMode() ){
    partition = MicoFlashGetInfo( MICO_PARTITION_ATE );
    if (partition->partition_owner != MICO_FLASH_NONE) {
      bootloader_start_app( partition->partition_start_addr );
    }
  }*/

#ifdef MICO_ENABLE_STDIO_TO_BOOT
BOOT:
#endif
  
  _mount();
  printf ( menu, MODEL, Bootloader_REVISION, HARDWARE_REVISION );

  while(1){                             
    Main_Menu ();
  }
}
Esempio n. 8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Flash unlock */
  FLASH_Unlock();

  /* Initialize Key Button mounted on STM3210X-EVAL board */       
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);   

  /* Test if Key push-button on STM3210X-EVAL Board is pressed */
  if (STM_EVAL_PBGetState(BUTTON_KEY)  == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
    if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)
    { 
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Esempio n. 9
0
void CLevel1_Return(void)
{
	//switch(vCounter[0])
	switch(GetCounter1())
	{
		case 1:
// 			SetCounter1(1);//vCounter[0] = 1;
			ClearScreen(0);
			Main_Menu(1);
			NVIC_EnableIRQ(EINT3_IRQn);//中断使能
			NVIC_SetPriority(EINT3_IRQn, PRIO_ZERO); //中断优先级
			SetAnnUartFlag(0);
			break;
		case 2:
// 			SetCounter1(2);//vCounter[0] = 2;
			ClearScreen(0);
			Main_Menu(2);
			break;
		case 3:
// 			SetCounter1(3);//vCounter[0] = 3;
			ClearScreen(0);
			Main_Menu(3);
			break;
		case 4:
// 			SetCounter1(4);//vCounter[0] = 4;
			ClearScreen(0);
			Main_Menu(4);
			break;
		case 5:
// 			SetCounter1(4);//vCounter[0] = 4;
			ClearScreen(0);
			Main_Menu(5);
			break;
		case 6:
			ClearScreen(0);
			Main_Menu(6);
			break;
// 		case 7:
// 			ClearScreen(0);
// 			Main_Menu(7);
// 			break;
		default:break;
	}	
 	SetCounter2(1);//vCounter[1] = 1;
}
Esempio n. 10
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Reset of all peripherals, Initializes the Systick. */
  HAL_Init();
  
  /* Configure the system clock to have a system clock = 168 Mhz */
  SystemClock_Config();

  /* Initialize Key Button mounted on STM324xG-EVAL board */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Test if Key push-button is pressed */
  if (BSP_PB_GetState(BUTTON_KEY) == GPIO_PIN_RESET)
  { 
    /* Execute the IAP driver in order to reprogram the Flash */
    IAP_Init();
    /* Display main menu */
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
    if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      JumpToApplication = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      JumpToApplication();
    }
  }

  while (1)
  {}
}
Esempio n. 11
0
int main()
{
    Main_Menu();
    return 0;
}
Esempio n. 12
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*Clock initialization. */
  clock_init();

  /* Flash unlock */
  FLASH_Unlock();


  /*GPIO Initialization. */
  /*GPIOA, GPIOB on APB2 bus clock enable. */
  	  RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN;

  	  /*PA0, PA1, PA2, PA3 in output mode general purpose push-pull. */
  	  GPIOA->CRL =(0x03 << (3 * 4)) | (0x03 << (2 * 4)) | (0x03 << (1 * 4)) | (0x03 << (0 * 4));

  	  /*PB0, PB1 in floating input mode. */
  	  GPIOB->CRL = (0x08 << (1 * 4)) | (0x08 << (0 * 4));

  	  /*why do we do this?. */
  	  GPIOB->ODR |= GPIO_ODR_ODR0 | GPIO_ODR_ODR1;

  	  /*Light up all leds by resetting the output bits. */
  	  GPIOA->BSRR |= GPIO_BSRR_BR0 | GPIO_BSRR_BR1 | GPIO_BSRR_BR2 | GPIO_BSRR_BR3;

  /* Initialize Key Button mounted on STM3210X-EVAL board */       
  //STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Test if button on the board is pressed during reset. */
  if ((GPIOB->IDR & GPIO_IDR_IDR1) == 0x00)
  { 
    /* If Key is pressed */
    /* Execute the IAP driver in order to re-program the Flash */
    IAP_Init();
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n=              (C) COPYRIGHT 2010 STMicroelectronics                 =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=     In-Application Programming Application  (Version 3.3.0)        =");
    SerialPutString("\r\n=                                                                    =");
    SerialPutString("\r\n=                                   By MCD Application Team          =");
    SerialPutString("\r\n======================================================================");
    SerialPutString("\r\n\r\n");
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "ApplicationAddress" */
	uint32_t pippo1, pippo2;
	pippo1 = (*(__IO uint32_t*)ApplicationAddress); // 0x08000000   what is this value
	pippo2 = pippo1 & 0x2FFE0000;
    if (pippo2 == 0x20000000)
    { 
      /* Jump to user application */
      /* JumpAddress is not a pointer type. */
      /* ApplicationAddress+4 casted to a pointer to uin32_t. Jump address is the content
       * of the cell pointed by ApplicationAddress
       * Though wouldn't this be correct: JumpAddress = ApplicationAddress+4;
       * or! why does it dereferences it?
       */
      JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

      /*Jump_To_Application now points to the same address = JumpAddress through casting. */
      Jump_To_Application = (pFunction) JumpAddress;

      /* Initialize user application's Stack Pointer */
      /* __set_MSP implemented in CMSIS (as all the functions __* like). */
      __set_MSP(*(__IO uint32_t*) ApplicationAddress);
      Jump_To_Application();
    }
  }

  while (1)
  {}
}
Esempio n. 13
0
//登录函数,提示用户输入用户名和密码,登录成功return 1,否则提示重新登录,超过3次,登录失败
int SysLogin() {

	int i=1,j,k;
   	account_list_t data,head;//
   	List_Init(head,account_node_t);//
   	data=(account_list_t)malloc(sizeof(account_node_t));//
    Account_Srv_FetchAll(head);//
    char choice;
    char username[30];
	char password[30];
	char vipname[10]={"vip"};
	char vippassword[10]={"123456"};
	do{
			system("cls");
	printf("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆  欢迎来到博纳新天地影院  ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n");
	printf("☆                              【A】管理员登录                                       ☆\n\n");
	printf("☆                              【B】售票员登录                                       ☆\n\n");
	printf("☆                              【M】经理登录                                         ☆\n\n");
	printf("☆                              【E】退出                                             ☆\n\n");      
//	printf("☆                              【D】返回上一层                                       ☆\n\n");    
	printf("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n\n");
    fflush(stdin);
	choice = getchar();
    switch(choice){
			case 'A':
			case 'a':    //创建系统初始化账号 
                      while(i<=3)
 				   	  { 
						printf("请输入用户名:\n");	
     					scanf("%s",username);
	  				    printf("请输入密码:\n");	
     					scanf("%s",password);
						if(Account_Srv_Verify(username,password))
						{
							data=Account_Srv_FindByUsrName(head,username);
							if(data->data.type!=9)
								printf("账户权限不够\n");
						
						else{
						
 										do {
 												system("cls");
												printf("\n==================================================================\n");
												printf("**************** 剧院门票管理系统 ****************\n");
												printf("                 [T]系统用户管理.\n");
												printf("                 [S]演出厅管理.\n");
												printf("                 [R]返回上一层.\n");
												printf("                 [E]退出系统.\n");
												printf("\n==================================================================\n");
												printf("请选择:");
												fflush(stdin);
												choice = getchar();
												switch (choice) {
												
													case 'T':
													case 't':
														Account_UI_MgtEntry();
														break;
													case 'S':
													case 's':
														Studio_UI_MgtEntry();
														break;	
													case 'R':
													case 'r':
														SysLogin(); 
														break;
												
													}
											} while ('E' != choice && 'e' != choice);
											break; 
 								}
 						
					}
						else 
						{
								printf("密码错误,请重试.\n");
								j=0; 
								i++;
								fflush(stdin); 
								continue;
						}
				  	  }
				  	  if(j==0)
					  {
							exit(0);
					  }		
					  break;
		     	case 'B':
				case 'b': 
					 while(i<=3)  {
					 	printf("请输入用户名:\n");	
     					scanf("%s",username);
	  				    printf("请输入密码:\n");	
     					scanf("%s",password);
     					if(Account_Srv_Verify(username,password)){
     						data=Account_Srv_FindByUsrName(head,username);
							if(data->data.type!=1)
								printf("账户权限不够\n");
							else
     						Main_Menu(1);
     					}
     					else
     					{
     						printf("密码错误,请重试.\n");
							j=0; 
							i++;
							fflush(stdin); 
							continue;
     					}
     					if(j==0)
     					{
							exit(0);
     					}
					 }
     					break;	
     			case 'M':
				case 'm': while(i<=3) 
						{
							  printf("请输入用户名:\n");	
	     				  	  scanf("%s",username);
		  				      printf("请输入密码:\n");	
	     					  scanf("%s",password);
	     					  if(Account_Srv_Verify(username,password)){
	     					  			data=Account_Srv_FindByUsrName(head,username);
								if(data->data.type!=2)
										printf("账户权限不够\n");
								else
										Main_Menu(2);
		     					}
	     					  	else
		     					{
		     						printf("密码错误,请重试.\n");
									j=0; 
									i++;
									fflush(stdin); 
									continue;
		     					}
		     					if(j==0)
		     					{
									exit(0);
		     					}		
						  }
					
     					break;	
			    case 'E':
			    case 'e':return 0;
			    case 'D':
				case 'd':
						SysLogin(); 
						break; 
			    
            }}while(1);


}
Esempio n. 14
0
void main(void)
{
    student_struct student_list[MAX_STUDENTS]; // Array of students
    int user_choice=0;                         // User choice

    FILE *grades=NULL, *students=NULL; // Files for student/grade info

//
// Open and check for errors in grades file
//
    if ((grades = fopen("grades.dat", "r")) == NULL)
    {
	 cerr << "Error opening grades.dat!\n";
	 exit(1);
    }

//
// Open and check for error in student file
//
    if ((students = fopen("Students.dat", "r")) == NULL)
    {
	 cerr << "Error opening students.dat!\n";
	 exit(1);
    }

//
// Reset all student structures
//
    ResetStudents(student_list);

//
// Read the grades in from the grades file
//
    ReadGrades(grades, student_list);

//
// Read the students in from the students file
//
    ReadStudents(students, student_list);
    cout << "Student file read.\n";

//
// Calculate needed student information
//
    CalculateInfo(student_list);
    cout << "Grades updated.\n\n\n";

//
// Loop to run functions chosen by user
//
    do
    {
	 user_choice = Main_Menu(); // Get user choice from menu screen

	 Handle_Event(user_choice, student_list); // Handle user choices

    }while(user_choice != EXIT_NUMBER); // End loop when user enters exit
								// condition

//
// Close both files
//
    fclose(grades);
    fclose(students);
}
Esempio n. 15
0
/*******************************************************************************
  * @函数名称	main
  * @函数说明   主函数
  * @输入参数   无
  * @输出参数   无
  * @返回参数   无
*******************************************************************************/
int main(void)
{
		uint8_t fuf=0;
		uint8_t fu_e=1;			//固件更新使能
	  uint8_t i=0;
	

		uint8_t hui[32]=
		{0x04,0x04,0xF4,0x54,0x54,0x54,0x54,0xFF,0x54,0x54,0x54,0x54,0xF4,0x04,0x04,0x00,
		0x40,0x30,0x01,0x01,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x71,0x01,0x08,0x30,0x00};/*"恵",0*/	
	
	
	
	
		SystemTick_Init();
		NVIC_Configuration();
	
	
	
	
	
		oled_control_Init();
		OLED_ON;	
	
		OLED_Init();
	
		SPI_FLASH_Init();		//SPI接口初始化
	
    
    FLASH_Unlock();			//STM32内部Flash 解锁
	
	
    //LED_Configuration();
	
	
    //配置按键
    KEY_Configuration();//按钮对应的PB5脚初始化	
		
    IAP_Init();					//即串口1初始化,但是没有串口中断程序
	
	
		buzzer_control_Init();
		coil_control_Init();
	
	
	
	
// 		OLED_Clear();
// 		OLED_ShowUnite(24,2,"if updata");
// 		OLED_ShowUnite(28,4,"press OK");		
// 	  delay_ms(500);










// 		while(i<5)
// 		{
// 			OLED_Clear();	
// 			OLED_DrawBMP(32,2,48,4,hui);
// 			OLED_ShowUnite(48,2,"  科  ");
// 			OLED_ShowUnite(32,4,"  合  技");	
// 			delay_ms(500);	
// 			
// 			OLED_Clear();		
// 			OLED_ShowUnite(32,2,"  合  技");	
// 			OLED_DrawBMP(32,4,48,6,hui);			
// 			OLED_ShowUnite(48,4,"  科  ");
// 			delay_ms(500);		
// 	
// 			i++;
// 		}
		
		
// 		OLED_Clear();	
// 		OLED_DrawBMP(32,2,48,4,hui);
// 		OLED_ShowUnite(48,2,"合科技");		
// 		delay_ms(800);
		
		
		//测试发送
// 		while(1)
// 		{
// 			Send_Byte(ACK);			//收到上位机发送的第0帧之后发送ACK命令
// 			Send_Byte(CRC16);		//接着再发送C,表示等待上位机发送数据帧
// 		}
	
    //按键是否按下
    //if (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)  == 0x00)
		
		
		
		/*
		出厂时,下载程序的步骤:
					1.下载字库
					2.下载IAP
					3.下载应用程序
		
		*/
		
		


		//在下载字库时,先将FIRMWARE_UPGRADE_FLAG标志置为1,所以再下载IAP程序时会直接进入固件更新
		
		
		SPI_FLASH_Read(&fuf,FIRMWARE_UPGRADE_FLAG,1);
		if(fuf==1)
    {
			
				OLED_Clear();
				//OLED_ShowUnite(16,2,"固件更新中...");
			  OLED_ShowUnite(32,2,"to updata");		
				delay_ms(500);
  

  			//假如按键按下
        //执行IAP驱动程序更新Flash程序

        SerialPutString("\r\n======================================================================");
        SerialPutString("\r\n=              (C) COPYRIGHT 2011 Lierda                             =");
        SerialPutString("\r\n=                                                                    =");
        SerialPutString("\r\n=     In-Application Programming Application  (Version 1.0.0)        =");
        SerialPutString("\r\n=                                                                    =");
        SerialPutString("\r\n=                                   By wuguoyan                      =");
        SerialPutString("\r\n======================================================================");
        SerialPutString("\r\n\r\n");
        Main_Menu();
    }
    //否则执行用户程序
    else
    {
			/*		
			在程序里#define ApplicationAddress    0x8003000 ,*(__IO uint32_t*)ApplicationAddress)
			即取0x8003000开始到0x8003003 的4个字节的值, 因为我们的应用程序APP中设置把 中断向
			量表 放置在0x08003000 开始的位置;而中断向量表里第一个放的就是栈顶地址的值
			也就是说,这句话即通过判断栈顶地址值是否正确(是否在0x2000 0000 - 0x 2000 2000之间)
			来判断是否应用程序已经下载了,因为应用程序的启动文件刚开始就去初始化化栈空间,
			如果栈顶值对了,说应用程已经下载了启动文件的初始化也执行了;				
			*/

			
        //判断用户是否已经下载程序,因为正常情况下此地址是栈地址。
        //若没有这一句的话,即使没有下载程序也会进入而导致跑飞。
			
				//*(__IO uint32_t*)ApplicationAddress 与 __vector_table[0]是一样的
				//__vector_table[0]是应用程序栈的顶
			
				//X=*(__IO uint32_t*)ApplicationAddress
        //if (( X & 0x2FFE0000 ) == 0x20000000)			
				//X只有在0x20000000与0x2001FFFF之间时,才可能有(X&0x2FFE0000) == 0x20000000成立
			
				//即栈顶是不是在以0x20000000开始的128K的范围内,这里便是STM32的RAM区域
			
        if (( ( *(__IO uint32_t*)ApplicationAddress ) & 0x2FFE0000 ) == 0x20000000)
        {
					
// 						OLED_Clear();
// 						OLED_ShowUnite(4,2,"Execute Program");
// 						delay_ms(500);							
					
					
					
            //SerialPutString("Execute Program\r\n\n");
            //跳转至用户代码
            JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
            Jump_To_Application = (pFunction) JumpAddress;

            //初始化用户程序的堆栈指针
            __set_MSP(*(__IO uint32_t*) ApplicationAddress);
            Jump_To_Application();		//执行复位中断函数
        }
        else
        {
						OLED_Clear();
						OLED_ShowUnite(4,2,"no user Program");
						delay_ms(500);							
										
            SerialPutString("no user Program\r\n\n");
        }
    }

// 		OLED_Clear();
// 		OLED_ShowUnite(16,2,"please reboot");
// 		delay_ms(500);		
// 		
// 		SerialPutString("please reboot\r\n\n");
//     while (1)
//     {
//     }
}
Esempio n. 16
0
int main(void)
{
	int 			fd_client = -1;
	char 			*buf;
	int 			con = -1;
	int 			opt = 0;
	fd_set 			readfds, exceptfds;
	struct 			timeval_t t;
	struct 			sockaddr_t addr;
	lib_config_t 	libConfig;
	volatile int	setval;
	volatile int	readval;

	buf = (char*)malloc(3*1024);

	libConfig.tcp_buf_dynamic = mxEnable;
	libConfig.tcp_max_connection_num = 12;
	libConfig.tcp_rx_size = 2048;
	libConfig.tcp_tx_size = 2048;
	libConfig.hw_watchdog = 0;
	libConfig.wifi_channel = WIFI_CHANNEL_1_13;
	lib_config(&libConfig);
  
	mxchipInit();
	UART_Init();


	printf("\r\n%s\r\n mxchipWNet library version: %s\r\n", APP_INFO, system_lib_version());
	printf(menu);
	printf ("\nMXCHIP> ");
	
	//init http
	set_tcp_keepalive(3, 60);
	setSslMaxlen(6*1024);
	t.tv_sec = 0;
  	t.tv_usec = 100;
	
//	void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

	while(1)
	{
		mxchipTick();	
		if(menu_enable)
			Main_Menu();
		if(configSuccess)
		{
			wNetConfig.wifi_mode = Station;
			wNetConfig.dhcpMode = DHCP_Client;
			StartNetwork(&wNetConfig);
			printf("connect to %s.....\r\n", wNetConfig.wifi_ssid);
			configSuccess = 0;
			menu_enable = 1;

			sysTick_configuration();
			config_gpio_pc6();
			config_gpio_pb8();

			while(1) 
			{
				readval= GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_6);
				mxchipTick();
				//If wifi is established, connect to WEBSERVER, and send a http request
				if(https_server_addr == 0 && dns_pending == 0)
				{  
					//DNS function
					https_server_addr = dns_request(WEB_SERVER);
					if(https_server_addr == -1)
						printf("DNS test: %s failed. \r\n", WEB_SERVER); 
					else if (https_server_addr == 0) //DNS pending, waiting for callback
					{
						dns_pending = 1;
						printf("2DNS test: %s success. \r\n", WEB_SERVER); 
						printf("21http server addr=%x\n",https_server_addr);
					}
				}
				
				if( fd_client == -1 && (u32)https_server_addr>0)
				{
					fd_client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
					setsockopt(fd_client,0,SO_BLOCKMODE,&opt,4);
					addr.s_ip = https_server_addr; 
					addr.s_port = 443;
					if (connect(fd_client, &addr, sizeof(addr))!=0) 
						printf("Connect to %s failed.\r\n", WEB_SERVER); 
					else   
						printf("Connect to %s success.\r\n", WEB_SERVER); 	
				}

				if(serverConnectted&&sslConnectted==0)
				{
					printf("Connect to web server success! Setup SSL ecryption...\r\n");
					if (setSSLmode(1, fd_client)!= MXCHIP_SUCCESS)
					{
						printf("SSL connect fail\r\n");
						close(fd_client);
						fd_client = -1;
						serverConnectted = 0;
					} 
					else 
					{
						printf("SSL connect\r\n");
						sslConnectted = 1;
					}
				}	
		
				if(readval==1&&sslConnectted)
				{
					printf("read value is 1\n");
					send(fd_client, sendhttpRequest, strlen(sendhttpRequest), 0);
				//	return 0;
				}
				if(check_responce&&sslConnectted)
				{
					printf("readval=%d\n",readval);
					check_responce=0;
					send(fd_client, responcehttpRequest, strlen(responcehttpRequest), 0);
					//Check status on erery sockets 
					FD_ZERO(&readfds);

					if(sslConnectted)
						FD_SET(fd_client, &readfds);
		
					select(1, &readfds, NULL, &exceptfds, &t);
		
					//Read html data from WEBSERVER
					if(sslConnectted)
					{
						if(FD_ISSET(fd_client, &readfds))
						{
							con = recv(fd_client, buf, 2*1024, 0);
							if(con > 0)
							{
								printf("Get %s data successful! data length: %d bytes data\r\n", WEB_SERVER, con);
								setval=r_http(buf);
								printf("read from http  is %d\n",setval);
					
								if(setval==1)
									GPIO_SetBits(GPIOB,GPIO_Pin_8);
								 else
								  	GPIO_ResetBits(GPIOB,GPIO_Pin_8);
							}
							else
							{
								close(fd_client);
								serverConnectted = 0;
								sslConnectted = 0;
								fd_client = -1;
								printf("Web connection closed.\r\n");
							}
						}
					}
				}
			}
		}
		
		if(easylink)
		{
			OpenEasylink2(60);	
			easylink = 0;
		}
	}
}