Exemplo n.º 1
0
Arquivo: PL061Gpio.c Projeto: pmj/edk2
/**

Routine Description:

  Gets the mode (function) of a GPIO pin

Arguments:

  This  - pointer to protocol
  Gpio  - which pin
  Mode  - pointer to output mode value

Returns:

  EFI_SUCCESS           - mode value retrieved
  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range

**/
EFI_STATUS
EFIAPI
GetMode (
  IN  EMBEDDED_GPIO       *This,
  IN  EMBEDDED_GPIO_PIN   Gpio,
  OUT EMBEDDED_GPIO_MODE  *Mode
  )
{
  EFI_STATUS    Status = EFI_SUCCESS;
  UINTN         Index, Offset, RegisterBase;

  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  ASSERT_EFI_ERROR (Status);

  // Check for errors
  if (Mode == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  // Check if it is input or output
  if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK(Offset)) {
    // Pin set to output
    if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset))) {
      *Mode = GPIO_MODE_OUTPUT_1;
    } else {
      *Mode = GPIO_MODE_OUTPUT_0;
    }
  } else {
    // Pin set to input
    *Mode = GPIO_MODE_INPUT;
  }

  return EFI_SUCCESS;
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
void
spi_cs_init(uint8_t port, uint8_t pin)
{
  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  ioc_set_over(port, pin, IOC_OVERRIDE_DIS);
  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  GPIO_SET_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
static void
config_gpio(uint8_t port, uint8_t pin, uint8_t type)
{
  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  if(type == HWTEST_GPIO_OUTPUT) {
    GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  } else if(type == HWTEST_GPIO_INPUT) {
    GPIO_SET_INPUT(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  }
}
Exemplo n.º 4
0
/**

Routine Description:

  Sets the state of a GPIO pin

Arguments:

  This  - pointer to protocol
  Gpio  - which pin to modify
  Mode  - mode to set

Returns:

  EFI_SUCCESS           - GPIO set as requested
  EFI_UNSUPPORTED       - Mode is not supported
  EFI_INVALID_PARAMETER - Gpio pin is out of range
**/
EFI_STATUS
EFIAPI
Set (
  IN  EMBEDDED_GPIO       *This,
  IN  EMBEDDED_GPIO_PIN   Gpio,
  IN  EMBEDDED_GPIO_MODE  Mode
  )
{
  EFI_STATUS    Status = EFI_SUCCESS;
  UINTN         Index, Offset, RegisterBase;

  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  if (EFI_ERROR (Status))
    goto EXIT;

  // Initialize the hardware if not already done
  if (!mPL061Initialized) {
    Status = PL061Initialize();
    if (EFI_ERROR(Status)) {
      goto EXIT;
    }
  }

  switch (Mode)
  {
    case GPIO_MODE_INPUT:
      // Set the corresponding direction bit to LOW for input
      MmioAnd8 (RegisterBase + PL061_GPIO_DIR_REG, ~GPIO_PIN_MASK(Gpio));
      break;

    case GPIO_MODE_OUTPUT_0:
      // Set the corresponding data bit to LOW for 0
      MmioWrite8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2), 0);
      // Set the corresponding direction bit to HIGH for output
      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));
      break;

    case GPIO_MODE_OUTPUT_1:
      // Set the corresponding data bit to HIGH for 1
      MmioWrite8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2), 0xff);
      // Set the corresponding direction bit to HIGH for output
      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));
      break;

    default:
      // Other modes are not supported
      return EFI_UNSUPPORTED;
  }

