add iot explorer demo for LN882x
add iot explorer demo for LN882x
This commit is contained in:
200
board/EVB_LN882x/BSP/Src/iot_explorer_examples.c
Normal file
200
board/EVB_LN882x/BSP/Src/iot_explorer_examples.c
Normal file
@@ -0,0 +1,200 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "osal/osal.h"
|
||||
#include "utils/debug/log.h"
|
||||
#include "utils/debug/art_assert.h"
|
||||
#include "utils/art_string.h"
|
||||
#include "wifi/wifi.h"
|
||||
#include "ping/ping.h"
|
||||
#include "netif/ethernetif.h"
|
||||
#include "wifi_manager/wifi_manager.h"
|
||||
#include "lwip/tcpip.h"
|
||||
#include "drv/drv_adc_measure.h"
|
||||
#include "utils/system_parameter.h"
|
||||
#include "hal/hal_adc.h"
|
||||
|
||||
static OS_Thread_t g_temp_cal_thread;
|
||||
#define TEMP_APP_TASK_STACK_SIZE 4*256 //Byte
|
||||
|
||||
volatile uint8_t dhcp_get_ip = 0;
|
||||
|
||||
void wifi_init_sta(void)
|
||||
{
|
||||
uint8_t macaddr[6] = {0}, macaddr_default[6] = {0};
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = "Supowang",
|
||||
.password = "13975426138",
|
||||
0,
|
||||
},
|
||||
};
|
||||
|
||||
wifi_config_t temp_config = {0};
|
||||
|
||||
wifi_init_type_t init_param = {
|
||||
.wifi_mode = WIFI_MODE_STATION,
|
||||
.sta_ps_mode = WIFI_NO_POWERSAVE,
|
||||
#if 1
|
||||
.dhcp_mode = WLAN_DHCP_CLIENT,
|
||||
#else
|
||||
.dhcp_mode = WLAN_STATIC_IP,
|
||||
.local_ip_addr = "192.168.1.110",
|
||||
.net_mask = "255.255.255.0",
|
||||
.gateway_ip_addr = "192.168.1.1",
|
||||
#endif
|
||||
//In station mode, define the length of the AP list scanned.
|
||||
.scanned_ap_list_size = SCANNED_AP_LIST_SIZE,
|
||||
};
|
||||
|
||||
|
||||
//Set wifi mode
|
||||
wifi_set_mode(init_param.wifi_mode);
|
||||
|
||||
//Check mac address
|
||||
system_parameter_get_wifi_macaddr_default(STATION_IF, macaddr_default);
|
||||
wifi_get_macaddr(STATION_IF, macaddr);
|
||||
if(is_valid_mac((const char *)macaddr) && memcmp(macaddr, macaddr_default, 6) != 0){
|
||||
//If there is a valid MAC in flash, use it
|
||||
wifi_set_macaddr_current(STATION_IF, macaddr);
|
||||
}else{
|
||||
//generate random macaddr
|
||||
generate_mac_randomly(macaddr);
|
||||
wifi_set_macaddr(STATION_IF, macaddr);
|
||||
}
|
||||
|
||||
//Check config
|
||||
wifi_get_config(STATION_IF, &temp_config);
|
||||
if(strlen((const char *)temp_config.sta.ssid) > 0){
|
||||
//If there is a valid config in flash, use it;
|
||||
wifi_set_config_current(STATION_IF, &temp_config);
|
||||
}else{
|
||||
//else, use the prev wifi_config and save it to flash.
|
||||
wifi_set_config(STATION_IF, &wifi_config);
|
||||
}
|
||||
|
||||
//Startup WiFi.
|
||||
if(!wifi_start(&init_param)){//WIFI_MAX_POWERSAVE
|
||||
LOG(LOG_LVL_ERROR, "[%s, %d]wifi_start() fail.\r\n", __func__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_ap(void)
|
||||
{
|
||||
uint8_t macaddr[6] = {0}, macaddr_default[6] = {0};
|
||||
wifi_config_t wifi_config = {
|
||||
.ap = {
|
||||
.ssid = "Supowang",
|
||||
.ssid_len = strlen("Supowang"),
|
||||
.password = "Supowang",
|
||||
.channel = 1,
|
||||
.authmode = WIFI_AUTH_OPEN,
|
||||
.ssid_hidden = 0,
|
||||
.max_connection = 4,
|
||||
.beacon_interval = 100,
|
||||
.reserved = 0,
|
||||
},
|
||||
};
|
||||
|
||||
wifi_config_t temp_config = {0};
|
||||
|
||||
wifi_init_type_t init_param = {
|
||||
.wifi_mode = WIFI_MODE_AP,
|
||||
.sta_ps_mode = WIFI_NO_POWERSAVE,
|
||||
.dhcp_mode = WLAN_DHCP_SERVER,
|
||||
};
|
||||
|
||||
//Set wifi mode
|
||||
wifi_set_mode(init_param.wifi_mode);
|
||||
|
||||
//Check mac address
|
||||
system_parameter_get_wifi_macaddr_default(SOFT_AP_IF, macaddr_default);
|
||||
wifi_get_macaddr(SOFT_AP_IF, macaddr);
|
||||
if(is_valid_mac((const char *)macaddr) && memcmp(macaddr, macaddr_default, 6) != 0){
|
||||
//If there is a valid MAC in flash, use it
|
||||
wifi_set_macaddr_current(SOFT_AP_IF, macaddr);
|
||||
}else{
|
||||
//generate random macaddr
|
||||
generate_mac_randomly(macaddr);
|
||||
wifi_set_macaddr(SOFT_AP_IF, macaddr);
|
||||
}
|
||||
|
||||
//Check config
|
||||
wifi_get_config(SOFT_AP_IF, &temp_config);
|
||||
if(strlen((const char *)temp_config.sta.ssid) > 0){
|
||||
//If there is a valid config in flash, use it;
|
||||
wifi_set_config_current(SOFT_AP_IF, &temp_config);
|
||||
}else{
|
||||
//else, use the prev wifi_config and save it to flash.
|
||||
wifi_set_config(SOFT_AP_IF, &wifi_config);
|
||||
}
|
||||
|
||||
//Startup WiFi.
|
||||
if(!wifi_start(&init_param)){
|
||||
LOG(LOG_LVL_ERROR, "[%s, %d]wifi_start() fail.\r\n", __func__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void temp_cal_app_task_entry(void *params)
|
||||
{
|
||||
drv_adc_init();
|
||||
OS_MsDelay(1);
|
||||
wifi_temp_cal_init(drv_adc_read(ADC_CHAN_0));
|
||||
|
||||
while(1)
|
||||
{
|
||||
OS_MsDelay(1);
|
||||
wifi_do_temp_cal_period(drv_adc_read(ADC_CHAN_0));
|
||||
OS_MsDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_event_sta_got_ip_cb(wifi_msg_t * msg)
|
||||
{
|
||||
dhcp_get_ip = 1;
|
||||
};
|
||||
|
||||
extern int data_template_light_thread(void);
|
||||
void application_entry(void *arg)
|
||||
{
|
||||
//wifi chip temperature calibration.
|
||||
if(OS_OK != OS_ThreadCreate(&g_temp_cal_thread, "TempAPP", temp_cal_app_task_entry, NULL, OS_PRIORITY_BELOW_NORMAL, TEMP_APP_TASK_STACK_SIZE)) {
|
||||
ART_ASSERT(1);
|
||||
}
|
||||
|
||||
reg_wifi_msg_callbcak(wifi_manager_get_handle(), WIFI_MSG_ID_STA_DHCP_GOT_IP,wifi_event_sta_got_ip_cb);
|
||||
|
||||
wifi_mode_enum_t wifi_mode = WIFI_MODE_STATION;
|
||||
|
||||
tcpip_ip_info_t ip_info = {0};
|
||||
wifi_interface_enum_t if_index;
|
||||
|
||||
if(wifi_mode == WIFI_MODE_STATION){
|
||||
if_index = STATION_IF;
|
||||
wifi_init_sta();
|
||||
}else if(wifi_mode == WIFI_MODE_AP){
|
||||
if_index = SOFT_AP_IF;
|
||||
wifi_init_ap();
|
||||
}else if(wifi_mode == WIFI_MODE_MONITOR){
|
||||
if_index = MONITOR_IF;
|
||||
}else{
|
||||
LOG(LOG_LVL_ERROR, "wifi interface error!\r\n");
|
||||
}
|
||||
|
||||
if((wifi_mode == WIFI_MODE_STATION)||(wifi_mode == WIFI_MODE_AP)) {
|
||||
//Wait for network link up
|
||||
while(LINK_UP != ethernetif_get_link_state()){
|
||||
OS_MsDelay(1000);
|
||||
}
|
||||
|
||||
ethernetif_get_ip_info(if_index, &ip_info);
|
||||
}
|
||||
|
||||
while(!dhcp_get_ip){
|
||||
OS_MsDelay(1000);
|
||||
};
|
||||
|
||||
data_template_light_thread();
|
||||
}
|
||||
|
||||
|
||||
|
39
board/EVB_LN882x/KEIL/qcloud_iot_explorer/JLinkSettings.ini
Normal file
39
board/EVB_LN882x/KEIL/qcloud_iot_explorer/JLinkSettings.ini
Normal file
@@ -0,0 +1,39 @@
|
||||
[BREAKPOINTS]
|
||||
ForceImpTypeAny = 0
|
||||
ShowInfoWin = 1
|
||||
EnableFlashBP = 2
|
||||
BPDuringExecution = 0
|
||||
[CFI]
|
||||
CFISize = 0x00
|
||||
CFIAddr = 0x00
|
||||
[CPU]
|
||||
MonModeVTableAddr = 0xFFFFFFFF
|
||||
MonModeDebug = 0
|
||||
MaxNumAPs = 0
|
||||
LowPowerHandlingMode = 0
|
||||
OverrideMemMap = 0
|
||||
AllowSimulation = 1
|
||||
ScriptFile=""
|
||||
[FLASH]
|
||||
CacheExcludeSize = 0x00
|
||||
CacheExcludeAddr = 0x00
|
||||
MinNumBytesFlashDL = 0
|
||||
SkipProgOnCRCMatch = 1
|
||||
VerifyDownload = 1
|
||||
AllowCaching = 1
|
||||
EnableFlashDL = 2
|
||||
Override = 1
|
||||
Device="CORTEX-M4"
|
||||
[GENERAL]
|
||||
WorkRAMSize = 0x00
|
||||
WorkRAMAddr = 0x00
|
||||
RAMUsageLimit = 0x00
|
||||
[SWO]
|
||||
SWOLogFile=""
|
||||
[MEM]
|
||||
RdOverrideOrMask = 0x00
|
||||
RdOverrideAndMask = 0xFFFFFFFF
|
||||
RdOverrideAddr = 0xFFFFFFFF
|
||||
WrOverrideOrMask = 0x00
|
||||
WrOverrideAndMask = 0xFFFFFFFF
|
||||
WrOverrideAddr = 0xFFFFFFFF
|
3557
board/EVB_LN882x/KEIL/qcloud_iot_explorer/TencentOS_tiny.uvoptx
Normal file
3557
board/EVB_LN882x/KEIL/qcloud_iot_explorer/TencentOS_tiny.uvoptx
Normal file
File diff suppressed because it is too large
Load Diff
1929
board/EVB_LN882x/KEIL/qcloud_iot_explorer/TencentOS_tiny.uvprojx
Normal file
1929
board/EVB_LN882x/KEIL/qcloud_iot_explorer/TencentOS_tiny.uvprojx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
|
||||
python ..\..\..\..\platform\vendor_bsp\LN\ln882x\tools\user_cmd\after_build_soc.py firmware_XIP
|
||||
|
||||
..\..\..\..\platform\vendor_bsp\LN\ln882x\tools\bin\mkimage.exe ln882x flashimage ..\..\..\..\platform\vendor_bsp\LN\ln882x\lib\boot_ram_ln882x.bin firmware_XIP.bin flashimage.bin release=1 crp_enable=0 app_version=10 hw_version=0
|
||||
|
||||
..\..\..\..\platform\vendor_bsp\LN\ln882x\tools\bin\fpu_patch.exe .\firmware_XIP.asm .\flashimage.bin
|
||||
|
||||
|
@@ -0,0 +1,78 @@
|
||||
#! armcc -E
|
||||
#include ".\flash_partition_table.h"
|
||||
#include ".\..\..\..\..\platform\vendor_bsp\LN\ln882x\include\cpu\ARM_CM4F\ln88xx\mem_map_ln882x.h"
|
||||
|
||||
|
||||
LR_FLASH FLASH_BASE+PRIMARY_PARTITION_OFFSET PRIMARY_PATTITION_SIZE
|
||||
{; load region size_region
|
||||
|
||||
ISR_VECTOR RAM_BASE ALIGN 0x100
|
||||
{
|
||||
startup_*.o (RESET, +First)
|
||||
}
|
||||
|
||||
ER_FLASH FLASH_BASE+PRIMARY_PARTITION_OFFSET + ImageLength(ISR_VECTOR) PRIMARY_PATTITION_SIZE
|
||||
{; load address = execution address
|
||||
*(InRoot$$Sections)
|
||||
.ANY (+RO)
|
||||
}
|
||||
|
||||
ER_CODE ImageLimit(ISR_VECTOR)
|
||||
{
|
||||
;mandatory item
|
||||
ll_qspi.o(+RO)
|
||||
ll_cache.o(+RO)
|
||||
ll_dma.o(+RO)
|
||||
ll_syscon.o(+RO)
|
||||
ll_sleep.o(+RO)
|
||||
ll_rtc.o(+RO)
|
||||
cache.o(+RO)
|
||||
qspi.o(+RO)
|
||||
flash.o(+RO)
|
||||
hal_dma.o(+RO)
|
||||
hal_syscon.o(+RO)
|
||||
hal_sleep.o(+RO)
|
||||
hal_rtc.o(+RO)
|
||||
;port.o(XIR)
|
||||
|
||||
;optional item
|
||||
;ll_uart.o(+RO)
|
||||
;hal_uart.o(+RO)
|
||||
;log.o(+RO)
|
||||
;serial.o(+RO)
|
||||
;serial_art2000.o(+RO)
|
||||
;fifobuf.o(+RO)
|
||||
}
|
||||
|
||||
ER_STACK +0
|
||||
{
|
||||
startup_ln*(+RW +ZI)
|
||||
}
|
||||
|
||||
ER_DATA +0
|
||||
{
|
||||
*(.ARM.__at_0x1FFFFFFC)
|
||||
.ANY (+RW +ZI)
|
||||
}
|
||||
|
||||
;IQ Data area cannot be used by ER_DATA region
|
||||
;ScatterAssert(ImageLimit(ER_DATA) < (0x20020300))
|
||||
|
||||
HEAP_SPACE +0 EMPTY RETENTION_MEM_BASE-ImageLimit(ER_DATA)
|
||||
{; Heap region
|
||||
}
|
||||
|
||||
NO_INIT_DATA RETENTION_MEM_BASE UNINIT 0x80
|
||||
{
|
||||
*(no_init_data)
|
||||
}
|
||||
|
||||
RETENTION RETENTION_MEM_BASE+0x80 ANY_SIZE 0x2000-0x80-16 RETENTION_MEM_SIZE
|
||||
{
|
||||
*(retention_data)
|
||||
phy_LN.o(+RW +ZI)
|
||||
ch_info.o(+RW +ZI)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,32 @@
|
||||
#ifndef __FLASH_PARTITION_TABLE_H__
|
||||
#define __FLASH_PARTITION_TABLE_H__
|
||||
|
||||
//#define RETENTION_MEM_BASE 0x20028000
|
||||
//#define RETENTION_MEM_SIZE 0x2000
|
||||
|
||||
#ifndef FLASH_BASE
|
||||
#define FLASH_BASE (0x10000000)
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_SIZE
|
||||
#define FLASH_SIZE (0x00200000)
|
||||
#endif
|
||||
|
||||
#ifndef PRIMARY_PARTITION_OFFSET
|
||||
#define PRIMARY_PARTITION_OFFSET (0x0000F000)
|
||||
#endif
|
||||
|
||||
#define PRIMARY_PATTITION_START 0x0000F000
|
||||
#define PRIMARY_PATTITION_SIZE 0xE1000
|
||||
//#define USERAPP_SRAM_BASE 0x1FFF0000
|
||||
#define BACKUP_PATTITION_START 0x000F0000
|
||||
#define BACKUP_PATTITION_SIZE 0xE1000
|
||||
#define USERDATA_PATTITION_START 0x001D1000
|
||||
#define USERDATA_PATTITION_SIZE 0x23000
|
||||
|
||||
//memory offset check
|
||||
#if ((PRIMARY_PATTITION_START < PRIMARY_PARTITION_OFFSET) || (BACKUP_PATTITION_START < PRIMARY_PATTITION_START) || (USERDATA_PATTITION_START < BACKUP_PATTITION_START) || (PRIMARY_PATTITION_START + PRIMARY_PATTITION_SIZE > BACKUP_PATTITION_START) || (BACKUP_PATTITION_START + BACKUP_PATTITION_SIZE > USERDATA_PATTITION_START) || (USERDATA_PATTITION_START + USERDATA_PATTITION_SIZE > FLASH_SIZE))
|
||||
#error "flash partition define error!"
|
||||
#endif
|
||||
|
||||
#endif /* __FLASH_PARTITION_TABLE_H__ */
|
Reference in New Issue
Block a user