code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __SYSTEM_ARMCM_H__ #define __SYSTEM_ARMCM_H__ #ifdef __cplusplus extern "C" { #endif #include "stdbool.h" extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ void SystemInit (void); // #ifdef UNALIGNED_ACCESS // __STATIC_FORCEINLINE bool get_unaligned_access_status(void) { return true; } // __STATIC_FORCEINLINE bool config_unaligned_access(bool enable) { return true; } // #else bool get_unaligned_access_status(void); bool config_unaligned_access(bool enable); // #endif uint32_t get_cpu_id(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/cmsis/inc/system_ARMCM.h
C
apache-2.0
1,240
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __SYSTEM_CP_H__ #define __SYSTEM_CP_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" void system_cp_reset_handler(void); void system_cp_init(int load_code); void system_cp_term(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/cmsis/inc/system_cp.h
C
apache-2.0
899
/****************************************************************************** * @file tz_context.h * @brief Context Management for Armv8-M TrustZone * @version V1.0.1 * @date 10. January 2018 ******************************************************************************/ /* * Copyright (c) 2017-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed 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 * * 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. */ #if defined ( __ICCARM__ ) #pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) #pragma clang system_header /* treat file as system include file */ #endif #ifndef TZ_CONTEXT_H #define TZ_CONTEXT_H #include <stdint.h> #ifndef TZ_MODULEID_T #define TZ_MODULEID_T /// \details Data type that identifies secure software modules called by a process. typedef uint32_t TZ_ModuleId_t; #endif /// \details TZ Memory ID identifies an allocated memory slot. typedef uint32_t TZ_MemoryId_t; /// Initialize secure context memory system /// \return execution status (1: success, 0: error) uint32_t TZ_InitContextSystem_S (void); /// Allocate context memory for calling secure software modules in TrustZone /// \param[in] module identifies software modules called from non-secure mode /// \return value != 0 id TrustZone memory slot identifier /// \return value 0 no memory available or internal error TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S /// \param[in] id TrustZone memory slot identifier /// \return execution status (1: success, 0: error) uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); /// Load secure context (called on RTOS thread context switch) /// \param[in] id TrustZone memory slot identifier /// \return execution status (1: success, 0: error) uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); /// Store secure context (called on RTOS thread context switch) /// \param[in] id TrustZone memory slot identifier /// \return execution status (1: success, 0: error) uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); #endif // TZ_CONTEXT_H
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/cmsis/inc/tz_context.h
C
apache-2.0
2,687
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __REG_PATCH_H__ #define __REG_PATCH_H__ #include "plat_types.h" #include "plat_addr_map.h" #ifdef PATCH_CTRL_BASE struct PATCH_CTRL_T { __IO uint32_t CTRL[PATCH_ENTRY_NUM]; }; struct PATCH_DATA_T { __IO uint32_t DATA[PATCH_ENTRY_NUM]; }; #define PATCH_CTRL_ENTRY_EN (1 << 0) #define PATCH_CTRL_ADDR_17_2_SHIFT 2 #define PATCH_CTRL_ADDR_17_2_MASK (0xFFFF << PATCH_CTRL_ADDR_17_2_SHIFT) #define PATCH_CTRL_17_2_ADDR(n) BITFIELD_VAL(PATCH_CTRL_30_2_ADDR, n) // For entry 0 only #define PATCH_CTRL_GLOBAL_EN (1 << 31) #define PATCH_CTRL_ADDR_MASK PATCH_CTRL_ADDR_17_2_MASK #define PATCH_CTRL_ADDR(n) ((n) & PATCH_CTRL_ADDR_17_2_MASK) #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/cmsis/reg_patch.h
C
apache-2.0
1,441
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __REG_PATCH_ARMV7M_H__ #define __REG_PATCH_ARMV7M_H__ #ifdef __ARM_ARCH_7EM__ #include "plat_types.h" #include "cmsis.h" struct PATCH_ARMV7M_T { __IO uint32_t FP_CTRL; __IO uint32_t FP_REMAP; __IO uint32_t FP_COMP[512]; }; #define NUM_CODE_6_4_SHIFT 12 #define NUM_CODE_6_4_MASK (0x7 << NUM_CODE_6_4_SHIFT) #define NUM_CODE_6_4(n) BITFIELD_VAL(NUM_CODE_6_4, n) #define NUM_LIT_SHIFT 8 #define NUM_LIT_MASK (0xF << NUM_LIT_SHIFT) #define NUM_LIT(n) BITFIELD_VAL(NUM_LIT, n) #define NUM_CODE_3_0_SHIFT 4 #define NUM_CODE_3_0_MASK (0xF << NUM_CODE_3_0_SHIFT) #define NUM_CODE_3_0(n) BITFIELD_VAL(NUM_CODE_3_0, n) #define FP_CTRL_KEY (1 << 1) #define FP_CTRL_ENABLE (1 << 0) #define REMAP_RMPSPT (1 << 29) #define REMAP_ADDR_28_5_SHIFT 5 #define REMAP_ADDR_28_5_MASK (0xFFFFFF << REMAP_ADDR_28_5_SHIFT) #define REMAP_ADDR_28_5(n) BITFIELD_VAL(REMAP_ADDR_28_5, n) #define REMAP_ADDR_SHIFT 0 #define REMAP_ADDR_MASK (0x1FFFFFFF << REMAP_ADDR_SHIFT) #define REMAP_ADDR(n) BITFIELD_VAL(REMAP_ADDR, n) #define COMP_REPLACE_SHIFT 30 #define COMP_REPLACE_MASK (0x3 << COMP_REPLACE_SHIFT) #define COMP_REPLACE(n) BITFIELD_VAL(COMP_REPLACE, n) #define COMP_ADDR_28_2_SHIFT 2 #define COMP_ADDR_28_2_MASK (0x7FFFFFF << COMP_ADDR_28_2_SHIFT) #define COMP_ADDR_28_2(n) BITFIELD_VAL(COMP_ADDR_28_2, n) #define COMP_ADDR_SHIFT 0 #define COMP_ADDR_MASK (0x1FFFFFFF << COMP_ADDR_SHIFT) #define COMP_ADDR(n) BITFIELD_VAL(COMP_ADDR, n) #define COMP_ENABLE (1 << 0) #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/cmsis/reg_patch_armv7m.h
C
apache-2.0
2,794
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __ANALOG_H__ #define __ANALOG_H__ #ifdef __cplusplus extern "C" { #endif #include "stdbool.h" #include "hal_analogif.h" #include "hal_cmu.h" #include "hal_aud.h" #include "plat_addr_map.h" #include CHIP_SPECIFIC_HDR(analog) #ifndef ISPI_ANA_REG #define ISPI_ANA_REG(reg) (reg) #endif #define analog_read(reg, val) hal_analogif_reg_read(ISPI_ANA_REG(reg), val) #define analog_write(reg, val) hal_analogif_reg_write(ISPI_ANA_REG(reg), val) #define FLOAT_TO_PPB_INT(f) ((int)(f * 1000 * 1000 * 1000)) enum ANA_AUD_PLL_USER_T { ANA_AUD_PLL_USER_CODEC, ANA_AUD_PLL_USER_I2S, ANA_AUD_PLL_USER_SPDIF, ANA_AUD_PLL_USER_PCM, ANA_AUD_PLL_USER_QTY }; void analog_aud_freq_pll_config(uint32_t freq, uint32_t div); void analog_aud_get_dc_calib_value(int16_t *dc_l, int16_t *dc_r); void analog_open(void); void analog_aud_xtal_tune(float ratio); void analog_aud_pll_tune(float ratio); void analog_aud_pll_open(enum ANA_AUD_PLL_USER_T user); void analog_aud_pll_close(enum ANA_AUD_PLL_USER_T user); void analog_aud_set_dac_gain(int32_t v); uint32_t analog_codec_get_dac_gain(void); uint32_t analog_codec_dac_gain_to_db(int32_t gain); int32_t analog_codec_dac_max_attn_db(void); void analog_aud_apply_anc_adc_gain_offset(enum ANC_TYPE_T type, int16_t offset_l, int16_t offset_r); void analog_aud_apply_adc_gain_offset(enum AUD_CHANNEL_MAP_T ch_map, int16_t offset); void analog_aud_codec_open(void); void analog_aud_codec_close(void); void analog_aud_codec_mute(void); void analog_aud_codec_nomute(void); void analog_aud_codec_adc_enable(enum AUD_IO_PATH_T input_path, enum AUD_CHANNEL_MAP_T ch_map, bool en); void analog_aud_codec_dac_enable(bool en); void analog_aud_codec_speaker_enable(bool en); void analog_aud_codec_anc_enable(enum ANC_TYPE_T type, bool en); void analog_aud_mickey_enable(bool en); void analog_sleep(void); void analog_wakeup(void); int analog_debug_config_audio_output(bool diff); int analog_debug_config_codec(uint16_t mv); int analog_debug_config_low_power_adc(bool enable); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/ana/analog.h
C
apache-2.0
2,780
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __PMU_HAAS1000_H__ #define __PMU_HAAS1000_H__ #ifdef __cplusplus extern "C" { #endif #define ISPI_PMU_REG(reg) (((reg) & 0xFFF) | 0x0000) #define ISPI_ANA_REG(reg) (((reg) & 0xFFF) | 0x1000) #define ISPI_RF_REG(reg) (((reg) & 0xFFF) | 0x2000) #define ISPI_WFRF_REG(reg) (((reg) & 0xFFF) | 0x3000) #define ana_read(reg,val) hal_analogif_reg_read(ISPI_ANA_REG(reg),val) #define ana_write(reg,val) hal_analogif_reg_write(ISPI_ANA_REG(reg),val) #define rf_read(reg,val) hal_analogif_reg_read(ISPI_RF_REG(reg),val) #define rf_write(reg,val) hal_analogif_reg_write(ISPI_RF_REG(reg),val) #define wfrf_read(reg,val) hal_analogif_reg_read(ISPI_WFRF_REG(reg),val) #define wfrf_write(reg,val) hal_analogif_reg_write(ISPI_WFRF_REG(reg),val) enum PMU_EFUSE_PAGE_T { PMU_EFUSE_PAGE_SECURITY = 0, PMU_EFUSE_PAGE_BOOT = 1, PMU_EFUSE_PAGE_FEATURE = 2, PMU_EFUSE_PAGE_BATTER_LV = 3, PMU_EFUSE_PAGE_BATTER_HV = 4, PMU_EFUSE_PAGE_SW_CFG = 5, PMU_EFUSE_PAGE_DCDC_CALI = 6, PMU_EFUSE_PAGE_RESERVED_7 = 7, PMU_EFUSE_PAGE_RESERVED_8 = 8, PMU_EFUSE_PAGE_DCCALIB2_L = 9, PMU_EFUSE_PAGE_DCCALIB2_R = 10, PMU_EFUSE_PAGE_DCCALIB_L = 11, PMU_EFUSE_PAGE_DCCALIB_R = 12, PMU_EFUSE_PAGE_DCXO = 13, PMU_EFUSE_PAGE_KEY_INFO1 = 14, PMU_EFUSE_PAGE_KEY_INFO2 = 15, }; enum PMU_PLL_DIV_TYPE_T { PMU_PLL_DIV_DIG, PMU_PLL_DIV_CODEC, PMU_PLL_DIV_PSRAM, }; enum PMU_IRQ_TYPE_T { PMU_IRQ_TYPE_GPADC, PMU_IRQ_TYPE_RTC, PMU_IRQ_TYPE_CHARGER, PMU_IRQ_TYPE_USB_PIN, PMU_IRQ_TYPE_GPIO, PMU_IRQ_TYPE_WDT, PMU_IRQ_TYPE_QTY }; uint8_t pmu_gpio_setup_irq(enum HAL_GPIO_PIN_T pin, const struct HAL_GPIO_IRQ_CFG_T *cfg); void pmu_codec_hppa_enable(int enable); void pmu_codec_mic_bias_enable(uint32_t map); void pmu_pll_div_reset_set(enum HAL_CMU_PLL_T pll); void pmu_pll_div_reset_clear(enum HAL_CMU_PLL_T pll); void pmu_pll_div_set(enum HAL_CMU_PLL_T pll, enum PMU_PLL_DIV_TYPE_T type, uint32_t div); void pmu_led_uart_enable(enum HAL_IOMUX_PIN_T pin); void pmu_led_uart_disable(enum HAL_IOMUX_PIN_T pin); void pmu_wdt_set_force_reboot(uint32_t force); int pmu_set_security_value_to_efuse(void); void pmu_reboot_hook(); void pmu_vcore_set_high_volt(); void pmu_vcore_set_normal_volt(); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/ana/haas1000/pmu_haas1000.h
C
apache-2.0
3,156
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __PMU_H__ #define __PMU_H__ #ifdef __cplusplus extern "C" { #endif #include <stdint.h> #include "hal_analogif.h" #include "hal_cmu.h" #include "hal_gpio.h" #include "plat_addr_map.h" #include CHIP_SPECIFIC_HDR(pmu) #ifndef ISPI_PMU_REG #define ISPI_PMU_REG(reg) (reg) #endif #define pmu_read(reg, val) hal_analogif_reg_read(ISPI_PMU_REG(reg), val) #define pmu_write(reg, val) hal_analogif_reg_write(ISPI_PMU_REG(reg), val) #define PMU_MANUAL_MODE 1 #define PMU_AUTO_MODE 0 #define PMU_LDO_ON 1 #define PMU_LDO_OFF 0 #define PMU_LP_MODE_ON 1 #define PMU_LP_MODE_OFF 0 #define PMU_DSLEEP_MODE_ON 1 #define PMU_DSLEEP_MODE_OFF 0 union SECURITY_VALUE_T { struct { unsigned short security_en :1; unsigned short reg_base :2; unsigned short reg_size :2; unsigned short reg_offset :2; unsigned short reserved :5; unsigned short chksum :4; }; unsigned short reg; }; enum PMU_CHARGER_STATUS_T { PMU_CHARGER_PLUGIN, PMU_CHARGER_PLUGOUT, PMU_CHARGER_UNKNOWN, }; enum PMU_POWER_ON_CAUSE_T { PMU_POWER_ON_CAUSE_NONE, PMU_POWER_ON_CAUSE_POWER_KEY, PMU_POWER_ON_CAUSE_RTC, PMU_POWER_ON_CAUSE_CHARGER, }; enum PMU_USB_PIN_CHK_STATUS_T { PMU_USB_PIN_CHK_NONE, // Chip acts as host PMU_USB_PIN_CHK_DEV_CONN, // Chip acts as host PMU_USB_PIN_CHK_DEV_DISCONN, // Chip acts as device PMU_USB_PIN_CHK_HOST_RESUME, PMU_USB_PIN_CHK_STATUS_QTY }; enum PMU_USB_CONFIG_TYPE_T { PMU_USB_CONFIG_TYPE_NONE, PMU_USB_CONFIG_TYPE_DEVICE, PMU_USB_CONFIG_TYPE_HOST, }; enum PMU_POWER_MODE_T { PMU_POWER_MODE_NONE, PMU_POWER_MODE_LDO, PMU_POWER_MODE_ANA_DCDC, PMU_POWER_MODE_DIG_DCDC, }; enum PMU_VIORISE_REQ_USER_T { PMU_VIORISE_REQ_USER_PWL0, PMU_VIORISE_REQ_USER_PWL1, PMU_VIORISE_REQ_USER_FLASH, PMU_VIORISE_REQ_USER_CHARGER, PMU_VIORISE_REQ_USER_QTY }; typedef void (*PMU_USB_PIN_CHK_CALLBACK)(enum PMU_USB_PIN_CHK_STATUS_T status); typedef void (*PMU_RTC_IRQ_HANDLER_T)(uint32_t seconds); typedef void (*PMU_CHARGER_IRQ_HANDLER_T)(enum PMU_CHARGER_STATUS_T status); typedef void (*PMU_WDT_IRQ_HANDLER_T)(void); typedef void (*PMU_IRQ_UNIFIED_HANDLER_T)(uint16_t irq_status); int pmu_open(void); void pmu_sleep(void); void pmu_wakeup(void); void pmu_mode_change(enum PMU_POWER_MODE_T mode); int pmu_get_security_value(union SECURITY_VALUE_T *val); void pmu_shutdown(void); void pmu_reset(void); int pmu_get_efuse(enum PMU_EFUSE_PAGE_T page, unsigned short *efuse); void pmu_codec_config(int enable); void pmu_anc_config(int enable); void pmu_usb_config(enum PMU_USB_CONFIG_TYPE_T type); void pmu_sleep_en(unsigned char sleep_en); void pmu_flash_write_config(void); void pmu_flash_read_config(void); void pmu_flash_freq_config(uint32_t freq); void pmu_psram_freq_config(uint32_t freq); void pmu_fir_high_speed_config(int enable); void pmu_iir_freq_config(uint32_t freq); void pmu_rs_freq_config(uint32_t freq); void pmu_sys_freq_config(enum HAL_CMU_FREQ_T freq); void pmu_high_performance_mode_enable(bool enable); void pmu_charger_init(void); void pmu_charger_set_irq_handler(PMU_CHARGER_IRQ_HANDLER_T handler); void pmu_charger_plugin_config(void); void pmu_charger_plugout_config(void); enum PMU_CHARGER_STATUS_T pmu_charger_get_status(void); int pmu_usb_config_pin_status_check(enum PMU_USB_PIN_CHK_STATUS_T status, PMU_USB_PIN_CHK_CALLBACK callback, int enable); void pmu_usb_enable_pin_status_check(void); void pmu_usb_disable_pin_status_check(void); void pmu_usb_get_pin_status(int *dp, int *dm); void pmu_rtc_enable(void); void pmu_rtc_disable(void); int pmu_rtc_enabled(void); void pmu_rtc_set(uint32_t seconds); uint32_t pmu_rtc_get(void); void pmu_rtc_set_alarm(uint32_t seconds); uint32_t pmu_rtc_get_alarm(void); void pmu_rtc_clear_alarm(void); int pmu_rtc_alarm_status_set(void); int pmu_rtc_alarm_alerted(); void pmu_rtc_set_irq_handler(PMU_RTC_IRQ_HANDLER_T handler); void pmu_viorise_req(enum PMU_VIORISE_REQ_USER_T user, bool rise); enum PMU_POWER_ON_CAUSE_T pmu_get_power_on_cause(void); int pmu_debug_config_ana(uint16_t volt); int pmu_debug_config_codec(uint16_t volt); int pmu_debug_config_audio_output(bool diff); int pmu_debug_config_vcrystal(bool on); void pmu_debug_reliability_test(int stage); void pmu_at_skip_shutdown(bool enable); void pmu_led_set_direction(enum HAL_GPIO_PIN_T pin, enum HAL_GPIO_DIR_T dir); enum HAL_GPIO_DIR_T pmu_led_get_direction(enum HAL_GPIO_PIN_T pin); void pmu_led_set_voltage_domains(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); void pmu_led_set_pull_select(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel); void pmu_led_set_value(enum HAL_GPIO_PIN_T pin, int data); int pmu_led_get_value(enum HAL_GPIO_PIN_T pin); void pmu_wdt_set_irq_handler(PMU_WDT_IRQ_HANDLER_T handler); int pmu_wdt_config(uint32_t irq_ms, uint32_t reset_ms); void pmu_wdt_start(void); void pmu_wdt_stop(void); void pmu_wdt_feed(void); void pmu_ntc_capture_enable(void); void pmu_ntc_capture_disable(void); int pmu_set_irq_unified_handler(enum PMU_IRQ_TYPE_T type, PMU_IRQ_UNIFIED_HANDLER_T hdlr); enum HAL_PWRKEY_IRQ_T pmu_pwrkey_irq_value_to_state(uint16_t irq_status); void pmu_ft_set_volt(enum PMU_POWER_MODE_T mode, unsigned short normal_v); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/ana/pmu.h
C
apache-2.0
6,247
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __PSRAMUHSPHY_H__ #define __PSRAMUHSPHY_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_addr_map.h" #include CHIP_SPECIFIC_HDR(psramuhsphy) #include "hal_phyif.h" #ifdef SPIPHY_PSRAMUHS0_REG #define SPI_PSRAMUHSPHY0_REG(reg) SPIPHY_PSRAMUHS0_REG(reg) #else #define SPI_PSRAMUHSPHY0_REG(reg) (reg) #endif #ifdef SPIPHY_PSRAMUHS1_REG #define SPI_PSRAMUHSPHY1_REG(reg) SPIPHY_PSRAMUHS1_REG(reg) #else #define SPI_PSRAMUHSPHY1_REG(reg) (reg) #endif #define psramuhsphy0_read(reg, val) hal_phyif_reg_read(SPI_PSRAMUHSPHY0_REG(reg), val) #define psramuhsphy0_write(reg, val) hal_phyif_reg_write(SPI_PSRAMUHSPHY0_REG(reg), val) #define psramuhsphy1_read(reg, val) hal_phyif_reg_read(SPI_PSRAMUHSPHY1_REG(reg), val) #define psramuhsphy1_write(reg, val) hal_phyif_reg_write(SPI_PSRAMUHSPHY1_REG(reg), val) void psramuhsphy_open(uint32_t clk); void psramuhsphy_init_calib(void); void psramuhsphy_calib(uint32_t clk); void psramuhsphy_sleep(void); void psramuhsphy_wakeup(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/ana/psramuhsphy.h
C
apache-2.0
1,724
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __USBPHY_H__ #define __USBPHY_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "plat_addr_map.h" #include CHIP_SPECIFIC_HDR(usbphy) #include "hal_analogif.h" #include "hal_phyif.h" #ifdef SPIPHY_USB_REG #define SPI_USBPHY_REG(reg) SPIPHY_USB_REG(reg) #elif defined(ISPI_USBPHY_REG) #define SPI_USBPHY_REG(reg) ISPI_USBPHY_REG(reg) #else #define SPI_USBPHY_REG(reg) (reg) #endif #ifdef CHIP_HAS_SPIPHY #define usbphy_read(reg, val) hal_phyif_reg_read(SPI_USBPHY_REG(reg), val) #define usbphy_write(reg, val) hal_phyif_reg_write(SPI_USBPHY_REG(reg), val) #else #define usbphy_read(reg, val) hal_analogif_reg_read(SPI_USBPHY_REG(reg), val) #define usbphy_write(reg, val) hal_analogif_reg_write(SPI_USBPHY_REG(reg), val) #endif void usbphy_open(void); void usbphy_close(void); void usbphy_sleep(void); void usbphy_wakeup(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/ana/usbphy.h
C
apache-2.0
1,630
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __BT_DRV_H__ #define __BT_DRV_H__ #ifdef __cplusplus extern "C" { #endif #include "cmsis.h" #ifdef RTOS #include "cmsis_os.h" #endif #include "hal_timer.h" #include "hal_analogif.h" #include "hal_trace.h" #define BT_DRV_REG_OP_ENTER() do{ uint32_t stime, spent_time; stime= hal_sys_timer_get(); #define BT_DRV_REG_OP_EXIT() spent_time = TICKS_TO_MS(hal_sys_timer_get()-stime);if (spent_time>2000)TRACE("%s exit, %dms",__func__, spent_time);}while(0); #if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || defined(CHIP_HAAS1000) #define BTDRV_ISPI_RF_REG(reg) (((reg) & 0xFFF) | 0x2000) #define WIFI_ISPI_WFRF_REG(reg) (((reg) & 0xFFF) | 0x3000) #else #define BTDRV_ISPI_RF_REG(reg) (reg) #endif #define btdrv_read_rf_reg(reg,val) hal_analogif_reg_read(BTDRV_ISPI_RF_REG(reg),val) #define btdrv_write_rf_reg(reg,val) hal_analogif_reg_write(BTDRV_ISPI_RF_REG(reg),val) #ifndef _btdrv_read_wifi_reg_ #define btdrv_read_wifi_reg(reg,val) hal_analogif_reg_read(WIFI_ISPI_WFRF_REG(reg),val) #define _btdrv_read_wifi_reg_ #endif #ifndef _btdrv_write_wifi_reg_ #define btdrv_write_wifi_reg(reg,val) hal_analogif_reg_write(WIFI_ISPI_WFRF_REG(reg),val) #define _btdrv_write_wifi_reg_ #endif #define btdrv_delay(ms) hal_sys_timer_delay(MS_TO_TICKS(ms)) #define BTDIGITAL_REG(a) (*(volatile uint32_t *)(a)) #define BTDIGITAL_BT_EM(a) (*(volatile uint16_t *)(a)) /// Macro to write a BT control structure field (16-bit wide) #define BTDIGITAL_EM_BT_WR(addr, value) (*(volatile uint16_t *)(addr)) = (value) #define BTDIGITAL_REG_SET_FIELD(reg, mask, shift, v)\ do{ \ volatile unsigned int tmp = *(volatile unsigned int *)(reg); \ tmp &= ~(mask<<shift); \ tmp |= (v<<shift); \ *(volatile unsigned int *)(reg) = tmp; \ }while(0) #define BTDIGITAL_REG_GET_FIELD(reg, mask, shift, v)\ do{ \ volatile unsigned int tmp = *(volatile unsigned int *)(reg); \ v = (tmp>>shift)&mask; \ }while(0) #define DRV_DEBUG 1 #if DRV_DEBUG #define DRV_PRINT(fmt, ...) TRACE(fmt, ##__VA_ARGS__) #define DRV_DUMP(s,buff,len) DUMP8(s,buff,len) #else #define DRV_PRINT(fmt, ...) #define DRV_DUMP(s,buff,len) #endif #if defined(CHIP_BEST2300) || defined(__FPGA_BT_2300__) #define BT_EM_ADDR_BASE (0xD021114A) #define BT_EM_SIZE (110) #define BLE_EM_CS_SIZE (90) #define EM_BT_PWRCNTL_ADDR (BT_EM_ADDR_BASE + 0x16) #define EM_BT_BT_EXT1_ADDR (BT_EM_ADDR_BASE + 0x66) #define EM_BT_BITOFF_ADDR (BT_EM_ADDR_BASE + 0x02) #define EM_BT_CLKOFF0_ADDR (BT_EM_ADDR_BASE + 0x04) #define EM_BT_CLKOFF1_ADDR (BT_EM_ADDR_BASE + 0x06) #define EM_BT_WINCNTL_ADDR (BT_EM_ADDR_BASE + 0x1A) #define EM_BT_RXBIT_ADDR (BT_EM_ADDR_BASE + 0x56) #define EM_BT_BTADDR1_ADDR (BT_EM_ADDR_BASE + 0xC) #define EM_BT_LINKCNTL_ADDR (BT_EM_ADDR_BASE + 0x8) #define EM_BT_RXDESCCNT_ADDR (BT_EM_ADDR_BASE + 0x5A) #define EM_BT_AUDIOBUF_OFF 0xd021449c #define EM_BT_RXACLBUFPTR_ADDR 0xd02115a0 #define REG_EM_BT_RXDESC_SIZE 14 #define LBRT_TX_PWR_FIX (3) #define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE (0xc0000050) #define DEFAULT_XTAL_FCAP 0x8080 #elif defined(CHIP_BEST2300P) || defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || defined(__FPGA_BT_1400__) || defined(CHIP_HAAS1000) #define BT_EM_ADDR_BASE (0xD02111A2) #define BT_EM_SIZE (110) #define BLE_EM_CS_SIZE (90) #define EM_BT_PWRCNTL_ADDR (BT_EM_ADDR_BASE + 0x16) #define EM_BT_BT_EXT1_ADDR (BT_EM_ADDR_BASE + 0x66) #define EM_BT_BITOFF_ADDR (BT_EM_ADDR_BASE + 0x02) #define EM_BT_CLKOFF0_ADDR (BT_EM_ADDR_BASE + 0x04) #define EM_BT_CLKOFF1_ADDR (BT_EM_ADDR_BASE + 0x06) #define EM_BT_WINCNTL_ADDR (BT_EM_ADDR_BASE + 0x1A) #define EM_BT_RXBIT_ADDR (BT_EM_ADDR_BASE + 0x56) #define EM_BT_BTADDR1_ADDR (BT_EM_ADDR_BASE + 0xC) #define EM_BT_LINKCNTL_ADDR (BT_EM_ADDR_BASE + 0x8) #define BLE_CRCINIT1_ADDR (0xd02100c2) #define EM_BT_RXDESCCNT_ADDR (BT_EM_ADDR_BASE + 0x5A) #define BLE_MAXEVTIME_ADDR (0xd02100d0) #define EM_BT_AUDIOBUF_OFF 0xd02144fc #define EM_BT_RXACLBUFPTR_ADDR 0xd02115f8 #define REG_EM_BT_RXDESC_SIZE 16 #define LBRT_TX_PWR_FIX (3) #define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE (0xc0000050) #define DEFAULT_XTAL_FCAP 0x8080 #elif defined(__FPGA_BT_1500__) #define BT_EM_ADDR_BASE (0xD0213000) #define BT_EM_SIZE (104) #define BLE_EM_CS_SIZE (112) #define EM_BT_PWRCNTL_ADDR (BT_EM_ADDR_BASE + 0x14) #define EM_BT_BT_EXT1_ADDR (BT_EM_ADDR_BASE + 0x60) #define EM_BT_BITOFF_ADDR //(BT_EM_ADDR_BASE + 0x02) #define EM_BT_CLKOFF0_ADDR (BT_EM_ADDR_BASE + 0x02) #define EM_BT_CLKOFF1_ADDR (BT_EM_ADDR_BASE + 0x04) #define EM_BT_WINCNTL_ADDR (BT_EM_ADDR_BASE + 0x18) #define EM_BT_RXBIT_ADDR (BT_EM_ADDR_BASE + 0x56) #define EM_BT_BTADDR1_ADDR (BT_EM_ADDR_BASE + 0x8) #define EM_BT_LINKCNTL_ADDR (BT_EM_ADDR_BASE + 0x6) #define EM_BT_RXDESCCNT_ADDR (BT_EM_ADDR_BASE + 0x5A) #define EM_BT_AUDIOBUF_OFF 0xd02144fc #define EM_BT_RXACLBUFPTR_ADDR 0xd02115f8 #define REG_EM_BT_RXDESC_SIZE 16 #define LBRT_TX_PWR_FIX (3) #define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE (0xc0000050) #define DEFAULT_XTAL_FCAP 0x8080 #else #define BT_EM_ADDR_BASE (0xD0210190) #define BT_EM_SIZE (96) #define BT_CONTROLLER_CRASH_DUMP_ADDR_BASE (0xc00064cc) #endif #ifndef __FPGA_BT_1500__ //#define FPGA_1303 #endif //bt max slot clock #define MAX_SLOT_CLOCK ((1L<<27) - 1) // A slot is 625 us #define SLOT_SIZE 625 //#define __PASS_CI_TEST_SETTING__ #define BT_LOW_POWER_MODE 1 #define BT_HIGH_PERFORMANCE_MODE 2 //#define __ENABLE_LINK_POWER_CONTROL__ #define BT_RFMODE BT_LOW_POWER_MODE //#define BT_RFMODE BT_HIGH_PERFORMANCE_MODE //#define BT_50_FUNCTION #define BT_POWERON 1 #define BT_POWEROFF 0 /// 8 bit access types #define _8_Bit 8 /// 16 bit access types #define _16_Bit 16 /// 32 bit access types #define _32_Bit 32 #define BTDRV_PATCH_WRITING 0x0 #define BTDRV_PATCH_DONE 0x1 #define BTDRV_CFG_WRITING 0x0 #define BTDRV_CFG_DONE 0x1 #define HCI_DBG_RD_MEM_CMD_OPCODE 0xFC01 #define HCI_DBG_WR_MEM_CMD_OPCODE 0xFC02 #define HCI_DBG_DEL_PAR_CMD_OPCODE 0xFC03 #define HCI_DBG_FLASH_ID_CMD_OPCODE 0xFC05 #define HCI_DBG_FLASH_ER_CMD_OPCODE 0xFC06 #define HCI_DBG_FLASH_WR_CMD_OPCODE 0xFC07 #define HCI_DBG_FLASH_RD_CMD_OPCODE 0xFC08 #define HCI_DBG_RD_PAR_CMD_OPCODE 0xFC09 #define HCI_DBG_WR_PAR_CMD_OPCODE 0xFC0A #define HCI_DBG_WLAN_COEX_CMD_OPCODE 0xFC0B #define HCI_DBG_ENTER_TEST_MODE_CMD_OPCODE 0xFC0C #define HCI_DBG_WLAN_COEXTST_SCEN_CMD_OPCODE 0xFC0D #define HCI_DBG_SEND_LMP_CMD_OPCODE 0xFC0E #define HCI_DBG_WR_SYNC_DATA_CFG_CMD_OPCODE 0xFC0F #define HCI_DBG_RD_KE_STATS_CMD_OPCODE 0xFC10 #define HCI_DBG_PLF_RESET_CMD_OPCODE 0xFC11 #define HCI_DBG_RD_MEM_INFO_CMD_OPCODE 0xFC12 #define HCI_DBG_EMUL_TESTER_CMD_OPCODE 0xFC2D #define HCI_DBG_SCATT_IMPROV_CMD_OPCODE 0xFC2E #define HCI_DBG_RF_REG_RD_CMD_OPCODE 0xFC39 #define HCI_DBG_RF_REG_WR_CMD_OPCODE 0xFC3A #define HCI_DBG_HW_REG_RD_CMD_OPCODE 0xFC30 #define HCI_DBG_HW_REG_WR_CMD_OPCODE 0xFC31 #define HCI_DBG_SET_BD_ADDR_CMD_OPCODE 0xFC32 #define HCI_DBG_SET_TYPE_PUB_CMD_OPCODE 0xFC33 #define HCI_DBG_SET_TYPE_RAND_CMD_OPCODE 0xFC34 #define HCI_DBG_SET_CRC_CMD_OPCODE 0xFC35 #define HCI_DBG_LLCP_DISCARD_CMD_OPCODE 0xFC36 #define HCI_DBG_RESET_RX_CNT_CMD_OPCODE 0xFC37 #define HCI_DBG_RESET_TX_CNT_CMD_OPCODE 0xFC38 #define HCI_DBG_SET_TX_PW_CMD_OPCODE 0xFC3B #define HCI_DBG_SET_SYNCWORD_CMD_OPCODE 0xFC3C //encrytion min and max key size #define HCI_DBG_SET_ENCRYPTION_KEY_SIZE_CMD_OPCODE 0xFC41 //preferred key type default :combine key #define HCI_DBG_SET_PREFERRED_KEY_TYPE_CMD_OPCODE 0xFC42 //creat unit key #define HCI_DBG_CREAT_UNIT_KEY_CMD_OPCODE 0xFC43 //set clk drift and jitter #define HCI_DBG_SET_LPCLK_DRIFT_JITTER_CMD_OPCODE 0xFC44 //set exernal wake up time oscillater wakeup time and radio wakeup time #define HCI_DBG_SET_WAKEUP_TIME_CMD_OPCODE 0xFC45 //change uart buadrate #define HCI_DBG_CHANGE_UART_BAUDRATE_CMD_OPCODE 0xFC46 //set sleep enable and external wakeup enable #define HCI_DBG_SET_SLEEP_EXWAKEUP_EN_CMD_OPCODE 0xFC47 //set private key #define HCI_DBG_SET_SP_PRIVATE_KEY_CMD_OPCODE 0xFC48 //set public key #define HCI_DBG_SET_SP_PUBLIC_KEY_CMD_OPCODE 0xFC49 //set errdata adopted #define HCI_DBG_SET_ERRDATA_ADOPTED_CMD_OPCODE 0xFC4A //set basic threshold #define HCI_DBG_SET_BASIC_THRESHOLD_CMD_OPCODE 0xFC4B //set edr threshold #define HCI_DBG_SET_EDR_THRESHOLD_CMD_OPCODE 0xFC4C //set basic algorithm #define HCI_DBG_SET_BASIC_ALGORITHM_CMD_OPCODE 0xFC4D //set edr alorithm #define HCI_DBG_SET_EDR_ALGORITHM_CMD_OPCODE 0xFC4E //set basic packet lut #define HCI_DBG_SET_BASIC_PKT_LUT_CMD_OPCODE 0xFC4F //set edr packet lut #define HCI_DBG_SET_EDR_PKT_LUT_CMD_OPCODE 0xFC50 //set diag_bt_hw #define HCI_DBG_SET_DIAG_BT_HW_CMD_OPCODE 0xFC54 //set diag ble hw #define HCI_DBG_SET_DIAG_BLE_HW_CMD_OPCODE 0xFC55 //set diag sw #define HCI_DBG_SET_DIAG_SW_CMD_OPCODE 0xFC56 //set ble channel assessment parameter #define HCI_DBG_SET_BLE_CA_PARA_CMD_OPCODE 0xFC57 //set ble rf timing //set ble rf timig //set ble rl size #define HCI_DBG_SET_RL_SIZE_CMD_OPCODE 0xFC5D ///set hostwake #define HCI_DBG_SET_HOSTWAKE_CMD_OPCODE 0xFC5E //reserved for VCO test #define HCI_DBG_BT_VCO_TEST_CMD_OPCODE 0xFCAA #if defined(CHIP_BEST2300) || defined(CHIP_BEST2300P) || \ defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \ defined(CHIP_HAAS1000) || \ defined(__FPGA_BT_2300__) ||defined(__FPGA_BT_1400__) || \ defined(__FPGA_BT_1500__) ///set dle dft value #define HCI_DBG_WR_DLE_DFT_VALUE_CMD_OPCODE 0xFC41 #define HCI_DBG_SET_SLEEP_SETTING_CMD_OPCODE 0xFC77 //bt address not ble address #define HCI_DBG_SET_BT_ADDR_CMD_OPCODE 0xFC72 //set pcm setting #define HCI_DBG_SET_PCM_SETTING_CMD_OPCODE 0xFC74 #define HCI_DBG_SET_RSSI_THRHLD_CMD_OPCODE 0xFC76 //set sync buff size #define HCI_DBG_SET_SYNC_BUF_SIZE_CMD_OPCODE 0xFC7F //set afh algorithm #define HCI_DBG_SET_AFH_ALGORITHM_CMD_OPCODE 0xFC80 //set local feature #define HCI_DBG_SET_LOCAL_FEATURE_CMD_OPCODE 0xFC81 #define HCI_DBG_SET_BT_RF_TIMING_CMD_OPCODE 0xFC83 //set local extend feature #define HCI_DBG_SET_LOCAL_EX_FEATURE_CMD_OPCODE 0xFC82 #define HCI_DBG_SET_2300_BT_RF_TIMING_CMD_OPCODE 0xFC83 #define HCI_DBG_SET_BLE_RF_TIMING_CMD_OPCODE 0xfc84 //bt setting interface #define HCI_DBG_SET_BT_SETTING_CMD_OPCODE 0xFC86 // xiao add for nonsignaling test mode #define HCI_DBG_NONSIG_TESTER_SETUP_CMD_OPCODE 0xFC87 /* xiao add for custom set param*/ #define HCI_DBG_SET_CUSTOM_PARAM_CMD_OPCODE 0xFC88 #define HCI_DBG_SET_SCO_SWITCH_CMD_OPCODE 0xFC89 #define HCI_DBG_SET_SNIFFER_ENV_CMD_OPCODE 0xFC8E //set sco path #define HCI_DBG_SET_SYNC_CONFIG_CMD_OPCODE 0xFC8F #define HCI_DBG_START_TWS_EXCHANGE_CMD_OPCODE 0xFC91 #define HCI_DBG_BTADDR_EXCHANGE_CMD_OPCODE 0xFC92 #define HCI_DBG_SEND_DATA_TO_PEER_DEV_CMD_OPCODE 0xFC93 #define HCI_DBG_SCO_TX_SILENCE_CMD_OPCODE 0xFC94 #define HCI_DBG_SNIFFER_CMD_OPCODE 0xFC95 #define HCI_DBG_CSB_UPDATE_LINK_PARAM_CMD_OPCODE 0xFC96 #define HCI_DBG_SET_LINK_LBRT_CMD_OPCODE 0xFC97 #define HCI_DBG_SET_CON_SLV_BCST_DATA_CMD_OPCODE 0xFC98 #define HCI_DBG_SET_ROLE_SWITCH_INSTANT_CMD_OPCODE 0xFC99 #define HCI_DBG_LOW_LAYER_METRICS_CMD_OPCODE 0xFC9B #define HCI_DBG_LMP_MESSAGE_RECORD_CMD_OPCODE 0xFC9C #define HCI_DBG_SET_LOCAL_FEATURE_50_CMD_OPCODE 0xFC72 #define HCI_DBG_SET_SLEEP_SETTING_50_CMD_OPCODE 0xFC70 #define HCI_DBG_SET_BT_SETTING_50_CMD_OPCODE 0xFC71 #define HCI_DBG_SET_CUSTOM_PARAM_50_CMD_OPCODE 0xFC73 #define HCI_DBG_SET_BT_SETTING_EXT1_CMD_OPCODE 0xFCAE #define HCI_DBG_SET_BT_TWS_LINK_CMD_OPCODE 0xFCAF #define HCI_DBG_SET_AFH_FOLLOW_CMD_OPCODE 0xFCB0 #define HCI_DBG_SET_RF_RX_GAIN_THS_TBL_CMD_OPCODE 0xFCB1 #define HCI_DBG_SET_RF_RX_GAIN_FIXED_CMD_OPCODE 0xFCB2 #else //bt address not ble address #define HCI_DBG_SET_BT_ADDR_CMD_OPCODE 0xFC40 //set sco path #define HCI_DBG_SET_SYNC_CONFIG_CMD_OPCODE 0xFC51 //set pcm setting #define HCI_DBG_SET_PCM_SETTING_CMD_OPCODE 0xFC52 //set sync buff size #define HCI_DBG_SET_SYNC_BUF_SIZE_CMD_OPCODE 0xFC53 //set local feature #define HCI_DBG_SET_LOCAL_FEATURE_CMD_OPCODE 0xFC59 //bt setting interface #define HCI_DBG_SET_BT_SETTING_CMD_OPCODE 0xFC5F //set afh algorithm #define HCI_DBG_SET_AFH_ALGORITHM_CMD_OPCODE 0xFC58 //set local extend feature #define HCI_DBG_SET_LOCAL_EX_FEATURE_CMD_OPCODE 0xFC5A #define HCI_DBG_SET_BT_RF_TIMING_CMD_OPCODE 0xFC5B #define HCI_DBG_SET_BLE_RF_TIMING_CMD_OPCODE 0xFC5C // xiao add for nonsignaling test mode #define HCI_DBG_NONSIG_TESTER_SETUP_CMD_OPCODE 0xFC60 /* xiao add for custom set param*/ #define HCI_DBG_SET_CUSTOM_PARAM_CMD_OPCODE 0xFC61 #define HCI_DBG_SET_SCO_SWITCH_CMD_OPCODE 0xFC62 #define HCI_DBG_SET_SNIFFER_ENV_CMD_OPCODE 0xFC67 #define HCI_DBG_START_TWS_EXCHANGE_CMD_OPCODE 0xFC69 #define HCI_DBG_BTADDR_EXCHANGE_CMD_OPCODE 0xFC6A #define HCI_DBG_SEND_DATA_TO_PEER_DEV_CMD_OPCODE 0xFC6B #define HCI_DBG_SCO_TX_SILENCE_CMD_OPCODE 0xFC6C #define HCI_DBG_SNIFFER_CMD_OPCODE 0xFC6D #define HCI_DBG_BT_VCO_TEST_CMD_OPCODE 0xFCAA // Only new controller IP has this funciton,it is a error opcode #define HCI_DBG_SET_ROLE_SWITCH_INSTANT_CMD_OPCODE 0xFCFF #define HCI_DBG_SET_LINK_LBRT_CMD_OPCODE 0xFCFF #define HCI_DBG_SET_BT_SETTING_EXT1_CMD_OPCODE 0xFCFF #define HCI_DBG_SET_BT_TWS_LINK_CMD_OPCODE 0xFCFF #define HCI_DBG_SET_AFH_FOLLOW_CMD_OPCODE 0xFCFF #define HCI_DBG_SET_RF_RX_GAIN_THS_TBL_CMD_OPCODE 0xFCFF #define HCI_DBG_SET_RF_RX_GAIN_FIXED_CMD_OPCODE 0xFCFF #endif // 2300, 2300p, 1400,1402,1501 #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/bt/bt_drv.h
C
apache-2.0
16,316
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __BT_DRV_INTERFACE_H__ #define __BT_DRV_INTERFACE_H__ #include "stdint.h" #include "stdbool.h" //LMP Opcodes #define LMP_NAME_REQ_OPCODE 1 #define LMP_NAME_RES_OPCODE 2 #define LMP_ACCEPTED_OPCODE 3 #define LMP_NOT_ACCEPTED_OPCODE 4 #define LMP_CLK_OFF_REQ_OPCODE 5 #define LMP_CLK_OFF_RES_OPCODE 6 #define LMP_DETACH_OPCODE 7 #define LMP_INRAND_OPCODE 8 #define LMP_COMBKEY_OPCODE 9 #define LMP_UNITKEY_OPCODE 10 #define LMP_AURAND_OPCODE 11 #define LMP_SRES_OPCODE 12 #define LMP_TEMPRAND_OPCODE 13 #define LMP_TEMPKEY_OPCODE 14 #define LMP_ENC_MODE_REQ_OPCODE 15 #define LMP_ENC_KEY_SIZE_REQ_OPCODE 16 #define LMP_START_ENC_REQ_OPCODE 17 #define LMP_STOP_ENC_REQ_OPCODE 18 #define LMP_SWITCH_REQ_OPCODE 19 #define LMP_HOLD_OPCODE 20 #define LMP_HOLD_REQ_OPCODE 21 #define LMP_SNIFF_REQ_OPCODE 23 #define LMP_UNSNIFF_REQ_OPCODE 24 #define LMP_PARK_REQ_OPCODE 25 #define LMP_SET_BSWIN_OPCODE 27 #define LMP_MODIF_BEACON_OPCODE 28 #define LMP_UNPARK_BD_REQ_OPCODE 29 #define LMP_UNPARK_PM_REQ_OPCODE 30 #define LMP_INCR_PWR_REQ_OPCODE 31 #define LMP_DECR_PWR_REQ_OPCODE 32 #define LMP_MAX_PWR_OPCODE 33 #define LMP_MIN_PWR_OPCODE 34 #define LMP_AUTO_RATE_OPCODE 35 #define LMP_PREF_RATE_OPCODE 36 #define LMP_VER_REQ_OPCODE 37 #define LMP_VER_RES_OPCODE 38 #define LMP_FEATS_REQ_OPCODE 39 #define LMP_FEATS_RES_OPCODE 40 #define LMP_QOS_OPCODE 41 #define LMP_QOS_REQ_OPCODE 42 #define LMP_SCO_LINK_REQ_OPCODE 43 #define LMP_RMV_SCO_LINK_REQ_OPCODE 44 #define LMP_MAX_SLOT_OPCODE 45 #define LMP_MAX_SLOT_REQ_OPCODE 46 #define LMP_TIMING_ACCU_REQ_OPCODE 47 #define LMP_TIMING_ACCU_RES_OPCODE 48 #define LMP_SETUP_CMP_OPCODE 49 #define LMP_USE_SEMI_PERM_KEY_OPCODE 50 #define LMP_HOST_CON_REQ_OPCODE 51 #define LMP_SLOT_OFF_OPCODE 52 #define LMP_PAGE_MODE_REQ_OPCODE 53 #define LMP_PAGE_SCAN_MODE_REQ_OPCODE 54 #define LMP_SUPV_TO_OPCODE 55 #define LMP_TEST_ACTIVATE_OPCODE 56 #define LMP_TEST_CTRL_OPCODE 57 #define LMP_ENC_KEY_SIZE_MASK_REQ_OPCODE 58 #define LMP_ENC_KEY_SIZE_MASK_RES_OPCODE 59 #define LMP_SET_AFH_OPCODE 60 #define LMP_ENCAPS_HDR_OPCODE 61 #define LMP_ENCAPS_PAYL_OPCODE 62 #define LMP_SP_CFM_OPCODE 63 #define LMP_SP_NB_OPCODE 64 #define LMP_DHKEY_CHK_OPCODE 65 #define LMP_PAUSE_ENC_AES_REQ_OPCODE 66 // CARE: round-off error #define BT_CLK_UNIT 312.5 //us #define BT_CLK_UNIT_2X 625 //us #define BT_CLK_UNIT_10X 3125 //us #define US_TO_BTCLKS(us) ((uint64_t)(us) * 2 / BT_CLK_UNIT_2X) #define BTCLKS_TO_US(n) ((uint64_t)(n) * BT_CLK_UNIT_2X / 2) #define DUT_CONNECT_STATUS_CONNECTED (1) #define DUT_CONNECT_STATUS_DISCONNECTED (2) #define BT_TRIG_NONE_ROLE (0) #define BT_TRIG_MASTER_ROLE (1) #define BT_TRIG_SLAVE_ROLE (2) #define btdrv_set_intersys_trace_enable() beshci_set_intersys_trace_enable() #define btdrv_set_spuv_hci_buff_trace_enable() beshci_set_supv_hci_buff_trace_enable() #define btdrv_set_a2dp_stream_trace_disable() beshci_set_a2dp_stream_trace_enable(false) #define btdrv_enable_sleep_checker(isEnable) beshci_enable_sleep_checker(isEnable) void btdrv_hciopen(void); void btdrv_hcioff(void); void bt_drv_extra_config_after_init(void); void btdrv_rf_init_ext(void); void btdrv_testmode_start(void); void btdrv_hci_reset(void); void btdrv_enable_nonsig_tx(uint8_t index); void btdrv_enable_nonsig_rx(uint8_t index); void bt_drv_calib_open(void); void bt_drv_check_calib(void); void bt_drv_calib_close(void); int bt_drv_calib_result_porc(uint32_t *capval); void bt_drv_calib_rxonly_porc(void); void btdrv_write_localinfo(char *name, uint8_t len, uint8_t *addr); void btdrv_disable_scan(void); #ifdef __cplusplus extern "C" { #endif void btdrv_start_bt(void); void btdrv_stop_bt(void); void btdrv_enable_dut(void); void bt_drv_rf_reset(void); void btdrv_sleep_config(uint8_t sleep_en); void btdrv_feature_default(void); void btdrv_test_mode_addr_set(void); int btdrv_meinit_param_init(void); int btdrv_meinit_param_remain_size_get(void); int btdrv_meinit_param_next_entry_get(uint32_t *addr, uint32_t *val); void btdrv_store_device_role(bool slave); bool btdrv_device_role_is_slave(void); uint32_t btdrv_rf_get_max_xtal_tune_ppb(void); uint32_t btdrv_rf_get_xtal_tune_factor(void); void btdrv_rf_init_xtal_fcap(uint32_t fcap); uint32_t btdrv_rf_get_init_xtal_fcap(void); uint32_t btdrv_rf_get_xtal_fcap(void); void btdrv_rf_set_xtal_fcap(uint32_t fcap, uint8_t is_direct); int btdrv_rf_xtal_fcap_busy(uint8_t is_direct); void btdrv_rf_bit_offset_track_enable(bool enable); void btdrv_rf_bit_offset_track_force_disable(void); uint32_t btdrv_rf_bit_offset_get(void); void btdrv_uart_bridge_loop(void); void btdrv_testmode_data_overide(void); void btdrv_set_bt_pcm_triggler_delay(uint8_t delay); void btdrv_set_bt_pcm_en(uint8_t en); uint16_t btdrv_rf_bitoffset_get(uint8_t conidx); void btdrv_syn_clr_trigger(void); uint32_t btdrv_rf_bit_offset_get(void); uint32_t btdrv_syn_get_curr_ticks(void); uint32_t bt_syn_get_curr_ticks(uint16_t conhdl); void bt_syn_set_tg_ticks(uint32_t val,uint16_t conhdl, uint8_t mode); void bt_syn_trig_checker(uint16_t conhdl); void btdrv_syn_trigger_codec_en(uint32_t v); uint32_t btdrv_get_syn_trigger_codec_en(void); uint32_t btdrv_get_trigger_ticks(void); void btdrv_rf_trig_patch_enable(bool enable); void btdrv_tws_trig_role(uint8_t role); void btdrv_rf_set_conidx(uint32_t conidx); #define ACL_TRIGGLE_MODE 1 #define SCO_TRIGGLE_MODE 2 void btdrv_enable_playback_triggler(uint8_t triggle_mode); void btdrv_set_bt_pcm_triggler_en(uint8_t en); void btdrv_set_bt_pcm_triggler_delay(uint8_t delay); void btdrv_set_bt_pcm_triggler_delay_reset(uint8_t delay); void btdrv_set_pcm_data_ignore_crc(void); uint8_t btdrv_conhdl_to_linkid(uint16_t connect_hdl); void btdrv_set_tws_role_triggler(uint8_t tws_mode); void btdrv_enable_dual_slave_configurable_slot_mode(bool isEnable, uint16_t activeDevHandle, uint8_t activeDevRole, uint16_t idleDevHandle, uint8_t idleDevRole); void btdrv_ins_patch_test_init(void); void btdrv_dynamic_patch_moble_disconnect_reason_hacker(uint16_t hciHandle); void btdrv_dynamic_patch_sco_status_clear(void); uint32_t btdrv_dut_get_connect_status(void); void btdrv_set_powerctrl_rssi_low(uint16_t rssi); void btdrv_seq_bak_mode(uint8_t mode,uint8_t linkid); void btdrv_enable_one_packet_more_head(bool enable); #if defined(CHIP_BEST2300) || defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || defined(CHIP_BEST2300P) || defined(CHIP_HAAS1000) void btdrv_linear_format_16bit_set(void); void btdrv_pcm_enable(void); void btdrv_pcm_disable(void); void btdrv_spi_trig_data_change(uint8_t spi_sel, uint8_t index, uint32_t value); void btdrv_spi_trig_data_set(uint8_t spi_sel); uint8_t btdrv_get_spi_trig_enable(uint8_t spi_sel); void btdrv_set_spi_trig_enable(uint8_t spi_sel); void btdrv_clear_spi_trig_enable(uint8_t spi_sel); void btdrv_spi_trig_init(void); void btdrv_spi_trig_select(uint8_t link_id, bool spi_set); void bt_drv_reg_cs_monitor(void); void btdrv_set_controller_trace_enable(uint8_t trace_level); uint8_t btdrv_get_controller_trace_level(void); bool btdrv_get_lmp_trace_enable(void); void btdrv_set_lmp_trace_enable(void); #endif void bt_drv_select_hwspi1(uint8_t link_id); bool btdrv_get_controller_trace_dump_enable(void); void btdrv_set_controller_trace_dump_enable(void); void beshci_enable_sleep_checker(bool isEnable); void beshci_set_intersys_trace_enable(void); void beshci_set_supv_hci_buff_trace_enable(void); void beshci_set_a2dp_stream_trace_enable(bool enable); bool btdrv_rf_rx_gain_adjust_getstatus(void); bool btdrv_rf_blerx_gain_adjust_getstatus(void); void btdrv_rf_blerx_gain_adjust_default(void); void btdrv_rf_blerx_gain_adjust_lowgain(void); void btdrv_send_cmd(uint16_t opcode,uint8_t cmdlen,const uint8_t *param); void btdrv_write_memory(uint8_t wr_type,uint32_t address,const uint8_t *value,uint8_t length); void bt_drv_patch_force_disconnect_ack(void); void bt_dev_music_link_config(uint16_t active_link,uint8_t active_role,uint16_t inactive_link,uint8_t inactive_role); void btdrv_memory_copy(uint32_t *dest,const uint32_t *src,uint16_t length); #if defined(TX_RX_PCM_MASK) uint8_t btdrv_is_pcm_mask_enable(void); #endif void btdrv_set_lpo_times(void); #if defined(PCM_FAST_MODE) void btdrv_open_pcm_fast_mode_enable(void); void btdrv_open_pcm_fast_mode_disable(void); #endif #if defined(CVSD_BYPASS) void btdrv_cvsd_bypass_enable(void); #endif void btdrv_write_private_public_key(uint8_t* private_key,uint8_t* public_key); void btdrv_hwagc_mode_set(uint8_t sync_mode); #define BTCLK_STATUS_PRINT() do{ \ TRACE("[%s] %d: curr bt time= %d", __func__, __LINE__, bt_syn_get_curr_ticks(app_tws_get_tws_conhdl())); \ }while(0) #define IS_ENABLE_BT_DRIVER_REG_DEBUG_READING 0 #define BT_DRIVER_GET_U8_REG_VAL(regAddr) (*(uint8_t *)(regAddr)) #define BT_DRIVER_GET_U16_REG_VAL(regAddr) (*(uint16_t *)(regAddr)) #define BT_DRIVER_GET_U32_REG_VAL(regAddr) (*(uint32_t *)(regAddr)) #define BT_DRIVER_PUT_U8_REG_VAL(regAddr, val) *(uint8_t *)(regAddr) = (val) #define BT_DRIVER_PUT_U16_REG_VAL(regAddr, val) *(uint16_t *)(regAddr) = (val) #define BT_DRIVER_PUT_U32_REG_VAL(regAddr, val) *(uint32_t *)(regAddr) = (val) void bt_drv_acl_tx_silence(uint16_t connHandle, uint8_t on); int btdrv_slave2master_clkcnt_convert(uint32_t local_clk, uint16_t local_cnt, int32_t clk_offset, uint16_t bit_offset, uint32_t *master_clk, uint16_t *master_cnt); int btdrv_clkcnt_diff(int32_t clk1, int16_t cnt1, int32_t clk2, int16_t cnt2, int32_t *diff_clk, uint16_t *diff_bit); bool bt_drv_set_ble_conn_latency(uint16_t ble_conhdl, uint16_t conn_latency); uint16_t bt_drv_get_ble_conn_latency(uint16_t ble_conhdl); void bt_drv_set_reconnecting_flag(); uint32_t bt_drv_get_reconnecting_flag(); void bt_drv_clear_reconnecting_flag(); bool bt_drv_is_enhanced_ibrt_rom(void); bool bt_drv_is_bes_fa_mode_en(void); uint16_t bt_drv_get_ibrt_sco_hdl(uint16_t acl_hdl); void bt_drv_get_ibrt_address(uint8_t *addr); void btdrv_enable_rf_sw(int rx_on, int tx_on); void btdrv_trigger_coredump(void); bool btdrv_is_ecc_enable(void); void bt_drv_adaptive_fa_rx_gain(int8_t rssi); void* bt_drv_get_btstack_chip_config(void); void btdrv_spi_sel_ble_setf(int elt_idx, uint8_t spiselble); #ifdef __SW_TRIG__ void btdrv_play_trig_mode_set(uint8_t mode); void btdrv_sw_trig_master_set(uint32_t Tclk_M, int16_t Tbit_M_h_ori); void btdrv_sw_trig_slave_calculate_and_set(uint16_t conhdl, uint32_t Tclk_M, int16_t Tbit_M_h_ori); #endif void btdrv_set_bdr_ble_txpower(uint8_t div, uint8_t power_level); void btdrv_set_edr_txpower(uint8_t div, uint8_t power_level); void btdrv_vco_test_start(uint8_t chnl); void btdrv_vco_test_stop(void); void btdrv_switch_to_i2c(void); void write_reg32(uint32_t reg32, uint32_t value); void read_reg32(uint32_t reg32); void nosignal_set_max_power_level(void); void nosignal_clear_max_power_level(void); void write_reg16(uint8_t reg16, uint16_t value); void read_reg16(uint8_t reg16); void wifi_write_reg16(uint8_t reg16, uint16_t value); void wifi_read_reg16(uint8_t reg16); void bt_drv_set_wlan_onoff(uint8_t en); void bt_drv_set_ble_adv_transq_on(uint8_t en); void bt_drv_set_ble_conn_transq_on(uint8_t en); void bt_drv_set_sniff_transq_on(uint8_t en); void bt_drv_set_rsw_transq_on(uint8_t en); void bt_drv_set_pscan_transq_on(uint8_t en); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/bt/bt_drv_interface.h
C
apache-2.0
12,954
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __BT_DRV_INTERNAL_H__ #define __BT_DRV_INTERNAL_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" typedef uint32_t BT_CONTROLER_TRACE_TYPE; #define BT_CONTROLER_TRACE_TYPE_INTERSYS 0x01 #define BT_CONTROLER_TRACE_TYPE_CONTROLLER 0x02 #define BT_CONTROLER_TRACE_TYPE_LMP_TRACE 0x04 #define BT_CONTROLER_TRACE_TYPE_SPUV_HCI_BUFF 0x08 #define BT_CONTROLER_FILTER_TRACE_TYPE_A2DP_STREAM 0x10 #define BT_CONTROLER_TRACE_TYPE_DUMP_BUFF 0x20 #define BT_SUB_SYS_TYPE 0 #define MCU_SYS_TYPE 1 #define BT_EM_AREA_1_TYPE 2 #define BT_EM_AREA_2_TYPE 3 uint8_t btdrv_rf_init(void); void btdrv_test_mode_rf_txpwr_init(void); void btdrv_ins_patch_init(void); void btdrv_data_patch_init(void); void btdrv_patch_en(uint8_t en); void btdrv_config_init(void); void btdrv_testmode_config_init(void); void btdrv_bt_spi_rawbuf_init(void); void btdrv_bt_spi_xtal_init(void); void btdrv_sync_config(void); void btdrv_rf_rx_gain_adjust_req(uint32_t user, bool lowgain); #ifdef BT_50_FUNCTION void btdrv_config_init_ble5(void); void btdrv_ins_patch_init_50(void); void btdrv_data_patch_init_50(void); #endif void btdrv_trace_config(BT_CONTROLER_TRACE_TYPE trace_config); void btdrv_dump_mem(uint8_t *dump_mem_start, uint32_t dump_length, uint8_t dump_type); void ld_util_bch_create(uint8_t *lap, uint8_t *bch); void bt_drv_ble_sup_timeout_set(uint16_t ble_conhdl, uint16_t sup_to); void btdrv_ecc_config(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/bt/bt_drv_internal.h
C
apache-2.0
2,205
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __CODEC_INT_H__ #define __CODEC_INT_H__ #include "plat_addr_map.h" #include "plat_types.h" #include "hal_codec.h" #include "hal_aud.h" #include CHIP_SPECIFIC_HDR(codec) #ifdef __cplusplus extern "C" { #endif typedef void (*CODEC_CLOSE_HANDLER)(void); enum CODEC_CLOSE_TYPE_T { CODEC_CLOSE_NORMAL, CODEC_CLOSE_ASYNC_REAL, CODEC_CLOSE_FORCED, }; uint32_t codec_int_open(void); uint32_t codec_int_stream_open(enum AUD_STREAM_T stream); uint32_t codec_int_stream_setup(enum AUD_STREAM_T stream, struct HAL_CODEC_CONFIG_T *cfg); void codec_int_stream_mute(enum AUD_STREAM_T stream, bool mute); void codec_int_stream_set_chan_vol(enum AUD_STREAM_T stream, enum AUD_CHANNEL_MAP_T ch_map, uint8_t vol); void codec_int_stream_restore_chan_vol(enum AUD_STREAM_T stream); uint32_t codec_int_stream_start(enum AUD_STREAM_T stream); uint32_t codec_int_stream_stop(enum AUD_STREAM_T stream); uint32_t codec_int_stream_close(enum AUD_STREAM_T stream); uint32_t codec_int_close(enum CODEC_CLOSE_TYPE_T type); void codec_int_set_close_handler(CODEC_CLOSE_HANDLER hdlr); typedef void (*CODEC_ANC_HANDLER)(enum AUD_STREAM_T stream, enum AUD_SAMPRATE_T rate, enum AUD_SAMPRATE_T *new_play, enum AUD_SAMPRATE_T *new_cap); int codec_anc_open(enum ANC_TYPE_T type, enum AUD_SAMPRATE_T dac_rate, enum AUD_SAMPRATE_T adc_rate, CODEC_ANC_HANDLER hdlr); int codec_anc_close(enum ANC_TYPE_T type); int codec_vad_open(const struct AUD_VAD_CONFIG_T *cfg); int codec_vad_close(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/codec/codec_int.h
C
apache-2.0
2,169
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __CODEC_HAAS1000_H__ #define __CODEC_HAAS1000_H__ #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/codec/haas1000/codec_haas1000.h
C
apache-2.0
786
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __BES_IRLIB_H__ #define __BES_IRLIB_H__ //#include "net_defs.h" #ifdef RTOS #include "cmsis_os.h" #endif #include "cmsis.h" #include "hal_timer.h" #include "hal_cmu.h" #include "hal_pwm.h" #include "hal_gpio.h" #ifdef __cplusplus extern "C" { #endif #if 0 #define ir_printf(s,...) TRACE(s, ##__VA_ARGS__) #define ir_printf_debug(s,...) TRACE(s, ##__VA_ARGS__) #define ir_printf_info(s,...) TRACE(s, ##__VA_ARGS__) #define ir_printf_warn(s,...) TRACE(s, ##__VA_ARGS__) #else #define ir_printf(s,...) printf(s, ##__VA_ARGS__) #define ir_printf_debug(...) #define ir_printf_info(s,...) printf(s, ##__VA_ARGS__) #define ir_printf_warn(s,...) printf(s, ##__VA_ARGS__) #endif #define MAX_IR_TX_BUF 512 //FUNCTION DEFILE #define CONFIG_IR_CHECK_ADDR_AND_CODE 1 #define CONFIG_IR_TIMER2 1 /* * NEC protocal Show: * 8 bits addr, 8 bits cmd code. * send addr and cmd code twice every time to improve reliable. * ----------------------------------------------------------------------------- * | Logical '1' | Logical '0' | Logical 'x' | * ----------------------------------------------------------------------------- * | 1(carrier)| 0 | 1(carrier)| 0 | 1(carrier)| - | * ----------------------------------------------------------------------------- * | 560uS | 1680uS | 560uS | 560uS | 560uS | | * | 2.25mS | 1.12mS | | | * ----------------------------------------------------------------------------- * 1(pulses): f=38KHz, T=26.3us, N=560/26.3=21 * 38KHz carrier frequency. * bit time is 1.12ms or 2.25ms. * send time is 68ms, send cycle is 110ms. * example: send 0x89(1001 0001 LSB first) addr, 0x82(0100 0001 LSB first) cmd code. * --------------------------------------------------------------------------------------------------------------------- * | S1 | S2 |L1|L0|L0|L1|L0|L0|L0|L1|L0|L1|L1|L0|L1|L1|L1|L0|L0|L1|L0|L0|L0|L0|L0|L1|L1|L1|L0|L1|L0|L1|L1|L1| E1 | * | 9mS |4.5mS|LSB MSB|LSB MSB|LSB MSB|LSB MSB|560uS| * | Start | 0x89 Address | ~0x89 Address | 0x82 Command | ~0x82 Command | End | * --------------------------------------------------------------------------------------------------------------------- * the repeat code S2 is 2.25mS. * * code dealt: * 0x89 = b 1000 1001 right shift >> dealt bit,so will get: b 1001 0001 (LSB First) * ~0x89 = b 0111 0110 right shift >> dealt bit,so will get: b 0110 1110 (LSB First) * 0x82 = b 1000 0010 right shift >> dealt bit,so will get: b 0100 0001 * ~0x82 = b 0111 1101 right shift >> dealt bit,so will get: b 1011 1110 * * 0x0b = b 0000 1011 right shift >> dealt bit,so will get: b 1101 0000 (LSB First) * */ /***************************************************************************** * struct or unit *****************************************************************************/ /** * Media r05d cmd. */ typedef enum { DRV_CMD_R05D_POWEROFF = 2, /* R05d power off command */ DRV_CMD_R05D_NORMAL = 4, } IR_R05D_T; #if 1 /* IR return parameter definition */ typedef enum { IR_OK = 0x00, /* IR OK,SUCCESS*/ IR_BUSY = 0x01, /* IR is busy state */ IR_PARAM_ERROR = 0x02, /* IR parameters error */ IR_MEM_ERROR = 0X03, /* IR memory error */ IR_UNKNOW = 0x04 /* IR UNKNOW state */ } IR_RET_T; #endif /* IR cmd definition */ typedef enum { IR_CMD_TX = 0x00, /* IR TX */ IR_CMD_RX = 0x01, /* IR RX */ IR_CMD_SLEEP = 0x02, /* IR SLEEP */ IR_CMD_EXIT = 0x03, /* EXIT */ IR_CMD_ERROR = 0x04, /* Error */ } IR_CMD_T; /* IR FINISH EVENT definition */ typedef enum { IR_TX_FINISH_EVENT = 0x00, /* IR ONE CODE TRANSMIT FINISHED */ IR_TX_TIMEOUT_EVENT = 0x01, /* IR TX TIMEOUT EVENT */ IR_TX_ERROR_EVENT = 0x02, /* IR TX ERROR EVENT */ } IR_EVENT_T; /* IR STATE */ typedef enum { IR_IDLE_STATE = 0x00, /* IDLE MODE*/ IR_TX_STATE = 0x01, /* BUSY! TX Doing */ IR_RX_STATE = 0X02, /* BUSY! RX Doing */ } IR_STATE_T; /* IR STUDY STATE */ typedef enum { IR_STU_INIT = 0x00, /* Study initial state */ IR_STU_DOING = 0x01, /* Study doing */ IR_STU_EXIT = 0X02, /* Study exit */ } IR_STUDY_T; /* * ir protocal. */ typedef enum { IR_STUDY_PROTO = 0, /* 学习到的码,这里简称学习协议 */ IR_NEC_PROTO, /* NEC protocol */ IR_ITT_PROTO, /* ITT protocol */ IR_MEDIA_R05D_PROTO, /* Media R05d protocol */ IR_GREE_YB0F2_PROTO, /* GREE YB0F2 protocol*/ IR_PROTO_MAX } IR_PROTO_T; /***************************************************************************** * functions *****************************************************************************/ typedef void (* IR_HW_FUNC)(void); typedef void (* IR_HW_START_FUNC)(uint32_t time); typedef void (* IR_CARRIER_INIT_FUNC)(enum HAL_IOMUX_PIN_T gpio); typedef void (* IR_CARRIER_FUNC)(void); typedef int (* IR_CARRIER_START_FUNC)(uint32_t carrier_freq, uint8_t freq_ratio); typedef void (* IR_TX_CB)(int type); typedef void (* IR_RX_CB)(IR_PROTO_T proto,uint16_t *frame,uint16_t num,uint8_t repeat); typedef void (* INPUT_CB)(uint32_t tm, enum HAL_GPIO_IRQ_POLARITY_T polarity); typedef struct { IR_HW_FUNC rtx_timer_init; /* 红外定时器初始化*/ IR_HW_START_FUNC txr_timer_start; /* 红外定时器设置周期并开启 */ IR_HW_FUNC txr_timer_stop; /* 红外定时器暂停 */ IR_HW_FUNC trx_timer_free; /* 释放红外定时*/ } IR_FUNC_S; typedef struct { IR_CARRIER_INIT_FUNC carrier_init; /* 红外载波初始化 */ IR_CARRIER_START_FUNC carrier_start; /* 红外载波发送开始 */ IR_CARRIER_FUNC carrier_stop; /* 红外载波发送停止 */ } IR_CARRI_F_S; #if 0 typedef struct { osMutexId mutex_id; #if (osCMSIS >= 0x20000U) osMutexAttr_t mutex_attr; #else uint32_t os_mutex_cb[3]; #endif }IR_MUTEX_T; #endif typedef struct ir_finish_event { uint8_t event_id; /**< even ID */ } IR_EVENT_S; typedef struct { uint8_t ircode[8]; /* useing bytes to code*/ uint16_t nums; /* ir code/frame number */ uint8_t cmd; /* IR RX OR IR TX cmd*/ uint16_t *frame; /* ir frame time buf */ IR_PROTO_T proto; /* ir protocal */ uint8_t repeat; /* ir repeat: 1 true,0: flase ; 像空调这种没有repeat的,可以直接复用代码命令*/ /*定义 bit0 for repeat bit1~4: other cmd */ } IR_MESG_S; typedef struct { uint8_t mode; /* repeat mode,<1>: repeat mode,<0>: no repeat mode*/ uint8_t repeat_sending; /* repeat sending <1>,doing repeat,<0>,normal*/ uint8_t framenum; /* ir repeat frame numbers*/ uint16_t frametime[4]; /* ir repeat time buffer */ //uint32_t repeat_interval; /* ir repeat interval*/ }IR_REPEAT_S; /********************** * 红外载波参数结构体 **********************/ typedef struct { enum HAL_PWM_ID_T id; /* 载波pwd id */ uint8_t ratio; /* 频率占空比 */ uint16_t freq; /* 载波频率 */ uint16_t *txbuf; /* ir tx time buffer */ uint16_t txnum; /* txbuf time numbers */ uint8_t txfinish; /* 标志红外码是否发送完 */ IR_REPEAT_S repeat; IR_PROTO_T prototal; /* IR protocal */ // IR_MUTEX_T tx_mutex; /* tx mutex */ IR_CARRI_F_S *funcs; /* tx functions */ } IR_CARRI_S; typedef struct { IR_TX_CB app_tx_cb; /* ir tx app cb func */ IR_RX_CB app_rx_cb; /* ir rx app cb func */ INPUT_CB app_input_cb; /* input app cb func */ }IR_CB_FUNCS; /********************** * 红外接收参数结构体 **********************/ typedef struct { uint8_t rx_mode; //接收模式: uint16_t *rx_frame; //每帧时间 uint16_t rx_num; //uint8_t rx_triger; //用于标志收到第一个中断 IR_STUDY_T study_state; //红外学习状态。 enum HAL_GPIO_PIN_T io; //GPIO } IR_RX_S; /********************** * 红外参数结构体 **********************/ typedef struct { IR_FUNC_S *ir_funcs; IR_STATE_T ir_state; } IR_PARAM_S; extern IR_CARRI_F_S ir_init_tx_funcs; extern IR_PARAM_S ir_pub_parm; extern IR_CARRI_S *ir_tx_param; extern IR_RX_S ir_rx_parm; extern IR_FUNC_S ir_init_cb; /*************************************************************** * Function : ir_get_status * Description : 获取红外工作状态 * Input : None * Output : None * Return : IR_STATE_T ****************************************************************/ IR_STATE_T ir_get_status(void); /*************************************************************** * Function : ir_set_status * Description : 设置红外工作状态 * Input : IR_STATE_T * Output : None * Return : None ****************************************************************/ void ir_set_status(const IR_STATE_T state); /*************************************************************** * Function : ir_get_status * Description : 获取红外学习状态 * Input : None * Output : None * Return : IR_RX_S ****************************************************************/ IR_STUDY_T ir_rx_get_status(void); /*************************************************************** * Function : ir_rx_set_status * Description : 设置红外学习状态 * Input : IR_STUDY_T * Output : None * Return : None ****************************************************************/ void ir_rx_set_status(const IR_STUDY_T state); /*************************************************************** * Function : ir_rx_gpio_irq_enable * Description : * Input : None * Output : None * Return : 0: success; others: failed ****************************************************************/ uint8_t ir_rx_gpio_irq_enable(void); /*************************************************************** * Function : ir_rx_gpio_irq_disable * Description : * Input : None * Output : None * Return : 0: success; others: failed ****************************************************************/ uint8_t ir_rx_gpio_irq_disable(void); /*************************************************************** * Function : ir_mailbox_put * Description : * Input : IR_MESG_S * * Output : None * Return : 0: success; others: failed ****************************************************************/ int ir_mailbox_put(IR_MESG_S *input); /*************************************************************** * Function : ir_mailbox_init * Description : * Input : None * Output : None * Return : 0: success; others: failed ****************************************************************/ int ir_mailbox_init(void); /*************************************************************** * Function : ir_tx_feedback_mailbox_init * Description : * Input : None * Output : None * Return : 0: success; others: failed ****************************************************************/ //int ir_tx_feedback_mailbox_init(void); /*************************************************************** * Function : ir_repeat_timer_init * Description : * Input : None * Output : None * Return : None ****************************************************************/ void ir_repeat_timer_init(void); /*************************************************************** * Function : ir_repeat_timer_del * Description : * Input : None * Output : None * Return : None ****************************************************************/ void ir_repeat_timer_del(void); /****************************************************************************** * Function : ir_create_thread * Description : 创建IR线程处理函数 * Input : None * Output : None * Return : 0: success,others: failed! ******************************************************************************/ int ir_create_thread(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/ir/inc/irlib.h
C
apache-2.0
13,553
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __USB_AUDIO_H__ #define __USB_AUDIO_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "hal_usb.h" enum USB_AUDIO_ITF_ID_T { USB_AUDIO_ITF_ID_RECV, USB_AUDIO_ITF_ID_SEND, #ifdef USB_AUDIO_MULTIFUNC USB_AUDIO_ITF_ID_RECV2, #endif USB_AUDIO_ITF_ID_QTY }; enum USB_AUDIO_ITF_CMD_T { USB_AUDIO_ITF_STOP, USB_AUDIO_ITF_START_16BIT, USB_AUDIO_ITF_START_24BIT, USB_AUDIO_ITF_START_32BIT, USB_AUDIO_ITF_CMD_QTY }; enum USB_AUDIO_STATE_EVENT_T { USB_AUDIO_STATE_RESET, // RESET event should be processed as quickly as possible USB_AUDIO_STATE_DISCONNECT, USB_AUDIO_STATE_SLEEP, USB_AUDIO_STATE_WAKEUP, USB_AUDIO_STATE_CONFIG, USB_AUDIO_STATE_RECV_PAUSE, USB_AUDIO_STATE_RECV_CONTINUE, USB_AUDIO_STATE_SET_RECV_RATE, USB_AUDIO_STATE_SET_SEND_RATE, USB_AUDIO_STATE_RECV2_PAUSE, USB_AUDIO_STATE_RECV2_CONTINUE, USB_AUDIO_STATE_EVENT_QTY }; enum USB_AUDIO_HID_EVENT_T { USB_AUDIO_HID_VOL_UP = (1 << 0), USB_AUDIO_HID_VOL_DOWN = (1 << 1), USB_AUDIO_HID_PLAY_PAUSE = (1 << 2), USB_AUDIO_HID_SCAN_NEXT = (1 << 3), USB_AUDIO_HID_SCAN_PREV = (1 << 4), USB_AUDIO_HID_STOP = (1 << 5), USB_AUDIO_HID_FAST_FWD = (1 << 6), USB_AUDIO_HID_REWIND = (1 << 7), USB_AUDIO_HID_VOL_MUTE = (1 << 8), USB_AUDIO_HID_VOICE_CMD = (1 << 9), USB_AUDIO_HID_REDIAL = (1 << 10), USB_AUDIO_HID_HOOK_SWITCH = (1 << 11), USB_AUDIO_HID_MIC_MUTE = (1 << 12), USB_AUDIO_HID_VOICE_MAIL = (1 << 13), USB_AUDIO_HID_RESERVED_14 = (1 << 14), USB_AUDIO_HID_RESERVED_15 = (1 << 15), }; struct USB_AUDIO_XFER_INFO_T { const uint8_t *data; uint32_t size; uint32_t next_size; bool pool_enabled; int8_t cur_compl_err; int8_t next_xfer_err; }; struct USB_AUDIO_VENDOR_MSG_T { const struct SETUP_PACKET *pkt; uint8_t *data; uint16_t length; }; typedef void (*USB_AUDIO_ITF_CALLBACK)(enum USB_AUDIO_ITF_ID_T id, enum USB_AUDIO_ITF_CMD_T cmd); typedef void (*USB_AUDIO_MUTE_CALLBACK)(enum USB_AUDIO_ITF_ID_T id, uint32_t mute); typedef void (*USB_AUDIO_SET_VOLUME)(enum USB_AUDIO_ITF_ID_T id, uint32_t percent); typedef uint32_t (*USB_AUDIO_GET_VOLUME)(enum USB_AUDIO_ITF_ID_T id); typedef void (*USB_AUDIO_XFER_CALLBACK)(enum USB_AUDIO_ITF_ID_T id, const struct USB_AUDIO_XFER_INFO_T *info); typedef void (*USB_AUDIO_STATE_CALLBACK)(enum USB_AUDIO_STATE_EVENT_T event, uint32_t param); typedef void (*HID_XFER_CALLBACK)(enum USB_AUDIO_HID_EVENT_T event, int error); typedef int (*USB_AUDIO_VENDOR_MSG_CALLBACK)(struct USB_AUDIO_VENDOR_MSG_T *msg); struct USB_AUDIO_CFG_T { uint32_t recv_sample_rate; uint32_t send_sample_rate; uint8_t *vendor_rx_buf; uint16_t vendor_rx_size; USB_AUDIO_ITF_CALLBACK itf_callback; USB_AUDIO_MUTE_CALLBACK mute_callback; USB_AUDIO_SET_VOLUME set_volume; USB_AUDIO_GET_VOLUME get_volume; USB_AUDIO_STATE_CALLBACK state_callback; USB_AUDIO_XFER_CALLBACK xfer_callback; HID_XFER_CALLBACK hid_send_callback; USB_AUDIO_VENDOR_MSG_CALLBACK vendor_msg_callback; }; int usb_audio_open(const struct USB_AUDIO_CFG_T *cfg); void usb_audio_close(void); int usb_audio_recv_ready(void); int usb_audio_send_ready(void); int usb_audio_start_recv(uint8_t *buf, uint32_t pos, uint32_t size); void usb_audio_stop_recv(void); int usb_audio_start_send(const uint8_t *buf, uint32_t pos, uint32_t size); void usb_audio_stop_send(void); void usb_audio_pause_send(void); int usb_audio_continue_send(uint32_t pos); int usb_audio_set_recv_pos(uint32_t pos); int usb_audio_set_send_pos(uint32_t pos); void usb_audio_hid_set_event(enum USB_AUDIO_HID_EVENT_T event, int state); const char *usb_audio_get_hid_event_name(enum USB_AUDIO_HID_EVENT_T event); int usb_audio_start_recv2(uint8_t *buf, uint32_t pos, uint32_t size); void usb_audio_stop_recv2(void); int usb_audio_set_recv2_pos(uint32_t pos); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_dev/inc/usb_audio.h
C
apache-2.0
4,693
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __USB_AUDIO_SYNC_H__ #define __USB_AUDIO_SYNC_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" typedef uint32_t (*USB_AUDIO_SYNC_TIME_TO_MS)(uint32_t time); enum UAUD_SYNC_RET_T { UAUD_SYNC_IDLE, UAUD_SYNC_START, UAUD_SYNC_ERR, }; struct USB_AUDIO_STREAM_INFO_T { // Difference error threshold uint16_t err_thresh; // Difference synchronization threshold uint16_t sync_thresh; // Sample rate uint32_t samp_rate; // Total sample count of the buffer uint32_t samp_cnt; // The number of value to calculate the average uint8_t diff_avg_cnt; // The stream info ID uint8_t id; // Whether to enable diff_target uint8_t diff_target_enabled; // The Max adjust ratio moving to diff_target float max_target_ratio; // The abosulte difference value between current diff and diff_target to apply max_target_ratio uint32_t max_target_thresh; // The target of the difference int diff_target; // Function to convert timestamp to ms. If NULL, default timer will be used. USB_AUDIO_SYNC_TIME_TO_MS time_to_ms; // Current timestamp. If time_to_ms is NULL, this member will be ignored. uint32_t time; // Internal control block uint32_t ctrl_block[8]; }; void usb_audio_sync_reset(struct USB_AUDIO_STREAM_INFO_T *info); int usb_audio_sync_normalize_diff(int diff, uint32_t size); enum UAUD_SYNC_RET_T usb_audio_sync(uint32_t pos_a, uint32_t pos_b, struct USB_AUDIO_STREAM_INFO_T *info, float *p_ratio); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_dev/inc/usb_audio_sync.h
C
apache-2.0
2,219
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __USB_CDC_H__ #define __USB_CDC_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" enum USB_SERIAL_API_MODE { USB_SERIAL_API_NONBLOCKING, USB_SERIAL_API_BLOCKING, }; enum USB_SERIAL_STATE_EVENT_T { USB_SERIAL_STATE_RESET, // RESET event should be processed as quickly as possible USB_SERIAL_STATE_DISCONNECT, USB_SERIAL_STATE_SLEEP, USB_SERIAL_STATE_WAKEUP, USB_SERIAL_STATE_CONFIG, USB_SERIAL_STATE_STALL_RECV, USB_SERIAL_STATE_STALL_SEND, USB_SERIAL_STATE_STALL_INTR, USB_SERIAL_STATE_UNSTALL_RECV, USB_SERIAL_STATE_UNSTALL_SEND, USB_SERIAL_STATE_UNSTALL_INTR, }; enum USB_SERIAL_RET_VALUE { USB_ERR_OK = 0, USB_ERR_RXTX_DATA = -1, USB_ERR_NOT_DONE = -2, USB_ERR_NOT_IDLE = -3, USB_ERR_NOT_LOCK = -9, USB_ERR_NOT_CONNECT = -10, USB_ERR_INV_PARAM = -11, USB_ERR_UNALIGNED = -12, USB_ERR_RX_SIZE = -13, USB_ERR_RXTX_CANCEL = -14, }; enum USB_SERIAL_STOP_BITS_T { USB_SERIAL_STOP_BITS_1 = 0, USB_SERIAL_STOP_BITS_1P5 = 1, USB_SERIAL_STOP_BITS_2 = 2, }; enum USB_SERIAL_PARITY_T { USB_SERIAL_PARITY_NONE = 0, USB_SERIAL_PARITY_ODD = 1, USB_SERIAL_PARITY_EVEN = 2, USB_SERIAL_PARITY_MARK = 3, USB_SERIAL_PARITY_SPACE = 4, }; struct USB_SERIAL_LINE_CODING_T { uint32_t rate; uint8_t stop_bits; uint8_t parity; uint8_t data_bits; }; typedef void (*USB_SERIAL_STATE_CALLBACK)(enum USB_SERIAL_STATE_EVENT_T event); typedef void (*USB_SERIAL_BREAK_CALLBACK)(uint16_t ms); typedef int (*USB_SERIAL_GET_LINE_CODING_CALLBACK)(struct USB_SERIAL_LINE_CODING_T *coding); typedef int (*USB_SERIAL_SET_LINE_CODING_CALLBACK)(const struct USB_SERIAL_LINE_CODING_T *coding); typedef void (*USB_SERIAL_XFER_CALLBACK)(const uint8_t *data, uint32_t size, int error); struct USB_SERIAL_CFG_T { USB_SERIAL_STATE_CALLBACK state_callback; USB_SERIAL_BREAK_CALLBACK break_callback; USB_SERIAL_GET_LINE_CODING_CALLBACK get_line_coding_callback; USB_SERIAL_SET_LINE_CODING_CALLBACK set_line_coding_callback; enum USB_SERIAL_API_MODE mode; }; int usb_serial_open(const struct USB_SERIAL_CFG_T *cfg); int usb_serial_reopen(USB_SERIAL_BREAK_CALLBACK break_handler); void usb_serial_close(void); int usb_serial_ready(void); int usb_serial_connected(void); void usb_serial_init_xfer(void); void usb_serial_cancel_recv(void); int usb_serial_flush_recv_buffer(void); int usb_serial_recv(uint8_t *buf, uint32_t size); int usb_serial_direct_recv(uint8_t *dma_buf, uint32_t size, uint32_t expect, uint32_t *recv, USB_SERIAL_XFER_CALLBACK callback); void usb_serial_cancel_send(void); int usb_serial_send(const uint8_t *buf, uint32_t size); int usb_serial_direct_send(const uint8_t *dma_buf, uint32_t size, USB_SERIAL_XFER_CALLBACK callback); int usb_serial_send_break(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_dev/inc/usb_cdc.h
C
apache-2.0
3,626
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __USB_DESCRIPTOR_H__ #define __USB_DESCRIPTOR_H__ #ifdef __cplusplus extern "C" { #endif /* Standard requests */ #define GET_STATUS (0) #define CLEAR_FEATURE (1) #define SET_FEATURE (3) #define SET_ADDRESS (5) #define GET_DESCRIPTOR (6) #define SET_DESCRIPTOR (7) #define GET_CONFIGURATION (8) #define SET_CONFIGURATION (9) #define GET_INTERFACE (10) #define SET_INTERFACE (11) /* bmRequestType.direction */ #define HOST_TO_DEVICE (0) #define DEVICE_TO_HOST (1) /* bmRequestType.type*/ #define STANDARD_TYPE (0) #define CLASS_TYPE (1) #define VENDOR_TYPE (2) #define RESERVED_TYPE (3) /* bmRequestType.recipient */ #define DEVICE_RECIPIENT (0) #define INTERFACE_RECIPIENT (1) #define ENDPOINT_RECIPIENT (2) #define OTHER_RECIPIENT (3) /* Descriptors */ #define DESCRIPTOR_TYPE(wValue) (wValue >> 8) #define DESCRIPTOR_INDEX(wValue) (wValue & 0xff) /* Device status */ #define DEVICE_STATUS_SELF_POWERED (1U<<0) #define DEVICE_STATUS_REMOTE_WAKEUP (1U<<1) /* Endpoint status */ #define ENDPOINT_STATUS_HALT (1U<<0) /* Standard feature selectors */ #define DEVICE_REMOTE_WAKEUP (1) #define ENDPOINT_HALT (0) #define TEST_MODE (2) /* Test mode selectors */ #define TEST_MODE_TEST_J (1) #define TEST_MODE_TEST_K (2) #define TEST_MODE_TEST_SE0_NAK (3) #define TEST_MODE_TEST_PACKET (4) #define TEST_MODE_FORCE_ENABLE (5) /* Standard descriptor types */ #define DEVICE_DESCRIPTOR (1) #define CONFIGURATION_DESCRIPTOR (2) #define STRING_DESCRIPTOR (3) #define INTERFACE_DESCRIPTOR (4) #define ENDPOINT_DESCRIPTOR (5) #define QUALIFIER_DESCRIPTOR (6) #define BOS_DESCRIPTOR (0xF) /* Standard descriptor lengths */ #define DEVICE_DESCRIPTOR_LENGTH (0x12) #define CONFIGURATION_DESCRIPTOR_LENGTH (0x09) #define INTERFACE_DESCRIPTOR_LENGTH (0x09) #define ENDPOINT_DESCRIPTOR_LENGTH (0x07) #define QUALIFIER_DESCRIPTOR_LENGTH (0x0A) #define BOS_DESCRIPTOR_LENGTH (0x05) /*string offset*/ #define STRING_OFFSET_LANGID (0) #define STRING_OFFSET_IMANUFACTURER (1) #define STRING_OFFSET_IPRODUCT (2) #define STRING_OFFSET_ISERIAL (3) #define STRING_OFFSET_ICONFIGURATION (4) #define STRING_OFFSET_IINTERFACE (5) /* USB Specification Release Number */ #define USB_VERSION_2_0 (0x0200) #define USB_VERSION_1_1 (0x0101) /* Least/Most significant byte of short integer */ #define LSB(n) ((n)&0xff) #define MSB(n) (((n)&0xff00)>>8) #define LSB0(n) ((n) & 0xFF) #define LSB1(n) (((n) >> 8) & 0xFF) #define LSB2(n) (((n) >> 16) & 0xFF) #define LSB3(n) (((n) >> 24) & 0xFF) /* Convert physical endpoint number to descriptor endpoint number */ #define PHY_TO_DESC(endpoint, dir) (((endpoint) & 0xF) | ((dir == EP_OUT) ? 0 : 0x80)) /* bmAttributes in configuration descriptor */ /* C_RESERVED must always be set */ #define C_RESERVED (1U<<7) #define C_SELF_POWERED (1U<<6) #define C_REMOTE_WAKEUP (1U<<5) /* bMaxPower in configuration descriptor */ #define C_POWER(mA) ((mA)/2) /* bmAttributes in endpoint descriptor */ #define E_CONTROL (0x00) #define E_ISOCHRONOUS (0x01) #define E_BULK (0x02) #define E_INTERRUPT (0x03) /* For isochronous endpoints only: */ #define E_NO_SYNCHRONIZATION (0x00) #define E_ASYNCHRONOUS (0x04) #define E_ADAPTIVE (0x08) #define E_SYNCHRONOUS (0x0C) #define E_DATA (0x00) #define E_FEEDBACK (0x10) #define E_IMPLICIT_FEEDBACK (0x20) #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_dev/inc/usb_descriptor.h
C
apache-2.0
4,331
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __USB_DEV_DESC_H__ #define __USB_DEV_DESC_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #ifdef USB_AUDIO_32BIT #if defined(USB_AUDIO_192K) && !defined(USB_HIGH_SPEED) #error "192K 32BIT stream can run on USB_HIGH_SPEED only" #endif #if defined(USB_AUDIO_176_4K) && !defined(USB_HIGH_SPEED) #error "176.4K 32BIT stream can run on USB_HIGH_SPEED only" #endif #elif defined(USB_AUDIO_24BIT) #if defined(USB_AUDIO_192K) && !defined(USB_HIGH_SPEED) #error "192K 24BIT stream can run on USB_HIGH_SPEED only" #endif #if defined(USB_AUDIO_176_4K) && !defined(USB_HIGH_SPEED) #error "176.4K 24BIT stream can run on USB_HIGH_SPEED only" #endif #endif #if defined(USB_AUDIO_384K) && !(defined(USB_HIGH_SPEED) && defined(USB_AUDIO_UAC2)) #error "384K stream can run on USB_HIGH_SPEED and USB_AUDIO_UAC2 only" #endif #if defined(USB_AUDIO_352_8K) && !(defined(USB_HIGH_SPEED) && defined(USB_AUDIO_UAC2)) #error "352.8K stream can run on USB_HIGH_SPEED and USB_AUDIO_UAC2 only" #endif #if defined(USB_AUDIO_UAC2) && !defined(USB_HIGH_SPEED) #error "USB_AUDIO_UAC2 should run on USB_HIGH_SPEED" #endif const uint8_t *cdc_dev_desc(uint8_t type); const uint8_t *cdc_string_desc(uint8_t index); const uint8_t *uaud_dev_desc(uint8_t type); const uint8_t *uaud_string_desc(uint8_t index); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_dev/inc/usb_dev_desc.h
C
apache-2.0
1,996
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _USB_HCD_H #define _USB_HCD_H #include "usb_host.h" #ifdef __cplusplus extern "C" { #endif #define USB_HCD_NAME "BES_CTROL" #define USB_HCD_ADDR 0x01 #define USB_HCD_VERSION 0x00010001 #define USB_HCD_MAX_PACKET_LEN (64) #define USB_HCD_AVAILABLE_BANDWIDTH (1024*1024) #define USB_HCD_NAME_LEN 16 #define USB_HCD_ADDR_LEN 16 #define USB_HCD_PORT_SIGNAL_LEN 16 #define USB_HCD_TOKEN_SETUP 0 #define USB_HCD_TOKEN_IN 1 #define USB_HCD_TOKEN_OUT 2 #define USB_HCD_MAX_ENDPOINTS 6 #if 0 // register GINTSTS // USB HCD Interrupt Status #define USB_HCD_STS_INT 0x0001 /* USB Interrupt */ //PrtInt #define USB_HCD_STS_ERRINT 0x0002 /* USB Error Interrupt */ #define USB_HCD_STS_PCD 0x0004 /* Port Change Detect */ //ConIDStsChng #define USB_HCD_STS_FLR 0x0008 /* Frame List Rellover */ #define USB_HCD_STS_HSE 0x00010 /* Host System Error */ #define USB_HCD_STS_IAA 0x00020 /* Interrupt on Async Advance */ #define USB_HCD_STS_SRI 0x00080 /* SOF - ECHI Derivation */ //Sof #define USB_HCD_STS_HCH 0x01000 /* Host Controller has Halted */ #define USB_HCD_STS_RECL 0x02000 /* Reclamation */ #define USB_HCD_STS_PSS 0x04000 /* Periodic Schedule Status */ #define USB_HCD_STS_ASS 0x08000 /* Asynchronous Schedule Status */ #define USB_HCD_STS_UAI 0x40000 /* USB Asynchronous Interrupt -EHCI derivation */ #define USB_HCD_STS_UPI 0x80000 /* USB Period Interrupt - EHCI derivation */ #endif typedef enum { USB_HCD_STATUS_HALT = 0, USB_HCD_STATUS_OPER = 1, USB_HCD_STATUS_DEAD = 2, }USB_HCD_STATUS_T; typedef enum { USB_HCD_TYPE_FULL_SPEED = 0, USB_HCD_TYPE_HIGH_SPEED = 1, }USB_HCD_TYPE_T; // Register GINTSTS typedef enum { USB_HCD_INTSTS_UNKNOWN = 0, // Current Mode of Operation (CurMod) // 1'b0: Device mode // 1'b1: Host mode USB_HCD_INTSTS_CURMOD = (0x1<<0), // * // RxFIFO Non-Empty (RxFLvl) USB_HCD_INTSTS_RXFLVL = (0x1<<4), // * // Incomplete Periodic Transfer (incomplP) USB_HCD_INTSTS_FETSUSP = (0x1<<22), // * // Host Port Interrupt (PrtInt) USB_HCD_INTSTS_PRTINT = (0x1<<24), // * // Host Channels Interrupt (HChInt) USB_HCD_INTSTS_HCHINT = (0x1<<25), // Periodic TxFIFO Empty (PTxFEmp) USB_HCD_INTSTS_PTXFEMP = (0x1<<26), // * // Connector ID Status Change (ConIDStsChng) USB_HCD_INTSTS_CONLDSTSCHNG = (0x1<<28), // * // Disconnect Detected Interrupt (DisconnInt) USB_HCD_INTSTS_DISCONNINT = (0x1<<29), // Session Request/New Session Detected Interrupt (SessReqInt) USB_HCD_INTSTS_SESSREQINT = (0x1<<30), // Resume/Remote Wakeup Detected Interrupt (WkUpInt) USB_HCD_INTSTS_WKUPINT = (0x1<<31), }USB_HCD_INTSTS_T; // Register HPRT typedef enum { USB_PORT_STATUS_UNKNOWN = 0x00, USB_PORT_STATUS_CONNECTION = (0x01 << 0), USB_PORT_STATUS_ENABLE = (0x01 << 1), USB_PORT_STAT_SUSPEND = (0x01 << 2), USB_PORT_STATUS_OVERCURRENT = (0x01 << 3), USB_PORT_STATUS_RESET = (0x01 << 4), USB_PORT_STATUS_POWER = (0x01 << 5), USB_PORT_STATUS_FULL_SPEED = (0x01 << 6), USB_PORT_STATUS_HIGH_SPEED = (0x01 << 7), }USB_PORT_STATUS_T; typedef enum { USB_HCD_PLUG_STATUS_UNKNOWN, USB_HCD_PLUG_STATUS_IN, USB_HCD_PLUG_STATUS_OUT, }USB_HCD_PLUG_STATUS_T; typedef enum { USB_HCD_EP_TYPE_CTRL, USB_HCD_EP_TYPE_ISO, USB_HCD_EP_TYPE_BULK, USB_HCD_EP_TYPE_INT, USB_HCD_EP_TYPE_QTY }USB_HCD_EP_TYPE_T; typedef enum { HCD_CMD_DISABLE_CONTROLLER = 0, // USB Host Controller disable. HCD_CMD_GET_PORT_STATUS = 1, // Get USB Port status. HCD_CMD_ENABLE_PORT = 2, // USB Port enable. HCD_CMD_DISABLE_PORT = 3, // USB Port disable. HCD_CMD_POWER_ON_PORT = 4, // USB Host power on. HCD_CMD_POWER_OFF_PORT = 5, // USB Host power off. HCD_CMD_RESUME_PORT = 6, // USB Port resume. HCD_CMD_SUSPEND_PORT = 7, // USB Port suspend. HCD_CMD_RESET_PORT = 8, // USB Port reset. HCD_CMD_GET_FRAME_NUMBER = 9, // Get Frame Number, for Isochronous Transfer. HCD_CMD_SET_FRAME_NUMBER = 10, // Set Frame Number, for Isochronous Transfer. HCD_CMD_TRANSFER_REQUEST = 11, // Transfer Request. HCD_CMD_CONTROL_TRANSFER_REQUEST = 12, // Transfer Request. HCD_CMD_TRANSFER_ABORT = 13, // Transfer Abort. HCD_CMD_CREATE_ENDPOINT = 14, // Create a endpoint. HCD_CMD_DESTROY_ENDPOINT = 15, // Destroy a endpoint. HCD_CMD_RESET_ENDPOINT = 16, // Reset endpoint. HCD_CMD_PROCESS_DONE_QUEUE = 17, // Process a transmission that has already occurred }HCD_CMD_T; typedef void (*HCD_INTERRUPT_HANDLE_CB) (void); typedef void (*HCD_PLUG_HANDLE_CB) (void); typedef void (*HCD_TRANSFER_CALLBACK)(int32_t device,\ int32_t endpoint,\ int32_t status,\ uint8_t* data,\ int32_t length,\ void* user_data); typedef struct _USB_HCD { char name[USB_HCD_NAME_LEN + 1]; uint8_t address[USB_HCD_ADDR_LEN]; uint32_t state; uint32_t type; uint32_t otg_capabilities; uint32_t root_hub_port_num; uint32_t root_hub_port_signal[USB_HCD_PORT_SIGNAL_LEN]; uint32_t task_signal; uint32_t (*hcd_entry_func)(struct _USB_HCD *, uint32_t, void *); uint32_t root_hub_device_connection; uint32_t device_num; uint32_t io; uint32_t power_switch; uint32_t available_bandwidth; uint32_t maximum_transfer_request_size; uint32_t version; void *controller_hardware; void *hcd_op; } USB_HCD_T; // cmd HCD_CMD_GET_PORT_STATUS Parameter typedef struct _HCD_DEVICE_PORT_T { uint8_t device; uint8_t port; }HCD_DEVICE_PORT_T; typedef struct _HCD_DEVICE_EP_T { uint8_t device; uint8_t ep; }HCD_DEVICE_EP_T; typedef struct _HCD_HUB_EP_T { uint8_t hub; uint8_t ep; }HCD_HUB_EP_T; // cmd HCD_CMD_TRANSFER_REQUEST Parameter. typedef struct _HCD_TRANSFER_T { uint8_t device; uint8_t ep; uint8_t flags; uint8_t* data; uint32_t data_len; HCD_TRANSFER_CALLBACK callback; void* user_data; }HCD_TRANSFER_T; // cmd HCD_CMD_TRANSFER_REQUEST(CONTROL) Parameter. typedef struct _HCD_CONTROL_TRANSFER_T { uint8_t device; uint8_t ep; int request_type; int request; int value; int index; uint8_t* data; int length; int actual_len; USBHOST_CALLBACK callback; void * user_data; }HCD_CONTROL_TRANSFER_T; // cmd HCD_CMD_CREATE_ENDPOINT Parameter typedef struct _HCD_CREATE_ENDPOINT_T { uint8_t device; uint8_t ep; uint8_t attributes; uint32_t max_packet_size; uint32_t interval; }HCD_CREATE_ENDPOINT_T; typedef void (*HCD_INTERRUPT_HANDLE_CB) (void); typedef void (*HCD_PLUG_HANDLE_CB) (void); int usb_hcd_init(USB_HCD_T * hcd, HCD_INTERRUPT_HANDLE_CB int_handle, HCD_PLUG_HANDLE_CB plug_handle); int usb_register_interrupt_cb(HCD_INTERRUPT_HANDLE_CB handle); int usb_hcd_cmd(USB_HCD_T * hcd,HCD_CMD_T cmd, void* param); // Get interrupt status, return USB HCD Interrupt Status. int usb_hcd_get_interrupt_status(void); // Get port status, return USB HCD Port Status. int usb_hcd_get_port_status(void); // Get usb plug status, return USB HCD Plug Status. int usb_hcd_get_plug_status(void); // Detect usb device plug staus. int usb_hcd_detect(USB_HCD_PLUG_STATUS_T plug_status); void usb_hcd_set_timeout(uint32_t ms); void usb_hcd_log_disable_for_debug(bool disable); #ifdef __cplusplus } #endif #endif //_USB_HCD_H
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_host/inc/usb_hcd.h
C
apache-2.0
8,696
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _USB_HCD_TEST #define _USB_HCD_TEST #ifdef __cplusplus extern "C" { #endif int test_usb_hcd_main(void); void test_usb_hcd_loop(void); void test_usb_hcd_get_interrupt_status(void); void test_usb_hcd_get_port_status(void); void test_usb_hcd_get_plug_status(void); int test_usb_hcd_cmd_get_port_status(void); void test_usb_hcd_cmd_create_point(uint8_t device, uint8_t port, uint8_t attributes, uint8_t interval, uint8_t max_packet_size); void test_usb_hcd_cmd_destroy_point(void); void test_usb_hcd_cmd_disable_controller(void); void test_usb_hcd_cmd_enable_port(void); void test_usb_hcd_cmd_disable_port(void); void test_usb_hcd_cmd_power_on_port(void); void test_usb_hcd_cmd_power_off_port(void); void test_usb_hcd_cmd_resume_port(void); void test_usb_hcd_cmd_suspend_port(void); void test_usb_hcd_cmd_reset_port(void); void test_usb_hcd_cmd_get_frame_number_port(void); void test_usb_hcd_cmd_set_frame_number_port(uint32_t frame_number); void test_usb_hcd_cmd_transfer_req(void); void test_usb_hcd_cmd_set_addr(void); void test_usb_hcd_cmd_get_descriptor(int descriptor_type); void test_usb_hcd_cmd_set_config(void); void test_usb_set_itf_ep(void); int test_usb_bulk_tracefer_req(int device, int ep, uint8_t* data, int length, HCD_TRANSFER_CALLBACK callback, void* userdata); void test_usb_hcd_cmd_process_done_queue(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_host/inc/usb_hcd_test.h
C
apache-2.0
2,226
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _USB_CONTROLLER_H #define _USB_CONTROLLER_H #include "plat_types.h" #include "hal_usbhost.h" // Config (default uses x bytes) #define MAX_DEVICES 1 // Max number of devices #define MAX_ENDPOINTS_TOTAL 8 // Max number of endpoints total #define MAX_ENDPOINTS_PER_DEVICE (MAX_ENDPOINTS_TOTAL/MAX_DEVICES)// Max number of endpoints for any one device // USB host structures #define TOKEN_SETUP 0 #define TOKEN_IN 1 #define TOKEN_OUT 2 // Status flags from hub #define PORT_CONNECTION 0 #define PORT_ENABLE 1 #define PORT_SUSPEND 2 #define PORT_OVER_CURRENT 3 #define PORT_RESET 4 #define PORT_POWER 8 #define PORT_LOW_SPEED 9 #define C_PORT_CONNECTION 16 #define C_PORT_ENABLE 17 #define C_PORT_SUSPEND 18 #define C_PORT_OVER_CURRENT 19 #define C_PORT_RESET 20 #define DEVICE_TO_HOST 0x80 #define HOST_TO_DEVICE 0x00 #define REQUEST_TYPE_CLASS 0x20 #define RECIPIENT_DEVICE 0x00 #define RECIPIENT_INTERFACE 0x01 #define RECIPIENT_ENDPOINT 0x02 #define RECIPIENT_OTHER 0x03 #define GET_STATUS 0 #define CLEAR_FEATURE 1 #define SET_FEATURE 3 #define SET_ADDRESS 5 #define GET_DESCRIPTOR 6 #define SET_DESCRIPTOR 7 #define GET_CONFIGURATION 8 #define SET_CONFIGURATION 9 #define GET_INTERFACE 10 #define SET_INTERFACE 11 #define SYNCH_FRAME 11 //=================================================================== //=================================================================== // Hardware defines #define USBHOST_CURRENT_CONNECT_STATUS 0x00000001 #define USBHOST_PORT_RESET_STATUS 0x00000010 #define CONNECT_STATUS_CHANGE (USBHOST_CURRENT_CONNECT_STATUS << 16) #define PORT_RESET_STATUS_CHANGE (USBHOST_PORT_RESET_STATUS << 16) #define TD_ROUNDING (uint32_t)0x00040000 #define TD_SETUP (uint32_t)0x00000000 #define TD_IN (uint32_t)0x00100000 #define TD_OUT (uint32_t)0x00080000 #define TD_DELAY_INT(x) (uint32_t)((x) << 21) #define TD_TOGGLE_0 (uint32_t)0x02000000 #define TD_TOGGLE_1 (uint32_t)0x03000000 #define TD_CC (uint32_t)0xF0000000 #define SKIP_CLEANUP_HW_CHAN (1 << 0) #define SKIP_CLEANUP_CLOSE (1 << 1) #define SKIP_CLEANUP_FILE_SYSTEM (1 << 2) #define USB_ENDPORT_DMA_BUFFER_LEN 1024 enum USB_ENDPORT_STATE_T { USB_ENDPORT_STATE_FREE, USB_ENDPORT_STATE_NOTQUEUED, USB_ENDPORT_STATE_IDLE, USB_ENDPORT_STATE_SETUPQUEUED, USB_ENDPORT_STATE_DATAQUEUED, USB_ENDPORT_STATE_STATUSQUEUED, USB_ENDPORT_STATE_CALLBACK_PENDING, // USB_ENDPORT_STATE_WAIT_PROCESS_DONE, }; // HostController EndPoint Descriptor typedef struct { volatile uint32_t control; volatile uint32_t tail_td; volatile uint32_t head_td; volatile uint32_t next; } HCED_T; // HostController Transfer Descriptor typedef struct { volatile uint32_t control; volatile uint32_t curr_buf_ptr; volatile uint32_t next; volatile uint32_t bufend; } HCTD_T; // Host Controller Communication Area typedef struct { volatile uint32_t InterruptTable[32]; volatile uint16_t FrameNumber; volatile uint16_t FrameNumberPad; volatile uint32_t DoneHead; volatile uint8_t Reserved[120]; } HCCA; enum USBHOST_CLASS_CODE_T { USB_CLASS_DEVICE = 0x0, USB_CLASS_AUDIO = 0x01, USB_CLASS_COMM = 0x02, USB_CLASS_HID = 0x03, USB_CLASS_PHYSICAL = 0x05, USB_CLASS_IMAGING = 0x06, USB_CLASS_PRINTER = 0x07, USB_CLASS_MASS_STORAGE = 0x08, USB_CLASS_HUB = 0x09, USB_CLASS_DATA = 0x0a, USB_CLASS_SMART_CARD = 0x0b, USB_CLASS_CONTENT_SECURITY = 0x0d, USB_CLASS_VIDEO = 0x0e, USB_CALSS_PERSONAL_HEALTHCARE = 0x0f, USB_CLASS_DIAGNOSTIC_DEVICE = 0xdc, USB_CLASS_WIRELESS = 0xe0, USB_CLASS_MISCELLANEOUS = 0xef, USB_CLASS_APP_SPECIFIC = 0xfe, USB_CLASS_VENDOR_SPECIFIC = 0xff }; enum USBHOST_DESCRIPTOR_TYPE { DESCRIPTOR_TYPE_DEVICE = 0x01, DESCRIPTOR_TYPE_CONFIG = 0x02, DESCRIPTOR_TYPE_STRING = 0x03, DESCRIPTOR_TYPE_INTERFACE = 0x04, DESCRIPTOR_TYPE_ENDPOINT = 0x05, DESCRIPTOR_TYPE_BOS = 0x0f, DESCRIPTOR_TYPE_DEVICE_CAPABILITY = 0x10, DESCRIPTOR_TYPE_DEVICE_HID = 0x21, DESCRIPTOR_TYPE_DEVICE_REPORT = 0x22, DESCRIPTOR_TYPE_DEVICE_PHYSICAL = 0x23, DESCRIPTOR_TYPE_DEVICE_HUB = 0x29, DESCRIPTOR_TYPE_DEVICE_SUPERSPEED_HUB = 0x2a, DESCRIPTOR_TYPE_DEVICE_ENDPOINT_COMPANION = 0x2a, }; enum USBHOST_ENDPOINT_DIRECTION_T { USB_ENDPOINT_DIRECTION_IN = 0x80, USB_ENDPOINT_DIRECTION_OUT = 0x0, }; enum USBHOST_TRANSFER_TYPE_T { USB_TRANSFER_TYPE_CONTROL = 0, USB_TRANSFER_TYPE_ISOCHRONOUS = 1, USB_TRANSFER_TYPE_BULK = 2, USB_TRANSFER_TYPE_INTERRUPT = 3, }; enum USBHOST_REQUEST_T { USB_REQUEST_GET_STATUS = 0x00, USB_REQUEST_CLEAR_FEATURE = 0x01, USB_REQUEST_SET_FEATURE = 0x03, USB_REQUEST_SET_ADDRESS = 0x05, USB_REQUEST_GET_DESCRIPTOR = 0x06, USB_REQUEST_SET_DESCRIPTOR = 0x07, USB_REQUEST_GET_CONFIGURATION = 0x08, USB_REQUEST_SET_CONFIGURATION = 0x09, USB_REQUEST_GET_INTERFACE = 0x0a, USB_REQUEST_SET_INTERFACE = 0x0b, USB_REQUEST_SYNCH_FRAME = 0x0c, USB_REQUEST_SET_SEL = 0x30, USB_REQUEST_SET_ISOCH_DELAY = 0x31, }; enum USBHOST_REQUEST_RECIPIENT_T { USB_REQUEST_RECIPIENT_DEVICE = 0x00, USB_REQUEST_RECIPIENT_INTERFACE = 0x01, USB_REQUEST_RECIPIENT_ENDPOINT = 0x02, USB_REQUEST_RECIPIENT_OTHER = 0x03, }; typedef struct { uint8_t length; uint8_t descriptor_type; uint16_t cdusb; uint8_t device_class; uint8_t device_sub_class; uint8_t device_protocol; uint8_t max_packet_size; uint16_t vendor; uint16_t dproduct; uint16_t cddevice; uint8_t manu_facturer; uint8_t product; uint8_t serial_number; uint8_t num_configurations; } USBHOST_DEVICE_DESCRIPTOR_T; typedef struct { uint8_t length; uint8_t descriptor_type; uint16_t total_length; uint8_t num_interface; uint8_t configuration_value; uint8_t configuration; uint8_t attributes; uint8_t max_power; } USBHOST_CONFIGURATION_DICRIPTOR_T; typedef struct { uint8_t length; uint8_t descriptor_type; uint8_t interface_number; uint8_t alternate_setting; uint8_t num_endpoints; uint8_t interface_class; uint8_t interface_sub_class; uint8_t interface_protocol; uint8_t interface; } USBHOST_INTERFACE_DESCRIPTOR_T; typedef struct { uint8_t length; uint8_t descriptor_type; uint8_t endpoint_address; uint8_t attributes; uint16_t max_packet_size; uint8_t interval; /* NOTE: these two are _only_ in audio endpoints. */ /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */ uint8_t refresh; uint8_t synch_address; } USBHOST_ENDPOINT_DESCRIPTOR_T; typedef struct { uint8_t length; uint8_t descriptor_type; uint16_t bcdhid; uint8_t country_code; uint8_t num_descriptors; uint8_t descriptor_type2; uint16_t descriptor_length; } USBHOST_HID_DESCRIPTOR_T; typedef struct { uint8_t length; uint8_t descriptor_type; uint8_t string[1]; } USBHOST_STRING_DESCRIPTION_T; typedef void (*USBHOST_INTERRUPT_HANDLE_CB) (void); typedef void (*USBHOST_PLUG_HANDLE_CB) (void); typedef void (*USBHOST_CALLBACK)(int32_t device,\ int32_t endpoint,\ int32_t status,\ uint8_t* data,\ int32_t len,\ void* user_data); typedef struct { uint8_t chan; uint8_t chan_ctrl_in; uint32_t dma_buff[USB_ENDPORT_DMA_BUFFER_LEN]; uint32_t dma_buff_len; bool first_xfer; HCED_T descriptor; HCTD_T td_head; volatile uint8_t current_state; bool wait_process_done_queue; uint8_t flags; uint16_t length; uint8_t* data; USBHOST_CALLBACK callback; void* user_data; }USBHOST_ENDPOINT_T; typedef struct { uint8_t bm_request_type; uint8_t b_request; uint16_t w_value; uint16_t w_index; uint16_t w_length; } USBHOST_SETUP_T; typedef struct { uint8_t endpoint_map[MAX_ENDPOINTS_PER_DEVICE*2]; uint8_t hub; uint8_t port; uint8_t addr; uint8_t pad; // Only if this device is a hub uint8_t hub_port_count; // nonzero if this is a hub uint8_t hub_interrupt_data; uint8_t hub_map; uint8_t hub_mask; int32_t flags; // 1 = Disconnected USBHOST_SETUP_T setup_buffer; }USBHOST_DEVICE_T; typedef struct { HCCA communication_area; USBHOST_ENDPOINT_T endpoints[MAX_ENDPOINTS_TOTAL]; USBHOST_ENDPOINT_T endpoint_zero; HCTD_T common_tail; USBHOST_SETUP_T setup_zero; USBHOST_DEVICE_T devices[MAX_DEVICES]; uint32_t frame_number; // 32 bit ms counter uint8_t callbacks_pending; // Endpoints with callbacks are pending, set from ISR via ProcessDoneQueue uint8_t root_hub_status_change; // Root hub status has changed, set from ISR enum HAL_USBHOST_PORT_EVENT_T root_hub_event; uint8_t unused0; uint8_t unused1; uint8_t connect_pending; // Reset has initiated a connect uint32_t connect_countdown; // Number of ms left after port is enabled before we can connect uint32_t disconn_countdown; // Number of ms left after reset in case of no events, so that we can disconnect uint8_t connect_hub; // Will connect on this hub uint8_t connect_port; // ... and this port uint8_t skip_cleanup_bitmap; uint8_t plug_status_change; enum HAL_USBHOST_PLUG_STATUS_T plug_status; #ifdef USB_SLEEP_TEST uint32_t sleep_count_down; uint32_t wakeup_count_down; uint32_t fs_test_count_down; #endif USBHOST_INTERRUPT_HANDLE_CB interrupt_cb; USBHOST_PLUG_HANDLE_CB plug_cb; bool is_open; }USBHOST_T; int usbhost_add_endpoint(int device, int ep, int attributes, int max_packet_size, int interval); int usbhost_add_endpoint_by_desc(int device, USBHOST_ENDPOINT_DESCRIPTOR_T* ed); int usbhost_remove_endpoint(int device, int ep); USBHOST_ENDPOINT_T* usbhost_get_endpoint(int device, int ep); void usbhost_set_interrupt_cb(void *cb); int usbhost_release(USBHOST_ENDPOINT_T* endpoint); void usbhost_process_done_queue(void); int usbhost_add_device(int hub, int port, bool isLowSpeed); int usbhost_init(USBHOST_INTERRUPT_HANDLE_CB interrupt_cb,USBHOST_PLUG_HANDLE_CB plug_cb); int usbhost_deinit(void); void usbhost_loop(void); USBHOST_T* usbhost_get_op(void); int32_t usbhost_get_frame_number(uint32_t *number); int32_t usbhost_set_frame_number(uint32_t number); int32_t usbhost_reset_port(int hub, int port); int32_t usbhost_resume_port(int hub, int port); int32_t usbhost_suspend_port(int hub, int port); int32_t usbhost_disconnect(int hub, int port); // called after reset void usbhost_connect(int hub, int port, bool lowspeed); void usbhost_reconnect_cleanup(int hub, int port); // Called from interrupt void usbhost_hub_status_change(int hub, int port, uint32_t status); int usbhost_wait_io_done(int device, int ep); int32_t usbhost_transfer(int device, int ep, uint8_t flags, uint8_t* data, int length, USBHOST_CALLBACK callback, void* user_data); int32_t usbhost_control_transfer(int device, int ep, int request_type, int request, int value, int index, uint8_t* data, int length, int *actual_len, USBHOST_CALLBACK callback, void * user_data); int32_t usbhost_interrupt_transfer(int device, int ep, uint8_t* data, int length, USBHOST_CALLBACK callback, void* user_data); int32_t usbhost_bulk_transfer(int device, int ep, uint8_t* data, int length, USBHOST_CALLBACK callback, void* user_data); int32_t usbhost_transfer_abort(int device, int ep); int32_t usbhost_getdescriptor(int device, int descType,int descIndex, uint8_t* data, int length); int32_t usbhost_get_string(int device, int index, char* dst, int length); int32_t usbhost_set_address(int device, int new_addr); int32_t usbhost_set_configuration(int device, int configNum); int32_t usbhost_set_interface(int device, int ifNum, int altNum); // HUB stuff int32_t usbhost_set_port_feature(int device, int feature, int index); int32_t usbhost_clear_port_feature(int device, int feature, int index); int32_t usbhost_set_port_power(int device, int port); int32_t usbhost_set_port_reset(int device, int port); int32_t usbhost_get_port_status(int device, int port, uint32_t* status); uint32_t usbhost_hcd_get_port_status(void); uint32_t usbhost_hcd_get_interrupt_status(void); uint32_t usbhost_hcd_get_plug_status(void); uint32_t usbhost_hcd_usb_usb_detect(uint32_t plug_status); int32_t usbhost_hcd_set_port_enable(void); int32_t usbhost_hcd_set_port_disable(void); int32_t usbhost_hcd_set_port_poweron(void); int32_t usbhost_hcd_set_port_poweroff(void); int32_t usbhost_hcd_set_port_resume(void); int32_t usbhost_hcd_set_port_suspend(void); int32_t usbhost_hcd_set_port_reset(void); int32_t usbhost_plug_thread_start(void); int32_t usbhost_hcd_set_timeout(uint32_t ms); int32_t usbhost_hcd_get_mps_size(int device, int ep); #define ERR_IO_PENDING -100 #define ERR_ENDPOINT_NONE_LEFT -101 #define ERR_ENDPOINT_NOT_FOUND -102 #define ERR_DEVICE_NOT_FOUND -103 #define ERR_DEVICE_NONE_LEFT -104 #define ERR_HUB_INIT_FAILED -105 #define ERR_INTERFACE_NOT_FOUND -106 #define ERR_DATA_SIZE_IS_ZERO -107 #define ERR_DATA_SIZE_TOO_LARGE -108 #define ERR_DATA_SIZE_NOT_ALIGNMENT -109 #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_host/inc/usb_host.h
C
apache-2.0
13,931
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 USB_MASS_STORAGE_H #define USB_MASS_STORAGE_H #include "plat_types.h" #define USB_MASS_STORAGE_BLOCK_SIZE 512 int32_t usb_mass_storage_init(int32_t device); int32_t usb_mass_storage_get_capacity(int32_t device, uint32_t* block_count, uint32_t* blockSize); int32_t usb_mass_storage_read(int32_t device, uint32_t block_addr, uint32_t block_count, uint8_t* dst, u32 blockSize); int32_t usb_mass_storage_write(int32_t device, uint32_t block_addr, uint32_t block_count, uint8_t* dst, u32 blockSize); void usb_mass_storage_set_read_ep(uint8_t ep); void usb_mass_storage_set_write_ep(uint8_t ep); void usb_mass_storage_set_itf_num(uint8_t num); #endif // USB_MASS_STORAGE_H
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/drivers/usb/usb_host/inc/usb_mass_storage.h
C
apache-2.0
1,710
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_CMU_BEST2001_H__ #define __HAL_CMU_BEST2001_H__ #ifdef __cplusplus extern "C" { #endif #ifdef FPGA #define HAL_CMU_DEFAULT_CRYSTAL_FREQ 26000000 #define HAL_CMU_VALID_CRYSTAL_FREQ { HAL_CMU_DEFAULT_CRYSTAL_FREQ, } #else #define HAL_CMU_VALID_CRYSTAL_FREQ { 26000000, 40000000, } #endif enum HAL_CMU_MOD_ID_T { // HCLK/HRST HAL_CMU_MOD_H_MCU, // 0 HAL_CMU_MOD_H_CACHE0, // 1 HAL_CMU_MOD_H_CP, // 2 HAL_CMU_MOD_H_CACHE1, // 3 HAL_CMU_MOD_H_ADMA, // 4 HAL_CMU_MOD_H_GDMA, // 5 HAL_CMU_MOD_H_SEC_ENG, // 6 HAL_CMU_MOD_H_USBC, // 7 HAL_CMU_MOD_H_USBH, // 8 HAL_CMU_MOD_H_I2C_SLAVE, // 9 HAL_CMU_MOD_H_AX2H_A7, // 10 HAL_CMU_MOD_H_AH2H_WF, // 11 HAL_CMU_MOD_H_AH2H_BT, // 12 HAL_CMU_MOD_H_CODEC, // 13 HAL_CMU_MOD_H_AHB1, // 14 HAL_CMU_MOD_H_AHB0, // 15 HAL_CMU_MOD_H_PSRAM1G, // 16 HAL_CMU_MOD_H_PSRAM200, // 17 HAL_CMU_MOD_H_FLASH, // 18 HAL_CMU_MOD_H_RAM9, // 19 HAL_CMU_MOD_H_RAM8, // 20 HAL_CMU_MOD_H_RAM7, // 21 HAL_CMU_MOD_H_RAM3_6, // 22 HAL_CMU_MOD_H_RAM1_2, // 23 HAL_CMU_MOD_H_RAM0, // 24 HAL_CMU_MOD_H_ROM0, // 25 HAL_CMU_MOD_H_BT_DUMP, // 26 HAL_CMU_MOD_H_WF_DUMP, // 27 HAL_CMU_MOD_H_SDMMC, // 28 HAL_CMU_MOD_H_CHECKSUM, // 29 HAL_CMU_MOD_H_CRC, // 30 // PCLK/PRST HAL_CMU_MOD_P_CMU, // 31 HAL_CMU_MOD_P_WDT, // 32 HAL_CMU_MOD_P_TIMER0, // 33 HAL_CMU_MOD_P_TIMER1, // 34 HAL_CMU_MOD_P_TIMER2, // 35 HAL_CMU_MOD_P_I2C0, // 36 HAL_CMU_MOD_P_I2C1, // 37 HAL_CMU_MOD_P_SPI, // 38 HAL_CMU_MOD_P_SLCD, // 39 HAL_CMU_MOD_P_SPI_ITN, // 40 HAL_CMU_MOD_P_SPI_PHY, // 41 HAL_CMU_MOD_P_UART0, // 42 HAL_CMU_MOD_P_UART1, // 43 HAL_CMU_MOD_P_UART2, // 44 HAL_CMU_MOD_P_PCM, // 45 HAL_CMU_MOD_P_I2S0, // 46 HAL_CMU_MOD_P_SPDIF0, // 47 HAL_CMU_MOD_P_TQWF, // 48 HAL_CMU_MOD_P_TQA7, // 49 HAL_CMU_MOD_P_TRNG, // 50 HAL_CMU_MOD_P_SEC_ENG, // 51 HAL_CMU_MOD_P_TZC, // 52 // OCLK/ORST HAL_CMU_MOD_O_SLEEP, // 53 HAL_CMU_MOD_O_USB, // 54 HAL_CMU_MOD_O_USB32K, // 55 HAL_CMU_MOD_O_PSRAM1G, // 56 HAL_CMU_MOD_O_PSRAM200, // 57 HAL_CMU_MOD_O_FLASH, // 58 HAL_CMU_MOD_O_SDMMC, // 59 HAL_CMU_MOD_O_WDT, // 60 HAL_CMU_MOD_O_TIMER0, // 61 HAL_CMU_MOD_O_TIMER1, // 62 HAL_CMU_MOD_O_TIMER2, // 63 HAL_CMU_MOD_O_I2C0, // 64 HAL_CMU_MOD_O_I2C1, // 65 HAL_CMU_MOD_O_SPI, // 66 HAL_CMU_MOD_O_SLCD, // 67 HAL_CMU_MOD_O_SPI_ITN, // 68 HAL_CMU_MOD_O_SPI_PHY, // 69 HAL_CMU_MOD_O_UART0, // 70 HAL_CMU_MOD_O_UART1, // 71 HAL_CMU_MOD_O_UART2, // 72 HAL_CMU_MOD_O_PCM, // 73 HAL_CMU_MOD_O_I2S0, // 74 HAL_CMU_MOD_O_SPDIF0, // 75 HAL_CMU_MOD_O_I2S1, // 76 HAL_CMU_MOD_O_A7, // 77 HAL_CMU_MOD_O_TSF, // 78 HAL_CMU_MOD_O_WDT_AP, // 79 HAL_CMU_MOD_O_TIMER0_AP, // 80 HAL_CMU_MOD_O_TIMER1_AP, // 81 // AON ACLK/ARST HAL_CMU_AON_A_CMU, // 82 HAL_CMU_AON_A_GPIO, // 83 HAL_CMU_AON_A_GPIO_INT, // 84 HAL_CMU_AON_A_WDT, // 85 HAL_CMU_AON_A_PWM, // 86 HAL_CMU_AON_A_TIMER, // 87 HAL_CMU_AON_A_IOMUX, // 88 HAL_CMU_AON_A_SPIDPD, // 89 HAL_CMU_AON_A_APBC, // 90 HAL_CMU_AON_A_H2H_MCU, // 91 // AON OCLK/ORST HAL_CMU_AON_O_WDT, // 92 HAL_CMU_AON_O_TIMER, // 93 HAL_CMU_AON_O_GPIO, // 94 HAL_CMU_AON_O_PWM0, // 95 HAL_CMU_AON_O_PWM1, // 96 HAL_CMU_AON_O_PWM2, // 97 HAL_CMU_AON_O_PWM3, // 98 HAL_CMU_AON_O_IOMUX, // 99 HAL_CMU_AON_O_SLP32K, // 100 HAL_CMU_AON_O_SLP26M, // 101 HAL_CMU_AON_O_SPIDPD, // 102 HAL_CMU_AON_RESERVED0, // 103 // AON SUBSYS HAL_CMU_AON_A7, // 104 HAL_CMU_AON_A7CPU, // 105 HAL_CMU_AON_MCU, // 106 HAL_CMU_AON_CODEC, // 107 HAL_CMU_AON_WF, // 108 HAL_CMU_AON_BT, // 109 HAL_CMU_AON_MCUCPU, // 110 HAL_CMU_AON_WFCPU, // 111 HAL_CMU_AON_BTCPU, // 112 HAL_CMU_AON_GLOBAL, // 113 HAL_CMU_MOD_QTY, HAL_CMU_MOD_GLOBAL = HAL_CMU_AON_GLOBAL, HAL_CMU_MOD_BT = HAL_CMU_AON_BT, HAL_CMU_MOD_BTCPU = HAL_CMU_AON_BTCPU, HAL_CMU_MOD_WF = HAL_CMU_AON_WF, HAL_CMU_MOD_WFCPU = HAL_CMU_AON_WFCPU, HAL_CMU_MOD_P_PWM = HAL_CMU_AON_A_PWM, HAL_CMU_MOD_O_PWM0 = HAL_CMU_AON_O_PWM0, HAL_CMU_MOD_O_PWM1 = HAL_CMU_AON_O_PWM1, HAL_CMU_MOD_O_PWM2 = HAL_CMU_AON_O_PWM2, HAL_CMU_MOD_O_PWM3 = HAL_CMU_AON_O_PWM3, HAL_CMU_H_ICACHE = HAL_CMU_MOD_H_CACHE0, HAL_CMU_H_DCACHE = HAL_CMU_MOD_QTY, HAL_CMU_H_ICACHECP = HAL_CMU_MOD_H_CACHE1, HAL_CMU_H_DCACHECP = HAL_CMU_MOD_QTY, HAL_CMU_MOD_P_SPI_DPD = HAL_CMU_AON_A_SPIDPD, HAL_CMU_MOD_O_SPI_DPD = HAL_CMU_AON_O_SPIDPD, HAL_CMU_MOD_H_PSRAM = HAL_CMU_MOD_H_PSRAM200, HAL_CMU_MOD_O_PSRAM = HAL_CMU_MOD_O_PSRAM200, HAL_CMU_MOD_H_PSRAMUHS = HAL_CMU_MOD_H_PSRAM1G, HAL_CMU_MOD_O_PSRAMUHS = HAL_CMU_MOD_O_PSRAM1G, }; enum HAL_CMU_CLOCK_OUT_ID_T { HAL_CMU_CLOCK_OUT_AON_32K = 0x00, HAL_CMU_CLOCK_OUT_AON_26M = 0x01, HAL_CMU_CLOCK_OUT_AON_52M = 0x02, HAL_CMU_CLOCK_OUT_AON_DIG_52M = 0x03, HAL_CMU_CLOCK_OUT_AON_DIG_104M = 0x04, HAL_CMU_CLOCK_OUT_AON_PER = 0x05, HAL_CMU_CLOCK_OUT_AON_USB = 0x06, HAL_CMU_CLOCK_OUT_AON_DCDC = 0x07, HAL_CMU_CLOCK_OUT_AON_CHCLK = 0x08, HAL_CMU_CLOCK_OUT_AON_SPDIF0 = 0x09, HAL_CMU_CLOCK_OUT_AON_MCU = 0x0A, HAL_CMU_CLOCK_OUT_AON_FLASH = 0x0B, HAL_CMU_CLOCK_OUT_AON_SYS = 0x0C, HAL_CMU_CLOCK_OUT_BT_32K = 0x40, HAL_CMU_CLOCK_OUT_BT_SYS = 0x41, HAL_CMU_CLOCK_OUT_BT_52M = 0x42, HAL_CMU_CLOCK_OUT_BT_26MI = 0x43, HAL_CMU_CLOCK_OUT_BT_13M = 0x44, HAL_CMU_CLOCK_OUT_BT_12M = 0x45, HAL_CMU_CLOCK_OUT_BT_ADC = 0x46, HAL_CMU_CLOCK_OUT_BT_ADC2 = 0x47, HAL_CMU_CLOCK_OUT_BT_24M = 0x48, HAL_CMU_CLOCK_OUT_BT_26M = 0x49, HAL_CMU_CLOCK_OUT_MCU_32K = 0x60, HAL_CMU_CLOCK_OUT_MCU_SYS = 0x61, HAL_CMU_CLOCK_OUT_MCU_FLASH = 0x62, HAL_CMU_CLOCK_OUT_MCU_USB = 0x63, HAL_CMU_CLOCK_OUT_MCU_PCLK = 0x64, HAL_CMU_CLOCK_OUT_MCU_I2S = 0x65, HAL_CMU_CLOCK_OUT_MCU_PCM = 0x66, HAL_CMU_CLOCK_OUT_MCU_SPDIF0 = 0x67, HAL_CMU_CLOCK_OUT_MCU_SDMMC = 0x68, HAL_CMU_CLOCK_OUT_MCU_SPI2 = 0x69, HAL_CMU_CLOCK_OUT_MCU_SPI0 = 0x6A, HAL_CMU_CLOCK_OUT_MCU_SPI1 = 0x6B, HAL_CMU_CLOCK_OUT_CODEC_ADC_ANA = 0x80, HAL_CMU_CLOCK_OUT_CODEC_CODEC = 0x81, HAL_CMU_CLOCK_OUT_CODEC_IIR = 0x82, HAL_CMU_CLOCK_OUT_CODEC_RS = 0x83, HAL_CMU_CLOCK_OUT_CODEC_HCLK = 0x84, }; enum HAL_CMU_I2S_MCLK_ID_T { HAL_CMU_I2S_MCLK_PLLCODEC = 0x00, HAL_CMU_I2S_MCLK_CODEC = 0x01, HAL_CMU_I2S_MCLK_PLLIIR = 0x02, HAL_CMU_I2S_MCLK_PLLRS = 0x03, HAL_CMU_I2S_MCLK_PLLSPDIF0 = 0x04, HAL_CMU_I2S_MCLK_PLLPCM = 0x05, HAL_CMU_I2S_MCLK_PER = 0x06, HAL_CMU_I2S_MCLK_CLK_OUT = 0x07, }; enum HAL_CMU_LOW_SYS_FREQ_T { HAL_CMU_LOW_SYS_FREQ_NONE, HAL_CMU_LOW_SYS_FREQ_13M, HAL_CMU_LOW_SYS_FREQ_6P5M, }; enum HAL_CMU_FREQ_T { HAL_CMU_FREQ_32K, HAL_CMU_FREQ_26M, HAL_CMU_FREQ_52M, HAL_CMU_FREQ_78M, HAL_CMU_FREQ_104M, HAL_CMU_FREQ_156M, HAL_CMU_FREQ_208M, HAL_CMU_FREQ_260M, HAL_CMU_FREQ_390M, HAL_CMU_FREQ_780M, HAL_CMU_FREQ_QTY }; #define HAL_CMU_FREQ_T HAL_CMU_FREQ_T enum HAL_CMU_PLL_T { HAL_CMU_PLL_USB = 0, HAL_CMU_PLL_AUD = HAL_CMU_PLL_USB, HAL_CMU_PLL_DDR, HAL_CMU_PLL_DSP, HAL_CMU_PLL_BB, HAL_CMU_PLL_BB_PSRAM, HAL_CMU_PLL_QTY }; #define HAL_CMU_PLL_T HAL_CMU_PLL_T enum HAL_CMU_PLL_USER_T { HAL_CMU_PLL_USER_SYS, HAL_CMU_PLL_USER_AUD, HAL_CMU_PLL_USER_USB, HAL_CMU_PLL_USER_FLASH, HAL_CMU_PLL_USER_PSRAM, HAL_CMU_PLL_USER_DSP, HAL_CMU_PLL_USER_QTY, HAL_CMU_PLL_USER_ALL = HAL_CMU_PLL_USER_QTY, }; #define HAL_CMU_PLL_USER_T HAL_CMU_PLL_USER_T void hal_cmu_low_sys_clock_set(enum HAL_CMU_LOW_SYS_FREQ_T freq); int hal_cmu_low_sys_clock_enabled(void); int hal_cmu_ddr_clock_enable(); void hal_cmu_codec_vad_clock_enable(uint32_t enabled); uint32_t hal_cmu_get_aon_chip_id(void); uint32_t hal_cmu_get_aon_revision_id(void); void hal_cmu_dma_dsd_enable(void); void hal_cmu_dma_dsd_disable(void); void hal_cmu_cp_enable(uint32_t sp, uint32_t entry); void hal_cmu_cp_disable(void); uint32_t hal_cmu_cp_get_entry_addr(void); void hal_cmu_wifi_clock_enable(void); void hal_cmu_wifi_clock_disable(void); void hal_cmu_wifi_reset_set(void); void hal_cmu_wifi_reset_clear(void); void hal_cmu_wifi_module_reset_clear(void); void hal_cmu_wifi_cpu_reset_clear(void); void hal_cmu_wifi_clock_cfg_80M(void); void hal_cmu_dsp_clock_enable(void); void hal_cmu_dsp_clock_disable(void); void hal_cmu_dsp_reset_set(void); void hal_cmu_dsp_reset_clear(void); void hal_cmu_dsp_init_boot_reg(uint32_t entry); void hal_cmu_dsp_start_cpu(void); void hal_cmu_dsp_setup(void); void hal_cmu_dsp_stop_cpu(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/haas1000/hal_cmu_haas1000.h
C
apache-2.0
10,903
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_DMACFG_BEST2001_H__ #define __HAL_DMACFG_BEST2001_H__ #define AUDMA_PERIPH_NUM 16 #define GPDMA_PERIPH_NUM 16 #define AUDMA_CHAN_NUM 8 #define GPDMA_CHAN_NUM 8 #define AUDMA_CHAN_START (0) #define GPDMA_CHAN_START (0) static const uint32_t bes2001_audma_fifo_addr[AUDMA_PERIPH_NUM] = { #if (A7_UART==1) UART0_BASE + 0x000, // UART0 RX UART0_BASE + 0x000, // UART0 TX #else CODEC_BASE + 0x01C, // CODEC RX CODEC_BASE + 0x01C, // CODEC TX #endif CODEC_BASE + 0x034, // DSD RX CODEC_BASE + 0x034, // DSD TX CODEC_BASE + 0x058, // CODEC TX2 I2C1_BASE + 0x010, // I2C1 RX I2C1_BASE + 0x010, // I2C1 TX SPI_BASE + 0x008, // SPI RX SPI_BASE + 0x008, // SPI TX 0, // NULL BTPCM_BASE + 0x1C0, // BTPCM RX BTPCM_BASE + 0x1C8, // BTPCM TX UART2_BASE + 0x000, // UART2 RX UART2_BASE + 0x000, // UART2 TX UART1_BASE + 0x000, // UART1 RX UART1_BASE + 0x000, // UART1 TX }; static const enum HAL_DMA_PERIPH_T bes2001_audma_fifo_periph[AUDMA_PERIPH_NUM] = { #if (A7_UART==1) HAL_GPDMA_UART0_RX, HAL_GPDMA_UART0_TX, #else HAL_AUDMA_CODEC_RX, HAL_AUDMA_CODEC_TX, #endif HAL_AUDMA_DSD_RX, HAL_AUDMA_DSD_TX, HAL_AUDMA_CODEC_TX2, HAL_GPDMA_I2C1_RX, HAL_GPDMA_I2C1_TX, #ifndef USED_SPI0_DMA HAL_GPDMA_SPI_RX, HAL_GPDMA_SPI_TX, #else HAL_AUDMA_I2S0_RX, HAL_AUDMA_I2S0_TX, #endif HAL_DMA_PERIPH_NULL, HAL_AUDMA_BTPCM_RX, HAL_AUDMA_BTPCM_TX, HAL_GPDMA_UART2_RX, HAL_GPDMA_UART2_TX, HAL_GPDMA_UART1_RX, HAL_GPDMA_UART1_TX, }; static const uint32_t bes2001_gpdma_fifo_addr[GPDMA_PERIPH_NUM] = { CODEC_BASE + 0x01C, // CODEC RX CODEC_BASE + 0x01C, // CODEC TX ISPI_BASE + 0x008, // ISPI TX ISPI_BASE + 0x008, // ISPI RX UART0_BASE + 0x000, // UART0 RX UART0_BASE + 0x000, // UART0 TX UART2_BASE + 0x000, // UART1 RX UART2_BASE + 0x000, // UART1 TX BTDUMP_BASE + 0x34, // BTDUMP SDMMC_BASE + 0x200, // SDMMC I2S0_BASE + 0x200, // I2S0 RX I2S0_BASE + 0x240, // I2S0 TX UART1_BASE + 0x000, // UART1 RX UART1_BASE + 0x000, // UART1 TX //I2C0_BASE + 0x010, // I2C RX //I2C0_BASE + 0x010, // I2C TX SPILCD_BASE + 0x008, // SPILCD RX SPILCD_BASE + 0x008, // SPILCD TX }; static const enum HAL_DMA_PERIPH_T bes2001_gpdma_fifo_periph[GPDMA_PERIPH_NUM] = { HAL_AUDMA_CODEC_RX, HAL_AUDMA_CODEC_TX, HAL_GPDMA_ISPI_RX, HAL_GPDMA_ISPI_TX, HAL_GPDMA_UART0_RX, HAL_GPDMA_UART0_TX, HAL_GPDMA_UART2_RX, HAL_GPDMA_UART2_TX, HAL_AUDMA_BTDUMP, HAL_GPDMA_SDMMC, #ifdef USED_SPI0_DMA HAL_GPDMA_SPI_RX, HAL_GPDMA_SPI_TX, #else HAL_AUDMA_I2S0_RX, HAL_AUDMA_I2S0_TX, #endif HAL_GPDMA_UART1_RX, HAL_GPDMA_UART1_TX, //HAL_GPDMA_I2C0_RX, //HAL_GPDMA_I2C0_TX, HAL_GPDMA_SPILCD_RX, HAL_GPDMA_SPILCD_TX, }; #ifndef DSP_USE_AUDMA #define audma_fifo_addr bes2001_audma_fifo_addr #define audma_fifo_periph bes2001_audma_fifo_periph #define gpdma_fifo_addr bes2001_gpdma_fifo_addr #define gpdma_fifo_periph bes2001_gpdma_fifo_periph #else #ifdef CHIP_HAAS1000_DSP //A7 use AUDMA #define audma_fifo_addr bes2001_audma_fifo_addr #define audma_fifo_periph bes2001_audma_fifo_periph #else //MCU use GPDMA #define audma_fifo_addr bes2001_gpdma_fifo_addr #define audma_fifo_periph bes2001_gpdma_fifo_periph #endif #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/haas1000/hal_dmacfg_haas1000.h
C
apache-2.0
4,351
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_IOMUX_HAAS1000_H__ #define __HAL_IOMUX_HAAS1000_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #ifndef ROM_BUILD #define PMU_HAS_LED_PIN #endif enum HAL_IOMUX_PIN_T { HAL_IOMUX_PIN_P0_0 = 0, HAL_IOMUX_PIN_P0_1, HAL_IOMUX_PIN_P0_2, HAL_IOMUX_PIN_P0_3, HAL_IOMUX_PIN_P0_4, HAL_IOMUX_PIN_P0_5, HAL_IOMUX_PIN_P0_6, HAL_IOMUX_PIN_P0_7, HAL_IOMUX_PIN_P1_0, HAL_IOMUX_PIN_P1_1, HAL_IOMUX_PIN_P1_2, HAL_IOMUX_PIN_P1_3, HAL_IOMUX_PIN_P1_4, HAL_IOMUX_PIN_P1_5, HAL_IOMUX_PIN_P1_6, HAL_IOMUX_PIN_P1_7, HAL_IOMUX_PIN_P2_0, HAL_IOMUX_PIN_P2_1, HAL_IOMUX_PIN_P2_2, HAL_IOMUX_PIN_P2_3, HAL_IOMUX_PIN_P2_4, HAL_IOMUX_PIN_P2_5, HAL_IOMUX_PIN_P2_6, HAL_IOMUX_PIN_P2_7, HAL_IOMUX_PIN_P3_0, HAL_IOMUX_PIN_P3_1, HAL_IOMUX_PIN_P3_2, HAL_IOMUX_PIN_P3_3, HAL_IOMUX_PIN_P3_4, HAL_IOMUX_PIN_P3_5, HAL_IOMUX_PIN_P3_6, HAL_IOMUX_PIN_P3_7, HAL_IOMUX_PIN_P4_0, HAL_IOMUX_PIN_P4_1, HAL_IOMUX_PIN_P4_2, HAL_IOMUX_PIN_P4_3, HAL_IOMUX_PIN_P4_4, HAL_IOMUX_PIN_P4_5, HAL_IOMUX_PIN_P4_6, HAL_IOMUX_PIN_P4_7, HAL_IOMUX_PIN_NUM, HAL_IOMUX_PIN_LED1 = HAL_IOMUX_PIN_NUM, HAL_IOMUX_PIN_LED2, HAL_IOMUX_PIN_LED_NUM, }; enum HAL_GPIO_PIN_T { HAL_GPIO_PIN_P0_0 = HAL_IOMUX_PIN_P0_0, HAL_GPIO_PIN_P0_1 = HAL_IOMUX_PIN_P0_1, HAL_GPIO_PIN_P0_2 = HAL_IOMUX_PIN_P0_2, HAL_GPIO_PIN_P0_3 = HAL_IOMUX_PIN_P0_3, HAL_GPIO_PIN_P0_4 = HAL_IOMUX_PIN_P0_4, HAL_GPIO_PIN_P0_5 = HAL_IOMUX_PIN_P0_5, HAL_GPIO_PIN_P0_6 = HAL_IOMUX_PIN_P0_6, HAL_GPIO_PIN_P0_7 = HAL_IOMUX_PIN_P0_7, HAL_GPIO_PIN_P1_0 = HAL_IOMUX_PIN_P1_0, HAL_GPIO_PIN_P1_1 = HAL_IOMUX_PIN_P1_1, HAL_GPIO_PIN_P1_2 = HAL_IOMUX_PIN_P1_2, HAL_GPIO_PIN_P1_3 = HAL_IOMUX_PIN_P1_3, HAL_GPIO_PIN_P1_4 = HAL_IOMUX_PIN_P1_4, HAL_GPIO_PIN_P1_5 = HAL_IOMUX_PIN_P1_5, HAL_GPIO_PIN_P1_6 = HAL_IOMUX_PIN_P1_6, HAL_GPIO_PIN_P1_7 = HAL_IOMUX_PIN_P1_7, HAL_GPIO_PIN_P2_0 = HAL_IOMUX_PIN_P2_0, HAL_GPIO_PIN_P2_1 = HAL_IOMUX_PIN_P2_1, HAL_GPIO_PIN_P2_2 = HAL_IOMUX_PIN_P2_2, HAL_GPIO_PIN_P2_3 = HAL_IOMUX_PIN_P2_3, HAL_GPIO_PIN_P2_4 = HAL_IOMUX_PIN_P2_4, HAL_GPIO_PIN_P2_5 = HAL_IOMUX_PIN_P2_5, HAL_GPIO_PIN_P2_6 = HAL_IOMUX_PIN_P2_6, HAL_GPIO_PIN_P2_7 = HAL_IOMUX_PIN_P2_7, HAL_GPIO_PIN_P3_0 = HAL_IOMUX_PIN_P3_0, HAL_GPIO_PIN_P3_1 = HAL_IOMUX_PIN_P3_1, HAL_GPIO_PIN_P3_2 = HAL_IOMUX_PIN_P3_2, HAL_GPIO_PIN_P3_3 = HAL_IOMUX_PIN_P3_3, HAL_GPIO_PIN_P3_4 = HAL_IOMUX_PIN_P3_4, HAL_GPIO_PIN_P3_5 = HAL_IOMUX_PIN_P3_5, HAL_GPIO_PIN_P3_6 = HAL_IOMUX_PIN_P3_6, HAL_GPIO_PIN_P3_7 = HAL_IOMUX_PIN_P3_7, HAL_GPIO_PIN_P4_0 = HAL_IOMUX_PIN_P4_0, HAL_GPIO_PIN_P4_1 = HAL_IOMUX_PIN_P4_1, HAL_GPIO_PIN_P4_2 = HAL_IOMUX_PIN_P4_2, HAL_GPIO_PIN_P4_3 = HAL_IOMUX_PIN_P4_3, HAL_GPIO_PIN_P4_4 = HAL_IOMUX_PIN_P4_4, HAL_GPIO_PIN_P4_5 = HAL_IOMUX_PIN_P4_5, HAL_GPIO_PIN_P4_6 = HAL_IOMUX_PIN_P4_6, HAL_GPIO_PIN_P4_7 = HAL_IOMUX_PIN_P4_7, HAL_GPIO_PIN_NUM = HAL_IOMUX_PIN_NUM, HAL_GPIO_PIN_LED1 = HAL_IOMUX_PIN_LED1, HAL_GPIO_PIN_LED2 = HAL_IOMUX_PIN_LED2, HAL_GPIO_PIN_LED_NUM = HAL_IOMUX_PIN_LED_NUM, }; enum HAL_IOMUX_FUNCTION_T { HAL_IOMUX_FUNC_NONE = 0, HAL_IOMUX_FUNC_GPIO, HAL_IOMUX_FUNC_AS_GPIO = HAL_IOMUX_FUNC_GPIO, HAL_IOMUX_FUNC_BT_UART_CTS, HAL_IOMUX_FUNC_BT_UART_RTS, HAL_IOMUX_FUNC_BT_UART_RX, HAL_IOMUX_FUNC_BT_UART_TX, HAL_IOMUX_FUNC_CLK_32K_IN, HAL_IOMUX_FUNC_CLK_REQ_IN, HAL_IOMUX_FUNC_CLK_REQ_OUT, HAL_IOMUX_FUNC_CLK_OUT, HAL_IOMUX_FUNC_I2C_M0_SCL, HAL_IOMUX_FUNC_I2C_M0_SDA, HAL_IOMUX_FUNC_I2C_M1_SCL, HAL_IOMUX_FUNC_I2C_M1_SDA, HAL_IOMUX_FUNC_I2S0_MCLK, HAL_IOMUX_FUNC_I2S0_SCK, HAL_IOMUX_FUNC_I2S0_SDI0, HAL_IOMUX_FUNC_I2S0_SDI1, HAL_IOMUX_FUNC_I2S0_SDI2, HAL_IOMUX_FUNC_I2S0_SDI3, HAL_IOMUX_FUNC_I2S0_SDO, HAL_IOMUX_FUNC_I2S0_WS, HAL_IOMUX_FUNC_PCM_CLK, HAL_IOMUX_FUNC_PCM_DI, HAL_IOMUX_FUNC_PCM_DO, HAL_IOMUX_FUNC_PCM_FSYNC, HAL_IOMUX_FUNC_PDM0_CK, HAL_IOMUX_FUNC_PDM0_D, HAL_IOMUX_FUNC_PDM1_CK, HAL_IOMUX_FUNC_PDM1_D, HAL_IOMUX_FUNC_PDM2_CK, HAL_IOMUX_FUNC_PDM2_D, HAL_IOMUX_FUNC_PWM0, HAL_IOMUX_FUNC_PWM1, HAL_IOMUX_FUNC_PWM2, HAL_IOMUX_FUNC_PWM3, HAL_IOMUX_FUNC_SDMMC_CLK, HAL_IOMUX_FUNC_SDMMC_CMD, HAL_IOMUX_FUNC_SDMMC_DATA0, HAL_IOMUX_FUNC_SDMMC_DATA1, HAL_IOMUX_FUNC_SDMMC_DATA2, HAL_IOMUX_FUNC_SDMMC_DATA3, HAL_IOMUX_FUNC_SDMMC_DATA4, HAL_IOMUX_FUNC_SDMMC_DATA5, HAL_IOMUX_FUNC_SDMMC_DATA6, HAL_IOMUX_FUNC_SDMMC_DATA7, HAL_IOMUX_FUNC_SPDIF0_DI, HAL_IOMUX_FUNC_SPDIF0_DO, HAL_IOMUX_FUNC_SPI_CLK,//spi0 HAL_IOMUX_FUNC_SPI_CS0, HAL_IOMUX_FUNC_SPI_CS1, HAL_IOMUX_FUNC_SPI_CS2, HAL_IOMUX_FUNC_SPI_CS3, HAL_IOMUX_FUNC_SPI_DCN, HAL_IOMUX_FUNC_SPI_DI0, HAL_IOMUX_FUNC_SPI_DI1, HAL_IOMUX_FUNC_SPI_DI2, HAL_IOMUX_FUNC_SPI_DI3, HAL_IOMUX_FUNC_SPI_DIO, HAL_IOMUX_FUNC_SPILCD_CLK,//spi1 HAL_IOMUX_FUNC_SPILCD_CS0, HAL_IOMUX_FUNC_SPILCD_CS1, HAL_IOMUX_FUNC_SPILCD_CS2, HAL_IOMUX_FUNC_SPILCD_CS3, HAL_IOMUX_FUNC_SPILCD_DCN, HAL_IOMUX_FUNC_SPILCD_DI0, HAL_IOMUX_FUNC_SPILCD_DI1, HAL_IOMUX_FUNC_SPILCD_DI2, HAL_IOMUX_FUNC_SPILCD_DI3, HAL_IOMUX_FUNC_SPILCD_DIO, HAL_IOMUX_FUNC_UART0_RX, HAL_IOMUX_FUNC_UART0_TX, HAL_IOMUX_FUNC_UART1_CTS, HAL_IOMUX_FUNC_UART1_RTS, HAL_IOMUX_FUNC_UART1_RX, HAL_IOMUX_FUNC_UART1_TX, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_FUNC_UART2_CTS, HAL_IOMUX_FUNC_UART2_RTS, HAL_IOMUX_FUNC_WF_UART_CTS, HAL_IOMUX_FUNC_WF_UART_RTS, HAL_IOMUX_FUNC_WF_UART_RX, HAL_IOMUX_FUNC_WF_UART_TX, HAL_IOMUX_FUNC_WF_FEM_CNTL0,//no ctrl1 HAL_IOMUX_FUNC_WF_FEM_CNTL2, HAL_IOMUX_FUNC_WF_FEM_CNTL3, HAL_IOMUX_FUNC_WF_FEM_CNTL4, HAL_IOMUX_FUNC_WF_FEM_CNTL5, HAL_IOMUX_FUNC_WF_FEM_CNTL6, HAL_IOMUX_FUNC_WF_FEM_CNTL7, HAL_IOMUX_FUNC_WF_FEM_CNTL8, HAL_IOMUX_FUNC_WF_FEM_CNTL9, HAL_IOMUX_FUNC_WF_SDIO_CLK, HAL_IOMUX_FUNC_WF_SDIO_CMD, HAL_IOMUX_FUNC_WF_SDIO_DATA0, HAL_IOMUX_FUNC_WF_SDIO_DATA1, HAL_IOMUX_FUNC_WF_SDIO_DATA2, HAL_IOMUX_FUNC_WF_SDIO_DATA3, HAL_IOMUX_FUNC_WF_WAKE_HOST, HAL_IOMUX_FUNC_WF_TXON, HAL_IOMUX_FUNC_END }; enum HAL_IOMUX_ISPI_ACCESS_T { HAL_IOMUX_ISPI_BT_RF = (1 << 0), HAL_IOMUX_ISPI_BT_PMU = (1 << 1), HAL_IOMUX_ISPI_BT_ANA = (1 << 2), HAL_IOMUX_ISPI_MCU_RF = (1 << 3), HAL_IOMUX_ISPI_MCU_PMU = (1 << 4), HAL_IOMUX_ISPI_MCU_ANA = (1 << 5), }; void hal_iomux_set_i2s_mclk(void); void hal_iomux_set_i2s1(void); void hal_iomux_set_mcu_clock_out(void); void hal_iomux_set_bt_clock_out(void); int32_t hal_iomux_set_io_driver(enum HAL_IOMUX_PIN_T pin, uint32_t val); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/haas1000/hal_iomux_haas1000.h
C
apache-2.0
7,673
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_XDMACFG_BEST2001_H__ #define __HAL_XDMACFG_BEST2001_H__ #define DSPXDMA_PERIPH_NUM 2 #define DSPXDMA_CHAN_NUM 16 #define DSPXDMA_CHAN_START (0) static const uint32_t bes2001_dspxdma_fifo_addr[DSPXDMA_PERIPH_NUM] = { FLASH_CTRL_BASE + 0x008, // FLASH RX FLASH_CTRL_BASE + 0x008, // FLASH TX }; static const enum HAL_XDMA_PERIPH_T bes2001_dspxdma_fifo_periph[DSPXDMA_PERIPH_NUM] = { HAL_DSPXDMA_MEM, }; #define dspxdma_fifo_addr bes2001_dspxdma_fifo_addr #define dspxdma_fifo_periph bes2001_dspxdma_fifo_periph #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/haas1000/hal_xdmacfg_haas1000.h
C
apache-2.0
1,266
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __PLAT_ADDR_MAP_BEST2001_H__ #define __PLAT_ADDR_MAP_BEST2001_H__ #ifdef __cplusplus extern "C" { #endif #define ROM_BASE 0x00000000 #define ROMD_BASE 0x24000000 #ifndef ROM_SIZE #define ROM_SIZE 0x00010000 #endif #define RAM0_BASE 0x20000000 #define RAMX0_BASE 0x00200000 #define RAM1_BASE 0x20040000 #define RAMX1_BASE 0x00240000 #define RAM2_BASE 0x20060000 #define RAMX2_BASE 0x00260000 #define RAM3_BASE 0x20080000 #define RAMX3_BASE 0x00280000 #define RAM4_BASE 0x200A0000 #define RAMX4_BASE 0x002A0000 #define RAM5_BASE 0x200C0000 #define RAMX5_BASE 0x002C0000 #define RAM6_BASE 0x200E0000 #define RAMX6_BASE 0x002E0000 #define RAM7_BASE 0x20100000 #define RAMX7_BASE 0x00300000 #define RAM8_BASE 0x20180000 #define RAMX8_BASE 0x00380000 #define RAM9_BASE 0x20200000 #define RAMX9_BASE 0x00400000 #define RAM_BASE RAM0_BASE #define RAMX_BASE RAMX0_BASE #define RAM9_SIZE 0x00080000 #ifdef LARGE_RAM #ifndef RAMCP_BASE #define RAMCP_BASE RAM9_BASE #endif #ifndef RAMCP_SIZE #define RAMCP_SIZE 0x30000 #endif #ifndef RAMCPX_BASE #define RAMCPX_BASE (RAMX9_BASE + RAMCP_SIZE) #endif #ifndef RAMCPX_SIZE #define RAMCPX_SIZE (RAM9_SIZE - RAMCP_SIZE) #endif #else /*LARGE_RAM*/ #ifndef RAMCP_BASE #define RAMCP_BASE RAM2_BASE #endif #ifndef RAMCP_SIZE #define RAMCP_SIZE (RAM3_BASE - RAMCP_BASE) #endif #ifndef RAMCPX_BASE #define RAMCPX_BASE RAMX1_BASE #endif #ifndef RAMCPX_SIZE #define RAMCPX_SIZE (RAMX2_BASE - RAMCPX_BASE) #endif #endif /*LARGE_RAM*/ #define MAX_RAM_SIZE (RAM9_BASE + RAM9_SIZE - RAM0_BASE) // 0x00280000 #ifndef RAM_SIZE #ifdef LARGE_RAM #ifdef NO_RAMCP #define RAM_SIZE MAX_RAM_SIZE #else #define RAM_SIZE (RAM9_BASE - RAM0_BASE) // 0x00080000 #endif #else #ifdef NO_RAMCP #define RAM_SIZE (RAM3_BASE - RAM0_BASE) // 0x00080000 #else #define RAM_SIZE (RAM1_BASE - RAM0_BASE) // 0x00040000 #endif #endif #endif #ifndef MCU_PSRAMUHS_SIZE #define MCU_PSRAMUHS_SIZE (0) #endif #define FLASH_BASE 0x2C000000 #define FLASH_NC_BASE 0x28000000 #define FLASHX_BASE 0x0C000000 #define FLASHX_NC_BASE 0x08000000 #define PSRAM_BASE 0x34000000 #define PSRAM_NC_BASE 0x30000000 #define PSRAMX_BASE 0x14000000 #define PSRAMX_NC_BASE 0x10000000 #define PSRAMUHS_BASE 0x3C000000 #define PSRAMUHS_NC_BASE 0x38000000 #define PSRAMUHSX_BASE 0x1C000000 #define PSRAMUHSX_NC_BASE 0x18000000 #define ICACHE_CTRL_BASE 0x07FFE000 #define ICACHECP_CTRL_BASE 0x07FFE000 #define DCACHE_CTRL_BASE 0x27FFE000 #define DCACHECP_CTRL_BASE 0x27FFE000 #define CMU_BASE 0x40000000 #define MCU_WDT_BASE 0x40001000 #define MCU_TIMER0_BASE 0x40002000 #define MCU_TIMER1_BASE 0x40003000 #define MCU_TIMER2_BASE 0x40004000 #define I2C0_BASE 0x40005000 #define I2C1_BASE 0x40006000 #define SPI_BASE 0x40007000 #define SPILCD_BASE 0x40008000 #define ISPI_BASE 0x40009000 #define SPIPHY_BASE 0x4000A000 #define UART0_BASE 0x4000B000 #define UART1_BASE 0x4000C000 #define UART2_BASE 0x4000D000 #define BTPCM_BASE 0x4000E000 #define I2S0_BASE 0x4000F000 #define SPDIF0_BASE 0x40010000 #define TRANSQW_BASE 0x40011000 #define TRANSQD_BASE 0x40012000 #define TRNG_BASE 0x40013000 #define SEC_ENG_BASE 0x40020000 #define AON_CMU_BASE 0x40080000 #define AON_GPIO_BASE 0x40081000 #define AON_WDT_BASE 0x40082000 #define AON_PWM_BASE 0x40083000 #define AON_TIMER_BASE 0x40084000 #define AON_GPIOAUX_BASE 0x40085000 #define AON_IOMUX_BASE 0x40086000 #define AON_SPIDPD_BASE 0x40087000 #define CHECKSUM_BASE 0x40100000 #define CRC_BASE 0x40108000 #define SDMMC_BASE 0x40110000 #define BES2001_AUDMA_BASE 0x40120000 #define BES2001_GPDMA_BASE 0x40130000 #define FLASH_CTRL_BASE 0x40140000 #define PSRAM_CTRL_BASE 0x40150000 #define I2C_SLAVE_BASE 0x40160000 #define WFDUMP_BASE 0x40170000 #define USB_BASE 0x40180000 #define SEDMA_BASE 0x401D0000 #define BTDUMP_BASE 0x401E0000 #define PSRAMUHS_CTRL_BASE 0x401F0000 #define CODEC_BASE 0x40300000 #define PATCH_ENTRY_NUM 8 #define PATCH_CTRL_BASE 0x000FFE00 #define PATCH_DATA_BASE 0x000FFF00 #define WIFI_PATCH_CTRL_BASE 0x6007fe00 #define WIFI_PATCH_DATA_BASE 0x6007ff00 #define BT_SUBSYS_BASE 0xA0000000 #define BT_RAM_BASE 0xC0000000 #define BT_UART_BASE 0xD0300000 #define BT_CMU_BASE 0xD0330000 #define WIFI_SUBSYS_BASE 0x60000000 #define WIFI_RAM_BASE 0x80000000 #define WIFI_PAS_BASE 0x82000000 #define WIFI_TRANSQM_BASE 0x9000A000 #define DSP_SUBSYS_BASE 0x50000000 #define DSP_BOOT_BASE 0x00000000 #define DSP_BOOT_SIZE (24 * 4) #define DSP_RAM0_BASE 0x50000000 #define DSP_RAM1_BASE 0x50080000 #define DSP_RAM2_BASE 0x50100000 #define DSP_RAM3_BASE 0x50180000 #define DSP_RAM4_BASE 0x50200000 #define DSP_RAM5_BASE 0x50220000 #define DSP_RAM_BASE DSP_RAM0_BASE #define DSP_RAM5_SIZE 0x00020000 #define MAX_DSP_RAM_SIZE (DSP_RAM5_BASE + DSP_RAM5_SIZE - DSP_RAM0_BASE) #ifndef DSP_RAM_SIZE #ifdef LARGE_DSP_RAM #define DSP_RAM_SIZE MAX_DSP_RAM_SIZE #else /*LARGE_DSP_RAM*/ #ifdef FPGA #define DSP_RAM_SIZE (DSP_RAM1_BASE - DSP_RAM0_BASE) #else /*FPGA*/ #define DSP_RAM_SIZE (DSP_RAM4_BASE - DSP_RAM0_BASE) #endif /*FPGA*/ #endif /*LARGE_DSP_RAM*/ #endif #ifndef DSP_PSRAMUHS_SIZE #define DSP_PSRAMUHS_SIZE (0) #endif #define DSP_PSRAMUHS_BASE (PSRAMUHS_BASE) #define DSP_PSRAMUHSX_BASE (PSRAMUHSX_BASE) #define MCU_PSRAMUHS_BASE (PSRAMUHS_BASE + DSP_PSRAMUHS_SIZE) #define MCU_PSRAMUHS_NC_BASE (PSRAMUHS_NC_BASE + DSP_PSRAMUHS_SIZE) #define MCU_PSRAMUHSX_BASE (PSRAMUHSX_BASE + DSP_PSRAMUHS_SIZE) #define DSP_BOOT_REG 0x58000000 #define DSP_WDT_BASE 0x58001000 #define DSP_TIMER0_BASE 0x58002000 #define DSP_TIMER1_BASE 0x58003000 #define DSP_TRANSQM_BASE 0x58004000 #define DSP_TIMESTAMP_GEN_BASE 0x58020000 #define DSP_DEBUGSYS_APB_BASE 0x58040000 #define DSP_XDMA_BASE 0x58200000 #define GIC_DISTRIBUTOR_BASE 0x58301000 #define GIC_INTERFACE_BASE 0x58302000 #define IOMUX_BASE AON_IOMUX_BASE #define GPIO_BASE AON_GPIO_BASE #define GPIOAUX_BASE AON_GPIOAUX_BASE #define PWM_BASE AON_PWM_BASE #define SPIDPD_BASE AON_SPIDPD_BASE #ifdef CHIP_HAAS1000_DSP #define TIMER0_BASE DSP_TIMER0_BASE #define TIMER1_BASE DSP_TIMER1_BASE #define TRANSQ0_BASE TRANSQW_BASE #define TRANSQ0_PEER_BASE WIFI_TRANSQM_BASE #define TRANSQ1_BASE DSP_TRANSQM_BASE #define TRANSQ1_PEER_BASE TRANSQD_BASE #define WDT_BASE DSP_WDT_BASE #else #define TIMER0_BASE MCU_TIMER0_BASE #define TIMER1_BASE MCU_TIMER1_BASE #define TIMER2_BASE MCU_TIMER2_BASE #define TRANSQ0_BASE TRANSQW_BASE #define TRANSQ0_PEER_BASE WIFI_TRANSQM_BASE #define TRANSQ1_BASE TRANSQD_BASE #define TRANSQ1_PEER_BASE DSP_TRANSQM_BASE #define WDT_BASE AON_WDT_BASE #endif #ifndef DSP_USE_AUDMA #define AUDMA_BASE BES2001_AUDMA_BASE #define GPDMA_BASE BES2001_GPDMA_BASE #else /*DSP_USE_AUDMA*/ #ifdef CHIP_HAAS1000_DSP #define AUDMA_BASE BES2001_AUDMA_BASE //A7 use AUDMA #else #define AUDMA_BASE BES2001_GPDMA_BASE //MCU use GPDMA #endif #endif /*DSP_USE_AUDMA*/ /* For module features */ #define SEC_ENG_HAS_HASH /* For linker scripts */ #define VECTOR_SECTION_SIZE 360 #define REBOOT_PARAM_SECTION_SIZE 64 #define ROM_BUILD_INFO_SECTION_SIZE 40 #define ROM_EXPORT_FN_SECTION_SIZE 128 #define PSRAMUHSX_TO_PSRAMUHS(d) ((d) - PSRAMUHSX_BASE + PSRAMUHS_BASE) #define PSRAMUHS_TO_PSRAMUHSX(d) ((d) - PSRAMUHS_BASE + PSRAMUHSX_BASE) #define PSRAMUHS_TO_PSRAMUHSNC(d) ((d) - PSRAMUHS_BASE + PSRAMUHS_NC_BASE) #define BT_INTESYS_MEM_OFFSET 0x00000000 #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/haas1000/plat_addr_map_haas1000.h
C
apache-2.0
12,412
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_ANALOGIF_H__ #define __HAL_ANALOGIF_H__ #ifdef __cplusplus extern "C" { #endif int hal_analogif_open(void); int hal_analogif_reg_write(unsigned short reg, unsigned short val); int hal_analogif_reg_read(unsigned short reg, unsigned short *val); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_analogif.h
C
apache-2.0
951
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 AUDIO_DEF_H #define AUDIO_DEF_H #ifdef __cplusplus extern "C" { #endif #include <stdint.h> #define CODEC_FREQ_24M 24000000 #define CODEC_FREQ_26M 26000000 #define CODEC_FREQ_24P576M 24576000 #define CODEC_FREQ_22P5792M 22579200 #define CODEC_FREQ_48K_SERIES CODEC_FREQ_24P576M #define CODEC_FREQ_44_1K_SERIES CODEC_FREQ_22P5792M #if 0 #elif defined(CHIP_BEST3001) || defined(CHIP_BEST3003) || defined(CHIP_BEST3005) #define CODEC_FREQ_CRYSTAL CODEC_FREQ_24M #define CODEC_PLL_DIV 36 #define CODEC_CMU_DIV 9 #ifdef CHIP_BEST3001 #define CODEC_PLAYBACK_BIT_DEPTH 20 #else #define CODEC_PLAYBACK_BIT_DEPTH 24 #endif #elif defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \ defined(CHIP_BEST2300) || defined(CHIP_BEST2300P) #define CODEC_FREQ_EXTRA_DIV 2 #define CODEC_PLL_DIV 16 #define CODEC_CMU_DIV 8 #define CODEC_PLAYBACK_BIT_DEPTH 24 #elif defined(CHIP_BEST1000) #if defined(__AUDIO_DIV_10___) #define CODEC_PLL_DIV 10 #elif defined(__AUDIO_DIV_9___) #define CODEC_PLL_DIV 9 #else #define CODEC_PLL_DIV 8 #endif #define CODEC_PLAYBACK_BIT_DEPTH 18 #elif defined(CHIP_BEST2000) #define CODEC_PLL_DIV 32 #define CODEC_CMU_DIV 8 #define CODEC_PLAYBACK_BIT_DEPTH 20 #elif defined(CHIP_HAAS1000) #define CODEC_PLL_DIV 38 #define CODEC_CMU_DIV 8 #define CODEC_PLAYBACK_BIT_DEPTH 20 #else #error "Please update audio definitions" #endif #ifndef CODEC_FREQ_CRYSTAL #define CODEC_FREQ_CRYSTAL CODEC_FREQ_26M #endif #ifndef CODEC_FREQ_EXTRA_DIV #define CODEC_FREQ_EXTRA_DIV 1 #endif #define CODEC_TX_PA_GAIN_DEFAULT -1 enum AUD_STREAM_USE_DEVICE_T{ AUD_STREAM_USE_DEVICE_NULL = 0, AUD_STREAM_USE_EXT_CODEC, AUD_STREAM_USE_I2S0_MASTER, AUD_STREAM_USE_I2S0_SLAVE, AUD_STREAM_USE_I2S1_MASTER, AUD_STREAM_USE_I2S1_SLAVE, AUD_STREAM_USE_TDM0_MASTER, AUD_STREAM_USE_TDM0_SLAVE, AUD_STREAM_USE_TDM1_MASTER, AUD_STREAM_USE_TDM1_SLAVE, AUD_STREAM_USE_INT_CODEC, AUD_STREAM_USE_INT_SPDIF, AUD_STREAM_USE_BT_PCM, AUD_STREAM_USE_DPD_RX, AUD_STREAM_USE_MC, }; enum AUD_SAMPRATE_T { AUD_SAMPRATE_NULL = 0, AUD_SAMPRATE_7350 = 7350, AUD_SAMPRATE_8000 = 8000, AUD_SAMPRATE_8463 = 8463, // 26M / 512 / 6 AUD_SAMPRATE_14700 = 14700, AUD_SAMPRATE_16000 = 16000, AUD_SAMPRATE_16927 = 16927, // 26M / 512 / 3 AUD_SAMPRATE_22050 = 22050, AUD_SAMPRATE_24000 = 24000, AUD_SAMPRATE_32000 = 32000, AUD_SAMPRATE_44100 = 44100, AUD_SAMPRATE_48000 = 48000, AUD_SAMPRATE_64000 = 64000, AUD_SAMPRATE_50781 = 50781, // 26M / 512 AUD_SAMPRATE_88200 = 88200, AUD_SAMPRATE_96000 = 96000, AUD_SAMPRATE_128000 = 128000, AUD_SAMPRATE_256000 = 256000, AUD_SAMPRATE_176400 = 176400, AUD_SAMPRATE_192000 = 192000, AUD_SAMPRATE_352800 = 352800, AUD_SAMPRATE_384000 = 384000, AUD_SAMPRATE_512000 = 512000, AUD_SAMPRATE_705600 = 705600, AUD_SAMPRATE_768000 = 768000, AUD_SAMPRATE_1024000 = 1024000, }; enum AUD_CHANNEL_NUM_T { AUD_CHANNEL_NUM_NULL = 0, AUD_CHANNEL_NUM_1 = 1, AUD_CHANNEL_NUM_2 = 2, AUD_CHANNEL_NUM_3 = 3, AUD_CHANNEL_NUM_4 = 4, AUD_CHANNEL_NUM_5 = 5, AUD_CHANNEL_NUM_6 = 6, AUD_CHANNEL_NUM_7 = 7, AUD_CHANNEL_NUM_8 = 8, }; // For preprocess check #define AUD_CHANNEL_MAP_CH0 (1 << 0) #define AUD_CHANNEL_MAP_CH1 (1 << 1) #define AUD_CHANNEL_MAP_CH2 (1 << 2) #define AUD_CHANNEL_MAP_CH3 (1 << 3) #define AUD_CHANNEL_MAP_CH4 (1 << 4) #define AUD_CHANNEL_MAP_CH5 (1 << 5) #define AUD_CHANNEL_MAP_CH6 (1 << 6) #define AUD_CHANNEL_MAP_CH7 (1 << 7) #define AUD_CHANNEL_MAP_DIGMIC_CH0 (1 << 8) #define AUD_CHANNEL_MAP_DIGMIC_CH1 (1 << 9) #define AUD_CHANNEL_MAP_DIGMIC_CH2 (1 << 10) #define AUD_CHANNEL_MAP_DIGMIC_CH3 (1 << 11) #define AUD_CHANNEL_MAP_DIGMIC_CH4 (1 << 12) #define AUD_CHANNEL_MAP_DIGMIC_CH5 (1 << 13) #define AUD_CHANNEL_MAP_DIGMIC_CH6 (1 << 14) #define AUD_CHANNEL_MAP_DIGMIC_CH7 (1 << 15) #define AUD_CHANNEL_MAP_ANA_ALL (0x00FF) #define AUD_CHANNEL_MAP_DIGMIC_ALL (0xFF00) #define AUD_CHANNEL_MAP_ALL (0xFFFF) enum AUD_CHANNEL_MAP_T { AUD_CHANNEL_MAP_END = AUD_CHANNEL_MAP_DIGMIC_CH7, }; enum AUD_VMIC_MAP_T { AUD_VMIC_MAP_VMIC1 = (AUD_CHANNEL_MAP_END << 1), AUD_VMIC_MAP_VMIC2 = (AUD_CHANNEL_MAP_END << 2), AUD_VMIC_MAP_VMIC3 = (AUD_CHANNEL_MAP_END << 3), AUD_VMIC_MAP_VMIC4 = (AUD_CHANNEL_MAP_END << 4), AUD_VMIC_MAP_VMIC5 = (AUD_CHANNEL_MAP_END << 5), }; enum AUD_BITS_T { AUD_BITS_NULL = 0, AUD_BITS_8 = 8, AUD_BITS_12 = 12, AUD_BITS_16 = 16, AUD_BITS_20 = 20, AUD_BITS_24 = 24, AUD_BITS_32 = 32, }; enum AUD_STREAM_ID_T { AUD_STREAM_ID_0 = 0, AUD_STREAM_ID_1, AUD_STREAM_ID_2, AUD_STREAM_ID_NUM, }; enum AUD_STREAM_T { AUD_STREAM_PLAYBACK = 0, AUD_STREAM_CAPTURE, AUD_STREAM_NUM, }; // TODO: Need rename enum AUD_IO_PATH_T { AUD_IO_PATH_NULL = 0, // Input path AUD_INPUT_PATH_MAINMIC, AUD_INPUT_PATH_VADMIC, AUD_INPUT_PATH_ASRMIC, AUD_INPUT_PATH_LINEIN, AUD_INPUT_PATH_NTMIC, AUD_INPUT_PATH_ANC_WNR, AUD_INPUT_PATH_USBAUDIO, // Output path AUD_OUTPUT_PATH_SPEAKER, }; struct AUD_IO_PATH_CFG_T { enum AUD_IO_PATH_T io_path; unsigned int cfg; }; enum ANC_TYPE_T { ANC_NOTYPE = 0, ANC_FEEDFORWARD, ANC_FEEDBACK, #if defined(AUDIO_ANC_TT_HW) ANC_TALKTHRU, #endif #if defined(AUDIO_ANC_FB_MC_HW) ANC_MUSICCANCLE, #endif }; struct CODEC_DAC_VOL_T { signed char tx_pa_gain :6; unsigned char sdm_gain :2; signed char sdac_volume; }; typedef signed char CODEC_ADC_VOL_T; enum TGT_VOLUME_LEVEL_T { TGT_VOLUME_LEVEL_WARNINGTONE = 0, TGT_VOLUME_LEVEL_MUTE, TGT_VOLUME_LEVEL_0, TGT_VOLUME_LEVEL_1, TGT_VOLUME_LEVEL_2, TGT_VOLUME_LEVEL_3, TGT_VOLUME_LEVEL_4, TGT_VOLUME_LEVEL_5, TGT_VOLUME_LEVEL_6, TGT_VOLUME_LEVEL_7, TGT_VOLUME_LEVEL_8, TGT_VOLUME_LEVEL_9, TGT_VOLUME_LEVEL_10, TGT_VOLUME_LEVEL_11, TGT_VOLUME_LEVEL_12, TGT_VOLUME_LEVEL_13, TGT_VOLUME_LEVEL_14, TGT_VOLUME_LEVEL_15, TGT_VOLUME_LEVEL_QTY }; enum TGT_ADC_VOL_LEVEL_T { TGT_ADC_VOL_LEVEL_0, TGT_ADC_VOL_LEVEL_1, TGT_ADC_VOL_LEVEL_2, TGT_ADC_VOL_LEVEL_3, TGT_ADC_VOL_LEVEL_4, TGT_ADC_VOL_LEVEL_5, TGT_ADC_VOL_LEVEL_6, TGT_ADC_VOL_LEVEL_7, TGT_ADC_VOL_LEVEL_8, TGT_ADC_VOL_LEVEL_9, TGT_ADC_VOL_LEVEL_10, TGT_ADC_VOL_LEVEL_11, TGT_ADC_VOL_LEVEL_12, TGT_ADC_VOL_LEVEL_13, TGT_ADC_VOL_LEVEL_14, TGT_ADC_VOL_LEVEL_15, TGT_ADC_VOL_LEVEL_QTY }; typedef void (*AUD_VAD_CALLBACK)(int found); enum AUD_VAD_TYPE_T { AUD_VAD_TYPE_NONE = 0, AUD_VAD_TYPE_MIX, AUD_VAD_TYPE_DIG, AUD_VAD_TYPE_ANA, AUD_VAD_TYPE_NUM, }; struct AUD_VAD_CONFIG_T { enum AUD_VAD_TYPE_T type; enum AUD_SAMPRATE_T sample_rate; AUD_VAD_CALLBACK handler; uint8_t udc; uint8_t upre; uint8_t frame_len; uint8_t mvad; uint8_t dig_mode; uint8_t pre_gain; uint8_t sth; uint8_t dc_bypass; uint8_t ds_bypass; uint8_t pre_bypass; uint8_t adc_gain; uint16_t range[4]; uint32_t frame_th[3]; uint32_t psd_th[2]; }; #ifdef __cplusplus } #endif #endif /* AUDIO_DEF_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_aud.h
C
apache-2.0
8,613
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_BOOTMODE_H__ #define __HAL_BOOTMODE_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #define HAL_HW_BOOTMODE_MASK (0xF << 0) #define HAL_SW_BOOTMODE_MASK (0x0FFFFFFF << 4) // SW_BOOTMODE_START (1 << 4) #define HAL_SW_BOOTMODE_READ_ENABLED (1 << 4) #define HAL_SW_BOOTMODE_WRITE_ENABLED (1 << 5) #define HAL_SW_BOOTMODE_JTAG_ENABLED (1 << 6) #define HAL_SW_BOOTMODE_FORCE_USB_DLD (1 << 7) #define HAL_SW_BOOTMODE_FORCE_UART_DLD (1 << 8) #define HAL_SW_BOOTMODE_DLD_TRANS_UART (1 << 9) #define HAL_SW_BOOTMODE_SKIP_FLASH_BOOT (1 << 10) #define HAL_SW_BOOTMODE_CHIP_TEST (1 << 11) #define HAL_SW_BOOTMODE_FACTORY (1 << 12) #define HAL_SW_BOOTMODE_CALIB (1 << 13) #define HAL_SW_BOOTMODE_ROM_RESERVED_14 (1 << 14) #define HAL_SW_BOOTMODE_FLASH_BOOT (1 << 15) #define HAL_SW_BOOTMODE_REBOOT (1 << 16) #define HAL_SW_BOOTMODE_ROM_RESERVED_17 (1 << 17) #define HAL_SW_BOOTMODE_FORCE_USB_PLUG_IN (1 << 18) #define HAL_SW_BOOTMODE_POWER_DOWN_WAKEUP (1 << 19) // APP_BOOTMODE_START (1 << 20) // Add new application bootmodes here (from highest bit to lowest bit) #define HAL_SW_BOOTMODE_TEST_MASK (0x1F << 20) #define HAL_SW_BOOTMODE_TEST_MODE (1 << 20) #define HAL_SW_BOOTMODE_TEST_SIGNALINGMODE (1 << 21) #define HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE (1 << 22) #define HAL_SW_BOOTMODE_TEST_SIGNALINGMODE_WIFI (1 << 23) #define HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE_WIFI (1 << 24) #define HAL_SW_BOOTMODE_ENTER_HIDE_BOOT (1 << 25) #define HAL_SW_BOOTMODE_RESERVED_BIT24 (1 << 26) #define HAL_SW_BOOTMODE_REBOOT_FROM_CRASH (1 << 27) #ifdef __USB_COMM__ #define HAL_SW_BOOTMODE_CDC_COMM (1 << 28) #endif #ifdef ANC_APP #define HAL_SW_BOOTMODE_REBOOT_BT_ON (1 << 29) #define HAL_SW_BOOTMODE_REBOOT_ANC_ON (1 << 30) #endif #define HAL_SW_BOOTMODE_WARM_BOOT (1 << 29) #ifdef USER_REBOOT_PLAY_MUSIC_AUTO #define HAL_SW_BOOTMODE_LOCAL_PLAYER (1 << 31) #endif // APP_BOOTMODE_END (1 << 31) // SW_BOOTMODE_END (1 << 31) union HAL_HW_BOOTMODE_T { struct { uint8_t watchdog : 1; uint8_t global : 1; uint8_t rtc : 1; uint8_t charger : 1; }; uint8_t reg; }; union HAL_HW_BOOTMODE_T hal_rom_hw_bootmode_get(void); union HAL_HW_BOOTMODE_T hal_hw_bootmode_get(void); void hal_hw_bootmode_init(void); void hal_hw_bootmode_clear(uint8_t clear_bits); uint32_t hal_sw_bootmode_get(void); void hal_sw_bootmode_set(uint32_t bm); void hal_sw_bootmode_clear(uint32_t bm); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_bootmode.h
C
apache-2.0
3,580
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 CACHE_HAL_H #define CACHE_HAL_H #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" enum HAL_CACHE_ID_T { HAL_CACHE_ID_I_CACHE = 0, HAL_CACHE_ID_D_CACHE, HAL_CACHE_ID_NUM, }; uint8_t hal_cache_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_writebuffer_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_writebuffer_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_writebuffer_flush(enum HAL_CACHE_ID_T id); uint8_t hal_cache_writeback_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_writeback_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_wrap_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_wrap_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cache_invalidate(enum HAL_CACHE_ID_T id, uint32_t start_address, uint32_t len); uint8_t hal_cache_sync(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_writebuffer_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_writebuffer_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_writebuffer_flush(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_writeback_enable(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_writeback_disable(enum HAL_CACHE_ID_T id); uint8_t hal_cachecp_invalidate(enum HAL_CACHE_ID_T id, uint32_t start_address, uint32_t len); uint8_t hal_cachecp_sync(enum HAL_CACHE_ID_T id); #ifdef __cplusplus } #endif #endif /* CACHE_HAL_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_cache.h
C
apache-2.0
2,142
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_CHIPID_H__ #define __HAL_CHIPID_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" // BEST1000: A=0 C=1 D=2 F=3 G=4 I=5 // BEST1400: A=0 B=1 C=2(cmuRev=2&diffRom) D=3 E=4(cmuRev=3&diffRom) F=5(cmuRev=4) // BEST1402: A=0 B=1 // BEST2000: A=0 C=1 D=2 E=3(rev=2&aonRev=4) F=4 G=5 // BEST2300: A=0 B=1(rfRev=15) C=3 D=4 E=5(rfRev=4&diffRom) enum HAL_CHIP_METAL_ID_T { HAL_CHIP_METAL_ID_0, HAL_CHIP_METAL_ID_1, HAL_CHIP_METAL_ID_2, HAL_CHIP_METAL_ID_3, HAL_CHIP_METAL_ID_4, HAL_CHIP_METAL_ID_5, HAL_CHIP_METAL_ID_6, HAL_CHIP_METAL_ID_7, HAL_CHIP_METAL_ID_8, HAL_CHIP_METAL_ID_9, HAL_CHIP_METAL_ID_10, HAL_CHIP_METAL_ID_11, HAL_CHIP_METAL_ID_12, HAL_CHIP_METAL_ID_13, HAL_CHIP_METAL_ID_14, HAL_CHIP_METAL_ID_15, }; enum HAL_BT_CHIP_SERIES_T { HAL_BT_CHIP_SERIES_2000, HAL_BT_CHIP_SERIES_2300, HAL_BT_CHIP_SERIES_2500, }; // Invoked by hal_chipid_init() only uint32_t read_hw_metal_id(void); void hal_chipid_init(void); enum HAL_CHIP_METAL_ID_T hal_get_chip_metal_id(void); enum HAL_BT_CHIP_SERIES_T hal_get_bt_chip_series(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_chipid.h
C
apache-2.0
1,825
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_CMD_H__ #define __HAL_CMD_H__ #include "stdint.h" // typedef enum { // HAL_CMD_ERR_NONE = 0x00, // HAL_CMD_ERR_LEN = 0x01, // HAL_CMD_ERR_CHECKSUM = 0x02, // HAL_CMD_ERR_NOT_SYNC = 0x03, // HAL_CMD_ERR_CMD = 0x06, // HAL_CMD_ERR_BURN_OK = 0x60, // HAL_CMD_ERR_SECTOR_SIZE = 0x61, // HAL_CMD_ERR_BURN_INFO_MISSING = 0x63, // HAL_CMD_ERR_SECTOR_DATA_LEN = 0x64, // HAL_CMD_ERR_SECTOR_DATA_CRC = 0x65, // HAL_CMD_ERR_SECTOR_SEQ = 0x66, // HAL_CMD_ERR_ERASE_FLSH = 0x67, // HAL_CMD_ERR_BURN_FLSH = 0x68, // } HAL_CMD_ERR_T; // typedef enum { // HAL_CMD_GET_PARA = 0x00, // HAL_CMD_SET_PARA, // HAL_CMD_SAVE_PARA, // HAL_CMD_PUSH_PARA, // HAL_CMD_PLAYBACK_SWITCH = 0x08, // HAL_CMD_CAPTURE_SWITCH, // HAL_CMD_BURN_HANDSHAKE = 0x10, // HAL_CMD_BURN_START, // HAL_CMD_BURN_DATA, // HAL_CMD_HANDSHAKE = 0x18, // HAL_CMD_SHUTDOWN, // HAL_CMD_REBOOT, // HAL_CMD_NOTIFICATION, // HAL_CMD_INVALID = 0xff // } EL_CMD_E; // typedef enum { // HAL_CMD_PARA_SOUND_VOLUME, // HAL_CMD_PARA_LC_SWITCH, // HAL_CMD_PARA_EQ_GAIN, // HAL_CMD_PARA_ANC_SWITCH, // HAL_CMD_PARA_ANC_GAIN, // HAL_CMD_PARA_INVALID // } EL_PARA_E; typedef enum { HAL_CMD_RX_START, HAL_CMD_RX_STOP, HAL_CMD_RX_DONE } hal_cmd_rx_status_t; typedef int (*hal_cmd_callback_t)(uint8_t *buf, uint32_t len); typedef void (*CMD_CALLBACK_HANDLER_T)(hal_cmd_rx_status_t status); #ifdef __cplusplus extern "C" { #endif int hal_cmd_init (void); int hal_cmd_open (void); int hal_cmd_close (void); #ifdef USB_AUDIO_APP void hal_cmd_run (hal_cmd_rx_status_t status); #else int hal_cmd_run (hal_cmd_rx_status_t status); #endif void hal_cmd_set_callback(CMD_CALLBACK_HANDLER_T handler); int hal_cmd_register(char *name, hal_cmd_callback_t callback); #ifdef USB_EQ_TUNING int hal_cmd_list_process(uint8_t *buf); void hal_cmd_tx_process (uint8_t** ppbuf, uint16_t* plen); #endif #ifdef __cplusplus } #endif // hal_cmd_t *hal_cmd_get_ptr(void); #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_cmd.h
C
apache-2.0
2,845
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_CMU_H__ #define __HAL_CMU_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "plat_addr_map.h" #include CHIP_SPECIFIC_HDR(hal_cmu) #ifndef HAL_CMU_DEFAULT_CRYSTAL_FREQ #define HAL_CMU_DEFAULT_CRYSTAL_FREQ 26000000 #endif #define LPU_TIMER_US(us) (((us) * 32 + 1000 - 1) / 1000) enum HAL_CMU_CLK_STATUS_T { HAL_CMU_CLK_DISABLED, HAL_CMU_CLK_ENABLED, }; enum HAL_CMU_CLK_MODE_T { HAL_CMU_CLK_AUTO, HAL_CMU_CLK_MANUAL, }; enum HAL_CMU_RST_STATUS_T { HAL_CMU_RST_SET, HAL_CMU_RST_CLR, }; enum HAL_CMU_TIMER_ID_T { HAL_CMU_TIMER_ID_00, HAL_CMU_TIMER_ID_01, HAL_CMU_TIMER_ID_10, HAL_CMU_TIMER_ID_11, HAL_CMU_TIMER_ID_20, HAL_CMU_TIMER_ID_21, }; #ifndef HAL_CMU_FREQ_T enum HAL_CMU_FREQ_T { HAL_CMU_FREQ_32K, HAL_CMU_FREQ_26M, HAL_CMU_FREQ_52M, HAL_CMU_FREQ_78M, HAL_CMU_FREQ_104M, HAL_CMU_FREQ_208M, HAL_CMU_FREQ_QTY }; #endif #ifndef HAL_CMU_PLL_T enum HAL_CMU_PLL_T { HAL_CMU_PLL_AUD, HAL_CMU_PLL_USB, HAL_CMU_PLL_QTY }; #endif #ifndef HAL_CMU_PLL_USER_T enum HAL_CMU_PLL_USER_T { HAL_CMU_PLL_USER_SYS, HAL_CMU_PLL_USER_AUD, HAL_CMU_PLL_USER_USB, HAL_CMU_PLL_USER_QTY, HAL_CMU_PLL_USER_ALL = HAL_CMU_PLL_USER_QTY, }; #endif enum HAL_CMU_PERIPH_FREQ_T { HAL_CMU_PERIPH_FREQ_26M, HAL_CMU_PERIPH_FREQ_52M, HAL_CMU_PERIPH_FREQ_QTY }; enum HAL_CMU_LPU_CLK_CFG_T { HAL_CMU_LPU_CLK_NONE, HAL_CMU_LPU_CLK_26M, HAL_CMU_LPU_CLK_PLL, HAL_CMU_LPU_CLK_QTY }; enum HAL_CMU_LPU_SLEEP_MODE_T { HAL_CMU_LPU_SLEEP_MODE_SYS, HAL_CMU_LPU_SLEEP_MODE_CHIP, HAL_CMU_LPU_SLEEP_MODE_QTY }; #ifndef HAL_PWM_ID_T enum HAL_PWM_ID_T { HAL_PWM_ID_0, HAL_PWM_ID_1, HAL_PWM_ID_2, HAL_PWM_ID_3, HAL_PWM_ID_QTY }; #endif #ifndef HAL_I2S_ID_T enum HAL_I2S_ID_T { HAL_I2S_ID_0 = 0, HAL_I2S_ID_QTY, }; #endif #ifndef HAL_SPDIF_ID_T enum HAL_SPDIF_ID_T { HAL_SPDIF_ID_0 = 0, HAL_SPDIF_ID_QTY, }; #endif enum HAL_CMU_USB_CLOCK_SEL_T { HAL_CMU_USB_CLOCK_SEL_PLL, HAL_CMU_USB_CLOCK_SEL_24M_X2, HAL_CMU_USB_CLOCK_SEL_48M, HAL_CMU_USB_CLOCK_SEL_26M_X2, HAL_CMU_USB_CLOCK_SEL_26M_X4, }; void hal_cmu_set_crystal_freq_index(uint32_t index); uint32_t hal_cmu_get_crystal_freq(void); uint32_t hal_cmu_get_default_crystal_freq(void); int hal_cmu_clock_enable(enum HAL_CMU_MOD_ID_T id); int hal_cmu_clock_disable(enum HAL_CMU_MOD_ID_T id); enum HAL_CMU_CLK_STATUS_T hal_cmu_clock_get_status(enum HAL_CMU_MOD_ID_T id); int hal_cmu_clock_set_mode(enum HAL_CMU_MOD_ID_T id, enum HAL_CMU_CLK_MODE_T mode); enum HAL_CMU_CLK_MODE_T hal_cmu_clock_get_mode(enum HAL_CMU_MOD_ID_T id); int hal_cmu_reset_set(enum HAL_CMU_MOD_ID_T id); int hal_cmu_reset_clear(enum HAL_CMU_MOD_ID_T id); enum HAL_CMU_RST_STATUS_T hal_cmu_reset_get_status(enum HAL_CMU_MOD_ID_T id); int hal_cmu_reset_pulse(enum HAL_CMU_MOD_ID_T id); int hal_cmu_timer_set_div(enum HAL_CMU_TIMER_ID_T id, uint32_t div); void hal_cmu_timer0_select_fast(void); void hal_cmu_timer0_select_slow(void); void hal_cmu_timer1_select_fast(void); void hal_cmu_timer1_select_slow(void); void hal_cmu_timer2_select_fast(void); void hal_cmu_timer2_select_slow(void); void hal_cmu_dsp_timer0_select_fast(void); void hal_cmu_dsp_timer0_select_slow(void); void hal_cmu_dsp_timer1_select_fast(void); void hal_cmu_dsp_timer1_select_slow(void); int hal_cmu_periph_set_div(uint32_t div); int hal_cmu_uart0_set_div(uint32_t div); int hal_cmu_uart1_set_div(uint32_t div); int hal_cmu_uart2_set_div(uint32_t div); int hal_cmu_spi_set_div(uint32_t div); int hal_cmu_slcd_set_div(uint32_t div); int hal_cmu_sdio_set_div(uint32_t div); int hal_cmu_sdmmc_set_div(uint32_t div); int hal_cmu_i2c_set_div(uint32_t div); int hal_cmu_uart0_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_uart1_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_uart2_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_spi_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_slcd_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_sdio_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_sdmmc_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_i2c_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_ispi_set_freq(enum HAL_CMU_PERIPH_FREQ_T freq); int hal_cmu_pwm_set_freq(enum HAL_PWM_ID_T id, uint32_t freq); int hal_cmu_flash_set_freq(enum HAL_CMU_FREQ_T freq); int hal_cmu_mem_set_freq(enum HAL_CMU_FREQ_T freq); int hal_cmu_sys_set_freq(enum HAL_CMU_FREQ_T freq); enum HAL_CMU_FREQ_T hal_cmu_sys_get_freq(void); enum HAL_CMU_FREQ_T hal_cmu_flash_get_freq(void); int hal_cmu_flash_select_pll(enum HAL_CMU_PLL_T pll); int hal_cmu_mem_select_pll(enum HAL_CMU_PLL_T pll); int hal_cmu_sys_select_pll(enum HAL_CMU_PLL_T pll); int hal_cmu_get_pll_status(enum HAL_CMU_PLL_T pll); int hal_cmu_pll_enable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_PLL_USER_T user); int hal_cmu_pll_disable(enum HAL_CMU_PLL_T pll, enum HAL_CMU_PLL_USER_T user); void hal_cmu_audio_resample_enable(void); void hal_cmu_audio_resample_disable(void); int hal_cmu_get_audio_resample_status(void); int hal_cmu_codec_adc_set_div(uint32_t div); uint32_t hal_cmu_codec_adc_get_div(void); int hal_cmu_codec_dac_set_div(uint32_t div); uint32_t hal_cmu_codec_dac_get_div(void); void hal_cmu_codec_clock_enable(void); void hal_cmu_codec_clock_disable(void); void hal_cmu_codec_reset_set(void); void hal_cmu_codec_reset_clear(void); void hal_cmu_codec_iir_enable(uint32_t speed); void hal_cmu_codec_iir_disable(void); int hal_cmu_codec_iir_set_div(uint32_t div); void hal_cmu_codec_fir_enable(uint32_t speed); void hal_cmu_codec_fir_disable(void); int hal_cmu_codec_fir_set_div(uint32_t div); void hal_cmu_codec_rs_enable(uint32_t speed); void hal_cmu_codec_rs_disable(void); int hal_cmu_codec_rs_set_div(uint32_t div); void hal_cmu_codec_set_fault_mask(uint32_t msk); void hal_cmu_i2s_clock_out_enable(enum HAL_I2S_ID_T id); void hal_cmu_i2s_clock_out_disable(enum HAL_I2S_ID_T id); void hal_cmu_i2s_set_slave_mode(enum HAL_I2S_ID_T id); void hal_cmu_i2s_set_master_mode(enum HAL_I2S_ID_T id); void hal_cmu_i2s_clock_enable(enum HAL_I2S_ID_T id); void hal_cmu_i2s_clock_disable(enum HAL_I2S_ID_T id); int hal_cmu_i2s_set_div(enum HAL_I2S_ID_T id, uint32_t div); int hal_cmu_i2s_mclk_enable(enum HAL_CMU_I2S_MCLK_ID_T id); void hal_cmu_i2s_mclk_disable(void); void hal_cmu_pcm_clock_out_enable(void); void hal_cmu_pcm_clock_out_disable(void); void hal_cmu_pcm_set_slave_mode(int clk_pol); void hal_cmu_pcm_set_master_mode(void); void hal_cmu_pcm_clock_enable(void); void hal_cmu_pcm_clock_disable(void); int hal_cmu_pcm_set_div(uint32_t div); int hal_cmu_spdif_clock_enable(enum HAL_SPDIF_ID_T id); int hal_cmu_spdif_clock_disable(enum HAL_SPDIF_ID_T id); int hal_cmu_spdif_set_div(enum HAL_SPDIF_ID_T id, uint32_t div); void hal_cmu_usb_set_device_mode(void); void hal_cmu_usb_set_host_mode(void); void hal_cmu_rom_select_usb_clock(enum HAL_CMU_USB_CLOCK_SEL_T sel); void hal_cmu_usb_clock_enable(void); void hal_cmu_usb_clock_disable(void); void hal_cmu_bt_clock_enable(void); void hal_cmu_bt_clock_disable(void); void hal_cmu_bt_reset_set(void); void hal_cmu_bt_reset_clear(void); void hal_cmu_bt_module_reset_clear(void); void hal_cmu_bt_module_init(void); int hal_cmu_clock_out_enable(enum HAL_CMU_CLOCK_OUT_ID_T id); void hal_cmu_clock_out_disable(void); void hal_cmu_write_lock(void); void hal_cmu_write_unlock(void); void hal_cmu_sys_reboot(void); void hal_cmu_jtag_enable(void); void hal_cmu_jtag_disable(void); void hal_cmu_jtag_clock_enable(void); void hal_cmu_jtag_clock_disable(void); void hal_cmu_simu_init(void); void hal_cmu_simu_pass(void); void hal_cmu_simu_fail(void); void hal_cmu_misc_init(void); void hal_cmu_misc_pass(void); void hal_cmu_misc_fail(void); void hal_cmu_simu_tag(uint8_t shift); void hal_cmu_simu_clr_tag(uint8_t shift); void hal_cmu_simu_set_val(uint32_t val); uint32_t hal_cmu_simu_get_val(void); void hal_cmu_low_freq_mode_init(void); void hal_cmu_low_freq_mode_enable(enum HAL_CMU_FREQ_T old_freq, enum HAL_CMU_FREQ_T new_freq); void hal_cmu_low_freq_mode_disable(enum HAL_CMU_FREQ_T old_freq, enum HAL_CMU_FREQ_T new_freq); void hal_cmu_rom_enable_pll(void); void hal_cmu_programmer_enable_pll(void); void hal_cmu_init_pll_selection(void); void hal_cmu_rom_setup(void); void hal_cmu_fpga_setup(void); void hal_cmu_setup(void); // Some internal functions void hal_cmu_apb_init_div(void); void hal_cmu_rom_clock_init(void); void hal_cmu_init_chip_feature(uint16_t feature); void hal_cmu_osc_x2_enable(void); void hal_cmu_osc_x4_enable(void); void hal_cmu_module_init_state(void); void hal_cmu_ema_init(void); void hal_cmu_lpu_wait_26m_ready(void); int hal_cmu_lpu_busy(void); int hal_cmu_lpu_init(enum HAL_CMU_LPU_CLK_CFG_T cfg); int hal_cmu_lpu_sleep(enum HAL_CMU_LPU_SLEEP_MODE_T mode); void hal_cmu_set_wakeup_pc(uint32_t pc); volatile uint32_t *hal_cmu_get_bootmode_addr(void); volatile uint32_t *hal_cmu_get_memsc_addr(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_cmu.h
C
apache-2.0
9,841
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_DMA_H__ #define __HAL_DMA_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" #define HAL_DMA_CHAN_NONE 0xFF #define HAL_DMA_MAX_DESC_XFER_SIZE 0xFFF enum HAL_DMA_RET_T { HAL_DMA_OK, HAL_DMA_ERR, }; enum HAL_DMA_GET_CHAN_T { HAL_DMA_HIGH_PRIO, HAL_DMA_LOW_PRIO, HAL_DMA_LOW_PRIO_ONLY }; // DMA Type of DMA controller enum HAL_DMA_FLOW_CONTROL_T { HAL_DMA_FLOW_M2M_DMA = 0, /* Memory to memory - DMA control */ HAL_DMA_FLOW_M2P_DMA = 1, /* Memory to peripheral - DMA control */ HAL_DMA_FLOW_P2M_DMA = 2, /* Peripheral to memory - DMA control */ HAL_DMA_FLOW_P2P_DMA = 3, /* Source peripheral to destination peripheral - DMA control */ HAL_DMA_FLOW_P2P_DSTPERIPH = 4, /* Source peripheral to destination peripheral - destination peripheral control */ HAL_DMA_FLOW_M2P_PERIPH = 5, /* Memory to peripheral - peripheral control */ HAL_DMA_FLOW_P2M_PERIPH = 6, /* Peripheral to memory - peripheral control */ HAL_DMA_FLOW_P2P_SRCPERIPH = 7, /* Source peripheral to destination peripheral - source peripheral control */ HAL_DMA_FLOW_FLAG_SI = 0x40, HAL_DMA_FLOW_FLAG_DI = 0x80, HAL_DMA_FLOW_FLAG_MASK = (HAL_DMA_FLOW_FLAG_SI | HAL_DMA_FLOW_FLAG_DI), HAL_DMA_FLOW_M2P_DI_DMA = HAL_DMA_FLOW_M2P_DMA | HAL_DMA_FLOW_FLAG_DI, HAL_DMA_FLOW_P2M_SI_DMA = HAL_DMA_FLOW_P2M_DMA | HAL_DMA_FLOW_FLAG_SI, HAL_DMA_FLOW_P2P_DI_DMA = HAL_DMA_FLOW_P2P_DMA | HAL_DMA_FLOW_FLAG_DI, HAL_DMA_FLOW_P2P_SI_DMA = HAL_DMA_FLOW_P2P_DMA | HAL_DMA_FLOW_FLAG_SI, }; // DMA Burst size in Source and Destination definitions enum HAL_DMA_BSIZE_T { HAL_DMA_BSIZE_1 = 0, /* Burst size = 1 */ HAL_DMA_BSIZE_4 = 1, /* Burst size = 4 */ HAL_DMA_BSIZE_8 = 2, /* Burst size = 8 */ HAL_DMA_BSIZE_16 = 3, /* Burst size = 16 */ HAL_DMA_BSIZE_32 = 4, /* Burst size = 32 */ HAL_DMA_BSIZE_64 = 5, /* Burst size = 64 */ HAL_DMA_BSIZE_128 = 6, /* Burst size = 128 */ HAL_DMA_BSIZE_256 = 7, /* Burst size = 256 */ }; // Width in Source transfer width and Destination transfer width definitions enum HAL_DMA_WDITH_T { HAL_DMA_WIDTH_BYTE = 0, /* Width = 1 byte */ HAL_DMA_WIDTH_HALFWORD = 1, /* Width = 2 bytes */ HAL_DMA_WIDTH_WORD = 2, /* Width = 4 bytes */ }; enum HAL_DMA_PERIPH_T { HAL_DMA_PERIPH_NULL = 0, HAL_GPDMA_MEM = 1, HAL_AUDMA_MEM = 2, HAL_GPDMA_SDIO = 10, HAL_GPDMA_SDMMC = 11, HAL_GPDMA_I2C0_RX = 12, HAL_GPDMA_I2C0_TX = 13, HAL_GPDMA_SPI_RX = 14, HAL_GPDMA_SPI_TX = 15, HAL_GPDMA_SPILCD_RX = 16, HAL_GPDMA_SPILCD_TX = 17, HAL_GPDMA_UART0_RX = 18, HAL_GPDMA_UART0_TX = 19, HAL_GPDMA_UART1_RX = 20, HAL_GPDMA_UART1_TX = 21, HAL_GPDMA_ISPI_RX = 22, HAL_GPDMA_ISPI_TX = 23, HAL_GPDMA_UART2_RX = 24, HAL_GPDMA_UART2_TX = 25, HAL_GPDMA_FLASH_RX = 26, HAL_GPDMA_FLASH_TX = 27, HAL_GPDMA_I2C1_RX = 28, HAL_GPDMA_I2C1_TX = 29, HAL_AUDMA_CODEC_RX = 50, HAL_AUDMA_CODEC_TX = 51, HAL_AUDMA_BTPCM_RX = 52, HAL_AUDMA_BTPCM_TX = 53, HAL_AUDMA_I2S0_RX = 54, HAL_AUDMA_I2S0_TX = 55, HAL_AUDMA_DPD_RX = 56, HAL_AUDMA_DPD_TX = 57, HAL_AUDMA_SPDIF0_RX = 58, HAL_AUDMA_SPDIF0_TX = 59, HAL_AUDMA_SPDIF1_RX = 60, HAL_AUDMA_SPDIF1_TX = 61, HAL_AUDMA_DSD_RX = 62, HAL_AUDMA_DSD_TX = 63, HAL_AUDMA_MC_RX = 64, HAL_AUDMA_FFT_RX = 65, HAL_AUDMA_FFT_TX = 66, HAL_AUDMA_FIR_RX = 67, HAL_AUDMA_FIR_TX = 68, HAL_AUDMA_IIR_RX = 69, HAL_AUDMA_IIR_TX = 70, HAL_AUDMA_BTDUMP = 71, HAL_AUDMA_I2S1_RX = 72, HAL_AUDMA_I2S1_TX = 73, HAL_AUDMA_FM_RX = 74, HAL_AUDMA_FMDUMP0 = 75, HAL_AUDMA_FMDUMP1 = 76, HAL_AUDMA_CODEC_TX2 = 77, HAL_DMA_PERIPH_QTY, }; struct HAL_DMA_DESC_T; typedef void (*HAL_DMA_IRQ_HANDLER_T)(uint8_t chan, uint32_t remain_tsize, uint32_t error, struct HAL_DMA_DESC_T *lli); typedef void (*HAL_DMA_START_CALLBACK_T)(uint8_t chan); typedef void (*HAL_DMA_DELAY_FUNC)(uint32_t ms); // DMA structure using for DMA configuration struct HAL_DMA_CH_CFG_T { uint8_t ch; /* DMA channel number */ uint8_t try_burst; uint16_t src_tsize; /* Length/Size of transfer */ enum HAL_DMA_WDITH_T src_width; enum HAL_DMA_WDITH_T dst_width; enum HAL_DMA_BSIZE_T src_bsize; enum HAL_DMA_BSIZE_T dst_bsize; enum HAL_DMA_FLOW_CONTROL_T type; /* Transfer Type */ enum HAL_DMA_PERIPH_T src_periph; enum HAL_DMA_PERIPH_T dst_periph; uint32_t src; /* Physical Source Address */ uint32_t dst; /* Physical Destination Address */ HAL_DMA_IRQ_HANDLER_T handler; HAL_DMA_START_CALLBACK_T start_cb; }; // Transfer Descriptor structure typedef struct HAL_DMA_DESC_T { uint32_t src; /* Source address */ uint32_t dst; /* Destination address */ uint32_t lli; /* Pointer to next descriptor structure */ uint32_t ctrl; /* Control word that has transfer size, type etc. */ }; // DMA 2D configuration structure struct HAL_DMA_2D_CFG_T { int16_t xmodify; uint16_t xcount; int16_t ymodify; uint16_t ycount; }; //============================================================= #if (CHIP_HAS_DMA != 0) void hal_dma_open(void); void hal_dma_close(void); bool hal_dma_chan_busy(uint8_t ch); uint8_t hal_dma_get_chan(enum HAL_DMA_PERIPH_T periph, enum HAL_DMA_GET_CHAN_T policy); void hal_dma_free_chan(uint8_t ch); uint32_t hal_dma_cancel(uint8_t ch); uint32_t hal_dma_stop(uint8_t ch); enum HAL_DMA_RET_T hal_dma_init_desc(struct HAL_DMA_DESC_T *desc, const struct HAL_DMA_CH_CFG_T *cfg, const struct HAL_DMA_DESC_T *next, int tc_irq); enum HAL_DMA_RET_T hal_dma_sg_start(const struct HAL_DMA_DESC_T *desc, const struct HAL_DMA_CH_CFG_T *cfg); enum HAL_DMA_RET_T hal_dma_sg_2d_start(const struct HAL_DMA_DESC_T *desc, const struct HAL_DMA_CH_CFG_T *cfg, const struct HAL_DMA_2D_CFG_T *src_2d, const struct HAL_DMA_2D_CFG_T *dst_2d); enum HAL_DMA_RET_T hal_dma_start(const struct HAL_DMA_CH_CFG_T *cfg); uint32_t hal_dma_get_cur_src_addr(uint8_t ch); uint32_t hal_dma_get_cur_dst_addr(uint8_t ch); uint32_t hal_dma_get_sg_remain_size(uint8_t ch); enum HAL_DMA_RET_T hal_dma_irq_run_chan(uint8_t ch); bool hal_dma_busy(void); HAL_DMA_DELAY_FUNC hal_dma_set_delay_func(HAL_DMA_DELAY_FUNC new_func); void hal_dma_remap_periph(enum HAL_DMA_PERIPH_T periph, int enable); void hal_dma_tc_irq_enable(uint8_t ch); void hal_dma_tc_irq_disable(uint8_t ch); #else /*CHIP_HAS_DMA != 0*/ static inline void hal_dma_open(void) {} static inline void hal_dma_close(void) {} static inline bool hal_dma_chan_busy(uint8_t ch) {return true;} static inline uint8_t hal_dma_get_chan(enum HAL_DMA_PERIPH_T periph, enum HAL_DMA_GET_CHAN_T policy) {return HAL_DMA_CHAN_NONE;} static inline void hal_dma_free_chan(uint8_t ch) {} static inline uint32_t hal_dma_cancel(uint8_t ch) {return 0;} static inline uint32_t hal_dma_stop(uint8_t ch) {return 0;} static inline enum HAL_DMA_RET_T hal_dma_init_desc(struct HAL_DMA_DESC_T *desc, const struct HAL_DMA_CH_CFG_T *cfg, const struct HAL_DMA_DESC_T *next, int tc_irq) {return HAL_DMA_ERR;} static inline enum HAL_DMA_RET_T hal_dma_sg_start(const struct HAL_DMA_DESC_T *desc, const struct HAL_DMA_CH_CFG_T *cfg) {return HAL_DMA_ERR;} static inline enum HAL_DMA_RET_T hal_dma_sg_2d_start(const struct HAL_DMA_DESC_T *desc, const struct HAL_DMA_CH_CFG_T *cfg, const struct HAL_DMA_2D_CFG_T *src_2d, const struct HAL_DMA_2D_CFG_T *dst_2d) {return HAL_DMA_ERR;} static inline enum HAL_DMA_RET_T hal_dma_start(const struct HAL_DMA_CH_CFG_T *cfg) {return HAL_DMA_ERR;} static inline uint32_t hal_dma_get_cur_src_addr(uint8_t ch) {return 0;} static inline uint32_t hal_dma_get_cur_dst_addr(uint8_t ch) {return 0;} static inline uint32_t hal_dma_get_sg_remain_size(uint8_t ch) {return 0;} static inline enum HAL_DMA_RET_T hal_dma_irq_run_chan(uint8_t ch) {return HAL_DMA_ERR;} static inline bool hal_dma_busy(void) {return true;} static inline HAL_DMA_DELAY_FUNC hal_dma_set_delay_func(HAL_DMA_DELAY_FUNC new_func) {return (HAL_DMA_DELAY_FUNC)0;} static inline void hal_dma_remap_periph(enum HAL_DMA_PERIPH_T periph, int enable) {} static inline void hal_dma_tc_irq_enable(uint8_t ch) {} static inline void hal_dma_tc_irq_disable(uint8_t ch) {} #endif /*CHIP_HAS_DMA != 0*/ //============================================================= #define hal_audma_open hal_dma_open #define hal_audma_close hal_dma_close #define hal_audma_chan_busy hal_dma_chan_busy #define hal_audma_get_chan hal_dma_get_chan #define hal_audma_free_chan hal_dma_free_chan #define hal_audma_cancel hal_dma_cancel #define hal_audma_stop hal_dma_stop #define hal_audma_init_desc hal_dma_init_desc #define hal_audma_sg_start hal_dma_sg_start #define hal_audma_start hal_dma_start #define hal_audma_get_cur_src_addr hal_dma_get_cur_src_addr #define hal_audma_get_cur_dst_addr hal_dma_get_cur_dst_addr #define hal_audma_get_sg_remain_size hal_dma_get_sg_remain_size #define hal_audma_irq_run_chan hal_dma_irq_run_chan #define hal_gpdma_open hal_dma_open #define hal_gpdma_close hal_dma_close #define hal_gpdma_chan_busy hal_dma_chan_busy #define hal_gpdma_get_chan hal_dma_get_chan #define hal_gpdma_free_chan hal_dma_free_chan #define hal_gpdma_cancel hal_dma_cancel #define hal_gpdma_stop hal_dma_stop #define hal_gpdma_init_desc hal_dma_init_desc #define hal_gpdma_sg_start hal_dma_sg_start #define hal_gpdma_start hal_dma_start #define hal_gpdma_get_cur_src_addr hal_dma_get_cur_src_addr #define hal_gpdma_get_cur_dst_addr hal_dma_get_cur_dst_addr #define hal_gpdma_get_sg_remain_size hal_dma_get_sg_remain_size #define hal_gpdma_irq_run_chan hal_dma_irq_run_chan //============================================================= #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_dma.h
C
apache-2.0
12,202
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_GPADC_H__ #define __HAL_GPADC_H__ #ifdef __cplusplus extern "C" { #endif #define HAL_GPADC_BAD_VALUE 0xFFFF enum HAL_GPADC_CHAN_T { HAL_GPADC_CHAN_0 = 0, HAL_GPADC_CHAN_BATTERY = 1, HAL_GPADC_CHAN_2 = 2, HAL_GPADC_CHAN_3 = 3, HAL_GPADC_CHAN_4 = 4, HAL_GPADC_CHAN_5 = 5, HAL_GPADC_CHAN_6 = 6, HAL_GPADC_CHAN_ADCKEY = 7, HAL_GPADC_CHAN_QTY, }; enum HAL_GPADC_ATP_T { HAL_GPADC_ATP_NULL = 0, HAL_GPADC_ATP_125US = 125, HAL_GPADC_ATP_500US = 500, HAL_GPADC_ATP_1MS = 1000, HAL_GPADC_ATP_2MS = 2000, HAL_GPADC_ATP_5MS = 5000, HAL_GPADC_ATP_10MS = 10000, HAL_GPADC_ATP_20MS = 20000, HAL_GPADC_ATP_30MS = 30000, HAL_GPADC_ATP_40MS = 40000, HAL_GPADC_ATP_50MS = 50000, HAL_GPADC_ATP_60MS = 60000, HAL_GPADC_ATP_ONESHOT = -1, }; enum HAL_ADCKEY_IRQ_T { HAL_ADCKEY_IRQ_NONE = 0, HAL_ADCKEY_IRQ_PRESSED = (1 << 0), HAL_ADCKEY_IRQ_RELEASED = (1 << 1), HAL_ADCKEY_IRQ_BOTH = (HAL_ADCKEY_IRQ_PRESSED | HAL_ADCKEY_IRQ_RELEASED), }; enum HAL_ADCKEY_IRQ_STATUS_T { HAL_ADCKEY_ADC_VALID = (1 << 0), HAL_ADCKEY_RELEASED = (1 << 1), HAL_ADCKEY_PRESSED = (1 << 2), HAL_ADCKEY_ERR0 = (1 << 3), HAL_ADCKEY_ERR1 = (1 << 4), }; typedef uint16_t HAL_GPADC_MV_T; typedef void (*HAL_GPADC_EVENT_CB_T)(uint16_t raw_val, HAL_GPADC_MV_T volt); typedef void (*HAL_ADCKEY_EVENT_CB_T)(enum HAL_ADCKEY_IRQ_STATUS_T irq_status, uint16_t raw_val); int hal_gpadc_open(enum HAL_GPADC_CHAN_T channel, enum HAL_GPADC_ATP_T atp, HAL_GPADC_EVENT_CB_T cb); bool hal_gpadc_get_volt(enum HAL_GPADC_CHAN_T ch, HAL_GPADC_MV_T *volt); int hal_gpadc_close(enum HAL_GPADC_CHAN_T channel); void hal_gpadc_sleep(void); void hal_gpadc_wakeup(void); void hal_adckey_set_irq_handler(HAL_ADCKEY_EVENT_CB_T cb); int hal_adckey_set_irq(enum HAL_ADCKEY_IRQ_T type); #ifdef __cplusplus } #endif #endif//__FMDEC_H__
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_gpadc.h
C
apache-2.0
2,615
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_GPIO_H__ #define __HAL_GPIO_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "hal_iomux.h" enum HAL_GPIO_DIR_T { HAL_GPIO_DIR_IN = 0, HAL_GPIO_DIR_OUT = 1, }; enum HAL_GPIO_IRQ_TYPE_T { HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE = 0, HAL_GPIO_IRQ_TYPE_EDGE_SENSITIVE, }; enum HAL_GPIO_IRQ_POLARITY_T { HAL_GPIO_IRQ_POLARITY_LOW_FALLING = 0, HAL_GPIO_IRQ_POLARITY_HIGH_RISING, }; typedef void (* HAL_GPIO_PIN_IRQ_HANDLER)(enum HAL_GPIO_PIN_T pin); struct HAL_GPIO_IRQ_CFG_T { uint8_t irq_enable:1; uint8_t irq_debounce:1; enum HAL_GPIO_IRQ_TYPE_T irq_type; enum HAL_GPIO_IRQ_POLARITY_T irq_polarity; HAL_GPIO_PIN_IRQ_HANDLER irq_handler; }; enum HAL_GPIO_DIR_T hal_gpio_pin_get_dir(enum HAL_GPIO_PIN_T pin); void hal_gpio_pin_set_dir(enum HAL_GPIO_PIN_T pin, enum HAL_GPIO_DIR_T dir, uint8_t val_for_out); void hal_gpio_pin_set(enum HAL_GPIO_PIN_T pin); void hal_gpio_pin_clr(enum HAL_GPIO_PIN_T pin); uint8_t hal_gpio_pin_get_val(enum HAL_GPIO_PIN_T pin); uint8_t hal_gpio_setup_irq(enum HAL_GPIO_PIN_T pin, const struct HAL_GPIO_IRQ_CFG_T *cfg); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_gpio.h
C
apache-2.0
1,819
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_I2C_H__ #define __HAL_I2C_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "hal_gpio.h" #include "hal_sensor_eng.h" // For 10-bit address devices: OR the following mask with the real address #define HAL_I2C_10BITADDR_MASK (1 << 15) enum HAL_I2C_ACTION_AFTER_WRITE_T { HAL_I2C_STOP_AFTER_WRITE = 0, HAL_I2C_RESTART_AFTER_WRITE, }; enum HAL_I2C_ID_T { HAL_I2C_ID_0 = 0, #if (CHIP_HAS_I2C > 1) HAL_I2C_ID_1, #endif HAL_I2C_ID_NUM, }; enum HAL_I2C_API_MODE_T { HAL_I2C_API_MODE_TASK = 0, HAL_I2C_API_MODE_SIMPLE, HAL_I2C_API_MODE_SENSOR_ENGINE, }; enum HAL_I2C_INT_STATUS_T { HAL_I2C_INT_STATUS_GEN_CALL_MASK = 0x1<<11, HAL_I2C_INT_STATUS_START_DET_MASK = 0x1<<10, HAL_I2C_INT_STATUS_STOP_DET_MASK = 0x1<<9, HAL_I2C_INT_STATUS_ACTIVITY_MASK = 0x1<<8, HAL_I2C_INT_STATUS_RX_DONE_MASK = 0x1<<7, HAL_I2C_INT_STATUS_TX_ABRT_MASK = 0x1<<6, HAL_I2C_INT_STATUS_RD_REQ_MASK = 0x1<<5, HAL_I2C_INT_STATUS_TX_EMPTY_MASK = 0x1<<4, HAL_I2C_INT_STATUS_TX_OVER_MASK = 0x1<<3, HAL_I2C_INT_STATUS_RX_FULL_MASK = 0x1<<2, HAL_I2C_INT_STATUS_RX_OVER_MASK = 0x1<<1, HAL_I2C_INT_STATUS_RX_UNDER_MASK = 0x1<<0, /* FIXME : same as i2cip definitions #define I2CIP_INT_STATUS_GEN_CALL_SHIFT (11) #define I2CIP_INT_STATUS_START_DET_SHIFT (10) #define I2CIP_INT_STATUS_STOP_DET_SHIFT (9) #define I2CIP_INT_STATUS_ACTIVITY_SHIFT (8) #define I2CIP_INT_STATUS_RX_DONE_SHIFT (7) #define I2CIP_INT_STATUS_TX_ABRT_SHIFT (6) #define I2CIP_INT_STATUS_RD_REQ_SHIFT (5) #define I2CIP_INT_STATUS_TX_EMPTY_SHIFT (4) #define I2CIP_INT_STATUS_TX_OVER_SHIFT (3) #define I2CIP_INT_STATUS_RX_FULL_SHIFT (2) #define I2CIP_INT_STATUS_RX_OVER_SHIFT (1) #define I2CIP_INT_STATUS_RX_UNDER_SHIFT (0) */ }; enum HAL_I2C_ERRCODE_T { HAL_I2C_ERRCODE_SLVRD_INTX = 1<<15, HAL_I2C_ERRCODE_SLV_ARBLOST = 1<<14, HAL_I2C_ERRCODE_SLVFLUSH_TXFIFO = 1<<13, HAL_I2C_ERRCODE_ARB_LOST = 1<<12, HAL_I2C_ERRCODE_MASTER_DIS = 1<<11, HAL_I2C_ERRCODE_10B_RD_NORSTRT = 1<<10, HAL_I2C_ERRCODE_SBYTE_NORSTRT = 1<<9, HAL_I2C_ERRCODE_HS_NORSTRT = 1<<8, HAL_I2C_ERRCODE_SBYTE_ACKDET = 1<<7, HAL_I2C_ERRCODE_HS_ACKDET = 1<<6, HAL_I2C_ERRCODE_GCALL_READ = 1<<5, HAL_I2C_ERRCODE_GCALL_NOACK = 1<<4, HAL_I2C_ERRCODE_TXDATA_NOACK = 1<<3, HAL_I2C_ERRCODE_10ADDR2_NOACK = 1<<2, HAL_I2C_ERRCODE_10ADDR1_NOACK = 1<<1, HAL_I2C_ERRCODE_7B_ADDR_NOACK = 1<<0, HAL_I2C_ERRCODE_INV_PARAM = 1<<31, HAL_I2C_ERRCODE_IN_USE = 1<<30, HAL_I2C_ERRCODE_FIFO_ERR = 1<<29, HAL_I2C_ERRCODE_SYNC_TIMEOUT = 1<<28, HAL_I2C_ERRCODE_ACT_TIMEOUT = 1<<27, HAL_I2C_ERRCODE_TFNF_TIMEOUT = 1<<26, HAL_I2C_ERRCODE_TFE_TIMEOUT = 1<<25, HAL_I2C_ERRCODE_RFNE_TIMEOUT = 1<<24, /* FIXME : same as i2cip definitions #define I2CIP_TX_ABRT_SOURCE_ABRT_SLVRD_INTX_SHIFT (15) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLV_ARBLOST_SHIFT (14) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLVFLUSH_TXFIFO_SHIFT (13) #define I2CIP_TX_ABRT_SOURCE_ARB_LOST_SHIFT (12) #define I2CIP_TX_ABRT_SOURCE_ABRT_MASTER_DIS_SHIFT (11) #define I2CIP_TX_ABRT_SOURCE_ABRT_10B_RD_NORSTRT_SHIFT (10) #define I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_NORSTRT_SHIFT (9) #define I2CIP_TX_ABRT_SOURCE_ABRT_HS_NORSTRT_SHIFT (8) #define I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_ACKDET_SHIFT (7) #define I2CIP_TX_ABRT_SOURCE_ABRT_HS_ACKDET_SHIFT (6) #define I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_READ_SHIFT (5) #define I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_NOACK_SHIFT (4) #define I2CIP_TX_ABRT_SOURCE_ABRT_TXDATA_NOACK_SHIFT (3) #define I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR2_NOACK_SHIFT (2) #define I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR1_NOACK_SHIFT (1) #define I2CIP_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_SHIFT (0) */ }; struct HAL_I2C_CONFIG_T { /* mode SIMPLE_MODE : pulling when reading or writing (always sync), or use dma external;master or slave;only enable slave related irq; TASK_MODE : task to driven reading or writing (sync or async, dma or non-dma);only master */ enum HAL_I2C_API_MODE_T mode; uint8_t use_sync; uint8_t use_dma; uint8_t as_master; uint32_t speed; uint32_t addr_as_slave; }; typedef void (*HAL_I2C_SENSOR_ENG_HANDLER_T)(enum HAL_I2C_ID_T id, const uint8_t *buf, uint32_t len); struct HAL_I2C_SENSOR_ENGINE_CONFIG_T { enum HAL_SENSOR_ENGINE_ID_T id; enum HAL_SENSOR_ENGINE_TRIGGER_T trigger_type; enum HAL_GPIO_PIN_T trigger_gpio; uint32_t period_us; uint16_t target_addr; uint8_t *write_buf; uint16_t write_txn_len; uint8_t *read_buf; uint16_t read_txn_len; uint16_t txn_cnt; uint8_t read_burst_cnt; HAL_I2C_SENSOR_ENG_HANDLER_T handler; }; struct HAL_GPIO_I2C_CONFIG_T { enum HAL_GPIO_PIN_T scl; enum HAL_GPIO_PIN_T sda; uint32_t speed; }; uint32_t hal_i2c_open(enum HAL_I2C_ID_T id, const struct HAL_I2C_CONFIG_T *cfg); uint32_t hal_i2c_close(enum HAL_I2C_ID_T id); uint32_t hal_i2c_reopen(enum HAL_I2C_ID_T id, const struct HAL_I2C_CONFIG_T *cfg); /* for master task mode */ typedef void (*HAL_I2C_TRANSFER_HANDLER_T)(enum HAL_I2C_ID_T id, uint32_t transfer_id, const uint8_t *tx_buf, uint32_t tx_len, const uint8_t *rx_buf, uint32_t rx_len, enum HAL_I2C_ERRCODE_T errcode); uint32_t hal_i2c_send(enum HAL_I2C_ID_T id, uint32_t device_addr, uint8_t *buf, uint32_t reg_len, uint32_t value_len, uint32_t transfer_id, HAL_I2C_TRANSFER_HANDLER_T handler); uint32_t hal_i2c_recv(enum HAL_I2C_ID_T id, uint32_t device_addr, uint8_t *buf, uint32_t reg_len, uint32_t value_len, uint8_t restart_after_write, uint32_t transfer_id, HAL_I2C_TRANSFER_HANDLER_T handler); // New I2C task mode APIs uint32_t hal_i2c_task_send(enum HAL_I2C_ID_T id, uint16_t device_addr, const uint8_t *tx_buf, uint16_t tx_len, uint32_t transfer_id, HAL_I2C_TRANSFER_HANDLER_T handler); uint32_t hal_i2c_task_recv(enum HAL_I2C_ID_T id, uint16_t device_addr, const uint8_t *tx_buf, uint16_t tx_len, uint8_t *rx_buf, uint16_t rx_len, uint32_t transfer_id, HAL_I2C_TRANSFER_HANDLER_T handler); uint32_t hal_i2c_task_msend(enum HAL_I2C_ID_T id, uint16_t device_addr, const uint8_t *tx_buf, uint16_t tx_item_len, uint16_t item_cnt, uint32_t transfer_id, HAL_I2C_TRANSFER_HANDLER_T handler); uint32_t hal_i2c_task_mrecv(enum HAL_I2C_ID_T id, uint16_t device_addr, const uint8_t *tx_buf, uint16_t tx_item_len, uint8_t *rx_buf, uint16_t rx_item_len, uint16_t item_cnt, uint32_t transfer_id, HAL_I2C_TRANSFER_HANDLER_T handler); /* for master task mode end */ /* for slave and simple master mode */ typedef void (*HAL_I2C_INT_HANDLER_T)(enum HAL_I2C_ID_T id, enum HAL_I2C_INT_STATUS_T status, uint32_t errocode); uint32_t hal_i2c_slv_write(enum HAL_I2C_ID_T id, uint8_t *buf, uint32_t buf_len, uint32_t *act_len); uint32_t hal_i2c_slv_read(enum HAL_I2C_ID_T id, uint8_t *buf, uint32_t buf_len, uint32_t *act_len); uint32_t hal_i2c_set_interrupt_handler(enum HAL_I2C_ID_T id, HAL_I2C_INT_HANDLER_T handler); uint32_t hal_i2c_mst_write(enum HAL_I2C_ID_T id, uint32_t device_addr, const uint8_t *buf, uint32_t buf_len, uint32_t *act_len, uint32_t restart, uint32_t stop, uint32_t yield); uint32_t hal_i2c_mst_read(enum HAL_I2C_ID_T id, uint32_t device_addr, uint8_t *buf, uint32_t buf_len, uint32_t *act_len, uint32_t restart, uint32_t stop, uint32_t yield); // New I2C simple mode APIs uint32_t hal_i2c_simple_send(enum HAL_I2C_ID_T id, uint16_t device_addr, const uint8_t *tx_buf, uint16_t tx_len); uint32_t hal_i2c_simple_recv(enum HAL_I2C_ID_T id, uint16_t device_addr, const uint8_t *tx_buf, uint16_t tx_len, uint8_t *rx_buf, uint16_t rx_len); /* for slave and simple master mode end */ /* sensor engine mode */ uint32_t hal_i2c_sensor_engine_start(enum HAL_I2C_ID_T id, const struct HAL_I2C_SENSOR_ENGINE_CONFIG_T *cfg); uint32_t hal_i2c_sensor_engine_stop(enum HAL_I2C_ID_T id); /* sensor engine end */ int hal_gpio_i2c_open(const struct HAL_GPIO_I2C_CONFIG_T *cfg); int hal_gpio_i2c_close(void); uint32_t hal_gpio_i2c_send(uint32_t device_addr, const uint8_t *buf, uint32_t reg_len, uint32_t value_len); uint32_t hal_gpio_i2c_recv(uint32_t device_addr, uint8_t *buf, uint32_t reg_len, uint32_t value_len, uint8_t restart_after_write); // New GPIO I2C APIs uint32_t hal_gpio_i2c_simple_send(uint32_t device_addr, const uint8_t *tx_buf, uint16_t tx_len); uint32_t hal_gpio_i2c_simple_recv(uint32_t device_addr, const uint8_t *tx_buf, uint16_t tx_len, uint8_t *rx_buf, uint16_t rx_len); #ifdef __cplusplus } #endif #endif /* __HAL_I2C_H__ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_i2c.h
C
apache-2.0
9,543
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_IOMUX_H__ #define __HAL_IOMUX_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "plat_addr_map.h" #include CHIP_SPECIFIC_HDR(hal_iomux) enum HAL_IOMUX_OP_TYPE_T { HAL_IOMUX_OP_KEEP_OTHER_FUNC_BIT = 0, HAL_IOMUX_OP_CLEAN_OTHER_FUNC_BIT, }; enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T { HAL_IOMUX_PIN_VOLTAGE_VIO = 0, HAL_IOMUX_PIN_VOLTAGE_MEM, // For PMU LED pins only HAL_IOMUX_PIN_VOLTAGE_VBAT, }; enum HAL_IOMUX_PIN_PULL_SELECT_T { HAL_IOMUX_PIN_NOPULL = 0, HAL_IOMUX_PIN_PULLUP_ENALBE, HAL_IOMUX_PIN_PULLDOWN_ENALBE, }; enum HAL_PWRKEY_IRQ_T { HAL_PWRKEY_IRQ_NONE = 0, HAL_PWRKEY_IRQ_FALLING_EDGE = (1 << 0), HAL_PWRKEY_IRQ_RISING_EDGE = (1 << 1), HAL_PWRKEY_IRQ_BOTH_EDGE = (HAL_PWRKEY_IRQ_FALLING_EDGE | HAL_PWRKEY_IRQ_RISING_EDGE), }; struct HAL_IOMUX_PIN_FUNCTION_MAP { enum HAL_IOMUX_PIN_T pin; enum HAL_IOMUX_FUNCTION_T function; enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt; enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel; }; uint32_t hal_iomux_check(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t count); uint32_t hal_iomux_init(const struct HAL_IOMUX_PIN_FUNCTION_MAP *map, uint32_t count); uint32_t hal_iomux_set_function(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_FUNCTION_T func, enum HAL_IOMUX_OP_TYPE_T type); enum HAL_IOMUX_FUNCTION_T hal_iomux_get_function(enum HAL_IOMUX_PIN_T pin); uint32_t hal_iomux_set_io_voltage_domains(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); uint32_t hal_iomux_set_io_pull_select(enum HAL_IOMUX_PIN_T pin, enum HAL_IOMUX_PIN_PULL_SELECT_T pull_sel); void hal_iomux_set_default_config(void); void hal_iomux_set_uart0_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); void hal_iomux_set_uart1_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); void hal_iomux_set_uart2_voltage(enum HAL_IOMUX_PIN_VOLTAGE_DOMAINS_T volt); bool hal_iomux_uart0_connected(void); bool hal_iomux_uart1_connected(void); void hal_iomux_set_uart0(void); void hal_iomux_set_uart1(void); void hal_iomux_set_uart2(void); void hal_iomux_set_analog_i2c(void); void hal_iomux_set_analog_i2c_master_slave(void); void hal_iomux_set_jtag(void); void hal_iomux_set_sdmmc_dt_n_out_group(int enable); void hal_iomux_set_i2s0(void); void hal_iomux_set_i2s1(void); void hal_iomux_set_spdif0(void); void hal_iomux_set_spdif1(void); void hal_iomux_set_dig_mic_clock_pin(enum HAL_IOMUX_PIN_T pin); void hal_iomux_set_dig_mic_data0_pin(enum HAL_IOMUX_PIN_T pin); void hal_iomux_set_dig_mic_data1_pin(enum HAL_IOMUX_PIN_T pin); void hal_iomux_set_dig_mic_data2_pin(enum HAL_IOMUX_PIN_T pin); void hal_iomux_set_dig_mic(uint32_t map); void hal_iomux_set_spi(void); void hal_iomux_set_spilcd(void); void hal_iomux_set_i2c0(void); void hal_iomux_set_i2c1(void); void hal_iomux_set_clock_out(void); void hal_iomux_set_clock_12m(void); void hal_iomux_clear_clock_12m(void); void hal_iomux_set_bt_tport(void); void hal_iomux_set_bt_rf_sw(int rx_on, int tx_on); void hal_iomux_ispi_access_init(void); enum HAL_IOMUX_ISPI_ACCESS_T hal_iomux_ispi_access_enable(enum HAL_IOMUX_ISPI_ACCESS_T access); enum HAL_IOMUX_ISPI_ACCESS_T hal_iomux_ispi_access_disable(enum HAL_IOMUX_ISPI_ACCESS_T access); int hal_pwrkey_set_irq(enum HAL_PWRKEY_IRQ_T type); bool hal_pwrkey_pressed(void); bool hal_pwrkey_startup_pressed(void); enum HAL_PWRKEY_IRQ_T hal_pwrkey_get_irq_state(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_iomux.h
C
apache-2.0
4,119
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_IR_H__ #define __HAL_IR_H__ #include "plat_types.h" #include "irlib.h" #include "hal_gpio.h" #ifdef __cplusplus extern "C" { #endif #define CARRIER_FREQ 38000 /* IR duty ratio: on puls in totol*/ typedef enum { //debug find that pwm value max 100 !!! DUTY_RATIO_1VS4 = 25,//51, //256, //0x00, /* 1:4*/ DUTY_RATIO_1VS3 = 34,//64, //256, //0x01, /* 1:3*/ DUTY_RATIO_1VS2 = 50,//85, //256, //0x02, /* 1:2*/ DUTY_RATIO_1VS1 = 100,//128, //256, //0x04, /* 1:1*/ } IR_DUTY_RATIO_T; /*************************************************************** * Function : hal_ir_tx_cb_register * Description : * Input : cb ****************************************************************/ void hal_ir_tx_cb_register(IR_TX_CB cb); /*************************************************************** * Function : hal_ir_rx_cb_register * Description : * Input : cb ****************************************************************/ void hal_ir_rx_cb_register(IR_RX_CB cb); /*************************************************************** * Function : hal_input_cb_register * Description : * Input : cb ****************************************************************/ void hal_input_cb_register(INPUT_CB cb); /*************************************************************** * Function : hal_ir_tx * Description : 发送红外码 * Input : proto: 传输的协议; *keycode: 发送的红外码; num:红外码数; repeat: 重复码 * repeat: bit0 repeat function: * bit1~bit7: others potocol cmd * Output : None * Return : 0: success; others: failed * //TODO: add mutex for muti access ****************************************************************/ int hal_ir_tx(IR_PROTO_T proto, uint8_t * keycode,uint16_t num,uint8_t repeat); /*************************************************************** * Function : hal_ir_tx_raw * Description : 发送红外帧原始的时间数据 * Input : proto: 传输的协议; *frame: 红外帧数据; num:帧个数; repeat: 重复码 * repeat: bit0 repeat function: * Output : None * Return : 0: success; others: failed * //TODO: add mutex for muti access ****************************************************************/ int hal_ir_tx_raw(IR_PROTO_T proto, uint16_t * frame, uint16_t num,uint8_t repeat); /*************************************************************** * Function : hal_ir_tx_init * Description : * Input : PWM gpio,freq,ratio * Output : None * Return : 0: success; others: failed ****************************************************************/ int hal_ir_tx_init(enum HAL_IOMUX_PIN_T io,uint16_t freq,uint8_t ratio); /*************************************************************** * Function : hal_ir_tx_deinit * Description : * Input : None * Output : None * Return : None ****************************************************************/ void hal_ir_tx_deinit(void); /*************************************************************** * Function : hal_ir_rx_init * Description : * Input : gpio * Output : None * Return : 0: success; others: failed ****************************************************************/ int hal_ir_rx_init(enum HAL_IOMUX_PIN_T gpio); int hal_input_init(enum HAL_IOMUX_PIN_T gpio); /*************************************************************** * Function : hal_ir_rx_deinit * Description : * Input : None * Output : None * Return : 0: success; others: failed ****************************************************************/ int hal_ir_rx_deinit(void); /*************************************************************** * Function : hal_ir_init * Description : * Input : IR_PARAM_S * Output : None * Return : 0: success; others: failed ****************************************************************/ int hal_ir_init(void); /*************************************************************** * Function : hal_ir_deinit * Description : * Input : None * Output : None * Return : 0: success; others: failed ****************************************************************/ int hal_ir_deinit(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_ir.h
C
apache-2.0
5,053
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_KEY_H__ #define __HAL_KEY_H__ #include "hal_gpio.h" #include "hal_gpadc.h" #ifdef __cplusplus extern "C" { #endif enum HAL_KEY_CODE_T { HAL_KEY_CODE_NONE = 0, HAL_KEY_CODE_PWR = (1 << 0), HAL_KEY_CODE_FN1 = (1 << 1), HAL_KEY_CODE_FN2 = (1 << 2), HAL_KEY_CODE_FN3 = (1 << 3), HAL_KEY_CODE_FN4 = (1 << 4), HAL_KEY_CODE_FN5 = (1 << 5), HAL_KEY_CODE_FN6 = (1 << 6), HAL_KEY_CODE_FN7 = (1 << 7), HAL_KEY_CODE_FN8 = (1 << 8), HAL_KEY_CODE_FN9 = (1 << 9), HAL_KEY_CODE_FN10 = (1 << 10), HAL_KEY_CODE_FN11 = (1 << 11), HAL_KEY_CODE_FN12 = (1 << 12), HAL_KEY_CODE_FN13 = (1 << 13), HAL_KEY_CODE_FN14 = (1 << 14), HAL_KEY_CODE_FN15 = (1 << 15), }; enum HAL_KEY_EVENT_T { HAL_KEY_EVENT_NONE = 0, HAL_KEY_EVENT_DOWN, HAL_KEY_EVENT_FIRST_DOWN, HAL_KEY_EVENT_CONTINUED_DOWN, HAL_KEY_EVENT_UP, HAL_KEY_EVENT_UP_AFTER_LONGPRESS, HAL_KEY_EVENT_LONGPRESS, HAL_KEY_EVENT_LONGLONGPRESS, HAL_KEY_EVENT_CLICK, HAL_KEY_EVENT_DOUBLECLICK, HAL_KEY_EVENT_TRIPLECLICK, HAL_KEY_EVENT_ULTRACLICK, HAL_KEY_EVENT_RAMPAGECLICK, HAL_KEY_EVENT_REPEAT, HAL_KEY_EVENT_GROUPKEY_DOWN, HAL_KEY_EVENT_GROUPKEY_REPEAT, HAL_KEY_EVENT_INITDOWN, HAL_KEY_EVENT_INITUP, HAL_KEY_EVENT_INITLONGPRESS, HAL_KEY_EVENT_INITLONGLONGPRESS, HAL_KEY_EVENT_INITFINISHED, HAL_KEY_EVENT_NUM, }; #define KEY_EVENT_SET(a) (1 << HAL_KEY_EVENT_ ## a) #define KEY_EVENT_SET2(a, b) (KEY_EVENT_SET(a) | KEY_EVENT_SET(b)) #define KEY_EVENT_SET3(a, b, c) (KEY_EVENT_SET2(a, b) | KEY_EVENT_SET(c)) #define KEY_EVENT_SET4(a, b, c, d) (KEY_EVENT_SET3(a, b, c) | KEY_EVENT_SET(d)) enum HAL_KEY_GPIOKEY_VAL_T { HAL_KEY_GPIOKEY_VAL_LOW = 0, HAL_KEY_GPIOKEY_VAL_HIGH, }; struct HAL_KEY_GPIOKEY_CFG_T { enum HAL_KEY_CODE_T key_code; struct HAL_IOMUX_PIN_FUNCTION_MAP key_config; enum HAL_KEY_GPIOKEY_VAL_T key_down; }; int hal_key_open(int checkPwrKey, int (* cb)(uint32_t, uint8_t)); enum HAL_KEY_EVENT_T hal_key_read_status(enum HAL_KEY_CODE_T code); int hal_key_close(void); int get_recovery_mode(void); #ifdef __cplusplus } #endif #endif//__FMDEC_H__
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_key.h
C
apache-2.0
2,867
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_LOCATION_H__ #define __HAL_LOCATION_H__ #ifdef __cplusplus extern "C" { #endif #define HAL_SEC_DEF_A(s, d, n) __attribute__((section(#s #d #n))) n #define HAL_SEC_DEF(section, name) HAL_SEC_DEF_A(section, ., name) #define HAL_SEC_LOC(section) HAL_SEC_DEF_A(section, , ) #if defined(__GNUC__) && !(defined(ROM_BUILD) || defined(PROGRAMMER)) #define BOOT_TEXT_SRAM_LOC HAL_SEC_LOC(.boot_text_sram) #define BOOT_TEXT_SRAM_DEF(n) HAL_SEC_DEF(.boot_text_sram, n) #define BOOT_TEXT_FLASH_LOC HAL_SEC_LOC(.boot_text_flash) #define BOOT_TEXT_FLASH_DEF(n) HAL_SEC_DEF(.boot_text_flash, n) #define BOOT_RODATA_LOC HAL_SEC_LOC(.boot_rodata) #define BOOT_RODATA_DEF(n) HAL_SEC_DEF(.boot_rodata, n) #define BOOT_DATA_LOC HAL_SEC_LOC(.boot_data) #define BOOT_DATA_DEF(n) HAL_SEC_DEF(.boot_data, n) #ifdef __ARMCC_VERSION #define BOOT_BSS_LOC HAL_SEC_LOC(.bss.boot_bss) #define BOOT_BSS_DEF(n) HAL_SEC_DEF(.bss.boot_bss, n) #else #define BOOT_BSS_LOC HAL_SEC_LOC(.boot_bss) #define BOOT_BSS_DEF(n) HAL_SEC_DEF(.boot_bss, n) #endif #define SRAM_TEXT_LOC HAL_SEC_LOC(.sram_text) #define SRAM_TEXT_DEF(n) HAL_SEC_DEF(.sram_text, n) #define SRAM_DATA_LOC HAL_SEC_LOC(.sram_data) #define SRAM_DATA_DEF(n) HAL_SEC_DEF(.sram_data, n) #define SRAM_STACK_LOC ALIGNED(8) HAL_SEC_LOC(.sram_data) #define SRAM_STACK_DEF(n) ALIGNED(8) HAL_SEC_LOC(.sram_data, n) #ifdef __ARMCC_VERSION #define SRAM_BSS_LOC HAL_SEC_LOC(.bss.sram_bss) #define SRAM_BSS_DEF(n) HAL_SEC_DEF(.bss.sram_bss, n) #else #define SRAM_BSS_LOC HAL_SEC_LOC(.sram_bss) #define SRAM_BSS_DEF(n) HAL_SEC_DEF(.sram_bss, n) #endif #define FRAM_TEXT_LOC HAL_SEC_LOC(.fast_text_sram) #define FRAM_TEXT_DEF(n) HAL_SEC_DEF(.fast_text_sram, n) #define CP_TEXT_SRAM_LOC HAL_SEC_LOC(.cp_text_sram) #define CP_TEXT_SRAM_DEF(n) HAL_SEC_DEF(.cp_text_sram, n) #define CP_DATA_LOC HAL_SEC_LOC(.cp_data) #define CP_DATA_DEF(n) HAL_SEC_DEF(.cp_data, n) #ifdef __ARMCC_VERSION #define CP_BSS_LOC HAL_SEC_LOC(.bss.cp_bss) #define CP_BSS_DEF(n) HAL_SEC_DEF(.bss.cp_bss, n) #else #define CP_BSS_LOC HAL_SEC_LOC(.cp_bss) #define CP_BSS_DEF(n) HAL_SEC_DEF(.cp_bss, n) #endif #define FLASH_TEXT_LOC HAL_SEC_LOC(.flash_text) #define FLASH_TEXT_DEF(n) HAL_SEC_DEF(.flash_text, n) #define FLASH_RODATA_LOC HAL_SEC_LOC(.flash_rodata) #define FLASH_RODATA_DEF(n) HAL_SEC_DEF(.flash_rodata, n) #define REBOOT_CUSTOM_PARAM_LOC HAL_SEC_LOC(.reboot_custom_param) #define REBOOT_CUSTOM_PARAM_DEF HAL_SEC_DEF(.reboot_custom_param) #else #define BOOT_TEXT_SRAM_LOC #define BOOT_TEXT_SRAM_DEF(n) n #if defined(__GNUC__) && defined(PROGRAMMER_INFLASH) #define BOOT_TEXT_FLASH_LOC HAL_SEC_LOC(.boot_text_flash) #define BOOT_TEXT_FLASH_DEF(n) HAL_SEC_DEF(.boot_text_flash, n) #else #define BOOT_TEXT_FLASH_LOC #define BOOT_TEXT_FLASH_DEF(n) n #endif #define BOOT_RODATA_LOC #define BOOT_RODATA_DEF(n) n #define BOOT_DATA_LOC #define BOOT_DATA_DEF(n) n #define BOOT_BSS_LOC #define BOOT_BSS_DEF(n) n #define SRAM_TEXT_LOC #define SRAM_TEXT_DEF(n) n #define SRAM_DATA_LOC #define SRAM_DATA_DEF(n) n #define SRAM_STACK_LOC #define SRAM_STACK_DEF(n) n #define SRAM_BSS_LOC #define SRAM_BSS_DEF(n) n #define FRAM_TEXT_LOC #define FRAM_TEXT_DEF(n) n #define CP_TEXT_SRAM_LOC #define CP_TEXT_SRAM_DEF(n) n #define CP_DATA_LOC #define CP_DATA_DEF(n) n #define CP_BSS_LOC #define CP_BSS_DEF(n) n #define FLASH_TEXT_LOC #define FLASH_TEXT_DEF(n) n #define FLASH_RODATA_LOC #define FLASH_RODATA_DEF(n) n #define REBOOT_CUSTOM_PARAM_LOC #define REBOOT_CUSTOM_PARAM_DEF(n) n #endif // !__GNUC__ || ROM_BUILD || PROGRAMMER #if defined(__GNUC__) && defined(__ARM_ARCH_ISA_ARM) #define SYNC_FLAGS_LOC HAL_SEC_LOC(.sync_flags) #define SYNC_FLAGS_DEF(n) HAL_SEC_DEF(.sync_flags, n) #else #define SYNC_FLAGS_LOC HAL_SEC_LOC(.sram_bss) #define SYNC_FLAGS_DEF(n) HAL_SEC_DEF(.sram_bss, n) #endif #if defined(__ARM_ARCH_ISA_ARM) #define PSRAMUHS_TEXT_LOC HAL_SEC_LOC(.psramuhs_text) #define PSRAMUHS_TEXT_DEF(n) HAL_SEC_DEF(.psramuhs_text, n) #else #define PSRAMUHS_TEXT_LOC #define PSRAMUHS_TEXT_DEF(n) n #endif #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_location.h
C
apache-2.0
5,634
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 NORFLASH_HAL_H #define NORFLASH_HAL_H #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "hal_cmu.h" #define HAL_NORFLASH_DEVICE_ID_LEN 3 #define HAL_NORFLASH_UNIQUE_ID_LEN 16 #define FLASH_SECTOR_SIZE_IN_BYTES 4096 #define FLASH_BLOCK_SIZE_IN_BYTES (32*1024) enum HAL_NORFLASH_ID_T { HAL_NORFLASH_ID_0 = 0, HAL_NORFLASH_ID_NUM, }; enum HAL_NORFLASH_RET_T { HAL_NORFLASH_OK, HAL_NORFLASH_SUSPENDED, HAL_NORFLASH_ERR, HAL_NORFLASH_BAD_ID, HAL_NORFLASH_BAD_DIV, HAL_NORFLASH_BAD_DIV_VERIF, HAL_NORFLASH_BAD_CFG, HAL_NORFLASH_BAD_OP, HAL_NORFLASH_BAD_CALIB, HAL_NORFLASH_BAD_ADDR, HAL_NORFLASH_BAD_LEN, HAL_NORFLASH_NOT_OPENED, }; enum HAL_NORFLASH_SPEED { HAL_NORFLASH_SPEED_13M = 13000000, HAL_NORFLASH_SPEED_26M = 26000000, HAL_NORFLASH_SPEED_52M = 52000000, HAL_NORFLASH_SPEED_78M = 78000000, HAL_NORFLASH_SPEED_104M = 104000000, HAL_NORFLASH_SPEED_130M = 130000000, HAL_NORFLASH_SPEED_156M = 156000000, HAL_NORFLASH_SPEED_182M = 182000000, HAL_NORFLASH_SPEED_208M = 208000000, HAL_NORFLASH_SPEED_234M = 234000000, }; enum HAL_NORFLASH_OP_MODE { // Different groups can be used together, different flash-device may support different option(s) // (1) basic read mode /* standard spi mode */ HAL_NORFLASH_OP_MODE_STAND_SPI = 0x1, /* fast spi mode*/ HAL_NORFLASH_OP_MODE_FAST_SPI = 0x2, /* dual mode */ HAL_NORFLASH_OP_MODE_DUAL_OUTPUT = 0x4, /* dual mode */ HAL_NORFLASH_OP_MODE_DUAL_IO = 0x8, /* quad mode */ HAL_NORFLASH_OP_MODE_QUAD_OUTPUT = 0x10, /* quad mode */ HAL_NORFLASH_OP_MODE_QUAD_IO = 0x20, // (2) extend read mode // read accelerate (no cmd bettween read operation) : // may need Dual or Quad Mode HAL_NORFLASH_OP_MODE_CONTINUOUS_READ = 0x40, // read high performance mode HAL_NORFLASH_OP_MODE_HIGH_PERFORMANCE = 0x80, // read wrap mode HAL_NORFLASH_OP_MODE_READ_WRAP = 0x100, // (3) program mode. // page program mode HAL_NORFLASH_OP_MODE_PAGE_PROGRAM = 0x200, // dual program mode HAL_NORFLASH_OP_MODE_DUAL_PAGE_PROGRAM = 0x400, // quad program mode HAL_NORFLASH_OP_MODE_QUAD_PAGE_PROGRAM = 0x800, // (4) advanced features // suspend and resume HAL_NORFLASH_OP_MODE_SUSPEND = 0x1000, // erase in standard spi mode HAL_NORFLASH_OP_MODE_ERASE_IN_STD = 0x2000, HAL_NORFLASH_OP_MODE_RESERVED = 0xFFFFFFFF, }; struct HAL_NORFLASH_CONFIG_T { uint32_t source_clk; uint32_t speed; enum HAL_NORFLASH_OP_MODE mode; /* internal use : can be config if need to (useful for rom) */ uint8_t override_config:1; uint8_t neg_phase:1; uint8_t pos_neg:1; uint8_t cmdquad:1; uint8_t samdly:3; uint8_t div; /* least 2 */ uint8_t dualmode:1; uint8_t holdpin:1; uint8_t wprpin:1; uint8_t quadmode:1; uint8_t spiruen:3; uint8_t spirden:3; uint8_t dualiocmd; uint8_t rdcmd; uint8_t frdcmd; uint8_t qrdcmd; /* quad io cmd */ #if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) uint8_t dec_enable; /* 1: enable decoder, 0: disable decoder */ uint8_t dec_idx; /* decoder key index ,from 0 to 3 */ uint32_t dec_addr; /* start address where to decode */ uint32_t dec_size; /* bytes number will be decoded */ #endif }; /* hal api */ void hal_norflash_set_freq(enum HAL_CMU_FREQ_T freq); enum HAL_NORFLASH_RET_T hal_norflash_init(void); enum HAL_NORFLASH_RET_T hal_norflash_deinit(void); enum HAL_NORFLASH_RET_T hal_norflash_open(enum HAL_NORFLASH_ID_T id, const struct HAL_NORFLASH_CONFIG_T *cfg); enum HAL_CMU_FREQ_T hal_norflash_clk_to_cmu_freq(uint32_t clk); enum HAL_NORFLASH_RET_T hal_norflash_get_size(enum HAL_NORFLASH_ID_T id, uint32_t *total_size, uint32_t *block_size, uint32_t *sector_size, uint32_t *page_size); enum HAL_NORFLASH_RET_T hal_norflash_get_boundary(enum HAL_NORFLASH_ID_T id, uint32_t address, uint32_t* block_boundary, uint32_t* sector_boundary); enum HAL_NORFLASH_RET_T hal_norflash_get_id(enum HAL_NORFLASH_ID_T id, uint8_t *value, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_get_unique_id(enum HAL_NORFLASH_ID_T id, uint8_t *value, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_enable_protection(enum HAL_NORFLASH_ID_T id); enum HAL_NORFLASH_RET_T hal_norflash_disable_protection(enum HAL_NORFLASH_ID_T id); enum HAL_NORFLASH_RET_T hal_norflash_erase_chip(enum HAL_NORFLASH_ID_T id); enum HAL_NORFLASH_RET_T hal_norflash_erase_suspend(enum HAL_NORFLASH_ID_T id, uint32_t start_address, uint32_t len, int suspend); enum HAL_NORFLASH_RET_T hal_norflash_erase(enum HAL_NORFLASH_ID_T id, uint32_t start_address, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_erase_resume(enum HAL_NORFLASH_ID_T id, int suspend); enum HAL_NORFLASH_RET_T hal_norflash_write_suspend(enum HAL_NORFLASH_ID_T id, uint32_t start_address, const uint8_t *buffer, uint32_t len, int suspend); enum HAL_NORFLASH_RET_T hal_norflash_write(enum HAL_NORFLASH_ID_T id, uint32_t start_address, const uint8_t *buffer, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_write_resume(enum HAL_NORFLASH_ID_T id, int suspend); enum HAL_NORFLASH_RET_T hal_norflash_suspend_check_irq(enum HAL_NORFLASH_ID_T id, uint32_t irq_num); enum HAL_NORFLASH_RET_T hal_norflash_read(enum HAL_NORFLASH_ID_T id, uint32_t start_address, uint8_t *buffer, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_close(enum HAL_NORFLASH_ID_T id); void hal_norflash_sleep(enum HAL_NORFLASH_ID_T id); void hal_norflash_wakeup(enum HAL_NORFLASH_ID_T id); int hal_norflash_busy(void); uint32_t hal_norflash_get_flash_total_size(enum HAL_NORFLASH_ID_T id); int hal_norflash_opened(enum HAL_NORFLASH_ID_T id); enum HAL_NORFLASH_RET_T hal_norflash_get_open_state(enum HAL_NORFLASH_ID_T id); enum HAL_NORFLASH_RET_T hal_norflash_security_register_lock(enum HAL_NORFLASH_ID_T id, uint32_t start_address, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_security_register_erase(enum HAL_NORFLASH_ID_T id, uint32_t start_address, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_security_register_write(enum HAL_NORFLASH_ID_T id, uint32_t start_address, const uint8_t *buffer, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_security_register_read(enum HAL_NORFLASH_ID_T id, uint32_t start_address, uint8_t *buffer, uint32_t len); enum HAL_NORFLASH_RET_T hal_norflash_enable_remap(enum HAL_NORFLASH_ID_T id, uint32_t addr, uint32_t len, uint32_t offset); enum HAL_NORFLASH_RET_T hal_norflash_disable_remap(enum HAL_NORFLASH_ID_T id); enum HAL_NORFLASH_RET_T hal_norflash_re_enable_remap(enum HAL_NORFLASH_ID_T id); int hal_norflash_get_remap_status(enum HAL_NORFLASH_ID_T id); #ifdef __cplusplus } #endif #endif /* NORFLASH_HAL_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_norflash.h
C
apache-2.0
7,650
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_NORFLASHIP_H__ #define __HAL_NORFLASHIP_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #if (CHIP_FLASH_CTRL_VER <= 1) #define NORFLASHIP_RXFIFO_SIZE 8 #define NORFLASHIP_TXFIFO_SIZE 256 #else #define NORFLASHIP_RXFIFO_SIZE 8 #define NORFLASHIP_TXFIFO_SIZE 16 #if !defined(CHIP_BEST2300) #define NORFLASHIP_HAS_SECURITY #endif #if (defined(CHIP_BEST2300) || defined(CHIP_BEST1400)) #define NORFLASHIP_REMAP_NUM 0 #else #define NORFLASHIP_HAS_IDLE_IO_CTRL #define NORFLASHIP_HAS_REMAP #define NORFLASHIP_REMAP_NUM 4 #endif #endif #define REMAP_SECTOR_SIZE 0x1000 uint8_t norflaship_continuous_read_mode_bit(uint8_t mode_bit); uint8_t norflaship_continuous_read_off(void); uint8_t norflaship_continuous_read_on(void); uint32_t norflaship_write_txfifo(const uint8_t *val, uint32_t len); #if (CHIP_FLASH_CTRL_VER <= 1) uint32_t norflaship_v1_write_txfifo_safe(const uint8_t *val, uint32_t len); uint32_t norflaship_v1_write_txfifo_all(const uint8_t *val, uint32_t len); #endif uint8_t norflaship_read_rxfifo_count(void); uint8_t norflaship_read_rxfifo(void); void norflaship_blksize(uint32_t blksize); void norflaship_cmd_addr(uint8_t cmd, uint32_t address); void norflaship_ext_tx_cmd(uint8_t cmd, uint32_t tx_len); void norflaship_ext_rx_cmd(uint8_t cmd, uint32_t tx_len, uint32_t rx_len); void norflaship_cmd_done(void); void norflaship_rxfifo_count_wait(uint8_t cnt); void norflaship_rxfifo_empty_wait(void); void norflaship_busy_wait(void); int norflaship_is_busy(void); void norflaship_clear_fifos(void); void norflaship_clear_rxfifo(void); void norflaship_clear_txfifo(void); void norflaship_div(uint32_t div); uint32_t norflaship_get_div(void); void norflaship_cmdquad(uint32_t v); uint32_t norflaship_get_pos_neg(void); void norflaship_pos_neg(uint32_t v); uint32_t norflaship_get_neg_phase(void); void norflaship_neg_phase(uint32_t v); uint32_t norflaship_get_samdly(void); void norflaship_samdly(uint32_t v); void norflaship_dual_mode(uint32_t v); void norflaship_hold_pin(uint32_t v); void norflaship_wpr_pin(uint32_t v); void norflaship_quad_mode(uint32_t v); void norflaship_dummyclc(uint32_t v); void norflaship_dummyclcen(uint32_t v); void norflaship_addrbyte4(uint32_t v); void norflaship_ruen(uint32_t v); void norflaship_rden(uint32_t v); void norflaship_dualiocmd(uint32_t v); void norflaship_rdcmd(uint32_t v); void norflaship_frdcmd(uint32_t v); void norflaship_qrdcmd(uint32_t v); uint32_t norflaship_get_rdcmd(void); void norflaship_set_idle_io_dir(uint32_t v); void norflaship_sleep(void); void norflaship_wakeup(void); void norflaship_dec_index(uint32_t idx); void norflaship_dec_saddr(uint32_t addr); void norflaship_dec_eaddr(uint32_t addr); void norflaship_dec_enable(void); void norflaship_dec_disable(void); void norflaship_man_wrap_width(uint32_t width); void norflaship_man_wrap_enable(void); void norflaship_man_wrap_disable(void); void norflaship_auto_wrap_cmd(uint32_t cmd); void norflaship_man_mode_enable(void); void norflaship_man_mode_disable(void); int norflaship_config_remap_section(uint32_t id, uint32_t addr, uint32_t len, uint32_t new_addr); void norflaship_enable_remap(void); void norflaship_disable_remap(void); int norflaship_get_remap_status(void); void norflaship_dummy_others(uint32_t v); void norflaship_fetch_disable(); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_norflaship.h
C
apache-2.0
4,189
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_OVERLAY_H__ #define __HAL_OVERLAY_H__ #ifdef __cplusplus extern "C" { #endif #define HAL_OVERLAY_TEXT0_LOC __attribute__((section(".overlay_text0"))) #define HAL_OVERLAY_TEXT1_LOC __attribute__((section(".overlay_text1"))) #define HAL_OVERLAY_TEXT2_LOC __attribute__((section(".overlay_text2"))) #define HAL_OVERLAY_TEXT3_LOC __attribute__((section(".overlay_text3"))) #define HAL_OVERLAY_TEXT4_LOC __attribute__((section(".overlay_text4"))) #define HAL_OVERLAY_TEXT5_LOC __attribute__((section(".overlay_text5"))) #define HAL_OVERLAY_TEXT6_LOC __attribute__((section(".overlay_text6"))) #define HAL_OVERLAY_TEXT7_LOC __attribute__((section(".overlay_text7"))) #define HAL_OVERLAY_RODATA0_LOC __attribute__((section(".overlay_rodata0"))) #define HAL_OVERLAY_RODATA1_LOC __attribute__((section(".overlay_rodata1"))) #define HAL_OVERLAY_RODATA2_LOC __attribute__((section(".overlay_rodata2"))) #define HAL_OVERLAY_RODATA3_LOC __attribute__((section(".overlay_rodata3"))) #define HAL_OVERLAY_RODATA4_LOC __attribute__((section(".overlay_rodata4"))) #define HAL_OVERLAY_RODATA5_LOC __attribute__((section(".overlay_rodata5"))) #define HAL_OVERLAY_RODATA6_LOC __attribute__((section(".overlay_rodata6"))) #define HAL_OVERLAY_RODATA7_LOC __attribute__((section(".overlay_rodata7"))) #define HAL_OVERLAY_DATA0_LOC __attribute__((section(".overlay_data0"))) #define HAL_OVERLAY_DATA1_LOC __attribute__((section(".overlay_data1"))) #define HAL_OVERLAY_DATA2_LOC __attribute__((section(".overlay_data2"))) #define HAL_OVERLAY_DATA3_LOC __attribute__((section(".overlay_data3"))) #define HAL_OVERLAY_DATA4_LOC __attribute__((section(".overlay_data4"))) #define HAL_OVERLAY_DATA5_LOC __attribute__((section(".overlay_data5"))) #define HAL_OVERLAY_DATA6_LOC __attribute__((section(".overlay_data6"))) #define HAL_OVERLAY_DATA7_LOC __attribute__((section(".overlay_data7"))) #define INVALID_OVERLAY_ADDR 0xffffffff enum HAL_OVERLAY_ID_T { HAL_OVERLAY_ID_0, HAL_OVERLAY_ID_1, HAL_OVERLAY_ID_2, HAL_OVERLAY_ID_3, HAL_OVERLAY_ID_4, HAL_OVERLAY_ID_5, HAL_OVERLAY_ID_6, HAL_OVERLAY_ID_7, HAL_OVERLAY_ID_QTY, HAL_OVERLAY_ID_IN_CFG, }; enum HAL_OVERLAY_RET_T { HAL_OVERLAY_RET_OK, HAL_OVERLAY_RET_BAD_ID, HAL_OVERLAY_RET_IN_CFG, HAL_OVERLAY_RET_IN_USE, }; #ifndef NO_OVERLAY enum HAL_OVERLAY_RET_T hal_overlay_load(enum HAL_OVERLAY_ID_T id); enum HAL_OVERLAY_RET_T hal_overlay_unload(enum HAL_OVERLAY_ID_T id); /* * get the overlay's text start address */ uint32_t hal_overlay_get_text_address(void); /* * get the whole size of the overlay text */ uint32_t hal_overlay_get_text_all_size(void); /* * get the segment size of one overlay text */ uint32_t hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id); /* * Use the free space of one segement, this function * return the free address of space */ uint32_t hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id); /* * get the free size for one overlay text */ uint32_t hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id); /* * acquire one overlay segment */ void hal_overlay_acquire(enum HAL_OVERLAY_ID_T id); /* * release one overlay segment */ void hal_overlay_release(enum HAL_OVERLAY_ID_T id); /* * check if any overlay segment is used */ bool hal_overlay_is_used(void); #else static inline enum HAL_OVERLAY_RET_T hal_overlay_load(enum HAL_OVERLAY_ID_T id) { return HAL_OVERLAY_RET_OK; } static inline enum HAL_OVERLAY_RET_T hal_overlay_unload(enum HAL_OVERLAY_ID_T id) { return HAL_OVERLAY_RET_OK; } static inline uint32_t hal_overlay_get_text_address(void) { return INVALID_OVERLAY_ADDR;} static inline uint32_t hal_overlay_get_text_all_size(void) { return 0;} static inline uint32_t hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id) { return 0;} static inline uint32_t hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id) { return INVALID_OVERLAY_ADDR;} static inline uint32_t hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id) { return 0;} static inline void hal_overlay_acquire(enum HAL_OVERLAY_ID_T id) { return;} static inline void hal_overlay_release(enum HAL_OVERLAY_ID_T id) { return;} static inline bool hal_overlay_is_used(void) { return false;} #endif /*NO_OVERLAY*/ #ifdef __cplusplus } #endif #endif /*__HAL_OVERLAY_H__*/
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_overlay.h
C
apache-2.0
5,082
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_PSC_H__ #define __HAL_PSC_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" void hal_psc_init(void); void hal_psc_mcu_auto_power_down(void); void hal_psc_mcu_auto_power_up(void); void hal_psc_codec_enable(void); void hal_psc_codec_disable(void); void hal_psc_bt_enable(void); void hal_psc_bt_disable(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_psc.h
C
apache-2.0
1,032
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_PWM_H__ #define __HAL_PWM_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" #include "hal_cmu.h" #define MAX_PWM_VALUE 0xFFFF struct HAL_PWM_CFG_T { uint32_t freq; uint32_t ratio; bool inv; bool sleep_on; }; int hal_pwm_set_ratio_max(uint32_t max); int hal_pwm_enable(enum HAL_PWM_ID_T id, const struct HAL_PWM_CFG_T *cfg); int hal_pwm_disable(enum HAL_PWM_ID_T id); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_pwm.h
C
apache-2.0
1,127
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_RTC_H__ #define __HAL_RTC_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" struct rtc_time { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; }; typedef void (*HAL_RTC_IRQ_HANDLER_T)(struct rtc_time *time); int hal_rtc_get(struct rtc_time *time); int hal_rtc_set(struct rtc_time *time); int hal_rtc_set_alarm(struct rtc_time *time); int hal_rtc_clear_alarm(void); HAL_RTC_IRQ_HANDLER_T hal_rtc_set_irq_handler(HAL_RTC_IRQ_HANDLER_T handler); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_rtc.h
C
apache-2.0
1,245
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SDIO_H__ #define __HAL_SDIO_H__ #define SDIO_MAX_FUNCTIONS 4 /* SDIO commands type argument response */ #define SD_IO_SEND_OP_COND 5 /* bcr [23:0] OCR R4 */ #define SD_IO_RW_DIRECT 52 /* ac [31:0] See below R5 */ #define SD_IO_RW_EXTENDED 53 /* adtc [31:0] See below R5 */ /* CMD52 arguments */ #define SDIO_ARG_CMD52_READ (0<<31) #define SDIO_ARG_CMD52_WRITE (1u<<31) #define SDIO_ARG_CMD52_FUNC_SHIFT 28 #define SDIO_ARG_CMD52_FUNC_MASK 0x7 #define SDIO_ARG_CMD52_RAW_FLAG (1u<<27) #define SDIO_ARG_CMD52_REG_SHIFT 9 #define SDIO_ARG_CMD52_REG_MASK 0x1ffff #define SDIO_ARG_CMD52_DATA_SHIFT 0 #define SDIO_ARG_CMD52_DATA_MASK 0xff #define SDIO_R5_DATA(resp) ((resp)[0] & 0xff) /* CMD53 arguments */ #define SDIO_ARG_CMD53_READ (0<<31) #define SDIO_ARG_CMD53_WRITE (1u<<31) #define SDIO_ARG_CMD53_FUNC_SHIFT 28 #define SDIO_ARG_CMD53_FUNC_MASK 0x7 #define SDIO_ARG_CMD53_BLOCK_MODE (1u<<27) #define SDIO_ARG_CMD53_INCREMENT (1u<<26) #define SDIO_ARG_CMD53_REG_SHIFT 9 #define SDIO_ARG_CMD53_REG_MASK 0x1ffff #define SDIO_ARG_CMD53_LENGTH_SHIFT 0 #define SDIO_ARG_CMD53_LENGTH_MASK 0x1ff #define SDIO_ARG_CMD53_LENGTH_MAX 511 /* R5 response bits */ #define R5_COM_CRC_ERROR (1 << 15) #define R5_ILLEGAL_COMMAND (1 << 14) #define R5_ERROR (1 << 11) #define R5_FUNCTION_NUMBER (1 << 9) #define R5_OUT_OF_RANGE (1 << 8) #define R5_STATUS(x) (x & 0xCB00) #define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* * Card Common Control Registers (CCCR) */ #define SDIO_REG_CCCR_CCCR_REV 0x00 #define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */ #define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */ #define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */ #define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */ #define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */ #define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */ #define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */ #define SDIO_REG_CCCR_SD_REV 0x01 #define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */ #define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */ #define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */ #define SDIO_REG_CCCR_IO_EN 0x02 #define SDIO_REG_CCCR_IO_RDY 0x03 #define SDIO_REG_CCCR_INT_EN 0x04 /* Function/Master Interrupt Enable */ #define SDIO_REG_CCCR_INT_PEND 0x05 /* Function Interrupt Pending */ #define SDIO_REG_CCCR_IO_ABORT 0x06 /* function abort/card reset */ #define SDIO_REG_CCCR_BUS_IF 0x07 /* bus interface controls */ #define SDIO_BUS_WIDTH_1BIT 0x00 #define SDIO_BUS_WIDTH_4BIT 0x02 #define SDIO_BUS_ECSI 0x20 /* Enable continuous SPI interrupt */ #define SDIO_BUS_SCSI 0x40 /* Support continuous SPI interrupt */ #define SDIO_BUS_ASYNC_INT 0x20 #define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */ #define SDIO_REG_CCCR_CARD_CAPS 0x08 #define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */ #define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */ #define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */ #define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */ #define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */ #define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */ #define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */ #define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */ #define SDIO_REG_CCCR_CIS_PTR 0x09 /* common CIS pointer (3 bytes) */ /* Following 4 regs are valid only if SBS is set */ #define SDIO_REG_CCCR_BUS_SUSPEND 0x0c #define SDIO_REG_CCCR_FUNC_SEL 0x0d #define SDIO_REG_CCCR_EXEC_FLAG 0x0e #define SDIO_REG_CCCR_READY_FLAG 0x0f #define SDIO_REG_CCCR_FN0_BLKSIZE 0x10 /* 2bytes, 0x10~0x11 */ #define SDIO_REG_CCCR_POWER_CTRL 0x12 #define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */ #define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */ #define SDIO_REG_CCCR_SPEED 0x13 #define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */ #define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */ /* * Function Basic Registers (FBR) */ #define SDIO_REG_FBR_BASE(f) ((f) * 0x100) /* base of function f's FBRs */ #define SDIO_REG_FBR_STD_FUNC_IF 0x00 #define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */ #define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */ #define SDIO_REG_FBR_STD_IF_EXT 0x01 #define SDIO_REG_FBR_POWER 0x02 #define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */ #define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */ #define SDIO_REG_FBR_CIS 0x09 /* CIS pointer (3 bytes) */ #define SDIO_REG_FBR_CSA 0x0C /* CSA pointer (3 bytes) */ #define SDIO_REG_FBR_CSA_DATA 0x0F #define SDIO_REG_FBR_BLKSIZE 0x10 /* block size (2 bytes) */ /* SDIO CIS Tuple code */ #define CISTPL_NULL 0x00 #define CISTPL_CHECKSUM 0x10 #define CISTPL_VERS_1 0x15 #define CISTPL_ALTSTR 0x16 #define CISTPL_MANFID 0x20 #define CISTPL_FUNCID 0x21 #define CISTPL_FUNCE 0x22 #define CISTPL_SDIO_STD 0x91 #define CISTPL_SDIO_EXT 0x92 #define CISTPL_END 0xff /* SDIO device id */ #define SDIO_ANY_FUNC_ID 0xff #define SDIO_ANY_MAN_ID 0xffff #define SDIO_ANY_PROD_ID 0xffff struct sdio_device_id { uint8_t func_code; uint16_t manufacturer; uint16_t product; }; struct sdio_cccr { uint8_t sdio_version; uint8_t sd_version; uint8_t direct_cmd:1, /* Card Supports Direct Commands during data transfer only SD mode, not used for SPI mode */ multi_block:1, /* Card Supports Multi-Block */ read_wait:1, /* Card Supports Read Wait only SD mode, not used for SPI mode */ suspend_resume:1, /* Card supports Suspend/Resume only SD mode, not used for SPI mode */ s4mi:1, /* generate interrupts during a 4-bit multi-block data transfer */ e4mi:1, /* Enable the multi-block IRQ during 4-bit transfer for the SDIO card */ low_speed:1, /* Card is a Low-Speed card */ low_speed_4:1; /* 4-bit support for Low-Speed cards */ uint8_t bus_width:1, /* Support SDIO bus width, 1:4bit, 0:1bit */ cd_disable:1, /* Connect[0]/Disconnect[1] the 10K-90K ohm pull-up resistor on CD/DAT[3] (pin 1) of the card */ power_ctrl:1, /* Support Master Power Control */ high_speed:1; /* Support High-Speed */ }; struct sdio_cis { uint16_t manufacturer; uint16_t product; uint16_t func0_blk_size; uint32_t max_tran_speed; }; /* * SDIO function CIS tuple (unknown to the core) */ struct sdio_function_tuple { struct sdio_function_tuple *next; uint8_t code; uint8_t size; uint8_t *data; }; struct sdio_function; typedef void (*sdio_irq_handler_t)(struct sdio_function *); struct mmc; /* * SDIO function devices */ struct sdio_function { struct mmc *mmc; /* the card this device belongs to */ void* dev; /* the device */ sdio_irq_handler_t irq_handler; /* IRQ callback */ uint8_t num; /* function number */ uint8_t func_code; /* Standard SDIO Function interface code */ uint16_t manufacturer; /* manufacturer id */ uint16_t product; /* product id */ uint32_t max_blk_size; /* maximum block size */ uint32_t cur_blk_size; /* current block size */ uint32_t enable_timeout_val; /* max enable timeout in msec */ uint32_t buf_id_tx; int buf_id_rx; /* byte */ uint32_t hw_type; uint32_t transq_pri; uint8_t transq_irq_count; uint8_t wsm_startup_done; void* priv; }; #define sdio_func sdio_function int32_t sdio_io_send_op_cond(struct mmc *mmc, uint32_t ocr, uint32_t *cmd5_resp); int32_t sdio_io_rw_direct(struct mmc *mmc, int32_t rw, uint32_t fn, uint32_t reg_addr, uint8_t *pdata, uint8_t raw); int32_t sdio_io_rw_extended(struct mmc *mmc, int32_t rw, uint32_t fn, uint32_t addr, int32_t op_code, uint8_t *buf, uint32_t blocks, uint32_t blksize); uint8_t sdio_io_readb(struct sdio_function *func, uint32_t reg, int32_t *err); int32_t sdio_io_writeb(struct sdio_function *func, uint32_t reg, uint8_t data); uint16_t sdio_io_readw(struct sdio_function *func, uint32_t addr, int32_t *err); int32_t sdio_io_writew(struct sdio_function *func, uint16_t data, uint32_t addr); uint32_t sdio_io_readl(struct sdio_function *func, uint32_t addr, int32_t *err); int32_t sdio_io_writel(struct sdio_function *func, uint32_t data, uint32_t addr); int32_t sdio_io_read_block(struct sdio_function *func, uint32_t addr, uint8_t *buf, uint32_t len); int32_t sdio_io_write_block(struct sdio_function *func, uint32_t addr, uint8_t *buf, uint32_t len); unsigned int sdio_align_size(struct sdio_function *func, unsigned int sz); int32_t sdio_attach_irq(struct sdio_function *func, sdio_irq_handler_t handler); int32_t sdio_detach_irq(struct sdio_function *func); int32_t sdio_enable_func(struct sdio_function *func); int32_t sdio_disable_func(struct sdio_function *func); int32_t sdio_set_block_size(struct sdio_function *func, uint32_t blksize); uint32_t mmc_detect_sdio(struct mmc *mmc); void hal_sdio_enable_irq(struct sdio_function *func); void hal_sdio_disable_irq(struct sdio_function *func); void hal_sdio_check_irq(struct sdio_function *func); #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sdio.h
C
apache-2.0
12,025
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _HAL_SDMMC_H_ #define _HAL_SDMMC_H_ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "hal_sdio.h" enum HAL_SDMMC_ID_T { HAL_SDMMC_ID_0 = 0, HAL_SDMMC_ID_NUM, }; typedef void (*HAL_SDMMC_DELAY_FUNC)(uint32_t ms); /* hal api */ HAL_SDMMC_DELAY_FUNC hal_sdmmc_set_delay_func(HAL_SDMMC_DELAY_FUNC new_func); int32_t hal_sdmmc_open(enum HAL_SDMMC_ID_T id); void hal_sdmmc_info(enum HAL_SDMMC_ID_T id, uint32_t *sector_count, uint32_t *sector_size); uint32_t hal_sdmmc_read_blocks(enum HAL_SDMMC_ID_T id, uint32_t start_block, uint32_t block_count, uint8_t* dest); uint32_t hal_sdmmc_write_blocks(enum HAL_SDMMC_ID_T id, uint32_t start_block, uint32_t block_count, uint8_t* src); void hal_sdmmc_close(enum HAL_SDMMC_ID_T id); void hal_sdmmc_dump(enum HAL_SDMMC_ID_T id); int hal_sdmmc_enable_detecter(enum HAL_SDMMC_ID_T id,void (* cb)(uint8_t)); void hal_sdmmc_init_vars(); uint32_t hal_sdmmc_get_bus_width(enum HAL_SDMMC_ID_T id); uint32_t hal_sdmmc_get_clock(enum HAL_SDMMC_ID_T id); #ifdef __cplusplus } #endif #endif /* _HAL_SDMMC_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sdmmc.h
C
apache-2.0
1,733
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SEC_ENG_H__ #define __HAL_SEC_ENG_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "stdbool.h" #include "stdint.h" #include "hal_dma.h" enum HAL_SE_RET_T { HAL_SE_OK, HAL_SE_ERR, HAL_SE_ALREADY_OPENED, HAL_SE_NOT_OPENED, HAL_SE_ENG_BUSY, HAL_SE_DMA_BUSY, HAL_SE_CFG_NULL, HAL_SE_INPUT_NULL, HAL_SE_OUTPUT_NULL, HAL_SE_KEY_NULL, HAL_SE_IV_NULL, HAL_SE_KEY2_NULL, HAL_SE_BAD_INPUT_LEN, HAL_SE_BAD_OUTPUT_LEN, HAL_SE_BAD_KEY_LEN, HAL_SE_BAD_AES_MODE, HAL_SE_BAD_AES_MODULAR, HAL_SE_BAD_MODE, HAL_SE_BAD_OP, }; enum HAL_SE_AES_MODE_T { HAL_SE_AES_EBC = 0, HAL_SE_AES_CBC = 1, HAL_SE_AES_CTR = 2, HAL_SE_AES_XTS = 3, HAL_SE_AES_KEY_WRAP = 4, HAL_SE_AES_MODE_QTY, }; enum HAL_SE_DONE_ERR_T { HAL_SE_DONE_OK = 0, HAL_SE_DONE_ERR_DMA_IN, HAL_SE_DONE_ERR_DMA_OUT, HAL_SE_DONE_ERR_DMA_IN_REMAIN, HAL_SE_DONE_ERR_DMA_OUT_REMAIN, HAL_SE_DONE_ERR_ENG_ERR1, HAL_SE_DONE_ERR_ENG_ERR2, HAL_SE_DONE_ERR_ENG_ERR1_ERR2, }; enum HAL_SE_HASH_MODE_T { HAL_SE_HASH_SHA1 = 0, HAL_SE_HASH_SHA256, HAL_SE_HASH_SHA224, HAL_SE_HASH_MD5, HAL_SE_HASH_SHA512, HAL_SE_HASH_SHA384, HAL_SE_HASH_QTY, }; typedef void (*HAL_SC_DONE_HANDLER_T)(void *buf, uint32_t len, enum HAL_SE_DONE_ERR_T err); struct HAL_SE_AES_CFG_T { enum HAL_SE_AES_MODE_T mode; const void *key; uint16_t key_len; uint8_t ctr_modular; const void *key2; const void *iv; const void *in; uint32_t in_len; void *out; uint32_t out_len; HAL_SC_DONE_HANDLER_T done_hdlr; }; struct HAL_SE_HASH_CFG_T { const void *in; uint32_t in_len; HAL_SC_DONE_HANDLER_T done_hdlr; }; enum HAL_SE_RET_T hal_se_open(void); enum HAL_SE_RET_T hal_se_close(void); enum HAL_SE_RET_T hal_se_aes_encrypt(const struct HAL_SE_AES_CFG_T *cfg); enum HAL_SE_RET_T hal_se_aes_decrypt(const struct HAL_SE_AES_CFG_T *cfg); int hal_se_aes_busy(void); enum HAL_SE_RET_T hal_se_aes_reset(void); enum HAL_SE_RET_T hal_se_hash_init(enum HAL_SE_HASH_MODE_T mode); enum HAL_SE_RET_T hal_se_hash_update(const struct HAL_SE_HASH_CFG_T *cfg); enum HAL_SE_RET_T hal_se_hash_final(const struct HAL_SE_HASH_CFG_T *cfg, uint64_t total_in_len); enum HAL_SE_RET_T hal_se_hash(enum HAL_SE_HASH_MODE_T mode, const struct HAL_SE_HASH_CFG_T *cfg); enum HAL_SE_RET_T hal_se_hash_get_digest(void *out, uint32_t out_len, uint32_t *real_len); int hal_se_hash_busy(void); enum HAL_SE_RET_T hal_se_hash_reset(void); enum HAL_SE_RET_T hal_se_hmac_init(enum HAL_SE_HASH_MODE_T mode, const void *key, uint32_t key_len); enum HAL_SE_RET_T hal_se_hmac_update(const struct HAL_SE_HASH_CFG_T *cfg); enum HAL_SE_RET_T hal_se_hmac_final(const struct HAL_SE_HASH_CFG_T *cfg, uint64_t total_in_len); enum HAL_SE_RET_T hal_se_hmac(enum HAL_SE_HASH_MODE_T mode, const void *key, uint32_t key_len, const struct HAL_SE_HASH_CFG_T *cfg); enum HAL_SE_RET_T hal_se_hmac_get_digest(void *out, uint32_t out_len, uint32_t *real_len); int hal_se_hmac_busy(void); enum HAL_SE_RET_T hal_se_hmac_reset(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sec_eng.h
C
apache-2.0
3,975
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SENSOR_HUB_H__ #define __HAL_SENSOR_HUB_H__ #ifdef __cplusplus extern "C" { #endif #include "hal_dma.h" #include "hal_gpio.h" enum HAL_SENSOR_ENGINE_ID_T { HAL_SENSOR_ENGINE_ID_0 = 0, HAL_SENSOR_ENGINE_ID_1, HAL_SENSOR_ENGINE_ID_2, HAL_SENSOR_ENGINE_ID_3, HAL_SENSOR_ENGINE_ID_QTY, }; enum HAL_SENSOR_ENGINE_TRIGGER_T { HAL_SENSOR_ENGINE_TRIGGER_TIMER = 0, HAL_SENSOR_ENGINE_TRIGGER_GPIO, HAL_SENSOR_ENGINE_TRIGGER_QTY, }; enum HAL_SENSOR_ENGINE_DEVICE_T { HAL_SENSOR_ENGINE_DEVICE_I2C0 = 0, HAL_SENSOR_ENGINE_DEVICE_I2C1, HAL_SENSOR_ENGINE_DEVICE_SPI0 = 4, HAL_SENSOR_ENGINE_DEVICE_SPI1, HAL_SENSOR_ENGINE_DEVICE_SPI2, }; typedef void (*HAL_SENSOR_ENG_HANDLER_T)(enum HAL_SENSOR_ENGINE_ID_T id, enum HAL_SENSOR_ENGINE_DEVICE_T device, const uint8_t *buf, uint32_t len); struct HAL_SENSOR_ENGINE_CFG_T { enum HAL_SENSOR_ENGINE_ID_T id; enum HAL_SENSOR_ENGINE_DEVICE_T device; enum HAL_SENSOR_ENGINE_TRIGGER_T trigger_type; enum HAL_GPIO_PIN_T trigger_gpio; uint32_t period_us; struct HAL_DMA_CH_CFG_T *tx_dma_cfg; struct HAL_DMA_CH_CFG_T *rx_dma_cfg; uint16_t device_address; uint16_t rx_burst_len; uint8_t rx_burst_cnt; uint8_t data_to_vad; HAL_SENSOR_ENG_HANDLER_T handler; }; int hal_sensor_engine_open(const struct HAL_SENSOR_ENGINE_CFG_T *cfg); int hal_sensor_engine_close(enum HAL_SENSOR_ENGINE_ID_T id); void hal_sensor_process_rx_buffer(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sensor_eng.h
C
apache-2.0
2,167
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SLEEP_H__ #define __HAL_SLEEP_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" enum HAL_CPU_WAKE_LOCK_USER_T { HAL_CPU_WAKE_LOCK_USER_RTOS, HAL_CPU_WAKE_LOCK_USER_EXTERNAL, HAL_CPU_WAKE_LOCK_USER_AUDIOFLINGER, HAL_CPU_WAKE_LOCK_USER_3, HAL_CPU_WAKE_LOCK_USER_4, HAL_CPU_WAKE_LOCK_USER_5, HAL_CPU_WAKE_LOCK_USER_6, HAL_CPU_WAKE_LOCK_USER_7, HAL_CPU_WAKE_LOCK_USER_8, HAL_CPU_WAKE_LOCK_USER_9, HAL_CPU_WAKE_LOCK_USER_10, HAL_CPU_WAKE_LOCK_USER_11, HAL_CPU_WAKE_LOCK_USER_12, HAL_CPU_WAKE_LOCK_USER_13, HAL_CPU_WAKE_LOCK_USER_14, HAL_CPU_WAKE_LOCK_USER_15, HAL_CPU_WAKE_LOCK_USER_16, HAL_CPU_WAKE_LOCK_USER_17, HAL_CPU_WAKE_LOCK_USER_18, HAL_CPU_WAKE_LOCK_USER_19, HAL_CPU_WAKE_LOCK_USER_20, HAL_CPU_WAKE_LOCK_USER_21, HAL_CPU_WAKE_LOCK_USER_22, HAL_CPU_WAKE_LOCK_USER_23, HAL_CPU_WAKE_LOCK_USER_24, HAL_CPU_WAKE_LOCK_USER_25, HAL_CPU_WAKE_LOCK_USER_26, HAL_CPU_WAKE_LOCK_USER_27, HAL_CPU_WAKE_LOCK_USER_28, HAL_CPU_WAKE_LOCK_USER_29, HAL_CPU_WAKE_LOCK_USER_30, HAL_CPU_WAKE_LOCK_USER_31, HAL_CPU_WAKE_LOCK_USER_QTY }; enum HAL_SYS_WAKE_LOCK_USER_T { HAL_SYS_WAKE_LOCK_USER_INTERSYS, HAL_SYS_WAKE_LOCK_USER_INTERSYS_HCI, HAL_SYS_WAKE_LOCK_USER_2, HAL_SYS_WAKE_LOCK_USER_3, HAL_SYS_WAKE_LOCK_USER_4, HAL_SYS_WAKE_LOCK_USER_TRANSQ, HAL_SYS_WAKE_LOCK_USER_6, HAL_SYS_WAKE_LOCK_USER_7, HAL_SYS_WAKE_LOCK_USER_8, HAL_SYS_WAKE_LOCK_USER_9, HAL_SYS_WAKE_LOCK_USER_10, HAL_SYS_WAKE_LOCK_USER_11, HAL_SYS_WAKE_LOCK_USER_12, HAL_SYS_WAKE_LOCK_USER_13, HAL_SYS_WAKE_LOCK_USER_14, HAL_SYS_WAKE_LOCK_USER_15, HAL_SYS_WAKE_LOCK_USER_16, HAL_SYS_WAKE_LOCK_USER_17, HAL_SYS_WAKE_LOCK_USER_18, HAL_SYS_WAKE_LOCK_USER_19, HAL_SYS_WAKE_LOCK_USER_20, HAL_SYS_WAKE_LOCK_USER_21, HAL_SYS_WAKE_LOCK_USER_22, HAL_SYS_WAKE_LOCK_USER_23, HAL_SYS_WAKE_LOCK_USER_24, HAL_SYS_WAKE_LOCK_USER_25, HAL_SYS_WAKE_LOCK_USER_26, HAL_SYS_WAKE_LOCK_USER_27, HAL_SYS_WAKE_LOCK_USER_28, HAL_SYS_WAKE_LOCK_USER_29, HAL_SYS_WAKE_LOCK_USER_30, HAL_SYS_WAKE_LOCK_USER_31, HAL_SYS_WAKE_LOCK_USER_QTY }; enum HAL_CHIP_WAKE_LOCK_USER_T { HAL_CHIP_WAKE_LOCK_USER_ANC, HAL_CHIP_WAKE_LOCK_USER_1, HAL_CHIP_WAKE_LOCK_USER_2, HAL_CHIP_WAKE_LOCK_USER_3, HAL_CHIP_WAKE_LOCK_USER_4, HAL_CHIP_WAKE_LOCK_USER_5, HAL_CHIP_WAKE_LOCK_USER_6, HAL_CHIP_WAKE_LOCK_USER_7, HAL_CHIP_WAKE_LOCK_USER_8, HAL_CHIP_WAKE_LOCK_USER_9, HAL_CHIP_WAKE_LOCK_USER_10, HAL_CHIP_WAKE_LOCK_USER_11, HAL_CHIP_WAKE_LOCK_USER_12, HAL_CHIP_WAKE_LOCK_USER_13, HAL_CHIP_WAKE_LOCK_USER_14, HAL_CHIP_WAKE_LOCK_USER_15, HAL_CHIP_WAKE_LOCK_USER_16, HAL_CHIP_WAKE_LOCK_USER_17, HAL_CHIP_WAKE_LOCK_USER_18, HAL_CHIP_WAKE_LOCK_USER_19, HAL_CHIP_WAKE_LOCK_USER_20, HAL_CHIP_WAKE_LOCK_USER_21, HAL_CHIP_WAKE_LOCK_USER_22, HAL_CHIP_WAKE_LOCK_USER_23, HAL_CHIP_WAKE_LOCK_USER_24, HAL_CHIP_WAKE_LOCK_USER_25, HAL_CHIP_WAKE_LOCK_USER_26, HAL_CHIP_WAKE_LOCK_USER_27, HAL_CHIP_WAKE_LOCK_USER_28, HAL_CHIP_WAKE_LOCK_USER_29, HAL_CHIP_WAKE_LOCK_USER_30, HAL_CHIP_WAKE_LOCK_USER_31, HAL_CHIP_WAKE_LOCK_USER_QTY }; enum HAL_SLEEP_HOOK_USER_T { HAL_SLEEP_HOOK_USER_NVRECORD = 0, HAL_SLEEP_HOOK_USER_OTA, HAL_SLEEP_HOOK_NORFLASH_API, HAL_SLEEP_HOOK_DUMP_LOG, HAL_SLEEP_HOOK_USER_QTY }; enum HAL_DEEP_SLEEP_HOOK_USER_T { HAL_DEEP_SLEEP_HOOK_USER_WDT = 0, HAL_DEEP_SLEEP_HOOK_USER_NVRECORD, HAL_DEEP_SLEEP_HOOK_USER_OTA, HAL_DEEP_SLEEP_HOOK_NORFLASH_API, HAL_DEEP_SLEEP_HOOK_DUMP_LOG, HAL_DEEP_SLEEP_HOOK_USER_QTY }; enum HAL_SLEEP_STATUS_T { HAL_SLEEP_STATUS_DEEP, HAL_SLEEP_STATUS_LIGHT, }; struct CPU_USAGE_T { uint8_t busy; uint8_t light_sleep; uint8_t sys_deep_sleep; uint8_t chip_deep_sleep; }; typedef int (*HAL_SLEEP_HOOK_HANDLER)(void); typedef int (*HAL_DEEP_SLEEP_HOOK_HANDLER)(void); int hal_sleep_irq_pending(void); int hal_sleep_specific_irq_pending(const uint32_t *irq, uint32_t cnt); enum HAL_SLEEP_STATUS_T hal_sleep_enter_sleep(void); enum HAL_SLEEP_STATUS_T hal_sleep_light_sleep(void); int hal_sleep_set_sleep_hook(enum HAL_SLEEP_HOOK_USER_T user, HAL_SLEEP_HOOK_HANDLER handler); int hal_sleep_set_deep_sleep_hook(enum HAL_DEEP_SLEEP_HOOK_USER_T user, HAL_DEEP_SLEEP_HOOK_HANDLER handler); int hal_cpu_wake_lock(enum HAL_CPU_WAKE_LOCK_USER_T user); int hal_cpu_wake_unlock(enum HAL_CPU_WAKE_LOCK_USER_T user); int hal_sys_wake_lock(enum HAL_SYS_WAKE_LOCK_USER_T user); int hal_sys_wake_unlock(enum HAL_SYS_WAKE_LOCK_USER_T user); int hal_chip_wake_lock(enum HAL_CHIP_WAKE_LOCK_USER_T user); int hal_chip_wake_unlock(enum HAL_CHIP_WAKE_LOCK_USER_T user); void hal_sleep_start_stats(uint32_t stats_interval_ms, uint32_t trace_interval_ms); int hal_sleep_get_stats(struct CPU_USAGE_T *usage); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sleep.h
C
apache-2.0
5,711
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SLEEP_MCU_PD_H__ #define __HAL_SLEEP_MCU_PD_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" void hal_sleep_mcu_power_down(void); void hal_sleep_mcu_power_up(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sleep_mcu_pd.h
C
apache-2.0
890
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SPI_H__ #define __HAL_SPI_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" enum HAL_SPI_MOD_CLK_SEL_T { HAL_SPI_MOD_CLK_SEL_NONE, HAL_SPI_MOD_CLK_SEL_OSC, HAL_SPI_MOD_CLK_SEL_OSC_X2, HAL_SPI_MOD_CLK_SEL_PLL, }; struct HAL_SPI_CTRL_T { uint32_t sspcr0_tx; uint32_t sspcr0_rx; uint16_t sspcr1; uint16_t sspcpsr; uint16_t sspdmacr; uint16_t ssprxcr_tx; uint16_t ssprxcr_rx; enum HAL_SPI_MOD_CLK_SEL_T clk_sel; }; struct HAL_SPI_CFG_T { uint32_t rate; bool clk_delay_half :1; bool clk_polarity :1; bool slave :1; bool dma_rx :1; bool dma_tx :1; bool rx_sep_line :1; uint8_t cs; uint8_t tx_bits; uint8_t rx_bits; uint8_t rx_frame_bits; }; typedef void (*HAL_SPI_DMA_HANDLER_T)(int error); //------------------------------------------------------------ // SPI common functions //------------------------------------------------------------ int hal_spi_init_ctrl(const struct HAL_SPI_CFG_T *cfg, struct HAL_SPI_CTRL_T *ctrl); //------------------------------------------------------------ // SPI ROM functions //------------------------------------------------------------ int hal_ispi_rom_open(const struct HAL_SPI_CFG_T *cfg); void hal_ispi_rom_activate_cs(uint32_t cs); int hal_ispi_rom_busy(void); int hal_ispi_rom_send(const void *data, uint32_t len); int hal_ispi_rom_recv(const void *cmd, void *data, uint32_t len); int hal_spiphy_rom_open(const struct HAL_SPI_CFG_T *cfg); void hal_spiphy_rom_close(void); int hal_spiphy_rom_busy(void); int hal_spiphy_rom_send(const void *data, uint32_t len); int hal_spiphy_rom_recv(const void *cmd, void *data, uint32_t len); //------------------------------------------------------------ // ISPI functions //------------------------------------------------------------ int hal_ispi_open(const struct HAL_SPI_CFG_T *cfg); int hal_ispi_close(uint32_t cs); void hal_ispi_activate_cs(uint32_t cs); int hal_ispi_busy(void); int hal_ispi_send(const void *data, uint32_t len); int hal_ispi_recv(const void *cmd, void *data, uint32_t len); int hal_ispi_dma_send(const void *data, uint32_t len, HAL_SPI_DMA_HANDLER_T handler); int hal_ispi_dma_recv(const void *cmd, void *data, uint32_t len, HAL_SPI_DMA_HANDLER_T handler); void hal_ispi_stop_dma_send(void); void hal_ispi_stop_dma_recv(void); //------------------------------------------------------------ // SPI peripheral functions //------------------------------------------------------------ int hal_spi_open(const struct HAL_SPI_CFG_T *cfg); int hal_spi_close(uint32_t cs); int hal_spi_activate_cs(uint32_t cs); int hal_spi_busy(void); #if 1 // conflict with alios things, need rename int hal_spi_send_nickname(const void *data, uint32_t len); int hal_spi_recv_nickname(const void *cmd, void *data, uint32_t len); #define hal_spi_send hal_spi_send_nickname #define hal_spi_recv hal_spi_recv_nickname #else int hal_spi_send(const void *data, uint32_t len); int hal_spi_recv(const void *cmd, void *data, uint32_t len); #endif int hal_spi_dma_send(const void *data, uint32_t len, HAL_SPI_DMA_HANDLER_T handler); int hal_spi_dma_recv(const void *cmd, void *data, uint32_t len, HAL_SPI_DMA_HANDLER_T handler); int hal_spi_no_dma_send(const void *data, uint32_t len); int hal_spi_no_dma_recv(const void *cmd, void *data, uint32_t len ); void hal_spi_stop_dma_send(void); void hal_spi_stop_dma_recv(void); int hal_spi_enable_and_send(const struct HAL_SPI_CTRL_T *ctrl, const void *data, uint32_t len); int hal_spi_enable_and_recv(const struct HAL_SPI_CTRL_T *ctrl, const void *cmd, void *data, uint32_t len); //------------------------------------------------------------ // SPI LCD functions //------------------------------------------------------------ int hal_spilcd_open(const struct HAL_SPI_CFG_T *cfg); int hal_spilcd_close(uint32_t cs); int hal_spilcd_activate_cs(uint32_t cs); int hal_spilcd_busy(void); int hal_spilcd_send(const void *data, uint32_t len); int hal_spilcd_recv(const void *cmd, void *data, uint32_t len); int hal_spilcd_dma_send(const void *data, uint32_t len, HAL_SPI_DMA_HANDLER_T handler); int hal_spilcd_dma_recv(const void *cmd, void *data, uint32_t len, HAL_SPI_DMA_HANDLER_T handler); void hal_spilcd_stop_dma_send(void); void hal_spilcd_stop_dma_recv(void); int hal_spilcd_set_data_mode(void); int hal_spilcd_set_cmd_mode(void); int hal_spilcd_enable_and_send(const struct HAL_SPI_CTRL_T *ctrl, const void *data, uint32_t len); int hal_spilcd_enable_and_recv(const struct HAL_SPI_CTRL_T *ctrl, const void *cmd, void *data, uint32_t len); //------------------------------------------------------------ // SPI PHY functions //------------------------------------------------------------ int hal_spiphy_open(const struct HAL_SPI_CFG_T *cfg); int hal_spiphy_close(uint32_t cs); void hal_spiphy_activate_cs(uint32_t cs); int hal_spiphy_busy(void); int hal_spiphy_send(const void *data, uint32_t len); int hal_spiphy_recv(const void *cmd, void *data, uint32_t len); //------------------------------------------------------------ // SPI DPD functions //------------------------------------------------------------ int hal_spidpd_open(const struct HAL_SPI_CFG_T *cfg); int hal_spidpd_close(uint32_t cs); int hal_spidpd_busy(void); int hal_spidpd_send(const void *data, uint32_t len); int hal_spidpd_recv(const void *cmd, void *data, uint32_t len); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_spi.h
C
apache-2.0
6,154
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_SYSFREQ_H__ #define __HAL_SYSFREQ_H__ #ifdef __cplusplus extern "C" { #endif #include "hal_cmu.h" enum HAL_SYSFREQ_USER_T { HAL_SYSFREQ_USER_INIT, HAL_SYSFREQ_USER_OVERLAY, HAL_SYSFREQ_USER_USB, HAL_SYSFREQ_USER_BT, HAL_SYSFREQ_USER_ANC, HAL_SYSFREQ_USER_WIFI, HAL_SYSFREQ_USER_APP_0, HAL_SYSFREQ_USER_APP_1, HAL_SYSFREQ_USER_APP_2, HAL_SYSFREQ_USER_APP_3, HAL_SYSFREQ_USER_APP_4, HAL_SYSFREQ_USER_APP_5, HAL_SYSFREQ_USER_APP_6, HAL_SYSFREQ_USER_APP_7, HAL_SYSFREQ_USER_APP_8, HAL_SYSFREQ_USER_APP_9, HAL_SYSFREQ_USER_APP_10, HAL_SYSFREQ_USER_APP_11, HAL_SYSFREQ_USER_APP_12, HAL_SYSFREQ_USER_APP_13, HAL_SYSFREQ_USER_APP_14, HAL_SYSFREQ_USER_APP_15, HAL_SYSFREQ_USER_QTY }; void hal_sysfreq_set_min_freq(enum HAL_CMU_FREQ_T freq); int hal_sysfreq_req(enum HAL_SYSFREQ_USER_T user, enum HAL_CMU_FREQ_T freq); enum HAL_CMU_FREQ_T hal_sysfreq_get(void); enum HAL_CMU_FREQ_T hal_sysfreq_get_hw_freq(void); int hal_sysfreq_busy(void); void hal_sysfreq_print(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_sysfreq.h
C
apache-2.0
1,767
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_TIMER_H__ #define __HAL_TIMER_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "hal_cmu.h" // ============================================================================= // Slow Timer (Default Timer) #ifdef FPGA #define SYS_TIMER_TICK_HZ_NOMINAL (32000) #else #define SYS_TIMER_TICK_HZ_NOMINAL (16000) #endif // #if (SYS_TIMER_TICK_HZ_NOMINAL % 1000) // #error "Bad SYS_TIMER_TICK_HZ_NOMINAL configuration" // #endif #ifdef CALIB_SLOW_TIMER #define SYS_TIMER_TICK_HZ hal_sys_timer_systick_hz() #define __MS_TO_TICKS(ms) hal_sys_timer_ms_to_ticks(ms) #define __US_TO_TICKS(us) hal_sys_timer_us_to_ticks(us) #define __TICKS_TO_MS(tick) hal_sys_timer_ticks_to_ms(tick) #define __TICKS_TO_US(tick) hal_sys_timer_ticks_to_us(tick) #else #define SYS_TIMER_TICK_HZ SYS_TIMER_TICK_HZ_NOMINAL #define __MS_TO_TICKS(ms) ((ms) * ((uint32_t)SYS_TIMER_TICK_HZ / 1000)) #define __US_TO_TICKS(us) (((us) * ((uint32_t)SYS_TIMER_TICK_HZ / 1000) + 1000 - 1) / 1000 + 1) #define __TICKS_TO_MS(tick) ((tick) / ((uint32_t)SYS_TIMER_TICK_HZ / 1000)) #define __TICKS_TO_US(tick) ((tick) * 1000 / ((uint32_t)SYS_TIMER_TICK_HZ / 1000)) #endif /* * * This is very confused with the common sense, because * MS_TO_TICKS is always refer to ms converted to os ticks * but here it is converted to a hardware timer's tick * which ticks is 16K one second; * * The same is as US_TO_TICKS, TICKS_TO_MS series; * They are reserved for historic reason; * * Note, don't use these macros, use MS_TO_HWTICKS/US_TO_HWTICKS/HWTICKS_TO_MS * alternately */ #define MS_TO_TICKS(ms) __MS_TO_TICKS(ms) #define US_TO_TICKS(us) __US_TO_TICKS(us) #define TICKS_TO_MS(tick) __TICKS_TO_MS(tick) #define TICKS_TO_US(tick) __TICKS_TO_US(tick) #define MS_TO_HWTICKS(ms) __MS_TO_TICKS(ms) #define US_TO_HWTICKS(us) __US_TO_TICKS(us) #define HWTICKS_TO_MS(tick) __TICKS_TO_MS(tick) #define HWTICKS_TO_US(tick) __TICKS_TO_US(tick) #define GET_CURRENT_TICKS() hal_sys_timer_get() #define GET_CURRENT_MS() TICKS_TO_MS(GET_CURRENT_TICKS()) uint32_t hal_systick_timer_get(void); void hal_sys_timer_open(void); uint32_t hal_sys_timer_get(void); uint32_t hal_sys_timer_get_in_sleep(void); uint32_t hal_sys_timer_get_max(void); void hal_sys_timer_delay(uint32_t ticks); void hal_sys_timer_delay_in_sleep(uint32_t ticks); void hal_sys_timer_delay_us(uint32_t us); void hal_sys_timer_delay_ns(uint32_t ns); uint32_t hal_sys_timer_calc_cpu_freq(uint32_t interval_ms, int high_res); uint32_t flash_hal_sys_timer_get(void); void flash_hal_sys_timer_delay(uint32_t ticks); void hal_sys_timer_calib_start(void); int hal_sys_timer_calib_end(void); void hal_sys_timer_calib(void); uint32_t hal_sys_timer_systick_hz(void); uint32_t hal_sys_timer_ms_to_ticks(uint32_t ms); uint32_t hal_sys_timer_us_to_ticks(uint32_t us); uint32_t hal_sys_timer_ticks_to_ms(uint32_t tick); uint32_t hal_sys_timer_ticks_to_us(uint32_t tick); uint32_t hal_timer_get_passed_ticks(uint32_t curr_ticks, uint32_t prev_ticks); //============================================================================= // Fast Timer #define CONFIG_FAST_SYSTICK_HZ (hal_cmu_get_crystal_freq() / 4) #define MS_TO_FAST_TICKS(ms) ((uint32_t)(ms) * (CONFIG_FAST_SYSTICK_HZ / 1000)) #define US_TO_FAST_TICKS(us) ((uint32_t)(us) * (CONFIG_FAST_SYSTICK_HZ / 1000 / 100) / 10) #define NS_TO_FAST_TICKS(ns) ((uint32_t)(ns) * (CONFIG_FAST_SYSTICK_HZ / 1000 / 100) / 10 / 1000) #define FAST_TICKS_TO_MS(tick) ((uint32_t)(tick) / (CONFIG_FAST_SYSTICK_HZ / 1000)) #define FAST_TICKS_TO_US(tick) ((uint32_t)(tick) * 10 / (CONFIG_FAST_SYSTICK_HZ / 1000 / 100)) #define FAST_TICKS_TO_NS(tick) ((uint32_t)(tick) * 10 * 1000 / (CONFIG_FAST_SYSTICK_HZ / 1000 / 100)) uint32_t hal_fast_sys_timer_get(void); #ifndef RTOS int osDelay(uint32_t ms); #endif typedef void (*SYS_TICK_HANDLER)(void); void hal_systick_timer_open(uint32_t freq, SYS_TICK_HANDLER handler); void hal_systick_timer_start(); void hal_systick_timer_stop(); void hal_timer2_start(uint32_t ticks); void hal_timer2_stop(void); void hal_timer2_open(void(*handler)(void)); void hal_timer2_close(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_timer.h
C
apache-2.0
5,079
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_TIMER_RAW_H__ #define __HAL_TIMER_RAW_H__ #ifdef __cplusplus extern "C" { #endif #ifndef IGNORE_HAL_TIMER_RAW_API_CHECK #if !(defined(ROM_BUILD) || defined(SIMU)) #error "Raw timer API can only be used in rom or simulation environment!" #endif #endif #include "hal_timer.h" #define HAL_TIMER_LOAD_DELTA 1 enum HAL_TIMER_TYPE_T { HAL_TIMER_TYPE_FREERUNNING = 0, HAL_TIMER_TYPE_ONESHOT, HAL_TIMER_TYPE_PERIODIC, HAL_TIMER_TYPE_QTY }; typedef void (*HAL_TIMER_IRQ_HANDLER_T)(uint32_t elapsed); void hal_timer_setup(enum HAL_TIMER_TYPE_T type, HAL_TIMER_IRQ_HANDLER_T handler); #if 1 // conflict with alios things, need rename void hal_timer_start_nickname(uint32_t load); void hal_timer_stop_nickname(void); #define hal_timer_start hal_timer_start_nickname #define hal_timer_stop hal_timer_stop_nickname #else void hal_timer_start(uint32_t load); void hal_timer_stop(void); #endif void hal_timer_continue(void); int hal_timer_is_enabled(void); void hal_timer_reload(uint32_t load); uint32_t hal_timer_get(void); uint32_t hal_timer_get_overrun_time(void); int hal_timer_irq_active(void); int hal_timer_irq_pending(void); uint32_t hal_timer_get_elapsed_time(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_timer_raw.h
C
apache-2.0
1,906
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_TRACE_H__ #define __HAL_TRACE_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #if 0 #define AUDIO_DEBUG #define AUDIO_DEBUG_V0_1_0 #define INTERSYS_RAW_DATA_ONLY #ifdef AUDIO_DEBUG #undef TRACE_BAUD_RATE #define TRACE_BAUD_RATE 2000000 #endif #endif #if (defined(AUDIO_DEBUG) && !defined(AUDIO_DEBUG_V0_1_0)) #define NO_REL_TRACE #endif #if (defined(AUDIO_DEBUG) && !defined(AUDIO_DEBUG_V0_1_0)) || \ defined(INTERSYS_RAW_DATA_ONLY) #define NO_TRACE #endif #if defined(__BT_DEBUG_TPORTS__) || defined(AUDIO_DEBUG_V0_1_0) #define HAL_TRACE_RX_ENABLE #define CRASH_REBOOT #endif /* * Total number of core registers stored */ #define CRASH_DUMP_REGISTERS_NUM 17 #define CRASH_DUMP_REGISTERS_NUM_BYTES ((CRASH_DUMP_REGISTERS_NUM)*4) /* * Number bytes to store from stack * - this is total, not per PSP/MSP */ #define CRASH_DUMP_STACK_NUM_BYTES 384 enum PRINTF_FLAG_T { PRINTF_FLAG_LINE_FEED = (1 << 0), PRINTF_FLAG_TIME_STAMP = (1 << 1), PRINTF_FLAG_CHECK_CRLR = (1 << 2), }; #if defined(TRACE_STR_SECTION) && !(defined(ROM_BUILD) || defined(PROGRAMMER) || defined(FPGA)) #define CONCAT_(x,y) x##y #define CONCATS(x,y) CONCAT_(x,y) #define __trcname CONCATS(__trc, __LINE__) #define TRC_STR_LOC __attribute__((section(TO_STRING(CONCATS(.trc_str.,__LINE__))))) #define TRC_STR(s) (({ static const char TRC_STR_LOC __trcname[] = (s); __trcname; })) #else #define TRC_STR_LOC #define TRC_STR(s) ((char *)s) #endif #define TRACE_DUMMY(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #if (defined(DEBUG) || defined(REL_TRACE_ENABLE)) && !defined(NO_REL_TRACE) #define REL_TRACE(str, ...) hal_trace_printf(TRC_STR(str), ##__VA_ARGS__) #define REL_TRACE_IMM(str, ...) hal_trace_printf_imm(str, ##__VA_ARGS__) #define REL_TRACE_NOCRLF(str, ...) hal_trace_printf_without_crlf(str, ##__VA_ARGS__) #define REL_TRACE_NOTS(str, ...) hal_trace_printf_without_ts(TRC_STR(str), ##__VA_ARGS__) #define REL_TRACE_IMM_NOTS(str, ...) hal_trace_printf_imm_without_ts(str, ##__VA_ARGS__) #define REL_TRACE_NOCRLF_NOTS(str, ...) hal_trace_printf_without_crlf_ts(str, ##__VA_ARGS__) #define REL_TRACE_OUTPUT(str, len) hal_trace_output(str, len) #define REL_TRACE_FLUSH() hal_trace_flush_buffer() #define REL_FUNC_ENTRY_TRACE() hal_trace_printf(__FUNCTION__) #define REL_DUMP8(str, buf, cnt) hal_trace_dump(str, sizeof(uint8_t), cnt, buf) #define REL_DUMP16(str, buf, cnt) hal_trace_dump(str, sizeof(uint16_t), cnt, buf) #define REL_DUMP32(str, buf, cnt) hal_trace_dump(str, sizeof(uint32_t), cnt, buf) #else #define REL_TRACE(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define REL_TRACE_IMM(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define REL_TRACE_NOCRLF(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define REL_TRACE_NOTS(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define REL_TRACE_IMM_NOTS(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define REL_TRACE_NOCRLF_NOTS(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define REL_TRACE_OUTPUT(str, len) hal_trace_dummy((const char *)str, len) #define REL_TRACE_FLUSH() hal_trace_dummy(NULL) #define REL_FUNC_ENTRY_TRACE() hal_trace_dummy(NULL) #define REL_DUMP8(str, buf, cnt) hal_dump_dummy(str, buf, cnt) #define REL_DUMP16(str, buf, cnt) hal_dump_dummy(str, buf, cnt) #define REL_DUMP32(str, buf, cnt) hal_dump_dummy(str, buf, cnt) #endif #if (!defined(DEBUG) && defined(REL_TRACE_ENABLE)) && !defined(NO_TRACE) // To avoid warnings on unused variables #define TRACE(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define TRACE_IMM(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define TRACE_NOCRLF(str, ...) hal_trace_dummy(str, ##__VA_ARGS__) #define TRACE_OUTPUT(str, len) hal_trace_dummy((const char *)str, len) #define TRACE_FLUSH() hal_trace_dummy(NULL) #define FUNC_ENTRY_TRACE() hal_trace_dummy(NULL) #define DUMP8(str, buf, cnt) hal_dump_dummy(str, buf, cnt) #define DUMP16(str, buf, cnt) hal_dump_dummy(str, buf, cnt) #define DUMP32(str, buf, cnt) hal_dump_dummy(str, buf, cnt) #else #define TRACE REL_TRACE #define TRACE_IMM REL_TRACE_IMM #define TRACE_NOCRLF REL_TRACE_NOCRLF #define TRACE_OUTPUT REL_TRACE_OUTPUT #define TRACE_FLUSH REL_TRACE_FLUSH #define FUNC_ENTRY_TRACE REL_FUNC_ENTRY_TRACE #define DUMP8 REL_DUMP8 #define DUMP16 REL_DUMP16 #define DUMP32 REL_DUMP32 #endif #if (defined(DEBUG) || defined(REL_TRACE_ENABLE)) && defined(ASSERT_SHOW_FILE_FUNC) #define ASSERT(cond, str, ...) { if (!(cond)) { hal_trace_assert_dump(__FILE__, __FUNCTION__, __LINE__, str, ##__VA_ARGS__); } } #define ASSERT_DUMP_ARGS const char *file, const char *func, unsigned int line, const char *fmt, ... #define ASSERT_FMT_ARG_IDX 4 #elif (defined(DEBUG) || defined(REL_TRACE_ENABLE)) && defined(ASSERT_SHOW_FILE) #define ASSERT(cond, str, ...) { if (!(cond)) { hal_trace_assert_dump(__FILE__, __LINE__, str, ##__VA_ARGS__); } } #define ASSERT_DUMP_ARGS const char *file, const char *func, unsigned int line, const char *fmt, ... #define ASSERT_FMT_ARG_IDX 4 #elif (defined(DEBUG) || defined(REL_TRACE_ENABLE)) && defined(ASSERT_SHOW_FUNC) #define ASSERT(cond, str, ...) { if (!(cond)) { hal_trace_assert_dump(__FUNCTION__, __LINE__, str, ##__VA_ARGS__); } } #define ASSERT_DUMP_ARGS const char *scope, unsigned int line, const char *fmt, ... #define ASSERT_FMT_ARG_IDX 3 #elif (defined(DEBUG) || defined(REL_TRACE_ENABLE)) #define ASSERT(cond, str, ...) { if (!(cond)) { hal_trace_assert_dump(str, ##__VA_ARGS__); } } #define ASSERT_DUMP_ARGS const char *fmt, ... #define ASSERT_FMT_ARG_IDX 1 #else #define ASSERT(cond, str, ...) { if (!(cond)) { hal_trace_dummy(str, ##__VA_ARGS__); hal_trace_assert_dump(NULL); } } #define ASSERT_DUMP_ARGS const char *fmt #define ASSERT_FMT_ARG_IDX 0 #endif #if (defined(DEBUG) || defined(REL_TRACE_ENABLE)) #define TRACE_FUNC_DECLARE(d, r) d #else #ifndef TRACE_FUNC_SPEC #define TRACE_FUNC_SPEC static inline #endif #define TRACE_FUNC_DECLARE(d, r) TRACE_FUNC_SPEC d { r; } #endif #if defined(__GNUC__) && !defined(NO_CHK_TRC_FMT) #define TRC_FMT_CHK(sidx, vaidx) __attribute__((format(printf, (sidx), (vaidx)))) #else #define TRC_FMT_CHK(sidx, vaidx) #endif #define ASSERT_NODUMP(cond) { if (!(cond)) { SAFE_PROGRAM_STOP(); } } #ifdef CHIP_BEST1000 // Avoid CPU instruction fetch blocking the system bus on BEST1000 #define SAFE_PROGRAM_STOP() do { asm volatile("nop; nop; nop; nop"); } while (1) #else #define SAFE_PROGRAM_STOP() do { } while (1) #endif enum HAL_TRACE_TRANSPORT_T { #ifdef CHIP_HAS_USB HAL_TRACE_TRANSPORT_USB, #endif HAL_TRACE_TRANSPORT_UART0, #if (CHIP_HAS_UART > 1) HAL_TRACE_TRANSPORT_UART1, #endif #if (CHIP_HAS_UART > 2) HAL_TRACE_TRANSPORT_UART2, #endif #if defined(CHIP_HAAS1000) HAL_TRACE_TRANSPORT_TRANSQ1, #endif HAL_TRACE_TRANSPORT_QTY }; enum HAL_TRACE_STATE_T { HAL_TRACE_STATE_CRASH_ASSERT_START, HAL_TRACE_STATE_CRASH_FAULT_START, HAL_TRACE_STATE_CRASH_END, }; enum HAL_TRACE_BUF_STATE_T { HAL_TRACE_BUF_STATE_FLUSH, HAL_TRACE_BUF_STATE_NEAR_FULL, HAL_TRACE_BUF_STATE_FULL, }; enum HAL_TRACE_CRASH_DUMP_MODULE_T { HAL_TRACE_CRASH_DUMP_MODULE_SYS = 0, HAL_TRACE_CRASH_DUMP_MODULE_ID1 = 1, HAL_TRACE_CRASH_DUMP_MODULE_ID2 = 2, HAL_TRACE_CRASH_DUMP_MODULE_ID3 = 3, HAL_TRACE_CRASH_DUMP_MODULE_BT = 4, HAL_TRACE_CRASH_DUMP_MODULE_END = 5, }; enum HAL_TRACE_MODUAL { HAL_TRACE_LEVEL_0 = 1<<0, HAL_TRACE_LEVEL_1 = 1<<1, HAL_TRACE_LEVEL_2 = 1<<2, HAL_TRACE_LEVEL_3 = 1<<3, HAL_TRACE_LEVEL_4 = 1<<4, HAL_TRACE_LEVEL_5 = 1<<5, HAL_TRACE_LEVEL_6 = 1<<6, HAL_TRACE_LEVEL_7 = 1<<7, HAL_TRACE_LEVEL_8 = 1<<8, HAL_TRACE_LEVEL_9 = 1<<9, HAL_TRACE_LEVEL_10 = 1<<10, HAL_TRACE_LEVEL_11 = 1<<11, HAL_TRACE_LEVEL_12 = 1<<12, HAL_TRACE_LEVEL_13 = 1<<13, HAL_TRACE_LEVEL_14 = 1<<14, HAL_TRACE_LEVEL_15 = 1<<15, HAL_TRACE_LEVEL_16 = 1<<16, HAL_TRACE_LEVEL_17 = 1<<17, HAL_TRACE_LEVEL_18 = 1<<18, HAL_TRACE_LEVEL_19 = 1<<19, HAL_TRACE_LEVEL_20 = 1<<20, HAL_TRACE_LEVEL_21 = 1<<21, HAL_TRACE_LEVEL_22 = 1<<22, HAL_TRACE_LEVEL_23 = 1<<23, HAL_TRACE_LEVEL_24 = 1<<24, HAL_TRACE_LEVEL_25 = 1<<25, HAL_TRACE_LEVEL_26 = 1<<26, HAL_TRACE_LEVEL_27 = 1<<27, HAL_TRACE_LEVEL_28 = 1<<28, HAL_TRACE_LEVEL_29 = 1<<29, HAL_TRACE_LEVEL_30 = 1<<30, HAL_TRACE_LEVEL_31 = 1<<31, HAL_TRACE_LEVEL_ALL = 0XFFFFFFFF, }; typedef enum { LOG_LV_NONE, LOG_LV_FATAL, LOG_LV_ERROR, LOG_LV_WARN, LOG_LV_INFO, LOG_LV_DEBUG, } LOG_LEVEL_T; typedef enum { LOG_MOD_NONE, LOG_MOD_OS, LOG_MOD_BT_STACK, LOG_MOD_SYS, LOG_MOD_MEDIA, LOG_MOD_APP, } LOG_MODULE_T; typedef void (*HAL_TRACE_CRASH_DUMP_CB_T)(void); typedef void (*HAL_TRACE_APP_NOTIFY_T)(enum HAL_TRACE_STATE_T state); typedef void (*HAL_TRACE_APP_OUTPUT_T)(const unsigned char *buf, unsigned int buf_len); typedef void (*HAL_TRACE_BUF_CTRL_T)(enum HAL_TRACE_BUF_STATE_T buf_ctrl); #include "stdarg.h" typedef int (*HAL_TRACE_PRINTF_HOOK_T)(const char *tag, const char *fmt, enum PRINTF_FLAG_T flag, va_list ap); int hal_trace_open(enum HAL_TRACE_TRANSPORT_T transport); void hal_trace_register_hook(HAL_TRACE_PRINTF_HOOK_T hook); void hal_trace_unregister_hook(HAL_TRACE_PRINTF_HOOK_T hook); int hal_trace_open_cp(void); TRACE_FUNC_DECLARE(int hal_trace_switch(enum HAL_TRACE_TRANSPORT_T transport), return 0); TRACE_FUNC_DECLARE(int hal_trace_close(void), return 0); TRACE_FUNC_DECLARE(void hal_trace_get_history_buffer(const unsigned char **buf1, unsigned int *len1, \ const unsigned char **buf2, unsigned int *len2), \ { if (buf1) { *buf1 = NULL; } if (len1) { *len1 = 0; } if (buf2) { *buf2 = NULL; } if (len2) { *len2 = 0; } }); TRACE_FUNC_DECLARE(int hal_trace_output(const unsigned char *buf, unsigned int buf_len), return 0); TRC_FMT_CHK(2, 3) TRACE_FUNC_DECLARE(int hal_trace_printf_with_lvl(unsigned int lvl, const char *fmt, ...), return 0); TRC_FMT_CHK(1, 2) TRACE_FUNC_DECLARE(int hal_trace_printf(const char *fmt, ...), return 0); TRC_FMT_CHK(1, 2) TRACE_FUNC_DECLARE(int hal_trace_printf_without_ts(const char *fmt, ...), return 0); TRC_FMT_CHK(1, 2) TRACE_FUNC_DECLARE(void hal_trace_printf_imm(const char *fmt, ...), return); TRC_FMT_CHK(1, 2) TRACE_FUNC_DECLARE(void hal_trace_printf_imm_without_ts(const char *fmt, ...), return); TRC_FMT_CHK(1, 2) TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf(const char *fmt, ...), return 0); TRACE_FUNC_DECLARE(int hal_trace_printf_no_ts(const char *fmt, ...), return 0); TRC_FMT_CHK(1, 2) TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf_ts(const char *fmt, ...), return 0); TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf_cmd(const char *fmt, ...), return 0); TRACE_FUNC_DECLARE(int hal_trace_printf_no_ts_cmd(const char *fmt, ...), return 0); TRC_FMT_CHK(2, 3) TRACE_FUNC_DECLARE(int hal_trace_printf_with_tag(const char *tag, const char *fmt, ...), return 0); TRACE_FUNC_DECLARE(int hal_trace_printf_without_crlf_fix_arg(const char *fmt), return 0); TRACE_FUNC_DECLARE(int hal_trace_dump(const char *fmt, unsigned int size, unsigned int count, const void *buffer), return 0); TRACE_FUNC_DECLARE(int hal_trace_busy(void), return 0); TRACE_FUNC_DECLARE(int hal_trace_pause(void), return 0); TRACE_FUNC_DECLARE(int hal_trace_continue(void), return 0); TRACE_FUNC_DECLARE(int hal_trace_flush_buffer(void), return 0); TRACE_FUNC_DECLARE(void hal_trace_idle_send(void), return); TRACE_FUNC_DECLARE(int hal_trace_crash_dump_register(enum HAL_TRACE_CRASH_DUMP_MODULE_T module, HAL_TRACE_CRASH_DUMP_CB_T cb), return 0); TRACE_FUNC_DECLARE(void hal_trace_app_register(HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_APP_OUTPUT_T output_cb), return); TRACE_FUNC_DECLARE(void hal_trace_app_custom_register(HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_APP_OUTPUT_T output_cb, HAL_TRACE_APP_OUTPUT_T crash_custom_cb), return); TRACE_FUNC_DECLARE(void hal_trace_cp_register(HAL_TRACE_APP_NOTIFY_T notify_cb, HAL_TRACE_BUF_CTRL_T buf_cb), return); TRACE_FUNC_DECLARE(void hal_trace_print_backtrace(uint32_t addr, uint32_t search_cnt, uint32_t print_cnt), return); TRACE_FUNC_DECLARE(void hal_trace_print_a7(const unsigned char *buf, unsigned int buf_len), return); TRACE_FUNC_DECLARE(bool hal_trace_crash_dump_onprocess(void), return false); TRACE_FUNC_DECLARE(uint32_t hal_trace_get_baudrate(void), return 0); TRC_FMT_CHK(1, 2) static inline void hal_trace_dummy(const char *fmt, ...) { } static inline void hal_dump_dummy(const char *fmt, ...) { } #if (ASSERT_FMT_ARG_IDX > 0) TRC_FMT_CHK(ASSERT_FMT_ARG_IDX, ASSERT_FMT_ARG_IDX + 1) #endif void NORETURN hal_trace_assert_dump(ASSERT_DUMP_ARGS); int hal_trace_address_writable(uint32_t addr); int hal_trace_address_executable(uint32_t addr); int hal_trace_address_readable(uint32_t addr); int32_t cli_printf(const char *buffer, ...); int hal_trace_output_block(const unsigned char *buf, unsigned int len); //============================================================================== // AUDIO_DEBUG //============================================================================== #ifdef AUDIO_DEBUG #define AUDIO_DEBUG_TRACE(str, ...) hal_trace_printf(str, ##__VA_ARGS__) #define AUDIO_DEBUG_DUMP(buf, cnt) hal_trace_output(buf, cnt) #endif #define print_addr(k) TRACE("***addr:%02x:%02x:%02x:%02x:%02x:%02x\n", (k)[0],(k)[1],(k)[2],(k)[3],(k)[4],(k)[5]) //============================================================================== // INTERSYS_RAW_DATA_ONLY //============================================================================== #ifdef INTERSYS_RAW_DATA_ONLY #define TRACE_RAW(str, ...) hal_trace_printf(str, ##__VA_ARGS__) #define DUMP8_RAW(str, buf, cnt) hal_trace_dump(str, sizeof(uint8_t), cnt, buf) #endif //============================================================================== // TRACE RX //============================================================================== #if defined(_AUTO_TEST_) #define HAL_TRACE_RX_ENABLE extern int auto_test_send(char *resp); #define AUTO_TEST_SEND(str) auto_test_send((char*)str) #endif #ifdef HAL_TRACE_RX_ENABLE #include "stdio.h" #define hal_trace_rx_parser(buf, str, ...) sscanf(buf, str, ##__VA_ARGS__) typedef unsigned int (*HAL_TRACE_RX_CALLBACK_T)(unsigned char *buf, unsigned int len); int hal_trace_rx_register(const char *name, HAL_TRACE_RX_CALLBACK_T callback); int hal_trace_rx_deregister(const char *name); #endif #define printf hal_trace_printf_without_crlf #define printf_no_ts hal_trace_printf_no_ts #define cmd_printf hal_trace_printf_without_crlf_cmd #define cmd_printf_no_ts hal_trace_printf_no_ts_cmd #define printf_raw hal_trace_printf_without_crlf_ts #define print_addr(k) TRACE("***addr:%02x:%02x:%02x:%02x:%02x:%02x\n", (k)[0],(k)[1],(k)[2],(k)[3],(k)[4],(k)[5]) #define uart_printf(...) //hal_trace_printf(__VA_ARGS__) #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_trace.h
C
apache-2.0
16,300
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_TRANSQ_H__ #define __HAL_TRANSQ_H__ #ifdef __cplusplus extern "C" { #endif #ifdef CHIP_HAS_TRANSQ #include "plat_types.h" #define RX_NUM_NORMAL 30 #define TX_NUM_NORMAL 30 enum HAL_TRANSQ_ID_T { HAL_TRANSQ_ID_0 = 0, #if (CHIP_HAS_TRANSQ > 1) HAL_TRANSQ_ID_1, #endif HAL_TRANSQ_ID_QTY }; enum HAL_TRANSQ_PRI_T { HAL_TRANSQ_PRI_NORMAL = 0, HAL_TRANSQ_PRI_HIGH, HAL_TRANSQ_PRI_QTY }; enum HAL_TRANSQ_RET_T { HAL_TRANSQ_RET_OK = 0, HAL_TRANSQ_RET_BAD_ID, HAL_TRANSQ_RET_BAD_PRI, HAL_TRANSQ_RET_BAD_CFG, HAL_TRANSQ_RET_BAD_SLOT, HAL_TRANSQ_RET_BAD_TX_NUM, HAL_TRANSQ_RET_BAD_RX_NUM, HAL_TRANSQ_RET_BAD_MODE, HAL_TRANSQ_RET_RX_EMPTY, HAL_TRANSQ_RET_TX_FULL, }; typedef void (*HAL_TRANSQ_RX_IRQ_HANDLER)(enum HAL_TRANSQ_PRI_T pri); typedef void (*HAL_TRANSQ_TX_IRQ_HANDLER)(enum HAL_TRANSQ_PRI_T pri, const uint8_t *data, uint32_t len); struct HAL_TRANSQ_SLOT_NUM_T { uint8_t tx_num[HAL_TRANSQ_PRI_QTY]; uint8_t rx_num[HAL_TRANSQ_PRI_QTY]; }; struct HAL_TRANSQ_CFG_T { struct HAL_TRANSQ_SLOT_NUM_T slot; uint8_t rx_irq_count; HAL_TRANSQ_RX_IRQ_HANDLER rx_handler; HAL_TRANSQ_TX_IRQ_HANDLER tx_handler; }; enum HAL_TRANSQ_RET_T hal_transq_get_rx_status(enum HAL_TRANSQ_ID_T id, enum HAL_TRANSQ_PRI_T pri, bool *ready); enum HAL_TRANSQ_RET_T hal_transq_get_tx_status(enum HAL_TRANSQ_ID_T id, enum HAL_TRANSQ_PRI_T pri, bool *done); bool hal_transq_tx_busy(enum HAL_TRANSQ_ID_T id); enum HAL_TRANSQ_RET_T hal_transq_rx_first(enum HAL_TRANSQ_ID_T id, enum HAL_TRANSQ_PRI_T pri, const uint8_t **data, uint32_t *len); enum HAL_TRANSQ_RET_T hal_transq_rx_next(enum HAL_TRANSQ_ID_T id, enum HAL_TRANSQ_PRI_T pri, const uint8_t **data, uint32_t *len); enum HAL_TRANSQ_RET_T hal_transq_tx(enum HAL_TRANSQ_ID_T id, enum HAL_TRANSQ_PRI_T pri, const uint8_t *data, uint32_t len); enum HAL_TRANSQ_RET_T hal_transq_update_num(enum HAL_TRANSQ_ID_T id, const struct HAL_TRANSQ_SLOT_NUM_T *slot); enum HAL_TRANSQ_RET_T hal_transq_open(enum HAL_TRANSQ_ID_T id, const struct HAL_TRANSQ_CFG_T *cfg); enum HAL_TRANSQ_RET_T hal_transq_close(enum HAL_TRANSQ_ID_T id); enum HAL_TRANSQ_RET_T hal_transq_flush(enum HAL_TRANSQ_ID_T id); uint8_t get_rx_irq_count(enum HAL_TRANSQ_ID_T id); #ifdef __ARM_ARCH_ISA_ARM #ifdef RTOS void hal_transq_local_irq_handler(int irq_num, void *irq_data); #endif #endif #endif // CHIP_HAS_TRANSQ #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_transq.h
C
apache-2.0
3,145
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_UART_H__ #define __HAL_UART_H__ #ifdef __cplusplus extern "C" { #endif #ifdef CHIP_HAS_UART #include "plat_types.h" #include "stdbool.h" #include "stdint.h" #include "hal_dma.h" //#define BT_UART #define HAL_UART_DMA_TRANSFER_STEP 0xFFF #ifdef __KNOWLES #define HAL_UART_DMA_TRANSFER_STEP_PINGPANG 640 #else #define HAL_UART_DMA_TRANSFER_STEP_PINGPANG 4 #endif enum HAL_UART_ID_T { HAL_UART_ID_0 = 0, #if (CHIP_HAS_UART > 1) HAL_UART_ID_1, #endif #if (CHIP_HAS_UART > 2) HAL_UART_ID_2, #endif #ifdef BT_UART HAL_UART_ID_BT, #endif HAL_UART_ID_QTY }; enum HAL_UART_PARITY_T { HAL_UART_PARITY_NONE, HAL_UART_PARITY_ODD, HAL_UART_PARITY_EVEN, HAL_UART_PARITY_FORCE1, HAL_UART_PARITY_FORCE0, }; enum HAL_UART_STOP_BITS_T { HAL_UART_STOP_BITS_1, HAL_UART_STOP_BITS_2, }; enum HAL_UART_DATA_BITS_T { HAL_UART_DATA_BITS_5, HAL_UART_DATA_BITS_6, HAL_UART_DATA_BITS_7, HAL_UART_DATA_BITS_8, }; enum HAL_UART_FLOW_CONTROL_T { HAL_UART_FLOW_CONTROL_NONE, HAL_UART_FLOW_CONTROL_RTS, HAL_UART_FLOW_CONTROL_CTS, HAL_UART_FLOW_CONTROL_RTSCTS, }; enum HAL_UART_FIFO_LEVEL_T { HAL_UART_FIFO_LEVEL_1_8, HAL_UART_FIFO_LEVEL_1_4, HAL_UART_FIFO_LEVEL_1_2, HAL_UART_FIFO_LEVEL_3_4, HAL_UART_FIFO_LEVEL_7_8, }; struct HAL_UART_CFG_T { enum HAL_UART_PARITY_T parity; enum HAL_UART_STOP_BITS_T stop; enum HAL_UART_DATA_BITS_T data; enum HAL_UART_FLOW_CONTROL_T flow; enum HAL_UART_FIFO_LEVEL_T rx_level; enum HAL_UART_FIFO_LEVEL_T tx_level; uint32_t baud; bool dma_rx : 1; bool dma_tx : 1; bool dma_rx_stop_on_err : 1; }; union HAL_UART_STATUS_T { struct { uint32_t FE :1; // frame error uint32_t PE :1; // parity error uint32_t BE :1; // break error uint32_t OE :1; // overrun error }; uint32_t reg; }; union HAL_UART_FLAG_T { struct { uint32_t CTS :1; uint32_t DSR :1; uint32_t DCD :1; uint32_t BUSY :1; uint32_t RXFE :1; // rx fifo empty uint32_t TXFF :1; // tx fifo full uint32_t RXFF :1; // rx fifo full uint32_t TXFE :1; // tx fifo empty uint32_t RI :1; // ring indicator }; uint32_t reg; }; union HAL_UART_IRQ_T { struct { uint32_t RIM :1; // ri uint32_t CTSM :1; // cts uint32_t DCDM :1; // dcd uint32_t DSRM :1; // dsr uint32_t RX :1; // rx uint32_t TX :1; // tx uint32_t RT :1; // receive timeout uint32_t FE :1; // framing error uint32_t PE :1; // parity error uint32_t BE :1; // break error uint32_t OE :1; // overrun }; uint32_t reg; }; typedef void (*HAL_UART_IRQ_HANDLER_T)(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T status); typedef void (*HAL_UART_IRQ_RXDMA_HANDLER_T)(uint32_t xfer_size, int dma_error, union HAL_UART_IRQ_T status); typedef void (*HAL_UART_IRQ_TXDMA_HANDLER_T)(uint32_t xfer_size, int dma_error); typedef void (*HAL_UART_IRQ_BREAK_HANDLER_T)(void); int hal_uart_open(enum HAL_UART_ID_T id, const struct HAL_UART_CFG_T *cfg); int hal_uart_reopen(enum HAL_UART_ID_T id, const struct HAL_UART_CFG_T *cfg); int hal_uart_close(enum HAL_UART_ID_T id); int hal_uart_opened(enum HAL_UART_ID_T id); int hal_uart_pause(enum HAL_UART_ID_T id); int hal_uart_continue(enum HAL_UART_ID_T id); int hal_uart_readable(enum HAL_UART_ID_T id); int hal_uart_writable(enum HAL_UART_ID_T id); uint8_t hal_uart_getc(enum HAL_UART_ID_T id); int hal_uart_putc(enum HAL_UART_ID_T id, uint8_t c); uint8_t hal_uart_blocked_getc(enum HAL_UART_ID_T id); int hal_uart_blocked_putc(enum HAL_UART_ID_T id, uint8_t c); union HAL_UART_FLAG_T hal_uart_get_flag(enum HAL_UART_ID_T id); union HAL_UART_STATUS_T hal_uart_get_status(enum HAL_UART_ID_T id); void hal_uart_clear_status(enum HAL_UART_ID_T id); void hal_uart_break_set(enum HAL_UART_ID_T id); void hal_uart_break_clear(enum HAL_UART_ID_T id); void hal_uart_flush(enum HAL_UART_ID_T id, uint32_t ticks); union HAL_UART_IRQ_T hal_uart_get_raw_irq(enum HAL_UART_ID_T id); void hal_uart_clear_irq(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T irq); union HAL_UART_IRQ_T hal_uart_irq_get_mask(enum HAL_UART_ID_T id); union HAL_UART_IRQ_T hal_uart_irq_set_mask(enum HAL_UART_ID_T id, union HAL_UART_IRQ_T mask); HAL_UART_IRQ_HANDLER_T hal_uart_irq_set_handler(enum HAL_UART_ID_T id, HAL_UART_IRQ_HANDLER_T handler); void hal_uart_irq_set_dma_handler(enum HAL_UART_ID_T id, HAL_UART_IRQ_RXDMA_HANDLER_T rxdma, HAL_UART_IRQ_TXDMA_HANDLER_T txdma, HAL_UART_IRQ_BREAK_HANDLER_T brk); int hal_uart_dma_recv(enum HAL_UART_ID_T id, uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt); int hal_uart_dma_recv_pingpang(enum HAL_UART_ID_T id, uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt); int hal_uart_dma_recv_mask(enum HAL_UART_ID_T id, uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt, const union HAL_UART_IRQ_T *mask); int hal_uart_dma_recv_mask2(enum HAL_UART_ID_T id, uint8_t *buf0, uint32_t len0, uint8_t *buf1, uint32_t len1, struct HAL_DMA_DESC_T desc[2], const union HAL_UART_IRQ_T *mask); int hal_uart_dma_recv_mask_pingpang(enum HAL_UART_ID_T id, uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt, const union HAL_UART_IRQ_T *mask, uint32_t step); int hal_uart_dma_recv_mask_stream(enum HAL_UART_ID_T id, uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt, const union HAL_UART_IRQ_T *mask, uint32_t step); uint32_t hal_uart_get_dma_recv_addr(enum HAL_UART_ID_T id); uint32_t hal_uart_stop_dma_recv(enum HAL_UART_ID_T id); int hal_uart_dma_send(enum HAL_UART_ID_T id, const uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt); int hal_uart_dma_send2(enum HAL_UART_ID_T id, const uint8_t *buf0, uint32_t len0, const uint8_t *buf1, uint32_t len1, struct HAL_DMA_DESC_T desc[2]); uint32_t hal_uart_stop_dma_send(enum HAL_UART_ID_T id); // addd for ali tihngs uart2 dma send int hal_uart_dma_send_sync_cache(enum HAL_UART_ID_T id, const uint8_t *buf, uint32_t len, struct HAL_DMA_DESC_T *desc, uint32_t *desc_cnt); // ======================================================================== // Test function int hal_uart_printf_init(void); void hal_uart_printf(const char *fmt, ...); void hal_uart_output(const unsigned char *buf, int size); #endif // CHIP_HAS_UART #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_uart.h
C
apache-2.0
7,661
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_USB_H__ #define __HAL_USB_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" #define USB_MAX_PACKET_SIZE_CTRL 64 #ifdef USB_HIGH_SPEED #define USB_MAX_PACKET_SIZE_BULK 512 #define USB_MAX_PACKET_SIZE_INT 1024 #define USB_MAX_PACKET_SIZE_ISO 1024 #define USB_FIFO_MPS_ISO_SEND 800 #else #define USB_MAX_PACKET_SIZE_BULK 64 #define USB_MAX_PACKET_SIZE_INT 64 #define USB_MAX_PACKET_SIZE_ISO 1023 #define USB_FIFO_MPS_ISO_SEND 768 #endif // H/w register bit field width limitation #define EPN_MAX_PKTCNT ((1 << 10) - 1) #define EPN_MAX_XFERSIZE ((1 << 19) - 1) #define EPNUM 6 #define CTRL_EPNUM 2 #define USB_L1_LIGHT_SLEEP_BESL USB_BESL_125US #define USB_L1_DEEP_SLEEP_BESL USB_BESL_6000US enum HAL_USB_API_MODE { HAL_USB_API_NONBLOCKING, HAL_USB_API_BLOCKING, }; enum EP_DIR { EP_OUT, EP_IN, }; enum CTRL_STAGE { NONE_STAGE, WAIT_SETUP_STAGE, SETUP_STAGE, DATA_OUT_STAGE, DATA_IN_STAGE, STATUS_OUT_STAGE, STATUS_IN_STAGE, }; enum ZLP_STATE { ZLP_AUTO, ZLP_DISABLED, }; enum XFER_COMPL_STATE { XFER_COMPL_SUCCESS, XFER_COMPL_ERROR, }; enum HAL_USB_STATE_EVENT { HAL_USB_EVENT_RESET, // RESET event should be processed as quickly as possible HAL_USB_EVENT_DISCONNECT, HAL_USB_EVENT_SUSPEND, HAL_USB_EVENT_L1_DEEP_SLEEP, HAL_USB_EVENT_RESUME, HAL_USB_EVENT_STALL, HAL_USB_EVENT_UNSTALL, HAL_USB_EVENT_QTY }; enum USB_BESL_T { USB_BESL_125US = 0, USB_BESL_150US, USB_BESL_200US, USB_BESL_300US, USB_BESL_400US, USB_BESL_500US, USB_BESL_1000US, USB_BESL_2000US, USB_BESL_3000US, USB_BESL_4000US, USB_BESL_5000US, USB_BESL_6000US, USB_BESL_7000US, USB_BESL_8000US, USB_BESL_9000US, USB_BESL_10000US, }; enum USB_BESL_HIRD_T { USB_BESL_HIRD_75US, USB_BESL_HIRD_100US, USB_BESL_HIRD_150US, USB_BESL_HIRD_250US, USB_BESL_HIRD_350US, USB_BESL_HIRD_450US, USB_BESL_HIRD_950US, USB_BESL_HIRD_1950US, USB_BESL_HIRD_2950US, USB_BESL_HIRD_3950US, USB_BESL_HIRD_4950US, USB_BESL_HIRD_5950US, USB_BESL_HIRD_6950US, USB_BESL_HIRD_7950US, USB_BESL_HIRD_8950US, USB_BESL_HIRD_9950US, }; enum USB_HIRD_T { USB_HIRD_50US, USB_HIRD_125US, USB_HIRD_200US, USB_HIRD_275US, USB_HIRD_350US, USB_HIRD_425US, USB_HIRD_500US, USB_HIRD_575US, USB_HIRD_650US, USB_HIRD_725US, USB_HIRD_800US, USB_HIRD_875US, USB_HIRD_950US, USB_HIRD_1025US, USB_HIRD_1100US, USB_HIRD_1175US, }; struct SETUP_PACKET { struct { uint8_t recipient : 5; uint8_t type : 2; uint8_t direction : 1; } bmRequestType; uint8_t bRequest; uint16_t wValue; uint16_t wIndex; uint16_t wLength; }; struct EP0_TRANSFER { enum CTRL_STAGE stage; uint8_t *data; uint16_t length; uint16_t trx_len; struct SETUP_PACKET setup_pkt; }; typedef const uint8_t *(*HAL_USB_GET_DESCRIPTOR_CALLBACK)(uint8_t); typedef bool (*HAL_USB_SETUPRECV_CALLBACK)(struct EP0_TRANSFER *); typedef bool (*HAL_USB_DATARECV_CALLBACK)(struct EP0_TRANSFER *); typedef bool (*HAL_USB_SETCFG_CALLBACK)(uint8_t); typedef bool (*HAL_USB_SETITF_CALLBACK)(uint16_t, uint16_t); typedef void (*HAL_USB_REMOTE_WAKEUP_CALLBACK)(int enable); typedef void (*HAL_USB_STATE_CHANGE_CALLBACK)(enum HAL_USB_STATE_EVENT, uint32_t); typedef bool (*HAL_USB_RECV_COMPL_CALLBACK)(const uint8_t *, uint32_t, enum XFER_COMPL_STATE); typedef bool (*HAL_USB_SEND_COMPL_CALLBACK)(const uint8_t *, uint32_t, enum XFER_COMPL_STATE); struct HAL_USB_CALLBACKS { HAL_USB_GET_DESCRIPTOR_CALLBACK device_desc; HAL_USB_GET_DESCRIPTOR_CALLBACK cfg_desc; HAL_USB_GET_DESCRIPTOR_CALLBACK string_desc; HAL_USB_SETUPRECV_CALLBACK setuprecv; HAL_USB_DATARECV_CALLBACK datarecv; HAL_USB_SETCFG_CALLBACK setcfg; HAL_USB_SETITF_CALLBACK setitf; HAL_USB_REMOTE_WAKEUP_CALLBACK set_remote_wakeup; HAL_USB_STATE_CHANGE_CALLBACK state_change; HAL_USB_RECV_COMPL_CALLBACK epn_recv_compl[EPNUM - 1]; HAL_USB_SEND_COMPL_CALLBACK epn_send_compl[EPNUM - 1]; }; int hal_usb_open(const struct HAL_USB_CALLBACKS *c, enum HAL_USB_API_MODE m); int hal_usb_reopen(const struct HAL_USB_CALLBACKS *c, uint8_t dcfg, uint8_t alt, uint16_t itf); void hal_usb_close(void); int hal_usb_remote_wakeup(int signal); void hal_usb_detect_disconn(void); void hal_usb_lpm_sleep_enable(void); void hal_usb_lpm_sleep_disable(void); int hal_usb_configured(void); int hal_usb_suspended(void); uint32_t hal_usb_calc_hshb_ep_mps(uint32_t pkt_size); int hal_usb_activate_epn(enum EP_DIR dir, uint8_t ep, uint8_t type, uint16_t mps); int hal_usb_deactivate_epn(enum EP_DIR dir, uint8_t ep); int hal_usb_update_recv_epn_mps(uint8_t ep, uint16_t mps); int hal_usb_update_send_epn_mc(uint8_t ep, uint8_t mc); void hal_usb_disable_ep(enum EP_DIR dir, uint8_t ep); void hal_usb_stall_ep(enum EP_DIR dir, uint8_t ep); void hal_usb_unstall_ep(enum EP_DIR dir, uint8_t ep); int hal_usb_get_ep_stall_state(enum EP_DIR dir, uint8_t ep); void hal_usb_stop_ep(enum EP_DIR dir, uint8_t ep); int hal_usb_recv_epn(uint8_t ep, uint8_t *buffer, uint32_t size); int hal_usb_send_epn(uint8_t ep, const uint8_t *buffer, uint32_t size, enum ZLP_STATE zlp); uint32_t hal_usb_get_soffn(void); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_usb.h
C
apache-2.0
6,345
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_USB_H__ #define __HAL_USB_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" #ifdef USB_HIGH_SPEED #define MAX_USBHOST_PACKET_SIZE 512 #else #define MAX_USBHOST_PACKET_SIZE 64 #endif #define USBHOST_EPNUM 6 #define HAL_USBHOST_CHAN_NONE 0xFF enum HAL_USBHOST_EP_TYPE_T { HAL_USBHOST_EP_CTRL, HAL_USBHOST_EP_ISO, HAL_USBHOST_EP_BULK, HAL_USBHOST_EP_INT, HAL_USBHOST_EP_QTY }; enum HAL_USBHOST_PID_TYPE_T { HAL_USBHOST_PID_DATA0 = 0, HAL_USBHOST_PID_DATA2 = 1, HAL_USBHOST_PID_DATA1 = 2, HAL_USBHOST_PID_MDATA = 3, HAL_USBHOST_PID_SETUP = 3, HAL_USBHOST_PID_QTY, HAL_USBHOST_PID_AUTO = 0xFF, }; enum HAL_USBHOST_PORT_EVENT_T { HAL_USBHOST_PORT_CONN, HAL_USBHOST_PORT_EN_LS, HAL_USBHOST_PORT_EN_FS, HAL_USBHOST_PORT_EN_HS, HAL_USBHOST_PORT_EN_BAD, HAL_USBHOST_PORT_DISCONN, HAL_USBHOST_PORT_QTY }; enum HAL_USBHOST_SETUP_STAGE_T { HAL_USBHOST_SETUP_DATA_IN, HAL_USBHOST_SETUP_DATA_OUT, HAL_USBHOST_SETUP_STATUS_IN, HAL_USBHOST_SETUP_STATUS_OUT, HAL_USBHOST_SETUP_DONE, HAL_USBHOST_SETUP_ERROR, HAL_USBHOST_SETUP_STAGE_QTY }; enum HAL_USBHOST_XFER_ERR_T { HAL_USBHOST_XFER_ERR_NONE, HAL_USBHOST_XFER_ERR_AHB, HAL_USBHOST_XFER_ERR_STALL, HAL_USBHOST_XFER_ERR_TRANSACTION, HAL_USBHOST_XFER_ERR_BABBLE, HAL_USBHOST_XFER_ERR_FRAME_OVERRUN, HAL_USBHOST_XFER_ERR_DATA_TOGGLE, HAL_USBHOST_XFER_ERR_TIMEOUT, HAL_USBHOST_XFER_ERR_DISCONN, HAL_USBHOST_XFER_ERR_QTY }; struct HAL_USBHOST_SETUP_XFER_T; typedef void (*HAL_USBHOST_DELAY_FUNC)(uint32_t ms); typedef void (*HAL_USBHOST_PORT_HANDLER)(enum HAL_USBHOST_PORT_EVENT_T evt); typedef void (*HAL_USBHOST_XFER_COMPL_HANDLER)(uint8_t chan, uint8_t *buf, uint32_t len, enum HAL_USBHOST_XFER_ERR_T error); typedef void (*HAL_USBHOST_SETUP_COMPL_HANDLER)(struct HAL_USBHOST_SETUP_XFER_T *setup, int error); enum HAL_USBHOST_PLUG_STATUS_T { HAL_USBHOST_PLUG_UNKNOWN, HAL_USBHOST_PLUG_IN, HAL_USBHOST_PLUG_OUT, }; typedef void (*HAL_USBHOST_PLUG_HANDLER)(enum HAL_USBHOST_PLUG_STATUS_T status); struct HAL_USBHOST_CHAN_TYPE_T { uint16_t mps; uint8_t ep_num; uint8_t ep_in; enum HAL_USBHOST_EP_TYPE_T ep_type; uint8_t dev_addr; }; struct HAL_USBHOST_XFER_T { uint8_t *buf; uint32_t size; uint8_t multi_cnt; enum HAL_USBHOST_PID_TYPE_T pid; HAL_USBHOST_XFER_COMPL_HANDLER handler; }; struct HAL_USBHOST_SETUP_PKT_T { uint8_t bmRequestType; uint8_t bRequest; uint16_t wValue; uint16_t wIndex; uint16_t wLength; }; struct HAL_USBHOST_SETUP_XFER_T { struct HAL_USBHOST_SETUP_PKT_T setup_pkt; enum HAL_USBHOST_SETUP_STAGE_T next_stage; HAL_USBHOST_SETUP_COMPL_HANDLER handler; uint8_t *data_buf; uint8_t chan_out; uint8_t chan_in; }; int hal_usbhost_open(HAL_USBHOST_PORT_HANDLER port_cb, HAL_USBHOST_DELAY_FUNC delay_fn); void hal_usbhost_close(void); void hal_usbhost_halt_chan(uint8_t chan); void hal_usbhost_port_reset(uint32_t ms); int hal_usbhost_get_chan(uint8_t *chan); int hal_usbhost_free_chan(uint8_t chan); int hal_usbhost_init_chan(uint8_t chan, const struct HAL_USBHOST_CHAN_TYPE_T *type); int hal_usbhost_update_chan_dev_addr(uint8_t chan, uint8_t dev_addr); int hal_usbhost_update_chan_mps(uint8_t chan, uint16_t mps); int hal_usbhost_start_xfer(uint8_t chan, const struct HAL_USBHOST_XFER_T *xfer); int hal_usbhost_start_setup_xfer(const struct HAL_USBHOST_SETUP_XFER_T *setup, uint32_t *recv_len); void hal_usbhost_detect(enum HAL_USBHOST_PLUG_STATUS_T status, HAL_USBHOST_PLUG_HANDLER handler); void hal_usbhost_sleep(void); void hal_usbhost_wakeup(void); uint32_t hal_usbhost_get_port_status(void); uint32_t hal_usbhost_get_interrupt_status(void); void hal_usbhost_set_port_enable(void); void hal_usbhost_set_port_disable(void); void hal_usbhost_set_port_poweron(void); void hal_usbhost_set_port_poweroff(void); void hal_usbhost_set_timeout(uint32_t ms); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_usbhost.h
C
apache-2.0
4,800
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 WDT_HAL_H #define WDT_HAL_H #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" enum HAL_WDT_ID_T { HAL_WDT_ID_0 = 0, HAL_WDT_ID_NUM, }; enum HAL_WDT_EVENT_T { HAL_WDT_EVENT_FIRE = 0, }; #define HAL_WDT_YES 1 #define HAL_WDT_NO 0 typedef void (*HAL_WDT_IRQ_CALLBACK)(enum HAL_WDT_ID_T id, uint32_t status); /* hal api */ void hal_wdt_set_irq_callback(enum HAL_WDT_ID_T id, HAL_WDT_IRQ_CALLBACK handler); /* mandatory operations */ int hal_wdt_start(enum HAL_WDT_ID_T id); int hal_wdt_stop(enum HAL_WDT_ID_T id); /* optional operations */ int hal_wdt_ping(enum HAL_WDT_ID_T id); int hal_wdt_set_timeout(enum HAL_WDT_ID_T id, unsigned int); unsigned int hal_wdt_get_timeleft(enum HAL_WDT_ID_T id); #ifdef __cplusplus } #endif #endif /* WDT_HAL_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_wdt.h
C
apache-2.0
1,439
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __HAL_XDMA_H__ #define __HAL_XDMA_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "stdbool.h" #define HAL_XDMA_CHAN_NONE 0xFF #define HAL_XDMA_MAX_DESC_XFER_SIZE 0x1FFF enum HAL_XDMA_RET_T { HAL_XDMA_OK, HAL_XDMA_ERR, }; enum HAL_XDMA_GET_CHAN_T { HAL_XDMA_PRIO_SET0, HAL_XDMA_PRIO_SET1, HAL_XDMA_PRIO_SET2, HAL_XDMA_PRIO_SET3, HAL_XDMA_PRIO_QTY }; // DMA Type of DMA controller enum HAL_XDMA_FLOW_CONTROL_T { HAL_XDMA_FLOW_M2M_DMA = 0, /* Memory to memory - DMA control */ HAL_XDMA_FLOW_M2P_DMA = 1, /* Memory to peripheral - DMA control */ HAL_XDMA_FLOW_P2M_DMA = 2, /* Peripheral to memory - DMA control */ HAL_XDMA_FLOW_P2P_DMA = 3, /* Source peripheral to destination peripheral - DMA control */ HAL_XDMA_FLOW_P2P_DSTPERIPH = 4, /* Source peripheral to destination peripheral - destination peripheral control */ HAL_XDMA_FLOW_M2P_PERIPH = 5, /* Memory to peripheral - peripheral control */ HAL_XDMA_FLOW_P2M_PERIPH = 6, /* Peripheral to memory - peripheral control */ HAL_XDMA_FLOW_P2P_SRCPERIPH = 7, /* Source peripheral to destination peripheral - source peripheral control */ HAL_XDMA_FLOW_FLAG_SI = 0x40, HAL_XDMA_FLOW_FLAG_DI = 0x80, HAL_XDMA_FLOW_FLAG_MASK = (HAL_XDMA_FLOW_FLAG_SI | HAL_XDMA_FLOW_FLAG_DI), HAL_XDMA_FLOW_M2P_DI_DMA = HAL_XDMA_FLOW_M2P_DMA | HAL_XDMA_FLOW_FLAG_DI, HAL_XDMA_FLOW_P2M_SI_DMA = HAL_XDMA_FLOW_P2M_DMA | HAL_XDMA_FLOW_FLAG_SI, HAL_XDMA_FLOW_P2P_DI_DMA = HAL_XDMA_FLOW_P2P_DMA | HAL_XDMA_FLOW_FLAG_DI, HAL_XDMA_FLOW_P2P_SI_DMA = HAL_XDMA_FLOW_P2P_DMA | HAL_XDMA_FLOW_FLAG_SI, }; // DMA Burst size in Source and Destination definitions enum HAL_XDMA_BSIZE_T { HAL_XDMA_BSIZE_RESERVED = 0, HAL_XDMA_BSIZE_8 = 1, /* Burst size = 8 */ HAL_XDMA_BSIZE_16 = 2, /* Burst size = 16 */ HAL_XDMA_BSIZE_32 = 3, /* Burst size = 32 */ HAL_XDMA_BSIZE_64 = 4, /* Burst size = 64 */ }; // Width in Source transfer width and Destination transfer width definitions enum HAL_XDMA_WDITH_T { HAL_XDMA_WIDTH_RESERVED = 0, /* WIDTH must be 0x0 for memory-to-memory moves or companion-chip-related operations */ HAL_XDMA_WIDTH_BYTE = 1, /* Width = 1 byte */ HAL_XDMA_WIDTH_HALFWORD = 2, /* Width = 2 bytes */ HAL_XDMA_WIDTH_WORD = 3, /* Width = 4 bytes */ }; enum HAL_XDMA_PERIPH_T { HAL_DSPXDMA_PERIPH_NULL = 0, HAL_DSPXDMA_MEM = 1, /* HAL_DSPXDMA_AUDIO = 2, HAL_DSPXDMA_CODEC_RX = 50, HAL_DSPXDMA_CODEC_TX = 51, HAL_DSPXDMA_BTPCM_RX = 52, HAL_DSPXDMA_BTPCM_TX = 53, HAL_DSPXDMA_I2S0_RX = 54, HAL_DSPXDMA_I2S0_TX = 55, HAL_DSPXDMA_DPD_RX = 56, HAL_DSPXDMA_DPD_TX = 57, HAL_DSPXDMA_SPDIF0_RX = 58, HAL_DSPXDMA_SPDIF0_TX = 59, HAL_DSPXDMA_SPDIF1_RX = 60, HAL_DSPXDMA_SPDIF1_TX = 61, HAL_DSPXDMA_DSD_RX = 62, HAL_DSPXDMA_DSD_TX = 63, HAL_DSPXDMA_MC_RX = 64, HAL_DSPXDMA_FFT_RX = 65, HAL_DSPXDMA_FFT_TX = 66, HAL_DSPXDMA_FIR_RX = 67, HAL_DSPXDMA_FIR_TX = 68, HAL_DSPXDMA_IIR_RX = 69, HAL_DSPXDMA_IIR_TX = 70, HAL_DSPXDMA_BTDUMP = 71, HAL_DSPXDMA_I2S1_RX = 72, HAL_DSPXDMA_I2S1_TX = 73, HAL_DSPXDMA_FM_RX = 74, HAL_DSPXDMA_FMDUMP0 = 75, HAL_DSPXDMA_FMDUMP1 = 76, HAL_DSPXDMA_CODEC_TX2 = 77, */ }; struct HAL_XDMA_DESC_T; typedef void (*HAL_XDMA_IRQ_HANDLER_T)(uint8_t chan, uint32_t remain_tsize, uint32_t error, struct HAL_XDMA_DESC_T *lli); typedef void (*HAL_XDMA_START_CALLBACK_T)(uint8_t chan); typedef void (*HAL_XDMA_DELAY_FUNC)(uint32_t ms); // DMA structure using for DMA configuration struct HAL_XDMA_CH_CFG_T { uint8_t ch; /* DMA channel number */ uint16_t src_tsize; /* Length/Size of transfer */ enum HAL_XDMA_WDITH_T width; enum HAL_XDMA_BSIZE_T bsize; enum HAL_XDMA_FLOW_CONTROL_T type; /* Transfer Type */ enum HAL_XDMA_PERIPH_T src_periph; enum HAL_XDMA_PERIPH_T dst_periph; uint32_t src; /* Physical Source Address */ uint32_t dst; /* Physical Destination Address */ HAL_XDMA_IRQ_HANDLER_T handler; HAL_XDMA_START_CALLBACK_T start_cb; }; // Transfer Descriptor structure typedef struct HAL_XDMA_DESC_T { uint32_t dadr; /* Pointer to next descriptor structure */ uint32_t sadr; /* Source address */ uint32_t tadr; /* Destination address */ uint32_t cmd; /* Control word that has transfer size, type etc. */ }; // DMA 2D configuration structure struct HAL_XDMA_2D_CFG_T { int16_t xmodify; uint16_t xcount; int16_t ymodify; uint16_t ycount; }; //============================================================= void hal_xdma_open(void); void hal_xdma_close(void); bool hal_xdma_chan_busy(uint8_t ch); uint8_t hal_xdma_get_chan(enum HAL_XDMA_PERIPH_T periph, enum HAL_XDMA_GET_CHAN_T policy); void hal_xdma_free_chan(uint8_t ch); uint32_t hal_xdma_cancel(uint8_t ch); uint32_t hal_xdma_stop(uint8_t ch); enum HAL_XDMA_RET_T hal_xdma_init_desc(struct HAL_XDMA_DESC_T *desc, const struct HAL_XDMA_CH_CFG_T *cfg, const struct HAL_XDMA_DESC_T *next, int tc_irq); enum HAL_XDMA_RET_T hal_xdma_sg_start(const struct HAL_XDMA_DESC_T *desc, const struct HAL_XDMA_CH_CFG_T *cfg); enum HAL_XDMA_RET_T hal_xdma_sg_2d_start(const struct HAL_XDMA_DESC_T *desc, const struct HAL_XDMA_CH_CFG_T *cfg, const struct HAL_XDMA_2D_CFG_T *src_2d, const struct HAL_XDMA_2D_CFG_T *dst_2d); enum HAL_XDMA_RET_T hal_xdma_start(const struct HAL_XDMA_CH_CFG_T *cfg); uint32_t hal_xdma_get_cur_src_addr(uint8_t ch); uint32_t hal_xdma_get_cur_dst_addr(uint8_t ch); uint32_t hal_xdma_get_sg_remain_size(uint8_t ch); enum HAL_XDMA_RET_T hal_xdma_irq_run_chan(uint8_t ch); bool hal_xdma_busy(void); HAL_XDMA_DELAY_FUNC hal_xdma_set_delay_func(HAL_XDMA_DELAY_FUNC new_func); void hal_xdma_remap_periph(enum HAL_XDMA_PERIPH_T periph, int enable); void hal_xdma_tc_irq_enable(uint8_t ch); void hal_xdma_tc_irq_disable(uint8_t ch); void hal_dspxdma_mem2mem_test(char *dst, char *src, uint16_t num); //============================================================= #define hal_dspxdma_open hal_xdma_open #define hal_dspxdma_close hal_xdma_close #define hal_dspxdma_chan_busy hal_xdma_chan_busy #define hal_dspxdma_get_chan hal_xdma_get_chan #define hal_dspxdma_free_chan hal_xdma_free_chan #define hal_dspxdma_cancel hal_xdma_cancel #define hal_dspxdma_stop hal_xdma_stop #define hal_dspxdma_init_desc hal_xdma_init_desc #define hal_dspxdma_sg_start hal_xdma_sg_start #define hal_dspxdma_start hal_xdma_start #define hal_dspxdma_get_cur_src_addr hal_xdma_get_cur_src_addr #define hal_dspxdma_get_cur_dst_addr hal_xdma_get_cur_dst_addr #define hal_dspxdma_get_sg_remain_size hal_xdma_get_sg_remain_size #define hal_dspxdma_irq_run_chan hal_xdma_irq_run_chan //============================================================= #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/hal_xdma.h
C
apache-2.0
8,585
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __PLAT_ADDR_MAP_H__ #define __PLAT_ADDR_MAP_H__ #ifdef __cplusplus extern "C" { #endif #define CHIP_ID_LITERAL haas1000 #define _TO_STRING_A(s) # s #define _TO_STRING(s) _TO_STRING_A(s) #define CONCAT_NAME_A(a, b) a ## b #define CONCAT_NAME(a, b) CONCAT_NAME_A(a, b) #define CONCAT_SUFFIX(a, b) a.b #define CONSTRUCT_HDR_NAME_A(d, n) d/n ## _ ## d #define CONSTRUCT_HDR_NAME(d, n) CONSTRUCT_HDR_NAME_A(d, n) #define CHIP_SPECIFIC_HDR(n) _TO_STRING(CONSTRUCT_HDR_NAME(CHIP_ID_LITERAL, n).h) #include CHIP_SPECIFIC_HDR(plat_addr_map) #define RAM_TO_RAMX(d) ((d) - RAM_BASE + RAMX_BASE) #define RAMX_TO_RAM(d) ((d) - RAMX_BASE + RAM_BASE) #define FLASH_TO_FLASHX(d) ((d) - FLASH_BASE + FLASHX_BASE) #define FLASHX_TO_FLASH(d) ((d) - FLASHX_BASE + FLASH_BASE) #define FLASH_C_TO_NC(d) ((d) - FLASH_BASE + FLASH_NC_BASE) #define FLASH_NC_TO_C(d) ((d) - FLASH_NC_BASE + FLASH_BASE) #define PSRAM_TO_PSRAMX(d) ((d) - PSRAM_BASE + PSRAMX_BASE) #define PSRAMX_TO_PSRAM(d) ((d) - PSRAMX_BASE + PSRAM_BASE) #define PSRAM_C_TO_NC(d) ((d) - PSRAM_BASE + PSRAM_NC_BASE) #define PSRAM_NC_TO_C(d) ((d) - PSRAM_NC_BASE + PSRAM_BASE) #define BUILD_INFO_MAGIC 0xBE57341D #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/plat_addr_map.h
C
apache-2.0
2,292
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __PLAT_TYPES_H__ #define __PLAT_TYPES_H__ #ifdef __cplusplus extern "C" { #endif #include "stddef.h" #include "stdint.h" #include "stdbool.h" #ifdef FPGA #define __TCMDATA __attribute__((section(".tcmdata"))) #define __RAMCODE __attribute__((section(".ramcode"))) #define __RAMDATA __attribute__((section(".ramdata"))) #define __PSRAMCODE #define __PSRAMDATA #define __PSRAMBSS #define __SRAM_EXT_BSS __attribute__((section(".sram_bss"))) #ifdef RESTRICTED_RAM #define __RRAMCODE __attribute__((section(".rram_text"))) #define __RRAMDATA __attribute__((section(".rram_data"))) #define __RRAMBSS __attribute__((section(".rram_bss"))) #else #define __RRAMCODE #define __RRAMDATA #define __RRAMBSS #endif #define __SRAMCODE __attribute__((section(".sram_text"))) #define __SRAMDATA __attribute__((section(".sram_data"))) #define __SRAMBSS __attribute__((section(".sram_bss"))) #define __AUDMA __attribute__((section(".audma"))) #define __FSRAMCODE __attribute__((section(".fast_text_sram"))) #define __BOOTSRAMCODE __attribute__((section(".boot_text_sram"))) #ifdef __FAR_FIELD_2000IWA__ #define __RX_CODE #else #define __RX_CODE __SRAMCODE #endif #else /*FPGA*/ #define __TCMDATA __attribute__((section(".tcmdata"))) #define __RAMCODE __attribute__((section(".ramcode"))) #define __RAMDATA __attribute__((section(".ramdata"))) #ifdef RESTRICTED_RAM #define __RRAMCODE __attribute__((section(".rram_text"))) #define __RRAMDATA __attribute__((section(".rram_data"))) #define __RRAMBSS __attribute__((section(".rram_bss"))) #else #define __RRAMCODE #define __RRAMDATA #define __RRAMBSS #endif #define __SRAMCODE __attribute__((section(".sram_text"))) #define __SRAMDATA __attribute__((section(".sram_data"))) #define __SRAMBSS __attribute__((section(".sram_bss"))) #define __AUDMA __attribute__((section(".audma"))) #define __FSRAMCODE __attribute__((section(".fast_text_sram"))) #define __BOOTSRAMCODE __attribute__((section(".boot_text_sram"))) #if defined(CHIP_HAS_PSRAM) && defined(PSRAM_ENABLE) #define __PSRAMCODE __attribute__((section(".psram_text"))) #define __PSRAMDATA __attribute__((section(".psram_data"))) #define __PSRAMBSS __attribute__((section(".psram_bss"))) #elif defined(CHIP_HAS_PSRAMUHS) && defined(PSRAMUHS_ENABLE) #define __PSRAMUHSCODE __attribute__((section(".psramuhs_text"))) #define __PSRAMUHSDATA __attribute__((section(".psramuhs_data"))) #define __PSRAMUHSBSS __attribute__((section(".psramuhs_bss"))) #define __PSRAMCODE __PSRAMUHSCODE #define __PSRAMDATA __PSRAMUHSDATA // #define __PSRAMBSS __PSRAMUHSBSS #define __PSRAMBSS #else #define __PSRAMCODE #define __PSRAMDATA #define __PSRAMBSS #endif #define __SRAM_EXT_CODE __PSRAMCODE #define __SRAM_EXT_DATA __PSRAMDATA #define __SRAM_EXT_BSS __PSRAMBSS #ifdef __FAR_FIELD_2000IWA__ #define __RX_CODE #else #define __RX_CODE __SRAMCODE #endif #endif /*FPGA*/ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef X32_F #define X32_F "x" #endif #ifndef X16_F #define X16_F "x" #endif #ifndef U32_F #define U32_F "d" #endif #ifndef S32_F #define S32_F "d" #endif #ifndef S16_F #define S16_F "d" #endif #ifndef U16_F #define U16_F "d" #endif typedef long long __int64; typedef long long __le64; typedef unsigned short __le16; typedef unsigned int __le32; typedef unsigned short __be16; typedef unsigned int __be32; typedef unsigned short __u16; typedef unsigned char __u8; typedef short __s16; typedef char __s8; typedef unsigned int __u32; typedef unsigned long u32; typedef int __s32; typedef float FP32; /* Single precision floating point */ typedef double FP64; /* Double precision floating point */ typedef unsigned int OS_STK; /* Each stack entry is 32-bit wide */ typedef unsigned int OS_CPU_SR; /* Define size of CPU status register (PSR = 32 bits) */ typedef void (*FUNCPtr)(void*); typedef unsigned char INT8U; /* Unsigned 8 bit quantity */ typedef signed char INT8S; /* Signed 8 bit quantity */ typedef unsigned char UCHAR; typedef char CHAR; typedef unsigned char* PUCHAR; typedef signed char* PCHAR; typedef unsigned char UINT8; typedef unsigned char uint8; typedef unsigned short UINT16; typedef unsigned short uint16; typedef unsigned int UINT32; typedef unsigned int uint32; typedef unsigned int uint32; typedef signed char INT8; typedef signed char int8; typedef short INT16; typedef short int16; typedef int INT32; typedef int int32; 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 unsigned char u8; typedef unsigned short u16; typedef unsigned long u32; typedef unsigned long long u64; typedef unsigned char U8; typedef unsigned short U16; typedef unsigned int U32; typedef unsigned long long U64; typedef char s8; typedef short s16; typedef long s32; typedef long long s64; //typedef char ascii; typedef unsigned char byte; /* unsigned 8-bit data */ typedef unsigned short word; /* unsigned 16-bit data */ typedef unsigned long dword; /* unsigned 32-bit data */ /* IO definitions (access restrictions to peripheral registers) */ /** \defgroup CMSIS_glob_defs CMSIS Global Defines <strong>IO Type Qualifiers</strong> are used \li to specify the access to peripheral variables. \li for automatic generation of peripheral register debug information. */ #ifndef __I #ifdef __cplusplus #define __I volatile /*!< Defines 'read only' permissions */ #else #define __I volatile const /*!< Defines 'read only' permissions */ #endif #define __O volatile /*!< Defines 'write only' permissions */ #define __IO volatile /*!< Defines 'read / write' permissions */ #endif #define BITFIELD_VAL(field, value) (((value) & (field ## _MASK >> field ## _SHIFT)) << field ## _SHIFT) #define SET_BITFIELD(reg, field, value) (((reg) & ~field ## _MASK) | BITFIELD_VAL(field, value)) #define GET_BITFIELD(reg, field) (((reg) & field ## _MASK) >> field ## _SHIFT) /* Frequently used macros */ #ifndef ALIGN #define ALIGN(val,exp) (((val) + ((exp)-1)) & ~((exp)-1)) #endif #ifndef ARRAY_SIZE #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) #endif #define LAST_ELEMENT(x) (&x[ARRAY_SIZE(x)-1]) #define BOUND(x, min, max) ( (x) < (min) ? (min) : ((x) > (max) ? (max):(x)) ) #define ROUND_SIZEOF(t) ((sizeof(t)+sizeof(int)-1)&~(sizeof(int)-1)) #ifndef MAX #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif #ifndef ABS #define ABS(x) ((x<0)?(-(x)):(x)) #endif #define TO_STRING_A(s) # s #define TO_STRING(s) TO_STRING_A(s) #ifdef __GNUC__ /* Remove const cast-away warnings from gcc -Wcast-qual */ #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) /// From http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/ /// Macro to use in a if statement to tell the compiler this branch /// is likely taken, and optimize accordingly. #define LIKELY(x) __builtin_expect(!!(x), 1) /// Macro to use in a if statement to tell the compiler this branch /// is unlikely take, and optimize accordingly. #define UNLIKELY(x) __builtin_expect(!!(x), 0) /// For packing structure #define PACKED __attribute__((packed)) /// To describe alignment #define ALIGNED(a) __attribute__((aligned(a))) /// For possibly unused functions or variables (e.g., debugging stuff) #define POSSIBLY_UNUSED __attribute__((unused)) /// For functions or variables must be emitted even if not referenced #define USED __attribute__((used)) /// For inline functions #define ALWAYS_INLINE __attribute__((always_inline)) // For functions never inlined #define NOINLINE __attribute__((noinline)) // For functions not caring performance #ifdef __ARMCC_VERSION #define OPT_SIZE #else #define OPT_SIZE __attribute__((optimize("Os"))) #endif // For functions not returning #define NORETURN __attribute__((noreturn)) // For ASM functions in C #ifdef __arm__ #define NAKED __attribute__((naked)) #else #define NAKED __attribute__((error("Unsupport naked functions"))) #endif // For weak symbols #define WEAK __attribute__((weak)) // Structure offset #ifndef OFFSETOF #define OFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif /** * CONTAINER_OF - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. * @type: the type of the container struct this is embedded in. * @member: the name of the member within the struct. * */ #ifndef CONTAINER_OF #define CONTAINER_OF(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - OFFSETOF(type,member) );}) #endif #else // Not GCC #define __UNCONST(a) #define LIKELY(x) #define UNLIKELY(x) #define PACKED #define ALIGNED(a) #define POSSIBLY_UNUSED #define USED #define ALWAYS_INLINE #define NOINLINE #define OPT_SIZE #define NORETURN #define NAKED #define WEAK #define OFFSETOF(TYPE, MEMBER) #endif // Not GCC /// C preprocessor conditional check /// -------------------------------- #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) #if defined(__GNUC__) && (GCC_VERSION >= 40600) && !defined(__cplusplus) // GCC 4.6 or later #define STATIC_ASSERT(e, m) _Static_assert(e, m) #elif defined(__GNUC__) && (GCC_VERSION >= 40300) && defined(__cplusplus) && (__cplusplus >= 201103L) #define STATIC_ASSERT(e, m) static_assert(e, m) #else // No built-in static assert /// FROM: http://www.pixelbeat.org/programming/gcc/static_assert.html #define ASSERT_CONCAT_(a, b) a##b #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) /* These can't be used after statements in c89. */ #ifdef __COUNTER__ #define STATIC_ASSERT(e, m) \ enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(e)) }; #else /* This can't be used twice on the same line so ensure if using in headers * that the headers are not included twice (by wrapping in #ifndef...#endif) * Note it doesn't cause an issue when used on same line of separate modules * compiled with gcc -combine -fwhole-program. */ #define STATIC_ASSERT(e, m) \ enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) }; #endif #endif // No built-in static assert /// -------------------------------- #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/plat_types.h
C++
apache-2.0
12,366
/* * Copyright (C) 2015-2020 Alibaba Group Holding Limited */ #ifndef __REG_I2CIP_H_ #define __REG_I2CIP_H_ #include "plat_types.h" #define I2CIP_TX_FIFO_DEPTH (8) #define I2CIP_RX_FIFO_DEPTH (8) #define NANO_TO_MICRO 1000 #define I2CIP_SS_SCL_HCNT_REG_OFFSET 0x14 #define I2CIP_SS_SCL_HCNT_SHIFT (0) #define I2CIP_SS_SCL_HCNT_MASK ((0xffff)<<I2CIP_SS_SCL_HCNT_SHIFT) #define I2CIP_SS_SCL_LCNT_REG_OFFSET 0x18 #define I2CIP_SS_SCL_LCNT_SHIFT (0) #define I2CIP_SS_SCL_LCNT_MASK ((0xffff)<<I2CIP_SS_SCL_LCNT_SHIFT) #define I2CIP_FS_SCL_HCNT_REG_OFFSET 0x1C #define I2CIP_FS_SCL_HCNT_SHIFT (0) #define I2CIP_FS_SCL_HCNT_MASK ((0xffff)<<I2CIP_FS_SCL_HCNT_SHIFT) #define I2CIP_FS_SCL_LCNT_REG_OFFSET 0x20 #define I2CIP_FS_SCL_LCNT_SHIFT (0) #define I2CIP_FS_SCL_LCNT_MASK ((0xffff)<<I2CIP_FS_SCL_LCNT_SHIFT) #define I2CIP_HS_SCL_HCNT_REG_OFFSET 0x24 #define I2CIP_HS_SCL_HCNT_SHIFT (0) #define I2CIP_HS_SCL_HCNT_MASK ((0xffff)<<I2CIP_HS_SCL_hCNT_SHIFT) #define I2CIP_HS_SCL_LCNT_REG_OFFSET 0x28 #define I2CIP_HS_SCL_LCNT_SHIFT (0) #define I2CIP_HS_SCL_LCNT_MASK ((0xffff)<<I2CIP_HS_SCL_LCNT_SHIFT) /* High and low times in different speed modes (in ns) */ #define MIN_SS_SCL_HIGHTIME 4000 #define MIN_SS_SCL_LOWTIME 4700 #define MIN_FS_SCL_HIGHTIME 600 #define MIN_FS_SCL_LOWTIME 1300 #define MIN_HS_SCL_HIGHTIME 60 #define MIN_HS_SCL_LOWTIME 160 /* Worst case timeout for 1 byte is kept as 2ms */ #define I2C_BYTE_TO (SYS_TIMER_TICK_HZ / 500) #define I2C_STOPDET_TO (SYS_TIMER_TICK_HZ / 500) #define I2C_BYTE_TO_BB (I2C_BYTE_TO * 16) /* i2c control register definitions */ #define I2CIP_CTRL_REG_OFFSET 0x0 #define I2CIP_SPEED_SHIFT (1) #define I2CIP_SPEED_MASK ((0x3)<<I2CIP_SPEED_SHIFT) #define I2CIP_HIGH_SPEED_SHIFT (1) #define I2CIP_HIGH_SPEED_MASK ((0x3)<<I2CIP_HIGH_SPEED_SHIFT) #define I2CIP_FAST_SPEED_SHIFT (1) #define I2CIP_FAST_SPEED_MASK ((0x2)<<I2CIP_HIGH_SPEED_SHIFT) #define I2CIP_STANDARD_SPEED_SHIFT (1) #define I2CIP_STANDARD_SPEED_MASK ((0x1)<<I2CIP_STANDARD_SPEED_SHIFT) #define I2CIP_SLAVE_DISABLE_SHIFT (6) #define I2CIP_SLAVE_DISABLE_MASK ((0x1)<<I2CIP_SLAVE_DISABLE_SHIFT) #define I2CIP_RESTART_ENABLE_SHIFT (5) #define I2CIP_RESTART_ENABLE_MASK ((0x1)<<I2CIP_RESTART_ENABLE_SHIFT) #define I2CIP_MASTER_MODE_SHIFT (0) #define I2CIP_MASTER_MODE_MASK ((0x1)<<I2CIP_MASTER_MODE_SHIFT) #define I2CIP_10BITADDR_MASTER_SHIFT (4) #define I2CIP_10BITADDR_MASTER_MASK ((0x1)<<I2CIP_10BITADDR_MASTER_SHIFT) #define I2CIP_10BITADDR_SLAVE_SHIFT (3) #define I2CIP_10BITADDR_SLAVE_MASK ((0x1)<<I2CIP_10BITADDR_SLAVE_SHIFT) /* i2c target address register definitions */ #define I2CIP_TARGET_ADDRESS_REG_OFFSET 0x04 #define I2CIP_TARGET_ADDRESS_SHIFT 0 #define I2CIP_TARGET_ADDRESS_MASK ((0x3ff)<<I2CIP_TARGET_ADDRESS_SHIFT) #define I2CIP_TARGET_ADDRESS_IC_10BITADDR_MASTER_SHIFT 12 #define I2CIP_TARGET_ADDRESS_IC_10BITADDR_MASTER_MASK (1 << I2CIP_TARGET_ADDRESS_IC_10BITADDR_MASTER_SHIFT) #define I2CIP_TARGET_ADDRESS_SPECIAL_BIT_SHIFT 11 #define I2CIP_TARGET_ADDRESS_SPECIAL_BIT_MASK ((0x1)<<I2CIP_TARGET_ADDRESS_SPECIAL_BIT_SHIFT) #define I2CIP_TARGET_ADDRESS_GC_OR_START_SHIFT 10 #define I2CIP_TARGET_ADDRESS_GC_OR_START_MASK ((0x1)<<I2CIP_TARGET_ADDRESS_GC_OR_START_SHIFT) /* i2c slave address register definitions */ #define I2CIP_ADDRESS_AS_SLAVE_REG_OFFSET 0x08 #define I2CIP_ADDRESS_AS_SLAVE_SHIFT (0) #define I2CIP_ADDRESS_AS_SLAVE_MASK ((0x3ff)<<I2CIP_ADDRESS_AS_SLAVE_SHIFT) /* i2c data buffer and command register definitions */ #define I2CIP_CMD_DATA_REG_OFFSET 0x10 #define I2CIP_CMD_DATA_CMD_SHIFT (8) #define I2CIP_CMD_DATA_CMD_MASK ((0x1)<<I2CIP_CMD_DATA_CMD_SHIFT) #define I2CIP_CMD_DATA_CMD_READ_SHIFT (8) #define I2CIP_CMD_DATA_CMD_READ_MASK ((0x1)<<I2CIP_CMD_DATA_CMD_READ_SHIFT) #define I2CIP_CMD_DATA_CMD_WRITE_SHIFT (8) #define I2CIP_CMD_DATA_CMD_WRITE_MASK ((0x0)<<I2CIP_CMD_DATA_CMD_WRITE_SHIFT) #define I2CIP_CMD_DATA_STOP_SHIFT (9) #define I2CIP_CMD_DATA_STOP_MASK ((0x1)<<I2CIP_CMD_DATA_STOP_SHIFT) #define I2CIP_CMD_DATA_RESTART_SHIFT (10) #define I2CIP_CMD_DATA_RESTART_MASK ((0x1)<<I2CIP_CMD_DATA_RESTART_SHIFT) /* i2c interrupt status register definitions */ #define I2CIP_INT_STATUS_REG_OFFSET 0x2C #define I2CIP_INT_STATUS_GEN_CALL_SHIFT (11) #define I2CIP_INT_STATUS_GEN_CALL_MASK ((0x1)<<I2CIP_INT_STATUS_GEN_CALL_SHIFT) #define I2CIP_INT_STATUS_START_DET_SHIFT (10) #define I2CIP_INT_STATUS_START_DET_MASK ((0x1)<<I2CIP_INT_STATUS_START_DET_SHIFT) #define I2CIP_INT_STATUS_STOP_DET_SHIFT (9) #define I2CIP_INT_STATUS_STOP_DET_MASK ((0x1)<<I2CIP_INT_STATUS_STOP_DET_SHIFT) #define I2CIP_INT_STATUS_ACTIVITY_SHIFT (8) #define I2CIP_INT_STATUS_ACTIVITY_MASK ((0x1)<<I2CIP_INT_STATUS_ACTIVITY_SHIFT) #define I2CIP_INT_STATUS_RX_DONE_SHIFT (7) #define I2CIP_INT_STATUS_RX_DONE_MASK ((0x1)<<I2CIP_INT_STATUS_RX_DONE_SHIFT) #define I2CIP_INT_STATUS_TX_ABRT_SHIFT (6) #define I2CIP_INT_STATUS_TX_ABRT_MASK ((0x1)<<I2CIP_INT_STATUS_TX_ABRT_SHIFT) #define I2CIP_INT_STATUS_RD_REQ_SHIFT (5) #define I2CIP_INT_STATUS_RD_REQ_MASK ((0x1)<<I2CIP_INT_STATUS_RD_REQ_SHIFT) #define I2CIP_INT_STATUS_TX_EMPTY_SHIFT (4) #define I2CIP_INT_STATUS_TX_EMPTY_MASK ((0x1)<<I2CIP_INT_STATUS_TX_EMPTY_SHIFT) #define I2CIP_INT_STATUS_TX_OVER_SHIFT (3) #define I2CIP_INT_STATUS_TX_OVER_MASK ((0x1)<<I2CIP_INT_STATUS_TX_OVER_SHIFT) #define I2CIP_INT_STATUS_RX_FULL_SHIFT (2) #define I2CIP_INT_STATUS_RX_FULL_MASK ((0x1)<<I2CIP_INT_STATUS_RX_FULL_SHIFT) #define I2CIP_INT_STATUS_RX_OVER_SHIFT (1) #define I2CIP_INT_STATUS_RX_OVER_MASK ((0x1)<<I2CIP_INT_STATUS_RX_OVER_SHIFT) #define I2CIP_INT_STATUS_RX_UNDER_SHIFT (0) #define I2CIP_INT_STATUS_RX_UNDER_MASK ((0x1)<<I2CIP_INT_STATUS_RX_UNDER_SHIFT) /* i2c raw interrupt status register definitions */ #define I2CIP_RAW_INT_STATUS_REG_OFFSET 0x34 #define I2CIP_RAW_INT_STATUS_GEN_CALL_SHIFT (11) #define I2CIP_RAW_INT_STATUS_GEN_CALL_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_GEN_CALL_SHIFT) #define I2CIP_RAW_INT_STATUS_START_DET_SHIFT (10) #define I2CIP_RAW_INT_STATUS_START_DET_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_START_DET_SHIFT) #define I2CIP_RAW_INT_STATUS_STOP_DET_SHIFT (9) #define I2CIP_RAW_INT_STATUS_STOP_DET_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_STOP_DET_SHIFT) #define I2CIP_RAW_INT_STATUS_ACTIVITY_SHIFT (8) #define I2CIP_RAW_INT_STATUS_ACTIVITY_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_ACTIVITY_SHIFT) #define I2CIP_RAW_INT_STATUS_RX_DONE_SHIFT (7) #define I2CIP_RAW_INT_STATUS_RX_DONE_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_RX_DONE_SHIFT) #define I2CIP_RAW_INT_STATUS_TX_ABRT_SHIFT (6) #define I2CIP_RAW_INT_STATUS_TX_ABRT_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_TX_ABRT_SHIFT) #define I2CIP_RAW_INT_STATUS_RD_REQ_SHIFT (5) #define I2CIP_RAW_INT_STATUS_RD_REQ_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_RD_REQ_SHIFT) #define I2CIP_RAW_INT_STATUS_TX_EMPTY_SHIFT (4) #define I2CIP_RAW_INT_STATUS_TX_EMPTY_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_TX_EMPTY_SHIFT) #define I2CIP_RAW_INT_STATUS_TX_OVER_SHIFT (3) #define I2CIP_RAW_INT_STATUS_TX_OVER_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_TX_OVER_SHIFT) #define I2CIP_RAW_INT_STATUS_RX_FULL_SHIFT (2) #define I2CIP_RAW_INT_STATUS_RX_FULL_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_RX_FULL_SHIFT) #define I2CIP_RAW_INT_STATUS_RX_OVER_SHIFT (1) #define I2CIP_RAW_INT_STATUS_RX_OVER_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_RX_OVER_SHIFT) #define I2CIP_RAW_INT_STATUS_RX_UNDER_SHIFT (0) #define I2CIP_RAW_INT_STATUS_RX_UNDER_MASK ((0x1)<<I2CIP_RAW_INT_STATUS_RX_UNDER_SHIFT) /* fifo threshold register definitions */ #define I2CIP_RX_THRESHOLD_REG_OFFSET 0x38 #define I2CIP_RX_TL_DEPTH (I2CIP_RX_FIFO_DEPTH - 1) #define I2CIP_RX_TL_QUARTER (I2CIP_RX_FIFO_DEPTH/4 - 1) #define I2CIP_RX_TL_HALF (I2CIP_RX_FIFO_DEPTH/2 - 1) #define I2CIP_RX_TL_THREE_QUARTER (I2CIP_RX_FIFO_DEPTH*3/4 - 1) #define I2CIP_RX_TL_1_BYTE (0) #define I2CIP_TX_THRESHOLD_REG_OFFSET 0x3C #define I2CIP_TX_TL_DEPTH ((I2CIP_TX_FIFO_DEPTH)) #define I2CIP_TX_TL_QUARTER (I2CIP_TX_FIFO_DEPTH/4) #define I2CIP_TX_TL_HALF (I2CIP_TX_FIFO_DEPTH/2) #define I2CIP_TX_TL_THREE_QUARTER (I2CIP_TX_FIFO_DEPTH*3/4) #define I2CIP_TX_TL_1_BYTE (1) #define I2CIP_TX_TL_ZERO (0) /* i2c enable register definitions */ #define I2CIP_ENABLE_REG_OFFSET 0x6c #define I2CIP_ENABLE_SHIFT 0 #define I2CIP_ENABLE_MASK ((0x1)<<I2CIP_ENABLE_SHIFT) /* i2c status register definitions */ #define I2CIP_STATUS_REG_OFFSET 0x70 #define I2CIP_STATUS_SA_SHIFT (6) #define I2CIP_STATUS_SA_MASK ((0x1)<<I2CIP_STATUS_SA_SHIFT) #define I2CIP_STATUS_SHIFT (5) #define I2CIP_STATUS_MASK ((0x1)<<I2CIP_STATUS_SHIFT) #define I2CIP_STATUS_RFF_SHIFT (4) #define I2CIP_STATUS_RFF_MASK ((0x1)<<I2CIP_STATUS_RFF_SHIFT) #define I2CIP_STATUS_RFNE_SHIFT (3) #define I2CIP_STATUS_RFNE_MASK ((0x1)<<I2CIP_STATUS_RFNE_SHIFT) #define I2CIP_STATUS_TFE_SHIFT (2) #define I2CIP_STATUS_TFE_MASK ((0x1)<<I2CIP_STATUS_TFE_SHIFT) #define I2CIP_STATUS_TFNF_SHIFT (1) #define I2CIP_STATUS_TFNF_MASK ((0x1)<<I2CIP_STATUS_TFNF_SHIFT) #define I2CIP_STATUS_ACT_SHIFT (0) #define I2CIP_STATUS_ACT_MASK ((0x1)<<I2CIP_STATUS_ACT_SHIFT) /* i2c interrupt mask register */ #define I2CIP_INT_MASK_REG_OFFSET 0x30 #define I2CIP_INT_MASK_GEN_CALL_SHIFT (11) #define I2CIP_INT_MASK_GEN_CALL_MASK ((0x1)<<I2CIP_INT_MASK_GEN_CALL_SHIFT) #define I2CIP_INT_MASK_START_DET_SHIFT (10) #define I2CIP_INT_MASK_START_DET_MASK ((0x1)<<I2CIP_INT_MASK_START_DET_SHIFT) #define I2CIP_INT_MASK_STOP_DET_SHIFT (9) #define I2CIP_INT_MASK_STOP_DET_MASK ((0x1)<<I2CIP_INT_MASK_STOP_DET_SHIFT) #define I2CIP_INT_MASK_ACTIVITY_SHIFT (8) #define I2CIP_INT_MASK_ACTIVITY_MASK ((0x1)<<I2CIP_INT_MASK_ACTIVITY_SHIFT) #define I2CIP_INT_MASK_RX_DONE_SHIFT (7) #define I2CIP_INT_MASK_RX_DONE_MASK ((0x1)<<I2CIP_INT_MASK_RX_DONE_SHIFT) #define I2CIP_INT_MASK_TX_ABRT_SHIFT (6) #define I2CIP_INT_MASK_TX_ABRT_MASK ((0x1)<<I2CIP_INT_MASK_TX_ABRT_SHIFT) #define I2CIP_INT_MASK_RD_REQ_SHIFT (5) #define I2CIP_INT_MASK_RD_REQ_MASK ((0x1)<<I2CIP_INT_MASK_RD_REQ_SHIFT) #define I2CIP_INT_MASK_TX_EMPTY_SHIFT (4) #define I2CIP_INT_MASK_TX_EMPTY_MASK ((0x1)<<I2CIP_INT_MASK_TX_EMPTY_SHIFT) #define I2CIP_INT_MASK_TX_OVER_SHIFT (3) #define I2CIP_INT_MASK_TX_OVER_MASK ((0x1)<<I2CIP_INT_MASK_TX_OVER_SHIFT) #define I2CIP_INT_MASK_RX_FULL_SHIFT (2) #define I2CIP_INT_MASK_RX_FULL_MASK ((0x1)<<I2CIP_INT_MASK_RX_FULL_SHIFT) #define I2CIP_INT_MASK_RX_OVER_SHIFT (1) #define I2CIP_INT_MASK_RX_OVER_MASK ((0x1)<<I2CIP_INT_MASK_RX_OVER_SHIFT) #define I2CIP_INT_MASK_RX_UNDER_SHIFT (0) #define I2CIP_INT_MASK_RX_UNDER_MASK ((0x1)<<I2CIP_INT_MASK_RX_UNDER_SHIFT) #define I2CIP_INT_UNMASK_ALL (0) #define I2CIP_INT_MASK_ALL \ (I2CIP_INT_MASK_GEN_CALL_MASK | \ I2CIP_INT_MASK_START_DET_MASK | \ I2CIP_INT_MASK_STOP_DET_MASK | \ I2CIP_INT_MASK_ACTIVITY_MASK | \ I2CIP_INT_MASK_RX_DONE_MASK | \ I2CIP_INT_MASK_TX_ABRT_MASK | \ I2CIP_INT_MASK_RD_REQ_MASK | \ I2CIP_INT_MASK_TX_EMPTY_MASK | \ I2CIP_INT_MASK_TX_OVER_MASK | \ I2CIP_INT_MASK_RX_FULL_MASK | \ I2CIP_INT_MASK_RX_OVER_MASK | \ I2CIP_INT_MASK_RX_UNDER_MASK) #define I2CIP_INT_MASK_ERROR_MASK \ (I2CIP_INT_MASK_TX_ABRT_MASK | \ I2CIP_INT_MASK_TX_OVER_MASK | \ I2CIP_INT_MASK_RX_OVER_MASK | \ I2CIP_INT_MASK_RX_UNDER_MASK) /* i2c enable status register definitions */ #define I2CIP_ENABLE_STATUS_REG_OFFSET 0x9c #define I2CIP_ENABLE_STATUS_ENABLE_SHIFT 0 #define I2CIP_ENABLE_STATUS_ENABLE_MASK ((0x1)<<I2CIP_ENABLE_STATUS_ENABLE_SHIFT) /* i2c tx fifo level register definitions */ #define I2CIP_TX_FIFO_LEVEL_REG_OFFSET 0x74 /* i2c rx fifo level register definitions */ #define I2CIP_RX_FIFO_LEVEL_REG_OFFSET 0x78 /* i2c sda hold time register */ #define I2CIP_SDA_HOLD_REG_OFFSET 0x7c /* i2c clear all intr register */ #define I2CIP_CLR_ALL_INTR_REG_OFFSET 0x40 /* i2c clear rx under register */ #define I2CIP_CLR_RX_UNDER_REG_OFFSET 0x44 /* i2c clear rx over register */ #define I2CIP_CLR_RX_OVER_REG_OFFSET 0x48 /* i2c clear tx over register */ #define I2CIP_CLR_TX_OVER_REG_OFFSET 0x4c /* i2c clear rd req register */ #define I2CIP_CLR_RD_REQ_REG_OFFSET 0x50 /* i2c clear tx abrt register */ #define I2CIP_CLR_TX_ABRT_REG_OFFSET 0x54 /* i2c clear rx done register */ #define I2CIP_CLR_RX_DONE_REG_OFFSET 0x58 /* i2c clear activity register */ #define I2CIP_CLR_ACTIVITY_REG_OFFSET 0x5c /* i2c clear stop det register */ #define I2CIP_CLR_STOP_DET_REG_OFFSET 0x60 /* i2c clear start det register */ #define I2CIP_CLR_START_DET_REG_OFFSET 0x64 /* i2c clear gen call register */ #define I2CIP_CLR_GEN_CALL_REG_OFFSET 0x68 /* i2c tx abrt source register */ #define I2CIP_TX_ABRT_SOURCE_REG_OFFSET 0x80 #define I2CIP_TX_ABRT_SOURCE_ABRT_SLVRD_INTX_SHIFT (15) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLVRD_INTX_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_SLVRD_INTX_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLV_ARBLOST_SHIFT (14) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLV_ARBLOST_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_SLV_ARBLOST_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLVFLUSH_TXFIFO_SHIFT (13) #define I2CIP_TX_ABRT_SOURCE_ABRT_SLVFLUSH_TXFIFO_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_SLVFLUSH_TXFIFO_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ARB_LOST_SHIFT (12) #define I2CIP_TX_ABRT_SOURCE_ARB_LOST_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ARB_LOST_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_MASTER_DIS_SHIFT (11) #define I2CIP_TX_ABRT_SOURCE_ABRT_MASTER_DIS_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_MASTER_DIS_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_10B_RD_NORSTRT_SHIFT (10) #define I2CIP_TX_ABRT_SOURCE_ABRT_10B_RD_NORSTRT_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_10B_RD_NORSTRT_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_NORSTRT_SHIFT (9) #define I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_NORSTRT_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_NORSTRT_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_HS_NORSTRT_SHIFT (8) #define I2CIP_TX_ABRT_SOURCE_ABRT_HS_NORSTRT_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_HS_NORSTRT_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_ACKDET_SHIFT (7) #define I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_ACKDET_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_SBYTE_ACKDET_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_HS_ACKDET_SHIFT (6) #define I2CIP_TX_ABRT_SOURCE_ABRT_HS_ACKDET_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_HS_ACKDET_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_READ_SHIFT (5) #define I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_READ_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_READ_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_NOACK_SHIFT (4) #define I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_NOACK_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_GCALL_NOACK_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_TXDATA_NOACK_SHIFT (3) #define I2CIP_TX_ABRT_SOURCE_ABRT_TXDATA_NOACK_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_TXDATA_NOACK_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR2_NOACK_SHIFT (2) #define I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR2_NOACK_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR2_NOACK_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR1_NOACK_SHIFT (1) #define I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR1_NOACK_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_10ADDR1_NOACK_SHIFT) #define I2CIP_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_SHIFT (0) #define I2CIP_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_MASK ((0x1)<<I2CIP_TX_ABRT_SOURCE_ABRT_7B_ADDR_NOACK_SHIFT) /* i2c dma control register */ #define I2CIP_DMA_CR_REG_OFFSET 0x88 #define I2CIP_DMA_CR_TDMAE_SHIFT (1) #define I2CIP_DMA_CR_TDMAE_MASK ((0x1)<<I2CIP_DMA_CR_TDMAE_SHIFT) #define I2CIP_DMA_CR_RDMAE_SHIFT (0) #define I2CIP_DMA_CR_RDMAE_MASK ((0x1)<<I2CIP_DMA_CR_RDMAE_SHIFT) /* i2c tx dma transfer threshold register */ #define I2CIP_DMA_TX_TL_REG_OFFSET 0x8c #define I2CIP_DMA_TX_TL_DEPTH (I2CIP_TX_FIFO_DEPTH) #define I2CIP_DMA_TX_TL_HALF (I2CIP_DMA_TX_TL_DEPTH/2) #define I2CIP_DMA_TX_TL_1_BYTE (1) /* i2c rx dma transfer threshold register */ #define I2CIP_DMA_RX_TL_REG_OFFSET 0x90 #define I2CIP_DMA_RX_TL_DEPTH (I2CIP_RX_FIFO_DEPTH) #define I2CIP_DMA_RX_TL_HALF (I2CIP_DMA_RX_TL_DEPTH/2) #define I2CIP_DMA_RX_TL_1_BYTE (1) #define I2CIP_IC_ENABLE_STATUS_REG_OFFSET 0x9C #define I2CIP_STATUS_IC_EN (1 << 0) #define I2CIP_STATUS_SLV_RX_ABORTED (1 << 1) #define I2CIP_STATUS_SLV_FIFO_FILLED_AND_FLUSHED (1 << 2) #define I2CIP_IC_FS_SPKLEN_REG_OFFSET 0xA0 #define I2CIP_IC_FS_SPKLEN_SHIFT 0 #define I2CIP_IC_FS_SPKLEN_MASK (0xFF << I2CIP_IC_FS_SPKLEN_SHIFT) #define I2CIP_IC_FS_SPKLEN(n) BITFIELD_VAL(I2CIP_IC_FS_SPKLEN, n) #define I2CIP_IC_HS_SPKLEN_REG_OFFSET 0xA4 #define I2CIP_IC_HS_SPKLEN_SHIFT 0 #define I2CIP_IC_HS_SPKLEN_MASK (0xFF << I2CIP_IC_FS_SPKLEN_SHIFT) #define I2CIP_IC_HS_SPKLEN(n) BITFIELD_VAL(I2CIP_IC_FS_SPKLEN, n) #define I2CIP_IC_VAD_PATH_REG_OFFSET 0xA8 #define I2CIP_IC_PUSH_DATA_BYPASS (1 << 0) /* Speed Selection */ #define IC_SPEED_MODE_STANDARD 1 #define IC_SPEED_MODE_FAST 2 #define IC_SPEED_MODE_MAX 3 #define I2C_MAX_SPEED 3400000 #define I2C_FSP_SPEED 1000000 #define I2C_FAST_SPEED 400000 #define I2C_STANDARD_SPEED 100000 #endif /* __REG_I2CIP_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/platform/hal/reg_i2cip.h
C
apache-2.0
16,815
/* ---------------------------------------------------------------------- * $Date: 5. February 2013 * $Revision: V1.02 * * Project: CMSIS-RTOS API * Title: cmsis_os.h template header file * * Version 0.02 * Initial Proposal Phase * Version 0.03 * osKernelStart added, optional feature: main started as thread * osSemaphores have standard behavior * osTimerCreate does not start the timer, added osTimerStart * osThreadPass is renamed to osThreadYield * Version 1.01 * Support for C++ interface * - const attribute removed from the osXxxxDef_t typedef's * - const attribute added to the osXxxxDef macros * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete * Added: osKernelInitialize * Version 1.02 * Control functions for short timeouts in microsecond resolution: * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec * Removed: osSignalGet *---------------------------------------------------------------------------- * * Copyright (c) 2013-2017 ARM LIMITED * * SPDX-License-Identifier: Apache-2.0 * * Licensed 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 * * 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. *---------------------------------------------------------------------------*/ /* * Copyright (C) 2015-2017 Alibaba Group Holding Limited */ #ifndef _CMSIS_OS_H #define _CMSIS_OS_H #include <stdint.h> #include <stddef.h> #include "k_api.h" #ifdef __ARM_ARCH_ISA_ARM #include "cmsis.h" #else #include "cmsis_compiler.h" #endif #define osCMSIS_RHINO 0xA0000U ///< RTOS identification and version (main[31:16].sub[15:0]) /// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version. #define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0]) /// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number. #define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0]) /// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS. #define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string /// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS. /* Memory Pools, Mail Queues, Signal is not supported yet */ #define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available /*not support yet*/ #define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available /*not support yet*/ #define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available #define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available /*not support yet*/ #define osFeature_Signals 1 ///< maximum number of Signal Flags available per thread #define osFeature_Semaphore 30 ///< maximum count for \ref osSemaphoreCreate function #define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available #define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available #ifdef OS_API_IN_INTLOCK // CAUTION: // It will be treated as in ISR when calling OS APIs in intlock(), but // the stack might still be using PSP instead of MSP. #define IN_ISR() (__get_IPSR() != 0 || __get_PRIMASK() != 0) #else #define IN_ISR() (__get_IPSR() != 0) #endif #ifdef __cplusplus extern "C" { #endif // ==== Enumeration, structures, defines ==== /// Priority used for thread control. /// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS. typedef enum { osPriorityIdle = -3, ///< priority: idle (lowest) osPriorityLow = -2, ///< priority: low osPriorityBelowNormal = -1, ///< priority: below normal osPriorityNormal = 0, ///< priority: normal (default) osPriorityAboveNormal = +1, ///< priority: above normal osPriorityHigh = +2, ///< priority: high osPriorityRealtime = +3, ///< priority: realtime (highest) osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority } osPriority; /// Timeout value. /// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS. #define osWaitForever 0xFFFFFFFF ///< wait forever timeout value /// Status code values returned by CMSIS-RTOS functions. /// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS. typedef enum { osOK = 0, ///< function completed; no error or event occurred. osEventSignal = 0x08, ///< function completed; signal event occurred. osEventMessage = 0x10, ///< function completed; message event occurred. osEventMail = 0x20, ///< function completed; mail event occurred. osEventTimeout = 0x40, ///< function completed; timeout occurred. osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. osErrorResource = 0x81, ///< resource not available: a specified resource was not available. osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. osErrorValue = 0x86, ///< value of a parameter is out of range. osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. } osStatus; /// Timer type value for the timer definition. /// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS. typedef enum { osTimerOnce = 0, ///< one-shot timer osTimerPeriodic = 1 ///< repeating timer } os_timer_type; /// Entry point of a thread. /// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS. typedef void (*os_pthread) (void const *argument); /// Entry point of a timer call back function. /// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS. typedef void (*os_ptimer) (void const *argument); // >>> the following data type definitions may shall adapted towards a specific RTOS /// Thread ID identifies the thread (pointer to a thread control block). /// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS. //typedef ktask_t *osThreadId; typedef struct { uint32_t tid; uint32_t alloc; // indicate if alloc pTask outside ktask_t * pTask; kevent_t * pEvent; task_entry_t func; void *pArg; }osThreadId_t, *osThreadId; /// Timer ID identifies the timer (pointer to a timer control block). /// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS. //typedef ktimer_t *osTimerId; typedef struct { ktimer_t * pTimer; os_ptimer cb; void * arg; }osTimerId_t, *osTimerId; /// Mutex ID identifies the mutex (pointer to a mutex control block). /// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS. typedef kmutex_t *osMutexId; /// Semaphore ID identifies the semaphore (pointer to a semaphore control block). /// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS. typedef ksem_t *osSemaphoreId; /// Pool ID identifies the memory pool (pointer to a memory pool control block). /// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS. typedef void *osPoolId; /// Message ID identifies the message queue (pointer to a message queue control block). /// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS. typedef kbuf_queue_t *osMessageQId; /// Mail ID identifies the mail queue (pointer to a mail queue control block). /// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS. //typedef kqueue_t *osMailQId; typedef void *osMailQId; /// Thread Definition structure contains startup information of a thread. /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. typedef struct os_thread_def { char *name; ///< Thread name os_pthread pthread; ///< start address of thread function osPriority tpriority; ///< initial thread priority uint32_t instances; ///< maximum number of instances of that thread function uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size tick_t ticks; ktask_t *ptcb; cpu_stack_t *pstackspace; } osThreadDef_t; /// Timer Definition structure contains timer parameters. /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS. typedef struct os_timer_def { char *name; os_ptimer ptimer; ///< start address of a timer function ktimer_t *timer; } osTimerDef_t; /// Mutex Definition structure contains setup information for a mutex. /// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS. typedef struct os_mutex_def { char *name; uint32_t dummy; ///< dummy value. kmutex_t *mutex; } osMutexDef_t; /// Semaphore Definition structure contains setup information for a semaphore. /// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS. typedef struct os_semaphore_def { char *name; uint32_t dummy; ///< dummy value. ksem_t *sem; } osSemaphoreDef_t; /// Definition structure for memory block allocation. /// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS. typedef struct os_pool_def { uint32_t pool_sz; ///< number of items (elements) in the pool uint32_t item_sz; ///< size of an item void *pool; ///< pointer to memory for pool } osPoolDef_t; /// Definition structure for message queue. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS. typedef struct os_messageQ_def { char *name; uint32_t queue_sz; ///< number of elements in the queue uint32_t item_sz; ///< size of an item void *pool; ///< memory array for messages kbuf_queue_t *queue; } osMessageQDef_t; /// Definition structure for mail queue. /// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS. #if 0 typedef struct os_mailQ_def { uint32_t queue_sz; ///< number of elements in the queue uint32_t item_sz; ///< size of an item void *pool; ///< memory array for mail } osMailQDef_t; #else typedef struct os_mailQ_def { osPoolDef_t mq_pool; ///< memory pool attributes void *mail; ///< pointer to mail } osMailQDef_t; #endif /// Event structure contains detailed information about an event. /// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS. /// However the struct may be extended at the end. typedef struct { osStatus status; ///< status code: event or error information union { uint32_t v; ///< message as 32-bit value void *p; ///< message or mail as void pointer int32_t signals; ///< signal flags } value; ///< event value union { osMailQId mail_id; ///< mail id obtained by \ref osMailCreate osMessageQId message_id; ///< message id obtained by \ref osMessageCreate } def; ///< event definition } osEvent; // ==== Kernel Control Functions ==== /// Initialize the RTOS Kernel for creating objects. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS. osStatus osKernelInitialize (void); /// Start the RTOS Kernel. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. osStatus osKernelStart (void); /// Check if the RTOS kernel is already started. /// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. /// \return 0 RTOS is not started, 1 RTOS is started. int32_t osKernelRunning(void); #if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available /// Get the RTOS kernel system timer counter /// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS. /// \return RTOS kernel system timer as 32-bit value uint32_t osKernelSysTick (void); /// The RTOS kernel system timer frequency in Hz /// \note Reflects the system timer setting and is typically defined in a configuration file. #define osKernelSysTickFrequency 100000000 /// Convert a microseconds value to a RTOS kernel system timer value. /// \param microsec time value in microseconds. /// \return time value normalized to the \ref osKernelSysTickFrequency #define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) #endif // System Timer available // ==== Thread Management ==== /// Create a Thread Definition with function, priority, and stack requirements. /// \param name name of the thread function. /// \param priority initial priority of the thread function. /// \param instances number of possible thread instances. /// \param stacksz stack size (in bytes) requirements for the thread function. /// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osThreadDef(name, priority, instances, stacksz) \ extern const osThreadDef_t os_thread_def_##name #else // define the object #define osThreadDef(name, priority, instances, stacksz, task_name) \ cpu_stack_t os_thread_stack_##name[stacksz/sizeof(cpu_stack_t)];\ const osThreadDef_t os_thread_def_##name = \ { (char *)(task_name), (os_pthread)(name), (osPriority)(priority), (uint32_t)(instances), (stacksz), \ (0), NULL, (os_thread_stack_##name)} #endif /// Access a Thread definition. /// \param name name of the thread definition object. /// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osThread(name) \ &os_thread_def_##name osStatus osThreadShow (osThreadId thread_id); /// Create a thread and add it to Active Threads and set it to state READY. /// \param[in] thread_def thread definition referenced with \ref osThread. /// \param[in] argument pointer that is passed to the thread function as start argument. /// \return thread ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS. osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); /// Return the thread ID of the current running thread. /// \return thread ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS. osThreadId osThreadGetId (void); /// Terminate execution of a thread and remove it from Active Threads. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS. osStatus osThreadTerminate (osThreadId thread_id); /// Pass control to next thread that is in state \b READY. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS. osStatus osThreadYield (void); /// Change priority of an active thread. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. /// \param[in] priority new priority value for the thread function. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS. osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); /// Get current priority of an active thread. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. /// \return current priority value of the thread function. /// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS. osPriority osThreadGetPriority (osThreadId thread_id); // ==== Generic Wait Functions ==== /// Wait for Timeout (Time Delay). /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value /// \return status code that indicates the execution status of the function. osStatus osDelay (uint32_t millisec); #if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available /// Wait for Signal, Message, Mail, or Timeout. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// \return event that contains signal, message, or mail information or error code. /// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS. osEvent osWait (uint32_t millisec); #endif // Generic Wait available // ==== Timer Management Functions ==== /// Define a Timer object. /// \param name name of the timer object. /// \param function name of the timer call back function. /// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osTimerDef(name, function) \ extern const osTimerDef_t os_timer_def_##name #else // define the object #define osTimerDef(name, function) \ const osTimerDef_t os_timer_def_##name = \ { (0), (os_ptimer)(function), (0)} #endif /// Access a Timer definition. /// \param name name of the timer object. /// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osTimer(name) \ &os_timer_def_##name /// Create a timer. /// \param[in] timer_def timer object referenced with \ref osTimer. /// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. /// \param[in] argument argument to the timer call back function. /// \return timer ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS. osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); /// Start or restart a timer. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS. osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); /// Stop the timer. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS. osStatus osTimerStop (osTimerId timer_id); /// Delete a timer that was created by \ref osTimerCreate. /// \param[in] timer_id timer ID obtained by \ref osTimerCreate. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS. osStatus osTimerDelete (osTimerId timer_id); // ==== Signal Management ==== not support yet /// Set the specified Signal Flags of an active thread. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. /// \param[in] signals specifies the signal flags of the thread that should be set. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. /// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS. int32_t osSignalSet (osThreadId thread_id, int32_t signals); /// Clear the specified Signal Flags of an active thread. /// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. /// \param[in] signals specifies the signal flags of the thread that shall be cleared. /// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. /// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS. int32_t osSignalClear (osThreadId thread_id, int32_t signals); /// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. /// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// \return event flag information or error code. /// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS. osEvent osSignalWait (int32_t signals, uint32_t millisec); // ==== Mutex Management ==== /// Define a Mutex. /// \param name name of the mutex object. /// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osMutexDef(name) \ extern const osMutexDef_t os_mutex_def_##name #else // define the object #define osMutexDef(name) \ const osMutexDef_t os_mutex_def_##name = {(0), (0), (0)} #endif /// Access a Mutex definition. /// \param name name of the mutex object. /// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osMutex(name) \ &os_mutex_def_##name osThreadId osMutexGetOwner (osMutexId mutex_id); /// Create and Initialize a Mutex object. /// \param[in] mutex_def mutex definition referenced with \ref osMutex. /// \return mutex ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS. osMutexId osMutexCreate (const osMutexDef_t *mutex_def); /// Wait until a Mutex becomes available. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS. osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); /// Release a Mutex that was obtained by \ref osMutexWait. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS. osStatus osMutexRelease (osMutexId mutex_id); /// Delete a Mutex that was created by \ref osMutexCreate. /// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS. osStatus osMutexDelete (osMutexId mutex_id); // ==== Semaphore Management Functions ==== #if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available /// Define a Semaphore object. /// \param name name of the semaphore object. /// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osSemaphoreDef(name) \ extern const osSemaphoreDef_t os_semaphore_def_##name #else // define the object #define osSemaphoreDef(name) \ const osSemaphoreDef_t os_semaphore_def_##name = {(0), (0), (0)} #endif /// Access a Semaphore definition. /// \param name name of the semaphore object. /// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osSemaphore(name) \ &os_semaphore_def_##name /// Create and Initialize a Semaphore object used for managing resources. /// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. /// \param[in] count number of available resources. /// \return semaphore ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS. osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); /// Wait until a Semaphore token becomes available. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// \return number of available tokens, or -1 in case of incorrect parameters. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS. int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); /// Release a Semaphore token. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS. osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); /// Delete a Semaphore that was created by \ref osSemaphoreCreate. /// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS. osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); #endif // Semaphore available // ==== Memory Pool Management Functions ==== not support yet #if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available /// \brief Define a Memory Pool. /// \param name name of the memory pool. /// \param no maximum number of blocks (objects) in the memory pool. /// \param type data type of a single block (object). /// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osPoolDef(name, no, type) \ extern const osPoolDef_t os_pool_def_##name #else // define the object #if 0 #define osPoolDef(name, no, type) const osPoolDef_t os_pool_def_##name = { (no), sizeof(type), NULL } #else #define osPoolDef(name, no, type) \ uint32_t os_pool_m_##name[3+((sizeof(type)+3)/4)*(no)]; \ const osPoolDef_t os_pool_def_##name = \ { (no), sizeof(type), (os_pool_m_##name) } #endif #endif /// \brief Access a Memory Pool definition. /// \param name name of the memory pool /// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osPool(name) \ &os_pool_def_##name /// Create and Initialize a memory pool. /// \param[in] pool_def memory pool definition referenced with \ref osPool. /// \return memory pool ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS. osPoolId osPoolCreate (const osPoolDef_t *pool_def); /// Allocate a memory block from a memory pool. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. /// \return address of the allocated memory block or NULL in case of no memory available. /// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS. void *osPoolAlloc (osPoolId pool_id); /// Allocate a memory block from a memory pool and set memory block to zero. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. /// \return address of the allocated memory block or NULL in case of no memory available. /// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS. void *osPoolCAlloc (osPoolId pool_id); /// Return an allocated memory block back to a specific memory pool. /// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. /// \param[in] block address of the allocated memory block that is returned to the memory pool. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS. osStatus osPoolFree (osPoolId pool_id, void *block); #endif // Memory Pool Management available // ==== Message Queue Management Functions ==== #if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available /// \brief Create a Message Queue Definition. /// \param name name of the queue. /// \param queue_sz maximum number of messages in the queue. /// \param type data type of a single message element (for debugger). /// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osMessageQDef(name, queue_sz, type) \ extern const osMessageQDef_t os_messageQ_def_##name #else // define the object #define osMessageQDef(name, queue_sz, type) \ const osMessageQDef_t os_messageQ_def_##name = \ {(0), (queue_sz), sizeof(type), (0), (0)} #endif /// \brief Access a Message Queue Definition. /// \param name name of the queue /// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osMessageQ(name) \ &os_messageQ_def_##name /// Create and Initialize a Message Queue. /// \param[in] queue_def queue definition referenced with \ref osMessageQ. /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. /// \return message queue ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS. osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); /// Put a Message to a Queue. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. /// \param[in] info message information. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS. osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); /// Get free Message Size of a Queue. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. /// \return free Message Size of a Queue. uint32_t osMessageGetSpace (osMessageQId queue_id); /// Get a Message or Wait for a Message from a Queue. /// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. /// \return event information that includes status code. /// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS. osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); osStatus osMessageQueueDelete (osMessageQId queue_id); #endif // Message Queues available // ==== Mail Queue Management Functions ==== not support yet #if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available /// \brief Create a Mail Queue Definition. /// \param name name of the queue /// \param queue_sz maximum number of messages in queue /// \param type data type of a single message element /// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #if defined (osObjectsExternal) // object is external #define osMailQDef(name, queue_sz, type) \ extern const osMailQDef_t os_mailQ_def_##name #else // define the object #if 0 #define osMailQDef(name, queue_sz, type) const osMailQDef_t os_mailQ_def_##name = { (queue_sz), sizeof (type) } #else #define osMailQDef(name, queue_sz, type) \ static uint32_t os_mailQ_m_##name[3+((sizeof(type)+3)/4)*(queue_sz)]; \ osMailQDef_t os_mailQ_def_##name = \ { {(queue_sz), sizeof(type), (os_mailQ_m_##name)}, NULL} #endif #endif /// \brief Access a Mail Queue Definition. /// \param name name of the queue /// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the /// macro body is implementation specific in every CMSIS-RTOS. #define osMailQ(name) \ &os_mailQ_def_##name /// Create and Initialize mail queue. /// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ /// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. /// \return mail queue ID for reference by other functions or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS. osMailQId osMailCreate (osMailQDef_t *queue_def, osThreadId thread_id); /// Allocate a memory block from a mail. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// \return pointer to memory block that can be filled with mail or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS. void *osMailAlloc (osMailQId queue_id, uint32_t millisec); /// Allocate a memory block from a mail and set memory block to zero. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// \return pointer to memory block that can be filled with mail or NULL in case of error. /// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS. void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); /// Put a mail to a queue. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. /// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS. osStatus osMailPut (osMailQId queue_id, void *mail); /// Get a mail from a queue. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. /// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out /// \return event that contains mail information or error code. /// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS. osEvent osMailGet (osMailQId queue_id, uint32_t millisec); /// Free a memory block from a mail. /// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. /// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet. /// \return status code that indicates the execution status of the function. /// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS. osStatus osMailFree (osMailQId queue_id, void *mail); #endif // Mail Queues available #define DEFAULT_STACK_SIZE (1024*4) void os_error_str (const char *fmt, ...); int osGetThreadIntId (void); const char *osGetThreadName (void); osStatus osThreadGetState(osThreadId thread_id); void osThreadExitPub (void); uint32_t osThreadGetPrivData(osThreadId thread_id); uint32_t osThreadSetPrivData(osThreadId thread_id, uint32_t privdata); /* cmsis interface thread name */ const char *osThreadGetName (osThreadId id); /* rhino interface thread name */ const char *osGetThreadName(); #ifdef __cplusplus } #endif #endif // _CMSIS_OS_H
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/cmsis/cmsis_os.h
C
apache-2.0
39,344
/*---------------------------------------------------------------------------- * RL-ARM - RTX *---------------------------------------------------------------------------- * Name: RT_MEMBOX.H * Purpose: Interface functions for fixed memory block management system * Rev.: V4.60 *---------------------------------------------------------------------------- * * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - 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. * - Neither the name of ARM nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDERS AND CONTRIBUTORS 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 __MEMBOX_H__ #define __MEMBOX_H__ /* Definitions */ #define BOX_ALIGN_8 0x80000000 /* Functions */ typedef struct OS_BM { void *free; /* Pointer to first free memory block */ void *end; /* Pointer to memory block end */ uint32_t blk_size; /* Memory block size */ } *P_BM; #define rt_init_box _init_box #define rt_calloc_box _calloc_box int _init_box (void *box_mem, uint32_t box_size, uint32_t blk_size); void *rt_alloc_box (void *box_mem); void * _calloc_box (void *box_mem); int rt_free_box (void *box_mem, void *box); /*---------------------------------------------------------------------------- * end of file *---------------------------------------------------------------------------*/ #endif /*__MEMBOX_H__*/
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/cmsis/k_membox.h
C
apache-2.0
2,914
#ifndef __CURL_CURL_H #define __CURL_CURL_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* * If you have libcurl problems, all docs and details are found here: * https://curl.haxx.se/libcurl/ * * curl-library mailing list subscription and unsubscription web interface: * https://cool.haxx.se/mailman/listinfo/curl-library/ */ #ifdef CURL_NO_OLDIES #define CURL_STRICTER #endif #include "curlver.h" /* libcurl version defines */ #include "system.h" /* determine things run-time */ /* * Define WIN32 when build target is Win32 API */ #if (defined(_WIN32) || defined(__WIN32__)) && \ !defined(WIN32) && !defined(__SYMBIAN32__) #define WIN32 #endif #include <stdio.h> #include <limits.h> #if defined(__FreeBSD__) && (__FreeBSD__ >= 2) /* Needed for __FreeBSD_version symbol definition */ #include <osreldate.h> #endif /* The include stuff here below is mainly for time_t! */ #include <sys/types.h> #include <time.h> #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) #if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \ defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)) /* The check above prevents the winsock2 inclusion if winsock.h already was included, since they can't co-exist without problems */ #include <winsock2.h> #include <ws2tcpip.h> #endif #endif /* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish libc5-based Linux systems. Only include it on systems that are known to require it! */ #if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \ defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \ defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \ defined(__CYGWIN__) || \ (defined(__FreeBSD_version) && (__FreeBSD_version < 800000)) #include <sys/select.h> #endif #if !defined(WIN32) && !defined(_WIN32_WCE) #ifdef USE_LWIPSOCK #include <lwip/sockets.h> #else #include <sys/socket.h> #endif #endif #if !defined(WIN32) && !defined(__WATCOMC__) && !defined(__VXWORKS__) #include <sys/time.h> #endif #ifdef __BEOS__ #include <support/SupportDefs.h> #endif /* Compatibility for non-Clang compilers */ #ifndef __has_declspec_attribute # define __has_declspec_attribute(x) 0 #endif #ifdef __cplusplus extern "C" { #endif #if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) typedef struct Curl_easy CURL; typedef struct Curl_share CURLSH; #else typedef void CURL; typedef void CURLSH; #endif /* * libcurl external API function linkage decorations. */ #ifdef CURL_STATICLIB # define CURL_EXTERN #elif defined(WIN32) || defined(__SYMBIAN32__) || \ (__has_declspec_attribute(dllexport) && \ __has_declspec_attribute(dllimport)) # if defined(BUILDING_LIBCURL) # define CURL_EXTERN __declspec(dllexport) # else # define CURL_EXTERN __declspec(dllimport) # endif #elif defined(BUILDING_LIBCURL) && defined(CURL_HIDDEN_SYMBOLS) # define CURL_EXTERN CURL_EXTERN_SYMBOL #else # define CURL_EXTERN #endif #ifndef curl_socket_typedef /* socket typedef */ #if defined(WIN32) && !defined(__LWIP_OPT_H__) && !defined(LWIP_HDR_OPT_H) typedef SOCKET curl_socket_t; #define CURL_SOCKET_BAD INVALID_SOCKET #else typedef int curl_socket_t; #define CURL_SOCKET_BAD -1 #endif #define curl_socket_typedef #endif /* curl_socket_typedef */ /* enum for the different supported SSL backends */ typedef enum { CURLSSLBACKEND_NONE = 0, CURLSSLBACKEND_OPENSSL = 1, CURLSSLBACKEND_GNUTLS = 2, CURLSSLBACKEND_NSS = 3, CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */ CURLSSLBACKEND_GSKIT = 5, CURLSSLBACKEND_POLARSSL = 6, CURLSSLBACKEND_WOLFSSL = 7, CURLSSLBACKEND_SCHANNEL = 8, CURLSSLBACKEND_SECURETRANSPORT = 9, CURLSSLBACKEND_AXTLS = 10, /* never used since 7.63.0 */ CURLSSLBACKEND_MBEDTLS = 11, CURLSSLBACKEND_MESALINK = 12 } curl_sslbackend; /* aliases for library clones and renames */ #define CURLSSLBACKEND_LIBRESSL CURLSSLBACKEND_OPENSSL #define CURLSSLBACKEND_BORINGSSL CURLSSLBACKEND_OPENSSL /* deprecated names: */ #define CURLSSLBACKEND_CYASSL CURLSSLBACKEND_WOLFSSL #define CURLSSLBACKEND_DARWINSSL CURLSSLBACKEND_SECURETRANSPORT struct curl_httppost { struct curl_httppost *next; /* next entry in the list */ char *name; /* pointer to allocated name */ long namelength; /* length of name length */ char *contents; /* pointer to allocated data contents */ long contentslength; /* length of contents field, see also CURL_HTTPPOST_LARGE */ char *buffer; /* pointer to allocated buffer contents */ long bufferlength; /* length of buffer field */ char *contenttype; /* Content-Type */ struct curl_slist *contentheader; /* list of extra headers for this form */ struct curl_httppost *more; /* if one field name has more than one file, this link should link to following files */ long flags; /* as defined below */ /* specified content is a file name */ #define CURL_HTTPPOST_FILENAME (1<<0) /* specified content is a file name */ #define CURL_HTTPPOST_READFILE (1<<1) /* name is only stored pointer do not free in formfree */ #define CURL_HTTPPOST_PTRNAME (1<<2) /* contents is only stored pointer do not free in formfree */ #define CURL_HTTPPOST_PTRCONTENTS (1<<3) /* upload file from buffer */ #define CURL_HTTPPOST_BUFFER (1<<4) /* upload file from pointer contents */ #define CURL_HTTPPOST_PTRBUFFER (1<<5) /* upload file contents by using the regular read callback to get the data and pass the given pointer as custom pointer */ #define CURL_HTTPPOST_CALLBACK (1<<6) /* use size in 'contentlen', added in 7.46.0 */ #define CURL_HTTPPOST_LARGE (1<<7) char *showfilename; /* The file name to show. If not set, the actual file name will be used (if this is a file part) */ void *userp; /* custom pointer used for HTTPPOST_CALLBACK posts */ curl_off_t contentlen; /* alternative length of contents field. Used if CURL_HTTPPOST_LARGE is set. Added in 7.46.0 */ }; /* This is the CURLOPT_PROGRESSFUNCTION callback proto. It is now considered deprecated but was the only choice up until 7.31.0 */ typedef int (*curl_progress_callback)(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); /* This is the CURLOPT_XFERINFOFUNCTION callback proto. It was introduced in 7.32.0, it avoids floating point and provides more detailed information. */ typedef int (*curl_xferinfo_callback)(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); #ifndef CURL_MAX_READ_SIZE /* The maximum receive buffer size configurable via CURLOPT_BUFFERSIZE. */ #define CURL_MAX_READ_SIZE 524288 #endif #ifndef CURL_MAX_WRITE_SIZE /* Tests have proven that 20K is a very bad buffer size for uploads on Windows, while 16K for some odd reason performed a lot better. We do the ifndef check to allow this value to easier be changed at build time for those who feel adventurous. The practical minimum is about 400 bytes since libcurl uses a buffer of this size as a scratch area (unrelated to network send operations). */ #define CURL_MAX_WRITE_SIZE 16384 #endif #ifndef CURL_MAX_HTTP_HEADER /* The only reason to have a max limit for this is to avoid the risk of a bad server feeding libcurl with a never-ending header that will cause reallocs infinitely */ #define CURL_MAX_HTTP_HEADER (100*1024) #endif /* This is a magic return code for the write callback that, when returned, will signal libcurl to pause receiving on the current transfer. */ #define CURL_WRITEFUNC_PAUSE 0x10000001 typedef size_t (*curl_write_callback)(char *buffer, size_t size, size_t nitems, void *outstream); /* This callback will be called when a new resolver request is made */ typedef int (*curl_resolver_start_callback)(void *resolver_state, void *reserved, void *userdata); /* enumeration of file types */ typedef enum { CURLFILETYPE_FILE = 0, CURLFILETYPE_DIRECTORY, CURLFILETYPE_SYMLINK, CURLFILETYPE_DEVICE_BLOCK, CURLFILETYPE_DEVICE_CHAR, CURLFILETYPE_NAMEDPIPE, CURLFILETYPE_SOCKET, CURLFILETYPE_DOOR, /* is possible only on Sun Solaris now */ CURLFILETYPE_UNKNOWN /* should never occur */ } curlfiletype; #define CURLFINFOFLAG_KNOWN_FILENAME (1<<0) #define CURLFINFOFLAG_KNOWN_FILETYPE (1<<1) #define CURLFINFOFLAG_KNOWN_TIME (1<<2) #define CURLFINFOFLAG_KNOWN_PERM (1<<3) #define CURLFINFOFLAG_KNOWN_UID (1<<4) #define CURLFINFOFLAG_KNOWN_GID (1<<5) #define CURLFINFOFLAG_KNOWN_SIZE (1<<6) #define CURLFINFOFLAG_KNOWN_HLINKCOUNT (1<<7) /* Content of this structure depends on information which is known and is achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man page for callbacks returning this structure -- some fields are mandatory, some others are optional. The FLAG field has special meaning. */ struct curl_fileinfo { char *filename; curlfiletype filetype; time_t time; /* always zero! */ unsigned int perm; int uid; int gid; curl_off_t size; long int hardlinks; struct { /* If some of these fields is not NULL, it is a pointer to b_data. */ char *time; char *perm; char *user; char *group; char *target; /* pointer to the target filename of a symlink */ } strings; unsigned int flags; /* used internally */ char *b_data; size_t b_size; size_t b_used; }; /* return codes for CURLOPT_CHUNK_BGN_FUNCTION */ #define CURL_CHUNK_BGN_FUNC_OK 0 #define CURL_CHUNK_BGN_FUNC_FAIL 1 /* tell the lib to end the task */ #define CURL_CHUNK_BGN_FUNC_SKIP 2 /* skip this chunk over */ /* if splitting of data transfer is enabled, this callback is called before download of an individual chunk started. Note that parameter "remains" works only for FTP wildcard downloading (for now), otherwise is not used */ typedef long (*curl_chunk_bgn_callback)(const void *transfer_info, void *ptr, int remains); /* return codes for CURLOPT_CHUNK_END_FUNCTION */ #define CURL_CHUNK_END_FUNC_OK 0 #define CURL_CHUNK_END_FUNC_FAIL 1 /* tell the lib to end the task */ /* If splitting of data transfer is enabled this callback is called after download of an individual chunk finished. Note! After this callback was set then it have to be called FOR ALL chunks. Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. This is the reason why we don't need "transfer_info" parameter in this callback and we are not interested in "remains" parameter too. */ typedef long (*curl_chunk_end_callback)(void *ptr); /* return codes for FNMATCHFUNCTION */ #define CURL_FNMATCHFUNC_MATCH 0 /* string corresponds to the pattern */ #define CURL_FNMATCHFUNC_NOMATCH 1 /* pattern doesn't match the string */ #define CURL_FNMATCHFUNC_FAIL 2 /* an error occurred */ /* callback type for wildcard downloading pattern matching. If the string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ typedef int (*curl_fnmatch_callback)(void *ptr, const char *pattern, const char *string); /* These are the return codes for the seek callbacks */ #define CURL_SEEKFUNC_OK 0 #define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */ #define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so libcurl might try other means instead */ typedef int (*curl_seek_callback)(void *instream, curl_off_t offset, int origin); /* 'whence' */ /* This is a return code for the read callback that, when returned, will signal libcurl to immediately abort the current transfer. */ #define CURL_READFUNC_ABORT 0x10000000 /* This is a return code for the read callback that, when returned, will signal libcurl to pause sending data on the current transfer. */ #define CURL_READFUNC_PAUSE 0x10000001 /* Return code for when the trailing headers' callback has terminated without any errors*/ #define CURL_TRAILERFUNC_OK 0 /* Return code for when was an error in the trailing header's list and we want to abort the request */ #define CURL_TRAILERFUNC_ABORT 1 typedef size_t (*curl_read_callback)(char *buffer, size_t size, size_t nitems, void *instream); typedef int (*curl_trailer_callback)(struct curl_slist **list, void *userdata); typedef enum { CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */ CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */ CURLSOCKTYPE_LAST /* never use */ } curlsocktype; /* The return code from the sockopt_callback can signal information back to libcurl: */ #define CURL_SOCKOPT_OK 0 #define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return CURLE_ABORTED_BY_CALLBACK */ #define CURL_SOCKOPT_ALREADY_CONNECTED 2 typedef int (*curl_sockopt_callback)(void *clientp, curl_socket_t curlfd, curlsocktype purpose); struct curl_sockaddr { int family; int socktype; int protocol; unsigned int addrlen; /* addrlen was a socklen_t type before 7.18.0 but it turned really ugly and painful on the systems that lack this type */ struct sockaddr addr; }; typedef curl_socket_t (*curl_opensocket_callback)(void *clientp, curlsocktype purpose, struct curl_sockaddr *address); typedef int (*curl_closesocket_callback)(void *clientp, curl_socket_t item); typedef enum { CURLIOE_OK, /* I/O operation successful */ CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ CURLIOE_FAILRESTART, /* failed to restart the read */ CURLIOE_LAST /* never use */ } curlioerr; typedef enum { CURLIOCMD_NOP, /* no operation */ CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ CURLIOCMD_LAST /* never use */ } curliocmd; typedef curlioerr (*curl_ioctl_callback)(CURL *handle, int cmd, void *clientp); #ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS /* * The following typedef's are signatures of malloc, free, realloc, strdup and * calloc respectively. Function pointers of these types can be passed to the * curl_global_init_mem() function to set user defined memory management * callback routines. */ typedef void *(*curl_malloc_callback)(size_t size); typedef void (*curl_free_callback)(void *ptr); typedef void *(*curl_realloc_callback)(void *ptr, size_t size); typedef char *(*curl_strdup_callback)(const char *str); typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); #define CURL_DID_MEMORY_FUNC_TYPEDEFS #endif /* the kind of data that is passed to information_callback*/ typedef enum { CURLINFO_TEXT = 0, CURLINFO_HEADER_IN, /* 1 */ CURLINFO_HEADER_OUT, /* 2 */ CURLINFO_DATA_IN, /* 3 */ CURLINFO_DATA_OUT, /* 4 */ CURLINFO_SSL_DATA_IN, /* 5 */ CURLINFO_SSL_DATA_OUT, /* 6 */ CURLINFO_END } curl_infotype; typedef int (*curl_debug_callback) (CURL *handle, /* the handle/transfer this concerns */ curl_infotype type, /* what kind of data */ char *data, /* points to the data */ size_t size, /* size of the data pointed to */ void *userptr); /* whatever the user please */ /* All possible error codes from all sorts of curl functions. Future versions may return other values, stay prepared. Always add new return codes last. Never *EVER* remove any. The return codes must remain the same! */ typedef enum { CURLE_OK = 0, CURLE_UNSUPPORTED_PROTOCOL, /* 1 */ CURLE_FAILED_INIT, /* 2 */ CURLE_URL_MALFORMAT, /* 3 */ CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for 7.17.0, reused in April 2011 for 7.21.5] */ CURLE_COULDNT_RESOLVE_PROXY, /* 5 */ CURLE_COULDNT_RESOLVE_HOST, /* 6 */ CURLE_COULDNT_CONNECT, /* 7 */ CURLE_WEIRD_SERVER_REPLY, /* 8 */ CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server due to lack of access - when login fails this is not returned. */ CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for 7.15.4, reused in Dec 2011 for 7.24.0]*/ CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */ CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server [was obsoleted in August 2007 for 7.17.0, reused in Dec 2011 for 7.24.0]*/ CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */ CURLE_FTP_WEIRD_227_FORMAT, /* 14 */ CURLE_FTP_CANT_GET_HOST, /* 15 */ CURLE_HTTP2, /* 16 - A problem in the http2 framing layer. [was obsoleted in August 2007 for 7.17.0, reused in July 2014 for 7.38.0] */ CURLE_FTP_COULDNT_SET_TYPE, /* 17 */ CURLE_PARTIAL_FILE, /* 18 */ CURLE_FTP_COULDNT_RETR_FILE, /* 19 */ CURLE_OBSOLETE20, /* 20 - NOT USED */ CURLE_QUOTE_ERROR, /* 21 - quote command failure */ CURLE_HTTP_RETURNED_ERROR, /* 22 */ CURLE_WRITE_ERROR, /* 23 */ CURLE_OBSOLETE24, /* 24 - NOT USED */ CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */ CURLE_READ_ERROR, /* 26 - couldn't open/read from file */ CURLE_OUT_OF_MEMORY, /* 27 */ /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error instead of a memory allocation error if CURL_DOES_CONVERSIONS is defined */ CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */ CURLE_OBSOLETE29, /* 29 - NOT USED */ CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */ CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */ CURLE_OBSOLETE32, /* 32 - NOT USED */ CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */ CURLE_HTTP_POST_ERROR, /* 34 */ CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */ CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */ CURLE_FILE_COULDNT_READ_FILE, /* 37 */ CURLE_LDAP_CANNOT_BIND, /* 38 */ CURLE_LDAP_SEARCH_FAILED, /* 39 */ CURLE_OBSOLETE40, /* 40 - NOT USED */ CURLE_FUNCTION_NOT_FOUND, /* 41 - NOT USED starting with 7.53.0 */ CURLE_ABORTED_BY_CALLBACK, /* 42 */ CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */ CURLE_OBSOLETE44, /* 44 - NOT USED */ CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */ CURLE_OBSOLETE46, /* 46 - NOT USED */ CURLE_TOO_MANY_REDIRECTS, /* 47 - catch endless re-direct loops */ CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */ CURLE_TELNET_OPTION_SYNTAX, /* 49 - Malformed telnet option */ CURLE_OBSOLETE50, /* 50 - NOT USED */ CURLE_OBSOLETE51, /* 51 - NOT USED */ CURLE_GOT_NOTHING, /* 52 - when this is a specific error */ CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */ CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as default */ CURLE_SEND_ERROR, /* 55 - failed sending network data */ CURLE_RECV_ERROR, /* 56 - failure in receiving network data */ CURLE_OBSOLETE57, /* 57 - NOT IN USE */ CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */ CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */ CURLE_PEER_FAILED_VERIFICATION, /* 60 - peer's certificate or fingerprint wasn't verified fine */ CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */ CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */ CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */ CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */ CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind that failed */ CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */ CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not accepted and we failed to login */ CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */ CURLE_TFTP_PERM, /* 69 - permission problem on server */ CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */ CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */ CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */ CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */ CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */ CURLE_CONV_FAILED, /* 75 - conversion failed */ CURLE_CONV_REQD, /* 76 - caller must register conversion callbacks using curl_easy_setopt options CURLOPT_CONV_FROM_NETWORK_FUNCTION, CURLOPT_CONV_TO_NETWORK_FUNCTION, and CURLOPT_CONV_FROM_UTF8_FUNCTION */ CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing or wrong format */ CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */ CURLE_SSH, /* 79 - error from the SSH layer, somewhat generic so the error message will be of interest when this has happened */ CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL connection */ CURLE_AGAIN, /* 81 - socket is not ready for send/recv, wait till it's ready and try again (Added in 7.18.2) */ CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or wrong format (Added in 7.19.0) */ CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in 7.19.0) */ CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */ CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */ CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */ CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */ CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */ CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the session will be queued */ CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not match */ CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */ CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer */ CURLE_RECURSIVE_API_CALL, /* 93 - an api function was called from inside a callback */ CURL_LAST /* never use! */ } CURLcode; #ifndef CURL_NO_OLDIES /* define this to test if your app builds with all the obsolete stuff removed! */ /* Previously obsolete error code re-used in 7.38.0 */ #define CURLE_OBSOLETE16 CURLE_HTTP2 /* Previously obsolete error codes re-used in 7.24.0 */ #define CURLE_OBSOLETE10 CURLE_FTP_ACCEPT_FAILED #define CURLE_OBSOLETE12 CURLE_FTP_ACCEPT_TIMEOUT /* compatibility with older names */ #define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING #define CURLE_FTP_WEIRD_SERVER_REPLY CURLE_WEIRD_SERVER_REPLY /* The following were added in 7.62.0 */ #define CURLE_SSL_CACERT CURLE_PEER_FAILED_VERIFICATION /* The following were added in 7.21.5, April 2011 */ #define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION /* The following were added in 7.17.1 */ /* These are scheduled to disappear by 2009 */ #define CURLE_SSL_PEER_CERTIFICATE CURLE_PEER_FAILED_VERIFICATION /* The following were added in 7.17.0 */ /* These are scheduled to disappear by 2009 */ #define CURLE_OBSOLETE CURLE_OBSOLETE50 /* no one should be using this! */ #define CURLE_BAD_PASSWORD_ENTERED CURLE_OBSOLETE46 #define CURLE_BAD_CALLING_ORDER CURLE_OBSOLETE44 #define CURLE_FTP_USER_PASSWORD_INCORRECT CURLE_OBSOLETE10 #define CURLE_FTP_CANT_RECONNECT CURLE_OBSOLETE16 #define CURLE_FTP_COULDNT_GET_SIZE CURLE_OBSOLETE32 #define CURLE_FTP_COULDNT_SET_ASCII CURLE_OBSOLETE29 #define CURLE_FTP_WEIRD_USER_REPLY CURLE_OBSOLETE12 #define CURLE_FTP_WRITE_ERROR CURLE_OBSOLETE20 #define CURLE_LIBRARY_NOT_FOUND CURLE_OBSOLETE40 #define CURLE_MALFORMAT_USER CURLE_OBSOLETE24 #define CURLE_SHARE_IN_USE CURLE_OBSOLETE57 #define CURLE_URL_MALFORMAT_USER CURLE_NOT_BUILT_IN #define CURLE_FTP_ACCESS_DENIED CURLE_REMOTE_ACCESS_DENIED #define CURLE_FTP_COULDNT_SET_BINARY CURLE_FTP_COULDNT_SET_TYPE #define CURLE_FTP_QUOTE_ERROR CURLE_QUOTE_ERROR #define CURLE_TFTP_DISKFULL CURLE_REMOTE_DISK_FULL #define CURLE_TFTP_EXISTS CURLE_REMOTE_FILE_EXISTS #define CURLE_HTTP_RANGE_ERROR CURLE_RANGE_ERROR #define CURLE_FTP_SSL_FAILED CURLE_USE_SSL_FAILED /* The following were added earlier */ #define CURLE_OPERATION_TIMEOUTED CURLE_OPERATION_TIMEDOUT #define CURLE_HTTP_NOT_FOUND CURLE_HTTP_RETURNED_ERROR #define CURLE_HTTP_PORT_FAILED CURLE_INTERFACE_FAILED #define CURLE_FTP_COULDNT_STOR_FILE CURLE_UPLOAD_FAILED #define CURLE_FTP_PARTIAL_FILE CURLE_PARTIAL_FILE #define CURLE_FTP_BAD_DOWNLOAD_RESUME CURLE_BAD_DOWNLOAD_RESUME /* This was the error code 50 in 7.7.3 and a few earlier versions, this is no longer used by libcurl but is instead #defined here only to not make programs break */ #define CURLE_ALREADY_COMPLETE 99999 /* Provide defines for really old option names */ #define CURLOPT_FILE CURLOPT_WRITEDATA /* name changed in 7.9.7 */ #define CURLOPT_INFILE CURLOPT_READDATA /* name changed in 7.9.7 */ #define CURLOPT_WRITEHEADER CURLOPT_HEADERDATA /* Since long deprecated options with no code in the lib that does anything with them. */ #define CURLOPT_WRITEINFO CURLOPT_OBSOLETE40 #define CURLOPT_CLOSEPOLICY CURLOPT_OBSOLETE72 #endif /*!CURL_NO_OLDIES*/ /* This prototype applies to all conversion callbacks */ typedef CURLcode (*curl_conv_callback)(char *buffer, size_t length); typedef CURLcode (*curl_ssl_ctx_callback)(CURL *curl, /* easy handle */ void *ssl_ctx, /* actually an OpenSSL SSL_CTX */ void *userptr); typedef enum { CURLPROXY_HTTP = 0, /* added in 7.10, new in 7.19.4 default is to use CONNECT HTTP/1.1 */ CURLPROXY_HTTP_1_0 = 1, /* added in 7.19.4, force to use CONNECT HTTP/1.0 */ CURLPROXY_HTTPS = 2, /* added in 7.52.0 */ CURLPROXY_SOCKS4 = 4, /* support added in 7.15.2, enum existed already in 7.10 */ CURLPROXY_SOCKS5 = 5, /* added in 7.10 */ CURLPROXY_SOCKS4A = 6, /* added in 7.18.0 */ CURLPROXY_SOCKS5_HOSTNAME = 7 /* Use the SOCKS5 protocol but pass along the host name rather than the IP address. added in 7.18.0 */ } curl_proxytype; /* this enum was added in 7.10 */ /* * Bitmasks for CURLOPT_HTTPAUTH and CURLOPT_PROXYAUTH options: * * CURLAUTH_NONE - No HTTP authentication * CURLAUTH_BASIC - HTTP Basic authentication (default) * CURLAUTH_DIGEST - HTTP Digest authentication * CURLAUTH_NEGOTIATE - HTTP Negotiate (SPNEGO) authentication * CURLAUTH_GSSNEGOTIATE - Alias for CURLAUTH_NEGOTIATE (deprecated) * CURLAUTH_NTLM - HTTP NTLM authentication * CURLAUTH_DIGEST_IE - HTTP Digest authentication with IE flavour * CURLAUTH_NTLM_WB - HTTP NTLM authentication delegated to winbind helper * CURLAUTH_BEARER - HTTP Bearer token authentication * CURLAUTH_ONLY - Use together with a single other type to force no * authentication or just that single type * CURLAUTH_ANY - All fine types set * CURLAUTH_ANYSAFE - All fine types except Basic */ #define CURLAUTH_NONE ((unsigned long)0) #define CURLAUTH_BASIC (((unsigned long)1)<<0) #define CURLAUTH_DIGEST (((unsigned long)1)<<1) #define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2) /* Deprecated since the advent of CURLAUTH_NEGOTIATE */ #define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE /* Used for CURLOPT_SOCKS5_AUTH to stay terminologically correct */ #define CURLAUTH_GSSAPI CURLAUTH_NEGOTIATE #define CURLAUTH_NTLM (((unsigned long)1)<<3) #define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4) #define CURLAUTH_NTLM_WB (((unsigned long)1)<<5) #define CURLAUTH_BEARER (((unsigned long)1)<<6) #define CURLAUTH_ONLY (((unsigned long)1)<<31) #define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE) #define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) #define CURLSSH_AUTH_ANY ~0 /* all types supported by the server */ #define CURLSSH_AUTH_NONE 0 /* none allowed, silly but complete */ #define CURLSSH_AUTH_PUBLICKEY (1<<0) /* public/private key files */ #define CURLSSH_AUTH_PASSWORD (1<<1) /* password */ #define CURLSSH_AUTH_HOST (1<<2) /* host key files */ #define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */ #define CURLSSH_AUTH_AGENT (1<<4) /* agent (ssh-agent, pageant...) */ #define CURLSSH_AUTH_GSSAPI (1<<5) /* gssapi (kerberos, ...) */ #define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY #define CURLGSSAPI_DELEGATION_NONE 0 /* no delegation (default) */ #define CURLGSSAPI_DELEGATION_POLICY_FLAG (1<<0) /* if permitted by policy */ #define CURLGSSAPI_DELEGATION_FLAG (1<<1) /* delegate always */ #define CURL_ERROR_SIZE 256 enum curl_khtype { CURLKHTYPE_UNKNOWN, CURLKHTYPE_RSA1, CURLKHTYPE_RSA, CURLKHTYPE_DSS, CURLKHTYPE_ECDSA, CURLKHTYPE_ED25519 }; struct curl_khkey { const char *key; /* points to a zero-terminated string encoded with base64 if len is zero, otherwise to the "raw" data */ size_t len; enum curl_khtype keytype; }; /* this is the set of return values expected from the curl_sshkeycallback callback */ enum curl_khstat { CURLKHSTAT_FINE_ADD_TO_FILE, CURLKHSTAT_FINE, CURLKHSTAT_REJECT, /* reject the connection, return an error */ CURLKHSTAT_DEFER, /* do not accept it, but we can't answer right now so this causes a CURLE_DEFER error but otherwise the connection will be left intact etc */ CURLKHSTAT_LAST /* not for use, only a marker for last-in-list */ }; /* this is the set of status codes pass in to the callback */ enum curl_khmatch { CURLKHMATCH_OK, /* match */ CURLKHMATCH_MISMATCH, /* host found, key mismatch! */ CURLKHMATCH_MISSING, /* no matching host/key found */ CURLKHMATCH_LAST /* not for use, only a marker for last-in-list */ }; typedef int (*curl_sshkeycallback) (CURL *easy, /* easy handle */ const struct curl_khkey *knownkey, /* known */ const struct curl_khkey *foundkey, /* found */ enum curl_khmatch, /* libcurl's view on the keys */ void *clientp); /* custom pointer passed from app */ /* parameter for the CURLOPT_USE_SSL option */ typedef enum { CURLUSESSL_NONE, /* do not attempt to use SSL */ CURLUSESSL_TRY, /* try using SSL, proceed anyway otherwise */ CURLUSESSL_CONTROL, /* SSL for the control connection or fail */ CURLUSESSL_ALL, /* SSL for all communication or fail */ CURLUSESSL_LAST /* not an option, never use */ } curl_usessl; /* Definition of bits for the CURLOPT_SSL_OPTIONS argument: */ /* - ALLOW_BEAST tells libcurl to allow the BEAST SSL vulnerability in the name of improving interoperability with older servers. Some SSL libraries have introduced work-arounds for this flaw but those work-arounds sometimes make the SSL communication fail. To regain functionality with those broken servers, a user can this way allow the vulnerability back. */ #define CURLSSLOPT_ALLOW_BEAST (1<<0) /* - NO_REVOKE tells libcurl to disable certificate revocation checks for those SSL backends where such behavior is present. */ #define CURLSSLOPT_NO_REVOKE (1<<1) /* The default connection attempt delay in milliseconds for happy eyeballs. CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.3 and happy-eyeballs-timeout-ms.d document this value, keep them in sync. */ #define CURL_HET_DEFAULT 200L /* The default connection upkeep interval in milliseconds. */ #define CURL_UPKEEP_INTERVAL_DEFAULT 60000L #ifndef CURL_NO_OLDIES /* define this to test if your app builds with all the obsolete stuff removed! */ /* Backwards compatibility with older names */ /* These are scheduled to disappear by 2009 */ #define CURLFTPSSL_NONE CURLUSESSL_NONE #define CURLFTPSSL_TRY CURLUSESSL_TRY #define CURLFTPSSL_CONTROL CURLUSESSL_CONTROL #define CURLFTPSSL_ALL CURLUSESSL_ALL #define CURLFTPSSL_LAST CURLUSESSL_LAST #define curl_ftpssl curl_usessl #endif /*!CURL_NO_OLDIES*/ /* parameter for the CURLOPT_FTP_SSL_CCC option */ typedef enum { CURLFTPSSL_CCC_NONE, /* do not send CCC */ CURLFTPSSL_CCC_PASSIVE, /* Let the server initiate the shutdown */ CURLFTPSSL_CCC_ACTIVE, /* Initiate the shutdown */ CURLFTPSSL_CCC_LAST /* not an option, never use */ } curl_ftpccc; /* parameter for the CURLOPT_FTPSSLAUTH option */ typedef enum { CURLFTPAUTH_DEFAULT, /* let libcurl decide */ CURLFTPAUTH_SSL, /* use "AUTH SSL" */ CURLFTPAUTH_TLS, /* use "AUTH TLS" */ CURLFTPAUTH_LAST /* not an option, never use */ } curl_ftpauth; /* parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ typedef enum { CURLFTP_CREATE_DIR_NONE, /* do NOT create missing dirs! */ CURLFTP_CREATE_DIR, /* (FTP/SFTP) if CWD fails, try MKD and then CWD again if MKD succeeded, for SFTP this does similar magic */ CURLFTP_CREATE_DIR_RETRY, /* (FTP only) if CWD fails, try MKD and then CWD again even if MKD failed! */ CURLFTP_CREATE_DIR_LAST /* not an option, never use */ } curl_ftpcreatedir; /* parameter for the CURLOPT_FTP_FILEMETHOD option */ typedef enum { CURLFTPMETHOD_DEFAULT, /* let libcurl pick */ CURLFTPMETHOD_MULTICWD, /* single CWD operation for each path part */ CURLFTPMETHOD_NOCWD, /* no CWD at all */ CURLFTPMETHOD_SINGLECWD, /* one CWD to full dir, then work on file */ CURLFTPMETHOD_LAST /* not an option, never use */ } curl_ftpmethod; /* bitmask defines for CURLOPT_HEADEROPT */ #define CURLHEADER_UNIFIED 0 #define CURLHEADER_SEPARATE (1<<0) /* CURLALTSVC_* are bits for the CURLOPT_ALTSVC_CTRL option */ #define CURLALTSVC_IMMEDIATELY (1<<0) #define CURLALTSVC_ALTUSED (1<<1) #define CURLALTSVC_READONLYFILE (1<<2) #define CURLALTSVC_H1 (1<<3) #define CURLALTSVC_H2 (1<<4) #define CURLALTSVC_H3 (1<<5) /* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ #define CURLPROTO_HTTP (1<<0) #define CURLPROTO_HTTPS (1<<1) #define CURLPROTO_FTP (1<<2) #define CURLPROTO_FTPS (1<<3) #define CURLPROTO_SCP (1<<4) #define CURLPROTO_SFTP (1<<5) #define CURLPROTO_TELNET (1<<6) #define CURLPROTO_LDAP (1<<7) #define CURLPROTO_LDAPS (1<<8) #define CURLPROTO_DICT (1<<9) #define CURLPROTO_FILE (1<<10) #define CURLPROTO_TFTP (1<<11) #define CURLPROTO_IMAP (1<<12) #define CURLPROTO_IMAPS (1<<13) #define CURLPROTO_POP3 (1<<14) #define CURLPROTO_POP3S (1<<15) #define CURLPROTO_SMTP (1<<16) #define CURLPROTO_SMTPS (1<<17) #define CURLPROTO_RTSP (1<<18) #define CURLPROTO_RTMP (1<<19) #define CURLPROTO_RTMPT (1<<20) #define CURLPROTO_RTMPE (1<<21) #define CURLPROTO_RTMPTE (1<<22) #define CURLPROTO_RTMPS (1<<23) #define CURLPROTO_RTMPTS (1<<24) #define CURLPROTO_GOPHER (1<<25) #define CURLPROTO_SMB (1<<26) #define CURLPROTO_SMBS (1<<27) #define CURLPROTO_ALL (~0) /* enable everything */ /* long may be 32 or 64 bits, but we should never depend on anything else but 32 */ #define CURLOPTTYPE_LONG 0 #define CURLOPTTYPE_OBJECTPOINT 10000 #define CURLOPTTYPE_STRINGPOINT 10000 #define CURLOPTTYPE_FUNCTIONPOINT 20000 #define CURLOPTTYPE_OFF_T 30000 /* *STRINGPOINT is an alias for OBJECTPOINT to allow tools to extract the string options from the header file */ /* name is uppercase CURLOPT_<name>, type is one of the defined CURLOPTTYPE_<type> number is unique identifier */ #ifdef CINIT #undef CINIT #endif #ifdef CURL_ISOCPP #define CINIT(na,t,nu) CURLOPT_ ## na = CURLOPTTYPE_ ## t + nu #else /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ #define LONG CURLOPTTYPE_LONG #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT #define STRINGPOINT CURLOPTTYPE_OBJECTPOINT #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT #define OFF_T CURLOPTTYPE_OFF_T #define CINIT(name,type,number) CURLOPT_/**/name = type + number #endif /* * This macro-mania below setups the CURLOPT_[what] enum, to be used with * curl_easy_setopt(). The first argument in the CINIT() macro is the [what] * word. */ typedef enum { /* This is the FILE * or void * the regular output should be written to. */ CINIT(WRITEDATA, OBJECTPOINT, 1), /* The full URL to get/put */ CINIT(URL, STRINGPOINT, 2), /* Port number to connect to, if other than default. */ CINIT(PORT, LONG, 3), /* Name of proxy to use. */ CINIT(PROXY, STRINGPOINT, 4), /* "user:password;options" to use when fetching. */ CINIT(USERPWD, STRINGPOINT, 5), /* "user:password" to use with proxy. */ CINIT(PROXYUSERPWD, STRINGPOINT, 6), /* Range to get, specified as an ASCII string. */ CINIT(RANGE, STRINGPOINT, 7), /* not used */ /* Specified file stream to upload from (use as input): */ CINIT(READDATA, OBJECTPOINT, 9), /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE * bytes big. */ CINIT(ERRORBUFFER, OBJECTPOINT, 10), /* Function that will be called to store the output (instead of fwrite). The * parameters will use fwrite() syntax, make sure to follow them. */ CINIT(WRITEFUNCTION, FUNCTIONPOINT, 11), /* Function that will be called to read the input (instead of fread). The * parameters will use fread() syntax, make sure to follow them. */ CINIT(READFUNCTION, FUNCTIONPOINT, 12), /* Time-out the read operation after this amount of seconds */ CINIT(TIMEOUT, LONG, 13), /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about * how large the file being sent really is. That allows better error * checking and better verifies that the upload was successful. -1 means * unknown size. * * For large file support, there is also a _LARGE version of the key * which takes an off_t type, allowing platforms with larger off_t * sizes to handle larger files. See below for INFILESIZE_LARGE. */ CINIT(INFILESIZE, LONG, 14), /* POST static input fields. */ CINIT(POSTFIELDS, OBJECTPOINT, 15), /* Set the referrer page (needed by some CGIs) */ CINIT(REFERER, STRINGPOINT, 16), /* Set the FTP PORT string (interface name, named or numerical IP address) Use i.e '-' to use default address. */ CINIT(FTPPORT, STRINGPOINT, 17), /* Set the User-Agent string (examined by some CGIs) */ CINIT(USERAGENT, STRINGPOINT, 18), /* If the download receives less than "low speed limit" bytes/second * during "low speed time" seconds, the operations is aborted. * You could i.e if you have a pretty high speed connection, abort if * it is less than 2000 bytes/sec during 20 seconds. */ /* Set the "low speed limit" */ CINIT(LOW_SPEED_LIMIT, LONG, 19), /* Set the "low speed time" */ CINIT(LOW_SPEED_TIME, LONG, 20), /* Set the continuation offset. * * Note there is also a _LARGE version of this key which uses * off_t types, allowing for large file offsets on platforms which * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. */ CINIT(RESUME_FROM, LONG, 21), /* Set cookie in request: */ CINIT(COOKIE, STRINGPOINT, 22), /* This points to a linked list of headers, struct curl_slist kind. This list is also used for RTSP (in spite of its name) */ CINIT(HTTPHEADER, OBJECTPOINT, 23), /* This points to a linked list of post entries, struct curl_httppost */ CINIT(HTTPPOST, OBJECTPOINT, 24), /* name of the file keeping your private SSL-certificate */ CINIT(SSLCERT, STRINGPOINT, 25), /* password for the SSL or SSH private key */ CINIT(KEYPASSWD, STRINGPOINT, 26), /* send TYPE parameter? */ CINIT(CRLF, LONG, 27), /* send linked-list of QUOTE commands */ CINIT(QUOTE, OBJECTPOINT, 28), /* send FILE * or void * to store headers to, if you use a callback it is simply passed to the callback unmodified */ CINIT(HEADERDATA, OBJECTPOINT, 29), /* point to a file to read the initial cookies from, also enables "cookie awareness" */ CINIT(COOKIEFILE, STRINGPOINT, 31), /* What version to specifically try to use. See CURL_SSLVERSION defines below. */ CINIT(SSLVERSION, LONG, 32), /* What kind of HTTP time condition to use, see defines */ CINIT(TIMECONDITION, LONG, 33), /* Time to use with the above condition. Specified in number of seconds since 1 Jan 1970 */ CINIT(TIMEVALUE, LONG, 34), /* 35 = OBSOLETE */ /* Custom request, for customizing the get command like HTTP: DELETE, TRACE and others FTP: to use a different list command */ CINIT(CUSTOMREQUEST, STRINGPOINT, 36), /* FILE handle to use instead of stderr */ CINIT(STDERR, OBJECTPOINT, 37), /* 38 is not used */ /* send linked-list of post-transfer QUOTE commands */ CINIT(POSTQUOTE, OBJECTPOINT, 39), CINIT(OBSOLETE40, OBJECTPOINT, 40), /* OBSOLETE, do not use! */ CINIT(VERBOSE, LONG, 41), /* talk a lot */ CINIT(HEADER, LONG, 42), /* throw the header out too */ CINIT(NOPROGRESS, LONG, 43), /* shut off the progress meter */ CINIT(NOBODY, LONG, 44), /* use HEAD to get http document */ CINIT(FAILONERROR, LONG, 45), /* no output on http error codes >= 400 */ CINIT(UPLOAD, LONG, 46), /* this is an upload */ CINIT(POST, LONG, 47), /* HTTP POST method */ CINIT(DIRLISTONLY, LONG, 48), /* bare names when listing directories */ CINIT(APPEND, LONG, 50), /* Append instead of overwrite on upload! */ /* Specify whether to read the user+password from the .netrc or the URL. * This must be one of the CURL_NETRC_* enums below. */ CINIT(NETRC, LONG, 51), CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */ CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */ CINIT(PUT, LONG, 54), /* HTTP PUT */ /* 55 = OBSOLETE */ /* DEPRECATED * Function that will be called instead of the internal progress display * function. This function should be defined as the curl_progress_callback * prototype defines. */ CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56), /* Data passed to the CURLOPT_PROGRESSFUNCTION and CURLOPT_XFERINFOFUNCTION callbacks */ CINIT(PROGRESSDATA, OBJECTPOINT, 57), #define CURLOPT_XFERINFODATA CURLOPT_PROGRESSDATA /* We want the referrer field set automatically when following locations */ CINIT(AUTOREFERER, LONG, 58), /* Port of the proxy, can be set in the proxy string as well with: "[host]:[port]" */ CINIT(PROXYPORT, LONG, 59), /* size of the POST input data, if strlen() is not good to use */ CINIT(POSTFIELDSIZE, LONG, 60), /* tunnel non-http operations through a HTTP proxy */ CINIT(HTTPPROXYTUNNEL, LONG, 61), /* Set the interface string to use as outgoing network interface */ CINIT(INTERFACE, STRINGPOINT, 62), /* Set the krb4/5 security level, this also enables krb4/5 awareness. This * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string * is set but doesn't match one of these, 'private' will be used. */ CINIT(KRBLEVEL, STRINGPOINT, 63), /* Set if we should verify the peer in ssl handshake, set 1 to verify. */ CINIT(SSL_VERIFYPEER, LONG, 64), /* The CApath or CAfile used to validate the peer certificate this option is used only if SSL_VERIFYPEER is true */ CINIT(CAINFO, STRINGPOINT, 65), /* 66 = OBSOLETE */ /* 67 = OBSOLETE */ /* Maximum number of http redirects to follow */ CINIT(MAXREDIRS, LONG, 68), /* Pass a long set to 1 to get the date of the requested document (if possible)! Pass a zero to shut it off. */ CINIT(FILETIME, LONG, 69), /* This points to a linked list of telnet options */ CINIT(TELNETOPTIONS, OBJECTPOINT, 70), /* Max amount of cached alive connections */ CINIT(MAXCONNECTS, LONG, 71), CINIT(OBSOLETE72, LONG, 72), /* OBSOLETE, do not use! */ /* 73 = OBSOLETE */ /* Set to explicitly use a new connection for the upcoming transfer. Do not use this unless you're absolutely sure of this, as it makes the operation slower and is less friendly for the network. */ CINIT(FRESH_CONNECT, LONG, 74), /* Set to explicitly forbid the upcoming transfer's connection to be re-used when done. Do not use this unless you're absolutely sure of this, as it makes the operation slower and is less friendly for the network. */ CINIT(FORBID_REUSE, LONG, 75), /* Set to a file name that contains random data for libcurl to use to seed the random engine when doing SSL connects. */ CINIT(RANDOM_FILE, STRINGPOINT, 76), /* Set to the Entropy Gathering Daemon socket pathname */ CINIT(EGDSOCKET, STRINGPOINT, 77), /* Time-out connect operations after this amount of seconds, if connects are OK within this time, then fine... This only aborts the connect phase. */ CINIT(CONNECTTIMEOUT, LONG, 78), /* Function that will be called to store headers (instead of fwrite). The * parameters will use fwrite() syntax, make sure to follow them. */ CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79), /* Set this to force the HTTP request to get back to GET. Only really usable if POST, PUT or a custom request have been used first. */ CINIT(HTTPGET, LONG, 80), /* Set if we should verify the Common name from the peer certificate in ssl * handshake, set 1 to check existence, 2 to ensure that it matches the * provided hostname. */ CINIT(SSL_VERIFYHOST, LONG, 81), /* Specify which file name to write all known cookies in after completed operation. Set file name to "-" (dash) to make it go to stdout. */ CINIT(COOKIEJAR, STRINGPOINT, 82), /* Specify which SSL ciphers to use */ CINIT(SSL_CIPHER_LIST, STRINGPOINT, 83), /* Specify which HTTP version to use! This must be set to one of the CURL_HTTP_VERSION* enums set below. */ CINIT(HTTP_VERSION, LONG, 84), /* Specifically switch on or off the FTP engine's use of the EPSV command. By default, that one will always be attempted before the more traditional PASV command. */ CINIT(FTP_USE_EPSV, LONG, 85), /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ CINIT(SSLCERTTYPE, STRINGPOINT, 86), /* name of the file keeping your private SSL-key */ CINIT(SSLKEY, STRINGPOINT, 87), /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ CINIT(SSLKEYTYPE, STRINGPOINT, 88), /* crypto engine for the SSL-sub system */ CINIT(SSLENGINE, STRINGPOINT, 89), /* set the crypto engine for the SSL-sub system as default the param has no meaning... */ CINIT(SSLENGINE_DEFAULT, LONG, 90), /* Non-zero value means to use the global dns cache */ CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* DEPRECATED, do not use! */ /* DNS cache timeout */ CINIT(DNS_CACHE_TIMEOUT, LONG, 92), /* send linked-list of pre-transfer QUOTE commands */ CINIT(PREQUOTE, OBJECTPOINT, 93), /* set the debug function */ CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94), /* set the data for the debug function */ CINIT(DEBUGDATA, OBJECTPOINT, 95), /* mark this as start of a cookie session */ CINIT(COOKIESESSION, LONG, 96), /* The CApath directory used to validate the peer certificate this option is used only if SSL_VERIFYPEER is true */ CINIT(CAPATH, STRINGPOINT, 97), /* Instruct libcurl to use a smaller receive buffer */ CINIT(BUFFERSIZE, LONG, 98), /* Instruct libcurl to not use any signal/alarm handlers, even when using timeouts. This option is useful for multi-threaded applications. See libcurl-the-guide for more background information. */ CINIT(NOSIGNAL, LONG, 99), /* Provide a CURLShare for mutexing non-ts data */ CINIT(SHARE, OBJECTPOINT, 100), /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default), CURLPROXY_HTTPS, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5. */ CINIT(PROXYTYPE, LONG, 101), /* Set the Accept-Encoding string. Use this to tell a server you would like the response to be compressed. Before 7.21.6, this was known as CURLOPT_ENCODING */ CINIT(ACCEPT_ENCODING, STRINGPOINT, 102), /* Set pointer to private data */ CINIT(PRIVATE, OBJECTPOINT, 103), /* Set aliases for HTTP 200 in the HTTP Response header */ CINIT(HTTP200ALIASES, OBJECTPOINT, 104), /* Continue to send authentication (user+password) when following locations, even when hostname changed. This can potentially send off the name and password to whatever host the server decides. */ CINIT(UNRESTRICTED_AUTH, LONG, 105), /* Specifically switch on or off the FTP engine's use of the EPRT command ( it also disables the LPRT attempt). By default, those ones will always be attempted before the good old traditional PORT command. */ CINIT(FTP_USE_EPRT, LONG, 106), /* Set this to a bitmask value to enable the particular authentications methods you like. Use this in combination with CURLOPT_USERPWD. Note that setting multiple bits may cause extra network round-trips. */ CINIT(HTTPAUTH, LONG, 107), /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx in second argument. The function must be matching the curl_ssl_ctx_callback proto. */ CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108), /* Set the userdata for the ssl context callback function's third argument */ CINIT(SSL_CTX_DATA, OBJECTPOINT, 109), /* FTP Option that causes missing dirs to be created on the remote server. In 7.19.4 we introduced the convenience enums for this option using the CURLFTP_CREATE_DIR prefix. */ CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110), /* Set this to a bitmask value to enable the particular authentications methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. Note that setting multiple bits may cause extra network round-trips. */ CINIT(PROXYAUTH, LONG, 111), /* FTP option that changes the timeout, in seconds, associated with getting a response. This is different from transfer timeout time and essentially places a demand on the FTP server to acknowledge commands in a timely manner. */ CINIT(FTP_RESPONSE_TIMEOUT, LONG, 112), #define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to tell libcurl to resolve names to those IP versions only. This only has affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */ CINIT(IPRESOLVE, LONG, 113), /* Set this option to limit the size of a file that will be downloaded from an HTTP or FTP server. Note there is also _LARGE version which adds large file support for platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ CINIT(MAXFILESIZE, LONG, 114), /* See the comment for INFILESIZE above, but in short, specifies * the size of the file being uploaded. -1 means unknown. */ CINIT(INFILESIZE_LARGE, OFF_T, 115), /* Sets the continuation offset. There is also a LONG version of this; * look above for RESUME_FROM. */ CINIT(RESUME_FROM_LARGE, OFF_T, 116), /* Sets the maximum size of data that will be downloaded from * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. */ CINIT(MAXFILESIZE_LARGE, OFF_T, 117), /* Set this option to the file name of your .netrc file you want libcurl to parse (using the CURLOPT_NETRC option). If not set, libcurl will do a poor attempt to find the user's home directory and check for a .netrc file in there. */ CINIT(NETRC_FILE, STRINGPOINT, 118), /* Enable SSL/TLS for FTP, pick one of: CURLUSESSL_TRY - try using SSL, proceed anyway otherwise CURLUSESSL_CONTROL - SSL for the control connection or fail CURLUSESSL_ALL - SSL for all communication or fail */ CINIT(USE_SSL, LONG, 119), /* The _LARGE version of the standard POSTFIELDSIZE option */ CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120), /* Enable/disable the TCP Nagle algorithm */ CINIT(TCP_NODELAY, LONG, 121), /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ /* 123 OBSOLETE. Gone in 7.16.0 */ /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ /* 127 OBSOLETE. Gone in 7.16.0 */ /* 128 OBSOLETE. Gone in 7.16.0 */ /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option can be used to change libcurl's default action which is to first try "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK response has been received. Available parameters are: CURLFTPAUTH_DEFAULT - let libcurl decide CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL */ CINIT(FTPSSLAUTH, LONG, 129), CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130), CINIT(IOCTLDATA, OBJECTPOINT, 131), /* 132 OBSOLETE. Gone in 7.16.0 */ /* 133 OBSOLETE. Gone in 7.16.0 */ /* zero terminated string for pass on to the FTP server when asked for "account" info */ CINIT(FTP_ACCOUNT, STRINGPOINT, 134), /* feed cookie into cookie engine */ CINIT(COOKIELIST, STRINGPOINT, 135), /* ignore Content-Length */ CINIT(IGNORE_CONTENT_LENGTH, LONG, 136), /* Set to non-zero to skip the IP address received in a 227 PASV FTP server response. Typically used for FTP-SSL purposes but is not restricted to that. libcurl will then instead use the same IP address it used for the control connection. */ CINIT(FTP_SKIP_PASV_IP, LONG, 137), /* Select "file method" to use when doing FTP, see the curl_ftpmethod above. */ CINIT(FTP_FILEMETHOD, LONG, 138), /* Local port number to bind the socket to */ CINIT(LOCALPORT, LONG, 139), /* Number of ports to try, including the first one set with LOCALPORT. Thus, setting it to 1 will make no additional attempts but the first. */ CINIT(LOCALPORTRANGE, LONG, 140), /* no transfer, set up connection and let application use the socket by extracting it with CURLINFO_LASTSOCKET */ CINIT(CONNECT_ONLY, LONG, 141), /* Function that will be called to convert from the network encoding (instead of using the iconv calls in libcurl) */ CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142), /* Function that will be called to convert to the network encoding (instead of using the iconv calls in libcurl) */ CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143), /* Function that will be called to convert from UTF8 (instead of using the iconv calls in libcurl) Note that this is used only for SSL certificate processing */ CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144), /* if the connection proceeds too quickly then need to slow it down */ /* limit-rate: maximum number of bytes per second to send or receive */ CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145), CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146), /* Pointer to command string to send if USER/PASS fails. */ CINIT(FTP_ALTERNATIVE_TO_USER, STRINGPOINT, 147), /* callback function for setting socket options */ CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148), CINIT(SOCKOPTDATA, OBJECTPOINT, 149), /* set to 0 to disable session ID re-use for this transfer, default is enabled (== 1) */ CINIT(SSL_SESSIONID_CACHE, LONG, 150), /* allowed SSH authentication methods */ CINIT(SSH_AUTH_TYPES, LONG, 151), /* Used by scp/sftp to do public/private key authentication */ CINIT(SSH_PUBLIC_KEYFILE, STRINGPOINT, 152), CINIT(SSH_PRIVATE_KEYFILE, STRINGPOINT, 153), /* Send CCC (Clear Command Channel) after authentication */ CINIT(FTP_SSL_CCC, LONG, 154), /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ CINIT(TIMEOUT_MS, LONG, 155), CINIT(CONNECTTIMEOUT_MS, LONG, 156), /* set to zero to disable the libcurl's decoding and thus pass the raw body data to the application even when it is encoded/compressed */ CINIT(HTTP_TRANSFER_DECODING, LONG, 157), CINIT(HTTP_CONTENT_DECODING, LONG, 158), /* Permission used when creating new files and directories on the remote server for protocols that support it, SFTP/SCP/FILE */ CINIT(NEW_FILE_PERMS, LONG, 159), CINIT(NEW_DIRECTORY_PERMS, LONG, 160), /* Set the behaviour of POST when redirecting. Values must be set to one of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ CINIT(POSTREDIR, LONG, 161), /* used by scp/sftp to verify the host's public key */ CINIT(SSH_HOST_PUBLIC_KEY_MD5, STRINGPOINT, 162), /* Callback function for opening socket (instead of socket(2)). Optionally, callback is able change the address or refuse to connect returning CURL_SOCKET_BAD. The callback should have type curl_opensocket_callback */ CINIT(OPENSOCKETFUNCTION, FUNCTIONPOINT, 163), CINIT(OPENSOCKETDATA, OBJECTPOINT, 164), /* POST volatile input fields. */ CINIT(COPYPOSTFIELDS, OBJECTPOINT, 165), /* set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy */ CINIT(PROXY_TRANSFER_MODE, LONG, 166), /* Callback function for seeking in the input stream */ CINIT(SEEKFUNCTION, FUNCTIONPOINT, 167), CINIT(SEEKDATA, OBJECTPOINT, 168), /* CRL file */ CINIT(CRLFILE, STRINGPOINT, 169), /* Issuer certificate */ CINIT(ISSUERCERT, STRINGPOINT, 170), /* (IPv6) Address scope */ CINIT(ADDRESS_SCOPE, LONG, 171), /* Collect certificate chain info and allow it to get retrievable with CURLINFO_CERTINFO after the transfer is complete. */ CINIT(CERTINFO, LONG, 172), /* "name" and "pwd" to use when fetching. */ CINIT(USERNAME, STRINGPOINT, 173), CINIT(PASSWORD, STRINGPOINT, 174), /* "name" and "pwd" to use with Proxy when fetching. */ CINIT(PROXYUSERNAME, STRINGPOINT, 175), CINIT(PROXYPASSWORD, STRINGPOINT, 176), /* Comma separated list of hostnames defining no-proxy zones. These should match both hostnames directly, and hostnames within a domain. For example, local.com will match local.com and www.local.com, but NOT notlocal.com or www.notlocal.com. For compatibility with other implementations of this, .local.com will be considered to be the same as local.com. A single * is the only valid wildcard, and effectively disables the use of proxy. */ CINIT(NOPROXY, STRINGPOINT, 177), /* block size for TFTP transfers */ CINIT(TFTP_BLKSIZE, LONG, 178), /* Socks Service */ CINIT(SOCKS5_GSSAPI_SERVICE, STRINGPOINT, 179), /* DEPRECATED, do not use! */ /* Socks Service */ CINIT(SOCKS5_GSSAPI_NEC, LONG, 180), /* set the bitmask for the protocols that are allowed to be used for the transfer, which thus helps the app which takes URLs from users or other external inputs and want to restrict what protocol(s) to deal with. Defaults to CURLPROTO_ALL. */ CINIT(PROTOCOLS, LONG, 181), /* set the bitmask for the protocols that libcurl is allowed to follow to, as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs to be set in both bitmasks to be allowed to get redirected to. Defaults to all protocols except FILE and SCP. */ CINIT(REDIR_PROTOCOLS, LONG, 182), /* set the SSH knownhost file name to use */ CINIT(SSH_KNOWNHOSTS, STRINGPOINT, 183), /* set the SSH host key callback, must point to a curl_sshkeycallback function */ CINIT(SSH_KEYFUNCTION, FUNCTIONPOINT, 184), /* set the SSH host key callback custom pointer */ CINIT(SSH_KEYDATA, OBJECTPOINT, 185), /* set the SMTP mail originator */ CINIT(MAIL_FROM, STRINGPOINT, 186), /* set the list of SMTP mail receiver(s) */ CINIT(MAIL_RCPT, OBJECTPOINT, 187), /* FTP: send PRET before PASV */ CINIT(FTP_USE_PRET, LONG, 188), /* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ CINIT(RTSP_REQUEST, LONG, 189), /* The RTSP session identifier */ CINIT(RTSP_SESSION_ID, STRINGPOINT, 190), /* The RTSP stream URI */ CINIT(RTSP_STREAM_URI, STRINGPOINT, 191), /* The Transport: header to use in RTSP requests */ CINIT(RTSP_TRANSPORT, STRINGPOINT, 192), /* Manually initialize the client RTSP CSeq for this handle */ CINIT(RTSP_CLIENT_CSEQ, LONG, 193), /* Manually initialize the server RTSP CSeq for this handle */ CINIT(RTSP_SERVER_CSEQ, LONG, 194), /* The stream to pass to INTERLEAVEFUNCTION. */ CINIT(INTERLEAVEDATA, OBJECTPOINT, 195), /* Let the application define a custom write method for RTP data */ CINIT(INTERLEAVEFUNCTION, FUNCTIONPOINT, 196), /* Turn on wildcard matching */ CINIT(WILDCARDMATCH, LONG, 197), /* Directory matching callback called before downloading of an individual file (chunk) started */ CINIT(CHUNK_BGN_FUNCTION, FUNCTIONPOINT, 198), /* Directory matching callback called after the file (chunk) was downloaded, or skipped */ CINIT(CHUNK_END_FUNCTION, FUNCTIONPOINT, 199), /* Change match (fnmatch-like) callback for wildcard matching */ CINIT(FNMATCH_FUNCTION, FUNCTIONPOINT, 200), /* Let the application define custom chunk data pointer */ CINIT(CHUNK_DATA, OBJECTPOINT, 201), /* FNMATCH_FUNCTION user pointer */ CINIT(FNMATCH_DATA, OBJECTPOINT, 202), /* send linked-list of name:port:address sets */ CINIT(RESOLVE, OBJECTPOINT, 203), /* Set a username for authenticated TLS */ CINIT(TLSAUTH_USERNAME, STRINGPOINT, 204), /* Set a password for authenticated TLS */ CINIT(TLSAUTH_PASSWORD, STRINGPOINT, 205), /* Set authentication type for authenticated TLS */ CINIT(TLSAUTH_TYPE, STRINGPOINT, 206), /* Set to 1 to enable the "TE:" header in HTTP requests to ask for compressed transfer-encoded responses. Set to 0 to disable the use of TE: in outgoing requests. The current default is 0, but it might change in a future libcurl release. libcurl will ask for the compressed methods it knows of, and if that isn't any, it will not ask for transfer-encoding at all even if this option is set to 1. */ CINIT(TRANSFER_ENCODING, LONG, 207), /* Callback function for closing socket (instead of close(2)). The callback should have type curl_closesocket_callback */ CINIT(CLOSESOCKETFUNCTION, FUNCTIONPOINT, 208), CINIT(CLOSESOCKETDATA, OBJECTPOINT, 209), /* allow GSSAPI credential delegation */ CINIT(GSSAPI_DELEGATION, LONG, 210), /* Set the name servers to use for DNS resolution */ CINIT(DNS_SERVERS, STRINGPOINT, 211), /* Time-out accept operations (currently for FTP only) after this amount of milliseconds. */ CINIT(ACCEPTTIMEOUT_MS, LONG, 212), /* Set TCP keepalive */ CINIT(TCP_KEEPALIVE, LONG, 213), /* non-universal keepalive knobs (Linux, AIX, HP-UX, more) */ CINIT(TCP_KEEPIDLE, LONG, 214), CINIT(TCP_KEEPINTVL, LONG, 215), /* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */ CINIT(SSL_OPTIONS, LONG, 216), /* Set the SMTP auth originator */ CINIT(MAIL_AUTH, STRINGPOINT, 217), /* Enable/disable SASL initial response */ CINIT(SASL_IR, LONG, 218), /* Function that will be called instead of the internal progress display * function. This function should be defined as the curl_xferinfo_callback * prototype defines. (Deprecates CURLOPT_PROGRESSFUNCTION) */ CINIT(XFERINFOFUNCTION, FUNCTIONPOINT, 219), /* The XOAUTH2 bearer token */ CINIT(XOAUTH2_BEARER, STRINGPOINT, 220), /* Set the interface string to use as outgoing network * interface for DNS requests. * Only supported by the c-ares DNS backend */ CINIT(DNS_INTERFACE, STRINGPOINT, 221), /* Set the local IPv4 address to use for outgoing DNS requests. * Only supported by the c-ares DNS backend */ CINIT(DNS_LOCAL_IP4, STRINGPOINT, 222), /* Set the local IPv6 address to use for outgoing DNS requests. * Only supported by the c-ares DNS backend */ CINIT(DNS_LOCAL_IP6, STRINGPOINT, 223), /* Set authentication options directly */ CINIT(LOGIN_OPTIONS, STRINGPOINT, 224), /* Enable/disable TLS NPN extension (http2 over ssl might fail without) */ CINIT(SSL_ENABLE_NPN, LONG, 225), /* Enable/disable TLS ALPN extension (http2 over ssl might fail without) */ CINIT(SSL_ENABLE_ALPN, LONG, 226), /* Time to wait for a response to a HTTP request containing an * Expect: 100-continue header before sending the data anyway. */ CINIT(EXPECT_100_TIMEOUT_MS, LONG, 227), /* This points to a linked list of headers used for proxy requests only, struct curl_slist kind */ CINIT(PROXYHEADER, OBJECTPOINT, 228), /* Pass in a bitmask of "header options" */ CINIT(HEADEROPT, LONG, 229), /* The public key in DER form used to validate the peer public key this option is used only if SSL_VERIFYPEER is true */ CINIT(PINNEDPUBLICKEY, STRINGPOINT, 230), /* Path to Unix domain socket */ CINIT(UNIX_SOCKET_PATH, STRINGPOINT, 231), /* Set if we should verify the certificate status. */ CINIT(SSL_VERIFYSTATUS, LONG, 232), /* Set if we should enable TLS false start. */ CINIT(SSL_FALSESTART, LONG, 233), /* Do not squash dot-dot sequences */ CINIT(PATH_AS_IS, LONG, 234), /* Proxy Service Name */ CINIT(PROXY_SERVICE_NAME, STRINGPOINT, 235), /* Service Name */ CINIT(SERVICE_NAME, STRINGPOINT, 236), /* Wait/don't wait for pipe/mutex to clarify */ CINIT(PIPEWAIT, LONG, 237), /* Set the protocol used when curl is given a URL without a protocol */ CINIT(DEFAULT_PROTOCOL, STRINGPOINT, 238), /* Set stream weight, 1 - 256 (default is 16) */ CINIT(STREAM_WEIGHT, LONG, 239), /* Set stream dependency on another CURL handle */ CINIT(STREAM_DEPENDS, OBJECTPOINT, 240), /* Set E-xclusive stream dependency on another CURL handle */ CINIT(STREAM_DEPENDS_E, OBJECTPOINT, 241), /* Do not send any tftp option requests to the server */ CINIT(TFTP_NO_OPTIONS, LONG, 242), /* Linked-list of host:port:connect-to-host:connect-to-port, overrides the URL's host:port (only for the network layer) */ CINIT(CONNECT_TO, OBJECTPOINT, 243), /* Set TCP Fast Open */ CINIT(TCP_FASTOPEN, LONG, 244), /* Continue to send data if the server responds early with an * HTTP status code >= 300 */ CINIT(KEEP_SENDING_ON_ERROR, LONG, 245), /* The CApath or CAfile used to validate the proxy certificate this option is used only if PROXY_SSL_VERIFYPEER is true */ CINIT(PROXY_CAINFO, STRINGPOINT, 246), /* The CApath directory used to validate the proxy certificate this option is used only if PROXY_SSL_VERIFYPEER is true */ CINIT(PROXY_CAPATH, STRINGPOINT, 247), /* Set if we should verify the proxy in ssl handshake, set 1 to verify. */ CINIT(PROXY_SSL_VERIFYPEER, LONG, 248), /* Set if we should verify the Common name from the proxy certificate in ssl * handshake, set 1 to check existence, 2 to ensure that it matches * the provided hostname. */ CINIT(PROXY_SSL_VERIFYHOST, LONG, 249), /* What version to specifically try to use for proxy. See CURL_SSLVERSION defines below. */ CINIT(PROXY_SSLVERSION, LONG, 250), /* Set a username for authenticated TLS for proxy */ CINIT(PROXY_TLSAUTH_USERNAME, STRINGPOINT, 251), /* Set a password for authenticated TLS for proxy */ CINIT(PROXY_TLSAUTH_PASSWORD, STRINGPOINT, 252), /* Set authentication type for authenticated TLS for proxy */ CINIT(PROXY_TLSAUTH_TYPE, STRINGPOINT, 253), /* name of the file keeping your private SSL-certificate for proxy */ CINIT(PROXY_SSLCERT, STRINGPOINT, 254), /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") for proxy */ CINIT(PROXY_SSLCERTTYPE, STRINGPOINT, 255), /* name of the file keeping your private SSL-key for proxy */ CINIT(PROXY_SSLKEY, STRINGPOINT, 256), /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") for proxy */ CINIT(PROXY_SSLKEYTYPE, STRINGPOINT, 257), /* password for the SSL private key for proxy */ CINIT(PROXY_KEYPASSWD, STRINGPOINT, 258), /* Specify which SSL ciphers to use for proxy */ CINIT(PROXY_SSL_CIPHER_LIST, STRINGPOINT, 259), /* CRL file for proxy */ CINIT(PROXY_CRLFILE, STRINGPOINT, 260), /* Enable/disable specific SSL features with a bitmask for proxy, see CURLSSLOPT_* */ CINIT(PROXY_SSL_OPTIONS, LONG, 261), /* Name of pre proxy to use. */ CINIT(PRE_PROXY, STRINGPOINT, 262), /* The public key in DER form used to validate the proxy public key this option is used only if PROXY_SSL_VERIFYPEER is true */ CINIT(PROXY_PINNEDPUBLICKEY, STRINGPOINT, 263), /* Path to an abstract Unix domain socket */ CINIT(ABSTRACT_UNIX_SOCKET, STRINGPOINT, 264), /* Suppress proxy CONNECT response headers from user callbacks */ CINIT(SUPPRESS_CONNECT_HEADERS, LONG, 265), /* The request target, instead of extracted from the URL */ CINIT(REQUEST_TARGET, STRINGPOINT, 266), /* bitmask of allowed auth methods for connections to SOCKS5 proxies */ CINIT(SOCKS5_AUTH, LONG, 267), /* Enable/disable SSH compression */ CINIT(SSH_COMPRESSION, LONG, 268), /* Post MIME data. */ CINIT(MIMEPOST, OBJECTPOINT, 269), /* Time to use with the CURLOPT_TIMECONDITION. Specified in number of seconds since 1 Jan 1970. */ CINIT(TIMEVALUE_LARGE, OFF_T, 270), /* Head start in milliseconds to give happy eyeballs. */ CINIT(HAPPY_EYEBALLS_TIMEOUT_MS, LONG, 271), /* Function that will be called before a resolver request is made */ CINIT(RESOLVER_START_FUNCTION, FUNCTIONPOINT, 272), /* User data to pass to the resolver start callback. */ CINIT(RESOLVER_START_DATA, OBJECTPOINT, 273), /* send HAProxy PROXY protocol header? */ CINIT(HAPROXYPROTOCOL, LONG, 274), /* shuffle addresses before use when DNS returns multiple */ CINIT(DNS_SHUFFLE_ADDRESSES, LONG, 275), /* Specify which TLS 1.3 ciphers suites to use */ CINIT(TLS13_CIPHERS, STRINGPOINT, 276), CINIT(PROXY_TLS13_CIPHERS, STRINGPOINT, 277), /* Disallow specifying username/login in URL. */ CINIT(DISALLOW_USERNAME_IN_URL, LONG, 278), /* DNS-over-HTTPS URL */ CINIT(DOH_URL, STRINGPOINT, 279), /* Preferred buffer size to use for uploads */ CINIT(UPLOAD_BUFFERSIZE, LONG, 280), /* Time in ms between connection upkeep calls for long-lived connections. */ CINIT(UPKEEP_INTERVAL_MS, LONG, 281), /* Specify URL using CURL URL API. */ CINIT(CURLU, OBJECTPOINT, 282), /* add trailing data just after no more data is available */ CINIT(TRAILERFUNCTION, FUNCTIONPOINT, 283), /* pointer to be passed to HTTP_TRAILER_FUNCTION */ CINIT(TRAILERDATA, OBJECTPOINT, 284), /* set this to 1L to allow HTTP/0.9 responses or 0L to disallow */ CINIT(HTTP09_ALLOWED, LONG, 285), /* alt-svc control bitmask */ CINIT(ALTSVC_CTRL, LONG, 286), /* alt-svc cache file name to possibly read from/write to */ CINIT(ALTSVC, STRINGPOINT, 287), /* maximum age of a connection to consider it for reuse (in seconds) */ CINIT(MAXAGE_CONN, LONG, 288), CURLOPT_LASTENTRY /* the last unused */ } CURLoption; #ifndef CURL_NO_OLDIES /* define this to test if your app builds with all the obsolete stuff removed! */ /* Backwards compatibility with older names */ /* These are scheduled to disappear by 2011 */ /* This was added in version 7.19.1 */ #define CURLOPT_POST301 CURLOPT_POSTREDIR /* These are scheduled to disappear by 2009 */ /* The following were added in 7.17.0 */ #define CURLOPT_SSLKEYPASSWD CURLOPT_KEYPASSWD #define CURLOPT_FTPAPPEND CURLOPT_APPEND #define CURLOPT_FTPLISTONLY CURLOPT_DIRLISTONLY #define CURLOPT_FTP_SSL CURLOPT_USE_SSL /* The following were added earlier */ #define CURLOPT_SSLCERTPASSWD CURLOPT_KEYPASSWD #define CURLOPT_KRB4LEVEL CURLOPT_KRBLEVEL #else /* This is set if CURL_NO_OLDIES is defined at compile-time */ #undef CURLOPT_DNS_USE_GLOBAL_CACHE /* soon obsolete */ #endif /* Below here follows defines for the CURLOPT_IPRESOLVE option. If a host name resolves addresses using more than one IP protocol version, this option might be handy to force libcurl to use a specific IP version. */ #define CURL_IPRESOLVE_WHATEVER 0 /* default, resolves addresses to all IP versions that your system allows */ #define CURL_IPRESOLVE_V4 1 /* resolve to IPv4 addresses */ #define CURL_IPRESOLVE_V6 2 /* resolve to IPv6 addresses */ /* three convenient "aliases" that follow the name scheme better */ #define CURLOPT_RTSPHEADER CURLOPT_HTTPHEADER /* These enums are for use with the CURLOPT_HTTP_VERSION option. */ enum { CURL_HTTP_VERSION_NONE, /* setting this means we don't care, and that we'd like the library to choose the best possible for us! */ CURL_HTTP_VERSION_1_0, /* please use HTTP 1.0 in the request */ CURL_HTTP_VERSION_1_1, /* please use HTTP 1.1 in the request */ CURL_HTTP_VERSION_2_0, /* please use HTTP 2 in the request */ CURL_HTTP_VERSION_2TLS, /* use version 2 for HTTPS, version 1.1 for HTTP */ CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE, /* please use HTTP 2 without HTTP/1.1 Upgrade */ CURL_HTTP_VERSION_LAST /* *ILLEGAL* http version */ }; /* Convenience definition simple because the name of the version is HTTP/2 and not 2.0. The 2_0 version of the enum name was set while the version was still planned to be 2.0 and we stick to it for compatibility. */ #define CURL_HTTP_VERSION_2 CURL_HTTP_VERSION_2_0 /* * Public API enums for RTSP requests */ enum { CURL_RTSPREQ_NONE, /* first in list */ CURL_RTSPREQ_OPTIONS, CURL_RTSPREQ_DESCRIBE, CURL_RTSPREQ_ANNOUNCE, CURL_RTSPREQ_SETUP, CURL_RTSPREQ_PLAY, CURL_RTSPREQ_PAUSE, CURL_RTSPREQ_TEARDOWN, CURL_RTSPREQ_GET_PARAMETER, CURL_RTSPREQ_SET_PARAMETER, CURL_RTSPREQ_RECORD, CURL_RTSPREQ_RECEIVE, CURL_RTSPREQ_LAST /* last in list */ }; /* These enums are for use with the CURLOPT_NETRC option. */ enum CURL_NETRC_OPTION { CURL_NETRC_IGNORED, /* The .netrc will never be read. * This is the default. */ CURL_NETRC_OPTIONAL, /* A user:password in the URL will be preferred * to one in the .netrc. */ CURL_NETRC_REQUIRED, /* A user:password in the URL will be ignored. * Unless one is set programmatically, the .netrc * will be queried. */ CURL_NETRC_LAST }; enum { CURL_SSLVERSION_DEFAULT, CURL_SSLVERSION_TLSv1, /* TLS 1.x */ CURL_SSLVERSION_SSLv2, CURL_SSLVERSION_SSLv3, CURL_SSLVERSION_TLSv1_0, CURL_SSLVERSION_TLSv1_1, CURL_SSLVERSION_TLSv1_2, CURL_SSLVERSION_TLSv1_3, CURL_SSLVERSION_LAST /* never use, keep last */ }; enum { CURL_SSLVERSION_MAX_NONE = 0, CURL_SSLVERSION_MAX_DEFAULT = (CURL_SSLVERSION_TLSv1 << 16), CURL_SSLVERSION_MAX_TLSv1_0 = (CURL_SSLVERSION_TLSv1_0 << 16), CURL_SSLVERSION_MAX_TLSv1_1 = (CURL_SSLVERSION_TLSv1_1 << 16), CURL_SSLVERSION_MAX_TLSv1_2 = (CURL_SSLVERSION_TLSv1_2 << 16), CURL_SSLVERSION_MAX_TLSv1_3 = (CURL_SSLVERSION_TLSv1_3 << 16), /* never use, keep last */ CURL_SSLVERSION_MAX_LAST = (CURL_SSLVERSION_LAST << 16) }; enum CURL_TLSAUTH { CURL_TLSAUTH_NONE, CURL_TLSAUTH_SRP, CURL_TLSAUTH_LAST /* never use, keep last */ }; /* symbols to use with CURLOPT_POSTREDIR. CURL_REDIR_POST_301, CURL_REDIR_POST_302 and CURL_REDIR_POST_303 can be bitwise ORed so that CURL_REDIR_POST_301 | CURL_REDIR_POST_302 | CURL_REDIR_POST_303 == CURL_REDIR_POST_ALL */ #define CURL_REDIR_GET_ALL 0 #define CURL_REDIR_POST_301 1 #define CURL_REDIR_POST_302 2 #define CURL_REDIR_POST_303 4 #define CURL_REDIR_POST_ALL \ (CURL_REDIR_POST_301|CURL_REDIR_POST_302|CURL_REDIR_POST_303) typedef enum { CURL_TIMECOND_NONE, CURL_TIMECOND_IFMODSINCE, CURL_TIMECOND_IFUNMODSINCE, CURL_TIMECOND_LASTMOD, CURL_TIMECOND_LAST } curl_TimeCond; /* Special size_t value signaling a zero-terminated string. */ #define CURL_ZERO_TERMINATED ((size_t) -1) /* curl_strequal() and curl_strnequal() are subject for removal in a future release */ CURL_EXTERN int curl_strequal(const char *s1, const char *s2); CURL_EXTERN int curl_strnequal(const char *s1, const char *s2, size_t n); /* Mime/form handling support. */ typedef struct curl_mime_s curl_mime; /* Mime context. */ typedef struct curl_mimepart_s curl_mimepart; /* Mime part context. */ /* * NAME curl_mime_init() * * DESCRIPTION * * Create a mime context and return its handle. The easy parameter is the * target handle. */ CURL_EXTERN curl_mime *curl_mime_init(CURL *easy); /* * NAME curl_mime_free() * * DESCRIPTION * * release a mime handle and its substructures. */ CURL_EXTERN void curl_mime_free(curl_mime *mime); /* * NAME curl_mime_addpart() * * DESCRIPTION * * Append a new empty part to the given mime context and return a handle to * the created part. */ CURL_EXTERN curl_mimepart *curl_mime_addpart(curl_mime *mime); /* * NAME curl_mime_name() * * DESCRIPTION * * Set mime/form part name. */ CURL_EXTERN CURLcode curl_mime_name(curl_mimepart *part, const char *name); /* * NAME curl_mime_filename() * * DESCRIPTION * * Set mime part remote file name. */ CURL_EXTERN CURLcode curl_mime_filename(curl_mimepart *part, const char *filename); /* * NAME curl_mime_type() * * DESCRIPTION * * Set mime part type. */ CURL_EXTERN CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype); /* * NAME curl_mime_encoder() * * DESCRIPTION * * Set mime data transfer encoder. */ CURL_EXTERN CURLcode curl_mime_encoder(curl_mimepart *part, const char *encoding); /* * NAME curl_mime_data() * * DESCRIPTION * * Set mime part data source from memory data, */ CURL_EXTERN CURLcode curl_mime_data(curl_mimepart *part, const char *data, size_t datasize); /* * NAME curl_mime_filedata() * * DESCRIPTION * * Set mime part data source from named file. */ CURL_EXTERN CURLcode curl_mime_filedata(curl_mimepart *part, const char *filename); /* * NAME curl_mime_data_cb() * * DESCRIPTION * * Set mime part data source from callback function. */ CURL_EXTERN CURLcode curl_mime_data_cb(curl_mimepart *part, curl_off_t datasize, curl_read_callback readfunc, curl_seek_callback seekfunc, curl_free_callback freefunc, void *arg); /* * NAME curl_mime_subparts() * * DESCRIPTION * * Set mime part data source from subparts. */ CURL_EXTERN CURLcode curl_mime_subparts(curl_mimepart *part, curl_mime *subparts); /* * NAME curl_mime_headers() * * DESCRIPTION * * Set mime part headers. */ CURL_EXTERN CURLcode curl_mime_headers(curl_mimepart *part, struct curl_slist *headers, int take_ownership); /* Old form API. */ /* name is uppercase CURLFORM_<name> */ #ifdef CFINIT #undef CFINIT #endif #ifdef CURL_ISOCPP #define CFINIT(name) CURLFORM_ ## name #else /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ #define CFINIT(name) CURLFORM_/**/name #endif typedef enum { CFINIT(NOTHING), /********* the first one is unused ************/ /* */ CFINIT(COPYNAME), CFINIT(PTRNAME), CFINIT(NAMELENGTH), CFINIT(COPYCONTENTS), CFINIT(PTRCONTENTS), CFINIT(CONTENTSLENGTH), CFINIT(FILECONTENT), CFINIT(ARRAY), CFINIT(OBSOLETE), CFINIT(FILE), CFINIT(BUFFER), CFINIT(BUFFERPTR), CFINIT(BUFFERLENGTH), CFINIT(CONTENTTYPE), CFINIT(CONTENTHEADER), CFINIT(FILENAME), CFINIT(END), CFINIT(OBSOLETE2), CFINIT(STREAM), CFINIT(CONTENTLEN), /* added in 7.46.0, provide a curl_off_t length */ CURLFORM_LASTENTRY /* the last unused */ } CURLformoption; #undef CFINIT /* done */ /* structure to be used as parameter for CURLFORM_ARRAY */ struct curl_forms { CURLformoption option; const char *value; }; /* use this for multipart formpost building */ /* Returns code for curl_formadd() * * Returns: * CURL_FORMADD_OK on success * CURL_FORMADD_MEMORY if the FormInfo allocation fails * CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form * CURL_FORMADD_NULL if a null pointer was given for a char * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) * CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated * CURL_FORMADD_MEMORY if some allocation for string copying failed. * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array * ***************************************************************************/ typedef enum { CURL_FORMADD_OK, /* first, no error */ CURL_FORMADD_MEMORY, CURL_FORMADD_OPTION_TWICE, CURL_FORMADD_NULL, CURL_FORMADD_UNKNOWN_OPTION, CURL_FORMADD_INCOMPLETE, CURL_FORMADD_ILLEGAL_ARRAY, CURL_FORMADD_DISABLED, /* libcurl was built with this disabled */ CURL_FORMADD_LAST /* last */ } CURLFORMcode; /* * NAME curl_formadd() * * DESCRIPTION * * Pretty advanced function for building multi-part formposts. Each invoke * adds one part that together construct a full post. Then use * CURLOPT_HTTPPOST to send it off to libcurl. */ CURL_EXTERN CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post, ...); /* * callback function for curl_formget() * The void *arg pointer will be the one passed as second argument to * curl_formget(). * The character buffer passed to it must not be freed. * Should return the buffer length passed to it as the argument "len" on * success. */ typedef size_t (*curl_formget_callback)(void *arg, const char *buf, size_t len); /* * NAME curl_formget() * * DESCRIPTION * * Serialize a curl_httppost struct built with curl_formadd(). * Accepts a void pointer as second argument which will be passed to * the curl_formget_callback function. * Returns 0 on success. */ CURL_EXTERN int curl_formget(struct curl_httppost *form, void *arg, curl_formget_callback append); /* * NAME curl_formfree() * * DESCRIPTION * * Free a multipart formpost previously built with curl_formadd(). */ CURL_EXTERN void curl_formfree(struct curl_httppost *form); /* * NAME curl_getenv() * * DESCRIPTION * * Returns a malloc()'ed string that MUST be curl_free()ed after usage is * complete. DEPRECATED - see lib/README.curlx */ CURL_EXTERN char *curl_getenv(const char *variable); /* * NAME curl_version() * * DESCRIPTION * * Returns a static ascii string of the libcurl version. */ CURL_EXTERN char *curl_version(void); /* * NAME curl_easy_escape() * * DESCRIPTION * * Escapes URL strings (converts all letters consider illegal in URLs to their * %XX versions). This function returns a new allocated string or NULL if an * error occurred. */ CURL_EXTERN char *curl_easy_escape(CURL *handle, const char *string, int length); /* the previous version: */ CURL_EXTERN char *curl_escape(const char *string, int length); /* * NAME curl_easy_unescape() * * DESCRIPTION * * Unescapes URL encoding in strings (converts all %XX codes to their 8bit * versions). This function returns a new allocated string or NULL if an error * occurred. * Conversion Note: On non-ASCII platforms the ASCII %XX codes are * converted into the host encoding. */ CURL_EXTERN char *curl_easy_unescape(CURL *handle, const char *string, int length, int *outlength); /* the previous version */ CURL_EXTERN char *curl_unescape(const char *string, int length); /* * NAME curl_free() * * DESCRIPTION * * Provided for de-allocation in the same translation unit that did the * allocation. Added in libcurl 7.10 */ CURL_EXTERN void curl_free(void *p); /* * NAME curl_global_init() * * DESCRIPTION * * curl_global_init() should be invoked exactly once for each application that * uses libcurl and before any call of other libcurl functions. * * This function is not thread-safe! */ CURL_EXTERN CURLcode curl_global_init(long flags); /* * NAME curl_global_init_mem() * * DESCRIPTION * * curl_global_init() or curl_global_init_mem() should be invoked exactly once * for each application that uses libcurl. This function can be used to * initialize libcurl and set user defined memory management callback * functions. Users can implement memory management routines to check for * memory leaks, check for mis-use of the curl library etc. User registered * callback routines with be invoked by this library instead of the system * memory management routines like malloc, free etc. */ CURL_EXTERN CURLcode curl_global_init_mem(long flags, curl_malloc_callback m, curl_free_callback f, curl_realloc_callback r, curl_strdup_callback s, curl_calloc_callback c); /* * NAME curl_global_cleanup() * * DESCRIPTION * * curl_global_cleanup() should be invoked exactly once for each application * that uses libcurl */ CURL_EXTERN void curl_global_cleanup(void); /* linked-list structure for the CURLOPT_QUOTE option (and other) */ struct curl_slist { char *data; struct curl_slist *next; }; /* * NAME curl_global_sslset() * * DESCRIPTION * * When built with multiple SSL backends, curl_global_sslset() allows to * choose one. This function can only be called once, and it must be called * *before* curl_global_init(). * * The backend can be identified by the id (e.g. CURLSSLBACKEND_OPENSSL). The * backend can also be specified via the name parameter (passing -1 as id). * If both id and name are specified, the name will be ignored. If neither id * nor name are specified, the function will fail with * CURLSSLSET_UNKNOWN_BACKEND and set the "avail" pointer to the * NULL-terminated list of available backends. * * Upon success, the function returns CURLSSLSET_OK. * * If the specified SSL backend is not available, the function returns * CURLSSLSET_UNKNOWN_BACKEND and sets the "avail" pointer to a NULL-terminated * list of available SSL backends. * * The SSL backend can be set only once. If it has already been set, a * subsequent attempt to change it will result in a CURLSSLSET_TOO_LATE. */ typedef struct { curl_sslbackend id; const char *name; } curl_ssl_backend; typedef enum { CURLSSLSET_OK = 0, CURLSSLSET_UNKNOWN_BACKEND, CURLSSLSET_TOO_LATE, CURLSSLSET_NO_BACKENDS /* libcurl was built without any SSL support */ } CURLsslset; CURL_EXTERN CURLsslset curl_global_sslset(curl_sslbackend id, const char *name, const curl_ssl_backend ***avail); /* * NAME curl_slist_append() * * DESCRIPTION * * Appends a string to a linked list. If no list exists, it will be created * first. Returns the new list, after appending. */ CURL_EXTERN struct curl_slist *curl_slist_append(struct curl_slist *, const char *); /* * NAME curl_slist_free_all() * * DESCRIPTION * * free a previously built curl_slist. */ CURL_EXTERN void curl_slist_free_all(struct curl_slist *); /* * NAME curl_getdate() * * DESCRIPTION * * Returns the time, in seconds since 1 Jan 1970 of the time string given in * the first argument. The time argument in the second parameter is unused * and should be set to NULL. */ CURL_EXTERN time_t curl_getdate(const char *p, const time_t *unused); /* info about the certificate chain, only for OpenSSL builds. Asked for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ struct curl_certinfo { int num_of_certs; /* number of certificates with information */ struct curl_slist **certinfo; /* for each index in this array, there's a linked list with textual information in the format "name: value" */ }; /* Information about the SSL library used and the respective internal SSL handle, which can be used to obtain further information regarding the connection. Asked for with CURLINFO_TLS_SSL_PTR or CURLINFO_TLS_SESSION. */ struct curl_tlssessioninfo { curl_sslbackend backend; void *internals; }; #define CURLINFO_STRING 0x100000 #define CURLINFO_LONG 0x200000 #define CURLINFO_DOUBLE 0x300000 #define CURLINFO_SLIST 0x400000 #define CURLINFO_PTR 0x400000 /* same as SLIST */ #define CURLINFO_SOCKET 0x500000 #define CURLINFO_OFF_T 0x600000 #define CURLINFO_MASK 0x0fffff #define CURLINFO_TYPEMASK 0xf00000 typedef enum { CURLINFO_NONE, /* first, never use this */ CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1, CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2, CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3, CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4, CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5, CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6, CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7, CURLINFO_SIZE_UPLOAD_T = CURLINFO_OFF_T + 7, CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8, CURLINFO_SIZE_DOWNLOAD_T = CURLINFO_OFF_T + 8, CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9, CURLINFO_SPEED_DOWNLOAD_T = CURLINFO_OFF_T + 9, CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10, CURLINFO_SPEED_UPLOAD_T = CURLINFO_OFF_T + 10, CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11, CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12, CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13, CURLINFO_FILETIME = CURLINFO_LONG + 14, CURLINFO_FILETIME_T = CURLINFO_OFF_T + 14, CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T = CURLINFO_OFF_T + 15, CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16, CURLINFO_CONTENT_LENGTH_UPLOAD_T = CURLINFO_OFF_T + 16, CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17, CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18, CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19, CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20, CURLINFO_PRIVATE = CURLINFO_STRING + 21, CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22, CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23, CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24, CURLINFO_OS_ERRNO = CURLINFO_LONG + 25, CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26, CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27, CURLINFO_COOKIELIST = CURLINFO_SLIST + 28, CURLINFO_LASTSOCKET = CURLINFO_LONG + 29, CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30, CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31, CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32, CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33, CURLINFO_CERTINFO = CURLINFO_PTR + 34, CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35, CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36, CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37, CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38, CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39, CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40, CURLINFO_LOCAL_IP = CURLINFO_STRING + 41, CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42, CURLINFO_TLS_SESSION = CURLINFO_PTR + 43, CURLINFO_ACTIVESOCKET = CURLINFO_SOCKET + 44, CURLINFO_TLS_SSL_PTR = CURLINFO_PTR + 45, CURLINFO_HTTP_VERSION = CURLINFO_LONG + 46, CURLINFO_PROXY_SSL_VERIFYRESULT = CURLINFO_LONG + 47, CURLINFO_PROTOCOL = CURLINFO_LONG + 48, CURLINFO_SCHEME = CURLINFO_STRING + 49, /* Fill in new entries below here! */ /* Preferably these would be defined conditionally based on the sizeof curl_off_t being 64-bits */ CURLINFO_TOTAL_TIME_T = CURLINFO_OFF_T + 50, CURLINFO_NAMELOOKUP_TIME_T = CURLINFO_OFF_T + 51, CURLINFO_CONNECT_TIME_T = CURLINFO_OFF_T + 52, CURLINFO_PRETRANSFER_TIME_T = CURLINFO_OFF_T + 53, CURLINFO_STARTTRANSFER_TIME_T = CURLINFO_OFF_T + 54, CURLINFO_REDIRECT_TIME_T = CURLINFO_OFF_T + 55, CURLINFO_APPCONNECT_TIME_T = CURLINFO_OFF_T + 56, CURLINFO_LASTONE = 56 } CURLINFO; /* CURLINFO_RESPONSE_CODE is the new name for the option previously known as CURLINFO_HTTP_CODE */ #define CURLINFO_HTTP_CODE CURLINFO_RESPONSE_CODE typedef enum { CURLCLOSEPOLICY_NONE, /* first, never use this */ CURLCLOSEPOLICY_OLDEST, CURLCLOSEPOLICY_LEAST_RECENTLY_USED, CURLCLOSEPOLICY_LEAST_TRAFFIC, CURLCLOSEPOLICY_SLOWEST, CURLCLOSEPOLICY_CALLBACK, CURLCLOSEPOLICY_LAST /* last, never use this */ } curl_closepolicy; #define CURL_GLOBAL_SSL (1<<0) /* no purpose since since 7.57.0 */ #define CURL_GLOBAL_WIN32 (1<<1) #define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) #define CURL_GLOBAL_NOTHING 0 #define CURL_GLOBAL_DEFAULT CURL_GLOBAL_ALL #define CURL_GLOBAL_ACK_EINTR (1<<2) /***************************************************************************** * Setup defines, protos etc for the sharing stuff. */ /* Different data locks for a single share */ typedef enum { CURL_LOCK_DATA_NONE = 0, /* CURL_LOCK_DATA_SHARE is used internally to say that * the locking is just made to change the internal state of the share * itself. */ CURL_LOCK_DATA_SHARE, CURL_LOCK_DATA_COOKIE, CURL_LOCK_DATA_DNS, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_DATA_CONNECT, CURL_LOCK_DATA_PSL, CURL_LOCK_DATA_LAST } curl_lock_data; /* Different lock access types */ typedef enum { CURL_LOCK_ACCESS_NONE = 0, /* unspecified action */ CURL_LOCK_ACCESS_SHARED = 1, /* for read perhaps */ CURL_LOCK_ACCESS_SINGLE = 2, /* for write perhaps */ CURL_LOCK_ACCESS_LAST /* never use */ } curl_lock_access; typedef void (*curl_lock_function)(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr); typedef void (*curl_unlock_function)(CURL *handle, curl_lock_data data, void *userptr); typedef enum { CURLSHE_OK, /* all is fine */ CURLSHE_BAD_OPTION, /* 1 */ CURLSHE_IN_USE, /* 2 */ CURLSHE_INVALID, /* 3 */ CURLSHE_NOMEM, /* 4 out of memory */ CURLSHE_NOT_BUILT_IN, /* 5 feature not present in lib */ CURLSHE_LAST /* never use */ } CURLSHcode; typedef enum { CURLSHOPT_NONE, /* don't use */ CURLSHOPT_SHARE, /* specify a data type to share */ CURLSHOPT_UNSHARE, /* specify which data type to stop sharing */ CURLSHOPT_LOCKFUNC, /* pass in a 'curl_lock_function' pointer */ CURLSHOPT_UNLOCKFUNC, /* pass in a 'curl_unlock_function' pointer */ CURLSHOPT_USERDATA, /* pass in a user data pointer used in the lock/unlock callback functions */ CURLSHOPT_LAST /* never use */ } CURLSHoption; CURL_EXTERN CURLSH *curl_share_init(void); CURL_EXTERN CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option, ...); CURL_EXTERN CURLSHcode curl_share_cleanup(CURLSH *); /**************************************************************************** * Structures for querying information about the curl library at runtime. */ typedef enum { CURLVERSION_FIRST, CURLVERSION_SECOND, CURLVERSION_THIRD, CURLVERSION_FOURTH, CURLVERSION_FIFTH, CURLVERSION_LAST /* never actually use this */ } CURLversion; /* The 'CURLVERSION_NOW' is the symbolic name meant to be used by basically all programs ever that want to get version information. It is meant to be a built-in version number for what kind of struct the caller expects. If the struct ever changes, we redefine the NOW to another enum from above. */ #define CURLVERSION_NOW CURLVERSION_FIFTH typedef struct { CURLversion age; /* age of the returned struct */ const char *version; /* LIBCURL_VERSION */ unsigned int version_num; /* LIBCURL_VERSION_NUM */ const char *host; /* OS/host/cpu/machine when configured */ int features; /* bitmask, see defines below */ const char *ssl_version; /* human readable string */ long ssl_version_num; /* not used anymore, always 0 */ const char *libz_version; /* human readable string */ /* protocols is terminated by an entry with a NULL protoname */ const char * const *protocols; /* The fields below this were added in CURLVERSION_SECOND */ const char *ares; int ares_num; /* This field was added in CURLVERSION_THIRD */ const char *libidn; /* These field were added in CURLVERSION_FOURTH */ /* Same as '_libiconv_version' if built with HAVE_ICONV */ int iconv_ver_num; const char *libssh_version; /* human readable string */ /* These fields were added in CURLVERSION_FIFTH */ unsigned int brotli_ver_num; /* Numeric Brotli version (MAJOR << 24) | (MINOR << 12) | PATCH */ const char *brotli_version; /* human readable string. */ } curl_version_info_data; #define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */ #define CURL_VERSION_KERBEROS4 (1<<1) /* Kerberos V4 auth is supported (deprecated) */ #define CURL_VERSION_SSL (1<<2) /* SSL options are present */ #define CURL_VERSION_LIBZ (1<<3) /* libz features are present */ #define CURL_VERSION_NTLM (1<<4) /* NTLM auth is supported */ #define CURL_VERSION_GSSNEGOTIATE (1<<5) /* Negotiate auth is supported (deprecated) */ #define CURL_VERSION_DEBUG (1<<6) /* Built with debug capabilities */ #define CURL_VERSION_ASYNCHDNS (1<<7) /* Asynchronous DNS resolves */ #define CURL_VERSION_SPNEGO (1<<8) /* SPNEGO auth is supported */ #define CURL_VERSION_LARGEFILE (1<<9) /* Supports files larger than 2GB */ #define CURL_VERSION_IDN (1<<10) /* Internationized Domain Names are supported */ #define CURL_VERSION_SSPI (1<<11) /* Built against Windows SSPI */ #define CURL_VERSION_CONV (1<<12) /* Character conversions supported */ #define CURL_VERSION_CURLDEBUG (1<<13) /* Debug memory tracking supported */ #define CURL_VERSION_TLSAUTH_SRP (1<<14) /* TLS-SRP auth is supported */ #define CURL_VERSION_NTLM_WB (1<<15) /* NTLM delegation to winbind helper is supported */ #define CURL_VERSION_HTTP2 (1<<16) /* HTTP2 support built-in */ #define CURL_VERSION_GSSAPI (1<<17) /* Built against a GSS-API library */ #define CURL_VERSION_KERBEROS5 (1<<18) /* Kerberos V5 auth is supported */ #define CURL_VERSION_UNIX_SOCKETS (1<<19) /* Unix domain sockets support */ #define CURL_VERSION_PSL (1<<20) /* Mozilla's Public Suffix List, used for cookie domain verification */ #define CURL_VERSION_HTTPS_PROXY (1<<21) /* HTTPS-proxy support built-in */ #define CURL_VERSION_MULTI_SSL (1<<22) /* Multiple SSL backends available */ #define CURL_VERSION_BROTLI (1<<23) /* Brotli features are present. */ #define CURL_VERSION_ALTSVC (1<<24) /* Alt-Svc handling built-in */ /* * NAME curl_version_info() * * DESCRIPTION * * This function returns a pointer to a static copy of the version info * struct. See above. */ CURL_EXTERN curl_version_info_data *curl_version_info(CURLversion); /* * NAME curl_easy_strerror() * * DESCRIPTION * * The curl_easy_strerror function may be used to turn a CURLcode value * into the equivalent human readable error string. This is useful * for printing meaningful error messages. */ CURL_EXTERN const char *curl_easy_strerror(CURLcode); /* * NAME curl_share_strerror() * * DESCRIPTION * * The curl_share_strerror function may be used to turn a CURLSHcode value * into the equivalent human readable error string. This is useful * for printing meaningful error messages. */ CURL_EXTERN const char *curl_share_strerror(CURLSHcode); /* * NAME curl_easy_pause() * * DESCRIPTION * * The curl_easy_pause function pauses or unpauses transfers. Select the new * state by setting the bitmask, use the convenience defines below. * */ CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask); #define CURLPAUSE_RECV (1<<0) #define CURLPAUSE_RECV_CONT (0) #define CURLPAUSE_SEND (1<<2) #define CURLPAUSE_SEND_CONT (0) #define CURLPAUSE_ALL (CURLPAUSE_RECV|CURLPAUSE_SEND) #define CURLPAUSE_CONT (CURLPAUSE_RECV_CONT|CURLPAUSE_SEND_CONT) #ifdef __cplusplus } #endif /* unfortunately, the easy.h and multi.h include files need options and info stuff before they can be included! */ #include "easy.h" /* nothing in curl is fun without the easy stuff */ #include "multi.h" #include "urlapi.h" /* the typechecker doesn't work in C++ (yet) */ #if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && \ !defined(__cplusplus) && !defined(CURL_DISABLE_TYPECHECK) #include "typecheck-gcc.h" #else #if defined(__STDC__) && (__STDC__ >= 1) /* This preprocessor magic that replaces a call with the exact same call is only done to make sure application authors pass exactly three arguments to these functions. */ #define curl_easy_setopt(handle,opt,param) curl_easy_setopt(handle,opt,param) #define curl_easy_getinfo(handle,info,arg) curl_easy_getinfo(handle,info,arg) #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) #define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) #endif /* __STDC__ >= 1 */ #endif /* gcc >= 4.3 && !__cplusplus */ #endif /* __CURL_CURL_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/curl.h
C
apache-2.0
106,482
#ifndef __CURL_CURLVER_H #define __CURL_CURLVER_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* This header file contains nothing but libcurl version info, generated by a script at release-time. This was made its own header file in 7.11.2 */ /* This is the global package copyright */ #define LIBCURL_COPYRIGHT "1996 - 2019 Daniel Stenberg, <daniel@haxx.se>." /* This is the version number of the libcurl package from which this header file origins: */ #define LIBCURL_VERSION "7.65.0-DEV" /* The numeric version number is also available "in parts" by using these defines: */ #define LIBCURL_VERSION_MAJOR 7 #define LIBCURL_VERSION_MINOR 65 #define LIBCURL_VERSION_PATCH 0 /* This is the numeric version of the libcurl version number, meant for easier parsing and comparions by programs. The LIBCURL_VERSION_NUM define will always follow this syntax: 0xXXYYZZ Where XX, YY and ZZ are the main version, release and patch numbers in hexadecimal (using 8 bits each). All three numbers are always represented using two digits. 1.2 would appear as "0x010200" while version 9.11.7 appears as "0x090b07". This 6-digit (24 bits) hexadecimal number does not show pre-release number, and it is always a greater number in a more recent release. It makes comparisons with greater than and less than work. Note: This define is the full hex number and _does not_ use the CURL_VERSION_BITS() macro since curl's own configure script greps for it and needs it to contain the full number. */ #define LIBCURL_VERSION_NUM 0x074100 /* * This is the date and time when the full source package was created. The * timestamp is not stored in git, as the timestamp is properly set in the * tarballs by the maketgz script. * * The format of the date follows this template: * * "2007-11-23" */ #define LIBCURL_TIMESTAMP "[unreleased]" #define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z)) #define CURL_AT_LEAST_VERSION(x,y,z) \ (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) #endif /* __CURL_CURLVER_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/curlver.h
C
apache-2.0
3,042
#ifndef __CURL_EASY_H #define __CURL_EASY_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ #ifdef __cplusplus extern "C" { #endif CURL_EXTERN CURL *curl_easy_init(void); CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); CURL_EXTERN void curl_easy_cleanup(CURL *curl); /* * NAME curl_easy_getinfo() * * DESCRIPTION * * Request internal information from the curl session with this function. The * third argument MUST be a pointer to a long, a pointer to a char * or a * pointer to a double (as the documentation describes elsewhere). The data * pointed to will be filled in accordingly and can be relied upon only if the * function returns CURLE_OK. This function is intended to get used *AFTER* a * performed transfer, all results from this function are undefined until the * transfer is completed. */ CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); /* * NAME curl_easy_duphandle() * * DESCRIPTION * * Creates a new curl session handle with the same options set for the handle * passed in. Duplicating a handle could only be a matter of cloning data and * options, internal state info and things like persistent connections cannot * be transferred. It is useful in multithreaded applications when you can run * curl_easy_duphandle() for each new thread to avoid a series of identical * curl_easy_setopt() invokes in every thread. */ CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl); /* * NAME curl_easy_reset() * * DESCRIPTION * * Re-initializes a CURL handle to the default values. This puts back the * handle to the same state as it was in when it was just created. * * It does keep: live connections, the Session ID cache, the DNS cache and the * cookies. */ CURL_EXTERN void curl_easy_reset(CURL *curl); /* * NAME curl_easy_recv() * * DESCRIPTION * * Receives data from the connected socket. Use after successful * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. */ CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n); /* * NAME curl_easy_send() * * DESCRIPTION * * Sends data over the connected socket. Use after successful * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. */ CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, size_t buflen, size_t *n); /* * NAME curl_easy_upkeep() * * DESCRIPTION * * Performs connection upkeep for the given session handle. */ CURL_EXTERN CURLcode curl_easy_upkeep(CURL *curl); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/easy.h
C
apache-2.0
3,641
#ifndef __CURL_MULTI_H #define __CURL_MULTI_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* This is an "external" header file. Don't give away any internals here! GOALS o Enable a "pull" interface. The application that uses libcurl decides where and when to ask libcurl to get/send data. o Enable multiple simultaneous transfers in the same thread without making it complicated for the application. o Enable the application to select() on its own file descriptors and curl's file descriptors simultaneous easily. */ /* * This header file should not really need to include "curl.h" since curl.h * itself includes this file and we expect user applications to do #include * <curl/curl.h> without the need for especially including multi.h. * * For some reason we added this include here at one point, and rather than to * break existing (wrongly written) libcurl applications, we leave it as-is * but with this warning attached. */ #include "curl.h" #ifdef __cplusplus extern "C" { #endif #if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) typedef struct Curl_multi CURLM; #else typedef void CURLM; #endif typedef enum { CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or curl_multi_socket*() soon */ CURLM_OK, CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was attempted to get added - again */ CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a callback */ CURLM_LAST } CURLMcode; /* just to make code nicer when using curl_multi_socket() you can now check for CURLM_CALL_MULTI_SOCKET too in the same style it works for curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM /* bitmask bits for CURLMOPT_PIPELINING */ #define CURLPIPE_NOTHING 0L #define CURLPIPE_HTTP1 1L #define CURLPIPE_MULTIPLEX 2L typedef enum { CURLMSG_NONE, /* first, not used */ CURLMSG_DONE, /* This easy handle has completed. 'result' contains the CURLcode of the transfer */ CURLMSG_LAST /* last, not used */ } CURLMSG; struct CURLMsg { CURLMSG msg; /* what this message means */ CURL *easy_handle; /* the handle it concerns */ union { void *whatever; /* message-specific data */ CURLcode result; /* return code for transfer */ } data; }; typedef struct CURLMsg CURLMsg; /* Based on poll(2) structure and values. * We don't use pollfd and POLL* constants explicitly * to cover platforms without poll(). */ #define CURL_WAIT_POLLIN 0x0001 #define CURL_WAIT_POLLPRI 0x0002 #define CURL_WAIT_POLLOUT 0x0004 struct curl_waitfd { curl_socket_t fd; short events; short revents; /* not supported yet */ }; /* * Name: curl_multi_init() * * Desc: inititalize multi-style curl usage * * Returns: a new CURLM handle to use in all 'curl_multi' functions. */ CURL_EXTERN CURLM *curl_multi_init(void); /* * Name: curl_multi_add_handle() * * Desc: add a standard curl handle to the multi stack * * Returns: CURLMcode type, general multi error code. */ CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *curl_handle); /* * Name: curl_multi_remove_handle() * * Desc: removes a curl handle from the multi stack again * * Returns: CURLMcode type, general multi error code. */ CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle); /* * Name: curl_multi_fdset() * * Desc: Ask curl for its fd_set sets. The app can use these to select() or * poll() on. We want curl_multi_perform() called as soon as one of * them are ready. * * Returns: CURLMcode type, general multi error code. */ CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *exc_fd_set, int *max_fd); /* * Name: curl_multi_wait() * * Desc: Poll on all fds within a CURLM set as well as any * additional fds passed to the function. * * Returns: CURLMcode type, general multi error code. */ CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, struct curl_waitfd extra_fds[], unsigned int extra_nfds, int timeout_ms, int *ret); /* * Name: curl_multi_perform() * * Desc: When the app thinks there's data available for curl it calls this * function to read/write whatever there is right now. This returns * as soon as the reads and writes are done. This function does not * require that there actually is data available for reading or that * data can be written, it can be called just in case. It returns * the number of handles that still transfer data in the second * argument's integer-pointer. * * Returns: CURLMcode type, general multi error code. *NOTE* that this only * returns errors etc regarding the whole multi stack. There might * still have occurred problems on individual transfers even when * this returns OK. */ CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles); /* * Name: curl_multi_cleanup() * * Desc: Cleans up and removes a whole multi stack. It does not free or * touch any individual easy handles in any way. We need to define * in what state those handles will be if this function is called * in the middle of a transfer. * * Returns: CURLMcode type, general multi error code. */ CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); /* * Name: curl_multi_info_read() * * Desc: Ask the multi handle if there's any messages/informationals from * the individual transfers. Messages include informationals such as * error code from the transfer or just the fact that a transfer is * completed. More details on these should be written down as well. * * Repeated calls to this function will return a new struct each * time, until a special "end of msgs" struct is returned as a signal * that there is no more to get at this point. * * The data the returned pointer points to will not survive calling * curl_multi_cleanup(). * * The 'CURLMsg' struct is meant to be very simple and only contain * very basic information. If more involved information is wanted, * we will provide the particular "transfer handle" in that struct * and that should/could/would be used in subsequent * curl_easy_getinfo() calls (or similar). The point being that we * must never expose complex structs to applications, as then we'll * undoubtably get backwards compatibility problems in the future. * * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out * of structs. It also writes the number of messages left in the * queue (after this read) in the integer the second argument points * to. */ CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue); /* * Name: curl_multi_strerror() * * Desc: The curl_multi_strerror function may be used to turn a CURLMcode * value into the equivalent human readable error string. This is * useful for printing meaningful error messages. * * Returns: A pointer to a zero-terminated error message. */ CURL_EXTERN const char *curl_multi_strerror(CURLMcode); /* * Name: curl_multi_socket() and * curl_multi_socket_all() * * Desc: An alternative version of curl_multi_perform() that allows the * application to pass in one of the file descriptors that have been * detected to have "action" on them and let libcurl perform. * See man page for details. */ #define CURL_POLL_NONE 0 #define CURL_POLL_IN 1 #define CURL_POLL_OUT 2 #define CURL_POLL_INOUT 3 #define CURL_POLL_REMOVE 4 #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD #define CURL_CSELECT_IN 0x01 #define CURL_CSELECT_OUT 0x02 #define CURL_CSELECT_ERR 0x04 typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ curl_socket_t s, /* socket */ int what, /* see above */ void *userp, /* private callback pointer */ void *socketp); /* private socket pointer */ /* * Name: curl_multi_timer_callback * * Desc: Called by libcurl whenever the library detects a change in the * maximum number of milliseconds the app is allowed to wait before * curl_multi_socket() or curl_multi_perform() must be called * (to allow libcurl's timed events to take place). * * Returns: The callback should return zero. */ typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ long timeout_ms, /* see above */ void *userp); /* private callback pointer */ CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, int *running_handles); CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, curl_socket_t s, int ev_bitmask, int *running_handles); CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, int *running_handles); #ifndef CURL_ALLOW_OLD_MULTI_SOCKET /* This macro below was added in 7.16.3 to push users who recompile to use the new curl_multi_socket_action() instead of the old curl_multi_socket() */ #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) #endif /* * Name: curl_multi_timeout() * * Desc: Returns the maximum number of milliseconds the app is allowed to * wait before curl_multi_socket() or curl_multi_perform() must be * called (to allow libcurl's timed events to take place). * * Returns: CURLM error code. */ CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, long *milliseconds); #undef CINIT /* re-using the same name as in curl.h */ #ifdef CURL_ISOCPP #define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num #else /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ #define LONG CURLOPTTYPE_LONG #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT #define OFF_T CURLOPTTYPE_OFF_T #define CINIT(name,type,number) CURLMOPT_/**/name = type + number #endif typedef enum { /* This is the socket callback function pointer */ CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), /* This is the argument passed to the socket callback */ CINIT(SOCKETDATA, OBJECTPOINT, 2), /* set to 1 to enable pipelining for this multi handle */ CINIT(PIPELINING, LONG, 3), /* This is the timer callback function pointer */ CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), /* This is the argument passed to the timer callback */ CINIT(TIMERDATA, OBJECTPOINT, 5), /* maximum number of entries in the connection cache */ CINIT(MAXCONNECTS, LONG, 6), /* maximum number of (pipelining) connections to one host */ CINIT(MAX_HOST_CONNECTIONS, LONG, 7), /* maximum number of requests in a pipeline */ CINIT(MAX_PIPELINE_LENGTH, LONG, 8), /* a connection with a content-length longer than this will not be considered for pipelining */ CINIT(CONTENT_LENGTH_PENALTY_SIZE, OFF_T, 9), /* a connection with a chunk length longer than this will not be considered for pipelining */ CINIT(CHUNK_LENGTH_PENALTY_SIZE, OFF_T, 10), /* a list of site names(+port) that are blacklisted from pipelining */ CINIT(PIPELINING_SITE_BL, OBJECTPOINT, 11), /* a list of server types that are blacklisted from pipelining */ CINIT(PIPELINING_SERVER_BL, OBJECTPOINT, 12), /* maximum number of open connections in total */ CINIT(MAX_TOTAL_CONNECTIONS, LONG, 13), /* This is the server push callback function pointer */ CINIT(PUSHFUNCTION, FUNCTIONPOINT, 14), /* This is the argument passed to the server push callback */ CINIT(PUSHDATA, OBJECTPOINT, 15), CURLMOPT_LASTENTRY /* the last unused */ } CURLMoption; /* * Name: curl_multi_setopt() * * Desc: Sets options for the multi handle. * * Returns: CURLM error code. */ CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, CURLMoption option, ...); /* * Name: curl_multi_assign() * * Desc: This function sets an association in the multi handle between the * given socket and a private pointer of the application. This is * (only) useful for curl_multi_socket uses. * * Returns: CURLM error code. */ CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd, void *sockp); /* * Name: curl_push_callback * * Desc: This callback gets called when a new stream is being pushed by the * server. It approves or denies the new stream. * * Returns: CURL_PUSH_OK or CURL_PUSH_DENY. */ #define CURL_PUSH_OK 0 #define CURL_PUSH_DENY 1 struct curl_pushheaders; /* forward declaration only */ CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, size_t num); CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, const char *name); typedef int (*curl_push_callback)(CURL *parent, CURL *easy, size_t num_headers, struct curl_pushheaders *headers, void *userp); #ifdef __cplusplus } /* end of extern "C" */ #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/multi.h
C
apache-2.0
16,211
#ifndef __CURL_SYSTEM_H #define __CURL_SYSTEM_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* * Try to keep one section per platform, compiler and architecture, otherwise, * if an existing section is reused for a different one and later on the * original is adjusted, probably the piggybacking one can be adversely * changed. * * In order to differentiate between platforms/compilers/architectures use * only compiler built in predefined preprocessor symbols. * * curl_off_t * ---------- * * For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit * wide signed integral data type. The width of this data type must remain * constant and independent of any possible large file support settings. * * As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit * wide signed integral data type if there is no 64-bit type. * * As a general rule, curl_off_t shall not be mapped to off_t. This rule shall * only be violated if off_t is the only 64-bit data type available and the * size of off_t is independent of large file support settings. Keep your * build on the safe side avoiding an off_t gating. If you have a 64-bit * off_t then take for sure that another 64-bit data type exists, dig deeper * and you will find it. * */ #if defined(__DJGPP__) || defined(__GO32__) # if defined(__DJGPP__) && (__DJGPP__ > 1) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # else # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__SALFORDC__) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__BORLANDC__) # if (__BORLANDC__ < 0x520) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # else # define CURL_TYPEOF_CURL_OFF_T __int64 # define CURL_FORMAT_CURL_OFF_T "I64d" # define CURL_FORMAT_CURL_OFF_TU "I64u" # define CURL_SUFFIX_CURL_OFF_T i64 # define CURL_SUFFIX_CURL_OFF_TU ui64 # endif # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__TURBOC__) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__WATCOMC__) # if defined(__386__) # define CURL_TYPEOF_CURL_OFF_T __int64 # define CURL_FORMAT_CURL_OFF_T "I64d" # define CURL_FORMAT_CURL_OFF_TU "I64u" # define CURL_SUFFIX_CURL_OFF_T i64 # define CURL_SUFFIX_CURL_OFF_TU ui64 # else # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__POCC__) # if (__POCC__ < 280) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # elif defined(_MSC_VER) # define CURL_TYPEOF_CURL_OFF_T __int64 # define CURL_FORMAT_CURL_OFF_T "I64d" # define CURL_FORMAT_CURL_OFF_TU "I64u" # define CURL_SUFFIX_CURL_OFF_T i64 # define CURL_SUFFIX_CURL_OFF_TU ui64 # else # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__LCC__) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__SYMBIAN32__) # if defined(__EABI__) /* Treat all ARM compilers equally */ # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # elif defined(__CW32__) # pragma longlong on # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # elif defined(__VC32__) # define CURL_TYPEOF_CURL_OFF_T __int64 # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int #elif defined(__MWERKS__) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(_WIN32_WCE) # define CURL_TYPEOF_CURL_OFF_T __int64 # define CURL_FORMAT_CURL_OFF_T "I64d" # define CURL_FORMAT_CURL_OFF_TU "I64u" # define CURL_SUFFIX_CURL_OFF_T i64 # define CURL_SUFFIX_CURL_OFF_TU ui64 # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__MINGW32__) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "I64d" # define CURL_FORMAT_CURL_OFF_TU "I64u" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_WS2TCPIP_H 1 #elif defined(__VMS) # if defined(__VAX) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # else # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int #elif defined(__OS400__) # if defined(__ILEC400__) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 # endif #elif defined(__MVS__) # if defined(__IBMC__) || defined(__IBMCPP__) # if defined(_ILP32) # elif defined(_LP64) # endif # if defined(_LONG_LONG) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # elif defined(_LP64) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # else # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 # endif #elif defined(__370__) # if defined(__IBMC__) || defined(__IBMCPP__) # if defined(_ILP32) # elif defined(_LP64) # endif # if defined(_LONG_LONG) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # elif defined(_LP64) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # else # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 # endif #elif defined(TPF) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # define CURL_TYPEOF_CURL_SOCKLEN_T int #elif defined(__TINYC__) /* also known as tcc */ # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Oracle Solaris Studio */ # if !defined(__LP64) && (defined(__ILP32) || \ defined(__i386) || \ defined(__sparcv8) || \ defined(__sparcv8plus)) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # elif defined(__LP64) || \ defined(__amd64) || defined(__sparcv9) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 #elif defined(__xlc__) /* IBM xlc compiler */ # if !defined(_LP64) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # else # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 /* ===================================== */ /* KEEP MSVC THE PENULTIMATE ENTRY */ /* ===================================== */ #elif defined(_MSC_VER) # if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) # define CURL_TYPEOF_CURL_OFF_T __int64 # define CURL_FORMAT_CURL_OFF_T "I64d" # define CURL_FORMAT_CURL_OFF_TU "I64u" # define CURL_SUFFIX_CURL_OFF_T i64 # define CURL_SUFFIX_CURL_OFF_TU ui64 # else # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T int /* ===================================== */ /* KEEP GENERIC GCC THE LAST ENTRY */ /* ===================================== */ #elif defined(__GNUC__) && !defined(_SCO_DS) # if !defined(__LP64__) && \ (defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \ defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \ defined(__sparc__) || defined(__mips__) || defined(__sh__) || \ defined(__XTENSA__) || \ (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4) || \ (defined(__LONG_MAX__) && __LONG_MAX__ == 2147483647L)) # define CURL_TYPEOF_CURL_OFF_T long long # define CURL_FORMAT_CURL_OFF_T "lld" # define CURL_FORMAT_CURL_OFF_TU "llu" # define CURL_SUFFIX_CURL_OFF_T LL # define CURL_SUFFIX_CURL_OFF_TU ULL # elif defined(__LP64__) || \ defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \ (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) || \ (defined(__LONG_MAX__) && __LONG_MAX__ == 9223372036854775807L) # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # endif # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t # define CURL_PULL_SYS_TYPES_H 1 # define CURL_PULL_SYS_SOCKET_H 1 #else /* generic "safe guess" on old 32 bit style */ # define CURL_TYPEOF_CURL_OFF_T long # define CURL_FORMAT_CURL_OFF_T "ld" # define CURL_FORMAT_CURL_OFF_TU "lu" # define CURL_SUFFIX_CURL_OFF_T L # define CURL_SUFFIX_CURL_OFF_TU UL # define CURL_TYPEOF_CURL_SOCKLEN_T int #endif #ifdef _AIX /* AIX needs <sys/poll.h> */ #define CURL_PULL_SYS_POLL_H #endif /* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */ /* ws2tcpip.h is required here to properly make type definitions below. */ #ifdef CURL_PULL_WS2TCPIP_H # include <winsock2.h> # include <windows.h> # include <ws2tcpip.h> #endif /* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ /* sys/types.h is required here to properly make type definitions below. */ #ifdef CURL_PULL_SYS_TYPES_H # include <sys/types.h> #endif /* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ /* sys/socket.h is required here to properly make type definitions below. */ #ifdef CURL_PULL_SYS_SOCKET_H #ifdef USE_LWIPSOCK # include <lwip/sockets.h> #else # include <sys/socket.h> #endif #endif /* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */ /* sys/poll.h is required here to properly make type definitions below. */ #ifdef CURL_PULL_SYS_POLL_H # include <sys/poll.h> #endif /* Data type definition of curl_socklen_t. */ #ifdef CURL_TYPEOF_CURL_SOCKLEN_T typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; #endif /* Data type definition of curl_off_t. */ #ifdef CURL_TYPEOF_CURL_OFF_T typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; #endif /* * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow * these to be visible and exported by the external libcurl interface API, * while also making them visible to the library internals, simply including * curl_setup.h, without actually needing to include curl.h internally. * If some day this section would grow big enough, all this should be moved * to its own header file. */ /* * Figure out if we can use the ## preprocessor operator, which is supported * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ * or __cplusplus so we need to carefully check for them too. */ #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ defined(__ILEC400__) /* This compiler is believed to have an ISO compatible preprocessor */ #define CURL_ISOCPP #else /* This compiler is believed NOT to have an ISO compatible preprocessor */ #undef CURL_ISOCPP #endif /* * Macros for minimum-width signed and unsigned curl_off_t integer constants. */ #if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) # define __CURL_OFF_T_C_HLPR2(x) x # define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) #else # ifdef CURL_ISOCPP # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix # else # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix # endif # define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) #endif #endif /* __CURL_SYSTEM_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/system.h
C
apache-2.0
18,574
#ifndef __CURL_TYPECHECK_GCC_H #define __CURL_TYPECHECK_GCC_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* wraps curl_easy_setopt() with typechecking */ /* To add a new kind of warning, add an * if(_curl_is_sometype_option(_curl_opt)) * if(!_curl_is_sometype(value)) * _curl_easy_setopt_err_sometype(); * block and define _curl_is_sometype_option, _curl_is_sometype and * _curl_easy_setopt_err_sometype below * * NOTE: We use two nested 'if' statements here instead of the && operator, in * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x * when compiling with -Wlogical-op. * * To add an option that uses the same type as an existing option, you'll just * need to extend the appropriate _curl_*_option macro */ #define curl_easy_setopt(handle, option, value) \ __extension__ ({ \ __typeof__(option) _curl_opt = option; \ if(__builtin_constant_p(_curl_opt)) { \ if(_curl_is_long_option(_curl_opt)) \ if(!_curl_is_long(value)) \ _curl_easy_setopt_err_long(); \ if(_curl_is_off_t_option(_curl_opt)) \ if(!_curl_is_off_t(value)) \ _curl_easy_setopt_err_curl_off_t(); \ if(_curl_is_string_option(_curl_opt)) \ if(!_curl_is_string(value)) \ _curl_easy_setopt_err_string(); \ if(_curl_is_write_cb_option(_curl_opt)) \ if(!_curl_is_write_cb(value)) \ _curl_easy_setopt_err_write_callback(); \ if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION) \ if(!_curl_is_resolver_start_callback(value)) \ _curl_easy_setopt_err_resolver_start_callback(); \ if((_curl_opt) == CURLOPT_READFUNCTION) \ if(!_curl_is_read_cb(value)) \ _curl_easy_setopt_err_read_cb(); \ if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ if(!_curl_is_ioctl_cb(value)) \ _curl_easy_setopt_err_ioctl_cb(); \ if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ if(!_curl_is_sockopt_cb(value)) \ _curl_easy_setopt_err_sockopt_cb(); \ if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ if(!_curl_is_opensocket_cb(value)) \ _curl_easy_setopt_err_opensocket_cb(); \ if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ if(!_curl_is_progress_cb(value)) \ _curl_easy_setopt_err_progress_cb(); \ if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ if(!_curl_is_debug_cb(value)) \ _curl_easy_setopt_err_debug_cb(); \ if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ if(!_curl_is_ssl_ctx_cb(value)) \ _curl_easy_setopt_err_ssl_ctx_cb(); \ if(_curl_is_conv_cb_option(_curl_opt)) \ if(!_curl_is_conv_cb(value)) \ _curl_easy_setopt_err_conv_cb(); \ if((_curl_opt) == CURLOPT_SEEKFUNCTION) \ if(!_curl_is_seek_cb(value)) \ _curl_easy_setopt_err_seek_cb(); \ if(_curl_is_cb_data_option(_curl_opt)) \ if(!_curl_is_cb_data(value)) \ _curl_easy_setopt_err_cb_data(); \ if((_curl_opt) == CURLOPT_ERRORBUFFER) \ if(!_curl_is_error_buffer(value)) \ _curl_easy_setopt_err_error_buffer(); \ if((_curl_opt) == CURLOPT_STDERR) \ if(!_curl_is_FILE(value)) \ _curl_easy_setopt_err_FILE(); \ if(_curl_is_postfields_option(_curl_opt)) \ if(!_curl_is_postfields(value)) \ _curl_easy_setopt_err_postfields(); \ if((_curl_opt) == CURLOPT_HTTPPOST) \ if(!_curl_is_arr((value), struct curl_httppost)) \ _curl_easy_setopt_err_curl_httpost(); \ if((_curl_opt) == CURLOPT_MIMEPOST) \ if(!_curl_is_ptr((value), curl_mime)) \ _curl_easy_setopt_err_curl_mimepost(); \ if(_curl_is_slist_option(_curl_opt)) \ if(!_curl_is_arr((value), struct curl_slist)) \ _curl_easy_setopt_err_curl_slist(); \ if((_curl_opt) == CURLOPT_SHARE) \ if(!_curl_is_ptr((value), CURLSH)) \ _curl_easy_setopt_err_CURLSH(); \ } \ curl_easy_setopt(handle, _curl_opt, value); \ }) /* wraps curl_easy_getinfo() with typechecking */ #define curl_easy_getinfo(handle, info, arg) \ __extension__ ({ \ __typeof__(info) _curl_info = info; \ if(__builtin_constant_p(_curl_info)) { \ if(_curl_is_string_info(_curl_info)) \ if(!_curl_is_arr((arg), char *)) \ _curl_easy_getinfo_err_string(); \ if(_curl_is_long_info(_curl_info)) \ if(!_curl_is_arr((arg), long)) \ _curl_easy_getinfo_err_long(); \ if(_curl_is_double_info(_curl_info)) \ if(!_curl_is_arr((arg), double)) \ _curl_easy_getinfo_err_double(); \ if(_curl_is_slist_info(_curl_info)) \ if(!_curl_is_arr((arg), struct curl_slist *)) \ _curl_easy_getinfo_err_curl_slist(); \ if(_curl_is_tlssessioninfo_info(_curl_info)) \ if(!_curl_is_arr((arg), struct curl_tlssessioninfo *)) \ _curl_easy_getinfo_err_curl_tlssesssioninfo(); \ if(_curl_is_certinfo_info(_curl_info)) \ if(!_curl_is_arr((arg), struct curl_certinfo *)) \ _curl_easy_getinfo_err_curl_certinfo(); \ if(_curl_is_socket_info(_curl_info)) \ if(!_curl_is_arr((arg), curl_socket_t)) \ _curl_easy_getinfo_err_curl_socket(); \ if(_curl_is_off_t_info(_curl_info)) \ if(!_curl_is_arr((arg), curl_off_t)) \ _curl_easy_getinfo_err_curl_off_t(); \ } \ curl_easy_getinfo(handle, _curl_info, arg); \ }) /* * For now, just make sure that the functions are called with three arguments */ #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) #define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) /* the actual warnings, triggered by calling the _curl_easy_setopt_err* * functions */ /* To define a new warning, use _CURL_WARNING(identifier, "message") */ #define _CURL_WARNING(id, message) \ static void __attribute__((__warning__(message))) \ __attribute__((__unused__)) __attribute__((__noinline__)) \ id(void) { __asm__(""); } _CURL_WARNING(_curl_easy_setopt_err_long, "curl_easy_setopt expects a long argument for this option") _CURL_WARNING(_curl_easy_setopt_err_curl_off_t, "curl_easy_setopt expects a curl_off_t argument for this option") _CURL_WARNING(_curl_easy_setopt_err_string, "curl_easy_setopt expects a " "string ('char *' or char[]) argument for this option" ) _CURL_WARNING(_curl_easy_setopt_err_write_callback, "curl_easy_setopt expects a curl_write_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_resolver_start_callback, "curl_easy_setopt expects a " "curl_resolver_start_callback argument for this option" ) _CURL_WARNING(_curl_easy_setopt_err_read_cb, "curl_easy_setopt expects a curl_read_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_ioctl_cb, "curl_easy_setopt expects a curl_ioctl_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_sockopt_cb, "curl_easy_setopt expects a curl_sockopt_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_opensocket_cb, "curl_easy_setopt expects a " "curl_opensocket_callback argument for this option" ) _CURL_WARNING(_curl_easy_setopt_err_progress_cb, "curl_easy_setopt expects a curl_progress_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_debug_cb, "curl_easy_setopt expects a curl_debug_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb, "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_conv_cb, "curl_easy_setopt expects a curl_conv_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_seek_cb, "curl_easy_setopt expects a curl_seek_callback argument for this option") _CURL_WARNING(_curl_easy_setopt_err_cb_data, "curl_easy_setopt expects a " "private data pointer as argument for this option") _CURL_WARNING(_curl_easy_setopt_err_error_buffer, "curl_easy_setopt expects a " "char buffer of CURL_ERROR_SIZE as argument for this option") _CURL_WARNING(_curl_easy_setopt_err_FILE, "curl_easy_setopt expects a 'FILE *' argument for this option") _CURL_WARNING(_curl_easy_setopt_err_postfields, "curl_easy_setopt expects a 'void *' or 'char *' argument for this option") _CURL_WARNING(_curl_easy_setopt_err_curl_httpost, "curl_easy_setopt expects a 'struct curl_httppost *' " "argument for this option") _CURL_WARNING(_curl_easy_setopt_err_curl_mimepost, "curl_easy_setopt expects a 'curl_mime *' " "argument for this option") _CURL_WARNING(_curl_easy_setopt_err_curl_slist, "curl_easy_setopt expects a 'struct curl_slist *' argument for this option") _CURL_WARNING(_curl_easy_setopt_err_CURLSH, "curl_easy_setopt expects a CURLSH* argument for this option") _CURL_WARNING(_curl_easy_getinfo_err_string, "curl_easy_getinfo expects a pointer to 'char *' for this info") _CURL_WARNING(_curl_easy_getinfo_err_long, "curl_easy_getinfo expects a pointer to long for this info") _CURL_WARNING(_curl_easy_getinfo_err_double, "curl_easy_getinfo expects a pointer to double for this info") _CURL_WARNING(_curl_easy_getinfo_err_curl_slist, "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info") _CURL_WARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo, "curl_easy_getinfo expects a pointer to " "'struct curl_tlssessioninfo *' for this info") _CURL_WARNING(_curl_easy_getinfo_err_curl_certinfo, "curl_easy_getinfo expects a pointer to " "'struct curl_certinfo *' for this info") _CURL_WARNING(_curl_easy_getinfo_err_curl_socket, "curl_easy_getinfo expects a pointer to curl_socket_t for this info") _CURL_WARNING(_curl_easy_getinfo_err_curl_off_t, "curl_easy_getinfo expects a pointer to curl_off_t for this info") /* groups of curl_easy_setops options that take the same type of argument */ /* To add a new option to one of the groups, just add * (option) == CURLOPT_SOMETHING * to the or-expression. If the option takes a long or curl_off_t, you don't * have to do anything */ /* evaluates to true if option takes a long argument */ #define _curl_is_long_option(option) \ (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) #define _curl_is_off_t_option(option) \ ((option) > CURLOPTTYPE_OFF_T) /* evaluates to true if option takes a char* argument */ #define _curl_is_string_option(option) \ ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \ (option) == CURLOPT_ACCEPT_ENCODING || \ (option) == CURLOPT_ALTSVC || \ (option) == CURLOPT_CAINFO || \ (option) == CURLOPT_CAPATH || \ (option) == CURLOPT_COOKIE || \ (option) == CURLOPT_COOKIEFILE || \ (option) == CURLOPT_COOKIEJAR || \ (option) == CURLOPT_COOKIELIST || \ (option) == CURLOPT_CRLFILE || \ (option) == CURLOPT_CUSTOMREQUEST || \ (option) == CURLOPT_DEFAULT_PROTOCOL || \ (option) == CURLOPT_DNS_INTERFACE || \ (option) == CURLOPT_DNS_LOCAL_IP4 || \ (option) == CURLOPT_DNS_LOCAL_IP6 || \ (option) == CURLOPT_DNS_SERVERS || \ (option) == CURLOPT_DOH_URL || \ (option) == CURLOPT_EGDSOCKET || \ (option) == CURLOPT_FTPPORT || \ (option) == CURLOPT_FTP_ACCOUNT || \ (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ (option) == CURLOPT_INTERFACE || \ (option) == CURLOPT_ISSUERCERT || \ (option) == CURLOPT_KEYPASSWD || \ (option) == CURLOPT_KRBLEVEL || \ (option) == CURLOPT_LOGIN_OPTIONS || \ (option) == CURLOPT_MAIL_AUTH || \ (option) == CURLOPT_MAIL_FROM || \ (option) == CURLOPT_NETRC_FILE || \ (option) == CURLOPT_NOPROXY || \ (option) == CURLOPT_PASSWORD || \ (option) == CURLOPT_PINNEDPUBLICKEY || \ (option) == CURLOPT_PRE_PROXY || \ (option) == CURLOPT_PROXY || \ (option) == CURLOPT_PROXYPASSWORD || \ (option) == CURLOPT_PROXYUSERNAME || \ (option) == CURLOPT_PROXYUSERPWD || \ (option) == CURLOPT_PROXY_CAINFO || \ (option) == CURLOPT_PROXY_CAPATH || \ (option) == CURLOPT_PROXY_CRLFILE || \ (option) == CURLOPT_PROXY_KEYPASSWD || \ (option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \ (option) == CURLOPT_PROXY_SERVICE_NAME || \ (option) == CURLOPT_PROXY_SSLCERT || \ (option) == CURLOPT_PROXY_SSLCERTTYPE || \ (option) == CURLOPT_PROXY_SSLKEY || \ (option) == CURLOPT_PROXY_SSLKEYTYPE || \ (option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \ (option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \ (option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \ (option) == CURLOPT_PROXY_TLSAUTH_TYPE || \ (option) == CURLOPT_RANDOM_FILE || \ (option) == CURLOPT_RANGE || \ (option) == CURLOPT_REFERER || \ (option) == CURLOPT_RTSP_SESSION_ID || \ (option) == CURLOPT_RTSP_STREAM_URI || \ (option) == CURLOPT_RTSP_TRANSPORT || \ (option) == CURLOPT_SERVICE_NAME || \ (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ (option) == CURLOPT_SSH_KNOWNHOSTS || \ (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ (option) == CURLOPT_SSLCERT || \ (option) == CURLOPT_SSLCERTTYPE || \ (option) == CURLOPT_SSLENGINE || \ (option) == CURLOPT_SSLKEY || \ (option) == CURLOPT_SSLKEYTYPE || \ (option) == CURLOPT_SSL_CIPHER_LIST || \ (option) == CURLOPT_TLSAUTH_PASSWORD || \ (option) == CURLOPT_TLSAUTH_TYPE || \ (option) == CURLOPT_TLSAUTH_USERNAME || \ (option) == CURLOPT_UNIX_SOCKET_PATH || \ (option) == CURLOPT_URL || \ (option) == CURLOPT_USERAGENT || \ (option) == CURLOPT_USERNAME || \ (option) == CURLOPT_USERPWD || \ (option) == CURLOPT_XOAUTH2_BEARER || \ 0) /* evaluates to true if option takes a curl_write_callback argument */ #define _curl_is_write_cb_option(option) \ ((option) == CURLOPT_HEADERFUNCTION || \ (option) == CURLOPT_WRITEFUNCTION) /* evaluates to true if option takes a curl_conv_callback argument */ #define _curl_is_conv_cb_option(option) \ ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) /* evaluates to true if option takes a data argument to pass to a callback */ #define _curl_is_cb_data_option(option) \ ((option) == CURLOPT_CHUNK_DATA || \ (option) == CURLOPT_CLOSESOCKETDATA || \ (option) == CURLOPT_DEBUGDATA || \ (option) == CURLOPT_FNMATCH_DATA || \ (option) == CURLOPT_HEADERDATA || \ (option) == CURLOPT_INTERLEAVEDATA || \ (option) == CURLOPT_IOCTLDATA || \ (option) == CURLOPT_OPENSOCKETDATA || \ (option) == CURLOPT_PRIVATE || \ (option) == CURLOPT_PROGRESSDATA || \ (option) == CURLOPT_READDATA || \ (option) == CURLOPT_SEEKDATA || \ (option) == CURLOPT_SOCKOPTDATA || \ (option) == CURLOPT_SSH_KEYDATA || \ (option) == CURLOPT_SSL_CTX_DATA || \ (option) == CURLOPT_WRITEDATA || \ (option) == CURLOPT_RESOLVER_START_DATA || \ (option) == CURLOPT_CURLU || \ 0) /* evaluates to true if option takes a POST data argument (void* or char*) */ #define _curl_is_postfields_option(option) \ ((option) == CURLOPT_POSTFIELDS || \ (option) == CURLOPT_COPYPOSTFIELDS || \ 0) /* evaluates to true if option takes a struct curl_slist * argument */ #define _curl_is_slist_option(option) \ ((option) == CURLOPT_HTTP200ALIASES || \ (option) == CURLOPT_HTTPHEADER || \ (option) == CURLOPT_MAIL_RCPT || \ (option) == CURLOPT_POSTQUOTE || \ (option) == CURLOPT_PREQUOTE || \ (option) == CURLOPT_PROXYHEADER || \ (option) == CURLOPT_QUOTE || \ (option) == CURLOPT_RESOLVE || \ (option) == CURLOPT_TELNETOPTIONS || \ 0) /* groups of curl_easy_getinfo infos that take the same type of argument */ /* evaluates to true if info expects a pointer to char * argument */ #define _curl_is_string_info(info) \ (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG) /* evaluates to true if info expects a pointer to long argument */ #define _curl_is_long_info(info) \ (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) /* evaluates to true if info expects a pointer to double argument */ #define _curl_is_double_info(info) \ (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) /* true if info expects a pointer to struct curl_slist * argument */ #define _curl_is_slist_info(info) \ (((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST)) /* true if info expects a pointer to struct curl_tlssessioninfo * argument */ #define _curl_is_tlssessioninfo_info(info) \ (((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION)) /* true if info expects a pointer to struct curl_certinfo * argument */ #define _curl_is_certinfo_info(info) ((info) == CURLINFO_CERTINFO) /* true if info expects a pointer to struct curl_socket_t argument */ #define _curl_is_socket_info(info) \ (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T) /* true if info expects a pointer to curl_off_t argument */ #define _curl_is_off_t_info(info) \ (CURLINFO_OFF_T < (info)) /* typecheck helpers -- check whether given expression has requested type*/ /* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros, * otherwise define a new macro. Search for __builtin_types_compatible_p * in the GCC manual. * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is * the actual expression passed to the curl_easy_setopt macro. This * means that you can only apply the sizeof and __typeof__ operators, no * == or whatsoever. */ /* XXX: should evaluate to true if expr is a pointer */ #define _curl_is_any_ptr(expr) \ (sizeof(expr) == sizeof(void *)) /* evaluates to true if expr is NULL */ /* XXX: must not evaluate expr, so this check is not accurate */ #define _curl_is_NULL(expr) \ (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) /* evaluates to true if expr is type*, const type* or NULL */ #define _curl_is_ptr(expr, type) \ (_curl_is_NULL(expr) || \ __builtin_types_compatible_p(__typeof__(expr), type *) || \ __builtin_types_compatible_p(__typeof__(expr), const type *)) /* evaluates to true if expr is one of type[], type*, NULL or const type* */ #define _curl_is_arr(expr, type) \ (_curl_is_ptr((expr), type) || \ __builtin_types_compatible_p(__typeof__(expr), type [])) /* evaluates to true if expr is a string */ #define _curl_is_string(expr) \ (_curl_is_arr((expr), char) || \ _curl_is_arr((expr), signed char) || \ _curl_is_arr((expr), unsigned char)) /* evaluates to true if expr is a long (no matter the signedness) * XXX: for now, int is also accepted (and therefore short and char, which * are promoted to int when passed to a variadic function) */ #define _curl_is_long(expr) \ (__builtin_types_compatible_p(__typeof__(expr), long) || \ __builtin_types_compatible_p(__typeof__(expr), signed long) || \ __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ __builtin_types_compatible_p(__typeof__(expr), int) || \ __builtin_types_compatible_p(__typeof__(expr), signed int) || \ __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ __builtin_types_compatible_p(__typeof__(expr), short) || \ __builtin_types_compatible_p(__typeof__(expr), signed short) || \ __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ __builtin_types_compatible_p(__typeof__(expr), char) || \ __builtin_types_compatible_p(__typeof__(expr), signed char) || \ __builtin_types_compatible_p(__typeof__(expr), unsigned char)) /* evaluates to true if expr is of type curl_off_t */ #define _curl_is_off_t(expr) \ (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) /* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ /* XXX: also check size of an char[] array? */ #define _curl_is_error_buffer(expr) \ (_curl_is_NULL(expr) || \ __builtin_types_compatible_p(__typeof__(expr), char *) || \ __builtin_types_compatible_p(__typeof__(expr), char[])) /* evaluates to true if expr is of type (const) void* or (const) FILE* */ #if 0 #define _curl_is_cb_data(expr) \ (_curl_is_ptr((expr), void) || \ _curl_is_ptr((expr), FILE)) #else /* be less strict */ #define _curl_is_cb_data(expr) \ _curl_is_any_ptr(expr) #endif /* evaluates to true if expr is of type FILE* */ #define _curl_is_FILE(expr) \ (_curl_is_NULL(expr) || \ (__builtin_types_compatible_p(__typeof__(expr), FILE *))) /* evaluates to true if expr can be passed as POST data (void* or char*) */ #define _curl_is_postfields(expr) \ (_curl_is_ptr((expr), void) || \ _curl_is_arr((expr), char) || \ _curl_is_arr((expr), unsigned char)) /* helper: __builtin_types_compatible_p distinguishes between functions and * function pointers, hide it */ #define _curl_callback_compatible(func, type) \ (__builtin_types_compatible_p(__typeof__(func), type) || \ __builtin_types_compatible_p(__typeof__(func) *, type)) /* evaluates to true if expr is of type curl_resolver_start_callback */ #define _curl_is_resolver_start_callback(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_resolver_start_callback)) /* evaluates to true if expr is of type curl_read_callback or "similar" */ #define _curl_is_read_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), __typeof__(fread) *) || \ _curl_callback_compatible((expr), curl_read_callback) || \ _curl_callback_compatible((expr), _curl_read_callback1) || \ _curl_callback_compatible((expr), _curl_read_callback2) || \ _curl_callback_compatible((expr), _curl_read_callback3) || \ _curl_callback_compatible((expr), _curl_read_callback4) || \ _curl_callback_compatible((expr), _curl_read_callback5) || \ _curl_callback_compatible((expr), _curl_read_callback6)) typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *); typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *); typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *); typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *); typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *); typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *); /* evaluates to true if expr is of type curl_write_callback or "similar" */ #define _curl_is_write_cb(expr) \ (_curl_is_read_cb(expr) || \ _curl_callback_compatible((expr), __typeof__(fwrite) *) || \ _curl_callback_compatible((expr), curl_write_callback) || \ _curl_callback_compatible((expr), _curl_write_callback1) || \ _curl_callback_compatible((expr), _curl_write_callback2) || \ _curl_callback_compatible((expr), _curl_write_callback3) || \ _curl_callback_compatible((expr), _curl_write_callback4) || \ _curl_callback_compatible((expr), _curl_write_callback5) || \ _curl_callback_compatible((expr), _curl_write_callback6)) typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *); typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t, const void *); typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *); typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *); typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t, const void *); typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *); /* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ #define _curl_is_ioctl_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_ioctl_callback) || \ _curl_callback_compatible((expr), _curl_ioctl_callback1) || \ _curl_callback_compatible((expr), _curl_ioctl_callback2) || \ _curl_callback_compatible((expr), _curl_ioctl_callback3) || \ _curl_callback_compatible((expr), _curl_ioctl_callback4)) typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *); typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *); typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *); typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *); /* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ #define _curl_is_sockopt_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_sockopt_callback) || \ _curl_callback_compatible((expr), _curl_sockopt_callback1) || \ _curl_callback_compatible((expr), _curl_sockopt_callback2)) typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t, curlsocktype); /* evaluates to true if expr is of type curl_opensocket_callback or "similar" */ #define _curl_is_opensocket_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_opensocket_callback) || \ _curl_callback_compatible((expr), _curl_opensocket_callback1) || \ _curl_callback_compatible((expr), _curl_opensocket_callback2) || \ _curl_callback_compatible((expr), _curl_opensocket_callback3) || \ _curl_callback_compatible((expr), _curl_opensocket_callback4)) typedef curl_socket_t (*_curl_opensocket_callback1) (void *, curlsocktype, struct curl_sockaddr *); typedef curl_socket_t (*_curl_opensocket_callback2) (void *, curlsocktype, const struct curl_sockaddr *); typedef curl_socket_t (*_curl_opensocket_callback3) (const void *, curlsocktype, struct curl_sockaddr *); typedef curl_socket_t (*_curl_opensocket_callback4) (const void *, curlsocktype, const struct curl_sockaddr *); /* evaluates to true if expr is of type curl_progress_callback or "similar" */ #define _curl_is_progress_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_progress_callback) || \ _curl_callback_compatible((expr), _curl_progress_callback1) || \ _curl_callback_compatible((expr), _curl_progress_callback2)) typedef int (*_curl_progress_callback1)(void *, double, double, double, double); typedef int (*_curl_progress_callback2)(const void *, double, double, double, double); /* evaluates to true if expr is of type curl_debug_callback or "similar" */ #define _curl_is_debug_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_debug_callback) || \ _curl_callback_compatible((expr), _curl_debug_callback1) || \ _curl_callback_compatible((expr), _curl_debug_callback2) || \ _curl_callback_compatible((expr), _curl_debug_callback3) || \ _curl_callback_compatible((expr), _curl_debug_callback4) || \ _curl_callback_compatible((expr), _curl_debug_callback5) || \ _curl_callback_compatible((expr), _curl_debug_callback6) || \ _curl_callback_compatible((expr), _curl_debug_callback7) || \ _curl_callback_compatible((expr), _curl_debug_callback8)) typedef int (*_curl_debug_callback1) (CURL *, curl_infotype, char *, size_t, void *); typedef int (*_curl_debug_callback2) (CURL *, curl_infotype, char *, size_t, const void *); typedef int (*_curl_debug_callback3) (CURL *, curl_infotype, const char *, size_t, void *); typedef int (*_curl_debug_callback4) (CURL *, curl_infotype, const char *, size_t, const void *); typedef int (*_curl_debug_callback5) (CURL *, curl_infotype, unsigned char *, size_t, void *); typedef int (*_curl_debug_callback6) (CURL *, curl_infotype, unsigned char *, size_t, const void *); typedef int (*_curl_debug_callback7) (CURL *, curl_infotype, const unsigned char *, size_t, void *); typedef int (*_curl_debug_callback8) (CURL *, curl_infotype, const unsigned char *, size_t, const void *); /* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ /* this is getting even messier... */ #define _curl_is_ssl_ctx_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_ssl_ctx_callback) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \ _curl_callback_compatible((expr), _curl_ssl_ctx_callback8)) typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *); typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *); typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *); typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *, const void *); #ifdef HEADER_SSL_H /* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX * this will of course break if we're included before OpenSSL headers... */ typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *); typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *); typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *); typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, const void *); #else typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; #endif /* evaluates to true if expr is of type curl_conv_callback or "similar" */ #define _curl_is_conv_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_conv_callback) || \ _curl_callback_compatible((expr), _curl_conv_callback1) || \ _curl_callback_compatible((expr), _curl_conv_callback2) || \ _curl_callback_compatible((expr), _curl_conv_callback3) || \ _curl_callback_compatible((expr), _curl_conv_callback4)) typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); /* evaluates to true if expr is of type curl_seek_callback or "similar" */ #define _curl_is_seek_cb(expr) \ (_curl_is_NULL(expr) || \ _curl_callback_compatible((expr), curl_seek_callback) || \ _curl_callback_compatible((expr), _curl_seek_callback1) || \ _curl_callback_compatible((expr), _curl_seek_callback2)) typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); #endif /* __CURL_TYPECHECK_GCC_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/typecheck-gcc.h
C
apache-2.0
43,280
#ifndef __CURL_URLAPI_H #define __CURL_URLAPI_H /*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 2018 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ #include "curl.h" #ifdef __cplusplus extern "C" { #endif /* the error codes for the URL API */ typedef enum { CURLUE_OK, CURLUE_BAD_HANDLE, /* 1 */ CURLUE_BAD_PARTPOINTER, /* 2 */ CURLUE_MALFORMED_INPUT, /* 3 */ CURLUE_BAD_PORT_NUMBER, /* 4 */ CURLUE_UNSUPPORTED_SCHEME, /* 5 */ CURLUE_URLDECODE, /* 6 */ CURLUE_OUT_OF_MEMORY, /* 7 */ CURLUE_USER_NOT_ALLOWED, /* 8 */ CURLUE_UNKNOWN_PART, /* 9 */ CURLUE_NO_SCHEME, /* 10 */ CURLUE_NO_USER, /* 11 */ CURLUE_NO_PASSWORD, /* 12 */ CURLUE_NO_OPTIONS, /* 13 */ CURLUE_NO_HOST, /* 14 */ CURLUE_NO_PORT, /* 15 */ CURLUE_NO_QUERY, /* 16 */ CURLUE_NO_FRAGMENT /* 17 */ } CURLUcode; typedef enum { CURLUPART_URL, CURLUPART_SCHEME, CURLUPART_USER, CURLUPART_PASSWORD, CURLUPART_OPTIONS, CURLUPART_HOST, CURLUPART_PORT, CURLUPART_PATH, CURLUPART_QUERY, CURLUPART_FRAGMENT, CURLUPART_ZONEID /* added in 7.65.0 */ } CURLUPart; #define CURLU_DEFAULT_PORT (1<<0) /* return default port number */ #define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set, if the port number matches the default for the scheme */ #define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if missing */ #define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */ #define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */ #define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */ #define CURLU_URLDECODE (1<<6) /* URL decode on get */ #define CURLU_URLENCODE (1<<7) /* URL encode on set */ #define CURLU_APPENDQUERY (1<<8) /* append a form style part */ #define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */ typedef struct Curl_URL CURLU; /* * curl_url() creates a new CURLU handle and returns a pointer to it. * Must be freed with curl_url_cleanup(). */ CURL_EXTERN CURLU *curl_url(void); /* * curl_url_cleanup() frees the CURLU handle and related resources used for * the URL parsing. It will not free strings previously returned with the URL * API. */ CURL_EXTERN void curl_url_cleanup(CURLU *handle); /* * curl_url_dup() duplicates a CURLU handle and returns a new copy. The new * handle must also be freed with curl_url_cleanup(). */ CURL_EXTERN CURLU *curl_url_dup(CURLU *in); /* * curl_url_get() extracts a specific part of the URL from a CURLU * handle. Returns error code. The returned pointer MUST be freed with * curl_free() afterwards. */ CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what, char **part, unsigned int flags); /* * curl_url_set() sets a specific part of the URL in a CURLU handle. Returns * error code. The passed in string will be copied. Passing a NULL instead of * a part string, clears that part. */ CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what, const char *part, unsigned int flags); #ifdef __cplusplus } /* end of extern "C" */ #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/rtos/rhino/kernel/include/network/curl/urlapi.h
C
apache-2.0
4,327
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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. cur_makefile := $(lastword $(MAKEFILE_LIST)) # ========================================================================== # Building # ========================================================================== src := $(obj) PHONY := __build __build: $(cur_makefile): ; # Init all relevant variables used in kbuild files so # 1) they have correct type # 2) they do not inherit any value from the environment obj-y := lib-y := subdir-y := archive-custom := archive-custom-valid := always := targets := EXTRA_AFLAGS := EXTRA_CFLAGS := EXTRA_CPPFLAGS := EXTRA_LDFLAGS := asflags-y := ccflags-y := cppflags-y := ldflags-y := subdir-asflags-y := subdir-ccflags-y := include $(srctree)/scripts/include.mk # For backward compatibility check that these variables do not change save-cflags := $(CFLAGS) kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file := $(kbuild-dir)/Makefile include $(kbuild-file) $(kbuild-file): ; # If the save-* variables changed error out ifeq ($(KBUILD_NOPEDANTIC),) ifneq ("$(save-cflags)","$(CFLAGS)") $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y) endif endif include $(srctree)/scripts/lib.mk ifeq ($(WIN_PLAT),y) create_dir = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1)) else create_dir = [ -d $(1) ] || mkdir -p $(1) endif ifneq ($(KBUILD_SRC),) # Create output directory if not already present _dummy := $(shell $(call create_dir,$(obj))) # Create directories for object files if directory does not exist # Needed when obj-y := dir/file.o syntax is used _dummy := $(foreach d,$(obj-dirs), $(shell $(call create_dir,$(d)))) endif ifndef obj $(warning kbuild: build.mk is included improperly) endif # =========================================================================== ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) lib-target := $(obj)/lib.a endif ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),) builtin-target := $(obj)/built-in$(built_in_suffix) endif submodgoals = SUBMODS := $(filter $(obj)/%,$(SUBMODS)) ifneq ($(SUBMODS),) lst_target := $(filter %.s %.i %.lst, $(SUBMODS)) ifeq ($(lib-target),) ifneq ($(filter $(obj)/lib.lst,$(lst_target)),) $(error Cannot make lib.lst: lib-target not exists) endif endif ifeq ($(builtin-target),) ifneq ($(filter $(obj)/built-in.lst,$(lst_target)),) $(error Cannot make built-in.lst: builtin-target not exists) endif endif lst_target_obj := $(lst_target) lst_target_obj := $(filter-out $(obj)/built-in.lst $(obj)/lib.lst,$(lst_target_obj)) lst_target_obj := $(lst_target_obj:.s=.o) lst_target_obj := $(lst_target_obj:.i=.o) lst_target_obj := $(lst_target_obj:.lst=.o) lst_target_obj := $(sort $(lst_target_obj)) cur_submods := $(filter-out $(lst_target),$(SUBMODS)) cur_submods += $(lst_target_obj) include scripts/submods.mk buildextra-y := $(filter $(cur_submods),$(extra-y)) ifeq ($(filter $(obj)/built-in.lst,$(lst_target)),) # Just compile some of the object files buildsubdir-y := $(call get_subdirs,$(subdir-y),$(cur_submods)) buildobj-y := $(filter $(cur_submods) $(addsuffix /built-in$(built_in_suffix),$(buildsubdir-y)),$(obj-y)) buildobj-y += $(foreach m,$(multi-used-y),$(if $(filter $(cur_submods),$(call get_multi_objs,$m))),$m,) else # Compile all the object files buildsubdir-y := $(subdir-y) buildobj-y := $(obj-y) endif ifeq ($(filter $(obj)/lib.lst,$(lst_target)),) # Just compile some of the lib files buildlib-y := $(filter $(cur_submods),$(lib-y)) else # Compile all the lib files buildlib-y := $(lib-y) endif # Check for invalid targets errobj-y := $(cur_submods) errobj-y := $(filter-out $(buildsubdir-y) $(addsuffix /%,$(buildsubdir-y)),$(errobj-y)) errobj-y := $(filter-out $(buildextra-y) $(buildobj-y) $(buildlib-y),$(errobj-y)) errobj-y := $(filter-out $(foreach m,$(multi-used-y),$(call get_multi_objs,$m)),$(errobj-y)) ifneq ($(errobj-y),) $(warning Unknown targets in [$(obj)]: $(errobj-y)) endif # Update lst targets all_buildobj-y := $(buildextra-y) $(buildobj-y) $(filter-out %.a,$(builtin-target)) all_buildlib-y := $(filter %.a,$(builtin-target)) $(lib-target) lst_target := $(filter $(lst_target), \ $(all_buildobj-y:.o=.s) \ $(all_buildobj-y:.o=.i) \ $(all_buildobj-y:.o=.lst) \ $(patsubst %.a,%.lst,$(all_buildlib-y))) # Avoid .o compile error affecting .i generation lst_i_target := $(filter %.i, $(lst_target)) ifneq ($(lst_i_target),) $(lst_i_target:.i=.o) : | $(lst_i_target) endif ifeq ($(COMPILE_ONLY),1) submodgoals = $(call get_submodgoals,$@,$(SUBMODS)) endif else # SUBMODS buildsubdir-y := $(subdir-y) buildextra-y := $(extra-y) buildobj-y := $(obj-y) buildlib-y := $(lib-y) endif # SUBMODS archive-src-target := archive-custom-target := ifeq ($(GEN_LIB),1) archive-src-target := $(addprefix $(srctree)/$(src)/lib/,$(notdir $(archive-src-y))) archive-src-target += $(archive-custom-valid) archive-src-target := $(strip $(archive-src-target)) archive-custom-target := $(addprefix $(srctree)/$(src)/lib/,$(notdir $(archive-custom-valid))) endif __build: $(builtin-target) $(lib-target) $(buildextra-y) $(buildsubdir-y) $(lst_target) $(archive-src-target) $(archive-custom-target) $(always) @: # Compile C sources (.c) # --------------------------------------------------------------------------- # Default is built-in, unless we know otherwise quiet_modtag := $(empty) $(empty) quiet_cmd_cc_dummy = CC $(quiet_modtag) $@ cmd_cc_dummy = $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -c -x c -o $@ $(devnull) # For dummy object files. Recipe is: $(call if_changed,cc_dummy) quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< $(obj)/%.s: $(src)/%.c FORCE $(call if_changed_dep,cc_s_c) quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@ cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< $(obj)/%.i: $(src)/%.c FORCE $(call if_changed_dep,cc_i_c) # C (.c) files # The C file is compiled and updated dependency information is generated. # (See cmd_cc_o_c + relevant part of rule_cc_o_c) quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< define rule_cc_o_c $(call echo-cmd,cc_o_c) $(cmd_cc_o_c) endef # Built-in and composite module parts $(obj)/%.o: $(src)/%.c FORCE $(call if_changed_rule,cc_o_c) # Compile C++ sources (.cpp) # --------------------------------------------------------------------------- quiet_cmd_cc_s_c++ = C++ $(quiet_modtag) $@ cmd_cc_s_c++ = $(CC) $(c++_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< $(obj)/%.s: $(src)/%.cpp FORCE $(call if_changed_dep,cc_s_c++) $(obj)/%.s: $(src)/%.cc FORCE $(call if_changed_dep,cc_s_c++) quiet_cmd_cc_i_c++ = CPP $(quiet_modtag) $@ cmd_cc_i_c++ = $(CPP) $(c++_flags) -o $@ $< $(obj)/%.i: $(src)/%.cpp FORCE $(call if_changed_dep,cc_i_c++) $(obj)/%.i: $(src)/%.cc FORCE $(call if_changed_dep,cc_i_c++) # C++ (.cpp) files # The C++ file is compiled and updated dependency information is generated. # (See cmd_cc_o_c++ + relevant part of rule_cc_o_c) quiet_cmd_cc_o_c++ = C++ $(quiet_modtag) $@ cmd_cc_o_c++ = $(C++) $(c++_flags) -c -o $@ $< define rule_cc_o_c++ $(call echo-cmd,cc_o_c++) $(cmd_cc_o_c++) endef # Built-in and composite module parts $(obj)/%.o: $(src)/%.cpp FORCE $(call if_changed_rule,cc_o_c++) $(obj)/%.o: $(src)/%.cc FORCE $(call if_changed_rule,cc_o_c++) # Compile assembler sources (.S) # --------------------------------------------------------------------------- quiet_cmd_as_s_S = CPP $(quiet_modtag) $@ cmd_as_s_S = $(CPP) $(a_cpp_flags) -o $@ $< $(obj)/%.s: $(src)/%.S FORCE $(call if_changed_dep,as_s_S) quiet_cmd_as_o_S = AS $(quiet_modtag) $@ cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(obj)/%.o: $(src)/%.S FORCE $(call if_changed_dep,as_o_S) targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(lst_target) targets += $(MAKECMDGOALS) $(always) # Common list command # --------------------------------------------------------------------------- quiet_cmd_dump_lst_o = MKLST $@ ifeq ($(TOOLCHAIN),armclang) cmd_dump_lst_o = $(OBJDUMP) --datasymbols --text -c -d --interleave=source --output=$@ $< else cmd_dump_lst_o = $(OBJDUMP) -Sdlxr $< > $@ endif lst-cmd = @$(call echo-cmd,dump_lst_o) $(cmd_dump_lst_o) $(obj)/%.lst: $(obj)/%.o $(call lst-cmd) # Build the compiled-in targets # --------------------------------------------------------------------------- # To build objects in subdirs, we need to descend into the directories $(sort $(subdir-obj-y)): $(buildsubdir-y) ; # Archive command ifeq ($(TOOLCHAIN),armclang) archive-cmd = $(AR) --create --debug_symbols $@ $(1) else ifeq ($(WIN_PLAT),y) archive-cmd = ( ( echo create $@ && \ echo addmod $(subst $(space),$(comma),$(strip $(filter-out %.a,$(1)))) && \ $(foreach o,$(filter %.a,$(1)),echo addlib $o && ) \ echo save && \ echo end ) | $(AR) -M ) else # Command "/bin/echo -e" cannot work on Apple Mac machines, so we use "/usr/bin/printf" instead archive-cmd = ( /usr/bin/printf 'create $@\n\ addmod $(subst $(space),$(comma),$(strip $(filter-out %.a,$(1))))\n\ $(foreach o,$(filter %.a,$(1)),addlib $o\n)save\nend' | $(AR) -M ) endif endif # Archive check ifeq ($(CHECK_LIB_SRC),1) ifneq ($(archive-bin-y),) $(info ) $(info Library source check OK: $(archive-bin-y)) $(info ) endif ifneq ($(archive-src-y),) $(info ) $(error Error: The source files exist for libraries: $(archive-src-y)) endif endif # Archive without source files cmd_use_lib_file = $(call CMDCPFILE,$<,$@) quiet_cmd_use_lib_file = USELIB $(@) ifneq ($(archive-bin-y),) ifeq ($(GEN_LIB),1) $(info ) $(warning WARNING: No source files found for libraries: $(archive-bin-y)) $(info ) endif $(archive-bin-y): $(obj)/%: $(srctree)/$(src)/lib/% FORCE ifeq ($(FORCE_TO_USE_LIB),1) $(call cmd,use_lib_file) else $(call if_changed,use_lib_file) endif targets += $(archive-bin-y) endif # archive-bin-y # Archive generation (with source files) ifeq ($(GEN_LIB),1) ifeq ($(FORCE_TO_USE_LIB),1) $(error Conflicted options: GEN_LIB and FORCE_TO_USE_LIB) endif ifneq ($(archive-src-target),) cmd_gen_lib_file = ( $(call create_dir,$(dir $(@))) ) && $(call archive-cmd,$(filter-out $(PHONY),$^)) quiet_cmd_gen_lib_file = GENLIB $(@) define archive-src-target-rule $(1): $(addprefix $(obj)/,$(patsubst %/,%/$(notdir $(builtin-target)),$($(notdir $(1:.a=-y))))) endef $(foreach m, $(archive-src-target), $(eval $(call archive-src-target-rule,$(m)))) $(archive-src-target): FORCE ifeq ($(CHECK_GEN_LIB_DEP),1) $(call if_changed,gen_lib_file) else # Always pack lib $(call cmd,gen_lib_file) endif targets += $(archive-src-target) endif # archive-src-y endif # GEN_LIB # # Rule to compile a set of .o files into one .o/.a built-in file # ifdef builtin-target ifeq ($(BUILT-IN-OBJ),1) quiet_cmd_link_o_target = LD $@ # If the list of objects to link is empty, just create an empty built-in.o ifeq ($(TOOLCHAIN),armclang) cmd_link_o_target = $(if $(strip $(obj-y)),\ $(LD) -Wl$(comma)$(subst $(space),$(comma),$(strip $(ld_flags) --partial)) -nostdlib $(LINK_CFLAGS) -o $@ $(obj-y), \ $(call CMDRMFILE,$@) && $(AR) --create --debug_symbols $@) else cmd_link_o_target = $(if $(strip $(obj-y)),\ $(LD) -Wl$(comma)$(subst $(space),$(comma),$(strip $(ld_flags) -r)) -nostdlib -nostartfiles $(LINK_CFLAGS) -o $@ $(obj-y), \ $(call CMDRMFILE,$@) && $(AR) rcs$(KBUILD_ARFLAGS) $@) endif $(builtin-target): $(buildobj-y) FORCE $(call if_changed,link_o_target) else # BUILT-IN-OBJ quiet_cmd_ar_o_target = AR $@ cmd_ar_o_target = $(call archive-cmd,$(obj-y)) $(builtin-target): $(buildobj-y) FORCE $(call if_changed,ar_o_target) endif # BUILT-IN-OBJ targets += $(builtin-target) $(obj)/built-in.lst: $(builtin-target) $(call lst-cmd) endif # builtin-target # # Rule to compile a set of .o files into one .a file # ifdef lib-target quiet_cmd_link_l_target = AR $@ ifeq ($(TOOLCHAIN),armclang) cmd_link_l_target = $(call CMDRMFILE,$@) && $(AR) --create --debug_symbols $@ $(lib-y) else cmd_link_l_target = $(call CMDRMFILE,$@) && $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y) endif $(lib-target): $(buildlib-y) FORCE $(call if_changed,link_l_target) targets += $(lib-target) $(obj)/lib.lst: $(lib-target) $(call lst-cmd) endif # # Rule to link composite objects # # Composite objects are specified in kbuild makefile as follows: # <composite-object>-objs := <list of .o files> # or # <composite-object>-y := <list of .o files> link_multi_deps = \ $(filter $(addprefix $(obj)/, \ $($(subst $(obj)/,,$(@:.o=-objs))) \ $($(subst $(obj)/,,$(@:.o=-y)))), $^) quiet_cmd_link_multi-y = LD $@ ifeq ($(TOOLCHAIN),armclang) cmd_link_multi-y = $(LD) -Wl,$(subst $(space),$(comma),$(strip $(ld_flags) --partial)) -nostdlib $(LINK_CFLAGS) -o $@ $(link_multi_deps) else cmd_link_multi-y = $(LD) -Wl,$(subst $(space),$(comma),$(strip $(ld_flags) -r --whole-archive)) -nostdlib -nostartfiles $(LINK_CFLAGS) -o $@ $(link_multi_deps) endif $(multi-used-y): FORCE $(call if_changed,link_multi-y) $(call multi_depend, $(multi-used-y), .o, -objs -y) targets += $(multi-used-y) $(multi-used-y:.o=.lst): %.lst : %.o $(call lst-cmd) # Descending # --------------------------------------------------------------------------- PHONY += $(subdir-y) $(subdir-y): $(Q)$(MAKE) $(build)=$@ $(submodgoals) # Add FORCE to the prequisites of a target to force it to be always rebuilt. # --------------------------------------------------------------------------- PHONY += FORCE FORCE: # Read all saved command lines and dependencies for the $(targets) we # may be building above, using $(if_changed{,_dep}). As an # optimization, we don't need to read them if the target does not # exist, we will rebuild anyway in that case. targets := $(wildcard $(sort $(targets))) cmd_files := $(wildcard $(foreach f,$(targets),$(call get_depfile_name,$(f)))) ifneq ($(cmd_files),) include $(cmd_files) $(cmd_files): ; endif # Declare the contents of the .PHONY variable as phony. We keep that # information in a variable se we can use it in if_changed and friends. .PHONY: $(PHONY) # Last-resort default rule for unknown targets %:: @$(call echo-help,*** Error: No rule is defined for target: $@) @exit 1
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/build.mk
Makefile
apache-2.0
14,995
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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. cur_makefile := $(lastword $(MAKEFILE_LIST)) # ========================================================================== # Cleaning up # ========================================================================== src := $(obj) PHONY := __clean __clean: $(cur_makefile): ; # Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir # Usage: # $(Q)$(MAKE) $(clean)=dir clean := -f $(srctree)/scripts/clean.mk obj kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) include $(kbuild-dir)/Makefile # Figure out what we need to build from the various variables # ========================================================================== __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) subdir-y += $(__subdir-y) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) subdir-m += $(__subdir-m) __subdir- := $(patsubst %/,%,$(filter %/, $(obj-))) subdir- += $(__subdir-) # Subdirectories we need to descend into subdir-ym := $(sort $(subdir-y) $(subdir-m)) subdir-ymn := $(sort $(subdir-ym) $(subdir-)) obj-ymn := $(obj-y) $(obj-m) $(obj-) lib-ymn := $(lib-y) $(lib-m) $(lib-) # if $(foo-objs) exists, foo.o is a composite object multi-used-ymn := $(sort $(foreach m,$(obj-ymn), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) multi-objs-ymn := $(foreach m, $(multi-used-ymn), $($(m:.o=-objs)) $($(m:.o=-y))) obj-ymn := $(patsubst %/, %/built-in.o %/built-in.a, $(obj-y) $(obj-m) $(obj-)) extra-ymn := $(extra-y) $(extra-m) $(extra-) # build a list of files to remove, usually relative to the current # directory __clean-files := $(obj-ymn) $(lib-ymn) $(multi-used-ymn) \ $(multi-objs-ymn) $(extra-ymn) \ built-in.o built-in.a lib.a \ $(always) $(targets) $(clean-files) __clean-files := $(filter-out $(no-clean-files), $(__clean-files)) # clean-files is given relative to the current directory, unless it # starts with $(objtree)/ (which means "./", so do not add "./" unless # you want to delete a file from the toplevel object directory). __clean-files := $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(__clean-files))) \ $(filter $(objtree)/%, $(__clean-files)) # same as clean-files __clean-dirs := $(addprefix $(obj)/, $(filter-out $(objtree)/%, $(clean-dirs))) \ $(filter $(objtree)/%, $(clean-dirs)) # Add subdir path subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) obj-ymn := $(addprefix $(obj)/,$(obj-ymn)) lib-ymn := $(addprefix $(obj)/,$(lib-ymn)) multi-used-ymn := $(addprefix $(obj)/,$(multi-used-ymn)) multi-objs-ymn := $(addprefix $(obj)/,$(multi-objs-ymn)) SUBMODS := $(filter $(obj)/%,$(SUBMODS)) ifneq ($(SUBMODS),) include scripts/submods.mk buildsubdir-ymn := $(call get_subdirs,$(subdir-ymn),$(SUBMODS)) __full-clean-files := $(__clean-files) __clean-files := $(filter $(SUBMODS),$(__full-clean-files)) __clean-files += $(obj)/built-in.o $(obj)/built-in.a $(obj)/lib.a __clean-files += $(foreach m,$(multi-used-ymn),$(if $(filter $(SUBMODS),$(call get_multi_objs,$m))),$m,) # Check for invalid targets errobj-ymn := $(SUBMODS) errobj-ymn := $(filter-out $(buildsubdir-ymn) $(addsuffix /%,$(buildsubdir-ymn)),$(errobj-ymn)) errobj-ymn := $(filter-out $(__clean-files),$(errobj-ymn)) errobj-ymn := $(filter-out $(foreach m,$(multi-used-ymn),$(call get_multi_objs,$m)),$(errobj-ymn)) ifneq ($(errobj-ymn),) $(warning Unknown targets in [$(obj)]: $(errobj-ymn)) endif else # SUBMODS ifeq ($(ALLCLEAN),1) RM_ALL := 1 ifneq ($(KBUILD_OUTPUT),) RM_DIR := 1 endif endif ifeq ($(RM_DIR),1) buildsubdir-ymn := else buildsubdir-ymn := $(subdir-ymn) endif endif # SUBMODS # Include intermediate files include $(srctree)/scripts/include.mk __clean-files += $(foreach f,$(__clean-files),$(call get_depfile_name,$f)) #$(info RM_DIR=$(RM_DIR), RM_ALL=$(RM_ALL)) #$(info buildsubdir-ymn=$(buildsubdir-ymn)) #$(info __clean-files=$(__clean-files)) __clean-files := $(wildcard $(__clean-files)) __clean-dirs := $(wildcard $(__clean-dirs)) # ========================================================================== ifeq ($(RM_DIR),1) quiet_cmd_clean = RMDIR $(obj) cmd_clean = $(call CMDRMDIR,$(obj)) else # RM_DIR quiet_cmd_clean = CLEAN $(obj) ifeq ($(RM_ALL),1) cmd_clean = $(call CMDRMFILER,$(obj),*.o *.a *.s *.d) else cmd_clean = $(call CMDRMFILE,$(__clean-files)) endif quiet_cmd_cleandir = CLEAN $(__clean-dirs) cmd_cleandir = $(call CMDRMDIR,$(__clean-dirs)) endif # RM_DIR __clean: $(buildsubdir-ymn) @: ifeq ($(RM_DIR),1) +$(call cmd,clean) else # RM_DIR ifeq ($(RM_ALL),1) +$(call cmd,clean) else ifneq ($(strip $(__clean-files)),) +$(call cmd,clean) endif endif ifneq ($(strip $(__clean-dirs)),) +$(call cmd,cleandir) endif endif # RM_DIR # =========================================================================== # Generic stuff # =========================================================================== # Descending # --------------------------------------------------------------------------- PHONY += $(subdir-ymn) $(subdir-ymn): $(Q)$(MAKE) $(clean)=$@ # Declare the contents of the .PHONY variable as phony. We keep that # information in a variable se we can use it in if_changed and friends. .PHONY: $(PHONY)
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/clean.mk
Makefile
apache-2.0
5,862
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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. cur_makefile := $(lastword $(MAKEFILE_LIST)) $(cur_makefile): ; # ========================================================================== # # make W=... settings # # W=1 - warnings that may be relevant and does not occur too often # W=2 - warnings that occur quite often but may still be relevant # W=3 - the more obscure warnings, can most likely be ignored # # $(call cc-option, -W...) handles gcc -W.. options which # are not supported by all versions of the compiler # ========================================================================== ifeq ("$(origin W)","command line") export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) endif ifdef KBUILD_ENABLE_EXTRA_GCC_CHECKS warning- := $(empty) warning-1 := -Wextra -Wunused -Wno-unused-parameter warning-1 += -Wmissing-declarations warning-1 += -Wmissing-format-attribute warning-1 += -Wmissing-include-dirs warning-1 += -Wunused-but-set-variable warning-1 += -Wno-missing-field-initializers c_warning-1 := -Wmissing-prototypes -Wold-style-definition warning-2 := -Waggregate-return warning-2 += -Wcast-align warning-2 += -Wdisabled-optimization warning-2 += -Wshadow warning-2 += -Wlogical-op warning-2 += -Wmissing-field-initializers c_warning-2 := -Wnested-externs warning-3 := -Wcast-qual warning-3 += -Wconversion warning-3 += -Wpacked warning-3 += -Wpadded warning-3 += -Wpointer-arith warning-3 += -Wredundant-decls warning-3 += -Wswitch-default warning-3 += -Wpacked-bitfield-compat warning-3 += -Wvla c_warning-3 := -Wbad-function-cast warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) c_warning := $(warning-$(findstring 1, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) c_warning += $(warning-$(findstring 2, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) c_warning += $(warning-$(findstring 3, $(KBUILD_ENABLE_EXTRA_GCC_CHECKS))) ifeq ("$(strip $(warning) $(c_warning))","") $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown) endif KBUILD_CFLAGS += $(warning) C_ONLY_FLAGS += $(c_warning) else ifeq ($(COMPILER),clang) KBUILD_CFLAGS += -Wno-initializer-overrides KBUILD_CFLAGS += -Wno-unused-value KBUILD_CFLAGS += -Wno-format KBUILD_CFLAGS += -Wno-unknown-warning-option KBUILD_CFLAGS += -Wno-sign-compare) KBUILD_CFLAGS += -Wno-format-zero-length KBUILD_CFLAGS += -Wno-uninitialized endif endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/extrawarn.mk
Makefile
apache-2.0
3,067
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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 __INCLUDE_MK__ __INCLUDE_MK__ := 1 cur_makefile := $(lastword $(MAKEFILE_LIST)) $(cur_makefile): ; #### # Generic definitions ifeq ($(WIN_PLAT),y) ifeq ($(WIN_SHELL),y) # make will choose sh.exe as SHELL if it finds sh.exe in the directories of PATH, regardless of # the setting in environment or parent (e.g., when git.exe is in the PATH) SHELL := cmd.exe endif endif # Convenient variables lparen := ( rparen := ) comma := , quote := " squote := ' empty := space := $(empty) $(empty) ifeq ($(WIN_PLAT),y) devnull := nul else devnull := /dev/null endif ### # Remove/copy commands ifeq ($(WIN_PLAT),y) CMDRMFILE = del /f /q $(subst /,\,$1) >nul 2>&1 CMDRMFILER = cd $(subst /,\,$1) && del /f /q /s $(subst /,\,$2) CMDRMDIR = rmdir /s /q $(subst /,\,$1) >nul 2>&1 || del /f /q /s $(subst /,\,$1)\* CMDCPFILE = copy /y $(subst /,\,$1 $2) else CMDRMFILE = rm -f $1 CMDRMFILER = find $1 $(RCS_FIND_IGNORE) \ \( $(addprefix -name ,'$(firstword $2)') \ $(addprefix -o -name ',$(addsuffix ',$(filter-out $(firstword $2),$2))) \) \ -type f -print | xargs rm -f CMDRMDIR = rm -fr $1 CMDCPFILE = cp -f $1 $2 endif ### # Build-in obj suffix ifeq ($(BUILT-IN-OBJ),1) built_in_suffix := .o else built_in_suffix := .a endif ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $(1)).$(notdir $(1)) ### # The temporary file to save gcc -MF generated dependencies must not # contain a comma get_depfile_name = $(subst $(comma),_,$(dot-target).d) depfile = $(call get_depfile_name,$@) ### # filename of target with directory and extension stripped basetarget = $(basename $(notdir $@)) ### # filename of first prerequisite with directory and extension stripped baseprereq = $(basename $(notdir $<)) ### # Escape special characters for use in echo statements ifeq ($(WIN_PLAT),y) # Escape redirection character in echo in Windows escchar = $(subst $(lparen),^$(lparen),$(subst $(rparen),^$(rparen),$(subst &,^&,$(subst |,^|,$(subst <,^<,$(subst >,^>,$1)))))) else # Escape single quote for use in echo statements escchar = $(subst $(squote),'\$(squote)',$1) endif ### # Easy method for doing a status message kecho := : ifeq ($(WIN_PLAT),y) quiet_kecho := echo. else quiet_kecho := echo endif silent_kecho := : kecho := $($(quiet)kecho) ifeq ($(WIN_PLAT),y) echo-help = @echo. $(call escchar,$(1)) & else echo-help = @echo ' $(call escchar,$(1))' endif ### # try-run ifeq ($(WIN_PLAT),y) try-run = $(shell ($(1) >$(devnull) 2>&1) && echo. $(2) || echo. $(3)) # Or, using define to construct multi-line WIN commands, # with if command: if not errorlevel 1 else try-run = $(shell if ($(1)) >$(devnull) 2>&1; \ then echo "$(2)"; \ else echo "$(3)"; \ fi) endif ### # cc-option cc-option = $(call try-run, \ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c \ -o $(devnull) $(devnull),$(1),$(2)) ### # Shorthand for $(Q)$(MAKE) -f scripts/build.mk obj= # Usage: # $(Q)$(MAKE) $(build)=dir build := -f $(srctree)/scripts/build.mk obj # Prefix -I with $(srctree) if it is not an absolute path. # skip if -I has no parameter #addtree = $(if $(patsubst -I%,%,$(1)), \ #$(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)) ifeq ($(WIN_PLAT),y) addtree = $(if $(patsubst -I%,%,$(1)), \ $(if $(filter-out -I$(KBUILD_ROOT)/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1))) else addtree = $(if $(patsubst -I%,%,$(1)), \ $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1))) endif # Find all -I options and call addtree flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) # echo command. # Short version is used, if $(quiet) equals `quiet_', otherwise full one. ifeq ($(WIN_PLAT),y) echo-cmd = $(if $($(quiet)cmd_$(1)),\ echo. $(call escchar,$($(quiet)cmd_$(1)))$(echo-why) &&) echo-cmd-nowhy = $(if $($(quiet)cmd_$(1)),\ echo. $(call escchar,$($(quiet)cmd_$(1))) &&) else echo-cmd = $(if $($(quiet)cmd_$(1)),\ echo ' $(call escchar,$($(quiet)cmd_$(1)))$(echo-why)' ;) echo-cmd-nowhy = $(if $($(quiet)cmd_$(1)),\ echo ' $(call escchar,$($(quiet)cmd_$(1)))' ;) endif # printing commands cmd = @$(echo-cmd) $(cmd_$(1)) # Add $(obj)/ for paths that are not absolute objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) ### # if_changed - execute command if any prerequisite is newer than # target, or command line has changed # if_changed_dep - as if_changed, but uses fixdep to reveal dependencies # including used config symbols # if_changed_rule - as if_changed but execute rule instead # See Documentation/kbuild/makefiles.txt for more info ifneq ($(KBUILD_NOCMDDEP),1) # Check if both arguments has same arguments. Result is empty string if equal. # User may override this check using make KBUILD_NOCMDDEP=1 arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ $(filter-out $(cmd_$@), $(cmd_$(1))) ) else arg-check = $(if $(strip $(cmd_$@)),,1) endif # Replace >$< with >$$< to preserve $ when reloading the .cmd file # (needed for make) # Replace >#< with >\#< to avoid starting a comment in the .cmd file # (needed for make) # Replace >'< with >'\''< to be able to enclose the whole string in '...' # (needed for the shell) make-cmd = $(call escchar,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1))))) # Find any prerequisites that is newer than target or that does not exist. # PHONY targets skipped in both cases. any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) ifeq ($(WIN_PLAT),y) depfile-new = echo. > $(depfile) && \ echo cmd_$@ := $(make-cmd) >> $(depfile) && \ echo. >> $(depfile) depfile-add = echo. >> $(depfile) && \ echo cmd_$@ := $(make-cmd) >> $(depfile) && \ echo. >> $(depfile) else depfile-new = printf '\n%s\n' 'cmd_$@ := $(make-cmd)' > $(depfile) depfile-add = printf '\n%s\n' 'cmd_$@ := $(make-cmd)' >> $(depfile) endif # Execute command if command has changed or prerequisite(s) are updated. # if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ @ ( $(echo-cmd) $(cmd_$(1)) ) && \ ( $(depfile-new) )) if_changed2 = $(if $(strip $(any-prereq) $(call arg-check,$(2))), \ @ ( $(call echo-cmd,$(1)) $(cmd_$(1)) && \ $(call echo-cmd,$(2)) $(cmd_$(2)) ) && \ ( $(call depfile-new,$(2)) )) # Execute the command and also postprocess generated .d dependencies file. if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \ @ ( $(echo-cmd) $(cmd_$(1)) ) && \ ( $(depfile-add) )) # Usage: $(call if_changed_rule,foo) # Will check if $(cmd_foo) or any of the prerequisites changed, # and if so will execute $(rule_foo). if_changed_rule = $(if $(strip $(any-prereq) $(arg-check)), \ @ ( $(rule_$(1)) ) && \ ( $(depfile-add) )) ### # why - tell why a a target got build # enabled by make V=2 # Output (listed in the order they are checked): # (1) - due to target is PHONY # (2) - due to target missing # (3) - due to: file1.h file2.h # (4) - due to command line change # (5) - due to missing .cmd file # (6) - due to target not in $(targets) # (1) PHONY targets are always build # (2) No target, so we better build it # (3) Prerequisite is newer than target # (4) The command line stored in the file named dir/.target.cmd # differed from actual command line. This happens when compiler # options changes # (5) No dir/.target.d file (used to store command line) # (6) No dir/.target.d file and target not listed in $(targets) # This is a good hint that there is a bug in the kbuild file ifeq ($(KBUILD_VERBOSE),2) why = \ $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ $(if $(wildcard $@), \ $(if $(strip $(any-prereq)),- due to: $(any-prereq), \ $(if $(arg-check), \ $(if $(cmd_$@),- due to command line change, \ $(if $(filter $@, $(targets)), \ - due to missing .d file, \ - due to $(notdir $@) not in $$(targets) \ ) \ ) \ ) \ ), \ - due to target missing \ ) \ ) echo-why = $(call escchar, $(strip $(why))) endif endif # __INCLUDE_MK__
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/include.mk
Makefile
apache-2.0
9,834
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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. cur_makefile := $(lastword $(MAKEFILE_LIST)) $(cur_makefile): ; # Backward compatibility asflags-y += $(EXTRA_AFLAGS) ccflags-y += $(EXTRA_CFLAGS) cppflags-y += $(EXTRA_CPPFLAGS) ldflags-y += $(EXTRA_LDFLAGS) # # flags that take effect in sub directories export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y) export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y) # Figure out what we need to build from the various variables # =========================================================================== # Handle archives # --------------------------------------------------------------------------- # Extract archives from $(obj-y) archive-y := $(filter %.a, $(obj-y)) archive-custom-valid := $(filter $(archive-custom), $(archive-y)) ifeq ($(archive-y),) archive-src-y := archive-bin-y := else # archive-y ifeq ($(FORCE_TO_USE_LIB),1) archive-bin-y := $(archive-y) else # Filter out archive-custom-valid archive-y := $(filter-out $(archive-custom-valid), $(archive-y)) # Extract archives that have source files available archive-src-y := $(foreach m, $(archive-y), $(if $(wildcard $(addprefix $(srctree)/$(src)/,$($(m:.a=-y):.o=.*))), $(m))) # Extract archives that do NOT have source files archive-bin-y := $(filter-out $(archive-src-y), $(archive-y)) endif # If the source files of the archive (including archive-custom-valid) exist, build the source files directly obj-y := $(filter-out $(archive-src-y) $(archive-custom-valid), $(obj-y)) $(foreach m, $(archive-src-y) $(archive-custom-valid), $($(m:.a=-y))) endif # archive-y # Handle composite objects # --------------------------------------------------------------------------- # if $(foo-objs) exists, foo.o is a composite object multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) # Build list of the parts of our composite objects, our composite # objects depend on those (obviously) multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) multi-objs-subdir := $(patsubst %/,%,$(filter %/, $(multi-objs-y))) multi-objs-archive := $(filter %.a, $(multi-objs-y)) multi-objs-y := $(patsubst %/, %/built-in$(built_in_suffix), $(multi-objs-y)) multi-objs := $(multi-objs-y) define multi_subdir_built_in $(foreach m, $(1), $(if $($(m:.o=$(strip $2))), $(eval $(m:.o=$(strip $2)) := $(patsubst %/, %/built-in$(built_in_suffix), $($(m:.o=$(strip $2))))))) endef ifneq ($(multi-objs-subdir),) $(call multi_subdir_built_in,$(multi-used-y),-objs) $(call multi_subdir_built_in,$(multi-used-y),-y) endif ifneq ($(multi-objs-archive),) ifneq ($(filter $(archive-custom), $(multi-objs-archive)),) $(error Composite objects cannot be built from customized archives) endif mobjs-archive-src-y := mobjs-archive-bin-y := mobjs-archive-y := $(multi-objs-archive) ifeq ($(FORCE_TO_USE_LIB),1) mobjs-archive-bin-y += $(mobjs-archive-y) else # Extract archives that have source files available mobjs-archive-src-y += $(foreach m, $(mobjs-archive-y), $(if $(wildcard $(addprefix $(srctree)/$(src)/,$($(m:.a=-y):.o=.*))), $(m))) # Extract archives that do NOT have source files mobjs-archive-bin-y := $(filter-out $(mobjs-archive-src-y), $(mobjs-archive-y)) endif # If the source files of the archive (including archive-custom-valid) exist, build the source files directly mobjs-obj-y := $(foreach m, $(mobjs-archive-src-y), $($(m:.a=-y))) archive-y += $(mobjs-archive-y) archive-bin-y += $(mobjs-archive-bin-y) archive-src-y += $(mobjs-archive-src-y) obj-y += $(mobjs-obj-y) endif # Handle objects in subdirs # --------------------------------------------------------------------------- # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o or .a # and add the directory to the list of dirs to descend into: $(subdir-y) __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) subdir-y += $(__subdir-y) obj-y := $(patsubst %/, %/built-in$(built_in_suffix), $(obj-y)) # Subdirectories we need to descend into subdir-y := $(sort $(subdir-y) $(multi-objs-subdir)) # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # tell kbuild to descend subdir-obj-y := $(filter %/built-in$(built_in_suffix), $(obj-y) $(multi-objs-y)) # $(obj-dirs) is a list of directories that contain object files obj-dirs := $(dir $(multi-objs) $(obj-y)) # Replace multi-part objects by their individual parts, look at local dir only real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) # Add subdir path extra-y := $(addprefix $(obj)/,$(extra-y)) always := $(addprefix $(obj)/,$(always)) targets := $(addprefix $(obj)/,$(targets)) obj-y := $(addprefix $(obj)/,$(obj-y)) lib-y := $(addprefix $(obj)/,$(lib-y)) subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) real-objs-y := $(addprefix $(obj)/,$(real-objs-y)) multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) subdir-y := $(addprefix $(obj)/,$(subdir-y)) obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) archive-y := $(addprefix $(obj)/,$(archive-y)) archive-src-y := $(addprefix $(obj)/,$(archive-src-y)) archive-bin-y := $(addprefix $(obj)/,$(archive-bin-y)) archive-custom-valid := $(addprefix $(obj)/,$(archive-custom-valid)) orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ $(ccflags-y) $(CFLAGS_$(basetarget).o) _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags) $(C_ONLY_FLAGS)) _c++_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags) $(C++_ONLY_FLAGS)) _a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ $(asflags-y) $(AFLAGS_$(basetarget).o) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) # If building the kernel in a separate objtree expand all occurrences # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). ifeq ($(KBUILD_SRC),) __c_flags = $(_c_flags) __c++_flags = $(_c++_flags) __a_flags = $(_a_flags) __cpp_flags = $(_cpp_flags) else # -I$(obj) locates generated .h files # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files # and locates generated .h files # FIXME: Replace both with specific CFLAGS* statements in the makefiles __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) __c++_flags = $(call addtree,-I$(obj)) $(call flags,_c++_flags) __a_flags = $(call flags,_a_flags) __cpp_flags = $(call flags,_cpp_flags) endif ifeq ($(WIN_PLAT),y) # Not to include system header files in dependency files, # for there are space characters in system path by default. depfile_flags = -MMD -MP -MF $(depfile) else depfile_flags = -MD -MP -MF $(depfile) endif c_flags = $(depfile_flags) $(NOSTDINC_FLAGS) $(__c_flags) c++_flags = $(depfile_flags) $(NOSTDINC_FLAGS) $(__c++_flags) a_flags = $(depfile_flags) $(NOSTDINC_FLAGS) $(__a_flags) a_cpp_flags = $(a_flags) cpp_flags = $(depfile_flags) $(NOSTDINC_FLAGS) $(__cpp_flags) ld_flags = $(LDFLAGS) $(ldflags-y) # Useful for describing the dependency of composite objects # Usage: # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) define multi_depend $(foreach m, $(notdir $1), \ $(eval $(obj)/$m: \ $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s))))))) endef # Commands useful for building a boot image # =========================================================================== # # Use as following: # # target: source(s) FORCE # $(if_changed,ld/objcopy/gzip) # # and add target to extra-y so that we know we have to # read in the saved command line # Linking # --------------------------------------------------------------------------- quiet_cmd_ld = LD $@ cmd_ld = $(LD) $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) \ $(filter-out FORCE,$^) -o $@ # Objcopy # --------------------------------------------------------------------------- quiet_cmd_objcopy = OBJCOPY $@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/lib.mk
Makefile
apache-2.0
8,851
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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. cur_makefile := $(lastword $(MAKEFILE_LIST)) $(cur_makefile): ; get_subdirs = $(foreach m, $(1), $(if $(filter $m/% $m,$(2)),$m,)) get_submodgoals = $(foreach m, \ $(patsubst $(1)/%,%,$(filter $(1)/%,$(2))), \ $(addprefix $(1)/,$(firstword $(subst /,$(space),$m)))) get_multi_objs = $(addprefix $(obj)/, $($(subst $(obj)/,,$(1:.o=-objs))) \ $($(subst $(obj)/,,$(1:.o=-objs))))
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/submods.mk
Makefile
apache-2.0
1,018
# Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. # Licensed 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. cur_makefile := $(lastword $(MAKEFILE_LIST)) $(cur_makefile): ; ifeq ($(WIN_PLAT),y) SUBMODGOALS := $(sort $(foreach m, $(MAKECMDGOALS), \ $(if $(filter-out ./,$(wildcard $(dir $(subst \,/,$m)) $(subst \,/,$m))),$m,))) else SUBMODGOALS := $(sort $(foreach m, $(MAKECMDGOALS), \ $(if $(filter-out ./,$(wildcard $(dir $m) $m)),$m,))) endif ifneq ($(SUBMODGOALS),) MAKECMDGOALS := $(filter-out $(SUBMODGOALS),$(MAKECMDGOALS)) ifeq ($(WIN_PLAT),y) SUBMODGOALS := $(subst \,/,$(SUBMODGOALS)) endif SUBMODS := $(patsubst $(CURDIR)/%,%,$(SUBMODGOALS)) SUBMODS := $(patsubst %/,%,$(SUBMODS)) # Filter out subdirectories if their parent directories already in SUBMODS SUBMODS := $(filter-out $(addsuffix /%,$(SUBMODS)),$(SUBMODS)) export SUBMODS endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/scripts/submods_init.mk
Makefile
apache-2.0
1,383
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 A7_CMD_H #define A7_CMD_H #ifdef __cplusplus extern "C" { #endif #define A7_CMD_MAX_LEN 120 typedef enum { AUD_DUMP_SRC_BEFORE_ALG, AUD_DUMP_SRC_INTER_ALG, AUD_DUMP_SRC_AFTER_ALG, AUD_DUMP_SRC_NUM, }AUD_DUMP_SRC_T; typedef enum { A7_CMD_TYPE_DEBUG_MM, A7_CMD_TYPE_AUDIO_DUMP, A7_CMD_TYPE_UART2_TRACE, A7_CMD_TYPE_STATPRINT, A7_CMD_TYPE_PANIC, A7_CMD_TYPE_HEAP_INIT, A7_CMD_TYPE_HANDSHAKE, A7_CMD_TYPE_DUMP_CFG, A7_CMD_TYPE_AISPEECH, A7_CMD_TYPE_USER, A7_CMD_TYPE_NUM, }A7_CMD_TYPE_T; typedef struct { A7_CMD_TYPE_T type; unsigned int p1; unsigned int p2; }A7_CMD_T; typedef void (* a7_cmd_callback_t)(char *data, int len); void a7_cmd_init(void); void a7_cmd_send(void *data, int len); void mcu_cmd_send(A7_CMD_T *cmd); void a7_cmd_send2(A7_CMD_T *cmd); void a7_cmd_recv_init(void); void set_a7_cmd_callback_handler (a7_cmd_callback_t callback); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/common/a7_cmd.h
C
apache-2.0
1,621
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _AISPEECH_CMD_H_ #define _AISPEECH_CMD_H_ #ifdef __cplusplus extern "C" { #endif typedef enum { CMD_STATE_IDLE, CMD_ASR_START, CMD_VAD_ONESHOT, CMD_VAD_START, CMD_VAD_STOP, CMD_NATIVE_API, CMD_TEXT_TRIGGER, CMD_SYSTEM_RESET, INFO_SPEECH_BEGBIN, INFO_SPEECH_BEGBIN_TIMEOUT, INFO_SPEECH_END, INFO_SPEECH_END_TIMEOUT, INFO_WAKEUP_WAKEUP, INFO_ASR_RESULT, CMD_AUDIO_MUTE, AISPEECH_CMD_MAX, }A7_AISPEECH_CMD_T; #ifdef __cplusplus } #endif #endif /* _AISPEECH_CMD_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/common/aispeech_cmd.h
C
apache-2.0
1,193
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _AUD_DUMP_H_ #define _AUD_DUMP_H_ #include <stdint.h> #include "a7_cmd.h" #ifdef __cplusplus extern "C" { #endif #define AUD_DUMP_IDLE 0 #define AUD_DUMP_INIT 0x12344321 #define AUD_DUMP_READY 0x43211234 #define AUD_DUMP_START 0x12121212 #define AUD_DUMP_MIC12 3 // 011, no ref #define _AUDIO_DUMP_TAG_ "/audiodump/" #define _AUDIO_DUMP_SRC_BEFORE_ALG_ "before-alg" #define _AUDIO_DUMP_SRC_INTER_ALG_ "inter-alg" #define _AUDIO_DUMP_SRC_AFTER_ALG_ "after-alg" typedef void (*aud_dump_cb_t)(unsigned char *data, unsigned int len, void *param); typedef struct { int handle; aud_dump_cb_t func; void *param; } multi_audio_dump_t; void ai_record(unsigned int dump_src, unsigned char *data, unsigned int len); void aud_dump_cb_register(aud_dump_cb_t cbf, void *param); void aud_dump_cb_unregister(aud_dump_cb_t cbf, void *param); int aud_dump_set(AUD_DUMP_SRC_T dump_src, int onoff); int aud_dump_set_channel(AUD_DUMP_SRC_T dump_src, int ch_map); int aud_dump_send(void); void aud_dump_init(void); uint32_t mic_resample_48_to_16(uint8_t *src, uint8_t *dst, uint32_t len); void mic_set_samplerate(int mic_samplerate); int mic_get_samplerate(); int mic_get_handshake_done(); void mic_reset_handshake(); void mic_set_period(int mic_period_ms); int mic_get_period(); #ifdef __cplusplus } #endif #endif /* _AUD_DUMP_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/common/aud_dump.h
C
apache-2.0
1,992
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _AUDIO_DUMP_SINGLE_CHANNEL_H_ #define _AUDIO_DUMP_SINGLE_CHANNEL_H_ #include "mcu_audio.h" #ifdef __cplusplus extern "C" { #endif void audio_dump_a7_cb_register(aud_dump_cb_t cbf, void *param); void audio_dump_a7_cb_unregister(aud_dump_cb_t cbf, void *param); #ifdef __cplusplus } #endif #endif /* _AUDIO_DUMP_SINGLE_CHANNEL_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/common/audio_dump_single_channel.h
C
apache-2.0
994
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _DATA_DUMP_H_ #define _DATA_DUMP_H_ #include <stdint.h> #ifdef __cplusplus extern "C" { #endif typedef void (*data_dump_cb_t)(unsigned char *data, unsigned int len, void *param); typedef void (*data_dump_cb_register_t)(data_dump_cb_t cbf, void *param); typedef void (*data_dump_cb_unregister_t)(data_dump_cb_t cbf, void *param); void *data_dump_open(data_dump_cb_register_t register_cbf, int kfifo_len_KB, int samplerate, int auto_start); void *data_dump_open_withfifo(data_dump_cb_register_t register_cbf, void *val_fifo, int samplerate, int auto_start); int data_dump_set_timeout(void *handle, int timeout); int data_dump_start(void *handle); int data_dump_get_size(void *handle); int data_dump_write(void *handle, void *buf, unsigned int size); int data_dump_read(void *handle, void *buf, unsigned int size); int data_dump_stop(void *handle); void data_dump_close(void *handle, data_dump_cb_unregister_t unregister_cbf); #ifdef __cplusplus } #endif #endif /* _DATA_DUMP_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/common/data_dump.h
C
apache-2.0
1,644
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 _MCU_AUDIO_H_ #define _MCU_AUDIO_H_ #include "aud_dump.h" #ifdef __cplusplus extern "C" { #endif #define NON_EXP_ALIGN(val, exp) (((val) + ((exp) - 1)) / (exp) * (exp)) #define AF_DMA_LIST_CNT 4 #ifndef MIC_SAMPLERATE #define MIC_SAMPLERATE 16000//AUD_SAMPRATE_16000 #endif #ifndef MIC_PERIOD_MS #define MIC_PERIOD_MS 64 #endif #ifndef MIC_BITS #define MIC_BITS 16 #endif #ifndef CHAN_NUM_CAPTURE #define CHAN_NUM_CAPTURE 3//2 #define CHAN_CAPTURE_MIC1 1 #define CHAN_CAPTURE_MIC2 2 #define CHAN_CAPTURE_REF1 0 #define CHAN_CAPTURE_NULL -1 #endif #define CHAN_SEP_BUF_CAPTURE false//true #define STREAM_DEVICE AUD_STREAM_USE_INT_CODEC #define TX_BUFF_ALIGN (4 * AF_DMA_LIST_CNT) #define RX_BURST_NUM 4 #define RX_ALL_CH_DMA_BURST_SIZE (RX_BURST_NUM * 2 * CHAN_NUM_CAPTURE) #define RX_BUFF_ALIGN (RX_ALL_CH_DMA_BURST_SIZE * AF_DMA_LIST_CNT) #define PLAYBACK_FRAME_SIZE ((MIC_SAMPLERATE/1000) * 2 * 1) //16bit, 1ch per ms #define CAPTURE_FRAME_SIZE ((MIC_SAMPLERATE/1000) * 2 * CHAN_NUM_CAPTURE) //16bit, CHAN_NUM_CAPTURE per ms #define PLAYBACK_SIZE NON_EXP_ALIGN(PLAYBACK_FRAME_SIZE * MIC_PERIOD_MS, TX_BUFF_ALIGN) #define _CAPTURE_SIZE NON_EXP_ALIGN(CAPTURE_FRAME_SIZE * MIC_PERIOD_MS, RX_BUFF_ALIGN) #define KFIFO_CAPTURE_SIZE (128*1024) #define _MULTI_RECORD_SUPPORT // external algorithm, so just keep recording /* 1:before m33->a7, 2:a7 received */ #ifdef RTOS #define _MULTI_RECORD_DUMP_POINT 1 #endif #if !defined(DSP_RAM_SHARE_SIZE) && !defined(DSP_SRAM_SOLO) #define A7_ALLOC_TRANSQ_BUF #endif #ifdef __ARM_ARCH_ISA_ARM #define A7_RECORD_DIRECT_CB // mic irq to cb directly #endif extern unsigned char *_a7_dsp_heap_alloc(char *func, int line, int size); #define a7_dsp_heap_alloc(size) _a7_dsp_heap_alloc((char *)__FUNCTION__, __LINE__, size) void aud_record_subscribe(aud_dump_cb_t cbf, void *param); void aud_record_unsubscribe(aud_dump_cb_t cbf, void *param); void mcu_cmd_send(A7_CMD_T *cmd); typedef void (*mcu_audiodump_cb_t)(aud_dump_cb_t cbf, void *param); void mcu_audiodump_register(char *pattern, mcu_audiodump_cb_t register_cb, mcu_audiodump_cb_t unregister_cb, int channels, int buf_KB, int timeout); void mcu_audiodump_unregister(char *pattern); void mcu_audio_task_init(void); void mic_set_samplerate(int mic_samplerate); int mic_get_samplerate(); #define MIC_BITRATE mic_get_samplerate() void mic_set_period(int mic_period_ms); int mic_get_period(); #define CAPTURE_PERIOD_MS mic_get_period() #define CAPTURE_SIZE NON_EXP_ALIGN(((MIC_BITRATE/1000) * 2 * CHAN_NUM_CAPTURE) * CAPTURE_PERIOD_MS, RX_BUFF_ALIGN) #define RECORD_CHAN_SIZE (CAPTURE_SIZE>>1) void audio_dump_a7_cb_register(aud_dump_cb_t cbf, void *param); void audio_dump_a7_cb_unregister(aud_dump_cb_t cbf, void *param); typedef void (*mcu_record_pre_handler)(uint8_t *buf, uint32_t len); void mcu_record_pre_handler_set(mcu_record_pre_handler handler); void enable_a7_kws(int enable); void a7_to_m33_aud_subscribe(aud_dump_cb_t cbf, void *param); void a7_to_m33_aud_unsubscribe(aud_dump_cb_t cbf, void *param); #ifdef __cplusplus } #endif #endif /* _MCU_AUDIO_H_ */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/common/mcu_audio.h
C
apache-2.0
4,064
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __AQE_KWS_H__ #define __AQE_KWS_H__ #include <stdint.h> #ifdef __cplusplus extern "C" { #endif typedef struct { int32_t bypass; } AqeKwsConfig; struct AqeKwsState_; typedef struct AqeKwsState_ AqeKwsState; AqeKwsState *aqe_kws_create(uint32_t sample_rate, uint32_t frame_size, AqeKwsConfig *cfg); int32_t aqe_kws_destroy(AqeKwsState *st); int32_t aqe_kws_process(AqeKwsState *st, int16_t *pcm_in, uint32_t pcm_len, int16_t *thres_buf); float aqe_kws_get_required_mips(AqeKwsState *st); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/a7_dsp/prj/kws/aqe_kws.h
C
apache-2.0
1,195
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __AUDIO_DUMP_H__ #define __AUDIO_DUMP_H__ #ifdef __cplusplus extern "C" { #endif #ifdef AUDIO_DEBUG #define AUDIO_DUMP #endif void audio_dump_init(int frame_len, int sample_bytes, int channel_num); void audio_dump_clear_up(void); void audio_dump_add_channel_data(int channel_id, void *pcm_buf, int pcm_len); void audio_dump_run(void); void data_dump_init(void); void data_dump_run(const char *str, void *data_buf, uint32_t data_len); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/audio_dump/include/audio_dump.h
C
apache-2.0
1,133
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __AUDIO_CFG_H__ #define __AUDIO_CFG_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" enum AUDIO_PROCESS_TYPE_T { AUDIO_PROCESS_TYPE_IIR_EQ = 0, AUDIO_PROCESS_TYPE_DRC, AUDIO_PROCESS_TYPE_LIMITER, AUDIO_PROCESS_TYPE_NUM, }; struct AUDIO_CFG_T_; typedef struct AUDIO_CFG_T_ AUDIO_CFG_T; int sizeof_audio_cfg(void); int store_audio_cfg_into_audio_section(AUDIO_CFG_T *cfg); void *load_audio_cfg_from_audio_section(enum AUDIO_PROCESS_TYPE_T type); #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/audio_process/audio_cfg.h
C
apache-2.0
1,175
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __AUDIO_PROCESS_H__ #define __AUDIO_PROCESS_H__ #ifdef __cplusplus extern "C" { #endif #include "stdint.h" #include "iir_process.h" #include "fir_process.h" typedef enum { AUDIO_EQ_TYPE_SW_IIR = 0, AUDIO_EQ_TYPE_HW_FIR, AUDIO_EQ_TYPE_HW_DAC_IIR, AUDIO_EQ_TYPE_HW_IIR, } AUDIO_EQ_TYPE_T; int audio_process_init(void); int audio_process_open(enum AUD_SAMPRATE_T sample_rate, enum AUD_BITS_T sample_bits,enum AUD_CHANNEL_NUM_T ch_num, int32_t frame_size, void *eq_buf, uint32_t len); int audio_process_run(uint8_t *buf, uint32_t len); int audio_process_close(void); int audio_eq_set_cfg(const FIR_CFG_T *fir_cfg,const IIR_CFG_T *iir_cfg,AUDIO_EQ_TYPE_T audio_eq_type); #ifdef USB_EQ_TUNING void audio_eq_usb_eq_update (void); #endif #ifdef __cplusplus } #endif #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/audio_process/audio_process.h
C
apache-2.0
1,448
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 AUDIO_SPECTRUM_H #define AUDIO_SPECTRUM_H void audio_spectrum_open(int sample_rate, enum AUD_BITS_T sample_bits); void audio_spectrum_close(void); void audio_spectrum_run(const uint8_t *buf, int len); #endif
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/audio_process/audio_spectrum.h
C
apache-2.0
871
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 AUDIO_FLINGER_H #define AUDIO_FLINGER_H #include "plat_types.h" #include "stdbool.h" #include "hal_aud.h" #ifdef __cplusplus extern "C" { #endif typedef uint32_t (*AF_STREAM_HANDLER_T)(uint8_t *buf, uint32_t len); typedef void (*AF_IRQ_NOTIFICATION_T)(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); typedef void (*AF_CODEC_PLAYBACK_POST_HANDLER_T)(uint8_t *buf, uint32_t len, void *cfg); //pingpong machine enum AF_PP_T{ PP_PING = 0, PP_PANG = 1 }; typedef enum { AF_USER_AI, AF_USER_THIRDPART, AF_USER_AUDIO, AF_USER_SBC, AF_USER_SCO, AF_USER_TEST, AF_USER_NUM } AF_USER_E; struct AF_STREAM_CONFIG_T { enum AUD_BITS_T bits; enum AUD_SAMPRATE_T sample_rate; enum AUD_CHANNEL_NUM_T channel_num; enum AUD_CHANNEL_MAP_T channel_map; enum AUD_STREAM_USE_DEVICE_T device; enum AUD_IO_PATH_T io_path; bool chan_sep_buf; bool i2s_master_clk_wait; uint8_t slot_cycles; uint16_t fs_cycles; AF_STREAM_HANDLER_T handler; uint8_t *data_ptr; uint32_t data_size; //should define type uint8_t vol; }; //Should define return status uint32_t af_open(void); void *af_thread_tid_get(void); uint32_t af_stream_open(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, const struct AF_STREAM_CONFIG_T *cfg); uint32_t af_stream_setup(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, const struct AF_STREAM_CONFIG_T *cfg); uint32_t af_stream_mute(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, bool mute); uint32_t af_stream_set_chan_vol(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, enum AUD_CHANNEL_MAP_T ch_map, uint8_t vol); uint32_t af_stream_restore_chan_vol(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_get_cfg(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream, struct AF_STREAM_CONFIG_T **cfg, bool needlock); uint32_t af_stream_start(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_stop(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_pause(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_restart(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_close(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_close(void); uint32_t af_stream_get_cur_dma_addr(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); int af_stream_get_cur_dma_pos(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); int af_stream_buffer_error(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_dma_tc_irq_enable(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); uint32_t af_stream_dma_tc_irq_disable(enum AUD_STREAM_ID_T id, enum AUD_STREAM_T stream); void af_set_irq_notification(AF_IRQ_NOTIFICATION_T notif); void af_lock_thread(void); void af_unlock_thread(void); void af_set_priority(AF_USER_E user, int priority); int af_get_priority(void); int af_get_default_priority(void); void af_reset_priority(void); void af_codec_tune_resample_rate(enum AUD_STREAM_T stream, float ratio); void af_codec_direct_tune_resample_rate(enum AUD_STREAM_T stream, float ratio); void af_codec_tune_both_resample_rate(float ratio); void af_codec_tune_pll(float ratio); void af_codec_tune_xtal(float ratio); void af_codec_tune(enum AUD_STREAM_T stream, float ratio); void af_codec_direct_tune(enum AUD_STREAM_T stream, float ratio); void af_codec_set_perf_test_power(int type); void af_codec_set_noise_reduction(bool enable); void af_codec_swap_output(bool swap); enum AF_CODEC_SYNC_TYPE_T { AF_CODEC_SYNC_TYPE_NONE, AF_CODEC_SYNC_TYPE_GPIO, AF_CODEC_SYNC_TYPE_BT, AF_CODEC_SYNC_TYPE_WIFI, }; void af_codec_sync_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable); void af_codec_sync_resample_rate_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable); void af_codec_sync_gain_config(enum AUD_STREAM_T stream, enum AF_CODEC_SYNC_TYPE_T type, bool enable); typedef void (*AF_ANC_HANDLER)(enum AUD_STREAM_T stream, enum AUD_SAMPRATE_T rate, enum AUD_SAMPRATE_T *new_play, enum AUD_SAMPRATE_T *new_cap); int af_anc_open(enum ANC_TYPE_T type, enum AUD_SAMPRATE_T play_rate, enum AUD_SAMPRATE_T capture_rate, AF_ANC_HANDLER handler); int af_anc_close(enum ANC_TYPE_T type); int af_vad_open(const struct AUD_VAD_CONFIG_T *cfg); int af_vad_close(void); int af_vad_start(void); int af_vad_stop(void); uint32_t af_vad_get_data(uint8_t *buf, uint32_t len); void af_dsd_enable(void); void af_dsd_disable(void); typedef void (*AF_CODEC_BT_TRIGGER_CALLBACK)(void); void af_codec_bt_trigger_config(bool en, AF_CODEC_BT_TRIGGER_CALLBACK callback); #ifdef AUDIO_OUTPUT_SW_GAIN #ifndef AUDIO_OUTPUT_SW_LIMITER typedef struct { float coefs_b[3]; float coefs_a[3]; float history_x[2]; float history_y[2]; }SW_GAIN_IIR_T; void af_codec_get_current_sw_gain_filter(SW_GAIN_IIR_T *filter); void af_code_sw_gain_sample_24bit(int32_t * sample); void af_code_sw_gain_sample_16bit(int16_t * sample); #endif #endif #ifdef __cplusplus } #endif #endif /* AUDIO_FLINGER_H */
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/audioflinger/audioflinger.h
C
apache-2.0
5,711
/* * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved. * Licensed 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 __APP_BLE_CMD_HANDLER_H__ #define __APP_BLE_CMD_HANDLER_H__ #ifdef __cplusplus extern "C" { #endif #include "hal_timer.h" #define GET_CURRENT_TICKS() hal_sys_timer_get() #define GET_CURRENT_MS() TICKS_TO_MS(GET_CURRENT_TICKS()) extern uint32_t __custom_handler_table_start[]; extern uint32_t __custom_handler_table_end[]; #define CUSTOM_COMMAND_TO_ADD(cmdCode, cmdHandler, isNeedResponse, timeoutWaitingRspInMs, cmdRspHandler) \ static const BLE_CUSTOM_CMD_INSTANCE_T cmdCode##_entry __attribute__((used, section(".custom_handler_table"))) = \ {(cmdCode), (cmdHandler), (isNeedResponse), (timeoutWaitingRspInMs), (cmdRspHandler)}; #define CUSTOM_COMMAND_PTR_FROM_ENTRY_INDEX(index) \ ((BLE_CUSTOM_CMD_INSTANCE_T *)((uint32_t)__custom_handler_table_start + (index)*sizeof(BLE_CUSTOM_CMD_INSTANCE_T))) #define INVALID_CUSTOM_ENTRY_INDEX 0xFFFF /** * @brief The BLE custom command handling return status * */ typedef enum { NO_ERROR = 0, INVALID_CMD_CODE, PARAMETER_LENGTH_OUT_OF_RANGE, PARAMETER_LENGTH_TOO_SHORT, HANDLING_FAILED, TIMEOUT_WAITING_RESPONSE, // TO ADD: new return status } BLE_CUSTOM_CMD_RET_STATUS_E; /** * @brief Type of the BLE data transmission path * */ typedef enum { TRANSMISSION_VIA_NOTIFICATION = 0, TRANSMISSION_VIA_INDICATION, TRANSMISSION_VIA_WRITE_CMD, TRANSMISSION_VIA_WRITE_REQ, } BLE_CUSTOM_CMD_TRANSMISSION_PATH_E; /** * @brief Format of the custom command handler function, called when the command is received * * @param cmdCode Custom command code, from BLE_CUSTOM_CMD_CODE_E * @param ptrParam Pointer of the received parameter * @param paramLen Length of the recevied parameter * */ typedef void (*BLE_CustomCmdHandler_t)(uint32_t cmdCode, uint8_t* ptrParam, uint32_t paramLen); /** * @brief Format of the custom command response handler function, * called when the response to formerly sent command is received * * @param retStatus Handling return status of the command * @param ptrParam Pointer of the received parameter * @param paramLen Length of the recevied parameter * */ typedef void (*BLE_CustomCmd_Response_Handler_t)(BLE_CUSTOM_CMD_RET_STATUS_E retStatus, uint8_t* ptrParam, uint32_t paramLen); /** * @brief Format of the raw data xfer received handler function * * @param ptrData Pointer of the received raw data * @param dataLen Length of the received raw data * */ typedef void (*BLE_RawDataReceived_Handler_t)(uint8_t* ptrData, uint32_t dataLen); /** * @brief Custom command definition data structure * */ typedef struct { uint16_t cmdCode; BLE_CustomCmdHandler_t cmdHandler; /**< command handler function */ uint8_t isNeedResponse; /**< true if needs the response from the peer device */ uint16_t timeoutWaitingRspInMs; /**< time-out of waiting for response in milli-seconds */ BLE_CustomCmd_Response_Handler_t cmdRspHandler; /**< command response handler function */ } BLE_CUSTOM_CMD_INSTANCE_T; /**< maximum payload size of one BLE custom command */ #define BLE_CUSTOM_CMD_MAXIMUM_PAYLOAD_SIZE 20 // assure that one BLE packet can include all the data /** * @brief BLE custom command playload * */ typedef struct { uint16_t cmdCode; /**< command code, from BLE_CUSTOM_CMD_CODE_E */ uint16_t paramLen; /**< length of the following parameter */ uint8_t param[BLE_CUSTOM_CMD_MAXIMUM_PAYLOAD_SIZE - 2*sizeof(uint16_t)]; } BLE_CUSTOM_CMD_PAYLOAD_T; /** * @brief Command response parameter structure * */ typedef struct { uint16_t cmdCodeToRsp; /**< tell which command code to response */ uint16_t cmdRetStatus; /**< handling result of the command, from BLE_CUSTOM_CMD_RET_STATUS_E */ uint16_t rspDataLen; /**< length of the response data */ uint8_t rspData[BLE_CUSTOM_CMD_MAXIMUM_PAYLOAD_SIZE - 5*sizeof(uint16_t)]; } BLE_CUSTOM_CMD_RSP_T; void BLE_get_response_handler(uint32_t funcCode, uint8_t* ptrParam, uint32_t paramLen); void BLE_raw_data_xfer_control_handler(uint32_t funcCode, uint8_t* ptrParam, uint32_t paramLen); void BLE_control_raw_data_xfer(bool isStartXfer); void BLE_set_raw_data_xfer_received_callback(BLE_RawDataReceived_Handler_t callback); void BLE_start_raw_data_xfer_control_rsp_handler(BLE_CUSTOM_CMD_RET_STATUS_E retStatus, uint8_t* ptrParam, uint32_t paramLen); void BLE_stop_raw_data_xfer_control_rsp_handler(BLE_CUSTOM_CMD_RET_STATUS_E retStatus, uint8_t* ptrParam, uint32_t paramLen); uint8_t* BLE_custom_command_raw_data_buffer_pointer(void); uint16_t BLE_custom_command_received_raw_data_size(void); BLE_CUSTOM_CMD_RET_STATUS_E BLE_send_response_to_command(uint32_t responsedCmdCode, BLE_CUSTOM_CMD_RET_STATUS_E returnStatus, uint8_t* rspData, uint32_t rspDataLen, BLE_CUSTOM_CMD_TRANSMISSION_PATH_E path); BLE_CUSTOM_CMD_RET_STATUS_E BLE_send_custom_command(uint32_t cmdCode, uint8_t* ptrParam, uint32_t paramLen, BLE_CUSTOM_CMD_TRANSMISSION_PATH_E path); BLE_CUSTOM_CMD_RET_STATUS_E BLE_custom_command_receive_data(uint8_t* ptrData, uint32_t dataLength); void BLE_custom_command_init(void); BLE_CUSTOM_CMD_INSTANCE_T* BLE_custom_command_get_entry_pointer_from_cmd_code(uint16_t cmdCode); uint16_t BLE_custom_command_get_entry_index_from_cmd_code(uint16_t cmdCode); #ifdef __cplusplus } #endif #endif // #ifndef __APP_BLE_CMD_HANDLER_H__
YifuLiu/AliOS-Things
hardware/chip/haas1000/drivers/services/ble_app/app_datapath/app_ble_cmd_handler.h
C
apache-2.0
6,006