EXIT:
  return Status;
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static void
floppin(uint8_t port, uint8_t pin)
{
  uint8_t i;
  GPIO_CLR_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  clock_delay_usec(500);
  for(i = 0; i < 50; i++) {
    GPIO_SET_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
    clock_delay_usec(500);
    GPIO_CLR_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
    clock_delay_usec(500);
  }
}
Exemplo n.º 6
0
void gpio_irq_enable(gpio_t dev)
{
    if (gpio_enabled(dev)) {
        int pin = pin_lut[dev];
        GPIO_NUM_TO_DEV(pin)->IE |= GPIO_PIN_MASK(GPIO_BIT_NUM(pin));
    }
}
Exemplo n.º 7
0
Arquivo: PL061Gpio.c Projeto: pmj/edk2
/**

Routine Description:

  Gets the state of a GPIO pin

Arguments:

  This  - pointer to protocol
  Gpio  - which pin to read
  Value - state of the pin

Returns:

  EFI_SUCCESS           - GPIO state returned in Value
  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
**/
EFI_STATUS
EFIAPI
Get (
  IN  EMBEDDED_GPIO     *This,
  IN  EMBEDDED_GPIO_PIN Gpio,
  OUT UINTN             *Value
  )
{
  EFI_STATUS    Status = EFI_SUCCESS;
  UINTN         Index, Offset, RegisterBase;

  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  ASSERT_EFI_ERROR (Status);

  if (Value == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset))) {
    *Value = 1;
  } else {
    *Value = 0;
  }

  return EFI_SUCCESS;
}
Exemplo n.º 8
0
int gpio_init_int(gpio_t dev, gpio_mode_t mode, gpio_flank_t flank,
                  gpio_cb_t cb, void *arg)
{
    int res, pin, irq_num;
    uint32_t mask;
    cc2538_gpio_t* instance;

    /* Note: gpio_init() also checks if the gpio is enabled. */
    res = gpio_init(dev, mode);
    if (res < 0) {
        return res;
    }

    /* Store the callback information for later: */
    gpio_config[dev].cb  = cb;
    gpio_config[dev].arg = arg;

    pin = pin_lut[dev];
    mask = GPIO_PIN_MASK(GPIO_BIT_NUM(pin));

    instance = GPIO_NUM_TO_DEV(pin);

    /* Enable power-up interrupts for this GPIO port: */
    SYS_CTRL_IWE |= BIT(GPIO_NUM_TO_PORT_NUM(pin));

    switch(flank) {
        case GPIO_FALLING:
            instance->IBE         &= ~mask;     /**< Not both edges */
            instance->IEV         &= ~mask;     /**< Falling edge */
            instance->P_EDGE_CTRL |=  BIT(pin); /**< Falling edge power-up interrupt */
            break;

        case GPIO_RISING:
            instance->IBE         &= ~mask;     /**< Not both edges */
            instance->IEV         |=  mask;     /**< Rising edge */
            instance->P_EDGE_CTRL &= ~BIT(pin); /**< Rising edge power-up interrupt */
            break;

        case GPIO_BOTH:
            instance->IBE = mask;               /**< Both edges */
            break;
    }

    instance->IS     &= ~mask;                  /**< Edge triggered (as opposed to level-triggered) */
    instance->IC     |=  mask;                  /**< Clear any preexisting interrupt state */
    instance->PI_IEN |= BIT(pin);               /**< Enable power-up interrupts for this pin */

    /* Set interrupt priority for the whole GPIO port: */
    irq_num = GPIO_PORT_A_IRQn + GPIO_NUM_TO_PORT_NUM(pin);
    NVIC_SetPriority(irq_num, GPIO_IRQ_PRIO);

    /* Enable interrupts for the whole GPIO port: */
    NVIC_EnableIRQ(irq_num);

    /* Enable interrupts for the specific pin: */
    instance->IE |= mask;

    return 0;
}
Exemplo n.º 9
0
/*---------------------------------------------------------------------------*/
static void
at_cmd_gpio_callback(struct at_cmd *cmd, uint8_t len, char *data)
{
  /* Format: AT&GPIO=PN,s where P(ort)N(number), s(tate)=1/0 */
  uint8_t port;
  uint8_t state = strncmp(&data[11], "1", 1) ? 0 : 1;
  uint8_t pin = atoi(&data[9]);

  if(strncmp(&data[10], ",", 1) != 0) {
    AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
    return;
  }

  if((pin < 0) || (pin > 7)) {
    AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
    return;
  }

  if((state < 0) || (state > 1)) {
    AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
    return;
  }

  if(strncmp(&data[8], "A", 1) == 0) {
    port = GPIO_A_NUM;
  } else if(strncmp(&data[8], "B", 1) == 0) {
    port = GPIO_B_NUM;
  } else if(strncmp(&data[8], "C", 1) == 0) {
    port = GPIO_C_NUM;
  } else if(strncmp(&data[8], "D", 1) == 0) {
    port = GPIO_D_NUM;
  } else {
    AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
    return;
  }

  config_gpio(port, pin, HWTEST_GPIO_OUTPUT);

  if(state) {
    GPIO_SET_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  } else {
    GPIO_CLR_PIN(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
  }

  AT_RESPONSE(AT_DEFAULT_RESPONSE_OK);
}
Exemplo n.º 10
0
Arquivo: PL061Gpio.c Projeto: pmj/edk2
/**

Routine Description:

  Sets the state of a GPIO pin

Arguments:

  This  - pointer to protocol
  Gpio  - which pin to modify
  Mode  - mode to set

Returns:

  EFI_SUCCESS           - GPIO set as requested
  EFI_UNSUPPORTED       - Mode is not supported
  EFI_INVALID_PARAMETER - Gpio pin is out of range
**/
EFI_STATUS
EFIAPI
Set (
  IN  EMBEDDED_GPIO       *This,
  IN  EMBEDDED_GPIO_PIN   Gpio,
  IN  EMBEDDED_GPIO_MODE  Mode
  )
{
  EFI_STATUS    Status = EFI_SUCCESS;
  UINTN         Index, Offset, RegisterBase;

  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  ASSERT_EFI_ERROR (Status);

  switch (Mode)
  {
    case GPIO_MODE_INPUT:
      // Set the corresponding direction bit to LOW for input
      MmioAnd8 (RegisterBase + PL061_GPIO_DIR_REG,
                ~GPIO_PIN_MASK(Offset) & 0xFF);
      break;

    case GPIO_MODE_OUTPUT_0:
      // Set the corresponding direction bit to HIGH for output
      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));
      // Set the corresponding data bit to LOW for 0
      PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0);
      break;

    case GPIO_MODE_OUTPUT_1:
      // Set the corresponding direction bit to HIGH for output
      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));
      // Set the corresponding data bit to HIGH for 1
      PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0xff);
      break;

    default:
      // Other modes are not supported
      return EFI_UNSUPPORTED;
  }

  return EFI_SUCCESS;
}
Exemplo n.º 11
0
void cb(uint8_t port, uint8_t pin){

	GPIO_CLEAR_INTERRUPT(GPIO_PORT_TO_BASE(port), GPIO_PIN_MASK(pin));
	if(port==2 && pin==0){
		start_time = vtimer_arch_now();
	}
	else{
		printf("time = %lu\n", vtimer_arch_now()-start_time);
	}
}
Exemplo n.º 12
0
//Use C0 to receive interrupt
void configGPIOInterrupt(){
	GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_SET_INPUT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_DETECT_EDGE(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_DETECT_RISING(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_ENABLE_INTERRUPT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));

	GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(2));
	GPIO_SET_INPUT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(2));
	GPIO_DETECT_EDGE(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(2));
	GPIO_DETECT_FALLING(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(2));
	GPIO_ENABLE_INTERRUPT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(2));

	ioc_set_over(GPIO_C_NUM,0, IOC_OVERRIDE_PUE);
	ioc_set_over(GPIO_C_NUM,2, IOC_OVERRIDE_PUE);
	nvic_interrupt_enable(NVIC_INT_GPIO_PORT_C);
	gpio_register_callback(cb,GPIO_C_NUM,0);
	gpio_register_callback(cb,GPIO_C_NUM,2);
}
Exemplo n.º 13
0
void gpio_set(gpio_t dev)
{
    int pin;

    if (!gpio_enabled(dev)) {
        return;
    }

    pin = pin_lut[dev];
    GPIO_NUM_TO_DEV(pin)->DATA |= GPIO_PIN_MASK(GPIO_BIT_NUM(pin));
}
Exemplo n.º 14
0
/*---------------------------------------------------------------------------*/
void
i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl,
         uint32_t bus_speed)
{
  /* Enable I2C clock in different modes */
  REG(SYS_CTRL_RCGCI2C) |= 1; /* Run mode */

  /* Reset I2C peripheral */
  REG(SYS_CTRL_SRI2C) |= 1; /* Reset position */

  /* Delay for a little bit */
  clock_delay_usec(50);

  REG(SYS_CTRL_SRI2C) &= ~1;  /* Normal position */

  /* Set pins in input */
  GPIO_SET_INPUT(GPIO_PORT_TO_BASE(port_sda), GPIO_PIN_MASK(pin_sda));
  GPIO_SET_INPUT(GPIO_PORT_TO_BASE(port_scl), GPIO_PIN_MASK(pin_scl));

  /* Set peripheral control for the pins */
  GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(port_sda), GPIO_PIN_MASK(pin_sda));
  GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(port_scl), GPIO_PIN_MASK(pin_scl));

  /* Set the pad to no drive type */
  ioc_set_over(port_sda, pin_sda, IOC_OVERRIDE_DIS);
  ioc_set_over(port_scl, pin_scl, IOC_OVERRIDE_DIS);

  /* Set pins as peripheral inputs */
  REG(IOC_I2CMSSDA) = ioc_input_sel(port_sda, pin_sda);
  REG(IOC_I2CMSSCL) = ioc_input_sel(port_scl, pin_scl);

  /* Set pins as peripheral outputs */
  ioc_set_sel(port_sda, pin_sda, IOC_PXX_SEL_I2C_CMSSDA);
  ioc_set_sel(port_scl, pin_scl, IOC_PXX_SEL_I2C_CMSSCL);

  /* Enable the I2C master module */
  i2c_master_enable();

  /* t the master clock frequency */
  i2c_set_frequency(bus_speed);
}
Exemplo n.º 15
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  uint8_t pin_mask = GPIO_PIN_MASK(value);

  if((type != ANALOG_GROVE_LIGHT) && (type != ANALOG_PHIDGET_ROTATION_1109) &&
     (type != ANALOG_GROVE_LOUDNESS)) {
    PRINTF("ADC sensors: sensor not supported, check adc_wrapper.h header\n");
    return ADC_WRAPPER_ERROR;
  }

  if(sensors.sensors_num >= ADC_SENSORS_MAX) {
    PRINTF("ADC sensors: all adc channels available have been assigned\n");
    return ADC_WRAPPER_ERROR;
  }

  if((value < 0x01) || (value > 0x07) || (value == BUTTON_USER_PIN)) {
    PRINTF("ADC sensors: invalid pin value, (PA0-PA1, PA3) are reserved\n");
    return ADC_WRAPPER_ERROR;
  }

  if(sensors.sensors_ports & pin_mask) {
    PRINTF("ADC sensors: a sensor has been already assigned to this pin\n");
    return ADC_WRAPPER_ERROR;
  }

  switch(type) {
  /* V+3.3 sensors */
  case ANALOG_GROVE_LIGHT:
  case ANALOG_GROVE_LOUDNESS:
  case ANALOG_PHIDGET_ROTATION_1109:
    if(adc_zoul.configure(SENSORS_HW_INIT, pin_mask) == ZOUL_SENSORS_ERROR) {
      return ADC_WRAPPER_ERROR;
    }
    sensors.sensor[sensors.sensors_num].type = type;
    sensors.sensor[sensors.sensors_num].pin_mask = pin_mask;
    sensors.sensor[sensors.sensors_num].vdd3 = 1;
    break;

  default:
    return ADC_WRAPPER_ERROR;
  }

  PRINTF("ADC sensors: type %u mask 0x%02X vdd3 %u\n",
         sensors.sensor[sensors.sensors_num].type,
         sensors.sensor[sensors.sensors_num].pin_mask,
         sensors.sensor[sensors.sensors_num].vdd3);

  sensors.sensors_num++;
  sensors.sensors_ports |= pin_mask;

  return ADC_WRAPPER_SUCCESS;
}
Exemplo n.º 16
0
/*---------------------------------------------------------------------------*/
static void
at_cmd_read_callback(struct at_cmd *cmd, uint8_t len, char *data)
{
  /* Format: AT&READ=PN where P(ort)N(number), N can be "*" to read all */
  uint8_t port, pin;
  char read_result[5];

  if(strncmp(&data[9], "*", 1) == 0) {
    pin = 0xFF;
  } else {
    pin = atoi(&data[9]);
  }

  if((pin < 0) || (pin > 7)) {
    if(pin != 0xFF) {
      AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
      return;
    }
  }

  if(pin < 8) {
    pin = GPIO_PIN_MASK(pin);
  }

  /* Exclude PA0-PA3  */
  if(strncmp(&data[8], "A", 1) == 0) {
    port = GPIO_A_NUM;
    if(pin < 0x1F) {
      AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
      return;
    } else {
      if(pin == 0xFF) {
        pin = 0xF0;
      }
    }
  } else if(strncmp(&data[8], "B", 1) == 0) {
    port = GPIO_B_NUM;
  } else if(strncmp(&data[8], "C", 1) == 0) {
    port = GPIO_C_NUM;
  } else if(strncmp(&data[8], "D", 1) == 0) {
    port = GPIO_D_NUM;
  } else {
    AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
    return;
  }

  config_gpio(port, pin, HWTEST_GPIO_INPUT);
  snprintf(read_result, 5, "0x%02X",
           (uint16_t)GPIO_READ_PIN(GPIO_PORT_TO_BASE(port), pin));
  AT_RESPONSE(read_result);
  AT_RESPONSE(AT_DEFAULT_RESPONSE_OK);
}
Exemplo n.º 17
0
/**

Routine Description:

  Gets the mode (function) of a GPIO pin

Arguments:

  This  - pointer to protocol
  Gpio  - which pin
  Mode  - pointer to output mode value

Returns:

  EFI_SUCCESS           - mode value retrieved
  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range

**/
EFI_STATUS
EFIAPI
GetMode (
  IN  EMBEDDED_GPIO       *This,
  IN  EMBEDDED_GPIO_PIN   Gpio,
  OUT EMBEDDED_GPIO_MODE  *Mode
  )
{
  EFI_STATUS    Status;
  UINTN         Index, Offset, RegisterBase;

  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  if (EFI_ERROR (Status))
    return Status;

  // Initialize the hardware if not already done
  if (!mPL061Initialized) {
    Status = PL061Initialize();
    if (EFI_ERROR(Status)) {
      return Status;
    }
  }

  // Check if it is input or output
  if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK(Offset)) {
    // Pin set to output
    if (MmioRead8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2))) {
      *Mode = GPIO_MODE_OUTPUT_1;
    } else {
      *Mode = GPIO_MODE_OUTPUT_0;
    }
  } else {
    // Pin set to input
    *Mode = GPIO_MODE_INPUT;
  }

  return EFI_SUCCESS;
}
Exemplo n.º 18
0
//Config PA1 as an PWM output pin
void initPWM()
{
    //Timer is 16Mhz
    /* Enable module clock for the GPTx in Active mode, GPT0 clock enable, CPU running */
    REG(SYS_CTRL_RCGCGPT) |= SYS_CTRL_RCGCGPT_GPT0;

    disable_gptimer();

    /* Use 16-bit timer */
    REG(GPT_CONF_BASE + GPTIMER_CFG) = 0x04;

    /* Configure PWM mode, 0x00000008 Timer A alternate mode. */
    REG(GPT_CONF_BASE + GPTIMER_TAMR) = 0;
    REG(GPT_CONF_BASE + GPTIMER_TAMR) |= GPTIMER_TAMR_TAAMS;

    /* To enable PWM mode, the TACM bit must be cleared and the lowest 2 bits
       (TAMR) field must be configured to 0x2.
       GPTIMER_TnMR bit values, GPTIMER_TAMR_TAMR_PERIODIC is 0x00000002 */
    REG(GPT_CONF_BASE + GPTIMER_TAMR) |= GPTIMER_TAMR_TAMR_PERIODIC;

    //how often the counter is incremented:  every  pre-scaler / clock 16000000 seconds
    REG(GPT_CONF_BASE + GPTIMER_TAPR) = 0; 	        //PRESCALER_VALUE

    /* Set the start value (period), count down */
    REG(GPT_CONF_BASE+ GPTIMER_TAILR) = 16000;	    //frequency: 1kHz. 16000: 3E80, 16000000:F42400

    /* Set the deassert period */
    REG(GPT_CONF_BASE + GPTIMER_TAMATCHR) = 12800;  //duty cycle: 20% so vibrator time is 20%. 800: 0x1F40, 8000000: 7A1200

    // Defined in contiki/cpu/cc2538/dev/ioc.h
    /* Function select for Port:Pin.
       The third param sel can be any of the IOC_PXX_SEL_xyz defines.
       For example, IOC_PXX_SEL_UART0_TXD will set the port to act as UART0 TX.
       Selects one of the 32 pins on the four 8-pin I/O-ports (port A, port B, port C, and port D) to be the GPT0OCP1.
       Configure pin : PA:1 selected as GPT0OCP1*/
    ioc_set_sel(PWM_GPIO_CONF_PORT, PWM_GPIO_CONF_PIN, IOC_CONF_SEL);

    /* Set Port:Pin override function, IOC_OVERRIDE_OE: Output */
    ioc_set_over(PWM_GPIO_CONF_PORT, PWM_GPIO_CONF_PIN, IOC_OVERRIDE_OE);

    /* Configure the pin to be under peripheral control with PIN_MASK of port with PORT_BASE.*/
    GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(PWM_GPIO_CONF_PORT), GPIO_PIN_MASK(PWM_GPIO_CONF_PIN));

    enable_gptimer();
}
Exemplo n.º 19
0
Arquivo: rv3049.c Projeto: lab11/atum
void
rv3049_init()
{
  /* Set the HOLD_N and WP_N pins to outputs and high */
  GPIO_SET_INPUT(GPIO_PORT_TO_BASE(RV3049_INT_N_PORT_NUM),
                 GPIO_PIN_MASK(RV3049_INT_N_PIN));

  spix_cs_init(RV3049_CS_PORT_NUM, RV3049_CS_PIN);
  SPI_CS_CLR(RV3049_CS_PORT_NUM, RV3049_CS_PIN);

  // Write the initial values
  {
    rv3049_time_t start_time = {RTC_SECONDS, RTC_MINUTES, RTC_HOURS,
                                RTC_DAYS,    RTC_WEEKDAY, RTC_MONTH,
                                RTC_YEAR};
    rv3049_set_time(&start_time);
  }
}
Exemplo n.º 20
0
/**

Routine Description:

  Gets the state of a GPIO pin

Arguments:

  This  - pointer to protocol
  Gpio  - which pin to read
  Value - state of the pin

Returns:

  EFI_SUCCESS           - GPIO state returned in Value
  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
**/
EFI_STATUS
EFIAPI
Get (
  IN  EMBEDDED_GPIO     *This,
  IN  EMBEDDED_GPIO_PIN Gpio,
  OUT UINTN             *Value
  )
{
  EFI_STATUS    Status = EFI_SUCCESS;
  UINTN         Index, Offset, RegisterBase;

  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  if (EFI_ERROR (Status))
    goto EXIT;

  if (Value == NULL) {
    Status = EFI_INVALID_PARAMETER;
    goto EXIT;
  }

  // Initialize the hardware if not already done
  if (!mPL061Initialized) {
    Status = PL061Initialize();
    if (EFI_ERROR(Status)) {
      goto EXIT;
    }
  }

  if (MmioRead8 (RegisterBase + PL061_GPIO_DATA_REG + (GPIO_PIN_MASK(Offset) << 2))) {
    *Value = 1;
  } else {
    *Value = 0;
  }

  EXIT:
  return Status;
}
Exemplo n.º 21
0
/**
 * \brief Initialize the fm25lb.
 */
