Ejemplo n.º 1
0
void ANO_Hexacopter_board_Init(void)
{
	//中断优先级组别设置
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
	
	//初始化系统滴答定时器
	cycleCounterInit();
	SysTick_Config(SystemCoreClock / 1000);	
	
	//初始化模拟I2C
	ANO_I2C_Soft::Init();
	//初始化SPI2
	ANO_SPI2::Init();
	//初始化NRF
	nrf.Init(MODEL_TX2,89);
	
	//初始化定时器输出PWM,24KHz
	ANO_PWM::out_Init(24000);

	uart3.Init(9600);
	
	ANO_LED::Init();	
	
	//解锁flash
	FLASH_Unlock();	
	//初始化虚拟eeprom设置
	EE_Init();	
}
Ejemplo n.º 2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB 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 64 MHz */
  SystemClock_Config();

  /* Unlock the Flash Program Erase controller */
  HAL_FLASH_Unlock();

  /* EEPROM Init */
  EE_Init();

/* --- Store successively many values of the three variables in the EEPROM ---*/
  /* Store 0x1000 values of Variable1 in EEPROM */
  for (VarValue = 1; VarValue <= 0x1000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[0], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);


  /* Store 0x2000 values of Variable2 in EEPROM */
  for (VarValue = 1; VarValue <= 0x2000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[1], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);


  /* Store 0x3000 values of Variable3 in EEPROM */
  for (VarValue = 1; VarValue <= 0x3000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[2], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
  EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]);

  while (1)
  {
  };
}
Ejemplo n.º 3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int mainOld(void)
{
    /* Setup STM32 system (clock, PLL and Flash configuration) */
    SystemInit();

    /* Unlock the Flash Program Erase controller */
    FLASH_Unlock();

    /* EEPROM Init */
    EE_Init();

    /* --- Store successively many values of the three variables in the EEPROM ---*/
    /* Store 1000 values of Variable1 in EEPROM */
    for (VarValue = 0; VarValue < 1000; VarValue++)
    {
        EE_WriteVariable(VirtAddVarTab[0], VarValue);
    }

    /* Store 500 values of Variable2 in EEPROM */
    for (VarValue = 0; VarValue < 500; VarValue++)
    {
        EE_WriteVariable(VirtAddVarTab[1], VarValue);
    }

    /* Store 800 values of Variable3 in EEPROM */
    for (VarValue = 0; VarValue < 800; VarValue++)
    {
        EE_WriteVariable(VirtAddVarTab[2], VarValue);
    }

    while (1);
}
void setup_FLASH()
{
	uint16_t tmp_eeprom_data_structure_version;
	FLASH_Unlock();
	EE_Init();
	EE_ReadVariable(VirtAddVarTab[index_eeprom_data_structure_version],&tmp_eeprom_data_structure_version);	//eeprom_data_structure_version lesen
	if (tmp_eeprom_data_structure_version != eeprom_data_structure_version)
	{
		EE_Format();
		EE_WriteVariable(VirtAddVarTab[index_eeprom_data_structure_version],eeprom_data_structure_version);
	}
}
Ejemplo n.º 5
0
/* init virtual EEPROM in FLASH ---------------------------------------------*/
void initEEPROM()
{
	/* Set virtual address */
	u16 i;
	for (i = 0; i < 0xC8; i++)
	{
		VirtAddVarTab[i] = i;
	}
	/* Unlock the Flash Program Erase controller */
	FLASH_Unlock();
	/* EEPROM Init */
	EE_Init();
}
Ejemplo n.º 6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */  
   /* Unlock the Flash Program Erase controller */
  FLASH_Unlock();

  /* EEPROM Init */
  EE_Init();

