Пример #1
0
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
	int i = 0;
	int found = 0,v = 0;
	int channel = -666;
	unsigned int gpio;
    	unsigned int sys_gpio;
	static char *kwlist[] = {"channel", NULL};
	v = get_lmk_revision();
	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &channel))
		return NULL;

	if (channel != -666 && get_gpio_number(channel, &gpio, &sys_gpio))
		return NULL;

   if (module_setup && !setup_error) {
      if (channel == -666) {
         // clean up any /sys/class exports
         event_cleanup_all();
         
         // set everything back to input
         for (i=0; i<256; i++) {
            if (gpio_direction[i] != -1) {
				debug("Clean %d \n",i);
				if(v == BANANAPRO){
					setup_gpio(*(pinTobcm_BP+i), INPUT, PUD_OFF);//take care
				} else if(v == LEMAKER_GUITAR){
					setup_gpio(*(pinTobcm_GT+i), INPUT, PUD_OFF);//take care
				}
				gpio_direction[i] = -1;
				found = 1;
            }
         }
      } else {
         // clean up any /sys/class exports
         event_cleanup(sys_gpio);

         // set everything back to input
         if (gpio_direction[sys_gpio] != -1) {
            setup_gpio(gpio, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
            found = 1;
         }
      }
   }

	//printf("-->Before set warning\n");
	//printf("found %d \t gpio_warnings %d\n",found,gpio_warnings);
   // check if any channels set up - if not warn about misuse of GPIO.cleanup()
   if (!found && gpio_warnings) {
      PyErr_WarnEx(NULL, "No channels have been set up yet - nothing to clean up!  Try cleaning up at the end of your program instead!", 1);
   }
	//printf("-->After set warning\n");

   Py_RETURN_NONE;
}
Пример #2
0
int main(int argc, char **argv)
{
  int i, j;
  long tmp=0;
  long tmp_avg=0;
  long tmp_avg2;
  long offset=0;
  float filter_low, filter_high;
  float spread_percent = SPREAD / 100.0 /2.0;
  int b;
  int nsamples=N_SAMPLES;
  long samples[nsamples];

  if (argc == 2) {
   offset = atol(argv[1]);
  }

  setHighPri();
  setup_io();
  setup_gpio();
  reset_converter();

  j=0;

  // get the dirty samples and average them
  for(i=0;i<nsamples;i++) {
  	reset_converter();
  	samples[i] = read_cnt(0, argc);
  	tmp_avg += samples[i];
  }

  tmp_avg = tmp_avg / nsamples;

  tmp_avg2 = 0;
  j=0;

  filter_low =  (float) tmp_avg * (1.0 - spread_percent);
  filter_high = (float) tmp_avg * (1.0 + spread_percent);

//  printf("%d %d\n", (int) filter_low, (int) filter_high);

  for(i=0;i<nsamples;i++) {
	if ((samples[i] < filter_high && samples[i] > filter_low) || 
            (samples[i] > filter_high && samples[i] < filter_low) ) {
		tmp_avg2 += samples[i];
	        j++;
	}
  }

  if (j == 0) {
    printf("No data to consider\n");
    exit(255);

  }
  printf("%d", (tmp_avg2 / j) - offset);

//  printf("average within %f percent: %d from %d samples, original: %d\n", spread_percent*100, (tmp_avg2 / j) - offset, j, tmp_avg - offset);
  unpull_pins();
  restore_io();
}
Пример #3
0
static void mainboard_init(device_t dev)
{
	int i;
	for (i = 0; i < 6; i++)
		i2c_init(i);
	setup_gpio();
}
Пример #4
0
void main(void)
{
	struct mem_timings *mem;
	void *entry;
	int is_resume = (get_wakeup_state() != IS_NOT_WAKEUP);

	/* Clock must be initialized before console_init, otherwise you may need
	 * to re-initialize serial console drivers again. */
	mem = setup_clock();

	console_init();

	setup_power(is_resume);
	setup_memory(mem, is_resume);

	if (is_resume) {
		wakeup();
	}

	setup_storage();
	setup_gpio();
	setup_graphics();

	/* Set SPI (primary CBFS media) clock to 50MHz and configure pinmux. */
	exynos_pinmux_spi1();
	clock_set_rate(PERIPH_ID_SPI1, 50000000);

	cbmem_initialize_empty();

	entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA, "fallback/ramstage");
	stage_exit(entry);
}
Пример #5
0
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
   int i;
   int chancount = -666;
   int found = 0;
   int channel = -666;
   unsigned int gpio;
   PyObject *chanlist = NULL;
   PyObject *chantuple = NULL;
   PyObject *tempobj;
   static char *kwlist[] = {"channel", NULL};
   unsigned int bcm_gpio;

   void cleanup_one(void)
   {
      // clean up any /sys/class exports
      event_cleanup(gpio);

      // set everything back to input
      if (gpio_direction[bcm_gpio] != -1) {
         setup_gpio(gpio, INPUT, PUD_OFF);
         gpio_direction[bcm_gpio] = -1;
         found = 1;
      }
   }
