diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogin_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogin_api.c index 44ce5b66cd..8a5237958a 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogin_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogin_api.c @@ -41,8 +41,11 @@ void analogin_init (analogin_t *obj, PinName pin) HAL_ADC_INIT_DAT HalADCInitDataTmp; PHAL_ADC_INIT_DAT pHalADCInitDataTmp = &HalADCInitDataTmp; /* To backup user config first */ - + +#if defined(CONFIG_MBED_ENABLED) _memset(&(obj->HalADCInitData), 0, sizeof(HAL_ADC_INIT_DAT)); +#endif + _memcpy(pHalADCInitDataTmp, &(obj->HalADCInitData), sizeof(HAL_ADC_INIT_DAT)); _memset(obj, 0x00, sizeof(analogin_t)); @@ -92,17 +95,13 @@ void analogin_init (analogin_t *obj, PinName pin) pSalADCHND->pUserCB = pSalADCMngtAdpt->pUserCB; /*To assign user callback pointers*/ - pSalADCMngtAdpt->pUserCB->pTXCB = pSalADCUserCBAdpt; - pSalADCMngtAdpt->pUserCB->pTXCCB = (pSalADCUserCBAdpt+1); - pSalADCMngtAdpt->pUserCB->pRXCB = (pSalADCUserCBAdpt+2); - pSalADCMngtAdpt->pUserCB->pRXCCB = (pSalADCUserCBAdpt+3); - pSalADCMngtAdpt->pUserCB->pRDREQCB = (pSalADCUserCBAdpt+4); - pSalADCMngtAdpt->pUserCB->pERRCB = (pSalADCUserCBAdpt+5); - pSalADCMngtAdpt->pUserCB->pDMATXCB = (pSalADCUserCBAdpt+6); - pSalADCMngtAdpt->pUserCB->pDMATXCCB = (pSalADCUserCBAdpt+7); - pSalADCMngtAdpt->pUserCB->pDMARXCB = (pSalADCUserCBAdpt+8); - pSalADCMngtAdpt->pUserCB->pDMARXCCB = (pSalADCUserCBAdpt+9); - + + pSalADCMngtAdpt->pUserCB->pRXCB = pSalADCUserCBAdpt; + pSalADCMngtAdpt->pUserCB->pRXCCB = (pSalADCUserCBAdpt+1); + pSalADCMngtAdpt->pUserCB->pERRCB = (pSalADCUserCBAdpt+2); + pSalADCMngtAdpt->pUserCB->pIDMARXCCB= (pSalADCUserCBAdpt+3); + pSalADCMngtAdpt->pUserCB->pDMARXCB = (pSalADCUserCBAdpt+4); + pSalADCMngtAdpt->pUserCB->pDMARXCCB = (pSalADCUserCBAdpt+5); /* Set ADC Device Number */ pSalADCHND->DevNum = adc_idx; @@ -136,9 +135,13 @@ float analogin_read(analogin_t *obj) uint8_t AnaloginIdx = 0; uint32_t AnalogDat = 0; +#if defined(CONFIG_MBED_ENABLED) //no auto-calibration implemented yet, uses hard coded calibrate uint32_t Offset = 0x2980; uint32_t AnalogDatFull = 0xAA00; +#else + uint32_t AnalogDatFull = 0; +#endif PSAL_ADC_MNGT_ADPT pSalADCMngtAdpt = NULL; PSAL_ADC_HND pSalADCHND = NULL; @@ -152,7 +155,12 @@ float analogin_read(analogin_t *obj) AnalogDat = AnaloginTmp[(AnaloginIdx/2)]; AnalogDat = (AnalogDat & AnaloginDatMsk); AnalogDat = (AnalogDat>>((u32)(16*(AnaloginIdx&0x01)))); + +#if defined(CONFIG_MBED_ENABLED) AnalogDat -= Offset; +#else + AnalogDatFull = 0xCE80; +#endif value = (float)(AnalogDat) / (float)(AnalogDatFull); return (float)value; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogout_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogout_api.c index d69e12db05..2c33b63290 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogout_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/analogout_api.c @@ -26,6 +26,8 @@ #define DAC_POSITIVE_FULL_SCALE 0x7E0 #define DAC_NEGATIVE_FULL_SCALE 0x820 +extern void HalDACPinMuxInit(void *Data); +extern void HalDACPinMuxDeInit(void *Data); /** \brief analogout_init:\n * to initialize DAC diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_peripheral_mbed_arm.ar b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_peripheral_mbed_arm.ar index 7aff54937f..156f86a576 100644 Binary files a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_peripheral_mbed_arm.ar and b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_peripheral_mbed_arm.ar differ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_wlan_mbed_arm.ar b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_wlan_mbed_arm.ar index 980575aa8b..0b2a03c1dd 100644 Binary files a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_wlan_mbed_arm.ar and b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/lib_wlan_mbed_arm.ar differ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_peripheral_mbed_gcc.a b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_peripheral_mbed_gcc.a index 2f6ab3f0c9..44b1a3c34f 100644 Binary files a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_peripheral_mbed_gcc.a and b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_peripheral_mbed_gcc.a differ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_wlan_mbed_gcc.a b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_wlan_mbed_gcc.a index 312525c618..bcd22c4880 100644 Binary files a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_wlan_mbed_gcc.a and b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/lib_wlan_mbed_gcc.a differ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_peripheral_mbed_iar.a b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_peripheral_mbed_iar.a index e906f7fd12..84af9c1399 100644 Binary files a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_peripheral_mbed_iar.a and b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_peripheral_mbed_iar.a differ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_wlan_mbed_iar.a b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_wlan_mbed_iar.a index a19c10c636..216b172d94 100644 Binary files a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_wlan_mbed_iar.a and b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/lib_wlan_mbed_iar.a differ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_autoconf.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_autoconf.h index 6613bbd524..5d3c7a03cb 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_autoconf.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_autoconf.h @@ -18,9 +18,7 @@ /* * Target Platform Selection */ -#define CONFIG_WITHOUT_MONITOR 1 - -#undef CONFIG_RTL8195A +#undef CONFIG_RTL8195A #define CONFIG_RTL8195A 1 #undef CONFIG_FPGA #undef CONFIG_RTL_SIM @@ -54,12 +52,21 @@ #undef CONFIG_IMAGE_AUTO_LOAD //#undef CONFIG_IMAGE_PAGE_LOAD //#define CONFIG_IMAGE_AUTO_LOAD 1 -#define CONFIG_BOOT_TO_UPGRADE_IMG2 1 + +#undef CONFIG_BOOT_TO_UPGRADE_IMG2 + #undef CONFIG_PERI_UPDATE_IMG #define CONFIG_BOOT_FROM_JTAG 1 #undef CONFIG_ALIGNMENT_EXCEPTION_ENABLE #define CONFIG_KERNEL 1 + #define PLATFORM_FREERTOS 1 +#define CONFIG_MBED_ENABLED 1 +#if defined(CONFIG_MBED_ENABLED) +#undef PLATFORM_FREERTOS +#define PLATFORM_CMSIS_RTOS 1 +#endif + #undef PLATFORM_UCOSII #undef PLATFORM_ECOS #undef CONFIG_TASK_SCHEDUL_DIS @@ -73,7 +80,11 @@ #define CONFIG_WDG 1 #undef CONFIG_WDG_NON #define CONFIG_WDG_NORMAL 1 -#define CONFIG_GDMA_EN 0 + +#undef CONFIG_WDG_TEST +#define CONFIG_WDG_MODULE 1 +#define CONFIG_GDMA_EN 1 + #define CONFIG_GDMA_NORMAL 1 #undef CONFIG_GDMA_TEST #define CONFIG_GDMA_MODULE 1 @@ -85,6 +96,7 @@ #define CONFIG_GPIO_NORMAL 1 #undef CONFIG_GPIO_TEST #define CONFIG_GPIO_MODULE 1 + #if defined(CONFIG_INIC) || (CONFIG_SDIOD) #define CONFIG_SDIO_DEVICE_EN 1 #define CONFIG_SDIO_DEVICE_NORMAL 1 @@ -107,6 +119,10 @@ #define DWC_HOST_ONLY 1 #define CONFIG_USB_HOST_ONLY 1 #endif + +#undef CONFIG_SDIO_HOST_EN +#undef CONFIG_USB_EN + #define CONFIG_SPI_COM_EN 1 #define CONFIG_SPI_COM_NORMAL 1 #undef CONFIG_SPI_COM_TEST @@ -121,24 +137,31 @@ #define CONFIG_I2C_MODULE 1 #undef CONFIG_DEBUG_LOG_I2C_HAL #undef CONFIG_PCM_EN -#undef CONFIG_I2S_EN -#undef CONFIG_I2S_NORMAL +#define CONFIG_I2S_EN 1 +#define CONFIG_I2S_NORMAL 1 #undef CONFIG_I2S_TEST -#undef CONFIG_I2S_MODULE +#define CONFIG_I2S_MODULE 1 + #undef CONFIG_DEBUG_LOG_I2S_HAL #undef CONFIG_NFC_EN #undef CONFIG_NFC_NORMAL #undef CONFIG_NFC_TEST #undef CONFIG_NFC_MODULE + +// power saving enable #define CONFIG_SOC_PS_EN 1 #define CONFIG_SOC_PS_NORMAL 1 #undef CONFIG_SOC_PS_TEST -//#define CONFIG_SOC_PS_MODULE 1 +#define CONFIG_SOC_PS_MODULE 1 + #define CONFIG_CRYPTO_EN 1 #define CONFIG_CRYPTO_NORMAL 1 #undef CONFIG_CRYPTO_TEST #define CONFIG_CRYPTO_MODULE 1 -#define CONFIG_MII_EN 1 + +//#define CONFIG_MII_EN 1 +#undef CONFIG_MII_EN + #define CONFIG_PWM_EN 1 #define CONFIG_PWM_NORMAL 1 #undef CONFIG_PWM_TEST @@ -186,19 +209,13 @@ #define CONFIG_UART_LOG_HISTORY 1 #undef CONFIG_CONSOLE_NORMALL_MODE #define CONFIG_CONSOLE_VERIFY_MODE 1 -#undef CONFIG_DEBUG_LOG + +//#undef CONFIG_DEBUG_LOG +#define CONFIG_DEBUG_LOG 1 + #define CONFIG_DEBUG_ERR_MSG 1 #undef CONFIG_DEBUG_WARN_MSG #undef CONFIG_DEBUG_INFO_MSG - -/* - * < SDK Option Config - */ -//#undef CONFIG_MBED_ENABLED -#ifdef CONFIG_MBED_ENABLED -#undef PLATFORM_FREERTOS -#define PLATFORM_CMSIS_RTOS 1 -#endif #undef CONFIG_APP_DEMO /* diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_opts.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_opts.h index c8beb5447f..e67a675caa 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_opts.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/platform_opts.h @@ -37,8 +37,9 @@ limitations under the License. #define SUPPORT_INTERACTIVE_MODE 0//on/off wifi_interactive_mode #define CONFIG_LOG_SERVICE_LOCK 0 -#define CONFIG_LOG_USE_HS_UART 0 //command/log via highspeed uart -#define CONFIG_LOG_USE_I2C 0 //command/log via I2C +#define CONFIG_ATCMD_MP 0 //support MP AT command +#define USE_MODE 1 //for test + #endif /** @@ -65,6 +66,7 @@ limitations under the License. */ #define AP_SETTING_SECTOR 0x000FE000 #define UART_SETTING_SECTOR 0x000FC000 +#define SPI_SETTING_SECTOR 0x000FC000 #define FAST_RECONNECT_DATA (0x80000 - 0x1000) /** @@ -75,6 +77,8 @@ limitations under the License. #define CONFIG_LWIP_LAYER 1 #define CONFIG_INIT_NET 1 //init lwip layer when start up #define CONFIG_WIFI_IND_USE_THREAD 0 // wifi indicate worker thread +#define CONFIG_ENABLE_AP_POLLING_CLIENT_ALIVE 1 // on or off AP POLLING CLIENT + //on/off relative commands in log service #define CONFIG_SSL_CLIENT 0 @@ -95,6 +99,11 @@ limitations under the License. /* For WPS and P2P */ #define CONFIG_ENABLE_WPS 0 #define CONFIG_ENABLE_P2P 0 + +#if CONFIG_ENABLE_WPS +#define CONFIG_ENABLE_WPS_DISCOVERY 1 +#endif + #if CONFIG_ENABLE_P2P #define CONFIG_ENABLE_WPS_AP 1 #undef CONFIG_WIFI_IND_USE_THREAD @@ -104,6 +113,17 @@ limitations under the License. #error "If CONFIG_ENABLE_P2P, need to define CONFIG_ENABLE_WPS_AP 1" #endif +/* For SSL/TLS */ +#define CONFIG_USE_POLARSSL 0 +#define CONFIG_USE_MBEDTLS 1 +#if ((CONFIG_USE_POLARSSL == 0) && (CONFIG_USE_MBEDTLS == 0)) || ((CONFIG_USE_POLARSSL == 1) && (CONFIG_USE_MBEDTLS == 1)) +#undef CONFIG_USE_POLARSSL +#define CONFIG_USE_POLARSSL 1 +#undef CONFIG_USE_MBEDTLS +#define CONFIG_USE_MBEDTLS 0 + +#endif + /* For Simple Link */ #define CONFIG_INCLUDE_SIMPLE_CONFIG 1 @@ -125,6 +145,9 @@ limitations under the License. #endif //end of #if CONFIG_WLAN /*******************************************************************************/ +/* For LWIP configuration */ +#define CONFIG_LWIP_DHCP_COARSE_TIMER 60 + /** * For Ethernet configurations */ @@ -166,6 +189,10 @@ limitations under the License. #endif /******************End of iNIC configurations*******************/ + +/* for CoAP example*/ +#define CONFIG_EXAMPLE_COAP 0 + /* For aj_basic_example */ #define CONFIG_EXAMPLE_AJ_BASIC 0 @@ -214,6 +241,12 @@ limitations under the License. /* For http download example */ #define CONFIG_EXAMPLE_HTTP_DOWNLOAD 0 +/* For httpc example */ +#define CONFIG_EXAMPLE_HTTPC 0 + +/* For httpd example */ +#define CONFIG_EXAMPLE_HTTPD 0 + /* For tcp keepalive example */ #define CONFIG_EXAMPLE_TCP_KEEPALIVE 0 @@ -232,6 +265,96 @@ limitations under the License. #define FATFS_DISK_SD 1 #define CONFIG_EXAMPLE_CODEC_SGTL5000 1 #endif +/* For audio mp3 pcm example */ +#define CONFIG_EXAMPLE_AUDIO_MP3 0 +#if CONFIG_EXAMPLE_AUDIO_MP3 +#define FATFS_DISK_SD 1 +#define CONFIG_EXAMPLE_MP3_STREAM_SGTL5000 1 +#endif + +/* For audio m4a example */ +#define CONFIG_EXAMPLE_AUDIO_M4A 0 +#if CONFIG_EXAMPLE_AUDIO_M4A +#define CONFIG_EXAMPLE_M4A_FROM_HTTP 1 // 1: From HTTP, 0: From SDCARD +#define FATFS_DISK_SD 1 +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +#undef SUPPORT_MP_MODE +#define SUPPORT_MP_MODE 0 +#if (CONFIG_EXAMPLE_M4A_FROM_HTTP == 0) +#undef CONFIG_WLAN +#define CONFIG_WLAN 0 +#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT +#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 +#undef SUPPORT_LOG_SERVICE +#define SUPPORT_LOG_SERVICE 0 +#else +#undef FAST_RECONNECT_DATA +#define FAST_RECONNECT_DATA (0x200000-0x1000) +#endif +#endif + +/* For audio m4a example */ +#define CONFIG_EXAMPLE_AUDIO_M4A_SELFPARSE 0 +#if CONFIG_EXAMPLE_AUDIO_M4A_SELFPARSE +#define FATFS_DISK_SD 1 +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMP LE_CONFIG 0 +#undef SUPPORT_MP_MODE +#define SUPPORT_MP_MODE 0 +#undef CONFIG_WLAN +#define CONFIG_WLAN 0 +#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT +#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 +#undef SUPPORT_LOG_SERVICE +#define SUPPORT_LOG_SERVICE 0 +#endif + +/* For m4a,mp3 combined example */ +#define CONFIG_EXAMPLE_AUDIO_M4A_MP3 0 +#if CONFIG_EXAMPLE_AUDIO_M4A_MP3 +#define FATFS_DISK_SD 1 +#undef CONFIG_WLAN +#define CONFIG_WLAN 0 +#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT +#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +#undef SUPPORT_LOG_SERVICE +#define SUPPORT_LOG_SERVICE 0 +#undef SUPPORT_MP_MODE +#define SUPPORT_MP_MODE 0 +#endif + +/* For audio amr example */ +#define CONFIG_EXAMPLE_AUDIO_AMR 0 +#if CONFIG_EXAMPLE_AUDIO_AMR +#define FATFS_DISK_SD 1 +#undef CONFIG_WLAN +#define CONFIG_WLAN 0 +#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT +#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +#endif + +/* For audio HLS example */ +#define CONFIG_EXAMPLE_AUDIO_HLS 0 +#if CONFIG_EXAMPLE_AUDIO_HLS +#define FATFS_DISK_SD 1 +#undef FAST_RECONNECT_DATA +#define FAST_RECONNECT_DATA (0x200000-0x1000) +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +#undef SUPPORT_MP_MODE +#define SUPPORT_MP_MODE 0 +#endif + +/*Foe alc audio dsp firmware upgrade */ +#define CONFIG_EXAMPLE_ALC_DSP_FW_UPGRADE 0 + +/*Foe audio pcm upload */ +#define CONFIG_EXAMPLE_AUDIO_PCM_UPLOAD 0 /* For UART Module AT command example */ #define CONFIG_EXAMPLE_UART_ATCMD 0 @@ -250,15 +373,50 @@ limitations under the License. #define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 #endif +/* For SPI Module AT command example */ +#define CONFIG_EXAMPLE_SPI_ATCMD 0 + +#if CONFIG_EXAMPLE_SPI_ATCMD +#undef FREERTOS_PMU_TICKLESS_PLL_RESERVED +#define FREERTOS_PMU_TICKLESS_PLL_RESERVED 1 +#undef CONFIG_OTA_UPDATE +#define CONFIG_OTA_UPDATE 1 +#undef CONFIG_TRANSPORT +#define CONFIG_TRANSPORT 1 +#undef LOG_SERVICE_BUFLEN +#define LOG_SERVICE_BUFLEN 1600 +#undef CONFIG_LOG_SERVICE_LOCK +#define CONFIG_LOG_SERVICE_LOCK 1 +#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT +#define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 +#endif #define CONFIG_EXAMPLE_MEDIA_SS 0 -#define CONFIG_EXAMPLE_MEDIA_MS 0 +#define CONFIG_EXAMPLE_MEDIA_MS 0 #define CONFIG_EXAMPLE_MEDIA_AUDIO_FROM_RTP 0 + +//Defines for mp3 streaming over wifi, default output through alc5651 +#define CONFIG_EXAMPLE_MP3_STREAM_RTP 0 + +#if CONFIG_EXAMPLE_MP3_STREAM_RTP +#undef CONFIG_EXAMPLE_MEDIA_AUDIO_FROM_RTP +#define CONFIG_EXAMPLE_MEDIA_AUDIO_FROM_RTP 1 +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +//Set this flag to 1 in case sgtl5000 to be used else alc5651 will be used +#define CONFIG_EXAMPLE_MP3_STREAM_SGTL5000 0 +#endif + // Use media source/sink example -#if (CONFIG_EXAMPLE_MEDIA_SS==1) || (CONFIG_EXAMPLE_MEDIA_MS==1) + +#if (CONFIG_EXAMPLE_MEDIA_SS==1) || (CONFIG_EXAMPLE_MEDIA_AUDIO_FROM_RTP) + #undef CONFIG_INCLUDE_SIMPLE_CONFIG #define CONFIG_INCLUDE_SIMPLE_CONFIG 0 #define CONFIG_ENABLE_WPS 0 -#endif +#endif + +/* For ISP AT COMMAND config*/ +#define CONFIG_ISP 0 /* For Mjpeg capture example*/ #define CONFIG_EXAMPLE_MJPEG_CAPTURE 0 @@ -266,6 +424,17 @@ limitations under the License. #define FATFS_DISK_SD 1 #endif +/* For DCT example*/ +#define CONFIG_EXAMPLE_DCT 0 + +/* For audio flash mp3 pcm example */ +#define CONFIG_EXAMPLE_FLASH_MP3 0 +#if CONFIG_EXAMPLE_FLASH_MP3 +#define FATFS_DISK_FLASH 1 +#define CONFIG_EXAMPLE_MP3_STREAM_SGTL5000 1 + +#endif + /****************** For EAP method example *******************/ #define CONFIG_EXAMPLE_EAP 0 @@ -279,6 +448,9 @@ limitations under the License. #if CONFIG_ENABLE_PEAP || CONFIG_ENABLE_TLS || CONFIG_ENABLE_TTLS #define CONFIG_ENABLE_EAP + +#undef CONFIG_EXAMPLE_WLAN_FAST_CONNECT + #define CONFIG_EXAMPLE_WLAN_FAST_CONNECT 0 #endif @@ -292,6 +464,11 @@ limitations under the License. /* For usb mass storage example */ #define CONFIG_EXAMPLE_USB_MASS_STORAGE 0 +/* For vendor specific example */ +#define CONFIG_EXAMPLE_USB_VENDOR_SPECIFIC 0 + +#define CONFIG_EXAMPLE_USB_ISOC_DEVICE 0 + /* For FATFS example*/ #define CONFIG_EXAMPLE_FATFS 0 #if CONFIG_EXAMPLE_FATFS @@ -300,8 +477,9 @@ limitations under the License. // fatfs version #define FATFS_R_10C // fatfs disk interface -#define FATFS_DISK_USB 0 -#define FATFS_DISK_SD 1 +#define FATFS_DISK_USB 0 +#define FATFS_DISK_SD 1 +#define FATFS_DISK_FLASH 0 #endif #endif @@ -380,7 +558,42 @@ in lwip_opt.h for support uart adapter*/ /* For ssl server example */ #define CONFIG_EXAMPLE_SSL_SERVER 0 +/*For timelapse example */ +#define CONFIG_EXAMPLE_TIMELAPSE 0 +#if CONFIG_EXAMPLE_TIMELAPSE +#define CONFIG_USE_HTTP_SERVER 0 +#if CONFIG_USE_HTTP_SERVER +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +#define CONFIG_ENABLE_WPS 0 +#else +#undef CONFIG_INCLUDE_SIMPLE_CONFIG +#define CONFIG_INCLUDE_SIMPLE_CONFIG 0 +#define CONFIG_ENABLE_WPS 0 +#define CONFIG_FATFS_EN 1 +#define FATFS_R_10C +#define FATFS_DISK_SD 1 +#endif +#endif + /* For ota update http example */ #define CONFIG_EXAMPLE_OTA_HTTP 0 +/* For Amazon AWS IoT example */ +#define CONFIG_EXAMPLE_AMAZON_AWS_IOT 0 +#define CONFIG_EXAMPLE_AMAZON_ALEXA 0 + +/*For wifi roaming example*/ +#define CONFIG_EXAMPLE_WIFI_ROAMING 0 +#if CONFIG_QQ_LINK +#define FATFS_R_10C +#define FATFS_DISK_USB 0 +#define FATFS_DISK_SD 1 +#endif +#if CONFIG_ENABLE_WPS +#define WPS_CONNECT_RETRY_COUNT 4 +#define WPS_CONNECT_RETRY_INTERVAL 5000 // in ms +#endif +#define AUTO_RECONNECT_COUNT 8 +#define AUTO_RECONNECT_INTERVAL 5 // in sec #endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_init.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_init.c index 4e7b39657d..1b1e581826 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_init.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_init.c @@ -14,6 +14,8 @@ * limitations under the License. */ #include "rtl8195a.h" +#include "basic_types.h" +#include "hal_common.h" #if defined(__CC_ARM) || \ (defined (__ARMCC_VERSION) && __ARMCC_VERSION >= 6010050) @@ -67,15 +69,20 @@ extern uint8_t __bss_dram_end__[]; extern VECTOR_Func NewVectorTable[]; extern void SystemCoreClockUpdate(void); +extern VOID En32KCalibration(VOID); extern void PLAT_Start(void); extern void PLAT_Main(void); IMAGE2_START_RAM_FUN_SECTION +__USED + const RAM_START_FUNCTION gImage2EntryFun0 = { PLAT_Start }; IMAGE2_VALID_PATTEN_SECTION +__USED + const uint8_t IMAGE2_SIGNATURE[20] = { 'R', 'T', 'K', 'W', 'i', 'n', 0x0, 0xff, (FW_VERSION&0xff), ((FW_VERSION >> 8)&0xff), @@ -166,11 +173,119 @@ void TRAP_HardFaultHandler_Patch(void) #endif extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n); +_WEAK void SDIO_Device_Off(void) +{ + /* Disable Clock for SDIO function */ + ACTCK_SDIOD_CCTRL(OFF); + + /* SDIO Function Disable */ + SDIOD_ON_FCTRL(OFF); + SDIOD_OFF_FCTRL(OFF); + // SDIO Pin Mux off + SDIOD_PIN_FCTRL(OFF); +} + +void SYSPlatformInit(void) +{ +#ifdef CONFIG_CHIP_A_CUT + //Set SPS lower voltage + HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_EFUSE_SYSCFG0, (HAL_READ32(SYSTEM_CTRL_BASE, REG_SYS_EFUSE_SYSCFG0)&0xf0ffffff)); +#else // B-Cut & C-Cut + //Set SPS lower voltage + HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_EFUSE_SYSCFG0, ((HAL_READ32(SYSTEM_CTRL_BASE, REG_SYS_EFUSE_SYSCFG0)&0xf0ffffff)|0x6000000)); +#endif + + //xtal buffer driving current + HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_XTAL_CTRL1, + ((HAL_READ32(SYSTEM_CTRL_BASE, REG_SYS_XTAL_CTRL1)&(~(BIT_MASK_SYS_XTAL_DRV_RF1< 10000) { /*Delay 100ms*/ + //DiagPrintf("32K linear Calibration Fail!!\n"); + flag = 0; + break; + } + } + } + } +} // Image2 Entry Function void PLAT_Init(void) { - uint32_t val; - // Overwrite vector table NewVectorTable[2] = (VECTOR_Func) TRAP_NMIHandler; #if defined ( __ICCARM__ ) @@ -185,25 +300,18 @@ void PLAT_Init(void) __rtl_memset_v1_00((void *)__bss_dtcm_start__, 0, __bss_dtcm_end__ - __bss_dtcm_start__); __rtl_memset_v1_00((void *)__bss_dram_start__, 0, __bss_dram_end__ - __bss_dram_start__); - extern HAL_TIMER_OP_EXT HalTimerOpExt; - __rtl_memset_v1_00((void *)&HalTimerOpExt, 0, sizeof(HalTimerOpExt)); - __rtl_memset_v1_00((void *)&HalTimerOp, 0, sizeof(HalTimerOp)); + HAL_WRITE32(SYSTEM_CTRL_BASE, REG_OSC32K_CTRL, (HAL_READ32(SYSTEM_CTRL_BASE, REG_OSC32K_CTRL)|BIT17|BIT18)); + HalDelayUs(40); +#ifdef CONFIG_TIMER_MODULE + // Re-init G-Timer HAL Function pointer with ROM Patch + if (HalCommonInit() != HAL_OK) { + DBG_8195A("Hal Common Init Failed.\n"); + } +#endif - HalTimerOpInit_Patch(&HalTimerOp); SystemCoreClockUpdate(); - // Set SPS lower voltage - val = __RTK_CTRL_READ32(REG_SYS_EFUSE_SYSCFG0); - val &= 0xf0ffffff; - val |= 0x6000000; - __RTK_CTRL_WRITE32(REG_SYS_EFUSE_SYSCFG0, val); - - // xtal buffer driving current - val = __RTK_CTRL_READ32(REG_SYS_XTAL_CTRL1); - val &= ~(BIT_MASK_SYS_XTAL_DRV_RF1 << BIT_SHIFT_SYS_XTAL_DRV_RF1); - val |= BIT_SYS_XTAL_DRV_RF1(1); - __RTK_CTRL_WRITE32(REG_SYS_XTAL_CTRL1, val); - + SYSPlatformInit(); // Initialize SPIC, then disable it for power saving. if ((HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) & BIT_SOC_FLASH_EN) != 0) { SpicNVMCalLoadAll(); @@ -212,11 +320,19 @@ void PLAT_Init(void) } #ifdef CONFIG_TIMER_MODULE + + OSC_32_LINEAR_CALIBRATION(10); + HalDelayUs(40); + Calibration32k(); #endif +#ifdef CONFIG_SOC_PS_MODULE + InitSoCPM(); +#endif + #ifndef CONFIG_SDIO_DEVICE_EN - SDIO_DEV_Disable(); + SDIO_Device_Off(); #endif // Enter App start function diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_trap.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_trap.h index e3a8327459..c59b4534d9 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_trap.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_trap.h @@ -18,10 +18,6 @@ typedef void (*VECTOR_Func)(void *data); -typedef struct { - void (*RamStartFun)(void); -} RAM_START_FUNCTION; - typedef struct { void (*RamStartFun)(void); void (*RamWakeupFun)(void); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_api.c index 7a7a96b62c..832b1595a6 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_api.c @@ -20,6 +20,8 @@ #include "gpio_api.h" +extern void HAL_GPIO_DeInit(HAL_GPIO_PIN *GPIO_Pin); + // convert Mbed pin mode to HAL Pin Mode const u8 GPIO_InPinMode[] = { DIN_PULL_NONE, // PullNone @@ -193,7 +195,6 @@ void gpio_pull_ctrl(gpio_t *obj, PinMode pull_type) HAL_GPIO_PullCtrl((u32) obj->pin, (u32)pull_type); } - void gpio_deinit(gpio_t *obj) { HAL_GPIO_DeInit(&obj->hal_pin); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_irq_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_irq_api.c index 8b97503b23..c00b9ba369 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_irq_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/gpio_irq_api.c @@ -19,6 +19,8 @@ #if CONFIG_GPIO_EN #include "gpio_irq_api.h" +extern void HAL_GPIO_DeInit(HAL_GPIO_PIN *GPIO_Pin); + int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) { uint32_t pin_name; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/i2c_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/i2c_api.c index 1783034d67..6f5fe376a5 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/i2c_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/i2c_api.c @@ -15,7 +15,6 @@ */ #include - #include "objects.h" #include "PinNames.h" #include "hal_i2c.h" @@ -79,7 +78,7 @@ static SAL_I2C_TRANSFER_BUF i2crxtranbuf[4]; extern u32 ConfigDebugErr; extern u32 ConfigDebuginfo; void i2c_init(i2c_t *obj, PinName sda, PinName scl) -{ +{ int i2c_sel; int i2c_idx; PSAL_I2C_MNGT_ADPT pSalI2CMngtAdpt = NULL; @@ -230,9 +229,9 @@ void i2c_frequency(i2c_t *obj, int hz) inline int i2c_start(i2c_t *obj) { - memset(address_save_int , 0, sizeof(address_save_int)); - memset(Byte_count , 0, sizeof(Byte_count)); - memset(address_save, 0, sizeof(address_save)); + _memset(address_save_int , 0, sizeof(address_save_int)); + _memset(Byte_count , 0, sizeof(Byte_count)); + _memset(address_save, 0, sizeof(address_save)); return 0; } @@ -279,7 +278,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) } else { /* Calculate user time out parameters */ I2CInTOTcnt = 300; - if ((I2CInTOTcnt != 0) && (I2CInTOTcnt != I2C_TIMEOOUT_ENDLESS)) { + if ((I2CInTOTcnt != 0) && (I2CInTOTcnt != I2C_TIMEOUT_ENDLESS)) { InTimeoutCount = (I2CInTOTcnt*1000/TIMER_TICK_US); InStartCount = HalTimerOp.HalTimerReadCount(1); } @@ -345,7 +344,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) } else { /* Calculate user time out parameters */ I2CInTOTcnt = 300; - if ((I2CInTOTcnt != 0) && (I2CInTOTcnt != I2C_TIMEOOUT_ENDLESS)) { + if ((I2CInTOTcnt != 0) && (I2CInTOTcnt != I2C_TIMEOUT_ENDLESS)) { InTimeoutCount = (I2CInTOTcnt*1000/TIMER_TICK_US); InStartCount = HalTimerOp.HalTimerReadCount(1); } @@ -458,7 +457,7 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) pSalI2CMngtAdpt = &(obj->SalI2CMngtAdpt); pSalI2CHND = &(pSalI2CMngtAdpt->pSalHndPriv->SalI2CHndPriv); address = (address & 0xFE ) >>1; - + uint16_t i2c_user_addr = (uint16_t) address; if (i2c_target_addr[pSalI2CHND->DevNum] != i2c_user_addr) { @@ -528,7 +527,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) } else { /* Calculate user time out parameters */ I2CInTOTcnt = 300; - if ((I2CInTOTcnt != 0) && (I2CInTOTcnt != I2C_TIMEOOUT_ENDLESS)) { + if ((I2CInTOTcnt != 0) && (I2CInTOTcnt != I2C_TIMEOUT_ENDLESS)) { InTimeoutCount = (I2CInTOTcnt*1000/TIMER_TICK_US); InStartCount = HalTimerOp.HalTimerReadCount(1); } diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/log_uart_api.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/log_uart_api.h index c88af28772..1c252ec6c1 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/log_uart_api.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/log_uart_api.h @@ -1,10 +1,10 @@ /* mbed Microcontroller Library * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * + * * 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 @@ -12,11 +12,12 @@ * 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 LOG_UART_API_H #define LOG_UART_API_H +#if defined(CONFIG_PLATFORM_8195A) && (CONFIG_PLATFORM_8195A == 1) #include "device.h" #include "serial_api.h" #include "hal_log_uart.h" @@ -25,43 +26,305 @@ extern "C" { #endif -typedef void (*loguart_irq_handler)(uint32_t id, LOG_UART_INT_ID event); +/** @addtogroup log_uart LOG_UART + * @ingroup hal + * @brief log_uart functions + * @{ + */ +///@name Ameba1 Only +///@{ + +/****************************************************** + * Type Definitions + ******************************************************/ +/** Log uart irq handler function pointer type + * + * @param id : The argument for log uart interrupt handler + * @param event : The log uart interrupt indication ID. More details is shown in hal_log_uart.h + */ +typedef void (*loguart_irq_handler)(uint32_t id, LOG_UART_INT_ID event); typedef struct log_uart_s log_uart_t; -int32_t log_uart_init (log_uart_t *obj, int baudrate, int data_bits, SerialParity parity, int stop_bits); +/****************************************************** + * Function Declarations + ******************************************************/ +/** + * @brief Initialize Realtek log uart. + * Initialize the required parts of the log uart. + * i.e. baudrate, data bits, parity, etc. + * @param[in] obj: The address of log uart object. + * @param[in] baudrate: Baud rate of the log uart object. + * @param[in] data_bits: Data bits of the log uart object. + * @param[in] parity: Parity type of the log uart object + - ParityNone, - Do not use parity + - ParityOdd, - Use odd parity + - ParityEven, - Use even parity + - ParityForced1, - Use even parity, the same as ParityEven + - ParityForced0 - Use odd parity, the same as ParityOdd + * @param[in] stop_bits: The number of stop bits for the log uart object. + * @return 0 if initialization is successful, -1 otherwise + */ +int32_t log_uart_init(log_uart_t *obj, int baudrate, int data_bits, SerialParity parity, int stop_bits); + +/** + * @brief Release the resources related to Realtek log uart. + + * @param[in] obj: The address of log uart object. + * @return None + */ void log_uart_free(log_uart_t *obj); + +/** + * @brief Set the baud rate of log uart. + + * @param[in] obj: The address of log uart object. + * @param[in] baudrate: Baud rate of the log uart object. + * @return None + */ void log_uart_baud(log_uart_t *obj, int baudrate); + +/** + * @brief Set parameters for log uart. + * including data bits, parity type and stop bits + + * @param[in] obj: The address of log uart object. + * @param[in] data_bits: Data bits of log uart object. + * @param[in] parity: Parity type of the log uart object + - ParityNone, - Do not use parity + - ParityOdd, - Use odd parity + - ParityEven, - Use even parity + - ParityForced1, - Use even parity, the same as ParityEven + - ParityForced0 - Use odd parity, the same as ParityOdd + * @param[in] stop_bits: The number of stop bits for the log uart object. + * @return None + */ void log_uart_format(log_uart_t *obj, int data_bits, SerialParity parity, int stop_bits); + +/** + * @brief Set irq handler for log uart. + * @param[in] obj: The address of log uart object. + * @param[in] handler: The interrupt handler for log uart. + * @param[in] id: The argument for log uart interrupt handler. + * @return None + */ void log_uart_irq_handler(log_uart_t *obj, loguart_irq_handler handler, uint32_t id); + +/** + * @brief Enable/disable the specific irq indication ID. + * @param[in] obj: The address of log uart object. + * @param[in] irq: The log uart interrupt indication ID which will be enabled/disabled. + * @param[in] enable: 1 enable, 0 disable + * @return None + */ void log_uart_irq_set(log_uart_t *obj, LOG_UART_INT_ID irq, uint32_t enable); + +/** + * @brief Read one character from log uart. + This function will block untill the log uart gets something to read + * @param[in] obj: The address of log uart object. + * @return the character read from log uart + */ char log_uart_getc(log_uart_t *obj); + +/** + * @brief Write one character to log uart. + This function will block untill the data is successfully written to log uart + * @param[in] obj: The address of log uart object. + * @param[in] c: The one byte data to be written to log uart. + * @return None + */ void log_uart_putc(log_uart_t *obj, char c); + +/** + * @brief Check whether log uart is ready to read data + * @param[in] obj: The address of log uart object. + * @return 1 if there is data at log uart to be read, 0 otherwise + */ int log_uart_readable(log_uart_t *obj); + +/** + * @brief Check whether log uart is ready to write data + * @param[in] obj: The address of log uart object. + * @return 1 if log uart is ready for writing, 0 otherwise + */ int log_uart_writable(log_uart_t *obj); + +/** + * @brief Clear both data at log uart + This function will clear data in both TX FIFO and RX FIFO of log uart + * @param[in] obj: The address of log uart object. + * @return None + */ void log_uart_clear(log_uart_t *obj); + +/** + * @brief Clear TX FIFO of log uart + * @param[in] obj: The address of log uart object. + * @return None + */ void log_uart_clear_tx(log_uart_t *obj); + +/** + * @brief Clear RX FIFO of log uart + * @param[in] obj: The address of log uart object. + * @return None + */ void log_uart_clear_rx(log_uart_t *obj); + +/** + * @brief Set break control for log uart + * @param[in] obj: The address of log uart object. + * @return None + */ void log_uart_break_set(log_uart_t *obj); + +/** + * @brief Clear break control for log uart + * @param[in] obj: The address of log uart object. + * @return None + */ void log_uart_break_clear(log_uart_t *obj); + +/** + * @brief Set the handler for complete TX + * @param[in] obj: The address of log uart object. + * @param[in] handler: The function which is called when log uart has finished transmitting data. + * @param[in] id: The parameter for handler. + * @return None + */ void log_uart_tx_comp_handler(log_uart_t *obj, void *handler, uint32_t id); + +/** + * @brief Set the handler for complete RX + * @param[in] obj: The address of log uart object. + * @param[in] handler: The function which is called when log uart has finished receving data + * @param[in] id: The parameter for handler. + * @return None + */ void log_uart_rx_comp_handler(log_uart_t *obj, void *handler, uint32_t id); + +/** + * @brief Set the handler for line status + * @param[in] obj: The address of log uart object. + * @param[in] handler: The function which is called when log uart gets an line status indication ID. + * @param[in] id: The parameter for handler. + * @return None + */ void log_uart_line_status_handler(log_uart_t *obj, void *handler, uint32_t id); -int32_t log_uart_recv (log_uart_t *obj, char *prxbuf, uint32_t len, uint32_t timeout_ms); -int32_t log_uart_send (log_uart_t *obj, char *ptxbuf, uint32_t len, uint32_t timeout_ms); -int32_t log_uart_recv_stream (log_uart_t *obj, char *prxbuf, uint32_t len); -int32_t log_uart_send_stream (log_uart_t *obj, char *ptxbuf, uint32_t len); -int32_t log_uart_recv_stream_timeout (log_uart_t *obj, char *prxbuf, uint32_t len, + +/** + * @brief Read data from log uart in blocking mode. + * @param[in] obj: The address of log uart object. + * @param[out] prxbuf: The buffer to store received data. + * @param[in] len: The maximum length of data to be read + * @param[in] timeout_ms: Blocking time in ms. + * @return the length of received data in bytes + */ +int32_t log_uart_recv(log_uart_t *obj, char *prxbuf, uint32_t len, uint32_t timeout_ms); + +/** + * @brief Send data to log uart in blocking mode + * @param[in] obj: The address of log uart object. + * @param[in] ptxbuf: Data buffer to be sent to log uart + * @param[in] len: Length of data to be sent to log uart + * @param[in] timeout_ms: Blocking time in ms. + * @return the length of sent data in bytes + */ +int32_t log_uart_send(log_uart_t *obj, char *ptxbuf, uint32_t len, uint32_t timeout_ms); + +/** + * @brief Read data from log uart in interrupt mode(Non-blocking) + * @param[in] obj: The address of log uart object. + * @param[out] prxbuf: The buffer to store received data. + * @param[in] len: The maximum length of data to be read + * @return 0 if success + */ +int32_t log_uart_recv_stream(log_uart_t *obj, char *prxbuf, uint32_t len); + +/** + * @brief Send data to log uart in interrupt mode(Non-blocking) + * @param[in] obj: The address of log uart object. + * @param[in] ptxbuf: Data buffer to be sent to log uart + * @param[in] len: Length of data to be sent to log uart + * @return 0 if success + */ +int32_t log_uart_send_stream(log_uart_t *obj, char *ptxbuf, uint32_t len); + +/** + * @brief Read data from log uart with a given timeout in interrupt mode(Non-blocking) + * @param[in] obj: The address of log uart object. + * @param[out] prxbuf: The buffer to store received data. + * @param[in] len: The maximum length of data to be read + * @param[in] timeout_ms: The timeout for reading data in ms + * @param[in] force_cs: User callback function + * @return the length in Byte of received data before timeout, or error (< 0) + */ +int32_t log_uart_recv_stream_timeout(log_uart_t *obj, char *prxbuf, uint32_t len, uint32_t timeout_ms, void *force_cs); -int32_t log_uart_send_stream_abort (log_uart_t *obj); -int32_t log_uart_recv_stream_abort (log_uart_t *obj); -void log_uart_disable (log_uart_t *obj); -void log_uart_enable (log_uart_t *obj); + +/** + * @brief Abort interrupt mode of sending data + * @param[in] obj: The address of log uart object. + * @return the length of data sent to log uart. + */ +int32_t log_uart_send_stream_abort(log_uart_t *obj); + +/** + * @brief Abort interrupt mode of receiving data + * @param[in] obj: The address of log uart object. + * @return the length of data received from log uart. + */ +int32_t log_uart_recv_stream_abort(log_uart_t *obj); + +/** + * @brief Disable log uart + * @param[in] obj: The address of log uart object. + * @return None. + */ +void log_uart_disable(log_uart_t *obj); + +/** + * @brief Enable log uart + * @param[in] obj: The address of log uart object. + * @return None. + */ +void log_uart_enable(log_uart_t *obj); + +/** + * @brief Read Line-Status register + * @return value: + * - Bit 0: RX Data Ready + * - Bit 1: Overrun Error + * - Bit 2: Parity Error + * - Bit 3: Framing Error + * - Bit 4: Break Interrupt (received data input is held in 0 state for a longer than a full word tx time) + * - Bit 5: TX FIFO empty (THR empty) + * - Bit 6: TX FIFO empty (THR & TSR both empty) + * - Bit 7: Receiver FIFO Error (parity error, framing error or break indication) + */ uint8_t log_uart_raed_lsr(log_uart_t *obj); + +/** + * @brief Read Modem-Status register + * @return value: + * - Bit 0: DCTS, The CTS line has changed its state + * - Bit 1: DDSR, The DSR line has changed its state + * - Bit 2: TERI, RI line has changed its state from low to high state + * - Bit 3: DDCD, DCD line has changed its state + * - Bit 4: Complement of the CTS input + * - Bit 5: Complement of the DSR input + * - Bit 6: Complement of the RI input + * - Bit 7: Complement of the DCD input + */ uint8_t log_uart_raed_msr(log_uart_t *obj); +///@} +/*\@}*/ + #ifdef __cplusplus } #endif +#endif //CONFIG_PLATFORM_8195A #endif // end of "#ifndef LOG_UART_API_H" diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/port_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/port_api.c index a181d88c08..0cd3b703fc 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/port_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/port_api.c @@ -142,7 +142,7 @@ void port_mode(port_t *obj, PinMode mode) break; } if (obj->mask & (1 << i)) { // If the pin is used - pin_mode(obj->pin_def[i], mode); + pin_mode((PinName)obj->pin_def[i], mode); } } } diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c index 46f2dde5fc..b91e9f6771 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/serial_api.c @@ -73,13 +73,17 @@ static HAL_GDMA_OP UartGdmaOp; #ifdef CONFIG_MBED_ENABLED #include "log_uart_api.h" + #include "hal_log_uart.h" + int stdio_uart_inited = 0; serial_t stdio_uart; log_uart_t stdio_uart_log; + static uint32_t serial_log_irq_ids; static uart_irq_handler log_irq_handler; static uint32_t serial_log_irq_en; + #endif static void SerialTxDoneCallBack(VOID *pAdapter); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_api.c index b1e9109800..032d6117bb 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_api.c @@ -16,7 +16,7 @@ #include "objects.h" #include "spi_api.h" - +#include "spi_ex_api.h" #include "PinNames.h" #include "pinmap.h" #include "hal_ssi.h" @@ -32,6 +32,11 @@ void spi_tx_done_callback(VOID *obj); void spi_rx_done_callback(VOID *obj); void spi_bus_tx_done_callback(VOID *obj); +#ifdef CONFIG_GDMA_EN +HAL_GDMA_OP SpiGdmaOp; +#endif + +uint8_t SPI0_IS_AS_SLAVE = 0; //TODO: Load default Setting: It should be loaded from external setting file. extern const DW_SSI_DEFAULT_SETTING SpiDefaultSetting; @@ -73,10 +78,12 @@ void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName sse _memset((void*)obj, 0, sizeof(spi_t)); obj->state = 0; - /* SsiClockDivider doesn't support odd number */ + uint32_t SystemClock = SystemGetCpuClk(); + uint32_t MaxSsiFreq = (SystemClock >> 2) >> 1; - DBG_SSI_INFO("SystemClock: %d\n", SystemGetCpuClk()); - DBG_SSI_INFO("MaxSsiFreq : %d\n", SystemGetCpuClk() >> 3); + /* SsiClockDivider doesn't support odd number */ + DBG_SSI_INFO("SystemClock: %d\n", SystemClock); + DBG_SSI_INFO("MaxSsiFreq : %d\n", MaxSsiFreq); ssi_mosi = pinmap_peripheral(mosi, PinMap_SSI_MOSI); ssi_miso = pinmap_peripheral(miso, PinMap_SSI_MISO); @@ -119,7 +126,23 @@ void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName sse DBG_SSI_ERR(ANSI_COLOR_RED"spi_init(): SPI %x init fails.\n"ANSI_COLOR_RESET,pHalSsiAdaptor->Index); return; } - osDelay(1); + + pHalSsiAdaptor->TxCompCallback = spi_tx_done_callback; + pHalSsiAdaptor->TxCompCbPara = (void*)obj; + pHalSsiAdaptor->RxCompCallback = spi_rx_done_callback; + pHalSsiAdaptor->RxCompCbPara = (void*)obj; + pHalSsiAdaptor->TxIdleCallback = spi_bus_tx_done_callback; + pHalSsiAdaptor->TxIdleCbPara = (void*)obj; + +#ifdef CONFIG_GDMA_EN + HalGdmaOpInit((VOID*)&SpiGdmaOp); + pHalSsiAdaptor->DmaConfig.pHalGdmaOp = &SpiGdmaOp; + pHalSsiAdaptor->DmaConfig.pRxHalGdmaAdapter = &obj->spi_gdma_adp_rx; + pHalSsiAdaptor->DmaConfig.pTxHalGdmaAdapter = &obj->spi_gdma_adp_tx; + obj->dma_en = 0; + pHalSsiAdaptor->HaveTxChannel = 0; + pHalSsiAdaptor->HaveRxChannel = 0; +#endif } void spi_free (spi_t *obj) @@ -129,6 +152,17 @@ void spi_free (spi_t *obj) HalSsiDeInit(pHalSsiAdaptor); SPI0_MULTI_CS_CTRL(OFF); + +#ifdef CONFIG_GDMA_EN + if (obj->dma_en & SPI_DMA_RX_EN) { + HalSsiRxGdmaDeInit(pHalSsiAdaptor); + } + + if (obj->dma_en & SPI_DMA_TX_EN) { + HalSsiTxGdmaDeInit(pHalSsiAdaptor); + } + obj->dma_en = 0; +#endif } void spi_format (spi_t *obj, int bits, int mode, int slave) @@ -183,6 +217,7 @@ void spi_format (spi_t *obj, int bits, int mode, int slave) if (pHalSsiAdaptor->Index == 0) { pHalSsiAdaptor->Role = SSI_SLAVE; pHalSsiAdaptor->SlaveOutputEnable = SLV_TXD_ENABLE; // <-- Slave only + SPI0_IS_AS_SLAVE = 1; DBG_SSI_INFO("SPI0 is as slave\n"); } else { DBG_SSI_ERR("The SPI%d cannot work as Slave mode, only SPI0 does.\r\n", pHalSsiAdaptor->Index); @@ -247,10 +282,12 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill) { int total = (tx_length > rx_length) ? tx_length : rx_length; + int i; + char out, in; - for (int i = 0; i < total; i++) { - char out = (i < tx_length) ? tx_buffer[i] : write_fill; - char in = spi_master_write(obj, out); + for (i = 0; i < total; i++) { + out = (i < tx_length) ? tx_buffer[i] : write_fill; + in = spi_master_write(obj, out); if (i < rx_length) { rx_buffer[i] = in; } @@ -296,3 +333,40 @@ int spi_busy (spi_t *obj) } +// Bus Idle: Real TX done, TX FIFO empty and bus shift all data out already +void spi_bus_tx_done_callback(VOID *obj) +{ + spi_t *spi_obj = (spi_t *)obj; + spi_irq_handler handler; + + if (spi_obj->bus_tx_done_handler) { + handler = (spi_irq_handler)spi_obj->bus_tx_done_handler; + handler(spi_obj->bus_tx_done_irq_id, (SpiIrq)0); + } +} + +void spi_tx_done_callback(VOID *obj) +{ + spi_t *spi_obj = (spi_t *)obj; + spi_irq_handler handler; + + if (spi_obj->state & SPI_STATE_TX_BUSY) { + spi_obj->state &= ~SPI_STATE_TX_BUSY; + if (spi_obj->irq_handler) { + handler = (spi_irq_handler)spi_obj->irq_handler; + handler(spi_obj->irq_id, SpiTxIrq); + } + } +} + +void spi_rx_done_callback(VOID *obj) +{ + spi_t *spi_obj = (spi_t *)obj; + spi_irq_handler handler; + + spi_obj->state &= ~SPI_STATE_RX_BUSY; + if (spi_obj->irq_handler) { + handler = (spi_irq_handler)spi_obj->irq_handler; + handler(spi_obj->irq_id, SpiRxIrq); + } +} diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_ex_api.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_ex_api.h new file mode 100644 index 0000000000..e80a4981ec --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/spi_ex_api.h @@ -0,0 +1,244 @@ +/* mbed Microcontroller Library + * Copyright (c) 2013-2016 Realtek Semiconductor Corp. + * + * 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 MBED_SPI_EXT_API_H +#define MBED_SPI_EXT_API_H + +#include "device.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup spi_ex SPI_EX + * @ingroup hal + * @brief spi extended functions + * @{ + */ + +///@name Ameba Common +///@{ + +#define SPI_DMA_RX_EN (1<<0) +#define SPI_DMA_TX_EN (1<<1) + +enum { + SPI_SCLK_IDLE_LOW=0, // the SCLK is Low when SPI is inactive + SPI_SCLK_IDLE_HIGH=2 // the SCLK is High when SPI is inactive +}; + +// SPI Master mode: for continuous transfer, how the CS toggle: +enum { + SPI_CS_TOGGLE_EVERY_FRAME=0, // let SCPH=0 then the CS toggle every frame + SPI_CS_TOGGLE_START_STOP=1 // let SCPH=1 the CS toggle at start and stop +}; + +enum { + SPI_SCLK_TOGGLE_MIDDLE=0, // Serial Clk toggle at middle of 1st data bit and latch data at 1st Clk edge + SPI_SCLK_TOGGLE_START=1 // Serial Clk toggle at start of 1st data bit and latch data at 2nd Clk edge +}; + +typedef enum { + CS_0 = 0, + CS_1 = 1, + CS_2 = 2, + CS_3 = 3, + CS_4 = 4, + CS_5 = 5, + CS_6 = 6, + CS_7 = 7 +}ChipSelect; + + +#define SPI_STATE_READY 0x00 +#define SPI_STATE_RX_BUSY (1<<1) +#define SPI_STATE_TX_BUSY (1<<2) + +typedef enum { + SpiRxIrq, + SpiTxIrq +} SpiIrq; + +typedef void (*spi_irq_handler)(uint32_t id, SpiIrq event); + +/** + * @brief Set SPI interrupt handler if needed. + * @param obj: spi object define in application software. + * @param handler: interrupt callback function + * @param id: interrupt callback parameter + * @retval none + */ +void spi_irq_hook(spi_t *obj, spi_irq_handler handler, uint32_t id); + +/** + * @brief Set SPI interrupt bus tx done handler if needed. + * @param obj: spi object define in application software. + * @param handler: interrupt bus tx done callback function + * @param id: interrupt callback parameter + * @retval none + */ +void spi_bus_tx_done_irq_hook(spi_t *obj, spi_irq_handler handler, uint32_t id); + +/** + * @brief Slave device to flush tx fifo. + * @param obj: spi slave object define in application software. + * @note : It will discard all data in both tx fifo and rx fifo + */ +void spi_slave_flush_fifo(spi_t * obj); + +/** + * @brief slave recv target length data use interrupt mode. + * @param obj: spi slave object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @retval : stream init status + */ +int32_t spi_slave_read_stream(spi_t *obj, char *rx_buffer, uint32_t length); + +/** + * @brief slave send target length data use interrupt mode. + * @param obj: spi slave object define in application software. + * @param tx_buffer: buffer to be written to Tx FIFO. + * @param length: number of data bytes to be send. + * @retval : stream init status + */ +int32_t spi_slave_write_stream(spi_t *obj, char *tx_buffer, uint32_t length); + +/** + * @brief master recv target length data use interrupt mode. + * @param obj: spi master object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @retval : stream init status + */ +int32_t spi_master_read_stream(spi_t *obj, char *rx_buffer, uint32_t length); + +/** + * @brief master send target length data use interrupt mode. + * @param obj: spi master object define in application software. + * @param tx_buffer: buffer to be written to Tx FIFO. + * @param length: number of data bytes to be send. + * @retval : stream init status + */ +int32_t spi_master_write_stream(spi_t *obj, char *tx_buffer, uint32_t length); + +/** + * @brief master send & recv target length data use interrupt mode. + * @param obj: spi master object define in application software. + * @param tx_buffer: buffer to be written to Tx FIFO. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be send & recv. + * @retval : stream init status + */ +int32_t spi_master_write_read_stream(spi_t *obj, char *tx_buffer, char *rx_buffer, uint32_t length); + +/** + * @brief slave recv target length data use interrupt mode and timeout mechanism. + * @param obj: spi slave object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @param timeout_ms: timeout waiting time. + * @retval : number of bytes read already + */ +int32_t spi_slave_read_stream_timeout(spi_t *obj, char *rx_buffer, uint32_t length, uint32_t timeout_ms); + +/** + * @brief slave recv target length data use interrupt mode and stop if the spi bus is idle. + * @param obj: spi slave object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @retval : number of bytes read already + */ +int32_t spi_slave_read_stream_terminate(spi_t *obj, char *rx_buffer, uint32_t length); + +//#ifdef CONFIG_GDMA_EN +/** + * @brief slave recv target length data use DMA mode. + * @param obj: spi slave object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @retval : stream init status + */ +int32_t spi_slave_read_stream_dma(spi_t *obj, char *rx_buffer, uint32_t length); + +/** + * @brief slave send target length data use DMA mode. + * @param obj: spi slave object define in application software. + * @param tx_buffer: buffer to be written to Tx FIFO. + * @param length: number of data bytes to be send. + * @retval : stream init status + */ +int32_t spi_slave_write_stream_dma(spi_t *obj, char *tx_buffer, uint32_t length); + +/** + * @brief master send & recv target length data use DMA mode. + * @param obj: spi master object define in application software. + * @param tx_buffer: buffer to be written to Tx FIFO. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be send & recv. + * @retval : stream init status + */ +int32_t spi_master_write_read_stream_dma(spi_t * obj, char * tx_buffer, char * rx_buffer, uint32_t length); + +/** + * @brief master recv target length data use DMA mode. + * @param obj: spi master object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @retval : stream init status + * @note : DMA or Interrupt mode can be used to TX dummy data + */ +int32_t spi_master_read_stream_dma(spi_t *obj, char *rx_buffer, uint32_t length); + +/** + * @brief master send target length data use DMA mode. + * @param obj: spi master object define in application software. + * @param tx_buffer: buffer to be written to Tx FIFO. + * @param length: number of data bytes to be send. + * @retval : stream init status + */ +int32_t spi_master_write_stream_dma(spi_t *obj, char *tx_buffer, uint32_t length); + +/** + * @brief slave recv target length data use DMA mode and timeout mechanism. + * @param obj: spi slave object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @param timeout_ms: timeout waiting time. + * @retval : number of bytes read already + */ +int32_t spi_slave_read_stream_dma_timeout(spi_t *obj, char *rx_buffer, uint32_t length, uint32_t timeout_ms); + +/** + * @brief slave recv target length data use DMA mode and stop if the spi bus is idle. + * @param obj: spi slave object define in application software. + * @param rx_buffer: buffer to save data read from SPI FIFO. + * @param length: number of data bytes to be read. + * @retval : number of bytes read already + */ +int32_t spi_slave_read_stream_dma_terminate(spi_t * obj, char * rx_buffer, uint32_t length); +//#endif + +///@} + +/*\@}*/ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.c index a82fe441e8..c67a2045fb 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.c @@ -76,7 +76,7 @@ void gtimer_init (gtimer_t *obj, uint32_t tid) pTimerAdapter->TimerIrqPriority = 0; pTimerAdapter->TimerLoadValueUs = 0xFFFFFFFF; // Just a whatever value pTimerAdapter->TimerMode = USER_DEFINED; - + HalTimerInit ((VOID*) pTimerAdapter); } diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.h b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.h index 7ad983c26e..33c61a3761 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/timer_api.h @@ -29,7 +29,7 @@ enum { TIMER3 = 5, // GTimer 5, share with PWM_2 TIMER4 = 0, // GTimer 0, share with software-RTC functions - GTIMER_MAX = 5 + GTIMER_MAX = 5 }; void gtimer_init (gtimer_t *obj, uint32_t tid); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/trng_api.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/trng_api.c index 5dd1b92faa..c708c2318b 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/trng_api.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/trng_api.c @@ -27,7 +27,7 @@ void trng_init(trng_t *obj) { _memset((void *)obj, 0, sizeof(trng_t)); - analogin_init(&obj->tradcng, ADC0); + analogin_init(&obj->tradcng, (PinName)ADC0); obj->inited = 1; } diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/us_ticker.c b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/us_ticker.c index 81bff2a2fa..40cb05c136 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/us_ticker.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/us_ticker.c @@ -97,7 +97,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp) HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId); HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, TimerAdapter.TimerLoadValueUs); - HalTimerOpExt.HalTimerSync(SYS_TIM_ID); + //HalTimerOpExt.HalTimerSync(SYS_TIM_ID); HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId); } @@ -107,7 +107,7 @@ void us_ticker_fire_interrupt(void) HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId); HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, TimerAdapter.TimerLoadValueUs); - HalTimerOpExt.HalTimerSync(SYS_TIM_ID); + //HalTimerOpExt.HalTimerSync(SYS_TIM_ID); HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId); } diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp b/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp index 5b243a623e..6580b83e2a 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp +++ b/targets/TARGET_Realtek/TARGET_AMEBA/rtw_emac.cpp @@ -76,6 +76,7 @@ bool RTW_EMAC::get_hwaddr(uint8_t *addr) const } else { printf("Get HW address failed\r\n"); } + return true; } void RTW_EMAC::set_hwaddr(const uint8_t *addr) diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib.h index c6dfcf1f69..d3b7499fc1 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib.h @@ -16,272 +16,41 @@ #ifndef __PLATFORM_STDLIB_H__ #define __PLATFORM_STDLIB_H__ -#define USE_CLIB_PATCH 0 -#if defined (__GNUC__) -/* build rom should set USE_RTL_ROM_CLIB=0 */ -#ifndef CONFIG_MBED_ENABLED -#include -#endif +#ifdef __cplusplus +extern "C" { #endif -#ifdef CONFIG_BUILD_ROM -#define USE_RTL_ROM_CLIB 0 -#else -#define BUFFERED_PRINTF 0 -#ifndef CONFIG_MBED_ENABLED -#define USE_RTL_ROM_CLIB 1 -#else -#define USE_RTL_ROM_CLIB 0 -#endif +#if defined(CONFIG_PLATFORM_8195A)+\ + defined(CONFIG_PLATFORM_8711B)+\ + defined(CONFIG_PLATFORM_8721D)+\ + defined(CONFIG_PLATFORM_8195BHP)+\ + defined(USE_STM322xG_EVAL)+\ + defined(USE_STM324xG_EVAL)+\ + defined(STM32F10X_XL) > 1 + #error "Cannot define two or more platform at one time" #endif #if defined(CONFIG_PLATFORM_8195A) -#if defined (__IARSTDLIB__) - #include - #include - #include - #include - #include "diag.h" - - #define strsep(str, delim) _strsep(str, delim) -#elif defined (__CC_ARM) - #include - #include - #include - #include - #include "diag.h" - #define strsep(str, delim) _strsep(str, delim) - #define _memset(dst, val, sz) memset(dst, val, sz) -#else - #include - #include - #include - #include "diag.h" - #include "strproc.h" - #include "basic_types.h" - #include "hal_misc.h" - #if USE_RTL_ROM_CLIB - #include "rtl_lib.h" - #endif - - #undef printf - #undef sprintf - #undef snprintf - #undef atoi - #undef memcmp - #undef memcpy - #undef memset - #undef strcmp - #undef strcpy - #undef strlen - #undef strncmp - #undef strncpy - #undef strsep - #undef strtok - #if USE_RTL_ROM_CLIB - #undef memchr - #undef memmove - #undef strcat - #undef strchr - #undef strncat - #undef strstr - #endif - - #if USE_RTL_ROM_CLIB -#if BUFFERED_PRINTF - extern int buffered_printf(const char* fmt, ...); - #define printf buffered_printf -#else - #define printf rtl_printf -#endif - #define sprintf rtl_sprintf - #define snprintf rtl_snprintf - #define memchr rtl_memchr - #define memcmp rtl_memcmp - #define memcpy rtl_memcpy - #define memmove rtl_memmove - #define memset rtl_memset - #define strcat rtl_strcat - #define strchr rtl_strchr - #define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2) - #define strcpy rtl_strcpy - #define strlen(str) rtl_strlen((const char *)str) - #define strncat rtl_strncat - #define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n) - #define strncpy rtl_strncpy - #define strstr rtl_strstr - #define strsep rtl_strsep - #define strtok rtl_strtok - #else - #if USE_CLIB_PATCH - extern int DiagSscanfPatch(const char *buf, const char *fmt, ...); - extern char* DiagStrtokPatch(char *str, const char* delim); - extern char* DiagStrstrPatch(char *string, char *substring); - extern int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...); - extern u32 DiagPrintfPatch(const char *fmt, ...); - extern u32 DiagSPrintfPatch(u8 *buf, const char *fmt, ...); - #define printf DiagPrintfPatch - #define sprintf DiagSPrintfPatch - #define snprintf DiagSnPrintfPatch - #define strstr(a, b) DiagStrstrPatch((char *)(a), (char *)(b)) - #define strtok DiagStrtokPatch - #else - #define printf DiagPrintf - #define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg) - #if defined (__GNUC__) - #define snprintf DiagSnPrintf // NULL function - #define strstr(str1, str2) prvStrStr(str1, str2) // NULL function - #endif - #define strtok(str, delim) _strsep(str, delim) - #endif - #define memcmp(dst, src, sz) _memcmp(dst, src, sz) - #define memcpy(dst, src, sz) _memcpy(dst, src, sz) - #define memset(dst, val, sz) _memset(dst, val, sz) - #define strchr(s, c) _strchr(s, c) // for B-cut ROM - #define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2) - #define strcpy(dest, src) _strcpy(dest, src) - #define strlen(str) prvStrLen((const unsigned char *) str) - #define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt) - #define strncpy(dest, src, count) _strncpy(dest, src, count) - #define strsep(str, delim) _strsep(str, delim) - #endif - - #define atoi(str) prvAtoi(str) - #define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM - - #if USE_CLIB_PATCH - #undef sscanf - #define sscanf DiagSscanfPatch - #else - #if defined (__GNUC__) - #undef sscanf //_sscanf - //extern int DiagSscanfPatch(const char *buf, const char *fmt, ...); - //#define sscanf DiagSscanfPatch - #define sscanf sscanf // use libc sscanf - #endif - #endif -#endif // defined (__IARSTDLIB__) - -// -// memory management -// -#ifndef CONFIG_MBED_ENABLED -extern void *pvPortMalloc( size_t xWantedSize ); -extern void vPortFree( void *pv ); -#define malloc pvPortMalloc -#define free vPortFree -#endif + #include "platform_stdlib_rtl8195a.h" #elif defined (CONFIG_PLATFORM_8711B) - -#if defined (__IARSTDLIB__) - #include - #include - #include - #include - #include /* va_list */ - #include "diag.h" - - #define strsep(str, delim) _strsep(str, delim) -#else - #include - #include - #include - #include /* va_list */ - #include "diag.h" - #include "strproc.h" - #include "memproc.h" - #include "basic_types.h" -#if USE_RTL_ROM_CLIB - #include "rtl_lib.h" - #include "rom_libc_string.h" -#endif - - #undef printf - #undef sprintf - #undef snprintf - #undef memchr - #undef memcmp - #undef memcpy - #undef memset - #undef memmove - #undef strcmp - #undef strcpy - #undef strlen - #undef strncmp - #undef strncpy - #undef strsep - #undef strtok - #undef strcat - #undef strchr - #undef strncat - #undef strstr - #undef atol - #undef atoi - #undef strpbrk - -#if USE_RTL_ROM_CLIB -#if BUFFERED_PRINTF - extern int buffered_printf(const char* fmt, ...); - #define printf buffered_printf -#else - #define printf rtl_printf -#endif - #define sprintf rtl_sprintf - #define snprintf rtl_snprintf - #define vsnprintf rtl_vsnprintf -#else - #define printf DiagPrintf - #define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg) - #define snprintf DiagSnPrintf // NULL function - #define vsnprintf(buf, size, fmt, ap) VSprintf(buf, fmt, ap) -#endif - #define memchr __rtl_memchr_v1_00 - #define memcmp(dst, src, sz) _memcmp(dst, src, sz) - #define memcpy(dst, src, sz) _memcpy(dst, src, sz) - #define memmove __rtl_memmove_v1_00 - #define memset(dst, val, sz) _memset(dst, val, sz) - - #define strchr(s, c) _strchr(s, c) // for B-cut ROM - #define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2) - #define strcpy(dest, src) _strcpy(dest, src) - #define strlen(str) prvStrLen((const unsigned char *) str) - #define strsep(str, delim) _strsep(str, delim) - #define strstr(str1, str2) prvStrStr(str1, str2) // NULL function - #define strtok(str, delim) prvStrtok(str, delim)//_strsep(str, delim) - #define strcat __rtl_strcat_v1_00 - - #define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt) - #define strncpy(dest, src, count) _strncpy(dest, src, count) - #define strncat __rtl_strncat_v1_00 - - #define atol(str) strtol(str,NULL,10) - #define atoi(str) prvAtoi(str) - #define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM -#if defined (__GNUC__) - #undef sscanf - #define sscanf _sscanf_patch - #define rand Rand -#endif - //extern int _sscanf_patch(const char *buf, const char *fmt, ...); - //#define sscanf _sscanf_patch - - -#endif // defined (__IARSTDLIB__) - -// -// memory management -// -extern void *pvPortMalloc( size_t xWantedSize ); -extern void vPortFree( void *pv ); -#define malloc pvPortMalloc -#define free vPortFree + #include "platform_stdlib_rtl8711b.h" +#elif defined (CONFIG_PLATFORM_8721D) + #include "platform_stdlib_rtl8721d.h" +#elif defined(CONFIG_PLATFORM_8195BHP) + #include "platform_stdlib_rtl8195bhp.h" #elif defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL) || defined(STM32F10X_XL) - #include - #include - #include - #include + #include "platform_stdlib_stm32.h" +#elif defined (CONFIG_PLATFORM_8710C) + #include "platform_stdlib_rtl8710c.h" +#else + #error "Undefined Platform stdlib" #endif +#if (CONFIG_PLATFORM_AMEBA_X == 0) +#include "basic_types.h" +#endif +#ifdef __cplusplus +} +#endif #endif //__PLATFORM_STDLIB_H__ - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib_rtl8195a.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib_rtl8195a.h new file mode 100644 index 0000000000..84ee1c4727 --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/platform/platform_stdlib_rtl8195a.h @@ -0,0 +1,166 @@ +#ifndef PLATFORM_STDLIB_RTL8195A_H +#define PLATFORM_STDLIB_RTL8195A_H + +#define USE_CLIB_PATCH 0 + +#if defined (__GNUC__) + /* build rom should set USE_RTL_ROM_CLIB=0 */ + #if !defined(CONFIG_MBED_ENABLED) + #include + #endif +#endif + +#if defined(CONFIG_BUILD_ROM) || defined(CONFIG_MBED_ENABLED) + #define USE_RTL_ROM_CLIB 0 +#else + #define BUFFERED_PRINTF 0 + #define USE_RTL_ROM_CLIB 1 +#endif + +#if defined (__IARSTDLIB__) + #include + #include + #include + #include + #include "diag.h" + + #define strsep(str, delim) _strsep(str, delim) +#elif defined (__CC_ARM) + #include + #include + #include + #include + #include "diag.h" + #define strsep(str, delim) _strsep(str, delim) +#elif defined (CONFIG_MBED_ENABLED) + #include + #include + #include + #include + #include "diag.h" + + #define strsep(str, delim) _strsep(str, delim) +#else + #include + #include + #include + #include "diag.h" + #include "strproc.h" + #include "basic_types.h" + #include "hal_misc.h" + #if USE_RTL_ROM_CLIB + #include "rtl_lib.h" + #endif + + #undef printf + #undef sprintf + #undef snprintf + #undef atoi + #undef memcmp + #undef memcpy + #undef memset + #undef strcmp + #undef strcpy + #undef strlen + #undef strncmp + #undef strncpy + #undef strsep + #undef strtok + #if USE_RTL_ROM_CLIB + #undef memchr + #undef memmove + #undef strcat + #undef strchr + #undef strncat + #undef strstr + #endif + + #if USE_RTL_ROM_CLIB + #if BUFFERED_PRINTF + extern int buffered_printf(const char* fmt, ...); + #define printf buffered_printf + #else + #define printf rtl_printf + #endif + + #define sprintf rtl_sprintf + #define snprintf rtl_snprintf + #define memchr rtl_memchr + #define memcmp rtl_memcmp + #define memcpy rtl_memcpy + #define memmove rtl_memmove + #define memset rtl_memset + #define strcat rtl_strcat + #define strchr rtl_strchr + #define strcmp(s1, s2) rtl_strcmp((const char *)s1, (const char *)s2) + #define strcpy rtl_strcpy + #define strlen(str) rtl_strlen((const char *)str) + #define strncat rtl_strncat + #define strncmp(s1, s2, n) rtl_strncmp((const char *)s1, (const char *)s2, n) + #define strncpy rtl_strncpy + #define strstr rtl_strstr + #define strsep rtl_strsep + #define strtok rtl_strtok + #else + #if USE_CLIB_PATCH + extern int DiagSscanfPatch(const char *buf, const char *fmt, ...); + extern char* DiagStrtokPatch(char *str, const char* delim); + extern char* DiagStrstrPatch(char *string, char *substring); + extern int DiagSnPrintfPatch(char *buf, size_t size, const char *fmt, ...); + extern u32 DiagPrintfPatch(const char *fmt, ...); + extern u32 DiagSPrintfPatch(u8 *buf, const char *fmt, ...); + #define printf DiagPrintfPatch + #define sprintf DiagSPrintfPatch + #define snprintf DiagSnPrintfPatch + #define strstr(a, b) DiagStrstrPatch((char *)(a), (char *)(b)) + #define strtok DiagStrtokPatch + #else + #define printf DiagPrintf + #define sprintf(fmt, arg...) DiagSPrintf((u8*)fmt, ##arg) + #if defined (__GNUC__) + #define snprintf DiagSnPrintf // NULL function + #define strstr(str1, str2) prvStrStr(str1, str2) // NULL function + #endif + #define strtok(str, delim) _strsep(str, delim) + #endif + #define memcmp(dst, src, sz) _memcmp(dst, src, sz) + #define memcpy(dst, src, sz) _memcpy(dst, src, sz) + #define memset(dst, val, sz) _memset(dst, val, sz) + #define strchr(s, c) _strchr(s, c) // for B-cut ROM + #define strcmp(str1, str2) prvStrCmp((const unsigned char *) str1, (const unsigned char *) str2) + #define strcpy(dest, src) _strcpy(dest, src) + #define strlen(str) prvStrLen((const unsigned char *) str) + #define strncmp(str1, str2, cnt) _strncmp(str1, str2, cnt) + #define strncpy(dest, src, count) _strncpy(dest, src, count) + #define strsep(str, delim) _strsep(str, delim) + #endif + + #define atoi(str) prvAtoi(str) + #define strpbrk(cs, ct) _strpbrk(cs, ct) // for B-cut ROM + + #if USE_CLIB_PATCH + #undef sscanf + #define sscanf DiagSscanfPatch + #else + #if defined (__GNUC__) + #undef sscanf //_sscanf + //extern int DiagSscanfPatch(const char *buf, const char *fmt, ...); + //#define sscanf DiagSscanfPatch + #define sscanf sscanf // use libc sscanf + #endif + #endif +#endif // defined (__IARSTDLIB__) + +// +// memory management +// +#if defined(CONFIG_MBED_ENABLED) + //use libc memory functions +#else + extern void *pvPortMalloc( size_t xWantedSize ); + extern void vPortFree( void *pv ); + #define malloc pvPortMalloc + #define free vPortFree +#endif + +#endif // PLATFORM_STDLIB_RTL8195A_H diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c deleted file mode 100644 index 4902ada864..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.c +++ /dev/null @@ -1,1967 +0,0 @@ -/* Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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. - */ - -//#include -//#include -#include -#include -#include -#include -#include "tcpip.h" -#include -#ifndef CONFIG_MBED_ENABLED -#include // -#endif -#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT || CONFIG_JD_SMART -#include "wlan_fast_connect/example_wlan_fast_connect.h" -#endif -#if CONFIG_EXAMPLE_UART_ATCMD -#include "at_cmd/atcmd_wifi.h" -#endif -extern u32 GlobalDebugEnable; -#define WIFI_CONF_MSG(...) do {\ - if (GlobalDebugEnable) \ - printf("\r" __VA_ARGS__);\ -}while(0) - -#if CONFIG_INIC_EN -extern int inic_start(void); -extern int inic_stop(void); -#endif - -/****************************************************** - * Constants - ******************************************************/ -#define SCAN_USE_SEMAPHORE 0 - -#define RTW_JOIN_TIMEOUT 15000 - -#define JOIN_ASSOCIATED (uint32_t)(1 << 0) -#define JOIN_AUTHENTICATED (uint32_t)(1 << 1) -#define JOIN_LINK_READY (uint32_t)(1 << 2) -#define JOIN_SECURITY_COMPLETE (uint32_t)(1 << 3) -#define JOIN_COMPLETE (uint32_t)(1 << 4) -#define JOIN_NO_NETWORKS (uint32_t)(1 << 5) -#define JOIN_WRONG_SECURITY (uint32_t)(1 << 6) -#define JOIN_HANDSHAKE_DONE (uint32_t)(1 << 7) -#define JOIN_SIMPLE_CONFIG (uint32_t)(1 << 8) -#define JOIN_AIRKISS (uint32_t)(1 << 9) - -/****************************************************** - * Type Definitions - ******************************************************/ - -/****************************************************** - * Variables Declarations - ******************************************************/ -#if !defined(CONFIG_MBED_ENABLED) -extern struct netif xnetif[NET_IF_NUM]; -#endif -/****************************************************** - * Variables Definitions - ******************************************************/ -static internal_scan_handler_t scan_result_handler_ptr = {0, 0, 0, RTW_FALSE, 0, 0, 0, 0, 0}; -static internal_join_result_t* join_user_data; -#ifdef CONFIG_MBED_ENABLED -static rtw_mode_t wifi_mode = RTW_MODE_STA; -#else -extern rtw_mode_t wifi_mode; -#endif -int error_flag = RTW_UNKNOWN; -uint32_t rtw_join_status; -#if ATCMD_VER == ATVER_2 -extern unsigned char dhcp_mode_sta; -#endif - -/****************************************************** - * Variables Definitions - ******************************************************/ - -#ifndef WLAN0_NAME - #define WLAN0_NAME "wlan0" -#endif -#ifndef WLAN1_NAME - #define WLAN1_NAME "wlan1" -#endif -/* Give default value if not defined */ -#ifndef NET_IF_NUM -#ifdef CONFIG_CONCURRENT_MODE -#define NET_IF_NUM 2 -#else -#define NET_IF_NUM 1 -#endif -#endif - -/*Static IP ADDRESS*/ -#ifndef IP_ADDR0 -#define IP_ADDR0 192 -#define IP_ADDR1 168 -#define IP_ADDR2 1 -#define IP_ADDR3 80 -#endif - -/*NETMASK*/ -#ifndef NETMASK_ADDR0 -#define NETMASK_ADDR0 255 -#define NETMASK_ADDR1 255 -#define NETMASK_ADDR2 255 -#define NETMASK_ADDR3 0 -#endif - -/*Gateway Address*/ -#ifndef GW_ADDR0 -#define GW_ADDR0 192 -#define GW_ADDR1 168 -#define GW_ADDR2 1 -#define GW_ADDR3 1 -#endif - -/*Static IP ADDRESS*/ -#ifndef AP_IP_ADDR0 -#define AP_IP_ADDR0 192 -#define AP_IP_ADDR1 168 -#define AP_IP_ADDR2 43 -#define AP_IP_ADDR3 1 -#endif - -/*NETMASK*/ -#ifndef AP_NETMASK_ADDR0 -#define AP_NETMASK_ADDR0 255 -#define AP_NETMASK_ADDR1 255 -#define AP_NETMASK_ADDR2 255 -#define AP_NETMASK_ADDR3 0 -#endif - -/*Gateway Address*/ -#ifndef AP_GW_ADDR0 -#define AP_GW_ADDR0 192 -#define AP_GW_ADDR1 168 -#define AP_GW_ADDR2 43 -#define AP_GW_ADDR3 1 -#endif - -/****************************************************** - * Function Definitions - ******************************************************/ - -#if CONFIG_WLAN -//----------------------------------------------------------------------------// -static int wifi_connect_local(rtw_network_info_t *pWifi) -{ - int ret = 0; - - if(is_promisc_enabled()) - promisc_set(0, NULL, 0); - - /* lock 4s to forbid suspend under linking */ - rtw_wakelock_timeout(4 *1000); - - if(!pWifi) return -1; - switch(pWifi->security_type){ - case RTW_SECURITY_OPEN: - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_NONE, NULL, 0, 0, 0, 0, NULL, 0); - break; - case RTW_SECURITY_WEP_PSK: - case RTW_SECURITY_WEP_SHARED: - ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_SHARED_KEY); - if(ret == 0) - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_WEP, NULL, pWifi->key_id, 1 /* set tx key */, 0, 0, pWifi->password, pWifi->password_len); - break; - case RTW_SECURITY_WPA_TKIP_PSK: - case RTW_SECURITY_WPA2_TKIP_PSK: - ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM); - if(ret == 0) - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_TKIP, NULL, 0, 0, 0, 0, NULL, 0); - if(ret == 0) - ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len); - break; - case RTW_SECURITY_WPA_AES_PSK: - case RTW_SECURITY_WPA2_AES_PSK: - case RTW_SECURITY_WPA2_MIXED_PSK: - case RTW_SECURITY_WPA_WPA2_MIXED: - ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM); - if(ret == 0) - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0, NULL, 0); - if(ret == 0) - ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len); - break; - default: - ret = -1; - WIFI_CONF_MSG("\n\rWIFICONF: security type(0x%x) is not supported.\n\r", pWifi->security_type); - break; - } - if(ret == 0) - ret = wext_set_ssid(WLAN0_NAME, pWifi->ssid.val, pWifi->ssid.len); - return ret; -} - -static int wifi_connect_bssid_local(rtw_network_info_t *pWifi) -{ - int ret = 0; - u8 bssid[12] = {0}; - - if(is_promisc_enabled()) - promisc_set(0, NULL, 0); - - /* lock 4s to forbid suspend under linking */ - rtw_wakelock_timeout(4 *1000); - - if(!pWifi) return -1; - switch(pWifi->security_type){ - case RTW_SECURITY_OPEN: - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_NONE, NULL, 0, 0, 0, 0, NULL, 0); - break; - case RTW_SECURITY_WEP_PSK: - case RTW_SECURITY_WEP_SHARED: - ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_SHARED_KEY); - if(ret == 0) - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_WEP, NULL, pWifi->key_id, 1 /* set tx key */, 0, 0, pWifi->password, pWifi->password_len); - break; - case RTW_SECURITY_WPA_TKIP_PSK: - case RTW_SECURITY_WPA2_TKIP_PSK: - ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM); - if(ret == 0) - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_TKIP, NULL, 0, 0, 0, 0, NULL, 0); - if(ret == 0) - ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len); - break; - case RTW_SECURITY_WPA_AES_PSK: - case RTW_SECURITY_WPA2_AES_PSK: - case RTW_SECURITY_WPA2_MIXED_PSK: - ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM); - if(ret == 0) - ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0, NULL, 0); - if(ret == 0) - ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len); - break; - default: - ret = -1; - WIFI_CONF_MSG("\n\rWIFICONF: security type(0x%x) is not supported.\n\r", pWifi->security_type); - break; - } - if(ret == 0){ - memcpy(bssid, pWifi->bssid.octet, ETH_ALEN); - if(pWifi->ssid.len){ - bssid[ETH_ALEN] = '#'; - bssid[ETH_ALEN + 1] = '@'; - memcpy(bssid + ETH_ALEN + 2, &pWifi, sizeof(pWifi)); - } - ret = wext_set_bssid(WLAN0_NAME, bssid); - } - return ret; -} - -void wifi_rx_beacon_hdl( char* buf, int buf_len, int flags, void* userdata) { - //printf("Beacon!\n"); -} - - -static void wifi_no_network_hdl(char* buf, int buf_len, int flags, void* userdata) -{ - if(join_user_data!=NULL) - rtw_join_status = JOIN_NO_NETWORKS; -} - -static void wifi_connected_hdl( char* buf, int buf_len, int flags, void* userdata) -{ -#ifdef CONFIG_ENABLE_EAP - if(get_eap_phase()){ - rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY; - return; - } -#endif /* CONFIG_ENABLE_EAP */ - - if((join_user_data!=NULL)&&((join_user_data->network_info.security_type == RTW_SECURITY_OPEN) || - (join_user_data->network_info.security_type == RTW_SECURITY_WEP_PSK) || - (join_user_data->network_info.security_type == RTW_SECURITY_WEP_SHARED))){ - rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY; - rtw_up_sema(&join_user_data->join_sema); - }else if((join_user_data!=NULL)&&((join_user_data->network_info.security_type == RTW_SECURITY_WPA2_AES_PSK) )){ - rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY; - } -} -static void wifi_handshake_done_hdl( char* buf, int buf_len, int flags, void* userdata) -{ - rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY|JOIN_HANDSHAKE_DONE; - if(join_user_data != NULL) - rtw_up_sema(&join_user_data->join_sema); -} - -static void wifi_disconn_hdl( char* buf, int buf_len, int flags, void* userdata) -{ - if(join_user_data != NULL){ - if(join_user_data->network_info.security_type == RTW_SECURITY_OPEN){ - - if(rtw_join_status == JOIN_NO_NETWORKS) - error_flag = RTW_NONE_NETWORK; - - }else if(join_user_data->network_info.security_type == RTW_SECURITY_WEP_PSK){ - - if(rtw_join_status == JOIN_NO_NETWORKS) - error_flag = RTW_NONE_NETWORK; - - else if(rtw_join_status == 0) - error_flag = RTW_CONNECT_FAIL; - - }else if(join_user_data->network_info.security_type == RTW_SECURITY_WPA2_AES_PSK){ - - if(rtw_join_status ==JOIN_NO_NETWORKS) - error_flag = RTW_NONE_NETWORK; - - else if(rtw_join_status == 0) - error_flag = RTW_CONNECT_FAIL; - - else if(rtw_join_status == (JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY)) - error_flag = RTW_WRONG_PASSWORD; - } - - }else{ - if(error_flag == RTW_NO_ERROR) //wifi_disconn_hdl will be dispatched one more time after join_user_data = NULL add by frankie - error_flag = RTW_UNKNOWN; - } - - if(join_user_data != NULL) - rtw_up_sema(&join_user_data->join_sema); - //printf("\r\nWiFi Disconnect. Error flag is %d.\n", error_flag); -} - -#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT || CONFIG_JD_SMART -#define WLAN0_NAME "wlan0" - -void restore_wifi_info_to_flash() -{ - - struct wlan_fast_reconnect * data_to_flash; - u32 channel = 0; - u8 index = 0; - u8 *ifname[1] = {WLAN0_NAME}; - rtw_wifi_setting_t setting; - //struct security_priv *psecuritypriv = &padapter->securitypriv; - //WLAN_BSSID_EX *pcur_bss = pmlmepriv->cur_network.network; - - data_to_flash = (struct wlan_fast_reconnect *)rtw_zmalloc(sizeof(struct wlan_fast_reconnect)); - - if(data_to_flash && p_write_reconnect_ptr){ - if(wifi_get_setting((const char*)ifname[0],&setting) || setting.mode == RTW_MODE_AP){ - WIFI_CONF_MSG("\r\n %s():wifi_get_setting fail or ap mode", __func__); - return; - } - channel = setting.channel; - - rtw_memset(psk_essid[index], 0, sizeof(psk_essid[index])); - strncpy(psk_essid[index], setting.ssid, strlen(setting.ssid)); - switch(setting.security_type){ - case RTW_SECURITY_OPEN: - rtw_memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index])); - rtw_memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index])); - data_to_flash->security_type = RTW_SECURITY_OPEN; - break; - case RTW_SECURITY_WEP_PSK: - channel |= (setting.key_idx) << 28; - rtw_memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index])); - rtw_memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index])); - rtw_memcpy(psk_passphrase[index], setting.password, sizeof(psk_passphrase[index])); - data_to_flash->security_type = RTW_SECURITY_WEP_PSK; - break; - case RTW_SECURITY_WPA_TKIP_PSK: - data_to_flash->security_type = RTW_SECURITY_WPA_TKIP_PSK; - break; - case RTW_SECURITY_WPA2_AES_PSK: - data_to_flash->security_type = RTW_SECURITY_WPA2_AES_PSK; - break; - default: - break; - } - - memcpy(data_to_flash->psk_essid, psk_essid[index], sizeof(data_to_flash->psk_essid)); - if (strlen(psk_passphrase64) == 64) { - memcpy(data_to_flash->psk_passphrase, psk_passphrase64, sizeof(data_to_flash->psk_passphrase)); - } else { - memcpy(data_to_flash->psk_passphrase, psk_passphrase[index], sizeof(data_to_flash->psk_passphrase)); - } - memcpy(data_to_flash->wpa_global_PSK, wpa_global_PSK[index], sizeof(data_to_flash->wpa_global_PSK)); - memcpy(&(data_to_flash->channel), &channel, 4); - - //call callback function in user program - p_write_reconnect_ptr((u8 *)data_to_flash, sizeof(struct wlan_fast_reconnect)); - - } - if(data_to_flash) - rtw_free(data_to_flash); -} - -#endif - -//----------------------------------------------------------------------------// -int wifi_connect( - char *ssid, - rtw_security_t security_type, - char *password, - int ssid_len, - int password_len, - int key_id, - void *semaphore) -{ - _sema join_semaphore; - rtw_result_t result = RTW_SUCCESS; - u8 wep_hex = 0; - u8 wep_pwd[14] = {0}; - - if(rtw_join_status & JOIN_SIMPLE_CONFIG || rtw_join_status & JOIN_AIRKISS){ - return RTW_ERROR; - } - - rtw_join_status = 0;//clear for last connect status - error_flag = RTW_UNKNOWN ;//clear for last connect status - if ( ( ( ( password_len > RTW_MAX_PSK_LEN ) || - ( password_len < RTW_MIN_PSK_LEN ) ) && - ( ( security_type == RTW_SECURITY_WPA_TKIP_PSK ) || - ( security_type == RTW_SECURITY_WPA_AES_PSK ) || - ( security_type == RTW_SECURITY_WPA2_AES_PSK ) || - ( security_type == RTW_SECURITY_WPA2_TKIP_PSK ) || - ( security_type == RTW_SECURITY_WPA2_MIXED_PSK ) ) )) { - error_flag = RTW_WRONG_PASSWORD; - return RTW_INVALID_KEY; - } - - if ((security_type == RTW_SECURITY_WEP_PSK)|| - (security_type ==RTW_SECURITY_WEP_SHARED)) { - if ((password_len != 5) && (password_len != 13) && - (password_len != 10)&& (password_len != 26)) { - error_flag = RTW_WRONG_PASSWORD; - return RTW_INVALID_KEY; - } else { - - if(password_len == 10) { - - u32 p[5] = {0}; - u8 i = 0; - sscanf((const char*)password, "%02lx%02lx%02lx%02lx%02lx", &p[0], &p[1], &p[2], &p[3], &p[4]); - for(i=0; i< 5; i++) - wep_pwd[i] = (u8)p[i]; - wep_pwd[5] = '\0'; - password_len = 5; - wep_hex = 1; - } else if (password_len == 26) { - u32 p[13] = {0}; - u8 i = 0; - sscanf((const char*)password, "%02lx%02lx%02lx%02lx%02lx%02lx%02lx"\ - "%02lx%02lx%02lx%02lx%02lx%02lx", &p[0], &p[1], &p[2], &p[3], &p[4],\ - &p[5], &p[6], &p[7], &p[8], &p[9], &p[10], &p[11], &p[12]); - for(i=0; i< 13; i++) - wep_pwd[i] = (u8)p[i]; - wep_pwd[13] = '\0'; - password_len = 13; - wep_hex = 1; - } - } - } - - internal_join_result_t *join_result = (internal_join_result_t *)rtw_zmalloc(sizeof(internal_join_result_t)); - if(!join_result) { - return RTW_NOMEM; - } - - join_result->network_info.ssid.len = ssid_len > 32 ? 32 : ssid_len; - rtw_memcpy(join_result->network_info.ssid.val, ssid, ssid_len); - - join_result->network_info.password_len = password_len; - if(password_len) { - /* add \0 to the end */ - join_result->network_info.password = rtw_zmalloc(password_len + 1); - if(!join_result->network_info.password) { - result = RTW_NOMEM; - goto error; - } - if (0 == wep_hex) - rtw_memcpy(join_result->network_info.password, password, password_len); - else - rtw_memcpy(join_result->network_info.password, wep_pwd, password_len); - - } - - join_result->network_info.security_type = security_type; - join_result->network_info.key_id = key_id; - - if(semaphore == NULL) { - rtw_init_sema( &join_result->join_sema, 0 ); - if(!join_result->join_sema){ - result = RTW_NORESOURCE; - goto error; - } - join_semaphore = join_result->join_sema; - } else { - join_result->join_sema = semaphore; - } - wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl,NULL); - wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL); - wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL); - wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl, NULL); - - wifi_connect_local(&join_result->network_info); - - join_user_data = join_result; - - if(semaphore == NULL) { -// for eap connection, timeout should be longer (default value in wpa_supplicant: 60s) -#ifdef CONFIG_ENABLE_EAP - if(get_eap_phase()){ - if(rtw_down_timeout_sema( &join_result->join_sema, 60000 ) == RTW_FALSE) { - WIFI_CONF_MSG("RTW API: Join bss timeout\r\n"); - if(password_len) { - rtw_free(join_result->network_info.password); - } - result = RTW_TIMEOUT; - goto error; - } else { - if(wifi_is_connected_to_ap( ) != RTW_SUCCESS) { - result = RTW_ERROR; - goto error; - } - } - } - else -#endif - if(rtw_down_timeout_sema( &join_result->join_sema, RTW_JOIN_TIMEOUT ) == RTW_FALSE) { - WIFI_CONF_MSG("RTW API: Join bss timeout\r\n"); - if(password_len) { - rtw_free(join_result->network_info.password); - } - result = RTW_TIMEOUT; - goto error; - } else { - if(join_result->network_info.password_len) { - rtw_free(join_result->network_info.password); - } - if(wifi_is_connected_to_ap( ) != RTW_SUCCESS) { - result = RTW_ERROR; - goto error; - } - } - } - - result = RTW_SUCCESS; - -#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT || CONFIG_JD_SMART - restore_wifi_info_to_flash(); -#endif - -error: - if(semaphore == NULL){ - rtw_free_sema( &join_semaphore); - } - join_user_data = NULL; - rtw_free((u8*)join_result); - wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl); - wifi_unreg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl); - wifi_unreg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl); - return result; -} - -int wifi_connect_bssid( - unsigned char bssid[ETH_ALEN], - char *ssid, - rtw_security_t security_type, - char *password, - int bssid_len, - int ssid_len, - int password_len, - int key_id, - void *semaphore) -{ - _sema join_semaphore; - rtw_result_t result = RTW_SUCCESS; - - if(rtw_join_status & JOIN_SIMPLE_CONFIG || rtw_join_status & JOIN_AIRKISS){ - return RTW_ERROR; - } - - rtw_join_status = 0;//clear for last connect status - error_flag = RTW_UNKNOWN;//clear for last connect status - internal_join_result_t *join_result = (internal_join_result_t *)rtw_zmalloc(sizeof(internal_join_result_t)); - if(!join_result) { - return RTW_NOMEM; - } - if(ssid_len && ssid){ - join_result->network_info.ssid.len = ssid_len > 32 ? 32 : ssid_len; - rtw_memcpy(join_result->network_info.ssid.val, ssid, ssid_len); - } - rtw_memcpy(join_result->network_info.bssid.octet, bssid, bssid_len); - - if ( ( ( ( password_len > RTW_MAX_PSK_LEN ) || - ( password_len < RTW_MIN_PSK_LEN ) ) && - ( ( security_type == RTW_SECURITY_WPA_TKIP_PSK ) || - ( security_type == RTW_SECURITY_WPA_AES_PSK ) || - ( security_type == RTW_SECURITY_WPA2_AES_PSK ) || - ( security_type == RTW_SECURITY_WPA2_TKIP_PSK ) || - ( security_type == RTW_SECURITY_WPA2_MIXED_PSK ) ) )|| - (((password_len != 5)&& (password_len != 13))&& - ((security_type == RTW_SECURITY_WEP_PSK)|| - (security_type ==RTW_SECURITY_WEP_SHARED ) ))) { - return RTW_INVALID_KEY; - } - join_result->network_info.password_len = password_len; - if(password_len) { - /* add \0 to the end */ - join_result->network_info.password = rtw_zmalloc(password_len + 1); - if(!join_result->network_info.password) { - return RTW_NOMEM; - } - rtw_memcpy(join_result->network_info.password, password, password_len); - } - - join_result->network_info.security_type = security_type; - join_result->network_info.key_id = key_id; - - if(semaphore == NULL) { - rtw_init_sema( &join_result->join_sema, 0 ); - if(!join_result->join_sema){ - return RTW_NORESOURCE; - } - join_semaphore = join_result->join_sema; - } else { - join_result->join_sema = semaphore; - } - wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl,NULL); - wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL); - wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL); - wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl, NULL); - - wifi_connect_bssid_local(&join_result->network_info); - - join_user_data = join_result; - - if(semaphore == NULL) { - if(rtw_down_timeout_sema( &join_result->join_sema, RTW_JOIN_TIMEOUT ) == RTW_FALSE) { - WIFI_CONF_MSG("RTW API: Join bss timeout\r\n"); - if(password_len) { - rtw_free(join_result->network_info.password); - } - rtw_free((u8*)join_result); - rtw_free_sema( &join_semaphore); - result = RTW_TIMEOUT; - goto error; - } else { - rtw_free_sema( &join_semaphore ); - if(join_result->network_info.password_len) { - rtw_free(join_result->network_info.password); - } - rtw_free((u8*)join_result); - if( wifi_is_connected_to_ap( ) != RTW_SUCCESS) { - result = RTW_ERROR; - goto error; - } - } - } - - result = RTW_SUCCESS; - -#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT || CONFIG_JD_SMART - restore_wifi_info_to_flash(); -#endif - -error: - join_user_data = NULL; - wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl); - wifi_unreg_event_handler(WIFI_EVENT_NO_NETWORK,wifi_no_network_hdl); - wifi_unreg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, wifi_handshake_done_hdl); - return result; -} - -int wifi_disconnect(void) -{ - int ret = 0; - - //set MAC address last byte to 1 since driver will filter the mac with all 0x00 or 0xff - //add extra 2 zero byte for check of #@ in wext_set_bssid() - const __u8 null_bssid[ETH_ALEN + 2] = {0, 0, 0, 0, 0, 1, 0, 0}; - - if (wext_set_bssid(WLAN0_NAME, null_bssid) < 0){ - WIFI_CONF_MSG("\n\rWEXT: Failed to set bogus BSSID to disconnect"); - ret = -1; - } - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_is_connected_to_ap( void ) -{ - return rltk_wlan_is_connected_to_ap(); -} - -//----------------------------------------------------------------------------// -int wifi_is_up(rtw_interface_t interface) -{ - if(interface == RTW_AP_INTERFACE) { - if(wifi_mode == RTW_MODE_STA_AP) { - return rltk_wlan_running(WLAN1_IDX); - } - } - - return rltk_wlan_running(WLAN0_IDX); -} - -int wifi_is_ready_to_transceive(rtw_interface_t interface) -{ - switch ( interface ) - { - case RTW_AP_INTERFACE: - return ( wifi_is_up(interface) == RTW_TRUE ) ? RTW_SUCCESS : RTW_ERROR; - - case RTW_STA_INTERFACE: - switch ( error_flag) - { - case RTW_NO_ERROR: - return RTW_SUCCESS; - - default: - return RTW_ERROR; - } - default: - return RTW_ERROR; - } -} - -//----------------------------------------------------------------------------// -int wifi_set_mac_address(char * mac) -{ - char buf[13+17+1]; - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 13+17, "write_mac %s", mac); - return wext_private_command(WLAN0_NAME, buf, 0); -} - -int wifi_get_mac_address(char * mac) -{ - int ret = 0; - char buf[32]; - rtw_memset(buf, 0, sizeof(buf)); - rtw_memcpy(buf, "read_mac", 8); - ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 32); - strcpy(mac, buf); - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_enable_powersave(void) -{ - return wext_enable_powersave(WLAN0_NAME, 1, 1); -} - -int wifi_disable_powersave(void) -{ - return wext_disable_powersave(WLAN0_NAME); -} - -#if 0 //Not ready -//----------------------------------------------------------------------------// -int wifi_get_txpower(int *poweridx) -{ - int ret = 0; - char buf[11]; - - rtw_memset(buf, 0, sizeof(buf)); - rtw_memcpy(buf, "txpower", 11); - ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 11); - sscanf(buf, "%d", poweridx); - - return ret; -} - -int wifi_set_txpower(int poweridx) -{ - int ret = 0; - char buf[24]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 24, "txpower patha=%d", poweridx); - ret = wext_private_command(WLAN0_NAME, buf, 0); - - return ret; -} -#endif - -//----------------------------------------------------------------------------// -int wifi_get_associated_client_list(void * client_list_buffer, uint16_t buffer_length) -{ - const char * ifname = WLAN0_NAME; - int ret = 0; - char buf[25]; - - if(wifi_mode == RTW_MODE_STA_AP) { - ifname = WLAN1_NAME; - } - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 25, "get_client_list %x", client_list_buffer); - ret = wext_private_command(ifname, buf, 0); - - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security) -{ - const char * ifname = WLAN0_NAME; - int ret = 0; - char buf[24]; - - if(wifi_mode == RTW_MODE_STA_AP) { - ifname = WLAN1_NAME; - } - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 24, "get_ap_info %x", ap_info); - ret = wext_private_command(ifname, buf, 0); - - snprintf(buf, 24, "get_security"); - ret = wext_private_command_with_retval(ifname, buf, buf, 24); - sscanf(buf, "%lu", security); - - return ret; -} - -int wifi_get_drv_ability(uint32_t *ability) -{ - return wext_get_drv_ability(WLAN0_NAME, ability); -} - -//----------------------------------------------------------------------------// -int wifi_set_country(rtw_country_code_t country_code) -{ - int ret; - - ret = wext_set_country(WLAN0_NAME, country_code); - - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_set_channel_plan(uint8_t channel_plan) -{ - const char * ifname = WLAN0_NAME; - int ret = 0; - char buf[24]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 24, "set_ch_plan %x", channel_plan); - ret = wext_private_command(ifname, buf, 0); - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_get_rssi(int *pRSSI) -{ - return wext_get_rssi(WLAN0_NAME, pRSSI); -} - -//----------------------------------------------------------------------------// -int wifi_set_channel(int channel) -{ - return wext_set_channel(WLAN0_NAME, channel); -} - -int wifi_get_channel(int *channel) -{ - return wext_get_channel(WLAN0_NAME, (u8*)channel); -} - -//----------------------------------------------------------------------------// -int wifi_register_multicast_address(rtw_mac_t *mac) -{ - return wext_register_multicast_address(WLAN0_NAME, mac); -} - -int wifi_unregister_multicast_address(rtw_mac_t *mac) -{ - return wext_unregister_multicast_address(WLAN0_NAME, mac); -} - -//----------------------------------------------------------------------------// -void wifi_set_mib(void) -{ - // adaptivity - wext_set_adaptivity(RTW_ADAPTIVITY_DISABLE); -} - -//----------------------------------------------------------------------------// -int wifi_rf_on(void) -{ - int ret; - ret = rltk_wlan_rf_on(); - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_rf_off(void) -{ - int ret; - ret = rltk_wlan_rf_off(); - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_on(rtw_mode_t mode) -{ - int ret = 1; - int timeout = 20; - int idx; - int devnum = 1; - static int event_init = 0; - - if(rltk_wlan_running(WLAN0_IDX)) { - WIFI_CONF_MSG("\n\rWIFI is already running"); - return 1; - } - - if(event_init == 0){ - init_event_callback_list(); - event_init = 1; - } - - wifi_mode = mode; - - if(mode == RTW_MODE_STA_AP) - devnum = 2; - - // set wifi mib - wifi_set_mib(); - WIFI_CONF_MSG("\n\rInitializing WIFI ..."); - for(idx=0;idxBSSID.octet, (*result_ptr)->BSSID.octet)){ - if((*result_ptr)->signal_strength > scan_result_handler_ptr.pap_details[i]->signal_strength){ - temp = scan_result_handler_ptr.pap_details[i]; - for(j = i-1; j >= 0; j--){ - if(scan_result_handler_ptr.pap_details[j]->signal_strength >= (*result_ptr)->signal_strength) - break; - else - scan_result_handler_ptr.pap_details[j+1] = scan_result_handler_ptr.pap_details[j]; - } - scan_result_handler_ptr.pap_details[j+1] = temp; - scan_result_handler_ptr.pap_details[j+1]->signal_strength = (*result_ptr)->signal_strength; - } - memset(*result_ptr, 0, sizeof(rtw_scan_result_t)); - return; - } - } - - scan_result_handler_ptr.scan_cnt++; - - if(scan_result_handler_ptr.scan_cnt > scan_result_handler_ptr.max_ap_size){ - scan_result_handler_ptr.scan_cnt = scan_result_handler_ptr.max_ap_size; - if((*result_ptr)->signal_strength > scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size-1]->signal_strength){ - rtw_memcpy(scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size-1], *result_ptr, sizeof(rtw_scan_result_t)); - temp = scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size -1]; - }else - return; - }else{ - rtw_memcpy(&scan_result_handler_ptr.ap_details[scan_result_handler_ptr.scan_cnt-1], *result_ptr, sizeof(rtw_scan_result_t)); - } - - for(i=0; i< scan_result_handler_ptr.scan_cnt-1; i++){ - if((*result_ptr)->signal_strength > scan_result_handler_ptr.pap_details[i]->signal_strength) - break; - } - insert_pos = i; - - for(i = scan_result_handler_ptr.scan_cnt-1; i>insert_pos; i--) - scan_result_handler_ptr.pap_details[i] = scan_result_handler_ptr.pap_details[i-1]; - - if(temp != NULL) - scan_result_handler_ptr.pap_details[insert_pos] = temp; - else - scan_result_handler_ptr.pap_details[insert_pos] = &scan_result_handler_ptr.ap_details[scan_result_handler_ptr.scan_cnt-1]; - rtw_memset(*result_ptr, 0, sizeof(rtw_scan_result_t)); -} - -void wifi_scan_done_hdl( char* buf, int buf_len, int flags, void* userdata) -{ - int i = 0; - rtw_scan_handler_result_t scan_result_report; - - for(i=0; ibuf, pscan_buf->buf_len, flags); - }else{ - wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl, NULL); - wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl, NULL); - ret = wext_set_scan(WLAN0_NAME, NULL, 0, flags); - } - - if(ret == 0) { - if(result_ptr != NULL){ - ret = wext_get_scan(WLAN0_NAME, pscan_buf->buf, pscan_buf->buf_len); - } - } - else if(ret == -1){ - if(result_ptr == NULL){ - wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl); - wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl); - } - } - return ret; -} - -int wifi_scan_networks_with_ssid(int (results_handler)(char*buf, int buflen, char *ssid, void *user_data), - OUT void* user_data, IN int scan_buflen, IN char* ssid, IN int ssid_len) -{ - int scan_cnt = 0, add_cnt = 0; - scan_buf_arg scan_buf; - int ret; - - scan_buf.buf_len = scan_buflen; - scan_buf.buf = (char*)rtw_malloc(scan_buf.buf_len); - if(!scan_buf.buf){ - WIFI_CONF_MSG("\n\rERROR: Can't malloc memory(%d)", scan_buf.buf_len); - return RTW_NOMEM; - } - //set ssid - memset(scan_buf.buf, 0, scan_buf.buf_len); - memcpy(scan_buf.buf, &ssid_len, sizeof(int)); - memcpy(scan_buf.buf+sizeof(int), ssid, ssid_len); - - //Scan channel - scan_cnt = wifi_scan(RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, &scan_buf); - if(scan_cnt < 0){ - WIFI_CONF_MSG("\n\rERROR: wifi scan failed"); - ret = RTW_ERROR; - }else{ - if(NULL == results_handler) - { - int plen = 0; - while(plen < scan_buf.buf_len){ - int len, rssi, ssid_len, i, security_mode; - int wps_password_id; - char *mac, *ssid; - //u8 *security_mode; - printf("\n\r"); - // len - len = (int)*(scan_buf.buf + plen); - printf("len = %d,\t", len); - // check end - if(len == 0) break; - // mac - mac = scan_buf.buf + plen + 1; - printf("mac = "); - for(i=0; i<6; i++) - printf("%02x ", (u8)*(mac+i)); - printf(",\t"); - // rssi - rssi = *(int*)(scan_buf.buf + plen + 1 + 6); - printf(" rssi = %d,\t", rssi); - // security_mode - security_mode = (int)*(scan_buf.buf + plen + 1 + 6 + 4); - switch (security_mode) { - case IW_ENCODE_ALG_NONE: - printf("sec = open ,\t"); - break; - case IW_ENCODE_ALG_WEP: - printf("sec = wep ,\t"); - break; - case IW_ENCODE_ALG_CCMP: - printf("sec = wpa/wpa2,\t"); - break; - } - // password id - wps_password_id = (int)*(scan_buf.buf + plen + 1 + 6 + 4 + 1); - printf("wps password id = %d,\t", wps_password_id); - - printf("channel = %d,\t", *(scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1)); - // ssid - ssid_len = len - 1 - 6 - 4 - 1 - 1 - 1; - ssid = scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1 + 1; - printf("ssid = "); - for(i=0; i 0) - { - rtw_msleep_os(20); - count --; - } - if(count == 0){ - WIFI_CONF_MSG("\n\r[%d]WiFi: Scan is running. Wait 2s timeout.", rtw_get_current_time()); - return RTW_TIMEOUT; - } - } - scan_result_handler_ptr.scan_start_time = rtw_get_current_time(); - scan_result_handler_ptr.scan_running = 1; -#endif - - scan_result_handler_ptr.gscan_result_handler = results_handler; - - scan_result_handler_ptr.max_ap_size = max_ap_size; - scan_result_handler_ptr.ap_details = (rtw_scan_result_t*)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t)); - if(scan_result_handler_ptr.ap_details == NULL){ - goto err_exit; - } - rtw_memset(scan_result_handler_ptr.ap_details, 0, max_ap_size*sizeof(rtw_scan_result_t)); - - scan_result_handler_ptr.pap_details = (rtw_scan_result_t**)rtw_zmalloc(max_ap_size*sizeof(rtw_scan_result_t*)); - if(scan_result_handler_ptr.pap_details == NULL) - goto error2_with_result_ptr; - rtw_memset(scan_result_handler_ptr.pap_details, 0, max_ap_size); - - scan_result_handler_ptr.scan_cnt = 0; - - scan_result_handler_ptr.scan_complete = RTW_FALSE; - scan_result_handler_ptr.user_data = user_data; - - if (wifi_scan( RTW_SCAN_COMMAMD<<4 | RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY, NULL) != RTW_SUCCESS) - { - goto error1_with_result_ptr; - } - - return RTW_SUCCESS; - -error1_with_result_ptr: - rtw_free((u8*)scan_result_handler_ptr.pap_details); - scan_result_handler_ptr.pap_details = NULL; - -error2_with_result_ptr: - rtw_free((u8*)scan_result_handler_ptr.ap_details); - scan_result_handler_ptr.ap_details = NULL; - -err_exit: - rtw_memset((void *)&scan_result_handler_ptr, 0, sizeof(scan_result_handler_ptr)); - return RTW_ERROR; -} -//----------------------------------------------------------------------------// -int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length) -{ - if(channel_list) - return wext_set_pscan_channel(WLAN0_NAME, channel_list, pscan_config, length); - else - return -1; -} - -//----------------------------------------------------------------------------// -int wifi_get_setting(const char *ifname, rtw_wifi_setting_t *pSetting) -{ - int ret = 0; - int mode = 0; - unsigned short security = 0; - - memset(pSetting, 0, sizeof(rtw_wifi_setting_t)); - if(wext_get_mode(ifname, &mode) < 0) - ret = -1; - - switch(mode) { - case IW_MODE_MASTER: - pSetting->mode = RTW_MODE_AP; - break; - case IW_MODE_INFRA: - default: - pSetting->mode = RTW_MODE_STA; - break; - //default: - //printf("\r\n%s(): Unknown mode %d\n", __func__, mode); - //break; - } - - if(wext_get_ssid(ifname, pSetting->ssid) < 0) - ret = -1; - if(wext_get_channel(ifname, &pSetting->channel) < 0) - ret = -1; - if(wext_get_enc_ext(ifname, &security, &pSetting->key_idx, pSetting->password) < 0) - ret = -1; - - switch(security){ - case IW_ENCODE_ALG_NONE: - pSetting->security_type = RTW_SECURITY_OPEN; - break; - case IW_ENCODE_ALG_WEP: - pSetting->security_type = RTW_SECURITY_WEP_PSK; - break; - case IW_ENCODE_ALG_TKIP: - pSetting->security_type = RTW_SECURITY_WPA_TKIP_PSK; - break; - case IW_ENCODE_ALG_CCMP: - pSetting->security_type = RTW_SECURITY_WPA2_AES_PSK; - break; - default: - break; - } - - if(security == IW_ENCODE_ALG_TKIP || security == IW_ENCODE_ALG_CCMP) - if(wext_get_passphrase(ifname, pSetting->password) < 0) - ret = -1; - - return ret; -} -//----------------------------------------------------------------------------// -int wifi_show_setting(const char *ifname, rtw_wifi_setting_t *pSetting) -{ - int ret = 0; - - printf("\n\r\nWIFI %s Setting:",ifname); - printf("\n\r=============================="); - - switch(pSetting->mode) { - case RTW_MODE_AP: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("\r\nAP,"); -#endif - printf("\n\r MODE => AP"); - break; - case RTW_MODE_STA: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("\r\nSTA,"); -#endif - printf("\n\r MODE => STATION"); - break; - default: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("\r\nUNKNOWN,"); -#endif - printf("\n\r MODE => UNKNOWN"); - } -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("%s,%d,", pSetting->ssid, pSetting->channel); -#endif - printf("\n\r SSID => %s", pSetting->ssid); - printf("\n\r CHANNEL => %d", pSetting->channel); - - switch(pSetting->security_type) { - case RTW_SECURITY_OPEN: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("OPEN,"); -#endif - printf("\n\r SECURITY => OPEN"); - break; - case RTW_SECURITY_WEP_PSK: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("WEP,%d,", pSetting->key_idx); -#endif - printf("\n\r SECURITY => WEP"); - printf("\n\r KEY INDEX => %d", pSetting->key_idx); - break; - case RTW_SECURITY_WPA_TKIP_PSK: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("TKIP,"); -#endif - printf("\n\r SECURITY => TKIP"); - break; - case RTW_SECURITY_WPA2_AES_PSK: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("AES,"); -#endif - printf("\n\r SECURITY => AES"); - break; - default: -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("UNKNOWN,"); -#endif - printf("\n\r SECURITY => UNKNOWN"); - } - -#if CONFIG_EXAMPLE_UART_ATCMD - at_printf("%s,", pSetting->password); -#endif - printf("\n\r PASSWORD => %s", pSetting->password); - printf("\n\r"); - - return ret; -} - -//----------------------------------------------------------------------------// -int wifi_set_network_mode(rtw_network_mode_t mode) -{ - if((mode == RTW_NETWORK_B) || (mode == RTW_NETWORK_BG) || (mode == RTW_NETWORK_BGN)) - return rltk_wlan_wireless_mode((unsigned char) mode); - - return -1; -} - -int wifi_set_wps_phase(unsigned char is_trigger_wps) -{ - return rltk_wlan_set_wps_phase(is_trigger_wps); -} - -//----------------------------------------------------------------------------// -int wifi_set_promisc(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used) -{ - return promisc_set(enabled, callback, len_used); -} - -void wifi_enter_promisc_mode(){ - int mode = 0; - unsigned char ssid[33]; - - if(wifi_mode == RTW_MODE_STA_AP){ - wifi_off(); - rtw_msleep_os(20); - wifi_on(RTW_MODE_PROMISC); - }else{ - wext_get_mode(WLAN0_NAME, &mode); - - switch(mode) { - case IW_MODE_MASTER: //In AP mode - //rltk_wlan_deinit(); - wifi_off();//modified by Chris Yang for iNIC - rtw_msleep_os(20); - //rltk_wlan_init(0, RTW_MODE_PROMISC); - //rltk_wlan_start(0); - wifi_on(RTW_MODE_PROMISC); - break; - case IW_MODE_INFRA: //In STA mode - if(wext_get_ssid(WLAN0_NAME, ssid) > 0) - wifi_disconnect(); - } - } -} - -int wifi_restart_ap( - unsigned char *ssid, - rtw_security_t security_type, - unsigned char *password, - int ssid_len, - int password_len, - int channel) -{ - unsigned char idx = 0; -#if !defined(CONFIG_MBED_ENABLED) - ip_addr_t ipaddr; - ip_addr_t netmask; - ip_addr_t gw; - struct netif * pnetif = &xnetif[0]; -#endif -#ifdef CONFIG_CONCURRENT_MODE - rtw_wifi_setting_t setting; - int sta_linked = 0; -#endif - - if(rltk_wlan_running(WLAN1_IDX)){ - idx = 1; - } - - // stop dhcp server -#ifndef CONFIG_MBED_ENABLED - dhcps_deinit(); -#endif - -#ifdef CONFIG_CONCURRENT_MODE - if(idx > 0){ - sta_linked = wifi_get_setting(WLAN0_NAME, &setting); - wifi_off(); - rtw_msleep_os(20); - wifi_on(RTW_MODE_STA_AP); - } - else -#endif - { -#if !defined(CONFIG_MBED_ENABLED) - IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); - IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); - IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); - netif_set_addr(pnetif, &ipaddr, &netmask,&gw); -#endif - wifi_off(); - rtw_msleep_os(20); - wifi_on(RTW_MODE_AP); - } - // start ap - if(wifi_start_ap((char*)ssid, security_type, (char*)password, ssid_len, password_len, channel) < 0) { - WIFI_CONF_MSG("\n\rERROR: Operation failed!"); - return -1; - } - -#if (INCLUDE_uxTaskGetStackHighWaterMark == 1) - printf("\r\nWebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL)); -#endif -#ifdef CONFIG_CONCURRENT_MODE - // connect to ap if wlan0 was linked with ap - if(idx > 0 && sta_linked == 0){ -#if CONFIG_DHCP_CLIENT - int ret; -#endif - printf("\r\nAP: ssid=%s", (char*)setting.ssid); - printf("\r\nAP: security_type=%d", setting.security_type); - printf("\r\nAP: password=%s", (char*)setting.password); - printf("\r\nAP: key_idx =%d\n", setting.key_idx); -#if CONFIG_DHCP_CLIENT - ret = -#endif - wifi_connect((char*)setting.ssid, - setting.security_type, - (char*)setting.password, - strlen((char*)setting.ssid), - strlen((char*)setting.password), - setting.key_idx, - NULL); -#if CONFIG_DHCP_CLIENT - if(ret == RTW_SUCCESS) { - /* Start DHCPClient */ - LwIP_DHCP(0, DHCP_START); - } -#endif - } -#endif -#if (INCLUDE_uxTaskGetStackHighWaterMark == 1) - printf("\r\nWebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL)); -#endif -#if !defined(CONFIG_MBED_ENABLED) - // start dhcp server - dhcps_init(&xnetif[idx]); -#endif - return 0; -} - -#if CONFIG_AUTO_RECONNECT -struct task_struct g_wifi_auto_reconnect_task; - -extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int, int); - -struct wifi_autoreconnect_param { - rtw_security_t security_type; - char *ssid; - int ssid_len; - char *password; - int password_len; - int key_id; -}; - -static void wifi_autoreconnect_thread(void *param) -{ -#if !defined(CONFIG_MBED_ENABLED) && CONFIG_LWIP_LAYER - int ret = RTW_ERROR; -#endif - struct wifi_autoreconnect_param *reconnect_param = (struct wifi_autoreconnect_param *) param; - WIFI_CONF_MSG("\n\rauto reconnect ...\n"); -#if !defined(CONFIG_MBED_ENABLED) && CONFIG_LWIP_LAYER - ret = -#endif - wifi_connect(reconnect_param->ssid, - reconnect_param->security_type, - reconnect_param->password, - reconnect_param->ssid_len, - reconnect_param->password_len, - reconnect_param->key_id, - NULL); -#if !defined(CONFIG_MBED_ENABLED) && CONFIG_LWIP_LAYER - if(ret == RTW_SUCCESS) { -#if ATCMD_VER == ATVER_2 - if (dhcp_mode_sta == 2){ - struct netif * pnetif = &xnetif[0]; - LwIP_UseStaticIP(pnetif); - dhcps_init(pnetif); - } - else -#endif - { - LwIP_DHCP(0, DHCP_START); -#if LWIP_AUTOIP - uint8_t *ip = LwIP_GetIP(&xnetif[0]); - if((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) { - WIFI_CONF_MSG("\n\nIPv4 AUTOIP ..."); - LwIP_AUTOIP(&xnetif[0]); - } -#endif - } - } -#endif - rtw_delete_task(&g_wifi_auto_reconnect_task); -} - -void wifi_autoreconnect_hdl(rtw_security_t security_type, - char *ssid, int ssid_len, - char *password, int password_len, - int key_id) -{ - static struct wifi_autoreconnect_param param; - param.security_type = security_type; - param.ssid = ssid; - param.ssid_len = ssid_len; - param.password = password; - param.password_len = password_len; - param.key_id = key_id; - - if(!rtw_create_task(&g_wifi_auto_reconnect_task,"wifi_autoreconnect",512,TASK_PRORITY_IDEL+1,wifi_autoreconnect_thread, ¶m)) - WIFI_CONF_MSG("\n\rTCP ERROR: Create TCP server task failed."); -} - -int wifi_config_autoreconnect(__u8 mode, __u8 retry_times, __u16 timeout) -{ - p_wlan_autoreconnect_hdl = wifi_autoreconnect_hdl; - return wext_set_autoreconnect(WLAN0_NAME, mode, retry_times, timeout); -} - -int wifi_set_autoreconnect(__u8 mode) -{ - p_wlan_autoreconnect_hdl = wifi_autoreconnect_hdl; - return wifi_config_autoreconnect(mode, 3, 5);//default retry 3 times, timeout 5 seconds -} - -int wifi_get_autoreconnect(__u8 *mode) -{ - return wext_get_autoreconnect(WLAN0_NAME, mode); -} -#endif - -#ifdef CONFIG_CUSTOM_IE -/* - * Example for custom ie - * - * u8 test_1[] = {221, 2, 2, 2}; - * u8 test_2[] = {221, 2, 1, 1}; - * rtw_custom_ie_t buf[2] = {{test_1, PROBE_REQ}, - * {test_2, PROBE_RSP | BEACON}}; - * u8 buf_test2[] = {221, 2, 1, 3} ; - * rtw_custom_ie_t buf_update = {buf_test2, PROBE_REQ}; - * - * add ie list - * static void cmd_add_ie(int argc, char **argv) - * { - * wifi_add_custom_ie((void *)buf, 2); - * } - * - * update current ie - * static void cmd_update_ie(int argc, char **argv) - * { - * wifi_update_custom_ie(&buf_update, 2); - * } - * - * delete all ie - * static void cmd_del_ie(int argc, char **argv) - * { - * wifi_del_custom_ie(); - * } - */ - -int wifi_add_custom_ie(void *cus_ie, int ie_num) -{ - return wext_add_custom_ie(WLAN0_NAME, cus_ie, ie_num); -} - - -int wifi_update_custom_ie(void *cus_ie, int ie_index) -{ - return wext_update_custom_ie(WLAN0_NAME, cus_ie, ie_index); -} - -int wifi_del_custom_ie() -{ - return wext_del_custom_ie(WLAN0_NAME); -} - -#endif - -#ifdef CONFIG_PROMISC -extern void promisc_init_packet_filter(void); -extern int promisc_add_packet_filter(u8 filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_t rule); -extern int promisc_enable_packet_filter(u8 filter_id); -extern int promisc_disable_packet_filter(u8 filter_id); -extern int promisc_remove_packet_filter(u8 filter_id); -void wifi_init_packet_filter() -{ - promisc_init_packet_filter(); -} - -int wifi_add_packet_filter(unsigned char filter_id, rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_t rule) -{ - return promisc_add_packet_filter(filter_id, patt, rule); -} - -int wifi_enable_packet_filter(unsigned char filter_id) -{ - return promisc_enable_packet_filter(filter_id); -} - -int wifi_disable_packet_filter(unsigned char filter_id) -{ - return promisc_disable_packet_filter(filter_id); -} - -int wifi_remove_packet_filter(unsigned char filter_id) -{ - return promisc_remove_packet_filter(filter_id); -} -#endif - -#ifdef CONFIG_AP_MODE -int wifi_enable_forwarding(void) -{ - return wext_enable_forwarding(WLAN0_NAME); -} - -int wifi_disable_forwarding(void) -{ - return wext_disable_forwarding(WLAN0_NAME); -} -#endif - -/* API to set flag for concurrent mode wlan1 issue_deauth when channel switched by wlan0 - * usage: wifi_set_ch_deauth(0) -> wlan0 wifi_connect -> wifi_set_ch_deauth(1) - */ -#ifdef CONFIG_CONCURRENT_MODE -int wifi_set_ch_deauth(__u8 enable) -{ - return wext_set_ch_deauth(WLAN1_NAME, enable); -} -#endif - -void wifi_set_indicate_mgnt(int enable) -{ - wext_set_indicate_mgnt(enable); - return; -} - -//----------------------------------------------------------------------------// -#endif //#if CONFIG_WLAN - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.h index 21bd4fa97c..d858751333 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_conf.h @@ -12,26 +12,31 @@ * 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. - * - ****************************************************************************** - * @file wifi_conf.h - * @author - * @version - * @brief This file provides user interface for Wi-Fi station and AP mode configuration - * base on the functionalities provided by Realtek Wi-Fi driver. - ****************************************************************************** */ + +/** + ****************************************************************************** + * @file wifi_conf.h + * @author + * @version + * @brief This file provides user interface for Wi-Fi station and AP mode configuration + * base on the functionalities provided by Realtek Wi-Fi driver. + ****************************************************************************** + */ #ifndef __WIFI_API_H #define __WIFI_API_H -#include "osdep_service.h" -#include "wifi_constants.h" -#include "wifi_structures.h" -#include "wifi_util.h" -#include "wifi_ind.h" -#ifndef CONFIG_MBED_ENABLED +/** @addtogroup nic NIC + * @ingroup wlan + * @brief NIC functions + * @{ + */ + +#include "wifi_constants.h" +#include "wifi_structures.h" +#include "wifi_util.h" +#include "wifi_ind.h" #include -#endif #ifdef __cplusplus extern "C" { @@ -44,7 +49,15 @@ #define RTW_ENABLE_API_INFO #ifdef RTW_ENABLE_API_INFO - #define RTW_API_INFO(args) do {printf args;} while(0) +#if defined(CONFIG_MBED_ENABLED) + extern __u32 GlobalDebugEnable; + #define RTW_API_INFO(...) do {\ + if (GlobalDebugEnable) \ + printf(__VA_ARGS__);\ + }while(0) +#else + #define RTW_API_INFO printf +#endif #else #define RTW_API_INFO(args) #endif @@ -225,18 +238,6 @@ int wifi_is_up(rtw_interface_t interface); * RTW_STA_INTERFACE, RTW_AP_INTERFACE * @return RTW_SUCCESS : if the interface is ready to * transceive ethernet packets - * @return RTW_NOTFOUND : no AP with a matching SSID was - * found - * @return RTW_NOT_AUTHENTICATED: a matching AP was found but - * it won't let you - * authenticate. This can - * occur if this device is - * in the block list on the - * AP. - * @return RTW_NOT_KEYED: the device has authenticated and - * associated but has not completed - * the key exchange. This can occur - * if the passphrase is incorrect. * @return RTW_ERROR : if the interface is not ready to * transceive ethernet packets */ @@ -297,6 +298,14 @@ int wifi_set_txpower(int poweridx); */ int wifi_get_associated_client_list(void * client_list_buffer, unsigned short buffer_length); +/** + * @brief Get connected AP's BSSID + * @param[out] bssid : the location where the AP BSSID will be stored + * @return RTW_SUCCESS : if result was successfully get + * @return RTW_ERROR : if result was not successfully get + */ +int wifi_get_ap_bssid(unsigned char *bssid); + /** * @brief Get the SoftAP information. * @param[out] ap_info: The location where the AP info will be stored. @@ -314,6 +323,15 @@ int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security); */ int wifi_set_country(rtw_country_code_t country_code); +/** + * @brief retrieved sta mode MAX data rate. + * @param[out] inidata_rate: MAX data rate. + * @return RTW_SUCCESS: If the INIDATA_RATE is successfully retrieved. + * @return RTW_ERROR: If the INIDATA_RATE is not retrieved. + * note: inidata_rate = 2 * (data rate), you need inidata_rate/2.0 to get the real rate + */ +int wifi_get_sta_max_data_rate(__u8 * inidata_rate); + /** * @brief Retrieve the latest RSSI value. * @param[out] pRSSI: Points to the integer to store the RSSI value gotten from driver. @@ -362,11 +380,21 @@ int wifi_register_multicast_address(rtw_mac_t *mac); int wifi_unregister_multicast_address(rtw_mac_t *mac); /** - * @brief Disable the adaptivity mode. + * @brief Setup the adaptivity mode. + * You can replace this weak function by the same name funcation to setup adaptivity mode you want. * @param None * @return If the function succeeds, the return value is 0. */ -void wifi_set_mib(void); +_WEAK void wifi_set_mib(void); + +/** + * @brief Setup country code. + * You can replace this weak function by the same name funcation to setup country code you want. + * @param None + * @return If the function succeeds, the return value is 0. + */ +//----------------------------------------------------------------------------// +_WEAK void wifi_set_country_code(void); /** * @brief Enable Wi-Fi RF. @@ -620,19 +648,31 @@ Set the network mode according to the data rate its supported. */ int wifi_set_network_mode(rtw_network_mode_t mode); +/** + * @brief Get the network mode. + * Driver works in BGN mode in default after driver initialization. This function is used to + * get the current wireless network mode for station mode. + * @param[in] pmode: Network mode to get. + * @return RTW_SUCCESS or RTW_ERROR. + */ +int wifi_get_network_mode(rtw_network_mode_t *pmode); + /** * @brief Set the chip to start or stop the promiscuous mode. - * @param[in] enabled: enabled can be set 0, 1 and 2. if enabled is zero, disable the promisc, else enable the promisc. + * @param[in] enabled: enabled can be set 0, 1, 2, 3 and 4. if enabled is zero, disable the promisc, else enable the promisc. * - 0 means disable the promisc. - * - 1 means enable the promisc. - * - 2 means enable the promisc special for length is used. + * - 1 means enable the promisc special for all ethernet frames. + * - 2 means enable the promisc special for Broadcast/Multicast ethernet frames. + * - 3 means enable the promisc special for all 802.11 frames. + * - 4 means enable the promisc special for Broadcast/Multicast 802.11 frames. * @param[in] callback: the callback function which will * receive and process the netowork data. - * @param[in] len_used: specify if the the promisc length is used. - * If len_used set to 1, packet length will be saved and transferred to callback function. + * @param[in] len_used: specify if the the promisc data length is used. + * If len_used set to 1, packet(frame data) length will be saved and transferred to callback function. * * @return RTW_SUCCESS or RTW_ERROR * @note This function can be used to implement vendor specified simple configure. + * @note To fetch Ethernet frames, the len_used should be set to 1 */ int wifi_set_promisc(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used); @@ -726,7 +766,6 @@ int wifi_get_autoreconnect(__u8 *mode); */ int wifi_get_last_error(void); - #ifdef CONFIG_CUSTOM_IE #ifndef BIT #define BIT(x) ((__u32)1 << (x)) @@ -742,7 +781,7 @@ enum CUSTOM_IE_TYPE{ PROBE_RSP = BIT(1), BEACON = BIT(2), }; -typedef uint32_t rtw_custom_ie_type_t; +typedef __u32 rtw_custom_ie_type_t; #endif /* _CUSTOM_IE_TYPE_ */ /* ie format @@ -837,13 +876,79 @@ int wifi_disable_packet_filter(unsigned char filter_id); int wifi_remove_packet_filter(unsigned char filter_id); #endif +/** + * @brief Get antenna infomation. + * @param[in] antenna: Points to store the antenna value gotten from driver, 0: main, 1: aux. + * @return 0 if success, otherwise return -1. + */ +#ifdef CONFIG_ANTENNA_DIVERSITY +int wifi_get_antenna_info(unsigned char *antenna); +#endif // #ifdef CONFIG_ANTENNA_DIVERSITY + void wifi_set_indicate_mgnt(int enable); +/** + * @brief Get the information of MP driver + * @param[out] ability : 0x1 stand for mp driver, and 0x0 stand for normal driver + * @return RTW_SUCCESS + */ +int wifi_get_drv_ability(uint32_t *ability); + +/** + * @brief Set channel plan into flash/efuse, must reboot after setting channel plan + * @param[in] channel_plan : the value of channel plan, define in wifi_constants.h + * @return RTW_SUCCESS or RTW_ERROR + */ +int wifi_set_channel_plan(uint8_t channel_plan); + +/** + * @brief Get channel plan from calibration section + * @param[out] channel_plan : point to the value of channel plan, define in wifi_constants.h + * @return RTW_SUCCESS or RTW_ERROR + */ +int wifi_get_channel_plan(uint8_t *channel_plan); + +#ifdef CONFIG_AP_MODE +/** + * @brief Enable packets forwarding in ap mode + * @return RTW_SUCCESS + */ +int wifi_enable_forwarding(void); + +/** + * @brief Disable packets forwarding in ap mode + * @return RTW_SUCCESS + */ +int wifi_disable_forwarding(void); +#endif + +#ifdef CONFIG_CONCURRENT_MODE +/** + * @brief Set flag for concurrent mode wlan1 issue_deauth when channel switched by wlan0 + * usage: wifi_set_ch_deauth(0) -> wlan0 wifi_connect -> wifi_set_ch_deauth(1) + * @param[in] enable : 0 for disable and 1 for enable + * @return RTW_SUCCESS + */ +int wifi_set_ch_deauth(__u8 enable); +#endif + +///@name Ameba1 Only +///@{ +/** + * @brief enable AP sending QoS Null0 Data to poll Sta be alive + * @param[in] enabled: enabled can be set to 0,1. + * - 0 means enable. + * - 1 means disable. + * @return None + */ +void wifi_set_ap_polling_sta(__u8 enabled); +///@} #ifdef __cplusplus } #endif +/*\@}*/ + #endif // __WIFI_API_H //----------------------------------------------------------------------------// - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_ind.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_ind.c deleted file mode 100644 index e794ee81d4..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_ind.c +++ /dev/null @@ -1,274 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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. - * - ******************************************************************************/ - -#include "wifi/wifi_ind.h" -#include "wifi/wifi_conf.h" -#include "osdep_service.h" -#include "platform_stdlib.h" - -/****************************************************** - * Constants - ******************************************************/ - -#define WIFI_INDICATE_MSG 0 -#define WIFI_MANAGER_STACKSIZE 1300 -#define WIFI_MANAGER_PRIORITY (0) //Actual priority is 4 since calling rtw_create_task -#define WIFI_MANAGER_Q_SZ 8 - -#define WIFI_EVENT_MAX_ROW 3 -/****************************************************** - * Globals - ******************************************************/ - -static event_list_elem_t event_callback_list[WIFI_EVENT_MAX][WIFI_EVENT_MAX_ROW]; -#if CONFIG_WIFI_IND_USE_THREAD -static rtw_worker_thread_t wifi_worker_thread; -#endif - -//----------------------------------------------------------------------------// -#if CONFIG_WIFI_IND_USE_THREAD -static rtw_result_t rtw_send_event_to_worker(int event_cmd, char *buf, int buf_len, int flags) -{ - rtw_event_message_t message; - int i; - rtw_result_t ret = RTW_SUCCESS; - char *local_buf = NULL; - - if(event_cmd >= WIFI_EVENT_MAX) - return RTW_BADARG; - - for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){ - if(event_callback_list[event_cmd][i].handler == NULL) - continue; - - message.function = (event_handler_t)event_callback_list[event_cmd][i].handler; - message.buf_len = buf_len; - if(buf_len){ - local_buf = (char*)pvPortMalloc(buf_len); - if(local_buf == NULL) - return RTW_NOMEM; - memcpy(local_buf, buf, buf_len); - //printf("\n!!!!!Allocate %p(%d) for evcmd %d\n", local_buf, buf_len, event_cmd); - } - message.buf = local_buf; - message.flags = flags; - message.user_data = event_callback_list[event_cmd][i].handler_user_data; - - ret = rtw_push_to_xqueue(&wifi_worker_thread.event_queue, &message, 0); - if(ret != RTW_SUCCESS){ - if(local_buf){ - printf("\r\nrtw_send_event_to_worker: enqueue cmd %d failed and free %p(%d)\n", event_cmd, local_buf, buf_len); - vPortFree(local_buf); - } - break; - } - } - return ret; -} -#else -static rtw_result_t rtw_indicate_event_handle(int event_cmd, char *buf, int buf_len, int flags) -{ - rtw_event_handler_t handle = NULL; - int i; - - if(event_cmd >= WIFI_EVENT_MAX) - return RTW_BADARG; - - for(i = 0; i < WIFI_EVENT_MAX_ROW; i++){ - handle = event_callback_list[event_cmd][i].handler; - if(handle == NULL) - continue; - handle(buf, buf_len, flags, event_callback_list[event_cmd][i].handler_user_data); - } - - return RTW_SUCCESS; -} -#endif - -void wifi_indication( rtw_event_indicate_t event, char *buf, int buf_len, int flags) -{ - // - // If upper layer application triggers additional operations on receiving of wext_wlan_indicate, - // please strictly check current stack size usage (by using uxTaskGetStackHighWaterMark() ) - // , and tries not to share the same stack with wlan driver if remaining stack space is - // not available for the following operations. - // ex: using semaphore to notice another thread. - switch(event) - { - case WIFI_EVENT_DISCONNECT: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r %s():Disconnection indication received", __FUNCTION__); -#endif - break; - case WIFI_EVENT_CONNECT: - // For WPA/WPA2 mode, indication of connection does not mean data can be - // correctly transmitted or received. Data can be correctly transmitted or - // received only when 4-way handshake is done. - // Please check WIFI_EVENT_FOURWAY_HANDSHAKE_DONE event -#if(WIFI_INDICATE_MSG==1) - // Sample: return mac address - if(buf != NULL && buf_len == 6) - { - printf("\n\r%s():Connect indication received: %02x:%02x:%02x:%02x:%02x:%02x", __FUNCTION__, - buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]); - } -#endif - break; - case WIFI_EVENT_FOURWAY_HANDSHAKE_DONE: -#if(WIFI_INDICATE_MSG==1) - if(buf != NULL) - { - if(buf_len == strlen(IW_EXT_STR_FOURWAY_DONE)) - printf("\n\r%s():%s", __FUNCTION__, buf); - } -#endif - break; - case WIFI_EVENT_SCAN_RESULT_REPORT: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_SCAN_RESULT_REPORT\n", __func__); -#endif - break; - case WIFI_EVENT_SCAN_DONE: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_SCAN_DONE\n", __func__); -#endif - break; - case WIFI_EVENT_RECONNECTION_FAIL: -#if(WIFI_INDICATE_MSG==1) - if(buf != NULL){ - if(buf_len == strlen(IW_EXT_STR_RECONNECTION_FAIL)) - printf("\n\r%s", buf); - } -#endif - break; - case WIFI_EVENT_NO_NETWORK: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_NO_NETWORK\n", __func__); -#endif - break; - case WIFI_EVENT_RX_MGNT: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_RX_MGNT\n", __func__); -#endif - break; -#if CONFIG_ENABLE_P2P - case WIFI_EVENT_SEND_ACTION_DONE: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_SEND_ACTION_DONE\n", __func__); -#endif - break; -#endif //CONFIG_ENABLE_P2P - case WIFI_EVENT_STA_ASSOC: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_STA_ASSOC\n", __func__); -#endif - break; - case WIFI_EVENT_STA_DISASSOC: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_STA_DISASSOC\n", __func__); -#endif - break; -#ifdef CONFIG_WPS - case WIFI_EVENT_STA_WPS_START: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_STA_WPS_START\n", __func__); -#endif - break; - case WIFI_EVENT_WPS_FINISH: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_WPS_FINISH\n", __func__); -#endif - break; - case WIFI_EVENT_EAPOL_RECVD: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_EAPOL_RECVD\n", __func__); -#endif - break; -#endif - case WIFI_EVENT_BEACON_AFTER_DHCP: -#if(WIFI_INDICATE_MSG==1) - printf("\n\r%s(): WIFI_EVENT_BEACON_AFTER_DHCP\n", __func__); -#endif - break; - } - -#if CONFIG_INIC_EN - inic_indicate_event(event, buf, buf_len, flags); -#endif//CONFIG_INIC_EN - -#if CONFIG_WIFI_IND_USE_THREAD - rtw_send_event_to_worker(event, buf, buf_len, flags); -#else - rtw_indicate_event_handle(event, buf, buf_len, flags); -#endif -} - -void wifi_reg_event_handler(unsigned int event_cmds, rtw_event_handler_t handler_func, void *handler_user_data) -{ - int i = 0, j = 0; - if(event_cmds < WIFI_EVENT_MAX){ - for(i=0; i < WIFI_EVENT_MAX_ROW; i++){ - if(event_callback_list[event_cmds][i].handler == NULL){ - for(j=0; j - -// Add extra interfaces to make release sdk able to determine promisc API linking -void promisc_deinit(void *padapter) -{ -#ifdef CONFIG_PROMISC - _promisc_deinit(padapter); -#endif -} - -int promisc_recv_func(void *padapter, void *rframe) -{ - // Never reach here if not define CONFIG_PROMISC -#ifdef CONFIG_PROMISC - return _promisc_recv_func(padapter, rframe); -#else - return 0; -#endif -} - -int promisc_set(rtw_rcr_level_t enabled, void (*callback)(unsigned char*, unsigned int, void*), unsigned char len_used) -{ -#ifdef CONFIG_PROMISC - return _promisc_set(enabled, callback, len_used); -#else - return -1; -#endif -} - -unsigned char is_promisc_enabled(void) -{ -#ifdef CONFIG_PROMISC - return _is_promisc_enabled(); -#else - return 0; -#endif -} - -int promisc_get_fixed_channel(void *fixed_bssid, u8 *ssid, int *ssid_length) -{ -#ifdef CONFIG_PROMISC - return _promisc_get_fixed_channel(fixed_bssid, ssid, ssid_length); -#else - return 0; -#endif -} -// End of Add extra interfaces - -struct eth_frame { - struct eth_frame *prev; - struct eth_frame *next; - unsigned char da[6]; - unsigned char sa[6]; - unsigned int len; - unsigned char type; - signed char rssi; -}; - -#if CONFIG_INIC_CMD_RSP -#if defined(__IAR_SYSTEMS_ICC__) -#pragma pack(1) -#endif -struct inic_eth_frame { - unsigned char da[6]; - unsigned char sa[6]; - unsigned int len; - unsigned char type; -}; -#if defined(__IAR_SYSTEMS_ICC__) -#pragma pack() -#endif - -static struct inic_eth_frame *inic_frame, *inic_frame_tail = NULL; -static int inic_frame_cnt = 0; -#define MAX_INIC_FRAME_NUM 50 //maximum packets for each channel -extern void inic_c2h_msg(const char *atcmd, char status, char *msg, u16 msg_len); -#endif - -struct eth_buffer { - struct eth_frame *head; - struct eth_frame *tail; -}; - -static struct eth_buffer eth_buffer; - -#ifdef CONFIG_PROMISC -#define MAX_PACKET_FILTER_INFO 5 -#define FILTER_ID_INIT_VALUE 10 -rtw_packet_filter_info_t paff_array[MAX_PACKET_FILTER_INFO]={{0}, {0}, {0}, {0}, {0}}; -static u8 packet_filter_enable_num = 0; - -void promisc_init_packet_filter() -{ - int i = 0; - for(i=0; ioffset; - paff_array[i].patt.mask_size = patt->mask_size; - paff_array[i].patt.mask = rtw_malloc(patt->mask_size); - memcpy(paff_array[i].patt.mask, patt->mask, patt->mask_size); - paff_array[i].patt.pattern= rtw_malloc(patt->mask_size); - memcpy(paff_array[i].patt.pattern, patt->pattern, patt->mask_size); - - paff_array[i].rule = rule; - paff_array[i].enable = 0; - - return 0; -} - -int promisc_enable_packet_filter(u8 filter_id) -{ - int i = 0; - while(i < MAX_PACKET_FILTER_INFO){ - if(paff_array[i].filter_id == filter_id) - break; - i++; - } - - if(i == MAX_PACKET_FILTER_INFO) - return -1; - - paff_array[i].enable = 1; - packet_filter_enable_num++; - return 0; -} - -int promisc_disable_packet_filter(u8 filter_id) -{ - int i = 0; - while(i < MAX_PACKET_FILTER_INFO){ - if(paff_array[i].filter_id == filter_id) - break; - i++; - } - - if(i == MAX_PACKET_FILTER_INFO) - return -1; - - paff_array[i].enable = 0; - packet_filter_enable_num--; - return 0; -} - -int promisc_remove_packet_filter(u8 filter_id) -{ - int i = 0; - while(i < MAX_PACKET_FILTER_INFO){ - if(paff_array[i].filter_id == filter_id) - break; - i++; - } - - if(i == MAX_PACKET_FILTER_INFO) - return -1; - - paff_array[i].filter_id = FILTER_ID_INIT_VALUE; - paff_array[i].enable = 0; - paff_array[i].rule = 0; - if(paff_array[i].patt.mask){ - rtw_mfree((void *) paff_array[i].patt.mask, paff_array[i].patt.mask_size); - paff_array[i].patt.mask = NULL; - } - - if(paff_array[i].patt.pattern){ - rtw_mfree((void *) paff_array[i].patt.pattern, paff_array[i].patt.mask_size); - paff_array[i].patt.pattern = NULL; - } - paff_array[i].patt.mask_size = 0; - return 0; -} -#endif - -/* Make callback simple to prevent latency to wlan rx when promiscuous mode */ -static void promisc_callback(unsigned char *buf, unsigned int len, void* userdata) -{ - struct eth_frame *frame = (struct eth_frame *) rtw_malloc(sizeof(struct eth_frame)); - - if(frame) { - frame->prev = NULL; - frame->next = NULL; - memcpy(frame->da, buf, 6); - memcpy(frame->sa, buf+6, 6); - frame->len = len; - frame->rssi = ((ieee80211_frame_info_t *)userdata)->rssi; - _lock lock; - _irqL irqL; - rtw_enter_critical(&lock, &irqL); - - if(eth_buffer.tail) { - eth_buffer.tail->next = frame; - frame->prev = eth_buffer.tail; - eth_buffer.tail = frame; - } - else { - eth_buffer.head = frame; - eth_buffer.tail = frame; - } - - rtw_exit_critical(&lock, &irqL); - } -} - -struct eth_frame* retrieve_frame(void) -{ - struct eth_frame *frame = NULL; - - _lock lock; - _irqL irqL; - rtw_enter_critical(&lock, &irqL); - - if(eth_buffer.head) { - frame = eth_buffer.head; - - if(eth_buffer.head->next) { - eth_buffer.head = eth_buffer.head->next; - eth_buffer.head->prev = NULL; - } - else { - eth_buffer.head = NULL; - eth_buffer.tail = NULL; - } - } - - rtw_exit_critical(&lock, &irqL); - - return frame; -} - -static void promisc_test(int duration, unsigned char len_used) -{ - int ch; - unsigned int start_time; - struct eth_frame *frame; - eth_buffer.head = NULL; - eth_buffer.tail = NULL; - - wifi_enter_promisc_mode(); - wifi_set_promisc(RTW_PROMISC_ENABLE, promisc_callback, len_used); - - for(ch = 1; ch <= 13; ch ++) { - if(wifi_set_channel(ch) == 0) - printf("\n\n\rSwitch to channel(%d)", ch); - - start_time = rtw_get_current_time(); - - while(1) { - unsigned int current_time = rtw_get_current_time(); - - if(rtw_systime_to_ms(current_time - start_time) < (unsigned int)duration) { - frame = retrieve_frame(); - - if(frame) { - int i; - printf("\n\rDA:"); - for(i = 0; i < 6; i ++) - printf(" %02x", frame->da[i]); - printf(", SA:"); - for(i = 0; i < 6; i ++) - printf(" %02x", frame->sa[i]); - printf(", len=%d", frame->len); - printf(", RSSI=%d", frame->rssi); -#if CONFIG_INIC_CMD_RSP - if(inic_frame_tail){ - if(inic_frame_cnt < MAX_INIC_FRAME_NUM){ - memcpy(inic_frame_tail->da, frame->da, 6); - memcpy(inic_frame_tail->sa, frame->sa, 6); - inic_frame_tail->len = frame->len; - inic_frame_tail++; - inic_frame_cnt++; - } - } -#endif - rtw_mfree((void *) frame, sizeof(struct eth_frame)); - } - else - rtw_mdelay_os(1); //delay 1 tick - } - else - break; - } -#if CONFIG_INIC_CMD_RSP - if(inic_frame){ - inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt); - memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM); - inic_frame_tail = inic_frame; - inic_frame_cnt = 0; - rtw_msleep_os(10); - } -#endif - } - - wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0); - - while((frame = retrieve_frame()) != NULL) - rtw_mfree((void *) frame, sizeof(struct eth_frame)); -} - -static void promisc_callback_all(unsigned char *buf, unsigned int len, void* userdata) -{ - struct eth_frame *frame = (struct eth_frame *) rtw_malloc(sizeof(struct eth_frame)); - - if(frame) { - frame->prev = NULL; - frame->next = NULL; - memcpy(frame->da, buf+4, 6); - memcpy(frame->sa, buf+10, 6); - frame->len = len; - /* - * type is the first byte of Frame Control Field of 802.11 frame - * If the from/to ds information is needed, type could be reused as follows: - * frame->type = ((((ieee80211_frame_info_t *)userdata)->i_fc & 0x0100) == 0x0100) ? 2 : 1; - * 1: from ds; 2: to ds - */ - frame->type = *buf; - frame->rssi = ((ieee80211_frame_info_t *)userdata)->rssi; - - _lock lock; - _irqL irqL; - rtw_enter_critical(&lock, &irqL); - - - if(eth_buffer.tail) { - eth_buffer.tail->next = frame; - frame->prev = eth_buffer.tail; - eth_buffer.tail = frame; - } - else { - eth_buffer.head = frame; - eth_buffer.tail = frame; - } - - rtw_exit_critical(&lock, &irqL); - } -} -static void promisc_test_all(int duration, unsigned char len_used) -{ - int ch; - unsigned int start_time; - struct eth_frame *frame; - eth_buffer.head = NULL; - eth_buffer.tail = NULL; - - wifi_enter_promisc_mode(); - wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used); - - for(ch = 1; ch <= 13; ch ++) { - if(wifi_set_channel(ch) == 0) - printf("\n\n\rSwitch to channel(%d)", ch); - - start_time = rtw_get_current_time(); - - while(1) { - unsigned int current_time = rtw_get_current_time(); - - if(rtw_systime_to_ms(current_time - start_time) < (unsigned int)duration) { - frame = retrieve_frame(); - - if(frame) { - int i; - printf("\n\rTYPE: 0x%x, ", frame->type); - printf("DA:"); - for(i = 0; i < 6; i ++) - printf(" %02x", frame->da[i]); - printf(", SA:"); - for(i = 0; i < 6; i ++) - printf(" %02x", frame->sa[i]); - printf(", len=%d", frame->len); - printf(", RSSI=%d", frame->rssi); -#if CONFIG_INIC_CMD_RSP - if(inic_frame_tail){ - if(inic_frame_cnt < MAX_INIC_FRAME_NUM){ - memcpy(inic_frame_tail->da, frame->da, 6); - memcpy(inic_frame_tail->sa, frame->sa, 6); - inic_frame_tail->len = frame->len; - inic_frame_tail->type = frame->type; - inic_frame_tail++; - inic_frame_cnt++; - } - } -#endif - rtw_mfree((void *) frame, sizeof(struct eth_frame)); - } - else - rtw_mdelay_os(1); //delay 1 tick - } - else - break; - } -#if CONFIG_INIC_CMD_RSP - if(inic_frame){ - inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt); - memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM); - inic_frame_tail = inic_frame; - inic_frame_cnt = 0; - rtw_msleep_os(10); - } -#endif - } - - wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0); - - while((frame = retrieve_frame()) != NULL) - rtw_mfree((void *) frame, sizeof(struct eth_frame)); -} - -void cmd_promisc(int argc, char **argv) -{ - int duration; -#if CONFIG_INIC_CMD_RSP - inic_frame_tail = inic_frame = rtw_malloc(sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM); - if(inic_frame == NULL){ - inic_c2h_msg("ATWM", RTW_BUFFER_UNAVAILABLE_TEMPORARY, NULL, 0); - return; - } -#endif - #ifdef CONFIG_PROMISC - wifi_init_packet_filter(); - #endif - if((argc == 2) && ((duration = atoi(argv[1])) > 0)) - //promisc_test(duration, 0); - promisc_test_all(duration, 0); - else if((argc == 3) && ((duration = atoi(argv[1])) > 0) && (strcmp(argv[2], "with_len") == 0)) - promisc_test(duration, 1); - else - printf("\n\rUsage: %s DURATION_SECONDS [with_len]", argv[0]); -#if CONFIG_INIC_CMD_RSP - if(inic_frame) - rtw_mfree(inic_frame, sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM); - inic_frame_tail = NULL; - inic_frame_cnt = 0; -#endif -} -#endif //#if CONFIG_WLAN - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.c deleted file mode 100644 index e35fef0d0c..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.c +++ /dev/null @@ -1,1344 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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. - * - ******************************************************************************/ -#include -#include -#include -#include -#include - -extern u32 GlobalDebugEnable; -#define WIFI_UTIL_MSG(...) do {\ - if (GlobalDebugEnable) \ - printf("\r" __VA_ARGS__);\ -}while(0) - -int iw_ioctl(const char *ifname, unsigned long request, struct iwreq *pwrq) -{ - memcpy(pwrq->ifr_name, ifname, 5); - return rltk_wlan_control(request, (void *) pwrq); -} - -int wext_get_ssid(const char *ifname, __u8 *ssid) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.essid.pointer = ssid; - iwr.u.essid.length = 32; - - if (iw_ioctl(ifname, SIOCGIWESSID, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWESSID] ssid = NULL, not connected"); //do not use perror - ret = -1; - } else { - ret = iwr.u.essid.length; - if (ret > 32) - ret = 32; - /* Some drivers include nul termination in the SSID, so let's - * remove it here before further processing. WE-21 changes this - * to explicitly require the length _not_ to include nul - * termination. */ - if (ret > 0 && ssid[ret - 1] == '\0') - ret--; - ssid[ret] = '\0'; - } - - return ret; -} - -int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.essid.pointer = (void *) ssid; - iwr.u.essid.length = ssid_len; - iwr.u.essid.flags = (ssid_len != 0); - - if (iw_ioctl(ifname, SIOCSIWESSID, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWESSID] error"); - ret = -1; - } - - return ret; -} - -int wext_set_bssid(const char *ifname, const __u8 *bssid) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.ap_addr.sa_family = ARPHRD_ETHER; - memcpy(iwr.u.ap_addr.sa_data, bssid, ETH_ALEN); - - if(bssid[ETH_ALEN]=='#' && bssid[ETH_ALEN + 1]=='@'){ - memcpy(iwr.u.ap_addr.sa_data + ETH_ALEN, bssid + ETH_ALEN, 6); - } - - if (iw_ioctl(ifname, SIOCSIWAP, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWAP] error"); - ret = -1; - } - - return ret; -} - -int is_broadcast_ether_addr(const unsigned char *addr) -{ - return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; -} - -int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.param.flags = idx & IW_AUTH_INDEX; - iwr.u.param.value = value; - - if (iw_ioctl(ifname, SIOCSIWAUTH, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rWEXT: SIOCSIWAUTH(param %d value 0x%x) failed)", idx, value); - } - - return ret; -} - -int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len) -{ - struct iwreq iwr; - int ret = 0; - struct iw_encode_ext *ext; - - ext = (struct iw_encode_ext *) rtw_malloc(sizeof(struct iw_encode_ext) + key_len); - if (ext == NULL) - return -1; - else - memset(ext, 0, sizeof(struct iw_encode_ext) + key_len); - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.encoding.flags = key_idx + 1; - iwr.u.encoding.flags |= IW_ENCODE_TEMP; - iwr.u.encoding.pointer = ext; - iwr.u.encoding.length = sizeof(struct iw_encode_ext) + key_len; - - if (alg == IW_ENCODE_DISABLED) - iwr.u.encoding.flags |= IW_ENCODE_DISABLED; - - if (addr == NULL || is_broadcast_ether_addr(addr)) - ext->ext_flags |= IW_ENCODE_EXT_GROUP_KEY; - - if (set_tx) - ext->ext_flags |= IW_ENCODE_EXT_SET_TX_KEY; - - ext->addr.sa_family = ARPHRD_ETHER; - - if (addr) - memcpy(ext->addr.sa_data, addr, ETH_ALEN); - else - memset(ext->addr.sa_data, 0xff, ETH_ALEN); - - if (key && key_len) { - memcpy(ext->key, key, key_len); - ext->key_len = key_len; - } - - ext->alg = alg; - - if (seq && seq_len) { - ext->ext_flags |= IW_ENCODE_EXT_RX_SEQ_VALID; - memcpy(ext->rx_seq, seq, seq_len); - } - - if (iw_ioctl(ifname, SIOCSIWENCODEEXT, &iwr) < 0) { - ret = -2; - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWENCODEEXT] set key fail"); - } - - rtw_free(ext); - return ret; -} - -int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase) -{ - struct iwreq iwr; - int ret = 0; - struct iw_encode_ext *ext; - - ext = (struct iw_encode_ext *) rtw_malloc(sizeof(struct iw_encode_ext) + 16); - if (ext == NULL) - return -1; - else - memset(ext, 0, sizeof(struct iw_encode_ext) + 16); - - iwr.u.encoding.pointer = ext; - - if (iw_ioctl(ifname, SIOCGIWENCODEEXT, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWENCODEEXT] error"); - ret = -1; - } - else - { - *alg = ext->alg; - if(key_idx) - *key_idx = (__u8)iwr.u.encoding.flags; - if(passphrase) - memcpy(passphrase, ext->key, ext->key_len); - } - - if (ext != NULL) - rtw_free(ext); - - return ret; -} - -int wext_set_passphrase(const char *ifname, const __u8 *passphrase, __u16 passphrase_len) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.passphrase.pointer = (void *) passphrase; - iwr.u.passphrase.length = passphrase_len; - iwr.u.passphrase.flags = (passphrase_len != 0); - - if (iw_ioctl(ifname, SIOCSIWPRIVPASSPHRASE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWESSID+0x1f] error"); - ret = -1; - } - - return ret; -} - -int wext_get_passphrase(const char *ifname, __u8 *passphrase) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.passphrase.pointer = (void *) passphrase; - - if (iw_ioctl(ifname, SIOCGIWPRIVPASSPHRASE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWPRIVPASSPHRASE] error"); - ret = -1; - } - else { - ret = iwr.u.passphrase.length; - passphrase[ret] = '\0'; - } - - return ret; -} - -#if 0 -int wext_set_mac_address(const char *ifname, char * mac) -{ - char buf[13+17+1]; - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 13+17, "write_mac %s", mac); - return wext_private_command(ifname, buf, 0); -} - -int wext_get_mac_address(const char *ifname, char * mac) -{ - int ret = 0; - char buf[32]; - - rtw_memset(buf, 0, sizeof(buf)); - rtw_memcpy(buf, "read_mac", 8); - ret = wext_private_command_with_retval(ifname, buf, buf, 32); - strcpy(mac, buf); - return ret; -} -#endif - -int wext_enable_powersave(const char *ifname, __u8 ips_mode, __u8 lps_mode) -{ - struct iwreq iwr; - int ret = 0; - __u16 pindex = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("pm_set"); - - // Encode parameters as TLV (type, length, value) format - para = rtw_malloc( 7 + (1+1+1) + (1+1+1) ); - if(para == NULL) return -1; - - snprintf((char*)para, cmd_len, "pm_set"); - pindex = 7; - - para[pindex++] = 0; // type 0 for ips - para[pindex++] = 1; - para[pindex++] = ips_mode; - - para[pindex++] = 1; // type 1 for lps - para[pindex++] = 1; - para[pindex++] = lps_mode; - - iwr.u.data.pointer = para; - iwr.u.data.length = pindex; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error"); - ret = -1; - } - - rtw_free(para); - return ret; -} - -int wext_disable_powersave(const char *ifname) -{ - struct iwreq iwr; - int ret = 0; - __u16 pindex = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("pm_set"); - - // Encode parameters as TLV (type, length, value) format - para = rtw_malloc( 7 + (1+1+1) + (1+1+1) ); - if(para == NULL) return -1; - - snprintf((char*)para, cmd_len, "pm_set"); - pindex = 7; - - para[pindex++] = 0; // type 0 for ips - para[pindex++] = 1; - para[pindex++] = 0; // ips = 0 - - para[pindex++] = 1; // type 1 for lps - para[pindex++] = 1; - para[pindex++] = 0; // lps = 0 - - iwr.u.data.pointer = para; - iwr.u.data.length = pindex; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error"); - ret = -1; - } - - rtw_free(para); - return ret; - -} - -int wext_set_tdma_param(const char *ifname, __u8 slot_period, __u8 rfon_period_len_1, __u8 rfon_period_len_2, __u8 rfon_period_len_3) -{ - struct iwreq iwr; - int ret = 0; - __u16 pindex = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("pm_set"); - - // Encode parameters as TLV (type, length, value) format - para = rtw_malloc( 7 + (1+1+4) ); - - snprintf((char*)para, cmd_len, "pm_set"); - pindex = 7; - - para[pindex++] = 2; // type 2 tdma param - para[pindex++] = 4; - para[pindex++] = slot_period; - para[pindex++] = rfon_period_len_1; - para[pindex++] = rfon_period_len_2; - para[pindex++] = rfon_period_len_3; - - iwr.u.data.pointer = para; - iwr.u.data.length = pindex; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error"); - ret = -1; - } - - rtw_free(para); - return ret; -} - -int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim) -{ - struct iwreq iwr; - int ret = 0; - __u16 pindex = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("pm_set"); - - // Encode parameters as TLV (type, length, value) format - para = rtw_malloc( 7 + (1+1+1) ); - - snprintf((char*)para, cmd_len, "pm_set"); - pindex = 7; - - para[pindex++] = 3; // type 3 lps dtim - para[pindex++] = 1; - para[pindex++] = lps_dtim; - - iwr.u.data.pointer = para; - iwr.u.data.length = pindex; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error"); - ret = -1; - } - - rtw_free(para); - return ret; -} - -int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim) -{ - - struct iwreq iwr; - int ret = 0; - __u16 pindex = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("pm_get"); - - // Encode parameters as TLV (type, length, value) format - para = rtw_malloc( 7 + (1+1+1) ); - - snprintf((char*)para, cmd_len, "pm_get"); - pindex = 7; - - para[pindex++] = 3; // type 3 for lps dtim - para[pindex++] = 1; - para[pindex++] = 0; - - iwr.u.data.pointer = para; - iwr.u.data.length = pindex; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error"); - ret = -1; - goto exit; - } - - //get result at the beginning of iwr.u.data.pointer - if((para[0]==3)&&(para[1]==1)) - *lps_dtim = para[2]; - else - WIFI_UTIL_MSG("\n\r%s error", __func__); - -exit: - rtw_free(para); - - return ret; -} - -int wext_set_tos_value(const char *ifname, __u8 *tos_value) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = sizeof("set_tos_value"); - - memset(&iwr, 0, sizeof(iwr)); - - para = rtw_malloc(cmd_len + 4); - snprintf((char*)para, cmd_len, "set_tos_value"); - - if (*tos_value >= 0 && *tos_value <=32){ - *(para + cmd_len) = 0x4f; - *(para + cmd_len+1) = 0xa4; - *(para + cmd_len+2) = 0; - *(para + cmd_len+3) = 0; - } - else if(*tos_value > 32 && *tos_value <=96){ - *(para + cmd_len) = 0x2b; - *(para + cmd_len+1) = 0xa4; - *(para + cmd_len+2) = 0; - *(para + cmd_len+3) = 0; - } - else if(*tos_value > 96 && *tos_value <= 160){ - *(para + cmd_len) = 0x22; - *(para + cmd_len+1) = 0x43; - *(para + cmd_len+2) = 0x5e; - *(para + cmd_len+3) = 0; - } - else if(*tos_value > 160){ - *(para + cmd_len) = 0x22; - *(para + cmd_len+1) = 0x32; - *(para + cmd_len+2) = 0x2f; - *(para + cmd_len+3) = 0; - } - - iwr.u.data.pointer = para; - iwr.u.data.length = cmd_len + 4; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_set_tos_value():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - - rtw_free(para); - return ret; -} - -int wext_get_tx_power(const char *ifname, __u8 *poweridx) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = sizeof("get_tx_power"); - - memset(&iwr, 0, sizeof(iwr)); - //Tx power size : 20 Bytes - //CCK 1M,2M,5.5M,11M : 4 Bytes - //OFDM 6M, 9M, 12M, 18M, 24M, 36M 48M, 54M : 8 Bytes - //MCS 0~7 : 8 Bytes - para = rtw_malloc(cmd_len + 20); - snprintf((char*)para, cmd_len, "get_tx_power"); - - iwr.u.data.pointer = para; - iwr.u.data.length = cmd_len + 20; - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_get_tx_power():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - - memcpy(poweridx,(__u8 *)(iwr.u.data.pointer),20); - rtw_free(para); - return ret; -} - -#if 0 -int wext_set_txpower(const char *ifname, int poweridx) -{ - int ret = 0; - char buf[24]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 24, "txpower patha=%d", poweridx); - ret = wext_private_command(ifname, buf, 0); - - return ret; -} - -int wext_get_associated_client_list(const char *ifname, void * client_list_buffer, uint16_t buffer_length) -{ - int ret = 0; - char buf[25]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 25, "get_client_list %x", client_list_buffer); - ret = wext_private_command(ifname, buf, 0); - - return ret; -} - -int wext_get_ap_info(const char *ifname, rtw_bss_info_t * ap_info, rtw_security_t* security) -{ - int ret = 0; - char buf[24]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 24, "get_ap_info %x", ap_info); - ret = wext_private_command(ifname, buf, 0); - - snprintf(buf, 24, "get_security"); - ret = wext_private_command_with_retval(ifname, buf, buf, 24); - sscanf(buf, "%d", security); - - return ret; -} -#endif - -int wext_set_mode(const char *ifname, int mode) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.mode = mode; - if (iw_ioctl(ifname, SIOCSIWMODE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWMODE] error"); - ret = -1; - } - - return ret; -} - -int wext_get_mode(const char *ifname, int *mode) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - - if (iw_ioctl(ifname, SIOCGIWMODE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWMODE] error"); - ret = -1; - } - else - *mode = iwr.u.mode; - - return ret; -} - -int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.essid.pointer = (void *) ssid; - iwr.u.essid.length = ssid_len; - iwr.u.essid.flags = (ssid_len != 0); - - if (iw_ioctl(ifname, SIOCSIWPRIVAPESSID, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVAPESSID] error"); - ret = -1; - } - - return ret; -} - -int wext_set_country(const char *ifname, rtw_country_code_t country_code) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - - iwr.u.param.value = country_code; - - if (iw_ioctl(ifname, SIOCSIWPRIVCOUNTRY, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWPRIVCOUNTRY] error"); - ret = -1; - } - return ret; -} - -int wext_get_rssi(const char *ifname, int *rssi) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - - if (iw_ioctl(ifname, SIOCGIWSENS, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWSENS] error"); - ret = -1; - } else { - *rssi = 0 - iwr.u.sens.value; - } - return ret; -} - -int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config, __u8 length) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int i =0; - - memset(&iwr, 0, sizeof(iwr)); - //Format of para:function_name num_channel chan1... pscan_config1 ... - para = rtw_malloc((length + length + 1) + 12);//size:num_chan + num_time + length + function_name - if(para == NULL) return -1; - - //Cmd - snprintf((char*)para, 12, "PartialScan"); - //length - *(para+12) = length; - for(i = 0; i < length; i++){ - *(para + 13 + i)= *(ch + i); - *((__u16*) (para + 13 + length + i))= *(pscan_config + i); - } - - iwr.u.data.pointer = para; - iwr.u.data.length = (length + length + 1) + 12; - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_set_pscan_channel():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - rtw_free(para); - return ret; -} -int wext_set_channel(const char *ifname, __u8 ch) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.freq.m = 0; - iwr.u.freq.e = 0; - iwr.u.freq.i = ch; - - if (iw_ioctl(ifname, SIOCSIWFREQ, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWFREQ] error"); - ret = -1; - } - - return ret; -} - -int wext_get_channel(const char *ifname, __u8 *ch) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - - if (iw_ioctl(ifname, SIOCGIWFREQ, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWFREQ] error"); - ret = -1; - } - else - *ch = iwr.u.freq.i; - - return ret; -} - -int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac) -{ - int ret = 0; - char buf[32]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 32, "reg_multicast "MAC_FMT, MAC_ARG(mac->octet)); - ret = wext_private_command(ifname, buf, 0); - - return ret; -} - -int wext_unregister_multicast_address(const char *ifname, rtw_mac_t *mac) -{ - int ret = 0; - char buf[35]; - - rtw_memset(buf, 0, sizeof(buf)); - snprintf(buf, 35, "reg_multicast -d "MAC_FMT, MAC_ARG(mac->octet)); - ret = wext_private_command(ifname, buf, 0); - - return ret; -} - -int wext_set_scan(const char *ifname, char *buf, __u16 buf_len, __u16 flags) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); -#if 0 //for scan_with_ssid - if(buf) - memset(buf, 0, buf_len); -#endif - iwr.u.data.pointer = buf; - iwr.u.data.flags = flags; - iwr.u.data.length = buf_len; - if (iw_ioctl(ifname, SIOCSIWSCAN, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWSCAN] error"); - ret = -1; - } - return ret; -} - -int wext_get_scan(const char *ifname, char *buf, __u16 buf_len) -{ - struct iwreq iwr; - int ret = 0; - - iwr.u.data.pointer = buf; - iwr.u.data.length = buf_len; - if (iw_ioctl(ifname, SIOCGIWSCAN, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCGIWSCAN] error"); - ret = -1; - }else - ret = iwr.u.data.flags; - return ret; -} - -int wext_private_command_with_retval(const char *ifname, char *cmd, char *ret_buf, int ret_len) -{ - struct iwreq iwr; - int ret = 0; - size_t buf_size; - char *buf; - - buf_size = 128; - if(strlen(cmd) >= buf_size) - buf_size = strlen(cmd) + 1; // 1 : '\0' - buf = (char*)rtw_malloc(buf_size); - if(!buf){ - WIFI_UTIL_MSG("\n\rWEXT: Can't malloc memory"); - return -1; - } - memset(buf, 0, buf_size); - strcpy(buf, cmd); - memset(&iwr, 0, sizeof(iwr)); - iwr.u.data.pointer = buf; - iwr.u.data.length = buf_size; - iwr.u.data.flags = 0; - - if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret); - } - if(ret_buf){ - if(ret_len > iwr.u.data.length) - ret_len = iwr.u.data.length; - rtw_memcpy(ret_buf, (char *) iwr.u.data.pointer, ret_len); - } - rtw_free(buf); - return ret; -} - -int wext_private_command(const char *ifname, char *cmd, int show_msg) -{ - struct iwreq iwr; - int ret = 0; - size_t buf_size; - char *buf; - - u8 cmdname[17] = {0}; // IFNAMSIZ+1 - - sscanf(cmd, "%16s", cmdname); - if((strcmp((const char *)cmdname, "config_get") == 0) - || (strcmp((const char *)cmdname, "config_set") == 0) - || (strcmp((const char *)cmdname, "efuse_get") == 0) - || (strcmp((const char *)cmdname, "efuse_set") == 0) - || (strcmp((const char *)cmdname, "mp_psd") == 0)) - buf_size = 2600;//2600 for config_get rmap,0,512 (or realmap) - else - buf_size = 512; - - if (strlen(cmd) >= buf_size) - buf_size = strlen(cmd) + 1; // 1 : '\0' - buf = (char*)rtw_malloc(buf_size); - if (!buf) { - WIFI_UTIL_MSG("\n\rWEXT: Can't malloc memory"); - return -1; - } - memset(buf, 0, buf_size); - strcpy(buf, cmd); - memset(&iwr, 0, sizeof(iwr)); - iwr.u.data.pointer = buf; - iwr.u.data.length = buf_size; - iwr.u.data.flags = 0; - - if ((ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr)) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCDEVPRIVATE] error. ret=%d\n", ret); - } - if (show_msg && iwr.u.data.length) { - if(iwr.u.data.length > buf_size) - WIFI_UTIL_MSG("\n\rWEXT: Malloc memory is not enough"); - WIFI_UTIL_MSG("\n\rPrivate Message: %s", (char *) iwr.u.data.pointer); - } - rtw_free(buf); - return ret; -} - -void wext_wlan_indicate(unsigned int cmd, union iwreq_data *wrqu, char *extra) -{ - unsigned char null_mac[6] = {0}; - - switch(cmd) - { - case SIOCGIWAP: - if(wrqu->ap_addr.sa_family == ARPHRD_ETHER) - { - if(!memcmp(wrqu->ap_addr.sa_data, null_mac, sizeof(null_mac))) - wifi_indication(WIFI_EVENT_DISCONNECT, NULL, 0, 0); - else - wifi_indication(WIFI_EVENT_CONNECT, wrqu->ap_addr.sa_data, sizeof(null_mac), 0); - } - break; - - case IWEVCUSTOM: - if(extra) - { - if(!memcmp(IW_EXT_STR_FOURWAY_DONE, extra, strlen(IW_EXT_STR_FOURWAY_DONE))) - wifi_indication(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE, extra, strlen(IW_EXT_STR_FOURWAY_DONE), 0); - else if(!memcmp(IW_EXT_STR_RECONNECTION_FAIL, extra, strlen(IW_EXT_STR_RECONNECTION_FAIL))) - wifi_indication(WIFI_EVENT_RECONNECTION_FAIL, extra, strlen(IW_EXT_STR_RECONNECTION_FAIL), 0); - else if(!memcmp(IW_EVT_STR_NO_NETWORK, extra, strlen(IW_EVT_STR_NO_NETWORK))) - wifi_indication(WIFI_EVENT_NO_NETWORK, extra, strlen(IW_EVT_STR_NO_NETWORK), 0); -#if CONFIG_ENABLE_P2P || defined(CONFIG_AP_MODE) - else if(!memcmp(IW_EVT_STR_STA_ASSOC, extra, strlen(IW_EVT_STR_STA_ASSOC))) - wifi_indication(WIFI_EVENT_STA_ASSOC, wrqu->data.pointer, wrqu->data.length, 0); - else if(!memcmp(IW_EVT_STR_STA_DISASSOC, extra, strlen(IW_EVT_STR_STA_DISASSOC))) - wifi_indication(WIFI_EVENT_STA_DISASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0); - else if(!memcmp(IW_EVT_STR_SEND_ACTION_DONE, extra, strlen(IW_EVT_STR_SEND_ACTION_DONE))) - wifi_indication(WIFI_EVENT_SEND_ACTION_DONE, NULL, 0, wrqu->data.flags); -#endif - } - break; - case SIOCGIWSCAN: - if(wrqu->data.pointer == NULL) - wifi_indication(WIFI_EVENT_SCAN_DONE, NULL, 0, 0); - else - wifi_indication(WIFI_EVENT_SCAN_RESULT_REPORT, wrqu->data.pointer, wrqu->data.length, 0); - break; - case IWEVMGNTRECV: - wifi_indication(WIFI_EVENT_RX_MGNT, wrqu->data.pointer, wrqu->data.length, wrqu->data.flags); - break; -#ifdef REPORT_STA_EVENT - case IWEVREGISTERED: - if(wrqu->addr.sa_family == ARPHRD_ETHER) - wifi_indication(WIFI_EVENT_STA_ASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0); - break; - case IWEVEXPIRED: - if(wrqu->addr.sa_family == ARPHRD_ETHER) - wifi_indication(WIFI_EVENT_STA_DISASSOC, wrqu->addr.sa_data, sizeof(null_mac), 0); - break; -#endif - default: - break; - - } - -} - - -int wext_send_eapol(const char *ifname, char *buf, __u16 buf_len, __u16 flags) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.data.pointer = buf; - iwr.u.data.length = buf_len; - iwr.u.data.flags = flags; - if (iw_ioctl(ifname, SIOCSIWEAPOLSEND, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWEAPOLSEND] error"); - ret = -1; - } - return ret; -} - -int wext_send_mgnt(const char *ifname, char *buf, __u16 buf_len, __u16 flags) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.data.pointer = buf; - iwr.u.data.length = buf_len; - iwr.u.data.flags = flags; - if (iw_ioctl(ifname, SIOCSIWMGNTSEND, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWMGNTSEND] error"); - ret = -1; - } - return ret; -} - -int wext_set_gen_ie(const char *ifname, char *buf, __u16 buf_len, __u16 flags) -{ - struct iwreq iwr; - int ret = 0; - - memset(&iwr, 0, sizeof(iwr)); - iwr.u.data.pointer = buf; - iwr.u.data.length = buf_len; - iwr.u.data.flags = flags; - if (iw_ioctl(ifname, SIOCSIWGENIE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rioctl[SIOCSIWGENIE] error"); - ret = -1; - } - return ret; -} - -int wext_set_autoreconnect(const char *ifname, __u8 mode, __u8 retry_times, __u16 timeout) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("SetAutoRecnt"); - para = rtw_malloc((4) + cmd_len);//size:para_len+cmd_len - if(para == NULL) return -1; - - //Cmd - snprintf((char*)para, cmd_len, "SetAutoRecnt"); - //length - *(para+cmd_len) = mode; //para1 - *(para+cmd_len+1) = retry_times; //para2 - *(para+cmd_len+2) = timeout; //para3 - - iwr.u.data.pointer = para; - iwr.u.data.length = (4) + cmd_len; - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_set_autoreconnect():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - rtw_free(para); - return ret; -} - -int wext_get_autoreconnect(const char *ifname, __u8 *mode) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("GetAutoRecnt"); - para = rtw_malloc(cmd_len);//size:para_len+cmd_len - //Cmd - snprintf((char*)para, cmd_len, "GetAutoRecnt"); - //length - - iwr.u.data.pointer = para; - iwr.u.data.length = cmd_len; - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_get_autoreconnect():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - *mode = *(__u8 *)(iwr.u.data.pointer); - rtw_free(para); - return ret; -} - -int wext_get_drv_ability(const char *ifname, __u32 *ability) -{ - int ret = 0; - char * buf = (char *)rtw_zmalloc(33); - if(buf == NULL) return -1; - - snprintf(buf, 33, "get_drv_ability %x", (unsigned int)ability); - ret = wext_private_command(ifname, buf, 0); - - rtw_free(buf); - return ret; -} - -#ifdef CONFIG_CUSTOM_IE -int wext_add_custom_ie(const char *ifname, void *cus_ie, int ie_num) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - if(ie_num <= 0 || !cus_ie){ - WIFI_UTIL_MSG("\n\rwext_add_custom_ie():wrong parameter"); - ret = -1; - return ret; - } - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("SetCusIE"); - para = rtw_malloc((4)* 2 + cmd_len);//size:addr len+cmd_len - if(para == NULL) return -1; - - //Cmd - snprintf(para, cmd_len, "SetCusIE"); - //addr length - *(__u32 *)(para + cmd_len) = (__u32)cus_ie; //ie addr - //ie_num - *(__u32 *)(para + cmd_len + 4) = ie_num; //num of ie - - iwr.u.data.pointer = para; - iwr.u.data.length = (4)* 2 + cmd_len;// 2 input - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_add_custom_ie():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - rtw_free(para); - - return ret; -} - -int wext_update_custom_ie(const char *ifname, void * cus_ie, int ie_index) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - if(ie_index <= 0 || !cus_ie){ - WIFI_UTIL_MSG("\n\rwext_update_custom_ie():wrong parameter"); - ret = -1; - return ret; - } - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("UpdateIE"); - para = rtw_malloc((4)* 2 + cmd_len);//size:addr len+cmd_len - if(para == NULL) return -1; - - //Cmd - snprintf(para, cmd_len, "UpdateIE"); - //addr length - *(__u32 *)(para + cmd_len) = (__u32)cus_ie; //ie addr - //ie_index - *(__u32 *)(para + cmd_len + 4) = ie_index; //num of ie - - iwr.u.data.pointer = para; - iwr.u.data.length = (4)* 2 + cmd_len;// 2 input - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_update_custom_ie():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - rtw_free(para); - - return ret; - -} - -int wext_del_custom_ie(const char *ifname) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("DelIE"); - para = rtw_malloc(cmd_len);//size:addr len+cmd_len - //Cmd - snprintf(para, cmd_len, "DelIE"); - - iwr.u.data.pointer = para; - iwr.u.data.length = cmd_len; - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_del_custom_ie():ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - rtw_free(para); - - return ret; - - -} - -#endif - -#ifdef CONFIG_AP_MODE -int wext_enable_forwarding(const char *ifname) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("forwarding_set"); - para = rtw_malloc(cmd_len + 1); - if(para == NULL) return -1; - - // forwarding_set 1 - snprintf((char *) para, cmd_len, "forwarding_set"); - *(para + cmd_len) = '1'; - - iwr.u.essid.pointer = para; - iwr.u.essid.length = cmd_len + 1; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_enable_forwarding(): ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - - rtw_free(para); - return ret; -} - -int wext_disable_forwarding(const char *ifname) -{ - struct iwreq iwr; - int ret = 0; - __u8 *para = NULL; - int cmd_len = 0; - - memset(&iwr, 0, sizeof(iwr)); - cmd_len = sizeof("forwarding_set"); - para = rtw_malloc(cmd_len + 1); - if(para == NULL) return -1; - - // forwarding_set 0 - snprintf((char *) para, cmd_len, "forwarding_set"); - *(para + cmd_len) = '0'; - - iwr.u.essid.pointer = para; - iwr.u.essid.length = cmd_len + 1; - - if (iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr) < 0) { - WIFI_UTIL_MSG("\n\rwext_disable_forwarding(): ioctl[SIOCDEVPRIVATE] error"); - ret = -1; - } - - rtw_free(para); - return ret; - -} -#endif - -#ifdef CONFIG_CONCURRENT_MODE -int wext_set_ch_deauth(const char *ifname, __u8 enable) -{ - int ret = 0; - char * buf = (char *)rtw_zmalloc(16); - if(buf == NULL) return -1; - - snprintf(buf, 16, "SetChDeauth %d", enable); - ret = wext_private_command(ifname, buf, 0); - - rtw_free(buf); - return ret; -} -#endif - -int wext_set_adaptivity(rtw_adaptivity_mode_t adaptivity_mode) -{ - extern u8 rtw_adaptivity_en; - extern u8 rtw_adaptivity_mode; - - switch(adaptivity_mode){ - case RTW_ADAPTIVITY_NORMAL: - rtw_adaptivity_en = 1; // enable adaptivity - rtw_adaptivity_mode = RTW_ADAPTIVITY_MODE_NORMAL; - break; - case RTW_ADAPTIVITY_CARRIER_SENSE: - rtw_adaptivity_en = 1; // enable adaptivity - rtw_adaptivity_mode = RTW_ADAPTIVITY_MODE_CARRIER_SENSE; - break; - case RTW_ADAPTIVITY_DISABLE: - default: - rtw_adaptivity_en = 0; //disable adaptivity - break; - } - return 0; -} - -int wext_set_adaptivity_th_l2h_ini(__u8 l2h_threshold) -{ - extern s8 rtw_adaptivity_th_l2h_ini; - rtw_adaptivity_th_l2h_ini = (__s8)l2h_threshold; - return 0; -} - -int wext_get_auto_chl(const char *ifname, unsigned char *channel_set, unsigned char channel_num) -{ - int ret = -1; - int channel = 0; - wext_disable_powersave(ifname); - if((channel = rltk_get_auto_chl(ifname,channel_set,channel_num)) != 0 ) - ret = channel; - wext_enable_powersave(ifname, 1, 1); - return ret; -} - -int wext_set_sta_num(unsigned char ap_sta_num) -{ - return rltk_set_sta_num(ap_sta_num); -} - -int wext_del_station(const char *ifname, unsigned char* hwaddr) -{ - return rltk_del_station(ifname, hwaddr); -} - -extern struct list_head *mf_list_head; -int wext_init_mac_filter(void) -{ - if (mf_list_head != NULL){ - return -1; - } - - mf_list_head = (struct list_head *)rtw_malloc(sizeof(struct list_head)); - if(mf_list_head == NULL){ - WIFI_UTIL_MSG("\n\r[ERROR] %s : can't allocate mf_list_head",__func__); - return -1; - } - - INIT_LIST_HEAD(mf_list_head); - - return 0; -} - -int wext_deinit_mac_filter(void) -{ - if (mf_list_head == NULL){ - return -1; - } - struct list_head *iterator; - rtw_mac_filter_list_t *item; - list_for_each(iterator, mf_list_head) { - item = list_entry(iterator, rtw_mac_filter_list_t, node); - list_del(iterator); - rtw_free(item); - item = NULL; - iterator = mf_list_head; - } - - rtw_free(mf_list_head); - mf_list_head = NULL; - return 0; -} - -int wext_add_mac_filter(unsigned char* hwaddr) -{ - if(mf_list_head == NULL){ - return -1; - } - - rtw_mac_filter_list_t *mf_list_new; - mf_list_new = (rtw_mac_filter_list_t *)rtw_malloc(sizeof(rtw_mac_filter_list_t)); - if(mf_list_new == NULL){ - WIFI_UTIL_MSG("\n\r[ERROR] %s : can't allocate mf_list_new",__func__); - return -1; - } - memcpy(mf_list_new->mac_addr,hwaddr,6); - list_add(&(mf_list_new->node), mf_list_head); - - return 0; -} - -int wext_del_mac_filter(unsigned char* hwaddr) -{ - if (mf_list_head == NULL){ - return -1; - } - - struct list_head *iterator; - rtw_mac_filter_list_t *item; - list_for_each(iterator, mf_list_head) { - item = list_entry(iterator, rtw_mac_filter_list_t, node); - if (memcmp(item->mac_addr, hwaddr, 6) == 0) { - list_del(iterator); - rtw_free(item); - item = NULL; - return 0; - } - } - return -1; -} - -extern void rtw_set_indicate_mgnt(int enable); -void wext_set_indicate_mgnt(int enable) -{ - rtw_set_indicate_mgnt(enable); - return; -} - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.h index 3333fcf6bc..2a1e8da67b 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/api/wifi/wifi_util.h @@ -28,6 +28,8 @@ extern "C" { int wext_get_ssid(const char *ifname, __u8 *ssid); int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len); +int wext_set_bssid(const char *ifname, const __u8 *bssid); +int wext_get_bssid(const char *ifname, __u8 *bssid); int wext_set_auth_param(const char *ifname, __u16 idx, __u32 value); int wext_set_key_ext(const char *ifname, __u16 alg, const __u8 *addr, int key_idx, int set_tx, const __u8 *seq, __u16 seq_len, __u8 *key, __u16 key_len); int wext_get_enc_ext(const char *ifname, __u16 *alg, __u8 *key_idx, __u8 *passphrase); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/autoconf.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/autoconf.h index 3d69fff618..ddfed02ebe 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/autoconf.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/autoconf.h @@ -14,7 +14,6 @@ * limitations under the License. ******************************************************************************/ - #ifndef WLANCONFIG_H #define WLANCONFIG_H @@ -22,19 +21,42 @@ * Include user defined options first. Anything not defined in these files * will be set to standard values. Override anything you dont like! */ -#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) || defined(CONFIG_HARDWARE_8188F) #include "platform_opts.h" -#endif -#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) -#define CONFIG_PLATFORM_AMEBA_X +#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) || defined(CONFIG_PLATFORM_8721D) || defined(CONFIG_PLATFORM_8195BHP) +#ifndef CONFIG_PLATFORM_AMEBA_X +#define CONFIG_PLATFORM_AMEBA_X 1 #endif - -#if !defined(CONFIG_PLATFORM_AMEBA_X) -#define PLATFORM_FREERTOS 1 -#define CONFIG_GSPI_HCI #else -#define CONFIG_LX_HCI +#define CONFIG_PLATFORM_AMEBA_X 0 +#endif + +#if (CONFIG_PLATFORM_AMEBA_X == 1) + #if defined(CONFIG_PLATFORM_8195BHP) + #define CONFIG_AXI_HCI + #else + #define CONFIG_LX_HCI + #endif +#else + #define PLATFORM_FREERTOS 1 + #ifdef USE_SDIO_INTERFACE + #define CONFIG_SDIO_HCI + #else + #define CONFIG_GSPI_HCI +#endif +#endif // #if (CONFIG_PLATFORM_AMEBA_X == 1) + +#if defined(CONFIG_HARDWARE_8188F) || defined(CONFIG_HARDWARE_8192E)|| defined(CONFIG_HARDWARE_8723D) || defined(CONFIG_HARDWARE_8821C) || defined(CONFIG_PLATFORM_8195BHP) || defined(CONFIG_HARDWARE_8188E) || defined(CONFIG_PLATFORM_8721D) +#define CONFIG_FW_C2H_PKT +#define PHYDM_LINUX_CODING_STYLE 1 +#else +#define PHYDM_LINUX_CODING_STYLE 0 +#endif + +#if (PHYDM_LINUX_CODING_STYLE == 1) +#define PHYDM_NEW_INTERFACE 1 +#else +#define PHYDM_NEW_INTERFACE 0 #endif #ifndef CONFIG_INIC_EN @@ -51,20 +73,20 @@ #define RTW_NOTCH_FILTER 0 #define CONFIG_EMBEDDED_FWIMG #define CONFIG_PHY_SETTING_WITH_ODM -#if !defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 0) #define CONFIG_ODM_REFRESH_RAMASK #define HAL_MAC_ENABLE 1 #define HAL_BB_ENABLE 1 #define HAL_RF_ENABLE 1 #endif -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) /* Patch when dynamic mechanism is not ready */ //#define CONFIG_DM_PATCH #endif //#define CONFIG_DEBUG //#define CONFIG_DEBUG_RTL871X -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define CONFIG_MEM_MONITOR MEM_MONITOR_SIMPLE #define WLAN_INTF_DBG 0 //#define CONFIG_DEBUG_DYNAMIC @@ -81,15 +103,20 @@ //#define CONFIG_DONT_CARE_TP //#define CONFIG_HIGH_TP //#define CONFIG_MEMORY_ACCESS_ALIGNED -#ifndef PLATFORM_CMSIS_RTOS // unsupported feature #define CONFIG_POWER_SAVING -#endif #ifdef CONFIG_POWER_SAVING #define CONFIG_IPS #define CONFIG_LPS //#define CONFIG_LPS_LCLK +#if (CONFIG_PLATFORM_AMEBA_X == 0) +#ifdef CONFIG_LPS_LCLK + #define CONFIG_DETECT_CPWM_BY_POLLING + #define LPS_RPWM_WAIT_MS 300 +#endif +#else #define CONFIG_LPS_32K #define TDMA_POWER_SAVING +#endif #define CONFIG_WAIT_PS_ACK #endif @@ -105,8 +132,12 @@ #define RX_AMSDU 0 #endif -#if defined(CONFIG_PLATFORM_AMEBA_X) - #if !defined(CONFIG_PLATFORM_8711B) +#if defined(CONFIG_PLATFORM_8711B) + #define CONFIG_FW_C2H_PKT +#endif + +#if (CONFIG_PLATFORM_AMEBA_X == 1) + #if defined(CONFIG_PLATFORM_8195A) #define CONFIG_USE_TCM_HEAP 1 /* USE TCM HEAP */ #endif #define CONFIG_RECV_TASKLET_THREAD @@ -126,7 +157,7 @@ #error "CONFIG_ISR_THREAD_MODE_POLLING and CONFIG_ISR_THREAD_MODE_INTERRUPT are mutually exclusive. " #endif -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) /* CRC DMEM optimized mode consume 1k less SRM memory consumption */ #define CRC_IMPLEMENTATION_MODE CRC_IMPLEMENTATION_DMEM_OPTIMIZED #endif @@ -136,7 +167,7 @@ #define AES_IMPLEMENTATION_MODE AES_IMPLEMENTATION_DMEM_OPTIMIZED #define USE_SKB_AS_XMITBUF 1 -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define USE_XMIT_EXTBUFF 1 #else #define USE_XMIT_EXTBUFF 0 @@ -149,7 +180,7 @@ #define NOT_SUPPORT_VHT #define NOT_SUPPORT_40M #define NOT_SUPPORT_80M -#ifndef CONFIG_PLATFORM_8711B +#if defined(CONFIG_PLATFORM_8195A) #define NOT_SUPPORT_BBSWING #endif #define NOT_SUPPORT_OLD_CHANNEL_PLAN @@ -164,7 +195,7 @@ #define CONFIG_AUTO_RECONNECT 1 #define ENABLE_HWPDN_PIN #define SUPPORT_SCAN_BUF 1 -#if !defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 0) #define BE_I_CUT 1 #endif @@ -175,7 +206,6 @@ //#define CONFIG_WPA2_PREAUTH #define PSK_SUPPORT_TKIP 1 #endif -//#define AP_PSK_SUPPORT_TKIP /* For promiscuous mode */ #define CONFIG_PROMISC @@ -190,7 +220,7 @@ // for probe request with custom vendor specific IE #define CONFIG_CUSTOM_IE -#if !defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 0) /* For multicast */ #define CONFIG_MULTICAST #endif @@ -201,20 +231,11 @@ #if defined(CONFIG_PLATFORM_8195A) #define CONFIG_RUNTIME_PORT_SWITCH #endif - #if defined(CONFIG_HARDWARE_8188F) - #define NET_IF_NUM 2 - #else #define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN) + 1) - #endif #else - #if defined(CONFIG_HARDWARE_8188F) - #define NET_IF_NUM 1 - #else #define NET_IF_NUM ((CONFIG_ETHERNET) + (CONFIG_WLAN)) - #endif #endif - /****************** For EAP auth configurations *******************/ #define CONFIG_TLS 0 #define CONFIG_PEAP 0 @@ -222,15 +243,17 @@ // DO NOT change the below config of EAP #ifdef PRE_CONFIG_EAP +#undef CONFIG_TLS #define CONFIG_TLS 1 +#undef CONFIG_PEAP #define CONFIG_PEAP 1 +#undef CONFIG_TTLS #define CONFIG_TTLS 1 #endif // enable 1X code in lib_wlan as default (increase 380 bytes) -#ifndef PLATFORM_CMSIS_RTOS // unsupported feature #define CONFIG_EAP -#endif + #if CONFIG_TLS || CONFIG_PEAP || CONFIG_TTLS #define EAP_REMOVE_UNUSED_CODE 1 #endif @@ -268,7 +291,7 @@ #define CONFIG_AP_MODE extern unsigned char g_user_ap_sta_num; #define USER_AP_STA_NUM g_user_ap_sta_num -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define AP_STA_NUM 3 //2014/10/27 modify to 3 #define USE_DEDICATED_BCN_TX 0 #if USE_DEDICATED_BCN_TX @@ -284,7 +307,7 @@ extern unsigned int g_ap_sta_num; #define CONFIG_AP_POLLING_CLIENT_ALIVE #endif #define CONFIG_NATIVEAP_MLME -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define CONFIG_INTERRUPT_BASED_TXBCN #endif #ifdef CONFIG_INTERRUPT_BASED_TXBCN @@ -292,14 +315,14 @@ extern unsigned int g_ap_sta_num; #define CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR #endif // #define CONFIG_GK_REKEY -#if !defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 0) #define USE_DEDICATED_BCN_TX 1 #endif #if CONFIG_INIC_EN // #define REPORT_STA_EVENT //useless #endif #else -#if !defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 0) #define USE_DEDICATED_BCN_TX 0 #endif #endif @@ -308,14 +331,14 @@ extern unsigned int g_ap_sta_num; #error "If CONFIG_GK_REKEY when CONFIG_AP_MODE, need to CONFIG_MULTIPLE_WPA_STA" #endif -#if !defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 0) #if !defined(CONFIG_AP_MODE) && defined(CONFIG_CONCURRENT_MODE) #error "If CONFIG_CONCURRENT_MODEE, need to CONFIG_AP_MODE" #endif #endif /* For efuse or flash config */ -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define CONFIG_RW_PHYSICAL_EFUSE 0 // Mask efuse user blocks #define CONFIG_HIDE_PROTECT_EFUSE 1 #define CONFIG_ADAPTOR_INFO_CACHING_FLASH 1 @@ -333,7 +356,7 @@ extern unsigned int g_ap_sta_num; #define MP_DRIVER 1 #define CONFIG_MP_IWPRIV_SUPPORT // #define HAL_EFUSE_MEMORY - #if defined(CONFIG_PLATFORM_AMEBA_X) + #if (CONFIG_PLATFORM_AMEBA_X == 1) #define MP_REG_TEST #endif #else @@ -342,10 +365,19 @@ extern unsigned int g_ap_sta_num; //Control wifi mcu function #define CONFIG_LITTLE_WIFI_MCU_FUNCTION_THREAD #define CONFIG_ODM_REFRESH_RAMASK + //#define CONFIG_ANTENNA_DIVERSITY + //#define CONFIG_BT_COEXIST #endif #endif // #ifdef CONFIG_MP_INCLUDED -#if defined(CONFIG_PLATFORM_AMEBA_X) +#ifdef CONFIG_BT_COEXIST + #undef NOT_SUPPORT_BT + #define CONFIG_BT_MAILBOX + #define CONFIG_BT_EFUSE + //#define CONFIG_BT_TWO_ANTENNA +#endif + +#if (CONFIG_PLATFORM_AMEBA_X == 1) #if defined(CONFIG_PLATFORM_8195A) #undef CONFIG_RTL8195A #define CONFIG_RTL8195A @@ -363,9 +395,109 @@ extern unsigned int g_ap_sta_num; #define CONFIG_MOVE_PSK_TO_ROM #define CONFIG_WOWLAN #define CONFIG_TRAFFIC_PROTECT + #define CONFIG_FABVERSION_UMC 1 + #if (CONFIG_INIC_EN == 1) + #undef CONFIG_PROMISC + #undef CONFIG_WPS + #undef CONFIG_AP_MODE + #undef CONFIG_NATIVEAP_MLME + #undef CONFIG_INTERRUPT_BASED_TXBCN + #undef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR + #undef USE_DEDICATED_BCN_TX + //#undef SUPPORT_SCAN_BUF + #undef CONFIG_CONCURRENT_MODE + #undef CONFIG_AUTO_RECONNECT + #endif + #endif + #if defined(CONFIG_PLATFORM_8721D) + #ifndef CONFIG_RTL8721D + #define CONFIG_RTL8721D + #endif + #undef NOT_SUPPORT_5G + #undef CONFIG_ADAPTOR_INFO_CACHING_FLASH + #define CONFIG_ADAPTOR_INFO_CACHING_FLASH 0 + #define CONFIG_EFUSE_SEPARATE + #define CONFIG_WOWLAN + #define CONFIG_TRAFFIC_PROTECT + #define SUPPORT_5G_CHANNEL 1 + #define DBG_DM_DIG 0 // DebugComponents: bit0 + //#define CONFIG_SUPPORT_DYNAMIC_TXPWR //rtw_phydm_fill_desc_dpt todo + #if (CONFIG_INIC_EN == 1) + #undef CONFIG_PROMISC + #undef CONFIG_WPS + #undef CONFIG_AP_MODE + #undef CONFIG_NATIVEAP_MLME + #undef CONFIG_INTERRUPT_BASED_TXBCN + #undef CONFIG_INTERRUPT_BASED_TXBCN_BCN_OK_ERR + #undef USE_DEDICATED_BCN_TX + //#undef SUPPORT_SCAN_BUF + #undef CONFIG_CONCURRENT_MODE + #undef CONFIG_AUTO_RECONNECT + #endif + #endif + #if defined(CONFIG_PLATFORM_8195BHP) + #define CONFIG_RTL8195B + #undef CONFIG_EAP +// #undef CONFIG_ADAPTOR_INFO_CACHING_FLASH +// #define CONFIG_ADAPTOR_INFO_CACHING_FLASH 0 + #undef CHECK_FLASH_VALID_MASK + #define CHECK_FLASH_VALID_MASK 0 + #undef CHECK_EFUSE_VALID_MASK + #define CHECK_EFUSE_VALID_MASK 0 + #undef CONFIG_RW_PHYSICAL_EFUSE + #define CONFIG_RW_PHYSICAL_EFUSE 1 // efuse_get realraw + #undef NOT_SUPPORT_5G + #undef NOT_SUPPORT_VHT + #undef NOT_SUPPORT_40M + #undef NOT_SUPPORT_80M + #define CONFIG_BW_80 + #define CONFIG_80211AC_VHT + #undef CONFIG_IPS +// #define CONFIG_NO_FW + #define CONFIG_EX_FW_BIN + #define LOAD_FW_HEADER_FROM_DRIVER +// #define RTW_IQK_FW_OFFLOAD + #define CONFIG_PHY_CAPABILITY_QUERY + #define CONFIG_FW_C2H_PKT + #define RTK_AC_SUPPORT + #define PHYDM_NEW_INTERFACE 1 + #define CONFIG_ISR_THREAD_MODE_INTERRUPT /* Wlan IRQ Interrupt Mode*/ +// #define CONFIG_WLAN_RF_CNTL + #define SUPPORT_5G_CHANNEL 1 + #define SUPPORTABLITY_PHYDMLIZE 1 + #define CONFIG_DFS + #ifdef CONFIG_DFS + #define CONFIG_DFS_ACTION + #endif + #undef CONFIG_RF_GAIN_OFFSET + + #define DBG_DM_DIG 0 // DebugComponents: bit0 +// #define CONFIG_DEBUG + + #define RTW_HALMAC /* Use HALMAC architecture */ + #define RTW_HALMAC_MU_BF 0 + #define RTW_HALMAC_SU_BF 0 + #define RTW_HALMAC_BT_COEX 0 + #define RTW_HALMAC_DUMP_INFO 0 + #define RTW_HALMAC_TXBF 0 + #define RTW_HALMAC_FW_OFFLOAD 0 + #define RTW_HALMAC_PHYSICAL_EFUSE 0 + #define RTW_HALMAC_SIZE_OPTIMIZATION 1 + #define RTW_HALMAC_SDIO_CIA_READ 0 + #define RTW_HALMAC_LTE_COEX 0 + + #define CONFIG_MAC_LOOPBACK_DRIVER_RTL8195B 0 #endif #elif defined(CONFIG_HARDWARE_8188F) #define CONFIG_RTL8188F +#elif defined(CONFIG_HARDWARE_8192E) +#define CONFIG_RTL8192E +#elif defined(CONFIG_HARDWARE_8821C) +#define CONFIG_RTL8821C +#elif defined(CONFIG_HARDWARE_8723D) +#define CONFIG_RTL8723D +#elif defined(CONFIG_HARDWARE_8188E) +#define CONFIG_RTL8188E #else #define CONFIG_RTL8188E #endif @@ -386,37 +518,57 @@ extern unsigned int g_ap_sta_num; #define RTL8188E_SUPPORT 0 #define RTL8188F_SUPPORT 0 #define RTL8711B_SUPPORT 0 +#define RTL8721D_SUPPORT 0 +#define RTL8821C_SUPPORT 0 +#define RTL8723D_SUPPORT 0 #if defined(CONFIG_PLATFORM_8195A) #undef RTL8195A_SUPPORT #define RTL8195A_SUPPORT 1 #elif defined(CONFIG_PLATFORM_8711B) #undef RTL8711B_SUPPORT #define RTL8711B_SUPPORT 1 +#elif defined(CONFIG_PLATFORM_8721D) +#undef RTL8721D_SUPPORT +#define RTL8721D_SUPPORT 1 +#elif defined(CONFIG_PLATFORM_8195BHP) +#undef RTL8195B_SUPPORT +#define RTL8195B_SUPPORT 1 #elif defined(CONFIG_HARDWARE_8188F) #undef RTL8188F_SUPPORT #define RTL8188F_SUPPORT 1 +#elif defined(CONFIG_HARDWARE_8192E) +#undef RTL8192E_SUPPORT +#define RTL8192E_SUPPORT 1 +#elif defined(CONFIG_HARDWARE_8821C) +#undef RTL8821C_SUPPORT +#define RTL8821C_SUPPORT 1 +#elif defined(CONFIG_HARDWARE_8723D) +#undef RTL8723D_SUPPORT +#define RTL8723D_SUPPORT 1 +#elif defined(CONFIG_HARDWARE_8188E) +#undef RTL8188E_SUPPORT +#define RTL8188E_SUPPORT 1 #else #undef RTL8188E_SUPPORT #define RTL8188E_SUPPORT 1 #endif -#define TEST_CHIP_SUPPORT 0 - -#define RTL8188E_FOR_TEST_CHIP 0 -#define RTL8188E_FPGA_TRUE_PHY_VERIFICATION 0 - // for Debug message #define DBG 0 -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #if(DBG == 0) #define ROM_E_RTW_MSG 1 + #define ROM_F_RTW_MSG 1 +#if (CONFIG_INIC_EN == 0) && (PHYDM_LINUX_CODING_STYLE == 0) /* For DM debug*/ // BB #define DBG_RX_INFO 1 + #define DBG_DM_DIG 1 // DebugComponents: bit0 + #define DBG_DM_RA_MASK 1 // DebugComponents: bit1 + #define DBG_DM_ANT_DIV 1 // DebugComponents: bit6 #define DBG_TX_RATE 1 // DebugComponents: bit9 #define DBG_DM_RA 1 // DebugComponents: bit9 - #define DBG_DM_DIG 1 // DebugComponents: bit0 - #define DBG_DM_ADAPTIVITY 1 // DebugComponents: bit16 + #define DBG_DM_ADAPTIVITY 1 // DebugComponents: bit17 // RF #define DBG_PWR_TRACKING 1 // DebugComponents: bit24 #define DBG_RF_IQK 1 // DebugComponents: bit26 @@ -424,13 +576,23 @@ extern unsigned int g_ap_sta_num; #define DBG_PWR_INDEX 1 // DebugComponents: bit30 #endif #endif +#endif /* For DM support */ -#if defined(CONFIG_RTL8188F) +#if defined(CONFIG_RTL8188F) +#define RATE_ADAPTIVE_SUPPORT 0 +#elif defined(CONFIG_RTL8821C) +#define RATE_ADAPTIVE_SUPPORT 0 +#elif defined(CONFIG_RTL8192E) +#define RATE_ADAPTIVE_SUPPORT 0 +#elif defined(CONFIG_RTL8723D) #define RATE_ADAPTIVE_SUPPORT 0 #elif defined(CONFIG_PLATFORM_8711B) -#define RATE_ADAPTIVE_SUPPORT 1 +#define RATE_ADAPTIVE_SUPPORT 0 #define CONFIG_ODM_REFRESH_RAMASK +#elif defined(CONFIG_PLATFORM_8721D) +#define RATE_ADAPTIVE_SUPPORT 0 +//#define CONFIG_ODM_REFRESH_RAMASK #else #define RATE_ADAPTIVE_SUPPORT 1 #endif @@ -444,13 +606,13 @@ extern unsigned int g_ap_sta_num; #define CONFIG_RTW_ADAPTIVITY_DML 0 -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define CONFIG_POWER_TRAINING_WIL 0 // in RA #else #define POWER_BY_RATE_SUPPORT 0 #endif -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define RTL8195A_FOR_TEST_CHIP 0 //#define CONFIG_WIFI_TEST 1 @@ -466,7 +628,13 @@ extern unsigned int g_ap_sta_num; #endif #ifdef CONFIG_FPGA //Enable mac loopback for test mode (Ameba) - #define CONFIG_TWO_MAC_DRIVER // for test mode + #ifdef CONFIG_WIFI_NORMAL + #define CONFIG_TWO_MAC_DRIVER // for test mode + #else //CONFIG_WIFI_VERIFY + #define ENABLE_MAC_LB_FOR_TEST_MODE + #endif + + #define AP_PSK_SUPPORT_TKIP #endif #ifdef ENABLE_MAC_LB_FOR_TEST_MODE @@ -475,7 +643,7 @@ extern unsigned int g_ap_sta_num; #define CONFIG_LWIP_LAYER 0 #define CONFIG_WLAN_HAL_TEST #define CONFIG_WLAN_HAL_RX_TASK - #define CONFIG_MAC_LOOPBACK_DRIVER_RTL8711B 1 + #define CONFIG_MAC_LOOPBACK_DRIVER_AMEBA 1 #define HAL_MAC_ENABLE 1 #define CONFIG_TWO_MAC_TEST_MODE #define DISABLE_BB_RF 1 @@ -508,4 +676,27 @@ extern unsigned int g_ap_sta_num; #undef NOT_SUPPORT_40M #undef CONFIG_CONCURRENT_MODE #endif + +#if defined(CONFIG_HARDWARE_8821C) +#define FW_IQK +#define RTW_HALMAC +#define LOAD_FW_HEADER_FROM_DRIVER +#define RTW_HALMAC_SIZE_OPTIMIZATION 1 +//#define CONFIG_NO_FW +#ifdef NOT_SUPPORT_5G +#undef NOT_SUPPORT_5G +#define SUPPORT_5G_CHANNEL 1 +#endif +#endif + +#if defined(CONFIG_RTL8723D) +#define HAL_EFUSE_MEMORY +#endif + +#define CONFIG_DFS +//#define CONFIG_EMPTY_EFUSE_PG_ENABLE + +#define WLAN_WAPPER_VERSION 1 + #endif //WLANCONFIG_H + diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/drv_conf.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/drv_conf.h deleted file mode 100644 index db451a18f4..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/drv_conf.h +++ /dev/null @@ -1,104 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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 __DRV_CONF_H__ -#define __DRV_CONF_H__ - -#include "autoconf.h" -#if ((RTL8195A_SUPPORT==1) || (RTL8711B_SUPPORT==1)) -#include "platform_autoconf.h" -#endif - -#if defined (PLATFORM_LINUX) && defined (PLATFORM_WINDOWS) - -#error "Shall be Linux or Windows, but not both!\n" - -#endif - -//Older Android kernel doesn't has CONFIG_ANDROID defined, -//add this to force CONFIG_ANDROID defined -#ifdef CONFIG_PLATFORM_ANDROID -#define CONFIG_ANDROID -#endif - -#ifdef CONFIG_ANDROID -//Some Android build will restart the UI while non-printable ascii is passed -//between java and c/c++ layer (JNI). We force CONFIG_VALIDATE_SSID -//for Android here. If you are sure there is no risk on your system about this, -//mask this macro define to support non-printable ascii ssid. -//#define CONFIG_VALIDATE_SSID -#ifdef CONFIG_PLATFORM_ARM_SUNxI - #ifdef CONFIG_VALIDATE_SSID - #undef CONFIG_VALIDATE_SSID - #endif -#endif - -//Android expect dbm as the rx signal strength unit -#define CONFIG_SIGNAL_DISPLAY_DBM -#endif - -#if defined(CONFIG_HAS_EARLYSUSPEND) && defined (CONFIG_RESUME_IN_WORKQUEUE) - #warning "You have CONFIG_HAS_EARLYSUSPEND enabled in your system, we disable CONFIG_RESUME_IN_WORKQUEUE automatically" - #undef CONFIG_RESUME_IN_WORKQUEUE -#endif - -#if defined(CONFIG_ANDROID_POWER) && defined (CONFIG_RESUME_IN_WORKQUEUE) - #warning "You have CONFIG_ANDROID_POWER enabled in your system, we disable CONFIG_RESUME_IN_WORKQUEUE automatically" - #undef CONFIG_RESUME_IN_WORKQUEUE -#endif - -#ifdef CONFIG_RESUME_IN_WORKQUEUE //this can be removed, because there is no case for this... - #if !defined( CONFIG_WAKELOCK) && !defined(CONFIG_ANDROID_POWER) - #error "enable CONFIG_RESUME_IN_WORKQUEUE without CONFIG_WAKELOCK or CONFIG_ANDROID_POWER will suffer from the danger of wifi's unfunctionality..." - #error "If you still want to enable CONFIG_RESUME_IN_WORKQUEUE in this case, mask this preprossor checking and GOOD LUCK..." - #endif -#endif - -//About USB VENDOR REQ -#if defined(CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC) && !defined(CONFIG_USB_VENDOR_REQ_MUTEX) - #warning "define CONFIG_USB_VENDOR_REQ_MUTEX for CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC automatically" - #define CONFIG_USB_VENDOR_REQ_MUTEX -#endif -#if defined(CONFIG_VENDOR_REQ_RETRY) && !defined(CONFIG_USB_VENDOR_REQ_MUTEX) - #warning "define CONFIG_USB_VENDOR_REQ_MUTEX for CONFIG_VENDOR_REQ_RETRY automatically" - #define CONFIG_USB_VENDOR_REQ_MUTEX -#endif - -#ifndef CONFIG_RTW_ADAPTIVITY_EN - #define CONFIG_RTW_ADAPTIVITY_EN 0 -#endif - -#ifndef CONFIG_RTW_ADAPTIVITY_MODE - #define CONFIG_RTW_ADAPTIVITY_MODE 0 -#endif - -#ifndef CONFIG_RTW_ADAPTIVITY_DML - #define CONFIG_RTW_ADAPTIVITY_DML 0 -#endif - -#ifndef CONFIG_RTW_ADAPTIVITY_DC_BACKOFF - #define CONFIG_RTW_ADAPTIVITY_DC_BACKOFF 4 -#endif - -#ifndef CONFIG_RTW_NHM_EN - #define CONFIG_RTW_NHM_EN 0 -#endif - -//#include - -#endif // __DRV_CONF_H__ - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/rom_aes.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/rom_aes.h deleted file mode 100644 index 304da937be..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/rom_aes.h +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * - * mbed Microcontroller Library - * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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. - * - ****************************************************************************** - * - * This is ROM code section. - * - ******************************************************************************/ -#ifndef ROM_AES_H -#define ROM_AES_H - -typedef struct -{ - u32 erk[64]; /* encryption round keys */ - u32 drk[64]; /* decryption round keys */ - int nr; /* number of rounds */ -}aes_context; - - -#define AES_BLOCKSIZE8 8 -#define AES_BLK_SIZE 16 // # octets in an AES block -typedef union _aes_block // AES cipher block -{ - unsigned long x[AES_BLK_SIZE/4]; // access as 8-bit octets or 32-bit words - unsigned char b[AES_BLK_SIZE]; -}aes_block; - - -void AES_WRAP(unsigned char * plain, int plain_len, - unsigned char * iv, int iv_len, - unsigned char * kek, int kek_len, - unsigned char *cipher, unsigned short *cipher_len); - -void AES_UnWRAP(unsigned char * cipher, int cipher_len, - unsigned char * kek, int kek_len, - unsigned char * plain); - -#endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/rtw_debug.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/rtw_debug.h deleted file mode 100644 index 92fa79d7a5..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/rtw_debug.h +++ /dev/null @@ -1,453 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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 __RTW_DEBUG_H__ -#define __RTW_DEBUG_H__ - - -#define _drv_always_ 1 -#define _drv_emerg_ 2 -#define _drv_alert_ 3 -#define _drv_crit_ 4 -#define _drv_err_ 5 -#define _drv_warning_ 6 -#define _drv_notice_ 7 -#define _drv_info_ 8 -#define _drv_dump_ 9 -#define _drv_debug_ 10 - - -#define _module_rtl871x_xmit_c_ BIT(0) -#define _module_xmit_osdep_c_ BIT(1) -#define _module_rtl871x_recv_c_ BIT(2) -#define _module_recv_osdep_c_ BIT(3) -#define _module_rtl871x_mlme_c_ BIT(4) -#define _module_mlme_osdep_c_ BIT(5) -#define _module_rtl871x_sta_mgt_c_ BIT(6) -#define _module_rtl871x_cmd_c_ BIT(7) -#define _module_cmd_osdep_c_ BIT(8) -#define _module_rtl871x_io_c_ BIT(9) -#define _module_io_osdep_c_ BIT(10) -#define _module_os_intfs_c_ BIT(11) -#define _module_rtl871x_security_c_ BIT(12) -#define _module_rtl871x_eeprom_c_ BIT(13) -#define _module_hal_init_c_ BIT(14) -#define _module_hci_hal_init_c_ BIT(15) -#define _module_rtl871x_ioctl_c_ BIT(16) -#define _module_rtl871x_ioctl_set_c_ BIT(17) -#define _module_rtl871x_ioctl_query_c_ BIT(18) -#define _module_rtl871x_pwrctrl_c_ BIT(19) -#define _module_hci_intfs_c_ BIT(20) -#define _module_hci_ops_c_ BIT(21) -#define _module_osdep_service_c_ BIT(22) -#define _module_mp_ BIT(23) -#define _module_hci_ops_os_c_ BIT(24) -#define _module_rtl871x_ioctl_os_c BIT(25) -#define _module_rtl8712_cmd_c_ BIT(26) -#define _module_fwcmd_c_ BIT(27) -#define _module_rtl8192c_xmit_c_ BIT(28) -#define _module_hal_xmit_c_ BIT(28) -#define _module_efuse_ BIT(29) -#define _module_rtl8712_recv_c_ BIT(30) -#define _module_rtl8712_led_c_ BIT(31) - -#undef _MODULE_DEFINE_ - -#if defined _RTW_XMIT_C_ - #define _MODULE_DEFINE_ _module_rtl871x_xmit_c_ -#elif defined _XMIT_OSDEP_C_ - #define _MODULE_DEFINE_ _module_xmit_osdep_c_ -#elif defined _RTW_RECV_C_ - #define _MODULE_DEFINE_ _module_rtl871x_recv_c_ -#elif defined _RECV_OSDEP_C_ - #define _MODULE_DEFINE_ _module_recv_osdep_c_ -#elif defined _RTW_MLME_C_ - #define _MODULE_DEFINE_ _module_rtl871x_mlme_c_ -#elif defined _MLME_OSDEP_C_ - #define _MODULE_DEFINE_ _module_mlme_osdep_c_ -#elif defined _RTW_MLME_EXT_C_ - #define _MODULE_DEFINE_ 1 -#elif defined _RTW_STA_MGT_C_ - #define _MODULE_DEFINE_ _module_rtl871x_sta_mgt_c_ -#elif defined _RTW_CMD_C_ - #define _MODULE_DEFINE_ _module_rtl871x_cmd_c_ -#elif defined _CMD_OSDEP_C_ - #define _MODULE_DEFINE_ _module_cmd_osdep_c_ -#elif defined _RTW_IO_C_ - #define _MODULE_DEFINE_ _module_rtl871x_io_c_ -#elif defined _IO_OSDEP_C_ - #define _MODULE_DEFINE_ _module_io_osdep_c_ -#elif defined _OS_INTFS_C_ - #define _MODULE_DEFINE_ _module_os_intfs_c_ -#elif defined _RTW_SECURITY_C_ - #define _MODULE_DEFINE_ _module_rtl871x_security_c_ -#elif defined _RTW_EEPROM_C_ - #define _MODULE_DEFINE_ _module_rtl871x_eeprom_c_ -#elif defined _HAL_INTF_C_ - #define _MODULE_DEFINE_ _module_hal_init_c_ -#elif (defined _HCI_HAL_INIT_C_) || (defined _SDIO_HALINIT_C_) - #define _MODULE_DEFINE_ _module_hci_hal_init_c_ -#elif defined _RTL871X_IOCTL_C_ - #define _MODULE_DEFINE_ _module_rtl871x_ioctl_c_ -#elif defined _RTL871X_IOCTL_SET_C_ - #define _MODULE_DEFINE_ _module_rtl871x_ioctl_set_c_ -#elif defined _RTL871X_IOCTL_QUERY_C_ - #define _MODULE_DEFINE_ _module_rtl871x_ioctl_query_c_ -#elif defined _RTL871X_PWRCTRL_C_ - #define _MODULE_DEFINE_ _module_rtl871x_pwrctrl_c_ -#elif defined _RTW_PWRCTRL_C_ - #define _MODULE_DEFINE_ 1 -#elif defined _HCI_INTF_C_ - #define _MODULE_DEFINE_ _module_hci_intfs_c_ -#elif defined _HCI_OPS_C_ - #define _MODULE_DEFINE_ _module_hci_ops_c_ -#elif defined _SDIO_OPS_C_ - #define _MODULE_DEFINE_ 1 -#elif defined _OSDEP_HCI_INTF_C_ - #define _MODULE_DEFINE_ _module_hci_intfs_c_ -#elif defined _OSDEP_SERVICE_C_ - #define _MODULE_DEFINE_ _module_osdep_service_c_ -#elif defined _HCI_OPS_OS_C_ - #define _MODULE_DEFINE_ _module_hci_ops_os_c_ -#elif defined _RTL871X_IOCTL_LINUX_C_ - #define _MODULE_DEFINE_ _module_rtl871x_ioctl_os_c -#elif defined _RTL8712_CMD_C_ - #define _MODULE_DEFINE_ _module_rtl8712_cmd_c_ -#elif defined _RTL8192C_XMIT_C_ - #define _MODULE_DEFINE_ 1 -#elif defined _RTL8723AS_XMIT_C_ - #define _MODULE_DEFINE_ 1 -#elif defined _RTL8712_RECV_C_ - #define _MODULE_DEFINE_ _module_rtl8712_recv_c_ -#elif defined _RTL8192CU_RECV_C_ - #define _MODULE_DEFINE_ _module_rtl8712_recv_c_ -#elif defined _RTL871X_MLME_EXT_C_ - #define _MODULE_DEFINE_ _module_mlme_osdep_c_ -#elif defined _RTW_MP_C_ - #define _MODULE_DEFINE_ _module_mp_ -#elif defined _RTW_MP_IOCTL_C_ - #define _MODULE_DEFINE_ _module_mp_ -#elif defined _RTW_EFUSE_C_ - #define _MODULE_DEFINE_ _module_efuse_ -#endif - -#ifdef PLATFORM_OS_CE -extern void rtl871x_cedbg(const char *fmt, ...); -#endif - -#define RT_TRACE(_Comp, _Level, Fmt) do{}while(0) -#define _func_enter_ do{}while(0) -#define _func_exit_ do{}while(0) -#define RT_PRINT_DATA(_Comp, _Level, _TitleString, _HexData, _HexDataLen) do{}while(0) - -#ifdef PLATFORM_WINDOWS - #define DBG_871X do {} while(0) - #define MSG_8192C do {} while(0) - #define DBG_8192C do {} while(0) - #define DBG_871X_LEVEL do {} while(0) -#else - #define DBG_871X(x, ...) do {} while(0) - #define MSG_8192C(x, ...) do {} while(0) - #define DBG_8192C(x,...) do {} while(0) - #define DBG_871X_LEVEL(x,...) do {} while(0) -#endif - -#undef _dbgdump -#ifdef PLATFORM_WINDOWS - - #ifdef PLATFORM_OS_XP - #define _dbgdump DbgPrint - #elif defined PLATFORM_OS_CE - #define _dbgdump rtl871x_cedbg - #endif - -#elif defined PLATFORM_LINUX - #define _dbgdump printk -#elif defined PLATFORM_ECOS - #define _dbgdump diag_printf -#elif defined(PLATFORM_FREERTOS) || defined (PLATFORM_CMSIS_RTOS) - #define _dbgdump printf("\n\r"); printf -#elif defined PLATFORM_FREEBSD - #define _dbgdump printf -#endif - -#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) -#define DRIVER_PREFIX "RTL871X: " -#endif - -#define DEBUG_LEVEL (_drv_err_) -#if defined (_dbgdump) - #undef DBG_871X_LEVEL -#if defined (__ICCARM__) || defined (__CC_ARM) ||defined(__GNUC__)|| defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) - #define DBG_871X_LEVEL(level, ...) \ - do {\ - _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while(0) -#else - #define DBG_871X_LEVEL(level, fmt, arg...) \ - do {\ - if (level <= DEBUG_LEVEL) {\ - if (level <= _drv_err_ && level > _drv_always_) {\ - _dbgdump(DRIVER_PREFIX"ERROR " fmt, ##arg);\ - } \ - else {\ - _dbgdump(DRIVER_PREFIX fmt, ##arg);\ - } \ - }\ - }while(0) -#endif //#ifdef __CC_ARM -#endif - -#ifdef CONFIG_DEBUG -#if defined (_dbgdump) - #undef DBG_871X - #define DBG_871X(...) do {\ - _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while(0) - - #undef MSG_8192C - #define MSG_8192C(...) do {\ - _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while(0) - - #undef DBG_8192C - #define DBG_8192C(...) do {\ - _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while(0) -#endif -#endif /* CONFIG_DEBUG */ - -#ifdef CONFIG_DEBUG_RTL871X -#ifndef _RTL871X_DEBUG_C_ - extern u32 GlobalDebugLevel; - extern u64 GlobalDebugComponents; -#endif - -#if defined (_dbgdump) && defined (_MODULE_DEFINE_) - - #undef RT_TRACE - #define RT_TRACE(_Comp, _Level, Fmt)\ - do {\ - if((_Comp & GlobalDebugComponents) && (_Level <= GlobalDebugLevel)) {\ - _dbgdump("%s [0x%08x,%d]", DRIVER_PREFIX, (unsigned int)_Comp, _Level);\ - _dbgdump Fmt;\ - }\ - }while(0) - -#endif - - -#if defined (_dbgdump) - - #undef _func_enter_ - #define _func_enter_ \ - do { \ - if (GlobalDebugLevel >= _drv_debug_) \ - { \ - _dbgdump("\n %s : %s enters at %d\n", DRIVER_PREFIX, __FUNCTION__, __LINE__);\ - } \ - } while(0) - - #undef _func_exit_ - #define _func_exit_ \ - do { \ - if (GlobalDebugLevel >= _drv_debug_) \ - { \ - _dbgdump("\n %s : %s exits at %d\n", DRIVER_PREFIX, __FUNCTION__, __LINE__); \ - } \ - } while(0) - - #undef RT_PRINT_DATA - #define RT_PRINT_DATA(_Comp, _Level, _TitleString, _HexData, _HexDataLen) \ - if(((_Comp) & GlobalDebugComponents) && (_Level <= GlobalDebugLevel)) \ - { \ - int __i; \ - u8 *ptr = (u8 *)_HexData; \ - printf("\r\n%s", DRIVER_PREFIX); \ - printf(_TitleString "--------Len=%d\n\r", _HexDataLen); \ - for( __i=0; __i<(int)_HexDataLen; __i++ ) \ - { \ - printf("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" "); \ - if (((__i + 1) % 16) == 0) printf("\n\r"); \ - } \ - printf("\n\r"); \ - } -#endif -#endif /* CONFIG_DEBUG_RTL871X */ - - -#ifdef CONFIG_PROC_DEBUG - - int proc_get_drv_version(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_write_reg(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_write_reg(struct file *file, const char *buffer, - unsigned long count, void *data); - - int proc_get_read_reg(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_read_reg(struct file *file, const char *buffer, - unsigned long count, void *data); - - - int proc_get_fwstate(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_sec_info(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_mlmext_state(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_qos_option(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_ht_option(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_rf_info(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_ap_info(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_adapter_state(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_trx_info(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_mac_reg_dump1(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_mac_reg_dump2(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_mac_reg_dump3(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_bb_reg_dump1(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_bb_reg_dump2(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_bb_reg_dump3(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_rf_reg_dump1(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_rf_reg_dump2(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_rf_reg_dump3(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_rf_reg_dump4(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - -#ifdef CONFIG_AP_MODE - - int proc_get_all_sta_info(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - -#endif - -#ifdef DBG_MEMORY_LEAK - int proc_get_malloc_cnt(char *page, char **start, - off_t offset, int count, - int *eof, void *data); -#endif - -#ifdef CONFIG_FIND_BEST_CHANNEL - int proc_get_best_channel(char *page, char **start, - off_t offset, int count, - int *eof, void *data); -#endif - - int proc_get_rx_signal(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_rx_signal(struct file *file, const char *buffer, - unsigned long count, void *data); -#ifdef CONFIG_80211N_HT - int proc_get_cbw40_enable(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_cbw40_enable(struct file *file, const char *buffer, - unsigned long count, void *data); - - int proc_get_ampdu_enable(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_ampdu_enable(struct file *file, const char *buffer, - unsigned long count, void *data); - - int proc_get_rx_stbc(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_rx_stbc(struct file *file, const char *buffer, - unsigned long count, void *data); -#endif //CONFIG_80211N_HT - - int proc_get_two_path_rssi(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_get_rssi_disp(char *page, char **start, - off_t offset, int count, - int *eof, void *data); - - int proc_set_rssi_disp(struct file *file, const char *buffer, - unsigned long count, void *data); - - -#endif //CONFIG_PROC_DEBUG - -#endif //__RTW_DEBUG_H__ - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_constants.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_constants.h index 9952503417..a3416a1f3a 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_constants.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_constants.h @@ -23,6 +23,12 @@ #ifndef _WIFI_CONSTANTS_H #define _WIFI_CONSTANTS_H +/** @addtogroup nic NIC + * @ingroup wlan + * @brief NIC functions + * @{ + */ + #ifdef __cplusplus extern "C" { #endif @@ -46,7 +52,6 @@ extern "C" { #define RTW_MAX_PSK_LEN (64) #define RTW_MIN_PSK_LEN (8) - #define MCSSET_LEN 16 /** @@ -67,7 +72,6 @@ enum RTW_BUFFER_UNAVAILABLE_PERMANENT = 10, /**< Buffer unavailable permanently */ RTW_WPS_PBC_OVERLAP = 11, /**< WPS PBC overlap */ RTW_CONNECTION_LOST = 12, /**< Connection lost */ - RTW_ERROR = -1, /**< Generic Error */ RTW_BADARG = -2, /**< Bad Argument */ RTW_BADOPTION = -3, /**< Bad option */ @@ -129,12 +133,9 @@ enum { RTW_SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */ RTW_SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */ RTW_SECURITY_WPA_WPA2_MIXED = ( WPA_SECURITY | WPA2_SECURITY ), /**< WPA/WPA2 Security */ - RTW_SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */ RTW_SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */ - RTW_SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown. Do not pass this to the join function! */ - RTW_SECURITY_FORCE_32_BIT = 0x7fffffff /**< Exists only to force rtw_security_t type to 32 bits */ }; typedef unsigned long rtw_security_t; @@ -181,6 +182,7 @@ enum { RTW_COUNTRY_FCC2, // 0x2A RTW_COUNTRY_WORLD2, // 0x47 RTW_COUNTRY_MKK2, // 0x58 + RTW_COUNTRY_GLOBAL, // 0x41 /* SPECIAL */ RTW_COUNTRY_WORLD, // WORLD1 @@ -364,9 +366,7 @@ enum { RTW_COUNTRY_YT, RTW_COUNTRY_ZA, RTW_COUNTRY_ZW, - RTW_COUNTRY_MAX - }; typedef unsigned long rtw_country_code_t; @@ -401,6 +401,15 @@ enum { }; typedef unsigned long rtw_scan_mode_t; +/** + * @brief The enumeration lists the supported autoreconnect mode by WIFI driver. + */ +typedef enum{ + RTW_AUTORECONNECT_DISABLE, + RTW_AUTORECONNECT_FINITE, + RTW_AUTORECONNECT_INFINITE +} rtw_autoreconnect_mode_t; + /** * @brief The enumeration lists the status to describe the connection link. */ @@ -449,7 +458,8 @@ enum { RTW_WPS_TYPE_REKEY = 0x0003, RTW_WPS_TYPE_PUSHBUTTON = 0x0004, RTW_WPS_TYPE_REGISTRAR_SPECIFIED = 0x0005, - RTW_WPS_TYPE_NONE = 0x0006 + RTW_WPS_TYPE_NONE = 0x0006, + RTW_WPS_TYPE_WSC = 0x0007 }; typedef unsigned long rtw_wps_type_t; @@ -490,9 +500,20 @@ enum { RTW_PROMISC_ENABLE_1 = 2, /**< Fetch only B/M packets */ RTW_PROMISC_ENABLE_2 = 3, /**< Fetch all 802.11 packets*/ RTW_PROMISC_ENABLE_3 = 4, /**< Fetch only B/M 802.11 packets*/ + RTW_PROMISC_ENABLE_4 = 5, /**< Fetch all 802.11 packets & MIMO PLCP headers. Please note that the PLCP header would be struct rtw_rx_info_t defined in wifi_structures.h*/ }; typedef unsigned long rtw_rcr_level_t; +/** + * @brief The enumeration lists the promisc rx type. + */ +#if CONFIG_UNSUPPORT_PLCPHDR_RPT +enum { + RTW_RX_NORMAL = 0, /**< The supported 802.11 packet*/ + RTW_RX_UNSUPPORT = 1, /**< Unsupported 802.11 packet info */ +}; +typedef unsigned long rtw_rx_type_t; +#endif /** * @brief The enumeration lists the disconnect reasons. */ @@ -501,7 +522,8 @@ enum{ RTW_NONE_NETWORK = 1, RTW_CONNECT_FAIL = 2, RTW_WRONG_PASSWORD = 3 , - RTW_DHCP_FAIL = 4, + RTW_4WAY_HANDSHAKE_TIMEOUT = 4, + RTW_DHCP_FAIL = 5, RTW_UNKNOWN, }; typedef unsigned long rtw_connect_error_flag_t; @@ -535,10 +557,16 @@ enum _WIFI_EVENT_INDICATE{ WIFI_EVENT_EAPOL_RECVD = 13, WIFI_EVENT_NO_NETWORK = 14, WIFI_EVENT_BEACON_AFTER_DHCP = 15, + WIFI_EVENT_IP_CHANGED = 16, + WIFI_EVENT_ICV_ERROR = 17, + WIFI_EVENT_CHALLENGE_FAIL = 18, WIFI_EVENT_MAX, }; typedef unsigned long rtw_event_indicate_t; #ifdef __cplusplus } #endif + +/*\@}*/ + #endif /* _WIFI_CONSTANTS_H */ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_structures.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_structures.h index 81331d1bf7..c170940239 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_structures.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/include/wifi_structures.h @@ -12,7 +12,7 @@ * 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. - ****************************************************************************** + ****************************************************************************** * @file wifi_structures.h * @author * @version @@ -23,6 +23,12 @@ #ifndef _WIFI_STRUCTURES_H #define _WIFI_STRUCTURES_H +/** @addtogroup nic NIC + * @ingroup wlan + * @brief NIC functions + * @{ + */ + //#include #include "wifi_constants.h" #include "dlist.h" @@ -30,7 +36,7 @@ extern "C" { #endif -#if defined(__IAR_SYSTEMS_ICC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined (__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack(1) #endif @@ -41,11 +47,11 @@ typedef struct rtw_ssid { unsigned char len; /**< SSID length */ unsigned char val[33]; /**< SSID name (AP name) */ } rtw_ssid_t; -#if defined(__IAR_SYSTEMS_ICC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined (__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack() #endif -#if defined(__IAR_SYSTEMS_ICC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined (__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack(1) #endif @@ -55,14 +61,15 @@ typedef struct rtw_ssid { typedef struct rtw_mac { unsigned char octet[6]; /**< Unique 6-byte MAC address */ } rtw_mac_t; -#if defined(__IAR_SYSTEMS_ICC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined (__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack() #endif /** * @brief The structure is used to describe the setting about SSID, * security type, password and default channel, used to start AP mode. - * @note The data length of string pointed by ssid and password should not exceed 32. + * @note The data length of string pointed by ssid should not exceed 32, + * and the data length of string pointed by password should not exceed 64. */ typedef struct rtw_ap_info { rtw_ssid_t ssid; @@ -75,7 +82,8 @@ typedef struct rtw_ap_info { /** * @brief The structure is used to describe the station mode setting about SSID, * security type and password, used when connecting to an AP. - * @note The data length of string pointed by ssid and password should not exceed 32. + * @note The data length of string pointed by ssid should not exceed 32, + * and the data length of string pointed by password should not exceed 64. */ typedef struct rtw_network_info { rtw_ssid_t ssid; @@ -86,7 +94,7 @@ typedef struct rtw_network_info { int key_id; }rtw_network_info_t; -#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack(1) #endif @@ -103,7 +111,7 @@ typedef struct rtw_scan_result { unsigned int channel; /**< Radio channel that the AP beacon was received on */ rtw_802_11_band_t band; /**< Radio band */ } rtw_scan_result_t; -#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack() #endif @@ -117,7 +125,7 @@ typedef struct rtw_scan_handler_result { } rtw_scan_handler_result_t; -#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack(1) #endif @@ -132,7 +140,7 @@ typedef struct rtw_wifi_setting { unsigned char password[65]; unsigned char key_idx; }rtw_wifi_setting_t; -#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) +#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__) || defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) #pragma pack() #endif @@ -210,8 +218,33 @@ typedef struct ieee80211_frame_info{ unsigned char bssid[6]; unsigned char encrypt; signed char rssi; +#if CONFIG_UNSUPPORT_PLCPHDR_RPT + rtw_rx_type_t type; +#endif }ieee80211_frame_info_t; +#if CONFIG_UNSUPPORT_PLCPHDR_RPT +typedef struct rtw_rx_info { + uint16_t length; //length without FCS + uint8_t filter; // 2: 2T rate pkt; 3: LDPC pkt + signed char rssi; //-128~-1 +}rtw_rx_info_t; + +struct rtw_plcp_info { + struct rtw_plcp_info *prev; + struct rtw_plcp_info *next; + uint16_t length; //length without FCS + uint8_t filter; // 1: HT-20 pkt; 2: HT-40 and not LDPC pkt; 3: LDPC pkt + signed char rssi; //-128~-1 +}; + +struct rtw_rx_buffer { + struct rtw_plcp_info *head; + struct rtw_plcp_info *tail; +}; + +#endif + typedef struct { char filter_id; rtw_packet_filter_pattern_t patt; @@ -228,4 +261,6 @@ typedef struct rtw_mac_filter_list{ } #endif +/*\@}*/ + #endif /* _WIFI_STRUCTURES_H */ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/freertos/wrapper.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/freertos/wrapper.h index 5488ce78fc..5cc291d17c 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/freertos/wrapper.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/freertos/wrapper.h @@ -18,7 +18,6 @@ #ifndef __WRAPPER_H__ #define __WRAPPER_H__ - //----- ------------------------------------------------------------------ // Include Files //----- ------------------------------------------------------------------ @@ -26,11 +25,8 @@ #include #include "wireless.h" #include -#ifdef PLATFORM_FREERTOS -#include "freertos_service.h" -#elif defined(PLATFORM_CMSIS_RTOS) -#include "rtx_service.h" -#endif +#include "osdep_service.h" + #ifndef __LIST_H #warning "DLIST_NOT_DEFINE!!!!!!" //----- ------------------------------------------------------------------ @@ -50,7 +46,6 @@ // }; #define LIST_HEAD_INIT(name) { &(name), &(name) } - #define INIT_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev = (ptr); \ } while (0) @@ -302,7 +297,6 @@ static __inline__ void skb_queue_head_init(struct sk_buff_head *list) static __inline__ void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk) { struct sk_buff *prev, *next; - newsk->list = list; list->qlen++; next = (struct sk_buff *)list; @@ -333,7 +327,7 @@ static __inline__ void skb_queue_tail(struct sk_buff_head *list, struct sk_buff } static __inline__ void skb_assign_buf(struct sk_buff *skb, unsigned char *buf, unsigned int len) -{ +{ skb->head = buf; skb->data = buf; skb->tail = buf; @@ -452,5 +446,3 @@ void rtw_del_timer(_timer *ptimer); #endif //__WRAPPER_H__ - - diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c index aa036bca40..cae0c3ccce 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.c @@ -4,7 +4,7 @@ * 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 @@ -19,31 +19,24 @@ #include #include #include - #if !defined(CONFIG_MBED_ENABLED) #include #include #endif - #include #include - //----- ------------------------------------------------------------------ // External Reference //----- ------------------------------------------------------------------ #if (CONFIG_LWIP_LAYER == 1) -#if defined(CONFIG_MBED_ENABLED) - extern struct netif *xnetif[]; -#else - extern struct netif xnetif[]; //LWIP netif -#endif +extern struct netif xnetif[]; //LWIP netif #endif /** * rltk_wlan_set_netif_info - set netif hw address and register dev pointer to netif device * @idx_wlan: netif index - * 0 for STA only or SoftAP only or STA in STA+SoftAP concurrent mode, - * 1 for SoftAP in STA+SoftAP concurrent mode + * 0 for STA only or SoftAP only or STA in STA+SoftAP concurrent mode, + * 1 for SoftAP in STA+SoftAP concurrent mode * @dev: register netdev pointer to LWIP. Reserved. * @dev_addr: set netif hw address * @@ -53,11 +46,11 @@ void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr { #if (CONFIG_LWIP_LAYER == 1) #if defined(CONFIG_MBED_ENABLED) - //rtw_memcpy(xnetif[idx_wlan]->hwaddr, dev_addr, 6); - //set netif hwaddr later + //rtw_memcpy(xnetif[idx_wlan]->hwaddr, dev_addr, 6); + //set netif hwaddr later #else - rtw_memcpy(xnetif[idx_wlan].hwaddr, dev_addr, 6); - xnetif[idx_wlan].state = dev; + rtw_memcpy(xnetif[idx_wlan].hwaddr, dev_addr, 6); + xnetif[idx_wlan].state = dev; #endif #endif } @@ -74,45 +67,45 @@ void rltk_wlan_set_netif_info(int idx_wlan, void * dev, unsigned char * dev_addr int rltk_wlan_send(int idx, struct eth_drv_sg *sg_list, int sg_len, int total_len) { #if (CONFIG_LWIP_LAYER == 1) - struct eth_drv_sg *last_sg; - struct sk_buff *skb = NULL; - int ret = 0; + struct eth_drv_sg *last_sg; + struct sk_buff *skb = NULL; + int ret = 0; - if (idx == -1) { - DBG_ERR("netif is DOWN"); - return -1; - } - DBG_TRACE("%s is called", __FUNCTION__); + if(idx == -1){ + DBG_ERR("netif is DOWN"); + return -1; + } + DBG_TRACE("%s is called", __FUNCTION__); - save_and_cli(); - if (rltk_wlan_check_isup(idx)) { - rltk_wlan_tx_inc(idx); - } else { - DBG_ERR("netif is DOWN"); - restore_flags(); - return -1; - } - restore_flags(); + save_and_cli(); + if (rltk_wlan_check_isup(idx)) { + rltk_wlan_tx_inc(idx); + } else { + DBG_ERR("netif is DOWN"); + restore_flags(); + return -1; + } + restore_flags(); - skb = rltk_wlan_alloc_skb(total_len); - if (skb == NULL) { - //DBG_ERR("rltk_wlan_alloc_skb() for data len=%d failed!", total_len); - ret = -1; - goto exit; - } + skb = rltk_wlan_alloc_skb(total_len); + if (skb == NULL) { + //DBG_ERR("rltk_wlan_alloc_skb() for data len=%d failed!", total_len); + ret = -1; + goto exit; + } - for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) { - rtw_memcpy(skb->tail, (void *)(sg_list->buf), sg_list->len); - skb_put(skb, sg_list->len); - } + for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) { + rtw_memcpy(skb->tail, (void *)(sg_list->buf), sg_list->len); + skb_put(skb, sg_list->len); + } - rltk_wlan_send_skb(idx, skb); + rltk_wlan_send_skb(idx, skb); exit: - save_and_cli(); - rltk_wlan_tx_dec(idx); - restore_flags(); - return ret; + save_and_cli(); + rltk_wlan_tx_dec(idx); + restore_flags(); + return ret; #endif } @@ -127,128 +120,130 @@ exit: void rltk_wlan_recv(int idx, struct eth_drv_sg *sg_list, int sg_len) { #if (CONFIG_LWIP_LAYER == 1) - struct eth_drv_sg *last_sg; - struct sk_buff *skb; + struct eth_drv_sg *last_sg; + struct sk_buff *skb; + + DBG_TRACE("%s is called", __FUNCTION__); + if(idx == -1){ + DBG_ERR("skb is NULL"); + return; + } + skb = rltk_wlan_get_recv_skb(idx); + DBG_ASSERT(skb, "No pending rx skb"); - DBG_TRACE("%s is called", __FUNCTION__); - - if (!rltk_wlan_check_isup(idx)) { - return; - } - - if (idx == -1) { - DBG_ERR("skb is NULL"); - return; - } - - skb = rltk_wlan_get_recv_skb(idx); - DBG_ASSERT(skb, "No pending rx skb"); - - for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) { - if (sg_list->buf != 0) { - rtw_memcpy((void *)(sg_list->buf), skb->data, sg_list->len); - skb_pull(skb, sg_list->len); - } - } + for (last_sg = &sg_list[sg_len]; sg_list < last_sg; ++sg_list) { + if (sg_list->buf != 0) { + rtw_memcpy((void *)(sg_list->buf), skb->data, sg_list->len); + skb_pull(skb, sg_list->len); + } + } #endif } int netif_is_valid_IP(int idx, unsigned char *ip_dest) { -#if CONFIG_LWIP_LAYER == 1 #if defined(CONFIG_MBED_ENABLED) - return 1; + return 1; #else - struct netif *pnetif = &xnetif[idx]; +#if CONFIG_LWIP_LAYER == 1 + struct netif * pnetif = &xnetif[idx]; - ip_addr_t addr = { 0 }; + ip_addr_t addr = { 0 }; #ifdef CONFIG_MEMORY_ACCESS_ALIGNED - unsigned int temp; - memcpy(&temp, ip_dest, sizeof(unsigned int)); - u32_t *ip_dest_addr = &temp; + unsigned int temp; + memcpy(&temp, ip_dest, sizeof(unsigned int)); + u32_t *ip_dest_addr = &temp; #else - u32_t *ip_dest_addr = (u32_t*)ip_dest; + u32_t *ip_dest_addr = (u32_t*)ip_dest; #endif - addr.addr = *ip_dest_addr; - - if (pnetif->ip_addr.addr == 0) { - return 1; - } - if (ip_addr_ismulticast(&addr) || ip_addr_isbroadcast(&addr,pnetif)) { - return 1; - } - - //if(ip_addr_netcmp(&(pnetif->ip_addr), &addr, &(pnetif->netmask))) //addr&netmask - // return 1; - - if (ip_addr_cmp(&(pnetif->ip_addr),&addr)) { - return 1; - } - - DBG_TRACE("invalid IP: %d.%d.%d.%d ",ip_dest[0],ip_dest[1],ip_dest[2],ip_dest[3]); +#if LWIP_VERSION_MAJOR >= 2 + ip_addr_set_ip4_u32(&addr, *ip_dest_addr); +#else + addr.addr = *ip_dest_addr; #endif + +#if (LWIP_VERSION_MAJOR >= 2) + if((ip_addr_get_ip4_u32(netif_ip_addr4(pnetif))) == 0) + return 1; +#else + + if(pnetif->ip_addr.addr == 0) + return 1; +#endif + + if(ip_addr_ismulticast(&addr) || ip_addr_isbroadcast(&addr,pnetif)){ + return 1; + } + + //if(ip_addr_netcmp(&(pnetif->ip_addr), &addr, &(pnetif->netmask))) //addr&netmask + // return 1; + + if(ip_addr_cmp(&(pnetif->ip_addr),&addr)) + return 1; + + DBG_TRACE("invalid IP: %d.%d.%d.%d ",ip_dest[0],ip_dest[1],ip_dest[2],ip_dest[3]); +#endif #ifdef CONFIG_DONT_CARE_TP - if (pnetif->flags & NETIF_FLAG_IPSWITCH) { - return 1; - } - else + if(pnetif->flags & NETIF_FLAG_IPSWITCH) + return 1; + else #endif - return 0; + return 0; #endif } -#if defined(CONFIG_MBED_ENABLED) - -#else -int netif_get_idx(struct netif *pnetif) +#if !defined(CONFIG_MBED_ENABLED) +int netif_get_idx(struct netif* pnetif) { #if (CONFIG_LWIP_LAYER == 1) - int idx = pnetif - xnetif; + int idx = pnetif - xnetif; - switch (idx) { - case 0: - return 0; - case 1: - return 1; - default: - return -1; - } -#else - return -1; + switch(idx) { + case 0: + return 0; + case 1: + return 1; + default: + return -1; + } +#else + return -1; #endif } unsigned char *netif_get_hwaddr(int idx_wlan) { #if (CONFIG_LWIP_LAYER == 1) - return xnetif[idx_wlan].hwaddr; + return xnetif[idx_wlan].hwaddr; #else - return NULL; + return NULL; #endif } #endif +#if defined(CONFIG_MBED_ENABLED) emac_callback emac_callback_func = NULL; void *emac_callback_data = NULL; -void set_callback_func(emac_callback p, void *data) { - emac_callback_func = p; - emac_callback_data = data; +void set_callback_func(emac_callback p, void *data) +{ + emac_callback_func = p; + emac_callback_data = data; } +#endif void netif_rx(int idx, unsigned int len) { #if (CONFIG_LWIP_LAYER == 1) #if defined(CONFIG_MBED_ENABLED) - emac_callback_func(emac_callback_data, NULL, len); + emac_callback_func(emac_callback_data, NULL, len); #else - ethernetif_recv(&xnetif[idx], len); + ethernetif_recv(&xnetif[idx], len); #endif #endif - #if (CONFIG_INIC_EN == 1) - inic_netif_rx(idx, len); + inic_netif_rx(idx, len); #endif } @@ -257,7 +252,7 @@ void netif_post_sleep_processing(void) #if (CONFIG_LWIP_LAYER == 1) #if defined(CONFIG_MBED_ENABLED) #else - lwip_POST_SLEEP_PROCESSING(); //For FreeRTOS tickless to enable Lwip ARP timer when leaving IPS - Alex Fang + lwip_POST_SLEEP_PROCESSING(); //For FreeRTOS tickless to enable Lwip ARP timer when leaving IPS - Alex Fang #endif #endif } @@ -267,7 +262,7 @@ void netif_pre_sleep_processing(void) #if (CONFIG_LWIP_LAYER == 1) #if defined(CONFIG_MBED_ENABLED) #else - lwip_PRE_SLEEP_PROCESSING(); + lwip_PRE_SLEEP_PROCESSING(); #endif #endif } @@ -275,9 +270,9 @@ void netif_pre_sleep_processing(void) #ifdef CONFIG_WOWLAN unsigned char *rltk_wlan_get_ip(int idx){ #if (CONFIG_LWIP_LAYER == 1) - return LwIP_GetIP(&xnetif[idx]); + return LwIP_GetIP(&xnetif[idx]); #else - return NULL; + return NULL; #endif } #endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.h index 5892aba322..5268dde776 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/lwip_intf.h @@ -30,12 +30,12 @@ struct netif; //----- ------------------------------------------------------------------ #if defined(CONFIG_MBED_ENABLED) struct eth_drv_sg { - unsigned int buf; - unsigned int len; + unsigned int buf; + unsigned int len; }; -#define MAX_ETH_DRV_SG 32 -#define MAX_ETH_MSG 1540 +#define MAX_ETH_DRV_SG 32 +#define MAX_ETH_MSG 1540 #else #include "ethernetif.h" // moved to ethernetif.h by jimmy 12/2/2015 #endif @@ -52,8 +52,11 @@ void rltk_wlan_send_skb(int idx, struct sk_buff *skb); //struct sk_buff as defin int rltk_wlan_send(int idx, struct eth_drv_sg *sg_list, int sg_len, int total_len); void rltk_wlan_recv(int idx, struct eth_drv_sg *sg_list, int sg_len); unsigned char rltk_wlan_running(unsigned char idx); // interface is up. 0: interface is down + +#if defined(CONFIG_MBED_ENABLED) typedef void (*emac_callback)(void *param, struct netif *netif, unsigned int len); void set_callback_func(emac_callback p, void *data); +#endif //----- ------------------------------------------------------------------ // Network Interface provided @@ -73,7 +76,6 @@ extern void lwip_PRE_SLEEP_PROCESSING(void); extern void lwip_POST_SLEEP_PROCESSING(void); #endif //CONFIG_LWIP_LAYER == 1 - #ifdef CONFIG_WOWLAN extern unsigned char *rltk_wlan_get_ip(int idx); #endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wireless.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wireless.h index ac988590c4..4d664c8a6e 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wireless.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wireless.h @@ -1206,4 +1206,6 @@ struct iw_event #define IW_EVT_STR_STA_DISASSOC "STA Disassoc" #define IW_EVT_STR_SEND_ACTION_DONE "Send Action Done" #define IW_EVT_STR_NO_NETWORK "No Assoc Network After Scan Done" +#define IW_EVT_STR_ICV_ERROR "ICV Eror" +#define IW_EVT_STR_CHALLENGE_FAIL "Auth Challenge Fail" #endif /* _LINUX_WIRELESS_H */ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wlan_intf.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wlan_intf.h index b586e0cc36..081447f699 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wlan_intf.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/common/drivers/wlan/realtek/src/osdep/wlan_intf.h @@ -67,6 +67,7 @@ int rltk_wlan_rf_on(void); int rltk_wlan_rf_off(void); int rltk_wlan_check_bus(void); int rltk_wlan_wireless_mode(unsigned char mode); +int rltk_wlan_get_wireless_mode(unsigned char *pmode); int rltk_wlan_set_wps_phase(unsigned char is_trigger_wps); int rtw_ps_enable(int enable); int rltk_wlan_is_connected_to_ap(void); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.c index f3d91ac100..ae92b9dc02 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.c @@ -1,48 +1,46 @@ /* RTX includes */ #include "osdep_service.h" #include "tcm_heap.h" -//#include -//#include //malloc(), free() -//#include //memcpy(), memcmp(), memset() #include "platform_stdlib.h" -//#include -//#include + /********************* os depended utilities ********************/ #ifndef USE_MUTEX_FOR_SPINLOCK #define USE_MUTEX_FOR_SPINLOCK 1 #endif -#define USE_HEAP_INFO 0 - -#define OS_TICK OS_TICK_FREQ -#define OS_TICK_RATE_MS (1000/OS_TICK) //----------------------------------------------------------------------- // Private Variables //----------------------------------------------------------------------- static unsigned long CriticalNesting = 0; +#if CONFIG_USE_TCM_HEAP +void *tcm_heap_malloc(int size); +#endif +#if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK) +extern int rtw_if_wifi_thread(char *name); +#endif //----------------------------------------------------------------------- // Misc Function //----------------------------------------------------------------------- int osdep_print = 0; #define _func_enter_ do{\ - if(osdep_print)\ - printf("enter %s\r\n", __FUNCTION__);\ - }while(0) + if(osdep_print)\ + printf("enter %s\r\n", __FUNCTION__);\ + }while(0) #define _func_exit_ do{\ - if(osdep_print)\ - printf("exit %s\r\n", __FUNCTION__);\ - }while(0) + if(osdep_print)\ + printf("exit %s\r\n", __FUNCTION__);\ + }while(0) void save_and_cli() { _func_enter_; #if defined(__CC_ARM) - rtw_enter_critical(NULL, NULL); + rtw_enter_critical(NULL, NULL); #else - __disable_irq(); + __disable_irq(); #endif _func_exit_; } @@ -51,9 +49,9 @@ void restore_flags() { _func_enter_; #if defined(__CC_ARM) - rtw_exit_critical(NULL, NULL); + rtw_exit_critical(NULL, NULL); #else - __enable_irq(); + __enable_irq(); #endif _func_exit_; } @@ -61,76 +59,66 @@ _func_exit_; void cli() { _func_enter_; - __disable_irq(); + __disable_irq(); _func_exit_; } /* Not needed on 64bit architectures */ static unsigned int __div64_32(u64 *n, unsigned int base) { - u64 rem = *n; - u64 b = base; - u64 res, d = 1; - unsigned int high = rem >> 32; + u64 rem = *n; + u64 b = base; + u64 res, d = 1; + unsigned int high = rem >> 32; _func_enter_; - /* Reduce the thing a bit first */ - res = 0; - if (high >= base) { - high /= base; - res = (u64) high << 32; - rem -= (u64) (high * base) << 32; - } + /* Reduce the thing a bit first */ + res = 0; + if (high >= base) { + high /= base; + res = (u64) high << 32; + rem -= (u64) (high * base) << 32; + } - while ((u64)b > 0 && b < rem) { - b = b+b; - d = d+d; - } + while ((u64)b > 0 && b < rem) { + b = b+b; + d = d+d; + } - do { - if (rem >= b) { - rem -= b; - res += d; - } - b >>= 1; - d >>= 1; - } while (d); + do { + if (rem >= b) { + rem -= b; + res += d; + } + b >>= 1; + d >>= 1; + } while (d); _func_exit_; - *n = res; - return rem; + *n = res; + return rem; } /********************* os depended service ********************/ -#if USE_HEAP_INFO -static uint32_t osFreeBytesRemaining=0x400; -#endif + static void _rtx2_memset(void *pbuf, int c, u32 sz); u8* _rtx2_malloc(u32 sz) { _func_enter_; - void *p = NULL; - p = (void *)malloc(sz); - if(p != NULL){ -#if USE_HEAP_INFO - osFreeBytesRemaining-=sz; -#endif - } + void *p = NULL; + p = (void *)malloc(sz); _func_exit_; - return p; + return p; } u8* _rtx2_zmalloc(u32 sz) { _func_enter_; - u8 *pbuf = _rtx2_malloc(sz); + u8 *pbuf = _rtx2_malloc(sz); - if (pbuf != NULL){ -#if USE_HEAP_INFO - osFreeBytesRemaining-=sz; -#endif - _rtx2_memset(pbuf, 0, sz); - } + if (pbuf != NULL){ + _rtx2_memset(pbuf, 0, sz); + } _func_exit_; - return pbuf; + return pbuf; } static void (*ext_free)( void *p ) = NULL; @@ -138,265 +126,279 @@ static uint32_t ext_upper = 0; static uint32_t ext_lower = 0; void rtw_set_mfree_ext( void (*free)( void *p ), uint32_t upper, uint32_t lower ) { - ext_free = free; - ext_upper = upper; - ext_lower = lower; + ext_free = free; + ext_upper = upper; + ext_lower = lower; } void _rtx2_mfree(u8 *pbuf, u32 sz) { _func_enter_; - if( ((uint32_t)pbuf >= ext_lower) && ((uint32_t)pbuf < ext_upper) ){ - if(ext_free) - ext_free(pbuf); - }else{ - free(pbuf); - } -#if USE_HEAP_INFO - osFreeBytesRemaining+=sz; -#endif + if( ((uint32_t)pbuf >= ext_lower) && ((uint32_t)pbuf < ext_upper) ){ + if(ext_free) + ext_free(pbuf); + }else{ + free(pbuf); + } } static void _rtx2_memcpy(void* dst, void* src, u32 sz) { _func_enter_; - memcpy(dst, src, sz); + memcpy(dst, src, sz); _func_exit_; } static int _rtx2_memcmp(void *dst, void *src, u32 sz) { _func_enter_; -//under Linux/GNU/GLibc, the return value of memcmp for two same mem. chunk is 0 - if (!(memcmp(dst, src, sz))) - return _SUCCESS; + //under Linux/GNU/GLibc, the return value of memcmp for two same mem. chunk is 0 + if (!(memcmp(dst, src, sz))) + return _SUCCESS; _func_exit_; - return _FAIL; + return _FAIL; } static void _rtx2_memset(void *pbuf, int c, u32 sz) { _func_enter_; - memset(pbuf, c, sz); + memset(pbuf, c, sz); _func_exit_; } static void _rtx2_init_sema(_sema *sem, int init_val) { _func_enter_; - rtx_sema_t *p_sem = (rtx_sema_t *)_rtx2_zmalloc(sizeof(rtx_sema_t)); - if(p_sem == NULL){ - goto err_exit; - } - *sem = (_sema)p_sem; - _rtx2_memset(&p_sem->data, 0, sizeof(p_sem->data)); - p_sem->attr.cb_mem = &p_sem->data; - p_sem->attr.cb_size = sizeof(p_sem->data); - p_sem->id = osSemaphoreNew(osRtxSemaphoreTokenLimit, (uint32_t)init_val, &p_sem->attr); - if (p_sem->id == NULL){ - goto err_exit; - } + rtx_sema_t *p_sem = (rtx_sema_t *)_rtx2_zmalloc(sizeof(rtx_sema_t)); + if(p_sem == NULL){ + goto err_exit; + } + *sem = (_sema)p_sem; + _rtx2_memset(&p_sem->data, 0, sizeof(p_sem->data)); + p_sem->attr.cb_mem = &p_sem->data; + p_sem->attr.cb_size = sizeof(p_sem->data); + p_sem->id = osSemaphoreNew(osRtxSemaphoreTokenLimit, (uint32_t)init_val, &p_sem->attr); + if (p_sem->id == NULL){ + goto err_exit; + } _func_exit_; - return; + return; err_exit: - DBG_ERR("error"); - if(p_sem) - _rtx2_mfree((u8 *)p_sem, sizeof(rtx_sema_t)); - *sem = NULL; - return; + DBG_ERR("error"); + if(p_sem) + _rtx2_mfree((u8 *)p_sem, sizeof(rtx_sema_t)); + *sem = NULL; + return; } static void _rtx2_free_sema(_sema *sema) { _func_enter_; - if(*sema){ - rtx_sema_t *p_sem = (rtx_sema_t *)(*sema); - osSemaphoreDelete(p_sem->id); - if(p_sem) - _rtx2_mfree((u8 *)p_sem, sizeof(rtx_sema_t)); - *sema = NULL; - }else - DBG_ERR("NULL pointer get"); + if(*sema){ + rtx_sema_t *p_sem = (rtx_sema_t *)(*sema); + osSemaphoreDelete(p_sem->id); + if(p_sem) + _rtx2_mfree((u8 *)p_sem, sizeof(rtx_sema_t)); + *sema = NULL; + } else { + DBG_ERR("NULL pointer get"); + } _func_exit_; } static void _rtx2_up_sema(_sema *sema) { - if(*sema){ - rtx_sema_t *p_sem = (rtx_sema_t *)(*sema); - osStatus_t status = osSemaphoreRelease(p_sem->id); - if ( status != osOK){ - DBG_ERR("error %d", status); - } - }else - DBG_ERR("NULL pointer get"); +_func_enter_; + if(*sema){ + rtx_sema_t *p_sem = (rtx_sema_t *)(*sema); + osStatus_t status = osSemaphoreRelease(p_sem->id); + if (status != osOK){ + DBG_ERR("error %d", status); + } + } else { + DBG_ERR("NULL pointer get"); + } _func_exit_; } static void _rtx2_up_sema_from_isr(_sema *sema) { _func_enter_; - if(*sema){ - rtx_sema_t *p_sem = (rtx_sema_t *)*sema; - osStatus_t status = osSemaphoreRelease(p_sem->id); - if (status != osOK){ - DBG_ERR("error %d", status); - } - }else - DBG_ERR("NULL pointer get"); + if(*sema){ + rtx_sema_t *p_sem = (rtx_sema_t *)*sema; + osStatus_t status = osSemaphoreRelease(p_sem->id); + if (status != osOK){ + DBG_ERR("error %d", status); + } + } else { + DBG_ERR("NULL pointer get"); + } _func_exit_; } static u32 _rtx2_down_sema(_sema *sema, u32 timeout_ms) { - if(*sema){ - rtx_sema_t *p_sem = (rtx_sema_t *)*sema; - if(timeout_ms == RTW_MAX_DELAY) { - timeout_ms = osWaitForever; - } else { - timeout_ms = rtw_ms_to_systime(timeout_ms); - } - osStatus_t status = osSemaphoreAcquire(p_sem->id, timeout_ms); - if (status == osOK){ - return _TRUE; - }; - } - return _FALSE; + if(*sema){ + rtx_sema_t *p_sem = (rtx_sema_t *)*sema; + if(timeout_ms == RTW_MAX_DELAY) { + timeout_ms = osWaitForever; + } else { + timeout_ms = rtw_ms_to_systime(timeout_ms); + } + osStatus_t status = osSemaphoreAcquire(p_sem->id, timeout_ms); + if (status == osOK){ + return _TRUE; + } + } + return _FALSE; } static void _rtx2_mutex_init(_mutex *mutex) { _func_enter_; - rtx_mutex_t *p_mut = (rtx_mutex_t *)_rtx2_zmalloc(sizeof(rtx_mutex_t)); - if(p_mut == NULL) - goto err_exit; - memset(&p_mut->data, 0, sizeof(p_mut->data)); - p_mut->attr.cb_mem = &p_mut->data; - p_mut->attr.cb_size = sizeof(p_mut->data); - p_mut->id = osMutexNew(&p_mut->attr); - if (p_mut->id == NULL) - goto err_exit; - *mutex = (_mutex)p_mut; + rtx_mutex_t *p_mut = (rtx_mutex_t *)_rtx2_zmalloc(sizeof(rtx_mutex_t)); + if(p_mut == NULL) + goto err_exit; + memset(&p_mut->data, 0, sizeof(p_mut->data)); + p_mut->attr.cb_mem = &p_mut->data; + p_mut->attr.cb_size = sizeof(p_mut->data); + p_mut->id = osMutexNew(&p_mut->attr); + if (p_mut->id == NULL) + goto err_exit; + *mutex = (_mutex)p_mut; _func_exit_; - return; + return; err_exit: - DBG_ERR("error"); - if(p_mut) - _rtx2_mfree((u8 *)p_mut, sizeof(rtx_mutex_t)); - *mutex = NULL; - return; + DBG_ERR("error"); + if(p_mut) + _rtx2_mfree((u8 *)p_mut, sizeof(rtx_mutex_t)); + *mutex = NULL; + return; } static void _rtx2_mutex_free(_mutex *pmutex) { _func_enter_; - if(*pmutex){ - rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); - osMutexDelete(p_mut->id); - if(p_mut) - _rtx2_mfree((u8 *)p_mut, sizeof(rtx_mutex_t)); - } + if(*pmutex){ + rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); + osMutexDelete(p_mut->id); + if(p_mut) + _rtx2_mfree((u8 *)p_mut, sizeof(rtx_mutex_t)); + } _func_exit_; } static void _rtx2_mutex_get(_mutex *pmutex) { _func_enter_; - if(*pmutex){ - rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); - if (osMutexAcquire(p_mut->id, 60 * 1000 / OS_TICK_RATE_MS) != osOK) - DBG_ERR("%s(%p) failed, retry\n", __FUNCTION__, p_mut); - } + if(*pmutex){ + rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); + if (osMutexAcquire(p_mut->id, 60 * 1000 / OS_TICK_RATE_MS) != osOK) + DBG_ERR("%s(%p) failed, retry\n", __FUNCTION__, p_mut); + } _func_exit_; -} +} static int _rtx2_mutex_get_timeout(_mutex *pmutex, u32 timeout_ms) { _func_enter_; - if(*pmutex){ - rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); - if(timeout_ms == RTW_MAX_DELAY) { - timeout_ms = osWaitForever; - } else { - timeout_ms = rtw_ms_to_systime(timeout_ms); - } - if(osMutexAcquire(p_mut->id, timeout_ms) == osOK){ - return _SUCCESS; - } - } + if(*pmutex){ + rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); + if(timeout_ms == RTW_MAX_DELAY) { + timeout_ms = osWaitForever; + } else { + timeout_ms = rtw_ms_to_systime(timeout_ms); + } + if(osMutexAcquire(p_mut->id, timeout_ms) == osOK){ + return _SUCCESS; + } + } _func_exit_; - DBG_ERR("%s(%p) failed, retry\n", __FUNCTION__, pmutex); - return _FAIL; + DBG_ERR("%s(%p) failed, retry\n", __FUNCTION__, pmutex); + return _FAIL; } static void _rtx2_mutex_put(_mutex *pmutex) { _func_enter_; - if(*pmutex){ - rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); - if (osMutexRelease(p_mut->id) != osOK) - DBG_ERR("\r\ninternal counter of mutex is 0 or calling task is not the owner of the mutex"); - } + if(*pmutex){ + rtx_mutex_t *p_mut = (rtx_mutex_t *)(*pmutex); + if (osMutexRelease(p_mut->id) != osOK) + DBG_ERR("\r\ninternal counter of mutex is 0 or calling task is not the owner of the mutex"); + } _func_exit_; } static void _rtx2_enter_critical(_lock *plock, _irqL *pirqL) { _func_enter_; - CriticalNesting++; - if(CriticalNesting == 1){ - osKernelLock();//tsk_lock & tsk_unlock should not be called nested - } + CriticalNesting++; + if(CriticalNesting == 1){ + osKernelLock();//tsk_lock & tsk_unlock should not be called nested + } _func_exit_; } void mbed_die(void){ - DBG_ERR(" %p die here", osThreadGetId()); - __disable_irq(); - while(1); + DBG_ERR(" %p die here", osThreadGetId()); + __disable_irq(); + while(1); } static void _rtx2_exit_critical(_lock *plock, _irqL *pirqL) { _func_enter_; - if(CriticalNesting == 0){ - DBG_ERR("die here"); - HALT(); - } - CriticalNesting--; - if(CriticalNesting == 0){ - osKernelUnlock(); - } + if(CriticalNesting == 0){ + DBG_ERR("die here"); + HALT(); + } + CriticalNesting--; + if(CriticalNesting == 0){ + osKernelUnlock(); + } _func_exit_; } static void _rtx2_enter_critical_from_isr(_lock *plock, _irqL *pirqL) { _func_enter_; - __disable_irq(); + __disable_irq(); _func_exit_; } static void _rtx2_exit_critical_from_isr(_lock *plock, _irqL *pirqL) { _func_enter_; - __enable_irq(); + __enable_irq(); _func_exit_; } static int _rtx2_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL) { _func_enter_; - while(_rtx2_mutex_get_timeout(pmutex, 60 * 1000) != _SUCCESS) - DBG_ERR("\n\r[%p] %s(%p) failed, retry\n", osThreadGetId(), __FUNCTION__, pmutex); + while(_rtx2_mutex_get_timeout(pmutex, 60 * 1000) != _SUCCESS) + DBG_ERR("\n\r[%p] %s(%p) failed, retry\n", osThreadGetId(), __FUNCTION__, pmutex); _func_exit_; - return _SUCCESS; + return _SUCCESS; } static void _rtx2_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL) { _func_enter_; - _rtx2_mutex_put(pmutex); + _rtx2_mutex_put(pmutex); +_func_exit_; +} + +static void _rtx2_cpu_lock(void) +{ +_func_enter_; + printf(" Not yet ready. Should not come over here!\r\n"); +_func_exit_; +} +static void _rtx2_cpu_unlock(void) +{ +_func_enter_; + printf(" Not yet ready. Should not come over here!\r\n"); _func_exit_; } @@ -404,7 +406,7 @@ static void _rtx2_spinlock_init(_lock *plock) { _func_enter_; #if USE_MUTEX_FOR_SPINLOCK - _rtx2_mutex_init(plock); + _rtx2_mutex_init(plock); #endif _func_exit_; } @@ -413,9 +415,9 @@ static void _rtx2_spinlock_free(_lock *plock) { _func_enter_; #if USE_MUTEX_FOR_SPINLOCK - if(plock != NULL){ - _rtx2_mutex_free(plock); - } + if(plock != NULL){ + _rtx2_mutex_free(plock); + } #endif _func_exit_; } @@ -424,7 +426,7 @@ static void _rtx2_spinlock(_lock *plock) { _func_enter_; #if USE_MUTEX_FOR_SPINLOCK - _rtx2_mutex_get(plock); + _rtx2_mutex_get(plock); #endif _func_exit_; } @@ -433,7 +435,7 @@ static void _rtx2_spinunlock(_lock *plock) { _func_enter_; #if USE_MUTEX_FOR_SPINLOCK - _rtx2_mutex_put(plock); + _rtx2_mutex_put(plock); #endif _func_exit_; } @@ -441,9 +443,9 @@ _func_exit_; static void _rtx2_spinlock_irqsave(_lock *plock, _irqL *irqL) { _func_enter_; - _rtx2_enter_critical(plock, irqL); + _rtx2_enter_critical(plock, irqL); #if USE_MUTEX_FOR_SPINLOCK - _rtx2_spinlock(plock); + _rtx2_spinlock(plock); #endif _func_exit_; } @@ -452,129 +454,130 @@ static void _rtx2_spinunlock_irqsave(_lock *plock, _irqL *irqL) { _func_enter_; #if USE_MUTEX_FOR_SPINLOCK - _rtx2_spinunlock(plock); + _rtx2_spinunlock(plock); #endif - _rtx2_exit_critical(plock, irqL); + _rtx2_exit_critical(plock, irqL); _func_exit_; } static int _rtx2_init_xqueue( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages ) { _func_enter_; - rtx_mbox_t *mbox = (rtx_mbox_t *)_rtx2_zmalloc(sizeof(rtx_mbox_t)); - if (mbox == NULL ){ - goto err_exit; - } - mbox->queue_mem = _rtx2_zmalloc(number_of_messages * (message_size + sizeof(os_message_t))); - if(mbox->queue_mem == NULL) - goto err_exit; - mbox->attr.mq_mem = mbox->queue_mem; - mbox->attr.mq_size = number_of_messages * (message_size + sizeof(os_message_t)); - mbox->attr.cb_mem = &mbox->data; - mbox->attr.cb_size = sizeof(mbox->data); - *queue = (_xqueue)mbox; - mbox->id = osMessageQueueNew(number_of_messages, message_size, &mbox->attr); - if(mbox->id == NULL) - goto err_exit; + rtx_mbox_t *mbox = (rtx_mbox_t *)_rtx2_zmalloc(sizeof(rtx_mbox_t)); + if (mbox == NULL ){ + goto err_exit; + } + mbox->queue_mem = _rtx2_zmalloc(number_of_messages * (message_size + sizeof(os_message_t))); + if(mbox->queue_mem == NULL) + goto err_exit; + mbox->attr.mq_mem = mbox->queue_mem; + mbox->attr.mq_size = number_of_messages * (message_size + sizeof(os_message_t)); + mbox->attr.cb_mem = &mbox->data; + mbox->attr.cb_size = sizeof(mbox->data); + *queue = (_xqueue)mbox; + mbox->id = osMessageQueueNew(number_of_messages, message_size, &mbox->attr); + if(mbox->id == NULL) + goto err_exit; _func_exit_; - return _SUCCESS; + return _SUCCESS; err_exit: - DBG_ERR("%s error\r\n", __FUNCTION__); - if(mbox){ - if(mbox->queue_mem) - _rtx2_mfree(mbox->queue_mem, number_of_messages * (message_size + sizeof(os_message_t))); - _rtx2_mfree((u8 *)mbox, sizeof(rtx_mbox_t)); - *queue = NULL; - } - return _FAIL; + DBG_ERR("%s error\r\n", __FUNCTION__); + if(mbox){ + if(mbox->queue_mem) + _rtx2_mfree(mbox->queue_mem, number_of_messages * (message_size + sizeof(os_message_t))); + _rtx2_mfree((u8 *)mbox, sizeof(rtx_mbox_t)); + *queue = NULL; + } + return _FAIL; } static int _rtx2_push_to_xqueue( _xqueue* queue, void* message, u32 timeout_ms ) { _func_enter_; - rtx_mbox_t *mbox; - if(timeout_ms == RTW_MAX_DELAY) { - timeout_ms = osWaitForever; - } else { - timeout_ms = rtw_ms_to_systime(timeout_ms); - } - - if (*queue != NULL){ - mbox = (rtx_mbox_t *)(*queue); - if(osMessageQueuePut(mbox->id, message, NULL, timeout_ms) != osOK ){ - DBG_ERR("%s error\n", __FUNCTION__); - return _FAIL; - } - } + rtx_mbox_t *mbox; + if(timeout_ms == RTW_MAX_DELAY) { + timeout_ms = osWaitForever; + } else { + timeout_ms = rtw_ms_to_systime(timeout_ms); + } + + if (*queue != NULL){ + mbox = (rtx_mbox_t *)(*queue); + if(osMessageQueuePut(mbox->id, message, 0, timeout_ms) != osOK ){ + DBG_ERR("%s error\n", __FUNCTION__); + return _FAIL; + } + } _func_exit_; - return _SUCCESS; + return _SUCCESS; } static int _rtx2_pop_from_xqueue( _xqueue* queue, void* message, u32 timeout_ms ) { _func_enter_; - if(timeout_ms == RTW_WAIT_FOREVER) { - timeout_ms = osWaitForever; - } else { - timeout_ms = rtw_ms_to_systime(timeout_ms); - } - if (*queue != NULL){ - rtx_mbox_t *mbox = (rtx_mbox_t *)(*queue); - osStatus_t res = osMessageQueueGet(mbox->id, message, NULL, timeout_ms); - if (res == osOK) { + if(timeout_ms == RTW_WAIT_FOREVER) { + timeout_ms = osWaitForever; + } else { + timeout_ms = rtw_ms_to_systime(timeout_ms); + } + if (*queue != NULL){ + rtx_mbox_t *mbox = (rtx_mbox_t *)(*queue); + osStatus_t res = osMessageQueueGet(mbox->id, message, NULL, timeout_ms); + if (res == osOK) { _func_exit_; - return _SUCCESS; - } - } + return _SUCCESS; + } + } - DBG_ERR("[%p] %s error", osThreadGetId(), __FUNCTION__); - return _FAIL; + DBG_ERR("[%p] %s error", osThreadGetId(), __FUNCTION__); +_func_exit_; + return _FAIL; } static int _rtx2_deinit_xqueue( _xqueue* queue ) { _func_enter_; - if(*queue != NULL){ - rtx_mbox_t *mbox = (rtx_mbox_t *)(*queue); - if(mbox->queue_mem) - _rtx2_mfree(mbox->queue_mem, mbox->attr.mq_size); - _rtx2_mfree((u8 *)mbox, sizeof(rtx_mbox_t)); - *queue = NULL; - } + if(*queue != NULL){ + rtx_mbox_t *mbox = (rtx_mbox_t *)(*queue); + if(mbox->queue_mem) + _rtx2_mfree(mbox->queue_mem, mbox->attr.mq_size); + _rtx2_mfree((u8 *)mbox, sizeof(rtx_mbox_t)); + *queue = NULL; + } _func_exit_; return 0; } static u32 _rtx2_get_current_time(void) { - return osKernelGetSysTimerCount(); + return osKernelGetSysTimerCount(); } static u32 _rtx2_systime_to_ms(u32 systime) { - return systime * OS_TICK_RATE_MS; + return systime * OS_TICK_RATE_MS; } static u32 _rtx2_systime_to_sec(u32 systime) { - return systime / OS_TICK; + return systime / OS_TICK; } static u32 _rtx2_ms_to_systime(u32 ms) { - return ms / OS_TICK_RATE_MS; + return ms / OS_TICK_RATE_MS; } static u32 _rtx2_sec_to_systime(u32 sec) { - return sec * OS_TICK; + return sec * OS_TICK; } static void _rtx2_msleep_os(int ms) { _func_enter_; - osDelay(_rtx2_ms_to_systime(ms)); + osDelay(_rtx2_ms_to_systime(ms)); _func_exit_; } @@ -582,13 +585,13 @@ static void _rtx2_usleep_os(int us) { _func_enter_; #if defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32F10X_XL) - // FreeRTOS does not provide us level delay. Use busy wait - WLAN_BSP_UsLoop(us); + // FreeRTOS does not provide us level delay. Use busy wait + WLAN_BSP_UsLoop(us); #elif defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) - //DBG_ERR("%s: Please Implement micro-second delay\n", __FUNCTION__); - HalDelayUs(us); + //DBG_ERR("%s: Please Implement micro-second delay\n", __FUNCTION__); + HalDelayUs(us); #else -// #error "Please implement hardware dependent micro second level sleep here" + // #error "Please implement hardware dependent micro second level sleep here" #endif _func_exit_; } @@ -596,7 +599,7 @@ _func_exit_; static void _rtx2_mdelay_os(int ms) { _func_enter_; - osDelay(_rtx2_ms_to_systime(ms)); + osDelay(_rtx2_ms_to_systime(ms)); _func_exit_; } @@ -604,13 +607,13 @@ static void _rtx2_udelay_os(int us) { _func_enter_; #if defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32F10X_XL) - // FreeRTOS does not provide us level delay. Use busy wait - WLAN_BSP_UsLoop(us); + // FreeRTOS does not provide us level delay. Use busy wait + WLAN_BSP_UsLoop(us); #elif defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) - //RtlUdelayOS(us); - HalDelayUs(us); + //RtlUdelayOS(us); + HalDelayUs(us); #else -// #error "Please implement hardware dependent micro second level sleep here" + // #error "Please implement hardware dependent micro second level sleep here" #endif _func_exit_; } @@ -618,256 +621,258 @@ _func_exit_; static void _rtx2_yield_os(void) { _func_enter_; - osThreadYield(); + osThreadYield(); _func_exit_; } static void _rtx2_ATOMIC_SET(ATOMIC_T *v, int i) { - atomic_set(v,i); + atomic_set(v,i); } static int _rtx2_ATOMIC_READ(ATOMIC_T *v) { - return atomic_read(v); + return atomic_read(v); } static void _rtx2_ATOMIC_ADD(ATOMIC_T *v, int i) { - save_and_cli(); - v->counter += i; - restore_flags(); + save_and_cli(); + v->counter += i; + restore_flags(); } static void _rtx2_ATOMIC_SUB(ATOMIC_T *v, int i) { - save_and_cli(); - v->counter -= i; - restore_flags(); + save_and_cli(); + v->counter -= i; + restore_flags(); } static void _rtx2_ATOMIC_INC(ATOMIC_T *v) { - save_and_cli(); - v->counter++; - restore_flags(); + save_and_cli(); + v->counter++; + restore_flags(); } static void _rtx2_ATOMIC_DEC(ATOMIC_T *v) { - save_and_cli(); - v->counter--; - restore_flags(); + save_and_cli(); + v->counter--; + restore_flags(); } static int _rtx2_ATOMIC_ADD_RETURN(ATOMIC_T *v, int i) { - int temp; + int temp; - save_and_cli(); - temp = v->counter; - temp += i; - v->counter = temp; - restore_flags(); + save_and_cli(); + temp = v->counter; + temp += i; + v->counter = temp; + restore_flags(); - return temp; + return temp; } static int _rtx2_ATOMIC_SUB_RETURN(ATOMIC_T *v, int i) { - int temp; + int temp; - save_and_cli(); - temp = v->counter; - temp -= i; - v->counter = temp; - restore_flags(); + save_and_cli(); + temp = v->counter; + temp -= i; + v->counter = temp; + restore_flags(); - return temp; + return temp; } static int _rtx2_ATOMIC_INC_RETURN(ATOMIC_T *v) { - return _rtx2_ATOMIC_ADD_RETURN(v, 1); + return _rtx2_ATOMIC_ADD_RETURN(v, 1); } static int _rtx2_ATOMIC_DEC_RETURN(ATOMIC_T *v) { - return _rtx2_ATOMIC_SUB_RETURN(v, 1); + return _rtx2_ATOMIC_SUB_RETURN(v, 1); } static u64 _rtx2_modular64(u64 n, u64 base) { - unsigned int __base = (base); - unsigned int __rem; + unsigned int __base = (base); + unsigned int __rem; _func_enter_; - if (((n) >> 32) == 0) { - __rem = (unsigned int)(n) % __base; - (n) = (unsigned int)(n) / __base; - } - else - __rem = __div64_32(&(n), __base); + if (((n) >> 32) == 0) { + __rem = (unsigned int)(n) % __base; + (n) = (unsigned int)(n) / __base; + } else { + __rem = __div64_32(&(n), __base); + } _func_exit_; - return __rem; + return __rem; } /* Refer to ecos bsd tcpip codes */ static int _rtx2_arc4random(void) { _func_enter_; - u32 res = _rtx2_get_current_time(); - static unsigned long seed = 0xDEADB00B; - seed = ((seed & 0x007F00FF) << 7) ^ - ((seed & 0x0F80FF00) >> 8) ^ // be sure to stir those low bits - (res << 13) ^ (res >> 9); // using the clock too! + u32 res = _rtx2_get_current_time(); + static unsigned long seed = 0xDEADB00B; + seed = ((seed & 0x007F00FF) << 7) ^ + ((seed & 0x0F80FF00) >> 8) ^ // be sure to stir those low bits + (res << 13) ^ (res >> 9); // using the clock too! _func_exit_; - return (int)seed; + return (int)seed; } static int _rtx2_get_random_bytes(void *buf, u32 len) { -#if 1 //becuase of 4-byte align, we use the follow code style. - unsigned int ranbuf; - unsigned int *lp; - int i, count; - count = len / sizeof(unsigned int); - lp = (unsigned int *) buf; + unsigned int ranbuf; + unsigned int *lp; + int i, count; + count = len / sizeof(unsigned int); + lp = (unsigned int *) buf; _func_enter_; - for(i = 0; i < count; i ++) { - lp[i] = _rtx2_arc4random(); - len -= sizeof(unsigned int); - } + for(i = 0; i < count; i ++) { + lp[i] = _rtx2_arc4random(); + len -= sizeof(unsigned int); + } - if(len > 0) { - ranbuf = _rtx2_arc4random(); - _rtx2_memcpy(&lp[i], &ranbuf, len); - } + if(len > 0) { + ranbuf = _rtx2_arc4random(); + _rtx2_memcpy(&lp[i], &ranbuf, len); + } _func_exit_; - return 0; -#else - unsigned long ranbuf, *lp; - lp = (unsigned long *)buf; - while (len > 0) { - ranbuf = _rtx2_arc4random(); - *lp++ = ranbuf; //this op need the pointer is 4Byte-align! - len -= sizeof(ranbuf); - } - return 0; -#endif + return 0; } static u32 _rtx2_GetFreeHeapSize(void) { -#if USE_HEAP_INFO - return osFreeBytesRemaining; -#else - return 0; -#endif + //TODO + return 0; } +/* Convert from wlan priority number to CMSIS type osPriority */ +static osPriority_t make_cmsis_priority (u32 fpriority) +{ + osPriority_t priority = (osPriority_t)fpriority; + priority += osPriorityHigh; + return priority; +} -#if CONFIG_USE_TCM_HEAP -void *tcm_heap_malloc(int size); -#endif static int _rtx2_create_task(struct task_struct *ptask, const char *name, u32 stack_size, u32 priority, thread_func_t func, void *thctx) { _func_enter_; - rtx_thread_data_t *thread_hdl = NULL; - u32 stacksize = stack_size * 4; //sizeof(DWORD) - if(!func) - goto err_exit; - thread_hdl = (rtx_thread_data_t *)_rtx2_zmalloc(sizeof(rtx_thread_data_t)); - if(thread_hdl == NULL) - goto err_exit; - if(priority > osPriorityRealtime){ - DBG_ERR("[%s]priority is higher than osPriorityRealtime", name); - priority = osPriorityRealtime; - } - thread_hdl->attr.name = name; - thread_hdl->attr.priority = (osPriority_t)priority; - thread_hdl->attr.cb_size = sizeof(thread_hdl->data); - thread_hdl->attr.cb_mem = &thread_hdl->data; - thread_hdl->attr.stack_size = stacksize; - thread_hdl->attr.stack_mem = (void *)_rtx2_malloc(stacksize); - if (thread_hdl->attr.stack_mem == NULL) - goto err_exit; + rtx_thread_data_t *thread_hdl = NULL; + u32 stacksize = stack_size * 4; //sizeof(DWORD) + u8 *(*_customized_malloc)( u32 size ) = _rtx2_malloc; + u8 *(*_customized_zmalloc)( u32 size ) = _rtx2_zmalloc; + if(!func) + goto err_exit; +#if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK) + if(rtw_if_wifi_thread((char *)name) == 0){ + priority = make_cmsis_priority(priority); + _customized_malloc = _rtw_vmalloc; + _customized_zmalloc = _rtw_zvmalloc; + } +#endif + thread_hdl = (rtx_thread_data_t *)_customized_zmalloc(sizeof(rtx_thread_data_t)); + if(thread_hdl == NULL) + goto err_exit; + if(priority > osPriorityRealtime){ + DBG_ERR("[%s]priority is higher than osPriorityRealtime", name); + priority = osPriorityRealtime; + } + thread_hdl->attr.name = name; + thread_hdl->attr.priority = (osPriority_t)priority; + thread_hdl->attr.cb_size = sizeof(thread_hdl->data); + thread_hdl->attr.cb_mem = &thread_hdl->data; + thread_hdl->attr.stack_size = stacksize; + thread_hdl->attr.stack_mem = (void *)_customized_malloc(stacksize); + if (thread_hdl->attr.stack_mem == NULL) { + DBG_ERR("[%s] malloc failed", name); + goto err_exit; + } - ptask->task = (_thread_hdl_)thread_hdl; - ptask->task_name = name; - ptask->blocked = 0; - ptask->callback_running = 0; + ptask->task = (_thread_hdl_)thread_hdl; + ptask->task_name = name; + ptask->blocked = 0; + ptask->callback_running = 0; - _rtx2_init_sema(&ptask->wakeup_sema, 0); - _rtx2_init_sema(&ptask->terminate_sema, 0); - //rtw_init_queue(&wq->work_queue); + _rtx2_init_sema(&ptask->wakeup_sema, 0); + _rtx2_init_sema(&ptask->terminate_sema, 0); + //rtw_init_queue(&wq->work_queue); - thread_hdl->id = osThreadNew((osThreadFunc_t)func, thctx, &thread_hdl->attr); - if(thread_hdl->id == NULL) - goto err_exit; - return _SUCCESS; + thread_hdl->id = osThreadNew((osThreadFunc_t)func, thctx, &thread_hdl->attr); + if (thread_hdl->id == NULL) { + DBG_ERR("[%s] osThreadNew failed", name); + goto err_exit; + } + return _SUCCESS; err_exit: - if(thread_hdl){ - _rtx2_free_sema(&ptask->wakeup_sema); - _rtx2_free_sema(&ptask->terminate_sema); - _rtx2_memset((u8 *)ptask, 0, sizeof(*ptask)); - if(thread_hdl->attr.stack_mem) - _rtx2_mfree((void *)thread_hdl->attr.stack_mem, thread_hdl->attr.stack_size); - _rtx2_mfree((u8 *)thread_hdl, sizeof(rtx_thread_data_t)); - } - DBG_ERR("Create Task \"%s\" Failed! \n", ptask->task_name); - return _FAIL; + if(thread_hdl){ + _rtx2_free_sema(&ptask->wakeup_sema); + _rtx2_free_sema(&ptask->terminate_sema); + _rtx2_memset((u8 *)ptask, 0, sizeof(*ptask)); + if(thread_hdl->attr.stack_mem) + _rtx2_mfree((void *)thread_hdl->attr.stack_mem, thread_hdl->attr.stack_size); + _rtx2_mfree((u8 *)thread_hdl, sizeof(rtx_thread_data_t)); + } + DBG_ERR("Create Task \"%s\" Failed! \n", name); + return _FAIL; } static void _rtx2_delete_task(struct task_struct *ptask) { _func_enter_; - rtx_thread_data_t *thread_hdl = (rtx_thread_data_t *)ptask->task; - if (!thread_hdl){ - DBG_ERR("_rtx2_delete_task(): ptask is NULL!\n"); - return; - } + rtx_thread_data_t *thread_hdl = (rtx_thread_data_t *)ptask->task; + if (!thread_hdl){ + DBG_ERR("_rtx2_delete_task(): ptask is NULL!\n"); + return; + } - ptask->blocked = 1; + ptask->blocked = 1; - _rtx2_up_sema(&ptask->wakeup_sema); - _rtx2_down_sema(&ptask->terminate_sema, TIMER_MAX_DELAY); + _rtx2_up_sema(&ptask->wakeup_sema); + _rtx2_down_sema(&ptask->terminate_sema, TIMER_MAX_DELAY); - osThreadTerminate(thread_hdl->id); - if(thread_hdl->attr.stack_mem) - _rtx2_mfree((void *)thread_hdl->attr.stack_mem, thread_hdl->attr.stack_size); - _rtx2_mfree((u8 *)thread_hdl, sizeof(rtx_thread_data_t)); - - //rtw_deinit_queue(&wq->work_queue); - _rtx2_free_sema(&ptask->wakeup_sema); - _rtx2_free_sema(&ptask->terminate_sema); + osThreadTerminate(thread_hdl->id); + if(thread_hdl->attr.stack_mem) + _rtx2_mfree((void *)thread_hdl->attr.stack_mem, thread_hdl->attr.stack_size); + _rtx2_mfree((u8 *)thread_hdl, sizeof(rtx_thread_data_t)); - ptask->task = NULL; + //rtw_deinit_queue(&wq->work_queue); + _rtx2_free_sema(&ptask->wakeup_sema); + _rtx2_free_sema(&ptask->terminate_sema); - DBG_TRACE("Delete Task \"%s\"\n", ptask->task_name); + ptask->task = NULL; + + DBG_TRACE("Delete Task \"%s\"\n", ptask->task_name); _func_exit_; } void _rtx2_wakeup_task(struct task_struct *ptask) { _func_enter_; - if(ptask) - _rtx2_up_sema(&ptask->wakeup_sema); + if(ptask) + _rtx2_up_sema(&ptask->wakeup_sema); _func_exit_; } static void _rtx2_thread_enter(char *name) { _func_enter_; - DBG_INFO("\n\rRTKTHREAD %s\n", name); + DBG_INFO("\n\rRTKTHREAD %s\n", name); _func_exit_; } static void _rtx2_thread_exit(void) { _func_enter_; - osThreadExit(); -_func_exit_; + osThreadExit(); } /***************************************************** @@ -892,204 +897,335 @@ typedef struct os_timer_cb_ { // Timer Control Block } os_timer_cb; *****************************************************/ _timerHandle _rtx2_timerCreate( const signed char *pcTimerName, - osdepTickType xTimerPeriodInTicks, - u32 uxAutoReload, - void * pvTimerID, - TIMER_FUN pxCallbackFunction ) + osdepTickType xTimerPeriodInTicks, + u32 uxAutoReload, + void * pvTimerID, + TIMER_FUN pxCallbackFunction ) { _func_enter_; - rtx_tmr_t *tmr = (rtx_tmr_t *)_rtx2_zmalloc(sizeof(rtx_tmr_t)); - osTimerType_t type = (uxAutoReload == _TRUE)?osTimerPeriodic:osTimerOnce; - if(tmr == NULL) - goto err_exit; + rtx_tmr_t *tmr = (rtx_tmr_t *)_rtx2_zmalloc(sizeof(rtx_tmr_t)); + osTimerType_t type = (uxAutoReload == _TRUE)?osTimerPeriodic:osTimerOnce; + if(tmr == NULL) + goto err_exit; - tmr->attr.name = pcTimerName; - tmr->attr.cb_mem = (void *)&tmr->data; - tmr->attr.cb_size = sizeof(tmr->data); - if(pvTimerID == NULL) - pvTimerID = (void *)tmr; - tmr->id = osTimerNew(pxCallbackFunction, type, pvTimerID, &tmr->attr); - if(tmr->id == NULL) - goto err_exit; + tmr->attr.name = (const char *)pcTimerName; + tmr->attr.cb_mem = (void *)&tmr->data; + tmr->attr.cb_size = sizeof(tmr->data); + if(pvTimerID == NULL) + pvTimerID = (void *)tmr; + tmr->id = osTimerNew(pxCallbackFunction, type, pvTimerID, &tmr->attr); + if(tmr->id == NULL) + goto err_exit; _func_exit_; - return (_timerHandle)tmr; + return (_timerHandle)tmr; err_exit: - DBG_ERR("error"); - if(tmr) - _rtx2_mfree((u8 *)tmr, sizeof(rtx_tmr_t)); - return NULL; + DBG_ERR("error"); + if(tmr) + _rtx2_mfree((u8 *)tmr, sizeof(rtx_tmr_t)); + return NULL; } -u32 _rtx2_timerDelete( _timerHandle xTimer, - osdepTickType xBlockTime ) +u32 _rtx2_timerDelete(_timerHandle xTimer, + osdepTickType xBlockTime) { _func_enter_; - rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; - osStatus_t status = osTimerDelete(tmr->id); - _rtx2_mfree((u8 *)tmr, sizeof(rtx_tmr_t)); - if(status != osOK){ - DBG_ERR("error %d", status); - return _FAIL; - } + rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; + osStatus_t status = osTimerDelete(tmr->id); + _rtx2_mfree((u8 *)tmr, sizeof(rtx_tmr_t)); + if(status != osOK){ + DBG_ERR("error %d", status); + return _FAIL; + } _func_exit_; - return _SUCCESS; + return _SUCCESS; } -u32 _rtx2_timerIsTimerActive( _timerHandle xTimer ) +u32 _rtx2_timerIsTimerActive(_timerHandle xTimer) { _func_enter_; - rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; - if(osTimerIsRunning(tmr->id)) - return _TRUE; - return _FALSE; + rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; + if (osTimerIsRunning(tmr->id)) { + return _TRUE; + } + return _FALSE; } -u32 _rtx2_timerStop( _timerHandle xTimer, - osdepTickType xBlockTime ) +u32 _rtx2_timerStop(_timerHandle xTimer, + osdepTickType xBlockTime) { _func_enter_; - rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; - if(_rtx2_timerIsTimerActive(xTimer) == _TRUE){ - osStatus_t status = osTimerStop(tmr->id); + rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; + if(_rtx2_timerIsTimerActive(xTimer) == _TRUE){ + osStatus_t status = osTimerStop(tmr->id); + if(status != osOK){ + DBG_ERR("error %d\n", status); _func_exit_; - if(status != osOK){ - DBG_ERR("error %d\n", status); - return _FAIL; - } - } - return _SUCCESS; + return _FAIL; + } + } +_func_exit_; + return _SUCCESS; } -u32 _rtx2_timerChangePeriod( _timerHandle xTimer, - osdepTickType xNewPeriod, - osdepTickType xBlockTime ) +u32 _rtx2_timerChangePeriod(_timerHandle xTimer, + osdepTickType xNewPeriod, + osdepTickType xBlockTime) { _func_enter_; - rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; - osStatus_t ret; + rtx_tmr_t *tmr = (rtx_tmr_t *) xTimer; + osStatus_t ret; - if(xNewPeriod == 0) - xNewPeriod += 1; - //xNewPeriod = _rtx2_systime_to_ms(xNewPeriod); - ret = osTimerStart(tmr->id, xNewPeriod); + if(xNewPeriod == 0) + xNewPeriod += 1; + //xNewPeriod = _rtx2_systime_to_ms(xNewPeriod); + ret = osTimerStart(tmr->id, xNewPeriod); _func_exit_; - if(ret == osOK) - return _SUCCESS; - - DBG_ERR("%s error\n", __FUNCTION__); - return _FAIL; + if(ret == osOK) + return _SUCCESS; + + DBG_ERR("%s error\n", __FUNCTION__); + return _FAIL; } -//void _rtx2_acquire_wakelock() -//{ -//#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1) -// acquire_wakelock(WAKELOCK_WLAN); -//#endif -//} +void *_rtx2_timerGetID(_timerHandle xTimer) +{ + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return NULL; +} -//void _rtx2_release_wakelock() -//{ -//#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1) -// release_wakelock(WAKELOCK_WLAN); -//#endif -//} +u32 _rtx2_timerStart(_timerHandle xTimer, + osdepTickType xBlockTime) +{ + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return _FAIL; +} + +u32 _rtx2_timerStartFromISR(_timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken) +{ + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return _FAIL; +} + +u32 _rtx2_timerStopFromISR(_timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken) +{ + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return _FAIL; +} + +u32 _rtx2_timerResetFromISR(_timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken) +{ + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return _FAIL; +} + +u32 _rtx2_timerChangePeriodFromISR(_timerHandle xTimer, + osdepTickType xNewPeriod, + osdepBASE_TYPE *pxHigherPriorityTaskWoken) +{ + if(xNewPeriod == 0) + xNewPeriod += 1; + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return _FAIL; +} + +u32 _rtx2_timerReset(_timerHandle xTimer, + osdepTickType xBlockTime) +{ + DBG_ERR("%s: Not implemented yet\n", __FUNCTION__); + return _FAIL; +} + +void _rtx2_acquire_wakelock() +{ + //TODO + return; +} + +void _rtx2_release_wakelock() +{ + //TODO + return; +} + +void _rtx2_wakelock_timeout(uint32_t timeout) +{ + //TODO + return; +} u8 _rtx2_get_scheduler_state(void) { _func_enter_; - osKernelState_t state = osKernelGetState(); - u8 state_out = OS_SCHEDULER_NOT_STARTED; - switch(state){ - case osKernelRunning: state = OS_SCHEDULER_RUNNING; break; - case osKernelSuspended: state = OS_SCHEDULER_SUSPENDED; break; - default: break; - } + osKernelState_t state = osKernelGetState(); + u8 state_out = OS_SCHEDULER_NOT_STARTED; + switch(state){ + case osKernelRunning: + state_out = OS_SCHEDULER_RUNNING; + break; + case osKernelSuspended: + state_out = OS_SCHEDULER_SUSPENDED; + break; + default: + break; + } _func_exit_; - return state_out; + return state_out; } const struct osdep_service_ops osdep_service = { - _rtx2_malloc, //rtw_vmalloc - _rtx2_zmalloc, //rtw_zvmalloc - _rtx2_mfree, //rtw_vmfree - _rtx2_malloc, //rtw_malloc - _rtx2_zmalloc, //rtw_zmalloc - _rtx2_mfree, //rtw_mfree - _rtx2_memcpy, //rtw_memcpy - _rtx2_memcmp, //rtw_memcmp - _rtx2_memset, //rtw_memset - _rtx2_init_sema, //rtw_init_sema - _rtx2_free_sema, //rtw_free_sema - _rtx2_up_sema, //rtw_up_sema - _rtx2_up_sema_from_isr,//rtw_up_sema_from_isr - _rtx2_down_sema, //rtw_down_sema - _rtx2_mutex_init, //rtw_mutex_init - _rtx2_mutex_free, //rtw_mutex_free - _rtx2_mutex_get, //rtw_mutex_get - _rtx2_mutex_get_timeout, //rtw_mutex_get_timeout - _rtx2_mutex_put, //rtw_mutex_put - _rtx2_enter_critical, //rtw_enter_critical - _rtx2_exit_critical, //rtw_exit_critical - _rtx2_enter_critical_from_isr, //rtw_enter_critical_from_isr - _rtx2_exit_critical_from_isr, //rtw_exit_critical_from_isr - NULL, //rtw_enter_critical_bh - NULL, //rtw_exit_critical_bh - _rtx2_enter_critical_mutex, //rtw_enter_critical_mutex - _rtx2_exit_critical_mutex, //rtw_exit_critical_mutex - _rtx2_spinlock_init, //rtw_spinlock_init - _rtx2_spinlock_free, //rtw_spinlock_free - _rtx2_spinlock, //rtw_spin_lock - _rtx2_spinunlock, //rtw_spin_unlock - _rtx2_spinlock_irqsave, //rtw_spinlock_irqsave - _rtx2_spinunlock_irqsave, //rtw_spinunlock_irqsave - _rtx2_init_xqueue,//rtw_init_xqueue - _rtx2_push_to_xqueue,//rtw_push_to_xqueue - _rtx2_pop_from_xqueue,//rtw_pop_from_xqueue - _rtx2_deinit_xqueue,//rtw_deinit_xqueue - _rtx2_get_current_time, //rtw_get_current_time - _rtx2_systime_to_ms, //rtw_systime_to_ms - _rtx2_systime_to_sec, //rtw_systime_to_sec - _rtx2_ms_to_systime, //rtw_ms_to_systime - _rtx2_sec_to_systime, //rtw_sec_to_systime - _rtx2_msleep_os, //rtw_msleep_os - _rtx2_usleep_os, //rtw_usleep_os - _rtx2_mdelay_os, //rtw_mdelay_os - _rtx2_udelay_os, //rtw_udelay_os - _rtx2_yield_os, //rtw_yield_os - - _rtx2_ATOMIC_SET, //ATOMIC_SET - _rtx2_ATOMIC_READ, //ATOMIC_READ - _rtx2_ATOMIC_ADD, //ATOMIC_ADD - _rtx2_ATOMIC_SUB, //ATOMIC_SUB - _rtx2_ATOMIC_INC, //ATOMIC_INC - _rtx2_ATOMIC_DEC, //ATOMIC_DEC - _rtx2_ATOMIC_ADD_RETURN, //ATOMIC_ADD_RETURN - _rtx2_ATOMIC_SUB_RETURN, //ATOMIC_SUB_RETURN - _rtx2_ATOMIC_INC_RETURN, //ATOMIC_INC_RETURN - _rtx2_ATOMIC_DEC_RETURN, //ATOMIC_DEC_RETURN + _rtx2_malloc, //rtw_vmalloc + _rtx2_zmalloc, //rtw_zvmalloc + _rtx2_mfree, //rtw_vmfree + _rtx2_malloc, //rtw_malloc + _rtx2_zmalloc, //rtw_zmalloc + _rtx2_mfree, //rtw_mfree + _rtx2_memcpy, //rtw_memcpy + _rtx2_memcmp, //rtw_memcmp + _rtx2_memset, //rtw_memset + _rtx2_init_sema, //rtw_init_sema + _rtx2_free_sema, //rtw_free_sema + _rtx2_up_sema, //rtw_up_sema + _rtx2_up_sema_from_isr, //rtw_up_sema_from_isr + _rtx2_down_sema, //rtw_down_timeout_sema + _rtx2_mutex_init, //rtw_mutex_init + _rtx2_mutex_free, //rtw_mutex_free + _rtx2_mutex_get, //rtw_mutex_get + _rtx2_mutex_get_timeout, //rtw_mutex_get_timeout + _rtx2_mutex_put, //rtw_mutex_put + _rtx2_enter_critical, //rtw_enter_critical + _rtx2_exit_critical, //rtw_exit_critical + _rtx2_enter_critical_from_isr, //rtw_enter_critical_from_isr + _rtx2_exit_critical_from_isr, //rtw_exit_critical_from_isr + NULL, //rtw_enter_critical_bh + NULL, //rtw_exit_critical_bh + _rtx2_enter_critical_mutex, //rtw_enter_critical_mutex + _rtx2_exit_critical_mutex, //rtw_exit_critical_mutex + _rtx2_cpu_lock, //rtw_cpu_lock + _rtx2_cpu_unlock, //rtw_cpu_unlock + _rtx2_spinlock_init, //rtw_spinlock_init + _rtx2_spinlock_free, //rtw_spinlock_free + _rtx2_spinlock, //rtw_spin_lock + _rtx2_spinunlock, //rtw_spin_unlock + _rtx2_spinlock_irqsave, //rtw_spinlock_irqsave + _rtx2_spinunlock_irqsave, //rtw_spinunlock_irqsave + _rtx2_init_xqueue, //rtw_init_xqueue + _rtx2_push_to_xqueue, //rtw_push_to_xqueue + _rtx2_pop_from_xqueue, //rtw_pop_from_xqueue + _rtx2_deinit_xqueue, //rtw_deinit_xqueue + _rtx2_get_current_time, //rtw_get_current_time + _rtx2_systime_to_ms, //rtw_systime_to_ms + _rtx2_systime_to_sec, //rtw_systime_to_sec + _rtx2_ms_to_systime, //rtw_ms_to_systime + _rtx2_sec_to_systime, //rtw_sec_to_systime + _rtx2_msleep_os, //rtw_msleep_os + _rtx2_usleep_os, //rtw_usleep_os + _rtx2_mdelay_os, //rtw_mdelay_os + _rtx2_udelay_os, //rtw_udelay_os + _rtx2_yield_os, //rtw_yield_os - _rtx2_modular64, //rtw_modular64 - _rtx2_get_random_bytes, //rtw_get_random_bytes - _rtx2_GetFreeHeapSize, //rtw_getFreeHeapSize + _rtx2_ATOMIC_SET, //ATOMIC_SET + _rtx2_ATOMIC_READ, //ATOMIC_READ + _rtx2_ATOMIC_ADD, //ATOMIC_ADD + _rtx2_ATOMIC_SUB, //ATOMIC_SUB + _rtx2_ATOMIC_INC, //ATOMIC_INC + _rtx2_ATOMIC_DEC, //ATOMIC_DEC + _rtx2_ATOMIC_ADD_RETURN, //ATOMIC_ADD_RETURN + _rtx2_ATOMIC_SUB_RETURN, //ATOMIC_SUB_RETURN + _rtx2_ATOMIC_INC_RETURN, //ATOMIC_INC_RETURN + _rtx2_ATOMIC_DEC_RETURN, //ATOMIC_DEC_RETURN - _rtx2_create_task, //rtw_create_task - _rtx2_delete_task, //rtw_delete_task - _rtx2_wakeup_task, //rtw_wakeup_task + _rtx2_modular64, //rtw_modular64 + _rtx2_get_random_bytes, //rtw_get_random_bytes + _rtx2_GetFreeHeapSize, //rtw_getFreeHeapSize - _rtx2_thread_enter, //rtw_thread_enter - _rtx2_thread_exit, //rtw_thread_exit + _rtx2_create_task, //rtw_create_task + _rtx2_delete_task, //rtw_delete_task + _rtx2_wakeup_task, //rtw_wakeup_task - _rtx2_timerCreate, //rtw_timerCreate, - _rtx2_timerDelete, //rtw_timerDelete, - _rtx2_timerIsTimerActive, //rtw_timerIsTimerActive, - _rtx2_timerStop, //rtw_timerStop, - _rtx2_timerChangePeriod, //rtw_timerChangePeriod + _rtx2_thread_enter, //rtw_thread_enter + _rtx2_thread_exit, //rtw_thread_exit - NULL, // rtw_acquire_wakelock - NULL, // rtw_release_wakelock - NULL, //rtw_wakelock_timeout + _rtx2_timerCreate, //rtw_timerCreate + _rtx2_timerDelete, //rtw_timerDelete + _rtx2_timerIsTimerActive, //rtw_timerIsTimerActive + _rtx2_timerStop, //rtw_timerStop + _rtx2_timerChangePeriod, //rtw_timerChangePeriod + _rtx2_timerGetID, //rtw_timerGetID + _rtx2_timerStart, //rtw_timerStart + _rtx2_timerStartFromISR, //rtw_timerStartFromISR + _rtx2_timerStopFromISR, //rtw_timerStopFromISR + _rtx2_timerResetFromISR, //rtw_timerResetFromISR + _rtx2_timerChangePeriodFromISR, //rtw_timerChangePeriodFromISR + _rtx2_timerReset, //rtw_timerReset - _rtx2_get_scheduler_state // rtw_get_scheduler_state + _rtx2_acquire_wakelock, //rtw_acquire_wakelock + _rtx2_release_wakelock, //rtw_release_wakelock + _rtx2_wakelock_timeout, //rtw_wakelock_timeout + _rtx2_get_scheduler_state //rtw_get_scheduler_state }; +/* +* Below block is to remove the compilation error of ARMCC +**/ +HAL_CUT_B_RAM_DATA_SECTION +_WEAK unsigned int rand_x = 123456789; + +_WEAK u8* RtlZmalloc(u32 sz) +{ + u8 *pbuf; + + pbuf= rtw_malloc(sz); + + if (pbuf != NULL) { + _memset(pbuf, 0, sz); + } + + return pbuf; +} + +_WEAK void RtlMfree(u8 *pbuf, u32 sz) +{ + rtw_mfree(pbuf, sz); +} + +_WEAK void UartLogIrqHandleRam(void * Data) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + +_WEAK void vPortSVCHandler(void) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + +_WEAK void xPortPendSVHandler(void) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + +_WEAK void xPortSysTickHandler(void) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + +_WEAK u8 __ram_start_table_start__[]; + +_WEAK void rtw_odm_acquirespinlock(void * adapter, int type) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + +_WEAK void rtw_odm_releasespinlock(void * adapter, int type) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + +_WEAK void ROM_WIFI_BSSID_SET(u8 iface_type, u8 variable, u8 *val) +{ + printf("%s: Should not come over here!\r\n", __func__); +} + diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.h index f35587f019..ff7a4ef7ad 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/cmsis_rtos/cmsis_rtos_service.h @@ -1,25 +1,33 @@ -#ifndef _RTX2_SERVICE_H_ -#define _RTX2_SERVICE_H_ +#ifndef _CMSIS_RTOS_SERVICE_H_ +#define _CMSIS_RTOS_SERVICE_H_ //----------------------------------------------------------------------- // Include Files //----------------------------------------------------------------------- -#include "wireless.h" +//#include "wireless.h" #include "dlist.h" #include -//#include #include "RTX_Config.h" -//#include -//#include -//#include #include "rtx_lib.h" // -------------------------------------------- // Platform dependent include file // -------------------------------------------- -#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) -//#include "platform_stdlib.h" -//#include "basic_types.h" -#include +#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8195BHP) +#include "platform/platform_stdlib.h" +extern VOID RtlUdelayOS(u32 us); +#elif defined(CONFIG_PLATFORM_8711B) +#include "platform/platform_stdlib.h" +#elif defined(CONFIG_PLATFORM_8721D) +#include "platform/platform_stdlib.h" +#elif defined(CONFIG_HARDWARE_8821C) +#include "basic_types.h" +#include "wlan_basic_types.h" +#elif defined(CONFIG_HARDWARE_8188F) +#include "platform/platform_stdlib.h" +#elif defined(CONFIG_HARDWARE_8192E) +#include "platform/platform_stdlib.h" +#elif defined(CONFIG_HARDWARE_8723D) +#include "platform/platform_stdlib.h" #else // other MCU may use standard library #include @@ -28,7 +36,7 @@ #if (defined CONFIG_GSPI_HCI || defined CONFIG_SDIO_HCI) || defined(CONFIG_LX_HCI) /* For SPI interface transfer and us delay implementation */ -#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) +#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) && !defined(CONFIG_PLATFORM_8721D) && !defined(CONFIG_PLATFORM_8195BHP) #include #endif #endif @@ -37,129 +45,101 @@ // -------------------------------------------- // Platform dependent type define // -------------------------------------------- -#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef signed char s8; -typedef signed short s16; -typedef signed int s32; -typedef signed long long s64; -typedef unsigned long long u64; -typedef unsigned int uint; -typedef signed int sint; - -#ifndef bool -typedef int bool; -#define true 1 -#define false 0 -#endif - -#define IN -#define OUT -#define VOID void -#define NDIS_OID uint -#define NDIS_STATUS uint -#ifndef PVOID -typedef void * PVOID; -#endif - -typedef unsigned int __kernel_size_t; -typedef int __kernel_ssize_t; -typedef __kernel_size_t SIZE_T; -typedef __kernel_ssize_t SSIZE_T; - -#endif //CONFIG_PLATFORM_8195A +#define OS_TICK OS_TICK_FREQ +#define OS_TICK_RATE_MS (1000/OS_TICK) // === SEMAPHORE === typedef struct { - osSemaphoreId_t id; - osSemaphoreAttr_t attr; - os_semaphore_t data; + osSemaphoreId_t id; + osSemaphoreAttr_t attr; + os_semaphore_t data; } rtx_sema_t; // === THREAD === typedef struct { - osThreadId_t id; - osThreadAttr_t attr; - os_thread_t data; + osThreadId_t id; + osThreadAttr_t attr; + os_thread_t data; } rtx_thread_data_t; // === MUTEX === typedef struct { - osMutexId_t id; - osMutexAttr_t attr; - os_mutex_t data; + osMutexId_t id; + osMutexAttr_t attr; + os_mutex_t data; } rtx_mutex_t; // === MAIL BOX === -#define RTX_MB_SIZE 8 +#define RTX_MB_SIZE 8 typedef struct { - osEventFlagsId_t id; - osEventFlagsAttr_t attr; - os_event_flags_t data; + osEventFlagsId_t id; + osEventFlagsAttr_t attr; + os_event_flags_t data; - uint8_t post_idx; - uint8_t fetch_idx; - void* queue[RTX_MB_SIZE]; + uint8_t post_idx; + uint8_t fetch_idx; + void* queue[RTX_MB_SIZE]; } rtx_mqueue_t; typedef struct { - osMessageQueueId_t id; - osMessageQueueAttr_t attr; - void *queue_mem; - os_message_queue_t data; + osMessageQueueId_t id; + osMessageQueueAttr_t attr; + void *queue_mem; + os_message_queue_t data; } rtx_mbox_t; typedef struct{ - osTimerId_t id; - osTimerAttr_t attr; - os_timer_t data; -}rtx_tmr_t; + osTimerId_t id; + osTimerAttr_t attr; + os_timer_t data; +} rtx_tmr_t; -#define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field) +#define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field) // os types -typedef char osdepCHAR; -typedef float osdepFLOAT; -typedef double osdepDOUBLE; -typedef long osdepLONG; -typedef short osdepSHORT; -typedef unsigned long osdepSTACK_TYPE; -typedef long osdepBASE_TYPE; -typedef unsigned long osdepTickType; +typedef char osdepCHAR; +typedef float osdepFLOAT; +typedef double osdepDOUBLE; +typedef long osdepLONG; +typedef short osdepSHORT; +typedef unsigned long osdepSTACK_TYPE; +typedef long osdepBASE_TYPE; +typedef unsigned long osdepTickType; -typedef void * _timerHandle; -typedef void * _sema; -typedef void * _mutex; -typedef void * _lock; -typedef void * _queueHandle; -typedef void * _xqueue; -typedef struct timer_list _timer; +typedef void * _timerHandle; +typedef void * _sema; +typedef void * _mutex; +typedef void * _lock; +typedef void * _queueHandle; +typedef void * _xqueue; +typedef struct timer_list _timer; -typedef struct sk_buff _pkt; -typedef unsigned char _buffer; +typedef struct sk_buff _pkt; +typedef unsigned char _buffer; +typedef unsigned int systime; #ifndef __LIST_H #warning "DLIST_NOT_DEFINE!!!!!!" struct list_head { - struct list_head *next, *prev; + struct list_head *next, *prev; }; #endif -struct __queue { - struct list_head queue; - _lock lock; +struct __queue { + struct list_head queue; + _lock lock; }; -typedef struct __queue _queue; -typedef struct list_head _list; -typedef unsigned long _irqL; +typedef struct __queue _queue; +typedef struct list_head _list; +typedef unsigned long _irqL; -typedef void* _thread_hdl_; -typedef void thread_return; -typedef void* thread_context; +typedef void* _thread_hdl_; +typedef void thread_return; +typedef void* thread_context; + +typedef struct { volatile int counter; } atomic_t; #define ATOMIC_T atomic_t #define HZ configTICK_RATE_HZ @@ -168,33 +148,40 @@ typedef void* thread_context; /* emulate a modern version */ #define LINUX_VERSION_CODE KERNEL_VERSION(2, 6, 17) -static __inline _list *get_next(_list *list) +static __inline _list *get_next(_list *list) { - return list->next; -} + return list->next; +} -static __inline _list *get_list_head(_queue *queue) +static __inline _list *get_list_head(_queue *queue) { - return (&(queue->queue)); + return (&(queue->queue)); } #define LIST_CONTAINOR(ptr, type, member) \ - ((type *)((char *)(ptr)-(SIZE_T)((char *)&((type *)ptr)->member - (char *)ptr))) + ((type *)((char *)(ptr)-(SIZE_T)((char *)&((type *)ptr)->member - (char *)ptr))) //#define container_of(p,t,n) (t*)((p)-&(((t*)0)->n)) #define container_of(ptr, type, member) \ - ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member))) -#define TASK_PRORITY_LOW osPriorityAboveNormal//osPriorityNormal -#define TASK_PRORITY_MIDDLE osPriorityHigh//osPriorityAboveNormal -#define TASK_PRORITY_HIGH osPriorityRealtime//osPriorityHigh -#define TASK_PRORITY_SUPER osPriorityRealtime -#define TASK_PRORITY_IDEL osPriorityIdle + ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member))) +#define TASK_PRORITY_LOW 1 +#define TASK_PRORITY_MIDDLE 2 +#define TASK_PRORITY_HIGH 3 +#define TASK_PRORITY_SUPER 4 +#define PRIORITIE_OFFSET 4 +#define TIMER_MAX_DELAY 0xFFFFFFFF -#define TIMER_MAX_DELAY 0xFFFFFFFF void save_and_cli(void); void restore_flags(void); void cli(void); +#ifndef mdelay +#define mdelay(t) ((t/OS_TICK_RATE_MS)>0)?(osDelay(t/OS_TICK_RATE_MS)):(osDelay(1)) +#endif + +#ifndef udelay +#define udelay(t) ((t/(OS_TICK_RATE_MS*1000))>0)?osDelay(t/(OS_TICK_RATE_MS*1000)):(osDelay(1)) +#endif //----- ------------------------------------------------------------------ // Common Definition //----- ------------------------------------------------------------------ @@ -208,45 +195,43 @@ void cli(void); #define KERN_INFO #define KERN_NOTICE -#define GFP_KERNEL 1 -#define GFP_ATOMIC 1 +#undef GFP_KERNEL +#define GFP_KERNEL 1 +#define GFP_ATOMIC 1 -#define SET_MODULE_OWNER(some_struct) do { } while (0) -#define SET_NETDEV_DEV(dev, obj) do { } while (0) -#define register_netdev(dev) (0) -#define unregister_netdev(dev) do { } while (0) -#define netif_queue_stopped(dev) (0) -#define netif_wake_queue(dev) do { } while (0) -#define printk printf +#define SET_MODULE_OWNER(some_struct) do { } while (0) +#define SET_NETDEV_DEV(dev, obj) do { } while (0) +#define register_netdev(dev) (0) +#define unregister_netdev(dev) do { } while (0) +#define netif_queue_stopped(dev) (0) +#define netif_wake_queue(dev) do { } while (0) +#define printk printf -#define DBG_ERR(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args) +#define DBG_ERR(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args) #if WLAN_INTF_DBG -#define DBG_TRACE(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args) -#define DBG_INFO(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args) +#define DBG_TRACE(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args) +#define DBG_INFO(fmt, args...) printf("\n\r[%s] " fmt, __FUNCTION__, ## args) #else #define DBG_TRACE(fmt, args...) #define DBG_INFO(fmt, args...) #endif -#define HALT() do { cli(); for(;;);} while(0) -#define ASSERT(x) do { \ - if((x) == 0) \ - printf("\n\rAssert(" #x ") failed on line %d in file %s", __LINE__, __FILE__); \ - HALT(); \ - } while(0) +#define HALT() do { cli(); for(;;);} while(0) +#undef ASSERT +#define ASSERT(x) do { \ + if((x) == 0){\ + printf("\n\rAssert(" #x ") failed on line %d in file %s", __LINE__, __FILE__); \ + HALT();}\ + } while(0) #undef DBG_ASSERT -#define DBG_ASSERT(x, msg) do { \ - if((x) == 0) \ - printf("\n\r%s, Assert(" #x ") failed on line %d in file %s", msg, __LINE__, __FILE__); \ - } while(0) +#define DBG_ASSERT(x, msg) do { \ + if((x) == 0) \ + printf("\n\r%s, Assert(" #x ") failed on line %d in file %s", msg, __LINE__, __FILE__); \ + } while(0) //----- ------------------------------------------------------------------ // Atomic Operation //----- ------------------------------------------------------------------ -#if !defined(CONFIG_PLATFORM_8195A) && !defined(CONFIG_PLATFORM_8711B) // for 8195A, it is defined in ..system../basic_types.h -typedef struct { volatile int counter; } atomic_t; -#endif - /* * atomic_read - read atomic variable @@ -255,6 +240,7 @@ typedef struct { volatile int counter; } atomic_t; * Atomically reads the value of @v. Note that the guaranteed * useful range of an atomic_t is only 24 bits. */ +#undef atomic_read #define atomic_read(v) ((v)->counter) /* @@ -265,6 +251,7 @@ typedef struct { volatile int counter; } atomic_t; * Atomically sets the value of @v to @i. Note that the guaranteed * useful range of an atomic_t is only 24 bits. */ +#undef atomic_set #define atomic_set(v,i) ((v)->counter = (i)) /* @@ -292,6 +279,10 @@ extern u32 rtw_is_list_empty(_list *phead); extern void rtw_list_insert_head(_list *plist, _list *phead); extern void rtw_list_insert_tail(_list *plist, _list *phead); extern void rtw_list_delete(_list *plist); -#define vPortExitCritical save_and_cli -#endif /* _RTX_SERVICE_H_ */ + +#if (defined CONFIG_PLATFORM_8711B) || (defined CONFIG_PLATFORM_8721D) +extern u32 random_seed; +#endif + +#endif /* _CMSIS_RTOS_SERVICE_H_ */ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/device_lock.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/device_lock.c index b76516d71b..6cbef3cc3d 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/device_lock.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/device_lock.c @@ -53,7 +53,7 @@ void device_mutex_lock(RT_DEV_LOCK_E device) { device_mutex_init(device); while(rtw_mutex_get_timeout(&device_mutex[device], 10000)<0) - printf("device lock timeout: %d\n", device); + printf("device lock timeout: %d\n", (int)device); } //====================================================== diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/device_lock.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/device_lock.h index b82568fdd7..d6a8c71b97 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/device_lock.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/device_lock.h @@ -15,7 +15,9 @@ enum _RT_DEV_LOCK_E RT_DEV_LOCK_EFUSE = 0, RT_DEV_LOCK_FLASH = 1, RT_DEV_LOCK_CRYPTO = 2, - RT_DEV_LOCK_MAX = 3 + RT_DEV_LOCK_PTA = 3, + RT_DEV_LOCK_WLAN = 4, + RT_DEV_LOCK_MAX = 5 }; typedef uint32_t RT_DEV_LOCK_E; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/osdep_service.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/osdep_service.h index 1eaf214e85..0299c40031 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/osdep_service.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/include/osdep_service.h @@ -1,4 +1,4 @@ -/* mbed Microcontroller Library +/****************************************************************************** * Copyright (c) 2013-2016 Realtek Semiconductor Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,42 +12,44 @@ * 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 __OSDEP_SERVICE_H_ #define __OSDEP_SERVICE_H_ -/* OS dep feature enable */ -#include +/** @addtogroup RTOS + * @{ + */ #ifdef __cplusplus extern "C" { #endif +/*************************** OS dep feature enable *******************************/ + +/****************************************************** + * Macros + ******************************************************/ #define CONFIG_LITTLE_ENDIAN -#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) -#define CONFIG_PLATFORM_AMEBA_X +#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) || defined(CONFIG_PLATFORM_8721D) || defined(CONFIG_PLATFORM_8195BHP) || defined(CONFIG_PLATFORM_8710C) +#define CONFIG_PLATFORM_AMEBA_X 1 #endif #if defined(CONFIG_PLATFORM_8195A) - #ifndef CONFIG_USE_TCM_HEAP #define CONFIG_USE_TCM_HEAP 1 /* USE TCM HEAP */ - #endif #define USE_MUTEX_FOR_SPINLOCK 1 #endif -#if defined(CONFIG_PLATFORM_AMEBA_X) +#if (CONFIG_PLATFORM_AMEBA_X == 1) #define CONFIG_MEM_MONITOR MEM_MONITOR_SIMPLE #else #define CONFIG_MEM_MONITOR MEM_MONITOR_LEAK #endif /* Define compilor specific symbol */ -// -// inline function -// +/*************************** inline functions *******************************/ #if defined ( __ICCARM__ ) #define __inline__ inline #define __inline inline @@ -71,9 +73,20 @@ extern "C" { #endif #include -#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) + +#if defined(CONFIG_PLATFORM_8710C) || defined(CONFIG_PLATFORM_8195BHP) +#include +#include +#if (CONFIG_CMSIS_FREERTOS_EN==1) +#define PLATFORM_FREERTOS 1 +#endif +#else +#if (CONFIG_PLATFORM_AMEBA_X == 1) #include "platform_autoconf.h" -#else //for 8189FM/8189FTV add by frankie_li 20160408 +#endif +#endif + +#if (CONFIG_PLATFORM_AMEBA_X == 0) #ifndef SUCCESS #define SUCCESS 0 #endif @@ -90,38 +103,64 @@ extern "C" { #define FALSE 0 #endif +#ifndef false + #define false 0 +#endif + #ifndef TRUE #define TRUE (!FALSE) #endif + +#ifndef true + #define true (!false) +#endif + + +#ifndef DBG_8195A +#define DBG_8195A +#endif #define _TRUE TRUE #define _FALSE FALSE #endif -#if defined( PLATFORM_FREERTOS) +#if defined(PLATFORM_FREERTOS) #include "freertos_service.h" -#elif defined( PLATFORM_ECOS) +#elif defined(PLATFORM_ECOS) #include "ecos/ecos_service.h" #elif defined(PLATFORM_CMSIS_RTOS) #include "cmsis_rtos_service.h" +#elif defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) +#include "customer_rtos_service.h" #endif #define RTW_MAX_DELAY 0xFFFFFFFF #define RTW_WAIT_FOREVER 0xFFFFFFFF -/* Definitions returned by xTaskGetSchedulerState(). */ +/****************************************************** + * Constants + ******************************************************/ +/** + * @brief Definitions returned by xTaskGetSchedulerState(). + */ + #define OS_SCHEDULER_NOT_STARTED 0 #define OS_SCHEDULER_RUNNING 1 #define OS_SCHEDULER_SUSPENDED 2 - +/****************************************************** + * Structures + ******************************************************/ struct timer_list { _timerHandle timer_hdl; unsigned long data; void (*function)(void *); }; +/****************************************************** + * Type Definitions + ******************************************************/ typedef thread_return (*thread_func_t)(thread_context context); typedef void (*TIMER_FUN)(void *context); typedef int (*event_handler_t)(char *buf, int buf_len, int flags, void *user_data); @@ -129,19 +168,18 @@ typedef int (*event_handler_t)(char *buf, int buf_len, int flags, void *user_dat #define CONFIG_THREAD_COMM_SEMA struct task_struct { const char *task_name; - _thread_hdl_ task; /* I: workqueue thread */ + _thread_hdl_ task; /* I: workqueue thread */ #ifdef CONFIG_THREAD_COMM_SIGNAL - const char *name; /* I: workqueue thread name */ - u32 queue_num; /* total signal num */ - u32 cur_queue_num; /* cur signal num should < queue_num */ + const char *name; /* I: workqueue thread name */ + u32 queue_num; /* total signal num */ + u32 cur_queue_num; /* cur signal num should < queue_num */ #elif defined(CONFIG_THREAD_COMM_SEMA) - _sema wakeup_sema; - _sema terminate_sema; -// _queue work_queue; //TODO + _sema wakeup_sema; /* for internal use only */ + _sema terminate_sema; /* for internal use only */ #endif - u32 blocked; - u32 callback_running; + u32 blocked; /* for internal use only */ + u32 callback_running; /* for internal use only */ }; typedef struct { @@ -165,6 +203,7 @@ struct worker_timer_entry { rtw_worker_thread_t *worker_thread; u32 timeout; }; + #ifdef CONFIG_THREAD_COMM_SIGNAL struct work_struct; typedef void (*work_func_t)(void *context); @@ -182,10 +221,10 @@ struct delayed_work { }; #endif + #ifdef CONFIG_MEM_MONITOR -//----- ------------------------------------------------------------------ -// Memory Monitor -//----- ------------------------------------------------------------------ + +/*************************** Memory Monitor *******************************/ #define MEM_MONITOR_SIMPLE 0x1 #define MEM_MONITOR_LEAK 0x2 @@ -194,19 +233,59 @@ struct delayed_work { #if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK struct mem_entry { struct list_head list; - int size; - void *ptr; + int size; + void *ptr; }; #endif +/** + * @brief This function initializes a memory table. + * @param[in] pmem_table: The pointer to the memory table. + * @param[in] used_num: The number of mem_entry kept in monitor which will be set to 0. + * @return None + */ void init_mem_monitor(_list *pmem_table, int *used_num); + +/** + * @brief This function deinitializes a memory table. + * @param[in] pmem_table: The pointer to the memory table. + * @param[in] used_num: The number of mem_entry kept in monitor. + * @return None + */ void deinit_mem_monitor(_list *pmem_table, int *used_num); + +/** + * @brief This function alloc mem_entry to the memory table. + * @param[in] pmem_table: The pointer to the memory table to be added. + * @param[in] ptr: The pointer to the position to be added. + * @param[in] size: The size of added memory. + * @param[in] used_num: The number of mem_entry kept in monitor which will add 1 after. + * @param[in] flag: MEM_MONITOR_FLAG_WPAS/MEM_MONITOR_FLAG_WIFI_DRV + * @return None + */ void add_mem_usage(_list *pmem_table, void *ptr, int size, int *used_num, int flag); + +/** + * @brief This function frees memory from the memory table. + * @param[in] pmem_table: The pointer to the memory table + * @param[in] ptr: The pointer to the position to be free. + * @param[in] used_num: The number of mem_entry kept in monitor. + * @param[in] flag: MEM_MONITOR_FLAG_WPAS/MEM_MONITOR_FLAG_WIFI_DRV + * @return None + */ void del_mem_usage(_list *pmem_table, void *ptr, int *used_num, int flag); + +/** + * @brief This function get the memory usage of a memory table. + * @param[in] pmem_table: The pointer to the memory table. + * @return The size of the memory used + */ int get_mem_usage(_list *pmem_table); +/*************************** End Memory Monitor *******************************/ #endif -/*********************************** OSDEP API *****************************************/ + +/*************************** Memory Management *******************************/ u8* _rtw_vmalloc(u32 sz); u8* _rtw_zvmalloc(u32 sz); void _rtw_vmfree(u8 *pbuf, u32 sz); @@ -214,11 +293,51 @@ u8* _rtw_zmalloc(u32 sz); u8* _rtw_malloc(u32 sz); void _rtw_mfree(u8 *pbuf, u32 sz); #ifdef CONFIG_MEM_MONITOR + +/** + * @brief This function allocates the virtually contiguous memory. + * @param[in] sz: The size of memory to be allocated. + * @return The pointer to the beginning of the memory + */ u8* rtw_vmalloc(u32 sz); + +/** + * @brief This function allocates the virtually contiguous memory + * and the values of the memory are setted to 0. + * @param[in] sz: The size of memory to be allocated. + * @return The pointer to the beginning of the memory + */ u8* rtw_zvmalloc(u32 sz); + +/** + * @brief This function frees the virtually contiguous memory. + * @param[in] pbuf: The pointer to the beginning of the memory to be free + * @param[in] sz: The size of memory allocated. + * @return None + */ void rtw_vmfree(u8 *pbuf, u32 sz); + +/** + * @brief This function allocates the memory + * and the values of the memory are setted to 0. + * @param[in] sz: The size of memory to be allocated. + * @return The pointer to the beginning of the memory + */ u8* rtw_zmalloc(u32 sz); + +/** + * @brief This function allocates the memory. + * @param[in] sz: The size of memory to be allocated. + * @return The pointer to the beginning of the memory + */ u8* rtw_malloc(u32 sz); + +/** + * @brief This function frees the virtually contiguous memory. + * @param[in] pbuf: The pointer to the beginning of the memory to be free + * @param[in] sz: The size of memory allocated. + * @return None + */ void rtw_mfree(u8 *pbuf, u32 sz); #else #define rtw_vmalloc _rtw_vmalloc @@ -229,100 +348,666 @@ void rtw_mfree(u8 *pbuf, u32 sz); #define rtw_mfree _rtw_mfree #endif #define rtw_free(buf) rtw_mfree((u8 *)buf, 0) + +/** + * @brief This function allocates a 2 dimensional array memory. + * @param[in] h: The height of the 2D array. + * @param[in] w: The width of the 2D array. + * @param[in] size: The size of the each charactor in array. + * @return the pointer to the beginning of the block + */ void* rtw_malloc2d(int h, int w, int size); + +/** + * @brief This function deallocates the block of memory previously allocated to make it available again. + * @param[in] pbuf: Pointer to a memory block previously allocated. + * @param[in] h: The height of the 2D array. + * @param[in] w: The width of the 2D array. + * @param[in] size: The size of the each charactor in array. + * @return None + */ void rtw_mfree2d(void *pbuf, int h, int w, int size); + +/** + * @brief This function copies the values of "sz" bytes from the location pointed to by "src" + * directly to the memory block pointed to by "des". + * @param[in] dst: Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*. + * @param[in] src: Pointer to the source of data to be copied, type-casted to a pointer of type void*. + * @param[in] sz: Size of memory to copy. + * @return None + */ void rtw_memcpy(void* dst, void* src, u32 sz); + +/** + * @brief This function compares the first "sz" bytes of the block of memory pointed by "dst" + * to the first "sz" bytes pointed by "src". + * @param[in] dst: Pointer to block of memory to be compared. + * @param[in] src: pointer to block of memory to compare. + * @param[in] sz: Size of memory to compare. + * @return <0: The first byte that does not match in both memory blocks has a lower value in dst than in src. + * @return 0: The contents of both memory blocks are equal. + * @return <0: The first byte that does not match in both memory blocks has a greater value in dst than in src. + */ int rtw_memcmp(void *dst, void *src, u32 sz); + +/** + * @brief This function sets the first "sz" bytes of the block of memory pointed by "pbuf" to the specified "c". + * @param[in] pbuf: Pointer to the block of memory to fill. + * @param[in] c: Value to be set. + * @param[in] sz: Size of memory to be set to the value "c". + * @return None + */ void rtw_memset(void *pbuf, int c, u32 sz); +/*************************** End Memory Management *******************************/ +/*************************** List *******************************/ + +/** + * @brief This function initializes the head of the list. + * @param[in] list: Pointer to the list to be initialized. + * @return None + */ void rtw_init_listhead(_list *list); + +/** + * @brief This function tests whether a list is empty. + * @param[in] phead: Pointer to the list to test. + * @return _TRUE/_FALSE + */ u32 rtw_is_list_empty(_list *phead); + +/** + * @brief This function adds a new entry after "phead" for the list. + * @param[in] plist: Pointer to the list to be added. + * @param[in] phead: List head to add it after. + * @return None + */ void rtw_list_insert_head(_list *plist, _list *phead); + +/** + * @brief This function adds a new entry before "phead" for the list. + * @param[in] plist: Pointer to the list to be added. + * @param[in] phead: List head to add it before. + * @return None + */ void rtw_list_insert_tail(_list *plist, _list *phead); + +/** + * @brief This function deletes entry from list and reinitialize it. + * @param[in] plist: The element to delete from the list. + * @return None + * @note Caller must check if the list is empty before calling rtw_list_delete + */ void rtw_list_delete(_list *plist); +/*************************** End List *******************************/ + +/*************************** Semaphores *******************************/ +/** + * @brief This function initializes the unnamed semaphore referred to by "sema" to the value "init_val". + * @param[in] sema: Pointer to the semaphore handle to be initialized. + * @param[in] init_val: Initial value for semaphore. + * @return None + */ void rtw_init_sema(_sema *sema, int init_val); -void rtw_free_sema(_sema *sema); -void rtw_up_sema(_sema *sema); -void rtw_up_sema_from_isr(_sema *sema); -u32 rtw_down_sema(_sema *sema); -u32 rtw_down_timeout_sema(_sema *sema, u32 timeout); -void rtw_mutex_init(_mutex *pmutex); -void rtw_mutex_free(_mutex *pmutex); -void rtw_mutex_put(_mutex *pmutex); -void rtw_mutex_get(_mutex *pmutex); -int rtw_mutex_get_timeout(_mutex *pmutex, u32 timeout_ms); -void rtw_enter_critical(_lock *plock, _irqL *pirqL); -void rtw_exit_critical(_lock *plock, _irqL *pirqL); -void rtw_enter_critical_from_isr(_lock *plock, _irqL *pirqL); -void rtw_exit_critical_from_isr(_lock *plock, _irqL *pirqL); -void rtw_enter_critical_bh(_lock *plock, _irqL *pirqL); -void rtw_exit_critical_bh(_lock *plock, _irqL *pirqL); -int rtw_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL); -void rtw_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL); -void rtw_spinlock_init(_lock *plock); -void rtw_spinlock_free(_lock *plock); -void rtw_spinlock_init(_lock *plock); -void rtw_spinlock_free(_lock *plock); -void rtw_spin_lock(_lock *plock); -void rtw_spin_unlock(_lock *plock); -void rtw_spinlock_irqsave(_lock *plock, _irqL *irqL); -void rtw_spinunlock_irqsave(_lock *plock, _irqL *irqL); +/** + * @brief This function deletes the semaphore. + * @param[in] sema: The semaphore to be deleted. + * @return None + */ +void rtw_free_sema(_sema *sema); + +/** + * @brief This function releases the semaphore. + * This macro must not be used from an ISR. + * @param[in] sema: The semaphore to be released. + * @return None + */ +void rtw_up_sema(_sema *sema); + +/** + * @brief This function releases the semaphore. + * This macro can be used from an ISR. + * @param[in] sema: The semaphore to be released. + * @return None + */ +void rtw_up_sema_from_isr(_sema *sema); + +/** + * @brief This function acquires the semaphore. If no more tasks are allowed to acquire the semaphore, + * calling this function will put the task to sleep until the semaphore is up. + * @param[in] sema: The semaphore to be acquired. + * @return pdTRUE: The semaphore was obtained. + * @return pdFALSE: Obtain the semaphore failed. + */ +u32 rtw_down_sema(_sema *sema); + +/** + * @brief This function acquires the semaphore. If no more tasks are allowed to acquire the semaphore, + * calling this function will put the task to sleep until the semaphore is up. + * @param[in] sema: The semaphore to be acquired. + * @param[in] timeout: The time in ms to wait for the semaphore to become available. + * @return pdTRUE: The semaphore was obtained. + * @return pdFALSE: Timeout without the semaphore becoming available. + */ +u32 rtw_down_timeout_sema(_sema *sema, u32 timeout); +/*************************** End Semaphores *******************************/ + +/*************************** Mutexes *******************************/ +/** + * @brief This function implements a mutex semaphore by using the existing queue mechanism. + * @param[in] pmutex: Pointer to the created mutex semaphore. + * @return None + */ +void rtw_mutex_init(_mutex *pmutex); + +/** + * @brief This function deletes the mutex semaphore. + * @param[in] pmutex: Pointer to the mutex semaphore to be deleted. + * @return None + */ +void rtw_mutex_free(_mutex *pmutex); + +/** + * @brief This function releases a mutex semaphore. + * @param[in] pmutex: Pointer to the mutex semaphore to be released. + * @return None + */ +void rtw_mutex_put(_mutex *pmutex); + +/** + * @brief This function obtains a mutex semaphore. + * @param[in] pmutex: Pointer to the mutex semaphore being taken - obtained when + * the mutex semaphore was created. + * @return None + */ +void rtw_mutex_get(_mutex *pmutex); + +/** + * @brief This function obtains a mutex semaphore with a timeout setting. + * @param[in] pmutex: Pointer to the mutex semaphore being taken - obtained when + * the mutex semaphore was created. + * @param[in] timeout: The time in ms to wait for the semaphore to become available. + * @return 0: The semaphore was obtained. + * @return -1: Timeout without the semaphore becoming available. + */ +int rtw_mutex_get_timeout(_mutex *pmutex, u32 timeout_ms); +/*************************** End Mutexes *******************************/ + +/*************************** SchedulerControl *******************************/ +/** + * @brief This function marks the start of a critical code region. + * Preemptive context switches cannot occur when in a critical region. + * @param[in] plock: Pointer to the spin lock semaphore. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + * @note: This may alter the stack (depending on the portable implementation) + * so must be used with care! + */ +void rtw_enter_critical(_lock *plock, _irqL *pirqL); + +/** + * @brief This function marks end of a critical code region. Preemptive context + * switches cannot occur when in a critical region. + * @param[in] plock: Pointer to the spin lock semaphore. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + * @note: This may alter the stack (depending on the portable implementation) + * so must be used with care! + */ +void rtw_exit_critical(_lock *plock, _irqL *pirqL); + +/** + * @brief This function marks the start of a critical code region from isr. + * @param[in] plock: Pointer to the spin lock semaphore. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + */ +void rtw_enter_critical_from_isr(_lock *plock, _irqL *pirqL); + +/** + * @brief This function marks the end of a critical code region from isr. + * @param[in] plock: Pointer to the spin lock semaphore. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + */ +void rtw_exit_critical_from_isr(_lock *plock, _irqL *pirqL); + +/** + * @brief This function obtains a spin lock semaphore. + * @param[in] plock: Pointer to the spin lock semaphore being taken - obtained when + * the mutex semaphore was created. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + */ +void rtw_enter_critical_bh(_lock *plock, _irqL *pirqL); + +/** + * @brief This function releases a spin lock semaphore. + * @param[in] plock: Pointer to the spin lock semaphore to be released. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + */ +void rtw_exit_critical_bh(_lock *plock, _irqL *pirqL); + +/** + * @brief This function obtains a semaphore. + * @param[in] pmutex: The handle to the mutex semaphore to be obtained. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + */ +int rtw_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL); + +/** + * @brief This function releases a semaphore. + * @param[in] pmutex: The handle to the mutex semaphore to be released. + * @param[in] pirqL: Pointer to the IRQ. + * @return None + */ +void rtw_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL); + +/** + * @brief This function will lock cpu. Can be used when xip active and want to do some flash operation. + * @return None + */ +void rtw_cpu_lock(void); + + /** + * @brief This function unlock cpu. + * @return None + */ +void rtw_cpu_unlock(void); + +/*************************** End SchedulerControl *******************************/ + +/*************************** Semaphores *******************************/ + +/** + * @brief This function implements a spin lock semaphore by using the existing queue mechanism. + * @param[in] plock: Pointer to the created spin lock semaphore. + * @return None + */ +void rtw_spinlock_init(_lock *plock); + +/** + * @brief This function deletes the spin lock semaphore. + * @param[in] pmutex: Pointer to the spin lock semaphore to be deleted. + * @return None + */ +void rtw_spinlock_free(_lock *plock); + +/** + * @brief This function obtains a spin lock semaphore. + * @param[in] plock: Pointer to the spin lock semaphore being taken - obtained when + * the mutex semaphore was created. + * @return None + */ +void rtw_spin_lock(_lock *plock); + +/** + * @brief This function releases a spin lock semaphore. + * @param[in] plock: Pointer to the spin lock semaphore to be released. + * @return None + */ +void rtw_spin_unlock(_lock *plock); + +/** + * @brief This function marks the start of a critical code region and + * obtains a spin lock semaphore. + * @param[in] plock: Pointer to the spin lock semaphore being taken - obtained when + * the mutex semaphore was created. + * @param[in] irqL: Pointer to the IRQ. + * @return None + */ +void rtw_spinlock_irqsave(_lock *plock, _irqL *irqL); + +/** + * @brief This function releases a spin lock semaphore and + marks the end of a critical code region. + * @param[in] plock: Pointer to the spin lock semaphore to be released. + * @param[in] irqL: Pointer to the IRQ. + * @return None + */ +void rtw_spinunlock_irqsave(_lock *plock, _irqL *irqL); +/*************************** End Semaphores *******************************/ + +/*************************** Queues *******************************/ + +/** + * @brief This function creates a new queue instance. + * @param[in] queue: The handle to the newly created queue. + * @param[in] name: The name of the queue + * @param[in] message_size: The number of bytes each message in the queue will require. + * @param[in] number_of_messages: The maximum number of messages that kthe queue can contain. + * @return 0: Creating queue success + * @return -1: Creating queue fail + */ int rtw_init_xqueue( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages ); + +/** + * @brief This function posts a message to the back of a queue. + * The message is queued by copy, not by reference. + * @param[in] queue: The handle to the queue on which the message is to be posted. + * @param[in] message: The pointer to the message that is to be placed on the queue. + * @param[in] timeout_ms: The maximum amout of time the task should block waiting for + the space to become available on the queue, should it already be full. + The time is defined in ms. + * @return 0: The message was successfully posted. + * @return -1: The message was not posted. + */ int rtw_push_to_xqueue( _xqueue* queue, void* message, u32 timeout_ms ); + +/** + * @brief This function receives a message from a queue. + * The message is recieved by copy so a buffer adequate size must be provided. + * @param[in] queue: The handle to the queue from which the message is to be received. + * @param[in] message: The pointer to the buffer into which the received message will be copied. + * @param[in] timeout_ms: The maximum amout of time the task should block waiting for a message to + * receive should the queue be empty at the time of the call. + The time is defined in ms. + * @return 0: A message was successfully received from the queue. + * @return -1: No message was received from the queue. + */ int rtw_pop_from_xqueue( _xqueue* queue, void* message, u32 timeout_ms ); + +/** + * @brief Delete a queue - freeing all the memory allocated for storing of messages placed on the queue. + * @param[in] queue: The handle to the queue to be deleted. + * @return 0: The queue was successfully deleted. + * @return -1: The queue was not empty so cannot be deleted. + */ int rtw_deinit_xqueue( _xqueue* queue ); +/** + * @brief This function creates a new queue instance. + * @param[in] pqueue: The handle to the newly created queue. + * @return None + */ void rtw_init_queue(_queue *pqueue); void rtw_deinit_queue(_queue *pqueue); u32 rtw_is_queue_empty(_queue *pqueue); + +/** + * @brief This function tests whether the queue is empty. + * @param[in] pqueue: The handle to the queue to be tested. + * @return None + */ u32 rtw_queue_empty(_queue *pqueue); + +/** + * @brief This function tests whether the "pelement" is at the "queue". + * @param[in] queue: The pointer to the queue that to be tested. + * @param[in] pelement: The element that to be tested. + * @return _TRUE/_FALSE + */ u32 rtw_end_of_queue_search(_list *queue, _list *pelement); _list* rtw_get_queue_head(_queue *queue); +/*************************** End Queues *******************************/ +/*************************** Time Management *******************************/ + +/** + * @brief Get the count of ticks since the vTaskStartScheduler was called. + * @return The count of ticks since the vTaskStartScheduler was called. + */ u32 rtw_get_current_time(void); -u32 rtw_systime_to_ms(u32 systime); -u32 rtw_systime_to_sec(u32 systime); -u32 rtw_ms_to_systime(u32 ms); -u32 rtw_sec_to_systime(u32 sec); -s32 rtw_get_passing_time_ms(u32 start); -s32 rtw_get_time_interval_ms(u32 start, u32 end); +/** + * @brief Convert system time to milliseconds. + * @param[in] systime: The system time to be converted. + * @return : The milliseconds that converted by the system time. + */ +u32 rtw_systime_to_ms(u32 systime); + +/** + * @brief Convert system time to seconds. + * @param[in] systime: The system time to be converted. + * @return : The seconds that converted by the system time. + */ +u32 rtw_systime_to_sec(u32 systime); + +/** + * @brief Convert milliseconds to system time. + * @param[in] systime: The milliseconds to be converted. + * @return : The system time that converted by the milliseconds. + */ +u32 rtw_ms_to_systime(u32 ms); + +/** + * @brief Convert seconds to system time. + * @param[in] systime: The seconds to be converted. + * @return : The system time that converted by the seconds. + */ +u32 rtw_sec_to_systime(u32 sec); + +/** + * @brief Get the passing time from the "start" in milliseconds. + * @param[in] start: The start time which is in system time format. + * @return : The passing time from "start" in milliseconds. + */ +s32 rtw_get_passing_time_ms(u32 start); + +/** + * @brief Get the interval time from the "start" to "end" in milliseconds. + * @param[in] start: The start time which is in system time format. + * @param[in] end: The end time which is in system time format. + * @return : The interval time from "start" to "end" in milliseconds. + */ +s32 rtw_get_time_interval_ms(u32 start, u32 end); +/*************************** End Time Management *******************************/ + +/** + * @brief This function suspends execution of the calling thread for "ms" milliseconds. + * @param[in] ms: The time that the function sleep in milliseconds + * @return None +*/ void rtw_msleep_os(int ms); + +/** + * @brief This function suspends execution of the calling thread for "us" microseconds. + * @param[in] ms: The time that the function sleep in microseconds + * @return None +*/ void rtw_usleep_os(int us); + +/** + * @brief This function converts the initial portion of the string to integer. + * @param[in] s: The pointer to the string to be converted. + * @return The converted value. +*/ u32 rtw_atoi(u8* s); + +/** + * @brief This function delays a task for the giving time in milliseconds. + * @param[in] ms: The amount of time, in milliseconds, that the calling task should block. + * @return None +*/ void rtw_mdelay_os(int ms); + +/** + * @brief This function delays a task for the giving time in microseconds. + * @param[in] ms: The amount of time, in microseconds, that the calling task should block. + * @return None +*/ void rtw_udelay_os(int us); + +/** + * @brief This function for forcing a context switch. + * @return None +*/ void rtw_yield_os(void); -//Atomic integer operations +/*************************** ATOMIC Integer *******************************/ + +/** + * @brief This function atomically sets the value of the variable. + * @param[in] v: Pointer of type atomic_t that to be set value. + * @param[in] i: Required value. + * @return None + * @note The guaranteed useful range of an atomic_t is only 24 bits. +*/ void ATOMIC_SET(ATOMIC_T *v, int i); + +/** + * @brief This function atomically reads the value of the variable. + * @param[in] v: Pointer of type atomic_t that to be read. + * @return The value of the variable. + * @note The guaranteed useful range of an atomic_t is only 24 bits. +*/ int ATOMIC_READ(ATOMIC_T *v); + +/** + * @brief This function adds "i" to the contained "v". + * @param[in] v: Pointer of type atomic_t. + * @param[in] i: value to add. + * @return None +*/ void ATOMIC_ADD(ATOMIC_T *v, int i); + +/** + * @brief This function subtracts "i" from th econtained "v". + * @param[in] v: Pointer of type atomic_t. + * @param[in] i: value to subtract. + * @return None +*/ void ATOMIC_SUB(ATOMIC_T *v, int i); + +/** + * @brief This function adds 1 to the contained "v". + * @param[in] v: Pointer of type atomic_t. + * @return None +*/ void ATOMIC_INC(ATOMIC_T *v); + +/** + * @brief This function subtracts 1 from th econtained "v". + * @param[in] v: Pointer of type atomic_t. + * @return None +*/ void ATOMIC_DEC(ATOMIC_T *v); + +/** + * @brief This function adds "i" to the contained "v" and returns the result. + * @param[in] v: Pointer of type atomic_t. + * @param[in] i: value to add. + * @return None +*/ int ATOMIC_ADD_RETURN(ATOMIC_T *v, int i); + +/** + * @brief This function subtracts "i" from th econtained "v" and returns the result. + * @param[in] v: Pointer of type atomic_t. + * @param[in] i: value to subtract. + * @return None +*/ int ATOMIC_SUB_RETURN(ATOMIC_T *v, int i); + +/** + * @brief This function adds 1 to the contained "v" and returns the result. + * @param[in] v: Pointer of type atomic_t. + * @return None +*/ int ATOMIC_INC_RETURN(ATOMIC_T *v); + +/** + * @brief This function subtracts 1 from th econtained "v" and returns the result. + * @param[in] v: Pointer of type atomic_t. + * @return None +*/ int ATOMIC_DEC_RETURN(ATOMIC_T *v); + +/** + * @brief This function subtracts 1 from th econtained "v" and test if the result equals 0. + * @param[in] v: Pointer of type atomic_t. + * @return 0: The result after subtracting 1 is 0 + * @return -1: The result after subtracting 1 is not 0 +*/ int ATOMIC_DEC_AND_TEST(ATOMIC_T *v); +/*************************** End ATOMIC *******************************/ u64 rtw_modular64(u64 x, u64 y); + +/** + * @brief This function generates random bytes. + * @param[in] dst: The pointer to the buffer to store the random bytes. + * @param[in] size: The size of the random bytes. + * @return 0 +*/ int rtw_get_random_bytes(void* dst, u32 size); + +/** + * @brief This function gets the available heap size. + * @return The value of the available heap size. +*/ u32 rtw_getFreeHeapSize(void); + void flush_signals_thread(void); +/** + * @brief This function indicates that the WLAN needs to stay on which means cannot go into power saving mode. + * @return None + * @note Defining configUSE_WAKELOCK_PMU 1 in "FreeRTOSConfig.h" needs to be done before compiling, + * or this API won't be effective. + */ void rtw_acquire_wakelock(void); + +/** + * @brief This function indicates that the WLAN does not need to stay on which means can go into power saving mode. + * @return None + * @note Defining configUSE_WAKELOCK_PMU 1 in "FreeRTOSConfig.h" needs to be done before compiling, + * or this API won't be effective. + */ void rtw_release_wakelock(void); void rtw_wakelock_timeout(u32 timeout); /*********************************** Thread related *****************************************/ + +/** + * @brief This function creates a new task and adds it to the list of tasks that are ready to run. + * @param[in] task: The task stucture which will store the task related infomation. + * @param[in] name: A descriptive name for the task. + * @param[in] stack_size: The size of the task stack specified as the variables the stack can hold. + * @param[in] priority: The priority at which the task should run. + * @param[in] func: The task entry function. + * @param[in] thctx: The pointer that will be used as the parameter for the task being created. + * @return pdPASS: The task was successfully created and added to a ready list. + * @return other error code defined in the file errors.h. + * @note For the task name, please do not use "rtw_little_wifi_mcu_thread", "rtw_check_in_req_state_thread", + "rtw_TDMA_change_state_thread", "xmit_thread", "recv_thread", "rtw_recv_tasklet", "rtw_xmit_tasklet", + "rtw_interrupt_thread", "cmd_thread", "usb_init", "MSC_BULK_CMD" and "MSC_BULK_DATA". + */ int rtw_create_task(struct task_struct *task, const char *name, u32 stack_size, u32 priority, thread_func_t func, void *thctx); + +/** + * @brief This function deletes a task. + * @param[in] task: The task stucture which will be deleted. + * @return None + */ void rtw_delete_task(struct task_struct * task); + +/** + * @brief This function wake up a task. + * @param[in] task: The task stucture which will be waked up. + * @return None + */ void rtw_wakeup_task(struct task_struct *task); + +/** + * @brief This function creates a new worker thread. + * @param[in] worker_thread: The pointer to the worker thread stucture. + * @param[in] priority: The priority of the thread. + * @param[in] stack_size: The size of the thread stack specified as the variables the stack can hold. + * @param[in] event_queue_size: The queue size of events. + * @return SUCCESS/FAIL. + */ int rtw_create_worker_thread( rtw_worker_thread_t* worker_thread, u8 priority, u32 stack_size, u32 event_queue_size ); + +/** + * @brief This function deletes a worker thread. + * @param[in] worker_thread: The pointer to the worker thread stucture to be deleted. + * @return SUCCESS/FAIL. + */ int rtw_delete_worker_thread( rtw_worker_thread_t* worker_thread ); #if 0 //TODO @@ -332,32 +1017,136 @@ int rtw_queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dw BOOLEAN rtw_cancel_delayed_work(struct delayed_work *dwork); #endif +/** + * @brief This function prints the name of the thread in DBG_INFO. + * @param[in] name: The name of the thread. + * @return None + */ void rtw_thread_enter(char *name); + +/** + * @brief This function exits the calling thread. + * @return None + */ void rtw_thread_exit(void); + +/** + * @brief This function gets the scheduler state of the calling thread. + * @return OS_SCHEDULER_NOT_STARTED + * @return OS_SCHEDULER_RUNNING + * @return OS_SCHEDULER_SUSPENDED + */ u8 rtw_get_scheduler_state(void); +/*************************** End Threads *******************************/ #ifdef PLATFORM_LINUX #define rtw_warn_on(condition) WARN_ON(condition) #else #define rtw_warn_on(condition) do {} while (0) #endif -/*********************************** Timer related *****************************************/ +/*************************** Timers *******************************/ + +/** + * @brief This function creates a new software timer instance. + * @param[in] pcTimerName: A text name that is assigned to the timer. + * @param[in] xTimerPeriodInTicks: The timer period which is defined in tick periods. + * @param[in] uxAutoReload: If uxAutoReload is set to pdTRUE then the timer will + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter. If + * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and + * enter the dormant state after it expires. + * @param[in] pvTimerID: An identifier that is assigned to the timer being created. + * @param[in] pxCallbackFunction: The function to call when the timer expires. + * @return If the timer is successfully create then a handle to the newly + * created timer is returned. If the timer cannot be created, then 0 is returned. + */ _timerHandle rtw_timerCreate( const signed char *pcTimerName, osdepTickType xTimerPeriodInTicks, u32 uxAutoReload, void * pvTimerID, TIMER_FUN pxCallbackFunction ); -u32 rtw_timerDelete( _timerHandle xTimer, - osdepTickType xBlockTime ); + +/** + * @brief This function deletes a timer that was previously created using rtw_timerCreate. + * @param[in] xTimer: The handle of the timer being deleted. + * @param[in] xBlockTime: Specifies th etime, in ticks, that the calling task should be held in the Blocked + * State to wait for the delete command to be successfully sent to the timer command queue, + * should the queue already be full when rtw_timerDelete was called. + * @return pdFAIL will be returned if the delete command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system. + */ +u32 rtw_timerDelete( _timerHandle xTimer, osdepTickType xBlockTime ); + +/** + * @brief This function queries a timer to see if it is active or dormant. + * @param[in] xTimer: The timer being queried. + * @return pdFALSE will be returned if the timer is dormant. A value other than + * pdFALSE will be returned if the timer is active. + * @note A timer will be dormant if: + * 1) It has been created but not started, or + * 2) It is an expired one-shot timer that has not been restarted. + */ u32 rtw_timerIsTimerActive( _timerHandle xTimer ); -u32 rtw_timerStop( _timerHandle xTimer, - osdepTickType xBlockTime ); + +/** + * @brief This function stops a timer that was previously started. + * @param[in] xTimer: The handle of the timer being stopped. + * @param[in] xBlockTime: Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the stop command to be successfully + * sent to the timer command queue, should the queue already be full when + * rtw_timerStop() was called. + * @return pdFAIL will be returned if the stop command could not be sent to + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will + * be returned if the command was successfully sent to the timer command queue. + * When the command is actually processed will depend on the priority of the + * timer service/daemon task relative to other tasks in the system. + */ +u32 rtw_timerStop( _timerHandle xTimer, osdepTickType xBlockTime ); + +/** + * @brief This function changes the period of a timer that was previously created. + * @param[in] xTimer: The handle of the timer that is having its period changed. + * @param[in] xNewPeriod: The new period for xTimer. + * @param[in] xBlockTime: Specifies the time, in ticks, that the calling task should + * be held in the Blocked state to wait for the change period command to be + * successfully sent to the timer command queue, should the queue already be + * full when rtw_timerChangePeriod() was called. + * @return pdFAIL will be returned if the change period command could not be + * sent to the timer command queue even after xTicksToWait ticks had passed. + * pdPASS will be returned if the command was successfully sent to the timer + * command queue. When the command is actually processed will depend on the + * priority of the timer service/daemon task relative to other tasks in the + * system. + */ u32 rtw_timerChangePeriod( _timerHandle xTimer, osdepTickType xNewPeriod, osdepTickType xBlockTime ); -/*********************************** OSDEP API end *****************************************/ +void *rtw_timerGetID( _timerHandle xTimer ); + +u32 rtw_timerStart( _timerHandle xTimer, osdepTickType xBlockTime ); + +u32 rtw_timerStartFromISR( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + +u32 rtw_timerStopFromISR( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + +u32 rtw_timerResetFromISR( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + +u32 rtw_timerChangePeriodFromISR( _timerHandle xTimer, + osdepTickType xNewPeriod, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + +u32 rtw_timerReset( _timerHandle xTimer, + osdepTickType xBlockTime ); + + +/*************************** End Timers *******************************/ #define LIST_CONTAINOR(ptr, type, member) \ ((type *)((char *)(ptr)-(SIZE_T)((char *)&((type *)ptr)->member - (char *)ptr))) @@ -424,6 +1213,8 @@ __inline static u32 bitshift(u32 bitmask) return i; } +#define rtw_min(a, b) ((a > b) ? b : a) + /* Macros for handling unaligned memory accesses */ #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1])) @@ -518,6 +1309,8 @@ struct osdep_service_ops { void (*rtw_exit_critical_bh)(_lock *plock, _irqL *pirqL); int (*rtw_enter_critical_mutex)(_mutex *pmutex, _irqL *pirqL); void (*rtw_exit_critical_mutex)(_mutex *pmutex, _irqL *pirqL); + void (*rtw_cpu_lock)(void); + void (*rtw_cpu_unlock)(void); void (*rtw_spinlock_init)(_lock *plock); void (*rtw_spinlock_free)(_lock *plock); void (*rtw_spin_lock)(_lock *plock); @@ -576,16 +1369,36 @@ struct osdep_service_ops { u32 (*rtw_timerChangePeriod)( _timerHandle xTimer, osdepTickType xNewPeriod, osdepTickType xBlockTime ); + void* (*rtw_timerGetID)( _timerHandle xTimer ); + u32 (*rtw_timerStart)( _timerHandle xTimer, + osdepTickType xBlockTime ); + u32 (*rtw_timerStartFromISR)( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + + u32 (*rtw_timerStopFromISR)( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + + u32 (*rtw_timerResetFromISR)( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + + u32 (*rtw_timerChangePeriodFromISR)( _timerHandle xTimer, + osdepTickType xNewPeriod, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ); + + u32 (*rtw_timerReset)( _timerHandle xTimer, + osdepTickType xBlockTime ); void (*rtw_acquire_wakelock)(void); void (*rtw_release_wakelock)(void); void (*rtw_wakelock_timeout)(u32 timeoutMs); u8 (*rtw_get_scheduler_state)(void); }; -/*********************************** OSDEP API end *****************************************/ #ifdef __cplusplus } #endif +/*\@}*/ + #endif //#ifndef __OSDEP_SERVICE_H_ + diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/osdep_service.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/osdep_service.c index 4b738e54d3..37bfc9821a 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/osdep_service.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/osdep_service.c @@ -5,6 +5,10 @@ ******************************************************************************/ #include +#if CONFIG_USE_TCM_HEAP +#include "tcm_heap.h" +#endif + #define OSDEP_DBG(x, ...) do {} while(0) extern struct osdep_service_ops osdep_service; @@ -53,7 +57,7 @@ int RTW_STATUS_CODE(int error_code) u32 rtw_atoi(u8* s) { int num=0,flag=0; - size_t i; + int i; for(i=0;i<=strlen((char *)s);i++) { @@ -70,8 +74,10 @@ u32 rtw_atoi(u8* s) return(num); } +#if CONFIG_USE_TCM_HEAP void *tcm_heap_malloc(int size); void *tcm_heap_calloc(int size); +#endif u8* _rtw_vmalloc(u32 sz) { u8 *pbuf = NULL; @@ -202,11 +208,10 @@ void add_mem_usage(_list *pmem_table, void *ptr, int size, int *used_num, int fl return; } else{ - if(flag == MEM_MONITOR_FLAG_WPAS) { + if(flag == MEM_MONITOR_FLAG_WPAS) DBG_INFO("Alloc memory at %p with size of %d", ptr, size); - } else { + else DBG_INFO("Alloc memory at %p with size of %d", ptr, size); - } } #if CONFIG_MEM_MONITOR & MEM_MONITOR_LEAK mem_entry = (struct mem_entry *) _rtw_malloc(sizeof(struct mem_entry)); @@ -608,6 +613,22 @@ void rtw_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL) OSDEP_DBG("Not implement osdep service: rtw_exit_critical_mutex"); } +void rtw_cpu_lock(void) +{ + if(osdep_service.rtw_cpu_lock) + osdep_service.rtw_cpu_lock(); + else + OSDEP_DBG("Not implement osdep service: rtw_cpu_lock"); +} + +void rtw_cpu_unlock(void) +{ + if(osdep_service.rtw_cpu_unlock) + osdep_service.rtw_cpu_unlock(); + else + OSDEP_DBG("Not implement osdep service: rtw_cpu_unlock"); +} + void rtw_init_queue(_queue *pqueue) { rtw_init_listhead(&(pqueue->queue)); @@ -1159,6 +1180,83 @@ u32 rtw_timerChangePeriod( _timerHandle xTimer, return 0; } +void *rtw_timerGetID( _timerHandle xTimer ) +{ + if(osdep_service.rtw_timerGetID) + return osdep_service.rtw_timerGetID(xTimer); + else + OSDEP_DBG("Not implement osdep service: rtw_timerGetID"); + + return NULL; +} + +u32 rtw_timerStart( _timerHandle xTimer, osdepTickType xBlockTime ) +{ + if(osdep_service.rtw_timerStart) + return osdep_service.rtw_timerStart(xTimer, xBlockTime); + else + OSDEP_DBG("Not implement osdep service: rtw_timerStart"); + + return 0; +} + +u32 rtw_timerStartFromISR( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ) +{ + if(osdep_service.rtw_timerStartFromISR) + return osdep_service.rtw_timerStartFromISR(xTimer, pxHigherPriorityTaskWoken); + else + OSDEP_DBG("Not implement osdep service: rtw_timerStartFromISR"); + + return 0; +} + +u32 rtw_timerStopFromISR( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ) +{ + if(osdep_service.rtw_timerStopFromISR) + return osdep_service.rtw_timerStopFromISR(xTimer, pxHigherPriorityTaskWoken); + else + OSDEP_DBG("Not implement osdep service: rtw_timerStopFromISR"); + + return 0; +} + +u32 rtw_timerResetFromISR( _timerHandle xTimer, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ) +{ + if(osdep_service.rtw_timerResetFromISR) + return osdep_service.rtw_timerResetFromISR(xTimer, pxHigherPriorityTaskWoken); + else + OSDEP_DBG("Not implement osdep service: rtw_timerResetFromISR"); + + return 0; +} + +u32 rtw_timerChangePeriodFromISR( _timerHandle xTimer, + osdepTickType xNewPeriod, + osdepBASE_TYPE *pxHigherPriorityTaskWoken ) +{ + if(osdep_service.rtw_timerChangePeriodFromISR) + return osdep_service.rtw_timerChangePeriodFromISR(xTimer, xNewPeriod, pxHigherPriorityTaskWoken); + else + OSDEP_DBG("Not implement osdep service: rtw_timerChangePeriodFromISR"); + + return 0; +} + +u32 rtw_timerReset( _timerHandle xTimer, + osdepTickType xBlockTime ) +{ + if(osdep_service.rtw_timerReset) + return osdep_service.rtw_timerReset(xTimer, xBlockTime); + else + OSDEP_DBG("Not implement osdep service: rtw_timerReset"); + + return 0; +} + + #if 0 //TODO void rtw_init_delayed_work(struct delayed_work *dwork, work_func_t func, const char *name) { diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/tcm_heap.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/tcm_heap.c index 40c1df764e..203a83039b 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/tcm_heap.c +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/os_dep/tcm_heap.c @@ -13,7 +13,7 @@ #define ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1)) -#define TCM_HEAP_SIZE (40*1024) +#define TCM_HEAP_SIZE (40*1024) static struct Heap g_tcm_heap; @@ -27,9 +27,9 @@ HEAP_DEFINE_BUF(tcm_heap, TCM_HEAP_SIZE); static int g_heap_inited=0; static _lock tcm_lock; -#ifdef PLATFORM_FREERTOS +#if defined(PLATFORM_FREERTOS) extern void vPortSetExtFree( void (*free)( void *p ), uint32_t upper, uint32_t lower ); -#else +#elif defined(PLATFORM_CMSIS_RTOS) extern void rtw_set_mfree_ext( void (*free)( void *p ), uint32_t upper, uint32_t lower ); #endif void tcm_heap_init(void) @@ -52,7 +52,7 @@ void tcm_heap_init(void) #if defined(PLATFORM_FREERTOS) // let RTOS know how to free memory if using as task stack vPortSetExtFree(tcm_heap_free, 0x20000000, 0x1fff0000); -#elif defined (PLATFORM_CMSIS_RTOS) +#elif defined(PLATFORM_CMSIS_RTOS) rtw_set_mfree_ext(tcm_heap_free, 0x20000000, 0x1fff0000); #endif } @@ -67,7 +67,7 @@ void tcm_heap_dump(void) chunk; prev = chunk, chunk = chunk->next) { - printf(" prev %p, chunk %p, size %d \n\r", prev, chunk, chunk->size); + printf(" prev %x, chunk %x, size %d \n\r", prev, chunk, chunk->size); } printf("--------------\n\r"); } @@ -246,10 +246,20 @@ int tcm_heap_freeSpace(void) */ void *tcm_heap_malloc(int size) { +#if defined(PLATFORM_CMSIS_RTOS) + int64_t *mem; + // Make sure that block is 8-byte aligned + size = (size + 7U) & ~((uint32_t)7U); + size += sizeof(int64_t); + mem = (int64_t *)tcm_heap_allocmem(size); +#else int *mem; - size += sizeof(int); - if ((mem = (int*)tcm_heap_allocmem(size))){ + mem = (int*)tcm_heap_allocmem(size); +#endif + + + if (mem){ *mem++ = size; } @@ -262,8 +272,8 @@ void *tcm_heap_malloc(int size) void *tcm_heap_calloc(int size) { void *mem; - - if ((mem = tcm_heap_malloc(size))) + mem = tcm_heap_malloc(size); + if (mem) memset(mem, 0, size); return mem; @@ -284,7 +294,11 @@ void *tcm_heap_calloc(int size) */ void tcm_heap_free(void *mem) { +#if defined(PLATFORM_CMSIS_RTOS) + int64_t *_mem = (int64_t *)mem; +#else int *_mem = (int *)mem; +#endif if (_mem) { diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_adc.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_adc.h index 819454c28f..1a0127a896 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_adc.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_adc.h @@ -45,7 +45,8 @@ enum _ADC_DBG_LVL_ { typedef uint32_t ADC_DBG_LVL; typedef uint32_t * PADC_DBG_LVL; -#if defined (CONFIG_DEBUG_LOG) && defined (CONFIG_DEBUG_LOG_ADC_HAL) +#ifdef CONFIG_DEBUG_LOG +#ifdef CONFIG_DEBUG_LOG_ADC_HAL #define DBG_8195A_ADC(...) do{ \ _DbgDump("\r"ADC_PREFIX __VA_ARGS__);\ @@ -63,6 +64,7 @@ typedef uint32_t * PADC_DBG_LVL; #define DBG_8195A_ADC(...) #define DBG_8195A_ADC_LVL(...) #endif +#endif //================ ADC HAL Related Enumeration ================== @@ -213,14 +215,10 @@ typedef struct _SAL_ADC_USERCB_ADPT_ { // ADC user callback structure typedef struct _SAL_ADC_USER_CB_ { - PSAL_ADC_USERCB_ADPT pTXCB; //ADC Transmit Callback - PSAL_ADC_USERCB_ADPT pTXCCB; //ADC Transmit Complete Callback PSAL_ADC_USERCB_ADPT pRXCB; //ADC Receive Callback PSAL_ADC_USERCB_ADPT pRXCCB; //ADC Receive Complete Callback - PSAL_ADC_USERCB_ADPT pRDREQCB; //ADC Read Request Callback PSAL_ADC_USERCB_ADPT pERRCB; //ADC Error Callback - PSAL_ADC_USERCB_ADPT pDMATXCB; //ADC DMA Transmit Callback - PSAL_ADC_USERCB_ADPT pDMATXCCB; //ADC DMA Transmit Complete Callback + PSAL_ADC_USERCB_ADPT pIDMARXCCB; //ADC Error Callback PSAL_ADC_USERCB_ADPT pDMARXCB; //ADC DMA Receive Callback PSAL_ADC_USERCB_ADPT pDMARXCCB; //ADC DMA Receive Complete Callback }SAL_ADC_USER_CB, *PSAL_ADC_USER_CB; @@ -229,7 +227,7 @@ typedef struct _SAL_ADC_USER_CB_ { typedef struct _SAL_ADC_TRANSFER_BUF_ { u32 DataLen; //ADC Transmfer Length u32 *pDataBuf; //ADC Transfer Buffer Pointer - u32 RSVD; // + u16 *pUserDataBuf; // }SAL_ADC_TRANSFER_BUF,*PSAL_ADC_TRANSFER_BUF; typedef struct _SAL_ADC_DMA_USER_DEF_ { diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_common.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_common.h new file mode 100644 index 0000000000..113c1a185a --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_common.h @@ -0,0 +1,17 @@ +/* + * Routines to access hardware + * + * Copyright (c) 2013 Realtek Semiconductor Corp. + * + * This module is a confidential and proprietary property of RealTek and + * possession or use of this module requires written permission of RealTek. + */ + +#ifndef _HAL_COMMON_H_ +#define _HAL_COMMON_H_ + +//================= Function Prototype START =================== +HAL_Status HalCommonInit(void); +//================= Function Prototype END =================== + +#endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_dac.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_dac.h index c06f1b7e65..97c6dd06af 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_dac.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_dac.h @@ -228,14 +228,9 @@ typedef struct _SAL_DAC_USERCB_ADPT_ { typedef struct _SAL_DAC_USER_CB_ { PSAL_DAC_USERCB_ADPT pTXCB; //DAC Transmit Callback PSAL_DAC_USERCB_ADPT pTXCCB; //DAC Transmit Complete Callback - PSAL_DAC_USERCB_ADPT pRXCB; //DAC Receive Callback - PSAL_DAC_USERCB_ADPT pRXCCB; //DAC Receive Complete Callback - PSAL_DAC_USERCB_ADPT pRDREQCB; //DAC Read Request Callback PSAL_DAC_USERCB_ADPT pERRCB; //DAC Error Callback PSAL_DAC_USERCB_ADPT pDMATXCB; //DAC DMA Transmit Callback PSAL_DAC_USERCB_ADPT pDMATXCCB; //DAC DMA Transmit Complete Callback - PSAL_DAC_USERCB_ADPT pDMARXCB; //DAC DMA Receive Callback - PSAL_DAC_USERCB_ADPT pDMARXCCB; //DAC DMA Receive Complete Callback }SAL_DAC_USER_CB, *PSAL_DAC_USER_CB; // DAC Transmit Buffer diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_efuse.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_efuse.h index 2f0a7d03e6..0911d966e3 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_efuse.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_efuse.h @@ -16,10 +16,12 @@ _LONG_CALL_ROM_ extern VOID HalEFUSEPowerSwitch8195AROM(IN u8 bWrite, IN u8 PwrState, IN u8 L25OutVoltage); extern u32 HALEFUSEOneByteReadRAM(IN u32 CtrlSetting, IN u16 Addr, OUT u8 *Data, IN u8 L25OutVoltage); extern u32 HALEFUSEOneByteWriteRAM(IN u32 CtrlSetting, IN u16 Addr, IN u8 Data, IN u8 L25OutVoltage); +u32 HALOneByteWriteRAM(IN u32 CtrlSetting,IN u16 Addr,IN u8 Data,IN u8 L25OutVoltage); #define EFUSERead8 HALEFUSEOneByteReadRAM #define EFUSEWrite8 HALEFUSEOneByteWriteRAM #define L25EOUTVOLTAGE 7 +#define DISABLE 0 #endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2c.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2c.h index 6b70087d89..290d93e006 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2c.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2c.h @@ -308,25 +308,26 @@ enum _I2C_ERR_TYPE_ { I2C_ERR_TX_ABRT = 0x08, //I2C TX terminated I2C_ERR_SLV_TX_NACK = 0x10, //I2C slave transmission terminated by master NACK, //but there are data in slave TX FIFO - I2C_ERR_MST_A_NACK = 0x12, - I2C_ERR_MST_D_NACK = 0x13, - I2C_ERR_USER_REG_TO = 0x20, + I2C_ERR_MST_A_NACK = 0x20, + I2C_ERR_MST_D_NACK = 0x40, + I2C_ERR_USER_REG_TO = 0x80, - I2C_ERR_RX_CMD_TO = 0x21, - I2C_ERR_RX_FF_TO = 0x22, - I2C_ERR_TX_CMD_TO = 0x23, - I2C_ERR_TX_FF_TO = 0x24, + I2C_ERR_RX_CMD_TO = 0x100, + I2C_ERR_RX_FF_TO = 0x200, + I2C_ERR_TX_CMD_TO = 0x400, + I2C_ERR_TX_FF_TO = 0x800, - I2C_ERR_TX_ADD_TO = 0x25, - I2C_ERR_RX_ADD_TO = 0x26, + I2C_ERR_TX_ADD_TO = 0x1000, + I2C_ERR_RX_ADD_TO = 0x2000, }; typedef uint32_t I2C_ERR_TYPE; typedef uint32_t *PI2C_ERR_TYPE; // I2C Time Out type -#define I2C_TIMEOOUT_DISABLE 0x00 -#define I2C_TIMEOOUT_ENDLESS 0xFFFFFFFF - +enum _I2C_TIMEOUT_TYPE_ { + I2C_TIMEOUT_DISABLE = 0x00, + I2C_TIMEOUT_ENDLESS = 0xFFFFFFFF, +}; typedef uint32_t I2C_TIMEOUT_TYPE; typedef uint32_t *PI2C_TIMEOUT_TYPE; diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2s.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2s.h new file mode 100644 index 0000000000..10b92d31d4 --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_i2s.h @@ -0,0 +1,347 @@ +/* + * Routines to access hardware + * + * Copyright (c) 2013 Realtek Semiconductor Corp. + * + * This module is a confidential and proprietary property of RealTek and + * possession or use of this module requires written permission of RealTek. + */ + +#ifndef _HAL_I2S_H_ +#define _HAL_I2S_H_ + +#include "rtl8195a_i2s.h" + +/* User Define Flags */ + +#define I2S_MAX_ID 1 // valid I2S index 0 ~ I2S_MAX_ID + +/**********************************************************************/ +/* I2S HAL initial data structure */ +typedef struct _HAL_I2S_INIT_DAT_ { + u8 I2SIdx; /*I2S index used*/ + u8 I2SEn; /*I2S module enable tx/rx/tx+rx*/ + u8 I2SMaster; /*I2S Master or Slave mode*/ + u8 I2SWordLen; /*I2S Word length 16 or 24bits*/ + + u8 I2SChNum; /*I2S Channel number mono or stereo*/ + u8 I2SPageNum; /*I2S Page Number 2~4*/ + u16 I2SPageSize; /*I2S page Size 1~4096 word*/ + + u8 *I2STxData; /*I2S Tx data pointer*/ + + u8 *I2SRxData; /*I2S Rx data pointer*/ + + u32 I2STxIntrMSK; /*I2S Tx Interrupt Mask*/ + u32 I2STxIntrClr; /*I2S Tx Interrupt register to clear */ + + u32 I2SRxIntrMSK; /*I2S Rx Interrupt Mask*/ + u32 I2SRxIntrClr; /*I2S Rx Interrupt register to clear*/ + + u16 I2STxIdx; /*I2S TX page index */ + u16 I2SRxIdx; /*I2S RX page index */ + + u16 I2SHWTxIdx; /*I2S HW TX page index */ + u16 I2SHWRxIdx; /*I2S HW RX page index */ + + + u16 I2SRate; /*I2S sample rate*/ + u8 I2STRxAct; /*I2S tx rx act*/ +}HAL_I2S_INIT_DAT, *PHAL_I2S_INIT_DAT; + +/**********************************************************************/ +/* I2S Data Structures */ +/* I2S Module Selection */ +typedef enum _I2S_MODULE_SEL_ { + I2S0_SEL = 0x0, + I2S1_SEL = 0x1, +}I2S_MODULE_SEL,*PI2S_MODULE_SEL; +/* +typedef struct _HAL_I2S_ADAPTER_ { + u32 Enable:1; + I2S_CTL_REG I2sCtl; + I2S_SETTING_REG I2sSetting; + u32 abc; + u8 I2sIndex; +}HAL_I2S_ADAPTER, *PHAL_I2S_ADAPTER; +*/ +/* I2S HAL Operations */ +typedef struct _HAL_I2S_OP_ { + RTK_STATUS (*HalI2SInit) (VOID *Data); + RTK_STATUS (*HalI2SDeInit) (VOID *Data); + RTK_STATUS (*HalI2STx) (VOID *Data, u8 *pBuff); + RTK_STATUS (*HalI2SRx) (VOID *Data, u8 *pBuff); + RTK_STATUS (*HalI2SEnable) (VOID *Data); + RTK_STATUS (*HalI2SIntrCtrl) (VOID *Data); + u32 (*HalI2SReadReg) (VOID *Data, u8 I2SReg); + RTK_STATUS (*HalI2SSetRate) (VOID *Data); + RTK_STATUS (*HalI2SSetWordLen) (VOID *Data); + RTK_STATUS (*HalI2SSetChNum) (VOID *Data); + RTK_STATUS (*HalI2SSetPageNum) (VOID *Data); + RTK_STATUS (*HalI2SSetPageSize) (VOID *Data); + + RTK_STATUS (*HalI2SClrIntr) (VOID *Data); + RTK_STATUS (*HalI2SClrAllIntr) (VOID *Data); + RTK_STATUS (*HalI2SDMACtrl) (VOID *Data); +/* + VOID (*HalI2sOnOff)(VOID *Data); + BOOL (*HalI2sInit)(VOID *Data); + BOOL (*HalI2sSetting)(VOID *Data); + BOOL (*HalI2sEn)(VOID *Data); + BOOL (*HalI2sIsrEnAndDis) (VOID *Data); + BOOL (*HalI2sDumpReg)(VOID *Data); + BOOL (*HalI2s)(VOID *Data); +*/ +}HAL_I2S_OP, *PHAL_I2S_OP; + + +/**********************************************************************/ + +/* I2S Pinmux Selection */ +#if 0 +typedef enum _I2S0_PINMUX_ { + I2S0_TO_S0 = 0x0, + I2S0_TO_S1 = 0x1, + I2S0_TO_S2 = 0x2, +}I2S0_PINMUX, *PI2S0_PINMUX; + +typedef enum _I2S1_PINMUX_ { + I2S1_TO_S0 = 0x0, + I2S1_TO_S1 = 0x1, +}I2S1_PINMUX, *PI2S1_PINMUX; +#endif + +typedef enum _I2S_PINMUX_ { + I2S_S0 = 0, + I2S_S1 = 1, + I2S_S2 = 2, + I2S_S3 = 3 +}I2S_PINMUX, *PI2S_PINMUX; + + +/* I2S Module Status */ +typedef enum _I2S_MODULE_STATUS_ { + I2S_DISABLE = 0x0, + I2S_ENABLE = 0x1, +}I2S_MODULE_STATUS, *PI2S_MODULE_STATUS; + + +/* I2S Device Status */ +typedef enum _I2S_Device_STATUS_ { + I2S_STS_UNINITIAL = 0x00, + I2S_STS_INITIALIZED = 0x01, + I2S_STS_IDLE = 0x02, + + I2S_STS_TX_READY = 0x03, + I2S_STS_TX_ING = 0x04, + + I2S_STS_RX_READY = 0x05, + I2S_STS_RX_ING = 0x06, + + I2S_STS_TRX_READY = 0x07, + I2S_STS_TRX_ING = 0x08, + + I2S_STS_ERROR = 0x09, +}I2S_Device_STATUS, *PI2S_Device_STATUS; + + +/* I2S Feature Status */ +typedef enum _I2S_FEATURE_STATUS_{ + I2S_FEATURE_DISABLED = 0, + I2S_FEATURE_ENABLED = 1, +}I2S_FEATURE_STATUS,*PI2S_FEATURE_STATUS; + +/* I2S Device Mode */ +typedef enum _I2S_DEV_MODE_ { + I2S_MASTER_MODE = 0x0, + I2S_SLAVE_MODE = 0x1 +}I2S_DEV_MODE, *PI2S_DEV_MODE; + +/* I2S Word Length */ +typedef enum _I2S_WORD_LEN_ { + I2S_WL_16 = 0x0, + I2S_WL_24 = 0x1, +}I2S_WORD_LEN, *PI2S_WORD_LEN; + +/* I2S Bus Transmit/Receive */ +typedef enum _I2S_DIRECTION_ { + I2S_ONLY_RX = 0x0, + I2S_ONLY_TX = 0x1, + I2S_TXRX = 0x2 +}I2S_DIRECTION, *PI2S_DIRECTION; + +/* I2S Channel number */ +typedef enum _I2S_CH_NUM_ { + I2S_CH_STEREO = 0x0, + I2S_CH_RSVD = 0x1, + I2S_CH_MONO = 0x2 +}I2S_CH_NUM, *PI2S_CH_NUM; + +/* I2S Page number */ +typedef enum _I2S_PAGE_NUM_ { + I2S_1PAGE = 0x0, + I2S_2PAGE = 0x1, + I2S_3PAGE = 0x2, + I2S_4PAGE = 0x3 +}I2S_PAGE_NUM, *PI2S_PAGE_NUM; + +/* I2S Sample rate*/ +typedef enum _I2S_SAMPLE_RATE_ { + I2S_SR_8KHZ = 0x00, // /12 + I2S_SR_16KHZ = 0x01, // /6 + I2S_SR_24KHZ = 0x02, // /4 + I2S_SR_32KHZ = 0x03, // /3 + I2S_SR_48KHZ = 0x05, // /2 + I2S_SR_96KHZ = 0x06, // x1, base 96kHz + I2S_SR_7p35KHZ = 0x10, + I2S_SR_14p7KHZ = 0x11, + I2S_SR_22p05KHZ = 0x12, + I2S_SR_29p4KHZ = 0x13, + I2S_SR_44p1KHZ = 0x15, + I2S_SR_88p2KHZ = 0x16 // x1, base 88200Hz +}I2S_SAMPLE_RATE, *PI2S_SAMPLE_RATE; + +/* I2S TX interrupt mask/status */ +typedef enum _I2S_TX_IMR_ { + I2S_TX_INT_PAGE0_OK = (1<<0), + I2S_TX_INT_PAGE1_OK = (1<<1), + I2S_TX_INT_PAGE2_OK = (1<<2), + I2S_TX_INT_PAGE3_OK = (1<<3), + I2S_TX_INT_FULL = (1<<4), + I2S_TX_INT_EMPTY = (1<<5) +} I2S_TX_IMR, *PI2S_TX_IMR; + +/* I2S RX interrupt mask/status */ +typedef enum _I2S_RX_IMR_ { + I2S_RX_INT_PAGE0_OK = (1<<0), + I2S_RX_INT_PAGE1_OK = (1<<1), + I2S_RX_INT_PAGE2_OK = (1<<2), + I2S_RX_INT_PAGE3_OK = (1<<3), + I2S_RX_INT_EMPTY = (1<<4), + I2S_RX_INT_FULL = (1<<5) +} I2S_RX_IMR, *PI2S_RX_IMR; + +/* I2S User Callbacks */ +typedef struct _SAL_I2S_USER_CB_{ + VOID (*TXCB) (VOID *Data); + VOID (*TXCCB) (VOID *Data); + VOID (*RXCB) (VOID *Data); + VOID (*RXCCB) (VOID *Data); + VOID (*RDREQCB) (VOID *Data); + VOID (*ERRCB) (VOID *Data); + VOID (*GENCALLCB) (VOID *Data); +}SAL_I2S_USER_CB,*PSAL_I2S_USER_CB; + +typedef struct _I2S_USER_CB_{ + VOID (*TxCCB)(uint32_t id, char *pbuf); + u32 TxCBId; + VOID (*RxCCB)(uint32_t id, char *pbuf); + u32 RxCBId; +}I2S_USER_CB,*PI2S_USER_CB; + +/* Software API Level I2S Handler */ +typedef struct _HAL_I2S_ADAPTER_{ + u8 DevNum; //I2S device number + u8 PinMux; //I2S pin mux seletion + u8 RSVD0; //Reserved + volatile u8 DevSts; //I2S device status + + u32 RSVD2; //Reserved + u32 I2SExd; //I2S extended options: + //bit 0: I2C RESTART supported, + // 0 for NOT supported, + // 1 for supported + //bit 1: I2C General Call supported + // 0 for NOT supported, + // 1 for supported + //bit 2: I2C START Byte supported + // 0 for NOT supported, + // 1 for supported + //bit 3: I2C Slave-No-Ack + // supported + // 0 for NOT supported, + // 1 for supported + //bit 4: I2C bus loading, + // 0 for 100pf, + // 1 for 400pf + //bit 5: I2C slave ack to General + // Call + //bit 6: I2C User register address + //bit 7: I2C 2-Byte User register + // address + //bit 31~bit 8: Reserved + u32 ErrType; // + u32 TimeOut; //I2S IO Timeout count + + PHAL_I2S_INIT_DAT pInitDat; //Pointer to I2S initial data struct + I2S_USER_CB UserCB; //Pointer to I2S User Callback + IRQ_HANDLE IrqHandle; // Irq Handler + + u32* TxPageList[4]; // The Tx DAM buffer: pointer of each page + u32* RxPageList[4]; // The Tx DAM buffer: pointer of each page +}HAL_I2S_ADAPTER, *PHAL_I2S_ADAPTER; + +typedef struct _HAL_I2S_DEF_SETTING_{ + u8 I2SMaster; // Master or Slave mode + u8 DevSts; //I2S device status + u8 I2SChNum; //I2S Channel number mono or stereo + u8 I2SPageNum; //I2S Page number 2~4 + u8 I2STRxAct; //I2S tx rx act, tx only or rx only or tx+rx + u8 I2SWordLen; //I2S Word length 16bit or 24bit + u16 I2SPageSize; //I2S Page size 1~4096 word + + u16 I2SRate; //I2S sample rate 8k ~ 96khz + + u32 I2STxIntrMSK; /*I2S Tx Interrupt Mask*/ + u32 I2SRxIntrMSK; /*I2S Rx Interrupt Mask*/ +}HAL_I2S_DEF_SETTING, *PHAL_I2S_DEF_SETTING; + + + +/**********************************************************************/ +HAL_Status +RtkI2SLoadDefault(IN VOID *Adapter, IN VOID *Setting); + +HAL_Status +RtkI2SInit(IN VOID *Data); + +HAL_Status +RtkI2SDeInit(IN VOID *Data); + +HAL_Status +RtkI2SEnable(IN VOID *Data); + +HAL_Status +RtkI2SDisable(IN VOID *Data); + +extern HAL_Status +HalI2SInit( IN VOID *Data); + +extern VOID +HalI2SDeInit( IN VOID *Data); + +extern HAL_Status +HalI2SDisable( IN VOID *Data); + +extern HAL_Status +HalI2SEnable( IN VOID *Data); + + + + +/**********************************************************************/ + + +VOID I2S0ISRHandle(VOID *Data); +VOID I2S1ISRHandle(VOID *Data); + + +/**********************************************************************/ + +VOID HalI2SOpInit( + IN VOID *Data +); + + +#endif + diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_misc.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_misc.h index 1888368821..f927a82c8d 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_misc.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_misc.h @@ -24,6 +24,19 @@ #define CHIP_ID_8710AM 0xFA #define CHIP_ID_SIP 0xF9 #define CHIP_ID_COMBO_SIP 0xF8 +#define CHIP_ID_SIP2 0xF7 +#define CHIP_ID_MICO100 0xF1 + +enum _HAL_RESET_REASON{ + REASON_DEFAULT_RST = 0, /**< normal startup by power on */ + REASON_WDT_RST, /**< hardware watch dog reset */ + REASON_EXCEPTION_RST, /**< exception reset, GPIO status won't change */ + REASON_SOFT_WDT_RST, /**< software watch dog reset, GPIO status won't change */ + REASON_SOFT_RESTART, /**< software restart ,system_restart , GPIO status won't change */ + REASON_DEEP_SLEEP_AWAKE, /**< wake up from deep-sleep */ + REASON_EXT_SYS_RST /**< external system reset */ +}; +typedef u32 HAL_RESET_REASON; #ifdef CONFIG_TIMER_MODULE extern _LONG_CALL_ u32 HalDelayUs(u32 us); @@ -43,5 +56,7 @@ extern _LONG_CALL_ROM_ int _memcmp( const void *av, const void *bv, SIZE_T len ) extern _LONG_CALL_ROM_ SIZE_T _strlen(const char *s); extern _LONG_CALL_ROM_ int _strcmp(const char *cs, const char *ct); +VOID HalSetResetCause(IN HAL_RESET_REASON reason); +HAL_RESET_REASON HalGetResetCause(VOID); #endif //_MISC_H_ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_pwm.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_pwm.h index 7101120fe3..9197e5abef 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_pwm.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_pwm.h @@ -15,6 +15,9 @@ #define _HAL_PWM_H_ #define MAX_PWM_CTRL_PIN 4 +#define MAX_GTIMER_NUM 4 +#define MAX_DEVID_TICK 1020 + // the minimum tick time for G-timer is 61 us (clock source = 32768Hz, reload value=1 and reload takes extra 1T) //#define GTIMER_TICK_US 31 // micro-second, 1000000/32768 ~= 30.5 #define MIN_GTIMER_TIMEOUT 61 // in micro-sec, use this value to set the g-timer to generate tick for PWM. 61=(1000000/32768)*2 @@ -32,6 +35,10 @@ typedef struct _HAL_PWM_ADAPTER_ { // float duty_ratio; // the dyty ratio = pulswidth/period }HAL_PWM_ADAPTER, *PHAL_PWM_ADAPTER; +typedef struct _HAL_PWM_GTIMER_ { + u32 tick_time; // the tick time for the G-timer + u8 reference; // map of referenced by PWM +}HAL_PWM_TIMER, *PHAL_PWM_TIMER; extern HAL_Status HAL_Pwm_Init( diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_spi_flash.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_spi_flash.h index f4b8b5ee11..6380ed97bb 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_spi_flash.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_spi_flash.h @@ -69,6 +69,8 @@ enum _SPIC_BIT_MODE_ { #define FLASH_WINBOND 3 #define FLASH_MICRON 4 #define FLASH_EON 5 +#define FLASH_GD 6 +#define FLASH_CYPRESS 7 //#define FLASH_MXIC_MX25L4006E 0 //#define FLASH_MXIC_MX25L8073E 0 @@ -82,40 +84,41 @@ enum _SPIC_BIT_MODE_ { #define FLASH_CMD_WRDI 0x04 //write disable #define FLASH_CMD_WRSR 0x01 //write status register #define FLASH_CMD_RDID 0x9F //read idenfication +#define FLASH_CMD_RDUID 0x4B //Read Unique ID #define FLASH_CMD_RDSR 0x05 //read status register #define FLASH_CMD_RDSFDP 0x5A //Read SFDP #define FLASH_CMD_READ 0x03 //read data #define FLASH_CMD_FREAD 0x0B //fast read data #define FLASH_CMD_PP 0x02 //Page Program -#define FLASH_CMD_DREAD 0x3B //Double Output Mode command 1-1-2 -#define FLASH_CMD_2READ 0xBB // 2 x I/O read command 1-2-2 -#define FLASH_CMD_QREAD 0x6B // 1I / 4O read command 1-1-4 -#define FLASH_CMD_4READ 0xEB // 4 x I/O read command 1-4-4 -#define FLASH_CMD_DPP 0xA2 // 1-1-2 -#define FLASH_CMD_2PP 0xD2 // 1-2-2 -#define FLASH_CMD_QPP 0x32 // 1-1-4 -#define FLASH_CMD_4PP 0x38 //quad page program 1-4-4 +#define FLASH_CMD_DREAD 0x3B //Double Output Mode command 1-1-2 +#define FLASH_CMD_2READ 0xBB // 2 x I/O read command 1-2-2 +#define FLASH_CMD_QREAD 0x6B // 1I / 4O read command 1-1-4 +#define FLASH_CMD_4READ 0xEB // 4 x I/O read command 1-4-4 +#define FLASH_CMD_DPP 0xA2 // 1-1-2 +#define FLASH_CMD_2PP 0xD2 // 1-2-2 +#define FLASH_CMD_QPP 0x32 // 1-1-4 +#define FLASH_CMD_4PP 0x38 //quad page program 1-4-4 #define FLASH_CMD_SE 0x20 //Sector Erase -#define FLASH_CMD_BE 0xD8 //Block Erase(or 0x52) -#define FLASH_CMD_CE 0xC7 //Chip Erase(or 0xC7) -#define FLASH_CMD_DP 0xB9 //Deep Power Down -#define FLASH_CMD_RDP 0xAB //Release from Deep Power-Down +#define FLASH_CMD_BE 0xD8 //Block Erase(or 0x52) +#define FLASH_CMD_CE 0xC7 //Chip Erase(or 0xC7) +#define FLASH_CMD_DP 0xB9 //Deep Power Down +#define FLASH_CMD_RDP 0xAB //Release from Deep Power-Down /*Micron Special command*/ -#define FLASH_CMD_DE 0xC4 -#define FLASH_CMD_4PP2 0x12 -#define FLASH_CMD_RFSR 0x70 -#define FLASH_CMD_CFSR 0x50 -#define FLASH_CMD_RNCR 0xB5 -#define FLASH_CMD_WNCR 0xB1 -#define FLASH_CMD_RVCR 0x85 -#define FLASH_CMD_WVCR 0x81 -#define FLASH_CMD_REVCR 0x65 -#define FLASH_CMD_WEVCR 0x61 -#define FLASH_CMD_REAR 0xC8 -#define FLASH_CMD_WEAR 0xC5 -#define FLASH_CMD_ENQUAD 0x35 -#define FLASH_CMD_EXQUAD 0xF5 +#define FLASH_CMD_DE 0xC4 +#define FLASH_CMD_4PP2 0x12 +#define FLASH_CMD_RFSR 0x70 +#define FLASH_CMD_CFSR 0x50 +#define FLASH_CMD_RNCR 0xB5 +#define FLASH_CMD_WNCR 0xB1 +#define FLASH_CMD_RVCR 0x85 +#define FLASH_CMD_WVCR 0x81 +#define FLASH_CMD_REVCR 0x65 +#define FLASH_CMD_WEVCR 0x61 +#define FLASH_CMD_REAR 0xC8 +#define FLASH_CMD_WEAR 0xC5 +#define FLASH_CMD_ENQUAD 0x35 +#define FLASH_CMD_EXQUAD 0xF5 /*MXIC Special command*/ #define FLASH_CMD_RDCR 0x15 //read configurate register @@ -126,6 +129,19 @@ enum _SPIC_BIT_MODE_ { #define FLASH_CMD_RDSCUR 0x2B // read security register #define FLASH_CMD_WRSCUR 0x2F // write security register +/*WINBOND Special command*/ +#define FLASH_CMD_GLOCK 0x7E +#define FLASH_CMD_GUNLOCK 0x98 +#define FLASH_CMD_RLOCK 0x3D +#define FLASH_CMD_SLOCK 0x36 +#define FLASH_CMD_SUNLOCK 0x39 +#define FLASH_CMD_WRSR3 0x11 +#define FLASH_CMD_RDSR3 0x15 + +/*Cypress Special command*/ +#define FLASH_CMD_RDSR4 0x07 //read status register 2 +#define FLASH_CMD_CLSR 0x30 //Clear status register 2 error bit + //#endif #if 0 #if FLASH_MXIC_MX25L4006E @@ -331,11 +347,16 @@ VOID SpicBlockEraseFlashRtl8195A(IN u32 Address); VOID SpicSectorEraseFlashRtl8195A(IN u32 Address); VOID SpicDieEraseFlashRtl8195A(IN u32 Address); VOID SpicWriteProtectFlashRtl8195A(IN u32 Protect); -VOID SpicWaitWipDoneRefinedRtl8195A(IN SPIC_INIT_PARA SpicInitPara); +VOID SpicWaitWipDoneRefinedRtl8195A(IN SPIC_INIT_PARA SpicInitPara); VOID SpicWaitOperationDoneRtl8195A(IN SPIC_INIT_PARA SpicInitPara); -VOID SpicRxCmdRefinedRtl8195A(IN u8 cmd,IN SPIC_INIT_PARA SpicInitPara); +VOID SpicTxCmdWithDataRtl8195A(IN u8 cmd,IN u8 DataPhaseLen,IN u8* pData,IN SPIC_INIT_PARA SpicInitPara); +VOID SpicTxCmdWithDataNoCheckRtl8195A(IN u8 cmd, IN u8 DataPhaseLen,IN u8* pData); +VOID SpicRxCmdRefinedRtl8195A(IN u8 cmd,IN SPIC_INIT_PARA SpicInitPara); +VOID SpicRxCmdWithDataRtl8195A(IN u8 cmd,IN u8 DataPhaseLen, IN u8* pData,IN SPIC_INIT_PARA SpicInitPara); u8 SpicGetFlashStatusRefinedRtl8195A(IN SPIC_INIT_PARA SpicInitPara); -VOID SpicInitRefinedRtl8195A(IN u8 InitBaudRate,IN u8 SpicBitMode); +u8 SpicGetFlashStatus3Rtl8195A(IN SPIC_INIT_PARA SpicInitPara); +u8 SpicGetFlashStatus4Rtl8195A(IN SPIC_INIT_PARA SpicInitPara); +VOID SpicInitRefinedRtl8195A(IN u8 InitBaudRate,IN u8 SpicBitMode); u32 SpicWaitWipRtl8195A(VOID); u32 SpicOneBitCalibrationRtl8195A(IN u8 SysCpuClk); VOID SpicDisableRtl8195A(VOID); @@ -343,10 +364,18 @@ VOID SpicDeepPowerDownFlashRtl8195A(VOID); VOID SpicUserProgramRtl8195A(IN u8 * data, IN SPIC_INIT_PARA SpicInitPara, IN u32 addr, IN u32 * LengthInfo); VOID SpicUserReadRtl8195A(IN u32 Length, IN u32 addr, IN u8 * data, IN u8 BitMode); VOID SpicUserReadFourByteRtl8195A(IN u32 Length, IN u32 addr, IN u32 * data, IN u8 BitMode); +VOID SpicReadUniqueIDRtl8195A(IN u8 *buff,IN u8 len); VOID SpicReadIDRtl8195A(VOID); VOID SpicSetFlashStatusRefinedRtl8195A(IN u32 data, IN SPIC_INIT_PARA SpicInitPara); VOID SpicSetExtendAddrRtl8195A(IN u32 data, IN SPIC_INIT_PARA SpicInitPara); u8 SpicGetExtendAddrRtl8195A(IN SPIC_INIT_PARA SpicInitPara); +VOID SpicSetLockModeRtl8195A(IN u8 Mode); +VOID SpicLockFlashRtl8195A(VOID); +VOID SpicUnlockFlashRtl8195A(VOID); +VOID SpicSingleLockRtl8195A(IN u32 Address); +VOID SpicSingleUnlockRtl8195A(IN u32 Address); +u8 SpicReadLockStateRtl8195A(IN u32 Address); + #if SPIC_CALIBRATION_IN_NVM VOID SpicNVMCalLoad(u8 BitMode, u8 CpuClk); VOID SpicNVMCalLoadAll(void); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_ssi.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_ssi.h index 04cb1e61c1..43881a18d2 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_ssi.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_ssi.h @@ -21,6 +21,7 @@ */ extern u32 SSI_DBG_CONFIG; +extern uint8_t SPI0_IS_AS_SLAVE; #define SSI_DBG_ENTRANCE(...) do {\ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_timer.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_timer.h index b716cbaae3..d152487eab 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_timer.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/hal_timer.h @@ -44,19 +44,16 @@ typedef struct _HAL_TIMER_OP_ { u32 (*HalGetTimerId)(u32 *TimerId); BOOL (*HalTimerInit)(VOID *Data); u32 (*HalTimerReadCount)(u32 TimerId); - //VOID (*HalTimerIrqEn)(u32 TimerId); VOID (*HalTimerIrqClear)(u32 TimerId); VOID (*HalTimerDis)(u32 TimerId); VOID (*HalTimerEn)(u32 TimerId); VOID (*HalTimerDumpReg)(u32 TimerId); - //VOID (*HalTimerReLoad)(u32 TimerId, u32 LoadUs); }HAL_TIMER_OP, *PHAL_TIMER_OP; typedef struct _HAL_TIMER_OP_EXT_ { - PHAL_TIMER_OP phal_timer_op_rom; - VOID (*HalTimerIrqEn)(u32 TimerId); - VOID (*HalTimerReLoad)(u32 TimerId, u32 LoadUs); - VOID (*HalTimerSync)(u32 TimerId); + PHAL_TIMER_OP phal_timer_op_rom; + VOID (*HalTimerIrqEn)(u32 TimerId); + VOID (*HalTimerReLoad)(u32 TimerId, u32 LoadUs); }HAL_TIMER_OP_EXT, *PHAL_TIMER_OP_EXT; #ifdef CONFIG_TIMER_MODULE diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a.h index 499700ecec..24eda206aa 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a.h @@ -28,6 +28,7 @@ #include "hal_diag.h" #include "hal_spi_flash.h" #include "rtl8195a_spi_flash.h" +#include "hal_timer.h" #include "hal_util.h" #include "hal_efuse.h" #include "hal_soc_ps_monitor.h" @@ -148,11 +149,9 @@ __##name##_Disable(void) \ #include "rtl8195a_trap.h" #include "rtl8195a_clk.h" #include "rtl8195a_misc.h" -#include "rtl8195a_sdio.h" #endif - /* ---------------------------------------------------------------------------- -- Cortex M3 Core Configuration ---------------------------------------------------------------------------- */ @@ -198,6 +197,10 @@ __##name##_Disable(void) \ #include "rtl8195a_i2c.h" #endif +#ifdef CONFIG_PCM_EN +#include "hal_pcm.h" +#include "rtl8195a_pcm.h" +#endif #ifdef CONFIG_PWM_EN #include "hal_pwm.h" @@ -226,7 +229,7 @@ __##name##_Disable(void) \ #endif #ifdef CONFIG_SDIO_DEVICE_EN -//#include "hal_sdio.h" +#include "hal_sdio.h" #endif #ifdef CONFIG_NFC_EN diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_i2s.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_i2s.h new file mode 100644 index 0000000000..13d7f59ea6 --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_i2s.h @@ -0,0 +1,714 @@ +/* + * Routines to access hardware + * + * Copyright (c) 2013 Realtek Semiconductor Corp. + * + * This module is a confidential and proprietary property of RealTek and + * possession or use of this module requires written permission of RealTek. + */ + + +#ifndef _RTL8195A_I2S_H_ +#define _RTL8195A_I2S_H_ + + +//=============== Register Bit Field Definition ==================== +// REG_I2S_CONTROL +#define BIT_CTLX_I2S_EN BIT(0) +#define BIT_SHIFT_CTLX_I2S_EN 0 +#define BIT_MASK_CTLX_I2S_EN 0x1 +#define BIT_CTRL_CTLX_I2S_EN(x) (((x) & BIT_MASK_CTLX_I2S_EN) << BIT_SHIFT_CTLX_I2S_EN) + +#define BIT_SHIFT_CTLX_I2S_TRX_ACT 1 +#define BIT_MASK_CTLX_I2S_TRX_ACT 0x3 +#define BIT_CTRL_CTLX_I2S_TRX_ACT(x) (((x) & BIT_MASK_CTLX_I2S_TRX_ACT) << BIT_SHIFT_CTLX_I2S_TRX_ACT) +#define BIT_GET_CTLX_I2S_TRX_ACT(x) (((x) >> BIT_SHIFT_CTLX_I2S_TRX_ACT) & BIT_MASK_CTLX_I2S_TRX_ACT) + +#define BIT_SHIFT_CTLX_I2S_CH_NUM 3 +#define BIT_MASK_CTLX_I2S_CH_NUM 0x3 +#define BIT_CTRL_CTLX_I2S_CH_NUM(x) (((x) & BIT_MASK_CTLX_I2S_CH_NUM) << BIT_SHIFT_CTLX_I2S_CH_NUM) +#define BIT_GET_CTLX_I2S_CH_NUM(x) (((x) >> BIT_SHIFT_CTLX_I2S_CH_NUM) & BIT_MASK_CTLX_I2S_CH_NUM) + +#define BIT_CTLX_I2S_WL BIT(6) +#define BIT_SHIFT_CTLX_I2S_WL 6 +#define BIT_MASK_CTLX_I2S_WL 0x1 +#define BIT_CTRL_CTLX_I2S_WL(x) (((x) & BIT_MASK_CTLX_I2S_WL) << BIT_SHIFT_CTLX_I2S_WL) + +#define BIT_CTLX_I2S_LRSWAP BIT(10) +#define BIT_SHIFT_CTLX_I2S_LRSWAP 10 +#define BIT_MASK_CTLX_I2S_LRSWAP 0x1 +#define BIT_CTRL_CTLX_I2S_LRSWAP(x) (((x) & BIT_MASK_CTLX_I2S_LRSWAP) << BIT_SHIFT_CTLX_I2S_LRSWAP) + +#define BIT_CTLX_I2S_SCK_INV BIT(11) +#define BIT_SHIFT_CTLX_I2S_SCK_INV 11 +#define BIT_MASK_CTLX_I2S_SCK_INV 0x1 +#define BIT_CTRL_CTLX_I2S_SCK_INV(x) (((x) & BIT_MASK_CTLX_I2S_SCK_INV) << BIT_SHIFT_CTLX_I2S_SCK_INV) + +#define BIT_CTLX_I2S_ENDIAN_SWAP BIT(12) +#define BIT_SHIFT_CTLX_I2S_ENDIAN_SWAP 12 +#define BIT_MASK_CTLX_I2S_ENDIAN_SWAP 0x1 +#define BIT_CTRL_CTLX_I2S_ENDIAN_SWAP(x) (((x) & BIT_MASK_CTLX_I2S_ENDIAN_SWAP) << BIT_SHIFT_CTLX_I2S_ENDIAN_SWAP) + +#define BIT_CTLX_I2S_SLAVE_MODE BIT(29) +#define BIT_SHIFT_CTLX_I2S_SLAVE_MODE 29 +#define BIT_MASK_CTLX_I2S_SLAVE_MODE 0x1 +#define BIT_CTRL_CTLX_I2S_SLAVE_MODE(x) (((x) & BIT_MASK_CTLX_I2S_SLAVE_MODE) << BIT_SHIFT_CTLX_I2S_SLAVE_MODE) + +#define BIT_CTLX_I2S_CLK_SRC BIT(30) +#define BIT_SHIFT_CTLX_I2S_CLK_SRC 30 +#define BIT_MASK_CTLX_I2S_CLK_SRC 0x1 +#define BIT_CTRL_CTLX_I2S_CLK_SRC(x) (((x) & BIT_MASK_CTLX_I2S_CLK_SRC) << BIT_SHIFT_CTLX_I2S_CLK_SRC) + +#define BIT_CTLX_I2S_SW_RSTN BIT(31) +#define BIT_SHIFT_CTLX_I2S_SW_RSTN 31 +#define BIT_MASK_CTLX_I2S_SW_RSTN 0x1 +#define BIT_CTRL_CTLX_I2S_SW_RSTN(x) (((x) & BIT_MASK_CTLX_I2S_SW_RSTN) << BIT_SHIFT_CTLX_I2S_SW_RSTN) + +// REG_I2S_SETTING +#define BIT_SHIFT_SETTING_I2S_PAGE_SZ 0 +#define BIT_MASK_SETTING_I2S_PAGE_SZ 0xFFF +#define BIT_CTRL_SETTING_I2S_PAGE_SZ(x) (((x) & BIT_MASK_SETTING_I2S_PAGE_SZ) << BIT_SHIFT_SETTING_I2S_PAGE_SZ) +#define BIT_GET_SETTING_I2S_PAGE_SZ(x) (((x) >> BIT_SHIFT_SETTING_I2S_PAGE_SZ) & BIT_MASK_SETTING_I2S_PAGE_SZ) + +#define BIT_SHIFT_SETTING_I2S_PAGE_NUM 12 +#define BIT_MASK_SETTING_I2S_PAGE_NUM 0x3 +#define BIT_CTRL_SETTING_I2S_PAGE_NUM(x) (((x) & BIT_MASK_SETTING_I2S_PAGE_NUM) << BIT_SHIFT_SETTING_I2S_PAGE_NUM) +#define BIT_GET_SETTING_I2S_PAGE_NUM(x) (((x) >> BIT_SHIFT_SETTING_I2S_PAGE_NUM) & BIT_MASK_SETTING_I2S_PAGE_NUM) + +#define BIT_SHIFT_SETTING_I2S_SAMPLE_RATE 14 +#define BIT_MASK_SETTING_I2S_SAMPLE_RATE 0x7 +#define BIT_CTRL_SETTING_I2S_SAMPLE_RATE(x) (((x) & BIT_MASK_SETTING_I2S_SAMPLE_RATE) << BIT_SHIFT_SETTING_I2S_SAMPLE_RATE) +#define BIT_GET_SETTING_I2S_SAMPLE_RATE(x) (((x) >> BIT_SHIFT_SETTING_I2S_SAMPLE_RATE) & BIT_MASK_SETTING_I2S_SAMPLE_RATE) + +// i2s trx page own bit +#define BIT_PAGE_I2S_OWN_BIT BIT(31) +#define BIT_SHIFT_PAGE_I2S_OWN_BIT 31 +#define BIT_MASK_PAGE_I2S_OWN_BIT 0x1 +#define BIT_CTRL_PAGE_I2S_OWN_BIT(x) (((x) & BIT_MASK_PAGE_I2S_OWN_BIT) << BIT_SHIFT_PAGE_I2S_OWN_BIT) + +//=============== Register Address Definition ==================== +#define REG_I2S_PAGE_OWN_OFF 0x004 + +#define REG_I2S_CTL 0x000 +#define REG_I2S_TX_PAGE_PTR 0x004 +#define REG_I2S_RX_PAGE_PTR 0x008 +#define REG_I2S_SETTING 0x00C + +#define REG_I2S_TX_MASK_INT 0x010 +#define REG_I2S_TX_STATUS_INT 0x014 +#define REG_I2S_RX_MASK_INT 0x018 +#define REG_I2S_RX_STATUS_INT 0x01c + + +#define REG_I2S_TX_PAGE0_OWN 0x020 +#define REG_I2S_TX_PAGE1_OWN 0x024 +#define REG_I2S_TX_PAGE2_OWN 0x028 +#define REG_I2S_TX_PAGE3_OWN 0x02C +#define REG_I2S_RX_PAGE0_OWN 0x030 +#define REG_I2S_RX_PAGE1_OWN 0x034 +#define REG_I2S_RX_PAGE2_OWN 0x038 +#define REG_I2S_RX_PAGE3_OWN 0x03C + +/*I2S Essential Functions and Macros*/ +VOID +HalI2SWrite32( + IN u8 I2SIdx, + IN u8 I2SReg, + IN u32 I2SVal +); + +u32 +HalI2SRead32( + IN u8 I2SIdx, + IN u8 I2SReg +); + +/* +#define HAL_I2SX_READ32(I2sIndex, addr) \ + HAL_READ32(I2S0_REG_BASE+ (I2sIndex*I2S1_REG_OFF), addr) +#define HAL_I2SX_WRITE32(I2sIndex, addr, value) \ + HAL_WRITE32((I2S0_REG_BASE+ (I2sIndex*I2S1_REG_OFF)), addr, value) +*/ + +#define HAL_I2S_WRITE32(I2SIdx, addr, value) HalI2SWrite32(I2SIdx,addr,value) +#define HAL_I2S_READ32(I2SIdx, addr) HalI2SRead32(I2SIdx,addr) + +/* I2S debug output*/ +#define I2S_PREFIX "RTL8195A[i2s]: " +#define I2S_PREFIX_LVL " [i2s_DBG]: " + +typedef enum _I2S_DBG_LVL_ { + HAL_I2S_LVL = 0x01, + SAL_I2S_LVL = 0x02, + VERI_I2S_LVL = 0x03, +}I2S_DBG_LVL,*PI2S_DBG_LVL; + +#ifdef CONFIG_DEBUG_LOG +#ifdef CONFIG_DEBUG_LOG_I2S_HAL + + #define DBG_8195A_I2S(...) do{ \ + _DbgDump("\r"I2S_PREFIX __VA_ARGS__);\ + }while(0) + + + #define I2SDBGLVL 0xFF + #define DBG_8195A_I2S_LVL(LVL,...) do{\ + if (LVL&I2SDBGLVL){\ + _DbgDump("\r"I2S_PREFIX_LVL __VA_ARGS__);\ + }\ + }while(0) +#else + #define DBG_I2S_LOG_PERD 100 + #define DBG_8195A_I2S(...) + #define DBG_8195A_I2S_LVL(...) +#endif +#else + #define DBG_I2S_LOG_PERD 100 + #define DBG_8195A_I2S(...) + #define DBG_8195A_I2S_LVL(...) +#endif + +/* +#define REG_I2S_PAGE_OWN_OFF 0x004 +#define REG_I2S_CTL 0x000 +#define REG_I2S_TX_PAGE_PTR 0x004 +#define REG_I2S_RX_PAGE_PTR 0x008 +#define REG_I2S_SETTING 0x00C + +#define REG_I2S_TX_MASK_INT 0x010 +#define REG_I2S_TX_STATUS_INT 0x014 +#define REG_I2S_RX_MASK_INT 0x018 +#define REG_I2S_RX_STATUS_INT 0x01c + + + +#define REG_I2S_TX_PAGE0_OWN 0x020 +#define REG_I2S_TX_PAGE1_OWN 0x024 +#define REG_I2S_TX_PAGE2_OWN 0x028 +#define REG_I2S_TX_PAGE3_OWN 0x02C +#define REG_I2S_RX_PAGE0_OWN 0x030 +#define REG_I2S_RX_PAGE1_OWN 0x034 +#define REG_I2S_RX_PAGE2_OWN 0x038 +#define REG_I2S_RX_PAGE3_OWN 0x03C +*/ +/* template +#define BIT_SHIFT_CTLX_ 7 +#define BIT_MASK_CTLX_ 0x1 +#define BIT_CTLX_(x) (((x) & BIT_MASK_CTLX_) << BIT_SHIFT_CTLX_) +#define BIT_INV_CTLX_ (~(BIT_MASK_CTLX_ << BIT_SHIFT_CTLX_)) +*//* +#define BIT_SHIFT_CTLX_IIS_EN 0 +#define BIT_MASK_CTLX_IIS_EN 0x1 +#define BIT_CTLX_IIS_EN(x) (((x) & BIT_MASK_CTLX_IIS_EN) << BIT_SHIFT_CTLX_IIS_EN) +#define BIT_INV_CTLX_IIS_EN (~(BIT_MASK_CTLX_IIS_EN << BIT_SHIFT_CTLX_IIS_EN)) + +#define BIT_SHIFT_CTLX_TRX 1 +#define BIT_MASK_CTLX_TRX 0x3 +#define BIT_CTLX_TRX(x) (((x) & BIT_MASK_CTLX_TRX) << BIT_SHIFT_CTLX_TRX) +#define BIT_INV_CTLX_TRX (~(BIT_MASK_CTLX_TRX << BIT_SHIFT_CTLX_TRX)) + +#define BIT_SHIFT_CTLX_CH_NUM 3 +#define BIT_MASK_CTLX_CH_NUM 0x3 +#define BIT_CTLX_CH_NUM(x) (((x) & BIT_MASK_CTLX_CH_NUM) << BIT_SHIFT_CTLX_CH_NUM) +#define BIT_INV_CTLX_CH_NUM (~(BIT_MASK_CTLX_CH_NUM << BIT_SHIFT_CTLX_CH_NUM)) + +#define BIT_SHIFT_CTLX_EDGE_SW 5 +#define BIT_MASK_CTLX_EDGE_SW 0x1 +#define BIT_CTLX_EDGE_SW(x) (((x) & BIT_MASK_CTLX_EDGE_SW) << BIT_SHIFT_CTLX_EDGE_SW) +#define BIT_INV_CTLX_EDGE_SW (~(BIT_MASK_CTLX_EDGE_SW << BIT_SHIFT_CTLX_EDGE_SW)) + +#define BIT_SHIFT_CTLX_WL 6 +#define BIT_MASK_CTLX_WL 0x1 +#define BIT_CTLX_WL(x) (((x) & BIT_MASK_CTLX_WL) << BIT_SHIFT_CTLX_WL) +#define BIT_INV_CTLX_WL (~(BIT_MASK_CTLX_WL << BIT_SHIFT_CTLX_WL)) + +#define BIT_SHIFT_CTLX_LOOP_BACK 7 +#define BIT_MASK_CTLX_LOOP_BACK 0x1 +#define BIT_CTLX_LOOP_BACK(x) (((x) & BIT_MASK_CTLX_LOOP_BACK) << BIT_SHIFT_CTLX_LOOP_BACK) +#define BIT_INV_CTLX_LOOP_BACK (~(BIT_MASK_CTLX_LOOP_BACK << BIT_SHIFT_CTLX_LOOP_BACK)) + + +#define BIT_SHIFT_CTLX_FORMAT 8 +#define BIT_MASK_CTLX_FORMAT 0x3 +#define BIT_CTLX_FORMAT(x) (((x) & BIT_MASK_CTLX_FORMAT) << BIT_SHIFT_CTLX_FORMAT) +#define BIT_INV_CTLX_FORMAT (~(BIT_MASK_CTLX_FORMAT << BIT_SHIFT_CTLX_FORMAT)) + +#define BIT_SHIFT_CTLX_LRSWAP 10 +#define BIT_MASK_CTLX_LRSWAP 0x1 +#define BIT_CTLX_LRSWAP(x) (((x) & BIT_MASK_CTLX_LRSWAP) << BIT_SHIFT_CTLX_LRSWAP) +#define BIT_INV_CTLX_LRSWAP (~(BIT_MASK_CTLX_LRSWAP << BIT_SHIFT_CTLX_LRSWAP)) + +#define BIT_SHIFT_CTLX_SCK_INV 11 +#define BIT_MASK_CTLX_SCK_INV 0x1 +#define BIT_CTLX_SCK_INV(x) (((x) & BIT_MASK_CTLX_SCK_INV) << BIT_SHIFT_CTLX_SCK_INV) +#define BIT_INV_CTLX_SCK_INV (~(BIT_MASK_CTLX_SCK_INV << BIT_SHIFT_CTLX_SCK_INV)) + +#define BIT_SHIFT_CTLX_ENDIAN_SWAP 12 +#define BIT_MASK_CTLX_ENDIAN_SWAP 0x1 +#define BIT_CTLX_ENDIAN_SWAP(x) (((x) & BIT_MASK_CTLX_ENDIAN_SWAP) << BIT_SHIFT_CTLX_ENDIAN_SWAP) +#define BIT_INV_CTLX_ENDIAN_SWAP (~(BIT_MASK_CTLX_ENDIAN_SWAP << BIT_SHIFT_CTLX_ENDIAN_SWAP)) + + +#define BIT_SHIFT_CTLX_DEBUG_SWITCH 15 +#define BIT_MASK_CTLX_DEBUG_SWITCH 0x3 +#define BIT_CTLX_DEBUG_SWITCH(x) (((x) & BIT_MASK_CTLX_DEBUG_SWITCH) << BIT_SHIFT_CTLX_DEBUG_SWITCH) +#define BIT_INV_CTLX_DEBUG_SWITCH (~(BIT_MASK_CTLX_DEBUG_SWITCH << BIT_SHIFT_CTLX_DEBUG_SWITCH)) + +#define BIT_SHIFT_CTLX_SLAVE_SEL 29 +#define BIT_MASK_CTLX_SLAVE_SEL 0x1 +#define BIT_CTLX_SLAVE_SEL(x) (((x) & BIT_MASK_CTLX_SLAVE_SEL) << BIT_SHIFT_CTLX_SLAVE_SEL) +#define BIT_INV_CTLX_SLAVE_SEL (~(BIT_MASK_CTLX_SLAVE_SEL << BIT_SHIFT_CTLX_SLAVE_SEL)) + + +#define BIT_SHIFT_CTLX_CLK_SRC 30 +#define BIT_MASK_CTLX_CLK_SRC 0x1 +#define BIT_CTLX_CLK_SRC(x) (((x) & BIT_MASK_CTLX_CLK_SRC) << BIT_SHIFT_CTLX_CLK_SRC) +#define BIT_INV_CTLX_CLK_SRC (~(BIT_MASK_CTLX_CLK_SRC << BIT_SHIFT_CTLX_CLK_SRC)) + + + +#define BIT_SHIFT_CTLX_SW_RSTN 31 +#define BIT_MASK_CTLX_SW_RSTN 0x1 +#define BIT_CTLX_SW_RSTN(x) (((x) & BIT_MASK_CTLX_SW_RSTN) << BIT_SHIFT_CTLX_SW_RSTN) +#define BIT_INV_CTLX_SW_RSTN (~(BIT_MASK_CTLX_SW_RSTN << BIT_SHIFT_CTLX_SW_RSTN)) + + +#define BIT_SHIFT_SETTING_PAGE_SZ 0 +#define BIT_MASK_SETTING_PAGE_SZ 0xFFF +#define BIT_SETTING_PAGE_SZ(x) (((x) & BIT_MASK_SETTING_PAGE_SZ) << BIT_SHIFT_SETTING_PAGE_SZ) +#define BIT_INV_SETTING_PAGE_SZ (~(BIT_MASK_SETTING_PAGE_SZ << BIT_SHIFT_SETTING_PAGE_SZ)) + +#define BIT_SHIFT_SETTING_PAGE_NUM 12 +#define BIT_MASK_SETTING_PAGE_NUM 0x3 +#define BIT_SETTING_PAGE_NUM(x) (((x) & BIT_MASK_SETTING_PAGE_NUM) << BIT_SHIFT_SETTING_PAGE_NUM) +#define BIT_INV_SETTING_PAGE_NUM (~(BIT_MASK_SETTING_PAGE_NUM << BIT_SHIFT_SETTING_PAGE_NUM)) + +#define BIT_SHIFT_SETTING_SAMPLE_RATE 14 +#define BIT_MASK_SETTING_SAMPLE_RATE 0x7 +#define BIT_SETTING_SAMPLE_RATE(x) (((x) & BIT_MASK_SETTING_SAMPLE_RATE) << BIT_SHIFT_SETTING_SAMPLE_RATE) +#define BIT_INV_SETTING_SAMPLE_RATE (~(BIT_MASK_SETTING_SAMPLE_RATE << BIT_SHIFT_SETTING_SAMPLE_RATE)) +*/ + +typedef enum _I2S_CTL_FORMAT { + FormatI2s = 0x00, + FormatLeftJustified = 0x01, + FormatRightJustified = 0x02 +}I2S_CTL_FORMAT, *PI2S_CTL_FORMAT; + +typedef enum _I2S_CTL_CHNUM { + ChannelStereo = 0x00, + Channel5p1 = 0x01, + ChannelMono = 0x02 +}I2S_CTL_CHNUM, *PI2S_CTL_CHNUM; + +typedef enum _I2S_CTL_TRX_ACT { + RxOnly = 0x00, + TxOnly = 0x01, + TXRX = 0x02 +}I2S_CTL_TRX_ACT, *PI2S_CTL_TRX_ACT; +/* +typedef struct _I2S_CTL_REG_ { + I2S_CTL_FORMAT Format; + I2S_CTL_CHNUM ChNum; + I2S_CTL_TRX_ACT TrxAct; + + u32 I2s_En :1; // Bit 0 + u32 Rsvd1to4 :4; // Bit 1-4 is TrxAct, ChNum + u32 EdgeSw :1; // Bit 5 Edge switch + u32 WordLength :1; // Bit 6 + u32 LoopBack :1; // Bit 7 + u32 Rsvd8to9 :2; // Bit 8-9 is Format + u32 DacLrSwap :1; // Bit 10 + u32 SckInv :1; // Bit 11 + u32 EndianSwap :1; // Bit 12 + u32 Rsvd13to14 :2; // Bit 11-14 + u32 DebugSwitch :2; // Bit 15-16 + u32 Rsvd17to28 :12; // Bit 17-28 + u32 SlaveMode :1; // Bit 29 + u32 SR44p1KHz :1; // Bit 30 + u32 SwRstn :1; // Bit 31 +} I2S_CTL_REG, *PI2S_CTL_REG; +*/ +typedef enum _I2S_SETTING_PAGE_NUM { + I2s1Page = 0x00, + I2s2Page = 0x01, + I2s3Page = 0x02, + I2s4Page = 0x03 +}I2S_SETTING_PAGE_NUM, *PI2S_SETTING_PAGE_NUM; + +//sampling rate +typedef enum _I2S_SETTING_SR { + I2sSR8K = 0x00, + I2sSR16K = 0x01, + I2sSR24K = 0x02, + I2sSR32K = 0x03, + I2sSR48K = 0x05, + I2sSR44p1K = 0x15, + I2sSR96K = 0x06, + I2sSR88p2K = 0x16 +}I2S_SETTING_SR, *PI2S_SETTING_SR; +/* +typedef struct _I2S_SETTING_REG_ { + I2S_SETTING_PAGE_NUM PageNum; + I2S_SETTING_SR SampleRate; + + u32 PageSize:12; // Bit 0-11 +}I2S_SETTING_REG, *PI2S_SETTING_REG; + +typedef enum _I2S_TX_ISR { + I2sTxP0OK = 0x01, + I2sTxP1OK = 0x02, + I2sTxP2OK = 0x04, + I2sTxP3OK = 0x08, + I2sTxPageUn = 0x10, + I2sTxFifoEmpty = 0x20 +}I2S_TX_ISR, *PI2S_TX_ISR; + +typedef enum _I2S_RX_ISR { + I2sRxP0OK = 0x01, + I2sRxP1OK = 0x02, + I2sRxP2OK = 0x04, + I2sRxP3OK = 0x08, + I2sRxPageUn = 0x10, + I2sRxFifoFull = 0x20 +}I2S_RX_ISR, *PI2S_RX_ISR; +*/ + +/* Hal I2S function prototype*/ +RTK_STATUS +HalI2SInitRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SInitRtl8195a_Patch( + IN VOID *Data +); + +RTK_STATUS +HalI2SDeInitRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2STxRtl8195a( + IN VOID *Data, + IN u8 *pBuff +); + +RTK_STATUS +HalI2SRxRtl8195a( + IN VOID *Data, + OUT u8 *pBuff +); + +RTK_STATUS +HalI2SEnableRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SIntrCtrlRtl8195a( + IN VOID *Data +); + +u32 +HalI2SReadRegRtl8195a( + IN VOID *Data, + IN u8 I2SReg +); + +RTK_STATUS +HalI2SSetRateRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SSetWordLenRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SSetChNumRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SSetPageNumRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SSetPageSizeRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SSetDirectionRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SSetDMABufRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SClrIntrRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SClrAllIntrRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SDMACtrlRtl8195a( + IN VOID *Data +); + +u8 +HalI2SGetTxPageRtl8195a( + IN VOID *Data +); + +u8 +HalI2SGetRxPageRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SPageSendRtl8195a( + IN VOID *Data, + IN u8 PageIdx +); + +RTK_STATUS +HalI2SPageRecvRtl8195a( + IN VOID *Data +); + +RTK_STATUS +HalI2SClearAllOwnBitRtl8195a( + IN VOID *Data +); + +#ifdef CONFIG_CHIP_E_CUT +_LONG_CALL_ RTK_STATUS +HalI2SInitRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetRateRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetWordLenRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetChNumRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetPageNumRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetPageSizeRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetDirectionRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SSetDMABufRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ u8 +HalI2SGetTxPageRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ u8 +HalI2SGetRxPageRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SPageSendRtl8195a_V04( + IN VOID *Data, + IN u8 PageIdx +); + +_LONG_CALL_ RTK_STATUS +HalI2SPageRecvRtl8195a_V04( + IN VOID *Data +); + +_LONG_CALL_ RTK_STATUS +HalI2SClearAllOwnBitRtl8195a_V04( + IN VOID *Data +); + +#endif // #ifdef CONFIG_CHIP_E_CUT + +// HAL functions Wrapper +static __inline VOID +HalI2SSetRate( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetRateRtl8195a(Data); +#else + HalI2SSetRateRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SSetWordLen( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetWordLenRtl8195a(Data); +#else + HalI2SSetWordLenRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SSetChNum( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetChNumRtl8195a(Data); +#else + HalI2SSetChNumRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SSetPageNum( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetPageNumRtl8195a(Data); +#else + HalI2SSetPageNumRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SSetPageSize( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetPageSizeRtl8195a(Data); +#else + HalI2SSetPageSizeRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SSetDirection( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetDirectionRtl8195a(Data); +#else + HalI2SSetDirectionRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SSetDMABuf( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SSetDMABufRtl8195a(Data); +#else + HalI2SSetDMABufRtl8195a_V04(Data); +#endif +} + +static __inline u8 +HalI2SGetTxPage( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + return HalI2SGetTxPageRtl8195a(Data); +#else + return HalI2SGetTxPageRtl8195a_V04(Data); +#endif +} + +static __inline u8 +HalI2SGetRxPage( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + return HalI2SGetRxPageRtl8195a(Data); +#else + return HalI2SGetRxPageRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SPageSend( + IN VOID *Data, + IN u8 PageIdx +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SPageSendRtl8195a(Data, PageIdx); +#else + HalI2SPageSendRtl8195a_V04(Data, PageIdx); +#endif +} + +static __inline VOID +HalI2SPageRecv( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SPageRecvRtl8195a(Data); +#else + HalI2SPageRecvRtl8195a_V04(Data); +#endif +} + +static __inline VOID +HalI2SClearAllOwnBit( + IN VOID *Data +) +{ +#ifndef CONFIG_CHIP_E_CUT + HalI2SClearAllOwnBitRtl8195a(Data); +#else + HalI2SClearAllOwnBitRtl8195a_V04(Data); +#endif +} + +#endif /* _RTL8195A_I2S_H_ */ + + diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_pwm.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_pwm.h index 9d7266096e..19e7fef38a 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_pwm.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_pwm.h @@ -37,6 +37,10 @@ HAL_Pwm_Disable_8195a( HAL_PWM_ADAPTER *pPwmAdapt ); +extern void +HAL_Pwm_Dinit_8195a( + HAL_PWM_ADAPTER *pPwmAdapt +); #ifdef CONFIG_CHIP_E_CUT extern _LONG_CALL_ void diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio.h index 788413fea1..561ad06645 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_sdio.h @@ -13,46 +13,1028 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MBED_RTL8195A_SDIO_H -#define MBED_RTL8195A_SDIO_H -__BUILD_CCTRL_MACRO(SDIOD, REG_PESOC_HCI_CLK_CTRL0) -__BUILD_CCTRL_MACRO(SDIOH, REG_PESOC_HCI_CLK_CTRL0) -#define __SDIOD_Enable() \ - do { \ - __RTK_PERI_SETBIT(REG_SOC_HCI_COM_FUNC_EN, BIT_SOC_HCI_SDIOD_ON_EN); \ - __RTK_PERI_SETBIT(REG_SOC_HCI_COM_FUNC_EN, BIT_SOC_HCI_SDIOD_OFF_EN); \ - } while (0) - -#define __SDIOH_Enable() \ - do { \ - __RTK_PERI_SETBIT(REG_SOC_HCI_COM_FUNC_EN, BIT_SOC_HCI_SDIOH_EN); \ - } while (0) - -#define __SDIOD_Disable() \ - do { \ - __RTK_READ32(SDIO_DEVICE_REG_BASE, 0); \ - __RTK_PERI_CLRBIT(REG_SOC_HCI_COM_FUNC_EN, BIT_SOC_HCI_SDIOD_ON_EN); \ - __RTK_PERI_CLRBIT(REG_SOC_HCI_COM_FUNC_EN, BIT_SOC_HCI_SDIOD_OFF_EN); \ - } while (0) - -#define __SDIOH_Disable() \ - do { \ - __RTK_READ32(SDIO_HOST_REG_BASE, 0); \ - __RTK_PERI_CLRBIT(REG_SOC_HCI_COM_FUNC_EN, BIT_SOC_HCI_SDIOH_EN); \ - } while (0) - -// PERI_MCTRL_HCI -#define __SDIOD_PINMUX_Enable() __RTK_PERI_SETBIT(REG_HCI_PINMUX_CTRL, BIT_HCI_SDIOD_PIN_EN) -#define __SDIOH_PINMUX_Enable() __RTK_PERI_SETBIT(REG_HCI_PINMUX_CTRL, BIT_HCI_SDIOH_PIN_EN) -#define __SDIOD_PINMUX_Disable() __RTK_PERI_CLRBIT(REG_HCI_PINMUX_CTRL, BIT_HCI_SDIOD_PIN_EN) -#define __SDIOH_PINMUX_Disable() __RTK_PERI_CLRBIT(REG_HCI_PINMUX_CTRL, BIT_HCI_SDIOH_PIN_EN) -#define __MII_PINMUX_Enable() __RTK_PERI_SETBIT(REG_HCI_PINMUX_CTRL, BIT_HCI_MII_PIN_EN) -#define __MII_PINMUX_Disable() __RTK_PERI_CLRBIT(REG_HCI_PINMUX_CTRL, BIT_HCI_MII_PIN_EN) - -// Interface for HAL functions -extern void SDIO_HST_Disable(void); -extern void SDIO_DEV_Disable(void); +#ifndef _RTL8195A_SDIO_H_ +#define _RTL8195A_SDIO_H_ +#include "hal_api.h" +#include "hal_util.h" +#if defined(CONFIG_SDIO_BOOT_SIM) || defined(CONFIG_SDIO_BOOT_ROM) +#define SDIO_BOOT_DRIVER 1 // is this SDIO driver works for booting +#else +#include "osdep_api.h" +#define SDIO_BOOT_DRIVER 0 // is this SDIO driver works for booting #endif + +#if defined(__IAR_SYSTEMS_ICC__) //for IAR SDK +#include "platform_opts.h" +#endif + +#ifndef CONFIG_INIC_EN +#define CONFIG_INIC_EN 0 +#endif +#if CONFIG_INIC_EN +#define CONFIG_INIC_SKB_TX 1 //use SKB for trx to improve the throughput +#define CONFIG_INIC_SKB_RX 1 +#endif + +#if defined(__IAR_SYSTEMS_ICC__) && (CONFIG_INIC_EN == 0)//for IAR SDK + #define SDIO_API_DEFINED 1 +#else + #define SDIO_API_DEFINED 0 +#endif + +#ifndef PRIORITIE_OFFSET //PRIORITIE_OFFSET in FreeRTOSConfig.h +#define PRIORITIE_OFFSET 0 +#endif + +#define SDIO_DEBUG 0 +#define SDIO_MP_MODE 0 // if includes MP mode function +#define SDIO_MAX_WAIT_RX_DMA 100 // Wait RX DMA done +#define SDIO_RX_PKT_SIZE_OVER_16K 0 /* is support SDIO RX packet size > 16K. if true, + a big packet will be transmited via multiple RX_BD */ +#define SDIO_MAILBOX_SIZE 10 // the maximum number of message block can be stored in this mailbox +#define SDIO_PERIODICAL_TIMER_INTERVAL 2000 // in ms, the interval of SDIO periodical timer +#define SDIO_AVG_TP_WIN_SIZE 20 // the number of entry to log the byte count for every periodical timer statistic, to calculate throughput + +#define HAL_SDIO_READ32(addr) HAL_READ32(SDIO_DEVICE_REG_BASE, addr) +#define HAL_SDIO_WRITE32(addr, value) HAL_WRITE32(SDIO_DEVICE_REG_BASE, addr, value) +#define HAL_SDIO_READ16(addr) HAL_READ16(SDIO_DEVICE_REG_BASE, addr) +#define HAL_SDIO_WRITE16(addr, value) HAL_WRITE16(SDIO_DEVICE_REG_BASE, addr, value) +#define HAL_SDIO_READ8(addr) HAL_READ8(SDIO_DEVICE_REG_BASE, addr) +#define HAL_SDIO_WRITE8(addr, value) HAL_WRITE8(SDIO_DEVICE_REG_BASE, addr, value) + +/***** Register Address *****/ +#define REG_SPDIO_TXBD_ADDR 0xA0 // 4 Bytes +#define REG_SPDIO_TXBD_SIZE 0xA4 // 4 Bytes +#define REG_SPDIO_TXBD_WPTR 0xA8 // 2 Bytes +#define REG_SPDIO_TXBD_RPTR 0xAC // 2 Bytes +#define REG_SPDIO_RXBD_ADDR 0xB0 // 4 Bytes +#define REG_SPDIO_RXBD_SIZE 0xB4 // 2 Bytes +#define REG_SPDIO_RXBD_C2H_WPTR 0xB6 // 2 Bytes +#define REG_SPDIO_RXBD_C2H_RPTR 0xB8 // 2 Bytes +#define REG_SPDIO_HCI_RX_REQ 0xBA // 1 Byte +#define REG_SPDIO_CPU_RST_DMA 0xBB // 1 Byte +#define REG_SPDIO_RX_REQ_ADDR 0xBC // 2 Bytes +#define REG_SPDIO_CPU_INT_MASK 0xC0 // 2 Bytes +#define REG_SPDIO_CPU_INT_STAS 0xC2 // 2 Bytes +#define REG_SPDIO_CCPWM 0xC4 // 1 Byts +#define REG_SPDIO_CPU_IND 0xC5 // 1 Byte +#define REG_SPDIO_CCPWM2 0xC6 // 2 Bytes +#define REG_SPDIO_CPU_H2C_MSG 0xC8 // 4 Bytes +#define REG_SPDIO_CPU_C2H_MSG 0xCC // 4 Bytes +#define REG_SPDIO_CRPWM 0xD0 // 1 Bytes +#define REG_SPDIO_CRPWM2 0xD2 // 2 Bytes +#define REG_SPDIO_AHB_DMA_CTRL 0xD4 // 4 Bytes +#define REG_SPDIO_RXBD_CNT 0xD8 // 4 Bytes +#define REG_SPDIO_TX_BUF_UNIT_SZ 0xD9 // 1 Bytes +#define REG_SPDIO_RX_BD_FREE_CNT 0xDA // 2 Bytes +#define REG_SPDIO_CPU_H2C_MSG_EXT 0xDC // 4 Bytes +#define REG_SPDIO_CPU_C2H_MSG_EXT 0xE0 // 4 Bytes + +// Register REG_SPDIO_CPU_RST_DMA +#define BIT_CPU_RST_SDIO_DMA BIT(7) + +// Register REG_SPDIO_CPU_INT_MASK, REG_SPDIO_CPU_INT_STAS +#define BIT_TXFIFO_H2C_OVF BIT(0) +#define BIT_H2C_BUS_RES_FAIL BIT(1) +#define BIT_H2C_DMA_OK BIT(2) +#define BIT_C2H_DMA_OK BIT(3) +#define BIT_H2C_MSG_INT BIT(4) +#define BIT_RPWM1_INT BIT(5) +#define BIT_RPWM2_INT BIT(6) +#define BIT_SDIO_RST_CMD_INT BIT(7) +#define BIT_RXBD_FLAG_ERR_INT BIT(8) +#define BIT_RX_BD_AVAI_INT BIT(9) +#define BIT_HOST_WAKE_CPU_INT BIT(10) + +// Register REG_SPDIO_CPU_IND +#define BIT_SYSTEM_TRX_RDY_IND BIT(0) + +// Register REG_SPDIO_HCI_RX_REQ +#define BIT_HCI_RX_REQ BIT(0) + +/* Register for SOC_HCI_COM_FUN_EN */ +#define BIT_SOC_HCI_SDIOD_OFF_EN BIT(1) // SDIO Function Block on Power_Off domain +#define BIT_SOC_HCI_SDIOD_ON_EN BIT(0) // SDIO Function Block on Power_On domain + +/* Register REG_PESOC_HCI_CLK_CTRL0 */ +#define BIT_SOC_SLPCK_SDIO_HST_EN BIT(3) // SDIO_HST clock enable when CPU sleep command +#define BIT_SOC_ACTCK_SDIO_HST_EN BIT(2) // SDIO_HST clock enable in CPU run mode +#define BIT_SOC_SLPCK_SDIO_DEV_EN BIT(1) // SDIO_DEV clock enable when CPU sleep command +#define BIT_SOC_ACTCK_SDIO_DEV_EN BIT(0) // SDIO_DEV clock enable in CPU run mode + +/***** Structer for each Register *****/ +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) +// Little Endian +// Register REG_SPDIO_HCI_RX_REQ @ 0xBA +typedef struct _SPDIO_HCI_RX_REQ { + u8 HCI_RX_REQ:1; /* bit[0], CPU trigger this bit to enable SDIO IP RX transfer by fetch BD info */ + u8 Reserved:7; /* bit[7:1], Reserved */ +} SPDIO_HCI_RX_REQ, *PSPDIO_HCI_RX_REQ; + +// Register REG_SPDIO_CPU_RST_DMA @ 0xBB +typedef struct _SPDIO_CPU_RST_DMA { + u8 Reserved:7; /* bit[6:0], Reserved */ + u8 CPU_RST_SDIO:1; /* bit[7], CPU set this bit to reset SDIO DMA */ +} SPDIO_CPU_RST_DMA, *PSPDIO_CPU_RST_DMA; + +// Register REG_SPDIO_CPU_INT_MASK @ 0xC0 +typedef struct _SPDIO_CPU_INT_MASK { + u16 TXFIFO_H2C_OVF:1; /* bit[0], set 0 to mask TXFIFO_H2C_OVF_INT */ + u16 H2C_BUS_RES_FAIL:1; /* bit[1], set 0 to mask H2C_BUS_RES_FAIL_INT */ + u16 H2C_DMA_OK:1; /* bit[2], set 0 to mask H2C_DMA_OK_INT */ + u16 C2H_DMA_OK:1; /* bit[3], set 0 to mask C2H_DMA_OK_INT */ + u16 H2C_MSG_INT:1; /* bit[4], set 0 to mask H2C_MSG_INT_INT */ + u16 RPWM_INT:1; /* bit[5], set 0 to mask RPWM_INT */ + u16 RPWM2_INT:1; /* bit[6], set 0 to mask RPWM2_INT */ + u16 SDIO_RST_CMD_INT:1; /* bit[7], set 0 to mask SDIO_RST_CMD_INT */ + u16 BD_FLAG_ERR_INT:1; /* bit[8], set 0 to mask BD_FLAG_ERR_INT */ + u16 Reserved:7; /* bit[15:9], Reserved */ +} SPDIO_CPU_INT_MASK, *PSPDIO_CPU_INT_MASK; + +// Register REG_SPDIO_CPU_INT_STATUS @ 0xC2 +typedef struct _SPDIO_CPU_INT_STAS { + u16 TXFIFO_H2C_OVF:1; /* bit[0], set 0 to mask TXFIFO_H2C_OVF_INT */ + u16 H2C_BUS_RES_FAIL:1; /* bit[1], set 0 to mask H2C_BUS_RES_FAIL_INT */ + u16 H2C_DMA_OK:1; /* bit[2], set 0 to mask H2C_DMA_OK_INT */ + u16 C2H_DMA_OK:1; /* bit[3], set 0 to mask C2H_DMA_OK_INT */ + u16 H2C_MSG_INT:1; /* bit[4], set 0 to mask H2C_MSG_INT_INT */ + u16 RPWM_INT:1; /* bit[5], set 0 to mask RPWM_INT */ + u16 RPWM2_INT:1; /* bit[6], set 0 to mask RPWM2_INT */ + u16 SDIO_RST_CMD_INT:1; /* bit[7], set 0 to mask SDIO_RST_CMD_INT */ + u16 BD_FLAG_ERR_INT:1; /* bit[8], set 0 to mask BD_FLAG_ERR_INT */ + u16 Reserved:7; /* bit[15:9], Reserved */ +} SPDIO_CPU_INT_STAS, *PSPDIO_CPU_INT_STAS; + +// Register REG_SPDIO_CCPWM @ 0xC4 +typedef struct _SPDIO_CCPWM { + u8 :1; /* bit[0] */ + u8 WLAN_TRX:1; /* bit[1], 0: WLAN Off; 1: WLAN On */ + u8 RPS_ST:1; /* bit[2], 0/1: AP Register Sleep/Active state */ + u8 WWLAN:1; /* bit[3], 0/1: "Wake on WLAN"/"Normal" state */ + u8 Reserved:3; /* bit[6:4], Reserved */ + u8 TOGGLING:1; /* bit[7], issue interrupt when 0->1 or 1->0 */ +} SPDIO_CCPWM, *PSPDIO_CCPWM; + +// Register REG_SPDIO_CPU_IND @ 0xC5 +typedef struct _SPDIO_CPU_IND { + u8 SYS_TRX_RDY:1; /* bit[0], To indicate the Host system that CPU is ready for TRX + , to be sync to 0x87[0] */ + u8 Reserved:7; /* bit[7:1], Reserved */ +} SPDIO_CPU_IND, *PSPDIO_CPU_IND; + +// Register REG_SPDIO_CPU_H2C_MSG @ 0xC8 +typedef struct _SPDIO_CPU_H2C_MSG { + u32 CPU_H2C_MSG:30; /* bit[30:0], Host CPU to FW message, sync from REG_SDIO_H2C_MSG */ + u32 Reserved:1; /* bit[31], Reserved */ +} SPDIO_CPU_H2C_MSG, *PSPDIO_CPU_H2C_MSG; + +// Register REG_SPDIO_CPU_C2H_MSG @ 0xCC +typedef struct _SPDIO_CPU_C2H_MSG { + u32 CPU_C2H_MSG:30; /* bit[30:0], FW to Host CPU message, sync to REG_SDIO_C2H_MSG */ + u32 Reserved:1; /* bit[31], Reserved */ +} SPDIO_CPU_C2H_MSG, *PSPDIO_CPU_C2H_MSG; + +// Register REG_SPDIO_CRPWM @ 0xD0 +typedef struct _SPDIO_CRPWM { + u8 :1; /* bit[0] */ + u8 WLAN_TRX:1; /* bit[1], 0: WLAN Off; 1: WLAN On */ + u8 RPS_ST:1; /* bit[2], 0/1: AP Register Sleep/Active state */ + u8 WWLAN:1; /* bit[3], 0/1: "Wake on WLAN"/"Normal" state */ + u8 Reserved:3; /* bit[6:4], Reserved */ + u8 TOGGLING:1; /* bit[7], issue interrupt when 0->1 or 1->0 */ +} SPDIO_CRPWM, *PSPDIO_CRPWM; + +// Register REG_SPDIO_AHB_DMA_CTRL @ 0xD4 +typedef struct _SPDIO_AHB_DMA_CTRL { + u32 TXFF_WLEVEL:7; /* bit[6:0], SPDIO TX FIFO water level */ + u32 :1; /* bit[7] */ + u32 RXFF_WLEVEL:7; /* bit[14:8], SPDIO RX FIFO water level */ + u32 :1; /* bit[15] */ + u32 AHB_DMA_CS:4; /* bit[19:16], AHB DMA state */ + u32 :1; /* bit[20] */ + u32 AHB_MASTER_RDY:1; /* bit[21], AHB Master Hready signal */ + u32 AHB_DMA_TRANS:2; /* bit[23:22], AHB DMA Trans value, for debugging */ + u32 AHB_BUSY_WAIT_CNT:4; /* bit[27:24], timeout for AHB controller to wait busy */ + u32 AHB_BURST_TYPE:3; /* bit[30:28], AHB burst type */ + u32 DISPATCH_TXAGG:1; /* bit[31], Enable to dispatch aggregated TX packet */ +} SPDIO_AHB_DMA_CTRL, *PSPDIO_AHB_DMA_CTRL; + +#else /* else of '#if LITTLE_ENDIAN' */ +// Big Endian +typedef struct _SPDIO_HCI_RX_REQ { + u8 Reserved:7; /* bit[7:1], Reserved */ + u8 HCI_RX_REQ:1; /* bit[0], CPU trigger this bit to enable SDIO IP RX transfer by fetch BD info */ +} SPDIO_HCI_RX_REQ, *PSPDIO_HCI_RX_REQ; + +// Register REG_SPDIO_CPU_RST_DMA @ 0xBB +typedef struct _SPDIO_CPU_RST_DMA { + u8 CPU_RST_SDIO:1; /* bit[7], CPU set this bit to reset SDIO DMA */ + u8 Reserved:7; /* bit[6:0], Reserved */ +} SPDIO_CPU_RST_DMA, *PSPDIO_CPU_RST_DMA; + +// Register REG_SPDIO_CPU_INT_MASK @ 0xC0 +typedef struct _SPDIO_CPU_INT_MASK { + u16 Reserved:7; /* bit[15:9], Reserved */ + u16 BD_FLAG_ERR_INT:1; /* bit[8], set 0 to mask BD_FLAG_ERR_INT */ + u16 SDIO_RST_CMD_INT:1; /* bit[7], set 0 to mask SDIO_RST_CMD_INT */ + u16 RPWM2_INT:1; /* bit[6], set 0 to mask RPWM2_INT */ + u16 RPWM_INT:1; /* bit[5], set 0 to mask RPWM_INT */ + u16 H2C_MSG_INT:1; /* bit[4], set 0 to mask H2C_MSG_INT_INT */ + u16 C2H_DMA_OK:1; /* bit[3], set 0 to mask C2H_DMA_OK_INT */ + u16 H2C_DMA_OK:1; /* bit[2], set 0 to mask H2C_DMA_OK_INT */ + u16 H2C_BUS_RES_FAIL:1; /* bit[1], set 0 to mask H2C_BUS_RES_FAIL_INT */ + u16 TXFIFO_H2C_OVF:1; /* bit[0], set 0 to mask TXFIFO_H2C_OVF_INT */ +} SPDIO_CPU_INT_MASK, *PSPDIO_CPU_INT_MASK; + +// Register REG_SPDIO_CPU_INT_STAS @ 0xC2 +typedef struct _SPDIO_CPU_INT_STAS { + u16 Reserved:7; /* bit[15:9], Reserved */ + u16 BD_FLAG_ERR_INT:1; /* bit[8], set 0 to mask BD_FLAG_ERR_INT */ + u16 SDIO_RST_CMD_INT:1; /* bit[7], set 0 to mask SDIO_RST_CMD_INT */ + u16 RPWM2_INT:1; /* bit[6], set 0 to mask RPWM2_INT */ + u16 RPWM_INT:1; /* bit[5], set 0 to mask RPWM_INT */ + u16 H2C_MSG_INT:1; /* bit[4], set 0 to mask H2C_MSG_INT_INT */ + u16 C2H_DMA_OK:1; /* bit[3], set 0 to mask C2H_DMA_OK_INT */ + u16 H2C_DMA_OK:1; /* bit[2], set 0 to mask H2C_DMA_OK_INT */ + u16 H2C_BUS_RES_FAIL:1; /* bit[1], set 0 to mask H2C_BUS_RES_FAIL_INT */ + u16 TXFIFO_H2C_OVF:1; /* bit[0], set 0 to mask TXFIFO_H2C_OVF_INT */ +} SPDIO_CPU_INT_STAS, *PSPDIO_CPU_INT_STAS; + +// Register REG_SPDIO_CCPWM @ 0xC4 +typedef struct _SPDIO_CCPWM { + u8 TOGGLING:1; /* bit[7], issue interrupt when 0->1 or 1->0 */ + u8 Reserved:3; /* bit[6:4], Reserved */ + u8 WWLAN:1; /* bit[3], 0/1: "Wake on WLAN"/"Normal" state */ + u8 RPS_ST:1; /* bit[2], 0/1: AP Register Sleep/Active state */ + u8 WLAN_TRX:1; /* bit[1], 0: WLAN Off; 1: WLAN On */ + u8 :1; /* bit[0] */ +} SPDIO_CCPWM, *PSPDIO_CCPWM; + +// Register REG_SPDIO_CPU_IND @ 0xC5 +typedef struct _SPDIO_CPU_IND { + u8 Reserved:7; /* bit[7:1], Reserved */ + u8 SYS_TRX_RDY:1; /* bit[0], To indicate the Host system that CPU is ready for TRX + , to be sync to 0x87[0] */ +} SPDIO_CPU_IND, *PSPDIO_CPU_IND; + +// Register REG_SPDIO_CPU_H2C_MSG @ 0xC8 +typedef struct _SPDIO_CPU_H2C_MSG { + u32 Reserved:1; /* bit[31], Reserved */ + u32 CPU_H2C_MSG:30; /* bit[30:0], Host CPU to FW message */ +} SPDIO_CPU_H2C_MSG, *PSPDIO_CPU_H2C_MSG; + +// Register REG_SPDIO_CPU_C2H_MSG @ 0xCC +typedef struct _SPDIO_CPU_C2H_MSG { + u32 Reserved:1; /* bit[31], Reserved */ + u32 CPU_C2H_MSG:30; /* bit[30:0], FW to Host CPU message, sync to REG_SDIO_C2H_MSG */ +} SPDIO_CPU_C2H_MSG, *PSPDIO_CPU_C2H_MSG; + +// Register REG_SPDIO_CRPWM @ 0xD0 +typedef struct _SPDIO_CRPWM { + u8 TOGGLING:1; /* bit[7], issue interrupt when 0->1 or 1->0 */ + u8 Reserved:3; /* bit[6:4], Reserved */ + u8 WWLAN:1; /* bit[3], 0/1: "Wake on WLAN"/"Normal" state */ + u8 RPS_ST:1; /* bit[2], 0/1: AP Register Sleep/Active state */ + u8 WLAN_TRX:1; /* bit[1], 0: WLAN Off; 1: WLAN On */ + u8 :1; /* bit[0] */ +} SPDIO_CRPWM, *PSPDIO_CRPWM; + +// Register REG_SPDIO_AHB_DMA_CTRL @ 0xD4 +typedef struct _SPDIO_AHB_DMA_CTRL { + u32 DISPATCH_TXAGG:1; /* bit[31], Enable to dispatch aggregated TX packet */ + u32 AHB_BURST_TYPE:3; /* bit[30:28], AHB burst type */ + u32 AHB_BUSY_WAIT_CNT:4; /* bit[27:24], timeout for AHB controller to wait busy */ + u32 AHB_DMA_TRANS:2; /* bit[23:22], AHB DMA Trans value, for debugging */ + u32 AHB_MASTER_RDY:1; /* bit[21], AHB Master Hready signal */ + u32 :1; /* bit[20] */ + u32 AHB_DMA_CS:4; /* bit[19:16], AHB DMA state */ + u32 :1; /* bit[15] */ + u32 RXFF_WLEVEL:7; /* bit[14:8], SPDIO RX FIFO water level */ + u32 :1; /* bit[7] */ + u32 TXFF_WLEVEL:7; /* bit[6:0], SPDIO TX FIFO water level */ +} SPDIO_AHB_DMA_CTRL, *PSPDIO_AHB_DMA_CTRL; + +#endif /* end of '#if LITTLE_ENDIAN' */ + + +//#define TX_FIFO_ADDR 0x0000 +//#define TX_FIFO_SIZE 0x8000 + +//TX BD setting +#if SDIO_BOOT_DRIVER +// for build ROM library +#define SDIO_TX_BD_NUM 2 // Number of TX BD +#define SDIO_TX_BD_BUF_SIZE (2048+32) // the size of a TX BD pointed buffer, WLan header = 26 bytes +#define SDIO_TX_PKT_NUM 10 // Number of TX packet handler + +//RX BD setting +#define RX_BD_FREE_TH 4 // trigger the interrupt when free RX BD over this threshold + +#define MAX_RX_BD_BUF_SIZE 16380 // the Maximum size for a RX_BD point to, make it 4-bytes aligned + +#define SDIO_RX_PKT_NUM 3 // Number of RX packet handler +//#define SDIO_RX_BD_NUM 10 // Number of RX BD, to make 32K of bus aggregation, it needs 22 RX_BD at least +#define SDIO_RX_BD_NUM (SDIO_RX_PKT_NUM*2) // Number of RX BD, to make 32K of bus aggregation, it needs 22 RX_BD at least +#define SDIO_RX_BD_BUF_SIZE (2048+24) // the size of a RX BD pointed buffer, sizeof(RX Desc) = 26 bytes +#define MIN_RX_BD_SEND_PKT 2 /* the minum needed RX_BD to send a Packet to Host, we need 2: + one for RX_Desc, the other for payload */ + +// CCPWM2 bit map definition for Firmware download +#define SDIO_INIT_DONE (BIT0) +#define SDIO_MEM_WR_DONE (BIT1) +#define SDIO_MEM_RD_DONE (BIT2) +#define SDIO_MEM_ST_DONE (BIT3) + +#define SDIO_CPWM2_TOGGLE (BIT15) + +#else +#if CONFIG_INIC_EN +//TX BD setting +#define SDIO_TX_BD_NUM 20 // Number of TX BD +#define SDIO_TX_BD_BUF_SIZE 1540 //1514+24 +//#define SDIO_TX_PKT_NUM 1 // not used + +//RX BD setting +#define RX_BD_FREE_TH 5 // trigger the interrupt when free RX BD over this threshold +#define SDIO_RX_BD_BUF_SIZE 1540 //1514+24 +#define MAX_RX_BD_BUF_SIZE 16380 // the Maximum size for a RX_BD point to, make it 4-bytes aligned +#define SDIO_RX_BD_NUM 32 // Number of RX BD, to make 32K of bus aggregation, it needs 22 RX_BD at least +#define SDIO_RX_PKT_NUM 128 // Number of RX packet handler +#define MIN_RX_BD_SEND_PKT 2 /* the minum needed RX_BD to send a Packet to Host, we need 2: + one for RX_Desc, the other for payload */ + +#else +#define SDIO_TX_BD_NUM 24 // Number of TX BD +#define SDIO_TX_BD_BUF_SIZE (2048+32) // the size of a TX BD pointed buffer, WLan header = 26 bytes +#define SDIO_TX_PKT_NUM 128 // Number of TX packet handler + +//RX BD setting +#define RX_BD_FREE_TH 5 // trigger the interrupt when free RX BD over this threshold + +#define SDIO_RX_BD_BUF_SIZE 2048 +#define MAX_RX_BD_BUF_SIZE 16380 // the Maximum size for a RX_BD point to, make it 4-bytes aligned + +//#define SDIO_TX_FIFO_SIZE (1024*64) // 64K +#define SDIO_RX_BD_NUM 24 // Number of RX BD, to make 32K of bus aggregation, it needs 22 RX_BD at least +#define SDIO_RX_PKT_NUM 128 // Number of RX packet handler +#define MIN_RX_BD_SEND_PKT 2 /* the minum needed RX_BD to send a Packet to Host, we need 2: + one for RX_Desc, the other for payload */ +#endif +#endif + +#define SDIO_IRQ_PRIORITY 10 + +/* SDIO Events */ +#define SDIO_EVENT_IRQ BIT(0) // Interrupt triggered +#define SDIO_EVENT_RX_PKT_RDY BIT(1) // A new SDIO packet ready +#define SDIO_EVENT_C2H_DMA_DONE BIT(2) // Interrupt of C2H DMA done triggered +#define SDIO_EVENT_DUMP BIT(3) // SDIO status dump periodically Enable +#define SDIO_EVENT_TXBD_REFILL BIT(4) // To refill TX BD buffer +#define SDIO_EVENT_EXIT BIT(28) // Request to exit the SDIO task +#define SDIO_EVENT_MP_STOPPED BIT(29) // The SDIO task is stopped +#define SDIO_EVENT_TX_STOPPED BIT(30) // The SDIO task is stopped +#define SDIO_EVENT_RX_STOPPED BIT(31) // The SDIO task is stopped + +#define SDIO_TASK_PRIORITY 1 // it can be 0(lowest) ~ configMAX_PRIORITIES-1(highest) +#define SDIO_MP_TASK_PRIORITY 2 // it can be 0(lowest) ~ configMAX_PRIORITIES-1(highest) +//#if SDIO_TASK_PRIORITY > (configMAX_PRIORITIES - 1) +#if SDIO_TASK_PRIORITY > (4 - 1) +#error "SDIO Task Priority Should be 0~(configMAX_PRIORITIES-1)" +#endif + +//#define TX_RX_PACKET_SIZE 0x144 + +typedef struct _SDIO_TX_BD_ { + u32 Address; /* The TX buffer physical address, it must be 4-bytes aligned */ +}SDIO_TX_BD, *PSDIO_TX_BD; + +#define TX_BD_STRUCTURE_SIZE (sizeof(SDIO_TX_BD)) + + +/* The RX Buffer Descriptor format */ + +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) +typedef struct _SDIO_RX_BD_ { + u32 BuffSize:14; /* bit[13:0], RX Buffer Size, Maximum 16384-1 */ + u32 LS:1; /* bit[14], is the Last Segment ? */ + u32 FS:1; /* bit[15], is the First Segment ? */ + u32 Seq:16; /* bit[31:16], The sequence number, it's no use for now */ + u32 PhyAddr; /* The RX buffer physical address, it must be 4-bytes aligned */ +} SDIO_RX_BD, *PSDIO_RX_BD; +#else +typedef struct _SDIO_RX_BD_ { + u32 Seq:16; /* bit[31:16], The sequence number, be used for ?? */ + u32 FS:1; /* bit[15], is the First Segment ? */ + u32 LS:1; /* bit[14], is the Last Segment ? */ + u32 BuffSize:14; /* bit[13:0], RX Buffer Size, Maximum 16384 */ + u32 PhyAddr; /* The RX buffer physical address, it must be 4-bytes aligned */ +} SDIO_RX_BD, *PSDIO_RX_BD; +#endif +#define RX_BD_STRUCTURE_SIZE (sizeof(SDIO_RX_BD)) + +// TODO: This data structer just for test, we should modify it for the normal driver +typedef struct _SDIO_TX_DESC{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 txpktsize:16; // bit[15:0] + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number +#else + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 txpktsize:16; // bit[15:0] +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the packet type + u32 rsvd0:24; +#else + u32 rsvd0:24; + u32 type:8; // bit[7:0], the packet type +#endif + + // u4Byte 2 + u32 rsvd1; + + // u4Byte 3 + u32 rsvd2; + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_TX_DESC, *PSDIO_TX_DESC; + +// TX Desc for Memory Write command +typedef struct _SDIO_TX_DESC_MW{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 txpktsize:16; // bit[15:0] + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number +#else + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 txpktsize:16; // bit[15:0] +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the packet type + u32 reply:1; // bit[8], request to send a reply message + u32 rsvd0:23; +#else + u32 rsvd0:23; + u32 reply:1; // bit[8], request to send a reply message + u32 type:8; // bit[7:0], the packet type +#endif + + // u4Byte 2 + u32 start_addr; // memory write start address + + // u4Byte 3 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 write_len:16; // bit[15:0], the length to write + u32 rsvd2:16; // bit[31:16] +#else + u32 rsvd2:16; // bit[31:16] + u32 write_len:16; // bit[15:0], the length to write +#endif + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_TX_DESC_MW, *PSDIO_TX_DESC_MW; + +// TX Desc for Memory Read command +typedef struct _SDIO_TX_DESC_MR{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 txpktsize:16; // bit[15:0] + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number +#else + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 txpktsize:16; // bit[15:0] +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the packet type + u32 rsvd0:24; +#else + u32 rsvd0:24; + u32 type:8; // bit[7:0], the packet type +#endif + + // u4Byte 2 + u32 start_addr; // memory write start address + + // u4Byte 3 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 read_len:16; // bit[15:0], the length to read + u32 rsvd2:16; // bit[31:16] +#else + u32 rsvd2:16; // bit[31:16] + u32 read_len:16; // bit[15:0], the length to read +#endif + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_TX_DESC_MR, *PSDIO_TX_DESC_MR; + +// TX Desc for Memory Set command +typedef struct _SDIO_TX_DESC_MS{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 txpktsize:16; // bit[15:0] + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number +#else + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 txpktsize:16; // bit[15:0] +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the packet type + u32 data:8; // bit[8:15], the value to be written to the memory + u32 reply:1; // bit[16], request to send a reply message + u32 rsvd0:15; +#else + u32 rsvd0:15; + u32 reply:1; // bit[16], request to send a reply message + u32 data:8; // bit[8:15], the value to be written to the memory + u32 type:8; // bit[7:0], the packet type +#endif + + // u4Byte 2 + u32 start_addr; // memory write start address + + // u4Byte 3 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 write_len:16; // bit[15:0], the length to write + u32 rsvd2:16; // bit[31:16] +#else + u32 rsvd2:16; // bit[31:16] + u32 write_len:16; // bit[15:0], the length to write +#endif + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_TX_DESC_MS, *PSDIO_TX_DESC_MS; + +// TX Desc for Jump to Start command +typedef struct _SDIO_TX_DESC_JS{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 txpktsize:16; // bit[15:0] + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number +#else + u32 bus_agg_num:8; // bit[31:24], the bus aggregation number + u32 offset:8; // bit[23:16], store the sizeof(SDIO_TX_DESC) + u32 txpktsize:16; // bit[15:0] +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the packet type + u32 rsvd0:24; +#else + u32 rsvd0:24; + u32 type:8; // bit[7:0], the packet type +#endif + + // u4Byte 2 + u32 start_fun; // the pointer of the startup function + + // u4Byte 3 + u32 rsvd2; + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_TX_DESC_JS, *PSDIO_TX_DESC_JS; + + +#define SIZE_TX_DESC (sizeof(SDIO_TX_DESC)) +// define the TX BD buffer size with unite of 64 byets +/* Be carefull!! the setting of hardware's TX BD buffer size may exceed the real size of + the TX BD buffer size, and then it may cause the hardware DMA write the buffer overflow */ +#define SDIO_TX_BUF_SZ_UNIT 64 +#define SDIO_TX_BD_BUF_USIZE ((((SDIO_TX_BD_BUF_SIZE+sizeof(SDIO_TX_DESC)-1)/SDIO_TX_BUF_SZ_UNIT)+1)&0xff) + +typedef struct _SDIO_TX_BD_BUFFER_ { + SDIO_TX_DESC TX_Desc; + u8 TX_Buffer[SDIO_TX_BD_BUF_SIZE]; +}SDIO_TX_BD_BUFFER, *PSDIO_TX_BD_BUFFER; + + +// TODO: This data structer just for test, we should modify it for the normal driver +typedef struct _SDIO_RX_DESC{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 pkt_len:16; // bit[15:0], the packet size + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 rsvd0:6; // bit[29:24] + u32 icv:1; // bit[30], ICV error + u32 crc:1; // bit[31], CRC error +#else + u32 crc:1; // bit[31], CRC error + u32 icv:1; // bit[30], ICV error + u32 rsvd0:6; // bit[29:24] + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 pkt_len:16; // bit[15:0], the packet size +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the type of this packet + u32 rsvd1:24; // bit[31:8] +#else + u32 rsvd1:24; // bit[31:8] + u32 type:8; // bit[7:0], the type of this packet +#endif + + // u4Byte 2 + u32 rsvd2; + + // u4Byte 3 + u32 rsvd3; + + // u4Byte 4 + u32 rsvd4; + + // u4Byte 5 + u32 rsvd5; +} SDIO_RX_DESC, *PSDIO_RX_DESC; + +// For memory read command +typedef struct _SDIO_RX_DESC_MR{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 pkt_len:16; // bit[15:0], the packet size + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 rsvd0:8; // bit[31:24] +#else + u32 rsvd0:8; // bit[31:24] + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 pkt_len:16; // bit[15:0], the packet size +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the type of this packet + u32 rsvd1:24; // bit[31:8] +#else + u32 rsvd1:24; // bit[31:8] + u32 type:8; // bit[7:0], the type of this packet +#endif + + // u4Byte 2 + u32 start_addr; + + // u4Byte 3 + u32 rsvd2; + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_RX_DESC_MR, *PSDIO_RX_DESC_MR; + +// For memory write reply command +typedef struct _SDIO_RX_DESC_MW{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 pkt_len:16; // bit[15:0], the packet size + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 rsvd0:8; // bit[31:24] +#else + u32 rsvd0:8; // bit[31:24] + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 pkt_len:16; // bit[15:0], the packet size +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the type of this packet + u32 rsvd1:24; // bit[31:8] +#else + u32 rsvd1:24; // bit[31:8] + u32 type:8; // bit[7:0], the type of this packet +#endif + + // u4Byte 2 + u32 start_addr; + + // u4Byte 3 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 write_len:16; // bit[15:0], the type of this packet + u32 result:8; // bit[23:16], the result of memory write command + u32 rsvd2:8; // bit[31:24] +#else + u32 rsvd2:8; // bit[31:24] + u32 result:8; // bit[23:16], the result of memory write command + u32 write_len:16; // bit[15:0], the type of this packet +#endif + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_RX_DESC_MW, *PSDIO_RX_DESC_MW; + +// For memory set reply command +typedef struct _SDIO_RX_DESC_MS{ + // u4Byte 0 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 pkt_len:16; // bit[15:0], the packet size + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 rsvd0:8; // bit[31:24] +#else + u32 rsvd0:8; // bit[31:24] + u32 offset:8; // bit[23:16], the offset from the packet start to the buf start, also means the size of RX Desc + u32 pkt_len:16; // bit[15:0], the packet size +#endif + + // u4Byte 1 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 type:8; // bit[7:0], the type of this packet + u32 rsvd1:24; // bit[31:8] +#else + u32 rsvd1:24; // bit[31:8] + u32 type:8; // bit[7:0], the type of this packet +#endif + + // u4Byte 2 + u32 start_addr; + + // u4Byte 3 +#if (SYSTEM_ENDIAN==PLATFORM_LITTLE_ENDIAN) + u32 write_len:16; // bit[15:0], the type of this packet + u32 result:8; // bit[23:16], the result of memory write command + u32 rsvd2:8; // bit[31:24] +#else + u32 rsvd2:8; // bit[31:24] + u32 result:8; // bit[23:16], the result of memory write command + u32 write_len:16; // bit[15:0], the type of this packet +#endif + + // u4Byte 4 + u32 rsvd3; + + // u4Byte 5 + u32 rsvd4; +} SDIO_RX_DESC_MS, *PSDIO_RX_DESC_MS; + +#define SIZE_RX_DESC (sizeof(SDIO_RX_DESC)) + +typedef struct _SDIO_RX_BD_BUFFER_ { + SDIO_RX_DESC RX_Desc; + u8 RX_Buffer[SDIO_RX_BD_BUF_SIZE]; +}SDIO_RX_BD_BUFFER, *PSDIO_RX_BD_BUFFER; + + +/* The data structer for a packet fordwarding to the WLan driver to transmit it */ +// TODO: This data structer just for test, we may need modify it for the normal driver +typedef struct _SDIO_TX_PACKET_ { + u8 *pHeader; // Point to the 1st byte of the packets + u16 PktSize; // the size (bytes) of this packet + _LIST list; // the link list to chain packets + u8 isDyna; // is Dynamic allocated +} SDIO_TX_PACKET, *PSDIO_TX_PACKET; + +/* the data structer to bind a TX_BD with a TX Packet */ +typedef struct _SDIO_TX_BD_HANDLE_ { + SDIO_TX_BD *pTXBD; // Point to the TX_BD buffer +#if SDIO_API_DEFINED + VOID *priv; +#else +#if CONFIG_INIC_EN +#if CONFIG_INIC_SKB_TX + struct sk_buff *skb; +#endif +#endif +#endif + SDIO_TX_PACKET *pPkt; // point to the Tx Packet + u8 isPktEnd; // For a packet over 1 BD , this flag to indicate is this BD contains a packet end + u8 isFree; // is this TX BD free +} SDIO_TX_BD_HANDLE, *PSDIO_TX_BD_HANDLE; + +/* The data structer for a packet which from the WLan driver to send to the Host */ +// TODO: This data structer just for test, we may need modify it for the normal driver + +#if SDIO_BOOT_DRIVER +typedef struct _SDIO_RX_PACKET_ { +// SDIO_RX_DESC RxDesc; // The RX Descriptor for this packet, to be send to Host ahead this packet + u8 *pData; // point to the head of payload of this packet + u16 Offset; // the offset from the pData to the payload buffer + _LIST list; // the link list to chain packets + u8 PktBuf[SDIO_RX_BD_BUF_SIZE]; // the Rx_Desc + payload data buffer, the first 24 bytes is reserved for RX_DESC +} SDIO_RX_PACKET, *PSDIO_RX_PACKET; +#else +typedef struct _SDIO_RX_PACKET_ { + SDIO_RX_DESC RxDesc; // The RX Descriptor for this packet, to be send to Host ahead this packet +#if SDIO_API_DEFINED + VOID *priv; +#else +#if CONFIG_INIC_EN +#if CONFIG_INIC_SKB_RX + struct sk_buff *skb; +#endif +#endif +#endif + u8 *pData; // point to the head of payload of this packet + u16 Offset; // the offset from the pData to the payload buffer + _LIST list; // the link list to chain packets + u8 isDyna; // is Dynamic allocated +} SDIO_RX_PACKET, *PSDIO_RX_PACKET; +#endif + +/* the data structer to bind a RX_BD with a RX Packet */ +typedef struct _SDIO_RX_BD_HANDLE_ { + SDIO_RX_BD *pRXBD; // Point to the RX_BD buffer + SDIO_RX_PACKET *pPkt; // point to the Rx Packet + u8 isPktEnd; // For a packet over 1 BD , this flag to indicate is this BD contains a packet end + u8 isFree; // is this RX BD free (DMA done and its RX packet has been freed) +} SDIO_RX_BD_HANDLE, *PSDIO_RX_BD_HANDLE; + +#if SDIO_MP_MODE +typedef struct _SDIO_MP_CMD_ { + u8 cmd_name[16]; + u32 cmd_type; +} SDIO_MP_CMD, *PSDIO_MP_CMD; + +typedef enum _SDIO_MP_CMD_TYPE_{ + SDIO_MP_START=1, + SDIO_MP_STOP=2, + SDIO_MP_LOOPBACK=3, + SDIO_MP_STATUS=4, + SDIO_MP_READ_REG8=5, + SDIO_MP_READ_REG16=6, + SDIO_MP_READ_REG32=7, + SDIO_MP_WRITE_REG8=8, + SDIO_MP_WRITE_REG16=9, + SDIO_MP_WRITE_REG32=10, + SDIO_MP_WAKEUP=11, // wakeup the SDIO task manually, for debugging + SDIO_MP_DUMP=12, // start/stop to dump the SDIO status periodically + SDIO_MP_CTX=13, // setup continue TX test + SDIO_MP_CRX=14, // setup continue RX test + SDIO_MP_CRX_DA=15, // setup continue RX with dynamic allocate RX Buf test + SDIO_MP_CRX_STOP=16, // setup continue RX test + SDIO_MP_DBG_MSG=17, // Debug message On/Off + +}SDIO_MP_CMD_TYPE; + +typedef enum _SDIO_CRX_MODE_{ + SDIO_CRX_STATIC_BUF = 1, + SDIO_CRX_DYNA_BUF = 2, +} SDIO_CRX_MODE; + +typedef struct _SDIO_MP_RX_PACKET_ { + _LIST list; // this member MUST be the 1st one, the link list to chain packets + u8 *pData; // point to the head of payload of this packet + u16 Offset; // the offset from the pData to the payload + u16 DataLen; // the data length of this packet +} SDIO_MP_RX_PACKET, *PSDIO_MP_RX_PACKET; + +#endif // end of '#if SDIO_MP_MODE' + +#define SDIO_CMD_TX_ETH 0x83 // request to TX a 802.3 packet +#define SDIO_CMD_TX_WLN 0x81 // request to TX a 802.11 packet +#define SDIO_CMD_H2C 0x11 // H2C(host to device) command packet +#define SDIO_CMD_MEMRD 0x51 // request to read a block of memory data +#define SDIO_CMD_MEMWR 0x53 // request to write a block of memory +#define SDIO_CMD_MEMST 0x55 // request to set a block of memory with a value +#define SDIO_CMD_STARTUP 0x61 // request to jump to the start up function + +#define SDIO_CMD_RX_ETH 0x82 // indicate a RX 802.3 packet +#define SDIO_CMD_RX_WLN 0x80 // indicate a RX 802.11 packet +#define SDIO_CMD_C2H 0x10 // C2H(device to host) command packet +#define SDIO_CMD_MEMRD_RSP 0x50 // response to memory block read command +#define SDIO_CMD_MEMWR_RSP 0x52 // response to memory write command +#define SDIO_CMD_MEMST_RSP 0x54 // response to memory set command +#define SDIO_CMD_STARTED 0x60 // indicate the program has jumped to the given function + +enum SDIO_RPWM2_BITS { + RPWM2_ACT_BIT = BIT0, // Active + RPWM2_SLEEP_BIT = 0, // Sleep + RPWM2_DSTANDBY_BIT = BIT1, // Deep Standby + RPWM2_PG_BIT = 0, // Power Gated + RPWM2_FBOOT_BIT = BIT2, // fast reboot + RPWM2_NBOOT_BIT = 0, // normal reboot + RPWM2_WKPIN_A5_BIT = BIT3, // enable GPIO A5 wakeup + RPWM2_WKPIN_C7_BIT = BIT4, // enable GPIO C7 wakeup + RPWM2_WKPIN_D5_BIT = BIT5, // enable GPIO D5 wakeup + RPWM2_WKPIN_E3_BIT = BIT6, // enable GPIO E3 wakeup + RPWM2_PIN_A5_LV_BIT = BIT7, // GPIO A5 wakeup level + RPWM2_PIN_C7_LV_BIT = BIT8, // GPIO C7 wakeup level + RPWM2_PIN_D5_LV_BIT = BIT9, // GPIO D5 wakeup level + RPWM2_PIN_E3_LV_BIT = BIT10, // GPIO E3 wakeup level + RPWM2_CG_BIT = BIT11, // Clock Gated + RPWM2_ACK_BIT = BIT14, // Acknowledge + RPWM2_TOGGLE_BIT = BIT15, // Toggle bit +}; + +enum SDIO_CPWM2_BITS { + CPWM2_ACT_BIT = BIT0, // Active + CPWM2_DSTANDBY_BIT = BIT1, // Deep Standby + CPWM2_FBOOT_BIT = BIT2, // fast reboot + CPWM2_INIC_FW_RDY_BIT = BIT3, // is the iNIC FW(1) or Boot FW(0) + + CPWM2_TOGGLE_BIT = BIT15, // Toggle bit +}; + +#ifdef CONFIG_SDIO_DEVICE_VERIFY + +#define TX_BD_STRUCTURE_NUM 10 +#define RX_BD_STRUCTURE_NUM 10 +#define TX_BD_BUFFER_SIZE 0x1000//0x2000//0x800 +#define RX_BD_BUFFER_SIZE 0x400//0x800 + +#define SDIO_RAM_ADDR_BASE 0x20080000 +#define SDIO_BUFFER_HEAD(addr) SDIO_RAM_ADDR_BASE + addr +#define HAL_SDIO_BUFFER_READ8(addr) HAL_READ8(SDIO_RAM_ADDR_BASE, addr) +#define HAL_SDIO_BUFFER_READ32(addr) HAL_READ32(SDIO_RAM_ADDR_BASE, addr) +#define HAL_SDIO_BUFFER_WRITE32(addr, value) HAL_WRITE32(SDIO_RAM_ADDR_BASE, addr, value) + +//#define RX_BD_ADDR 0x8000 +//#define RX_BUFFER_ADDR 0x8050 + +typedef enum _SDIO_TEST_FUNC_ { + SDIO_TEST_INIT, // 0 + SDIO_TEST_INT_ON, // 1 + SDIO_TEST_INT_OFF, // 2 + SDIO_HCI_RX_REQ, // 3 + SDIO_RESET_TXFIFIO, // 4 + SDIO_CPU_RST_DMA, // 5 + SDIO_CPU_CLR_INT_REG, // 6 + SDIO_TIMER_TEST, // 7 + SDIO_TEST_DEBUG, // 8 + SDIO_TEST, // 9 + SDIO_HELP = 0xff +}SDIO_TEST_FUNC, *PSDIO_TEST_FUNC; + +typedef struct _SDIO_TEST_ADAPTER_ { + u32 TXWritePtr; + u32 TXReadPtr; + u16 RXWritePtr; + u16 RXReadPtr; + u16 IntMask; + u16 IntStatus; +} SDIO_TEST_ADAPTER, *PSDIO_TEST_ADAPTER; + + +VOID +MovePKTToRX( + IN u32 Source, IN u32 Destination, IN u32 PKTSize +); + +BOOL +PacketProcess( + IN SDIO_TEST_ADAPTER *pDevStatus +); + +VOID +SdioDeviceIrqHandleFunc( + IN VOID *DATA +); + +VOID +SdioDeviceTestApp( + IN u32 Data +); + +VOID +InitRXBD(VOID); + +VOID +InitTXFIFO(VOID); + +VOID +IrqRegister(VOID); + +#endif // end of "#ifdef CONFIG_SDIO_DEVICE_VERIFY" + +#endif /* #ifndef _RTL8195A_SDIO_H_ */ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_timer.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_timer.h index 42d5c62e0c..caf8223d11 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_timer.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_timer.h @@ -94,11 +94,6 @@ HalTimerReadCountRtl8195a_Patch( IN u32 TimerId ); -VOID -HalTimerSync( - IN u32 TimerId -); - VOID HalTimerIrqEnRtl8195a( IN u32 TimerId diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_uart.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_uart.h index 1da6d5eb0a..1ddbce84af 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_uart.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/fwlib/rtl8195a/rtl8195a_uart.h @@ -74,8 +74,10 @@ #define RUART_TRAN_HOLD_REG_OFF 0x24 //Transmitter Holding Register #define RUART_MISC_CTL_REG_OFF 0x28 -#define RUART_TXDMA_BURSTSIZE_MASK 0xF8 //7:3 -#define RUART_RXDMA_BURSTSIZE_MASK 0x1F00 //12:8 +#define RUART_TXDMA_EN_MASK 0x02 // [1] +#define RUART_RXDMA_EN_MASK 0x04 // [2] +#define RUART_TXDMA_BURSTSIZE_MASK 0xF8 // [7:3] +#define RUART_RXDMA_BURSTSIZE_MASK 0x1F00 // [12:8] #define RUART_DEBUG_REG_OFF 0x3C @@ -551,6 +553,26 @@ HalRuartExitCriticalRtl8195a( IN VOID *Data ); +VOID +HalRuartTxGdmaEnable8195a( + IN VOID *pHalRuartAdapter +); + +VOID +HalRuartTxGdmaDisable8195a( + IN VOID *pHalRuartAdapter +); + +VOID +HalRuartRxGdmaEnable8195a( + IN VOID *pHalRuartAdapter +); + +VOID +HalRuartRxGdmaDisable8195a( + IN VOID *pHalRuartAdapter +); + #if CONFIG_CHIP_E_CUT _LONG_CALL_ HAL_Status HalRuartResetTxFifoRtl8195a_V04( @@ -649,33 +671,10 @@ _LONG_CALL_ VOID HalRuartExitCriticalRtl8195a_V04( IN VOID *Data ); - #endif // #if CONFIG_CHIP_E_CUT #ifdef CONFIG_MBED_ENABLED // Interface to ROM functions -//extern __longcall void HalRuartAdapterLoadDefRtl8195a(UART_Handle *uart, uint8_t idx); -//extern __longcall void HalRuartDeInitRtl8195a(UART_Handle *uart); -//extern __longcall HAL_Status HalRuartDisableRtl8195a(UART_Handle *data); -//extern __longcall HAL_Status HalRuartEnableRtl8195a(UART_Handle *data); -//extern __longcall void HalRuartDmaInitRtl8195a(UART_Handle *data); -//extern __longcall void HalRuartTxGdmaLoadDefRtl8195a(UART_Handle *uart, RUART_DMA_Config *cfg); -//extern __longcall void HalRuartRxGdmaLoadDefRtl8195a(UART_Handle *uart, RUART_DMA_Config *cfg); -//extern __longcall HAL_Status HalRuartGetCRtl8195a(UART_Handle *uart, uint8_t *byte); -//extern __longcall HAL_Status HalRuartPutCRtl8195a(UART_Handle *uart, uint8_t byte); -//extern __longcall HAL_Status RuartLock(UART_Handle * uart); -//extern __longcall void RuartUnlock(UART_Handle * uart); -//extern __longcall void HalRuartSetIMRRtl8195a(UART_Handle *uart); -//extern __longcall uint8_t HalRuartGetIMRRtl8195a(UART_Handle *uart); -//extern __longcall uint32_t HalRuartSendRtl8195a(UART_Handle *, uint8_t *, uint32_t, uint32_t); -//extern __longcall HAL_Status HalRuartIntSendRtl8195a(UART_Handle *, uint8_t *, uint32_t); -//extern __longcall HAL_Status HalRuartIntRecvRtl8195a(UART_Handle *, uint8_t *, uint32_t); -//extern __longcall uint32_t HalRuartRecvRtl8195a(UART_Handle *, uint8_t *, uint32_t, uint32_t); -//extern __longcall void HalRuartRegIrqRtl8195a(UART_Handle *Data); -//extern __longcall void HalRuartIntEnableRtl8195a(UART_Handle *Data); -//extern __longcall void HalRuartIntDisableRtl8195a(UART_Handle *Data); -//extern __longcall uint32_t HalRuartGetDebugValueRtl8195a(HAL_RUART_ADAPTER *Data, uint32_t sel); -//extern __longcall void HalRuartRTSCtrlRtl8195a(UART_Handle *Data, bool val); extern __longcall HAL_Status RuartIsTimeout(uint32_t StartCount, uint32_t TimeoutCnt); #endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/driver/rtl_consol.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/driver/rtl_consol.c deleted file mode 100644 index ebeae470bd..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/driver/rtl_consol.c +++ /dev/null @@ -1,384 +0,0 @@ -/******************************************************************************* - *Copyright (c) 2013-2016 Realtek Semiconductor Corp, All Rights Reserved - * SPDX-License-Identifier: LicenseRef-PBL - * - * Licensed under the Permissive Binary License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at https://www.mbed.com/licenses/PBL-1.0 - * - * See the License for the specific language governing permissions and limitations under the License. - ******************************************************************************* - */ - -#include "rtl8195a.h" -//#include -#include "rtl_consol.h"//#include "osdep_service.h" -////#include "FreeRTOS.h" -////#include "task.h" -////#include "semphr.h" - -#include "tcm_heap.h" - -struct task_struct RtlConsolTaskRam_task; - -MON_RAM_BSS_SECTION - volatile UART_LOG_CTL UartLogCtl; -MON_RAM_BSS_SECTION - volatile UART_LOG_CTL *pUartLogCtl; -MON_RAM_BSS_SECTION - u8 *ArgvArray[MAX_ARGV]; -MON_RAM_BSS_SECTION - UART_LOG_BUF UartLogBuf; - - -#ifdef CONFIG_UART_LOG_HISTORY -MON_RAM_BSS_SECTION - u8 UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN]; -#endif - -_LONG_CALL_ -extern u8 -UartLogCmdChk( - IN u8 RevData, - IN UART_LOG_CTL *prvUartLogCtl, - IN u8 EchoFlag -); - -_LONG_CALL_ -extern VOID -ArrayInitialize( - IN u8 *pArrayToInit, - IN u8 ArrayLen, - IN u8 InitValue -); - -_LONG_CALL_ -extern VOID -UartLogHistoryCmd( - IN u8 RevData, - IN UART_LOG_CTL *prvUartLogCtl, - IN u8 EchoFlag -); - -_LONG_CALL_ -extern VOID -UartLogCmdExecute( - IN PUART_LOG_CTL pUartLogCtlExe -); - - - -//================================================= - - -/* Minimum and maximum values a `signed long int' can hold. - (Same as `int'). */ -#ifndef __LONG_MAX__ -#if defined (__alpha__) || (defined (__sparc__) && defined(__arch64__)) || defined (__sparcv9) || defined (__s390x__) -#define __LONG_MAX__ 9223372036854775807L -#else -#define __LONG_MAX__ 2147483647L -#endif /* __alpha__ || sparc64 */ -#endif -#undef LONG_MIN -#define LONG_MIN (-LONG_MAX-1) -#undef LONG_MAX -#define LONG_MAX __LONG_MAX__ - -/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */ -#undef ULONG_MAX -#define ULONG_MAX (LONG_MAX * 2UL + 1) - -#ifndef __LONG_LONG_MAX__ -#define __LONG_LONG_MAX__ 9223372036854775807LL -#endif - - -#if 0 -//====================================================== -//: UartLogIrqHandleRam -//: To deal with Uart-Log RX IRQ -//: VOID -//: VOID -//: NA -//====================================================== -//MON_RAM_TEXT_SECTION -VOID -UartLogIrqHandleRam -( - VOID * Data -) -{ - u8 UartReceiveData = 0; - //For Test - BOOL PullMode = _FALSE; - - u32 IrqEn = DiagGetIsrEnReg(); - - DiagSetIsrEnReg(0); - - UartReceiveData = DiagGetChar(PullMode); - if (UartReceiveData == 0) { - goto exit; - } - - //KB_ESC chk is for cmd history, it's a special case here. - if (UartReceiveData == KB_ASCII_ESC) { - //4 Esc detection is only valid in the first stage of boot sequence (few seconds) - if (pUartLogCtl->ExecuteEsc != _TRUE) - { - pUartLogCtl->ExecuteEsc = _TRUE; - (*pUartLogCtl).EscSTS = 0; - } - else - { - //4 the input commands are valid only when the task is ready to execute commands - if ((pUartLogCtl->BootRdy == 1) -#ifdef CONFIG_KERNEL - ||(pUartLogCtl->TaskRdy == 1) -#endif - ) - { - if ((*pUartLogCtl).EscSTS==0) - { - (*pUartLogCtl).EscSTS = 1; - } - } - else - { - (*pUartLogCtl).EscSTS = 0; - } - } - } - else if ((*pUartLogCtl).EscSTS==1){ - if (UartReceiveData != KB_ASCII_LBRKT){ - (*pUartLogCtl).EscSTS = 0; - } - else{ - (*pUartLogCtl).EscSTS = 2; - } - } - - else{ - if ((*pUartLogCtl).EscSTS==2){ - (*pUartLogCtl).EscSTS = 0; -#ifdef CONFIG_UART_LOG_HISTORY - if ((UartReceiveData=='A')|| UartReceiveData=='B'){ - UartLogHistoryCmd(UartReceiveData,(UART_LOG_CTL *)pUartLogCtl,1); - } -#endif - } - else{ - if (UartLogCmdChk(UartReceiveData,(UART_LOG_CTL *)pUartLogCtl,1)==2) - { - //4 check UartLog buffer to prevent from incorrect access - if (pUartLogCtl->pTmpLogBuf != NULL) - { - pUartLogCtl->ExecuteCmd = _TRUE; -#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED - if (pUartLogCtl->TaskRdy) - //RtlUpSemaFromISR((_Sema *)&pUartLogCtl->Sema); - rtw_up_sema_from_isr((_sema *)&pUartLogCtl->Sema); -#endif - } - else - { - ArrayInitialize((u8 *)pUartLogCtl->pTmpLogBuf->UARTLogBuf, UART_LOG_CMD_BUFLEN, '\0'); - } - } - } - } -exit: - DiagSetIsrEnReg(IrqEn); - -} - - - -//MON_RAM_TEXT_SECTION -VOID -RtlConsolInitRam( - IN u32 Boot, - IN u32 TBLSz, - IN VOID *pTBL -) -{ - UartLogBuf.BufCount = 0; - ArrayInitialize(&UartLogBuf.UARTLogBuf[0],UART_LOG_CMD_BUFLEN,'\0'); - pUartLogCtl = &UartLogCtl; - - pUartLogCtl->NewIdx = 0; - pUartLogCtl->SeeIdx = 0; - pUartLogCtl->RevdNo = 0; - pUartLogCtl->EscSTS = 0; - pUartLogCtl->BootRdy = 0; - pUartLogCtl->pTmpLogBuf = &UartLogBuf; -#ifdef CONFIG_UART_LOG_HISTORY - pUartLogCtl->CRSTS = 0; - pUartLogCtl->pHistoryBuf = &UartLogHistoryBuf[0]; -#endif - pUartLogCtl->pfINPUT = (VOID*)&DiagPrintf; - pUartLogCtl->pCmdTbl = (PCOMMAND_TABLE) pTBL; - pUartLogCtl->CmdTblSz = TBLSz; -#ifdef CONFIG_KERNEL - pUartLogCtl->TaskRdy = 0; -#endif - //executing boot sequence - if (Boot == ROM_STAGE) - { - pUartLogCtl->ExecuteCmd = _FALSE; - pUartLogCtl->ExecuteEsc = _FALSE; - } - else - { - pUartLogCtl->ExecuteCmd = _FALSE; - pUartLogCtl->ExecuteEsc= _TRUE;//don't check Esc anymore -#if defined(CONFIG_KERNEL) - /* Create a Semaphone */ - //RtlInitSema((_Sema*)&(pUartLogCtl->Sema), 0); - rtw_init_sema((_sema*)&(pUartLogCtl->Sema), 0); - pUartLogCtl->TaskRdy = 0; -#ifdef PLATFORM_FREERTOS -#define LOGUART_STACK_SIZE 128 //USE_MIN_STACK_SIZE modify from 512 to 128 -//if(rtw_create_task(&g_tcp_client_task, "tcp_client_handler", LOGUART_STACK_SIZE, TASK_PRORITY_MIDDLE, tcp_client_handler, 0) != _SUCCESS) -#if CONFIG_USE_TCM_HEAP - { - int ret = 0; - void *stack_addr = tcm_heap_malloc(LOGUART_STACK_SIZE*sizeof(int)); - //void *stack_addr = rtw_malloc(stack_size*sizeof(int)); - if(stack_addr == NULL){ - DiagPrintf("Out of TCM heap in \"LOGUART_TASK\" "); - } - ret = xTaskGenericCreate( - RtlConsolTaskRam, - (const char *)"LOGUART_TASK", - LOGUART_STACK_SIZE, - NULL, - tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET, - NULL, - stack_addr, - NULL); - if (pdTRUE != ret) - { - DiagPrintf("Create Log UART Task Err!!\n"); - } - } -#else - if (pdTRUE != xTaskCreate( RtlConsolTaskRam, (const signed char * const)"LOGUART_TASK", LOGUART_STACK_SIZE, NULL, tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET, NULL)) - { - DiagPrintf("Create Log UART Task Err!!\n"); - } -#endif - -#endif - -#endif - } - - CONSOLE_8195A(); -} - -extern u8** GetArgv(const u8 *string); -#if SUPPORT_LOG_SERVICE -extern char log_buf[LOG_SERVICE_BUFLEN]; -//extern osSemaphore(log_rx_interrupt_sema); -_sema log_rx_interrupt_sema; -#endif -//====================================================== -void console_cmd_exec(PUART_LOG_CTL pUartLogCtlExe) -{ - u8 CmdCnt = 0; - u8 argc = 0; - u8 **argv; - //u32 CmdNum; - PUART_LOG_BUF pUartLogBuf = pUartLogCtlExe->pTmpLogBuf; -#if SUPPORT_LOG_SERVICE - strncpy(log_buf, (const u8*)&(*pUartLogBuf).UARTLogBuf[0], LOG_SERVICE_BUFLEN-1); -#endif - argc = GetArgc((const u8*)&((*pUartLogBuf).UARTLogBuf[0])); - argv = GetArgv((const u8*)&((*pUartLogBuf).UARTLogBuf[0])); - - if(argc > 0){ -#if SUPPORT_LOG_SERVICE -// if(log_handler(argv[0]) == NULL) -// legency_interactive_handler(argc, argv); - //RtlUpSema((_Sema *)&log_rx_interrupt_sema); - rtw_up_sema((_sema *)&log_rx_interrupt_sema); -#endif - ArrayInitialize(argv[0], sizeof(argv[0]) ,0); - }else{ -#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1) - pmu_acquire_wakelock(BIT(PMU_LOGUART_DEVICE)); -#endif - CONSOLE_8195A(); // for null command - } - - (*pUartLogBuf).BufCount = 0; - ArrayInitialize(&(*pUartLogBuf).UARTLogBuf[0], UART_LOG_CMD_BUFLEN, '\0'); -} -//====================================================== -// overload original RtlConsolTaskRam -//MON_RAM_TEXT_SECTION -VOID -RtlConsolTaskRam( - VOID *Data -) -{ -#if SUPPORT_LOG_SERVICE - log_service_init(); -#endif - //4 Set this for UartLog check cmd history -#ifdef CONFIG_KERNEL - pUartLogCtl->TaskRdy = 1; -#endif -#ifndef CONFIG_KERNEL - pUartLogCtl->BootRdy = 1; -#endif - do{ -#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED - //RtlDownSema((_Sema *)&pUartLogCtl->Sema); - rtw_down_sema((_sema *)&pUartLogCtl->Sema); -#endif - if (pUartLogCtl->ExecuteCmd) { - // Add command handler here - console_cmd_exec((PUART_LOG_CTL)pUartLogCtl); - //UartLogCmdExecute((PUART_LOG_CTL)pUartLogCtl); - pUartLogCtl->ExecuteCmd = _FALSE; - } - }while(1); -} - -//====================================================== -extern void console_init_hs_uart(void); -void console_init(void) -{ - #if CONFIG_LOG_USE_HS_UART - sys_log_uart_off(); - console_init_hs_uart(); - #elif(CONFIG_LOG_USE_I2C) - sys_log_uart_off(); - // TODO: - #else - IRQ_HANDLE UartIrqHandle; - - //4 Register Log Uart Callback function - UartIrqHandle.Data = NULL;//(u32)&UartAdapter; - UartIrqHandle.IrqNum = UART_LOG_IRQ; - UartIrqHandle.IrqFun = (IRQ_FUN) UartLogIrqHandleRam; - UartIrqHandle.Priority = 6; - - - //4 Register Isr handle - InterruptUnRegister(&UartIrqHandle); - InterruptRegister(&UartIrqHandle); - #endif - -#if !TASK_SCHEDULER_DISABLED - RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL); -#else - RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL); -#endif -} - -#endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/driver/rtl_consol.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/driver/rtl_consol.h deleted file mode 100644 index 538d2c5460..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/driver/rtl_consol.h +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - *Copyright (c) 2013-2016 Realtek Semiconductor Corp, All Rights Reserved - * SPDX-License-Identifier: LicenseRef-PBL - * - * Licensed under the Permissive Binary License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at https://www.mbed.com/licenses/PBL-1.0 - * - * See the License for the specific language governing permissions and limitations under the License. - ******************************************************************************* - */ - -#ifndef _RTK_CONSOL_H_ -#define _RTK_CONSOL_H_ -/* - * Include user defined options first. Anything not defined in these files - * will be set to standard values. Override anything you dont like! - */ - #if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B) -#include "platform_opts.h" -#endif - -//#include "osdep_api.h" -#include "osdep_service.h" -#include "hal_diag.h" - -#define CONSOLE_PREFIX "#" - - -//Log UART -//UART_LOG_CMD_BUFLEN: only 126 bytes could be used for keeping input -// cmd, the last byte is for string end ('\0'). -#define UART_LOG_CMD_BUFLEN 127 -#define MAX_ARGV 10 - - - -typedef u32 (*ECHOFUNC)(IN u8*,...); //UART LOG echo-function type. - -typedef struct _UART_LOG_BUF_ { - u8 BufCount; //record the input cmd char number. - u8 UARTLogBuf[UART_LOG_CMD_BUFLEN]; //record the input command. -} UART_LOG_BUF, *PUART_LOG_BUF; - - - -typedef struct _UART_LOG_CTL_ { - u8 NewIdx; - u8 SeeIdx; - u8 RevdNo; - u8 EscSTS; - u8 ExecuteCmd; - u8 ExecuteEsc; - u8 BootRdy; - u8 Resvd; - PUART_LOG_BUF pTmpLogBuf; - VOID *pfINPUT; - PCOMMAND_TABLE pCmdTbl; - u32 CmdTblSz; -#ifdef CONFIG_UART_LOG_HISTORY - u32 CRSTS; -#endif -#ifdef CONFIG_UART_LOG_HISTORY - u8 (*pHistoryBuf)[UART_LOG_CMD_BUFLEN]; -#endif -#ifdef CONFIG_KERNEL - u32 TaskRdy; - //_Sema Sema; - _sema Sema; -#else - // Since ROM code will reference this typedef, so keep the typedef same size - u32 TaskRdy; - void *Sema; -#endif -} UART_LOG_CTL, *PUART_LOG_CTL; - - -#define KB_ASCII_NUL 0x00 -#define KB_ASCII_BS 0x08 -#define KB_ASCII_TAB 0x09 -#define KB_ASCII_LF 0x0A -#define KB_ASCII_CR 0x0D -#define KB_ASCII_ESC 0x1B -#define KB_ASCII_SP 0x20 -#define KB_ASCII_BS_7F 0x7F -#define KB_ASCII_LBRKT 0x5B //[ - -#define KB_SPACENO_TAB 1 - -#ifdef CONFIG_UART_LOG_HISTORY -#define UART_LOG_HISTORY_LEN 5 -#endif - -#ifdef CONFIG_DEBUG_LOG -#define _ConsolePrint DiagPrintf -#else -#define _ConsolePrint -#endif - -#ifndef CONSOLE_PREFIX -#define CONSOLE_PREFIX "" -#endif - -#define CONSOLE_8195A(...) do {\ - _ConsolePrint("\r"CONSOLE_PREFIX __VA_ARGS__);\ -}while(0) - - -_LONG_CALL_ VOID -RtlConsolInit( - IN u32 Boot, - IN u32 TBLSz, - IN VOID *pTBL -); - -#if defined(CONFIG_KERNEL) -_LONG_CALL_ VOID -RtlConsolTaskRam( - VOID *Data -); -#endif - -_LONG_CALL_ VOID -RtlConsolTaskRom( - VOID *Data -); - - -_LONG_CALL_ u32 -Strtoul( - IN const u8 *nptr, - IN u8 **endptr, - IN u32 base -); - -void console_init(void); - -#endif //_RTK_CONSOL_H_ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/os/cmsis_pmu_8195a.c b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/os/cmsis_pmu_8195a.c new file mode 100644 index 0000000000..f787ad8126 --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/os/cmsis_pmu_8195a.c @@ -0,0 +1,213 @@ +#if DEVICE_SLEEP + +//#include "FreeRTOS.h" +#include "cmsis_pmu_8195a.h" + +#include + +#include "platform_autoconf.h" +#include "platform_stdlib.h" +//#include "sys_api.h" + +#include "sleep_ex_api.h" + +#ifndef portNVIC_SYSTICK_CURRENT_VALUE_REG +#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) ) +#endif + +uint32_t missing_tick = 0; + +static uint32_t wakelock = 0; +//static uint32_t wakelock = DEFAULT_WAKELOCK; + +static uint32_t wakeup_event = DEFAULT_WAKEUP_EVENT; + +typedef struct { + uint32_t nDeviceId; + PSM_HOOK_FUN sleep_hook_fun; + void* sleep_param_ptr; + PSM_HOOK_FUN wakeup_hook_fun; + void* wakeup_param_ptr; +} PSM_DD_HOOK_INFO; + +#define MAX_PSM_DD_HOOK_INFO_SIZE 8 +uint32_t psm_dd_hook_info_size = 0; +PSM_DD_HOOK_INFO psm_dd_hook_infos[MAX_PSM_DD_HOOK_INFO_SIZE]; + +static uint8_t last_wakelock_state[32] = { + DEFAULT_WAKELOCK & 0x01, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; +static uint32_t last_acquire_wakelock_time[32] = {0}; +static uint32_t hold_wakelock_time[32] = {0}; +static uint32_t base_sys_time = 0; + +static uint32_t sys_sleep_time = 0; + +unsigned char reserve_pll = 0; +unsigned char generate_wakelock_stats = 0; + + +/* -------- FreeRTOS macro implementation -------- */ + +int cmsis_ready_to_sleep() { + return wakelock == 0; +} + +void pmu_acquire_wakelock(uint32_t lock_id) { + + wakelock |= BIT(lock_id); + + if (generate_wakelock_stats) { + uint32_t i; + + //uint32_t current_timestamp = osKernelSysTick(); + uint32_t current_timestamp = osKernelGetSysTimerCount(); + + for (i=0; i<32; i++) { + if ( (1< 0) { + sprintf(pcWriteBuffer, "%x\t\t%d\r\n", i, hold_wakelock_time[i]); + } + } + pcWriteBuffer += strlen( pcWriteBuffer ); + } + sprintf(pcWriteBuffer, "time passed: %d ms, system sleep %d ms\r\n", current_timestamp - base_sys_time, sys_sleep_time); + } +} + +void pmu_clean_wakelock_stat() { + uint32_t i; + + //base_sys_time = osKernelSysTick(); + base_sys_time = osKernelGetSysTimerCount(); + + for (i=0; i<32; i++) { + hold_wakelock_time[i] = 0; + if (last_wakelock_state[i] == 1) { + last_acquire_wakelock_time[i] = base_sys_time; + } + } + sys_sleep_time = 0; +} + +void pmu_add_wakeup_event(uint32_t event) { + wakeup_event |= event; +} + +void pmu_del_wakeup_event(uint32_t event) { + wakeup_event &= ~event; + // To fulfill tickless design, system timer is required to be wakeup event + wakeup_event |= SLEEP_WAKEUP_BY_STIMER; +} + +void pmu_register_sleep_callback(uint32_t nDeviceId, PSM_HOOK_FUN sleep_hook_fun, void* sleep_param_ptr, PSM_HOOK_FUN wakeup_hook_fun, void* wakeup_param_ptr) { + uint32_t i; + for (i=0; i 1) { + // if we have more than 2 items, just swap the last item into current slot + psm_dd_hook_infos[i].nDeviceId = psm_dd_hook_infos[psm_dd_hook_info_size-1].nDeviceId; + psm_dd_hook_infos[i].sleep_hook_fun = psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_hook_fun; + psm_dd_hook_infos[i].sleep_param_ptr = psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_param_ptr; + psm_dd_hook_infos[i].wakeup_hook_fun = psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_hook_fun; + psm_dd_hook_infos[i].wakeup_param_ptr = psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_param_ptr; + + // Then erase the last item + psm_dd_hook_infos[psm_dd_hook_info_size-1].nDeviceId = 0; + psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_hook_fun = NULL; + psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_param_ptr = NULL; + psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_hook_fun = NULL; + psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_param_ptr = NULL; + } else { + // we only have one item, just erase it + psm_dd_hook_infos[i].nDeviceId = 0; + psm_dd_hook_infos[i].sleep_hook_fun = NULL; + psm_dd_hook_infos[i].sleep_param_ptr = NULL; + psm_dd_hook_infos[i].wakeup_hook_fun = NULL; + psm_dd_hook_infos[i].wakeup_param_ptr = NULL; + } + psm_dd_hook_info_size--; + break; + } + } +} + +void pmu_set_pll_reserved(unsigned char reserve) { + reserve_pll = reserve; +} + +#endif diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/os/cmsis_pmu_8195a.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/os/cmsis_pmu_8195a.h new file mode 100644 index 0000000000..adff9cc8ea --- /dev/null +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/8195a/misc/os/cmsis_pmu_8195a.h @@ -0,0 +1,110 @@ +#ifndef __FREERTOS_PMU_H_ +#define __FREERTOS_PMU_H_ + +#if DEVICE_SLEEP +#include "sleep_ex_api.h" + +#ifndef BIT +#define BIT(n) (1<= 8000000) +#define _USED __attribute__((used)) +#else +#define _USED _Pragma("__root") +#endif + #elif defined(__CC_ARM) // defined in rtl8195a_compiler.h #define SECTION(_name) __attribute__ ((section(_name))) #define _LONG_CALL_ __attribute__ ((long_call)) #define ALIGNMTO(_bound) __attribute__ ((aligned (_bound))) - #define _LONG_CALL_ROM_ _LONG_CALL_ +#define _WEAK __attribute__ ((weak)) +#define _USED __attribute__((used)) #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #define SECTION(_name) __attribute__ ((__section__(_name))) @@ -222,6 +236,7 @@ typedef __kernel_ssize_t SSIZE_T; #define _LONG_CALL_ROM_ _LONG_CALL_ #endif #define _WEAK __attribute__ ((weak)) +#define _USED __attribute__((used)) #else #define SECTION(_name) __attribute__ ((__section__(_name))) @@ -239,6 +254,7 @@ typedef __kernel_ssize_t SSIZE_T; #define _LONG_CALL_ROM_ _LONG_CALL_ #endif #define _WEAK __attribute__ ((weak)) +#define _USED __attribute__((used)) #endif @@ -526,11 +542,9 @@ typedef unsigned char BOOLEAN,*PBOOLEAN; #define __restrict /* Ignore */ #endif -/* in rtl8195a_trap.h typedef struct _RAM_START_FUNCTION_ { VOID (*RamStartFun) (VOID); }RAM_START_FUNCTION, *PRAM_START_FUNCTION; -*/ typedef struct _RAM_FUNCTION_START_TABLE_ { VOID (*RamStartFun) (VOID); diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/bsp/section_config.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/bsp/section_config.h index d6f87264df..06031d9ca7 100644 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/bsp/section_config.h +++ b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/bsp/section_config.h @@ -1,21 +1,17 @@ -/******************************************************************************* - *Copyright (c) 2013-2016 Realtek Semiconductor Corp, All Rights Reserved - * SPDX-License-Identifier: LicenseRef-PBL - * - * Licensed under the Permissive Binary License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at https://www.mbed.com/licenses/PBL-1.0 - * - * See the License for the specific language governing permissions and limitations under the License. - ******************************************************************************* +/* + * Routines to access hardware + * + * Copyright (c) 2013 Realtek Semiconductor Corp. + * + * This module is a confidential and proprietary property of RealTek and + * possession or use of this module requires written permission of RealTek. */ #ifndef _SECTION_CONFIG_H_ #define _SECTION_CONFIG_H_ -#include "platform_autoconf.h" #include "basic_types.h" +#include "platform_autoconf.h" #define RAM_DEDECATED_VECTOR_TABLE_SECTION \ SECTION(".ram_dedecated_vector_table") @@ -131,16 +127,20 @@ #define E_CUT_ROM_DATA_SECTION \ SECTION(".cute.ram.data") -//#define FWUROM_DATA_SECTION SECTION(".fwurom.data") - -//#define FWUROM_RODATA_SECTION SECTION(".fwurom.rodata") - +/* +#define FWUROM_DATA_SECTION \ + SECTION(".fwurom.data") + +#define FWUROM_RODATA_SECTION \ + SECTION(".fwurom.rodata") +*/ + #define FWUROM_TEXT_SECTION \ SECTION(".fwurom.text") - + #define XMPORT_ROM_TEXT_SECTION \ SECTION(".xmportrom.text") - + #define XDMROM_TEXT_SECTION \ SECTION(".xmodemrom.text") @@ -149,7 +149,6 @@ #if defined (__CC_ARM) #define IMAGE1_VALID_PATTEN_SECTION \ SECTION(".image1.validate.rodata") __attribute__((used)) - #define IMAGE2_VALID_PATTEN_SECTION \ SECTION(".image2.validate.rodata") __attribute__((used)) #else @@ -230,7 +229,6 @@ #define SRAM_BF_DATA_SECTION \ SECTION(".bfsram.data") - #define START_RAM_FUN_SECTION \ SECTION(".start.ram.data") @@ -288,10 +286,10 @@ #if defined (__CC_ARM) #define IMAGE2_START_RAM_FUN_SECTION \ - SECTION(".image2.ram.data") __attribute__((used)) + SECTION(".image2.ram.data") __attribute__((used)) #else #define IMAGE2_START_RAM_FUN_SECTION \ - SECTION(".image2.ram.data") + SECTION(".image2.ram.data") #endif #define SDRAM_DATA_SECTION \ diff --git a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/rtl_std_lib/include/rtl_lib.h b/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/rtl_std_lib/include/rtl_lib.h deleted file mode 100644 index d936cf1355..0000000000 --- a/targets/TARGET_Realtek/TARGET_AMEBA/sdk/soc/realtek/common/rtl_std_lib/include/rtl_lib.h +++ /dev/null @@ -1,155 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2013-2016 Realtek Semiconductor Corp. - * - * 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 _RTL_LIB_H_ -#define _RTL_LIB_H_ - - -#include -#include - - -extern int __rtl_errno; - - -void init_rom_libgloss_ram_map(void); - - -// -// RTL library functions for Libc::stdio -// - -extern int rtl_printf(IN const char* fmt, ...); -extern int rtl_vprintf(const char *fmt, void *param); -extern int rtl_sprintf(char* str, const char* fmt, ...); -extern int rtl_snprintf(char* str, size_t size, const char* fmt, ...); -extern int rtl_vsnprintf(char *str, size_t size, const char *fmt, void *param); - -// -// RTL library functions for string -// - -extern void * rtl_memchr(const void * src_void , int c , size_t length); -extern int rtl_memcmp(const void * m1 , const void * m2 , size_t n); -extern void * rtl_memcpy(void * dst0 , const void * src0 , size_t len0); -extern void * rtl_memmove( void * dst_void , const void * src_void , size_t length); -extern void * rtl_memset(void * m , int c , size_t n); -extern char * rtl_strcat(char * s1 , const char * s2); -extern char * rtl_strchr(const char *s1 , int i); -extern int rtl_strcmp(const char *s1 , const char *s2); -extern char* rtl_strcpy(char *dst0 , const char *src0); -extern size_t rtl_strlen(const char *str); -extern char * rtl_strncat(char * s1 , const char * s2 , size_t n); -extern int rtl_strncmp(const char *s1 , const char *s2 , size_t n); -extern char * rtl_strncpy(char * dst0 , const char * src0 , size_t count); -extern char * rtl_strstr(const char *searchee , const char *lookfor); -extern char * rtl_strsep(char **source_ptr , const char *delim); -extern char * rtl_strtok(char * s , const char * delim); - -// -// RTL library functions for math -// - - -extern double rtl_fabs(double); -extern float rtl_fabsf(float a); -extern float rtl_cos_f32(float a); -extern float rtl_sin_f32(float a); - -extern float rtl_fadd(float a, float b); -extern float rtl_fsub(float a, float b); -extern float rtl_fmul(float a, float b); -extern float rtl_fdiv(float a, float b); - -extern int rtl_fcmplt(float a, float b); -extern int rtl_fcmpgt(float a, float b); - - - - - -// -// RTL eabi functions - -extern double rtl_ftod(float f); - -extern double rtl_ddiv(double a, double b); - - -// -// Macro Library Functions -// - -typedef union -{ - float value; - u32 word; -} ieee_float_shape_type; - -/* Get a 32 bit int from a float. */ - -#define GET_FLOAT_WORD(i,d) \ -do { \ - ieee_float_shape_type gf_u; \ - gf_u.value = (d); \ - (i) = gf_u.word; \ -} while (0) - -/* Set a float from a 32 bit int. */ - -#define SET_FLOAT_WORD(d,i) \ -do { \ - ieee_float_shape_type sf_u; \ - sf_u.word = (i); \ - (d) = sf_u.value; \ -} while (0) - -static inline -float rtl_nanf(void) -{ - float x; - - SET_FLOAT_WORD(x,0x7fc00000); - return x; -} - - -// -// Library Test functions -// - -extern int rtl_lib_test(IN u16 argc, IN u8 *argv[]); -extern int rtl_math_test(IN u16 argc, IN u8 *argv[]); -extern int rtl_string_test(IN u16 argc, IN u8 *argv[]); - - -// -// Macro functions -// - -#undef dbg_printf -#define dbg_printf(fmt, args...) \ - rtl_printf("%s():%d : " fmt "\n", __FUNCTION__, __LINE__, ##args); - - -#undef err_printf -#define err_printf(fmt, args...) \ - rtl_printf("%s():%d : " fmt "\n", __FUNCTION__, __LINE__, ##args); - - -#endif /* _RTL_LIB_H_ */ - diff --git a/targets/TARGET_Realtek/mbed_rtx.h b/targets/TARGET_Realtek/mbed_rtx.h index 934726af56..96a8bc0756 100644 --- a/targets/TARGET_Realtek/mbed_rtx.h +++ b/targets/TARGET_Realtek/mbed_rtx.h @@ -41,4 +41,4 @@ #endif #endif -#endif \ No newline at end of file +#endif diff --git a/tools/bootloaders/REALTEK_RTL8195AM/LICENSE b/tools/bootloaders/REALTEK_RTL8195AM/LICENSE new file mode 100644 index 0000000000..591ac29615 --- /dev/null +++ b/tools/bootloaders/REALTEK_RTL8195AM/LICENSE @@ -0,0 +1,49 @@ +Permissive Binary License + +Version 1.0, September 2015 + +Redistribution. Redistribution and use in binary form, without +modification, are permitted provided that the following conditions are +met: + +1) Redistributions must reproduce the above copyright notice and the + following disclaimer in the documentation and/or other materials + provided with the distribution. + +2) Unless to the extent explicitly permitted by law, no reverse + engineering, decompilation, or disassembly of this software is + permitted. + +3) Redistribution as part of a software development kit must include the + accompanying file named "DEPENDENCIES" and any dependencies listed in + that file. + +4) Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +Limited patent license. The copyright holders (and contributors) grant a +worldwide, non-exclusive, no-charge, royalty-free patent license to +make, have made, use, offer to sell, sell, import, and otherwise +transfer this software, where such license applies only to those patent +claims licensable by the copyright holders (and contributors) that are +necessarily infringed by this software. This patent license shall not +apply to any combinations that include this software. No hardware is +licensed hereunder. + +If you institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the software +itself infringes your patent(s), then your rights granted under this +license shall terminate as of the date such litigation is filed. + +DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS." 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 THE COPYRIGHT +HOLDERS OR 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. \ No newline at end of file diff --git a/tools/bootloaders/REALTEK_RTL8195AM/ram_1.bin b/tools/bootloaders/REALTEK_RTL8195AM/ram_1.bin index 5179455fb5..3a229b4341 100644 Binary files a/tools/bootloaders/REALTEK_RTL8195AM/ram_1.bin and b/tools/bootloaders/REALTEK_RTL8195AM/ram_1.bin differ