mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
4eb8121bae
15 files changed
+1303
-329
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* File : drv_spi.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2012, 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
|
||||
* 2017-11-02 勤为本 first version
|
||||
*/
|
||||
|
||||
#ifndef LS1C_DRV_SPI_H
|
||||
#define LS1C_DRV_SPI_H
|
||||
|
||||
|
||||
#include "../libraries/ls1c_spi.h"
|
||||
|
||||
|
||||
struct ls1c_spi
|
||||
{
|
||||
unsigned char SPIx; // LS1C_SPI_0 or LS1C_SPI_1
|
||||
};
|
||||
|
||||
|
||||
struct ls1c_spi_cs
|
||||
{
|
||||
unsigned char cs; // LS1C_SPI_CS_0, LS1C_SPI_CS_1, LS1C_SPI_CS_2 or LS1C_SPI_CS_3
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 初始化并注册龙芯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);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
// led接口
|
||||
// 使用低电平点亮led,高电平熄灭led
|
||||
|
||||
|
||||
#include "ls1c_gpio.h"
|
||||
|
||||
|
||||
// 初始化led
|
||||
// @led_gpio led所在gpio引脚
|
||||
void led_init(unsigned int led_gpio)
|
||||
{
|
||||
gpio_init(led_gpio, gpio_mode_output);
|
||||
gpio_set(led_gpio, gpio_level_high); // 指示灯默认熄灭
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
// 点亮led
|
||||
// @led_gpio led所在gpio引脚
|
||||
void led_on(unsigned int led_gpio)
|
||||
{
|
||||
gpio_set(led_gpio, gpio_level_low);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
// 熄灭led
|
||||
// @led_gpio
|
||||
void led_off(unsigned int led_gpio)
|
||||
{
|
||||
gpio_set(led_gpio, gpio_level_high);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// led接口
|
||||
// 使用低电平点亮led,高电平熄灭led
|
||||
|
||||
#ifndef __OPENLOONGSON_LED_H
|
||||
#define __OPENLOONGSON_LED_H
|
||||
|
||||
|
||||
// 初始化led
|
||||
// @led_gpio led所在gpio引脚
|
||||
void led_init(unsigned int led_gpio);
|
||||
|
||||
|
||||
// 点亮led
|
||||
// @led_gpio led所在gpio引脚
|
||||
void led_on(unsigned int led_gpio);
|
||||
|
||||
|
||||
// 熄灭led
|
||||
// @led_gpio
|
||||
void led_off(unsigned int led_gpio);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -29,15 +29,10 @@
|
||||
|
||||
|
||||
// SPI模块编号
|
||||
typedef enum
|
||||
{
|
||||
LS1C_SPI_0 = 0,
|
||||
LS1C_SPI_1,
|
||||
}ls1c_spi_t;
|
||||
|
||||
#define LS1C_SPI_0 (0)
|
||||
#define LS1C_SPI_1 (1)
|
||||
|
||||
// 片选
|
||||
#define LS1C_SPI_INVALID_CS (-1)
|
||||
#define LS1C_SPI_CS_0 (0)
|
||||
#define LS1C_SPI_CS_1 (1)
|
||||
#define LS1C_SPI_CS_2 (2)
|
||||
@@ -50,31 +45,80 @@ typedef enum
|
||||
#define SPI_CPHA_0 (0)
|
||||
|
||||
|
||||
// 硬件SPI信息
|
||||
typedef struct
|
||||
{
|
||||
ls1c_spi_t SPIx; // SPI模块编号
|
||||
unsigned long max_speed_hz; // 最大通信速度,单位hz
|
||||
unsigned char cs; // 片选
|
||||
unsigned char cpol; // 时钟极性
|
||||
unsigned char cpha; // 时钟相位
|
||||
}ls1c_spi_info_t;
|
||||
// 寄存器偏移
|
||||
#define LS1C_SPI_SPCR_OFFSET (0) // 控制寄存器
|
||||
#define LS1C_SPI_SPSR_OFFSET (1) // 状态寄存器
|
||||
#define LS1C_SPI_TxFIFO_OFFSET (2) // 发送的数据寄存器,与接收数据寄存器的偏移相同
|
||||
#define LS1C_SPI_RxFIFO_OFFSET (2) // 接收的数据寄存器,与发送数据寄存器的偏移相同
|
||||
#define LS1C_SPI_SPER_OFFSET (3) // 外部寄存器
|
||||
#define LS1C_SPI_SFC_PARAM_OFFSET (4) // 参数控制寄存器
|
||||
#define LS1C_SPI_SFC_SOFTCS_OFFSET (5) // 片选控制寄存器
|
||||
#define LS1C_SPI_SFC_TIMING_OFFSET (6) // 时序控制寄存器
|
||||
|
||||
// 寄存器SPCR中的位域
|
||||
#define LS1C_SPI_SPCR_SPIE_BIT (7)
|
||||
#define LS1C_SPI_SPCR_SPIE_MASK (0x01 << LS1C_SPI_SPCR_SPIE_BIT)
|
||||
#define LS1C_SPI_SPCR_SPE_BIT (6)
|
||||
#define LS1C_SPI_SPCR_SPE_MASK (0x01 << LS1C_SPI_SPCR_SPE_BIT)
|
||||
#define LS1C_SPI_SPCR_CPOL_BIT (3)
|
||||
#define LS1C_SPI_SPCR_CPOL_MASK (0x01 << LS1C_SPI_SPCR_CPOL_BIT)
|
||||
#define LS1C_SPI_SPCR_CPHA_BIT (2)
|
||||
#define LS1C_SPI_SPCR_CPHA_MASK (0x01 << LS1C_SPI_SPCR_CPHA_BIT)
|
||||
#define LS1C_SPI_SPCR_SPR_BIT (0)
|
||||
#define LS1C_SPI_SPCR_SPR_MASK (0x03 << LS1C_SPI_SPCR_SPR_BIT)
|
||||
|
||||
// 寄存器SPSR中的位域
|
||||
#define LS1C_SPI_SPSR_SPIF_BIT (7)
|
||||
#define LS1C_SPI_SPSR_SPIF_MASK (0x01 << LS1C_SPI_SPSR_SPIF_BIT)
|
||||
#define LS1C_SPI_SPSR_WCOL_BIT (6)
|
||||
#define LS1C_SPI_SPSR_WCOL_MASK (0x01 << LS1C_SPI_SPSR_WCOL_BIT)
|
||||
|
||||
// 寄存器SPER中的位域
|
||||
#define LS1C_SPI_SPER_SPRE_BIT (0)
|
||||
#define LS1C_SPI_SPER_SPRE_MASK (0x3 << LS1C_SPI_SPER_SPRE_BIT)
|
||||
|
||||
// 寄存器SFC_SOFTCS的位域
|
||||
#define LS1C_SPI_SFC_SOFTCS_CSN_BIT (4)
|
||||
#define LS1C_SPI_SFC_SOFTCS_CSN_MASK (0x0f << LS1C_SPI_SFC_SOFTCS_CSN_BIT)
|
||||
#define LS1C_SPI_SFC_SOFTCS_CSEN_BIT (0)
|
||||
#define LS1C_SPI_SFC_SOFTCS_CSEN_MASK (0x0f << LS1C_SPI_SFC_SOFTCS_CSEN_BIT)
|
||||
|
||||
// 发送超时的门限值
|
||||
#define LS1C_SPI_TX_TIMEOUT (20000)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 初始化指定SPI模块
|
||||
* @spi_info_p SPI模块信息
|
||||
* 获取指定SPI模块的基地址
|
||||
* @SPIx SPI模块的编号
|
||||
*/
|
||||
void spi_init(ls1c_spi_info_t *spi_info_p);
|
||||
inline void *ls1c_spi_get_base(unsigned char SPIx);
|
||||
|
||||
|
||||
/*
|
||||
* 设置时钟
|
||||
* @spi_base 基地址
|
||||
* @max_hz 最大频率,单位hz
|
||||
*/
|
||||
void ls1c_spi_set_clock(void *spi_base, unsigned long max_hz);
|
||||
|
||||
|
||||
/*
|
||||
* 设置通信模式(时钟极性和相位)
|
||||
* @spi_base 基地址
|
||||
* @cpol 时钟极性
|
||||
* @cpha 时钟相位
|
||||
*/
|
||||
void ls1c_spi_set_mode(void *spi_base, unsigned char cpol, unsigned char cpha);
|
||||
|
||||
|
||||
/*
|
||||
* 设置指定片选为指定状态
|
||||
* @spi_info_p SPI模块信息
|
||||
* @spi_base 基地址
|
||||
* @cs 片选
|
||||
* @new_status 片选引脚的新状态,取值为0或1,即高电平或低电平
|
||||
*/
|
||||
void spi_set_cs(ls1c_spi_info_t *spi_info_p, int new_status);
|
||||
void ls1c_spi_set_cs(void *spi_base, unsigned char cs, int new_status);
|
||||
|
||||
|
||||
/*
|
||||
@@ -82,18 +126,20 @@ void spi_set_cs(ls1c_spi_info_t *spi_info_p, int new_status);
|
||||
* 注意,在多任务的系统中,此函数需要互斥。
|
||||
* 即保证在和某个从设备收发某个字节的过程中,不能被切换到其它任务同时与另外的在同一个SPI总线上的从设备通信
|
||||
* 因为龙芯1c的每路SPI上可能接有不同的从设备,通信频率、模式等可能不同
|
||||
* @spi_info_p SPI接口
|
||||
* @spi_base 基地址
|
||||
* @tx_ch 待发送的数据
|
||||
* @ret 收到的数据
|
||||
*/
|
||||
unsigned char spi_txrx_byte(ls1c_spi_info_t *spi_info_p, unsigned char tx_ch);
|
||||
unsigned char ls1c_spi_txrx_byte(void *spi_base, unsigned char tx_ch);
|
||||
|
||||
|
||||
/*
|
||||
* 打印指定SPI模块的所有寄存器的值
|
||||
* @spi_info_p SPI模块信息
|
||||
* @spi_base 基地址
|
||||
*/
|
||||
void spi_print_all_regs_info(ls1c_spi_info_t *spi_info_p);
|
||||
void ls1c_spi_print_all_regs_info(void *spi_base);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -227,6 +227,11 @@
|
||||
#define RTGUI_IMAGE_BMP
|
||||
// </section>
|
||||
|
||||
#define RT_USING_SPI
|
||||
#define RT_USING_SPI0
|
||||
#define RT_USING_SPI1
|
||||
|
||||
|
||||
// </RDTConfigurator>
|
||||
|
||||
#endif
|
||||
@@ -16,8 +16,6 @@
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
#include <gpio.h>
|
||||
#include <stm32f10x_exti.h>
|
||||
|
||||
#ifdef RT_USING_PIN
|
||||
|
||||
@@ -591,12 +589,12 @@ rt_err_t stm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
|
||||
index = get_pin(pin);
|
||||
if (index == RT_NULL)
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
irqindex = bit2bitno(index->pin);
|
||||
if(irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
@@ -612,7 +610,7 @@ rt_err_t stm32_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
|
||||
if(pin_irq_hdr_tab[irqindex].pin != -1)
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
return RT_EBUSY;
|
||||
return -RT_EBUSY;
|
||||
}
|
||||
pin_irq_hdr_tab[irqindex].pin = pin;
|
||||
pin_irq_hdr_tab[irqindex].hdr = hdr;
|
||||
@@ -631,12 +629,12 @@ rt_err_t stm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
|
||||
index = get_pin(pin);
|
||||
if (index == RT_NULL)
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
irqindex = bit2bitno(index->pin);
|
||||
if(irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
@@ -667,20 +665,20 @@ rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
||||
index = get_pin(pin);
|
||||
if (index == RT_NULL)
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
if(enabled == PIN_IRQ_ENABLE)
|
||||
{
|
||||
irqindex = bit2bitno(index->pin);
|
||||
if(irqindex < 0 || irqindex >= ITEM_NUM(pin_irq_map))
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
level = rt_hw_interrupt_disable();
|
||||
if(pin_irq_hdr_tab[irqindex].pin == -1)
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
irqmap = &pin_irq_map[irqindex];
|
||||
/* GPIO Periph clock enable */
|
||||
@@ -720,7 +718,7 @@ rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
||||
irqmap = get_pin_irq_map(index->pin);
|
||||
if(irqmap == RT_NULL)
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
EXTI_InitStructure.EXTI_Line = irqmap->irqbit;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
@@ -730,7 +728,7 @@ rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
||||
}
|
||||
else
|
||||
{
|
||||
return RT_ENOSYS;
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
|
||||
+778
-71
File diff suppressed because it is too large.
Load diff
@@ -14,7 +14,7 @@ CONFIG_RT_TICK_PER_SECOND=1000
|
||||
CONFIG_RT_DEBUG=y
|
||||
CONFIG_RT_USING_OVERFLOW_CHECK=y
|
||||
CONFIG_RT_DEBUG_INIT=1
|
||||
# CONFIG_RT_DEBUG_THREAD is not set
|
||||
CONFIG_RT_DEBUG_THREAD=0
|
||||
CONFIG_RT_USING_HOOK=y
|
||||
CONFIG_IDLE_THREAD_STACK_SIZE=1024
|
||||
# CONFIG_RT_USING_TIMER_SOFT is not set
|
||||
@@ -42,6 +42,7 @@ CONFIG_RT_USING_SMALL_MEM=y
|
||||
# Kernel Device Object
|
||||
#
|
||||
CONFIG_RT_USING_DEVICE=y
|
||||
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
||||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=128
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart"
|
||||
@@ -100,6 +101,8 @@ CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512
|
||||
CONFIG_RT_DFS_ELM_REENTRANT=y
|
||||
CONFIG_RT_USING_DFS_DEVFS=y
|
||||
CONFIG_RT_USING_DFS_NET=y
|
||||
CONFIG_HAVE_SYS_SELECT_H=y
|
||||
# CONFIG_HAVE_SYS_SOCKET_H is not set
|
||||
# CONFIG_RT_USING_DFS_ROMFS is not set
|
||||
# CONFIG_RT_USING_DFS_RAMFS is not set
|
||||
# CONFIG_RT_USING_DFS_UFFS is not set
|
||||
@@ -151,7 +154,14 @@ CONFIG_RT_LWIP_DNS=y
|
||||
CONFIG_RT_LWIP_DHCP=y
|
||||
CONFIG_IP_SOF_BROADCAST=1
|
||||
CONFIG_IP_SOF_BROADCAST_RECV=1
|
||||
CONFIG_LWIP_USING_DHCPD=y
|
||||
# CONFIG_LWIP_USING_DHCPD is not set
|
||||
|
||||
#
|
||||
# Static IPv4 Address
|
||||
#
|
||||
CONFIG_RT_LWIP_IPADDR="192.168.10.30"
|
||||
CONFIG_RT_LWIP_GWADDR="192.168.10.1"
|
||||
CONFIG_RT_LWIP_MSKADDR="255.255.255.0"
|
||||
CONFIG_RT_LWIP_UDP=y
|
||||
CONFIG_RT_LWIP_TCP=y
|
||||
# CONFIG_RT_LWIP_RAW is not set
|
||||
@@ -189,6 +199,11 @@ CONFIG_LWIP_SO_RCVBUF=1
|
||||
#
|
||||
# CONFIG_RT_USING_GUIENGINE is not set
|
||||
|
||||
#
|
||||
# VBUS(Virtual Software BUS)
|
||||
#
|
||||
# CONFIG_RT_USING_VBUS is not set
|
||||
|
||||
#
|
||||
# RT-Thread online packages
|
||||
#
|
||||
@@ -227,12 +242,14 @@ CONFIG_LWIP_SO_RCVBUF=1
|
||||
#
|
||||
# multimedia packages
|
||||
#
|
||||
# CONFIG_PKG_USING_FASTLZ is not set
|
||||
|
||||
#
|
||||
# tools packages
|
||||
#
|
||||
# CONFIG_PKG_USING_CMBACKTRACE is not set
|
||||
# CONFIG_PKG_USING_EASYLOGGER is not set
|
||||
# CONFIG_PKG_USING_SYSTEMVIEW is not set
|
||||
|
||||
#
|
||||
# miscellaneous packages
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define RT_DEBUG
|
||||
#define RT_USING_OVERFLOW_CHECK
|
||||
#define RT_DEBUG_INIT 1
|
||||
/* RT_DEBUG_THREAD is not set */
|
||||
#define RT_DEBUG_THREAD 0
|
||||
#define RT_USING_HOOK
|
||||
#define IDLE_THREAD_STACK_SIZE 1024
|
||||
/* RT_USING_TIMER_SOFT is not set */
|
||||
@@ -40,6 +40,7 @@
|
||||
/* Kernel Device Object */
|
||||
|
||||
#define RT_USING_DEVICE
|
||||
/* RT_USING_INTERRUPT_INFO is not set */
|
||||
#define RT_USING_CONSOLE
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart"
|
||||
@@ -93,6 +94,8 @@
|
||||
#define RT_DFS_ELM_REENTRANT
|
||||
#define RT_USING_DFS_DEVFS
|
||||
#define RT_USING_DFS_NET
|
||||
#define HAVE_SYS_SELECT_H
|
||||
/* HAVE_SYS_SOCKET_H is not set */
|
||||
/* RT_USING_DFS_ROMFS is not set */
|
||||
/* RT_USING_DFS_RAMFS is not set */
|
||||
/* RT_USING_DFS_UFFS is not set */
|
||||
@@ -139,7 +142,13 @@
|
||||
#define RT_LWIP_DHCP
|
||||
#define IP_SOF_BROADCAST 1
|
||||
#define IP_SOF_BROADCAST_RECV 1
|
||||
#define LWIP_USING_DHCPD
|
||||
/* LWIP_USING_DHCPD is not set */
|
||||
|
||||
/* Static IPv4 Address */
|
||||
|
||||
#define RT_LWIP_IPADDR "192.168.10.30"
|
||||
#define RT_LWIP_GWADDR "192.168.10.1"
|
||||
#define RT_LWIP_MSKADDR "255.255.255.0"
|
||||
#define RT_LWIP_UDP
|
||||
#define RT_LWIP_TCP
|
||||
/* RT_LWIP_RAW is not set */
|
||||
@@ -175,6 +184,10 @@
|
||||
|
||||
/* RT_USING_GUIENGINE is not set */
|
||||
|
||||
/* VBUS(Virtual Software BUS) */
|
||||
|
||||
/* RT_USING_VBUS is not set */
|
||||
|
||||
/* RT-Thread online packages */
|
||||
|
||||
/* system packages */
|
||||
@@ -205,10 +218,13 @@
|
||||
|
||||
/* multimedia packages */
|
||||
|
||||
/* PKG_USING_FASTLZ is not set */
|
||||
|
||||
/* tools packages */
|
||||
|
||||
/* PKG_USING_CMBACKTRACE is not set */
|
||||
/* PKG_USING_EASYLOGGER is not set */
|
||||
/* PKG_USING_SYSTEMVIEW is not set */
|
||||
|
||||
/* miscellaneous packages */
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ int rt_pin_read(rt_base_t pin);
|
||||
rt_err_t rt_pin_attach_irq(rt_int32_t pin, rt_uint32_t mode,
|
||||
void (*hdr)(void *args), void *args);
|
||||
rt_err_t rt_pin_dettach_irq(rt_int32_t pin);
|
||||
rt_err_t pin_irq_enable(rt_base_t pin, rt_uint32_t enabled);
|
||||
rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled);
|
||||
|
||||
int rt_device_pin_irq_register(const char *name, const struct rt_pin_ops *ops,
|
||||
void *user_data);
|
||||
|
||||
@@ -117,7 +117,7 @@ rt_err_t rt_pin_dettach_irq(rt_int32_t pin)
|
||||
}
|
||||
return RT_ENOSYS;
|
||||
}
|
||||
rt_err_t pin_irq_enable(rt_base_t pin, rt_uint32_t enabled)
|
||||
rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled)
|
||||
{
|
||||
RT_ASSERT(_hw_pin.ops != RT_NULL);
|
||||
if(_hw_pin.ops->pin_irq_enable)
|
||||
|
||||
@@ -41,8 +41,11 @@ struct rt_wlan_info info;
|
||||
#define WIFI_SETTING_FN "/appfs/setting.json"
|
||||
#endif
|
||||
|
||||
#ifndef WIFI_DEVICE_NAME
|
||||
#define WIFI_DEVICE_NAME "w0"
|
||||
#ifndef WIFI_DEVICE_STA_NAME
|
||||
#define WIFI_DEVICE_STA_NAME "w0"
|
||||
#endif
|
||||
#ifndef WIFI_DEVICE_AP_NAME
|
||||
#define WIFI_DEVICE_AP_NAME "ap"
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
@@ -304,53 +307,43 @@ int wifi_default(void)
|
||||
/* read default setting for wifi */
|
||||
wifi_read_cfg(WIFI_SETTING_FN);
|
||||
|
||||
/* get wlan device */
|
||||
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_NAME);
|
||||
if (!wlan)
|
||||
{
|
||||
rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_NAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (network_mode == WIFI_STATION)
|
||||
{
|
||||
struct rt_wlan_info *info;
|
||||
|
||||
info = (struct rt_wlan_info *)rt_malloc (sizeof(struct rt_wlan_info));
|
||||
if (!info)
|
||||
/* get wlan device */
|
||||
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_STA_NAME);
|
||||
if (!wlan)
|
||||
{
|
||||
rt_kprintf("wifi: out of memory\n");
|
||||
rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_STA_NAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* wifi station */
|
||||
rt_wlan_info_init(info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, wifi_ssid);
|
||||
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, wifi_ssid);
|
||||
result =rt_wlan_init(wlan, WIFI_STATION);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
result = rt_wlan_connect(wlan, info, wifi_key);
|
||||
result = rt_wlan_connect(wlan, &info, wifi_key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* wifi AP */
|
||||
struct rt_wlan_info *info;
|
||||
|
||||
info = (struct rt_wlan_info *)rt_malloc (sizeof(struct rt_wlan_info));
|
||||
if (!info)
|
||||
/* get wlan device */
|
||||
wlan = (struct rt_wlan_device*)rt_device_find(WIFI_DEVICE_AP_NAME);
|
||||
if (!wlan)
|
||||
{
|
||||
rt_kprintf("wifi: out of memory\n");
|
||||
rt_kprintf("no wlan:%s device\n", WIFI_DEVICE_AP_NAME);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rt_wlan_info_init(info, WIFI_AP, SECURITY_WPA2_AES_PSK, wifi_ssid);
|
||||
info->channel = 11;
|
||||
rt_wlan_info_init(&info, WIFI_AP, SECURITY_WPA2_AES_PSK, wifi_ssid);
|
||||
info.channel = 11;
|
||||
|
||||
/* wifi soft-AP */
|
||||
result =rt_wlan_init(wlan, WIFI_AP);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
result = rt_wlan_softap(wlan, info, wifi_key);
|
||||
result = rt_wlan_softap(wlan, &info, wifi_key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,6 +410,7 @@ int wifi(int argc, char** argv)
|
||||
if (strcmp(argv[2], "join") == 0)
|
||||
{
|
||||
rt_wlan_init(wlan, WIFI_STATION);
|
||||
network_mode = WIFI_STATION;
|
||||
|
||||
/* TODO: use easy-join to replace */
|
||||
rt_wlan_info_init(&info, WIFI_STATION, SECURITY_WPA2_MIXED_PSK, argv[3]);
|
||||
@@ -471,34 +465,37 @@ int wifi(int argc, char** argv)
|
||||
else if (strcmp(argv[2], "ap") == 0)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_wlan_info *info;
|
||||
|
||||
info = (struct rt_wlan_info*)rt_malloc(sizeof(struct rt_wlan_info));
|
||||
if (argc == 4)
|
||||
{
|
||||
// open soft-AP
|
||||
rt_wlan_info_init(info, WIFI_AP, SECURITY_OPEN, argv[3]);
|
||||
info->channel = 11;
|
||||
rt_wlan_info_init(&info, WIFI_AP, SECURITY_OPEN, argv[3]);
|
||||
info.channel = 11;
|
||||
|
||||
result =rt_wlan_init(wlan, WIFI_AP);
|
||||
/* start soft ap */
|
||||
result = rt_wlan_softap(wlan, info, NULL);
|
||||
result = rt_wlan_softap(wlan, &info, NULL);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
network_mode = WIFI_AP;
|
||||
}
|
||||
}
|
||||
else if (argc == 5)
|
||||
{
|
||||
// WPA2 with password
|
||||
rt_wlan_info_init(info, WIFI_AP, SECURITY_WPA2_AES_PSK, argv[3]);
|
||||
info->channel = 11;
|
||||
rt_wlan_info_init(&info, WIFI_AP, SECURITY_WPA2_AES_PSK, argv[3]);
|
||||
info.channel = 11;
|
||||
|
||||
result =rt_wlan_init(wlan, WIFI_AP);
|
||||
/* start soft ap */
|
||||
result = rt_wlan_softap(wlan, info, argv[4]);
|
||||
result = rt_wlan_softap(wlan, &info, argv[4]);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
network_mode = WIFI_AP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* release information */
|
||||
rt_free(info);
|
||||
|
||||
wifi_usage();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef __RTT_DIRENT_H__
|
||||
#define __RTT_DIRENT_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtlibc.h>
|
||||
|
||||
/*
|
||||
* dirent.h - format of directory entries
|
||||
* Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
|
||||
*/
|
||||
|
||||
/* File types */
|
||||
#define FT_REGULAR 0 /* regular file */
|
||||
#define FT_SOCKET 1 /* socket file */
|
||||
#define FT_DIRECTORY 2 /* directory */
|
||||
#define FT_USER 3 /* user defined */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DIR_STRUCTURE
|
||||
typedef struct
|
||||
{
|
||||
int fd; /* directory file */
|
||||
char buf[512];
|
||||
int num;
|
||||
int cur;
|
||||
} DIR;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DIRENT_STRUCTURE
|
||||
struct dirent
|
||||
{
|
||||
rt_uint8_t d_type; /* The type of the file */
|
||||
rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
|
||||
rt_uint16_t d_reclen; /* length of this record */
|
||||
char d_name[256]; /* The null-terminated file name */
|
||||
};
|
||||
#endif
|
||||
|
||||
int closedir(DIR *);
|
||||
DIR *opendir(const char *);
|
||||
struct dirent *readdir(DIR *);
|
||||
int readdir_r(DIR *, struct dirent *, struct dirent **);
|
||||
void rewinddir(DIR *);
|
||||
void seekdir(DIR *, long int);
|
||||
long telldir(DIR *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user