Exemplo n.º 1
0
int mpu9150_init(mpu9150_t *dev, i2c_t i2c, mpu9150_hw_addr_t hw_addr,
        mpu9150_comp_addr_t comp_addr)
{
    char temp;

    dev->i2c_dev = i2c;
    dev->hw_addr = hw_addr;
    dev->comp_addr = comp_addr;
    dev->conf = DEFAULT_STATUS;

    /* Initialize I2C interface */
    if (i2c_init_master(dev->i2c_dev, I2C_SPEED_FAST)) {
        DEBUG("[Error] I2C device not enabled\n");
        return -1;
    }

    /* Acquire exclusive access */
    i2c_acquire(dev->i2c_dev);

    /* Reset MPU9150 registers and afterwards wake up the chip */
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_RESET);
    hwtimer_wait(HWTIMER_TICKS(MPU9150_RESET_SLEEP_US));
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP);

    /* Release the bus, it is acquired again inside each function */
    i2c_release(dev->i2c_dev);

    /* Set default full scale ranges and sample rate */
    mpu9150_set_gyro_fsr(dev, MPU9150_GYRO_FSR_2000DPS);
    mpu9150_set_accel_fsr(dev, MPU9150_ACCEL_FSR_2G);
    mpu9150_set_sample_rate(dev, MPU9150_DEFAULT_SAMPLE_RATE);

    /* Disable interrupt generation */
    i2c_acquire(dev->i2c_dev);
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_ENABLE_REG, REG_RESET);

    /* Initialize magnetometer */
    if (compass_init(dev)) {
        i2c_release(dev->i2c_dev);
        return -2;
    }
    /* Release the bus, it is acquired again inside each function */
    i2c_release(dev->i2c_dev);
    mpu9150_set_compass_sample_rate(dev, 10);
    /* Enable all sensors */
    i2c_acquire(dev->i2c_dev);
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_PLL);
    i2c_read_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, &temp);
    temp &= ~(MPU9150_PWR_ACCEL | MPU9150_PWR_GYRO);
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, temp);
    i2c_release(dev->i2c_dev);
    hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US));

    return 0;
}
Exemplo n.º 2
0
void sender(void)
{
    unsigned int i = 0;
    msg_t mesg;
    transceiver_command_t tcmd;
    radio_packet_t p;

    mesg.type = SND_PKT;
    mesg.content.ptr = (char *) &tcmd;

    tcmd.transceivers = TRANSCEIVER_NATIVE;
    tcmd.data = &p;

    p.length = PACKET_SIZE;
    p.dst = 0;

    puts("Start sending packets");

    while (1) {
        /* filling uint8_t buffer with uint16_t sequence number */
        snd_buffer[0] = (i & 0xFF00) >> 8;
        snd_buffer[1] = i & 0x00FF;
        p.data = snd_buffer;
        i++;
        msg_send(&mesg, transceiver_pid);
        hwtimer_wait(HWTIMER_TICKS(SENDING_DELAY));
    }
}
Exemplo n.º 3
0
void cc2420_reset(void)
{
    P4OUT |= CC2420_VREGEN_PIN;
    P4OUT &= ~CC2420_RESETn_PIN;
    hwtimer_wait(500);
    P4OUT |= CC2420_RESETn_PIN;
}
Exemplo n.º 4
0
int main(void) {
    int radio_pid;
    uint8_t i;
    for (i = 0; i < SND_BUFFER_SIZE; i++) { 
        memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH);
    }
    thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, shell_runner, "shell");
    radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
    transceiver_init(TRANSCEIVER_CC1100);
    transceiver_start();
    transceiver_register(TRANSCEIVER_CC1100, radio_pid);
    sender(NULL);

    printf("Config:\n");
    printf("\tid: %u\n", sysconfig.id);
    printf("\taddr: %u\n", sysconfig.radio_address);
    printf("\tchannel: %u\n", sysconfig.radio_channel);
   
   while (1) {
       extern void thread_print_all(void);
       thread_print_all();
       print_buffer(NULL);
       hwtimer_wait(50000);
   }
}
Exemplo n.º 5
0
void cc110x_cs(void)
{
    volatile int retry_count = 0;
    /* Switch MISO/GDO1 to GPIO input mode */
    gpio_init_in(CC110X_GDO1, GPIO_NOPULL);
    /* CS to low */
    gpio_clear(CC110X_CS);
    /* Wait for SO to go low (voltage regulator
     * has stabilized and the crystal is running) */
    while (gpio_read(CC110X_GDO1)) {
        /* Wait ~500us and try again */
        hwtimer_wait(CS_SO_WAIT_TIME);

        if (gpio_read(CC110X_GDO1)) {
            retry_count++;

            if (retry_count > CC1100_GDO1_LOW_RETRY) {
                puts("[CC1100 SPI] fatal error\n");
                break;
            }

            gpio_set(CC110X_CS);
            gpio_clear(CC110X_CS);
        }
    }
    /* Switch MISO/GDO1 to SPI mode */
    spi_conf_pins(CC110X_SPI);
}
Exemplo n.º 6
0
int main(void)
{
    int16_t a;
    msg_t mesg;
    transceiver_command_t tcmd;

    printf("\n\tmain(): initializing transceiver\n");
    transceiver_init(TRANSCEIVER_NATIVE);

    printf("\n\tmain(): starting transceiver\n");
    transceiver_start();

#ifndef SENDER
    printf("\n\tmain(): starting radio thread\n");
    kernel_pid_t radio_pid = thread_create(
            radio_stack_buffer, sizeof(radio_stack_buffer),
            PRIORITY_MAIN - 2, CREATE_STACKTEST,
            radio, NULL, "radio");
    transceiver_register(TRANSCEIVER_NATIVE, radio_pid);
#endif

#ifdef SENDER
    a = SENDER_ADDR;
#elif defined ADDR
    a = ADDR;
#else
    a = DEFAULT_RCV_ADDR;
#endif
    tcmd.transceivers = TRANSCEIVER_NATIVE;
    tcmd.data = &a;
    mesg.content.ptr = (char *) &tcmd;
    mesg.type = SET_ADDRESS;

    printf("[nativenet] trying to set address %" PRIi16 "\n", a);
    msg_send_receive(&mesg, &mesg, transceiver_pid);

#ifdef SENDER
    hwtimer_wait(HWTIMER_TICKS(SECOND));
    sender();
#else
    hwtimer_wait(HWTIMER_TICKS(WAIT_TIME * SECOND));
    receiving = 0;
    printf("Missed %u of %u packets after %u seconds\n", missed_cnt, (last_seq - first),  WAIT_TIME);
#endif

    return 0;
}
Exemplo n.º 7
0
int reboot_arch(int mode)
{
    printf("Going into reboot, mode %i\n", mode);
    /* wait 1 ms to make sure the printf is finished */
    hwtimer_wait(HWTIMER_TICKS(1000));
    NVIC_SystemReset();
    return -1;
}
Exemplo n.º 8
0
void nrf24l01p_transmit(nrf24l01p_t *dev)
{
    gpio_set(dev->ce);
    hwtimer_wait(DELAY_CE_HIGH_US); /* at least 10 us high */
    gpio_clear(dev->ce);

    hwtimer_spin(DELAY_CHANGE_TXRX_US);
}
Exemplo n.º 9
0
void cc2420_init(int tpid)
{
    uint16_t reg;
    transceiver_pid = tpid;

    cc2420_spi_init();
    hwtimer_wait(CC2420_WAIT_TIME);
    cc2420_reset();

    cc2420_strobe(CC2420_STROBE_XOSCON);               //enable crystal

    while((cc2420_strobe(NOBYTE) & 0x40) == 0);        //wait for crystal to be stable
    hwtimer_wait(CC2420_WAIT_TIME);

    reg = cc2420_read_reg(CC2420_REG_MDMCTRL0);
    reg |= CC2420_ADR_DECODE;                          //enable adr decode
    reg |= CC2420_AUTOACK;                             //enable auto ack
    reg |= CC2420_AUTOCRC;                             //enable auto crc
    reg &= ~(CC2420_RES_FRM_MODE);                     //disable reserved frames
    cc2420_write_reg(CC2420_REG_MDMCTRL0, reg);

    /* Change default values as recomended in the data sheet, */
    /* RX bandpass filter = 1.3uA. */
    reg = cc2420_read_reg(CC2420_REG_RXCTRL1);
    reg |= CC2420_RXBPF_LOCUR;
    cc2420_write_reg(CC2420_REG_RXCTRL1, reg);

    /* Set the FIFOP threshold to maximum. */
    cc2420_write_reg(CC2420_REG_IOCFG0, 127);

    /* Turn off "Security enable" (page 32). */
    reg = cc2420_read_reg(CC2420_REG_SECCTRL0);
    reg &= ~CC2420_RXFIFO_PROTECTION;
    cc2420_write_reg(CC2420_REG_SECCTRL0, reg);

    /* set output power to 0dbm */
    cc2420_write_reg(CC2420_REG_TXCTRL, 0xA0FF);

    cc2420_set_channel(CC2420_DEFAULT_CHANNR);
    cc2420_set_pan(0x1111);
    DEBUG("CC2420 initialized and set to channel %i and pan %i\n", radio_channel, radio_pan);
    cc2420_init_interrupts();
    cc2420_switch_to_rx();

}
Exemplo n.º 10
0
/**
 * Configure bypass mode
 * Caution: This internal function does not acquire exclusive access to the I2C bus.
 *          Acquisation and release is supposed to be handled by the calling function.
 */
