This commit is contained in:
james 2024-07-25 21:13:42 +08:00
parent bcc787a68f
commit 66c6558488
17 changed files with 702 additions and 39 deletions

197
.config
View File

@ -135,7 +135,9 @@ CONFIG_FINSH_USING_OPTION_COMPLETION=y
# CONFIG_RT_USING_DEV_BUS is not set
CONFIG_RT_USING_DEVICE_IPC=y
CONFIG_RT_UNAMED_PIPE_NUMBER=64
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
CONFIG_RT_USING_SYSTEM_WORKQUEUE=y
CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
CONFIG_RT_USING_SERIAL=y
CONFIG_RT_USING_SERIAL_V1=y
# CONFIG_RT_USING_SERIAL_V2 is not set
@ -162,14 +164,52 @@ CONFIG_RT_USING_PWM=y
# CONFIG_RT_USING_PM is not set
# CONFIG_RT_USING_RTC is not set
# CONFIG_RT_USING_SDIO is not set
# CONFIG_RT_USING_SPI is not set
CONFIG_RT_USING_SPI=y
# CONFIG_RT_USING_SPI_BITOPS is not set
# CONFIG_RT_USING_QSPI is not set
# CONFIG_RT_USING_SPI_MSD is not set
CONFIG_RT_USING_SFUD=y
CONFIG_RT_SFUD_USING_SFDP=y
CONFIG_RT_SFUD_USING_FLASH_INFO_TABLE=y
# CONFIG_RT_SFUD_USING_QSPI is not set
CONFIG_RT_SFUD_SPI_MAX_HZ=50000000
# CONFIG_RT_DEBUG_SFUD is not set
# CONFIG_RT_USING_ENC28J60 is not set
# CONFIG_RT_USING_SPI_WIFI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set
# CONFIG_RT_USING_TOUCH is not set
# CONFIG_RT_USING_LCD is not set
# CONFIG_RT_USING_HWCRYPTO is not set
# CONFIG_RT_USING_WIFI is not set
CONFIG_RT_USING_WIFI=y
CONFIG_RT_WLAN_DEVICE_STA_NAME="wlan0"
CONFIG_RT_WLAN_DEVICE_AP_NAME="wlan1"
CONFIG_RT_WLAN_SSID_MAX_LENGTH=32
CONFIG_RT_WLAN_PASSWORD_MAX_LENGTH=32
CONFIG_RT_WLAN_DEV_EVENT_NUM=2
CONFIG_RT_WLAN_MANAGE_ENABLE=y
CONFIG_RT_WLAN_SCAN_WAIT_MS=10000
CONFIG_RT_WLAN_CONNECT_WAIT_MS=10000
CONFIG_RT_WLAN_SCAN_SORT=y
CONFIG_RT_WLAN_MSH_CMD_ENABLE=y
CONFIG_RT_WLAN_JOIN_SCAN_BY_MGNT=y
CONFIG_RT_WLAN_AUTO_CONNECT_ENABLE=y
CONFIG_AUTO_CONNECTION_PERIOD_MS=2000
CONFIG_RT_WLAN_CFG_ENABLE=y
CONFIG_RT_WLAN_CFG_INFO_MAX=3
CONFIG_RT_WLAN_PROT_ENABLE=y
CONFIG_RT_WLAN_PROT_NAME_LEN=8
CONFIG_RT_WLAN_PROT_MAX=2
CONFIG_RT_WLAN_DEFAULT_PROT="lwip"
CONFIG_RT_WLAN_PROT_LWIP_ENABLE=y
CONFIG_RT_WLAN_PROT_LWIP_NAME="lwip"
# CONFIG_RT_WLAN_PROT_LWIP_PBUF_FORCE is not set
CONFIG_RT_WLAN_WORK_THREAD_ENABLE=y
CONFIG_RT_WLAN_WORKQUEUE_THREAD_NAME="wlan"
CONFIG_RT_WLAN_WORKQUEUE_THREAD_SIZE=2048
CONFIG_RT_WLAN_WORKQUEUE_THREAD_PRIO=15
# CONFIG_RT_WLAN_DEBUG is not set
# CONFIG_RT_USING_VIRTIO is not set
CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_KTIME is not set
@ -225,9 +265,87 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
#
# Network
#
# CONFIG_RT_USING_SAL is not set
# CONFIG_RT_USING_NETDEV is not set
# CONFIG_RT_USING_LWIP is not set
CONFIG_RT_USING_SAL=y
CONFIG_SAL_INTERNET_CHECK=y
#
# Docking with protocol stacks
#
CONFIG_SAL_USING_LWIP=y
# CONFIG_SAL_USING_AT is not set
# CONFIG_SAL_USING_TLS is not set
# end of Docking with protocol stacks
CONFIG_SAL_SOCKETS_NUM=16
CONFIG_RT_USING_NETDEV=y
CONFIG_NETDEV_USING_IFCONFIG=y
CONFIG_NETDEV_USING_PING=y
CONFIG_NETDEV_USING_NETSTAT=y
CONFIG_NETDEV_USING_AUTO_DEFAULT=y
# CONFIG_NETDEV_USING_IPV6 is not set
CONFIG_NETDEV_IPV4=1
CONFIG_NETDEV_IPV6=0
CONFIG_RT_USING_LWIP=y
# CONFIG_RT_USING_LWIP_LOCAL_VERSION is not set
# CONFIG_RT_USING_LWIP141 is not set
CONFIG_RT_USING_LWIP203=y
# CONFIG_RT_USING_LWIP212 is not set
# CONFIG_RT_USING_LWIP_LATEST is not set
CONFIG_RT_USING_LWIP_VER_NUM=0x20003
# CONFIG_RT_USING_LWIP_IPV6 is not set
CONFIG_RT_LWIP_MEM_ALIGNMENT=4
CONFIG_RT_LWIP_IGMP=y
CONFIG_RT_LWIP_ICMP=y
# CONFIG_RT_LWIP_SNMP is not set
CONFIG_RT_LWIP_DNS=y
CONFIG_RT_LWIP_DHCP=y
CONFIG_IP_SOF_BROADCAST=1
CONFIG_IP_SOF_BROADCAST_RECV=1
#
# Static IPv4 Address
#
CONFIG_RT_LWIP_IPADDR="192.168.1.30"
CONFIG_RT_LWIP_GWADDR="192.168.1.1"
CONFIG_RT_LWIP_MSKADDR="255.255.255.0"
# end of Static IPv4 Address
CONFIG_RT_LWIP_UDP=y
CONFIG_RT_LWIP_TCP=y
CONFIG_RT_LWIP_RAW=y
# CONFIG_RT_LWIP_PPP is not set
CONFIG_RT_MEMP_NUM_NETCONN=8
CONFIG_RT_LWIP_PBUF_NUM=16
CONFIG_RT_LWIP_RAW_PCB_NUM=4
CONFIG_RT_LWIP_UDP_PCB_NUM=4
CONFIG_RT_LWIP_TCP_PCB_NUM=4
CONFIG_RT_LWIP_TCP_SEG_NUM=40
CONFIG_RT_LWIP_TCP_SND_BUF=8196
CONFIG_RT_LWIP_TCP_WND=8196
CONFIG_RT_LWIP_TCPTHREAD_PRIORITY=10
CONFIG_RT_LWIP_TCPTHREAD_MBOX_SIZE=8
CONFIG_RT_LWIP_TCPTHREAD_STACKSIZE=1024
# CONFIG_LWIP_NO_RX_THREAD is not set
# CONFIG_LWIP_NO_TX_THREAD is not set
CONFIG_RT_LWIP_ETHTHREAD_PRIORITY=12
CONFIG_RT_LWIP_ETHTHREAD_STACKSIZE=1024
CONFIG_RT_LWIP_ETHTHREAD_MBOX_SIZE=8
# CONFIG_RT_LWIP_REASSEMBLY_FRAG is not set
CONFIG_LWIP_NETIF_STATUS_CALLBACK=1
CONFIG_LWIP_NETIF_LINK_CALLBACK=1
CONFIG_RT_LWIP_NETIF_NAMESIZE=6
CONFIG_SO_REUSE=1
CONFIG_LWIP_SO_RCVTIMEO=1
CONFIG_LWIP_SO_SNDTIMEO=1
CONFIG_LWIP_SO_RCVBUF=1
CONFIG_LWIP_SO_LINGER=0
# CONFIG_RT_LWIP_NETIF_LOOPBACK is not set
CONFIG_LWIP_NETIF_LOOPBACK=0
# CONFIG_RT_LWIP_STATS is not set
# CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set
CONFIG_RT_LWIP_USING_PING=y
# CONFIG_LWIP_USING_DHCPD is not set
# CONFIG_RT_LWIP_DEBUG is not set
# CONFIG_RT_USING_AT is not set
# end of Network
@ -242,7 +360,34 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# Utilities
#
# CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set
CONFIG_RT_USING_ULOG=y
# CONFIG_ULOG_OUTPUT_LVL_A is not set
# CONFIG_ULOG_OUTPUT_LVL_E is not set
# CONFIG_ULOG_OUTPUT_LVL_W is not set
# CONFIG_ULOG_OUTPUT_LVL_I is not set
CONFIG_ULOG_OUTPUT_LVL_D=y
CONFIG_ULOG_OUTPUT_LVL=7
# CONFIG_ULOG_USING_ISR_LOG is not set
CONFIG_ULOG_ASSERT_ENABLE=y
CONFIG_ULOG_LINE_BUF_SIZE=128
# CONFIG_ULOG_USING_ASYNC_OUTPUT is not set
#
# log format
#
# CONFIG_ULOG_OUTPUT_FLOAT is not set
CONFIG_ULOG_USING_COLOR=y
CONFIG_ULOG_OUTPUT_TIME=y
# CONFIG_ULOG_TIME_USING_TIMESTAMP is not set
CONFIG_ULOG_OUTPUT_LEVEL=y
CONFIG_ULOG_OUTPUT_TAG=y
# CONFIG_ULOG_OUTPUT_THREAD_NAME is not set
# end of log format
CONFIG_ULOG_BACKEND_USING_CONSOLE=y
# CONFIG_ULOG_BACKEND_USING_FILE is not set
# CONFIG_ULOG_USING_FILTER is not set
# CONFIG_ULOG_USING_SYSLOG is not set
# CONFIG_RT_USING_UTEST is not set
# CONFIG_RT_USING_VAR_EXPORT is not set
# CONFIG_RT_USING_RESOURCE_ID is not set
@ -299,7 +444,25 @@ CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
# CONFIG_PKG_USING_WLAN_WICED is not set
# end of Wiced WiFi
# CONFIG_PKG_USING_RW007 is not set
CONFIG_PKG_USING_RW007=y
CONFIG_PKG_RW007_PATH="/packages/iot/WiFi/rw007"
CONFIG_PKG_USING_RW007_V210=y
# CONFIG_PKG_USING_RW007_V201 is not set
# CONFIG_PKG_USING_RW007_V200 is not set
# CONFIG_PKG_USING_RW007_V111 is not set
# CONFIG_PKG_USING_RW007_V110 is not set
# CONFIG_PKG_USING_RW007_V100 is not set
# CONFIG_PKG_USING_RW007_LATEST_VERSION is not set
CONFIG_PKG_RW007_VER="v2.1.0"
# CONFIG_RW007_NOT_USE_EXAMPLE_DRIVERS is not set
CONFIG_RW007_USING_STM32_DRIVERS=y
CONFIG_RW007_SPI_MAX_HZ=30000000
CONFIG_RW007_SPI_BUS_NAME="spi2"
CONFIG_RW007_CS_PIN=102
CONFIG_RW007_BOOT0_PIN=175
CONFIG_RW007_BOOT1_PIN=102
CONFIG_RW007_INT_BUSY_PIN=62
CONFIG_RW007_RST_PIN=187
#
# CYW43012 WiFi
@ -919,7 +1082,12 @@ CONFIG_KERNEL_SAMPLES_USING_MESSAGEQUEUE=y
# CONFIG_PKG_USING_LZMA is not set
# CONFIG_PKG_USING_RALARAM is not set
# CONFIG_PKG_USING_MULTIBUTTON is not set
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
CONFIG_PKG_USING_FLEXIBLE_BUTTON=y
CONFIG_PKG_FLEXIBLE_BUTTON_PATH="/packages/misc/FlexibleButton"
# CONFIG_PKG_USING_FLEXIBLE_BUTTON_DEMO is not set
CONFIG_PKG_USING_FLEXIBLE_BUTTON_V100=y
# CONFIG_PKG_USING_FLEXIBLE_BUTTON_LATEST is not set
CONFIG_PKG_FLEXIBLE_BUTTON_VER="v1.0.0"
# CONFIG_PKG_USING_CANFESTIVAL is not set
# CONFIG_PKG_USING_ZLIB is not set
# CONFIG_PKG_USING_MINIZIP is not set
@ -1202,13 +1370,13 @@ CONFIG_BSP_USING_USB_TO_USART=y
# CONFIG_BSP_USING_ONBOARD_LCD is not set
# CONFIG_BSP_USING_ONBOARD_LED_MATRIX is not set
# CONFIG_BSP_USING_LVGL is not set
# CONFIG_BSP_USING_SPI_FLASH is not set
CONFIG_BSP_USING_SPI_FLASH=y
# CONFIG_BSP_USING_EEPROM is not set
# CONFIG_BSP_USING_ENC28j60 is not set
# CONFIG_BSP_USING_FS is not set
# CONFIG_BSP_USING_FAL is not set
# CONFIG_BSP_USING_EASYFLASH is not set
# CONFIG_BSP_USING_RW007_WLAN is not set
CONFIG_BSP_USING_RW007_WLAN=y
# CONFIG_BSP_USING_AHT21 is not set
# CONFIG_BSP_USING_AP3216C is not set
# CONFIG_BSP_USING_ICM20608 is not set
@ -1234,7 +1402,11 @@ CONFIG_BSP_USING_UART1=y
# CONFIG_BSP_USING_PWM is not set
# CONFIG_BSP_USING_ON_CHIP_FLASH is not set
# CONFIG_BSP_USING_SOFT_SPI is not set
# CONFIG_BSP_USING_SPI is not set
CONFIG_BSP_USING_SPI=y
# CONFIG_BSP_USING_SPI1 is not set
CONFIG_BSP_USING_SPI2=y
# CONFIG_BSP_SPI2_TX_USING_DMA is not set
# CONFIG_BSP_SPI2_RX_USING_DMA is not set
# CONFIG_BSP_USING_ADC is not set
# CONFIG_BSP_USING_I2C is not set
# CONFIG_BSP_USING_ONBOARD_PM is not set
@ -1252,6 +1424,7 @@ CONFIG_BSP_USING_UART1=y
#
# Board extended module Drivers
#
CONFIG_BSP_USING_TEST=y
# CONFIG_BSP_USING_AT_ESP8266 is not set
# end of Board extended module Drivers
# end of Hardware Drivers Config

