xiewenxiang commented on a change in pull request #3543: URL: https://github.com/apache/incubator-nuttx/pull/3543#discussion_r616393255
########## File path: arch/risc-v/src/esp32c3/esp32c3_ble_adapter.c ########## @@ -0,0 +1,2059 @@ +/**************************************************************************** + * arch/risc-v/src/esp32c3/esp32c3_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> + +#ifdef CONFIG_ESP32C3_BLE + +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <assert.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 "esp32c3_ble_adapter.h" +#include "hardware/esp32c3_syscon.h" +#include "esp32c3.h" +#include "esp32c3_attr.h" +#include "esp32c3_irq.h" +#include "esp32c3_rt_timer.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 "espidf_wifi.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +#define OSI_FUNCS_TIME_BLOCKING 0xffffffff +#define OSI_VERSION 0x00010006 +#define OSI_MAGIC_VALUE 0xfadebead + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* BLE message queue private data */ + +struct mq_adpt +{ + 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 +{ + void (*func)(void *arg); /* Interrupt callback function */ + void *arg; /* Interrupt private data */ +}; + +/* BLE low power control struct */ + +typedef union +{ + struct + { + uint32_t enable : 1; /* whether low power mode is required */ + uint32_t lpclk_sel : 2; /* low power clock source */ + uint32_t mac_bb_pd : 1; /* whether hardware(MAC, BB) force-power-down is required during sleep */ + uint32_t wakeup_timer_required : 1; /* whether system timer is needed */ + uint32_t no_light_sleep : 1; /* do not allow system to enter light sleep after bluetooth is enabled */ + uint32_t reserved : 26; /* reserved */ + }; + uint32_t val; +} btdm_lpcntl_t; + +/* low power control status */ + +typedef union +{ + struct + { + uint32_t pm_lock_released : 1; /* whether power management lock is released */ + uint32_t mac_bb_pd : 1; /* whether hardware(MAC, BB) is powered down */ + uint32_t phy_enabled : 1; /* whether phy is switched on */ + uint32_t wakeup_timer_started : 1; /* whether wakeup timer is started */ + uint32_t reserved : 28; /* reserved */ + }; + uint32_t val; +} btdm_lpstat_t; + +/* vendor dependent signals to be posted to controller task */ + +typedef enum +{ + BTDM_VND_OL_SIG_WAKEUP_TMR = 0, + BTDM_VND_OL_SIG_NUM, +} btdm_vnd_ol_sig_t; + +/* 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 +{ + 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 +{ + esp_bt_mode_t mode; + intptr_t start; + intptr_t end; +} btdm_dram_available_region_t; + +typedef void (* osi_intr_handler)(void); + +/* BLE OS function */ + +struct osi_funcs_t +{ + uint32_t _magic; + uint32_t _version; + void (*_interrupt_set)(int cpu_no, int intr_source, + int interrupt_no, int interrpt_prio); + void (*_interrupt_clear)(int interrupt_source, int interrupt_no); + void (*_interrupt_handler_set)(int interrupt_no, void * fn, void *arg); + void (*_interrupt_disable)(void); + void (*_interrupt_restore)(void); + void (*_task_yield)(void); + void (*_task_yield_from_isr)(void); + void *(*_semphr_create)(uint32_t max, uint32_t init); + void (*_semphr_delete)(void *semphr); + int (*_semphr_take_from_isr)(void *semphr, void *hptw); + int (*_semphr_give_from_isr)(void *semphr, void *hptw); + int (*_semphr_take)(void *semphr, uint32_t block_time_ms); + int (*_semphr_give)(void *semphr); + void *(*_mutex_create)(void); + void (*_mutex_delete)(void *mutex); + int (*_mutex_lock)(void *mutex); + int (*_mutex_unlock)(void *mutex); + void *(* _queue_create)(uint32_t queue_len, uint32_t item_size); + void (* _queue_delete)(void *queue); + int (* _queue_send)(void *queue, void *item, uint32_t block_time_ms); + int (* _queue_send_from_isr)(void *queue, void *item, void *hptw); + int (* _queue_recv)(void *queue, void *item, uint32_t block_time_ms); + int (* _queue_recv_from_isr)(void *queue, void *item, void *hptw); + int (* _task_create)(void *task_func, const char *name, + uint32_t stack_depth, void *param, uint32_t prio, + void *task_handle, uint32_t core_id); + void (* _task_delete)(void *task_handle); + bool (* _is_in_isr)(void); + int (* _cause_sw_intr_to_core)(int core_id, int intr_no); + void *(* _malloc)(size_t size); + void *(* _malloc_internal)(size_t size); + void (* _free)(void *p); + int (* _read_efuse_mac)(uint8_t mac[6]); + void (* _srand)(unsigned int seed); + int (* _rand)(void); + uint32_t (* _btdm_lpcycles_2_hus)(uint32_t cycles, uint32_t *error_corr); + uint32_t (* _btdm_hus_2_lpcycles)(uint32_t us); + bool (* _btdm_sleep_check_duration)(int32_t *slot_cnt); + void (* _btdm_sleep_enter_phase1)(uint32_t lpcycles); /* called when interrupt is disabled */ + void (* _btdm_sleep_enter_phase2)(void); + void (* _btdm_sleep_exit_phase1)(void); /* called from ISR */ + void (* _btdm_sleep_exit_phase2)(void); /* called from ISR */ + void (* _btdm_sleep_exit_phase3)(void); /* called from task */ + void (* _coex_wifi_sleep_set)(bool sleep); + int (* _coex_core_ble_conn_dyn_prio_get)(bool *low, bool *high); + void (* _coex_schm_status_bit_set)(uint32_t type, uint32_t status); + void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status); + void (* _interrupt_on)(int intr_num); + void (* _interrupt_off)(int intr_num); + void (* _esp_hw_power_down)(void); + void (* _esp_hw_power_up)(void); + void (* _ets_backup_dma_copy)(uint32_t reg, + uint32_t mem_addr, uint32_t num, bool to_rem); Review comment: All of the same problems has been modified. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org