2222#ifndef MKW2XDRF_H_
2323#define MKW2XDRF_H_
2424
25+ #include <stdint.h>
26+
27+ #include "board.h"
28+ #include "periph/spi.h"
29+ #include "periph/gpio.h"
2530#include "net/ng_netdev.h"
2631
2732#ifdef __cplusplus
2833extern "C" {
2934#endif
3035
3136/**
32- * @brief Maximum packet length, including XBee API frame overhead
37+ * @brief Maximum packet length
3338 */
3439#define KW2XRF_MAX_PKT_LENGTH (127U)
3540
@@ -47,58 +52,90 @@ extern "C" {
4752 */
4853#define KW2XRF_DEFAULT_SHORT_ADDR (0x0002)
4954
55+ /**
56+ * @brief Default short address used after initialization
57+ */
58+ #define KW2XRF_DEFAULT_ADDR_LONG (0x0000000000000000)
59+
5060/**
5161 * @brief Default PAN ID used after initialization
5262 */
53- #define KW2XRF_DEFAULT_PANID (0x0001 )
63+ #define KW2XRF_DEFAULT_PANID (0x0023 )
5464
5565/**
5666 * @brief Default channel used after initialization
5767 */
58- #define KW2XRF_DEFAULT_CHANNEL (13U)
68+ #define KW2XRF_DEFAULT_CHANNEL (17U)
69+
70+ /**
71+ * @brief Default TX_POWER in dbm used after initialization
72+ */
73+ #define KW2XRF_DEFAULT_TX_POWER (0)
5974
6075/**
6176 * @brief Maximum output power of the kw2x device in dBm
6277 */
63- #define MKW2XDRF_OUTPUT_POWER_MAX 8
78+ #define MKW2XDRF_OUTPUT_POWER_MAX (8)
6479
6580/**
6681 * @brief Minimum output power of the kw2x device in dBm
6782 */
68- #define MKW2XDRF_OUTPUT_POWER_MIN (-35)
83+ #define MKW2XDRF_OUTPUT_POWER_MIN (-35)
84+
85+ /**
86+ * @brief Internal device option flags
87+ * @{
88+ */
89+ #define KW2XRF_OPT_AUTOACK (0x0001) /**< auto ACKs active */
90+ #define KW2XRF_OPT_CSMA (0x0002) /**< CSMA active */
91+ #define KW2XRF_OPT_PROMISCUOUS (0x0004) /**< promiscuous mode active */
92+ #define KW2XRF_OPT_PRELOADING (0x0008) /**< preloading enabled */
93+ #define KW2XRF_OPT_TELL_TX_START (0x0010) /**< notify MAC layer on TX start */
94+ #define KW2XRF_OPT_TELL_TX_END (0x0020) /**< notify MAC layer on TX finished */
95+ #define KW2XRF_OPT_TELL_RX_START (0x0040) /**< notify MAC layer on RX start */
96+ #define KW2XRF_OPT_TELL_RX_END (0x0080) /**< notify MAC layer on RX finished */
97+ #define KW2XRF_OPT_RAWDUMP (0x0100) /**< pass RAW frame data to upper layer */
98+ #define KW2XRF_OPT_SRC_ADDR_LONG (0x0200) /**< send data using long source address */
99+ #define KW2XRF_OPT_USE_SRC_PAN (0x0400) /**< do not compress source PAN ID */
100+ /** @} */
69101
70102/**
71103 * @brief kw2xrf device descriptor
72104 */
73105typedef struct {
74106 /* netdev fields */
75- ng_netdev_driver_t const * driver ; /**< pointer to the devices interface */
76- ng_netdev_event_cb_t event_cb ; /**< netdev event callback */
77- kernel_pid_t mac_pid ; /**< the driver's thread's PID */
78- /* Devide driver specific fields */
79- uint8_t buf [KW2XRF_MAX_PKT_LENGTH ]; /**> Buffer for the kw2x radio device */
107+ ng_netdev_driver_t const * driver ; /**< Pointer to the devices interface */
108+ ng_netdev_event_cb_t event_cb ; /**< Netdev event callback */
109+ kernel_pid_t mac_pid ; /**< The driver's thread's PID */
110+ /* driver specific fields */
111+ uint8_t buf [KW2XRF_MAX_PKT_LENGTH ]; /**< Buffer for incoming or outgoing packets */
80112 ng_netconf_state_t state ; /**< Variable to keep radio driver's state */
81113 uint8_t seq_nr ; /**< Next packets sequence number */
82114 uint16_t radio_pan ; /**< The PAN the radio device is using */
83115 uint8_t radio_channel ; /**< The channel the radio device is using */
84116 uint8_t addr_short [2 ]; /**< The short address the radio device is using */
85117 uint8_t addr_long [8 ]; /**< The long address the radio device is using */
86- uint8_t options ; /**< Bit field to save enable/disable options */
118+ uint16_t option ; /**< Bit field to save enable/disable options */
119+ int8_t tx_power ; /**< The current tx-power setting of the device */
87120 ng_nettype_t proto ; /**< Protocol the interface speaks */
88121} kw2xrf_t ;
89122
90123/**
91124 * @brief Initialize the given KW2XRF device
92- *
93- * @param[out] dev KW2XRF device to initialize
125+ * @param[out] dev device descriptor
126+ * @param[in] spi SPI bus the device is connected to
127+ * @param[in] spi_speed SPI speed to use
128+ * @param[in] cs_pin GPIO pin connected to chip select
129+ * @param[in] int_pin GPIO pin connected to the interrupt pin
94130 *
95131 * @return 0 on success
96- * @return -ENODEV on invalid device descriptor
132+ * @return <0 on error
97133 */
98- int kw2xrf_init (kw2xrf_t * dev );
134+ int kw2xrf_init (kw2xrf_t * dev , spi_t spi , spi_speed_t spi_speed ,
135+ gpio_t cs_pin , gpio_t int_pin );
99136
100137/**
101- * Reference to the KW2XRF driver interface.
138+ * @brief Reference to the KW2XRF driver interface
102139 */
103140extern const ng_netdev_driver_t kw2xrf_driver ;
104141
0 commit comments