Пример #6
0
// python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args)
{
   int i;
   int found = 0;

   if (module_setup && !setup_error)
   {
      // clean up any /sys/class exports
      event_cleanup();

      // set everything back to input
      for (i=0; i<54; i++)
      {
         if (gpio_direction[i] != -1)
         {
            setup_gpio(i, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
            found = 1;
         }
      }
   }

   // check if any channels set up - if not warn about misuse of GPIO.cleanup()
   if (!found && gpio_warnings)
   {
      PyErr_WarnEx(NULL, "No channels have been set up yet - nothing to clean up!  Try cleaning up at the end of your program instead!", 1);
   }

   Py_RETURN_NONE;
}
Пример #7
0
int main(int argc, char **argv) {
	int pin = 4;
	setup_gpio();
	set_pin_out(pin);
	
	int rep;

	struct timespec delay;
	delay.tv_sec = 0;
	delay.tv_nsec = 1000000;


	if (argc > 1) {
		rep = atoi(argv[1]);
	} else {
		rep = 5;
	}
	while (rep > 0) {
		write_pin_high(pin);
		nanosleep(&delay, NULL);
		write_pin_low(pin);
		nanosleep(&delay, NULL);
		--rep;
	}
	return 0;
}
Пример #8
0
void mainboard_romstage_entry(unsigned long bist)
{
	if (bist == 0)
		enable_lapic();

	i5000_lpc_config();

	winbond_enable_serial(PNP_DEV(0x2e, 2), 0x3f8);

	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	early_config();

	setup_gpio();

	enable_smbus();

        smbus_write_byte(0x6f, 0x00, 0x63);
        smbus_write_byte(0x6f, 0x01, 0x04);
        smbus_write_byte(0x6f, 0x02, 0x53);
        smbus_write_byte(0x6f, 0x03, 0x39);
        smbus_write_byte(0x6f, 0x08, 0x06);
        smbus_write_byte(0x6f, 0x09, 0x00);

	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xf0, (uintptr_t)DEFAULT_RCBA | 1);
	i5000_fbdimm_init();
	smbus_write_byte(0x69, 0x01, 0x01);
}
Пример #9
0
void main(unsigned long bist)
{
	if (bist == 0)
		enable_lapic();

	i5000_lpc_config();

	w83627hf_enable_serial(PNP_DEV(0x2e, 2), 0x3f8);

	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	early_config();

	setup_gpio();

	enable_smbus();

	/* setup PCIe MMCONF base address */
	pci_write_config32(PCI_DEV(0, 16, 0), 0x64,
			   CONFIG_MMCONF_BASE_ADDRESS >> 16);

        smbus_write_byte(0x6f, 0x00, 0x63);
        smbus_write_byte(0x6f, 0x01, 0x04);
        smbus_write_byte(0x6f, 0x02, 0x53);
        smbus_write_byte(0x6f, 0x03, 0x39);
        smbus_write_byte(0x6f, 0x08, 0x06);
        smbus_write_byte(0x6f, 0x09, 0x00);

	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xf0, DEFAULT_RCBA | 1);
	i5000_fbdimm_init();
	smbus_write_byte(0x69, 0x01, 0x01);
}
Пример #10
0
void main(void)
{

	extern struct mem_timings mem_timings;
	void *entry;
	int is_resume = (get_wakeup_state() != IS_NOT_WAKEUP);

	/* Clock must be initialized before console_init, otherwise you may need
	 * to re-initialize serial console drivers again. */
	system_clock_init();

	console_init();

	setup_power(is_resume);
	setup_memory(&mem_timings, is_resume);

	primitive_mem_test();

	if (is_resume) {
		wakeup();
	}

	setup_storage();
	setup_gpio();
	setup_ec();

	simple_spi_test();
	/* Set SPI (primary CBFS media) clock to 50MHz. */
	/* if this is uncommented SPI will not work correctly. */
	clock_set_rate(PERIPH_ID_SPI1, 50000000);
	simple_spi_test();
	entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA, "fallback/coreboot_ram");
	simple_spi_test();
	stage_exit(entry);
}
// python function cleanup(channel=None)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
   int i;
   int found = 0;
   int channel = -666;
   unsigned int gpio;
   static char *kwlist[] = {"channel", NULL};

   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &channel))
      return NULL;

   if (channel != -666 && get_gpio_number(channel, &gpio))
      return NULL;

   if (module_setup && !setup_error) {
      if (channel == -666) {
         // clean up any /sys/class exports
         event_cleanup_all();

         // set everything back to input
         for (i=0; i<54; i++) {
            if (gpio_direction[i] != -1) {
               setup_gpio(i, INPUT, PUD_OFF);
               gpio_direction[i] = -1;
               found = 1;
            }
         }
      } else {
         // clean up any /sys/class exports
         event_cleanup(gpio);

         // set everything back to input
         if (gpio_direction[gpio] != -1) {
            setup_gpio(gpio, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
            found = 1;
         }
      }
   }

   // check if any channels set up - if not warn about misuse of GPIO.cleanup()
   if (!found && gpio_warnings) {
      PyErr_WarnEx(NULL, "No channels have been set up yet - nothing to clean up!  Try cleaning up at the end of your program instead!", 1);
   }

   Py_RETURN_NONE;
}
Пример #12
0
// python function setup(channel, direction, pull_up_down=PUD_OFF, initial=None)
static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwargs)
{
   unsigned int gpio;
   int channel, direction;
   int pud = PUD_OFF + PY_PUD_CONST_OFFSET;
   int initial = -1;
   static char *kwlist[] = {"channel", "direction", "pull_up_down", "initial", NULL};
   int func;

   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &channel, &direction, &pud, &initial))
      return NULL;

   // check module has been imported cleanly
   if (setup_error)
   {
      PyErr_SetString(PyExc_RuntimeError, "Module not imported correctly!");
      return NULL;
   }

   // run init_module if module not set up
   if (!module_setup && (init_module() != SETUP_OK))
      return NULL;

   if (get_gpio_number(channel, &gpio))
      return NULL;

   if (direction != INPUT && direction != OUTPUT)
   {
      PyErr_SetString(PyExc_ValueError, "An invalid direction was passed to setup()");
      return NULL;
   }

   if (direction == OUTPUT)
      pud = PUD_OFF + PY_PUD_CONST_OFFSET;

   pud -= PY_PUD_CONST_OFFSET;
   if (pud != PUD_OFF && pud != PUD_DOWN && pud != PUD_UP)
   {
      PyErr_SetString(PyExc_ValueError, "Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN");
      return NULL;
   }

   func = gpio_function(gpio);
   if (gpio_warnings &&                             // warnings enabled and
       ((func != 0 && func != 1) ||                 // (already one of the alt functions or
       (gpio_direction[gpio] == -1 && func == 1)))  // already an output not set from this program)
   {
      PyErr_WarnEx(NULL, "This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.", 1);
   }

   if (direction == OUTPUT && (initial == LOW || initial == HIGH))
   {
      output_gpio(gpio, initial);
   }
   setup_gpio(gpio, direction, pud);
   gpio_direction[gpio] = direction;

   Py_RETURN_NONE;
}
Пример #13
0
void main(void)
{

	extern struct mem_timings mem_timings;
	int is_resume = (get_wakeup_state() != IS_NOT_WAKEUP);
	int power_init_failed;

	exynos5420_config_smp();
	power_init_failed = setup_power(is_resume);

	timestamp_init(timestamp_get());
	timestamp_add_now(TS_START_ROMSTAGE);

	/* Clock must be initialized before console_init, otherwise you may need
	 * to re-initialize serial console drivers again. */
	system_clock_init();

	exynos_pinmux_uart3();
	console_init();
	exception_init();

	if (power_init_failed)
		die("Failed to intialize power.\n");

	/* re-initialize PMIC I2C channel after (re-)setting system clocks */
	i2c_init(PMIC_I2C_BUS, 1000000, 0x00); /* 1MHz */

	timestamp_add_now(TS_BEFORE_INITRAM);

	setup_memory(&mem_timings, is_resume);

	timestamp_add_now(TS_AFTER_INITRAM);

	primitive_mem_test();

	trustzone_init();

	if (is_resume) {
		wakeup();
	}

	setup_gpio();
	setup_ec();

	simple_spi_test();
	/* Set SPI (primary CBFS media) clock to 50MHz. */
	/* if this is uncommented SPI will not work correctly. */
	clock_set_rate(PERIPH_ID_SPI1, 50000000);
	exynos_pinmux_spi1();
	simple_spi_test();

	cbmem_initialize_empty();

	simple_spi_test();

	timestamp_add_now(TS_END_ROMSTAGE);

	run_ramstage();
}
Пример #14
0
// python function setup(channel, direction, pull_up_down=PUD_OFF)
static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwargs)
{
   int gpio, channel, direction;
   int pud = PUD_OFF;
   static char *kwlist[] = {"channel", "direction", "pull_up_down", NULL};
   
   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|i", kwlist, &channel, &direction, &pud))
      return NULL;

   if (direction != INPUT && direction != OUTPUT)
   {
      PyErr_SetString(InvalidDirectionException, "An invalid direction was passed to setup()");
      return NULL;
   }

   if (direction == OUTPUT)
      pud = PUD_OFF;

   if (pud != PUD_OFF && pud != PUD_DOWN && pud != PUD_UP)
   {
      PyErr_SetString(InvalidPullException, "Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN");
      return NULL;
   }

   if (gpio_mode != BOARD && gpio_mode != BCM)
   {
      PyErr_SetString(ModeNotSetException, "Please set mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)");
      return NULL;
   }

   if ( (gpio_mode == BCM && (channel < 0 || channel > 53))
     || (gpio_mode == BOARD && (channel < 1 || channel > 26)) )
   {
      PyErr_SetString(InvalidChannelException, "The channel sent is invalid on a Raspberry Pi");
      return NULL;
   }

   if (gpio_mode == BOARD)
   {
      gpio = pin_to_gpio[channel];
      if (gpio == -1)
      {
         PyErr_SetString(InvalidChannelException, "The channel sent is invalid on a Raspberry Pi");
         return NULL;
      }
   }
   else // gpio_mode == BCM
   {
      gpio = channel;
   }

//   printf("Setup GPIO %d direction %d pud %d\n", gpio, direction, pud);
   setup_gpio(gpio, direction, pud);
   gpio_direction[gpio] = direction;

   Py_INCREF(Py_None);
   return Py_None;
}
Пример #15
0
int main(void)
{ 

  printf ("Traffic light demo\n");

  // Map the I/O sections
  setup_io();

  // Set 12 GPIO pins to output mode
  setup_gpio();

  GPIO_CLR0 = ALL_LEDS;		//Turn all LEDs off

  int i = 1;

  while(i < 4)	//Loop forever
  {
    printf("Traffic lights loop %d\n", i);

	GPIO_SET0 = RED_NORTH | GRN_EAST;	// Turn on North red. Turn on East green
	long_wait(80);						// Wait a bit
	GPIO_CLR0 = ALL_LEDS;				// Turn led off
	
	GPIO_SET0 = RED_NORTH | YEL_EAST;	// Turn on North red. Turn on East yellow 
	long_wait(20);						// Wait a short bit
	GPIO_CLR0 = ALL_LEDS;				// Turn led off
	
	GPIO_SET0 = RED_NORTH | RED_EAST;
	long_wait(20);
	GPIO_CLR0 = ALL_LEDS;

	GPIO_SET0 = YEL_NORTH | RED_EAST;
	long_wait(20);
	GPIO_CLR0 = ALL_LEDS;

	GPIO_SET0 = GRN_NORTH | RED_EAST;
	long_wait(80);
	GPIO_CLR0 = ALL_LEDS;	

	GPIO_SET0 = YEL_NORTH | RED_EAST;
	long_wait(20);
	GPIO_CLR0 = ALL_LEDS;

	GPIO_SET0 = RED_NORTH | RED_EAST;
	long_wait(20);
	GPIO_CLR0 = ALL_LEDS;	
	
	GPIO_SET0 = RED_NORTH | YEL_EAST;
	long_wait(20);
	GPIO_CLR0 = ALL_LEDS;
	
	
  i++;
  } 

  GPIO_CLR0 = ALL_LEDS;	//Turn all LEDs off
  restore_io();
} // main
Пример #16
0
static int gpio_wait(int pin)
{
	char path[BUFFER_MAX];
	int fd;
 
	snprintf(path, BUFFER_MAX, "/sys/class/gpio/gpio%d/value", pin);
	fd = open(path, O_RDONLY);
	if (-1 == fd) {
		fprintf(stderr, "Failed to open gpio for reading!\n");
		return -1;
	}

	read(fd, path, 3);

	struct pollfd p = {
		.fd = fd,
		.events = POLLPRI|POLLERR,
	};

	int r = poll(&p, 1, -1);
	if(r != 1) {
		fprintf(stderr, "poll() failed!\n");
		close(fd);
		return -1;
	}

	close(fd);
	return 0;
}
 
 
int main(int argv, char** argc)
{
	if(gpio_export(PIN)) {
		return 1;
	}

	gpio_direction(PIN, IN);

	setup();
	setup_gpio(POUT, OUTPUT, PUD_OFF);

	while(1) {
		gpio_edge(PIN, RISING);
		gpio_wait(PIN);
		output_gpio(POUT, HIGH);
		gpio_edge(PIN, FALLING);
		gpio_wait(PIN);
		output_gpio(POUT, LOW);
	}

	if(gpio_unexport(PIN)) {
		return 1;
	}

	return 0;
}
Пример #17
0
void cmain()
{
	setup_gpio();

	while (1) {
		led_on();
		wait();
		led_off();
		wait();
	}
}
Пример #18
0
// function run on exit of python
static void gpio_cleanup(void)
{
   int i;

//   printf("GPIO cleanup\n");
   for (i=0; i<54; i++)
      if (gpio_direction[i] != -1)
      {
//         printf("GPIO %d --> INPUT\n", i);
         setup_gpio(i, INPUT, PUD_OFF);
      }

    cleanup();
}
Пример #19
0
// python function setup(channel, direction, pull_up_down=PUD_OFF, initial=None)
static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwargs)
{
   unsigned int gpio;
   int channel, direction;
   int pud = PUD_OFF;
   int initial = -1;
   static char *kwlist[] = {"channel", "direction", "pull_up_down", "initial", NULL};
   int func;

   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &channel, &direction, &pud, &initial))
      return NULL;

   if (get_gpio_number(channel, &gpio))
       return NULL;

   if (direction != INPUT && direction != OUTPUT)
   {
      PyErr_SetString(InvalidDirectionException, "An invalid direction was passed to setup()");
      return NULL;
   }

   if (direction == OUTPUT)
      pud = PUD_OFF;

   if (pud != PUD_OFF && pud != PUD_DOWN && pud != PUD_UP)
   {
      PyErr_SetString(InvalidPullException, "Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN");
      return NULL;
   }

   func = gpio_function(gpio);
   if (gpio_warnings &&                             // warnings enabled and
       ((func != 0 && func != 1) ||                 // (already one of the alt functions or
       (gpio_direction[gpio] == -1 && func == 1)))  // already an output not set from this program)
   {
      PyErr_WarnEx(NULL, "This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.", 1);
   }

