Ejemplo n.º 1
0
int main(int argc, char **argv)
{
  int g,rep, i;
 
  // Set up gpi pointer for direct register access
  wiringPiSetupGpio ();
  setup_io();
  for (i = 0; i < 28; i++)
  {
	  INP_GPIO(i);
	  printf("%d", GET_GPIO(i));
  }
  printf("\n");
  //exit(0);
  OUT_GPIO(INT); GPIO_SET(INT);
  OUT_GPIO(NMI); GPIO_SET(NMI);
  OUT_GPIO(CLK); GPIO_SET(CLK);
  OUT_GPIO(WAIT); GPIO_SET(WAIT);
  OUT_GPIO(BUSRQ); GPIO_SET(BUSRQ);
  OUT_GPIO(RESET); GPIO_SET(RESET);
  OUT_GPIO(SI); GPIO_SET(SI);
  OUT_GPIO(CP); GPIO_SET(CP);
  OUT_GPIO(CS_16); GPIO_SET(CS_16);
  OUT_GPIO(M); 
  ResetSimulationVars();  
  WriteControlPins();
  DoReset();
  
  while(1)
	  loop();
}
Ejemplo n.º 2
0
void initMotor(OUT_MOTOR* motor, char * n1, char* n2, char * file, int pinPWM, int pinIN1, int pinIN2, int pinSTBY, double vitesse){
	motor->cap = fopen(file,"r");

	motor->pinSTBY = pinSTBY;
	motor->pinIN1 = pinIN1;
	motor->pinIN2= pinIN2;
	motor->pinPWM=pinPWM;

	INP_GPIO(pinIN1);
	INP_GPIO(pinIN2);
	INP_GPIO(pinSTBY);
	INP_GPIO(pinPWM);

	OUT_GPIO(pinIN1);
	OUT_GPIO(pinIN2);
	OUT_GPIO(pinSTBY);
	OUT_GPIO(pinPWM); 
	GPIO_SET = 1 << pinSTBY;
	GPIO_CLR = 1 << pinIN1 | 1 << pinIN2 | 1<< pinPWM;

	motor->vitesse=vitesse;
	int err = rt_task_create(&(motor->task),n1, TASK_STKSZ, TASK_PRIO, TASK_MODE);
	err |= rt_alarm_create(&(motor->alarm),n2);
	err |= rt_task_set_periodic(&(motor->task), TM_NOW, PERIODE_MOTOR);
	if (!err) {
		rt_task_start(&(motor->task),&taskMotor,motor);
	}

}
Ejemplo n.º 3
0
int main(int argc, char **argv) {
	//int rep;

	// Set up gpi pointer for direct register access
	setup_io();

	// GPIO23 - NTX2 enable
	INP_GPIO(23); // must use INP_GPIO before we can use OUT_GPIO
	OUT_GPIO(23);
	// GPIO18 - NTX2 Data	
	INP_GPIO(18); // must use INP_GPIO before we can use OUT_GPIO
	OUT_GPIO(18);


	GPIO_SET = 1<<23;

	char send[]="I'm growing a beard\n";

	//for (rep=0; rep<8; rep++) {
		int i;
		for (i=0; i<strlen(send); i++){
			domex_txbyte(send[i]);
		}
	//}
	GPIO_CLR = 1<<23;
	return 0;

}
Ejemplo n.º 4
0
static int bcm2835gpio_init(void)
{
	bitbang_interface = &bcm2835gpio_bitbang;

	if (!is_gpio_valid(tdo_gpio) || !is_gpio_valid(tdi_gpio) ||
		!is_gpio_valid(tck_gpio) || !is_gpio_valid(tms_gpio) ||
		(trst_gpio != -1 && !is_gpio_valid(trst_gpio)) ||
		(srst_gpio != -1 && !is_gpio_valid(srst_gpio)))
		return ERROR_JTAG_INIT_FAILED;

	dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
	if (dev_mem_fd < 0) {
		perror("open");
		return ERROR_JTAG_INIT_FAILED;
	}

	pio_base = mmap(NULL, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE,
				MAP_SHARED, dev_mem_fd, BCM2835_GPIO_BASE);

	if (pio_base == MAP_FAILED) {
		perror("mmap");
		close(dev_mem_fd);
		return ERROR_JTAG_INIT_FAILED;
	}

	tdo_gpio_mode = MODE_GPIO(tdo_gpio);
	tdi_gpio_mode = MODE_GPIO(tdi_gpio);
	tck_gpio_mode = MODE_GPIO(tck_gpio);
	tms_gpio_mode = MODE_GPIO(tms_gpio);
	/*
	 * Configure TDO as an input, and TDI, TCK, TMS, TRST, SRST
	 * as outputs.  Drive TDI and TCK low, and TMS/TRST/SRST high.
	 */
	INP_GPIO(tdo_gpio);

	GPIO_CLR = 1<<tdi_gpio | 1<<tck_gpio;
	GPIO_SET = 1<<tms_gpio;

	OUT_GPIO(tdi_gpio);
	OUT_GPIO(tck_gpio);
	OUT_GPIO(tms_gpio);
	if (trst_gpio != -1) {
		trst_gpio_mode = MODE_GPIO(trst_gpio);
		GPIO_SET = 1 << trst_gpio;
		OUT_GPIO(trst_gpio);
	}
	if (srst_gpio != -1) {
		srst_gpio_mode = MODE_GPIO(srst_gpio);
		GPIO_SET = 1 << srst_gpio;
		OUT_GPIO(srst_gpio);
	}

	LOG_DEBUG("saved pinmux settings: tck %d tms %d tdi %d "
		  "tdo %d trst %d srst %d", tck_gpio_mode, tms_gpio_mode,
		  tdi_gpio_mode, tdo_gpio_mode, trst_gpio_mode, srst_gpio_mode);

	return ERROR_OK;
}
Ejemplo n.º 5
0
Archivo: dotstar.c Proyecto: TobiBu/POV
// Initialize pins/SPI for output
static PyObject *begin(DotStarObject *self) {
	if(self->dataPin == 0xFF) { // Use hardware SPI
		if((self->fd = open("/dev/spidev0.0", O_RDWR)) < 0) {
			printf("Can't open /dev/spidev0.0 (try 'sudo')\n");
			return NULL;
		}
		uint8_t mode = SPI_MODE_0 | SPI_NO_CS;
		ioctl(self->fd, SPI_IOC_WR_MODE, &mode);
		// The actual data rate may be less than requested.
		// Hardware SPI speed is a function of the system core
		// frequency and the smallest power-of-two prescaler
		// that will not exceed the requested rate.
		// e.g. 8 MHz request: 250 MHz / 32 = 7.8125 MHz.
		ioctl(self->fd, SPI_IOC_WR_MAX_SPEED_HZ, self->bitrate);
		xfer[0].tx_buf = (unsigned long)header;
		xfer[2].tx_buf = (unsigned long)footer;
		xfer[0].speed_hz = xfer[1].speed_hz = xfer[2].speed_hz =
		  self->bitrate;
	} else { // Use bitbang "soft" SPI (any 2 pins)
		if(gpio == NULL) { // First time accessing GPIO?
			int fd;

			if((fd = open("/dev/mem", O_RDWR | O_SYNC)) < 0) {
				printf("Can't open /dev/mem (try 'sudo')\n");
				return NULL;
			}
			isPi2 = (boardType() == 2);
			gpio  = (volatile unsigned *)mmap( // Memory-map I/O
			  NULL,                 // Any adddress will do
			  BLOCK_SIZE,           // Mapped block length
			  PROT_READ|PROT_WRITE, // Enable read+write
			  MAP_SHARED,           // Shared w/other processes
			  fd,                   // File to map
			  isPi2 ?
			   PI2_GPIO_BASE :      // -> GPIO registers
			   PI1_GPIO_BASE);
			close(fd);              // Not needed after mmap()
			if(gpio == MAP_FAILED) {
				err("Can't mmap()");
				return NULL;
			}
			gpioSet = &gpio[7];
			gpioClr = &gpio[10];
		}

		self->dataMask  = 1 << self->dataPin;
		self->clockMask = 1 << self->clockPin;

		// Set 2 pins as outputs.  Must use INP before OUT.
		INP_GPIO(self->dataPin);  OUT_GPIO(self->dataPin);
		INP_GPIO(self->clockPin); OUT_GPIO(self->clockPin);

		*gpioClr = self->dataMask | self->clockMask; // data+clock LOW
	}

	Py_INCREF(Py_None);
	return Py_None;
}
Ejemplo n.º 6
0
void init(uint8_t dataPin, uint8_t clockPin) {
    setup_io();

    INP_GPIO(dataPin); // must use INP_GPIO before we can use OUT_GPIO
    OUT_GPIO(dataPin);

    INP_GPIO(clockPin); // must use INP_GPIO before we can use OUT_GPIO
    OUT_GPIO(clockPin);
}
Ejemplo n.º 7
0
void userApp1(void * args)
{
    int n_pin;
    // set all the seg not to illume
    for (n_pin = 0; n_pin < 8; ++n_pin){
        INP_GPIO(pin[n_pin]);
        OUT_GPIO(pin[n_pin]);
        digitalWrite(pin[n_pin], HIGH);
    }

    // set all the node not to off 
    for(n_pin = 0; n_pin < 4; ++n_pin){
        INP_GPIO(node[n_pin]);
        OUT_GPIO(node[n_pin]);
        digitalWrite(node[n_pin], LOW);
    }

    INP_GPIO(16);
    OUT_GPIO(16);

    int i_node = 0;
    int disp_buffer[4] = {5, 0, 5, 0};
    int disp_num = 0;
    int last_dht11_dat0 = dht11_dat[0], last_dht11_dat2 = dht11_dat[2];

    int i, update_flag;

	while(1)
	{
        if(last_dht11_dat0 != dht11_dat[0] || last_dht11_dat2 != dht11_dat[2]){
            disp_buffer[1] = dht11_dat[0]%10;
            disp_buffer[0] = dht11_dat[0]/10;
            disp_buffer[3] = dht11_dat[2]%10;
            disp_buffer[2] = dht11_dat[2]/10;
        }

        last_dht11_dat0 = dht11_dat[0];
        last_dht11_dat2 = dht11_dat[2];

        digitalWrite(node[i_node], LOW);
        i_node = (i_node+1) % 4; 
        disp_num = disp_buffer[i_node];

        for(n_pin = 0; n_pin < 8; ++n_pin){
            digitalWrite(pin[n_pin], digit[disp_num][n_pin]);
        } 

        digitalWrite(node[i_node], HIGH);

        //wtf_delay(100);
        OSTimeDly(1);
	}
}
Ejemplo n.º 8
0
void setup_shiftreg()
{
  // set SER to output
  INP_GPIO(SER);
  OUT_GPIO(SER);
  // set SCLK to output
  INP_GPIO(SCLK);
  OUT_GPIO(SCLK);
  // set RCLK to output
  INP_GPIO(RCLK);
  OUT_GPIO(RCLK);
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
#ifdef DEMO_ENABLED
  int g,rep;
#endif

  /* Set up gpi pointer for direct register access */
  setup_io();
#ifndef DEMO_ENABLED  
  /* Set GPIO pin 4 to output */
  INP_GPIO(pin); 
  OUT_GPIO(pin);
#else
  /* Set all exposed GPIO pins to output */
  for (g = 0; g <= 32; g++)
  {
    if( ((1<<g) & 0x3e6cf93) != 0)
    {
      INP_GPIO(g);
      OUT_GPIO(g);
    }
  }
  GPIO_CLR = 0x3e6cf93; //clear all output pins
#endif

#ifdef DEMO_ENABLED
  while (1)
  {
    for (rep = 0; rep < 14; rep++)
    { 
      GPIO_SET = 1<<pins[rep];
      printf("Set pin: %d\n", pins[rep]);
      sleep(1);
      GPIO_CLR = 1<<pins[rep];
      printf("Clear pin: %d\n", pins[rep]);
      sleep(1);
    }
  }
#else
  while (1)
  {
    GPIO_SET = 1<<pin;
    printf("Set pin: %d\n", pin);
    sleep(1);
    GPIO_CLR = 1<<pin;
    printf("Clear pin: %d\n", pin);
    sleep(1);
  }
#endif

  return 0;
}
Ejemplo n.º 10
0
int main()
{

int g,rep;
setup_io(); /*Direct Register access*/

#if 0
/*Set gpio 7..11 to outpu mode*/
for(g=7; g <= 18; g++)
{
 INP_GPIO(g);
 OUT_GPIO(g);

} 
#endif

INP_GPIO(17);
OUT_GPIO(17);

while(1)
{
 GPIO_SET = 1 << 17;
 //delay(500);
 sleep(1);
 GPIO_CLR = 1 << 17;
 //delay(500);
 sleep(1);

}

#if 0
for (rep=0; rep=10; rep++)
{  
  for(g=7; g <= 11; g++)
   {
      GPIO_SET = 1 << g;
      sleep(1);
   }
  for(g=7; g<= 11; g++)
  {
      GPIO_CLR = 1 << g;
      sleep(1); 
  } 
}


#endif

}
Ejemplo n.º 11
0
int rpi_gpio_open(struct rtdm_dev_context *context, rtdm_user_info_t *user_info, int oflags)
{
  struct rpi_gpio_context *ctx;
  
  ctx = (struct rpi_gpio_context *) context->dev_private;
  ctx->gpio_addr = virt_addr;
  ctx->gpio_rt = gpio_rt;
  ctx->gpio_nrt = gpio_nrt;


  OUT_GPIO(ctx->gpio_addr, ctx->gpio_rt);
  OUT_GPIO(ctx->gpio_addr, ctx->gpio_nrt);

  return 0;
}
Ejemplo n.º 12
0
/** 
 * init_module() - This function is called when the module is loaded
 * 
 * Return: On succes the function retuns a 0 (SUCCES). Otherwise a 
 * negative number is returned.
 */