View File

@ -1,4 +1,5 @@
# Day 3 IPC机制
同步是指按预定的先后次序进行运行
![alt text](image-3.png)
![alt text](image.png)
1. √
@ -11,18 +12,15 @@ only one can use the resource at a time
## 阻塞非阻塞
Blocking/Non-blocking
线程/资源都有
![alt text](image-1.png)
阻塞: 等待,一个线程
非阻塞: 不等待
线程阻塞:资源被其它线程占用
阻塞式线程:只能执行当前任务并等待其完成
非阻塞式线程:执行当前任务,还可以做其它事情,完成时收到异步通知
## 挂起
<!-- ## 同步
一个线程在等待另一个线程
## 异步
一个线程在等待另一个线程,另一个线程在等待另一个线程 -->
暂时搁置
> 当信号量实例数目为零时,再申请该信号量的线程就会被挂起在该信号量的等待队列上,等待可用的信号量实例(资源)。
把寄存器,线程栈里面的东西保存下来
## 死锁
两个线程互相等待,需要对方的资源
@ -32,37 +30,49 @@ Blocking/Non-blocking
## 信号量
约等于停车场剩余车位
用于线程间同步、互斥
- 二值信号量 约等于bool 获得1不得0
![alt text](image-4.png)
- 计数信号量 初始为期待的值???
- ![alt text](image-5.png)
- 裸机 根据全局变量flag 反应(错误、破坏、不能挂起一直停在这……???)
- 有线程释放,信号量+1有线程获得信号量-1
- 二值信号量 约等于bool 初始为0解决同步问题
- 计数信号量 初始为期待的值(允许同时访问同一资源的任务个数),用于解决资源计数问题
- 裸机 根据全局变量flag 反应(不知道谁修改→错误、逻辑混乱、破坏、不能挂起一直停在这……)
- 用系统的api不要flag
- 三种反应:一直等,等一会,不等
api
信号量控制块由结构体 struct rt_semaphore 表示。另外一种 C 表达方式 rt_sem_t
``` c
static rt_sem_t dynamic_sem = RT_NULL;
```
**api**
### √ 创建信号量(动态)节省资源,动态分配,可能内存破坏
从对象管理器中分配一个semaphore对象……
当信号量不可用时的线程排队方式flag:RT_IPC_FLAG_FIFO先进先出/RT_IPC_FLAG_PRIO优先级
注意区别?
``` c
rt_sem_t rt_sem_create(const char* name, rt_uint32_t value, rt_uint8_t flag);
// flag:RT_IPC_FLAG_FIFO先进先出/RT_IPC_FLAG_PRIO优先级
```
### √ 删除信号量
### √ 删除信号量(动态)
(适用于动态创建的信号量)
删除信号量以释放系统资源。如果删除该信号量时,有线程正在等待该信号量,那么删除操作会先唤醒等待在该信号量上的线程(等待线程的返回值是 - RT_ERROR然后再释放信号量的内存资源
``` c
rt_err_t rt_sem_delete(rt_sem_t sem);
```
### 初始化信号量(静态)还在内存,别人也用不了
### 初始化信号量(静态)还在内存,不用了别人也用不了
``` c
rt_err_t rt_sem_init(rt_sem_t sem, const char* name, rt_uint32_t value, rt_uint8_t flag);
```
### 脱离信号量
从内核对象管理器中脱离
从内核对象管理器中脱离 ,原来挂起在信号量上的等待线程将获得 - RT_ERROR 的返回值
``` c
rt_err_t rt_sem_detach(rt_sem_t sem);
```
### 获取信号量
time 单位tick
time 单位tick/RT_WAITING_FOREVER
RT_EOK:成功获得信号量
-RT_ETIMEOUT:超时依然未获得信号量
-RT_ERROR:其他错误
``` c
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time);
```
![alt text](image-6.png)
### 无等待获取信号量
``` c

52
Day4/README.md Normal file
View File

@ -0,0 +1,52 @@
### I/O框架
显示屏、串口通信、flash、SD卡、以太网接口
open,close...
### 派生设备种类
![alt text](image.png)
### 字符设备、块设备
#### 字符设备
顺序读取:键盘、串口
#### 块设备
随机读取硬盘、SD卡、NAND FLASH
### 为什么分类设备
一类的控制相同
### 例子
RT_D
##
### 创建销毁设备
### 注册销毁
### flags
分行?
### 实验1注册
### 访问
### 查找、初始化
### 打开、关闭
### 打开标志位
### 控制设备
### 读写设备
### 回调
### 调用关系图
IO设备管理层
PIN设备驱动框架层
PIN设备驱动层
## GPIO
引脚电源、时钟、控制、I/O
GPIO,功能复用I/O
可编程控制中断
![alt text](image-1.png)
rt_pin_mode()
rt_pin_write()
rt_pin_read()
![alt text](image-2.png)
### 外部中断
## I2C总线

19
Day4/SConscript Normal file
View File

@ -0,0 +1,19 @@
from building import *
import os
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
src += ['arduino_main.cpp']
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')

BIN
Day4/image-1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
Day4/image-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

BIN
Day4/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

56
Day4/pin_irq_example.c Normal file
View File

@ -0,0 +1,56 @@
#include <drv_gpio.h>
#include <rtdevice.h>
#include <rtthread.h>
#define LOG_TAG "pin.irq"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#define KEY_UP GET_PIN(C, 5)
#define KEY_DOWN GET_PIN(C, 1)
#define KEY_LEFT GET_PIN(C, 0)
#define KEY_RIGHT GET_PIN(C, 4)
void key_up_callback(void *args)
{
int value = rt_pin_read(KEY_UP);
LOG_I("key up value: %d\n", value);
}
void key_down_callback(void *args)
{
int value = rt_pin_read(KEY_DOWN);
LOG_I("key down value: %d\n", value);
}
void key_left_callback(void *args)
{
int value = rt_pin_read(KEY_LEFT);
LOG_I("key left value: %d\n", value);
}
void key_right_callback(void *args)
{
int value = rt_pin_read(KEY_RIGHT);
LOG_I("key right value: %d\n", value);
}
static int rt_pin_irq_example(void)
{
rt_pin_mode(KEY_UP, PIN_MODE_INPUT_PULLUP);
rt_pin_mode(KEY_DOWN, PIN_MODE_INPUT_PULLUP);
rt_pin_mode(KEY_LEFT, PIN_MODE_INPUT_PULLUP);
rt_pin_mode(KEY_RIGHT, PIN_MODE_INPUT_PULLUP);
rt_pin_attach_irq(KEY_UP, PIN_IRQ_MODE_FALLING, key_up_callback, RT_NULL);
rt_pin_attach_irq(KEY_DOWN, PIN_IRQ_MODE_FALLING, key_down_callback, RT_NULL);
rt_pin_attach_irq(KEY_LEFT, PIN_IRQ_MODE_FALLING, key_left_callback, RT_NULL);
rt_pin_attach_irq(KEY_RIGHT, PIN_IRQ_MODE_FALLING, key_right_callback, RT_NULL);
rt_pin_irq_enable(KEY_UP,PIN_IRQ_ENABLE);
rt_pin_irq_enable(KEY_DOWN,PIN_IRQ_ENABLE);
rt_pin_irq_enable(KEY_LEFT,PIN_IRQ_ENABLE);
rt_pin_irq_enable(KEY_RIGHT,PIN_IRQ_ENABLE);
return RT_EOK;
}
MSH_CMD_EXPORT_ALIAS(rt_pin_irq_example,irq, pin_irq_example);

18
Day4/test_drv_example.c Normal file
View File

@ -0,0 +1,18 @@
#include <rtthread.h>
#include <rtdevice.h>
static int rt_device_test_init(void)
{
rt_device_t test_dev = rt_device_create(RT_Device_Class_Char,0);
if(!test_dev)
{
rt_kprintf("test_dev create failed\n");
return -RT_ERROR;
}
if(rt_device_register(test_dev,"test_dev",RT_DEVICE_FLAG_RDWR)!=RT_EOK)
{
rt_kprintf("test_dev register failed\n");
}
return RT_EOK;
}
MSH_CMD_EXPORT_ALIAS(rt_device_test_init,devtest, test device init);

View File

@ -2,7 +2,10 @@ from building import *
import os
cwd = GetCurrentDir()
src = Glob('*.c')
# src = Glob('*.c')
src = [
'main.c',
]
CPPPATH = [cwd]
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):

View File

@ -0,0 +1,85 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <icm20608.h>
#define LOG_TAG "icm.app"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
static void icm_thread_entry(void *parameter)
{
icm20608_device_t dev = RT_NULL;
const char *i2c_bus_name = "i2c2";
int count = 0;
rt_err_t result;
/* 初始化 icm20608 传感器 */
dev = icm20608_init(i2c_bus_name);
if (dev == RT_NULL)
{
LOG_E("The sensor initializes failure");
}
else
{
LOG_D("The sensor initializes success");
}
/* 对 icm20608 进行零值校准:采样 10 次,求取平均值作为零值 */
result = icm20608_calib_level(dev, 10);
if (result == RT_EOK)
{
LOG_D("The sensor calibrates success");
LOG_D("accel_offset: X%6d Y%6d Z%6d", dev->accel_offset.x, dev->accel_offset.y, dev->accel_offset.z);
LOG_D("gyro_offset : X%6d Y%6d Z%6d", dev->gyro_offset.x, dev->gyro_offset.y, dev->gyro_offset.z);
}
else
{
LOG_E("The sensor calibrates failure");
icm20608_deinit(dev);
}
while (count++ < 100)
{
rt_int16_t accel_x, accel_y, accel_z;
rt_int16_t gyros_x, gyros_y, gyros_z;
/* 读取三轴加速度 */
result = icm20608_get_accel(dev, &accel_x, &accel_y, &accel_z);
if (result == RT_EOK)
{
LOG_D("current accelerometer: accel_x%6d, accel_y%6d, accel_z%6d", accel_x, accel_y, accel_z);
}
else
{
LOG_E("The sensor does not work");
}
/* 读取三轴陀螺仪 */
result = icm20608_get_gyro(dev, &gyros_x, &gyros_y, &gyros_z);
if (result == RT_EOK)
{
LOG_D("current gyroscope : gyros_x%6d, gyros_y%6d, gyros_z%6d", gyros_x, gyros_y, gyros_z);
}
else
{
LOG_E("The sensor does not work");
break;
}
rt_thread_mdelay(1000);
}
}
static int icm_app(void)
{
rt_thread_t res = rt_thread_create("icm", icm_thread_entry, RT_NULL, 1024, 20, 50);
if(res == RT_NULL)
{
return -RT_ERROR;
}
rt_thread_startup(res);
return RT_EOK;
}
MSH_CMD_EXPORT(icm_app, icm_app);

View File

@ -0,0 +1,31 @@
//未完成
#include <rtthread.h>
#include <rtdevice.h>
#include <drv_spi.h>
#include <drv_gpio.h>
static int spi_attach(void)
{
return rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(B,12));
}
// INIT_DEVICE_EXPORT(spi_attach);
static int spi_transfer_one_data(void)
{
rt_err_t ret =RT_EOK;
struct rt_spi_device *spi_d20 = (struct rt_spi_device *)rt_device_find("spi20");
struct rt_spi_configuration cfg;
cfg.data_width = 8;
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB;
cfg.max_hz =1 *1000 *1000;
rt_spi_configure(spi20,&cfg);
rt_uint8_t sendBuff = 0xDA;
rt_uint8_t recvBuff = 0xF1;
ret =rt_spi_transfer(spi20,&sendBuff,&recvBuff,1);
rt_kprintf("sret = %d\n",ret);
}
MSH_CMD_EXPORT(spi_transfer_one_data, spi transfer one data);

View File

@ -0,0 +1,19 @@
#include <rtthread.h>
#include <rtdevice.h>
#define LOG_TAG "drv.test"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
static int dev_test_app(void)
[
rt_device_t test_dev = rt_device_find("test_dev");
if(test_dev == RT_NULL)
{
LOG_E("Cannot find test_dev");
return -RT_ERROR;
}
rt_device_open(test_dev, RT_DEVICE_OFLAG_RDWR);
rt_device_close(test_dev);
]

View File

@ -727,6 +727,10 @@ endmenu
menu "Board extended module Drivers"
config BSP_USING_TEST
bool "Enable test driver"
default n
menuconfig BSP_USING_AT_ESP8266
bool "Enable ESP8266(AT Command, COM3)"
default n

View File

@ -122,6 +122,9 @@ if GetDepend(['BSP_USING_PULSE_ENCODER']):
if GetDepend(['BSP_USING_USBH']):
src += ['drv_usbh.c']
if GetDepend(['BSP_USING_TEST']):
src += ['drv_test.c']
path += [os.path.join(cwd, 'config')]
if GetDepend('BSP_USING_ON_CHIP_FLASH'):

View File

@ -0,0 +1,66 @@
#include <rtthread.h>
#include <rtdevice.h>
#if defined(BSP_USING_TEST)
#define DRV_DEBUG
#define LOG_TAG "drv.test"
#include <drv_log.h>
static rt_err_t dev_test_init(rt_device_t dev)
{
LOG_I("test dev init");
return RT_EOK;
}
static rt_err_t dev_test_open(rt_device_t dev,rt_uint16_t oflag)
{
LOG_I("test dev open flag = %d",oflag);
return RT_EOK;
}
static rt_err_t dev_test_close(rt_device_t dev)
{
LOG_I("test dev close");
return RT_EOK;
}
static rt_ssize_t dev_test_read(rt_device_t dev,rt_off_t pos,void *buffer,rt_size_t size)
{
LOG_I("test dev read pos = %d,size = %d",pos,size);
return RT_EOK;
}
static rt_ssize_t dev_test_write(rt_device_t dev,rt_off_t pos,const void *buffer,rt_size_t size)
{
LOG_I("test dev write pos = %d,size = %d",pos,size);
return RT_EOK;
}
static rt_err_t dev_test_control(rt_device_t dev,int cmd,void *args)
{
LOG_I("test dev control cmd %d",cmd);
return RT_EOK;
}
int rt_drv_test_init(void)
{
rt_device_t test_dev = rt_device_create(RT_Device_Class_Char,0);
if(!test_dev)
{
LOG_E("test dev create failed");
return -RT_ERROR;
}
test_dev->init = dev_test_init;
test_dev->open = dev_test_open;
test_dev->close = dev_test_close;
test_dev->read = dev_test_read;
test_dev->write = dev_test_write;
test_dev->control = dev_test_control;
if(rt_device_register(test_dev,"test_dev",RT_DEVICE_FLAG_RDWR) != RT_EOK)
{
LOG_E("test dev register failed");
return -RT_ERROR;
}
return RT_EOK;
}
INIT_BOARD_EXPORT(rt_drv_test_init);
#endif

View File

@ -89,6 +89,9 @@
#define RT_USING_DEVICE_IPC
#define RT_UNAMED_PIPE_NUMBER 64
#define RT_USING_SYSTEM_WORKQUEUE
#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
#define RT_USING_SERIAL
#define RT_USING_SERIAL_V1
#define RT_SERIAL_USING_DMA
@ -96,6 +99,37 @@
#define RT_USING_I2C
#define RT_USING_I2C_BITOPS
#define RT_USING_PWM
#define RT_USING_SPI
#define RT_USING_SFUD
#define RT_SFUD_USING_SFDP
#define RT_SFUD_USING_FLASH_INFO_TABLE
#define RT_SFUD_SPI_MAX_HZ 50000000
#define RT_USING_WIFI
#define RT_WLAN_DEVICE_STA_NAME "wlan0"
#define RT_WLAN_DEVICE_AP_NAME "wlan1"
#define RT_WLAN_SSID_MAX_LENGTH 32
#define RT_WLAN_PASSWORD_MAX_LENGTH 32
#define RT_WLAN_DEV_EVENT_NUM 2
#define RT_WLAN_MANAGE_ENABLE
#define RT_WLAN_SCAN_WAIT_MS 10000
#define RT_WLAN_CONNECT_WAIT_MS 10000
#define RT_WLAN_SCAN_SORT
#define RT_WLAN_MSH_CMD_ENABLE
#define RT_WLAN_JOIN_SCAN_BY_MGNT
#define RT_WLAN_AUTO_CONNECT_ENABLE
#define AUTO_CONNECTION_PERIOD_MS 2000
#define RT_WLAN_CFG_ENABLE
#define RT_WLAN_CFG_INFO_MAX 3
#define RT_WLAN_PROT_ENABLE
#define RT_WLAN_PROT_NAME_LEN 8
#define RT_WLAN_PROT_MAX 2
#define RT_WLAN_DEFAULT_PROT "lwip"
#define RT_WLAN_PROT_LWIP_ENABLE
#define RT_WLAN_PROT_LWIP_NAME "lwip"
#define RT_WLAN_WORK_THREAD_ENABLE
#define RT_WLAN_WORKQUEUE_THREAD_NAME "wlan"
#define RT_WLAN_WORKQUEUE_THREAD_SIZE 2048
#define RT_WLAN_WORKQUEUE_THREAD_PRIO 15
#define RT_USING_PIN
/* end of Device Drivers */
@ -126,6 +160,65 @@
/* Network */
#define RT_USING_SAL
#define SAL_INTERNET_CHECK
/* Docking with protocol stacks */
#define SAL_USING_LWIP
/* end of Docking with protocol stacks */
#define SAL_SOCKETS_NUM 16
#define RT_USING_NETDEV
#define NETDEV_USING_IFCONFIG
#define NETDEV_USING_PING
#define NETDEV_USING_NETSTAT
#define NETDEV_USING_AUTO_DEFAULT
#define NETDEV_IPV4 1
#define NETDEV_IPV6 0
#define RT_USING_LWIP
#define RT_USING_LWIP203
#define RT_USING_LWIP_VER_NUM 0x20003
#define RT_LWIP_MEM_ALIGNMENT 4
#define RT_LWIP_IGMP
#define RT_LWIP_ICMP
#define RT_LWIP_DNS
#define RT_LWIP_DHCP
#define IP_SOF_BROADCAST 1
#define IP_SOF_BROADCAST_RECV 1
/* Static IPv4 Address */
#define RT_LWIP_IPADDR "192.168.1.30"
#define RT_LWIP_GWADDR "192.168.1.1"
#define RT_LWIP_MSKADDR "255.255.255.0"
/* end of Static IPv4 Address */
#define RT_LWIP_UDP
#define RT_LWIP_TCP
#define RT_LWIP_RAW
#define RT_MEMP_NUM_NETCONN 8
#define RT_LWIP_PBUF_NUM 16
#define RT_LWIP_RAW_PCB_NUM 4
#define RT_LWIP_UDP_PCB_NUM 4
#define RT_LWIP_TCP_PCB_NUM 4
#define RT_LWIP_TCP_SEG_NUM 40
#define RT_LWIP_TCP_SND_BUF 8196
#define RT_LWIP_TCP_WND 8196
#define RT_LWIP_TCPTHREAD_PRIORITY 10
#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8
#define RT_LWIP_TCPTHREAD_STACKSIZE 1024
#define RT_LWIP_ETHTHREAD_PRIORITY 12
#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_NETIF_LINK_CALLBACK 1
#define RT_LWIP_NETIF_NAMESIZE 6
#define SO_REUSE 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_RCVBUF 1
#define LWIP_SO_LINGER 0
#define LWIP_NETIF_LOOPBACK 0
#define RT_LWIP_USING_PING
/* end of Network */
/* Memory protection */
@ -134,6 +227,20 @@
/* Utilities */
#define RT_USING_ULOG
#define ULOG_OUTPUT_LVL_D
#define ULOG_OUTPUT_LVL 7
#define ULOG_ASSERT_ENABLE
#define ULOG_LINE_BUF_SIZE 128
/* log format */
#define ULOG_USING_COLOR
#define ULOG_OUTPUT_TIME
#define ULOG_OUTPUT_LEVEL
#define ULOG_OUTPUT_TAG
/* end of log format */
#define ULOG_BACKEND_USING_CONSOLE
/* end of Utilities */
/* Using USB legacy version */
@ -155,6 +262,16 @@
/* Wiced WiFi */
/* end of Wiced WiFi */
#define PKG_USING_RW007
#define PKG_USING_RW007_V210
#define RW007_USING_STM32_DRIVERS
#define RW007_SPI_MAX_HZ 30000000
#define RW007_SPI_BUS_NAME "spi2"
#define RW007_CS_PIN 102
#define RW007_BOOT0_PIN 175
#define RW007_BOOT1_PIN 102
#define RW007_INT_BUSY_PIN 62
#define RW007_RST_PIN 187
/* CYW43012 WiFi */
@ -279,6 +396,8 @@
/* entertainment: terminal games and other interesting software packages */
/* end of entertainment: terminal games and other interesting software packages */
#define PKG_USING_FLEXIBLE_BUTTON
#define PKG_USING_FLEXIBLE_BUTTON_V100
/* end of miscellaneous packages */
/* Arduino libraries */
@ -334,6 +453,8 @@
/* Onboard Peripheral Drivers */
#define BSP_USING_USB_TO_USART
#define BSP_USING_SPI_FLASH
#define BSP_USING_RW007_WLAN
/* end of Onboard Peripheral Drivers */
/* On-chip Peripheral Drivers */
@ -341,10 +462,13 @@
#define BSP_USING_GPIO
#define BSP_USING_UART
#define BSP_USING_UART1
#define BSP_USING_SPI
#define BSP_USING_SPI2
/* end of On-chip Peripheral Drivers */
/* Board extended module Drivers */
#define BSP_USING_TEST
/* end of Board extended module Drivers */
/* end of Hardware Drivers Config */