Merge branch 'master' of https://github.com/RT-Thread/rt-thread
This commit is contained in:
commit
564df04da1
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* File : rt_low_level_iar.inc
|
||||
* File : rt_low_level_init.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
|
@ -19,8 +19,10 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-04-14 ArdaFu first version
|
||||
* 2018-06-04 ArdaFu first version
|
||||
*/
|
||||
#ifndef __RT_LOW_LEVEL_INIT_H__
|
||||
#define __RT_LOW_LEVEL_INIT_H__
|
||||
|
||||
/*-------- Stack size of CPU modes -------------------------------------------*/
|
||||
#define UND_STK_SIZE 512
|
||||
|
@ -29,3 +31,5 @@
|
|||
#define IRQ_STK_SIZE 1024
|
||||
#define FIQ_STK_SIZE 1024
|
||||
#define SYS_STK_SIZE 512
|
||||
#define Heap_Size 512
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
;/*
|
||||
; * File : rt_low_level_keil.inc
|
||||
; * This file is part of RT-Thread RTOS
|
||||
; * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
; *
|
||||
; * This program is free software; you can redistribute it and/or modify
|
||||
; * it under the terms of the GNU General Public License as published by
|
||||
; * the Free Software Foundation; either version 2 of the License, or
|
||||
; * (at your option) any later version.
|
||||
; *
|
||||
; * This program is distributed in the hope that it will be useful,
|
||||
; * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; * GNU General Public License for more details.
|
||||
; *
|
||||
; * You should have received a copy of the GNU General Public License along
|
||||
; * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
; *
|
||||
; * Change Logs:
|
||||
; * Date Author Notes
|
||||
; * 2015-04-14 ArdaFu first version
|
||||
; */
|
||||
|
||||
;/*-------- Stack size of CPU modes ------------------------------------------*/
|
||||
UND_STK_SIZE EQU 512
|
||||
SVC_STK_SIZE EQU 4096
|
||||
ABT_STK_SIZE EQU 512
|
||||
IRQ_STK_SIZE EQU 1024
|
||||
FIQ_STK_SIZE EQU 1024
|
||||
SYS_STK_SIZE EQU 512
|
||||
Heap_Size EQU 512
|
||||
END
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* File : rt_low_level_gcc.inc
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-04-14 ArdaFu first version
|
||||
*/
|
||||
|
||||
/*--------- Stack size of CPU modes ------------------------------------------*/
|
||||
.equ UND_STK_SIZE, 2048
|
||||
.equ SVC_STK_SIZE, 4096
|
||||
.equ ABT_STK_SIZE, 2048
|
||||
.equ IRQ_STK_SIZE, 4096
|
||||
.equ FIQ_STK_SIZE, 4096
|
||||
.equ SYS_STK_SIZE, 2048
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* File : rt_low_level_iar.inc
|
||||
* File : rt_low_level_init.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
*
|
||||
|
@ -19,8 +19,10 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-04-14 ArdaFu first version
|
||||
* 2018-06-04 ArdaFu first version
|
||||
*/
|
||||
#ifndef __RT_LOW_LEVEL_INIT_H__
|
||||
#define __RT_LOW_LEVEL_INIT_H__
|
||||
|
||||
/*-------- Stack size of CPU modes -------------------------------------------*/
|
||||
#define UND_STK_SIZE 512
|
||||
|
@ -29,3 +31,5 @@
|
|||
#define IRQ_STK_SIZE 1024
|
||||
#define FIQ_STK_SIZE 1024
|
||||
#define SYS_STK_SIZE 512
|
||||
#define Heap_Size 512
|
||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||
;/*
|
||||
; * File : rt_low_level_keil.inc
|
||||
; * This file is part of RT-Thread RTOS
|
||||
; * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
; *
|
||||
; * This program is free software; you can redistribute it and/or modify
|
||||
; * it under the terms of the GNU General Public License as published by
|
||||
; * the Free Software Foundation; either version 2 of the License, or
|
||||
; * (at your option) any later version.
|
||||
; *
|
||||
; * This program is distributed in the hope that it will be useful,
|
||||
; * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; * GNU General Public License for more details.
|
||||
; *
|
||||
; * You should have received a copy of the GNU General Public License along
|
||||
; * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
; *
|
||||
; * Change Logs:
|
||||
; * Date Author Notes
|
||||
; * 2015-04-14 ArdaFu first version
|
||||
; */
|
||||
|
||||
;/*-------- Stack size of CPU modes ------------------------------------------*/
|
||||
UND_STK_SIZE EQU 512
|
||||
SVC_STK_SIZE EQU 4096
|
||||
ABT_STK_SIZE EQU 512
|
||||
IRQ_STK_SIZE EQU 1024
|
||||
FIQ_STK_SIZE EQU 1024
|
||||
SYS_STK_SIZE EQU 512
|
||||
END
|
|
@ -28,7 +28,6 @@
|
|||
#include <platform.h>
|
||||
#include <encoding.h>
|
||||
#include <interrupt.h>
|
||||
#include <drv_led.h>
|
||||
|
||||
extern void use_default_clocks(void);
|
||||
extern void use_pll(int refsel, int bypass, int r, int f, int q);
|
||||
|
|
|
@ -433,6 +433,8 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p)
|
|||
enet_handle_t * enet_handle = &lpc_emac_device.handle;
|
||||
ENET_Type *enet_base = lpc_emac_device.base;
|
||||
uint8_t * data;
|
||||
|
||||
uint16_t len;
|
||||
|
||||
RT_ASSERT(p != NULL);
|
||||
RT_ASSERT(enet_handle != RT_NULL);
|
||||
|
@ -454,11 +456,13 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p)
|
|||
}
|
||||
}
|
||||
|
||||
data = (uint8_t *)ENET_ALIGN(&lpc_emac_device.RxDataBuff[lpc_emac_device.txIdx * ENET_ALIGN(ENET_RXBUFF_SIZE)]);
|
||||
pbuf_copy_partial(p, data, p->tot_len, 0);
|
||||
// fix RxDataBuff -> TxDataBuff, ENET_RXBUFF_SIZE -> ENET_TXBUFF_SIZE
|
||||
data = (uint8_t *)ENET_ALIGN(&lpc_emac_device.TxDataBuff[lpc_emac_device.txIdx * ENET_ALIGN(ENET_TXBUFF_SIZE)]);
|
||||
len = pbuf_copy_partial(p, data, p->tot_len, 0);
|
||||
lpc_emac_device.txIdx = (lpc_emac_device.txIdx + 1) / ENET_TXBD_NUM;
|
||||
|
||||
result = ENET_SendFrame(enet_base, enet_handle, data, p->len);
|
||||
// fix 'p->len' to 'len', avoid send wrong partial packet.
|
||||
result = ENET_SendFrame(enet_base, enet_handle, data, len);
|
||||
|
||||
if ((result == kStatus_ENET_TxFrameFail) || (result == kStatus_ENET_TxFrameOverLen) || (result == kStatus_ENET_TxFrameBusy))
|
||||
{
|
||||
|
|
|
@ -407,6 +407,22 @@ rt_err_t mci_hw_init(const char *device_name)
|
|||
rt_kprintf("SD_Init failed!\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
follow the page: https://community.nxp.com/thread/454769
|
||||
|
||||
The issue concerns sdmmc library bug (I finally solved) in SD_Init() in the file sdmmc/src/fsl_sd.c:SD_SelectBusTiming()
|
||||
calls SD_SwitchFunction() which sets block size to 64bytes (512bits).Therefore SD_SetBlockSize(card, FSL_SDMMC_DEFAULT_BLOCK_SIZE)
|
||||
should be called again before SD_Init() exits.
|
||||
*/
|
||||
|
||||
if (kStatus_Success != SDMMC_SetBlockSize(_mci_device->card.host.base, _mci_device->card.host.transfer, FSL_SDMMC_DEFAULT_BLOCK_SIZE))
|
||||
{
|
||||
SD_Deinit(&_mci_device->card);
|
||||
memset(&_mci_device->card, 0U, sizeof(_mci_device->card));
|
||||
rt_kprintf("SD_Init failed!\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* initialize mutex lock */
|
||||
rt_mutex_init(&_mci_device->lock, device_name, RT_IPC_FLAG_FIFO);
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-11-02 勤为本 first version
|
||||
* 2017-11-02 勤为本 first version
|
||||
* 2018-06-09 zhuangwei add spi0 cs0 support,remove msd_init
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
@ -42,14 +43,14 @@ static rt_err_t configure(struct rt_spi_device *device, struct rt_spi_configurat
|
|||
static rt_uint32_t xfer(struct rt_spi_device *device, struct rt_spi_message *message);
|
||||
|
||||
|
||||
static struct rt_spi_ops ls1c_spi_ops =
|
||||
static struct rt_spi_ops ls1c_spi_ops =
|
||||
{
|
||||
.configure = configure,
|
||||
.xfer = xfer
|
||||
};
|
||||
|
||||
|
||||
static rt_err_t configure(struct rt_spi_device *device,
|
||||
static rt_err_t configure(struct rt_spi_device *device,
|
||||
struct rt_spi_configuration *configuration)
|
||||
{
|
||||
struct rt_spi_bus *spi_bus = NULL;
|
||||
|
@ -69,28 +70,28 @@ static rt_err_t configure(struct rt_spi_device *device,
|
|||
spi_base = ls1c_spi_get_base(SPIx);
|
||||
|
||||
{
|
||||
// 使能SPI控制器,master模式,关闭中断
|
||||
// 使能SPI控制器,master模式,关闭中断
|
||||
reg_write_8(0x53, spi_base + LS1C_SPI_SPCR_OFFSET);
|
||||
|
||||
// 清空状态寄存器
|
||||
// 清空状态寄存器
|
||||
reg_write_8(0xc0, spi_base + LS1C_SPI_SPSR_OFFSET);
|
||||
|
||||
// 1字节产生中断,采样(读)与发送(写)时机同时
|
||||
// 1字节产生中断,采样(读)与发送(写)时机同时
|
||||
reg_write_8(0x03, spi_base + LS1C_SPI_SPER_OFFSET);
|
||||
|
||||
// 关闭SPI flash
|
||||
// 关闭SPI flash
|
||||
val = reg_read_8(spi_base + LS1C_SPI_SFC_PARAM_OFFSET);
|
||||
val &= 0xfe;
|
||||
reg_write_8(val, spi_base + LS1C_SPI_SFC_PARAM_OFFSET);
|
||||
|
||||
// spi flash时序控制寄存器
|
||||
// spi flash时序控制寄存器
|
||||
reg_write_8(0x05, spi_base + LS1C_SPI_SFC_TIMING_OFFSET);
|
||||
}
|
||||
|
||||
|
||||
// baudrate
|
||||
ls1c_spi_set_clock(spi_base, configuration->max_hz);
|
||||
|
||||
// 设置通信模式(时钟极性和相位)
|
||||
// 设置通信模式(时钟极性和相位)
|
||||
if (configuration->mode & RT_SPI_CPOL) // cpol
|
||||
{
|
||||
cpol = SPI_CPOL_1;
|
||||
|
@ -115,7 +116,7 @@ static rt_err_t configure(struct rt_spi_device *device,
|
|||
}
|
||||
|
||||
|
||||
static rt_uint32_t xfer(struct rt_spi_device *device,
|
||||
static rt_uint32_t xfer(struct rt_spi_device *device,
|
||||
struct rt_spi_message *message)
|
||||
{
|
||||
struct rt_spi_bus *spi_bus = NULL;
|
||||
|
@ -148,7 +149,7 @@ static rt_uint32_t xfer(struct rt_spi_device *device,
|
|||
ls1c_spi_set_cs(spi_base, cs, 0);
|
||||
}
|
||||
|
||||
// 收发数据
|
||||
// 收发数据
|
||||
send_ptr = message->send_buf;
|
||||
recv_ptr = message->recv_buf;
|
||||
while (size--)
|
||||
|
@ -180,7 +181,7 @@ static rt_uint32_t xfer(struct rt_spi_device *device,
|
|||
|
||||
|
||||
#ifdef RT_USING_SPI0
|
||||
struct ls1c_spi ls1c_spi0 =
|
||||
struct ls1c_spi ls1c_spi0 =
|
||||
{
|
||||
.SPIx = LS1C_SPI_0,
|
||||
};
|
||||
|
@ -190,7 +191,7 @@ static struct rt_spi_bus spi0_bus;
|
|||
|
||||
|
||||
#ifdef RT_USING_SPI1
|
||||
struct ls1c_spi ls1c_spi1 =
|
||||
struct ls1c_spi ls1c_spi1 =
|
||||
{
|
||||
.SPIx = LS1C_SPI_1,
|
||||
};
|
||||
|
@ -200,10 +201,10 @@ static struct rt_spi_bus spi1_bus;
|
|||
|
||||
|
||||
/*
|
||||
* 初始化并注册龙芯1c的spi总线
|
||||
* @SPI SPI总线,比如LS1C_SPI_0, LS1C_SPI_1
|
||||
* @spi_bus_name 总线名字
|
||||
* @ret
|
||||
* 初始化并注册龙芯1c的spi总线
|
||||
* @SPI SPI总线,比如LS1C_SPI_0, LS1C_SPI_1
|
||||
* @spi_bus_name 总线名字
|
||||
* @ret
|
||||
*/
|
||||
rt_err_t ls1c_spi_bus_register(rt_uint8_t SPI, const char *spi_bus_name)
|
||||
{
|
||||
|
@ -235,14 +236,16 @@ int ls1c_hw_spi_init(void)
|
|||
pin_set_purpose(79, PIN_PURPOSE_OTHER);
|
||||
pin_set_purpose(80, PIN_PURPOSE_OTHER);
|
||||
pin_set_purpose(83, PIN_PURPOSE_OTHER);//cs2 - SD card
|
||||
pin_set_purpose(82, PIN_PURPOSE_OTHER);//cs1
|
||||
|
||||
pin_set_remap(78, PIN_REMAP_FOURTH);
|
||||
pin_set_remap(79, PIN_REMAP_FOURTH);
|
||||
pin_set_remap(80, PIN_REMAP_FOURTH);
|
||||
pin_set_remap(83, PIN_REMAP_FOURTH);//cs2 - SD card
|
||||
pin_set_remap(82, PIN_REMAP_FOURTH);//cs1
|
||||
ls1c_spi_bus_register(LS1C_SPI_0,"spi0");
|
||||
pin_set_purpose(82, PIN_PURPOSE_OTHER);//cs1
|
||||
pin_set_purpose(81, PIN_PURPOSE_OTHER);//cs0
|
||||
|
||||
pin_set_remap(78, PIN_REMAP_DEFAULT);
|
||||
pin_set_remap(79, PIN_REMAP_DEFAULT);
|
||||
pin_set_remap(80, PIN_REMAP_DEFAULT);
|
||||
pin_set_remap(83, PIN_REMAP_DEFAULT);//cs2 - SD card
|
||||
pin_set_remap(82, PIN_REMAP_DEFAULT);//CS1
|
||||
pin_set_remap(81, PIN_REMAP_DEFAULT);//cs0
|
||||
ls1c_spi_bus_register(LS1C_SPI_0, "spi0");
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_SPI1
|
||||
|
@ -254,7 +257,7 @@ int ls1c_hw_spi_init(void)
|
|||
pin_set_remap(47, PIN_REMAP_THIRD);
|
||||
pin_set_remap(48, PIN_REMAP_THIRD);
|
||||
pin_set_remap(49, PIN_REMAP_THIRD);//CS0 - touch screen
|
||||
ls1c_spi_bus_register(LS1C_SPI_1,"spi1");
|
||||
ls1c_spi_bus_register(LS1C_SPI_1, "spi1");
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -262,31 +265,35 @@ int ls1c_hw_spi_init(void)
|
|||
#ifdef RT_USING_SPI0
|
||||
/* attach cs */
|
||||
{
|
||||
static struct rt_spi_device spi_device0;
|
||||
static struct rt_spi_device spi_device1;
|
||||
static struct rt_spi_device spi_device2;
|
||||
static struct ls1c_spi_cs spi_cs0;
|
||||
static struct ls1c_spi_cs spi_cs1;
|
||||
static struct ls1c_spi_cs spi_cs2;
|
||||
|
||||
/* spi02: CS2 SD Card*/
|
||||
spi_cs2.cs = LS1C_SPI_CS_2;
|
||||
rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void*)&spi_cs2);
|
||||
rt_spi_bus_attach_device(&spi_device2, "spi02", "spi0", (void *)&spi_cs2);
|
||||
spi_cs1.cs = LS1C_SPI_CS_1;
|
||||
rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void*)&spi_cs1);
|
||||
msd_init("sd0", "spi02");
|
||||
rt_spi_bus_attach_device(&spi_device1, "spi01", "spi0", (void *)&spi_cs1);
|
||||
spi_cs0.cs = LS1C_SPI_CS_0;
|
||||
rt_spi_bus_attach_device(&spi_device0, "spi00", "spi0", (void *)&spi_cs0);
|
||||
}
|
||||
#endif
|
||||
#ifdef RT_USING_SPI1
|
||||
#ifdef RT_USING_SPI1
|
||||
{
|
||||
static struct rt_spi_device spi_device;
|
||||
static struct ls1c_spi_cs spi_cs;
|
||||
|
||||
/* spi10: CS0 Touch*/
|
||||
spi_cs.cs = LS1C_SPI_CS_0;
|
||||
rt_spi_bus_attach_device(&spi_device, "spi10", "spi1", (void*)&spi_cs);
|
||||
rt_spi_bus_attach_device(&spi_device, "spi10", "spi1", (void *)&spi_cs);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
INIT_BOARD_EXPORT(ls1c_hw_spi_init);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -260,7 +260,7 @@ inline void ls1c_spi_clear(void *spi_base)
|
|||
val = reg_read_8(spi_base + LS1C_SPI_SPSR_OFFSET);
|
||||
if (LS1C_SPI_SPSR_WCOL_MASK & val)
|
||||
{
|
||||
rt_kprintf("[%s] clear register SPSR's wcol!\r\n"); // 手册和linux源码中不一样,加个打印看看
|
||||
rt_kprintf("[%s] clear register SPSR's wcol!\r\n",__FUNCTION__); // 手册和linux源码中不一样,加个打印看看
|
||||
reg_write_8(val & ~LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET); // 写0,linux源码中是写0
|
||||
// reg_write_8(val | LS1C_SPI_SPSR_WCOL_MASK, spi_base + LS1C_SPI_SPSR_OFFSET); // 写1,按照1c手册,应该写1
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ static rt_err_t stm32f1_wdg_control(rt_watchdog_t *wdt, int cmd, void *arg)
|
|||
switch(cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
|
||||
timeout_ms = (rt_uint32_t) arg;
|
||||
timeout_ms = *((rt_uint32_t*) arg);
|
||||
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
|
||||
if(timeout_ms >= 13107)
|
||||
{
|
||||
|
|
|
@ -66,6 +66,10 @@ config RT_USING_PIN
|
|||
bool "Using generic GPIO device drivers"
|
||||
default y
|
||||
|
||||
config RT_USING_PWM
|
||||
bool "Using PWM device drivers"
|
||||
default n
|
||||
|
||||
config RT_USING_MTD_NOR
|
||||
bool "Using MTD Nor Flash device drivers"
|
||||
default n
|
||||
|
@ -162,6 +166,24 @@ config RT_USING_WIFI
|
|||
bool "Using Wi-Fi network"
|
||||
default n
|
||||
|
||||
if RT_USING_WIFI
|
||||
config RT_USING_WLAN_STA
|
||||
bool "Using station mode"
|
||||
default y
|
||||
|
||||
config RT_USING_WLAN_AP
|
||||
bool "Using ap mode"
|
||||
default n
|
||||
|
||||
config WIFI_DEVICE_STA_NAME
|
||||
string "the wifi device name for station"
|
||||
default "w0"
|
||||
|
||||
config WIFI_DEVICE_AP_NAME
|
||||
string "the wifi device name for ap"
|
||||
default "ap"
|
||||
endif
|
||||
|
||||
config RT_USING_AUDIO
|
||||
bool "Using Audio device drivers"
|
||||
default n
|
||||
|
|
|
@ -54,6 +54,9 @@ int cortexm_cputime_init(void)
|
|||
/* check support bit */
|
||||
if ((DWT->CTRL & (1UL << DWT_CTRL_NOCYCCNT_Pos)) == 0)
|
||||
{
|
||||
/* enable trace*/
|
||||
CoreDebug->DEMCR |= (1UL << CoreDebug_DEMCR_TRCENA_Pos);
|
||||
|
||||
/* whether cycle counter not enabled */
|
||||
if ((DWT->CTRL & (1UL << DWT_CTRL_CYCCNTENA_Pos)) == 0)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* File : rt_drv_pwm.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-07 aozima the first version
|
||||
*/
|
||||
|
||||
#ifndef __DRV_PWM_H_INCLUDE__
|
||||
#define __DRV_PWM_H_INCLUDE__
|
||||
|
||||
#define PWM_CMD_ENABLE (128 + 0)
|
||||
#define PWM_CMD_DISABLE (128 + 1)
|
||||
#define PWM_CMD_SET (128 + 2)
|
||||
#define PWM_CMD_GET (128 + 3)
|
||||
|
||||
struct rt_pwm_configuration
|
||||
{
|
||||
rt_uint32_t channel; /* 0-n */
|
||||
rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */
|
||||
rt_uint32_t pulse; /* unit:ns (pulse<=period) */
|
||||
};
|
||||
|
||||
struct rt_device_pwm;
|
||||
struct rt_pwm_ops
|
||||
{
|
||||
rt_err_t (*control)(struct rt_device_pwm *device, int cmd, void *arg);
|
||||
};
|
||||
|
||||
struct rt_device_pwm
|
||||
{
|
||||
struct rt_device parent;
|
||||
const struct rt_pwm_ops *ops;
|
||||
};
|
||||
|
||||
extern rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data);
|
||||
|
||||
#endif /* __DRV_PWM_H_INCLUDE__ */
|
|
@ -112,6 +112,10 @@ extern "C" {
|
|||
#include "drivers/cputime.h"
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_PWM
|
||||
#include "drivers/rt_drv_pwm.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,6 +8,9 @@ group = []
|
|||
if GetDepend(['RT_USING_PIN']):
|
||||
src = src + ['pin.c']
|
||||
|
||||
if GetDepend(['RT_USING_PWM']):
|
||||
src = src + ['rt_drv_pwm.c']
|
||||
|
||||
if len(src):
|
||||
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
|
|
|
@ -0,0 +1,214 @@
|
|||
/*
|
||||
* File : rt_drv_pwm.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-07 aozima the first version
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
|
||||
static rt_err_t _pwm_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_device_pwm *pwm = (struct rt_device_pwm *)dev;
|
||||
|
||||
if (pwm->ops->control)
|
||||
{
|
||||
result = pwm->ops->control(pwm, cmd, args);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
pos: channel
|
||||
void *buffer: rt_uint32_t pulse[size]
|
||||
size : number of pulse, only set to sizeof(rt_uint32_t).
|
||||
*/
|
||||
static rt_size_t _pwm_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_device_pwm *pwm = (struct rt_device_pwm *)dev;
|
||||
rt_uint32_t *pulse = (rt_uint32_t *)buffer;
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
configuration.channel = pos;
|
||||
|
||||
if (pwm->ops->control)
|
||||
{
|
||||
result = pwm->ops->control(pwm, PWM_CMD_GET, &configuration);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
*pulse = configuration.pulse;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
pos: channel
|
||||
void *buffer: rt_uint32_t pulse[size]
|
||||
size : number of pulse, only set to sizeof(rt_uint32_t).
|
||||
*/
|
||||
static rt_size_t _pwm_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_device_pwm *pwm = (struct rt_device_pwm *)dev;
|
||||
rt_uint32_t *pulse = (rt_uint32_t *)buffer;
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
configuration.channel = pos;
|
||||
|
||||
if (pwm->ops->control)
|
||||
{
|
||||
result = pwm->ops->control(pwm, PWM_CMD_GET, &configuration);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
configuration.pulse = *pulse;
|
||||
|
||||
result = pwm->ops->control(pwm, PWM_CMD_SET, &configuration);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
|
||||
memset(device, 0, sizeof(struct rt_device_pwm));
|
||||
|
||||
device->parent.type = RT_Device_Class_Miscellaneous;
|
||||
|
||||
device->parent.init = RT_NULL;
|
||||
device->parent.open = RT_NULL;
|
||||
device->parent.close = RT_NULL;
|
||||
device->parent.read = _pwm_read;
|
||||
device->parent.write = _pwm_write;
|
||||
device->parent.control = _pwm_control;
|
||||
|
||||
device->ops = ops;
|
||||
device->parent.user_data = (void *)user_data;
|
||||
|
||||
result = rt_device_register(&device->parent, name, RT_DEVICE_FLAG_RDWR);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rt_pwm_enable(int channel)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_device *device = rt_device_find("pwm");
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
if (!device)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = channel;
|
||||
result = rt_device_control(device, PWM_CMD_ENABLE, &configuration);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rt_pwm_set(int channel, rt_uint32_t period, rt_uint32_t pulse)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_device *device = rt_device_find("pwm");
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
if (!device)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = channel;
|
||||
configuration.period = period;
|
||||
configuration.pulse = pulse;
|
||||
result = rt_device_control(device, PWM_CMD_SET, &configuration);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(rt_pwm_enable, pwm_enable, enable pwm by channel.);
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(rt_pwm_set, pwm_set, set pwm.);
|
||||
|
||||
#ifdef FINSH_USING_MSH
|
||||
static int pwm_enable(int argc, char **argv)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
rt_kprintf("Usage: pwm_enable 1\n");
|
||||
result = -RT_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
result = rt_pwm_enable(atoi(argv[1]));
|
||||
|
||||
_exit:
|
||||
return result;
|
||||
}
|
||||
MSH_CMD_EXPORT(pwm_enable, pwm_enable 1);
|
||||
|
||||
static int pwm_set(int argc, char **argv)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
rt_kprintf("Usage: pwm_set 1 100 50\n");
|
||||
result = -RT_ERROR;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
result = rt_pwm_set(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
|
||||
|
||||
_exit:
|
||||
return result;
|
||||
}
|
||||
MSH_CMD_EXPORT(pwm_set, pwm_set 1 100 50);
|
||||
|
||||
#endif /* FINSH_USING_MSH */
|
||||
|
||||
|
||||
#endif /* RT_USING_FINSH */
|
|
@ -183,7 +183,7 @@ void sfud_log_debug(const char *file, const long line, const char *format, ...)
|
|||
|
||||
/* args point to the first variable parameter */
|
||||
va_start(args, format);
|
||||
rt_kprintf("[SFUD](%s:%ld) ", file, line);
|
||||
rt_kprintf("[SFUD] (%s:%ld) ", file, line);
|
||||
/* must use vprintf to print */
|
||||
vsnprintf(log_buf, sizeof(log_buf), format, args);
|
||||
rt_kprintf("%s\n", log_buf);
|
||||
|
@ -201,7 +201,7 @@ void sfud_log_info(const char *format, ...) {
|
|||
|
||||
/* args point to the first variable parameter */
|
||||
va_start(args, format);
|
||||
rt_kprintf("[SFUD]");
|
||||
rt_kprintf("[SFUD] ");
|
||||
/* must use vprintf to print */
|
||||
vsnprintf(log_buf, sizeof(log_buf), format, args);
|
||||
rt_kprintf("%s\n", log_buf);
|
||||
|
@ -216,6 +216,9 @@ sfud_err sfud_spi_port_init(sfud_flash *flash) {
|
|||
flash->spi.lock = spi_lock;
|
||||
flash->spi.unlock = spi_unlock;
|
||||
flash->spi.user_data = flash;
|
||||
if (RT_TICK_PER_SECOND < 1000) {
|
||||
rt_kprintf("[SFUD] Warning: The OS tick(%d) is less than 1000. So the flash write will take more time.\n", RT_TICK_PER_SECOND);
|
||||
}
|
||||
/* 100 microsecond delay */
|
||||
flash->retry.delay = retry_delay_100us;
|
||||
/* 60 seconds timeout */
|
||||
|
@ -371,7 +374,7 @@ rt_err_t rt_sfud_flash_delete(rt_spi_flash_device_t spi_flash_dev) {
|
|||
|
||||
static void sf(uint8_t argc, char **argv) {
|
||||
|
||||
#define CMD_SETECT_INDEX 0
|
||||
#define CMD_PROBE_INDEX 0
|
||||
#define CMD_READ_INDEX 1
|
||||
#define CMD_WRITE_INDEX 2
|
||||
#define CMD_ERASE_INDEX 3
|
||||
|
@ -384,7 +387,7 @@ static void sf(uint8_t argc, char **argv) {
|
|||
size_t i = 0;
|
||||
|
||||
const char* sf_help_info[] = {
|
||||
[CMD_SETECT_INDEX] = "sf probe [spi_device] - probe and init SPI flash by given 'spi_device'",
|
||||
[CMD_PROBE_INDEX] = "sf probe [spi_device] - probe and init SPI flash by given 'spi_device'",
|
||||
[CMD_READ_INDEX] = "sf read addr size - read 'size' bytes starting at 'addr'",
|
||||
[CMD_WRITE_INDEX] = "sf write addr data1 ... dataN - write some bytes 'data' to flash starting at 'addr'",
|
||||
[CMD_ERASE_INDEX] = "sf erase addr size - erase 'size' bytes starting at 'addr'",
|
||||
|
@ -404,7 +407,7 @@ static void sf(uint8_t argc, char **argv) {
|
|||
|
||||
if (!strcmp(operator, "probe")) {
|
||||
if (argc < 3) {
|
||||
rt_kprintf("Usage: %s.\n", sf_help_info[CMD_SETECT_INDEX]);
|
||||
rt_kprintf("Usage: %s.\n", sf_help_info[CMD_PROBE_INDEX]);
|
||||
} else {
|
||||
char *spi_dev_name = argv[2];
|
||||
rtt_dev_bak = rtt_dev;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* File : wlan_cmd.c
|
||||
* Wi-Fi common commands
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2016, RT-Thread Development Team
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -40,6 +40,13 @@ static char wifi_ssid[32] = {0};
|
|||
static char wifi_key[32] = {0};
|
||||
static int network_mode = WIFI_STATION;
|
||||
|
||||
#define WLAN_DEBUG 1
|
||||
#if WLAN_DEBUG
|
||||
#define WLAN_DBG(...) rt_kprintf("[WLAN]"),rt_kprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define WLAN_DBG(...)
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_SETTING_FN
|
||||
#define WIFI_SETTING_FN "/appfs/setting.json"
|
||||
#endif
|
||||
|
@ -69,7 +76,7 @@ int wifi_set_mode(int mode)
|
|||
return network_mode;
|
||||
}
|
||||
|
||||
int wifi_set_setting(const char* ssid, const char* pwd)
|
||||
int wifi_set_setting(const char *ssid, const char *pwd)
|
||||
{
|
||||
if (!ssid) return -1;
|
||||
|
||||
|
@ -87,13 +94,13 @@ int wifi_set_setting(const char* ssid, const char* pwd)
|
|||
}
|
||||
|
||||
#ifdef PKG_USING_CJSON
|
||||
int wifi_read_cfg(const char* filename)
|
||||
int wifi_read_cfg(const char *filename)
|
||||
{
|
||||
int fd;
|
||||
cJSON *json = RT_NULL;
|
||||
|
||||
fd = open(filename,O_RDONLY, 0);
|
||||
if(fd < 0)
|
||||
fd = open(filename, O_RDONLY, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
/* no setting file */
|
||||
return -1;
|
||||
|
@ -106,7 +113,7 @@ int wifi_read_cfg(const char* filename)
|
|||
length = lseek(fd, 0, SEEK_END);
|
||||
if (length)
|
||||
{
|
||||
char *json_str = (char *) rt_malloc (length);
|
||||
char *json_str = (char *) rt_malloc(length);
|
||||
if (json_str)
|
||||
{
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
|
@ -149,7 +156,7 @@ int wifi_read_cfg(const char* filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wifi_save_cfg(const char* filename)
|
||||
int wifi_save_cfg(const char *filename)
|
||||
{
|
||||
int fd;
|
||||
cJSON *json = RT_NULL;
|
||||
|
@ -162,7 +169,7 @@ int wifi_save_cfg(const char* filename)
|
|||
length = lseek(fd, 0, SEEK_END);
|
||||
if (length)
|
||||
{
|
||||
char *json_str = (char *) rt_malloc (length);
|
||||
char *json_str = (char *) rt_malloc(length);
|
||||
if (json_str)
|
||||
{
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
|
@ -244,9 +251,9 @@ int wifi_save_cfg(const char* filename)
|
|||
|
||||
int wifi_save_setting(void)
|
||||
{
|
||||
#ifdef PKG_USING_CJSON
|
||||
#ifdef PKG_USING_CJSON
|
||||
wifi_save_cfg(WIFI_SETTING_FN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -265,7 +272,7 @@ int wifi_softap_setup_netif(struct netif *netif)
|
|||
{
|
||||
char name[8];
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, netif->name, sizeof(name)>sizeof(netif->name)? sizeof(netif->name) : sizeof(name));
|
||||
strncpy(name, netif->name, sizeof(name) > sizeof(netif->name) ? sizeof(netif->name) : sizeof(name));
|
||||
dhcpd_start(name);
|
||||
}
|
||||
#endif
|
||||
|
@ -279,15 +286,15 @@ int wifi_default(void)
|
|||
int result = 0;
|
||||
struct rt_wlan_device *wlan;
|
||||
|
||||
#ifdef PKG_USING_CJSON
|
||||
#ifdef PKG_USING_CJSON
|
||||
/* read default setting for wifi */
|
||||
wifi_read_cfg(WIFI_SETTING_FN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (network_mode == WIFI_STATION)
|
||||
{
|
||||
/* get wlan device */
|
||||
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_STA_NAME);
|
||||
wlan = (struct rt_wlan_device *)rt_device_find(WIFI_DEVICE_STA_NAME);
|
||||
if (!wlan)
|
||||
{
|
||||
rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_STA_NAME);
|
||||
|
@ -296,7 +303,7 @@ int wifi_default(void)
|
|||
|
||||
/* wifi station */
|
||||
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, wifi_ssid);
|
||||
result =rt_wlan_init(wlan, WIFI_STATION);
|
||||
result = rt_wlan_init(wlan, WIFI_STATION);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
result = rt_wlan_connect(wlan, &info, wifi_key);
|
||||
|
@ -306,7 +313,7 @@ int wifi_default(void)
|
|||
{
|
||||
/* wifi AP */
|
||||
/* get wlan device */
|
||||
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_AP_NAME);
|
||||
wlan = (struct rt_wlan_device *)rt_device_find(WIFI_DEVICE_AP_NAME);
|
||||
if (!wlan)
|
||||
{
|
||||
rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_AP_NAME);
|
||||
|
@ -317,7 +324,7 @@ int wifi_default(void)
|
|||
info.channel = 11;
|
||||
|
||||
/* wifi soft-AP */
|
||||
result =rt_wlan_init(wlan, WIFI_AP);
|
||||
result = rt_wlan_init(wlan, WIFI_AP);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
result = rt_wlan_softap(wlan, &info, wifi_key);
|
||||
|
@ -334,14 +341,14 @@ static void wifi_usage(void)
|
|||
rt_kprintf("wifi - Do the default wifi action\n");
|
||||
rt_kprintf("wifi wlan_dev scan\n");
|
||||
rt_kprintf("wifi wlan_dev join SSID PASSWORD\n");
|
||||
rt_kprintf("wifi wlan_dev ap SSID [PASSWORD]\n");
|
||||
rt_kprintf("wifi wlan_dev ap SSID [PASSWORD]\n");
|
||||
rt_kprintf("wifi wlan_dev up\n");
|
||||
rt_kprintf("wifi wlan_dev down\n");
|
||||
rt_kprintf("wifi wlan_dev rssi\n");
|
||||
rt_kprintf("wifi wlan_dev status\n");
|
||||
}
|
||||
|
||||
int wifi(int argc, char** argv)
|
||||
int wifi(int argc, char **argv)
|
||||
{
|
||||
struct rt_wlan_device *wlan;
|
||||
|
||||
|
@ -368,15 +375,15 @@ int wifi(int argc, char** argv)
|
|||
|
||||
network_mode = WIFI_STATION;
|
||||
|
||||
#ifdef PKG_USING_CJSON
|
||||
#ifdef PKG_USING_CJSON
|
||||
wifi_save_cfg(WIFI_SETTING_FN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get wlan device */
|
||||
wlan = (struct rt_wlan_device*)rt_device_find(argv[1]);
|
||||
wlan = (struct rt_wlan_device *)rt_device_find(argv[1]);
|
||||
if (!wlan)
|
||||
{
|
||||
rt_kprintf("no wlan:%s device\n", argv[1]);
|
||||
|
@ -397,6 +404,7 @@ int wifi(int argc, char** argv)
|
|||
/* TODO: use easy-join to replace */
|
||||
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, argv[3]);
|
||||
rt_wlan_connect(wlan, &info, argv[4]);
|
||||
rt_wlan_info_deinit(&info);
|
||||
}
|
||||
else if (strcmp(argv[2], "up") == 0)
|
||||
{
|
||||
|
@ -406,36 +414,28 @@ int wifi(int argc, char** argv)
|
|||
else if (strcmp(argv[2], "down") == 0)
|
||||
{
|
||||
rt_wlan_disconnect(wlan);
|
||||
rt_wlan_info_deinit(&info);
|
||||
}
|
||||
else if (strcmp(argv[2], "scan") == 0)
|
||||
{
|
||||
struct rt_wlan_info *infos;
|
||||
struct rt_wlan_scan_result *scan_result = RT_NULL;
|
||||
|
||||
infos = (struct rt_wlan_info*)rt_malloc(sizeof(struct rt_wlan_info) * 12);
|
||||
if (infos)
|
||||
rt_wlan_scan(wlan, &scan_result);
|
||||
if (scan_result)
|
||||
{
|
||||
int index, num;
|
||||
|
||||
memset(infos, 0x0, sizeof(struct rt_wlan_info) * 12);
|
||||
num = rt_wlan_scan(wlan, infos, 12);
|
||||
|
||||
num = scan_result->ap_num;
|
||||
rt_kprintf("----Wi-Fi APInformation----\n");
|
||||
for (index = 0; index < num; index ++)
|
||||
{
|
||||
rt_kprintf("----Wi-Fi AP[%d] Information----\n", index);
|
||||
rt_kprintf("SSID: %-.32s\n", infos[index].ssid);
|
||||
rt_kprintf("rssi: %d\n", infos[index].rssi);
|
||||
rt_kprintf(" chn: %d\n", infos[index].channel);
|
||||
rt_kprintf("rate: %d\n", infos[index].datarate);
|
||||
rt_kprintf("\n");
|
||||
rt_kprintf("SSID:%-.32s, ", scan_result->ap_table[index].ssid);
|
||||
rt_kprintf("rssi:%d, ", scan_result->ap_table[index].rssi);
|
||||
rt_kprintf("chn:%d, ", scan_result->ap_table[index].channel);
|
||||
rt_kprintf("rate:%d\n", scan_result->ap_table[index].datarate);
|
||||
}
|
||||
|
||||
/* de-initialize info */
|
||||
for (index = 0; index < num; index ++)
|
||||
{
|
||||
rt_wlan_info_deinit(&infos[index]);
|
||||
}
|
||||
rt_free(infos);
|
||||
}
|
||||
rt_wlan_release_scan_result(&scan_result);
|
||||
}
|
||||
else if (strcmp(argv[2], "rssi") == 0)
|
||||
{
|
||||
|
@ -454,7 +454,7 @@ int wifi(int argc, char** argv)
|
|||
rt_wlan_info_init(&info, WIFI_AP, SECURITY_OPEN, argv[3]);
|
||||
info.channel = 11;
|
||||
|
||||
result =rt_wlan_init(wlan, WIFI_AP);
|
||||
result = rt_wlan_init(wlan, WIFI_AP);
|
||||
/* start soft ap */
|
||||
result = rt_wlan_softap(wlan, &info, NULL);
|
||||
if (result == RT_EOK)
|
||||
|
@ -468,19 +468,19 @@ int wifi(int argc, char** argv)
|
|||
rt_wlan_info_init(&info, WIFI_AP, SECURITY_WPA2_AES_PSK, argv[3]);
|
||||
info.channel = 11;
|
||||
|
||||
result =rt_wlan_init(wlan, WIFI_AP);
|
||||
result = rt_wlan_init(wlan, WIFI_AP);
|
||||
/* start soft ap */
|
||||
result = rt_wlan_softap(wlan, &info, argv[4]);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
network_mode = WIFI_AP;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wifi_usage();
|
||||
}
|
||||
|
||||
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
rt_kprintf("wifi start failed! result=%d\n", result);
|
||||
|
@ -496,13 +496,13 @@ int wifi(int argc, char** argv)
|
|||
|
||||
rt_kprintf("Wi-Fi AP: %-.32s\n", wlan->info->ssid);
|
||||
rt_kprintf("MAC Addr: %02x:%02x:%02x:%02x:%02x:%02x\n", wlan->info->bssid[0],
|
||||
wlan->info->bssid[1],
|
||||
wlan->info->bssid[2],
|
||||
wlan->info->bssid[3],
|
||||
wlan->info->bssid[4],
|
||||
wlan->info->bssid[5]);
|
||||
wlan->info->bssid[1],
|
||||
wlan->info->bssid[2],
|
||||
wlan->info->bssid[3],
|
||||
wlan->info->bssid[4],
|
||||
wlan->info->bssid[5]);
|
||||
rt_kprintf(" Channel: %d\n", wlan->info->channel);
|
||||
rt_kprintf("DataRate: %dMbps\n", wlan->info->datarate/1000);
|
||||
rt_kprintf("DataRate: %dMbps\n", wlan->info->datarate / 1000);
|
||||
rt_kprintf(" RSSI: %d\n", rssi);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,3 +1,28 @@
|
|||
/*
|
||||
* File : wlan_cmd.h
|
||||
* Wi-Fi common commands
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-06-05 RT-Thread first version
|
||||
*/
|
||||
|
||||
#ifndef WLAN_CMD_H__
|
||||
#define WLAN_CMD_H__
|
||||
|
||||
|
@ -11,11 +36,11 @@ int wifi_default(void);
|
|||
/* setup netif for soft-ap */
|
||||
int wifi_softap_setup_netif(struct netif *netif);
|
||||
|
||||
int wifi_set_setting(const char* ssid, const char* pwd);
|
||||
int wifi_set_setting(const char *ssid, const char *pwd);
|
||||
|
||||
#ifdef PKG_USING_CJSON
|
||||
int wifi_read_cfg(const char* filename);
|
||||
int wifi_save_cfg(const char* filename);
|
||||
int wifi_read_cfg(const char *filename);
|
||||
int wifi_save_cfg(const char *filename);
|
||||
#endif
|
||||
/* save wifi setting with default storage file */
|
||||
int wifi_save_setting(void);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* RT-Thread Wi-Fi Device
|
||||
*
|
||||
* COPYRIGHT (C) 2014 - 2015, Shanghai Real-Thread Technology Co., Ltd
|
||||
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||
*
|
||||
|
@ -29,15 +29,13 @@
|
|||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include <lwip/netifapi.h>
|
||||
|
||||
#include "wlan_dev.h"
|
||||
#include "wlan_cmd.h"
|
||||
|
||||
#define NIOCTL_SADDR 0x02
|
||||
|
||||
void rt_wlan_info_init(struct rt_wlan_info* info, rt_wlan_mode_t mode, rt_wlan_security_t security,
|
||||
char *ssid)
|
||||
void rt_wlan_info_init(struct rt_wlan_info *info, rt_wlan_mode_t mode, rt_wlan_security_t security,
|
||||
char *ssid)
|
||||
{
|
||||
if (info == RT_NULL) return ;
|
||||
|
||||
|
@ -46,15 +44,15 @@ void rt_wlan_info_init(struct rt_wlan_info* info, rt_wlan_mode_t mode, rt_wlan_s
|
|||
info->security = security;
|
||||
if (ssid)
|
||||
{
|
||||
info->ssid = rt_malloc(strlen((char*)ssid) + 1);
|
||||
info->ssid = rt_malloc(strlen((char *)ssid) + 1);
|
||||
if (info->ssid)
|
||||
{
|
||||
strncpy((char*)info->ssid, (char*)ssid, strlen((char*)ssid) + 1);
|
||||
strncpy((char *)info->ssid, (char *)ssid, strlen((char *)ssid) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rt_wlan_info_deinit(struct rt_wlan_info* info)
|
||||
void rt_wlan_info_deinit(struct rt_wlan_info *info)
|
||||
{
|
||||
if (info->ssid)
|
||||
{
|
||||
|
@ -65,18 +63,32 @@ void rt_wlan_info_deinit(struct rt_wlan_info* info)
|
|||
memset(info, 0x0, sizeof(struct rt_wlan_info));
|
||||
}
|
||||
|
||||
int rt_wlan_init(struct rt_wlan_device* device, rt_wlan_mode_t mode)
|
||||
int rt_wlan_init(struct rt_wlan_device *device, rt_wlan_mode_t mode)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (device == RT_NULL) return 0;
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_INIT, (void*)&mode);
|
||||
if (device->info == RT_NULL)
|
||||
{
|
||||
struct rt_wlan_info *info;
|
||||
char *ssid;
|
||||
|
||||
info = rt_malloc(sizeof(struct rt_wlan_info));
|
||||
if (info)
|
||||
{
|
||||
ssid = rt_malloc(SSID_LENGTH_MAX_SIZE);
|
||||
info->ssid = ssid;
|
||||
}
|
||||
device->info = info;
|
||||
}
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_INIT, (void *)&mode);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_connect(struct rt_wlan_device* device, struct rt_wlan_info* info, char *password)
|
||||
int rt_wlan_connect(struct rt_wlan_device *device, struct rt_wlan_info *info, char *password)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
|
@ -87,28 +99,14 @@ int rt_wlan_connect(struct rt_wlan_device* device, struct rt_wlan_info* info, ch
|
|||
rt_wlan_set_info(device, info);
|
||||
}
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_EASYJOIN, (void*)password);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
struct netif *netif = device->parent.netif;
|
||||
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
||||
|
||||
netifapi_netif_set_up(netif);
|
||||
eth_device_linkchange(&(device->parent), RT_TRUE);
|
||||
|
||||
#ifdef RT_LWIP_DHCP
|
||||
/* set DHCP flags */
|
||||
// netif->flags |= NETIF_FLAG_DHCP;
|
||||
/* start DHCP */
|
||||
dhcp_start(netif);
|
||||
#endif
|
||||
|
||||
rt_strncpy((char*)device->key, (char*)password, sizeof(device->key) - 1);
|
||||
}
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_EASYJOIN, (void *)password);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_softap(struct rt_wlan_device* device, struct rt_wlan_info* info, char *password)
|
||||
int rt_wlan_softap(struct rt_wlan_device *device, struct rt_wlan_info *info, char *password)
|
||||
{
|
||||
int result = RT_EOK;
|
||||
|
||||
|
@ -119,21 +117,14 @@ int rt_wlan_softap(struct rt_wlan_device* device, struct rt_wlan_info* info, cha
|
|||
rt_wlan_set_info(device, info);
|
||||
}
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SOFTAP, (void*)password);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
rt_strncpy((char*)device->key, (char*)password, sizeof(device->key) - 1);
|
||||
rt_strncpy((char *)device->key, (char *)password, sizeof(device->key) - 1);
|
||||
|
||||
netifapi_netif_set_up(device->parent.netif);
|
||||
eth_device_linkchange(&(device->parent), RT_TRUE);
|
||||
|
||||
wifi_softap_setup_netif(device->parent.netif);
|
||||
}
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SOFTAP, (void *)password);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_disconnect(struct rt_wlan_device* device)
|
||||
int rt_wlan_disconnect(struct rt_wlan_device *device)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
|
@ -141,33 +132,30 @@ int rt_wlan_disconnect(struct rt_wlan_device* device)
|
|||
|
||||
/* save event handler */
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_DISCONNECT, RT_NULL);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
netifapi_netif_set_down(device->parent.netif);
|
||||
eth_device_linkchange(&(device->parent), RT_FALSE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_set_info(struct rt_wlan_device* device, struct rt_wlan_info* info)
|
||||
int rt_wlan_set_info(struct rt_wlan_device *device, struct rt_wlan_info *info)
|
||||
{
|
||||
if (device->info == info) return RT_EOK; /* same info */
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
if (device->info == RT_NULL) return -RT_EIO;
|
||||
|
||||
if (device->info != RT_NULL)
|
||||
{
|
||||
rt_wlan_info_deinit(device->info);
|
||||
rt_free(device->info);
|
||||
}
|
||||
|
||||
device->info = info;
|
||||
device->info->mode = info->mode;
|
||||
device->info->security = info->security;
|
||||
memset(device->info->ssid, 0, SSID_LENGTH_MAX_SIZE);
|
||||
memcpy(device->info->ssid, info->ssid, strlen(info->ssid));
|
||||
memcpy(device->info->bssid, info->bssid, 6);
|
||||
device->info->datarate = info->datarate;
|
||||
device->info->channel = info->channel;
|
||||
device->info->rssi = info->rssi;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device* device)
|
||||
struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device *device)
|
||||
{
|
||||
struct rt_wlan_info* info = RT_NULL;
|
||||
struct rt_wlan_info *info = RT_NULL;
|
||||
|
||||
if (device != RT_NULL)
|
||||
{
|
||||
|
@ -177,70 +165,153 @@ struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device* device)
|
|||
return info;
|
||||
}
|
||||
|
||||
int rt_wlan_scan(struct rt_wlan_device* device, struct rt_wlan_info *infos, int item_sz)
|
||||
int rt_wlan_scan(struct rt_wlan_device *device, struct rt_wlan_scan_result **scan_result)
|
||||
{
|
||||
int result;
|
||||
struct rt_wlan_info_request request;
|
||||
|
||||
if (device == RT_NULL) return 0;
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SCAN, scan_result);
|
||||
|
||||
request.req_number = item_sz;
|
||||
request.rsp_number = 0;
|
||||
request.infos = infos;
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SCAN, (void*)&request);
|
||||
result = result; /* skip warning */
|
||||
|
||||
return request.rsp_number;
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_get_rssi(struct rt_wlan_device* device)
|
||||
int rt_wlan_get_rssi(struct rt_wlan_device *device)
|
||||
{
|
||||
int rssi;
|
||||
int result;
|
||||
|
||||
if (device == RT_NULL) return 0;
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_GET_RSSI, (void*)&rssi);
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_GET_RSSI, (void *)&rssi);
|
||||
|
||||
if (result == RT_EOK) return rssi;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_get_mac(struct rt_wlan_device* device, rt_uint8_t hwaddr[6])
|
||||
int rt_wlan_get_mac(struct rt_wlan_device *device, rt_uint8_t hwaddr[6])
|
||||
{
|
||||
int result;
|
||||
if (device == RT_NULL) return 0;
|
||||
result = rt_device_control(RT_DEVICE(device), NIOCTL_GADDR, (void*)hwaddr);
|
||||
result = rt_device_control(RT_DEVICE(device), NIOCTL_GADDR, (void *)hwaddr);
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_set_mac(struct rt_wlan_device* device, rt_uint8_t hwaddr[6])
|
||||
int rt_wlan_set_mac(struct rt_wlan_device *device, rt_uint8_t hwaddr[6])
|
||||
{
|
||||
int result;
|
||||
if (device == RT_NULL) return 0;
|
||||
result = rt_device_control(RT_DEVICE(device), NIOCTL_SADDR, (void*)hwaddr);
|
||||
result = rt_device_control(RT_DEVICE(device), NIOCTL_SADDR, (void *)hwaddr);
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_enter_powersave(struct rt_wlan_device* device, int level)
|
||||
int rt_wlan_enter_powersave(struct rt_wlan_device *device, int level)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_ENTER_POWERSAVE, (void*)&level);
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_ENTER_POWERSAVE, (void *)&level);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void rt_wlan_set_event_callback(struct rt_wlan_device* device, rt_wlan_event_handler handler,
|
||||
void *user_data)
|
||||
int rt_wlan_register_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event,
|
||||
rt_wlan_event_handler handler)
|
||||
{
|
||||
if (device == RT_NULL) return ;
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
if (event >= WIFI_EVT_MAX) return -RT_EINVAL;
|
||||
|
||||
device->handler = handler;
|
||||
device->user_data = user_data;
|
||||
device->handler[event] = handler;
|
||||
|
||||
return ;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
int rt_wlan_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event)
|
||||
{
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
if (event >= WIFI_EVT_MAX) return -RT_EINVAL;
|
||||
|
||||
device->handler[event] = RT_NULL;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
int rt_wlan_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
if (event >= WIFI_EVT_MAX) return -RT_EINVAL;
|
||||
|
||||
if (device->handler[event] != RT_NULL)
|
||||
device->handler[event](device, event, user_data);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
int rt_wlan_cfg_monitor(struct rt_wlan_device *device, rt_wlan_monitor_opition_t opition)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_CFG_MONITOR, (void *)&opition);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_set_monitor_callback(struct rt_wlan_device *device, rt_wlan_monitor_callback_t callback)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SET_MONITOR_CALLBACK, (void *)callback);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_set_channel(struct rt_wlan_device *device, int channel)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
|
||||
result = rt_device_control(RT_DEVICE(device), WIFI_SET_CHANNEL, (void *)&channel);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int rt_wlan_get_channel(struct rt_wlan_device *device)
|
||||
{
|
||||
int channel = 0;
|
||||
|
||||
if (device == RT_NULL) return -RT_EIO;
|
||||
|
||||
rt_device_control(RT_DEVICE(device), WIFI_GET_CHANNEL, &channel);
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
void rt_wlan_release_scan_result(struct rt_wlan_scan_result **scan_result)
|
||||
{
|
||||
int i, ap_num;
|
||||
struct rt_wlan_scan_result *_scan_result;
|
||||
|
||||
if (*scan_result != RT_NULL)
|
||||
{
|
||||
_scan_result = *scan_result;
|
||||
ap_num = _scan_result->ap_num;
|
||||
for (i = 0; i < ap_num; i++)
|
||||
{
|
||||
if (_scan_result->ap_table[i].ssid != RT_NULL)
|
||||
{
|
||||
rt_free(_scan_result->ap_table[i].ssid);
|
||||
_scan_result->ap_table[i].ssid = RT_NULL;
|
||||
}
|
||||
}
|
||||
_scan_result->ap_num = 0;
|
||||
rt_free(_scan_result->ap_table);
|
||||
_scan_result->ap_table = RT_NULL;
|
||||
}
|
||||
rt_free(*scan_result);
|
||||
*scan_result = RT_NULL;
|
||||
scan_result = RT_NULL;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* RT-Thread Wi-Fi Device
|
||||
*
|
||||
* COPYRIGHT (C) 2014 - 2015, Shanghai Real-Thread Technology Co., Ltd
|
||||
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||
*
|
||||
|
@ -25,6 +25,7 @@
|
|||
* Date Author Notes
|
||||
* 2014-09-11 Bernard the first verion
|
||||
*/
|
||||
|
||||
#ifndef WIFI_DEVICE_H__
|
||||
#define WIFI_DEVICE_H__
|
||||
|
||||
|
@ -33,6 +34,7 @@
|
|||
|
||||
typedef enum
|
||||
{
|
||||
WIFI_NONE,
|
||||
WIFI_STATION,
|
||||
WIFI_AP,
|
||||
} rt_wlan_mode_t;
|
||||
|
@ -47,6 +49,10 @@ typedef enum
|
|||
WIFI_DISCONNECT,
|
||||
WIFI_GET_RSSI, /* get sensitivity (dBm) */
|
||||
WIFI_ENTER_POWERSAVE,
|
||||
WIFI_CFG_MONITOR, /* start/stop minitor */
|
||||
WIFI_SET_CHANNEL,
|
||||
WIFI_GET_CHANNEL,
|
||||
WIFI_SET_MONITOR_CALLBACK,
|
||||
} rt_wlan_cmd_t;
|
||||
|
||||
typedef enum
|
||||
|
@ -56,6 +62,12 @@ typedef enum
|
|||
WIFI_PWR_NORMAL
|
||||
} rt_wlan_powersave_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WIFI_MONITOR_START,
|
||||
WIFI_MONITOR_STOP
|
||||
} rt_wlan_monitor_opition_t;
|
||||
|
||||
#define SHARED_ENABLED 0x00008000
|
||||
#define WPA_SECURITY 0x00200000
|
||||
#define WPA2_SECURITY 0x00400000
|
||||
|
@ -66,7 +78,7 @@ typedef enum
|
|||
#define WSEC_SWFLAG 0x0008
|
||||
|
||||
#define KEY_ARRAY_SIZE 32
|
||||
|
||||
#define SSID_LENGTH_MAX_SIZE 32 + 1
|
||||
/**
|
||||
* Enumeration of Wi-Fi security modes
|
||||
*/
|
||||
|
@ -74,23 +86,32 @@ typedef enum
|
|||
{
|
||||
SECURITY_OPEN = 0, /**< Open security */
|
||||
SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
|
||||
SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
|
||||
SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
|
||||
SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
|
||||
SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
|
||||
SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
|
||||
SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
|
||||
SECURITY_WEP_SHARED = (WEP_ENABLED | SHARED_ENABLED), /**< WEP Security with shared authentication */
|
||||
SECURITY_WPA_TKIP_PSK = (WPA_SECURITY | TKIP_ENABLED), /**< WPA Security with TKIP */
|
||||
SECURITY_WPA_AES_PSK = (WPA_SECURITY | AES_ENABLED), /**< WPA Security with AES */
|
||||
SECURITY_WPA2_AES_PSK = (WPA2_SECURITY | AES_ENABLED), /**< WPA2 Security with AES */
|
||||
SECURITY_WPA2_TKIP_PSK = (WPA2_SECURITY | TKIP_ENABLED), /**< WPA2 Security with TKIP */
|
||||
SECURITY_WPA2_MIXED_PSK = (WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED), /**< WPA2 Security with AES & TKIP */
|
||||
SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
|
||||
SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
|
||||
SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown.
|
||||
SECURITY_UNKNOWN = -1, /**< May be returned by scan function if security is unknown.
|
||||
Do not pass this to the join function! */
|
||||
} rt_wlan_security_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WIFI_EVT_INIT_DONE = 0,
|
||||
WIFI_EVT_LINK_DOWN,
|
||||
WIFI_EVT_LINK_UP,
|
||||
}rt_wlan_event_t;
|
||||
WIFI_EVT_CONNECT,
|
||||
WIFI_EVT_DISCONNECT,
|
||||
WIFI_EVT_AP_START,
|
||||
WIFI_EVT_AP_STOP,
|
||||
WIFI_EVENT_STA_ASSOC,
|
||||
WIFI_EVENT_STA_DISASSOC,
|
||||
WIFI_EVT_SCAN_DONE,
|
||||
WIFI_EVT_MAX,
|
||||
} rt_wlan_event_t;
|
||||
|
||||
/* wifi network information */
|
||||
struct rt_wlan_info
|
||||
|
@ -117,59 +138,83 @@ struct rt_wlan_info_request
|
|||
struct rt_wlan_info *infos;/* the array of information to save response */
|
||||
};
|
||||
|
||||
struct rt_wlan_device;
|
||||
typedef void (*rt_wlan_event_handler)(struct rt_wlan_device* device, rt_wlan_event_t event, void* user_data);
|
||||
typedef struct rt_wlan_scan_result
|
||||
{
|
||||
char ap_num;
|
||||
struct rt_wlan_info *ap_table;
|
||||
} rt_wlan_scan_result_t;
|
||||
|
||||
struct rt_wlan_device;
|
||||
typedef void (*rt_wlan_event_handler)(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data);
|
||||
typedef void (*rt_wlan_monitor_callback_t)(uint8_t *data, int len, void *user_data);
|
||||
struct rt_wlan_device
|
||||
{
|
||||
struct eth_device parent;
|
||||
|
||||
struct rt_wlan_info* info;
|
||||
struct rt_wlan_info *info;
|
||||
char key[KEY_ARRAY_SIZE + 1];
|
||||
|
||||
rt_wlan_event_handler handler;
|
||||
void* user_data;
|
||||
rt_wlan_event_handler handler[WIFI_EVT_MAX];
|
||||
void *user_data;
|
||||
int interface;
|
||||
};
|
||||
|
||||
/*
|
||||
* Wi-Fi Information APIs
|
||||
*/
|
||||
void rt_wlan_info_init(struct rt_wlan_info* info, rt_wlan_mode_t mode, rt_wlan_security_t security,
|
||||
char *ssid);
|
||||
void rt_wlan_info_deinit(struct rt_wlan_info* info);
|
||||
void rt_wlan_info_init(struct rt_wlan_info *info, rt_wlan_mode_t mode, rt_wlan_security_t security,
|
||||
char *ssid);
|
||||
void rt_wlan_info_deinit(struct rt_wlan_info *info);
|
||||
|
||||
/*
|
||||
* Wi-Fi Manager APIs
|
||||
*/
|
||||
int rt_wlan_init(struct rt_wlan_device* device, rt_wlan_mode_t mode);
|
||||
int rt_wlan_init(struct rt_wlan_device *device, rt_wlan_mode_t mode);
|
||||
|
||||
int rt_wlan_connect(struct rt_wlan_device* device, struct rt_wlan_info* info,
|
||||
char *password);
|
||||
int rt_wlan_disconnect(struct rt_wlan_device* device);
|
||||
int rt_wlan_connect(struct rt_wlan_device *device, struct rt_wlan_info *info,
|
||||
char *password);
|
||||
int rt_wlan_disconnect(struct rt_wlan_device *device);
|
||||
|
||||
int rt_wlan_softap(struct rt_wlan_device* device, struct rt_wlan_info* info,
|
||||
char *password);
|
||||
int rt_wlan_softap(struct rt_wlan_device *device, struct rt_wlan_info *info,
|
||||
char *password);
|
||||
|
||||
/* set wifi information for AP */
|
||||
int rt_wlan_set_info(struct rt_wlan_device* device, struct rt_wlan_info* info);
|
||||
int rt_wlan_set_info(struct rt_wlan_device *device, struct rt_wlan_info *info);
|
||||
/* get wifi information for AP */
|
||||
struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device* device);
|
||||
struct rt_wlan_info *rt_wlan_get_info(struct rt_wlan_device *device);
|
||||
|
||||
/* get the AP result which were scaned in station */
|
||||
int rt_wlan_scan(struct rt_wlan_device* device, struct rt_wlan_info *infos, int item_sz);
|
||||
int rt_wlan_scan(struct rt_wlan_device *device, struct rt_wlan_scan_result **scan_result);
|
||||
|
||||
/* get rssi */
|
||||
int rt_wlan_get_rssi(struct rt_wlan_device* device);
|
||||
int rt_wlan_get_rssi(struct rt_wlan_device *device);
|
||||
/* Get/Set MAC */
|
||||
int rt_wlan_get_mac(struct rt_wlan_device* device,rt_uint8_t hwaddr[6]);
|
||||
int rt_wlan_set_mac(struct rt_wlan_device* device,rt_uint8_t hwaddr[6]);
|
||||
int rt_wlan_get_mac(struct rt_wlan_device *device, rt_uint8_t hwaddr[6]);
|
||||
int rt_wlan_set_mac(struct rt_wlan_device *device, rt_uint8_t hwaddr[6]);
|
||||
|
||||
/* enter power save level */
|
||||
int rt_wlan_enter_powersave(struct rt_wlan_device* device, int level);
|
||||
int rt_wlan_enter_powersave(struct rt_wlan_device *device, int level);
|
||||
|
||||
void rt_wlan_set_event_callback(struct rt_wlan_device* device, rt_wlan_event_handler handler,
|
||||
void *user_data);
|
||||
/* register the event handler */
|
||||
int rt_wlan_register_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event,
|
||||
rt_wlan_event_handler handler);
|
||||
|
||||
/* un-register the event handler */
|
||||
int rt_wlan_unregister_event_handler(struct rt_wlan_device *device, rt_wlan_event_t event);
|
||||
|
||||
/* wlan driver indicate event to upper layer through wifi_indication. */
|
||||
int rt_wlan_indicate_event_handle(struct rt_wlan_device *device, rt_wlan_event_t event,
|
||||
void *user_data);
|
||||
|
||||
/* start or stop monitor */
|
||||
int rt_wlan_cfg_monitor(struct rt_wlan_device *device, rt_wlan_monitor_opition_t opition);
|
||||
|
||||
/* set callback function for monitor mode*/
|
||||
int rt_wlan_set_monitor_callback(struct rt_wlan_device *device, rt_wlan_monitor_callback_t callback);
|
||||
|
||||
/* Set the monitor channel */
|
||||
int rt_wlan_set_channel(struct rt_wlan_device *device, int channel);
|
||||
|
||||
void rt_wlan_release_scan_result(struct rt_wlan_scan_result **scan_result);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* RT-Thread Wi-Fi Device
|
||||
*
|
||||
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-02-27 EvalZero the first verion
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include <lwip/netifapi.h>
|
||||
|
||||
#include "wlan_dev.h"
|
||||
#include "wlan_cmd.h"
|
||||
|
||||
#define WLAN_MGNT_DEBUG 1
|
||||
|
||||
#if WLAN_MGNT_DEBUG
|
||||
#define WLAN_MGNT_DBG(...) rt_kprintf("[WLAN_MGNT]"),rt_kprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define WLAN_MGNT_DBG(...)
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_DEVICE_STA_NAME
|
||||
#define WIFI_DEVICE_STA_NAME "w0"
|
||||
#endif
|
||||
#ifndef WIFI_DEVICE_AP_NAME
|
||||
#define WIFI_DEVICE_AP_NAME "ap"
|
||||
#endif
|
||||
|
||||
static void wlan_mgnt_init_done_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan init done event callback \n");
|
||||
}
|
||||
|
||||
static void wlan_mgnt_link_up_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan link up event callback \n");
|
||||
}
|
||||
|
||||
static void wlan_mgnt_link_down_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan link down event callback \n");
|
||||
}
|
||||
|
||||
static void wlan_mgnt_sta_connect_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan sta connect event callback \n");
|
||||
struct netif *netif = device->parent.netif;
|
||||
|
||||
netifapi_netif_set_up(netif);
|
||||
netifapi_netif_set_link_up(netif);
|
||||
#ifdef RT_LWIP_DHCP
|
||||
/* start DHCP */
|
||||
dhcp_start(netif);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void wlan_mgnt_sta_disconnect_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan sta disconnect event callback \n");
|
||||
netifapi_netif_set_down(device->parent.netif);
|
||||
netifapi_netif_set_link_down(device->parent.netif);
|
||||
rt_memset(&device->parent.netif->ip_addr, 0, sizeof(ip_addr_t));
|
||||
rt_memset(&device->parent.netif->netmask, 0, sizeof(ip_addr_t));
|
||||
rt_memset(&device->parent.netif->gw, 0, sizeof(ip_addr_t));
|
||||
#ifdef RT_LWIP_DHCP
|
||||
dhcp_stop(device->parent.netif);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void wlan_mgnt_ap_start_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan ap start event callback \n");
|
||||
netifapi_netif_set_up(device->parent.netif);
|
||||
netifapi_netif_set_link_up(device->parent.netif);
|
||||
|
||||
wifi_softap_setup_netif(device->parent.netif);
|
||||
}
|
||||
|
||||
|
||||
static void wlan_mgnt_ap_stop_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan ap stop event callback \n");
|
||||
|
||||
netifapi_netif_set_down(device->parent.netif);
|
||||
netifapi_netif_set_link_down(device->parent.netif);
|
||||
}
|
||||
|
||||
static void wlan_mgnt_ap_associate_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan ap associate event callback \n");
|
||||
}
|
||||
|
||||
static void wlan_mgnt_ap_disassociate_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan ap disassociate event callback \n");
|
||||
}
|
||||
|
||||
static void wlan_mgnt_scan_done_event(struct rt_wlan_device *device, rt_wlan_event_t event, void *user_data)
|
||||
{
|
||||
WLAN_MGNT_DBG("wlan scan done event callback \n");
|
||||
}
|
||||
|
||||
int rt_wlan_mgnt_attach(struct rt_wlan_device *device, void *user_data)
|
||||
{
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_INIT_DONE, wlan_mgnt_init_done_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_LINK_DOWN, wlan_mgnt_link_up_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_LINK_UP, wlan_mgnt_link_down_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_CONNECT, wlan_mgnt_sta_connect_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_DISCONNECT, wlan_mgnt_sta_disconnect_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_AP_START, wlan_mgnt_ap_start_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_AP_STOP, wlan_mgnt_ap_stop_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVENT_STA_ASSOC, wlan_mgnt_ap_associate_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVENT_STA_DISASSOC, wlan_mgnt_ap_disassociate_event);
|
||||
rt_wlan_register_event_handler(device, WIFI_EVT_SCAN_DONE, wlan_mgnt_scan_done_event);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
|
@ -1,7 +1,11 @@
|
|||
/*
|
||||
* File : rt_low_level_gcc.inc
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
||||
* RT-Thread Wi-Fi Device
|
||||
*
|
||||
* COPYRIGHT (C) 2014 - 2018, Shanghai Real-Thread Technology Co., Ltd
|
||||
*
|
||||
* This file is part of RT-Thread (http://www.rt-thread.org)
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -19,13 +23,12 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2015-04-14 ArdaFu first version
|
||||
* 2018-02-27 EvalZero the first verion
|
||||
*/
|
||||
|
||||
/*--------- Stack size of CPU modes ------------------------------------------*/
|
||||
.equ UND_STK_SIZE, 2048
|
||||
.equ SVC_STK_SIZE, 4096
|
||||
.equ ABT_STK_SIZE, 2048
|
||||
.equ IRQ_STK_SIZE, 4096
|
||||
.equ FIQ_STK_SIZE, 4096
|
||||
.equ SYS_STK_SIZE, 2048
|
||||
#ifndef __WLAN_MGNT_H__
|
||||
#define __WLAN_MGNT_H__
|
||||
|
||||
int rt_wlan_mgnt_attach(struct rt_wlan_device *device, void *user_data);
|
||||
|
||||
#endif
|
|
@ -70,6 +70,10 @@ config FINSH_USING_MSH_DEFAULT
|
|||
config FINSH_USING_MSH_ONLY
|
||||
bool "Only using module shell"
|
||||
default n
|
||||
|
||||
config FINSH_ARG_MAX
|
||||
int "The command arg num for shell"
|
||||
default 10
|
||||
endif
|
||||
|
||||
endif
|
||||
|
|
|
@ -37,7 +37,10 @@
|
|||
#include <dfs_posix.h>
|
||||
#endif
|
||||
|
||||
#define RT_FINSH_ARG_MAX 10
|
||||
#ifndef FINSH_ARG_MAX
|
||||
#define FINSH_ARG_MAX 10
|
||||
#endif
|
||||
|
||||
typedef int (*cmd_function_t)(int argc, char **argv);
|
||||
|
||||
#ifdef FINSH_USING_MSH
|
||||
|
@ -99,7 +102,7 @@ int msh_help(int argc, char **argv)
|
|||
}
|
||||
FINSH_FUNCTION_EXPORT_ALIAS(msh_help, __cmd_help, RT-Thread shell help.);
|
||||
|
||||
static int msh_split(char *cmd, rt_size_t length, char *argv[RT_FINSH_ARG_MAX])
|
||||
static int msh_split(char *cmd, rt_size_t length, char *argv[FINSH_ARG_MAX])
|
||||
{
|
||||
char *ptr;
|
||||
rt_size_t position;
|
||||
|
@ -118,7 +121,7 @@ static int msh_split(char *cmd, rt_size_t length, char *argv[RT_FINSH_ARG_MAX])
|
|||
ptr ++; position ++;
|
||||
}
|
||||
|
||||
if(argc >= RT_FINSH_ARG_MAX)
|
||||
if(argc >= FINSH_ARG_MAX)
|
||||
{
|
||||
rt_kprintf("Too many args ! We only Use:\n");
|
||||
for(i = 0; i < argc; i++)
|
||||
|
@ -284,7 +287,7 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)
|
|||
int argc;
|
||||
rt_size_t cmd0_size = 0;
|
||||
cmd_function_t cmd_func;
|
||||
char *argv[RT_FINSH_ARG_MAX];
|
||||
char *argv[FINSH_ARG_MAX];
|
||||
|
||||
RT_ASSERT(cmd);
|
||||
RT_ASSERT(retp);
|
||||
|
|
|
@ -4,6 +4,7 @@ from building import *
|
|||
|
||||
comm = rtconfig.ARCH + '/common'
|
||||
path = rtconfig.ARCH + '/' + rtconfig.CPU
|
||||
ASFLAGS = ''
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
if rtconfig.PLATFORM == 'armcc':
|
||||
|
@ -21,7 +22,10 @@ if rtconfig.PLATFORM == 'cl':
|
|||
if rtconfig.PLATFORM == 'mingw':
|
||||
src = Glob(path + '/*.c')
|
||||
|
||||
if rtconfig.PLATFORM == 'armcc' and rtconfig.ARCH == 'arm' and rtconfig.CPU == 'arm926':
|
||||
ASFLAGS = ' --cpreproc'
|
||||
|
||||
CPPPATH = [RTT_ROOT + '/libcpu/' + rtconfig.ARCH + '/' + rtconfig.CPU, RTT_ROOT + '/libcpu/' + rtconfig.ARCH + '/common']
|
||||
group = DefineGroup(rtconfig.CPU.upper(), src, depend = [''], CPPPATH = CPPPATH)
|
||||
group = DefineGroup(rtconfig.CPU.upper(), src, depend = [''], CPPPATH = CPPPATH, ASFLAGS = ASFLAGS)
|
||||
|
||||
Return('group')
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
* 2015-04-21 ArdaFu Remove remap code. Using mmu to map vector table
|
||||
* 2015-06-04 aozima Align stack address to 8 byte.
|
||||
*/
|
||||
|
||||
|
||||
#include "rt_low_level_init.h"
|
||||
|
||||
#define S_FRAME_SIZE (18*4) //72
|
||||
|
||||
@#define S_SPSR (17*4) //SPSR
|
||||
|
@ -54,9 +56,8 @@
|
|||
#define MODE_ABT 0x17
|
||||
#define MODE_UND 0x1B
|
||||
#define MODEMASK 0x1F
|
||||
#define NOINT 0xC0
|
||||
|
||||
.include "rt_low_level_gcc.inc"
|
||||
#define NOINT 0xC0
|
||||
|
||||
@;----------------------- Stack and Heap Definitions ---------------------------
|
||||
.section .nobss, "w"
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
; * 2015-04-21 ArdaFu Remove remap code. Using mmu to map vector table
|
||||
; * 2015-06-04 aozima Align stack address to 8 byte.
|
||||
; */
|
||||
|
||||
|
||||
#include "rt_low_level_init.h"
|
||||
|
||||
#define S_FRAME_SIZE (18*4) ;72
|
||||
|
||||
;#define S_SPSR (17*4) ;SPSR
|
||||
|
@ -54,9 +56,8 @@
|
|||
#define MODE_ABT 0x17
|
||||
#define MODE_UND 0x1B
|
||||
#define MODEMASK 0x1F
|
||||
#define NOINT 0xC0
|
||||
|
||||
#include "rt_low_level_iar.inc"
|
||||
#define NOINT 0xC0
|
||||
|
||||
;----------------------- Stack and Heap Definitions ----------------------------
|
||||
MODULE ?cstartup
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
; * 2015-06-04 aozima Align stack address to 8 byte.
|
||||
; */
|
||||
|
||||
#include "rt_low_level_init.h"
|
||||
|
||||
S_FRAME_SIZE EQU (18*4) ;72
|
||||
;S_SPSR EQU (17*4) ;SPSR
|
||||
;S_CPSR EQU (16*4) ;CPSR
|
||||
|
@ -46,7 +48,6 @@ S_PC EQU (15*4) ;R15
|
|||
;S_R1 EQU (1*4)
|
||||
;S_R0 EQU (0*4)
|
||||
|
||||
|
||||
MODE_USR EQU 0X10
|
||||
MODE_FIQ EQU 0X11
|
||||
MODE_IRQ EQU 0X12
|
||||
|
@ -57,8 +58,6 @@ MODE_SYS EQU 0X1F
|
|||
MODEMASK EQU 0X1F
|
||||
|
||||
NOINT EQU 0xC0
|
||||
|
||||
GET rt_low_level_keil.inc
|
||||
|
||||
;----------------------- Stack and Heap Definitions ----------------------------
|
||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||
|
|
|
@ -487,6 +487,11 @@ def MergeGroup(src_group, group):
|
|||
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
|
||||
else:
|
||||
src_group['CPPDEFINES'] = group['CPPDEFINES']
|
||||
if group.has_key('ASFLAGS'):
|
||||
if src_group.has_key('ASFLAGS'):
|
||||
src_group['ASFLAGS'] = src_group['ASFLAGS'] + group['ASFLAGS']
|
||||
else:
|
||||
src_group['ASFLAGS'] = group['ASFLAGS']
|
||||
|
||||
# for local CCFLAGS/CPPPATH/CPPDEFINES
|
||||
if group.has_key('LOCAL_CCFLAGS'):
|
||||
|
@ -520,6 +525,11 @@ def MergeGroup(src_group, group):
|
|||
src_group['LIBPATH'] = src_group['LIBPATH'] + group['LIBPATH']
|
||||
else:
|
||||
src_group['LIBPATH'] = group['LIBPATH']
|
||||
if group.has_key('LOCAL_ASFLAGS'):
|
||||
if src_group.has_key('LOCAL_ASFLAGS'):
|
||||
src_group['LOCAL_ASFLAGS'] = src_group['LOCAL_ASFLAGS'] + group['LOCAL_ASFLAGS']
|
||||
else:
|
||||
src_group['LOCAL_ASFLAGS'] = group['LOCAL_ASFLAGS']
|
||||
|
||||
def DefineGroup(name, src, depend, **parameters):
|
||||
global Env
|
||||
|
@ -550,6 +560,8 @@ def DefineGroup(name, src, depend, **parameters):
|
|||
Env.AppendUnique(CPPDEFINES = group['CPPDEFINES'])
|
||||
if group.has_key('LINKFLAGS'):
|
||||
Env.AppendUnique(LINKFLAGS = group['LINKFLAGS'])
|
||||
if group.has_key('ASFLAGS'):
|
||||
Env.AppendUnique(ASFLAGS = group['ASFLAGS'])
|
||||
|
||||
# check whether to clean up library
|
||||
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
|
||||
|
@ -645,13 +657,14 @@ def DoBuilding(target, objects):
|
|||
|
||||
# handle local group
|
||||
def local_group(group, objects):
|
||||
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
|
||||
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES') or group.has_key('LOCAL_ASFLAGS'):
|
||||
CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '')
|
||||
CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', [''])
|
||||
CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', [''])
|
||||
ASFLAGS = Env.get('ASFLAGS', '') + group.get('LOCAL_ASFLAGS', '')
|
||||
|
||||
for source in group['src']:
|
||||
objects.append(Env.Object(source, CCFLAGS = CCFLAGS,
|
||||
objects.append(Env.Object(source, CCFLAGS = CCFLAGS, ASFLAGS = ASFLAGS,
|
||||
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES))
|
||||
|
||||
return True
|
||||
|
@ -775,6 +788,11 @@ def EndBuilding(target, program = None):
|
|||
from cscope import CscopeDatabase
|
||||
CscopeDatabase(Projects)
|
||||
|
||||
if not GetOption('help') and not GetOption('target'):
|
||||
if not os.path.exists(rtconfig.EXEC_PATH):
|
||||
print "Error: Toolchain path (%s) is not exist, please check 'EXEC_PATH' in path or rtconfig.py." % rtconfig.EXEC_PATH
|
||||
sys.exit(1)
|
||||
|
||||
def SrcRemove(src, remove):
|
||||
if not src:
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue