Пример #1
0
/*---------------------------------------------------------------------------*/
void
cc1200_arch_init(void)
{
  /* First leave RESET high */
  GPIO_SOFTWARE_CONTROL(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
  GPIO_SET_OUTPUT(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);
  ioc_set_over(CC1200_RESET_PORT, CC1200_RESET_PIN, IOC_OVERRIDE_OE);
  GPIO_SET_PIN(CC1200_RESET_PORT_BASE, CC1200_RESET_PIN_MASK);

  /* Initialize CSn, enable CSn and then wait for MISO to go low*/
  spix_cs_init(CC1200_SPI_CSN_PORT, CC1200_SPI_CSN_PIN);

  /* Initialize SPI */
  spix_init(CC1200_SPI_INSTANCE);

  /* Configure GPIOx */
  GPIO_SOFTWARE_CONTROL(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK);
  GPIO_SET_INPUT(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK);
  GPIO_SOFTWARE_CONTROL(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  GPIO_SET_INPUT(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);

  /* Leave CSn as default */
  cc1200_arch_spi_deselect();

  /* Ensure MISO is high */
  BUSYWAIT_UNTIL(
    GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK),
    RTIMER_SECOND / 10);
}
Пример #2
0
/*---------------------------------------------------------------------------*/
void
felicia_spi_init(void)
{
  /* Initialize ring buffers for RX and TX data */
  ringbuf_init(&spi_rx_buf, rxbuf_data, sizeof(rxbuf_data));
  ringbuf_init(&spi_tx_buf, txbuf_data, sizeof(txbuf_data));

  /* Configre SSI interface and init TX FIFO */
  ssi_reconfigure(1);

  /* Set the mux correctly to connect the SSI pins to the correct GPIO pins */
  /* set input pin with ioc */
  REG(IOC_CLK_SSIIN_SSI0) = ioc_input_sel(SPI_CLK_PORT, SPI_CLK_PIN);
  REG(IOC_SSIFSSIN_SSI0) = ioc_input_sel(SPI_SEL_PORT, SPI_SEL_PIN);
  REG(IOC_SSIRXD_SSI0) = ioc_input_sel(SPI_MOSI_PORT, SPI_MOSI_PIN);
  /* set output pin */
  ioc_set_sel(SPI_MISO_PORT, SPI_MISO_PIN, IOC_PXX_SEL_SSI0_TXD);

  /* Set pins as input and MISo as output */
  GPIO_SET_INPUT(SPI_CLK_PORT_BASE, SPI_CLK_PIN_MASK);
  GPIO_SET_INPUT(SPI_MOSI_PORT_BASE, SPI_MOSI_PIN_MASK);
  GPIO_SET_INPUT(SPI_SEL_PORT_BASE, SPI_SEL_PIN_MASK); /* it seems that setting SEL as input is not necessary */
  GPIO_SET_OUTPUT(SPI_MISO_PORT_BASE, SPI_MISO_PIN_MASK);
  /* Put all the SSI gpios into peripheral mode */
  GPIO_PERIPHERAL_CONTROL(SPI_CLK_PORT_BASE, SPI_CLK_PIN_MASK);
  GPIO_PERIPHERAL_CONTROL(SPI_MOSI_PORT_BASE, SPI_MOSI_PIN_MASK);
  GPIO_PERIPHERAL_CONTROL(SPI_MISO_PORT_BASE, SPI_MISO_PIN_MASK);
  GPIO_PERIPHERAL_CONTROL(SPI_SEL_PORT_BASE, SPI_SEL_PIN_MASK); /* it seems that setting SEL: as peripheral controlled is not necessary */
  /* Disable any pull ups or the like */
  ioc_set_over(SPI_CLK_PORT, SPI_CLK_PIN, IOC_OVERRIDE_DIS);
  ioc_set_over(SPI_MOSI_PORT, SPI_MOSI_PIN, IOC_OVERRIDE_DIS);
  ioc_set_over(SPI_MISO_PORT, SPI_MISO_PIN, IOC_OVERRIDE_DIS);
  ioc_set_over(SPI_SEL_PORT, SPI_SEL_PIN, IOC_OVERRIDE_PDE); /* it seems that configuring pull-ups/downs on SEL is not necessary */

  /* Configure output INT pin (from Felicia to Host */
  GPIO_SET_OUTPUT(SPI_INT_PORT_BASE, SPI_INT_PIN_MASK);
  GPIO_CLR_PIN(SPI_INT_PORT_BASE, SPI_INT_PIN_MASK);

  /* Configure CS pin and detection for both edges on that pin */
  GPIO_SOFTWARE_CONTROL(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_SET_INPUT(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_DETECT_EDGE(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_TRIGGER_BOTH_EDGES(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  GPIO_ENABLE_INTERRUPT(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK);
  ioc_set_over(SPI_CS_PORT, SPI_CS_PIN, IOC_OVERRIDE_PUE);
  /* Enable interrupt form CS pin */
  nvic_interrupt_enable(NVIC_INT_GPIO_PORT_B);
  gpio_register_callback(cs_isr, SPI_CS_PORT, SPI_CS_PIN);
}
Пример #3
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  if(type != SENSORS_ACTIVE) {
    return DIMMER_ERROR;
  }

  if(value) {
    /* This is the Triac's gate pin */
    GPIO_SOFTWARE_CONTROL(DIMMER_GATE_PORT_BASE, DIMMER_GATE_PIN_MASK);
    GPIO_SET_OUTPUT(DIMMER_GATE_PORT_BASE, DIMMER_GATE_PIN_MASK);
    ioc_set_over(DIMMER_GATE_PORT, DIMMER_GATE_PIN, IOC_OVERRIDE_OE);
    GPIO_CLR_PIN(DIMMER_GATE_PORT_BASE, DIMMER_GATE_PIN_MASK);

    /* This is the zero-crossing pin and interrupt */
    GPIO_SOFTWARE_CONTROL(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
    GPIO_SET_INPUT(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);

    /* Pull-up resistor, detect rising edge */
    GPIO_DETECT_EDGE(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
    GPIO_DETECT_RISING(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
    gpio_register_callback(dimmer_zero_cross_int_handler, DIMMER_SYNC_PORT,
                           DIMMER_SYNC_PIN);

    /* Spin process until an interrupt is received */
    process_start(&ac_dimmer_int_process, NULL);

    /* Enable interrupts */
    GPIO_ENABLE_INTERRUPT(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
    // ioc_set_over(DIMMER_SYNC_PORT, DIMMER_SYNC_PIN, IOC_OVERRIDE_PUE);
    NVIC_EnableIRQ(DIMMER_INT_VECTOR);

    enabled = 1;
    dimming = DIMMER_DEFAULT_START_VALUE;
    return DIMMER_SUCCESS;
  }

  /* Disable interrupt and pins */
  
  GPIO_DISABLE_INTERRUPT(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
  GPIO_SET_INPUT(DIMMER_GATE_PORT_BASE, DIMMER_GATE_PIN_MASK);
  GPIO_SET_OUTPUT(DIMMER_SYNC_PORT_BASE, DIMMER_SYNC_PIN_MASK);
  process_exit(&ac_dimmer_int_process);

  enabled = 0;
  dimming = 0;
  return DIMMER_SUCCESS;
}
Пример #4
0
/**
 * \brief Init function for the left button.
 *
 * Parameters are ignored. They have been included because the prototype is
 * dictated by the core sensor api. The return value is also not required by
 * the API but otherwise ignored.
 *
 * \param type ignored
 * \param value ignored
 * \return ignored
 */
static int
config_ac_zero_detector(int type, int value)
{
//  config(BUTTON_LEFT_PORT_BASE, BUTTON_LEFT_PIN_MASK);
      /* Software controlled */
  GPIO_SOFTWARE_CONTROL(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);

  /* Se2t pin to input */
  GPIO_SET_INPUT(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);

  /* Enable edge detection */
  GPIO_DETECT_EDGE(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);

  /* Single edge */
  GPIO_TRIGGER_SINGLE_EDGE(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);

  /* Trigger interrupt on Falling edge */
  GPIO_DETECT_FALLING(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);
//We can't use RISING detect, becuse while symithtor is open detector will always return 1=like we have
//zero crossing, so we can use FALLING edge only.

//  GPIO_DETECT_RISING(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);

  GPIO_ENABLE_INTERRUPT(AC_ZERO_DETECTOR_PORT_BASE, AC_ZERO_DETECTOR_PIN_MASK);

  ioc_set_over(AC_ZERO_DETECTOR_PORT, AC_ZERO_DETECTOR_PIN, IOC_OVERRIDE_PUE);

  nvic_interrupt_enable(AC_ZERO_DETECTOR_VECTOR);
  gpio_register_callback(zero_cross_callback, AC_ZERO_DETECTOR_PORT, AC_ZERO_DETECTOR_PIN);
  return 1;
}
Пример #5
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
    if(type != MOTION_ACTIVE) {
        PRINTF("Motion: invalid configuration option\n");
        return MOTION_ERROR;
    }

    if(!value) {
        presence_int_callback = NULL;
        GPIO_DISABLE_INTERRUPT(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
        return MOTION_SUCCESS;
    }

    /* Configure interruption */
    GPIO_SOFTWARE_CONTROL(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
    GPIO_SET_INPUT(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
    GPIO_DETECT_RISING(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
    ioc_set_over(MOTION_SENSOR_PORT, MOTION_SENSOR_PIN, IOC_OVERRIDE_DIS);
    gpio_register_callback(motion_interrupt_handler, MOTION_SENSOR_PORT,
                           MOTION_SENSOR_PIN);

    process_start(&motion_int_process, NULL);

    GPIO_ENABLE_INTERRUPT(MOTION_SENSOR_PORT_BASE, MOTION_SENSOR_PIN_MASK);
    nvic_interrupt_enable(MOTION_SENSOR_VECTOR);
    return MOTION_SUCCESS;
}
Пример #6
0
/*---------------------------------------------------------------------------*/
int
mp3_wtv020sd_config(uint8_t mode)
{
  if(mode != MP3_WTV020SD_GPIO_MODE && mode != MP3_WTV020SD_LINE_MODE) {
    return MP3_WTV020SD_ERROR;
  }

  if(mode == MP3_WTV020SD_GPIO_MODE) {
    GPIO_SOFTWARE_CONTROL(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
    GPIO_SET_OUTPUT(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
    GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
    GPIO_SOFTWARE_CONTROL(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
    GPIO_SET_OUTPUT(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
    GPIO_SET_PIN(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
  } else {
    GPIO_SOFTWARE_CONTROL(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
    GPIO_SET_OUTPUT(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
    GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
    GPIO_SOFTWARE_CONTROL(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
    GPIO_SET_OUTPUT(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
    GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
    GPIO_SOFTWARE_CONTROL(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
    GPIO_SET_OUTPUT(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
    GPIO_SET_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
  }

  GPIO_SOFTWARE_CONTROL(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK);
  GPIO_SET_INPUT(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK);

  initialized = mode;
  return MP3_WTV020SD_SUCCESS;
}
Пример #7
0
/**
 * Initializes the TPS62730 voltage regulator
 * By default it is in bypass mode, Vout = Vin, Iq < 1 uA
 */
void
tps62730_init(void)
{
  GPIO_SET_OUTPUT(BSP_TPS62730_BASE, BSP_TPS62730_ON);
  GPIO_SET_INPUT(BSP_TPS62730_BASE, BSP_TPS62730_STATUS);

  tps62730_bypass();
}
Пример #8
0
/**
 * \brief Common initialiser for all buttons
 * \param port_base GPIO port's register offset
 * \param pin_mask Pin mask corresponding to the button's pin
 */
static void
config(uint32_t port_base, uint32_t pin_mask)
{
  GPIO_SOFTWARE_CONTROL(port_base, pin_mask);
  GPIO_SET_INPUT(port_base, pin_mask);
  GPIO_DETECT_EDGE(port_base, pin_mask);
  GPIO_TRIGGER_BOTH_EDGES(port_base, pin_mask);
  GPIO_ENABLE_INTERRUPT(port_base, pin_mask);
}
Пример #9
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);
}
Пример #10
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));
  }
}
Пример #11
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);
}
Пример #12
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  switch(type) {
  case SENSORS_HW_INIT:

    /* This should filter out disabled sensors as its value should be zero */
    if((value < ZOUL_SENSORS_ADC_MIN) || (value > ZOUL_SENSORS_ADC_ALL)) {
      PRINTF("ADC: invalid adc pin mask (0x%02X)\n", value);
      return ZOUL_SENSORS_ERROR;
    }

    GPIO_SOFTWARE_CONTROL(GPIO_A_BASE, value);
    GPIO_SET_INPUT(GPIO_A_BASE, value);

    if(value & ZOUL_SENSORS_ADC1) {
      ioc_set_over(GPIO_A_NUM, ADC_SENSORS_ADC1_PIN, IOC_OVERRIDE_ANA);
    }
    if(value & ZOUL_SENSORS_ADC2) {
      ioc_set_over(GPIO_A_NUM, ADC_SENSORS_ADC2_PIN, IOC_OVERRIDE_ANA);
    }
    if(value & ZOUL_SENSORS_ADC3) {
      ioc_set_over(GPIO_A_NUM, ADC_SENSORS_ADC3_PIN, IOC_OVERRIDE_ANA);
    }
    if(value & ZOUL_SENSORS_ADC4) {
      ioc_set_over(GPIO_A_NUM, ADC_SENSORS_ADC4_PIN, IOC_OVERRIDE_ANA);
    }
    if(value & ZOUL_SENSORS_ADC5) {
      ioc_set_over(GPIO_A_NUM, ADC_SENSORS_ADC5_PIN, IOC_OVERRIDE_ANA);
    }
    if(value & ZOUL_SENSORS_ADC6) {
      ioc_set_over(GPIO_A_NUM, ADC_SENSORS_ADC6_PIN, IOC_OVERRIDE_ANA);
    }
    adc_init();
    set_decimation_rate(SOC_ADC_ADCCON_DIV_512);
    enabled_channels |= value;
    PRINTF("ADC: enabled channels 0x%02X\n", enabled_channels);
    break;

  case ZOUL_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE:
    return set_decimation_rate((uint8_t)value);

  default:
    return ZOUL_SENSORS_ERROR;
  }
  return 0;
}
Пример #13
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  switch(type) {
  case SENSORS_HW_INIT:
    GPIO_SOFTWARE_CONTROL(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK);
    GPIO_SET_OUTPUT(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK);
    GPIO_CLR_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK);
    ioc_set_over(ADC_ALS_PWR_PORT, ADC_ALS_PWR_PIN, IOC_OVERRIDE_DIS);

    GPIO_SOFTWARE_CONTROL(GPIO_A_BASE, ADC_ALS_OUT_PIN_MASK);
    GPIO_SET_INPUT(GPIO_A_BASE, ADC_ALS_OUT_PIN_MASK);
    ioc_set_over(GPIO_A_NUM, ADC_ALS_OUT_PIN, IOC_OVERRIDE_ANA);

    break;
  }
  return 0;
}
Пример #14
0
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);
  }
}
Пример #15
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();
}
Пример #16
0
/**
 * \brief Initialize the nRF51822.
 */
void
nrf51822_init()
{
  // Setup interrupt from nRF51822
  GPIO_SOFTWARE_CONTROL(NRF51822_INT_BASE, NRF51822_INT_MASK);
  GPIO_SET_INPUT(NRF51822_INT_BASE, NRF51822_INT_MASK);
  GPIO_DETECT_EDGE(NRF51822_INT_BASE, NRF51822_INT_MASK);
  GPIO_TRIGGER_SINGLE_EDGE(NRF51822_INT_BASE, NRF51822_INT_MASK);
  GPIO_DETECT_RISING(NRF51822_INT_BASE, NRF51822_INT_MASK);
  GPIO_ENABLE_INTERRUPT(NRF51822_INT_BASE, NRF51822_INT_MASK);
  ioc_set_over(NRF51822_INT_PORT_NUM, 0, IOC_OVERRIDE_DIS);
  nvic_interrupt_enable(NVIC_INT_GPIO_PORT_B);
  gpio_register_callback(nrf51822_interrupt,
                         NRF51822_INT_PORT_NUM,
                         NRF51822_INT_PIN);


  spi_cs_init(NRF51822_CS_N_PORT_NUM, NRF51822_CS_N_PIN);
  SPI_CS_SET(NRF51822_CS_N_PORT_NUM, NRF51822_CS_N_PIN);
}
Пример #17
0
/**
 * \brief PIN initializer for platform (user) button
 * \param port_base GPIO port's register offset
 * \param pin_mask Pin mask corresponding to the button's pin
 */
static void
config(uint32_t port_base, uint32_t pin_mask)
{
  /* Software controlled */
  GPIO_SOFTWARE_CONTROL(port_base, pin_mask);

  /* Set pin to input */
  GPIO_SET_INPUT(port_base, pin_mask);

  /* Enable edge detection */
  GPIO_DETECT_EDGE(port_base, pin_mask);

  /* Single edge */
  GPIO_TRIGGER_SINGLE_EDGE(port_base, pin_mask);

  /* Trigger interrupt on Falling edge */
  GPIO_DETECT_FALLING(port_base, pin_mask);

  GPIO_ENABLE_INTERRUPT(port_base, pin_mask);
}
Пример #18
0
/*---------------------------------------------------------------------------*/
void
enc28j60_arch_spi_init(void)
{
  /* Set all pins to GPIO mode */

  /* CS, MOSI, CLK are output pins */
  GPIO_SET_OUTPUT(SPI_CS_PORT, SPI_CS_BIT);
  GPIO_SET_OUTPUT(SPI_MOSI_PORT, SPI_MOSI_BIT);
  GPIO_SET_OUTPUT(SPI_CLK_PORT, SPI_CLK_BIT);

  /* MISO is an input pin */
  GPIO_SET_INPUT(SPI_MISO_PORT, SPI_MISO_BIT);

  /* The CS pin is active low, so we set it high when we haven't
     selected the chip. */
  gpio_set(SPI_CS_PORT, SPI_CS_BIT);

  /* The CLK is active low, we set it high when we aren't using it. */
  gpio_reset(SPI_CLK_PORT, SPI_CLK_BIT);
}
Пример #19
0
/**
 * \brief Init function for the User button.
 * \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
 *             or 0 respectively)
 *
 * \param value Depends on the value of the type argument
 * \return Depends on the value of the type argument
 */
static int
config_user(int type, int value)
{
  switch(type) {
  case SENSORS_HW_INIT:
    button_press_duration_exceeded = process_alloc_event();

    /* Software controlled */
    GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    /* Set pin to input */
    GPIO_SET_INPUT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    /* Enable edge detection */
    GPIO_DETECT_EDGE(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    /* Both Edges */
    GPIO_TRIGGER_BOTH_EDGES(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);

    ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);

    gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN);
    break;
  case SENSORS_ACTIVE:
    if(value) {
      GPIO_ENABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
      nvic_interrupt_enable(BUTTON_USER_VECTOR);
    } else {
      GPIO_DISABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
      nvic_interrupt_disable(BUTTON_USER_VECTOR);
    }
    return value;
  case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL:
    press_duration = (clock_time_t)value;
    break;
  default:
    break;
  }

  return 1;
}
Пример #20
0
/*---------------------------------------------------------------------------*/
void
cc1200_arch_gpio2_setup_irq(int rising)
{

  GPIO_SOFTWARE_CONTROL(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  GPIO_SET_INPUT(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  GPIO_DETECT_EDGE(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  GPIO_TRIGGER_SINGLE_EDGE(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);

  if(rising) {
    GPIO_DETECT_RISING(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  } else {
    GPIO_DETECT_FALLING(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  }

  GPIO_ENABLE_INTERRUPT(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
  ioc_set_over(CC1200_GDO2_PORT, CC1200_GDO2_PIN, IOC_OVERRIDE_PUE);
  NVIC_EnableIRQ(CC1200_GPIOx_VECTOR);
  gpio_register_callback(cc1200_int_handler, CC1200_GDO2_PORT,
                         CC1200_GDO2_PIN);
}
Пример #21
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();
}
Пример #22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(mainProcess, ev, data) {
    PROCESS_BEGIN();

    GPIO_SET_OUTPUT(GPIO_A_BASE, 0xf8);
    GPIO_SET_OUTPUT(GPIO_B_BASE, 0x0f);
    GPIO_SET_OUTPUT(GPIO_C_BASE, 0x02);
    GPIO_CLR_PIN(GPIO_A_BASE, 0xf8);
    GPIO_CLR_PIN(GPIO_B_BASE, 0x07);
    GPIO_SET_PIN(EDISON_WAKEUP_BASE, EDISON_WAKEUP_PIN_MASK); // edison WAKEUP

    GPIO_SET_INPUT(RESET_PORT_BASE, RESET_PIN_MASK); // reset
    ioc_set_over(RESET_PORT, RESET_PIN, IOC_OVERRIDE_PUE);

    leds_off(LEDS_RED);
    leds_off(LEDS_GREEN);
    leds_off(LEDS_BLUE);

    // RESET interrupt, active low
    GPIO_DETECT_EDGE(RESET_PORT_BASE, RESET_PIN_MASK);
    GPIO_DETECT_FALLING(RESET_PORT_BASE, RESET_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(RESET_PORT_BASE, RESET_PIN_MASK);
    gpio_register_callback(resetcallBack, RESET_PORT, RESET_PIN);
    GPIO_ENABLE_INTERRUPT(RESET_PORT_BASE, RESET_PIN_MASK);
    nvic_interrupt_enable(RESET_NVIC_PORT);

    GPIO_CLR_PIN(TRIUMVI_DATA_READY_PORT_BASE, TRIUMVI_DATA_READY_MASK);

    // SPI CS interrupt
    GPIO_DETECT_EDGE(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    GPIO_DETECT_RISING(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);
    gpio_register_callback(spiCScallBack, SPI0_CS_PORT, SPI0_CS_PIN);
    GPIO_ENABLE_INTERRUPT(SPI0_CS_PORT_BASE, SPI0_CS_PIN_MASK);

    // SPI interface
    spix_slave_init(SPIDEV);
    spix_txdma_enable(SPIDEV);
    spi_register_callback(spiFIFOcallBack);
    spix_interrupt_enable(SPIDEV, SSI_IM_RXIM_M); // RX FIFO half full
    nvic_interrupt_enable(NVIC_INT_SSI0);

    // uDMA SPI0 TX
    udma_channel_disable(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_prio_set_default(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_use_primary(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_use_single(CC2538_SPI0_TX_DMA_CHAN);
    udma_channel_mask_clr(CC2538_SPI0_TX_DMA_CHAN);
    udma_set_channel_dst(CC2538_SPI0_TX_DMA_CHAN, SPI0DR);
    udma_set_channel_assignment(CC2538_SPI0_TX_DMA_CHAN, UDMA_CH11_SSI0TX);


    simple_network_set_callback(&rf_rx_handler);
    //NETSTACK_RADIO.off();
    
    process_start(&decryptProcess, NULL);
    process_start(&spiProcess, NULL);


    while (1){
        PROCESS_YIELD();
        // buffer is not empty, spi is not in use
        //if ((spiInUse==0) && (spix_busy(SPIDEV)==0) && ((triumviAvailIDX!=triumviFullIDX) || (triumviRXBufFull==1))){
        if ((spiInUse==0) && ((triumviAvailIDX!=triumviFullIDX) || (triumviRXBufFull==1))){
            GPIO_SET_PIN(TRIUMVI_DATA_READY_PORT_BASE, TRIUMVI_DATA_READY_MASK);
            if (triumviRXBufFull==1){
                resetCnt += 1;
                if (resetCnt==RESET_THRESHOLD){
                    watchdog_reboot();
                }
            }
            #ifdef LED_DEBUG
            leds_off(LEDS_RED);
            leds_off(LEDS_GREEN);
            leds_off(LEDS_BLUE);
            #endif
        }
        // Fail safe, CC2538 missing some SPI commands, reset spi state
        else if (triumviRXBufFull==1){
            spiState = SPI_RESET;
            process_poll(&spiProcess);
            #ifdef LED_DEBUG
            leds_off(LEDS_RED);
            leds_off(LEDS_GREEN);
            leds_on(LEDS_BLUE);
            #endif
        }
    }
    PROCESS_END();
}
Пример #23
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  if((type != WEATHER_METER_ACTIVE) &&
     (type != WEATHER_METER_ANEMOMETER_INT_OVER) &&
     (type != WEATHER_METER_RAIN_GAUGE_INT_OVER) &&
     (type != WEATHER_METER_ANEMOMETER_INT_DIS) &&
     (type != WEATHER_METER_RAIN_GAUGE_INT_DIS)) {
    PRINTF("Weather: invalid configuration option\n");
    return WEATHER_METER_ERROR;
  }

  if(type == WEATHER_METER_ACTIVE) {

    anemometer.value_avg = 0;
    anemometer.ticks_avg = 0;

    weather_sensors.anemometer.int_en = 0;
    weather_sensors.rain_gauge.int_en = 0;
    weather_sensors.anemometer.ticks = 0;
    weather_sensors.rain_gauge.ticks = 0;
    weather_sensors.anemometer.value = 0;
    weather_sensors.rain_gauge.value = 0;

    if(!value) {
      anemometer_int_callback = NULL;
      rain_gauge_int_callback = NULL;
      GPIO_DISABLE_INTERRUPT(ANEMOMETER_SENSOR_PORT_BASE,
                             ANEMOMETER_SENSOR_PIN_MASK);
      GPIO_DISABLE_INTERRUPT(RAIN_GAUGE_SENSOR_PORT_BASE,
                             RAIN_GAUGE_SENSOR_PIN_MASK);
      process_exit(&weather_meter_int_process);
      enabled = 0;
      PRINTF("Weather: disabled\n");
      return WEATHER_METER_SUCCESS;
    }

    /* Configure the wind vane */
    adc_zoul.configure(SENSORS_HW_INIT, WIND_VANE_ADC);

    /* Configure anemometer interruption */
    GPIO_SOFTWARE_CONTROL(ANEMOMETER_SENSOR_PORT_BASE, ANEMOMETER_SENSOR_PIN_MASK);
    GPIO_SET_INPUT(ANEMOMETER_SENSOR_PORT_BASE, ANEMOMETER_SENSOR_PIN_MASK);
    GPIO_DETECT_RISING(ANEMOMETER_SENSOR_PORT_BASE, ANEMOMETER_SENSOR_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(ANEMOMETER_SENSOR_PORT_BASE,
                             ANEMOMETER_SENSOR_PIN_MASK);
    ioc_set_over(ANEMOMETER_SENSOR_PORT, ANEMOMETER_SENSOR_PIN, IOC_OVERRIDE_DIS);
    gpio_register_callback(weather_meter_interrupt_handler, ANEMOMETER_SENSOR_PORT,
                           ANEMOMETER_SENSOR_PIN);

    /* Configure rain gauge interruption */
    GPIO_SOFTWARE_CONTROL(RAIN_GAUGE_SENSOR_PORT_BASE, RAIN_GAUGE_SENSOR_PIN_MASK);
    GPIO_SET_INPUT(RAIN_GAUGE_SENSOR_PORT_BASE, RAIN_GAUGE_SENSOR_PIN_MASK);
    GPIO_DETECT_RISING(RAIN_GAUGE_SENSOR_PORT_BASE, RAIN_GAUGE_SENSOR_PIN_MASK);
    GPIO_TRIGGER_SINGLE_EDGE(RAIN_GAUGE_SENSOR_PORT_BASE,
                             RAIN_GAUGE_SENSOR_PIN_MASK);
    ioc_set_over(RAIN_GAUGE_SENSOR_PORT, RAIN_GAUGE_SENSOR_PIN, IOC_OVERRIDE_DIS);
    gpio_register_callback(weather_meter_interrupt_handler, RAIN_GAUGE_SENSOR_PORT,
                           RAIN_GAUGE_SENSOR_PIN);

    process_start(&weather_meter_int_process, NULL);

    /* Initialize here prior the first second tick */
    wind_vane.value_prev = weather_meter_get_wind_dir();

    ctimer_set(&ct, CLOCK_SECOND, ct_callback, NULL);

    GPIO_ENABLE_INTERRUPT(ANEMOMETER_SENSOR_PORT_BASE, ANEMOMETER_SENSOR_PIN_MASK);
    GPIO_ENABLE_INTERRUPT(RAIN_GAUGE_SENSOR_PORT_BASE, RAIN_GAUGE_SENSOR_PIN_MASK);
    nvic_interrupt_enable(ANEMOMETER_SENSOR_VECTOR);
    nvic_interrupt_enable(RAIN_GAUGE_SENSOR_VECTOR);

    enabled = 1;
    PRINTF("Weather: started\n");
    return WEATHER_METER_SUCCESS;
  }

  switch(type) {
  case WEATHER_METER_ANEMOMETER_INT_OVER:
    weather_sensors.anemometer.int_en = 1;
    weather_sensors.anemometer.int_thres = value;
    PRINTF("Weather: anemometer threshold %u\n", value);
    break;
  case WEATHER_METER_RAIN_GAUGE_INT_OVER:
    weather_sensors.rain_gauge.int_en = 1;
    weather_sensors.rain_gauge.int_thres = value;
    PRINTF("Weather: rain gauge threshold %u\n", value);
    break;
  case WEATHER_METER_ANEMOMETER_INT_DIS:
    PRINTF("Weather: anemometer int disabled\n");
    weather_sensors.anemometer.int_en = 0;
    break;
  case WEATHER_METER_RAIN_GAUGE_INT_DIS:
    PRINTF("Weather: rain gauge int disabled\n");
    weather_sensors.rain_gauge.int_en = 0;
    break;
  default:
    return WEATHER_METER_ERROR;
  }

  return WEATHER_METER_SUCCESS;
}