add support for NuttX

This commit is contained in:
Matias N
2020-12-17 18:37:20 +01:00
committed by Andrzej Kaczmarek
parent 542806abc0
commit c14c47bb68
37 changed files with 3663 additions and 11 deletions
+58
View File
@@ -0,0 +1,58 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# * http://www.apache.org/licenses/LICENSE-2.0
# * Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Configure NimBLE variables
NIMBLE_CFG_TINYCRYPT := 1
# Skip files that don't build for this port
NIMBLE_IGNORE := $(NIMBLE_ROOT)/porting/nimble/src/hal_timer.c \
$(NIMBLE_ROOT)/porting/nimble/src/os_cputime.c \
$(NIMBLE_ROOT)/porting/nimble/src/os_cputime_pwr2.c
include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs
CSRCS := $(NIMBLE_SRC)
# Source files for NPL OSAL
CSRCS += \
$(wildcard $(NIMBLE_ROOT)/porting/npl/nuttx/src/*.c) \
$(wildcard $(NIMBLE_ROOT)/nimble/transport/socket/src/*.c) \
$(TINYCRYPT_SRC)
# Source files for demo app
CSRCS += $(NIMBLE_ROOT)/porting/examples/nuttx/ble.c
MAINSRC = $(NIMBLE_ROOT)/porting/examples/nuttx/main.c
# Add NPL and all NimBLE directories to include paths
INC = \
$(wildcard $(NIMBLE_ROOT)/porting/examples/nuttx/include) \
$(NIMBLE_ROOT)/porting/npl/nuttx/include \
$(NIMBLE_ROOT)/nimble/transport/socket/include \
$(NIMBLE_INCLUDE) \
$(TINYCRYPT_INCLUDE)
INCLUDES := $(addprefix -I, $(INC))
CFLAGS += \
$(NIMBLE_CFLAGS) \
$(INCLUDES) \
$(TINYCRYPT_CFLAGS) \
-DNIMBLE_CFG_CONTROLLER=0 -DOS_CFG_ALIGN_4=4 -DOS_CFG_ALIGNMENT=4 \
-Ddefault_RNG_defined=0
PROGNAME=nimble
+118
View File
@@ -0,0 +1,118 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include "nimble/nimble_port.h"
#include "host/ble_hs.h"
#include "host/util/util.h"
#include "services/gap/ble_svc_gap.h"
static const char gap_name[] = "nimble";
static uint8_t own_addr_type;
static void start_advertise(void);
static void
put_ad(uint8_t ad_type, uint8_t ad_len, const void *ad, uint8_t *buf,
uint8_t *len)
{
buf[(*len)++] = ad_len + 1;
buf[(*len)++] = ad_type;
memcpy(&buf[*len], ad, ad_len);
*len += ad_len;
}
static void
update_ad(void)
{
uint8_t ad[BLE_HS_ADV_MAX_SZ];
uint8_t ad_len = 0;
uint8_t ad_flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
put_ad(BLE_HS_ADV_TYPE_FLAGS, 1, &ad_flags, ad, &ad_len);
put_ad(BLE_HS_ADV_TYPE_COMP_NAME, sizeof(gap_name), gap_name, ad, &ad_len);
ble_gap_adv_set_data(ad, ad_len);
}
static int
gap_event_cb(struct ble_gap_event *event, void *arg)
{
switch (event->type) {
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status) {
start_advertise();
}
break;
case BLE_GAP_EVENT_DISCONNECT:
start_advertise();
break;
}
return 0;
}
static void
start_advertise(void)
{
struct ble_gap_adv_params advp;
int rc;
printf("advertise\n");
update_ad();
memset(&advp, 0, sizeof advp);
advp.conn_mode = BLE_GAP_CONN_MODE_UND;
advp.disc_mode = BLE_GAP_DISC_MODE_GEN;
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
&advp, gap_event_cb, NULL);
assert(rc == 0);
}
static void
app_ble_sync_cb(void)
{
int rc;
rc = ble_hs_util_ensure_addr(0);
assert(rc == 0);
rc = ble_hs_id_infer_auto(0, &own_addr_type);
assert(rc == 0);
start_advertise();
}
void
nimble_host_task(void *param)
{
ble_hs_cfg.sync_cb = app_ble_sync_cb;
ble_svc_gap_device_name_set(gap_name);
nimble_port_run();
}
@@ -0,0 +1,32 @@
/**
* This file was generated by Apache newt version: 1.9.0-dev
*/
#ifndef H_MYNEWT_LOGCFG_
#define H_MYNEWT_LOGCFG_
#include "modlog/modlog.h"
#include "log_common/log_common.h"
#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
#define BLE_HS_LOG_INFO(...) MODLOG_INFO(4, __VA_ARGS__)
#define BLE_HS_LOG_WARN(...) MODLOG_WARN(4, __VA_ARGS__)
#define BLE_HS_LOG_ERROR(...) MODLOG_ERROR(4, __VA_ARGS__)
#define BLE_HS_LOG_CRITICAL(...) MODLOG_CRITICAL(4, __VA_ARGS__)
#define BLE_HS_LOG_DISABLED(...) MODLOG_DISABLED(4, __VA_ARGS__)
#define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
#define DFLT_LOG_INFO(...) MODLOG_INFO(0, __VA_ARGS__)
#define DFLT_LOG_WARN(...) MODLOG_WARN(0, __VA_ARGS__)
#define DFLT_LOG_ERROR(...) MODLOG_ERROR(0, __VA_ARGS__)
#define DFLT_LOG_CRITICAL(...) MODLOG_CRITICAL(0, __VA_ARGS__)
#define DFLT_LOG_DISABLED(...) MODLOG_DISABLED(0, __VA_ARGS__)
#define MFG_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
#define MFG_LOG_INFO(...) IGNORE(__VA_ARGS__)
#define MFG_LOG_WARN(...) IGNORE(__VA_ARGS__)
#define MFG_LOG_ERROR(...) IGNORE(__VA_ARGS__)
#define MFG_LOG_CRITICAL(...) IGNORE(__VA_ARGS__)
#define MFG_LOG_DISABLED(...) MODLOG_DISABLED(128, __VA_ARGS__)
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,24 @@
/**
* This file was generated by Apache newt version: 1.9.0-dev
*/
#ifndef H_MYNEWT_SYSFLASH_
#define H_MYNEWT_SYSFLASH_
#include "flash_map/flash_map.h"
/**
* This flash map definition is used for two purposes:
* 1. To locate the meta area, which contains the true flash map definition.
* 2. As a fallback in case the meta area cannot be read from flash.
*/
extern const struct flash_area sysflash_map_dflt[6];
#define FLASH_AREA_BOOTLOADER 0
#define FLASH_AREA_IMAGE_0 1
#define FLASH_AREA_IMAGE_1 2
#define FLASH_AREA_IMAGE_SCRATCH 3
#define FLASH_AREA_REBOOT_LOG 16
#define FLASH_AREA_NFFS 17
#endif
+124
View File
@@ -0,0 +1,124 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "nimble/nimble_npl.h"
#include "nimble/nimble_port.h"
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
#include "services/ans/ble_svc_ans.h"
#include "services/ias/ble_svc_ias.h"
#include "services/lls/ble_svc_lls.h"
#include "services/tps/ble_svc_tps.h"
static struct ble_npl_task s_task_host;
static struct ble_npl_task s_task_hci;
void nimble_host_task(void *param);
void ble_hci_sock_ack_handler(void *param);
void ble_hci_sock_init(void);
void ble_hci_sock_set_device(int dev);
void ble_store_ram_init(void);
#define TASK_DEFAULT_PRIORITY 1
#define TASK_DEFAULT_STACK NULL
#define TASK_DEFAULT_STACK_SIZE 400
void *ble_hci_sock_task(void *param)
{
printf("hci sock task\n");
ble_hci_sock_ack_handler(param);
return NULL;
}
void *ble_host_task(void *param)
{
printf("host task\n");
nimble_host_task(param);
return NULL;
}
int main(int argc, char *argv[])
{
int ret = 0;
/* allow to specify custom hci */
if (argc > 1) {
ble_hci_sock_set_device(atoi(argv[1]));
}
printf("hci init\n");
ble_hci_sock_init();
printf("port init\n");
nimble_port_init();
/* This example provides GATT Alert service */
printf("gap init\n");
ble_svc_gap_init();
printf("gatt init\n");
ble_svc_gatt_init();
printf("ans init\n");
ble_svc_ans_init();
printf("ias init\n");
ble_svc_ias_init();
printf("lls init\n");
ble_svc_lls_init();
printf("tps init\n");
ble_svc_tps_init();
/* XXX Need to have template for store */
ble_store_ram_init();
printf("hci_sock task init\n");
ret = ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task,
NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
if (ret != 0)
{
fprintf(stderr, "error starting hci task: %i\n", ret);
}
/* Create task which handles default event queue for host stack. */
printf("ble_host task init\n");
ret = ble_npl_task_init(&s_task_host, "ble_host", ble_host_task,
NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
if (ret != 0)
{
fprintf(stderr, "error starting ble task: %i\n", ret);
}
while (true)
{
usleep(100);
//pause();
}
return 0;
}