Skip to content

Commit 4ebcd7c

Browse files
drivers/kw2xrf: add IEEE 802.15.4 Radio HAL support
Co-authored-by: Michel Rottleuthner <michel.rottleuthner@haw-hamburg.de>
1 parent 4ace2ed commit 4ebcd7c

14 files changed

Lines changed: 794 additions & 874 deletions

File tree

drivers/include/kw2xrf.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "net/netdev/ieee802154.h"
3333
#include "net/gnrc/nettype.h"
3434
#include "thread.h"
35+
#include "net/ieee802154/radio.h"
3536

3637
#ifdef __cplusplus
3738
extern "C" {
@@ -107,6 +108,7 @@ typedef struct kw2xrf_params {
107108
spi_clk_t spi_clk; /**< SPI clock speed to use */
108109
gpio_t cs_pin; /**< GPIO pin connected to chip select */
109110
gpio_t int_pin; /**< GPIO pin connected to the interrupt pin */
111+
gpio_t rst_pin; /**< GPIO pin connected to RST_B */
110112
} kw2xrf_params_t;
111113

112114
/**
@@ -115,13 +117,12 @@ typedef struct kw2xrf_params {
115117
* @extends netdev_ieee802154_t
116118
*/
117119
typedef struct {
118-
netdev_ieee802154_t netdev; /**< netdev parent struct */
119120
/**
120121
* @brief device specific fields
121122
* @{
122123
*/
123124
thread_t *thread; /**< Network driver thread, for providing feedback from IRQ handler */
124-
kw2xrf_params_t params; /**< parameters for initialization */
125+
const kw2xrf_params_t *params; /**< parameters for initialization */
125126
uint8_t buf[KW2XRF_MAX_PKT_LENGTH]; /**< Buffer for incoming or outgoing packets */
126127
uint8_t state; /**< current state of the radio */
127128
uint8_t tx_frame_len; /**< length of the current TX frame */
@@ -130,6 +131,13 @@ typedef struct {
130131
this is required to know when to
131132
return to @ref kw2xrf_t::idle_state */
132133
int16_t tx_power; /**< The current tx-power setting of the device */
134+
bool ack_requested; /**< ACK was requested for last frame */
135+
bool ch_clear; /**< CCA indicated channel clear */
136+
bool waiting_for_cca; /**< Indicate whether CCA is still ongoing */
137+
bool tx_done; /**< Indicate whether TX completed */
138+
bool ack_rcvd; /**< Indicate if ACK was received for last transmission */
139+
bool cca_before_tx; /**< true if CCA shall be performed before TX */
140+
bool tx_cca_pending; /**< true a manual CCA was started and a TX should be triggered on channel clear indication */
133141
/** @} */
134142
} kw2xrf_t;
135143

@@ -146,12 +154,16 @@ void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params, uint8_t index);
146154
/**
147155
* @brief Initialize the given KW2XRF device
148156
* @param[out] dev device descriptor
149-
* @param[in] cb irq callback
157+
* @param[in] params parameters for device initialization
158+
* @param[in] hal pointer to IEEE 802.15.4 Radio HAL descriptor
159+
* @param[in] cb isr callback
160+
* @param[in] ctx context pointer handed to isr
150161
*
151162
* @return 0 on success
152163
* @return <0 on error
153164
*/
154-
int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb);
165+
int kw2xrf_init(kw2xrf_t *dev, const kw2xrf_params_t *params, ieee802154_dev_t *hal,
166+
gpio_cb_t cb, void *ctx);
155167

156168
/**
157169
* @brief Configure radio with default values
@@ -160,6 +172,13 @@ int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb);
160172
*/
161173
void kw2xrf_reset_phy(kw2xrf_t *dev);
162174

