static void pull_data(struct device *dev) { const struct spi_dw_config *info = dev->config->config_info; struct spi_dw_data *spi = dev->driver_data; u32_t data = 0; DBG_COUNTER_INIT(); while (read_rxflr(info->regs)) { data = read_dr(info->regs); DBG_COUNTER_INC(); if (spi->rx_buf && spi->rx_buf_len > 0) { switch (spi->dfs) { case 1: UNALIGNED_PUT(data, (u8_t *)spi->rx_buf); break; case 2: UNALIGNED_PUT(data, (u16_t *)spi->rx_buf); break; #ifndef CONFIG_ARC case 4: UNALIGNED_PUT(data, (u32_t *)spi->rx_buf); break; #endif } spi->rx_buf += spi->dfs; spi->rx_buf_len--; } spi->fifo_diff--; } if (!spi->rx_buf_len && spi->tx_buf_len < DW_SPI_FIFO_DEPTH) { write_rxftlr(spi->tx_buf_len - 1, info->regs); } else if (read_rxftlr(info->regs) >= spi->rx_buf_len) { write_rxftlr(spi->rx_buf_len - 1, info->regs); } SYS_LOG_DBG("Pulled: %d", DBG_COUNTER_RESULT()); }
/** * FIXME choose correct OUI, or add support in L2 */ static u8_t *get_mac(struct device *dev) { u32_t *ptr = (u32_t *)mac_addr; mac_addr[7] = 0x00; mac_addr[6] = 0x12; mac_addr[5] = 0x4b; mac_addr[4] = 0x00; UNALIGNED_PUT(sys_rand32_get(), ptr); mac_addr[0] = (mac_addr[0] & ~0x01) | 0x02; return mac_addr; }
static inline u8_t *get_mac(struct device *dev) { struct upipe_context *upipe = dev->driver_data; upipe->mac_addr[0] = 0x00; upipe->mac_addr[1] = 0x10; upipe->mac_addr[2] = 0x20; upipe->mac_addr[3] = 0x30; #if defined(CONFIG_IEEE802154_UPIPE_RANDOM_MAC) UNALIGNED_PUT(sys_cpu_to_be32(sys_rand32_get()), (u32_t *) ((u8_t *)upipe->mac_addr+4)); #else upipe->mac_addr[4] = CONFIG_IEEE802154_UPIPE_MAC4; upipe->mac_addr[5] = CONFIG_IEEE802154_UPIPE_MAC5; upipe->mac_addr[6] = CONFIG_IEEE802154_UPIPE_MAC6; upipe->mac_addr[7] = CONFIG_IEEE802154_UPIPE_MAC7; #endif return upipe->mac_addr; }
int net_addr_pton(sa_family_t family, const char *src, void *dst) { if (family == AF_INET) { struct in_addr *addr = (struct in_addr *)dst; size_t i, len; len = strlen(src); for (i = 0; i < len; i++) { if (!(src[i] >= '0' && src[i] <= '9') && src[i] != '.') { return -EINVAL; } } memset(addr, 0, sizeof(struct in_addr)); for (i = 0; i < sizeof(struct in_addr); i++) { char *endptr; addr->s4_addr[i] = strtol(src, &endptr, 10); src = ++endptr; } } else if (family == AF_INET6) { /* If the string contains a '.', it means it's of the form * X:X:X:X:X:X:x.x.x.x, and contains only 6 16-bit pieces */ int expected_groups = strchr(src, '.') ? 6 : 8; struct in6_addr *addr = (struct in6_addr *)dst; int i, len; if (*src == ':') { /* Ignore a leading colon, makes parsing neater */ src++; } len = strlen(src); for (i = 0; i < len; i++) { if (!(src[i] >= '0' && src[i] <= '9') && !(src[i] >= 'A' && src[i] <= 'F') && !(src[i] >= 'a' && src[i] <= 'f') && src[i] != '.' && src[i] != ':') return -EINVAL; } for (i = 0; i < expected_groups; i++) { char *tmp; if (!src || *src == '\0') { return -EINVAL; } if (*src != ':') { /* Normal IPv6 16-bit piece */ UNALIGNED_PUT(htons(strtol(src, NULL, 16)), &addr->s6_addr16[i]); src = strchr(src, ':'); if (!src && i < expected_groups - 1) { return -EINVAL; } src++; continue; } /* Two colons in a row */ for (; i < expected_groups; i++) { UNALIGNED_PUT(0, &addr->s6_addr16[i]); } tmp = strrchr(src, ':'); if (src == tmp && (expected_groups == 6 || !src[1])) { src++; break; } if (expected_groups == 6) { /* we need to drop the trailing * colon since it's between the * ipv6 and ipv4 addresses, rather than being * a part of the ipv6 address */ tmp--; } /* Calculate the amount of skipped zeros */ i = expected_groups - 1; do { if (*tmp == ':') { i--; } } while (tmp-- != src); src++; } if (expected_groups == 6) { /* Parse the IPv4 part */ for (i = 0; i < 4; i++) { if (!src || !*src) { return -EINVAL; } addr->s6_addr[12 + i] = strtol(src, NULL, 10); src = strchr(src, '.'); if (!src && i < 3) { return -EINVAL; } src++; } } } else { return -EINVAL; } return 0; }