Updated SDK from version 1.00.08 to 1.00.10
This commit is contained in:
parent
02034ea702
commit
64025046e7
1
.gitignore
vendored
1
.gitignore
vendored
@ -89,3 +89,4 @@ dkms.conf
|
|||||||
#Exceptions
|
#Exceptions
|
||||||
bin/w800
|
bin/w800
|
||||||
!bin/build/w800/lib/
|
!bin/build/w800/lib/
|
||||||
|
!lib/w800/
|
||||||
|
|||||||
14
demo/Makefile
Normal file
14
demo/Makefile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
TOP_DIR = ..
|
||||||
|
sinclude $(TOP_DIR)/tools/w800/conf.mk
|
||||||
|
|
||||||
|
ifndef PDIR
|
||||||
|
GEN_LIBS = libdemo$(LIB_EXT)
|
||||||
|
COMPONENTS_libdemo = console/libconsole$(LIB_EXT)
|
||||||
|
endif
|
||||||
|
|
||||||
|
#DEFINES +=
|
||||||
|
|
||||||
|
sinclude $(TOP_DIR)/tools/w800/rules.mk
|
||||||
|
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||||
|
PDIR := ../$(PDIR)
|
||||||
|
sinclude $(PDIR)Makefile
|
||||||
@ -1,13 +1,15 @@
|
|||||||
TOP_DIR = ../../../../../..
|
TOP_DIR = ../..
|
||||||
sinclude $(TOP_DIR)/tools/w800/conf.mk
|
sinclude $(TOP_DIR)/tools/w800/conf.mk
|
||||||
|
|
||||||
ifndef PDIR
|
ifndef PDIR
|
||||||
GEN_LIBS = libpolarssl$(LIB_EXT)
|
GEN_LIBS = libconsole$(LIB_EXT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#DEFINES +=
|
#DEFINES +=
|
||||||
|
|
||||||
sinclude $(TOP_DIR)/tools/w800/rules.mk
|
sinclude $(TOP_DIR)/tools/w800/rules.mk
|
||||||
|
|
||||||
|
INCLUDES := $(INCLUDES) -I $(PDIR)include
|
||||||
|
|
||||||
PDIR := ../$(PDIR)
|
PDIR := ../$(PDIR)
|
||||||
sinclude $(PDIR)Makefile
|
sinclude $(PDIR)Makefile
|
||||||
437
demo/console/wm_demo_console.h
Normal file
437
demo/console/wm_demo_console.h
Normal file
@ -0,0 +1,437 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_demo_cmd.h
|
||||||
|
*
|
||||||
|
* Description: demo command header
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*****************************************************************************/
|
||||||
|
#ifndef __WM_DEMO_CMD_H__
|
||||||
|
#define __WM_DEMO_CMD_H__
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_watchdog.h"
|
||||||
|
#include "wm_config.h"
|
||||||
|
#include "wm_ram_config.h"
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
EXTERN FUNC
|
||||||
|
*****************************************************************/
|
||||||
|
extern int demo_connect_net(void *, ...);
|
||||||
|
extern int demo_connect_net_with_specific_info(void *, ...);
|
||||||
|
extern int demo_socket_client(void *, ...);
|
||||||
|
extern int demo_socket_server(void *, ...);
|
||||||
|
extern int demo_oneshot(void *, ...);
|
||||||
|
extern int demo_socket_config(void *, ...);
|
||||||
|
extern int demo_webserver_config(void *, ...);
|
||||||
|
extern int demo_create_softap(void *, ...);
|
||||||
|
extern int uart_demo(void *, ...);
|
||||||
|
extern int ntp_demo(void *, ...);
|
||||||
|
extern int ntp_set_server_demo(void *, ...);
|
||||||
|
extern int ntp_query_cfg(void *, ...);
|
||||||
|
extern int flash_demo(void *, ...);
|
||||||
|
extern int Socket_Client_Demo(void *, ...);
|
||||||
|
extern int sck_c_send_data_demo(void *, ...);
|
||||||
|
extern int socket_server_demo(void *, ...);
|
||||||
|
extern int sck_s_send_data_demo(void *, ...);
|
||||||
|
extern int socket_udp_demo(void *, ...);
|
||||||
|
extern int udp_send_data_demo(void *, ...);
|
||||||
|
|
||||||
|
extern int apsta_demo(void *, ...);
|
||||||
|
extern int apsta_socket_demo(void *, ...);
|
||||||
|
extern int gpio_demo(void *, ...);
|
||||||
|
extern int gpio_isr_test(void *, ...);
|
||||||
|
extern int pwm_demo(void *, ...);
|
||||||
|
extern int crypt_hard_demo(void *, ...);
|
||||||
|
extern int wm_7816_demo(void *, ...);
|
||||||
|
extern int rsa_demo(void *, ...);
|
||||||
|
extern int slave_spi_demo(void *, ...);
|
||||||
|
//extern int master_spi_demo(void *, ...);
|
||||||
|
extern int master_spi_recv_data(void *, ...);
|
||||||
|
extern int master_spi_send_data(void *, ...);
|
||||||
|
extern int pmu_timer0_demo(void *, ...);
|
||||||
|
extern int pmu_timer1_demo(void *, ...);
|
||||||
|
extern int rtc_demo(void *, ...);
|
||||||
|
extern int timer_demo(void *, ...);
|
||||||
|
extern int http_fwup_demo(void *, ...);
|
||||||
|
extern int http_get_demo(void *, ...);
|
||||||
|
extern int http_post_demo(void *, ...);
|
||||||
|
extern int http_put_demo(void *, ...);
|
||||||
|
extern int socket_server_demo(void *, ...);
|
||||||
|
extern int sck_s_send_data_demo(void *, ...);
|
||||||
|
extern int CreateMCastDemoTask(void *, ...);
|
||||||
|
extern int adc_input_voltage_demo(void *, ...);
|
||||||
|
extern int adc_chip_temperature_demo(void*,...);
|
||||||
|
extern int adc_power_voltage_demo(void *, ...);
|
||||||
|
extern int adc_input_voltage_cal_demo(void *, ...);
|
||||||
|
extern int adc_input_voltage_multipoint_cal_demo(void *, ...);
|
||||||
|
extern int sd_card_test(void *, ...);
|
||||||
|
|
||||||
|
extern int demo_wps_pbc(void *, ...);
|
||||||
|
extern int demo_wps_pin(void *, ...);
|
||||||
|
extern int demo_wps_get_pin(void *, ...);
|
||||||
|
|
||||||
|
|
||||||
|
extern int demo_iperf_auto_test(void *, ...);
|
||||||
|
extern int CreateSSLServerDemoTask(void *, ...);
|
||||||
|
extern int lwsDemoTest(void *, ...);
|
||||||
|
extern int tls_i2s_io_init(void *, ...);
|
||||||
|
extern int tls_i2s_demo(void *, ...);
|
||||||
|
extern int i2c_demo(void *, ...);
|
||||||
|
extern int scan_demo(void *, ...);
|
||||||
|
extern int scan_format2_demo(void *, ...);
|
||||||
|
extern int scan_specified_demo(void *, ...);
|
||||||
|
extern int https_demo(void *, ...);
|
||||||
|
extern int mqtt_demo(void *, ...);
|
||||||
|
extern int fatfs_test(void *, ...);
|
||||||
|
extern int mbedtls_demo(void *, ...);
|
||||||
|
|
||||||
|
extern int dsp_demo(void *,...);
|
||||||
|
|
||||||
|
#if (TLS_CONFIG_BLE == CFG_ON)
|
||||||
|
extern int demo_ble_config(void *, ...); /*wifi connection by ble configuration*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_BT
|
||||||
|
extern int demo_bt_enable(void *, ...);
|
||||||
|
extern int demo_bt_destroy(void *, ...);
|
||||||
|
#if (TLS_CONFIG_BLE == CFG_ON)
|
||||||
|
extern int demo_ble_server_on(void *, ...);
|
||||||
|
extern int demo_ble_server_off(void *, ...);
|
||||||
|
extern int demo_ble_client_on(void *, ...);
|
||||||
|
extern int demo_ble_client_off(void *, ...);
|
||||||
|
|
||||||
|
extern int demo_ble_scan(void *,...);
|
||||||
|
extern int demo_ble_adv(void *,...);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (TLS_CONFIG_BR_EDR== CFG_ON)
|
||||||
|
extern int demo_bt_app_on(void *, ...);
|
||||||
|
extern int demo_bt_app_off(void *, ...);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_TOUCHSENSOR
|
||||||
|
extern int demo_touchsensor(void *, ...);
|
||||||
|
#endif
|
||||||
|
#if DEMO_LCD
|
||||||
|
extern void lcd_test(void);
|
||||||
|
#endif
|
||||||
|
extern int avoid_copy_entry(void *, ...);
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
LOCAL FUNC
|
||||||
|
*****************************************************************/
|
||||||
|
static void demo_console_show_info(char *buf);
|
||||||
|
static int demo_console_show_help(void *p, ...);
|
||||||
|
static int demo_sys_reset(void *p, ...);
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
LOCAL TYPE
|
||||||
|
*****************************************************************/
|
||||||
|
typedef struct demo_console_st
|
||||||
|
{
|
||||||
|
int rx_data_len;
|
||||||
|
u8 *rx_buf; /*uart rx*/
|
||||||
|
u16 rptr;
|
||||||
|
u8 MsgNum;
|
||||||
|
} Demo_Console;
|
||||||
|
|
||||||
|
struct demo_console_info_t
|
||||||
|
{
|
||||||
|
char *cmd;
|
||||||
|
int (*callfn)(void *, ...);
|
||||||
|
short type;/* perbit: 0-string, 1-number */
|
||||||
|
short param_cnt;
|
||||||
|
char *info;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DEMO_CONSOLE_CMD 1 //被解析成cmd
|
||||||
|
#define DEMO_CONSOLE_SHORT_CMD 2 //CMD的一部分,没有解析完
|
||||||
|
#define DEMO_CONSOLE_WRONG_CMD 3
|
||||||
|
|
||||||
|
#define DEMO_BUF_SIZE TLS_UART_RX_BUF_SIZE
|
||||||
|
|
||||||
|
const char HTTP_POST[] = "t-httppost";
|
||||||
|
const char HTTP_PUT[] = "t-httpput";
|
||||||
|
|
||||||
|
|
||||||
|
struct demo_console_info_t console_tbl[] =
|
||||||
|
{
|
||||||
|
//To Do When Add New Demo
|
||||||
|
#if DEMO_CONNECT_NET
|
||||||
|
{"t-connect", demo_connect_net, 0, 2, "Test connecting ap;t-connect(\"ssid\",\"pwd\"); For open ap, pwd should be empty"},
|
||||||
|
{"t-connect_ss", demo_connect_net_with_specific_info, 0x1C, 5, "Test connecting ap;t-connect_ss(\"ssid\",\"pwd\",timeout,pci_en,scan_mode); For open ap, pwd should be empty"},
|
||||||
|
{"t-oneshot", demo_oneshot, 0, 0, "Test Oneshot configuration"},
|
||||||
|
// {"t-socketcfg", demo_socket_config, 0, 0, "Test socket configuration"},
|
||||||
|
{"t-webcfg", demo_webserver_config, 0, 0, "Test web server configuration"},
|
||||||
|
#if (TLS_CONFIG_BLE == CFG_ON)
|
||||||
|
{"t-blecfg", demo_ble_config, 0, 0, "Test ble mode configuration"},
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_APSTA
|
||||||
|
{"t-apsta", apsta_demo, 0x0, 4, "Test connecting with AP by apsta mode;"},
|
||||||
|
{"t-asskt", apsta_socket_demo, 0x0, 0, "Test socket communication in apsta mode;"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_SOFT_AP
|
||||||
|
{"t-softap", demo_create_softap, 0x1C, 5, "Test softap create & station join monitor;"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_WPS
|
||||||
|
{"t-wps-get-pin", demo_wps_get_pin, 0x0, 0, "Test WPS get pin"},
|
||||||
|
{"t-wps-start-pin", demo_wps_pin, 0x0, 0, "Test WPS start pin"},
|
||||||
|
{"t-wps-start-pbc", demo_wps_pbc, 0x0, 0, "Test WPS start pbc"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_SCAN
|
||||||
|
{"t-scan", scan_demo, 0x0, 0, "Test wifi scan"},
|
||||||
|
{"t-scanf2", scan_format2_demo, 0x0, 0, "Test wifi scan format2"},
|
||||||
|
{"t-ss", scan_specified_demo, 0x3c, 6, "Test specified scan t-ss(\"ssid\",\"mac\",chan,scan_type,min_interval,max_interval)"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
#if DEMO_UARTx
|
||||||
|
{"t-uart", uart_demo, 0x7, 3, "Test uart tx/rx; For example t-uart=(9600,0,0),baudrate 9600 ,parity none and 1 stop bit"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_GPIO
|
||||||
|
{"t-gpioirq", gpio_isr_test, 0x0, 0, "Test gpio interrupt services"},
|
||||||
|
{"t-gpio", gpio_demo, 0x0, 0, "Test gpio read and write"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_FLASH
|
||||||
|
{"t-flash", flash_demo, 0x0, 0, "Test Read/Write Flash "},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_ENCRYPT
|
||||||
|
{"t-crypt", crypt_hard_demo, 0x0, 0, "Test Encryption/Decryption API"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_RSA
|
||||||
|
{"t-rsa", rsa_demo, 0x0, 0, "Test RSA Encryption/Decryption API"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_RTC
|
||||||
|
{"t-rtc", rtc_demo, 0x0, 0, "Test rtc"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_TIMER
|
||||||
|
{"t-timer", timer_demo, 0x0, 0, "Test timer"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_PWM
|
||||||
|
{"t-pwm", pwm_demo, 0x1F, 5, "Test PWM output, for example t-pwm=(0,20,99,1,0) to test ALLSYC mode."},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_PMU
|
||||||
|
{"t-pmuT0", pmu_timer0_demo, 0x1, 1, "Test power management unit with timer0"},
|
||||||
|
{"t-pmuT1", pmu_timer1_demo, 0x1, 1, "Test power management unit with timer1"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_I2C
|
||||||
|
{"t-i2c", i2c_demo, 0x1, 1, "Test I2C module, for example t-i2c to W&R AT24CXX."},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_I2S
|
||||||
|
{"t-i2sioinit", tls_i2s_io_init, 0, 0, "Initialize I2S IO."},
|
||||||
|
{"t-i2s", tls_i2s_demo, 0x3F, 6, "Test I2S module, for example t-i2s=(0,1,44100,16,0,0) to send data."},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_MASTER_SPI
|
||||||
|
{"t-mspi-s", master_spi_send_data, 0x3, 2, "Test SPI Master sending data(Note: need another module acts as a client device)"},
|
||||||
|
{"t-mspi-r", master_spi_recv_data, 0x3, 2, "Test SPI Master receiving data(Note: need another module acts as a client device)"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_SLAVE_SPI
|
||||||
|
{"t-sspi", slave_spi_demo, 0x1, 1, "Test slave HSPI,t-sspi=(0),(Note: need another module support as a master device)"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_SDIO_HOST
|
||||||
|
{"t-sdh", sd_card_test, 0x0, 0, "Test sdio host write & read sd card"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_ADC
|
||||||
|
{"t-adctemp", adc_chip_temperature_demo, 0x0, 0, "(ADC)Test chip temperature"},
|
||||||
|
{"t-adcvolt", adc_input_voltage_demo, 0x1, 1, "(ADC)Test input voltage,0-PA1(chan0), 1-PA4(chan1),8-different"},
|
||||||
|
{"t-adcpower", adc_power_voltage_demo, 0x0, 0, "(ADC)Sample power supply voltage"},
|
||||||
|
{"t-adccal", adc_input_voltage_cal_demo, 0x3, 2, "(ADC)Calibrate input voltage"},
|
||||||
|
{"t-adccalmp", adc_input_voltage_multipoint_cal_demo, 0x1F, 5, "(ADC) mulitpoint Calibrate t-adccalmp(chanbitmap,chan1ref,chan2ref,chan3ref,chan4ref),unit:mV"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_7816
|
||||||
|
{"t-7816", wm_7816_demo, 0x0, 0, "Test 7816 tx/rx function"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
#if DEMO_STD_SOCKET_CLIENT
|
||||||
|
{"t-sockc", Socket_Client_Demo, 0x1, 2, "Test data stream as [STANDARD SOCKET] CLIENT(working after connecting with AP successfully)"},
|
||||||
|
{"t-skcsnd", sck_c_send_data_demo, 0x3, 2, "Test socket client send data, len:send len, uart_trans: is or not use uart retransmission"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_STD_SOCKET_SERVER
|
||||||
|
{"t-socks", socket_server_demo, 0x1, 1, "Test data stream as [STANDARD SOCKET] SERVER(working after connecting with AP successfully)"},
|
||||||
|
{"t-skssnd", sck_s_send_data_demo, 0x7, 3, "Test socket server send data skt_no:socket num, len:send len, uart_trans: is or not use uart retransmission"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_SOCKET_CLIENT_SERVER
|
||||||
|
{"t-client", demo_socket_client,0x4,4,"Test socket client; t-client(\"ssid\",\"pwd\",port,\"ip\")"},
|
||||||
|
{"t-server", demo_socket_server,0x4,3,"Test socket server; t-server(\"ssid\",\"pwd\",port,)"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_UDP
|
||||||
|
{"t-udp", socket_udp_demo, 0x3, 3, "Test data stream as UDP(working after connecting with AP successfully)"},
|
||||||
|
{"t-sndudp", udp_send_data_demo, 0x1, 1, "Test udp send data"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_UDP_MULTI_CAST
|
||||||
|
{"t-mcast", CreateMCastDemoTask, 0x0, 1, "Test Multicast data stream"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_NTP
|
||||||
|
{"t-ntp", ntp_demo, 0x0, 0, "Test NTP"},
|
||||||
|
{"t-setntps", ntp_set_server_demo, 0x0, 3, "Set NTP server ip;For example:t-setntps(\"cn.ntp.org.cn\", \"ntp.sjtu.edu.cn\", \"192.168.1.101\"),max server num is 3"},
|
||||||
|
{"t-queryntps", ntp_query_cfg, 0x0, 0, "Query the NTP server domain"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_HTTP
|
||||||
|
{"t-httpfwup", http_fwup_demo, 0x0, 1, "Test firmware update via HTTP, like this t-httpfwup=(http://192.168.1.100:8080/WM_W600_SEC.img)"},
|
||||||
|
{"t-httpget", http_get_demo, 0x0, 1, "Test HTTP get method, like this t-httpget"},
|
||||||
|
{(char *)HTTP_POST, http_post_demo, 0x0, 1, "Test HTTP post method, like this t-httppost=(user=winnermicro)"},
|
||||||
|
{(char *)HTTP_PUT, http_put_demo, 0x0, 1, "Test HTTP put method, like this t-httpput=(user=winnermicro)"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_SSL_SERVER
|
||||||
|
{"t-ssl-server", CreateSSLServerDemoTask, 0x0, 1, "Test ssl server,remember to turn on TLS_CONFIG_SERVER_SIDE_SSL"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_WEBSOCKETS
|
||||||
|
{"t-websockets", lwsDemoTest, 0x0, 0, "websockets demo test"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_HTTPS
|
||||||
|
{"t-https", https_demo, 0x0, 0, "Test https request"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_MBEDTLS
|
||||||
|
{"t-mbedtls", mbedtls_demo, 0x0, 0, "Test mbedtls ssl"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_MQTT
|
||||||
|
{"t-mqtt", mqtt_demo, 0x1, 1, "Test mqtt: 0-TCP; 1-TLS; 2-WS; 3-WSS"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_FATFS
|
||||||
|
{"t-fatfs", fatfs_test, 0x0, 0, "Test fatfs on sd card"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_IPERF_AUTO_TEST
|
||||||
|
{"t-iperf", demo_iperf_auto_test, 0x7E, 7, "Iperf auto test"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_DSP
|
||||||
|
{"t-dsp", dsp_demo, 0x1, 1, "DSP demo:0-fir,1-matrix,2-rfft,3-sin,4-variance"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_BT
|
||||||
|
{"t-bt-on", demo_bt_enable, 0x0, 0, "Test enable bt system"},
|
||||||
|
{"t-bt-off", demo_bt_destroy, 0x0, 0, "Test destroy bt system"},
|
||||||
|
#if (TLS_CONFIG_BLE == CFG_ON)
|
||||||
|
{"t-ble-server-on", demo_ble_server_on, 0x0, 0, "Test enable ble server"},
|
||||||
|
{"t-ble-server-off", demo_ble_server_off, 0x0, 0, "Test disable ble server"},
|
||||||
|
{"t-ble-client-on", demo_ble_client_on, 0x0, 0, "Test enable ble client"},
|
||||||
|
{"t-ble-client-off", demo_ble_client_off, 0x0, 0, "Test disable ble client"},
|
||||||
|
{"t-ble-adv", demo_ble_adv, 0x01, 1, "Test start connectable/unconnectable/stop ble advertisement,eg: t-ble-adv=(1/2/0)"},
|
||||||
|
{"t-ble-scan",demo_ble_scan, 0x01, 1, "Test start/stop ble scan,eg: t-ble-scan=(1/0)"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (TLS_CONFIG_BR_EDR == CFG_ON)
|
||||||
|
{"t-bt-demo-on", demo_bt_app_on, 0x0, 0, "Test enable bt app on"},
|
||||||
|
{"t-bt-demo-off", demo_bt_app_off, 0x0, 0, "Test disable bt app off"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_TOUCHSENSOR
|
||||||
|
{"t-touch", demo_touchsensor, 0x1, 1, "Test Touch sensor function,0:all, 1:touch sensor 1... 15:touch sensor 15"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_LCD
|
||||||
|
{"t-lcd", (void *)lcd_test, 0, 0, "Test LCD output, eg: t-lcd"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEMO_AVOID_COPY
|
||||||
|
{"t-avoidcopy", avoid_copy_entry, 0x0, 0, "Test Avoid Copy function"},
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//控制台上显示的最后一个命令,如果要让命令显示在控制台上,需要放在该行的上面
|
||||||
|
{"demohelp", demo_console_show_help, 0, 0, "Display Help information"},
|
||||||
|
//下面的命令用于内部测试,不显示在控制台上
|
||||||
|
{"reset", demo_sys_reset, 0, 0, "Reset System"},
|
||||||
|
//最后一个命令,检索命令时判断结束标识
|
||||||
|
{"lastcmd", NULL, 0, 0, "Table Terminal Flag; MUST BE THE LAST ONE"}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void demo_console_show_info(char *buf)
|
||||||
|
{
|
||||||
|
char *p = NULL;
|
||||||
|
char *p1 = NULL;
|
||||||
|
|
||||||
|
p = buf;
|
||||||
|
p1 = strchr(p, '\n');
|
||||||
|
if(NULL == p1)
|
||||||
|
{
|
||||||
|
printf("%s\n", p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(p1 != NULL)
|
||||||
|
{
|
||||||
|
*p1 = '\0';
|
||||||
|
printf("%s\n", p);
|
||||||
|
printf("%-30s", " ");
|
||||||
|
p = p1 + 1;
|
||||||
|
p1 = strchr(p, '\n');
|
||||||
|
}
|
||||||
|
printf("%s\n", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int demo_console_show_help(void *p, ...)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf("\n%-10s", "Sequence");
|
||||||
|
printf("%-20s", "Command");
|
||||||
|
printf("%s", "Description");
|
||||||
|
printf("\n------------------------------------------------------------------------------------\n");
|
||||||
|
for(i = 0; ; i ++)
|
||||||
|
{
|
||||||
|
printf("%-10d", i + 1);
|
||||||
|
printf("%-20s", console_tbl[i].cmd);
|
||||||
|
//printf("%s\n",console_tbl[i].info);
|
||||||
|
demo_console_show_info(console_tbl[i].info);
|
||||||
|
if(0 == strcmp(console_tbl[i].cmd, "demohelp"))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("------------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_sys_reset(void *p, ...)
|
||||||
|
{
|
||||||
|
tls_sys_set_reboot_reason(REBOOT_REASON_ACTIVE);
|
||||||
|
tls_sys_reset();
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*__WM_DEMO_CMD_H__*/
|
||||||
|
|
||||||
486
demo/console/wm_demo_console_task.c
Normal file
486
demo/console/wm_demo_console_task.c
Normal file
@ -0,0 +1,486 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_demo_console_task.c
|
||||||
|
*
|
||||||
|
* Description: demo console task
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_CONSOLE
|
||||||
|
#include "wm_demo_console.h"
|
||||||
|
|
||||||
|
#define DEMO_TASK_SIZE 2048
|
||||||
|
static tls_os_queue_t *demo_q = NULL;
|
||||||
|
static OS_STK DemoTaskStk[DEMO_TASK_SIZE];
|
||||||
|
static Demo_Console gstConsole;
|
||||||
|
#define DEMO_CONSOLE_BUF_SIZE 512
|
||||||
|
|
||||||
|
extern int strtodec(int *dec, char *str);
|
||||||
|
|
||||||
|
|
||||||
|
void demo_console_malloc(void)
|
||||||
|
{
|
||||||
|
gstConsole.rx_buf = tls_mem_alloc(DEMO_CONSOLE_BUF_SIZE + 1);
|
||||||
|
if(NULL == gstConsole.rx_buf)
|
||||||
|
{
|
||||||
|
printf("\nmalloc rx fail\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memset(gstConsole.rx_buf, 0, DEMO_CONSOLE_BUF_SIZE + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
s16 demo_console_rx(u16 len, void* user_data)
|
||||||
|
{
|
||||||
|
gstConsole.rx_data_len += len;
|
||||||
|
|
||||||
|
if (gstConsole.MsgNum < 3)
|
||||||
|
{
|
||||||
|
gstConsole.MsgNum ++;
|
||||||
|
tls_os_queue_send(demo_q, (void *)1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *demo_cmd_get_first_comma(char *buf, int len)
|
||||||
|
{
|
||||||
|
char prec = '\0', curc;
|
||||||
|
int n = 0;
|
||||||
|
if(len <= 0)
|
||||||
|
return NULL;
|
||||||
|
if(*buf == '"')
|
||||||
|
{
|
||||||
|
for(n = 1; n < len; n++)
|
||||||
|
{
|
||||||
|
curc = *(buf + n);
|
||||||
|
if(curc == ',' && prec == '"')
|
||||||
|
{
|
||||||
|
if(n < 3 || *(buf + n - 2) != '\\')
|
||||||
|
{
|
||||||
|
return buf + n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prec = curc;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return strchr(buf, ',');
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_cmd_param(void *param, int type)
|
||||||
|
{
|
||||||
|
if (type == 0)
|
||||||
|
{
|
||||||
|
return (int)((char *)param);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return *(int *)param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_cmd_quotation_filter(u8 **keyInfo, u8 *inbuf)
|
||||||
|
{
|
||||||
|
u8 len = strlen((char *)inbuf);
|
||||||
|
int i;
|
||||||
|
if (*inbuf == '"')
|
||||||
|
{
|
||||||
|
/* argument such as "xxxx" */
|
||||||
|
inbuf++; /* skip 1st <"> */
|
||||||
|
len -= 1;
|
||||||
|
*keyInfo = inbuf;
|
||||||
|
if((*(inbuf + len - 1) == '"') && (*(inbuf + len) == '\0'))
|
||||||
|
{
|
||||||
|
*(inbuf + len - 1) = '\0';
|
||||||
|
len -= 1;
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if(inbuf[i] == '\\')
|
||||||
|
{
|
||||||
|
len -= 1;
|
||||||
|
memcpy(inbuf + i, inbuf + i + 1, len - i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inbuf[len] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*keyInfo = inbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int demo_call_fn(int (*fn)(), int *param, int count)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if(NULL == fn || NULL == param)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(count)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
ret = (int)fn();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ret = (int)fn(param[0]);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ret = (int)fn(param[0], param[1]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2]);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3]);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3], param[4]);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3], param[4], param[5]);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3], param[4], param[5], param[6]);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7]);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7], param[8]);
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
ret = (int)fn(param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7], param[8], param[9]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = (int)fn( );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_cmd_execute(Demo_Console *sys)
|
||||||
|
{
|
||||||
|
int ifcmd = 0;
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
int remain_len;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
#define MAX_DEMO_ARG 20
|
||||||
|
int param[MAX_DEMO_ARG];
|
||||||
|
int arg_count = 0;
|
||||||
|
|
||||||
|
u8 *ptmp_param = NULL;
|
||||||
|
|
||||||
|
u8 *buf = NULL;
|
||||||
|
u8 *pparam_equal = NULL;
|
||||||
|
u8 *pparam_begin = NULL;
|
||||||
|
u8 *pparam_end = NULL;
|
||||||
|
u8 *comma;
|
||||||
|
u8 *arg[MAX_DEMO_ARG] = {NULL};
|
||||||
|
int len;
|
||||||
|
u8 *strfirst = NULL;
|
||||||
|
u8 *str_r = NULL;
|
||||||
|
u8 *str_n = NULL;
|
||||||
|
|
||||||
|
for(i = 0; ; i++)
|
||||||
|
{
|
||||||
|
strfirst = (u8 *)strstr((char *)sys->rx_buf, console_tbl[i].cmd);
|
||||||
|
if (strfirst != NULL)
|
||||||
|
{
|
||||||
|
/*remove \r\n from input string*/
|
||||||
|
str_r = (u8 *)strchr((char *)strfirst, '\r');
|
||||||
|
str_n = (u8 *)strchr((char *)strfirst, '\n');
|
||||||
|
if (str_r&&(str_n == NULL))
|
||||||
|
{
|
||||||
|
if (str_r > strfirst)
|
||||||
|
{
|
||||||
|
strfirst[str_r - strfirst] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((str_r == NULL)&&str_n)
|
||||||
|
{
|
||||||
|
if (str_n > strfirst)
|
||||||
|
{
|
||||||
|
strfirst[str_n - strfirst] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (str_r && str_n)
|
||||||
|
{
|
||||||
|
if (((str_r > str_n) && (str_r > strfirst)))
|
||||||
|
{
|
||||||
|
strfirst[str_n - strfirst] = '\0';
|
||||||
|
}
|
||||||
|
else if ((str_r < str_n) && (str_n > strfirst))
|
||||||
|
{
|
||||||
|
strfirst[str_r - strfirst] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*parser()*/
|
||||||
|
pparam_equal = (u8 *)strchr((char *)(sys->rx_buf + strlen(console_tbl[i].cmd)), '=');
|
||||||
|
pparam_begin = (u8 *)strchr((char *)(sys->rx_buf + strlen(console_tbl[i].cmd)), '(');
|
||||||
|
if (pparam_equal)
|
||||||
|
{
|
||||||
|
if (pparam_begin && (pparam_begin > pparam_equal))
|
||||||
|
{
|
||||||
|
if (pparam_equal - strfirst > strlen(console_tbl[i].cmd))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!pparam_begin)
|
||||||
|
{
|
||||||
|
printf("\ndemo cmd short\n");
|
||||||
|
return DEMO_CONSOLE_SHORT_CMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (pparam_begin && (pparam_begin - strfirst > strlen(console_tbl[i].cmd)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if no '(', compare the cmd string with input string*/
|
||||||
|
if (!pparam_begin && (strlen((char *)strfirst) != strlen(console_tbl[i].cmd)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pparam_end = (u8 *)strchr((char *)(pparam_begin + 1), ')');
|
||||||
|
if (!pparam_begin && !pparam_end)
|
||||||
|
{
|
||||||
|
/*No Parameter,use default parameter to execute*/
|
||||||
|
printf("\n[CMD]%s\n", console_tbl[i].cmd);
|
||||||
|
for (j = 0; j < console_tbl[i].param_cnt; j++)
|
||||||
|
{
|
||||||
|
if (!((console_tbl[i].type >> j) & 0x1))
|
||||||
|
{
|
||||||
|
param[j] = (int)NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param[j] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = demo_call_fn((int (*)())console_tbl[i].callfn, param, console_tbl[i].param_cnt);
|
||||||
|
if(WM_FAILED == ret)
|
||||||
|
{
|
||||||
|
printf("\nrun demo failed\n");
|
||||||
|
}
|
||||||
|
return DEMO_CONSOLE_CMD;
|
||||||
|
}
|
||||||
|
else if (pparam_begin && pparam_end && ((pparam_end - pparam_begin) > 0))
|
||||||
|
{
|
||||||
|
remain_len = pparam_end - pparam_begin;
|
||||||
|
buf = pparam_begin + 1;
|
||||||
|
arg[0] = buf;
|
||||||
|
arg_count = 0;
|
||||||
|
*(u8 *)pparam_end = '\0';
|
||||||
|
while (remain_len > 0)
|
||||||
|
{
|
||||||
|
comma = (u8 *)demo_cmd_get_first_comma((char *)buf, remain_len);
|
||||||
|
if (pparam_end && !comma)
|
||||||
|
{
|
||||||
|
if (arg_count >= (console_tbl[i].param_cnt - 1))
|
||||||
|
break;
|
||||||
|
/* last parameter */
|
||||||
|
*(u8 *)pparam_end = '\0';
|
||||||
|
remain_len -= (pparam_end - buf);
|
||||||
|
if(remain_len <= 1)
|
||||||
|
break;
|
||||||
|
if (pparam_end != buf)
|
||||||
|
arg_count++;
|
||||||
|
arg[arg_count] = pparam_end + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*(u8 *)comma = '\0';
|
||||||
|
if (arg_count >= (console_tbl[i].param_cnt - 1))
|
||||||
|
break;
|
||||||
|
arg_count++;
|
||||||
|
arg[arg_count] = comma + 1;
|
||||||
|
remain_len -= (comma - buf + 1);
|
||||||
|
buf = comma + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j <= arg_count; j++)
|
||||||
|
{
|
||||||
|
while(' ' == *(arg[j]))
|
||||||
|
{
|
||||||
|
arg[j] ++;
|
||||||
|
}
|
||||||
|
len = strlen((char *)arg[j]);
|
||||||
|
while(len > 0 && ' ' == *(arg[j] + len - 1))
|
||||||
|
{
|
||||||
|
*(arg[j] + len - 1) = 0;
|
||||||
|
len --;
|
||||||
|
}
|
||||||
|
if (!((console_tbl[i].type >> j) & 0x1))
|
||||||
|
{
|
||||||
|
if(0 == len)
|
||||||
|
param[j] = (int)NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
demo_cmd_quotation_filter(&ptmp_param, arg[j]);
|
||||||
|
param[j] = (int)ptmp_param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(0 == len)
|
||||||
|
param[j] = -1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (strtodec(¶m[j], (char *)arg[j]) < 0)
|
||||||
|
{
|
||||||
|
printf("parameter err\r\n");
|
||||||
|
return DEMO_CONSOLE_WRONG_CMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = arg_count + 1; j < console_tbl[i].param_cnt; j++)
|
||||||
|
{
|
||||||
|
if (!((console_tbl[i].type >> j) & 0x1))
|
||||||
|
{
|
||||||
|
param[j] = (int)NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param[j] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n[CMD]%s\n", console_tbl[i].cmd);
|
||||||
|
|
||||||
|
ret = demo_call_fn((int (*)())console_tbl[i].callfn, param, console_tbl[i].param_cnt);
|
||||||
|
if(WM_FAILED == ret)
|
||||||
|
{
|
||||||
|
printf("\nrun demo failed\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Use input param to execute function*/
|
||||||
|
ifcmd = DEMO_CONSOLE_CMD;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (pparam_begin && !pparam_end)
|
||||||
|
{
|
||||||
|
printf("\ndemo cmd short\n");
|
||||||
|
return DEMO_CONSOLE_SHORT_CMD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*wrong cmd parameter,discard this cmd*/
|
||||||
|
printf("\nwrong cmd param\n");
|
||||||
|
//demo_console_show_help(NULL);
|
||||||
|
return DEMO_CONSOLE_WRONG_CMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strstr(console_tbl[i].cmd, "lastcmd") != NULL) //last command
|
||||||
|
{
|
||||||
|
/*wrong cmd parameter,discard this cmd*/
|
||||||
|
//demo_console_show_help(NULL);
|
||||||
|
printf("\nwrong cmd\n");
|
||||||
|
return DEMO_CONSOLE_WRONG_CMD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ifcmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//console task use UART0 as communication port with PC
|
||||||
|
void demo_console_task(void *sdata)
|
||||||
|
{
|
||||||
|
void *msg;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
demo_console_show_help(NULL);
|
||||||
|
demo_console_malloc();
|
||||||
|
gstConsole.rptr = 0;
|
||||||
|
gstConsole.rx_data_len = DEMO_CONSOLE_BUF_SIZE;
|
||||||
|
tls_uart_set_baud_rate(TLS_UART_0, 115200);
|
||||||
|
tls_uart_rx_callback_register(TLS_UART_0, demo_console_rx, NULL);
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(demo_q, (void **)&msg, 0, 0);
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
ret = tls_uart_read(TLS_UART_0, gstConsole.rx_buf + gstConsole.rptr, gstConsole.rx_data_len);
|
||||||
|
if(ret <= 0)
|
||||||
|
break;
|
||||||
|
gstConsole.rx_data_len -= ret;
|
||||||
|
gstConsole.rptr += ret;
|
||||||
|
if(gstConsole.rx_data_len <= 0)
|
||||||
|
break;
|
||||||
|
tls_os_time_delay(20);
|
||||||
|
}
|
||||||
|
if(gstConsole.rptr == 0)
|
||||||
|
break;
|
||||||
|
ret = demo_cmd_execute(&gstConsole); //parse command and execute if needed
|
||||||
|
if(DEMO_CONSOLE_CMD == ret)
|
||||||
|
{
|
||||||
|
/*modify*/
|
||||||
|
//printf("Demo cmd is finished\r\n");
|
||||||
|
}
|
||||||
|
else if(DEMO_CONSOLE_WRONG_CMD == ret)
|
||||||
|
{
|
||||||
|
//printf("Demo cmd is wrong\r\n");
|
||||||
|
}
|
||||||
|
else if(DEMO_CONSOLE_SHORT_CMD == ret)
|
||||||
|
{
|
||||||
|
//param not passed all, do nothing.
|
||||||
|
//printf("Demo cmd is short\r\n");
|
||||||
|
}
|
||||||
|
memset(gstConsole.rx_buf, 0, DEMO_CONSOLE_BUF_SIZE); /*After command finished transfering, clear buffer*/
|
||||||
|
gstConsole.rptr = 0;
|
||||||
|
|
||||||
|
if(gstConsole.MsgNum)
|
||||||
|
gstConsole.MsgNum --;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateDemoTask(void)
|
||||||
|
{
|
||||||
|
tls_os_queue_create(&demo_q, DEMO_QUEUE_SIZE);
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_console_task,
|
||||||
|
NULL,
|
||||||
|
(void *)DemoTaskStk, /* task's stack start address */
|
||||||
|
DEMO_TASK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DEMO_CONSOLE
|
||||||
|
|
||||||
215
demo/wm_7816_demo.c
Normal file
215
demo/wm_7816_demo.c
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "wm_regs.h"
|
||||||
|
#include "wm_7816.h"
|
||||||
|
#include "wm_gpio.h"
|
||||||
|
#include "wm_uart.h"
|
||||||
|
#include "wm_osal.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_pmu.h"
|
||||||
|
|
||||||
|
#if DEMO_7816
|
||||||
|
|
||||||
|
struct sc_rx
|
||||||
|
{
|
||||||
|
uint8_t *buf;
|
||||||
|
u16 buf_len;
|
||||||
|
u16 require_len;
|
||||||
|
u16 current_len;
|
||||||
|
tls_os_sem_t * sem_rx;
|
||||||
|
uint8_t timeout;
|
||||||
|
}sc_rx;
|
||||||
|
|
||||||
|
extern void tls_uart_rx_callback_register(u16 uart_no, s16(*rx_callback) (u16 len, void* user_data), void *priv_data);
|
||||||
|
extern void tls_uart_free_tx_sent_data(struct tls_uart_port *port);
|
||||||
|
|
||||||
|
const char i2d_cmd[] = { 0x00,0xa4,0x04,0x04,0x10,0xa0,0x00,
|
||||||
|
0x00,0x00,0x30,0x50,0x00,0x00,0x00,
|
||||||
|
0x00,0x00,0x00,0x00,0x49,0x64,0x32 };
|
||||||
|
|
||||||
|
s16 uart2_rx_cb(uint16_t len)
|
||||||
|
{
|
||||||
|
if (len == 0xFFFF)
|
||||||
|
{
|
||||||
|
sc_rx.timeout = 1;
|
||||||
|
tls_os_sem_release(sc_rx.sem_rx);
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
if(sc_rx.current_len + len < sc_rx.require_len)
|
||||||
|
{
|
||||||
|
tls_uart_read(2, &sc_rx.buf[sc_rx.current_len], len);
|
||||||
|
sc_rx.current_len += len;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tls_uart_read(2, &sc_rx.buf[sc_rx.current_len], len);
|
||||||
|
sc_rx.current_len += len;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_os_sem_release(sc_rx.sem_rx);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wm_sc_atr_test()
|
||||||
|
{
|
||||||
|
char sdata[4] = {0xff, 0x10, 0x95};
|
||||||
|
//char rdata[4] = {0xa,0xb,0xc,0xd};
|
||||||
|
char parity_byte = (uint8_t)(0xff ^ (uint8_t)0x10 ^ 0x95);
|
||||||
|
sdata[3] = parity_byte;
|
||||||
|
char test[32];
|
||||||
|
|
||||||
|
uint16_t sc_state = 0;
|
||||||
|
/*open 7816 clk*/
|
||||||
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_UART2);
|
||||||
|
sc_io.clk_pin_num = WM_IO_PB_04;
|
||||||
|
sc_io.clk_opt = WM_IO_OPTION2;
|
||||||
|
|
||||||
|
sc_io.io_pin_num = WM_IO_PB_02;
|
||||||
|
sc_io.io_opt = WM_IO_OPTION3;
|
||||||
|
sc_io.initialed = 1;
|
||||||
|
|
||||||
|
sc_rx.buf = (uint8_t *)test;
|
||||||
|
sc_rx.buf_len = 32;
|
||||||
|
sc_rx.require_len = 20;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_os_sem_create(&sc_rx.sem_rx, 0);
|
||||||
|
|
||||||
|
wm_sc_powerInit();
|
||||||
|
tls_uart_port_init(2, NULL, 1);
|
||||||
|
tls_uart_set_parity(2, TLS_UART_PMODE_EVEN);
|
||||||
|
tls_uart_set_stop_bits(2, TLS_UART_TWO_STOPBITS);
|
||||||
|
wm_sc_set_bcwt(0x1ff);
|
||||||
|
|
||||||
|
tls_uart_rx_callback_register((u16) TLS_UART_2, (void *)uart2_rx_cb, NULL);
|
||||||
|
tls_uart_tx_callback_register(2, (s16(*) (struct tls_uart_port *))tls_uart_free_tx_sent_data);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
switch(sc_state)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
wm_sc_colreset();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (test[0] == 0x3b)
|
||||||
|
{
|
||||||
|
sc_rx.require_len = 4;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_uart_write(2, sdata, 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sc_state = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (test[0] == 0xff)
|
||||||
|
{
|
||||||
|
if (!memcmp(sdata, test, 4))
|
||||||
|
{
|
||||||
|
wm_sc_set_etu(32);
|
||||||
|
}
|
||||||
|
sc_rx.require_len = 1;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_uart_write(2, (char *)i2d_cmd, 5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (test[0] == 0xA4)
|
||||||
|
{
|
||||||
|
sc_rx.require_len = 2;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_uart_write(2, (char *)&i2d_cmd[5], 16);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (test[0] == 0x90)
|
||||||
|
{
|
||||||
|
test[0] = 0x00;
|
||||||
|
test[1] = 0x36;
|
||||||
|
test[2] = 0x00;
|
||||||
|
test[3] = 0x00;
|
||||||
|
test[4] = 0x03;
|
||||||
|
sc_rx.require_len = 1;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_uart_write(2, test, 5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
if (test[0] == 0x36)
|
||||||
|
{
|
||||||
|
test[0] = 0x41;
|
||||||
|
test[1] = 0x00;
|
||||||
|
test[2] = 0x41;
|
||||||
|
sc_rx.require_len = 0x2;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_uart_write(2, test, 3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
if (test[0] == 0x61)
|
||||||
|
{
|
||||||
|
test[0] = 0x00;
|
||||||
|
test[1] = 0xc0;
|
||||||
|
test[2] = 0x00;
|
||||||
|
test[3] = 0x00;
|
||||||
|
test[4] = 0x16;
|
||||||
|
sc_rx.require_len = 0x19;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
tls_uart_write(2, test, 5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
if (test[0] == 0xc0)
|
||||||
|
{
|
||||||
|
test[19] = 0;
|
||||||
|
printf("id2:%s\r\n", &test[1]);
|
||||||
|
printf("\nhot reset \n");
|
||||||
|
sc_rx.require_len = 20;
|
||||||
|
sc_rx.current_len = 0;
|
||||||
|
sc_rx.timeout = 0;
|
||||||
|
wm_sc_hotreset();
|
||||||
|
sc_state = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tls_os_sem_acquire(sc_rx.sem_rx, 0);
|
||||||
|
if (!sc_rx.timeout)
|
||||||
|
{
|
||||||
|
sc_state++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("timeout\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEMO_TASK_SIZE 768
|
||||||
|
static OS_STK DemoTaskStk7816[DEMO_TASK_SIZE];
|
||||||
|
#define DEMO_CONSOLE_BUF_SIZE 512
|
||||||
|
|
||||||
|
int wm_7816_demo(void)
|
||||||
|
{
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
wm_sc_atr_test,
|
||||||
|
NULL,
|
||||||
|
(void *)DemoTaskStk7816,
|
||||||
|
DEMO_TASK_SIZE * sizeof(u32),
|
||||||
|
61,
|
||||||
|
0);
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
171
demo/wm_adc_demo.c
Normal file
171
demo/wm_adc_demo.c
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_adc_demo.c
|
||||||
|
*
|
||||||
|
* Description: adc demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : dave
|
||||||
|
*
|
||||||
|
* Date : 2014-8-18
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_adc.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_ADC
|
||||||
|
#define TMAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
|
||||||
|
#define TMACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||||
|
int adc_input_voltage_cal_demo(u8 chan, signed short refvoltage)
|
||||||
|
{
|
||||||
|
int ret =0;
|
||||||
|
u8 mac[6];
|
||||||
|
|
||||||
|
tls_get_mac_addr(mac);
|
||||||
|
printf("Mac["TMACSTR"],Cch[%d], Refvol[%d] ", TMAC2STR(mac), chan, refvoltage);
|
||||||
|
|
||||||
|
ret = adc_offset_calibration(chan, refvoltage);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
printf("Calok ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Calerr \r\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int voltage =0;
|
||||||
|
int i =0 ;
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (i != chan)
|
||||||
|
{
|
||||||
|
wm_adc_config(i);
|
||||||
|
voltage = adc_get_inputVolt(i);
|
||||||
|
printf("Mch[%d]-%d(mV) ", i, voltage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\r\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int adc_input_voltage_multipoint_cal_demo(int chanused,int chan0ref, int chan1ref, int chan2ref, int chan3ref)
|
||||||
|
{
|
||||||
|
int ret =0;
|
||||||
|
u8 mac[6];
|
||||||
|
int refvol[4] = {chan0ref, chan1ref, chan2ref, chan3ref};
|
||||||
|
|
||||||
|
tls_get_mac_addr(mac);
|
||||||
|
printf("Mac["TMACSTR"],", TMAC2STR(mac));
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (chanused&(1<<i))
|
||||||
|
{
|
||||||
|
printf("ch[%d], refvol[%d] ", i, refvol[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = adc_multipoint_calibration(chanused, refvol);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
printf("Calok \r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Calerr \r\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int voltage =0;
|
||||||
|
int i =0 ;
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
wm_adc_config(i);
|
||||||
|
voltage = adc_get_inputVolt(i);
|
||||||
|
printf("Mch[%d]-%d(mV) \r\n", i, voltage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int adc_input_voltage_demo(u8 chan)
|
||||||
|
{
|
||||||
|
int voltage =0;
|
||||||
|
|
||||||
|
if (chan < 4)
|
||||||
|
{
|
||||||
|
wm_adc_config(chan);
|
||||||
|
}
|
||||||
|
else if (chan == 8 )
|
||||||
|
{
|
||||||
|
wm_adc_config(0);
|
||||||
|
wm_adc_config(1);
|
||||||
|
}
|
||||||
|
else if (chan == 9)
|
||||||
|
{
|
||||||
|
wm_adc_config(2);
|
||||||
|
wm_adc_config(3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
voltage = adc_get_inputVolt(chan);
|
||||||
|
if (voltage < 0)
|
||||||
|
{
|
||||||
|
voltage = 0 - voltage;
|
||||||
|
printf("chan:%d, -%d(mV) or -%d.%03d(V)\r\n", chan, voltage, voltage/1000, voltage%1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("chan:%d, %d(mV) or %d.%03d(V)\r\n", chan, voltage, voltage/1000, voltage%1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int adc_chip_temperature_demo(void)
|
||||||
|
{
|
||||||
|
char temperature[8] = {0};
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
temp = adc_temp();
|
||||||
|
if (temp < 0)
|
||||||
|
{
|
||||||
|
temp = 0 - temp;
|
||||||
|
sprintf(temperature, "-%d.%03d", temp/1000, temp%1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf(temperature, "%d.%03d", temp/1000, temp%1000);
|
||||||
|
}
|
||||||
|
printf("tem: %s\r\n", temperature);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int adc_power_voltage_demo(void)
|
||||||
|
{
|
||||||
|
int voltage =0;
|
||||||
|
|
||||||
|
voltage = adc_get_interVolt();
|
||||||
|
printf("Power voltage:%d(mV) or %d.%03d(V)\r\n",voltage, voltage/1000, voltage%1000);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
366
demo/wm_apsta_demo.c
Normal file
366
demo/wm_apsta_demo.c
Normal file
@ -0,0 +1,366 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_apsta_demo.c
|
||||||
|
*
|
||||||
|
* Description: apsta demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : LiLimin
|
||||||
|
*
|
||||||
|
* Date : 2015-3-24
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "wm_netif.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
|
||||||
|
#if DEMO_APSTA
|
||||||
|
|
||||||
|
#define APSTA_DEMO_TASK_PRIO 38
|
||||||
|
#define APSTA_DEMO_TASK_SIZE 256
|
||||||
|
#define APSTA_DEMO_QUEUE_SIZE 4
|
||||||
|
|
||||||
|
static bool ApstaDemoIsInit = false;
|
||||||
|
static OS_STK ApstaDemoTaskStk[APSTA_DEMO_TASK_SIZE];
|
||||||
|
static tls_os_queue_t *ApstaDemoTaskQueue = NULL;
|
||||||
|
|
||||||
|
#define APSTA_DEMO_CMD_SOFTAP_CREATE 0x0
|
||||||
|
#define APSTA_DEMO_CMD_STA_JOIN_NET 0x1
|
||||||
|
#define APSTA_DEMO_CMD_SOFTAP_CLOSE 0x2
|
||||||
|
|
||||||
|
#define APSTA_DEMO_CMD_SOCKET_DEMO 0x3
|
||||||
|
|
||||||
|
#define APSTA_DEMO_SOCKET_DEMO_REMOTE_PORT 65530
|
||||||
|
#define APSTA_DEMO_SOCKET_DEMO_LOCAL_PORT 65531
|
||||||
|
|
||||||
|
extern u8 *wpa_supplicant_get_mac(void);
|
||||||
|
extern u8 *hostapd_get_mac(void);
|
||||||
|
|
||||||
|
|
||||||
|
static char apsta_demo_ssid[33];
|
||||||
|
static char apsta_demo_pwd[65];
|
||||||
|
static char apsta_demo_apssid[33];
|
||||||
|
static char apsta_demo_appwd[65];
|
||||||
|
|
||||||
|
static void apsta_demo_client_event(u8 *mac, enum tls_wifi_client_event_type event)
|
||||||
|
{
|
||||||
|
wm_printf("client %M is %s\r\n", mac, event ? "offline" : "online");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apsta_demo_net_status(u8 status)
|
||||||
|
{
|
||||||
|
struct netif *netif = tls_get_netif();
|
||||||
|
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
wm_printf("sta join net failed\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
wm_printf("sta net disconnected\n");
|
||||||
|
tls_os_queue_send(ApstaDemoTaskQueue, (void *)APSTA_DEMO_CMD_SOFTAP_CLOSE, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
wm_printf("\nsta ip: %v\n", netif->ip_addr.addr);
|
||||||
|
tls_os_queue_send(ApstaDemoTaskQueue, (void *)APSTA_DEMO_CMD_SOFTAP_CREATE, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_SOFTAP_FAILED:
|
||||||
|
wm_printf("softap create failed\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_SOFTAP_CLOSED:
|
||||||
|
wm_printf("softap closed\n");
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET2_UP:
|
||||||
|
wm_printf("\nsoftap ip: %v\n", netif->next->ip_addr.addr);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int soft_ap_demo(char *apssid, char *appwd)
|
||||||
|
{
|
||||||
|
struct tls_softap_info_t apinfo;
|
||||||
|
struct tls_ip_info_t ipinfo;
|
||||||
|
u8 ret = 0;
|
||||||
|
|
||||||
|
memset(&apinfo, 0, sizeof(apinfo));
|
||||||
|
memset(&ipinfo, 0, sizeof(ipinfo));
|
||||||
|
|
||||||
|
u8 *ssid = (u8 *)"w600_apsta_demo";
|
||||||
|
u8 ssid_len = strlen("w600_apsta_demo");
|
||||||
|
|
||||||
|
if (apssid)
|
||||||
|
{
|
||||||
|
ssid_len = strlen(apssid);
|
||||||
|
MEMCPY(apinfo.ssid, apssid, ssid_len);
|
||||||
|
apinfo.ssid[ssid_len] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MEMCPY(apinfo.ssid, ssid, ssid_len);
|
||||||
|
apinfo.ssid[ssid_len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
apinfo.encrypt = strlen(appwd) ? IEEE80211_ENCRYT_CCMP_WPA2 : IEEE80211_ENCRYT_NONE;
|
||||||
|
apinfo.channel = 11; /*channel*/
|
||||||
|
apinfo.keyinfo.format = 1; /*format:0,hex, 1,ascii*/
|
||||||
|
apinfo.keyinfo.index = 1; /*wep index*/
|
||||||
|
apinfo.keyinfo.key_len = strlen(appwd); /*key length*/
|
||||||
|
MEMCPY(apinfo.keyinfo.key, appwd, strlen(appwd));
|
||||||
|
|
||||||
|
/*ip information:ip address,mask, DNS name*/
|
||||||
|
ipinfo.ip_addr[0] = 192;
|
||||||
|
ipinfo.ip_addr[1] = 168;
|
||||||
|
ipinfo.ip_addr[2] = 8;
|
||||||
|
ipinfo.ip_addr[3] = 1;
|
||||||
|
ipinfo.netmask[0] = 255;
|
||||||
|
ipinfo.netmask[1] = 255;
|
||||||
|
ipinfo.netmask[2] = 255;
|
||||||
|
ipinfo.netmask[3] = 0;
|
||||||
|
MEMCPY(ipinfo.dnsname, "local.wm", sizeof("local.wm"));
|
||||||
|
|
||||||
|
ret = tls_wifi_softap_create((struct tls_softap_info_t * )&apinfo, (struct tls_ip_info_t * )&ipinfo);
|
||||||
|
wm_printf("\nap create %s ! \n", (ret == WM_SUCCESS) ? "Successfully" : "Error");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int connect_wifi_demo(char *ssid, char *pwd)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));
|
||||||
|
if (WM_SUCCESS == ret)
|
||||||
|
wm_printf("\nplease wait connect net......\n");
|
||||||
|
else
|
||||||
|
wm_printf("\napsta connect net failed, please check configure......\n");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_wifi_config(void)
|
||||||
|
{
|
||||||
|
u8 ssid_set = 0;
|
||||||
|
u8 wireless_protocol = 0;
|
||||||
|
struct tls_param_ip *ip_param = NULL;
|
||||||
|
|
||||||
|
tls_wifi_disconnect();
|
||||||
|
|
||||||
|
tls_wifi_softap_destroy();
|
||||||
|
|
||||||
|
tls_wifi_set_oneshot_flag(0);
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);
|
||||||
|
if (TLS_PARAM_IEEE80211_INFRA != wireless_protocol)
|
||||||
|
{
|
||||||
|
wireless_protocol = TLS_PARAM_IEEE80211_INFRA;
|
||||||
|
tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)0);
|
||||||
|
if (0 == ssid_set)
|
||||||
|
{
|
||||||
|
ssid_set = 1;
|
||||||
|
tls_param_set(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)1); /*set flag to broadcast BSSID*/
|
||||||
|
}
|
||||||
|
|
||||||
|
ip_param = tls_mem_alloc(sizeof(struct tls_param_ip));
|
||||||
|
if (ip_param)
|
||||||
|
{
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, ip_param, FALSE);
|
||||||
|
ip_param->dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, ip_param, FALSE);
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_SOFTAP_IP, ip_param, FALSE);
|
||||||
|
ip_param->dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_SOFTAP_IP, ip_param, FALSE);
|
||||||
|
|
||||||
|
tls_mem_free(ip_param);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_netif_add_status_event(apsta_demo_net_status);
|
||||||
|
|
||||||
|
tls_wifi_softap_client_event_register(apsta_demo_client_event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apsta_demo_socket_demo(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int ret;
|
||||||
|
int skt;
|
||||||
|
u8 *mac;
|
||||||
|
u8 *mac2;
|
||||||
|
struct netif *netif;
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
|
netif = tls_get_netif();
|
||||||
|
|
||||||
|
/*broadcast message to current AP tha STA is connected*/
|
||||||
|
printf("broadcast send mac in sta's bbs...\n");
|
||||||
|
skt = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (skt < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = ip_addr_get_ip4_u32(&netif->ip_addr);
|
||||||
|
addr.sin_port = htons(APSTA_DEMO_SOCKET_DEMO_LOCAL_PORT);
|
||||||
|
|
||||||
|
ret = bind(skt, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
if (0 != ret)
|
||||||
|
{
|
||||||
|
close(skt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||||
|
addr.sin_port = htons(APSTA_DEMO_SOCKET_DEMO_REMOTE_PORT);
|
||||||
|
|
||||||
|
mac = wpa_supplicant_get_mac();
|
||||||
|
|
||||||
|
for (i = 0; i < 60; i++)
|
||||||
|
{
|
||||||
|
sendto(skt, mac, ETH_ALEN, 0, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
tls_os_time_delay(HZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(skt);
|
||||||
|
|
||||||
|
|
||||||
|
/*broadcast message at current soft AP*/
|
||||||
|
printf("broadcast send mac in softap's bbs...\n");
|
||||||
|
skt = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (skt < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = ip_addr_get_ip4_u32(&netif->next->ip_addr);
|
||||||
|
addr.sin_port = htons(APSTA_DEMO_SOCKET_DEMO_LOCAL_PORT);
|
||||||
|
|
||||||
|
ret = bind(skt, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
if (0 != ret)
|
||||||
|
{
|
||||||
|
close(skt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = setsockopt(skt, IPPROTO_IP, IP_MULTICAST_IF, &addr.sin_addr, sizeof(struct in_addr));
|
||||||
|
if(0 != ret)
|
||||||
|
{
|
||||||
|
close(skt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
|
||||||
|
addr.sin_port = htons(APSTA_DEMO_SOCKET_DEMO_REMOTE_PORT);
|
||||||
|
|
||||||
|
mac2 = hostapd_get_mac();
|
||||||
|
|
||||||
|
for (i = 0; i < 60; i++)
|
||||||
|
{
|
||||||
|
sendto(skt, mac2, ETH_ALEN, 0, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
tls_os_time_delay(HZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(skt);
|
||||||
|
|
||||||
|
printf("apsta socket sent end.\n");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void apsta_demo_task(void *p)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
void *msg;
|
||||||
|
|
||||||
|
for( ; ; )
|
||||||
|
{
|
||||||
|
ret = tls_os_queue_receive(ApstaDemoTaskQueue, (void **)&msg, 0, 0);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case APSTA_DEMO_CMD_STA_JOIN_NET:
|
||||||
|
connect_wifi_demo(apsta_demo_ssid, apsta_demo_pwd);
|
||||||
|
break;
|
||||||
|
case APSTA_DEMO_CMD_SOFTAP_CREATE:
|
||||||
|
soft_ap_demo(apsta_demo_apssid, apsta_demo_appwd);
|
||||||
|
break;
|
||||||
|
case APSTA_DEMO_CMD_SOFTAP_CLOSE:
|
||||||
|
tls_wifi_softap_destroy();
|
||||||
|
break;
|
||||||
|
case APSTA_DEMO_CMD_SOCKET_DEMO:
|
||||||
|
apsta_demo_socket_demo();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//apsta demo
|
||||||
|
//Command as:t-apsta("ssid","pwd", "apsta", "appwd");
|
||||||
|
int apsta_demo(char *ssid, char *pwd, char *apssid, char *appwd)
|
||||||
|
{
|
||||||
|
memset(apsta_demo_ssid, 0, sizeof(apsta_demo_ssid));
|
||||||
|
memset(apsta_demo_pwd, 0, sizeof(apsta_demo_pwd));
|
||||||
|
|
||||||
|
strcpy(apsta_demo_ssid, ssid);
|
||||||
|
wm_printf("\nsta_ssid=%s\n", apsta_demo_ssid);
|
||||||
|
|
||||||
|
strcpy(apsta_demo_pwd, pwd);
|
||||||
|
wm_printf("\nsta_password=%s\n", apsta_demo_pwd);
|
||||||
|
|
||||||
|
strcpy(apsta_demo_apssid, apssid);
|
||||||
|
wm_printf("\nap_ssid=%s\n", apsta_demo_apssid);
|
||||||
|
|
||||||
|
strcpy(apsta_demo_appwd, appwd);
|
||||||
|
wm_printf("\nap_password=%s\n", apsta_demo_appwd);
|
||||||
|
|
||||||
|
if (!ApstaDemoIsInit)
|
||||||
|
{
|
||||||
|
init_wifi_config();
|
||||||
|
|
||||||
|
tls_os_task_create(NULL, NULL, apsta_demo_task,
|
||||||
|
(void *)0, (void *)ApstaDemoTaskStk,/* task's stack start address */
|
||||||
|
APSTA_DEMO_TASK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
APSTA_DEMO_TASK_PRIO, 0);
|
||||||
|
|
||||||
|
tls_os_queue_create(&ApstaDemoTaskQueue, APSTA_DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
ApstaDemoIsInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_os_queue_send(ApstaDemoTaskQueue, (void *)APSTA_DEMO_CMD_STA_JOIN_NET, 0);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int apsta_socket_demo(void)
|
||||||
|
{
|
||||||
|
if (ApstaDemoIsInit)
|
||||||
|
{
|
||||||
|
tls_os_queue_send(ApstaDemoTaskQueue, (void *)APSTA_DEMO_CMD_SOCKET_DEMO, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("please run the apsta demo first.\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
78
demo/wm_avoid_copy_demo.c
Normal file
78
demo/wm_avoid_copy_demo.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_internal_flash.h"
|
||||||
|
#include "wm_crypto_hard.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_AVOID_COPY
|
||||||
|
extern void dumpBuffer(char *name, char* buffer, int len);
|
||||||
|
extern int config_flash_decrypt_param(uint32_t code_decrypt, uint32_t dbus_decrypt, uint32_t data_decrypt);
|
||||||
|
|
||||||
|
int avoid_copy_secret_firm(u32 addr)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
char *buf = tls_mem_alloc(128);
|
||||||
|
u8 uuid[18];
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tls_fls_read_unique_id(uuid);
|
||||||
|
dumpBuffer("uuid", (char *)uuid, 18);
|
||||||
|
config_flash_decrypt_param(1, 1, 1);
|
||||||
|
tls_fls_read(addr, (u8 *)buf, 32);
|
||||||
|
dumpBuffer("decrypted data", buf, 32);
|
||||||
|
if(memcmp(uuid, buf, 9) || memcmp(&uuid[9], &buf[16], 9))
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
tls_mem_free(buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int avoid_copy_open_firm(u32 addr)
|
||||||
|
{
|
||||||
|
const u8 aesKey[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66};
|
||||||
|
psCipherContext_t ctx;
|
||||||
|
int ret = 0;
|
||||||
|
char *buf = tls_mem_alloc(128);
|
||||||
|
u8 uuid[18];
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tls_fls_read_unique_id(uuid);
|
||||||
|
dumpBuffer("uuid", (char *)uuid, 18);
|
||||||
|
tls_fls_read(addr, (u8 *)buf, 32);
|
||||||
|
tls_crypto_aes_init(&ctx, NULL, aesKey, 16, CRYPTO_MODE_ECB);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, (unsigned char *)buf, (unsigned char *)buf, 32, CRYPTO_WAY_DECRYPT);
|
||||||
|
dumpBuffer("decrypted data", buf, 32);
|
||||||
|
if(memcmp(uuid, buf, 9) || memcmp(&uuid[9], &buf[16], 9))
|
||||||
|
{
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
tls_mem_free(buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int avoid_copy_entry(void)
|
||||||
|
{
|
||||||
|
int type = 0;
|
||||||
|
FLASH_ENCRYPT_CTRL_Type encrypt_ctrl;
|
||||||
|
encrypt_ctrl.w = M32(HR_FLASH_ENCRYPT_CTRL);
|
||||||
|
type = encrypt_ctrl.b.code_decrypt;
|
||||||
|
if((type == 1 && avoid_copy_secret_firm(0x800F000)) || (type == 0 && avoid_copy_open_firm(0x800F000)))
|
||||||
|
{
|
||||||
|
printf("avoid copy %s firm start fail!\n", type == 1 ? "secret" : "open");
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
if (type == 1) /*restore for secret*/
|
||||||
|
M32(HR_FLASH_ENCRYPT_CTRL) = encrypt_ctrl.w;
|
||||||
|
printf("avoid copy %s firm start success!\n", type == 1 ? "secret" : "open");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
176
demo/wm_connect_net_demo.c
Normal file
176
demo/wm_connect_net_demo.c
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_wifi_oneshot.h"
|
||||||
|
#include "wm_param.h"
|
||||||
|
|
||||||
|
#if DEMO_CONNECT_NET
|
||||||
|
static void con_net_status_changed_event(u8 status )
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
printf("NETIF_WIFI_JOIN_SUCCESS\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
printf("NETIF_WIFI_JOIN_FAILED\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
printf("NETIF_WIFI_DISCONNECTED\n");
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
{
|
||||||
|
struct tls_ethif *tmpethif = tls_netif_get_ethif();
|
||||||
|
print_ipaddr(&tmpethif->ip_addr);
|
||||||
|
#if TLS_CONFIG_IPV6
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[0]);
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[1]);
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[2]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//printf("UNKONWN STATE:%d\n", status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_oneshot(void)
|
||||||
|
{
|
||||||
|
printf("waiting for oneshot \n");
|
||||||
|
tls_netif_add_status_event(con_net_status_changed_event);
|
||||||
|
tls_wifi_set_oneshot_flag(1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_socket_config(void)
|
||||||
|
{
|
||||||
|
printf("AP Mode socket config demo \n");
|
||||||
|
tls_netif_add_status_event(con_net_status_changed_event);
|
||||||
|
tls_wifi_set_oneshot_flag(2);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_webserver_config(void)
|
||||||
|
{
|
||||||
|
printf("AP Mode web server config mode \n");
|
||||||
|
tls_netif_add_status_event(con_net_status_changed_event);
|
||||||
|
tls_wifi_set_oneshot_flag(3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_ble_config(void)
|
||||||
|
{
|
||||||
|
printf("BLE config mode \n");
|
||||||
|
#if TLS_CONFIG_BT
|
||||||
|
extern int demo_bt_enable();
|
||||||
|
tls_netif_add_status_event(con_net_status_changed_event);
|
||||||
|
demo_bt_enable();
|
||||||
|
tls_os_time_delay(HZ/2);
|
||||||
|
tls_wifi_set_oneshot_flag(4);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//acitve connect to specified AP, use command as: t-connet("ssid","pwd");
|
||||||
|
int demo_connect_net(char *ssid, char *pwd)
|
||||||
|
{
|
||||||
|
struct tls_param_ip *ip_param = NULL;
|
||||||
|
u8 wireless_protocol = 0;
|
||||||
|
|
||||||
|
if (!ssid)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nssid:%s\n", ssid);
|
||||||
|
printf("password=%s\n", pwd);
|
||||||
|
tls_wifi_disconnect();
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);
|
||||||
|
if (TLS_PARAM_IEEE80211_INFRA != wireless_protocol)
|
||||||
|
{
|
||||||
|
tls_wifi_softap_destroy();
|
||||||
|
wireless_protocol = TLS_PARAM_IEEE80211_INFRA;
|
||||||
|
tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_wifi_set_oneshot_flag(0);
|
||||||
|
|
||||||
|
ip_param = tls_mem_alloc(sizeof(struct tls_param_ip));
|
||||||
|
if (ip_param)
|
||||||
|
{
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, ip_param, FALSE);
|
||||||
|
ip_param->dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, ip_param, FALSE);
|
||||||
|
tls_mem_free(ip_param);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_netif_add_status_event(con_net_status_changed_event);
|
||||||
|
tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));
|
||||||
|
printf("\nplease wait connect net......\n");
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//acitve connect to specified AP, use command as: t-connet_ss("ssid","pwd", 10, 0, 0);
|
||||||
|
int demo_connect_net_with_specific_info(char *ssid, char *pwd, u32 timeout, u32 pci_en, u32 scan_mode)
|
||||||
|
{
|
||||||
|
struct tls_param_ip *ip_param = NULL;
|
||||||
|
u8 wireless_protocol = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (!ssid)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nssid:%s\n", ssid);
|
||||||
|
printf("password=%s\n", pwd);
|
||||||
|
tls_wifi_disconnect();
|
||||||
|
|
||||||
|
/*clear quick connect information because of scan_mode */
|
||||||
|
{
|
||||||
|
struct tls_param_quick_connect quick_connect;
|
||||||
|
quick_connect.quick_connect_en = FALSE;
|
||||||
|
quick_connect.chanId = 255;
|
||||||
|
|
||||||
|
tls_param_set(TLS_PARAM_ID_QUICK_CONNECT, &quick_connect, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);
|
||||||
|
if (TLS_PARAM_IEEE80211_INFRA != wireless_protocol)
|
||||||
|
{
|
||||||
|
tls_wifi_softap_destroy();
|
||||||
|
wireless_protocol = TLS_PARAM_IEEE80211_INFRA;
|
||||||
|
tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_wifi_set_oneshot_flag(0);
|
||||||
|
|
||||||
|
ip_param = tls_mem_alloc(sizeof(struct tls_param_ip));
|
||||||
|
if (ip_param)
|
||||||
|
{
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, ip_param, FALSE);
|
||||||
|
ip_param->dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, ip_param, FALSE);
|
||||||
|
tls_mem_free(ip_param);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_netif_add_status_event(con_net_status_changed_event);
|
||||||
|
/*configure if sta can connect open/wep AP*/
|
||||||
|
tls_wifi_cfg_connect_pci(pci_en);
|
||||||
|
/*configure the timeout that module connect AP during scanning*/
|
||||||
|
tls_wifi_cfg_connect_timeout(timeout);
|
||||||
|
/*configure if the module immediately connect AP after scan specific AP*/
|
||||||
|
tls_wifi_cfg_connect_scan_mode(scan_mode);
|
||||||
|
tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));
|
||||||
|
printf("\nplease wait connect net......\n");
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
99
demo/wm_crypt_demo.c
Normal file
99
demo/wm_crypt_demo.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_crypt_demo.c
|
||||||
|
*
|
||||||
|
* Description: crypt demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : wangmin
|
||||||
|
*
|
||||||
|
* Date : 2014-6-2
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_crypto.h"
|
||||||
|
|
||||||
|
#if DEMO_ENCRYPT
|
||||||
|
int crypt_demo(char *buf)
|
||||||
|
{
|
||||||
|
|
||||||
|
u8 iv[16];
|
||||||
|
u8 dat[24];
|
||||||
|
u8 key[16]="abcdefghijklmnop";
|
||||||
|
u8 plain[16]="0123456789ABCDEF";
|
||||||
|
int i;
|
||||||
|
int len = 16;
|
||||||
|
|
||||||
|
for(i=0;i<16;i++) iv[i]=i;
|
||||||
|
|
||||||
|
memset(dat, 0, 16);
|
||||||
|
MEMCPY(dat, plain, sizeof(plain));
|
||||||
|
|
||||||
|
/******start AES 128 En/Decrypt********/
|
||||||
|
printf("---start AES128:\n");
|
||||||
|
if (aes_128_cbc_encrypt(key, iv, dat, sizeof(plain))){
|
||||||
|
printf("Encrypted Failed\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
printf("Encrypted OK:\n");
|
||||||
|
for(i=0; i<len; i++) printf("%x", dat[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(aes_128_cbc_decrypt(key, iv, dat, sizeof(plain))){
|
||||||
|
printf("Decrypt failed\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}else{
|
||||||
|
printf("Decrypted OK:\n");
|
||||||
|
for(i=0; i<len; i++) printf("%x", dat[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/******start RC4********/
|
||||||
|
printf("\n----start RC4:\n");
|
||||||
|
rc4(key, sizeof(key), plain, sizeof(plain));
|
||||||
|
printf("Encrypted OK:\n");
|
||||||
|
for(i=0; i<sizeof(plain); i++) printf("%x", plain[i]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
rc4(key, sizeof(key),plain, sizeof(plain));
|
||||||
|
printf("Decrypted OK:\n");
|
||||||
|
for(i=0; i<sizeof(plain); i++) printf("%x", plain[i]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
|
||||||
|
/******start HMAC MD5********/
|
||||||
|
printf("\n---start HMAC MD5:\n");
|
||||||
|
memset(dat, 0, sizeof(dat));
|
||||||
|
if(hmac_md5(key, sizeof(key), plain, sizeof(plain), dat)){
|
||||||
|
printf("Caculated failed\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}else{
|
||||||
|
printf("HMAC MD5: \n");
|
||||||
|
for(i=0; i<len; i++) printf("%x", dat[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/******start MD5********/
|
||||||
|
printf("\n----start MD5:\n");
|
||||||
|
memset(dat, 0, sizeof(dat));
|
||||||
|
md5(plain, sizeof(plain),dat);
|
||||||
|
printf("MD5: \n");
|
||||||
|
for(i=0; i<len; i++) printf("%x", dat[i]);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
/******start SHA1********/
|
||||||
|
printf("\n---start SHA1:\n");
|
||||||
|
len = 20;
|
||||||
|
memset(dat, 0, sizeof(dat));
|
||||||
|
sha1(plain, sizeof(plain),dat);
|
||||||
|
printf("SHA1: \n");
|
||||||
|
for(i=0; i<len; i++) printf("%x", dat[i]);
|
||||||
|
printf("\n");
|
||||||
|
return WM_SUCCESS;;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
592
demo/wm_crypt_hard_demo.c
Normal file
592
demo/wm_crypt_hard_demo.c
Normal file
@ -0,0 +1,592 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_crypto_hard.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_ENCRYPT
|
||||||
|
|
||||||
|
void RNG_hard_demo(void)
|
||||||
|
{
|
||||||
|
u8 *out = NULL;
|
||||||
|
u16 i;
|
||||||
|
|
||||||
|
out = tls_mem_alloc(1000);
|
||||||
|
|
||||||
|
tls_crypto_random_init(0xFDA3C97A, CRYPTO_RNG_SWITCH_16);
|
||||||
|
tls_crypto_random_bytes(out, 10);
|
||||||
|
|
||||||
|
printf("RNG out:\n");
|
||||||
|
for(i=0; i<10; i++)
|
||||||
|
{
|
||||||
|
printf("%X ", out[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
tls_crypto_random_bytes(out, 20);
|
||||||
|
|
||||||
|
printf("RNG out:\n");
|
||||||
|
for(i=0; i<20; i++)
|
||||||
|
{
|
||||||
|
printf("%X ", out[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
tls_crypto_random_stop();
|
||||||
|
|
||||||
|
tls_mem_free(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rc4_hard_demo(void)
|
||||||
|
{
|
||||||
|
psCipherContext_t ctx;
|
||||||
|
u8 *in = NULL;
|
||||||
|
u8 *out1 = NULL;
|
||||||
|
u8 *out2 = NULL;
|
||||||
|
u8 *key = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
in = tls_mem_alloc(1000);
|
||||||
|
out1 = tls_mem_alloc(1000);
|
||||||
|
out2 = tls_mem_alloc(1000);
|
||||||
|
key = tls_mem_alloc(16);
|
||||||
|
|
||||||
|
if((in==NULL) || (out1==NULL) || (out2==NULL) || (key==NULL))
|
||||||
|
{
|
||||||
|
printf("malloc err\n");
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<1000; i++)
|
||||||
|
{
|
||||||
|
in[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<16; i++)
|
||||||
|
{
|
||||||
|
key[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1000);
|
||||||
|
memset(out2, 0, 1000);
|
||||||
|
|
||||||
|
if(ERR_OK != tls_crypto_rc4_init(&ctx, key, 16))
|
||||||
|
{
|
||||||
|
printf("rc4 init err\n");
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
tls_crypto_rc4(&ctx, in, out1, 1000);
|
||||||
|
tls_crypto_rc4(&ctx, out1, out2, 1000);
|
||||||
|
|
||||||
|
if(memcmp(in, out2, 1000))
|
||||||
|
{
|
||||||
|
printf("rc4 test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("rc4 test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
OUT:
|
||||||
|
if(in != NULL)
|
||||||
|
tls_mem_free(in);
|
||||||
|
if(out1 != NULL)
|
||||||
|
tls_mem_free(out1);
|
||||||
|
if(out2 != NULL)
|
||||||
|
tls_mem_free(out2);
|
||||||
|
if(key != NULL)
|
||||||
|
tls_mem_free(key);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int aes_hard_demo(void)
|
||||||
|
{
|
||||||
|
psCipherContext_t ctx;
|
||||||
|
u8 *in = NULL;
|
||||||
|
u8 *out1 = NULL;
|
||||||
|
u8 *out2 = NULL;
|
||||||
|
u8 *key = NULL;
|
||||||
|
u8 *iv = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
|
||||||
|
in = tls_mem_alloc(1024); //AES 必须是16的整数倍,否则会出错
|
||||||
|
out1 = tls_mem_alloc(1024);
|
||||||
|
out2 = tls_mem_alloc(1024);
|
||||||
|
key = tls_mem_alloc(16);
|
||||||
|
iv = tls_mem_alloc(16);
|
||||||
|
|
||||||
|
if((in==NULL) || (out1==NULL) || (out2==NULL) || (key==NULL) || (iv==NULL))
|
||||||
|
{
|
||||||
|
printf("malloc err\n");
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<1024; i++)
|
||||||
|
{
|
||||||
|
in[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<16; i++)
|
||||||
|
{
|
||||||
|
key[i] = rand();
|
||||||
|
iv[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_aes_init(&ctx, iv, key, 16, CRYPTO_MODE_ECB);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("aes ecb test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("aes ecb test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_aes_init(&ctx, iv, key, 16, CRYPTO_MODE_CBC);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("aes cbc test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("aes cbc test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_aes_init(&ctx, iv, key, 16, CRYPTO_MODE_CTR);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_aes_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("aes ctr test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("aes ctr test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
OUT:
|
||||||
|
if(in != NULL)
|
||||||
|
tls_mem_free(in);
|
||||||
|
if(out1 != NULL)
|
||||||
|
tls_mem_free(out1);
|
||||||
|
if(out2 != NULL)
|
||||||
|
tls_mem_free(out2);
|
||||||
|
if(key != NULL)
|
||||||
|
tls_mem_free(key);
|
||||||
|
if(iv != NULL)
|
||||||
|
tls_mem_free(iv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int des_hard_demo(void)
|
||||||
|
{
|
||||||
|
psCipherContext_t ctx;
|
||||||
|
u8 *in = NULL;
|
||||||
|
u8 *out1 = NULL;
|
||||||
|
u8 *out2 = NULL;
|
||||||
|
u8 *key = NULL;
|
||||||
|
u8 *iv = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
|
||||||
|
in = tls_mem_alloc(1024);
|
||||||
|
out1 = tls_mem_alloc(1024);
|
||||||
|
out2 = tls_mem_alloc(1024);
|
||||||
|
key = tls_mem_alloc(8);
|
||||||
|
iv = tls_mem_alloc(8);
|
||||||
|
|
||||||
|
if((in==NULL) || (out1==NULL) || (out2==NULL) || (key==NULL) || (iv==NULL))
|
||||||
|
{
|
||||||
|
printf("malloc err\n");
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<1024; i++)
|
||||||
|
{
|
||||||
|
in[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<8; i++)
|
||||||
|
{
|
||||||
|
key[i] = rand();
|
||||||
|
iv[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_des_init(&ctx, iv, key, 8, CRYPTO_MODE_ECB);
|
||||||
|
tls_crypto_des_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_des_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("des ecb test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("des ecb test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_des_init(&ctx, iv, key, 8, CRYPTO_MODE_CBC);
|
||||||
|
tls_crypto_des_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_des_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("des cbc test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("des cbc test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
OUT:
|
||||||
|
if(in != NULL)
|
||||||
|
tls_mem_free(in);
|
||||||
|
if(out1 != NULL)
|
||||||
|
tls_mem_free(out1);
|
||||||
|
if(out2 != NULL)
|
||||||
|
tls_mem_free(out2);
|
||||||
|
if(key != NULL)
|
||||||
|
tls_mem_free(key);
|
||||||
|
if(iv != NULL)
|
||||||
|
tls_mem_free(iv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int des3_hard_demo(void)
|
||||||
|
{
|
||||||
|
psCipherContext_t ctx;
|
||||||
|
u8 *in = NULL;
|
||||||
|
u8 *out1 = NULL;
|
||||||
|
u8 *out2 = NULL;
|
||||||
|
u8 *key = NULL;
|
||||||
|
u8 *iv = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
|
||||||
|
in = tls_mem_alloc(1024);
|
||||||
|
out1 = tls_mem_alloc(1024);
|
||||||
|
out2 = tls_mem_alloc(1024);
|
||||||
|
key = tls_mem_alloc(24);
|
||||||
|
iv = tls_mem_alloc(8);
|
||||||
|
|
||||||
|
if((in==NULL) || (out1==NULL) || (out2==NULL) || (key==NULL) || (iv==NULL))
|
||||||
|
{
|
||||||
|
printf("malloc err\n");
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<1024; i++)
|
||||||
|
{
|
||||||
|
in[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<24; i++)
|
||||||
|
{
|
||||||
|
key[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<8; i++)
|
||||||
|
{
|
||||||
|
iv[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_3des_init(&ctx, iv, key, 24, CRYPTO_MODE_ECB);
|
||||||
|
tls_crypto_3des_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_3des_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("3des ecb test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("3des ecb test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out1, 0, 1024);
|
||||||
|
memset(out2, 0, 1024);
|
||||||
|
tls_crypto_3des_init(&ctx, iv, key, 24, CRYPTO_MODE_CBC);
|
||||||
|
tls_crypto_3des_encrypt_decrypt(&ctx, in, out1, 1024, CRYPTO_WAY_ENCRYPT);
|
||||||
|
tls_crypto_3des_encrypt_decrypt(&ctx, out1, out2, 1024, CRYPTO_WAY_DECRYPT);
|
||||||
|
if(memcmp(in, out2, 1024))
|
||||||
|
{
|
||||||
|
printf("3des cbc test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("3des cbc test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
OUT:
|
||||||
|
if(in != NULL)
|
||||||
|
tls_mem_free(in);
|
||||||
|
if(out1 != NULL)
|
||||||
|
tls_mem_free(out1);
|
||||||
|
if(out2 != NULL)
|
||||||
|
tls_mem_free(out2);
|
||||||
|
if(key != NULL)
|
||||||
|
tls_mem_free(key);
|
||||||
|
if(iv != NULL)
|
||||||
|
tls_mem_free(iv);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int crc_hard_demo(void)
|
||||||
|
{
|
||||||
|
u32 crckey = 0xFFFFFFFF;
|
||||||
|
psCrcContext_t ctx;
|
||||||
|
u8 *in = NULL;
|
||||||
|
int i;
|
||||||
|
u32 crcvalue = 0;
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
|
||||||
|
in = tls_mem_alloc(1024);
|
||||||
|
if(in==NULL)
|
||||||
|
{
|
||||||
|
printf("malloc err\n");
|
||||||
|
goto OUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<1024; i++)
|
||||||
|
{
|
||||||
|
in[i] = rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_8, 0);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_8 normal value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_8, INPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_8 INPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_8, OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_8 OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_8, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_8 INPUT_REFLECT | OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_MODBUS, 0);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_MODBUS normal value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_MODBUS, INPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_MODBUS INPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_MODBUS, OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_MODBUS OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_MODBUS, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_MODBUS INPUT_REFLECT | OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_CCITT, 0);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_CCITT normal value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_CCITT, INPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_CCITT INPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_CCITT, OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_CCITT OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_16_CCITT, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_16_CCITT INPUT_REFLECT | OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_32, 0);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_32 normal value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_32, INPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_32 INPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_32, OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_32 OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
tls_crypto_crc_init(&ctx, crckey, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_update(&ctx, in, 1024);
|
||||||
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
|
printf("CRYPTO_CRC_TYPE_32 INPUT_REFLECT | OUTPUT_REFLECT value:0x%08X\n", crcvalue);
|
||||||
|
|
||||||
|
OUT:
|
||||||
|
if(in != NULL)
|
||||||
|
tls_mem_free(in);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int md5_hard_demo(void)
|
||||||
|
{
|
||||||
|
psDigestContext_t ctx;
|
||||||
|
u8 md5hash[16];
|
||||||
|
u8 *md5in1 = (u8 *)"abacdefghgjklmno1234";
|
||||||
|
u8 *md5in2 = (u8 *)"1234567890123456abcd";
|
||||||
|
u8 md5real[16]={0xD6, 0xEB, 0xD1, 0x1B, 0x0D, 0x42, 0x84, 0xE8,
|
||||||
|
0x52, 0x74, 0xA6, 0xA8, 0x2A, 0x3B, 0x2A, 0x12,};
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
|
||||||
|
tls_crypto_md5_init(&ctx);
|
||||||
|
tls_crypto_md5_update(&ctx, md5in1, 20);
|
||||||
|
tls_crypto_md5_update(&ctx, md5in2, 20);
|
||||||
|
tls_crypto_md5_final(&ctx, md5hash);
|
||||||
|
|
||||||
|
if(memcmp(md5hash, md5real, 16))
|
||||||
|
{
|
||||||
|
printf("md5 test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("md5 test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("md5 hash:");
|
||||||
|
// for(int i=0; i<16; i++)
|
||||||
|
// {
|
||||||
|
// printf("0x%02X, ", md5hash[i]);
|
||||||
|
// }
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sha1_hard_demo(void)
|
||||||
|
{
|
||||||
|
psDigestContext_t ctx;
|
||||||
|
u8 sha1hash[20];
|
||||||
|
u8 *sha1in1 = (u8 *)"abacdefghgjklmno1234";
|
||||||
|
u8 *sha1in2 = (u8 *)"1234567890123456abcd";
|
||||||
|
u8 sha1real[20]={0xA9, 0xED, 0x29, 0x56, 0x83, 0x6A, 0x59, 0x22, 0x27, 0x70,
|
||||||
|
0x87, 0x52, 0xDC, 0xB5, 0x1D, 0x2B, 0xBA, 0x93, 0x40, 0xA6,};
|
||||||
|
|
||||||
|
tls_crypto_init();
|
||||||
|
|
||||||
|
tls_crypto_sha1_init(&ctx);
|
||||||
|
tls_crypto_sha1_update(&ctx, sha1in1, 20);
|
||||||
|
tls_crypto_sha1_update(&ctx, sha1in2, 20);
|
||||||
|
tls_crypto_sha1_final(&ctx, sha1hash);
|
||||||
|
|
||||||
|
if(memcmp(sha1hash, sha1real, 16))
|
||||||
|
{
|
||||||
|
printf("sha1 test fail\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("sha1 test success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("sha1 hash:");
|
||||||
|
// for(int i=0; i<20; i++)
|
||||||
|
// {
|
||||||
|
// printf("0x%02X, ", sha1hash[i]);
|
||||||
|
// }
|
||||||
|
// printf("\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int crypt_hard_demo(void)
|
||||||
|
{
|
||||||
|
RNG_hard_demo();
|
||||||
|
rc4_hard_demo();
|
||||||
|
aes_hard_demo();
|
||||||
|
des_hard_demo();
|
||||||
|
des3_hard_demo();
|
||||||
|
crc_hard_demo();
|
||||||
|
md5_hard_demo();
|
||||||
|
sha1_hard_demo();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
165
demo/wm_demo.h
Normal file
165
demo/wm_demo.h
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
#ifndef __WM_DEMO_H__
|
||||||
|
#define __WM_DEMO_H__
|
||||||
|
|
||||||
|
#define DEMO_ON 1
|
||||||
|
#define DEMO_OFF 0
|
||||||
|
|
||||||
|
//demo console
|
||||||
|
#define DEMO_CONSOLE DEMO_OFF
|
||||||
|
|
||||||
|
//socket demo
|
||||||
|
#define DEMO_STD_SOCKET_CLIENT (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
#define DEMO_STD_SOCKET_SERVER (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
#define DEMO_UDP (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//connect demo
|
||||||
|
#define DEMO_CONNECT_NET (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
#define DEMO_SOCKET_CLIENT_SERVER (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//apsta demo
|
||||||
|
#define DEMO_APSTA (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//Uart rx&tx demo
|
||||||
|
#define DEMO_UARTx (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//AP dmeo
|
||||||
|
#define DEMO_SOFT_AP (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//WPS demo
|
||||||
|
#define DEMO_WPS (DEMO_OFF && DEMO_CONSOLE && TLS_CONFIG_WPS && TLS_IEEE8021X_EAPOL)
|
||||||
|
|
||||||
|
//gpio demo
|
||||||
|
#define DEMO_GPIO (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//flash demo
|
||||||
|
#define DEMO_FLASH (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//master spi demo
|
||||||
|
#define DEMO_MASTER_SPI (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//Encryption&Decryption demo
|
||||||
|
#define DEMO_ENCRYPT (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//rsa demo
|
||||||
|
#define DEMO_RSA (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//rtc demo
|
||||||
|
#define DEMO_RTC (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//timer demo
|
||||||
|
#define DEMO_TIMER (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//i2c demo
|
||||||
|
#define DEMO_I2C (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//pwm demo
|
||||||
|
#define DEMO_PWM (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//pmu demo
|
||||||
|
#define DEMO_PMU (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//ntp demo
|
||||||
|
#define DEMO_NTP (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//i2s demo
|
||||||
|
#define DEMO_I2S (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//adc demo
|
||||||
|
#define DEMO_ADC (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//slave spi demo
|
||||||
|
#define DEMO_SLAVE_SPI (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//7816
|
||||||
|
#define DEMO_7816 (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//touch sensor
|
||||||
|
#define DEMO_TOUCHSENSOR (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//LCD
|
||||||
|
#define DEMO_LCD (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
|
||||||
|
//ssl server demo
|
||||||
|
#define DEMO_SSL_SERVER (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//websocket demo
|
||||||
|
#define DEMO_WEBSOCKETS (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
//http demo
|
||||||
|
#define DEMO_HTTP (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
#define DEMO_SCAN (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
#define DEMO_HTTPS (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
#define DEMO_MQTT (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
#define DEMO_SDIO_HOST (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
#define DEMO_FATFS (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
#define DEMO_MBEDTLS (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
|
||||||
|
#define DEMO_DSP (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
#define DEMO_BT (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
#define DEMO_AVOID_COPY (DEMO_OFF && DEMO_CONSOLE)
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// user prio 32 - 60
|
||||||
|
#define DEMO_TASK_PRIO 32
|
||||||
|
#define DEMO_SOCKET_C_TASK_PRIO (DEMO_TASK_PRIO + 1)
|
||||||
|
#define DEMO_SOCKET_S_TASK_PRIO (DEMO_SOCKET_C_TASK_PRIO + 1)
|
||||||
|
#define DEMO_SOCKET_RECEIVE_TASK_PRIO (DEMO_SOCKET_S_TASK_PRIO + 1)
|
||||||
|
#define DEMO_SOCKET_S_SEND_TASK_PRIO (DEMO_SOCKET_RECEIVE_TASK_PRIO + 1)
|
||||||
|
#define DEMO_SOCKET_S_RECEIVE_TASK_PRIO (DEMO_SOCKET_S_SEND_TASK_PRIO + 1)
|
||||||
|
#define DEMO_UDP_TASK_PRIO (DEMO_SOCKET_S_RECEIVE_TASK_PRIO + 1)
|
||||||
|
#define DEMO_UDP_RECEIVE_TASK_PRIO (DEMO_UDP_TASK_PRIO + 1)
|
||||||
|
#define DEMO_MCAST_TASK_PRIO (DEMO_UDP_RECEIVE_TASK_PRIO + 1)
|
||||||
|
#define DEMO_SOCK_FWUP_TASK_PRIO (DEMO_MCAST_TASK_PRIO + 1)
|
||||||
|
#define DEMO_UART_TASK_PRIO (DEMO_SOCK_FWUP_TASK_PRIO + 1)
|
||||||
|
#define DEMO_SSL_SERVER_TASK_PRIO (DEMO_UART_TASK_PRIO + 1)
|
||||||
|
#define DEMO_WEBSOCKETS_TASK_PRIO (DEMO_SSL_SERVER_TASK_PRIO + 1)
|
||||||
|
|
||||||
|
#define DEMO_QUEUE_SIZE 32
|
||||||
|
|
||||||
|
#define DEMO_BUF_SIZE TLS_UART_RX_BUF_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
/*Message Definition used for Demo task*/
|
||||||
|
#define DEMO_MSG_WJOIN_FAILD 1
|
||||||
|
#define DEMO_MSG_WJOIN_SUCCESS 2
|
||||||
|
#define DEMO_MSG_SOCKET_RECEIVE_DATA 3
|
||||||
|
#define DEMO_MSG_UART_RECEIVE_DATA 4
|
||||||
|
#define DEMO_MSG_SOCKET_ERR 5
|
||||||
|
#define DEMO_MSG_SOCKET_CREATE 6
|
||||||
|
#define DEMO_MSG_SOCKET_TEST 7
|
||||||
|
#define DEMO_MSG_OPEN_UART 8
|
||||||
|
#define DEMO_MSG_UART_CMD_DATA 9
|
||||||
|
|
||||||
|
typedef struct demo_sys
|
||||||
|
{
|
||||||
|
char *rxbuf; /*uart rx*/
|
||||||
|
char *txbuf; /*uart tx*/
|
||||||
|
u16 wptr;
|
||||||
|
u16 rptr;
|
||||||
|
u8 dummy1; /*not used*/
|
||||||
|
u8 MsgNum;
|
||||||
|
|
||||||
|
|
||||||
|
bool socket_ok;
|
||||||
|
int socket_num;
|
||||||
|
char *sock_rx;
|
||||||
|
u16 sock_data_len;
|
||||||
|
|
||||||
|
int recvlen; /*socket rx length, used to debug*/
|
||||||
|
int translen; /*socket tx length, used to debug*/
|
||||||
|
u8 dummy2; /*not used*/
|
||||||
|
} ST_Demo_Sys;
|
||||||
|
|
||||||
|
void CreateDemoTask(void);
|
||||||
|
|
||||||
|
extern int wm_printf(const char *fmt,...) ;
|
||||||
|
|
||||||
|
#endif
|
||||||
700
demo/wm_dsp_demo.c
Normal file
700
demo/wm_dsp_demo.c
Normal file
@ -0,0 +1,700 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_adc_demo.c
|
||||||
|
*
|
||||||
|
* Description: adc demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : dave
|
||||||
|
*
|
||||||
|
* Date : 2014-8-18
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "wm_include.h"
|
||||||
|
#if DEMO_DSP
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "csky_math.h"
|
||||||
|
#include "csky_const_structs.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define TAP_NUM 28
|
||||||
|
#define FIR_SIZE 320
|
||||||
|
|
||||||
|
q15_t fir_src[FIR_SIZE] = {
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
0x0000, 0x5e22, 0x3b17, 0xf7bc, 0x0df3, 0x3333, 0x0df3, 0xf7bc,
|
||||||
|
0x3b17, 0x5e22, 0x0000, 0xa1de, 0xc4e9, 0x0844, 0xf20d, 0xcccd,
|
||||||
|
0xf20d, 0x0844, 0xc4e9, 0xa1de, 0x0000, 0x5e22, 0x3b17, 0xf7bc,
|
||||||
|
0x0df3, 0x3333, 0x0df3, 0xf7bc, 0x3b17, 0x5e22, 0x0000, 0xa1de,
|
||||||
|
0xc4e9, 0x0844, 0xf20d, 0xcccd, 0xf20d, 0x0844, 0xc4e9, 0xa1de,
|
||||||
|
};
|
||||||
|
|
||||||
|
q15_t ref_fir_result[FIR_SIZE] = {
|
||||||
|
0x0000, 0x0000, 0x0019, 0x0043, 0x006a, 0x0078, 0x003d, 0xff7a,
|
||||||
|
0xfe41, 0xfd23, 0xfd06, 0xfec8, 0x02e8, 0x092e, 0x108d, 0x1779,
|
||||||
|
0x1cb9, 0x1ff5, 0x2193, 0x2225, 0x21ea, 0x207f, 0x1cec, 0x1641,
|
||||||
|
0x0c68, 0x0078, 0xf43e, 0xe97c, 0xe16e, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
0x24e4, 0x235c, 0x1eab, 0x16c7, 0x0c2b, 0x0000, 0xf3d4, 0xe938,
|
||||||
|
0xe154, 0xdca3, 0xdb1b, 0xdca3, 0xe154, 0xe938, 0xf3d4, 0x0000,
|
||||||
|
0x0c2b, 0x16c7, 0x1eab, 0x235c, 0x24e4, 0x235c, 0x1eab, 0x16c7,
|
||||||
|
0x0c2b, 0x0000, 0xf3d4, 0xe938, 0xe154, 0xdca3, 0xdb1b, 0xdca3,
|
||||||
|
0xe154, 0xe938, 0xf3d4, 0x0000, 0x0c2b, 0x16c7, 0x1eab, 0x235c,
|
||||||
|
};
|
||||||
|
|
||||||
|
q15_t fir_coeffs[FIR_SIZE] = {
|
||||||
|
0x0023, 0x0046, 0x0068, 0x0064, 0x0000, 0xff19, 0xfde3, 0xfd05,
|
||||||
|
0xfd71, 0x0000, 0x04f0, 0x0b97, 0x1272, 0x179d, 0x1989, 0x179d,
|
||||||
|
0x1272, 0x0b97, 0x04f0, 0x0000, 0xfd71, 0xfd05, 0xfde3, 0xff19,
|
||||||
|
0x0000, 0x0064, 0x0068, 0x0046, 0x0023,
|
||||||
|
};
|
||||||
|
|
||||||
|
q15_t fir_states[FIR_SIZE * 2];
|
||||||
|
q15_t fir_result[FIR_SIZE * 2];
|
||||||
|
int dsp_fir_demo(void)
|
||||||
|
{
|
||||||
|
uint16_t tap;
|
||||||
|
uint16_t block_size;
|
||||||
|
csky_fir_instance_q15 S;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
tap = TAP_NUM + 2;
|
||||||
|
block_size = FIR_SIZE;
|
||||||
|
|
||||||
|
csky_fir_init_q15(&S, tap, fir_coeffs, fir_states, block_size);
|
||||||
|
|
||||||
|
csky_fir_q15(&S, fir_src, fir_result, block_size);
|
||||||
|
|
||||||
|
for (i = 0; i < block_size; i++) {
|
||||||
|
if (fir_result[i] != ref_fir_result[i]) {
|
||||||
|
printf("dsp fir run failure!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("dsp fir run success!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define MAT_ROW 16
|
||||||
|
#define MAT_COL 16
|
||||||
|
#define MAT_SIZE 16 * 16
|
||||||
|
|
||||||
|
q31_t data_src0[MAT_SIZE] = {
|
||||||
|
0x3e6386a, 0x5f9e7e7, 0x7b63e96, 0x8d5e856, 0x73be7bf, 0x1248208, 0xd9b2873, 0x692a55c,
|
||||||
|
0x06eb1b7, 0xe24827e, 0x8d6fb14, 0x7d92249, 0x92e74d1, 0xf9d3352, 0x0c4a540, 0x7e4bb61,
|
||||||
|
0xcd4cd29, 0x91fa08c, 0x0378df1, 0x2eed447, 0x79d190d, 0x7b5293b, 0xfa7ecfd, 0x629dc7d,
|
||||||
|
0x9e6d2b1, 0xc29cd59, 0x4d19a1c, 0xb9fe299, 0x9ed99f8, 0xde49a1d, 0x111dca9, 0xdb51116,
|
||||||
|
0x96f0cec, 0x7ccf56b, 0x7e1a5dc, 0x1bca8dd, 0x87ea03e, 0x5984c2c, 0x166011b, 0x4b6a366,
|
||||||
|
0xe1510d0, 0x60a1d7f, 0x2db6aca, 0xe5e3aaf, 0x7b49e39, 0x27d620e, 0x2e2e5db, 0x40bb4a9,
|
||||||
|
0x5372794, 0x6c36f28, 0xf4b22c4, 0xb83b5f1, 0xfe6f0a5, 0xc88fcc5, 0xa55385a, 0x6d01df1,
|
||||||
|
0x5015caf, 0x4e5c4e6, 0x722da46, 0x3252535, 0xff2e3f3, 0x702de6d, 0xdf12aa9, 0x9c2c236,
|
||||||
|
0xe3bbf96, 0x1073675, 0xed1103e, 0xe801f65, 0x5cdb5b7, 0x2eb58ba, 0x67c3bf2, 0xadc8747,
|
||||||
|
0xbe7d11e, 0xf60c07f, 0x97705ab, 0x908c4bf, 0x85bce6b, 0x1ed42f5, 0x9406cbf, 0x18d7f4c,
|
||||||
|
0x467a60f, 0xee744c1, 0xb6953e6, 0x2141a5a, 0xbe2d21e, 0xdbae0c9, 0x23e3c53, 0x047d93a,
|
||||||
|
0x626985f, 0x974943e, 0x688f6ac, 0x3f66bfd, 0x8dc7e78, 0xc868354, 0xf4d366a, 0xee3b7ca,
|
||||||
|
0xadeb220, 0xd67cfb3, 0xb178cc4, 0x0e28a3f, 0x5592bab, 0x7ca73b9, 0xa9b6686, 0x20836ba,
|
||||||
|
0x3670053, 0x1073ebf, 0x028c484, 0xeb9f5cd, 0xa4104e2, 0xb486c22, 0x8c3f7dc, 0x3b10560,
|
||||||
|
0x9bff18a, 0x388154a, 0x552f61d, 0xa0a9057, 0x5047832, 0x9580203, 0x10df843, 0x69c6517,
|
||||||
|
0xe0ce560, 0xaff8533, 0x1d6a51e, 0x4fb27f9, 0x64babb8, 0xf06b175, 0x3cfe690, 0xc2dc710,
|
||||||
|
0x67b874f, 0x837eee6, 0x3a04e39, 0xab5094f, 0x210461a, 0xc0140be, 0x6e7e652, 0x29f9d2d,
|
||||||
|
0xbfb9321, 0x081ccf0, 0xd0ea0ac, 0xe12dcfe, 0xf73ffbf, 0x86f9ded, 0x89ba77f, 0x984550f,
|
||||||
|
0x60588a1, 0xdfc268a, 0x079d69e, 0x80417f7, 0x8092aeb, 0x4fb4696, 0x48795d7, 0xe3a2240,
|
||||||
|
0xc0bb05e, 0xdae376b, 0x93d6383, 0xd1ae6db, 0x0f944ea, 0x604d9dd, 0x74495b2, 0xf37257d,
|
||||||
|
0x7ff267c, 0x6c35193, 0x543ea29, 0xeb0cb21, 0xe135968, 0x959cc0a, 0x2f89313, 0x3d71230,
|
||||||
|
0x446a138, 0xd095a6d, 0x59c1d7e, 0x7c6dd7b, 0xfe94b0f, 0x1c2f016, 0x3e0c1d0, 0x23dbec5,
|
||||||
|
0x5d3fcb8, 0x0be6171, 0x030a33e, 0xfd0d65b, 0x678721b, 0x0800428, 0xf75a25a, 0x515084a,
|
||||||
|
0x8cc3bf9, 0x3a0bba9, 0xa4ffb72, 0x37dab42, 0x915a63c, 0xb41ea15, 0x6ffcb1e, 0xa1cd4bc,
|
||||||
|
0x8970ce2, 0xf950a66, 0x0d4d5f1, 0xa8ed2a1, 0x2e2b86d, 0x4cf5a0a, 0xc2a434e, 0x19b0324,
|
||||||
|
0x2f6f125, 0x0409b0a, 0xded8282, 0xe9c6627, 0x65cc29e, 0x051944d, 0x036bd27, 0xf3ec2bb,
|
||||||
|
0x0b704ef, 0xff1d11d, 0xb699d6b, 0x2ab5eed, 0xe0fa8d7, 0x3d23851, 0x11bb8f1, 0x95c25e1,
|
||||||
|
0x1eca8c0, 0x4a67b43, 0x1f550b8, 0x993fd4c, 0xc9df6a8, 0x8dc76df, 0xbdabefd, 0x26f68d8,
|
||||||
|
0x7f63c62, 0xcf18ba9, 0x167b699, 0x84966de, 0x21c7c8a, 0xa444066, 0xbfaf6f2, 0x6c1fa76,
|
||||||
|
0x3f26b95, 0xb459a03, 0x7f5f8fb, 0x3c0c111, 0xc4e0408, 0x5cb850c, 0xc28d15a, 0x53b629a,
|
||||||
|
0x02d16e2, 0x736a171, 0xa48c217, 0x9ea30b4, 0xbe46e95, 0xf019d68, 0xd1bdbfc, 0x8db8962,
|
||||||
|
0x7a2d6d1, 0x2d985c2, 0x0470aa4, 0x2326814, 0x181d1c0, 0xf1642a9, 0x424c217, 0xcede20d,
|
||||||
|
};
|
||||||
|
|
||||||
|
q31_t data_src1[MAT_SIZE] = {
|
||||||
|
0xe7014cad, 0xfabb35de, 0x6a5caca5, 0x3aa21c61, 0x0434ea19, 0x356daa70, 0x003d994e, 0x5ef41f8b,
|
||||||
|
0xbfbb5627, 0x3d063e39, 0xd8bdf7e0, 0x83c78d29, 0xd46c70ba, 0x055674ed, 0x5d795568, 0x49f050a0,
|
||||||
|
0x625cfbc9, 0x10a3957e, 0x6545d05e, 0xb3dea603, 0x81ec0157, 0x7e308eef, 0xd4fdc98d, 0x390c46b0,
|
||||||
|
0xe2ec9acb, 0x79f7e096, 0xd5a99db7, 0x33e864e8, 0xb448c9f4, 0xb8157431, 0x916a4352, 0xf918893d,
|
||||||
|
0x33592dc4, 0xfd57b242, 0xfb858dbe, 0xb75de09d, 0x305defda, 0xa9980f16, 0xac839aff, 0x2b07adfb,
|
||||||
|
0xee726af2, 0x05f6ed55, 0x131a1233, 0x01ba2e6b, 0x44682f5a, 0x57a6bbd2, 0x77f2a072, 0x542c591e,
|
||||||
|
0xbdeb57bd, 0xc512600a, 0xf157683d, 0x79f10f0b, 0x722e642e, 0x9d12aeff, 0x2029b4ef, 0xadc7a880,
|
||||||
|
0x54b4fa07, 0xee0eede1, 0x5d2b046a, 0xe19aa7b0, 0x91e9c2a2, 0x29b5f89c, 0x994817fa, 0xd28e2742,
|
||||||
|
0x4284567f, 0x7d5f9c26, 0xcfcf2c2c, 0x17de4d07, 0x5fa015d0, 0x69b23434, 0x133c0952, 0x0ced437a,
|
||||||
|
0x531c0dd1, 0xb5084fe6, 0xb2d5078d, 0x909f5a63, 0x73356cc1, 0x50f4cbb0, 0x0c06b0ba, 0x79e4bd45,
|
||||||
|
0xca7a1bef, 0xaf055ed5, 0x8e290b1a, 0xcded6495, 0x9cffaf83, 0xfb4ddf33, 0x40409402, 0x75ba5f87,
|
||||||
|
0xf3f7b791, 0xd2ca6ecc, 0x2c25bf11, 0xdbcbe574, 0xa8806fbc, 0x4b3b8ff9, 0xe7290934, 0xc738d6b7,
|
||||||
|
0xc7063951, 0x5c9588fe, 0x40f87f67, 0x77bb604c, 0xdac50e6d, 0x5a0ff472, 0xa74d0210, 0x1894e055,
|
||||||
|
0xe16c642c, 0x9c61fd9a, 0x66de6bb5, 0xbbf7e3b2, 0xc954842c, 0xf8174754, 0x9b66fbcf, 0x92a50a25,
|
||||||
|
0x819047ee, 0x885a9bb6, 0xa1c74f5e, 0x655e4761, 0xbdef9277, 0x4f5682d1, 0xdb5667dd, 0x4efe7d6f,
|
||||||
|
0x6d05b888, 0xe00dc420, 0xb2fbf70e, 0xb418d774, 0x2fe7b194, 0xcf3d0770, 0x3962f443, 0x405030b3,
|
||||||
|
0xdfed11c1, 0xd4fb3366, 0xdb1db645, 0xb0a58278, 0x0f7200f9, 0xafcf7937, 0xa4d9f5ab, 0x7c0a4ffa,
|
||||||
|
0x3da7ed8f, 0xd4749651, 0xcc5c599c, 0x5053dbd8, 0xa4226514, 0x3005318d, 0x1d1a494f, 0x54c8c706,
|
||||||
|
0xefdad3a4, 0x3fade214, 0xe557ccac, 0x8075eba5, 0x1cdbaf08, 0xbf487d64, 0x59c16c5d, 0x62cbf1d1,
|
||||||
|
0x3cd58567, 0xd794345e, 0xff1bf3d3, 0xe4b82129, 0x03181c59, 0x7ca258e9, 0x48709a7d, 0x6c1e596b,
|
||||||
|
0xcde68124, 0x24f53341, 0x62b184e8, 0x36362666, 0xcd01d317, 0x8ddf51e5, 0xd67ea19d, 0xb6be0597,
|
||||||
|
0x72691640, 0x512eb377, 0x63d0c384, 0x8db71a37, 0x38a8e1aa, 0x451a62f1, 0x110e0be7, 0xd3b7dd35,
|
||||||
|
0xca75d298, 0xab532ddb, 0x856ff47f, 0x5e2357c4, 0x4c5303f0, 0x1be4e5e4, 0xc6734701, 0x88dd8405,
|
||||||
|
0x0295e4f1, 0x081c875c, 0x005cb4e1, 0xe0036157, 0x6dc8cb79, 0x545f690e, 0x4fb29cc5, 0x4dd77bb2,
|
||||||
|
0xbe158c7f, 0x73c3b6a7, 0x5815ac8c, 0x9e496d5c, 0x4baf2b6e, 0x46f8b459, 0x8189ef65, 0xf37cd94b,
|
||||||
|
0x4ab89822, 0x0568412c, 0xc6e928f5, 0x466604b7, 0x3b6b286d, 0x34c1f8a0, 0x13a79531, 0x09cac61b,
|
||||||
|
0x6fca7f40, 0x0b13c216, 0xc9beff6a, 0x89fd68e9, 0x47f5a9a9, 0x02d5189d, 0x4d4a1a4f, 0x83880a42,
|
||||||
|
0xf3c1a485, 0x4639293d, 0x08b17bb3, 0xaa50f1e4, 0x3ff60a36, 0x1867f7b0, 0x71abe5b2, 0xf69a7e42,
|
||||||
|
0x5c356d79, 0xc05ca232, 0xc016789d, 0x192346c3, 0xd9e1963d, 0x871aa13a, 0xff56263c, 0xf9451b8f,
|
||||||
|
0x59651625, 0x9ec98a7b, 0x130204cd, 0x69872d7a, 0xe84618f6, 0x40bc5bbc, 0x5f177cf0, 0x521cb03e,
|
||||||
|
0xe5b0c054, 0x141d509d, 0xfd0672a0, 0x1ab44a37, 0x8de66e6f, 0x7d89e3cb, 0x09b01186, 0x7381a70d,
|
||||||
|
0xe3f3465c, 0x201d804c, 0xe9ad8c9d, 0xd1b7785a, 0xbd4f53e8, 0xff292fb5, 0x01f237e3, 0x73b02511,
|
||||||
|
};
|
||||||
|
|
||||||
|
q31_t ref_maxtrix_result[MAT_SIZE] = {
|
||||||
|
0xf84cf2b8, 0x1536ab68, 0x0061195f, 0xfca81fb9, 0x0d8c7a53, 0x0dec5e3b, 0xf5b41d95, 0x00e59e7f,
|
||||||
|
0x1a13101c, 0x01a576bf, 0x09c49345, 0xd6ada1e7, 0x0c86111d, 0x25d80f60, 0x14aa5962, 0x170e1386,
|
||||||
|
0xf0f7277b, 0x0facf024, 0xfe83bde7, 0xfc111eca, 0xfc37a520, 0x24e81ef3, 0xf040feca, 0x1dae7005,
|
||||||
|
0x106d63a3, 0x00c1d77f, 0xfc26b982, 0xd645e218, 0xfa88c2d8, 0x238eda3f, 0x14e584dd, 0x229fad0f,
|
||||||
|
0xf73fceba, 0xfd06a467, 0xf471a945, 0xf7900747, 0x08503d1d, 0x09f5056a, 0xe775f417, 0x18d09235,
|
||||||
|
0x141df628, 0xff60a630, 0xf1106a9c, 0xf216269b, 0x05af82e7, 0x24038a0e, 0x1c6a2b02, 0x2c7827f9,
|
||||||
|
0xfc079d2f, 0x0e2a1cac, 0xf7c4f82d, 0xfd449c9a, 0x067b85a1, 0x07e663c3, 0xe782b934, 0x19450c43,
|
||||||
|
0x294479db, 0xee67427d, 0x0304fab1, 0xe738de98, 0x01fe89f6, 0x344db25a, 0x170d4b73, 0x2629a60f,
|
||||||
|
0xe7f74143, 0xfab77a1d, 0xf94564df, 0x07db2ce5, 0x14fb02da, 0xe97bf82b, 0xe88aeab7, 0x19b55658,
|
||||||
|
0x2be1c0f4, 0xf2ad8359, 0x043f4db4, 0xe374b9b4, 0x0099d99e, 0x36b8b1c8, 0x27b15277, 0x2fd76638,
|
||||||
|
0x14a583e6, 0x0a9c6ade, 0xf55dafb8, 0xe0121d67, 0xf22de778, 0x0a077139, 0xf9543d5e, 0x2042689d,
|
||||||
|
0x191eb6fd, 0x0197d477, 0xfb45ee66, 0xf095bf67, 0xfc56d6aa, 0x2efad848, 0x1e58f161, 0x2f33a504,
|
||||||
|
0x07e3ca2a, 0x02e27143, 0xfcbbda44, 0xf90fb8bb, 0x01d5a9af, 0x18209af4, 0xe5d3e3e9, 0x09628ecd,
|
||||||
|
0x05492aa2, 0x042596a8, 0xfceed6b0, 0xef330357, 0x066391aa, 0x1e31ea2d, 0x1a506d4e, 0x1b121669,
|
||||||
|
0xf7e03a16, 0xf9e8a6ff, 0xed1d7f79, 0xedd0db2b, 0x07346730, 0x02165c02, 0xff541fa3, 0x1d822d7b,
|
||||||
|
0x17f22337, 0x000b151d, 0xf95ec677, 0xe5e6026f, 0xf399bf33, 0x26fc6384, 0x1fe2eadd, 0x2a40af9f,
|
||||||
|
0xecf46eb9, 0xfb5f785b, 0xfc3a9f77, 0x027fa05e, 0xff8434d1, 0x01743688, 0xe2237bdf, 0x06dc8386,
|
||||||
|
0x205f0c32, 0x042e03fd, 0x092defb6, 0xeee00701, 0xf7712120, 0x2a24dd5b, 0x0ff86daf, 0x150940a5,
|
||||||
|
0xf0ab2782, 0xf5809187, 0xede587a2, 0x079f5995, 0xf0257e93, 0x1120c0bd, 0xf56c7863, 0x20e6a923,
|
||||||
|
0x2562e598, 0x0177958f, 0xf8131c3e, 0xe0ccfab1, 0xf774ac44, 0x223bddc1, 0x13eeba7f, 0x33444b3d,
|
||||||
|
0xeff739fc, 0x0e993e2f, 0xfc5754a5, 0xfb594b61, 0x163c5888, 0x05aabf1d, 0xf3ec9689, 0x108cb049,
|
||||||
|
0x27089a02, 0xf75c5b20, 0xfd64fcb9, 0xe7ba2bb1, 0x02ae58e8, 0x30f8b69a, 0x0ce60bfa, 0x2161ef2c,
|
||||||
|
0xee8e1ccb, 0x0bd7307d, 0x03e8273a, 0x14b8452b, 0x0b6bc589, 0x02fae097, 0xee953972, 0x00e02004,
|
||||||
|
0x2248a558, 0xf66ae246, 0x0f9c419d, 0xe02205e3, 0xf5770a0b, 0x1eab85bd, 0x0615fb78, 0x0e1154d9,
|
||||||
|
0xeb5a27f3, 0x056ea40d, 0x117b1f5b, 0x1c30094d, 0xee99d7e7, 0x1d0d8e17, 0xe4e39e5d, 0x092b35f2,
|
||||||
|
0x0db00686, 0x1105b2f9, 0x0d030c67, 0xdfde0a2b, 0xf1a4520a, 0x1419f876, 0xf508dd03, 0x0c922ec4,
|
||||||
|
0x0eb917cf, 0x068c4417, 0xf34053fd, 0xef91c79d, 0x065c4b00, 0x13787a20, 0xea690bec, 0x07d34771,
|
||||||
|
0x200afc48, 0xffa2d732, 0xef4ef2e2, 0xf7cfd288, 0x15d56d20, 0x20c05f13, 0x1b2604f7, 0x2a082b91,
|
||||||
|
0xf4c935d6, 0x05efad6c, 0x05eaf1bc, 0xfd2db7fc, 0xf26e9f00, 0x08dc79c5, 0xf0909be5, 0x18abe97e,
|
||||||
|
0x1e13c538, 0xfb5266de, 0x07b1f059, 0xef81f822, 0xef5c9ba0, 0x204c0736, 0x07f0f4d9, 0x11354ca9,
|
||||||
|
0xff4393b6, 0xffa0b5d3, 0xe6420adf, 0xfda29512, 0xf9e6c712, 0x14819176, 0xfb1eaf40, 0x1b72bdfe,
|
||||||
|
0x12f85bde, 0xf29fc5c3, 0x055bc5ad, 0xde95cfd6, 0xf422392f, 0x1f219940, 0x091c01c1, 0x16ee7cf2,
|
||||||
|
};
|
||||||
|
|
||||||
|
q31_t maxtrix_result[MAT_SIZE];
|
||||||
|
int dsp_matrix_demo(void)
|
||||||
|
{
|
||||||
|
csky_matrix_instance_q31 src0;
|
||||||
|
csky_matrix_instance_q31 src1;
|
||||||
|
csky_matrix_instance_q31 dst;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
csky_mat_init_q31(&src0, MAT_ROW, MAT_COL, data_src0);
|
||||||
|
csky_mat_init_q31(&src1, MAT_ROW, MAT_COL, data_src1);
|
||||||
|
csky_mat_init_q31(&dst, MAT_ROW, MAT_COL, maxtrix_result);
|
||||||
|
|
||||||
|
csky_mat_mult_q31(&src0, &src1, &dst);
|
||||||
|
|
||||||
|
for (i = 0; i < MAT_SIZE; i++) {
|
||||||
|
if (maxtrix_result[i] != ref_maxtrix_result[i]) {
|
||||||
|
printf("dsp matrix cal run failure!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("dsp matrix cal run success!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define RFFT_TEST_SIZE 1024
|
||||||
|
|
||||||
|
q15_t rfft_src[RFFT_TEST_SIZE] = {
|
||||||
|
0x4000, 0x44d9, 0x43e0, 0x3dc9, 0x33bb, 0x2735, 0x19e9, 0x0d90,
|
||||||
|
0x03be, 0xfdbe, 0xfc6f, 0x002d, 0x08cc, 0x1596, 0x255f, 0x36a1,
|
||||||
|
0x479d, 0x568c, 0x61c2, 0x67de, 0x67e9, 0x616d, 0x5488, 0x41e2,
|
||||||
|
0x2aa8, 0x106c, 0xf506, 0xda68, 0xc271, 0xaec5, 0xa0a7, 0x98dc,
|
||||||
|
0x979e, 0x9c93, 0xa6de, 0xb52e, 0xc5e5, 0xd73e, 0xe774, 0xf4f2,
|
||||||
|
0xfe79, 0x033a, 0x02ea, 0xfdcc, 0xf4a7, 0xe8b0, 0xdb72, 0xcea1,
|
||||||
|
0xc3f4, 0xbcf7, 0xbae6, 0xbe8d, 0xc831, 0xd789, 0xebc2, 0x038f,
|
||||||
|
0x1d49, 0x370f, 0x4ef7, 0x6337, 0x724c, 0x7b21, 0x7d24, 0x7854,
|
||||||
|
0x6d41, 0x5cfe, 0x4906, 0x3319, 0x1d14, 0x08c4, 0xf7bc, 0xeb31,
|
||||||
|
0xe3dd, 0xe1f4, 0xe519, 0xec73, 0xf6b9, 0x025b, 0x0da4, 0x16ec,
|
||||||
|
0x1cb9, 0x1dec, 0x19db, 0x1063, 0x01ef, 0xef6c, 0xda38, 0xc404,
|
||||||
|
0xaea7, 0x9bf7, 0x8d9f, 0x84f4, 0x82d5, 0x879b, 0x9309, 0xa457,
|
||||||
|
0xba41, 0xd322, 0xed1f, 0x064a, 0x1cd8, 0x2f3f, 0x3c61, 0x43a0,
|
||||||
|
0x44ee, 0x40c6, 0x3823, 0x2c68, 0x1f36, 0x1248, 0x0746, 0xff9e,
|
||||||
|
0xfc5c, 0xfe12, 0x04cc, 0x1009, 0x1eca, 0x2fa8, 0x40f8, 0x50ee,
|
||||||
|
0x5dd1, 0x661c, 0x68a9, 0x64cf, 0x5a6e, 0x49f8, 0x3467, 0x1b2a,
|
||||||
|
0x0000, 0xe4d6, 0xcb99, 0xb608, 0xa592, 0x9b31, 0x9757, 0x99e4,
|
||||||
|
0xa22f, 0xaf12, 0xbf08, 0xd058, 0xe136, 0xeff7, 0xfb34, 0x01ee,
|
||||||
|
0x03a4, 0x0062, 0xf8ba, 0xedb8, 0xe0ca, 0xd398, 0xc7dd, 0xbf3a,
|
||||||
|
0xbb12, 0xbc60, 0xc39f, 0xd0c1, 0xe328, 0xf9b6, 0x12e1, 0x2cde,
|
||||||
|
0x45bf, 0x5ba9, 0x6cf7, 0x7865, 0x7d2b, 0x7b0c, 0x7261, 0x6409,
|
||||||
|
0x5159, 0x3bfc, 0x25c8, 0x1094, 0xfe11, 0xef9d, 0xe625, 0xe214,
|
||||||
|
0xe347, 0xe914, 0xf25c, 0xfda5, 0x0947, 0x138d, 0x1ae7, 0x1e0c,
|
||||||
|
0x1c23, 0x14cf, 0x0844, 0xf73c, 0xe2ec, 0xcce7, 0xb6fa, 0xa302,
|
||||||
|
0x92bf, 0x87ac, 0x82dc, 0x84df, 0x8db4, 0x9cc9, 0xb109, 0xc8f1,
|
||||||
|
0xe2b7, 0xfc71, 0x143e, 0x2877, 0x37cf, 0x4173, 0x451a, 0x4309,
|
||||||
|
0x3c0c, 0x315f, 0x248e, 0x1750, 0x0b59, 0x0234, 0xfd16, 0xfcc6,
|
||||||
|
0x0187, 0x0b0e, 0x188c, 0x28c2, 0x3a1b, 0x4ad2, 0x5922, 0x636d,
|
||||||
|
0x6862, 0x6724, 0x5f59, 0x513b, 0x3d8f, 0x2598, 0x0afa, 0xef94,
|
||||||
|
0xd558, 0xbe1e, 0xab78, 0x9e93, 0x9817, 0x9822, 0x9e3e, 0xa974,
|
||||||
|
0xb863, 0xc95f, 0xdaa1, 0xea6a, 0xf734, 0xffd3, 0x0391, 0x0242,
|
||||||
|
0xfc42, 0xf270, 0xe617, 0xd8cb, 0xcc45, 0xc237, 0xbc20, 0xbb27,
|
||||||
|
0xc000, 0xcad3, 0xdb3a, 0xf048, 0x089c, 0x227f, 0x3c0d, 0x535d,
|
||||||
|
0x66b0, 0x7497, 0x7c16, 0x7cb7, 0x7696, 0x6a60, 0x593e, 0x44bc,
|
||||||
|
0x2ea4, 0x18d3, 0x050e, 0xf4d6, 0xe94b, 0xe30d, 0xe232, 0xe645,
|
||||||
|
0xee51, 0xf8fe, 0x04b2, 0x0fb6, 0x1867, 0x1d5c, 0x1d8b, 0x1864,
|
||||||
|
0x0de0, 0xfe84, 0xeb58, 0xd5cd, 0xbf9e, 0xaaa5, 0x98b4, 0x8b66,
|
||||||
|
0x83fc, 0x833c, 0x8960, 0x960f, 0xa867, 0xbf0d, 0xd84e, 0xf248,
|
||||||
|
0x0b11, 0x20e6, 0x3252, 0x3e4f, 0x445b, 0x4482, 0x3f5d, 0x35fe,
|
||||||
|
0x29d4, 0x1c8c, 0x0fe0, 0x0570, 0xfe96, 0xfc4b, 0xff06, 0x06b6,
|
||||||
|
0x12bf, 0x220b, 0x3324, 0x4453, 0x53ce, 0x5fe2, 0x671b, 0x686a,
|
||||||
|
0x6340, 0x5799, 0x4606, 0x2f99, 0x15d3, 0xfa81, 0xdf93, 0xc6f0,
|
||||||
|
0xb24b, 0xa2fd, 0x99e5, 0x975a, 0x9b1f, 0xa470, 0xb212, 0xc272,
|
||||||
|
0xd3cf, 0xe461, 0xf288, 0xfcef, 0x02ae, 0x0361, 0xff2d, 0xf6c0,
|
||||||
|
0xeb3d, 0xde1e, 0xd113, 0xc5d7, 0xbe00, 0xbadf, 0xbd57, 0xc5ca,
|
||||||
|
0xd40b, 0xe761, 0xfe97, 0x1813, 0x31fe, 0x4a6c, 0x5f89, 0x6fc1,
|
||||||
|
0x79e6, 0x7d4b, 0x79d1, 0x6fed, 0x6098, 0x4d3c, 0x378d, 0x2167,
|
||||||
|
0x0c9d, 0xfad1, 0xed4c, 0xe4e5, 0xe1e9, 0xe41a, 0xeab3, 0xf482,
|
||||||
|
0x0000, 0x0b7e, 0x154d, 0x1be6, 0x1e17, 0x1b1b, 0x12b4, 0x052f,
|
||||||
|
0xf363, 0xde99, 0xc873, 0xb2c4, 0x9f68, 0x9013, 0x862f, 0x82b5,
|
||||||
|
0x861a, 0x903f, 0xa077, 0xb594, 0xce02, 0xe7ed, 0x0169, 0x189f,
|
||||||
|
0x2bf5, 0x3a36, 0x42a9, 0x4521, 0x4200, 0x3a29, 0x2eed, 0x21e2,
|
||||||
|
0x14c3, 0x0940, 0x00d3, 0xfc9f, 0xfd52, 0x0311, 0x0d78, 0x1b9f,
|
||||||
|
0x2c31, 0x3d8e, 0x4dee, 0x5b90, 0x64e1, 0x68a6, 0x661b, 0x5d03,
|
||||||
|
0x4db5, 0x3910, 0x206d, 0x057f, 0xea2d, 0xd067, 0xb9fa, 0xa867,
|
||||||
|
0x9cc0, 0x9796, 0x98e5, 0xa01e, 0xac32, 0xbbad, 0xccdc, 0xddf5,
|
||||||
|
0xed41, 0xf94a, 0x00fa, 0x03b5, 0x016a, 0xfa90, 0xf020, 0xe374,
|
||||||
|
0xd62c, 0xca02, 0xc0a3, 0xbb7e, 0xbba5, 0xc1b1, 0xcdae, 0xdf1a,
|
||||||
|
0xf4ef, 0x0db8, 0x27b2, 0x40f3, 0x5799, 0x69f1, 0x76a0, 0x7cc4,
|
||||||
|
0x7c04, 0x749a, 0x674c, 0x555b, 0x4062, 0x2a33, 0x14a8, 0x017c,
|
||||||
|
0xf220, 0xe79c, 0xe275, 0xe2a4, 0xe799, 0xf04a, 0xfb4e, 0x0702,
|
||||||
|
0x11af, 0x19bb, 0x1dce, 0x1cf3, 0x16b5, 0x0b2a, 0xfaf2, 0xe72d,
|
||||||
|
0xd15c, 0xbb44, 0xa6c2, 0x95a0, 0x896a, 0x8349, 0x83ea, 0x8b69,
|
||||||
|
0x9950, 0xaca3, 0xc3f3, 0xdd81, 0xf764, 0x0fb8, 0x24c6, 0x352d,
|
||||||
|
0x4000, 0x44d9, 0x43e0, 0x3dc9, 0x33bb, 0x2735, 0x19e9, 0x0d90,
|
||||||
|
0x03be, 0xfdbe, 0xfc6f, 0x002d, 0x08cc, 0x1596, 0x255f, 0x36a1,
|
||||||
|
0x479d, 0x568c, 0x61c2, 0x67de, 0x67e9, 0x616d, 0x5488, 0x41e2,
|
||||||
|
0x2aa8, 0x106c, 0xf506, 0xda68, 0xc271, 0xaec5, 0xa0a7, 0x98dc,
|
||||||
|
0x979e, 0x9c93, 0xa6de, 0xb52e, 0xc5e5, 0xd73e, 0xe774, 0xf4f2,
|
||||||
|
0xfe79, 0x033a, 0x02ea, 0xfdcc, 0xf4a7, 0xe8b0, 0xdb72, 0xcea1,
|
||||||
|
0xc3f4, 0xbcf7, 0xbae6, 0xbe8d, 0xc831, 0xd789, 0xebc2, 0x038f,
|
||||||
|
0x1d49, 0x370f, 0x4ef7, 0x6337, 0x724c, 0x7b21, 0x7d24, 0x7854,
|
||||||
|
0x6d41, 0x5cfe, 0x4906, 0x3319, 0x1d14, 0x08c4, 0xf7bc, 0xeb31,
|
||||||
|
0xe3dd, 0xe1f4, 0xe519, 0xec73, 0xf6b9, 0x025b, 0x0da4, 0x16ec,
|
||||||
|
0x1cb9, 0x1dec, 0x19db, 0x1063, 0x01ef, 0xef6c, 0xda38, 0xc404,
|
||||||
|
0xaea7, 0x9bf7, 0x8d9f, 0x84f4, 0x82d5, 0x879b, 0x9309, 0xa457,
|
||||||
|
0xba41, 0xd322, 0xed1f, 0x064a, 0x1cd8, 0x2f3f, 0x3c61, 0x43a0,
|
||||||
|
0x44ee, 0x40c6, 0x3823, 0x2c68, 0x1f36, 0x1248, 0x0746, 0xff9e,
|
||||||
|
0xfc5c, 0xfe12, 0x04cc, 0x1009, 0x1eca, 0x2fa8, 0x40f8, 0x50ee,
|
||||||
|
0x5dd1, 0x661c, 0x68a9, 0x64cf, 0x5a6e, 0x49f8, 0x3467, 0x1b2a,
|
||||||
|
0x0000, 0xe4d6, 0xcb99, 0xb608, 0xa592, 0x9b31, 0x9757, 0x99e4,
|
||||||
|
0xa22f, 0xaf12, 0xbf08, 0xd058, 0xe136, 0xeff7, 0xfb34, 0x01ee,
|
||||||
|
0x03a4, 0x0062, 0xf8ba, 0xedb8, 0xe0ca, 0xd398, 0xc7dd, 0xbf3a,
|
||||||
|
0xbb12, 0xbc60, 0xc39f, 0xd0c1, 0xe328, 0xf9b6, 0x12e1, 0x2cde,
|
||||||
|
0x45bf, 0x5ba9, 0x6cf7, 0x7865, 0x7d2b, 0x7b0c, 0x7261, 0x6409,
|
||||||
|
0x5159, 0x3bfc, 0x25c8, 0x1094, 0xfe11, 0xef9d, 0xe625, 0xe214,
|
||||||
|
0xe347, 0xe914, 0xf25c, 0xfda5, 0x0947, 0x138d, 0x1ae7, 0x1e0c,
|
||||||
|
0x1c23, 0x14cf, 0x0844, 0xf73c, 0xe2ec, 0xcce7, 0xb6fa, 0xa302,
|
||||||
|
0x92bf, 0x87ac, 0x82dc, 0x84df, 0x8db4, 0x9cc9, 0xb109, 0xc8f1,
|
||||||
|
0xe2b7, 0xfc71, 0x143e, 0x2877, 0x37cf, 0x4173, 0x451a, 0x4309,
|
||||||
|
0x3c0c, 0x315f, 0x248e, 0x1750, 0x0b59, 0x0234, 0xfd16, 0xfcc6,
|
||||||
|
0x0187, 0x0b0e, 0x188c, 0x28c2, 0x3a1b, 0x4ad2, 0x5922, 0x636d,
|
||||||
|
0x6862, 0x6724, 0x5f59, 0x513b, 0x3d8f, 0x2598, 0x0afa, 0xef94,
|
||||||
|
0xd558, 0xbe1e, 0xab78, 0x9e93, 0x9817, 0x9822, 0x9e3e, 0xa974,
|
||||||
|
0xb863, 0xc95f, 0xdaa1, 0xea6a, 0xf734, 0xffd3, 0x0391, 0x0242,
|
||||||
|
0xfc42, 0xf270, 0xe617, 0xd8cb, 0xcc45, 0xc237, 0xbc20, 0xbb27,
|
||||||
|
0xc000, 0xcad3, 0xdb3a, 0xf048, 0x089c, 0x227f, 0x3c0d, 0x535d,
|
||||||
|
0x66b0, 0x7497, 0x7c16, 0x7cb7, 0x7696, 0x6a60, 0x593e, 0x44bc,
|
||||||
|
0x2ea4, 0x18d3, 0x050e, 0xf4d6, 0xe94b, 0xe30d, 0xe232, 0xe645,
|
||||||
|
0xee51, 0xf8fe, 0x04b2, 0x0fb6, 0x1867, 0x1d5c, 0x1d8b, 0x1864,
|
||||||
|
0x0de0, 0xfe84, 0xeb58, 0xd5cd, 0xbf9e, 0xaaa5, 0x98b4, 0x8b66,
|
||||||
|
0x83fc, 0x833c, 0x8960, 0x960f, 0xa867, 0xbf0d, 0xd84e, 0xf248,
|
||||||
|
0x0b11, 0x20e6, 0x3252, 0x3e4f, 0x445b, 0x4482, 0x3f5d, 0x35fe,
|
||||||
|
0x29d4, 0x1c8c, 0x0fe0, 0x0570, 0xfe96, 0xfc4b, 0xff06, 0x06b6,
|
||||||
|
0x12bf, 0x220b, 0x3324, 0x4453, 0x53ce, 0x5fe2, 0x671b, 0x686a,
|
||||||
|
0x6340, 0x5799, 0x4606, 0x2f99, 0x15d3, 0xfa81, 0xdf93, 0xc6f0,
|
||||||
|
0xb24b, 0xa2fd, 0x99e5, 0x975a, 0x9b1f, 0xa470, 0xb212, 0xc272,
|
||||||
|
0xd3cf, 0xe461, 0xf288, 0xfcef, 0x02ae, 0x0361, 0xff2d, 0xf6c0,
|
||||||
|
0xeb3d, 0xde1e, 0xd113, 0xc5d7, 0xbe00, 0xbadf, 0xbd57, 0xc5ca,
|
||||||
|
0xd40b, 0xe761, 0xfe97, 0x1813, 0x31fe, 0x4a6c, 0x5f89, 0x6fc1,
|
||||||
|
0x79e6, 0x7d4b, 0x79d1, 0x6fed, 0x6098, 0x4d3c, 0x378d, 0x2167,
|
||||||
|
0x0c9d, 0xfad1, 0xed4c, 0xe4e5, 0xe1e9, 0xe41a, 0xeab3, 0xf482,
|
||||||
|
0x0000, 0x0b7e, 0x154d, 0x1be6, 0x1e17, 0x1b1b, 0x12b4, 0x052f,
|
||||||
|
0xf363, 0xde99, 0xc873, 0xb2c4, 0x9f68, 0x9013, 0x862f, 0x82b5,
|
||||||
|
0x861a, 0x903f, 0xa077, 0xb594, 0xce02, 0xe7ed, 0x0169, 0x189f,
|
||||||
|
0x2bf5, 0x3a36, 0x42a9, 0x4521, 0x4200, 0x3a29, 0x2eed, 0x21e2,
|
||||||
|
0x14c3, 0x0940, 0x00d3, 0xfc9f, 0xfd52, 0x0311, 0x0d78, 0x1b9f,
|
||||||
|
0x2c31, 0x3d8e, 0x4dee, 0x5b90, 0x64e1, 0x68a6, 0x661b, 0x5d03,
|
||||||
|
0x4db5, 0x3910, 0x206d, 0x057f, 0xea2d, 0xd067, 0xb9fa, 0xa867,
|
||||||
|
0x9cc0, 0x9796, 0x98e5, 0xa01e, 0xac32, 0xbbad, 0xccdc, 0xddf5,
|
||||||
|
0xed41, 0xf94a, 0x00fa, 0x03b5, 0x016a, 0xfa90, 0xf020, 0xe374,
|
||||||
|
0xd62c, 0xca02, 0xc0a3, 0xbb7e, 0xbba5, 0xc1b1, 0xcdae, 0xdf1a,
|
||||||
|
0xf4ef, 0x0db8, 0x27b2, 0x40f3, 0x5799, 0x69f1, 0x76a0, 0x7cc4,
|
||||||
|
0x7c04, 0x749a, 0x674c, 0x555b, 0x4062, 0x2a33, 0x14a8, 0x017c,
|
||||||
|
0xf220, 0xe79c, 0xe275, 0xe2a4, 0xe799, 0xf04a, 0xfb4e, 0x0702,
|
||||||
|
0x11af, 0x19bb, 0x1dce, 0x1cf3, 0x16b5, 0x0b2a, 0xfaf2, 0xe72d,
|
||||||
|
0xd15c, 0xbb44, 0xa6c2, 0x95a0, 0x896a, 0x8349, 0x83ea, 0x8b69,
|
||||||
|
0x9950, 0xaca3, 0xc3f3, 0xdd81, 0xf764, 0x0fb8, 0x24c6, 0x352d,
|
||||||
|
};
|
||||||
|
|
||||||
|
q15_t ref_rfft_result[RFFT_TEST_SIZE + 2] = {
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0xe000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x2000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||||
|
0x0000, 0x0000,
|
||||||
|
};
|
||||||
|
|
||||||
|
static q15_t rfft_srcdata[RFFT_TEST_SIZE + 2]; /*use local variable to store rfft_src,because rfft process will change the srcdata*/
|
||||||
|
int dsp_rfft_demo(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int err;
|
||||||
|
q15_t result[RFFT_TEST_SIZE + 2];
|
||||||
|
|
||||||
|
memcpy(rfft_srcdata, rfft_src, (RFFT_TEST_SIZE + 2)*sizeof(q15_t));
|
||||||
|
csky_rfft_q15(&csky_rfft_sR_q15_len1024, rfft_srcdata, result);
|
||||||
|
|
||||||
|
for (i = 0; i < RFFT_TEST_SIZE + 2; i++) {
|
||||||
|
err = abs(result[i] - ref_rfft_result[i]);
|
||||||
|
if (err > 0xf) {
|
||||||
|
printf("dsp rfft run failure!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("dsp rfft run success!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define SIN_TEST_SIZE 128
|
||||||
|
|
||||||
|
q31_t sin_src[SIN_TEST_SIZE] = {
|
||||||
|
0x71f40eb8, 0x1aedfac4, 0x0f3ff639, 0x40eb378a, 0x159f1974, 0x5428ca42, 0x3e990f9d, 0x209a58e6,
|
||||||
|
0x62875be9, 0x5816212a, 0x28a6ff13, 0x7a51f6a7, 0x3ca51dcd, 0x052989e9, 0x613a6877, 0x413bbd0c,
|
||||||
|
0x502a2298, 0x44af92d2, 0x1851b3ba, 0x531d1932, 0x5259e962, 0x36537413, 0x457bf10d, 0x6f43906c,
|
||||||
|
0x473fcc60, 0x3ed09220, 0x2a151a9b, 0x12b52c1b, 0x3f79f6a8, 0x0aea56a5, 0x7f5ab471, 0x0ee05125,
|
||||||
|
0x2ec0f1de, 0x2b59847b, 0x6da9fe05, 0x0aa207c9, 0x4e0db117, 0x1ad037ab, 0x78555489, 0x2005ef5a,
|
||||||
|
0x107b129e, 0x36df9796, 0x4687e80b, 0x732d0ac1, 0x534c3c63, 0x1c0f8e39, 0x30b19f31, 0x19f18910,
|
||||||
|
0x3850eca4, 0x10118818, 0x45a0df62, 0x4104e5c3, 0x14195691, 0x74162b17, 0x5b9f737e, 0x445d0125,
|
||||||
|
0x1df54a61, 0x788e5af7, 0x3bc0bd34, 0x0f07e8f3, 0x211f4d64, 0x31a834bb, 0x506dd274, 0x6bb74d4b,
|
||||||
|
0x66e132bc, 0x263e92dd, 0x5cb47ec9, 0x541f4af5, 0x2320126d, 0x58b7700e, 0x00d0828f, 0x1182b519,
|
||||||
|
0x3d33cf33, 0x6577c618, 0x22af9e0f, 0x058ffea4, 0x2bf32d25, 0x07fb97e5, 0x7895e5f5, 0x73b5f4dd,
|
||||||
|
0x0399834c, 0x52f68eac, 0x66311a01, 0x3690ee7d, 0x1258b0e3, 0x1d85a331, 0x28e0511a, 0x1485ae28,
|
||||||
|
0x556e56c5, 0x690aa18a, 0x040672e5, 0x5c14209e, 0x5d8ff577, 0x61ba1095, 0x27c2e01e, 0x797a7a8f,
|
||||||
|
0x2d957473, 0x2a0c920a, 0x5b8d5230, 0x4c5e6a70, 0x62c33c82, 0x552b8cf0, 0x52a5adae, 0x3023134c,
|
||||||
|
0x2015d046, 0x734945c9, 0x73233bd0, 0x4e0a9921, 0x52fc390d, 0x02b26459, 0x25ea9d61, 0x4197a318,
|
||||||
|
0x55b9ca53, 0x6eb23e44, 0x31862277, 0x7b8f7be8, 0x2c0cc008, 0x533a8b83, 0x6a35c724, 0x0a232bc0,
|
||||||
|
0x2e6247d9, 0x3b442980, 0x1de30e64, 0x749b41b2, 0x70834a66, 0x01f8428b, 0x56356d0a, 0x4708a91b,
|
||||||
|
};
|
||||||
|
|
||||||
|
q31_t ref_sin_result[SIN_TEST_SIZE] = {
|
||||||
|
0xae927d72, 0x7c0dcc9a, 0x571dc1b4, 0xfa3a9ce8, 0x6fbe4766, 0x950553ac, 0x08cd75d4, 0x7ff10d88,
|
||||||
|
0x80fc5f3e, 0x8989e528, 0x74a02914, 0xdcc60f08, 0x14fc107a, 0x2016c0b4, 0x803bb9f2, 0xf841608c,
|
||||||
|
0xa4c37a12, 0xe2d13fdc, 0x7701f3ce, 0x98c47cba, 0x9babda5e, 0x3a861816, 0xddf4f932, 0xa247ba02,
|
||||||
|
0xd36834fe, 0x0771665a, 0x70a392a6, 0x65b47542, 0x034a13ca, 0x4158f3d2, 0xfbf19cc6, 0x55615368,
|
||||||
|
0x5fdfbdea, 0x6ca44370, 0x9bbb0ff4, 0x3fd0ad96, 0xae8a0976, 0x7bdf3ff8, 0xd0f56b9a, 0x7fffc56a,
|
||||||
|
0x5c9ea4d4, 0x3771a934, 0xd7aa340e, 0xb4a477aa, 0x9816491c, 0x7d9cd9ea, 0x575fbe36, 0x7a621b14,
|
||||||
|
0x2f245878, 0x5acfe2d2, 0xdd15a2fa, 0xf9996cf4, 0x6ac53b20, 0xb9575c24, 0x82f21454, 0xe4cb524a,
|
||||||
|
0x7f5b34f4, 0xd2434f50, 0x1a7e13a4, 0x561a435e, 0x7fcdac80, 0x52dadf6a, 0xa39b2218, 0x94978822,
|
||||||
|
0x873b677e, 0x7a08961a, 0x81ac072c, 0x95262c98, 0x7e7e8b94, 0x8818541c, 0x051dbcf2, 0x60f7405a,
|
||||||
|
0x1185c64c, 0x849581a0, 0x7ee31fd6, 0x2284557a, 0x6a99f2be, 0x30e22044, 0xd26fa1a0, 0xb76248d4,
|
||||||
|
0x167fd962, 0x9954214a, 0x85de5864, 0x392d8c3e, 0x644f642a, 0x7f0db084, 0x7409edc4, 0x6c371202,
|
||||||
|
0x90d846b8, 0x8c670202, 0x19206920, 0x825db7b6, 0x80eac460, 0x8075db58, 0x76d279d2, 0xd7b86778,
|
||||||
|
0x6494f30e, 0x70bd232c, 0x830a5b0a, 0xb6f92e88, 0x812cf66e, 0x91aab728, 0x9a86f676, 0x59e5afda,
|
||||||
|
0x7fff28b2, 0xb53400a0, 0xb472be58, 0xae98fc86, 0x993ebfe8, 0x10e525f8, 0x7aa33c5c, 0xf60164b2,
|
||||||
|
0x8feff520, 0x9fe370c6, 0x537dd3cc, 0xe4538b3e, 0x6a40ae5e, 0x98572fc8, 0x8fbe4fce, 0x3d18f9cc,
|
||||||
|
0x61655134, 0x1d79d4fc, 0x7f4f471a, 0xbc1671de, 0xa7cc325e, 0x0c5b6644, 0x8e80c89c, 0xd4adac08,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int32_t dsp_sin_demo(void)
|
||||||
|
{
|
||||||
|
q31_t result;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < SIN_TEST_SIZE; i++) {
|
||||||
|
result = csky_sin_q31(sin_src[i]);
|
||||||
|
|
||||||
|
if (result != ref_sin_result[i]) {
|
||||||
|
printf("dsp sin run failure!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("dsp sin run success!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define VARIANCE_STATIS_SIZE 128
|
||||||
|
|
||||||
|
q15_t variance_src[VARIANCE_STATIS_SIZE] = {
|
||||||
|
0x0af7, 0x2217, 0xd65a, 0x0066, 0xf0fb, 0x3d15, 0x37d2, 0x3245,
|
||||||
|
0xf8c6, 0x2032, 0x3467, 0xefc9, 0xcee3, 0x0337, 0xebaa, 0x2cb9,
|
||||||
|
0xd7d6, 0xdab8, 0x03e5, 0xcaca, 0xded2, 0x1139, 0xce38, 0x0dbd,
|
||||||
|
0x31e4, 0xfecf, 0xe821, 0x218e, 0x3a2e, 0x12ac, 0xfe1f, 0xf816,
|
||||||
|
0xd7db, 0xf8b9, 0xfe7b, 0x2e3a, 0x1bb5, 0x0f67, 0xcb7e, 0xce4e,
|
||||||
|
0x09ad, 0xfb18, 0x05d1, 0xc4de, 0x0a26, 0x1082, 0xfdb0, 0xd48c,
|
||||||
|
0x208f, 0x2591, 0xe54c, 0x00f9, 0xde77, 0xd8aa, 0x2783, 0xc889,
|
||||||
|
0xd912, 0x3cc6, 0x099d, 0x0aa7, 0x399a, 0xccce, 0x307a, 0x321b,
|
||||||
|
0xdb66, 0xd55f, 0x12b4, 0xd715, 0xceeb, 0xeec3, 0xf381, 0xcb7f,
|
||||||
|
0x1786, 0x0601, 0x3e34, 0xdb3b, 0x35a1, 0x1524, 0x1f2a, 0xf071,
|
||||||
|
0xfcc5, 0xcd9a, 0x3120, 0xf8f9, 0x1589, 0x1d36, 0xe490, 0x0bfe,
|
||||||
|
0xef6e, 0x25d7, 0xc96a, 0x3f12, 0x2355, 0xc0f2, 0x31c9, 0x2e9c,
|
||||||
|
0x194b, 0x3147, 0xfb9a, 0xef8f, 0xcaa0, 0x3fa5, 0x2f57, 0xc002,
|
||||||
|
0x1709, 0x13d3, 0xf4b6, 0xfcfa, 0xf1b3, 0xf9dd, 0xc36d, 0xf670,
|
||||||
|
0xcd8b, 0xc585, 0x072f, 0x0e3f, 0x1e92, 0xe0e3, 0x1cf6, 0x1b4c,
|
||||||
|
0x007b, 0x3246, 0x23c3, 0xff58, 0x2179, 0x1562, 0x3d33, 0xcefc,
|
||||||
|
};
|
||||||
|
|
||||||
|
int dsp_variance_demo(void)
|
||||||
|
{
|
||||||
|
q15_t result;
|
||||||
|
q15_t ref_result = 0xa8b;
|
||||||
|
csky_var_q15(variance_src, VARIANCE_STATIS_SIZE, &result);
|
||||||
|
|
||||||
|
if (result == ref_result) {
|
||||||
|
printf("dsp variance run success!\n");
|
||||||
|
} else {
|
||||||
|
printf("dsp variance run failure!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dsp_demo(u8 func)
|
||||||
|
{
|
||||||
|
switch(func)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
dsp_fir_demo();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
dsp_matrix_demo();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
dsp_rfft_demo();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
dsp_sin_demo();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
dsp_variance_demo();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("no demo for this func no!!!\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
165
demo/wm_fatfs_demo.c
Normal file
165
demo/wm_fatfs_demo.c
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
#include "ff.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_FATFS
|
||||||
|
|
||||||
|
#define TEST_DEBUG_EN 1
|
||||||
|
#if TEST_DEBUG_EN
|
||||||
|
#define TEST_DEBUG(fmt, ...) printf("%s: "fmt, __func__, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define TEST_DEBUG(fmt, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define FATFS_TASK_SIZE 1024
|
||||||
|
#define FATFS_TASK_PRIO 1
|
||||||
|
|
||||||
|
static OS_STK FatfsTaskStk[FATFS_TASK_SIZE];
|
||||||
|
static int console_cmd = 0;
|
||||||
|
|
||||||
|
|
||||||
|
//FAT功能测试:格式化测试,文件写入测试,文件读取测试(基本功能)
|
||||||
|
int fatfs_func(void)
|
||||||
|
{
|
||||||
|
FATFS fs; //FatFs文件系统对象
|
||||||
|
FIL fnew; //文件对象
|
||||||
|
FRESULT res_sd;//文件操作结果
|
||||||
|
UINT fnum; //文件成功读写数量
|
||||||
|
BYTE ReadBuffer[256] = {0};
|
||||||
|
BYTE work[FF_MAX_SS];
|
||||||
|
BYTE WriteBuffer[] = "成功移植了FatFs文件系统!\r\n"; //写缓存区
|
||||||
|
|
||||||
|
|
||||||
|
wm_sdio_host_config(0);
|
||||||
|
|
||||||
|
//挂载SD卡
|
||||||
|
res_sd = f_mount(&fs, "0:", 1);
|
||||||
|
|
||||||
|
//***********************格式化测试****************************
|
||||||
|
if(res_sd == FR_NO_FILESYSTEM)
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("SD卡没有文件系统,即将进行格式化...\r\n");
|
||||||
|
//格式化
|
||||||
|
|
||||||
|
res_sd = f_mkfs("0:", 0, work, sizeof(work));
|
||||||
|
|
||||||
|
if(res_sd == FR_OK)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("SD卡成功格式化!\r\n");
|
||||||
|
//格式化后先取消挂载
|
||||||
|
res_sd = f_mount(NULL, "0:", 1);
|
||||||
|
//再重新挂载
|
||||||
|
res_sd = f_mount(&fs, "0:", 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TEST_DEBUG("文件格式化失败!错误代码:%d; will try again...\r\n",res_sd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(res_sd != FR_OK)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("挂载文件系统失败!可能是因为文件初始化失败!错误代码:%d\r\n", res_sd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TEST_DEBUG("文件系统挂载成功, 可进行读写测试!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//***********************写测试****************************
|
||||||
|
//打开文件,如果文件不存在则创建它
|
||||||
|
TEST_DEBUG("即将进行文件写入测试....\r\n");
|
||||||
|
//打开文件,若不存在就创建
|
||||||
|
res_sd = f_open(&fnew, "0:FatFs读写测试文件.txt", FA_CREATE_ALWAYS | FA_WRITE);
|
||||||
|
//文件打开成功
|
||||||
|
if(res_sd == FR_OK)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("打开文件成功!开始写入数据!\r\n");
|
||||||
|
res_sd= f_write(&fnew, WriteBuffer, sizeof(WriteBuffer), &fnum);
|
||||||
|
|
||||||
|
if(res_sd == FR_OK)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("数据写入成功,共写入%d个字符!\r\n", fnum);
|
||||||
|
TEST_DEBUG("数据:%s", WriteBuffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TEST_DEBUG("数据写入失败!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭文件
|
||||||
|
f_close(&fnew);
|
||||||
|
}
|
||||||
|
|
||||||
|
//***********************读测试****************************
|
||||||
|
//打开文件,如果文件不存在则创建它
|
||||||
|
TEST_DEBUG("即将进行文件读取测试....\r\n");
|
||||||
|
//打开文件,若不存在就创建
|
||||||
|
res_sd = f_open(&fnew, "0:FatFs读写测试文件.txt", FA_OPEN_EXISTING | FA_READ);
|
||||||
|
//文件打开成功
|
||||||
|
if(res_sd == FR_OK)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("打开文件成功!开始读取数据!\r\n");
|
||||||
|
res_sd= f_read(&fnew, ReadBuffer, sizeof(ReadBuffer), &fnum);
|
||||||
|
|
||||||
|
if(res_sd == FR_OK)
|
||||||
|
{
|
||||||
|
TEST_DEBUG("数据读取成功!\r\n");
|
||||||
|
TEST_DEBUG("数据:%s\r\n", ReadBuffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TEST_DEBUG("数据读取失败!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭文件
|
||||||
|
f_close(&fnew);
|
||||||
|
}
|
||||||
|
|
||||||
|
//取消挂载文件系统
|
||||||
|
f_mount(NULL, "0:", 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void fatfs_task(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if( console_cmd==1 )
|
||||||
|
{
|
||||||
|
fatfs_func();
|
||||||
|
console_cmd = 0;
|
||||||
|
}
|
||||||
|
tls_os_time_delay(HZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fatfs_test(void)
|
||||||
|
{
|
||||||
|
static int flag = 0;
|
||||||
|
|
||||||
|
console_cmd = 1;
|
||||||
|
if( flag == 0 )
|
||||||
|
{
|
||||||
|
flag = 1;
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
( void (*))fatfs_task,
|
||||||
|
NULL,
|
||||||
|
(void *)FatfsTaskStk, /* task's stack start address */
|
||||||
|
FATFS_TASK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
FATFS_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
69
demo/wm_flash_demo.c
Normal file
69
demo/wm_flash_demo.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_flash_demo.c
|
||||||
|
*
|
||||||
|
* @brief flash demo function
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_internal_flash.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_FLASH
|
||||||
|
|
||||||
|
#define TEST_FLASH_BUF_SIZE 4000
|
||||||
|
|
||||||
|
int flash_demo(void)
|
||||||
|
{
|
||||||
|
u8 *write_buf = NULL;
|
||||||
|
u8 *read_buf = NULL;
|
||||||
|
u16 i;
|
||||||
|
|
||||||
|
tls_fls_init(); //initialize flash driver
|
||||||
|
|
||||||
|
write_buf = tls_mem_alloc(TEST_FLASH_BUF_SIZE);
|
||||||
|
if (NULL == write_buf)
|
||||||
|
{
|
||||||
|
printf("\nmalloc write buf error\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < TEST_FLASH_BUF_SIZE; i ++)
|
||||||
|
{
|
||||||
|
write_buf[i] = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_fls_write(0x1F0303, write_buf, 1247); /**verifying cross sector writing*/
|
||||||
|
tls_fls_write(0x1F0303 + 1247, write_buf + 1247, 2571);
|
||||||
|
tls_fls_write(0x1F0303 + 1247 + 2571, write_buf + 1247 + 2571, 182);
|
||||||
|
|
||||||
|
read_buf = tls_mem_alloc(TEST_FLASH_BUF_SIZE);
|
||||||
|
if (NULL == read_buf)
|
||||||
|
{
|
||||||
|
printf("\nmalloc read buf error\n");
|
||||||
|
tls_mem_free(write_buf);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
memset(read_buf, 0, TEST_FLASH_BUF_SIZE);
|
||||||
|
tls_fls_read(0x1F0303, read_buf, TEST_FLASH_BUF_SIZE);
|
||||||
|
|
||||||
|
if (0 == memcmp(write_buf, read_buf, TEST_FLASH_BUF_SIZE))
|
||||||
|
{
|
||||||
|
printf("\nsuccess\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\nfail\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_mem_free(write_buf);
|
||||||
|
tls_mem_free(read_buf);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
101
demo/wm_gpio_demo.c
Normal file
101
demo/wm_gpio_demo.c
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_gpio_demo.c
|
||||||
|
*
|
||||||
|
* Description: gpio demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : dave
|
||||||
|
*
|
||||||
|
* Date : 2014-6-2
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_GPIO
|
||||||
|
|
||||||
|
#define DEMO_ISR_IO WM_IO_PA_01
|
||||||
|
static void demo_gpio_isr_callback(void *context)
|
||||||
|
{
|
||||||
|
u16 ret;
|
||||||
|
|
||||||
|
ret = tls_get_gpio_irq_status(DEMO_ISR_IO);
|
||||||
|
printf("\nint flag =%d\n",ret);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
tls_clr_gpio_irq_status(DEMO_ISR_IO);
|
||||||
|
ret = tls_gpio_read(DEMO_ISR_IO);
|
||||||
|
printf("\nafter int io =%d\n",ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//gpio 测试程序
|
||||||
|
int gpio_demo(void)
|
||||||
|
{
|
||||||
|
u16 gpio_pin;
|
||||||
|
u16 ret;
|
||||||
|
|
||||||
|
//测试gpioB 6,7
|
||||||
|
for(gpio_pin = WM_IO_PB_06; gpio_pin <= WM_IO_PB_07; gpio_pin ++)
|
||||||
|
{
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
ret = tls_gpio_read(gpio_pin); /*先读默认状态*/
|
||||||
|
printf("\ngpio%c[%d] default value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ?'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
/*During gpio's floating attribute, output high or low test*/
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
tls_gpio_write(gpio_pin,1); /*写高*/
|
||||||
|
ret = tls_gpio_read(gpio_pin);
|
||||||
|
printf("\ngpio%c[%d] floating high value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ? 'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
tls_gpio_write(gpio_pin,0); /*写低*/
|
||||||
|
ret = tls_gpio_read(gpio_pin);
|
||||||
|
printf("\ngpio%c[%d] floating low value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ? 'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
/*During gpio's pullup attribute, output high or low test*/
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
|
||||||
|
tls_gpio_write(gpio_pin,1); /*写高*/
|
||||||
|
ret = tls_gpio_read(gpio_pin);
|
||||||
|
printf("\ngpio%c[%d] pullhigh value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ?'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
|
||||||
|
tls_gpio_write(gpio_pin,0); /*写低*/
|
||||||
|
ret = tls_gpio_read(gpio_pin);
|
||||||
|
printf("\ngpio%c[%d] pullhigh value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ? 'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
/*During gpio's pulldown attribute, output high or low test*/
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLLOW);
|
||||||
|
tls_gpio_write(gpio_pin,1); /*写高*/
|
||||||
|
ret = tls_gpio_read(gpio_pin);
|
||||||
|
printf("\ngpio%c[%d] pulllow value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ?'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLLOW);
|
||||||
|
tls_gpio_write(gpio_pin,0); /*写低*/
|
||||||
|
ret = tls_gpio_read(gpio_pin);
|
||||||
|
printf("\ngpio%c[%d] pulllow value==[%d]\n", (gpio_pin >= WM_IO_PB_00) ? 'B':'A', (gpio_pin >= WM_IO_PB_00) ?(gpio_pin - WM_IO_PB_00):gpio_pin,ret);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int gpio_isr_test(void)
|
||||||
|
{
|
||||||
|
u16 gpio_pin;
|
||||||
|
|
||||||
|
gpio_pin = DEMO_ISR_IO;
|
||||||
|
|
||||||
|
//测试中断
|
||||||
|
tls_gpio_cfg(gpio_pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
tls_gpio_isr_register(gpio_pin, demo_gpio_isr_callback, NULL);
|
||||||
|
tls_gpio_irq_enable(gpio_pin, WM_GPIO_IRQ_TRIG_RISING_EDGE);
|
||||||
|
printf("\ntest gpio %d rising isr\n",gpio_pin);
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
193
demo/wm_http_demo.c
Normal file
193
demo/wm_http_demo.c
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_http_fwup.h"
|
||||||
|
|
||||||
|
#if DEMO_HTTP
|
||||||
|
extern int t_http_fwup(char *url);
|
||||||
|
#define HTTP_CLIENT_BUFFER_SIZE 1024
|
||||||
|
|
||||||
|
u8 RemoteIp[4] = {192, 168, 1, 100}; //Remote server's IP when test http function
|
||||||
|
|
||||||
|
u32 http_snd_req(HTTPParameters ClientParams, HTTP_VERB verb, char *pSndData, u8 parseXmlJson)
|
||||||
|
{
|
||||||
|
int nRetCode;
|
||||||
|
u32 nSize, nTotal = 0;
|
||||||
|
char *Buffer = NULL;
|
||||||
|
HTTP_SESSION_HANDLE pHTTP;
|
||||||
|
u32 nSndDataLen ;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Buffer = (char *)tls_mem_alloc(HTTP_CLIENT_BUFFER_SIZE);
|
||||||
|
if(Buffer == NULL)
|
||||||
|
{
|
||||||
|
return HTTP_CLIENT_ERROR_NO_MEMORY;
|
||||||
|
}
|
||||||
|
memset(Buffer, 0, HTTP_CLIENT_BUFFER_SIZE);
|
||||||
|
printf("HTTP Client v1.0\r\n");
|
||||||
|
nSndDataLen = (pSndData == NULL ? 0 : strlen(pSndData));
|
||||||
|
// Open the HTTP request handle
|
||||||
|
pHTTP = HTTPClientOpenRequest(0);
|
||||||
|
if(!pHTTP)
|
||||||
|
{
|
||||||
|
nRetCode = HTTP_CLIENT_ERROR_INVALID_HANDLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if((nRetCode = HTTPClientAddRequestHeaders(pHTTP,"media type", "application/json", 1))!= HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// Set the Verb
|
||||||
|
nRetCode = HTTPClientSetVerb(pHTTP, verb);
|
||||||
|
if(nRetCode != HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#if TLS_CONFIG_HTTP_CLIENT_AUTH
|
||||||
|
// Set authentication
|
||||||
|
if(ClientParams.AuthType != AuthSchemaNone)
|
||||||
|
{
|
||||||
|
if((nRetCode = HTTPClientSetAuth(pHTTP, ClientParams.AuthType, NULL)) != HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set authentication
|
||||||
|
if((nRetCode = HTTPClientSetCredentials(pHTTP, ClientParams.UserName, ClientParams.Password)) != HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //TLS_CONFIG_HTTP_CLIENT_AUTH
|
||||||
|
#if TLS_CONFIG_HTTP_CLIENT_PROXY
|
||||||
|
// Use Proxy server
|
||||||
|
if(ClientParams.UseProxy == TRUE)
|
||||||
|
{
|
||||||
|
if((nRetCode = HTTPClientSetProxy(pHTTP, ClientParams.ProxyHost, ClientParams.ProxyPort, NULL, NULL)) != HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //TLS_CONFIG_HTTP_CLIENT_PROXY
|
||||||
|
if((nRetCode = HTTPClientSendRequest(pHTTP, ClientParams.Uri, pSndData, nSndDataLen, verb == VerbPost || verb == VerbPut, 0, 0)) != HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Retrieve the the headers and analyze them
|
||||||
|
if((nRetCode = HTTPClientRecvResponse(pHTTP, 30)) != HTTP_CLIENT_SUCCESS)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("Start to receive data from remote server...\r\n");
|
||||||
|
|
||||||
|
// Get the data until we get an error or end of stream code
|
||||||
|
while(nRetCode == HTTP_CLIENT_SUCCESS || nRetCode != HTTP_CLIENT_EOS)
|
||||||
|
{
|
||||||
|
// Set the size of our buffer
|
||||||
|
nSize = HTTP_CLIENT_BUFFER_SIZE;
|
||||||
|
// Get the data
|
||||||
|
nRetCode = HTTPClientReadData(pHTTP, Buffer, nSize, 300, &nSize);
|
||||||
|
if(nRetCode != HTTP_CLIENT_SUCCESS && nRetCode != HTTP_CLIENT_EOS)
|
||||||
|
break;
|
||||||
|
printf("%s", Buffer);
|
||||||
|
nTotal += nSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(0); // Run only once
|
||||||
|
tls_mem_free(Buffer);
|
||||||
|
|
||||||
|
if(pHTTP)
|
||||||
|
HTTPClientCloseRequest(&pHTTP);
|
||||||
|
if(ClientParams.Verbose == TRUE)
|
||||||
|
{
|
||||||
|
printf("\n\nHTTP Client terminated %d (got %d b)\n\n", nRetCode, nTotal);
|
||||||
|
}
|
||||||
|
return nRetCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 http_get(HTTPParameters ClientParams)
|
||||||
|
{
|
||||||
|
return http_snd_req(ClientParams, VerbGet, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 http_post(HTTPParameters ClientParams, char *pSndData)
|
||||||
|
{
|
||||||
|
return http_snd_req(ClientParams, VerbPost, pSndData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 http_put(HTTPParameters ClientParams, char *pSndData)
|
||||||
|
{
|
||||||
|
return http_snd_req(ClientParams, VerbPut, pSndData, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int http_get_demo(char *buf)
|
||||||
|
{
|
||||||
|
HTTPParameters httpParams;
|
||||||
|
|
||||||
|
memset(&httpParams, 0, sizeof(HTTPParameters));
|
||||||
|
httpParams.Uri = (char *)tls_mem_alloc(128);
|
||||||
|
if(httpParams.Uri == NULL)
|
||||||
|
{
|
||||||
|
printf("malloc error.\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
memset(httpParams.Uri, 0, 128);
|
||||||
|
sprintf(httpParams.Uri, "%s", buf);
|
||||||
|
httpParams.Verbose = TRUE;
|
||||||
|
printf("Location: %s\n", httpParams.Uri);
|
||||||
|
http_get(httpParams);
|
||||||
|
tls_mem_free(httpParams.Uri);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
int http_post_demo(char *postData)
|
||||||
|
{
|
||||||
|
HTTPParameters httpParams;
|
||||||
|
|
||||||
|
memset(&httpParams, 0, sizeof(HTTPParameters));
|
||||||
|
httpParams.Uri = (char *)tls_mem_alloc(128);
|
||||||
|
if(httpParams.Uri == NULL)
|
||||||
|
{
|
||||||
|
printf("malloc error.\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
memset(httpParams.Uri, 0, 128);
|
||||||
|
sprintf(httpParams.Uri, "http://%d.%d.%d.%d:8080/TestWeb/login.do", RemoteIp[0], RemoteIp[1], RemoteIp[2], RemoteIp[3]);
|
||||||
|
printf("Location: %s\n", httpParams.Uri);
|
||||||
|
httpParams.Verbose = TRUE;
|
||||||
|
http_post(httpParams, postData);
|
||||||
|
tls_mem_free(httpParams.Uri);
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
int http_put_demo(char *putData)
|
||||||
|
{
|
||||||
|
HTTPParameters httpParams;
|
||||||
|
|
||||||
|
memset(&httpParams, 0, sizeof(HTTPParameters));
|
||||||
|
httpParams.Uri = (char *)tls_mem_alloc(128);
|
||||||
|
if(httpParams.Uri == NULL)
|
||||||
|
{
|
||||||
|
printf("malloc error.\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
memset(httpParams.Uri, 0, 128);
|
||||||
|
sprintf(httpParams.Uri, "http://%d.%d.%d.%d:8080/TestWeb/login_put.do", RemoteIp[0], RemoteIp[1], RemoteIp[2], RemoteIp[3]);
|
||||||
|
printf("Location: %s\n", httpParams.Uri);
|
||||||
|
httpParams.Verbose = TRUE;
|
||||||
|
http_put(httpParams, putData);
|
||||||
|
tls_mem_free(httpParams.Uri);
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int http_fwup_demo(char *url)
|
||||||
|
{
|
||||||
|
t_http_fwup(url);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //DEMO_HTTP
|
||||||
|
|
||||||
216
demo/wm_https_demo.c
Normal file
216
demo/wm_https_demo.c
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_https_demo.c
|
||||||
|
*
|
||||||
|
* Description: ssl client demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : LiLimin
|
||||||
|
*
|
||||||
|
* Date : 2015-3-24
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_netif.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "tls_common.h"
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
#include "lwip/inet.h"
|
||||||
|
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
#include "HTTPClientWrapper.h"
|
||||||
|
|
||||||
|
#if DEMO_HTTPS
|
||||||
|
|
||||||
|
#define HTTPS_DEMO_TASK_PRIO 38
|
||||||
|
#define HTTPS_DEMO_TASK_SIZE 2048 //1024
|
||||||
|
#define HTTPS_DEMO_QUEUE_SIZE 4
|
||||||
|
|
||||||
|
#define HTTPS_RECV_BUF_LEN_MAX 1024
|
||||||
|
|
||||||
|
#define HTTPS_DEMO_CMD_START 0x1
|
||||||
|
|
||||||
|
#define HTTPS_DEMO_SERVER "www.tencent.com"
|
||||||
|
#define HTTPS_DEMO_PORT 443
|
||||||
|
|
||||||
|
static bool https_demo_inited = FALSE;
|
||||||
|
static OS_STK https_demo_task_stk[HTTPS_DEMO_TASK_SIZE];
|
||||||
|
static tls_os_queue_t *https_demo_task_queue = NULL;
|
||||||
|
|
||||||
|
static const char *https_request = "GET /legal/html/zh-cn/index.html HTTP/1.0\r\n"
|
||||||
|
"Host: "HTTPS_DEMO_SERVER"\r\n"
|
||||||
|
"User-Agent: W80X\r\n"
|
||||||
|
"\r\n";
|
||||||
|
|
||||||
|
extern struct netif *tls_get_netif(void);
|
||||||
|
extern int wm_printf(const char *fmt, ...);
|
||||||
|
|
||||||
|
static void https_demo_net_status(u8 status)
|
||||||
|
{
|
||||||
|
struct netif *netif = tls_get_netif();
|
||||||
|
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
wm_printf("sta join net failed\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
wm_printf("sta net disconnected\n");
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
wm_printf("sta ip: %v\n", netif->ip_addr.addr);
|
||||||
|
tls_os_queue_send(https_demo_task_queue, (void *)HTTPS_DEMO_CMD_START, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void https_demo_task(void *p)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
void *msg;
|
||||||
|
tls_ssl_t *ssl_p;
|
||||||
|
int fd;
|
||||||
|
struct hostent *hp;
|
||||||
|
struct sockaddr_in server;
|
||||||
|
char *recvbuf;
|
||||||
|
int total = 0;
|
||||||
|
struct tls_ethif *ether_if = tls_netif_get_ethif();
|
||||||
|
|
||||||
|
if (ether_if->status)
|
||||||
|
{
|
||||||
|
wm_printf("sta ip: %v\n", ether_if->ip_addr.addr);
|
||||||
|
tls_os_queue_send(https_demo_task_queue, (void *)HTTPS_DEMO_CMD_START, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for( ; ; )
|
||||||
|
{
|
||||||
|
ret = tls_os_queue_receive(https_demo_task_queue, (void **)&msg, 0, 0);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case HTTPS_DEMO_CMD_START:
|
||||||
|
do
|
||||||
|
{
|
||||||
|
hp = gethostbyname(HTTPS_DEMO_SERVER);
|
||||||
|
if (hp == NULL )
|
||||||
|
{
|
||||||
|
wm_printf("get address error\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
wm_printf("create socket error\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&server, 0, sizeof(struct sockaddr_in));
|
||||||
|
memcpy(&(server.sin_addr), hp->h_addr, hp->h_length);
|
||||||
|
server.sin_family = AF_INET;
|
||||||
|
server.sin_port = htons(HTTPS_DEMO_PORT);
|
||||||
|
|
||||||
|
wm_printf("step 1: ssl connect to...\r\n");
|
||||||
|
ret = HTTPWrapperSSLConnect(&ssl_p, fd, (const struct sockaddr *)&server, sizeof(server), HTTPS_DEMO_SERVER);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
wm_printf("https connect error\r\n");
|
||||||
|
close(fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
recvbuf = tls_mem_alloc(HTTPS_RECV_BUF_LEN_MAX + 1);
|
||||||
|
if (!recvbuf)
|
||||||
|
{
|
||||||
|
wm_printf("https malloc error\r\n");
|
||||||
|
HTTPWrapperSSLClose(ssl_p, fd);
|
||||||
|
close(fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
wm_printf("step 2: send https request [%s]\r\n", https_request);
|
||||||
|
ret = HTTPWrapperSSLSend(ssl_p, fd, (char *)https_request, strlen(https_request), 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
wm_printf("https send error\r\n");
|
||||||
|
tls_mem_free(recvbuf);
|
||||||
|
HTTPWrapperSSLClose(ssl_p, fd);
|
||||||
|
close(fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ret = HTTPWrapperSSLRecv(ssl_p, fd, recvbuf, HTTPS_RECV_BUF_LEN_MAX, 0);
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
if (SOCKET_SSL_MORE_DATA == ret)
|
||||||
|
{
|
||||||
|
recvbuf[HTTPS_RECV_BUF_LEN_MAX] = '\0';
|
||||||
|
wm_printf("step 3: recvd https resp %d bytes [%s]\r\n", HTTPS_RECV_BUF_LEN_MAX, recvbuf);
|
||||||
|
total += HTTPS_RECV_BUF_LEN_MAX;
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wm_printf("https recv closed\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
recvbuf[ret] = '\0';
|
||||||
|
wm_printf("step 3: recvd https resp %d bytes [%s]\r\n", ret, recvbuf);
|
||||||
|
total += ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (ret > 0);
|
||||||
|
|
||||||
|
wm_printf("step 3: recvd https resp total %d bytes.\r\n", total);
|
||||||
|
|
||||||
|
tls_mem_free(recvbuf);
|
||||||
|
HTTPWrapperSSLClose(ssl_p, fd);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
wm_printf("\r\nhttps demo end.\r\n");
|
||||||
|
}
|
||||||
|
while (0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//https request demo
|
||||||
|
//This example should make STA connected to AP firstly, then access web page https://www.tencent.com/legal/html/zh-cn/index.html
|
||||||
|
int https_demo(void)
|
||||||
|
{
|
||||||
|
if (!https_demo_inited)
|
||||||
|
{
|
||||||
|
tls_os_task_create(NULL, NULL, https_demo_task,
|
||||||
|
NULL, (void *)https_demo_task_stk, /* task's stack start address */
|
||||||
|
HTTPS_DEMO_TASK_SIZE * sizeof(u32),/* task's stack size, unit:byte */
|
||||||
|
HTTPS_DEMO_TASK_PRIO, 0);
|
||||||
|
|
||||||
|
tls_os_queue_create(&https_demo_task_queue, HTTPS_DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_netif_add_status_event(https_demo_net_status);
|
||||||
|
|
||||||
|
https_demo_inited = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
167
demo/wm_i2c_demo.c
Normal file
167
demo/wm_i2c_demo.c
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file wm_i2c_demo.c
|
||||||
|
* @version
|
||||||
|
* @date
|
||||||
|
* @author
|
||||||
|
* @note
|
||||||
|
* Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_i2c.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
#if DEMO_I2C
|
||||||
|
|
||||||
|
#define I2C_FREQ (200000)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief read one byte from the specified address of the eeprom
|
||||||
|
* @param addr the eeprom address will be read from
|
||||||
|
* @retval the read data
|
||||||
|
*/
|
||||||
|
u8 AT24CXX_ReadOneByte(u16 addr)
|
||||||
|
{
|
||||||
|
u8 temp=0;
|
||||||
|
//printf("\nread addr=%x\n",ReadAddr);
|
||||||
|
tls_i2c_write_byte(0xA0,1);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
tls_i2c_write_byte(addr,0);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
|
||||||
|
tls_i2c_write_byte(0xA1,1);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
temp=tls_i2c_read_byte(0,1);
|
||||||
|
//printf("\nread byte=%x\n",temp);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief read multibytes from the specified address of the eeprom
|
||||||
|
* @param[in] addr the eeprom address will be read from
|
||||||
|
* @param[in] buf Pointer to data buffer
|
||||||
|
* @param[in] len amount of data to be read
|
||||||
|
* @retval null
|
||||||
|
*/
|
||||||
|
void AT24CXX_ReadLenByte(u16 addr,u8 *buf,u16 len)
|
||||||
|
{
|
||||||
|
//printf("\nread len addr=%x\n",ReadAddr);
|
||||||
|
tls_i2c_write_byte(0xA0,1);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
tls_i2c_write_byte(addr,0);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
tls_i2c_write_byte(0xA1,1);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
while(len > 1)
|
||||||
|
{
|
||||||
|
*buf++ = tls_i2c_read_byte(1,0);
|
||||||
|
//printf("\nread byte=%x\n",*(pBuffer - 1));
|
||||||
|
len --;
|
||||||
|
}
|
||||||
|
*buf = tls_i2c_read_byte(0,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief write one byte to the specified address of the eeprom
|
||||||
|
* @param addr the eeprom address will be write to
|
||||||
|
* @retval null
|
||||||
|
*/
|
||||||
|
void AT24CXX_WriteOneByte(u16 addr, u8 data)
|
||||||
|
{
|
||||||
|
tls_i2c_write_byte(0XA0, 1);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
tls_i2c_write_byte(addr, 0);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
tls_i2c_write_byte(data, 0);
|
||||||
|
tls_i2c_wait_ack();
|
||||||
|
tls_i2c_stop();
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief check the eeprom is normal or not
|
||||||
|
* @retval
|
||||||
|
* 0---success
|
||||||
|
* 1---failed
|
||||||
|
* @note
|
||||||
|
* different 24Cxx chip will use the different addr
|
||||||
|
*/
|
||||||
|
u8 AT24CXX_Check(void)
|
||||||
|
{
|
||||||
|
u8 temp;
|
||||||
|
temp=AT24CXX_ReadOneByte(255);
|
||||||
|
if (temp==0x55)return 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AT24CXX_WriteOneByte(255, 0x55);
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
temp=AT24CXX_ReadOneByte(255);
|
||||||
|
if (temp==0x55)return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief read multibytes from the specified address of the eeprom
|
||||||
|
* @param[in] addr the eeprom address will be read from
|
||||||
|
* @param[in] buf Pointer to data buffer
|
||||||
|
* @param[in] len amount of data to be read
|
||||||
|
* @retval null
|
||||||
|
*/
|
||||||
|
void AT24CXX_Read(u16 addr, u8 *buf, u16 len)
|
||||||
|
{
|
||||||
|
while(len)
|
||||||
|
{
|
||||||
|
*buf++=AT24CXX_ReadOneByte(addr++);
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief write multibytes from the specified address of the eeprom
|
||||||
|
* @param[in] addr the eeprom address will be read from
|
||||||
|
* @param[in] buf Pointer to data buffer
|
||||||
|
* @param[in] len amount of data to be write
|
||||||
|
* @retval null
|
||||||
|
*/
|
||||||
|
void AT24CXX_Write(u16 addr, u8 *buf, u16 len)
|
||||||
|
{
|
||||||
|
while(len--)
|
||||||
|
{
|
||||||
|
AT24CXX_WriteOneByte(addr,*buf);
|
||||||
|
addr++;
|
||||||
|
buf++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int i2c_demo(char *buf)
|
||||||
|
{
|
||||||
|
u8 testbuf[] = {"AT24CXX I2C TEST OK"};
|
||||||
|
u8 datatmp[32];
|
||||||
|
|
||||||
|
wm_i2c_scl_config(WM_IO_PA_01);
|
||||||
|
wm_i2c_sda_config(WM_IO_PA_04);
|
||||||
|
|
||||||
|
tls_i2c_init(I2C_FREQ);
|
||||||
|
|
||||||
|
while(AT24CXX_Check())
|
||||||
|
{
|
||||||
|
printf("\nAT24CXX check faild\n");
|
||||||
|
}
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
printf("\nAT24CXX check success\n");
|
||||||
|
|
||||||
|
AT24CXX_Write(0,(u8 *)testbuf,sizeof(testbuf));
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
memset(datatmp,0,sizeof(datatmp));
|
||||||
|
//AT24CXX_Read(0,datatmp,sizeof(testbuf));
|
||||||
|
AT24CXX_ReadLenByte(0,(u8 *)datatmp,sizeof(testbuf));
|
||||||
|
printf("\nread data is:%s\n",datatmp);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/
|
||||||
335
demo/wm_i2s_demo.c
Normal file
335
demo/wm_i2s_demo.c
Normal file
@ -0,0 +1,335 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file wm_i2s_demo.c
|
||||||
|
* @version
|
||||||
|
* @date
|
||||||
|
* @author
|
||||||
|
* @note
|
||||||
|
* Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "wm_i2s.h"
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_I2S
|
||||||
|
|
||||||
|
#define DEMO_DATA_SIZE (1024)
|
||||||
|
|
||||||
|
extern int wm_i2s_tranceive_dma(uint32_t i2s_mode, wm_dma_handler_type *hdma_tx, wm_dma_handler_type *hdma_rx, uint16_t *data_tx, uint16_t *data_rx, uint16_t len);
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
WM_I2S_MODE_INT,
|
||||||
|
WM_I2S_MODE_DMA
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
WM_I2S_TX = 1,
|
||||||
|
WM_I2S_RX = 2,
|
||||||
|
WM_I2S_TR = 3,
|
||||||
|
WM_I2S_TR_SLAVE = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t i2s_demo_rx[DEMO_DATA_SIZE] = { 0 };
|
||||||
|
uint32_t i2s_demo_tx[DEMO_DATA_SIZE] = { 0 };
|
||||||
|
|
||||||
|
static void show_rx_data(u16 len)
|
||||||
|
{
|
||||||
|
printf("recv %d\r\n", len);
|
||||||
|
for(u16 i=0; i<len; i++)
|
||||||
|
{
|
||||||
|
printf("%08X ", i2s_demo_rx[i]);
|
||||||
|
if(i % 16 == 15)
|
||||||
|
{
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tls_i2s_tx_int_demo()
|
||||||
|
{
|
||||||
|
for(u16 len = 0; len < DEMO_DATA_SIZE; len++)
|
||||||
|
{
|
||||||
|
i2s_demo_tx[len] = 0xA55A55A0+len;
|
||||||
|
}
|
||||||
|
|
||||||
|
wm_i2s_tx_int((int16_t *)i2s_demo_tx, DEMO_DATA_SIZE, NULL);
|
||||||
|
printf("send %d\r\n", DEMO_DATA_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tls_i2s_rx_int_demo()
|
||||||
|
{
|
||||||
|
memset((u8 *)i2s_demo_rx, 0, DEMO_DATA_SIZE*sizeof(i2s_demo_rx[0]));
|
||||||
|
wm_i2s_rx_int((int16_t *)i2s_demo_rx, DEMO_DATA_SIZE);
|
||||||
|
show_rx_data(DEMO_DATA_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tls_i2s_tr_int_demo(I2S_InitDef *opts)
|
||||||
|
{
|
||||||
|
for(u16 len = 0; len < DEMO_DATA_SIZE; len++)
|
||||||
|
{
|
||||||
|
i2s_demo_tx[len] = 0xA55A55A0+len;
|
||||||
|
}
|
||||||
|
memset((u8 *)i2s_demo_rx, 0, DEMO_DATA_SIZE*sizeof(i2s_demo_rx[0]));
|
||||||
|
wm_i2s_tx_rx_int(opts, (int16_t *)i2s_demo_tx, (int16_t *)i2s_demo_rx, DEMO_DATA_SIZE);
|
||||||
|
show_rx_data(DEMO_DATA_SIZE);
|
||||||
|
}
|
||||||
|
static uint32_t g_tx_buff_val = 0xA55A55A0;
|
||||||
|
static wm_dma_handler_type hdma_tx;
|
||||||
|
static void i2sDmaSendCpltCallback(wm_dma_handler_type *hdma)
|
||||||
|
{
|
||||||
|
// int i = DEMO_DATA_SIZE/2;
|
||||||
|
// for(; i < DEMO_DATA_SIZE; i++)
|
||||||
|
// {
|
||||||
|
// i2s_demo_tx[i] = g_tx_buff_val++;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
static void i2sDmaSendHalfCpltCallback(wm_dma_handler_type *hdma)
|
||||||
|
{
|
||||||
|
// int i = 0;
|
||||||
|
// for(; i < DEMO_DATA_SIZE/2; i++)
|
||||||
|
// {
|
||||||
|
// i2s_demo_tx[i] = g_tx_buff_val++;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
static void tls_i2s_tx_dma_demo()
|
||||||
|
{
|
||||||
|
for(u16 len = 0; len < DEMO_DATA_SIZE; len++)
|
||||||
|
{
|
||||||
|
i2s_demo_tx[len] = g_tx_buff_val++;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
wm_i2s_tx_dma((int16_t *)i2s_demo_tx, DEMO_DATA_SIZE, NULL);
|
||||||
|
printf("send %d\r\n", DEMO_DATA_SIZE);
|
||||||
|
#else
|
||||||
|
memset(&hdma_tx, 0, sizeof(wm_dma_handler_type));
|
||||||
|
hdma_tx.XferCpltCallback = i2sDmaSendCpltCallback;
|
||||||
|
hdma_tx.XferHalfCpltCallback = i2sDmaSendHalfCpltCallback;
|
||||||
|
wm_i2s_transmit_dma(&hdma_tx, (uint16_t *)i2s_demo_tx, DEMO_DATA_SIZE * 2);
|
||||||
|
printf("dma transmit start\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static wm_dma_handler_type hdma_rx;
|
||||||
|
static volatile uint8_t g_recv_state = 0; //1: recv half cplt; 2: recv cplt;
|
||||||
|
static volatile uint32_t g_recv_count = 0;
|
||||||
|
static void i2sDmaRecvCpltCallback(wm_dma_handler_type *hdma)
|
||||||
|
{
|
||||||
|
g_recv_state = 2;
|
||||||
|
g_recv_count++;
|
||||||
|
// printf("%d\n", g_recv_count);
|
||||||
|
}
|
||||||
|
static void i2sDmaRecvHalfCpltCallback(wm_dma_handler_type *hdma)
|
||||||
|
{
|
||||||
|
g_recv_state = 1;
|
||||||
|
}
|
||||||
|
static void tls_i2s_rx_dma_demo()
|
||||||
|
{
|
||||||
|
memset((u8 *)i2s_demo_rx, 0, DEMO_DATA_SIZE*sizeof(i2s_demo_rx[0]));
|
||||||
|
#if 0
|
||||||
|
wm_i2s_rx_dma((int16_t *)i2s_demo_rx, DEMO_DATA_SIZE);
|
||||||
|
show_rx_data(DEMO_DATA_SIZE);
|
||||||
|
#else
|
||||||
|
memset(&hdma_rx, 0, sizeof(wm_dma_handler_type));
|
||||||
|
hdma_rx.XferCpltCallback = i2sDmaRecvCpltCallback;
|
||||||
|
hdma_rx.XferHalfCpltCallback = i2sDmaRecvHalfCpltCallback;
|
||||||
|
wm_i2s_receive_dma(&hdma_rx, (uint16_t *)i2s_demo_rx, DEMO_DATA_SIZE*2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
static void tls_i2s_tr_dma_demo(I2S_InitDef *opts)
|
||||||
|
{
|
||||||
|
for(u16 len = 0; len < DEMO_DATA_SIZE; len++)
|
||||||
|
{
|
||||||
|
i2s_demo_tx[len] = 0xA55A55A0+len;
|
||||||
|
}
|
||||||
|
memset((u8 *)i2s_demo_rx, 0, DEMO_DATA_SIZE*sizeof(i2s_demo_rx[0]));
|
||||||
|
#if 0
|
||||||
|
wm_i2s_tx_rx_dma(opts, (int16_t *)i2s_demo_tx, (int16_t *)i2s_demo_rx, DEMO_DATA_SIZE);
|
||||||
|
show_rx_data(DEMO_DATA_SIZE);
|
||||||
|
#else
|
||||||
|
memset(&hdma_tx, 0, sizeof(wm_dma_handler_type));
|
||||||
|
hdma_tx.XferCpltCallback = i2sDmaSendCpltCallback;
|
||||||
|
hdma_tx.XferHalfCpltCallback = i2sDmaSendHalfCpltCallback;
|
||||||
|
memset(&hdma_rx, 0, sizeof(wm_dma_handler_type));
|
||||||
|
hdma_rx.XferCpltCallback = i2sDmaRecvCpltCallback;
|
||||||
|
hdma_rx.XferHalfCpltCallback = i2sDmaRecvHalfCpltCallback;
|
||||||
|
wm_i2s_tranceive_dma(opts->I2S_Mode_MS, &hdma_tx, &hdma_rx, (uint16_t *)i2s_demo_tx, (uint16_t *)i2s_demo_rx, DEMO_DATA_SIZE*2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param[in] format
|
||||||
|
* - \ref 0: i2s
|
||||||
|
* - \ref 1: msb
|
||||||
|
* - \ref 2: pcma
|
||||||
|
* - \ref 3: pcmb
|
||||||
|
*
|
||||||
|
* @param[in] tx_rx
|
||||||
|
* - \ref 1: transmit
|
||||||
|
* - \ref 2: receive
|
||||||
|
* - \ref 3: duplex master
|
||||||
|
* - \ref 4: duplex slave
|
||||||
|
*
|
||||||
|
* @param[in] freq
|
||||||
|
* sample rate
|
||||||
|
*
|
||||||
|
* @param[in] datawidth
|
||||||
|
* - \ref 8: 8 bit
|
||||||
|
* - \ref 16: 16 bit
|
||||||
|
* - \ref 24: 24 bit
|
||||||
|
* - \ref 32: 32 bit
|
||||||
|
*
|
||||||
|
* @param[in] stereo
|
||||||
|
* - \ref 0: stereo
|
||||||
|
* - \ref 1: mono
|
||||||
|
*
|
||||||
|
* @param[in] mode
|
||||||
|
* - \ref 0: interrupt
|
||||||
|
* - \ref 1: dma
|
||||||
|
*
|
||||||
|
* @retval
|
||||||
|
*
|
||||||
|
* @note
|
||||||
|
* t-i2s=(0,1,44100,16,0,0) -- M_I2S send(ISR mode)
|
||||||
|
* t-i2s=(0,1,44100,16,0,1) -- M_I2S send(DMA mode)
|
||||||
|
* t-i2s=(0,2,44100,16,0,0) -- S_I2S recv(ISR mode)
|
||||||
|
* t-i2s=(0,2,44100,16,0,1) -- S_I2S recv(DMA mode)
|
||||||
|
*/
|
||||||
|
int tls_i2s_demo(s8 format,
|
||||||
|
s8 tx_rx,
|
||||||
|
s32 freq,
|
||||||
|
s8 datawidth,
|
||||||
|
s8 stereo,
|
||||||
|
s8 mode)
|
||||||
|
{
|
||||||
|
int i = 0, count = 0;
|
||||||
|
I2S_InitDef opts = { I2S_MODE_MASTER, I2S_CTRL_STEREO, I2S_RIGHT_CHANNEL, I2S_Standard, I2S_DataFormat_16, 8000, 5000000 };
|
||||||
|
|
||||||
|
opts.I2S_Mode_MS = (tx_rx-1);
|
||||||
|
opts.I2S_Mode_SS = (stereo<<22);
|
||||||
|
opts.I2S_Mode_LR = I2S_LEFT_CHANNEL;
|
||||||
|
opts.I2S_Trans_STD = (format*0x1000000);
|
||||||
|
opts.I2S_DataFormat = (datawidth/8 - 1)*0x10;
|
||||||
|
opts.I2S_AudioFreq = freq;
|
||||||
|
opts.I2S_MclkFreq = 80000000;
|
||||||
|
|
||||||
|
printf("\r\n");
|
||||||
|
printf("format:%d, tx_en:%d, freq:%d, ", format, tx_rx, freq);
|
||||||
|
printf("datawidth:%d, stereo:%d, mode:%d\r\n", datawidth, stereo, mode);
|
||||||
|
wm_i2s_port_init(&opts);
|
||||||
|
wm_i2s_register_callback(NULL);
|
||||||
|
|
||||||
|
if (WM_I2S_MODE_INT == mode)
|
||||||
|
{
|
||||||
|
if (tx_rx == WM_I2S_TX)
|
||||||
|
{
|
||||||
|
tls_i2s_tx_int_demo();
|
||||||
|
}
|
||||||
|
if (tx_rx == WM_I2S_RX)
|
||||||
|
{
|
||||||
|
tls_i2s_rx_int_demo();
|
||||||
|
}
|
||||||
|
if (tx_rx == WM_I2S_TR)
|
||||||
|
{
|
||||||
|
opts.I2S_Mode_MS = I2S_MODE_MASTER;
|
||||||
|
tls_i2s_tr_int_demo(&opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (WM_I2S_MODE_DMA == mode)
|
||||||
|
{
|
||||||
|
if (tx_rx == WM_I2S_TX)
|
||||||
|
{
|
||||||
|
tls_i2s_tx_dma_demo();
|
||||||
|
}
|
||||||
|
else if (tx_rx == WM_I2S_RX)
|
||||||
|
{
|
||||||
|
tls_i2s_rx_dma_demo();
|
||||||
|
}
|
||||||
|
else if (tx_rx == WM_I2S_TR)
|
||||||
|
{
|
||||||
|
opts.I2S_Mode_MS = I2S_MODE_MASTER;
|
||||||
|
tls_i2s_tr_dma_demo(&opts);
|
||||||
|
}
|
||||||
|
else if (tx_rx == WM_I2S_TR_SLAVE)
|
||||||
|
{
|
||||||
|
opts.I2S_Mode_MS = I2S_MODE_SLAVE;
|
||||||
|
tls_i2s_tr_dma_demo(&opts);
|
||||||
|
}
|
||||||
|
if(tx_rx > WM_I2S_TX)
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if(g_recv_state == 1)
|
||||||
|
{
|
||||||
|
g_recv_state = 0;
|
||||||
|
count = 0;
|
||||||
|
i = 1;
|
||||||
|
for(; i < DEMO_DATA_SIZE/2; i++)
|
||||||
|
{
|
||||||
|
if(i2s_demo_rx[i] - i2s_demo_rx[i-1] != 1)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
printf("%d: %x-%x\n", i, i2s_demo_rx[i-1], i2s_demo_rx[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if(count)
|
||||||
|
{
|
||||||
|
printf("%d half %X-%X, err %d\n", g_recv_count, i2s_demo_rx[0], i2s_demo_rx[i - 1], count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(g_recv_state == 2)
|
||||||
|
{
|
||||||
|
g_recv_state = 0;
|
||||||
|
if(g_recv_count>0 && g_recv_count % 100 == 0)
|
||||||
|
{
|
||||||
|
printf("\n[%d]total receive %d*4KB bytes\n\n", tls_os_get_time(), g_recv_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
i = DEMO_DATA_SIZE/2 + 1;
|
||||||
|
for(; i < DEMO_DATA_SIZE; i++)
|
||||||
|
{
|
||||||
|
if(i2s_demo_rx[i] - i2s_demo_rx[i-1] != 1)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
printf("%d: %x-%x\n", i, i2s_demo_rx[i-1], i2s_demo_rx[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if(count)
|
||||||
|
{
|
||||||
|
printf("%d all %X-%X, err %d\n", g_recv_count, i2s_demo_rx[DEMO_DATA_SIZE/2], i2s_demo_rx[i - 1], count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (WM_I2S_MODE_INT == mode)
|
||||||
|
{
|
||||||
|
wm_i2s_tx_rx_stop();
|
||||||
|
printf("\ntest done.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
int tls_i2s_io_init(void)
|
||||||
|
{
|
||||||
|
wm_i2s_ck_config(WM_IO_PB_08);
|
||||||
|
wm_i2s_ws_config(WM_IO_PB_09);
|
||||||
|
wm_i2s_di_config(WM_IO_PB_10);
|
||||||
|
wm_i2s_do_config(WM_IO_PB_11);
|
||||||
|
printf("\r\n");
|
||||||
|
printf("ck--PB08, ws--PB09, di--PB10, do--PB11;\r\n");
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*** (C) COPYRIGHT 2014 Winner Microelectronics Co., Ltd. ***/
|
||||||
193
demo/wm_iperf_auto_demo.c
Normal file
193
demo/wm_iperf_auto_demo.c
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "iperf.h"
|
||||||
|
#include "lwip/inet.h"
|
||||||
|
#include "wm_cmdp.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if (DEMO_IPERF_AUTO_TEST && TLS_CONFIG_WIFI_PERF_TEST && TLS_IPERF_AUTO_TEST)
|
||||||
|
|
||||||
|
|
||||||
|
u8 iperf_test_info[15] = {0};
|
||||||
|
|
||||||
|
u8 iperf_test_rev[10] = {0};
|
||||||
|
u8 sever_ip[16];
|
||||||
|
u16 iperfLocalPort = 0;
|
||||||
|
|
||||||
|
extern tls_os_queue_t *tht_q;
|
||||||
|
extern struct tht_param *gThtSys;
|
||||||
|
extern void CreateThroughputTask(void);
|
||||||
|
|
||||||
|
void iperf_start(u8 mode, u8 chnl, u8 interval, u32 maxcnt, u16 localport, u32 severIp)
|
||||||
|
{
|
||||||
|
|
||||||
|
CreateThroughputTask();
|
||||||
|
if (gThtSys)
|
||||||
|
{
|
||||||
|
if(mode)
|
||||||
|
{
|
||||||
|
gThtSys->role = 's';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gThtSys->role = 'c';
|
||||||
|
|
||||||
|
inet_ntoa_r(severIp, (char *)sever_ip, 16);
|
||||||
|
strcpy(gThtSys->server_hostname, (char *)sever_ip);
|
||||||
|
printf("ipaddr:%s\n", gThtSys->server_hostname);
|
||||||
|
|
||||||
|
gThtSys->protocol = Pudp;
|
||||||
|
gThtSys->rate = 0;
|
||||||
|
gThtSys->block_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gThtSys->localport = localport;
|
||||||
|
|
||||||
|
gThtSys->report_interval = interval;
|
||||||
|
gThtSys->duration = maxcnt;
|
||||||
|
gThtSys->port = chnl + PORT - 1;
|
||||||
|
|
||||||
|
tls_os_queue_send(tht_q, (void *)TLS_MSG_WIFI_PERF_TEST_START, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int demo_iperf_auto_test(u8 *ssid, u8 csmode, u8 remoteIP, u8 bgnrate, u8 pcrate, u8 interval, u32 maxcnt)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
u16 i;
|
||||||
|
int ipefTestSock;
|
||||||
|
u8 destip[4];
|
||||||
|
u32 severIp;
|
||||||
|
struct tls_cmd_wl_hw_mode_t hw_mode;
|
||||||
|
struct tls_cmd_link_status_t lk;
|
||||||
|
|
||||||
|
|
||||||
|
memset(&hw_mode, 0, sizeof(struct tls_cmd_wl_hw_mode_t));
|
||||||
|
hw_mode.hw_mode = 2;
|
||||||
|
hw_mode.max_rate = bgnrate;
|
||||||
|
ret = tls_cmd_set_hw_mode(&hw_mode, 1);
|
||||||
|
|
||||||
|
if (!ssid)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nssid:%s\n", ssid);
|
||||||
|
|
||||||
|
ret = tls_wifi_connect(ssid, strlen((char *)ssid), NULL, 0);
|
||||||
|
while(WM_WIFI_JOINED != tls_wifi_get_state())
|
||||||
|
{
|
||||||
|
tls_os_time_delay(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&lk, 0, sizeof(struct tls_cmd_link_status_t));
|
||||||
|
while(lk.ip[0] == 0)
|
||||||
|
{
|
||||||
|
tls_cmd_get_link_status(&lk);
|
||||||
|
tls_os_time_delay(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&destip[0], &lk.ip[0], 4);
|
||||||
|
destip[3] = remoteIP;
|
||||||
|
memcpy(&severIp, &destip[0], 4);
|
||||||
|
|
||||||
|
iperfLocalPort ++;
|
||||||
|
if(iperfLocalPort > 20)
|
||||||
|
{
|
||||||
|
iperfLocalPort = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ipefTestSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
|
||||||
|
if(ipefTestSock < 0)
|
||||||
|
{
|
||||||
|
printf("iperf test socket creat err\n");
|
||||||
|
return WM_FAILED;;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(csmode) //iperf ×÷Ϊ·þÎñ¶Ë
|
||||||
|
{
|
||||||
|
printf("iperf test sever start\n");
|
||||||
|
iperf_start(csmode, destip[2] - 100, interval, maxcnt, iperfLocalPort, severIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in localAddr;
|
||||||
|
memset(&localAddr, 0, sizeof(struct sockaddr_in));
|
||||||
|
localAddr.sin_family = AF_INET;
|
||||||
|
localAddr.sin_port = htons(20000 + iperfLocalPort);
|
||||||
|
memcpy(&localAddr.sin_addr.s_addr, &lk.ip[0], 4);
|
||||||
|
printf("iperf test port:%d\n", 20000 + iperfLocalPort);
|
||||||
|
|
||||||
|
if (bind(ipefTestSock, (const struct sockaddr *)&localAddr, sizeof(const struct sockaddr_in)) < 0)
|
||||||
|
{
|
||||||
|
printf("iperf test bind err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in iperfAddr;
|
||||||
|
memset(&iperfAddr, 0, sizeof(struct sockaddr_in));
|
||||||
|
iperfAddr.sin_family = AF_INET;
|
||||||
|
iperfAddr.sin_port = htons(30000);
|
||||||
|
iperfAddr.sin_addr.s_addr = severIp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (0 != connect(ipefTestSock, (const struct sockaddr *)&iperfAddr, sizeof(const struct sockaddr_in)))
|
||||||
|
{
|
||||||
|
printf("iperf test connect err\n");
|
||||||
|
if(i++ > 5)
|
||||||
|
{
|
||||||
|
closesocket(ipefTestSock);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iperf_test_info[0] = csmode;
|
||||||
|
iperf_test_info[1] = destip[2] - 100;
|
||||||
|
memcpy(&iperf_test_info[2], &lk.ip[0], 4);
|
||||||
|
iperf_test_info[6] = pcrate;
|
||||||
|
iperf_test_info[7] = interval;
|
||||||
|
memcpy(&iperf_test_info[8], &maxcnt, 4);
|
||||||
|
|
||||||
|
if(send(ipefTestSock, (const char *)iperf_test_info, 12, 0) < 0)
|
||||||
|
{
|
||||||
|
printf("iperf test tcp send err\n");
|
||||||
|
closesocket(ipefTestSock);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(csmode == 0)
|
||||||
|
{
|
||||||
|
ret = recv(ipefTestSock, iperf_test_rev, 10, 0);
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
ret = strcmp((const char *)iperf_test_rev, "OK");
|
||||||
|
closesocket(ipefTestSock);
|
||||||
|
if(ret == 0)
|
||||||
|
{
|
||||||
|
printf("iperf test client start\n");
|
||||||
|
tls_os_time_delay(100);
|
||||||
|
iperf_start(csmode, destip[2] - 100, interval, maxcnt, iperfLocalPort, severIp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("iperf test tcp recv err\n");
|
||||||
|
closesocket(ipefTestSock);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
closesocket(ipefTestSock);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
85
demo/wm_lcd_demo.c
Normal file
85
demo/wm_lcd_demo.c
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file wm_lcd.c
|
||||||
|
* @author
|
||||||
|
* @version
|
||||||
|
* @date
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Microelectronics Co., Ltd. All rights reserved.
|
||||||
|
*****************************************************************************/
|
||||||
|
#include "wm_include.h"
|
||||||
|
|
||||||
|
#if DEMO_LCD
|
||||||
|
#include "wm_osal.h"
|
||||||
|
#include "wm_lcd.h"
|
||||||
|
#include "wm_io.h"
|
||||||
|
#include "wm_pmu.h"
|
||||||
|
|
||||||
|
/*********************************************************
|
||||||
|
Available COM and SEGMENT
|
||||||
|
|
||||||
|
COM00:PB_25 COM01:PB_21 COM02:PB_22 COM03:PB_27 COM04:PB_28 COM05:PB_29 COM06:PB_30 COM07:PB_31
|
||||||
|
|
||||||
|
SEG00:PB_23 SEG01:PB_26 SEG02:PB_24 SEG03:PA_07 SEG04:PA_08 SEG05:PA_09 SEG06:PA_10 SEG07:PA_11
|
||||||
|
SEG08:PA_12 SEG09:PA_13 SEG10:PA_14 SEG11:PA_15 SEG12:PB_00 SEG13:PB_01 SEG14:PB_02 SEG15:PB_03
|
||||||
|
SEG16:PB_04 SEG17:PB_05 SEG18:PB_06 SEG19:PB_07 SEG20:PB_08 SEG21:PB_09 SEG22:PB_10 SEG23:PB_11
|
||||||
|
SEG24:PB_12 SEG25:PB_13 SEG26:PB_14 SEG27:PB_15 SEG28:PB_16 SEG29:PB_17 SEG30:PB_18 SEG31:PA_06
|
||||||
|
********************************************************/
|
||||||
|
/*test lcd output after cfg lcd and make lcd pin output fixed state*/
|
||||||
|
void lcd_test(void)
|
||||||
|
{
|
||||||
|
int i,j;
|
||||||
|
tls_lcd_options_t lcd_opts = {
|
||||||
|
true,
|
||||||
|
BIAS_ONEFOURTH,
|
||||||
|
DUTY_ONEEIGHTH,
|
||||||
|
VLCD31,
|
||||||
|
4,
|
||||||
|
60,
|
||||||
|
};
|
||||||
|
/* COM 0-3 */
|
||||||
|
tls_io_cfg_set(WM_IO_PB_25, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PB_21, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PB_22, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION6);
|
||||||
|
|
||||||
|
/* SEG 0-5 */
|
||||||
|
tls_io_cfg_set(WM_IO_PB_23, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PB_26, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PB_24, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PA_07, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PA_08, WM_IO_OPTION6);
|
||||||
|
tls_io_cfg_set(WM_IO_PA_09, WM_IO_OPTION6);
|
||||||
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD);
|
||||||
|
|
||||||
|
/*enable output valid*/
|
||||||
|
tls_reg_write32(HR_LCD_COM_EN, 0xF);
|
||||||
|
tls_reg_write32(HR_LCD_SEG_EN, 0x3F);
|
||||||
|
|
||||||
|
tls_lcd_init(&lcd_opts);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
for(i=0; i<4; i++)
|
||||||
|
{
|
||||||
|
for(j=0; j<6; j++)
|
||||||
|
{
|
||||||
|
tls_lcd_seg_set(i, j, 1);
|
||||||
|
tls_os_time_delay(500);
|
||||||
|
printf("%d %d %d\n", i, j, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<4; i++)
|
||||||
|
{
|
||||||
|
for(j=0; j<6; j++)
|
||||||
|
{
|
||||||
|
tls_lcd_seg_set(i, j, 0);
|
||||||
|
tls_os_time_delay(500);
|
||||||
|
printf("%d %d %d\n", i, j, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
178
demo/wm_master_spi_demo.c
Normal file
178
demo/wm_master_spi_demo.c
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_master_spi_demo.c
|
||||||
|
*
|
||||||
|
* @brief SPI master demo function
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_MASTER_SPI
|
||||||
|
#include "wm_hostspi.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
#define SPI_DATA_LEN 1508
|
||||||
|
int master_spi_send_data(int clk, int type)
|
||||||
|
{
|
||||||
|
int *p;
|
||||||
|
int i;
|
||||||
|
char *tx_buf = NULL;
|
||||||
|
|
||||||
|
/*MASTER SPI configuratioin*/
|
||||||
|
wm_spi_cs_config(WM_IO_PB_04);
|
||||||
|
wm_spi_ck_config(WM_IO_PB_02);
|
||||||
|
wm_spi_di_config(WM_IO_PB_03);
|
||||||
|
wm_spi_do_config(WM_IO_PB_05);
|
||||||
|
printf("\r\n");
|
||||||
|
printf("cs--PB04, ck--PB02, di--PB03, do--PB05;\r\n");
|
||||||
|
|
||||||
|
if (clk < 0)
|
||||||
|
{
|
||||||
|
clk = 1000000; /* default 1M */
|
||||||
|
}
|
||||||
|
if (-1 == type)
|
||||||
|
{
|
||||||
|
type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == type)
|
||||||
|
{
|
||||||
|
tls_spi_trans_type(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tls_spi_trans_type(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, clk);
|
||||||
|
|
||||||
|
tx_buf = tls_mem_alloc(SPI_DATA_LEN);
|
||||||
|
if (NULL == tx_buf)
|
||||||
|
{
|
||||||
|
printf("\nspi_demo tx mem err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tx_buf, 0, SPI_DATA_LEN);
|
||||||
|
strcpy(tx_buf, "data");
|
||||||
|
p = (int *)&tx_buf[4];
|
||||||
|
*p = 1500;
|
||||||
|
p ++;
|
||||||
|
for(i = 0;i < (SPI_DATA_LEN-8)/4;i ++)
|
||||||
|
{
|
||||||
|
*p = 0x12345678;
|
||||||
|
p ++;
|
||||||
|
}
|
||||||
|
printf("SPI Master send 1500 byte, modeA, little endian\n");
|
||||||
|
|
||||||
|
tls_spi_write((u8 *)tx_buf, SPI_DATA_LEN);
|
||||||
|
|
||||||
|
tls_mem_free(tx_buf);
|
||||||
|
|
||||||
|
printf("after send\n");
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int master_spi_recv_data(int clk, int type)
|
||||||
|
{
|
||||||
|
int *p;
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
int errorflag = 0;
|
||||||
|
char *tx_buf = NULL;
|
||||||
|
char *rx_buf = NULL;
|
||||||
|
|
||||||
|
/*MASTER SPI configuratioin*/
|
||||||
|
wm_spi_cs_config(WM_IO_PB_04);
|
||||||
|
wm_spi_ck_config(WM_IO_PB_02);
|
||||||
|
wm_spi_di_config(WM_IO_PB_03);
|
||||||
|
wm_spi_do_config(WM_IO_PB_05);
|
||||||
|
printf("\r\n");
|
||||||
|
printf("cs--PB04, ck--PB02, di--PB03, do--PB05;\r\n");
|
||||||
|
|
||||||
|
if (clk < 0)
|
||||||
|
{
|
||||||
|
clk = 1000000; /* default 1M */
|
||||||
|
}
|
||||||
|
if (-1 == type)
|
||||||
|
{
|
||||||
|
type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == type)
|
||||||
|
{
|
||||||
|
tls_spi_trans_type(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tls_spi_trans_type(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_spi_setup(TLS_SPI_MODE_0, TLS_SPI_CS_LOW, clk);
|
||||||
|
|
||||||
|
printf("SPI Master receive 1500 byte, modeA, little endian\n");
|
||||||
|
|
||||||
|
tx_buf = tls_mem_alloc(SPI_DATA_LEN);
|
||||||
|
if (NULL == tx_buf)
|
||||||
|
{
|
||||||
|
printf("\nspi_demo tx mem err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(tx_buf, 0, SPI_DATA_LEN);
|
||||||
|
strcpy(tx_buf, "up-m");
|
||||||
|
p = (int *)&tx_buf[4];
|
||||||
|
*p = 1500;
|
||||||
|
tls_spi_write((u8 *)tx_buf, SPI_DATA_LEN);
|
||||||
|
|
||||||
|
tls_os_time_delay(100);
|
||||||
|
|
||||||
|
rx_buf = tls_mem_alloc(SPI_DATA_LEN);
|
||||||
|
if (NULL == rx_buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(tx_buf);
|
||||||
|
printf("\nspi_demo rx mem err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(rx_buf, 0, SPI_DATA_LEN);
|
||||||
|
tls_spi_read((u8 *)rx_buf, SPI_DATA_LEN);
|
||||||
|
p = (int *)&rx_buf[0];
|
||||||
|
len = *p;
|
||||||
|
p ++;
|
||||||
|
for(i = 0;i < len/4;i ++)
|
||||||
|
{
|
||||||
|
if(*(p + i) != 0x12345678)
|
||||||
|
{
|
||||||
|
errorflag ++;
|
||||||
|
printf("[%d]=[%x]\n",i, *(p + i));
|
||||||
|
if(errorflag > 100)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(errorflag > 0)
|
||||||
|
{
|
||||||
|
printf("rcv spi data error\r\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("rcv data len: %d\n", len);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_mem_free(tx_buf);
|
||||||
|
tls_mem_free(rx_buf);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
387
demo/wm_mbedtls_demo.c
Normal file
387
demo/wm_mbedtls_demo.c
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_mbedtls_demo.c
|
||||||
|
*
|
||||||
|
* Description: ssl client demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : LiLimin
|
||||||
|
*
|
||||||
|
* Date : 2015-3-24
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "wm_netif.h"
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
#include "mbedtls/net_sockets.h"
|
||||||
|
#include "mbedtls/debug.h"
|
||||||
|
#include "mbedtls/ssl.h"
|
||||||
|
#include "mbedtls/entropy.h"
|
||||||
|
#include "mbedtls/ctr_drbg.h"
|
||||||
|
#include "mbedtls/error.h"
|
||||||
|
#include "mbedtls/certs.h"
|
||||||
|
|
||||||
|
#if DEMO_MBEDTLS
|
||||||
|
|
||||||
|
#define MBEDTLS_DEMO_TASK_PRIO 38
|
||||||
|
#define MBEDTLS_DEMO_TASK_SIZE 2048
|
||||||
|
#define MBEDTLS_DEMO_QUEUE_SIZE 4
|
||||||
|
|
||||||
|
#define MBEDTLS_DEMO_RECV_BUF_LEN 1024
|
||||||
|
|
||||||
|
#define MBEDTLS_DEMO_CMD_START 0x1
|
||||||
|
|
||||||
|
#define MBEDTLS_DEMO_SERVER "www.tencent.com"
|
||||||
|
#define MBEDTLS_DEMO_PORT "443"
|
||||||
|
|
||||||
|
#define MBEDTLS_DEMO_USE_CERT 0
|
||||||
|
|
||||||
|
static bool mbedtls_demo_inited = FALSE;
|
||||||
|
static OS_STK mbedtls_demo_task_stk[MBEDTLS_DEMO_TASK_SIZE];
|
||||||
|
static tls_os_queue_t *mbedtls_demo_task_queue = NULL;
|
||||||
|
|
||||||
|
static const char *http_request = "GET /legal/html/zh-cn/index.html HTTP/1.0\r\n"
|
||||||
|
"Host: "MBEDTLS_DEMO_SERVER"\r\n"
|
||||||
|
"User-Agent: ssl_client\r\n"
|
||||||
|
"\r\n";
|
||||||
|
|
||||||
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
|
static const char mbedtls_demos_pem[] = \
|
||||||
|
"-----BEGIN CERTIFICATE-----\r\n" \
|
||||||
|
"MIIDhzCCAm+gAwIBAgIBADANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \
|
||||||
|
"MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \
|
||||||
|
"MTEwMjEyMTQ0NDAwWhcNMjEwMjEyMTQ0NDAwWjA7MQswCQYDVQQGEwJOTDERMA8G\r\n" \
|
||||||
|
"A1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwggEiMA0G\r\n" \
|
||||||
|
"CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDA3zf8F7vglp0/ht6WMn1EpRagzSHx\r\n" \
|
||||||
|
"mdTs6st8GFgIlKXsm8WL3xoemTiZhx57wI053zhdcHgH057Zk+i5clHFzqMwUqny\r\n" \
|
||||||
|
"50BwFMtEonILwuVA+T7lpg6z+exKY8C4KQB0nFc7qKUEkHHxvYPZP9al4jwqj+8n\r\n" \
|
||||||
|
"YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\r\n" \
|
||||||
|
"R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\r\n" \
|
||||||
|
"KNF+AksjoBXyOGVkCeoMbo4bF6BxyLObyavpw/LPh5aPgAIynplYb6LVAgMBAAGj\r\n" \
|
||||||
|
"gZUwgZIwDAYDVR0TBAUwAwEB/zAdBgNVHQ4EFgQUtFrkpbPe0lL2udWmlQ/rPrzH\r\n" \
|
||||||
|
"/f8wYwYDVR0jBFwwWoAUtFrkpbPe0lL2udWmlQ/rPrzH/f+hP6Q9MDsxCzAJBgNV\r\n" \
|
||||||
|
"BAYTAk5MMREwDwYDVQQKEwhQb2xhclNTTDEZMBcGA1UEAxMQUG9sYXJTU0wgVGVz\r\n" \
|
||||||
|
"dCBDQYIBADANBgkqhkiG9w0BAQUFAAOCAQEAuP1U2ABUkIslsCfdlc2i94QHHYeJ\r\n" \
|
||||||
|
"SsR4EdgHtdciUI5I62J6Mom+Y0dT/7a+8S6MVMCZP6C5NyNyXw1GWY/YR82XTJ8H\r\n" \
|
||||||
|
"DBJiCTok5DbZ6SzaONBzdWHXwWwmi5vg1dxn7YxrM9d0IjxM27WNKs4sDQhZBQkF\r\n" \
|
||||||
|
"pjmfs2cb4oPl4Y9T9meTx/lvdkRYEug61Jfn6cA+qHpyPYdTH+UshITnmp5/Ztkf\r\n" \
|
||||||
|
"m/UTSLBNFNHesiTZeH31NcxYGdHSme9Nc/gfidRa0FLOCfWxRlFqAI47zG9jAQCZ\r\n" \
|
||||||
|
"7Z2mCGDNMhjQc+BYcdnl0lPXjdDK6V0qCg1dVewhUBcW5gZKzV7e9+DpVA==\r\n" \
|
||||||
|
"-----END CERTIFICATE-----\r\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern struct netif *tls_get_netif(void);
|
||||||
|
extern int wm_printf(const char *fmt, ...);
|
||||||
|
|
||||||
|
static void mbedtls_demo_net_status(u8 status)
|
||||||
|
{
|
||||||
|
struct netif *netif = tls_get_netif();
|
||||||
|
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
wm_printf("sta join net failed\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
wm_printf("sta net disconnected\n");
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
wm_printf("sta ip: %v\n", netif->ip_addr.addr);
|
||||||
|
tls_os_queue_send(mbedtls_demo_task_queue, (void *)MBEDTLS_DEMO_CMD_START, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_DEBUG_C)
|
||||||
|
#define DEBUG_LEVEL 3
|
||||||
|
|
||||||
|
static void ssl_client_debug( void *ctx, int level,
|
||||||
|
const char *file, int line,
|
||||||
|
const char *str )
|
||||||
|
{
|
||||||
|
((void) level);
|
||||||
|
|
||||||
|
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
|
||||||
|
fflush( (FILE *) ctx );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int ssl_client_demo(void)
|
||||||
|
{
|
||||||
|
int ret = 1, len;
|
||||||
|
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||||
|
mbedtls_net_context server_fd;
|
||||||
|
unsigned char buf[MBEDTLS_DEMO_RECV_BUF_LEN];
|
||||||
|
const char *pers = "ssl_client";
|
||||||
|
|
||||||
|
mbedtls_entropy_context entropy;
|
||||||
|
mbedtls_ctr_drbg_context ctr_drbg;
|
||||||
|
mbedtls_ssl_context ssl;
|
||||||
|
mbedtls_ssl_config conf;
|
||||||
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
|
mbedtls_x509_crt cacert;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_DEBUG_C)
|
||||||
|
mbedtls_debug_set_threshold( DEBUG_LEVEL );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 0. Initialize the RNG and the session data
|
||||||
|
*/
|
||||||
|
mbedtls_net_init( &server_fd );
|
||||||
|
mbedtls_ssl_init( &ssl );
|
||||||
|
mbedtls_ssl_config_init( &conf );
|
||||||
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
|
mbedtls_x509_crt_init( &cacert );
|
||||||
|
#endif
|
||||||
|
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||||
|
|
||||||
|
mbedtls_printf( "\n . Seeding the random number generator..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
mbedtls_entropy_init( &entropy );
|
||||||
|
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||||
|
(const unsigned char *) pers,
|
||||||
|
strlen( pers ) ) ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_printf( " ok\n" );
|
||||||
|
|
||||||
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
|
/*
|
||||||
|
* 0. Initialize certificates
|
||||||
|
*/
|
||||||
|
mbedtls_printf( " . Loading the CA root certificate ..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_demos_pem,
|
||||||
|
sizeof(mbedtls_demos_pem) );
|
||||||
|
if( ret < 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_printf( " ok (%d skipped)\n", ret );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1. Start the connection
|
||||||
|
*/
|
||||||
|
mbedtls_printf( " . Connecting to tcp/%s/%s...", MBEDTLS_DEMO_SERVER, MBEDTLS_DEMO_PORT );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_net_connect( &server_fd, MBEDTLS_DEMO_SERVER,
|
||||||
|
MBEDTLS_DEMO_PORT, MBEDTLS_NET_PROTO_TCP ) ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_printf( " ok\n" );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 2. Setup stuff
|
||||||
|
*/
|
||||||
|
mbedtls_printf( " . Setting up the SSL/TLS structure..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_ssl_config_defaults( &conf,
|
||||||
|
MBEDTLS_SSL_IS_CLIENT,
|
||||||
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||||
|
MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_printf( " ok\n" );
|
||||||
|
|
||||||
|
/* OPTIONAL is not optimal for security,
|
||||||
|
* but makes interop easier in this simplified example */
|
||||||
|
mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_NONE );
|
||||||
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
|
mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
|
||||||
|
#endif
|
||||||
|
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_DEBUG_C)
|
||||||
|
mbedtls_ssl_conf_dbg( &conf, ssl_client_debug, stdout );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ( ret = mbedtls_ssl_set_hostname( &ssl, MBEDTLS_DEMO_SERVER ) ) != 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 4. Handshake
|
||||||
|
*/
|
||||||
|
mbedtls_printf( " . Performing the SSL/TLS handshake..." );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 )
|
||||||
|
{
|
||||||
|
if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_printf( " ok\n" );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 3. Write the GET request
|
||||||
|
*/
|
||||||
|
mbedtls_printf( " > Write to server:" );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
len = sprintf( (char *) buf, http_request );
|
||||||
|
|
||||||
|
while( ( ret = mbedtls_ssl_write( &ssl, buf, len ) ) <= 0 )
|
||||||
|
{
|
||||||
|
if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||||
|
{
|
||||||
|
mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len = ret;
|
||||||
|
mbedtls_printf( "\r\n\r\n %d bytes written\n\n%s", len, (char *) buf );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 7. Read the HTTP response
|
||||||
|
*/
|
||||||
|
mbedtls_printf( " < Read from server:" );
|
||||||
|
fflush( stdout );
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
len = sizeof( buf ) - 1;
|
||||||
|
memset( buf, 0, sizeof( buf ) );
|
||||||
|
ret = mbedtls_ssl_read( &ssl, buf, len );
|
||||||
|
|
||||||
|
if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if( ret < 0 )
|
||||||
|
{
|
||||||
|
//mbedtls_printf( "failed\n ! mbedtls_ssl_read returned %d\n\n", ret );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ret == 0 )
|
||||||
|
{
|
||||||
|
mbedtls_printf( "\n\nEOF\n\n" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = ret;
|
||||||
|
mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );
|
||||||
|
}
|
||||||
|
while( 1 );
|
||||||
|
|
||||||
|
mbedtls_ssl_close_notify( &ssl );
|
||||||
|
|
||||||
|
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||||
|
|
||||||
|
exit:
|
||||||
|
|
||||||
|
#ifdef MBEDTLS_ERROR_C
|
||||||
|
if( exit_code != MBEDTLS_EXIT_SUCCESS )
|
||||||
|
{
|
||||||
|
char error_buf[100];
|
||||||
|
mbedtls_strerror( ret, error_buf, 100 );
|
||||||
|
mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mbedtls_net_free( &server_fd );
|
||||||
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
|
mbedtls_x509_crt_free( &cacert );
|
||||||
|
#endif
|
||||||
|
mbedtls_ssl_free( &ssl );
|
||||||
|
mbedtls_ssl_config_free( &conf );
|
||||||
|
mbedtls_ctr_drbg_free( &ctr_drbg );
|
||||||
|
mbedtls_entropy_free( &entropy );
|
||||||
|
|
||||||
|
return( exit_code );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mbedtls_demo_task(void *p)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
void *msg;
|
||||||
|
struct tls_ethif *ether_if = tls_netif_get_ethif();
|
||||||
|
|
||||||
|
if (ether_if->status)
|
||||||
|
{
|
||||||
|
wm_printf("sta ip: %v\n", ether_if->ip_addr.addr);
|
||||||
|
tls_os_queue_send(mbedtls_demo_task_queue, (void *)MBEDTLS_DEMO_CMD_START, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for( ; ; )
|
||||||
|
{
|
||||||
|
ret = tls_os_queue_receive(mbedtls_demo_task_queue, (void **)&msg, 0, 0);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
switch ((u32)msg)
|
||||||
|
{
|
||||||
|
case MBEDTLS_DEMO_CMD_START:
|
||||||
|
ssl_client_demo();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//https request demo
|
||||||
|
//This example should make STA connected to AP firstly, then access web page https://www.tencent.com/legal/html/zh-cn/index.html
|
||||||
|
int mbedtls_demo(void)
|
||||||
|
{
|
||||||
|
if (!mbedtls_demo_inited)
|
||||||
|
{
|
||||||
|
tls_os_task_create(NULL, NULL, mbedtls_demo_task,
|
||||||
|
NULL, (void *)mbedtls_demo_task_stk, /* task's stack start address */
|
||||||
|
MBEDTLS_DEMO_TASK_SIZE * sizeof(u32),/* task's stack size, unit:byte */
|
||||||
|
MBEDTLS_DEMO_TASK_PRIO, 0);
|
||||||
|
|
||||||
|
tls_os_queue_create(&mbedtls_demo_task_queue, MBEDTLS_DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_netif_add_status_event(mbedtls_demo_net_status);
|
||||||
|
|
||||||
|
mbedtls_demo_inited = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
219
demo/wm_mcast_demo.c
Normal file
219
demo/wm_mcast_demo.c
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_mcast_demo.c
|
||||||
|
*
|
||||||
|
* Description: mcast demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : wanghaifang
|
||||||
|
*
|
||||||
|
* Date : 2014-6-2
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
|
||||||
|
#if DEMO_UDP_MULTI_CAST
|
||||||
|
#define DEMO_MCAST_TASK_SIZE 256
|
||||||
|
tls_os_queue_t *demo_mcast_q = NULL;
|
||||||
|
static OS_STK DemoMCastTaskStk[DEMO_MCAST_TASK_SIZE];
|
||||||
|
u8 is_snd = 1;
|
||||||
|
|
||||||
|
extern ST_Demo_Sys gDemoSys;
|
||||||
|
static void demo_mcast_task(void *sdata);
|
||||||
|
|
||||||
|
#define MPORT 5100
|
||||||
|
static u8 MCASTIP[4] = {224, 1, 2, 1};
|
||||||
|
#define MCAST_BUF_SIZE 1024
|
||||||
|
int mcastsendrcv(bool snd)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
int ret;
|
||||||
|
int size;
|
||||||
|
int ttl = 10;
|
||||||
|
int loop = 0;
|
||||||
|
int times = 0;
|
||||||
|
int i = 65;
|
||||||
|
char *buffer = NULL;
|
||||||
|
socklen_t socklen;
|
||||||
|
struct sockaddr_in localaddr, fromaddr, Multi_addr;
|
||||||
|
struct ip_mreq mreq;
|
||||||
|
|
||||||
|
s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
if(s < 0)
|
||||||
|
{
|
||||||
|
printf("socket error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printf("multi case socket num=%d\n", s);
|
||||||
|
Multi_addr.sin_family = AF_INET;
|
||||||
|
Multi_addr.sin_port = htons(MPORT);
|
||||||
|
MEMCPY((char *)&Multi_addr.sin_addr, (char *)MCASTIP, 4);
|
||||||
|
|
||||||
|
localaddr.sin_family = AF_INET;
|
||||||
|
localaddr.sin_port = htons(MPORT);
|
||||||
|
localaddr.sin_addr.s_addr = htonl(0x00000000UL);
|
||||||
|
fromaddr.sin_family = AF_INET;
|
||||||
|
fromaddr.sin_port = htons(MPORT);
|
||||||
|
fromaddr.sin_addr.s_addr = htonl(0x00000000UL);
|
||||||
|
ret = bind(s, (struct sockaddr *)&localaddr, sizeof(localaddr));
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
printf("bind error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//Configure multicast TTL
|
||||||
|
if(setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
|
||||||
|
{
|
||||||
|
printf("IP_MULTICAST_TTL");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//Setting local loop for multicast
|
||||||
|
if(setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) < 0)
|
||||||
|
{
|
||||||
|
printf("IP_MULTICAST_LOOP");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
MEMCPY((char *)&mreq.imr_multiaddr.s_addr, (char *)MCASTIP, 4);
|
||||||
|
mreq.imr_interface.s_addr = htonl(0x00000000UL);
|
||||||
|
//join multicast group
|
||||||
|
if(setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
|
||||||
|
{
|
||||||
|
printf("IP_ADD_MEMBERSHIP");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
buffer = tls_mem_alloc(MCAST_BUF_SIZE);
|
||||||
|
if(NULL == buffer)
|
||||||
|
return -1;
|
||||||
|
memset(buffer, 0, MCAST_BUF_SIZE);
|
||||||
|
//loop rx or tx data
|
||||||
|
if(snd)
|
||||||
|
{
|
||||||
|
for(times = 0; times < 20; times++)
|
||||||
|
{
|
||||||
|
memset(buffer, i, MCAST_BUF_SIZE);
|
||||||
|
size = sendto(s, buffer, MCAST_BUF_SIZE, 0, (struct sockaddr *)&Multi_addr, sizeof(Multi_addr));
|
||||||
|
printf("multi case sendto buf=%s, size=%d\n", buffer, size);
|
||||||
|
tls_os_time_delay(50);
|
||||||
|
i++;
|
||||||
|
memset(buffer, 0, MCAST_BUF_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(times = 0; times < 5; times++)
|
||||||
|
{
|
||||||
|
socklen = sizeof(fromaddr);
|
||||||
|
recvfrom(s, buffer, MCAST_BUF_SIZE, 0, (struct sockaddr *)&fromaddr, &socklen);
|
||||||
|
printf("multi case recvfrom buf=%s, socklen=%d\n", buffer, socklen);
|
||||||
|
memset(buffer, 0, MCAST_BUF_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tls_mem_free(buffer);
|
||||||
|
//leave multicast group
|
||||||
|
ret = setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
printf("IP_DROP_MEMBERSHIP");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
closesocket(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CreateMCastDemoTask(char *buf)
|
||||||
|
{
|
||||||
|
if(strstr(buf, "recv"))
|
||||||
|
{
|
||||||
|
is_snd = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
is_snd = 1;
|
||||||
|
printf("is_snd=%d, para:%s\n", is_snd, buf);
|
||||||
|
tls_os_queue_create(&demo_mcast_q, DEMO_QUEUE_SIZE);
|
||||||
|
//Task to deal with socket message
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_mcast_task,
|
||||||
|
NULL,
|
||||||
|
(void *)DemoMCastTaskStk, /* task's stack start address*/
|
||||||
|
DEMO_MCAST_TASK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_MCAST_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void mcast_net_status_changed_event(u8 status )
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
tls_os_queue_send(demo_mcast_q, (void *)DEMO_MSG_WJOIN_FAILD, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
tls_os_queue_send(demo_mcast_q, (void *)DEMO_MSG_WJOIN_SUCCESS, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
tls_os_queue_send(demo_mcast_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void demo_mcast_task(void *sdata)
|
||||||
|
{
|
||||||
|
// ST_Demo_Sys *sys = (ST_Demo_Sys *)sdata;
|
||||||
|
void *msg;
|
||||||
|
struct tls_ethif *ethif = tls_netif_get_ethif();
|
||||||
|
|
||||||
|
printf("\nmcast task\n");
|
||||||
|
|
||||||
|
if(ethif->status) /*connected to ap and get IP*/
|
||||||
|
{
|
||||||
|
tls_os_queue_send(demo_mcast_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct tls_param_ip ip_param;
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
ip_param.dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
tls_wifi_set_oneshot_flag(1); /*Enable oneshot configuration*/
|
||||||
|
printf("\nwait one shot......\n");
|
||||||
|
}
|
||||||
|
tls_netif_add_status_event(mcast_net_status_changed_event);
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(demo_mcast_q, (void **)&msg, 0, 0);
|
||||||
|
//printf("\n msg =%d\n",msg);
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case DEMO_MSG_WJOIN_SUCCESS:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_CREATE:
|
||||||
|
mcastsendrcv(is_snd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_WJOIN_FAILD:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_ERR:
|
||||||
|
printf("\nsocket err\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
765
demo/wm_mqtt_demo.c
Normal file
765
demo/wm_mqtt_demo.c
Normal file
@ -0,0 +1,765 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_mqtt_demo.c
|
||||||
|
*
|
||||||
|
* Description: mqtt demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : LiLimin
|
||||||
|
*
|
||||||
|
* Date : 2019-3-24
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "list.h"
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_netif.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "tls_common.h"
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
#include "lwip/inet.h"
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
#include "libemqtt.h"
|
||||||
|
#include "private-libwebsockets.h"
|
||||||
|
#include "libwebsockets.h"
|
||||||
|
#include "HTTPClient.h"
|
||||||
|
|
||||||
|
#if DEMO_MQTT
|
||||||
|
|
||||||
|
#define MQTT_DEMO_TASK_PRIO 39
|
||||||
|
#define MQTT_DEMO_TASK_SIZE 2048
|
||||||
|
#define MQTT_DEMO_QUEUE_SIZE 16
|
||||||
|
|
||||||
|
#define MQTT_DEMO_RECV_BUF_LEN_MAX 1024
|
||||||
|
|
||||||
|
#define MQTT_DEMO_CMD_START 0x1
|
||||||
|
#define MQTT_DEMO_CMD_HEART 0x2
|
||||||
|
#define MQTT_DEMO_CMD_LOOP 0x3
|
||||||
|
|
||||||
|
#define MQTT_DEMO_READ_TIMEOUT (-1000)
|
||||||
|
|
||||||
|
#define MQTT_DEMO_READ_TIME_SEC 5
|
||||||
|
#define MQTT_DEMO_READ_TIME_US 0
|
||||||
|
|
||||||
|
#define MQTT_DEMO_CLIENT_ID "wm_mqtt_client"
|
||||||
|
#define MQTT_DEMO_TX_PUB_TOPIC "topic_tx"
|
||||||
|
#define MQTT_DEMO_RX_PUB_TOPIC "topic_rx"
|
||||||
|
|
||||||
|
#define MQTT_DEMO_SERVER_ADDR "192.168.1.101"
|
||||||
|
#define MQTT_DEMO_SERVER_PORT_TCP 1883
|
||||||
|
#define MQTT_DEMO_SERVER_PORT_TLS 8883
|
||||||
|
#define MQTT_DEMO_SERVER_PORT_WS 8080
|
||||||
|
#define MQTT_DEMO_SERVER_PORT_WSS 8081
|
||||||
|
|
||||||
|
typedef enum _conn_type
|
||||||
|
{
|
||||||
|
MQTT_CONN_TYPE_TCP = 0,
|
||||||
|
MQTT_CONN_TYPE_TLS,
|
||||||
|
MQTT_CONN_TYPE_WS,
|
||||||
|
MQTT_CONN_TYPE_WSS,
|
||||||
|
}mqtt_conn_type;
|
||||||
|
|
||||||
|
typedef struct _mqtt_demo_context
|
||||||
|
{
|
||||||
|
mqtt_conn_type conn_type;
|
||||||
|
int mqtt_demo_socket_id;
|
||||||
|
tls_ssl_t *ssl;
|
||||||
|
struct lws* ws_context;
|
||||||
|
struct dl_list ws_tx_list;
|
||||||
|
struct dl_list ws_rx_list;
|
||||||
|
uint16_t server_port;
|
||||||
|
int (*connect)(struct _mqtt_demo_context *ctx, const struct sockaddr *name, socklen_t namelen,char *hostname);
|
||||||
|
int (*close_mqtt)(struct _mqtt_demo_context *ctx);
|
||||||
|
int (*send_packet)(int socket_info, const void *buf, unsigned int count);
|
||||||
|
int (*read_packet)(struct _mqtt_demo_context *ctx, uint8_t *buf, int buf_len, int sec, int us);
|
||||||
|
int mqtt_demo_mqtt_keepalive;
|
||||||
|
tls_os_timer_t *mqtt_demo_heartbeat_timer;
|
||||||
|
mqtt_broker_handle_t mqtt_demo_mqtt_broker;
|
||||||
|
uint8_t mqtt_demo_packet_buffer[MQTT_DEMO_RECV_BUF_LEN_MAX];
|
||||||
|
}mqtt_demo_context_t;
|
||||||
|
|
||||||
|
static bool mqtt_demo_inited = FALSE;
|
||||||
|
static OS_STK mqtt_demo_task_stk[MQTT_DEMO_TASK_SIZE];
|
||||||
|
static tls_os_queue_t *mqtt_demo_task_queue = NULL;
|
||||||
|
/*static tls_os_timer_t *mqtt_demo_heartbeat_timer = NULL;
|
||||||
|
|
||||||
|
static int mqtt_demo_socket_id;
|
||||||
|
static int mqtt_demo_mqtt_keepalive = 300;
|
||||||
|
static mqtt_broker_handle_t mqtt_demo_mqtt_broker;
|
||||||
|
|
||||||
|
static uint8_t mqtt_demo_packet_buffer[MQTT_DEMO_RECV_BUF_LEN_MAX];*/
|
||||||
|
|
||||||
|
extern struct netif *tls_get_netif(void);
|
||||||
|
extern int wm_printf(const char *fmt, ...);
|
||||||
|
|
||||||
|
static void mqtt_demo_net_status(u8 status)
|
||||||
|
{
|
||||||
|
struct netif *netif = tls_get_netif();
|
||||||
|
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
wm_printf("sta join net failed\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
wm_printf("sta net disconnected\n");
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
wm_printf("sta ip: %v\n", netif->ip_addr.addr);
|
||||||
|
tls_os_queue_send(mqtt_demo_task_queue, (void *)MQTT_DEMO_CMD_START, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mqtt_demo_heart_timer(void *ptmr, void *parg)
|
||||||
|
{
|
||||||
|
tls_os_status_t os_status = tls_os_queue_send(mqtt_demo_task_queue, (void *)MQTT_DEMO_CMD_HEART, 0);
|
||||||
|
wm_printf("==> heart timer %d\n", os_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct _ws_packet
|
||||||
|
{
|
||||||
|
struct dl_list list;
|
||||||
|
char *buf;
|
||||||
|
int buf_len;
|
||||||
|
}ws_packet;
|
||||||
|
static int lwsCallbackNotify(struct lws *wsi,enum lws_callback_reasons reason,void *user, void *in, size_t len)
|
||||||
|
{
|
||||||
|
mqtt_demo_context_t *ctx = (mqtt_demo_context_t *)user;
|
||||||
|
u32 cpu_sr;
|
||||||
|
ws_packet *packet = NULL;
|
||||||
|
//wm_printf("%s: enter ctx 0x%x, reason %d\n", __func__, ctx, reason);
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||||
|
wm_printf("CLIENT_ESTABLISHED\n");
|
||||||
|
//now_state = HANDLE_SESSION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||||
|
wm_printf("CLIENT_CONNECTION_ERROR\n");
|
||||||
|
//now_state = EXIT_SESSION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLOSED:
|
||||||
|
wm_printf("CLOSED\n");
|
||||||
|
//now_state = EXIT_SESSION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||||
|
//((char *)in)[len] = '\0';
|
||||||
|
wm_printf("lws receive len %d\n", len);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
packet = (ws_packet *)tls_mem_alloc(sizeof(ws_packet));
|
||||||
|
if(packet == NULL)
|
||||||
|
{
|
||||||
|
wm_printf("%s: malloc packet error\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dl_list_init(&packet->list);
|
||||||
|
packet->buf = tls_mem_alloc(len);
|
||||||
|
if(packet->buf == NULL)
|
||||||
|
{
|
||||||
|
tls_mem_free(packet);
|
||||||
|
wm_printf("%s: malloc packet buffer error\n", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memset(packet->buf, 0, len);
|
||||||
|
memcpy(packet->buf, in, len);
|
||||||
|
packet->buf_len = len;
|
||||||
|
cpu_sr = tls_os_set_critical();
|
||||||
|
dl_list_add_tail(&ctx->ws_rx_list, &packet->list);
|
||||||
|
tls_os_release_critical(cpu_sr);
|
||||||
|
//wm_printf("recv packets count %d\n", dl_list_len(&ctx->ws_rx_list));
|
||||||
|
}while(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLIENT_WRITEABLE:
|
||||||
|
//wm_printf("lws writeable list count %d\n", dl_list_len(&ctx->ws_tx_list));
|
||||||
|
packet = dl_list_first(&ctx->ws_tx_list, ws_packet, list);
|
||||||
|
//wm_printf("dl_list_first packet 0x%x\n", packet);
|
||||||
|
if(packet != NULL)
|
||||||
|
{
|
||||||
|
wm_printf("lws_write ");
|
||||||
|
int n = lws_write( wsi, (unsigned char *)packet->buf + LWS_SEND_BUFFER_PRE_PADDING, packet->buf_len, LWS_WRITE_BINARY );
|
||||||
|
wm_printf("ret %d\n", n);
|
||||||
|
if( n <= 0 )
|
||||||
|
{
|
||||||
|
wm_printf("send error %d\r\n", n);
|
||||||
|
}
|
||||||
|
cpu_sr = tls_os_set_critical();
|
||||||
|
dl_list_del(&packet->list);
|
||||||
|
tls_os_release_critical(cpu_sr);
|
||||||
|
tls_mem_free(packet->buf);
|
||||||
|
tls_mem_free(packet);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct lws_protocols protocols[] = {
|
||||||
|
{
|
||||||
|
"mqtt",
|
||||||
|
lwsCallbackNotify,
|
||||||
|
0,
|
||||||
|
2048,
|
||||||
|
0,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
{ NULL, NULL, 0, 0, 0, NULL } /* end */
|
||||||
|
};
|
||||||
|
#define LWS_SERVER_PATH "/"
|
||||||
|
|
||||||
|
static int mqtt_ws_connect(mqtt_demo_context_t *ctx, const struct sockaddr *name, socklen_t namelen,char *hostname)
|
||||||
|
{
|
||||||
|
struct lws_client_connect_info connInfo;
|
||||||
|
struct lws_context_creation_info info;
|
||||||
|
struct lws_context *lwscontext = NULL;
|
||||||
|
|
||||||
|
memset(&info, 0, sizeof(info) );
|
||||||
|
info.port = CONTEXT_PORT_NO_LISTEN;
|
||||||
|
if(ctx->server_port == MQTT_DEMO_SERVER_PORT_WSS)
|
||||||
|
{
|
||||||
|
info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||||
|
}
|
||||||
|
protocols[0].user = ctx;
|
||||||
|
protocols[0].per_session_data_size = sizeof(mqtt_demo_context_t *);
|
||||||
|
wm_printf("protocols[0].user 0x%x\n", protocols[0].user);
|
||||||
|
info.protocols = protocols;
|
||||||
|
info.max_http_header_data=512;
|
||||||
|
info.max_http_header_pool=4;
|
||||||
|
|
||||||
|
lwscontext = lws_create_context(&info);
|
||||||
|
memset(&connInfo, 0 , sizeof(connInfo) );
|
||||||
|
connInfo.context = lwscontext;
|
||||||
|
connInfo.address = MQTT_DEMO_SERVER_ADDR;
|
||||||
|
connInfo.port = ctx->server_port;
|
||||||
|
connInfo.ssl_connection = ctx->server_port == MQTT_DEMO_SERVER_PORT_WSS ? 1 : 0;
|
||||||
|
connInfo.path = LWS_SERVER_PATH;
|
||||||
|
connInfo.host = MQTT_DEMO_SERVER_ADDR;
|
||||||
|
connInfo.userdata = ctx;
|
||||||
|
connInfo.protocol = protocols[0].name;
|
||||||
|
connInfo.ietf_version_or_minus_one=13;
|
||||||
|
connInfo.origin = MQTT_DEMO_SERVER_ADDR;
|
||||||
|
ctx->ws_context = lws_client_connect_via_info( &connInfo );
|
||||||
|
if(ctx->ws_context == NULL )
|
||||||
|
{
|
||||||
|
lws_context_destroy(lwscontext);
|
||||||
|
ctx->ws_context->context = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int mqtt_ws_close_socket(mqtt_demo_context_t *ctx)
|
||||||
|
{
|
||||||
|
wm_printf("EXIT_SESSION ctx 0x%x\n", ctx);
|
||||||
|
if(ctx->ws_context != NULL )
|
||||||
|
{
|
||||||
|
if( ctx->ws_context->context != NULL ) {
|
||||||
|
lws_context_destroy(ctx->ws_context->context);
|
||||||
|
ctx->ws_context->context = NULL;
|
||||||
|
}
|
||||||
|
lws_free(ctx->ws_context);
|
||||||
|
ctx->ws_context = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int mqtt_ws_send_packet(int socket_info, const void *buf, unsigned int count)
|
||||||
|
{
|
||||||
|
mqtt_demo_context_t *ctx = (mqtt_demo_context_t *)socket_info;
|
||||||
|
u32 cpu_sr;
|
||||||
|
ws_packet *packet = (ws_packet *)tls_mem_alloc(sizeof(ws_packet));
|
||||||
|
|
||||||
|
//wm_printf("%s: enter ctx 0x%x\n", __func__, ctx);
|
||||||
|
if(packet == NULL)
|
||||||
|
{
|
||||||
|
wm_printf("%s: malloc packet error\n", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
dl_list_init(&packet->list);
|
||||||
|
packet->buf = tls_mem_alloc(count + LWS_SEND_BUFFER_PRE_PADDING + 4);
|
||||||
|
if(packet->buf == NULL)
|
||||||
|
{
|
||||||
|
tls_mem_free(packet);
|
||||||
|
wm_printf("%s: malloc packet buffer error\n", __func__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(packet->buf, 0, count + LWS_SEND_BUFFER_PRE_PADDING + 4);
|
||||||
|
memcpy(packet->buf + LWS_SEND_BUFFER_PRE_PADDING, buf, count);
|
||||||
|
packet->buf_len = count;
|
||||||
|
cpu_sr = tls_os_set_critical();
|
||||||
|
dl_list_add_tail(&ctx->ws_tx_list, &packet->list);
|
||||||
|
tls_os_release_critical(cpu_sr);
|
||||||
|
//wm_printf("send packets count %d\n", dl_list_len(&ctx->ws_tx_list));
|
||||||
|
lws_callback_on_writable(ctx->ws_context);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
static int mqtt_ws_read_packet(mqtt_demo_context_t *ctx, uint8_t *buf, int buf_len, int sec, int us)
|
||||||
|
{
|
||||||
|
u32 cpu_sr;
|
||||||
|
ws_packet *packet = NULL;
|
||||||
|
int start_tick = tls_os_get_time();
|
||||||
|
volatile int now_tick;
|
||||||
|
int timeout = (sec*1000 + us/1000) * HZ / 1000;
|
||||||
|
//wm_printf("%s: enter ctx 0x%x, timeout %d, start_tick %d\n", __func__, ctx, timeout, start_tick);
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
lws_service(ctx->ws_context->context, 250);
|
||||||
|
lws_callback_on_writable(ctx->ws_context);
|
||||||
|
packet = dl_list_first(&ctx->ws_rx_list, ws_packet, list);
|
||||||
|
//wm_printf("%s dl_list_first packet 0x%x\n", __func__, packet);
|
||||||
|
if(packet != NULL)
|
||||||
|
{
|
||||||
|
if(buf_len > packet->buf_len)
|
||||||
|
{
|
||||||
|
buf_len = packet->buf_len;
|
||||||
|
}
|
||||||
|
memcpy(buf, packet->buf, buf_len);
|
||||||
|
cpu_sr = tls_os_set_critical();
|
||||||
|
dl_list_del(&packet->list);
|
||||||
|
tls_os_release_critical(cpu_sr);
|
||||||
|
tls_mem_free(packet->buf);
|
||||||
|
tls_mem_free(packet);
|
||||||
|
return buf_len;
|
||||||
|
}
|
||||||
|
tls_os_time_delay(10);
|
||||||
|
now_tick = tls_os_get_time();
|
||||||
|
//wm_printf("%s tick now %d | %d < %d\n", __func__, now_tick, (now_tick - start_tick), timeout);
|
||||||
|
}while((now_tick - start_tick) < timeout);
|
||||||
|
//wm_printf("%s return timeout\n", __func__);
|
||||||
|
return MQTT_DEMO_READ_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mqtt_tls_connect(mqtt_demo_context_t *ctx, const struct sockaddr *name, socklen_t namelen,char *hostname)
|
||||||
|
{
|
||||||
|
return HTTPWrapperSSLConnect(&ctx->ssl, ctx->mqtt_demo_socket_id, name, namelen, hostname);
|
||||||
|
}
|
||||||
|
static int mqtt_tls_close_socket(mqtt_demo_context_t *ctx)
|
||||||
|
{
|
||||||
|
return HTTPWrapperSSLClose(ctx->ssl, ctx->mqtt_demo_socket_id);
|
||||||
|
}
|
||||||
|
static int mqtt_tls_send_packet(int socket_info, const void *buf, unsigned int count)
|
||||||
|
{
|
||||||
|
mqtt_demo_context_t *ctx = (mqtt_demo_context_t *)socket_info;
|
||||||
|
return HTTPWrapperSSLSend(ctx->ssl, ctx->mqtt_demo_socket_id, (char *)buf, count, 0);
|
||||||
|
}
|
||||||
|
static int mqtt_tls_read_packet(mqtt_demo_context_t *ctx, uint8_t *buf, int buf_len, int sec, int us)
|
||||||
|
{
|
||||||
|
int ret = HTTPWrapperSSLRecv(ctx->ssl, ctx->mqtt_demo_socket_id, (char *)buf, buf_len, 0);
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
if (SOCKET_SSL_MORE_DATA == ret)
|
||||||
|
{
|
||||||
|
ret = buf_len;
|
||||||
|
}
|
||||||
|
else if(MBEDTLS_ERR_SSL_TIMEOUT == ret)
|
||||||
|
{
|
||||||
|
ret = MQTT_DEMO_READ_TIMEOUT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wm_printf("tls recv %d closed\r\n", ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mqtt_tcp_connect(mqtt_demo_context_t *ctx, const struct sockaddr *name, socklen_t namelen,char *hostname)
|
||||||
|
{
|
||||||
|
return connect(ctx->mqtt_demo_socket_id, name, namelen);
|
||||||
|
}
|
||||||
|
static int mqtt_tcp_close_socket(mqtt_demo_context_t *ctx)
|
||||||
|
{
|
||||||
|
int fd = ctx->mqtt_demo_socket_id;
|
||||||
|
return closesocket(fd);
|
||||||
|
}
|
||||||
|
static int mqtt_tcp_send_packet(int socket_info, const void *buf, unsigned int count)
|
||||||
|
{
|
||||||
|
mqtt_demo_context_t *ctx = (mqtt_demo_context_t *)socket_info;
|
||||||
|
return send(ctx->mqtt_demo_socket_id, buf, count, 0);
|
||||||
|
}
|
||||||
|
static int mqtt_tcp_read_packet(mqtt_demo_context_t *ctx, uint8_t *buf, int buf_len, int sec, int us)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int bytes_rcvd;
|
||||||
|
int fd = ctx->mqtt_demo_socket_id;
|
||||||
|
|
||||||
|
if ((sec >= 0) || (us >= 0))
|
||||||
|
{
|
||||||
|
fd_set readfds;
|
||||||
|
struct timeval tmv;
|
||||||
|
|
||||||
|
// Initialize the file descriptor set
|
||||||
|
FD_ZERO (&readfds);
|
||||||
|
FD_SET (fd, &readfds);
|
||||||
|
|
||||||
|
// Initialize the timeout data structure
|
||||||
|
tmv.tv_sec = sec;
|
||||||
|
tmv.tv_usec = us;
|
||||||
|
|
||||||
|
// select returns 0 if timeout, 1 if input available, -1 if error
|
||||||
|
ret = select(fd + 1, &readfds, NULL, NULL, &tmv);
|
||||||
|
if(ret < 0)
|
||||||
|
return -2;
|
||||||
|
else if(ret == 0)
|
||||||
|
return MQTT_DEMO_READ_TIMEOUT;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if((bytes_rcvd = recv(fd, buf, buf_len, 0)) <= 0)
|
||||||
|
{
|
||||||
|
//printf("%d, %d\r\n", bytes_rcvd, mqtt_demo_socket_id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return bytes_rcvd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mqtt_demo_recv_parse(mqtt_demo_context_t *ctx, int sec, int us)
|
||||||
|
{
|
||||||
|
int total_bytes = 0, bytes_rcvd, packet_length;
|
||||||
|
memset(ctx->mqtt_demo_packet_buffer, 0, sizeof(ctx->mqtt_demo_packet_buffer));
|
||||||
|
|
||||||
|
bytes_rcvd = ctx->read_packet(ctx, (ctx->mqtt_demo_packet_buffer + total_bytes), MQTT_DEMO_RECV_BUF_LEN_MAX, sec, us);
|
||||||
|
if(bytes_rcvd <= 0)
|
||||||
|
{
|
||||||
|
return bytes_rcvd;
|
||||||
|
}
|
||||||
|
//printf("recv [len=%d] : %s\n", bytes_rcvd, mqtt_demo_packet_buffer);
|
||||||
|
total_bytes += bytes_rcvd; // Keep tally of total bytes
|
||||||
|
if (total_bytes < 2)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// now we have the full fixed header in mqtt_demo_packet_buffer
|
||||||
|
// parse it for remaining length and number of bytes
|
||||||
|
uint16_t rem_len = mqtt_parse_rem_len(ctx->mqtt_demo_packet_buffer);
|
||||||
|
uint8_t rem_len_bytes = mqtt_num_rem_len_bytes(ctx->mqtt_demo_packet_buffer);
|
||||||
|
|
||||||
|
//packet_length = mqtt_demo_packet_buffer[1] + 2; // Remaining length + fixed header length
|
||||||
|
// total packet length = remaining length + byte 1 of fixed header + remaning length part of fixed header
|
||||||
|
packet_length = rem_len + rem_len_bytes + 1;
|
||||||
|
|
||||||
|
while(total_bytes < packet_length) // Reading the packet
|
||||||
|
{
|
||||||
|
if((bytes_rcvd = ctx->read_packet(ctx, (ctx->mqtt_demo_packet_buffer + total_bytes), MQTT_DEMO_RECV_BUF_LEN_MAX, sec, us)) <= 0)
|
||||||
|
return -1;
|
||||||
|
total_bytes += bytes_rcvd; // Keep tally of total bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
return packet_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mqtt_demo_init_socket(mqtt_demo_context_t *ctx, const char *hostname, short port, int keepalive)
|
||||||
|
{
|
||||||
|
int flag = 1;
|
||||||
|
struct hostent *hp;
|
||||||
|
|
||||||
|
// Create the socket
|
||||||
|
if((ctx->mqtt_demo_socket_id = socket(PF_INET, SOCK_STREAM, 0)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Disable Nagle Algorithm
|
||||||
|
if (setsockopt(ctx->mqtt_demo_socket_id, IPPROTO_TCP, 0x01, (char *)&flag, sizeof(flag)) < 0)
|
||||||
|
{
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// query host ip start
|
||||||
|
hp = gethostbyname(hostname);
|
||||||
|
if (hp == NULL )
|
||||||
|
{
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_in socket_address;
|
||||||
|
memset(&socket_address, 0, sizeof(struct sockaddr_in));
|
||||||
|
socket_address.sin_family = AF_INET;
|
||||||
|
socket_address.sin_port = htons(port);
|
||||||
|
memcpy(&(socket_address.sin_addr), hp->h_addr, hp->h_length);
|
||||||
|
|
||||||
|
// Connect the socket
|
||||||
|
if((ctx->connect(ctx, (struct sockaddr *)&socket_address, sizeof(socket_address), NULL)) < 0)
|
||||||
|
{
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MQTT stuffs
|
||||||
|
mqtt_set_alive(&ctx->mqtt_demo_mqtt_broker, ctx->mqtt_demo_mqtt_keepalive);
|
||||||
|
ctx->mqtt_demo_mqtt_broker.socketid = (int)ctx;
|
||||||
|
ctx->mqtt_demo_mqtt_broker.mqttsend = ctx->send_packet;
|
||||||
|
//wm_printf("socket id = %d\n", mqtt_demo_socket_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mqtt_demo_init(mqtt_demo_context_t *ctx)
|
||||||
|
{
|
||||||
|
int packet_length, ret = 0;
|
||||||
|
uint16_t msg_id, msg_id_rcv;
|
||||||
|
|
||||||
|
wm_printf("step1: init mqtt lib.\r\n");
|
||||||
|
mqtt_init(&ctx->mqtt_demo_mqtt_broker, MQTT_DEMO_CLIENT_ID);
|
||||||
|
mqtt_init_auth(&ctx->mqtt_demo_mqtt_broker, "admin", "password");
|
||||||
|
|
||||||
|
wm_printf("step2: establishing TCP connection.\r\n");
|
||||||
|
ret = mqtt_demo_init_socket(ctx, MQTT_DEMO_SERVER_ADDR, ctx->server_port, ctx->mqtt_demo_mqtt_keepalive);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
wm_printf("init_socket ret=%d\n", ret);
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
wm_printf("step3: establishing mqtt connection.\r\n");
|
||||||
|
ret = mqtt_connect(&ctx->mqtt_demo_mqtt_broker);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
wm_printf("mqtt_connect ret=%d\n", ret);
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
|
||||||
|
packet_length = mqtt_demo_recv_parse(ctx, MQTT_DEMO_READ_TIME_SEC, MQTT_DEMO_READ_TIME_US);
|
||||||
|
if(packet_length < 0)
|
||||||
|
{
|
||||||
|
wm_printf("Error(%d) on read packet!\n", packet_length);
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MQTTParseMessageType(ctx->mqtt_demo_packet_buffer) != MQTT_MSG_CONNACK)
|
||||||
|
{
|
||||||
|
wm_printf("CONNACK expected!\n");
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx->mqtt_demo_packet_buffer[3] != 0x00)
|
||||||
|
{
|
||||||
|
wm_printf("CONNACK failed!\n");
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wm_printf("step4: subscribe mqtt\r\n");
|
||||||
|
mqtt_subscribe(&ctx->mqtt_demo_mqtt_broker, MQTT_DEMO_TX_PUB_TOPIC, &msg_id);
|
||||||
|
|
||||||
|
packet_length = mqtt_demo_recv_parse(ctx, MQTT_DEMO_READ_TIME_SEC, MQTT_DEMO_READ_TIME_US);
|
||||||
|
if(packet_length < 0)
|
||||||
|
{
|
||||||
|
wm_printf("Error(%d) on read packet!\n", packet_length);
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MQTTParseMessageType(ctx->mqtt_demo_packet_buffer) != MQTT_MSG_SUBACK)
|
||||||
|
{
|
||||||
|
wm_printf("SUBACK expected!\n");
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg_id_rcv = mqtt_parse_msg_id(ctx->mqtt_demo_packet_buffer);
|
||||||
|
if(msg_id != msg_id_rcv)
|
||||||
|
{
|
||||||
|
wm_printf("%d message id was expected, but %d message id was found!\n", msg_id, msg_id_rcv);
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
wm_printf("step4+: unsubscribe mqtt\r\n");
|
||||||
|
mqtt_unsubscribe(&ctx->mqtt_demo_mqtt_broker, MQTT_DEMO_TX_PUB_TOPIC, &msg_id);
|
||||||
|
|
||||||
|
packet_length = mqtt_demo_recv_parse(ctx, MQTT_DEMO_READ_TIME_SEC, MQTT_DEMO_READ_TIME_US);
|
||||||
|
if(packet_length < 0)
|
||||||
|
{
|
||||||
|
wm_printf("Error(%d) on read packet!\n", packet_length);
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(MQTTParseMessageType(ctx->mqtt_demo_packet_buffer) != MQTT_MSG_UNSUBACK)
|
||||||
|
{
|
||||||
|
wm_printf("UNSUBACK expected!\n");
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
wm_printf("step5: start the Heart-beat preservation timer ");
|
||||||
|
ret = tls_os_timer_create(&ctx->mqtt_demo_heartbeat_timer,
|
||||||
|
mqtt_demo_heart_timer,
|
||||||
|
NULL, (10 * HZ), TRUE, NULL);
|
||||||
|
if (TLS_OS_SUCCESS == ret)
|
||||||
|
{
|
||||||
|
tls_os_timer_start(ctx->mqtt_demo_heartbeat_timer);
|
||||||
|
}
|
||||||
|
wm_printf("%s\r\n" , TLS_OS_SUCCESS == ret ? "ok" : "error");
|
||||||
|
|
||||||
|
/* step6: push mqtt subscription (when a subscription message is received) */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mqtt_demo_loop(mqtt_demo_context_t *ctx)
|
||||||
|
{
|
||||||
|
int packet_length = 0;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
counter++;
|
||||||
|
packet_length = mqtt_demo_recv_parse(ctx, 1, 1);
|
||||||
|
if(packet_length > 0)
|
||||||
|
{
|
||||||
|
//wm_printf("recvd Packet Header: 0x%x...\n", mqtt_demo_packet_buffer[0]);
|
||||||
|
|
||||||
|
if (MQTTParseMessageType(ctx->mqtt_demo_packet_buffer) == MQTT_MSG_PUBLISH)
|
||||||
|
{
|
||||||
|
uint8_t topic[100], *msg;
|
||||||
|
uint16_t len;
|
||||||
|
len = mqtt_parse_pub_topic(ctx->mqtt_demo_packet_buffer, topic);
|
||||||
|
topic[len] = '\0'; // for printf
|
||||||
|
len = mqtt_parse_publish_msg(ctx->mqtt_demo_packet_buffer, &msg);
|
||||||
|
msg[len] = '\0'; // for printf
|
||||||
|
wm_printf("recvd: %s >>> %s\n", topic, msg);
|
||||||
|
|
||||||
|
mqtt_publish(&ctx->mqtt_demo_mqtt_broker, (const char *)MQTT_DEMO_RX_PUB_TOPIC, (const char *)msg, len, 0);
|
||||||
|
wm_printf("pushed: %s <<< %s\n", MQTT_DEMO_RX_PUB_TOPIC, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_os_queue_send(mqtt_demo_task_queue, (void *)MQTT_DEMO_CMD_LOOP, 0);
|
||||||
|
}
|
||||||
|
else if (packet_length == MQTT_DEMO_READ_TIMEOUT)
|
||||||
|
{
|
||||||
|
tls_os_queue_send(mqtt_demo_task_queue, (void *)MQTT_DEMO_CMD_LOOP, 0);
|
||||||
|
}
|
||||||
|
else if(packet_length == -1)
|
||||||
|
{
|
||||||
|
wm_printf("mqtt error:(%d), stop mqtt demo!\n", packet_length);
|
||||||
|
tls_os_timer_stop(ctx->mqtt_demo_heartbeat_timer);
|
||||||
|
ctx->close_mqtt(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mqtt_demo_task(void *p)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
void *msg;
|
||||||
|
struct tls_ethif *ether_if = tls_netif_get_ethif();
|
||||||
|
mqtt_demo_context_t *ctx = tls_mem_alloc(sizeof(mqtt_demo_context_t));
|
||||||
|
|
||||||
|
if(ctx == NULL)
|
||||||
|
{
|
||||||
|
wm_printf("MQTT Demo context malloc Error!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memset(ctx, 0, sizeof(mqtt_demo_context_t));
|
||||||
|
ctx->conn_type = (mqtt_conn_type)p;
|
||||||
|
wm_printf("conn_type %u ctx 0x%x mqtt_demo_socket_id 0x%x\n", ctx->conn_type, ctx, (int)&ctx->mqtt_demo_socket_id);
|
||||||
|
switch(ctx->conn_type)
|
||||||
|
{
|
||||||
|
case MQTT_CONN_TYPE_TCP:
|
||||||
|
ctx->connect = mqtt_tcp_connect;
|
||||||
|
ctx->close_mqtt = mqtt_tcp_close_socket;
|
||||||
|
ctx->send_packet = mqtt_tcp_send_packet;
|
||||||
|
ctx->read_packet = mqtt_tcp_read_packet;
|
||||||
|
ctx->server_port = MQTT_DEMO_SERVER_PORT_TCP;
|
||||||
|
break;
|
||||||
|
case MQTT_CONN_TYPE_TLS:
|
||||||
|
ctx->connect = mqtt_tls_connect;
|
||||||
|
ctx->close_mqtt = mqtt_tls_close_socket;
|
||||||
|
ctx->send_packet = mqtt_tls_send_packet;
|
||||||
|
ctx->read_packet = mqtt_tls_read_packet;
|
||||||
|
ctx->server_port = MQTT_DEMO_SERVER_PORT_TLS;
|
||||||
|
break;
|
||||||
|
case MQTT_CONN_TYPE_WS:
|
||||||
|
case MQTT_CONN_TYPE_WSS:
|
||||||
|
ctx->connect = mqtt_ws_connect;
|
||||||
|
ctx->close_mqtt = mqtt_ws_close_socket;
|
||||||
|
ctx->send_packet = mqtt_ws_send_packet;
|
||||||
|
ctx->read_packet = mqtt_ws_read_packet;
|
||||||
|
ctx->server_port = MQTT_CONN_TYPE_WS == ctx->conn_type ? MQTT_DEMO_SERVER_PORT_WS : MQTT_DEMO_SERVER_PORT_WSS;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
wm_printf("conn_type %u is not supported error!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ctx->mqtt_demo_socket_id = -1;
|
||||||
|
ctx->mqtt_demo_mqtt_keepalive = 300;
|
||||||
|
dl_list_init(&ctx->ws_tx_list);
|
||||||
|
dl_list_init(&ctx->ws_rx_list);
|
||||||
|
if (ether_if->status)
|
||||||
|
{
|
||||||
|
wm_printf("sta ip: %v\n", ether_if->ip_addr.addr);
|
||||||
|
tls_os_queue_send(mqtt_demo_task_queue, (void *)MQTT_DEMO_CMD_START, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ; ; )
|
||||||
|
{
|
||||||
|
ret = tls_os_queue_receive(mqtt_demo_task_queue, (void **)&msg, 0, 0);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case MQTT_DEMO_CMD_START:
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ret = mqtt_demo_init(ctx);
|
||||||
|
if (ret)
|
||||||
|
break;
|
||||||
|
tls_os_queue_send(mqtt_demo_task_queue, (void *)MQTT_DEMO_CMD_LOOP, 0);
|
||||||
|
}
|
||||||
|
while (0);
|
||||||
|
break;
|
||||||
|
case MQTT_DEMO_CMD_HEART:
|
||||||
|
wm_printf("send heart ping\r\n");
|
||||||
|
mqtt_ping(&ctx->mqtt_demo_mqtt_broker);
|
||||||
|
break;
|
||||||
|
case MQTT_DEMO_CMD_LOOP:
|
||||||
|
mqtt_demo_loop(ctx);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//mqtt demo
|
||||||
|
//测试服务器:mqtt.yichen.link:3883
|
||||||
|
//服务器端用于发送的订阅主题为:winnermicro/mqtt_tx_demo
|
||||||
|
//服务器端用于接收的订阅主题为:winnermicro/mqtt_rx_demo
|
||||||
|
//工作流程: 接收到winnermicro/mqtt_tx_demo推送的消息后打印在屏幕上,并再次推送到winnermicro/mqtt_rx_demo
|
||||||
|
int mqtt_demo(int type)
|
||||||
|
{
|
||||||
|
if (!mqtt_demo_inited)
|
||||||
|
{
|
||||||
|
tls_os_task_create(NULL, NULL, mqtt_demo_task,
|
||||||
|
(void *)type, (void *)mqtt_demo_task_stk, /* task's stack start address */
|
||||||
|
MQTT_DEMO_TASK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
MQTT_DEMO_TASK_PRIO, 0);
|
||||||
|
|
||||||
|
tls_os_queue_create(&mqtt_demo_task_queue, MQTT_DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_netif_add_status_event(mqtt_demo_net_status);
|
||||||
|
|
||||||
|
mqtt_demo_inited = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
94
demo/wm_ntp_demo.c
Normal file
94
demo/wm_ntp_demo.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_ntp_demo.c
|
||||||
|
*
|
||||||
|
* @brief ntp demo function
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "wm_rtc.h"
|
||||||
|
#include "wm_ntp.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_NTP
|
||||||
|
extern const char DEMO_SET_NTP_S[];
|
||||||
|
|
||||||
|
static int isNetworkOk(void)
|
||||||
|
{
|
||||||
|
struct tls_ethif *etherIf = tls_netif_get_ethif();
|
||||||
|
|
||||||
|
return etherIf->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setAutoConnectMode(void)
|
||||||
|
{
|
||||||
|
u8 auto_reconnect = 0xff;
|
||||||
|
|
||||||
|
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_GET, &auto_reconnect);
|
||||||
|
if(auto_reconnect != WIFI_AUTO_CNT_ON)
|
||||||
|
{
|
||||||
|
auto_reconnect = WIFI_AUTO_CNT_ON;
|
||||||
|
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_SET, &auto_reconnect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//You should config ssid and pwd first before run ntp_demo.
|
||||||
|
int ntp_demo(void)
|
||||||
|
{
|
||||||
|
unsigned int t; //used to save time relative to 1970
|
||||||
|
struct tm *tblock;
|
||||||
|
|
||||||
|
setAutoConnectMode();
|
||||||
|
while(1 != isNetworkOk())
|
||||||
|
{
|
||||||
|
tls_os_time_delay(HZ);
|
||||||
|
printf("waiting for wifi connected......\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
t = tls_ntp_client();
|
||||||
|
|
||||||
|
printf("now Time : %s\n", ctime((const time_t *)&t));
|
||||||
|
tblock = localtime((const time_t *)&t); //switch to local time
|
||||||
|
//printf(" sec=%d,min=%d,hour=%d,mon=%d,year=%d\n",tblock->tm_sec,tblock->tm_min,tblock->tm_hour,tblock->tm_mon,tblock->tm_year);
|
||||||
|
tls_set_rtc(tblock);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ntp_set_server_demo(char *ipaddr1, char *ipaddr2, char *ipaddr3)
|
||||||
|
{
|
||||||
|
int server_no = 0;
|
||||||
|
printf("\n ipaddr1=%x,2=%x,3=%x\n", (u32)ipaddr1, (u32)ipaddr2, (u32)ipaddr3);
|
||||||
|
if (ipaddr1)
|
||||||
|
{
|
||||||
|
tls_ntp_set_server(ipaddr1, server_no++);
|
||||||
|
printf("ntp server %d:%s\n", server_no, ipaddr1);
|
||||||
|
}
|
||||||
|
if (ipaddr2)
|
||||||
|
{
|
||||||
|
tls_ntp_set_server(ipaddr2, server_no ++);
|
||||||
|
printf("ntp server %d:%s\n", server_no, ipaddr2);
|
||||||
|
}
|
||||||
|
if (ipaddr3)
|
||||||
|
{
|
||||||
|
tls_ntp_set_server(ipaddr3, server_no ++);
|
||||||
|
printf("ntp server %d:%s\n", server_no, ipaddr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ntp_query_cfg(void)
|
||||||
|
{
|
||||||
|
tls_ntp_query_sntpcfg();
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
58
demo/wm_pmu_demo.c
Normal file
58
demo/wm_pmu_demo.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_pmu.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_PMU //DEMO_PMU_TIMER
|
||||||
|
|
||||||
|
|
||||||
|
static void pmu_timer0_irq(u8 *arg)
|
||||||
|
{
|
||||||
|
tls_pmu_timer0_stop();
|
||||||
|
printf("pmu timer0 irq\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pmu_timer1_irq(u8 *arg)
|
||||||
|
{
|
||||||
|
tls_pmu_timer1_stop();
|
||||||
|
printf("pmu timer1 irq\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int pmu_timer0_demo(u8 enterStandby)
|
||||||
|
{
|
||||||
|
tls_pmu_clk_select(0);/*0:select 32K RC osc, 1: select 40M divide clock*/
|
||||||
|
tls_pmu_timer0_isr_register((tls_pmu_irq_callback)pmu_timer0_irq, NULL);
|
||||||
|
tls_pmu_timer0_start(10);
|
||||||
|
printf("pmu timer0 test start\n");
|
||||||
|
|
||||||
|
if(enterStandby)
|
||||||
|
{
|
||||||
|
printf("pmu will standby\n");
|
||||||
|
tls_pmu_standby_start();/*If you want to verify sleep function, using function tls_pmu_sleep_start()*/
|
||||||
|
printf("pmu enter standby\n");
|
||||||
|
}
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pmu_timer1_demo(u8 enterStandby)
|
||||||
|
{
|
||||||
|
tls_pmu_clk_select(0);/*0:select 32K RC osc, 1: select 40M divide clock*/
|
||||||
|
tls_pmu_timer1_isr_register((tls_pmu_irq_callback)pmu_timer1_irq, NULL);
|
||||||
|
tls_pmu_timer1_start(5000);
|
||||||
|
printf("pmu timer1 test start\n");
|
||||||
|
|
||||||
|
if(enterStandby)
|
||||||
|
{
|
||||||
|
printf("pmu will standby\n");
|
||||||
|
tls_pmu_standby_start();/*If you want to verify sleep function, using function tls_pmu_sleep_start()*/
|
||||||
|
printf("pmu enter standby\n");
|
||||||
|
}
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
316
demo/wm_pwm_demo.c
Normal file
316
demo/wm_pwm_demo.c
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_pwm_demo.c
|
||||||
|
*
|
||||||
|
* Description: pwm demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : dave
|
||||||
|
*
|
||||||
|
* Date : 2014-7-18
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_pwm.h"
|
||||||
|
#include "wm_cpu.h"
|
||||||
|
#include "wm_io.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_regs.h"
|
||||||
|
#include "wm_dma.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_PWM
|
||||||
|
|
||||||
|
static int pwm_demo_multiplex_config(u8 channel)
|
||||||
|
{
|
||||||
|
switch (channel)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
wm_pwm0_config(WM_IO_PB_00);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
wm_pwm1_config(WM_IO_PB_01);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
wm_pwm2_config(WM_IO_PB_02);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
wm_pwm3_config(WM_IO_PB_03);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
wm_pwm4_config(WM_IO_PA_07);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
wm_pwm0_config(WM_IO_PB_19);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
wm_pwm1_config(WM_IO_PB_20);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
wm_pwm2_config(WM_IO_PA_00);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
wm_pwm3_config(WM_IO_PA_01);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
wm_pwm4_config(WM_IO_PA_04);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pwm_demo_allsyc_mode(u8 channel,u32 freq, u8 duty, u8 num)
|
||||||
|
{
|
||||||
|
pwm_init_param pwm_param;
|
||||||
|
int ret=-1;
|
||||||
|
tls_sys_clk sysclk;
|
||||||
|
|
||||||
|
tls_sys_clk_get(&sysclk);
|
||||||
|
|
||||||
|
memset(&pwm_param, 0, sizeof(pwm_init_param));
|
||||||
|
pwm_param.period = 255;
|
||||||
|
pwm_param.cnt_type = WM_PWM_CNT_TYPE_EDGE_ALIGN_OUT;
|
||||||
|
pwm_param.loop_type = WM_PWM_LOOP_TYPE_LOOP;
|
||||||
|
pwm_param.mode = WM_PWM_OUT_MODE_ALLSYC;
|
||||||
|
pwm_param.inverse_en = DISABLE;
|
||||||
|
pwm_param.pnum = num;
|
||||||
|
pwm_param.pnum_int = DISABLE;
|
||||||
|
pwm_param.duty = duty;
|
||||||
|
pwm_param.channel = channel;
|
||||||
|
pwm_param.clkdiv = sysclk.apbclk*UNIT_MHZ/256/freq;
|
||||||
|
|
||||||
|
ret = tls_pwm_out_init(&pwm_param);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pwm_demo_2syc_mode(u8 channel,u32 freq, u8 duty, u8 num)
|
||||||
|
{
|
||||||
|
pwm_init_param pwm_param;
|
||||||
|
int ret=-1;
|
||||||
|
tls_sys_clk sysclk;
|
||||||
|
|
||||||
|
tls_sys_clk_get(&sysclk);
|
||||||
|
|
||||||
|
memset(&pwm_param, 0, sizeof(pwm_init_param));
|
||||||
|
pwm_param.period = 255;
|
||||||
|
pwm_param.cnt_type = WM_PWM_CNT_TYPE_EDGE_ALIGN_OUT;
|
||||||
|
pwm_param.loop_type = WM_PWM_LOOP_TYPE_LOOP;
|
||||||
|
pwm_param.mode = WM_PWM_OUT_MODE_2SYC;
|
||||||
|
pwm_param.inverse_en = DISABLE;
|
||||||
|
pwm_param.pnum = num;
|
||||||
|
pwm_param.pnum_int = DISABLE;
|
||||||
|
pwm_param.duty = duty;
|
||||||
|
pwm_param.channel = channel;
|
||||||
|
pwm_param.clkdiv = sysclk.apbclk*UNIT_MHZ/256/freq;
|
||||||
|
|
||||||
|
ret = tls_pwm_out_init(&pwm_param);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pwm_demo_mc_mode(u8 channel,u32 freq, u8 duty, u8 num)
|
||||||
|
{
|
||||||
|
pwm_init_param pwm_param;
|
||||||
|
int ret=-1;
|
||||||
|
tls_sys_clk sysclk;
|
||||||
|
|
||||||
|
tls_sys_clk_get(&sysclk);
|
||||||
|
|
||||||
|
memset(&pwm_param, 0, sizeof(pwm_init_param));
|
||||||
|
pwm_param.period = 255;
|
||||||
|
pwm_param.cnt_type = WM_PWM_CNT_TYPE_EDGE_ALIGN_OUT;
|
||||||
|
pwm_param.loop_type = WM_PWM_LOOP_TYPE_LOOP;
|
||||||
|
pwm_param.mode = WM_PWM_OUT_MODE_MC;
|
||||||
|
pwm_param.inverse_en = DISABLE;
|
||||||
|
pwm_param.pnum = num;
|
||||||
|
pwm_param.pnum_int = DISABLE;
|
||||||
|
pwm_param.duty = duty;
|
||||||
|
pwm_param.channel = channel;
|
||||||
|
pwm_param.clkdiv = sysclk.apbclk*UNIT_MHZ/256/freq;
|
||||||
|
|
||||||
|
pwm_param.dten = ENABLE;
|
||||||
|
pwm_param.dtclkdiv = 3;
|
||||||
|
pwm_param.dtcnt = 255;
|
||||||
|
|
||||||
|
ret = tls_pwm_out_init(&pwm_param);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pwm_demo_break_mode(u8 channel,u32 freq, u8 duty)
|
||||||
|
{
|
||||||
|
int ret=-1;
|
||||||
|
|
||||||
|
ret = tls_pwm_brake_mode_config(channel, ENABLE, WM_PWM_BRAKE_OUT_HIGH);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pwm_isr_callback(void)
|
||||||
|
{
|
||||||
|
int fcount=0, rcount=0;
|
||||||
|
int status = tls_reg_read32(HR_PWM_INTSTS);
|
||||||
|
|
||||||
|
if (status & 0x200)
|
||||||
|
{
|
||||||
|
tls_reg_write32(HR_PWM_INTSTS, tls_reg_read32(HR_PWM_INTSTS) & 0x60);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(status&0x40) //ϽµÑØÖжÏ
|
||||||
|
{
|
||||||
|
if((status&300) == 0)
|
||||||
|
{
|
||||||
|
fcount=((tls_reg_read32(HR_PWM_CAPDAT)&0xFFFF0000)>>16);
|
||||||
|
}
|
||||||
|
tls_reg_write32(HR_PWM_INTSTS, tls_reg_read32(HR_PWM_INTSTS) & 0x40);
|
||||||
|
printf("fcount = %d\n",fcount);
|
||||||
|
}
|
||||||
|
if(status&0x00000020) //ÉÏÉýÑØÖжÏ
|
||||||
|
{
|
||||||
|
if((status&0x00000280) == 0)
|
||||||
|
{
|
||||||
|
rcount=(tls_reg_read32(HR_PWM_CAPDAT)&0x0000FFFF);
|
||||||
|
}
|
||||||
|
tls_reg_write32(HR_PWM_INTSTS, tls_reg_read32(HR_PWM_INTSTS) & 0x20);
|
||||||
|
printf("rcount = %d\n",rcount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 pwmDmaCap[100];
|
||||||
|
|
||||||
|
static void pwm_dma_callback(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i=0; i<100; i++)
|
||||||
|
{
|
||||||
|
printf("num:%d, pwmH:%d, pwmL:%d\n", i, (pwmDmaCap[i]>>16), (pwmDmaCap[i]&0x0000ffff));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_capture_mode_int(u8 channel,u32 freq)
|
||||||
|
{
|
||||||
|
tls_sys_clk sysclk;
|
||||||
|
|
||||||
|
tls_sys_clk_get(&sysclk);
|
||||||
|
|
||||||
|
pwm_demo_multiplex_config(channel);
|
||||||
|
|
||||||
|
tls_pwm_stop(channel);
|
||||||
|
|
||||||
|
tls_pwm_isr_register(pwm_isr_callback);
|
||||||
|
tls_pwm_cap_init(channel, sysclk.apbclk*UNIT_MHZ/256/freq, DISABLE, WM_PWM_CAP_RISING_FALLING_EDGE_INT);
|
||||||
|
tls_pwm_start(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pwm_capture_mode_dma(u8 channel,u32 freq)
|
||||||
|
{
|
||||||
|
u8 dmaCh;
|
||||||
|
struct tls_dma_descriptor DmaDesc;
|
||||||
|
tls_sys_clk sysclk;
|
||||||
|
|
||||||
|
tls_sys_clk_get(&sysclk);
|
||||||
|
|
||||||
|
memset(pwmDmaCap, 0, sizeof(pwmDmaCap)/sizeof(char));
|
||||||
|
|
||||||
|
pwm_demo_multiplex_config(channel);
|
||||||
|
tls_pwm_stop(channel);
|
||||||
|
|
||||||
|
dmaCh = tls_dma_request(1, TLS_DMA_FLAGS_CHANNEL_SEL(TLS_DMA_SEL_PWM_CAP0) | TLS_DMA_FLAGS_HARD_MODE);
|
||||||
|
DmaDesc.src_addr = HR_PWM_CAPDAT;
|
||||||
|
DmaDesc.dest_addr = (unsigned int)pwmDmaCap;
|
||||||
|
DmaDesc.dma_ctrl = TLS_DMA_DESC_CTRL_DEST_ADD_INC | TLS_DMA_DESC_CTRL_BURST_SIZE1 | TLS_DMA_DESC_CTRL_DATA_SIZE_WORD | TLS_DMA_DESC_CTRL_TOTAL_BYTES(400);
|
||||||
|
DmaDesc.valid = TLS_DMA_DESC_VALID;
|
||||||
|
DmaDesc.next = NULL;
|
||||||
|
tls_dma_start(dmaCh, &DmaDesc, 0);
|
||||||
|
tls_dma_irq_register(dmaCh, (void (*))pwm_dma_callback, NULL, TLS_DMA_IRQ_TRANSFER_DONE);
|
||||||
|
|
||||||
|
tls_pwm_cap_init(channel, sysclk.apbclk*UNIT_MHZ/256/freq, DISABLE, WM_PWM_CAP_DMA_INT);
|
||||||
|
tls_pwm_start(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used demonstrate pwm usage.
|
||||||
|
*
|
||||||
|
* @param[in] channel pwm channel, range from 0 to 4
|
||||||
|
* @param[in] freq freq range from 3Hz~160kHz
|
||||||
|
* @param[in] duty duty range from 0 to 255
|
||||||
|
* @param[in] mode 0:BRAKE, 1:ALLSYC, 2:2SYC, 3:MC, 4:INDPT
|
||||||
|
* @param[in] pnum period num,range from 0 to 255
|
||||||
|
*
|
||||||
|
* @retval WM_SUCCESS success
|
||||||
|
* @retval WM_FAILED failed
|
||||||
|
*
|
||||||
|
* @note For example, call this like this "pwm_demo(0,20,99,1,0);".
|
||||||
|
*/
|
||||||
|
int pwm_demo(u8 channel, u16 freq, u8 duty, u8 mode, u8 num)
|
||||||
|
{
|
||||||
|
int ret=-1;
|
||||||
|
u8 channel_used = 0;
|
||||||
|
|
||||||
|
channel_used = (channel > 4)? (channel - 5):channel;
|
||||||
|
printf("\r\ninput num:%d, channel:%d, freq:%d, duty:%d, mode:%d, num:%d\r\n", channel, channel_used, freq, duty, mode, num);
|
||||||
|
if(channel < 10)
|
||||||
|
{
|
||||||
|
pwm_demo_multiplex_config(channel);
|
||||||
|
tls_pwm_stop(channel_used);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case WM_PWM_OUT_MODE_INDPT:
|
||||||
|
ret = tls_pwm_init(channel_used, freq, duty, num);
|
||||||
|
if(ret != WM_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
tls_pwm_start(channel_used);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_PWM_OUT_MODE_ALLSYC:
|
||||||
|
ret = pwm_demo_allsyc_mode(channel_used, freq, duty, num);
|
||||||
|
if(ret != WM_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
tls_pwm_start(channel_used);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_PWM_OUT_MODE_2SYC:
|
||||||
|
ret = pwm_demo_2syc_mode(channel_used, freq, duty, num);
|
||||||
|
|
||||||
|
if(ret != WM_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
tls_pwm_start(channel_used);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_PWM_OUT_MODE_MC:
|
||||||
|
ret = pwm_demo_mc_mode(channel_used, freq, duty, num);
|
||||||
|
if(ret != WM_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
tls_pwm_start(channel_used);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_PWM_OUT_MODE_BRAKE:
|
||||||
|
ret = pwm_demo_break_mode(channel_used, freq, duty);
|
||||||
|
if(ret != WM_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
tls_pwm_start(channel_used);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
225
demo/wm_rsa_demo.c
Normal file
225
demo/wm_rsa_demo.c
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_crypto_hard_mbed.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#if DEMO_RSA
|
||||||
|
#include "mbedtls/platform.h"
|
||||||
|
#include "mbedtls/sha1.h"
|
||||||
|
#include "mbedtls/rsa.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Example RSA-1024 keypair, for test purposes
|
||||||
|
*/
|
||||||
|
#define KEY_LEN 128
|
||||||
|
|
||||||
|
#define RSA_N "9292758453063D803DD603D5E777D788" \
|
||||||
|
"8ED1D5BF35786190FA2F23EBC0848AEA" \
|
||||||
|
"DDA92CA6C3D80B32C4D109BE0F36D6AE" \
|
||||||
|
"7130B9CED7ACDF54CFC7555AC14EEBAB" \
|
||||||
|
"93A89813FBF3C4F8066D2D800F7C38A8" \
|
||||||
|
"1AE31942917403FF4946B0A83D3D3E05" \
|
||||||
|
"EE57C6F5F5606FB5D4BC6CD34EE0801A" \
|
||||||
|
"5E94BB77B07507233A0BC7BAC8F90F79"
|
||||||
|
|
||||||
|
#define RSA_E "10001"
|
||||||
|
|
||||||
|
#define RSA_D "24BF6185468786FDD303083D25E64EFC" \
|
||||||
|
"66CA472BC44D253102F8B4A9D3BFA750" \
|
||||||
|
"91386C0077937FE33FA3252D28855837" \
|
||||||
|
"AE1B484A8A9A45F7EE8C0C634F99E8CD" \
|
||||||
|
"DF79C5CE07EE72C7F123142198164234" \
|
||||||
|
"CABB724CF78B8173B9F880FC86322407" \
|
||||||
|
"AF1FEDFDDE2BEB674CA15F3E81A1521E" \
|
||||||
|
"071513A1E85B5DFA031F21ECAE91A34D"
|
||||||
|
|
||||||
|
#define RSA_P "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
|
||||||
|
"2C01CAD19EA484A87EA4377637E75500" \
|
||||||
|
"FCB2005C5C7DD6EC4AC023CDA285D796" \
|
||||||
|
"C3D9E75E1EFC42488BB4F1D13AC30A57"
|
||||||
|
|
||||||
|
#define RSA_Q "C000DF51A7C77AE8D7C7370C1FF55B69" \
|
||||||
|
"E211C2B9E5DB1ED0BF61D0D9899620F4" \
|
||||||
|
"910E4168387E3C30AA1E00C339A79508" \
|
||||||
|
"8452DD96A9A5EA5D9DCA68DA636032AF"
|
||||||
|
|
||||||
|
#define PT_LEN 24
|
||||||
|
#define RSA_PT "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
|
||||||
|
"\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PKCS1_V15)
|
||||||
|
static int myrand( void *rng_state, unsigned char *output, size_t len )
|
||||||
|
{
|
||||||
|
#if !defined(__OpenBSD__)
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if( rng_state != NULL )
|
||||||
|
rng_state = NULL;
|
||||||
|
|
||||||
|
for( i = 0; i < len; ++i )
|
||||||
|
output[i] = rand();
|
||||||
|
#else
|
||||||
|
if( rng_state != NULL )
|
||||||
|
rng_state = NULL;
|
||||||
|
|
||||||
|
arc4random_buf( output, len );
|
||||||
|
#endif /* !OpenBSD */
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
#endif /* MBEDTLS_PKCS1_V15 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checkup routine
|
||||||
|
*/
|
||||||
|
int mbedtls_rsa_self_test( int verbose )
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#if defined(MBEDTLS_PKCS1_V15)
|
||||||
|
size_t len;
|
||||||
|
mbedtls_rsa_context rsa;
|
||||||
|
unsigned char rsa_plaintext[PT_LEN];
|
||||||
|
unsigned char rsa_decrypted[PT_LEN];
|
||||||
|
unsigned char rsa_ciphertext[KEY_LEN];
|
||||||
|
#if defined(MBEDTLS_SHA1_C)
|
||||||
|
unsigned char sha1sum[20];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mbedtls_mpi K;
|
||||||
|
|
||||||
|
mbedtls_mpi_init( &K );
|
||||||
|
mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 );
|
||||||
|
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_N ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, &K, NULL, NULL, NULL, NULL ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_P ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, &K, NULL, NULL, NULL ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_Q ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, &K, NULL, NULL ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_D ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, NULL, &K, NULL ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_E ) );
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, NULL, NULL, &K ) );
|
||||||
|
|
||||||
|
MBEDTLS_MPI_CHK( mbedtls_rsa_complete( &rsa ) );
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( " RSA key validation: " );
|
||||||
|
|
||||||
|
if( mbedtls_rsa_check_pubkey( &rsa ) != 0 ||
|
||||||
|
mbedtls_rsa_check_privkey( &rsa ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n PKCS#1 encryption : " );
|
||||||
|
|
||||||
|
memcpy( rsa_plaintext, RSA_PT, PT_LEN );
|
||||||
|
|
||||||
|
if( mbedtls_rsa_pkcs1_encrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PUBLIC,
|
||||||
|
PT_LEN, rsa_plaintext,
|
||||||
|
rsa_ciphertext ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n PKCS#1 decryption : " );
|
||||||
|
|
||||||
|
if( mbedtls_rsa_pkcs1_decrypt( &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE,
|
||||||
|
&len, rsa_ciphertext, rsa_decrypted,
|
||||||
|
sizeof(rsa_decrypted) ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n" );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SHA1_C)
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( " PKCS#1 data sign : " );
|
||||||
|
|
||||||
|
if( mbedtls_sha1_ret( rsa_plaintext, PT_LEN, sha1sum ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
return( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( mbedtls_rsa_pkcs1_sign( &rsa, myrand, NULL,
|
||||||
|
MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 0,
|
||||||
|
sha1sum, rsa_ciphertext ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n PKCS#1 sig. verify: " );
|
||||||
|
|
||||||
|
if( mbedtls_rsa_pkcs1_verify( &rsa, NULL, NULL,
|
||||||
|
MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 0,
|
||||||
|
sha1sum, rsa_ciphertext ) != 0 )
|
||||||
|
{
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "failed\n" );
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "passed\n" );
|
||||||
|
#endif /* MBEDTLS_SHA1_C */
|
||||||
|
|
||||||
|
if( verbose != 0 )
|
||||||
|
mbedtls_printf( "\n" );
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
mbedtls_mpi_free( &K );
|
||||||
|
mbedtls_rsa_free( &rsa );
|
||||||
|
#else /* MBEDTLS_PKCS1_V15 */
|
||||||
|
((void) verbose);
|
||||||
|
#endif /* MBEDTLS_PKCS1_V15 */
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int rsa_demo(void)
|
||||||
|
{
|
||||||
|
mbedtls_rsa_self_test(1);
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
194
demo/wm_rtc_demo.c
Normal file
194
demo/wm_rtc_demo.c
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_rtc.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/**
|
||||||
|
NOTE: This demo shows a rtc irq occurs at 00:00:00 on everyday;
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define NTP_UPDATE_PERIOD (360*HZ)
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
bool alarm_triger_setting; //rtc irq enabled
|
||||||
|
bool ntp_time_updated; //ntp time updated
|
||||||
|
bool ntp_update_frequency; //ntp update high/low duty
|
||||||
|
uint32_t alarm_time; //rtc irq occurs time;
|
||||||
|
uint32_t alarm_setting_time; //rtc irq enable time;
|
||||||
|
tls_os_timer_t *ntp_update_timer;
|
||||||
|
} rtc_s;
|
||||||
|
|
||||||
|
static rtc_s * rtc_ptr = NULL;
|
||||||
|
|
||||||
|
static void rtc_alarm_irq(void *arg)
|
||||||
|
{
|
||||||
|
struct tm *time_tm = NULL;
|
||||||
|
struct tm rtc_time_tm;
|
||||||
|
rtc_s *rtc = (rtc_s *)arg;
|
||||||
|
|
||||||
|
rtc->alarm_triger_setting = false;
|
||||||
|
rtc->ntp_time_updated = false;
|
||||||
|
|
||||||
|
tls_get_rtc(&rtc_time_tm);
|
||||||
|
|
||||||
|
printf("ALARM INFO...........................\r\n");
|
||||||
|
printf("current rtc time: %04u/%02u/%02u %02u:%02u:%02u\n", rtc_time_tm.tm_year+1900, rtc_time_tm.tm_mon+1, rtc_time_tm.tm_mday, rtc_time_tm.tm_hour, rtc_time_tm.tm_min, rtc_time_tm.tm_sec);
|
||||||
|
|
||||||
|
time_tm = localtime((const time_t *)&rtc->alarm_time);
|
||||||
|
printf("alarm rtc time: %04u/%02u/%02u %02u:%02u:%02u\n", time_tm->tm_year+1900, time_tm->tm_mon+1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
|
||||||
|
|
||||||
|
time_tm = localtime((const time_t *)&rtc->alarm_setting_time);
|
||||||
|
printf("alarm rtc setting time: %04u/%02u/%02u %02u:%02u:%02u\n", time_tm->tm_year+1900, time_tm->tm_mon+1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
|
||||||
|
|
||||||
|
printf("ALARM INFO END...........................\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ntp_update_timer_cb(void *ptmr, void *parg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
uint32_t time_now;
|
||||||
|
struct tm *time_tm = NULL;
|
||||||
|
struct tm rtc_time_tm;
|
||||||
|
|
||||||
|
rtc_s *rtc = (rtc_s *)parg;
|
||||||
|
time_now = tls_ntp_client();
|
||||||
|
|
||||||
|
if(time_now != 0)
|
||||||
|
{
|
||||||
|
time_tm = localtime((const time_t *)&time_now); //switch to local time format
|
||||||
|
if(!rtc->ntp_time_updated)
|
||||||
|
{
|
||||||
|
//rtc->ntp_time_updated = true;
|
||||||
|
tls_set_rtc(time_tm);
|
||||||
|
printf("update rtc time: %04u/%02u/%02u %02u:%02u:%02u\n", time_tm->tm_year+1900, time_tm->tm_mon+1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
printf("current ntp time: %04u/%02u/%02u %02u:%02u:%02u\n", time_tm->tm_year+1900, time_tm->tm_mon+1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rtc->ntp_update_frequency){
|
||||||
|
tls_os_timer_change((tls_os_timer_t *)ptmr, NTP_UPDATE_PERIOD);
|
||||||
|
rtc->ntp_update_frequency = true; //indicate ntp update in low duty
|
||||||
|
printf("ntp timer update running low frequency\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rtc->alarm_triger_setting)
|
||||||
|
{
|
||||||
|
//rtc->alarm_triger_setting = true;
|
||||||
|
rtc->alarm_setting_time = time_now;
|
||||||
|
|
||||||
|
//configure rtc irq occurs at next day on 00:00:00
|
||||||
|
rtc->alarm_time = time_now + 24*3600; //plus one day;
|
||||||
|
time_tm = localtime((const time_t *)&rtc->alarm_time); //switch to local time format
|
||||||
|
time_tm->tm_hour = 0; //overwritten to 0
|
||||||
|
time_tm->tm_min = 0; //overwritten to 0
|
||||||
|
time_tm->tm_sec = 0; //overwritten to 0
|
||||||
|
rtc->alarm_time = mktime(time_tm); //remember the alarm time
|
||||||
|
|
||||||
|
if(1)
|
||||||
|
{
|
||||||
|
tls_rtc_timer_start(time_tm);
|
||||||
|
printf("alarm time setting: %04u/%02u/%02u %02u:%02u:%02u\n", time_tm->tm_year+1900, time_tm->tm_mon+1, time_tm->tm_mday, time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_get_rtc((struct tm *)&rtc_time_tm);
|
||||||
|
printf("current rtc time: %04u/%02u/%02u %02u:%02u:%02u\n", rtc_time_tm.tm_year+1900, rtc_time_tm.tm_mon+1, rtc_time_tm.tm_mday, rtc_time_tm.tm_hour, rtc_time_tm.tm_min, rtc_time_tm.tm_sec);
|
||||||
|
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
printf("ntp update failed...\r\n");
|
||||||
|
tls_os_timer_change((tls_os_timer_t *)ptmr, NTP_UPDATE_PERIOD/100);
|
||||||
|
rtc->ntp_update_frequency = false; //indicate ntp updating in high duty;
|
||||||
|
tls_get_rtc((struct tm *)&rtc_time_tm);
|
||||||
|
printf("old rtc time: %04u/%02u/%02u %02u:%02u:%02u\n", rtc_time_tm.tm_year+1900, rtc_time_tm.tm_mon+1, rtc_time_tm.tm_mday, rtc_time_tm.tm_hour, rtc_time_tm.tm_min, rtc_time_tm.tm_sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
int rtc_demo(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if(rtc_ptr) return 0;
|
||||||
|
|
||||||
|
rtc_ptr = tls_mem_alloc(sizeof(rtc_s));
|
||||||
|
assert(rtc_ptr != NULL);
|
||||||
|
|
||||||
|
memset(rtc_ptr, 0, sizeof(rtc_s));
|
||||||
|
tls_rtc_isr_register(rtc_alarm_irq, (void*)rtc_ptr);
|
||||||
|
ret = tls_os_timer_create(&rtc_ptr->ntp_update_timer,ntp_update_timer_cb,(void*)rtc_ptr, NTP_UPDATE_PERIOD/100, TRUE, (uint8_t *)"ntp_update_timer");
|
||||||
|
|
||||||
|
if(ret == TLS_OS_SUCCESS)
|
||||||
|
{
|
||||||
|
tls_os_timer_start(rtc_ptr->ntp_update_timer);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
tls_mem_free(rtc_ptr);
|
||||||
|
rtc_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int rtc_demo_deinit()
|
||||||
|
{
|
||||||
|
if(rtc_ptr == NULL) return 0;
|
||||||
|
|
||||||
|
tls_os_timer_stop(rtc_ptr->ntp_update_timer);
|
||||||
|
tls_os_timer_delete(rtc_ptr->ntp_update_timer);
|
||||||
|
rtc_ptr->ntp_update_timer = NULL;
|
||||||
|
tls_rtc_timer_stop();
|
||||||
|
tls_mem_free(rtc_ptr);
|
||||||
|
rtc_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_rtc_clock_irq(void *arg)
|
||||||
|
{
|
||||||
|
struct tm tblock;
|
||||||
|
tls_get_rtc(&tblock);
|
||||||
|
printf("rtc clock, sec=%d,min=%d,hour=%d,mon=%d,year=%d\n", tblock.tm_sec, tblock.tm_min, tblock.tm_hour, tblock.tm_mon, tblock.tm_year);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int rtc_demo(void)
|
||||||
|
{
|
||||||
|
struct tm tblock;
|
||||||
|
|
||||||
|
tblock.tm_year = 17;
|
||||||
|
tblock.tm_mon = 11;
|
||||||
|
tblock.tm_mday = 20;
|
||||||
|
tblock.tm_hour = 14;
|
||||||
|
tblock.tm_min = 30;
|
||||||
|
tblock.tm_sec = 0;
|
||||||
|
tls_set_rtc(&tblock);
|
||||||
|
|
||||||
|
tls_rtc_isr_register(demo_rtc_clock_irq, NULL);
|
||||||
|
tblock.tm_year = 17;
|
||||||
|
tblock.tm_mon = 11;
|
||||||
|
tblock.tm_mday = 20;
|
||||||
|
tblock.tm_hour = 14;
|
||||||
|
tblock.tm_min = 30;
|
||||||
|
tblock.tm_sec = 20;
|
||||||
|
tls_rtc_timer_start(&tblock);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(200);
|
||||||
|
tls_get_rtc(&tblock);
|
||||||
|
printf("rtc cnt, sec=%02d,min=%02d,hour=%02d,mon=%02d,year=%02d\n", tblock.tm_sec, tblock.tm_min, tblock.tm_hour, tblock.tm_mon, tblock.tm_year);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
461
demo/wm_scan_demo.c
Normal file
461
demo/wm_scan_demo.c
Normal file
@ -0,0 +1,461 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_scan_demo.c
|
||||||
|
*
|
||||||
|
* Description: wifi scan demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : muqing
|
||||||
|
*
|
||||||
|
* Date : 2018-12-03
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "tls_wireless.h"
|
||||||
|
|
||||||
|
#if DEMO_SCAN
|
||||||
|
|
||||||
|
static char *scan_privacy_string(u8 privacy)
|
||||||
|
{
|
||||||
|
char *sec;
|
||||||
|
|
||||||
|
switch (privacy)
|
||||||
|
{
|
||||||
|
case WM_WIFI_AUTH_MODE_OPEN:
|
||||||
|
sec = "NONE";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WEP_AUTO:
|
||||||
|
sec = "WEP/AUTO";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA_PSK_TKIP:
|
||||||
|
sec = "WPA_PSK/TKIP";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA_PSK_CCMP:
|
||||||
|
sec = "WPA_PSK/CCMP";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA_PSK_AUTO:
|
||||||
|
sec = "WPA_PSK/AUTO";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA2_PSK_TKIP:
|
||||||
|
sec = "WPA2_PSK/TKIP";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA2_PSK_CCMP:
|
||||||
|
sec = "WPA2_PSK/CCMP";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA2_PSK_AUTO:
|
||||||
|
sec = "WPA2_PSK/AUTO";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA_WPA2_PSK_TKIP:
|
||||||
|
sec = "WPA_PSK/WPA2_PSK/TKIP";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA_WPA2_PSK_CCMP:
|
||||||
|
sec = "WPA_PSK/WPA2_PSK/CCMP";
|
||||||
|
break;
|
||||||
|
case WM_WIFI_AUTH_MODE_WPA_WPA2_PSK_AUTO:
|
||||||
|
sec = "WPA_PSK/WPA2_PSK/AUTO";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
sec = "Unknown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *scan_mode_string(u8 mode)
|
||||||
|
{
|
||||||
|
char *ap_mode;
|
||||||
|
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
ap_mode = "IBSS";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ap_mode = "ESS";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ap_mode = "ESS";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ap_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void wifi_scan_handler(void)
|
||||||
|
{
|
||||||
|
char *buf = NULL;
|
||||||
|
char *buf1 = NULL;
|
||||||
|
u32 buflen;
|
||||||
|
int i, j;
|
||||||
|
int err;
|
||||||
|
u8 ssid[33];
|
||||||
|
struct tls_scan_bss_t *wsr;
|
||||||
|
struct tls_bss_info_t *bss_info;
|
||||||
|
|
||||||
|
buflen = 2000;
|
||||||
|
buf = tls_mem_alloc(buflen);
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf1 = tls_mem_alloc(300);
|
||||||
|
if(!buf1)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
memset(buf1, 0, 300);
|
||||||
|
|
||||||
|
err = tls_wifi_get_scan_rslt((u8 *)buf, buflen);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
wsr = (struct tls_scan_bss_t *)buf;
|
||||||
|
bss_info = (struct tls_bss_info_t *)(buf + 8);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
for(i = 0; i < wsr->count; i++)
|
||||||
|
{
|
||||||
|
j = sprintf(buf1, "bssid:%02X%02X%02X%02X%02X%02X, ", bss_info->bssid[0], bss_info->bssid[1],
|
||||||
|
bss_info->bssid[2], bss_info->bssid[3], bss_info->bssid[4], bss_info->bssid[5]);
|
||||||
|
j += sprintf(buf1 + j, "ch:%d, ", bss_info->channel);
|
||||||
|
j += sprintf(buf1 + j, "rssi:%d, ", (signed char)bss_info->rssi);
|
||||||
|
j += sprintf(buf1 + j, "wps:%d, ", bss_info->wps_support);
|
||||||
|
j += sprintf(buf1 + j, "max_rate:%dMbps, ", bss_info->max_data_rate);
|
||||||
|
j += sprintf(buf1 + j, "%s, ", scan_mode_string(bss_info->mode));
|
||||||
|
j += sprintf(buf1 + j, "%s, ", scan_privacy_string(bss_info->privacy));
|
||||||
|
memcpy(ssid, bss_info->ssid, bss_info->ssid_len);
|
||||||
|
ssid[bss_info->ssid_len] = '\0';
|
||||||
|
j += sprintf(buf1 + j, "%s", ssid);
|
||||||
|
|
||||||
|
printf("%s\n", buf1);
|
||||||
|
|
||||||
|
bss_info ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf);
|
||||||
|
}
|
||||||
|
if(buf1)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wifi_scan_format2_handler(void)
|
||||||
|
{
|
||||||
|
char *buf = NULL;
|
||||||
|
char *buf1 = NULL;
|
||||||
|
u32 buflen;
|
||||||
|
int i, j;
|
||||||
|
int err;
|
||||||
|
u8 ssid[33];
|
||||||
|
struct tls_scan_bss_format2_t *wsr;
|
||||||
|
struct tls_bss_info_format2_t *bss_info;
|
||||||
|
|
||||||
|
buflen = 2000;
|
||||||
|
buf = tls_mem_alloc(buflen);
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf1 = tls_mem_alloc(300);
|
||||||
|
if(!buf1)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
memset(buf1, 0, 300);
|
||||||
|
|
||||||
|
err = tls_wifi_get_scan_rslt_format2((u8 *)buf, buflen);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
wsr = (struct tls_scan_bss_format2_t *)buf;
|
||||||
|
bss_info = (struct tls_bss_info_format2_t *)(buf + 8);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
for(i = 0; i < wsr->count; i++)
|
||||||
|
{
|
||||||
|
j = sprintf(buf1, "(%d,", bss_info->ecn);
|
||||||
|
memcpy(ssid, bss_info->ssid, bss_info->ssid_len);
|
||||||
|
ssid[bss_info->ssid_len] = '\0';
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%s", ssid);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, ",%d, ", (signed char)bss_info->rssi);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "\"%02x:%02x:%02x:%02x:%02x:%02x\", ", bss_info->bssid[0], bss_info->bssid[1],
|
||||||
|
bss_info->bssid[2], bss_info->bssid[3], bss_info->bssid[4], bss_info->bssid[5]);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d, ", bss_info->channel);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d, ", bss_info->group_cipher);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d, ", bss_info->pairwise_cipher);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d, ", bss_info->bgn);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->wps_support);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->freq_offset);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d)", bss_info->freqcal_val);
|
||||||
|
|
||||||
|
|
||||||
|
printf("%s\n", buf1);
|
||||||
|
|
||||||
|
bss_info ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf);
|
||||||
|
}
|
||||||
|
if(buf1)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct specified_scan_info
|
||||||
|
{
|
||||||
|
u8 specified_ssid[33];
|
||||||
|
u16 specified_ssid_len;
|
||||||
|
u8 specified_bssid[18];
|
||||||
|
u8 specified_chan;
|
||||||
|
u8 specified_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct specified_scan_info specifiedinfo;
|
||||||
|
|
||||||
|
static void wifi_scan_format2_filter_handler(void)
|
||||||
|
{
|
||||||
|
char *buf = NULL;
|
||||||
|
char *buf1 = NULL;
|
||||||
|
u32 buflen;
|
||||||
|
int i, j;
|
||||||
|
int err;
|
||||||
|
u8 ssid[33];
|
||||||
|
u8 bssid[18];
|
||||||
|
struct tls_scan_bss_format2_t *wsr;
|
||||||
|
struct tls_bss_info_format2_t *bss_info;
|
||||||
|
u8 bitmask = 0;
|
||||||
|
|
||||||
|
buflen = 2000;
|
||||||
|
buf = tls_mem_alloc(buflen);
|
||||||
|
if (!buf)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf1 = tls_mem_alloc(300);
|
||||||
|
if(!buf1)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
memset(buf1, 0, 300);
|
||||||
|
|
||||||
|
err = tls_wifi_get_scan_rslt_format2((u8 *)buf, buflen);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
wsr = (struct tls_scan_bss_format2_t *)buf;
|
||||||
|
bss_info = (struct tls_bss_info_format2_t *)(buf + 8);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
bitmask = specifiedinfo.specified_mask;
|
||||||
|
for(i = 0; i < wsr->count; i++)
|
||||||
|
{
|
||||||
|
j = sprintf(buf1, "(%d,", bss_info->ecn);
|
||||||
|
if (bitmask&0x1)
|
||||||
|
{
|
||||||
|
if((specifiedinfo.specified_ssid_len != bss_info->ssid_len)
|
||||||
|
|| memcmp(bss_info->ssid,specifiedinfo.specified_ssid,bss_info->ssid_len))
|
||||||
|
{
|
||||||
|
bss_info++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(ssid, bss_info->ssid, bss_info->ssid_len);
|
||||||
|
ssid[bss_info->ssid_len] = '\0';
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%s", ssid);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, ",%d,", (signed char)bss_info->rssi);
|
||||||
|
|
||||||
|
if (bitmask&0x2)
|
||||||
|
{
|
||||||
|
sprintf((char *)bssid, "%02x:%02x:%02x:%02x:%02x:%02x", bss_info->bssid[0], bss_info->bssid[1],
|
||||||
|
bss_info->bssid[2], bss_info->bssid[3], bss_info->bssid[4], bss_info->bssid[5]);
|
||||||
|
if (strcmp((const char *)bssid, (const char *)specifiedinfo.specified_bssid))
|
||||||
|
{
|
||||||
|
bss_info++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
j += sprintf(buf1 + j, "\"%02x:%02x:%02x:%02x:%02x:%02x\",", bss_info->bssid[0], bss_info->bssid[1],
|
||||||
|
bss_info->bssid[2], bss_info->bssid[3], bss_info->bssid[4], bss_info->bssid[5]);
|
||||||
|
|
||||||
|
if (bitmask&0x4)
|
||||||
|
{
|
||||||
|
if (bss_info->channel != specifiedinfo.specified_chan)
|
||||||
|
{
|
||||||
|
bss_info++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->channel);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->freq_offset);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->freqcal_val);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->pairwise_cipher);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->group_cipher);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d,", bss_info->bgn);
|
||||||
|
|
||||||
|
j += sprintf(buf1 + j, "%d)", bss_info->wps_support);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("%s\n", buf1);
|
||||||
|
|
||||||
|
bss_info ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf);
|
||||||
|
}
|
||||||
|
if(buf1)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int user_scan_specified(u8 *ssid, u8 *mac, u8 chan, u8 scan_type, u32 min_interval, u32 max_interval)
|
||||||
|
{
|
||||||
|
struct tls_wifi_scan_param_t wscan_param;
|
||||||
|
|
||||||
|
memset(&specifiedinfo, 0, sizeof(specifiedinfo));
|
||||||
|
specifiedinfo.specified_mask = 0;
|
||||||
|
if (strlen((const char *)ssid) && (strlen((const char *)ssid) < 33))
|
||||||
|
{
|
||||||
|
memset(specifiedinfo.specified_ssid, 0, 33);
|
||||||
|
strcpy((char *)specifiedinfo.specified_ssid, (char *)ssid);
|
||||||
|
specifiedinfo.specified_ssid_len = strlen((const char *)ssid);
|
||||||
|
specifiedinfo.specified_mask = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
specifiedinfo.specified_ssid[0] = '\0';
|
||||||
|
specifiedinfo.specified_ssid_len = 0;
|
||||||
|
specifiedinfo.specified_mask &= ~1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen((const char *)mac) == 17)
|
||||||
|
{
|
||||||
|
memset(specifiedinfo.specified_bssid, 0, 17);
|
||||||
|
strcpy((char *)specifiedinfo.specified_bssid, (char *)mac);
|
||||||
|
specifiedinfo.specified_mask |= 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
specifiedinfo.specified_bssid[0] = '\0';
|
||||||
|
specifiedinfo.specified_mask &= ~2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scan_type)
|
||||||
|
{
|
||||||
|
wscan_param.scan_type = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wscan_param.scan_type = 0;
|
||||||
|
}
|
||||||
|
if (chan == 0)
|
||||||
|
{
|
||||||
|
specifiedinfo.specified_chan = 0;
|
||||||
|
wscan_param.scan_chanlist = 0x1FFF;
|
||||||
|
specifiedinfo.specified_mask &= ~4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
specifiedinfo.specified_chan = chan;
|
||||||
|
specifiedinfo.specified_mask |=4;
|
||||||
|
wscan_param.scan_chanlist = 1<<(chan-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (min_interval == 0)
|
||||||
|
{
|
||||||
|
wscan_param.scan_chinterval = 120;
|
||||||
|
wscan_param.scan_times = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wscan_param.scan_chinterval = min_interval;
|
||||||
|
if (max_interval >= min_interval)
|
||||||
|
{
|
||||||
|
wscan_param.scan_times = (max_interval + min_interval/2)/min_interval;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wscan_param.scan_times = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_wifi_scan_by_param(&wscan_param);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Scan demo*/
|
||||||
|
int scan_demo(void)
|
||||||
|
{
|
||||||
|
tls_wifi_scan_result_cb_register(wifi_scan_handler);
|
||||||
|
tls_wifi_scan();
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scan_format2_demo(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
tls_wifi_scan_result_cb_register(wifi_scan_format2_handler);
|
||||||
|
tls_wifi_scan();
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*specified Scan demo*/
|
||||||
|
int scan_specified_demo(u8 *ssid, u8 *mac, u32 chan, u32 scan_type, u32 min_interval, u32 max_interval)
|
||||||
|
{
|
||||||
|
tls_wifi_scan_result_cb_register(wifi_scan_format2_filter_handler);
|
||||||
|
user_scan_specified(ssid, mac, chan, scan_type, min_interval, max_interval);
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
142
demo/wm_sck_client_demo.c
Normal file
142
demo/wm_sck_client_demo.c
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "lwip/errno.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define DEMO_SOCK_BUF_SIZE 512
|
||||||
|
static const char *sock_tx = "message from client";
|
||||||
|
|
||||||
|
int socket_num = -1;
|
||||||
|
static int socket_client_connect(int port, char *ip);
|
||||||
|
|
||||||
|
static void c_con_net_status_changed_event(u8 status )
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
{
|
||||||
|
struct tls_ethif * tmpethif = tls_netif_get_ethif();
|
||||||
|
#if TLS_CONFIG_IPV4
|
||||||
|
print_ipaddr(&tmpethif->ip_addr);
|
||||||
|
#if TLS_CONFIG_IPV6
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[0]);
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[1]);
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[2]);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
printf("net up ==> ip = %d.%d.%d.%d\n",ip4_addr1(&tmpethif->ip_addr.addr),ip4_addr2(&tmpethif->ip_addr.addr),
|
||||||
|
ip4_addr3(&tmpethif->ip_addr.addr),ip4_addr4(&tmpethif->ip_addr.addr));
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
//shutdown(socket_num,0);
|
||||||
|
closesocket(socket_num);
|
||||||
|
socket_num = -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int c_connect_wifi(char *ssid, char *pwd)
|
||||||
|
{
|
||||||
|
if (!ssid)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
printf("\nssid:%s\n", ssid);
|
||||||
|
printf("password=%s\n",pwd);
|
||||||
|
|
||||||
|
tls_netif_add_status_event(c_con_net_status_changed_event);
|
||||||
|
|
||||||
|
tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int socket_client_connect(int port, char *ip)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char sock_rx[DEMO_SOCK_BUF_SIZE] = {0};
|
||||||
|
struct sockaddr_in pin;
|
||||||
|
printf("port:%d,ip:%s\n",port,ip);
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
memset(&pin, 0, sizeof(struct sockaddr));
|
||||||
|
pin.sin_family=AF_INET;
|
||||||
|
|
||||||
|
pin.sin_addr.s_addr = ipaddr_addr(ip);
|
||||||
|
pin.sin_port=htons(port);
|
||||||
|
if((socket_num = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0)
|
||||||
|
{
|
||||||
|
printf("creat socket fail, errno:%d\n",errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connect(socket_num, (struct sockaddr *)&pin, sizeof(struct sockaddr)) != 0)
|
||||||
|
{
|
||||||
|
printf("connect fail errno:%d\n",errno);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("connect success\n");
|
||||||
|
}
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1000);
|
||||||
|
ret = send(socket_num, sock_tx, strlen(sock_tx), 0);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
printf("Error occured during sending, errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = recv(socket_num, sock_rx, sizeof(sock_rx)-1, 0);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
printf("Receive failed, errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sock_rx[ret] = 0;
|
||||||
|
printf("\nReceive %d bytes from %s\n",ret,ip);
|
||||||
|
printf("%s\n",sock_rx);
|
||||||
|
}
|
||||||
|
tls_os_time_delay(2);
|
||||||
|
}
|
||||||
|
if(socket_num != -1)
|
||||||
|
{
|
||||||
|
printf("shutting down socket and restaring...\n");
|
||||||
|
shutdown(socket_num,0);
|
||||||
|
closesocket(socket_num);
|
||||||
|
socket_num = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_socket_client(char *ssid, char *pwd,int port,char *ip)
|
||||||
|
{
|
||||||
|
struct tls_ethif * ethif;
|
||||||
|
c_connect_wifi(ssid,pwd);
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
ethif = tls_netif_get_ethif();
|
||||||
|
if(ethif->status)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
socket_client_connect(port,ip);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
162
demo/wm_sck_server_demo.c
Normal file
162
demo/wm_sck_server_demo.c
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
#include "wm_include.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "lwip/errno.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define DEMO_SOCK_BUF_SIZE 512
|
||||||
|
static const char *sock_tx = "message from server";
|
||||||
|
|
||||||
|
int new_fd = -1;
|
||||||
|
int server_fd = -1;
|
||||||
|
|
||||||
|
static int create_socket_server(int port);
|
||||||
|
|
||||||
|
static void s_con_net_status_changed_event(u8 status )
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
{
|
||||||
|
struct tls_ethif * tmpethif = tls_netif_get_ethif();
|
||||||
|
#if TLS_CONFIG_IPV4
|
||||||
|
print_ipaddr(&tmpethif->ip_addr);
|
||||||
|
#if TLS_CONFIG_IPV6
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[0]);
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[1]);
|
||||||
|
print_ipaddr(&tmpethif->ip6_addr[2]);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
printf("net up ==> ip = %d.%d.%d.%d\n",ip4_addr1(&tmpethif->ip_addr.addr),ip4_addr2(&tmpethif->ip_addr.addr),
|
||||||
|
ip4_addr3(&tmpethif->ip_addr.addr),ip4_addr4(&tmpethif->ip_addr.addr));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
printf("network disconnection\n");
|
||||||
|
closesocket(new_fd);
|
||||||
|
closesocket(server_fd);
|
||||||
|
new_fd = -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int s_connect_wifi(char *ssid, char *pwd)
|
||||||
|
{
|
||||||
|
if (!ssid)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
printf("\nssid:%s\n", ssid);
|
||||||
|
printf("password=%s\n",pwd);
|
||||||
|
tls_netif_add_status_event(s_con_net_status_changed_event);
|
||||||
|
|
||||||
|
tls_wifi_connect((u8 *)ssid, strlen(ssid), (u8 *)pwd, strlen(pwd));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int create_socket_server(int port)
|
||||||
|
{
|
||||||
|
|
||||||
|
char sock_rx[DEMO_SOCK_BUF_SIZE] = {0};
|
||||||
|
struct sockaddr_in server_addr; // server address information
|
||||||
|
struct sockaddr_in client_addr; // connector's address information
|
||||||
|
socklen_t sin_size;
|
||||||
|
int ret;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||||
|
{
|
||||||
|
printf("create socket fail,errno :%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
server_addr.sin_family = AF_INET;
|
||||||
|
server_addr.sin_port = htons(port);
|
||||||
|
server_addr.sin_addr.s_addr = ((u32) 0x00000000UL);
|
||||||
|
memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));
|
||||||
|
|
||||||
|
if (bind(server_fd, (struct sockaddr *) &server_addr,
|
||||||
|
sizeof(server_addr)) != 0)
|
||||||
|
{
|
||||||
|
printf("bind fail, errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listen(server_fd, 1) != 0)
|
||||||
|
{
|
||||||
|
printf("listen fail,errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("listen port %d\n", port);
|
||||||
|
sin_size = sizeof(client_addr);
|
||||||
|
new_fd = accept(server_fd, (struct sockaddr *) &client_addr,
|
||||||
|
&sin_size);
|
||||||
|
printf("accept newfd = %d\n",new_fd);
|
||||||
|
|
||||||
|
if (new_fd < 0)
|
||||||
|
{
|
||||||
|
printf("accept fail,errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
memset(sock_rx, 0, DEMO_SOCK_BUF_SIZE);
|
||||||
|
ret = recv(new_fd, sock_rx, sizeof(sock_rx)-1, 0);
|
||||||
|
if(ret == 0)
|
||||||
|
{
|
||||||
|
printf("connection disconnect\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(ret < 0)
|
||||||
|
{
|
||||||
|
printf("receive fail errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sock_rx[ret] = 0;
|
||||||
|
printf("\nReceive %d bytes from %s\n", ret, inet_ntoa(client_addr.sin_addr.s_addr));
|
||||||
|
printf("%s\n",sock_rx);
|
||||||
|
ret = send(new_fd, sock_tx, strlen(sock_tx), 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("Error occured during sending,errno:%d\n",errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(new_fd != -1)
|
||||||
|
{
|
||||||
|
printf("shutting down socket and restaring...\n");
|
||||||
|
shutdown(new_fd,0);
|
||||||
|
closesocket(new_fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void demo_socket_server(char *ssid,char *pwd, int port)
|
||||||
|
{
|
||||||
|
struct tls_ethif * ethif;
|
||||||
|
s_connect_wifi(ssid, pwd);
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
ethif = tls_netif_get_ethif();
|
||||||
|
if(ethif->status)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
create_socket_server(port);
|
||||||
|
}
|
||||||
280
demo/wm_sdio_host_demo.c
Normal file
280
demo/wm_sdio_host_demo.c
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_sdio_host.h"
|
||||||
|
#include "wm_debug.h"
|
||||||
|
#include "wm_dma.h"
|
||||||
|
#include "wm_cpu.h"
|
||||||
|
#include "random.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
#if DEMO_SDIO_HOST
|
||||||
|
extern int wm_sd_card_set_blocklen(uint32_t blocklen);
|
||||||
|
extern int wm_sd_card_query_status(uint32_t rca, uint32_t *respCmd0);
|
||||||
|
#define TEST_DEBUG_EN 0
|
||||||
|
#if TEST_DEBUG_EN
|
||||||
|
#define TEST_DEBUG(fmt, ...) printf("%s: "fmt, __func__, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define TEST_DEBUG(fmt, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* single block write & read
|
||||||
|
* bus_width: 0:1bit; 2:4bits
|
||||||
|
* */
|
||||||
|
static int sdh_card_wr_sb(uint32_t rca, uint8_t bus_width, const uint32_t tsize)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
int i = 0;
|
||||||
|
char* buf = NULL;
|
||||||
|
char* bufR = NULL;
|
||||||
|
uint32_t sd_addr = 0;
|
||||||
|
|
||||||
|
buf = tls_mem_alloc(512);
|
||||||
|
if(buf == NULL)
|
||||||
|
goto end;
|
||||||
|
bufR = tls_mem_alloc(512);
|
||||||
|
if(bufR == NULL)
|
||||||
|
goto end;
|
||||||
|
random_get_bytes(buf, 512);
|
||||||
|
TEST_DEBUG("bus width %s\n", bus_width == 0 ? "1bit" : "4bits");
|
||||||
|
ret = wm_sd_card_set_bus_width(rca, bus_width);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
ret = wm_sd_card_set_blocklen(0x200); //512
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
for(i=0; i<(tsize/512); i++)
|
||||||
|
{
|
||||||
|
sd_addr = SDCardInfo.CSDVer == 1 ? (i * 512) : i;
|
||||||
|
ret = wm_sd_card_block_write(rca, sd_addr, buf);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
ret = wm_sd_card_query_status(rca, NULL);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
for(i=0; i<(tsize/512); i++)
|
||||||
|
{
|
||||||
|
sd_addr = SDCardInfo.CSDVer == 1 ? (i * 512) : i;
|
||||||
|
ret = wm_sd_card_block_read(rca, sd_addr, bufR);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
if(memcmp(buf, bufR, 512))
|
||||||
|
{
|
||||||
|
printf("i=%d\n", i);
|
||||||
|
dumpBuffer("buf", buf, 512);
|
||||||
|
dumpBuffer("bufR", bufR, 512);
|
||||||
|
ret = -2;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
end:
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf);
|
||||||
|
}
|
||||||
|
if(bufR)
|
||||||
|
{
|
||||||
|
tls_mem_free(bufR);
|
||||||
|
}
|
||||||
|
TEST_DEBUG("ret %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
static int sdh_card_wr_sb_fullchip(uint32_t rca, uint8_t bus_width, const uint32_t tsize)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
int i = 0;
|
||||||
|
char* buf = NULL;
|
||||||
|
char* bufR = NULL;
|
||||||
|
uint32_t sd_addr = 0;
|
||||||
|
|
||||||
|
buf = tls_mem_alloc(768);
|
||||||
|
if(buf == NULL)
|
||||||
|
goto end;
|
||||||
|
bufR = tls_mem_alloc(512);
|
||||||
|
if(bufR == NULL)
|
||||||
|
goto end;
|
||||||
|
for(i = 0; i < 768; i++)
|
||||||
|
{
|
||||||
|
buf[i] = i & 0xFF;
|
||||||
|
}
|
||||||
|
TEST_DEBUG("bus width %s\n", bus_width == 0 ? "1bit" : "4bits");
|
||||||
|
ret = wm_sd_card_set_bus_width(rca, bus_width);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
ret = wm_sd_card_set_blocklen(0x200); //512
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
#if 1
|
||||||
|
for(i=(SDCardInfo.CardCapacity-tsize)/512; i<(SDCardInfo.CardCapacity/512); i++)
|
||||||
|
{
|
||||||
|
sd_addr = SDCardInfo.CSDVer == 1 ? (i * 512) : i;
|
||||||
|
ret = wm_sd_card_block_write(rca, sd_addr, &buf[(i%256)/4*4]);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
ret = wm_sd_card_query_status(rca, NULL);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
for(i=(SDCardInfo.CardCapacity-tsize)/512; i<(SDCardInfo.CardCapacity/512); i++)
|
||||||
|
{
|
||||||
|
sd_addr = SDCardInfo.CSDVer == 1 ? (i * 512) : i;
|
||||||
|
ret = wm_sd_card_block_read(rca, sd_addr, bufR);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
printf("i=%d\n", i);
|
||||||
|
if(memcmp(&buf[(i%256)/4*4], bufR, 512))
|
||||||
|
{
|
||||||
|
dumpBuffer("buf", &buf[(i%256)/4*4], 512);
|
||||||
|
dumpBuffer("bufR", bufR, 512);
|
||||||
|
ret = -2;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
end:
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf);
|
||||||
|
}
|
||||||
|
if(bufR)
|
||||||
|
{
|
||||||
|
tls_mem_free(bufR);
|
||||||
|
}
|
||||||
|
TEST_DEBUG("ret %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* multi blocks write & read by dma
|
||||||
|
* bus_width: 0:1bit; 2:4bits
|
||||||
|
* */
|
||||||
|
static int sdh_card_wr_mbs_dma_4M_test(uint32_t rca, uint8_t bus_width, uint32_t block_cnt)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
int i = 0;
|
||||||
|
char* buf = NULL;
|
||||||
|
char* bufR = NULL;
|
||||||
|
const uint32_t tsize = 4*1024;//*1024;
|
||||||
|
int buflen = 512*block_cnt;
|
||||||
|
uint32_t sd_addr = 0;
|
||||||
|
|
||||||
|
buf = tls_mem_alloc(buflen);
|
||||||
|
if(buf == NULL)
|
||||||
|
goto end;
|
||||||
|
bufR = tls_mem_alloc(buflen);
|
||||||
|
if(bufR == NULL)
|
||||||
|
goto end;
|
||||||
|
random_get_bytes(buf, buflen);
|
||||||
|
TEST_DEBUG("bus width %s\n", bus_width == 0 ? "1bit" : "4bits");
|
||||||
|
ret = wm_sd_card_set_bus_width(rca, bus_width);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
ret = wm_sd_card_set_blocklen(0x200); //512
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
//(tsize/512)---->total block number;
|
||||||
|
//(block_cnt)---->write/read x blocks every time;
|
||||||
|
//(sd_addr)---->start from address 0(block 0 too)
|
||||||
|
for(i=0; i<(tsize/512); i+=block_cnt)
|
||||||
|
{
|
||||||
|
sd_addr = SDCardInfo.CSDVer == 1 ? (i * 512) : i;
|
||||||
|
ret = wm_sd_card_blocks_write(rca, sd_addr, buf, buflen);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
ret = wm_sd_card_query_status(rca, NULL);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
for(i=0; i<(tsize/512); i+=block_cnt)
|
||||||
|
{
|
||||||
|
sd_addr = SDCardInfo.CSDVer == 1 ? (i * 512) : i;
|
||||||
|
memset(bufR, 0, buflen);
|
||||||
|
ret = wm_sd_card_blocks_read(rca, sd_addr, bufR, buflen);
|
||||||
|
if(ret)
|
||||||
|
goto end;
|
||||||
|
if(memcmp(buf, bufR, buflen))
|
||||||
|
{
|
||||||
|
ret = -2;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
end:
|
||||||
|
if(buf)
|
||||||
|
{
|
||||||
|
tls_mem_free(buf);
|
||||||
|
}
|
||||||
|
if(bufR)
|
||||||
|
{
|
||||||
|
tls_mem_free(bufR);
|
||||||
|
}
|
||||||
|
TEST_DEBUG("ret %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wr_delay(int cir)
|
||||||
|
{
|
||||||
|
#ifdef TLS_CONFIG_CPU_XT804
|
||||||
|
volatile int delay = cir;
|
||||||
|
#else
|
||||||
|
int delay = count;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while(delay--)
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int sd_card_test(void)
|
||||||
|
{
|
||||||
|
uint32_t rca;
|
||||||
|
int ret=0;
|
||||||
|
|
||||||
|
wm_sdio_host_config(0);
|
||||||
|
ret += sdh_card_init(&rca);
|
||||||
|
printf("\nsdh_card_init, ret = %d\n", ret);
|
||||||
|
#if 0
|
||||||
|
ret += sdh_card_wr_sb_fullchip(rca, 0, 1024*1024);
|
||||||
|
printf("\nW & R 0, ret = %d\n", ret);
|
||||||
|
wr_delay(10000);
|
||||||
|
#else
|
||||||
|
ret += sdh_card_wr_sb(rca, 0, 1024);
|
||||||
|
printf("\nW & R 1, ret = %d\n", ret);
|
||||||
|
wr_delay(10000);
|
||||||
|
ret += sdh_card_wr_sb(rca, 2, 1024);
|
||||||
|
printf("W & R 2, ret = %d\n", ret);
|
||||||
|
wr_delay(10000);
|
||||||
|
ret += sdh_card_wr_mbs_dma_4M_test(rca, 0, 4);
|
||||||
|
printf("W & R 3, ret = %d\n", ret);
|
||||||
|
wr_delay(10000);
|
||||||
|
ret += sdh_card_wr_mbs_dma_4M_test(rca, 2, 6);
|
||||||
|
printf("W & R 4, ret = %d\n", ret);
|
||||||
|
wr_delay(10000);
|
||||||
|
#endif
|
||||||
|
if( ret ==0 ) {
|
||||||
|
printf("\nsd card write read OK, ret = %d\n", ret);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("\nsd card write read FAIL, ret = %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
147
demo/wm_slave_spi_demo.c
Normal file
147
demo/wm_slave_spi_demo.c
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_slave_spi_demo.c
|
||||||
|
*
|
||||||
|
* @brief SPI slave demo function
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_mem.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_SLAVE_SPI
|
||||||
|
|
||||||
|
#define USER_DEBUG 1
|
||||||
|
#if USER_DEBUG
|
||||||
|
#define USER_PRINT printf
|
||||||
|
#else
|
||||||
|
#define USER_PRINT(fmt, ...)
|
||||||
|
#endif
|
||||||
|
#define HSPI_BUF_SIZE 1024
|
||||||
|
|
||||||
|
u32 count = 0;
|
||||||
|
|
||||||
|
static u8 GetCrc(u8 *buf, u16 len)
|
||||||
|
{
|
||||||
|
u8 crc = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if(buf != NULL && len > 0)
|
||||||
|
{
|
||||||
|
for(i=0; i<len; i++)
|
||||||
|
crc += buf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static s16 HspiRxDataCb(char *buf)
|
||||||
|
{
|
||||||
|
int i = 0, err_num = 0;
|
||||||
|
|
||||||
|
for(i=0; i<HSPI_BUF_SIZE; i++)
|
||||||
|
{
|
||||||
|
if(buf[i] != ((i + 1)%255))
|
||||||
|
err_num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err_num != 0)
|
||||||
|
{
|
||||||
|
USER_PRINT("err_num = %d\n", err_num);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
if(count%100 == 0)
|
||||||
|
USER_PRINT("RX ok %d\n", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_hspi_tx_data(buf, HSPI_BUF_SIZE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static s16 HspiRxCmdCb(char *buf)
|
||||||
|
{
|
||||||
|
u16 len = 0;
|
||||||
|
u8 *tx_buf = NULL;
|
||||||
|
int i = 0;
|
||||||
|
printf("%s\n", __func__);
|
||||||
|
if(buf[0] != 0x5A)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
len = buf[1] << 8 | buf[2];
|
||||||
|
USER_PRINT("rx[%d] :", len);
|
||||||
|
for(i=0; i<len; i++)
|
||||||
|
USER_PRINT("%02x ", buf[i]);
|
||||||
|
USER_PRINT("\n");
|
||||||
|
|
||||||
|
if(buf[len - 1] != GetCrc((u8 *)buf, len - 1))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if(buf[3] == 0x01)
|
||||||
|
{
|
||||||
|
tx_buf = tls_mem_alloc(HSPI_BUF_SIZE);
|
||||||
|
if(tx_buf == NULL)
|
||||||
|
return -1;
|
||||||
|
for(i=0; i<HSPI_BUF_SIZE; i++)
|
||||||
|
tx_buf[i] = (i + 1)%255;
|
||||||
|
|
||||||
|
tls_hspi_tx_data((char *)tx_buf, HSPI_BUF_SIZE);
|
||||||
|
tls_mem_free(tx_buf);
|
||||||
|
tx_buf = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HspiInit(int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(type == HSPI_INTERFACE_SPI)
|
||||||
|
{
|
||||||
|
wm_hspi_gpio_config(0);
|
||||||
|
}
|
||||||
|
else if (type == HSPI_INTERFACE_SDIO)
|
||||||
|
{
|
||||||
|
wm_sdio_slave_config(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("do not support interface\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_slave_spi_init();
|
||||||
|
tls_set_high_speed_interface_type(type);
|
||||||
|
tls_set_hspi_user_mode(1);
|
||||||
|
tls_hspi_rx_data_callback_register(HspiRxDataCb);
|
||||||
|
tls_hspi_rx_cmd_callback_register(HspiRxCmdCb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int slave_spi_demo(int type)
|
||||||
|
{
|
||||||
|
if(type == 0)
|
||||||
|
{
|
||||||
|
type = HSPI_INTERFACE_SPI;
|
||||||
|
printf("\r\ntype:%s\r\n", "HSPI_SLAVE");
|
||||||
|
HspiInit(type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
type = HSPI_INTERFACE_SDIO;
|
||||||
|
printf("\r\ntype:%s\r\n", "SDIO_SLAVE");
|
||||||
|
HspiInit(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
444
demo/wm_socket_client_demo.c
Normal file
444
demo/wm_socket_client_demo.c
Normal file
@ -0,0 +1,444 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_socket_client_demo.c
|
||||||
|
*
|
||||||
|
* @brief socket demo function
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_STD_SOCKET_CLIENT
|
||||||
|
#define DEMO_SOCK_C_TASK_SIZE 512
|
||||||
|
#define DEMO_SOCK_BUF_SIZE 512
|
||||||
|
|
||||||
|
#define DEMO_SOCK_MSG_UART_RX 1
|
||||||
|
#define DEMO_SOCK_MSG_UART_OFF 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static OS_STK sock_c_task_stk[DEMO_SOCK_C_TASK_SIZE];
|
||||||
|
static OS_STK sock_c_rcv_task_stk[DEMO_SOCK_C_TASK_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef struct demo_sock_c
|
||||||
|
*/
|
||||||
|
typedef struct demo_sock_c
|
||||||
|
{
|
||||||
|
tls_os_queue_t *sock_c_q;
|
||||||
|
char *sock_rx;
|
||||||
|
char *sock_tx;
|
||||||
|
bool socket_ok;
|
||||||
|
int socket_num;
|
||||||
|
int remote_port;
|
||||||
|
u32 remote_ip;
|
||||||
|
u32 rcv_data_len;
|
||||||
|
int snd_skt_no;
|
||||||
|
int snd_data_len;
|
||||||
|
int uart_trans;
|
||||||
|
int uart_txlen;
|
||||||
|
|
||||||
|
} ST_Demo_Sock_C;
|
||||||
|
|
||||||
|
typedef struct demo_sockc_uart
|
||||||
|
{
|
||||||
|
u8 *rxbuf;
|
||||||
|
u16 rxlen;
|
||||||
|
} ST_Demo_Sockc_uart;
|
||||||
|
|
||||||
|
|
||||||
|
ST_Demo_Sock_C *demo_sock_c = NULL;
|
||||||
|
|
||||||
|
tls_os_queue_t *demo_sockc_q = NULL;
|
||||||
|
|
||||||
|
ST_Demo_Sockc_uart demo_sockc_uart = {0};
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_sock_c_task(void *sdata);
|
||||||
|
|
||||||
|
|
||||||
|
int create_client_socket_demo(void)
|
||||||
|
{
|
||||||
|
struct sockaddr_in pin;
|
||||||
|
|
||||||
|
memset(&pin, 0, sizeof(struct sockaddr));
|
||||||
|
pin.sin_family = AF_INET;
|
||||||
|
demo_sock_c->socket_num = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
|
||||||
|
pin.sin_addr.s_addr = demo_sock_c->remote_ip;
|
||||||
|
pin.sin_port = htons(demo_sock_c->remote_port);
|
||||||
|
|
||||||
|
printf("\nsocket num=%d\n", demo_sock_c->socket_num);
|
||||||
|
if (connect(demo_sock_c->socket_num, (struct sockaddr *)&pin, sizeof(struct sockaddr)) != 0)
|
||||||
|
{
|
||||||
|
printf("connect failed! socket num=%d\n", demo_sock_c->socket_num);
|
||||||
|
closesocket(demo_sock_c->socket_num);
|
||||||
|
tls_os_queue_send(demo_sock_c->sock_c_q, (void *)DEMO_MSG_SOCKET_ERR, 0);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
demo_sock_c->socket_ok = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int socket_client_demo(void)
|
||||||
|
{
|
||||||
|
struct tls_ethif *ethif;
|
||||||
|
|
||||||
|
ethif = tls_netif_get_ethif();
|
||||||
|
printf("\nip=%d.%d.%d.%d\n", ip4_addr1(ip_2_ip4(ðif->ip_addr)), ip4_addr2(ip_2_ip4(ðif->ip_addr)),
|
||||||
|
ip4_addr3(ip_2_ip4(ðif->ip_addr)), ip4_addr4(ip_2_ip4(ðif->ip_addr)));
|
||||||
|
|
||||||
|
|
||||||
|
return create_client_socket_demo();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sock_client_recv_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Sock_C *sock_c = (ST_Demo_Sock_C *)sdata;
|
||||||
|
int ret = 0;
|
||||||
|
fd_set fdsr;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
if (sock_c->socket_ok)
|
||||||
|
{
|
||||||
|
FD_ZERO(&fdsr);
|
||||||
|
FD_SET(sock_c->socket_num, &fdsr);
|
||||||
|
tv.tv_sec = 1;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
ret = select(sock_c->socket_num+1, &fdsr, NULL, NULL, &tv);
|
||||||
|
if (0 == ret)
|
||||||
|
{
|
||||||
|
// printf("select ret=%d\n",ret);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (-1 == ret)
|
||||||
|
{
|
||||||
|
printf("select error\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FD_ISSET(sock_c->socket_num, &fdsr))
|
||||||
|
{
|
||||||
|
FD_CLR(sock_c->socket_num, &fdsr);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
ret = recv(sock_c->socket_num, sock_c->sock_rx, DEMO_SOCK_BUF_SIZE, 0);
|
||||||
|
|
||||||
|
if(ret > 0)
|
||||||
|
{
|
||||||
|
sock_c->rcv_data_len += ret;
|
||||||
|
|
||||||
|
if(sock_c->uart_trans)
|
||||||
|
{
|
||||||
|
tls_uart_write(TLS_UART_1, sock_c->sock_rx, ret);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("rcv: %d\n", sock_c->rcv_data_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sock_c->socket_ok = FALSE;
|
||||||
|
closesocket(sock_c->socket_num);
|
||||||
|
printf("closesocket: %d\n", sock_c->socket_num);
|
||||||
|
sock_c->socket_num = 0;
|
||||||
|
tls_os_queue_send(sock_c->sock_c_q, (void *)DEMO_MSG_SOCKET_ERR, 0);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sck_c_send_data_demo(int len, int uart_trans)
|
||||||
|
{
|
||||||
|
printf("\nlen=%d, uart_trans=%d\n", len, uart_trans);
|
||||||
|
if (NULL == demo_sock_c)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
if (!demo_sock_c->socket_ok)
|
||||||
|
{
|
||||||
|
printf("skt not created\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_c->snd_data_len = len;
|
||||||
|
|
||||||
|
if(demo_sock_c->uart_trans && (0 == uart_trans))
|
||||||
|
{
|
||||||
|
demo_sock_c->uart_trans = uart_trans;
|
||||||
|
tls_os_queue_send(demo_sockc_q, (void *) DEMO_SOCK_MSG_UART_OFF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_c->uart_trans = uart_trans;
|
||||||
|
|
||||||
|
tls_os_queue_send(demo_sock_c->sock_c_q, (void *)DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static s16 demo_sockc_rx(u16 len)
|
||||||
|
{
|
||||||
|
demo_sockc_uart.rxlen += len;
|
||||||
|
tls_os_queue_send(demo_sockc_q, (void *) DEMO_SOCK_MSG_UART_RX, 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Socket_Client_Demo(int port, char *ip)
|
||||||
|
{
|
||||||
|
if (demo_sock_c)
|
||||||
|
{
|
||||||
|
printf("run\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
if (-1 == port || NULL == ip)
|
||||||
|
{
|
||||||
|
printf("please input remote port and ip\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
printf("\nremote ip: %s, remote port: %d\n", ip, port);
|
||||||
|
|
||||||
|
if (NULL == demo_sock_c)
|
||||||
|
{
|
||||||
|
demo_sock_c = tls_mem_alloc(sizeof(ST_Demo_Sock_C));
|
||||||
|
if (NULL == demo_sock_c)
|
||||||
|
{
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
memset(demo_sock_c, 0, sizeof(ST_Demo_Sock_C));
|
||||||
|
|
||||||
|
demo_sock_c->sock_rx = tls_mem_alloc(DEMO_SOCK_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_sock_c->sock_rx)
|
||||||
|
{
|
||||||
|
goto _error3;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_c->sock_tx = tls_mem_alloc(DEMO_SOCK_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_sock_c->sock_tx)
|
||||||
|
{
|
||||||
|
goto _error4;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_os_queue_create(&(demo_sock_c->sock_c_q), DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_os_queue_create(&demo_sockc_q, DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_uart_set_baud_rate(TLS_UART_1, 115200);
|
||||||
|
tls_uart_rx_callback_register(TLS_UART_1, (s16(*)(u16, void*))demo_sockc_rx,NULL);
|
||||||
|
|
||||||
|
//deal with socket's message
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_sock_c_task,
|
||||||
|
(void *)demo_sock_c,
|
||||||
|
(void *)sock_c_task_stk, /* task's stack start address */
|
||||||
|
DEMO_SOCK_C_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_SOCKET_C_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
|
||||||
|
//deal with socket's rx data
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
sock_client_recv_task,
|
||||||
|
(void *)demo_sock_c,
|
||||||
|
(void *)sock_c_rcv_task_stk, /* task's stack start address */
|
||||||
|
DEMO_SOCK_C_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_SOCKET_RECEIVE_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_c->remote_port = port;
|
||||||
|
demo_sock_c->remote_ip = ipaddr_addr(ip);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
|
||||||
|
_error4:
|
||||||
|
tls_mem_free(demo_sock_c->sock_rx);
|
||||||
|
_error3:
|
||||||
|
tls_mem_free(demo_sock_c);
|
||||||
|
demo_sock_c = NULL;
|
||||||
|
_error:
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void sock_c_net_status_changed_event(u8 status )
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
tls_os_queue_send(demo_sock_c->sock_c_q, (void *)DEMO_MSG_WJOIN_FAILD, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
tls_os_queue_send(demo_sock_c->sock_c_q, (void *)DEMO_MSG_WJOIN_SUCCESS, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
tls_os_queue_send(demo_sock_c->sock_c_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void demo_sock_c_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Sock_C *sock_c = (ST_Demo_Sock_C *)sdata;
|
||||||
|
void *msg;
|
||||||
|
struct tls_ethif *ethif = tls_netif_get_ethif();
|
||||||
|
int len;
|
||||||
|
int ret;
|
||||||
|
void *uart_msg;
|
||||||
|
u16 offset = 0;
|
||||||
|
u16 readlen = 0;
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nsock c task\n");
|
||||||
|
|
||||||
|
if(ethif->status) /*connected to ap and get IP*/
|
||||||
|
{
|
||||||
|
tls_os_queue_send(sock_c->sock_c_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct tls_param_ip ip_param;
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
ip_param.dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
tls_wifi_set_oneshot_flag(1); /*Enable oneshot configuration*/
|
||||||
|
printf("\nwait one shot......\n");
|
||||||
|
}
|
||||||
|
tls_netif_add_status_event(sock_c_net_status_changed_event);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(sock_c->sock_c_q, (void **)&msg, 0, 0);
|
||||||
|
//printf("\n msg =%d\n",msg);
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case DEMO_MSG_WJOIN_SUCCESS:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_CREATE:
|
||||||
|
socket_client_demo();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_WJOIN_FAILD:
|
||||||
|
if(sock_c->socket_num > 0)
|
||||||
|
{
|
||||||
|
sock_c->socket_num = 0;
|
||||||
|
sock_c->socket_ok = FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_RECEIVE_DATA:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_UART_RECEIVE_DATA:
|
||||||
|
|
||||||
|
while(sock_c->uart_trans)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(demo_sockc_q, (void **) &uart_msg, 0, 0);
|
||||||
|
|
||||||
|
if((u32)uart_msg != DEMO_SOCK_MSG_UART_RX)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
readlen = (demo_sockc_uart.rxlen > DEMO_SOCK_BUF_SIZE) ?
|
||||||
|
DEMO_SOCK_BUF_SIZE : demo_sockc_uart.rxlen;
|
||||||
|
if (readlen == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sockc_uart.rxbuf = tls_mem_alloc(readlen);
|
||||||
|
if(demo_sockc_uart.rxbuf == NULL)
|
||||||
|
{
|
||||||
|
printf("demo_socks_uart->rxbuf malloc err\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ret = tls_uart_read(TLS_UART_1, demo_sockc_uart.rxbuf, readlen);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
tls_mem_free(demo_sockc_uart.rxbuf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
demo_sockc_uart.rxlen -= ret;
|
||||||
|
readlen = ret;
|
||||||
|
|
||||||
|
offset = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ret = send(sock_c->socket_num, demo_sockc_uart.rxbuf + offset, readlen, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset += ret;
|
||||||
|
readlen -= ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(readlen);
|
||||||
|
tls_mem_free(demo_sockc_uart.rxbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-1 == sock_c->snd_data_len)
|
||||||
|
{
|
||||||
|
len = DEMO_SOCK_BUF_SIZE;
|
||||||
|
}
|
||||||
|
else if(sock_c->snd_data_len != 0)
|
||||||
|
{
|
||||||
|
len = (sock_c->snd_data_len > DEMO_SOCK_BUF_SIZE) ?
|
||||||
|
DEMO_SOCK_BUF_SIZE : sock_c->snd_data_len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(sock_c->sock_tx, 0x35, len);
|
||||||
|
ret = send(sock_c->socket_num, sock_c->sock_tx, len, 0);
|
||||||
|
if (ret != -1)
|
||||||
|
{
|
||||||
|
if (sock_c->snd_data_len != -1)
|
||||||
|
{
|
||||||
|
sock_c->snd_data_len -= ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sock_c->socket_ok && sock_c->snd_data_len != 0)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
tls_os_queue_send(sock_c->sock_c_q, (void *)DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_ERR:
|
||||||
|
tls_os_time_delay(200);
|
||||||
|
printf("\nsocket err\n");
|
||||||
|
create_client_socket_demo( );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
673
demo/wm_socket_server_demo.c
Normal file
673
demo/wm_socket_server_demo.c
Normal file
@ -0,0 +1,673 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_socket_server_demo.c
|
||||||
|
*
|
||||||
|
* @brief socket demo function
|
||||||
|
*
|
||||||
|
* @Author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if DEMO_STD_SOCKET_SERVER
|
||||||
|
#define DEMO_SOCK_S_TASK_SIZE 512
|
||||||
|
#define DEMO_SOCK_BUF_SIZE 1024
|
||||||
|
#define BACKLOG 7 // how many pending connections queue will hold
|
||||||
|
|
||||||
|
|
||||||
|
#define DEMO_SOCK_MSG_UART_RX 1
|
||||||
|
#define DEMO_SOCK_MSG_UART_OFF 2
|
||||||
|
|
||||||
|
|
||||||
|
static OS_STK sock_s_task_stk[DEMO_SOCK_S_TASK_SIZE];
|
||||||
|
static OS_STK sock_s_rcv_task_stk[DEMO_SOCK_S_TASK_SIZE];
|
||||||
|
static OS_STK sock_s_snd_task_stk[DEMO_SOCK_S_TASK_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef struct demo_sock_s
|
||||||
|
*/
|
||||||
|
typedef struct demo_sock_s
|
||||||
|
{
|
||||||
|
// OS_STK *sock_s_task_stk;
|
||||||
|
tls_os_queue_t *sock_s_q;
|
||||||
|
// OS_STK *sock_rcv_task_stk;
|
||||||
|
// OS_STK *sock_snd_task_stk;
|
||||||
|
char *sock_rx;
|
||||||
|
char *sock_tx;
|
||||||
|
bool socket_ok;
|
||||||
|
int server_fd;
|
||||||
|
int my_port;
|
||||||
|
int conn_num;
|
||||||
|
int client_fd_queue[BACKLOG];
|
||||||
|
u32 rcv_data_len[BACKLOG];
|
||||||
|
int if_snd[BACKLOG];
|
||||||
|
int all_snd;
|
||||||
|
int uart_trans;
|
||||||
|
int uart_txlen;
|
||||||
|
int snd_data_len[BACKLOG];
|
||||||
|
} ST_Demo_Sock_S;
|
||||||
|
|
||||||
|
typedef struct demo_socks_uart
|
||||||
|
{
|
||||||
|
u8 *rxbuf;
|
||||||
|
u16 rxlen;
|
||||||
|
} ST_Demo_Socks_uart;
|
||||||
|
|
||||||
|
|
||||||
|
ST_Demo_Sock_S *demo_sock_s = NULL;
|
||||||
|
|
||||||
|
tls_os_queue_t *demo_socks_q = NULL;
|
||||||
|
|
||||||
|
ST_Demo_Socks_uart demo_socks_uart = {0};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_sock_s_task(void *sdata);
|
||||||
|
static void sock_server_recv_task(void *sdata);
|
||||||
|
static void sock_server_snd_task(void *sdata);
|
||||||
|
|
||||||
|
static void sock_server_recv_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Sock_S *sock_s = (ST_Demo_Sock_S *) sdata;
|
||||||
|
int ret = 0;
|
||||||
|
fd_set fdsr;
|
||||||
|
//fd_set fdexpt;
|
||||||
|
int maxsock = 0;
|
||||||
|
#if 1
|
||||||
|
struct timeval tv;
|
||||||
|
#endif
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
if (sock_s->conn_num < 1)
|
||||||
|
{
|
||||||
|
// printf("no socket \n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/** initialize file descriptor set */
|
||||||
|
FD_ZERO(&fdsr);
|
||||||
|
// FD_ZERO(&fdexpt);
|
||||||
|
#if 1 /**not use timeout*/
|
||||||
|
/** timeout setting */
|
||||||
|
tv.tv_sec = 1;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
#endif
|
||||||
|
maxsock = 0;
|
||||||
|
/** add active connection to fd set */
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
if (sock_s->client_fd_queue[i] != -1)
|
||||||
|
{
|
||||||
|
FD_SET(sock_s->client_fd_queue[i], &fdsr);
|
||||||
|
// FD_SET(sock_s->client_fd_queue[i], &fdexpt);
|
||||||
|
if (sock_s->client_fd_queue[i] > maxsock)
|
||||||
|
{
|
||||||
|
maxsock = sock_s->client_fd_queue[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = select(maxsock + 1, &fdsr, NULL, NULL, &tv);
|
||||||
|
//ret = select(maxsock + 1, &fdsr, NULL, &fdexpt, NULL);
|
||||||
|
// printf("recv select ret=%d\n",ret);
|
||||||
|
if (0 == ret)
|
||||||
|
{
|
||||||
|
// printf("select ret=%d\n",ret);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (-1 == ret)
|
||||||
|
{
|
||||||
|
printf("select error\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
if (-1 == sock_s->client_fd_queue[i])
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FD_ISSET(sock_s->client_fd_queue[i], &fdsr))
|
||||||
|
{
|
||||||
|
memset(sock_s->sock_rx, 0, DEMO_SOCK_BUF_SIZE);
|
||||||
|
ret = recv(sock_s->client_fd_queue[i], sock_s->sock_rx, DEMO_SOCK_BUF_SIZE, 0);
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
// client close
|
||||||
|
printf("client[%d] close\n", i);
|
||||||
|
closesocket(sock_s->client_fd_queue[i]);
|
||||||
|
FD_CLR(sock_s->client_fd_queue[i], &fdsr);
|
||||||
|
sock_s->conn_num --;
|
||||||
|
if (sock_s->conn_num <= 0)
|
||||||
|
{
|
||||||
|
sock_s->socket_ok = 0;
|
||||||
|
}
|
||||||
|
sock_s->client_fd_queue[i] = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// receive data
|
||||||
|
sock_s->rcv_data_len[i] += ret;
|
||||||
|
if(sock_s->uart_trans
|
||||||
|
&& sock_s->if_snd[i])
|
||||||
|
{
|
||||||
|
tls_uart_write(TLS_UART_1, sock_s->sock_rx, ret);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\nsock[%d] rcv len==%d\n", sock_s->client_fd_queue[i], sock_s->rcv_data_len[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (FD_ISSET(sock_s->client_fd_queue[i], &fdexpt))
|
||||||
|
// {
|
||||||
|
// printf("expt error\n");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sock_server_snd_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Sock_S *sock_s = (ST_Demo_Sock_S *) sdata;
|
||||||
|
void *msg;
|
||||||
|
int i;
|
||||||
|
int len = DEMO_SOCK_BUF_SIZE;
|
||||||
|
int ret;
|
||||||
|
fd_set fdsr;
|
||||||
|
int maxsock = 0;
|
||||||
|
u8 if_send = 0;
|
||||||
|
void *uart_msg;
|
||||||
|
u16 offset = 0;
|
||||||
|
u16 readlen = 0;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(sock_s->sock_s_q, (void **) &msg, 0, 0);
|
||||||
|
// printf("msg=%d\n",msg);
|
||||||
|
switch ((u32) msg)
|
||||||
|
{
|
||||||
|
case DEMO_MSG_UART_RECEIVE_DATA:
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1); /**adjust send speed*/
|
||||||
|
FD_ZERO(&fdsr);
|
||||||
|
/** add active connection to fd set */
|
||||||
|
maxsock = 0;
|
||||||
|
if_send = 0;
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
if (sock_s->client_fd_queue[i] != -1 && (sock_s->snd_data_len[i] != 0 || sock_s->uart_trans) &&
|
||||||
|
(1 == sock_s->if_snd[i] || 1 == sock_s->all_snd))
|
||||||
|
{
|
||||||
|
if_send = 1;
|
||||||
|
FD_SET(sock_s->client_fd_queue[i], &fdsr);
|
||||||
|
|
||||||
|
if (sock_s->client_fd_queue[i] > maxsock)
|
||||||
|
{
|
||||||
|
maxsock = sock_s->client_fd_queue[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//printf("maxsock==%d\n",maxsock);
|
||||||
|
if (0 == if_send)
|
||||||
|
{
|
||||||
|
// printf("do not send\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = select(maxsock + 1, NULL, &fdsr, NULL, NULL);
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
printf("send select ret=%d\n", ret);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sock_s->uart_trans)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(demo_socks_q, (void **) &uart_msg, 0, 0);
|
||||||
|
|
||||||
|
if((u32)uart_msg != DEMO_SOCK_MSG_UART_RX)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
readlen = (demo_socks_uart.rxlen > DEMO_SOCK_BUF_SIZE) ?
|
||||||
|
DEMO_SOCK_BUF_SIZE : demo_socks_uart.rxlen;
|
||||||
|
demo_socks_uart.rxbuf = tls_mem_alloc(readlen);
|
||||||
|
if(demo_socks_uart.rxbuf == NULL)
|
||||||
|
{
|
||||||
|
printf("demo_socks_uart->rxbuf malloc err\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ret = tls_uart_read(TLS_UART_1, demo_socks_uart.rxbuf, readlen);
|
||||||
|
if(ret < 0)
|
||||||
|
{
|
||||||
|
tls_mem_free(demo_socks_uart.rxbuf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
demo_socks_uart.rxlen -= ret;
|
||||||
|
readlen = ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < BACKLOG; i ++)
|
||||||
|
{
|
||||||
|
if (-1 == sock_s->client_fd_queue[i] || (0 == sock_s->if_snd[i] &&
|
||||||
|
0 == sock_s->all_snd))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FD_ISSET(sock_s->client_fd_queue[i], &fdsr))
|
||||||
|
{
|
||||||
|
|
||||||
|
if(sock_s->uart_trans)
|
||||||
|
{
|
||||||
|
// printf("send data len:%d\n", uart_msg->rxlen);
|
||||||
|
offset = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
ret = send(sock_s->client_fd_queue[i], demo_socks_uart.rxbuf + offset, readlen, 0);
|
||||||
|
offset += ret;
|
||||||
|
readlen -= ret;
|
||||||
|
}
|
||||||
|
while(readlen);
|
||||||
|
tls_mem_free(demo_socks_uart.rxbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (-1 == sock_s->snd_data_len[i])
|
||||||
|
{
|
||||||
|
len = DEMO_SOCK_BUF_SIZE;
|
||||||
|
}
|
||||||
|
else if(sock_s->snd_data_len[i] != 0)
|
||||||
|
{
|
||||||
|
len = (sock_s->snd_data_len[i] > DEMO_SOCK_BUF_SIZE) ?
|
||||||
|
DEMO_SOCK_BUF_SIZE : sock_s->snd_data_len[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// printf("send skno=%d\n",sock_s->client_fd_queue[i]);
|
||||||
|
memset(sock_s->sock_tx, sock_s->client_fd_queue[i] + 0x30, len);
|
||||||
|
ret = send(sock_s->client_fd_queue[i], sock_s->sock_tx, len, 0);
|
||||||
|
// printf("ret=%d\n",ret);
|
||||||
|
if (ret != -1)
|
||||||
|
{
|
||||||
|
if (sock_s->snd_data_len[i] != -1)
|
||||||
|
{
|
||||||
|
sock_s->snd_data_len[i] -= ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_WJOIN_FAILD:
|
||||||
|
sock_s->server_fd = -1;
|
||||||
|
sock_s->socket_ok = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sck_s_send_data_demo(int skt_no, int len, int uart_trans)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
printf("\nsktno=%d, len=%d, uart_trans=%d\n", skt_no, len, uart_trans);
|
||||||
|
if (NULL == demo_sock_s)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == skt_no || -1 == skt_no)
|
||||||
|
{
|
||||||
|
demo_sock_s->all_snd = 1;
|
||||||
|
for (i = 0; i < BACKLOG; i ++)
|
||||||
|
{
|
||||||
|
demo_sock_s->snd_data_len[i] = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
demo_sock_s->all_snd = 0;
|
||||||
|
for (i = 0; i < BACKLOG; i ++)
|
||||||
|
{
|
||||||
|
if(demo_sock_s->client_fd_queue[i] != -1)
|
||||||
|
{
|
||||||
|
if (skt_no == demo_sock_s->client_fd_queue[i])
|
||||||
|
{
|
||||||
|
demo_sock_s->if_snd[i] = 1;
|
||||||
|
demo_sock_s->snd_data_len[i] = len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
demo_sock_s->if_snd[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(demo_sock_s->uart_trans && (0 == uart_trans))
|
||||||
|
{
|
||||||
|
demo_sock_s->uart_trans = uart_trans;
|
||||||
|
tls_os_queue_send(demo_socks_q, (void *) DEMO_SOCK_MSG_UART_OFF, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_s->uart_trans = uart_trans;
|
||||||
|
|
||||||
|
tls_os_queue_send(demo_sock_s->sock_s_q,
|
||||||
|
(void *) DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static s16 demo_socks_rx(u16 len)
|
||||||
|
{
|
||||||
|
demo_socks_uart.rxlen += len;
|
||||||
|
tls_os_queue_send(demo_socks_q, (void *) DEMO_SOCK_MSG_UART_RX, 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int socket_server_demo(int port)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
if (demo_sock_s)
|
||||||
|
{
|
||||||
|
printf("run\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
if (-1 == port)
|
||||||
|
{
|
||||||
|
port = 1020;
|
||||||
|
}
|
||||||
|
printf("server demo port=%d\n", port);
|
||||||
|
if (NULL == demo_sock_s)
|
||||||
|
{
|
||||||
|
demo_sock_s = tls_mem_alloc(sizeof(ST_Demo_Sock_S));
|
||||||
|
if (NULL == demo_sock_s)
|
||||||
|
{
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
memset(demo_sock_s, 0, sizeof(ST_Demo_Sock_S));
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
demo_sock_s->client_fd_queue[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_s->sock_rx = tls_mem_alloc(DEMO_SOCK_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_sock_s->sock_rx)
|
||||||
|
{
|
||||||
|
goto _error3;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_s->sock_tx = tls_mem_alloc(DEMO_SOCK_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_sock_s->sock_tx)
|
||||||
|
{
|
||||||
|
goto _error4;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_os_queue_create(&demo_sock_s->sock_s_q, DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_os_queue_create(&demo_socks_q, DEMO_QUEUE_SIZE);
|
||||||
|
|
||||||
|
tls_uart_set_baud_rate(TLS_UART_1, 115200);
|
||||||
|
tls_uart_rx_callback_register(TLS_UART_1,(s16(*)(u16, void*))demo_socks_rx, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
//deal with user's socket message
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_sock_s_task,
|
||||||
|
(void *) demo_sock_s,
|
||||||
|
(void *) sock_s_task_stk, /* task's stack start address */
|
||||||
|
DEMO_SOCK_S_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_SOCKET_S_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
|
||||||
|
//deal with socket's rx data
|
||||||
|
tls_os_task_create(NULL, "recv",
|
||||||
|
sock_server_recv_task,
|
||||||
|
(void *) demo_sock_s,
|
||||||
|
(void *) sock_s_rcv_task_stk, /* task's stack start address */
|
||||||
|
DEMO_SOCK_S_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_SOCKET_S_RECEIVE_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
// deal with socket's tx data
|
||||||
|
tls_os_task_create(NULL, "send",
|
||||||
|
sock_server_snd_task,
|
||||||
|
(void *) demo_sock_s,
|
||||||
|
(void *) sock_s_snd_task_stk, /* task's stack start address */
|
||||||
|
DEMO_SOCK_S_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_SOCKET_S_SEND_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_sock_s->my_port = port;
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
|
||||||
|
|
||||||
|
tls_mem_free(demo_sock_s->sock_tx);
|
||||||
|
_error4:
|
||||||
|
tls_mem_free(demo_sock_s->sock_rx);
|
||||||
|
_error3:
|
||||||
|
tls_mem_free(demo_sock_s);
|
||||||
|
demo_sock_s = NULL;
|
||||||
|
_error:
|
||||||
|
printf("mem err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void sock_s_net_status_changed_event(u8 status)
|
||||||
|
{
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
tls_os_queue_send(demo_sock_s->sock_s_q,
|
||||||
|
(void *) DEMO_MSG_WJOIN_FAILD, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
tls_os_queue_send(demo_sock_s->sock_s_q,
|
||||||
|
(void *) DEMO_MSG_WJOIN_SUCCESS, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
tls_os_queue_send(demo_sock_s->sock_s_q,
|
||||||
|
(void *) DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void showclient(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf("client count: %d\n", demo_sock_s->conn_num);
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
printf("[%d]:%d ", i, demo_sock_s->client_fd_queue[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int socket_server(void)
|
||||||
|
{
|
||||||
|
int new_fd; // listen on sock_fd, new connection on new_fd
|
||||||
|
struct sockaddr_in server_addr; // server address information
|
||||||
|
struct sockaddr_in client_addr; // connector's address information
|
||||||
|
socklen_t sin_size;
|
||||||
|
int yes = 1;
|
||||||
|
int i;
|
||||||
|
fd_set fdsr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if ((demo_sock_s->server_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
||||||
|
{
|
||||||
|
printf("create socket err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setsockopt(demo_sock_s->server_fd, SOL_SOCKET, SO_REUSEADDR, &yes,
|
||||||
|
sizeof(int)) == -1)
|
||||||
|
{
|
||||||
|
printf("set sockopt err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** host byte order */
|
||||||
|
server_addr.sin_family = AF_INET;
|
||||||
|
/** short, network byte order */
|
||||||
|
server_addr.sin_port = htons(demo_sock_s->my_port);
|
||||||
|
/** automatically fill with my IP */
|
||||||
|
server_addr.sin_addr.s_addr = ((u32) 0x00000000UL);
|
||||||
|
memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));
|
||||||
|
|
||||||
|
if (bind(demo_sock_s->server_fd, (struct sockaddr *) &server_addr,
|
||||||
|
sizeof(server_addr)) == -1)
|
||||||
|
{
|
||||||
|
printf("bind err\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listen(demo_sock_s->server_fd, BACKLOG) == -1)
|
||||||
|
{
|
||||||
|
printf("listen err\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("listen port %d\n", demo_sock_s->my_port);
|
||||||
|
|
||||||
|
demo_sock_s->conn_num = 0;
|
||||||
|
|
||||||
|
sin_size = sizeof(client_addr);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// initialize file descriptor set
|
||||||
|
FD_ZERO(&fdsr);
|
||||||
|
FD_SET(demo_sock_s->server_fd, &fdsr);
|
||||||
|
|
||||||
|
ret = select(demo_sock_s->server_fd + 1, &fdsr, NULL, NULL, NULL);
|
||||||
|
if(ret <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (FD_ISSET(demo_sock_s->server_fd, &fdsr))
|
||||||
|
{
|
||||||
|
new_fd = accept(demo_sock_s->server_fd, (struct sockaddr *) &client_addr,
|
||||||
|
&sin_size);
|
||||||
|
printf("accept newfd=%d\n", new_fd);
|
||||||
|
if (new_fd <= 0)
|
||||||
|
{
|
||||||
|
printf("accept err\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// add to fd queue
|
||||||
|
if (demo_sock_s->conn_num < BACKLOG)
|
||||||
|
{
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
if (demo_sock_s->client_fd_queue[i] == -1)
|
||||||
|
{
|
||||||
|
demo_sock_s->client_fd_queue[i] = new_fd;
|
||||||
|
demo_sock_s->conn_num++;
|
||||||
|
if (demo_sock_s->conn_num)
|
||||||
|
{
|
||||||
|
demo_sock_s->socket_ok = 1;
|
||||||
|
tls_os_queue_send(demo_sock_s->sock_s_q,
|
||||||
|
(void *) DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("new connection client[%d] %s:%d\n",
|
||||||
|
demo_sock_s->conn_num, inet_ntoa(client_addr.sin_addr),
|
||||||
|
ntohs(client_addr.sin_port));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("max connections arrive, exit\n");
|
||||||
|
closesocket(new_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
showclient();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
// close other connections
|
||||||
|
for (i = 0; i < BACKLOG; i++)
|
||||||
|
{
|
||||||
|
if (demo_sock_s->client_fd_queue[i] != -1)
|
||||||
|
{
|
||||||
|
closesocket(demo_sock_s->client_fd_queue[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closesocket(demo_sock_s->server_fd);
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_sock_s_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Sock_S *sock_s = (ST_Demo_Sock_S *) sdata;
|
||||||
|
void *msg;
|
||||||
|
struct tls_ethif *ethif = tls_netif_get_ethif();
|
||||||
|
|
||||||
|
printf("\nsock s task\n");
|
||||||
|
|
||||||
|
if (ethif->status) /*connected to ap and get IP*/
|
||||||
|
{
|
||||||
|
tls_os_queue_send(sock_s->sock_s_q, (void *) DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct tls_param_ip ip_param;
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
ip_param.dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
|
||||||
|
tls_wifi_set_oneshot_flag(1); /*Enable oneshot configuration*/
|
||||||
|
printf("\nwait one shot......\n");
|
||||||
|
}
|
||||||
|
tls_netif_add_status_event(sock_s_net_status_changed_event);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(sock_s->sock_s_q, (void **) &msg, 0, 0);
|
||||||
|
switch ((u32) msg)
|
||||||
|
{
|
||||||
|
case DEMO_MSG_WJOIN_SUCCESS:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_CREATE:
|
||||||
|
ethif = tls_netif_get_ethif();
|
||||||
|
printf("\nserver ip=%d.%d.%d.%d\n", ip4_addr1(ip_2_ip4(ðif->ip_addr)), ip4_addr2(ip_2_ip4(ðif->ip_addr)),
|
||||||
|
ip4_addr3(ip_2_ip4(ðif->ip_addr)), ip4_addr4(ip_2_ip4(ðif->ip_addr)));
|
||||||
|
socket_server();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
188
demo/wm_softap_demo.c
Normal file
188
demo/wm_softap_demo.c
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_softap_demo.c
|
||||||
|
*
|
||||||
|
* Description: soft ap demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : cuiyanchang
|
||||||
|
*
|
||||||
|
* Date : 2014-6-2
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_SOFT_AP
|
||||||
|
/*1)Add sta add callback function
|
||||||
|
2)Add sta list monitor task*/
|
||||||
|
static tls_os_timer_t *sta_monitor_tim = NULL;
|
||||||
|
static u32 totalstanum = 0;
|
||||||
|
/*mac that not allowed to join soft ap, you can change it.*/
|
||||||
|
unsigned char blackmac[6] = {0x44,0xc3,0x46,0x41,0x71,0x1f};
|
||||||
|
|
||||||
|
static u32 delblackstatimeout = 60;
|
||||||
|
static u32 delcnt = 0;
|
||||||
|
|
||||||
|
static u32 addrefusecnt = 0;
|
||||||
|
static u32 addrefusecnttimeout = 60;
|
||||||
|
|
||||||
|
#define ADD_BLACK_STATE 0
|
||||||
|
#define DEL_BLACK_STATE 1
|
||||||
|
static u32 blackstate = DEL_BLACK_STATE;
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_monitor_stalist_tim(void *ptmr, void *parg)
|
||||||
|
{
|
||||||
|
u8 *stabuf = NULL;
|
||||||
|
u32 stanum = 0;
|
||||||
|
int i = 0;
|
||||||
|
stabuf = tls_mem_alloc(1024);
|
||||||
|
if (stabuf)
|
||||||
|
{
|
||||||
|
stanum = 0;
|
||||||
|
memset(stabuf, 0, 1024);
|
||||||
|
tls_wifi_get_authed_sta_info(&stanum, stabuf, 1024);
|
||||||
|
if (totalstanum != stanum)
|
||||||
|
{
|
||||||
|
wm_printf("white sta mac:\n");
|
||||||
|
for (i = 0; i < stanum ; i++)
|
||||||
|
{
|
||||||
|
wm_printf("%M\n", &stabuf[i * 6]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalstanum = stanum;
|
||||||
|
stanum = 0;
|
||||||
|
memset(stabuf, 0, 1024);
|
||||||
|
tls_wifi_softap_get_blackinfo(&stanum, stabuf, 1024);
|
||||||
|
wm_printf("black sta mac:\n");
|
||||||
|
for (i = 0; i < stanum ; i++)
|
||||||
|
{
|
||||||
|
wm_printf("%M\n", &stabuf[i * 6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (blackstate)
|
||||||
|
{
|
||||||
|
case DEL_BLACK_STATE: /*delete sta's for black list*/
|
||||||
|
delcnt++;
|
||||||
|
if (delcnt > delblackstatimeout)
|
||||||
|
{
|
||||||
|
for (i = 0; i < stanum ; i++)
|
||||||
|
{
|
||||||
|
tls_wifi_softap_del_blacksta(&stabuf[i*6]);
|
||||||
|
}
|
||||||
|
delcnt = 0;
|
||||||
|
blackstate = ADD_BLACK_STATE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ADD_BLACK_STATE: /*add station into black list*/
|
||||||
|
addrefusecnt ++;
|
||||||
|
if (addrefusecnt > addrefusecnttimeout)
|
||||||
|
{
|
||||||
|
tls_wifi_softap_add_blacksta(blackmac);
|
||||||
|
tls_wifi_softap_del_station(blackmac);
|
||||||
|
addrefusecnt = 0;
|
||||||
|
blackstate = DEL_BLACK_STATE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_mem_free(stabuf);
|
||||||
|
stabuf = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_create_softap(u8 *ssid, u8 *key, int chan, int encrypt, int format)
|
||||||
|
{
|
||||||
|
struct tls_softap_info_t *apinfo;
|
||||||
|
struct tls_ip_info_t *ipinfo;
|
||||||
|
u8 ret = 0;
|
||||||
|
u8 ssid_set = 0;
|
||||||
|
u8 wireless_protocol = 0;
|
||||||
|
|
||||||
|
|
||||||
|
u8 ssid_len = 0;
|
||||||
|
if (!ssid)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
ipinfo = tls_mem_alloc(sizeof(struct tls_ip_info_t));
|
||||||
|
if (!ipinfo)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
apinfo = tls_mem_alloc(sizeof(struct tls_softap_info_t));
|
||||||
|
if (!apinfo)
|
||||||
|
{
|
||||||
|
tls_mem_free(ipinfo);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, TRUE);
|
||||||
|
if (TLS_PARAM_IEEE80211_SOFTAP != wireless_protocol)
|
||||||
|
{
|
||||||
|
wireless_protocol = TLS_PARAM_IEEE80211_SOFTAP;
|
||||||
|
tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *) &wireless_protocol, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_wifi_set_oneshot_flag(0); /*disable oneshot*/
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)0);
|
||||||
|
if (0 == ssid_set)
|
||||||
|
{
|
||||||
|
ssid_set = 1;
|
||||||
|
tls_param_set(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)1); /*set bssid broadcast flag*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tls_wifi_disconnect();
|
||||||
|
|
||||||
|
ssid_len = strlen((const char *)ssid);
|
||||||
|
MEMCPY(apinfo->ssid, ssid, ssid_len);
|
||||||
|
apinfo->ssid[ssid_len] = '\0';
|
||||||
|
|
||||||
|
apinfo->encrypt = encrypt; /*0:open, 1:wep64, 2:wep128,3:TKIP WPA ,4: CCMP WPA, 5:TKIP WPA2 ,6: CCMP WPA2*/
|
||||||
|
apinfo->channel = chan; /*channel*/
|
||||||
|
apinfo->keyinfo.format = format; /*key's format:0-HEX, 1-ASCII*/
|
||||||
|
apinfo->keyinfo.index = 1; /*wep key index*/
|
||||||
|
apinfo->keyinfo.key_len = strlen((const char *)key); /*key length*/
|
||||||
|
MEMCPY(apinfo->keyinfo.key, key, apinfo->keyinfo.key_len);
|
||||||
|
/*ip info:ipaddress, netmask, dns*/
|
||||||
|
ipinfo->ip_addr[0] = 192;
|
||||||
|
ipinfo->ip_addr[1] = 168;
|
||||||
|
ipinfo->ip_addr[2] = 1;
|
||||||
|
ipinfo->ip_addr[3] = 1;
|
||||||
|
ipinfo->netmask[0] = 255;
|
||||||
|
ipinfo->netmask[1] = 255;
|
||||||
|
ipinfo->netmask[2] = 255;
|
||||||
|
ipinfo->netmask[3] = 0;
|
||||||
|
MEMCPY(ipinfo->dnsname, "local.wm", sizeof("local.wm"));
|
||||||
|
|
||||||
|
blackstate = DEL_BLACK_STATE;
|
||||||
|
tls_wifi_softap_add_blacksta(blackmac);
|
||||||
|
|
||||||
|
ret = tls_wifi_softap_create(apinfo, ipinfo);
|
||||||
|
wm_printf("\n ap create %s ! \n", (ret == WM_SUCCESS) ? "Successfully" : "Error");
|
||||||
|
|
||||||
|
if (WM_SUCCESS == ret)
|
||||||
|
{
|
||||||
|
if (sta_monitor_tim)
|
||||||
|
{
|
||||||
|
tls_os_timer_delete(sta_monitor_tim);
|
||||||
|
sta_monitor_tim = NULL;
|
||||||
|
}
|
||||||
|
tls_os_timer_create(&sta_monitor_tim, demo_monitor_stalist_tim, NULL, 500, TRUE, NULL);
|
||||||
|
tls_os_timer_start(sta_monitor_tim);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_mem_free(ipinfo);
|
||||||
|
tls_mem_free(apinfo);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
1199
demo/wm_ssl_server_demo.c
Normal file
1199
demo/wm_ssl_server_demo.c
Normal file
File diff suppressed because it is too large
Load Diff
80
demo/wm_ssl_server_demo.h
Normal file
80
demo/wm_ssl_server_demo.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#ifndef _h_MATRIXSSLAPP
|
||||||
|
#define _h_MATRIXSSLAPP
|
||||||
|
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_SSL_SERVER
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#include <errno.h> /* Defines EWOULDBLOCK, etc. */
|
||||||
|
#include <stdlib.h> /* Defines malloc, exit, etc. */
|
||||||
|
#include "wm_ssl_server.h"
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*
|
||||||
|
Platform independent socket defines for convenience
|
||||||
|
*/
|
||||||
|
#ifndef SOCKET
|
||||||
|
typedef int32 SOCKET;
|
||||||
|
#endif
|
||||||
|
#ifndef INVALID_SOCKET
|
||||||
|
#define INVALID_SOCKET -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SOCKET_ERRNO errno
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*
|
||||||
|
Configuration Options
|
||||||
|
*/
|
||||||
|
#define HTTPS_PORT 4433 /* Port to run the server/client on */
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#if !TLS_CONFIG_USE_MBEDTLS
|
||||||
|
/*
|
||||||
|
Protocol specific defines
|
||||||
|
*/
|
||||||
|
/* Maximum size of parseable http element. In this case, a HTTP header line. */
|
||||||
|
#define HTTPS_BUFFER_MAX 256
|
||||||
|
|
||||||
|
/* Return codes from http parsing routine */
|
||||||
|
#define HTTPS_COMPLETE 1 /* Full request/response parsed */
|
||||||
|
#define HTTPS_PARTIAL 0 /* Only a partial request/response was received */
|
||||||
|
#define HTTPS_ERROR MATRIXSSL_ERROR /* Invalid/unsupported HTTP syntax */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
DLListEntry List;
|
||||||
|
tls_ssl_t *ssl;
|
||||||
|
SOCKET fd;
|
||||||
|
psTime_t time; /* Last time there was activity */
|
||||||
|
uint32 timeout; /* in milliseconds*/
|
||||||
|
uint32 flags;
|
||||||
|
unsigned char *parsebuf; /* Partial data */
|
||||||
|
uint32 parsebuflen;
|
||||||
|
uint32 bytes_received;
|
||||||
|
uint32 bytes_requested;
|
||||||
|
uint32 bytes_sent;
|
||||||
|
} httpConn_t;
|
||||||
|
|
||||||
|
static int32 httpBasicParse(httpConn_t *cp, unsigned char *buf, uint32 len,
|
||||||
|
int32 trace);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //DEMO_SSL_SERVER
|
||||||
|
|
||||||
|
#endif /* _h_MATRIXSSLAPP */
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
40
demo/wm_timer_demo.c
Normal file
40
demo/wm_timer_demo.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_timer.h"
|
||||||
|
|
||||||
|
#if DEMO_TIMER
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_timer_irq(u8 *arg)
|
||||||
|
{
|
||||||
|
printf("timer irq\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int timer_demo(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
u8 timer_id;
|
||||||
|
struct tls_timer_cfg timer_cfg;
|
||||||
|
|
||||||
|
timer_cfg.unit = TLS_TIMER_UNIT_MS;
|
||||||
|
timer_cfg.timeout = 2000;
|
||||||
|
timer_cfg.is_repeat = 1;
|
||||||
|
timer_cfg.callback = (tls_timer_irq_callback)demo_timer_irq;
|
||||||
|
timer_cfg.arg = NULL;
|
||||||
|
timer_id = tls_timer_create(&timer_cfg);
|
||||||
|
tls_timer_start(timer_id);
|
||||||
|
printf("timer start\n");
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
124
demo/wm_touchsensor_demo.c
Normal file
124
demo/wm_touchsensor_demo.c
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_touchsensor.h"
|
||||||
|
#include "wm_regs.h"
|
||||||
|
#include "wm_irq.h"
|
||||||
|
#include "wm_cpu.h"
|
||||||
|
#include "wm_gpio.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
#if DEMO_TOUCHSENSOR
|
||||||
|
#define KEY_PRESS_QUEUE_LENGTH (32)
|
||||||
|
tls_os_queue_t *key_press_queue = NULL;
|
||||||
|
#define KEY_PRESS_TASK_STACK 512
|
||||||
|
u32 key_press_stack[KEY_PRESS_TASK_STACK];
|
||||||
|
|
||||||
|
#define SCAN_PERIOD (1) //range [1, 63] unit:16ms
|
||||||
|
#define SCAN_WINDOW (32) //range [3,63]
|
||||||
|
#define TOUCH_BIAS (4) //range[1,7]
|
||||||
|
|
||||||
|
//total touch number
|
||||||
|
#define TOUCH_MAX_NUM (15)
|
||||||
|
//different touch can use different limit
|
||||||
|
u16 touch_limit[TOUCH_MAX_NUM] = {40, 30, 30, 30, 30, 30, 30, 30, 30, 30, 45, 35, 40, 30, 30};
|
||||||
|
enum tls_io_name touchio[TOUCH_MAX_NUM] = {WM_IO_PA_07, WM_IO_PA_09, WM_IO_PA_10, /*touch 1-3*/
|
||||||
|
WM_IO_PB_00, WM_IO_PB_01, WM_IO_PB_02, /*touch 4-6*/
|
||||||
|
WM_IO_PB_03, WM_IO_PB_04, WM_IO_PB_05, /*touch 7-9*/
|
||||||
|
WM_IO_PB_06, WM_IO_PB_07, WM_IO_PB_08, /*touch 10-12*/
|
||||||
|
WM_IO_PB_09, WM_IO_PA_12, WM_IO_PA_14};/*touch 13-15*/
|
||||||
|
|
||||||
|
void key_press_callback(u32 status)
|
||||||
|
{
|
||||||
|
if (key_press_queue)
|
||||||
|
{
|
||||||
|
tls_os_queue_send(key_press_queue,(void *)status,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void key_press_task_hdl(void)
|
||||||
|
{
|
||||||
|
u32 *msg;
|
||||||
|
u32 value = 0;
|
||||||
|
int i = 0;
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(key_press_queue,(void * *)&msg,0,0);
|
||||||
|
value = (u32)msg;
|
||||||
|
for (i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
if (value&(1<<i))
|
||||||
|
{
|
||||||
|
wm_printf("key %d\r\n is pressed\r\n", (i+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*test code
|
||||||
|
You can call this function in function UserMain in main.c and when you touch the pad,you can find uart log printing from function tls_touchsensor_irq_handler.
|
||||||
|
If the corresponding bit is set, this touch sensor has been touched.
|
||||||
|
You can register your callback if need.
|
||||||
|
*/
|
||||||
|
void key_init(int touchnum)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
/*deinit all touch sensor*/
|
||||||
|
for (i = TOUCH_MAX_NUM; i > 0; i--)
|
||||||
|
{
|
||||||
|
tls_touchsensor_deinit(i);
|
||||||
|
tls_gpio_cfg(touchio[i-1],WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_touchsensor_scan_stop();
|
||||||
|
for (i = 0; i < TOUCH_MAX_NUM; i++)
|
||||||
|
{
|
||||||
|
if ((touchnum == 0) || (touchnum & (1 << i)))
|
||||||
|
{
|
||||||
|
/*1)configure touch sensor IO multiplex.*/
|
||||||
|
wm_touch_sensor_config(touchio[i]);
|
||||||
|
/*2)set threshold each touch pad, you can set different threshold for each touch pad*/
|
||||||
|
tls_touchsensor_threshold_config(i + 1, touch_limit[i]);
|
||||||
|
tls_touchsensor_chan_config(i+1);
|
||||||
|
/*3)enable touch sensor's irq , only enable specified irq bit, you can find the pad is touched by irq.*/
|
||||||
|
tls_touchsensor_irq_enable(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*4)init touch sensor's parameter, all touch sensor only can use the same configure parameter.
|
||||||
|
user can adjust window,scan period and bias current*/
|
||||||
|
tls_touchsensor_scan_config(SCAN_PERIOD, SCAN_WINDOW, TOUCH_BIAS);
|
||||||
|
tls_touchsensor_scan_start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void key_press_init(int touchnum)
|
||||||
|
{
|
||||||
|
if (key_press_queue == NULL)
|
||||||
|
{
|
||||||
|
tls_os_queue_create(&key_press_queue,KEY_PRESS_QUEUE_LENGTH);
|
||||||
|
tls_os_task_create(NULL,NULL, (void *)key_press_task_hdl,NULL, (u8 *)&key_press_stack[0],KEY_PRESS_TASK_STACK*4,50,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_touchsensor_irq_register(key_press_callback);
|
||||||
|
key_init(touchnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_touchsensor(int touchnum)
|
||||||
|
{
|
||||||
|
if ((touchnum <= 65535) )
|
||||||
|
{
|
||||||
|
wm_printf("test touch:%x\r\n", touchnum);
|
||||||
|
key_press_init(touchnum);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wm_printf("Usage: t-touch(0),t-touch(1),t-touch(3),t-touch(5)...t-touch(65535)\r\n");
|
||||||
|
wm_printf(" 1)If you enable only one touch sensor, then touch sensor 1 must be used firstly.\r\n");
|
||||||
|
wm_printf(" 2)You can set touchnum == 0 and enable all touch sensor.\r\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
205
demo/wm_uart_demo.c
Normal file
205
demo/wm_uart_demo.c
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_uart_demo.c
|
||||||
|
*
|
||||||
|
* @brief uart demo function
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_http_fwup.h"
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
#include "wm_cpu.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
|
||||||
|
#if DEMO_UARTx
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
|
#define USE_DMA_TX_FTR 0
|
||||||
|
#if USE_DMA_TX_FTR
|
||||||
|
#include "wm_dma.h"
|
||||||
|
extern int tls_uart_dma_off(u16 uart_no);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEMO_UART_TAST_STK_SIZE 1024
|
||||||
|
#define DEMO_UART_RX_BUF_SIZE 1024
|
||||||
|
|
||||||
|
static OS_STK demo_uart_task_stk[DEMO_UART_TAST_STK_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef struct DEMO_UART
|
||||||
|
*/
|
||||||
|
typedef struct DEMO_UART
|
||||||
|
{
|
||||||
|
tls_os_queue_t *demo_uart_q;
|
||||||
|
// OS_STK *demo_uart_task_stk;
|
||||||
|
int bandrate;
|
||||||
|
TLS_UART_PMODE_T parity;
|
||||||
|
TLS_UART_STOPBITS_T stopbits;
|
||||||
|
char *rx_buf;
|
||||||
|
int rx_msg_num;
|
||||||
|
int rx_data_len;
|
||||||
|
} DEMO_UART_ST;
|
||||||
|
|
||||||
|
static DEMO_UART_ST *demo_uart = NULL;
|
||||||
|
|
||||||
|
#if USE_DMA_TX_FTR
|
||||||
|
static void uart_dma_done(void *uart_no)
|
||||||
|
{
|
||||||
|
u16 ch = *((u16 *)uart_no);
|
||||||
|
tls_uart_dma_off(ch);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
static s16 demo_uart_rx(u16 len)
|
||||||
|
{
|
||||||
|
if (NULL == demo_uart)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_uart->rx_data_len += len;
|
||||||
|
if (demo_uart->rx_msg_num < 3)
|
||||||
|
{
|
||||||
|
demo_uart->rx_msg_num++;
|
||||||
|
tls_os_queue_send(demo_uart->demo_uart_q, (void *) DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_uart_task(void *sdata)
|
||||||
|
{
|
||||||
|
DEMO_UART_ST *uart = (DEMO_UART_ST *) sdata;
|
||||||
|
tls_uart_options_t opt;
|
||||||
|
void *msg;
|
||||||
|
int ret = 0;
|
||||||
|
int len = 0;
|
||||||
|
int rx_len = 0;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(uart->demo_uart_q, (void **) &msg, 0, 0);
|
||||||
|
switch ((u32) msg)
|
||||||
|
{
|
||||||
|
case DEMO_MSG_OPEN_UART:
|
||||||
|
{
|
||||||
|
opt.baudrate = uart->bandrate;
|
||||||
|
opt.paritytype = uart->parity;
|
||||||
|
opt.stopbits = uart->stopbits;
|
||||||
|
opt.charlength = TLS_UART_CHSIZE_8BIT;
|
||||||
|
opt.flow_ctrl = TLS_UART_FLOW_CTRL_NONE;
|
||||||
|
|
||||||
|
//选择待使用的引脚及具体的复用功能
|
||||||
|
/* UART1_RX-PB07 UART1_TX-PB06 */
|
||||||
|
wm_uart1_rx_config(WM_IO_PB_07);
|
||||||
|
wm_uart1_tx_config(WM_IO_PB_06);
|
||||||
|
|
||||||
|
if (WM_SUCCESS != tls_uart_port_init(TLS_UART_1, &opt, 0))
|
||||||
|
{
|
||||||
|
printf("uart1 init error\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_uart_rx_callback_register((u16) TLS_UART_1, (s16(*)(u16, void*))demo_uart_rx, NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_UART_RECEIVE_DATA:
|
||||||
|
{
|
||||||
|
rx_len = uart->rx_data_len;
|
||||||
|
while (rx_len > 0)
|
||||||
|
{
|
||||||
|
len = (rx_len > DEMO_UART_RX_BUF_SIZE) ? DEMO_UART_RX_BUF_SIZE : rx_len;
|
||||||
|
memset(uart->rx_buf, 0, (DEMO_UART_RX_BUF_SIZE + 1));
|
||||||
|
ret = tls_uart_read(TLS_UART_1, (u8 *) uart->rx_buf, len); /* input */
|
||||||
|
if (ret <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rx_len -= ret;
|
||||||
|
uart->rx_data_len -= ret;
|
||||||
|
|
||||||
|
#if USE_DMA_TX_FTR
|
||||||
|
tls_uart_dma_write(uart->rx_buf, len, uart_dma_done, TLS_UART_1);
|
||||||
|
#else
|
||||||
|
tls_uart_write(TLS_UART_1, uart->rx_buf, ret); /* output */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (uart->rx_msg_num > 0)
|
||||||
|
{
|
||||||
|
uart->rx_msg_num--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int uart_demo(int bandrate, int parity, int stopbits)
|
||||||
|
{
|
||||||
|
printf("\nuart demo param=%d, %d, %d\n", bandrate, parity, stopbits);
|
||||||
|
if (NULL == demo_uart)
|
||||||
|
{
|
||||||
|
demo_uart = tls_mem_alloc(sizeof(DEMO_UART_ST));
|
||||||
|
if (NULL == demo_uart)
|
||||||
|
{
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
memset(demo_uart, 0, sizeof(DEMO_UART_ST));
|
||||||
|
|
||||||
|
demo_uart->rx_buf = tls_mem_alloc(DEMO_UART_RX_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_uart->rx_buf)
|
||||||
|
{
|
||||||
|
goto _error1;
|
||||||
|
}
|
||||||
|
tls_os_queue_create(&(demo_uart->demo_uart_q), DEMO_QUEUE_SIZE);
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_uart_task,
|
||||||
|
(void *) demo_uart,
|
||||||
|
(void *) demo_uart_task_stk, /** 任务栈的起始地址 */
|
||||||
|
DEMO_UART_TAST_STK_SIZE*4, /** 任务栈的大小 */
|
||||||
|
DEMO_UART_TASK_PRIO, 0);
|
||||||
|
}
|
||||||
|
if (-1 == bandrate)
|
||||||
|
{
|
||||||
|
bandrate = 115200;
|
||||||
|
}
|
||||||
|
if (-1 == parity)
|
||||||
|
{
|
||||||
|
parity = TLS_UART_PMODE_DISABLED;
|
||||||
|
}
|
||||||
|
if (-1 == stopbits)
|
||||||
|
{
|
||||||
|
stopbits = TLS_UART_ONE_STOPBITS;
|
||||||
|
}
|
||||||
|
demo_uart->bandrate = bandrate;
|
||||||
|
demo_uart->parity = (TLS_UART_PMODE_T) parity;
|
||||||
|
demo_uart->stopbits = (TLS_UART_STOPBITS_T) stopbits;
|
||||||
|
demo_uart->rx_msg_num = 0;
|
||||||
|
demo_uart->rx_data_len = 0;
|
||||||
|
tls_os_queue_send(demo_uart->demo_uart_q, (void *) DEMO_MSG_OPEN_UART, 0);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
|
||||||
|
_error1:
|
||||||
|
tls_mem_free(demo_uart);
|
||||||
|
demo_uart = NULL;
|
||||||
|
_error:
|
||||||
|
printf("\nmem error\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
403
demo/wm_udp_demo.c
Normal file
403
demo/wm_udp_demo.c
Normal file
@ -0,0 +1,403 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_udp_demo.c
|
||||||
|
*
|
||||||
|
* @brief udp demo
|
||||||
|
*
|
||||||
|
* @author dave
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_demo.h"
|
||||||
|
#include "wm_sockets.h"
|
||||||
|
|
||||||
|
#if DEMO_UDP
|
||||||
|
#define DEMO_UDP_BROADCAST 0
|
||||||
|
#define DEMO_UDP_UNICAST 1
|
||||||
|
#define DEMO_UDP_MUTICAST 2
|
||||||
|
|
||||||
|
#define DEMO_UDP_TASK_SIZE 512
|
||||||
|
#define DEMO_UDP_BUF_SIZE 1024
|
||||||
|
|
||||||
|
#define DEMO_UDP_LOCAL_PORT 3000
|
||||||
|
|
||||||
|
static u8 MCASTIP[4] = {224, 1, 2, 1};
|
||||||
|
|
||||||
|
static OS_STK udp_task_stk[DEMO_UDP_TASK_SIZE];
|
||||||
|
static OS_STK udp_rcv_task_stk[DEMO_UDP_TASK_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef struct demo_udp
|
||||||
|
*/
|
||||||
|
typedef struct demo_udp
|
||||||
|
{
|
||||||
|
tls_os_queue_t *udp_q;
|
||||||
|
struct ip_mreq mreq;
|
||||||
|
char *sock_rx;
|
||||||
|
char *sock_tx;
|
||||||
|
int cast_mode;
|
||||||
|
bool socket_ok;
|
||||||
|
int socket_num;
|
||||||
|
int port;
|
||||||
|
u32 ip_addr;
|
||||||
|
u32 rcv_data_len;
|
||||||
|
int snd_skt_no;
|
||||||
|
int snd_data_len;
|
||||||
|
|
||||||
|
} ST_Demo_Udp;
|
||||||
|
|
||||||
|
ST_Demo_Udp *demo_udp = NULL;
|
||||||
|
|
||||||
|
static void demo_udp_task(void *sdata);
|
||||||
|
|
||||||
|
|
||||||
|
int create_udp_socket_demo(void)
|
||||||
|
{
|
||||||
|
struct sockaddr_in pin;
|
||||||
|
struct tls_ethif *ethif;
|
||||||
|
int ttl = 10;
|
||||||
|
int loop = 0;
|
||||||
|
|
||||||
|
ethif = tls_netif_get_ethif();
|
||||||
|
printf("local ip : %d.%d.%d.%d\n", ip4_addr1(ip_2_ip4(ðif->ip_addr)), ip4_addr2(ip_2_ip4(ðif->ip_addr)),
|
||||||
|
ip4_addr3(ip_2_ip4(ðif->ip_addr)), ip4_addr4(ip_2_ip4(ðif->ip_addr)));
|
||||||
|
demo_udp->socket_num = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
|
||||||
|
memset(&pin, 0, sizeof(struct sockaddr_in));
|
||||||
|
pin.sin_family = AF_INET;
|
||||||
|
pin.sin_addr.s_addr = (u32)0x00000000UL; //IPADDR_ANY
|
||||||
|
pin.sin_port = htons(DEMO_UDP_LOCAL_PORT);
|
||||||
|
|
||||||
|
printf("local port :%d\n", DEMO_UDP_LOCAL_PORT);
|
||||||
|
if (bind(demo_udp->socket_num, (struct sockaddr *) &pin, sizeof(pin)) == -1)
|
||||||
|
{
|
||||||
|
printf("bind err\n");
|
||||||
|
closesocket(demo_udp->socket_num);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DEMO_UDP_MUTICAST == demo_udp->cast_mode)
|
||||||
|
{
|
||||||
|
//Configure multicast TTL
|
||||||
|
printf("set muticast\n");
|
||||||
|
if (setsockopt(demo_udp->socket_num, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
|
||||||
|
{
|
||||||
|
printf("IP_MULTICAST_TTL");
|
||||||
|
closesocket(demo_udp->socket_num);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
//Local Loop setting
|
||||||
|
if (setsockopt(demo_udp->socket_num, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) < 0)
|
||||||
|
{
|
||||||
|
printf("IP_MULTICAST_LOOP");
|
||||||
|
closesocket(demo_udp->socket_num);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
MEMCPY((char *) & (demo_udp->mreq.imr_multiaddr.s_addr), (char *)MCASTIP, 4);
|
||||||
|
demo_udp->mreq.imr_interface.s_addr = htonl(0x00000000UL);
|
||||||
|
//join muticast group
|
||||||
|
if (setsockopt(demo_udp->socket_num, IPPROTO_IP, IP_ADD_MEMBERSHIP, &(demo_udp->mreq), sizeof(demo_udp->mreq)) < 0)
|
||||||
|
{
|
||||||
|
printf("IP_ADD_MEMBERSHIP");
|
||||||
|
closesocket(demo_udp->socket_num);
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_udp->socket_ok = TRUE;
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void demo_udp_recv_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Udp *udp = (ST_Demo_Udp *)sdata;
|
||||||
|
int ret = 0;
|
||||||
|
struct sockaddr_in pin;
|
||||||
|
socklen_t addrlen = sizeof(struct sockaddr);
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
if (udp->socket_ok)
|
||||||
|
{
|
||||||
|
ret = recvfrom(udp->socket_num, udp->sock_rx, DEMO_UDP_BUF_SIZE,
|
||||||
|
0, (struct sockaddr *)&pin, &addrlen);
|
||||||
|
|
||||||
|
if (ret > 0)
|
||||||
|
{
|
||||||
|
printf("rcv from %s : port : %d len = %d\n", inet_ntoa(pin.sin_addr), htons(pin.sin_port), ret);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("rcv err\n");
|
||||||
|
udp->socket_ok = FALSE;
|
||||||
|
if (DEMO_UDP_MUTICAST == udp->cast_mode)
|
||||||
|
{
|
||||||
|
setsockopt(udp->socket_num, IPPROTO_IP, IP_DROP_MEMBERSHIP, &(udp->mreq), sizeof(udp->mreq));
|
||||||
|
}
|
||||||
|
closesocket(udp->socket_num);
|
||||||
|
printf("closesocket\n");
|
||||||
|
tls_os_queue_send(udp->udp_q, (void *)DEMO_MSG_SOCKET_ERR, 0);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tls_os_time_delay(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int udp_send_data_demo(int len)
|
||||||
|
{
|
||||||
|
printf("\nlen=%d\n", len);
|
||||||
|
if (NULL == demo_udp)
|
||||||
|
{
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
if (!demo_udp->socket_ok)
|
||||||
|
{
|
||||||
|
printf("skt not created\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_udp->snd_data_len = len;
|
||||||
|
tls_os_queue_send(demo_udp->udp_q, (void *)DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief udp demo
|
||||||
|
*
|
||||||
|
* @param[in] cast_mode unicast or broadcast, 0 is broadcast, 1 is unicast, default is broadcast
|
||||||
|
* @param[in] port port num
|
||||||
|
* @param[in] *ip if cast mode is unicast, need define ip addr.
|
||||||
|
*
|
||||||
|
* @retval 0 success
|
||||||
|
* @retval other failed
|
||||||
|
*
|
||||||
|
* @note None
|
||||||
|
*/
|
||||||
|
int socket_udp_demo(int cast_mode, int port, char *ip)
|
||||||
|
{
|
||||||
|
if (demo_udp)
|
||||||
|
{
|
||||||
|
printf("run\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
printf("udp demo,cast:%d, port:%d\n", cast_mode, port);
|
||||||
|
if(-1 == cast_mode)
|
||||||
|
{
|
||||||
|
cast_mode = DEMO_UDP_BROADCAST;
|
||||||
|
}
|
||||||
|
if(-1 == port || port > 65536)
|
||||||
|
{
|
||||||
|
printf("port err\n");
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
if(NULL == ip)
|
||||||
|
{
|
||||||
|
if (DEMO_UDP_UNICAST == cast_mode)
|
||||||
|
{
|
||||||
|
printf("donot input ip,will send broadcast packet\n");
|
||||||
|
cast_mode = DEMO_UDP_BROADCAST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL == demo_udp)
|
||||||
|
{
|
||||||
|
demo_udp = tls_mem_alloc(sizeof(ST_Demo_Udp));
|
||||||
|
if (NULL == demo_udp)
|
||||||
|
{
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
memset(demo_udp, 0, sizeof(ST_Demo_Udp));
|
||||||
|
|
||||||
|
demo_udp->sock_rx = tls_mem_alloc(DEMO_UDP_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_udp->sock_rx)
|
||||||
|
{
|
||||||
|
goto _error3;
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_udp->sock_tx = tls_mem_alloc(DEMO_UDP_BUF_SIZE + 1);
|
||||||
|
if (NULL == demo_udp->sock_tx)
|
||||||
|
{
|
||||||
|
goto _error4;
|
||||||
|
}
|
||||||
|
|
||||||
|
tls_os_queue_create(&(demo_udp->udp_q), DEMO_QUEUE_SIZE);
|
||||||
|
//deal with socket's message
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_udp_task,
|
||||||
|
(void *)demo_udp,
|
||||||
|
(void *)udp_task_stk, /* task's stack start address */
|
||||||
|
DEMO_UDP_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_UDP_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
|
||||||
|
//deal with socket's rx data
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
demo_udp_recv_task,
|
||||||
|
(void *)demo_udp,
|
||||||
|
(void *)udp_rcv_task_stk, /* task's stack start address */
|
||||||
|
DEMO_UDP_TASK_SIZE*sizeof(u32), /* task's stack size, unit:byte */
|
||||||
|
DEMO_UDP_RECEIVE_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
demo_udp->port = port;
|
||||||
|
if (ip)
|
||||||
|
{
|
||||||
|
demo_udp->ip_addr = ipaddr_addr(ip);
|
||||||
|
}
|
||||||
|
demo_udp->cast_mode = cast_mode;
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
|
||||||
|
_error4:
|
||||||
|
tls_mem_free(demo_udp->sock_rx);
|
||||||
|
_error3:
|
||||||
|
tls_mem_free(demo_udp);
|
||||||
|
demo_udp = NULL;
|
||||||
|
_error:
|
||||||
|
return WM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void udp_net_status_changed_event(u8 status )
|
||||||
|
{
|
||||||
|
switch(status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
tls_os_queue_send(demo_udp->udp_q, (void *)DEMO_MSG_WJOIN_FAILD, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
tls_os_queue_send(demo_udp->udp_q, (void *)DEMO_MSG_WJOIN_SUCCESS, 0);
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
tls_os_queue_send(demo_udp->udp_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void demo_udp_task(void *sdata)
|
||||||
|
{
|
||||||
|
ST_Demo_Udp *udp = (ST_Demo_Udp *)sdata;
|
||||||
|
void *msg;
|
||||||
|
struct tls_ethif *ethif = tls_netif_get_ethif();
|
||||||
|
int len;
|
||||||
|
int ret;
|
||||||
|
struct sockaddr_in pin;
|
||||||
|
|
||||||
|
if(ethif->status) /*connected to ap and get IP*/
|
||||||
|
{
|
||||||
|
tls_os_queue_send(udp->udp_q, (void *)DEMO_MSG_SOCKET_CREATE, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct tls_param_ip ip_param;
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
ip_param.dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, &ip_param, TRUE);
|
||||||
|
tls_wifi_set_oneshot_flag(1); /*Enable oneshot configuration*/
|
||||||
|
printf("\nwait one shot......\n");
|
||||||
|
}
|
||||||
|
tls_netif_add_status_event(udp_net_status_changed_event);
|
||||||
|
|
||||||
|
memset(&pin, 0, sizeof(struct sockaddr_in));
|
||||||
|
pin.sin_family = AF_INET;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
tls_os_queue_receive(udp->udp_q, (void **)&msg, 0, 0);
|
||||||
|
//printf("\n msg =%d\n",msg);
|
||||||
|
switch((u32)msg)
|
||||||
|
{
|
||||||
|
case DEMO_MSG_WJOIN_SUCCESS:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_CREATE:
|
||||||
|
create_udp_socket_demo();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_WJOIN_FAILD:
|
||||||
|
if(udp->socket_num > 0)
|
||||||
|
{
|
||||||
|
udp->socket_num = 0;
|
||||||
|
udp->socket_ok = FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_RECEIVE_DATA:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_UART_RECEIVE_DATA:
|
||||||
|
if (-1 == udp->snd_data_len)
|
||||||
|
{
|
||||||
|
len = DEMO_UDP_BUF_SIZE;
|
||||||
|
}
|
||||||
|
else if(udp->snd_data_len != 0)
|
||||||
|
{
|
||||||
|
len = (udp->snd_data_len > DEMO_UDP_BUF_SIZE) ?
|
||||||
|
DEMO_UDP_BUF_SIZE : udp->snd_data_len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memset(udp->sock_tx, 'u', len);
|
||||||
|
|
||||||
|
if (DEMO_UDP_BROADCAST == udp->cast_mode)
|
||||||
|
{
|
||||||
|
pin.sin_addr.s_addr = htonl(0xffffffffUL); //IPADDR_BROADCAST
|
||||||
|
}
|
||||||
|
else if (DEMO_UDP_MUTICAST == udp->cast_mode)
|
||||||
|
{
|
||||||
|
MEMCPY((char *) & (pin.sin_addr.s_addr), (char *)MCASTIP, 4);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pin.sin_addr.s_addr = udp->ip_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
pin.sin_port = htons(udp->port);
|
||||||
|
|
||||||
|
ret = sendto(udp->socket_num, udp->sock_tx, len, 0, (struct sockaddr *)&pin, sizeof(struct sockaddr));
|
||||||
|
// printf("ret = %d\n",ret);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("send err\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (udp->snd_data_len != -1)
|
||||||
|
{
|
||||||
|
udp->snd_data_len -= ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (udp->socket_ok && udp->snd_data_len != 0)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(8);
|
||||||
|
tls_os_queue_send(udp->udp_q, (void *)DEMO_MSG_UART_RECEIVE_DATA, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DEMO_MSG_SOCKET_ERR:
|
||||||
|
tls_os_time_delay(200);
|
||||||
|
printf("\nsocket err\n");
|
||||||
|
create_udp_socket_demo( );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
305
demo/wm_websockets_demo.c
Normal file
305
demo/wm_websockets_demo.c
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
#include "wm_include.h"
|
||||||
|
#include "libwebsockets.h"
|
||||||
|
|
||||||
|
#if DEMO_WEBSOCKETS
|
||||||
|
|
||||||
|
/*
|
||||||
|
****************************************************************************************
|
||||||
|
Notice
|
||||||
|
Test steps(with LWS_USE_SSL disabled):
|
||||||
|
1, Download websocket tool from https://download.csdn.net/download/zwl1584671413/10618985 ;
|
||||||
|
2, Unzip it and excute "websocketd --port=8080 echo_client.bat" in your CLI window.
|
||||||
|
3, Redefine LWS_SERVER_NAME.
|
||||||
|
4, Run function lwsDemoTest() in your main entrance or demo console.
|
||||||
|
|
||||||
|
Test steps(with LWS_USE_SSL enabled):
|
||||||
|
1, Download websocket tool from https://download.csdn.net/download/zwl1584671413/10618985 ;
|
||||||
|
2, Unzip it and excute
|
||||||
|
"websocketd --port=8080 --ssl --sslcert="certificate.pem" --sslkey="key.pem" echo_client.bat"
|
||||||
|
in your CLI window.
|
||||||
|
3, Run function lwsDemoTest() in your main entrance or demo console.
|
||||||
|
|
||||||
|
Need to see detail logs? Please mask NDEBUG and LWS_WITH_NO_LOGS from file lws_config.h.
|
||||||
|
****************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define lws_debug printf
|
||||||
|
#define SEND_MSG_MIN 128 // only {"msg_type":"keepalive"}
|
||||||
|
#define DEMO_LWS_RECV_TASK_SIZE 2048
|
||||||
|
#define DEMO_LWS_SEND_TASK_SIZE 256
|
||||||
|
#define LWS_USE_SSL (1 && TLS_CONFIG_HTTP_CLIENT_SECURE)
|
||||||
|
#define LWS_SERVER_NAME "192.168.1.100"
|
||||||
|
#define LWS_SERVER_PORT 8080//4
|
||||||
|
#define LWS_SERVER_PATH "/"
|
||||||
|
|
||||||
|
enum lws_state{
|
||||||
|
EXIT_SESSION,
|
||||||
|
INIT_SESSION,
|
||||||
|
SET_UP_SESSION,
|
||||||
|
HANDLE_SESSION
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*Communication_ReceiveData)(const char *data, unsigned int dataLength);
|
||||||
|
static Communication_ReceiveData receive_data_notify = NULL ;
|
||||||
|
|
||||||
|
static OS_STK DemoLwsRecvStk[DEMO_LWS_RECV_TASK_SIZE];
|
||||||
|
static OS_STK DemoLwsSendStk[DEMO_LWS_SEND_TASK_SIZE];
|
||||||
|
static struct lws* g_wsContext=NULL;
|
||||||
|
static u8 send_buffer[SEND_MSG_MIN + LWS_SEND_BUFFER_PRE_PADDING + 4];
|
||||||
|
static u8 *data_2send=NULL;
|
||||||
|
static int data_length;
|
||||||
|
static u32 watchDog = 0;
|
||||||
|
enum lws_state now_state = INIT_SESSION;
|
||||||
|
|
||||||
|
|
||||||
|
static int demoLwsSend(const char *data, unsigned int length)
|
||||||
|
{
|
||||||
|
if( g_wsContext==NULL){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
data_length = length;
|
||||||
|
if(length < SEND_MSG_MIN ){
|
||||||
|
memset( send_buffer, 0, sizeof(send_buffer) );
|
||||||
|
memcpy(send_buffer + LWS_SEND_BUFFER_PRE_PADDING , data, length );
|
||||||
|
data_2send = send_buffer + LWS_SEND_BUFFER_PRE_PADDING;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
lws_debug("length > SEND_MSG_MIN\r\n");
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lwsCallbackNotify(struct lws *wsi,enum lws_callback_reasons reason,void *user, void *in, size_t len)
|
||||||
|
{
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
||||||
|
lws_debug("CLIENT_ESTABLISHED\n");
|
||||||
|
now_state = HANDLE_SESSION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
||||||
|
lws_debug("CLIENT_CONNECTION_ERROR\n");
|
||||||
|
now_state = EXIT_SESSION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLOSED:
|
||||||
|
lws_debug("CLOSED\n");
|
||||||
|
now_state = EXIT_SESSION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLIENT_RECEIVE:
|
||||||
|
((char *)in)[len] = '\0';
|
||||||
|
if( receive_data_notify!=NULL )
|
||||||
|
receive_data_notify( in, len );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LWS_CALLBACK_CLIENT_WRITEABLE:
|
||||||
|
watchDog = 0;
|
||||||
|
if( data_2send !=NULL ){
|
||||||
|
lws_debug("send %s\r\n", data_2send);
|
||||||
|
int n = lws_write( g_wsContext, data_2send, data_length, LWS_WRITE_TEXT );
|
||||||
|
if( n <= 0 ) {
|
||||||
|
lws_debug("send %d\r\n", n);
|
||||||
|
now_state = EXIT_SESSION;
|
||||||
|
}
|
||||||
|
data_2send = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int isNetworkOk(void)
|
||||||
|
{
|
||||||
|
struct tls_ethif* etherIf= tls_netif_get_ethif();
|
||||||
|
|
||||||
|
return etherIf->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void dataReceived(const char *data, unsigned int dataLength)
|
||||||
|
{
|
||||||
|
lws_debug("recv:%s\r\n\r\n", data );
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct lws_protocols protocols[] = {
|
||||||
|
{
|
||||||
|
"wss",
|
||||||
|
lwsCallbackNotify,
|
||||||
|
0,
|
||||||
|
2048,
|
||||||
|
},
|
||||||
|
{ NULL, NULL, 0, 0 } /* end */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void lwsRecvTask( void* lparam )
|
||||||
|
{
|
||||||
|
struct lws_client_connect_info connInfo;
|
||||||
|
struct lws_context_creation_info info;
|
||||||
|
struct lws_context *lwscontext = NULL;
|
||||||
|
u32 oldTick = 0, nowTick = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
//lws_debug("now_state: %d\n", now_state);
|
||||||
|
switch(now_state)
|
||||||
|
{
|
||||||
|
case INIT_SESSION:
|
||||||
|
{
|
||||||
|
if(1 == isNetworkOk())
|
||||||
|
{
|
||||||
|
if( lwscontext == NULL )
|
||||||
|
{
|
||||||
|
memset(&info, 0, sizeof(info) );
|
||||||
|
info.port = CONTEXT_PORT_NO_LISTEN;
|
||||||
|
#if LWS_USE_SSL
|
||||||
|
info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||||
|
#endif
|
||||||
|
info.protocols = protocols;
|
||||||
|
info.options = 0;
|
||||||
|
info.max_http_header_data=512;
|
||||||
|
info.max_http_header_pool=4;
|
||||||
|
|
||||||
|
lwscontext = lws_create_context(&info);
|
||||||
|
memset(&connInfo, 0 , sizeof(connInfo) );
|
||||||
|
connInfo.context = lwscontext;
|
||||||
|
connInfo.address = LWS_SERVER_NAME;
|
||||||
|
connInfo.port = LWS_SERVER_PORT;
|
||||||
|
connInfo.ssl_connection=LWS_USE_SSL;
|
||||||
|
connInfo.path = LWS_SERVER_PATH;
|
||||||
|
connInfo.host = LWS_SERVER_NAME;
|
||||||
|
connInfo.userdata=NULL;
|
||||||
|
connInfo.protocol = protocols[0].name;
|
||||||
|
connInfo.ietf_version_or_minus_one=13;
|
||||||
|
connInfo.origin = LWS_SERVER_NAME;
|
||||||
|
now_state = SET_UP_SESSION;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lws_debug("illegal context\r\n");
|
||||||
|
now_state = EXIT_SESSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lws_debug("wifi offline\r\n");
|
||||||
|
tls_os_time_delay(HZ*5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SET_UP_SESSION:
|
||||||
|
{
|
||||||
|
g_wsContext=lws_client_connect_via_info( &connInfo );
|
||||||
|
if(g_wsContext==NULL ){
|
||||||
|
lws_debug("lws_client_connect_via_info fail\r\n\r\n");
|
||||||
|
now_state = EXIT_SESSION;
|
||||||
|
tls_os_time_delay(HZ*5);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
now_state = HANDLE_SESSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HANDLE_SESSION:
|
||||||
|
{
|
||||||
|
nowTick = tls_os_get_time();
|
||||||
|
if(nowTick - oldTick > HZ) {
|
||||||
|
if(isNetworkOk()) {
|
||||||
|
lws_callback_on_writable(g_wsContext);
|
||||||
|
(watchDog > 5)?(now_state = EXIT_SESSION):(watchDog ++);
|
||||||
|
oldTick = nowTick;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
now_state = EXIT_SESSION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lws_service(lwscontext, 250);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EXIT_SESSION:
|
||||||
|
{
|
||||||
|
lws_debug("EXIT_SESSION\n");
|
||||||
|
if( lwscontext != NULL ) {
|
||||||
|
lws_context_destroy(lwscontext);
|
||||||
|
}
|
||||||
|
lwscontext = NULL;
|
||||||
|
g_wsContext = NULL;
|
||||||
|
watchDog = 0;
|
||||||
|
tls_os_time_delay(HZ*5);
|
||||||
|
now_state = INIT_SESSION;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void lwsSendTask( void* lparam )
|
||||||
|
{
|
||||||
|
char dbgStr[128] = {0};
|
||||||
|
u16 len = 0, cnt = 0;
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
sprintf(dbgStr, "{\"msg_type\":\"keepalive\"} %d", cnt++);
|
||||||
|
len = strlen(dbgStr);
|
||||||
|
dbgStr[len] = '\0';
|
||||||
|
demoLwsSend( dbgStr, len );
|
||||||
|
tls_os_time_delay(2*HZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int demoWebsocketTaskCreate( void *recvFunc)
|
||||||
|
{
|
||||||
|
receive_data_notify = (Communication_ReceiveData)recvFunc;
|
||||||
|
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
lwsRecvTask,
|
||||||
|
(void *)NULL,
|
||||||
|
(void *)DemoLwsRecvStk,
|
||||||
|
DEMO_LWS_RECV_TASK_SIZE * sizeof(u32),
|
||||||
|
DEMO_SSL_SERVER_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
|
||||||
|
tls_os_task_create(NULL, NULL,
|
||||||
|
lwsSendTask,
|
||||||
|
(void *)NULL,
|
||||||
|
(void *)DemoLwsSendStk,
|
||||||
|
DEMO_LWS_SEND_TASK_SIZE * sizeof(u32),
|
||||||
|
DEMO_SSL_SERVER_TASK_PRIO,
|
||||||
|
0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setAutoConnectMode(void)
|
||||||
|
{
|
||||||
|
u8 auto_reconnect = 0xff;
|
||||||
|
|
||||||
|
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_GET, &auto_reconnect);
|
||||||
|
if(auto_reconnect != WIFI_AUTO_CNT_ON)
|
||||||
|
{
|
||||||
|
auto_reconnect = WIFI_AUTO_CNT_ON;
|
||||||
|
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_SET, &auto_reconnect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int lwsDemoTest(void)
|
||||||
|
{
|
||||||
|
setAutoConnectMode();
|
||||||
|
demoWebsocketTaskCreate(dataReceived);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
103
demo/wm_wps_demo.c
Normal file
103
demo/wm_wps_demo.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_mcast_demo.c
|
||||||
|
*
|
||||||
|
* Description: mcast demo function
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author : wanghaifang
|
||||||
|
*
|
||||||
|
* Date : 2014-6-2
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
|
||||||
|
#if DEMO_WPS
|
||||||
|
static void demo_wps_netif_stataus_callbak(u8 status)
|
||||||
|
{
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case NETIF_WIFI_JOIN_SUCCESS:
|
||||||
|
printf("WiFi JOIN SUCCESS\r\n");
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_JOIN_FAILED:
|
||||||
|
printf("WiFi JOIN FAILED:%d\r\n", tls_wifi_get_errno());
|
||||||
|
break;
|
||||||
|
case NETIF_WIFI_DISCONNECTED:
|
||||||
|
printf("WiFi DISCONNECT\r\n");
|
||||||
|
break;
|
||||||
|
case NETIF_IP_NET_UP:
|
||||||
|
{
|
||||||
|
struct tls_ethif *ethif;
|
||||||
|
ethif = tls_netif_get_ethif();
|
||||||
|
printf("NET UP OK,Local IP:%d.%d.%d.%d\r\n", ip4_addr1(ip_2_ip4(ðif->ip_addr)), ip4_addr2(ip_2_ip4(ðif->ip_addr)),
|
||||||
|
ip4_addr3(ip_2_ip4(ðif->ip_addr)), ip4_addr4(ip_2_ip4(ðif->ip_addr)));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Not Expected Value:%d\r\n", status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_wps_pbc(char *buf)
|
||||||
|
{
|
||||||
|
struct tls_param_ip ip_param;
|
||||||
|
int ret = WM_FAILED;
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
|
||||||
|
ip_param.dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, &ip_param, FALSE);
|
||||||
|
|
||||||
|
#if TLS_CONFIG_WPS
|
||||||
|
tls_wifi_set_oneshot_flag(0);
|
||||||
|
tls_netif_add_status_event(demo_wps_netif_stataus_callbak);/*register net status event*/
|
||||||
|
ret = tls_wps_start_pbc();
|
||||||
|
#endif
|
||||||
|
if(ret == WM_SUCCESS)
|
||||||
|
printf("Start WPS pbc mode ... \n");
|
||||||
|
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int demo_wps_pin(char *buf)
|
||||||
|
{
|
||||||
|
int ret = WM_FAILED;
|
||||||
|
struct tls_param_ip ip_param;
|
||||||
|
|
||||||
|
tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
|
||||||
|
ip_param.dhcp_enable = TRUE;
|
||||||
|
tls_param_set(TLS_PARAM_ID_IP, &ip_param, FALSE);
|
||||||
|
|
||||||
|
#if TLS_CONFIG_WPS
|
||||||
|
tls_wifi_set_oneshot_flag(0);
|
||||||
|
tls_netif_add_status_event(demo_wps_netif_stataus_callbak);/*register net status event*/
|
||||||
|
ret = tls_wps_start_pin();
|
||||||
|
#endif
|
||||||
|
if(ret == WM_SUCCESS)
|
||||||
|
printf("Start WPS pin mode ... \n");
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int demo_wps_get_pin(char *buf)
|
||||||
|
{
|
||||||
|
#if TLS_CONFIG_WPS
|
||||||
|
u8 pin[WPS_PIN_LEN + 1];
|
||||||
|
|
||||||
|
if(!tls_wps_get_pin(pin))
|
||||||
|
printf("Pin code: %s\n", pin);
|
||||||
|
|
||||||
|
if(!tls_wps_set_pin(pin, WPS_PIN_LEN))
|
||||||
|
printf("Pin set correctly: %s\n", pin);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return WM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@ -1,6 +1,48 @@
|
|||||||
==========================================================
|
==========================================================
|
||||||
| CHANGELOG: WinnerMicro Software Development Kit |
|
| CHANGELOG: WinnerMicro Software Development Kit |
|
||||||
==========================================================
|
==========================================================
|
||||||
|
W800 SDK v1.00.10 | 2022/12/29
|
||||||
|
==========================
|
||||||
|
1. 驱动更新
|
||||||
|
1)提供模组ADC校准功能接口
|
||||||
|
2)修复PSRAM IO复用不完整问题
|
||||||
|
3)Flash驱动修改不再每次都写状态寄存器
|
||||||
|
4)增加RF参数备份机制
|
||||||
|
5)修改对于SD 1.0卡的支持
|
||||||
|
|
||||||
|
2. 更新secboot,支持青藤Flash的QIO模式切换;优化每次启动过程都操作flash状态寄存器来切QIO模式的操作
|
||||||
|
|
||||||
|
3. 升级LWIP版本至V2.1.3版本
|
||||||
|
4. 优化一键配网功能
|
||||||
|
5. demo修改:
|
||||||
|
1)HSPI和SDIO的从设备的DEMO更新,通过参数区分HSPI和SDIO的初始化
|
||||||
|
2)修改demo的控制台的接收处理,解决接收命令字不足后无法使用控制台的问题
|
||||||
|
3)增加新的联网demo
|
||||||
|
4)增加新的扫描demo
|
||||||
|
5)增加softap的黑名单功能demo
|
||||||
|
6. 修复芯片Sleep模式功耗波动问题,修改GPIO默认配置为输入上拉;客户使用时按照IO复用配置,使用指定的上下拉功能
|
||||||
|
7. RTOS问题修复
|
||||||
|
1)修复rtos适配函数没有判断指针是否为空的操作
|
||||||
|
2)修复RTOS任务创建时句柄赋值处理
|
||||||
|
8. 修复因调整tick值并进行时间计算而导致的可能除0操作
|
||||||
|
|
||||||
|
9. Wi-Fi库更新内容:
|
||||||
|
1)增加WLAN数字增益可调接口
|
||||||
|
2)增加连接扫描不到热点的时间可控的API
|
||||||
|
3)增加可配置是否可连接open/wep网络的API
|
||||||
|
4)增加是否扫描到立即连接AP的API
|
||||||
|
5)支持AP的黑名单功能
|
||||||
|
6)修复APSTA模式下某些手机连接不上的问题(因信道变更时信标帧内部分信道相关信息未更新)
|
||||||
|
|
||||||
|
10. 编译相关
|
||||||
|
1)修复某些场景下的编译报错问题(例如:内存调试打开,mbedtls模块编译报错的问题)
|
||||||
|
2)修改编译工具链,支持CPP代码的编译
|
||||||
|
3)因为升级了LWIP和MQTT,CDK的编译工程变更,建议使用新的工程,把之前改动合过来;
|
||||||
|
如果确实要使用之前的工程,需要把相关文件加入,编译前要清理一下编译工程下的过程中文件(.mk,.bat,.txt,LST和OBJ)
|
||||||
|
4)如果用户打开较多demo、或者进行内存调试,或者打开wm_debug.h调试功能,而且要使用经典蓝牙的CDK工程编译
|
||||||
|
或者使用make编译,需要对链接文件里的I-SRAM进行调整(位置、大小)由此带来一系列的调整(编译固件存放的位置也要调整)
|
||||||
|
5)清理编译告警
|
||||||
|
|
||||||
W800 SDK v1.00.08 | 2022/07/26
|
W800 SDK v1.00.08 | 2022/07/26
|
||||||
==========================
|
==========================
|
||||||
*********
|
*********
|
||||||
|
|||||||
Binary file not shown.
@ -10,6 +10,6 @@
|
|||||||
#ifndef WM_NETIF_H
|
#ifndef WM_NETIF_H
|
||||||
#define WM_NETIF_H
|
#define WM_NETIF_H
|
||||||
#include "wm_config.h"
|
#include "wm_config.h"
|
||||||
#include "wm_netif2.0.3.h"
|
#include "wm_netif2.1.3.h"
|
||||||
#endif /* WM_NETIF_H */
|
#endif /* WM_NETIF_H */
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* @file wm_netif2.0.3.h
|
* @file wm_netif2.1.3.h
|
||||||
*
|
*
|
||||||
* @brief netif203 module
|
* @brief netif213 module
|
||||||
*
|
*
|
||||||
* @author dave
|
* @author WinnerMicro
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
||||||
*/
|
*/
|
||||||
@ -37,6 +37,8 @@ extern int tls_filter_module_srcmac(u8 *mac);
|
|||||||
|
|
||||||
/** WinnerMicro ONSHOT */
|
/** WinnerMicro ONSHOT */
|
||||||
#define TLS_CONFIG_UDP_LSD_SPECIAL (ONESHOT_ON&& TLS_CONFIG_UDP_ONE_SHOT)
|
#define TLS_CONFIG_UDP_LSD_SPECIAL (ONESHOT_ON&& TLS_CONFIG_UDP_ONE_SHOT)
|
||||||
|
/** Delay start plcp receive*/
|
||||||
|
#define TLS_CONFIG_ONESHOT_DELAY_SPECIAL ONESHOT_ON
|
||||||
|
|
||||||
/** AP ONESHOT */
|
/** AP ONESHOT */
|
||||||
#define TLS_CONFIG_AP_MODE_ONESHOT (ONESHOT_ON && TLS_CONFIG_AP)
|
#define TLS_CONFIG_AP_MODE_ONESHOT (ONESHOT_ON && TLS_CONFIG_AP)
|
||||||
@ -45,7 +47,7 @@ extern int tls_filter_module_srcmac(u8 *mac);
|
|||||||
|
|
||||||
|
|
||||||
/** AIRKISS ONESHOT */
|
/** AIRKISS ONESHOT */
|
||||||
#define TLS_CONFIG_AIRKISS_MODE_ONESHOT (ONESHOT_OFF && TLS_CONFIG_UDP_ONE_SHOT)
|
#define TLS_CONFIG_AIRKISS_MODE_ONESHOT (ONESHOT_ON && TLS_CONFIG_UDP_ONE_SHOT)
|
||||||
#define AIRKISS_USE_SELF_WRITE 1
|
#define AIRKISS_USE_SELF_WRITE 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -294,6 +294,41 @@ u32 adc_get_interVolt(void);
|
|||||||
*/
|
*/
|
||||||
int adc_temp(void);
|
int adc_temp(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to calibrate adc single-end voltage. offset after FT or multipoint calibration.
|
||||||
|
*
|
||||||
|
* @param[in] chan: adc calibration channel to be used, ADC channel 0,1,2,3
|
||||||
|
* @param[in] refvoltage: calibration reference voltage to be used, unit:mV
|
||||||
|
* input range[100,2300)mV, suggest reference voltage[500,2000]mV
|
||||||
|
*
|
||||||
|
* @return 0: success, < 0: failure
|
||||||
|
*
|
||||||
|
* @note After FT calibration or mulitpoint calibration, adc curve is y=ax+b,
|
||||||
|
* y is real voltage(unit:mV), x is adc sample data
|
||||||
|
* a and b is the coefficient. This fuction only used to revise b value.
|
||||||
|
*/
|
||||||
|
int adc_offset_calibration(int chan, int refvoltage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function can used to calibrate adc coefficient if not calibrated,
|
||||||
|
* or adc offset after FT or multipoint calibration.
|
||||||
|
*
|
||||||
|
* @param[in] chanused: bitmap, specified calibration channel,only bit0-3 can be used
|
||||||
|
* @param[in] refvoltage[]: array, calibration reference voltage to be used, unit:mV
|
||||||
|
* refvoltage keep the same position with chan bitmap
|
||||||
|
* input range[100,2300)mV, suggest reference voltage[500,2000]mV
|
||||||
|
*
|
||||||
|
* @return 0: success, < 0: failure
|
||||||
|
*
|
||||||
|
* @note 1)Adc curve is y=ax+b,y is real voltage(unit:mV), x is adc sample data.
|
||||||
|
* After calibration, we can get a and b, or only update b.
|
||||||
|
* 2) Only used single-end adc
|
||||||
|
* 3) For example, use chan 0,1,3, and refvoltage 500,1000,2000,
|
||||||
|
* then chanused is 0xB, refvoltage[] value is {500,1000,0, 2000};
|
||||||
|
*/
|
||||||
|
int adc_multipoint_calibration(int chanused, int refvoltage[]);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@ -311,6 +346,9 @@ void signedToUnsignedData(int *adcValue);
|
|||||||
void tls_adc_buffer_bypass_set(u8 isset);
|
void tls_adc_buffer_bypass_set(u8 isset);
|
||||||
void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol);
|
void tls_adc_cmp_start(int Channel, int cmp_data, int cmp_pol);
|
||||||
u32 adc_get_offset(void);
|
u32 adc_get_offset(void);
|
||||||
|
void tls_adc_set_pga(int gain1, int gain2);
|
||||||
|
int cal_voltage(double vol);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,8 @@ enum {
|
|||||||
CMD_RX_IQ_PHASE,
|
CMD_RX_IQ_PHASE,
|
||||||
CMD_TX_GAIN,
|
CMD_TX_GAIN,
|
||||||
CMD_TX_ADC_CAL,
|
CMD_TX_ADC_CAL,
|
||||||
|
CMD_FREQ_ERR,
|
||||||
|
CMD_RF_CAL_FLAG,
|
||||||
CMD_ALL,
|
CMD_ALL,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,7 +47,9 @@ typedef struct FT_ADC_CAL_UNIT
|
|||||||
typedef struct FT_ADC_CAL
|
typedef struct FT_ADC_CAL
|
||||||
{
|
{
|
||||||
unsigned int valid_cnt;
|
unsigned int valid_cnt;
|
||||||
FT_ADC_CAL_UINT_ST units[8];
|
FT_ADC_CAL_UINT_ST units[6];
|
||||||
|
float a;
|
||||||
|
float b;
|
||||||
}FT_ADC_CAL_ST;
|
}FT_ADC_CAL_ST;
|
||||||
|
|
||||||
typedef struct FT_TEMP_CAL
|
typedef struct FT_TEMP_CAL
|
||||||
@ -303,6 +307,18 @@ int tls_rf_cal_finish_op(u8 *calflag, u8 flag);
|
|||||||
*/
|
*/
|
||||||
int tls_get_adc_cal_param(FT_ADC_CAL_ST *adc_cal);
|
int tls_get_adc_cal_param(FT_ADC_CAL_ST *adc_cal);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set adc cal param
|
||||||
|
*
|
||||||
|
* @param[out] adc_cal adc cal param
|
||||||
|
*
|
||||||
|
* @retval TLS_EFUSE_STATUS_OK get success
|
||||||
|
* @retval TLS_EFUSE_STATUS_EIO get failed
|
||||||
|
*/
|
||||||
|
int tls_set_adc_cal_param(FT_ADC_CAL_ST *adc_cal);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -42,7 +42,7 @@ enum TYPE_FLASH_ID{
|
|||||||
SPIFLASH_MID_XMC = 0x20,
|
SPIFLASH_MID_XMC = 0x20,
|
||||||
SPIFLASH_MID_XTX = 0x0B,
|
SPIFLASH_MID_XTX = 0x0B,
|
||||||
SPIFLASH_MID_TSINGTENG = 0xEB, /*UNIGROUP TSINGTENG*/
|
SPIFLASH_MID_TSINGTENG = 0xEB, /*UNIGROUP TSINGTENG*/
|
||||||
SPIFLASH_MID_TSINGTENG_1MB = 0xCD, /*UNIGROUP TSINGTENG*/
|
SPIFLASH_MID_TSINGTENG_1MB_4MB = 0xCD, /*UNIGROUP TSINGTENG*/
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ typedef struct
|
|||||||
long long CardCapacity;
|
long long CardCapacity;
|
||||||
u32 CardBlockSize;
|
u32 CardBlockSize;
|
||||||
u16 RCA;
|
u16 RCA;
|
||||||
u8 CardType;
|
u8 CSDVer;
|
||||||
} SD_CardInfo_t;
|
} SD_CardInfo_t;
|
||||||
extern SD_CardInfo_t SDCardInfo;
|
extern SD_CardInfo_t SDCardInfo;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
#ifndef WM_SOCKET_H
|
#ifndef WM_SOCKET_H
|
||||||
#define WM_SOCKET_H
|
#define WM_SOCKET_H
|
||||||
#include "wm_config.h"
|
#include "wm_config.h"
|
||||||
#include "wm_socket2.0.3.h"
|
#include "wm_socket2.1.3.h"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,17 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
* @file wm_socket2.0.3.h
|
* @file wm_socket2.1.3.h
|
||||||
*
|
*
|
||||||
* @brief socket203 Module
|
* @brief socket2.1.3 apis
|
||||||
*
|
*
|
||||||
* @author dave
|
* @author winnermicro
|
||||||
*
|
*
|
||||||
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
||||||
*/
|
*/
|
||||||
#ifndef WM_SOCKET2_0_3_H
|
#ifndef WM_SOCKET2_1_3_H
|
||||||
#define WM_SOCKET2_0_3_H
|
#define WM_SOCKET2_1_3_H
|
||||||
|
|
||||||
#include "wm_type_def.h"
|
#include "wm_type_def.h"
|
||||||
#include "wm_netif.h"
|
#include "wm_netif.h"
|
||||||
|
#include "lwip/err.h"
|
||||||
|
#include "lwip/pbuf.h"
|
||||||
|
|
||||||
|
|
||||||
//socket state defination
|
//socket state defination
|
||||||
#define NETCONN_STATE_NONE 0
|
#define NETCONN_STATE_NONE 0
|
||||||
@ -30,40 +33,6 @@
|
|||||||
#define TLS_MAX_SOCKET_NUM 4
|
#define TLS_MAX_SOCKET_NUM 4
|
||||||
#define TLS_MAX_NETCONN_NUM 20
|
#define TLS_MAX_NETCONN_NUM 20
|
||||||
|
|
||||||
/** Main packet buffer struct */
|
|
||||||
struct pbuf {
|
|
||||||
/** next pbuf in singly linked pbuf chain */
|
|
||||||
struct pbuf *next;
|
|
||||||
|
|
||||||
/** pointer to the actual data in the buffer */
|
|
||||||
void *payload;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* total length of this buffer and all next buffers in chain
|
|
||||||
* belonging to the same packet.
|
|
||||||
*
|
|
||||||
* For non-queue packet chains this is the invariant:
|
|
||||||
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
|
|
||||||
*/
|
|
||||||
u16_t tot_len;
|
|
||||||
|
|
||||||
/** length of this buffer */
|
|
||||||
u16_t len;
|
|
||||||
|
|
||||||
/** pbuf_type as u8_t instead of enum to save space */
|
|
||||||
u8_t /*pbuf_type*/ type;
|
|
||||||
|
|
||||||
/** misc flags */
|
|
||||||
u8_t flags;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the reference count always equals the number of pointers
|
|
||||||
* that refer to this pbuf. This can be pointers from an application,
|
|
||||||
* the stack itself, or pbuf->next pointers from a chain.
|
|
||||||
*/
|
|
||||||
u16_t ref;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This Function prototype for tcp error callback functions. Called when
|
* @brief This Function prototype for tcp error callback functions. Called when
|
||||||
* receives a RST or is unexpectedly closed for any other reason.
|
* receives a RST or is unexpectedly closed for any other reason.
|
||||||
@ -169,45 +138,6 @@ typedef err_t (*socket_accept_fn)(u8 skt_num, err_t err);
|
|||||||
*/
|
*/
|
||||||
typedef void(*socket_state_changed_fn)(u8 skt_num, u8 event, u8 state);
|
typedef void(*socket_state_changed_fn)(u8 skt_num, u8 event, u8 state);
|
||||||
|
|
||||||
/** Definitions for error constants. */
|
|
||||||
typedef enum {
|
|
||||||
/** No error, everything OK. */
|
|
||||||
ERR_OK = 0,
|
|
||||||
/** Out of memory error. */
|
|
||||||
ERR_MEM = -1,
|
|
||||||
/** Buffer error. */
|
|
||||||
ERR_BUF = -2,
|
|
||||||
/** Timeout. */
|
|
||||||
ERR_TIMEOUT = -3,
|
|
||||||
/** Routing problem. */
|
|
||||||
ERR_RTE = -4,
|
|
||||||
/** Operation in progress */
|
|
||||||
ERR_INPROGRESS = -5,
|
|
||||||
/** Illegal value. */
|
|
||||||
ERR_VAL = -6,
|
|
||||||
/** Operation would block. */
|
|
||||||
ERR_WOULDBLOCK = -7,
|
|
||||||
/** Address in use. */
|
|
||||||
ERR_USE = -8,
|
|
||||||
/** Already connecting. */
|
|
||||||
ERR_ALREADY = -9,
|
|
||||||
/** Conn already established.*/
|
|
||||||
ERR_ISCONN = -10,
|
|
||||||
/** Not connected. */
|
|
||||||
ERR_CONN = -11,
|
|
||||||
/** Low-level netif error */
|
|
||||||
ERR_IF = -12,
|
|
||||||
|
|
||||||
/** Connection aborted. */
|
|
||||||
ERR_ABRT = -13,
|
|
||||||
/** Connection reset. */
|
|
||||||
ERR_RST = -14,
|
|
||||||
/** Connection closed. */
|
|
||||||
ERR_CLSD = -15,
|
|
||||||
/** Illegal argument. */
|
|
||||||
ERR_ARG = -16
|
|
||||||
} err_enum_t;
|
|
||||||
|
|
||||||
enum tls_socket_protocol{
|
enum tls_socket_protocol{
|
||||||
SOCKET_PROTO_TCP, /* TCP Protocol */
|
SOCKET_PROTO_TCP, /* TCP Protocol */
|
||||||
SOCKET_PROTO_UDP, /* UDP Protocol */
|
SOCKET_PROTO_UDP, /* UDP Protocol */
|
||||||
@ -317,106 +247,5 @@ int tls_socket_get_status(u8 skt_num, u8 *buf, u32 bufsize);
|
|||||||
*/
|
*/
|
||||||
int tls_socket_udp_sendto(u16 localport, u8 *ip_addr, u16 port, void *pdata, u16 len);
|
int tls_socket_udp_sendto(u16 localport, u8 *ip_addr, u16 port, void *pdata, u16 len);
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup pbuf
|
|
||||||
* Enumeration of pbuf layers
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
/** Includes spare room for transport layer header, e.g. UDP header.
|
|
||||||
* Use this if you intend to pass the pbuf to functions like udp_send().
|
|
||||||
*/
|
|
||||||
PBUF_TRANSPORT,
|
|
||||||
/** Includes spare room for IP header.
|
|
||||||
* Use this if you intend to pass the pbuf to functions like raw_send().
|
|
||||||
*/
|
|
||||||
PBUF_IP,
|
|
||||||
/** Includes spare room for link layer header (ethernet header).
|
|
||||||
* Use this if you intend to pass the pbuf to functions like ethernet_output().
|
|
||||||
* @see PBUF_LINK_HLEN
|
|
||||||
*/
|
|
||||||
PBUF_LINK,
|
|
||||||
/** Includes spare room for additional encapsulation header before ethernet
|
|
||||||
* headers (e.g. 802.11).
|
|
||||||
* Use this if you intend to pass the pbuf to functions like netif->linkoutput().
|
|
||||||
* @see PBUF_LINK_ENCAPSULATION_HLEN
|
|
||||||
*/
|
|
||||||
PBUF_RAW_TX,
|
|
||||||
/** Use this for input packets in a netif driver when calling netif->input()
|
|
||||||
* in the most common case - ethernet-layer netif driver. */
|
|
||||||
PBUF_RAW
|
|
||||||
} pbuf_layer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup pbuf
|
|
||||||
* Enumeration of pbuf types
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
/** pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload
|
|
||||||
are allocated in one piece of contiguous memory (so the first payload byte
|
|
||||||
can be calculated from struct pbuf).
|
|
||||||
pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might
|
|
||||||
change in future versions).
|
|
||||||
This should be used for all OUTGOING packets (TX).*/
|
|
||||||
PBUF_RAM,
|
|
||||||
/** pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in
|
|
||||||
totally different memory areas. Since it points to ROM, payload does not
|
|
||||||
have to be copied when queued for transmission. */
|
|
||||||
PBUF_ROM,
|
|
||||||
/** pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change
|
|
||||||
so it has to be duplicated when queued before transmitting, depending on
|
|
||||||
who has a 'ref' to it. */
|
|
||||||
PBUF_REF,
|
|
||||||
/** pbuf payload refers to RAM. This one comes from a pool and should be used
|
|
||||||
for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct
|
|
||||||
pbuf and its payload are allocated in one piece of contiguous memory (so
|
|
||||||
the first payload byte can be calculated from struct pbuf).
|
|
||||||
Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing,
|
|
||||||
you are unable to receive TCP acks! */
|
|
||||||
PBUF_POOL
|
|
||||||
} pbuf_type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This Function allocates a pbuf of the given type (possibly a chain for PBUF_POOL type).
|
|
||||||
*
|
|
||||||
* The actual memory allocated for the pbuf is determined by the
|
|
||||||
* layer at which the pbuf is allocated and the requested size
|
|
||||||
* (from the size parameter).
|
|
||||||
*
|
|
||||||
* @param[in] l layer flag to define header size
|
|
||||||
* @param[in] length size of the pbuf's payload
|
|
||||||
* @param[in] type this parameter decides how and where the pbuf
|
|
||||||
*
|
|
||||||
* @retval The allocated pbuf. If multiple pbufs where allocated, this
|
|
||||||
* is the first pbuf of a pbuf chain.
|
|
||||||
*/
|
|
||||||
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This Function for release the buffer that you receive within the socket_recv_fn callback function.
|
|
||||||
* Attention please: If you return ERR_OK in the socket_recv_fn callback function, you must call this
|
|
||||||
* function to release the buffer by yourself. Otherwise, the buffer do not need be
|
|
||||||
* released by your code.
|
|
||||||
*
|
|
||||||
* @param[in] p The buffer you received in the socket_recv_fn callback function.
|
|
||||||
*
|
|
||||||
* @retval The number of de-allocated pbufs
|
|
||||||
*/
|
|
||||||
u8 pbuf_free(struct pbuf *p);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This Function for copy (part of) the contents of a packet buffer to an application supplied buffer.
|
|
||||||
*
|
|
||||||
* @param[in] p the pbuf from which to copy data.
|
|
||||||
*
|
|
||||||
* @param[in] dataptr the application supplied buffer
|
|
||||||
*
|
|
||||||
* @param[in] len length of data to copy (dataptr must be big enough). No more
|
|
||||||
* than buf->tot_len will be copied, irrespective of len
|
|
||||||
*
|
|
||||||
* @param[in] offset offset into the packet buffer from where to begin copying len bytes
|
|
||||||
*
|
|
||||||
* @retval The number of bytes copied, or 0 on failure
|
|
||||||
*/
|
|
||||||
u16_t pbuf_copy_partial(const struct pbuf *p, void *dataptr, u16_t len, u16_t offset);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -10,6 +10,6 @@
|
|||||||
#ifndef WM_SOCKET_API_H
|
#ifndef WM_SOCKET_API_H
|
||||||
#define WM_SOCKET_API_H
|
#define WM_SOCKET_API_H
|
||||||
#include "wm_config.h"
|
#include "wm_config.h"
|
||||||
#include "wm_sockets2.0.3.h"
|
#include "wm_sockets2.1.3.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
26
include/net/wm_sockets2.1.3.h
Normal file
26
include/net/wm_sockets2.1.3.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* @file wm_sockets2.1.3.h
|
||||||
|
*
|
||||||
|
* @brief sockets2.1.3 apis
|
||||||
|
*
|
||||||
|
* @author winnermicro
|
||||||
|
*
|
||||||
|
* @copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
||||||
|
*/
|
||||||
|
#ifndef WM_SOCKET_API2_1_3_H
|
||||||
|
#define WM_SOCKET_API2_1_3_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "wm_type_def.h"
|
||||||
|
#include "wm_config.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "lwip/ip_addr.h"
|
||||||
|
#include "lwip/sockets.h"
|
||||||
|
#include "lwip/netdb.h"
|
||||||
|
|
||||||
|
extern void print_ipaddr(ip_addr_t *ip);
|
||||||
|
extern struct netif *wm_ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@ -24,7 +24,7 @@
|
|||||||
//#define WM_MEM_DEBUG 1
|
//#define WM_MEM_DEBUG 1
|
||||||
#if WM_MEM_DEBUG
|
#if WM_MEM_DEBUG
|
||||||
|
|
||||||
#include "list.h"
|
#include "../list.h"
|
||||||
|
|
||||||
#define MEM_HEADER_PATTERN 0x76028412
|
#define MEM_HEADER_PATTERN 0x76028412
|
||||||
#define MEM_TAILER_PATTERN 0x83395627
|
#define MEM_TAILER_PATTERN 0x83395627
|
||||||
|
|||||||
@ -113,6 +113,28 @@ enum tls_wifi_auth_mode {
|
|||||||
WM_WIFI_AUTH_MODE_UNKNOWN = 128
|
WM_WIFI_AUTH_MODE_UNKNOWN = 128
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Wi-Fi encryption enum */
|
||||||
|
enum tls_wifi_encrypt_mode {
|
||||||
|
WM_WIFI_ECN_MODE_OPEN = 0, /**< encrypt mode : open */
|
||||||
|
WM_WIFI_ECN_MODE_WEP = 1, /**< encrypt mode : wep*/
|
||||||
|
WM_WIFI_ECN_MODE_WPA_PSK = 2, /**< encrypt mode : wpa psk*/
|
||||||
|
WM_WIFI_ECN_MODE_WPA2_PSK = 3, /**< encrypt mode : wpa2 psk*/
|
||||||
|
WM_WIFI_ECN_MODE_WPA_WPA2_PSK = 4, /**< encrypt mode : wpa and wpa2 psk*/
|
||||||
|
WM_WIFI_ECN_MODE_UNKNOWN = 5, /**< encrypt mode : unknown*/
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Wi-Fi group/pairwise cipher enumu*/
|
||||||
|
enum tls_wifi_cipher_mode{
|
||||||
|
WM_WIFI_CIPHER_NONE = 0,
|
||||||
|
WM_WIFI_CIPHER_WEP40 = 1,
|
||||||
|
WM_WIFI_CIPHER_WEP104 = 2,
|
||||||
|
WM_WIFI_CIPHER_TKIP = 3,
|
||||||
|
WM_WIFI_CIPHER_CCMP = 4,
|
||||||
|
WM_WIFI_CIPHER_TKIP_AND_CCMP = 5,
|
||||||
|
WM_WIFI_CIPHER_AES_CMAC_128 = 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Wi-Fi states */
|
/** Wi-Fi states */
|
||||||
enum tls_wifi_states {
|
enum tls_wifi_states {
|
||||||
WM_WIFI_DISCONNECTED, /**< Disconnected state */
|
WM_WIFI_DISCONNECTED, /**< Disconnected state */
|
||||||
@ -270,6 +292,29 @@ struct tls_scan_bss_t {
|
|||||||
struct tls_bss_info_t bss[1]; /**< list of bss found*/
|
struct tls_bss_info_t bss[1]; /**< list of bss found*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** format2 bss information */
|
||||||
|
struct tls_bss_info_format2_t {
|
||||||
|
u8 ecn; /**< encryption type, @ref enum tls_wifi_encrypt_mode */
|
||||||
|
u8 rssi; /**< signal strength of AP, real rssi = (signed char)rssi */
|
||||||
|
u8 ssid[32]; /**< SSID of AP */
|
||||||
|
u8 ssid_len; /**< SSID length */
|
||||||
|
u8 bssid[ETH_ALEN]; /**< MAC address of AP */
|
||||||
|
u8 channel; /**< channel of AP */
|
||||||
|
s16 freq_offset; /**< reserved do not support*/
|
||||||
|
s16 freqcal_val; /**< reserved do not support*/
|
||||||
|
s8 pairwise_cipher; /**< pairwise cipher. @ref enum tls_wifi_cipher_mode */
|
||||||
|
s8 group_cipher; /**< group cipher. @ref enum tls_wifi_cipher_mode */
|
||||||
|
u8 bgn; /**< bgnmode, bit0:b mode, bit1:g mode, bit2:n mode */
|
||||||
|
bool wps_support; /**< is support WPS function */
|
||||||
|
};
|
||||||
|
|
||||||
|
/** format2 scan result */
|
||||||
|
struct tls_scan_bss_format2_t {
|
||||||
|
u32 count; /**< total count */
|
||||||
|
u32 length; /**< bss info total length */
|
||||||
|
struct tls_bss_info_format2_t bss[1]; /**< list of bss found*/
|
||||||
|
};
|
||||||
|
|
||||||
/** station information */
|
/** station information */
|
||||||
struct tls_sta_info_t {
|
struct tls_sta_info_t {
|
||||||
u8 mac_addr[ETH_ALEN]; /**< MAC address of station */
|
u8 mac_addr[ETH_ALEN]; /**< MAC address of station */
|
||||||
@ -299,7 +344,8 @@ struct tls_wifi_tx_rate_t {
|
|||||||
|
|
||||||
/** scan param */
|
/** scan param */
|
||||||
struct tls_wifi_scan_param_t{
|
struct tls_wifi_scan_param_t{
|
||||||
u32 scan_times; /**< Scan times, >=0, if zero, only 1 times */
|
u16 scan_type;
|
||||||
|
u16 scan_times; /**< Scan times, >=0, if zero, only 1 times */
|
||||||
u16 scan_chanlist; /**< Scan channel list ,[0,3FFF],per bit is one channel,if zero or above 0x3FFF, scan all channel*/
|
u16 scan_chanlist; /**< Scan channel list ,[0,3FFF],per bit is one channel,if zero or above 0x3FFF, scan all channel*/
|
||||||
u16 scan_chinterval; /**< Scan channel switch time,>=0, if zero, use default value, unit:ms */
|
u16 scan_chinterval; /**< Scan channel switch time,>=0, if zero, use default value, unit:ms */
|
||||||
};
|
};
|
||||||
@ -632,6 +678,24 @@ void tls_wifi_scan_result_cb_register(void (*callback)(void));
|
|||||||
int tls_wifi_get_scan_rslt(u8* buf, u32 buffer_size);
|
int tls_wifi_get_scan_rslt(u8* buf, u32 buffer_size);
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
* Function: tls_wifi_get_scan_rslt_format2
|
||||||
|
*
|
||||||
|
* Description: get result of last scan for format2 result
|
||||||
|
*
|
||||||
|
* Input: buffer: address to store returned BSS info
|
||||||
|
* buffer_size: the length of the buffer
|
||||||
|
* Output: BSS info got by last scan
|
||||||
|
*
|
||||||
|
* Return: WM_SUCCESS: return ok;
|
||||||
|
* WM_FAILED: failed to get result;
|
||||||
|
* Note: user need to memalloc a buffer in advance. size for one item of scan result is @ref struct tls_bss_info_format2_t
|
||||||
|
* the buffer size depends how many items user wants.
|
||||||
|
* Date : 2022-6-07
|
||||||
|
****************************************************************************/
|
||||||
|
int tls_wifi_get_scan_rslt_format2(u8* buf, u32 buffer_size);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is used to create soft ap
|
* @brief This function is used to create soft ap
|
||||||
*
|
*
|
||||||
@ -1014,20 +1078,6 @@ int tls_wifi_send_mgmt(enum tls_wifi_mgmt_type type, struct tls_wifi_hdr_mac_t *
|
|||||||
*/
|
*/
|
||||||
int tls_wifi_send_data(struct tls_wifi_hdr_mac_t *mac, u8 *data, u16 data_len, struct tls_wifi_tx_rate_t *tx);
|
int tls_wifi_send_data(struct tls_wifi_hdr_mac_t *mac, u8 *data, u16 data_len, struct tls_wifi_tx_rate_t *tx);
|
||||||
|
|
||||||
#if TLS_CONFIG_AP
|
|
||||||
/**
|
|
||||||
* @brief This function is used to get authed sta list
|
|
||||||
*
|
|
||||||
* @param[out] *sta_num authed's station number
|
|
||||||
* @param[out] *buf address to store returned station list info, tls_sta_info_t
|
|
||||||
* @param[in] buf_size buffer size
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*
|
|
||||||
* @note None
|
|
||||||
*/
|
|
||||||
void tls_wifi_get_authed_sta_info(u32 *sta_num, u8 *buf, u32 buf_size);
|
|
||||||
#endif
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is used to get current Wi-Fi State
|
* @brief This function is used to get current Wi-Fi State
|
||||||
*
|
*
|
||||||
@ -1114,6 +1164,43 @@ int tls_wifi_softap_set_sta_num(unsigned char ap_sta_num);
|
|||||||
*/
|
*/
|
||||||
int tls_wifi_softap_del_station(unsigned char* hwaddr);
|
int tls_wifi_softap_del_station(unsigned char* hwaddr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function used to add sta to black list for softap
|
||||||
|
*
|
||||||
|
* @param[out] hwaddr: sta's mac address to forbid
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note None
|
||||||
|
*/
|
||||||
|
int tls_wifi_softap_add_blacksta(unsigned char *hwaddr);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function used to accept sta joining softap that sta in balck list
|
||||||
|
*
|
||||||
|
* @param[out] hwaddr: mac address to delete from black list
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note None
|
||||||
|
*/
|
||||||
|
int tls_wifi_softap_del_blacksta(unsigned char *hwaddr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function used to get stations from blacklist
|
||||||
|
*
|
||||||
|
* @param[out] sta_num: station's number in blacklist
|
||||||
|
* @param[out] buf: store stations to get from blacklist
|
||||||
|
* @param[in] buf_size: memory size to store stations in blacklist
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note None
|
||||||
|
*/
|
||||||
|
int tls_wifi_softap_get_blackinfo(u32 *sta_num, u8 *buf, u32 buf_size);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is used to set some information display in the process of wifi networking
|
* @brief This function is used to set some information display in the process of wifi networking
|
||||||
*
|
*
|
||||||
@ -1147,6 +1234,109 @@ void tls_wifi_set_tempcomp_flag(int flag);
|
|||||||
*/
|
*/
|
||||||
u8 tls_wifi_get_tempcomp_flag(void);
|
u8 tls_wifi_get_tempcomp_flag(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to get temperature compensation flag
|
||||||
|
*
|
||||||
|
* @param[in] fixrateindex: 11b:0-3, 11g:4-11, 11n-ht20:12-19, 11n-ht40:20-27
|
||||||
|
* @param[in] retrycnt: retry count, range[1,15]
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note When use this function, data to be transfered will use fix rate.
|
||||||
|
*/
|
||||||
|
void tls_wifi_set_fixed_rate(u32 fixrateindex, u32 retrycnt);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set listen_interval (dummy interface)
|
||||||
|
*
|
||||||
|
* @param[in] listen_interval: >=1
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note this is dummy interface. this value can used only in sta mode.
|
||||||
|
*/
|
||||||
|
int tls_wifi_cfg_listen_interval(u16 listen_interval);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set connect timeout
|
||||||
|
*
|
||||||
|
* @param[in] timeout: to connect ap's time, >=5s
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note valid only when scan AP failed.
|
||||||
|
*/
|
||||||
|
int tls_wifi_cfg_connect_timeout(u16 timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to configure scan mode
|
||||||
|
*
|
||||||
|
* @param[in] mode:0-find max RSSI AP, 1-find AP and immediately stop scan to start join
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note only used in STA mode.
|
||||||
|
*/
|
||||||
|
int tls_wifi_cfg_connect_scan_mode(u32 mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set pci flag
|
||||||
|
*
|
||||||
|
* @param[in] pci flag:0-can join any supported AP(open,wep,wpa,wpa2)
|
||||||
|
* 1-only join AP(WPA/WPA2 that supported)
|
||||||
|
*
|
||||||
|
* @return None
|
||||||
|
*
|
||||||
|
* @note none.
|
||||||
|
*/
|
||||||
|
int tls_wifi_cfg_connect_pci(u32 pci_en);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set 11b's digital gain
|
||||||
|
*
|
||||||
|
* @param[in] value:gain value, <0x40
|
||||||
|
*
|
||||||
|
* @return 0:if value is valid,-1:if value is invalid
|
||||||
|
*
|
||||||
|
* @note none.
|
||||||
|
*/
|
||||||
|
int tls_wifi_set_11b_digital_gain(u8 value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to get 11b's gain value
|
||||||
|
*
|
||||||
|
* @param[in] None
|
||||||
|
*
|
||||||
|
* @return gain value
|
||||||
|
*
|
||||||
|
* @note none.
|
||||||
|
*/
|
||||||
|
u8 tls_wifi_get_11b_digital_gain(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set 11n's digital gain
|
||||||
|
*
|
||||||
|
* @param[in] value:gain value, <0x40
|
||||||
|
*
|
||||||
|
* @return 0:if value is valid,-1:if value is invalid
|
||||||
|
*
|
||||||
|
* @note none.
|
||||||
|
*/
|
||||||
|
int tls_wifi_set_11n_digital_gain(u8 value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to get 11n's gain value
|
||||||
|
*
|
||||||
|
* @param[in] None
|
||||||
|
*
|
||||||
|
* @return gain value
|
||||||
|
*
|
||||||
|
* @note none.
|
||||||
|
*/
|
||||||
|
u8 tls_wifi_get_11n_digital_gain(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@ -9,10 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef __WM_TYPE_DEF_H__
|
#ifndef __WM_TYPE_DEF_H__
|
||||||
#define __WM_TYPE_DEF_H__
|
#define __WM_TYPE_DEF_H__
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef bool
|
|
||||||
#undef bool
|
|
||||||
#endif
|
|
||||||
#ifdef u8
|
#ifdef u8
|
||||||
#undef u8
|
#undef u8
|
||||||
#endif
|
#endif
|
||||||
@ -53,7 +51,7 @@ typedef unsigned char INT8U;
|
|||||||
#endif
|
#endif
|
||||||
typedef signed char INT8S;
|
typedef signed char INT8S;
|
||||||
|
|
||||||
typedef unsigned char bool;
|
//typedef unsigned char bool;
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
typedef signed char s8;
|
typedef signed char s8;
|
||||||
typedef unsigned short u16;
|
typedef unsigned short u16;
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
I-SRAM : ORIGIN = 0x080d0400 , LENGTH = 0x138000 /* I-SRAM 1M+128KB */
|
I-SRAM : ORIGIN = 0x080d0400 , LENGTH = 0x128000 /* I-SRAM 1M+160KB */
|
||||||
D-SRAM : ORIGIN = 0x20000100 , LENGTH = 0x47EFC /* D-SRAM 288KB */
|
D-SRAM : ORIGIN = 0x20000100 , LENGTH = 0x47EFC /* D-SRAM 288KB */
|
||||||
V-SRAM : ORIGIN = 0x20000000 , LENGTH = 0x100 /* off-chip SRAM 8MB */
|
V-SRAM : ORIGIN = 0x20000000 , LENGTH = 0x100 /* off-chip SRAM 8MB */
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -443,7 +443,7 @@ void tls_mem_alloc_info(void)
|
|||||||
i = 1;
|
i = 1;
|
||||||
dl_list_for_each(pos, &memory_used_list, MEMORY_BLOCK, list){
|
dl_list_for_each(pos, &memory_used_list, MEMORY_BLOCK, list){
|
||||||
printf("Block(%2d): addr<%p>, file<%s>, line<%d>, length<%d>\r\n",
|
printf("Block(%2d): addr<%p>, file<%s>, line<%d>, length<%d>\r\n",
|
||||||
i, pos->header_pattern, pos->file, pos->line, pos->length);
|
i, (void *)pos->header_pattern, pos->file, pos->line, pos->length);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
tls_os_release_critical(cpu_sr);
|
tls_os_release_critical(cpu_sr);
|
||||||
@ -470,7 +470,7 @@ int is_safe_addr_debug(void* p, u32 len, char* file, int line)
|
|||||||
if(((u32)p) + len > ((u32)(pos->header_pattern + sizeof(MEMORY_PATTERN) + PRE_OVERSIZE + pos->length)))
|
if(((u32)p) + len > ((u32)(pos->header_pattern + sizeof(MEMORY_PATTERN) + PRE_OVERSIZE + pos->length)))
|
||||||
{
|
{
|
||||||
printf("==>Memory oversize. Block(%2d): addr<%p>, file<%s>, line<%d>, length<%d>\r\n",
|
printf("==>Memory oversize. Block(%2d): addr<%p>, file<%s>, line<%d>, length<%d>\r\n",
|
||||||
i, pos->header_pattern, pos->file, pos->line, pos->length);
|
i, (void *)pos->header_pattern, pos->file, pos->line, pos->length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -508,7 +508,7 @@ u32 alloc_heap_mem_max_size = 0;
|
|||||||
extern u32 total_mem_size;
|
extern u32 total_mem_size;
|
||||||
void * mem_alloc_debug(u32 size)
|
void * mem_alloc_debug(u32 size)
|
||||||
{
|
{
|
||||||
// u32 cpu_sr = 0;
|
u32 cpu_sr = 0;
|
||||||
u32 *buffer = NULL;
|
u32 *buffer = NULL;
|
||||||
u32 length = size;
|
u32 length = size;
|
||||||
|
|
||||||
@ -516,6 +516,8 @@ void * mem_alloc_debug(u32 size)
|
|||||||
//printf("size:%d\n", size);
|
//printf("size:%d\n", size);
|
||||||
if (!memory_manager_initialized) {
|
if (!memory_manager_initialized) {
|
||||||
tls_os_status_t os_status;
|
tls_os_status_t os_status;
|
||||||
|
|
||||||
|
cpu_sr = tls_os_set_critical();
|
||||||
memory_manager_initialized = true;
|
memory_manager_initialized = true;
|
||||||
//
|
//
|
||||||
// NOTE: If two thread allocate the very first allocation simultaneously
|
// NOTE: If two thread allocate the very first allocation simultaneously
|
||||||
@ -525,6 +527,7 @@ void * mem_alloc_debug(u32 size)
|
|||||||
os_status = tls_os_sem_create(&mem_sem, 1);
|
os_status = tls_os_sem_create(&mem_sem, 1);
|
||||||
if(os_status != TLS_OS_SUCCESS)
|
if(os_status != TLS_OS_SUCCESS)
|
||||||
printf("mem_alloc_debug: tls_os_sem_create mem_sem error\r\n");
|
printf("mem_alloc_debug: tls_os_sem_create mem_sem error\r\n");
|
||||||
|
tls_os_release_critical(cpu_sr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_ADD_HEADER
|
#if USING_ADD_HEADER
|
||||||
@ -545,7 +548,7 @@ void * mem_alloc_debug(u32 size)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
tls_os_sem_acquire(mem_sem, 0);
|
tls_os_sem_acquire(mem_sem, 0);
|
||||||
//cpu_sr = tls_os_set_critical();
|
cpu_sr = tls_os_set_critical();
|
||||||
buffer = (u32*)malloc(length);
|
buffer = (u32*)malloc(length);
|
||||||
if(buffer)
|
if(buffer)
|
||||||
{
|
{
|
||||||
@ -555,11 +558,8 @@ void * mem_alloc_debug(u32 size)
|
|||||||
buffer++;
|
buffer++;
|
||||||
total_mem_size -= length;
|
total_mem_size -= length;
|
||||||
}
|
}
|
||||||
//if(tls_get_isr_count() == 0)
|
tls_os_release_critical(cpu_sr);
|
||||||
// {
|
tls_os_sem_release(mem_sem);
|
||||||
// tls_os_release_critical(cpu_sr);
|
|
||||||
tls_os_sem_release(mem_sem);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
tls_os_sem_acquire(mem_sem, 0);
|
tls_os_sem_acquire(mem_sem, 0);
|
||||||
@ -574,7 +574,7 @@ void * mem_alloc_debug(u32 size)
|
|||||||
|
|
||||||
void mem_free_debug(void *p)
|
void mem_free_debug(void *p)
|
||||||
{
|
{
|
||||||
// u32 cpu_sr = 0;
|
u32 cpu_sr = 0;
|
||||||
// u32 len = 0;
|
// u32 len = 0;
|
||||||
#if USING_ADD_HEADER
|
#if USING_ADD_HEADER
|
||||||
u32* intMemPtr = NULL;
|
u32* intMemPtr = NULL;
|
||||||
@ -584,7 +584,7 @@ void mem_free_debug(void *p)
|
|||||||
if(isrstatus == 0)
|
if(isrstatus == 0)
|
||||||
{
|
{
|
||||||
tls_os_sem_acquire(mem_sem, 0);
|
tls_os_sem_acquire(mem_sem, 0);
|
||||||
// cpu_sr = tls_os_set_critical();
|
cpu_sr = tls_os_set_critical();
|
||||||
}
|
}
|
||||||
|
|
||||||
intMemPtr = (u32*)p;
|
intMemPtr = (u32*)p;
|
||||||
@ -611,7 +611,7 @@ void mem_free_debug(void *p)
|
|||||||
|
|
||||||
if(isrstatus == 0)
|
if(isrstatus == 0)
|
||||||
{
|
{
|
||||||
// tls_os_release_critical(cpu_sr);
|
tls_os_release_critical(cpu_sr);
|
||||||
tls_os_sem_release(mem_sem);
|
tls_os_sem_release(mem_sem);
|
||||||
}
|
}
|
||||||
#else //UCOSII
|
#else //UCOSII
|
||||||
@ -627,7 +627,7 @@ void mem_free_debug(void *p)
|
|||||||
void * mem_realloc_debug(void *mem_address, u32 size)
|
void * mem_realloc_debug(void *mem_address, u32 size)
|
||||||
{
|
{
|
||||||
u32 * mem_re_addr = NULL;
|
u32 * mem_re_addr = NULL;
|
||||||
// u32 cpu_sr = 0;
|
u32 cpu_sr = 0;
|
||||||
u32 length = size;
|
u32 length = size;
|
||||||
|
|
||||||
#if USING_ADD_HEADER
|
#if USING_ADD_HEADER
|
||||||
@ -665,7 +665,7 @@ void * mem_realloc_debug(void *mem_address, u32 size)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
tls_os_sem_acquire(mem_sem, 0);
|
tls_os_sem_acquire(mem_sem, 0);
|
||||||
// cpu_sr = tls_os_set_critical();
|
cpu_sr = tls_os_set_critical();
|
||||||
mem_re_addr = (u32*)malloc(length);
|
mem_re_addr = (u32*)malloc(length);
|
||||||
if(mem_re_addr && mem_address)
|
if(mem_re_addr && mem_address)
|
||||||
{
|
{
|
||||||
@ -683,7 +683,7 @@ void * mem_realloc_debug(void *mem_address, u32 size)
|
|||||||
mem_re_addr ++;
|
mem_re_addr ++;
|
||||||
total_mem_size -= length;
|
total_mem_size -= length;
|
||||||
}
|
}
|
||||||
// tls_os_release_critical(cpu_sr);
|
tls_os_release_critical(cpu_sr);
|
||||||
tls_os_sem_release(mem_sem);
|
tls_os_sem_release(mem_sem);
|
||||||
|
|
||||||
mem_free_debug(mem_address);
|
mem_free_debug(mem_address);
|
||||||
@ -704,7 +704,7 @@ void * mem_realloc_debug(void *mem_address, u32 size)
|
|||||||
|
|
||||||
void *mem_calloc_debug(u32 n, u32 size)
|
void *mem_calloc_debug(u32 n, u32 size)
|
||||||
{
|
{
|
||||||
// u32 cpu_sr = 0;
|
u32 cpu_sr = 0;
|
||||||
u32 *buffer = NULL;
|
u32 *buffer = NULL;
|
||||||
u32 length = 0;
|
u32 length = 0;
|
||||||
|
|
||||||
@ -728,7 +728,7 @@ void *mem_calloc_debug(u32 n, u32 size)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
tls_os_sem_acquire(mem_sem, 0);
|
tls_os_sem_acquire(mem_sem, 0);
|
||||||
// cpu_sr = tls_os_set_critical();
|
cpu_sr = tls_os_set_critical();
|
||||||
buffer = (u32*)malloc(length);
|
buffer = (u32*)malloc(length);
|
||||||
if(buffer)
|
if(buffer)
|
||||||
{
|
{
|
||||||
@ -740,7 +740,7 @@ void *mem_calloc_debug(u32 n, u32 size)
|
|||||||
total_mem_size -= length;
|
total_mem_size -= length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tls_os_release_critical(cpu_sr);
|
tls_os_release_critical(cpu_sr);
|
||||||
tls_os_sem_release(mem_sem);
|
tls_os_sem_release(mem_sem);
|
||||||
}
|
}
|
||||||
#else //UCOSII
|
#else //UCOSII
|
||||||
@ -765,15 +765,15 @@ u32 tls_mem_get_avail_heapsize(void)
|
|||||||
{
|
{
|
||||||
#if USING_ADD_HEADER
|
#if USING_ADD_HEADER
|
||||||
u32 availablemem = 0;
|
u32 availablemem = 0;
|
||||||
// u32 cpu_sr;
|
u32 cpu_sr;
|
||||||
|
|
||||||
tls_os_sem_acquire(mem_sem, 0);
|
tls_os_sem_acquire(mem_sem, 0);
|
||||||
//cpu_sr = tls_os_set_critical();
|
cpu_sr = tls_os_set_critical();
|
||||||
availablemem = total_mem_size;
|
availablemem = total_mem_size;
|
||||||
// tls_os_release_critical(cpu_sr);
|
tls_os_release_critical(cpu_sr);
|
||||||
tls_os_sem_release(mem_sem);
|
tls_os_sem_release(mem_sem);
|
||||||
|
|
||||||
return availablemem&0xFFFFF000;
|
return availablemem;
|
||||||
#else
|
#else
|
||||||
u8 *p = NULL;
|
u8 *p = NULL;
|
||||||
u32 startpos = 0;
|
u32 startpos = 0;
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
#include "wm_mem.h"
|
#include "wm_mem.h"
|
||||||
#include "tls_common.h"
|
#include "tls_common.h"
|
||||||
#include "wm_debug.h"
|
#include "wm_debug.h"
|
||||||
//#include "wm_sockets.h"
|
#include "wm_sockets.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
@ -454,8 +454,8 @@ char * strndup(const char *s, size_t len)
|
|||||||
memcpy(ret, s, len);
|
memcpy(ret, s, len);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 1
|
||||||
int gettimeofday(struct timeval *tv, void *tz)
|
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u32 current_tick;
|
u32 current_tick;
|
||||||
|
|||||||
@ -31,10 +31,14 @@ typedef struct
|
|||||||
double a[3];
|
double a[3];
|
||||||
}ST_ADC_POLYFIT_PARAM;
|
}ST_ADC_POLYFIT_PARAM;
|
||||||
|
|
||||||
|
/*f(x) = kx + b*/
|
||||||
|
//#define ADC_CAL_K_POS (6)
|
||||||
|
//#define ADC_CAL_B_POS (7)
|
||||||
|
|
||||||
|
|
||||||
ST_ADC_POLYFIT_PARAM _polyfit_param = {0};
|
ST_ADC_POLYFIT_PARAM _polyfit_param = {0};
|
||||||
extern void polyfit(int n,double x[],double y[],int poly_n,double a[]);
|
extern void polyfit(int n,double x[],double y[],int poly_n,double a[]);
|
||||||
//TODO
|
|
||||||
#define HR_SD_ADC_CONFIG_REG 0
|
|
||||||
static int adc_offset = 0;
|
static int adc_offset = 0;
|
||||||
static int *adc_dma_buffer = NULL;
|
static int *adc_dma_buffer = NULL;
|
||||||
volatile ST_ADC gst_adc;
|
volatile ST_ADC gst_adc;
|
||||||
@ -79,28 +83,45 @@ static void adc_dma_isr_callbk(void)
|
|||||||
}
|
}
|
||||||
int adc_polyfit_init(ST_ADC_POLYFIT_PARAM *polyfit_param)
|
int adc_polyfit_init(ST_ADC_POLYFIT_PARAM *polyfit_param)
|
||||||
{
|
{
|
||||||
FT_ADC_CAL_ST adc_st;
|
FT_ADC_CAL_ST adc_cal;
|
||||||
double x[16] = {0};
|
/*function f(x) = ax + b*/
|
||||||
double y[16] = {0};
|
float a = 0.0;
|
||||||
int n = 4, poly_n = 1; // or = 2
|
float b = 0.0;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
double x[8] = {0.0};
|
||||||
|
double y[8] = {0.0};
|
||||||
|
|
||||||
polyfit_param->poly_n = 0;
|
polyfit_param->poly_n = 0;
|
||||||
memset(&adc_st, 0, sizeof(adc_st));
|
memset(&adc_cal, 0, sizeof(adc_cal));
|
||||||
tls_get_adc_cal_param(&adc_st);
|
tls_get_adc_cal_param(&adc_cal);
|
||||||
//dumpBuffer("adc_st",(char *)&adc_st, sizeof(adc_st));
|
if ((adc_cal.valid_cnt == 4)
|
||||||
n = adc_st.valid_cnt;
|
||(adc_cal.valid_cnt == 2)
|
||||||
if(n >= 4 && n <= 8)
|
|| (adc_cal.valid_cnt == 3))
|
||||||
{
|
{
|
||||||
for(i = 0; i < n; i++)
|
//memcpy((char *)&a, (char *)&adc_cal.units[ADC_CAL_K_POS], 4);
|
||||||
|
//memcpy((char *)&b, (char *)&adc_cal.units[ADC_CAL_B_POS], 4);
|
||||||
|
a = adc_cal.a;
|
||||||
|
b = adc_cal.b;
|
||||||
|
if ((a > 1.0) && (a < 1.3) && (b < -1000.0)) /*new calibration*/
|
||||||
{
|
{
|
||||||
x[i] = (double)adc_st.units[i].real_val;
|
polyfit_param->poly_n = 1;
|
||||||
y[i] = (double)adc_st.units[i].ref_val;
|
polyfit_param->a[1] = a;
|
||||||
|
polyfit_param->a[0] = b;
|
||||||
|
}
|
||||||
|
else /*old calibration*/
|
||||||
|
{
|
||||||
|
for(i = 0; i < adc_cal.valid_cnt; i++)
|
||||||
|
{
|
||||||
|
x[i] = (double)adc_cal.units[i].real_val;
|
||||||
|
y[i] = (double)adc_cal.units[i].ref_val;
|
||||||
|
}
|
||||||
|
polyfit_param->poly_n = 1;
|
||||||
|
polyfit(adc_cal.valid_cnt,x,y,1, polyfit_param->a);
|
||||||
|
if (b < -1000.0)
|
||||||
|
{
|
||||||
|
polyfit_param->a[0] = b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
polyfit_param->poly_n = poly_n;
|
|
||||||
polyfit(n,x,y,poly_n,polyfit_param->a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -472,26 +493,11 @@ static void waitForAdcDone(void)
|
|||||||
int cal_voltage(double vol)
|
int cal_voltage(double vol)
|
||||||
{
|
{
|
||||||
double y1, voltage;
|
double y1, voltage;
|
||||||
|
|
||||||
double vol_30mV;
|
|
||||||
int average = ((int)vol >> 2) & 0xFFFF;
|
int average = ((int)vol >> 2) & 0xFFFF;
|
||||||
|
|
||||||
if(_polyfit_param.poly_n == 2)
|
if(_polyfit_param.poly_n == 1)
|
||||||
{
|
|
||||||
y1 = _polyfit_param.a[2]*average*average + _polyfit_param.a[1]*average + _polyfit_param.a[0];
|
|
||||||
}
|
|
||||||
else if(_polyfit_param.poly_n == 1)
|
|
||||||
{
|
{
|
||||||
y1 = _polyfit_param.a[1]*average + _polyfit_param.a[0];
|
y1 = _polyfit_param.a[1]*average + _polyfit_param.a[0];
|
||||||
vol_30mV = ((double)300.0L - _polyfit_param.a[0]) / _polyfit_param.a[1];
|
|
||||||
if(average + 170 < vol_30mV)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if(average < vol_30mV)
|
|
||||||
{
|
|
||||||
y1 = 300.0L - 200.0L*(vol_30mV - average) / 170.0L;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -642,3 +648,4 @@ int adc_temp(void)
|
|||||||
return temperature;
|
return temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
187
platform/drivers/adc/wm_adc_cal.c
Normal file
187
platform/drivers/adc/wm_adc_cal.c
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* File Name : wm_adc_cal.c
|
||||||
|
*
|
||||||
|
* Description: adc calibration
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Author :
|
||||||
|
*
|
||||||
|
* Date : 2022-10-10
|
||||||
|
*****************************************************************************/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "wm_include.h"
|
||||||
|
#include "wm_regs.h"
|
||||||
|
#include "wm_adc.h"
|
||||||
|
#include "wm_io.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
#include "wm_efuse.h"
|
||||||
|
|
||||||
|
#define ZERO_CAL_MAX_NUM (10)
|
||||||
|
/*f(x) = kx + b*/
|
||||||
|
//#define ADC_CAL_B_POS (7)
|
||||||
|
//#define ADC_CAL_K_POS (6)
|
||||||
|
#define ADC_CAL_REF_VOLTAGE_POS (5)
|
||||||
|
extern void polyfit(int n,double x[],double y[],int poly_n,double a[]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function can used to calibrate adc coefficient if not calibrated,
|
||||||
|
* or adc offset after FT or multipoint calibration.
|
||||||
|
*
|
||||||
|
* @param[in] chanused: bitmap, specified calibration channel,only bit0-3 can be used
|
||||||
|
* @param[in] refvoltage[]: array, calibration reference voltage to be used, unit:mV
|
||||||
|
* refvoltage keep the same position with chan bitmap
|
||||||
|
* real range[100,2300)mV, suggest reference voltage[500,2000]mV
|
||||||
|
*
|
||||||
|
* @return 0: success, < 0: failure
|
||||||
|
*
|
||||||
|
* @note 1)Adc curve is y=ax+b,y is real voltage(unit:mV), x is adc sample data.
|
||||||
|
* After calibration, we can get a and b, or only update b.
|
||||||
|
* 2) Only used single-end adc
|
||||||
|
* 3) For example, use chan 0,1,3, and refvoltage 500,1000,2000,
|
||||||
|
* then chanused is 0xB, refvoltage[] value is {500,1000,0, 2000};
|
||||||
|
*/
|
||||||
|
int adc_multipoint_calibration(int chanused, int refvoltage[])
|
||||||
|
{
|
||||||
|
#define MAX_ADC_CAL_CHAN (4)
|
||||||
|
#define MAX_ADC_REF_VOLTAGE (2300)
|
||||||
|
#define MIN_ADC_REF_VOLTAGE (100)
|
||||||
|
if (((chanused &((1<<MAX_ADC_CAL_CHAN)-1)) == 0) || (refvoltage == NULL))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FT_ADC_CAL_ST adc_cal;
|
||||||
|
int average = 0;
|
||||||
|
int chancnt = 0;
|
||||||
|
u32 sum_value = 0;
|
||||||
|
float b = 0.0;
|
||||||
|
|
||||||
|
int *prefvoltage = refvoltage;
|
||||||
|
|
||||||
|
/*update calibration parameter*/
|
||||||
|
memset(&adc_cal, 0xFF, sizeof(FT_ADC_CAL_ST));
|
||||||
|
|
||||||
|
for (int j = 0; j < MAX_ADC_CAL_CHAN; j++)
|
||||||
|
{
|
||||||
|
if ((chanused&(1<<j)) == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((prefvoltage[j] < MIN_ADC_REF_VOLTAGE) || (prefvoltage[j] >= MAX_ADC_REF_VOLTAGE))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/*config adc chan for calibration*/
|
||||||
|
wm_adc_config(j);
|
||||||
|
|
||||||
|
/*config adc and start capture data*/
|
||||||
|
tls_adc_init(0, 0);
|
||||||
|
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
|
||||||
|
tls_adc_set_pga(1,1);
|
||||||
|
tls_adc_set_clk(40);
|
||||||
|
tls_adc_start_with_cpu(j);
|
||||||
|
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
sum_value = 0;
|
||||||
|
for (int i = 1; i <= ZERO_CAL_MAX_NUM; i++)
|
||||||
|
{
|
||||||
|
tls_os_time_delay(1);
|
||||||
|
average = *(TLS_REG *)(HR_SD_ADC_RESULT_REG);
|
||||||
|
average = ADC_RESULT_VAL(average);
|
||||||
|
signedToUnsignedData(&average);
|
||||||
|
sum_value += average;
|
||||||
|
}
|
||||||
|
|
||||||
|
adc_cal.units[chancnt].ref_val = prefvoltage[j]*10;
|
||||||
|
adc_cal.units[chancnt].real_val = sum_value/ZERO_CAL_MAX_NUM/4;
|
||||||
|
chancnt++;
|
||||||
|
tls_adc_stop(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chancnt >= 2)
|
||||||
|
{
|
||||||
|
float k = 0.0;
|
||||||
|
double a[4] = {0.0};
|
||||||
|
double x[8] = {0.0};
|
||||||
|
double y[8] = {0.0};
|
||||||
|
|
||||||
|
for(int i = 0; i < chancnt; i++)
|
||||||
|
{
|
||||||
|
x[i] = (double)adc_cal.units[i].real_val;
|
||||||
|
y[i] = (double)adc_cal.units[i].ref_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
polyfit(chancnt, x, y, 1, a);
|
||||||
|
|
||||||
|
k = (float)a[1];
|
||||||
|
b = (float)a[0];
|
||||||
|
//memcpy((char *)&adc_cal.units[ADC_CAL_K_POS], (char *)&k, 4);
|
||||||
|
//memcpy((char *)&adc_cal.units[ADC_CAL_B_POS], (char *)&b, 4);
|
||||||
|
adc_cal.a = k;
|
||||||
|
adc_cal.b = b;
|
||||||
|
adc_cal.valid_cnt = chancnt;
|
||||||
|
return tls_set_adc_cal_param(&adc_cal);
|
||||||
|
}
|
||||||
|
else /*only one reference voltage*/
|
||||||
|
{
|
||||||
|
/*update calibration parameter*/
|
||||||
|
int currentvalue = cal_voltage((double)adc_cal.units[0].real_val*4);
|
||||||
|
int ret = tls_get_adc_cal_param(&adc_cal);
|
||||||
|
if ((ret == 0) && (adc_cal.valid_cnt >= 2) && (adc_cal.valid_cnt <= 4))
|
||||||
|
{
|
||||||
|
/*reference voltage by user settings*/
|
||||||
|
for (int i = 0; i < MAX_ADC_CAL_CHAN; i++)
|
||||||
|
{
|
||||||
|
if (chanused&(1<<i))
|
||||||
|
{
|
||||||
|
adc_cal.units[ADC_CAL_REF_VOLTAGE_POS].ref_val = prefvoltage[i];
|
||||||
|
average = prefvoltage[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*update parameter b that used by the function f(x)=ax+b */
|
||||||
|
//memcpy((char *)&b, (char *)&adc_cal.units[ADC_CAL_B_POS], 4);
|
||||||
|
b = adc_cal.b;
|
||||||
|
b = b + (average - currentvalue)*10; /*0.1mV*/
|
||||||
|
//memcpy((char *)&adc_cal.units[ADC_CAL_B_POS], (char *)&b, 4);
|
||||||
|
adc_cal.b = b;
|
||||||
|
return tls_set_adc_cal_param(&adc_cal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to calibrate adc offset after FT or multipoint calibration.
|
||||||
|
*
|
||||||
|
* @param[in] chan: adc calibration channel to be used
|
||||||
|
* @param[in] refvoltage: calibration reference voltage to be used, unit:mV
|
||||||
|
*
|
||||||
|
* @return 0: success, < 0: failure
|
||||||
|
*
|
||||||
|
* @note After FT calibration or mulitpoint calibration, adc curve is y=ax+b,
|
||||||
|
* y is real voltage(unit:mV), x is adc sample data
|
||||||
|
* a and b is the coefficient. This fuction only used to revise b value.
|
||||||
|
*/
|
||||||
|
int adc_offset_calibration(int chan, int refvoltage)
|
||||||
|
{
|
||||||
|
if (chan >= 0 && chan < 4)
|
||||||
|
{
|
||||||
|
int refvol[4] = {0, 0, 0, 0};
|
||||||
|
refvol[chan] = refvoltage;
|
||||||
|
return adc_multipoint_calibration((1<<chan), refvol);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
void polyfit_verify(double x, double* a)
|
void polyfit_verify(double x, double* a)
|
||||||
{
|
{
|
||||||
double y1 = a[2]*x*x + a[1]*x + a[0];
|
double y1 = a[1]*x + a[0];
|
||||||
printf("x=%d, y1=%d\n", (int)x, (int)(y1+0.5));
|
printf("x=%d, y1=%d\n", (int)x, (int)(y1+0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,9 +95,9 @@ x[i]-=A[i*n+j]*x[j];
|
|||||||
|
|
||||||
void polyfit_test(void)
|
void polyfit_test(void)
|
||||||
{
|
{
|
||||||
int i,n=4,poly_n=2;
|
int i,n=2,poly_n=1;
|
||||||
double x[4]={4823, 9816, 14851, 19837},y[4]={5000, 9986, 15001, 19959};
|
double x[2]={15174, 19196},y[2]={5000, 9986};
|
||||||
double a[3];
|
double a[2];
|
||||||
void polyfit(int n,double *x,double *y,int poly_n,double a[]);
|
void polyfit(int n,double *x,double *y,int poly_n,double a[]);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#define FT_MAGICNUM_ADDR (FLASH_BASE_ADDR)
|
#define FT_MAGICNUM_ADDR (FLASH_BASE_ADDR)
|
||||||
|
#define FT_PARAM_RUNTIME_ADDR (FT_MAGICNUM_ADDR + 0x1000)
|
||||||
#define MAGICNUM_LEN (4)
|
#define MAGICNUM_LEN (4)
|
||||||
#define MAC_ADDR_LEN (6)
|
#define MAC_ADDR_LEN (6)
|
||||||
#define FT_GAIN_LEN (84)
|
#define FT_GAIN_LEN (84)
|
||||||
@ -70,28 +71,23 @@ static u8 default_mac[6] = {0x00,0x25,0x08,0x09,0x01,0x0F};
|
|||||||
FT_PARAM_ST_VER1 gftParamVer1;
|
FT_PARAM_ST_VER1 gftParamVer1;
|
||||||
|
|
||||||
FT_PARAM_ST *gftParam = (FT_PARAM_ST *)&gftParamVer1;
|
FT_PARAM_ST *gftParam = (FT_PARAM_ST *)&gftParamVer1;
|
||||||
int tls_ft_param_init(void)
|
static int _ft_ext1_valid(FT_PARAM_ST *pft)
|
||||||
|
{
|
||||||
|
//printf("version_no %d, ext_param_len %x\n", pft->version_no, pft->ext_param_len);
|
||||||
|
if (pft->version_no > 0 && pft->version_no < 0xFFFF && pft->ext_param_len >= sizeof(FT_PARAM_ST_EXT_1) &&
|
||||||
|
pft->ext_param_len <= (sizeof(FT_PARAM_ST_EXT_1) + FT_PARAM_EXT_REVERSED_LEN))
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
static int _ft_param_init(u32 ft_addr, FT_PARAM_ST *pft)
|
||||||
{
|
{
|
||||||
u32 crcvalue = 0;
|
u32 crcvalue = 0;
|
||||||
psCrcContext_t ctx;
|
psCrcContext_t ctx;
|
||||||
FT_PARAM_ST_VER1 *pft_ver1 = NULL;
|
FT_PARAM_ST_VER1 *pft_ver1 = NULL;
|
||||||
FT_PARAM_ST *pft = NULL;
|
|
||||||
|
|
||||||
if (gftParam->magic_no == SIGNATURE_WORD)
|
tls_fls_read(ft_addr, (unsigned char *)pft, sizeof(FT_PARAM_ST_VER1));
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
pft = tls_mem_alloc(sizeof(FT_PARAM_ST_VER1));
|
|
||||||
if (pft == NULL)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
|
||||||
memset(gftParam, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
|
||||||
|
|
||||||
tls_fls_read(FT_MAGICNUM_ADDR, (unsigned char *)pft, sizeof(FT_PARAM_ST_VER1));
|
|
||||||
if (pft->magic_no == SIGNATURE_WORD)
|
if (pft->magic_no == SIGNATURE_WORD)
|
||||||
{
|
{
|
||||||
tls_crypto_init();
|
tls_crypto_init();
|
||||||
@ -100,14 +96,13 @@ int tls_ft_param_init(void)
|
|||||||
tls_crypto_crc_final(&ctx, &crcvalue);
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
if (pft->checksum != crcvalue)
|
if (pft->checksum != crcvalue)
|
||||||
{
|
{
|
||||||
tls_mem_free(pft);
|
//tls_mem_free(pft);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (pft->version_no > 0 && pft->version_no < 0xFFFF && pft->ext_param_len >= sizeof(FT_PARAM_ST_EXT_1) &&
|
if (_ft_ext1_valid(pft))
|
||||||
pft->ext_param_len <= (sizeof(FT_PARAM_ST_EXT_1) + FT_PARAM_EXT_REVERSED_LEN))
|
|
||||||
{
|
{
|
||||||
pft_ver1 = (FT_PARAM_ST_VER1 *)pft;
|
pft_ver1 = (FT_PARAM_ST_VER1 *)pft;
|
||||||
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
@ -115,31 +110,100 @@ int tls_ft_param_init(void)
|
|||||||
tls_crypto_crc_final(&ctx, &crcvalue);
|
tls_crypto_crc_final(&ctx, &crcvalue);
|
||||||
if(pft_ver1->ext_checksum == crcvalue)
|
if(pft_ver1->ext_checksum == crcvalue)
|
||||||
{
|
{
|
||||||
memcpy((unsigned char *)gftParam, (unsigned char *)pft, sizeof(FT_PARAM_ST_VER1));
|
return 1;
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pft->version_no = 0xFFFF;
|
pft->version_no = 0xFFFF;
|
||||||
pft->ext_param_len = 0xFFFF;
|
pft->ext_param_len = 0xFFFF;
|
||||||
memcpy((unsigned char *)gftParam, (unsigned char *)pft, sizeof(FT_PARAM_ST));
|
|
||||||
}while(0);
|
}while(0);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
int tls_ft_param_init(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
FT_PARAM_ST *pft = NULL;
|
||||||
|
|
||||||
|
if (gftParam->magic_no == SIGNATURE_WORD)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
memset(gftParam, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
|
||||||
|
pft = tls_mem_alloc(sizeof(FT_PARAM_ST_VER1));
|
||||||
|
if (pft == NULL)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_PARAM_RUNTIME_ADDR, pft);
|
||||||
|
if(FALSE == ret)
|
||||||
|
{
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_MAGICNUM_ADDR, pft);
|
||||||
|
}
|
||||||
|
if(1 == ret)
|
||||||
|
{
|
||||||
|
memcpy((unsigned char *)gftParam, (unsigned char *)pft, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
}
|
||||||
|
else if(2 == ret)
|
||||||
|
{
|
||||||
|
memcpy((unsigned char *)gftParam, (unsigned char *)pft, sizeof(FT_PARAM_ST));
|
||||||
}
|
}
|
||||||
tls_mem_free(pft);
|
tls_mem_free(pft);
|
||||||
|
|
||||||
/*lock parameter*/
|
/*lock parameter*/
|
||||||
tls_flash_unlock();
|
tls_flash_unlock();
|
||||||
return TRUE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen)
|
int tls_ft_param_get(unsigned int opnum, void *data, unsigned int rdlen)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
switch (opnum)
|
switch (opnum)
|
||||||
{
|
{
|
||||||
|
case CMD_FREQ_ERR:
|
||||||
|
if(_ft_ext1_valid(gftParam))
|
||||||
|
{
|
||||||
|
memcpy(data, (char *)&gftParamVer1.ft_ext1.rf_freq_err, FREQERR_LEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = tls_fls_read(FREQERR_ADDR, data, FREQERR_LEN);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CMD_RF_CAL_FLAG:
|
||||||
|
if(_ft_ext1_valid(gftParam))
|
||||||
|
{
|
||||||
|
memcpy(data, (char *)&gftParamVer1.ft_ext1.rf_cal_flag, CAL_FLAG_LEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = tls_fls_read(CAL_FLAG_ADDR, data, CAL_FLAG_LEN);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
case CMD_TX_ADC_CAL:
|
case CMD_TX_ADC_CAL:
|
||||||
if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
|
if(_ft_ext1_valid(gftParam))
|
||||||
{
|
{
|
||||||
memcpy(data, (unsigned char *)&gftParamVer1.ft_ext1.adc_cal_param, rdlen);
|
memcpy(data, (unsigned char *)&gftParamVer1.ft_ext1.adc_cal_param, rdlen);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_WIFI_MAC: /*MAC*/
|
case CMD_WIFI_MAC: /*MAC*/
|
||||||
if ((gftParam->wifi_mac_addr[0]&0x1)
|
if ((gftParam->wifi_mac_addr[0]&0x1)
|
||||||
@ -217,13 +281,57 @@ int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
|
|||||||
{
|
{
|
||||||
psCrcContext_t ctx;
|
psCrcContext_t ctx;
|
||||||
unsigned int writelen = 0;
|
unsigned int writelen = 0;
|
||||||
|
FT_PARAM_ST *pft = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (!data || !len)
|
if (!data || !len)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pft = tls_mem_alloc(sizeof(FT_PARAM_ST_VER1));
|
||||||
|
if (pft == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_PARAM_RUNTIME_ADDR, pft);
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_MAGICNUM_ADDR, pft);
|
||||||
|
if(!ret || memcmp(pft, gftParam, sizeof(FT_PARAM_ST_VER1)))
|
||||||
|
{
|
||||||
|
tls_flash_unlock();
|
||||||
|
tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_MAGICNUM_ADDR, pft);
|
||||||
|
if(!ret || memcmp(pft, gftParam, sizeof(FT_PARAM_ST_VER1)))
|
||||||
|
{
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
tls_mem_free(pft);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!_ft_ext1_valid(gftParam))
|
||||||
|
{
|
||||||
|
gftParam->version_no = 1;
|
||||||
|
gftParam->ext_param_len = sizeof(FT_PARAM_ST_EXT_1);
|
||||||
|
memset((char *)&gftParamVer1.ft_ext1, 0xFF, gftParam->ext_param_len);
|
||||||
|
}
|
||||||
switch (opnum)
|
switch (opnum)
|
||||||
{
|
{
|
||||||
|
case CMD_FREQ_ERR:
|
||||||
|
memcpy((char *)&gftParamVer1.ft_ext1.rf_freq_err, (char *)data, FREQERR_LEN);
|
||||||
|
break;
|
||||||
|
case CMD_RF_CAL_FLAG:
|
||||||
|
memcpy((char *)&gftParamVer1.ft_ext1.rf_cal_flag, (char *)data, CAL_FLAG_LEN);
|
||||||
|
break;
|
||||||
|
case CMD_TX_ADC_CAL:
|
||||||
|
memcpy((unsigned char *)&gftParamVer1.ft_ext1.adc_cal_param, data, len);
|
||||||
|
break;
|
||||||
|
|
||||||
case CMD_WIFI_MAC: /*MAC*/
|
case CMD_WIFI_MAC: /*MAC*/
|
||||||
memcpy(gftParam->wifi_mac_addr, (unsigned char *)data, len);
|
memcpy(gftParam->wifi_mac_addr, (unsigned char *)data, len);
|
||||||
break;
|
break;
|
||||||
@ -269,25 +377,44 @@ int tls_ft_param_set(unsigned int opnum, void *data, unsigned int len)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
tls_mem_free(pft);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tls_crypto_init();
|
tls_crypto_init();
|
||||||
|
/*len to write to flash*/
|
||||||
|
writelen = sizeof(FT_PARAM_ST_VER1);
|
||||||
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
|
tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
|
||||||
|
tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
|
||||||
|
|
||||||
gftParam->magic_no = SIGNATURE_WORD;
|
gftParam->magic_no = SIGNATURE_WORD;
|
||||||
|
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
||||||
tls_crypto_crc_update(&ctx, (unsigned char *)gftParam + 8, sizeof(FT_PARAM_ST) -8);
|
tls_crypto_crc_update(&ctx, (unsigned char *)gftParam + 8, sizeof(FT_PARAM_ST) -8);
|
||||||
tls_crypto_crc_final(&ctx, &gftParam->checksum);
|
tls_crypto_crc_final(&ctx, &gftParam->checksum);
|
||||||
writelen = sizeof(FT_PARAM_ST);
|
|
||||||
if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
|
|
||||||
{
|
|
||||||
writelen = sizeof(FT_PARAM_ST_VER1);
|
|
||||||
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
|
||||||
tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
|
|
||||||
tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
|
|
||||||
}
|
|
||||||
tls_flash_unlock();
|
tls_flash_unlock();
|
||||||
|
tls_fls_write(FT_PARAM_RUNTIME_ADDR, (unsigned char *)gftParam, writelen);
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_PARAM_RUNTIME_ADDR, pft);
|
||||||
|
if(!ret || memcmp(pft, gftParam, sizeof(FT_PARAM_ST_VER1)))
|
||||||
|
{
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
tls_mem_free(pft);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, writelen);
|
tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, writelen);
|
||||||
tls_flash_lock();
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
ret = _ft_param_init(FT_MAGICNUM_ADDR, pft);
|
||||||
|
if(!ret || memcmp(pft, gftParam, sizeof(FT_PARAM_ST_VER1)))
|
||||||
|
{
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
tls_mem_free(pft);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(pft, 0xFF, sizeof(FT_PARAM_ST_VER1));
|
||||||
|
tls_mem_free(pft);
|
||||||
|
//tls_flash_lock();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,45 +606,26 @@ int tls_set_rx_iq_phase(u8 *rxPhase)
|
|||||||
int tls_freq_err_op(u8 *freqerr, u8 flag)
|
int tls_freq_err_op(u8 *freqerr, u8 flag)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
psCrcContext_t ctx;
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
if (flag){
|
if (flag){
|
||||||
tls_flash_unlock();
|
ret = tls_ft_param_set(CMD_FREQ_ERR, freqerr, FREQERR_LEN);
|
||||||
if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
|
|
||||||
{
|
|
||||||
memcpy((char *)&gftParamVer1.ft_ext1.rf_freq_err, (char *)freqerr, FREQERR_LEN);
|
|
||||||
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
|
||||||
tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
|
|
||||||
tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
|
|
||||||
ret = tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, sizeof(FT_PARAM_ST_VER1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = tls_fls_write(FREQERR_ADDR, freqerr, FREQERR_LEN);
|
|
||||||
}
|
|
||||||
tls_flash_lock();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
|
ret = tls_ft_param_get(CMD_FREQ_ERR, freqerr, FREQERR_LEN);
|
||||||
|
if(!ret)
|
||||||
{
|
{
|
||||||
memcpy((char *)freqerr, (char *)&gftParamVer1.ft_ext1.rf_freq_err, FREQERR_LEN);
|
memcpy(&value, freqerr, FREQERR_LEN);
|
||||||
}
|
if (value > 200000) /*when freq offset is out of range (-200KHz, 200KHz),do not use it*/
|
||||||
else
|
{
|
||||||
{
|
value = 200000;
|
||||||
ret = tls_fls_read(FREQERR_ADDR, freqerr, FREQERR_LEN);
|
memcpy((char *)freqerr, (char *)&value, FREQERR_LEN);
|
||||||
}
|
}
|
||||||
|
else if (value < -200000)
|
||||||
memcpy(&value, freqerr, FREQERR_LEN);
|
{
|
||||||
if (value > 200000) /*when freq offset is out of range (-200KHz, 200KHz),do not use it*/
|
value = -200000;
|
||||||
{
|
memcpy((char *)freqerr, (char *)&value, FREQERR_LEN);
|
||||||
value = 200000;
|
}
|
||||||
memcpy((char *)freqerr, (char *)&value, FREQERR_LEN);
|
|
||||||
}
|
|
||||||
else if (value < -200000)
|
|
||||||
{
|
|
||||||
value = -200000;
|
|
||||||
memcpy((char *)freqerr, (char *)&value, FREQERR_LEN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@ -533,33 +641,12 @@ int tls_freq_err_op(u8 *freqerr, u8 flag)
|
|||||||
int tls_rf_cal_finish_op(u8 *calflag, u8 flag)
|
int tls_rf_cal_finish_op(u8 *calflag, u8 flag)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
psCrcContext_t ctx;
|
|
||||||
if (flag){
|
if (flag){
|
||||||
tls_flash_unlock();
|
ret = tls_ft_param_set(CMD_RF_CAL_FLAG, calflag, CAL_FLAG_LEN);
|
||||||
if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
|
|
||||||
{
|
|
||||||
memcpy((char *)&gftParamVer1.ft_ext1.rf_cal_flag, (char *)calflag, CAL_FLAG_LEN);
|
|
||||||
tls_crypto_crc_init(&ctx, 0xFFFFFFFF, CRYPTO_CRC_TYPE_32, INPUT_REFLECT | OUTPUT_REFLECT);
|
|
||||||
tls_crypto_crc_update(&ctx, (unsigned char *)&gftParamVer1.ft_ext1, gftParam->ext_param_len);
|
|
||||||
tls_crypto_crc_final(&ctx, &gftParamVer1.ext_checksum);
|
|
||||||
ret = tls_fls_write(FT_MAGICNUM_ADDR, (unsigned char *)gftParam, sizeof(FT_PARAM_ST_VER1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = tls_fls_write(CAL_FLAG_ADDR, calflag, CAL_FLAG_LEN);
|
|
||||||
}
|
|
||||||
tls_flash_lock();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(gftParam->version_no > 0 && gftParam->version_no < 0xFFFF)
|
ret = tls_ft_param_get(CMD_RF_CAL_FLAG, calflag, CAL_FLAG_LEN);
|
||||||
{
|
|
||||||
memcpy((char *)calflag, (char *)&gftParamVer1.ft_ext1.rf_cal_flag, CAL_FLAG_LEN);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = tls_fls_read(CAL_FLAG_ADDR, calflag, CAL_FLAG_LEN);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@ -600,11 +687,31 @@ int tls_set_tx_gain(u8 *txgain)
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to get adc cal param
|
||||||
|
*
|
||||||
|
* @param[out] adc_cal adc cal param
|
||||||
|
*
|
||||||
|
* @retval TLS_EFUSE_STATUS_OK get success
|
||||||
|
* @retval TLS_EFUSE_STATUS_EIO get failed
|
||||||
|
*/
|
||||||
int tls_get_adc_cal_param(FT_ADC_CAL_ST *adc_cal)
|
int tls_get_adc_cal_param(FT_ADC_CAL_ST *adc_cal)
|
||||||
{
|
{
|
||||||
return tls_ft_param_get(CMD_TX_ADC_CAL, adc_cal, sizeof(FT_ADC_CAL_ST));
|
return tls_ft_param_get(CMD_TX_ADC_CAL, adc_cal, sizeof(FT_ADC_CAL_ST));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to set adc cal param
|
||||||
|
*
|
||||||
|
* @param[out] adc_cal adc cal param
|
||||||
|
*
|
||||||
|
* @retval TLS_EFUSE_STATUS_OK get success
|
||||||
|
* @retval TLS_EFUSE_STATUS_EIO get failed
|
||||||
|
*/
|
||||||
|
int tls_set_adc_cal_param(FT_ADC_CAL_ST *adc_cal)
|
||||||
|
{
|
||||||
|
return tls_ft_param_set(CMD_TX_ADC_CAL, adc_cal, sizeof(FT_ADC_CAL_ST));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -206,7 +206,7 @@ void wm_psram_config(uint8_t numsel)
|
|||||||
{
|
{
|
||||||
switch(numsel)
|
switch(numsel)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0://W800 or w801
|
||||||
tls_io_cfg_set(WM_IO_PB_00, WM_IO_OPTION4);/*CK*/
|
tls_io_cfg_set(WM_IO_PB_00, WM_IO_OPTION4);/*CK*/
|
||||||
tls_io_cfg_set(WM_IO_PB_01, WM_IO_OPTION4);/*CS*/
|
tls_io_cfg_set(WM_IO_PB_01, WM_IO_OPTION4);/*CS*/
|
||||||
tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION4);/*D0*/
|
tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION4);/*D0*/
|
||||||
@ -217,6 +217,16 @@ void wm_psram_config(uint8_t numsel)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1://w801
|
case 1://w801
|
||||||
|
tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);/*CK*/
|
||||||
|
tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);/*CS*/
|
||||||
|
tls_io_cfg_set(WM_IO_PB_02, WM_IO_OPTION4);/*D0*/
|
||||||
|
tls_io_cfg_set(WM_IO_PB_03, WM_IO_OPTION4);/*D1*/
|
||||||
|
tls_io_cfg_set(WM_IO_PB_04, WM_IO_OPTION4);/*D2*/
|
||||||
|
tls_io_cfg_set(WM_IO_PB_05, WM_IO_OPTION4);/*D3*/
|
||||||
|
tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2://w861
|
||||||
tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);/*CK*/
|
tls_io_cfg_set(WM_IO_PA_15, WM_IO_OPTION1);/*CK*/
|
||||||
tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);/*CS*/
|
tls_io_cfg_set(WM_IO_PB_27, WM_IO_OPTION1);/*CS*/
|
||||||
tls_io_cfg_set(WM_IO_PB_28, WM_IO_OPTION1);/*D0*/
|
tls_io_cfg_set(WM_IO_PB_28, WM_IO_OPTION1);/*D0*/
|
||||||
@ -1089,7 +1099,7 @@ void wm_gpio_af_disable(void)
|
|||||||
#endif
|
#endif
|
||||||
tls_reg_write32(HR_GPIOB_AFSEL, 0x0);
|
tls_reg_write32(HR_GPIOB_AFSEL, 0x0);
|
||||||
|
|
||||||
tls_reg_write32(HR_GPIOA_DATA_PULLEN, 0xffff);
|
tls_reg_write32(HR_GPIOA_DATA_PULLEN, 0x0);
|
||||||
tls_reg_write32(HR_GPIOB_DATA_PULLEN, 0xffffffff);
|
tls_reg_write32(HR_GPIOB_DATA_PULLEN, 0x0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,17 +59,18 @@ static void writeBpBit_for_1wreg(char cmp, char bp4, char bp3, char bp2, char bp
|
|||||||
M32(HR_FLASH_CMD_ADDR) = 0x0C035;
|
M32(HR_FLASH_CMD_ADDR) = 0x0C035;
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
status |= (read_first_value() & 0xFF) << 8;
|
status |= (read_first_value() & 0xFF) << 8;
|
||||||
|
|
||||||
/*Write Enable*/
|
|
||||||
M32(HR_FLASH_CMD_ADDR) = 0x6;
|
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
|
||||||
|
|
||||||
bpstatus = (bp4 << 6) | (bp3 << 5) | (bp2 << 4) | (bp1 << 3) | (bp0 << 2);
|
bpstatus = (bp4 << 6) | (bp3 << 5) | (bp2 << 4) | (bp1 << 3) | (bp0 << 2);
|
||||||
status = (status & 0xBF83) | bpstatus | (cmp << 14);
|
if ((status & 0x407C) != (bpstatus|(cmp<<14)))
|
||||||
|
{
|
||||||
|
status = (status & 0xBF83) | bpstatus | (cmp << 14);
|
||||||
|
/*Write Enable*/
|
||||||
|
M32(HR_FLASH_CMD_ADDR) = 0x6;
|
||||||
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
|
|
||||||
M32(RSA_BASE_ADDRESS) = status;
|
M32(RSA_BASE_ADDRESS) = status;
|
||||||
M32(HR_FLASH_CMD_ADDR) = 0x1A001;
|
M32(HR_FLASH_CMD_ADDR) = 0x1A001;
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeBpBit_for_2wreg(char cmp, char bp4, char bp3, char bp2, char bp1, char bp0)
|
static void writeBpBit_for_2wreg(char cmp, char bp4, char bp3, char bp2, char bp1, char bp0)
|
||||||
@ -86,24 +87,29 @@ static void writeBpBit_for_2wreg(char cmp, char bp4, char bp3, char bp2, char bp
|
|||||||
status |= (read_first_value() & 0xFF) << 8;
|
status |= (read_first_value() & 0xFF) << 8;
|
||||||
|
|
||||||
/*Write Enable*/
|
/*Write Enable*/
|
||||||
M32(HR_FLASH_CMD_ADDR) = 0x6;
|
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
|
||||||
|
|
||||||
bpstatus = (bp4 << 6) | (bp3 << 5) | (bp2 << 4) | (bp1 << 3) | (bp0 << 2);
|
bpstatus = (bp4 << 6) | (bp3 << 5) | (bp2 << 4) | (bp1 << 3) | (bp0 << 2);
|
||||||
bpstatus = (status & 0x83) | bpstatus;
|
if ((bpstatus != (status & 0x7C)))
|
||||||
|
{
|
||||||
|
bpstatus = (status & 0x83) | bpstatus;
|
||||||
|
|
||||||
M32(RSA_BASE_ADDRESS) = bpstatus;
|
M32(HR_FLASH_CMD_ADDR) = 0x6;
|
||||||
M32(HR_FLASH_CMD_ADDR) = 0xA001;
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
|
||||||
|
|
||||||
|
M32(RSA_BASE_ADDRESS) = bpstatus;
|
||||||
|
M32(HR_FLASH_CMD_ADDR) = 0xA001;
|
||||||
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
M32(HR_FLASH_CMD_ADDR) = 0x6;
|
if (((status & 0x4000)>>8) != (cmp << 6))
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
{
|
||||||
|
M32(HR_FLASH_CMD_ADDR) = 0x6;
|
||||||
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
|
|
||||||
status = ((status>>8) & 0xBF) | (cmp << 6);
|
status = ((status>>8) & 0xBF) | (cmp << 6);
|
||||||
M32(RSA_BASE_ADDRESS) = status;
|
M32(RSA_BASE_ADDRESS) = status;
|
||||||
M32(HR_FLASH_CMD_ADDR) = 0xA031;
|
M32(HR_FLASH_CMD_ADDR) = 0xA031;
|
||||||
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
M32(HR_FLASH_CMD_START) = CMD_START_Msk;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,10 +156,10 @@ static int flashunlock(void)
|
|||||||
{
|
{
|
||||||
case SPIFLASH_MID_GD:
|
case SPIFLASH_MID_GD:
|
||||||
case SPIFLASH_MID_TSINGTENG:
|
case SPIFLASH_MID_TSINGTENG:
|
||||||
case SPIFLASH_MID_TSINGTENG_1MB:
|
|
||||||
writeBpBit_for_1wreg(0, 0, 0, 0, 0, 0);
|
writeBpBit_for_1wreg(0, 0, 0, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
case SPIFLASH_MID_PUYA:
|
case SPIFLASH_MID_PUYA:
|
||||||
|
case SPIFLASH_MID_TSINGTENG_1MB_4MB:
|
||||||
if (inside_fls->density == 0x100000)/*PUYA 1M Flash use 1 register to set lock/unlock*/
|
if (inside_fls->density == 0x100000)/*PUYA 1M Flash use 1 register to set lock/unlock*/
|
||||||
{
|
{
|
||||||
writeBpBit_for_1wreg(0, 0, 0, 0, 0, 0);
|
writeBpBit_for_1wreg(0, 0, 0, 0, 0, 0);
|
||||||
@ -184,10 +190,10 @@ static int flashlock(void)
|
|||||||
{
|
{
|
||||||
case SPIFLASH_MID_GD:
|
case SPIFLASH_MID_GD:
|
||||||
case SPIFLASH_MID_TSINGTENG:
|
case SPIFLASH_MID_TSINGTENG:
|
||||||
case SPIFLASH_MID_TSINGTENG_1MB:
|
|
||||||
writeBpBit_for_1wreg(0, 1, 1, 0, 1, 0);
|
writeBpBit_for_1wreg(0, 1, 1, 0, 1, 0);
|
||||||
break;
|
break;
|
||||||
case SPIFLASH_MID_PUYA:
|
case SPIFLASH_MID_PUYA:
|
||||||
|
case SPIFLASH_MID_TSINGTENG_1MB_4MB:
|
||||||
if (inside_fls->density == 0x100000) /*PUYA 1M Flash use 1 register to set lock/unlock*/
|
if (inside_fls->density == 0x100000) /*PUYA 1M Flash use 1 register to set lock/unlock*/
|
||||||
{
|
{
|
||||||
writeBpBit_for_1wreg(0, 1, 1, 0, 1, 0);
|
writeBpBit_for_1wreg(0, 1, 1, 0, 1, 0);
|
||||||
@ -655,7 +661,7 @@ int tls_fls_read_unique_id(unsigned char *uuid)
|
|||||||
case SPIFLASH_MID_GD:
|
case SPIFLASH_MID_GD:
|
||||||
case SPIFLASH_MID_PUYA:
|
case SPIFLASH_MID_PUYA:
|
||||||
case SPIFLASH_MID_TSINGTENG:
|
case SPIFLASH_MID_TSINGTENG:
|
||||||
case SPIFLASH_MID_TSINGTENG_1MB:
|
case SPIFLASH_MID_TSINGTENG_1MB_4MB:
|
||||||
dumy_bytes = 4;
|
dumy_bytes = 4;
|
||||||
uni_bytes = 16;
|
uni_bytes = 16;
|
||||||
break;
|
break;
|
||||||
@ -870,7 +876,7 @@ int tls_fls_otp_lock(void)
|
|||||||
case SPIFLASH_MID_TSINGTENG:
|
case SPIFLASH_MID_TSINGTENG:
|
||||||
writeLbBit_for_1wreg((1<<10));
|
writeLbBit_for_1wreg((1<<10));
|
||||||
break;
|
break;
|
||||||
case SPIFLASH_MID_TSINGTENG_1MB:
|
case SPIFLASH_MID_TSINGTENG_1MB_4MB:
|
||||||
writeLbBit_for_1wreg((7<<11));
|
writeLbBit_for_1wreg((7<<11));
|
||||||
break;
|
break;
|
||||||
case SPIFLASH_MID_FUDANMICRO:
|
case SPIFLASH_MID_FUDANMICRO:
|
||||||
@ -1460,8 +1466,21 @@ int tls_fls_init(void)
|
|||||||
fls->OTPWRParam.pageSize = 256;
|
fls->OTPWRParam.pageSize = 256;
|
||||||
switch(fls->flashid)
|
switch(fls->flashid)
|
||||||
{
|
{
|
||||||
|
case SPIFLASH_MID_TSINGTENG_1MB_4MB:
|
||||||
|
if (fls->density == 0x100000)
|
||||||
|
{
|
||||||
|
fls->OTPWRParam.eraseSize = 1024;
|
||||||
|
}
|
||||||
|
else if (fls->density == 0x400000)
|
||||||
|
{
|
||||||
|
fls->OTPWRParam.eraseSize = 2048;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fls->OTPWRParam.eraseSize = 256;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SPIFLASH_MID_GD:
|
case SPIFLASH_MID_GD:
|
||||||
case SPIFLASH_MID_TSINGTENG_1MB:
|
|
||||||
fls->OTPWRParam.eraseSize = 1024;
|
fls->OTPWRParam.eraseSize = 1024;
|
||||||
break;
|
break;
|
||||||
case SPIFLASH_MID_FUDANMICRO:
|
case SPIFLASH_MID_FUDANMICRO:
|
||||||
|
|||||||
@ -33,6 +33,8 @@ static void io_cfg_option1(enum tls_io_name name)
|
|||||||
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
||||||
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) & (~BIT(pin)));
|
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) & (~BIT(pin)));
|
||||||
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) & (~BIT(pin)));
|
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) & (~BIT(pin)));
|
||||||
|
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin))); /*disable pullup*/
|
||||||
|
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin))); /*disable pulldown*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void io_cfg_option2(enum tls_io_name name)
|
static void io_cfg_option2(enum tls_io_name name)
|
||||||
@ -54,6 +56,8 @@ static void io_cfg_option2(enum tls_io_name name)
|
|||||||
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
||||||
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) & (~BIT(pin)));
|
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) & (~BIT(pin)));
|
||||||
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) | BIT(pin));
|
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) | BIT(pin));
|
||||||
|
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin))); /*disable pullup*/
|
||||||
|
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin))); /*disable pulldown*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void io_cfg_option3(enum tls_io_name name)
|
static void io_cfg_option3(enum tls_io_name name)
|
||||||
@ -75,6 +79,8 @@ static void io_cfg_option3(enum tls_io_name name)
|
|||||||
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
||||||
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) | BIT(pin));
|
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) | BIT(pin));
|
||||||
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) & (~BIT(pin)));
|
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) & (~BIT(pin)));
|
||||||
|
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin))); /*disable pullup*/
|
||||||
|
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin))); /*disable pulldown*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void io_cfg_option4(enum tls_io_name name)
|
static void io_cfg_option4(enum tls_io_name name)
|
||||||
@ -96,6 +102,8 @@ static void io_cfg_option4(enum tls_io_name name)
|
|||||||
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) | BIT(pin)); /* gpio function */
|
||||||
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) | BIT(pin));
|
tls_reg_write32(HR_GPIO_AF_S1 + offset, tls_reg_read32(HR_GPIO_AF_S1 + offset) | BIT(pin));
|
||||||
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) | BIT(pin));
|
tls_reg_write32(HR_GPIO_AF_S0 + offset, tls_reg_read32(HR_GPIO_AF_S0 + offset) | BIT(pin));
|
||||||
|
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin))); /*disable pullup*/
|
||||||
|
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin))); /*disable pulldown*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void io_cfg_option5(enum tls_io_name name)
|
static void io_cfg_option5(enum tls_io_name name)
|
||||||
@ -115,6 +123,8 @@ static void io_cfg_option5(enum tls_io_name name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) & (~BIT(pin))); /* disable gpio function */
|
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) & (~BIT(pin))); /* disable gpio function */
|
||||||
|
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin))); /*disable pullup*/
|
||||||
|
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin))); /*disable pulldown*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 io_pa_option67 = 0;
|
static u32 io_pa_option67 = 0;
|
||||||
@ -139,8 +149,8 @@ static void io_cfg_option6(enum tls_io_name name)
|
|||||||
|
|
||||||
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) & (~BIT(pin))); /* disable gpio function */
|
tls_reg_write32(HR_GPIO_AF_SEL + offset, tls_reg_read32(HR_GPIO_AF_SEL + offset) & (~BIT(pin))); /* disable gpio function */
|
||||||
tls_reg_write32(HR_GPIO_DIR + offset, tls_reg_read32(HR_GPIO_DIR + offset) & (~BIT(pin)));
|
tls_reg_write32(HR_GPIO_DIR + offset, tls_reg_read32(HR_GPIO_DIR + offset) & (~BIT(pin)));
|
||||||
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin)));
|
tls_reg_write32(HR_GPIO_PULLUP_EN + offset, tls_reg_read32(HR_GPIO_PULLUP_EN + offset) | (BIT(pin))); /*disable pullup*/
|
||||||
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin)));
|
tls_reg_write32(HR_GPIO_PULLDOWN_EN + offset, tls_reg_read32(HR_GPIO_PULLDOWN_EN + offset) & (~BIT(pin))); /*disable pulldown*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void io_cfg_option7(enum tls_io_name name)
|
static void io_cfg_option7(enum tls_io_name name)
|
||||||
|
|||||||
@ -88,10 +88,11 @@ int wm_sdh_config(void)
|
|||||||
|
|
||||||
tls_sys_clk_get(&sysclk);
|
tls_sys_clk_get(&sysclk);
|
||||||
SDIO_HOST->MMC_CARDSEL = 0xC0 | (sysclk.cpuclk / 2 - 1);//0xd3; //enable module, enable mmcclk
|
SDIO_HOST->MMC_CARDSEL = 0xC0 | (sysclk.cpuclk / 2 - 1);//0xd3; //enable module, enable mmcclk
|
||||||
SDIO_HOST->MMC_CTL = 0xD3;//0xC3; //4bits, low speed, 1/4 divider, auto transfer, mmc mode.
|
SDIO_HOST->MMC_CTL = 0x13;//0xC3; //4bits, low speed, 1/4 divider, auto transfer, mmc mode.
|
||||||
SDIO_HOST->MMC_INT_MASK = 0x100; //unmask sdio data interrupt.
|
SDIO_HOST->MMC_INT_MASK = 0x100; //unmask sdio data interrupt.
|
||||||
SDIO_HOST->MMC_CRCCTL = 0xC0; //
|
SDIO_HOST->MMC_CRCCTL = 0xC0; //
|
||||||
SDIO_HOST->MMC_TIMEOUTCNT = 0xff;
|
SDIO_HOST->MMC_TIMEOUTCNT = 0xff;
|
||||||
|
SDIO_HOST->MMC_IO_MBCTL |= 0xf0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,10 +114,14 @@ int wm_sd_card_initialize(uint32_t *rca)
|
|||||||
// CMD 3 Get RCA.
|
// CMD 3 Get RCA.
|
||||||
//======================================================
|
//======================================================
|
||||||
begin:
|
begin:
|
||||||
wm_sdh_send_cmd(0, 0, 0x04); //Send CMD0
|
//Send CMD0 + 8 null clock to reset and stablize
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
for (int i = 0; i < 7 - recnt; i++)
|
||||||
|
{
|
||||||
|
wm_sdh_send_cmd(0, 0, 0x84);
|
||||||
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
|
}
|
||||||
delay_cnt(1000);
|
delay_cnt(1000);
|
||||||
wm_sdh_send_cmd(8, 0x1AA, 0x44); //Send CMD8
|
wm_sdh_send_cmd(8, 0x1AA, 0xC4); //Send CMD8
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD8 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD8 respCmd", (char *)respCmd, 5);
|
||||||
@ -129,14 +134,14 @@ begin:
|
|||||||
}
|
}
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
wm_sdh_send_cmd(55, 0, 0x44); //Send CMD55
|
wm_sdh_send_cmd(55, 0, 0xC4); //Send CMD55
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD55 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD55 respCmd", (char *)respCmd, 5);
|
||||||
if((respCmd[1] & 0xFF) != 55)
|
if((respCmd[1] & 0xFF) != 55)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
wm_sdh_send_cmd(41, 0xC0100000, 0x44); //Send ACMD41
|
wm_sdh_send_cmd(41, 0xC0100000, 0xC4); //Send ACMD41
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
sm_sdh_wait_interrupt(3, 1000); //由于sd规范中,Acmd41返回的crc永远是11111,也就是应该忽略crc;这里的crc错误应该忽略。
|
sm_sdh_wait_interrupt(3, 1000); //由于sd规范中,Acmd41返回的crc永远是11111,也就是应该忽略crc;这里的crc错误应该忽略。
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
@ -150,14 +155,14 @@ begin:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wm_sdh_send_cmd(2, 0, 0x54); //Send CMD2
|
wm_sdh_send_cmd(2, 0, 0xD4); //Send CMD2
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
sm_sdh_wait_interrupt(3, 1000);
|
sm_sdh_wait_interrupt(3, 1000);
|
||||||
wm_sdh_get_response(respCmd, 4);
|
wm_sdh_get_response(respCmd, 4);
|
||||||
sh_dumpBuffer("CMD2 respCmd", (char *)respCmd, 16);
|
sh_dumpBuffer("CMD2 respCmd", (char *)respCmd, 16);
|
||||||
if((respCmd[3] >> 24 & 0xFF) != 0x3F) //sd规范定义固定为0x3F,所以导致crc错误
|
if((respCmd[3] >> 24 & 0xFF) != 0x3F) //sd规范定义固定为0x3F,所以导致crc错误
|
||||||
goto end;
|
goto end;
|
||||||
wm_sdh_send_cmd(3, 0, 0x44); //Send CMD3
|
wm_sdh_send_cmd(3, 0, 0xC4); //Send CMD3
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD3 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD3 respCmd", (char *)respCmd, 5);
|
||||||
@ -179,6 +184,7 @@ static uint32_t SD_GetCapacity(uint8_t *csd, SD_CardInfo_t *SDCardInfo)
|
|||||||
|
|
||||||
if((csd[0]&0xC0)==0x40)//判断bit126是否为1
|
if((csd[0]&0xC0)==0x40)//判断bit126是否为1
|
||||||
{
|
{
|
||||||
|
SDCardInfo->CSDVer = 2;
|
||||||
csize = csd[9] + ((uint32_t)csd[8] << 8) + ((uint32_t)(csd[7] & 63) << 16) + 1;
|
csize = csd[9] + ((uint32_t)csd[8] << 8) + ((uint32_t)(csd[7] & 63) << 16) + 1;
|
||||||
Capacity = csize << 9;
|
Capacity = csize << 9;
|
||||||
SDCardInfo->CardCapacity = (long long)Capacity*1024;
|
SDCardInfo->CardCapacity = (long long)Capacity*1024;
|
||||||
@ -186,6 +192,7 @@ static uint32_t SD_GetCapacity(uint8_t *csd, SD_CardInfo_t *SDCardInfo)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
SDCardInfo->CSDVer = 1;
|
||||||
n = (csd[5] & 0x0F) + ((csd[10] & 0x80) >> 7) + ((csd[9] & 0x03) << 1) + 2;
|
n = (csd[5] & 0x0F) + ((csd[10] & 0x80) >> 7) + ((csd[9] & 0x03) << 1) + 2;
|
||||||
csize = (csd[8] >> 6) + ((uint16_t)csd[7] << 2) + ((uint16_t)(csd[6] & 0x03) << 10) + 1;
|
csize = (csd[8] >> 6) + ((uint16_t)csd[7] << 2) + ((uint16_t)(csd[6] & 0x03) << 10) + 1;
|
||||||
Capacity = (uint32_t)csize << (n - 10);
|
Capacity = (uint32_t)csize << (n - 10);
|
||||||
@ -219,7 +226,7 @@ int wm_sd_card_set_blocklen(uint32_t blocklen)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
uint32_t respCmd[2];
|
uint32_t respCmd[2];
|
||||||
wm_sdh_send_cmd(16, blocklen, 0x44); //Send CMD16
|
wm_sdh_send_cmd(16, blocklen, 0xC4); //Send CMD16
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD16 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD16 respCmd", (char *)respCmd, 5);
|
||||||
@ -234,7 +241,7 @@ int wm_sd_card_select(uint32_t rca)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
uint32_t respCmd[2];
|
uint32_t respCmd[2];
|
||||||
wm_sdh_send_cmd(7, rca<<16, 0x44); //Send CMD7
|
wm_sdh_send_cmd(7, rca<<16, 0xC4); //Send CMD7
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD7 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD7 respCmd", (char *)respCmd, 5);
|
||||||
@ -247,7 +254,7 @@ end:
|
|||||||
|
|
||||||
void wm_sd_card_deselect()
|
void wm_sd_card_deselect()
|
||||||
{
|
{
|
||||||
wm_sdh_send_cmd(7, 0, 0x04); //Send CMD7
|
wm_sdh_send_cmd(7, 0, 0x84); //Send CMD7
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +266,7 @@ int wm_sd_card_query_status(uint32_t rca, uint32_t *respCmd0)
|
|||||||
uint8_t error_state = 0;
|
uint8_t error_state = 0;
|
||||||
#endif
|
#endif
|
||||||
uint32_t respCmd[2];
|
uint32_t respCmd[2];
|
||||||
wm_sdh_send_cmd(13, rca<<16, 0x44); //Send CMD13
|
wm_sdh_send_cmd(13, rca<<16, 0xC4); //Send CMD13
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD13 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD13 respCmd", (char *)respCmd, 5);
|
||||||
@ -288,7 +295,7 @@ int wm_sd_card_switch_func(uint8_t speed_mode)
|
|||||||
int i;
|
int i;
|
||||||
uint32_t respCmd[2];
|
uint32_t respCmd[2];
|
||||||
|
|
||||||
wm_sdh_send_cmd(6, 0x00fffff1, 0x44); //Send CMD6
|
wm_sdh_send_cmd(6, 0x00fffff1, 0xC4); //Send CMD6
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD6 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD6 respCmd", (char *)respCmd, 5);
|
||||||
@ -296,7 +303,7 @@ int wm_sd_card_switch_func(uint8_t speed_mode)
|
|||||||
goto end;
|
goto end;
|
||||||
SDIO_HOST->BUF_CTL = 0x4020; //disable dma, read sd card
|
SDIO_HOST->BUF_CTL = 0x4020; //disable dma, read sd card
|
||||||
SDIO_HOST->MMC_INT_SRC |= 0x7ff; // clear all firstly
|
SDIO_HOST->MMC_INT_SRC |= 0x7ff; // clear all firstly
|
||||||
SDIO_HOST->MMC_IO = 0x3; //!!!read data, auto transfer
|
SDIO_HOST->MMC_IO = 0x83; //!!!read data, auto transfer
|
||||||
sm_sdh_wait_interrupt(1, -1);
|
sm_sdh_wait_interrupt(1, -1);
|
||||||
TEST_DEBUG("read complete\n");
|
TEST_DEBUG("read complete\n");
|
||||||
for(i = 0; i < 128; i++)
|
for(i = 0; i < 128; i++)
|
||||||
@ -315,7 +322,7 @@ int wm_sd_card_switch_func(uint8_t speed_mode)
|
|||||||
TEST_DEBUG("the value of byte 17~20 is 0x%x\n", respCmd[1]);
|
TEST_DEBUG("the value of byte 17~20 is 0x%x\n", respCmd[1]);
|
||||||
if(respCmd[1] & 0xF) //support high speed
|
if(respCmd[1] & 0xF) //support high speed
|
||||||
{
|
{
|
||||||
wm_sdh_send_cmd(6, 0x80fffff0 | speed_mode, 0x44); //Send CMD6
|
wm_sdh_send_cmd(6, 0x80fffff0 | speed_mode, 0xC4); //Send CMD6
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD6 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD6 respCmd", (char *)respCmd, 5);
|
||||||
@ -323,7 +330,7 @@ int wm_sd_card_switch_func(uint8_t speed_mode)
|
|||||||
goto end;
|
goto end;
|
||||||
SDIO_HOST->BUF_CTL = 0x4020; //disable dma, read sd card
|
SDIO_HOST->BUF_CTL = 0x4020; //disable dma, read sd card
|
||||||
SDIO_HOST->MMC_INT_SRC |= 0x7ff; // clear all firstly
|
SDIO_HOST->MMC_INT_SRC |= 0x7ff; // clear all firstly
|
||||||
SDIO_HOST->MMC_IO = 0x3; //!!!read data, auto transfer
|
SDIO_HOST->MMC_IO = 0x83; //!!!read data, auto transfer
|
||||||
sm_sdh_wait_interrupt(1, -1);
|
sm_sdh_wait_interrupt(1, -1);
|
||||||
TEST_DEBUG("read complete\n");
|
TEST_DEBUG("read complete\n");
|
||||||
for(i = 0; i < 128; i++)
|
for(i = 0; i < 128; i++)
|
||||||
@ -378,13 +385,13 @@ int wm_sd_card_set_bus_width(uint32_t rca, uint8_t bus_width)
|
|||||||
{
|
{
|
||||||
SDIO_HOST->MMC_CTL &= ~(1 << 7);
|
SDIO_HOST->MMC_CTL &= ~(1 << 7);
|
||||||
}
|
}
|
||||||
wm_sdh_send_cmd(55, rca<<16, 0x44); //Send CMD55
|
wm_sdh_send_cmd(55, rca<<16, 0xC4); //Send CMD55
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("CMD55 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("CMD55 respCmd", (char *)respCmd, 5);
|
||||||
if((respCmd[1] & 0xFF) != 55)
|
if((respCmd[1] & 0xFF) != 55)
|
||||||
goto end;
|
goto end;
|
||||||
wm_sdh_send_cmd(6, bus_width, 0x44); //Send ACMD6
|
wm_sdh_send_cmd(6, bus_width, 0xC4); //Send ACMD6
|
||||||
sm_sdh_wait_interrupt(0, -1);
|
sm_sdh_wait_interrupt(0, -1);
|
||||||
wm_sdh_get_response(respCmd, 2);
|
wm_sdh_get_response(respCmd, 2);
|
||||||
sh_dumpBuffer("ACMD6 respCmd", (char *)respCmd, 5);
|
sh_dumpBuffer("ACMD6 respCmd", (char *)respCmd, 5);
|
||||||
@ -399,7 +406,7 @@ int wm_sd_card_stop_trans(void)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
uint32_t respCmd[2];
|
uint32_t respCmd[2];
|
||||||
wm_sdh_send_cmd(12, 0, 0x44); //Send CMD12
|
wm_sdh_send_cmd(12, 0, 0xC4); //Send CMD12
|
||||||
ret = sm_sdh_wait_interrupt(0, -1);
|
ret = sm_sdh_wait_interrupt(0, -1);
|
||||||
if(ret)
|
if(ret)
|
||||||
goto end;
|
goto end;
|
||||||
@ -415,7 +422,7 @@ end:
|
|||||||
static void sdio_host_reset(void)
|
static void sdio_host_reset(void)
|
||||||
{
|
{
|
||||||
tls_bitband_write(HR_CLK_RST_CTL, 27, 0);
|
tls_bitband_write(HR_CLK_RST_CTL, 27, 0);
|
||||||
|
delay_cnt(1000);
|
||||||
tls_bitband_write(HR_CLK_RST_CTL, 27, 1);
|
tls_bitband_write(HR_CLK_RST_CTL, 27, 1);
|
||||||
while(tls_bitband_read(HR_CLK_RST_CTL, 27) == 0);
|
while(tls_bitband_read(HR_CLK_RST_CTL, 27) == 0);
|
||||||
}
|
}
|
||||||
@ -431,6 +438,7 @@ int sdh_card_init(uint32_t *rca_ref)
|
|||||||
ret = wm_sd_card_initialize(&rca);
|
ret = wm_sd_card_initialize(&rca);
|
||||||
if(ret)
|
if(ret)
|
||||||
goto end;
|
goto end;
|
||||||
|
SDCardInfo.RCA = (u16)(rca & 0xFFFF);
|
||||||
ret = wm_sd_card_query_csd(rca);
|
ret = wm_sd_card_query_csd(rca);
|
||||||
if(ret)
|
if(ret)
|
||||||
goto end;
|
goto end;
|
||||||
@ -444,6 +452,8 @@ int sdh_card_init(uint32_t *rca_ref)
|
|||||||
if(ret)
|
if(ret)
|
||||||
goto end;
|
goto end;
|
||||||
*rca_ref = rca;
|
*rca_ref = rca;
|
||||||
|
|
||||||
|
SDIO_HOST->MMC_CTL = 0xD3;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
end:
|
end:
|
||||||
TEST_DEBUG("ret %d\n", ret);
|
TEST_DEBUG("ret %d\n", ret);
|
||||||
|
|||||||
@ -606,7 +606,7 @@ ATTRIBUTE_ISR void UART0_IRQHandler(void)
|
|||||||
port->rx_callback(1, port->priv_data);
|
port->rx_callback(1, port->priv_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (port->rx_callback != NULL && !rx_byte_cb_flag)
|
if (rxlen && port->rx_callback != NULL && !rx_byte_cb_flag)
|
||||||
{
|
{
|
||||||
port->rx_callback(rxlen, port->priv_data);
|
port->rx_callback(rxlen, port->priv_data);
|
||||||
}
|
}
|
||||||
@ -693,6 +693,10 @@ ATTRIBUTE_ISR void UART1_IRQHandler(void)
|
|||||||
ch = (u8) port->regs->UR_RXW;
|
ch = (u8) port->regs->UR_RXW;
|
||||||
recv->buf[recv->head] = ch;
|
recv->buf[recv->head] = ch;
|
||||||
recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
|
recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
|
||||||
|
if(port->rx_callback != NULL && rx_byte_cb_flag)
|
||||||
|
{
|
||||||
|
port->rx_callback(1, port->priv_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,10 +717,6 @@ ATTRIBUTE_ISR void UART1_IRQHandler(void)
|
|||||||
port->plus_char_cnt = 3;
|
port->plus_char_cnt = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(rxlen && port->rx_callback != NULL && rx_byte_cb_flag)
|
|
||||||
{
|
|
||||||
port->rx_callback(1, port->priv_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (rxlen && port->rx_callback!=NULL && !rx_byte_cb_flag)
|
if (rxlen && port->rx_callback!=NULL && !rx_byte_cb_flag)
|
||||||
{
|
{
|
||||||
@ -798,6 +798,10 @@ ATTRIBUTE_ISR void UART2_4_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
recv->buf[recv->head] = ch;
|
recv->buf[recv->head] = ch;
|
||||||
recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
|
recv->head = (recv->head + 1) & (TLS_UART_RX_BUF_SIZE - 1);
|
||||||
|
if(port->rx_callback != NULL && rx_byte_cb_flag)
|
||||||
|
{
|
||||||
|
port->rx_callback(1, port->priv_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( escapefifocnt==3 && ch=='+')
|
if( escapefifocnt==3 && ch=='+')
|
||||||
@ -817,12 +821,8 @@ ATTRIBUTE_ISR void UART2_4_IRQHandler(void)
|
|||||||
port->plus_char_cnt = 3;
|
port->plus_char_cnt = 3;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(port->rx_callback != NULL && rx_byte_cb_flag)
|
|
||||||
{
|
|
||||||
port->rx_callback(1, port->priv_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (port->rx_callback!=NULL && !rx_byte_cb_flag)
|
if (rxlen && port->rx_callback!=NULL && !rx_byte_cb_flag)
|
||||||
{
|
{
|
||||||
port->rx_callback(rxlen, port->priv_data);
|
port->rx_callback(rxlen, port->priv_data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -419,6 +419,7 @@ int tls_wl_if_sta_add(struct tls_wif *wif,
|
|||||||
int tls_wl_if_sta_remove(struct tls_wif *wif, u8 *addr);
|
int tls_wl_if_sta_remove(struct tls_wif *wif, u8 *addr);
|
||||||
int tls_wl_if_get_inact_sec(struct tls_wif *wif, const u8 *addr);
|
int tls_wl_if_get_inact_sec(struct tls_wif *wif, const u8 *addr);
|
||||||
int tls_wl_if_get_scan_res(struct tls_wif *wif, u8 *buf, u32 buf_size);
|
int tls_wl_if_get_scan_res(struct tls_wif *wif, u8 *buf, u32 buf_size);
|
||||||
|
int tls_wl_if_get_scan_res_format2(struct tls_wif *wif, u8 *buf, u32 buf_size);
|
||||||
int tls_wl_if_disconnect(struct tls_wif *wif);
|
int tls_wl_if_disconnect(struct tls_wif *wif);
|
||||||
int tls_wl_if_tx(struct tls_wif *wif,
|
int tls_wl_if_tx(struct tls_wif *wif,
|
||||||
u8 *buf, u32 buflen, bool last_packet, bool is_apsta, bool not_delay);
|
u8 *buf, u32 buflen, bool last_packet, bool is_apsta, bool not_delay);
|
||||||
|
|||||||
@ -35,5 +35,7 @@ char * strdup(const char *s);
|
|||||||
char * strndup(const char *s, size_t len);
|
char * strndup(const char *s, size_t len);
|
||||||
|
|
||||||
int sendchar(int ch);
|
int sendchar(int ch);
|
||||||
|
void dumpBuffer(char *name, char* buffer, int len);
|
||||||
|
void dumpUint32(char *name, u32* buffer, int len);
|
||||||
|
|
||||||
#endif /* UTILS_H */
|
#endif /* UTILS_H */
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
#include "wm_watchdog.h"
|
#include "wm_watchdog.h"
|
||||||
#include "wm_wifi.h"
|
#include "wm_wifi.h"
|
||||||
#if TLS_CONFIG_ONLY_FACTORY_ATCMD
|
#if TLS_CONFIG_ONLY_FACTORY_ATCMD
|
||||||
#include "factory_atcmd.h"
|
#include "../../src/app/factorycmd/factory_atcmd.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* c librayr mutex */
|
/* c librayr mutex */
|
||||||
@ -101,7 +101,7 @@ tls_os_task_t tstusermainhdl = NULL;
|
|||||||
|
|
||||||
#define FW_MAJOR_VER 0x1
|
#define FW_MAJOR_VER 0x1
|
||||||
#define FW_MINOR_VER 0x0
|
#define FW_MINOR_VER 0x0
|
||||||
#define FW_PATCH_VER 0x8
|
#define FW_PATCH_VER 0x10
|
||||||
|
|
||||||
const char FirmWareVer[4] =
|
const char FirmWareVer[4] =
|
||||||
{
|
{
|
||||||
|
|||||||
@ -168,7 +168,7 @@ static int bt_aes_decrypt(uint8_t *key, uint8_t *src_ptr, int length, uint8_t *d
|
|||||||
psCipherContext_t ctx;
|
psCipherContext_t ctx;
|
||||||
uint8_t *buf = NULL;
|
uint8_t *buf = NULL;
|
||||||
TLS_DBGPRT_INFO("original data:");
|
TLS_DBGPRT_INFO("original data:");
|
||||||
TLS_DBGPRT_DUMP(src_ptr, length);
|
TLS_DBGPRT_DUMP((char *)src_ptr, length);
|
||||||
|
|
||||||
if(key == NULL || src_ptr == NULL || length % 16 != 0) {
|
if(key == NULL || src_ptr == NULL || length % 16 != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
@ -182,7 +182,7 @@ static int bt_aes_decrypt(uint8_t *key, uint8_t *src_ptr, int length, uint8_t *d
|
|||||||
|
|
||||||
MEMCPY(buf, src_ptr, length);
|
MEMCPY(buf, src_ptr, length);
|
||||||
TLS_DBGPRT_INFO("aes key:");
|
TLS_DBGPRT_INFO("aes key:");
|
||||||
TLS_DBGPRT_DUMP(key, 16);
|
TLS_DBGPRT_DUMP((char *)key, 16);
|
||||||
|
|
||||||
if(tls_crypto_aes_init(&ctx, key, key, 16, CRYPTO_MODE_ECB) != 0) {
|
if(tls_crypto_aes_init(&ctx, key, key, 16, CRYPTO_MODE_ECB) != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
@ -194,7 +194,7 @@ static int bt_aes_decrypt(uint8_t *key, uint8_t *src_ptr, int length, uint8_t *d
|
|||||||
|
|
||||||
MEMCPY(dest_ptr, buf, length);
|
MEMCPY(dest_ptr, buf, length);
|
||||||
TLS_DBGPRT_INFO("decrypt data:");
|
TLS_DBGPRT_INFO("decrypt data:");
|
||||||
TLS_DBGPRT_DUMP(dest_ptr, length);
|
TLS_DBGPRT_DUMP((char *)dest_ptr, length);
|
||||||
ret = DePKCS7Padding(dest_ptr, length);
|
ret = DePKCS7Padding(dest_ptr, length);
|
||||||
out:
|
out:
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ static int bt_aes_encrypt(uint8_t *key, uint8_t *src_ptr, int length, uint8_t *d
|
|||||||
psCipherContext_t ctx;
|
psCipherContext_t ctx;
|
||||||
unsigned char *aes_encode_temp = NULL;
|
unsigned char *aes_encode_temp = NULL;
|
||||||
TLS_DBGPRT_INFO("original data:");
|
TLS_DBGPRT_INFO("original data:");
|
||||||
TLS_DBGPRT_DUMP(src_ptr, length);
|
TLS_DBGPRT_DUMP((char *)src_ptr, length);
|
||||||
aes_encode_temp = tls_mem_alloc(length + 16);
|
aes_encode_temp = tls_mem_alloc(length + 16);
|
||||||
|
|
||||||
if(aes_encode_temp == NULL) {
|
if(aes_encode_temp == NULL) {
|
||||||
@ -264,7 +264,7 @@ static int bt_aes_encrypt(uint8_t *key, uint8_t *src_ptr, int length, uint8_t *d
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TLS_DBGPRT_INFO("encrypt data:");
|
//TLS_DBGPRT_INFO("encrypt data:");
|
||||||
TLS_DBGPRT_DUMP(dest_ptr, len);
|
TLS_DBGPRT_DUMP((char *)dest_ptr, len);
|
||||||
ret = len;
|
ret = len;
|
||||||
out:
|
out:
|
||||||
|
|
||||||
|
|||||||
@ -327,7 +327,7 @@ static int ble_uart_init(int8_t uart_idx, int bandrate, int parity, int stopbits
|
|||||||
wm_uart_task,
|
wm_uart_task,
|
||||||
(void *) wm_uart,
|
(void *) wm_uart,
|
||||||
(void *) wm_uart_task_stk, /** 任务栈的起始地址 */
|
(void *) wm_uart_task_stk, /** 任务栈的起始地址 */
|
||||||
WM_UART_TAST_STK_SIZE, /** 任务栈的大小 */
|
WM_UART_TAST_STK_SIZE*4, /** 任务栈的大小 */
|
||||||
WM_UART_TASK_PRIO, 0);
|
WM_UART_TASK_PRIO, 0);
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
status = tls_os_queue_create(&(wm_uart->wm_queue_msg_available), 6);
|
status = tls_os_queue_create(&(wm_uart->wm_queue_msg_available), 6);
|
||||||
@ -336,7 +336,7 @@ static int ble_uart_init(int8_t uart_idx, int bandrate, int parity, int stopbits
|
|||||||
wm_dispatch_task,
|
wm_dispatch_task,
|
||||||
(void *) wm_uart,
|
(void *) wm_uart,
|
||||||
(void *) wm_disp_task_stk, /** 任务栈的起始地址 */
|
(void *) wm_disp_task_stk, /** 任务栈的起始地址 */
|
||||||
WM_DISP_TAST_STK_SIZE, /** 任务栈的大小 */
|
WM_DISP_TAST_STK_SIZE*4, /** 任务栈的大小 */
|
||||||
WM_UART_TASK_PRIO+1, 0);
|
WM_UART_TASK_PRIO+1, 0);
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "tls_common.h"
|
|
||||||
#include "wm_mem.h"
|
#include "wm_mem.h"
|
||||||
#include "wm_debug.h"
|
#include "wm_debug.h"
|
||||||
#include "lwip/stats.h"
|
#include "lwip/stats.h"
|
||||||
@ -25,6 +24,8 @@
|
|||||||
#include "lwip/prot/dhcp.h"
|
#include "lwip/prot/dhcp.h"
|
||||||
#include "netif/ethernetif.h"
|
#include "netif/ethernetif.h"
|
||||||
#include "dhcp_server.h"
|
#include "dhcp_server.h"
|
||||||
|
#include "tls_common.h"
|
||||||
|
#include "wm_wifi.h"
|
||||||
|
|
||||||
#if TLS_CONFIG_AP
|
#if TLS_CONFIG_AP
|
||||||
|
|
||||||
@ -36,7 +37,7 @@
|
|||||||
extern u8 *wpa_supplicant_get_mac(void);
|
extern u8 *wpa_supplicant_get_mac(void);
|
||||||
|
|
||||||
|
|
||||||
/* 是否根据客户端dhcp报文中的broadcast标志来回应,不使用则统一使用广播回复 */
|
/* 是否根据客户端dhcp报文中的broadcast标志来回应,不使用则统一使用广播回复 */
|
||||||
#define DHCPS_CHECK_BROADCAST_FLAG
|
#define DHCPS_CHECK_BROADCAST_FLAG
|
||||||
#ifdef DHCPS_CHECK_BROADCAST_FLAG
|
#ifdef DHCPS_CHECK_BROADCAST_FLAG
|
||||||
#define IS_BROADCAST_SEND(x) (((x) >> 15) == 1 ? TRUE : FALSE)
|
#define IS_BROADCAST_SEND(x) (((x) >> 15) == 1 ? TRUE : FALSE)
|
||||||
@ -158,7 +159,7 @@ static bool _CheckMacIsValid(u8 *mac)
|
|||||||
|
|
||||||
sta_buf = tls_mem_alloc(STA_MAC_BUF_LEN);
|
sta_buf = tls_mem_alloc(STA_MAC_BUF_LEN);
|
||||||
if (!sta_buf)
|
if (!sta_buf)
|
||||||
return FALSE;/* 系统资源不足,无需再让client接入 */
|
return FALSE;/* 系统资源不足,无需再让client接入 */
|
||||||
|
|
||||||
memset(sta_buf, 0, STA_MAC_BUF_LEN);
|
memset(sta_buf, 0, STA_MAC_BUF_LEN);
|
||||||
tls_wifi_get_authed_sta_info(&sta_num, sta_buf, STA_MAC_BUF_LEN);
|
tls_wifi_get_authed_sta_info(&sta_num, sta_buf, STA_MAC_BUF_LEN);
|
||||||
@ -167,7 +168,7 @@ static bool _CheckMacIsValid(u8 *mac)
|
|||||||
{
|
{
|
||||||
if (!compare_ether_addr(mac, sta->mac_addr))
|
if (!compare_ether_addr(mac, sta->mac_addr))
|
||||||
{
|
{
|
||||||
ret = TRUE;/* 本SOFTAP下的client才予以分配IP */
|
ret = TRUE;/* 本SOFTAP下的client才予以分配IP */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sta++;
|
sta++;
|
||||||
@ -1134,7 +1135,8 @@ INT8S DHCPS_Start(struct netif *Netif)
|
|||||||
udp_bind(DhcpServer->Socket, IP_ADDR_ANY, DHCP_SERVER_UDP_PORT);
|
udp_bind(DhcpServer->Socket, IP_ADDR_ANY, DHCP_SERVER_UDP_PORT);
|
||||||
|
|
||||||
/* bind multicast&broadcast netif */
|
/* bind multicast&broadcast netif */
|
||||||
udp_bind_multicast_netif(DhcpServer->Socket, &Netif->ip_addr);
|
//udp_bind_multicast_netif(DhcpServer->Socket, &Netif->ip_addr);
|
||||||
|
udp_set_multicast_netif_addr(DhcpServer->Socket, &Netif->ip_addr);
|
||||||
|
|
||||||
/* Set up the recv callback and argument. */
|
/* Set up the recv callback and argument. */
|
||||||
udp_recv(DhcpServer->Socket, (udp_recv_fn)DHCPS_RecvCb, Netif);
|
udp_recv(DhcpServer->Socket, (udp_recv_fn)DHCPS_RecvCb, Netif);
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
#include "wm_internal_flash.h"
|
#include "wm_internal_flash.h"
|
||||||
#include "litepoint.h"
|
#include "litepoint.h"
|
||||||
#include "wm_ram_config.h"
|
#include "wm_ram_config.h"
|
||||||
|
#include "wm_adc.h"
|
||||||
|
#include "wm_gpio_afsel.h"
|
||||||
|
|
||||||
#define FACTORY_ATCMD_MAX_ARG 10
|
#define FACTORY_ATCMD_MAX_ARG 10
|
||||||
#define FACTORY_ATCMD_NAME_MAX_LEN 10
|
#define FACTORY_ATCMD_NAME_MAX_LEN 10
|
||||||
@ -523,7 +525,7 @@ static int factory_atcmd_txgi_proc( struct factory_atcmd_token_t *tok, char *res
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/*<EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>ӳflash<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʴ洢<EFBFBD><EFBFBD><EFBFBD>*/
|
/*如实反映flash参数区的实际存储情况*/
|
||||||
ret = tls_get_tx_gain(tx_gain);
|
ret = tls_get_tx_gain(tx_gain);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
@ -842,6 +844,102 @@ static int factory_atcmd_qver_proc( struct factory_atcmd_token_t *tok, char *res
|
|||||||
__DATE__, __TIME__);
|
__DATE__, __TIME__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
static int factory_atcmd_test_mode_proc( struct factory_atcmd_token_t *tok, char *res_resp, u32 *res_len)
|
||||||
|
{
|
||||||
|
wm_adc_config(0);
|
||||||
|
wm_adc_config(1);
|
||||||
|
wm_adc_config(2);
|
||||||
|
wm_adc_config(3);
|
||||||
|
*res_len = factory_atcmd_ok_resp(res_resp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int factory_atcmd_adc_cal_proc( struct factory_atcmd_token_t *tok, char *res_resp, u32 *res_len)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int val = 0;
|
||||||
|
int i = 0;
|
||||||
|
int refvoltage[4] = {0};
|
||||||
|
FT_ADC_CAL_ST adc_cal;
|
||||||
|
|
||||||
|
if (tok->arg_found)
|
||||||
|
{
|
||||||
|
if (tok->arg_found < 5)
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_err_resp(res_resp, FACTORY_ATCMD_ERR_INV_PARAMS);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ret = strtodec(&val, tok->arg[0]);
|
||||||
|
if (ret < 0 || val > 15 || val < 1)
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_err_resp(res_resp, FACTORY_ATCMD_ERR_INV_PARAMS);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for(i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
ret = strtodec(&refvoltage[i], tok->arg[i + 1]);
|
||||||
|
if (ret < 0 )
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_err_resp(res_resp, FACTORY_ATCMD_ERR_INV_PARAMS);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = adc_multipoint_calibration(val, refvoltage);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_ok_resp(res_resp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_err_resp(res_resp, FACTORY_ATCMD_ERR_FLASH);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = tls_get_adc_cal_param(&adc_cal);
|
||||||
|
//dumpBuffer("&adc_cal", &adc_cal, sizeof(adc_cal));
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
*res_len = sprintf(res_resp, "+OK=%lf,%lf\r\n", adc_cal.a, adc_cal.b);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_err_resp(res_resp,FACTORY_ATCMD_ERR_FLASH);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int factory_atcmd_adc_vol_proc( struct factory_atcmd_token_t *tok, char *res_resp, u32 *res_len)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int val = 0xF;
|
||||||
|
int i = 0;
|
||||||
|
int voltage[4] = {0};
|
||||||
|
|
||||||
|
if (tok->arg_found)
|
||||||
|
{
|
||||||
|
ret = strtodec(&val, tok->arg[0]);
|
||||||
|
if (ret < 0 || val > 15 || val < 1)
|
||||||
|
{
|
||||||
|
*res_len = factory_atcmd_err_resp(res_resp, FACTORY_ATCMD_ERR_INV_PARAMS);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (val & (1 << i))
|
||||||
|
{
|
||||||
|
wm_adc_config(i);
|
||||||
|
voltage[i] = adc_get_inputVolt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*res_len = sprintf(res_resp, "+OK=%d,%d,%d,%d\r\n", voltage[0], voltage[1], voltage[2], voltage[3]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct factory_atcmd_t factory_atcmd_tbl[] =
|
static struct factory_atcmd_t factory_atcmd_tbl[] =
|
||||||
@ -869,6 +967,9 @@ static struct factory_atcmd_t factory_atcmd_tbl[] =
|
|||||||
{ "&LPRSTT", factory_atcmd_lprstt_proc},
|
{ "&LPRSTT", factory_atcmd_lprstt_proc},
|
||||||
{ "&CALFIN", factory_atcmd_calfinish_proc},
|
{ "&CALFIN", factory_atcmd_calfinish_proc},
|
||||||
{ "FREQ", factory_atcmd_freq_err_proc},
|
{ "FREQ", factory_atcmd_freq_err_proc},
|
||||||
|
{ "&TESTM", factory_atcmd_test_mode_proc},
|
||||||
|
{ "&ADCCAL", factory_atcmd_adc_cal_proc},
|
||||||
|
{ "&ADCVOL", factory_atcmd_adc_vol_proc},
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1171,7 +1272,7 @@ void factory_atcmd_init(void)
|
|||||||
|
|
||||||
tls_uart_port_init(TLS_UART_0, NULL, 0);
|
tls_uart_port_init(TLS_UART_0, NULL, 0);
|
||||||
|
|
||||||
tls_os_task_create(NULL,"atcmd",factory_atcmd_thread_handle,NULL,(u8 *)factory_atcmd_stack,FACTORY_ATCMD_STACK_SIZE,50,0);
|
tls_os_task_create(NULL,NULL,factory_atcmd_thread_handle,NULL,(u8 *)factory_atcmd_stack,FACTORY_ATCMD_STACK_SIZE,50,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1859,7 +1859,10 @@ static UINT32 HTTPIntrnConnectionOpen (P_HTTP_SESSION pHTTPSession)
|
|||||||
(HTTP_SOCKADDR*)&ServerAddress, // Server address
|
(HTTP_SOCKADDR*)&ServerAddress, // Server address
|
||||||
sizeof(HTTP_SOCKADDR)); // Length of server address structure
|
sizeof(HTTP_SOCKADDR)); // Length of server address structure
|
||||||
// The socket was set to be asyn so we should check the error being returned from connect()
|
// The socket was set to be asyn so we should check the error being returned from connect()
|
||||||
nRetCode = SocketGetErr(pHTTPSession->HttpConnection.HttpSocket);
|
if(nRetCode)
|
||||||
|
{
|
||||||
|
nRetCode = SocketGetErr(pHTTPSession->HttpConnection.HttpSocket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nRetCode == 0 || nRetCode == HTTP_EWOULDBLOCK || nRetCode == HTTP_EINPROGRESS)
|
if(nRetCode == 0 || nRetCode == HTTP_EWOULDBLOCK || nRetCode == HTTP_EINPROGRESS)
|
||||||
@ -1876,6 +1879,7 @@ static UINT32 HTTPIntrnConnectionOpen (P_HTTP_SESSION pHTTPSession)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//printf("%s: nRetCode %d\n", __func__, nRetCode);
|
||||||
// Socket connection problem
|
// Socket connection problem
|
||||||
nRetCode = HTTP_CLIENT_ERROR_SOCKET_CONNECT;
|
nRetCode = HTTP_CLIENT_ERROR_SOCKET_CONNECT;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
#include "lwip/arch.h"
|
|
||||||
#include "HTTPClientWrapper.h"
|
#include "HTTPClientWrapper.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "wm_osal.h"
|
#include "wm_osal.h"
|
||||||
@ -908,6 +907,7 @@ int HTTPWrapperSSLConnect(tls_ssl_t **ssl_p,int fd,const struct sockaddr *name,i
|
|||||||
/* OPTIONAL is not optimal for security,
|
/* OPTIONAL is not optimal for security,
|
||||||
* but makes interop easier in this simplified example */
|
* but makes interop easier in this simplified example */
|
||||||
mbedtls_ssl_conf_authmode( &ssl->conf, MBEDTLS_SSL_VERIFY_NONE );
|
mbedtls_ssl_conf_authmode( &ssl->conf, MBEDTLS_SSL_VERIFY_NONE );
|
||||||
|
//mbedtls_ssl_conf_authmode( &ssl->conf, MBEDTLS_SSL_VERIFY_REQUIRED);
|
||||||
#if MBEDTLS_DEMO_USE_CERT
|
#if MBEDTLS_DEMO_USE_CERT
|
||||||
mbedtls_ssl_conf_ca_chain( &ssl->conf, &ssl->cacert, NULL );
|
mbedtls_ssl_conf_ca_chain( &ssl->conf, &ssl->cacert, NULL );
|
||||||
#endif
|
#endif
|
||||||
@ -917,6 +917,8 @@ int HTTPWrapperSSLConnect(tls_ssl_t **ssl_p,int fd,const struct sockaddr *name,i
|
|||||||
mbedtls_ssl_conf_dbg( &ssl->conf, ssl_client_debug, stdout );
|
mbedtls_ssl_conf_dbg( &ssl->conf, ssl_client_debug, stdout );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
mbedtls_ssl_conf_read_timeout( &ssl->conf, 5000 );
|
||||||
|
|
||||||
if( ( ret = mbedtls_ssl_setup( &ssl->ssl, &ssl->conf ) ) != 0 )
|
if( ( ret = mbedtls_ssl_setup( &ssl->ssl, &ssl->conf ) ) != 0 )
|
||||||
{
|
{
|
||||||
mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
|
mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
|
||||||
@ -929,7 +931,8 @@ int HTTPWrapperSSLConnect(tls_ssl_t **ssl_p,int fd,const struct sockaddr *name,i
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_ssl_set_bio( &ssl->ssl, &ssl->server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
//mbedtls_ssl_set_bio( &ssl->ssl, &ssl->server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||||
|
mbedtls_ssl_set_bio( &ssl->ssl, &ssl->server_fd, mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 4. Handshake
|
* 4. Handshake
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#define HTTP_CLIENT_WRAPPER
|
#define HTTP_CLIENT_WRAPPER
|
||||||
|
|
||||||
#include "wm_config.h"
|
#include "wm_config.h"
|
||||||
|
#include "lwip/opt.h"
|
||||||
#include "lwip/arch.h"
|
#include "lwip/arch.h"
|
||||||
|
|
||||||
#if TLS_CONFIG_HTTP_CLIENT_SECURE
|
#if TLS_CONFIG_HTTP_CLIENT_SECURE
|
||||||
|
|||||||
@ -2210,17 +2210,15 @@ iperf_init_stream(struct iperf_stream *sp, struct iperf_test *test)
|
|||||||
}
|
}
|
||||||
/* Set IP TOS */
|
/* Set IP TOS */
|
||||||
if ((opt = test->settings->tos)!=0) {
|
if ((opt = test->settings->tos)!=0) {
|
||||||
if (test->settings->domain == AF_INET6) {
|
|
||||||
#ifdef IPV6_TCLASS
|
#ifdef IPV6_TCLASS
|
||||||
|
if (test->settings->domain == AF_INET6) {
|
||||||
if (setsockopt(sp->socket, IPPROTO_IPV6, IPV6_TCLASS, &opt, sizeof(opt)) < 0) {
|
if (setsockopt(sp->socket, IPPROTO_IPV6, IPV6_TCLASS, &opt, sizeof(opt)) < 0) {
|
||||||
i_errno = IESETCOS;
|
i_errno = IESETCOS;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
#else
|
} else
|
||||||
i_errno = IESETCOS;
|
|
||||||
return (-1);
|
|
||||||
#endif
|
#endif
|
||||||
} else {
|
{
|
||||||
if (setsockopt(sp->socket, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)) < 0) {
|
if (setsockopt(sp->socket, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)) < 0) {
|
||||||
i_errno = IESETTOS;
|
i_errno = IESETTOS;
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <wm_sockets.h>
|
#include <wm_sockets.h>
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
|
||||||
static int poll ( struct lws_pollfd * fds, unsigned int nfds, int timeout)
|
static int _poll ( struct lws_pollfd * fds, unsigned int nfds, int timeout)
|
||||||
{
|
{
|
||||||
int ret, i, max_fd=0;
|
int ret, i, max_fd=0;
|
||||||
fd_set readset, writeset;
|
fd_set readset, writeset;
|
||||||
@ -70,7 +70,7 @@ LWS_VISIBLE int lws_send_pipe_choked(struct lws *wsi)
|
|||||||
fds.events = POLLOUT;
|
fds.events = POLLOUT;
|
||||||
fds.revents = 0;
|
fds.revents = 0;
|
||||||
|
|
||||||
if (poll(&fds, 1, 0) != 1)
|
if (_poll(&fds, 1, 0) != 1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if ((fds.revents & POLLOUT) == 0)
|
if ((fds.revents & POLLOUT) == 0)
|
||||||
@ -84,7 +84,7 @@ LWS_VISIBLE int lws_send_pipe_choked(struct lws *wsi)
|
|||||||
LWS_VISIBLE int
|
LWS_VISIBLE int
|
||||||
lws_poll_listen_fd(struct lws_pollfd *fd)
|
lws_poll_listen_fd(struct lws_pollfd *fd)
|
||||||
{
|
{
|
||||||
return poll(fd, 1, 0);
|
return _poll(fd, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -129,7 +129,7 @@ lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
|
|||||||
timeout_ms = 0;
|
timeout_ms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = poll(pt->fds, pt->fds_count, timeout_ms);
|
n = _poll(pt->fds, pt->fds_count, timeout_ms);
|
||||||
|
|
||||||
#if 0//def LWS_OPENSSL_SUPPORT
|
#if 0//def LWS_OPENSSL_SUPPORT
|
||||||
if (!pt->rx_draining_ext_list &&
|
if (!pt->rx_draining_ext_list &&
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include "lwip/opt.h"
|
||||||
#include "lwip/arch.h"
|
#include "lwip/arch.h"
|
||||||
#include "wm_osal.h"
|
#include "wm_osal.h"
|
||||||
//#include <ctype.h>
|
//#include <ctype.h>
|
||||||
|
|||||||
@ -149,6 +149,7 @@
|
|||||||
#include "APSCommonServices.h"
|
#include "APSCommonServices.h"
|
||||||
#include "lwip/sockets.h"
|
#include "lwip/sockets.h"
|
||||||
#include "wm_sockets.h"
|
#include "wm_sockets.h"
|
||||||
|
#include "wm_netif.h"
|
||||||
#include "lwip/inet.h"
|
#include "lwip/inet.h"
|
||||||
#include "lwip/igmp.h"
|
#include "lwip/igmp.h"
|
||||||
#include <time.h> // platform support for UTC time
|
#include <time.h> // platform support for UTC time
|
||||||
|
|||||||
@ -2733,6 +2733,10 @@
|
|||||||
|
|
||||||
/* Platform options */
|
/* Platform options */
|
||||||
//#define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
|
//#define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
|
||||||
|
#if WM_MEM_DEBUG
|
||||||
|
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
|
||||||
|
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
|
||||||
|
#else
|
||||||
#ifdef tls_mem_calloc
|
#ifdef tls_mem_calloc
|
||||||
#define MBEDTLS_PLATFORM_STD_CALLOC tls_mem_calloc /**< Default allocator to use, can be undefined */
|
#define MBEDTLS_PLATFORM_STD_CALLOC tls_mem_calloc /**< Default allocator to use, can be undefined */
|
||||||
#define MBEDTLS_PLATFORM_STD_FREE tls_mem_free /**< Default free to use, can be undefined */
|
#define MBEDTLS_PLATFORM_STD_FREE tls_mem_free /**< Default free to use, can be undefined */
|
||||||
@ -2740,6 +2744,7 @@
|
|||||||
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
|
#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
|
||||||
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
|
#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
//#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
|
//#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
|
||||||
//#define MBEDTLS_PLATFORM_STD_TIME tls_os_get_time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
|
//#define MBEDTLS_PLATFORM_STD_TIME tls_os_get_time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
|
||||||
//#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
|
//#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
|
||||||
|
|||||||
@ -292,7 +292,7 @@ int mqtt_connect(mqtt_broker_handle_t* broker)
|
|||||||
memcpy(packet+offset, broker->password, passwordlen);
|
memcpy(packet+offset, broker->password, passwordlen);
|
||||||
offset += passwordlen;
|
offset += passwordlen;
|
||||||
}
|
}
|
||||||
|
//dumpBuffer("conn packet", packet, packetLen);
|
||||||
ret = broker->mqttsend(broker->socketid, packet, packetLen);
|
ret = broker->mqttsend(broker->socketid, packet, packetLen);
|
||||||
if(ret < packetLen) {
|
if(ret < packetLen) {
|
||||||
tls_mem_free(fixed_header);
|
tls_mem_free(fixed_header);
|
||||||
@ -475,6 +475,24 @@ int mqtt_pubrel(mqtt_broker_handle_t* broker, uint16_t message_id) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int encode_length(int length, uint8_t *buf)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
buf[ret] = (uint8_t)(length % 0x80);
|
||||||
|
length /= 0x80;
|
||||||
|
if(length > 0)
|
||||||
|
{
|
||||||
|
buf[ret] |= 0x80;
|
||||||
|
}
|
||||||
|
ret++;
|
||||||
|
}while(length > 0);
|
||||||
|
|
||||||
|
//dumpBuffer("encode_length", buf, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int mqtt_subscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t* message_id) {
|
int mqtt_subscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t* message_id) {
|
||||||
uint16_t topiclen = strlen(topic);
|
uint16_t topiclen = strlen(topic);
|
||||||
|
|
||||||
@ -483,7 +501,8 @@ int mqtt_subscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t* me
|
|||||||
uint8_t *packet=NULL;
|
uint8_t *packet=NULL;
|
||||||
int utf_topicLen;
|
int utf_topicLen;
|
||||||
int packetLen;
|
int packetLen;
|
||||||
uint8_t fixed_header[2];
|
uint8_t fixed_header[6];
|
||||||
|
int fixed_header_len;
|
||||||
|
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
|
|
||||||
@ -514,11 +533,13 @@ int mqtt_subscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t* me
|
|||||||
/********************add by alex***********************/
|
/********************add by alex***********************/
|
||||||
// Fixed header
|
// Fixed header
|
||||||
fixed_header[0] = MQTT_MSG_SUBSCRIBE | MQTT_QOS1_FLAG;
|
fixed_header[0] = MQTT_MSG_SUBSCRIBE | MQTT_QOS1_FLAG;
|
||||||
fixed_header[1] = sizeof(var_header)+utf_topicLen;
|
//fixed_header[1] = sizeof(var_header)+utf_topicLen;
|
||||||
|
fixed_header_len = encode_length(sizeof(var_header)+utf_topicLen, &fixed_header[1]);
|
||||||
|
fixed_header_len += 1;
|
||||||
/******************************************************/
|
/******************************************************/
|
||||||
|
|
||||||
/***********************add by alex********************/
|
/***********************add by alex********************/
|
||||||
packetLen = sizeof(var_header)+sizeof(fixed_header)+utf_topicLen;
|
packetLen = sizeof(var_header)+fixed_header_len+utf_topicLen;
|
||||||
packet = (uint8_t*)tls_mem_alloc( packetLen );
|
packet = (uint8_t*)tls_mem_alloc( packetLen );
|
||||||
if( packet==NULL )
|
if( packet==NULL )
|
||||||
{
|
{
|
||||||
@ -526,9 +547,11 @@ int mqtt_subscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t* me
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(packet, 0, packetLen);
|
memset(packet, 0, packetLen);
|
||||||
memcpy(packet, fixed_header, sizeof(fixed_header));
|
memcpy(packet, fixed_header, fixed_header_len);
|
||||||
memcpy(packet+sizeof(fixed_header), var_header, sizeof(var_header));
|
memcpy(packet+fixed_header_len, var_header, sizeof(var_header));
|
||||||
memcpy(packet+sizeof(fixed_header)+sizeof(var_header), utf_topic, utf_topicLen);
|
memcpy(packet+fixed_header_len+sizeof(var_header), utf_topic, utf_topicLen);
|
||||||
|
|
||||||
|
//dumpBuffer("subscribe packet", packet, packetLen);
|
||||||
|
|
||||||
// Send the packet
|
// Send the packet
|
||||||
if(broker->mqttsend(broker->socketid, packet, packetLen) < packetLen) {
|
if(broker->mqttsend(broker->socketid, packet, packetLen) < packetLen) {
|
||||||
@ -549,7 +572,8 @@ int mqtt_unsubscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t*
|
|||||||
/******************add by alex*******************/
|
/******************add by alex*******************/
|
||||||
uint8_t *utf_topic=NULL;
|
uint8_t *utf_topic=NULL;
|
||||||
int utf_topicLen;
|
int utf_topicLen;
|
||||||
uint8_t fixed_header[2];
|
uint8_t fixed_header[6];
|
||||||
|
int fixed_header_len;
|
||||||
uint8_t *packet = NULL;
|
uint8_t *packet = NULL;
|
||||||
int packetLen;
|
int packetLen;
|
||||||
|
|
||||||
@ -579,9 +603,11 @@ int mqtt_unsubscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t*
|
|||||||
/*************************add by alex*******************************/
|
/*************************add by alex*******************************/
|
||||||
// Fixed header
|
// Fixed header
|
||||||
fixed_header[0] = MQTT_MSG_UNSUBSCRIBE | MQTT_QOS1_FLAG;
|
fixed_header[0] = MQTT_MSG_UNSUBSCRIBE | MQTT_QOS1_FLAG;
|
||||||
fixed_header[1] = sizeof(var_header)+utf_topicLen;
|
//fixed_header[1] = sizeof(var_header)+utf_topicLen;
|
||||||
|
fixed_header_len = encode_length(sizeof(var_header)+utf_topicLen, &fixed_header[1]);
|
||||||
|
fixed_header_len += 1;
|
||||||
|
|
||||||
packetLen = sizeof(var_header)+sizeof(fixed_header)+utf_topicLen;
|
packetLen = sizeof(var_header)+fixed_header_len+utf_topicLen;
|
||||||
packet = (uint8_t*)tls_mem_alloc( packetLen );
|
packet = (uint8_t*)tls_mem_alloc( packetLen );
|
||||||
if( packet==NULL )
|
if( packet==NULL )
|
||||||
{
|
{
|
||||||
@ -589,9 +615,9 @@ int mqtt_unsubscribe(mqtt_broker_handle_t* broker, const char* topic, uint16_t*
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(packet, 0, packetLen);
|
memset(packet, 0, packetLen);
|
||||||
memcpy(packet, fixed_header, sizeof(fixed_header));
|
memcpy(packet, fixed_header, fixed_header_len);
|
||||||
memcpy(packet+sizeof(fixed_header), var_header, sizeof(var_header));
|
memcpy(packet+fixed_header_len, var_header, sizeof(var_header));
|
||||||
memcpy(packet+sizeof(fixed_header)+sizeof(var_header), utf_topic, utf_topicLen);
|
memcpy(packet+fixed_header_len+sizeof(var_header), utf_topic, utf_topicLen);
|
||||||
|
|
||||||
// Send the packet
|
// Send the packet
|
||||||
if(broker->mqttsend(broker->socketid, packet, packetLen) < packetLen) {
|
if(broker->mqttsend(broker->socketid, packet, packetLen) < packetLen) {
|
||||||
|
|||||||
@ -38,20 +38,24 @@ lsd_printf_fn lsd_printf = NULL;
|
|||||||
|
|
||||||
static u8 *lsd_scan_bss;
|
static u8 *lsd_scan_bss;
|
||||||
|
|
||||||
|
#define LSD_SRC_CNT (3)
|
||||||
|
|
||||||
const u8 lsd_dst_addr[3] = {0x01,0x00,0x5e};
|
const u8 lsd_dst_addr[3] = {0x01,0x00,0x5e};
|
||||||
u8 lsd_last_num[2] = {0,0};
|
u8 lsd_last_num[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u16 lsd_head[2][4] = {{0,0,0,0},{0,0,0,0}};
|
u16 lsd_head[LSD_SRC_CNT][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
|
||||||
u16 lsd_byte[2][4] = {{0,0,0,0},{0,0,0,0}};
|
u16 lsd_byte[LSD_SRC_CNT][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0}};
|
||||||
u8 lsd_state = 0;
|
u8 lsd_state[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u16 lsd_data_datum = 0;
|
u16 lsd_data_datum[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u8 lsd_head_cnt[2] = {0,0};
|
u8 lsd_head_cnt[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u8 lsd_byte_cnt[2] = {0,0};
|
u8 lsd_head_bw20[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u8 lsd_sync_cnt = 0;
|
u8 lsd_byte_cnt[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u8 lsd_src_mac[6] = {0};
|
u8 lsd_sync_cnt[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u8 lsd_data_cnt = 0;
|
u8 lsd_src_mac[LSD_SRC_CNT][6] = {{0}, {0}, {0}};
|
||||||
u16 lsd_last_seq[2] = {0,0};
|
u8 lsd_data_cnt[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u16 lsd_last_len = 0;
|
u16 lsd_last_seq[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
u8 lsd_temp_lock = 0;
|
u16 lsd_last_len[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
|
u8 lsd_temp_lock[LSD_SRC_CNT] = {0, 0, 0};
|
||||||
|
u8 lsd_lock_chan_cnt = 0;
|
||||||
|
|
||||||
|
|
||||||
struct lsd_data_t *lsd_data = NULL;
|
struct lsd_data_t *lsd_data = NULL;
|
||||||
@ -196,12 +200,24 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if(hdr->duration_id == 0) //normal mode stbc 不处理
|
||||||
|
{
|
||||||
|
tods = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(1 == ieee80211_has_tods(hdr->frame_control))
|
||||||
|
{
|
||||||
|
tods = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tods = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
multicast = ieee80211_get_DA(hdr);
|
multicast = ieee80211_get_DA(hdr);
|
||||||
|
|
||||||
if(0 == ieee80211_has_tods(hdr->frame_control))
|
|
||||||
{
|
|
||||||
return LSD_ONESHOT_CONTINUE;
|
|
||||||
}
|
|
||||||
//for LSD only tods
|
//for LSD only tods
|
||||||
if (ieee80211_is_data_qos(hdr->frame_control))
|
if (ieee80211_is_data_qos(hdr->frame_control))
|
||||||
{
|
{
|
||||||
@ -212,15 +228,15 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
frm_len = data_len;
|
frm_len = data_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
tods = ieee80211_has_tods(hdr->frame_control);
|
//tods = ieee80211_has_tods(hdr->frame_control);
|
||||||
SrcMac = ieee80211_get_SA(hdr);
|
SrcMac = ieee80211_get_SA(hdr);
|
||||||
|
|
||||||
if(memcmp(multicast, lsd_dst_addr, 3))
|
if(memcmp(multicast, lsd_dst_addr, 3) && hdr->duration_id)
|
||||||
{
|
{
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(lsd_state)
|
switch(lsd_state[tods])
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if ((frm_len < 60) || (frm_len > 86))
|
if ((frm_len < 60) || (frm_len > 86))
|
||||||
@ -228,24 +244,26 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_zero_ether_addr(lsd_src_mac))
|
if(is_zero_ether_addr(lsd_src_mac[tods]))
|
||||||
{
|
{
|
||||||
memcpy(lsd_src_mac, SrcMac, 6);
|
memcpy(lsd_src_mac[tods], SrcMac, 6);
|
||||||
lsd_head_cnt[0] = lsd_head_cnt[1] = 0;
|
lsd_head_cnt[tods] = 0;
|
||||||
lsd_sync_cnt = 0;
|
lsd_head_bw20[tods] = 0;
|
||||||
lsd_last_seq[0] = lsd_last_seq[1] = 0;
|
lsd_sync_cnt[tods] = 0;
|
||||||
lsd_temp_lock = 0;
|
lsd_last_seq[tods] = 0;
|
||||||
memset(lsd_head, 0, sizeof(lsd_head));
|
lsd_temp_lock[tods] = 0;
|
||||||
|
memset(lsd_head[tods], 0, sizeof(lsd_head)/LSD_SRC_CNT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(memcmp(lsd_src_mac, SrcMac, 6))
|
if(memcmp(lsd_src_mac[tods], SrcMac, 6))
|
||||||
{
|
{
|
||||||
memcpy(lsd_src_mac, SrcMac, 6);
|
memcpy(lsd_src_mac[tods], SrcMac, 6);
|
||||||
lsd_head_cnt[0] = lsd_head_cnt[1] = 0;
|
lsd_head_cnt[tods] = 0;
|
||||||
lsd_sync_cnt = 0;
|
lsd_head_bw20[tods] = 0;
|
||||||
lsd_last_seq[0] = lsd_last_seq[1] = 0;
|
lsd_sync_cnt[tods] = 0;
|
||||||
memset(lsd_head, 0, sizeof(lsd_head));
|
lsd_last_seq[tods] = 0;
|
||||||
|
memset(lsd_head[tods], 0, sizeof(lsd_head)/LSD_SRC_CNT);
|
||||||
}else{
|
}else{
|
||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("tods:%d,%d,"MACSTR"\n", tods, frm_len, MAC2STR(SrcMac));
|
lsd_printf("tods:%d,%d,"MACSTR"\n", tods, frm_len, MAC2STR(SrcMac));
|
||||||
@ -265,22 +283,27 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(((lsd_head[tods][lsd_head_cnt[tods]]+1) != lsd_head[tods][lsd_head_cnt[tods]-1])
|
if(((lsd_head[tods][lsd_head_cnt[tods]]+1) != lsd_head[tods][lsd_head_cnt[tods]-1])
|
||||||
&& ((lsd_head[tods][lsd_head_cnt[tods]]-3) != lsd_head[tods][lsd_head_cnt[tods]-1]))
|
&& ((lsd_head[tods][lsd_head_cnt[tods]]-3) != lsd_head[tods][lsd_head_cnt[tods]-1]))
|
||||||
{
|
{
|
||||||
lsd_temp_lock = 0;
|
lsd_temp_lock[tods] = 0;
|
||||||
lsd_head_cnt[tods] = 0;
|
lsd_head_cnt[tods] = 0;
|
||||||
|
lsd_head_bw20[tods] = 0;
|
||||||
lsd_head[tods][0] = frm_len;
|
lsd_head[tods][0] = frm_len;
|
||||||
}else{
|
}else{
|
||||||
lsd_temp_lock = 1;
|
lsd_temp_lock[tods] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lsd_head_cnt[tods] ++;
|
lsd_head_cnt[tods] ++;
|
||||||
|
if(0 == (hdr->duration_id&0x01))
|
||||||
|
{
|
||||||
|
lsd_head_bw20[tods] ++;
|
||||||
|
}
|
||||||
|
|
||||||
if(lsd_head_cnt[tods] >= 4)
|
if(lsd_head_cnt[tods] >= 4)
|
||||||
{
|
{
|
||||||
lsd_sync_cnt ++;
|
lsd_sync_cnt[tods] ++;
|
||||||
lsd_head_cnt[tods] = 0;
|
lsd_head_cnt[tods] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lsd_sync_cnt >= 1)
|
if(lsd_sync_cnt[tods] >= 1)
|
||||||
{
|
{
|
||||||
guide_len = lsd_head[tods][0];
|
guide_len = lsd_head[tods][0];
|
||||||
for(i=1; i<=3; i++)
|
for(i=1; i<=3; i++)
|
||||||
@ -288,28 +311,48 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(guide_len > lsd_head[tods][i])
|
if(guide_len > lsd_head[tods][i])
|
||||||
guide_len = lsd_head[tods][i]; //È¡³öͬ²½Í·ÖÐ×îСֵ
|
guide_len = lsd_head[tods][i]; //È¡³öͬ²½Í·ÖÐ×îСֵ
|
||||||
}
|
}
|
||||||
lsd_state = 1; //同步完成, 锁定源MAC和信道
|
lsd_state[tods] = 1; //同步完成, 锁定源MAC和信道
|
||||||
lsd_data_datum = guide_len - LSD_GUIDE_DATUM + LSD_DATA_OFFSET; //获取到基准长度
|
lsd_data_datum[tods] = guide_len - LSD_GUIDE_DATUM + LSD_DATA_OFFSET; //获取到基准长度
|
||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("lsd lock:%d\n", lsd_data_datum);
|
lsd_printf("lsd lock:%d\n", lsd_data_datum);
|
||||||
|
if (lsd_printf)
|
||||||
printf("SRC MAC:%02X:%02X:%02X:%02X:%02X:%02X\n",
|
lsd_printf("SRC MAC:%02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||||
lsd_src_mac[0],lsd_src_mac[1],lsd_src_mac[2],lsd_src_mac[3],lsd_src_mac[4],lsd_src_mac[5]);
|
lsd_src_mac[tods][0],lsd_src_mac[tods][1],lsd_src_mac[tods][2],lsd_src_mac[tods][3],lsd_src_mac[tods][4],lsd_src_mac[tods][5]);
|
||||||
return LSD_ONESHOT_CHAN_LOCKED;
|
if(lsd_head_bw20[tods] >= 4)
|
||||||
|
{
|
||||||
|
lsd_head_bw20[tods] = 0;
|
||||||
|
if (lsd_lock_chan_cnt == 1)
|
||||||
|
{
|
||||||
|
lsd_lock_chan_cnt = 2;
|
||||||
|
return LSD_ONESHOT_CHAN_LOCKED_BW20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (lsd_lock_chan_cnt == 1)
|
||||||
|
{
|
||||||
|
lsd_lock_chan_cnt = 2;
|
||||||
|
return LSD_ONESHOT_CHAN_LOCKED_BW40;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(lsd_temp_lock == 1)
|
if(lsd_temp_lock[tods] == 1)
|
||||||
{
|
{
|
||||||
return LSD_ONESHOT_CHAN_TEMP_LOCKED;
|
if (lsd_lock_chan_cnt == 0)
|
||||||
|
{
|
||||||
|
lsd_lock_chan_cnt = 1;
|
||||||
|
return LSD_ONESHOT_CHAN_TEMP_LOCKED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if((frm_len >= 1024) || (frm_len < lsd_data_datum))
|
if((frm_len >= 1024) || (frm_len < lsd_data_datum[tods]))
|
||||||
{
|
{
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(memcmp(lsd_src_mac, SrcMac, 6))
|
if(memcmp(lsd_src_mac[tods], SrcMac, 6))
|
||||||
{
|
{
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -327,7 +370,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
lsd_last_num[tods] = multicast[5];
|
lsd_last_num[tods] = multicast[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
lsd_byte[tods][lsd_byte_cnt[tods]] = frm_len - lsd_data_datum;
|
lsd_byte[tods][lsd_byte_cnt[tods]] = frm_len - lsd_data_datum[tods];
|
||||||
if((lsd_byte_cnt[tods]==0) && (lsd_byte[tods][0]>=256))
|
if((lsd_byte_cnt[tods]==0) && (lsd_byte[tods][0]>=256))
|
||||||
{
|
{
|
||||||
lsd_byte_cnt[tods] = 0;
|
lsd_byte_cnt[tods] = 0;
|
||||||
@ -361,16 +404,16 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(data_coding.crc == (u8)crcValue)
|
if(data_coding.crc == (u8)crcValue)
|
||||||
{
|
{
|
||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("%d\n", data_coding.seq);
|
lsd_printf("[%d]%d\n", tods, data_coding.seq);
|
||||||
lsd_data->data[data_coding.seq<<1] = data_coding.data1;
|
lsd_data->data[data_coding.seq<<1] = data_coding.data1;
|
||||||
lsd_data->used[data_coding.seq<<1] = 1;
|
lsd_data->used[data_coding.seq<<1] = 1;
|
||||||
lsd_data_cnt ++;
|
lsd_data_cnt[tods] ++;
|
||||||
lsd_data->data[(data_coding.seq<<1)+1] = data_coding.data2;
|
lsd_data->data[(data_coding.seq<<1)+1] = data_coding.data2;
|
||||||
lsd_data->used[(data_coding.seq<<1)+1] = 1;
|
lsd_data->used[(data_coding.seq<<1)+1] = 1;
|
||||||
lsd_data_cnt ++;
|
lsd_data_cnt[tods] ++;
|
||||||
if(lsd_data_cnt >= LSD_DATA_MAX)
|
if(lsd_data_cnt[tods] >= LSD_DATA_MAX)
|
||||||
{
|
{
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_ERR;
|
return LSD_ONESHOT_ERR;
|
||||||
}
|
}
|
||||||
@ -386,7 +429,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
ssidLen = lsd_data->data[2];
|
ssidLen = lsd_data->data[2];
|
||||||
if((ssidLen > 32) || (pwdLen > 64))
|
if((ssidLen > 32) || (pwdLen > 64))
|
||||||
{
|
{
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_ERR;
|
return LSD_ONESHOT_ERR;
|
||||||
}
|
}
|
||||||
@ -395,7 +438,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("totalLen:%d, ssidLen:%d, pwdLen:%d, err\n", totalLen, ssidLen, pwdLen);
|
lsd_printf("totalLen:%d, ssidLen:%d, pwdLen:%d, err\n", totalLen, ssidLen, pwdLen);
|
||||||
|
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -406,7 +449,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("totalLen:%d, ssidLen:%d, pwdLen:%d, err\n", totalLen, ssidLen, pwdLen);
|
lsd_printf("totalLen:%d, ssidLen:%d, pwdLen:%d, err\n", totalLen, ssidLen, pwdLen);
|
||||||
|
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -418,7 +461,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("totalLen:%d, ssidLen:%d, pwdLen:%d, err\n", totalLen, ssidLen, pwdLen);
|
lsd_printf("totalLen:%d, ssidLen:%d, pwdLen:%d, err\n", totalLen, ssidLen, pwdLen);
|
||||||
|
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -428,7 +471,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("ssidLen:%d, pwdLen:%d, err\n", ssidLen, pwdLen);
|
lsd_printf("ssidLen:%d, pwdLen:%d, err\n", ssidLen, pwdLen);
|
||||||
|
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -437,12 +480,12 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("ssidLen:%d, pwdLen:%d, err\n", ssidLen, pwdLen);
|
lsd_printf("ssidLen:%d, pwdLen:%d, err\n", ssidLen, pwdLen);
|
||||||
|
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lsd_data_cnt >= totalLen + 2)
|
if(lsd_data_cnt[tods] >= totalLen + 2)
|
||||||
{
|
{
|
||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("get all\n");
|
lsd_printf("get all\n");
|
||||||
@ -452,7 +495,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("totalCrc err\n");
|
lsd_printf("totalCrc err\n");
|
||||||
|
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -464,7 +507,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
lsd_param->user_len = totalLen - 2;
|
lsd_param->user_len = totalLen - 2;
|
||||||
if(lsd_param->user_len > 128)
|
if(lsd_param->user_len > 128)
|
||||||
{
|
{
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_ERR;
|
return LSD_ONESHOT_ERR;
|
||||||
}
|
}
|
||||||
@ -477,17 +520,17 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
bssidCrc = lsd_data->data[3];
|
bssidCrc = lsd_data->data[3];
|
||||||
if(pwdLen > 0)
|
if(pwdLen > 0)
|
||||||
{
|
{
|
||||||
memcpy(lsd_param->pwd, &lsd_data->data[4], pwdLen);
|
memcpy(&lsd_param->pwd, &lsd_data->data[4], pwdLen);
|
||||||
memcpy(lsd_param->ssid, &lsd_data->data[5+pwdLen], ssidLen);
|
memcpy(&lsd_param->ssid, &lsd_data->data[5+pwdLen], ssidLen);
|
||||||
ssidCrc = lsd_data->data[5+ssidLen+pwdLen];
|
ssidCrc = lsd_data->data[5+ssidLen+pwdLen];
|
||||||
lsd_param->user_len = totalLen - pwdLen - ssidLen - 5;
|
lsd_param->user_len = totalLen - pwdLen - ssidLen - 5;
|
||||||
if(lsd_param->user_len > 128)
|
if(lsd_param->user_len > 128)
|
||||||
{
|
{
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_ERR;
|
return LSD_ONESHOT_ERR;
|
||||||
}
|
}
|
||||||
memcpy(lsd_param->user_data, &lsd_data->data[6+ssidLen+pwdLen], lsd_param->user_len);
|
memcpy(&lsd_param->user_data, &lsd_data->data[6+ssidLen+pwdLen], lsd_param->user_len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -496,7 +539,7 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
lsd_param->user_len = totalLen - ssidLen - 4;
|
lsd_param->user_len = totalLen - ssidLen - 4;
|
||||||
if(lsd_param->user_len > 128)
|
if(lsd_param->user_len > 128)
|
||||||
{
|
{
|
||||||
lsd_data_cnt = 0;
|
lsd_data_cnt[tods] = 0;
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
||||||
return LSD_ONESHOT_ERR;
|
return LSD_ONESHOT_ERR;
|
||||||
}
|
}
|
||||||
@ -569,8 +612,11 @@ int tls_lsd_recv(u8 *buf, u16 data_len)
|
|||||||
{
|
{
|
||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("pwdCrc err\n");
|
lsd_printf("pwdCrc err\n");
|
||||||
lsd_data_cnt = 0;
|
memset((u8 *)&lsd_data->data[4], 0, pwdLen);
|
||||||
memset((u8 *)lsd_data, 0, sizeof(struct lsd_data_t));
|
memset((u8 *)&lsd_data->used[4], 0, pwdLen);
|
||||||
|
lsd_data->used[1] = 0;
|
||||||
|
lsd_data->data[1] = 0;
|
||||||
|
lsd_data_cnt[tods] = lsd_data_cnt[tods] - pwdLen;
|
||||||
memset(lsd_param->pwd, 0, 65);
|
memset(lsd_param->pwd, 0, 65);
|
||||||
return LSD_ONESHOT_CONTINUE;
|
return LSD_ONESHOT_CONTINUE;
|
||||||
}
|
}
|
||||||
@ -634,18 +680,20 @@ void tls_lsd_init(u8 *scanBss)
|
|||||||
|
|
||||||
memset(lsd_head, 0, sizeof(lsd_head));
|
memset(lsd_head, 0, sizeof(lsd_head));
|
||||||
memset(lsd_byte, 0, sizeof(lsd_byte));
|
memset(lsd_byte, 0, sizeof(lsd_byte));
|
||||||
memset(lsd_src_mac, 0, 6);
|
memset(lsd_src_mac, 0, sizeof(lsd_src_mac));
|
||||||
|
|
||||||
memset(lsd_last_num, 0, sizeof(lsd_last_num));
|
memset(lsd_last_num, 0, sizeof(lsd_last_num));
|
||||||
lsd_temp_lock = 0;
|
memset(lsd_temp_lock, 0, sizeof(lsd_temp_lock));
|
||||||
lsd_state = 0;
|
memset(lsd_state, 0, sizeof(lsd_state));
|
||||||
lsd_data_datum = 0;
|
memset(lsd_data_datum, 0, sizeof(lsd_data_datum));
|
||||||
|
memset(lsd_head_bw20, 0, sizeof(lsd_head_bw20));
|
||||||
memset(lsd_head_cnt, 0, sizeof(lsd_head_cnt));
|
memset(lsd_head_cnt, 0, sizeof(lsd_head_cnt));
|
||||||
memset(lsd_byte_cnt, 0, sizeof(lsd_byte_cnt));
|
memset(lsd_byte_cnt, 0, sizeof(lsd_byte_cnt));
|
||||||
lsd_sync_cnt = 0;
|
memset(lsd_sync_cnt, 0, sizeof(lsd_sync_cnt));
|
||||||
lsd_data_cnt = 0;
|
memset(lsd_data_cnt, 0, sizeof(lsd_data_cnt));
|
||||||
memset(lsd_last_seq, 0, sizeof(lsd_last_seq));
|
memset(lsd_last_seq, 0, sizeof(lsd_last_seq));
|
||||||
lsd_scan_bss = scanBss;
|
lsd_scan_bss = scanBss;
|
||||||
|
lsd_lock_chan_cnt = 0;
|
||||||
|
|
||||||
if(lsd_printf)
|
if(lsd_printf)
|
||||||
lsd_printf("tls_lsd_init\n");
|
lsd_printf("tls_lsd_init\n");
|
||||||
|
|||||||
@ -24,11 +24,14 @@ typedef enum
|
|||||||
|
|
||||||
LSD_ONESHOT_CHAN_TEMP_LOCKED = 1,
|
LSD_ONESHOT_CHAN_TEMP_LOCKED = 1,
|
||||||
|
|
||||||
LSD_ONESHOT_CHAN_LOCKED = 2,
|
LSD_ONESHOT_CHAN_LOCKED_BW20 = 2,
|
||||||
|
|
||||||
LSD_ONESHOT_COMPLETE = 3,
|
LSD_ONESHOT_CHAN_LOCKED_BW40 = 3,
|
||||||
|
|
||||||
|
LSD_ONESHOT_COMPLETE = 4,
|
||||||
|
|
||||||
|
LSD_ONESHOT_ERR = 5
|
||||||
|
|
||||||
LSD_ONESHOT_ERR = 4
|
|
||||||
|
|
||||||
} lsd_oneshot_status_t;
|
} lsd_oneshot_status_t;
|
||||||
|
|
||||||
|
|||||||
@ -107,6 +107,11 @@ static u8 scanChanErr = 0;
|
|||||||
|
|
||||||
static tls_os_sem_t *gWifiRecvSem = NULL;
|
static tls_os_sem_t *gWifiRecvSem = NULL;
|
||||||
|
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
#define ONESHOT_SPECIAL_DELAY_TIME (8 * HZ)
|
||||||
|
static u32 g_oneshot_dur_time = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TLS_CONFIG_AP_MODE_ONESHOT
|
#if TLS_CONFIG_AP_MODE_ONESHOT
|
||||||
@ -451,7 +456,7 @@ int tls_filter_module_srcmac(u8 *mac){
|
|||||||
|
|
||||||
static void wifi_change_chanel(u32 chanid, u8 bandwidth)
|
static void wifi_change_chanel(u32 chanid, u8 bandwidth)
|
||||||
{
|
{
|
||||||
tls_wl_change_channel_info(chanid, 0);//bandwidth);
|
tls_wl_change_channel_info(chanid, bandwidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TLS_CONFIG_UDP_LSD_SPECIAL
|
#if TLS_CONFIG_UDP_LSD_SPECIAL
|
||||||
@ -489,7 +494,8 @@ static void oneshot_lsd_finish(void)
|
|||||||
int tls_wifi_lsd_oneshot_special(u8 *data, u16 data_len)
|
int tls_wifi_lsd_oneshot_special(u8 *data, u16 data_len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
struct ieee80211_hdr *hdr = (struct ieee80211_hdr*)data;
|
||||||
|
|
||||||
ret = tls_lsd_recv(data, data_len);
|
ret = tls_lsd_recv(data, data_len);
|
||||||
if(ret == LSD_ONESHOT_ERR)
|
if(ret == LSD_ONESHOT_ERR)
|
||||||
{
|
{
|
||||||
@ -501,9 +507,14 @@ int tls_wifi_lsd_oneshot_special(u8 *data, u16 data_len)
|
|||||||
ONESHOT_DBG("LSD_ONESHOT_CHAN_TEMP_LOCKED:%d\r\n", tls_os_get_time());
|
ONESHOT_DBG("LSD_ONESHOT_CHAN_TEMP_LOCKED:%d\r\n", tls_os_get_time());
|
||||||
tls_oneshot_switch_channel_tim_temp_stop();
|
tls_oneshot_switch_channel_tim_temp_stop();
|
||||||
}
|
}
|
||||||
else if(ret == LSD_ONESHOT_CHAN_LOCKED)
|
else if(ret == LSD_ONESHOT_CHAN_LOCKED_BW20)
|
||||||
{
|
{
|
||||||
ONESHOT_DBG("LSD_ONESHOT_CHAN_LOCKED:%d\r\n", tls_os_get_time());
|
ONESHOT_DBG("LSD_ONESHOT_CHAN_LOCKED_BW20:%d,%x\r\n", tls_os_get_time(), hdr->duration_id);
|
||||||
|
tls_oneshot_switch_channel_tim_stop((struct ieee80211_hdr *)data);
|
||||||
|
}
|
||||||
|
else if(ret == LSD_ONESHOT_CHAN_LOCKED_BW40)
|
||||||
|
{
|
||||||
|
hdr->duration_id |= 0x0001; ////force change to bw40
|
||||||
tls_oneshot_switch_channel_tim_stop((struct ieee80211_hdr *)data);
|
tls_oneshot_switch_channel_tim_stop((struct ieee80211_hdr *)data);
|
||||||
}
|
}
|
||||||
else if(ret == LSD_ONESHOT_COMPLETE)
|
else if(ret == LSD_ONESHOT_COMPLETE)
|
||||||
@ -554,7 +565,7 @@ int soft_ap_create(void)
|
|||||||
|
|
||||||
apinfo.encrypt = 0; /*0:open, 1:wep64, 2:wep128*/
|
apinfo.encrypt = 0; /*0:open, 1:wep64, 2:wep128*/
|
||||||
apinfo.channel = 5; /*channel random*/
|
apinfo.channel = 5; /*channel random*/
|
||||||
/*ip information: ip address?ê?netmask?ê?dns*/
|
/*ip information: ip address?ê?netmask?ê?dns*/
|
||||||
ipinfo.ip_addr[0] = 192;
|
ipinfo.ip_addr[0] = 192;
|
||||||
ipinfo.ip_addr[1] = 168;
|
ipinfo.ip_addr[1] = 168;
|
||||||
ipinfo.ip_addr[2] = 1;
|
ipinfo.ip_addr[2] = 1;
|
||||||
@ -695,7 +706,11 @@ void tls_oneshot_callback_start(void)
|
|||||||
tls_airkiss_start();
|
tls_airkiss_start();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TLS_CONFIG_UDP_LSD_SPECIAL
|
#if TLS_CONFIG_UDP_LSD_SPECIAL
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
tls_wl_plcp_stop();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LSD_ONESHOT_DEBUG
|
#if LSD_ONESHOT_DEBUG
|
||||||
lsd_printf = printf;
|
lsd_printf = printf;
|
||||||
#endif
|
#endif
|
||||||
@ -1099,6 +1114,10 @@ void tls_oneshot_switch_channel_tim_stop(struct ieee80211_hdr *hdr)
|
|||||||
ONESHOT_DBG("change to BW20 ch:%d\n", ch);
|
ONESHOT_DBG("change to BW20 ch:%d\n", ch);
|
||||||
tls_wifi_change_chanel(ch);
|
tls_wifi_change_chanel(ch);
|
||||||
}
|
}
|
||||||
|
else if(hdr->duration_id == 0)
|
||||||
|
{
|
||||||
|
ONESHOT_DBG("special frame!!!!!!!!!!!!!!\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tls_oneshot_switch_channel_tim_temp_stop(void)
|
void tls_oneshot_switch_channel_tim_temp_stop(void)
|
||||||
@ -1249,6 +1268,9 @@ void tls_oneshot_task_handle(void *arg)
|
|||||||
void *msg;
|
void *msg;
|
||||||
#if TLS_CONFIG_UDP_ONE_SHOT
|
#if TLS_CONFIG_UDP_ONE_SHOT
|
||||||
static int chanCnt = 0;
|
static int chanCnt = 0;
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
static int chanRepeat = 0;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
@ -1274,6 +1296,10 @@ void tls_oneshot_task_handle(void *arg)
|
|||||||
tls_oneshot_scan_result_deal();
|
tls_oneshot_scan_result_deal();
|
||||||
|
|
||||||
chanCnt = 0;
|
chanCnt = 0;
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
chanRepeat = 0;
|
||||||
|
g_oneshot_dur_time = tls_os_get_time();
|
||||||
|
#endif
|
||||||
wifi_change_chanel(airwifichan[chanCnt], airchantype[chanCnt]);
|
wifi_change_chanel(airwifichan[chanCnt], airchantype[chanCnt]);
|
||||||
|
|
||||||
tls_oneshot_callback_start();
|
tls_oneshot_callback_start();
|
||||||
@ -1305,9 +1331,33 @@ void tls_oneshot_task_handle(void *arg)
|
|||||||
{
|
{
|
||||||
chanCnt = 0;
|
chanCnt = 0;
|
||||||
}
|
}
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
if (chanRepeat)
|
||||||
{
|
{
|
||||||
|
if((tls_os_get_time() - g_oneshot_dur_time) >= ONESHOT_SPECIAL_DELAY_TIME)
|
||||||
|
{
|
||||||
|
ONESHOT_DBG("plcp stop\r\n");
|
||||||
|
tls_wl_plcp_stop();
|
||||||
|
chanRepeat = 0;
|
||||||
|
g_oneshot_dur_time = tls_os_get_time();
|
||||||
|
}
|
||||||
|
wifi_change_chanel(airwifichan[chanCnt], 0);
|
||||||
|
ONESHOT_DBG("@chan:%d,bandwidth:%d,%d\n", airwifichan[chanCnt], 0, tls_os_get_time());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
if((tls_os_get_time() - g_oneshot_dur_time) >= ONESHOT_SPECIAL_DELAY_TIME)
|
||||||
|
{
|
||||||
|
ONESHOT_DBG("plcp start\r\n");
|
||||||
|
tls_wl_plcp_start();
|
||||||
|
chanRepeat = 1;
|
||||||
|
g_oneshot_dur_time = tls_os_get_time();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
wifi_change_chanel(airwifichan[chanCnt], airchantype[chanCnt]);
|
wifi_change_chanel(airwifichan[chanCnt], airchantype[chanCnt]);
|
||||||
ONESHOT_DBG("chan:%d,bandwidth:%d\n", airwifichan[chanCnt], airchantype[chanCnt]);
|
ONESHOT_DBG("chan:%d,bandwidth:%d,%d\n", airwifichan[chanCnt], airchantype[chanCnt], tls_os_get_time());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TLS_CONFIG_AIRKISS_MODE_ONESHOT
|
#if TLS_CONFIG_AIRKISS_MODE_ONESHOT
|
||||||
@ -1342,6 +1392,9 @@ void tls_oneshot_task_handle(void *arg)
|
|||||||
|
|
||||||
case ONESHOT_STOP_CHAN_SWITCH:
|
case ONESHOT_STOP_CHAN_SWITCH:
|
||||||
gchanLock = 1;
|
gchanLock = 1;
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
tls_wl_plcp_start();
|
||||||
|
#endif
|
||||||
ONESHOT_DBG("stop channel ch:%d time:%d\n",airwifichan[chanCnt], (tls_os_get_time()-oneshottime)*1000/HZ);
|
ONESHOT_DBG("stop channel ch:%d time:%d\n",airwifichan[chanCnt], (tls_os_get_time()-oneshottime)*1000/HZ);
|
||||||
if (gWifiSwitchChanTim)
|
if (gWifiSwitchChanTim)
|
||||||
{
|
{
|
||||||
@ -1357,9 +1410,7 @@ void tls_oneshot_task_handle(void *arg)
|
|||||||
{
|
{
|
||||||
tls_os_timer_stop(gWifiRecvTimOut);
|
tls_os_timer_stop(gWifiRecvTimOut);
|
||||||
tls_os_timer_change(gWifiRecvTimOut, TLS_ONESHOT_RECV_TIME);
|
tls_os_timer_change(gWifiRecvTimOut, TLS_ONESHOT_RECV_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ONESHOT_HANDSHAKE_TIMEOUT:
|
case ONESHOT_HANDSHAKE_TIMEOUT:
|
||||||
@ -1520,8 +1571,8 @@ void tls_oneshot_task_create(void)
|
|||||||
err = tls_os_task_create(NULL, NULL,
|
err = tls_os_task_create(NULL, NULL,
|
||||||
tls_oneshot_task_handle,
|
tls_oneshot_task_handle,
|
||||||
NULL,
|
NULL,
|
||||||
(void *)OneshotTaskStk, /* 任务栈的起始地址 */
|
(void *)OneshotTaskStk, /* 任务栈的起始地址 */
|
||||||
ONESHOT_TASK_SIZE * sizeof(u32), /* 任务栈的大小 */
|
ONESHOT_TASK_SIZE * sizeof(u32), /* 任务栈的大小 */
|
||||||
TLS_ONESHOT_TASK_PRIO,
|
TLS_ONESHOT_TASK_PRIO,
|
||||||
0);
|
0);
|
||||||
if (err != TLS_OS_SUCCESS)
|
if (err != TLS_OS_SUCCESS)
|
||||||
@ -1661,7 +1712,11 @@ int tls_wifi_set_oneshot_flag(u8 flag)
|
|||||||
else /*udp mode*/
|
else /*udp mode*/
|
||||||
{
|
{
|
||||||
tls_wifi_set_listen_mode(1);
|
tls_wifi_set_listen_mode(1);
|
||||||
|
#if TLS_CONFIG_ONESHOT_DELAY_SPECIAL
|
||||||
|
#else
|
||||||
tls_wl_plcp_start();
|
tls_wl_plcp_start();
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
tls_wifi_start_oneshot();
|
tls_wifi_start_oneshot();
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user