saramonteiro commented on a change in pull request #4509: URL: https://github.com/apache/incubator-nuttx/pull/4509#discussion_r715210569
########## File path: arch/xtensa/src/esp32/esp32_ble_adapter.c ########## @@ -0,0 +1,2814 @@ +/**************************************************************************** + * arch/xtensa/src/esp32/esp32_ble_adapter.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 <nuttx/config.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.h> +#include <debug.h> +#include <pthread.h> +#include <fcntl.h> +#include <unistd.h> +#include <clock/clock.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <nuttx/kmalloc.h> +#include <nuttx/mqueue.h> +#include <nuttx/spinlock.h> +#include <nuttx/irq.h> +#include <nuttx/semaphore.h> +#include <nuttx/kthread.h> +#include <nuttx/wdog.h> +#include <nuttx/wqueue.h> +#include <nuttx/sched.h> +#include <nuttx/signal.h> +#include <irq/irq.h> + +#include "hardware/esp32_dport.h" +#include "espidf_wifi.h" +#include "xtensa.h" +#include "xtensa_attr.h" +#include "esp32_rt_timer.h" +#include "esp32_ble_adapter.h" + +#ifdef CONFIG_ESP32_WIFI_BT_COEXIST +# include "esp_coexist_internal.h" +# include "esp_coexist_adapter.h" +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +typedef void (*xt_handler)(void *); +typedef void (* coex_func_cb_t)(uint32_t event, int sched_cnt); + +#define XTHAL_SET_INTSET(v) do { int __interrupt = (int)(v); \ + __asm__ __volatile__("wsr.intset %0" :: "a"(__interrupt):"memory"); \ + } while(0) + +#define ESP_ERR_INVALID_STATE 0x103 + +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff +#define OSI_VERSION 0x00010002 +#define OSI_MAGIC_VALUE 0xfadebead + +#define BTDM_ASYNC_WAKEUP_REQ_HCI 0 +#define BTDM_ASYNC_WAKEUP_REQ_COEX 1 +#define BTDM_ASYNC_WAKEUP_REQMAX 2 + +#ifdef CONFIG_PM +#define BTDM_MIN_TIMER_UNCERTAINTY_US (1800) + +/* Low Power Clock Selection */ + +#define BTDM_LPCLK_SEL_XTAL (0) +#define BTDM_LPCLK_SEL_XTAL32K (1) +#define BTDM_LPCLK_SEL_RTC_SLOW (2) +#define BTDM_LPCLK_SEL_8M (3) + +/* Sleep and wakeup interval control */ + +#define BTDM_MIN_SLEEP_DURATION (24) /* threshold of interval in half slots to allow to fall into modem sleep */ +#define BTDM_MODEM_WAKE_UP_DELAY (8) /* delay in half slots of modem wake up procedure, including re-enable PHY/RF */ +#endif + +#define BTDM_MODEM_SLEEP_MODE_NONE 0 + +#define ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL 0x20200622 + +extern void btdm_controller_set_sleep_mode(uint8_t mode); + +#ifdef CONFIG_ESP32_WIFI_BT_COEXIST +extern void coex_pti_v2(void); +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +#define RTC_CLK_CAL_FRACT 19 /* Number of fractional bits in values returned by rtc_clk_cal */ + +/* DPORT_WIFI_CLK_EN : R/W ;bitpos:[31:0] ;default: 32'hfffce030 ; */ + +#define DPORT_WIFI_CLK_EN 0xFFFFFFFF +#define DPORT_WIFI_CLK_EN_M ((DPORT_WIFI_CLK_EN_V)<<(DPORT_WIFI_CLK_EN_S)) +#define DPORT_WIFI_CLK_EN_V 0xFFFFFFFF +#define DPORT_WIFI_CLK_EN_S 0 + +/* Write value to DPORT register (does not require protecting) */ + +#define DPORT_REG_WRITE(_r, _v) _DPORT_REG_WRITE((_r), (_v)) +#define DPORT_REG_READ(_r) _DPORT_REG_READ(_r) + +#define DPORT_READ_PERI_REG(addr) _DPORT_READ_PERI_REG(addr) +#define _DPORT_READ_PERI_REG(addr) (*((volatile uint32_t *)(addr))) +#define _DPORT_WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)(addr))) = (uint32_t)(val) + +/* Write value to register */ + +#define DPORT_WRITE_PERI_REG(addr, val) _DPORT_WRITE_PERI_REG((addr), (val)) + +/* Set bits of register controlled by mask */ + +#define DPORT_SET_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)|(mask))) + +/* clear bits of register controlled by mask */ + +#define DPORT_CLEAR_PERI_REG_MASK(reg, mask) DPORT_WRITE_PERI_REG((reg), (DPORT_READ_PERI_REG(reg)&(~(mask)))) + +/* BLE message queue private data */ + +struct mq_adpt_s +{ + struct file mq; /* Message queue handle */ + uint32_t msgsize; /* Message size */ + char name[16]; /* Message queue name */ +}; + +/* BLE interrupt adapter private data */ + +struct irq_adpt_s +{ + void (*func)(void *arg); /* Interrupt callback function */ + void *arg; /* Interrupt private data */ +}; + +/* BLE low power control struct */ + +typedef struct btdm_lpcntl_s +{ + uint32_t enable; /* whether low power mode is required */ + uint32_t lpclk_sel; /* low power clock source */ + uint32_t mac_bb_pd; /* whether hardware(MAC, BB) force-power-down is required during sleep */ + uint32_t wakeup_timer_required; /* whether system timer is needed */ + uint32_t no_light_sleep; /* do not allow system to enter light sleep after bluetooth is enabled */ +} btdm_lpcntl_t; + +/* low power control status */ + +typedef struct btdm_lpstat_s +{ + uint32_t pm_lock_released; /* whether power management lock is released */ + uint32_t mac_bb_pd; /* whether hardware(MAC, BB) is powered down */ + uint32_t phy_enabled; /* whether phy is switched on */ + uint32_t wakeup_timer_started; /* whether wakeup timer is started */ +} btdm_lpstat_t; + +/* vendor dependent signals to be posted to controller task */ + +typedef enum +{ + BTDM_VND_OL_SIG_WAKEUP_TMR, + BTDM_VND_OL_SIG_NUM, +} btdm_vnd_ol_sig_t; + +#ifdef CONFIG_PM +/* wakeup request sources */ + +typedef enum +{ + BTDM_ASYNC_WAKEUP_SRC_VHCI, + BTDM_ASYNC_WAKEUP_SRC_DISA, + BTDM_ASYNC_WAKEUP_SRC_TMR, + BTDM_ASYNC_WAKEUP_SRC_MAX, +} btdm_wakeup_src_t; +#endif + +typedef enum +{ + PERIPH_LEDC_MODULE = 0, + PERIPH_UART0_MODULE, + PERIPH_UART1_MODULE, + PERIPH_UART2_MODULE, + PERIPH_I2C0_MODULE, + PERIPH_I2C1_MODULE, + PERIPH_I2S0_MODULE, + PERIPH_I2S1_MODULE, + PERIPH_TIMG0_MODULE, + PERIPH_TIMG1_MODULE, + PERIPH_PWM0_MODULE, + PERIPH_PWM1_MODULE, + PERIPH_PWM2_MODULE, + PERIPH_PWM3_MODULE, + PERIPH_UHCI0_MODULE, + PERIPH_UHCI1_MODULE, + PERIPH_RMT_MODULE, + PERIPH_PCNT_MODULE, + PERIPH_SPI_MODULE, + PERIPH_HSPI_MODULE, + PERIPH_VSPI_MODULE, + PERIPH_SPI_DMA_MODULE, + PERIPH_SDMMC_MODULE, + PERIPH_SDIO_SLAVE_MODULE, + PERIPH_CAN_MODULE, + PERIPH_EMAC_MODULE, + PERIPH_RNG_MODULE, + PERIPH_WIFI_MODULE, + PERIPH_BT_MODULE, + PERIPH_WIFI_BT_COMMON_MODULE, + PERIPH_BT_BASEBAND_MODULE, + PERIPH_BT_LC_MODULE, + PERIPH_AES_MODULE, + PERIPH_SHA_MODULE, + PERIPH_RSA_MODULE, +} periph_module_e; + +/* prototype of function to handle vendor dependent signals */ + +typedef void (* btdm_vnd_ol_task_func_t)(void *param); + +/* VHCI function interface */ + +typedef struct vhci_host_callback_s +{ + void (*notify_host_send_available)(void); /* callback used to notify that the host can send packet to controller */ + int (*notify_host_recv)(uint8_t *data, uint16_t len); /* callback used to notify that the controller has a packet to send to the host */ +} vhci_host_callback_t; + +/* DRAM region */ + +typedef struct btdm_dram_available_region_s +{ + esp_bt_mode_t mode; + intptr_t start; + intptr_t end; +} btdm_dram_available_region_t; + +typedef void (* osi_intr_handler)(void); Review comment: ```suggestion typedef void (*osi_intr_handler)(void); ``` add comment to this function pointer -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org