/* --- Store successively many values of the three variables in the EEPROM ---*/
  /* Store 0x1000 values of Variable1 in EEPROM */
  for (VarValue = 1; VarValue <= 0x1000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[0], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);


  /* Store 0x2000 values of Variable2 in EEPROM */
  for (VarValue = 1; VarValue <= 0x2000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[1], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);


  /* Store 0x3000 values of Variable3 in EEPROM */
  for (VarValue = 1; VarValue <= 0x3000; VarValue++)
  {
    EE_WriteVariable(VirtAddVarTab[2], VarValue);
  }

  /* read the last stored variables data*/
  EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
  EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
  EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]);

  while (1);
}
Ejemplo n.º 7
0
void conf_general_init(void) {
	// First, make sure that all relevant virtual addresses are assigned for page swapping.
	memset(VirtAddVarTab, 0, sizeof(VirtAddVarTab));

	int ind = 0;
	for (unsigned int i = 0;i < (sizeof(app_configuration) / 2);i++) {
		VirtAddVarTab[ind++] = EEPROM_BASE_MCCONF + i;
	}

	for (unsigned int i = 0;i < (sizeof(app_configuration) / 2);i++) {
		VirtAddVarTab[ind++] = EEPROM_BASE_APPCONF + i;
	}

	FLASH_Unlock();
	EE_Init();
}
Ejemplo n.º 8
0
void IAC_Init(void)
{
	 delay_init(72);
	 MCO_INIT();
	 Nvic_Init(); 
   LED_GPIO_Config();	
   I2C_INIT();
	 delay(0XFFF);
	 TIM3_Init(2500);
	 usart1_config();
	 ADC1_Init();	
	 NRF24L01_Init();
   Moto_Init();	
	 LED_SHOW();
	 FLASH_Unlock();
	 EE_Init();
}
Ejemplo n.º 9
0
void getConfig()
{
	FLASH_Unlock();

	uint16_t i;

	uint16_t *ptr;
	EE_Init();
	EE_ReadVariable(EADDR_IS_INITIALIZED,&i);
	if(i != 0x5253)
	{
		//empty or corrupted EEPROM detected: write default config
		//EE_Format();
		EE_WriteVariable(EADDR_IS_INITIALIZED, 0x5253);
		s.commutationMethod = commutationMethod_HALL;
		s.inputMethod = inputMethod_stepDir;
		s.encoder_PPR = 4000;
		s.encoder_poles = 4;
		s.encoder_counts_per_step = 10;
		s.pid_Kp = 10;
		s.pid_Ki = 0;
		s.pid_Kd = 0;
		s.usart_baud = 1152;
		writeConfig(s);
		return;

	}
	ptr = (uint16_t *)&s;
	for(i=0; i<sizeof(servoConfig)/2;i++)
	{

		if(EE_ReadVariable(EADDR_CONFIG_START+i, ptr)!=0)
			usart_sendStr("Flash Error\n\r");
		ptr++;
	}

	return;

}
Ejemplo n.º 10
0
void ANO_Remoter_board_Init(void)
{
	u8 data[32]={0};u8 ack[32]={0};
	//中断优先级组别设置
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	
	//初始化系统滴答定时器
	SysTick_Config(SystemCoreClock / 1000);	
	LED_INIT();
	//初始化模拟I2C
	ANO_I2C_Soft::Init();	
	
	//初始化串口1
	Uart1_Init(115200);
	
	//初始化SPI2
	ANO_SPI2::Init();	

	while(nrf.Check()==false);
	//初始化NRF
	nrf.Init(MODEL_RX2,40);
//while(1)
//{
//	//memset(data,0,sizeof(data));
//	data[0]=0x31;data[1]=0x32;data[2]=0x33;
//	nrf.NRF_Tx_Dat(data,ack);
//	nrf.delayms(50);
//}
	//初始化ADC采样
	ADC1_Init();
	
	//解锁flash
	FLASH_Unlock();	
	//初始化虚拟eeprom设置
	EE_Init();	
	
}
Ejemplo n.º 11
0
int main(void)
{

	SystemInit();
	GPIOInit();
	FLASH_Unlock();
	EE_Init();

  USBD_Init(&USB_OTG_dev,
#ifdef USE_USB_OTG_HS
  USB_OTG_HS_CORE_ID,
#else
  USB_OTG_FS_CORE_ID,
#endif
  &USR_desc,
  &USBD_HID_cb,
  &USR_cb);

	bitCount = 0;
	currentValue = 0;
	set = 0;
	ignoreNext = 0;
	uppercaseNext = 0;
	shiftPressed = 0;
	buttonPressed = 0;
	getHowMany();

	int i = 0;
	resetBuffer();

	for(;;)
	{
		/*
		 * Po wcisnieciu przycisku nastepuje wyslanie raportu USB
		 * zawierajacego rejestr przycisnietych klaiwszy
		 */
		if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
		{
			if (!buttonPressed)
			{
				buttonPressed = 1;
				for (i = 0; i < 64; i++)
				{
					EE_ReadVariable(VirtAddVarTab[i], &InBuffer[i]);
				}

				USBD_HID_SendReport (&USB_OTG_dev, InBuffer, 64);

			}
		} else if (buttonPressed)
		{
			buttonPressed = 0;
		}

		if (checkBufferReady())
		{
			/*
			 * Jezeli zapisano 64 wcisniecia klawiszy,
			 * nalezy oproznic EEPROM przed kontynuacja zapisu
			 *
			 */
			if(EEPROMFull())
			{
				GPIO_ToggleBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
				continue;
			}

			unsetBufferReady();
			startTimer();

			EE_WriteVariable(VirtAddVarTab[howMany=howMany+0x01], currentChar);
			EE_WriteVariable(VirtAddVarTab[63], howMany);

			}

		}
}
Ejemplo n.º 12
0
int main(void)
{  	
	u8 i;
	u8 RecvBuf[32];
	u8 SendBuf[32];
	u8 offline = 0;
	u8 recv_flag = 0;
	u32 pd2ms=0,pd20ams=0,pd20bms=0,pd100ms=0;

	SystemInit();
	RCC_Configuration();
	NVIC_Configuration();
	GPIO_Configuration();
	
	USART1_Configuration();
	dbgPrintf(" Init Ticktack !\r\n");
	cycleCounterInit();
	SysTick_Config(SystemCoreClock / 1000);	
	for(i=0;i<2;i++)
	{
		OP_LED1;OP_LED2;OP_LED3;OP_LED4;
		delay_ms(500);
		OP_LED1;OP_LED2;OP_LED3;OP_LED4;
		delay_ms(500);
	}
	FilterInit();
	controllerInit();

	dbgPrintf(" Init eeprom!\r\n");
	FLASH_Unlock();	
	EE_Init();
	EE_Read_ACC_GYRO_Offset();
	/* 如果PID丢失或者错误,将下面两行注释去掉,重新编译烧写,运行一遍,可将PID还原,然后重新注释,再烧写一遍 */
	//EE_Write_PID();
	//EE_Write_Rate_PID();
	EE_Read_PID();
	EE_Read_Rate_PID();

	dbgPrintf(" Init adc!\r\n");
	ADC_DMA_Init();

	dbgPrintf(" Init NRF24L01 !\r\n");
	SPI_NRF_Init();	
	Nrf24l01_Init();
	NRF24l01_SetRxMode();
	
	while(Nrf24l01_Check())	
	{
		dbgPrintf("NRF24L01 Fault !\r\n");
		delay_ms(500);
	}
	dbgPrintf("NRF24L01 Is Detected !\r\n");

	dbgPrintf("Init MPU6050...\r\n");
	IIC_Init();
	MPU6050_initialize();


	dbgPrintf("Init Motor...\r\n");
	Motor_Init();
	Motor_SetPwm(0,0,0,0);


	pd20bms = TIMIRQCNT + 10*ITS_PER_MS;
	while(1)
	{
		if(TIMIRQCNT>pd2ms + 2*ITS_PER_MS-1)	// every 4ms
		{
			GetEulerAngle();
			if(lock_flag==UNLOCK) 
				AttitudeToMotors(angle.y,angle.x,angle.z);
			else
			{
				MOTOR1=0;	 			
				MOTOR2=0;				
				MOTOR3=0;				
				MOTOR4=0;				
			}
			Motor_SetPwm(MOTOR1,MOTOR2,MOTOR3,MOTOR4);
			pd2ms = TIMIRQCNT;
		}
		
		if(TIMIRQCNT>pd20ams + 20*ITS_PER_MS-1)	// every 20ms
		{
				if(NRF24l01_Recv(RecvBuf)>10)
				{
						if((RecvBuf[RecvBuf[2]+3]==CheckSum(RecvBuf, RecvBuf[2]+3))&&(RecvBuf[0]==0xAA))
						{
								if(RecvBuf[1]!=0xC0)		
									OP_LED1;		
								offline=0;
								switch(RecvBuf[1])
								{
										case 0xC0:  //control
												Getdesireddata(RecvBuf);
												OP_LED2;
												break;
										case 0x10:  //W PID
												SetPID(RecvBuf);
												break;
										case 0x11:  //W Attitude
												SetAccGyroOffset(RecvBuf);
												break;
										case 0x12:  //W Control offset
												break;
										case 0x14:  //W Rate PID
												SetRatePID(RecvBuf);
												break;
										case 0x20:  //R PID
												recv_flag = RESEND;
												GetPID(SendBuf);
												break;
										case 0x21:  //R Attitude
												recv_flag = RESEND;
												GetAccGyroOffset(SendBuf);
												break;
										case 0x22:  //R Control offset
												break;
										case 0x24:  //R Rate PID
												recv_flag = RESEND;
												GetRatePID(SendBuf);
												break;
										case 0x40:	//校准姿态
												EnableCalibration();
												break;
										case 0x41:	//校准遥控器零点												
												break;
									 default:
												break;
								}
						}
				}
				pd20ams = TIMIRQCNT;
		}
		if(TIMIRQCNT>pd20bms + 20*ITS_PER_MS-1)	// every 20ms
		{
			if(recv_flag==0)
         		GetState(SendBuf);
      		else
         		recv_flag--;
			NRF_SendData(SendBuf);
			OP_LED3;
			pd20bms = TIMIRQCNT;
		}
		
		if(TIMIRQCNT>pd100ms + 100*ITS_PER_MS-1)	// every 100ms
		{
			if(offline>20)
				lock_flag = LOCK;
			offline++;
//			OP_LED4;
			pd100ms = TIMIRQCNT;
		}
	}
}
Ejemplo n.º 13
0
/**
 * Initializes the Tekdaqc's FLASH disk.
 *
 * @param none
 * @retval none
 */
