Initial commit: MT firmware project

- BLE peripheral applications
- dr_piezo and bladder_patch projects

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Charles Kwon
2026-01-25 17:26:39 +09:00
commit 72f5eb3cd9
2559 changed files with 1594625 additions and 0 deletions

85
external/lwip/src/port/arch/cc.h vendored Normal file
View File

@@ -0,0 +1,85 @@
/**
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#ifndef __ARCH_CC_H__
#define __ARCH_CC_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
// Includes definition of mch_printf macro to do printf
#include "nordic_common.h"
#include "nrf.h"
#include "compiler_abstraction.h"
#include "nrf_assert.h"
#include "errno.h"
#include "app_util.h"
#define BYTE_ORDER LITTLE_ENDIAN
typedef uint8_t u8_t;
typedef int8_t s8_t;
typedef uint16_t u16_t;
typedef int16_t s16_t;
typedef uint32_t u32_t;
typedef int32_t s32_t;
typedef uintptr_t mem_ptr_t;
#define LWIP_ERR_T int
/* Define (sn)printf formatters for these lwIP types */
#define U16_F "hu"
#define S16_F "hd"
#define X16_F "hx"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
/* Compiler hints for packing structures */
//#define PACK_STRUCT_FIELD __attribute__((packed))
//#define PACK_STRUCT_FLD_8 __attribute__((packed))
//#define PACK_STRUCT_STRUCT __attribute__((packed))
#define PACK_STRUCT_BEGIN __attribute__((packed))
//#define PACK_STRUCT_END
void nrf_message(const char * m);
/* Plaform specific diagnostic output */
#define LWIP_PLATFORM_DIAG(x)
#define LWIP_PLATFORM_ASSERT(x) ASSERT(x)
#define LWIP_RAND() ((u32_t)rand())
#endif /* __ARCH_CC_H__ */

157
external/lwip/src/port/arch/lwipopts.h vendored Normal file
View File