int init_module(void)
{
	Major = register_chrdev(0, DEVICE_NAME, &fops);
	if (Major < 0) 
	{
		printk(KERN_ALERT "Registering char device failed with %d\n", Major);
		return Major;
	}
    
	printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);
	printk(KERN_INFO "the driver, create a device file with\n");
        
	printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
	printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");
	printk(KERN_INFO "the device file.\n");
	printk(KERN_INFO "Remove the device file and module when done.\n");
    
    // Map GPIO
    gpio.map = ioremap(GPIO_BASE, 1); //Gives a pointer to the first GPIO register
	gpio.addr = (volatile unsigned int *)gpio.map;

	// Set pin directions for the LED
    INP_GPIO(GPIO_LED);
	OUT_GPIO(GPIO_LED);
    
	return SUCCESS;
}
Ejemplo n.º 13
0
//
// Configure GPIOs as input or output
//
void gpioSetPin(uint8_t pin, uint8_t dir) {

  // Set pin number to given direction
  INP_GPIO(pin);  // Must make pin an input first, even for output
  if (dir == GPIO_OUTPUT)
    OUT_GPIO(pin);
}
Ejemplo n.º 14
0
int 
main()
{
	if(init_gpio() == -1) 
	{
		printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
        return (-1);
    }
	
	printf("Helloblink is started with GIOP%d at pin number 8.\n", LED_PIN);
	
	// Define gpio 4 (LED) as output
	INP_GPIO(LED_PIN);
	OUT_GPIO(LED_PIN);

	while(1)
	{
		GPIO_SET(LED_PIN);
		usleep(100 * 1000);
	
		GPIO_CLR(LED_PIN);
		usleep(100 * 1000);
	}

	return 0;	
}
Ejemplo n.º 15
0
bool HWAbstraction::setupIO() {
    int memFd;
    /* open /dev/mem */
    if ((memFd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
        printf("can't open /dev/mem \n");
        return false;
    }

    /* mmap GPIO */
    m_gpioMap = mmap(
                    NULL,             //Any adddress in our space will do
                    BLOCK_SIZE,       //Map length
                    PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
                    MAP_SHARED,       //Shared with other processes
                    memFd,           //File to map
                    GPIO_BASE         //Offset to GPIO peripheral
                );

    close(memFd); //No need to keep mem_fd open after mmap

    if (m_gpioMap == MAP_FAILED) {
        printf("mmap error %p\n", m_gpioMap);//errno also set!
        return false;
    }

    // Always use volatile pointer!
    m_gpio = (volatile unsigned *)m_gpioMap;
    INP_GPIO(25);
    OUT_GPIO(25);

    return true;
} // setup_io
Ejemplo n.º 16
0
Archivo: rpi.c Proyecto: hsbp/seg7tiny
int main()
{
	int ch;
	if (map_peripheral(&gpio) == -1) {
		printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
		return -1;
	}

	// Define pin as output
	INP_GPIO(PIN);
	OUT_GPIO(PIN);

	BIT1();
	while((ch = getchar()) != EOF) {
		short bit;
		usleep(4000);
		BIT0(); // start
		usleep(BITLEN);
		for (bit = 1; bit != 0x100; bit <<= 1) {
			if (bit & ch) BIT1(); else BIT0();
			usleep(BITLEN);
		}
		BIT1(); // stop
		usleep(BITLEN);
	}

	return 0;
}
Ejemplo n.º 17
0
inline void pinMode(int g, int dir)
{
	if (dir == OUTPUT)
		OUT_GPIO(g);
	else
		INP_GPIO(g);
}
void WriteByte(unsigned char value)
{
  unsigned char Mask=1;
  int loop;

   for(loop=0;loop<8;loop++)
     {
       INP_GPIO(DS_PIN);
       OUT_GPIO(DS_PIN);
       GPIO_CLR= 1 <<DS_PIN;

       if((value & Mask)!=0)
        {
           DELAY1US
            INP_GPIO(DS_PIN);
           DelayMicrosecondsNoSleep(60);

        }
        else
        {
           DelayMicrosecondsNoSleep(60);
           INP_GPIO(DS_PIN);
           DelayMicrosecondsNoSleep(1);
        }
      Mask*=2;
      DelayMicrosecondsNoSleep(60);
    }


   usleep(100);
}
unsigned char ReadByte(void)
{

   unsigned char Mask=1;
   int loop;
   unsigned  char data=0;

  int loop2;


   for(loop=0;loop<8;loop++)
     {
       //  set output
       INP_GPIO(DS_PIN);
       OUT_GPIO(DS_PIN);
       //  PIN LOW
       GPIO_CLR= 1<<DS_PIN;
       DELAY1US
       //  set input
       INP_GPIO(DS_PIN);
       // Wait  2 us
       DelayMicrosecondsNoSleep(2);
       if(GPIO_READ(DS_PIN)!=0)
       data |= Mask;
       Mask*=2;
       DelayMicrosecondsNoSleep(60);
      }

    return data;
}
Ejemplo n.º 20
0
int buzzer_main(int argc, const char* argv[]) {
    if(map_peripheral(&g_gpio) == -1) {
        printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
        return -1;
    }
    s_pin = 4;
    INP_GPIO(s_pin);
    OUT_GPIO(s_pin);
 
    size_t len = 64;
    char* line = (char*)malloc(len);
    int fre = 0;
    int elapsed = 0;
 
    while (getline(&line, &len, stdin) != -1) {
        int r = sscanf(line, "%d %d\n", &fre, &elapsed);
        if (r == 2) {
            if (fre < 20) {
                // no sound
                usleep(elapsed*1000);
            } else {
                playSound(fre, elapsed);
            }
        } else {
            fprintf(stderr, "skip, invalid line: %s", line);
        }
    }
 
    printf("sound count = %lld, high = %lld, low = %lld\n", s_count, s_high, s_low);
    free(line);
    return 0;
}
Ejemplo n.º 21
0
int gpio_direction_output(unsigned gpio, int value)
{
   INP_GPIO(gpio);
   OUT_GPIO(gpio);
   gpio_set_value(gpio, value);
   return 0;
}
Ejemplo n.º 22
0
int main(int argc, char *argv[]) {
	int g, rep;

	// Setup the gpio pointer
	setup_io();

	// Swtich GPIOs 7 though 11 to output mode
	for (g = 5; g <= 6; g++) {
		INP_GPIO(g);
		OUT_GPIO(g);
		GPIO_CLR = 1 << g;			// SET it LOW
	}

	// Toggle the GPIOs
	for (rep = 0; rep < 5; rep++) {
		
		printf("Repetition: %i\n", rep);

		for (g = 5; g <= 6; g++) {
			GPIO_SET = 1 << g;
			printf("  HIGH: %i\n", g);
//			sleep(1);
			usleep(500000);
			GPIO_CLR = 1 << g;
			printf("  LOW: %i\n", g);
//			sleep(1);
			usleep(500000);
		}
	}
	
	// Ran file
	return 0;
}
Ejemplo n.º 23
0
int main()
{
    int value;
  if(map_peripheral(&gpio) == -1) 
  {
    printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
    return -1;
  }
 
  // Define pin 17 as output
  INP_GPIO(2);
  OUT_GPIO(17);
 
  while(1)
  {
    // Toggle pin 17 (blink a led!)
    GPIO_SET = 1 << 17;
    sleep(1);
 
    value = GPIO_READ(2);
    while(!value) {
//        delay(20);
        value = GPIO_READ(2);
    }
    
    GPIO_CLR = 1 << 17;
    sleep(1);
  }
 
  return 0; 
}
Ejemplo n.º 24
0
JNIEXPORT jboolean JNICALL Java_javaforce_pi_GPIO_configOutput
  (JNIEnv *env, jclass obj, jint bit)
{
  INP_GPIO(bit);  //Always use INP_GPIO before OUT_GPIO -- why???
  OUT_GPIO(bit);
  return JNI_TRUE;
}
Ejemplo n.º 25
0
Archivo: GPIO.c Proyecto: woody2/ledbar
int initGPIO() {
	// Map the GPIO and Aux memory
	mGPIO = mapMem ( GPIO_BASE, 0x1000 );

	// UART1 = Mini-UART, UART0 - PL011
	// Set GPIO15 and 16 for UART1 to ALT5 Mini-Uart
	INP_GPIO ( kBufferDirectionPin );
	OUT_GPIO ( kBufferDirectionPin );
	INP_GPIO ( kScopeTriggerPin );
	OUT_GPIO ( kScopeTriggerPin );
	INP_GPIO ( kUART1TxPin );
	SET_GPIO_ALT ( kUART1TxPin, 5 );
	INP_GPIO ( kUART1RxPin );
	SET_GPIO_ALT ( kUART1RxPin, 5 );
	INP_GPIO ( kUART1RTSPin);
	SET_GPIO_ALT ( kUART1RTSPin, 5 );
}
Ejemplo n.º 26
0
/** 
 * init_module() - This function is called when the module is loaded
 * 
 * Return: On succes the function retuns a 0 (SUCCES). Otherwise a 
 * negative number is returned.
 */
int init_module(void)
{
	Major = register_chrdev(0, DEVICE_NAME, &fops);
	if (Major < 0) 
	{
		printk(KERN_ALERT "Registering char device failed with %d\n", Major);
		return Major;
	}
    
	printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);
	printk(KERN_INFO "the driver, create a device file with\n");
        
	printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
	printk(KERN_INFO "Try various minor numbers. Try to echo to\n");
	printk(KERN_INFO "the device file.\n");
	printk(KERN_INFO "Remove the device file and module when done.\n");
    
	gpio = (volatile unsigned int *)ioremap(GPIO_BASE,  1024);
	pwm  = (volatile unsigned int *)ioremap(PWM_BASE,   1024);
	clk  = (volatile unsigned int *)ioremap(CLOCK_BASE, 1024);
	
	// Set pin directions for the output
	INP_GPIO(GPIO_OUTP);
	OUT_GPIO(GPIO_OUTP);
	
	// PWM and clock settings 
	
	SET_GPIO_ALT(GPIO_PWM1, GPIO_ALT);
	
	// stop clock and waiting for busy flag doesn't work, so kill clock
	*(clk + CLK_CTL) = CLK_PASSWD | CLK_CTL_KILL; 
	udelay(10);  
	
	// Set clock divider
	*(clk + CLK_DIV)  = CLK_PASSWD | CLK_DIV_DIVI(96); 
	
	// source=osc and enable clock
	*(clk + CLK_CTL) = CLK_PASSWD | CLK_CTL_ENAB | CLK_CTL_SRC(CLK_CTL_SRC_OSC); 

	// disable PWM and start with a clean register
	*(pwm + PWM_CTL) = 0;
	
	// needs some time until the PWM module gets disabled, without the delay the PWM module crashes
	udelay(10);  
	
	// Set the PWM range
	*(pwm + PWM_RNG2) = 4000;
	
	// Initialize with a 50% dutycycle
	setServo(50);
	
	// start PWM in M/S transmission mode
	*(pwm + PWM_CTL) = PWM_CTL_MSEN2 | PWM_CTL_PWEN2;
	
	interrupt_config();
    
	return SUCCESS;
}
Ejemplo n.º 27
0
//
// Set GPIO pins to the right mode
// DEMO GPIO mapping:
//         Function            Mode
// GPIO0=  LED                 Output
// GPIO1=  LED                 Output
// GPIO4=  PWM channel-B       Output
// GPIO7=  SPI chip select B   Funct. 0
// GPIO8=  SPI chip select A   Funct. 0
// GPIO9=  SPI MISO            Funct. 0
// GPIO10= SPI MOSI            Funct. 0
// GPIO11= SPI CLK             Funct. 0
// GPIO14= UART TXD           (Funct. 0)
// GPIO15= UART RXD           (Funct. 0)
// GPIO17= LED                 Output
// GPIO18= PWM channel-A       Funct. 5
// GPIO21= LED                 Output
// GPIO22= LED                 Output
// GPIO23= LED                 Output
// GPIO24= Pushbutton          Input
// GPIO25= Pushbutton          Input
//
// Always call INP_GPIO(x) first
// as that is how the macros work
void setup_gpio()
{
   INP_GPIO(0);  OUT_GPIO(0);
   INP_GPIO(1);  OUT_GPIO(1);
   INP_GPIO(4);  OUT_GPIO(4);
   INP_GPIO(7);  SET_GPIO_ALT(7,0);
   INP_GPIO(8);  SET_GPIO_ALT(8,0);
   INP_GPIO(9);  SET_GPIO_ALT(9,0);
   INP_GPIO(10); SET_GPIO_ALT(10,0);
   INP_GPIO(11); SET_GPIO_ALT(11,0);
   // 14 and 15 are already set to UART mode
   // by Linux. Best if we don't touch them
   // INP_GPIO(14); SET_GPIO_ALT(14,0);
   // INP_GPIO(54); SET_GPIO_ALT(15,0);
   INP_GPIO(17);  OUT_GPIO(17);
   INP_GPIO(18);  SET_GPIO_ALT(18,5);
   INP_GPIO(21);  OUT_GPIO(21);
   INP_GPIO(22);  OUT_GPIO(22);
   INP_GPIO(23);  OUT_GPIO(23);
   INP_GPIO(24);
   INP_GPIO(25);

   // enable pull-up on GPIO24&25
   GPIO_PULL = 2;
   short_wait();
   // clock on GPIO 24 & 25 (bit 24 & 25 set)
   GPIO_PULLCLK0 = 0x03000000;
   short_wait();
   GPIO_PULL = 0;
   GPIO_PULLCLK0 = 0;
} // setup_gpio
Ejemplo n.º 28
0
static unsigned char* PinMode(struct uState* S, unsigned char* pc, number* res) {
  if (!res) return skip(S, skip(S, pc));
  number pin;
  pc = eval(S, pc, &pin);
  pc = eval(S, pc, res);
  INP_GPIO(pin);
  if (*res) OUT_GPIO(pin);
  return pc;
}
Ejemplo n.º 29
0
void gpio_setout(int g)
{
#ifndef GPIO_SIMULATED
  /* always INP_GPIO before OUT_GPIO */
  //INP_GPIO(g); #### this causes glitching
  OUT_GPIO(g);
#else
  printf("gpio:out:%d\n", g);
#endif
}
Ejemplo n.º 30
0
int setup_io()
{
    /* open /dev/mem */
    if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0)
    {
        printf("can't open /dev/mem \n");
        return -1;
    }
    
    /* mmap GPIO */
    gpio_map = mmap(
        NULL,                //Any adddress in our space will do
        BLOCK_SIZE,          //Map length
        PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
        MAP_SHARED,          //Shared with other processes
        mem_fd,              //File to map
        GPIO_BASE);

    close(mem_fd); //No need to keep mem_fd open after mmap
    
    if (gpio_map == MAP_FAILED)
    {
        printf("mmap error %d\n", (int)gpio_map);
        return -2;
    }
    
    // Always use volatile pointer!
    gpio = (volatile unsigned *)gpio_map;
    
    INP_GPIO(JTAG_TCK);
    INP_GPIO(JTAG_TMS);
    INP_GPIO(JTAG_TDI);
    INP_GPIO(JTAG_TDO); //Receive output from Device to rpi

    nop_sleep(WAIT);

    OUT_GPIO(JTAG_TDI); //Send data from rpi to Device
    OUT_GPIO(JTAG_TMS);
    OUT_GPIO(JTAG_TCK);
    nop_sleep(WAIT);

    return 0;
}