From 3ba99aabe4c67ecbe42a8ac2980c503a53bc7935 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Mon, 28 Mar 2016 19:59:37 +0200 Subject: [PATCH 1/2] xbee: fix naming inconsistency --- drivers/include/xbee.h | 6 +++--- sys/auto_init/netif/auto_init_xbee.c | 2 +- tests/driver_xbee/xbee_params.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/include/xbee.h b/drivers/include/xbee.h index eea9d87e7c..293a900bb3 100644 --- a/drivers/include/xbee.h +++ b/drivers/include/xbee.h @@ -154,7 +154,7 @@ extern const gnrc_netdev_driver_t xbee_driver; * @param[in] baudrate baudrate to use * @param[in] sleep_pin GPIO pin that is connected to the SLEEP pin, set to * GPIO_UNDEF if not used - * @param[in] status_pin GPIO pin that is connected to the STATUS pin, set to + * @param[in] reset_pin GPIO pin that is connected to the STATUS pin, set to * GPIO_UNDEF if not used * * @return 0 on success @@ -162,7 +162,7 @@ extern const gnrc_netdev_driver_t xbee_driver; * @return -ENXIO on invalid UART or GPIO pins */ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, - gpio_t sleep_pin, gpio_t status_pin); + gpio_t sleep_pin, gpio_t reset_pin); /** * @brief auto_init struct holding Xbee device initalization params @@ -172,7 +172,7 @@ typedef struct xbee_params { uint32_t baudrate; /**< baudrate to use */ gpio_t sleep_pin; /**< GPIO pin that is connected to the SLEEP pin set to GPIO_UNDEF if not used */ - gpio_t status_pin; /**< GPIO pin that is connected to the STATUS pin + gpio_t reset_pin; /**< GPIO pin that is connected to the STATUS pin set to GPIO_UNDEF if not used */ } xbee_params_t; diff --git a/sys/auto_init/netif/auto_init_xbee.c b/sys/auto_init/netif/auto_init_xbee.c index 764c10f472..b7a106ac3b 100644 --- a/sys/auto_init/netif/auto_init_xbee.c +++ b/sys/auto_init/netif/auto_init_xbee.c @@ -54,7 +54,7 @@ void auto_init_xbee(void) p->uart, p->baudrate, p->sleep_pin, - p->status_pin); + p->reset_pin); if (res < 0) { DEBUG("Error initializing XBee radio device!"); diff --git a/tests/driver_xbee/xbee_params.h b/tests/driver_xbee/xbee_params.h index 11eb1f0fa4..6191583005 100644 --- a/tests/driver_xbee/xbee_params.h +++ b/tests/driver_xbee/xbee_params.h @@ -27,7 +27,7 @@ static xbee_params_t xbee_params[] = { { .uart = XBEE_UART, .baudrate = 9600U, .sleep_pin = GPIO_UNDEF, - .status_pin = GPIO_UNDEF + .reset_pin = GPIO_UNDEF }, }; From 59674a679b02d7f695bd5ed4f321ca2e555c5494 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Sun, 27 Mar 2016 21:36:00 +0200 Subject: [PATCH 2/2] netdev2: use params parameter for setup --- cpu/native/include/netdev2_tap.h | 14 +++-- cpu/native/netdev2_tap/netdev2_tap.c | 4 +- cpu/native/startup.c | 4 +- drivers/at86rf2xx/at86rf2xx.c | 12 ++--- drivers/at86rf2xx/at86rf2xx_getset.c | 2 +- drivers/at86rf2xx/at86rf2xx_internal.c | 62 +++++++++++------------ drivers/at86rf2xx/at86rf2xx_netdev.c | 14 ++--- drivers/encx24j600/encx24j600.c | 8 +-- drivers/ethos/ethos.c | 8 +-- drivers/include/at86rf2xx.h | 59 +++++++++------------ drivers/include/encx24j600.h | 17 +++++-- drivers/include/ethos.h | 17 +++++-- drivers/include/xbee.h | 34 +++++-------- drivers/xbee/xbee.c | 31 ++++++------ sys/auto_init/netif/auto_init_at86rf2xx.c | 8 +-- sys/auto_init/netif/auto_init_xbee.c | 6 +-- tests/driver_at86rf2xx/main.c | 3 +- 17 files changed, 146 insertions(+), 157 deletions(-) diff --git a/cpu/native/include/netdev2_tap.h b/cpu/native/include/netdev2_tap.h index b8f32e9bc9..39d8dd16a0 100644 --- a/cpu/native/include/netdev2_tap.h +++ b/cpu/native/include/netdev2_tap.h @@ -46,6 +46,14 @@ typedef struct netdev2_tap { uint8_t promiscous; /**< Flag for promiscous mode */ } netdev2_tap_t; +/** + * @brief tap interface initialization parameters + */ +typedef struct { + char **tap_name; /**< Name of the host system's tap + inteface to bind to. */ +} netdev2_tap_params_t; + /** * @brief global device struct. driver only supports one tap device as of now. */ @@ -54,10 +62,10 @@ extern netdev2_tap_t netdev2_tap; /** * @brief Setup netdev2_tap_t structure. * - * @param dev the preallocated netdev2_tap device handle to setup - * @param name Name of the host system's tap inteface to bind to. + * @param dev the preallocated netdev2_tap device handle to setup + * @param params initialization parameters */ -void netdev2_tap_setup(netdev2_tap_t *dev, const char *name); +void netdev2_tap_setup(netdev2_tap_t *dev, const netdev2_tap_params_t *params); /** * @brief Cleanup tap resources diff --git a/cpu/native/netdev2_tap/netdev2_tap.c b/cpu/native/netdev2_tap/netdev2_tap.c index 7d3c065281..2bc69fc874 100644 --- a/cpu/native/netdev2_tap/netdev2_tap.c +++ b/cpu/native/netdev2_tap/netdev2_tap.c @@ -265,9 +265,9 @@ static int _send(netdev2_t *netdev, const struct iovec *vector, int n) return _native_writev(dev->tap_fd, vector, n); } -void netdev2_tap_setup(netdev2_tap_t *dev, const char *name) { +void netdev2_tap_setup(netdev2_tap_t *dev, const netdev2_tap_params_t *params) { dev->netdev.driver = &netdev2_driver_tap; - strncpy(dev->tap_name, name, IFNAMSIZ); + strncpy(dev->tap_name, *(params->tap_name), IFNAMSIZ); } static void _tap_isr(void) { diff --git a/cpu/native/startup.c b/cpu/native/startup.c index 42b0edc013..28360ce9ab 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -313,7 +313,9 @@ __attribute__((constructor)) static void startup(int argc, char **argv) native_cpu_init(); native_interrupt_init(); #ifdef MODULE_NETDEV2_TAP - netdev2_tap_setup(&netdev2_tap, argv[1]); + netdev2_tap_params_t p; + p.tap_name = &(argv[1]); + netdev2_tap_setup(&netdev2_tap, &p); #endif board_init(); diff --git a/drivers/at86rf2xx/at86rf2xx.c b/drivers/at86rf2xx/at86rf2xx.c index 4b9159228d..b418433327 100644 --- a/drivers/at86rf2xx/at86rf2xx.c +++ b/drivers/at86rf2xx/at86rf2xx.c @@ -35,23 +35,17 @@ #include "debug.h" -void at86rf2xx_setup(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed, - gpio_t cs_pin, gpio_t int_pin, gpio_t sleep_pin, - gpio_t reset_pin) +void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params) { netdev2_t *netdev = (netdev2_t *)dev; netdev->driver = &at86rf2xx_driver; /* initialize device descriptor */ - dev->spi = spi; - dev->cs_pin = cs_pin; - dev->int_pin = int_pin; - dev->sleep_pin = sleep_pin; - dev->reset_pin = reset_pin; + memcpy(&dev->params, params, sizeof(at86rf2xx_params_t)); dev->idle_state = AT86RF2XX_STATE_TRX_OFF; dev->state = AT86RF2XX_STATE_SLEEP; /* initialise SPI */ - spi_init_master(dev->spi, SPI_CONF_FIRST_RISING, spi_speed); + spi_init_master(dev->params.spi, SPI_CONF_FIRST_RISING, params->spi_speed); } void at86rf2xx_reset(at86rf2xx_t *dev) diff --git a/drivers/at86rf2xx/at86rf2xx_getset.c b/drivers/at86rf2xx/at86rf2xx_getset.c index 4fb4ae5d97..80383e7f34 100644 --- a/drivers/at86rf2xx/at86rf2xx_getset.c +++ b/drivers/at86rf2xx/at86rf2xx_getset.c @@ -455,7 +455,7 @@ void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state) /* Discard all IRQ flags, framebuffer is lost anyway */ at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS); /* Go to SLEEP mode from TRX_OFF */ - gpio_set(dev->sleep_pin); + gpio_set(dev->params.sleep_pin); dev->state = state; } else { _set_state(dev, state); diff --git a/drivers/at86rf2xx/at86rf2xx_internal.c b/drivers/at86rf2xx/at86rf2xx_internal.c index 11c78bd511..610750f917 100644 --- a/drivers/at86rf2xx/at86rf2xx_internal.c +++ b/drivers/at86rf2xx/at86rf2xx_internal.c @@ -32,26 +32,26 @@ void at86rf2xx_reg_write(const at86rf2xx_t *dev, const uint8_t addr, const uint8_t value) { - spi_acquire(dev->spi); - gpio_clear(dev->cs_pin); - spi_transfer_reg(dev->spi, + spi_acquire(dev->params.spi); + gpio_clear(dev->params.cs_pin); + spi_transfer_reg(dev->params.spi, AT86RF2XX_ACCESS_REG | AT86RF2XX_ACCESS_WRITE | addr, value, 0); - gpio_set(dev->cs_pin); - spi_release(dev->spi); + gpio_set(dev->params.cs_pin); + spi_release(dev->params.spi); } uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, const uint8_t addr) { char value; - spi_acquire(dev->spi); - gpio_clear(dev->cs_pin); - spi_transfer_reg(dev->spi, + spi_acquire(dev->params.spi); + gpio_clear(dev->params.cs_pin); + spi_transfer_reg(dev->params.spi, AT86RF2XX_ACCESS_REG | AT86RF2XX_ACCESS_READ | addr, 0, &value); - gpio_set(dev->cs_pin); - spi_release(dev->spi); + gpio_set(dev->params.cs_pin); + spi_release(dev->params.spi); return (uint8_t)value; } @@ -61,14 +61,14 @@ void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t *data, const size_t len) { - spi_acquire(dev->spi); - gpio_clear(dev->cs_pin); - spi_transfer_reg(dev->spi, + spi_acquire(dev->params.spi); + gpio_clear(dev->params.cs_pin); + spi_transfer_reg(dev->params.spi, AT86RF2XX_ACCESS_SRAM | AT86RF2XX_ACCESS_READ, (char)offset, NULL); - spi_transfer_bytes(dev->spi, NULL, (char *)data, len); - gpio_set(dev->cs_pin); - spi_release(dev->spi); + spi_transfer_bytes(dev->params.spi, NULL, (char *)data, len); + gpio_set(dev->params.cs_pin); + spi_release(dev->params.spi); } void at86rf2xx_sram_write(const at86rf2xx_t *dev, @@ -76,21 +76,21 @@ void at86rf2xx_sram_write(const at86rf2xx_t *dev, const uint8_t *data, const size_t len) { - spi_acquire(dev->spi); - gpio_clear(dev->cs_pin); - spi_transfer_reg(dev->spi, + spi_acquire(dev->params.spi); + gpio_clear(dev->params.cs_pin); + spi_transfer_reg(dev->params.spi, AT86RF2XX_ACCESS_SRAM | AT86RF2XX_ACCESS_WRITE, (char)offset, NULL); - spi_transfer_bytes(dev->spi, (char *)data, NULL, len); - gpio_set(dev->cs_pin); - spi_release(dev->spi); + spi_transfer_bytes(dev->params.spi, (char *)data, NULL, len); + gpio_set(dev->params.cs_pin); + spi_release(dev->params.spi); } void at86rf2xx_fb_start(const at86rf2xx_t *dev) { - spi_acquire(dev->spi); - gpio_clear(dev->cs_pin); - spi_transfer_byte(dev->spi, + spi_acquire(dev->params.spi); + gpio_clear(dev->params.cs_pin); + spi_transfer_byte(dev->params.spi, AT86RF2XX_ACCESS_FB | AT86RF2XX_ACCESS_READ, NULL); } @@ -99,13 +99,13 @@ void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, const size_t len) { - spi_transfer_bytes(dev->spi, NULL, (char *)data, len); + spi_transfer_bytes(dev->params.spi, NULL, (char *)data, len); } void at86rf2xx_fb_stop(const at86rf2xx_t *dev) { - gpio_set(dev->cs_pin); - spi_release(dev->spi); + gpio_set(dev->params.cs_pin); + spi_release(dev->params.spi); } uint8_t at86rf2xx_get_status(const at86rf2xx_t *dev) @@ -123,7 +123,7 @@ void at86rf2xx_assert_awake(at86rf2xx_t *dev) if(at86rf2xx_get_status(dev) == AT86RF2XX_STATE_SLEEP) { /* wake up and wait for transition to TRX_OFF */ - gpio_clear(dev->sleep_pin); + gpio_clear(dev->params.sleep_pin); xtimer_usleep(AT86RF2XX_WAKEUP_DELAY); /* update state */ @@ -138,9 +138,9 @@ void at86rf2xx_hardware_reset(at86rf2xx_t *dev) at86rf2xx_assert_awake(dev); /* trigger hardware reset */ - gpio_clear(dev->reset_pin); + gpio_clear(dev->params.reset_pin); xtimer_usleep(AT86RF2XX_RESET_PULSE_WIDTH); - gpio_set(dev->reset_pin); + gpio_set(dev->params.reset_pin); xtimer_usleep(AT86RF2XX_RESET_DELAY); } diff --git a/drivers/at86rf2xx/at86rf2xx_netdev.c b/drivers/at86rf2xx/at86rf2xx_netdev.c index 488ed33d25..49baf60b77 100644 --- a/drivers/at86rf2xx/at86rf2xx_netdev.c +++ b/drivers/at86rf2xx/at86rf2xx_netdev.c @@ -69,13 +69,13 @@ static int _init(netdev2_t *netdev) at86rf2xx_t *dev = (at86rf2xx_t *)netdev; /* initialise GPIOs */ - gpio_init(dev->cs_pin, GPIO_OUT); - gpio_set(dev->cs_pin); - gpio_init(dev->sleep_pin, GPIO_OUT); - gpio_clear(dev->sleep_pin); - gpio_init(dev->reset_pin, GPIO_OUT); - gpio_set(dev->reset_pin); - gpio_init_int(dev->int_pin, GPIO_IN, GPIO_RISING, _irq_handler, dev); + gpio_init(dev->params.cs_pin, GPIO_OUT); + gpio_set(dev->params.cs_pin); + gpio_init(dev->params.sleep_pin, GPIO_OUT); + gpio_clear(dev->params.sleep_pin); + gpio_init(dev->params.reset_pin, GPIO_OUT); + gpio_set(dev->params.reset_pin); + gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, _irq_handler, dev); /* make sure device is not sleeping, so we can query part number */ at86rf2xx_assert_awake(dev); diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index cf7c079be1..1c855eb0ba 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -82,12 +82,12 @@ static inline void unlock(encx24j600_t *dev) { mutex_unlock(&dev->mutex); } -void encx24j600_setup(encx24j600_t *dev, spi_t spi, gpio_t cs, gpio_t int_pin) +void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params) { dev->netdev.driver = &netdev2_driver_encx24j600; - dev->spi = spi; - dev->cs = cs; - dev->int_pin = int_pin; + dev->spi = params->spi; + dev->cs = params->cs; + dev->int_pin = params->int_pin; dev->rx_next_ptr = RX_BUFFER_START; mutex_init(&dev->mutex); diff --git a/drivers/ethos/ethos.c b/drivers/ethos/ethos.c index ff233a4006..835cfaa448 100644 --- a/drivers/ethos/ethos.c +++ b/drivers/ethos/ethos.c @@ -47,16 +47,16 @@ static const uint8_t _esc_esc[] = {ETHOS_ESC_CHAR, (ETHOS_ESC_CHAR ^ 0x20)}; static const uint8_t _esc_delim[] = {ETHOS_ESC_CHAR, (ETHOS_FRAME_DELIMITER ^ 0x20)}; -void ethos_setup(ethos_t *dev, uart_t uart, uint32_t baudrate, uint8_t *buf, size_t bufsize) +void ethos_setup(ethos_t *dev, const ethos_params_t *params) { dev->netdev.driver = &netdev2_driver_ethos; - dev->uart = uart; + dev->uart = params->uart; dev->state = WAIT_FRAMESTART; dev->framesize = 0; dev->frametype = 0; dev->last_framesize = 0; - tsrb_init(&dev->inbuf, (char*)buf, bufsize); + tsrb_init(&dev->inbuf, (char*)params->buf, params->bufsize); mutex_init(&dev->out_mutex); uint32_t a = random_uint32(); @@ -67,7 +67,7 @@ void ethos_setup(ethos_t *dev, uart_t uart, uint32_t baudrate, uint8_t *buf, siz dev->mac_addr[0] &= (0x2); /* unset globally unique bit */ dev->mac_addr[0] &= ~(0x1); /* set unicast bit*/ - uart_init(uart, baudrate, ethos_isr, (void*)dev); + uart_init(params->uart, params->baudrate, ethos_isr, (void*)dev); uint8_t frame_delim = ETHOS_FRAME_DELIMITER; uart_write(dev->uart, &frame_delim, 1); diff --git a/drivers/include/at86rf2xx.h b/drivers/include/at86rf2xx.h index ede06f710f..79c5b88e6f 100644 --- a/drivers/include/at86rf2xx.h +++ b/drivers/include/at86rf2xx.h @@ -132,32 +132,6 @@ extern "C" { * finished */ /** @} */ -/** - * @brief Device descriptor for AT86RF2XX radio devices - * - * @extends netdev2_ieee802154_t - */ -typedef struct { - netdev2_ieee802154_t netdev; /**< netdev2 parent struct */ - /** - * @brief device specific fields - * @{ - */ - spi_t spi; /**< used SPI device */ - gpio_t cs_pin; /**< chip select pin */ - gpio_t sleep_pin; /**< sleep pin */ - gpio_t reset_pin; /**< reset pin */ - gpio_t int_pin; /**< external interrupt pin */ - uint8_t state; /**< current state of the radio */ - uint8_t tx_frame_len; /**< length of the current TX frame */ -#ifdef MODULE_AT86RF212B - /* Only AT86RF212B supports multiple pages (PHY modes) */ - uint8_t page; /**< currently used channel page */ -#endif - uint8_t idle_state; /**< state to return to after sending */ - /** @} */ -} at86rf2xx_t; - /** * @brief struct holding all params needed for device initialization */ @@ -170,20 +144,35 @@ typedef struct at86rf2xx_params { gpio_t reset_pin; /**< GPIO pin connected to the reset pin */ } at86rf2xx_params_t; +/** + * @brief Device descriptor for AT86RF2XX radio devices + * + * @extends netdev2_ieee802154_t + */ +typedef struct { + netdev2_ieee802154_t netdev; /**< netdev2 parent struct */ + /** + * @brief device specific fields + * @{ + */ + at86rf2xx_params_t params; /**< parameters for initialization */ + uint8_t state; /**< current state of the radio */ + uint8_t tx_frame_len; /**< length of the current TX frame */ +#ifdef MODULE_AT86RF212B + /* Only AT86RF212B supports multiple pages (PHY modes) */ + uint8_t page; /**< currently used channel page */ +#endif + uint8_t idle_state; /**< state to return to after sending */ + /** @} */ +} at86rf2xx_t; + /** * @brief Setup an AT86RF2xx based device state * * @param[out] dev device descriptor - * @param[in] spi SPI bus the device is connected to - * @param[in] spi_speed SPI speed to use - * @param[in] cs_pin GPIO pin connected to chip select - * @param[in] int_pin GPIO pin connected to the interrupt pin - * @param[in] sleep_pin GPIO pin connected to the sleep pin - * @param[in] reset_pin GPIO pin connected to the reset pin + * @param[in] params parameters for device initialization */ -void at86rf2xx_setup(at86rf2xx_t *dev, spi_t spi, spi_speed_t spi_speed, - gpio_t cs_pin, gpio_t int_pin, gpio_t sleep_pin, - gpio_t reset_pin); +void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params); /** * @brief Trigger a hardware reset and configure radio with default values diff --git a/drivers/include/encx24j600.h b/drivers/include/encx24j600.h index d8317c8443..683b6c1efc 100644 --- a/drivers/include/encx24j600.h +++ b/drivers/include/encx24j600.h @@ -44,18 +44,25 @@ typedef struct { mutex_t mutex; /**< mutex used to lock device access */ } encx24j600_t; +/** + * @brief Struct containing the needed peripheral configuration + */ +typedef struct { + spi_t spi; /**< SPI line */ + gpio_t cs_pin; /**< chip select pin */ + gpio_t int_pin; /**< interrupt pin */ +} encx24j600_params_t; + /** * @brief Setup an encx24j600 based device state. * * This function sets SPI pins, initializes the device state structure. * It does not initialize the device itself. * - * @param[out] dev the handle of the device to initialize - * @param[in] spi SPI device the device is connected to - * @param[in] cs_pin SPI chip select pin used to select the device - * @param[in] int_pin pin the device will trigger an interrupt on + * @param[out] dev the handle of the device to initialize + * @param[in] params parameters for device initialization */ -void encx24j600_setup(encx24j600_t *dev, spi_t spi, gpio_t cs_pin, gpio_t int_pin); +void encx24j600_setup(encx24j600_t *dev, const encx24j600_params_t *params); #ifdef __cplusplus } diff --git a/drivers/include/ethos.h b/drivers/include/ethos.h index 061d79ae96..9d9db0480d 100644 --- a/drivers/include/ethos.h +++ b/drivers/include/ethos.h @@ -80,6 +80,16 @@ typedef struct { mutex_t out_mutex; /**< mutex used for locking concurrent sends */ } ethos_t; +/** + * @brief Struct containing the needed configuration + */ +typedef struct { + uart_t uart; /**< UART device to use */ + uint32_t baudrate; /**< baudrate to UART device */ + uint8_t buf; /**< buffer for incoming packets */ + size_t bufsize; /**< size of ethos_params_t::buf */ +} ethos_params_t; + /** * @brief Setup an ethos based device state. * @@ -90,12 +100,9 @@ typedef struct { * E.g., if 1536b ethernet frames are expected, 2048 is probably a good size for @p buf. * * @param[out] dev handle of the device to initialize - * @param[in] uart UART device to use - * @param[in] baudrate baudrate for UART device - * @param[in] buf buffer for incoming packets - * @param[in] bufsize size of @p buf + * @param[in] params parameters for device initialization */ -void ethos_setup(ethos_t *dev, uart_t uart, uint32_t baudrate, uint8_t *buf, size_t bufsize); +void ethos_setup(ethos_t *dev, const ethos_params_t *params); /** * @brief send frame over serial port using ethos' framing diff --git a/drivers/include/xbee.h b/drivers/include/xbee.h index 293a900bb3..a146536915 100644 --- a/drivers/include/xbee.h +++ b/drivers/include/xbee.h @@ -141,6 +141,18 @@ typedef struct { uint16_t rx_limit; /**< size RX frame transferred */ } xbee_t; +/** + * @brief auto_init struct holding Xbee device initalization params + */ +typedef struct xbee_params { + uart_t uart; /**< UART interfaced the device is connected to */ + uint32_t baudrate; /**< baudrate to use */ + gpio_t sleep_pin; /**< GPIO pin that is connected to the SLEEP pin + set to GPIO_UNDEF if not used */ + gpio_t reset_pin; /**< GPIO pin that is connected to the STATUS pin + set to GPIO_UNDEF if not used */ +} xbee_params_t; + /** * @brief Reference to the XBee driver interface */ @@ -150,31 +162,13 @@ extern const gnrc_netdev_driver_t xbee_driver; * @brief Initialize the given Xbee device * * @param[out] dev Xbee device to initialize - * @param[in] uart UART interfaced the device is connected to - * @param[in] baudrate baudrate to use - * @param[in] sleep_pin GPIO pin that is connected to the SLEEP pin, set to - * GPIO_UNDEF if not used - * @param[in] reset_pin GPIO pin that is connected to the STATUS pin, set to - * GPIO_UNDEF if not used + * @param[in] params parameters for device initialization * * @return 0 on success * @return -ENODEV on invalid device descriptor * @return -ENXIO on invalid UART or GPIO pins */ -int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, - gpio_t sleep_pin, gpio_t reset_pin); - -/** - * @brief auto_init struct holding Xbee device initalization params - */ -typedef struct xbee_params { - uart_t uart; /**< UART interfaced the device is connected to */ - uint32_t baudrate; /**< baudrate to use */ - gpio_t sleep_pin; /**< GPIO pin that is connected to the SLEEP pin - set to GPIO_UNDEF if not used */ - gpio_t reset_pin; /**< GPIO pin that is connected to the STATUS pin - set to GPIO_UNDEF if not used */ -} xbee_params_t; +int xbee_init(xbee_t *dev, const xbee_params_t *params); #ifdef __cplusplus } diff --git a/drivers/xbee/xbee.c b/drivers/xbee/xbee.c index 234413a13a..09f03b68cd 100644 --- a/drivers/xbee/xbee.c +++ b/drivers/xbee/xbee.c @@ -395,8 +395,7 @@ static int _set_proto(xbee_t *dev, uint8_t *val, size_t len) /* * Driver's "public" functions */ -int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, - gpio_t reset_pin, gpio_t sleep_pin) +int xbee_init(xbee_t *dev, const xbee_params_t *params) { uint8_t tmp[2]; @@ -404,15 +403,15 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, if (dev == NULL) { return -ENODEV; } - if (uart >= UART_NUMOF) { + if (params->uart >= UART_NUMOF) { return -ENXIO; } /* set device driver */ dev->driver = &xbee_driver; /* set peripherals to use */ - dev->uart = uart; - dev->reset_pin = reset_pin; - dev->sleep_pin = sleep_pin; + dev->uart = params->uart; + dev->reset_pin = params->reset_pin; + dev->sleep_pin = params->sleep_pin; /* set default options */ dev->addr_flags = 0; dev->proto = XBEE_DEFAULT_PROTOCOL; @@ -423,29 +422,29 @@ int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate, dev->resp_limit = 1; /* needs to be greater then 0 initially */ dev->rx_count = 0; /* initialize UART and GPIO pins */ - if (uart_init(uart, baudrate, _rx_cb, dev) < 0) { + if (uart_init(params->uart, params->baudrate, _rx_cb, dev) < 0) { DEBUG("xbee: Error initializing UART\n"); return -ENXIO; } - if (reset_pin != GPIO_UNDEF) { - if (gpio_init(reset_pin, GPIO_OUT) < 0) { + if (params->reset_pin != GPIO_UNDEF) { + if (gpio_init(params->reset_pin, GPIO_OUT) < 0) { DEBUG("xbee: Error initializing RESET pin\n"); return -ENXIO; } - gpio_set(reset_pin); + gpio_set(params->reset_pin); } - if (sleep_pin != GPIO_UNDEF) { - if (gpio_init(sleep_pin, GPIO_OUT) < 0) { + if (params->sleep_pin != GPIO_UNDEF) { + if (gpio_init(params->sleep_pin, GPIO_OUT) < 0) { DEBUG("xbee: Error initializing SLEEP pin\n"); return -ENXIO; } - gpio_clear(sleep_pin); + gpio_clear(params->sleep_pin); } /* if reset pin is connected, do a hardware reset */ - if (reset_pin != GPIO_UNDEF) { - gpio_clear(reset_pin); + if (params->reset_pin != GPIO_UNDEF) { + gpio_clear(params->reset_pin); xtimer_usleep(RESET_DELAY); - gpio_set(reset_pin); + gpio_set(params->reset_pin); } /* put the XBee device into command mode */ xtimer_usleep(ENTER_CMD_MODE_DELAY); diff --git a/sys/auto_init/netif/auto_init_at86rf2xx.c b/sys/auto_init/netif/auto_init_at86rf2xx.c index 775d9f9b06..9eb1d1e3a7 100644 --- a/sys/auto_init/netif/auto_init_at86rf2xx.c +++ b/sys/auto_init/netif/auto_init_at86rf2xx.c @@ -50,13 +50,7 @@ void auto_init_at86rf2xx(void) int res; DEBUG("Initializing AT86RF2xx radio at SPI_%i\n", p->spi); - at86rf2xx_setup(&at86rf2xx_devs[i], - p->spi, - p->spi_speed, - p->cs_pin, - p->int_pin, - p->sleep_pin, - p->reset_pin); + at86rf2xx_setup(&at86rf2xx_devs[i], (at86rf2xx_params_t*) p); res = gnrc_netdev2_ieee802154_init(&gnrc_adpt[i], (netdev2_ieee802154_t *)&at86rf2xx_devs[i]); diff --git a/sys/auto_init/netif/auto_init_xbee.c b/sys/auto_init/netif/auto_init_xbee.c index b7a106ac3b..73c15dc3b0 100644 --- a/sys/auto_init/netif/auto_init_xbee.c +++ b/sys/auto_init/netif/auto_init_xbee.c @@ -50,11 +50,7 @@ void auto_init_xbee(void) for (size_t i = 0; i < XBEE_NUM; i++) { const xbee_params_t *p = &xbee_params[i]; DEBUG("Initializing XBee radio at UART_%i\n", p->uart); - int res = xbee_init(&xbee_devs[i], - p->uart, - p->baudrate, - p->sleep_pin, - p->reset_pin); + int res = xbee_init(&xbee_devs[i], (xbee_params_t*) p); if (res < 0) { DEBUG("Error initializing XBee radio device!"); diff --git a/tests/driver_at86rf2xx/main.c b/tests/driver_at86rf2xx/main.c index 1be7bfb5bb..59416db368 100644 --- a/tests/driver_at86rf2xx/main.c +++ b/tests/driver_at86rf2xx/main.c @@ -96,8 +96,7 @@ int main(void) netdev2_t *dev = (netdev2_t *)(&devs[i]); printf("Initializing AT86RF2xx radio at SPI_%d\n", p->spi); - at86rf2xx_setup(&devs[i], p->spi, p->spi_speed, p->cs_pin, - p->int_pin, p->sleep_pin, p->reset_pin); + at86rf2xx_setup(&devs[i], (at86rf2xx_params_t*) p); dev->event_callback = _event_cb; dev->driver->init(dev); }