@@ -0,0 +1,157 @@
/**
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#ifndef __LWIPOPTS_H__
#define __LWIPOPTS_H__
#include "mem_manager.h"
#define NO_SYS 1
#define NO_SYS_NO_TIMERS 0
#define MEM_LIBC_MALLOC 1
#define MEMP_MEM_MALLOC 1
#define MEM_ALIGNMENT 4
#define MEM_SIZE 0
#define PBUF_POOL_SIZE 32
#define LWIP_ARP 0
#define IP_REASS_MAX_PBUFS 0
#define IP_FRAG_USES_STATIC_BUF 0
#define MEMP_NUM_RAW_PCB 0
#define MEMP_NUM_UDP_PCB 2
#define MEMP_NUM_TCP_PCB 1
#define MEMP_NUM_TCP_PCB_LISTEN 1
#define MEMP_NUM_TCP_SEG 0
#define MEMP_NUM_FRAG_PBUF 0
#define MEMP_NUM_TCPIP_MSG_API 0
#define MEMP_NUM_TCPIP_MSG_INPKT 0
#define MEMP_NUM_SNMP_NODE 0
#define MEMP_NUM_SNMP_ROOTNODE 0
#define MEMP_NUM_SNMP_VARBIND 0
#define MEMP_NUM_SNMP_VALUE 0
#define IP_DEFAULT_TTL 255
#define IP_SOF_BROADCAST 0
#define IP_SOF_BROADCAST_RECV 0
#define LWIP_ICMP 1
#define LWIP_BROADCAST_PING 0
#define LWIP_MULTICAST_PING 0
#define LWIP_RAW 0
#define TCP_LISTEN_BACKLOG 1
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define LWIP_NETIF_HWADDRHINT 1
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define LWIP_STATS_DISPLAY 0
#define MEM_STATS 0
#define SYS_STATS 0
#define MEMP_STATS 0
#define LINK_STATS 0
#define ETHARP_TRUST_IP_MAC 0
#define ETH_PAD_SIZE 2
#define LWIP_CHKSUM_ALGORITHM 2
#define LWIP_CHECKSUM_ON_COPY 1
#define LWIP_ND6_MAX_MULTICAST_SOLICIT 1
#define LWIP_ND6_MAX_NEIGHBOR_ADVERTISEMENT 1
#define LWIP_ND6_RETRANS_TIMER 20000
#define LWIP_ND6_QUEUEING 0
#define LWIP_ND6_NUM_ROUTERS 1
#define LWIP_ND6_DELAY_FIRST_PROBE_TIME 10000
#define LWIP_TCP_KEEPALIVE 1
#define LWIP_ARP 0
#define ARP_TABLE_SIZE 0
#define IP_REASSEMBLY 0
#define IP_FRAG 0
#define LWIP_TCP 1
#define LWIP_IPV6 1
#define LWIP_IPV4 0
#define LWIP_ICMP6 1
#define LWIP_IPV6_REASS 0
#define LWIP_ND6_TCP_REACHABILITY_HINTS 0
#define LWIP_IPV6_MLD 0
#define LWIP_STATS 0
#define PPP_IPV6_SUPPORT 0
#define LWIP_PPP_API 0
#define PPP_SUPPORT 0
#define LWIP_DNS 1
#define LWIP_SUPPORT_CUSTOM_PBUF 1
#define LWIP_BTLE_6LOWPAN 1
#define TCP_TMR_INTERVAL 50
// Keepalive values, compliant with RFC 1122. Don't change this unless you know what you're doing
#define TCP_KEEPIDLE_DEFAULT 10000UL // Default KEEPALIVE timer in milliseconds
#define TCP_KEEPINTVL_DEFAULT 2000UL // Default Time between KEEPALIVE probes in milliseconds
#define TCP_KEEPCNT_DEFAULT 9U // Default Counter for KEEPALIVE probes
#define TCP_MSS 896
#define TCP_WND (4 * TCP_MSS)
#define TCP_SND_BUF (4 * TCP_MSS)
#define SO_REUSE 1
//#define mem_init(...)
//#define mem_free(p) nrf_free((p))
//#define mem_malloc(sz) nrf_malloc((sz))
//#define mem_trim(p,sz) nrf_realloc((p),(sz))
#define LWIP_DEBUG 0
#define ETHARP_DEBUG LWIP_DBG_OFF
#define NETIF_DEBUG LWIP_DBG_OFF
#define PBUF_DEBUG LWIP_DBG_OFF
#define API_LIB_DEBUG LWIP_DBG_OFF
#define API_MSG_DEBUG LWIP_DBG_OFF
#define SOCKETS_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
#define INET_DEBUG LWIP_DBG_OFF
#define IP_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define MEM_DEBUG LWIP_DBG_OFF
#define MEMP_DEBUG LWIP_DBG_OFF
#define SYS_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#define TCP_WND_DEBUG LWIP_DBG_OFF
#define TCP_FR_DEBUG LWIP_DBG_OFF
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#define TCP_RST_DEBUG LWIP_DBG_OFF
#define UDP_DEBUG LWIP_DBG_OFF
#define TCPIP_DEBUG LWIP_DBG_OFF
#define PPP_DEBUG LWIP_DBG_OFF
#define SLIP_DEBUG LWIP_DBG_OFF
#define DHCP_DEBUG LWIP_DBG_OFF
#define SYS_LIGHTWEIGHT_PROT 0
#endif /* __LWIPOPTS_H__ */

36
external/lwip/src/port/arch/perf.h vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */

45
external/lwip/src/port/arch/sys_arch.h vendored Normal file
View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
*/
#ifndef __ARCH_SYS_ARCH_H__
#define __ARCH_SYS_ARCH_H__
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
typedef void * sys_prot_t;
typedef void * sys_sem_t;
typedef void * sys_mbox_t;
typedef void * sys_thread_t;
#endif /* __ARCH_SYS_ARCH_H__ */

View File

