first submission

This commit is contained in:
qiyongshuang
2023-02-01 14:19:13 +08:00
parent d534aad004
commit b79c6ac80d
3711 changed files with 745432 additions and 2 deletions
@@ -0,0 +1,37 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_conf.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : Library configuration file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_CONF_H
#define __CH32V20x_CONF_H
#include "ch32v20x_adc.h"
#include "ch32v20x_bkp.h"
#include "ch32v20x_can.h"
#include "ch32v20x_crc.h"
#include "ch32v20x_dbgmcu.h"
#include "ch32v20x_dma.h"
#include "ch32v20x_exti.h"
#include "ch32v20x_flash.h"
#include "ch32v20x_gpio.h"
#include "ch32v20x_i2c.h"
#include "ch32v20x_iwdg.h"
#include "ch32v20x_pwr.h"
#include "ch32v20x_rcc.h"
#include "ch32v20x_rtc.h"
#include "ch32v20x_spi.h"
#include "ch32v20x_tim.h"
#include "ch32v20x_usart.h"
#include "ch32v20x_wwdg.h"
#include "ch32v20x_it.h"
#include "ch32v20x_misc.h"
#endif /* __CH32V20x_CONF_H */
@@ -0,0 +1,18 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_it.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : This file contains the headers of the interrupt handlers.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_IT_H
#define __CH32V20x_IT_H
#include "debug.h"
#endif /* __CH32V20x_IT_H */
@@ -0,0 +1,72 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_adapter_blemesh_mac.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/20
* Description : lwns适配器,模拟ble sig mesh的mac协议
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_ADAPTER_BLEMESH_MAC_H_
#define _LWNS_ADAPTER_BLEMESH_MAC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "lwns_config.h"
#define LWNS_USE_BLEMESH_MAC 1 //是否使能模仿blemesh的mac协议,注意只能使能一个mac层协议。
#if LWNS_USE_BLEMESH_MAC
struct blemesh_mac_phy_manage_struct
{
struct blemesh_mac_phy_manage_struct *next;
uint8_t *data;
}; //模仿blemesh mac层发送管理结构体
#define LWNS_MAC_TRANSMIT_TIMES 2 //一次发送,调用硬件发送几次
#define LWNS_MAC_PERIOD_MS 10 //mac接收周期,轮流切换
#define LWNS_MAC_SEND_DELAY_MAX_MS 10 //蓝牙mesh就是10ms以内的随机数。
#define LWNS_MAC_SEND_PACKET_MAX_NUM 8 //发送链表最多支持几个数据包等待发送
#define BLE_PHY_ONE_PACKET_MAX_625US 5 //ble mac发送一个包最大可能需要的周期
#define LLE_MODE_ORIGINAL_RX (0x80) //如果配置LLEMODE时加上此宏,则接收第一字节为原始数据(原来为RSSI)
#define LWNS_HTIMER_PERIOD_MS 20 //为(1000/HTIMER_SECOND_NUM)
//RF_TX和RF_RX所用的类型,可以修改,不推荐改
#define USER_RF_RX_TX_TYPE 0xff
#define LWNS_PHY_OUTPUT_TIMEOUT_MS 5
//receive process evt
#define LWNS_PHY_RX_OPEN_EVT 1
#define LWNS_PHY_RX_CHANGE_CHANNEL_EVT 2
//send process evt
#define LWNS_HTIMER_PERIOD_EVT 1
#define LWNS_PHY_OUTPUT_PREPARE_EVT 2
#define LWNS_PHY_OUTPUT_FINISH_EVT 4
extern void RF_Init(void);
extern void lwns_init(void);
extern void lwns_shut(void);
extern void lwns_start(void);
#ifdef __cplusplus
}
#endif
#endif /* LWNS_USE_BLEMESH_MAC */
#endif /* _LWNS_ADAPTER_BLEMESH_MAC_H_ */
@@ -0,0 +1,78 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_adapter_csma_mac.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/20
* Description : lwns适配器,模拟csma的mac协议
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_ADAPTER_CSMA_MAC_H_
#define _LWNS_ADAPTER_CSMA_MAC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "lwns_config.h"
#define LWNS_USE_CSMA_MAC 0 //是否使能模仿csma的mac协议,注意只能使能一个mac层协议。
#if LWNS_USE_CSMA_MAC
struct csma_mac_phy_manage_struct
{
struct csma_mac_phy_manage_struct *next;
uint8_t *data;
}; //模拟csma mac层发送管理结构体
typedef enum
{
BLE_PHY_MANAGE_STATE_FREE = 0,
BLE_PHY_MANAGE_STATE_RECEIVED,
BLE_PHY_MANAGE_STATE_WAIT_SEND,
BLE_PHY_MANAGE_STATE_SENDING,
} BLE_PHY_MANAGE_STATE_t;
#define LWNS_MAC_TRANSMIT_TIMES 2 //一次发送,调用硬件发送几次
#define LWNS_MAC_PERIOD_MS 20 //mac发送接收检测周期,如果有需要发送的数据包,则开始随机延迟检测冲突。//为(1000/HTIMER_SECOND_NUM)
#define LWNS_MAC_SEND_DELAY_MAX_625US LWNS_NEIGHBOR_MAX_NUM //随机延迟,该值越小,越容易出现错误,推荐大一些,8测试概率还可以。
#define BLE_PHY_ONE_PACKET_MAX_625US 5
#define LWNS_MAC_SEND_PACKET_MAX_NUM 8 //发送链表最多支持几个数据包等待发送
#define LWNS_MAC_SEND_DELAY_MAX_TIMES LWNS_NEIGHBOR_MAX_NUM / 2 //在发送被取消,延迟几次后,不再随机等待,立刻发送
#define LLE_MODE_ORIGINAL_RX (0x80) //如果配置LLEMODE时加上此宏,则接收第一字节为原始数据(原来为RSSI)
//RF_TX和RF_RX所用的类型,可以修改,不推荐改
#define USER_RF_RX_TX_TYPE 0xff
#define LWNS_PHY_OUTPUT_TIMEOUT_MS 5
//receive process evt
#define LWNS_PHY_RX_OPEN_EVT 1
//send process evt
#define LWNS_PHY_PERIOD_EVT 1
#define LWNS_PHY_OUTPUT_EVT 2
#define LWNS_PHY_OUTPUT_FINISH_EVT 4
extern void RF_Init(void);
extern void lwns_init(void);
extern void lwns_shut(void);
extern void lwns_start(void);
#endif /* LWNS_USE_CSMA_MAC */
#ifdef __cplusplus
}
#endif
#endif /* _LWNS_ADAPTER_CSMA_MAC_H_ */
@@ -0,0 +1,60 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_adapter_no_mac.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/20
* Description : lwns适配器,不使用mac协议,纯透传
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_ADAPTER_NO_MAC_H_
#define _LWNS_ADAPTER_NO_MAC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "lwns_config.h"
#define LWNS_USE_NO_MAC 0 //是否使能纯透传mac协议,适合不存在并发情况的星型网络,即主机问从机答的星型网络。
#if LWNS_USE_NO_MAC
typedef enum
{
BLE_PHY_MANAGE_STATE_FREE = 0,
BLE_PHY_MANAGE_STATE_SENDING,
} BLE_PHY_MANAGE_STATE_t;
#define LLE_MODE_ORIGINAL_RX (0x80) //如果配置LLEMODE时加上此宏,则接收第一字节为原始数据(原来为RSSI)
#define LWNS_HTIMER_PERIOD_MS 20 //为(1000/HTIMER_SECOND_NUM)
//RF_TX和RF_RX所用的类型,可以修改,不推荐改
#define USER_RF_RX_TX_TYPE 0xff
#define LWNS_PHY_OUTPUT_TIMEOUT_MS 5
//receive process evt
#define LWNS_PHY_RX_OPEN_EVT 1
//send process evt
#define LWNS_HTIMER_PERIOD_EVT 1
#define LWNS_PHY_OUTPUT_FINISH_EVT 2
extern void RF_Init(void);
extern void lwns_init(void);
extern void lwns_shut(void);
extern void lwns_start(void);
#endif /* LWNS_USE_NO_MAC */
#ifdef __cplusplus
}
#endif
#endif /* _LWNS_ADAPTER_NO_MAC_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_broadcast_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/20
* Description : broadcast£¬¹ã²¥³ÌÐòÀý×Ó
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_BROADCAST_EXAMPLE_H_
#define _LWNS_BROADCAST_EXAMPLE_H_
#include "lwns_config.h"
#define BROADCAST_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_broadcast_process_init(void);
#endif /* LWNS_BROADCAST_EXAMPLE_H_ */
@@ -0,0 +1,28 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_config.h
* Author : WCH
* Version : V1.0
* Date : 2021/11/17
* Description : lwns配置选项
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_CONFIG_H_
#define _LWNS_CONFIG_H_
#include "config.h"
#include "WCH_LWNS_LIB.h"
#define LWNS_ADDR_USE_BLE_MAC 1 //是否使用蓝牙硬件的mac地址作为默认lwns地址
#define LWNS_ENCRYPT_ENABLE 1 //是否使能加密
#define QBUF_MANUAL_NUM 4 //qbuf缓存数量配置
#define ROUTE_ENTRY_MANUAL_NUM 32 //路由条目数量配置
#define LWNS_NEIGHBOR_MAX_NUM 8 //最大邻居数量
#endif /* _LWNS_CONFIG_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_mesh_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/28
* Description : mesh´«Êä³ÌÐòÀý×Ó
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_MESH_EXAMPLE_H_
#define _LWNS_MESH_EXAMPLE_H_
#include "lwns_config.h"
#define MESH_EXAMPLE_TX_PERIOD_EVT 1 << (0)
#define MESH_EXAMPLE_TX_NODE_EVT 1 << (1)
void lwns_mesh_process_init(void);
#endif /* _LWNS_MESH_EXAMPLE_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_multicast_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/20
* Description : single-hop multicast£¬×é²¥´«ÊäÀý×Ó
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_MULTICAST_EXAMPLE_H_
#define _LWNS_MULTICAST_EXAMPLE_H_
#include "lwns_config.h"
#define MULTICAST_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_multicast_process_init(void);
#endif /* _LWNS_MULTICAST_EXAMPLE_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_multinetflood_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/11/10
* Description : multinetflood,组播网络泛洪传输例子
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_MULTINETFLOOD_EXAMPLE_H_
#define _LWNS_MULTINETFLOOD_EXAMPLE_H_
#include "lwns_config.h"
#define MULTINETFLOOD_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_multinetflood_process_init(void);
#endif /* _LWNS_MULTINETFLOOD_EXAMPLE_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_netflood_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/07/12
* Description : netflood£¬ÍøÂç·ººé´«ÊäÀý×Ó
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_NETFLOOD_EXAMPLE_H_
#define _LWNS_NETFLOOD_EXAMPLE_H_
#include "lwns_config.h"
#define NETFLOOD_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_netflood_process_init(void);
#endif /* _LWNS_NETFLOOD_EXAMPLE_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_ruc_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/30
* Description : reliable unicast£¬¿É¿¿µ¥²¥´«ÊäÀý×Ó
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_RUC_EXAMPLE_H_
#define _LWNS_RUC_EXAMPLE_H_
#include "lwns_config.h"
#define RUC_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_ruc_process_init(void);
#endif /* _LWNS_RUC_EXAMPLE_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_rucft_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/30
* Description : reliable unicast file transfer,可靠单播文件传输例子
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_RUCFT_EXAMPLE_H_
#define _LWNS_RUCFT_EXAMPLE_H_
#include "lwns_config.h"
#define RUCFT_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_rucft_process_init(void);
#endif /* _LWNS_RUCFT_EXAMPLE_H_ */
+21
View File
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_sec.h
* Author : WCH
* Version : V1.0
* Date : 2021/09/17
* Description : lwnsÏûÏ¢¼ÓÃÜ
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_SEC_H_
#define _LWNS_SEC_H_
#include "lwns_config.h"
int lwns_msg_encrypt(uint8_t *src, uint8_t *to, uint8_t mlen);
int lwns_msg_decrypt(uint8_t *src, uint8_t *to, uint8_t mlen);
#endif /* _LWNS_SEC_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_unicast_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/06/19
* Description : lwnsµ¥²¥´«ÊäÀý×Ó
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_UNICAST_EXAMPLE_H_
#define _LWNS_UNICAST_EXAMPLE_H_
#include "lwns_config.h"
#define UNICAST_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_unicast_process_init(void);
#endif /* _LWNS_UNICAST_EXAMPLE_H_ */
@@ -0,0 +1,21 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : lwns_uninetflood_example.h
* Author : WCH
* Version : V1.0
* Date : 2021/10/25
* Description : lwns单播网络泛洪传输例子,将数据网络泛洪发送至指定节点
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _LWNS_UNINETFLOOD_EXAMPLE_H_
#define _LWNS_UNINETFLOOD_EXAMPLE_H_
#include "lwns_config.h"
#define UNINETFLOOD_EXAMPLE_TX_PERIOD_EVT 1 << (0)
void lwns_uninetflood_process_init(void);
#endif /* _LWNS_UNINETFLOOD_EXAMPLE_H_ */
@@ -0,0 +1,31 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v20x.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : CH32V20x Device Peripheral Access Layer System Header File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __SYSTEM_ch32v20x_H
#define __SYSTEM_ch32v20x_H
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */
/* System_Exported_Functions */
extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif /*__CH32V20x_SYSTEM_H */