static void conf_bypass(mpu9150_t *dev, uint8_t bypass_enable)
{
   char data;
   i2c_read_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, &data);

   if (bypass_enable) {
       data &= ~(BIT_I2C_MST_EN);
       i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, data);
       hwtimer_wait(HWTIMER_TICKS(MPU9150_BYPASS_SLEEP_US));
       i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_PIN_CFG_REG, BIT_I2C_BYPASS_EN);
   }
   else {
       data |= BIT_I2C_MST_EN;
       i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, data);
       hwtimer_wait(HWTIMER_TICKS(MPU9150_BYPASS_SLEEP_US));
       i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_INT_PIN_CFG_REG, REG_RESET);
   }
}
Exemplo n.º 11
0
static void reset(void)
{
    cc110x_wakeup_from_rx();
#ifdef MODULE_CC110x_SPI
    cc110x_spi_select();
#endif
    cc110x_strobe(CC1100_SRES);
    hwtimer_wait(RTIMER_TICKS(100));
}
Exemplo n.º 12
0
int main(void)
{
    printf("when the race condition is hit, hwtimer will wait a very very long time...\n");

    while (1) {
        for (unsigned long i = 256; i; i = i >> 1) {
            printf("wait %lu\n", i);
            hwtimer_wait(i);
        }
    }
}
Exemplo n.º 13
0
static void power_up_reset(void)
{
#ifdef MODULE_CC110x_SPI
    cc110x_spi_unselect();
    cc110x_spi_cs();
    cc110x_spi_unselect();
#endif
    hwtimer_wait(RESET_WAIT_TIME);
    reset();
    radio_state = RADIO_IDLE;
}
Exemplo n.º 14
0
/************************************************************************************************
 * @fn          adc12_single_conversion
 * @brief       Init ADC12. Do single conversion. Turn off ADC12.
 * @param       none
 * @return      none
 ************************************************************************************************/
