Blame view

RIOT/drivers/include/kw2xrf.h 5.31 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  /*
   * Copyright (C) 2016 Phytec Messtechnik GmbH
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    drivers_kw2xrf KW2x radio-driver
   * @ingroup     drivers_netdev
   * @brief       Device driver for the NXP CR20A and KW2xD radios
   * @{
   *
   * @file
   * @brief       Interface definition for the kw2xrf driver
   *
   * @author      Johann Fischer <j.fischer@phytec.de>
   * @author      Jonas Remmert <j.remmert@phytec.de>
   * @author      Sebastian Meiling <s@mlng.net>
   */
  
  #ifndef KW2XRF_H
  #define KW2XRF_H
  
  #include <stdint.h>
  
  #include "board.h"
  #include "periph/spi.h"
  #include "periph/gpio.h"
  #include "net/netdev.h"
  #include "net/netdev/ieee802154.h"
  #include "net/gnrc/nettype.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   Maximum packet length
   */
  #define KW2XRF_MAX_PKT_LENGTH           (IEEE802154_FRAME_LEN_MAX)
  
  /**
   * @brief   Default PAN ID used after initialization
   */
  #define KW2XRF_DEFAULT_PANID            (IEEE802154_DEFAULT_PANID)
  
  /**
   * @name    Default channel used after initialization
   *
   * @{
   */
  #ifndef KW2XRF_DEFAULT_CHANNEL
  #define KW2XRF_DEFAULT_CHANNEL          (IEEE802154_DEFAULT_CHANNEL)
  #endif
  /** @} */
  
  /**
   * @name    Allowed range of channels
   *
   * @{
   */
  #define KW2XRF_MIN_CHANNEL              (11U)
  #define KW2XRF_MAX_CHANNEL              (26U)
  /** @} */
  
  /**
   * @brief   Default TX_POWER in dbm used after initialization
   */
  #define KW2XRF_DEFAULT_TX_POWER         (IEEE802154_DEFAULT_TXPOWER)
  
  /**
   * @brief   Maximum output power of the kw2x device in dBm
   */
  #define KW2XDRF_OUTPUT_POWER_MAX       (8)
  
  /**
   * @brief   Minimum output power of the kw2x device in dBm
   */
  #define KW2XDRF_OUTPUT_POWER_MIN       (-35)
  
  /**
   * @brief   Internal device option flags
   *
   * `0x00ff` is reserved for general IEEE 802.15.4 flags
   * (see @ref netdev_ieee802154_t)
   *
   * @{
   */
  #define KW2XRF_OPT_SRC_ADDR_LONG    (NETDEV_IEEE802154_SRC_MODE_LONG)  /**< legacy define */
  #define KW2XRF_OPT_RAWDUMP          (NETDEV_IEEE802154_RAW)            /**< legacy define */
  #define KW2XRF_OPT_ACK_REQ          (NETDEV_IEEE802154_ACK_REQ)        /**< legacy define */
  
  #define KW2XRF_OPT_AUTOCCA          (0x0100)    /**< CCA befor TX active */
  #define KW2XRF_OPT_PROMISCUOUS      (0x0200)    /**< promiscuous mode
                                                    *   active */
  #define KW2XRF_OPT_PRELOADING       (0x0400)    /**< preloading enabled */
  #define KW2XRF_OPT_TELL_TX_START    (0x0800)    /**< notify MAC layer on TX
                                                    *   start */
  #define KW2XRF_OPT_TELL_TX_END      (0x1000)    /**< notify MAC layer on TX
                                                    *   finished */
  #define KW2XRF_OPT_TELL_RX_START    (0x2000)    /**< notify MAC layer on RX
                                                    *   start */
  #define KW2XRF_OPT_TELL_RX_END      (0x4000)    /**< notify MAC layer on RX
                                                    *   finished */
  #define KW2XRF_OPT_AUTOACK          (0x8000)    /**< enable automatically ACK
                                                    *   for incommint packet */
  /** @} */
  
  /**
   * @brief   Struct holding all params needed for device initialization
   */
  typedef struct kw2xrf_params {
      spi_t spi;                          /**< SPI bus the device is connected to */
      spi_clk_t spi_clk;                  /**< SPI clock speed to use */
      gpio_t cs_pin;                      /**< GPIO pin connected to chip select */
      gpio_t int_pin;                     /**< GPIO pin connected to the interrupt pin */
  } kw2xrf_params_t;
  
  /**
   * @brief   Device descriptor for KW2XRF radio devices
   *
   * @extends netdev_ieee802154_t
   */
  typedef struct {
      netdev_ieee802154_t netdev;          /**< netdev parent struct */
      /**
       * @brief   device specific fields
       * @{
       */
      kw2xrf_params_t params;             /**< parameters for initialization */
      uint8_t buf[KW2XRF_MAX_PKT_LENGTH]; /**< Buffer for incoming or outgoing packets */
      uint8_t state;                      /**< current state of the radio */
      uint8_t tx_frame_len;               /**< length of the current TX frame */
      uint8_t idle_state;                 /**< state to return to after sending */
      uint8_t pending_tx;                 /**< keep track of pending TX calls
                                               this is required to know when to
                                               return to @ref kw2xrf_t::idle_state */
      int16_t tx_power;                   /**< The current tx-power setting of the device */
      /** @} */
  } kw2xrf_t;
  
  /**
   * @brief   Setup an KW2XRF based device state
   *
   * @param[out] dev          device descriptor
   * @param[in]  params       parameters for device initialization
   */
  void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params);
  
  /**
   * @brief   Initialize the given KW2XRF device
   * @param[out] dev          device descriptor
   * @param[in] cb            irq callback
   *
   * @return                  0 on success
   * @return                  <0 on error
   */
  int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb);
  
  /**
   * @brief   Configure radio with default values
   *
   * @param[in] dev           device to reset
   */
  void kw2xrf_reset_phy(kw2xrf_t *dev);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* KW2XRF_H */
  /** @} */