コード例 #1
0
ファイル: EEPROM.cpp プロジェクト: eseawind/Gyfxy
void Flash_ProtectMode(u32 *ProtectedPages)
{
	vu32 WRPR_Value;
  	FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP|FLASH_FLAG_PGERR |FLASH_FLAG_WRPRTERR);

  	/* Get pages write protection status */
  	WRPR_Value = FLASH_GetWriteProtectionOptionByte();
  	*ProtectedPages = WRPR_Value & 0x000000C0;

#ifdef WriteProtection_Disable
  	if (ProtectedPages == 0x00)
  	{// Pages are write protected  

    	// Disable the write protection 
    	FLASHStatus = FLASH_EraseOptionBytes();

    	// Generate System Reset to load the new option byte values  
    	NVIC_GenerateSystemReset();
  	}
#else
 	#ifdef WriteProtection_Enable
  
  	if (ProtectedPages != 0x00)
  	{	// Pages not write protected  
    	#ifdef USE_STM3210B_EVAL
   	 	// Enable the pages write protection  
    	FLASHStatus = FLASH_EnableWriteProtection(FLASH_WRProt_Pages24to27 |FLASH_WRProt_Pages28to31);    
    	#else   
    	// Enable the pages write protection  
    	FLASHStatus = FLASH_EnableWriteProtection(FLASH_WRProt_Pages12to13 |FLASH_WRProt_Pages14to15);
    	#endif
    	// Generate System Reset to load the new option byte values  
    	NVIC_GenerateSystemReset();
  	}
 	#endif