void
fm25lb_init()
{
  /* Set the HOLD_N and WP_N pins to outputs and high */
  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(FM25LB_HOLD_N_PORT_NUM),
                  GPIO_PIN_MASK(FM25LB_HOLD_N_PIN));
  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(FM25LB_WP_N_PORT_NUM),
                  GPIO_PIN_MASK(FM25LB_WP_N_PIN));
  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(FM25LB_HOLD_N_PORT_NUM),
                        GPIO_PIN_MASK(FM25LB_HOLD_N_PIN));
  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(FM25LB_WP_N_PORT_NUM),
                        GPIO_PIN_MASK(FM25LB_WP_N_PIN));
  GPIO_SET_PIN(GPIO_PORT_TO_BASE(FM25LB_HOLD_N_PORT_NUM),
               GPIO_PIN_MASK(FM25LB_HOLD_N_PIN));
  GPIO_SET_PIN(GPIO_PORT_TO_BASE(FM25LB_WP_N_PORT_NUM),
               GPIO_PIN_MASK(FM25LB_WP_N_PIN));

  spi_cs_init(FM25LB_CS_N_PORT_NUM, FM25LB_CS_N_PIN);
}
Exemplo n.º 22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(gpiot_process, ev, data) {
	PROCESS_BEGIN();
	etimer_set(&periodic_timer_gpio, CLOCK_SECOND/10);
	GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_SET_INPUT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));//input: pin: C0
	GPIO_DETECT_EDGE(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_TRIGGER_SINGLE_EDGE(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_DETECT_RISING(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	GPIO_ENABLE_INTERRUPT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(0));
	ioc_set_over(GPIO_C_NUM, 0, IOC_OVERRIDE_PUE);
	nvic_interrupt_enable(NVIC_INT_GPIO_PORT_C);
	gpio_register_callback(gp_int,GPIO_C_NUM, 0);
	while(1) {
		PROCESS_YIELD();
		leds_toggle(LEDS_RED);
		etimer_restart(&periodic_timer_gpio);
	}
	PROCESS_END();
}
Exemplo n.º 23
0
Arquivo: fm25v02.c Projeto: lab11/G2
/**
 * \brief Initialize the FM25V02.
 */
void
fm25v02_init()
{
  #if defined(VERSION9) || defined(VERSION10) || defined(VERSION11)
  /* Set the HOLD_N and WP_N pins to outputs and high */
  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(FM25V02_HOLD_N_PORT_NUM),
                  GPIO_PIN_MASK(FM25V02_HOLD_N_PIN));
  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(FM25V02_WP_N_PORT_NUM),
                  GPIO_PIN_MASK(FM25V02_WP_N_PIN));
  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(FM25V02_HOLD_N_PORT_NUM),
                        GPIO_PIN_MASK(FM25V02_HOLD_N_PIN));
  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(FM25V02_WP_N_PORT_NUM),
                        GPIO_PIN_MASK(FM25V02_WP_N_PIN));
  GPIO_SET_PIN(GPIO_PORT_TO_BASE(FM25V02_HOLD_N_PORT_NUM),
               GPIO_PIN_MASK(FM25V02_HOLD_N_PIN));
  GPIO_SET_PIN(GPIO_PORT_TO_BASE(FM25V02_WP_N_PORT_NUM),
               GPIO_PIN_MASK(FM25V02_WP_N_PIN));
  #endif

  spi_cs_init(FM25V02_CS_N_PORT_NUM, FM25V02_CS_N_PIN);
  SPI_CS_SET(FM25V02_CS_N_PORT_NUM, FM25V02_CS_N_PIN);
}
Exemplo n.º 24
0
/*---------------------------------------------------------------------------*/
void
uart_init(uint8_t uart)
{
  const uart_regs_t *regs;

  if(uart >= UART_INSTANCE_COUNT) {
    return;
  }
  regs = &uart_regs[uart];
  if(regs->rx.port < 0 || regs->tx.port < 0) {
    return;
  }

  lpm_register_peripheral(permit_pm1);

  /* Enable clock for the UART while Running, in Sleep and Deep Sleep */
  REG(SYS_CTRL_RCGCUART) |= regs->sys_ctrl_rcgcuart_uart;
  REG(SYS_CTRL_SCGCUART) |= regs->sys_ctrl_scgcuart_uart;
  REG(SYS_CTRL_DCGCUART) |= regs->sys_ctrl_dcgcuart_uart;

  /* Run on SYS_DIV */
  REG(regs->base | UART_CC) = 0;

  /*
   * Select the UARTx RX pin by writing to the IOC_UARTRXD_UARTn register
   *
   * The value to be written will be on of the IOC_INPUT_SEL_Pxn defines from
   * ioc.h. The value can also be calculated as:
   *
   * (port << 3) + pin
   */
  REG(regs->ioc_uartrxd_uart) = (regs->rx.port << 3) + regs->rx.pin;

  /*
   * Pad Control for the TX pin:
   * - Set function to UARTn TX
   * - Output Enable
   */
  ioc_set_sel(regs->tx.port, regs->tx.pin, regs->ioc_pxx_sel_uart_txd);
  ioc_set_over(regs->tx.port, regs->tx.pin, IOC_OVERRIDE_OE);

  /* Set RX and TX pins to peripheral mode */
  GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(regs->tx.port),
                          GPIO_PIN_MASK(regs->tx.pin));
  GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(regs->rx.port),
                          GPIO_PIN_MASK(regs->rx.pin));

  /*
   * UART Interrupt Masks:
   * Acknowledge RX and RX Timeout
   * Acknowledge Framing, Overrun and Break Errors
   */
  REG(regs->base | UART_IM) = UART_IM_RXIM | UART_IM_RTIM;
  REG(regs->base | UART_IM) |= UART_IM_OEIM | UART_IM_BEIM | UART_IM_FEIM;

  REG(regs->base | UART_IFLS) =
    UART_IFLS_RXIFLSEL_1_8 | UART_IFLS_TXIFLSEL_1_2;

  /* Make sure the UART is disabled before trying to configure it */
  REG(regs->base | UART_CTL) = UART_CTL_VALUE;

  /* Baud Rate Generation */
  REG(regs->base | UART_IBRD) = regs->ibrd;
  REG(regs->base | UART_FBRD) = regs->fbrd;

  /* UART Control: 8N1 with FIFOs */
  REG(regs->base | UART_LCRH) = UART_LCRH_WLEN_8 | UART_LCRH_FEN;

  /*
   * Enable hardware flow control (RTS/CTS) if requested.
   * Note that hardware flow control is available only on UART1.
   */
  if(regs->cts.port >= 0) {
    REG(IOC_UARTCTS_UART1) = ioc_input_sel(regs->cts.port, regs->cts.pin);
    GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(regs->cts.port), GPIO_PIN_MASK(regs->cts.pin));
    ioc_set_over(regs->cts.port, regs->cts.pin, IOC_OVERRIDE_DIS);
    REG(UART_1_BASE | UART_CTL) |= UART_CTL_CTSEN;
  }

  if(regs->rts.port >= 0) {
    ioc_set_sel(regs->rts.port, regs->rts.pin, IOC_PXX_SEL_UART1_RTS);
    GPIO_PERIPHERAL_CONTROL(GPIO_PORT_TO_BASE(regs->rts.port), GPIO_PIN_MASK(regs->rts.pin));
    ioc_set_over(regs->rts.port, regs->rts.pin, IOC_OVERRIDE_OE);
    REG(UART_1_BASE | UART_CTL) |= UART_CTL_RTSEN;
  }

  /* UART Enable */
  REG(regs->base | UART_CTL) |= UART_CTL_UARTEN;

  /* Enable UART0 Interrupts */
  nvic_interrupt_enable(regs->nvic_int);
}
Exemplo n.º 25
0
static void
recv_handler(void)
{
    char* str;
    int z;
    int tag1=0;
    int tag2=0;
    int tag3=0;
    int tag4=0;
    int tag5=0;
//int tag5=0;
    str = uip_appdata;
    //printf("string is: '%s':",str);
    if (BLE==0)
    {
        set_bluetooth();
        initPWM();
        BLE=1;
    }

// For Beacon 1
    for (z=0; z<=2; z++)
    {
        if (str[z]==data1[z])
        {
            tag1=1;
        }
        else
        {
            tag1=0;

            break;
        }
    }

// For Beacon 2
    for (z=0; z<=2; z++)
    {
        if (str[z]==data2[z])
        {
            tag2=1;
        }
        else
        {
            tag2=0;

            break;
        }
    }


// For Beacon 3
    for (z=0; z<=2; z++)
    {
        if (str[z]==data3[z])
        {
            tag3=1;
        }
        else
        {
            tag3=0;

            break;
        }
    }


//For Beacon 4
    for (z=0; z<=2; z++)
    {
        if (str[z]==data4[z])
        {
            tag4=1;
        }
        else
        {
            tag4=0;

            break;
        }

    }

    for (z=0; z<=2; z++)
    {
        if (str[z]==data5[z])
        {
            tag5=1;
        }
        else
        {
            tag5=0;

            break;
        }
    }

    if (tag5==1)
    {
        cycle=1;
        if (vat1==0)
        {
            GPIO_SET_OUTPUT(GPIO_C_BASE, GPIO_PIN_MASK(1));
            GPIO_SET_PIN(GPIO_C_BASE, GPIO_PIN_MASK(1));
            vat1=1;
        }
        else if (vat1==1)
        {

            GPIO_CLR_PIN(GPIO_C_BASE, GPIO_PIN_MASK(1));
            vat1=0;
        }
    }
    else if (tag1==1)
    {
        IMU.RSS1=packetbuf_attr(PACKETBUF_ATTR_RSSI);

        //TODO:  when approaching beacon1, start vibrate.
        if(IMU.RSS1 <= 100)
        {
            if(get_gptimer_state() == GPTIMER_OFF) {}
            //enable_gptimer();
        }
        else
        {
            if(get_gptimer_state() == GPTIMER_ON) {}
            //disable_gptimer();
        }
    }
    else if (tag2==1)
    {
        IMU.RSS2=packetbuf_attr(PACKETBUF_ATTR_RSSI);

    }
    else if (tag3==1)
    {
        IMU.RSS3=packetbuf_attr(PACKETBUF_ATTR_RSSI);

    }
    else if (tag4==1)
    {
        IMU.RSS4=packetbuf_attr(PACKETBUF_ATTR_RSSI);
    }
}
Exemplo n.º 26
0
void set_bluetooth()
{
    GPIO_SET_OUTPUT(GPIO_D_BASE, GPIO_PIN_MASK(3));
    GPIO_SET_PIN(GPIO_D_BASE, GPIO_PIN_MASK(3));
//Make sure the Reset is off on bluetooth

//GPIO_SET_OUTPUT(GPIO_B_BASE, GPIO_PIN_MASK(0));
//GPIO_SET_PIN(GPIO_B_BASE, GPIO_PIN_MASK(0));
    /*
    uart_write_byte(0,'P');
    uart_write_byte(0,'O');
    uart_write_byte(0,'W');
    uart_write_byte(0,'E');
    uart_write_byte(0,'R');
    uart_write_byte(0,' ');
    uart_write_byte(0,'O');
    uart_write_byte(0,'N');
    uart_write_byte(0,'\r');
    */
    uart_write_byte(0,'R');
    uart_write_byte(0,'E');
    uart_write_byte(0,'S');
    uart_write_byte(0,'T');
    uart_write_byte(0,'O');
    uart_write_byte(0,'R');
    uart_write_byte(0,'E');
    uart_write_byte(0,'\r');
    Delay_ms(1000);

    uart_write_byte(0,'R');
    uart_write_byte(0,'E');
    uart_write_byte(0,'S');
    uart_write_byte(0,'E');
    uart_write_byte(0,'T');
    uart_write_byte(0,'\r');
    Delay_ms(400);

//TODO: 'SET BAUD=115200\r'
    uart_write_byte(0,'S');
    uart_write_byte(0,'E');
    uart_write_byte(0,'T');
    uart_write_byte(0,' ');
    uart_write_byte(0,'B');
    uart_write_byte(0,'A');
    uart_write_byte(0,'U');
    uart_write_byte(0,'D');
    uart_write_byte(0,'=');
    uart_write_byte(0,'1');
    uart_write_byte(0,'1');
    uart_write_byte(0,'5');
    uart_write_byte(0,'2');
    uart_write_byte(0,'0');
    uart_write_byte(0,'0');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'w');
    uart_write_byte(0,'r');
    uart_write_byte(0,'i');
    uart_write_byte(0,'t');
    uart_write_byte(0,'e');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'R');
    uart_write_byte(0,'E');
    uart_write_byte(0,'S');
    uart_write_byte(0,'E');
    uart_write_byte(0,'T');
    uart_write_byte(0,'\r');
    Delay_ms(400);

