Merge branch 'smp' of https://gitlink.org.cn/tuyuyang/xiuos into smp
|
@ -1,3 +1,3 @@
|
|||
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence ab abb
|
||||
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence panasonic fatek ab abb
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
After Width: | Height: | Size: 3.0 MiB |
|
@ -1,22 +1,48 @@
|
|||
# 台达 DVP通信测试
|
||||
# 台达 PLC与矽达通ARM通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 通信接线及参数设置
|
||||
## 台达DVP与矽达通ARM通信处测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 网口
|
||||
* 通过自带 RJ45 网口连接
|
||||
* 网口参数:IP:192.168.250.27 Port:502
|
||||
* 测试的协议:Modbus TCP
|
||||
|
||||
## 存储区
|
||||
### 存储区
|
||||
|
||||
- 含M,D,X,Y。台达PLC中 各存储区地址和Modbus地址有明确的对应表,详见台达DVP协议解析测试文档。
|
||||
|
||||
## 通信测试
|
||||
### 通信测试
|
||||
|
||||
- 共测试BOOL,INT16,INT32,FLOAT 共四种类型数据。
|
||||
- 测试D区,M区和Y区。
|
||||
|
||||
|
||||
|
||||
## 台达AS332T与矽达通ARM通信处测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 网口
|
||||
* 通过自带 RJ45 网口连接
|
||||
* 网口参数:IP:192.168.250.5 Port:502
|
||||
* 测试的协议:Modbus TCP
|
||||
|
||||
### 存储区
|
||||
|
||||
- 含M,D,X,Y。台达PLC中 各存储区地址和Modbus地址有明确的对应表,详见台达AS332T协议解析测试文档。
|
||||
|
||||
### 通信测试结果
|
||||
|
||||
- 共测试BOOL,INT16,INT32,FLOAT 共四种类型数据。
|
||||
- 测试D区,M区和Y区。
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
/*
|
||||
* 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.
|
||||
|
@ -15,9 +17,53 @@
|
|||
* @brief PLC DELTA AS332T app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.9.27
|
||||
* @date 2022.10.10
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlDeltaas332tTest(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(ControlDeltaas332tTest, Delta as332t Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
After Width: | Height: | Size: 123 KiB |
After Width: | Height: | Size: 171 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 14 KiB |
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "DELTA_AS332T_TCP",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.5",
|
||||
"local_ip": "192.168.250.233",
|
||||
"gateway": "192.168.250.1",
|
||||
"netmask": "255.255.254.0",
|
||||
"port": 502
|
||||
},
|
||||
"protocol_type": 2,
|
||||
"read_period": 1000,
|
||||
"read_item_list": [
|
||||
{
|
||||
"value_name": "M16",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 16,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "M17",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 17,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "M18",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 30,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "D300",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 300,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "D301",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 302,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "D302",
|
||||
"value_type": 4,
|
||||
"function_code": 3,
|
||||
"start_address": 302,
|
||||
"quantity": 2
|
||||
},
|
||||
{
|
||||
"value_name": "D304",
|
||||
"value_type": 9,
|
||||
"function_code": 3,
|
||||
"start_address": 304,
|
||||
"quantity": 2
|
||||
},
|
||||
{
|
||||
"value_name": "Y1.0",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 40976,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "Y10",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 40970,
|
||||
"quantity": 1
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := fatek_fbs_24mc_uart.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,42 @@
|
|||
# 永宏通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 永宏FBs-24MCT2-AC通信测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 网口和串口
|
||||
* FBS-24MCT2自带圆口232,用于程序的下载。
|
||||
* 可本体拓展FBs-CBES用于Modbus TCP,永宏私有协议永宏协议等通信。板卡默认IP:192.168.2.3.端口号500,永宏协议
|
||||
* 通过本体拓展FBs-CM22通信模板,可用于Modbus RTU及永宏协议通信。串口接线:+接485A;-接485B。
|
||||
* 串口模块MODBUS RTU通信参数配置:通信速率:9600;数据位:8bit;停止位:1bit;校验:偶校验
|
||||
* 串口模块永宏协议通信参数配置:通信速率:9600;数据位:8bit;停止位:1bit;校验:偶校验
|
||||
* 终端与PLC通信测试,PC编程软件与PLC不能处于联机状态。
|
||||
|
||||
|
||||
### 存储区
|
||||
|
||||
- 存储区 X,Y,R,D区等。
|
||||
|
||||
### 通信测试
|
||||
|
||||
- 共测试BOOL,INT16等类型数据。
|
||||
|
||||
|
||||
- 测试Y区,R区及D区数据。
|
||||
|
||||
|
||||
- 测试截图:
|
||||
|
||||
测试PLC环境搭建:
|
||||
|
||||

|
||||
|
||||
解析完成的配方为:
|
||||
|
||||

|
||||
|
||||
测试结果:
|
||||
|
||||

|
|
@ -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 fatek_fbs_24mc_uart.c
|
||||
* @brief PLC fatek fbs app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.11.28
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlFatekFBsUartTest(void)
|
||||
{
|
||||
int i, j = 0;
|
||||
int read_data_length = 0;
|
||||
uint8_t read_data[128] = {0};
|
||||
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
Adapter4GActive();
|
||||
#endif
|
||||
|
||||
ControlProtocolType modbus_rtu_protocol = ControlProtocolFind();
|
||||
if (NULL == modbus_rtu_protocol) {
|
||||
printf("%s get modbus rtu protocol %p failed\n", __func__, modbus_rtu_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get modbus rtu protocol %p successfull\n", __func__, modbus_rtu_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == modbus_rtu_protocol->protocol_status) {
|
||||
ControlProtocolOpen(modbus_rtu_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(modbus_rtu_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] modbus rtu 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_rtu_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlFatekFBsUartTest, fatek fbs uart Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
After Width: | Height: | Size: 172 KiB |
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "FATEK_FBSMC24T_RTU",
|
||||
"communication_type": 1,
|
||||
"serial_config": {
|
||||
"station": 1,
|
||||
"baud_rate": 9600,
|
||||
"data_bits": 8,
|
||||
"stop_bits": 1,
|
||||
"check_mode":3
|
||||
},
|
||||
"protocol_type": 3,
|
||||
"read_period": 2000,
|
||||
"read_item_list": [
|
||||
{
|
||||
"value_name": "Y0",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "D0",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 6000,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R10",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 10,
|
||||
"quantity": 1
|
||||
}
|
||||
]
|
||||
}
|
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 3.1 MiB |
After Width: | Height: | Size: 200 KiB |
|
@ -1,3 +1,3 @@
|
|||
SRC_FILES := mitsubishi_fx3u.c mitsubishi_fx5u.c mitsubishi_fx2n.c mitsubishi_q02u.c
|
||||
SRC_FILES := mitsubishi_fx3u.c mitsubishi_fx5u.c mitsubishi_fx2n.c mitsubishi_q02u.c mitsubishi_q06h.c mitsubishi_q03udv.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -1,24 +1,88 @@
|
|||
# 三菱 FX2N通信测试
|
||||
# 三菱通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 通信接线及参数设置
|
||||
## 三菱FX2N通信测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 串口
|
||||
* FX2N自带8针圆口422,用于程序的下载。全系列不支持网口,且需购买串口拓展模块FX2N-485-BD用于通信测试。
|
||||
* 接线:RDA和SDA短接,引出A;RDB与SDB短接,引出B。
|
||||
* 串口模块支持MC-1C协议,通信速率:9600;数据位:7bit;停止位:1bit;校验:偶校验
|
||||
|
||||
## 存储区
|
||||
### 存储区
|
||||
|
||||
- 存储区 I,Q,M,D区。
|
||||
|
||||
## 通信测试
|
||||
### 通信测试
|
||||
|
||||
- 共测试BOOL,INT16,FLOAT共三种类型数据。
|
||||
|
||||
|
||||
- 测试M区及D区数据。
|
||||
|
||||
## 三菱Q06H通信测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 接口
|
||||
* 首次连接时,可通过CPU自带的串口(打印机方口线)进行程序的下载。
|
||||
* 本次测试通过Q06H拓展的模块QJ71E71_100模块的网口模块进行MC—3E通信测试。
|
||||
* PLC网口模块IP:192.168.250.21 端口号:4000
|
||||
|
||||
### 存储区
|
||||
|
||||
- 存储区 I,Q,M,D区。
|
||||
|
||||
### 通信测试
|
||||
|
||||
- 共测试BOOL,INT16,FLOAT共三种类型数据。
|
||||
|
||||
|
||||
- 测试M区及D区数据。
|
||||
|
||||
- 测试截图:
|
||||
|
||||
解析完成的配方为
|
||||
|
||||

|
||||
|
||||
测试结果:
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## 三菱Q03UDV通信测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 接口
|
||||
* 本次测试通过Q03UDV拓展的模块QJ71E71_100模块的网口模块进行MC—3E通信测试。网口模块IP:192.168.250.21 端口号:4000
|
||||
* 本次测试还可通过Q03UDV自身网口进行MC—3E通信测试。网口模块IP:192.168.250.22 端口号:6000
|
||||
|
||||
### 存储区
|
||||
|
||||
- 存储区 I,Q,M,D区。
|
||||
|
||||
### 通信测试
|
||||
|
||||
- 共测试BOOL,INT16,FLOAT共三种类型数据。
|
||||
|
||||
|
||||
- 测试M区及D区数据。
|
||||
|
||||
- 测试截图:
|
||||
|
||||
扩展模块解析完成的配方为
|
||||
|
||||

|
||||
|
||||
CPU自带网口解析完成的配方为
|
||||
|
||||

|
||||
|
||||
测试结果:
|
||||
|
||||

|
||||
|
|
After Width: | Height: | Size: 2.8 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 158 KiB |
After Width: | Height: | Size: 164 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 156 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 6.8 KiB |
|
@ -0,0 +1,368 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "FX3U_MC_1E",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.25",
|
||||
"local_ip": "192.168.250.233",
|
||||
"gateway": "192.168.250.1",
|
||||
"netmask": "255.255.254.0",
|
||||
"port": 2000
|
||||
},
|
||||
"protocol_type": 6,
|
||||
"read_period": 2000,
|
||||
"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
|
||||
},
|
||||
{
|
||||
"value_name": "Y001",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "1",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "Y002",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "2",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "Y010",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "10",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "D400",
|
||||
"value_type": 4,
|
||||
"device_code": "D",
|
||||
"head_device_number_string": "400",
|
||||
"device_points_count": 2,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
}
|
||||
|
||||
]
|
||||
}
|
|
@ -0,0 +1,331 @@
|
|||
{
|
||||
"device_id": 769,
|
||||
"device_name": "Q02UCPU",
|
||||
"communication_type": 1,
|
||||
"serial_config": {
|
||||
"station": 0,
|
||||
"baud_rate": 19200,
|
||||
"data_bits": 7,
|
||||
"stop_bits": 1,
|
||||
"check_mode": 3
|
||||
},
|
||||
"protocol_type": 10,
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,494 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "Q02UCPU_MC_3E",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.21",
|
||||
"local_ip": "192.168.250.233",
|
||||
"gateway": "192.168.250.1",
|
||||
"netmask": "255.255.254.0",
|
||||
"port": 4000
|
||||
},
|
||||
"protocol_type": 7,
|
||||
"read_period": 2000,
|
||||
"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
|
||||
},
|
||||
{
|
||||
"value_name": "Y001",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "1",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "Y002",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "2",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "Y010",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "10",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "D400",
|
||||
"value_type": 4,
|
||||
"device_code": "D",
|
||||
"head_device_number_string": "400",
|
||||
"device_points_count": 2,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "D402",
|
||||
"value_type": 8,
|
||||
"device_code": "D",
|
||||
"head_device_number_string": "402",
|
||||
"device_points_count": 4,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "D406",
|
||||
"value_type": 8,
|
||||
"device_code": "D",
|
||||
"head_device_number_string": "406",
|
||||
"device_points_count": 4,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "B1",
|
||||
"value_type": 1,
|
||||
"device_code": "B",
|
||||
"head_device_number_string": "1",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "B10",
|
||||
"value_type": 1,
|
||||
"device_code": "B",
|
||||
"head_device_number_string": "10",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "B20",
|
||||
"value_type": 1,
|
||||
"device_code": "B",
|
||||
"head_device_number_string": "20",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "W1",
|
||||
"value_type": 3,
|
||||
"device_code": "W",
|
||||
"head_device_number_string": "1",
|
||||
"device_points_count": 1,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "W2",
|
||||
"value_type": 4,
|
||||
"device_code": "W",
|
||||
"head_device_number_string": "2",
|
||||
"device_points_count": 2,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "W4",
|
||||
"value_type": 9,
|
||||
"device_code": "W",
|
||||
"head_device_number_string": "4",
|
||||
"device_points_count": 2,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "W6",
|
||||
"value_type": 8,
|
||||
"device_code": "W",
|
||||
"head_device_number_string": "6",
|
||||
"device_points_count": 4,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "W22",
|
||||
"value_type": 3,
|
||||
"device_code": "W",
|
||||
"head_device_number_string": "22",
|
||||
"device_points_count": 1,
|
||||
"command_type": 1,
|
||||
"monitoring_timer": 100
|
||||
},
|
||||
{
|
||||
"value_name": "B44",
|
||||
"value_type": 1,
|
||||
"device_code": "B",
|
||||
"head_device_number_string": "44",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 500
|
||||
},
|
||||
{
|
||||
"value_name": "B200",
|
||||
"value_type": 1,
|
||||
"device_code": "B",
|
||||
"head_device_number_string": "200",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 500
|
||||
},
|
||||
{
|
||||
"value_name": "Y100",
|
||||
"value_type": 1,
|
||||
"device_code": "Y",
|
||||
"head_device_number_string": "100",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 500
|
||||
},
|
||||
{
|
||||
"value_name": "X150",
|
||||
"value_type": 1,
|
||||
"device_code": "X",
|
||||
"head_device_number_string": "150",
|
||||
"device_points_count": 1,
|
||||
"command_type": 0,
|
||||
"monitoring_timer": 500
|
||||
}
|
||||
|
||||
]
|
||||
}
|
|
@ -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 mitsubishi_q03udv.c
|
||||
* @brief PLC MITSUBISHI Q03udv app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.10.30
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlQ03udvTest(void)
|
||||
{
|
||||
int i, j = 0;
|
||||
int read_data_length = 0;
|
||||
uint8_t read_data[128] = {0};
|
||||
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
Adapter4GActive();
|
||||
#endif
|
||||
|
||||
ControlProtocolType melsec_3e_protocol = ControlProtocolFind();
|
||||
if (NULL == melsec_3e_protocol) {
|
||||
printf("%s get melsec 3e protocol %p failed\n", __func__, melsec_3e_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get melsec 3e protocol %p successfull\n", __func__, melsec_3e_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == melsec_3e_protocol->protocol_status) {
|
||||
ControlProtocolOpen(melsec_3e_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(melsec_3e_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] melsec 3c 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(melsec_3c_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlQ03udvTest, Mitsubishi Q03udv Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
|
@ -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 mitsubishi_q06h.c
|
||||
* @brief PLC MITSUBISHI Q06H app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.10.30
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlQ06hTest(void)
|
||||
{
|
||||
int i, j = 0;
|
||||
int read_data_length = 0;
|
||||
uint8_t read_data[128] = {0};
|
||||
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
Adapter4GActive();
|
||||
#endif
|
||||
|
||||
ControlProtocolType melsec_3e_protocol = ControlProtocolFind();
|
||||
if (NULL == melsec_3e_protocol) {
|
||||
printf("%s get melsec 3e protocol %p failed\n", __func__, melsec_3e_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get melsec 3e protocol %p successfull\n", __func__, melsec_3e_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == melsec_3e_protocol->protocol_status) {
|
||||
ControlProtocolOpen(melsec_3e_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(melsec_3e_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] melsec 3c 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(melsec_3c_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlQ06hTest, Mitsubishi Q06H Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "NJ501",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.22",
|
||||
"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": "整型1",
|
||||
"value_type": 3,
|
||||
"area_char": "D",
|
||||
"data_type": 1,
|
||||
"start_address": 100,
|
||||
"bit_address": 0,
|
||||
"data_length": 1
|
||||
}
|
||||
]
|
||||
}
|
|
@ -18,6 +18,34 @@
|
|||
* @date 2022.9.27
|
||||
*/
|
||||
|
||||
|
||||
#include <control.h>
|
||||
|
||||
void ControlNj501Test(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(ControlNj501Test, Omron Plc FINS Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
SRC_FILES := panasonic_fpxh_tcp.c panasonic_fpxh_uart.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -0,0 +1,39 @@
|
|||
# 松下通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 松下FPXHC40ET通信测试
|
||||
|
||||
### 通信接线及参数设置
|
||||
|
||||
* 网口和串口
|
||||
* FPXHC40ET自带miniUSB,用于程序的下载。本体自带的串口为RS232。
|
||||
* 本体自带的网口可用于Modbus TCP,Ethernet/IP等通信。目前用于Modbus TCP通信测试,网口IP:192.168.250.51 Port:502
|
||||
* 通过本体拓展FPXH-COM3通信模板,可用于Modbus RTU通信。串口接线:S+接485A;S-接485B。
|
||||
* 串口模块通信参数配置:通信速率:115200;数据位:8bit;停止位:1bit;校验:偶校验
|
||||
|
||||
### 存储区
|
||||
|
||||
- 存储区 X,Y,R,D,L区等。
|
||||
|
||||
### 通信测试
|
||||
|
||||
- 共测试BOOL,INT16等类型数据。
|
||||
|
||||
|
||||
- 测试Y区,R区及DT区数据。
|
||||
|
||||
|
||||
- 测试截图:
|
||||
|
||||
测试PLC环境搭建:
|
||||
|
||||

|
||||
|
||||
解析完成的配方为:
|
||||
|
||||

|
||||
|
||||
测试结果:
|
||||
|
||||

|
After Width: | Height: | Size: 200 KiB |
After Width: | Height: | Size: 182 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 6.4 KiB |
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "PANASONIC_FPXH_TCP",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.51",
|
||||
"local_ip": "192.168.250.233",
|
||||
"gateway": "192.168.250.1",
|
||||
"netmask": "255.255.254.0",
|
||||
"port": 502
|
||||
},
|
||||
"protocol_type": 2,
|
||||
"read_period": 1000,
|
||||
"read_item_list": [
|
||||
{
|
||||
"value_name": "Y0",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R0",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address":2048,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R100",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 2208,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R101",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 2209,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "DT0",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "DT1",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 1,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "DT200",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 200,
|
||||
"quantity": 1
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "PANASONIC_FPXH_RTU",
|
||||
"communication_type": 1,
|
||||
"serial_config": {
|
||||
"station": 1,
|
||||
"baud_rate": 9600,
|
||||
"data_bits": 8,
|
||||
"stop_bits": 1,
|
||||
"check_mode":3
|
||||
},
|
||||
"protocol_type": 3,
|
||||
"read_period": 2000,
|
||||
"read_item_list": [
|
||||
{
|
||||
"value_name": "Y0",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R0",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address":2048,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R100",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 2208,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "R101",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 2209,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "DT0",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "DT1",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 1,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "DT200",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 200,
|
||||
"quantity": 1
|
||||
}
|
||||
|
||||
]
|
||||
}
|
|
@ -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 panasonic_fpxh_ethernet.c
|
||||
* @brief PLC panasonic fpxh app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.11.22
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlPanasonicFpxhTCPTest(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(ControlPanasonicFpxhTCPTest, panasonic Fpxh TCP Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
|
@ -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 panasonic_fpxh_uart.c
|
||||
* @brief PLC panasonic fpxh app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.11.22
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlPanasonicFpxhUartTest(void)
|
||||
{
|
||||
int i, j = 0;
|
||||
int read_data_length = 0;
|
||||
uint8_t read_data[128] = {0};
|
||||
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
Adapter4GActive();
|
||||
#endif
|
||||
|
||||
ControlProtocolType modbus_rtu_protocol = ControlProtocolFind();
|
||||
if (NULL == modbus_rtu_protocol) {
|
||||
printf("%s get modbus rtu protocol %p failed\n", __func__, modbus_rtu_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get modbus rtu protocol %p successfull\n", __func__, modbus_rtu_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == modbus_rtu_protocol->protocol_status) {
|
||||
ControlProtocolOpen(modbus_rtu_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(modbus_rtu_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] modbus rtu 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_rtu_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlPanasonicFpxhUartTest, panasonic fpxh uart Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
SRC_FILES := siemens_s7_200_cn.c siemens_s7_200_smart.c siemens_s7_300.c siemens_s7_1200.c siemens_s7_1500.c
|
||||
SRC_FILES := siemens_s7_200_cn.c siemens_s7_200_smart.c siemens_s7_1200.c siemens_s7_1500.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"device_id": 1,
|
||||
"device_name": "S7-1215",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.5",
|
||||
"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": 10,
|
||||
"start": 32,
|
||||
"amount": 1
|
||||
}
|
||||
]
|
||||
}
|
|
@ -18,3 +18,28 @@
|
|||
* @date 2023.3.27
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
void ControlS71200Test(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(ControlS71200Test, Siemens Plc S7_1215 Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
|
@ -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 siemens_s7_300.c
|
||||
* @brief PLC SIEMENS S7-300 app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.3.27
|
||||
*/
|
||||
|
|
@ -31,32 +31,14 @@ Modification:
|
|||
|
||||
context_switch:
|
||||
# store original context to stack
|
||||
str lr, [r13, #-4]!
|
||||
str r12, [r13, #-4]!
|
||||
str r11, [r13, #-4]!
|
||||
str r10, [r13, #-4]!
|
||||
str r9, [r13, #-4]!
|
||||
str r8, [r13, #-4]!
|
||||
str r7, [r13, #-4]!
|
||||
str r6, [r13, #-4]!
|
||||
str r5, [r13, #-4]!
|
||||
str r4, [r13, #-4]!
|
||||
stmfd r13!, {r4-r12, lr}
|
||||
|
||||
# switch the stack
|
||||
str r13, [r0] // save current sp to the old PCB (**old)
|
||||
mov r13, r1 // load the next stack
|
||||
|
||||
# restore context from stack
|
||||
ldr r4, [r13], #4
|
||||
ldr r5, [r13], #4
|
||||
ldr r6, [r13], #4
|
||||
ldr r7, [r13], #4
|
||||
ldr r8, [r13], #4
|
||||
ldr r9, [r13], #4
|
||||
ldr r10, [r13], #4
|
||||
ldr r11, [r13], #4
|
||||
ldr r12, [r13], #4
|
||||
ldr lr, [r13], #4
|
||||
ldmfd r13!, {r4-r12, lr}
|
||||
|
||||
# return to the caller
|
||||
bx lr
|
||||
|
|
|
@ -76,7 +76,7 @@ Modification:
|
|||
|
||||
#define NR_CPU 4
|
||||
|
||||
__attribute__((always_inline)) static inline uint32_t user_mode()
|
||||
__attribute__((always_inline, optimize("O0"))) static inline uint32_t user_mode()
|
||||
{
|
||||
uint32_t val;
|
||||
|
||||
|
@ -92,6 +92,16 @@ __attribute__((always_inline)) static inline uint32_t user_mode()
|
|||
return val;
|
||||
}
|
||||
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void cpu_into_low_power()
|
||||
{
|
||||
WFE();
|
||||
}
|
||||
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void cpu_leave_low_power()
|
||||
{
|
||||
SEV();
|
||||
}
|
||||
|
||||
struct context {
|
||||
uint32_t r4;
|
||||
uint32_t r5;
|
||||
|
@ -103,12 +113,12 @@ struct context {
|
|||
uint32_t r11;
|
||||
uint32_t r12;
|
||||
uint32_t lr;
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
/// @brief init task context, set return address to trap return
|
||||
/// @param
|
||||
extern void task_prepare_enter();
|
||||
__attribute__((__always_inline__)) static inline void arch_init_context(struct context* ctx)
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void arch_init_context(struct context* ctx)
|
||||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->lr = (uint32_t)(task_prepare_enter + 4);
|
||||
|
@ -133,13 +143,13 @@ struct trapframe {
|
|||
uint32_t r11;
|
||||
uint32_t r12;
|
||||
uint32_t pc;
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
/// @brief init task trapframe (*especially the user mode cpsr)
|
||||
/// @param tf
|
||||
/// @param sp
|
||||
/// @param pc
|
||||
__attribute__((__always_inline__)) static inline void arch_init_trapframe(struct trapframe* tf, uintptr_t sp, uintptr_t pc)
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void arch_init_trapframe(struct trapframe* tf, uintptr_t sp, uintptr_t pc)
|
||||
{
|
||||
memset(tf, 0, sizeof(*tf));
|
||||
tf->spsr = user_mode();
|
||||
|
@ -153,7 +163,7 @@ __attribute__((__always_inline__)) static inline void arch_init_trapframe(struct
|
|||
/// @param tf
|
||||
/// @param sp
|
||||
/// @param pc
|
||||
__attribute__((__always_inline__)) static inline void arch_trapframe_set_sp_pc(struct trapframe* tf, uintptr_t sp, uintptr_t pc)
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void arch_trapframe_set_sp_pc(struct trapframe* tf, uintptr_t sp, uintptr_t pc)
|
||||
{
|
||||
tf->sp_usr = sp;
|
||||
tf->pc = pc;
|
||||
|
@ -163,7 +173,7 @@ __attribute__((__always_inline__)) static inline void arch_trapframe_set_sp_pc(s
|
|||
/// @param tf
|
||||
/// @param argc
|
||||
/// @param argv
|
||||
__attribute__((__always_inline__)) static inline void arch_set_main_params(struct trapframe* tf, int argc, uintptr_t argv)
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void arch_set_main_params(struct trapframe* tf, int argc, uintptr_t argv)
|
||||
{
|
||||
tf->r0 = (uint32_t)argc;
|
||||
tf->r1 = (uint32_t)argv;
|
||||
|
@ -178,7 +188,7 @@ __attribute__((__always_inline__)) static inline void arch_set_main_params(struc
|
|||
/// @param param5
|
||||
/// @return
|
||||
extern int syscall(int sys_num, uintptr_t param1, uintptr_t param2, uintptr_t param3, uintptr_t param4);
|
||||
__attribute__((__always_inline__)) static inline int arch_syscall(struct trapframe* tf, int* syscall_num)
|
||||
__attribute__((always_inline, optimize("O0"))) static inline int arch_syscall(struct trapframe* tf, int* syscall_num)
|
||||
{
|
||||
// call syscall
|
||||
*syscall_num = tf->r0;
|
||||
|
@ -188,7 +198,7 @@ __attribute__((__always_inline__)) static inline int arch_syscall(struct trapfra
|
|||
/// @brief set return reg to trapframe
|
||||
/// @param tf
|
||||
/// @param ret
|
||||
__attribute__((__always_inline__)) static inline void arch_set_return(struct trapframe* tf, int ret)
|
||||
__attribute__((always_inline, optimize("O0"))) static inline void arch_set_return(struct trapframe* tf, int ret)
|
||||
{
|
||||
tf->r0 = (uint32_t)ret;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export CROSS_COMPILE ?= arm-none-eabi-
|
||||
export DEVICE = -march=armv7-a -mtune=cortex-a9 -mfpu=vfpv3-d16 -ftree-vectorize -ffast-math -mfloat-abi=softfp
|
||||
export CFLAGS := $(DEVICE) -Wall -O0 -g -gdwarf-2
|
||||
export CFLAGS := $(DEVICE) -Wall -O2 -g -gdwarf-2 -Wnull-dereference -Waddress -Warray-bounds -Wchar-subscripts -Wimplicit-int -Wimplicit-function-declaration -Wcomment -Wformat -Wmissing-braces -Wnonnull -Wparentheses -Wpointer-sign -Wreturn-type -Wsequence-point -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wunused-function
|
||||
export AFLAGS := -c $(DEVICE) -x assembler-with-cpp -D__ASSEMBLY__ -gdwarf-2
|
||||
# export LFLAGS := $(DEVICE) -Wl,-Map=XiZi-imx6q-sabrelite.map,-cref,-u,_boot_start -T $(KERNEL_ROOT)/hardkernel/arch/arm/armv7-a/cortex-a9/preboot_for_imx6q-sabrelite/nxp_imx6q_sabrelite.lds
|
||||
export LFLAGS := $(DEVICE) --specs=nosys.specs -Wl,-Map=XiZi-imx6q-sabrelite.map,-cref,-u,_boot_start -T $(KERNEL_ROOT)/hardkernel/arch/arm/armv7-a/cortex-a9/preboot_for_imx6q-sabrelite/nxp_imx6q_sabrelite.lds
|
||||
|
|
|
@ -77,6 +77,10 @@ BOOT_STACK_SIZE = 0x4000;
|
|||
RAM_VECTORS_SIZE = 72;
|
||||
|
||||
/* Specify the memory areas */
|
||||
/*
|
||||
ddr3: physical area: [0x10000000, 0x50000000);
|
||||
virt_ddr3: virt area exclude boot(start_sec), that will be [0x90000000 + 0x11000, 0xD0000000)
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
ocram (rwx) : ORIGIN = 0x00900000, LENGTH = 256K
|
||||
|
@ -154,7 +158,7 @@ SECTIONS
|
|||
PROVIDE(boot_end_addr = .);
|
||||
} > ddr3
|
||||
|
||||
/* Other Kernel code is placed over 0x80000000 + 128KB. */
|
||||
/* Other Kernel code is placed over 0x10011000(phy) and 0x90011000(virt). */
|
||||
.text : AT(0x10011000) {
|
||||
*(.vectors)
|
||||
. = ALIGN(0x1000);
|
||||
|
|
|
@ -40,24 +40,8 @@ static void _sys_clock_init()
|
|||
{
|
||||
uint32_t freq = get_main_clock(IPG_CLK);
|
||||
gpt_init(CLKSRC_IPG_CLK, freq / 1000000, RESTART_MODE, WAIT_MODE_EN | STOP_MODE_EN);
|
||||
switch (cur_cpuid()) {
|
||||
case 0:
|
||||
gpt_set_compare_event(kGPTOutputCompare1, OUTPUT_CMP_DISABLE, 1000);
|
||||
gpt_counter_enable(kGPTOutputCompare1);
|
||||
break;
|
||||
case 1:
|
||||
gpt_set_compare_event(kGPTOutputCompare2, OUTPUT_CMP_DISABLE, 1000);
|
||||
gpt_counter_enable(kGPTOutputCompare2);
|
||||
break;
|
||||
case 2:
|
||||
gpt_set_compare_event(kGPTOutputCompare3, OUTPUT_CMP_DISABLE, 1000);
|
||||
gpt_counter_enable(kGPTOutputCompare3);
|
||||
break;
|
||||
case 3:
|
||||
gpt_set_compare_event(kGPTOutputCompare1, OUTPUT_CMP_DISABLE, 1000);
|
||||
gpt_counter_enable(kGPTOutputCompare1);
|
||||
break;
|
||||
}
|
||||
gpt_set_compare_event(kGPTOutputCompare1, OUTPUT_CMP_DISABLE, 1000);
|
||||
gpt_counter_enable(kGPTOutputCompare1);
|
||||
}
|
||||
|
||||
static uint32_t _get_clock_int()
|
||||
|
|
|
@ -218,10 +218,7 @@ bool secondary_cpu_hardkernel_init(int cpu_id, struct TraceTag* _hardkernel_tag)
|
|||
// cache
|
||||
p_icache_driver->enable();
|
||||
p_dcache_driver->enable();
|
||||
// p_icache_driver->disable();
|
||||
// p_dcache_driver->disable();
|
||||
// clock
|
||||
// p_clock_driver->sys_clock_init();
|
||||
p_intr_driver->single_irq_enable(p_clock_driver->get_clock_int(), cpu_id, 0);
|
||||
// mmu
|
||||
secondary_cpu_load_kern_pgdir(&init_mmu_tag, &init_intr_tag);
|
||||
|
|
|
@ -41,32 +41,18 @@ Modification:
|
|||
*************************************************/
|
||||
#include "core.h"
|
||||
#include "memlayout.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "multicores.h"
|
||||
#include "spinlock.h"
|
||||
#include "syscall.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
__attribute__((always_inline)) static inline void _abort_reason(uint32_t fault_status)
|
||||
{
|
||||
if ((fault_status & 0xd) == 0x1) // Alignment failure
|
||||
KPrintf("reason: alignment\n");
|
||||
else if ((fault_status & 0xd) == 0x5) // External abort "on translation"
|
||||
KPrintf("reason: ext. abort on trnslt.\n");
|
||||
else if ((fault_status & 0xd) == 0x5) // Translation
|
||||
KPrintf("reason: sect. translation\n");
|
||||
else if ((fault_status & 0xd) == 0x9) // Domain
|
||||
KPrintf("reason: sect. domain\n");
|
||||
else if ((fault_status & 0xd) == 0xd) // Permission
|
||||
KPrintf("reason: sect. permission\n");
|
||||
else if ((fault_status & 0xd) == 0x8) // External abort
|
||||
KPrintf("reason: ext. abort\n");
|
||||
else
|
||||
KPrintf("reason: unknown???\n");
|
||||
}
|
||||
#include "assert.h"
|
||||
#include "multicores.h"
|
||||
#include "syscall.h"
|
||||
#include "task.h"
|
||||
|
||||
void dump_tf(struct trapframe* tf)
|
||||
{
|
||||
KPrintf("sp_usr: 0x%x\n", tf->sp_usr);
|
||||
KPrintf("lr_usr: 0x%x\n", tf->lr_usr);
|
||||
KPrintf("lr_svc: 0x%x\n", tf->lr_svc);
|
||||
KPrintf(" spsr: 0x%x\n", tf->spsr);
|
||||
KPrintf(" r0: 0x%x\n", tf->r0);
|
||||
|
@ -85,64 +71,76 @@ void dump_tf(struct trapframe* tf)
|
|||
KPrintf(" pc: 0x%x\n", tf->pc);
|
||||
}
|
||||
|
||||
void dabort_reason(struct trapframe* r)
|
||||
{
|
||||
uint32_t fault_status, dfa;
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 0" : "=r"(fault_status)::);
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c6, c0, 0" : "=r"(dfa)::);
|
||||
LOG("program counter: 0x%x caused\n", r->pc);
|
||||
LOG("data abort at 0x%x, status 0x%x\n", dfa, fault_status);
|
||||
|
||||
if ((fault_status & 0xd) == 0x1) // Alignment failure
|
||||
KPrintf("reason: alignment\n");
|
||||
else if ((fault_status & 0xd) == 0x5) // External abort "on translation"
|
||||
KPrintf("reason: ext. abort on trnslt.\n");
|
||||
else if ((fault_status & 0xd) == 0x5) // Translation
|
||||
KPrintf("reason: sect. translation\n");
|
||||
else if ((fault_status & 0xd) == 0x9) // Domain
|
||||
KPrintf("reason: sect. domain\n");
|
||||
else if ((fault_status & 0xd) == 0xd) // Permission
|
||||
KPrintf("reason: sect. permission\n");
|
||||
else if ((fault_status & 0xd) == 0x8) // External abort
|
||||
KPrintf("reason: ext. abort\n");
|
||||
else
|
||||
KPrintf("reason: unknown???\n");
|
||||
|
||||
dump_tf(r);
|
||||
}
|
||||
|
||||
void iabort_reason(struct trapframe* r)
|
||||
{
|
||||
uint32_t fault_status, ifa;
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 1" : "=r"(fault_status)::);
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c6, c0, 2" : "=r"(ifa)::);
|
||||
LOG("prefetch abort at 0x%x, status 0x%x\n", ifa, fault_status);
|
||||
|
||||
if ((fault_status & 0xd) == 0x1) // Alignment failure
|
||||
KPrintf("reason: alignment\n");
|
||||
else if ((fault_status & 0xd) == 0x5) // External abort "on translation"
|
||||
KPrintf("reason: ext. abort on trnslt.\n");
|
||||
else if ((fault_status & 0xd) == 0x5) // Translation
|
||||
KPrintf("reason: sect. translation\n");
|
||||
else if ((fault_status & 0xd) == 0x9) // Domain
|
||||
KPrintf("reason: sect. domain\n");
|
||||
else if ((fault_status & 0xd) == 0xd) // Permission
|
||||
KPrintf("reason: sect. permission\n");
|
||||
else if ((fault_status & 0xd) == 0x8) // External abort
|
||||
KPrintf("reason: ext. abort\n");
|
||||
else
|
||||
KPrintf("reason: unknown???\n");
|
||||
|
||||
dump_tf(r);
|
||||
}
|
||||
|
||||
void handle_undefined_instruction(struct trapframe* tf)
|
||||
{
|
||||
// unimplemented trap handler
|
||||
KPrintf("undefined instruction at %x\n", tf->pc);
|
||||
ERROR("undefined instruction at %x\n", tf->pc);
|
||||
xizi_enter_kernel();
|
||||
panic("");
|
||||
}
|
||||
|
||||
extern void context_switch(struct context**, struct context*);
|
||||
void dabort_handler(struct trapframe* r)
|
||||
void handle_reserved(void)
|
||||
{
|
||||
if (!is_spinlock_locked(&whole_kernel_lock) || whole_kernel_lock.owner_cpu != cur_cpuid()) {
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
}
|
||||
uint32_t dfs, dfa;
|
||||
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 0" : "=r"(dfs)::);
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c6, c0, 0" : "=r"(dfa)::);
|
||||
|
||||
if (r->pc < KERN_MEM_BASE) { // Exception occured in User space: exit
|
||||
ERROR("dabort in user space: %s\n", cur_cpu()->task->name);
|
||||
LOG("program counter: 0x%x caused\n", r->pc);
|
||||
LOG("data abort at 0x%x, status 0x%x\n", dfa, dfs);
|
||||
_abort_reason(dfs);
|
||||
dump_tf(r);
|
||||
sys_exit(cur_cpu()->task);
|
||||
context_switch(&cur_cpu()->task->main_thread.context, cur_cpu()->scheduler);
|
||||
} else { // Exception occured in Kernel space: panic
|
||||
LOG("program counter: 0x%x caused\n", r->pc);
|
||||
LOG("data abort at 0x%x, status 0x%x\n", dfa, dfs);
|
||||
_abort_reason(dfs);
|
||||
dump_tf(r);
|
||||
panic("data abort exception\n");
|
||||
}
|
||||
// unimplemented trap handler
|
||||
ERROR("Unimplemented Reserved\n");
|
||||
xizi_enter_kernel();
|
||||
panic("");
|
||||
}
|
||||
|
||||
void iabort_handler(struct trapframe* r)
|
||||
void handle_fiq(void)
|
||||
{
|
||||
if (!is_spinlock_locked(&whole_kernel_lock) || whole_kernel_lock.owner_cpu != cur_cpuid()) {
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
}
|
||||
uint32_t ifs, ifa;
|
||||
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 1" : "=r"(ifs)::);
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c6, c0, 2" : "=r"(ifa)::);
|
||||
|
||||
if (r->pc < KERN_MEM_BASE) { // Exception occured in User space: exit
|
||||
ERROR("iabort in user space: %s\n", cur_cpu()->task->name);
|
||||
LOG("program counter: 0x%x(%s) caused\n", r->pc, cur_cpu()->task);
|
||||
LOG("prefetch abort at 0x%x, status 0x%x\n", ifa, ifs);
|
||||
_abort_reason(ifs);
|
||||
dump_tf(r);
|
||||
sys_exit(cur_cpu()->task);
|
||||
context_switch(&cur_cpu()->task->main_thread.context, cur_cpu()->scheduler);
|
||||
} else { // Exception occured in Kernel space: panic
|
||||
LOG("program counter: 0x%x(%s) caused\n", r->pc, cur_cpu()->task);
|
||||
LOG("prefetch abort at 0x%x, status 0x%x\n", ifa, ifs);
|
||||
_abort_reason(ifs);
|
||||
dump_tf(r);
|
||||
panic("prefetch abort exception\n");
|
||||
}
|
||||
}
|
||||
ERROR("Unimplemented FIQ\n");
|
||||
xizi_enter_kernel();
|
||||
panic("");
|
||||
}
|
|
@ -45,6 +45,8 @@ Author: AIIT XUOS Lab
|
|||
Modification:
|
||||
1. take only gicd part of functions
|
||||
*************************************************/
|
||||
#include "string.h"
|
||||
|
||||
#include "gicv2_common_opa.h"
|
||||
#include "gicv2_registers.h"
|
||||
|
||||
|
@ -139,7 +141,7 @@ void gic_send_sgi(uint32_t irqID, uint32_t target_list, uint32_t filter_list)
|
|||
|
||||
void gic_init(void)
|
||||
{
|
||||
gicd_t* gicd = gic_get_gicd();
|
||||
volatile gicd_t* gicd = gic_get_gicd();
|
||||
|
||||
// First disable the distributor.
|
||||
gic_enable(false);
|
||||
|
@ -150,7 +152,9 @@ void gic_init(void)
|
|||
|
||||
for (uint32_t i = 0; i < 255; i++) {
|
||||
*(uint32_t*)(&gicd->IPRIORITYRn[i * sizeof(uint32_t)]) = (uint32_t)0x80808080;
|
||||
// memset((void*)&gicd->IPRIORITYRn[i * sizeof(uint32_t)], 0x80, sizeof(uint32_t));
|
||||
*(uint32_t*)(&gicd->ITARGETSRn[i * sizeof(uint32_t)]) = (uint32_t)0x01010101;
|
||||
// memset((void*)&gicd->IPRIORITYRn[i * sizeof(uint32_t)], 0x01, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
// Init the GIC CPU interface.
|
||||
|
|
|
@ -42,13 +42,13 @@ extern void trap_iabort(void);
|
|||
extern void trap_dabort(void);
|
||||
extern void trap_irq_enter(void);
|
||||
extern void trap_undefined_instruction(void);
|
||||
extern void handle_reserved(void);
|
||||
extern void handle_fiq(void);
|
||||
|
||||
static struct XiziTrapDriver xizi_trap_driver;
|
||||
|
||||
void panic(char* s)
|
||||
{
|
||||
xizi_trap_driver.cpu_irq_disable();
|
||||
spinlock_unlock(&whole_kernel_lock);
|
||||
KPrintf("panic: %s\n", s);
|
||||
for (;;)
|
||||
;
|
||||
|
@ -56,7 +56,6 @@ void panic(char* s)
|
|||
|
||||
/* stack for different mode*/
|
||||
static char mode_stack_pages[NR_CPU][NR_MODE_STACKS][MODE_STACK_SIZE];
|
||||
|
||||
extern uint32_t _vector_jumper;
|
||||
extern uint32_t _vector_start;
|
||||
extern uint32_t _vector_end;
|
||||
|
@ -71,19 +70,6 @@ void init_cpu_mode_stacks(int cpu_id)
|
|||
}
|
||||
}
|
||||
|
||||
void handle_reserved(void)
|
||||
{
|
||||
// unimplemented trap handler
|
||||
LOG("Unimplemented Reserved\n");
|
||||
panic("");
|
||||
}
|
||||
|
||||
void handle_fiq(void)
|
||||
{
|
||||
LOG("Unimplemented FIQ\n");
|
||||
panic("");
|
||||
}
|
||||
|
||||
static void _sys_irq_init(int cpu_id)
|
||||
{
|
||||
/* load exception vectors */
|
||||
|
@ -99,9 +85,10 @@ static void _sys_irq_init(int cpu_id)
|
|||
vector_base[5] = (uint32_t)handle_reserved; // Reserved
|
||||
vector_base[6] = (uint32_t)trap_irq_enter; // IRQ
|
||||
vector_base[7] = (uint32_t)handle_fiq; // FIQ
|
||||
|
||||
gic_init();
|
||||
}
|
||||
/* active hardware irq responser */
|
||||
gic_init();
|
||||
xizi_trap_driver.switch_hw_irqtbl((uint32_t*)&_vector_jumper);
|
||||
}
|
||||
|
||||
|
@ -153,29 +140,6 @@ static void _bind_irq_handler(int irq, irq_handler_t handler)
|
|||
xizi_trap_driver.sw_irqtbl[irq].handler = handler;
|
||||
}
|
||||
|
||||
static bool _send_sgi(uint32_t irq, uint32_t bitmask, enum SgiFilterType type)
|
||||
{
|
||||
if (bitmask > (1 << NR_CPU) - 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
enum _gicd_sgi_filter sgi_filter;
|
||||
switch (type) {
|
||||
case SgiFilter_TargetList:
|
||||
sgi_filter = kGicSgiFilter_UseTargetList;
|
||||
break;
|
||||
case SgiFilter_AllOtherCPUs:
|
||||
sgi_filter = kGicSgiFilter_AllOtherCPUs;
|
||||
break;
|
||||
default:
|
||||
sgi_filter = kGicSgiFilter_OnlyThisCPU;
|
||||
break;
|
||||
}
|
||||
gic_send_sgi(irq, bitmask, sgi_filter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t _hw_before_irq()
|
||||
{
|
||||
|
||||
|
@ -192,29 +156,11 @@ static uint32_t _hw_cur_int_num(uint32_t int_info)
|
|||
return int_info & 0x1FF;
|
||||
}
|
||||
|
||||
static uint32_t _hw_cur_int_cpu(uint32_t int_info)
|
||||
{
|
||||
return (int_info >> 10) & 0x7;
|
||||
}
|
||||
|
||||
static void _hw_after_irq(uint32_t int_info)
|
||||
{
|
||||
gic_write_end_of_irq(int_info);
|
||||
}
|
||||
|
||||
static int _is_interruptable(void)
|
||||
{
|
||||
uint32_t val;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mrs %0, cpsr"
|
||||
: "=r"(val)
|
||||
:
|
||||
:);
|
||||
|
||||
return !(val & DIS_INT);
|
||||
}
|
||||
|
||||
int _cur_cpu_id()
|
||||
{
|
||||
return cpu_get_current();
|
||||
|
@ -231,12 +177,9 @@ static struct XiziTrapDriver xizi_trap_driver = {
|
|||
.switch_hw_irqtbl = _switch_hw_irqtbl,
|
||||
|
||||
.bind_irq_handler = _bind_irq_handler,
|
||||
.send_sgi = _send_sgi,
|
||||
|
||||
.is_interruptable = _is_interruptable,
|
||||
.hw_before_irq = _hw_before_irq,
|
||||
.hw_cur_int_num = _hw_cur_int_num,
|
||||
.hw_cur_int_cpu = _hw_cur_int_cpu,
|
||||
.hw_after_irq = _hw_after_irq,
|
||||
};
|
||||
|
||||
|
|
|
@ -47,43 +47,17 @@ trap_return:
|
|||
ldmfd r13!, {r14}
|
||||
ldmfd r13!, {r2}
|
||||
msr spsr_cxsf, r2
|
||||
ldr r0, [r13], #4
|
||||
ldr r1, [r13], #4
|
||||
ldr r2, [r13], #4
|
||||
ldr r3, [r13], #4
|
||||
ldr r4, [r13], #4
|
||||
ldr r5, [r13], #4
|
||||
ldr r6, [r13], #4
|
||||
ldr r7, [r13], #4
|
||||
ldr r8, [r13], #4
|
||||
ldr r9, [r13], #4
|
||||
ldr r10, [r13], #4
|
||||
ldr r11, [r13], #4
|
||||
ldr r12, [r13], #4
|
||||
ldm r13!, {pc}^
|
||||
ldmfd r13!, {r0-r12, pc}^ // restore context and return
|
||||
|
||||
user_trap_swi_enter:
|
||||
# save trapframe to swi stack
|
||||
sub sp, sp, #56
|
||||
str r14, [sp, #52]
|
||||
str r12, [sp, #48]
|
||||
str r11, [sp, #44]
|
||||
str r10, [sp, #40]
|
||||
str r9, [sp, #36]
|
||||
str r8, [sp, #32]
|
||||
str r7, [sp, #28]
|
||||
str r6, [sp, #24]
|
||||
str r5, [sp, #20]
|
||||
str r4, [sp, #16]
|
||||
str r3, [sp, #12]
|
||||
str r2, [sp, #8]
|
||||
str r1, [sp, #4]
|
||||
str r0, [sp]
|
||||
# save trapframe to swi stack
|
||||
cpsid i
|
||||
stmfd sp!, {r0-r12, r14} // save context
|
||||
mrs r2, spsr // copy spsr to r2
|
||||
stmfd r13!, {r2} // save r2(spsr) to the stack
|
||||
|
||||
mrs r2, spsr
|
||||
stmfd r13!, {r2}
|
||||
stmfd r13!, {r14}
|
||||
stmfd r13, {sp, lr}^
|
||||
stmfd r13!, {r14} // save r14 again to have one uniform trapframe
|
||||
stmfd r13, {sp, lr}^ // save user mode sp and lr
|
||||
sub r13, r13, #8
|
||||
|
||||
# call syscall handler
|
||||
|
@ -92,17 +66,13 @@ user_trap_swi_enter:
|
|||
b trap_return
|
||||
|
||||
trap_irq_enter:
|
||||
# save context in irq stack
|
||||
sub r14, r14, #4
|
||||
sub sp, sp, #16
|
||||
str r14, [sp, #12]
|
||||
str r2, [sp, #8]
|
||||
str r1, [sp, #4]
|
||||
str r0, [sp]
|
||||
|
||||
mrs r1, spsr
|
||||
mov r0, r13 // irq stack stop
|
||||
add r13, r13, #16 // reset IRQ stack
|
||||
# save it on the stack as r14 is banked
|
||||
cpsid i
|
||||
sub r14, r14, #4 // r14 (lr) contains the interrupted PC
|
||||
stmfd r13!, {r0-r2, r14} //
|
||||
mrs r1, spsr // save spsr_irq
|
||||
mov r0, r13 // save stack stop (r13_irq)
|
||||
add r13, r13, #16 // reset the IRQ stack
|
||||
|
||||
# switch to the SVC mode
|
||||
mrs r2, cpsr
|
||||
|
@ -111,134 +81,110 @@ trap_irq_enter:
|
|||
msr cpsr_cxsf, r2
|
||||
|
||||
# build the trap frame
|
||||
ldr r2, [r0, #12]
|
||||
ldr r2, [r0, #12] // read the r14_irq, then save it
|
||||
stmfd r13!, {r2}
|
||||
sub r13, r13, #40
|
||||
str r12, [r13, #36]
|
||||
str r11, [r13, #32]
|
||||
str r10, [r13, #28]
|
||||
str r9, [r13, #24]
|
||||
str r8, [r13, #20]
|
||||
str r7, [r13, #16]
|
||||
str r6, [r13, #12]
|
||||
str r5, [r13, #8]
|
||||
str r4, [r13, #4]
|
||||
str r3, [r13]
|
||||
|
||||
ldmfd r0, {r3-r5}
|
||||
stmfd r13!, {r3-r12} // r4-r12 are preserved (non-banked)
|
||||
ldmfd r0, {r3-r5} // copy r0-r2 over from irq stack
|
||||
stmfd r13!, {r3-r5}
|
||||
stmfd r13!, {r1}
|
||||
stmfd r13!, {lr}
|
||||
stmfd r13, {sp, lr}^
|
||||
stmfd r13!, {r1} // save spsr
|
||||
stmfd r13!, {lr} // save lr_svc
|
||||
|
||||
stmfd r13, {sp, lr}^ // save user mode sp and lr
|
||||
sub r13, r13, #8
|
||||
|
||||
mov r0, r13 // trapframe as parameters
|
||||
bl intr_irq_dispatch
|
||||
b trap_return
|
||||
|
||||
trap_reset_enter:
|
||||
mov r14, #0
|
||||
sub r13, r13, #56
|
||||
str r14, [r13, #52]
|
||||
str r12, [r13, #48]
|
||||
str r11, [r13, #44]
|
||||
str r10, [r13, #40]
|
||||
str r9, [r13, #36]
|
||||
str r8, [r13, #32]
|
||||
str r7, [r13, #28]
|
||||
str r6, [r13, #24]
|
||||
str r5, [r13, #20]
|
||||
str r4, [r13, #16]
|
||||
str r3, [r13, #12]
|
||||
str r2, [r13, #8]
|
||||
str r1, [r13, #4]
|
||||
str r0, [r13]
|
||||
|
||||
mrs r2, spsr
|
||||
stmfd r13!, {r2}
|
||||
stmfd r13!, {r14}
|
||||
stmfd r13, {sp, lr}^
|
||||
sub r13, r13, #8
|
||||
mov r0, r13
|
||||
bl _vector_jumper
|
||||
|
||||
trap_dabort:
|
||||
sub r14, r14, #8
|
||||
sub r13, r13, #56
|
||||
str r14, [r13, #52]
|
||||
str r12, [r13, #48]
|
||||
str r11, [r13, #44]
|
||||
str r10, [r13, #40]
|
||||
str r9, [r13, #36]
|
||||
str r8, [r13, #32]
|
||||
str r7, [r13, #28]
|
||||
str r6, [r13, #24]
|
||||
str r5, [r13, #20]
|
||||
str r4, [r13, #16]
|
||||
str r3, [r13, #12]
|
||||
str r2, [r13, #8]
|
||||
str r1, [r13, #4]
|
||||
str r0, [r13]
|
||||
# save it on the stack as r14 is banked
|
||||
cpsid i
|
||||
sub r14, r14, #8 // r14 (lr) contains the interrupted PC
|
||||
stmfd r13!, {r0-r2, r14} //
|
||||
mrs r1, spsr // save spsr_irq
|
||||
mov r0, r13 // save stack stop (r13_irq)
|
||||
add r13, r13, #16 // reset the IRQ stack
|
||||
|
||||
mrs r2, spsr
|
||||
stmfd r13!, {r2}
|
||||
stmfd r13!, {r14}
|
||||
stmfd r13, {sp, lr}^
|
||||
# switch to the SVC mode
|
||||
mrs r2, cpsr
|
||||
bic r2, r2, #ARM_CPSR_MODE_MASK
|
||||
orr r2, r2, #ARM_MODE_SVC
|
||||
msr cpsr_cxsf, r2
|
||||
|
||||
# build the trap frame
|
||||
ldr r2, [r0, #12] // read the r14_irq, then save it
|
||||
stmfd r13!, {r2}
|
||||
stmfd r13!, {r3-r12} // r4-r12 are preserved (non-banked)
|
||||
ldmfd r0, {r3-r5} // copy r0-r2 over from irq stack
|
||||
stmfd r13!, {r3-r5}
|
||||
stmfd r13!, {r1} // save spsr
|
||||
stmfd r13!, {lr} // save lr_svc
|
||||
|
||||
stmfd r13, {sp, lr}^ // save user mode sp and lr
|
||||
sub r13, r13, #8
|
||||
mov r0, r13
|
||||
|
||||
mov r0, r13 // trapframe as parameters
|
||||
bl dabort_handler
|
||||
|
||||
trap_iabort:
|
||||
sub r14, r14, #4
|
||||
sub r13, r13, #56
|
||||
str r14, [r13, #52]
|
||||
str r12, [r13, #48]
|
||||
str r11, [r13, #44]
|
||||
str r10, [r13, #40]
|
||||
str r9, [r13, #36]
|
||||
str r8, [r13, #32]
|
||||
str r7, [r13, #28]
|
||||
str r6, [r13, #24]
|
||||
str r5, [r13, #20]
|
||||
str r4, [r13, #16]
|
||||
str r3, [r13, #12]
|
||||
str r2, [r13, #8]
|
||||
str r1, [r13, #4]
|
||||
str r0, [r13]
|
||||
# save it on the stack as r14 is banked
|
||||
cpsid i
|
||||
sub r14, r14, #4 // r14 (lr) contains the interrupted PC
|
||||
stmfd r13!, {r0-r2, r14} //
|
||||
mrs r1, spsr // save spsr_irq
|
||||
mov r0, r13 // save stack stop (r13_irq)
|
||||
add r13, r13, #16 // reset the IRQ stack
|
||||
|
||||
mrs r2, spsr
|
||||
# switch to the SVC mode
|
||||
mrs r2, cpsr
|
||||
bic r2, r2, #ARM_CPSR_MODE_MASK
|
||||
orr r2, r2, #ARM_MODE_SVC
|
||||
msr cpsr_cxsf, r2
|
||||
|
||||
# build the trap frame
|
||||
ldr r2, [r0, #12] // read the r14_irq, then save it
|
||||
stmfd r13!, {r2}
|
||||
stmfd r13!, {r14}
|
||||
stmfd r13, {sp, lr}^
|
||||
stmfd r13!, {r3-r12} // r4-r12 are preserved (non-banked)
|
||||
ldmfd r0, {r3-r5} // copy r0-r2 over from irq stack
|
||||
stmfd r13!, {r3-r5}
|
||||
stmfd r13!, {r1} // save spsr
|
||||
stmfd r13!, {lr} // save lr_svc
|
||||
|
||||
stmfd r13, {sp, lr}^ // save user mode sp and lr
|
||||
sub r13, r13, #8
|
||||
mov r0, r13
|
||||
|
||||
mov r0, r13 // trapframe as parameters
|
||||
bl iabort_handler
|
||||
|
||||
trap_undefined_instruction:
|
||||
sub r13, r13, #56
|
||||
str r14, [r13, #52]
|
||||
str r12, [r13, #48]
|
||||
str r11, [r13, #44]
|
||||
str r10, [r13, #40]
|
||||
str r9, [r13, #36]
|
||||
str r8, [r13, #32]
|
||||
str r7, [r13, #28]
|
||||
str r6, [r13, #24]
|
||||
str r5, [r13, #20]
|
||||
str r4, [r13, #16]
|
||||
str r3, [r13, #12]
|
||||
str r2, [r13, #8]
|
||||
str r1, [r13, #4]
|
||||
str r0, [r13]
|
||||
# save it on the stack as r14 is banked
|
||||
cpsid i
|
||||
sub r14, r14, #4 // r14 (lr) contains the interrupted PC
|
||||
stmfd r13!, {r0-r2, r14} //
|
||||
mrs r1, spsr // save spsr_irq
|
||||
mov r0, r13 // save stack stop (r13_irq)
|
||||
add r13, r13, #16 // reset the IRQ stack
|
||||
|
||||
mrs r2, spsr
|
||||
# switch to the SVC mode
|
||||
mrs r2, cpsr
|
||||
bic r2, r2, #ARM_CPSR_MODE_MASK
|
||||
orr r2, r2, #ARM_MODE_SVC
|
||||
msr cpsr_cxsf, r2
|
||||
|
||||
# build the trap frame
|
||||
ldr r2, [r0, #12] // read the r14_irq, then save it
|
||||
stmfd r13!, {r2}
|
||||
stmfd r13!, {r14}
|
||||
stmfd r13, {sp, lr}^
|
||||
sub r13, r13, #8
|
||||
mov r0, r13
|
||||
bl handle_undefined_instruction
|
||||
stmfd r13!, {r3-r12} // r4-r12 are preserved (non-banked)
|
||||
ldmfd r0, {r3-r5} // copy r0-r2 over from irq stack
|
||||
stmfd r13!, {r3-r5}
|
||||
stmfd r13!, {r1} // save spsr
|
||||
stmfd r13!, {lr} // save lr_svc
|
||||
|
||||
stmfd r13, {sp, lr}^ // save user mode sp and lr
|
||||
sub r13, r13, #8
|
||||
|
||||
mov r0, r13 // trapframe as parameters
|
||||
bl handle_undefined_instruction
|
||||
|
||||
init_stack:
|
||||
# set the stack for Other mode
|
||||
|
|
|
@ -42,12 +42,13 @@ extern void trap_iabort(void);
|
|||
extern void trap_dabort(void);
|
||||
extern void trap_irq_enter(void);
|
||||
extern void trap_undefined_instruction(void);
|
||||
extern void handle_reserved(void);
|
||||
extern void handle_fiq(void);
|
||||
|
||||
static struct XiziTrapDriver xizi_trap_driver;
|
||||
|
||||
void panic(char* s)
|
||||
{
|
||||
xizi_trap_driver.cpu_irq_disable();
|
||||
KPrintf("panic: %s\n", s);
|
||||
for (;;)
|
||||
;
|
||||
|
@ -55,7 +56,6 @@ void panic(char* s)
|
|||
|
||||
/* stack for different mode*/
|
||||
static char mode_stack_pages[NR_CPU][NR_MODE_STACKS][MODE_STACK_SIZE];
|
||||
|
||||
extern uint32_t _vector_jumper;
|
||||
extern uint32_t _vector_start;
|
||||
extern uint32_t _vector_end;
|
||||
|
@ -72,19 +72,6 @@ void init_cpu_mode_stacks(int cpu_id)
|
|||
}
|
||||
}
|
||||
|
||||
void handle_reserved(void)
|
||||
{
|
||||
// unimplemented trap handler
|
||||
LOG("Unimplemented Reserved\n");
|
||||
panic("");
|
||||
}
|
||||
|
||||
void handle_fiq(void)
|
||||
{
|
||||
LOG("Unimplemented FIQ\n");
|
||||
panic("");
|
||||
}
|
||||
|
||||
static void _sys_irq_init(int cpu_id)
|
||||
{
|
||||
|
||||
|
@ -101,18 +88,18 @@ static void _sys_irq_init(int cpu_id)
|
|||
vector_base[5] = (uint32_t)handle_reserved; // Reserved
|
||||
vector_base[6] = (uint32_t)trap_irq_enter; // IRQ
|
||||
vector_base[7] = (uint32_t)handle_fiq; // FIQ
|
||||
}
|
||||
|
||||
/* active hardware irq responser */
|
||||
XScuGic_Config* gic_config = XScuGic_LookupConfig(XPAR_PS7_SCUGIC_0_DEVICE_ID);
|
||||
if (NULL == gic_config) {
|
||||
ERROR("Error while looking up gic config\n");
|
||||
return;
|
||||
}
|
||||
int gic_init_status = XScuGic_CfgInitialize(&IntcInstance, gic_config, gic_config->CpuBaseAddress);
|
||||
if (gic_init_status != XST_SUCCESS) {
|
||||
ERROR("Error initializing gic\n");
|
||||
return;
|
||||
/* active hardware irq responser */
|
||||
XScuGic_Config* gic_config = XScuGic_LookupConfig(XPAR_PS7_SCUGIC_0_DEVICE_ID);
|
||||
if (NULL == gic_config) {
|
||||
ERROR("Error while looking up gic config\n");
|
||||
return;
|
||||
}
|
||||
int gic_init_status = XScuGic_CfgInitialize(&IntcInstance, gic_config, gic_config->CpuBaseAddress);
|
||||
if (gic_init_status != XST_SUCCESS) {
|
||||
ERROR("Error initializing gic\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
xizi_trap_driver.switch_hw_irqtbl((uint32_t*)&_vector_jumper);
|
||||
|
@ -164,24 +151,6 @@ static void _bind_irq_handler(int irq, irq_handler_t handler)
|
|||
xizi_trap_driver.sw_irqtbl[irq].handler = handler;
|
||||
}
|
||||
|
||||
static bool _send_sgi(uint32_t irq, uint32_t bitmask, enum SgiFilterType type)
|
||||
{
|
||||
if (bitmask > (1 << NR_CPU) - 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int cpu_id = 0;
|
||||
while (bitmask != 0) {
|
||||
if ((bitmask & 0x1) != 0) {
|
||||
XScuGic_SoftwareIntr(&IntcInstance, irq, cpu_id);
|
||||
}
|
||||
cpu_id++;
|
||||
bitmask >>= 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static uint32_t _hw_before_irq()
|
||||
{
|
||||
|
||||
|
@ -194,29 +163,11 @@ static uint32_t _hw_cur_int_num(uint32_t int_info)
|
|||
return int_info & XSCUGIC_ACK_INTID_MASK;
|
||||
}
|
||||
|
||||
static uint32_t _hw_cur_int_cpu(uint32_t int_info)
|
||||
{
|
||||
return (int_info >> 5) & 0x3;
|
||||
}
|
||||
|
||||
static void _hw_after_irq(uint32_t int_info)
|
||||
{
|
||||
XScuGic_CPUWriteReg(&IntcInstance, XSCUGIC_EOI_OFFSET, int_info);
|
||||
}
|
||||
|
||||
static int _is_interruptable(void)
|
||||
{
|
||||
uint32_t val;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mrs %0, cpsr"
|
||||
: "=r"(val)
|
||||
:
|
||||
:);
|
||||
|
||||
return !(val & DIS_INT);
|
||||
}
|
||||
|
||||
int _cur_cpu_id()
|
||||
{
|
||||
return cpu_get_current();
|
||||
|
@ -233,18 +184,15 @@ static struct XiziTrapDriver xizi_trap_driver = {
|
|||
.switch_hw_irqtbl = _switch_hw_irqtbl,
|
||||
|
||||
.bind_irq_handler = _bind_irq_handler,
|
||||
.send_sgi = _send_sgi,
|
||||
|
||||
.is_interruptable = _is_interruptable,
|
||||
.hw_before_irq = _hw_before_irq,
|
||||
.hw_cur_int_num = _hw_cur_int_num,
|
||||
.hw_cur_int_cpu = _hw_cur_int_cpu,
|
||||
.hw_after_irq = _hw_after_irq,
|
||||
};
|
||||
|
||||
struct XiziTrapDriver* hardkernel_intr_init(struct TraceTag* hardkernel_tag)
|
||||
{
|
||||
xizi_trap_driver.sys_irq_init(0);
|
||||
xizi_trap_driver.cpu_irq_enable();
|
||||
xizi_trap_driver.cpu_irq_disable();
|
||||
return &xizi_trap_driver;
|
||||
}
|
|
@ -27,8 +27,8 @@
|
|||
#include "multicores.h"
|
||||
|
||||
struct lock_node {
|
||||
int cpu_id;
|
||||
struct double_list_node node;
|
||||
int cpu_id;
|
||||
};
|
||||
|
||||
static struct double_list_node lock_request_guard;
|
||||
|
@ -52,7 +52,7 @@ enum {
|
|||
SPINLOCK_LOCK_WAITFOREVER = 0xFFFFFFFF,
|
||||
};
|
||||
|
||||
void spinlock_init(struct spinlock* lock, char* name)
|
||||
__attribute__((optimize("O0"))) void spinlock_init(struct spinlock* lock, char* name)
|
||||
{
|
||||
lock->owner_cpu = SPINLOCK_STATE_UNLOCK;
|
||||
strncpy(lock->name, name, 24);
|
||||
|
@ -61,33 +61,59 @@ void spinlock_init(struct spinlock* lock, char* name)
|
|||
extern int _spinlock_lock(struct spinlock* lock, uint32_t timeout);
|
||||
void _spinlock_unlock(struct spinlock* lock);
|
||||
|
||||
void spinlock_lock(struct spinlock* lock)
|
||||
__attribute__((optimize("O0"))) void spinlock_lock(struct spinlock* lock)
|
||||
{
|
||||
if (lock->owner_cpu != SPINLOCK_STATE_UNLOCK && lock->owner_cpu == cur_cpuid()) {
|
||||
int cur_cpu_id = cur_cpuid();
|
||||
if (lock->owner_cpu != SPINLOCK_STATE_UNLOCK && lock->owner_cpu == cur_cpu_id) {
|
||||
ERROR("spinlock %s lock double locked by core %d\n", lock->name, lock->owner_cpu);
|
||||
panic("");
|
||||
}
|
||||
|
||||
struct double_list_node* p_lock_node = &core_lock_request[cur_cpu_id].node;
|
||||
_spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
doubleListAddOnBack(&core_lock_request[cur_cpuid()].node, &lock_request_guard);
|
||||
doubleListAddOnBack(p_lock_node, &lock_request_guard);
|
||||
_spinlock_unlock(&request_lock);
|
||||
|
||||
while (lock_request_guard.next != &core_lock_request[cur_cpuid()].node)
|
||||
while (lock_request_guard.next != p_lock_node)
|
||||
;
|
||||
|
||||
_spinlock_lock(lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
}
|
||||
|
||||
void spinlock_unlock(struct spinlock* lock)
|
||||
__attribute__((optimize("O0"))) void spinlock_unlock(struct spinlock* lock)
|
||||
{
|
||||
assert(lock_request_guard.next == &core_lock_request[cur_cpuid()].node);
|
||||
struct double_list_node* p_lock_node = &core_lock_request[cur_cpuid()].node;
|
||||
assert(lock_request_guard.next == p_lock_node);
|
||||
_spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
_double_list_del(core_lock_request[cur_cpuid()].node.prev, core_lock_request[cur_cpuid()].node.next);
|
||||
_double_list_del(p_lock_node->prev, p_lock_node->next);
|
||||
_spinlock_unlock(&request_lock);
|
||||
|
||||
_spinlock_unlock(lock);
|
||||
}
|
||||
|
||||
bool is_spinlock_locked(struct spinlock* lock)
|
||||
__attribute__((optimize("O0"))) bool spinlock_try_lock(struct spinlock* lock)
|
||||
{
|
||||
return lock->owner_cpu != SPINLOCK_STATE_UNLOCK;
|
||||
int cur_cpu_id = cur_cpuid();
|
||||
if (lock->owner_cpu != SPINLOCK_STATE_UNLOCK && lock->owner_cpu == cur_cpu_id) {
|
||||
ERROR("spinlock %s lock double locked by core %d\n", lock->name, lock->owner_cpu);
|
||||
panic("");
|
||||
}
|
||||
|
||||
struct double_list_node* p_lock_node = &core_lock_request[cur_cpu_id].node;
|
||||
_spinlock_lock(&request_lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
doubleListAddOnBack(p_lock_node, &lock_request_guard);
|
||||
if (lock_request_guard.next != p_lock_node) {
|
||||
_double_list_del(p_lock_node->prev, p_lock_node->next);
|
||||
_spinlock_unlock(&request_lock);
|
||||
return false;
|
||||
}
|
||||
_spinlock_unlock(&request_lock);
|
||||
_spinlock_lock(lock, SPINLOCK_LOCK_WAITFOREVER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_spinlock_hold_by_current_cpu(struct spinlock* lock)
|
||||
{
|
||||
return lock->owner_cpu;
|
||||
}
|
|
@ -34,7 +34,7 @@ Modification:
|
|||
#define STACK_DEPTH 32
|
||||
|
||||
struct spinlock { // Mutex.
|
||||
uint32_t owner_cpu; // 1 for locked, 0 for unlocked
|
||||
volatile uint32_t owner_cpu; // 1 for locked, 0 for unlocked
|
||||
char name[28]; // The call stack (an array of program counters)
|
||||
} __attribute__((aligned(32)));
|
||||
|
||||
|
@ -42,4 +42,5 @@ bool module_spinlock_use_intr_init(void);
|
|||
void spinlock_init(struct spinlock* lock, char* name);
|
||||
void spinlock_lock(struct spinlock* lock);
|
||||
void spinlock_unlock(struct spinlock* lock);
|
||||
bool is_spinlock_locked(struct spinlock* lock);
|
||||
bool spinlock_try_lock(struct spinlock* lock);
|
||||
bool is_spinlock_hold_by_current_cpu(struct spinlock* lock);
|
|
@ -56,8 +56,6 @@ struct irq_table_entry {
|
|||
struct XiziTrapDriver {
|
||||
/* irq number table*/
|
||||
struct irq_table_entry sw_irqtbl[NR_IRQS];
|
||||
/* current irq number happening in cpu*/
|
||||
uint32_t curr_int[NR_CPU];
|
||||
|
||||
void (*sys_irq_init)(int);
|
||||
int (*cur_cpu_id)();
|
||||
|
@ -66,17 +64,14 @@ struct XiziTrapDriver {
|
|||
void (*cpu_irq_disable)();
|
||||
void (*single_irq_enable)(int irq, int cpu, int prio);
|
||||
void (*single_irq_disable)(int irq, int cpu);
|
||||
uint32_t* (*switch_hw_irqtbl)(uint32_t*);
|
||||
|
||||
bool (*send_sgi)(uint32_t, uint32_t, enum SgiFilterType);
|
||||
uint32_t* (*switch_hw_irqtbl)(uint32_t*);
|
||||
void (*bind_irq_handler)(int, irq_handler_t);
|
||||
|
||||
/* check if no if interruptable */
|
||||
int (*is_interruptable)();
|
||||
/* code runs before irq handling */
|
||||
uint32_t (*hw_before_irq)();
|
||||
uint32_t (*hw_cur_int_num)(uint32_t int_info);
|
||||
uint32_t (*hw_cur_int_cpu)(uint32_t int_info);
|
||||
/* code runs after irq handling */
|
||||
void (*hw_after_irq)(uint32_t int_info);
|
||||
};
|
||||
|
@ -101,4 +96,7 @@ void panic(char* s);
|
|||
bool intr_distributer_init(struct IrqDispatcherRightGroup*);
|
||||
void intr_irq_dispatch(struct trapframe* tf);
|
||||
bool swi_distributer_init(struct SwiDispatcherRightGroup*);
|
||||
void software_irq_dispatch(struct trapframe* tf);
|
||||
void software_irq_dispatch(struct trapframe* tf);
|
||||
|
||||
void dabort_reason(struct trapframe* r);
|
||||
void iabort_reason(struct trapframe* r);
|
|
@ -56,10 +56,11 @@ Modification:
|
|||
#define MAX_NR_FREE_PAGES ((PHY_MEM_STOP - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT)
|
||||
|
||||
/* User memory layout */
|
||||
#define USER_STACK_SIZE PAGE_SIZE
|
||||
#define USER_STACK_SIZE MODE_STACK_SIZE
|
||||
#define USER_MEM_BASE (0x00000000)
|
||||
#define USER_MEM_TOP DEV_VRTMEM_BASE
|
||||
#define USER_IPC_SPACE_BASE (0x70000000)
|
||||
#define USER_IPC_USE_ALLOCATOR_WATERMARK (0x70010000)
|
||||
#define USER_IPC_SPACE_TOP (USER_MEM_TOP - USER_STACK_SIZE)
|
||||
|
||||
/* Deivce memory layout */
|
||||
|
|
|
@ -38,24 +38,6 @@ Modification:
|
|||
// extern struct MmuCommonDone mmu_common_done;
|
||||
static struct MmuDriverRightGroup right_group;
|
||||
|
||||
void load_pgdir_critical(uintptr_t pgdir_paddr, struct TraceTag* intr_driver_tag)
|
||||
{
|
||||
|
||||
/* get cache driver */
|
||||
struct ICacheDone* p_icache_done = AchieveResource(&right_group.icache_driver_tag);
|
||||
struct DCacheDone* p_dcache_done = AchieveResource(&right_group.dcache_driver_tag);
|
||||
|
||||
/* get intr driver */
|
||||
struct XiziTrapDriver* p_intr_driver = AchieveResource(intr_driver_tag);
|
||||
|
||||
p_intr_driver->cpu_irq_disable();
|
||||
TTBR0_W((uint32_t)pgdir_paddr);
|
||||
CLEARTLB(0);
|
||||
p_icache_done->invalidateall();
|
||||
p_dcache_done->flushall();
|
||||
p_intr_driver->cpu_irq_enable();
|
||||
}
|
||||
|
||||
void load_pgdir(uintptr_t pgdir_paddr)
|
||||
{
|
||||
/* get cache driver */
|
||||
|
@ -94,7 +76,6 @@ static struct MmuCommonDone mmu_common_done = {
|
|||
.MmuUsrDevPteAttr = GetUsrDevPteAttr,
|
||||
.MmuKernPteAttr = GetKernPteAttr,
|
||||
|
||||
.LoadPgdirCrit = load_pgdir_critical,
|
||||
.LoadPgdir = load_pgdir,
|
||||
.TlbFlushAll = tlb_flush_all,
|
||||
.TlbFlush = tlb_flush_range,
|
||||
|
|
|
@ -53,13 +53,14 @@ Modification:
|
|||
#define NUM_TOPLEVEL_PDE NUM_LEVEL3_PDE
|
||||
|
||||
#define PAGE_SIZE LEVEL4_PTE_SIZE
|
||||
#define MAX_NR_FREE_PAGES ((PHY_MEM_STOP - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT)
|
||||
#define MAX_NR_FREE_PAGES ((PHY_USER_FREEMEM_BASE - PHY_MEM_BASE) >> LEVEL4_PTE_SHIFT)
|
||||
|
||||
/* User memory layout */
|
||||
#define USER_STACK_SIZE PAGE_SIZE
|
||||
#define USER_STACK_SIZE MODE_STACK_SIZE
|
||||
#define USER_MEM_BASE (0x00000000)
|
||||
#define USER_MEM_TOP DEV_VRTMEM_BASE
|
||||
#define USER_IPC_SPACE_BASE (0x70000000)
|
||||
#define USER_IPC_USE_ALLOCATOR_WATERMARK (0x70010000)
|
||||
#define USER_IPC_SPACE_TOP (USER_MEM_TOP - USER_STACK_SIZE)
|
||||
|
||||
/* Deivce memory layout */
|
||||
|
|
|
@ -27,7 +27,6 @@ struct MmuCommonDone
|
|||
void (*MmuUsrDevPteAttr)(uintptr_t* attr);
|
||||
void (*MmuKernPteAttr)(uintptr_t* attr);
|
||||
|
||||
void (*LoadPgdirCrit)(uintptr_t pgdir_paddr, struct TraceTag*);
|
||||
void (*LoadPgdir)(uintptr_t pgdir_paddr);
|
||||
void (*TlbFlushAll)();
|
||||
void (*TlbFlush)(uintptr_t vaddr, int len);
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// \author (c) Marco Paland (info@paland.com)
|
||||
// 2014-2019, PALANDesign Hannover, Germany
|
||||
//
|
||||
// \license The MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
|
||||
// embedded systems with a very limited resources.
|
||||
// Use this instead of bloated standard/newlib printf.
|
||||
// These routines are thread safe and reentrant.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PRINTF_H_
|
||||
#define _PRINTF_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Tiny printf implementation
|
||||
* You have to implement _putchar if you use printf()
|
||||
* To avoid conflicts with the regular printf() API it is overridden by macro defines
|
||||
* and internal underscore-appended functions like printf_() are used
|
||||
* \param format A string that specifies the format of the output
|
||||
* \return The number of characters that are written into the array, not counting the terminating null character
|
||||
*/
|
||||
#define KPrintf printf_
|
||||
#define printf printf_
|
||||
int printf_(const char* format, ...);
|
||||
|
||||
/**
|
||||
* Tiny sprintf implementation
|
||||
* Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
|
||||
* \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
|
||||
* \param format A string that specifies the format of the output
|
||||
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
||||
*/
|
||||
#define sprintf sprintf_
|
||||
int sprintf_(char* buffer, const char* format, ...);
|
||||
|
||||
/**
|
||||
* Tiny snprintf/vsnprintf implementation
|
||||
* \param buffer A pointer to the buffer where to store the formatted string
|
||||
* \param count The maximum number of characters to store in the buffer, including a terminating null character
|
||||
* \param format A string that specifies the format of the output
|
||||
* \param va A value identifying a variable arguments list
|
||||
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
|
||||
* null character. A value equal or larger than count indicates truncation. Only when the returned value
|
||||
* is non-negative and less than count, the string has been completely written.
|
||||
*/
|
||||
#define snprintf snprintf_
|
||||
#define vsnprintf vsnprintf_
|
||||
int snprintf_(char* buffer, size_t count, const char* format, ...);
|
||||
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
|
||||
|
||||
/**
|
||||
* Tiny vprintf implementation
|
||||
* \param format A string that specifies the format of the output
|
||||
* \param va A value identifying a variable arguments list
|
||||
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
||||
*/
|
||||
#define vprintf vprintf_
|
||||
int vprintf_(const char* format, va_list va);
|
||||
|
||||
/**
|
||||
* printf with output function
|
||||
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
|
||||
* \param out An output function which takes one character and an argument pointer
|
||||
* \param arg An argument pointer for user data passed to output function
|
||||
* \param format A string that specifies the format of the output
|
||||
* \return The number of characters that are sent to the output function, not counting the terminating null character
|
||||
*/
|
||||
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _PRINTF_H_
|
|
@ -1,15 +1,34 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// \author (c) Marco Paland (info@paland.com)
|
||||
// 2014-2019, PALANDesign Hannover, Germany
|
||||
//
|
||||
// \license The MIT License (MIT)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
// \brief Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on
|
||||
// embedded systems with a very limited resources. These routines are thread
|
||||
// safe and reentrant!
|
||||
// Use this instead of the bloated standard/newlib printf cause these use
|
||||
// malloc for printf (and may not be thread safe).
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @file uart_common_ope.c
|
||||
* @brief support uart common operation
|
||||
|
@ -17,8 +36,10 @@
|
|||
* @author AIIT XUOS Lab
|
||||
* @date 2023.11.20
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "uart_common_ope.h"
|
||||
#include "assert.h"
|
||||
|
||||
struct PrintProxy {
|
||||
struct TraceTag uart_driver_tag;
|
||||
|
@ -38,85 +59,840 @@ int serial_init(struct TraceTag* uart_driver_tag)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void PrintInt(int xx, int base, int sign)
|
||||
// 'ntoa' conversion buffer size, this must be big enough to hold one converted
|
||||
// numeric number including padded zeros (dynamically created on stack)
|
||||
// default: 32 byte
|
||||
#define PRINTF_NTOA_BUFFER_SIZE 32U
|
||||
|
||||
#define PRINTF_FTOA_BUFFER_SIZE 32U
|
||||
|
||||
// support for the floating point type (%f)
|
||||
// default: activated
|
||||
#define PRINTF_SUPPORT_FLOAT
|
||||
|
||||
// support for exponential floating point notation (%e/%g)
|
||||
// default: activated
|
||||
#define PRINTF_SUPPORT_EXPONENTIAL
|
||||
|
||||
// define the default floating point precision
|
||||
// default: 6 digits
|
||||
#define PRINTF_DEFAULT_FLOAT_PRECISION 6U
|
||||
|
||||
// define the largest float suitable to print with %f
|
||||
// default: 1e9
|
||||
#define PRINTF_MAX_FLOAT 1e9
|
||||
|
||||
// support for the long long types (%llu or %p)
|
||||
// default: activated
|
||||
#define PRINTF_SUPPORT_LONG_LONG
|
||||
|
||||
// support for the ptrdiff_t type (%t)
|
||||
// ptrdiff_t is normally defined in <stddef.h> as long or long long type
|
||||
// default: activated
|
||||
#define PRINTF_SUPPORT_PTRDIFF_T
|
||||
|
||||
#define _putchar proxy()->serial->putc
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// internal flag definitions
|
||||
#define FLAGS_ZEROPAD (1U << 0U)
|
||||
#define FLAGS_LEFT (1U << 1U)
|
||||
#define FLAGS_PLUS (1U << 2U)
|
||||
#define FLAGS_SPACE (1U << 3U)
|
||||
#define FLAGS_HASH (1U << 4U)
|
||||
#define FLAGS_UPPERCASE (1U << 5U)
|
||||
#define FLAGS_CHAR (1U << 6U)
|
||||
#define FLAGS_SHORT (1U << 7U)
|
||||
#define FLAGS_LONG (1U << 8U)
|
||||
#define FLAGS_LONG_LONG (1U << 9U)
|
||||
#define FLAGS_PRECISION (1U << 10U)
|
||||
#define FLAGS_ADAPT_EXP (1U << 11U)
|
||||
|
||||
// import float.h for DBL_MAX
|
||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
// output function type
|
||||
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen);
|
||||
|
||||
// wrapper (used as buffer) for output function type
|
||||
typedef struct {
|
||||
void (*fct)(char character, void* arg);
|
||||
void* arg;
|
||||
} out_fct_wrap_type;
|
||||
|
||||
// internal buffer output
|
||||
static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen)
|
||||
{
|
||||
static char digits[] = "0123456789ABCDEF";
|
||||
char buf[16];
|
||||
int i;
|
||||
uint32_t x;
|
||||
|
||||
if (sign && (sign = xx < 0)) {
|
||||
x = -xx;
|
||||
} else {
|
||||
x = xx;
|
||||
if (idx < maxlen) {
|
||||
((char*)buffer)[idx] = character;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
do {
|
||||
buf[i++] = digits[x % base];
|
||||
} while ((x /= base) != 0);
|
||||
|
||||
if (sign)
|
||||
buf[i++] = '-';
|
||||
|
||||
while (--i >= 0)
|
||||
proxy()->serial->putc(buf[i]);
|
||||
}
|
||||
|
||||
void KPrintf(char* fmt, ...)
|
||||
// internal null output
|
||||
static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen)
|
||||
{
|
||||
int i, c;
|
||||
uint32_t* argp;
|
||||
char* s;
|
||||
(void)character;
|
||||
(void)buffer;
|
||||
(void)idx;
|
||||
(void)maxlen;
|
||||
}
|
||||
|
||||
if (fmt == 0) {
|
||||
KPrintf("null fmt");
|
||||
return;
|
||||
// internal _putchar wrapper
|
||||
static inline void _out_char(char character, void* buffer, size_t idx, size_t maxlen)
|
||||
{
|
||||
(void)buffer;
|
||||
(void)idx;
|
||||
(void)maxlen;
|
||||
if (character) {
|
||||
_putchar(character);
|
||||
}
|
||||
}
|
||||
|
||||
// internal output function wrapper
|
||||
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen)
|
||||
{
|
||||
(void)idx;
|
||||
(void)maxlen;
|
||||
if (character) {
|
||||
// buffer is the output fct pointer
|
||||
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
|
||||
}
|
||||
}
|
||||
|
||||
// internal secure strlen
|
||||
// \return The length of the string (excluding the terminating 0) limited by 'maxsize'
|
||||
static inline unsigned int _strnlen_s(const char* str, size_t maxsize)
|
||||
{
|
||||
const char* s;
|
||||
for (s = str; *s && maxsize--; ++s)
|
||||
;
|
||||
return (unsigned int)(s - str);
|
||||
}
|
||||
|
||||
// internal test if char is a digit (0-9)
|
||||
// \return true if char is a digit
|
||||
static inline bool _is_digit(char ch)
|
||||
{
|
||||
return (ch >= '0') && (ch <= '9');
|
||||
}
|
||||
|
||||
// internal ASCII string to unsigned int conversion
|
||||
static unsigned int _atoi(const char** str)
|
||||
{
|
||||
unsigned int i = 0U;
|
||||
while (_is_digit(**str)) {
|
||||
i = i * 10U + (unsigned int)(*((*str)++) - '0');
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
// output the specified string in reverse, taking care of any zero-padding
|
||||
static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen, const char* buf, size_t len, unsigned int width, unsigned int flags)
|
||||
{
|
||||
const size_t start_idx = idx;
|
||||
|
||||
// pad spaces up to given width
|
||||
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
|
||||
for (size_t i = len; i < width; i++) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
|
||||
argp = (uint32_t*)(void*)(&fmt + 1);
|
||||
// reverse string
|
||||
while (len) {
|
||||
out(buf[--len], buffer, idx++, maxlen);
|
||||
}
|
||||
|
||||
for (i = 0; (c = fmt[i] & 0xff) != 0; i++) {
|
||||
if (c != '%') {
|
||||
proxy()->serial->putc(c);
|
||||
// append pad spaces up to given width
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (idx - start_idx < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
// internal itoa format
|
||||
static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
// pad leading zeros
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
||||
width--;
|
||||
}
|
||||
while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
// handle hash
|
||||
if (flags & FLAGS_HASH) {
|
||||
if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) {
|
||||
len--;
|
||||
if (len && (base == 16U)) {
|
||||
len--;
|
||||
}
|
||||
}
|
||||
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = 'x';
|
||||
} else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = 'X';
|
||||
} else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = 'b';
|
||||
}
|
||||
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
||||
if (negative) {
|
||||
buf[len++] = '-';
|
||||
} else if (flags & FLAGS_PLUS) {
|
||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||
} else if (flags & FLAGS_SPACE) {
|
||||
buf[len++] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
|
||||
}
|
||||
|
||||
// internal itoa for 'long' type
|
||||
static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
|
||||
// no hash for 0 values
|
||||
if (!value) {
|
||||
flags &= ~FLAGS_HASH;
|
||||
}
|
||||
|
||||
// write if precision != 0 and value is != 0
|
||||
if (!(flags & FLAGS_PRECISION) || value) {
|
||||
do {
|
||||
const char digit = (char)(value % base);
|
||||
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||
value /= base;
|
||||
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
|
||||
}
|
||||
|
||||
// internal itoa for 'long long' type
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
|
||||
// no hash for 0 values
|
||||
if (!value) {
|
||||
flags &= ~FLAGS_HASH;
|
||||
}
|
||||
|
||||
// write if precision != 0 and value is != 0
|
||||
if (!(flags & FLAGS_PRECISION) || value) {
|
||||
do {
|
||||
const char digit = (char)(value % base);
|
||||
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||
value /= base;
|
||||
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_LONG_LONG
|
||||
|
||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT
|
||||
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags);
|
||||
#endif
|
||||
|
||||
// internal ftoa for fixed decimal floating point
|
||||
static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
char buf[PRINTF_FTOA_BUFFER_SIZE];
|
||||
size_t len = 0U;
|
||||
double diff = 0.0;
|
||||
|
||||
// powers of 10
|
||||
static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
|
||||
|
||||
// test for special values
|
||||
if (value != value)
|
||||
return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags);
|
||||
if (value < -DBL_MAX)
|
||||
return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags);
|
||||
if (value > DBL_MAX)
|
||||
return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width, flags);
|
||||
|
||||
// test for very large values
|
||||
// standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
|
||||
if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) {
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
return _etoa(out, buffer, idx, maxlen, value, prec, width, flags);
|
||||
#else
|
||||
return 0U;
|
||||
#endif
|
||||
}
|
||||
|
||||
// test for negative
|
||||
bool negative = false;
|
||||
if (value < 0) {
|
||||
negative = true;
|
||||
value = 0 - value;
|
||||
}
|
||||
|
||||
// set default precision, if not set explicitly
|
||||
if (!(flags & FLAGS_PRECISION)) {
|
||||
prec = PRINTF_DEFAULT_FLOAT_PRECISION;
|
||||
}
|
||||
// limit precision to 9, cause a prec >= 10 can lead to overflow errors
|
||||
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) {
|
||||
buf[len++] = '0';
|
||||
prec--;
|
||||
}
|
||||
|
||||
int whole = (int)value;
|
||||
double tmp = (value - whole) * pow10[prec];
|
||||
unsigned long frac = (unsigned long)tmp;
|
||||
diff = tmp - frac;
|
||||
|
||||
if (diff > 0.5) {
|
||||
++frac;
|
||||
// handle rollover, e.g. case 0.99 with prec 1 is 1.0
|
||||
if (frac >= pow10[prec]) {
|
||||
frac = 0;
|
||||
++whole;
|
||||
}
|
||||
} else if (diff < 0.5) {
|
||||
} else if ((frac == 0U) || (frac & 1U)) {
|
||||
// if halfway, round up if odd OR if last digit is 0
|
||||
++frac;
|
||||
}
|
||||
|
||||
if (prec == 0U) {
|
||||
diff = value - (double)whole;
|
||||
if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) {
|
||||
// exactly 0.5 and ODD, then round up
|
||||
// 1.5 -> 2, but 2.5 -> 2
|
||||
++whole;
|
||||
}
|
||||
} else {
|
||||
unsigned int count = prec;
|
||||
// now do fractional part, as an unsigned number
|
||||
while (len < PRINTF_FTOA_BUFFER_SIZE) {
|
||||
--count;
|
||||
buf[len++] = (char)(48U + (frac % 10U));
|
||||
if (!(frac /= 10U)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// add extra 0s
|
||||
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
if (len < PRINTF_FTOA_BUFFER_SIZE) {
|
||||
// add decimal
|
||||
buf[len++] = '.';
|
||||
}
|
||||
}
|
||||
|
||||
// do whole part, number is reversed
|
||||
while (len < PRINTF_FTOA_BUFFER_SIZE) {
|
||||
buf[len++] = (char)(48 + (whole % 10));
|
||||
if (!(whole /= 10)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// pad leading zeros
|
||||
if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) {
|
||||
if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
||||
width--;
|
||||
}
|
||||
while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
|
||||
buf[len++] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
if (len < PRINTF_FTOA_BUFFER_SIZE) {
|
||||
if (negative) {
|
||||
buf[len++] = '-';
|
||||
} else if (flags & FLAGS_PLUS) {
|
||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||
} else if (flags & FLAGS_SPACE) {
|
||||
buf[len++] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
|
||||
}
|
||||
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
|
||||
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
// check for NaN and special values
|
||||
if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) {
|
||||
return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags);
|
||||
}
|
||||
|
||||
// determine the sign
|
||||
const bool negative = value < 0;
|
||||
if (negative) {
|
||||
value = -value;
|
||||
}
|
||||
|
||||
// default precision
|
||||
if (!(flags & FLAGS_PRECISION)) {
|
||||
prec = PRINTF_DEFAULT_FLOAT_PRECISION;
|
||||
}
|
||||
|
||||
// determine the decimal exponent
|
||||
// based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c)
|
||||
union {
|
||||
uint64_t U;
|
||||
double F;
|
||||
} conv;
|
||||
|
||||
conv.F = value;
|
||||
int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2
|
||||
conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2)
|
||||
// now approximate log10 from the log2 integer part and an expansion of ln around 1.5
|
||||
int expval = (int)(0.1760912590558 + exp2 * 0.301029995663981 + (conv.F - 1.5) * 0.289529654602168);
|
||||
// now we want to compute 10^expval but we want to be sure it won't overflow
|
||||
exp2 = (int)(expval * 3.321928094887362 + 0.5);
|
||||
const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453;
|
||||
const double z2 = z * z;
|
||||
conv.U = (uint64_t)(exp2 + 1023) << 52U;
|
||||
// compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex
|
||||
conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14)))));
|
||||
// correct for rounding errors
|
||||
if (value < conv.F) {
|
||||
expval--;
|
||||
conv.F /= 10;
|
||||
}
|
||||
|
||||
// the exponent format is "%+03d" and largest value is "307", so set aside 4-5 characters
|
||||
unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U;
|
||||
|
||||
// in "%g" mode, "prec" is the number of *significant figures* not decimals
|
||||
if (flags & FLAGS_ADAPT_EXP) {
|
||||
// do we want to fall-back to "%f" mode?
|
||||
if ((value >= 1e-4) && (value < 1e6)) {
|
||||
if ((int)prec > expval) {
|
||||
prec = (unsigned)((int)prec - expval - 1);
|
||||
} else {
|
||||
prec = 0;
|
||||
}
|
||||
flags |= FLAGS_PRECISION; // make sure _ftoa respects precision
|
||||
// no characters in exponent
|
||||
minwidth = 0U;
|
||||
expval = 0;
|
||||
} else {
|
||||
// we use one sigfig for the whole part
|
||||
if ((prec > 0) && (flags & FLAGS_PRECISION)) {
|
||||
--prec;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// will everything fit?
|
||||
unsigned int fwidth = width;
|
||||
if (width > minwidth) {
|
||||
// we didn't fall-back so subtract the characters required for the exponent
|
||||
fwidth -= minwidth;
|
||||
} else {
|
||||
// not enough characters, so go back to default sizing
|
||||
fwidth = 0U;
|
||||
}
|
||||
if ((flags & FLAGS_LEFT) && minwidth) {
|
||||
// if we're padding on the right, DON'T pad the floating part
|
||||
fwidth = 0U;
|
||||
}
|
||||
|
||||
// rescale the float value
|
||||
if (expval) {
|
||||
value /= conv.F;
|
||||
}
|
||||
|
||||
// output the floating part
|
||||
const size_t start_idx = idx;
|
||||
idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP);
|
||||
|
||||
// output the exponent part
|
||||
if (minwidth) {
|
||||
// output the exponential symbol
|
||||
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
|
||||
// output the exponent value
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1, FLAGS_ZEROPAD | FLAGS_PLUS);
|
||||
// might need to right-pad spaces
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (idx - start_idx < width)
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
|
||||
// internal vsnprintf
|
||||
static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va)
|
||||
{
|
||||
unsigned int flags, width, precision, n;
|
||||
size_t idx = 0U;
|
||||
|
||||
if (!buffer) {
|
||||
// use null output function
|
||||
out = _out_null;
|
||||
}
|
||||
|
||||
while (*format) {
|
||||
// format specifier? %[flags][width][.precision][length]
|
||||
if (*format != '%') {
|
||||
// no
|
||||
out(*format, buffer, idx++, maxlen);
|
||||
format++;
|
||||
continue;
|
||||
} else {
|
||||
// yes, evaluate it
|
||||
format++;
|
||||
}
|
||||
|
||||
c = fmt[++i] & 0xff;
|
||||
// evaluate flags
|
||||
flags = 0U;
|
||||
do {
|
||||
switch (*format) {
|
||||
case '0':
|
||||
flags |= FLAGS_ZEROPAD;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '-':
|
||||
flags |= FLAGS_LEFT;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '+':
|
||||
flags |= FLAGS_PLUS;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= FLAGS_SPACE;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
case '#':
|
||||
flags |= FLAGS_HASH;
|
||||
format++;
|
||||
n = 1U;
|
||||
break;
|
||||
default:
|
||||
n = 0U;
|
||||
break;
|
||||
}
|
||||
} while (n);
|
||||
|
||||
if (!c)
|
||||
// evaluate width field
|
||||
width = 0U;
|
||||
if (_is_digit(*format)) {
|
||||
width = _atoi(&format);
|
||||
} else if (*format == '*') {
|
||||
const int w = va_arg(va, int);
|
||||
if (w < 0) {
|
||||
flags |= FLAGS_LEFT; // reverse padding
|
||||
width = (unsigned int)-w;
|
||||
} else {
|
||||
width = (unsigned int)w;
|
||||
}
|
||||
format++;
|
||||
}
|
||||
|
||||
// evaluate precision field
|
||||
precision = 0U;
|
||||
if (*format == '.') {
|
||||
flags |= FLAGS_PRECISION;
|
||||
format++;
|
||||
if (_is_digit(*format)) {
|
||||
precision = _atoi(&format);
|
||||
} else if (*format == '*') {
|
||||
const int prec = (int)va_arg(va, int);
|
||||
precision = prec > 0 ? (unsigned int)prec : 0U;
|
||||
format++;
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate length field
|
||||
switch (*format) {
|
||||
case 'l':
|
||||
flags |= FLAGS_LONG;
|
||||
format++;
|
||||
if (*format == 'l') {
|
||||
flags |= FLAGS_LONG_LONG;
|
||||
format++;
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
flags |= FLAGS_SHORT;
|
||||
format++;
|
||||
if (*format == 'h') {
|
||||
flags |= FLAGS_CHAR;
|
||||
format++;
|
||||
}
|
||||
break;
|
||||
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
|
||||
case 't':
|
||||
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
#endif
|
||||
case 'j':
|
||||
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
case 'z':
|
||||
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
// evaluate specifier
|
||||
switch (*format) {
|
||||
case 'd':
|
||||
PrintInt(*argp++, 10, 1);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'p':
|
||||
PrintInt(*argp++, 16, 0);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if ((s = (char*)*argp++) == 0) {
|
||||
s = "(null)";
|
||||
case 'X':
|
||||
case 'o':
|
||||
case 'b': {
|
||||
// set the base
|
||||
unsigned int base;
|
||||
if (*format == 'x' || *format == 'X') {
|
||||
base = 16U;
|
||||
} else if (*format == 'o') {
|
||||
base = 8U;
|
||||
} else if (*format == 'b') {
|
||||
base = 2U;
|
||||
} else {
|
||||
base = 10U;
|
||||
flags &= ~FLAGS_HASH; // no hash for dec format
|
||||
}
|
||||
// uppercase
|
||||
if (*format == 'X') {
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
}
|
||||
|
||||
for (; *s; s++) {
|
||||
proxy()->serial->putc(*s);
|
||||
// no plus or space flag for u, x, X, o, b
|
||||
if ((*format != 'i') && (*format != 'd')) {
|
||||
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
|
||||
}
|
||||
|
||||
// ignore '0' flag when precision is given
|
||||
if (flags & FLAGS_PRECISION) {
|
||||
flags &= ~FLAGS_ZEROPAD;
|
||||
}
|
||||
|
||||
// convert the integer
|
||||
if ((*format == 'i') || (*format == 'd')) {
|
||||
// signed
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
const long long value = va_arg(va, long long);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
const long value = va_arg(va, long);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||
} else {
|
||||
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int)
|
||||
: va_arg(va, int);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||
}
|
||||
} else {
|
||||
// unsigned
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags);
|
||||
} else {
|
||||
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int)
|
||||
: va_arg(va, unsigned int);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||
case 'f':
|
||||
case 'F':
|
||||
if (*format == 'F')
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format++;
|
||||
break;
|
||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if ((*format == 'g') || (*format == 'G'))
|
||||
flags |= FLAGS_ADAPT_EXP;
|
||||
if ((*format == 'E') || (*format == 'G'))
|
||||
flags |= FLAGS_UPPERCASE;
|
||||
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format++;
|
||||
break;
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // PRINTF_SUPPORT_FLOAT
|
||||
case 'c': {
|
||||
unsigned int l = 1U;
|
||||
// pre padding
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// char output
|
||||
out((char)va_arg(va, int), buffer, idx++, maxlen);
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case 's': {
|
||||
const char* p = va_arg(va, char*);
|
||||
unsigned int l = _strnlen_s(p, precision ? precision : (size_t)-1);
|
||||
// pre padding
|
||||
if (flags & FLAGS_PRECISION) {
|
||||
l = (l < precision ? l : precision);
|
||||
}
|
||||
if (!(flags & FLAGS_LEFT)) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
// string output
|
||||
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||
out(*(p++), buffer, idx++, maxlen);
|
||||
}
|
||||
// post padding
|
||||
if (flags & FLAGS_LEFT) {
|
||||
while (l++ < width) {
|
||||
out(' ', buffer, idx++, maxlen);
|
||||
}
|
||||
}
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p': {
|
||||
width = sizeof(void*) * 2U;
|
||||
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
||||
if (is_ll) {
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags);
|
||||
} else {
|
||||
#endif
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags);
|
||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||
}
|
||||
#endif
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
||||
case '%':
|
||||
proxy()->serial->putc('%');
|
||||
out('%', buffer, idx++, maxlen);
|
||||
format++;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Print unknown % sequence to draw attention.
|
||||
proxy()->serial->putc('%');
|
||||
proxy()->serial->putc(c);
|
||||
out(*format, buffer, idx++, maxlen);
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// termination
|
||||
out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
|
||||
|
||||
// return written chars without terminating \0
|
||||
return (int)idx;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int printf_(const char* format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
char buffer[1];
|
||||
const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sprintf_(char* buffer, const char* format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va);
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int snprintf_(char* buffer, size_t count, const char* format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
const int ret = _vsnprintf(_out_buffer, buffer, count, format, va);
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vprintf_(const char* format, va_list va)
|
||||
{
|
||||
char buffer[1];
|
||||
return _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
||||
}
|
||||
|
||||
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
|
||||
{
|
||||
return _vsnprintf(_out_buffer, buffer, count, format, va);
|
||||
}
|
||||
|
||||
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
const out_fct_wrap_type out_fct_wrap = { out, arg };
|
||||
const int ret = _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va);
|
||||
va_end(va);
|
||||
return ret;
|
||||
}
|
|
@ -24,6 +24,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "actracer.h"
|
||||
#include "printf.h"
|
||||
|
||||
struct XiziSerialDriver {
|
||||
void (*sys_serial_init)();
|
||||
|
@ -33,8 +34,6 @@ struct XiziSerialDriver {
|
|||
void (*putc)(uint8_t);
|
||||
};
|
||||
|
||||
void KPrintf(char* fmt, ...);
|
||||
|
||||
struct XiziSerialDriver* hardkernel_uart_init(struct TraceTag* hardkernel_tag);
|
||||
|
||||
int serial_init(struct TraceTag* uart_driver_tag);
|
||||
|
|
|
@ -101,7 +101,7 @@ static bool dealloc_trace_meta(struct TraceMeta* meta)
|
|||
|
||||
static tracer_mem_chunk_idx_t trace_meta_map_mem_chunk(struct TraceMeta* const p_trace_meta, tracer_mem_chunk_idx_t mem_chunk_num)
|
||||
{
|
||||
tracer_mem_chunk_idx_t addr;
|
||||
tracer_mem_chunk_idx_t addr = 0;
|
||||
/* direct mapping */
|
||||
if (mem_chunk_num < TRACEMETA_NR_DIRECT) {
|
||||
if ((addr = p_trace_meta->addr[mem_chunk_num]) == 0) {
|
||||
|
@ -367,8 +367,9 @@ static void trace_locate_inner(struct TraceTag* target, struct TraceTag* const p
|
|||
// p_trace_meta: TRACER_OWNER, VT_FS or other.
|
||||
// TRACER_OWNER: path: "", name: "dir name"
|
||||
// other: path: "", name: "file name"
|
||||
if (!p_trace_meta) {
|
||||
if (p_trace_meta == NULL) {
|
||||
DEBUG("trace_locate, not found\n");
|
||||
return;
|
||||
}
|
||||
target->type = p_trace_meta->type;
|
||||
target->meta = p_trace_meta;
|
||||
|
|
|
@ -105,6 +105,9 @@ static struct tracer_mem_chunk* tracer_get_mem_chunk_cache(uint32_t chunk_id)
|
|||
struct tracer_mem_chunk* tracer_mem_chunk_read(uint32_t chunk_id)
|
||||
{
|
||||
struct tracer_mem_chunk* b = tracer_get_mem_chunk_cache(chunk_id);
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(b->flag & TRACER_MEM_CHUNK_VALID)) {
|
||||
tracer_mem_chunk_sync(b);
|
||||
b->flag |= TRACER_MEM_CHUNK_VALID;
|
||||
|
@ -137,6 +140,9 @@ static void tracer_mem_chunk_zero(uint32_t chunk_id)
|
|||
assert(chunk_id >= 0 && chunk_id < tracer_mem_chunk_syner.nr_mem_chunks);
|
||||
struct tracer_mem_chunk* tracer_mem_chunk = NULL;
|
||||
tracer_mem_chunk = tracer_mem_chunk_read(chunk_id);
|
||||
if (tracer_mem_chunk == NULL) {
|
||||
return;
|
||||
}
|
||||
memset(tracer_mem_chunk->data, 0, tracer_mem_chunk_syner.mem_chunk_size);
|
||||
tracer_mem_chunk_write(tracer_mem_chunk);
|
||||
tracer_mem_chunk_release(tracer_mem_chunk);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
toolchain ?= arm-none-eabi-
|
||||
user_ldflags = --specs=nosys.specs -Wl,-Map=user.map,-cref -N
|
||||
cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -no-pie
|
||||
cflags = -std=c11 -O2 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -no-pie
|
||||
endif
|
||||
ifeq ($(BOARD), zynq7000-zc702)
|
||||
toolchain ?= arm-xilinx-eabi-
|
||||
user_ldflags = -Wl,--start-group,-lgcc,-lc,--end-group -N
|
||||
cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
||||
cflags = -std=c11 -O2 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie
|
||||
board_specs = stub.o
|
||||
#cflags = -Wall -g -std=c11
|
||||
endif
|
||||
|
@ -19,11 +19,17 @@ c_useropts = -O0
|
|||
INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
all: init test_fs simple_client simple_server shell fs_server test_priority readme.txt | bin
|
||||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr test_irq_block test_irq_send readme.txt | bin
|
||||
else
|
||||
all: init test_fs simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin
|
||||
endif
|
||||
../tools/mkfs/mkfs ./fs.img $^
|
||||
@mv $(filter-out readme.txt, $^) bin
|
||||
@mv *.o bin
|
||||
|
@ -32,31 +38,45 @@ all: init test_fs simple_client simple_server shell fs_server test_priority read
|
|||
bin:
|
||||
@mkdir -p bin
|
||||
|
||||
shell: shell_port.o libserial.o shell_cmd_list.o shell.o shell_ext.o libfs_to_client.o libipc.o session.o usyscall.o libmem.o
|
||||
ifeq ($(BOARD), imx6q-sabrelite)
|
||||
test_irq_send: test_irq_sender.o usyscall.o arch_usyscall.o libserial.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
endif
|
||||
|
||||
test_irq_block: test_irq_block.o libserial.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_irq_hdlr: test_irq_handler.o libserial.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
shell: shell_port.o libserial.o shell_cmd_list.o shell.o shell_ext.o libfs_to_client.o libipc.o session.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
init: init.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o libmem.o
|
||||
init: init.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_fs: test_fs.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o libmem.o
|
||||
test_fs: test_fs.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o libfs_to_client.o usyscall.o libmem.o
|
||||
simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o libfs_to_client.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
simple_server: simple_server.o libserial.o libipc.o session.o simple_service.o usyscall.o libmem.o
|
||||
simple_server: simple_server.o libserial.o libipc.o session.o simple_service.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
fs_server: fs_server.o libfs_to_client.o fs.o libserial.o libipc.o session.o block_io.o usyscall.o libmem.o
|
||||
fs_server: fs_server.o libfs_to_client.o fs.o libserial.o libipc.o session.o block_io.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
test_priority: test_priority.o libserial.o usyscall.o libmem.o
|
||||
test_priority: test_priority.o libserial.o usyscall.o arch_usyscall.o libmem.o
|
||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||
@${objdump} -S $@ > $@.asm
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ signed short userShellRead(char* data, unsigned short len)
|
|||
while (length--) {
|
||||
cur_read = getc();
|
||||
if (cur_read == 0xff) {
|
||||
yield();
|
||||
yield(SYS_TASK_YIELD_NO_REASON);
|
||||
}
|
||||
// *data++ = getc();
|
||||
*data++ = cur_read;
|
||||
|
|
|
@ -84,7 +84,7 @@ int main(int argc, char** argv)
|
|||
if (argc >= 2) {
|
||||
id = string_to_integer(argv[1]);
|
||||
}
|
||||
printf("This is Simple Client %d, size is 0x%x\n", id, task_heap_base());
|
||||
// printf("This is Simple Client %d, size is 0x%x\n", id, task_heap_base());
|
||||
|
||||
struct Session session_wait;
|
||||
struct Session session_nowait;
|
||||
|
|
|
@ -9,10 +9,12 @@
|
|||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include "libipc.h"
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
/// this file is only used for debug
|
||||
#pragma once
|
||||
IPC_SERVICES(IpcSwIntrHandler, Ipc_intr_3, Ipc_wait_intr_3);
|
||||
|
||||
void printf(char* fmt, ...);
|
||||
|
||||
char getc();
|
||||
enum {
|
||||
SW_INTERRUPT_3 = 3,
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "test_irq.h"
|
||||
|
||||
IPC_INTERFACE(Ipc_wait_intr_3, 1, ignore, 0);
|
||||
int wait_intr(struct Session* session, void* ignore_param)
|
||||
{
|
||||
return IPC_CALL(Ipc_wait_intr_3)(session, NULL);
|
||||
}
|
||||
|
||||
static char prog_name[] = "TEST_IRQ_BLOCK";
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct Session session;
|
||||
if (connect_session(&session, "TestIRQ", 4096) < 0) {
|
||||
printf("connect session failed\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
printf("%s start waiting for IRQ.\n", prog_name);
|
||||
wait_intr(&session, NULL);
|
||||
printf("%s return from waiting for IRQ.\n", prog_name);
|
||||
|
||||
exit();
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "test_irq.h"
|
||||
|
||||
static bool has_one_interrupt = false;
|
||||
int IPC_DO_SERVE_FUNC(Ipc_intr_3)(void* ignore)
|
||||
{
|
||||
printf("TEST_SW_HDLR: In %s()\n", __func__);
|
||||
has_one_interrupt = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int IPC_DO_SERVE_FUNC(Ipc_wait_intr_3)(void* ignore)
|
||||
{
|
||||
// delay the this handle
|
||||
if (!has_one_interrupt) {
|
||||
delay_session();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// serve can be done by now
|
||||
has_one_interrupt = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
IPC_SERVER_INTERFACE(Ipc_intr_3, 1);
|
||||
IPC_SERVER_INTERFACE(Ipc_wait_intr_3, 1);
|
||||
IPC_SERVER_REGISTER_INTERFACES(IpcSwIntrHandler, 2, Ipc_intr_3, Ipc_wait_intr_3);
|
||||
int main()
|
||||
{
|
||||
if (register_irq(SW_INTERRUPT_3, Ipc_intr_3) < 0) {
|
||||
printf("TEST_SW_HDLR: bind failed");
|
||||
exit();
|
||||
}
|
||||
|
||||
static char prog_name[] = "TestIRQ";
|
||||
if (register_server("TestIRQ") < 0) {
|
||||
printf("register server name: %s failed.\n", prog_name);
|
||||
exit();
|
||||
}
|
||||
|
||||
ipc_server_loop(&IpcSwIntrHandler);
|
||||
|
||||
exit();
|
||||
}
|
|
@ -15,10 +15,12 @@ c_useropts = -O0
|
|||
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
board: libserial.o usyscall.o
|
||||
board: libserial.o arch_usyscall.o test_irq_sender.o
|
||||
@mv $^ ../../app
|
||||
|
||||
%.o: %.c
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "usyscall.h"
|
||||
|
||||
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
__asm__ volatile(
|
||||
"mov r0, %1;\
|
||||
mov r1, %2;\
|
||||
mov r2, %3;\
|
||||
mov r3, %4;\
|
||||
mov r4, %5;\
|
||||
swi 0;\
|
||||
dsb;\
|
||||
isb;\
|
||||
mov %0, r0"
|
||||
: "=r"(ret)
|
||||
: "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4)
|
||||
: "memory", "r0", "r1", "r2", "r3", "r4");
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "libserial.h"
|
||||
#include "usyscall.h"
|
||||
|
||||
enum {
|
||||
SW_INTERRUPT_3 = 3,
|
||||
};
|
||||
|
||||
enum {
|
||||
ARM_PERIPHERAL_BASE = 0x00A00000,
|
||||
MX6Q_GICD_BASE_OFFSET = 0x1000,
|
||||
MX6Q_GICC_BASE_OFFSET = 0x100,
|
||||
|
||||
ARM_PERIPHERAL_VIRT_BASE = 0x50000000,
|
||||
};
|
||||
|
||||
enum _gicd_sgi_filter {
|
||||
//! Forward the interrupt to the CPU interfaces specified in the @a target_list parameter.
|
||||
kGicSgiFilter_UseTargetList = 0,
|
||||
|
||||
//! Forward the interrupt to all CPU interfaces except that of the processor that requested
|
||||
//! the interrupt.
|
||||
kGicSgiFilter_AllOtherCPUs = 1,
|
||||
|
||||
//! Forward the interrupt only to the CPU interface of the processor that requested the
|
||||
//! interrupt.
|
||||
kGicSgiFilter_OnlyThisCPU = 2
|
||||
};
|
||||
|
||||
struct _gicd_registers {
|
||||
uint32_t CTLR; //!< Distributor Control Register.
|
||||
uint32_t TYPER; //!< Interrupt Controller Type Register.
|
||||
uint32_t IIDR; //!< Distributor Implementer Identification Register.
|
||||
uint32_t _reserved0[29];
|
||||
uint32_t IGROUPRn[8]; //!< Interrupt Group Registers.
|
||||
uint32_t _reserved1[24];
|
||||
uint32_t ISENABLERn[32]; //!< Interrupt Set-Enable Registers.
|
||||
uint32_t ICENABLERn[32]; //!< Interrupt Clear-Enable Registers.
|
||||
uint32_t ISPENDRn[32]; //!< Interrupt Set-Pending Registers.
|
||||
uint32_t ICPENDRn[32]; //!< Interrupt Clear-Pending Registers.
|
||||
uint32_t ICDABRn[32]; //!< Active Bit Registers.
|
||||
uint32_t _reserved2[32];
|
||||
uint8_t IPRIORITYRn[255 * sizeof(uint32_t)]; //!< Interrupt Priority Registers. (Byte accessible)
|
||||
uint32_t _reserved3;
|
||||
uint8_t ITARGETSRn[255 * sizeof(uint32_t)]; //!< Interrupt Processor Targets Registers. (Byte accessible)
|
||||
uint32_t _reserved4;
|
||||
uint32_t ICFGRn[64]; //!< Interrupt Configuration Registers.
|
||||
uint32_t _reserved5[128];
|
||||
uint32_t SGIR; //!< Software Generated Interrupt Register
|
||||
};
|
||||
typedef volatile struct _gicd_registers gicd_t;
|
||||
|
||||
enum _gicd_sgir_fields {
|
||||
kBP_GICD_SGIR_TargetListFilter = 24,
|
||||
kBM_GICD_SGIR_TargetListFilter = (0x3 << kBP_GICD_SGIR_TargetListFilter),
|
||||
|
||||
kBP_GICD_SGIR_CPUTargetList = 16,
|
||||
kBM_GICD_SGIR_CPUTargetList = (0xff << kBP_GICD_SGIR_CPUTargetList),
|
||||
|
||||
kBP_GICD_SGIR_NSATT = 15,
|
||||
kBM_GICD_SGIR_NSATT = (1 << kBP_GICD_SGIR_NSATT),
|
||||
|
||||
kBP_GICD_SGIR_SGIINTID = 0,
|
||||
kBM_GICD_SGIR_SGIINTID = 0xf
|
||||
};
|
||||
|
||||
void gic_send_sgi(uint32_t irqID, uint32_t target_list, uint32_t filter_list)
|
||||
{
|
||||
gicd_t* gicd = (gicd_t*)(ARM_PERIPHERAL_VIRT_BASE + MX6Q_GICD_BASE_OFFSET);
|
||||
gicd->SGIR = (filter_list << kBP_GICD_SGIR_TargetListFilter) //
|
||||
| (target_list << kBP_GICD_SGIR_CPUTargetList) //
|
||||
| (irqID & 0xf);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
static char prog_name[] = "TEST_IRQ_SEND";
|
||||
printf("%s: Mapping GIC\n", prog_name);
|
||||
mmap(ARM_PERIPHERAL_VIRT_BASE, ARM_PERIPHERAL_BASE, 0x2000, true);
|
||||
|
||||
// int send_time = 1000;
|
||||
int send_time = 1;
|
||||
printf("%s: Sending soft interrupt for %d times\n", prog_name, send_time);
|
||||
for (int i = 0; i < send_time; i++) {
|
||||
gic_send_sgi(SW_INTERRUPT_3, 0xF, kGicSgiFilter_UseTargetList);
|
||||
printf("%s: Soft interrupt send 1 time\n", prog_name);
|
||||
}
|
||||
printf("%s: Soft interrupt send done\n", prog_name);
|
||||
exit();
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "usyscall.h"
|
||||
#include "libmem.h"
|
||||
|
||||
static int
|
||||
syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
__asm__ volatile(
|
||||
"mov r0, %1;\
|
||||
mov r1, %2;\
|
||||
mov r2, %3;\
|
||||
mov r3, %4;\
|
||||
mov r4, %5;\
|
||||
swi 0;\
|
||||
dsb;\
|
||||
isb;\
|
||||
mov %0, r0"
|
||||
: "=r"(ret)
|
||||
: "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4)
|
||||
: "memory", "r0", "r1", "r2", "r3", "r4");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv)
|
||||
{
|
||||
int file_size = ipc_fsize(session, fd);
|
||||
void* img = malloc(file_size);
|
||||
int read_len = 0, cur_read_len = 0;
|
||||
while (read_len < file_size) {
|
||||
cur_read_len = file_size - read_len < 4096 ? file_size - read_len : 4096;
|
||||
read_len += ipc_read(session, fd, img + read_len, read_len, cur_read_len);
|
||||
}
|
||||
int ret = syscall(SYSCALL_SPAWN, (intptr_t)img, (intptr_t)name, (intptr_t)argv, 0);
|
||||
free(img);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int exit()
|
||||
{
|
||||
return syscall(SYSCALL_EXIT, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int yield()
|
||||
{
|
||||
return syscall(SYSCALL_YIELD, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int kill(int pid)
|
||||
{
|
||||
return syscall(SYSCALL_KILL, (intptr_t)pid, 0, 0, 0);
|
||||
}
|
||||
|
||||
int register_server(char* name)
|
||||
{
|
||||
return syscall(SYSCALL_SERVER, (intptr_t)name, 0, 0, 0);
|
||||
}
|
||||
|
||||
int session(char* path, int capacity, struct Session* user_session)
|
||||
{
|
||||
return syscall(SYSCALL_SESSION, (intptr_t)path, (intptr_t)capacity, (intptr_t)user_session, 0);
|
||||
}
|
||||
|
||||
int poll_session(struct Session* userland_session_arr, int arr_capacity)
|
||||
{
|
||||
return syscall(SYSCALL_POLL_SESSION, (intptr_t)userland_session_arr, (intptr_t)arr_capacity, 0, 0);
|
||||
}
|
||||
|
||||
int close_session(struct Session* session)
|
||||
{
|
||||
return syscall(SYSCALL_CLOSE_SESSION, (intptr_t)session, 0, 0, 0);
|
||||
}
|
||||
|
||||
int get_memblock_info(sys_state_info* info)
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_MEMBLOCK_INFO, (intptr_t)info, 0, 0);
|
||||
}
|
||||
|
||||
int set_priority(sys_state_info* info)
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SET_TASK_PRIORITY, (intptr_t)info, 0, 0);
|
||||
}
|
||||
|
||||
int task_heap_base()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_GET_HEAP_BASE, 0, 0, 0);
|
||||
}
|
||||
|
||||
int show_task()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_TASKS, 0, 0, 0);
|
||||
}
|
||||
|
||||
int show_mem()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_MEM_INFO, 0, 0, 0);
|
||||
}
|
||||
|
||||
int show_cpu()
|
||||
{
|
||||
return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_CPU_INFO, 0, 0, 0);
|
||||
}
|
||||
|
||||
int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev)
|
||||
{
|
||||
return syscall(SYSCALL_MMAP, vaddr, paddr, (intptr_t)len, (intptr_t)is_dev);
|
||||
}
|
||||
|
||||
int register_irq(int irq, int opcode)
|
||||
{
|
||||
return syscall(SYSCALL_REGISTER_IRQ, (intptr_t)irq, (intptr_t)opcode, 0, 0);
|
||||
}
|
|
@ -19,10 +19,12 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
|||
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
|
||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
board: libserial.o stub.o usyscall.o
|
||||
board: libserial.o stub.o arch_usyscall.o
|
||||
@mv $^ ../../app
|
||||
|
||||
%.o: %.c
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "usyscall.h"
|
||||
|
||||
int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
__asm__ volatile(
|
||||
"mov r0, %1;\
|
||||
mov r1, %2;\
|
||||
mov r2, %3;\
|
||||
mov r3, %4;\
|
||||
mov r4, %5;\
|
||||
swi 0;\
|
||||
dsb;\
|
||||
isb;\
|
||||
mov %0, r0"
|
||||
: "=r"(ret)
|
||||
: "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4)
|
||||
: "memory", "r0", "r1", "r2", "r3", "r4");
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libserial.h"
|
||||
#include "session.h"
|
||||
|
||||
// clang-format off
|
||||
#define SYSCALL_TEST 0
|
||||
#define SYSCALL_SPAWN 1 // generate a brand new task to run elf
|
||||
#define SYSCALL_EXIT 2 // exit task, delete the task cb
|
||||
#define SYSCALL_YIELD 3 // yield task, go to scheduler
|
||||
|
||||
#define SYSCALL_MMAP 4 // map a virt page to phy page
|
||||
#define SYSCALL_SERVER 5 // register current task as a server
|
||||
#define SYSCALL_SESSION 6 // create a session to a server
|
||||
#define SYSCALL_POLL_SESSION 7 // server poll for it's server sessions
|
||||
#define SYSCALL_CLOSE_SESSION 8 // client close it's client sessions
|
||||
|
||||
#define SYSCALL_EXEC 9 // run elf using current task
|
||||
#define SYSCALL_SYS_STATE 10 // run system state
|
||||
#define SYSCALL_REGISTER_IRQ 11 //
|
||||
|
||||
#define SYSCALL_KILL 12 // kill the task by id
|
||||
// clang-format on
|
||||
|
||||
typedef enum {
|
||||
SYS_STATE_TEST = 0,
|
||||
SYS_STATE_SET_TASK_PRIORITY,
|
||||
SYS_STATE_GET_HEAP_BASE,
|
||||
SYS_STATE_MEMBLOCK_INFO,
|
||||
SYS_STATE_SHOW_TASKS,
|
||||
SYS_STATE_SHOW_MEM_INFO,
|
||||
SYS_STATE_SHOW_CPU_INFO,
|
||||
} sys_state_option;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uintptr_t memblock_start;
|
||||
uintptr_t memblock_end;
|
||||
} memblock_info;
|
||||
int priority;
|
||||
} sys_state_info;
|
||||
|
||||
typedef int (*ipc_read_fn)(struct Session* session, int fd, char* dst, int offset, int len);
|
||||
typedef int (*ipc_fsize_fn)(struct Session* session, int fd);
|
||||
typedef int (*ipc_write_fn)(struct Session* session, int fd, char* src, int offset, int len);
|
||||
|
||||
int spawn(struct Session* session, int fd, ipc_read_fn ipc_read, ipc_fsize_fn ipc_fsize, char* name, char** argv);
|
||||
int exit();
|
||||
int yield();
|
||||
int kill(int pid);
|
||||
int register_server(char* name);
|
||||
int session(char* path, int capacity, struct Session* user_session);
|
||||
int poll_session(struct Session* userland_session_arr, int arr_capacity);
|
||||
int close_session(struct Session* session);
|
||||
int task_heap_base();
|
||||
int get_memblock_info(sys_state_info* info);
|
||||
int set_priority(sys_state_info* info);
|
||||
int show_task();
|
||||
int show_mem();
|
||||
int show_cpu();
|
||||
int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev);
|
||||
int register_irq(int irq, int opcode);
|
|
@ -19,6 +19,8 @@ INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
|||
-I$(KERNEL_ROOT)/services/fs/fs_server/include \
|
||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ struct Inode {
|
|||
};
|
||||
|
||||
// directory entry
|
||||
#define DIR_NAME_SIZE 14
|
||||
#define DIR_NAME_SIZE 30
|
||||
struct DirectEntry {
|
||||
uint16_t inum;
|
||||
char name[DIR_NAME_SIZE];
|
||||
|
|
|
@ -18,6 +18,8 @@ c_useropts = -O0
|
|||
INC_DIR = -I$(KERNEL_ROOT)/services/fs/libfs \
|
||||
-I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SRC_DIR := ipc memory
|
||||
SRC_DIR := ipc memory usyscall
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ c_useropts = -O0
|
|||
|
||||
INC_DIR = -I$(KERNEL_ROOT)/services/lib/ipc \
|
||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||
-I$(KERNEL_ROOT)/services/app
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ void ipc_msg_send_wait(struct IpcMsg* msg)
|
|||
msg->header.done = 0;
|
||||
while (msg->header.done == 0) {
|
||||
/// @todo syscall yield with prio decrease
|
||||
yield();
|
||||
yield(SYS_TASK_YIELD_BLOCK_IPC);
|
||||
}
|
||||
assert(msg->header.done == 1);
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ int ipc_session_wait(struct Session* session)
|
|||
struct IpcMsg* msg = IPCSESSION_MSG(session);
|
||||
while (msg->header.done == 0) {
|
||||
/// @todo syscall yield with prio decrease
|
||||
yield();
|
||||
yield(SYS_TASK_YIELD_BLOCK_IPC);
|
||||
}
|
||||
assert(msg->header.done == 1);
|
||||
return msg->header.ret_val;
|
||||
|
@ -156,9 +156,15 @@ void delay_session(void)
|
|||
session_delayed = true;
|
||||
}
|
||||
|
||||
bool is_cur_session_delayed(void)
|
||||
{
|
||||
return session_delayed;
|
||||
}
|
||||
|
||||
void ipc_server_loop(struct IpcNode* ipc_node)
|
||||
{
|
||||
struct Session session_list[NR_MAX_SESSION];
|
||||
memset(session_list, 0, sizeof(session_list));
|
||||
for (;;) {
|
||||
/* if connect sessions are greater than NR_MAX_SESSION,
|
||||
a full round will require multiple polls.
|
||||
|
@ -167,40 +173,49 @@ void ipc_server_loop(struct IpcNode* ipc_node)
|
|||
*/
|
||||
poll_session(session_list, NR_MAX_SESSION);
|
||||
/* handle each session */
|
||||
for (int i = 0; i < NR_MAX_SESSION; i++) {
|
||||
if (session_list[i].buf == NULL) {
|
||||
yield();
|
||||
break;
|
||||
}
|
||||
cur_sess_id = session_list[i].id;
|
||||
struct IpcMsg* msg = IPCSESSION_MSG(&session_list[i]);
|
||||
/* handle every message in current session
|
||||
a session could be delay in case one of its message(current message) needs to wait for an interrupt message's arrival
|
||||
interfaces[opcode] should explicitly call delay_session() and return to delay this session
|
||||
*/
|
||||
while (msg->header.magic == IPC_MSG_MAGIC && msg->header.valid == 1 && msg->header.done != 1) {
|
||||
// printf("session %d [%d, %d]\n", session_list[i].id, session_list[i].head, session_list[i].tail);
|
||||
if (session_used_size(&session_list[i]) == 0 && session_forward_tail(&session_list[i], msg->header.len) < 0) {
|
||||
bool has_delayed = true;
|
||||
for (int repeat = 0; repeat <= 1 && has_delayed; repeat++) {
|
||||
has_delayed = false;
|
||||
for (int i = 0; i < NR_MAX_SESSION; i++) {
|
||||
session_delayed = false;
|
||||
if (session_list[i].buf == NULL) {
|
||||
yield(SYS_TASK_YIELD_NO_REASON);
|
||||
break;
|
||||
}
|
||||
if (ipc_node->interfaces[msg->header.opcode]) {
|
||||
ipc_node->interfaces[msg->header.opcode](msg);
|
||||
// check if this session is delayed by op handler, all messages after the delayed message in current session is blocked.
|
||||
if (session_delayed) {
|
||||
session_delayed = false;
|
||||
cur_sess_id = session_list[i].id;
|
||||
struct IpcMsg* msg = IPCSESSION_MSG(&session_list[i]);
|
||||
/* handle every message in current session
|
||||
a session could be delay in case one of its message(current message) needs to wait for an interrupt message's arrival
|
||||
interfaces[opcode] should explicitly call delay_session() and return to delay this session
|
||||
*/
|
||||
while (msg->header.magic == IPC_MSG_MAGIC && msg->header.valid == 1 && msg->header.done == 0) {
|
||||
// printf("session %d [%d, %d]\n", session_list[i].id, session_list[i].head, session_list[i].tail);
|
||||
if (session_used_size(&session_list[i]) == 0 && session_forward_tail(&session_list[i], msg->header.len) < 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("Unsupport opcode(%d) for server: %s\n", msg->header.opcode, ipc_node->name);
|
||||
|
||||
// this is a message needs to handle
|
||||
if (ipc_node->interfaces[msg->header.opcode]) {
|
||||
ipc_node->interfaces[msg->header.opcode](msg);
|
||||
// check if this session is delayed by op handler, all messages after the delayed message in current session is blocked.
|
||||
if (is_cur_session_delayed()) {
|
||||
msg->header.delayed = 1;
|
||||
has_delayed = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
printf("Unsupport opcode(%d) for server: %s\n", msg->header.opcode, ipc_node->name);
|
||||
}
|
||||
// current msg is a message that needs to ignore
|
||||
// finish this message in server's perspective
|
||||
if (session_forward_head(&session_list[i], msg->header.len) < 0) {
|
||||
break;
|
||||
}
|
||||
msg = IPCSESSION_MSG(&session_list[i]);
|
||||
}
|
||||
// finish this message in server's perspective
|
||||
while (session_forward_head(&session_list[i], msg->header.len) < 0) {
|
||||
yield();
|
||||
}
|
||||
msg = IPCSESSION_MSG(&session_list[i]);
|
||||
// stop handle this session
|
||||
cur_sess_id = -1;
|
||||
}
|
||||
// stop handle this session
|
||||
cur_sess_id = -1;
|
||||
}
|
||||
}
|
||||
}
|