//   printf("Setup GPIO %d direction %d pud %d\n", gpio, direction, pud);
   if (direction == OUTPUT && (initial == LOW || initial == HIGH))
   {
//      printf("Writing intial value %d\n",initial);
      output_gpio(gpio, initial);
   }
   setup_gpio(gpio, direction, pud);
   gpio_direction[gpio] = direction;

   Py_INCREF(Py_None);
   return Py_None;
}
Пример #20
0
//
// Quick play all patterns
//
int main(void)
{ int p,r,last;

  printf ("These are the connections for the LEDs test:\n");
  printf ("jumpers in every out location (U3-out-B1, U3-out-B2, etc)\n");
  printf ("GP25 in J2 --- B1 in J3\n");
  printf ("GP24 in J2 --- B2 in J3\n");
  printf ("GP23 in J2 --- B3 in J3\n");
  printf ("GP22 in J2 --- B4 in J3\n");
  printf ("GP21 in J2 --- B5 in J3\n");
  printf ("GP18 in J2 --- B6 in J3\n");
  printf ("GP17 in J2 --- B7 in J3\n");
  printf ("GP11 in J2 --- B8 in J3\n");
  printf ("GP10 in J2 --- B9 in J3\n");
  printf ("GP9 in J2 --- B10 in J3\n");
  printf ("GP8 in J2 --- B11 in J3\n");
  printf ("GP7 in J2 --- B12 in J3\n");
  printf ("(If you don't have enough straps and jumpers you can install\n");
  printf ("just a few of them, then run again later with the next batch.)\n");
  printf ("When ready hit enter.\n");
  (void) getchar();

  // Map the I/O sections
  setup_io();

  // Set 12 GPIO pins to output mode
  setup_gpio();

  /* for testing purposes...
  GPIO_SET0 = 0x180;
  (void) getchar();
  GPIO_CLR0 = 0x100;
  (void) getchar();
  */

  for (p=0; p<3; p++)
  {
    // run pattern several times
    start_new_pattern(p);
    for (r=0; r<2; r++)
    { do {
        last = led_step();
        long_wait(3);
      } while (!last);
    } // run the pattern 2 times
  } // loop over patterns

  leds_off();
  restore_io();
} // main
Пример #21
0
// Python function cleanup()
// Sets everything back to input
static PyObject*
py_cleanup(PyObject *self, PyObject *args)
{
    int i;
    for (i=0; i<54; i++) {
        if (gpio_direction[i] != -1) {
            // printf("GPIO %d --> INPUT\n", i);
            setup_gpio(i, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
        }
    }

    Py_INCREF(Py_None);
    return Py_None;
}
Пример #22
0
//
//  Read ADC input 0 and show as horizontal bar
//
int main(void)
{ 
  setup_io();
  setup_gpio();

  while (1)
  {
//   short_wait();
	GPIO_CLR0 = 0x080;
//   short_wait();
	GPIO_SET0 = 0x080;
  }

  return 0;
}
Пример #23
0
int main(int argc, char **args)
{
	const ff_gpio *gpio = setup_gpio(GPIO7, A3);
	dump_gpio(main, gpio);

	blink(gpio);

	close(mem_fd);

	if (gpio->address != NULL)
		free(gpio->address);
	free(gpio);

	return 0;
}
Пример #24
0
// python function setup(channel, direction, pull_up_down=PUD_OFF, initial=None)
static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwargs)
{
   unsigned int gpio;
   int channel, direction;
   unsigned int sys_gpio;
   int pud = PUD_OFF + PY_PUD_CONST_OFFSET;
   static char *kwlist[] = {"channel", "direction", "pull_up_down", "initial", NULL};
   int initial = -1;
   
   if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii", kwlist, &channel, &direction, &pud, &initial))
      return NULL;
   // check module has been imported cleanly
   if (setup_error)
   {
      PyErr_SetString(PyExc_RuntimeError, "Module not imported correctly!");
      return NULL;
   }
  
   if (get_gpio_number(channel, &gpio, &sys_gpio)){
      return NULL;
 
   }
   if (direction != INPUT && direction != OUTPUT)
   {
      PyErr_SetString(PyExc_ValueError, "An invalid direction was passed to setup()");
      return NULL;
   }

   if (direction == OUTPUT)
      pud = PUD_OFF + PY_PUD_CONST_OFFSET;

   pud -= PY_PUD_CONST_OFFSET;
   if (pud != PUD_OFF && pud != PUD_DOWN && pud != PUD_UP)
   {
      PyErr_SetString(PyExc_ValueError, "Invalid value for pull_up_down - should be either PUD_OFF, PUD_UP or PUD_DOWN");
      return NULL;
   }
   
   if (direction == OUTPUT && (initial == LOW || initial == HIGH))
   {
      output_gpio(gpio, initial);
   }
   setup_gpio(gpio, direction, pud);
   
   gpio_direction[sys_gpio] = direction;
   
   Py_RETURN_NONE;
}
Пример #25
0
void
irpause()
{
    struct timespec ts = { .tv_sec = 0, .tv_nsec = 450000 };
    while(nanosleep(&ts, &ts) < 0 && errno == EINTR) ;
}