uint16_t adc12_single_conversion(uint16_t ref, uint16_t sht, uint16_t channel)
{
    /* Initialize the shared reference module  */
    REFCTL0 |= REFMSTR + ref + REFON;           /* Enable internal reference (1.5V or 2.5V) */

    /* Initialize ADC12_A  */
    ADC12CTL0 = sht + ADC12ON;                  /* Set sample time  */
    ADC12CTL1 = ADC12SHP;                       /* Enable sample timer */
    ADC12MCTL0 = ADC12SREF_1 + channel;         /* ADC input channel   */
    ADC12IE = 0x001;                            /* ADC_IFG upon conv result-ADCMEMO */
    enableIRQ();

    /* Wait 2 ticks (66us) to allow internal reference to settle */
    hwtimer_wait(2);

    /* Start ADC12 */
    ADC12CTL0 |= ADC12ENC;

    /* Clear data ready flag */
    adc12_data_ready = 0;

    /* Sampling and conversion start   */
    ADC12CTL0 |= ADC12SC;

    /* Wait until ADC12 has finished */
    hwtimer_wait(5);

    while (!adc12_data_ready);

    /* Shut down ADC12 */
    ADC12CTL0 &= ~(ADC12ENC | ADC12SC | sht);
    ADC12CTL0 &= ~ADC12ON;

    /* Shut down reference voltage   */
    REFCTL0 &= ~(REFMSTR + ref + REFON);

    ADC12IE = 0;

    /* Return ADC result */
    return adc12_result;
}
Exemplo n.º 15
0
int nrf24l01p_off(nrf24l01p_t *dev)
{
    char read;
    int status;

    nrf24l01p_read_reg(dev, REG_CONFIG, &read);
    status = nrf24l01p_write_reg(dev, REG_CONFIG, (read & ~PWR_UP));

    hwtimer_wait(DELAY_CHANGE_PWR_MODE_US);

    return status;
}
Exemplo n.º 16
0
Arquivo: mac.c Projeto: fjrk/RIOT
void sixlowpan_mac_send_ieee802154_frame(const ieee_802154_long_t *addr,
        const uint8_t *payload,
        uint8_t length, uint8_t mcast)
{
    uint16_t daddr;
    /* TODO: check if dedicated response struct is necessary */
    msg_t transceiver_rsp;
    r_src_addr = local_address;
    mesg.type = SND_PKT;
    mesg.content.ptr = (char *) &tcmd;

    tcmd.transceivers = transceiver_type;
    tcmd.data = &p;

    ieee802154_frame_t frame;

    memset(&frame, 0, sizeof(frame));
    set_ieee802154_fcf_values(&frame, IEEE_802154_LONG_ADDR_M,
                              IEEE_802154_LONG_ADDR_M);
    set_ieee802154_frame_values(&frame);

    memcpy(&(frame.dest_addr[0]), &(addr->uint8[0]), 8);
    memcpy(&(frame.src_addr[0]), &(iface.laddr.uint8[0]), 8);

    daddr = HTONS(addr->uint16[3]);
    frame.payload = (uint8_t *)payload; // payload won't be changed so cast is legal.
    frame.payload_len = length;
    uint8_t hdrlen = get_802154_hdr_len(&frame);

    memset(&buf, 0, PAYLOAD_SIZE);
    init_802154_frame(&frame, (uint8_t *)&buf);
    memcpy(&buf[hdrlen], frame.payload, frame.payload_len);
    /* set FCS */
    /* RSSI = 0 */
    buf[frame.payload_len+hdrlen] = 0;
    /* FCS Valid = 1 / LQI Correlation Value = 0 */
    buf[frame.payload_len+hdrlen+1] = 0x80;
    DEBUG("IEEE802.15.4 frame - FCF: %02X %02X DPID: %02X SPID: %02X DSN: %02X\n", buf[0], buf[1], frame->dest_pan_id, frame->src_pan_id, frame->seq_nr);

    p.length = hdrlen + frame.payload_len + IEEE_802154_FCS_LEN;

    if (mcast == 0) {
        p.dst = daddr;
    }
    else {
        p.dst = 0;
    }

    p.data = buf;
    msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid);

    hwtimer_wait(5000);
}
Exemplo n.º 17
0
int main(void)
{
    puts("FLASH!");
    int *bad;
    int *foo;

    hwtimer_init();

    printf("%04X\n", WDMOD); 
    hwtimer_wait(1000 * 1000);

    memcpy(bad, foo, 1000);
    return 0;
}
Exemplo n.º 18
0
/**
 * @set TX mode
 */
