未验证 提交 1e25cea9 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #2519 from WinnerMicro/master

[BSP]add BSP for Winner Micro W60X devices。
#
# Automatically generated file; DO NOT EDIT.
# RT-Thread Configuration
#
#
# RT-Thread Kernel
#
CONFIG_RT_NAME_MAX=8
# CONFIG_RT_USING_SMP is not set
CONFIG_RT_ALIGN_SIZE=4
# CONFIG_RT_THREAD_PRIORITY_8 is not set
CONFIG_RT_THREAD_PRIORITY_32=y
# CONFIG_RT_THREAD_PRIORITY_256 is not set
CONFIG_RT_THREAD_PRIORITY_MAX=32
CONFIG_RT_TICK_PER_SECOND=1000
CONFIG_RT_USING_OVERFLOW_CHECK=y
CONFIG_RT_USING_HOOK=y
CONFIG_RT_USING_IDLE_HOOK=y
CONFIG_RT_IDEL_HOOK_LIST_SIZE=4
CONFIG_IDLE_THREAD_STACK_SIZE=256
CONFIG_RT_USING_TIMER_SOFT=y
CONFIG_RT_TIMER_THREAD_PRIO=4
CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
CONFIG_RT_DEBUG=y
CONFIG_RT_DEBUG_COLOR=y
# CONFIG_RT_DEBUG_INIT_CONFIG is not set
# CONFIG_RT_DEBUG_THREAD_CONFIG is not set
# CONFIG_RT_DEBUG_SCHEDULER_CONFIG is not set
# CONFIG_RT_DEBUG_IPC_CONFIG is not set
# CONFIG_RT_DEBUG_TIMER_CONFIG is not set
# CONFIG_RT_DEBUG_IRQ_CONFIG is not set
# CONFIG_RT_DEBUG_MEM_CONFIG is not set
# CONFIG_RT_DEBUG_SLAB_CONFIG is not set
# CONFIG_RT_DEBUG_MEMHEAP_CONFIG is not set
# CONFIG_RT_DEBUG_MODULE_CONFIG is not set
#
# Inter-Thread communication
#
CONFIG_RT_USING_SEMAPHORE=y
CONFIG_RT_USING_MUTEX=y
CONFIG_RT_USING_EVENT=y
CONFIG_RT_USING_MAILBOX=y
CONFIG_RT_USING_MESSAGEQUEUE=y
# CONFIG_RT_USING_SIGNALS is not set
#
# Memory Management
#
CONFIG_RT_USING_MEMPOOL=y
# CONFIG_RT_USING_MEMHEAP is not set
# CONFIG_RT_USING_NOHEAP is not set
CONFIG_RT_USING_SMALL_MEM=y
# CONFIG_RT_USING_SLAB is not set
# CONFIG_RT_USING_MEMTRACE is not set
CONFIG_RT_USING_HEAP=y
#
# Kernel Device Object
#
CONFIG_RT_USING_DEVICE=y
# CONFIG_RT_USING_DEVICE_OPS is not set
# CONFIG_RT_USING_INTERRUPT_INFO is not set
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=128
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
CONFIG_RT_VER_NUM=0x40001
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
#
# RT-Thread Components
#
CONFIG_RT_USING_COMPONENTS_INIT=y
CONFIG_RT_USING_USER_MAIN=y
CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048
CONFIG_RT_MAIN_THREAD_PRIORITY=10
#
# C++ features
#
# CONFIG_RT_USING_CPLUSPLUS is not set
#
# Command shell
#
CONFIG_RT_USING_FINSH=y
CONFIG_FINSH_THREAD_NAME="tshell"
CONFIG_FINSH_USING_HISTORY=y
CONFIG_FINSH_HISTORY_LINES=5
CONFIG_FINSH_USING_SYMTAB=y
CONFIG_FINSH_USING_DESCRIPTION=y
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
CONFIG_FINSH_THREAD_PRIORITY=20
CONFIG_FINSH_THREAD_STACK_SIZE=4096
CONFIG_FINSH_CMD_SIZE=80
# CONFIG_FINSH_USING_AUTH is not set
CONFIG_FINSH_USING_MSH=y
CONFIG_FINSH_USING_MSH_DEFAULT=y
CONFIG_FINSH_USING_MSH_ONLY=y
CONFIG_FINSH_ARG_MAX=10
#
# Device virtual file system
#
CONFIG_RT_USING_DFS=y
CONFIG_DFS_USING_WORKDIR=y
CONFIG_DFS_FILESYSTEMS_MAX=4
CONFIG_DFS_FILESYSTEM_TYPES_MAX=4
CONFIG_DFS_FD_MAX=16
# CONFIG_RT_USING_DFS_MNTTABLE is not set
# CONFIG_RT_USING_DFS_ELMFAT is not set
CONFIG_RT_USING_DFS_DEVFS=y
# CONFIG_RT_USING_DFS_ROMFS is not set
# CONFIG_RT_USING_DFS_RAMFS is not set
# CONFIG_RT_USING_DFS_UFFS is not set
# CONFIG_RT_USING_DFS_JFFS2 is not set
# CONFIG_RT_USING_DFS_NFS is not set
#
# Device Drivers
#
CONFIG_RT_USING_DEVICE_IPC=y
CONFIG_RT_PIPE_BUFSZ=512
CONFIG_RT_USING_SERIAL=y
CONFIG_RT_SERIAL_USING_DMA=y
CONFIG_RT_SERIAL_RB_BUFSZ=64
# CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_HWTIMER is not set
# CONFIG_RT_USING_CPUTIME is not set
# CONFIG_RT_USING_I2C is not set
CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_ADC is not set
# CONFIG_RT_USING_PWM is not set
# CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_MTD is not set
# CONFIG_RT_USING_PM is not set
# CONFIG_RT_USING_RTC is not set
# CONFIG_RT_USING_SDIO is not set
# CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set
#
# Using WiFi
#
CONFIG_RT_USING_WIFI=y
CONFIG_RT_WLAN_DEVICE_STA_NAME="wlan0"
CONFIG_RT_WLAN_DEVICE_AP_NAME="wlan1"
CONFIG_RT_WLAN_DEFAULT_PROT="lwip"
CONFIG_RT_WLAN_SCAN_WAIT_MS=10000
CONFIG_RT_WLAN_CONNECT_WAIT_MS=10000
CONFIG_RT_WLAN_SSID_MAX_LENGTH=32
CONFIG_RT_WLAN_PASSWORD_MAX_LENGTH=32
CONFIG_RT_WLAN_SCAN_SORT=y
CONFIG_RT_WLAN_CFG_INFO_MAX=3
CONFIG_RT_WLAN_WORKQUEUE_THREAD_NAME="wlan_job"
CONFIG_RT_WLAN_WORKQUEUE_THREAD_SIZE=2048
CONFIG_RT_WLAN_WORKQUEUE_THREAD_PRIO=22
CONFIG_RT_WLAN_DEV_EVENT_NUM=2
# CONFIG_RT_WLAN_PROT_LWIP_PBUF_FORCE is not set
# CONFIG_RT_WLAN_DEBUG is not set
#
# Using USB
#
# CONFIG_RT_USING_USB_HOST is not set
# CONFIG_RT_USING_USB_DEVICE is not set
#
# POSIX layer and C standard library
#
CONFIG_RT_USING_LIBC=y
# CONFIG_RT_USING_PTHREADS is not set
CONFIG_RT_USING_POSIX=y
# CONFIG_RT_USING_POSIX_MMAP is not set
# CONFIG_RT_USING_POSIX_TERMIOS is not set
# CONFIG_RT_USING_POSIX_AIO is not set
# CONFIG_RT_USING_MODULE is not set
#
# Network
#
#
# Socket abstraction layer
#
CONFIG_RT_USING_SAL=y
#
# protocol stack implement
#
CONFIG_SAL_USING_LWIP=y
CONFIG_SAL_USING_POSIX=y
CONFIG_SAL_PROTO_FAMILIES_NUM=4
#
# light weight TCP/IP stack
#
CONFIG_RT_USING_LWIP=y
# CONFIG_RT_USING_LWIP141 is not set
CONFIG_RT_USING_LWIP202=y
# CONFIG_RT_USING_LWIP210 is not set
# CONFIG_RT_USING_LWIP_IPV6 is not set
CONFIG_RT_LWIP_IGMP=y
CONFIG_RT_LWIP_ICMP=y
# CONFIG_RT_LWIP_SNMP is not set
CONFIG_RT_LWIP_DNS=y
CONFIG_RT_LWIP_DHCP=y
CONFIG_IP_SOF_BROADCAST=1
CONFIG_IP_SOF_BROADCAST_RECV=1
#
# Static IPv4 Address
#
CONFIG_RT_LWIP_IPADDR="192.168.1.30"
CONFIG_RT_LWIP_GWADDR="192.168.1.1"
CONFIG_RT_LWIP_MSKADDR="255.255.255.0"
CONFIG_RT_LWIP_UDP=y
CONFIG_RT_LWIP_TCP=y
CONFIG_RT_LWIP_RAW=y
# CONFIG_RT_LWIP_PPP is not set
CONFIG_RT_MEMP_NUM_NETCONN=8
CONFIG_RT_LWIP_PBUF_NUM=16
CONFIG_RT_LWIP_RAW_PCB_NUM=4
CONFIG_RT_LWIP_UDP_PCB_NUM=4
CONFIG_RT_LWIP_TCP_PCB_NUM=4
CONFIG_RT_LWIP_TCP_SEG_NUM=40
CONFIG_RT_LWIP_TCP_SND_BUF=10240
CONFIG_RT_LWIP_TCP_WND=10240
CONFIG_RT_LWIP_TCPTHREAD_PRIORITY=10
CONFIG_RT_LWIP_TCPTHREAD_MBOX_SIZE=8
CONFIG_RT_LWIP_TCPTHREAD_STACKSIZE=1024
CONFIG_LWIP_NO_RX_THREAD=y
CONFIG_LWIP_NO_TX_THREAD=y
CONFIG_RT_LWIP_ETHTHREAD_PRIORITY=12
CONFIG_RT_LWIP_ETHTHREAD_STACKSIZE=1024
CONFIG_RT_LWIP_ETHTHREAD_MBOX_SIZE=8
# CONFIG_RT_LWIP_REASSEMBLY_FRAG is not set
CONFIG_LWIP_NETIF_STATUS_CALLBACK=1
CONFIG_SO_REUSE=1
CONFIG_LWIP_SO_RCVTIMEO=1
CONFIG_LWIP_SO_SNDTIMEO=1
CONFIG_LWIP_SO_RCVBUF=1
# CONFIG_RT_LWIP_NETIF_LOOPBACK is not set
CONFIG_LWIP_NETIF_LOOPBACK=0
# CONFIG_RT_LWIP_STATS is not set
# CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set
# CONFIG_RT_LWIP_DEBUG is not set
#
# Modbus master and slave stack
#
# CONFIG_RT_USING_MODBUS is not set
#
# AT commands
#
# CONFIG_RT_USING_AT is not set
CONFIG_LWIP_USING_DHCPD=y
CONFIG_DHCPD_SERVER_IP="192.168.169.1"
# CONFIG_DHCPD_USING_ROUTER is not set
# CONFIG_LWIP_USING_CUSTOMER_DNS_SERVER is not set
#
# VBUS(Virtual Software BUS)
#
# CONFIG_RT_USING_VBUS is not set
#
# Utilities
#
# CONFIG_RT_USING_LOGTRACE is not set
# CONFIG_RT_USING_RYM is not set
CONFIG_RT_USING_ULOG=y
# CONFIG_ULOG_OUTPUT_LVL_A is not set
# CONFIG_ULOG_OUTPUT_LVL_E is not set
# CONFIG_ULOG_OUTPUT_LVL_W is not set
CONFIG_ULOG_OUTPUT_LVL_I=y
# CONFIG_ULOG_OUTPUT_LVL_D is not set
CONFIG_ULOG_OUTPUT_LVL=6
CONFIG_ULOG_USING_ISR_LOG=y
CONFIG_ULOG_ASSERT_ENABLE=y
CONFIG_ULOG_LINE_BUF_SIZE=128
# CONFIG_ULOG_USING_ASYNC_OUTPUT is not set
#
# log format
#
# CONFIG_ULOG_OUTPUT_FLOAT is not set
CONFIG_ULOG_USING_COLOR=y
CONFIG_ULOG_OUTPUT_TIME=y
# CONFIG_ULOG_TIME_USING_TIMESTAMP is not set
CONFIG_ULOG_OUTPUT_LEVEL=y
CONFIG_ULOG_OUTPUT_TAG=y
# CONFIG_ULOG_OUTPUT_THREAD_NAME is not set
CONFIG_ULOG_BACKEND_USING_CONSOLE=y
# CONFIG_ULOG_USING_FILTER is not set
# CONFIG_ULOG_USING_SYSLOG is not set
# CONFIG_RT_USING_UTEST is not set
#
# RT-Thread online packages
#
#
# IoT - internet of things
#
# CONFIG_PKG_USING_PAHOMQTT is not set
# CONFIG_PKG_USING_WEBCLIENT is not set
# CONFIG_PKG_USING_WEBNET is not set
# CONFIG_PKG_USING_MONGOOSE is not set
# CONFIG_PKG_USING_WEBTERMINAL is not set
# CONFIG_PKG_USING_CJSON is not set
# CONFIG_PKG_USING_JSMN is not set
# CONFIG_PKG_USING_LIBMODBUS is not set
# CONFIG_PKG_USING_LJSON is not set
# CONFIG_PKG_USING_EZXML is not set
# CONFIG_PKG_USING_NANOPB is not set
#
# Wi-Fi
#
#
# Marvell WiFi
#
# CONFIG_PKG_USING_WLANMARVELL is not set
#
# Wiced WiFi
#
# CONFIG_PKG_USING_WLAN_WICED is not set
# CONFIG_PKG_USING_RW007 is not set
# CONFIG_PKG_USING_COAP is not set
# CONFIG_PKG_USING_NOPOLL is not set
# CONFIG_PKG_USING_NETUTILS is not set
# CONFIG_PKG_USING_AT_DEVICE is not set
# CONFIG_PKG_USING_WIZNET is not set
#
# IoT Cloud
#
# CONFIG_PKG_USING_ONENET is not set
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
# CONFIG_PKG_USING_ALI_IOTKIT is not set
# CONFIG_PKG_USING_AZURE is not set
# CONFIG_PKG_USING_TENCENT_IOTKIT is not set
# CONFIG_PKG_USING_NIMBLE is not set
# CONFIG_PKG_USING_OTA_DOWNLOADER is not set
#
# security packages
#
# CONFIG_PKG_USING_MBEDTLS is not set
# CONFIG_PKG_USING_libsodium is not set
# CONFIG_PKG_USING_TINYCRYPT is not set
#
# language packages
#
# CONFIG_PKG_USING_LUA is not set
# CONFIG_PKG_USING_JERRYSCRIPT is not set
# CONFIG_PKG_USING_MICROPYTHON is not set
#
# multimedia packages
#
# CONFIG_PKG_USING_OPENMV is not set
# CONFIG_PKG_USING_MUPDF is not set
# CONFIG_PKG_USING_STEMWIN is not set
#
# tools packages
#
# CONFIG_PKG_USING_CMBACKTRACE is not set
# CONFIG_PKG_USING_EASYFLASH is not set
# CONFIG_PKG_USING_EASYLOGGER is not set
# CONFIG_PKG_USING_SYSTEMVIEW is not set
# CONFIG_PKG_USING_RDB is not set
# CONFIG_PKG_USING_QRCODE is not set
# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
# CONFIG_PKG_USING_ADBD is not set
#
# system packages
#
# CONFIG_PKG_USING_GUIENGINE is not set
# CONFIG_PKG_USING_CAIRO is not set
# CONFIG_PKG_USING_PIXMAN is not set
# CONFIG_PKG_USING_LWEXT4 is not set
# CONFIG_PKG_USING_PARTITION is not set
# CONFIG_PKG_USING_FAL is not set
# CONFIG_PKG_USING_SQLITE is not set
# CONFIG_PKG_USING_RTI is not set
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
# CONFIG_PKG_USING_CMSIS is not set
# CONFIG_PKG_USING_DFS_YAFFS is not set
# CONFIG_PKG_USING_LITTLEFS is not set
#
# peripheral libraries and drivers
#
# CONFIG_PKG_USING_SENSORS_DRIVERS is not set
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_AHT10 is not set
# CONFIG_PKG_USING_AP3216C is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# CONFIG_PKG_USING_ICM20608 is not set
# CONFIG_PKG_USING_U8G2 is not set
# CONFIG_PKG_USING_BUTTON is not set
# CONFIG_PKG_USING_MPU6XXX is not set
# CONFIG_PKG_USING_PCF8574 is not set
# CONFIG_PKG_USING_SX12XX is not set
# CONFIG_PKG_USING_SIGNAL_LED is not set
CONFIG_PKG_USING_WM_LIBRARIES=y
CONFIG_PKG_WM_LIBRARIES_PATH="/packages/peripherals/wm_libraries"
# CONFIG_PKG_USING_WM_LIBRARIES_V100 is not set
CONFIG_PKG_USING_WM_LIBRARIES_LATEST_VERSION=y
CONFIG_PKG_WM_LIBRARIES_VER="latest"
# CONFIG_PKG_USING_KENDRYTE_SDK is not set
#
# miscellaneous packages
#
# CONFIG_PKG_USING_LIBCSV is not set
# CONFIG_PKG_USING_OPTPARSE is not set
# CONFIG_PKG_USING_FASTLZ is not set
# CONFIG_PKG_USING_MINILZO is not set
# CONFIG_PKG_USING_QUICKLZ is not set
# CONFIG_PKG_USING_MULTIBUTTON is not set
# CONFIG_PKG_USING_CANFESTIVAL is not set
# CONFIG_PKG_USING_ZLIB is not set
# CONFIG_PKG_USING_DSTR is not set
# CONFIG_PKG_USING_TINYFRAME is not set
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
#
# samples: kernel and components samples
#
# CONFIG_PKG_USING_KERNEL_SAMPLES is not set
# CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
# CONFIG_PKG_USING_NETWORK_SAMPLES is not set
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
# CONFIG_PKG_USING_HELLO is not set
# CONFIG_PKG_USING_VI is not set
# CONFIG_PKG_USING_NNOM is not set
#
# Env config
#
# CONFIG_SYS_AUTO_UPDATE_PKGS is not set
# CONFIG_SYS_CREATE_MDK_IAR_PROJECT is not set
CONFIG_SYS_PKGS_DOWNLOAD_ACCELERATE=y
CONFIG_BSP_USING_WM_LIBRARIES=y
#
# W60x Device config
#
CONFIG_SOC_W600_A8xx=y
# CONFIG_SOC_W601_A8xx is not set
#
# Hardware Drivers Config
#
#
# On-chip Peripheral Drivers
#
CONFIG_BSP_USING_UART=y
CONFIG_BSP_USING_UART0=y
# CONFIG_BSP_USING_UART1 is not set
# CONFIG_BSP_USING_UART2 is not set
CONFIG_BSP_USING_PIN=y
CONFIG_BSP_USING_WIFI=y
# CONFIG_BSP_USING_HWTIMER is not set
# CONFIG_BSP_USING_PWM is not set
# CONFIG_BSP_USING_I2C is not set
# CONFIG_BSP_USING_SPI is not set
# CONFIG_BSP_USING_WDT is not set
# CONFIG_BSP_USING_RTC is not set
# CONFIG_BSP_USING_STANDBY is not set
#
# Offboard Peripheral Drivers
#
# CONFIG_BSP_USING_FLASH is not set
*.pyc
*.map
*.dblite
*.elf
*.bin
*.hex
*.axf
*.exe
*.pdb
*.idb
*.ilk
*.old
build
Debug
documentation/html
packages/
*~
*.o
*.obj
*.out
*.bak
*.dep
*.lib
*.i
*.d
.DS_Stor*
.config 3
.config 4
.config 5
Midea-X1
*.uimg
GPATH
GRTAGS
GTAGS
.vscode
JLinkLog.txt
JLinkSettings.ini
DebugConfig/
RTE/
settings/
*.uvguix*
cconfig.h
mainmenu "RT-Thread Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config RTT_DIR
string
option env="RTT_ROOT"
default "../.."
# you can change the RTT_ROOT default "../.." to your rtthread_root,
# example : default "F:/git_repositories/rt-thread"
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"
config ENV_DIR
string
option env="ENV_ROOT"
default "/"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "$ENV_DIR/tools/scripts/cmds/Kconfig"
source "$BSP_DIR/drivers/Kconfig"
# Winner Micro W60X 板级支持包
## 简介
W60X 芯片是[联盛德微电子](http://www.winnermicro.com)推出的一款嵌入式 Wi-Fi SoC 芯片。该芯片集成度高,所需外围器件少,性价比高。适用于 IoT(智能家庭)领域各种智能产品。高度集成的 Wi-Fi 功能是其主要功能;另外,该芯片集成 Cortex-M3 内核,内置 QFlash,SDIO、SPI、UART、GPIO、I²C、PWM、I²S、7816 等接口, 支持多种硬件加解密算法。
更多信息请查看`packages/wm_libraries/DOC 中的寄存器手册`
## 外设支持
| 驱动 | 支持情况 | 备注 |
| ---------- | :------: | :---------------------------------------------: |
| UART | 支持 | UART0/UART1/UART2 |
| GPIO | 支持 | 自动根据芯片型号选择引脚布局 |
| SPI | 支持 | 低速 SPI,支持 SPI BUS,8/32bit 主机模式 |
| SPI Flash | 支持 | 支持 W25QXX、SFUD |
| WDT | 支持 | 支持 |
| I2C | 支持 | 硬件 I2C |
| RTC | 支持 | 支持 ntp 同步、支持 Alarm |
| ADC | 支持 | 8 channel ADC 采集 CPU 温度采集(W601 支持) |
| PWM | 支持 | 5 channel PWM 输出 |
| Timer | 支持 | 5个Timers 独立工作 |
| WiFi | 支持 | 支持 IEEE802.11b/g/n,支持 sta、ap、ap+sta 模式 |
| 低功耗 | 支持 | 支持 WiFi 协议节电,支持 standby 深度节电 |
## 使用说明
使用说明分为如下两个章节:
- 快速上手
本章节是为刚接触 RT-Thread 的新手准备的使用说明,遵循简单的步骤即可将 RT-Thread 操作系统运行在该开发板上,看到实验效果 。
- 进阶使用
本章节是为需要在 RT-Thread 操作系统上使用更多开发板资源的开发者准备的。通过使用 ENV 工具对 BSP 进行配置,可以开启更多板载资源,实现更多高级功能。
### 快速上手
本 BSP 为开发者提供 MDK5 和 IAR 工程,并且支持 GCC 开发环境。下面以 MDK5 开发环境为例,介绍如何将系统运行起来。
#### 编译
1. env 工具中使用 `pkgs --update` 命令下载必要的软件包。
2. env 工具中使用 `scons --target=mdk5` 命令生成工程
2. 双击 project.uvprojx 文件,打开 MDK5 工程,完成程序的编译工作。
#### 下载
目前支持两种下载方式,下面将分别说明:
- JLink下载
将 JLink 连接到开发板,然后点击 MDK5 中的下载按钮即可下载程序到开发板。JLink 下载之前 **务必参考** `packages/wm_libraries/DOC` 目录下的 `《WM_W60X_SWD调试配置指南》`。
- 串口下载
程序编译正确无误后,会在 `Bin` 文件夹中生成 `.img` 固件,使用带有 Xmodem 协议的串口工具对固件进行下载(默认 UART0-115200)。串口下载参考 `packages/wm_libraries/DOC` 目录下的 `《WM_W60X_固件升级指导》`。
#### 运行结果
下载程序成功之后,系统会自动运行,会在`UART0`上看到 RT-Thread 的启动 logo 信息:
```bash
\ | /
- RT - Thread Operating System
/ | \ 4.0.1 build Mar 21 2019
2006 - 2019 Copyright by rt-thread team
```
- 默认串口`UART0` 波特率`115200`
### 进阶使用
此 BSP 默认只开启了 GPIO 和 UART0 的功能,如果需使用其他外设,需要利用 ENV 工具对 BSP 进行配置,步骤如下:
1. 在 bsp 下打开 env 工具。
2. 输入`menuconfig`命令配置工程,配置好之后保存退出。
3. 输入`pkgs --update`命令更新软件包。
4. 输入`scons --target=mdk5``scons --target=iar` 命令重新生成工程。
## 注意事项
> 使用 W600 芯片时,请注意芯片 Flash 的大小,区分 2M Flash 和 1M Flash。更多信息请查看 `packages/wm_libraries/DOC` 的文档:
- 《WM_W60X_2M_Flash布局说明》
- 《WM_W60X_2M_Flash参数区使用说明》
- 《WM_W60X_2M_Flash固件生成说明》
## 联系人信息
[RT_Thread](https://github.com/RT-Thread/rt-thread)
[WinnerMicro](https://github.com/WinnerMicro)
## 感谢
[flyingcys](https://github.com/flyingcys) < [294102238@qq.com](mailto:294102238@qq.com) >
\ No newline at end of file
FUNC void Setup (void) {
SP = _RDWORD(0x8010100); // Setup Stack Pointer
PC = _RDWORD(0x8010104); // Setup Program Counter
_WDWORD(0xE000ED08, 0x8010100); // Setup VTOR
}
LOAD %L INCREMENTAL // load the application
Setup(); // Setup for Running
g, _main
\ No newline at end of file
# for module compiling
import os
Import('RTT_ROOT')
cwd = str(Dir('#'))
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')
import os
import sys
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
from building import *
except:
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
print(RTT_ROOT)
exit(-1)
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
if rtconfig.PLATFORM == 'iar':
env.Replace(CCCOM = ['$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
env.Replace(ARFLAGS = [''])
env.Replace(LINKCOM = env["LINKCOM"] + ' --map project.map')
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
# make a building
DoBuilding(TARGET, objs)
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-02-13 tyx first implementation
*/
#include <rtthread.h>
#include <rtdevice.h>
int main(void)
{
/* set wifi work mode */
rt_wlan_set_mode(RT_WLAN_DEVICE_STA_NAME, RT_WLAN_STATION);
rt_wlan_set_mode(RT_WLAN_DEVICE_AP_NAME, RT_WLAN_AP);
return 0;
}
config BSP_USING_WM_LIBRARIES
bool
select PKG_USING_WM_LIBRARIES
default y
menu "W60x Device config"
choice
prompt "Device type"
default SOC_W600-A8xx
config SOC_W600_A8xx
bool "W600-A8xx"
config SOC_W601_A8xx
bool "W601-A8xx"
endchoice
endmenu
menu "Hardware Drivers Config"
menu "On-chip Peripheral Drivers"
menuconfig BSP_USING_UART
bool "Using UART"
select RT_USING_SERIAL
default y
if BSP_USING_UART
config BSP_USING_UART0
bool "Enabel UART 0"
default y
config BSP_USING_UART1
bool "Enabel UART 1"
default n
if BSP_USING_UART1
config WM_UART1_BAUDRATE
int "UART1 baudrate"
default 115200
config WM_UART1_RX_PIN
int "UART1 RX pin number"
default 31
config WM_UART1_TX_PIN
int "UART1 TX pin number"
default 32
endif
config BSP_USING_UART2
bool "Enabel UART 2"
default n
if BSP_USING_UART2
config WM_UART2_BAUDRATE
int "UART2 baudrate"
default 115200
config WM_UART2_RX_PIN
int "UART2 RX pin number"
default 13
config WM_UART2_TX_PIN
int "UART2 TX pin number"
default 14
endif
endif
config BSP_USING_PIN
bool "Using PIN"
select RT_USING_PIN
default y
config BSP_USING_WIFI
bool "Using WIFI"
select RT_USING_WIFI
select RT_USING_LWIP
default y
if SOC_W601_A8xx
menuconfig BSP_USING_ADC
bool "Enable ADC"
select RT_USING_ADC
default n
if BSP_USING_ADC
config USING_CPU_TEMP
bool "Enable CPU Temperature"
config USING_ADC_CH1
bool "Enable ADC Channel 1"
config USING_ADC_CH2
bool "Enable ADC Channel 2"
config USING_ADC_CH3
bool "Enable ADC Channel 3"
config USING_ADC_CH4
bool "Enable ADC Channel 4"
config USING_ADC_CH5
bool "Enable ADC Channel 5"
config USING_ADC_CH6
bool "Enable ADC Channel 6"
config USING_ADC_CH7
bool "Enable ADC Channel 7"
config USING_ADC_CH8
bool "Enable ADC Channel 8"
endif
endif
menuconfig BSP_USING_HWTIMER
bool "Enable HWTIMER"
select RT_USING_HWTIMER
default n
if BSP_USING_HWTIMER
config USING_HW_TIMER1
bool "Enable hw timer1"
config USING_HW_TIMER2
bool "Enable hw timer2"
config USING_HW_TIMER3
bool "Enable hw timer3"
config USING_HW_TIMER4
bool "Enable hw timer4"
config USING_HW_TIMER5
bool "Enable hw timer5"
endif
menuconfig BSP_USING_PWM
bool "Enable PWM"
select RT_USING_PWM
default n
if BSP_USING_PWM
config USING_PWM_CH1
bool "Enable pwm channel 1"
default n
if USING_PWM_CH1
config WM_PWM_CH1_PIN
int "wm pwm channel 1 pin number"
default 23
endif
config USING_PWM_CH2
bool "Enable pwm channel 2"
default n
if USING_PWM_CH2
config WM_PWM_CH2_PIN
int "wm pwm channel 2 pin number"
default 22
endif
config USING_PWM_CH3
bool "Enable pwm channel 3"
default n
if USING_PWM_CH3
config WM_PWM_CH3_PIN
int "wm pwm channel 3 pin number"
default 21
endif
config USING_PWM_CH4
bool "Enable pwm channel 4"
default n
if USING_PWM_CH4
config WM_PWM_CH4_PIN
int "wm pwm channel 4 pin number"
default 20
endif
config USING_PWM_CH5
bool "Enable pwm channel 5"
default n
if USING_PWM_CH5
config WM_PWM_CH5_PIN
int "wm pwm channel 5 pin number"
default 19
endif
endif
menuconfig BSP_USING_I2C
bool "Enable I2C"
select RT_USING_I2C
default n
if BSP_USING_I2C
config WM_HW_I2C_FREQ
int "wm hardware I2C frequency(HZ)"
default 200000
config WM_I2C_DAT_PIN
int "wm I2C DAT pin number"
default 19
config WM_I2C_SCL_PIN
int "wm I2C SCL pin number"
default 18
endif
menuconfig BSP_USING_SPI
bool "Enable SPI"
select RT_USING_SPI
default n
if BSP_USING_SPI
config WM_SPI_CK_PIN
int "wm SPI CK pin number"
default 21
config WM_SPI_DO_PIN
int "wm SPI DO pin number"
default 23
config WM_SPI_DI_PIN
int "wm SPI DI pin number"
default 22
endif
config BSP_USING_WDT
bool "Enable WDT"
select RT_USING_WDT
default n
menuconfig BSP_USING_RTC
bool "Enable RTC"
select RT_USING_RTC
default n
if BSP_USING_RTC
config BSP_USING_ALARM
bool "Enable Alarm"
select RT_USING_ALARM
default n
endif
config BSP_USING_STANDBY
bool "Enable standby"
default n
endmenu
menu "Offboard Peripheral Drivers"
menuconfig BSP_USING_FLASH
bool "Enable Flash"
select RT_USING_SFUD
select BSP_USING_SPI
default n
if BSP_USING_FLASH
config SPI_Flash_BUS_NAME
string "SPI BUS Name"
default "spi0"
config SPI_Flash_CS_PIN
int "SPI Flash CS pin number"
default 20
endif
endmenu
endmenu
from building import *
cwd = GetCurrentDir()
list = os.listdir(cwd)
objs = []
src = Split('''
board.c
drv_uart.c
pin_map.c
''')
if GetDepend(['BSP_USING_ADC']):
src += ['drv_adc.c']
if GetDepend(['BSP_USING_WIFI']):
src += ['drv_wifi.c']
if GetDepend('BSP_USING_PIN'):
src += ['drv_pin.c']
if GetDepend('BSP_USING_SDIO'):
src += ['drv_sdio.c']
if GetDepend('BSP_USING_CAN'):
src += ['drv_can.c']
if GetDepend('BSP_USING_HWTIMER'):
src += ['drv_hw_timer.c']
if GetDepend('BSP_USING_CPUTIME'):
src += ['drv_cputime.c']
if GetDepend('BSP_USING_I2C'):
src += ['drv_i2c.c']
if GetDepend('BSP_USING_SPI'):
src += ['drv_spi.c']
if GetDepend(['BSP_USING_FLASH']):
src += ['drv_spiflash.c']
if GetDepend('BSP_USING_LCD'):
src += ['drv_lcd.c']
if GetDepend('BSP_USING_PWM'):
src += ['drv_pwm.c']
if GetDepend('BSP_USING_RTC'):
src += ['drv_rtc.c']
if GetDepend('BSP_USING_WDT'):
src += ['drv_wdt.c']
if GetDepend('BSP_USING_STANDBY'):
src += ['drv_standby.c']
CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
objs = objs + group
Return('objs')
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#include <rthw.h>
#include <rtthread.h>
#include "wm_type_def.h"
#include "misc.h"
#include "wm_cpu.h"
#include "wm_debug.h"
#include "wm_io.h"
#include "wm_gpio_afsel.h"
#include "wm_crypto_hard.h"
#include "wm_hostspi.h"
#include "wm_flash.h"
#include "wm_internal_flash.h"
#include "wm_fwup.h"
#include "wm_pmu.h"
#include "drv_uart.h"
#include "board.h"
#define FW_MAJOR_VER 0x03
#define FW_MINOR_VER 0x00
#define FW_PATCH_VER 0x00
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
};
const unsigned int HZ = RT_TICK_PER_SECOND;
struct tls_ethif *tls_netif_get_ethif(void)
{
return RT_NULL;
}
int tls_os_get_type(void)
{
return 0;
}
err_t tls_dhcp_stop(void)
{
return 0;
}
u8 tls_get_isr_count(void)
{
return 0;
}
void *mem_alloc_debug(u32 size)
{
return rt_malloc(size);
}
void mem_free_debug(void *p)
{
rt_free(p);
}
void disp_version_info(void)
{
extern const char WiFiVer[];
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");
}
void wm_gpio_config(void)
{
/* must call first */
wm_gpio_af_disable();
/*MASTER SPI configuratioin*/
wm_spi_cs_config(WM_IO_PA_02);
wm_spi_ck_config(WM_IO_PA_11);
wm_spi_di_config(WM_IO_PA_03);
wm_spi_do_config(WM_IO_PA_09);
}
static int wm_infsl_init(void)
{
tls_spi_init();
tls_spifls_init();
tls_fls_init();
/*initialize flash layout parameter according to image type*/
tls_fls_layout_init();
return 0;
}
INIT_DEVICE_EXPORT(wm_infsl_init);
static void _idle_hook_callback(void)
{
#if !defined(__CC_ARM)
__asm volatile ("wfi");
#else
__asm
{
WFI;
}
#endif
}
void wm_sys_clk_config(void)
{
tls_sys_clk sysclk;
tls_sys_clk_set(CPU_CLK_80M);
tls_sys_clk_get(&sysclk);
SysTick_Config(sysclk.cpuclk * UNIT_MHZ / RT_TICK_PER_SECOND);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
tls_pmu_clk_select(0);
}
/**
* This is the timer interrupt service routine.
*
*/
void OS_CPU_SysTickHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
}
/**
* This function will initial board.
*/
void rt_hw_board_init(void)
{
/* must call first to configure gpio Alternate functions according the hardware design */
wm_gpio_config();
wm_sys_clk_config();
#ifdef RT_USING_HEAP
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#ifdef RT_USING_CONSOLE
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
#if TLS_CONFIG_HARD_CRYPTO
tls_crypto_init();
#endif
NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP, ENABLE);
rt_thread_idle_sethook(_idle_hook_callback);
}
#ifdef RT_USING_FINSH
#include <finsh.h>
static void reboot(uint8_t argc, char **argv)
{
rt_hw_cpu_reset();
}
FINSH_FUNCTION_EXPORT_ALIAS(reboot, __cmd_reboot, Reboot System);
#endif /* RT_USING_FINSH */
/*@}*/
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#ifndef __BOARD_H__
#define __BOARD_H__
#ifdef __CC_ARM
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define HEAP_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="CSTACK"
#define HEAP_BEGIN (__segment_end("CSTACK"))
#else
extern int __bss_end__;
#define HEAP_BEGIN (&__bss_end__)
#endif
#define HEAP_END (0x20038000UL)
void rt_hw_board_init(void);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-23 fanwenl 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "wm_io.h"
#include "wm_adc.h"
#include "wm_gpio_afsel.h"
#include "drv_adc.h"
#ifdef BSP_USING_ADC
#if defined(USING_ADC_CH1) || defined(USING_ADC_CH2) || defined(USING_ADC_CH3) || defined(USING_ADC_CH4) || \
defined(USING_ADC_CH5) || defined(USING_ADC_CH6) || defined(USING_ADC_CH7) || defined(USING_ADC_CH8)
static rt_err_t wm_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled)
{
if (channel < 1 || channel > 8)
return RT_ERROR;
if (enabled == RT_TRUE)
{
tls_adc_start_with_cpu(channel - 1);
}
else
{
tls_adc_stop(0);
}
return RT_EOK;
}
static rt_err_t wm_adc_convert(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value)
{
if (channel < 1 || channel > 8)
return RT_ERROR;
*value = adc_get_inputVolt(channel - 1) ;
return RT_EOK;
}
static struct rt_adc_ops wm_adc_ops =
{
wm_adc_enabled,
wm_adc_convert,
};
static struct rt_adc_device wm_adc;
#endif
#ifdef USING_CPU_TEMP
static rt_err_t wm_cpu_temp_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled)
{
if (enabled == RT_FALSE)
{
tls_adc_stop(0);
}
return RT_EOK;
}
static rt_err_t wm_cpu_temp_convert(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value)
{
*value = (rt_uint32_t)adc_temp();
/**
sprintf(temperature, "%d.%d", *value/1000, (*value%1000)/100);
printf("tem: %s", temperature);
*/
return RT_EOK;
}
static struct rt_adc_ops wm_cpu_temp_ops =
{
wm_cpu_temp_enabled,
wm_cpu_temp_convert,
};
static struct rt_adc_device wm_cpu_temp;
#endif
int wm_hw_adc_init(void)
{
/*adc io config*/
#ifdef USING_ADC_CH1
wm_adc_config(0);
#endif
#ifdef USING_ADC_CH2
wm_adc_config(1);
#endif
#ifdef USING_ADC_CH3
wm_adc_config(2);
#endif
#ifdef USING_ADC_CH4
wm_adc_config(3);
#endif
#ifdef USING_ADC_CH5
wm_adc_config(4);
#endif
#ifdef USING_ADC_CH6
wm_adc_config(5);
#endif
#ifdef USING_ADC_CH7
wm_adc_config(6);
#endif
#ifdef USING_ADC_CH8
wm_adc_config(7);
#endif
#if defined(USING_ADC_CH1) || defined(USING_ADC_CH2) || defined(USING_ADC_CH3) || defined(USING_ADC_CH4) || \
defined(USING_ADC_CH5) || defined(USING_ADC_CH6) || defined(USING_ADC_CH7) || defined(USING_ADC_CH8)
rt_hw_adc_register(&wm_adc, "adc", &wm_adc_ops, 0);
#endif
#ifdef USING_CPU_TEMP
rt_hw_adc_register(&wm_cpu_temp, "cputemp", &wm_cpu_temp_ops, 0);
#endif
return RT_EOK;
}
INIT_DEVICE_EXPORT(wm_hw_adc_init);
#endif /* BSP_USING_ADC */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-22 fanwenl 1st version
*/
#ifndef __DRV_ADC_H__
#define __DRV_ADC_H__
int wm_hw_adc_init(void);
#endif /* __DRV_ADC_H__ */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-19 fanwenl 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "wm_type_def.h"
#include "wm_timer.h"
#include "drv_hw_timer.h"
#ifdef BSP_USING_HWTIMER
struct wm_timer_Type
{
enum tls_timer_unit unit;
enum tls_timer_id id;
};
static void wm_timer_init(rt_hwtimer_t *timer, rt_uint32_t state)
{
struct tls_timer_cfg timer_cfg;
struct wm_timer_Type *wm_timer = (struct wm_timer_Type *)timer->parent.user_data;
timer_cfg.unit = wm_timer->unit;
timer_cfg.timeout = 0xFFFFFFFF;
timer_cfg.is_repeat = 0;
timer_cfg.callback = NULL;
timer_cfg.arg = NULL;
if (state == 1)
{
tls_timer_create(&timer_cfg, wm_timer->id);
}
else if (state == 0)
{
tls_timer_destroy(wm_timer->id);
}
}
static rt_err_t wm_timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_t opmode)
{
struct wm_timer_Type *wm_timer = (struct wm_timer_Type *)timer->parent.user_data;
uint8_t m;
tls_timer_change(wm_timer->id, t);
m = (opmode == HWTIMER_MODE_ONESHOT) ? 0 : 1;
tls_timer_set_mode(wm_timer->id, m);
tls_timer_start(wm_timer->id);
return RT_EOK;
}
static void wm_timer_stop(rt_hwtimer_t *timer)
{
struct wm_timer_Type *wm_timer = (struct wm_timer_Type *)timer->parent.user_data;
tls_timer_stop(wm_timer->id);
}
static rt_err_t wm_timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)
{
/* The frequency value is an immutable value. */
if (cmd != HWTIMER_CTRL_FREQ_SET)
{
return -RT_ENOSYS;
}
if ( *(rt_uint32_t*)arg == 1000000)
{
return RT_EOK;
}
else
{
return -RT_ENOSYS;
}
}
static const struct rt_hwtimer_info _info =
{
1000000, /* the maximum count frequency can be set */
1000000, /* the minimum count frequency can be set */
0xFFFFFFFF, /* the maximum counter value */
HWTIMER_CNTMODE_DW, /* Increment or Decreasing count mode */
};
static const struct rt_hwtimer_ops _ops =
{
wm_timer_init,
wm_timer_start,
wm_timer_stop,
RT_NULL,
wm_timer_ctrl,
};
#ifdef USING_HW_TIMER1
static rt_hwtimer_t _timer1;
static struct wm_timer_Type wm_timer1;
#endif
#ifdef USING_HW_TIMER2
static rt_hwtimer_t _timer2;
static struct wm_timer_Type wm_timer2;
#endif
#ifdef USING_HW_TIMER3
static rt_hwtimer_t _timer3;
static struct wm_timer_Type wm_timer3;
#endif
#ifdef USING_HW_TIMER4
static rt_hwtimer_t _timer4;
static struct wm_timer_Type wm_timer4;
#endif
#ifdef USING_HW_TIMER5
static rt_hwtimer_t _timer5;
static struct wm_timer_Type wm_timer5;
#endif
int wm_hw_timer_init(void)
{
#ifdef USING_HW_TIMER1
wm_timer1.id = TLS_TIMER_ID_1;
wm_timer1.unit = TLS_TIMER_UNIT_US;
_timer1.info = &_info;
_timer1.ops = &_ops;
rt_device_hwtimer_register(&_timer1, "timer1", &wm_timer1);
#endif
#ifdef USING_HW_TIMER2
wm_timer2.id = TLS_TIMER_ID_2;
wm_timer2.unit = TLS_TIMER_UNIT_US;
_timer2.info = &_info;
_timer2.ops = &_ops;
rt_device_hwtimer_register(&_timer2, "timer2", &wm_timer2);
#endif
#ifdef USING_HW_TIMER3
wm_timer3.id = TLS_TIMER_ID_3;
wm_timer3.unit = TLS_TIMER_UNIT_US;
_timer3.info = &_info;
_timer3.ops = &_ops;
rt_device_hwtimer_register(&_timer3, "timer3", &wm_timer3);
#endif
#ifdef USING_HW_TIMER4
wm_timer4.id = TLS_TIMER_ID_4;
wm_timer4.unit = TLS_TIMER_UNIT_US;
_timer4.info = &_info;
_timer4.ops = &_ops;
rt_device_hwtimer_register(&_timer4, "timer4", &wm_timer4);
#endif
#ifdef USING_HW_TIMER5
wm_timer5.id = TLS_TIMER_ID_5;
wm_timer5.unit = TLS_TIMER_UNIT_US;
_timer5.info = &_info;
_timer5.ops = &_ops;
rt_device_hwtimer_register(&_timer5, "timer5", &wm_timer5);
#endif
return 0;
}
INIT_BOARD_EXPORT(wm_hw_timer_init);
void TIM1_IRQHandler(void)
{
timer_clear_irq(1);
#ifdef USING_HW_TIMER1
rt_device_hwtimer_isr(&_timer1);
#endif
}
void TIM2_IRQHandler(void)
{
timer_clear_irq(2);
#ifdef USING_HW_TIMER2
rt_device_hwtimer_isr(&_timer2);
#endif
}
void TIM3_IRQHandler(void)
{
timer_clear_irq(3);
#ifdef USING_HW_TIMER3
rt_device_hwtimer_isr(&_timer3);
#endif
}
void TIM4_IRQHandler(void)
{
timer_clear_irq(4);
#ifdef USING_HW_TIMER4
rt_device_hwtimer_isr(&_timer4);
#endif
}
void TIM5_IRQHandler(void)
{
timer_clear_irq(5);
#ifdef USING_HW_TIMER5
rt_device_hwtimer_isr(&_timer5);
#endif
}
#endif /* BSP_USING_HWTIMER */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-19 fanwenl 1st version
*/
#ifndef __DRV_HWTIMER_H__
#define __DRV_HWTIMER_H__
int wm_hw_timer_init(void);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-9 fanwenl 1st version
*/
#include <rtdevice.h>
#include <rtthread.h>
#include "wm_i2c.h"
#include "wm_io.h"
#include "wm_gpio_afsel.h"
#include "pin_map.h"
#include "drv_i2c.h"
#ifdef BSP_USING_I2C
struct wm_i2c_bus
{
struct rt_i2c_bus_device parent;
struct rt_i2c_msg *msg;
rt_uint32_t msg_cnt;
volatile rt_uint32_t msg_ptr;
volatile rt_uint32_t dptr;
};
static struct wm_i2c_bus wm_i2c;
static rt_size_t wm_i2c_mst_xfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num);
static rt_size_t wm_i2c_slv_xfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num);
static rt_err_t wm_i2c_bus_control(struct rt_i2c_bus_device *bus,
rt_uint32_t,
rt_uint32_t);
static const struct rt_i2c_bus_device_ops wm_i2c_ops =
{
wm_i2c_mst_xfer,
wm_i2c_slv_xfer,
wm_i2c_bus_control,
};
static rt_err_t wm_i2c_send_address(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg *msg)
{
uint8_t addr_msb, addr_lsb;
if (msg->flags & RT_I2C_ADDR_10BIT)
{
addr_msb = 0xf0 | ((msg->addr >> 7) & 0x06);
addr_lsb = msg->addr & 0xff;
if (msg->flags & RT_I2C_RD)
{
addr_msb |= 0x01;
}
tls_i2c_write_byte(addr_msb, 1);
tls_i2c_wait_ack();
tls_i2c_write_byte(addr_lsb, 0);
tls_i2c_wait_ack();
}
else
{
tls_i2c_write_byte((msg->addr << 1) | msg->flags, 1);
tls_i2c_wait_ack();
}
return RT_EOK;
}
static rt_size_t wm_i2c_mst_xfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num)
{
struct wm_i2c_bus *wm_i2c;
rt_size_t i;
RT_ASSERT(bus != RT_NULL);
wm_i2c = (struct wm_i2c_bus *)bus;
wm_i2c->msg = msgs;
wm_i2c->msg_ptr = 0;
wm_i2c->msg_cnt = num;
wm_i2c->dptr = 0;
for (i = 0; i < wm_i2c->msg_cnt; i++)
{
if (!(wm_i2c->msg[i].flags & RT_I2C_NO_START))
{
wm_i2c_send_address(bus, &(wm_i2c->msg[i]));
}
if (wm_i2c->msg[i].flags & RT_I2C_RD)
{
while (wm_i2c->msg[i].len > 1)
{
*wm_i2c->msg[i].buf++ = tls_i2c_read_byte(1, 0);
wm_i2c->msg[i].len--;
}
*wm_i2c->msg[i].buf = tls_i2c_read_byte(0, 0);
}
else
{
while (wm_i2c->msg[i].len > 0)
{
tls_i2c_write_byte(*wm_i2c->msg[i].buf, 0);
tls_i2c_wait_ack();
wm_i2c->msg[i].len--;
wm_i2c->msg[i].buf++;
}
}
}
wm_i2c->msg = RT_NULL;
wm_i2c->msg_ptr = 0;
wm_i2c->msg_cnt = 0;
wm_i2c->dptr = 0;
tls_i2c_stop();
for (int j = 0; j < 3000; j++);
return i;
}
static rt_size_t wm_i2c_slv_xfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num)
{
return 0;
}
static rt_err_t wm_i2c_bus_control(struct rt_i2c_bus_device *bus,
rt_uint32_t cmd,
rt_uint32_t arg)
{
return RT_ERROR;
}
void WM_I2C_IRQHandler(void)
{
extern void I2C_IRQHandler(void);
/* enter interrupt */
rt_interrupt_enter();
I2C_IRQHandler();
/* leave interrupt */
rt_interrupt_leave();
}
int wm_hw_i2c_init(void)
{
rt_int16_t gpio_pin;
gpio_pin = wm_get_pin(WM_I2C_SCL_PIN);
if (gpio_pin >= 0)
{
wm_i2c_scl_config((enum tls_io_name)gpio_pin);
}
gpio_pin = wm_get_pin(WM_I2C_DAT_PIN);
if (gpio_pin >= 0)
{
wm_i2c_sda_config((enum tls_io_name)gpio_pin);
}
tls_i2c_init(WM_HW_I2C_FREQ);
wm_i2c.parent.ops = &wm_i2c_ops;
rt_i2c_bus_device_register(&wm_i2c.parent, "i2c");
return 0;
}
INIT_DEVICE_EXPORT(wm_hw_i2c_init);
#endif /* BSP_USING_I2C */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-9 fanwenl 1st version
*/
#ifndef __DRV_I2C_H__
#define __DRV_I2C_H__
int wm_hw_i2c_init(void);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>
#include "wm_type_def.h"
#include "wm_io.h"
#include "wm_gpio.h"
#include "pin_map.h"
#include "drv_pin.h"
#ifdef BSP_USING_PIN
static void wm_pin_mode(struct rt_device *device, rt_base_t pin, rt_base_t mode)
{
rt_int16_t gpio_pin;
gpio_pin = wm_get_pin(pin);
if (gpio_pin < 0)
{
return;
}
if (mode == PIN_MODE_INPUT)
{
tls_gpio_cfg((enum tls_io_name)gpio_pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_FLOATING);
}
else if (mode == PIN_MODE_INPUT_PULLUP)
{
tls_gpio_cfg((enum tls_io_name)gpio_pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH);
}
else if (mode == PIN_MODE_INPUT_PULLDOWN)
{
tls_gpio_cfg((enum tls_io_name)gpio_pin, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLLOW);
}
else if (mode == PIN_MODE_OUTPUT)
{
tls_gpio_cfg((enum tls_io_name)gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
}
return;
}
static void wm_pin_write(struct rt_device *device, rt_base_t pin, rt_base_t value)
{
rt_int16_t gpio_pin;
gpio_pin = wm_get_pin(pin);
if (gpio_pin < 0)
{
return;
}
tls_gpio_write((enum tls_io_name)gpio_pin, value);
return;
}
static int wm_pin_read(struct rt_device *device, rt_base_t pin)
{
rt_int16_t gpio_pin;
gpio_pin = wm_get_pin(pin);
if (gpio_pin < 0)
{
return PIN_LOW;
}
return tls_gpio_read((enum tls_io_name)gpio_pin);
}
static rt_err_t wm_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
rt_uint32_t mode, void (*hdr)(void *args), void *args)
{
rt_int16_t gpio_pin;
rt_base_t level;
gpio_pin = wm_get_pin(pin);
if (gpio_pin < 0)
{
return RT_ENOSYS;
}
level = rt_hw_interrupt_disable();
/*irq mode set*/
switch (mode)
{
case PIN_IRQ_MODE_RISING:
tls_gpio_irq_cfg((enum tls_io_name)gpio_pin, WM_GPIO_IRQ_TRIG_RISING_EDGE);
break;
case PIN_IRQ_MODE_FALLING:
tls_gpio_irq_cfg((enum tls_io_name)gpio_pin, WM_GPIO_IRQ_TRIG_FALLING_EDGE);
break;
case PIN_IRQ_MODE_RISING_FALLING:
tls_gpio_irq_cfg((enum tls_io_name)gpio_pin, WM_GPIO_IRQ_TRIG_DOUBLE_EDGE);
break;
case PIN_IRQ_MODE_HIGH_LEVEL:
tls_gpio_irq_cfg((enum tls_io_name)gpio_pin, WM_GPIO_IRQ_TRIG_HIGH_LEVEL);
break;
case PIN_IRQ_MODE_LOW_LEVEL:
tls_gpio_irq_cfg((enum tls_io_name)gpio_pin, WM_GPIO_IRQ_TRIG_LOW_LEVEL);
break;
default:
rt_hw_interrupt_enable(level);
return RT_ENOSYS;
}
tls_gpio_isr_register((enum tls_io_name)gpio_pin, hdr, args);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
static rt_err_t wm_pin_detach_irq(struct rt_device *device, rt_int32_t pin)
{
return RT_EOK;
}
static rt_err_t wm_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled)
{
rt_int16_t gpio_pin;
rt_base_t level;
gpio_pin = wm_get_pin(pin);
if (gpio_pin < 0)
{
return RT_ENOSYS;
}
level = rt_hw_interrupt_disable();
if (enabled == PIN_IRQ_ENABLE)
{
tls_clr_gpio_irq_status((enum tls_io_name)gpio_pin);
tls_gpio_irq_enable((enum tls_io_name)gpio_pin);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
else if (enabled == PIN_IRQ_DISABLE)
{
tls_gpio_irq_disable((enum tls_io_name)gpio_pin);
rt_hw_interrupt_enable(level);
return RT_EOK;
}
else
{
rt_hw_interrupt_enable(level);
return RT_ENOSYS;
}
}
struct rt_pin_ops _wm_pin_ops =
{
wm_pin_mode,
wm_pin_write,
wm_pin_read,
wm_pin_attach_irq,
wm_pin_detach_irq,
wm_pin_irq_enable
};
int wm_hw_pin_init(void)
{
int ret = rt_device_pin_register("pin", &_wm_pin_ops, RT_NULL);
return ret;
}
INIT_BOARD_EXPORT(wm_hw_pin_init);
void WM_GPIOA_IRQHandler(void)
{
rt_interrupt_enter();
GPIOA_IRQHandler();
rt_interrupt_leave();
}
void WM_GPIOB_IRQHandler(void)
{
rt_interrupt_enter();
GPIOB_IRQHandler();
rt_interrupt_leave();
}
#endif /* BSP_USING_PIN */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#ifndef DRV_GPIO_H__
#define DRV_GPIO_H__
int wm_hw_pin_init(void);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-22 fanwenl 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "wm_type_def.h"
#include "wm_cpu.h"
#include "wm_pwm.h"
#include "wm_gpio_afsel.h"
#include "drv_pwm.h"
#include "pin_map.h"
#ifdef BSP_USING_PWM
#define MAX_PERIOD 255
#define MIN_PERIOD 2
#define MIN_PULSE 1
#define MAX_CLKDIV 65535
static rt_err_t wm_pwm_set(rt_uint8_t channel, struct rt_pwm_configuration *configuration)
{
rt_uint32_t period, pulse;
rt_uint32_t psc;
pwm_init_param pwm_param;
int ret = WM_FAILED;
tls_sys_clk sysclk;
tls_sys_clk_get(&sysclk);
rt_memset(&pwm_param, 0, sizeof(pwm_init_param));
pwm_param.channel = channel;
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_INDPT;
pwm_param.inverse_en = DISABLE;
pwm_param.pnum = 0;
pwm_param.pnum_int = DISABLE;
period = (unsigned long long)configuration->period * sysclk.apbclk / 1000ULL;
psc = period / MAX_PERIOD + 1;
if (psc > MAX_CLKDIV)
{
psc = MAX_CLKDIV;
}
pwm_param.clkdiv = psc;
period = period / psc;
if (period < MIN_PERIOD)
{
period = MIN_PERIOD;
}
else if (period > MAX_PERIOD)
{
period = MAX_PERIOD;
}
pwm_param.period = period - 1;
pulse = (unsigned long long)configuration->pulse * sysclk.apbclk / psc / 1000ULL;
if (pulse < MIN_PULSE)
{
pulse = MIN_PULSE;
}
else if (pulse > period)
{
pulse = period;
}
pwm_param.duty = pulse - 1;
ret = tls_pwm_out_init(pwm_param);
if (ret == WM_SUCCESS)
{
return RT_EOK;
}
else
{
return RT_ERROR;
}
}
static rt_err_t wm_pwm_get(rt_uint8_t channel, struct rt_pwm_configuration *configuration)
{
tls_sys_clk sysclk;
uint32_t clkdiv;
uint8_t duty, period;
tls_sys_clk_get(&sysclk);
tls_pwm_get_info(channel, &clkdiv, &duty, &period);
configuration->period = (period + 1) * clkdiv * 1000UL / sysclk.apbclk;
configuration->pulse = (duty + 1) * clkdiv * 1000UL / sysclk.apbclk;
return RT_EOK;
}
static rt_err_t wm_pwm_control(struct rt_device_pwm *device, int cmd, void *arg)
{
struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)arg;
int ret = WM_FAILED;
rt_uint32_t channel = 0;
channel = configuration->channel - 1;
if (channel > 4)
return RT_EINVAL;
switch (cmd)
{
case PWM_CMD_ENABLE:
ret = tls_pwm_start(channel);
if (ret == WM_SUCCESS)
return RT_EOK;
else
return RT_ERROR;
case PWM_CMD_DISABLE:
ret = tls_pwm_stop(channel);
if (ret == WM_SUCCESS)
return RT_EOK;
else
return RT_ERROR;
case PWM_CMD_SET:
return wm_pwm_set(channel, configuration);
case PWM_CMD_GET:
return wm_pwm_get(channel, configuration);
default:
return RT_EINVAL;
}
}
static struct rt_pwm_ops drv_ops =
{
wm_pwm_control
};
static struct rt_device_pwm wm_pwm;
int wm_hw_pwm_init(void)
{
rt_int16_t gpio_pin;
/*io config*/
#ifdef USING_PWM_CH1
gpio_pin = wm_get_pin(WM_PWM_CH1_PIN);
if (gpio_pin >= 0)
{
wm_pwm1_config((enum tls_io_name)gpio_pin);
}
#endif
#ifdef USING_PWM_CH2
gpio_pin = wm_get_pin(WM_PWM_CH2_PIN);
if (gpio_pin >= 0)
{
wm_pwm2_config((enum tls_io_name)gpio_pin);
}
#endif
#ifdef USING_PWM_CH3
gpio_pin = wm_get_pin(WM_PWM_CH3_PIN);
if (gpio_pin >= 0)
{
wm_pwm3_config((enum tls_io_name)gpio_pin);
}
#endif
#ifdef USING_PWM_CH4
gpio_pin = wm_get_pin(WM_PWM_CH4_PIN);
if (gpio_pin >= 0)
{
wm_pwm4_config((enum tls_io_name)gpio_pin);
}
#endif
#ifdef USING_PWM_CH5
gpio_pin = wm_get_pin(WM_PWM_CH5_PIN);
if (gpio_pin >= 0)
{
wm_pwm5_config((enum tls_io_name)gpio_pin);
}
#endif
#if defined(USING_PWM_CH1) || defined(USING_PWM_CH2) || defined(USING_PWM_CH3) || \
defined(USING_PWM_CH4) || defined(USING_PWM_CH5)
rt_device_pwm_register(&wm_pwm, "pwm", &drv_ops, 0);
#endif
return RT_EOK;
}
INIT_DEVICE_EXPORT(wm_hw_pwm_init);
#endif /* BSP_USING_PWM */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-22 fanwenl 1st version
*/
#ifndef __DRV_PWM_H__
#define __DRV_PWM_H__
int wm_hw_pwm_init(void);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
* 2019-03-01 fanwenl add alarm
*/
#include <rtdevice.h>
#include <rtthread.h>
#include <time.h>
#include "wm_regs.h"
#include "wm_irq.h"
#include "tls_common.h"
#include "wm_rtc.h"
#include "drv_rtc.h"
#ifdef BSP_USING_RTC
static struct rt_rtc_device rtc_device;
static time_t wm_get_timestamp(void)
{
struct tm tm_new = {0};
int ctrl1 = 0;
int ctrl2 = 0;
ctrl1 = tls_reg_read32(HR_PMU_RTC_CTRL1);
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2);
tm_new.tm_year = ((int)((int)ctrl2 & 0x00007f00) >> 8);
tm_new.tm_mon = (ctrl2 & 0x0000000f);
tm_new.tm_mday = (ctrl1 & 0x1f000000) >> 24;
tm_new.tm_hour = (ctrl1 & 0x001f0000) >> 16;
tm_new.tm_min = (ctrl1 & 0x00003f00) >> 8;
tm_new.tm_sec = ctrl1 & 0x0000003f;
return mktime(&tm_new);
}
static int wm_set_timestamp(time_t timestamp)
{
int ctrl1 = 0;
int ctrl2 = 0;
struct tm *tblock;
tblock = localtime(&timestamp);
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2); /* disable */
ctrl2 &= ~(1 << 16);
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
ctrl1 |= tblock->tm_sec;
ctrl1 |= tblock->tm_min << 8;
ctrl1 |= tblock->tm_hour << 16;
ctrl1 |= tblock->tm_mday << 24;
tls_reg_write32(HR_PMU_RTC_CTRL1, ctrl1);
ctrl2 = 0;
ctrl2 |= tblock->tm_mon;
ctrl2 |= tblock->tm_year << 8;
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
ctrl2 = tls_reg_read32(HR_PMU_RTC_CTRL2);/* enable */
ctrl2 |= (1 << 16);
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2);
return RT_EOK;
}
#ifdef BSP_USING_ALARM
static int wm_alarm_set_timestamp(struct rt_rtc_wkalarm *wkalarm)
{
int ctrl1 = 0;
int ctrl2 = 0;
struct tm *tblock;
time_t timestamp = 0;
timestamp = wm_get_timestamp();
tblock = localtime(&timestamp);
tls_irq_enable(PMU_RTC_INT);
ctrl1 |= wkalarm->tm_sec;
ctrl1 |= wkalarm->tm_min << 8;
ctrl1 |= wkalarm->tm_hour << 16;
ctrl1 |= tblock->tm_mday << 24;
ctrl2 |= tblock->tm_mon;
ctrl2 |= tblock->tm_year << 8;
tls_reg_write32(HR_PMU_RTC_CTRL2, ctrl2 | BIT(16));
tls_reg_write32(HR_PMU_RTC_CTRL1, ctrl1 | BIT(31));/* must set the enable */
return RT_EOK;
}
static void wm_rtc_alarm_callback(void *arg)
{
rt_alarm_update(0, 0);
}
#endif
static rt_err_t wm_rtc_init(rt_device_t dev)
{
wm_set_timestamp((time_t)0);
#ifdef BSP_USING_ALARM
tls_rtc_isr_register(wm_rtc_alarm_callback, (void *)0);
#endif
return RT_EOK;
}
static rt_err_t wm_rtc_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
static rt_err_t wm_rtc_close(rt_device_t dev)
{
return RT_EOK;
}
static rt_err_t wm_rtc_control(rt_device_t dev, int cmd, void *args)
{
#ifdef BSP_USING_ALARM
struct rt_rtc_device* rtc_device;
rtc_device = (struct rt_rtc_device* )dev;
#endif
RT_ASSERT(dev != RT_NULL);
switch (cmd)
{
case RT_DEVICE_CTRL_RTC_GET_TIME:
*(rt_uint32_t *)args = wm_get_timestamp();
break;
case RT_DEVICE_CTRL_RTC_SET_TIME:
wm_set_timestamp(*(time_t *)args);
break;
#ifdef BSP_USING_ALARM
case RT_DEVICE_CTRL_RTC_GET_ALARM:
*(struct rt_rtc_wkalarm *)args = rtc_device->wkalarm;
return RT_EOK;
case RT_DEVICE_CTRL_RTC_SET_ALARM:
rtc_device->wkalarm = *(struct rt_rtc_wkalarm *)args;
wm_alarm_set_timestamp(&rtc_device->wkalarm);
break;
#endif
default:
return RT_EINVAL;
}
return RT_EOK;
}
static rt_size_t wm_rtc_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
wm_rtc_control(dev, RT_DEVICE_CTRL_RTC_GET_TIME, buffer);
return size;
}
static rt_size_t wm_rtc_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
wm_rtc_control(dev, RT_DEVICE_CTRL_RTC_SET_TIME, (void *)buffer);
return size;
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops _ops =
{
.init = wm_rtc_init,
.open = wm_rtc_open,
.close = wm_rtc_close,
.read = wm_rtc_read,
.write = wm_rtc_write,
.control = wm_rtc_control
};
#endif
int wm_hw_rtc_init(void)
{
rt_memset(&rtc_device, 0, sizeof(rtc_device));
rtc_device.device.type = RT_Device_Class_RTC;
rtc_device.device.rx_indicate = RT_NULL;
rtc_device.device.tx_complete = RT_NULL;
#ifdef RT_USING_DEVICE_OPS
rtc_device.ops = &_ops;
#else
rtc_device.device.init = wm_rtc_init;
rtc_device.device.open = wm_rtc_open;
rtc_device.device.close = wm_rtc_close;
rtc_device.device.read = wm_rtc_read;
rtc_device.device.write = wm_rtc_write;
rtc_device.device.control = wm_rtc_control;
#endif
rtc_device.device.user_data = RT_NULL;
/* register a rtc device */
rt_device_register(&rtc_device.device, "rtc", RT_DEVICE_FLAG_RDWR);
return 0;
}
INIT_DEVICE_EXPORT(wm_hw_rtc_init);
#endif /* BSP_USING_RTC */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#ifndef DRV_RTC_H__
#define DRV_RTC_H__
#include <rtdevice.h>
#ifdef RT_USING_ALARM
#include <alarm.h>
#endif
struct rt_rtc_device
{
struct rt_device device;
#ifdef RT_USING_ALARM
struct rt_rtc_wkalarm wkalarm;
#endif
};
int wm_hw_rtc_init(void);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-12 fanwenl 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "wm_hostspi.h"
#include "wm_spi_hal.h"
#include "wm_io.h"
#include "wm_gpio_afsel.h"
#include "pin_map.h"
#include "drv_spi.h"
#ifdef BSP_USING_SPI
#define BSP_SPI_MAX_HZ (20* 1000 *1000)
struct wm_sw_spi_cs
{
rt_int16_t pin;
};
struct wm_spi
{
struct rt_spi_configuration *cfg;
};
static rt_err_t wm_hostspi_init(struct rt_spi_configuration *cfg)
{
spi_clear_fifo();
spi_set_endian(1);
if (cfg->data_width == 8)
{
tls_spi_trans_type(SPI_BYTE_TRANSFER);
}
if (cfg->data_width == 16)
{
tls_spi_trans_type(SPI_WORD_TRANSFER);
}
spi_set_mode(cfg->mode);
spi_set_chipselect_mode(SPI_CS_INACTIVE_MODE);
spi_force_cs_out(1);
if(cfg->max_hz > BSP_SPI_MAX_HZ)
{
cfg->max_hz = BSP_SPI_MAX_HZ;
}
spi_set_sclk(cfg->max_hz);
spi_set_tx_trigger_level(0);
spi_set_rx_trigger_level(7);
spi_set_rx_channel(1);
spi_set_tx_channel(1);
return RT_EOK;
}
static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg)
{
RT_ASSERT(cfg != RT_NULL);
RT_ASSERT(device != RT_NULL);
/*将cfg参数放到device中*/
struct wm_spi *hspi = (struct wm_spi *)device->bus->parent.user_data;
hspi->cfg = cfg;
wm_hostspi_init(cfg);
return RT_EOK;
}
static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message)
{
RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL);
RT_ASSERT(device->bus->parent.user_data != RT_NULL);
struct wm_sw_spi_cs *cs = device->parent.user_data;
struct tls_spi_transfer tls_transfer;
tls_transfer.tx_buf = message->send_buf;
tls_transfer.rx_buf = message->recv_buf;
tls_transfer.len = message->length;
rt_int32_t length = 0;
rt_int32_t remain_length = message->length;
length = spi_fill_txfifo(&tls_transfer, remain_length);
spi_set_sclk_length(length * 8, 0);
if (message->cs_take)
{
tls_gpio_write((enum tls_io_name)cs->pin, 0);
}
spi_sclk_start();
while (remain_length > 0)
{
while (spi_i2s_get_busy_status() == 1)
;
length = spi_get_rxfifo(&tls_transfer, remain_length);
remain_length -= length;
if (remain_length == 0)
{
while (spi_i2s_get_busy_status() == 1)
;
if (message->cs_release)
{
tls_gpio_write((enum tls_io_name)cs->pin, 1);
}
}
while (spi_i2s_get_busy_status() == 1)
;
length = spi_fill_txfifo(&tls_transfer, remain_length);
if (length)
{
spi_set_sclk_length(length * 8, 0);
spi_sclk_start();
}
}
while (spi_i2s_get_busy_status() == 1)
;
if (message->cs_release)
{
tls_gpio_write((enum tls_io_name)cs->pin, 1);
}
return message->length - remain_length;
}
rt_err_t wm_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin)
{
rt_err_t ret;
rt_int16_t gpio_pin;
struct rt_spi_device *spi_device;
struct wm_sw_spi_cs *cs_pin;
gpio_pin = wm_get_pin(pin);
if (gpio_pin == WM_PIN_DEFAULT)
{
return -RT_ERROR;
}
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
RT_ASSERT(spi_device != RT_NULL);
cs_pin = (struct wm_sw_spi_cs *)rt_malloc(sizeof(struct wm_sw_spi_cs));
RT_ASSERT(cs_pin != RT_NULL);
cs_pin->pin = gpio_pin;
tls_gpio_cfg((enum tls_io_name)gpio_pin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_write((enum tls_io_name)gpio_pin, 1);
ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
return ret;
}
static struct rt_spi_ops wm_spi_ops =
{
.configure = spi_configure,
.xfer = spixfer
};
struct wm_spi spi;
struct rt_spi_bus wm_spi_bus;
int wm_hw_spi_bus_init(void)
{
rt_int16_t gpio_pin;
gpio_pin = wm_get_pin(WM_SPI_CK_PIN);
if (gpio_pin >= 0)
{
wm_spi_ck_config((enum tls_io_name)gpio_pin);
}
gpio_pin = wm_get_pin(WM_SPI_DI_PIN);
if (gpio_pin >= 0)
{
wm_spi_di_config((enum tls_io_name)gpio_pin);
}
gpio_pin = wm_get_pin(WM_SPI_DO_PIN);
if (gpio_pin >= 0)
{
wm_spi_do_config((enum tls_io_name)gpio_pin);
}
wm_spi_bus.parent.user_data = &spi;
rt_spi_bus_register(&wm_spi_bus, "spi0", &wm_spi_ops);
return RT_EOK;
}
INIT_PREV_EXPORT(wm_hw_spi_bus_init);
#endif /* BSP_USING_SPI */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-12 fanwenl 1st version
*/
#ifndef __DRV_SPI_BUS_H__
#define __DRV_SPI_BUS_H__
#include <rtthread.h>
int wm_hw_spi_bus_init(void);
rt_err_t wm_spi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint32_t pin);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-12 fanwenl 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#ifdef BSP_USING_FLASH
#include "drv_spi.h"
#include "string.h"
#include "spi_flash.h"
#include "spi_flash_sfud.h"
int wm_nor_flash_init(void)
{
rt_spi_flash_device_t spi_device;
wm_spi_bus_attach_device(SPI_Flash_BUS_NAME, "norspi", SPI_Flash_CS_PIN);
spi_device = rt_sfud_flash_probe("flash0", "norspi");
if (spi_device == RT_NULL)
{
return -RT_ERROR;
}
return 0;
}
INIT_DEVICE_EXPORT(wm_nor_flash_init);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-12 fanwenl 1st version
*/
#ifndef __DRV_SPI_FLASH_H_
#define __DRV_SPI_FLASH_H_
int wm_nor_flash_init(void);
#endif /* __DRV_SPI_FLASH_H_ */
\ No newline at end of file
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-13 tyx first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_standby.h"
#ifdef BSP_USING_STANDBY
#include "wm_type_def.h"
#include "wm_cpu.h"
#include "wm_pmu.h"
#include "wm_irq.h"
#include "wm_regs.h"
typedef volatile unsigned long vu32;
#define M32(adr) (*((vu32*) (adr)))
typedef void (*rom_standby_func)(void);
static const rom_standby_func pm_standby = (rom_standby_func)0x499;
#ifdef __ICCARM__
extern void standby_idr(void);
#endif
#if (1 == GCC_COMPILE)
void wm_pm_standby(void)
{
__asm volatile (
" cpsid i \n" /* disable irq*/
" dsb \n"
" ldr r0, =0X499 \n"
" bx r0 \n"
" movs r0, #0x00 \n"
" isb \n"
);
}
#endif
/**
* This function will put w60x into run/shutdown mode.
*
* @param timeout How many OS Ticks that MCU can sleep
*/
void sys_start_standby(int ms)
{
rt_uint32_t val;
int timeout = ms;
RT_ASSERT(timeout > 0);
tls_pmu_clk_select(0);
if (timeout <= 65535)
{
/* Enter PM_TIMER_MODE */
tls_irq_enable(PMU_TIMER1_INT);
tls_pmu_timer1_stop();
tls_pmu_timer1_start(timeout);
}
else if(timeout <= 65535000)
{
timeout /= 1000;
tls_irq_enable(PMU_TIMER0_INT);
tls_pmu_timer0_stop();
tls_pmu_timer0_start(timeout);
}
else
{
return;
}
tls_irq_enable(PMU_GPIO_WAKEUP_INT); //Open interrupt by default to clear the interrupt flag for IO wake-up
val = tls_reg_read32(HR_PMU_PS_CR);
val |= 0x01;
tls_reg_write32(HR_PMU_PS_CR, val);
}
#ifdef RT_USING_FINSH
#include <finsh.h>
#include <stdlib.h>
static void standby(uint8_t argc, char **argv)
{
if (argc != 2)
{
rt_kprintf("Usage: standby timeout(ms)\n");
rt_kprintf("eg : standby 5000\n");
}
else
{
sys_start_standby(atoi(argv[1]));
}
}
FINSH_FUNCTION_EXPORT_ALIAS(standby, __cmd_standby, sleep System);
#endif /* RT_USING_FINSH */
#endif /* BSP_USING_STANDBY */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-25 tyx add file
*/
#ifndef __DRV_STANDBY_H__
#define __DRV_STANDBY_H__
void sys_start_standby(int ms);
#endif
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "wm_io.h"
#include "wm_uart.h"
#include "wm_gpio_afsel.h"
#include "wm_type_def.h"
#include "wm_cpu.h"
#include "drv_uart.h"
#include "pin_map.h"
#define WM600_UART0 (TLS_UART_REGS_T *) HR_UART0_BASE_ADDR
#define WM600_UART1 (TLS_UART_REGS_T *) HR_UART1_BASE_ADDR
#define WM600_UART2 (TLS_UART_REGS_T *) HR_UART2_BASE_ADDR
static void wm_uart_reg_init(TLS_UART_REGS_T *UARTx)
{
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
if (UARTx == WM600_UART0)
{
/* disable auto flow control */
tls_reg_write32(HR_UART0_FLOW_CTRL, 0);
/* disable dma */
tls_reg_write32(HR_UART0_DMA_CTRL, 0);
/* one byte tx */
tls_reg_write32(HR_UART0_FIFO_CTRL, 0);
/* disable interrupt */
tls_reg_write32(HR_UART0_INT_MASK, 0xFF);
/* enable rx/timeout interrupt */
tls_reg_write32(HR_UART0_INT_MASK, ~(3 << 2));
}
else if (UARTx == WM600_UART1)
{
/* 4 byte tx, 8 bytes rx */
tls_reg_write32(HR_UART1_FIFO_CTRL, (0x01 << 2) | (0x02 << 4));
/* enable rx timeout, disable rx dma, disable tx dma */
tls_reg_write32(HR_UART1_DMA_CTRL, (8 << 3) | (1 << 2));
/* enable rx/timeout interrupt */
tls_reg_write32(HR_UART1_INT_MASK, ~(3 << 2));
}
else if (UARTx == WM600_UART2)
{
/* 4 byte tx, 8 bytes rx */
tls_reg_write32(HR_UART2_FIFO_CTRL, (0x01 << 2) | (0x02 << 4));
/* enable rx timeout, disable rx dma, disable tx dma */
tls_reg_write32(HR_UART2_DMA_CTRL, (8 << 3) | (1 << 2));
/* enable rx/timeout interrupt */
tls_reg_write32(HR_UART2_INT_MASK, ~(3 << 2));
UARTx->UR_LC &= ~(0x1000000);
}
}
static void wm_uart_gpio_config(TLS_UART_REGS_T *UARTx)
{
#if defined(BSP_USING_UART1) || defined(BSP_USING_UART2)
rt_int16_t gpio_pin;
#endif
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
if (UARTx == WM600_UART0)
{
/* UART0_TX-PA04 UART0_RX-PA05 */
wm_uart0_tx_config(WM_IO_PA_04);
wm_uart0_rx_config(WM_IO_PA_05);
}
#ifdef BSP_USING_UART1
else if (UARTx == WM600_UART1)
{
gpio_pin = wm_get_pin(WM_UART1_RX_PIN);
if (gpio_pin >= 0)
{
wm_uart1_rx_config((enum tls_io_name)gpio_pin);
}
gpio_pin = wm_get_pin(WM_UART1_TX_PIN);
if (gpio_pin >= 0)
{
wm_uart1_tx_config((enum tls_io_name)gpio_pin);
}
}
#endif
#ifdef BSP_USING_UART2
else if (UARTx == WM600_UART2)
{
gpio_pin = wm_get_pin(WM_UART2_RX_PIN);
if (gpio_pin >= 0)
{
wm_uart2_rx_config((enum tls_io_name)gpio_pin);
}
gpio_pin = wm_get_pin(WM_UART2_TX_PIN);
if (gpio_pin >= 0)
{
wm_uart2_tx_scio_config((enum tls_io_name)gpio_pin);
}
}
#endif
}
static void wm_uart_irq_config(TLS_UART_REGS_T *UARTx)
{
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
/* config uart interrupt register */
/* clear interrupt */
UARTx->UR_INTS = 0xFFFFFFFF;
/* enable interupt */
UARTx->UR_INTM = 0x0;
UARTx->UR_DMAC = (4UL << UDMA_RX_FIFO_TIMEOUT_SHIFT) | UDMA_RX_FIFO_TIMEOUT;
/* config FIFO control */
UARTx->UR_FIFOC = UFC_TX_FIFO_LVL_16_BYTE | UFC_RX_FIFO_LVL_16_BYTE | UFC_TX_FIFO_RESET | UFC_RX_FIFO_RESET;
UARTx->UR_LC &= ~(ULCON_TX_EN | ULCON_RX_EN);
UARTx->UR_LC |= ULCON_TX_EN | ULCON_RX_EN;
}
static int wm_uart_baudrate_set(TLS_UART_REGS_T *UARTx, u32 baudrate)
{
u32 value;
u32 apbclk;
tls_sys_clk sysclk;
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
tls_sys_clk_get(&sysclk);
apbclk = sysclk.apbclk * 1000000;
value = (apbclk / (16 * baudrate) - 1) |
(((apbclk % (baudrate * 16)) * 16 / (baudrate * 16)) << 16);
UARTx->UR_BD = value;
return WM_SUCCESS;
}
static int wm_uart_parity_set(TLS_UART_REGS_T *UARTx, TLS_UART_PMODE_T paritytype)
{
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
if (paritytype == TLS_UART_PMODE_DISABLED)
UARTx->UR_LC &= ~ULCON_PMD_EN;
else if (paritytype == TLS_UART_PMODE_EVEN)
{
UARTx->UR_LC &= ~ULCON_PMD_MASK;
UARTx->UR_LC |= ULCON_PMD_EVEN;
}
else if (paritytype == TLS_UART_PMODE_ODD)
{
UARTx->UR_LC &= ~ULCON_PMD_MASK;
UARTx->UR_LC |= ULCON_PMD_ODD;
}
else
return WM_FAILED;
return WM_SUCCESS;
}
static int wm_uart_stopbits_set(TLS_UART_REGS_T *UARTx, TLS_UART_STOPBITS_T stopbits)
{
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
if (stopbits == TLS_UART_TWO_STOPBITS)
UARTx->UR_LC |= ULCON_STOP_2;
else
UARTx->UR_LC &= ~ULCON_STOP_2;
return WM_SUCCESS;
}
static int wm_uart_databits_set(TLS_UART_REGS_T *UARTx, TLS_UART_CHSIZE_T charlength)
{
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
UARTx->UR_LC &= ~ULCON_WL_MASK;
if (charlength == TLS_UART_CHSIZE_5BIT)
UARTx->UR_LC |= ULCON_WL5;
else if (charlength == TLS_UART_CHSIZE_6BIT)
UARTx->UR_LC |= ULCON_WL6;
else if (charlength == TLS_UART_CHSIZE_7BIT)
UARTx->UR_LC |= ULCON_WL7;
else if (charlength == TLS_UART_CHSIZE_8BIT)
UARTx->UR_LC |= ULCON_WL8;
else
return WM_FAILED;
return WM_SUCCESS;
}
static int wm_uart_flow_ctrl_set(TLS_UART_REGS_T *UARTx, TLS_UART_FLOW_CTRL_MODE_T flow_ctrl)
{
RT_ASSERT(UARTx == WM600_UART0 || UARTx == WM600_UART1 || UARTx == WM600_UART2);
switch (flow_ctrl)
{
case TLS_UART_FLOW_CTRL_NONE:
UARTx->UR_FC = 0;
break;
case TLS_UART_FLOW_CTRL_HARDWARE:
UARTx->UR_FC = (1UL << 0) | (6UL << 2);
break;
default:
break;
}
return WM_SUCCESS;
}
struct device_uart
{
TLS_UART_REGS_T volatile *uart_device;
rt_uint32_t uart_irq_no;
};
static rt_err_t drv_uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg);
static rt_err_t drv_uart_control(struct rt_serial_device *serial, int cmd, void *arg);
static int drv_uart_putc(struct rt_serial_device *serial, char c);
static int drv_uart_getc(struct rt_serial_device *serial);
static rt_size_t drv_uart_dma_transmit(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction);
const struct rt_uart_ops _uart_ops =
{
drv_uart_configure,
drv_uart_control,
drv_uart_putc,
drv_uart_getc,
drv_uart_dma_transmit
};
/*
* UART interface
*/
static rt_err_t drv_uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
struct device_uart *uart;
u32 baud_rate;
TLS_UART_PMODE_T parity;
TLS_UART_STOPBITS_T stop_bits;
TLS_UART_CHSIZE_T data_bits;
RT_ASSERT(serial != RT_NULL && cfg != RT_NULL);
serial->config = *cfg;
uart = (struct device_uart *)serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
switch (cfg->baud_rate)
{
case BAUD_RATE_2000000:
case BAUD_RATE_921600:
case BAUD_RATE_460800:
case BAUD_RATE_230400:
case BAUD_RATE_115200:
case BAUD_RATE_57600:
case BAUD_RATE_38400:
case BAUD_RATE_19200:
case BAUD_RATE_9600:
case BAUD_RATE_4800:
case BAUD_RATE_2400:
baud_rate = cfg->baud_rate;
break;
default:
rt_kprintf("baudrate set failed... default rate:115200\r\n");
baud_rate = BAUD_RATE_115200;
break;
}
wm_uart_baudrate_set((TLS_UART_REGS_T *)uart->uart_device, baud_rate);
switch (cfg->parity)
{
case PARITY_ODD:
parity = TLS_UART_PMODE_ODD;
break;
case PARITY_EVEN:
parity = TLS_UART_PMODE_EVEN;
break;
case PARITY_NONE:
default:
parity = TLS_UART_PMODE_DISABLED;
break;
}
wm_uart_parity_set((TLS_UART_REGS_T *)uart->uart_device, parity);
switch (cfg->stop_bits)
{
case STOP_BITS_2:
stop_bits = TLS_UART_TWO_STOPBITS;
break;
case STOP_BITS_1:
default:
stop_bits = TLS_UART_ONE_STOPBITS;
break;
}
wm_uart_stopbits_set((TLS_UART_REGS_T *)uart->uart_device, stop_bits);
switch (cfg->data_bits)
{
case DATA_BITS_5:
data_bits = TLS_UART_CHSIZE_5BIT;
break;
case DATA_BITS_6:
data_bits = TLS_UART_CHSIZE_6BIT;
break;
case DATA_BITS_7:
data_bits = TLS_UART_CHSIZE_7BIT;
break;
case DATA_BITS_8:
default:
data_bits = TLS_UART_CHSIZE_8BIT;
break;
}
wm_uart_databits_set((TLS_UART_REGS_T *)uart->uart_device, data_bits);
wm_uart_flow_ctrl_set((TLS_UART_REGS_T *)uart->uart_device, TLS_UART_FLOW_CTRL_NONE);
return (RT_EOK);
}
static rt_err_t drv_uart_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct device_uart *)serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
/* Disable the UART Interrupt */
tls_irq_disable(uart->uart_irq_no);
break;
case RT_DEVICE_CTRL_SET_INT:
/* Enable the UART Interrupt */
tls_irq_enable(uart->uart_irq_no);
break;
}
return (RT_EOK);
}
static int drv_uart_putc(struct rt_serial_device *serial, char c)
{
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct device_uart *)serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
while (uart->uart_device->UR_FIFOS & 0x3F); /* wait THR is empty */
uart->uart_device->UR_TXW = (char)c;
return (1);
}
static int drv_uart_getc(struct rt_serial_device *serial)
{
int ch;
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct device_uart *)serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
ch = -1;
if (uart->uart_device->UR_FIFOS & UFS_RX_FIFO_CNT_MASK)
ch = (int)uart->uart_device->UR_RXW;
return ch;
}
static rt_size_t drv_uart_dma_transmit(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction)
{
return (0);
}
static void drv_uart_irq_handler(struct rt_serial_device *serial)
{
u32 intr_src;
struct device_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct device_uart *)serial->parent.user_data;
RT_ASSERT(uart != RT_NULL);
/* check interrupt status */
intr_src = uart->uart_device->UR_INTS;
uart->uart_device->UR_INTS = intr_src;
if ((intr_src & UART_RX_INT_FLAG) && (0 == (uart->uart_device->UR_INTM & UIS_RX_FIFO)))
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
}
if (intr_src & UART_TX_INT_FLAG)
{
}
if (intr_src & UIS_CTS_CHNG)
{
}
}
#ifdef BSP_USING_UART0
static struct rt_serial_device serial0;
static struct device_uart uart0 =
{
WM600_UART0,
UART0_INT,
};
void UART0_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
drv_uart_irq_handler(&serial0);
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_UART1
static struct rt_serial_device serial1;
static struct device_uart uart1 =
{
WM600_UART1,
UART1_INT,
};
void UART1_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
drv_uart_irq_handler(&serial1);
/* leave interrupt */
rt_interrupt_leave();
}
#endif
#ifdef BSP_USING_UART2
static struct rt_serial_device serial2;
static struct device_uart uart2 =
{
WM600_UART2,
UART2_INT,
};
void UART2_IRQHandler(void)
{
/* enter interrupt */
rt_interrupt_enter();
drv_uart_irq_handler(&serial2);
/* leave interrupt */
rt_interrupt_leave();
}
#endif
/*
* UART Initiation
*/
int wm_hw_uart_init(void)
{
struct rt_serial_device *serial;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
struct device_uart *uart;
#ifdef BSP_USING_UART0
{
serial = &serial0;
uart = &uart0;
/* Init UART Hardware */
wm_uart_gpio_config((TLS_UART_REGS_T *)uart->uart_device);
wm_uart_reg_init((TLS_UART_REGS_T *)uart->uart_device);
wm_uart_irq_config((TLS_UART_REGS_T *)uart->uart_device);
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = 115200;
rt_hw_serial_register(serial,
"uart0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif /* BSP_USING_UART0 */
#ifdef BSP_USING_UART1
{
serial = &serial1;
uart = &uart1;
/* Init UART Hardware */
wm_uart_gpio_config((TLS_UART_REGS_T *)uart->uart_device);
wm_uart_reg_init((TLS_UART_REGS_T *)uart->uart_device);
wm_uart_irq_config((TLS_UART_REGS_T *)uart->uart_device);
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = WM_UART1_BAUDRATE;
rt_hw_serial_register(serial,
"uart1",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif /* BSP_USING_UART1 */
#ifdef BSP_USING_UART2
{
serial = &serial2;
uart = &uart2;
/* Init UART Hardware */
wm_uart_gpio_config((TLS_UART_REGS_T *)uart->uart_device);
wm_uart_reg_init((TLS_UART_REGS_T *)uart->uart_device);
wm_uart_irq_config((TLS_UART_REGS_T *)uart->uart_device);
serial->ops = &_uart_ops;
serial->config = config;
serial->config.baud_rate = WM_UART2_BAUDRATE;
rt_hw_serial_register(serial,
"uart2",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
}
#endif /* BSP_USING_UART2 */
return 0;
}
INIT_BOARD_EXPORT(wm_hw_uart_init);
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#ifndef __DRV_UART_H__
#define __DRV_UART_H__
int wm_hw_uart_init(void);
#endif /* __DRV_UART_H__ */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-9 fanwenl 1st version
*/
#include <rtdevice.h>
#include "wm_watchdog.h"
#ifdef BSP_USING_WDT
static rt_err_t wm_wdg_init(rt_watchdog_t *wdt)
{
/*init for 10S*/
tls_watchdog_init(1000000);
tls_watchdog_stop();
return RT_EOK;
}
static rt_err_t wm_wdg_control(rt_watchdog_t *wdt, int cmd, void *arg)
{
uint64_t timeout_us = 0;
switch (cmd)
{
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
timeout_us = *((rt_uint32_t *)arg) * 1000000;
if (timeout_us >= 0xFFFFFFFF)
timeout_us = 0xFFFFFFFF;
tls_watchdog_set_timeout((rt_uint32_t)timeout_us);
break;
case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
timeout_us = tls_watchdog_get_timeout();
*((rt_uint32_t *)arg) = timeout_us / 1000000;
break;
case RT_DEVICE_CTRL_WDT_GET_TIMELEFT:
timeout_us = tls_watchdog_get_timeleft();
*((rt_uint32_t *)arg) = timeout_us / 1000000;
break;
case RT_DEVICE_CTRL_WDT_KEEPALIVE:
tls_watchdog_clr();
break;
case RT_DEVICE_CTRL_WDT_START:
tls_watchdog_start();
break;
case RT_DEVICE_CTRL_WDT_STOP:
tls_watchdog_stop();
break;
default:
return RT_EIO;
}
return RT_EOK;
}
static const struct rt_watchdog_ops wm_wdg_pos =
{
wm_wdg_init,
wm_wdg_control,
};
static rt_watchdog_t wm_wdg;
int wm_hw_wdg_init(void)
{
wm_wdg.ops = &wm_wdg_pos;
rt_hw_watchdog_register(&wm_wdg, "wdg", 0, RT_NULL);
return RT_EOK;
}
INIT_DEVICE_EXPORT(wm_hw_wdg_init);
#endif /*BSP_USING_WDT */
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#include <rtthread.h>
#include <wlan_dev.h>
#include "wm_type_def.h"
#include "wm_wifi.h"
#include "drv_wifi.h"
#define DBG_ENABLE
#define DBG_LEVEL DBG_INFO
#define DBG_SECTION_NAME "WIFI"
#define DBG_COLOR
#include <rtdbg.h>
#include "wm_ram_config.h"
#include "wm_efuse.h"
#include "wm_params.h"
#include "wm_debug.h"
#include "tls_ieee80211.h"
//#define ETH_RX_DUMP
//#define ETH_TX_DUMP
//#define MINI_DUMP
#define MAX_ADDR_LEN (6)
struct drv_wifi
{
struct rt_wlan_device *wlan;
rt_uint8_t dev_addr[MAX_ADDR_LEN];
};
static const struct rt_wlan_dev_ops ops;
static struct drv_wifi wifi_sta;
static struct drv_wifi wifi_ap;
extern int hed_rf_current_channel;
extern u8 *wpa_supplicant_get_mac(void);
extern u8 *hostapd_get_mac(void);
extern uint8_t* tls_wifi_buffer_acquire(int total_len);
extern void *tls_wl_init(u8 *tx_gain, u8* mac_addr, u8 *hwver);
extern int wpa_supplicant_init(u8 *mac_addr);
extern void wpa_supplicant_set_mac(u8 *mac);
extern void tls_wifi_buffer_release(rt_bool_t is_apsta, rt_uint8_t* buffer);
#if defined(ETH_RX_DUMP) || defined(ETH_TX_DUMP)
static void packet_dump(const char *msg, const void *ptr, rt_uint32_t len)
{
rt_uint32_t j;
rt_uint8_t *p = (rt_uint8_t *)ptr;
rt_kprintf("%s %d byte\n", msg, len);
#ifdef MINI_DUMP
return;
#endif
for (j = 0; j < len; j++)
{
if ((j % 8) == 0)
{
rt_kprintf(" ");
}
if ((j % 16) == 0)
{
rt_kprintf("\r\n");
}
rt_kprintf("%02x ", *p ++);
}
rt_kprintf("\n\n");
}
#endif /* dump */
err_t tls_netif_set_addr(void *ipaddr, void *netmask, void *gw)
{
LOG_D("%s %d\r\n", __FUNCTION__, __LINE__);
return 0;
}
static int wm_ethernetif_input(const rt_uint8_t *bssid, rt_uint8_t *buf, rt_uint32_t buf_len)
{
rt_err_t err = -RT_ERROR;
if (0 == compare_ether_addr(bssid, wifi_ap.dev_addr))
err = rt_wlan_dev_report_data(wifi_ap.wlan, (void *)buf, buf_len);
else
err = rt_wlan_dev_report_data(wifi_sta.wlan, (void *)buf, buf_len);
return err ? -1 : 0;
}
static void wm_wlan_client_event(u8 *mac, enum tls_wifi_client_event_type event)
{
struct rt_wlan_buff buff;
struct rt_wlan_info sta;
rt_memcpy(sta.bssid, mac, MAX_ADDR_LEN);
buff.data = &sta;
buff.len = sizeof(sta);
if (WM_WIFI_CLIENT_EVENT_ONLINE == event)
{
rt_wlan_dev_indicate_event_handle(wifi_ap.wlan, RT_WLAN_DEV_EVT_AP_ASSOCIATED, &buff);
}
else
{
rt_wlan_dev_indicate_event_handle(wifi_ap.wlan, RT_WLAN_DEV_EVT_AP_DISASSOCIATED, &buff);
}
}
static void wm_wlan_status_changed(rt_uint8_t status)
{
LOG_D("status:%d", status);
switch (status)
{
case WIFI_JOIN_SUCCESS:
LOG_D("NETIF_WIFI_JOIN_SUCCESS");
rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_CONNECT, RT_NULL);
break;
case WIFI_JOIN_FAILED:
LOG_D("NETIF_WIFI_JOIN_FAILED");
rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_CONNECT_FAIL, RT_NULL);
break;
case WIFI_DISCONNECTED:
LOG_D("NETIF_WIFI_DISCONNECTED");
rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_DISCONNECT, RT_NULL);
break;
case WIFI_SOFTAP_SUCCESS:
LOG_D("WIFI_SOFTAP_SUCCESS");
rt_wlan_dev_indicate_event_handle(wifi_ap.wlan, RT_WLAN_DEV_EVT_AP_START, RT_NULL);
break;
case WIFI_SOFTAP_CLOSED:
LOG_D("WIFI_SOFTAP_CLOSED");
rt_wlan_dev_indicate_event_handle(wifi_ap.wlan, RT_WLAN_DEV_EVT_AP_STOP, RT_NULL);
break;
default:
break;
}
}
static rt_err_t wm_wlan_init(void)
{
extern rt_uint8_t tx_gain_group[];
rt_uint8_t mac_addr[6] = {0x00, 0x25, 0x08, 0x09, 0x01, 0x0F};
/*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*/
{
LOG_E("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)
{
LOG_I("wl driver initial failured\n");
}
if (wpa_supplicant_init(mac_addr))
{
LOG_I("supplicant initial failured\n");
}
rt_memcpy(wifi_sta.dev_addr, wpa_supplicant_get_mac(), MAX_ADDR_LEN);
LOG_D("sta_mac:%02x-%02x-%02x-%02x-%02x-%02x\r\n", wifi_sta.dev_addr[0], wifi_sta.dev_addr[1], wifi_sta.dev_addr[2], wifi_sta.dev_addr[3], wifi_sta.dev_addr[4], wifi_sta.dev_addr[5]);
rt_memcpy(wifi_ap.dev_addr, hostapd_get_mac(), MAX_ADDR_LEN);
LOG_D("ap_mac:%02x-%02x-%02x-%02x-%02x-%02x\r\n", wifi_ap.dev_addr[0], wifi_ap.dev_addr[1], wifi_ap.dev_addr[2], wifi_ap.dev_addr[3], wifi_ap.dev_addr[4], wifi_ap.dev_addr[5]);
return RT_EOK;
}
static void wm_wlan_promisc_dataframe_callback(u8 *data, u32 data_len)
{
rt_wlan_dev_promisc_handler(wifi_sta.wlan, data, data_len);
}
static rt_err_t drv_wlan_init(struct rt_wlan_device *wlan)
{
static int inited = 0;
if (inited)
return RT_EOK;
wm_wlan_init();
tls_ethernet_data_rx_callback(wm_ethernetif_input);
tls_wifi_status_change_cb_register(wm_wlan_status_changed);
tls_wifi_softap_client_event_register(wm_wlan_client_event);
inited = 1;
return RT_EOK;
}
static rt_err_t drv_wlan_mode(struct rt_wlan_device *wlan, rt_wlan_mode_t mode)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
u8 wmode = IEEE80211_MODE_INFRA;
if (mode == RT_WLAN_AP)
wmode = IEEE80211_MODE_AP;
tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *)&wmode, TRUE);
return RT_EOK;
}
static void wm_wlan_scan_callback(void)
{
int buflen = 2000;
char *buf = RT_NULL;
int err;
struct rt_wlan_info wlan_info;
struct rt_wlan_buff buff;
buf = rt_malloc(buflen);
if (RT_NULL == buf)
{
LOG_E("rt_malloc failed...\r\n");
return;
}
err = tls_wifi_get_scan_rslt((u8 *)buf, buflen);
if (err != WM_SUCCESS)
{
rt_free(buf);
return;
}
struct tls_scan_bss_t *scan_res = (struct tls_scan_bss_t *)buf;
struct tls_bss_info_t *bss_info = (struct tls_bss_info_t *)scan_res->bss;
if (scan_res->count <= 0)
{
rt_free(buf);
return;
}
int i;
for (i = 0; i < scan_res->count; i ++)
{
rt_memset(&wlan_info, 0, sizeof(wlan_info));
rt_memcpy(&wlan_info.bssid[0], bss_info->bssid, 6);
rt_memcpy(wlan_info.ssid.val, bss_info->ssid, bss_info->ssid_len);
wlan_info.ssid.len = bss_info->ssid_len;
if (bss_info->ssid_len)
wlan_info.hidden = 0;
else
wlan_info.hidden = 1;
wlan_info.channel = (rt_int16_t)bss_info->channel;
wlan_info.rssi = -(char)(0x100 - bss_info->rssi);
wlan_info.datarate = bss_info->max_data_rate * 1000000;
wlan_info.band = RT_802_11_BAND_2_4GHZ;
wlan_info.security = SECURITY_OPEN;
if (WM_WIFI_AUTH_MODE_WEP_AUTO & bss_info->privacy)
wlan_info.security |= WEP_ENABLED;
if (WM_WIFI_AUTH_MODE_WPA_PSK_TKIP & bss_info->privacy)
wlan_info.security |= WPA_SECURITY | TKIP_ENABLED;
if (WM_WIFI_AUTH_MODE_WPA_PSK_CCMP & bss_info->privacy)
wlan_info.security |= WPA_SECURITY | AES_ENABLED;
if (WM_WIFI_AUTH_MODE_WPA2_PSK_CCMP & bss_info->privacy)
wlan_info.security |= WPA2_SECURITY | AES_ENABLED;
if (WM_WIFI_AUTH_MODE_WPA2_PSK_TKIP & bss_info->privacy)
wlan_info.security |= WPA2_SECURITY | TKIP_ENABLED;
if (bss_info->wps_support)
wlan_info.security |= WPS_ENABLED;
if (WM_WIFI_AUTH_MODE_UNKNOWN == bss_info->privacy)
wlan_info.security = SECURITY_UNKNOWN;
/* rtt incompleted... */
if (wlan_info.security & SECURITY_WPA2_MIXED_PSK)
wlan_info.security = SECURITY_WPA2_MIXED_PSK;
else if (wlan_info.security & SECURITY_WPA2_TKIP_PSK)
wlan_info.security = SECURITY_WPA2_TKIP_PSK;
else if (wlan_info.security & SECURITY_WPA2_AES_PSK)
wlan_info.security = SECURITY_WPA2_AES_PSK;
else if (wlan_info.security & SECURITY_WPA_AES_PSK)
wlan_info.security = SECURITY_WPA_AES_PSK;
else if (wlan_info.security & SECURITY_WPA_TKIP_PSK)
wlan_info.security = SECURITY_WPA_TKIP_PSK;
else if (wlan_info.security & SECURITY_WEP_PSK)
wlan_info.security = SECURITY_WEP_PSK;
else if ((SECURITY_UNKNOWN == wlan_info.security) && bss_info->wps_support)
wlan_info.security = SECURITY_WPS_SECURE;
LOG_D("%s-%x", wlan_info.ssid.val, wlan_info.security);
bss_info ++;
buff.data = &wlan_info;
buff.len = sizeof(wlan_info);
rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_SCAN_REPORT, &buff);
}
rt_free(buf);
rt_wlan_dev_indicate_event_handle(wifi_sta.wlan, RT_WLAN_DEV_EVT_SCAN_DONE, RT_NULL);
}
static rt_err_t drv_wlan_scan(struct rt_wlan_device *wlan, struct rt_scan_info *scan_info)
{
int ret;
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
/* register scan complt callback*/
tls_wifi_scan_result_cb_register(wm_wlan_scan_callback);
/* trigger the scan */
ret = tls_wifi_scan();
if ((ret == WM_WIFI_SCANNING_BUSY) || (ret == WM_FAILED))
return -RT_ERROR;
return RT_EOK;
}
static rt_err_t drv_wlan_join(struct rt_wlan_device *wlan, struct rt_sta_info *sta_info)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
tls_wifi_disconnect();
tls_wifi_connect((u8 *)sta_info->ssid.val, sta_info->ssid.len, (u8 *)sta_info->key.val, sta_info->key.len);
return RT_EOK;
}
static rt_err_t drv_wlan_softap(struct rt_wlan_device *wlan, struct rt_ap_info *ap_info)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
struct tls_softap_info_t apinfo;
struct tls_ip_info_t ipinfo;
rt_memset(&apinfo, 0, sizeof(apinfo));
rt_memcpy(apinfo.ssid, ap_info->ssid.val, ap_info->ssid.len);
apinfo.channel = ap_info->channel;
switch (ap_info->security) /* only support wpa2-psk and open */
{
case SECURITY_WEP_PSK:
apinfo.encrypt = IEEE80211_ENCRYT_WEP40;
break;
case SECURITY_WPA_TKIP_PSK:
apinfo.encrypt = IEEE80211_ENCRYT_TKIP_WPA;
break;
case SECURITY_WPA_AES_PSK:
apinfo.encrypt = IEEE80211_ENCRYT_CCMP_WPA;
break;
case SECURITY_WPA2_TKIP_PSK:
apinfo.encrypt = IEEE80211_ENCRYT_TKIP_WPA2;
break;
case SECURITY_WPA2_AES_PSK:
case SECURITY_WPA2_MIXED_PSK:
apinfo.encrypt = IEEE80211_ENCRYT_CCMP_WPA2;
break;
default:
apinfo.encrypt = IEEE80211_ENCRYT_NONE;
break;
}
apinfo.keyinfo.format = 1; /* ascii */
apinfo.keyinfo.index = 1; /* index */
apinfo.keyinfo.key_len = ap_info->key.len;
rt_memcpy(apinfo.keyinfo.key, ap_info->key.val, ap_info->key.len);
LOG_D("ch=%d, hd=%d, key=%s, sec=%x, ssid=%s", ap_info->channel, ap_info->hidden, ap_info->key.val, ap_info->security, ap_info->ssid.val);
rt_memset(&ipinfo, 0, sizeof(ipinfo));
ipinfo.ip_addr[0] = 192;
ipinfo.ip_addr[1] = 168;
ipinfo.ip_addr[2] = 48;
ipinfo.ip_addr[3] = 1;
ipinfo.netmask[0] = 255;
ipinfo.netmask[1] = 255;
ipinfo.netmask[2] = 255;
ipinfo.netmask[3] = 0;
u8 ssid_set = ap_info->hidden ? 0 : 1;
tls_param_set(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, FALSE);
rt_memcpy(ipinfo.dnsname, "local.w60x", sizeof("local.w60x"));
int ret = tls_wifi_softap_create(&apinfo, &ipinfo);
return (ret == WM_SUCCESS) ? RT_EOK : RT_ERROR;
}
static rt_err_t drv_wlan_disconnect(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
tls_wifi_disconnect();
return RT_EOK;
}
static rt_err_t drv_wlan_ap_stop(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
tls_wifi_softap_destroy();
return RT_EOK;
}
static rt_err_t drv_wlan_ap_deauth(struct rt_wlan_device *wlan, rt_uint8_t mac[])
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
struct tls_wifi_hdr_mac_t machdr;
struct tls_wifi_tx_rate_t tx;
rt_memset(&machdr, 0, sizeof(machdr));
rt_memcpy(machdr.da_addr, mac, MAX_ADDR_LEN);
rt_memcpy(machdr.sa_addr, hostapd_get_mac(), MAX_ADDR_LEN);
rt_memcpy(machdr.bssid, hostapd_get_mac(), MAX_ADDR_LEN);
rt_memset(&tx, 0, sizeof(tx));
tx.tx_rate = WM_WIFI_TX_RATEIDX_1M;
tx.tx_gain = tls_wifi_get_tx_gain_max(WM_WIFI_TX_RATEIDX_1M);
unsigned short reason = WLAN_REASON_UNSPECIFIED;/* htons */
int ret = tls_wifi_send_mgmt(WM_WIFI_MGMT_TYPE_DEAUTH, &machdr, (u8 *)&reason, sizeof(reason), &tx);
return (0 == ret) ? RT_EOK : RT_ERROR;
}
static rt_err_t drv_wlan_scan_stop(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
return RT_EOK;
}
static int drv_wlan_get_rssi(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
struct tls_curr_bss_t bss;
rt_memset(&bss, 0, sizeof(bss));
tls_wifi_get_current_bss(&bss);
return -bss.rssi - 1;
}
static rt_err_t drv_wlan_set_powersave(struct rt_wlan_device *wlan, int level)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
tls_wifi_set_psflag(level ? TRUE : FALSE, FALSE);
return RT_EOK;
}
static int drv_wlan_get_powersave(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
return tls_wifi_get_psflag();
}
static rt_err_t drv_wlan_cfg_promisc(struct rt_wlan_device *wlan, rt_bool_t start)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
if (RT_TRUE == start)
{
tls_wifi_set_listen_mode(1);
tls_wifi_data_recv_cb_register(wm_wlan_promisc_dataframe_callback);
}
else
{
tls_wifi_set_listen_mode(0);
tls_wifi_data_recv_cb_register(RT_NULL);
}
return RT_EOK;
}
static rt_err_t drv_wlan_cfg_filter(struct rt_wlan_device *wlan, struct rt_wlan_filter *filter)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
return RT_EINVAL;/* not support */
}
static rt_err_t drv_wlan_set_channel(struct rt_wlan_device *wlan, int channel)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
tls_wifi_change_chanel(channel - 1);
return RT_EOK;
}
static int drv_wlan_get_channel(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
return hed_rf_current_channel;
}
static rt_err_t drv_wlan_set_country(struct rt_wlan_device *wlan, rt_country_code_t country_code)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
u8 region = (u8)country_code;
tls_param_set(TLS_PARAM_ID_COUNTRY_REGION, (void *)&region, TRUE);
return RT_EOK;
}
static rt_country_code_t drv_wlan_get_country(struct rt_wlan_device *wlan)
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
u8 region = RT_COUNTRY_CHINA;
tls_param_get(TLS_PARAM_ID_COUNTRY_REGION, (void *)&region, FALSE);
return (rt_country_code_t)region; //RT_EOK;
}
static rt_err_t drv_wlan_set_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[])
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
if (wlan->user_data == &wifi_sta) /* ap don't support */
{
wpa_supplicant_set_mac(mac);
tls_set_mac_addr(mac);
}
return RT_EOK;
}
static rt_err_t drv_wlan_get_mac(struct rt_wlan_device *wlan, rt_uint8_t mac[])
{
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
if (wlan->user_data == &wifi_sta)
rt_memcpy(mac, wpa_supplicant_get_mac(), MAX_ADDR_LEN);
else
rt_memcpy(mac, hostapd_get_mac(), MAX_ADDR_LEN);
return RT_EOK;
}
static int drv_wlan_recv(struct rt_wlan_device *wlan, void *buff, int len)
{
return RT_EOK;
}
static int drv_wlan_send(struct rt_wlan_device *wlan, void *buff, int len)
{
rt_uint8_t *dst = tls_wifi_buffer_acquire(len);
if (dst == NULL)
return -RT_ENOMEM;
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* Drop the padding word */
#endif
#if defined(ETH_TX_DUMP)
packet_dump("Tx", buff, len);
#endif
rt_memcpy(dst, buff, len);
#if TLS_CONFIG_AP
if (netif != tls_get_netif())
tls_wifi_buffer_release(true, dst);
else
#endif
tls_wifi_buffer_release(false, dst);
#if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* Reclaim the padding word */
#endif
return RT_EOK;
}
static const struct rt_wlan_dev_ops ops =
{
.wlan_init = drv_wlan_init,
.wlan_mode = drv_wlan_mode,
.wlan_scan = drv_wlan_scan,
.wlan_join = drv_wlan_join,
.wlan_softap = drv_wlan_softap,
.wlan_disconnect = drv_wlan_disconnect,
.wlan_ap_stop = drv_wlan_ap_stop,
.wlan_ap_deauth = drv_wlan_ap_deauth,
.wlan_scan_stop = drv_wlan_scan_stop,
.wlan_get_rssi = drv_wlan_get_rssi,
.wlan_set_powersave = drv_wlan_set_powersave,
.wlan_get_powersave = drv_wlan_get_powersave,
.wlan_cfg_promisc = drv_wlan_cfg_promisc,
.wlan_cfg_filter = drv_wlan_cfg_filter,
.wlan_set_channel = drv_wlan_set_channel,
.wlan_get_channel = drv_wlan_get_channel,
.wlan_set_country = drv_wlan_set_country,
.wlan_get_country = drv_wlan_get_country,
.wlan_set_mac = drv_wlan_set_mac,
.wlan_get_mac = drv_wlan_get_mac,
.wlan_recv = drv_wlan_recv,
.wlan_send = drv_wlan_send,
};
int wm_hw_wifi_init(void)
{
static struct rt_wlan_device wlan;
static struct rt_wlan_device wlan2;
LOG_D("F:%s L:%d", __FUNCTION__, __LINE__);
rt_memset(&wifi_sta, 0, sizeof(wifi_sta));
rt_err_t ret = rt_wlan_dev_register(&wlan, RT_WLAN_DEVICE_STA_NAME, &ops, 0, &wifi_sta);
wifi_sta.wlan = &wlan;
rt_memset(&wifi_ap, 0, sizeof(wifi_ap));
ret |= rt_wlan_dev_register(&wlan2, RT_WLAN_DEVICE_AP_NAME, &ops, 0, &wifi_ap);
wifi_ap.wlan = &wlan2;
return ret; //RT_EOK;
}
INIT_DEVICE_EXPORT(wm_hw_wifi_init);
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-15 flyingcys 1st version
*/
#ifndef __DRV_WIFI_H__
#define __DRV_WIFI_H__
int wm_hw_wifi_init(void);
#endif /* __DRV_WIFI_H__ */
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x08010100;
/*-Memory Regions-*/
/* rom 959K */
define symbol __ICFEDIT_region_ROM_start__ = 0x08010100;
define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;
/* ram 224k */
define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_RAM_end__ = 0x2003C000;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0xc00;
define symbol __ICFEDIT_size_heap__ = 0x1A000;
/**** End of ICF editor section. ###ICF###*/
define memory mem with size = 4G;
define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];
define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];
define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };
initialize by copy { readwrite };
do not initialize { section .noinit };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place in ROM_region { readonly };
place in RAM_region { readwrite, last block CSTACK};
\ No newline at end of file
/* Linker script to configure memory regions.
* Need modifying for a specific board.
* FLASH.ORIGIN: starting address of flash
* FLASH.LENGTH: length of flash
* RAM.ORIGIN: starting address of RAM bank 0
* RAM.LENGTH: length of RAM bank 0
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x8010100, LENGTH = 959K /* 960K-256B */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x3C000 /* 240K */
}
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __copy_table_start__
* __copy_table_end__
* __zero_table_start__
* __zero_table_end__
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
*/
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
. = ALIGN(4);
_stext = .;
KEEP(*(.isr_vector))
. = ALIGN(4);
*(.text) /* remaining code */
*(.text.*) /* remaining code */
*(.rodata) /* read-only data (constants) */
*(.rodata*)
*(.glue_7)
*(.glue_7t)
*(.gnu.linkonce.t*)
/* section information for finsh shell */
. = ALIGN(4);
__fsymtab_start = .;
KEEP(*(FSymTab))
__fsymtab_end = .;
. = ALIGN(4);
__vsymtab_start = .;
KEEP(*(VSymTab))
__vsymtab_end = .;
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)))
__rt_init_end = .;
. = ALIGN(4);
KEEP(*(.init))
KEEP(*(.fini))
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
KEEP(*(.eh_frame*))
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
__etext = .;
.data : AT (__etext)
{
. = ALIGN(4);
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
KEEP(*(.jcr*))
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM
.stack_dummy (COPY):
{
. = ALIGN(8);
__stack_start__ = .;
*(.stack*)
__stack_end__ = .;
} > RAM
.bss __stack_end__ :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM
ASSERT(__StackTop <= 0x20028000, "stack address error")
}
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08010100 0x000EFEFF { ; load region size_region
ER_IROM1 0x08010100 0x000EFEFF { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x0003C000 { ; RW data
.ANY (+RW +ZI)
}
}
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-21 fanwenl first version
*/
#include <rtthread.h>
#include "wm_io.h"
#include "pin_map.h"
#if defined(SOC_W600_A8xx)
#define WM60X_PIN_NUMBERS 33
#elif defined(SOC_W601_A8xx)
#define WM60X_PIN_NUMBERS 69
#endif
#define __WM_PIN(index, gpio_index) (gpio_index)
#define WM_PIN_NUM(items) (sizeof(items) / sizeof(items[0]))
/* WM chip GPIO map*/
static const rt_int16_t pins[] =
{
__WM_PIN(0, WM_PIN_DEFAULT),
#if (WM60X_PIN_NUMBERS == 33)
__WM_PIN(1, WM_PIN_DEFAULT),
__WM_PIN(2, WM_PIN_DEFAULT),
__WM_PIN(3, WM_PIN_DEFAULT),
__WM_PIN(4, WM_PIN_DEFAULT),
__WM_PIN(5, WM_PIN_DEFAULT),
__WM_PIN(6, WM_PIN_DEFAULT),
__WM_PIN(7, WM_PIN_DEFAULT),
__WM_PIN(8, WM_PIN_DEFAULT),
__WM_PIN(9, WM_PIN_DEFAULT),
__WM_PIN(10, WM_PIN_DEFAULT),
__WM_PIN(11, WM_PIN_DEFAULT),
__WM_PIN(12, WM_PIN_DEFAULT),
__WM_PIN(13, WM_IO_PA_00),
__WM_PIN(14, WM_IO_PA_01),
__WM_PIN(15, WM_IO_PA_04),
__WM_PIN(16, WM_PIN_DEFAULT),
__WM_PIN(17, WM_IO_PA_05),
__WM_PIN(18, WM_IO_PB_13),
__WM_PIN(19, WM_IO_PB_14),
__WM_PIN(20, WM_IO_PB_15),
__WM_PIN(21, WM_IO_PB_16),
__WM_PIN(22, WM_IO_PB_17),
__WM_PIN(23, WM_IO_PB_18),
__WM_PIN(24, WM_PIN_DEFAULT),
__WM_PIN(25, WM_PIN_DEFAULT),
__WM_PIN(26, WM_IO_PB_06),
__WM_PIN(27, WM_IO_PB_07),
__WM_PIN(28, WM_IO_PB_08),
__WM_PIN(29, WM_IO_PB_09),
__WM_PIN(30, WM_IO_PB_10),
__WM_PIN(31, WM_IO_PB_11),
__WM_PIN(32, WM_IO_PB_12),
__WM_PIN(33, WM_PIN_DEFAULT),
#elif (WM60X_PIN_NUMBERS == 69)
__WM_PIN(1, WM_IO_PB_19),
__WM_PIN(2, WM_IO_PB_20),
__WM_PIN(3, WM_IO_PB_21),
__WM_PIN(4, WM_IO_PB_22),
__WM_PIN(5, WM_IO_PB_23),
__WM_PIN(6, WM_IO_PB_24),
__WM_PIN(7, WM_IO_PB_25),
__WM_PIN(8, WM_IO_PB_26),
__WM_PIN(9, WM_PIN_DEFAULT),
__WM_PIN(10, WM_PIN_DEFAULT),
__WM_PIN(11, WM_PIN_DEFAULT),
__WM_PIN(12, WM_PIN_DEFAULT),
__WM_PIN(13, WM_PIN_DEFAULT),
__WM_PIN(14, WM_PIN_DEFAULT),
__WM_PIN(15, WM_PIN_DEFAULT),
__WM_PIN(16, WM_PIN_DEFAULT),
__WM_PIN(17, WM_PIN_DEFAULT),
__WM_PIN(18, WM_PIN_DEFAULT),
__WM_PIN(19, WM_PIN_DEFAULT),
__WM_PIN(20, WM_PIN_DEFAULT),
__WM_PIN(21, WM_PIN_DEFAULT),
__WM_PIN(22, WM_PIN_DEFAULT),
__WM_PIN(23, WM_IO_PA_00),
__WM_PIN(24, WM_IO_PA_01),
__WM_PIN(25, WM_IO_PA_02),
__WM_PIN(26, WM_IO_PA_03),
__WM_PIN(27, WM_IO_PA_04),
__WM_PIN(28, WM_PIN_DEFAULT),
__WM_PIN(29, WM_IO_PA_05),
__WM_PIN(30, WM_IO_PA_13),
__WM_PIN(31, WM_IO_PA_14),
__WM_PIN(32, WM_IO_PA_15),
__WM_PIN(33, WM_IO_PA_06),
__WM_PIN(34, WM_PIN_DEFAULT),
__WM_PIN(35, WM_IO_PA_07),
__WM_PIN(36, WM_IO_PA_08),
__WM_PIN(37, WM_IO_PA_09),
__WM_PIN(38, WM_IO_PA_10),
__WM_PIN(39, WM_IO_PA_11),
__WM_PIN(40, WM_IO_PA_12),
__WM_PIN(41, WM_IO_PB_28),
__WM_PIN(42, WM_PIN_DEFAULT),
__WM_PIN(43, WM_IO_PB_13),
__WM_PIN(44, WM_IO_PB_14),
__WM_PIN(45, WM_IO_PB_15),
__WM_PIN(46, WM_PIN_DEFAULT),
__WM_PIN(47, WM_IO_PB_16),
__WM_PIN(48, WM_IO_PB_17),
__WM_PIN(49, WM_IO_PB_18),
__WM_PIN(50, WM_PIN_DEFAULT),
__WM_PIN(51, WM_IO_PB_30),
__WM_PIN(52, WM_IO_PB_31),
__WM_PIN(53, WM_IO_PB_27),
__WM_PIN(54, WM_IO_PB_00),
__WM_PIN(55, WM_IO_PB_01),
__WM_PIN(56, WM_IO_PB_02),
__WM_PIN(57, WM_IO_PB_03),
__WM_PIN(58, WM_PIN_DEFAULT),
__WM_PIN(59, WM_IO_PB_04),
__WM_PIN(60, WM_IO_PB_05),
__WM_PIN(61, WM_IO_PB_06),
__WM_PIN(62, WM_IO_PB_07),
__WM_PIN(63, WM_IO_PB_08),
__WM_PIN(64, WM_IO_PB_09),
__WM_PIN(65, WM_IO_PB_10),
__WM_PIN(66, WM_IO_PB_11),
__WM_PIN(67, WM_IO_PB_12),
__WM_PIN(68, WM_PIN_DEFAULT),
__WM_PIN(69, WM_PIN_DEFAULT),
#endif
};
rt_int16_t wm_get_pin(rt_base_t pin_index)
{
rt_int16_t gpio_pin = WM_PIN_DEFAULT;
if (pin_index < WM_PIN_NUM(pins))
{
gpio_pin = pins[pin_index];
}
return gpio_pin;
}
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-21 fanwenl first version
*/
#ifndef __PIN_MAP_H__
#define __PIN_MAP_H__
#include <rtthread.h>
#define WM_PIN_DEFAULT (-1)
rt_int16_t wm_get_pin(rt_base_t pin_index);
#endif
@echo off
@rem if debug_info=1, Debugging Print Information will be turned on
set debug_info=0
@rem if make_fal=1, Partition tables are put into firmware
set make_fal=0
@rem Setting firmware output directory
set out_path=.\Bin
@rem Setting the bin file path
set bin_file=.\rtthread.bin
@rem Setting winnermicro libraries path
set wmlib_path=.\packages\wm_libraries-
@rem Setting the 1M flash layout file
set layout_1M_file=.
@rem Setting the 2M flash layout file
set layout_2M_file=.
@rem Setting the makeimg by adding rtt flash original fls
set makeimg_new_fls=.
if "%wmlib_path:~0,1%" == "." (set wmlib_path=%~dp0%wmlib_path%)
@rem find winnermicro libraries full path
for /f "delims=" %%i in ('dir /ad /b /s %wmlib_path%*') do (set wmlib_path_full=%%i)
@rem Setting the version.txt file path
set version_file=%wmlib_path_full%\Tools\version.txt
@rem Setting the secboot.img file path
set secboot_file=%wmlib_path_full%\Tools\secboot.img
@rem Setting the wm_gzip.exe file path
set wm_gzip_file=%wmlib_path_full%\Tools\wm_gzip.exe
@rem Setting the makeimg.exe file path
set makeimg_file=%wmlib_path_full%\Tools\makeimg.exe
@rem Setting the makeimg_all.exe file path
set makeimg_all_file=%wmlib_path_full%\Tools\makeimg_all.exe
@rem Prepare to generate firmware
@rem Get the full path
if "%out_path:~0,1%" == "." (set out_path=%~dp0%out_path%)
if "%bin_file:~0,1%" == "." (set bin_file=%~dp0%bin_file%)
@rem Create output folder
if not exist "%out_path%" (md "%out_path%")
@rem Copy the required files
if exist "%bin_file%" (copy "%bin_file%" "%out_path%") else (echo makeimg err! No bin file found: %bin_file% & goto end)
if exist "%version_file%" (copy "%version_file%" "%out_path%") else (echo makeimg err! No version file found: %version_file% & goto end)
if exist "%secboot_file%" (copy "%secboot_file%" "%out_path%") else (echo makeimg err! No secboot file found: %secboot_file% & goto end)
@rem Check the existence of firmware generation tools
if not exist "%wm_gzip_file%" (echo makeimg err! No wm_gzip file found: "%wm_gzip_file%" & goto end)
if not exist "%makeimg_file%" (echo makeimg err! No makeimg file found: "%makeimg_file%" & goto end)
if not exist "%makeimg_all_file%" (echo makeimg err! No makeimg_all file found: "%makeimg_all_file%" & goto end)
@rem Get File Names and File Extensions
for /f "delims=" %%A in ('dir /b %bin_file%') do set "bin_file_name=%%A"
for /f "delims=." %%A in ('dir /b %bin_file%') do set bin_name=%%A
for /f "delims=%bin_name%" %%A in ('dir /b %bin_file%') do set bin_extend=%%A
for /f "delims=" %%A in ('dir /b %version_file%') do set "version_file_name=%%A"
for /f "delims=" %%A in ('dir /b %secboot_file%') do set "secboot_file_name=%%A"
@rem Print Debug Information
if not "%debug_info%"=="0" (echo bin_file_name:%bin_file_name% & echo bin_name:%bin_name% & echo bin_extend:%bin_extend% & echo version_file_name:%version_file_name% & echo secboot_file_name:%secboot_file_name%)
echo makeimg 1M Flash...
@rem Start making 1M flash firmware
set file_pos_1M=_1M
@rem Create command parameters
set wm_gzip_cmd="%out_path%\%bin_file_name%"
set makeimg_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%%file_pos_1M%.img" 0 0 "%out_path%\%version_file_name%" 90000 10100
set makeimg_gz_img_cmd="%out_path%\%bin_file_name%.gz" "%out_path%\%bin_name%_GZ%file_pos_1M%.img" 0 1 "%out_path%\%version_file_name%" 90000 10100 "%out_path%\%bin_file_name%"
set makeimg_sec_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%_SEC%file_pos_1M%.img" 0 0 "%out_path%\%version_file_name%" 90000 10100
set makeimg_all_cmd="%out_path%\%secboot_file_name%" "%out_path%\%bin_name%%file_pos_1M%.img" "%out_path%\%bin_name%%file_pos_1M%.FLS"
@rem Print command Information
if not "%debug_info%"=="0" (echo wm_gzip %wm_gzip_cmd%)
if not "%debug_info%"=="0" (echo makeimg %makeimg_img_cmd%)
if not "%debug_info%"=="0" (echo makeimg %makeimg_gz_img_cmd%)
if not "%debug_info%"=="0" (echo makeimg %makeimg_sec_img_cmd%)
if not "%debug_info%"=="0" (echo makeimg_all %makeimg_all_cmd%)
@rem Execute firmware generation commands
"%wm_gzip_file%" %wm_gzip_cmd%
"%makeimg_file%" %makeimg_img_cmd%
"%makeimg_file%" %makeimg_gz_img_cmd%
"%makeimg_file%" %makeimg_sec_img_cmd%
"%makeimg_all_file%" %makeimg_all_cmd%
@rem Delete temporary files
if exist "%out_path%\%bin_name%%file_pos_1M%.img" (del "%out_path%\%bin_name%%file_pos_1M%.img")
if exist "%out_path%\%bin_file_name%.gz" (del "%out_path%\%bin_file_name%.gz")
@rem Start making 2M flash firmware
echo makeimg 2M Flash...
set file_pos_2M=_2M
@rem Create command parameters
set wm_gzip_cmd="%out_path%\%bin_file_name%"
set makeimg_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%%file_pos_2M%.img" 3 0 "%out_path%\%version_file_name%" 100000 10100
set makeimg_gz_img_cmd="%out_path%\%bin_file_name%.gz" "%out_path%\%bin_name%_GZ%file_pos_2M%.img" 3 1 "%out_path%\%version_file_name%" 100000 10100 "%out_path%\%bin_file_name%"
set makeimg_sec_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%_SEC%file_pos_2M%.img" 3 0 "%out_path%\%version_file_name%" 100000 10100
set makeimg_all_cmd="%out_path%\%secboot_file_name%" "%out_path%\%bin_name%%file_pos_2M%.img" "%out_path%\%bin_name%%file_pos_2M%.FLS"
@rem Print command Information
if not "%debug_info%"=="0" (echo wm_gzip %wm_gzip_cmd%)
if not "%debug_info%"=="0" (echo makeimg %makeimg_img_cmd%)
if not "%debug_info%"=="0" (echo makeimg %makeimg_gz_img_cmd%)
if not "%debug_info%"=="0" (echo makeimg %makeimg_sec_img_cmd%)
if not "%debug_info%"=="0" (echo makeimg_all %makeimg_all_cmd%)
@rem Execute firmware generation commands
"%wm_gzip_file%" %wm_gzip_cmd%
"%makeimg_file%" %makeimg_img_cmd%
"%makeimg_file%" %makeimg_gz_img_cmd%
"%makeimg_file%" %makeimg_sec_img_cmd%
"%makeimg_all_file%" %makeimg_all_cmd%
@rem Delete temporary files
if exist "%out_path%\%bin_name%%file_pos_2M%.img" (del "%out_path%\%bin_name%%file_pos_2M%.img")
if exist "%out_path%\%bin_file_name%.gz" (del "%out_path%\%bin_file_name%.gz")
@rem Partition tables are put into firmware
if not "%make_fal%"=="1" ( goto end)
@rem Get the full path
if "%layout_1M_file:~0,1%" == "." (set layout_1M_file=%~dp0%layout_1M_file%)
if "%layout_2M_file:~0,1%" == "." (set layout_2M_file=%~dp0%layout_2M_file%)
if "%makeimg_new_fls:~0,1%" == "." (set makeimg_new_fls=%~dp0%makeimg_new_fls%)
@rem Check whether the file exists
if not exist "%layout_1M_file%" (echo makeimg err! No makeimg file found: "%layout_1M_file%" & goto end)
if not exist "%layout_2M_file%" (echo makeimg err! No makeimg file found: "%layout_2M_file%" & goto end)
if not exist "%makeimg_new_fls%" (echo makeimg err! No makeimg file found: "%makeimg_new_fls%" & goto end)
@rem Create command parameters to new fls
set makeimg_new_cmd_1M="%out_path%\%bin_name%%file_pos_1M%.FLS" "%layout_1M_file%" "%out_path%\%bin_name%_layout%file_pos_1M%.FLS"
@rem Execute generation fls cmd
"%makeimg_new_fls%" %makeimg_new_cmd_1M%
@rem Create command parameters to new fls
set makeimg_new_cmd_2M="%out_path%\%bin_name%%file_pos_2M%.FLS" "%layout_2M_file%" "%out_path%\%bin_name%_layout%file_pos_2M%.FLS"
@rem Execute generation fls cmd
"%makeimg_new_fls%" %makeimg_new_cmd_2M%
@rem Delete temporary files
if exist "%out_path%\%bin_name%_1M.FLS" (del "%out_path%\%bin_name%%file_pos_1M%.FLS")
if exist "%out_path%\%bin_name%_2M.FLS" (del "%out_path%\%bin_name%%file_pos_2M%.FLS")
:end
echo end
# -*- coding: utf-8 -*-
import os
import sys
import shutil
import subprocess
import time
import platform
# if debug_info=True, Debugging Print Information will be turned on
debug_info=False
# if make_fal=True, Partition tables are put into firmware
make_fal=False
# Setting firmware output directory
out_path='./Bin'
# Setting the bin file path
bin_file='./rtthread.bin'
# Setting winnermicro libraries path
wmlib_path='./packages/wm_libraries-'
# Setting the 1M flash layout file
layout_1M_file='.'
# Setting the 2M flash layout file
layout_2M_file='.'
# Setting the makeimg by adding rtt flash original fls
makeimg_new_fls='.'
def execute_command(cmdstring, cwd=None, shell=True):
"""Execute the system command at the specified address."""
if shell:
cmdstring_list = cmdstring
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, shell=shell, bufsize=8192)
stdout_str = ""
while sub.poll() is None:
stdout_str += str(sub.stdout.read())
time.sleep(0.1)
return stdout_str
def copy_file(name, path):
res = True
if os.path.exists(path):
shutil.copy(path, out_path)
else:
print('makeimg err! No ' + name + ' file found: ' + path)
res = False
return res
def is_exists(name, path):
res = True
if not os.path.exists(path):
print('makeimg err! No ' + name + ' file found: ' + path)
res = False
return res
def get_exec_path(path):
(file_path, file_name) = os.path.split(path)
(name, extend) = os.path.splitext(file_name)
exec_path = ''
if (platform.system() == "Windows"):
exec_path = os.path.abspath(file_path + '/' + name + '.exe')
elif (platform.system() == "Linux"):
exec_path = os.path.abspath(file_path + '/' + name)
if debug_info:
print('file_path: ' + file_path)
print('file_name: ' + file_name)
print('name: ' + name)
print('extend: ' + extend)
return exec_path
def do_makeimg(tool_path, param):
str = "\"" + tool_path + "\"" + ' ' + param
if debug_info:
print('exec cmd: ' + str);
execute_command(str)
def get_wmlib_path_full(path):
(_wmlib_path,_wmlib_name) = os.path.split(path)
files = os.listdir(_wmlib_path)
for f in files:
if _wmlib_name in f:
return _wmlib_path + '/' + f
return path
if __name__=='__main__':
# find winnermicro libraries full path
wmlib_path_full = get_wmlib_path_full(wmlib_path)
# Setting the version.txt file path
version_file=wmlib_path_full + '/Tools/version.txt'
# Setting the secboot.img file path
secboot_file=wmlib_path_full + '/Tools/secboot.img'
# Setting the wm_gzip.exe file path
wm_gzip_file=wmlib_path_full + '/Tools/wm_gzip.exe'
# Setting the makeimg.exe file path
makeimg_file=wmlib_path_full + '/Tools/makeimg.exe'
# Setting the makeimg_all.exe file path
makeimg_all_file=wmlib_path_full + '/Tools/makeimg_all.exe'
# Get absolute path
out_path = os.path.abspath(out_path).replace('\\', '/');
bin_file = os.path.abspath(bin_file).replace('\\', '/');
version_file = os.path.abspath(version_file).replace('\\', '/');
secboot_file = os.path.abspath(secboot_file).replace('\\', '/');
wm_gzip_file = os.path.abspath(wm_gzip_file).replace('\\', '/');
makeimg_file = os.path.abspath(makeimg_file).replace('\\', '/');
makeimg_all_file = os.path.abspath(makeimg_all_file).replace('\\', '/');
# Create the output directory
if not os.path.exists(out_path): os.mkdir(out_path)
# Copy file
if not copy_file('bin', bin_file): exit(0)
if not copy_file('version', version_file): exit(0)
if not copy_file('secboot', secboot_file): exit(0)
# Check the existence of packaging tools
if not is_exists('wm_gzip', wm_gzip_file): exit(0)
if not is_exists('makeimg', makeimg_file): exit(0)
if not is_exists('makeimg_all', makeimg_all_file): exit(0)
# Get File Names and File Extensions
(bin_file_path,bin_file_name) = os.path.split(bin_file)
(bin_name,bin_extend) = os.path.splitext(bin_file_name)
(version_file_path,version_file_name) = os.path.split(version_file)
(secboot_file_path,secboot_file_name) = os.path.split(secboot_file)
# print debug Information
if debug_info: print('bin_file_name:' + bin_file_name + 'bin_name:' + bin_name + 'bin_extend:' + bin_extend + 'version_file_name:' + version_file_name + 'secboot_file_name:' + secboot_file_name)
print('makeimg 1M Flash...')
file_pos_1M='_1M'
gzip_param = "\"" + out_path + '/' + bin_file_name + "\""
make_img_param = "\"" + out_path + '/' + bin_file_name + "\"" + ' ' + "\"" + out_path + '/' + bin_name + file_pos_1M + '.img' + "\"" + ' 0' + ' 0' + ' ' + "\"" + out_path + '/' + version_file_name + "\"" + ' 90000' + ' 10100'
make_GZ_param = "\"" + out_path + '/' + bin_file_name + '.gz' + "\"" + ' ' + "\"" + out_path + '/' + bin_name + '_GZ' + file_pos_1M + '.img' +"\"" + ' 0' + ' 1' + ' ' + "\"" + out_path + '/' + version_file_name + "\"" + ' 90000' + ' 10100' + ' ' + "\"" + out_path + '/' + bin_file_name + "\""
make_SEC_param = "\"" + out_path + '/' + bin_file_name + "\"" + ' ' + "\"" + out_path + '/' + bin_name + '_SEC' + file_pos_1M + '.img' + "\"" + ' 0' + ' 0' + ' ' + "\"" + out_path + '/' + version_file_name + "\"" + ' 90000' + ' 10100'
make_FLS_param = "\"" + out_path + '/' + secboot_file_name + "\"" + ' ' + "\"" + out_path + '/' + bin_name + file_pos_1M + '.img' + "\"" + ' ' + "\"" + out_path + '/' + bin_name + file_pos_1M + '.FLS' + "\""
if debug_info:
print('gzip_param' + gzip_param)
print('make_img_param' + make_img_param)
print('make_GZ_param' + make_GZ_param)
print('make_SEC_param' + make_SEC_param)
print('make_FLS_param' + make_FLS_param)
do_makeimg(wm_gzip_file, gzip_param)
do_makeimg(makeimg_file, make_img_param)
do_makeimg(makeimg_file, make_GZ_param)
do_makeimg(makeimg_file, make_SEC_param)
do_makeimg(makeimg_all_file, make_FLS_param)
rm_file = out_path + '/' + bin_name + file_pos_1M + '.img'
if os.path.exists(rm_file):
os.remove(rm_file)
rm_file = out_path + '/' + bin_file_name + '.gz'
if os.path.exists(rm_file):
os.remove(rm_file)
print('makeimg 2M Flash...')
file_pos_2M='_2M'
gzip_param = "\"" + out_path + '/' + bin_file_name + "\""
make_img_param = "\"" + out_path + '/' + bin_file_name + "\"" + ' ' + "\"" + out_path + '/' + bin_name + file_pos_2M + '.img' + "\"" + ' 3' + ' 0' + ' ' + "\"" + out_path + '/' + version_file_name + "\"" + ' 100000' + ' 10100'
make_GZ_param = "\"" + out_path + '/' + bin_file_name + '.gz' + "\"" + ' ' + "\"" + out_path + '/' + bin_name + '_GZ' + file_pos_2M + '.img' +"\"" + ' 3' + ' 1' + ' ' + "\"" + out_path + '/' + version_file_name + "\"" + ' 100000' + ' 10100' + ' ' + "\"" + out_path + '/' + bin_file_name + "\""
make_SEC_param = "\"" + out_path + '/' + bin_file_name + "\"" + ' ' + "\"" + out_path + '/' + bin_name + '_SEC' + file_pos_2M + '.img' + "\"" + ' 3' + ' 0' + ' ' + "\"" + out_path + '/' + version_file_name + "\"" + ' 100000' + ' 10100'
make_FLS_param = "\"" + out_path + '/' + secboot_file_name + "\"" + ' ' + "\"" + out_path + '/' + bin_name + file_pos_2M + '.img' + "\"" + ' ' + "\"" + out_path + '/' + bin_name + file_pos_2M + '.FLS' + "\""
if debug_info:
print('gzip_param' + gzip_param)
print('make_img_param' + make_img_param)
print('make_GZ_param' + make_GZ_param)
print('make_SEC_param' + make_SEC_param)
print('make_FLS_param' + make_FLS_param)
do_makeimg(wm_gzip_file, gzip_param)
do_makeimg(makeimg_file, make_img_param)
do_makeimg(makeimg_file, make_GZ_param)
do_makeimg(makeimg_file, make_SEC_param)
do_makeimg(makeimg_all_file, make_FLS_param)
rm_file = out_path + '/' + bin_name + file_pos_2M + '.img'
if os.path.exists(rm_file):
os.remove(rm_file)
rm_file = out_path + '/' + bin_file_name + '.gz'
if os.path.exists(rm_file):
os.remove(rm_file)
if make_fal:
# Get absolute path
layout_1M_file = os.path.abspath(layout_1M_file).replace('\\', '/');
layout_2M_file = os.path.abspath(layout_2M_file).replace('\\', '/');
makeimg_new_fls = os.path.abspath(makeimg_new_fls).replace('\\', '/');
# Create command parameters to new fls
makeimg_new_cmd="\"" + out_path + '/' + bin_name + file_pos_1M + '.FLS' + "\"" + ' ' + "\"" + layout_1M_file + "\"" + ' ' + "\"" + out_path + '/'+ bin_name + '_layout' + file_pos_1M+'.FLS' +"\""
do_makeimg(makeimg_new_fls, makeimg_new_cmd)
makeimg_new_cmd="\"" + out_path + '/' + bin_name + file_pos_2M + '.FLS' + "\"" + ' ' + "\"" + layout_2M_file + "\"" + ' ' + "\"" + out_path + '/'+ bin_name + '_layout' + file_pos_2M+'.FLS' +"\""
do_makeimg(makeimg_new_fls, makeimg_new_cmd)
# Delete temporary files
rm_file = out_path + '/' + bin_name + file_pos_1M + '.FLS'
if os.path.exists(rm_file):
os.remove(rm_file)
rm_file = out_path + '/' + bin_name + file_pos_2M + '.FLS'
if os.path.exists(rm_file):
os.remove(rm_file)
print('end')
\ No newline at end of file
此差异已折叠。
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\project.ewp</path>
</project>
<batchBuild/>
</workspace>
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册