#endif
}
コード例 #2
0
ファイル: hw_int_stm32f10x.c プロジェクト: t0mac0/wiimouse
PUBLIC inline void HW_INT_SystemReset(void)
{
	NVIC_GenerateSystemReset();
}
コード例 #3
0
ファイル: board.c プロジェクト: barriquello/iotstack
void board_reset(){
  NVIC_GenerateSystemReset();
}
コード例 #4
0
int main(void)
{
  FIL log_file;
  int i, j, result;
  int file_number = 0;
  u8 configNumber = 1;
  u8 maxConfig;
  u8 *p;
  time_t rawtime;
  u8 debugState = 0; //debug off

#ifdef DEBUG
  debug();
#endif

  RCC_Configuration();
  GPIO_Configuration();
  NVIC_Configuration();
  SystickConfigure();
  Timer3Init();
#ifdef UART1_DEBUG
  (void)USART1_Init(115200);
#endif
  LedConfigureGPIO();
  ButtonConfigureGPIO();
  BuzzerConfigureGPIO();

#ifdef CAN_FEATURE_ENABLED
  GPIO_InitTypeDef GPIO_InitStructure;

  // Configure CAN pin: RX
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  // Configure CAN pin: TX
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
#endif

  MMC_PowerOff();
  timer2=1000;
  while(timer2);
  MMC_PowerOn();

#ifdef UART1_DEBUG
  printf("\n\n%s %s\n", HW_VERSION, SW_VERSION);
#endif

  ConfigureClock();
  timer2=1000;
  while(timer2);

  buttonState = 0;

  CardInserted();
  
  if (FR_OK != f_mount(0, &Fatfs[0]))
  {
    LedSetColor(amber, fast);
    BuzzerSetMode(0x83);
#ifdef UART1_DEBUG
    printf("error mounting fat device\n");
#endif
    while(buttonState != 2);
    NVIC_GenerateSystemReset();
  }

  if (ReadTimeDateFile())
  {
#ifdef UART1_DEBUG
    rawtime = RTC_GetCounter();
    printf("Time set: %s\n", ctime (&rawtime) );
#endif
  }

#ifdef DEBUG_LOG
  if (ReadDebugFile())
  {
    debugState = 1;
  }
#endif

#ifdef CAN_FEATURE_ENABLED
  if (ReadCanFile())
  {
    canDiag = 1;
    CAN_Open();
  }
#endif

  i = ReadSpeedFile();
  if (i > 0)
  {
    KW1281_SPEED = i;
    autobaud = 0;
  }

  if (ReadDelayFile())
  {
    user_defined_timings = 1;
  }
  
  if (!ReadConfig())
  {
    LedSetColor(amber, fast); 
    BuzzerSetMode(0x83);
#ifdef UART1_DEBUG
    printf("error reading config\n");
#endif
    MMC_PowerOff();
    while(buttonState != 2);
    NVIC_GenerateSystemReset(); 
  }
  
  if (config[0][0] > 0)
  {
    maxConfig = 1;
    if (config[1][0] > 0)
    {
      maxConfig = 2;
      if (config[2][0] > 0)
      {
        maxConfig = 3;
      }
    }
  }
  else
  {
    LedSetColor(amber, fast); 
    BuzzerSetMode(0x83);
#ifdef UART1_DEBUG
    printf("error reading config\n");
#endif
    MMC_PowerOff();
    while(buttonState != 2);
    NVIC_GenerateSystemReset(); 
  }

  file_number = GetNextFileNumber();
#ifdef UART1_DEBUG
  printf("file number %d\n", file_number);
#endif
  if (!file_number)
  {
    LedSetColor(amber, fast); 
    BuzzerSetMode(0x83);
#ifdef UART1_DEBUG
    printf("can't get number of next file\n");
#endif
    MMC_PowerOff();
    while(buttonState != 2);
    NVIC_GenerateSystemReset(); 
  }
  
  while(1)
  {
    i = USART2_GetData();
    buttonState = 0;
    LedSetColor(configNumber, continous);
    BuzzerSetMode(configNumber);
    do
    {
      if (2 == buttonState)
      {
        configNumber = (configNumber < maxConfig)?configNumber+1:1;
        LedSetColor(configNumber, continous);
        BuzzerSetMode(configNumber);
        buttonState = 0;
      }
    } while (1 != buttonState);
    
    buttonState = 0;
    LedSetColor(green, fast);
    BuzzerSetMode(0x81);

    i = CreateLogFile(file_number, &log_file);

    i = f_printf(&log_file, "%s, sw_ver: %s\n", HW_VERSION, SW_VERSION);

    rawtime = RTC_GetCounter();
    i = f_printf(&log_file, "Current time: %s\n", ctime (&rawtime));
    
    timeSec = 0;
    time10MSec = 0;
    
    if (canDiag)
    {
      i = f_printf(&log_file, "CAN 500kbit\n\n");
      LedSetColor(configNumber, slow);
      BuzzerSetMode(configNumber);
      result = vwtp(&config[configNumber-1], &log_file, debugState);
      
      switch (result)
      {
        case 0:
          timer2 = 500;
          i = f_printf(&log_file, "\n\nLogging terminated by user\n");
          break;
        
        case 1:
          LedSetColor(red, fast);
          BuzzerSetMode(0x82); //communication error
          timer2 = 2000;
          i = f_printf(&log_file, "\n\nConnection lost\n");
          break;
          
        case 2:
          i = CloseLogFile(&log_file);
          LedSetColor(amber, fast);
          BuzzerSetMode(0x83); //filesystem error
          MMC_PowerOff();
          while(buttonState != 2);
          NVIC_GenerateSystemReset();  
          break;
        
        case 11:
          LedSetColor(red, fast);
          BuzzerSetMode(0x82); //communication error
          timer2 = 2000;
          i = f_printf(&log_file, "\n\nCannot connect with ECU\n", result);
          break;

        default:
          LedSetColor(red, fast);
          BuzzerSetMode(0x82); //communication error
          timer2 = 2000;
          i = f_printf(&log_file, "\n\nCommunication error, error code = %d\n", result);
          break;
      }
    } 
    else //KW1281 diag
    {
      i = kw1281_max_init_attempts;
      do
      {
        result = ISO9141Init(&KW1281_SPEED);

        --i;
        if ((result>0) && (i>0))
        {
          timer2=1000;
          while(timer2);
        }
      } while (result && i);

      if (0 == result) //connected with ECU
      {
        i = f_printf(&log_file, "Connected @ %d baud %s%s\n\n", KW1281_SPEED, autobaud?"(autodetected)":"(set by user)", user_defined_timings?", user defined timings":"");
        LedSetColor(configNumber, slow);
        BuzzerSetMode(configNumber);
    
        buttonState = 0;
        i = kw1281_diag(&config[configNumber-1], &log_file, debugState);
      
        switch (i)
        {
          case 0:
            timer2 = 500;
            i = f_printf(&log_file, "\n\nLogging terminated by user\n");
            break;
        
          case 1:
            LedSetColor(red, fast);
            BuzzerSetMode(0x82); //communication error
            timer2 = 2000;
            i = f_printf(&log_file, "\n\nConnection lost\n");
            break;
          
          case 2:
          default:
            i = CloseLogFile(&log_file);
            LedSetColor(amber, fast);
            BuzzerSetMode(0x83); //filesystem error
            MMC_PowerOff();
            while(buttonState != 2);
            NVIC_GenerateSystemReset();  
        }
      }
      if (0 != result)
      {
        i = f_printf(&log_file, "Cannot connect with ECU: ");
        if (0xff == result)
        {
          i = f_printf(&log_file, "no response\n");
        }
        else if (0x7f == result)
        {
          i = f_printf(&log_file, "sync error - wrong speed (set to %d baud)?!\n", KW1281_SPEED);
        }
        else if (0x10 == result)
        {
          i = f_printf(&log_file, "not a KW1281 protocol\n");
        }
        else
        {
          i = f_printf(&log_file, "error code %d\n", result);
        }
        LedSetColor(red, fast); 
        BuzzerSetMode(0x82);
        timer2 = 2000;
      }
    } // end of KW1281 diag

    i = CloseLogFile(&log_file);
    file_number++;
    while (timer2>0);
  }
}
コード例 #5
0
ファイル: hw_nvic_stm32f10x.c プロジェクト: t0mac0/wiimouse
PUBLIC void HW_NVIC_SystemReset(void)
{
    NVIC_GenerateSystemReset();
}