//TODO: change UART to 115200 after we set Bluetooth to 115200
    set_uart_baud_rate(UART_CONF_BASE);

    uart_write_byte(0,'D');
    uart_write_byte(0,'I');
    uart_write_byte(0,'S');
    uart_write_byte(0,'C');
    uart_write_byte(0,'O');
    uart_write_byte(0,'V');
    uart_write_byte(0,'E');
    uart_write_byte(0,'R');
    uart_write_byte(0,'A');
    uart_write_byte(0,'B');
    uart_write_byte(0,'L');
    uart_write_byte(0,'E');
    uart_write_byte(0,' ');
    uart_write_byte(0,'O');
    uart_write_byte(0,'N');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'A');
    uart_write_byte(0,'U');
    uart_write_byte(0,'T');
    uart_write_byte(0,'O');
    uart_write_byte(0,'C');
    uart_write_byte(0,'O');
    uart_write_byte(0,'N');
    uart_write_byte(0,'N');
    uart_write_byte(0,'=');
    uart_write_byte(0,'0');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'S');
    uart_write_byte(0,'E');
    uart_write_byte(0,'T');
    uart_write_byte(0,' ');
    uart_write_byte(0,'D');
    uart_write_byte(0,'E');
    uart_write_byte(0,'E');
    uart_write_byte(0,'P');
    uart_write_byte(0,'_');
    uart_write_byte(0,'S');
    uart_write_byte(0,'L');
    uart_write_byte(0,'E');
    uart_write_byte(0,'E');
    uart_write_byte(0,'P');
    uart_write_byte(0,'=');
    uart_write_byte(0,'O');
    uart_write_byte(0,'F');
    uart_write_byte(0,'F');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'M');
    uart_write_byte(0,'A');
    uart_write_byte(0,'X');
    uart_write_byte(0,'_');
    uart_write_byte(0,'R');
    uart_write_byte(0,'E');
    uart_write_byte(0,'C');
    uart_write_byte(0,'=');
    uart_write_byte(0,'0');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'S');
    uart_write_byte(0,'E');
    uart_write_byte(0,'T');
    uart_write_byte(0,' ');
    uart_write_byte(0,'D');
    uart_write_byte(0,'I');
    uart_write_byte(0,'S');
    uart_write_byte(0,'C');
    uart_write_byte(0,'O');
    uart_write_byte(0,'V');
    uart_write_byte(0,'E');
    uart_write_byte(0,'R');
    uart_write_byte(0,'A');
    uart_write_byte(0,'B');
    uart_write_byte(0,'L');
    uart_write_byte(0,'E');
    uart_write_byte(0,'=');
    uart_write_byte(0,'2');
    uart_write_byte(0,' ');
    uart_write_byte(0,'0');
    uart_write_byte(0,'\r');
    Delay_ms(400);


    uart_write_byte(0,'w');
    uart_write_byte(0,'r');
    uart_write_byte(0,'i');
    uart_write_byte(0,'t');
    uart_write_byte(0,'e');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'R');
    uart_write_byte(0,'E');
    uart_write_byte(0,'S');
    uart_write_byte(0,'E');
    uart_write_byte(0,'T');
    uart_write_byte(0,'\r');
    Delay_ms(400);

    uart_write_byte(0,'E');
    uart_write_byte(0,'N');
    uart_write_byte(0,'T');
    uart_write_byte(0,'E');
    uart_write_byte(0,'R');
    uart_write_byte(0,'_');
    uart_write_byte(0,'D');
    uart_write_byte(0,'A');
    uart_write_byte(0,'T');
    uart_write_byte(0,'A');
    uart_write_byte(0,'\r');
    Delay_ms(400);
}
Exemplo n.º 27
0
PROCESS_THREAD(MPU_DATA, ev, data)
{
    static struct etimer sdtimer;

    PROCESS_BEGIN();

    if(isInitialized==0)
    {
// Turn off 3.3-V domain (lcd/sdcard power, output low)
//GPIOPinTypeGPIOOutput(BSP_3V3_EN_BASE, BSP_3V3_EN);
//GPIOPinWrite(BSP_3V3_EN_BASE, BSP_3V3_EN, 0);
        GPIO_SET_OUTPUT(BSP_3V3_EN_BASE, BSP_3V3_EN);
        GPIO_CLR_PIN(BSP_3V3_EN_BASE, BSP_3V3_EN);

// If 3.3-V domain is initially off, make sure it's off >1 ms for a complete
// sd card power cycle

// Approx 10 ms delay
        Delay_ms(10);

// Enable 3.3-V domain (it takes <= 600 us to stabilize)
//GPIOPinWrite(BSP_3V3_EN_BASE, BSP_3V3_EN, BSP_3V3_EN);  // high
        GPIO_SET_PIN(BSP_3V3_EN_BASE, BSP_3V3_EN);
        Delay_ms(100);//100ms

//Disable LCD
//GPIOPinTypeGPIOOutput(GPIO_B_BASE, (5));
//GPIOPinWrite(GPIO_B_BASE, (5), (5));
        GPIO_SET_OUTPUT(GPIO_B_BASE, GPIO_PIN_MASK(5));
        GPIO_SET_PIN(GPIO_B_BASE, GPIO_PIN_MASK(5));
        GPIO_SET_INPUT(GPIO_B_BASE, GPIO_PIN_MASK(3));
        GPIO_CLEAR_INTERRUPT(GPIO_B_BASE, 0xFF);
        GPIO_ENABLE_INTERRUPT(GPIO_B_BASE, 0X08);
        GPIO_DETECT_RISING(GPIO_B_BASE, 0X08);

//Turn on Bluetooth
//GPIO_SET_OUTPUT(GPIO_D_BASE, GPIO_PIN_MASK(3));
//GPIO_SET_PIN(GPIO_D_BASE, GPIO_PIN_MASK(3));
        uart_init(UART_CONF_BASE);

        GPIO_SET_OUTPUT(GPIO_B_BASE, GPIO_PIN_MASK(6));
        GPIO_CLR_PIN(GPIO_B_BASE, GPIO_PIN_MASK(6));

        clock_delay(6000);
        GPIO_SET_PIN(GPIO_B_BASE, GPIO_PIN_MASK(6));
        clock_delay(6000);
        init_i2c();
        clock_delay(6000);
        init_MPU9150 ();

        isInitialized = 1;
    }

    while(1)
    {
//  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&sdtimer));

//GPIO_SET_PIN(GPIO_C_BASE, lGPIO_PIN_MASK(2));
        etimer_set(&sdtimer, CLOCK_SECOND/400);    //TODO: change from 80 ---> 200

        PROCESS_YIELD();

//GPIO_SET_PIN(GPIO_C_BASE, GPIO_PIN_MASK(1));
#define GPIO_B_BASE             0x400DA000  // GPIO
#define GPIO_PIN_3              0x00000008  // GPIO pin 3

        uint32_t gpio = REG(GPIO_B_BASE + (0x00000000 + (GPIO_PIN_3 << 2))) & GPIO_PIN_3;
        if(gpio)
        {
            read_sensor_data(IMU.Payload);

            PKT_NUM ++;
            IMU_PACKET[0]=IMU.Payload[0];
            IMU_PACKET[1]=IMU.Payload[1];
            IMU_PACKET[2]=IMU.Payload[2];
            IMU_PACKET[3]=IMU.Payload[3];
            IMU_PACKET[4]=IMU.Payload[4];
            IMU_PACKET[5]=IMU.Payload[5];
            IMU_PACKET[6]=IMU.Payload[6];
            IMU_PACKET[7]=IMU.Payload[7];
            IMU_PACKET[8]=IMU.Payload[8];
            IMU_PACKET[9]=IMU.Payload[9];
            IMU_PACKET[10]=IMU.Payload[10];
            IMU_PACKET[11]=IMU.Payload[11];
            IMU_PACKET[12]=IMU.Payload[12];
            IMU_PACKET[13]=IMU.Payload[13];
            IMU_PACKET[14]=IMU.Payload[14];
            IMU_PACKET[15]=IMU.Payload[15];
            IMU_PACKET[16]=IMU.Payload[16];
            IMU_PACKET[17]=IMU.Payload[17];

            if (cycle==1)
            {

                IMU_PACKET[18]=IMU.RSS1;
                IMU_PACKET[19]=IMU.RSS2;
                IMU_PACKET[20]=IMU.RSS3;
                IMU_PACKET[21]=IMU.RSS4;

                if (vat==0)
                {
                    GPIO_SET_OUTPUT(GPIO_C_BASE, GPIO_PIN_MASK(0));
                    GPIO_SET_PIN(GPIO_C_BASE, GPIO_PIN_MASK(0));
                    vat=1;
                }

                else if (vat==1)
                {

                    GPIO_CLR_PIN(GPIO_C_BASE, GPIO_PIN_MASK(0));
                    vat=0;
                }
                cycle=0;
            }

            else if (cycle==0)
            {

                IMU_PACKET[18]=0;
                IMU_PACKET[19]=0;
                IMU_PACKET[20]=0;
                IMU_PACKET[21]=0;
            }

            // Add packet number, so we can detect packet loss.
            IMU_PACKET[22]=PKT_NUM & 0x00ff;
            IMU_PACKET[23]=PKT_NUM >> 8 & 0x00ff ;

            unsigned char outLen = 0;
            byteStuff (&IMU_PACKET[0], PKT_LEN, outPkt, &outLen);
            char i;
            for(i=0; i<outLen; i++)
            {
                uart_write_byte(0,outPkt[i]);
            }
        }

//push_data_to_buffer_imu();
        /*
        if ((stage_imu==1) &&(SD_BUSY==0))
        writedata_imu();
        */
    }
    PROCESS_END();
}
Exemplo n.º 28
0
void configGPIOOuput(){
	GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(1));
	GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(GPIO_C_NUM), GPIO_PIN_MASK(1));

}
Exemplo n.º 29
0
void set_up_single_driver_gpio(uint32_t gpio_port_num, uint32_t gpio_pin_num) {
    GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(gpio_port_num), GPIO_PIN_MASK(gpio_pin_num));
    GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(gpio_port_num), GPIO_PIN_MASK(gpio_pin_num));
    ioc_set_over(gpio_port_num, gpio_pin_num, IOC_OVERRIDE_OE);
}