Merge branch 'xuos_prepare_for_master' into prepare_for_master

This commit is contained in:
Jeremy 2023-05-15 10:57:50 +08:00
commit 39c8ee354b
136 changed files with 10675 additions and 3635 deletions

7
.gitmodules vendored
View File

@ -22,3 +22,10 @@
[submodule "Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-riscv64/kendryte-sdk/kendryte-sdk-source"]
path = Ubiquitous/RT-Thread_Fusion_XiUOS/aiit_board/xidatong-riscv64/kendryte-sdk/kendryte-sdk-source
url = https://code.gitlink.org.cn/chunyexixiaoyu/kendryte-sdk-source.git
[submodule "APP_Framework/lib/lorawan/lora_radio_driver"]
path = APP_Framework/lib/lorawan/lora_radio_driver
url = https://gitlink.org.cn/IACU/lora_radio_driver.git
[submodule "APP_Framework/lib/lorawan/lorawan_devicenode"]
path = APP_Framework/lib/lorawan/lorawan_devicenode
url = https://gitlink.org.cn/IACU/lorawan_devicenode.git
branch = master

View File

@ -235,6 +235,10 @@ menu "test app"
default "/dev/qspi_W25Q128"
endif
endif
menuconfig USER_TEST_TIMER
bool "Config test soft timer"
default n
endif
endmenu

View File