void
write_byte(uint8_t byte)
{
    for(int i = 0; i < 8; i++) {
        if(byte & 1) {
            output_gpio(gpio_pin, HIGH);
        }

        irpause();

        if(byte & 1) {
            output_gpio(gpio_pin, LOW);
        }

        irpause();

        byte >>= 1;
    }
}

int
main(int argc, const char** argv)
{
    if(argc < 2 || !(gpio_pin = atoi(argv[1]))) {
        fprintf(stderr, "usage: irtx <gpio pin>\n");
    }

    if(setup() != SETUP_OK) {
        fprintf(stderr, "could not set up GPIO\n");
    }

    setup_gpio(gpio_pin, OUTPUT, PUD_OFF);

    write_byte('X');

    cleanup();
}
Пример #26
0
void main(void)
{
	struct mem_timings *mem;
	int is_resume = (get_wakeup_state() != IS_NOT_WAKEUP);

	timestamp_init(timestamp_get());
	timestamp_add_now(TS_START_ROMSTAGE);

	/* Clock must be initialized before console_init, otherwise you may need
	 * to re-initialize serial console drivers again. */
	mem = setup_clock();

	console_init();
	exception_init();

	setup_power(is_resume);

	timestamp_add_now(TS_BEFORE_INITRAM);

	setup_memory(mem, is_resume);

	timestamp_add_now(TS_AFTER_INITRAM);

	/* This needs to happen on normal boots and on resume. */
	trustzone_init();

	if (is_resume) {
		wakeup();
	}

	setup_gpio();
	setup_graphics();

	/* Set SPI (primary CBFS media) clock to 50MHz and configure pinmux. */
	exynos_pinmux_spi1();
	clock_set_rate(PERIPH_ID_SPI1, 50000000);

	cbmem_initialize_empty();

	timestamp_add_now(TS_END_ROMSTAGE);

	run_ramstage();
}
Пример #27
0
int main(void)
{ //int p, r, last;

  ALL_LEDS = (L1|L2|L3|L4|L5|L6|L7|L8|L9|L10|L11|L12);
  setup_gpio();
  int x = 0;
  for(;;)
  {
  GPIO_SET0 = leds2[x];
  long_wait(1);
  GPIO_SET0 = 0;
  leds_off();
  long_wait(1);
  x++;
  if(x == 23)
  {x =0;}
  }
  return 0;
} // main
Пример #28
0
// python function cleanup()
static PyObject *py_cleanup(PyObject *self, PyObject *args)
{
    int i;

    // clean up any /sys/class exports
    event_cleanup();

    // set everything back to input
    for (i=0; i<54; i++)
        if (gpio_direction[i] != -1)
        {
//            printf("GPIO %d --> INPUT\n", i);
            setup_gpio(i, INPUT, PUD_OFF);
            gpio_direction[i] = -1;
        }

   Py_INCREF(Py_None);
   return Py_None;
}
Пример #29
0
void main(unsigned long bist)
{
	if (bist == 0)
		enable_lapic();

	i5000_lpc_config();

	w83627hf_enable_serial(PNP_DEV(0x2e, 2), 0x3f8);

	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	early_config();

	setup_gpio();

	enable_smbus();

	/* setup PCIe MMCONF base address */
	pci_write_config32(PCI_DEV(0, 16, 0), 0x64,
			   CONFIG_MMCONF_BASE_ADDRESS >> 16);

	outb(0x07, 0x11b8);

	/* These are smbus write captured with serialice. They
	   seem to setup the clock generator */

	smbus_write_byte(0x6f, 0x88, 0x1f);
	smbus_write_byte(0x6f, 0x81, 0xff);
	smbus_write_byte(0x6f, 0x82, 0xff);
	smbus_write_byte(0x6f, 0x80, 0x23);

	outb(0x03, 0x11b8);
	outb(0x01, 0x11b8);

	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xf0, DEFAULT_RCBA | 1);
	i5000_fbdimm_init();
	smbus_write_byte(0x69, 0x01, 0x01);
}
Пример #30
0
void mainboard_romstage_entry(unsigned long bist)
{
	if (bist == 0)
		enable_lapic();

	i5000_lpc_config();

	winbond_enable_serial(SERIAL_DEV, 0x3f8);
	console_init();

	/* Halt if there was a built in self test failure */
	report_bist_failure(bist);

	early_config();

	setup_gpio();

	enable_smbus();

	outb(0x07, 0x11b8);

	/* These are smbus write captured with serialice. They
	   seem to setup the clock generator */

	smbus_write_byte(0x6f, 0x88, 0x1f);
	smbus_write_byte(0x6f, 0x81, 0xff);
	smbus_write_byte(0x6f, 0x82, 0xff);
	smbus_write_byte(0x6f, 0x80, 0x23);

	outb(0x03, 0x11b8);
	outb(0x01, 0x11b8);

	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xf0, (uintptr_t)DEFAULT_RCBA | 1);
	i5000_fbdimm_init();
	smbus_write_byte(0x69, 0x01, 0x01);
}