int cmd_send(int argc, char **argv)
{
    (void) argc;
    (void) argv;

    puts("Send");

    int status = 0;
    char tx_buf[NRF24L01P_MAX_DATA_LENGTH];

    /* fill TX buffer with numbers 32..1 */
    for (int i = 0; i < sizeof(tx_buf); i++) {
        tx_buf[i] = NRF24L01P_MAX_DATA_LENGTH - i;
    }
    /* power on the device */
    if (nrf24l01p_on(&nrf24l01p_0) < 0) {
        puts("Error in nrf24l01p_on");
        return;
    }
    /* setup device as transmitter */
    if (nrf24l01p_set_txmode(&nrf24l01p_0) < 0) {
        puts("Error in nrf24l01p_set_txmode");
        return;
    }
    /* load data to transmit into device */
    if (nrf24l01p_preload(&nrf24l01p_0, tx_buf, NRF24L01P_MAX_DATA_LENGTH) < 0) {
        puts("Error in nrf24l01p_preload");
        return;
    }
    /* trigger transmitting */
    nrf24l01p_transmit(&nrf24l01p_0);
    /* wait while data is pysically transmitted  */
    hwtimer_wait(DELAY_DATA_ON_AIR);
    /* get status of the transceiver */
    status = nrf24l01p_get_status(&nrf24l01p_0);
    if (status < 0) {
        puts("Error in nrf24l01p_get_status");
    }
    if (status & TX_DS) {
        puts("Sent Packet");
    }
    /* setup device as receiver */
    if (nrf24l01p_set_rxmode(&nrf24l01p_0) < 0) {
        puts("Error in nrf24l01p_set_rxmode");
        return 1;
    }

    return 0;
}
Exemplo n.º 19
0
uint32_t srf02_get_distance(uint8_t ranging_mode)
{
    bool status = false;
    uint8_t reg_size = 1;
    uint8_t range_high_byte = 0;
    uint8_t range_low_byte = 0;
    uint8_t rx_buff[reg_size];
    uint8_t tx_buff[reg_size];
    uint32_t distance = 0;

    tx_buff[0] = ranging_mode;
    status = i2c_write(SRF02_I2C_INTERFACE, SRF02_DEFAULT_ADDR,
                       SRF02_COMMAND_REG, tx_buff, reg_size);

    if (!status) {
        puts("Write the ranging command to the i2c-interface is failed");
        distance = UINT32_MAX;
        return distance;
    }

    hwtimer_wait(HWTIMER_TICKS(65000));

    status = i2c_read(SRF02_I2C_INTERFACE, SRF02_DEFAULT_ADDR,
                      SRF02_RANGE_HIGH_BYTE, rx_buff, reg_size);

    if (!status) {
        puts("Read the high echo byte from the i2c-interface is failed");
        distance = UINT32_MAX;
        return distance;
    }

    range_high_byte = rx_buff[0];

    status = i2c_read(SRF02_I2C_INTERFACE, SRF02_DEFAULT_ADDR,
                      SRF02_RANGE_LOW_BYTE, rx_buff, reg_size);

    if (!status) {
        puts("Read the low echo byte from the i2c-interface is failed");
        distance = UINT32_MAX;
        return distance;
    }

    range_low_byte = rx_buff[0];

    distance = (range_high_byte << 8) | range_low_byte;
    //printf("%u | %u\n", range_high_byte, range_low_byte);
    return distance;
}
Exemplo n.º 20
0
int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
{
    char pwr_2_setting;

    if (dev->conf.gyro_pwr == pwr_conf) {
        return 0;
    }

    /* Acquire exclusive access */
    if (i2c_acquire(dev->i2c_dev)) {
        return -1;
    }

    /* Read current power management 2 configuration */
    i2c_read_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, &pwr_2_setting);
    /* Prepare power register settings */
    if (pwr_conf == MPU9150_SENSOR_PWR_ON) {
        /* Set clock to pll */
        i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_PLL);
        pwr_2_setting &= ~(MPU9150_PWR_GYRO);
    }
    else {
        /* Configure power management 1 register */
        if ((dev->conf.accel_pwr == MPU9150_SENSOR_PWR_OFF)
                && (dev->conf.compass_pwr == MPU9150_SENSOR_PWR_OFF)) {
            /* All sensors turned off, put the MPU-9150 to sleep */
            i2c_write_reg(dev->i2c_dev, dev->hw_addr,
                    MPU9150_PWR_MGMT_1_REG, BIT_PWR_MGMT1_SLEEP);
        }
        else {
            /* Reset clock to internal oscillator */
            i2c_write_reg(dev->i2c_dev, dev->hw_addr,
                    MPU9150_PWR_MGMT_1_REG, MPU9150_PWR_WAKEUP);
        }
        pwr_2_setting |= MPU9150_PWR_GYRO;
    }
    /* Enable/disable gyroscope standby in power management 2 register */
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, pwr_2_setting);

    /* Release the bus */
    i2c_release(dev->i2c_dev);

    dev->conf.gyro_pwr = pwr_conf;
    hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US));

    return 0;
}
Exemplo n.º 21
0
int main(void) {
    int radio_pid;
    uint8_t i;
    for (i = 0; i < SND_BUFFER_SIZE; i++) { 
        memset(snd_buffer[i], i, CC1100_MAX_DATA_LENGTH);
    }
    thread_create(shell_stack_buffer, SHELL_STACK_SIZE, PRIORITY_MAIN-1, CREATE_STACKTEST, shell_runner, "shell");
    radio_pid = thread_create(radio_stack_buffer, RADIO_STACK_SIZE, PRIORITY_MAIN-2, CREATE_STACKTEST, radio, "radio");
    transceiver_init(TRANSCEIVER_CC1100);
    transceiver_start();
    transceiver_register(TRANSCEIVER_CC1100, radio_pid);
   
   while (1) {
//       LED_GREEN_TOGGLE;
       hwtimer_wait(1000 * 1000);
   }
}
Exemplo n.º 22
0
void ping(radio_address_t addr, uint8_t channr)
{
    cc1100_set_packet_handler(protocol_id, pong_handler);
    cc1100_set_channel(channr);
    cc1100_set_address(r_address);

    while(1) {
        vtimer_now(&start);
        int trans_ok = cc1100_send_csmaca(addr,
                                          protocol_id, 2, pipa->payload, sizeof(pipa->payload));

        if(trans_ok < 0) {
            print_failed();
        }

        hwtimer_wait(500000);
    }
}
Exemplo n.º 23
0
int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
{
    char pwr_1_setting, usr_ctrl_setting, s1_do_setting;

    if (dev->conf.compass_pwr == pwr_conf) {
        return 0;
    }

    /* Acquire exclusive access */
    if (i2c_acquire(dev->i2c_dev)) {
        return -1;
    }

    /* Read current user control configuration */
    i2c_read_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, &usr_ctrl_setting);
    /* Prepare power register settings */
    if (pwr_conf == MPU9150_SENSOR_PWR_ON) {
        pwr_1_setting = MPU9150_PWR_WAKEUP;
        s1_do_setting = MPU9150_COMP_SINGLE_MEASURE;
        usr_ctrl_setting |= BIT_I2C_MST_EN;
    }
    else {
        pwr_1_setting = BIT_PWR_MGMT1_SLEEP;
        s1_do_setting = MPU9150_COMP_POWER_DOWN;
        usr_ctrl_setting &= ~(BIT_I2C_MST_EN);
    }
    /* Configure power management 1 register if needed */
    if ((dev->conf.gyro_pwr == MPU9150_SENSOR_PWR_OFF)
            && (dev->conf.accel_pwr == MPU9150_SENSOR_PWR_OFF)) {
        i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, pwr_1_setting);
    }
    /* Configure mode writing by slave line 1 */
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_SLAVE1_DATA_OUT_REG, s1_do_setting);
    /* Enable/disable I2C master mode */
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_USER_CTRL_REG, usr_ctrl_setting);

    /* Release the bus */
    i2c_release(dev->i2c_dev);

    dev->conf.compass_pwr = pwr_conf;
    hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US));

    return 0;
}
Exemplo n.º 24
0
void sender(char *count) {
    unsigned int c = 3;
    unsigned int i;

    mesg.type = SND_PKT;
    mesg.content.ptr = (char*) &tcmd;

    tcmd.transceivers = TRANSCEIVER_CC1100;
    tcmd.data = &p;

    p.length = CC1100_MAX_DATA_LENGTH;
    p.dst = 0;

    for (i = 0; i < c; i++) {
        puts(".");
        p.data = snd_buffer[i % SND_BUFFER_SIZE];
        msg_send(&mesg, transceiver_pid, 1);
        hwtimer_wait(50000);
    }
}
Exemplo n.º 25
0
Arquivo: main.c Projeto: 4120976/RIOT
int main(void)
{
    puts("hwtimer test application...");

    puts("");
    puts("  Timers should print \"callback x\" once when they run out.");
    printf("  The order for x is 1, n-1, n-2, ..., 2 where n is the number of available hardware timers (%u on this platform).\n", HWTIMER_MAXTIMERS);
    puts("  One timer should fire every second until all timers have run out.");
    puts("  Additionally the message \"hwtimer set.\" should be printed once 1 second from now.");
    puts("");
    puts("Setting timers:");
    puts("");

    unsigned long delay = BASE_DELAY + ((HWTIMER_MAXTIMERS - 1) * DELTA_DELAY);

    /* make the first timer first to fire so timers do not run out linearly */
    char *msgn = msg;
    snprintf(msgn, MSGLEN, "callback %2x", 1);
    hwtimer_set(HWTIMER_TICKS(BASE_DELAY), callback, (void *) msgn);
    printf("set %s\n", msgn);

    /* set up to HWTIMER_MAXTIMERS-1 because hwtimer_wait below also
     * needs a timer */
    for (int i = 1; i < (HWTIMER_MAXTIMERS - 1); i++) {
        msgn = msg + (i * MSGLEN);
        delay -= DELTA_DELAY;
        snprintf(msgn, MSGLEN, "callback %2x", i + 1);
        hwtimer_set(HWTIMER_TICKS(delay), callback, (void *) msgn);
        printf("set %s\n", msgn);
    }

    puts("");
    puts("All timers set.");
    puts("");

    hwtimer_wait(HWTIMER_TICKS(1000UL * 1000UL));

    puts("hwtimer set.");
    thread_sleep();
    return 0;
}
Exemplo n.º 26
0
void srf02_start_ranging(uint16_t ranging_mode)
{
    uint32_t distance = 0;

    while (1) {
        distance = srf02_get_distance(ranging_mode);

        if (distance != UINT32_MAX) {
            switch (ranging_mode) {
                case SRF02_REAL_RANGING_MODE_CM :
                    printf("distance = %lu cm\n", distance);
                    break;

                case SRF02_REAL_RANGING_MODE_INCH :
                    printf("distance = %lu inch\n", distance);
                    break;

                case SRF02_REAL_RANGING_MODE_MICRO_SEC:
                    // dist_m = 0.000172 distance_micro_sec (air)
                    printf("distance = %lu micro_sec\n", distance);
                    break;

                case SRF02_FAKE_RANGING_MODE_CM:
                case SRF02_FAKE_RANGING_MODE_INCH:
                case SRF02_FAKE_RANGING_MODE_MICRO_SEC:
                    printf("distance fake ranging = %lu \n", distance);
                    break;

                default:
                    printf("distance = %lu cm\n", distance);
            }

            hwtimer_wait(HWTIMER_TICKS(50000));
        }
        else {
            break;
        }
    }

    puts("The SRF02 range sampling is ended!!");
}
Exemplo n.º 27
0
int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
{
    char pwr_1_setting, pwr_2_setting;

    if (dev->conf.accel_pwr == pwr_conf) {
        return 0;
    }

    /* Acquire exclusive access */
    if (i2c_acquire(dev->i2c_dev)) {
        return -1;
    }

    /* Read current power management 2 configuration */
    i2c_read_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, &pwr_2_setting);
    /* Prepare power register settings */
    if (pwr_conf == MPU9150_SENSOR_PWR_ON) {
        pwr_1_setting = MPU9150_PWR_WAKEUP;
        pwr_2_setting &= ~(MPU9150_PWR_ACCEL);
    }
    else {
        pwr_1_setting = BIT_PWR_MGMT1_SLEEP;
        pwr_2_setting |= MPU9150_PWR_ACCEL;
    }
    /* Configure power management 1 register if needed */
    if ((dev->conf.gyro_pwr == MPU9150_SENSOR_PWR_OFF)
            && (dev->conf.compass_pwr == MPU9150_SENSOR_PWR_OFF)) {
        i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_1_REG, pwr_1_setting);
    }
    /* Enable/disable accelerometer standby in power management 2 register */
    i2c_write_reg(dev->i2c_dev, dev->hw_addr, MPU9150_PWR_MGMT_2_REG, pwr_2_setting);

    /* Release the bus */
    i2c_release(dev->i2c_dev);

    dev->conf.accel_pwr = pwr_conf;
    hwtimer_wait(HWTIMER_TICKS(MPU9150_PWR_CHANGE_SLEEP_US));

    return 0;
}
Exemplo n.º 28
0
int pcd8544_init(pcd8544_t *dev, spi_t spi, gpio_t cs, gpio_t reset, gpio_t mode)
{
    /* save pin mapping */
    dev->spi = spi;
    dev->cs = cs;
    dev->reset = reset;
    dev->mode = mode;
    dev->inverted = 0;

    DEBUG("done setting dev members\n");

    /* initialze pins */
    gpio_init_out(cs, GPIO_NOPULL);
    gpio_init_out(reset, GPIO_NOPULL);
    gpio_init_out(mode, GPIO_NOPULL);
    DEBUG("done with gpios\n");
    /* clear CS line */
    gpio_set(cs);
    DEBUG("done clearing CS line\n");
    /* initialize SPI */
    spi_init_master(spi, SPI_CONF_FIRST_RISING, SPI_SPEED_1MHZ);
    DEBUG("done initializing SPI master\n");
    /* reset display */
    gpio_clear(reset);
    hwtimer_wait(RESET_DELAY);
    gpio_set(reset);

    /* clear display memory */
    pcd8544_clear(dev);
    /* write initialization sequence to display */
    pcd8544_set_contrast(dev, PCD8544_DEFAULT_CONTRAST);
    pcd8544_set_bias(dev, PCD8544_DEFAULT_BIAS);
    pcd8544_set_tempcoef(dev, PCD8544_DEFAULT_TEMPCOEF);
    /* enable display */
    _write(dev, MODE_CMD, CMD_ENABLE_H);
    _write(dev, MODE_CMD, CMD_MODE_NORMAL);
    return 0;
}
Exemplo n.º 29
0
void cc110x_rx_handler(void) {
    uint8_t res = 0;

	// Possible packet received, RX -> IDLE (0.1 us)
	rflags.CAA      = 0;
	rflags.MAN_WOR  = 0;
	cc110x_statistic.packets_in++;

	res = receive_packet((uint8_t*)&(cc110x_rx_buffer[rx_buffer_next].packet), sizeof(cc110x_packet_t));
	if (res) {
        // If we are sending a burst, don't accept packets.
		// Only ACKs are processed (for stopping the burst).
		// Same if state machine is in TX lock.
		if (radio_state == RADIO_SEND_BURST || rflags.TX)
		{
			cc110x_statistic.packets_in_while_tx++;
			return;
		}

        cc110x_rx_buffer[rx_buffer_next].rssi = rflags._RSSI;
        cc110x_rx_buffer[rx_buffer_next].lqi = rflags._LQI;
		cc110x_strobe(CC1100_SFRX);		// ...for flushing the RX FIFO

		// Valid packet. After a wake-up, the radio should be in IDLE.
		// So put CC1100 to RX for WOR_TIMEOUT (have to manually put
		// the radio back to sleep/WOR).
		//cc110x_spi_write_reg(CC1100_MCSM0, 0x08);	// Turn off FS-Autocal
		cc110x_write_reg(CC1100_MCSM2, 0x07);	// Configure RX_TIME (until end of packet)
        cc110x_strobe(CC1100_SRX);
        hwtimer_wait(IDLE_TO_RX_TIME);
        radio_state = RADIO_RX;
        
#ifdef DBG_IGNORE
        if (is_ignored(cc110x_rx_buffer[rx_buffer_next].packet.phy_src)) {
            LED_RED_TOGGLE;
            return;
        }
#endif

        /* notify transceiver thread if any */
        if (transceiver_pid) {
            msg_t m;  
            m.type = (uint16_t) RCV_PKT_CC1100;
            m.content.value = rx_buffer_next;
            msg_send_int(&m, transceiver_pid);
        }

        /* shift to next buffer element */
        if (++rx_buffer_next == RX_BUF_SIZE) {
            rx_buffer_next = 0;
        }
        return;
    }
	else
	{
		// No ACK received so TOF is unpredictable
		rflags.TOF = 0;

		// CRC false or RX buffer full -> clear RX FIFO in both cases
		cc110x_strobe(CC1100_SIDLE);	// Switch to IDLE (should already be)...
		cc110x_strobe(CC1100_SFRX);		// ...for flushing the RX FIFO

		// If packet interrupted this nodes send call,
		// don't change anything after this point.
		if (radio_state == RADIO_AIR_FREE_WAITING)
		{
			cc110x_strobe(CC1100_SRX);
			hwtimer_wait(IDLE_TO_RX_TIME);
			return;
		}
		// If currently sending, exit here (don't go to RX/WOR)
		if (radio_state == RADIO_SEND_BURST)
		{
			cc110x_statistic.packets_in_while_tx++;
			return;
		}

		// No valid packet, so go back to RX/WOR as soon as possible
		cc110x_switch_to_rx();
	}
}
Exemplo n.º 30
0
void ng_at86rf2xx_reset(ng_at86rf2xx_t *dev)
{
#if CPUID_ID_LEN
    uint8_t cpuid[CPUID_ID_LEN];
    eui64_t addr_long;
#endif

    /* trigger hardware reset */
    gpio_clear(dev->reset_pin);
    hwtimer_wait(HWTIMER_TICKS(RESET_DELAY));
    gpio_set(dev->reset_pin);
    /* reset options and sequence number */
    dev->seq_nr = 0;
    dev->options = 0;
    /* set short and long address */
#if CPUID_ID_LEN
    cpuid_get(cpuid);

#if CPUID_ID_LEN < 8
    /* in case CPUID_ID_LEN < 8, fill missing bytes with zeros */
    for (int i = CPUID_ID_LEN; i < 8; i++) {
        cpuid[i] = 0;
    }
#else
    for (int i = 8; i < CPUID_ID_LEN; i++) {
        cpuid[i & 0x07] ^= cpuid[i];
    }
#endif
    /* make sure we mark the address as non-multicast and not globally unique */
    cpuid[0] &= ~(0x01);
    cpuid[0] |= 0x02;
    /* copy and set long address */
    memcpy(&addr_long, cpuid, 8);
    ng_at86rf2xx_set_addr_long(dev, NTOHLL(addr_long.uint64.u64));
    ng_at86rf2xx_set_addr_short(dev, NTOHS(addr_long.uint16[0].u16));
#else
    ng_at86rf2xx_set_addr_long(dev, NG_AT86RF2XX_DEFAULT_ADDR_LONG);
    ng_at86rf2xx_set_addr_short(dev, NG_AT86RF2XX_DEFAULT_ADDR_SHORT);
#endif
    /* set default PAN id */
    ng_at86rf2xx_set_pan(dev, NG_AT86RF2XX_DEFAULT_PANID);
    /* set default channel */
    ng_at86rf2xx_set_chan(dev, NG_AT86RF2XX_DEFAULT_CHANNEL);
    /* set default TX power */
    ng_at86rf2xx_set_txpower(dev, NG_AT86RF2XX_DEFAULT_TXPOWER);
    /* set default options */
    ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_AUTOACK, true);
    ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_CSMA, true);
    ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_TELL_RX_START, false);
    ng_at86rf2xx_set_option(dev, NG_AT86RF2XX_OPT_TELL_RX_END, true);
    /* set default protocol */
