Exemplo n.º 1
0
int main(int argc, char **argv) {

	int value1,value2;

	printf("Gumstix GPIO test\n");

	gpio_enable(146);
	gpio_enable(147);

	gpio_set_write(146);
	gpio_set_write(147);

	value1=gpio_read(146);
	value2=gpio_read(147);

	value2=!value1;

	while(1){
		gpio_write(146,value1);
		gpio_write(147,value2);

		value1=!value1;
		value2=!value2;
		usleep(500000);

	}

	return 0;
}
Exemplo n.º 2
0
void HardwareSerial::begin(unsigned int baud) {
// for now, do nothing. We will use whatever the ISP had set up.
  measurePCLK();

#if MCU == MCU_ARM7TDMI
  //Set up the pins
  if(port==0) {
    gpio_set_write(0);
    gpio_set_read(1);
    set_pin(0,1); //TX0
    set_pin(1,1); //RX0
  } else {
    gpio_set_write(8);
    gpio_set_read(9);
    set_pin(8,1); //TX1
    set_pin(9,1); //RX1
  }
#else
  //This only knows how to set up UART0.
  IODIR(0)|= (1<<2); //TX set to output
  IODIR(0)&=~(1<<3); //RX set to input
  IOCON(0,2)=(0b010 << 0) |  //Function TX0
             (0b00  << 3) |  //No pullup/pulldown
             (0b0   << 5) |  //No hysteresis
             (0b0   << 6) |  //No inversion
             (0b0   << 9) |  //Standard slew
             (0b0   <<10) ;  //Not open-drain
  IOCON(0,3)=(0b010 << 0) |  //Function RX0
             (0b00  << 3) |  //No pullup/pulldown
             (0b0   << 5) |  //No hysteresis
             (0b0   << 6) |  //No inversion
             (0b0   << 9) |  //Standard slew
             (0b0   <<10) ;  //Not open-drain
#endif
  ULCR(port) = (3 << 0) | //8 data bits
               (0 << 2) | //1 stop bit
               (0 << 3) | //No parity
               (0 << 4) | //I said, no parity!
               (0 << 6) | //No break transmission
               (1 << 7);  //DLAB = 1
  //DLAB - Divisor Latch Access bit. When set, a certain memory address
  //       maps to the divisor latches, which control the baud rate. When
  //       cleared, those same addresses correspond to the processor end
  //       of the FIFOs. In other words, set the DLAB to change the baud
  //       rate, and clear it to use the FIFOs.

  unsigned int Denom=PCLK/baud;
  unsigned int UDL=Denom/16;

  UDLM(port)=(UDL >> 8) & 0xFF;
  UDLL(port)=(UDL >> 0) & 0xFF;
  UFDR(port)=0x10; //reset nilpotent value

  UFCR(port) = (1 << 0) |  //FIFOs on
               (1 << 1) |  //Clear rx FIFO
               (1 << 2) |  //Clear tx FIFO
               (3 << 6);   //Rx watermark=14 bytes
  ULCR(port) = ULCR(port) & ~(1<<7); //Turn of DLAB - FIFOs accessable
  UIER(port)=0;

}