175+
/**
176+
* @brief IRQ Handler for the KW2XRF device
177+
*
178+
* @param[in] dev pointer to the IEEE 802.15.4 Radio HAL descriptor
179+
*/
180+
void kw2xrf_radio_hal_irq_handler(void *dev);
181+
163182
#ifdef __cplusplus
164183
}
165184
#endif

drivers/kw2xrf/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ menuconfig MODULE_KW2XRF
2121
select MODULE_NETDEV
2222
select MODULE_NETDEV_IEEE802154
2323
select MODULE_CORE_THREAD_FLAGS
24+
select MODULE_IOLIST
25+
select HAVE_BHP_IRQ_HANDLER
2426

2527
config MODULE_KW2XRF_TESTMODE
2628
bool "Test mode"

drivers/kw2xrf/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
SUBMODULES := 1
22

3-
SRC := kw2xrf.c kw2xrf_getset.c kw2xrf_intern.c kw2xrf_netdev.c kw2xrf_spi.c
3+
SRC := kw2xrf.c kw2xrf_getset.c kw2xrf_intern.c kw2xrf_radio_hal.c kw2xrf_spi.c
4+
5+
ifneq (,$(filter kw2xrf_testmode,$(USEMODULE)))
6+
SRC += kw2xrf_tm.c
7+
endif
48

59
include $(RIOTBASE)/Makefile.base

drivers/kw2xrf/Makefile.dep

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
USEMODULE += luid
22
USEMODULE += ieee802154
3-
USEMODULE += netdev_ieee802154
43
USEMODULE += core_thread_flags
4+
USEMODULE += iolist
5+
USEMODULE += bhp
6+
7+
ifneq (,$(filter netdev,$(USEMODULE)))
8+
USEMODULE += netdev_ieee802154_submac
9+
endif
10+
511
FEATURES_REQUIRED += periph_spi
612
FEATURES_REQUIRED += periph_gpio
713
FEATURES_REQUIRED += periph_gpio_irq

drivers/kw2xrf/Makefile.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
USEMODULE_INCLUDES_kw2xrf := $(LAST_MAKEFILEDIR)/include
22
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_kw2xrf)
3+
4+
PSEUDOMODULES += kw2xrf_testmode

drivers/kw2xrf/include/kw2xrf_getset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef KW2XRF_GETSET_H
2020
#define KW2XRF_GETSET_H
2121

22+
#include "kw2xrf_reg.h"
2223
#include "kw2xrf.h"
2324

2425
#ifdef __cplusplus

drivers/kw2xrf/include/kw2xrf_params.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ extern "C" {
5353
#define KW2XRF_PARAMS { .spi = KW2XRF_PARAM_SPI, \
5454
.spi_clk = KW2XRF_PARAM_SPI_CLK, \
5555
.cs_pin = KW2XRF_PARAM_CS, \
56-
.int_pin = KW2XRF_PARAM_INT }
56+
.int_pin = KW2XRF_PARAM_INT, \
57+
.rst_pin = KW2XRF_PARAM_RESET }
5758
#endif
5859
/**@}*/
5960

drivers/kw2xrf/kw2xrf.c

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,8 @@ static void kw2xrf_set_address(kw2xrf_t *dev)
5454
kw2xrf_set_addr_short(dev, ntohs(addr_long.uint16[0].u16));
5555
}
5656

