Example #1
0
static int _set(netdev2_t *dev, netopt_t opt, void *value, size_t value_len)
{
    cc110x_t *cc110x = &((netdev2_cc110x_t*) dev)->cc110x;

    switch (opt) {
        case NETOPT_CHANNEL:
            {
                uint8_t *arg = (uint8_t*)value;
                uint8_t channel = arg[value_len-1];
                if ((channel < CC110X_MIN_CHANNR) || (channel > CC110X_MAX_CHANNR)) {
                    return -EINVAL;
                }
                if (cc110x_set_channel(cc110x, channel) == -1) {
                    return -EINVAL;
                }
                return 1;
            }
        case NETOPT_ADDRESS:
            if (value_len < 1) {
                return -EINVAL;
            }
            if (!cc110x_set_address(cc110x, *(uint8_t*)value)) {
                return -EINVAL;
            }
            return 1;
        default:
            return -ENOTSUP;
    }

    return 0;
}
Example #2
0
void set_radio_chann(char *str){
    uint16_t chann;
    int res = sscanf(str, "set_chann %hu", &chann);
    if(res < 1){
        printf("Usage: set_chann [channel]\n");
    }

    cc110x_set_channel(chann);
}
Example #3
0
int16_t cc110x_set_config_channel(uint8_t channr)
{
    int16_t c = cc110x_set_channel(channr);

    if(c) {
        sysconfig.radio_channel = c;
    }

    config_save();
    return c;
}
Example #4
0
/*---------------------------------------------------------------------------*
 * 								Radio Driver API                             *
 *---------------------------------------------------------------------------*/
void cc110x_init(int tpid)
{
    transceiver_pid = tpid;
    DEBUG("Transceiver PID: %i\n", transceiver_pid);

    rx_buffer_next = 0;

#ifdef MODULE_CC110X_SPI
    /* Initialize SPI */
    cc110x_spi_init();
#endif

    /* Load driver & reset */
    power_up_reset();

    /* Write configuration to configuration registers */
    cc110x_writeburst_reg(0x00, cc110x_conf, CC1100_CONF_SIZE);

    /* Write PATABLE (power settings) */
    cc110x_write_reg(CC1100_PATABLE, pa_table[pa_table_index]);

    /* Initialize Radio Flags */
    rflags._RSSI         = 0x00;
    rflags.LL_ACK       = 0;
    rflags.CAA          = 0;
    rflags.CRC_STATE    = 0;
    rflags.SEQ          = 0;
    rflags.MAN_WOR      = 0;
    rflags.KT_RES_ERR   = 0;
    rflags.TX           = 0;
    rflags.WOR_RST      = 0;

    /* Set default channel number */
#ifdef MODULE_CONFIG
    cc110x_set_config_channel(sysconfig.radio_channel);
#else
    cc110x_set_channel(CC1100_DEFAULT_CHANNR);
#endif
    DEBUG("CC1100 initialized and set to channel %i\n", radio_channel);

    /* Switch to desired mode (WOR or RX) */
    rd_set_mode(RADIO_MODE_ON);

#ifdef DBG_IGNORE
    cc110x_init_ignore();
#endif
}
Example #5
0
static int _set(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
{
    cc110x_t *cc110x = &((netdev_cc110x_t*) dev)->cc110x;

    switch (opt) {
        case NETOPT_CHANNEL:
            {
                const uint8_t *arg = value;
                uint8_t channel = arg[value_len-1];
            #if CC110X_MIN_CHANNR
                if (channel < CC110X_MIN_CHANNR) {
                    return -EINVAL;
                }
            #endif /* CC110X_MIN_CHANNR */
                if (channel > CC110X_MAX_CHANNR) {
                    return -EINVAL;
                }
                if (cc110x_set_channel(cc110x, channel) == -1) {
                    return -EINVAL;
                }
                return 1;
            }
        case NETOPT_ADDRESS:
            if (value_len < 1) {
                return -EINVAL;
            }
            if (!cc110x_set_address(cc110x, *(const uint8_t*)value)) {
                return -EINVAL;
            }
            return 1;
#ifdef MODULE_GNRC_NETIF
        case NETOPT_PROTO:
            if (value_len != sizeof(gnrc_nettype_t)) {
                return -EINVAL;
            }
            else {
                cc110x->proto = (gnrc_nettype_t) value;
                return sizeof(gnrc_nettype_t);
            }
            break;
#endif
        default:
            return -ENOTSUP;
    }

    return 0;
}
Example #6
0
/*
 * @brief Sets the radio channel for any transceiver device
 *
 * @param t         The transceiver device
 * @param channel   The channel to be set
 *
 * @return The radio channel AFTER calling the set command, -1 on error
 */
static int32_t set_channel(transceiver_type_t t, void *channel)
{
    /* cppcheck: c is read depending on enabled modules */
    /* cppcheck-suppress unreadVariable */
    uint8_t c = *((uint8_t *)channel);

    switch (t) {
        case TRANSCEIVER_CC1100:
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY))
            return cc110x_set_channel(c);
#elif MODULE_CC110X_LEGACY_CSMA
            return cc1100_set_channel(c);
#else
            return -1;
#endif
#ifdef MODULE_CC2420

        case TRANSCEIVER_CC2420:
            return cc2420_set_channel(c);
#endif
#ifdef MODULE_MC1322X

        case TRANSCEIVER_MC1322X:
            maca_set_channel(c);
            return c; ///< TODO: should be changed!implement get channel
#endif
#ifdef MODULE_NATIVENET

        case TRANSCEIVER_NATIVE:
            return nativenet_set_channel(c);
#endif
#ifdef MODULE_AT86RF231

        case TRANSCEIVER_AT86RF231:
            return at86rf231_set_channel(c);
#endif

        default:
            return -1;
    }
}
Example #7
0
int _cc110x_set_option(netdev_t *dev, netdev_opt_t opt, void *value, size_t value_len)
{
    if (dev != &cc110x_dev) {
        return -ENODEV;
    }

    switch (opt) {
        case NETDEV_OPT_CHANNEL:
            if (value_len != sizeof(uint8_t)) {
                return -EOVERFLOW;
            }
            if (cc110x_set_channel(*((uint8_t *)value)) == -1) {
                return -EINVAL;
            }
            break;
        case NETDEV_OPT_ADDRESS:
            /* leaves room for optimization */
            if (value_len > sizeof(radio_address_t)) {
                return -EOVERFLOW;
            }
            radio_address_t temp_address;
            if (value_len == sizeof(uint8_t)) {
                temp_address = ((radio_address_t)(*((uint8_t *)value)));
            }
            else {
                temp_address = *((radio_address_t *)value);
            }
            if (!cc110x_set_address(temp_address)) {
                return -EINVAL;
            }
            break;
        default:
            return -ENOTSUP;
    }

    return 0;
}