Skip to content

Commit

Permalink
fixup use eui64_t and network_uint16_t
Browse files Browse the repository at this point in the history
  • Loading branch information
benemorius committed Mar 12, 2020
1 parent 96b55ed commit 11f9456
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 39 deletions.
8 changes: 4 additions & 4 deletions drivers/kw41zrf/include/kw41zrf_getset.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,31 @@ uint16_t kw41zrf_get_pan(kw41zrf_t *dev);
* @param[in] dev kw41zrf device descriptor
* @param[in] addr short address
*/
void kw41zrf_set_addr_short(kw41zrf_t *dev, uint16_t addr);
void kw41zrf_set_addr_short(kw41zrf_t *dev, network_uint16_t addr);

/**
* @brief Set long address of a given device
*
* @param[in] dev kw41zrf device descriptor
* @param[in] addr long address
*/
void kw41zrf_set_addr_long(kw41zrf_t *dev, uint64_t addr);
void kw41zrf_set_addr_long(kw41zrf_t *dev, eui64_t addr);

/**
* @brief Get short address of a given device
*
* @param[in] dev kw41zrf device descriptor
* @return current short address
*/
uint16_t kw41zrf_get_addr_short(kw41zrf_t *dev);
network_uint16_t kw41zrf_get_addr_short(kw41zrf_t *dev);

/**
* @brief Get long address of a given device
*
* @param[in] dev kw41zrf device descriptor
* @return current long address
*/
uint64_t kw41zrf_get_addr_long(kw41zrf_t *dev);
eui64_t kw41zrf_get_addr_long(kw41zrf_t *dev);

/**
* @brief Get CCA threshhold of a given device
Expand Down
7 changes: 2 additions & 5 deletions drivers/kw41zrf/kw41zrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ static void kw41zrf_set_address(kw41zrf_t *dev)
/* get unique IDs to use as hardware addresses */
luid_get_eui64(&addr_long);
luid_get_short(&addr_short);
/* make sure we mark the address as non-multicast and not globally unique */
addr_long.uint8[0] &= ~(0x01);
addr_long.uint8[0] |= (0x02);
/* set short and long address */
kw41zrf_set_addr_long(dev, ntohll(addr_long.uint64.u64));
kw41zrf_set_addr_short(dev, ntohs(addr_short.u16));
kw41zrf_set_addr_long(dev, addr_long);
kw41zrf_set_addr_short(dev, addr_short);
}

void kw41zrf_setup(kw41zrf_t *dev)
Expand Down
24 changes: 11 additions & 13 deletions drivers/kw41zrf/kw41zrf_getset.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,35 @@ void kw41zrf_set_pan(kw41zrf_t *dev, uint16_t pan)
DEBUG("[kw41zrf] set pan to: 0x%x\n", pan);
}

void kw41zrf_set_addr_short(kw41zrf_t *dev, uint16_t addr)
void kw41zrf_set_addr_short(kw41zrf_t *dev, network_uint16_t addr)
{
(void) dev;
ZLL->MACSHORTADDRS0 = (ZLL->MACSHORTADDRS0 & ~ZLL_MACSHORTADDRS0_MACSHORTADDRS0_MASK) |
ZLL_MACSHORTADDRS0_MACSHORTADDRS0(addr);
ZLL_MACSHORTADDRS0_MACSHORTADDRS0(addr.u16);
}

void kw41zrf_set_addr_long(kw41zrf_t *dev, uint64_t addr)
void kw41zrf_set_addr_long(kw41zrf_t *dev, eui64_t addr)
{
(void) dev;
/* Network byte order */
addr = byteorder_swapll(addr);
ZLL->MACLONGADDRS0_LSB = (uint32_t)addr;
ZLL->MACLONGADDRS0_MSB = (addr >> 32);
ZLL->MACLONGADDRS0_LSB = (uint32_t)addr.uint64.u64;
ZLL->MACLONGADDRS0_MSB = (addr.uint64.u64 >> 32);
}

uint16_t kw41zrf_get_addr_short(kw41zrf_t *dev)
network_uint16_t kw41zrf_get_addr_short(kw41zrf_t *dev)
{
(void) dev;
return (ZLL->MACSHORTADDRS0 & ZLL_MACSHORTADDRS0_MACSHORTADDRS0_MASK) >>
ZLL_MACSHORTADDRS0_MACSHORTADDRS0_SHIFT;
uint16_t addr = (ZLL->MACSHORTADDRS0 & ZLL_MACSHORTADDRS0_MACSHORTADDRS0_MASK) >>
ZLL_MACSHORTADDRS0_MACSHORTADDRS0_SHIFT;
return (network_uint16_t)addr;
}