void FlashDiskInit(void) {
	/* EEPROM Init */
	EE_Init();
}
Ejemplo n.º 14
0
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	
//initiate user button
  PB_Config();

	//initiate LEDs and turn them on
  LED_Config();	
	
 

  /* -----------------------------------------------------------------------
    TIM3 Configuration: Output Compare Timing Mode:
    
    In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
    since APB1 prescaler is different from 1.   
      TIM3CLK = 2 * PCLK1  
      PCLK1 = HCLK / 4 
      => TIM3CLK = HCLK / 2 = SystemCoreClock /2
          
    To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /0.5 MHz) - 1
                                              
    CC1 update rate = TIM3 counter clock / CCR1_Val = 10.0 Hz
    ==> Toggling frequency = 5 Hz

    Note: 
     SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
     Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
     function to update SystemCoreClock variable value. Otherwise, any configuration
     based on this variable will be incorrect.    
		 ----------------------------------------------------------------------- */ 	
	
	//=======================Configure and init Timer======================
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1;

 /* TIM Configuration */
  TIM3_Config();

	// configure the output compare
	TIM3_OCConfig();

  /* TIM Interrupts enable */
  TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);

  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
	
//======================================configure and init LCD  ======================	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
	
//================EEPROM init====================================

/* Unlock the Flash Program Erase controller */
		FLASH_Unlock();
		/* EEPROM Init */
		EE_Init();
		