@@ -0,0 +1,352 @@
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/pbuf.h"
#include "lwip/stats.h"
#include "lwip/netif.h"
#include "lwip/ip6.h"
#include "sdk_config.h"
#include "app_timer.h"
#include "ble_ipsp.h"
#include "ble_6lowpan.h"
#include "mem_manager.h"
#include "iot_context_manager.h"
#include "nrf_platform_port.h"
/**
* @defgroup nrf_driver_debug_log Module's Log Macros
* @details Macros used for creating module logs which can be useful in understanding handling
* of events or actions on API requests. These are intended for debugging purposes and
* can be enabled by defining the NRF_DRIVER_ENABLE_LOGS.
* @note If NRF_LWIP_DRIVER_CONFIG_LOG_ENABLED is disabled, having NRF_DRIVER_ENABLE_LOGS has no effect.
* @{
*/
#if NRF_LWIP_DRIVER_CONFIG_LOG_ENABLED
#define NRF_LOG_MODULE_NAME LwIP
#define NRF_LOG_LEVEL NRF_LWIP_DRIVER_CONFIG_LOG_LEVEL
#define NRF_LOG_INFO_COLOR NRF_LWIP_DRIVER_CONFIG_INFO_COLOR
#define NRF_LOG_DEBUG_COLOR NRF_LWIP_DRIVER_CONFIG_DEBUG_COLOR
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();
#define NRF_DRIVER_TRC NRF_LOG_DEBUG /**< Used for getting trace of execution in the module. */
#define NRF_DRIVER_LOG NRF_LOG_INFO /**< Used for logging details. */
#define NRF_DRIVER_ERR NRF_LOG_ERROR /**< Used for logging errors in the module. */
#define NRF_DRIVER_DUMP NRF_LOG_HEXDUMP_DEBUG /**< Used for dumping octet information to get details of bond information etc. */
#define NRF_DRIVER_ENTRY() NRF_DRIVER_TRC(">> %s", __func__)
#define NRF_DRIVER_EXIT() NRF_DRIVER_TRC("<< %s", __func__)
#else // NRF_LWIP_DRIVER_CONFIG_LOG_ENABLED
#define NRF_DRIVER_TRC(...) /**< Disables traces. */
#define NRF_DRIVER_LOG(...) /**< Disables loggs. */
#define NRF_DRIVER_DUMP(...) /**< Disables dumping of octet streams. */
#define NRF_DRIVER_ERR(...) /**< Disables error logs. */
#define NRF_DRIVER_ENTRY(...)
#define NRF_DRIVER_EXIT(...)
#endif // NRF_LWIP_DRIVER_CONFIG_LOG_ENABLED
/** Driver table to maintain mapping between IP interface and Bluetooth as transport. */
struct blenetif {
iot_interface_t * p_ble_interface;
struct netif netif;
};
struct blenetif m_blenetif_table[BLE_6LOWPAN_MAX_INTERFACE]; /**< Table maintaining network interface of LwIP and also corresponding 6lowpan interface. */
/** @brief Function to add received packet to pbuf queue and notify the stack of received packet. */
static void blenetif_input(struct netif * p_netif, uint8_t * p_payload, uint16_t payload_len)
{
struct pbuf * p_buffer;
NRF_DRIVER_ENTRY();
NRF_DRIVER_DUMP(p_payload, payload_len);
// Allocate a pbuf chain of pbufs from the pool.
p_buffer = pbuf_alloc(PBUF_RAW, payload_len, PBUF_REF);
if (p_buffer != NULL)
{
p_buffer->payload = p_payload;
p_buffer->len = payload_len;
p_buffer->tot_len = payload_len;
if (ip6_input(p_buffer, p_netif) != ERR_OK)
{
NRF_DRIVER_LOG("IP Stack returned error.");
}
UNUSED_VARIABLE(pbuf_free(p_buffer));
}
NRF_DRIVER_EXIT();
}
/** @brief Network interface output function registered with LwIP to send packets on 6lowpan. */
static err_t blenetif_output(struct netif * p_netif, struct pbuf * p_buffer, const ip6_addr_t * p_addr)
{
struct blenetif * p_blenetif = (struct blenetif *)p_netif->state;
uint8_t * p_payload;
err_t error_code = ERR_MEM;
const uint16_t requested_len = p_buffer->len;
NRF_DRIVER_ENTRY();
NRF_DRIVER_DUMP(p_buffer->payload, requested_len);
p_payload = nrf_malloc(p_buffer->len);
if (NULL != p_payload)
{
memcpy(p_payload, p_buffer->payload, p_buffer->len);
uint32_t retval = ble_6lowpan_interface_send(p_blenetif->p_ble_interface,
p_payload,
requested_len);
if (retval != NRF_SUCCESS)
{
NRF_DRIVER_ERR("Failed to send IP packet, reason 0x%08X", retval);
nrf_free(p_payload);
}
else
{
error_code = ERR_OK;
}
}
else
{
NRF_DRIVER_ERR("Failed to allocate memory for output packet");
}
NRF_DRIVER_EXIT();
return error_code;
}
/** @brief Initialization once network interface has been added. */
static err_t blenetif_init(struct netif * p_netif)
{
// Set link MTU size.
p_netif->mtu = BLE_IPSP_MTU;
// Device capabilities and link status
p_netif->flags = NETIF_FLAG_LINK_UP;
// Indicate interface link is up.
netif_set_up(p_netif);
// Enable Address Auto configuration.
p_netif->ip6_autoconfig_enabled = 1;
return ERR_OK;
}
/**@brief Callback registered with 6lowpan to receive asynchronous events. */
static void blenetif_transport_callback(iot_interface_t * p_interface,
ble_6lowpan_event_t * p_event)
{
uint32_t index;
uint32_t err_code;
struct blenetif * p_blenetif = NULL;
// Search network interface added for the 6lowpan interface that has generated the event.
for (index = 0; index < BLE_6LOWPAN_MAX_INTERFACE; index++)
{
if (p_interface == m_blenetif_table[index].p_ble_interface)
{
p_blenetif = &m_blenetif_table[index];
break;
}
}
switch(p_event->event_id)
{
case BLE_6LO_EVT_INTERFACE_ADD:
{
// If no existing interface was found, allocate a new one.
if (p_blenetif == NULL)
{
for (index = 0; index < BLE_6LOWPAN_MAX_INTERFACE; index++)
{
if (m_blenetif_table[index].p_ble_interface == NULL)
{
p_blenetif = &m_blenetif_table[index];
p_blenetif->p_ble_interface = p_interface;
break;
}
}
}
else
{
// Interface already exists, this is an error, should not happen.
break;
}
err_code = iot_context_manager_table_alloc(p_interface);
if (err_code == NRF_SUCCESS)
{
NRF_DRIVER_LOG("Successfully allocated context table!");
}
else
{
NRF_DRIVER_ERR("Failed to allocate context table!");
}
#if (IPV6_LL_ADDR_SIZE == 6)
memcpy(p_blenetif->netif.hwaddr, p_interface->local_addr.identifier, 3);
memcpy(p_blenetif->netif.hwaddr + 3, p_interface->local_addr.identifier + 5, 3);
#else
memcpy(p_blenetif->netif.hwaddr, p_interface->local_addr.identifier, IPV6_LL_ADDR_SIZE);
#endif
p_blenetif->netif.hwaddr_len = IPV6_LL_ADDR_SIZE;
UNUSED_VARIABLE(netif_add(&p_blenetif->netif, p_blenetif, blenetif_init, NULL));
p_blenetif->netif.ip6_addr[0].addr[0] = HTONL(0xFE800000);
p_blenetif->netif.ip6_addr[0].addr[1] = HTONL(0x00000000);
p_blenetif->netif.ip6_addr[0].addr[2] = *((u32_t *) (&p_interface->local_addr.identifier[0]));
p_blenetif->netif.ip6_addr[0].addr[3] = *((u32_t *) (&p_interface->local_addr.identifier[4]));
// Flip local/universal bit.
p_blenetif->netif.ip6_addr[0].addr[2] ^= IPV6_IID_FLIP_VALUE;
p_blenetif->netif.ip6_addr_state[0] = IP6_ADDR_TENTATIVE;
p_blenetif->netif.output_ip6 = blenetif_output;
nrf_driver_interface_up(p_interface);
break;
}
case BLE_6LO_EVT_INTERFACE_DELETE:
{
if (p_blenetif != NULL)
{
netif_remove(&p_blenetif->netif);
p_blenetif->p_ble_interface = NULL;
err_code = iot_context_manager_table_free(p_interface);
if (err_code == NRF_SUCCESS)
{
NRF_DRIVER_ERR("Successfully freed context table!");
}
nrf_driver_interface_down(p_interface);
}
break;
}
case BLE_6LO_EVT_INTERFACE_DATA_RX:
{
if (p_blenetif != NULL)
{
// Handle received IP packet.
blenetif_input(&p_blenetif->netif,
p_event->event_param.rx_event_param.p_packet,
p_event->event_param.rx_event_param.packet_len);
nrf_free(p_event->event_param.rx_event_param.p_packet);
}
else
{
NRF_DRIVER_ERR("Dropping packet, unknown interface.");
}
break;
}
default:
break;
}
}
/**@brief Driver initialization. */
uint32_t nrf_driver_init(void)
{
uint32_t err_code;
uint32_t index;
ble_6lowpan_init_t init_param;
init_param.event_handler = blenetif_transport_callback;
init_param.p_eui64 = EUI64_LOCAL_IID;
err_code = iot_context_manager_init();
if (err_code == NRF_SUCCESS)
{
// 6lowpan initialization and callback registration.
err_code = ble_6lowpan_init(&init_param);
for (index = 0; index < BLE_6LOWPAN_MAX_INTERFACE; index++)
{
m_blenetif_table[index].p_ble_interface = NULL;
}
}
return err_code;
}
/**@brief Message function to redirect LwIP debug traces to nRF tracing. */
void nrf_message(const char * m)
{
NRF_DRIVER_LOG(m);
}
/**@brief Interface implementation expected by the LwIP stack to get system ticks. */
u32_t sys_now(void)
{
u32_t sys_tick;
sys_tick = app_timer_cnt_get();
//Note: In case prescaler value is changed, this calculation to get sys tick applies.
//Currently, this is not used for saving in code execution as sys_now is called
//often.
//sys_tick = ROUNDED_DIV(((sys_tick & 0x00FFFFF) * (NRF_DRIVER_TIMER_PRESCALER + 1) * 1000), APP_TIMER_CLOCK_FREQ);
//sys_tick *= 8;
return sys_tick;
}
void mem_init(void)
{
}
void *mem_trim(void *mem, mem_size_t size)
{
return nrf_realloc(mem, size);
}
void *mem_malloc(mem_size_t size)
{
return nrf_malloc(size);
}
void *mem_calloc(mem_size_t count, mem_size_t size)
{
return nrf_calloc(count, size);
}
void mem_free(void *mem)
{
nrf_free(mem);
}

View File

@@ -0,0 +1,47 @@
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
/** @file nrf_driver.h
*
* @brief Implements lwip stack driver on nRF.
*
* @details Implements lwip stack driver on nRF.
*/
#ifndef NRF_PLATFORM_PORT_H__
#define NRF_PLATFORM_PORT_H__
#include "iot_common.h"
/**@brief Prescaler value for timer module to get a tick of about 1 ms.
*
* @note Applications using lwIP and this driver, must use this value of prescaler when
* initializing the timer module.
*/
#define NRF_DRIVER_TIMER_PRESCALER 31
/**@brief Initializes the driver for LwIP stack. */
uint32_t nrf_driver_init(void);
/**@brief API assumed to be implemented by the application to handle interface up event.
*
* @param[in] p_interface Identifies the interface.
*/
extern void nrf_driver_interface_up(iot_interface_t const * p_interface);
/**@brief API assumed to be implemented by the application to handle interface down event.
*
* @param[in] p_interface Identifies the interface.
*/
extern void nrf_driver_interface_down(iot_interface_t const * p_interface);
#endif //NRF_PLATFORM_PORT_H__