57-
void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params, uint8_t index)
58-
{
59-
netdev_t *netdev = &dev->netdev.netdev;
60-
61-
netdev->driver = &kw2xrf_driver;
62-
/* initialize device descriptor */
63-
dev->params = *params;
64-
dev->idle_state = XCVSEQ_RECEIVE;
65-
dev->state = 0;
66-
dev->pending_tx = 0;
67-
kw2xrf_spi_init(dev);
68-
kw2xrf_set_power_mode(dev, KW2XRF_IDLE);
69-
DEBUG("[kw2xrf] enabling RX/TX completion and start events");
70-
kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL2, MKW2XDM_PHY_CTRL2_RX_WMRK_MSK);
71-
kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL2, MKW2XDM_PHY_CTRL2_RXMSK);
72-
kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL2, MKW2XDM_PHY_CTRL2_TXMSK);
73-
DEBUG("[kw2xrf] setup finished\n");
74-
75-
/* register with netdev */
76-
netdev_register(netdev, NETDEV_KW2XRF, index);
77-
}
78-
79-
int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb)
80-
{
81-
if (dev == NULL) {
82-
return -ENODEV;
83-
}
84-
85-
kw2xrf_set_out_clk(dev);
86-
kw2xrf_disable_interrupts(dev);
87-
/* set up GPIO-pin used for IRQ */
88-
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_FALLING, cb, dev);
89-
90-
kw2xrf_abort_sequence(dev);
91-
kw2xrf_update_overwrites(dev);
92-
kw2xrf_timer_init(dev, KW2XRF_TIMEBASE_62500HZ);
93-
DEBUG("[kw2xrf] init finished\n");
94-
95-
return 0;
96-
}
97-
9857
void kw2xrf_reset_phy(kw2xrf_t *dev)
9958
{
100-
netdev_ieee802154_reset(&dev->netdev);
101-
10259
dev->tx_power = KW2XRF_DEFAULT_TX_POWER;
10360
kw2xrf_set_tx_power(dev, dev->tx_power);
10461

@@ -110,7 +67,10 @@ void kw2xrf_reset_phy(kw2xrf_t *dev)
11067

11168
kw2xrf_set_rx_watermark(dev, 1);
11269

113-
kw2xrf_set_option(dev, KW2XRF_OPT_AUTOACK, true);
70+
if (!IS_ACTIVE(CONFIG_IEEE802154_AUTO_ACK_DISABLE)) {
71+
kw2xrf_set_option(dev, KW2XRF_OPT_AUTOACK, true);
72+
}
73+
11474
kw2xrf_set_option(dev, KW2XRF_OPT_ACK_REQ, true);
11575
kw2xrf_set_option(dev, KW2XRF_OPT_AUTOCCA, true);
11676

drivers/kw2xrf/kw2xrf_getset.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ void kw2xrf_set_option(kw2xrf_t *dev, uint16_t option, bool state)
368368

369369
/* set option field */
370370
if (state) {
371-
dev->netdev.flags |= option;
372-
373371
/* trigger option specific actions */
374372
switch (option) {
375373
case KW2XRF_OPT_AUTOCCA:
@@ -404,7 +402,6 @@ void kw2xrf_set_option(kw2xrf_t *dev, uint16_t option, bool state)
404402
}
405403
}
406404
else {
407-
dev->netdev.flags &= ~(option);
408405
/* trigger option specific actions */
409406
switch (option) {
410407
case KW2XRF_OPT_AUTOCCA:
@@ -416,15 +413,6 @@ void kw2xrf_set_option(kw2xrf_t *dev, uint16_t option, bool state)
416413
/* disable promiscuous mode */
417414
kw2xrf_clear_dreg_bit(dev, MKW2XDM_PHY_CTRL4,
418415
MKW2XDM_PHY_CTRL4_PROMISCUOUS);
419-
/* re-enable AUTOACK only if the option is set */
420-
if (dev->netdev.flags & KW2XRF_OPT_AUTOACK) {
421-
kw2xrf_set_dreg_bit(dev, MKW2XDM_PHY_CTRL1,
422-
MKW2XDM_PHY_CTRL1_AUTOACK);
423-
}
424-
if (dev->netdev.flags & KW2XRF_OPT_ACK_REQ) {
425-
kw2xrf_set_dreg_bit(dev, MKW2XDM_PHY_CTRL1,
426-
MKW2XDM_PHY_CTRL1_RXACKRQD);
427-
}
428416
break;
429417

430418
case KW2XRF_OPT_AUTOACK:

0 commit comments

Comments
 (0)