uint64_t kw41zrf_get_addr_long(kw41zrf_t *dev)
eui64_t kw41zrf_get_addr_long(kw41zrf_t *dev)
{
(void) dev;
uint64_t addr = ((uint64_t)ZLL->MACLONGADDRS0_MSB << 32) | ZLL->MACLONGADDRS0_LSB;
/* Network byte order */
addr = byteorder_swapll(addr);

return addr;
return (eui64_t)(network_uint64_t)addr;
}

int8_t kw41zrf_get_cca_threshold(kw41zrf_t *dev)
Expand Down
26 changes: 9 additions & 17 deletions drivers/kw41zrf/kw41zrf_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,6 @@ int kw41zrf_netdev_get(netdev_t *netdev, netopt_t opt, void *value, size_t len)
*((netopt_state_t *)value) = kw41zrf_netdev_get_state(dev);
return sizeof(netopt_state_t);

case NETOPT_MAX_PACKET_SIZE:
assert(len >= sizeof(uint16_t));
*((uint16_t *)value) = KW41ZRF_MAX_PKT_LENGTH - _MAX_MHR_OVERHEAD;
return sizeof(uint16_t);

case NETOPT_PRELOADING:
assert(len >= sizeof(netopt_enable_t));
*((netopt_enable_t *)value) =
Expand Down Expand Up @@ -563,14 +558,14 @@ int kw41zrf_netdev_get(netdev_t *netdev, netopt_t opt, void *value, size_t len)

case NETOPT_ADDRESS:
assert(len >= sizeof(uint16_t));
*((uint16_t *)value) = kw41zrf_get_addr_short(dev);
*((network_uint16_t *)value) = kw41zrf_get_addr_short(dev);
res = sizeof(uint16_t);
break;

case NETOPT_ADDRESS_LONG:
assert(len >= sizeof(uint64_t));
*((uint64_t *)value) = kw41zrf_get_addr_long(dev);
res = sizeof(uint64_t);
assert(len >= sizeof(eui64_t));
*((eui64_t *)value) = kw41zrf_get_addr_long(dev);
res = sizeof(eui64_t);
break;

case NETOPT_TX_POWER:
Expand Down Expand Up @@ -641,10 +636,6 @@ static int kw41zrf_netdev_set(netdev_t *netdev, netopt_t opt, const void *value,

/* These settings do not require the transceiver to be awake */
switch (opt) {
case NETOPT_CHANNEL_PAGE:
res = -EINVAL;
break;

case NETOPT_STATE:
assert(len <= sizeof(const netopt_state_t));
res = kw41zrf_netdev_set_state(dev, *((const netopt_state_t *)value));
Expand Down Expand Up @@ -777,14 +768,14 @@ static int kw41zrf_netdev_set(netdev_t *netdev, netopt_t opt, const void *value,

case NETOPT_ADDRESS:
assert(len <= sizeof(const uint16_t));
kw41zrf_set_addr_short(dev, *((const uint16_t *)value));
kw41zrf_set_addr_short(dev, *((const network_uint16_t *)value));
res = sizeof(const uint16_t);
break;

case NETOPT_ADDRESS_LONG:
assert(len <= sizeof(const uint64_t));
kw41zrf_set_addr_long(dev, *((const uint64_t *)value));
res = sizeof(const uint64_t);
assert(len <= sizeof(const eui64_t));
kw41zrf_set_addr_long(dev, *((const eui64_t *)value));
res = sizeof(const eui64_t);
break;

case NETOPT_NID:
Expand Down Expand Up @@ -888,6 +879,7 @@ static uint32_t _isr_event_seq_t_ccairq(kw41zrf_t *dev, uint32_t irqsts)
}

dev->backoff_delay = 0;
/* disable TMR2 match */
bit_clear32(&ZLL->PHY_CTRL, ZLL_PHY_CTRL_TMR2CMP_EN_SHIFT);
}
if (irqsts & ZLL_IRQSTS_CCAIRQ_MASK) {
Expand Down

0 comments on commit 11f9456

Please sign in to comment.