@ -97,5 +97,9 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES += test_can.c
endif
ifeq ($(CONFIG_USER_TEST_TIMER),y)
SRC_FILES += test_timer.c
endif
include $(KERNEL_ROOT)/compiler.mk
endif

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: test_timer.c
* @brief: a application of soft timer function
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/03/09
*/
#include <transform.h>
void TimerFunction(union sigval sig_val)
{
static int cnt = 0;
printf("%s cnt %d\n", __func__, cnt++);
}
void TestTimer(void)
{
int ret = 0;
int timer_flags;
timer_t timer_id;
struct sigevent evp;
memset(&evp, 0, sizeof(struct sigevent));
timer_flags = TIMER_TRIGGER_PERIODIC;
evp.sigev_notify = SIGEV_THREAD;
evp.sigev_notify_function = TimerFunction;
evp.sigev_notify_attributes = &timer_flags;
ret = timer_create(CLOCK_REALTIME, &evp, &timer_id);
if (ret < 0) {
printf("%s create timer failed ret %d\n", __func__, ret);
return;
}
struct itimerspec value;
//active time interval
value.it_interval.tv_sec = 2;
value.it_interval.tv_nsec = 0;
//first timer set time
value.it_value.tv_sec = 2;
value.it_value.tv_nsec = 0;
ret = timer_settime(timer_id, 1, &value, NULL);
if (ret < 0) {
printf("%s set timer time failed ret %d\n", __func__, ret);
return;
}
printf("%s success\n", __func__);
}
PRIV_SHELL_CMD_FUNCTION(TestTimer, soft timer test, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -1,3 +1,3 @@
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,3 @@
SRC_FILES := br_x20cp0410.c br_x20cp1381.c br_x20cp1586.c
SRC_FILES := br_x20cp0410.c br_x20cp1381.c br_x20cp1586.c br_ppc2100.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,23 @@
# 贝加莱 PPC2100通信测试
[TOC]
## 通信接线及参数设置
* 网口
* 通过ETH1 RJ45 网口连接
* 网口参数IP192.168.250.26 Port502
* 测试的协议:Modbus TCP
## 存储区
- 贝加莱PLC与其他PLC不同没有明确类似MD等这样的存储区的概念Modbus地址取决于库函数中结构体变量索引。
## 通信测试
- 共测试BOOLINT16INT32FLOAT,DOUBLE 共五种类型数据。
- 测试BOOL型变量用功能码01测其他类型变量用功能码03。
-

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file br_ppc2100.c
* @brief PLC BR PPC2100 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.5.8
*/
#include <control.h>
extern int Adapter4GActive(void);
void ControlBrTest_PPC2100(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
#ifdef CONNECTION_ADAPTER_4G
Adapter4GActive();
#endif
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
if (NULL == modbus_tcp_protocol) {
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
return;
}
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
ControlProtocolOpen(modbus_tcp_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_tcp_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlBrTest_PPC2100, Delta ppc2100 Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -0,0 +1,93 @@
{
"device_id": 1,
"device_name": "BR_PPC2100",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.26",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.254.0",
"port": 502
},
"protocol_type": 2,
"read_period": 2000,
"read_item_list": [
{
"value_name": "motorrun",
"value_type": 1,
"function_code": 2,
"start_address": 0,
"quantity": 1
},
{
"value_name": "motorstop",
"value_type": 1,
"function_code": 2,
"start_address": 1,
"quantity": 1
},
{
"value_name": "valueopen",
"value_type": 1,
"function_code": 1,
"start_address": 100,
"quantity": 1
},
{
"value_name": "valueclose",
"value_type": 1,
"function_code": 1,
"start_address": 101,
"quantity": 1
},
{
"value_name": "step",
"value_type": 3,
"function_code": 4,
"start_address": 100,
"quantity": 1
},
{
"value_name": "temperature",
"value_type": 9,
"function_code": 4,
"start_address": 101,
"quantity": 2
},
{
"value_name": "status",
"value_type": 4,
"function_code": 4,
"start_address": 103,
"quantity": 2
},
{
"value_name": "mode",
"value_type": 3,
"function_code": 3,
"start_address": 200,
"quantity": 1
},
{
"value_name": "setTemperature",
"value_type": 9,
"function_code": 3,
"start_address": 201,
"quantity": 2
},
{
"value_name": "setConuter",
"value_type": 4,
"function_code": 3,
"start_address": 203,
"quantity": 2
},
{
"value_name": "LrealTest",
"value_type": 8,
"function_code": 3,
"start_address": 205,
"quantity": 4
}
]
}

View File

@ -0,0 +1,22 @@
# 台达 DVP通信测试
[TOC]
## 通信接线及参数设置
* 网口
* 通过自带 RJ45 网口连接
* 网口参数IP192.168.250.27 Port502
* 测试的协议:Modbus TCP
## 存储区
- 含MDXY。台达PLC中 各存储区地址和Modbus地址有明确的对应表详见台达DVP协议解析测试文档。
## 通信测试
- 共测试BOOLINT16INT32FLOAT 共四种类型数据。
- 测试D区M区和Y区。

View File

@ -0,0 +1,80 @@
{
"device_id": 1,
"device_name": "DELTA_DVP",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.27",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.254.0",
"port": 502
},
"protocol_type": 2,
"read_period": 2000,
"read_item_list": [
{
"value_name": "M20",
"value_type": 1,
"function_code": 1,
"start_address": 2068,
"quantity": 1
},
{
"value_name": "M100",
"value_type": 1,
"function_code": 1,
"start_address":2148,
"quantity": 1
},
{
"value_name": "Y10",
"value_type": 1,
"function_code": 1,
"start_address": 1288,
"quantity": 1
},
{
"value_name": "D200",
"value_type": 3,
"function_code": 3,
"start_address":4296,
"quantity": 1
},
{
"value_name": "D201",
"value_type": 3,
"function_code": 3,
"start_address": 4297,
"quantity": 1
},
{
"value_name": "D220",
"value_type": 4,
"function_code": 3,
"start_address": 4316,
"quantity": 2
},
{
"value_name": "D222",
"value_type": 4,
"function_code": 3,
"start_address": 4318,
"quantity": 2
},
{
"value_name": "D300",
"value_type": 9,
"function_code": 3,
"start_address": 4396,
"quantity": 2
},
{
"value_name": "D302",
"value_type": 9,
"function_code": 3,
"start_address": 4398,
"quantity": 2
}
]
}

View File

@ -1,3 +1,3 @@
SRC_FILES := ge_versamax001.c
SRC_FILES := ge_versamax001.c ge_cpe100.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,57 @@
---
typora-copy-images-to: upload
---
# 艾默生原GE 通信测试
[TOC]
## 小型VersaMAX CPU001测试
### 通信接线及参数设置
* 串口
* COM2为15孔D型 RS485。波特率19200数据位8位停止位1位校验偶校验。接线按下图典型双线接法。
![ge_versamax_serial](./img/ge_versamax_serial.png)
### 存储区
- 存储区 IQAIR区。其他内存区如MAQ不能直接访问要通过程序转换访问。
### 通信测试
- 共测试BOOLINT16FLOAT共三种类型数据。
- 测试R区及Q区数据。
- R区数据测试用功能码03以字为单位读取。配方中start_address字段为PLC地址直接减1。
- Q区数据测试用功能码01以位为单位读取。配方中start_address字段为PLC地址直接减1。
## 中型PLC CPE100通信测试
### 通信接线及参数设置
- 网口
- 网口RJ45参数 IP192.168.250.28 端口号502
### 存储区
- 存储区 IQAIR区。其他内存区如MAQ不能直接访问要通过程序转换访问。
### 通信测试
- 共测试BOOLINT16INT32FLOATDOUBLE共五种类型数据。
- 测试R区及Q区数据。
- R区数据测试用功能码03以字为单位读取。配方中start_address字段为PLC地址直接减1。
- Q区数据测试用功能码01以位为单位读取。配方中start_address字段为PLC地址直接减1。

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file ge_cpe100.c
* @brief PLC GE Versamax app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.9.27
*/
#include <control.h>
extern int Adapter4GActive(void);
void ControlGecpe100Test(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
#ifdef CONNECTION_ADAPTER_4G
Adapter4GActive();
#endif
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
if (NULL == modbus_tcp_protocol) {
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
return;
}
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
ControlProtocolOpen(modbus_tcp_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_tcp_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlGecpe100Test, ge cpe100 Demo, PRIV_SHELL_CMD_MAIN_ATTR);

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

View File

@ -0,0 +1,73 @@
{
"device_id": 1,
"device_name": "GE_CPE100_TCP",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.28",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.254.0",
"port": 502
},
"protocol_type": 2,
"read_period": 2000,
"read_item_list": [
{
"value_name": "Q001",
"value_type": 1,
"function_code": 1,
"start_address": 0,
"quantity": 1
},
{
"value_name": "Q010",
"value_type": 1,
"function_code": 1,
"start_address":9,
"quantity": 1
},
{
"value_name": "Q066",
"value_type": 1,
"function_code": 1,
"start_address": 65,
"quantity": 1
},
{
"value_name": "Q100",
"value_type": 1,
"function_code": 1,
"start_address":99,
"quantity": 1
},
{
"value_name": "R11",
"value_type": 3,
"function_code": 3,
"start_address": 10,
"quantity": 1
},
{
"value_name": "R12",
"value_type": 9,
"function_code": 3,
"start_address": 11,
"quantity": 2
},
{
"value_name": "R14",
"value_type": 8,
"function_code": 3,
"start_address": 13,
"quantity": 4
},
{
"value_name": "R18",
"value_type": 4,
"function_code": 3,
"start_address": 17,
"quantity": 2
}
]
}

View File

@ -0,0 +1,58 @@
{
"device_id": 1,
"device_name": "GE_VersaMAX_RTU",
"communication_type": 1,
"serial_config": {
"station": 1,
"baud_rate": 19200,
"data_bits": 8,
"stop_bits": 1,
"check_mode": 2
},
"protocol_type": 3,
"read_period": 2000,
"read_item_list": [
{
"value_name": "Q001",
"value_type": 1,
"function_code": 1,
"start_address": 0,
"quantity": 1
},
{
"value_name": "Q010",
"value_type": 1,
"function_code": 1,
"start_address": 9,
"quantity": 1
},
{
"value_name": "Q066",
"value_type": 1,
"function_code": 1,
"start_address": 65,
"quantity": 1
},
{
"value_name": "Q100",
"value_type": 1,
"function_code": 1,
"start_address": 99,
"quantity": 1
},
{
"value_name": "R11",
"value_type": 3,
"function_code": 3,
"start_address": 10,
"quantity": 1
},
{
"value_name": "R12",
"value_type": 9,
"function_code": 3,
"start_address": 11,
"quantity": 2
}
]
}

View File

@ -0,0 +1,3 @@
SRC_FILES := inovance_am401_cpu1608tn_ethernet.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,26 @@
# INOVANCE AM4011608TN通信测试
[TOC]
## 通信接线及参数设置
* 网口
* CN3 EtherNET,Mosbus TCP协议IP192.168.250.50Port502
* 串口
* CN1 RS485AM401只支持一路串口AM600可支持两路串口。AM401接线pin1:485-pin2:485+。波特率9600数据位8位停止位1位校验偶校验
## 存储区
- 存储区 IQM区。
## 通信测试
1共测试BOOLINT16INT32FLOAT共四种类型数据。
2测试M区及Q区数据。
3M区数据测试用功能码03以字为单位读取。如读MX0.3,则读取MW0然后按位拆解。如读MW100则配方文件中起始地址则直接写100即可。如读MDx则配方文件中起始地址应为2*x这是汇川的地址编码规则决定如MD200则对应400。
4Q区数据测试用功能码01以位为单位读取。如读QX.Y则配方文件中起始地址为X*8+Y如读QWQD等则需按位进行读取后然后组合得到。

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file inovance_am401_cpu1608tn_ethernet.c
* @brief PLC inovance am401 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.4.25
*/
#include <control.h>
extern int Adapter4GActive(void);
void ControlInovanceam401EthernetTest(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
#ifdef CONNECTION_ADAPTER_4G
Adapter4GActive();
#endif
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
if (NULL == modbus_tcp_protocol) {
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
return;
}
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
ControlProtocolOpen(modbus_tcp_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_tcp_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlInovanceam401EthernetTest, inovance am401 ethernet Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -0,0 +1,80 @@
{
"device_id": 1,
"device_name": "INOVANCE_AM401_TCP",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.50",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.254.0",
"port": 502
},
"protocol_type": 2,
"read_period": 2000,
"read_item_list": [
{
"value_name": "q00",
"value_type": 1,
"function_code": 1,
"start_address": 0,
"quantity": 1
},
{
"value_name": "q01",
"value_type": 1,
"function_code": 1,
"start_address":1,
"quantity": 1
},
{
"value_name": "q10",
"value_type": 1,
"function_code": 1,
"start_address": 8,
"quantity": 1
},
{
"value_name": "mw100",
"value_type": 3,
"function_code": 3,
"start_address": 100,
"quantity": 1
},
{
"value_name": "mw101",
"value_type": 3,
"function_code": 3,
"start_address": 101,
"quantity": 1
},
{
"value_name": "md200",
"value_type": 4,
"function_code": 3,
"start_address": 400,
"quantity": 2
},
{
"value_name": "md201",
"value_type": 4,
"function_code": 3,
"start_address": 402,
"quantity": 2
},
{
"value_name": "md300",
"value_type": 9,
"function_code": 3,
"start_address": 600,
"quantity": 2
},
{
"value_name": "md301",
"value_type": 9,
"function_code": 3,
"start_address": 602,
"quantity": 2
}
]
}

View File

@ -0,0 +1,24 @@
# 三菱 FX2N通信测试
[TOC]
## 通信接线及参数设置
* 串口
* FX2N自带8针圆口422用于程序的下载。全系列不支持网口且需购买串口拓展模块FX2N-485-BD用于通信测试。
* 接线RDA和SDA短接引出ARDB与SDB短接引出B。
* 串口模块支持MC-1C协议通信速率9600数据位7bit停止位1bit校验偶校验
## 存储区
- 存储区 IQMD区。
## 通信测试
- 共测试BOOLINT16FLOAT共三种类型数据。
- 测试M区及D区数据。

View File

@ -0,0 +1,331 @@
{
"device_id": 769,
"device_name": "S01",
"communication_type": 1,
"serial_config": {
"station": 1,
"baud_rate": 9600,
"data_bits": 7,
"stop_bits": 1,
"check_mode": 3
},
"protocol_type": 9,
"read_period": 1000,
"read_item_list": [
{
"value_name": "启动",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "0",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "停止",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "1",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "使能",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "2",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "回零",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "3",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "急停",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "4",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "正限位",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "5",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "负限位",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "6",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "自动运行中",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "20",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "故障",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "21",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "待机",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "22",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "手动模式",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "23",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "自动模式",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "24",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "运行方向",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "25",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "复位",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "26",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "备用1",
"value_type": 1,
"device_code": "M",
"head_device_number_string": "27",
"device_points_count": 1,
"command_type": 0,
"monitoring_timer": 100
},
{
"value_name": "产量",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "0",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型1",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "1",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型2",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "2",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型3",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "3",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型4",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "4",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型5",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "5",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型6",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "50",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型7",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "51",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型8",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "52",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "整型9",
"value_type": 3,
"device_code": "D",
"head_device_number_string": "53",
"device_points_count": 1,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "速度",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "200",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "加速度",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "202",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "减速度",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "204",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "起始位置",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "206",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "终点位置",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "208",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "张力值",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "300",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "浮点型1",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "302",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "浮点型2",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "304",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "浮点型3",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "306",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
},
{
"value_name": "浮点型4",
"value_type": 9,
"device_code": "D",
"head_device_number_string": "308",
"device_points_count": 2,
"command_type": 1,
"monitoring_timer": 100
}
]
}

View File

@ -0,0 +1,70 @@
# OMRON_CP1L通信测试
[TOC]
## 通信接线及参数设置
* 本体无接口增加CP1W-CIF41网络板卡
* FINS协议PLC IP192.168.250.31Port9600
## 存储区
- 存储区 WD区。
## JSON配方设计
* 共测试BOOLINT16共2种类型数据,以下为JSON文件解释。
- ```json
{
"device_id": 1, //设备ID默认是1此参数无效
"device_name": "CP1L", //设备名称,自定义
"communication_type": 0, //通讯协议类型 0是以太网1是串口
"socket_config": { //以太网配置
"plc_ip": "192.168.250.31", //PLC的IP地址
"local_ip": "192.168.250.233", //矽达通IP地址设定
"gateway": "192.168.250.1", //矽达通的网关地址设定
"netmask": "255.255.255.0", //矽达通子网掩码设定
"port": 9600 //端口号设定
},
"protocol_type": 5, //通讯协议5代表FINS协议
"read_period": 100, //交互周期ms
"read_item_list": [
{
"value_name": "停止", //变量名称,自定义
"value_type": 1, //变量类型BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9
"area_char": "W", //变量功能块
"data_type": 0, //数据传输类型BOOL = 0,WORD = 1
"start_address": 100, //起始地址
"bit_address": 1, //BOOL地址偏移位采集变量地址是W100.1
"data_length": 1 //BOOL长度默认是1代表读取1个BOOL长度
},
{
"value_name": "转速", //变量名称,自定义
"value_type": 3, //变量类型BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9
"area_char": "D", //变量功能块
"data_type": 1, //数据传输类型BOOL = 0,WORD = 1
"start_address": 101, //起始地址
"bit_address": 0, //以WORD采集方式时此参数无效采集变量地址是D101
"data_length": 1 //WORD长度默认是1代表读取1个WORD长度2个字节
}
]
}
```
## 通信测试
(1) 新增1个通信demo命名为omron_cp1l.c
(2) 复制样例代码程序到omron_cp1l.c文件中
(3) void **ControlOmronCP1LTest**(void) 更改函数名;
(4) PRIV_SHELL_CMD_FUNCTION(**ControlOmronCP1LTest**, **Omron Plc Cp1l Demo**, PRIV_SHELL_CMD_MAIN_ATTR);更改测试指令;
(5) 剪裁配置完成后,用过烧写器下载至矽达通中,重启后完成测试。

View File

@ -11,10 +11,39 @@
*/
/**
* @file omron_cj2m.c
* @brief PLC OMRON CJ2M app
* @file omron_cp1h.c
* @brief PLC OMRON CP1H app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.9.27
* @date 2023.4.1
*/
#include <control.h>
void ControlOmronCP1HTest(void)
{
int i = 0;
uint16_t read_data_length = 0;
uint8_t read_data[1024] = {0};
ControlProtocolType fins_protocol = ControlProtocolFind();
if (NULL == fins_protocol) {
printf("%s get fins protocol %p failed\n", __func__, fins_protocol);
return;
}
printf("%s get fins protocol %p successfull\n", __func__, fins_protocol);
if (CONTROL_REGISTERED == fins_protocol->protocol_status) {
ControlProtocolOpen(fins_protocol);
for (;;) {
read_data_length = ControlProtocolRead(fins_protocol, read_data, sizeof(read_data));
printf("%s read [%d] fins data %d using receipe file\n", __func__, i, read_data_length);
i++;
PrivTaskDelay(100000);
}
//ControlProtocolClose(fins_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlOmronCP1HTest, Omron Plc Cp1h Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -45,4 +45,4 @@ void ControlOmronCP1LTest(void)
//ControlProtocolClose(fins_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlOmronCP1LTest, Omron Plc FINS Demo, PRIV_SHELL_CMD_MAIN_ATTR);
PRIV_SHELL_CMD_FUNCTION(ControlOmronCP1LTest, Omron Plc Cp1l Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -18,6 +18,34 @@
* @date 2022.9.27
*/
#include <control.h>
void ControlOmronNX102Test(void)
{
int i = 0;
uint16_t read_data_length = 0;
uint8_t read_data[1024] = {0};
ControlProtocolType fins_protocol = ControlProtocolFind();
if (NULL == fins_protocol) {
printf("%s get fins protocol %p failed\n", __func__, fins_protocol);
return;
}
printf("%s get fins protocol %p successfull\n", __func__, fins_protocol);
if (CONTROL_REGISTERED == fins_protocol->protocol_status) {
ControlProtocolOpen(fins_protocol);
for (;;) {
read_data_length = ControlProtocolRead(fins_protocol, read_data, sizeof(read_data));
printf("%s read [%d] fins data %d using receipe file\n", __func__, i, read_data_length);
i++;
PrivTaskDelay(10000);
}
// ControlProtocolClose(fins_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlOmronNX102Test, Omron Plc FINS Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -0,0 +1,70 @@
{
"device_id": 1,
"device_name": "CP1H",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.46",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.255.0",
"port": 9600
},
"protocol_type": 5,
"read_period": 100,
"read_item_list": [
{
"value_name": "启动",
"value_type": 1,
"area_char": "W",
"data_type": 0,
"start_address": 10,
"bit_address": 0,
"data_length": 1
},
{
"value_name": "停止",
"value_type": 1,
"area_char": "W",
"data_type": 0,
"start_address": 10,
"bit_address": 1,
"data_length": 1
},
{
"value_name": "暂停",
"value_type": 1,
"area_char": "W",
"data_type": 0,
"start_address": 10,
"bit_address": 2,
"data_length": 1
},
{
"value_name": "整型1",
"value_type": 3,
"area_char": "D",
"data_type": 1,
"start_address": 100,
"bit_address": 0,
"data_length": 1
},
{
"value_name": "整型2",
"value_type": 3,
"area_char": "D",
"data_type": 1,
"start_address": 101,
"bit_address": 0,
"data_length": 1
},
{
"value_name": "浮点",
"value_type": 9,
"area_char": "D",
"data_type": 1,
"start_address": 110,
"bit_address": 0,
"data_length": 2
}
]
}

View File

@ -0,0 +1,52 @@
{
"device_id": 1,
"device_name": "CP1L",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.31",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.255.0",
"port": 9600
},
"protocol_type": 5,
"read_period": 100,
"read_item_list": [
{
"value_name": "启动",
"value_type": 1,
"area_char": "W",
"data_type": 0,
"start_address": 100,
"bit_address": 0,
"data_length": 1
},
{
"value_name": "停止",
"value_type": 1,
"area_char": "W",
"data_type": 0,
"start_address": 100,
"bit_address": 1,
"data_length": 1
},
{
"value_name": "转速",
"value_type": 3,
"area_char": "D",
"data_type": 1,
"start_address": 101,
"bit_address": 0,
"data_length": 1
},
{
"value_name": "产量",
"value_type": 3,
"area_char": "D",
"data_type": 1,
"start_address": 102,
"bit_address": 0,
"data_length": 1
}
]
}

View File

@ -19,9 +19,6 @@
*/
#include <control.h>
extern int Adapter4GActive(void);
void ControlM241Test(void)
{
int i, j = 0;

View File

@ -0,0 +1,79 @@
# SIEMENS - S7-1512通信测试
[TOC]
## 通信接线及参数设置
* 本体以太网口
* S7协议PLC IP192.168.250.2Port102
## 存储区
- 存储区 QDB区。
## JSON配方设计
* 共测试BOOLINT16共2种类型数据,以下为JSON文件解释。
- ```json
{
"device_id": 1, //设备ID默认是1此参数无效
"device_name": "S7-1512", //设备名称,自定义
"communication_type": 0, //通讯协议类型 0是以太网1是串口
"socket_config": { //以太网配置
"plc_ip": "192.168.250.2", //PLC的IP地址
"local_ip": "192.168.250.233", //矽达通IP地址设定
"gateway": "192.168.250.1", //矽达通的网关地址设定
"netmask": "255.255.255.0", //矽达通子网掩码设定
"port": 102 //端口号设定
},
"protocol_type": 1, //通讯协议5代表FINS协议
"read_period": 100, //交互周期ms
"read_item_list": [
{
"value_name": "布尔1", //变量名称,自定义
"value_type": 1, //变量类型BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9
"area": "Q", //变量功能块
"wordlen": "Bit", //变量字长类型,有Bit Byte Word DWord Real Counter Timer
"db_number": 1, //如为DB区填写对应的DB块编号,如不是DB区无效
"start": 1, //BOOL地址偏移位采集变量地址是Q0.1
"amount": 1 //BOOL长度默认是1代表读取1个BOOL长度
},
{
"value_name": "整型", //变量名称,自定义
"value_type": 3, //变量类型BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9
"area": "DB", //变量功能块
"wordlen": "Word", //变量字长类型,有Bit Byte Word DWord Real Counter Timer
"db_number": 18, //如为DB区即DB18块
"start": 2, //Word地址偏移位采集变量地址是DB18.DBW2
"amount": 1 //Word长度默认是1代表读取1个WORD长度2个字节
},
{
"value_name": "浮点数", //变量名称,自定义
"value_type": 9, //变量类型BOOL = 1,INT8 = 2,INT16,INT32,UINT8,UINT16,UINT32,DOUBLE,FLOAT = 9
"area": "DB", //变量功能块
"wordlen": "Real", //变量字长类型,有Bit Byte Word DWord Real Counter Timer
"db_number": 18, //如为DB区即DB18块
"start": 18, //Real地址偏移位采集变量地址是DB18.DBD18
"amount": 1 //Real长度默认是1代表读取1个Real长度4个字节
}
]
}
```
## 通信测试
(1) 新增1个通信demo命名为simens_s7_1500.c
(2) 复制样例代码程序到simens_s7_1500.c文件中
(3) void **ControlS71500Test**(void)更改函数名;
(4) PRIV_SHELL_CMD_FUNCTION(**ControlS71500Test, Siemens Plc S7_1512 Demo**, PRIV_SHELL_CMD_MAIN_ATTR);更改测试指令;
(5) 剪裁配置完成后,用过烧写器下载至矽达通中,重启后完成测试。

View File

@ -15,9 +15,6 @@
* @brief PLC SIEMENS S7-1200 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.9.27
* @date 2023.3.27
*/

View File

@ -15,9 +15,31 @@
* @brief PLC SIEMENS S7-1500 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.9.27
* @date 2023.3.27
*/
#include <control.h>
void ControlS71500Test(void)
{
int i = 0;
uint16_t read_data_length = 0;
uint8_t read_data[1024] = {0};
ControlProtocolType s7_protocol = ControlProtocolFind();
if (NULL == s7_protocol) {
printf("%s get s7 protocol %p failed\n", __func__, s7_protocol);
return;
}
printf("%s get s7 protocol %p successfull\n", __func__, s7_protocol);
if (CONTROL_REGISTERED == s7_protocol->protocol_status) {
ControlProtocolOpen(s7_protocol);
for (;;) {
read_data_length = ControlProtocolRead(s7_protocol, read_data, sizeof(read_data));
printf("%s read [%d] s7 data %d using receipe file\n", __func__, i, read_data_length);
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
}
}
PRIV_SHELL_CMD_FUNCTION(ControlS71500Test, Siemens Plc S7_1512 Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -11,13 +11,10 @@
*/
/**
* @file siemens_s7_200_smart.c
* @brief PLC SIEMENS S7-200 SMART app
* @file siemens_s7_200 smart.c
* @brief PLC SIEMENS S7-200 smart app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.9.27
* @date 2023.3.27
*/

View File

@ -15,9 +15,6 @@
* @brief PLC SIEMENS S7-300 app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022.9.27
* @date 2023.3.27
*/

View File

@ -0,0 +1,70 @@
{
"device_id": 1,
"device_name": "S7-1512",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.2",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.252",
"netmask": "255.255.255.0",
"port": 102
},
"protocol_type": 1,
"read_period": 100,
"read_item_list": [
{
"value_name": "布尔1",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 1,
"amount": 1
},
{
"value_name": "布尔2",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 2,
"amount": 1
},
{
"value_name": "布尔3",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 3,
"amount": 1
},
{
"value_name": "布尔4",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 4,
"amount": 1
},
{
"value_name": "整型",
"value_type": 3,
"area": "DB",
"wordlen": "Word",
"db_number": 18,
"start": 2,
"amount": 1
},
{
"value_name": "浮点数",
"value_type": 9,
"area": "DB",
"wordlen": "Real",
"db_number": 18,
"start": 18,
"amount": 1
}
]
}

View File

@ -1,3 +1,3 @@
SRC_FILES := xsdh-60a32-e.c xdh-60t4-e.c
SRC_FILES := xdh_60t4_e.c xsdh_60a32_e.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,184 @@
{
"device_id": 1,
"device_name": "OP01",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.32",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.255.0",
"port": 502
},
"protocol_type": 2,
"read_period": 100,
"read_item_list": [
{
"value_name": "M19",
"value_type": 1,
"function_code": 5,
"start_address": 19,
"quantity": 1
},
{
"value_name": "M20",
"value_type": 1,
"function_code": 5,
"start_address":20,
"quantity": 1
},
{
"value_name": "D500",
"value_type": 4,
"function_code": 6,
"start_address": 500,
"quantity": 1
},
{
"value_name": "D501",
"value_type": 4,
"function_code": 6,
"start_address": 501,
"quantity": 1
},
{
"value_name": "D502",
"value_type": 4,
"function_code": 6,
"start_address": 502,
"quantity": 1
},
{
"value_name": "D503",
"value_type": 4,
"function_code": 6,
"start_address": 503,
"quantity": 1
},
{
"value_name": "D504",
"value_type": 4,
"function_code": 6,
"start_address": 504,
"quantity": 1
},
{
"value_name": "M22",
"value_type": 1,
"function_code": 5,
"start_address": 22,
"quantity": 1
},
{
"value_name": "D505",
"value_type": 4,
"function_code": 6,
"start_address": 505,
"quantity": 1
},
{
"value_name": "D506",
"value_type": 4,
"function_code": 6,
"start_address": 506,
"quantity": 1
},
{
"value_name": "D507",
"value_type": 4,
"function_code": 6,
"start_address": 507,
"quantity": 1
},
{
"value_name": "D508",
"value_type": 4,
"function_code": 6,
"start_address": 508,
"quantity": 1
},
{
"value_name": "D509",
"value_type": 4,
"function_code": 6,
"start_address": 509,
"quantity": 1
},
{
"value_name": "D510",
"value_type": 4,
"function_code": 6,
"start_address": 510,
"quantity": 1
},
{
"value_name": "D511",
"value_type": 4,
"function_code": 6,
"start_address": 511,
"quantity": 1
},
{
"value_name": "M23",
"value_type": 1,
"function_code": 5,
"start_address": 23,
"quantity": 1
},
{
"value_name": "M24",
"value_type": 1,
"function_code": 5,
"start_address":24,
"quantity": 1
},
{
"value_name": "M25",
"value_type": 1,
"function_code": 5,
"start_address": 25,
"quantity": 1
},
{
"value_name": "M26",
"value_type": 1,
"function_code": 5,
"start_address": 26,
"quantity": 1
},
{
"value_name": "M29",
"value_type": 1,
"function_code": 5,
"start_address": 29,
"quantity": 1
},
{
"value_name": "D513",
"value_type": 4,
"function_code": 3,
"start_address": 513,
"quantity": 1
},
{
"value_name": "D515",
"value_type": 4,
"function_code": 3,
"start_address": 515,
"quantity": 1
},
{
"value_name": "M27",
"value_type": 1,
"function_code": 1,
"start_address":27,
"quantity": 1
},
{
"value_name": "M28",
"value_type": 1,
"function_code": 1,
"start_address":28,
"quantity": 1
}
]
}

View File

@ -0,0 +1,93 @@
{
"device_id": 255,
"device_name": "GJ2",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.45",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.1",
"netmask": "255.255.255.0",
"port": 502
},
"protocol_type": 2,
"read_period": 100,
"read_item_list": [
{
"value_name": "QX40.0",
"value_type": 1,
"function_code": 1,
"start_address":0,
"quantity": 1
},
{
"value_name": "QX40.1",
"value_type": 1,
"function_code": 1,
"start_address": 1,
"quantity": 1
},
{
"value_name": "QX40.2",
"value_type": 1,
"function_code": 1,
"start_address": 2,
"quantity": 1
},
{
"value_name": "QX40.3",
"value_type": 1,
"function_code": 1,
"start_address":3,
"quantity": 1
},
{
"value_name": "QX40.4",
"value_type": 1,
"function_code": 1,
"start_address": 4,
"quantity": 1
},
{
"value_name": "QW0",
"value_type": 3,
"function_code": 3,
"start_address": 0,
"quantity": 2
},
{
"value_name": "QW1",
"value_type": 3,
"function_code": 3,
"start_address": 1,
"quantity": 2
},
{
"value_name": "QW2",
"value_type": 3,
"function_code": 3,
"start_address": 2,
"quantity": 2
},
{
"value_name": "QW3",
"value_type": 3,
"function_code": 3,
"start_address": 3,
"quantity": 2
},
{
"value_name": "QW10",
"value_type": 3,
"function_code": 4,
"start_address": 0,
"quantity": 2
},
{
"value_name": "QW11",
"value_type": 3,
"function_code": 4,
"start_address": 1,
"quantity": 2
}
]
}

View File

@ -1,20 +0,0 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file mitsubishi_fx3u.c
* @brief PLC MITSUBISHI FX3U app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.2.1
*/

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file xdh-60t4-e.c
* @brief PLC XINJE XDH-60T4-E app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.4.5
*/
#include <control.h>
void ControlXDHTest(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
if (NULL == modbus_tcp_protocol) {
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
return;
}
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
ControlProtocolOpen(modbus_tcp_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_tcp_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlXDHTest, Xinje Plc XDH_60T4_E Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -1,19 +0,0 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file mitsubishi_fx3u.c
* @brief PLC MITSUBISHI FX3U app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.3.1
*/

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file xsdh-60a32-e.c
* @brief PLC XINJE XSDH-60A32-E app
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023.3.28
*/
#include <control.h>
void ControlXSDHTest(void)
{
int i, j = 0;
int read_data_length = 0;
uint8_t read_data[128] = {0};
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
if (NULL == modbus_tcp_protocol) {
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
return;
}
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
ControlProtocolOpen(modbus_tcp_protocol);
for (;;) {
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
if (read_data_length) {
for (j = 0; j < read_data_length; j ++) {
printf("j %d data 0x%x\n", j, read_data[j]);
}
}
i++;
memset(read_data, 0, sizeof(read_data));
PrivTaskDelay(10000);
}
//ControlProtocolClose(modbus_tcp_protocol);
}
}
PRIV_SHELL_CMD_FUNCTION(ControlXSDHTest, Xinje Plc XSDH_60A32_E Demo, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -27,7 +27,7 @@
extern "C" {
#endif
#define MODBUS_TCP_UNIT_ID 0x01
#define MODBUS_TCP_READ_CMD_LENGTH 0x0C
#define MODBUS_TCP_WRITE_SINGLE_CMD_LENGTH 0x0C

View File

@ -225,7 +225,7 @@ static int ModbusTcpInitialDataInfo(ModbusTcpReadItem *p_read_item, uint16_t ind
p_base_data_info->p_command[5] = 0x09;
}
p_base_data_info->p_command[6] = MODBUS_TCP_UNIT_ID;
p_base_data_info->p_command[6] = control_protocol->recipe->device_id;
p_base_data_info->p_command[7] = function_code;
p_base_data_info->p_command[8] = start_address >> 8;
p_base_data_info->p_command[9] = start_address;

View File

@ -23,6 +23,7 @@ endif
config CONTROL_PROTOCOL_S7
bool "Using s7 control protocol"
default n
select CONTROL_USING_SOCKET
if CONTROL_PROTOCOL_S7
source "$APP_DIR/Framework/control/plc_protocol/s7/Kconfig"
endif

View File

@ -329,7 +329,11 @@ void *ReceivePlcDataTask(void *parameter)
/*read all variable item data, put them into circular_area*/
if (i == control_protocol->recipe->read_item_count) {
printf("%s get %d item %d length\n", __func__, i, data_length);
// for(int i = 0; i < data_length; i++){
// printf("%x\n",fins_data[i]);
// }
CircularAreaAppWrite(circular_area, fins_data, data_length, 0);
printf("%s\n",fins_data);
}
/*read data every single 'read_period' ms*/

View File

@ -0,0 +1,408 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef snap7_h
#define snap7_h
//---------------------------------------------------------------------------
# include <stdint.h>
# include <unistd.h>
//******************************************************************************
// COMMON
//******************************************************************************
// Exact length types regardless of platform/processor
typedef uint8_t byte;
typedef uint16_t word;
typedef uint32_t longword;
typedef byte* pbyte;
typedef word* pword;
typedef uintptr_t S7Object; // multi platform/processor object reference
// DON'T CONFUSE IT WITH AN OLE OBJECT, IT'S SIMPLY
// AN INTEGER VALUE (32 OR 64 BIT) USED AS HANDLE.
#ifndef __cplusplus
typedef struct
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}tm;
typedef int bool;
#define false 0;
#define true 1;
#endif
static const int errLibInvalidParam = -1;
static const int errLibInvalidObject = -2;
// CPU status
#define S7CpuStatusUnknown 0x00
#define S7CpuStatusRun 0x08
#define S7CpuStatusStop 0x04
// ISO Errors
static const longword errIsoConnect = 0x00010000; // Connection error
static const longword errIsoDisconnect = 0x00020000; // Disconnect error
static const longword errIsoInvalidPDU = 0x00030000; // Bad format
static const longword errIsoInvalidDataSize = 0x00040000; // Bad Datasize passed to send/recv buffer is invalid
static const longword errIsoNullPointer = 0x00050000; // Null passed as pointer
static const longword errIsoShortPacket = 0x00060000; // A short packet received
static const longword errIsoTooManyFragments = 0x00070000; // Too many packets without EoT flag
static const longword errIsoPduOverflow = 0x00080000; // The sum of fragments data exceded maximum packet size
static const longword errIsoSendPacket = 0x00090000; // An error occurred during send
static const longword errIsoRecvPacket = 0x000A0000; // An error occurred during recv
static const longword errIsoInvalidParams = 0x000B0000; // Invalid TSAP params
static const longword errIsoResvd_1 = 0x000C0000; // Unassigned
static const longword errIsoResvd_2 = 0x000D0000; // Unassigned
static const longword errIsoResvd_3 = 0x000E0000; // Unassigned
static const longword errIsoResvd_4 = 0x000F0000; // Unassigned
// Tag Struct
typedef struct {
int Area;
int DBNumber;
int Start;
int Size;
int WordLen;
}TS7Tag, * PS7Tag;
//------------------------------------------------------------------------------
// PARAMS LIST
//------------------------------------------------------------------------------
static const int p_u16_LocalPort = 1;
static const int p_u16_RemotePort = 2;
static const int p_i32_PingTimeout = 3;
static const int p_i32_SendTimeout = 4;
static const int p_i32_RecvTimeout = 5;
static const int p_i32_WorkInterval = 6;
static const int p_u16_SrcRef = 7;
static const int p_u16_DstRef = 8;
static const int p_u16_SrcTSap = 9;
static const int p_i32_PDURequest = 10;
static const int p_i32_MaxClients = 11;
static const int p_i32_BSendTimeout = 12;
static const int p_i32_BRecvTimeout = 13;
static const int p_u32_RecoveryTime = 14;
static const int p_u32_KeepAliveTime = 15;
// Client/Partner Job status
static const int JobComplete = 0;
static const int JobPending = 1;
//******************************************************************************
// CLIENT
//******************************************************************************
// Error codes
static const longword errNegotiatingPDU = 0x00100000;
static const longword errCliInvalidParams = 0x00200000;
static const longword errCliJobPending = 0x00300000;
static const longword errCliTooManyItems = 0x00400000;
static const longword errCliInvalidWordLen = 0x00500000;
static const longword errCliPartialDataWritten = 0x00600000;
static const longword errCliSizeOverPDU = 0x00700000;
static const longword errCliInvalidPlcAnswer = 0x00800000;
static const longword errCliAddressOutOfRange = 0x00900000;
static const longword errCliInvalidTransportSize = 0x00A00000;
static const longword errCliWriteDataSizeMismatch = 0x00B00000;
static const longword errCliItemNotAvailable = 0x00C00000;
static const longword errCliInvalidValue = 0x00D00000;
static const longword errCliCannotStartPLC = 0x00E00000;
static const longword errCliAlreadyRun = 0x00F00000;
static const longword errCliCannotStopPLC = 0x01000000;
static const longword errCliCannotCopyRamToRom = 0x01100000;
static const longword errCliCannotCompress = 0x01200000;
static const longword errCliAlreadyStop = 0x01300000;
static const longword errCliFunNotAvailable = 0x01400000;
static const longword errCliUploadSequenceFailed = 0x01500000;
static const longword errCliInvalidDataSizeRecvd = 0x01600000;
static const longword errCliInvalidBlockType = 0x01700000;
static const longword errCliInvalidBlockNumber = 0x01800000;
static const longword errCliInvalidBlockSize = 0x01900000;
static const longword errCliDownloadSequenceFailed = 0x01A00000;
static const longword errCliInsertRefused = 0x01B00000;
static const longword errCliDeleteRefused = 0x01C00000;
static const longword errCliNeedPassword = 0x01D00000;
static const longword errCliInvalidPassword = 0x01E00000;
static const longword errCliNoPasswordToSetOrClear = 0x01F00000;
static const longword errCliJobTimeout = 0x02000000;
static const longword errCliPartialDataRead = 0x02100000;
static const longword errCliBufferTooSmall = 0x02200000;
static const longword errCliFunctionRefused = 0x02300000;
static const longword errCliDestroying = 0x02400000;
static const longword errCliInvalidParamNumber = 0x02500000;
static const longword errCliCannotChangeParam = 0x02600000;
static const int MaxVars = 20; // Max vars that can be transferred with MultiRead/MultiWrite
// Client Connection Type
static const word CONNTYPE_PG = 0x0001; // Connect to the PLC as a PG
static const word CONNTYPE_OP = 0x0002; // Connect to the PLC as an OP
static const word CONNTYPE_BASIC = 0x0003; // Basic connection
// Area ID
static const byte S7AreaPE = 0x81;
static const byte S7AreaPA = 0x82;
static const byte S7AreaMK = 0x83;
static const byte S7AreaDB = 0x84;
static const byte S7AreaCT = 0x1C;
static const byte S7AreaTM = 0x1D;
// Word Length
static const int S7WLBit = 0x01;
static const int S7WLByte = 0x02;
static const int S7WLWord = 0x04;
static const int S7WLDWord = 0x06;
static const int S7WLReal = 0x08;
static const int S7WLCounter = 0x1C;
static const int S7WLTimer = 0x1D;
// Block type
static const byte Block_OB = 0x38;
static const byte Block_DB = 0x41;
static const byte Block_SDB = 0x42;
static const byte Block_FC = 0x43;
static const byte Block_SFC = 0x44;
static const byte Block_FB = 0x45;
static const byte Block_SFB = 0x46;
// Sub Block Type
static const byte SubBlk_OB = 0x08;
static const byte SubBlk_DB = 0x0A;
static const byte SubBlk_SDB = 0x0B;
static const byte SubBlk_FC = 0x0C;
static const byte SubBlk_SFC = 0x0D;
static const byte SubBlk_FB = 0x0E;
static const byte SubBlk_SFB = 0x0F;
// Block languages
static const byte BlockLangAWL = 0x01;
static const byte BlockLangKOP = 0x02;
static const byte BlockLangFUP = 0x03;
static const byte BlockLangSCL = 0x04;
static const byte BlockLangDB = 0x05;
static const byte BlockLangGRAPH = 0x06;
// Read/Write Multivars
typedef struct {
int Area;
int WordLen;
int Result;
int DBNumber;
int Start;
int Amount;
void* pdata;
} TS7DataItem, * PS7DataItem;
//typedef int TS7ResultItems[MaxVars];
//typedef TS7ResultItems *PS7ResultItems;
// List Blocks
typedef struct {
int OBCount;
int FBCount;
int FCCount;
int SFBCount;
int SFCCount;
int DBCount;
int SDBCount;
} TS7BlocksList, * PS7BlocksList;
// Blocks info
typedef struct {
int BlkType; // Block Type (OB, DB)
int BlkNumber; // Block number
int BlkLang; // Block Language
int BlkFlags; // Block flags
int MC7Size; // The real size in bytes
int LoadSize; // Load memory size
int LocalData; // Local data
int SBBLength; // SBB Length
int CheckSum; // Checksum
int Version; // Block version
// Chars info
char CodeDate[11]; // Code date
char IntfDate[11]; // Interface date
char Author[9]; // Author
char Family[9]; // Family
char Header[9]; // Header
} TS7BlockInfo, * PS7BlockInfo;
typedef word TS7BlocksOfType[0x2000];
typedef TS7BlocksOfType* PS7BlocksOfType;
// Order code
typedef struct {
char Code[21];
byte V1;
byte V2;
byte V3;
} TS7OrderCode, * PS7OrderCode;
// CPU Info
typedef struct {
char ModuleTypeName[33];
char SerialNumber[25];
char ASName[25];
char Copyright[27];
char ModuleName[25];
} TS7CpuInfo, * PS7CpuInfo;
// CP Info
typedef struct {
int MaxPduLengt;
int MaxConnections;
int MaxMpiRate;
int MaxBusRate;
} TS7CpInfo, * PS7CpInfo;
// See §33.1 of "System Software for S7-300/400 System and Standard Functions"
// and see SFC51 description too
typedef struct {
word LENTHDR;
word N_DR;
} SZL_HEADER, * PSZL_HEADER;
typedef struct {
SZL_HEADER Header;
byte Data[0x4000 - 4];
} TS7SZL, * PS7SZL;
// SZL List of available SZL IDs : same as SZL but List items are big-endian adjusted
typedef struct {
SZL_HEADER Header;
word List[0x2000 - 2];
} TS7SZLList, * PS7SZLList;
// See §33.19 of "System Software for S7-300/400 System and Standard Functions"
typedef struct {
word sch_schal;
word sch_par;
word sch_rel;
word bart_sch;
word anl_sch;
} TS7Protection, * PS7Protection;
// Client completion callback
typedef void (*pfn_CliCompletion) (void* usrPtr, int opCode, int opResult);
//------------------------------------------------------------------------------
// Import prototypes
//------------------------------------------------------------------------------
S7Object Cli_Create();
void Cli_Destroy(S7Object* Client);
int Cli_ConnectTo(S7Object Client, const char* Address, int Rack, int Slot);
int Cli_SetConnectionParams(S7Object Client, const char* Address, word LocalTSAP, word RemoteTSAP);
int Cli_SetConnectionType(S7Object Client, word ConnectionType);
int Cli_Connect(S7Object Client);
int Cli_Disconnect(S7Object Client);
int Cli_GetParam(S7Object Client, int ParamNumber, void* pValue);
int Cli_SetParam(S7Object Client, int ParamNumber, void* pValue);
int Cli_SetAsCallback(S7Object Client, pfn_CliCompletion pCompletion, void* usrPtr);
// Data I/O main functions
int Cli_ReadArea(S7Object Client, int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData);
int Cli_WriteArea(S7Object Client, int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData);
int Cli_ReadMultiVars(S7Object Client, PS7DataItem Item, int ItemsCount);
int Cli_WriteMultiVars(S7Object Client, PS7DataItem Item, int ItemsCount);
// Data I/O Lean functions
int Cli_DBRead(S7Object Client, int DBNumber, int Start, int Size, void* pUsrData);
int Cli_DBWrite(S7Object Client, int DBNumber, int Start, int Size, void* pUsrData);
int Cli_MBRead(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_MBWrite(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_EBRead(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_EBWrite(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_ABRead(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_ABWrite(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_TMRead(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_TMWrite(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_CTRead(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_CTWrite(S7Object Client, int Start, int Amount, void* pUsrData);
// Directory functions
int Cli_ListBlocks(S7Object Client, TS7BlocksList* pUsrData);
int Cli_GetAgBlockInfo(S7Object Client, int BlockType, int BlockNum, TS7BlockInfo* pUsrData);
int Cli_GetPgBlockInfo(S7Object Client, void* pBlock, TS7BlockInfo* pUsrData, int Size);
int Cli_ListBlocksOfType(S7Object Client, int BlockType, TS7BlocksOfType* pUsrData, int* ItemsCount);
// Blocks functions
int Cli_Upload(S7Object Client, int BlockType, int BlockNum, void* pUsrData, int* Size);
int Cli_FullUpload(S7Object Client, int BlockType, int BlockNum, void* pUsrData, int* Size);
int Cli_Download(S7Object Client, int BlockNum, void* pUsrData, int Size);
int Cli_Delete(S7Object Client, int BlockType, int BlockNum);
int Cli_DBGet(S7Object Client, int DBNumber, void* pUsrData, int* Size);
int Cli_DBFill(S7Object Client, int DBNumber, int FillChar);
// Date/Time functions
int Cli_GetPlcDateTime(S7Object Client, tm* DateTime);
int Cli_SetPlcDateTime(S7Object Client, tm* DateTime);
int Cli_SetPlcSystemDateTime(S7Object Client);
// System Info functions
int Cli_GetOrderCode(S7Object Client, TS7OrderCode* pUsrData);
int Cli_GetCpuInfo(S7Object Client, TS7CpuInfo* pUsrData);
int Cli_GetCpInfo(S7Object Client, TS7CpInfo* pUsrData);
int Cli_ReadSZL(S7Object Client, int ID, int Index, TS7SZL* pUsrData, int* Size);
int Cli_ReadSZLList(S7Object Client, TS7SZLList* pUsrData, int* ItemsCount);
// Control functions
int Cli_PlcHotStart(S7Object Client);
int Cli_PlcColdStart(S7Object Client);
int Cli_PlcStop(S7Object Client);
int Cli_CopyRamToRom(S7Object Client, int Timeout);
int Cli_Compress(S7Object Client, int Timeout);
int Cli_GetPlcStatus(S7Object Client, int* Status);
// Security functions
int Cli_GetProtection(S7Object Client, TS7Protection* pUsrData);
int Cli_SetSessionPassword(S7Object Client, char* Password);
int Cli_ClearSessionPassword(S7Object Client);
// Low level
int Cli_IsoExchangeBuffer(S7Object Client, void* pUsrData, int* Size);
// Misc
int Cli_GetExecTime(S7Object Client, int* Time);
int Cli_GetLastError(S7Object Client, int* LastError);
int Cli_GetPduLength(S7Object Client, int* Requested, int* Negotiated);
int Cli_ErrorText(int Error, char* Text, int TextLen);
// 1.1.0
int Cli_GetConnected(S7Object Client, int* Connected);
//------------------------------------------------------------------------------
// Async functions
//------------------------------------------------------------------------------
int Cli_AsReadArea(S7Object Client, int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData);
int Cli_AsWriteArea(S7Object Client, int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData);
int Cli_AsDBRead(S7Object Client, int DBNumber, int Start, int Size, void* pUsrData);
int Cli_AsDBWrite(S7Object Client, int DBNumber, int Start, int Size, void* pUsrData);
int Cli_AsMBRead(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_AsMBWrite(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_AsEBRead(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_AsEBWrite(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_AsABRead(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_AsABWrite(S7Object Client, int Start, int Size, void* pUsrData);
int Cli_AsTMRead(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_AsTMWrite(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_AsCTRead(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_AsCTWrite(S7Object Client, int Start, int Amount, void* pUsrData);
int Cli_AsListBlocksOfType(S7Object Client, int BlockType, TS7BlocksOfType* pUsrData, int* ItemsCount);
int Cli_AsReadSZL(S7Object Client, int ID, int Index, TS7SZL* pUsrData, int* Size);
int Cli_AsReadSZLList(S7Object Client, TS7SZLList* pUsrData, int* ItemsCount);
int Cli_AsUpload(S7Object Client, int BlockType, int BlockNum, void* pUsrData, int* Size);
int Cli_AsFullUpload(S7Object Client, int BlockType, int BlockNum, void* pUsrData, int* Size);
int Cli_AsDownload(S7Object Client, int BlockNum, void* pUsrData, int Size);
int Cli_AsCopyRamToRom(S7Object Client, int Timeout);
int Cli_AsCompress(S7Object Client, int Timeout);
int Cli_AsDBGet(S7Object Client, int DBNumber, void* pUsrData, int* Size);
int Cli_AsDBFill(S7Object Client, int DBNumber, int FillChar);
int Cli_CheckAsCompletion(S7Object Client, int* opResult);
int Cli_WaitAsCompletion(S7Object Client, int Timeout);
#endif // snap7_h

View File

@ -16,4 +16,27 @@
* @version 3.0
* @author AIIT XUOS Lab
* @date 2022-10-08
*/
*/
#ifndef S7_H
#define S7_H
#include <control_def.h>
#include "libs7.h"
#define BASE_PLC_RECV_BUFF_SIZE 1024
ControlProtocolType control_protocol;
int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe);
void voidpush(uint8_t *datastack,uint8_t* args,uint16_t length);
static uint8_t GetUniformValueTypeMemorySize(UniformValueType uniform_value_type);
typedef struct
{
TS7DataItem data_info;
UniformValueType value_type;
char value_name[20];
}S7ReadItem;
#endif

View File

@ -1,4 +1,2 @@
SRC_FILES :=
SRC_FILES := libs7.a s7.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,242 @@
/*
* Copyright (c) 2022 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file s7.c
* @brief plc protocol s7
* @version 3.0
* @author AIIT XUOS Lab
* @date 2023-4-14
*/
#include <s7.h>
/**
* @description: S7 Receive Plc Data Task
* @param parameter - parameter pointer
* @return
*/
void *ReceivePlcDataTask(void *parameter)
{
printf("%s %d\n", __func__, __LINE__);
ReadPlcDataByRecipe(control_protocol->recipe);
}
/**
* @description: S7 Protocol Open
* @param control_protocol - control protocol pointer
* @return success : 0 error
*/
int S7Open(struct ControlProtocol *control_protocol)
{
ControlProtocolOpenDef(control_protocol);
return 0;
}
/**
* @description: S7 Protocol Close
* @param control_protocol - control protocol pointer
* @return success : 0 error
*/
int S7Close(struct ControlProtocol *control_protocol)
{
ControlProtocolCloseDef();
return 0;
}
/**
* @description: S7 Protocol Read Data
* @param control_protocol - control protocol pointer
* @param buf - read data buffer pointer
* @param len - read data length
* @return success : data length error : 0
*/
int S7Read(struct ControlProtocol *control_protocol, void *buf, size_t len)
{
struct CircularAreaApp *circular_area = (struct CircularAreaApp *)control_protocol->args;
return CircularAreaAppRead(circular_area, buf, len);
}
static struct ControlDone s7_protocol_done =
{
._open = S7Open,
._close = S7Close,
._read = S7Read,
._write = NULL,
._ioctl = NULL,
};
/**
* @description: Push Data Onto a Stack One By One
* @param datastack - data stack pointer
* @param args - data pointer
* @param length - data length
* @return
*/
void PushDataIntoStack(uint8_t *datastack,uint8_t* args,uint16_t length)
{
static int index = 8;
for(int i =0; i < length; i ++) {
datastack[index] = args[i];
index++;
if(index >= control_protocol->recipe->protocol_data.data_length){
index = 8;
}
}
}
/**
* @description: Read PLC Data By Recipe
* @param p_recipe - recipe pointer
* @return success : 0 error : -1
*/
int8_t ReadPlcDataByRecipe(struct ControlRecipe *p_recipe)
{
uint16_t data_length = control_protocol->recipe->protocol_data.data_length;
uint8_t *s7_data = control_protocol->recipe->protocol_data.data;
struct CircularAreaApp *circular_area = (struct CircularAreaApp *)control_protocol->args;
S7Object s7_plc = {0};
char plc_ip_string[15] = {0};
s7_plc = Cli_Create();
sprintf(plc_ip_string, "%u.%u.%u.%u",
p_recipe->socket_config.plc_ip[0],
p_recipe->socket_config.plc_ip[1],
p_recipe->socket_config.plc_ip[2],
p_recipe->socket_config.plc_ip[3]);
int16_t read_item_count = p_recipe->read_item_count;
uint8_t *p_read_item = (uint8_t *)(p_recipe->read_item);
while (1) {
int8_t error = 0;
while (!error) {
uint16_t i = 0;
for (i = 0; i < read_item_count; i ++) {
int is_connected = 0;
Cli_GetConnected(s7_plc, &is_connected);
while (!is_connected) {
if (Cli_ConnectTo(s7_plc, plc_ip_string, 0, 1) != 0) {
PrivTaskDelay(1000);
} else {
break;
}
}
TS7DataItem data_info = ((S7ReadItem*)p_read_item + i)->data_info;
Cli_ReadMultiVars(s7_plc, &data_info, 1);
uint16_t Size = GetValueTypeMemorySize(((S7ReadItem*)p_read_item + i)->value_type);
ControlPrintfList("S7 RECV", data_info.pdata,Size);
PushDataIntoStack(s7_data,data_info.pdata,Size);
PrivTaskDelay(100);
}
/*read all variable item data, put them into circular_area*/
if (i == read_item_count) {
printf("%s get %d item %d length\n", __func__, i, data_length);
CircularAreaAppWrite(circular_area, s7_data, data_length, 0);
}
}
}
return 0;
}
/**
* @description: S7 Protocol read item Init
* @param p_read_item - read item pointer
* @param read_item_json - read item json pointer
* @param p_data - unused
* @return success : 0 error : -1
*/
static uint8_t InitialS7ReadItem(S7ReadItem* p_read_item, cJSON* read_item_json, uint8_t* p_data)
{
p_read_item->value_type = cJSON_GetObjectItem(read_item_json, "value_type")->valueint;
strncpy(p_read_item->value_name, cJSON_GetObjectItem(read_item_json, "value_name")->valuestring, 20);
TS7DataItem* p_data_info = &(p_read_item->data_info);
p_data_info->Amount = cJSON_GetObjectItem(read_item_json, "amount")->valueint;
p_data_info->Start = cJSON_GetObjectItem(read_item_json, "start")->valueint;
p_data_info->DBNumber = cJSON_GetObjectItem(read_item_json, "db_number")->valueint;
char* area_valuestring = cJSON_GetObjectItem(read_item_json, "area")->valuestring;
if (strcmp(area_valuestring, "I") == 0)
p_data_info->Area = S7AreaPE;
else if (strcmp(area_valuestring, "Q") == 0)
p_data_info->Area = S7AreaPA;
else if (strcmp(area_valuestring, "M") == 0)
p_data_info->Area = S7AreaMK;
else if (strcmp(area_valuestring, "DB") == 0)
p_data_info->Area = S7AreaDB;
else if (strcmp(area_valuestring, "C") == 0)
p_data_info->Area = S7AreaCT;
else if (strcmp(area_valuestring, "T") == 0)
p_data_info->Area = S7AreaTM;
char* wordlen_valuestring = cJSON_GetObjectItem(read_item_json, "wordlen")->valuestring;
if (strcmp(wordlen_valuestring, "Bit") == 0)
p_data_info->WordLen = S7WLBit;
else if (strcmp(wordlen_valuestring, "Byte") == 0)
p_data_info->WordLen = S7WLByte;
else if (strcmp(wordlen_valuestring, "Word") == 0)
p_data_info->WordLen = S7WLWord;
else if (strcmp(wordlen_valuestring, "DWord") == 0)
p_data_info->WordLen = S7WLDWord;
else if (strcmp(wordlen_valuestring, "Real") == 0)
p_data_info->WordLen = S7WLReal;
else if (strcmp(wordlen_valuestring, "Counter") == 0)
p_data_info->WordLen = S7WLCounter;
else if (strcmp(wordlen_valuestring, "Timer") == 0)
p_data_info->WordLen = S7WLTimer;
p_data_info->pdata = p_data;
printf("value_type is %d, amount is %d, start is %04d, db_number is %d, area is 0x%03x, wordlen is %d.\n",
p_read_item->value_type, p_data_info->Amount, p_data_info->Start, p_data_info->DBNumber,
p_data_info->Area, p_data_info->WordLen);
return GetValueTypeMemorySize(p_read_item->value_type);
}
/**
* @description: S7 Protocol Cmd Generate
* @param p_recipe - recipe pointer
* @param protocol_format_info - protocol format info pointer
* @return success : 0 error : -1
*/
int S7ProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatInfo *protocol_format_info)
{
int ret = 0;
uint8_t *S7_plc_read_data = PrivMalloc(p_recipe->protocol_data.data_length);
uint16_t S7_plc_read_data_index = 8;
cJSON *read_single_item_json = protocol_format_info->read_single_item_json;
int i = protocol_format_info->read_item_index;
if (0 == i)
p_recipe->read_item = PrivMalloc(sizeof(S7ReadItem) * p_recipe->read_item_count);
S7_plc_read_data_index += InitialS7ReadItem((S7ReadItem *)(p_recipe->read_item) + i,
read_single_item_json, S7_plc_read_data + S7_plc_read_data_index);
if (S7_plc_read_data_index == 8) {
ret = -1;
printf("%s read %d item failed!\n", __func__, i);
}
return ret;
}
/**
* @description: S7 Protocol Init
* @param p_recipe - recipe pointer
* @return success : 0 error : -1
*/
int S7ProtocolInit(struct ControlRecipe *p_recipe)
{
p_recipe->read_item = PrivMalloc(sizeof(S7ReadItem) * p_recipe->read_item_count);
if (NULL == p_recipe->read_item) {
PrivFree(p_recipe->read_item);
return -1;
}
memset(p_recipe->read_item, 0, sizeof(S7ReadItem));
p_recipe->ControlProtocolFormatCmd = S7ProtocolFormatCmd;
p_recipe->done = &s7_protocol_done;
return 0;
}

View File

@ -0,0 +1,88 @@
{
"device_id": 1,
"device_name": "demo",
"communication_type": 0,
"socket_config": {
"plc_ip": "192.168.250.2",
"local_ip": "192.168.250.233",
"gateway": "192.168.250.252",
"netmask": "255.255.255.0",
"port": 102
},
"protocol_type": 1,
"read_period": 100,
"read_item_list": [
{
"value_name": "浮点数",
"value_type": 9,
"area": "DB",
"wordlen": "Real",
"db_number": 18,
"start": 18,
"amount": 1
},
{
"value_name": "整型1",
"value_type": 3,
"area": "M",
"wordlen": "WORD",
"db_number": 1,
"start": 100,
"amount": 1
},
{
"value_name": "整型2",
"value_type": 3,
"area": "M",
"wordlen": "WORD",
"db_number": 1,
"start": 102,
"amount": 1
},
{
"value_name": "布尔1",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 1,
"amount": 1
},
{
"value_name": "布尔2",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 2,
"amount": 1
},
{
"value_name": "布尔3",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 3,
"amount": 1
},
{
"value_name": "布尔4",
"value_type": 1,
"area": "Q",
"wordlen": "Bit",
"db_number": 1,
"start": 4,
"amount": 1
},
{
"value_name": "整型3",
"value_type": 3,
"area": "DB",
"wordlen": "Word",
"db_number": 18,
"start": 2,
"amount": 1
}
]
}

View File

@ -21,8 +21,6 @@
#include <control.h>
#include <control_def.h>
ControlProtocolType control_protocol;
/**
* @description: Control Framework Find certain Protocol
* @param void
@ -126,6 +124,7 @@ static int ControlAnalyzeRecipe(ControlProtocolType control_protocol, const char
return -1;
}
strncpy(control_protocol->device->dev_name, control_protocol->recipe->device_name, 20);
control_protocol->protocol_type = control_protocol->recipe->protocol_type;
/*Get the variable need to read from recipe file*/
@ -254,6 +253,15 @@ int ControlFrameworkInit(void)
ret = -1;
goto _out;
}
control_protocol->device = (struct ControlDevice *)PrivMalloc(sizeof(struct ControlDevice));
if (NULL == control_protocol->device) {
printf("%s malloc control device failed!\n", __func__);
PrivFree(control_protocol->device);
PrivFree(control_protocol);
ret = -1;
goto _out;
}
//Control Protocol Struct Init
ret = ControlProtocolInit(control_protocol);
@ -274,6 +282,7 @@ int ControlFrameworkInit(void)
}
control_protocol->protocol_status = CONTROL_REGISTERED;
control_protocol->device->status = CONTROL_REGISTERED;
ret = ControlPeripheralInit(control_protocol->recipe);
if (ret < 0) {
@ -281,9 +290,65 @@ int ControlFrameworkInit(void)
PrivFree(control_protocol);
goto _out;
}
printf("%u %u\n",control_protocol->recipe->total_data_length,control_protocol->recipe->device_id);
printf("%s ControlPeripheralInit done\n", __func__);
_out:
return ret;
}
static char *const protocol_type_str[] =
{
"TYPE_START",
"S7",
"MODBUS_TCP",
"MODBUS_UART",
"OPC_UA",
"FINS",
"MELSEC_1E",
"MELSEC_3E_Q_L",
"MELSEC_3E_IQ_R",
"MELSEC_1C",
"MELSEC_3C",
"TYPE_END"
};
/**
* @description: Control Framework Shell Cmd Information
* @param void
* @return success : 0 error : -1
*/
void ShowControl(void)
{
int i = 0;
int maxlen;
const char *item_type = "control_protocol_type";
const char *item_name_0 = "control_protocol_name";
const char *item_name_1 = "control_device_name";
const char *item_status = "status";
ControlProtocolType control_protocol = ControlProtocolFind();
printf(" %-28s%-28s%-26s%-20s\n", item_type, item_name_0, item_name_1, item_status);
maxlen = 90;
while (i < maxlen) {
i++;
if (maxlen == i) {
printf("-\n");
} else {
printf("-");
}
}
if (control_protocol) {
printf("%s", " ");
KPrintf("%-28s%-28s%-26s%-8d\n",
protocol_type_str[1],
protocol_type_str[1],
control_protocol->device->dev_name,
control_protocol->device->status);
}
}
PRIV_SHELL_CMD_FUNCTION(ShowControl, show control framework information, PRIV_SHELL_CMD_FUNC_ATTR);

View File

@ -24,10 +24,13 @@
#include <transform.h>
#include <list.h>
#ifdef __cplusplus
extern "C" {
#endif
struct ControlProtocol;
typedef struct ControlProtocol *ControlProtocolType;
@ -62,6 +65,15 @@ typedef enum
CONTROL_UNREGISTERED,
}ProtocolStatus;
struct ControlDevice
{
char *dev_name;
int status;
//to do
void *dev_done;
};
struct ControlProtocol
{
char *name;
@ -70,6 +82,7 @@ struct ControlProtocol
struct ControlRecipe *recipe;
struct ControlDone *done;
struct ControlDevice *device;
void *args;
@ -98,6 +111,9 @@ int ControlProtocolWrite(struct ControlProtocol *control_protocol, const void *b
/*Control Framework Protocol Ioctl*/
int ControlProtocolIoctl(struct ControlProtocol *control_protocol, int cmd, void *args);
/*Control Framework new certain Protocol*/
ControlProtocolType control_protocol;
#ifdef __cplusplus
}
#endif

View File

@ -45,6 +45,10 @@ extern int ModbusTcpProtocolInit(struct ControlRecipe *p_recipe);
extern int ModbusUartProtocolInit(struct ControlRecipe *p_recipe);
#endif
#ifdef CONTROL_PROTOCOL_S7
extern int S7ProtocolInit(struct ControlRecipe *p_recipe);
#endif
/*
CONTROL FRAMEWORK READ DATA FORMAT:
| HEAD |device_id|read data length|read item count| data |
@ -80,6 +84,9 @@ static struct ControlProtocolInitParam protocol_init[] =
#ifdef CONTROL_PROTOCOL_MODBUS_UART
{ PROTOCOL_MODBUS_UART, ModbusUartProtocolInit },
#endif
#ifdef CONTROL_PROTOCOL_S7
{ PROTOCOL_S7, S7ProtocolInit },
#endif
{ PROTOCOL_END, NULL },
};
@ -445,30 +452,24 @@ void RecipeReadVariableItem(struct ControlRecipe *p_recipe, cJSON *p_recipe_file
p_recipe->protocol_data.data = PrivMalloc(CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length);
p_recipe->protocol_data.data_length = CONTROL_DATA_HEAD_LENGTH + p_recipe->total_data_length;
memset(p_recipe->protocol_data.data, 0, p_recipe->protocol_data.data_length);
protocol_format_info.p_read_item_data = p_recipe->protocol_data.data + CONTROL_DATA_HEAD_LENGTH;
/*Init The Control Protocol*/
ControlProtocolInitDesc(p_recipe, protocol_init);
/*Format Data Header, Reference "CONTROL FRAMEWORK READ DATA FORMAT"*/
FormatDataHeader(p_recipe);
uint16_t read_item_count = p_recipe->read_item_count;
for (i = 0; i < read_item_count; i ++) {
cJSON *read_single_item_json = cJSON_GetArrayItem(read_item_list_json, i);
protocol_format_info.read_single_item_json = read_single_item_json;
protocol_format_info.read_item_index = i;
/*Format Protocol Cmd By Analyze Variable Item One By One*/
ret = p_recipe->ControlProtocolFormatCmd(p_recipe, &protocol_format_info);
if (ret < 0) {
printf("%s read %d item failed!\n", __func__, i);
continue;
if (ret < 0) {
printf("%s read %d item failed!\n", __func__, i);
continue;
}
}
}
}

View File

@ -44,6 +44,7 @@ extern "C" {
} \
}while (0)
typedef enum
{
UNIFORM_BOOL = 1,

View File

@ -68,6 +68,30 @@ int PrivSemaphoreAbandon(sem_t *sem)
return sem_post(sem);
}
/**********************event****************************/
#ifndef SEPARATE_COMPILE
int PrivEventCreate(uint8_t flag)
{
return UserEventCreate(flag);
}
int PrivEvenDelete(int event)
{
UserEventDelete(event);
return 1;
}
int PrivEvenTrigger(int event, uint32_t set)
{
return UserEventTrigger(event, set);
}
int PrivEventProcess(int event, uint32_t set, uint8_t option, int32_t wait_time, unsigned int *Recved)
{
return UserEventProcess(event, set, option, wait_time, Recved);
}
#endif
/**************************task*************************/
int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
@ -107,6 +131,36 @@ uint32_t PrivGetTickTime()
return CalculateTimeMsFromTick(CurrentTicksGain());
}
#endif
/******************Soft Timer*********************/
int PrivTimerCreate(clockid_t clockid, struct sigevent * evp, timer_t * timerid)
{
return timer_create(clockid, evp, timerid);
}
int PrivTimerDelete(timer_t timerid)
{
return timer_delete(timerid);
}
int PrivTimerStartRun(timer_t timerid)
{
return UserTimerStartRun(timerid);
}
int PrivTimerQuitRun(timer_t timerid)
{
return UserTimerQuitRun(timerid);
}
int PrivTimerModify(timer_t timerid, int flags, const struct itimerspec *restrict value,
struct itimerspec *restrict ovalue)
{
return timer_settime(timerid, flags, value, ovalue);
}
/*************************************************/
/*********************fs**************************/
#ifdef FS_VFS
/************************Driver Posix Transform***********************/
@ -165,6 +219,7 @@ int PrivIoctl(int fd, int cmd, void *args)
case LCD_TYPE:
ret = PrivLcdIoctl(fd, cmd, ioctl_cfg->args);
break;
case SPI_TYPE:
case I2C_TYPE:
case RTC_TYPE:
case ADC_TYPE:

View File

@ -24,6 +24,7 @@
#include <pthread.h>
#include <signal.h>
#include <semaphore.h>
#include <timer.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
@ -42,6 +43,16 @@ extern "C" {
#define NAME_NUM_MAX 32
#ifndef EVENT_AND
#define EVENT_AND (1 << 0)
#endif
#ifndef EVENT_OR
#define EVENT_OR (1 << 1)
#endif
#ifndef EVENT_AUTOCLEAN
#define EVENT_AUTOCLEAN (1 << 2)
#endif
/*********************GPIO define*********************/
#define GPIO_LOW 0x00
#define GPIO_HIGH 0x01
@ -93,6 +104,30 @@ extern "C" {
#define SERIAL_RB_BUFSZ 128
#endif
/********************SPI define*******************/
#define SPI_MAX_CLOCK 40000000
#define spi_device_max_num 4
#define SPI_LINE_CPHA (1 << 0)
#define SPI_LINE_CPOL (1 << 1)
#define SPI_LSB (0 << 2)
#define SPI_MSB (1 << 2)
#define SPI_DEV_MASTER (0 << 3)
#define SPI_DEV_SLAVE (1 << 3)
#define SPI_MODE_0 (0 | 0)
#define SPI_MODE_1 (0 | SPI_LINE_CPHA)
#define SPI_MODE_2 (SPI_LINE_CPOL | 0)
#define SPI_MODE_3 (SPI_LINE_CPOL | SPI_LINE_CPHA)
#define SPI_MODE_MASK (SPI_LINE_CPHA | SPI_LINE_CPOL | SPI_MSB)
#define SPI_CS_HIGH (1 << 4)
#define SPI_NO_CS (1 << 5)
#define SPI_3WIRE (1 << 6)
#define SPI_READY (1 << 7)
struct PinDevIrq
{
int irq_mode;//< RISING/FALLING/HIGH/LOW
@ -139,6 +174,15 @@ struct SerialDataCfg
enum ExtSerialPortConfigure port_configure;
};
struct SpiMasterParam
{
uint8 spi_work_mode;//CPOL CPHA
uint8 spi_frame_format;//frame format
uint8 spi_data_bit_width;//bit width
uint8 spi_data_endian;//little endian0big endian1
uint32 spi_maxfrequency;//work frequency
};
enum IoctlDriverType
{
SERIAL_TYPE = 0,
@ -362,6 +406,14 @@ int PrivSemaphoreObtainNoWait(sem_t *sem);
int PrivSemaphoreAbandon(sem_t *sem);
int32_t PrivSemaphoreSetValue(int32_t sem, uint16_t val);
/*********************event**********************/
#ifndef SEPARATE_COMPILE
int PrivEventCreate(uint8_t flag);
int PrivEvenDelete(int event);
int PrivEvenTrigger(int event, uint32_t set);
int PrivEventProcess(int event, uint32_t set, uint8_t option, int32_t wait_time, unsigned int *Recved);
#endif
/*********************task**************************/
int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr,
@ -388,6 +440,13 @@ void *PrivRealloc(void *pointer, size_t size);
void *PrivCalloc(size_t count, size_t size);
void PrivFree(void *pointer);
/******************soft timer*********************/
int PrivTimerCreate(clockid_t clockid, struct sigevent * evp, timer_t * timerid);
int PrivTimerDelete(timer_t timerid);
int PrivTimerStartRun(timer_t timerid);
int PrivTimerQuitRun(timer_t timerid);
int PrivTimerModify(timer_t timerid, int flags, const struct itimerspec *restrict value,
struct itimerspec *restrict ovalue);
#ifdef __cplusplus
}

View File

@ -11,4 +11,8 @@ ifeq ($(CONFIG_KERNEL_MESSAGEQUEUE),y)
SRC_FILES += mqueue.c
endif
ifeq ($(CONFIG_KERNEL_SOFTTIMER),y)
SRC_FILES += timer.c
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -32,33 +32,33 @@ extern "C" {
typedef int pid_t;
typedef unsigned long int pthread_t;
// struct sched_param {
// int sched_priority; /* process execution scheduling priority */
// size_t slice; /* time slice in SCHED_RR mode (ms) */
// };
// typedef struct pthread_attr {
// unsigned char is_initialized; /* if the attr is initialized set to 1, otherwise set to 0 */
// void *stackaddr; /* the start addr of the stack of the pthead */
// size_t stacksize; /* the size of the stack of the pthead */
// unsigned char contentionscope; /* the scope of contention, only PTHREAD_SCOPE_SYSTEM is supported */
// unsigned char inheritsched; /* when set to PTHREAD_INHERIT_SCHED, specifies that the thread scheduling attributes
// shall be inherited from the creating thread, and the scheduling attributes in this
// attr argument shall be ignored */
// unsigned char schedpolicy; /* the sched policy of the thread */
// struct sched_param schedparam; /* the parameter of the thread scheduling */
// size_t guardsize; /* guardsize is set to protect the stack, not supported */
// unsigned char detachstate; /* when set to PTHREAD_CREATE_JOINABLE, thread will not end untill the creating thread end */
// } pthread_attr_t;
struct sched_param {
int sched_priority; /* process execution scheduling priority */
size_t slice; /* time slice in SCHED_RR mode (ms) */
};
typedef struct pthread_attr {
unsigned char is_initialized; /* if the attr is initialized set to 1, otherwise set to 0 */
void *stackaddr; /* the start addr of the stack of the pthead */
size_t stacksize; /* the size of the stack of the pthead */
unsigned char contentionscope; /* the scope of contention, only PTHREAD_SCOPE_SYSTEM is supported */
unsigned char inheritsched; /* when set to PTHREAD_INHERIT_SCHED, specifies that the thread scheduling attributes
shall be inherited from the creating thread, and the scheduling attributes in this
attr argument shall be ignored */
unsigned char schedpolicy; /* the sched policy of the thread */
struct sched_param schedparam; /* the parameter of the thread scheduling */
size_t guardsize; /* guardsize is set to protect the stack, not supported */
unsigned char detachstate; /* when set to PTHREAD_CREATE_JOINABLE, thread will not end untill the creating thread end */
} pthread_attr_t;
// typedef struct pthread_mutexattr {
// int is_initialized;
// int type;
// int protocol;
// int prioceiling;
// int pshared;
// } pthread_mutexattr_t;
typedef struct pthread_mutexattr {
int is_initialized;
int type;
int protocol;
int prioceiling;
int pshared;
} pthread_mutexattr_t;
// typedef int pthread_mutex_t ;
typedef int pthread_mutex_t ;
#ifdef __cplusplus
}

View File

@ -0,0 +1,151 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: signal.h
* @brief: the function definition of posix signal
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/3/9
*
*/
#ifndef SIGNAL_H
#define SIGNAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <sys/types.h>
/* sigev_notify values
NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
#define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */
/* when the event of interest occurs. */
#define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */
/* value, shall be delivered when the event of */
/* interest occurs. */
#define SIGEV_THREAD 3 /* A notification function shall be called to */
/* perform notification. */
/* Signal Generation and Delivery, P1003.1b-1993, p. 63
NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
sigev_notify_attributes to the sigevent structure. */
union sigval
{
int sival_int; /* Integer signal value */
void *sival_ptr; /* Pointer signal value */
};
struct sigevent
{
int sigev_notify; /* Notification type */
int sigev_signo; /* Signal number */
union sigval sigev_value; /* Signal value */
void (*sigev_notify_function)( union sigval );
/* Notification function */
void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
};
struct siginfo
{
uint16_t si_signo;
uint16_t si_code;
union sigval si_value;
};
typedef struct siginfo siginfo_t;
#define SI_USER 0x01 /* Signal sent by kill(). */
#define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */
#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */
#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */
typedef void (*_sig_func_ptr)(int);
typedef unsigned long sigset_t;
struct sigaction
{
_sig_func_ptr sa_handler;
sigset_t sa_mask;
int sa_flags;
};
/*
* Structure used in sigaltstack call.
*/
typedef struct sigaltstack
{
void *ss_sp; /* Stack base or pointer. */
int ss_flags; /* Flags. */
size_t ss_size; /* Stack size. */
} stack_t;
#define SIG_SETMASK 0 /* set mask with sigprocmask() */
#define SIG_BLOCK 1 /* set of signals to block */
#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
#define sigemptyset(what) (*(what) = 0, 0)
#define sigfillset(what) (*(what) = ~(0), 0)
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
#if defined(__GNUC__)
#define SIGHUP 1 /* hangup */
#define SIGINT 2 /* interrupt */
#define SIGQUIT 3 /* quit */
#define SIGILL 4 /* illegal instruction (not reset when caught) */
#define SIGTRAP 5 /* trace trap (not reset when caught) */
#define SIGIOT 6 /* IOT instruction */
#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
#define SIGEMT 7 /* EMT instruction */
#define SIGFPE 8 /* floating point exception */
#define SIGKILL 9 /* kill (cannot be caught or ignored) */
#define SIGBUS 10 /* bus error */
#define SIGSEGV 11 /* segmentation violation */
#define SIGSYS 12 /* bad argument to system call */
#define SIGPIPE 13 /* write on a pipe with no one to read it */
#define SIGALRM 14 /* alarm clock */
#define SIGTERM 15 /* software termination signal from kill */
#define SIGURG 16 /* urgent condition on IO channel */
#define SIGSTOP 17 /* sendable stop signal not from tty */
#define SIGTSTP 18 /* stop signal from tty */
#define SIGCONT 19 /* continue a stopped process */
#define SIGCHLD 20 /* to parent on child stop or exit */
#define SIGCLD 20 /* System V name for SIGCHLD */
#define SIGTTIN 21 /* to readers pgrp upon background tty read */
#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
#define SIGIO 23 /* input/output possible signal */
#define SIGPOLL SIGIO /* System V name for SIGIO */
#define SIGXCPU 24 /* exceeded CPU time limit */
#define SIGXFSZ 25 /* exceeded file size limit */
#define SIGVTALRM 26 /* virtual time alarm */
#define SIGPROF 27 /* profiling time alarm */
#define SIGWINCH 28 /* window changed */
#define SIGLOST 29 /* resource lost (eg, record-lock lost) */
#define SIGUSR1 30 /* user defined signal 1 */
#define SIGUSR2 31 /* user defined signal 2 */
#define NSIG 32 /* signal 0 implied */
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: timer.h
* @brief: the function definition of posix soft timer
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/3/8
*
*/
#ifndef TIMER_H
#define TIMER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "../../switch_api/user_api.h"
#if !defined(LIB_MUSLLIB)
#include "signal.h"
#endif
#include <time.h>
#ifndef TIMER_TRIGGER_ONCE
#define TIMER_TRIGGER_ONCE (1 << 0)
#endif
#ifndef TIMER_TRIGGER_PERIODIC
#define TIMER_TRIGGER_PERIODIC (1 << 1)
#endif
int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid);
int timer_delete(timer_t timerid);
int timer_settime(timer_t timerid, int flags, const struct itimerspec *restrict value,
struct itimerspec *restrict ovalue);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif

View File

@ -0,0 +1,123 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: timer.c
* @brief: posix api of soft timer
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/3/8
*
*/
#include <string.h>
#include <stdio.h>
#include "include/timer.h"
#include "include/semaphore.h"
#include "include/pthread.h"
static sem_t timer_sem;
static pthread_t timer_task;
struct timer_func {
union sigval value;
int timer_flags;
void (* user_timer_function)(union sigval val);
};
struct timer_func g_timer_func;
static void *timer_callback(void *args)
{
struct sigevent *evp = (struct sigevent *)args;
while (1) {
if (g_timer_func.user_timer_function != NULL) {
if (0 == sem_timedwait(&timer_sem, NULL)) {
g_timer_func.user_timer_function(g_timer_func.value);
}
}
}
}
int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid)
{
int timer_id;
char timer_name[16];
if ((NULL == evp) || (NULL == timerid)) {
errno = EINVAL;
return -1;
}
/* Only support SIGEV_THREAD. */
if (evp->sigev_notify != SIGEV_THREAD) {
errno = ENOTSUP;
return -1;
}
memset(timer_name, 0, sizeof(timer_name));
snprintf(timer_name, sizeof(timer_name), "timer_%d", clockid);
sem_init(&timer_sem, 0, 0);
g_timer_func.value = evp->sigev_value;
g_timer_func.user_timer_function = evp->sigev_notify_function;
g_timer_func.timer_flags = *(int *)(evp->sigev_notify_attributes);
pthread_attr_t attr;
attr.schedparam.sched_priority = 22;
attr.stacksize = 2048;
pthread_create(&timer_task, &attr, &timer_callback, (void *)evp);
timer_id = UserTimerCreate(timer_name, NULL, (void *)&timer_sem, 1000, g_timer_func.timer_flags);
*timerid = timer_id;
return timer_id;
}
int timer_delete(timer_t timerid)
{
pthread_kill(timer_task, 0);
UserTimerQuitRun(timerid);
sem_destroy(&timer_sem);
return 0;
}
int timer_settime(timer_t timerid, int flags, const struct itimerspec *restrict value,
struct itimerspec *restrict ovalue)
{
if (NULL == value) {
errno = EFAULT;
return -1;
}
//reference from RTT
/* calculate timer period(tick); To avoid lost of accuracy, because "TICK_PER_SECOND" maybe 100, 1000, 1024 and so on.
*
* tick millisecond millisecond * TICK_PER_SECOND
* ------------------------- = -------------------------- ---> tick = -------------------------------------
* TICK_PER_SECOND MILLISECOND_PER_SECOND MILLISECOND_PER_SECOND
*
*/
uint32_t ms_value = value->it_interval.tv_nsec / 1000000;
uint32_t ticks = (value->it_interval.tv_sec * TICK_PER_SECOND) + (ms_value * TICK_PER_SECOND) / 1000;
UserTimerModify(timerid, ticks);
if (flags) {
UserTimerStartRun(timerid);
}
}

View File

@ -17,6 +17,10 @@ ifeq ($(CONFIG_SEPARATE_COMPILE),y)
SRC_FILES += user_msg.c
endif
ifeq ($(CONFIG_KERNEL_SOFTTIMER),y)
SRC_FILES += user_timer.c
endif
ifeq ($(CONFIG_FS_VFS),y)
SRC_FILES += user_fs.c
endif

View File

@ -123,6 +123,14 @@ long UserMsgQueueRecv(int32_t mq, void *buffer, size_t size,int32_t wait_time);
long UserMsgQueueReinit(int32_t mq);
#endif
#ifdef KERNEL_SOFTTIMER
int32_t UserTimerCreate(const char *name, void (*timeout)(void *parameter), void *parameter, uint32_t time, uint8_t trigger_mode);
long UserTimerDelete(int32_t timer_id);
long UserTimerStartRun(int32_t timer_id);
long UserTimerQuitRun(int32_t timer_id);
long UserTimerModify(int32_t timer_id, uint32_t ticks);
#endif
int open(const char *path, int flags, ...);
int read(int fd, void *buf, size_t len);
int write(int fd, const void *buf, size_t len);
@ -240,6 +248,14 @@ uint8_t UserGetTaskPriority(int32_t id);
#define UserMsgQueueReinit KMsgQueueReinit
#endif
#ifdef KERNEL_SOFTTIMER
int32_t UserTimerCreate(const char *name, void (*timeout)(void *parameter), void *parameter, uint32_t time, uint8_t trigger_mode);
long UserTimerDelete(int32_t timer_id);
long UserTimerStartRun(int32_t timer_id);
long UserTimerQuitRun(int32_t timer_id);
long UserTimerModify(int32_t timer_id, uint32_t ticks);
#endif
#define UserPrintf KPrintf
#endif

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: user_timer.c
* @brief: the priviate user api of soft timer for application
* @version: 3.0
* @author: AIIT XUOS Lab
* @date: 2023/3/8
*
*/
#include "user_api.h"
/**
* This function will create a soft timer.
*
* @param name the name of the timer.
* @param timeout the callback of the timer.
* @param parameter the parameter of the callback function
* @param time the timeout time
* @param trigger_mode the trigger way of the timer
*
* @return id on success;ENOMEMORY/ERROR on failure
*/
int32_t UserTimerCreate(const char *name,
void (*timeout)(void *parameter),
void *parameter,
uint32_t time,
uint8_t trigger_mode) {
return (int32_t)KSwitch5(KS_USER_TIMER_CREATE, (uintptr_t)name, (uintptr_t)timeout, (uintptr_t)parameter, (uintptr_t)time, (uintptr_t)trigger_mode);
}
/**
* This function will delete a timer.
*
* @param timer_id the id number of timer.
*
* @return EOK on success;EINVALED on failure
*
*/
x_err_t UserTimerDelete(int32_t timer_id) {
return (x_err_t)KSwitch1(KS_USER_TIMER_DELETE, (uintptr_t)timer_id);
}
/**
* This function will startup a timer.
*
* @param timer_id the id number of timer.
*
* @return EOK on success;EINVALED on failure
*
*/
x_err_t UserTimerStartRun(int32_t timer_id) {
return (x_err_t)KSwitch1(KS_USER_TIMER_STARTRUN, (uintptr_t)timer_id);
}
/**
* This function will stop a timer.
*
* @param timer_id the id number of timer.
*
* @return EOK on success;EINVALED on failure
*
*/
x_err_t UserTimerQuitRun(int32_t timer_id) {
return (x_err_t)KSwitch1(KS_USER_TIMER_QUITRUN, (uintptr_t)timer_id);
}
/**
* This function will modify the timeout of a timer.
*
* @param timer_id the id number of timer.
* @param ticks timeout ticks
*
* @return EOK on success;EINVALED on failure
*
*/
x_err_t UserTimerModify(int32_t timer_id, uint32_t ticks) {
return (x_err_t)KSwitch2(KS_USER_TIMER_MODIFY, (uintptr_t)timer_id, (uintptr_t)ticks);
}

View File

@ -9,8 +9,9 @@ menu "app lib"
config APP_SELECT_OTHER_LIB
bool "app select other lib"
endchoice
source "$APP_DIR/lib/cJSON/Kconfig"
source "$APP_DIR/lib/queue/Kconfig"
source "$APP_DIR/lib/lvgl/Kconfig"
source "$APP_DIR/lib/embedded_database/Kconfig"
source "$APP_DIR/lib/cJSON/Kconfig"
source "$APP_DIR/lib/queue/Kconfig"
source "$APP_DIR/lib/lvgl/Kconfig"
source "$APP_DIR/lib/embedded_database/Kconfig"
source "$APP_DIR/lib/lorawan/Kconfig"
endmenu

View File

@ -14,4 +14,8 @@ ifeq ($(CONFIG_LIB_USING_CJSON),y)
SRC_DIR += cJSON
endif
ifeq ($(CONFIG_LIB_USING_LORAWAN),y)
SRC_DIR += lorawan
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,3 +1,5 @@
menuconfig LIB_USING_CJSON
bool "USING cJSON"
default n
menu "lib using cJSON"
menuconfig LIB_USING_CJSON
bool "USING cJSON"
default n
endmenu

View File

@ -1,6 +1,10 @@
menuconfig USING_EMBEDDED_DATABASE
bool "embedded database"
default n
if USING_EMBEDDED_DATABASE
source "$APP_DIR/lib/embedded_database/flashdb/Kconfig"
endif
menu "lib using embedded_database"
menuconfig USING_EMBEDDED_DATABASE
bool "embedded database"
default n
if USING_EMBEDDED_DATABASE
source "$APP_DIR/lib/embedded_database/flashdb/Kconfig"
endif
endmenu

View File

@ -0,0 +1,30 @@
menu "lib using LoRaWan"
menuconfig LIB_USING_LORAWAN
bool "Using LoRaWan lib"
default n
if LIB_USING_LORAWAN
menuconfig LIB_USING_LORAWAN_ED_STACK
help
Please add "source "$APP_DIR/lib/lorawan/lorawan_devicenode/Kconfig"" when using lorawan_devicenode
bool "LoRaWan using lorawan_ed_stack lib"
default n
select LIB_USING_LORA_RADIO
if LIB_USING_LORAWAN_ED_STACK
endif
menuconfig LIB_USING_LORA_RADIO
help
Please add "source "$APP_DIR/lib/lorawan/lora_radio_driver/Kconfig"" when using lora_radio_driver
bool "LoRaWan using lora-radio-driver lib"
default n
if LIB_USING_LORA_RADIO
endif
endif
endmenu

View File

@ -0,0 +1,11 @@
SRC_DIR :=
ifeq ($(CONFIG_LIB_USING_LORA_RADIO),y)
SRC_DIR += lora_radio_driver
endif
ifeq ($(CONFIG_LIB_USING_LORAWAN_ED_STACK),y)
SRC_DIR += lorawan_devicenode
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,47 @@
# lorawan子模块调试说明
矽璓工业物联操作系统XiUOS目前支持lorawan相关开源库通过子模块形式管理该目录主要内容是包含**lora_radio_driver**、**lorawan_devicenode**等。
## 目录内容
```
xiuos/APP_Framework/lib/lorawan
├── README.md
├── lora_radio_driver lora_radio驱动库
├── lorawan_devicenode lorawan节点协议栈
├── Kconfig lorawan Kconfig配置
└── Makefile lorawan Makefile
```
## 使用
使用前执行以下操作:
```
# 下载代码
# 进入APP_Framework/lib/lorawan目录下载更新子模块
git submodule init
git submodule update APP_Framework/lib/lorawan/lora_radio_driver
git submodule update APP_Framework/lib/lorawan/lorawan_devicenode
# 进入 APP_Framework/lib/lorawan/Kconfig 配置增加子模块source路径
menuconfig LIB_USING_LORAWAN_ED_STACK
bool "LoRaWan using lorawan_ed_stack lib"
default n
select LIB_USING_LORA_RADIO
if LIB_USING_LORAWAN_ED_STACK
source "$APP_DIR/lib/lorawan/lorawan_devicenode/Kconfig"
endif
menuconfig LIB_USING_LORA_RADIO
bool "LoRaWan using lora-radio-driver lib"
default n
if LIB_USING_LORA_RADIO
source "$APP_DIR/lib/lorawan/lora_radio_driver/Kconfig"
endif
#编译对应OS即可
```

@ -0,0 +1 @@
Subproject commit bc03d64f4b7408f85512735064dc5569431d6c8d

@ -0,0 +1 @@
Subproject commit 2896d7234688de77992e7e1872a7e67a9456b420

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,7 @@
menuconfig LIB_USING_QUEUE
bool "USING QUEUE"
default n
menu "lib using queue"
menuconfig LIB_USING_QUEUE
bool "USING QUEUE"
default n
endmenu

View File

@ -5,4 +5,6 @@ source "$KERNEL_DIR/lib/Kconfig"
source "$KERNEL_DIR/fs/Kconfig"
source "$KERNEL_DIR/tool/Kconfig"
source "$KERNEL_DIR/../../APP_Framework/Kconfig"

View File

@ -62,6 +62,10 @@ PART += COMPILE_KERNEL
else ifeq ($(CONFIG_COMPILER_APP)_$(CONFIG_COMPILER_KERNEL),y_y)
PART := COMPILE_APP COMPILE_KERNEL
else ifeq ($(CONFIG_MCUBOOT_BOOTLOADER), y)
PART := COMPILE_BOOTLOADER
else ifeq ($(CONFIG_MCUBOOT_APPLICATION), y)
PART := COMPILE_APPLICATION
else
PART :=
@ -88,6 +92,22 @@ COMPILE_ALL:
@$(MAKE) -C build TARGET=XiZi-$(BOARD).elf LINK_FLAGS=LFLAGS
@rm build/Makefile build/make.obj
COMPILE_BOOTLOADER:
@for dir in $(SRC_DIR);do \
$(MAKE) -C $$dir; \
done
@cp link.mk build/Makefile
@$(MAKE) -C build COMPILE_TYPE="-boot" TARGET=XiZi-$(BOARD)-boot.elf LINK_FLAGS=LFLAGS
@rm build/Makefile build/make.obj
COMPILE_APPLICATION:
@for dir in $(SRC_DIR);do \
$(MAKE) -C $$dir; \
done
@cp link.mk build/Makefile
@$(MAKE) -C build COMPILE_TYPE="-app" TARGET=XiZi-$(BOARD)-app.elf LINK_FLAGS=LFLAGS
@rm build/Makefile build/make.obj
COMPILE_MUSL:
@for dir in $(MUSL_DIR);do \
$(MAKE) -C $$dir COMPILE_TYPE=$@ CONFIG_RESOURCES_LWIP=n; \

View File

@ -49,6 +49,61 @@ Modification:
.weak Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
#ifdef __BOOTLOADER /* BOOT */
cpsid i /* Mask interrupts */
.equ VTOR, 0xE000ED08
ldr r0, =VTOR
ldr r1, =__isr_vector
str r1, [r0]
ldr r2, [r1]
msr msp, r2
ldr r0,=SystemInit
blx r0
/* Loop to copy data from read only memory to RAM. The ranges
* of copy from/to are specified by following symbols evaluated in
* linker script.
* __bootloader_end: End of code section, i.e., begin of data sections to copy from.
* __data_start__/__data_end__: RAM address range that data should be
* __noncachedata_start__/__noncachedata_end__ : none cachable region
* copied to. Both must be aligned to 4 bytes boundary. */
ldr r1, =__etext
ldr r2, =__data_start__
ldr r3, =__data_end__
/* Here are two copies of loop implemenations. First one favors code size
* and the second one favors performance. Default uses the first one.
* Change to "#if 0" to use the second one */
.LoopCopy0:
cmp r2, r3
ittt lt
ldrlt r0, [r1], #4
strlt r0, [r2], #4
blt .LoopCopy0
/* This part of work usually is done in C library startup code. Otherwise,
* define this macro to enable it in this startup.
*
* Loop to zero out BSS section, which uses following symbols
* in linker script:
* __bss_start__: start of BSS section. Must align to 4
* __bss_end__: end of BSS section. Must align to 4
*/
ldr r1, =__bss_start__
ldr r2, =__bss_end__
movs r0, 0
.LoopCopy1:
cmp r1, r2
itt lt
strlt r0, [r1], #4
blt .LoopCopy1
ldr r0,=ota_entry
blx r0
#else /* APP */
cpsid i /* Mask interrupts */
.equ VTOR, 0xE000ED08
ldr r0, =VTOR
@ -122,7 +177,7 @@ Reset_Handler:
blt .LC4
#endif /* __STARTUP_INITIALIZE_NONCACHEDATA */
#ifdef __STARTUP_CLEAR_BSS
#if 1
/* This part of work usually is done in C library startup code. Otherwise,
* define this macro to enable it in this startup.
*
@ -144,5 +199,6 @@ Reset_Handler:
ldr r0,=entry
blx r0
#endif /* MCUBOOT_BOOTLOADER */
.size Reset_Handler, . - Reset_Handler

View File

@ -22,7 +22,7 @@
static struct HardwareDev *g_spi_lora_dev;
static BusType buspin;
tRadioDriver *Radio = NONE;
static tRadioDriver *Radio = NONE;
void SX1276InitIo(void)
{
struct PinParam PinCfg;

View File

@ -22,7 +22,7 @@
static struct HardwareDev *g_spi_lora_dev;
static BusType buspin;
tRadioDriver *Radio = NONE;
static tRadioDriver *Radio = NONE;
void SX1276InitIo(void)
{
struct PinParam PinCfg;

View File

@ -77,7 +77,7 @@ static x_err_t ReadRegs(struct HardwareDev* dev, uint8 len, uint8* buf)
// not used in polling mode
static void touch_pin_irqhandler(void* arg)
{
KPrintf("int hdr working.\n");
//KPrintf("int hdr working.\n");
if (!SemReleaseFlag)
{
KSemaphoreAbandon(touch_sem);

View File

@ -1,11 +1,11 @@
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_hc32f4a0.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_hc32f4a0.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
export APPLFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
export APPLFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
export DEFINES := -DHAVE_CCONFIG_H -DHC32F4A0 -DUSE_DDL_DRIVER -DHAVE_SIGINFO

View File

@ -25,7 +25,7 @@
#define LORA_RST_PIN (GPIO_PIN_02)
static struct HardwareDev *g_spi_lora_dev;
tRadioDriver *Radio = NONE;
static tRadioDriver *Radio = NONE;
void SX1276InitIo(void)
{

View File

@ -64,6 +64,10 @@ Modification:
#include <connect_wdt.h>
#endif
#ifdef TOOL_USING_OTA
#include <ota.h>
#endif
#ifdef BSP_USING_SEMC
extern status_t BOARD_InitSEMC(void);
#ifdef BSP_USING_EXTSRAM
@ -330,12 +334,12 @@ struct InitSequenceDesc _board_init[] =
#endif
#ifdef BSP_USING_SDIO
{ "sdio", Imxrt1052HwSdioInit },
{ "sdio", Imxrt1052HwSdioInit },
#endif
#ifdef BSP_USING_USB
#ifdef BSP_USING_NXP_USBH
{ "nxp hw usb", Imxrt1052HwUsbHostInit },
{ "nxp hw usb", Imxrt1052HwUsbHostInit },
#endif
#endif
@ -344,7 +348,7 @@ struct InitSequenceDesc _board_init[] =
#endif
#ifdef BSP_USING_LCD
{ "hw_lcd", Imxrt1052HwLcdInit },
{ "hw_lcd", Imxrt1052HwLcdInit },
#endif
#ifdef BSP_USING_TOUCH
@ -358,7 +362,7 @@ struct InitSequenceDesc _board_init[] =
#ifdef BSP_USING_WDT
{ "hw_wdt", Imxrt1052HwWdgInit },
#endif
{ " NONE ",NONE },
{ " NONE ",NONE },
};
/**
@ -367,7 +371,7 @@ struct InitSequenceDesc _board_init[] =
void InitBoardHardware()
{
int i = 0;
int ret = 0;
int ret = 0;
BOARD_ConfigMPU();
BOARD_InitPins();
@ -403,10 +407,14 @@ void InitBoardHardware()
KPrintf("board initialization......\n");
for(i = 0; _board_init[i].fn != NONE; i++) {
ret = _board_init[i].fn();
KPrintf("initialize %s %s\n",_board_init[i].fn_name, ret == 0 ? "success" : "failed");
}
ret = _board_init[i].fn();
KPrintf("initialize %s %s\n",_board_init[i].fn_name, ret == 0 ? "success" : "failed");
}
KPrintf("board init done.\n");
KPrintf("start kernel...\n");
}
KPrintf("start kernel...\n");
#ifdef TOOL_USING_OTA
//跳转成功设置lastjumpflag为JUMP_SUCCESS_FLAG
app_clear_jumpflag();
#endif
}

View File

@ -15,7 +15,11 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
export LINK_LWIP := $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a
endif
ifeq ($(CONFIG_BSP_USING_USB),y)
ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y)
export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32-boot.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-bootloader.lds
else ifeq ($(CONFIG_MCUBOOT_APPLICATION),y)
export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32-app.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-application.lds
else ifeq ($(CONFIG_BSP_USING_USB),y)
export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-usb.lds
else
export LFLAGS += -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-xidatong-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
@ -28,5 +32,9 @@ export APPLFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections
export DEFINES := -DHAVE_CCONFIG_H -DCPU_MIMXRT1052CVL5B -DSKIP_SYSCLK_INIT -DEVK_MCIMXRM -DFSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1 -DXIP_EXTERNAL_FLASH=1 -D__STARTUP_INITIALIZE_NONCACHEDATA -D__STARTUP_CLEAR_BSS
ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y)
export DEFINES += -D__BOOTLOADER
endif
export ARCH = arm
export MCU = cortex-m7

View File

@ -33,7 +33,7 @@ Modification:
#include "fsl_clock.h"
#include "fsl_enet.h"
#include "clock_config.h"
// #include <xizi.h>
#include <xizi.h>
#include <arch_interrupt.h>
extern int heap_start;

View File

@ -50,6 +50,53 @@ void BOARD_InitBootClocks(void);
******************************************************************************/
#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 600000000U /*!< Core clock frequency: 600000000Hz */
/* Clock outputs (values are in Hz): */
#define BOARD_BOOTCLOCKRUN_AHB_CLK_ROOT 600000000UL
#define BOARD_BOOTCLOCKRUN_CAN_CLK_ROOT 40000000UL
#define BOARD_BOOTCLOCKRUN_CKIL_SYNC_CLK_ROOT 32768UL
#define BOARD_BOOTCLOCKRUN_CLKO1_CLK 0UL
#define BOARD_BOOTCLOCKRUN_CLKO2_CLK 0UL
#define BOARD_BOOTCLOCKRUN_CLK_1M 1000000UL
#define BOARD_BOOTCLOCKRUN_CLK_24M 24000000UL
#define BOARD_BOOTCLOCKRUN_CSI_CLK_ROOT 12000000UL
#define BOARD_BOOTCLOCKRUN_ENET1_TX_CLK 2400000UL
#define BOARD_BOOTCLOCKRUN_ENET_125M_CLK 2400000UL
#define BOARD_BOOTCLOCKRUN_ENET_25M_REF_CLK 1200000UL
#define BOARD_BOOTCLOCKRUN_FLEXIO1_CLK_ROOT 30000000UL
#define BOARD_BOOTCLOCKRUN_FLEXIO2_CLK_ROOT 30000000UL
#define BOARD_BOOTCLOCKRUN_FLEXSPI_CLK_ROOT 160000000UL
#define BOARD_BOOTCLOCKRUN_GPT1_IPG_CLK_HIGHFREQ 75000000UL
#define BOARD_BOOTCLOCKRUN_GPT2_IPG_CLK_HIGHFREQ 75000000UL
#define BOARD_BOOTCLOCKRUN_IPG_CLK_ROOT 150000000UL
#define BOARD_BOOTCLOCKRUN_LCDIF_CLK_ROOT 9642857UL
#define BOARD_BOOTCLOCKRUN_LPI2C_CLK_ROOT 60000000UL
#define BOARD_BOOTCLOCKRUN_LPSPI_CLK_ROOT 105600000UL
#define BOARD_BOOTCLOCKRUN_LVDS1_CLK 1200000000UL
#define BOARD_BOOTCLOCKRUN_MQS_MCLK 63529411UL
#define BOARD_BOOTCLOCKRUN_PERCLK_CLK_ROOT 75000000UL
#define BOARD_BOOTCLOCKRUN_PLL7_MAIN_CLK 24000000UL
#define BOARD_BOOTCLOCKRUN_SAI1_CLK_ROOT 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI1_MCLK1 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI1_MCLK2 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI1_MCLK3 30000000UL
#define BOARD_BOOTCLOCKRUN_SAI2_CLK_ROOT 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI2_MCLK1 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI2_MCLK2 0UL
#define BOARD_BOOTCLOCKRUN_SAI2_MCLK3 30000000UL
#define BOARD_BOOTCLOCKRUN_SAI3_CLK_ROOT 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI3_MCLK1 63529411UL
#define BOARD_BOOTCLOCKRUN_SAI3_MCLK2 0UL
#define BOARD_BOOTCLOCKRUN_SAI3_MCLK3 30000000UL
#define BOARD_BOOTCLOCKRUN_SEMC_CLK_ROOT 75000000UL
#define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL
#define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL
#define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL
#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL
#define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL
#define BOARD_BOOTCLOCKRUN_USBPHY2_CLK 0UL
#define BOARD_BOOTCLOCKRUN_USDHC1_CLK_ROOT 198000000UL
#define BOARD_BOOTCLOCKRUN_USDHC2_CLK_ROOT 198000000UL
/*! @brief Arm PLL set for BOARD_BootClockRUN configuration.
*/
extern const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN;

View File

@ -0,0 +1,264 @@
/*
** ###################################################################
** Processors: MIMXRT1052CVJ5B
** MIMXRT1052CVL5B
** MIMXRT1052DVJ6B
** MIMXRT1052DVL6B
**
** Compiler: GNU C Compiler
** Reference manual: IMXRT1050RM Rev.1, 03/2018
** Version: rev. 1.0, 2018-09-21
** Build: b180921
**
** Abstract:
** Linker file for the GNU C Compiler
**
** Copyright 2016 Freescale Semiconductor, Inc.
** Copyright 2016-2018 NXP
** All rights reserved.
**
** SPDX-License-Identifier: BSD-3-Clause
**
** http: www.nxp.com
** mail: support@nxp.com
**
** ###################################################################
*/
/**
* @file link.lds
* @brief xidatong-arm32 Linker script
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-28
*/
/*************************************************
File name: link.lds
Description: xidatong-arm32 Linker script
Others: take MIMXRT1052xxxxx_flexspi_nor.ld for references
History:
1. Date: 2021-05-28
Author: AIIT XUOS Lab
Modification:
1. add shell cmd table and g_service_table
*************************************************/
/* Entry Point */
ENTRY(Reset_Handler)
STACK_SIZE = 0x4000;
/* Specify the memory areas */
MEMORY
{
m_interrupts (RX) : ORIGIN = 0x60100000, LENGTH = 0x00000400
m_text (RX) : ORIGIN = 0x60100400, LENGTH = 0x000FFC00
m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000
m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000
m_sdram (RW) : ORIGIN = 0x80000000, LENGTH = 0x01E00000
m_nocache (RW) : ORIGIN = 0x81E00000, LENGTH = 0x00200000
}
/* Define output sections */
SECTIONS
{
/* The startup code goes first into internal RAM */
.interrupts :
{
__VECTOR_TABLE = .;
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
__VECTOR_RAM = __VECTOR_TABLE;
__RAM_VECTOR_TABLE_SIZE_BYTES = 0x0;
/* The program code and other data goes into internal RAM */
.text :
{
. = ALIGN(4);
*(EXCLUDE_FILE(
/* Exclude flash and frequently executed functions from XIP */
*fsl_romapi.o
*flash.o
) .text) /* .text sections (code) */
*(EXCLUDE_FILE(
/* Exclude flash and frequently executed functions from XIP */
*fsl_romapi.o
*flash.o
) .text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
/* section information for shell */
. = ALIGN(4);
_shell_command_start = .;
KEEP (*(shellCommand))
_shell_command_end = .;
. = ALIGN(4);
__isrtbl_idx_start = .;
KEEP(*(.isrtbl.idx))
__isrtbl_start = .;
KEEP(*(.isrtbl))
__isrtbl_end = .;
. = ALIGN(4);
PROVIDE(g_service_table_start = ABSOLUTE(.));
KEEP(*(.g_service_table))
PROVIDE(g_service_table_end = ABSOLUTE(.));
} > m_text
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > m_text
.ARM :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} > m_text
__etext = .; /* define a global symbol at end of code */
__DATA_ROM = .; /* Symbol is used by startup for data initialization */
.data : AT(__DATA_ROM)
{
. = ALIGN(4);
__DATA_RAM = .;
__data_start__ = .; /* create a global symbol at data start */
/* Explicit placement of flash and frequently executed functions in RAM */
*fsl_romapi.o
*flash.o
*(.data) /* .data sections */
*(.data*) /* .data* sections */
KEEP(*(.jcr*))
. = ALIGN(4);
PROVIDE(_sramfuncs = ABSOLUTE(.));
KEEP(*(RamFunction))
PROVIDE(_eramfuncs = ABSOLUTE(.));
__data_end__ = .; /* define a global symbol at data end */
} > m_data
__NDATA_ROM = __DATA_ROM + (__data_end__ - __data_start__);
.ncache.init : AT(__NDATA_ROM)
{
__noncachedata_start__ = .; /* create a global symbol at ncache data start */
*(NonCacheable.init)
. = ALIGN(4);
__noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */
} > m_nocache
. = __noncachedata_init_end__;
.ncache :
{
*(NonCacheable)
. = ALIGN(4);
__noncachedata_end__ = .; /* define a global symbol at ncache data end */
} > m_nocache
__DATA_END = __NDATA_ROM + (__noncachedata_init_end__ - __noncachedata_start__);
text_end = ORIGIN(m_text) + LENGTH(m_text);
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
/* Uninitialized data section */
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
. = ALIGN(4);
__START_BSS = .;
__bss_start__ = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
__END_BSS = .;
} > m_data
.stack :
{
. = ALIGN(8);
stack_start = .;
. += STACK_SIZE;
stack_end = .;
__StackTop = .;
heap_start = .;
} > m_data2
PROVIDE(heap_end = ORIGIN(m_data2) + LENGTH(m_data2));
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@ -0,0 +1,280 @@
/*
** ###################################################################
** Processors: MIMXRT1052CVJ5B
** MIMXRT1052CVL5B
** MIMXRT1052DVJ6B
** MIMXRT1052DVL6B
**
** Compiler: GNU C Compiler
** Reference manual: IMXRT1050RM Rev.1, 03/2018
** Version: rev. 1.0, 2018-09-21
** Build: b180921
**
** Abstract:
** Linker file for the GNU C Compiler
**
** Copyright 2016 Freescale Semiconductor, Inc.
** Copyright 2016-2018 NXP
** All rights reserved.
**
** SPDX-License-Identifier: BSD-3-Clause
**
** http: www.nxp.com
** mail: support@nxp.com
**
** ###################################################################
*/
/**
* @file link.lds
* @brief xidatong-arm32 Linker script
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-28
*/
/*************************************************
File name: link.lds
Description: xidatong-arm32 Linker script
Others: take MIMXRT1052xxxxx_flexspi_nor.ld for references
History:
1. Date: 2021-05-28
Author: AIIT XUOS Lab
Modification:
1. add shell cmd table and g_service_table
*************************************************/
/* Entry Point */
ENTRY(Reset_Handler)
STACK_SIZE = 0x8000;
/* Specify the memory areas */
MEMORY
{
m_boot_data (RX) : ORIGIN = 0x60000000, LENGTH = 0x00001000
m_image_vertor_table (RX) : ORIGIN = 0x60001000, LENGTH = 0x00001000
/*bootloader*/
m_interrupts (RX) : ORIGIN = 0x60002000, LENGTH = 0x00000400
m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x0007DC00
m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000
m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000
m_sdram (RW) : ORIGIN = 0x80000000, LENGTH = 0x01E00000
m_nocache (RW) : ORIGIN = 0x81E00000, LENGTH = 0x00200000
}
/* Define output sections */
SECTIONS
{
.boot_data :
{
KEEP(*(.boot_hdr.conf))
} > m_boot_data
.image_vertor_table :
{
KEEP(*(.boot_hdr.ivt))
KEEP(*(.boot_hdr.boot_data))
KEEP(*(.boot_hdr.dcd_data))
} > m_image_vertor_table
/* The startup code goes first into internal RAM */
.interrupts :
{
__VECTOR_TABLE = .;
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} > m_interrupts
__VECTOR_RAM = __VECTOR_TABLE;
__RAM_VECTOR_TABLE_SIZE_BYTES = 0x0;
/* The program code and other data goes into internal RAM */
.text :
{
. = ALIGN(4);
*(EXCLUDE_FILE(
/* Exclude flash and frequently executed functions from XIP */
*fsl_romapi.o
*flash.o
) .text) /* .text sections (code) */
*(EXCLUDE_FILE(
/* Exclude flash and frequently executed functions from XIP */
*fsl_romapi.o
*flash.o
) .text*) /* .text* sections (code) */
*(.rodata) /* .rodata sections (constants, strings, etc.) */
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
*(.glue_7) /* glue arm to thumb code */
*(.glue_7t) /* glue thumb to arm code */
*(.eh_frame)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
/* section information for shell */
. = ALIGN(4);
_shell_command_start = .;
KEEP (*(shellCommand))
_shell_command_end = .;
. = ALIGN(4);
__isrtbl_idx_start = .;
KEEP(*(.isrtbl.idx))
__isrtbl_start = .;
KEEP(*(.isrtbl))
__isrtbl_end = .;
. = ALIGN(4);
PROVIDE(g_service_table_start = ABSOLUTE(.));
KEEP(*(.g_service_table))
PROVIDE(g_service_table_end = ABSOLUTE(.));
} > m_text
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > m_text
.ARM :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > m_text
.ctors :
{
__CTOR_LIST__ = .;
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
from the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__CTOR_END__ = .;
} > m_text
.dtors :
{
__DTOR_LIST__ = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__DTOR_END__ = .;
} > m_text
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array*))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > m_text
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} > m_text
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
} > m_text
__etext = .; /* define a global symbol at end of code */
__DATA_ROM = .; /* Symbol is used by startup for data initialization */
.data : AT(__DATA_ROM)
{
. = ALIGN(4);
__DATA_RAM = .;
__data_start__ = .; /* create a global symbol at data start */
/* Explicit placement of flash and frequently executed functions in RAM */
*fsl_romapi.o
*flash.o
*(.data) /* .data sections */
*(.data*) /* .data* sections */
KEEP(*(.jcr*))
. = ALIGN(4);
PROVIDE(_sramfuncs = ABSOLUTE(.));
KEEP(*(RamFunction))
PROVIDE(_eramfuncs = ABSOLUTE(.));
__data_end__ = .; /* define a global symbol at data end */
} > m_data
__NDATA_ROM = __DATA_ROM + (__data_end__ - __data_start__);
.ncache.init : AT(__NDATA_ROM)
{
__noncachedata_start__ = .; /* create a global symbol at ncache data start */
*(NonCacheable.init)
. = ALIGN(4);
__noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */
} > m_nocache
. = __noncachedata_init_end__;
.ncache :
{
*(NonCacheable)
. = ALIGN(4);
__noncachedata_end__ = .; /* define a global symbol at ncache data end */
} > m_nocache
__DATA_END = __NDATA_ROM + (__noncachedata_init_end__ - __noncachedata_start__);
text_end = ORIGIN(m_text) + LENGTH(m_text);
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
/* Uninitialized data section */
.bss :
{
/* This is used by the startup in order to initialize the .bss section */
. = ALIGN(4);
__START_BSS = .;
__bss_start__ = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
__END_BSS = .;
} > m_data
.stack :
{
. = ALIGN(8);
stack_start = .;
. += STACK_SIZE;
stack_end = .;
__StackTop = .;
heap_start = .;
} > m_data
PROVIDE(heap_end = ORIGIN(m_data) + LENGTH(m_data));
.ARM.attributes 0 : { *(.ARM.attributes) }
}

View File

@ -260,5 +260,4 @@ SECTIONS
PROVIDE(heap_end = ORIGIN(m_data2) + LENGTH(m_data2));
.ARM.attributes 0 : { *(.ARM.attributes) }
}
}

View File

@ -4,4 +4,8 @@ ifeq ($(CONFIG_BSP_USING_SDIO),y)
SRC_FILES += fsl_usdhc.c
endif
ifeq ($(CONFIG_TOOL_USING_OTA),y)
SRC_FILES += fsl_romapi.c flash.c mcuboot.c common.c ymodem.c
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@ -78,11 +78,11 @@ outputs:
- {id: ENET_25M_REF_CLK.outFreq, value: 1.2 MHz}
- {id: FLEXIO1_CLK_ROOT.outFreq, value: 30 MHz}
- {id: FLEXIO2_CLK_ROOT.outFreq, value: 30 MHz}
- {id: FLEXSPI_CLK_ROOT.outFreq, value: 2880/11 MHz}
- {id: FLEXSPI_CLK_ROOT.outFreq, value: 160 MHz}
- {id: GPT1_ipg_clk_highfreq.outFreq, value: 75 MHz}
- {id: GPT2_ipg_clk_highfreq.outFreq, value: 75 MHz}
- {id: IPG_CLK_ROOT.outFreq, value: 150 MHz}
- {id: LCDIF_CLK_ROOT.outFreq, value: 67.5/7 MHz}
- {id: LCDIF_CLK_ROOT.outFreq, value: 67.5 MHz}
- {id: LPI2C_CLK_ROOT.outFreq, value: 60 MHz}
- {id: LPSPI_CLK_ROOT.outFreq, value: 105.6 MHz}
- {id: LVDS1_CLK.outFreq, value: 1.2 GHz}
@ -108,10 +108,8 @@ outputs:
settings:
- {id: CCM.AHB_PODF.scale, value: '1', locked: true}
- {id: CCM.ARM_PODF.scale, value: '2', locked: true}
- {id: CCM.FLEXSPI_PODF.scale, value: '1', locked: true}
- {id: CCM.FLEXSPI_SEL.sel, value: CCM_ANALOG.PLL3_PFD0_CLK}
- {id: CCM.LCDIF_PODF.scale, value: '8', locked: true}
- {id: CCM.LCDIF_PRED.scale, value: '7', locked: true}
- {id: CCM.FLEXSPI_PODF.scale, value: '3', locked: true}
- {id: CCM.FLEXSPI_SEL.sel, value: CCM.PLL3_SW_CLK_SEL}
- {id: CCM.LPSPI_PODF.scale, value: '5', locked: true}
- {id: CCM.PERCLK_PODF.scale, value: '2', locked: true}
- {id: CCM.SEMC_PODF.scale, value: '8'}
@ -148,23 +146,20 @@ sources:
/*******************************************************************************
* Variables for BOARD_BootClockRUN configuration
******************************************************************************/
const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN =
{
.loopDivider = 100, /* PLL loop divider, Fout = Fin * 50 */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN =
{
.loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */
.numerator = 0, /* 30 bit numerator of fractional loop divider */
.denominator = 1, /* 30 bit denominator of fractional loop divider */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN =
{
.loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN = {
.loopDivider = 100, /* PLL loop divider, Fout = Fin * 50 */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN = {
.loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */
.numerator = 0, /* 30 bit numerator of fractional loop divider */
.denominator = 1, /* 30 bit denominator of fractional loop divider */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN = {
.loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
/*******************************************************************************
* Code for BOARD_BootClockRUN configuration
******************************************************************************/
@ -229,9 +224,10 @@ void BOARD_BootClockRUN(void)
CLOCK_SetDiv(kCLOCK_Usdhc2Div, 1);
/* Set Usdhc2 clock source. */
CLOCK_SetMux(kCLOCK_Usdhc2Mux, 0);
/* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd.
* With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged.
* Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/
/* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd.
* With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left
* unchanged.
* Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/
#ifndef SKIP_SYSCLK_INIT
/* Disable Semc clock gate. */
CLOCK_DisableClock(kCLOCK_Semc);
@ -242,16 +238,17 @@ void BOARD_BootClockRUN(void)
/* Set Semc clock source. */
CLOCK_SetMux(kCLOCK_SemcMux, 0);
#endif
/* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd.
* With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged.
* Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/
/* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd.
* With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left
* unchanged.
* Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/
#if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1))
/* Disable Flexspi clock gate. */
CLOCK_DisableClock(kCLOCK_FlexSpi);
/* Set FLEXSPI_PODF. */
CLOCK_SetDiv(kCLOCK_FlexspiDiv, 0);
CLOCK_SetDiv(kCLOCK_FlexspiDiv, 2);
/* Set Flexspi clock source. */
CLOCK_SetMux(kCLOCK_FlexspiMux, 3);
CLOCK_SetMux(kCLOCK_FlexspiMux, 1);
#endif
/* Disable CSI clock gate. */
CLOCK_DisableClock(kCLOCK_Csi);
@ -331,9 +328,9 @@ void BOARD_BootClockRUN(void)
/* Disable LCDIF clock gate. */
CLOCK_DisableClock(kCLOCK_LcdPixel);
/* Set LCDIF_PRED. */
CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 6);
CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 1);
/* Set LCDIF_CLK_PODF. */
CLOCK_SetDiv(kCLOCK_LcdifDiv, 7);
CLOCK_SetDiv(kCLOCK_LcdifDiv, 3);
/* Set Lcdif pre clock source. */
CLOCK_SetMux(kCLOCK_LcdifPreMux, 5);
/* Disable SPDIF clock gate. */
@ -365,8 +362,9 @@ void BOARD_BootClockRUN(void)
/* Init ARM PLL. */
CLOCK_InitArmPll(&armPllConfig_BOARD_BootClockRUN);
/* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd.
* With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged.
* Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/
* With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left
* unchanged. Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as
* well.*/
#ifndef SKIP_SYSCLK_INIT
/* Init System PLL. */
CLOCK_InitSysPll(&sysPllConfig_BOARD_BootClockRUN);
@ -382,8 +380,9 @@ void BOARD_BootClockRUN(void)
CCM_ANALOG->PLL_SYS &= ~CCM_ANALOG_PLL_SYS_PFD_OFFSET_EN_MASK;
#endif
/* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd.
* With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged.
* Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/
* With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left
* unchanged. Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as
* well.*/
#if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1))
/* Init Usb1 PLL. */
CLOCK_InitUsb1Pll(&usb1PllConfig_BOARD_BootClockRUN);
@ -420,7 +419,8 @@ void BOARD_BootClockRUN(void)
/* Bypass Enet PLL. */
CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllEnet, 1);
/* Set Enet output divider. */
CCM_ANALOG->PLL_ENET = (CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1);
CCM_ANALOG->PLL_ENET =
(CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1);
/* Enable Enet output. */
CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENABLE_MASK;
/* Enable Enet25M output. */
@ -440,7 +440,8 @@ void BOARD_BootClockRUN(void)
/* Set per clock source. */
CLOCK_SetMux(kCLOCK_PerclkMux, 0);
/* Set lvds1 clock source. */
CCM_ANALOG->MISC1 = (CCM_ANALOG->MISC1 & (~CCM_ANALOG_MISC1_LVDS1_CLK_SEL_MASK)) | CCM_ANALOG_MISC1_LVDS1_CLK_SEL(0);
CCM_ANALOG->MISC1 =
(CCM_ANALOG->MISC1 & (~CCM_ANALOG_MISC1_LVDS1_CLK_SEL_MASK)) | CCM_ANALOG_MISC1_LVDS1_CLK_SEL(0);
/* Set clock out1 divider. */
CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_DIV_MASK)) | CCM_CCOSR_CLKO1_DIV(0);
/* Set clock out1 source. */
@ -466,7 +467,7 @@ void BOARD_BootClockRUN(void)
/* Set SAI3 MCLK3 clock source. */
IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI3MClk3Sel, 0);
/* Set MQS configuration. */
IOMUXC_MQSConfig(IOMUXC_GPR,kIOMUXC_MqsPwmOverSampleRate32, 0);
IOMUXC_MQSConfig(IOMUXC_GPR, kIOMUXC_MqsPwmOverSampleRate32, 0);
/* Set ENET Tx clock source. */
IOMUXC_EnableMode(IOMUXC_GPR, kIOMUXC_GPR_ENET1RefClkMode, false);
/* Set GPT1 High frequency reference clock source. */
@ -476,4 +477,3 @@ void BOARD_BootClockRUN(void)
/* Set SystemCoreClock variable. */
SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK;
}

View File

@ -0,0 +1,301 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: common.c
* @brief: file common.c
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2023/3/24
*/
#include "common.h"
static uint32_t UartSrcFreq(void)
{
uint32_t freq;
if (CLOCK_GetMux(kCLOCK_UartMux) == 0){
freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
} else {
freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
}
return freq;
}
void UartConfig(void)
{
lpuart_config_t config;
LPUART_GetDefaultConfig(&config);
config.baudRate_Bps = 115200u;
config.enableTx = true;
config.enableRx = true;
LPUART_Init(LPUART1, &config, UartSrcFreq());
}
/**
* @brief Convert an Integer to a string
* @param str: The string
* @param intnum: The intger to be converted
* @retval None
*/
void Int2Str(uint8_t* str, int32_t intnum)
{
uint32_t i, Div = 1000000000, j = 0, Status = 0;
for (i = 0; i < 10; i++)
{
str[j++] = (intnum / Div) + 48;
intnum = intnum % Div;
Div /= 10;
if ((str[j-1] == '0') & (Status == 0))
{
j = 0;
}
else
{
Status++;
}
}
}
/**
* @brief Convert a string to an integer
* @param inputstr: The string to be converted
* @param intnum: The intger value
* @retval 1: Correct
* 0: Error
*/
uint32_t Str2Int(uint8_t *inputstr, int32_t *intnum)
{
uint32_t i = 0, res = 0;
uint32_t val = 0;
if (inputstr[0] == '0' && (inputstr[1] == 'x' || inputstr[1] == 'X'))
{
if (inputstr[2] == '\0')
{
return 0;
}
for (i = 2; i < 11; i++)
{
if (inputstr[i] == '\0')
{
*intnum = val;
/* return 1; */
res = 1;
break;
}
if (ISVALIDHEX(inputstr[i]))
{
val = (val << 4) + CONVERTHEX(inputstr[i]);
}
else
{
/* return 0, Invalid input */
res = 0;
break;
}
}
/* over 8 digit hex --invalid */
if (i >= 11)
{
res = 0;
}
}
else /* max 10-digit decimal input */
{
for (i = 0;i < 11;i++)
{
if (inputstr[i] == '\0')
{
*intnum = val;
/* return 1 */
res = 1;
break;
}
else if ((inputstr[i] == 'k' || inputstr[i] == 'K') && (i > 0))
{
val = val << 10;
*intnum = val;
res = 1;
break;
}
else if ((inputstr[i] == 'm' || inputstr[i] == 'M') && (i > 0))
{
val = val << 20;
*intnum = val;
res = 1;
break;
}
else if (ISVALIDDEC(inputstr[i]))
{
val = val * 10 + CONVERTDEC(inputstr[i]);
}
else
{
/* return 0, Invalid input */
res = 0;
break;
}
}
/* Over 10 digit decimal --invalid */
if (i >= 11)
{
res = 0;
}
}
return res;
}
/**
* @brief Get an integer from the HyperTerminal
* @param num: The inetger
* @retval 1: Correct
* 0: Error
*/
uint32_t GetIntegerInput(int32_t * num)
{
uint8_t inputstr[16];
while (1)
{
GetInputString(inputstr);
if (inputstr[0] == '\0') continue;
if ((inputstr[0] == 'a' || inputstr[0] == 'A') && inputstr[1] == '\0')
{
Serial_PutString("User Cancelled \r\n");
return 0;
}
if (Str2Int(inputstr, num) == 0)
{
Serial_PutString("Error, Input again: \r\n");
}
else
{
return 1;
}
}
}
/**
* @brief Test to see if a key has been pressed on the HyperTerminal
* @param key: The key pressed
* @retval 1: Correct
* 0: Error
*/
uint32_t SerialKeyPressed(uint8_t *key)
{
if ((kLPUART_RxDataRegFullFlag)&LPUART_GetStatusFlags(LPUART1))
{
*key = LPUART_ReadByte(LPUART1);
return 1;
}
else
{
return 0;
}
}
/**
* @brief Get a key from the HyperTerminal
* @param None
* @retval The Key Pressed
*/
uint8_t GetKey(void)
{
uint8_t key = 0;
/* Waiting for user input */
while (1)
{
if (SerialKeyPressed((uint8_t*)&key)) break;
}
return key;
}
/**
* @brief Print a character on the HyperTerminal
* @param c: The character to be printed
* @retval None
*/
void SerialPutChar(uint8_t c)
{
LPUART_WriteByte(LPUART1,c);
while(!(kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(LPUART1)))
{
}
}
/**
* @brief Print a string on the HyperTerminal
* @param s: The string to be printed
* @retval None
*/
void Serial_PutString(uint8_t *s)
{
while (*s != '\0')
{
SerialPutChar(*s);
s++;
}
}
/**
* @brief Get Input string from the HyperTerminal
* @param buffP: The input string
* @retval None
*/
void GetInputString (uint8_t * buffP)
{
uint32_t bytes_read = 0;
uint8_t c = 0;
do
{
c = GetKey();
if (c == '\r')
break;
if (c == '\b') /* Backspace */
{
if (bytes_read > 0)
{
Serial_PutString("\b \b");
bytes_read --;
}
continue;
}
if (bytes_read >= CMD_STRING_SIZE )
{
Serial_PutString("Command string size overflow\r\n");
bytes_read = 0;
continue;
}
if (c >= 0x20 && c <= 0x7E)
{
buffP[bytes_read++] = c;
SerialPutChar(c);
}
}
while (1);
Serial_PutString(("\n\r"));
buffP[bytes_read] = '\0';
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 NXP
* Copyright 2017 - 2020 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
@ -26,7 +26,7 @@ achieve better performance, it is depend on the IDE Floating point settings, if
in IDE, clock_64b_t will switch to double type automatically. only support IAR and MDK here */
#if __FPU_USED
#if ((defined(__ICCARM__)) || (defined(__GNUC__)))
#if (defined(__ICCARM__))
#if (__ARMVFP__ >= __ARMFPV5__) && \
(__ARM_FP == 0xE) /*0xe implies support for half, single and double precision operations*/
@ -35,6 +35,14 @@ typedef double clock_64b_t;
typedef uint64_t clock_64b_t;
#endif
#elif (defined(__GNUC__))
#if (__ARM_FP == 0xE) /*0xe implies support for half, single and double precision operations*/
typedef double clock_64b_t;
#else
typedef uint64_t clock_64b_t;
#endif
#elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
#if defined __TARGET_FPU_FPV5_D16
@ -71,6 +79,13 @@ volatile uint32_t g_rtcXtalFreq;
*/
static uint32_t CLOCK_GetPeriphClkFreq(void);
/*!
* @brief Get the frequency of PLL USB1 software clock.
*
* @return The frequency of PLL USB1 software clock.
*/
static uint32_t CLOCK_GetPllUsb1SWFreq(void);
/*******************************************************************************
* Code
******************************************************************************/
@ -80,7 +95,7 @@ static uint32_t CLOCK_GetPeriphClkFreq(void)
uint32_t freq;
/* Periph_clk2_clk ---> Periph_clk */
if (CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK)
if ((CCM->CBCDR & CCM_CBCDR_PERIPH_CLK_SEL_MASK) != 0U)
{
switch (CCM->CBCMR & CCM_CBCMR_PERIPH_CLK2_SEL_MASK)
{
@ -141,6 +156,30 @@ static uint32_t CLOCK_GetPeriphClkFreq(void)
return freq;
}
static uint32_t CLOCK_GetPllUsb1SWFreq(void)
{
uint32_t freq;
switch ((CCM->CCSR & CCM_CCSR_PLL3_SW_CLK_SEL_MASK) >> CCM_CCSR_PLL3_SW_CLK_SEL_SHIFT)
{
case 0:
{
freq = CLOCK_GetPllFreq(kCLOCK_PllUsb1);
break;
}
case 1:
{
freq = 24000000UL;
break;
}
default:
freq = 0UL;
break;
}
return freq;
}
/*!
* brief Initialize the external 24MHz clock.
*
@ -161,11 +200,11 @@ void CLOCK_InitExternalClk(bool bypassXtalOsc)
assert(!bypassXtalOsc);
CCM_ANALOG->MISC0_CLR = CCM_ANALOG_MISC0_XTAL_24M_PWD_MASK; /* Power up */
while ((XTALOSC24M->LOWPWR_CTRL & XTALOSC24M_LOWPWR_CTRL_XTALOSC_PWRUP_STAT_MASK) == 0)
while ((XTALOSC24M->LOWPWR_CTRL & XTALOSC24M_LOWPWR_CTRL_XTALOSC_PWRUP_STAT_MASK) == 0U)
{
}
CCM_ANALOG->MISC0_SET = CCM_ANALOG_MISC0_OSC_XTALOK_EN_MASK; /* detect freq */
while ((CCM_ANALOG->MISC0 & CCM_ANALOG_MISC0_OSC_XTALOK_MASK) == 0)
while ((CCM_ANALOG->MISC0 & CCM_ANALOG_MISC0_OSC_XTALOK_MASK) == 0UL)
{
}
CCM_ANALOG->MISC0_CLR = CCM_ANALOG_MISC0_OSC_XTALOK_EN_MASK;
@ -194,9 +233,13 @@ void CLOCK_DeinitExternalClk(void)
void CLOCK_SwitchOsc(clock_osc_t osc)
{
if (osc == kCLOCK_RcOsc)
{
XTALOSC24M->LOWPWR_CTRL_SET = XTALOSC24M_LOWPWR_CTRL_SET_OSC_SEL_MASK;
}
else
{
XTALOSC24M->LOWPWR_CTRL_CLR = XTALOSC24M_LOWPWR_CTRL_CLR_OSC_SEL_MASK;
}
}
/*!
@ -235,10 +278,10 @@ uint32_t CLOCK_GetSemcFreq(void)
uint32_t freq;
/* SEMC alternative clock ---> SEMC Clock */
if (CCM->CBCDR & CCM_CBCDR_SEMC_CLK_SEL_MASK)
if ((CCM->CBCDR & CCM_CBCDR_SEMC_CLK_SEL_MASK) != 0U)
{
/* PLL3 PFD1 ---> SEMC alternative clock ---> SEMC Clock */
if (CCM->CBCDR & CCM_CBCDR_SEMC_ALT_CLK_SEL_MASK)
if ((CCM->CBCDR & CCM_CBCDR_SEMC_ALT_CLK_SEL_MASK) != 0U)
{
freq = CLOCK_GetUsb1PfdFreq(kCLOCK_Pfd1);
}
@ -279,14 +322,14 @@ uint32_t CLOCK_GetPerClkFreq(void)
uint32_t freq;
/* Osc_clk ---> PER Clock*/
if (CCM->CSCMR1 & CCM_CSCMR1_PERCLK_CLK_SEL_MASK)
if ((CCM->CSCMR1 & CCM_CSCMR1_PERCLK_CLK_SEL_MASK) != 0U)
{
freq = CLOCK_GetOscFreq();
}
/* Periph_clk ---> AHB Clock ---> IPG Clock ---> PER Clock */
else
{
freq = CLOCK_GetFreq(kCLOCK_IpgClk);
freq = CLOCK_GetIpgFreq();
}
freq /= (((CCM->CSCMR1 & CCM_CSCMR1_PERCLK_PODF_MASK) >> CCM_CSCMR1_PERCLK_PODF_SHIFT) + 1U);
@ -350,6 +393,18 @@ uint32_t CLOCK_GetFreq(clock_name_t name)
case kCLOCK_Usb1PllPfd3Clk:
freq = CLOCK_GetUsb1PfdFreq(kCLOCK_Pfd3);
break;
case kCLOCK_Usb1SwClk:
freq = CLOCK_GetPllUsb1SWFreq();
break;
case kCLOCK_Usb1Sw120MClk:
freq = CLOCK_GetPllUsb1SWFreq() / 4UL;
break;
case kCLOCK_Usb1Sw60MClk:
freq = CLOCK_GetPllUsb1SWFreq() / 8UL;
break;
case kCLOCK_Usb1Sw80MClk:
freq = CLOCK_GetPllUsb1SWFreq() / 6UL;
break;
case kCLOCK_Usb2PllClk:
freq = CLOCK_GetPllFreq(kCLOCK_PllUsb2);
break;
@ -388,6 +443,45 @@ uint32_t CLOCK_GetFreq(clock_name_t name)
return freq;
}
/*!
* brief Gets the frequency of selected clock root.
*
* param clockRoot The clock root used to get the frequency, please refer to @ref clock_root_t.
* return The frequency of selected clock root.
*/
uint32_t CLOCK_GetClockRootFreq(clock_root_t clockRoot)
{
const clock_name_t clockRootSourceArray[][6] = CLOCK_ROOT_SOUCE;
const clock_mux_t clockRootMuxTupleArray[] = CLOCK_ROOT_MUX_TUPLE;
const clock_div_t clockRootDivTupleArray[][2] = CLOCK_ROOT_DIV_TUPLE;
uint32_t freq = 0UL;
clock_mux_t clockRootMuxTuple = clockRootMuxTupleArray[(uint8_t)clockRoot];
clock_div_t clockRootPreDivTuple = clockRootDivTupleArray[(uint8_t)clockRoot][0];
clock_div_t clockRootPostDivTuple = clockRootDivTupleArray[(uint8_t)clockRoot][1];
uint32_t clockRootMuxValue = (CCM_TUPLE_REG(CCM, clockRootMuxTuple) & CCM_TUPLE_MASK(clockRootMuxTuple)) >>
CCM_TUPLE_SHIFT(clockRootMuxTuple);
clock_name_t clockSourceName;
clockSourceName = clockRootSourceArray[(uint8_t)clockRoot][clockRootMuxValue];
assert(clockSourceName != kCLOCK_NoneName);
freq = CLOCK_GetFreq(clockSourceName);
if (clockRootPreDivTuple != kCLOCK_NonePreDiv)
{
freq /= ((CCM_TUPLE_REG(CCM, clockRootPreDivTuple) & CCM_TUPLE_MASK(clockRootPreDivTuple)) >>
CCM_TUPLE_SHIFT(clockRootPreDivTuple)) +
1UL;
}
freq /= ((CCM_TUPLE_REG(CCM, clockRootPostDivTuple) & CCM_TUPLE_MASK(clockRootPostDivTuple)) >>
CCM_TUPLE_SHIFT(clockRootPostDivTuple)) +
1UL;
return freq;
}
/*! brief Enable USB HS clock.
*
* This function only enables the access to USB HS prepheral, upper layer
@ -401,10 +495,12 @@ uint32_t CLOCK_GetFreq(clock_name_t name)
*/
bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq)
{
uint32_t i;
CCM->CCGR6 |= CCM_CCGR6_CG0_MASK;
USB1->USBCMD |= USBHS_USBCMD_RST_MASK;
for (volatile uint32_t i = 0; i < 400000;
i++) /* Add a delay between RST and RS so make sure there is a DP pullup sequence*/
/* Add a delay between RST and RS so make sure there is a DP pullup sequence*/
for (i = 0; i < 400000U; i++)
{
__ASM("nop");
}
@ -426,10 +522,12 @@ bool CLOCK_EnableUsbhs0Clock(clock_usb_src_t src, uint32_t freq)
*/
bool CLOCK_EnableUsbhs1Clock(clock_usb_src_t src, uint32_t freq)
{
uint32_t i = 0;
CCM->CCGR6 |= CCM_CCGR6_CG0_MASK;
USB2->USBCMD |= USBHS_USBCMD_RST_MASK;
for (volatile uint32_t i = 0; i < 400000;
i++) /* Add a delay between RST and RS so make sure there is a DP pullup sequence*/
/* Add a delay between RST and RS so make sure there is a DP pullup sequence*/
for (i = 0; i < 400000U; i++)
{
__ASM("nop");
}
@ -450,7 +548,7 @@ bool CLOCK_EnableUsbhs1Clock(clock_usb_src_t src, uint32_t freq)
bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq)
{
const clock_usb_pll_config_t g_ccmConfigUsbPll = {.loopDivider = 0U};
if (CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_ENABLE_MASK)
if ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_ENABLE_MASK) != 0U)
{
CCM_ANALOG->PLL_USB1 |= CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK;
}
@ -494,7 +592,7 @@ void CLOCK_InitArmPll(const clock_arm_pll_config_t *config)
(CCM_ANALOG->PLL_ARM & (~(CCM_ANALOG_PLL_ARM_DIV_SELECT_MASK | CCM_ANALOG_PLL_ARM_POWERDOWN_MASK))) |
CCM_ANALOG_PLL_ARM_ENABLE_MASK | CCM_ANALOG_PLL_ARM_DIV_SELECT(config->loopDivider);
while ((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_ARM & CCM_ANALOG_PLL_ARM_LOCK_MASK) == 0UL)
{
}
@ -528,7 +626,7 @@ void CLOCK_InitSysPll(const clock_sys_pll_config_t *config)
CCM_ANALOG_PLL_SYS_ENABLE_MASK | CCM_ANALOG_PLL_SYS_DIV_SELECT(config->loopDivider);
/* Initialize the fractional mode */
CCM_ANALOG->PLL_SYS_NUM = CCM_ANALOG_PLL_SYS_NUM_A(config->numerator);
CCM_ANALOG->PLL_SYS_NUM = CCM_ANALOG_PLL_SYS_NUM_A(config->numerator);
CCM_ANALOG->PLL_SYS_DENOM = CCM_ANALOG_PLL_SYS_DENOM_B(config->denominator);
/* Initialize the spread spectrum mode */
@ -536,7 +634,7 @@ void CLOCK_InitSysPll(const clock_sys_pll_config_t *config)
CCM_ANALOG_PLL_SYS_SS_ENABLE(config->ss_enable) |
CCM_ANALOG_PLL_SYS_SS_STOP(config->ss_stop);
while ((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_LOCK_MASK) == 0UL)
{
}
@ -569,7 +667,7 @@ void CLOCK_InitUsb1Pll(const clock_usb_pll_config_t *config)
CCM_ANALOG_PLL_USB1_ENABLE_MASK | CCM_ANALOG_PLL_USB1_POWER_MASK |
CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK | CCM_ANALOG_PLL_USB1_DIV_SELECT(config->loopDivider);
while ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_LOCK_MASK) == 0UL)
{
}
@ -602,7 +700,7 @@ void CLOCK_InitUsb2Pll(const clock_usb_pll_config_t *config)
CCM_ANALOG_PLL_USB2_ENABLE_MASK | CCM_ANALOG_PLL_USB2_POWER_MASK |
CCM_ANALOG_PLL_USB2_EN_USB_CLKS_MASK | CCM_ANALOG_PLL_USB2_DIV_SELECT(config->loopDivider);
while ((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_LOCK_MASK) == 0UL)
{
}
@ -634,7 +732,7 @@ void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config)
CCM_ANALOG->PLL_AUDIO = (CCM_ANALOG->PLL_AUDIO & (~CCM_ANALOG_PLL_AUDIO_BYPASS_CLK_SRC_MASK)) |
CCM_ANALOG_PLL_AUDIO_BYPASS_MASK | CCM_ANALOG_PLL_AUDIO_BYPASS_CLK_SRC(config->src);
CCM_ANALOG->PLL_AUDIO_NUM = CCM_ANALOG_PLL_AUDIO_NUM_A(config->numerator);
CCM_ANALOG->PLL_AUDIO_NUM = CCM_ANALOG_PLL_AUDIO_NUM_A(config->numerator);
CCM_ANALOG->PLL_AUDIO_DENOM = CCM_ANALOG_PLL_AUDIO_DENOM_B(config->denominator);
/*
@ -689,7 +787,7 @@ void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config)
CCM_ANALOG->PLL_AUDIO = pllAudio;
while ((CCM_ANALOG->PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_LOCK_MASK) == 0UL)
{
}
@ -702,7 +800,7 @@ void CLOCK_InitAudioPll(const clock_audio_pll_config_t *config)
*/
void CLOCK_DeinitAudioPll(void)
{
CCM_ANALOG->PLL_AUDIO = CCM_ANALOG_PLL_AUDIO_POWERDOWN_MASK;
CCM_ANALOG->PLL_AUDIO = (uint32_t)CCM_ANALOG_PLL_AUDIO_POWERDOWN_MASK;
}
/*!
@ -721,7 +819,7 @@ void CLOCK_InitVideoPll(const clock_video_pll_config_t *config)
CCM_ANALOG->PLL_VIDEO = (CCM_ANALOG->PLL_VIDEO & (~CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC_MASK)) |
CCM_ANALOG_PLL_VIDEO_BYPASS_MASK | CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC(config->src);
CCM_ANALOG->PLL_VIDEO_NUM = CCM_ANALOG_PLL_VIDEO_NUM_A(config->numerator);
CCM_ANALOG->PLL_VIDEO_NUM = CCM_ANALOG_PLL_VIDEO_NUM_A(config->numerator);
CCM_ANALOG->PLL_VIDEO_DENOM = CCM_ANALOG_PLL_VIDEO_DENOM_B(config->denominator);
/*
@ -775,7 +873,7 @@ void CLOCK_InitVideoPll(const clock_video_pll_config_t *config)
CCM_ANALOG->PLL_VIDEO = pllVideo;
while ((CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_LOCK_MASK) == 0UL)
{
}
@ -820,7 +918,7 @@ void CLOCK_InitEnetPll(const clock_enet_pll_config_t *config)
enet_pll;
/* Wait for stable */
while ((CCM_ANALOG->PLL_ENET & CCM_ANALOG_PLL_ENET_LOCK_MASK) == 0)
while ((CCM_ANALOG->PLL_ENET & CCM_ANALOG_PLL_ENET_LOCK_MASK) == 0UL)
{
}
@ -883,10 +981,10 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
break;
case kCLOCK_PllSys:
/* PLL output frequency = Fref * (DIV_SELECT + NUM/DENOM). */
freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_SYS_NUM))) /
((clock_64b_t)(CCM_ANALOG->PLL_SYS_DENOM));
freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_SYS_NUM)));
freqTmp /= ((clock_64b_t)(CCM_ANALOG->PLL_SYS_DENOM));
if (CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK)
if ((CCM_ANALOG->PLL_SYS & CCM_ANALOG_PLL_SYS_DIV_SELECT_MASK) != 0U)
{
freq *= 22U;
}
@ -899,7 +997,7 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
break;
case kCLOCK_PllUsb1:
freq = (freq * ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) ? 22U : 20U));
freq = (freq * (((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) != 0UL) ? 22U : 20U));
break;
case kCLOCK_PllAudio:
@ -907,8 +1005,8 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
divSelect =
(CCM_ANALOG->PLL_AUDIO & CCM_ANALOG_PLL_AUDIO_DIV_SELECT_MASK) >> CCM_ANALOG_PLL_AUDIO_DIV_SELECT_SHIFT;
freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_NUM))) /
((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_DENOM));
freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_NUM)));
freqTmp /= ((clock_64b_t)(CCM_ANALOG->PLL_AUDIO_DENOM));
freq = freq * divSelect + (uint32_t)freqTmp;
@ -938,7 +1036,12 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
freq = freq >> 1U;
break;
case CCM_ANALOG_PLL_AUDIO_POST_DIV_SELECT(2U):
freq = freq >> 0U;
break;
default:
assert(false);
break;
}
@ -952,7 +1055,13 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
freq >>= 1U;
break;
case CCM_ANALOG_MISC2_AUDIO_DIV_MSB(0) | CCM_ANALOG_MISC2_AUDIO_DIV_LSB(0):
case CCM_ANALOG_MISC2_AUDIO_DIV_MSB(1) | CCM_ANALOG_MISC2_AUDIO_DIV_LSB(0):
freq >>= 0U;
break;
default:
assert(false);
break;
}
break;
@ -962,9 +1071,8 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
divSelect =
(CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_DIV_SELECT_MASK) >> CCM_ANALOG_PLL_VIDEO_DIV_SELECT_SHIFT;
freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_NUM))) /
((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_DENOM));
freqTmp = ((clock_64b_t)freq * ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_NUM)));
freqTmp /= ((clock_64b_t)(CCM_ANALOG->PLL_VIDEO_DENOM));
freq = freq * divSelect + (uint32_t)freqTmp;
/* VIDEO PLL output = PLL output frequency / POSTDIV. */
@ -993,21 +1101,32 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
freq = freq >> 1U;
break;
case CCM_ANALOG_PLL_VIDEO_POST_DIV_SELECT(2U):
freq = freq >> 0U;
break;
default:
assert(false);
break;
}
switch (CCM_ANALOG->MISC2 & CCM_ANALOG_MISC2_VIDEO_DIV_MASK)
{
case CCM_ANALOG_MISC2_VIDEO_DIV(3):
case CCM_ANALOG_MISC2_VIDEO_DIV(3U):
freq >>= 2U;
break;
case CCM_ANALOG_MISC2_VIDEO_DIV(1):
case CCM_ANALOG_MISC2_VIDEO_DIV(1U):
freq >>= 1U;
break;
case CCM_ANALOG_MISC2_VIDEO_DIV(0U):
case CCM_ANALOG_MISC2_VIDEO_DIV(2U):
freq >>= 0U;
break;
default:
assert(false);
break;
}
break;
@ -1023,7 +1142,7 @@ uint32_t CLOCK_GetPllFreq(clock_pll_t pll)
break;
case kCLOCK_PllUsb2:
freq = (freq * ((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_DIV_SELECT_MASK) ? 22U : 20U));
freq = (freq * (((CCM_ANALOG->PLL_USB2 & CCM_ANALOG_PLL_USB2_DIV_SELECT_MASK) != 0U) ? 22U : 20U));
break;
default:
freq = 0U;
@ -1049,13 +1168,14 @@ void CLOCK_InitSysPfd(clock_pfd_t pfd, uint8_t pfdFrac)
uint32_t pfd528;
pfd528 = CCM_ANALOG->PFD_528 &
~((CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_528_PFD0_FRAC_MASK) << (8 * pfdIndex));
~(((uint32_t)((uint32_t)CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_528_PFD0_FRAC_MASK)
<< (8UL * pfdIndex)));
/* Disable the clock output first. */
CCM_ANALOG->PFD_528 = pfd528 | (CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8 * pfdIndex));
CCM_ANALOG->PFD_528 = pfd528 | ((uint32_t)CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8UL * pfdIndex));
/* Set the new value and enable output. */
CCM_ANALOG->PFD_528 = pfd528 | (CCM_ANALOG_PFD_528_PFD0_FRAC(pfdFrac) << (8 * pfdIndex));
CCM_ANALOG->PFD_528 = pfd528 | (CCM_ANALOG_PFD_528_PFD0_FRAC(pfdFrac) << (8UL * pfdIndex));
}
/*!
@ -1067,7 +1187,7 @@ void CLOCK_InitSysPfd(clock_pfd_t pfd, uint8_t pfdFrac)
*/
void CLOCK_DeinitSysPfd(clock_pfd_t pfd)
{
CCM_ANALOG->PFD_528 |= CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8 * pfd);
CCM_ANALOG->PFD_528 |= (uint32_t)CCM_ANALOG_PFD_528_PFD0_CLKGATE_MASK << (8U * (uint8_t)pfd);
}
/*!
@ -1086,13 +1206,14 @@ void CLOCK_InitUsb1Pfd(clock_pfd_t pfd, uint8_t pfdFrac)
uint32_t pfd480;
pfd480 = CCM_ANALOG->PFD_480 &
~((CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_480_PFD0_FRAC_MASK) << (8 * pfdIndex));
~(((uint32_t)((uint32_t)CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK | CCM_ANALOG_PFD_480_PFD0_FRAC_MASK)
<< (8UL * pfdIndex)));
/* Disable the clock output first. */
CCM_ANALOG->PFD_480 = pfd480 | (CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8 * pfdIndex));
CCM_ANALOG->PFD_480 = pfd480 | ((uint32_t)CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8UL * pfdIndex));
/* Set the new value and enable output. */
CCM_ANALOG->PFD_480 = pfd480 | (CCM_ANALOG_PFD_480_PFD0_FRAC(pfdFrac) << (8 * pfdIndex));
CCM_ANALOG->PFD_480 = pfd480 | (CCM_ANALOG_PFD_480_PFD0_FRAC(pfdFrac) << (8UL * pfdIndex));
}
/*!
@ -1104,7 +1225,7 @@ void CLOCK_InitUsb1Pfd(clock_pfd_t pfd, uint8_t pfdFrac)
*/
void CLOCK_DeinitUsb1Pfd(clock_pfd_t pfd)
{
CCM_ANALOG->PFD_480 |= CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8 * pfd);
CCM_ANALOG->PFD_480 |= (uint32_t)CCM_ANALOG_PFD_480_PFD0_CLKGATE_MASK << (8UL * (uint8_t)pfd);
}
/*!
@ -1217,3 +1338,180 @@ void CLOCK_DisableUsbhs1PhyPllClock(void)
CCM_ANALOG->PLL_USB2 &= ~CCM_ANALOG_PLL_USB2_EN_USB_CLKS_MASK;
USBPHY2->CTRL |= USBPHY_CTRL_CLKGATE_MASK; /* Set to 1U to gate clocks */
}
/*!
* brief Set the clock source and the divider of the clock output1.
*
* param selection The clock source to be output, please refer to clock_output1_selection_t.
* param divider The divider of the output clock signal, please refer to clock_output_divider_t.
*/
void CLOCK_SetClockOutput1(clock_output1_selection_t selection, clock_output_divider_t divider)
{
uint32_t tmp32;
tmp32 = CCM->CCOSR;
if (selection == kCLOCK_DisableClockOutput1)
{
tmp32 &= ~CCM_CCOSR_CLKO1_EN_MASK;
}
else
{
tmp32 |= CCM_CCOSR_CLKO1_EN_MASK;
tmp32 &= ~(CCM_CCOSR_CLKO1_SEL_MASK | CCM_CCOSR_CLKO1_DIV_MASK);
tmp32 |= CCM_CCOSR_CLKO1_SEL(selection) | CCM_CCOSR_CLKO1_DIV(divider);
}
CCM->CCOSR = tmp32;
}
/*!
* brief Set the clock source and the divider of the clock output2.
*
* param selection The clock source to be output, please refer to clock_output2_selection_t.
* param divider The divider of the output clock signal, please refer to clock_output_divider_t.
*/
void CLOCK_SetClockOutput2(clock_output2_selection_t selection, clock_output_divider_t divider)
{
uint32_t tmp32;
tmp32 = CCM->CCOSR;
if (selection == kCLOCK_DisableClockOutput2)
{
tmp32 &= CCM_CCOSR_CLKO2_EN_MASK;
}
else
{
tmp32 |= CCM_CCOSR_CLKO2_EN_MASK;
tmp32 &= ~(CCM_CCOSR_CLKO2_SEL_MASK | CCM_CCOSR_CLKO2_DIV_MASK);
tmp32 |= CCM_CCOSR_CLKO2_SEL(selection) | CCM_CCOSR_CLKO2_DIV(divider);
}
CCM->CCOSR = tmp32;
}
/*!
* brief Get the frequency of clock output1 clock signal.
*
* return The frequency of clock output1 clock signal.
*/
uint32_t CLOCK_GetClockOutCLKO1Freq(void)
{
uint32_t freq = 0U;
uint32_t tmp32;
tmp32 = CCM->CCOSR;
if ((tmp32 & CCM_CCOSR_CLKO1_EN_MASK) != 0UL)
{
switch ((tmp32 & CCM_CCOSR_CLKO1_SEL_MASK) >> CCM_CCOSR_CLKO1_SEL_SHIFT)
{
case (uint32_t)kCLOCK_OutputPllUsb1:
freq = CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 2U;
break;
case (uint32_t)kCLOCK_OutputPllSys:
freq = CLOCK_GetPllFreq(kCLOCK_PllSys) / 2U;
break;
case (uint32_t)kCLOCK_OutputPllVideo:
freq = CLOCK_GetPllFreq(kCLOCK_PllVideo) / 2U;
break;
case (uint32_t)kCLOCK_OutputSemcClk:
freq = CLOCK_GetSemcFreq();
break;
case (uint32_t)kCLOCK_OutputLcdifPixClk:
freq = CLOCK_GetClockRootFreq(kCLOCK_LcdifClkRoot);
break;
case (uint32_t)kCLOCK_OutputAhbClk:
freq = CLOCK_GetAhbFreq();
break;
case (uint32_t)kCLOCK_OutputIpgClk:
freq = CLOCK_GetIpgFreq();
break;
case (uint32_t)kCLOCK_OutputPerClk:
freq = CLOCK_GetPerClkFreq();
break;
case (uint32_t)kCLOCK_OutputCkilSyncClk:
freq = CLOCK_GetRtcFreq();
break;
case (uint32_t)kCLOCK_OutputPll4MainClk:
freq = CLOCK_GetPllFreq(kCLOCK_PllAudio);
break;
default:
/* This branch should never be hit. */
break;
}
freq /= (((tmp32 & CCM_CCOSR_CLKO1_DIV_MASK) >> CCM_CCOSR_CLKO1_DIV_SHIFT) + 1U);
}
else
{
freq = 0UL;
}
return freq;
}
/*!
* brief Get the frequency of clock output2 clock signal.
*
* return The frequency of clock output2 clock signal.
*/
uint32_t CLOCK_GetClockOutClkO2Freq(void)
{
uint32_t freq = 0U;
uint32_t tmp32;
tmp32 = CCM->CCOSR;
if ((tmp32 & CCM_CCOSR_CLKO2_EN_MASK) != 0UL)
{
switch ((tmp32 & CCM_CCOSR_CLKO2_SEL_MASK) >> CCM_CCOSR_CLKO2_SEL_SHIFT)
{
case (uint32_t)kCLOCK_OutputUsdhc1Clk:
freq = CLOCK_GetClockRootFreq(kCLOCK_Usdhc1ClkRoot);
break;
case (uint32_t)kCLOCK_OutputLpi2cClk:
freq = CLOCK_GetClockRootFreq(kCLOCK_Lpi2cClkRoot);
break;
case (uint32_t)kCLOCK_OutputCsiClk:
freq = CLOCK_GetClockRootFreq(kCLOCK_CsiClkRoot);
break;
case (uint32_t)kCLOCK_OutputOscClk:
freq = CLOCK_GetOscFreq();
break;
case (uint32_t)kCLOCK_OutputUsdhc2Clk:
freq = CLOCK_GetClockRootFreq(kCLOCK_Usdhc2ClkRoot);
break;
case (uint32_t)kCLOCK_OutputSai1Clk:
freq = CLOCK_GetClockRootFreq(kCLOCK_Sai1ClkRoot);
break;
case (uint32_t)kCLOCK_OutputSai2Clk:
freq = CLOCK_GetClockRootFreq(kCLOCK_Sai2ClkRoot);
break;
case (uint32_t)kCLOCK_OutputSai3Clk:
freq = CLOCK_GetClockRootFreq(kCLOCK_Sai3ClkRoot);
break;
case (uint32_t)kCLOCK_OutputCanClk:
freq = CLOCK_GetClockRootFreq(kCLOCK_CanClkRoot);
break;
case (uint32_t)kCLOCK_OutputFlexspiClk:
freq = CLOCK_GetClockRootFreq(kCLOCK_FlexspiClkRoot);
break;
case (uint32_t)kCLOCK_OutputUartClk:
freq = CLOCK_GetClockRootFreq(kCLOCK_UartClkRoot);
break;
case (uint32_t)kCLOCK_OutputSpdif0Clk:
freq = CLOCK_GetClockRootFreq(kCLOCK_SpdifClkRoot);
break;
default:
/* This branch should never be hit. */
break;
}
freq /= (((tmp32 & CCM_CCOSR_CLKO2_DIV_MASK) >> CCM_CCOSR_CLKO2_DIV_SHIFT) + 1U);
}
else
{
freq = 0UL;
}
return freq;
}

View File

@ -135,16 +135,16 @@ void *SDK_Malloc(size_t size, size_t alignbytes)
p_align_addr = (void *)SDK_SIZEALIGN((uint32_t)p_addr + sizeof(mem_align_cb_t), alignbytes);
p_cb = (mem_align_cb_t *)((uint32_t)p_align_addr - 4);
p_cb = (mem_align_cb_t *)((uint32_t)p_align_addr - 4U);
p_cb->identifier = SDK_MEM_MAGIC_NUMBER;
p_cb->offset = (uint32_t)p_align_addr - (uint32_t)p_addr;
p_cb->offset = (uint32_t)p_align_addr - (uint32_t)p_addr;
return (void *)p_align_addr;
}
void SDK_Free(void *ptr)
{
mem_align_cb_t *p_cb = (mem_align_cb_t *)((uint32_t)ptr - 4);
mem_align_cb_t *p_cb = (mem_align_cb_t *)((uint32_t)ptr - 4U);
if (p_cb->identifier != SDK_MEM_MAGIC_NUMBER)
{

Some files were not shown because too many files have changed in this diff Show More