#ifdef MODULE_NG_SIXLOWPAN
    dev->proto = NG_NETTYPE_SIXLOWPAN;
#else
    dev->proto = NG_NETTYPE_UNDEF;
#endif
    /* enable safe mode (protect RX FIFO until reading data starts) */
    ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__TRX_CTRL_2,
                          NG_AT86RF2XX_TRX_CTRL_2_MASK__RX_SAFE_MODE);
#ifdef MODULE_NG_AT86RF212B
    ng_at86rf2xx_set_freq(dev,NG_AT86RF2XX_FREQ_915MHZ);
#endif

    /* don't populate masked interrupt flags to IRQ_STATUS register */
    uint8_t tmp = ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__TRX_CTRL_1);
    tmp &= ~(NG_AT86RF2XX_TRX_CTRL_1_MASK__IRQ_MASK_MODE);
    ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__TRX_CTRL_1, tmp);

    /* enable interrupts */
    ng_at86rf2xx_reg_write(dev, NG_AT86RF2XX_REG__IRQ_MASK,
                          NG_AT86RF2XX_IRQ_STATUS_MASK__TRX_END);
    /* clear interrupt flags */
    ng_at86rf2xx_reg_read(dev, NG_AT86RF2XX_REG__IRQ_STATUS);

    /* go into RX state */
    ng_at86rf2xx_set_state(dev, NG_AT86RF2XX_STATE_RX_AACK_ON);

    DEBUG("ng_at86rf2xx_reset(): reset complete.\n");
}