//============ Set up for random number generation==============
	RNG_Config();


	//with the default font, LCD can display  12 lines of chars, they are LINE(0), LINE(1)...LINE(11) 
	//with the default font, LCD can display  15 columns, they are COLUMN(0)....COLUMN(14)


		LCD_Clear(LCD_COLOR_WHITE);
			
	

		
		LCD_DisplayStringLine(LINE(0),  (uint8_t *) "Attempt");
		LCD_DisplayStringLine(LINE(2),  (uint8_t *) "Record");
		
		EE_WriteVariable(VirtAddVarTab[0],VarValue);
		EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
		sprintf(str, "%d", VarDataTab[0]);
		//LCD_DisplayStringLine(LINE(3),  (uint8_t *) str);
		//randomNumber = RNG_GetRandomNumber()/100000;

		//sprintf(str, "%d", randomNumber());
		//LCD_DisplayStringLine(LINE(5),  (uint8_t *) str);
		
		resetTimer();
		
		/*the following while loop is where the main part of the code is
		* it currently uses the userbutton on board since Mario forgot to bring along his
		* jumper cables to test out the push button part
		*/
		
		//if toggle = 0 lights are  blinking
		//if toggle = 1 2 second wait
		//if toggle = 2 LED toggle off, the lights stay on
		
		//@TODO add external push button to code
		externalButton();
  while (1){ 
			int num = TIM_GetCounter(TIM3);
		//This is for the start of the procedure 
		if(toggle==0){
			if(num == 3000){
					STM_EVAL_LEDOn(LED3);
				  STM_EVAL_LEDOn(LED4);
			}
			else if(num == 6000){
					STM_EVAL_LEDOff(LED3);
					STM_EVAL_LEDOff(LED4);
					resetTimer();
			}
		}
			//if the user button has been pressed and the lights are blinking
			if (UBPressed==1 && toggle==0) {
				STM_EVAL_LEDOff(LED3);
				STM_EVAL_LEDOff(LED4);
				UBPressed=0;
				PB_Config();
				resetTimerLong();
				toggle = 1;
				rand = randomNumber();//generate a random number 
			}

			//this is the to get the wait time for the reaction test.
			if(toggle==1){
					if(num == rand){ //if num is equal to the ramdom gened number turn on the LEDs and reset the timer
							STM_EVAL_LEDOn(LED3);
							STM_EVAL_LEDOn(LED4);
							resetTimerLong();
					}
			}
			//this is the code for when the reaction timer has gone off
			if (UBPressed==1 && toggle==1) {
				 
				//this if statement is to prevent cheating
				//if the number = 0 it means that the user cheated as someone should not be able to get 0
				if(num == 0){
					ExtButtonPressed=0;
					PB_Config();
					externalButton();
					resetTimer();
					toggle = 0;
				}else{
				sprintf(str, "%d", num);
				//this block of code writes to the LCD the lastest user reaction time.
				LCD_DisplayStringLine(LINE(1),  (uint8_t *) "          ");
				LCD_DisplayStringLine(LINE(1),  (uint8_t *) str);
				EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
				//this if statement determines wheter the user has beat their best reaction time
				if(num < VarDataTab[0]){
						VarValue = num;
						EE_WriteVariable(VirtAddVarTab[0],VarValue);
				}
				/*the following block of code writes to the LCD the record reaction time*/
				EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
				sprintf(str, "%d", VarDataTab[0]);
				LCD_DisplayStringLine(LINE(3),  (uint8_t *) "          ");
				LCD_DisplayStringLine(LINE(3),  (uint8_t *) str);
				UBPressed=0;
				PB_Config();
				resetTimerLong();
				toggle = 2; 
			}
			}
			//the user needs to press the button to get the reaction time game going again. 
			//to reset the reaction timer
			if (ExtButtonPressed==1) {
				ExtButtonPressed=0;
				PB_Config();
				externalButton();
				resetTimer();
				toggle = 0;
			}
			
	}
	
}
Ejemplo n.º 15
0
int main(void)
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_ADC_Init();
    MX_SPI1_Init();
    MX_USB_DEVICE_Init();
    MX_TIM14_Init();

    HAL_FLASH_Unlock();
    EE_Init();

    EE_ReadVariable(VirtAddVarTab[0], &x_low_th);
    EE_ReadVariable(VirtAddVarTab[1], &x_high_th);
    EE_ReadVariable(VirtAddVarTab[2], &y_low_th);
    EE_ReadVariable(VirtAddVarTab[3], &y_high_th);

    HAL_FLASH_Lock();

    HAL_ADC_Start_DMA(&hadc, (uint32_t*)axis, 5);

    while (1)
    {
        HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_SET);

        HAL_TIM_Base_Start_IT(&htim14);
        while (!u100ticks) /* do nothing for 100 us */;
        HAL_TIM_Base_Stop_IT(&htim14);
        u100ticks = 0;

        HAL_StatusTypeDef status =
            HAL_SPI_Receive(&hspi1, rx_buffer, sizeof(rx_buffer), 3000);

        switch(status)
        {
        case HAL_OK:
            report.buttons[0] = 0x00;
            // report.buttons[1] = 0x00;
            report.buttons[2] = 0x00;

            if ((rx_buffer[0] & 0xff) != 0xff)   // if all bits of rx_buffer[0] is 1 assume shifter is disconnected
            {
                if (rx_buffer[0] & 4)   report.buttons[0] |= 1;         else report.buttons[0] &= ~1;
                if (rx_buffer[0] & 1)   report.buttons[0] |= (1 << 1);  else report.buttons[0] &= ~(1 << 1);
                if (rx_buffer[0] & 2)   report.buttons[0] |= (1 << 2);  else report.buttons[0] &= ~(1 << 2);
                if (rx_buffer[0] & 8)   report.buttons[0] |= (1 << 3);  else report.buttons[0] &= ~(1 << 3);

                if (rx_buffer[1] & 1)   report.buttons[2] |= 1;         else report.buttons[2] &= ~1;
                if (rx_buffer[1] & 2)   report.buttons[2] |= (1 << 1);  else report.buttons[2] &= ~(1 << 1);
                if (rx_buffer[1] & 4)   report.buttons[2] |= (1 << 2);  else report.buttons[2] &= ~(1 << 2);
                if (rx_buffer[1] & 8)   report.buttons[2] |= (1 << 3);  else report.buttons[2] &= ~(1 << 3);

                if (rx_buffer[1] & 32)  report.buttons[0] |= (1 << 4);  else report.buttons[0] &= ~(1 << 4);
                if (rx_buffer[1] & 128) report.buttons[0] |= (1 << 5);  else report.buttons[0] &= ~(1 << 5);
                if (rx_buffer[1] & 64)  report.buttons[0] |= (1 << 6);  else report.buttons[0] &= ~(1 << 6);
                if (rx_buffer[1] & 16)  report.buttons[0] |= (1 << 7);  else report.buttons[0] &= ~(1 << 7);
            }
            break;

        case HAL_TIMEOUT:
        case HAL_BUSY:
        case HAL_ERROR:
            Error_Handler();
        default:
            report.buttons[0] = 0xff;
            break;
        }

        HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_RESET);
        report.id = 0x01;

        x_axis = ((X_AXIS << 2) + x_axis * 96) / 100;
        y_axis = ((Y_AXIS << 2) + y_axis * 96) / 100;

        if (rx_buffer[0] & 16)
        {
            if (y_axis < y_low_th)   // stick towards player
            {
                report.buttons[1] = 128;
                report.buttons[2] &= ~(1 << 4);
            }
            else if (y_axis > y_high_th)   // stick opposite to player
            {
                report.buttons[1] = 0; // neutral
                report.buttons[2] |= (1 << 4);
            }
            else
            {
                report.buttons[1] = 0; // neutral
                report.buttons[2] &= ~(1 << 4);
            }
        }
        else
        {
            report.buttons[1] &= ~(1 << 7);
            report.buttons[2] &= ~(1 << 4);

            if (y_axis < y_low_th)   // stick towards player
            {
                if (x_axis < x_low_th)
                {
                    if (!report.buttons[1]) report.buttons[1] = 2; // 2nd gear
                }
                else if (!report.buttons[1])
                {
                    report.buttons[1] = (x_axis > x_high_th) ? ((rx_buffer[0] & 64) ? 64 : 32) : 8;
                }
            }
            else
            {
                if (y_axis > y_high_th)   // stick opposite to player
                {
                    if (x_axis < x_low_th)
                    {
                        if (!report.buttons[1]) report.buttons[1] = 1; // 1st gear
                    }
                    else if (!report.buttons[1])
                    {
                        report.buttons[1] = (x_axis > x_high_th) ? 16 : 4;
                    }
                }
                else
                {
                    report.buttons[1] = 0; // neutral
                }
            }
        }

        report.axis[0] = x_axis;
        report.axis[1] = y_axis;

        if (report2send == 2)
        {
            HAL_FLASH_Unlock();

            EE_WriteVariable(VirtAddVarTab[0], x_low_th);
            EE_WriteVariable(VirtAddVarTab[1], x_high_th);
            EE_WriteVariable(VirtAddVarTab[2], y_low_th);
            EE_WriteVariable(VirtAddVarTab[3], y_high_th);

            HAL_FLASH_Lock();
            report2send = 0;
        }

        if (hUsbDeviceFS.pClassData
                && ((USBD_HID_HandleTypeDef *)hUsbDeviceFS.pClassData)->state == HID_IDLE)
        {
            USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t *)&report, sizeof(report));
        }
    }
}
Ejemplo n.º 16
0
int main(void)
{
	uint8_t buf[HID_OUT_BUFFER_SIZE-1], RepeatCounter = 0;
	IRMP_DATA myIRData;
	int8_t ret;
	/* first wakeup slot empty? */
	uint8_t learn_wakeup = eeprom_restore(buf, (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS);

	USB_HID_Init();
	LED_Switch_init();
	IRMP_Init();
	irsnd_init();
	FLASH_Unlock();
	EE_Init();
	Systick_Init();

	while (1) {
		if (!AlarmValue)
			Wakeup();

		wakeup_reset();

		/* test if USB is connected to PC and command is received */
		if (USB_HID_GetStatus() == USB_HID_CONNECTED && USB_HID_ReceiveData(buf) == RX_READY && buf[0] == STAT_CMD) {

			switch ((enum access) buf[1]) {
			case ACC_GET:
				ret = get_handler(buf);
				break;
			case ACC_SET:
				ret = set_handler(buf);
				break;
			case ACC_RESET:
				ret = reset_handler(buf);
				break;
			default:
				ret = -1;
			}

			if (ret == -1) {
				buf[0] = STAT_FAILURE;
				ret = 3;
			} else {
				buf[0] = STAT_SUCCESS;
			}

			/* send configuration data */
			USB_HID_SendData(REPORT_ID_CONFIG, buf, ret);
			toggle_LED();
		}

		/* poll IR-data */
		if (irmp_get_data(&myIRData)) {
			if (learn_wakeup) {
				/* store received wakeup IRData in first wakeup slot */
				eeprom_store((MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS, (uint8_t *) &myIRData);
				learn_wakeup = 0;
			}

			if (!(myIRData.flags)) {
				RepeatCounter = 0;
			} else {
				RepeatCounter++;
			}

			if (RepeatCounter == 0 || RepeatCounter >= MIN_REPEATS) {
				toggle_LED();
				/* if macros are sent already, while the trigger IR data are still repeated,
				 * the receiving device may crash */
				check_macros(&myIRData);
				check_wakeups(&myIRData);
			}

			/* send IR-data */
			memcpy(buf, &myIRData, sizeof(myIRData));
			USB_HID_SendData(REPORT_ID_IR, buf, sizeof(myIRData));
		}
	}
}
Ejemplo n.º 17
0
void native_init(void)
{
	NVIC_InitTypeDef NVIC_InitStructure;
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	uint16_t PrescalerValue = 0;

	/*!< At this stage the microcontroller clock setting is already configured,
	   this is done through SystemInit() function which is called from startup
	   file (startup_stm32f10x_xx.s) before to branch to application main.
	   To reconfigure the default setting of SystemInit() function, refer to
	   system_stm32f10x.c file
	 */

	/* TIM1 clock enable */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

	/* Configure the NVIC Preemption Priority Bits */
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

	/* Enable the TIM1 global Interrupt */
	NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	/* ---------------------------------------------------------------
		TIM1 Configuration: Up counting mode
		TIM1 counter clock at 1 MHz
		TIM1 generates an update event every 1000 pulses
	--------------------------------------------------------------- */

	/* Compute the prescaler value */
	PrescalerValue = (uint16_t) (SystemCoreClock/1000000) - 1;

	/* Time base configuration */
	TIM_TimeBaseStructure.TIM_Prescaler = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseStructure.TIM_Period = 1000;
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_RepetitionCounter	= 0;

	TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

	/* Prescaler configuration */
	TIM_PrescalerConfig(TIM1, PrescalerValue, TIM_PSCReloadMode_Immediate);

	/* Auto-reload preload configuration */
	TIM_ARRPreloadConfig(TIM1, ENABLE);

	/* TIM IT enable */
	TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

	/* TIM1 enable counter */
	TIM_Cmd(TIM1, ENABLE);

	/* Unlock the Flash Program Erase controller */
	FLASH_Unlock();

	/* EEPROM Init */
	EE_Init();
}
Ejemplo n.º 18
0
int main(void)
{
	uint8_t buf[HID_OUT_BUFFER_SIZE-1];
	IRMP_DATA myIRData;
	int8_t ret;

	LED_Switch_init();
	Systick_Init();
	USB_Reset();
	USB_HID_Init();
	USB_DISC_release();
	IRMP_Init();
	irsnd_init();
	FLASH_Unlock();
	EE_Init();
	irmp_set_callback_ptr (led_callback);

	while (1) {
		if (!AlarmValue)
			Wakeup();

		if (!send_ir_on_delay)
			send_magic();

		wakeup_reset();

		/* test if USB is connected to PC, sendtransfer is complete and configuration command is received */
		if (USB_HID_GetStatus() == CONFIGURED && PrevXferComplete && USB_HID_ReceiveData(buf) == RX_READY && buf[0] == STAT_CMD) {

			switch ((enum access) buf[1]) {
			case ACC_GET:
				ret = get_handler(buf);
				break;
			case ACC_SET:
				ret = set_handler(buf);
				break;
			case ACC_RESET:
				ret = reset_handler(buf);
				break;
			default:
				ret = -1;
			}

			if (ret == -1) {
				buf[0] = STAT_FAILURE;
				ret = 3;
			} else {
				buf[0] = STAT_SUCCESS;
			}

			/* send configuration data */
			USB_HID_SendData(REPORT_ID_CONFIG, buf, ret);
			blink_LED();
			if(Reboot)
				reboot();
		}

		/* poll IR-data */
		if (irmp_get_data(&myIRData)) {
			myIRData.flags = myIRData.flags & IRMP_FLAG_REPETITION;
			if (!(myIRData.flags)) {
				store_wakeup(&myIRData);
				check_macros(&myIRData);
				check_wakeups(&myIRData);
				check_resets(&myIRData);
				check_reboot(&myIRData);
			}

			/* send IR-data */
			USB_HID_SendData(REPORT_ID_IR, (uint8_t *) &myIRData, sizeof(myIRData));
		}
	}
}
Ejemplo n.º 19
0
void EE_INIT(void)
{
	EE_Init();
}
Ejemplo n.º 20
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
	
//initiate user button
  //PB_Config();
	STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

	//initiate LEDs and turn them on
  LED_Config();	
	
 

  /* -----------------------------------------------------------------------
    TIM3 Configuration: Output Compare Timing Mode:
    
    In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
    since APB1 prescaler is different from 1.   
      TIM3CLK = 2 * PCLK1  
      PCLK1 = HCLK / 4 
      => TIM3CLK = HCLK / 2 = SystemCoreClock /2
          
    To get TIM3 counter clock at 50 MHz, the prescaler is computed as follows:
       Prescaler = (TIM3CLK / TIM3 counter clock) - 1
       Prescaler = ((SystemCoreClock /2) /0.5 MHz) - 1
                                              
    CC1 update rate = TIM3 counter clock / CCR1_Val = 10.0 Hz
    ==> Toggling frequency = 5 Hz

    Note: 
     SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
     Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
     function to update SystemCoreClock variable value. Otherwise, any configuration
     based on this variable will be incorrect.    
		 ----------------------------------------------------------------------- */ 	
	
	//=======================Configure and init Timer======================
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 500000) - 1; //configures clock speed at 500 KHz. Both Tim2 and Tim3 use the same prescsaler and therefore run at the same speed.

 /* TIM Configuration */
  TIM3_Config();
	TIM2_Config();

	// configure the output compare
	TIM3_OCConfig();
	TIM2_OCConfig();

  /* TIM Interrupts enable */
  TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
	TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
	
  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
	TIM_Cmd(TIM2, ENABLE); 
	
//======================================configure and init LCD  ======================	
	 /* LCD initiatization */
  LCD_Init();
  
  /* LCD Layer initiatization */
  LCD_LayerInit();
    
  /* Enable the LTDC */
  LTDC_Cmd(ENABLE);
  
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
	
//================EEPROM init====================================

/* Unlock the Flash Program Erase controller */
		FLASH_Unlock();
		/* EEPROM Init */
		EE_Init();

//============ Set up for random number generation==============
	RNG_Config();
	Ext_PushButton_Interrupt(); //configures external push button

	//with the default font, LCD can display  12 lines of chars, they are LINE(0), LINE(1)...LINE(11) 
	//with the default font, LCD can display  15 columns, they are COLUMN(0)....COLUMN(14)


		LCD_Clear(LCD_COLOR_WHITE); //change the background colour of LCD 
			
		//Display a string in one line, on the first line (line=0)
		LCD_DisplayString(0, 2, (uint8_t *) "Best: ");  //the line will not wrap
		
  while (1){ 
		
			if (UBPressed==1) { //press user button
					if (pause==1){	//pause mode
						randnum = ((RNG_GetRandomNumber()%2000)+1000); //generates a random number between 1000 and 3000
						Pause_Random(randnum); //see below function to see how the pause is implemented
					}
					else { //measure time mode
						TIM_ITConfig(TIM2, TIM_IT_CC1, DISABLE); //turns off timer 2
						TIM_Cmd(TIM2, DISABLE);
						time = timer; //gets user's time
						if (initial == 1) { //sets initial best_time to first time 
						best_time = time; 
						initial = 0;
						LCD_DisplayInt((uint16_t) 0, (uint16_t) 7, best_time);
						} 
						LCD_DisplayString(2, 1, (uint8_t *) "Time: "); //print time
						LCD_DisplayString(2, 7, (uint8_t *) "                 "); //clears line
						LCD_DisplayInt((uint16_t) 2, (uint16_t) 7, time); //displays user's time
						LCD_DisplayString(2, 11, (uint8_t *) "ms"); //print ms
						if (time > 10 && time < best_time) { //set new best time
							best_time = time;
							LCD_DisplayString(0, 7, (uint8_t *) "          "); //clears line
							LCD_DisplayInt((uint16_t) 0, (uint16_t) 7, best_time);
						}
						TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE); //turns on timer 2
						TIM_Cmd(TIM2, ENABLE);
						pause = 1; //this makes it so that you can use the user button to repeat the cycle in case you don't have an external push button
					}
				UBPressed=0;				
			}

	}
}
Ejemplo n.º 21
0
void calibrate_init(void)
{
    float_pack_t pack;
    bool found_acc_matrix = 0;

    // Make FLASH writable while initializing the virtual EEPROM
    FLASH_Unlock();
    EE_Init();
    FLASH_Lock();

    // Set defaults of no change if any of the values are not found
    if (EE_ReadVariable(EE_GYRO_OFF_X_L, &pack.s[0]) || EE_ReadVariable(EE_GYRO_OFF_X_H, &pack.s[1]))
        g_cal.gyro_offset[0] = 0.0;
    else
        g_cal.gyro_offset[0] = pack.f;

    if (EE_ReadVariable(EE_GYRO_OFF_Y_L, &pack.s[0]) || EE_ReadVariable(EE_GYRO_OFF_Y_H, &pack.s[1]))
        g_cal.gyro_offset[1] = 0.0;
    else
        g_cal.gyro_offset[1] = pack.f;

    if (EE_ReadVariable(EE_GYRO_OFF_Z_L, &pack.s[0]) || EE_ReadVariable(EE_GYRO_OFF_Z_H, &pack.s[1]))
        g_cal.gyro_offset[2] = 0.0;
    else {
        g_cal.gyro_offset[2] = pack.f;
        // mark if we were able to successfully load a gyro offset from EEPROM
        stored_gyro_offset = 1;
    }

    // Read the 3x3 scale and cross axis matrix
    for (uint8_t i = 0; i < 3; i++) {
        for (uint8_t j = 0; j < 3; j++) {
            if (EE_ReadVariable(EE_GYRO_SCALE_START + (i*3 + j)*2, &pack.s[0]) || EE_ReadVariable(EE_GYRO_SCALE_START + (i*3 + j)*2 + 1, &pack.s[1]))
                // Fill missing values with the identity matrix
                g_cal.gyro_scale[i][j] = (i == j) ? 1.0 : 0.0;
            else
                g_cal.gyro_scale[i][j] = pack.f;
        }
    }

    // Read the 3x3 scale and cross axis matrix
    for (uint8_t i = 0; i < 3; i++) {
        for (uint8_t j = 0; j < 3; j++) {
            if (EE_ReadVariable(EE_ACC_SCALE_START + (i*3 + j)*2, &pack.s[0]) || EE_ReadVariable(EE_ACC_SCALE_START + (i*3 + j)*2 + 1, &pack.s[1])) {
                // Fill missing values with the identity matrix
                g_cal.acc_scale[i][j] = (i == j) ? 1.0 : 0.0;
            } else {
                g_cal.acc_scale[i][j] = pack.f;
                found_acc_matrix = 1;
            }
        }
    }

    if (!found_acc_matrix)
        init_legacy_acc();

    if (EE_ReadVariable(EE_ACC_OFF_X_L, &pack.s[0]) || EE_ReadVariable(EE_ACC_OFF_X_H, &pack.s[1]))
        g_cal.acc_offset[0] = 0.0;
    else
        g_cal.acc_offset[0] = pack.f;

    if (EE_ReadVariable(EE_ACC_OFF_Y_L, &pack.s[0]) || EE_ReadVariable(EE_ACC_OFF_Y_H, &pack.s[1]))
        g_cal.acc_offset[1] = 0.0;
    else
        g_cal.acc_offset[1] = pack.f;

    if (EE_ReadVariable(EE_ACC_OFF_Z_L, &pack.s[0]) || EE_ReadVariable(EE_ACC_OFF_Z_H, &pack.s[1]))
        g_cal.acc_offset[2] = 0.0;
    else
        g_cal.acc_offset[2] = pack.f;

    if (EE_ReadVariable(EE_TEMPERATURE_L, &pack.s[0]) || EE_ReadVariable(EE_TEMPERATURE_H, &pack.s[1]))
        g_cal.temperature = 0.0;  // Just pick a fake temperature
    else
        g_cal.temperature = pack.f;

    // If we have calibration, and the calibration was performed with the cross
    // axis sign error, fix it
    if (found_acc_matrix) {
        uint16_t version = 0;
        EE_ReadVariable(EE_CAL_VERSION, &version);
        // CALIBRATE_HD and newer have the fix
        if (version < CALIBRATE_HD) {
            fix_cross_axis();
        }
    }

    // Start at the factory calibrated gyro offset
    memcpy(current_offset.offset, g_cal.gyro_offset, sizeof(float)*3);
    current_offset.temperature_actual = g_cal.temperature;

    // Initialize the gyro offset temperature bins
    temperature_init(&current_offset);
}
Ejemplo n.º 22
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
  
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock to have a system clock = 180 Mhz */
  SystemClock_Config();
  
   /* Unlock the Flash Program Erase controller */
  HAL_FLASH_Unlock();
  
  /* Configure LED1 */
  BSP_LED_Init(LED1);

  /* EEPROM Init */
  if( EE_Init() != EE_OK)
  {
    Error_Handler();
  }
  
  /* --- Store successively many values of the three variables in the EEPROM ---*/
  /* Store 0x1000 values of Variable1 in EEPROM */
  for (VarValue = 1; VarValue <= 0x1000; VarValue++)
  {
    /* Sequence 1 */
    if((EE_WriteVariable(VirtAddVarTab[0],  VarValue)) != HAL_OK)
    {
      Error_Handler();
    }
    if((EE_ReadVariable(VirtAddVarTab[0],  &VarDataTab[0])) != HAL_OK)
    {
      Error_Handler();
    }
    if (VarValue != VarDataTab[0])
    {
      Error_Handler();
    }
    
    /* Sequence 2 */
    if(EE_WriteVariable(VirtAddVarTab[1], ~VarValue) != HAL_OK)
    {
      Error_Handler();
    }  
    if(EE_ReadVariable(VirtAddVarTab[1],  &VarDataTab[1]) != HAL_OK)
    {
      Error_Handler();
    } 
    if(((uint16_t)~VarValue) != VarDataTab[1])
    {
      Error_Handler();
    }

    /* Sequence 3 */
    if(EE_WriteVariable(VirtAddVarTab[2],  VarValue << 1) != HAL_OK)
    {
      Error_Handler();
    }
    if(EE_ReadVariable(VirtAddVarTab[2],  &VarDataTab[2]) != HAL_OK)
    {
      Error_Handler();
    } 
    if ((VarValue << 1) != VarDataTab[2])
    {
      Error_Handler();
    }
  }

  /* Store 0x2000 values of Variable2 in EEPROM */
  for (VarValue = 1; VarValue <= 0x2000; VarValue++)
  {
    if(EE_WriteVariable(VirtAddVarTab[1], VarValue) != HAL_OK)
    {
      Error_Handler();
    }      
    if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]) != HAL_OK)
    {
      Error_Handler();
    }    
    if(VarValue != VarDataTab[1])
    {
      Error_Handler();
    }
  }

  /* read the last stored variables data*/
  if(EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK)
  {
    Error_Handler();
  }   
  if (VarDataTmp != VarDataTab[0])
  {
    Error_Handler();
  }

  if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTmp) != HAL_OK)
  {
    Error_Handler();
  }    
  if (VarDataTmp != VarDataTab[1])
  {
    Error_Handler();
  }

  if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTmp) != HAL_OK)
  {
    Error_Handler();
  }    
  if (VarDataTmp != VarDataTab[2])
  {
    Error_Handler();
  }
  
  /* Store 0x3000 values of Variable3 in EEPROM */
  for (VarValue = 1; VarValue <= 0x3000; VarValue++)
  {
    if(EE_WriteVariable(VirtAddVarTab[2], VarValue) != HAL_OK)
    {
      Error_Handler();
    }      
    if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]) != HAL_OK)
    {
      Error_Handler();
    }    
    if(VarValue != VarDataTab[2])
    {
      Error_Handler();
    }
  }

  /* read the last stored variables data*/
  if(EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK)
  {
    Error_Handler();
  }    
  if (VarDataTmp != VarDataTab[0])
  {
    Error_Handler();
  }

  if(EE_ReadVariable(VirtAddVarTab[1], &VarDataTmp) != HAL_OK)
  {
    Error_Handler();
  }
  if (VarDataTmp != VarDataTab[1])
  {
    Error_Handler();
  }

  if(EE_ReadVariable(VirtAddVarTab[2], &VarDataTmp) != HAL_OK)
  {
    Error_Handler();
  }  
  if (VarDataTmp != VarDataTab[2])
  {
    Error_Handler();
  }

  while (1)
  {
    /* Turn LED1 On */
    BSP_LED_On(LED1);
  }
}
Ejemplo n.º 23
0
//*----------------------------------------------------------------------------
//* Function Name       : main
//* Object              :
//* Object              :
//* Input Parameters    :
//* Output Parameters   :
//* Functions called    :
//*----------------------------------------------------------------------------
int main(void)
{
//	uchar i;

	// Set unbuffered mode for stdout (newlib)
	//setvbuf( stdout, 0, _IONBF, 0 );

//	SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);

	// HW init
	mchf_board_init();


	// Power on
	mchf_board_green_led(1);

	// Set default transceiver state
	TransceiverStateInit();

	// Virtual Eeprom init
	ts.ee_init_stat = EE_Init();	// get status of EEPROM initialization

	// Show logo
	UiLcdHy28_ShowStartUpScreen(100);

	// Extra init
	MiscInit();

	// Init the RX Hilbert transform/filter prior
	// to initializing the audio!
	//
	UiCalcRxPhaseAdj();
	//
	// Init TX Hilbert transform/filter
	//
	UiCalcTxPhaseAdj();	//

	UiDriverLoadFilterValue();	// Get filter value so we can init audio with it

	// Audio HW init
	audio_driver_init();

	// Usb Host driver init
	//keyb_driver_init();

	// UI HW init
	ui_driver_init();

	// Audio HW init - again, using EEPROM-loaded values
	audio_driver_init();
	//
	ts.audio_gain_change = 99;		// Force update of volume control
	uiCodecMute(0);					// make cure codec is un-muted

	UiCheckForEEPROMLoadDefaultRequest();	// check - and act on - request for loading of EEPROM defaults, if any


#ifdef DEBUG_BUILD
	printf("== main loop starting ==\n\r");
#endif

	// Transceiver main loop
	for(;;)
	{
		// UI events processing
		ui_driver_thread();

		// Audio driver processing
		//audio_driver_thread();

		// USB Host driver processing
		//usbh_driver_thread();

		// Reset WD - not working
		//wd_reset();
	}
}