build: W600-SDK importiert, Firmware-Build und Hello am EVK

Docker-Build mit gcc-arm-none-eabi 4.9-2014q4 (statt Homebrew-Cask) verwendet,
Dockerfile/tools/docker.sh dafür aus Task 13 vorgezogen. cmake/sdk.cmake schont
gcc 4.9 (kennt -fcommon/-Wno-error=... nicht). Zwei zusätzliche SDK-Stubs
(EarlyInit, pre_gpio_config) in src/sys/sdk_stubs.c ergänzt, siehe sdk/PATCHES.md.
This commit is contained in:
Michael Sauer
2026-09-11 12:52:26 +02:00
parent 4e7ff78fc6
commit 1b0501179d
610 changed files with 224089 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
# THE VERSION NUMBER
SET(CMAKE_SYSTEM_NAME Generic)
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
PROJECT(WMMAIN)
SET(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1)
SET(CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")
set(CMAKE_VERBOSE_MAKEFILE OFF)
# ENABLE ASM
ENABLE_LANGUAGE(ASM)
SET(CMAKE_STATIC_LIBRARY_PREFIX)
SET(CMAKE_STATIC_LIBRARY_SUFFIX)
SET(CMAKE_EXECUTABLE_LIBRARY_PREFIX)
SET(CMAKE_EXECUTABLE_LIBRARY_SUFFIX)
# C FLAGS
SET(CMAKE_C_FLAGS " -mthumb --function-sections --data-sections -mcpu=cortex-m3 -std=gnu99 -mabi=aapcs -march=armv7-m -fno-builtin ")
STRING(APPEND CMAKE_C_FLAGS " -DGCC_COMPILE=1 -DWOLFSSL_USER_SETTINGS -D_IN_ADDR_T_DECLARED -D__MACHINE_ENDIAN_H__ -D_TIMEVAL_DEFINED -D__INSIDE_CYGWIN_NET__ ")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -gdwarf-2 -Wall -DDEBUG ")
SET(CMAKE_C_FLAGS_RELEASE "-Os -Wall")
# DEBUG ASM FLAGS
SET(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_ASM_FLAGS_DEBUG} -O0 -g3 -gdwarf-2 -Wall -mthumb-interwork -mthumb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -mabi=aapcs -fno-builtin -DDEBUG ")
SET(CMAKE_ASM_FLAGS_RELEASE "${CMAKE_ASM_FLAGS_RELEASE} -Os -Wall -mthumb-interwork -mthumb -std=gnu99 -mcpu=cortex-m3 -march=armv7-m -mabi=aapcs -fno-builtin ")
# Library sources
SET(LIBRARY_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/wm_main.c"
"${CMAKE_CURRENT_SOURCE_DIR}/tls_sys.c"
)
function(ADD_LIB_TARGET LIBTARGET)
add_library(${LIBTARGET} OBJECT ${LIBRARY_SOURCES})
# ADD_CUSTOM_COMMAND(TARGET ${LIBTARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EXECUTABLE_OUTPUT_PATH}/${LIBTARGET} ${CMAKE_CURRENT_SOURCE_DIR}/../../Lib/GNU/${LIBTARGET})
endfunction()
ADD_LIB_TARGET(wmmain.a)
+581
View File
@@ -0,0 +1,581 @@
/**************************************************************************
* File Name : tls_sys.c
* Author :
* Version :
* Date :
* Description :
*
* Copyright (c) 2014 Winner Microelectronics Co., Ltd.
* All rights reserved.
*
***************************************************************************/
#include "wm_config.h"
#include "wm_osal.h"
#include "tls_sys.h"
#include "wm_mem.h"
#include "wm_debug.h"
#include "wm_params.h"
#include "wm_regs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wm_wifi.h"
#include "wm_netif.h"
#include "wm_sockets.h"
#include "wm_include.h"
#if TLS_CONFIG_AP
#include "wm_dhcp_server.h"
#include "wm_dns_server.h"
#include "wm_cpu.h"
#endif
#include "wm_wl_task.h"
#if TLS_CONFIG_RMMS
#if (GCC_COMPILE==1)
#include "wm_cmdp_hostif_gcc.h"
#else
#include "wm_cmdp_hostif.h"
#endif
#endif
#include "misc.h"
struct tls_sys_msg
{
u32 msg;
void *data;
};
#define SYS_TASK_STK_SIZE 512
static tls_os_queue_t *msg_queue;
#if TLS_DBG_LEVEL_DUMP
void TLS_DBGPRT_DUMP(char *p, u32 len)
{
int i;
if (TLS_DBG_LEVEL_DUMP)
{
wm_printf("dump length : %d\n", len);
for (i = 0; i < len; i++)
{
wm_printf("%02X ", p[i]);
if ((i + 1) % 16 == 0 && (i + 1) % 32 != 0)
{
wm_printf("- ");
}
if ((i + 1) % 32 == 0)
{
wm_printf("\n");
}
if (i == 2000)
{
wm_printf("\n");
break;
}
}
wm_printf("\n");
}
}
//-------------------------------------------------------------------------
#endif
static void sys_net_up()
{
ip_addr_t ip_addr, net_mask, gateway, dns1, dns2;
struct tls_param_ip ip_param;
bool enable = FALSE;
tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
if (ip_param.dhcp_enable)
{
ip_addr_set_zero(&ip_addr);
ip_addr_set_zero(&net_mask);
ip_addr_set_zero(&gateway);
tls_netif_set_addr( &ip_addr, &net_mask, &gateway);
tls_netif_set_up();
tls_dhcp_start();
}
else
{
tls_dhcp_stop();
tls_netif_set_up();
MEMCPY((char*)ip_2_ip4(&ip_addr), &ip_param.ip, 4);
MEMCPY((char*)ip_2_ip4(&net_mask), &ip_param.netmask, 4);
MEMCPY((char*)ip_2_ip4(&gateway), &ip_param.gateway, 4);
tls_netif_set_addr( &ip_addr, &net_mask, &gateway);
MEMCPY((char*)ip_2_ip4(&dns1), &ip_param.dns1, 4);
MEMCPY((char*)ip_2_ip4(&dns2), &ip_param.dns2, 4);
tls_netif_dns_setserver(0, &dns1);
tls_netif_dns_setserver(1, &dns2);
/*when DHCP is disabled, Use static IP without IP_NET_UP Reporting,
set wifi powersaving flag according to TLS_PARAM_ID_PSM here.*/
tls_param_get(TLS_PARAM_ID_PSM, &enable, TRUE);
tls_wifi_set_psflag(enable, FALSE);
}
return ;
}
//-------------------------------------------------------------------------
#if TLS_CONFIG_AP
static void sys_net2_up()
{
ip_addr_t ip_addr, net_mask, gateway;
struct tls_param_ip ip_param;
u8 dnsname[32];
dnsname[0] = '\0';
tls_param_get(TLS_PARAM_ID_DNSNAME, dnsname, 0);
tls_param_get(TLS_PARAM_ID_SOFTAP_IP, &ip_param, FALSE);
tls_netif2_set_up();
MEMCPY((char*)ip_2_ip4(&ip_addr), &ip_param.ip, 4);
MEMCPY((char*)ip_2_ip4(&net_mask), &ip_param.netmask, 4);
MEMCPY((char*)ip_2_ip4(&gateway), &ip_param.gateway, 4);
tls_netif2_set_addr(&ip_addr, &net_mask, &gateway);
if (ip_param.dhcp_enable)
{
tls_dhcps_start();
}
if ('\0' != dnsname[0])
{
tls_dnss_start(dnsname);
}
return ;
}
//-------------------------------------------------------------------------
static void sys_net2_down()
{
tls_dnss_stop();
tls_dhcps_stop();
tls_netif2_set_down();
return ;
}
#endif
static void sys_net_down()
{
struct tls_param_ip ip_param;
#if TLS_CONFIG_RMMS
tls_rmms_stop();
#endif
tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
if (ip_param.dhcp_enable)
{
tls_dhcp_stop();
}
tls_netif_set_status(0);
tls_netif_set_down();
/* Try to reconnect if auto_connect is set*/
tls_auto_reconnect();
return ;
}
//-------------------------------------------------------------------------
#if TLS_CONFIG_AP
static void tls_auto_reconnect_softap(void)
{
struct tls_param_ssid ssid;
struct tls_softap_info_t *apinfo;
struct tls_ip_info_t *ipinfo;
struct tls_param_ip ip_param;
struct tls_param_key key;
apinfo = tls_mem_alloc(sizeof(struct tls_softap_info_t));
if (apinfo == NULL)
{
return ;
}
ipinfo = tls_mem_alloc(sizeof(struct tls_ip_info_t));
if (ipinfo == NULL)
{
tls_mem_free(apinfo);
return ;
}
tls_param_get(TLS_PARAM_ID_SOFTAP_SSID, (void*) &ssid, TRUE);
memcpy(apinfo->ssid, ssid.ssid, ssid.ssid_len);
apinfo->ssid[ssid.ssid_len] = '\0';
tls_param_get(TLS_PARAM_ID_SOFTAP_ENCRY, (void*) &apinfo->encrypt, TRUE);
tls_param_get(TLS_PARAM_ID_SOFTAP_CHANNEL, (void*) &apinfo->channel, TRUE);
tls_param_get(TLS_PARAM_ID_SOFTAP_KEY, (void*) &key, TRUE);
apinfo->keyinfo.key_len = key.key_length;
apinfo->keyinfo.format = key.key_format;
apinfo->keyinfo.index = key.key_index;
memcpy(apinfo->keyinfo.key, key.psk, key.key_length);
tls_param_get(TLS_PARAM_ID_SOFTAP_IP, &ip_param, TRUE);
/*ip配置信息:ip地址,掩码,dns名称*/
memcpy(ipinfo->ip_addr, ip_param.ip, 4);
memcpy(ipinfo->netmask, ip_param.netmask, 4);
tls_param_get(TLS_PARAM_ID_DNSNAME, ipinfo->dnsname, FALSE);
tls_wifi_softap_create(apinfo, ipinfo);
tls_mem_free(apinfo);
tls_mem_free(ipinfo);
return ;
}
//-------------------------------------------------------------------------
#endif
void tls_auto_reconnect(void)
{
struct tls_param_ssid ssid;
u8 auto_reconnect = 0xff;
u8 wireless_protocol = 0;
#if 0
u8 i = 0;
while (i < 200)
{
if (tls_wifi_get_oneshot_flag())
{
/*oneshot config ongoing,do not reconnect WiFi*/
return ;
} tls_os_time_delay(1);
i++;
}
#endif
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_GET, &auto_reconnect);
if (auto_reconnect == WIFI_AUTO_CNT_OFF)
{
return ;
}
else if (auto_reconnect == WIFI_AUTO_CNT_TMP_OFF)
{
auto_reconnect = WIFI_AUTO_CNT_ON;
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_SET, &auto_reconnect);
return ; //tmparary return, for active "DISCONNECT" , such as AT CMD
}
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void*) &wireless_protocol, TRUE);
switch (wireless_protocol)
{
case TLS_PARAM_IEEE80211_INFRA:
#if TLS_CONFIG_AP
case (TLS_PARAM_IEEE80211_INFRA | TLS_PARAM_IEEE80211_SOFTAP):
#endif
{
struct tls_param_original_key origin_key;
struct tls_param_bssid bssid;
tls_param_get(TLS_PARAM_ID_BSSID, (void*) &bssid, TRUE);
tls_param_get(TLS_PARAM_ID_SSID, (void*) &ssid, TRUE);
tls_param_get(TLS_PARAM_ID_ORIGIN_KEY, (void*) &origin_key, TRUE);
if (bssid.bssid_enable)
{
if(ssid.ssid_len)
{
tls_wifi_connect_by_ssid_bssid(ssid.ssid, ssid.ssid_len, bssid.bssid, origin_key.psk, origin_key.key_length);
}
else
{
tls_wifi_connect_by_bssid(bssid.bssid, origin_key.psk, origin_key.key_length);
}
}
else if(ssid.ssid_len)
{
tls_wifi_connect(ssid.ssid, ssid.ssid_len, origin_key.psk, origin_key.key_length);
}
}
break;
#if TLS_CONFIG_AP
case TLS_PARAM_IEEE80211_SOFTAP:
{
tls_auto_reconnect_softap();
}
break;
#endif
default:
break;
}
return ;
}
//-------------------------------------------------------------------------
#if TLS_CONFIG_RMMS
static void tls_proc_rmms(struct rmms_msg *msg)
{
int err;
struct tls_hostif *hif = tls_get_hostif();
if (0 == hif->rmms_status)
{
hif->rmms_status = 1;
err = tls_hostif_cmd_handler(HOSTIF_RMMS_AT_CMD, (char*)msg, 6+strlen(
(char*)(msg->CmdStr)));
if (0 != err)
{
tls_mem_free(msg);
hif->rmms_status = 0;
}
}
return ;
}
//-------------------------------------------------------------------------
#endif
/*
* sys task stack
*/
static u32 sys_task_stk[SYS_TASK_STK_SIZE];
void tls_sys_task(void *data)
{
u8 err;
struct tls_sys_msg *msg;
u8 auto_reconnect = WIFI_AUTO_CNT_OFF;
//u8 oneshotflag = 0;
//u8 auto_mode = 0;
for (;;)
{
err = tls_os_queue_receive(msg_queue, (void **) &msg, 0, 0);
if (!err)
{
switch (msg->msg)
{
case SYS_MSG_NET_UP:
sys_net_up();
break;
#if TLS_CONFIG_AP
case SYS_MSG_NET2_UP:
sys_net2_up();
break;
case SYS_MSG_NET2_DOWN:
sys_net2_down();
break;
case SYS_MSG_NET2_FAIL:
sys_net2_down();
tls_auto_reconnect();
break;
#endif
case SYS_MSG_NET_DOWN:
sys_net_down();
break;
case SYS_MSG_CONNECT_FAILED:
sys_net_down();
break;
case SYS_MSG_AUTO_MODE_RUN:
/*restore WiFi auto reconnect Tmp OFF*/
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_GET,
&auto_reconnect);
if (auto_reconnect == WIFI_AUTO_CNT_TMP_OFF)
{
auto_reconnect = WIFI_AUTO_CNT_ON;
tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_SET,
&auto_reconnect);
}
tls_auto_reconnect();
break;
#if TLS_CONFIG_RMMS
case SYS_MSG_RMMS:
tls_proc_rmms(msg->data);
break;
#endif
default:
break;
}
tls_mem_free(msg);
}
else
{
}
}
}
//-------------------------------------------------------------------------
void tls_sys_send_msg(u32 msg, void *data)
{
struct tls_sys_msg *pmsg;
pmsg = tls_mem_alloc(sizeof(struct tls_sys_msg));
if (NULL != pmsg)
{
memset(pmsg, 0, sizeof(struct tls_sys_msg));
pmsg->msg = msg;
pmsg->data = data;
tls_os_queue_send(msg_queue, pmsg, 0);
}
return ;
}
//-------------------------------------------------------------------------
void tls_sys_auto_mode_run(void)
{
tls_sys_send_msg(SYS_MSG_AUTO_MODE_RUN, NULL);
}
//-------------------------------------------------------------------------
static void tls_sys_net_up(void)
{
tls_sys_send_msg(SYS_MSG_NET_UP, NULL);
}
//-------------------------------------------------------------------------
#if TLS_CONFIG_AP
static void tls_sys_net2_up(void)
{
tls_sys_send_msg(SYS_MSG_NET2_UP, NULL);
}
//-------------------------------------------------------------------------
static void tls_sys_net2_down(void)
{
tls_sys_send_msg(SYS_MSG_NET2_DOWN, NULL);
}
static void tls_sys_net2_fail(void)
{
tls_sys_send_msg(SYS_MSG_NET2_FAIL, NULL);
}
#endif
static void tls_sys_net_down(void)
{
tls_sys_send_msg(SYS_MSG_NET_DOWN, NULL);
}
//-------------------------------------------------------------------------
static void tls_sys_connect_failed(void)
{
tls_sys_send_msg(SYS_MSG_CONNECT_FAILED, NULL);
}
//-------------------------------------------------------------------------
static void sys_net_status_changed(u8 status)
{
#if TLS_CONFIG_TLS_DEBUG
struct tls_ethif *ethif;
#endif
#if TLS_CONFIG_AP
u8 wireless_protocol = 0;
#endif
bool enable = FALSE;
switch (status)
{
case NETIF_WIFI_JOIN_SUCCESS:
TLS_DBGPRT_INFO("join net success\n");
tls_sys_net_up();
break;
case NETIF_WIFI_JOIN_FAILED:
{
TLS_DBGPRT_INFO("join net failed\n");
}
tls_sys_connect_failed();
break;
case NETIF_WIFI_DISCONNECTED:
{
TLS_DBGPRT_INFO("net disconnected\n");
}
tls_sys_net_down();
break;
case NETIF_IP_NET_UP:
tls_netif_set_status(1);
/*when DHCP enable, IP_NET_UP Report, set wifi powersaving flag according to TLS_PARAM_ID_PSM*/
tls_param_get(TLS_PARAM_ID_PSM, &enable, TRUE);
tls_wifi_set_psflag(enable, FALSE);
#if TLS_CONFIG_TLS_DEBUG
ethif = tls_netif_get_ethif();
TLS_DBGPRT_INFO("net up ==> ip = %v\n", ethif->ip_addr.addr);
#endif
#if TLS_CONFIG_AP
tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void*) &wireless_protocol,
TRUE);
if ((TLS_PARAM_IEEE80211_SOFTAP &wireless_protocol) &&
(WM_WIFI_JOINED != tls_wifi_softap_get_state()))
{
tls_auto_reconnect_softap();
}
#endif
//#if TLS_CONFIG_RMMS
// tls_rmms_start();
//#endif
break;
#if TLS_CONFIG_AP
case NETIF_WIFI_SOFTAP_SUCCESS:
TLS_DBGPRT_INFO("softap create success.\n");
tls_sys_net2_up();
break;
case NETIF_WIFI_SOFTAP_FAILED:
TLS_DBGPRT_INFO("softap create failed.\n");
tls_sys_net2_fail();
break;
case NETIF_WIFI_SOFTAP_CLOSED:
TLS_DBGPRT_INFO("softap closed.\n");
tls_sys_net2_down();
break;
case NETIF_IP_NET2_UP:
#if TLS_CONFIG_TLS_DEBUG
ethif = tls_netif_get_ethif2();
TLS_DBGPRT_INFO("net up ==> ip = %v\n", ethif->ip_addr.addr);
#endif
break;
#endif
default:
break;
}
}
//-------------------------------------------------------------------------
int tls_sys_init()
{
int err;
/* create messge queue */
#define SYS_MSG_SIZE 20
err = tls_os_queue_create(&msg_queue, SYS_MSG_SIZE);
if (err)
{
return - 1;
}
/* create task */
tls_os_task_create(NULL, "Sys Task", tls_sys_task, (void*)0, (void*)
&sys_task_stk, /* task's stack start address */
SYS_TASK_STK_SIZE *sizeof(u32), /* task's stack size, unit:byte */
TLS_SYS_TASK_PRIO, 0);
tls_netif_add_status_event(sys_net_status_changed);
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef TLS_SYS_H
#define TLS_SYS_H
#include "wm_type_def.h"
#include "wm_params.h"
#define SYS_MSG_NET_UP 1
#define SYS_MSG_NET_DOWN 2
#define SYS_MSG_CONNECT_FAILED 3
#define SYS_MSG_AUTO_MODE_RUN 4
#define SYS_MSG_NET2_UP 5
#define SYS_MSG_NET2_DOWN 6
#define SYS_MSG_NET2_FAIL 7
#define SYS_MSG_RMMS 8
int tls_sys_init(void);
void tls_auto_reconnect(void);
#endif /* end of TLS_SYS_H */
+402
View File
@@ -0,0 +1,402 @@
/*****************************************************************************
*
* File Name : wm_main.c
*
* Description: wm main
*
* Copyright (c) 2014 Winner Micro Electronic Design Co., Ltd.
* All rights reserved.
*
* Author :
*
* Date : 2014-6-14
*****************************************************************************/
#include <string.h>
#include "wm_irq.h"
#include "tls_sys.h"
#include "wm_regs.h"
#include "wm_type_def.h"
#include "wm_timer.h"
#include "wm_irq.h"
#include "wm_params.h"
#include "wm_hostspi.h"
#include "wm_flash.h"
#include "wm_fls_gd25qxx.h"
#include "wm_internal_flash.h"
#include "wm_efuse.h"
#include "wm_debug.h"
#include "wm_netif.h"
#include "wm_at_ri_init.h"
#include "wm_config.h"
#include "wm_osal.h"
#include "wm_http_client.h"
#include "wm_cpu.h"
#include "misc.h"
#include "wm_webserver.h"
#include "wm_io.h"
#include "wm_mem.h"
#include "wm_wl_task.h"
#include "wm_wl_timers.h"
#include "wm_watchdog.h"
#ifdef TLS_CONFIG_HARD_CRYPTO
#include "wm_crypto_hard.h"
#endif
#include "wm_gpio_afsel.h"
#include "wm_pmu.h"
/* c librayr mutex */
tls_os_sem_t *libc_sem;
/*----------------------------------------------------------------------------
* Standard Library multithreading interface
*---------------------------------------------------------------------------*/
#ifndef __MICROLIB
/*--------------------------- _mutex_initialize -----------------------------*/
int _mutex_initialize (u32 *mutex) {
/* Allocate and initialize a system mutex. */
//tls_os_sem_create(&libc_sem, 1);
//mutex = (u32 *)libc_sem;
return(1);
}
/*--------------------------- _mutex_acquire --------------------------------*/
void _mutex_acquire (u32 *mutex) {
//u8 err;
/* Acquire a system mutex, lock stdlib resources. */
tls_os_sem_acquire(libc_sem, 0);
}
/*--------------------------- _mutex_release --------------------------------*/
void _mutex_release (u32 *mutex) {
/* Release a system mutex, unlock stdlib resources. */
tls_os_sem_release(libc_sem);
}
#endif
#define TASK_START_STK_SIZE 1200 /* Size of each task's stacks (# of WORDs) */
u32 TaskStartStk[TASK_START_STK_SIZE];
#ifdef TLS_CONFIG_HTTP_CLIENT_TASK
u8 pSession_flag=0;
#endif
#define FW_MAJOR_VER 0x03
#define FW_MINOR_VER 0x04
#define FW_PATCH_VER 0x08
const char FirmWareVer[4] = {
'G',
FW_MAJOR_VER, /* Main version */
FW_MINOR_VER, /* Subversion */
FW_PATCH_VER /* Internal version */
};
const char HwVer[6] = {
'H',
0x1,
0x0,
0x0,
0x0,
0x0
};
extern const char WiFiVer[];
extern u8 tx_gain_group[];
extern void *tls_wl_init(u8 *tx_gain, u8* mac_addr, u8 *hwver);
extern int wpa_supplicant_init(u8 *mac_addr);
extern void tls_sys_auto_mode_run(void);
extern void tls_spi_slave_sel(u16 slave);
extern void EarlyInit(void);
extern void UserMain(void);
extern void tls_fls_layout_init(void);
extern void Debug_UartInit(void);
void task_start (void *data);
void tls_os_timer_init(void)
{
tls_sys_clk sysclk;
tls_sys_clk_get(&sysclk);
SysTick_Config(sysclk.cpuclk*UNIT_MHZ/HZ);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
}
/****************/
/* main program */
/****************/
void vApplicationIdleHook( void )
{
/* clear watch dog interrupt */
tls_watchdog_clr();
#if !defined(__CC_ARM)
__asm volatile ("wfi");
#else
__WFI();
#endif
return;
}
void tls_exception_handler(unsigned int *sp, unsigned int exceptinfo)
{
int i = 0;
u32 value = 0;
value = (*(volatile int *)0xE000ED28);
switch(exceptinfo)
{
case 1:
printf("mem fault:\n");
if (value&0xFF)
{
printf("E000_ED28 Val:%x\n", value&0xFF);
}
break;
case 2:
printf("bus fault:\n");
if ((value>>8)&0xFF)
{
printf("E000_ED29 Val:%x\n", ((value>>8)&0xFF));
}
break;
case 3:
printf("usage fault:\n");
if ((value>>16)&0x3FF)
{
printf("E000_ED2A Val:%x\n", ((value>>16)&0x3FF));
}
break;
case 0:
default:
printf("hard fault:\n");
value = *(volatile int *)0xE000ED2C;
if (value)
{
printf("E000_ED2C Val:%x\n", value);
}
break;
}
// printf("Stack:%08p\n", sp);
// printf("StackInfo:\n");
for (i = 0; i < 16; i++)
{
printf("%08x\n", *sp++);
}
while(1);
}
void wm_gpio_config()
{
/* must call first */
wm_gpio_af_disable();
/* UART0_TX-PA04 UART0_RX-PA05 */
wm_uart0_tx_config(WM_IO_PA_04);
wm_uart0_rx_config(WM_IO_PA_05);
/* UART1_RX-PB11 UART1_TX-PB12 */
wm_uart1_rx_config(WM_IO_PB_11);
wm_uart1_tx_config(WM_IO_PB_12);
#if WM_CONFIG_DEBUG_UART2
/* UART2_RX-PA00 UART2_TX-PA01 */
wm_uart2_rx_config(WM_IO_PA_00);
wm_uart2_tx_scio_config(WM_IO_PA_01);
#endif
extern void pre_gpio_config();
pre_gpio_config();
/*MASTER SPI configuratioin*/
//wm_spi_cs_config(WM_IO_PB_15);
//wm_spi_ck_config(WM_IO_PB_16);
wm_spi_di_config(WM_IO_PB_17);
//wm_spi_do_config(WM_IO_PB_18);
}
bool debug_monitor_enable(void) {
volatile uint32_t *dhcsr = (uint32_t*)0xE000EDF0;
if ((*dhcsr & 0x1) != 0) {
printf("Halting Debug Enabled - Can't Enable Monitor Mode Debug!");
return false;
}
volatile uint32_t *demcr = (uint32_t*)0xE000EDFC;
const uint32_t mon_en_bit = 16;
*demcr |= 1 << mon_en_bit;
// Priority for DebugMonitor Exception is bits[7:0].
// We will use the lowest priority so other ISRs can
// fire while in the DebugMonitor Interrupt
volatile uint32_t *shpr3 = (uint32_t *)0xE000ED20;
*shpr3 = 0xff;
printf("Monitor Mode Debug Enabled!");
return true;
}
void tls_fix_wifi_irq_priority()
{
tls_irq_set_priority(RX_INT, IRQ_MAX_SYSCALL_PRIORITY);
}
int main(void)
{
tls_sys_clk_set(CPU_CLK_80M);
tls_pmu_clk_select(0);
tls_os_init(NULL);
Debug_UartInit();/*initialize debug uart for mapping to printf*/
/* before use malloc() function, must create mutex used by c_lib */
tls_os_sem_create(&libc_sem, 1);
EarlyInit();
{
tls_os_task_create(NULL, NULL,
task_start,
(void *)0,
(void *)&TaskStartStk[0], /* task's stack start address */
TASK_START_STK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
1,
0);
}
/* initial os ticker */
tls_os_timer_init();
//debug_monitor_enable();
tls_os_start_scheduler();
return 0;
}
void disp_version_info(void)
{
TLS_DBGPRT_INFO("\n\n");
TLS_DBGPRT_INFO("****************************************************************\n");
TLS_DBGPRT_INFO("* *\n");
TLS_DBGPRT_INFO("* Copyright (C) 2014 WinnerMicro Co. Ltd. *\n");
TLS_DBGPRT_INFO("* All rights reserved. *\n");
TLS_DBGPRT_INFO("* WinnerMicro Firmware Version: %x.%x.%X *\n",
FirmWareVer[1], FirmWareVer[2], FirmWareVer[3]);
TLS_DBGPRT_INFO("* WinnerMicro Hardware Version: %x.%x.%x.%x.%x *\n",
HwVer[1], HwVer[2], HwVer[3],HwVer[4],HwVer[5]);
TLS_DBGPRT_INFO("* *\n");
TLS_DBGPRT_INFO("* WinnerMicro Wi-Fi Lib Version: %x.%x.%x *\n",
WiFiVer[0], WiFiVer[1], WiFiVer[2]);
TLS_DBGPRT_INFO("****************************************************************\n");
}
/*****************************************************************************
* Function Name // task_start
* Descriptor // before create multi_task, we create a task_start task
* // in this example, this task display the cpu usage
* Input
* Output
* Return
****************************************************************************/
void task_start (void *data)
{
u8 mac_addr[6] = {0x00,0x25,0x08,0x09,0x01,0x0F};
/* must call first to configure gpio Alternate functions according the hardware design */
wm_gpio_config();
#if TLS_CONFIG_HARD_CRYPTO
tls_crypto_init();
#endif
#if (TLS_CONFIG_LS_SPI)
tls_spi_init();
tls_spifls_init();
#endif
tls_fls_init();
/*initialize flash layout parameter according to image type*/
tls_fls_layout_init();
/*PARAM GAIN,MAC default*/
tls_ft_param_init();
tls_param_load_factory_default();
tls_param_init(); /*add param to init sysparam_lock sem*/
tls_get_tx_gain(&tx_gain_group[0]);
TLS_DBGPRT_INFO("tx gain ");
TLS_DBGPRT_DUMP((char *)(&tx_gain_group[0]), 12);
if (tls_wifi_mem_cfg(WIFI_MEM_START_ADDR, 7, 7)) /*wifi tx&rx mem customized interface*/
{
TLS_DBGPRT_INFO("wl mem initial failured\n");
}
tls_get_mac_addr(&mac_addr[0]);
TLS_DBGPRT_INFO("mac addr ");
TLS_DBGPRT_DUMP((char *)(&mac_addr[0]), 6);
if(tls_wl_init(NULL, &mac_addr[0], NULL) == NULL){
TLS_DBGPRT_INFO("wl driver initial failured\n");
}
if (wpa_supplicant_init(mac_addr)) {
TLS_DBGPRT_INFO("supplicant initial failured\n");
}
tls_fix_wifi_irq_priority();
tls_ethernet_init();
tls_sys_init();
/*HOSTIF&UART*/
#if TLS_CONFIG_HOSTIF
tls_hostif_init();
#if (TLS_CONFIG_HS_SPI)
tls_hspi_init();
#endif
#if TLS_CONFIG_UART
//tls_uart_init();
#endif
#if TLS_CONFIG_HTTP_CLIENT_TASK
// http_client_task_init();
#endif
#endif
/* call user main function */
UserMain();
tls_sys_auto_mode_run();
NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP, ENABLE);
for (;;)
{
#if 1
tls_os_time_delay(0x10000000);
#else
//printf("start up\n");
extern void tls_os_disp_task_stat_info(void);
tls_os_disp_task_stat_info();
tls_os_time_delay(1000);
#endif
}
}