コード例 #1
0
ファイル: channels.c プロジェクト: PhracturedBlue/deviation
s32 CHAN_ReadRawInput(int channel)
{
    s32 value = 0;
    if ((~Transmitter.ignore_src & SWITCH_STOCK) == SWITCH_STOCK) {
      switch(channel) {
        case INP_HOLD0:    value = gpio_get(GPIOC, GPIO11); break;
        case INP_HOLD1:    value = ! gpio_get(GPIOC, GPIO11); break;
        case INP_FMOD0:    value = gpio_get(GPIOC, GPIO10); break;
        case INP_FMOD1:    value = ! gpio_get(GPIOC, GPIO10); break;
        case INP_SWA0:     value = global_extra_switches   & 0x04;  break;
        case INP_SWA1:     value = !(global_extra_switches & 0x0c); break;
        case INP_SWA2:     value = global_extra_switches   & 0x08;  break;
        case INP_SWB0:     value = global_extra_switches   & 0x01;  break;
        case INP_SWB1:     value = !(global_extra_switches & 0x03); break;
        case INP_SWB2:     value = global_extra_switches   & 0x02;  break;
        case INP_SWG0:     value = global_extra_switches   & 0x04;  break;
        case INP_SWG1:     value = !(global_extra_switches & 0x0c); break;
        case INP_SWH0:     value = global_extra_switches   & 0x01;  break;
        case INP_SWH1:     value = !(global_extra_switches & 0x03); break;
      }
    } else {
      if ((~Transmitter.ignore_src & SWITCH_3x1) == SWITCH_3x1) {
        switch(channel) {
          case INP_SWA0:  value = (global_extra_switches & (1 << (SW_02 - 1))); break;
          case INP_SWA1:  value = (!(global_extra_switches & (1 << (SW_01 - 1))) && !(global_extra_switches & (1 << (SW_02 - 1)))); break;
          case INP_SWA2:  value = (global_extra_switches & (1 << (SW_01 - 1))); break;
        }
      } else if ((~Transmitter.ignore_src & SWITCH_2x8) == SWITCH_2x8) {
        switch(channel) {
          case INP_SWA0:  value = !(global_extra_switches & (1 << (SW_03 - 1))); break;
          case INP_SWA1:  value = (global_extra_switches & (1 << (SW_03 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_3x2) == SWITCH_3x2) {
        switch(channel) {
          case INP_SWB0:  value = (global_extra_switches & (1 << (SW_04 - 1))); break;
          case INP_SWB1:  value = (!(global_extra_switches & (1 << (SW_03 - 1))) && !(global_extra_switches & (1 << (SW_04 - 1)))); break;
          case INP_SWB2:  value = (global_extra_switches & (1 << (SW_03 - 1))); break;
        }
      } else if ((~Transmitter.ignore_src & SWITCH_2x7) == SWITCH_2x7) {
        switch(channel) {
          case INP_SWB0:  value = !(global_extra_switches & (1 << (SW_04 - 1))); break;
          case INP_SWB1:  value = (global_extra_switches & (1 << (SW_04 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_3x3) == SWITCH_3x3) {
        switch(channel) {
          case INP_SWC0:  value = (global_extra_switches & (1 << (SW_06 - 1))); break;
          case INP_SWC1:  value = (!(global_extra_switches & (1 << (SW_05 - 1))) && !(global_extra_switches & (1 << (SW_06 - 1)))); break;
          case INP_SWC2:  value = (global_extra_switches & (1 << (SW_05 - 1))); break;
        }
      } else if ((~Transmitter.ignore_src & SWITCH_2x6) == SWITCH_2x6) {
        switch(channel) {
          case INP_SWC0:  value = !(global_extra_switches & (1 << (SW_05 - 1))); break;
          case INP_SWC1:  value = (global_extra_switches & (1 << (SW_05 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_3x4) == SWITCH_3x4) {
        switch(channel) {
          case INP_SWD0:  value = (global_extra_switches & (1 << (SW_08 - 1))); break;
          case INP_SWD1:  value = (!(global_extra_switches & (1 << (SW_07 - 1))) && !(global_extra_switches & (1 << (SW_08 - 1)))); break;
          case INP_SWD2:  value = (global_extra_switches & (1 << (SW_07 - 1))); break;
        }
      } else if ((~Transmitter.ignore_src & SWITCH_2x5) == SWITCH_2x5) {
        switch(channel) {
          case INP_SWD0:  value = !(global_extra_switches & (1 << (SW_06 - 1))); break;
          case INP_SWD1:  value = (global_extra_switches & (1 << (SW_06 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_2x4) == SWITCH_2x4) {
        switch(channel) {
          case INP_SWE0:  value = !(global_extra_switches & (1 << (SW_07 - 1))); break;
          case INP_SWE1:  value = (global_extra_switches & (1 << (SW_07 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_2x3) == SWITCH_2x3) {
        switch(channel) {
          case INP_SWF0:  value = !(global_extra_switches & (1 << (SW_08 - 1))); break;
          case INP_SWF1:  value = (global_extra_switches & (1 << (SW_08 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_2x2) == SWITCH_2x2) {
        switch(channel) {
          case INP_SWG0:  value = !(global_extra_switches & (1 << (SW_09 - 1))); break;
          case INP_SWG1:  value = (global_extra_switches & (1 << (SW_09 - 1))); break;
        }
      }
      if ((~Transmitter.ignore_src & SWITCH_2x1) == SWITCH_2x1) {
        switch(channel) {
          case INP_SWH0:  value = !(global_extra_switches & (1 << (SW_10 - 1))); break;
          case INP_SWH1:  value = (global_extra_switches & (1 << (SW_10 - 1))); break;
        }
      }
    }
    if ((~Transmitter.ignore_src & POT_1) == POT_1) {
      switch(channel) {
        case INP_AUX4: value = adc_array_raw[4]; break;
      }
    }
    if ((~Transmitter.ignore_src & POT_2) == POT_2) {
      switch(channel) {
        case INP_AUX5:  value = adc_array_raw[5]; break;
      }
    }
    switch(channel) {
      case INP_THROTTLE: value = adc_array_raw[0]; break;  // bug fix: right vertical
      case INP_AILERON:   value = adc_array_raw[1]; break;  // bug fix: right horizon
      case INP_RUDDER: value = adc_array_raw[2]; break;  // bug fix: left horizon
      case INP_ELEVATOR:  value = adc_array_raw[3]; break;  // bug fix: left vertical
    }
    return value;
}
コード例 #2
0
ファイル: test.c プロジェクト: npic/rtvmc
errcode_t test_step(test_t * test)
{
    errcode_t retval;
    uint16_t i;
    uint8_t pin_val;
    /*
    char uart_out_char = 0;
    */
    retval = reschedule(&test->uut);
    CHECK_OK(retval, "Failed to do scheduling\n");
    test->uut.PP = test->uut.NPP;
    for (i = 0; i < test->uut.proc_table_size; i++)
    {
        if (test->uut.PP == i)
        {
            fprintf(test->schedules[i], "%u 1\n", test->uut.time);
        }
        else
        {
            fprintf(test->schedules[i], "%u 0\n", test->uut.time);
        }
    }
    for (i = 0; i < test->input_size; i++)
    {
        if (test->gpio_input[i].time == test->uut.time)
        {
            retval = gpio_set(test->gpio_input[i].pin, test->gpio_input[i].value);
            CHECK_OK(retval, "Failed to set test pin\n");
        }
        /*
        if (test->timings[i] == test->uut.time)
        {
            retval = enqueue(&test->uut.uart.in, test->input[i]);
            CHECK_OK(retval, "Failed to enqueue a test input\n");
            fprintf(test->uart_in, "%hu %hd\n", test->uut.time, (int16_t)test->input[i]);
            CHECK_NOT_FERROR(test->uart_in);
            break;
        }
        */
    }
    for (i = 0; i < TEST_PIN_COUNT; i++)
    {
        retval = gpio_get(i, &pin_val);
        CHECK_OK(retval, "Failed to get test pin\n");
        fprintf(test->gpio_files[i], "%u %u\n", test->uut.time, pin_val);
    }
    /*
    if (i == test->input_size)  / * i.e. there is no input this time * /
    {
        fprintf(test->uart_in, "%hu 0\n", test->uut.time);
        CHECK_NOT_FERROR(test->uart_in);
    }
    retval = dequeue(&test->uut.uart.out, &uart_out_char);
    CHECK_OK(retval, "Failed to dequeue from UART out\n");
    fprintf(test->uart_out, "%hu %hd\n", test->uut.time, (int16_t)uart_out_char);
    CHECK_NOT_FERROR(test->uart_out);
    */
    test->uut.proc_table[test->uut.PP].current_observed_time++;
    retval = step(&test->uut);
    test->uut.time++;
    CHECK_OK(retval, "Failed to execute instruction\n");
    if (test->uut.time >= test->test_length)
    {
        finish_test(test);
    }
    return OK;
}
コード例 #3
0
static long
gpio_ioctl(struct file * file, unsigned int cmd,
	   unsigned long arg)

{
	unsigned long val;

	switch(cmd)
	{
		case GPIO_CMD_SET_BTN_RST:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;
			if (val)
				DO_RESET();
			break;
		case GPIO_CMD_GET_BTN_RST:
			val = BUTTON_RESET();
			if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_SET_LED_BTN_WLAN:
			if (vs_sysid != VS_SYSID_ARETE)
			    return -EFAULT;
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	    return -EFAULT;
	        	gpio_set(LED_BTN_WLAN_MASK,!val?LED_BTN_WLAN_MASK:0UL);
			break;
		case GPIO_CMD_GET_BTN_WLAN:
			if (vs_sysid != VS_SYSID_ARETE)
			    return -EFAULT;
			val = BUTTON_WLAN();
			if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_SET_LEDS:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;
			gpio_set(MASK_LEDS, led2reg(val));
			break;
		case GPIO_CMD_GET_LEDS:
			val = LEDS(gpio_get());
			if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_SET_LED_POWER:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;
			gpio_set(LED_POWER_MASK, val?LED_POWER_MASK:0UL);
			break;
		case GPIO_CMD_SET_LED_BLUE:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;
			gpio_set(LED_BLUE_MASK, val?LED_BLUE_MASK:0UL);
			break;
		case GPIO_CMD_SET_LED_GREEN:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;
			gpio_set(LED_GREEN_MASK, val?LED_GREEN_MASK:0UL);
			break;

		// buzzer
		case GPIO_CMD_SET_BUZZER:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;
			if (val == 1)
				set_buzzer(1);
			else if(val == 0)
				set_buzzer(0);
			else
				return -EINVAL;
			break;
		case GPIO_CMD_GET_BUZZER:
			val = (gpio_get() & BUZZER_MASK)?1:0;
			if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_SET_BUZZER_FRQ:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(val)))
	        	return -EFAULT;

			if((val < FREQ_MIN) || (val > FREQ_MAX))
				return -EINVAL;

			// check if thread has been already activated
			if(freq_thread != NULL)
			{
				kthread_stop(freq_thread);
				freq_thread = NULL;
			}

			buzzer_freq = val;
			freq_thread = kthread_run(buzzer_thread, NULL, "buzzer thread");
			if(IS_ERR(freq_thread))
			{
				printk("Error starting kthread\n");
				freq_thread = NULL;
			}
			break;
		case GPIO_CMD_GET_BUZZER_FRQ:
			val = buzzer_freq;
			if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;

		// external GPIOs
		case GPIO_CMD_SET:
			{
				struct gpio_struct set;
				
    			if (copy_from_user(&set, (struct gpio_struct*)arg, sizeof(set)))
		        	return -EFAULT;
				
				gpio_ext_set(set.mask, set.value);
			}
			break;
		case GPIO_CMD_GET:
			val = gpio_ext_get();
    		if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_SET_CTRL:
   			{
				struct gpio_struct set;
				
    			if (copy_from_user(&set, (struct gpio_struct*)arg, sizeof(set)))
		        	return -EFAULT;
				
			// relays are not to be switched to input and isolated inputs are not to be switched to output
			if(vs_sysid == VS_SYSID_ALENA)
			{
				if((set.mask & GPIO_BIT_0 && set.value & GPIO_BIT_0) || (set.mask & GPIO_BIT_1 && set.value & GPIO_BIT_1) ||
				    (set.mask & GPIO_BIT_6 && !(set.value & GPIO_BIT_6)) || (set.mask & GPIO_BIT_7 && !(set.value & GPIO_BIT_7)))
					return -EINVAL;
			}	
				gpio_ext_set_mode(set.mask, set.value);
			}
			break;
		case GPIO_CMD_GET_CTRL:
			val = gpio_ext_get_mode();
    		if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_SET_IRQMASK:
   			{
				struct gpio_struct set;
				
    			if (copy_from_user(&set, (struct gpio_struct*)arg, sizeof(set)))
		        	return -EFAULT;
				
				gpio_ext_set_irqmask(set.mask, set.value);
			}
			break;
		case GPIO_CMD_GET_IRQMASK:
			val = gpio_ext_get_irqmask();
    		if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_GET_CHANGE:
			val = gpio_ext_get_change();
    		if (copy_to_user((unsigned long *)arg, &val, sizeof(val)))
		       	return -EFAULT;
			break;
		case GPIO_CMD_GET_CHANGES:
   			if (copy_from_user(&val, (unsigned long*)arg, sizeof(unsigned long)))
	        	return -EFAULT;
			if (val >= NUMBER_OF_GPIOS)
				return -EFAULT;
    		if (copy_to_user((unsigned long*)arg, &gpio_ext_irq_changes[val], sizeof(gpio_ext_irq_changes[0])))
		       	return -EFAULT;
			break;
		default:
			return -EINVAL;
	}
	return 0;
}
コード例 #4
0
ファイル: touchscreen-hw.c プロジェクト: lireric/ssn
static int GPIO_GetInputState(uint16_t pin)
{
	return gpio_get(TS_PORT, pin);
}
コード例 #5
0
char cc3k_get_irq(void) {
    return gpio_get(GPIOC, CC3000_IRQ)!=0;
}
コード例 #6
0
ファイル: main.c プロジェクト: Needrom/Freescale
  void main(void)
{
	int i1=0;
	int count10S = 0;
	Device_init();
        disable_irq(PIT0_IRQn);
        systick_delay_ms(50);
        FLOAT_LDC_init(SPI1);
        systick_delay_ms(50);
        FLOAT_LDC_init(SPI0);
        systick_delay_ms(1000);
        uart_init(UART3,115200);
        key_init(0);
        key_init(1);
        key_init(2);
        //LDC_EVM_TEST();
        
        //Speed_Ctl_Init(short point_value, double dKpp, double dKii, double dKdd);
        
      while(1)
      {
        //value_collect();
    
       LCD_P6x8Str(0,2,"Rmax Lmin");
        printf("Rmax Rmin\r\n");
        systick_delay_ms(1500);
        i1=50;
        
        while(i1--)
       {
           adjustment[2]=(float)filter(SPI1)/10;//右max
           LCD_BL(55,2,(uint16)adjustment[2]);
           printf("%d\r\n",adjustment[2]);
       }
        
       i1=50;
       while(i1--)
       {
          adjustment[1]=(float)filter(SPI0)/10;//左min
          LCD_BL(90,2,(uint16)adjustment[1]);
          printf("%d\r\n",adjustment[1]);
       }
       
       LCD_BL(55,2,(uint16)adjustment[1]);
       LCD_BL(90,2,(uint16)adjustment[2]);      
        
        
    
       LCD_P6x8Str(0,4,"Lmax Rmin");
       printf("Lmax Rmin\r\n");
       systick_delay_ms(1500);
       i1=50;
       while(i1--)
       {
       adjustment[3]=(float)filter(SPI1)/10;//右min
       LCD_BL(55,4,(uint16)adjustment[3]);
       printf("%d\r\n",adjustment[3]);
       }
        
       i1=50;
       while(i1--)
       {
        adjustment[4]=(float)filter(SPI0)/10;//左max
        LCD_BL(90,4,(uint16)adjustment[4]);
        printf("%d\r\n",adjustment[4]);
       }
       
       LCD_BL(55,4,(uint16)adjustment[4]);
       LCD_BL(90,4,(uint16)adjustment[3]);
       
       if(adjustment[1]<=adjustment[3])
         adjustment[5]=adjustment[1];//次小值
       else
         adjustment[5]=adjustment[3];//次小值
       
       if(adjustment[2]>=adjustment[4])
         adjustment[6]=adjustment[2];//次大值
       else
         adjustment[6]=adjustment[4];//次大值
       
       divisor = (adjustment[2] - adjustment[3])/60;                              //48 //50
       divisor2 = (adjustment[4] - adjustment[1])/59;                             //48 //45
       
       zengfuzhi =  (adjustment[2] - adjustment[3])/(adjustment[4] - adjustment[1]);
//       for(int i=0;i<10;i++)
//       {
//         printf("%d\r\n",adjustment[i]);
//       }
//       systick_delay_ms(1000);
       
       
          
       LCD_P6x8Str(0,6,"Mid value");
        i1 = 50;
       systick_delay_ms(1500);
       while(i1--)
       {
        adjustment[7]=(float)filter(SPI0)/10;//左
        adjustment[8]=(float)filter(SPI1)/10;//右
        LCD_BL(55,6,(uint16)adjustment[7]);
        LCD_BL(90,6,(uint16)adjustment[8]);
       }
            if(adjustment[7]>=adjustment[8])
       { flag=1;
       adjustment[0]=adjustment[7]-adjustment[8];
       }
       else
       {
         flag=0;
       adjustment[0]=adjustment[8]-adjustment[7]; 
       }
       
       LCD_Fill(0x00);
       
       Out_side_collect();
       
       LCD_Fill(0x00);
       
       adjustment_change();
       
       enable_irq(PIT0_IRQn);
          while(1)
          { 
                  
                  if(PIT_1sFlag == 1)
                  {
                        gpio_turn(PTD4);
                        PIT_1sFlag = 0;
                        count10S ++;
                  }
                  if(key_check(2) == 0)
                  {
                    LCD_Fill(0x00);
                    Motor_stop();
                    break;
                  }
                  else
                  {
                    if(PIT_5msFlag == 1)
                    {
                      LDC_get();
                      PIT_5msFlag = 0;
                      Steering_Change();
                    }
                    if(count10S > 10)
                    {  
                      if(gpio_get(PTC4) == 0)
                      {
                        while(1)
                        {
                          Motor_stop();
                          Steering_Change();
                        }
                      }
                    }
                    if(PIT_10msFlag == 1)
                    {
                      Quad_count();
                      now = (float)guad_val;
                      Motor_PID(now);
                      PIT_10msFlag = 0;
                      
                    }
                    if(PIT_20msFlag == 1)
                    {

                      PIT_20msFlag = 0;
                    }
                    if(PIT_50msFlag == 1)
                    {
                      
                      //Result_collect();
                      PIT_50msFlag = 0;
                    }
 
                    
                    //printf("guad_val:%d \r\n",(guad_val));
                    
                    //TEST_display();
                    speed_control();
                    
                    //key_choice();
                    uint16 i23 = gpio_get(PTC4); 
                    
                    //LCD_BL(50,2,(uint16)(i23));
                  }
          }
      }
}
コード例 #7
0
ファイル: main.c プロジェクト: chenxuuu/SmartCar
/*!
 *  @brief      OLED显示
 *  @since      v1.0
 *  @note       没啥
 *  Sample usage:           oled_display();
 */
void oled_display()
{
    //第一行显示拨码开关状态
    OLED_P6x8Str(0, 0, "12345678");
    OLED_P6x8Str(50, 0, "speed:");	    Display_number(86, 0, vPID.Setpoint);
    OLED_P6x8Str(50, 1, "Error:");	    Display_number(86, 1, Error);
    OLED_P6x8Str(0, 2, "slope:");	    DisplayFloat(36, 2, slope.slope);
    OLED_P6x8Str(80, 2, "P:");	        DisplayFloatpid(92, 2, actuator_P);
    OLED_P6x8Str(0, 3, "Distance:");	Display_number(54, 3, distance);
    OLED_P6x8Str(86, 3, "D:");	        DisplayFloatpid(98, 3, actuator_D);
    OLED_P6x8Str(0, 4, "Bluetooth:");   
    if(bluetooth == 1)
        OLED_P6x8Str(60, 4, "connected ");
    else if(bluetooth == 0)
        OLED_P6x8Str(60, 4, "disconnect");
    else
        OLED_P6x8Str(60, 4, "off       ");
    OLED_P6x8Str(0, 5, "stop?");
    if(stop_done)
        OLED_P6x8Str(36, 5, "yes");
    else
        OLED_P6x8Str(36, 5, "no");

    #if ( CAR_NUMBER == 1 )
        OLED_P6x8Str(0, 7, "Interesting");
        OLED_P6x8Str(91, 7, "Car:1A");
    #endif
    #if ( CAR_NUMBER == 2 )
        OLED_P6x8Str(0, 7, "Interesting");
        OLED_P6x8Str(91, 7, "Car:2B");
    #endif

    if(!gpio_get (PTE1))
        OLED_P6x8Str(0, 1, "^");
    else
        OLED_P6x8Str(0, 1, " ");

    if(!gpio_get (PTE2))
        OLED_P6x8Str(6, 1, "^");
    else
        OLED_P6x8Str(6, 1, " ");

    if(!gpio_get (PTE3))
        OLED_P6x8Str(12, 1, "^");
    else
        OLED_P6x8Str(12, 1, " ");

    if(!gpio_get (PTE4))
        OLED_P6x8Str(18, 1, "^");
    else
        OLED_P6x8Str(18, 1, " ");

    if(!gpio_get (PTE5))
        OLED_P6x8Str(24, 1, "^");
    else
        OLED_P6x8Str(24, 1, " ");

    if(!gpio_get (PTE6))
        OLED_P6x8Str(30, 1, "^");
    else
        OLED_P6x8Str(30, 1, " ");

    if(!gpio_get (PTE7))
        OLED_P6x8Str(36, 1, "^");
    else
        OLED_P6x8Str(36, 1, " ");

    if(!gpio_get (PTE8))
        OLED_P6x8Str(42, 1, "^");
    else
        OLED_P6x8Str(42, 1, " ");

    if(key_check(KEY_A) == KEY_DOWN)
    {
        OLED_Init();    //OLED初始化  防花屏
    }

    if(key_check(KEY_U) == KEY_DOWN)     //按K2重新获取两边线数组,串口接收
    {
        get_initial_value(img, &slope);

        printf("const int left_initial[110] ={");
        for(i = 0; i < 110; i++)
        {
            printf("%d, ", slope.left_initial_value[i]);
            //printf("[%d]=%d\n", i, slope.right_initial_value[i]);
        }
        printf("};\nconst int right_initial[110] ={");
        for(i = 0; i < 110; i++)
        {
            printf("%d, ", slope.right_initial_value[i]);
            //printf("[%d]=%d\n", i, slope.right_initial_value[i]);
        }
        printf("};//Pay attention to delete the last \",\"\n");
        //initial_value_get=1;
    }

}
コード例 #8
0
static uint8_t select_audio_codec(void)
{
	int audio_db_sel = gpio_get(AUDIO_DB_ID);

	return audio_db_sel;
}
コード例 #9
0
ファイル: bsp.c プロジェクト: mour/ratfist-stm32
bool bsp_led_get_state(enum board_led led)
{
	cm3_assert(is_initialized);

	return gpio_get(GPIOC, led_pin_lut[led]);
}
コード例 #10
0
ファイル: adf4153.c プロジェクト: DenisKuzovin/no-OS
/**************************************************************************//**
 * @brief Initialize SPI and Initial Values for ADF4106 Board.
 *
 * @param device     - The device structure.
 * @param init_param - The structure that contains the device initial
 * 		       parameters.
 *
 * @return success
******************************************************************************/
int8_t adf4153_init(struct adf4153_dev **device,
		    struct adf4153_init_param init_param)
{
	struct adf4153_dev *dev;
	int8_t status;

	dev = (struct adf4153_dev *)malloc(sizeof(*dev));
	if (!dev)
		return -1;

	dev->adf4153_st = init_param.adf4153_st;

	dev->adf4153_rfin_min_frq = 10000000;   // 10 Mhz
	dev->adf4153_rfin_max_frq = 250000000;  // 250 Mhz
	dev->adf4153_pfd_max_frq  = 32000000;   // 32 Mhz
	dev->adf4153_vco_min_frq  = 500000000;  // 500 Mhz
	dev->adf4153_vco_max_frq  = 4000000000; // 4 Ghz
	dev->adf4153_mod_max      = 4095;       // the MOD is stored in 12 bits
	dev->r0 = 0;
	dev->r1 = 0;
	dev->r2 = 0;
	dev->r3 = 0;

	/* CPHA = 1; CPOL = 0; */
	status = spi_init(&dev->spi_desc, &init_param.spi_init);

	/* GPIO */
	status |= gpio_get(&dev->gpio_le, init_param.gpio_le);
	status |= gpio_get(&dev->gpio_ce, init_param.gpio_ce);
	status |= gpio_get(&dev->gpio_le2, init_param.gpio_le2);
	status |= gpio_get(&dev->gpio_ce2, init_param.gpio_ce2);

	/* Bring CE high to put device to power up */
	ADF4153_CE_OUT;
	ADF4153_CE_HIGH;
	/* Initialize the load enable pin */
	ADF4153_LE_OUT;
	ADF4153_LE_LOW;

	/* Write all zeros to the noise and spur register */
	adf4153_update_latch(dev,
			     ADF4153_CTRL_NOISE_SPUR |
			     0x0);
	/* selects the lowest noise mode by default */
	adf4153_update_latch(dev,
			     ADF4153_CTRL_NOISE_SPUR |
			     0x3C7);
	/* Set up the control register and enable the counter reset */
	adf4153_update_latch(dev,
			     ADF4153_CTRL_CONTROL |
			     ADF4153_R2_COUNTER_RST(ADF4153_CR_ENABLED) |
			     ADF4153_R2_CP_3STATE(dev->adf4153_st.cp_three_state) |
			     ADF4153_R2_POWER_DOWN(dev->adf4153_st.power_down) |
			     ADF4153_R2_LDP(dev->adf4153_st.ldp) |
			     ADF4153_R2_PD_POL(dev->adf4153_st.pd_polarity) |
			     ADF4153_R2_CP_CURRENT(dev->adf4153_st.cp_current) |
			     ADF4153_R2_REF_DOUBLER(dev->adf4153_st.ref_doubler) |
			     ADF4153_R2_RESYNC(dev->adf4153_st.resync)
			    );
	/* If resync feature is enabled */
	if(init_param.adf4153_st.resync != 0x0) {
		/* Load the R divider register */
		adf4153_update_latch(dev,
				     ADF4153_CTRL_R_DIVIDER |
				     ADF4153_R1_MOD(10) |    //Resync Delay
				     ADF4153_R1_RCOUNTER(dev->adf4153_st.r_counter) |
				     ADF4153_R1_PRESCALE(dev->adf4153_st.prescaler) |
				     ADF4153_R1_MUXOUT(dev->adf4153_st.muxout) |
				     ADF4153_R1_LOAD(ADF4153_LOAD_RESYNC)
				    );
	}
	/* Load the R divider register */
	adf4153_update_latch(dev,
			     ADF4153_CTRL_R_DIVIDER |
			     ADF4153_R1_MOD(dev->adf4153_st.mod_value) |
			     ADF4153_R1_RCOUNTER(dev->adf4153_st.r_counter) |
			     ADF4153_R1_PRESCALE(dev->adf4153_st.prescaler) |
			     ADF4153_R1_MUXOUT(dev->adf4153_st.muxout) |
			     ADF4153_R1_LOAD(ADF4153_LOAD_NORMAL)
			    );
	/* Load the N divider register */
	adf4153_update_latch(dev,
			     ADF4153_CTRL_N_DIVIDER |
			     ADF4153_R0_FRAC(dev->adf4153_st.frac_value) |
			     ADF4153_R0_INT(dev->adf4153_st.int_value) |
			     ADF4153_R0_FASTLOCK(dev->adf4153_st.fastlock)
			    );

	/* Disable the counter reset in the Control Register */
	dev->r2 &= ~ADF4153_R2_COUNTER_RST(ADF4153_R2_COUNTER_RST_MASK);
	adf4153_update_latch(dev,
			     ADF4153_CTRL_CONTROL |
			     dev->r2 |
			     ADF4153_R2_COUNTER_RST(ADF4153_CR_DISABLED)
			    );

	*device = dev;

	return status;
}
コード例 #11
0
ファイル: channels.c プロジェクト: Chen-Leon/DeviationX
s32 CHAN_ReadRawInput(int channel)
{
    s32 value = 0;
    switch(channel) {
    case INP_AILERON:  value = adc_array_raw[0]; break;  // bug fix: right vertical
    case INP_ELEVATOR: value = adc_array_raw[1]; break;  // bug fix: right horizon
    case INP_THROTTLE: value = adc_array_raw[2]; break;  // bug fix: left horizon
    case INP_RUDDER:   value = adc_array_raw[3]; break;  // bug fix: left vertical
    case INP_AUX4:     value = adc_array_raw[4]; break;
    case INP_AUX5:     value = adc_array_raw[5]; break;
    case INP_AUX6:     value = adc_array_raw[6]; break;
    case INP_AUX7:     value = adc_array_raw[7]; break;
    case INP_SWA0:     value = gpio_get(GPIOC, GPIO0); break;
    case INP_SWA1:     value = ! gpio_get(GPIOC, GPIO0); break;
    case INP_SWB0:     value = gpio_get(GPIOC, GPIO1); break;
    case INP_SWB1:     value = ! gpio_get(GPIOC, GPIO1); break;
    case INP_SWC0:     value = ! gpio_get(GPIOC, GPIO2); break;
    case INP_SWC1:     value = (gpio_get(GPIOC, GPIO2) && gpio_get(GPIOC, GPIO3)); break;
    case INP_SWC2:     value = ! gpio_get(GPIOC, GPIO3); break;
    case INP_SWD0:     value = gpio_get(GPIOC, GPIO6); break;
    case INP_SWD1:     value = ! gpio_get(GPIOC, GPIO6); break;
    case INP_SWE0:     value = ! gpio_get(GPIOC, GPIO4); break;
    case INP_SWE1:     value = (gpio_get(GPIOC, GPIO4) && gpio_get(GPIOC, GPIO5)); break;
    case INP_SWE2:     value = ! gpio_get(GPIOC, GPIO5); break;
    case INP_SWF0:     value = gpio_get(GPIOC, GPIO7); break;
    case INP_SWF1:     value = ! gpio_get(GPIOC, GPIO7); break;
    case INP_SWG0:     value = ! gpio_get(GPIOC, GPIO8); break;
    case INP_SWG1:     value = (gpio_get(GPIOC, GPIO8) && gpio_get(GPIOC, GPIO9)); break;
    case INP_SWG2:     value = ! gpio_get(GPIOC, GPIO9); break;
    case INP_SWH0:     value = gpio_get(GPIOA, GPIO8); break;
    case INP_SWH1:     value = ! gpio_get(GPIOA, GPIO8); break;
    }
    return value;
}
コード例 #12
0
ファイル: main_f4.c プロジェクト: fcayci/px4bootloader
int
main(void)
{
	bool try_boot = true;			/* try booting before we drop to the bootloader */
	unsigned timeout = BOOTLOADER_DELAY;	/* if nonzero, drop out of the bootloader after this time */

	/* Enable the FPU before we hit any FP instructions */
	SCB_CPACR |= ((3UL << 10*2) | (3UL << 11*2)); /* set CP10 Full Access and set CP11 Full Access */

	/* do board-specific initialisation */
	board_init();

	/*
	 * Check the force-bootloader register; if we find the signature there, don't
	 * try booting.
	 */
	if (board_get_rtc_signature() == BOOT_RTC_SIGNATURE) {

		/*
		 * Don't even try to boot before dropping to the bootloader.
		 */
		try_boot = false;

		/*
		 * Don't drop out of the bootloader until something has been uploaded.
		 */
		timeout = 0;

		/*
		 * Clear the signature so that if someone resets us while we're
		 * in the bootloader we'll try to boot next time.
		 */
		board_set_rtc_signature(0);
	}

#ifdef INTERFACE_USB
	/*
	 * Check for USB connection - if present, don't try to boot, but set a timeout after
	 * which we will fall out of the bootloader.
	 *
	 * If the force-bootloader pins are tied, we will stay here until they are removed and
	 * we then time out.
	 */
	if (gpio_get(GPIOA, GPIO9) != 0) {

		/* don't try booting before we set up the bootloader */
		try_boot = false;
	}
#endif

	/* Try to boot the app if we think we should just go straight there */
	if (try_boot) {

		/* set the boot-to-bootloader flag so that if boot fails on reset we will stop here */
#ifdef BOARD_BOOT_FAIL_DETECT
		board_set_rtc_signature(BOOT_RTC_SIGNATURE);
#endif

		/* try to boot immediately */
		jump_to_app();

		/* booting failed, stay in the bootloader forever */
		timeout = 0;
	}

	/* configure the clock for bootloader activity */
	rcc_clock_setup_hse_3v3(&clock_setup);

	/* start the interface */
	cinit(BOARD_INTERFACE_CONFIG);

#if 0
	// MCO1/02
	gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO8);
	gpio_set_output_options(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_100MHZ, GPIO8);
	gpio_set_af(GPIOA, GPIO_AF0, GPIO8);
	gpio_mode_setup(GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
	gpio_set_af(GPIOC, GPIO_AF0, GPIO9);
#endif

	while (1)
	{
		/* run the bootloader, come back after an app is uploaded or we time out */
		bootloader(timeout);

		/* if the force-bootloader pins are strapped, just loop back */
		if (board_test_force_pin())
			continue;

		/* set the boot-to-bootloader flag so that if boot fails on reset we will stop here */
#ifdef BOARD_BOOT_FAIL_DETECT
		board_set_rtc_signature(BOOT_RTC_SIGNATURE);
#endif

		/* look to see if we can boot the app */
		jump_to_app();

		/* launching the app failed - stay in the bootloader forever */
		timeout = 0;
	}
}
コード例 #13
0
int get_write_protect_state(void)
{
	return !gpio_get(WRITE_PROTECT);
}
コード例 #14
0
ファイル: battery.c プロジェクト: Ole-x/musicboxV2
int battery_state() {
	return gpio_get(BAT_STAT_PORT, BAT_STAT1_PORT | BAT_STAT2_PORT | BAT_PG_PORT);
}
コード例 #15
0
ファイル: main.c プロジェクト: chenxuuu/SmartCar
/***********************************主函数**************************************/
void  main(void)
{
    for(i = 0; i < 110; i++)   //装载摄像头边线初值
    {
        slope.left_initial_value[i] = left_initial[i];
        slope.right_initial_value[i] = right_initial[i];
    }
    camera_init(imgbuff);						//初始化摄像头
    //配置中断服务函数
    set_vector_handler(PORTA_VECTORn , PORTA_IRQHandler);   //设置LPTMR的中断服务函数为 PORTA_IRQHandler
    set_vector_handler(DMA0_VECTORn , DMA0_IRQHandler);     //设置LPTMR的中断服务函数为 PORTA_IRQHandler

    set_vector_handler(PORTE_VECTORn ,PORTE_IRQHandler);    //设置PORTE的中断服务函数为 PORTE_IRQHandler
    enable_irq (PORTE_IRQn);                                //使能PORTE中断

    port_init(PTE2, ALT1 | PULLUP );     //5  蓝牙同时发车
    if(!gpio_get (PTE2))   //蓝牙通讯同时发车
    {
        key_init(KEY_A);
        OLED_Init();
        while(1)
        {
            #if ( CAR_NUMBER == 2 )
                OLED_P6x8Str(0, 6, "Press K6 to start!");
                if(key_check(KEY_A) == KEY_DOWN)   //按K3发车
                {
                    uart_putchar(VCAN_PORT, ch);
                    OLED_P6x8Str(0, 6, "                  ");
                    bluetooth = 1;
                    break;
                }
            #endif
            #if ( CAR_NUMBER == 1 )
                OLED_P6x8Str(0, 6, "Start 2B to start!");
                while(uart_query (VCAN_PORT) == 0);
                OLED_P6x8Str(0, 6, "                  ");
                bluetooth = 1;
                break;
            #endif
        }
    }
    else
    {
        bluetooth = 2;
    }

    mk60int();
	init_PID();

    while(1)
    {
        oled_display();
        camera_get_img();						//摄像头获取图像
        img_extract(img, imgbuff, CAMERA_SIZE);	//解压图像
        get_slope(img, &slope); //获取斜率
        boundary_detection();//扫描图像获取边界
        picture_analysis();//获取中线
        //SetMotorVoltage(0.2,0.2);
        if(!gpio_get (PTE1))
        {
           vcan_sendimg(imgbuff,CAMERA_SIZE);//摄像头看图像
        }

        if(!gpio_get (PTE2))   //蓝牙同时发车
        {
            #if ( CAR_NUMBER == 1 )
                if(uart_querychar (VCAN_PORT, &ch) != 0)
                {
                    if(ch == 's')
                    {
                        stop_done = 1;
                    }
                }
            #endif
            #if ( CAR_NUMBER == 2 )
                if(stop_done)
                {
                    lptmr_delay_ms(500);    //延时确保后车过线
                    while(1)
                    {
                        uart_putchar(VCAN_PORT, ch_stop);
                    }
                }
            #endif
        }

        if(!gpio_get (PTE3))   //速度40
        {
            vPID.Setpoint = 40;
        }
        if(!gpio_get (PTE4))  //速度45
        {
            vPID.Setpoint = 45;
        }
        if(!gpio_get (PTE5))   //速度50
        {
            vPID.Setpoint = 50;
        }
        if(!gpio_get (PTE6))   //速度47
        {
            vPID.Setpoint = 46;
        }
        if(!gpio_get (PTE7))   //速度48
        {
            vPID.Setpoint = 47;
        }
        if(!gpio_get (PTE8))   //速度49
        {
            vPID.Setpoint = 48;
        }
        //ware1[0]=xielv;
        //vcan_sendware(ware1, sizeof(xielv));
        /*
        Display_number(36, 6, ttt);
        Display_number(0, 6, sss);
        printf("%d,", left_diuxian1);
        printf("%d\n",tt-t);
        */
        //printf("%d\n",speed1);

        //printf("%d,",left_diuxian1);

        //printf("%d\n",slope3);

        //printf("%d,",left_chazi);
        //printf("%d\n",right_chazi);
        //printf("%d,",m);
        //printf("%d\n",a);
        // if(!gpio_get (PTE8))
        // {
        //     for(l=0;l<120;l++)
        //     {
        //         printf("%d,",left_bianjie[l]);
        //     }
        //     printf("\n");
        // }
   }
}
コード例 #16
0
ファイル: main.c プロジェクト: inno-IAR-2013/inno-IAR-2013
void main()
{   

  uart_init(UART3, 115200); // For our flashed bluetooth
  //uart_init(UART3, 9600); // For our non-flashed bluetooth
  gpio_init(PORTE,6,GPI,0); // SW2 goes into gyro calibration mode
  
  
  printf("\nWelcome to the SmartCar 2013 Sensor team developement system\n");
  while(1){
    
   printf("==============================================================\n");
   printf("Please select mode:\n---------------------------\n");
   printf("1:Accelerometer&gyro\n");
   printf("2:LinearCCD\n");
   printf("3:Flash Memory\n");
   printf("4:Encoder testing\n");
   printf("6:Motor control test\n");
   printf("7:SystemLoop Test\n");
   
   delayms(300);
   
   if(gpio_get(PORTE,6)==0){
     
     adc_init(ADC1,AD5b);
     adc_init(ADC1,AD7b);
        
     printf("We are now in gyro calibration mode, Please keep car stationery and wait till light dies");
     gpio_init(PORTE,24,GPO,0);
     gpio_init(PORTE,25,GPO,0);
     gpio_init(PORTE,26,GPO,0);
     gpio_init(PORTE,27,GPO,0);
     
     delayms(3000);
     
     turn_gyro_offset=ad_ave(ADC1,AD5b,ADC_12bit,10000);
     balance_gyro_offset=ad_ave(ADC1,AD7b,ADC_12bit,10000);
     
     store_u32_to_flashmem1(turn_gyro_offset);
     store_u32_to_flashmem2(balance_gyro_offset);
     
     gpio_turn(PORTE,24);
     gpio_turn(PORTE,25);
     gpio_turn(PORTE,26);
     gpio_turn(PORTE,27);
     
     while(1){}
     
   }
   
   g_char_mode = '7';                 // Hard code mode = system loop
   //g_char_mode = uart_getchar(UART3);
 
     switch (g_char_mode){
      case '0':
        //VR analog input
        adc_init(ADC0,AD14);
        
        while(1){
          delayms(500);
          printf("\n%d",ad_once(ADC0,AD14,ADC_16bit));//vr value
        }
          
      break;
       
      case '1':
        uart_sendStr(UART3,"The mode now is 1: Accelerometer and Gyroscope Test");
        
        //accl_init();
        adc_init(ADC1,AD6b);
        adc_init(ADC1,AD7b);
        adc_init(ADC0,AD14);
        adc_init(ADC1,AD4b);
        
        
        balance_centerpoint_set=ad_ave(ADC0,AD14,ADC_12bit,10);

        printf("\nEverything Initialized alright\n");
        
        while(1)
        { 
          //printf("\n\f====================================");
          //control_tilt=(ad_ave(ADC1,AD6b,ADC_12bit,8)-3300)+(balance_centerpoint_set/10);
          //printf("\nMain gyro%d",control_tilt);//theta
          //printf("\n%d",ad_once(ADC1,AD7b,ADC_12bit)-1940);//omega
          printf("\n%d",ad_ave(ADC1,AD6b,ADC_12bit,8)-940);
          delayms(50);
          
        }
     break;
     
     case '2':
        uart_sendStr(UART3,"The mode now is 2: Linear CCD");
        ccd_interrupts_init();
        printf("\nEverything Initialized alright\n");
       
        while(1)
        { 
            //ccd_sampling(1); // Longer SI CCD Sampling
        }
     break;
     
     case '3':
        uart_sendStr(UART3,"The mode now is 3:Flash Memory\n");
        Flash_init();
        printf("Flash Memory init ok\n");
        printf("writing the u32 : 3125 to memory 1\n");
        store_u32_to_flashmem1(3125);
        printf("writing the u32: 1019 to memory 2\n");
        store_u32_to_flashmem2(1019);
        
        printf("Now reading from memory\n");
        printf("Memory 1:%d\n",get_u32_from_flashmem1());
        
        printf("Memory 2:%d\n",get_u32_from_flashmem2());
        
        
       
        while(1)
        { 
            //stops loop to see results
        }
     break;
        
      case '4':
        //temporary case for debuggine encoder libraries, move to encoder.h later
        uart_sendStr(UART3,"The mode now is 4: encoder test");
             
        DisableInterrupts;
        exti_init(PORTA,6,rising_up);    //inits left encoder interrupt capture
        exti_init(PORTA,7,rising_up);    //inits right encoder interrupt capture
             
        pit_init_ms(PIT1,500);                 //periodic interrupt every 500ms
     
        EnableInterrupts;
        printf("\nEverything Initialized alright\n");
     
        while(1){
        
        }
          
      break;

      case '6':
        uart_sendStr(UART3,"The mode now is 6: Motor Control test");
        //inits
        motor_init();
        
        printf("\nEverything Initialized alright\n");
        delayms(1000);
        
        while(1)
        { 
          //printf("\n\fInput 0-9 Motor Speed, Currently:%d",motor_test);
          //motor_test=100*(uart_getchar(UART3)-48);
          
          FTM_PWM_Duty(FTM1,CH0,2000);
          FTM_PWM_Duty(FTM1,CH1,2000);//left
          
          printf("\n\f Input direction : 0 or 1");
          motor_test = uart_getchar(UART3)-48;
         
          
          
          if (motor_test){
            gpio_set(PORTD,9,1);
            gpio_set(PORTD,7,1);//this is DIR
          }else{
            gpio_set(PORTD,9,0);
            gpio_set(PORTD,1,0);//this is DIR
          }
          
        }  
      break;

      case '7':
        printf("\n The Mode is now 7: SystemLoop Test");
        
        adc_init(ADC1,AD6b);
        adc_init(ADC1,AD7b);
        adc_init(ADC0,AD14);
        adc_init(ADC1,AD5b);
        
        //balance_centerpoint_set=ad_ave(ADC0,AD14,ADC_12bit,10);
        
        turn_gyro_offset=get_u32_from_flashmem1();
        balance_gyro_offset=get_u32_from_flashmem2();
        
        motor_init();
        
        gpio_set(PORTD,9,0); //dir
        gpio_set(PORTD,7,0); //dir
        
        FTM_PWM_Duty(FTM1, CH0, 3000); //initital speed
        FTM_PWM_Duty(FTM1, CH1, 3000); //initital speed               
        
        ccd_interrupts_init();
        pit_init_ms(PIT3,1);
        
        printf("\nEverything inited alright");
        
        
        while(1){
          //system loop runs 
        }
        
     break;
      
     default :
     printf("\n\fYou entered:%c, Please enter a number from 1-7 to select a mode\n\f",g_char_mode);
        
    }
   }
}
コード例 #17
0
int get_write_protect_state(void)
{
	/* Read PCH_WP GPIO. */
	return gpio_get(GPIO_PCH_WP);
}
コード例 #18
0
ファイル: chromeos.c プロジェクト: serenasensini/coreboot
int get_recovery_mode_switch(void)
{
	// Both RECOVERY_SERVO and RECOVERY_PUSHKEY are low active.
	return !(gpio_get(GPIO_RECOVERY_SERVO) &&
		 gpio_get(GPIO_RECOVERY_PUSHKEY));
}
コード例 #19
0
int tda18219_wait_irq(void)
{
	while(!gpio_get(GPIOA, TDA_PIN_IRQ));

	return 0;
}
コード例 #20
0
char cc3k_get_din() {
    return gpio_get(GPIOF, CC3000_DIN)!=0;
}
コード例 #21
0
ファイル: baro_board.c プロジェクト: AE4317group07/paparazzi
static bool_t baro_eoc(void)
{
  return gpio_get(GPIOB, GPIO0);
}
コード例 #22
0
ファイル: msm_i2c.c プロジェクト: sndnvaps/HTC-leo-cLK
static int msm_i2c_recover_bus_busy(void)
{
	int i;
	bool gpio_clk_status = false;
	uint32_t status = readl(dev.pdata->i2c_base + I2C_STATUS);
	I2C_DBG_FUNC_LINE();

	if (!(status & (I2C_STATUS_BUS_ACTIVE | I2C_STATUS_WR_BUFFER_FULL)))
		return 0;

	if (dev.pdata->set_mux_to_i2c)
		dev.pdata->set_mux_to_i2c(0);

	if (status & I2C_STATUS_RD_BUFFER_FULL) {
		I2C_DBG(DEBUGLEVEL, "Read buffer full, status %x, intf %x\n",  status, readl(dev.pdata->i2c_base + I2C_INTERFACE_SELECT));
		writel(I2C_WRITE_DATA_LAST_BYTE, dev.pdata->i2c_base + I2C_WRITE_DATA);
		readl(dev.pdata->i2c_base + I2C_READ_DATA);
	}
	else if (status & I2C_STATUS_BUS_MASTER) {
		I2C_DBG(DEBUGLEVEL, "Still the bus master, status %x, intf %x\n", status, readl(dev.pdata->i2c_base + I2C_INTERFACE_SELECT));
		writel(I2C_WRITE_DATA_LAST_BYTE | 0xff, dev.pdata->i2c_base + I2C_WRITE_DATA);
	}

	I2C_DBG(DEBUGLEVEL, "i2c_scl: %d, i2c_sda: %d\n", gpio_get(dev.pdata->scl_gpio), gpio_get(dev.pdata->sda_gpio));

	for (i = 0; i < 9; i++) {
		if (gpio_get(dev.pdata->sda_gpio) && gpio_clk_status)
			break;
			
		gpio_set(dev.pdata->scl_gpio, 0);
		udelay(5);
		
		gpio_set(dev.pdata->sda_gpio, 0);
		udelay(5);
		
		gpio_config(dev.pdata->scl_gpio, GPIO_INPUT);
		udelay(5);
		
		if (!gpio_get(dev.pdata->scl_gpio))
			udelay(20);
			
		if (!gpio_get(dev.pdata->scl_gpio))
			mdelay(10);
			
		gpio_clk_status = gpio_get(dev.pdata->scl_gpio);
		gpio_config(dev.pdata->sda_gpio, GPIO_INPUT);
		udelay(5);
	}
	
	if (dev.pdata->set_mux_to_i2c)
		dev.pdata->set_mux_to_i2c(1);

	udelay(10);

	status = readl(dev.pdata->i2c_base + I2C_STATUS);
	if (!(status & I2C_STATUS_BUS_ACTIVE)) {
		I2C_DBG(DEBUGLEVEL, "Bus busy cleared after %d clock cycles, status %x, intf %x\n", i, status, readl(dev.pdata->i2c_base + I2C_INTERFACE_SELECT));
		return 0;
	}
	
	I2C_DBG(DEBUGLEVEL, "Bus still busy, status %x, intf %x\n", status, readl(dev.pdata->i2c_base + I2C_INTERFACE_SELECT));
	return ERR_NOT_READY;
}
コード例 #23
0
ファイル: chromeos.c プロジェクト: RafaelRMachado/Coreboot
void fill_lb_gpios(struct lb_gpios *gpios)
{
	int count = 0;

	/* Write Protect: active low */
	gpios->gpios[count].port = GPIO(R1);
	gpios->gpios[count].polarity = ACTIVE_LOW;
	gpios->gpios[count].value = gpio_get(GPIO(R1));
	strncpy((char *)gpios->gpios[count].name, "write protect",
		GPIO_MAX_NAME_LENGTH);
	count++;

	/* Recovery: active high */
	gpios->gpios[count].port = -1;
	gpios->gpios[count].polarity = ACTIVE_HIGH;
	gpios->gpios[count].value = get_recovery_mode_switch();
	strncpy((char *)gpios->gpios[count].name, "recovery",
		GPIO_MAX_NAME_LENGTH);
	count++;

	/* Lid: active high */
	gpios->gpios[count].port = GPIO(R4);
	gpios->gpios[count].polarity = ACTIVE_HIGH;
	gpios->gpios[count].value = -1;
	strncpy((char *)gpios->gpios[count].name, "lid", GPIO_MAX_NAME_LENGTH);
	count++;

	/* Power: active low */
	gpios->gpios[count].port = GPIO(Q0);
	gpios->gpios[count].polarity = ACTIVE_LOW;
	gpios->gpios[count].value = -1;
	strncpy((char *)gpios->gpios[count].name, "power",
		GPIO_MAX_NAME_LENGTH);
	count++;

	/* Developer: virtual GPIO active high */
	gpios->gpios[count].port = -1;
	gpios->gpios[count].polarity = ACTIVE_HIGH;
	gpios->gpios[count].value = get_developer_mode_switch();
	strncpy((char *)gpios->gpios[count].name, "developer",
		GPIO_MAX_NAME_LENGTH);
	count++;

	/* EC in RW: active high */
	gpios->gpios[count].port = GPIO(U4);
	gpios->gpios[count].polarity = ACTIVE_HIGH;
	gpios->gpios[count].value = -1;
	strncpy((char *)gpios->gpios[count].name, "EC in RW",
		GPIO_MAX_NAME_LENGTH);
	count++;

	/* Reset: active low (output) */
	gpios->gpios[count].port = GPIO(I5);
	gpios->gpios[count].polarity = ACTIVE_LOW;
	gpios->gpios[count].value = -1;
	strncpy((char *)gpios->gpios[count].name, "reset",
		GPIO_MAX_NAME_LENGTH);
	count++;

	gpios->size = sizeof(*gpios) + (count * sizeof(struct lb_gpio));
	gpios->count = count;

	printk(BIOS_ERR, "Added %d GPIOS size %d\n", count, gpios->size);
}
コード例 #24
0
ファイル: main_f1.c プロジェクト: LukeMike/Bootloader
int
main(void)
{
	unsigned timeout = 0;

	/* do board-specific initialisation */
	board_init();

#if defined(INTERFACE_USART) | defined (INTERFACE_USB)
	/* XXX sniff for a USART connection to decide whether to wait in the bootloader? */
	timeout = BOOTLOADER_DELAY;
#endif

#ifdef INTERFACE_I2C
# error I2C bootloader detection logic not implemented
#endif

	/* if the app left a cookie saying we should wait, then wait */
	if (should_wait())
		timeout = BOOTLOADER_DELAY;

#ifdef BOARD_FORCE_BL_PIN
	/* if the force-BL pin state matches the state of the pin, wait in the bootloader forever */
	if (BOARD_FORCE_BL_VALUE == gpio_get(BOARD_FORCE_BL_PORT, BOARD_FORCE_BL_PIN))
		timeout = 0xffffffff;
#endif

	/* look for the magic wait-in-bootloader value in backup register zero */


	/* if we aren't expected to wait in the bootloader, try to boot immediately */
	if (timeout == 0) {
		/* try to boot immediately */
		jump_to_app();

		/* if we returned, there is no app; go to the bootloader and stay there */
		timeout = 0;
	}

	/* configure the clock for bootloader activity */
#if defined(INTERFACE_USB)
	rcc_clock_setup_in_hsi_out_48mhz();
#else
	rcc_clock_setup_in_hsi_out_24mhz();
#endif

	/* start the interface */
	cinit(BOARD_INTERFACE_CONFIG);

	while (1)
	{
		/* run the bootloader, possibly coming back after the timeout */
		bootloader(timeout);

		/* look to see if we can boot the app */
		jump_to_app();

		/* boot failed; stay in the bootloader forever next time */
		timeout = 0;
	}
}
コード例 #25
0
ファイル: chromeos.c プロジェクト: hschauhan/xvisor-coreboot
int get_recovery_mode_switch(void)
{
	return !gpio_get(GPIO_RECOVERY);
}
コード例 #26
0
int get_write_protect_state(void)
{
	return !gpio_get(GPIO(R1));
}
コード例 #27
0
ファイル: stepper_motors.c プロジェクト: eddyem/IR-controller
/**
 * Check flags set by timers & do next:
 *  - decrease step counter if it isn't zero;
 *  - stop motor if counter is zero but motor still active
 */
void process_stepper_motors(){
	int i, j;
	const uint32_t ports[] = {MOTOR_TIM1_PORT, MOTOR_TIM2_PORT};
	const uint32_t pins[] = {MOTOR_TIM1_PIN, MOTOR_TIM2_PIN};
	const uint8_t startno[] = {0, 3};
	const uint8_t stopno[]  = {3, 5};
	//static uint8_t showcurpos[5] = {0,0,0,0,0};
	uint8_t curpos;
	const uint32_t Tim[2] = {TIM3, TIM4};
	for(j = 0; j < 2; j++){
		// new period of motors' timer -- maximum value for all periods in group
		uint16_t new_period = 0;
		if(timer_flag[j]){
			timer_flag[j] = 0;
			uint8_t is_active = 0;
			for(i = startno[j]; i < stopno[j]; i++)
				if(Motor_active[i]) is_active = 1;
			if(!is_active) continue; // don't generate clock pulses when there's no moving motors
			if(undervoltage_test(MOTORS_VOLTAGE_ALERT)){ // UNDERVOLTAGE! Stop all active motors
				for(i = 0; i < 5; i++)
					if(Motor_active[i]) stop_motor(i);
				return;
			}
			gpio_toggle(ports[j], pins[j]); // change clock state
			if(!gpio_get(ports[j], pins[j])){ // negative pulse - omit this half-step
				continue;
			}
			for(i = startno[j]; i < stopno[j]; i++){ // check motors
				if(Motor_active[i] == 0) continue; // inactive motor
				curpos = check_ep(i);
				if(Motor_steps[i] == 0){ // end of moving
					stop_motor(i); // even if this is a turret with move2pos[i]!=0 we should stop
						//(what if there's some slipping or so on?)
				}else{ // we should move further
					if(waits[i]){ // waiting for position stabilisation
						uint8_t got_new_position = 0;
						waits[i]--;
						if(waits[i]) continue; // there's more half-steps to skip
						// tell user current position if we was stopped at fixed pos
						if(lastpos[i] == 0 && curpos != 0){
							got_new_position = 1;
							MSG("position of motor ", "[ " STR_ENDSW_STATE " ");
							print_int(i, lastsendfun);
							lastsendfun(' ');
							print_int(curpos, lastsendfun);
							if(mode == LINE_MODE) P(" ]", lastsendfun);
							lastsendfun('\n');
						}
						lastpos[i] = curpos;
						// turn on motor after pause
						gpio_set(MOTOR_EN_PORT, MOTOR_EN_PIN(i));
						if(j == 1){ // this is a linear stage
							if(test_stages_endpos(i, curpos)){ // this is the end of way
								stop_motor(i);
							}
						}else{ // this is a turret
							if(move2pos[i]){ // we should move to specific position
								if(curpos == move2pos[i]){ // we are on position
									stop_motor(i);
								}else if(got_new_position){ // add some steps to move to next position
									if(++positions_pass[i] > MAX_POSITIONS_PASS){
										ERR("Can't reach given position");
										stop_motor(i);
									}else
										Motor_steps[i] += TURRETS_NEXT_POS_STEPS;
								}
							}
						}
					}else{
						// check for overcurrent: if MOTOR_EN_PIN == 0
						if(!gpio_get(MOTOR_EN_PORT, MOTOR_EN_PIN(i))){
							ERR("overcurrent\n");
							stop_motor(i);
							continue;
						}
						if(lastpos[i] != curpos){ // transition process
							if(lastpos[i] == 0){ // come towards position
								if(j == 0){ // this is a turret: make pause & prepare acceleration for start
									waits[i] = Turrets_pause;
									accel[i] = START_MOTORS_ACCEL_IDX_4;
								}else{
									waits[i] = 1;
								}
								// turn off motor while a pause (turret will be locked at fixed position by spring)
								// for this short pause we can simply do a pulldown
								gpio_clear(MOTOR_EN_PORT, MOTOR_EN_PIN(i));
								continue;
							}
							lastpos[i] = curpos;
						}
						Motor_steps[i]--;
						// change value of current motor's position
						Motor_abs_steps[i] += Motor_step_increment[i];
						if(accel[i]){ // we are starting
							uint32_t NP = (uint32_t)Motor_period[j] * accel_mults[(accel[i]--)/4];
							if(NP > 0xffff) NP = 0xffff;
							if(new_period < NP) new_period = (uint16_t)NP;
						}
					}
				}
			}
			if(new_period){ // we have to change motors' speed when accelerating
				timer_set_period(Tim[j], new_period);
			}
		}
	}
}
コード例 #28
0
/*
#define ADC_CONVERSION_FACTOR 4096.0f
#define VREF 2.966f	//ADC conversion reference voltage

#define CONVERSION_FACTOR_JOINT_0 1.0f
#define CONVERSION_FACTOR_JOINT_1 1.0f
#define CONVERSION_FACTOR_JOINT_2 1.0f
*/
void tim1_up_tim10_isr(void) 
{

  //Clear the update interrupt flag
  timer_clear_flag(TIM1,  TIM_SR_UIF);

  static int counter=0;
/*
  if (counter==0)
  {
      gpio_set(GPIOD,GPIO12);
       counter+=1;
  }
  else 
  {
      gpio_clear(GPIOD,GPIO12);
      counter=0;
  }
*/

        int button=0;

        button=gpio_get(GPIOA,GPIO0);




    counter+=1;
    if (counter>=1000)
    {
    gpio_toggle(GPIOD,GPIO12);
    counter=0;

    }

/*
        if (button)
        {
        gpio_toggle(GPIOD,GPIO12);
        gpio_toggle(GPIOD,GPIO13);
        gpio_toggle(GPIOD,GPIO14);
        gpio_toggle(GPIOD,GPIO15);
        }
*/
/*
        if (button)
        {
        gpio_set(GPIOD,GPIO12);
        gpio_set(GPIOD,GPIO13);
        gpio_set(GPIOD,GPIO14);
        gpio_set(GPIOD,GPIO15);
        }

        else
        {
        gpio_clear(GPIOD,GPIO12);
        gpio_clear(GPIOD,GPIO13);
        gpio_clear(GPIOD,GPIO14);
        gpio_clear(GPIOD,GPIO15);
        }
*/
}
コード例 #29
0
ファイル: generic.c プロジェクト: Oxyoptia/coreboot
static void i2c_generic_fill_ssdt(struct device *dev)
{
	struct drivers_i2c_generic_config *config = dev->chip_info;
	const char *scope = acpi_device_scope(dev);
	struct acpi_i2c i2c = {
		.address = dev->path.i2c.device,
		.mode_10bit = dev->path.i2c.mode_10bit,
		.speed = config->speed ? : I2C_SPEED_FAST,
		.resource = scope,
	};

	if (!dev->enabled || !scope)
		return;

	if (!config->hid) {
		printk(BIOS_ERR, "%s: ERROR: HID required\n", dev_path(dev));
		return;
	}

	/* Device */
	acpigen_write_scope(scope);
	acpigen_write_device(acpi_device_name(dev));
	acpigen_write_name_string("_HID", config->hid);
	acpigen_write_name_integer("_UID", config->uid);
	acpigen_write_name_string("_DDN", config->desc);
	acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);

	/* Resources */
	acpigen_write_name("_CRS");
	acpigen_write_resourcetemplate_header();
	acpi_device_write_i2c(&i2c);
	acpi_device_write_interrupt(&config->irq);
	acpigen_write_resourcetemplate_footer();

	/* Wake capabilities */
	if (config->wake) {
		acpigen_write_name_integer("_S0W", 4);
		acpigen_write_PRW(config->wake, 3);
	}

	acpigen_pop_len(); /* Device */
	acpigen_pop_len(); /* Scope */

	printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev),
	       config->desc ? : dev->chip_ops->name, dev_path(dev));
}

/* Use name specified in config or build one from I2C address */
static const char *i2c_generic_acpi_name(struct device *dev)
{
	struct drivers_i2c_generic_config *config = dev->chip_info;
	static char name[5];

	if (config->name)
		return name;

	snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
	name[4] = '\0';
	return name;
}
#endif

static struct device_operations i2c_generic_ops = {
	.read_resources		  = DEVICE_NOOP,
	.set_resources		  = DEVICE_NOOP,
	.enable_resources	  = DEVICE_NOOP,
#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
	.acpi_name		  = &i2c_generic_acpi_name,
	.acpi_fill_ssdt_generator = &i2c_generic_fill_ssdt,
#endif
};

static void i2c_generic_enable(struct device *dev)
{
	struct drivers_i2c_generic_config *config = dev->chip_info;

	/* Check if device is present by reading GPIO */
	if (config->device_present_gpio) {
		int present = gpio_get(config->device_present_gpio);
		present ^= config->device_present_gpio_invert;

		printk(BIOS_INFO, "%s is %spresent\n",
		       dev->chip_ops->name, present ? "" : "not ");

		if (!present) {
			dev->enabled = 0;
			return;
		}
	}

	dev->ops = &i2c_generic_ops;
}

struct chip_operations drivers_i2c_generic_ops = {
	CHIP_NAME("I2C Device")
	.enable_dev = &i2c_generic_enable
};