Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
void
cc1200_arch_gpio2_enable_irq(void)
{
  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);
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
void setup_unplug_detect_pin() {
	gpio_register_callback(unplug_detect, PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_NUM);
	GPIO_DETECT_FALLING(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_POWER_UP_ON_FALLING(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
	GPIO_CLEAR_INTERRUPT(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_CLEAR_POWER_UP_INTERRUPT(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
	GPIO_ENABLE_INTERRUPT(PLUG_DETECT_PORT_BASE, PLUG_DETECT_PIN_MASK);
	GPIO_ENABLE_POWER_UP_INTERRUPT(PLUG_DETECT_PORT_NUM, PLUG_DETECT_PIN_MASK);
}
Exemplo n.º 6
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.º 7
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;
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
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.º 10
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);
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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.º 16
0
/*---------------------------------------------------------------------------*/
static void
ct_callback(void *ptr)
{
  uint32_t wind_speed;
  int16_t wind_dir;
  int16_t wind_dir_delta;

  /* Disable to make the calculations in an interrupt-safe context */
  GPIO_DISABLE_INTERRUPT(ANEMOMETER_SENSOR_PORT_BASE,
                         ANEMOMETER_SENSOR_PIN_MASK);
  wind_speed = weather_sensors.anemometer.ticks;
  wind_speed *= WEATHER_METER_ANEMOMETER_SPEED_1S;
  weather_sensors.anemometer.value = (uint16_t)wind_speed;
  anemometer.ticks_avg++;
  anemometer.value_avg += weather_sensors.anemometer.value;
  anemometer.value_buf_xm += weather_sensors.anemometer.value;

  /* Take maximum value */
  if(weather_sensors.anemometer.value > anemometer.value_max) {
    anemometer.value_max = weather_sensors.anemometer.value;
  }

  /* Mitsuta method to get the wind direction average */
  wind_dir = weather_meter_get_wind_dir();
  wind_dir_delta = wind_dir - wind_vane.value_prev;

  if(wind_dir_delta < -1800) {
    wind_vane.value_prev += wind_dir_delta + 3600;
  } else if(wind_dir_delta > 1800) {
    wind_vane.value_prev += wind_dir_delta - 3600;
  } else {
    wind_vane.value_prev += wind_dir_delta;
  }

  wind_vane.value_buf_xm += wind_vane.value_prev;

  /* Calculate the 2 minute average */
  if(!(anemometer.ticks_avg % WEATHER_METER_AVG_PERIOD)) {
    PRINTF("\nWeather: calculate the %u averages ***\n", WEATHER_METER_AVG_PERIOD);

    if(anemometer.value_buf_xm) {
      anemometer.value_avg_xm = anemometer.value_buf_xm / WEATHER_METER_AVG_PERIOD;
      anemometer.value_buf_xm = 0;
    } else {
      anemometer.value_avg_xm = 0;
    }

    if(wind_vane.value_buf_xm >= 0) {
      wind_vane.value_buf_xm = wind_vane.value_buf_xm / WEATHER_METER_AVG_PERIOD;
      wind_vane.value_avg_xm = wind_vane.value_buf_xm;
    } else {
      wind_vane.value_buf_xm = ABS(wind_vane.value_buf_xm) / WEATHER_METER_AVG_PERIOD;
      wind_vane.value_avg_xm = wind_vane.value_buf_xm;
      wind_vane.value_avg_xm = ~wind_vane.value_avg_xm + 1;
    }

    if(wind_vane.value_avg_xm >= 3600) {
      wind_vane.value_avg_xm -= 3600;
    } else if(wind_vane.value_avg_xm < 0) {
      wind_vane.value_avg_xm += 3600;
    }

    wind_vane.value_buf_xm = 0;
    wind_vane.value_prev = wind_dir;
  }

  /* Check for roll-over */
  if(!anemometer.ticks_avg) {
    anemometer.value_avg = 0;
  }

  weather_sensors.anemometer.ticks = 0;

  /* Enable the interrupt again */
  GPIO_ENABLE_INTERRUPT(ANEMOMETER_SENSOR_PORT_BASE,
                        ANEMOMETER_SENSOR_PIN_MASK);

  ctimer_set(&ct, CLOCK_SECOND, ct_callback, NULL);
}
Exemplo n.º 17
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();
}