riscv/esp32c3: Add esp32c3 BLE driver
This commit is contained in:
parent
c89c11a078
commit
8b96edc3a5
@ -133,6 +133,8 @@
|
|||||||
/* Reserved CPU interrupt for specific drivers */
|
/* Reserved CPU interrupt for specific drivers */
|
||||||
|
|
||||||
#define ESP32C3_CPUINT_WMAC 1 /* Wi-Fi MAC */
|
#define ESP32C3_CPUINT_WMAC 1 /* Wi-Fi MAC */
|
||||||
|
#define ESP32C3_CPUINT_BT_BB 5 /* BT BB */
|
||||||
|
#define ESP32C3_CPUINT_RWBLE 8 /* RW BLE */
|
||||||
|
|
||||||
/* IRQ numbers. */
|
/* IRQ numbers. */
|
||||||
|
|
||||||
|
@ -162,6 +162,12 @@ config ESP32C3_RTC_HEAP
|
|||||||
select ARCH_HAVE_EXTRA_HEAPS
|
select ARCH_HAVE_EXTRA_HEAPS
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config ESP32C3_WIRELESS
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select ESP32C3_RT_TIMER
|
||||||
|
select ESP32C3_TIMER0
|
||||||
|
|
||||||
menu "ESP32-C3 Peripheral Support"
|
menu "ESP32-C3 Peripheral Support"
|
||||||
|
|
||||||
config ESP32C3_ADC
|
config ESP32C3_ADC
|
||||||
@ -328,6 +334,22 @@ config ESP32C3_RSA_ACCELERATOR
|
|||||||
---help---
|
---help---
|
||||||
Enable ESP32-C3 RSA accelerator support.
|
Enable ESP32-C3 RSA accelerator support.
|
||||||
|
|
||||||
|
config ESP32C3_WIFI
|
||||||
|
bool "Wi-Fi"
|
||||||
|
default n
|
||||||
|
select NET
|
||||||
|
select ARCH_PHY_INTERRUPT
|
||||||
|
select ESP32C3_WIRELESS
|
||||||
|
---help---
|
||||||
|
Enable Wi-Fi support
|
||||||
|
|
||||||
|
config ESP32C3_BLE
|
||||||
|
bool "BLE"
|
||||||
|
default n
|
||||||
|
select ESP32C3_WIRELESS
|
||||||
|
---help---
|
||||||
|
Enable BLE support
|
||||||
|
|
||||||
endmenu # ESP32-C3 Peripheral Support
|
endmenu # ESP32-C3 Peripheral Support
|
||||||
|
|
||||||
menu "I2C Configuration"
|
menu "I2C Configuration"
|
||||||
@ -641,7 +663,7 @@ endif # ESP32C3_ADC1
|
|||||||
endmenu # ADC Configuration
|
endmenu # ADC Configuration
|
||||||
|
|
||||||
menu "Wi-Fi configuration"
|
menu "Wi-Fi configuration"
|
||||||
depends on ESP32C3_WIRELESS
|
depends on ESP32C3_WIFI
|
||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "ESP32-C3 Wi-Fi mode"
|
prompt "ESP32-C3 Wi-Fi mode"
|
||||||
@ -763,7 +785,29 @@ config ESP32C3_WIFI_RECONNECT
|
|||||||
---help---
|
---help---
|
||||||
Select this option to enable Wi-Fi to reconnect for station when disconnected.
|
Select this option to enable Wi-Fi to reconnect for station when disconnected.
|
||||||
|
|
||||||
endmenu # ESP32C3_WIRELESS
|
endmenu # Wi-Fi configuration
|
||||||
|
|
||||||
|
menu "BLE Configuration"
|
||||||
|
depends on ESP32C3_BLE
|
||||||
|
|
||||||
|
config ESP32C3_BLE_PKTBUF_NUM
|
||||||
|
int "BLE netcard packet buffer number per netcard"
|
||||||
|
default 16
|
||||||
|
|
||||||
|
config ESP32C3_BLE_TTY_NAME
|
||||||
|
string "BLE TTY device name"
|
||||||
|
default "/dev/ttyHCI0"
|
||||||
|
depends on UART_BTH4
|
||||||
|
|
||||||
|
config ESP32C3_BLE_TASK_STACK_SIZE
|
||||||
|
int "Controller task stack size"
|
||||||
|
default 4096
|
||||||
|
|
||||||
|
config ESP32C3_BLE_TASK_PRIORITY
|
||||||
|
int "Controller task priority"
|
||||||
|
default 110
|
||||||
|
|
||||||
|
endmenu # BLE Configuration
|
||||||
|
|
||||||
menu "SPI Flash configuration"
|
menu "SPI Flash configuration"
|
||||||
depends on ESP32C3_SPIFLASH
|
depends on ESP32C3_SPIFLASH
|
||||||
|
@ -178,7 +178,7 @@ endif
|
|||||||
|
|
||||||
ifeq ($(CONFIG_ESP32C3_WIRELESS),y)
|
ifeq ($(CONFIG_ESP32C3_WIRELESS),y)
|
||||||
WIRELESS_DRV_UNPACK = esp-wireless-drivers-3rdparty
|
WIRELESS_DRV_UNPACK = esp-wireless-drivers-3rdparty
|
||||||
WIRELESS_DRV_ID = 2b53111
|
WIRELESS_DRV_ID = df1f8c1
|
||||||
WIRELESS_DRV_ZIP = $(WIRELESS_DRV_ID).zip
|
WIRELESS_DRV_ZIP = $(WIRELESS_DRV_ID).zip
|
||||||
WIRELESS_DRV_URL = https://github.com/espressif/esp-wireless-drivers-3rdparty/archive
|
WIRELESS_DRV_URL = https://github.com/espressif/esp-wireless-drivers-3rdparty/archive
|
||||||
|
|
||||||
@ -200,13 +200,22 @@ clean_context::
|
|||||||
|
|
||||||
INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)include)
|
INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)include)
|
||||||
INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)include$(DELIM)esp32c3)
|
INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)include$(DELIM)esp32c3)
|
||||||
CHIP_CSRCS += esp32c3_wlan.c esp32c3_wifi_utils.c esp32c3_wifi_adapter.c
|
|
||||||
|
|
||||||
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)libs$(DELIM)esp32c3
|
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)libs$(DELIM)esp32c3
|
||||||
EXTRA_LIBS += -lcore -lnet80211 -lpp -lsmartconfig -lcoexist -lespnow -lphy -lwpa_supplicant -lwapi
|
EXTRA_LIBS += -lphy
|
||||||
|
|
||||||
# Due to some Wi-Fi related libraries, the option is need to avoid linking too much
|
# Due to some Wi-Fi related libraries, the option is need to avoid linking too much
|
||||||
# unused functions.
|
# unused functions.
|
||||||
|
|
||||||
LDFLAGS += --gc-sections
|
LDFLAGS += --gc-sections
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ESP32C3_WIFI),y)
|
||||||
|
CHIP_CSRCS += esp32c3_wlan.c esp32c3_wifi_utils.c esp32c3_wifi_adapter.c
|
||||||
|
EXTRA_LIBS += -lcore -lnet80211 -lpp -lsmartconfig -lcoexist -lespnow -lwpa_supplicant -lwapi
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ESP32C3_BLE),y)
|
||||||
|
CHIP_CSRCS += esp32c3_ble_adapter.c esp32c3_ble.c
|
||||||
|
EXTRA_LIBS += -lbtbb -lbtdm_app
|
||||||
|
endif
|
||||||
|
337
arch/risc-v/src/esp32c3/esp32c3_ble.c
Normal file
337
arch/risc-v/src/esp32c3/esp32c3_ble.c
Normal file
@ -0,0 +1,337 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/risc-v/src/esp32c3/esp32c3_ble.c
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <queue.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/nuttx.h>
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
#include <nuttx/wqueue.h>
|
||||||
|
#include <nuttx/net/bluetooth.h>
|
||||||
|
#include <nuttx/wireless/bluetooth/bt_driver.h>
|
||||||
|
#include <nuttx/wireless/bluetooth/bt_uart.h>
|
||||||
|
|
||||||
|
#if defined(CONFIG_UART_BTH4)
|
||||||
|
#include <nuttx/serial/uart_bth4.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "esp32c3_ble_adapter.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* BLE packet buffer max number */
|
||||||
|
|
||||||
|
#define BLE_BUF_NUM CONFIG_ESP32C3_BLE_PKTBUF_NUM
|
||||||
|
|
||||||
|
/* BLE packet buffer max size */
|
||||||
|
|
||||||
|
#define BLE_BUF_SIZE 1024
|
||||||
|
|
||||||
|
/* Low-priority work queue process RX/TX */
|
||||||
|
|
||||||
|
#define BLE_WORK LPWORK
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct esp32c3_ble_priv_s
|
||||||
|
{
|
||||||
|
struct bt_driver_s drv; /* NuttX BT/BLE driver data */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32c3_ble_open(struct bt_driver_s *drv);
|
||||||
|
static int esp32c3_ble_send(struct bt_driver_s *drv,
|
||||||
|
enum bt_buf_type_e type,
|
||||||
|
void *data, size_t len);
|
||||||
|
static void esp32c3_ble_close(struct bt_driver_s *drv);
|
||||||
|
|
||||||
|
static void esp32c3_ble_send_ready(void);
|
||||||
|
static int esp32c3_ble_recv_cb(uint8_t *data, uint16_t len);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static struct esp32c3_ble_priv_s g_ble_priv =
|
||||||
|
{
|
||||||
|
.drv =
|
||||||
|
{
|
||||||
|
.head_reserve = H4_HEADER_SIZE,
|
||||||
|
.open = esp32c3_ble_open,
|
||||||
|
.send = esp32c3_ble_send,
|
||||||
|
.close = esp32c3_ble_close
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static esp_vhci_host_callback_t vhci_host_cb =
|
||||||
|
{
|
||||||
|
.notify_host_send_available = esp32c3_ble_send_ready,
|
||||||
|
.notify_host_recv = esp32c3_ble_recv_cb
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_send_ready
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* If the controller could send HCI comand will callback this function.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void esp32c3_ble_send_ready(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_recv_cb
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* BLE receive callback function when BLE hardware receive packet
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* data - BLE packet data pointer
|
||||||
|
* len - BLE packet length
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* 0 on success or a negated value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32c3_ble_recv_cb(uint8_t *data, uint16_t len)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
bool valid;
|
||||||
|
enum bt_buf_type_e type;
|
||||||
|
struct esp32c3_ble_priv_s *priv = &g_ble_priv;
|
||||||
|
|
||||||
|
switch (data[0])
|
||||||
|
{
|
||||||
|
case H4_EVT:
|
||||||
|
type = BT_EVT;
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
case H4_ACL:
|
||||||
|
type = BT_ACL_IN;
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
case H4_ISO:
|
||||||
|
type = BT_ISO_IN;
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
ret = ERROR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* send packet to host */
|
||||||
|
|
||||||
|
ret = bt_netdev_receive(&priv->drv, type,
|
||||||
|
&data[H4_HEADER_SIZE],
|
||||||
|
len - H4_HEADER_SIZE);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
wlerr("Failed to receive ret=%d\n", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_send
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* ESP32-C3 BLE send callback function for BT driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* drv - BT driver pointer
|
||||||
|
* type - BT packet type
|
||||||
|
* data - BT packte data buffer pointer
|
||||||
|
* len - BT packte length
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Sent bytes on success or a negated value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32c3_ble_send(struct bt_driver_s *drv,
|
||||||
|
enum bt_buf_type_e type,
|
||||||
|
void *data, size_t len)
|
||||||
|
{
|
||||||
|
uint8_t *hdr = (uint8_t *)data - drv->head_reserve;
|
||||||
|
|
||||||
|
if ((len + H4_HEADER_SIZE) > BLE_BUF_SIZE)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == BT_CMD)
|
||||||
|
{
|
||||||
|
*hdr = H4_CMD;
|
||||||
|
}
|
||||||
|
else if (type == BT_ACL_OUT)
|
||||||
|
{
|
||||||
|
*hdr = H4_ACL;
|
||||||
|
}
|
||||||
|
else if (type == BT_ISO_OUT)
|
||||||
|
{
|
||||||
|
*hdr = H4_ISO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (esp32c3_vhci_host_check_send_available())
|
||||||
|
{
|
||||||
|
esp32c3_vhci_host_send_packet(hdr, len + drv->head_reserve);
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_close
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* ESP32-C3 BLE close callback function for BT driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* drv - BT driver pointer
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void esp32c3_ble_close(struct bt_driver_s *drv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_open
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* ESP32-C3 BLE open callback function for BT driver.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* drv - BT driver pointer
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* OK on success or a negated value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32c3_ble_open(struct bt_driver_s *drv)
|
||||||
|
{
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Init BT controller
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* success or fail
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_ble_initialize(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = esp32c3_bt_controller_init();
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
wlerr("Failed to initialize BLE ret=%d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp32c3_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
wlerr("Failed to Enable BLE ret=%d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = esp32c3_vhci_register_callback(&vhci_host_cb);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
wlerr("Failed to register BLE callback ret=%d\n", ret);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_UART_BTH4)
|
||||||
|
ret = uart_bth4_register(CONFIG_BT_UART_ON_DEV_NAME, &g_ble_priv.drv);
|
||||||
|
#else
|
||||||
|
ret = bt_netdev_register(&g_ble_priv.drv);
|
||||||
|
#endif
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
wlerr("bt_netdev_register error: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
50
arch/risc-v/src/esp32c3/esp32c3_ble.h
Normal file
50
arch/risc-v/src/esp32c3/esp32c3_ble.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/risc-v/src/esp32c3/esp32c3_ble.h
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BLE_H
|
||||||
|
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BLE_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_ble_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Init BT controller
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* success or fail
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_ble_initialize(void);
|
||||||
|
|
||||||
|
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BLE_H */
|
2007
arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c
Normal file
2007
arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c
Normal file
File diff suppressed because it is too large
Load Diff
161
arch/risc-v/src/esp32c3/esp32c3_ble_adapter.h
Normal file
161
arch/risc-v/src/esp32c3/esp32c3_ble_adapter.h
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/risc-v/src/esp32c3/esp32c3_ble_adapter.h
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BLE_ADAPTER_H
|
||||||
|
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BLE_ADAPTER_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "esp_bt.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_bt_controller_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Init BT controller.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_bt_controller_init(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_bt_controller_deinit
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Deinit BT controller.
|
||||||
|
* Input Parameters:
|
||||||
|
* cfg - Initial configuration of BT controller.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_bt_controller_deinit(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_bt_controller_enable
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* disable BT controller.
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_bt_controller_enable(esp_bt_mode_t mode);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_bt_controller_disable
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* disable BT controller.
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_bt_controller_disable(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_bt_controller_enable
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Enable BT controller.
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
esp_bt_controller_status_t esp32c3_bt_controller_get_status(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_vhci_host_check_send_available
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* used for check actively if the host can send packet to controller or not.
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* bool - true or false
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool esp32c3_vhci_host_check_send_available(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_vhci_host_send_packet
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* host send packet to controller.
|
||||||
|
* Input Parameters:
|
||||||
|
* data - the packet point
|
||||||
|
* len - the packet length
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void esp32c3_vhci_host_send_packet(uint8_t *data, uint16_t len);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32c3_vhci_register_callback
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* register the vhci reference callback.
|
||||||
|
* Input Parameters:
|
||||||
|
* callback - struct defined by vhci_host_callback structure.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* status - success or fail
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32c3_vhci_register_callback(
|
||||||
|
const esp_vhci_host_callback_t *callback);
|
||||||
|
|
||||||
|
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BLE_ADAPTER_H */
|
@ -88,10 +88,19 @@ void up_irqinitialize(void)
|
|||||||
* Object | CPU INT | Peripheral
|
* Object | CPU INT | Peripheral
|
||||||
* | |
|
* | |
|
||||||
* Wi-Fi | 1 | 1
|
* Wi-Fi | 1 | 1
|
||||||
|
* BT BB | 5 | 5
|
||||||
|
* RW BLE | 8 | 8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32C3_WIRELESS
|
#ifdef CONFIG_ESP32C3_WIRELESS
|
||||||
|
# ifdef CONFIG_ESP32C3_WIFI
|
||||||
g_cpuint_map[ESP32C3_CPUINT_WMAC] = ESP32C3_PERIPH_WIFI_MAC_NMI;
|
g_cpuint_map[ESP32C3_CPUINT_WMAC] = ESP32C3_PERIPH_WIFI_MAC_NMI;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef CONFIG_ESP32C3_BLE
|
||||||
|
g_cpuint_map[ESP32C3_CPUINT_BT_BB] = ESP32C3_PERIPH_BT_BB;
|
||||||
|
g_cpuint_map[ESP32C3_CPUINT_RWBLE] = ESP32C3_PERIPH_RWBLE_IRQ;
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Clear all peripheral interrupts from "bootloader" */
|
/* Clear all peripheral interrupts from "bootloader" */
|
||||||
|
@ -353,6 +353,14 @@ static void *wifi_coex_get_schm_curr_phase(void);
|
|||||||
static int wifi_coex_set_schm_curr_phase_idx(int idx);
|
static int wifi_coex_set_schm_curr_phase_idx(int idx);
|
||||||
static int wifi_coex_get_schm_curr_phase_idx(void);
|
static int wifi_coex_get_schm_curr_phase_idx(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Extern Functions declaration
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32C3_BLE
|
||||||
|
extern void coex_pti_v2(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions declaration
|
* Public Functions declaration
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -2456,6 +2464,9 @@ static void wifi_phy_enable(void)
|
|||||||
esp_phy_enable_clock();
|
esp_phy_enable_clock();
|
||||||
phy_set_wifi_mode_only(0);
|
phy_set_wifi_mode_only(0);
|
||||||
register_chipv7_phy(&phy_init_data, cal_data, PHY_RF_CAL_NONE);
|
register_chipv7_phy(&phy_init_data, cal_data, PHY_RF_CAL_NONE);
|
||||||
|
#ifdef CONFIG_ESP32C3_BLE
|
||||||
|
coex_pti_v2();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
g_phy_access_ref++;
|
g_phy_access_ref++;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32C3_WIRELESS
|
#ifdef CONFIG_ESP32C3_WIFI
|
||||||
|
|
||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -2026,4 +2026,4 @@ int esp32c3_wlan_softap_initialize(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_ESP32C3_WIRELESS */
|
#endif /* CONFIG_ESP32C3_WIFI */
|
||||||
|
@ -40,7 +40,7 @@ extern "C"
|
|||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32C3_WIRELESS
|
#ifdef CONFIG_ESP32C3_WIFI
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
@ -82,7 +82,7 @@ int esp32c3_wlan_sta_initialize(void);
|
|||||||
int esp32c3_wlan_softap_initialize(void);
|
int esp32c3_wlan_softap_initialize(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_ESP32C3_WIRELESS */
|
#endif /* CONFIG_ESP32C3_WIFI */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,7 +22,7 @@ CONFIG_BUILTIN=y
|
|||||||
CONFIG_DRIVERS_IEEE80211=y
|
CONFIG_DRIVERS_IEEE80211=y
|
||||||
CONFIG_DRIVERS_WIRELESS=y
|
CONFIG_DRIVERS_WIRELESS=y
|
||||||
CONFIG_ESP32C3_AUTO_SLEEP=y
|
CONFIG_ESP32C3_AUTO_SLEEP=y
|
||||||
CONFIG_ESP32C3_WIRELESS=y
|
CONFIG_ESP32C3_WIFI=y
|
||||||
CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM=y
|
CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM=y
|
||||||
CONFIG_FS_PROCFS=y
|
CONFIG_FS_PROCFS=y
|
||||||
CONFIG_HAVE_CXX=y
|
CONFIG_HAVE_CXX=y
|
||||||
|
49
boards/risc-v/esp32c3/esp32c3-devkit/configs/ble/defconfig
Normal file
49
boards/risc-v/esp32c3/esp32c3-devkit/configs/ble/defconfig
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
CONFIG_ARCH="risc-v"
|
||||||
|
CONFIG_ARCH_BOARD="esp32c3-devkit"
|
||||||
|
CONFIG_ARCH_BOARD_ESP32C3_DEVKIT=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32c3"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32C3=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32C3WROOM02=y
|
||||||
|
CONFIG_ARCH_INTERRUPTSTACK=1536
|
||||||
|
CONFIG_ARCH_RISCV=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BTSAK=y
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_DRIVERS_BLUETOOTH=y
|
||||||
|
CONFIG_DRIVERS_IEEE80211=y
|
||||||
|
CONFIG_DRIVERS_WIRELESS=y
|
||||||
|
CONFIG_ESP32C3_BLE=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_NAME_MAX=48
|
||||||
|
CONFIG_NET_BLUETOOTH=y
|
||||||
|
CONFIG_NET_SOCKOPTS=y
|
||||||
|
CONFIG_NET_TCP=y
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||||
|
CONFIG_RAW_BINARY=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_SIG_DEFAULT=y
|
||||||
|
CONFIG_SPINLOCK=y
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
|
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||||
|
CONFIG_WIRELESS=y
|
||||||
|
CONFIG_WIRELESS_BLUETOOTH=y
|
@ -32,7 +32,7 @@ CONFIG_ESP32C3_MTD_SIZE=0xf0000
|
|||||||
CONFIG_ESP32C3_SPIFLASH=y
|
CONFIG_ESP32C3_SPIFLASH=y
|
||||||
CONFIG_ESP32C3_WIFI_SAVE_PARAM=y
|
CONFIG_ESP32C3_WIFI_SAVE_PARAM=y
|
||||||
CONFIG_ESP32C3_WIFI_STATION_SOFTAP_COEXISTENCE=y
|
CONFIG_ESP32C3_WIFI_STATION_SOFTAP_COEXISTENCE=y
|
||||||
CONFIG_ESP32C3_WIRELESS=y
|
CONFIG_ESP32C3_WIFI=y
|
||||||
CONFIG_EXAMPLES_DHCPD=y
|
CONFIG_EXAMPLES_DHCPD=y
|
||||||
CONFIG_EXPERIMENTAL=y
|
CONFIG_EXPERIMENTAL=y
|
||||||
CONFIG_FS_PROCFS=y
|
CONFIG_FS_PROCFS=y
|
||||||
|
@ -21,7 +21,7 @@ CONFIG_BOARD_LOOPSPERMSEC=16717
|
|||||||
CONFIG_BUILTIN=y
|
CONFIG_BUILTIN=y
|
||||||
CONFIG_DRIVERS_IEEE80211=y
|
CONFIG_DRIVERS_IEEE80211=y
|
||||||
CONFIG_DRIVERS_WIRELESS=y
|
CONFIG_DRIVERS_WIRELESS=y
|
||||||
CONFIG_ESP32C3_WIRELESS=y
|
CONFIG_ESP32C3_WIFI=y
|
||||||
CONFIG_FS_PROCFS=y
|
CONFIG_FS_PROCFS=y
|
||||||
CONFIG_HAVE_CXX=y
|
CONFIG_HAVE_CXX=y
|
||||||
CONFIG_HAVE_CXXINITIALIZE=y
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
@ -67,6 +67,10 @@
|
|||||||
# include "esp32c3_rtc_lowerhalf.h"
|
# include "esp32c3_rtc_lowerhalf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32C3_BLE
|
||||||
|
# include "esp32c3_ble.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -303,10 +307,20 @@ int esp32c3_bringup(void)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "Failed to initialize RT timer: %d\n", ret);
|
syslog(LOG_ERR, "Failed to initialize RT timer: %d\n", ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32C3_WIRELESS
|
#ifdef CONFIG_ESP32C3_BLE
|
||||||
|
ret = esp32c3_ble_initialize();
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: Failed to initialize BLE\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32C3_WIFI
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32C3_WIFI_SAVE_PARAM
|
#ifdef CONFIG_ESP32C3_WIFI_SAVE_PARAM
|
||||||
ret = esp32c3_init_wifi_storage();
|
ret = esp32c3_init_wifi_storage();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user