Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
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.
+41
View File
@@ -0,0 +1,41 @@
This README file contains information on the contents of the meta-bhs layer.
Please see the corresponding sections below for details.
Dependencies
============
URI: <first dependency>
branch: <branch name>
URI: <second dependency>
branch: <branch name>
.
.
.
Patches
=======
Please submit any patches against the meta-bhs layer to the xxxx mailing list (xxxx@zzzz.org)
and cc: the maintainer:
Maintainer: XXX YYYYYY <xxx.yyyyyy@zzzzz.com>
Table of Contents
=================
I. Adding the meta-bhs layer to your build
II. Misc
I. Adding the meta-bhs layer to your build
=================================================
Run 'bitbake-layers add-layer meta-bhs'
II. Misc
========
--- replace with specific information about the meta-bhs layer ---
+13
View File
@@ -0,0 +1,13 @@
# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"
# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
${LAYERDIR}/recipes-*/*/*.bbappend"
BBFILE_COLLECTIONS += "meta-bhs"
BBFILE_PATTERN_meta-bhs = "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-bhs = "14"
LAYERDEPENDS_meta-bhs = "core"
LAYERSERIES_COMPAT_meta-bhs = "mickledore"
+39
View File
@@ -0,0 +1,39 @@
KERNEL_DEVICETREE = "aspeed-ast2600-evb.dtb"
UBOOT_MACHINE = "ast2600_openbmc_spl_defconfig"
UBOOT_DEVICETREE = "ast2600-evb"
SPL_BINARY = "spl/u-boot-spl.bin"
SOCSEC_SIGN_ENABLE = "0"
require conf/machine/include/bmc-common.inc
require conf/machine/include/ast2600.inc
require conf/machine/include/obmc-evb-common.inc
SERIAL_CONSOLES = "115200;ttyS4"
FLASH_SIZE = "65536"
MACHINE_FEATURES += "\
obmc-bmc-state-mgmt \
obmc-chassis-state-mgmt \
obmc-host-state-mgmt \
obmc-phosphor-chassis-mgmt \
obmc-host-ipmi \
obmc-phosphor-fan-mgmt \
obmc-phosphor-flash-mgmt \
"
VIRTUAL-RUNTIME_obmc-host-state-manager ?= "x86-power-control"
VIRTUAL-RUNTIME_obmc-chassis-state-manager ?= "x86-power-control"
VIRTUAL-RUNTIME_obmc-sensors-hwmon ?= "dbus-sensors"
VIRTUAL-RUNTIME_obmc-inventory-manager = "entity-manager"
PREFERRED_PROVIDER_virtual/obmc-inventory-data = "entity-manager"
PREFERRED_PROVIDER_virtual/obmc-chassis-mgmt = "packagegroup-luxshare-apps"
#PREFERRED_PROVIDER_virtual/obmc-fan-mgmt = "packagegroup-luxshare-apps"
PREFERRED_PROVIDER_virtual/obmc-flash-mgmt = "packagegroup-luxshare-apps"
PREFERRED_PROVIDER_virtual/obmc-host-ipmi-hw ?= "phosphor-ipmi-kcs"
PREFERRED_PROVIDER_virtual/obmc-system-mgmt = "packagegroup-luxshare-apps"
PREFERRED_PROVIDER_virtual/phosphor-led-manager-config-native = "led-manager-config-native"
default_user_commands = "\
useradd -p '\$1\$UGMqyqdg\$iuxCzWsMmQru3a31HxoEb/' -u 1000 -M -d /tmp -G priv-admin,web,redfish,ipmi ADMIN; \
"
EXTRA_USERS_PARAMS:append:pn-obmc-phosphor-image = "${default_user_commands}"
@@ -0,0 +1,20 @@
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "8"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \
##OEROOT##/meta \
##OEROOT##/meta-poky \
##OEROOT##/meta-openembedded/meta-oe \
##OEROOT##/meta-openembedded/meta-networking \
##OEROOT##/meta-openembedded/meta-python \
##OEROOT##/meta-phosphor \
##OEROOT##/meta-aspeed \
##OEROOT##/meta-evb/meta-evb-aspeed/meta-evb-ast2600 \
##OEROOT##/meta-luxshare/ \
##OEROOT##/meta-luxshare/meta-common \
##OEROOT##/meta-luxshare/meta-bhs \
"
@@ -0,0 +1,5 @@
Common targets are:
obmc-phosphor-image: Includes OpenBMC Phosphor userspace and Web UI
Note that the core targets will not set the default phosphor password.
@@ -0,0 +1,21 @@
MACHINE ??= "bhs-ast2600"
DISTRO ?= "openbmc-phosphor"
PACKAGE_CLASSES ?= "package_ipk"
SANITY_TESTED_DISTROS:append ?= " *"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
#BB_NO_NETWORK = "1"
USER_CLASSES ?= "buildstats"
PATCHRESOLVE = "noop"
BB_DISKMON_DIRS ??= "\
STOPTASKS,${TMPDIR},1G,100K \
STOPTASKS,${DL_DIR},1G,100K \
STOPTASKS,${SSTATE_DIR},1G,100K \
STOPTASKS,/tmp,100M,100K \
HALT,${TMPDIR},100M,1K \
HALT,${DL_DIR},100M,1K \
HALT,${SSTATE_DIR},100M,1K \
HALT,/tmp,10M,1K"
CONF_VERSION = "2"
#SSTATE_DIR=""
#DL_DIR=""
require conf/machine/include/obmc-bsp-common.inc
@@ -0,0 +1,282 @@
/dts-v1/;
#include "ast2600-u-boot.dtsi"
/ {
model = "AST2600 EVB";
compatible = "aspeed,ast2600-evb", "aspeed,ast2600";
memory {
device_type = "memory";
reg = <0x80000000 0x40000000>;
};
chosen {
stdout-path = &uart5;
};
aliases {
mmc0 = &emmc_slot0;
mmc1 = &sdhci_slot0;
mmc2 = &sdhci_slot1;
spi0 = &fmc;
spi1 = &spi1;
spi2 = &spi2;
ethernet0 = &mac0;
ethernet1 = &mac1;
ethernet2 = &mac2;
ethernet3 = &mac3;
};
cpus {
cpu@0 {
clock-frequency = <800000000>;
};
cpu@1 {
clock-frequency = <800000000>;
};
};
};
&uart5 {
u-boot,dm-pre-reloc;
status = "okay";
};
&sdrammc {
clock-frequency = <400000000>;
};
&wdt1 {
status = "okay";
};
&wdt2 {
status = "okay";
};
&wdt3 {
status = "okay";
};
&mdio {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = < &pinctrl_mdio1_default &pinctrl_mdio2_default
&pinctrl_mdio3_default &pinctrl_mdio4_default>;
#address-cells = <1>;
#size-cells = <0>;
ethphy0: ethernet-phy@0 {
reg = <0>;
};
ethphy1: ethernet-phy@1 {
reg = <0>;
};
ethphy2: ethernet-phy@2 {
reg = <0>;
};
ethphy3: ethernet-phy@3 {
reg = <0>;
};
};
&mac0 {
status = "okay";
phy-mode = "rgmii-rxid";
phy-handle = <&ethphy0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_rgmii1_default>;
};
&fmc {
status = "okay";
flash@0 {
compatible = "spi-flash", "sst,w25q256";
status = "okay";
spi-max-frequency = <25000000>;
spi-tx-bus-width = <2>;
spi-rx-bus-width = <2>;
};
flash@1 {
compatible = "spi-flash", "sst,w25q256";
status = "okay";
spi-max-frequency = <25000000>;
spi-tx-bus-width = <2>;
spi-rx-bus-width = <2>;
};
};
&spi1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_spi1_default &pinctrl_spi1abr_default
&pinctrl_spi1cs1_default &pinctrl_spi1wp_default
&pinctrl_spi1wp_default &pinctrl_spi1quad_default>;
flash@0 {
status = "okay";
spi-max-frequency = <50000000>;
spi-tx-bus-width = <4>;
spi-rx-bus-width = <4>;
};
flash@1 {
status = "disabled";
spi-max-frequency = <50000000>;
spi-tx-bus-width = <4>;
spi-rx-bus-width = <4>;
};
};
&emmc {
u-boot,dm-pre-reloc;
timing-phase = <0x000f0097>;
};
&emmc_slot0 {
u-boot,dm-pre-reloc;
status = "disabled";
bus-width = <4>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_emmc_default>;
sdhci-drive-type = <1>;
};
&sdhci {
timing-phase = <0x00c6375f>;
};
&sdhci_slot0 {
status = "disabled";
bus-width = <4>;
pwr-gpios = <&gpio0 ASPEED_GPIO(V, 0) GPIO_ACTIVE_HIGH>;
pwr-sw-gpios = <&gpio0 ASPEED_GPIO(V, 1) GPIO_ACTIVE_HIGH>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sd1_default>;
sdhci-drive-type = <1>;
};
&sdhci_slot1 {
status = "disabled";
bus-width = <4>;
pwr-gpios = <&gpio0 ASPEED_GPIO(V, 2) GPIO_ACTIVE_HIGH>;
pwr-sw-gpios = <&gpio0 ASPEED_GPIO(V, 3) GPIO_ACTIVE_HIGH>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_sd2_default>;
sdhci-drive-type = <1>;
};
&i2c4 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c5_default>;
};
&i2c5 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c6_default>;
};
&i2c6 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c7_default>;
};
&i2c7 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c8_default>;
};
&i2c8 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c9_default>;
};
&i2c14 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c15_default>;
at24c32@53 {
compatible = "atmel,24c32";
reg = <0x53>;
ethaddr-in-eeprom;
eth0-offset = <0x500>;
};
};
&pcie_phy1 {
status = "okay";
};
&pcie_bridge {
status = "okay";
};
#if 0
&fsim0 {
status = "okay";
};
&fsim1 {
status = "okay";
};
#endif
#if 0
&vhub {
status = "okay";
};
#endif
&ehci1 {
status = "okay";
};
&display_port {
status = "okay";
};
#if 0
&scu {
mac0-clk-delay = <0x10 0x0a
0x10 0x10
0x10 0x10>;
mac1-clk-delay = <0x10 0x0a
0x10 0x10
0x10 0x10>;
mac2-clk-delay = <0x08 0x04
0x08 0x04
0x08 0x04>;
mac3-clk-delay = <0x08 0x04
0x08 0x04
0x08 0x04>;
};
#endif
&hace {
u-boot,dm-pre-reloc;
status = "okay";
};
&acry {
u-boot,dm-pre-reloc;
status = "okay";
};
+2
View File
@@ -0,0 +1,2 @@
CONFIG_MAC_ADDR_IN_EEPROM=y
CONFIG_EEPROM_AT24=y
@@ -0,0 +1,16 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += " \
file://ast2600-evb.dts \
file://bhs.cfg \
"
do_configure:append() {
dts="../ast2600-evb.dts"
if [ ! -f $dts]; then
echo $dts" does not exist"
else
cp ../ast2600-evb.dts ./source/arch/arm/dts/
fi
}
@@ -0,0 +1,7 @@
[Match]
Name=eth0
[Network]
DHCP=no
LinkLocalAddressing=no
Address=192.168.255.254/24
Gateway=192.168.255.1
@@ -0,0 +1,10 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://00-bmc-eth0.network"
do_install:append() {
install -d ${D}${sysconfdir}/systemd/network
install -m 0644 ${WORKDIR}/00-bmc-eth0.network ${D}${sysconfdir}/systemd/network
}
FILES:${PN} += " ${sysconfdir}/systemd/network/00-bmc-eth0.network "
@@ -0,0 +1,155 @@
From 1d2fac5f2cd1f44a5e93151fe2e6e6ddb43bf126 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 27 Nov 2024 12:25:57 +0800
Subject: [PATCH] Add WA to enable i3c1 as i3c1 PVNN_MAIN_CPU1 voltage not
available when bmc kernel bootup
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
drivers/i3c/master.c | 11 +++--
drivers/i3c/master/dw-i3c-master.c | 79 ++++++++++++++++++++++++++++--
2 files changed, 83 insertions(+), 7 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 534db4f05deb..3f210541cb49 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2072,9 +2072,12 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
* Reset all dynamic address that may have been assigned before
* (assigned by the bootloader for example).
*/
- ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
- if (ret && ret != I3C_ERROR_M2)
- goto err_bus_cleanup;
+ if (!master->jdec_spd) {
+ ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
+ if (ret && ret != I3C_ERROR_M2)
+ goto err_bus_cleanup;
+ }
+
/*
* Reserve init_dyn_addr first, and then try to pre-assign dynamic
@@ -2121,7 +2124,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
* Since SPD devices are all with static address. Don't do DAA if we
* know it is a pure I2C bus.
*/
- if (master->jdec_spd && n_i3cdev == 0)
+ if (master->jdec_spd)
return 0;
ret = i3c_master_do_daa(master);
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 6d1ba40eca0f..1ad8a0bba7dc 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -374,8 +374,16 @@
#define AST2600_I3C_IBI_MAX_PAYLOAD 255
-#define SEL_CPU0_I3C_DDR_GPIO 921
-#define SEL_CPU1_I3C_DDR_GPIO 922
+#define SEL_CPU0_I3C_DDR_GPIO 921
+#define SEL_CPU1_I3C_DDR_GPIO 922
+#define I3C_SPD_BMC_MUX0_SEL 1004
+#define I3C_SPD_BMC_MUX0_EN 852
+#define I3C_SPD_BMC_MUX1_SEL 1005
+#define I3C_SPD_BMC_MUX1_EN 853
+#define I3C_SPD_BMC_MUX2_SEL 1006
+#define I3C_SPD_BMC_MUX2_EN 854
+#define I3C_SPD_BMC_MUX3_SEL 1007
+#define I3C_SPD_BMC_MUX3_EN 909
struct dw_i3c_master_caps {
u8 cmdfifodepth;
@@ -3141,6 +3149,69 @@ static void i3c_gpio_switch_bios(struct dw_i3c_master *master)
gpio_free(SEL_CPU1_I3C_DDR_GPIO);
}
+static void i3c_gpio_switch_dimm(struct dw_i3c_master *master)
+{
+ if (gpio_request(I3C_SPD_BMC_MUX0_SEL, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX0_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX0_EN, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX0_EN\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX1_SEL, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX1_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX1_EN, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX1_EN\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX2_SEL, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX2_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX2_EN, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX2_EN\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX3_SEL, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX3_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX3_EN, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate I3C_SPD_BMC_MUX3_EN\n");
+ return;
+ }
+
+ gpio_direction_output(I3C_SPD_BMC_MUX0_SEL, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX0_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_SEL, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_EN, 1);
+
+ usleep_range(500, 1000);
+
+ gpio_free(I3C_SPD_BMC_MUX0_SEL);
+ gpio_free(I3C_SPD_BMC_MUX0_EN);
+ gpio_free(I3C_SPD_BMC_MUX1_SEL);
+ gpio_free(I3C_SPD_BMC_MUX1_EN);
+ gpio_free(I3C_SPD_BMC_MUX2_SEL);
+ gpio_free(I3C_SPD_BMC_MUX2_EN);
+ gpio_free(I3C_SPD_BMC_MUX3_SEL);
+ gpio_free(I3C_SPD_BMC_MUX3_EN);
+}
+
static int dw_i3c_probe(struct platform_device *pdev)
{
const struct of_device_id *match;
@@ -3155,6 +3226,9 @@ static int dw_i3c_probe(struct platform_device *pdev)
master->dev = &pdev->dev;
master->base.bus_driver_context = master;
+ i3c_gpio_switch_bmc(master);
+ i3c_gpio_switch_dimm(master);
+
master->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(master->regs))
return PTR_ERR(master->regs);
@@ -3180,7 +3254,6 @@ static int dw_i3c_probe(struct platform_device *pdev)
spin_lock_init(&master->ibi.master.lock);
platform_set_drvdata(pdev, master);
- i3c_gpio_switch_bmc(master);
/* Information regarding the FIFOs/QUEUEs depth */
ret = readl(master->regs + QUEUE_STATUS_LEVEL);
--
2.34.1
@@ -0,0 +1,399 @@
From 136ea6342d8de89ab6166dfce0ba20f67aabc0d3 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Thu, 9 Oct 2025 10:49:32 +0800
Subject: [PATCH] Add sw workaround to let all dimm spd devices to receive ccc
message
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
drivers/i3c/master.c | 251 ++++++++++++++++++++++++++++++-------
include/linux/i3c/master.h | 11 ++
2 files changed, 214 insertions(+), 48 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 534db4f05deb..9cd566d3928f 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -16,12 +16,117 @@
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
#include "internals.h"
static DEFINE_IDR(i3c_bus_idr);
static DEFINE_MUTEX(i3c_core_lock);
+static void i3c_gpio_switch_init(struct i3c_master_controller *master)
+{
+ if (gpio_request(I3C_SPD_BMC_MUX0_SEL, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX0_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX0_EN, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX0_EN\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX1_SEL, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX1_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX1_EN, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX1_EN\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX2_SEL, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX2_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX2_EN, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX2_EN\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX3_SEL, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX3_SEL\n");
+ return;
+ }
+
+ if (gpio_request(I3C_SPD_BMC_MUX3_EN, "dw-i3c-master")) {
+ dev_err(&master->dev, "unable to allocate I3C_SPD_BMC_MUX3_EN\n");
+ return;
+ }
+}
+
+static void i3c_gpio_switch_free(void)
+{
+ gpio_free(I3C_SPD_BMC_MUX0_SEL);
+ gpio_free(I3C_SPD_BMC_MUX0_EN);
+ gpio_free(I3C_SPD_BMC_MUX1_SEL);
+ gpio_free(I3C_SPD_BMC_MUX1_EN);
+ gpio_free(I3C_SPD_BMC_MUX2_SEL);
+ gpio_free(I3C_SPD_BMC_MUX2_EN);
+ gpio_free(I3C_SPD_BMC_MUX3_SEL);
+ gpio_free(I3C_SPD_BMC_MUX3_EN);
+}
+
+static void i3c_gpio_switch_dimm_group(int gNum)
+{
+ if(gNum == 0)
+ {
+ gpio_direction_output(I3C_SPD_BMC_MUX0_SEL, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX0_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_SEL, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_EN, 1);
+ }
+ if(gNum == 1)
+ {
+ gpio_direction_output(I3C_SPD_BMC_MUX0_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX0_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_EN, 1);
+ }
+ if(gNum == 2)
+ {
+ gpio_direction_output(I3C_SPD_BMC_MUX0_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX0_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_SEL, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_SEL, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_EN, 0);
+ }
+ if(gNum == 3)
+ {
+ gpio_direction_output(I3C_SPD_BMC_MUX0_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX0_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX1_EN, 0);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX2_EN, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_SEL, 1);
+ gpio_direction_output(I3C_SPD_BMC_MUX3_EN, 0);
+ }
+}
+
/**
* i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
* @bus: I3C bus to take the lock on
@@ -593,39 +698,51 @@ static ssize_t rescan_store(struct device *dev, struct device_attribute *attr,
if (!res)
return count;
+ i3c_gpio_switch_init(master);
+
i3c_device_publish_event(master, i3c_event_prepare_for_rescan);
- i3c_bus_maintenance_lock(bus);
+ for(int i=0; i<4; i++) {
+ i3c_gpio_switch_dimm_group(i);
+ usleep_range(2000, 2100);
- ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
- I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
- I3C_CCC_EVENT_HJ);
- if (ret && ret != I3C_ERROR_M2) {
- dev_dbg(&master->dev,
- "Failed to run broadcast DISEC for rescan, ret=%d\n", ret);
- i3c_bus_maintenance_unlock(bus);
- return ret;
- }
+ i3c_bus_maintenance_lock(bus);
+
+ ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
+ I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
+ I3C_CCC_EVENT_HJ);
+ if (ret && ret != I3C_ERROR_M2) {
+ dev_dbg(&master->dev,
+ "Failed to run broadcast DISEC for rescan, ret=%d\n", ret);
+ i3c_bus_maintenance_unlock(bus);
+ i3c_gpio_switch_free();
+ return ret;
+ }
+
+ ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
+ if (ret && ret != I3C_ERROR_M2) {
+ dev_dbg(&master->dev,
+ "Failed to run RSTDAA for rescan, ret=%d\n", ret);
+ i3c_bus_maintenance_unlock(bus);
+ i3c_gpio_switch_free();
+ return ret;
+ }
- ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
- if (ret && ret != I3C_ERROR_M2) {
- dev_dbg(&master->dev,
- "Failed to run RSTDAA for rescan, ret=%d\n", ret);
i3c_bus_maintenance_unlock(bus);
- return ret;
+ usleep_range(2000, 2100);
}
- i3c_bus_maintenance_unlock(bus);
-
ret = i3c_master_do_daa(master);
if (ret) {
dev_dbg(&master->dev, "Failed to run DAA for rescan, ret=%d\n",
ret);
+ i3c_gpio_switch_free();
return ret;
}
i3c_device_publish_event(master, i3c_event_rescan_done);
+ i3c_gpio_switch_free();
return count;
}
static DEVICE_ATTR_WO(rescan);
@@ -1863,11 +1980,17 @@ int i3c_master_do_daa(struct i3c_master_controller *master)
{
int ret = 0;
+ i3c_gpio_switch_init(master);
mutex_lock(&master->daa_lock);
i3c_bus_maintenance_lock(&master->bus);
if (master->jdec_spd) {
- ret = i3c_master_sethid_locked(master);
- ret = i3c_master_setaasa_locked(master);
+ for(int i=0; i<4; i++) {
+ i3c_gpio_switch_dimm_group(i);
+ usleep_range(2000, 2100);
+ ret = i3c_master_sethid_locked(master);
+ ret = i3c_master_setaasa_locked(master);
+ usleep_range(2000, 2100);
+ }
} else {
ret = master->ops->do_daa(master);
}
@@ -1880,6 +2003,7 @@ int i3c_master_do_daa(struct i3c_master_controller *master)
mutex_unlock:
mutex_unlock(&master->daa_lock);
+ i3c_gpio_switch_free();
return ret;
}
EXPORT_SYMBOL_GPL(i3c_master_do_daa);
@@ -2011,6 +2135,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
struct i2c_dev_desc *i2cdev;
int ret, n_i3cdev = 0;
+ i3c_gpio_switch_init(master);
/*
* First attach all devices with static definitions provided by the
* FW.
@@ -2061,21 +2186,31 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
goto err_bus_cleanup;
}
- /* Disable all slave events before starting DAA. */
- ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
- I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
- I3C_CCC_EVENT_HJ);
- if (ret && ret != I3C_ERROR_M2)
- goto err_bus_cleanup;
+ for(int i=0; i<4; i++) {
+ i3c_gpio_switch_dimm_group(i);
+ usleep_range(2000, 2100);
+ /* Disable all slave events before starting DAA. */
+ ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
+ I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
+ I3C_CCC_EVENT_HJ);
+ if (ret && ret != I3C_ERROR_M2)
+ goto err_bus_cleanup;
+ usleep_range(2000, 2100);
+ }
- /*
- * Reset all dynamic address that may have been assigned before
- * (assigned by the bootloader for example).
- */
- ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
- if (ret && ret != I3C_ERROR_M2)
- goto err_bus_cleanup;
+ for(int i=0; i<4; i++) {
+ i3c_gpio_switch_dimm_group(i);
+ usleep_range(2000, 2100);
+ /*
+ * Reset all dynamic address that may have been assigned before
+ * (assigned by the bootloader for example).
+ */
+ ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
+ if (ret && ret != I3C_ERROR_M2)
+ goto err_bus_cleanup;
+ usleep_range(2000, 2100);
+ }
/*
* Reserve init_dyn_addr first, and then try to pre-assign dynamic
* address and retrieve device information if needed.
@@ -2117,12 +2252,16 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
n_i3cdev++;
}
+ i3c_gpio_switch_free();
+
/*
* Since SPD devices are all with static address. Don't do DAA if we
* know it is a pure I2C bus.
*/
if (master->jdec_spd && n_i3cdev == 0)
+ {
return 0;
+ }
ret = i3c_master_do_daa(master);
if (ret)
@@ -2131,7 +2270,12 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
return 0;
err_rstdaa:
- i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
+ for(int i=0; i<4; i++) {
+ i3c_gpio_switch_dimm_group(i);
+ usleep_range(2000, 2100);
+ i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
+ usleep_range(2000, 2100);
+ }
err_bus_cleanup:
if (master->ops->bus_cleanup)
@@ -2140,6 +2284,7 @@ static int i3c_master_bus_init(struct i3c_master_controller *master)
err_detach_devs:
i3c_master_detach_free_devs(master);
+ i3c_gpio_switch_free();
return ret;
}
@@ -2147,27 +2292,37 @@ static void i3c_master_bus_cleanup(struct i3c_master_controller *master)
{
int ret;
- i3c_bus_maintenance_lock(&master->bus);
- /* Disable all slave events before starting DAA. */
- ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
- I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
- I3C_CCC_EVENT_HJ);
- if (ret && ret != I3C_ERROR_M2)
- dev_dbg(&master->dev, "failed to send DISEC, ret=%i\n", ret);
+ i3c_gpio_switch_init(master);
- /*
- * Reset all dynamic address that may have been assigned before
- * (assigned by the bootloader for example).
- */
- ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
- if (ret && ret != I3C_ERROR_M2)
- dev_dbg(&master->dev, "failed to send RSTDAA, ret=%i\n", ret);
- i3c_bus_maintenance_unlock(&master->bus);
+ for(int i=0; i<4; i++) {
+ i3c_gpio_switch_dimm_group(i);
+ usleep_range(2000, 2100);
+ i3c_bus_maintenance_lock(&master->bus);
+ /* Disable all slave events before starting DAA. */
+ ret = i3c_master_disec_locked(master, I3C_BROADCAST_ADDR,
+ I3C_CCC_EVENT_SIR | I3C_CCC_EVENT_MR |
+ I3C_CCC_EVENT_HJ);
+ if (ret && ret != I3C_ERROR_M2)
+ dev_dbg(&master->dev, "failed to send DISEC, ret=%i\n", ret);
+
+ /*
+ * Reset all dynamic address that may have been assigned before
+ * (assigned by the bootloader for example).
+ */
+ ret = i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR);
+ if (ret && ret != I3C_ERROR_M2)
+ dev_dbg(&master->dev, "failed to send RSTDAA, ret=%i\n", ret);
+
+ i3c_bus_maintenance_unlock(&master->bus);
+ usleep_range(2000, 2100);
+ }
if (master->ops->bus_cleanup)
master->ops->bus_cleanup(master);
i3c_master_detach_free_devs(master);
+
+ i3c_gpio_switch_free();
}
static void i3c_master_attach_boardinfo(struct i3c_dev_desc *i3cdev)
diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h
index 22bcf638e5b1..6bf882d21a1e 100644
--- a/include/linux/i3c/master.h
+++ b/include/linux/i3c/master.h
@@ -690,4 +690,15 @@ void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot);
struct i3c_ibi_slot *i3c_master_get_free_ibi_slot(struct i3c_dev_desc *dev);
+#define SEL_CPU0_I3C_DDR_GPIO 921
+#define SEL_CPU1_I3C_DDR_GPIO 922
+#define I3C_SPD_BMC_MUX0_SEL 1004
+#define I3C_SPD_BMC_MUX0_EN 852
+#define I3C_SPD_BMC_MUX1_SEL 1005
+#define I3C_SPD_BMC_MUX1_EN 853
+#define I3C_SPD_BMC_MUX2_SEL 1006
+#define I3C_SPD_BMC_MUX2_EN 854
+#define I3C_SPD_BMC_MUX3_SEL 1007
+#define I3C_SPD_BMC_MUX3_EN 909
+
#endif /* I3C_MASTER_H */
--
2.34.1
@@ -0,0 +1,64 @@
From 44944d5fe90cd5a71b60d8393324c6a90779e635 Mon Sep 17 00:00:00 2001
From: "Chen.Zhao" <zhao.chen@luxshare-ict.com>
Date: Thu, 19 Sep 2024 17:08:07 +0800
Subject: [PATCH] Force set pmbus page to 4 to fix Delta PSU reading error
issue Because Delta PSU page command has bug. It not report error when set
page above 3. It will make pmbus logic confusion. So forece set max page to
3.
---
drivers/hwmon/pmbus/pmbus.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/hwmon/pmbus/pmbus.c b/drivers/hwmon/pmbus/pmbus.c
index 9fa5e237a03f..2ac33333e7d2 100644
--- a/drivers/hwmon/pmbus/pmbus.c
+++ b/drivers/hwmon/pmbus/pmbus.c
@@ -78,6 +78,11 @@ static void pmbus_find_sensor_groups(struct i2c_client *client,
PMBUS_STATUS_TEMPERATURE))
info->func[0] |= PMBUS_HAVE_STATUS_TEMP;
+ /*
+ * because delta psu page commad has bug, it will make pmbus mask confusion
+ * force set pmbus mask to enable read current, voltage, fan, temperature and power
+ */
+ info->func[0] = 0x3f27d;
rv = pmbus_query_register(client, PMBUS_READ_EIN);
/* only direct format for EIN and EOUT supported */
if (rv > 0 && (rv & PB_QUERY_COMMAND_SUPPORTED) &&
@@ -97,6 +102,11 @@ static void pmbus_find_sensor_groups(struct i2c_client *client,
info->m[PSC_POWER_AVERAGE] = 1;
}
+ /*
+ * because delta psu page commad has bug, it will make pmbus mask confusion.
+ * remove read other page information.
+ */
+ #if 0
/* Sensors detected on all pages */
for (page = 0; page < info->pages; page++) {
if (pmbus_check_word_register(client, page, PMBUS_READ_VOUT)) {
@@ -114,6 +124,7 @@ static void pmbus_find_sensor_groups(struct i2c_client *client,
if (pmbus_check_word_register(client, page, PMBUS_READ_POUT))
info->func[page] |= PMBUS_HAVE_POUT;
}
+ #endif
}
/*
@@ -135,7 +146,11 @@ static int pmbus_identify(struct i2c_client *client,
int page;
for (page = 1; page < PMBUS_PAGES; page++) {
- if (pmbus_set_page(client, page, 0xff) < 0)
+ /*
+ * because delta psu page commad has bug, it will make pmbus mask confusion
+ * force set max page to 4.
+ */
+ if ((pmbus_set_page(client, page, 0xff) < 0) || (page > 3))
break;
}
pmbus_set_page(client, 0, 0xff);
--
2.25.1
@@ -0,0 +1,70 @@
From 459fdb4b3f4d905072f1dfa25e90deee1347779b Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 22 Oct 2025 10:48:26 +0800
Subject: [PATCH] Solve the do_daa exception exit issue when the DIMM slots are
not fully populated.
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
drivers/i3c/master.c | 8 ++++++++
drivers/i3c/master/dw-i3c-master.c | 4 ++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 9cd566d3928f..6997a92ac8e7 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1979,6 +1979,7 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
int i3c_master_do_daa(struct i3c_master_controller *master)
{
int ret = 0;
+ bool result = false;
i3c_gpio_switch_init(master);
mutex_lock(&master->daa_lock);
@@ -1989,13 +1990,20 @@ int i3c_master_do_daa(struct i3c_master_controller *master)
usleep_range(2000, 2100);
ret = i3c_master_sethid_locked(master);
ret = i3c_master_setaasa_locked(master);
+ if(ret == 0)
+ result = true;
usleep_range(2000, 2100);
}
+ if(result)
+ ret = 0;
} else {
ret = master->ops->do_daa(master);
}
i3c_bus_maintenance_unlock(&master->bus);
+ dev_dbg(&master->dev,
+ "ret = %d, result = %d\n", ret, (int)result);
+
if (ret)
goto mutex_unlock;
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index c29c609510e7..d27b89318df2 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -3162,7 +3162,7 @@ static int dw_i3c_probe(struct platform_device *pdev)
master->maxdevs = DEVICE_ADDR_TABLE_DEPTH(ret);
master->dat_depth = DEVICE_ADDR_TABLE_DEPTH(ret);
if (master->maxdevs < MAX_DEVS) {
- dev_info(master->dev, "HW DAT supports only %i target devices - enabling SW DAT to support %i devices\n",
+ dev_dbg(master->dev, "HW DAT supports only %i target devices - enabling SW DAT to support %i devices\n",
master->maxdevs, MAX_DEVS);
master->maxdevs = MAX_DEVS;
master->sw_dat_enabled = true;
@@ -3215,7 +3215,7 @@ static int dw_i3c_probe(struct platform_device *pdev)
if (ret)
dev_warn(master->dev, "Failed to initialize debug FS, ret=%i\n", ret);
- dev_info(&pdev->dev, "i3c bus %d registered, irq %d\n",
+ dev_dbg(&pdev->dev, "i3c bus %d registered, irq %d\n",
master->base.bus_id, irq);
return 0;
--
2.34.1
@@ -0,0 +1,125 @@
From 91773622d78c8a32c5591a8d1e7f9f4cb51486d8 Mon Sep 17 00:00:00 2001
From: Sujoy Ray <sujoy.ray@intel.com>
Date: Wed, 20 Mar 2024 14:22:49 -0700
Subject: [PATCH] Workaround VW interrupt design issue
In AST2600, eSPI reset interrupt is triggered at both edges.
In the ISR GPIO direction register is set, and it has been found
that if it is set after the first interrupt, it gets cleared when
the 2nd edge arrives. To fix the issue workqueue is created at it
is delayed by 500ms. The GPIO direction register is set in the
context of delayed workqueue.
Signed-off-by: Sujoy Ray <sujoy.ray@intel.com>
---
drivers/gpio/gpio-aspeed-espi-vw.c | 52 ++++++++++++++++++++++++------
1 file changed, 43 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpio-aspeed-espi-vw.c b/drivers/gpio/gpio-aspeed-espi-vw.c
index 0c78d78fa540..418dc7266662 100644
--- a/drivers/gpio/gpio-aspeed-espi-vw.c
+++ b/drivers/gpio/gpio-aspeed-espi-vw.c
@@ -6,6 +6,8 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
+#include <linux/workqueue.h>
+#include <linux/timer.h>
#include <linux/mfd/syscon.h>
#include <linux/soc/aspeed/aspeed-espi.h>
@@ -49,6 +51,15 @@ struct aspeed_espi_gpio {
spinlock_t lock;
};
+struct aspeed_espi_vw_delayed_work_struct {
+ struct delayed_work delayed_work;
+ void *arg;
+};
+
+static struct workqueue_struct *aspeed_espi_gpio_workqueue;
+static void aspeed_espi_vw_gpio_workqueue(struct work_struct *work);
+static struct aspeed_espi_vw_delayed_work_struct aspeed_vw_work;
+
static void aspeed_espi_vw_gpio_enable(struct regmap *map, u32 dir_mask)
{
regmap_update_bits(map, ASPEED_ESPI_INT_EN, ASPEED_ESPI_INT_EN_VW_MASK,
@@ -75,6 +86,26 @@ static void set_nth_bit(u32 *n, uint8_t offset, u32 val)
*n = *n | (1ul << offset);
}
+void aspeed_espi_vw_gpio_workqueue(struct work_struct *work)
+{
+ struct aspeed_espi_gpio *gpio;
+ struct aspeed_espi_vw_delayed_work_struct *work_ptr;
+ unsigned long flags;
+
+ struct delayed_work *dw = container_of(work, struct delayed_work, work);
+
+ work_ptr = container_of(dw, struct aspeed_espi_vw_delayed_work_struct,
+ delayed_work);
+ gpio = work_ptr->arg;
+ aspeed_espi_vw_gpio_enable(gpio->map, gpio->dir_mask);
+ dev_dbg(gpio->dev, "Resetting VGPIO value [%08X] from workqueue\n",
+ cached_reg_val);
+ spin_lock_irqsave(&gpio->lock, flags);
+ regmap_update_bits(gpio->map, ASPEED_ESPI_VW_GPIO_VAL, gpio->dir_mask,
+ cached_reg_val);
+ spin_unlock_irqrestore(&gpio->lock, flags);
+}
+
static int vgpio_get_value(struct gpio_chip *gc, unsigned int offset)
{
struct aspeed_espi_gpio *gpio = gpiochip_get_data(gc);
@@ -213,22 +244,16 @@ static int aspeed_espi_vw_gpio_init(struct device *dev, struct aspeed_espi_gpio
static void aspeed_espi_vw_irq(int irq, void *arg)
{
struct aspeed_espi_gpio *gpio = arg;
- unsigned long flags;
u32 sts;
-
if (regmap_read(gpio->map, ASPEED_ESPI_INT_STS, &sts)) {
dev_dbg(gpio->dev, "Error reading int status\n");
return;
}
if (sts & ASPEED_ESPI_INT_STS_HW_RESET) {
- dev_dbg(gpio->dev, "Resetting VGPIO value [%08X]\n", cached_reg_val);
- aspeed_espi_vw_gpio_enable(gpio->map, gpio->dir_mask);
-
- spin_lock_irqsave(&gpio->lock, flags);
- regmap_update_bits(gpio->map, ASPEED_ESPI_VW_GPIO_VAL, gpio->dir_mask,
- cached_reg_val);
- spin_unlock_irqrestore(&gpio->lock, flags);
+ dev_dbg(gpio->dev, "Scheduling workqueue for deferred processing\n");
+ queue_delayed_work(aspeed_espi_gpio_workqueue, &aspeed_vw_work.delayed_work,
+ msecs_to_jiffies(500));
}
/* Clearing of status register will be done from parent driver*/
}
@@ -257,6 +282,14 @@ static int aspeed_espi_gpio_probe(struct platform_device *pdev)
aspeed_espi_register_gpio(pdev->dev.parent, aspeed_espi_vw_irq, gpio);
+ aspeed_espi_gpio_workqueue = create_workqueue("aspeed_espi_workqueue");
+ if (!aspeed_espi_gpio_workqueue) {
+ pr_err("Failed to create workqueue");
+ return -ENOMEM;
+ }
+
+ aspeed_vw_work.arg = gpio;
+ INIT_DELAYED_WORK(&aspeed_vw_work.delayed_work, aspeed_espi_vw_gpio_workqueue);
return ret;
}
@@ -265,6 +298,7 @@ static int aspeed_espi_gpio_remove(struct platform_device *pdev)
struct aspeed_espi_gpio *gpio = dev_get_drvdata(&pdev->dev);
aspeed_espi_vw_gpio_disable(gpio->map);
+ cancel_delayed_work_sync(&aspeed_vw_work.delayed_work);
return 0;
}
--
2.25.1
@@ -0,0 +1,223 @@
From 674e059d34193930cd48df8fe1f2f5bf49c83469 Mon Sep 17 00:00:00 2001
From: roly <Rolyli.Li@luxshare-ict.com>
Date: Thu, 9 Jan 2025 08:54:00 +0800
Subject: [PATCH] soc aspeed abr Add sysfs attrs for flash toggle
---
drivers/spi/spi-aspeed-smc.c | 60 +++++++++++++
include/linux/soc/aspeed/aspeed-abr.h | 118 ++++++++++++++++++++++++++
2 files changed, 178 insertions(+)
create mode 100644 include/linux/soc/aspeed/aspeed-abr.h
diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c
index 70c4e6e3e2e8..8a819f8f65ba 100644
--- a/drivers/spi/spi-aspeed-smc.c
+++ b/drivers/spi/spi-aspeed-smc.c
@@ -13,6 +13,7 @@
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/spi/spi-mem.h>
+#include <linux/soc/aspeed/aspeed-abr.h>
#define DEVICE_NAME "spi-aspeed-smc"
@@ -110,6 +111,53 @@ struct aspeed_spi {
u8 *op_buf;
};
+static ssize_t access_primary_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct aspeed_spi *aspi = dev_get_drvdata(dev);
+
+ return _access_primary_show(aspi->regs, attr, buf);
+}
+
+static ssize_t access_primary_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct aspeed_spi *aspi = dev_get_drvdata(dev);
+
+ return _access_primary_store(aspi->regs, attr, buf, size);
+}
+
+static ssize_t access_backup_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct aspeed_spi *aspi = dev_get_drvdata(dev);
+
+ return _access_backup_show(aspi->regs, attr, buf);
+}
+
+static ssize_t access_backup_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct aspeed_spi *aspi = dev_get_drvdata(dev);
+
+ return _access_backup_store(aspi->regs, attr, buf, size);
+}
+
+static DEVICE_ATTR_RW(access_primary);
+static DEVICE_ATTR_RW(access_backup);
+
+static struct attribute *bswitch_primary_attrs[] = {
+ &dev_attr_access_primary.attr, NULL
+};
+
+static struct attribute *bswitch_backup_attrs[] = {
+ &dev_attr_access_backup.attr, NULL
+};
+
+ATTRIBUTE_GROUPS(bswitch_primary);
+ATTRIBUTE_GROUPS(bswitch_backup);
static u32 aspeed_spi_get_io_mode(const struct spi_mem_op *op)
{
switch (op->data.buswidth) {
@@ -908,6 +956,18 @@ static int aspeed_spi_probe(struct platform_device *pdev)
ctlr->num_chipselect = data->max_cs;
ctlr->dev.of_node = dev->of_node;
+ if (of_device_is_compatible(dev->of_node, "aspeed,ast2600-fmc")) {
+ /* if boot from alt source, show access_primary, otherwise show access_backup */
+ if (readl(aspi->regs + OFFSET_ABR_CTRL_STATUS) &
+ ABR_BOOT_SRC_INDICATE) {
+ if (devm_device_add_groups(dev, bswitch_primary_groups))
+ dev_warn(dev, "Could not add access_primary\n");
+ } else {
+ if (devm_device_add_groups(dev, bswitch_backup_groups))
+ dev_warn(dev, "Could not add access_backup\n");
+ }
+ }
+
ret = devm_spi_register_controller(dev, ctlr);
if (ret) {
dev_err(&pdev->dev, "spi_register_controller failed\n");
diff --git a/include/linux/soc/aspeed/aspeed-abr.h b/include/linux/soc/aspeed/aspeed-abr.h
new file mode 100644
index 000000000000..144f43dff1ac
--- /dev/null
+++ b/include/linux/soc/aspeed/aspeed-abr.h
@@ -0,0 +1,118 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef __ASPEED_ABR_H__
+#define __ASPEED_ABR_H__
+
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/io.h>
+
+#define OFFSET_ABR_CTRL_STATUS 0x64
+#define OFFSET_ABR_TIMER_RELOAD 0x68
+#define OFFSET_ABR_TIMER_RESTART 0x6c
+
+#define ABR_WDT_ENABLE BIT(0)
+#define ABR_BOOT_SRC_INDICATE BIT(4)
+#define ABR_RESTART_MAGIC 0x4755
+#define ABR_CLEAR_BOOT_SRC_MAGIC (0xEA << 16)
+#define ABR_RELOAD_MAX_VALUE 0x1fff
+
+static inline ssize_t _access_primary_show(void __iomem *regs,
+ struct device_attribute *attr,
+ char *buf)
+{
+ u32 status = readl(regs + OFFSET_ABR_CTRL_STATUS);
+
+ return sysfs_emit(buf, "%u\n", !(status & ABR_BOOT_SRC_INDICATE));
+}
+
+static inline ssize_t _access_primary_store(void __iomem *regs,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ unsigned long val;
+
+ if (kstrtoul(buf, 10, &val))
+ return -EINVAL;
+
+ /* disable watchdog */
+ if (val == 0) {
+ writel(0, regs + OFFSET_ABR_CTRL_STATUS);
+ return size;
+ }
+
+ /* val is the microsecond, convert to reload count(0.1s) */
+ val /= (100 * 1000);
+
+ /*
+ * bit[12:0] : Reload value of expire time
+ * The time unit is 0.1 second. Default set at 22 seconds
+ * 0: Immediately timeout
+ */
+ val = val < ABR_RELOAD_MAX_VALUE ? val : ABR_RELOAD_MAX_VALUE;
+
+ writel(0, regs + OFFSET_ABR_CTRL_STATUS);
+ writel(val, regs + OFFSET_ABR_TIMER_RELOAD);
+
+ /* Write 0x4755 value to load the reload value into watchdog counter */
+ writel(ABR_RESTART_MAGIC, regs + OFFSET_ABR_TIMER_RESTART);
+
+ /* Enable watchdog */
+ writel(ABR_WDT_ENABLE, regs + OFFSET_ABR_CTRL_STATUS);
+ return size;
+}
+
+static inline ssize_t _access_backup_show(void __iomem *regs,
+ struct device_attribute *attr,
+ char *buf)
+{
+ u32 status = readl(regs + OFFSET_ABR_CTRL_STATUS);
+ u32 timer_reload = readl(regs + OFFSET_ABR_TIMER_RELOAD);
+
+ if (!(status & ABR_WDT_ENABLE))
+ return sysfs_emit(buf, "%u\n", 0);
+
+ /*
+ * [31:16] Counter value status
+ * timeout unit is 0.1s, convert to microseconds
+ */
+ return sysfs_emit(buf, "%u\n", (timer_reload >> 16) * 100 * 1000);
+}
+
+static inline ssize_t _access_backup_store(void __iomem *regs,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ unsigned long val;
+
+ if (kstrtoul(buf, 10, &val))
+ return -EINVAL;
+
+ /* disable watchdog */
+ if (val == 0) {
+ writel(0, regs + OFFSET_ABR_CTRL_STATUS);
+ return size;
+ }
+
+ /* val is the microsecond, convert to reload count(0.1s) */
+ val /= (100 * 1000);
+
+ /*
+ * bit[12:0] : Reload value of expire time
+ * The time unit is 0.1 second. Default set at 22 seconds
+ * 0: Immediately timeout
+ */
+ val = val < ABR_RELOAD_MAX_VALUE ? val : ABR_RELOAD_MAX_VALUE;
+
+ writel(0, regs + OFFSET_ABR_CTRL_STATUS);
+ writel(val, regs + OFFSET_ABR_TIMER_RELOAD);
+
+ /* Write 0x4755 value to load the reload value into watchdog counter */
+ writel(ABR_RESTART_MAGIC, regs + OFFSET_ABR_TIMER_RESTART);
+
+ /* Enable watchdog */
+ writel(ABR_WDT_ENABLE, regs + OFFSET_ABR_CTRL_STATUS);
+ return size;
+}
+
+#endif
--
2.25.1
@@ -0,0 +1,32 @@
From f9583e98c2a73f1642c28dc7c043bc8a656c6b83 Mon Sep 17 00:00:00 2001
From: Zbigniew Lukwinski <zbigniew.lukwinski@linux.intel.com>
Date: Wed, 11 May 2022 15:26:24 +0200
Subject: [PATCH] i3c: mctp: workaround for wrong DCR value
In GNR A0 there is an issue about DCR value. I3C MNG IP in GNR A0
introduces itself with DCR=0xC9. Adding this value to allow MCTP over
I3C driver to be loaded in this case as well.
Issue will be fixed in GNR B0.
Signed-off-by: Zbigniew Lukwinski <zbigniew.lukwinski@linux.intel.com>
Upstream-Status: Pending
---
drivers/i3c/mctp/i3c-mctp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/i3c/mctp/i3c-mctp.c b/drivers/i3c/mctp/i3c-mctp.c
index b0e3814..42e864d 100644
--- a/drivers/i3c/mctp/i3c-mctp.c
+++ b/drivers/i3c/mctp/i3c-mctp.c
@@ -333,6 +333,8 @@ static void i3c_mctp_remove(struct i3c_device *i3cdev)
static const struct i3c_device_id i3c_mctp_ids[] = {
I3C_CLASS(0xCC, 0x0),
+ /* Workaround for GNR A0 where I3C MNG IP introduces itself with DCR=0xC9 */
+ I3C_CLASS(0xC9, 0x0),
{ },
};
--
2.7.4
@@ -0,0 +1,105 @@
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index d333e7422f4a..f586deaf9d38 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -236,7 +236,14 @@ EXPORT_SYMBOL_GPL(pwm_get_chip_data);
static bool pwm_ops_check(const struct pwm_chip *chip)
{
const struct pwm_ops *ops = chip->ops;
+ /* driver supports legacy, non-atomic operation */
+ if (ops->config && ops->enable && ops->disable) {
+ if (IS_ENABLED(CONFIG_PWM_DEBUG))
+ dev_warn(chip->dev,
+ "Driver needs updating to atomic API\n");
+ return true;
+ }
if (!ops->apply)
return false;
@@ -538,6 +545,73 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
}
}
+static int pwm_apply_legacy(struct pwm_chip *chip, struct pwm_device *pwm,
+ const struct pwm_state *state)
+{
+ int err;
+ struct pwm_state initial_state = pwm->state;
+
+ if (state->polarity != pwm->state.polarity) {
+ if (!chip->ops->set_polarity)
+ return -EINVAL;
+
+ /*
+ * Changing the polarity of a running PWM is only allowed when
+ * the PWM driver implements ->apply().
+ */
+ if (pwm->state.enabled) {
+ chip->ops->disable(chip, pwm);
+
+ /*
+ * Update pwm->state already here in case
+ * .set_polarity() or another callback depend on that.
+ */
+ pwm->state.enabled = false;
+ }
+
+ err = chip->ops->set_polarity(chip, pwm, state->polarity);
+ if (err)
+ goto rollback;
+
+ pwm->state.polarity = state->polarity;
+ }
+
+ if (!state->enabled) {
+ if (pwm->state.enabled)
+ chip->ops->disable(chip, pwm);
+
+ return 0;
+ }
+
+ /*
+ * We cannot skip calling ->config even if state->period ==
+ * pwm->state.period && state->duty_cycle == pwm->state.duty_cycle
+ * because we might have exited early in the last call to
+ * pwm_apply_state because of !state->enabled and so the two values in
+ * pwm->state might not be configured in hardware.
+ */
+ err = chip->ops->config(pwm->chip, pwm,
+ state->duty_cycle,
+ state->period);
+ if (err)
+ goto rollback;
+
+ pwm->state.period = state->period;
+ pwm->state.duty_cycle = state->duty_cycle;
+
+ if (!pwm->state.enabled) {
+ err = chip->ops->enable(chip, pwm);
+ if (err)
+ goto rollback;
+ }
+
+ return 0;
+
+rollback:
+ pwm->state = initial_state;
+ return err;
+}
+
/**
* pwm_apply_state() - atomically apply a new state to a PWM device
* @pwm: PWM device
@@ -570,7 +644,10 @@ int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
state->usage_power == pwm->state.usage_power)
return 0;
- err = chip->ops->apply(chip, pwm, state);
+ if (chip->ops->apply)
+ err = chip->ops->apply(chip, pwm, state);
+ else
+ err = pwm_apply_legacy(chip, pwm, state);
if (err)
return err;
@@ -0,0 +1,36 @@
From 356d9bdcc0555170ae8f61bae3d082745a5b7406 Mon Sep 17 00:00:00 2001
From: Zbigniew Lukwinski <zbigniew.lukwinski@linux.intel.com>
Date: Fri, 11 Aug 2023 01:16:51 +0200
Subject: [PATCH] i3c: master: drop GETMRL and GETMWL for MNG use case
For MNG use case there is no need to send GETMRL and GETMWL because those
CCCs are not supported by target device. For MNG use case will use
hardcoded maximum values.
Moreover there is an issue in ICE1.0 where PEC error counter is bumped up
in case sending not supported CCC.
Signed-off-by: Zbigniew Lukwinski <zbigniew.lukwinski@linux.intel.com>
---
drivers/i3c/master.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 234599825f41..0f9fcf1fab35 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1546,8 +1546,10 @@ static int i3c_master_retrieve_dev_info(struct i3c_dev_desc *dev)
if (dev->info.bcr & I3C_BCR_IBI_PAYLOAD)
dev->info.max_ibi_len = 1;
- i3c_master_getmrl_locked(master, &dev->info);
- i3c_master_getmwl_locked(master, &dev->info);
+ if (!master->is_mng) {
+ i3c_master_getmrl_locked(master, &dev->info);
+ i3c_master_getmwl_locked(master, &dev->info);
+ }
if (dev->info.bcr & I3C_BCR_HDR_CAP) {
ret = i3c_master_gethdrcap_locked(master, &dev->info);
--
2.34.1
@@ -0,0 +1,89 @@
From 0851611d47f99f5bbba29d3cb39e109a4ecdcb0e Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Fri, 11 Oct 2024 12:48:24 +0800
Subject: [PATCH] Add I3C GPIO switch in dw-i3c-master driver
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
drivers/i3c/master/dw-i3c-master.c | 34 ++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index c29c609510e7..6d1ba40eca0f 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -25,6 +25,7 @@
#include <linux/regmap.h>
#include <linux/reset.h>
#include <linux/slab.h>
+#include <linux/gpio.h>
/*
* Below bits are valid for I3Cx Global register (REG1) on AST2600 platform.
@@ -373,6 +374,9 @@
#define AST2600_I3C_IBI_MAX_PAYLOAD 255
+#define SEL_CPU0_I3C_DDR_GPIO 921
+#define SEL_CPU1_I3C_DDR_GPIO 922
+
struct dw_i3c_master_caps {
u8 cmdfifodepth;
u8 datafifodepth;
@@ -3110,6 +3114,33 @@ static int dw_i3c_debugfs_init(struct dw_i3c_master *master)
return 0;
}
+static void i3c_gpio_switch_bmc(struct dw_i3c_master *master)
+{
+ if (gpio_request(SEL_CPU0_I3C_DDR_GPIO, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate SEL_CPU0_I3C_DDR_GPIO\n");
+ return;
+ }
+
+ if (gpio_request(SEL_CPU1_I3C_DDR_GPIO, "dw-i3c-master")) {
+ dev_err(master->dev, "unable to allocate SEL_CPU0_I3C_DDR_GPIO\n");
+ return;
+ }
+ gpio_direction_output(SEL_CPU0_I3C_DDR_GPIO, 1);
+ gpio_direction_output(SEL_CPU1_I3C_DDR_GPIO, 1);
+
+ usleep_range(500, 1000);
+}
+
+static void i3c_gpio_switch_bios(struct dw_i3c_master *master)
+{
+ gpio_direction_output(SEL_CPU0_I3C_DDR_GPIO, 0);
+ gpio_direction_output(SEL_CPU1_I3C_DDR_GPIO, 0);
+ usleep_range(500, 1000);
+
+ gpio_free(SEL_CPU0_I3C_DDR_GPIO);
+ gpio_free(SEL_CPU1_I3C_DDR_GPIO);
+}
+
static int dw_i3c_probe(struct platform_device *pdev)
{
const struct of_device_id *match;
@@ -3149,6 +3180,7 @@ static int dw_i3c_probe(struct platform_device *pdev)
spin_lock_init(&master->ibi.master.lock);
platform_set_drvdata(pdev, master);
+ i3c_gpio_switch_bmc(master);
/* Information regarding the FIFOs/QUEUEs depth */
ret = readl(master->regs + QUEUE_STATUS_LEVEL);
@@ -3218,9 +3250,11 @@ static int dw_i3c_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "i3c bus %d registered, irq %d\n",
master->base.bus_id, irq);
+ i3c_gpio_switch_bios(master);
return 0;
err_assert_rst:
+ i3c_gpio_switch_bios(master);
reset_control_assert(master->core_rst);
err_disable_core_clk:
--
2.34.1
@@ -0,0 +1,668 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright 2019 IBM Corp.
/dts-v1/;
#include "aspeed-g6.dtsi"
#include <dt-bindings/gpio/aspeed-gpio.h>
/ {
model = "AST2600 EVB";
compatible = "aspeed,ast2600-evb", "aspeed,ast2600";
aliases {
serial4 = &uart5;
i2c16 = &channel_12_0;
i2c17 = &channel_12_1;
i2c18 = &channel_12_2;
i2c19 = &channel_12_3;
i2c20 = &channel_12_4;
i2c21 = &channel_12_5;
i2c22 = &channel_12_6;
i2c23 = &channel_12_7;
};
chosen {
bootargs = "console=ttyS4,115200n8";
};
memory@80000000 {
device_type = "memory";
reg = <0x80000000 0x80000000>;
};
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
ranges;
video_engine_memory: video {
size = <0x04000000>;
alignment = <0x01000000>;
compatible = "shared-dma-pool";
reusable;
};
gfx_memory: framebuffer {
size = <0x01000000>;
alignment = <0x01000000>;
compatible = "shared-dma-pool";
reusable;
};
espi_mmbi_memory: espi_mmbi_memory {
no-map;
reg = <0x9EFF0000 0x10000>; /* 64K */
};
};
leds {
compatible = "gpio-leds";
heartbeat {
gpios = <&gpio0 ASPEED_GPIO(B, 0) GPIO_ACTIVE_LOW>;
linux,default-trigger = "timer";
};
health_green {
gpios = <&gpio0 ASPEED_GPIO(G, 6) GPIO_ACTIVE_LOW>;
};
health_red {
gpios = <&gpio0 ASPEED_GPIO(G, 7) GPIO_ACTIVE_LOW>;
};
uidbtn {
gpios = <&gpio0 ASPEED_GPIO(S, 6) GPIO_ACTIVE_LOW>;
};
};
iio-hwmon {
compatible = "iio-hwmon";
io-channels = <&adc0 0>, <&adc0 1>, <&adc0 2>, <&adc0 3>,
<&adc0 4>, <&adc0 5>, <&adc0 6>, <&adc0 7>,
<&adc1 0>, <&adc1 1>, <&adc1 2>, <&adc1 3>,
<&adc1 4>, <&adc1 5>, <&adc1 6>, <&adc1 7>;
};
};
&mdio0 {
status = "okay";
ethphy0: ethernet-phy@0 {
compatible = "ethernet-phy-ieee802.3-c22";
reg = <0>;
};
};
&mac0 {
status = "okay";
phy-mode = "rgmii-txid";
phy-handle = <&ethphy0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_rgmii1_default>;
clocks = <&syscon ASPEED_CLK_GATE_MAC1CLK>,
<&syscon ASPEED_CLK_MAC1RCLK>;
clock-names = "MACCLK", "RCLK";
};
&uart1 {
status = "okay";
pinctrl-0 = <&pinctrl_txd1_default
&pinctrl_rxd1_default>;
};
&uart2 {
status = "okay";
pinctrl-0 = <>;
};
&uart3 {
status = "okay";
pinctrl-0 = <>;
};
&uart4 {
status = "okay";
pinctrl-0 = <>;
};
&uart5 {
status = "okay";
};
&uart_routing {
status = "okay";
};
&emmc_controller {
status = "okay";
};
&emmc {
non-removable;
bus-width = <4>;
max-frequency = <100000000>;
clk-phase-mmc-hs200 = <9>, <225>;
};
&rtc {
status = "okay";
};
&fmc {
status = "okay";
flash@0 {
status = "okay";
m25p,fast-read;
label = "bmc";
spi-rx-bus-width = <2>;
spi-max-frequency = <25000000>;
#include "openbmc-flash-layout-64.dtsi"
};
flash@1 {
status = "okay";
m25p,fast-read;
label = "alt-bmc";
spi-rx-bus-width = <2>;
spi-max-frequency = <25000000>;
#include "openbmc-flash-layout-64-alt.dtsi"
};
};
&spi1 {
status = "okay";
low-spi-clk-write;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_spi1_default &pinctrl_spi1cs1_default>;
flash@0 {
status = "okay";
m25p,fast-read;
label = "bios";
spi-max-frequency = <33000000>;
spi-tx-bus-width = <1>;
spi-rx-bus-width = <1>;
};
};
&adc0 {
vref = <1800>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_adc0_default &pinctrl_adc1_default
&pinctrl_adc2_default &pinctrl_adc3_default
&pinctrl_adc4_default &pinctrl_adc5_default
&pinctrl_adc6_default &pinctrl_adc7_default>;
};
&adc1 {
vref = <1800>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_adc8_default &pinctrl_adc9_default
&pinctrl_adc10_default &pinctrl_adc11_default
&pinctrl_adc12_default &pinctrl_adc13_default
&pinctrl_adc14_default &pinctrl_adc15_default>;
};
&i2c0 {
status = "okay";
};
&i2c1 {
status = "okay";
};
&i2c2 {
status = "okay";
};
&i2c3 {
status = "okay";
};
&i2c4 {
status = "okay";
};
&i2c5 {
status = "okay";
};
&i2c6 {
status = "okay";
};
&i2c7 {
status = "okay";
};
&i2c8 {
status = "okay";
};
&i2c9 {
status = "okay";
};
&i2c12 {
status = "okay";
i2c-switch@74 {
compatible = "nxp,pca9548";
reg = <0x74>;
#address-cells = <1>;
#size-cells = <0>;
channel_12_0: i2c@0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
};
channel_12_1: i2c@1 {
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
};
channel_12_2: i2c@2 {
#address-cells = <1>;
#size-cells = <0>;
reg = <2>;
};
channel_12_3: i2c@3 {
#address-cells = <1>;
#size-cells = <0>;
reg = <3>;
};
channel_12_4: i2c@4 {
#address-cells = <1>;
#size-cells = <0>;
reg = <4>;
};
channel_12_5: i2c@5 {
#address-cells = <1>;
#size-cells = <0>;
reg = <5>;
};
channel_12_6: i2c@6 {
#address-cells = <1>;
#size-cells = <0>;
reg = <6>;
};
channel_12_7: i2c@7 {
#address-cells = <1>;
#size-cells = <0>;
reg = <7>;
};
};
};
&i2c13 {
status = "okay";
};
&i2c14 {
status = "okay";
eeprom@53 {
compatible = "atmel,24c32";
reg = <0x53>;
};
};
&i2c15 {
status = "okay";
};
&i3cglobal {
status = "okay";
};
&i3c0 {
/* I3C_SPD_BMC */
status = "okay";
i3c-scl-hz = <2000000>;
i3c-pp-scl-high-ns = <250>;
i2c-scl-hz = <400000>;
i3c-od-scl-high-ns = <1130>;
sda-tx-hold-ns = <30>;
jdec-spd;
spd@50,3C000000000 {
reg = <0x50 0x3C0 0x00000000>;
assigned-address = <0x50>;
};
spd@48,3C000000008 {
reg = <0x48 0x3C0 0x00000008>;
assigned-address = <0x48>;
};
spd@10,3C000000010 {
reg = <0x10 0x3C0 0x00000010>;
assigned-address = <0x10>;
};
spd@30,3C000000030 {
reg = <0x30 0x3C0 0x00000030>;
assigned-address = <0x30>;
};
spd@52,3C000000002 {
reg = <0x52 0x3C0 0x00000002>;
assigned-address = <0x52>;
};
spd@4A,3C00000000A {
reg = <0x4A 0x3C0 0x0000000A>;
assigned-address = <0x4A>;
};
spd@12,3C000000012 {
reg = <0x12 0x3C0 0x00000012>;
assigned-address = <0x12>;
};
spd@32,3C000000032 {
reg = <0x32 0x3C0 0x00000032>;
assigned-address = <0x32>;
};
spd@54,3C000000004 {
reg = <0x54 0x3C0 0x00000004>;
assigned-address = <0x54>;
};
spd@4C,3C00000000C {
reg = <0x4C 0x3C0 0x0000000C>;
assigned-address = <0x4C>;
};
spd@14,3C000000014 {
reg = <0x14 0x3C0 0x00000014>;
assigned-address = <0x14>;
};
spd@34,3C000000034 {
reg = <0x34 0x3C0 0x00000034>;
assigned-address = <0x34>;
};
};
&i3c1 {
/* I3C_SPD_BMC */
status = "okay";
i3c-scl-hz = <2000000>;
i3c-pp-scl-high-ns = <250>;
i2c-scl-hz = <400000>;
i3c-od-scl-high-ns = <1130>;
sda-tx-hold-ns = <30>;
jdec-spd;
spd@50,3C000000000 {
reg = <0x50 0x3C0 0x00000000>;
assigned-address = <0x50>;
};
spd@48,3C000000008 {
reg = <0x48 0x3C0 0x00000008>;
assigned-address = <0x48>;
};
spd@10,3C000000010 {
reg = <0x10 0x3C0 0x00000010>;
assigned-address = <0x10>;
};
spd@30,3C000000030 {
reg = <0x30 0x3C0 0x00000030>;
assigned-address = <0x30>;
};
spd@52,3C000000002 {
reg = <0x52 0x3C0 0x00000002>;
assigned-address = <0x52>;
};
spd@4A,3C00000000A {
reg = <0x4A 0x3C0 0x0000000A>;
assigned-address = <0x4A>;
};
spd@12,3C000000012 {
reg = <0x12 0x3C0 0x00000012>;
assigned-address = <0x12>;
};
spd@32,3C000000032 {
reg = <0x32 0x3C0 0x00000032>;
assigned-address = <0x32>;
};
spd@54,3C000000004 {
reg = <0x54 0x3C0 0x00000004>;
assigned-address = <0x54>;
};
spd@4C,3C00000000C {
reg = <0x4C 0x3C0 0x0000000C>;
assigned-address = <0x4C>;
};
spd@14,3C000000014 {
reg = <0x14 0x3C0 0x00000014>;
assigned-address = <0x14>;
};
spd@34,3C000000034 {
reg = <0x34 0x3C0 0x00000034>;
assigned-address = <0x34>;
};
};
&fsim0 {
status = "okay";
};
&kcs1 {
aspeed,lpc-io-reg = <0xCA0>;
status = "okay";
};
&kcs2 {
aspeed,lpc-io-reg = <0xCA8 0xCA9>;
status = "okay";
};
&kcs3 {
aspeed,lpc-io-reg = <0xCA2>;
status = "okay";
};
&kcs4 {
aspeed,lpc-io-reg = <0xCA4>;
status = "okay";
};
&vhub {
status = "okay";
pinctrl-names = "default";
};
&video {
status = "okay";
memory-region = <&video_engine_memory>;
};
&gfx {
status = "okay";
memory-region = <&gfx_memory>;
};
&espi {
status = "okay";
};
&vwgpio {
gpio-count = <32>;
gpio-names-mask = <0x000001F3>;
gpio-dir-mask = <0x00000FF0>;
gpio-names = "VW_FM_BIOS_POST_CMPLT_N", "VW_DIMM_I3C_SWITCH",
"VW_FM_DUAL_PARTITION_N", "VW_FM_STANDALONE_MODE_N",
"VW_FM_4S_8S_N_MODE", "VW_FM_NODE_ID_1", "VW_FM_NODE_ID_0";
status = "okay";
};
&mmbi {
status = "okay";
host-map-addr = <0xF6810000>;
memory-region = <&espi_mmbi_memory>;
};
&sio_regs {
status = "okay";
sio_status {
offset = <0x10C>;
bit-mask = <0x1F>;
bit-shift = <4>;
};
sio29_status {
offset = <0x170>;
bit-mask = <0xFF>;
bit-shift = <8>;
};
};
&lpc_sio {
status = "okay";
};
&lpc_snoop {
snoop-ports = <0x80>;
status = "okay";
};
//&peci0 {
// status = "okay";
//};
&jtag0 {
status = "okay";
};
&jtag1 {
status = "okay";
};
&wdt2 {
status = "okay";
};
&pwm_tacho {
status = "okay";
pinctrl-names = "default";
#pwm-cells=<3>;
pinctrl-0 = <&pinctrl_pwm0_default &pinctrl_tach0_default
&pinctrl_pwm1_default &pinctrl_tach1_default
&pinctrl_pwm2_default &pinctrl_tach2_default
&pinctrl_pwm3_default &pinctrl_tach3_default
&pinctrl_pwm4_default &pinctrl_tach4_default
&pinctrl_pwm5_default &pinctrl_tach5_default
&pinctrl_pwm6_default &pinctrl_tach6_default
&pinctrl_pwm7_default &pinctrl_tach7_default
>;
fan@0 {
reg = <0x00>;
aspeed,fan-tach-ch = /bits/ 8 <0x00>;
};
fan@1 {
reg = <0x01>;
aspeed,fan-tach-ch = /bits/ 8 <0x01>;
};
fan@2 {
reg = <0x02>;
aspeed,fan-tach-ch = /bits/ 8 <0x02>;
};
fan@3 {
reg = <0x03>;
aspeed,fan-tach-ch = /bits/ 8 <0x03>;
};
fan@4 {
reg = <0x04>;
aspeed,fan-tach-ch = /bits/ 8 <0x04>;
};
fan@5 {
reg = <0x05>;
aspeed,fan-tach-ch = /bits/ 8 <0x05>;
};
fan@6 {
reg = <0x06>;
aspeed,fan-tach-ch = /bits/ 8 <0x06>;
};
fan@7 {
reg = <0x07>;
aspeed,fan-tach-ch = /bits/ 8 <0x07>;
};
};
&mctp {
status = "okay";
};
&peci_legacy0 {
status = "okay";
};
&pcieh {
status = "okay";
};
&gpio0 {
status = "okay";
gpio-line-names =
/*A0-A7*/ "","","","","SMB_CPU_PIROM_SCL","SMB_CPU_PIROM_SDA","SMB_IPMB_STBY_LVC3_SCL","SMB_IPMB_STBY_LVC3_SDA",
/*B0-B7*/ "","","","FM_CPU1_ERR2_LVT3_N","RGMII_BMC_RMM4_LVC3_R_MDC","RGMII_BMC_RMM4_LVC3_R_MDIO","FM_BMC_BMCINIT_R","FP_ID_LED_N",
/*C0-C7*/ "FM_FORCE_BMC_UPDATE_N","RST_RGMII_PHYRST_N","FM_TPM_EN_PULSE","","","","FM_CPU1_ERR0_LVT3_N","FM_CPU1_ERR1_LVT3_N",
/*D0-D7*/ "CPU_ERR0","CPU_ERR1","CPU_ERR2","PRDY_N","FM_SPD_SWITCH_CTRL_N","","","",
/*E0-E7*/ "FM_SKT1_FAULT_LED","FM_SKT0_FAULT_LED","CLK_50M_CKMNG_BMCB","","I3C_SPD_BMC_MUX0_EN","I3C_SPD_BMC_MUX1_EN","I3C_SPD_BMC_MUX2_EN","",
/*F0-F7*/ "","FM_DUAL_PARTITION_MODE_N","FM_STANDALONE_MODE_N","FM_4S_8S_N_MODE","FM_NODE_ID0","FM_NODE_ID1","","",
/*G0-G7*/ "FM_SMB_BMC_NVME_LVC3_ALERT_N","RST_BMC_HSBP_MUX_N","FP_LED_STATUS_GREEN_N","FP_LED_STATUS_AMBER_N","","FM_PARTITION_SEL","","",
/*H0-H7*/ "POWER_OUT","SGPIO_BMC_LD_R","SGPIO_BMC_DOUT_R","SGPIO_BMC_DIN","PLTRST_N","CPU_CATERR","","",
/*I0-I7*/ "","JTAG_ASD_TDI_R","JTAG_ASD_TCK_R","JTAG_ASD_TMS_R","JTAG_ASD_TDO","FM_BMC_PWRBTN_OUT_R_N","FM_BMC_PWR_BTN_N","",
/*J0-J7*/ "","","","","","","","",
/*K0-K7*/ "","","","","","","","",
/*L0-L7*/ "","","","","PREQ_N","I3C_SPD_BMC_MUX3_EN","","",
/*M0-M7*/ "","","","","","","SPA_SOUT","SPA_SIN",
/*N0-N7*/ "","SEL_CPU0_I3C_DDR_SW","SEL_CPU1_I3C_DDR_SW","","ID_BUTTON","POWER_BUTTON","SPB_SOUT","SPB_SIN",
/*O0-O7*/ "","","","","","","NMI_BUTTON","SPEAKER_BMC_R",
/*P0-P7*/ "","","","","","","","LED_BMC_HB_LED_N",
/*Q0-Q7*/ "","","","","","","","",
/*R0-R7*/ "","","","","","","","",
/*S0-S7*/ "RST_BMC_PCIE_MUX_N","FM_BMC_TRUST_N","FM_BMC_FRU_WP_N","","PWRGD_CPU0_AUXPWRGD","","","EN_BMC_ADC_P3V_VBAT",
/*T0-T7*/ "","","","","","","","",
/*U0-U7*/ "","","","","","","","",
/*V0-V7*/ "SIO_S3","SIO_S5","","SIO_ONCONTROL","","PS_PWROK","","",
/*W0-W7*/ "LPC_LAD0_ESPI_R_IO0","LPC_LAD1_ESPI_R_IO1","LPC_LAD2_ESPI_R_IO2","LPC_LAD3_ESPI_R_IO3","CLK_24M_66M_LPC0_ESPI_BMC","LPC_LFRAME_N_ESPI_CS0_BMC_N","IRQ_LPC_SERIRQ_ESPI_ALERT_N","RST_LPC_LRST_ESPI_RST_BMC_R_N",
/*X0-X7*/ "SEL_MONITOR_MUX","","PCH_BMC_THERMTRIP","","I3C_SPD_BMC_MUX0_SEL","I3C_SPD_BMC_MUX1_SEL","I3C_SPD_BMC_MUX2_SEL","I3C_SPD_BMC_MUX3_SEL",
/*Y0-Y7*/ "FM_BMC_CMOS_CLR_R_N","","FM_BMC_SAFS_EN","IRQ_SML1_PMBUS_BMC_ALERT_N","SPI_BMC_BOOT_R_IO2","SPI_BMC_BOOT_R_IO3","PU_SPI_BMC_BOOT_ABR","PU_SPI_BMC_BOOT_WP_N",
/*Z0-Z7*/ "","","","HW_STRAP_5","HW_STRAP_6","HW_STRAP_7","HW_STRAP_2","HW_STRAP_3";
};
@@ -0,0 +1,4 @@
CONFIG_INPUT_EVDEV=y
CONFIG_INPUT_KEYBOARD=y
CONFIG_KEYBOARD_GPIO=y
CONFIG_KEYBOARD_GPIO_POLLED=y
@@ -0,0 +1,2 @@
CONFIG_JTAG=y
CONFIG_JTAG_ASPEED=y
@@ -0,0 +1,8 @@
CONFIG_ESPI_LGMR_ADDR=0xF6810000
CONFIG_SENSORS_ASPEED_CHASSIS=y
CONFIG_GPIO_ASPEED_ESPI_VW=y
CONFIG_SMART_MODULE=n
CONFIG_DW_I3C_MASTER=m
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
@@ -0,0 +1,28 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI += " \
file://intel-bhs.cfg \
file://aspeed-ast2600-evb.dts \
file://0001-Workaround-VW-interrupt-design-issue.patch \
file://0002-i3c-mctp-workaround-for-wrong-DCR-value.patch \
file://0003-i3c-master-drop-GETMRL-and-GETMWL-for-MNG-use-case.patch \
file://0001-Force-set-pmbus-page-to-4-to-fix-Delta-PSU-reading-e.patch \
file://0003-Revert-pwm-Drop-support-for-legacy-drivers.patch \
file://0001-Modify-JTAG-driver-to-aspeed-driver.patch \
file://enable-gpio-key.cfg \
file://enable-jtag-driver.cfg \
file://0001-soc-aspeed-abr-Add-sysfs-attrs-for-flash-toggle.patch \
file://0001-Add-sw-workaround-to-let-all-dimm-spd-devices-to-rec.patch \
file://0001-Solve-the-do_daa-exception-exit-issue-when-the-DIMM-.patch \
"
do_configure:append() {
dts="../aspeed-ast2600-evb.dts"
if [ ! -f $dts]; then
echo $dts" does not exist"
else
cp ../aspeed-ast2600-evb.dts ./source/arch/arm/boot/dts/
fi
}
@@ -0,0 +1,21 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
LICENSE = "CLOSED"
SRC_URI += " \
file://cJSON.c \
file://cJSON.h \
file://lux_json_api.c \
file://lux_json_api.h \
file://lux_system_api.c \
file://lux_system_api.h \
file://cover_heat.c \
file://cover_heat.h \
file://lux_base.h \
file://cover_heat.json \
file://cover_heat_12fan.json \
file://CMakeLists.txt "
S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"
DEPENDS += "systemd dbus"
inherit pkgconfig cmake obmc-phosphor-systemd
SYSTEMD_SERVICE:${PN} = "cover-heat.service "
@@ -0,0 +1,19 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
inherit obmc-phosphor-systemd
SRC_URI += "file://cover-heat.service \
file://cover-heat.sh \
"
SYSTEMD_SERVICE_${PN} = "cover-heat.service"
do_install:append() {
# deal with systemd unit files
install -d ${D}${systemd_unitdir}/system
install -m 0755 ${WORKDIR}/cover-heat.sh ${D}${bindir}/cover-heat.sh
install -m 0644 ${WORKDIR}/cover-heat.service ${D}${systemd_unitdir}/system
}
FILES_${PN} += "${systemd_unitdir}/system/cover-heat.service"
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.15)
project(cover_heat)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
pkg_check_modules(DBUS REQUIRED dbus-1)
aux_source_directory(. SRC)
add_executable(${CMAKE_PROJECT_NAME} ${SRC})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${DBUS_LIBRARIES})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${DBUS_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${SYSTEMD_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${SYSTEMD_LIBRARIES})
install(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES cover_heat.json DESTINATION bin)
install(FILES cover_heat_12fan.json DESTINATION bin)
install(FILES cover-heat.sh DESTINATION bin)
@@ -0,0 +1,13 @@
CFLAGS += -Wall
OBJS = cover_heat.o cJSON.o lux_json_api.o lux_system_api.o
EXE = cover_heat
.c.o:
$(CC) -c $<
$(EXE): $(OBJS)
$(CC) $(OBJS) -o $@
all:$(EXE)
clean:
rm -f $(EXE) $(OBJS)
install:
cp $(EXE) $(INSTALL_DIR)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,292 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
pPermission 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.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 14
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,12 @@
[Unit]
Description=Oem Cover Heat Service
Requires=xyz.openbmc_project.EntityManager.service
After=xyz.openbmc_project.EntityManager.service
[Service]
Restart=always
RestartSec=5
ExecStart=/usr/bin/cover-heat.sh
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,4 @@
#!/bin/sh
#start cover heat logic
/usr/bin/cover_heat
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,355 @@
#ifndef DIMM_FSC_H
#define DIMM_FSC_H
#define DIMM_FSC_VERSION "V0.1"
#define FAN_TABLE_PATH "/usr/bin/cover_heat.json"
#define COVER_MANUAL_CONTROL_FLAG "/tmp/cover_manual"
#define COVER_MANUAL_CONTROL_VALUE "/tmp/cover_manual_value"
//define for thermal oem command
#define DIMM_SETPOINT_PATH "/tmp/dimm_setpoint"
#define COVER_SETPOINT_PATH "/tmp/cover_setpoint"
#define COVER_STATUS_PATH "/tmp/cover_status"
#define FSC_ENABLE_STATUS_PATH "/tmp/fsc_enable"
#define SETPOINT_CONSTANT "constant"
#define SETPOINT_VARIABLE "variable"
#define MAX_FSC_PWM_CHANNEL 24
#define MAX_DIMM_SLOT 24
#define MAX_JSON_CHARACTER_SIZE 128
#define MAX_SENSOR_NAME_LENGTH 16
#define MAX_KEY_LENGTH 32
#define PWM_POWER_ON_IN_SHORT_TIME 80
#define MAX_PWM_THERMAL_DEFINE 100
#define MIN_PWM_THERMAL_DEFINE 1
#define MAX_OL_SENSOR 10
#define MAX_OL_SENSOR_STEPS 50
#define MAX_CL_SENSOR 50
#define MAX_FAN_COUNT 20
#define MAX_SETPOINT_CASE 10
#define MAX_SENSOR_E_SECTION 12
#define MAX_SENSOR_EC_SECTION 9
#define MAX_ABNORMAL_SENSOR 50
#define MAX_FAN_AVERAGE_COUNT 10
#define PID_INIT_PWM 50
#define SENSOR_REAL_VALUE_INITIAL 127 /*init sensor reading to 127, sign value */
#define POWERON_FSC_DELAY 10
#define INLET_SENSOR_VALUE_ABNORMAL_STATE 35 /*if inlet sensor is can't read, need use 35 do fsc control */
#define SENSOR_UPPER_NON_CRITICAL_PWM 80
#define SENSOR_UPPER_CRITICAL_PWM 90
#define SENSOR_UPPER_NON_RECOVERABLE_PWM 100
#define MAX_READING_CACHE 10
#define READING_INVALID 0
#define READING_VALID 1
#define FCB_I2C_BUS 7
#define FCB_CPLD_SLAVE_ADDR 0x7c
#define FCB_TMP468_ADDR 0x90
#define DIMM_HEAT_TURN_OFF 0
#define DIMM_HEAT_TURN_ON 1
#define COVER_PRE_HEAT_TEMP 20
#define DIMM_FAN_MIN_PWM 37
#define PTC_PRE_HEAT_MAX_PWM 80
#define PTC_PRE_HEAT_MIN_PWM 0
#define PTC_PRE_HEAT_PWM 80
#define PTC_HEAT_MAX_PWM 100
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFscFanReg;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFscHeatReg;
typedef struct
{
INT8U u8DIMMIndex;
char acDbusPath[256];
}__attribute__ ((packed))SDIMMDbus;
typedef enum
{
REG_FCB_CPLD_FAN_QUANTITY = 0x0006,
REG_FCB_GET_HEAT_COVER_STATUS = 0x0037,
REG_FCB_DIMM_INITIAL_PWM = 0x0051,
REG_FCB_DIMM0_SET_PWM = 0x0052,
REG_FCB_DIMM1_SET_PWM = 0x0053,
REG_FCB_DIMM2_SET_PWM = 0x0054,
REG_FCB_DIMM3_SET_PWM = 0x0055,
REG_FCB_DIMM4_SET_PWM = 0x0056,
REG_FCB_DIMM5_SET_PWM = 0x0057,
REG_FCB_DIMM6_SET_PWM = 0x0058,
REG_FCB_DIMM7_SET_PWM = 0x0059,
REG_FCB_DIMM8_SET_PWM = 0x005a,
REG_FCB_DIMM9_SET_PWM = 0x005b,
REG_FCB_DIMM10_SET_PWM = 0x005c,
REG_FCB_DIMM11_SET_PWM = 0x005d,
REG_FCB_DIMM12_SET_PWM = 0x005e,
REG_FCB_DIMM13_SET_PWM = 0x005f,
REG_FCB_DIMM14_SET_PWM = 0x0060,
REG_FCB_DIMM15_SET_PWM = 0x0061,
REG_FCB_DIMM16_SET_PWM = 0x0062,
REG_FCB_DIMM17_SET_PWM = 0x0063,
REG_FCB_DIMM18_SET_PWM = 0x0064,
REG_FCB_DIMM19_SET_PWM = 0x0065,
REG_FCB_DIMM20_SET_PWM = 0x0066,
REG_FCB_DIMM21_SET_PWM = 0x0067,
REG_FCB_DIMM22_SET_PWM = 0x0068,
REG_FCB_DIMM23_SET_PWM = 0x0069,
REG_FCB_PTC_INITIAL_PWM = 0x0075,
REG_FCB_PTC_DIMM23_SET_PWM = 0x0076,
REG_FCB_PTC_DIMM22_SET_PWM = 0x0077,
REG_FCB_PTC_DIMM21_SET_PWM = 0x0078,
REG_FCB_PTC_DIMM20_SET_PWM = 0x0079,
REG_FCB_PTC_DIMM19_SET_PWM = 0x007a,
REG_FCB_PTC_DIMM18_SET_PWM = 0x007b,
REG_FCB_PTC_DIMM17_SET_PWM = 0x007c,
REG_FCB_PTC_DIMM16_SET_PWM = 0x007d,
REG_FCB_PTC_DIMM15_SET_PWM = 0x007e,
REG_FCB_PTC_DIMM14_SET_PWM = 0x007f,
REG_FCB_PTC_DIMM13_SET_PWM = 0x0080,
REG_FCB_PTC_DIMM12_SET_PWM = 0x0081,
REG_FCB_PTC_DIMM11_SET_PWM = 0x0082,
REG_FCB_PTC_DIMM10_SET_PWM = 0x0083,
REG_FCB_PTC_DIMM9_SET_PWM = 0x0084,
REG_FCB_PTC_DIMM8_SET_PWM = 0x0085,
REG_FCB_PTC_DIMM7_SET_PWM = 0x0086,
REG_FCB_PTC_DIMM6_SET_PWM = 0x0087,
REG_FCB_PTC_DIMM5_SET_PWM = 0x0088,
REG_FCB_PTC_DIMM4_SET_PWM = 0x0089,
REG_FCB_PTC_DIMM3_SET_PWM = 0x008a,
REG_FCB_PTC_DIMM2_SET_PWM = 0x008b,
REG_FCB_PTC_DIMM1_SET_PWM = 0x008c,
REG_FCB_PTC_DIMM0_SET_PWM = 0x008d,
REG_FCB_SET_HEAT_COVER_STATUS = 0x008e,
}EUbbPriCPLDReg;
typedef enum
{
/*Power good status*/
PS_GOOD_FAIL=0,
PS_GOOD_OK,
/*Update flag */
FSC_FAN_TABLE_NORMAL = 0,
FSC_FAN_TABLE_UPDATE = 1,
/*Fan table load status flag */
FSC_FAN_TABLE_LOAD_FAIL = 0,
FSC_FAN_TABLE_LOAD_SUCCESS = 1,
/*Control mode*/
FSC_FAN_TABLE_AUTO = 0,
FSC_FAN_TABLE_MANUAL = 1,
/*Sensor present */
FSC_SENSOR_NOT_PRESENT = 0,
FSC_SENSOR_PRESENT = 1,
/*Sensor present */
FSC_SENSOR_NORMAL = 0,
FSC_SENSOR_ABNORMAL = 1,
/*Fan type */
FSC_FAN_TYPE_SINGLE = 0,
FSC_FAN_TYPE_TWIN = 1,
/*Fan status */
FSC_FAN_NORMAL = 0,
FSC_FAN_FAIL = 1,
/*Fsc work when dc off */
FSC_WORK_DC_ON_ONLY = 0,
FSC_WORK_DC_OFF = 1,
/*Fan fail handle type */
FSC_ABNORMAL_POLICY_UNUSED = 0,
FSC_ABNORMAL_POLICY_INCREASE = 1,
FSC_ABNORMAL_POLICY_CONSTANT = 2,
/*FSC normal or abnormal */
FSC_NORMAL = 0,
FSC_ABNORMAL = 1,
/*Thermal debug */
FSC_NO_THERMAL_DEBUG = 0,
FSC_OPEN_THERMAL_DEBUG = 1,
}EFscFlag;
typedef struct
{
char acProject[MAX_KEY_LENGTH];
char acCustomer[MAX_KEY_LENGTH];
char acVersion[MAX_KEY_LENGTH];
char acPlatform[MAX_KEY_LENGTH];
}__attribute__ ((packed))SFscHeader;
typedef struct
{
INT8U u8MaxReadingCache;
INT16U u16Elevation;
char acFanType[MAX_KEY_LENGTH];
char acWorkDCOff[MAX_KEY_LENGTH];
}__attribute__ ((packed))SFscGlobalConfig;
typedef struct
{
INT8U u8MaxPwmNum;
INT8U u8MaxFanNum;
INT8U u8FanSensorNumPWMMatch[MAX_FAN_COUNT];
INT8U u8MaxFanDuty;
INT8U u8MinFanDuty;
}__attribute__ ((packed))SFscFanConfig;
typedef struct
{
char acCLSensorType[MAX_KEY_LENGTH];
char acCLSensorStatus[MAX_KEY_LENGTH];
INT8U u8DT;
char acSensorName[MAX_SENSOR_NAME_LENGTH + 1];
INT8S s8VendorSpec;
INT8S s8CustomerSpec;
char acSetpointType[MAX_KEY_LENGTH];
INT8S s8SetpointDefault;
char acSetpointCase[MAX_SETPOINT_CASE][MAX_KEY_LENGTH];
INT8S as8SetpointValue[MAX_SETPOINT_CASE];
char acSetpointCaseUse[MAX_KEY_LENGTH];
INT8U au8FanWeight[MAX_FSC_PWM_CHANNEL];
INT8U u8Hysteresis;
INT8S as8EValue[MAX_SENSOR_E_SECTION-1];
INT8S as8ECValue[MAX_SENSOR_EC_SECTION-1];
float afPValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
float afIValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
float afDValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
INT8U u8SensorNumber;
INT8S s8Setpoint;
INT8S as8RealValue[MAX_READING_CACHE];
float fP;
float fI;
float fD;
INT8U u8SensorSDRPresent; /*sensor sdr present flag, 1 - present, 0 - not present*/
INT8U u8Present; /*sensor present flag, 1 - present, 0 - not present*/
INT8U u8Abnormal; /*sensor health flag, 1 - abnormal, 0 - normal*/
INT8U u8Health; /*sensor reading value status*/
INT8U u8NoReadingTries;
INT8U u8SensorStatus;
/* Event Flags description */
/* Bit 0 - Initialization Done */
/* Bit 1 - Update in Progress */
/* Bit 2 - reserved */
/* Bit 3 - reserved */
/* Bit 4 - reserved */
/* Bit 5 - Unable to read */
/* Bit 6 - Sensor Scanning disabled */
/* Bit 7 - Event Message Disabled */
INT32U u32CalculateTick;
INT8U u8PwmPIDCalculate;
INT16S s16LastPwmPIDCalculate;
float fPIncrement;
float fIIncrement;
float fDIncrement;
INT8U u8PwmAfterWeighting[MAX_FSC_PWM_CHANNEL];
INT8U u8PwmAfterWeightingCache[MAX_FSC_PWM_CHANNEL][MAX_FAN_AVERAGE_COUNT];
INT8U u8PwmAfterHysteresis[MAX_FSC_PWM_CHANNEL];
INT8U u8SensorNoReading;
}__attribute__ ((packed))SFscCLSensorInfo;
typedef struct
{
INT8U u8MaxCLSensor;
INT8U u8TotalCLSensor;
char acPIDAdjustMethod[MAX_KEY_LENGTH];
INT8U u8CLSensorESection;
INT8U u8CLSensorECSection;
INT8U u8CLSensorSetpointMaxCase;
SFscCLSensorInfo asFscCLSensorInfo[MAX_CL_SENSOR];
}__attribute__ ((packed))SFscCLSensor;
typedef struct
{
INT8U u8FanSensorNumberStart;
char acFanFailSingle[MAX_KEY_LENGTH];
INT8U u8FanFailTwin1;
INT8U u8FanFailTwin2Diff;
char acFanFailTwin2Same[MAX_KEY_LENGTH];
/*fan status: 0 - normal, 1 - abnormal */
INT8U au8FanStatus[MAX_FAN_COUNT];
INT8U au8FanFailPwm[MAX_FSC_PWM_CHANNEL];
INT8U au8FanFailConstantPwm;
INT8U u8FanFailHandleType;
}__attribute__ ((packed))SFscFanFail;
typedef struct
{
char acSensorName[MAX_SENSOR_NAME_LENGTH];
char acFailPolicy[MAX_KEY_LENGTH];
INT8U u8FailValue;
INT8U u8SensorFailHandleType;
INT8U u8SensorFailPwmOut;
}__attribute__ ((packed))SFscSensorFailInfo;
typedef struct
{
INT8U u8MaxAbnormalSensor;
INT8U u8TotalAbnormalSensor;
SFscFanFail sFscFanFail;
SFscSensorFailInfo asFscSensorFailInfo[MAX_ABNORMAL_SENSOR];
}__attribute__ ((packed))SFscAbnormalEvent;
typedef struct
{
INT8U u8UpdateFlag; /*1 - update, 0 - normal */
INT8U u8FanTableLoadStatus; /*1 - success, 0 - fail */
INT8U u8ControlMode; /*1 - manual, 0 - auto */
INT8U u8ThermalDebug; /*thermal debug falg, 0 - no debug, 1 - debuging */
INT8U u8WorkDCOff; /*1 - work when dc off, 0 - no work when dc off */
INT8U u8LoadTableTries;
INT32U u32Tick;
INT8U u8SKUID;
INT8U u8MaxOLPwm;
INT8U au8CLPwm[MAX_FSC_PWM_CHANNEL];
INT8U au8MaxAbnormalPwm;
INT8U au8MaxAbnormalIncreasePwm;
char acFactorSensorName[16];
INT8U u8FactorPwm;
INT8U u8FscStatus; /*0 - normal fsc, 1 - abnormal fsc */
INT8U au8PwmOut[MAX_FSC_PWM_CHANNEL];
INT8U au8ManualPwmOut[MAX_FSC_PWM_CHANNEL];
INT8U u8MaxCoverTemp;
}__attribute__ ((packed))SFscRunningInfo;
typedef struct
{
SFscHeader sFSCHeader;
SFscGlobalConfig sFscGlobalConfig;
SFscFanConfig sFscFanConfig;
SFscCLSensor sFscCLSensor;
SFscAbnormalEvent sFscAbnormalEvent;
SFscRunningInfo sFscRunningInfo;
}__attribute__ ((packed))SFscInfo;
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,712 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_base
*
* Description :
* base, include base typedef, base define, base enum
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/03/23 xxx 0.01 First draft
***********************************************************/
#ifndef __LUX_BASE_H__
#define __LUX_BASE_H__
/***********************************************************
*
* Base Include Zone
*
***********************************************************/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <semaphore.h>
#include <mqueue.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/route.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <dirent.h>
/***********************************************************
*
* Base Typedef Zone
*
***********************************************************/
typedef unsigned char INT8U;
typedef unsigned short INT16U;
typedef unsigned int INT32U;
typedef signed char INT8S;
typedef short INT16S;
typedef long INT32S;
/***********************************************************
*
* Base Define Zone
*
***********************************************************/
#define SHM_KEY "/LuxShare"
#define NV_SETTING_FILE "/conf/bmc.setting"
/*Queue Name Define*/
#define QUEUE_NAME_BLOCK0 "QueueBlock0"
#define QUEUE_NAME_BLOCK1 "QueueBlock1"
#define QUEUE_NAME_BLOCK2 "QueueBlock2"
#define QUEUE_NAME_REDIS_HANDLER "RedisHandler"
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define PRINT printf
#define SHOW_RUNNING PRINT("# %s Running ......\n", __FUNCTION__)
#define ERROR_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define NORMAL_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define WARN_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define DEBUG_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define LUX_SLEEP(Seconds, MSeconds) \
do{\
struct timeval TimeInterval;\
TimeInterval.tv_sec = Seconds;\
TimeInterval.tv_usec = MSeconds*1000;\
select(0, NULL, NULL, NULL, &TimeInterval);\
}while(0)
/***********************************************************
*
* Base Enum Zone
*
***********************************************************/
/*Common Code*/
typedef enum
{
DISABLE_STATE=0,
ENABLE_STATE=1,
INVALID_STATE=0,
VALID_STATE=1,
ABSENT_STATE=0,
PRESENT_STATE=1,
FALSE_STATE=0,
TRUE_STATE=1,
NO_STATE=0,
YES_STATE=1,
CABLE_PRESENT_ONLY=2,
}ECommonCode;
/*Function Return Code */
typedef enum
{
FUNC_FILE_OPEN_FAIL = -1,
FUNC_LIB_OPEN_FAIL = -1,
FUNC_FAIL_N1 = -1,
FUNC_OK=0,
FUNC_FAILED,
}EFuncRetCode;
/*EBits Define*/
typedef enum
{
BIT0=(1<<0),
BIT1=(1<<1),
BIT2=(1<<2),
BIT3=(1<<3),
BIT4=(1<<4),
BIT5=(1<<5),
BIT6=(1<<6),
BIT7=(1<<7),
BIT8=(1<<8),
BIT9=(1<<9),
BIT10=(1<<10),
BIT11=(1<<11),
BIT12=(1<<12),
BIT13=(1<<13),
BIT14=(1<<14),
BIT15=(1<<15),
BIT16=(1<<16),
BIT17=(1<<17),
BIT18=(1<<18),
BIT19=(1<<19),
BIT20=(1<<20),
BIT21=(1<<21),
BIT22=(1<<22),
BIT23=(1<<23),
BIT24=(1<<24),
BIT25=(1<<25),
BIT26=(1<<26),
BIT27=(1<<27),
BIT28=(1<<28),
BIT29=(1<<29),
BIT30=(1<<30),
BIT31=(1<<31),
BIT0_1=(BIT0|BIT1),
BIT0_2=(BIT0_1|BIT2),
BIT0_3=(BIT0_2|BIT3),
BIT0_4=(BIT0_3|BIT4),
BIT0_5=(BIT0_4|BIT5),
BIT0_6=(BIT0_5|BIT6),
BIT0_7=(BIT0_6|BIT7),
BIT0_8=(BIT0_7|BIT8),
BIT0_9=(BIT0_8|BIT9),
BIT0_10=(BIT0_9|BIT10),
BIT0_11=(BIT0_10|BIT11),
BIT0_12=(BIT0_11|BIT12),
BIT0_13=(BIT0_12|BIT13),
BIT0_14=(BIT0_13|BIT14),
BIT0_15=(BIT0_14|BIT15),
BIT0_16=(BIT0_15|BIT16),
BIT0_17=(BIT0_16|BIT17),
BIT0_18=(BIT0_17|BIT18),
BIT0_19=(BIT0_18|BIT19),
BIT0_20=(BIT0_19|BIT20),
BIT0_21=(BIT0_20|BIT21),
BIT0_22=(BIT0_21|BIT22),
BIT0_23=(BIT0_22|BIT23),
BIT0_24=(BIT0_23|BIT24),
BIT0_25=(BIT0_24|BIT25),
BIT0_26=(BIT0_25|BIT26),
BIT0_27=(BIT0_26|BIT27),
BIT0_28=(BIT0_27|BIT28),
BIT0_29=(BIT0_28|BIT29),
BIT0_30=(BIT0_29|BIT30),
BIT0_31=(BIT0_30|BIT31),
BIT1_2=(BIT1|BIT2),
BIT1_3=(BIT1_2|BIT3),
BIT1_4=(BIT1_3|BIT4),
BIT1_5=(BIT1_4|BIT5),
BIT1_6=(BIT1_5|BIT6),
BIT1_7=(BIT1_6|BIT7),
BIT1_8=(BIT1_7|BIT8),
BIT1_9=(BIT1_8|BIT9),
BIT1_10=(BIT1_9|BIT10),
BIT1_11=(BIT1_10|BIT11),
BIT1_12=(BIT1_11|BIT12),
BIT1_13=(BIT1_12|BIT13),
BIT1_14=(BIT1_13|BIT14),
BIT1_15=(BIT1_14|BIT15),
BIT1_16=(BIT1_15|BIT16),
BIT1_17=(BIT1_16|BIT17),
BIT1_18=(BIT1_17|BIT18),
BIT1_19=(BIT1_18|BIT19),
BIT1_20=(BIT1_19|BIT20),
BIT1_21=(BIT1_20|BIT21),
BIT1_22=(BIT1_21|BIT22),
BIT1_23=(BIT1_22|BIT23),
BIT1_24=(BIT1_23|BIT24),
BIT1_25=(BIT1_24|BIT25),
BIT1_26=(BIT1_25|BIT26),
BIT1_27=(BIT1_26|BIT27),
BIT1_28=(BIT1_27|BIT28),
BIT1_29=(BIT1_28|BIT29),
BIT1_30=(BIT1_29|BIT30),
BIT1_31=(BIT1_30|BIT31),
BIT2_3=(BIT2|BIT3),
BIT2_4=(BIT2_3|BIT4),
BIT2_5=(BIT2_4|BIT5),
BIT2_6=(BIT2_5|BIT6),
BIT2_7=(BIT2_6|BIT7),
BIT2_8=(BIT2_7|BIT8),
BIT2_9=(BIT2_8|BIT9),
BIT2_10=(BIT2_9|BIT10),
BIT2_11=(BIT2_10|BIT11),
BIT2_12=(BIT2_11|BIT12),
BIT2_13=(BIT2_12|BIT13),
BIT2_14=(BIT2_13|BIT14),
BIT2_15=(BIT2_14|BIT15),
BIT2_16=(BIT2_15|BIT16),
BIT2_17=(BIT2_16|BIT17),
BIT2_18=(BIT2_17|BIT18),
BIT2_19=(BIT2_18|BIT19),
BIT2_20=(BIT2_19|BIT20),
BIT2_21=(BIT2_20|BIT21),
BIT2_22=(BIT2_21|BIT22),
BIT2_23=(BIT2_22|BIT23),
BIT2_24=(BIT2_23|BIT24),
BIT2_25=(BIT2_24|BIT25),
BIT2_26=(BIT2_25|BIT26),
BIT2_27=(BIT2_26|BIT27),
BIT2_28=(BIT2_27|BIT28),
BIT2_29=(BIT2_28|BIT29),
BIT2_30=(BIT2_29|BIT30),
BIT2_31=(BIT2_30|BIT31),
BIT3_4=(BIT3|BIT4),
BIT3_5=(BIT3_4|BIT5),
BIT3_6=(BIT3_5|BIT6),
BIT3_7=(BIT3_6|BIT7),
BIT3_8=(BIT3_7|BIT8),
BIT3_9=(BIT3_8|BIT9),
BIT3_10=(BIT3_9|BIT10),
BIT3_11=(BIT3_10|BIT11),
BIT3_12=(BIT3_11|BIT12),
BIT3_13=(BIT3_12|BIT13),
BIT3_14=(BIT3_13|BIT14),
BIT3_15=(BIT3_14|BIT15),
BIT3_16=(BIT3_15|BIT16),
BIT3_17=(BIT3_16|BIT17),
BIT3_18=(BIT3_17|BIT18),
BIT3_19=(BIT3_18|BIT19),
BIT3_20=(BIT3_19|BIT20),
BIT3_21=(BIT3_20|BIT21),
BIT3_22=(BIT3_21|BIT22),
BIT3_23=(BIT3_22|BIT23),
BIT3_24=(BIT3_23|BIT24),
BIT3_25=(BIT3_24|BIT25),
BIT3_26=(BIT3_25|BIT26),
BIT3_27=(BIT3_26|BIT27),
BIT3_28=(BIT3_27|BIT28),
BIT3_29=(BIT3_28|BIT29),
BIT3_30=(BIT3_29|BIT30),
BIT3_31=(BIT3_30|BIT31),
BIT4_5=(BIT4|BIT5),
BIT4_6=(BIT4_5|BIT6),
BIT4_7=(BIT4_6|BIT7),
BIT4_8=(BIT4_7|BIT8),
BIT4_9=(BIT4_8|BIT9),
BIT4_10=(BIT4_9|BIT10),
BIT4_11=(BIT4_10|BIT11),
BIT4_12=(BIT4_11|BIT12),
BIT4_13=(BIT4_12|BIT13),
BIT4_14=(BIT4_13|BIT14),
BIT4_15=(BIT4_14|BIT15),
BIT4_16=(BIT4_15|BIT16),
BIT4_17=(BIT4_16|BIT17),
BIT4_18=(BIT4_17|BIT18),
BIT4_19=(BIT4_18|BIT19),
BIT4_20=(BIT4_19|BIT20),
BIT4_21=(BIT4_20|BIT21),
BIT4_22=(BIT4_21|BIT22),
BIT4_23=(BIT4_22|BIT23),
BIT4_24=(BIT4_23|BIT24),
BIT4_25=(BIT4_24|BIT25),
BIT4_26=(BIT4_25|BIT26),
BIT4_27=(BIT4_26|BIT27),
BIT4_28=(BIT4_27|BIT28),
BIT4_29=(BIT4_28|BIT29),
BIT4_30=(BIT4_29|BIT30),
BIT4_31=(BIT4_30|BIT31),
BIT5_6=(BIT5|BIT6),
BIT5_7=(BIT5_6|BIT7),
BIT5_8=(BIT5_7|BIT8),
BIT5_9=(BIT5_8|BIT9),
BIT5_10=(BIT5_9|BIT10),
BIT5_11=(BIT5_10|BIT11),
BIT5_12=(BIT5_11|BIT12),
BIT5_13=(BIT5_12|BIT13),
BIT5_14=(BIT5_13|BIT14),
BIT5_15=(BIT5_14|BIT15),
BIT5_16=(BIT5_15|BIT16),
BIT5_17=(BIT5_16|BIT17),
BIT5_18=(BIT5_17|BIT18),
BIT5_19=(BIT5_18|BIT19),
BIT5_20=(BIT5_19|BIT20),
BIT5_21=(BIT5_20|BIT21),
BIT5_22=(BIT5_21|BIT22),
BIT5_23=(BIT5_22|BIT23),
BIT5_24=(BIT5_23|BIT24),
BIT5_25=(BIT5_24|BIT25),
BIT5_26=(BIT5_25|BIT26),
BIT5_27=(BIT5_26|BIT27),
BIT5_28=(BIT5_27|BIT28),
BIT5_29=(BIT5_28|BIT29),
BIT5_30=(BIT5_29|BIT30),
BIT5_31=(BIT5_30|BIT31),
BIT6_7=(BIT6|BIT7),
BIT6_8=(BIT6_7|BIT8),
BIT6_9=(BIT6_8|BIT9),
BIT6_10=(BIT6_9|BIT10),
BIT6_11=(BIT6_10|BIT11),
BIT6_12=(BIT6_11|BIT12),
BIT6_13=(BIT6_12|BIT13),
BIT6_14=(BIT6_13|BIT14),
BIT6_15=(BIT6_14|BIT15),
BIT6_16=(BIT6_15|BIT16),
BIT6_17=(BIT6_16|BIT17),
BIT6_18=(BIT6_17|BIT18),
BIT6_19=(BIT6_18|BIT19),
BIT6_20=(BIT6_19|BIT20),
BIT6_21=(BIT6_20|BIT21),
BIT6_22=(BIT6_21|BIT22),
BIT6_23=(BIT6_22|BIT23),
BIT6_24=(BIT6_23|BIT24),
BIT6_25=(BIT6_24|BIT25),
BIT6_26=(BIT6_25|BIT26),
BIT6_27=(BIT6_26|BIT27),
BIT6_28=(BIT6_27|BIT28),
BIT6_29=(BIT6_28|BIT29),
BIT6_30=(BIT6_29|BIT30),
BIT6_31=(BIT6_30|BIT31),
BIT7_8=(BIT7|BIT8),
BIT7_9=(BIT7_8|BIT9),
BIT7_10=(BIT7_9|BIT10),
BIT7_11=(BIT7_10|BIT11),
BIT7_12=(BIT7_11|BIT12),
BIT7_13=(BIT7_12|BIT13),
BIT7_14=(BIT7_13|BIT14),
BIT7_15=(BIT7_14|BIT15),
BIT7_16=(BIT7_15|BIT16),
BIT7_17=(BIT7_16|BIT17),
BIT7_18=(BIT7_17|BIT18),
BIT7_19=(BIT7_18|BIT19),
BIT7_20=(BIT7_19|BIT20),
BIT7_21=(BIT7_20|BIT21),
BIT7_22=(BIT7_21|BIT22),
BIT7_23=(BIT7_22|BIT23),
BIT7_24=(BIT7_23|BIT24),
BIT7_25=(BIT7_24|BIT25),
BIT7_26=(BIT7_25|BIT26),
BIT7_27=(BIT7_26|BIT27),
BIT7_28=(BIT7_27|BIT28),
BIT7_29=(BIT7_28|BIT29),
BIT7_30=(BIT7_29|BIT30),
BIT7_31=(BIT7_30|BIT31),
BIT8_9=(BIT8|BIT9),
BIT8_10=(BIT8_9|BIT10),
BIT8_11=(BIT8_10|BIT11),
BIT8_12=(BIT8_11|BIT12),
BIT8_13=(BIT8_12|BIT13),
BIT8_14=(BIT8_13|BIT14),
BIT8_15=(BIT8_14|BIT15),
BIT8_16=(BIT8_15|BIT16),
BIT8_17=(BIT8_16|BIT17),
BIT8_18=(BIT8_17|BIT18),
BIT8_19=(BIT8_18|BIT19),
BIT8_20=(BIT8_19|BIT20),
BIT8_21=(BIT8_20|BIT21),
BIT8_22=(BIT8_21|BIT22),
BIT8_23=(BIT8_22|BIT23),
BIT8_24=(BIT8_23|BIT24),
BIT8_25=(BIT8_24|BIT25),
BIT8_26=(BIT8_25|BIT26),
BIT8_27=(BIT8_26|BIT27),
BIT8_28=(BIT8_27|BIT28),
BIT8_29=(BIT8_28|BIT29),
BIT8_30=(BIT8_29|BIT30),
BIT8_31=(BIT8_30|BIT31),
BIT9_10=(BIT9|BIT10),
BIT9_11=(BIT9_10|BIT11),
BIT9_12=(BIT9_11|BIT12),
BIT9_13=(BIT9_12|BIT13),
BIT9_14=(BIT9_13|BIT14),
BIT9_15=(BIT9_14|BIT15),
BIT9_16=(BIT9_15|BIT16),
BIT9_17=(BIT9_16|BIT17),
BIT9_18=(BIT9_17|BIT18),
BIT9_19=(BIT9_18|BIT19),
BIT9_20=(BIT9_19|BIT20),
BIT9_21=(BIT9_20|BIT21),
BIT9_22=(BIT9_21|BIT22),
BIT9_23=(BIT9_22|BIT23),
BIT9_24=(BIT9_23|BIT24),
BIT9_25=(BIT9_24|BIT25),
BIT9_26=(BIT9_25|BIT26),
BIT9_27=(BIT9_26|BIT27),
BIT9_28=(BIT9_27|BIT28),
BIT9_29=(BIT9_28|BIT29),
BIT9_30=(BIT9_29|BIT30),
BIT9_31=(BIT9_30|BIT31),
BIT10_11=(BIT10|BIT11),
BIT10_12=(BIT10_11|BIT12),
BIT10_13=(BIT10_12|BIT13),
BIT10_14=(BIT10_13|BIT14),
BIT10_15=(BIT10_14|BIT15),
BIT10_16=(BIT10_15|BIT16),
BIT10_17=(BIT10_16|BIT17),
BIT10_18=(BIT10_17|BIT18),
BIT10_19=(BIT10_18|BIT19),
BIT10_20=(BIT10_19|BIT20),
BIT10_21=(BIT10_20|BIT21),
BIT10_22=(BIT10_21|BIT22),
BIT10_23=(BIT10_22|BIT23),
BIT10_24=(BIT10_23|BIT24),
BIT10_25=(BIT10_24|BIT25),
BIT10_26=(BIT10_25|BIT26),
BIT10_27=(BIT10_26|BIT27),
BIT10_28=(BIT10_27|BIT28),
BIT10_29=(BIT10_28|BIT29),
BIT10_30=(BIT10_29|BIT30),
BIT10_31=(BIT10_30|BIT31),
BIT11_12=(BIT11|BIT12),
BIT11_13=(BIT11_12|BIT13),
BIT11_14=(BIT11_13|BIT14),
BIT11_15=(BIT11_14|BIT15),
BIT11_16=(BIT11_15|BIT16),
BIT11_17=(BIT11_16|BIT17),
BIT11_18=(BIT11_17|BIT18),
BIT11_19=(BIT11_18|BIT19),
BIT11_20=(BIT11_19|BIT20),
BIT11_21=(BIT11_20|BIT21),
BIT11_22=(BIT11_21|BIT22),
BIT11_23=(BIT11_22|BIT23),
BIT11_24=(BIT11_23|BIT24),
BIT11_25=(BIT11_24|BIT25),
BIT11_26=(BIT11_25|BIT26),
BIT11_27=(BIT11_26|BIT27),
BIT11_28=(BIT11_27|BIT28),
BIT11_29=(BIT11_28|BIT29),
BIT11_30=(BIT11_29|BIT30),
BIT11_31=(BIT11_30|BIT31),
BIT12_13=(BIT12|BIT13),
BIT12_14=(BIT12_13|BIT14),
BIT12_15=(BIT12_14|BIT15),
BIT12_16=(BIT12_15|BIT16),
BIT12_17=(BIT12_16|BIT17),
BIT12_18=(BIT12_17|BIT18),
BIT12_19=(BIT12_18|BIT19),
BIT12_20=(BIT12_19|BIT20),
BIT12_21=(BIT12_20|BIT21),
BIT12_22=(BIT12_21|BIT22),
BIT12_23=(BIT12_22|BIT23),
BIT12_24=(BIT12_23|BIT24),
BIT12_25=(BIT12_24|BIT25),
BIT12_26=(BIT12_25|BIT26),
BIT12_27=(BIT12_26|BIT27),
BIT12_28=(BIT12_27|BIT28),
BIT12_29=(BIT12_28|BIT29),
BIT12_30=(BIT12_29|BIT30),
BIT12_31=(BIT12_30|BIT31),
BIT13_14=(BIT13|BIT14),
BIT13_15=(BIT13_14|BIT15),
BIT13_16=(BIT13_15|BIT16),
BIT13_17=(BIT13_16|BIT17),
BIT13_18=(BIT13_17|BIT18),
BIT13_19=(BIT13_18|BIT19),
BIT13_20=(BIT13_19|BIT20),
BIT13_21=(BIT13_20|BIT21),
BIT13_22=(BIT13_21|BIT22),
BIT13_23=(BIT13_22|BIT23),
BIT13_24=(BIT13_23|BIT24),
BIT13_25=(BIT13_24|BIT25),
BIT13_26=(BIT13_25|BIT26),
BIT13_27=(BIT13_26|BIT27),
BIT13_28=(BIT13_27|BIT28),
BIT13_29=(BIT13_28|BIT29),
BIT13_30=(BIT13_29|BIT30),
BIT13_31=(BIT13_30|BIT31),
BIT14_15=(BIT14|BIT15),
BIT14_16=(BIT14_15|BIT16),
BIT14_17=(BIT14_16|BIT17),
BIT14_18=(BIT14_17|BIT18),
BIT14_19=(BIT14_18|BIT19),
BIT14_20=(BIT14_19|BIT20),
BIT14_21=(BIT14_20|BIT21),
BIT14_22=(BIT14_21|BIT22),
BIT14_23=(BIT14_22|BIT23),
BIT14_24=(BIT14_23|BIT24),
BIT14_25=(BIT14_24|BIT25),
BIT14_26=(BIT14_25|BIT26),
BIT14_27=(BIT14_26|BIT27),
BIT14_28=(BIT14_27|BIT28),
BIT14_29=(BIT14_28|BIT29),
BIT14_30=(BIT14_29|BIT30),
BIT14_31=(BIT14_30|BIT31),
BIT15_16=(BIT15|BIT16),
BIT15_17=(BIT15_16|BIT17),
BIT15_18=(BIT15_17|BIT18),
BIT15_19=(BIT15_18|BIT19),
BIT15_20=(BIT15_19|BIT20),
BIT15_21=(BIT15_20|BIT21),
BIT15_22=(BIT15_21|BIT22),
BIT15_23=(BIT15_22|BIT23),
BIT15_24=(BIT15_23|BIT24),
BIT15_25=(BIT15_24|BIT25),
BIT15_26=(BIT15_25|BIT26),
BIT15_27=(BIT15_26|BIT27),
BIT15_28=(BIT15_27|BIT28),
BIT15_29=(BIT15_28|BIT29),
BIT15_30=(BIT15_29|BIT30),
BIT15_31=(BIT15_30|BIT31),
BIT16_17=(BIT16|BIT17),
BIT16_18=(BIT16_17|BIT18),
BIT16_19=(BIT16_18|BIT19),
BIT16_20=(BIT16_19|BIT20),
BIT16_21=(BIT16_20|BIT21),
BIT16_22=(BIT16_21|BIT22),
BIT16_23=(BIT16_22|BIT23),
BIT16_24=(BIT16_23|BIT24),
BIT16_25=(BIT16_24|BIT25),
BIT16_26=(BIT16_25|BIT26),
BIT16_27=(BIT16_26|BIT27),
BIT16_28=(BIT16_27|BIT28),
BIT16_29=(BIT16_28|BIT29),
BIT16_30=(BIT16_29|BIT30),
BIT16_31=(BIT16_30|BIT31),
BIT17_18=(BIT17|BIT18),
BIT17_19=(BIT17_18|BIT19),
BIT17_20=(BIT17_19|BIT20),
BIT17_21=(BIT17_20|BIT21),
BIT17_22=(BIT17_21|BIT22),
BIT17_23=(BIT17_22|BIT23),
BIT17_24=(BIT17_23|BIT24),
BIT17_25=(BIT17_24|BIT25),
BIT17_26=(BIT17_25|BIT26),
BIT17_27=(BIT17_26|BIT27),
BIT17_28=(BIT17_27|BIT28),
BIT17_29=(BIT17_28|BIT29),
BIT17_30=(BIT17_29|BIT30),
BIT17_31=(BIT17_30|BIT31),
BIT18_19=(BIT18|BIT19),
BIT18_20=(BIT18_19|BIT20),
BIT18_21=(BIT18_20|BIT21),
BIT18_22=(BIT18_21|BIT22),
BIT18_23=(BIT18_22|BIT23),
BIT18_24=(BIT18_23|BIT24),
BIT18_25=(BIT18_24|BIT25),
BIT18_26=(BIT18_25|BIT26),
BIT18_27=(BIT18_26|BIT27),
BIT18_28=(BIT18_27|BIT28),
BIT18_29=(BIT18_28|BIT29),
BIT18_30=(BIT18_29|BIT30),
BIT18_31=(BIT18_30|BIT31),
BIT19_20=(BIT19|BIT20),
BIT19_21=(BIT19_20|BIT21),
BIT19_22=(BIT19_21|BIT22),
BIT19_23=(BIT19_22|BIT23),
BIT19_24=(BIT19_23|BIT24),
BIT19_25=(BIT19_24|BIT25),
BIT19_26=(BIT19_25|BIT26),
BIT19_27=(BIT19_26|BIT27),
BIT19_28=(BIT19_27|BIT28),
BIT19_29=(BIT19_28|BIT29),
BIT19_30=(BIT19_29|BIT30),
BIT19_31=(BIT19_30|BIT31),
BIT20_21=(BIT20|BIT21),
BIT20_22=(BIT20_21|BIT22),
BIT20_23=(BIT20_22|BIT23),
BIT20_24=(BIT20_23|BIT24),
BIT20_25=(BIT20_24|BIT25),
BIT20_26=(BIT20_25|BIT26),
BIT20_27=(BIT20_26|BIT27),
BIT20_28=(BIT20_27|BIT28),
BIT20_29=(BIT20_28|BIT29),
BIT20_30=(BIT20_29|BIT30),
BIT20_31=(BIT20_30|BIT31),
BIT21_22=(BIT21|BIT22),
BIT21_23=(BIT21_22|BIT23),
BIT21_24=(BIT21_23|BIT24),
BIT21_25=(BIT21_24|BIT25),
BIT21_26=(BIT21_25|BIT26),
BIT21_27=(BIT21_26|BIT27),
BIT21_28=(BIT21_27|BIT28),
BIT21_29=(BIT21_28|BIT29),
BIT21_30=(BIT21_29|BIT30),
BIT21_31=(BIT21_30|BIT31),
BIT22_23=(BIT22|BIT23),
BIT22_24=(BIT22_23|BIT24),
BIT22_25=(BIT22_24|BIT25),
BIT22_26=(BIT22_25|BIT26),
BIT22_27=(BIT22_26|BIT27),
BIT22_28=(BIT22_27|BIT28),
BIT22_29=(BIT22_28|BIT29),
BIT22_30=(BIT22_29|BIT30),
BIT22_31=(BIT22_30|BIT31),
BIT23_24=(BIT23|BIT24),
BIT23_25=(BIT23_24|BIT25),
BIT23_26=(BIT23_25|BIT26),
BIT23_27=(BIT23_26|BIT27),
BIT23_28=(BIT23_27|BIT28),
BIT23_29=(BIT23_28|BIT29),
BIT23_30=(BIT23_29|BIT30),
BIT23_31=(BIT23_30|BIT31),
BIT24_25=(BIT24|BIT25),
BIT24_26=(BIT24_25|BIT26),
BIT24_27=(BIT24_26|BIT27),
BIT24_28=(BIT24_27|BIT28),
BIT24_29=(BIT24_28|BIT29),
BIT24_30=(BIT24_29|BIT30),
BIT24_31=(BIT24_30|BIT31),
BIT25_26=(BIT25|BIT26),
BIT25_27=(BIT25_26|BIT27),
BIT25_28=(BIT25_27|BIT28),
BIT25_29=(BIT25_28|BIT29),
BIT25_30=(BIT25_29|BIT30),
BIT25_31=(BIT25_30|BIT31),
BIT26_27=(BIT26|BIT27),
BIT26_28=(BIT26_27|BIT28),
BIT26_29=(BIT26_28|BIT29),
BIT26_30=(BIT26_29|BIT30),
BIT26_31=(BIT26_30|BIT31),
BIT27_28=(BIT27|BIT28),
BIT27_29=(BIT27_28|BIT29),
BIT27_30=(BIT27_29|BIT30),
BIT27_31=(BIT27_30|BIT31),
BIT28_29=(BIT28|BIT29),
BIT28_30=(BIT28_29|BIT30),
BIT28_31=(BIT28_30|BIT31),
BIT29_30=(BIT29|BIT30),
BIT29_31=(BIT29_30|BIT31),
BIT30_31=(BIT30|BIT31),
}EBits;
#endif
@@ -0,0 +1,913 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_json_api
*
* Description :
* JSON API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/04/21 Laurence Zhou 0.01 First draft
***********************************************************/
#include "lux_json_api.h"
/***********************************************************
* Name:
* LuxcJSONParseJsonFile
*
* Summary:
* parse JSON file to get the HEAD pointer(note: remeber to call Luxcjsondelete() to free memory)
*
* Return Value:
* The LuxcJSONParseJsonFile() function returns a HEAD pointer to HEAD node of the Doubly Linked List
*
* Parameter Input:
* char* pcFileName -- JSON file name with Absolute path
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
cJSON* LuxcJSONParseJsonFile(char* pcFileName)
{
long lLen = 0;
char* psBuf = NULL;
cJSON* psRoot = NULL;
if(NULL == pcFileName)
{
return NULL;
}
FILE* fp = LuxFopen(pcFileName, "rb+");
if (NULL == fp)
{
printf("open file %s failed.\n", pcFileName);
return NULL;
}
LuxFseek(fp, 0, SEEK_END);
lLen = LuxFtell(fp);
if (0 == lLen)
{
return NULL;
}
LuxFseek(fp, 0, SEEK_SET);
psBuf = (char *)LuxMalloc(sizeof(char) * lLen);
LuxFread(psBuf, 1, lLen, fp);
LuxFclose(fp);
cJSON_Minify(psBuf);
psRoot = cJSON_Parse(psBuf);
if (NULL == psRoot)
{
return NULL;
}
LuxFree(psBuf);
return psRoot;
}
/***********************************************************
* Name:
* LuxcJSONPrint
*
* Summary:
* Render a cJSON entity to text for transfer/storage(note: remeber to call Luxcjsonfree to free memory)
*
* Return Value:
* a string
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxcJSONPrint(const cJSON* psItem)
{
if(NULL != psItem)
{
return cJSON_Print(psItem);
}
return NULL;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectItem
*
* Summary:
* Get item "pcKey" from psObject
*
* Return Value:
* Pointer to the "pcKey" cJSON node
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
**********************************************************/
cJSON* LuxcJSONGetObjectItem(const cJSON* const psObject, const char* const pcKey)
{
if(NULL == psObject)
{
return NULL;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return NULL;
}
if(NULL == pcKey)
{
return NULL;
}
cJSON* psTemp = NULL;
psTemp = cJSON_GetObjectItem(psObject, pcKey);
if (psTemp)
{
return psTemp;
}
else
{
return NULL;
}
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntValue
*
* Summary:
* Get int value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piValue -- Pointer that holds the int value
*
* Parameter Output:
* piVAlue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntValue(const cJSON* const psObject, const char* const pcKey,int* piValue )
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piValue)
{
return FUNC_FAILED;
}
if( NULL == (psItem = (cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
*piValue = psItem->valueint;
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleValue
*
* Summary:
* Get double value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double* pdValue -- Pointer that holds the double value
*
* Parameter Output:
* pdValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleValue(const cJSON* const psObject,const char* const pcKey, double* pdValue)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pdValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem = (cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
*pdValue = psItem->valuedouble;
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringSize
*
* Summary:
* Get the length of String
*
* Return Value:
* length of String
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetOjectStringSize(const cJSON* const psObject, const char* const pcKey, int *piSize)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
psItem = cJSON_GetObjectItem(psObject, pcKey);
*piSize = LuxStrlen(psItem->valuestring);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringValue
*
* Summary:
* Get string value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* char* pcValue -- Pointer that holds the String value
*
* Parameter Output:
* pcValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectStringValue(const cJSON* const psObject, const char* const pcKey, char* pcValue )
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pcValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem=(cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
LuxStrcpy(pcValue,psItem->valuestring);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectBooleanValue
*
* Summary:
* Get boolean value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* cJSON_bool* pbValue -- Pointer that holds the boolean value
*
* Parameter Output:
* pbValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectBooleanValue(const cJSON* const psObject, const char* const pcKey, cJSON_bool* pbValue)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pbValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
if(false == psItem->valueint)
{
*pbValue = false;
return FUNC_OK;
}
else
{
*pbValue = true;
return FUNC_OK;
}
}
/***********************************************************
* Name:
* LuxcJSONGetObjectArraySize
*
* Summary:
* Get the array size
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectArraySize(const cJSON* const psObject, const char* const pcKey, int* piSize)
{
cJSON* psArray = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
*piSize = cJSON_GetArraySize(psArray);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntArray
*
* Summary:
* Get the int array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piArray -- Pointer that holds the int array(if pass NULL to piArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* piArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntArray(const cJSON* const psObject, const char* const pcKey, int* piArray,int* piSize)
{
cJSON *psArray = NULL;
cJSON *psTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == piArray )
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0,j = 0; i < *piSize && j < *piSize; ++i,++j)
{
psTemp = cJSON_GetArrayItem(psArray, i);
piArray[j] = psTemp->valueint;
psTemp = NULL;
}
psArray = NULL;
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleArray
*
* Summary:
* Get the double array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double* piArray -- Pointer that holds the double array(if pass NULL to pdArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* pdArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleArray(const cJSON* const psObject, const char* const pcKey, double* pdArray, int* piSize )
{
cJSON *psArray = NULL;
cJSON *psTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == pdArray)
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0,j = 0; i < *piSize && j < *piSize; ++i,++j)
{
psTemp = cJSON_GetArrayItem(psArray, i);
pdArray[j] = psTemp->valuedouble;
psTemp = NULL;
}
psArray = NULL;
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringArray
*
* Summary:
* Get the string array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* char (*pcArray)[MAXSIZE] -- Pointer that holds the string array(if pass NULL to pcArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* pcArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectStringArray(const cJSON* const psObject, const char* const pcKey, char (*pcArray)[MAXSIZE],int* piSize)
{
cJSON* pscJSONStringArray = NULL;
cJSON* pscJSONStringTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == pcArray)
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (pscJSONStringArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piSize; ++i)
{
pscJSONStringTemp = cJSON_GetArrayItem(pscJSONStringArray, i);
LuxStrcpy(pcArray[i],pscJSONStringTemp->valuestring);
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetArrayRowColumnSize
*
* Summary:
* Get the two-dimensional array's row and column
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetArrayRowColumnSize(const cJSON* const psObject, const char* const pcKey,int* piRow,int* piColumn)
{
cJSON* psArray =NULL;
cJSON *psArray21 = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
*piRow = cJSON_GetArraySize(psArray);
if(NULL == (psArray21 = cJSON_GetArrayItem(psArray, 0)))
{
return FUNC_FAILED;
}
*piColumn = cJSON_GetArraySize(psArray21);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntArray2
*
* Summary:
* Get the two-dimensional array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int (*piArray2)[MAXSIZE] -- Pointer that holds the two-dimensional arrray
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* piArray2,piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntArray2(const cJSON* const psObject, const char* const pcKey, int (*piArray2)[MAXSIZE],int* piRow, int* piColumn)
{
cJSON *psArray = NULL;
cJSON *psArrayTemp = NULL;
cJSON *psValueTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == piArray2)
{
if(FUNC_OK == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piRow; ++i )
{
psArrayTemp = cJSON_GetArrayItem(psArray, i);
for(int j = 0; j < *piColumn; ++j){
psValueTemp = cJSON_GetArrayItem(psArrayTemp, j);
piArray2[i][j] = psValueTemp->valueint;
psValueTemp= NULL;
}
psArrayTemp = NULL;
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleArray2
*
* Summary:
* Get the two-dimensional array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double (*piArray2)[MAXSIZE] -- Pointer that holds the two-dimensional arrray
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* pdArray2,piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleArray2(const cJSON* const psObject, const char* const pcKey, double (*pdArray2)[MAXSIZE],int* piRow, int* piColumn)
{
cJSON *psArray = NULL;
cJSON *psArrayTemp = NULL;
cJSON *PsValueTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == pdArray2)
{
if(FUNC_OK == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piRow; ++i )
{
psArrayTemp = cJSON_GetArrayItem(psArray, i);
for(int j = 0; j < *piColumn; ++j)
{
PsValueTemp = cJSON_GetArrayItem(psArrayTemp, j);
pdArray2[i][j] = PsValueTemp->valuedouble;
PsValueTemp = NULL;
}
psArrayTemp = NULL;
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONDelete
*
* Summary:
* Delete a cJSON entity and all subentities
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* cJSON* psItem -- the HEAD pointer
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONDelete(cJSON* psItem)
{
if(NULL != psItem)
{
cJSON_Delete(psItem);
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONFree
*
* Summary:
* free object
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* cJSON* psItem -- the HEAD pointer
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONFree(void* psObject)
{
if(NULL != psObject)
{
cJSON_free(psObject);
}
return FUNC_OK;
}
@@ -0,0 +1,56 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : LuxcJSON
*
* Description :
* JSON API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/04/21 Laurence Zhou 0.01 First draft
***********************************************************/
#ifndef LUX_JSON_API_H
#define LUX_JSON_API_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
#include "lux_system_api.h"
#define MAXSIZE 128
#ifdef true
#undef true
#endif
#define true ((cJSON_bool)1)
#ifdef false
#undef false
#endif
#define false ((cJSON_bool)0)
extern cJSON* LuxcJSONParseJsonFile(char* pcFileName);
extern char* LuxcJSONPrint(const cJSON* psItem);
extern cJSON* LuxcJSONGetObjectItem(const cJSON* const psObject, const char* const pcKey);
extern EFuncRetCode LuxcJSONGetObjectIntValue(const cJSON* const psObject, const char* const pcKey,int* piValue );
extern EFuncRetCode LuxcJSONGetObjectDoubleValue(const cJSON* const psObject,const char* const pcKey, double* pdValue);
extern EFuncRetCode LuxcJSONGetObjectStringValue(const cJSON* const psObject, const char* const pcKey, char* pcValue );
extern EFuncRetCode LuxcJSONGetObjectBooleanValue(const cJSON* const psObject, const char* const pcKey, cJSON_bool* pbValue);
extern EFuncRetCode LuxcJSONGetObjectArraySize(const cJSON* const psObject, const char* const pcKey, int* piSize);
extern EFuncRetCode LuxcJSONGetObjectIntArray(const cJSON* const psObject, const char* const pcKey, int* piArray,int* piSize);
extern EFuncRetCode LuxcJSONGetObjectDoubleArray(const cJSON* const psObject, const char* const pcKey, double* pdArray, int* piSize );
extern EFuncRetCode LuxcJSONGetObjectStringArray(const cJSON* const psObject, const char* const pcKey, char (*pcArray)[MAXSIZE],int* piSize);
extern EFuncRetCode LuxcJSONGetObjectIntArray2(const cJSON* const psObject, const char* const pcKey, int (*piArray2)[MAXSIZE],int* piRow, int* piColumn);
extern EFuncRetCode LuxcJSONGetObjectDoubleArray2(const cJSON* const psObject, const char* const pcKey, double (*pdArray2)[MAXSIZE],int* piRow, int* piColumn);
extern EFuncRetCode LuxcJSONDelete(cJSON* psItem);
extern EFuncRetCode LuxcJSONFree(void* psObject);
EFuncRetCode LuxcJSONGetOjectStringSize(const cJSON* const psObject, const char* const pcKey, int *piSize);
extern EFuncRetCode LuxcJSONGetArrayRowColumnSize(const cJSON* const psObject, const char* const pcKey, int* piRow,int* piColumn);
#endif /* LUX_JSON_API_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,123 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_system_api
*
* Description :
* system or C API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/03/23 chin 0.01 First draft
* 2021/4/25 huangliang 0.02 add system calls
***********************************************************/
#ifndef __LUX_SYSTEM_API_H__
#define __LUX_SYSTEM_API_H__
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include "lux_base.h"
#include <unistd.h>
#include <arpa/inet.h>
#include <regex.h>
#include <netdb.h> /* gethostbyname() */
#define F_OK 0
extern void* LuxMmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
extern int LuxMunmap(void *addr, size_t length);
extern int LuxMsync(void *addr, size_t length, int flags);
extern void* LuxMemset(void* pStr, int iValue, size_t szCount);
extern EFuncRetCode LuxMemsetSafe(void* pDestStr, size_t szSize, int iValue, size_t szCount);
extern void* LuxMemcpy(void* pDst, const void* pSrc, size_t szCount);
extern EFuncRetCode LuxMemcpySafe(void* pDst, size_t szSize, const void* pSrc, size_t szCount);
extern int LuxMemcmp(const void* pBuf1,const void* pBuf2,size_t szCount);
extern char* LuxStrcpy(char* pcDestStr, const char* pcScrStr);
extern char* LuxStrncpy(char* pcDestStr, const char* pcScrStr, size_t szCount);
extern int LuxStrcmp(const char* pcStr1, const char* pcStr2);
extern int LuxStrncmp(const char* pcStr1, const char* pcStr2, size_t szCount);
extern size_t LuxStrlen(const char* pcStr);
extern size_t LuxStrnlen(const char* pcStr, size_t szLen);
extern char* LuxStrcat(char* pcDestStr, const char* pcSrcStr);
extern char* LuxStrncat(char* pcDest, const char* pcSrc, size_t szCount);
extern char* LuxStrstr(char* pcDestStr, const char* pcSrcStr);
extern int LuxPrintf(const char* fmt,...);
extern int LuxFprintf(FILE* fp, char* fmt, ...);
extern int LuxDprintf(int fd, const char *fmt, ...);
extern int LuxSprintf(char* pcBuf, const char* fmt, ...);
extern int LuxSnprintf(char* pcBuf, size_t szSize, const char* fmt, ...);
extern int LuxSscanf(const char* pcBuf, const char* fmt, ...);
extern int LuxScanf(const char* fmt, ...);
extern int LuxFscanf(FILE* stream, const char* fmt, ...);
extern int LuxOpenAndCreat(const char* pcPathname,int iFlags,mode_t mode);
extern int LuxOpen(const char* pcPathname,int iFlags);
extern int LuxClose(int fd);
extern ssize_t LuxRead(int fd, void* pBuf, size_t szCount);
extern ssize_t LuxWrite(int fd, void* pBuf, size_t szCount);
extern off_t LuxLseek(int fd, off_t offset, int iWhence);
extern FILE* LuxFopen(const char* pcPathname, const char* pcMode);
extern int LuxFclose(FILE* stream);
extern size_t LuxFread(void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern size_t LuxFwrite(const void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern int LuxFseek(FILE *stream, long offset, int iWhence);
extern long LuxFtell(FILE* stream);
extern void LuxRewind(FILE* stream);
extern EFuncRetCode LuxSystem(char* pcCmdStr);
extern FILE* LuxPopen(const char* pcCmdStr, const char* pcType);
extern int LuxPclose(FILE* stream);
extern void* LuxDlopen(const char* pcFilename, int iFlags);
extern int LuxDlclose(void* pDlhandle);
extern void* LuxDlsym(void* pDlhandle, const char* pcSymbol);
extern char* LuxDlerror(void);
extern time_t LuxTime(time_t* timep);
extern char* LuxCtime(const time_t* timep);
extern char* LuxAsctime(const struct tm* tm);
extern struct tm* LuxGmtime(const time_t* timep);
extern struct tm* LuxLocaltime(const time_t* timep);
extern time_t LuxMktime(struct tm* tm);
extern void* LuxMalloc(size_t size);
extern void* LuxCalloc(size_t nmemb, size_t size);
extern void* LuxRealloc(void* ptr, size_t size);
extern void LuxFree(void* ptr);
extern void* LuxMemchr(const void* pStr, int iCharacter, size_t szCount);
extern char* LuxStrchr(const char* pcStr, int iCharacter);
extern char* LuxStrtok(char* pcStr, const char* pcDelim);
extern int LuxFeof(FILE* stream);
extern int LuxFflush(FILE* stream);
extern int LuxRemove(const char* pcFilename);
extern int LuxRename(const char* pcOldFilename, const char* pcNewFilename);
extern int LuxRand(void);
extern void LuxSrand(unsigned int iSeed);
extern int LuxAccess(const char* pcPathName,int mode);
extern int LuxClosedir(DIR* psDir);
extern struct dirent* LuxReaddir(DIR* psDir);
extern int LuxChdir(const char* pcPathName);
extern int LuxRmdir(const char* pcPathname);
extern int LuxChmod(const char* pcFilename,mode_t mode);
extern int LuxMkdir(const char* pcPathName,mode_t mode);
extern int LuxClockgettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int LuxClocksettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int LuxFgetc(FILE *pstream);
extern int LuxFputc(int chara, FILE *pstream);
extern int LuxFerror(FILE *pstream);
extern DIR* LuxOpendir(const char *pcdirname);
extern const char* LuxInetNtop(int af, const void* psrc, char* pcDst, size_t size);
extern int LuxInetPton(int af, const char *pcSrc, void *pDst);
extern char* LuxInetNtoa(struct in_addr in);
extern int LuxSocket(int domain, int type, int protocol);
extern int LuxIoctl(int fd, unsigned long request, ...);
extern void LuxReboot(int iFlag);
extern int LuxRegcomp(regex_t *compiled, const char *pattern, int cflags);
extern int LuxRegexec(regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr[], int eflags);
extern void LuxRegfree(regex_t *compiled);
extern int LuxGetaddrinfo( const char *hostname, const char *service, const struct addrinfo *hints, struct addrinfo **result );
extern int LuxAtoi(const char* paddr);
#endif
@@ -0,0 +1,21 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
LICENSE = "CLOSED"
SRC_URI += " \
file://cJSON.c \
file://cJSON.h \
file://lux_json_api.c \
file://lux_json_api.h \
file://lux_system_api.c \
file://lux_system_api.h \
file://pre_heat.c \
file://pre_heat.h \
file://lux_base.h \
file://pre_heat.json \
file://pre-heat.sh \
file://CMakeLists.txt "
S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"
DEPENDS += "systemd dbus"
inherit pkgconfig cmake obmc-phosphor-systemd
SYSTEMD_SERVICE:${PN} = " pre-heat.service "
@@ -0,0 +1,19 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
inherit obmc-phosphor-systemd
SRC_URI += "file://pre-heat.service \
file://pre-heat.sh \
"
SYSTEMD_SERVICE_${PN} = "pre-heat.service"
do_install:append() {
# deal with systemd unit files
install -d ${D}${systemd_unitdir}/system
install -m 0755 ${WORKDIR}/pre-heat.sh ${D}${bindir}/pre-heat.sh
install -m 0644 ${WORKDIR}/pre-heat.service ${D}${systemd_unitdir}/system
}
FILES_${PN} += "${systemd_unitdir}/system/pre-heat.service"
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.15)
project(pre_heat)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
pkg_check_modules(DBUS REQUIRED dbus-1)
aux_source_directory(. SRC)
add_executable(${CMAKE_PROJECT_NAME} ${SRC})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${DBUS_LIBRARIES})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${DBUS_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${SYSTEMD_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE /usr/include)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${SYSTEMD_LIBRARIES})
install(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES pre_heat.json DESTINATION bin)
install(FILES pre-heat.sh DESTINATION bin)
@@ -0,0 +1,13 @@
CFLAGS += -Wall
OBJS = pre_heat.o cJSON.o lux_json_api.o lux_system_api.o
EXE = pre_heat
.c.o:
$(CC) -c $<
$(EXE): $(OBJS)
$(CC) $(OBJS) -o $@
all:$(EXE)
clean:
rm -f $(EXE) $(OBJS)
install:
cp $(EXE) $(INSTALL_DIR)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,292 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
pPermission 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.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 14
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,712 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_base
*
* Description :
* base, include base typedef, base define, base enum
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/03/23 xxx 0.01 First draft
***********************************************************/
#ifndef __LUX_BASE_H__
#define __LUX_BASE_H__
/***********************************************************
*
* Base Include Zone
*
***********************************************************/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <semaphore.h>
#include <mqueue.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/route.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <dirent.h>
/***********************************************************
*
* Base Typedef Zone
*
***********************************************************/
typedef unsigned char INT8U;
typedef unsigned short INT16U;
typedef unsigned int INT32U;
typedef signed char INT8S;
typedef short INT16S;
typedef long INT32S;
/***********************************************************
*
* Base Define Zone
*
***********************************************************/
#define SHM_KEY "/LuxShare"
#define NV_SETTING_FILE "/conf/bmc.setting"
/*Queue Name Define*/
#define QUEUE_NAME_BLOCK0 "QueueBlock0"
#define QUEUE_NAME_BLOCK1 "QueueBlock1"
#define QUEUE_NAME_BLOCK2 "QueueBlock2"
#define QUEUE_NAME_REDIS_HANDLER "RedisHandler"
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define PRINT printf
#define SHOW_RUNNING PRINT("# %s Running ......\n", __FUNCTION__)
#define ERROR_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define NORMAL_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define WARN_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define DEBUG_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define LUX_SLEEP(Seconds, MSeconds) \
do{\
struct timeval TimeInterval;\
TimeInterval.tv_sec = Seconds;\
TimeInterval.tv_usec = MSeconds*1000;\
select(0, NULL, NULL, NULL, &TimeInterval);\
}while(0)
/***********************************************************
*
* Base Enum Zone
*
***********************************************************/
/*Common Code*/
typedef enum
{
DISABLE_STATE=0,
ENABLE_STATE=1,
INVALID_STATE=0,
VALID_STATE=1,
ABSENT_STATE=0,
PRESENT_STATE=1,
FALSE_STATE=0,
TRUE_STATE=1,
NO_STATE=0,
YES_STATE=1,
CABLE_PRESENT_ONLY=2,
}ECommonCode;
/*Function Return Code */
typedef enum
{
FUNC_FILE_OPEN_FAIL = -1,
FUNC_LIB_OPEN_FAIL = -1,
FUNC_FAIL_N1 = -1,
FUNC_OK=0,
FUNC_FAILED,
}EFuncRetCode;
/*EBits Define*/
typedef enum
{
BIT0=(1<<0),
BIT1=(1<<1),
BIT2=(1<<2),
BIT3=(1<<3),
BIT4=(1<<4),
BIT5=(1<<5),
BIT6=(1<<6),
BIT7=(1<<7),
BIT8=(1<<8),
BIT9=(1<<9),
BIT10=(1<<10),
BIT11=(1<<11),
BIT12=(1<<12),
BIT13=(1<<13),
BIT14=(1<<14),
BIT15=(1<<15),
BIT16=(1<<16),
BIT17=(1<<17),
BIT18=(1<<18),
BIT19=(1<<19),
BIT20=(1<<20),
BIT21=(1<<21),
BIT22=(1<<22),
BIT23=(1<<23),
BIT24=(1<<24),
BIT25=(1<<25),
BIT26=(1<<26),
BIT27=(1<<27),
BIT28=(1<<28),
BIT29=(1<<29),
BIT30=(1<<30),
BIT31=(1<<31),
BIT0_1=(BIT0|BIT1),
BIT0_2=(BIT0_1|BIT2),
BIT0_3=(BIT0_2|BIT3),
BIT0_4=(BIT0_3|BIT4),
BIT0_5=(BIT0_4|BIT5),
BIT0_6=(BIT0_5|BIT6),
BIT0_7=(BIT0_6|BIT7),
BIT0_8=(BIT0_7|BIT8),
BIT0_9=(BIT0_8|BIT9),
BIT0_10=(BIT0_9|BIT10),
BIT0_11=(BIT0_10|BIT11),
BIT0_12=(BIT0_11|BIT12),
BIT0_13=(BIT0_12|BIT13),
BIT0_14=(BIT0_13|BIT14),
BIT0_15=(BIT0_14|BIT15),
BIT0_16=(BIT0_15|BIT16),
BIT0_17=(BIT0_16|BIT17),
BIT0_18=(BIT0_17|BIT18),
BIT0_19=(BIT0_18|BIT19),
BIT0_20=(BIT0_19|BIT20),
BIT0_21=(BIT0_20|BIT21),
BIT0_22=(BIT0_21|BIT22),
BIT0_23=(BIT0_22|BIT23),
BIT0_24=(BIT0_23|BIT24),
BIT0_25=(BIT0_24|BIT25),
BIT0_26=(BIT0_25|BIT26),
BIT0_27=(BIT0_26|BIT27),
BIT0_28=(BIT0_27|BIT28),
BIT0_29=(BIT0_28|BIT29),
BIT0_30=(BIT0_29|BIT30),
BIT0_31=(BIT0_30|BIT31),
BIT1_2=(BIT1|BIT2),
BIT1_3=(BIT1_2|BIT3),
BIT1_4=(BIT1_3|BIT4),
BIT1_5=(BIT1_4|BIT5),
BIT1_6=(BIT1_5|BIT6),
BIT1_7=(BIT1_6|BIT7),
BIT1_8=(BIT1_7|BIT8),
BIT1_9=(BIT1_8|BIT9),
BIT1_10=(BIT1_9|BIT10),
BIT1_11=(BIT1_10|BIT11),
BIT1_12=(BIT1_11|BIT12),
BIT1_13=(BIT1_12|BIT13),
BIT1_14=(BIT1_13|BIT14),
BIT1_15=(BIT1_14|BIT15),
BIT1_16=(BIT1_15|BIT16),
BIT1_17=(BIT1_16|BIT17),
BIT1_18=(BIT1_17|BIT18),
BIT1_19=(BIT1_18|BIT19),
BIT1_20=(BIT1_19|BIT20),
BIT1_21=(BIT1_20|BIT21),
BIT1_22=(BIT1_21|BIT22),
BIT1_23=(BIT1_22|BIT23),
BIT1_24=(BIT1_23|BIT24),
BIT1_25=(BIT1_24|BIT25),
BIT1_26=(BIT1_25|BIT26),
BIT1_27=(BIT1_26|BIT27),
BIT1_28=(BIT1_27|BIT28),
BIT1_29=(BIT1_28|BIT29),
BIT1_30=(BIT1_29|BIT30),
BIT1_31=(BIT1_30|BIT31),
BIT2_3=(BIT2|BIT3),
BIT2_4=(BIT2_3|BIT4),
BIT2_5=(BIT2_4|BIT5),
BIT2_6=(BIT2_5|BIT6),
BIT2_7=(BIT2_6|BIT7),
BIT2_8=(BIT2_7|BIT8),
BIT2_9=(BIT2_8|BIT9),
BIT2_10=(BIT2_9|BIT10),
BIT2_11=(BIT2_10|BIT11),
BIT2_12=(BIT2_11|BIT12),
BIT2_13=(BIT2_12|BIT13),
BIT2_14=(BIT2_13|BIT14),
BIT2_15=(BIT2_14|BIT15),
BIT2_16=(BIT2_15|BIT16),
BIT2_17=(BIT2_16|BIT17),
BIT2_18=(BIT2_17|BIT18),
BIT2_19=(BIT2_18|BIT19),
BIT2_20=(BIT2_19|BIT20),
BIT2_21=(BIT2_20|BIT21),
BIT2_22=(BIT2_21|BIT22),
BIT2_23=(BIT2_22|BIT23),
BIT2_24=(BIT2_23|BIT24),
BIT2_25=(BIT2_24|BIT25),
BIT2_26=(BIT2_25|BIT26),
BIT2_27=(BIT2_26|BIT27),
BIT2_28=(BIT2_27|BIT28),
BIT2_29=(BIT2_28|BIT29),
BIT2_30=(BIT2_29|BIT30),
BIT2_31=(BIT2_30|BIT31),
BIT3_4=(BIT3|BIT4),
BIT3_5=(BIT3_4|BIT5),
BIT3_6=(BIT3_5|BIT6),
BIT3_7=(BIT3_6|BIT7),
BIT3_8=(BIT3_7|BIT8),
BIT3_9=(BIT3_8|BIT9),
BIT3_10=(BIT3_9|BIT10),
BIT3_11=(BIT3_10|BIT11),
BIT3_12=(BIT3_11|BIT12),
BIT3_13=(BIT3_12|BIT13),
BIT3_14=(BIT3_13|BIT14),
BIT3_15=(BIT3_14|BIT15),
BIT3_16=(BIT3_15|BIT16),
BIT3_17=(BIT3_16|BIT17),
BIT3_18=(BIT3_17|BIT18),
BIT3_19=(BIT3_18|BIT19),
BIT3_20=(BIT3_19|BIT20),
BIT3_21=(BIT3_20|BIT21),
BIT3_22=(BIT3_21|BIT22),
BIT3_23=(BIT3_22|BIT23),
BIT3_24=(BIT3_23|BIT24),
BIT3_25=(BIT3_24|BIT25),
BIT3_26=(BIT3_25|BIT26),
BIT3_27=(BIT3_26|BIT27),
BIT3_28=(BIT3_27|BIT28),
BIT3_29=(BIT3_28|BIT29),
BIT3_30=(BIT3_29|BIT30),
BIT3_31=(BIT3_30|BIT31),
BIT4_5=(BIT4|BIT5),
BIT4_6=(BIT4_5|BIT6),
BIT4_7=(BIT4_6|BIT7),
BIT4_8=(BIT4_7|BIT8),
BIT4_9=(BIT4_8|BIT9),
BIT4_10=(BIT4_9|BIT10),
BIT4_11=(BIT4_10|BIT11),
BIT4_12=(BIT4_11|BIT12),
BIT4_13=(BIT4_12|BIT13),
BIT4_14=(BIT4_13|BIT14),
BIT4_15=(BIT4_14|BIT15),
BIT4_16=(BIT4_15|BIT16),
BIT4_17=(BIT4_16|BIT17),
BIT4_18=(BIT4_17|BIT18),
BIT4_19=(BIT4_18|BIT19),
BIT4_20=(BIT4_19|BIT20),
BIT4_21=(BIT4_20|BIT21),
BIT4_22=(BIT4_21|BIT22),
BIT4_23=(BIT4_22|BIT23),
BIT4_24=(BIT4_23|BIT24),
BIT4_25=(BIT4_24|BIT25),
BIT4_26=(BIT4_25|BIT26),
BIT4_27=(BIT4_26|BIT27),
BIT4_28=(BIT4_27|BIT28),
BIT4_29=(BIT4_28|BIT29),
BIT4_30=(BIT4_29|BIT30),
BIT4_31=(BIT4_30|BIT31),
BIT5_6=(BIT5|BIT6),
BIT5_7=(BIT5_6|BIT7),
BIT5_8=(BIT5_7|BIT8),
BIT5_9=(BIT5_8|BIT9),
BIT5_10=(BIT5_9|BIT10),
BIT5_11=(BIT5_10|BIT11),
BIT5_12=(BIT5_11|BIT12),
BIT5_13=(BIT5_12|BIT13),
BIT5_14=(BIT5_13|BIT14),
BIT5_15=(BIT5_14|BIT15),
BIT5_16=(BIT5_15|BIT16),
BIT5_17=(BIT5_16|BIT17),
BIT5_18=(BIT5_17|BIT18),
BIT5_19=(BIT5_18|BIT19),
BIT5_20=(BIT5_19|BIT20),
BIT5_21=(BIT5_20|BIT21),
BIT5_22=(BIT5_21|BIT22),
BIT5_23=(BIT5_22|BIT23),
BIT5_24=(BIT5_23|BIT24),
BIT5_25=(BIT5_24|BIT25),
BIT5_26=(BIT5_25|BIT26),
BIT5_27=(BIT5_26|BIT27),
BIT5_28=(BIT5_27|BIT28),
BIT5_29=(BIT5_28|BIT29),
BIT5_30=(BIT5_29|BIT30),
BIT5_31=(BIT5_30|BIT31),
BIT6_7=(BIT6|BIT7),
BIT6_8=(BIT6_7|BIT8),
BIT6_9=(BIT6_8|BIT9),
BIT6_10=(BIT6_9|BIT10),
BIT6_11=(BIT6_10|BIT11),
BIT6_12=(BIT6_11|BIT12),
BIT6_13=(BIT6_12|BIT13),
BIT6_14=(BIT6_13|BIT14),
BIT6_15=(BIT6_14|BIT15),
BIT6_16=(BIT6_15|BIT16),
BIT6_17=(BIT6_16|BIT17),
BIT6_18=(BIT6_17|BIT18),
BIT6_19=(BIT6_18|BIT19),
BIT6_20=(BIT6_19|BIT20),
BIT6_21=(BIT6_20|BIT21),
BIT6_22=(BIT6_21|BIT22),
BIT6_23=(BIT6_22|BIT23),
BIT6_24=(BIT6_23|BIT24),
BIT6_25=(BIT6_24|BIT25),
BIT6_26=(BIT6_25|BIT26),
BIT6_27=(BIT6_26|BIT27),
BIT6_28=(BIT6_27|BIT28),
BIT6_29=(BIT6_28|BIT29),
BIT6_30=(BIT6_29|BIT30),
BIT6_31=(BIT6_30|BIT31),
BIT7_8=(BIT7|BIT8),
BIT7_9=(BIT7_8|BIT9),
BIT7_10=(BIT7_9|BIT10),
BIT7_11=(BIT7_10|BIT11),
BIT7_12=(BIT7_11|BIT12),
BIT7_13=(BIT7_12|BIT13),
BIT7_14=(BIT7_13|BIT14),
BIT7_15=(BIT7_14|BIT15),
BIT7_16=(BIT7_15|BIT16),
BIT7_17=(BIT7_16|BIT17),
BIT7_18=(BIT7_17|BIT18),
BIT7_19=(BIT7_18|BIT19),
BIT7_20=(BIT7_19|BIT20),
BIT7_21=(BIT7_20|BIT21),
BIT7_22=(BIT7_21|BIT22),
BIT7_23=(BIT7_22|BIT23),
BIT7_24=(BIT7_23|BIT24),
BIT7_25=(BIT7_24|BIT25),
BIT7_26=(BIT7_25|BIT26),
BIT7_27=(BIT7_26|BIT27),
BIT7_28=(BIT7_27|BIT28),
BIT7_29=(BIT7_28|BIT29),
BIT7_30=(BIT7_29|BIT30),
BIT7_31=(BIT7_30|BIT31),
BIT8_9=(BIT8|BIT9),
BIT8_10=(BIT8_9|BIT10),
BIT8_11=(BIT8_10|BIT11),
BIT8_12=(BIT8_11|BIT12),
BIT8_13=(BIT8_12|BIT13),
BIT8_14=(BIT8_13|BIT14),
BIT8_15=(BIT8_14|BIT15),
BIT8_16=(BIT8_15|BIT16),
BIT8_17=(BIT8_16|BIT17),
BIT8_18=(BIT8_17|BIT18),
BIT8_19=(BIT8_18|BIT19),
BIT8_20=(BIT8_19|BIT20),
BIT8_21=(BIT8_20|BIT21),
BIT8_22=(BIT8_21|BIT22),
BIT8_23=(BIT8_22|BIT23),
BIT8_24=(BIT8_23|BIT24),
BIT8_25=(BIT8_24|BIT25),
BIT8_26=(BIT8_25|BIT26),
BIT8_27=(BIT8_26|BIT27),
BIT8_28=(BIT8_27|BIT28),
BIT8_29=(BIT8_28|BIT29),
BIT8_30=(BIT8_29|BIT30),
BIT8_31=(BIT8_30|BIT31),
BIT9_10=(BIT9|BIT10),
BIT9_11=(BIT9_10|BIT11),
BIT9_12=(BIT9_11|BIT12),
BIT9_13=(BIT9_12|BIT13),
BIT9_14=(BIT9_13|BIT14),
BIT9_15=(BIT9_14|BIT15),
BIT9_16=(BIT9_15|BIT16),
BIT9_17=(BIT9_16|BIT17),
BIT9_18=(BIT9_17|BIT18),
BIT9_19=(BIT9_18|BIT19),
BIT9_20=(BIT9_19|BIT20),
BIT9_21=(BIT9_20|BIT21),
BIT9_22=(BIT9_21|BIT22),
BIT9_23=(BIT9_22|BIT23),
BIT9_24=(BIT9_23|BIT24),
BIT9_25=(BIT9_24|BIT25),
BIT9_26=(BIT9_25|BIT26),
BIT9_27=(BIT9_26|BIT27),
BIT9_28=(BIT9_27|BIT28),
BIT9_29=(BIT9_28|BIT29),
BIT9_30=(BIT9_29|BIT30),
BIT9_31=(BIT9_30|BIT31),
BIT10_11=(BIT10|BIT11),
BIT10_12=(BIT10_11|BIT12),
BIT10_13=(BIT10_12|BIT13),
BIT10_14=(BIT10_13|BIT14),
BIT10_15=(BIT10_14|BIT15),
BIT10_16=(BIT10_15|BIT16),
BIT10_17=(BIT10_16|BIT17),
BIT10_18=(BIT10_17|BIT18),
BIT10_19=(BIT10_18|BIT19),
BIT10_20=(BIT10_19|BIT20),
BIT10_21=(BIT10_20|BIT21),
BIT10_22=(BIT10_21|BIT22),
BIT10_23=(BIT10_22|BIT23),
BIT10_24=(BIT10_23|BIT24),
BIT10_25=(BIT10_24|BIT25),
BIT10_26=(BIT10_25|BIT26),
BIT10_27=(BIT10_26|BIT27),
BIT10_28=(BIT10_27|BIT28),
BIT10_29=(BIT10_28|BIT29),
BIT10_30=(BIT10_29|BIT30),
BIT10_31=(BIT10_30|BIT31),
BIT11_12=(BIT11|BIT12),
BIT11_13=(BIT11_12|BIT13),
BIT11_14=(BIT11_13|BIT14),
BIT11_15=(BIT11_14|BIT15),
BIT11_16=(BIT11_15|BIT16),
BIT11_17=(BIT11_16|BIT17),
BIT11_18=(BIT11_17|BIT18),
BIT11_19=(BIT11_18|BIT19),
BIT11_20=(BIT11_19|BIT20),
BIT11_21=(BIT11_20|BIT21),
BIT11_22=(BIT11_21|BIT22),
BIT11_23=(BIT11_22|BIT23),
BIT11_24=(BIT11_23|BIT24),
BIT11_25=(BIT11_24|BIT25),
BIT11_26=(BIT11_25|BIT26),
BIT11_27=(BIT11_26|BIT27),
BIT11_28=(BIT11_27|BIT28),
BIT11_29=(BIT11_28|BIT29),
BIT11_30=(BIT11_29|BIT30),
BIT11_31=(BIT11_30|BIT31),
BIT12_13=(BIT12|BIT13),
BIT12_14=(BIT12_13|BIT14),
BIT12_15=(BIT12_14|BIT15),
BIT12_16=(BIT12_15|BIT16),
BIT12_17=(BIT12_16|BIT17),
BIT12_18=(BIT12_17|BIT18),
BIT12_19=(BIT12_18|BIT19),
BIT12_20=(BIT12_19|BIT20),
BIT12_21=(BIT12_20|BIT21),
BIT12_22=(BIT12_21|BIT22),
BIT12_23=(BIT12_22|BIT23),
BIT12_24=(BIT12_23|BIT24),
BIT12_25=(BIT12_24|BIT25),
BIT12_26=(BIT12_25|BIT26),
BIT12_27=(BIT12_26|BIT27),
BIT12_28=(BIT12_27|BIT28),
BIT12_29=(BIT12_28|BIT29),
BIT12_30=(BIT12_29|BIT30),
BIT12_31=(BIT12_30|BIT31),
BIT13_14=(BIT13|BIT14),
BIT13_15=(BIT13_14|BIT15),
BIT13_16=(BIT13_15|BIT16),
BIT13_17=(BIT13_16|BIT17),
BIT13_18=(BIT13_17|BIT18),
BIT13_19=(BIT13_18|BIT19),
BIT13_20=(BIT13_19|BIT20),
BIT13_21=(BIT13_20|BIT21),
BIT13_22=(BIT13_21|BIT22),
BIT13_23=(BIT13_22|BIT23),
BIT13_24=(BIT13_23|BIT24),
BIT13_25=(BIT13_24|BIT25),
BIT13_26=(BIT13_25|BIT26),
BIT13_27=(BIT13_26|BIT27),
BIT13_28=(BIT13_27|BIT28),
BIT13_29=(BIT13_28|BIT29),
BIT13_30=(BIT13_29|BIT30),
BIT13_31=(BIT13_30|BIT31),
BIT14_15=(BIT14|BIT15),
BIT14_16=(BIT14_15|BIT16),
BIT14_17=(BIT14_16|BIT17),
BIT14_18=(BIT14_17|BIT18),
BIT14_19=(BIT14_18|BIT19),
BIT14_20=(BIT14_19|BIT20),
BIT14_21=(BIT14_20|BIT21),
BIT14_22=(BIT14_21|BIT22),
BIT14_23=(BIT14_22|BIT23),
BIT14_24=(BIT14_23|BIT24),
BIT14_25=(BIT14_24|BIT25),
BIT14_26=(BIT14_25|BIT26),
BIT14_27=(BIT14_26|BIT27),
BIT14_28=(BIT14_27|BIT28),
BIT14_29=(BIT14_28|BIT29),
BIT14_30=(BIT14_29|BIT30),
BIT14_31=(BIT14_30|BIT31),
BIT15_16=(BIT15|BIT16),
BIT15_17=(BIT15_16|BIT17),
BIT15_18=(BIT15_17|BIT18),
BIT15_19=(BIT15_18|BIT19),
BIT15_20=(BIT15_19|BIT20),
BIT15_21=(BIT15_20|BIT21),
BIT15_22=(BIT15_21|BIT22),
BIT15_23=(BIT15_22|BIT23),
BIT15_24=(BIT15_23|BIT24),
BIT15_25=(BIT15_24|BIT25),
BIT15_26=(BIT15_25|BIT26),
BIT15_27=(BIT15_26|BIT27),
BIT15_28=(BIT15_27|BIT28),
BIT15_29=(BIT15_28|BIT29),
BIT15_30=(BIT15_29|BIT30),
BIT15_31=(BIT15_30|BIT31),
BIT16_17=(BIT16|BIT17),
BIT16_18=(BIT16_17|BIT18),
BIT16_19=(BIT16_18|BIT19),
BIT16_20=(BIT16_19|BIT20),
BIT16_21=(BIT16_20|BIT21),
BIT16_22=(BIT16_21|BIT22),
BIT16_23=(BIT16_22|BIT23),
BIT16_24=(BIT16_23|BIT24),
BIT16_25=(BIT16_24|BIT25),
BIT16_26=(BIT16_25|BIT26),
BIT16_27=(BIT16_26|BIT27),
BIT16_28=(BIT16_27|BIT28),
BIT16_29=(BIT16_28|BIT29),
BIT16_30=(BIT16_29|BIT30),
BIT16_31=(BIT16_30|BIT31),
BIT17_18=(BIT17|BIT18),
BIT17_19=(BIT17_18|BIT19),
BIT17_20=(BIT17_19|BIT20),
BIT17_21=(BIT17_20|BIT21),
BIT17_22=(BIT17_21|BIT22),
BIT17_23=(BIT17_22|BIT23),
BIT17_24=(BIT17_23|BIT24),
BIT17_25=(BIT17_24|BIT25),
BIT17_26=(BIT17_25|BIT26),
BIT17_27=(BIT17_26|BIT27),
BIT17_28=(BIT17_27|BIT28),
BIT17_29=(BIT17_28|BIT29),
BIT17_30=(BIT17_29|BIT30),
BIT17_31=(BIT17_30|BIT31),
BIT18_19=(BIT18|BIT19),
BIT18_20=(BIT18_19|BIT20),
BIT18_21=(BIT18_20|BIT21),
BIT18_22=(BIT18_21|BIT22),
BIT18_23=(BIT18_22|BIT23),
BIT18_24=(BIT18_23|BIT24),
BIT18_25=(BIT18_24|BIT25),
BIT18_26=(BIT18_25|BIT26),
BIT18_27=(BIT18_26|BIT27),
BIT18_28=(BIT18_27|BIT28),
BIT18_29=(BIT18_28|BIT29),
BIT18_30=(BIT18_29|BIT30),
BIT18_31=(BIT18_30|BIT31),
BIT19_20=(BIT19|BIT20),
BIT19_21=(BIT19_20|BIT21),
BIT19_22=(BIT19_21|BIT22),
BIT19_23=(BIT19_22|BIT23),
BIT19_24=(BIT19_23|BIT24),
BIT19_25=(BIT19_24|BIT25),
BIT19_26=(BIT19_25|BIT26),
BIT19_27=(BIT19_26|BIT27),
BIT19_28=(BIT19_27|BIT28),
BIT19_29=(BIT19_28|BIT29),
BIT19_30=(BIT19_29|BIT30),
BIT19_31=(BIT19_30|BIT31),
BIT20_21=(BIT20|BIT21),
BIT20_22=(BIT20_21|BIT22),
BIT20_23=(BIT20_22|BIT23),
BIT20_24=(BIT20_23|BIT24),
BIT20_25=(BIT20_24|BIT25),
BIT20_26=(BIT20_25|BIT26),
BIT20_27=(BIT20_26|BIT27),
BIT20_28=(BIT20_27|BIT28),
BIT20_29=(BIT20_28|BIT29),
BIT20_30=(BIT20_29|BIT30),
BIT20_31=(BIT20_30|BIT31),
BIT21_22=(BIT21|BIT22),
BIT21_23=(BIT21_22|BIT23),
BIT21_24=(BIT21_23|BIT24),
BIT21_25=(BIT21_24|BIT25),
BIT21_26=(BIT21_25|BIT26),
BIT21_27=(BIT21_26|BIT27),
BIT21_28=(BIT21_27|BIT28),
BIT21_29=(BIT21_28|BIT29),
BIT21_30=(BIT21_29|BIT30),
BIT21_31=(BIT21_30|BIT31),
BIT22_23=(BIT22|BIT23),
BIT22_24=(BIT22_23|BIT24),
BIT22_25=(BIT22_24|BIT25),
BIT22_26=(BIT22_25|BIT26),
BIT22_27=(BIT22_26|BIT27),
BIT22_28=(BIT22_27|BIT28),
BIT22_29=(BIT22_28|BIT29),
BIT22_30=(BIT22_29|BIT30),
BIT22_31=(BIT22_30|BIT31),
BIT23_24=(BIT23|BIT24),
BIT23_25=(BIT23_24|BIT25),
BIT23_26=(BIT23_25|BIT26),
BIT23_27=(BIT23_26|BIT27),
BIT23_28=(BIT23_27|BIT28),
BIT23_29=(BIT23_28|BIT29),
BIT23_30=(BIT23_29|BIT30),
BIT23_31=(BIT23_30|BIT31),
BIT24_25=(BIT24|BIT25),
BIT24_26=(BIT24_25|BIT26),
BIT24_27=(BIT24_26|BIT27),
BIT24_28=(BIT24_27|BIT28),
BIT24_29=(BIT24_28|BIT29),
BIT24_30=(BIT24_29|BIT30),
BIT24_31=(BIT24_30|BIT31),
BIT25_26=(BIT25|BIT26),
BIT25_27=(BIT25_26|BIT27),
BIT25_28=(BIT25_27|BIT28),
BIT25_29=(BIT25_28|BIT29),
BIT25_30=(BIT25_29|BIT30),
BIT25_31=(BIT25_30|BIT31),
BIT26_27=(BIT26|BIT27),
BIT26_28=(BIT26_27|BIT28),
BIT26_29=(BIT26_28|BIT29),
BIT26_30=(BIT26_29|BIT30),
BIT26_31=(BIT26_30|BIT31),
BIT27_28=(BIT27|BIT28),
BIT27_29=(BIT27_28|BIT29),
BIT27_30=(BIT27_29|BIT30),
BIT27_31=(BIT27_30|BIT31),
BIT28_29=(BIT28|BIT29),
BIT28_30=(BIT28_29|BIT30),
BIT28_31=(BIT28_30|BIT31),
BIT29_30=(BIT29|BIT30),
BIT29_31=(BIT29_30|BIT31),
BIT30_31=(BIT30|BIT31),
}EBits;
#endif
@@ -0,0 +1,913 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_json_api
*
* Description :
* JSON API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/04/21 Laurence Zhou 0.01 First draft
***********************************************************/
#include "lux_json_api.h"
/***********************************************************
* Name:
* LuxcJSONParseJsonFile
*
* Summary:
* parse JSON file to get the HEAD pointer(note: remeber to call Luxcjsondelete() to free memory)
*
* Return Value:
* The LuxcJSONParseJsonFile() function returns a HEAD pointer to HEAD node of the Doubly Linked List
*
* Parameter Input:
* char* pcFileName -- JSON file name with Absolute path
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
cJSON* LuxcJSONParseJsonFile(char* pcFileName)
{
long lLen = 0;
char* psBuf = NULL;
cJSON* psRoot = NULL;
if(NULL == pcFileName)
{
return NULL;
}
FILE* fp = LuxFopen(pcFileName, "rb+");
if (NULL == fp)
{
printf("open file %s failed.\n", pcFileName);
return NULL;
}
LuxFseek(fp, 0, SEEK_END);
lLen = LuxFtell(fp);
if (0 == lLen)
{
return NULL;
}
LuxFseek(fp, 0, SEEK_SET);
psBuf = (char *)LuxMalloc(sizeof(char) * lLen);
LuxFread(psBuf, 1, lLen, fp);
LuxFclose(fp);
cJSON_Minify(psBuf);
psRoot = cJSON_Parse(psBuf);
if (NULL == psRoot)
{
return NULL;
}
LuxFree(psBuf);
return psRoot;
}
/***********************************************************
* Name:
* LuxcJSONPrint
*
* Summary:
* Render a cJSON entity to text for transfer/storage(note: remeber to call Luxcjsonfree to free memory)
*
* Return Value:
* a string
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxcJSONPrint(const cJSON* psItem)
{
if(NULL != psItem)
{
return cJSON_Print(psItem);
}
return NULL;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectItem
*
* Summary:
* Get item "pcKey" from psObject
*
* Return Value:
* Pointer to the "pcKey" cJSON node
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
**********************************************************/
cJSON* LuxcJSONGetObjectItem(const cJSON* const psObject, const char* const pcKey)
{
if(NULL == psObject)
{
return NULL;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return NULL;
}
if(NULL == pcKey)
{
return NULL;
}
cJSON* psTemp = NULL;
psTemp = cJSON_GetObjectItem(psObject, pcKey);
if (psTemp)
{
return psTemp;
}
else
{
return NULL;
}
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntValue
*
* Summary:
* Get int value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piValue -- Pointer that holds the int value
*
* Parameter Output:
* piVAlue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntValue(const cJSON* const psObject, const char* const pcKey,int* piValue )
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piValue)
{
return FUNC_FAILED;
}
if( NULL == (psItem = (cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
*piValue = psItem->valueint;
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleValue
*
* Summary:
* Get double value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double* pdValue -- Pointer that holds the double value
*
* Parameter Output:
* pdValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleValue(const cJSON* const psObject,const char* const pcKey, double* pdValue)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pdValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem = (cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
*pdValue = psItem->valuedouble;
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringSize
*
* Summary:
* Get the length of String
*
* Return Value:
* length of String
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetOjectStringSize(const cJSON* const psObject, const char* const pcKey, int *piSize)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
psItem = cJSON_GetObjectItem(psObject, pcKey);
*piSize = LuxStrlen(psItem->valuestring);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringValue
*
* Summary:
* Get string value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* char* pcValue -- Pointer that holds the String value
*
* Parameter Output:
* pcValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectStringValue(const cJSON* const psObject, const char* const pcKey, char* pcValue )
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pcValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem=(cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
LuxStrcpy(pcValue,psItem->valuestring);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectBooleanValue
*
* Summary:
* Get boolean value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* cJSON_bool* pbValue -- Pointer that holds the boolean value
*
* Parameter Output:
* pbValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectBooleanValue(const cJSON* const psObject, const char* const pcKey, cJSON_bool* pbValue)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pbValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
if(false == psItem->valueint)
{
*pbValue = false;
return FUNC_OK;
}
else
{
*pbValue = true;
return FUNC_OK;
}
}
/***********************************************************
* Name:
* LuxcJSONGetObjectArraySize
*
* Summary:
* Get the array size
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectArraySize(const cJSON* const psObject, const char* const pcKey, int* piSize)
{
cJSON* psArray = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
*piSize = cJSON_GetArraySize(psArray);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntArray
*
* Summary:
* Get the int array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piArray -- Pointer that holds the int array(if pass NULL to piArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* piArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntArray(const cJSON* const psObject, const char* const pcKey, int* piArray,int* piSize)
{
cJSON *psArray = NULL;
cJSON *psTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == piArray )
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0,j = 0; i < *piSize && j < *piSize; ++i,++j)
{
psTemp = cJSON_GetArrayItem(psArray, i);
piArray[j] = psTemp->valueint;
psTemp = NULL;
}
psArray = NULL;
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleArray
*
* Summary:
* Get the double array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double* piArray -- Pointer that holds the double array(if pass NULL to pdArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* pdArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleArray(const cJSON* const psObject, const char* const pcKey, double* pdArray, int* piSize )
{
cJSON *psArray = NULL;
cJSON *psTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == pdArray)
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0,j = 0; i < *piSize && j < *piSize; ++i,++j)
{
psTemp = cJSON_GetArrayItem(psArray, i);
pdArray[j] = psTemp->valuedouble;
psTemp = NULL;
}
psArray = NULL;
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringArray
*
* Summary:
* Get the string array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* char (*pcArray)[MAXSIZE] -- Pointer that holds the string array(if pass NULL to pcArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* pcArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectStringArray(const cJSON* const psObject, const char* const pcKey, char (*pcArray)[MAXSIZE],int* piSize)
{
cJSON* pscJSONStringArray = NULL;
cJSON* pscJSONStringTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == pcArray)
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (pscJSONStringArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piSize; ++i)
{
pscJSONStringTemp = cJSON_GetArrayItem(pscJSONStringArray, i);
LuxStrcpy(pcArray[i],pscJSONStringTemp->valuestring);
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetArrayRowColumnSize
*
* Summary:
* Get the two-dimensional array's row and column
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetArrayRowColumnSize(const cJSON* const psObject, const char* const pcKey,int* piRow,int* piColumn)
{
cJSON* psArray =NULL;
cJSON *psArray21 = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
*piRow = cJSON_GetArraySize(psArray);
if(NULL == (psArray21 = cJSON_GetArrayItem(psArray, 0)))
{
return FUNC_FAILED;
}
*piColumn = cJSON_GetArraySize(psArray21);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntArray2
*
* Summary:
* Get the two-dimensional array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int (*piArray2)[MAXSIZE] -- Pointer that holds the two-dimensional arrray
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* piArray2,piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntArray2(const cJSON* const psObject, const char* const pcKey, int (*piArray2)[MAXSIZE],int* piRow, int* piColumn)
{
cJSON *psArray = NULL;
cJSON *psArrayTemp = NULL;
cJSON *psValueTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == piArray2)
{
if(FUNC_OK == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piRow; ++i )
{
psArrayTemp = cJSON_GetArrayItem(psArray, i);
for(int j = 0; j < *piColumn; ++j){
psValueTemp = cJSON_GetArrayItem(psArrayTemp, j);
piArray2[i][j] = psValueTemp->valueint;
psValueTemp= NULL;
}
psArrayTemp = NULL;
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleArray2
*
* Summary:
* Get the two-dimensional array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double (*piArray2)[MAXSIZE] -- Pointer that holds the two-dimensional arrray
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* pdArray2,piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleArray2(const cJSON* const psObject, const char* const pcKey, double (*pdArray2)[MAXSIZE],int* piRow, int* piColumn)
{
cJSON *psArray = NULL;
cJSON *psArrayTemp = NULL;
cJSON *PsValueTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == pdArray2)
{
if(FUNC_OK == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piRow; ++i )
{
psArrayTemp = cJSON_GetArrayItem(psArray, i);
for(int j = 0; j < *piColumn; ++j)
{
PsValueTemp = cJSON_GetArrayItem(psArrayTemp, j);
pdArray2[i][j] = PsValueTemp->valuedouble;
PsValueTemp = NULL;
}
psArrayTemp = NULL;
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONDelete
*
* Summary:
* Delete a cJSON entity and all subentities
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* cJSON* psItem -- the HEAD pointer
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONDelete(cJSON* psItem)
{
if(NULL != psItem)
{
cJSON_Delete(psItem);
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONFree
*
* Summary:
* free object
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* cJSON* psItem -- the HEAD pointer
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONFree(void* psObject)
{
if(NULL != psObject)
{
cJSON_free(psObject);
}
return FUNC_OK;
}
@@ -0,0 +1,56 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : LuxcJSON
*
* Description :
* JSON API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/04/21 Laurence Zhou 0.01 First draft
***********************************************************/
#ifndef LUX_JSON_API_H
#define LUX_JSON_API_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
#include "lux_system_api.h"
#define MAXSIZE 128
#ifdef true
#undef true
#endif
#define true ((cJSON_bool)1)
#ifdef false
#undef false
#endif
#define false ((cJSON_bool)0)
extern cJSON* LuxcJSONParseJsonFile(char* pcFileName);
extern char* LuxcJSONPrint(const cJSON* psItem);
extern cJSON* LuxcJSONGetObjectItem(const cJSON* const psObject, const char* const pcKey);
extern EFuncRetCode LuxcJSONGetObjectIntValue(const cJSON* const psObject, const char* const pcKey,int* piValue );
extern EFuncRetCode LuxcJSONGetObjectDoubleValue(const cJSON* const psObject,const char* const pcKey, double* pdValue);
extern EFuncRetCode LuxcJSONGetObjectStringValue(const cJSON* const psObject, const char* const pcKey, char* pcValue );
extern EFuncRetCode LuxcJSONGetObjectBooleanValue(const cJSON* const psObject, const char* const pcKey, cJSON_bool* pbValue);
extern EFuncRetCode LuxcJSONGetObjectArraySize(const cJSON* const psObject, const char* const pcKey, int* piSize);
extern EFuncRetCode LuxcJSONGetObjectIntArray(const cJSON* const psObject, const char* const pcKey, int* piArray,int* piSize);
extern EFuncRetCode LuxcJSONGetObjectDoubleArray(const cJSON* const psObject, const char* const pcKey, double* pdArray, int* piSize );
extern EFuncRetCode LuxcJSONGetObjectStringArray(const cJSON* const psObject, const char* const pcKey, char (*pcArray)[MAXSIZE],int* piSize);
extern EFuncRetCode LuxcJSONGetObjectIntArray2(const cJSON* const psObject, const char* const pcKey, int (*piArray2)[MAXSIZE],int* piRow, int* piColumn);
extern EFuncRetCode LuxcJSONGetObjectDoubleArray2(const cJSON* const psObject, const char* const pcKey, double (*pdArray2)[MAXSIZE],int* piRow, int* piColumn);
extern EFuncRetCode LuxcJSONDelete(cJSON* psItem);
extern EFuncRetCode LuxcJSONFree(void* psObject);
EFuncRetCode LuxcJSONGetOjectStringSize(const cJSON* const psObject, const char* const pcKey, int *piSize);
extern EFuncRetCode LuxcJSONGetArrayRowColumnSize(const cJSON* const psObject, const char* const pcKey, int* piRow,int* piColumn);
#endif /* LUX_JSON_API_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,123 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_system_api
*
* Description :
* system or C API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/03/23 chin 0.01 First draft
* 2021/4/25 huangliang 0.02 add system calls
***********************************************************/
#ifndef __LUX_SYSTEM_API_H__
#define __LUX_SYSTEM_API_H__
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include "lux_base.h"
#include <unistd.h>
#include <arpa/inet.h>
#include <regex.h>
#include <netdb.h> /* gethostbyname() */
#define F_OK 0
extern void* LuxMmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
extern int LuxMunmap(void *addr, size_t length);
extern int LuxMsync(void *addr, size_t length, int flags);
extern void* LuxMemset(void* pStr, int iValue, size_t szCount);
extern EFuncRetCode LuxMemsetSafe(void* pDestStr, size_t szSize, int iValue, size_t szCount);
extern void* LuxMemcpy(void* pDst, const void* pSrc, size_t szCount);
extern EFuncRetCode LuxMemcpySafe(void* pDst, size_t szSize, const void* pSrc, size_t szCount);
extern int LuxMemcmp(const void* pBuf1,const void* pBuf2,size_t szCount);
extern char* LuxStrcpy(char* pcDestStr, const char* pcScrStr);
extern char* LuxStrncpy(char* pcDestStr, const char* pcScrStr, size_t szCount);
extern int LuxStrcmp(const char* pcStr1, const char* pcStr2);
extern int LuxStrncmp(const char* pcStr1, const char* pcStr2, size_t szCount);
extern size_t LuxStrlen(const char* pcStr);
extern size_t LuxStrnlen(const char* pcStr, size_t szLen);
extern char* LuxStrcat(char* pcDestStr, const char* pcSrcStr);
extern char* LuxStrncat(char* pcDest, const char* pcSrc, size_t szCount);
extern char* LuxStrstr(char* pcDestStr, const char* pcSrcStr);
extern int LuxPrintf(const char* fmt,...);
extern int LuxFprintf(FILE* fp, char* fmt, ...);
extern int LuxDprintf(int fd, const char *fmt, ...);
extern int LuxSprintf(char* pcBuf, const char* fmt, ...);
extern int LuxSnprintf(char* pcBuf, size_t szSize, const char* fmt, ...);
extern int LuxSscanf(const char* pcBuf, const char* fmt, ...);
extern int LuxScanf(const char* fmt, ...);
extern int LuxFscanf(FILE* stream, const char* fmt, ...);
extern int LuxOpenAndCreat(const char* pcPathname,int iFlags,mode_t mode);
extern int LuxOpen(const char* pcPathname,int iFlags);
extern int LuxClose(int fd);
extern ssize_t LuxRead(int fd, void* pBuf, size_t szCount);
extern ssize_t LuxWrite(int fd, void* pBuf, size_t szCount);
extern off_t LuxLseek(int fd, off_t offset, int iWhence);
extern FILE* LuxFopen(const char* pcPathname, const char* pcMode);
extern int LuxFclose(FILE* stream);
extern size_t LuxFread(void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern size_t LuxFwrite(const void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern int LuxFseek(FILE *stream, long offset, int iWhence);
extern long LuxFtell(FILE* stream);
extern void LuxRewind(FILE* stream);
extern EFuncRetCode LuxSystem(char* pcCmdStr);
extern FILE* LuxPopen(const char* pcCmdStr, const char* pcType);
extern int LuxPclose(FILE* stream);
extern void* LuxDlopen(const char* pcFilename, int iFlags);
extern int LuxDlclose(void* pDlhandle);
extern void* LuxDlsym(void* pDlhandle, const char* pcSymbol);
extern char* LuxDlerror(void);
extern time_t LuxTime(time_t* timep);
extern char* LuxCtime(const time_t* timep);
extern char* LuxAsctime(const struct tm* tm);
extern struct tm* LuxGmtime(const time_t* timep);
extern struct tm* LuxLocaltime(const time_t* timep);
extern time_t LuxMktime(struct tm* tm);
extern void* LuxMalloc(size_t size);
extern void* LuxCalloc(size_t nmemb, size_t size);
extern void* LuxRealloc(void* ptr, size_t size);
extern void LuxFree(void* ptr);
extern void* LuxMemchr(const void* pStr, int iCharacter, size_t szCount);
extern char* LuxStrchr(const char* pcStr, int iCharacter);
extern char* LuxStrtok(char* pcStr, const char* pcDelim);
extern int LuxFeof(FILE* stream);
extern int LuxFflush(FILE* stream);
extern int LuxRemove(const char* pcFilename);
extern int LuxRename(const char* pcOldFilename, const char* pcNewFilename);
extern int LuxRand(void);
extern void LuxSrand(unsigned int iSeed);
extern int LuxAccess(const char* pcPathName,int mode);
extern int LuxClosedir(DIR* psDir);
extern struct dirent* LuxReaddir(DIR* psDir);
extern int LuxChdir(const char* pcPathName);
extern int LuxRmdir(const char* pcPathname);
extern int LuxChmod(const char* pcFilename,mode_t mode);
extern int LuxMkdir(const char* pcPathName,mode_t mode);
extern int LuxClockgettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int LuxClocksettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int LuxFgetc(FILE *pstream);
extern int LuxFputc(int chara, FILE *pstream);
extern int LuxFerror(FILE *pstream);
extern DIR* LuxOpendir(const char *pcdirname);
extern const char* LuxInetNtop(int af, const void* psrc, char* pcDst, size_t size);
extern int LuxInetPton(int af, const char *pcSrc, void *pDst);
extern char* LuxInetNtoa(struct in_addr in);
extern int LuxSocket(int domain, int type, int protocol);
extern int LuxIoctl(int fd, unsigned long request, ...);
extern void LuxReboot(int iFlag);
extern int LuxRegcomp(regex_t *compiled, const char *pattern, int cflags);
extern int LuxRegexec(regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr[], int eflags);
extern void LuxRegfree(regex_t *compiled);
extern int LuxGetaddrinfo( const char *hostname, const char *service, const struct addrinfo *hints, struct addrinfo **result );
extern int LuxAtoi(const char* paddr);
#endif
@@ -0,0 +1,12 @@
[Unit]
Description=Oem Pre Heat Service
Requires=xyz.openbmc_project.EntityManager.service
After=xyz.openbmc_project.EntityManager.service
[Service]
Restart=always
RestartSec=5
ExecStart=/usr/bin/pre-heat.sh
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,3 @@
#!/bin/sh
/usr/bin/pre_heat
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,384 @@
#ifndef PRE_HEAT_H
#define PRE_HEAT_H
#define DIMM_FSC_VERSION "V0.1"
#define FAN_TABLE_PATH "/usr/bin/pre_heat.json"
//define for thermal oem command
#define DIMM_SETPOINT_PATH "/tmp/dimm_setpoint"
#define COVER_SETPOINT_PATH "/tmp/cover_setpoint"
#define COVER_STATUS_PATH "/tmp/cover_status"
#define FSC_CONTROL_MODE "/tmp/fsc_control_mode"
#define FSC_ENABLE_STATUS_PATH "/tmp/fsc_enable"
#define SETPOINT_CONSTANT "constant"
#define SETPOINT_VARIABLE "variable"
#define MAX_FSC_PWM_CHANNEL 29
#define MAX_DIMM_SLOT 24
#define MAX_DIMM_POWER_SLOT 4
#define MAX_MB_PWM_CHANNEL 5
#define MAX_JSON_CHARACTER_SIZE 128
#define MAX_SENSOR_NAME_LENGTH 16
#define MAX_KEY_LENGTH 32
#define PWM_POWER_ON_IN_SHORT_TIME 80
#define MAX_PWM_THERMAL_DEFINE 100
#define MIN_PWM_THERMAL_DEFINE 1
#define MAX_OL_SENSOR 10
#define MAX_OL_SENSOR_STEPS 50
#define MAX_CL_SENSOR 50
#define MAX_FAN_COUNT 20
#define MAX_SETPOINT_CASE 10
#define MAX_SENSOR_E_SECTION 12
#define MAX_SENSOR_EC_SECTION 9
#define MAX_ABNORMAL_SENSOR 50
#define MAX_FAN_AVERAGE_COUNT 10
#define PID_INIT_PWM 50
#define SENSOR_REAL_VALUE_INITIAL 127 /*init sensor reading to 127, sign value */
#define POWERON_FSC_DELAY 10
#define INLET_SENSOR_VALUE_ABNORMAL_STATE 35 /*if inlet sensor is can't read, need use 35 do fsc control */
#define SENSOR_UPPER_NON_CRITICAL_PWM 80
#define SENSOR_UPPER_CRITICAL_PWM 90
#define SENSOR_UPPER_NON_RECOVERABLE_PWM 100
#define MAX_READING_CACHE 10
#define READING_INVALID 0
#define READING_VALID 1
#define FCB_I2C_BUS 7
#define FCB_CPLD_SLAVE_ADDR 0x7c
#define FCB_TMP468_ADDR 0x90
#define DIMM_HEAT_TURN_OFF 0
#define DIMM_HEAT_TURN_ON 1
#define PTC_PRE_HEAT_MAX_PWM 100
#define PTC_PRE_HEAT_MIN_PWM 1
#define PTC_PRE_HEAT_PWM 30
#define DIMM_FAN_MIN_PWM 37
#define CPU_FAN_MIN_PWM 80
#define FCB_6056_LOWER_TEMP_MIN_PWM 75
#define FCB_6056_HIGH_TEMP_MAX_PWM 40
#define FCB_6056_HIGH_TEMP_MIN_PWM 0
#define FCB_6056_FAN_NUM 4
#define FCB_6056_PRE_HEAT_PWM 10
typedef struct
{
INT8U u8ControlMode;
INT8U u8PWM[MAX_FSC_PWM_CHANNEL];
}__attribute__ ((packed))SFscControlMode;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFscFanReg;
typedef struct
{
INT8U u8DIMMIndex;
char acDbusPath[256];
}__attribute__ ((packed))SDIMMDbus;
typedef struct
{
INT8U u8CPUIndex;
char acDbusPath[256];
}__attribute__ ((packed))SCPUDbus;
typedef struct
{
INT8U u8DIMMPowerIndex;
char acDbusPath[256];
}__attribute__ ((packed))SDIMMPowerDbus;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFscHeatReg;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFsc6056FanReg;
typedef enum
{
REG_FCB_CPLD_FAN_QUANTITY = 0x0006,
REG_FCB_GET_HEAT_COVER_STATUS = 0x0037,
REG_FCB_DIMM_INITIAL_PWM = 0x0051,
REG_FCB_DIMM23_SET_PWM = 0x0052,
REG_FCB_DIMM22_SET_PWM = 0x0053,
REG_FCB_DIMM21_SET_PWM = 0x0054,
REG_FCB_DIMM20_SET_PWM = 0x0055,
REG_FCB_DIMM19_SET_PWM = 0x0056,
REG_FCB_DIMM18_SET_PWM = 0x0057,
REG_FCB_DIMM17_SET_PWM = 0x0058,
REG_FCB_DIMM16_SET_PWM = 0x0059,
REG_FCB_DIMM15_SET_PWM = 0x005a,
REG_FCB_DIMM14_SET_PWM = 0x005b,
REG_FCB_DIMM13_SET_PWM = 0x005c,
REG_FCB_DIMM12_SET_PWM = 0x005d,
REG_FCB_DIMM11_SET_PWM = 0x005e,
REG_FCB_DIMM10_SET_PWM = 0x005f,
REG_FCB_DIMM9_SET_PWM = 0x0060,
REG_FCB_DIMM8_SET_PWM = 0x0061,
REG_FCB_DIMM7_SET_PWM = 0x0062,
REG_FCB_DIMM6_SET_PWM = 0x0063,
REG_FCB_DIMM5_SET_PWM = 0x0064,
REG_FCB_DIMM4_SET_PWM = 0x0065,
REG_FCB_DIMM3_SET_PWM = 0x0066,
REG_FCB_DIMM2_SET_PWM = 0x0067,
REG_FCB_DIMM1_SET_PWM = 0x0068,
REG_FCB_DIMM0_SET_PWM = 0x0069,
REG_FCB_PTC_INITIAL_PWM = 0x0075,
REG_FCB_PTC_DIMM23_SET_PWM = 0x0076,
REG_FCB_PTC_DIMM22_SET_PWM = 0x0077,
REG_FCB_PTC_DIMM21_SET_PWM = 0x0078,
REG_FCB_PTC_DIMM20_SET_PWM = 0x0079,
REG_FCB_PTC_DIMM19_SET_PWM = 0x007a,
REG_FCB_PTC_DIMM18_SET_PWM = 0x007b,
REG_FCB_PTC_DIMM17_SET_PWM = 0x007c,
REG_FCB_PTC_DIMM16_SET_PWM = 0x007d,
REG_FCB_PTC_DIMM15_SET_PWM = 0x007e,
REG_FCB_PTC_DIMM14_SET_PWM = 0x007f,
REG_FCB_PTC_DIMM13_SET_PWM = 0x0080,
REG_FCB_PTC_DIMM12_SET_PWM = 0x0081,
REG_FCB_PTC_DIMM11_SET_PWM = 0x0082,
REG_FCB_PTC_DIMM10_SET_PWM = 0x0083,
REG_FCB_PTC_DIMM9_SET_PWM = 0x0084,
REG_FCB_PTC_DIMM8_SET_PWM = 0x0085,
REG_FCB_PTC_DIMM7_SET_PWM = 0x0086,
REG_FCB_PTC_DIMM6_SET_PWM = 0x0087,
REG_FCB_PTC_DIMM5_SET_PWM = 0x0088,
REG_FCB_PTC_DIMM4_SET_PWM = 0x0089,
REG_FCB_PTC_DIMM3_SET_PWM = 0x008a,
REG_FCB_PTC_DIMM2_SET_PWM = 0x008b,
REG_FCB_PTC_DIMM1_SET_PWM = 0x008c,
REG_FCB_PTC_DIMM0_SET_PWM = 0x008d,
REG_FCB_SET_HEAT_COVER_STATUS = 0x008e,
}EUbbPriCPLDReg;
typedef enum
{
/*Power good status*/
PS_GOOD_FAIL=0,
PS_GOOD_OK,
/*Update flag */
FSC_FAN_TABLE_NORMAL = 0,
FSC_FAN_TABLE_UPDATE = 1,
/*Fan table load status flag */
FSC_FAN_TABLE_LOAD_FAIL = 0,
FSC_FAN_TABLE_LOAD_SUCCESS = 1,
/*Control mode*/
FSC_FAN_TABLE_AUTO = 0,
FSC_FAN_TABLE_MANUAL = 1,
/*Sensor present */
FSC_SENSOR_NOT_PRESENT = 0,
FSC_SENSOR_PRESENT = 1,
/*Sensor present */
FSC_SENSOR_NORMAL = 0,
FSC_SENSOR_ABNORMAL = 1,
/*Fan type */
FSC_FAN_TYPE_SINGLE = 0,
FSC_FAN_TYPE_TWIN = 1,
/*Fan status */
FSC_FAN_NORMAL = 0,
FSC_FAN_FAIL = 1,
/*Fsc work when dc off */
FSC_WORK_DC_ON_ONLY = 0,
FSC_WORK_DC_OFF = 1,
/*Fan fail handle type */
FSC_ABNORMAL_POLICY_UNUSED = 0,
FSC_ABNORMAL_POLICY_INCREASE = 1,
FSC_ABNORMAL_POLICY_CONSTANT = 2,
/*FSC normal or abnormal */
FSC_NORMAL = 0,
FSC_ABNORMAL = 1,
/*Thermal debug */
FSC_NO_THERMAL_DEBUG = 0,
FSC_OPEN_THERMAL_DEBUG = 1,
}EFscFlag;
typedef struct
{
char acProject[MAX_KEY_LENGTH];
char acCustomer[MAX_KEY_LENGTH];
char acVersion[MAX_KEY_LENGTH];
char acPlatform[MAX_KEY_LENGTH];
}__attribute__ ((packed))SFscHeader;
typedef struct
{
INT8U u8MaxReadingCache;
INT16U u16Elevation;
char acFanType[MAX_KEY_LENGTH];
char acWorkDCOff[MAX_KEY_LENGTH];
}__attribute__ ((packed))SFscGlobalConfig;
typedef struct
{
INT8U u8MaxPwmNum;
INT8U u8MaxFanNum;
INT8U u8FanSensorNumPWMMatch[MAX_FAN_COUNT];
INT8U u8MaxFanDuty;
INT8U u8MinFanDuty;
}__attribute__ ((packed))SFscFanConfig;
typedef struct
{
char acCLSensorType[MAX_KEY_LENGTH];
char acCLSensorStatus[MAX_KEY_LENGTH];
INT8U u8DT;
char acSensorName[MAX_SENSOR_NAME_LENGTH + 1];
INT8S s8VendorSpec;
INT8S s8CustomerSpec;
char acSetpointType[MAX_KEY_LENGTH];
INT8S s8SetpointDefault;
char acSetpointCase[MAX_SETPOINT_CASE][MAX_KEY_LENGTH];
INT8S as8SetpointValue[MAX_SETPOINT_CASE];
char acSetpointCaseUse[MAX_KEY_LENGTH];
INT8U au8FanWeight[MAX_FSC_PWM_CHANNEL];
INT8U u8Hysteresis;
INT8S as8EValue[MAX_SENSOR_E_SECTION-1];
INT8S as8ECValue[MAX_SENSOR_EC_SECTION-1];
float afPValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
float afIValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
float afDValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
INT8U u8SensorNumber;
INT8S s8Setpoint;
INT8S as8RealValue[MAX_READING_CACHE];
float fP;
float fI;
float fD;
INT8U u8SensorSDRPresent; /*sensor sdr present flag, 1 - present, 0 - not present*/
INT8U u8Present; /*sensor present flag, 1 - present, 0 - not present*/
INT8U u8Abnormal; /*sensor health flag, 1 - abnormal, 0 - normal*/
INT8U u8Health; /*sensor reading value status*/
INT8U u8NoReadingTries;
INT8U u8SensorStatus;
/* Event Flags description */
/* Bit 0 - Initialization Done */
/* Bit 1 - Update in Progress */
/* Bit 2 - reserved */
/* Bit 3 - reserved */
/* Bit 4 - reserved */
/* Bit 5 - Unable to read */
/* Bit 6 - Sensor Scanning disabled */
/* Bit 7 - Event Message Disabled */
INT32U u32CalculateTick;
INT8U u8PwmPIDCalculate;
INT16S s16LastPwmPIDCalculate;
float fPIncrement;
float fIIncrement;
float fDIncrement;
INT8U u8PwmAfterWeighting[MAX_FSC_PWM_CHANNEL];
INT8U u8PwmAfterWeightingCache[MAX_FSC_PWM_CHANNEL][MAX_FAN_AVERAGE_COUNT];
INT8U u8PwmAfterHysteresis[MAX_FSC_PWM_CHANNEL];
}__attribute__ ((packed))SFscCLSensorInfo;
typedef struct
{
INT8U u8MaxCLSensor;
INT8U u8TotalCLSensor;
char acPIDAdjustMethod[MAX_KEY_LENGTH];
INT8U u8CLSensorESection;
INT8U u8CLSensorECSection;
INT8U u8CLSensorSetpointMaxCase;
SFscCLSensorInfo asFscCLSensorInfo[MAX_CL_SENSOR];
}__attribute__ ((packed))SFscCLSensor;
typedef struct
{
INT8U u8FanSensorNumberStart;
char acFanFailSingle[MAX_KEY_LENGTH];
INT8U u8FanFailTwin1;
INT8U u8FanFailTwin2Diff;
char acFanFailTwin2Same[MAX_KEY_LENGTH];
/*fan status: 0 - normal, 1 - abnormal */
INT8U au8FanStatus[MAX_FAN_COUNT];
INT8U au8FanFailPwm[MAX_FSC_PWM_CHANNEL];
INT8U au8FanFailConstantPwm;
INT8U u8FanFailHandleType;
}__attribute__ ((packed))SFscFanFail;
typedef struct
{
char acSensorName[MAX_SENSOR_NAME_LENGTH];
char acFailPolicy[MAX_KEY_LENGTH];
INT8U u8FailValue;
INT8U u8SensorFailHandleType;
INT8U u8SensorFailPwmOut;
}__attribute__ ((packed))SFscSensorFailInfo;
typedef struct
{
INT8U u8MaxAbnormalSensor;
INT8U u8TotalAbnormalSensor;
SFscFanFail sFscFanFail;
SFscSensorFailInfo asFscSensorFailInfo[MAX_ABNORMAL_SENSOR];
}__attribute__ ((packed))SFscAbnormalEvent;
typedef struct
{
INT8U u8UpdateFlag; /*1 - update, 0 - normal */
INT8U u8FanTableLoadStatus; /*1 - success, 0 - fail */
INT8U u8ControlMode; /*1 - manual, 0 - auto */
INT8U u8ThermalDebug; /*thermal debug falg, 0 - no debug, 1 - debuging */
INT8U u8WorkDCOff; /*1 - work when dc off, 0 - no work when dc off */
INT8U u8LoadTableTries;
INT32U u32Tick;
INT8U u8SKUID;
INT8U u8MaxOLPwm;
INT8U au8CLPwm[MAX_FSC_PWM_CHANNEL];
INT8U au8MaxAbnormalPwm;
INT8U au8MaxAbnormalIncreasePwm;
char acFactorSensorName[16];
INT8U u8FactorPwm;
INT8U u8FscStatus; /*0 - normal fsc, 1 - abnormal fsc */
INT8U au8PwmOut[MAX_FSC_PWM_CHANNEL];
INT8U au8ManualPwmOut[MAX_FSC_PWM_CHANNEL];
INT8U u8MaxCoverTemp;
}__attribute__ ((packed))SFscRunningInfo;
typedef struct
{
SFscHeader sFSCHeader;
SFscGlobalConfig sFscGlobalConfig;
SFscFanConfig sFscFanConfig;
SFscCLSensor sFscCLSensor;
SFscAbnormalEvent sFscAbnormalEvent;
SFscRunningInfo sFscRunningInfo;
}__attribute__ ((packed))SFscInfo;
#endif
File diff suppressed because it is too large Load Diff
+22
View File
@@ -0,0 +1,22 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
LICENSE = "CLOSED"
SRC_URI += " \
file://cJSON.c \
file://cJSON.h \
file://lux_json_api.c \
file://lux_json_api.h \
file://lux_system_api.c \
file://lux_system_api.h \
file://dimm_fsc.c \
file://dimm_fsc.h \
file://lux_base.h \
file://dimm_fsc.json \
file://dimm_fsc.h \
file://dimm-fsc.sh \
file://CMakeLists.txt "
S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"
DEPENDS += "systemd dbus"
inherit pkgconfig cmake obmc-phosphor-systemd
SYSTEMD_SERVICE:${PN} = " dimm-fsc.service "
@@ -0,0 +1,19 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
inherit obmc-phosphor-systemd
SRC_URI += "file://dimm-fsc.service \
file://dimm-fsc.sh \
"
SYSTEMD_SERVICE_${PN} = "dimm-fsc.service"
do_install:append() {
# deal with systemd unit files
install -d ${D}${systemd_unitdir}/system
install -m 0755 ${WORKDIR}/dimm-fsc.sh ${D}${bindir}/dimm-fsc.sh
install -m 0644 ${WORKDIR}/dimm-fsc.service ${D}${systemd_unitdir}/system
}
FILES_${PN} += "${systemd_unitdir}/system/dimm-fsc.service"
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.15)
project(dimm_fsc)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SYSTEMD REQUIRED libsystemd)
pkg_check_modules(DBUS REQUIRED dbus-1)
aux_source_directory(. SRC)
add_executable(${CMAKE_PROJECT_NAME} ${SRC})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${DBUS_LIBRARIES})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${DBUS_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${SYSTEMD_INCLUDE_DIRS})
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE /usr/include)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${SYSTEMD_LIBRARIES})
install(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES dimm_fsc.json DESTINATION bin)
install(FILES dimm-fsc.sh DESTINATION bin)
@@ -0,0 +1,13 @@
CFLAGS += -Wall
OBJS = dimm_fsc.o cJSON.o lux_json_api.o lux_system_api.o
EXE = dimm_fsc
.c.o:
$(CC) -c $<
$(EXE): $(OBJS)
$(CC) $(OBJS) -o $@
all:$(EXE)
clean:
rm -f $(EXE) $(OBJS)
install:
cp $(EXE) $(INSTALL_DIR)
File diff suppressed because it is too large Load Diff
+292
View File
@@ -0,0 +1,292 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
pPermission 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.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 14
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,12 @@
[Unit]
Description=Oem Dimm FSC Service
Requires=xyz.openbmc_project.EntityManager.service
After=xyz.openbmc_project.EntityManager.service
[Service]
Restart=always
RestartSec=5
ExecStart=/usr/bin/dimm-fsc.sh
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,4 @@
#!/bin/sh
#start dimm fsc logic
/usr/bin/dimm_fsc
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,390 @@
#ifndef DIMM_FSC_H
#define DIMM_FSC_H
#define DIMM_FSC_VERSION "V0.1"
#define FAN_TABLE_PATH "/usr/bin/dimm_fsc.json"
//define for thermal oem command
#define DIMM_SETPOINT_PATH "/tmp/dimm_setpoint"
#define COVER_SETPOINT_PATH "/tmp/cover_setpoint"
#define COVER_STATUS_PATH "/tmp/cover_status"
#define FSC_CONTROL_MODE "/tmp/fsc_control_mode"
#define FSC_ENABLE_STATUS_PATH "/tmp/fsc_enable"
#define SETPOINT_CONSTANT "constant"
#define SETPOINT_VARIABLE "variable"
#define MAX_FSC_PWM_CHANNEL 29
#define MAX_DIMM_SLOT 24
#define MAX_DIMM_POWER_SLOT 4
#define MAX_MB_PWM_CHANNEL 5
#define MAX_JSON_CHARACTER_SIZE 128
#define MAX_SENSOR_NAME_LENGTH 16
#define MAX_KEY_LENGTH 32
#define PWM_POWER_ON_IN_SHORT_TIME 80
#define MAX_PWM_THERMAL_DEFINE 100
#define MIN_PWM_THERMAL_DEFINE 1
#define MAX_OL_SENSOR 10
#define MAX_OL_SENSOR_STEPS 50
#define MAX_CL_SENSOR 50
#define MAX_FAN_COUNT 20
#define MAX_SETPOINT_CASE 10
#define MAX_SENSOR_E_SECTION 12
#define MAX_SENSOR_EC_SECTION 9
#define MAX_ABNORMAL_SENSOR 50
#define MAX_FAN_AVERAGE_COUNT 10
#define PID_INIT_PWM 50
#define SENSOR_REAL_VALUE_INITIAL 127 /*init sensor reading to 127, sign value */
#define POWERON_FSC_DELAY 10
#define INLET_SENSOR_VALUE_ABNORMAL_STATE 35 /*if inlet sensor is can't read, need use 35 do fsc control */
#define SENSOR_UPPER_NON_CRITICAL_PWM 80
#define SENSOR_UPPER_CRITICAL_PWM 90
#define SENSOR_UPPER_NON_RECOVERABLE_PWM 100
#define MAX_READING_CACHE 10
#define READING_INVALID 0
#define READING_VALID 1
#define FCB_I2C_BUS 7
#define FCB_CPLD_SLAVE_ADDR 0x7c
#define FCB_TMP468_ADDR 0x90
#define DIMM_HEAT_TURN_OFF 0
#define DIMM_HEAT_TURN_ON 1
#define PTC_PRE_HEAT_MAX_PWM 50
#define PTC_PRE_HEAT_MIN_PWM 1
#define PTC_PRE_HEAT_PWM 30
#define DIMM_FAN_MIN_PWM 37
#define CPU_FAN_MIN_PWM 80
#define FCB_6056_LOWER_TEMP_MIN_PWM 75
#define FCB_6056_HIGH_TEMP_MAX_PWM 40
#define FCB_6056_HIGH_TEMP_MIN_PWM 0
#define FCB_6056_FAN_NUM 4
#define DIMM_PROTECT_TEMPERATURE 85
typedef struct
{
INT8U u8ControlMode;
INT8U u8PWM[MAX_FSC_PWM_CHANNEL];
}__attribute__ ((packed))SFscControlMode;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFscFanReg;
typedef struct
{
INT8U u8DIMMIndex;
char acDbusPath[256];
}__attribute__ ((packed))SDIMMDbus;
typedef struct
{
INT8U u8CPUIndex;
char acDbusPath[256];
}__attribute__ ((packed))SCPUDbus;
typedef struct
{
INT8U u8DIMMPowerIndex;
char acDbusPath[256];
}__attribute__ ((packed))SDIMMPowerDbus;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFscHeatReg;
typedef struct
{
INT8U u8DIMMIndex;
INT8U u16Reg;
}__attribute__ ((packed))SFsc6056FanReg;
typedef enum
{
REG_FCB_CPLD_FAN_QUANTITY = 0x0006,
REG_FCB_GET_HEAT_COVER_STATUS = 0x0037,
REG_FCB_DIMM_INITIAL_PWM = 0x0051,
REG_FCB_DIMM23_SET_PWM = 0x0052,
REG_FCB_DIMM22_SET_PWM = 0x0053,
REG_FCB_DIMM21_SET_PWM = 0x0054,
REG_FCB_DIMM20_SET_PWM = 0x0055,
REG_FCB_DIMM19_SET_PWM = 0x0056,
REG_FCB_DIMM18_SET_PWM = 0x0057,
REG_FCB_DIMM17_SET_PWM = 0x0058,
REG_FCB_DIMM16_SET_PWM = 0x0059,
REG_FCB_DIMM15_SET_PWM = 0x005a,
REG_FCB_DIMM14_SET_PWM = 0x005b,
REG_FCB_DIMM13_SET_PWM = 0x005c,
REG_FCB_DIMM12_SET_PWM = 0x005d,
REG_FCB_DIMM11_SET_PWM = 0x005e,
REG_FCB_DIMM10_SET_PWM = 0x005f,
REG_FCB_DIMM9_SET_PWM = 0x0060,
REG_FCB_DIMM8_SET_PWM = 0x0061,
REG_FCB_DIMM7_SET_PWM = 0x0062,
REG_FCB_DIMM6_SET_PWM = 0x0063,
REG_FCB_DIMM5_SET_PWM = 0x0064,
REG_FCB_DIMM4_SET_PWM = 0x0065,
REG_FCB_DIMM3_SET_PWM = 0x0066,
REG_FCB_DIMM2_SET_PWM = 0x0067,
REG_FCB_DIMM1_SET_PWM = 0x0068,
REG_FCB_DIMM0_SET_PWM = 0x0069,
REG_FCB_PTC_INITIAL_PWM = 0x0075,
REG_FCB_PTC_DIMM23_SET_PWM = 0x0076,
REG_FCB_PTC_DIMM22_SET_PWM = 0x0077,
REG_FCB_PTC_DIMM21_SET_PWM = 0x0078,
REG_FCB_PTC_DIMM20_SET_PWM = 0x0079,
REG_FCB_PTC_DIMM19_SET_PWM = 0x007a,
REG_FCB_PTC_DIMM18_SET_PWM = 0x007b,
REG_FCB_PTC_DIMM17_SET_PWM = 0x007c,
REG_FCB_PTC_DIMM16_SET_PWM = 0x007d,
REG_FCB_PTC_DIMM15_SET_PWM = 0x007e,
REG_FCB_PTC_DIMM14_SET_PWM = 0x007f,
REG_FCB_PTC_DIMM13_SET_PWM = 0x0080,
REG_FCB_PTC_DIMM12_SET_PWM = 0x0081,
REG_FCB_PTC_DIMM11_SET_PWM = 0x0082,
REG_FCB_PTC_DIMM10_SET_PWM = 0x0083,
REG_FCB_PTC_DIMM9_SET_PWM = 0x0084,
REG_FCB_PTC_DIMM8_SET_PWM = 0x0085,
REG_FCB_PTC_DIMM7_SET_PWM = 0x0086,
REG_FCB_PTC_DIMM6_SET_PWM = 0x0087,
REG_FCB_PTC_DIMM5_SET_PWM = 0x0088,
REG_FCB_PTC_DIMM4_SET_PWM = 0x0089,
REG_FCB_PTC_DIMM3_SET_PWM = 0x008a,
REG_FCB_PTC_DIMM2_SET_PWM = 0x008b,
REG_FCB_PTC_DIMM1_SET_PWM = 0x008c,
REG_FCB_PTC_DIMM0_SET_PWM = 0x008d,
REG_FCB_SET_HEAT_COVER_STATUS = 0x008e,
}EUbbPriCPLDReg;
typedef enum
{
/*Power good status*/
PS_GOOD_FAIL=0,
PS_GOOD_OK,
/*Update flag */
FSC_FAN_TABLE_NORMAL = 0,
FSC_FAN_TABLE_UPDATE = 1,
/*Fan table load status flag */
FSC_FAN_TABLE_LOAD_FAIL = 0,
FSC_FAN_TABLE_LOAD_SUCCESS = 1,
/*Control mode*/
FSC_FAN_TABLE_AUTO = 0,
FSC_FAN_TABLE_MANUAL = 1,
/*Sensor present */
FSC_SENSOR_NOT_PRESENT = 0,
FSC_SENSOR_PRESENT = 1,
/*Sensor present */
FSC_SENSOR_NORMAL = 0,
FSC_SENSOR_ABNORMAL = 1,
/*Fan type */
FSC_FAN_TYPE_SINGLE = 0,
FSC_FAN_TYPE_TWIN = 1,
/*Fan status */
FSC_FAN_NORMAL = 0,
FSC_FAN_FAIL = 1,
/*Fsc work when dc off */
FSC_WORK_DC_ON_ONLY = 0,
FSC_WORK_DC_OFF = 1,
/*Fan fail handle type */
FSC_ABNORMAL_POLICY_UNUSED = 0,
FSC_ABNORMAL_POLICY_INCREASE = 1,
FSC_ABNORMAL_POLICY_CONSTANT = 2,
/*FSC normal or abnormal */
FSC_NORMAL = 0,
FSC_ABNORMAL = 1,
/*Thermal debug */
FSC_NO_THERMAL_DEBUG = 0,
FSC_OPEN_THERMAL_DEBUG = 1,
}EFscFlag;
typedef struct
{
char acProject[MAX_KEY_LENGTH];
char acCustomer[MAX_KEY_LENGTH];
char acVersion[MAX_KEY_LENGTH];
char acPlatform[MAX_KEY_LENGTH];
}__attribute__ ((packed))SFscHeader;
typedef struct
{
INT8U u8MaxReadingCache;
INT16U u16Elevation;
char acFanType[MAX_KEY_LENGTH];
char acWorkDCOff[MAX_KEY_LENGTH];
}__attribute__ ((packed))SFscGlobalConfig;
typedef struct
{
INT8U u8MaxPwmNum;
INT8U u8MaxFanNum;
INT8U u8FanSensorNumPWMMatch[MAX_FAN_COUNT];
INT8U u8MaxFanDuty;
INT8U u8MinFanDuty;
}__attribute__ ((packed))SFscFanConfig;
typedef struct
{
char acCLSensorType[MAX_KEY_LENGTH];
char acCLSensorStatus[MAX_KEY_LENGTH];
INT8U u8DT;
char acSensorName[MAX_SENSOR_NAME_LENGTH + 1];
INT8S s8VendorSpec;
INT8S s8CustomerSpec;
char acSetpointType[MAX_KEY_LENGTH];
INT8S s8SetpointDefault;
char acSetpointCase[MAX_SETPOINT_CASE][MAX_KEY_LENGTH];
INT8S as8SetpointValue[MAX_SETPOINT_CASE];
char acSetpointCaseUse[MAX_KEY_LENGTH];
INT8U au8FanWeight[MAX_FSC_PWM_CHANNEL];
INT8U u8Hysteresis;
INT8S as8EValue[MAX_SENSOR_E_SECTION-1];
INT8S as8ECValue[MAX_SENSOR_EC_SECTION-1];
float afPValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
float afIValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
float afDValue[MAX_SENSOR_EC_SECTION][MAX_SENSOR_E_SECTION];
INT8U u8SensorNumber;
INT8S s8Setpoint;
double as8RealValue[MAX_READING_CACHE];
float fP;
float fI;
float fD;
INT8U u8SensorSDRPresent; /*sensor sdr present flag, 1 - present, 0 - not present*/
INT8U u8Present; /*sensor present flag, 1 - present, 0 - not present*/
INT8U u8Abnormal; /*sensor health flag, 1 - abnormal, 0 - normal*/
INT8U u8Health; /*sensor reading value status*/
INT8U u8NoReadingTries;
INT8U u8SensorStatus;
/* Event Flags description */
/* Bit 0 - Initialization Done */
/* Bit 1 - Update in Progress */
/* Bit 2 - reserved */
/* Bit 3 - reserved */
/* Bit 4 - reserved */
/* Bit 5 - Unable to read */
/* Bit 6 - Sensor Scanning disabled */
/* Bit 7 - Event Message Disabled */
INT32U u32CalculateTick;
INT8U u8PwmPIDCalculate;
INT16S s16LastPwmPIDCalculate;
double dPIncrement;
double dIIncrement;
double dDIncrement;
INT8U u8PwmAfterWeighting[MAX_FSC_PWM_CHANNEL];
INT8U u8PwmAfterWeightingCache[MAX_FSC_PWM_CHANNEL][MAX_FAN_AVERAGE_COUNT];
INT8U u8PwmAfterHysteresis[MAX_FSC_PWM_CHANNEL];
INT8U u8SensorNoReading;
}__attribute__ ((packed))SFscCLSensorInfo;
typedef struct
{
INT8U u8MaxCLSensor;
INT8U u8TotalCLSensor;
char acPIDAdjustMethod[MAX_KEY_LENGTH];
INT8U u8CLSensorESection;
INT8U u8CLSensorECSection;
INT8U u8CLSensorSetpointMaxCase;
SFscCLSensorInfo asFscCLSensorInfo[MAX_CL_SENSOR];
}__attribute__ ((packed))SFscCLSensor;
typedef struct
{
INT8U u8FanSensorNumberStart;
char acFanFailSingle[MAX_KEY_LENGTH];
INT8U u8FanFailTwin1;
INT8U u8FanFailTwin2Diff;
char acFanFailTwin2Same[MAX_KEY_LENGTH];
/*fan status: 0 - normal, 1 - abnormal */
INT8U au8FanStatus[MAX_FAN_COUNT];
INT8U au8FanFailPwm[MAX_FSC_PWM_CHANNEL];
INT8U au8FanFailConstantPwm;
INT8U u8FanFailHandleType;
}__attribute__ ((packed))SFscFanFail;
typedef struct
{
char acSensorName[MAX_SENSOR_NAME_LENGTH];
char acFailPolicy[MAX_KEY_LENGTH];
INT8U u8FailValue;
INT8U u8SensorFailHandleType;
INT8U u8SensorFailPwmOut;
}__attribute__ ((packed))SFscSensorFailInfo;
typedef struct
{
INT8U u8MaxAbnormalSensor;
INT8U u8TotalAbnormalSensor;
SFscFanFail sFscFanFail;
SFscSensorFailInfo asFscSensorFailInfo[MAX_ABNORMAL_SENSOR];
}__attribute__ ((packed))SFscAbnormalEvent;
typedef struct
{
INT8U u8UpdateFlag; /*1 - update, 0 - normal */
INT8U u8FanTableLoadStatus; /*1 - success, 0 - fail */
INT8U u8ControlMode; /*1 - manual, 0 - auto */
INT8U u8ThermalDebug; /*thermal debug falg, 0 - no debug, 1 - debuging */
INT8U u8WorkDCOff; /*1 - work when dc off, 0 - no work when dc off */
INT8U u8LoadTableTries;
INT32U u32Tick;
INT8U u8SKUID;
INT8U u8MaxOLPwm;
INT8U au8CLPwm[MAX_FSC_PWM_CHANNEL];
INT8U au8MaxAbnormalPwm;
INT8U au8MaxAbnormalIncreasePwm;
char acFactorSensorName[16];
INT8U u8FactorPwm;
INT8U u8FscStatus; /*0 - normal fsc, 1 - abnormal fsc */
INT8U au8PwmOut[MAX_FSC_PWM_CHANNEL];
INT8U au8ManualPwmOut[MAX_FSC_PWM_CHANNEL];
INT8U u8MaxCoverTemp;
double u16DIMMTotalPower;
INT8U u8MaxDIMMSensorTemp;
double u8DIMMGroupMaxTemp[4];
double u8DIMMGroupMinTemp[4];
}__attribute__ ((packed))SFscRunningInfo;
typedef struct
{
SFscHeader sFSCHeader;
SFscGlobalConfig sFscGlobalConfig;
SFscFanConfig sFscFanConfig;
SFscCLSensor sFscCLSensor;
SFscAbnormalEvent sFscAbnormalEvent;
SFscRunningInfo sFscRunningInfo;
}__attribute__ ((packed))SFscInfo;
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,712 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_base
*
* Description :
* base, include base typedef, base define, base enum
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/03/23 xxx 0.01 First draft
***********************************************************/
#ifndef __LUX_BASE_H__
#define __LUX_BASE_H__
/***********************************************************
*
* Base Include Zone
*
***********************************************************/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <semaphore.h>
#include <mqueue.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/route.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <dirent.h>
/***********************************************************
*
* Base Typedef Zone
*
***********************************************************/
typedef unsigned char INT8U;
typedef unsigned short INT16U;
typedef unsigned int INT32U;
typedef signed char INT8S;
typedef short INT16S;
typedef long INT32S;
/***********************************************************
*
* Base Define Zone
*
***********************************************************/
#define SHM_KEY "/LuxShare"
#define NV_SETTING_FILE "/conf/bmc.setting"
/*Queue Name Define*/
#define QUEUE_NAME_BLOCK0 "QueueBlock0"
#define QUEUE_NAME_BLOCK1 "QueueBlock1"
#define QUEUE_NAME_BLOCK2 "QueueBlock2"
#define QUEUE_NAME_REDIS_HANDLER "RedisHandler"
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define PRINT printf
#define SHOW_RUNNING PRINT("# %s Running ......\n", __FUNCTION__)
#define ERROR_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define NORMAL_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define WARN_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define DEBUG_PRINT PRINT("[(%s)%04d]%s():", __FILE__, __LINE__, __FUNCTION__), PRINT
#define LUX_SLEEP(Seconds, MSeconds) \
do{\
struct timeval TimeInterval;\
TimeInterval.tv_sec = Seconds;\
TimeInterval.tv_usec = MSeconds*1000;\
select(0, NULL, NULL, NULL, &TimeInterval);\
}while(0)
/***********************************************************
*
* Base Enum Zone
*
***********************************************************/
/*Common Code*/
typedef enum
{
DISABLE_STATE=0,
ENABLE_STATE=1,
INVALID_STATE=0,
VALID_STATE=1,
ABSENT_STATE=0,
PRESENT_STATE=1,
FALSE_STATE=0,
TRUE_STATE=1,
NO_STATE=0,
YES_STATE=1,
CABLE_PRESENT_ONLY=2,
}ECommonCode;
/*Function Return Code */
typedef enum
{
FUNC_FILE_OPEN_FAIL = -1,
FUNC_LIB_OPEN_FAIL = -1,
FUNC_FAIL_N1 = -1,
FUNC_OK=0,
FUNC_FAILED,
}EFuncRetCode;
/*EBits Define*/
typedef enum
{
BIT0=(1<<0),
BIT1=(1<<1),
BIT2=(1<<2),
BIT3=(1<<3),
BIT4=(1<<4),
BIT5=(1<<5),
BIT6=(1<<6),
BIT7=(1<<7),
BIT8=(1<<8),
BIT9=(1<<9),
BIT10=(1<<10),
BIT11=(1<<11),
BIT12=(1<<12),
BIT13=(1<<13),
BIT14=(1<<14),
BIT15=(1<<15),
BIT16=(1<<16),
BIT17=(1<<17),
BIT18=(1<<18),
BIT19=(1<<19),
BIT20=(1<<20),
BIT21=(1<<21),
BIT22=(1<<22),
BIT23=(1<<23),
BIT24=(1<<24),
BIT25=(1<<25),
BIT26=(1<<26),
BIT27=(1<<27),
BIT28=(1<<28),
BIT29=(1<<29),
BIT30=(1<<30),
BIT31=(1<<31),
BIT0_1=(BIT0|BIT1),
BIT0_2=(BIT0_1|BIT2),
BIT0_3=(BIT0_2|BIT3),
BIT0_4=(BIT0_3|BIT4),
BIT0_5=(BIT0_4|BIT5),
BIT0_6=(BIT0_5|BIT6),
BIT0_7=(BIT0_6|BIT7),
BIT0_8=(BIT0_7|BIT8),
BIT0_9=(BIT0_8|BIT9),
BIT0_10=(BIT0_9|BIT10),
BIT0_11=(BIT0_10|BIT11),
BIT0_12=(BIT0_11|BIT12),
BIT0_13=(BIT0_12|BIT13),
BIT0_14=(BIT0_13|BIT14),
BIT0_15=(BIT0_14|BIT15),
BIT0_16=(BIT0_15|BIT16),
BIT0_17=(BIT0_16|BIT17),
BIT0_18=(BIT0_17|BIT18),
BIT0_19=(BIT0_18|BIT19),
BIT0_20=(BIT0_19|BIT20),
BIT0_21=(BIT0_20|BIT21),
BIT0_22=(BIT0_21|BIT22),
BIT0_23=(BIT0_22|BIT23),
BIT0_24=(BIT0_23|BIT24),
BIT0_25=(BIT0_24|BIT25),
BIT0_26=(BIT0_25|BIT26),
BIT0_27=(BIT0_26|BIT27),
BIT0_28=(BIT0_27|BIT28),
BIT0_29=(BIT0_28|BIT29),
BIT0_30=(BIT0_29|BIT30),
BIT0_31=(BIT0_30|BIT31),
BIT1_2=(BIT1|BIT2),
BIT1_3=(BIT1_2|BIT3),
BIT1_4=(BIT1_3|BIT4),
BIT1_5=(BIT1_4|BIT5),
BIT1_6=(BIT1_5|BIT6),
BIT1_7=(BIT1_6|BIT7),
BIT1_8=(BIT1_7|BIT8),
BIT1_9=(BIT1_8|BIT9),
BIT1_10=(BIT1_9|BIT10),
BIT1_11=(BIT1_10|BIT11),
BIT1_12=(BIT1_11|BIT12),
BIT1_13=(BIT1_12|BIT13),
BIT1_14=(BIT1_13|BIT14),
BIT1_15=(BIT1_14|BIT15),
BIT1_16=(BIT1_15|BIT16),
BIT1_17=(BIT1_16|BIT17),
BIT1_18=(BIT1_17|BIT18),
BIT1_19=(BIT1_18|BIT19),
BIT1_20=(BIT1_19|BIT20),
BIT1_21=(BIT1_20|BIT21),
BIT1_22=(BIT1_21|BIT22),
BIT1_23=(BIT1_22|BIT23),
BIT1_24=(BIT1_23|BIT24),
BIT1_25=(BIT1_24|BIT25),
BIT1_26=(BIT1_25|BIT26),
BIT1_27=(BIT1_26|BIT27),
BIT1_28=(BIT1_27|BIT28),
BIT1_29=(BIT1_28|BIT29),
BIT1_30=(BIT1_29|BIT30),
BIT1_31=(BIT1_30|BIT31),
BIT2_3=(BIT2|BIT3),
BIT2_4=(BIT2_3|BIT4),
BIT2_5=(BIT2_4|BIT5),
BIT2_6=(BIT2_5|BIT6),
BIT2_7=(BIT2_6|BIT7),
BIT2_8=(BIT2_7|BIT8),
BIT2_9=(BIT2_8|BIT9),
BIT2_10=(BIT2_9|BIT10),
BIT2_11=(BIT2_10|BIT11),
BIT2_12=(BIT2_11|BIT12),
BIT2_13=(BIT2_12|BIT13),
BIT2_14=(BIT2_13|BIT14),
BIT2_15=(BIT2_14|BIT15),
BIT2_16=(BIT2_15|BIT16),
BIT2_17=(BIT2_16|BIT17),
BIT2_18=(BIT2_17|BIT18),
BIT2_19=(BIT2_18|BIT19),
BIT2_20=(BIT2_19|BIT20),
BIT2_21=(BIT2_20|BIT21),
BIT2_22=(BIT2_21|BIT22),
BIT2_23=(BIT2_22|BIT23),
BIT2_24=(BIT2_23|BIT24),
BIT2_25=(BIT2_24|BIT25),
BIT2_26=(BIT2_25|BIT26),
BIT2_27=(BIT2_26|BIT27),
BIT2_28=(BIT2_27|BIT28),
BIT2_29=(BIT2_28|BIT29),
BIT2_30=(BIT2_29|BIT30),
BIT2_31=(BIT2_30|BIT31),
BIT3_4=(BIT3|BIT4),
BIT3_5=(BIT3_4|BIT5),
BIT3_6=(BIT3_5|BIT6),
BIT3_7=(BIT3_6|BIT7),
BIT3_8=(BIT3_7|BIT8),
BIT3_9=(BIT3_8|BIT9),
BIT3_10=(BIT3_9|BIT10),
BIT3_11=(BIT3_10|BIT11),
BIT3_12=(BIT3_11|BIT12),
BIT3_13=(BIT3_12|BIT13),
BIT3_14=(BIT3_13|BIT14),
BIT3_15=(BIT3_14|BIT15),
BIT3_16=(BIT3_15|BIT16),
BIT3_17=(BIT3_16|BIT17),
BIT3_18=(BIT3_17|BIT18),
BIT3_19=(BIT3_18|BIT19),
BIT3_20=(BIT3_19|BIT20),
BIT3_21=(BIT3_20|BIT21),
BIT3_22=(BIT3_21|BIT22),
BIT3_23=(BIT3_22|BIT23),
BIT3_24=(BIT3_23|BIT24),
BIT3_25=(BIT3_24|BIT25),
BIT3_26=(BIT3_25|BIT26),
BIT3_27=(BIT3_26|BIT27),
BIT3_28=(BIT3_27|BIT28),
BIT3_29=(BIT3_28|BIT29),
BIT3_30=(BIT3_29|BIT30),
BIT3_31=(BIT3_30|BIT31),
BIT4_5=(BIT4|BIT5),
BIT4_6=(BIT4_5|BIT6),
BIT4_7=(BIT4_6|BIT7),
BIT4_8=(BIT4_7|BIT8),
BIT4_9=(BIT4_8|BIT9),
BIT4_10=(BIT4_9|BIT10),
BIT4_11=(BIT4_10|BIT11),
BIT4_12=(BIT4_11|BIT12),
BIT4_13=(BIT4_12|BIT13),
BIT4_14=(BIT4_13|BIT14),
BIT4_15=(BIT4_14|BIT15),
BIT4_16=(BIT4_15|BIT16),
BIT4_17=(BIT4_16|BIT17),
BIT4_18=(BIT4_17|BIT18),
BIT4_19=(BIT4_18|BIT19),
BIT4_20=(BIT4_19|BIT20),
BIT4_21=(BIT4_20|BIT21),
BIT4_22=(BIT4_21|BIT22),
BIT4_23=(BIT4_22|BIT23),
BIT4_24=(BIT4_23|BIT24),
BIT4_25=(BIT4_24|BIT25),
BIT4_26=(BIT4_25|BIT26),
BIT4_27=(BIT4_26|BIT27),
BIT4_28=(BIT4_27|BIT28),
BIT4_29=(BIT4_28|BIT29),
BIT4_30=(BIT4_29|BIT30),
BIT4_31=(BIT4_30|BIT31),
BIT5_6=(BIT5|BIT6),
BIT5_7=(BIT5_6|BIT7),
BIT5_8=(BIT5_7|BIT8),
BIT5_9=(BIT5_8|BIT9),
BIT5_10=(BIT5_9|BIT10),
BIT5_11=(BIT5_10|BIT11),
BIT5_12=(BIT5_11|BIT12),
BIT5_13=(BIT5_12|BIT13),
BIT5_14=(BIT5_13|BIT14),
BIT5_15=(BIT5_14|BIT15),
BIT5_16=(BIT5_15|BIT16),
BIT5_17=(BIT5_16|BIT17),
BIT5_18=(BIT5_17|BIT18),
BIT5_19=(BIT5_18|BIT19),
BIT5_20=(BIT5_19|BIT20),
BIT5_21=(BIT5_20|BIT21),
BIT5_22=(BIT5_21|BIT22),
BIT5_23=(BIT5_22|BIT23),
BIT5_24=(BIT5_23|BIT24),
BIT5_25=(BIT5_24|BIT25),
BIT5_26=(BIT5_25|BIT26),
BIT5_27=(BIT5_26|BIT27),
BIT5_28=(BIT5_27|BIT28),
BIT5_29=(BIT5_28|BIT29),
BIT5_30=(BIT5_29|BIT30),
BIT5_31=(BIT5_30|BIT31),
BIT6_7=(BIT6|BIT7),
BIT6_8=(BIT6_7|BIT8),
BIT6_9=(BIT6_8|BIT9),
BIT6_10=(BIT6_9|BIT10),
BIT6_11=(BIT6_10|BIT11),
BIT6_12=(BIT6_11|BIT12),
BIT6_13=(BIT6_12|BIT13),
BIT6_14=(BIT6_13|BIT14),
BIT6_15=(BIT6_14|BIT15),
BIT6_16=(BIT6_15|BIT16),
BIT6_17=(BIT6_16|BIT17),
BIT6_18=(BIT6_17|BIT18),
BIT6_19=(BIT6_18|BIT19),
BIT6_20=(BIT6_19|BIT20),
BIT6_21=(BIT6_20|BIT21),
BIT6_22=(BIT6_21|BIT22),
BIT6_23=(BIT6_22|BIT23),
BIT6_24=(BIT6_23|BIT24),
BIT6_25=(BIT6_24|BIT25),
BIT6_26=(BIT6_25|BIT26),
BIT6_27=(BIT6_26|BIT27),
BIT6_28=(BIT6_27|BIT28),
BIT6_29=(BIT6_28|BIT29),
BIT6_30=(BIT6_29|BIT30),
BIT6_31=(BIT6_30|BIT31),
BIT7_8=(BIT7|BIT8),
BIT7_9=(BIT7_8|BIT9),
BIT7_10=(BIT7_9|BIT10),
BIT7_11=(BIT7_10|BIT11),
BIT7_12=(BIT7_11|BIT12),
BIT7_13=(BIT7_12|BIT13),
BIT7_14=(BIT7_13|BIT14),
BIT7_15=(BIT7_14|BIT15),
BIT7_16=(BIT7_15|BIT16),
BIT7_17=(BIT7_16|BIT17),
BIT7_18=(BIT7_17|BIT18),
BIT7_19=(BIT7_18|BIT19),
BIT7_20=(BIT7_19|BIT20),
BIT7_21=(BIT7_20|BIT21),
BIT7_22=(BIT7_21|BIT22),
BIT7_23=(BIT7_22|BIT23),
BIT7_24=(BIT7_23|BIT24),
BIT7_25=(BIT7_24|BIT25),
BIT7_26=(BIT7_25|BIT26),
BIT7_27=(BIT7_26|BIT27),
BIT7_28=(BIT7_27|BIT28),
BIT7_29=(BIT7_28|BIT29),
BIT7_30=(BIT7_29|BIT30),
BIT7_31=(BIT7_30|BIT31),
BIT8_9=(BIT8|BIT9),
BIT8_10=(BIT8_9|BIT10),
BIT8_11=(BIT8_10|BIT11),
BIT8_12=(BIT8_11|BIT12),
BIT8_13=(BIT8_12|BIT13),
BIT8_14=(BIT8_13|BIT14),
BIT8_15=(BIT8_14|BIT15),
BIT8_16=(BIT8_15|BIT16),
BIT8_17=(BIT8_16|BIT17),
BIT8_18=(BIT8_17|BIT18),
BIT8_19=(BIT8_18|BIT19),
BIT8_20=(BIT8_19|BIT20),
BIT8_21=(BIT8_20|BIT21),
BIT8_22=(BIT8_21|BIT22),
BIT8_23=(BIT8_22|BIT23),
BIT8_24=(BIT8_23|BIT24),
BIT8_25=(BIT8_24|BIT25),
BIT8_26=(BIT8_25|BIT26),
BIT8_27=(BIT8_26|BIT27),
BIT8_28=(BIT8_27|BIT28),
BIT8_29=(BIT8_28|BIT29),
BIT8_30=(BIT8_29|BIT30),
BIT8_31=(BIT8_30|BIT31),
BIT9_10=(BIT9|BIT10),
BIT9_11=(BIT9_10|BIT11),
BIT9_12=(BIT9_11|BIT12),
BIT9_13=(BIT9_12|BIT13),
BIT9_14=(BIT9_13|BIT14),
BIT9_15=(BIT9_14|BIT15),
BIT9_16=(BIT9_15|BIT16),
BIT9_17=(BIT9_16|BIT17),
BIT9_18=(BIT9_17|BIT18),
BIT9_19=(BIT9_18|BIT19),
BIT9_20=(BIT9_19|BIT20),
BIT9_21=(BIT9_20|BIT21),
BIT9_22=(BIT9_21|BIT22),
BIT9_23=(BIT9_22|BIT23),
BIT9_24=(BIT9_23|BIT24),
BIT9_25=(BIT9_24|BIT25),
BIT9_26=(BIT9_25|BIT26),
BIT9_27=(BIT9_26|BIT27),
BIT9_28=(BIT9_27|BIT28),
BIT9_29=(BIT9_28|BIT29),
BIT9_30=(BIT9_29|BIT30),
BIT9_31=(BIT9_30|BIT31),
BIT10_11=(BIT10|BIT11),
BIT10_12=(BIT10_11|BIT12),
BIT10_13=(BIT10_12|BIT13),
BIT10_14=(BIT10_13|BIT14),
BIT10_15=(BIT10_14|BIT15),
BIT10_16=(BIT10_15|BIT16),
BIT10_17=(BIT10_16|BIT17),
BIT10_18=(BIT10_17|BIT18),
BIT10_19=(BIT10_18|BIT19),
BIT10_20=(BIT10_19|BIT20),
BIT10_21=(BIT10_20|BIT21),
BIT10_22=(BIT10_21|BIT22),
BIT10_23=(BIT10_22|BIT23),
BIT10_24=(BIT10_23|BIT24),
BIT10_25=(BIT10_24|BIT25),
BIT10_26=(BIT10_25|BIT26),
BIT10_27=(BIT10_26|BIT27),
BIT10_28=(BIT10_27|BIT28),
BIT10_29=(BIT10_28|BIT29),
BIT10_30=(BIT10_29|BIT30),
BIT10_31=(BIT10_30|BIT31),
BIT11_12=(BIT11|BIT12),
BIT11_13=(BIT11_12|BIT13),
BIT11_14=(BIT11_13|BIT14),
BIT11_15=(BIT11_14|BIT15),
BIT11_16=(BIT11_15|BIT16),
BIT11_17=(BIT11_16|BIT17),
BIT11_18=(BIT11_17|BIT18),
BIT11_19=(BIT11_18|BIT19),
BIT11_20=(BIT11_19|BIT20),
BIT11_21=(BIT11_20|BIT21),
BIT11_22=(BIT11_21|BIT22),
BIT11_23=(BIT11_22|BIT23),
BIT11_24=(BIT11_23|BIT24),
BIT11_25=(BIT11_24|BIT25),
BIT11_26=(BIT11_25|BIT26),
BIT11_27=(BIT11_26|BIT27),
BIT11_28=(BIT11_27|BIT28),
BIT11_29=(BIT11_28|BIT29),
BIT11_30=(BIT11_29|BIT30),
BIT11_31=(BIT11_30|BIT31),
BIT12_13=(BIT12|BIT13),
BIT12_14=(BIT12_13|BIT14),
BIT12_15=(BIT12_14|BIT15),
BIT12_16=(BIT12_15|BIT16),
BIT12_17=(BIT12_16|BIT17),
BIT12_18=(BIT12_17|BIT18),
BIT12_19=(BIT12_18|BIT19),
BIT12_20=(BIT12_19|BIT20),
BIT12_21=(BIT12_20|BIT21),
BIT12_22=(BIT12_21|BIT22),
BIT12_23=(BIT12_22|BIT23),
BIT12_24=(BIT12_23|BIT24),
BIT12_25=(BIT12_24|BIT25),
BIT12_26=(BIT12_25|BIT26),
BIT12_27=(BIT12_26|BIT27),
BIT12_28=(BIT12_27|BIT28),
BIT12_29=(BIT12_28|BIT29),
BIT12_30=(BIT12_29|BIT30),
BIT12_31=(BIT12_30|BIT31),
BIT13_14=(BIT13|BIT14),
BIT13_15=(BIT13_14|BIT15),
BIT13_16=(BIT13_15|BIT16),
BIT13_17=(BIT13_16|BIT17),
BIT13_18=(BIT13_17|BIT18),
BIT13_19=(BIT13_18|BIT19),
BIT13_20=(BIT13_19|BIT20),
BIT13_21=(BIT13_20|BIT21),
BIT13_22=(BIT13_21|BIT22),
BIT13_23=(BIT13_22|BIT23),
BIT13_24=(BIT13_23|BIT24),
BIT13_25=(BIT13_24|BIT25),
BIT13_26=(BIT13_25|BIT26),
BIT13_27=(BIT13_26|BIT27),
BIT13_28=(BIT13_27|BIT28),
BIT13_29=(BIT13_28|BIT29),
BIT13_30=(BIT13_29|BIT30),
BIT13_31=(BIT13_30|BIT31),
BIT14_15=(BIT14|BIT15),
BIT14_16=(BIT14_15|BIT16),
BIT14_17=(BIT14_16|BIT17),
BIT14_18=(BIT14_17|BIT18),
BIT14_19=(BIT14_18|BIT19),
BIT14_20=(BIT14_19|BIT20),
BIT14_21=(BIT14_20|BIT21),
BIT14_22=(BIT14_21|BIT22),
BIT14_23=(BIT14_22|BIT23),
BIT14_24=(BIT14_23|BIT24),
BIT14_25=(BIT14_24|BIT25),
BIT14_26=(BIT14_25|BIT26),
BIT14_27=(BIT14_26|BIT27),
BIT14_28=(BIT14_27|BIT28),
BIT14_29=(BIT14_28|BIT29),
BIT14_30=(BIT14_29|BIT30),
BIT14_31=(BIT14_30|BIT31),
BIT15_16=(BIT15|BIT16),
BIT15_17=(BIT15_16|BIT17),
BIT15_18=(BIT15_17|BIT18),
BIT15_19=(BIT15_18|BIT19),
BIT15_20=(BIT15_19|BIT20),
BIT15_21=(BIT15_20|BIT21),
BIT15_22=(BIT15_21|BIT22),
BIT15_23=(BIT15_22|BIT23),
BIT15_24=(BIT15_23|BIT24),
BIT15_25=(BIT15_24|BIT25),
BIT15_26=(BIT15_25|BIT26),
BIT15_27=(BIT15_26|BIT27),
BIT15_28=(BIT15_27|BIT28),
BIT15_29=(BIT15_28|BIT29),
BIT15_30=(BIT15_29|BIT30),
BIT15_31=(BIT15_30|BIT31),
BIT16_17=(BIT16|BIT17),
BIT16_18=(BIT16_17|BIT18),
BIT16_19=(BIT16_18|BIT19),
BIT16_20=(BIT16_19|BIT20),
BIT16_21=(BIT16_20|BIT21),
BIT16_22=(BIT16_21|BIT22),
BIT16_23=(BIT16_22|BIT23),
BIT16_24=(BIT16_23|BIT24),
BIT16_25=(BIT16_24|BIT25),
BIT16_26=(BIT16_25|BIT26),
BIT16_27=(BIT16_26|BIT27),
BIT16_28=(BIT16_27|BIT28),
BIT16_29=(BIT16_28|BIT29),
BIT16_30=(BIT16_29|BIT30),
BIT16_31=(BIT16_30|BIT31),
BIT17_18=(BIT17|BIT18),
BIT17_19=(BIT17_18|BIT19),
BIT17_20=(BIT17_19|BIT20),
BIT17_21=(BIT17_20|BIT21),
BIT17_22=(BIT17_21|BIT22),
BIT17_23=(BIT17_22|BIT23),
BIT17_24=(BIT17_23|BIT24),
BIT17_25=(BIT17_24|BIT25),
BIT17_26=(BIT17_25|BIT26),
BIT17_27=(BIT17_26|BIT27),
BIT17_28=(BIT17_27|BIT28),
BIT17_29=(BIT17_28|BIT29),
BIT17_30=(BIT17_29|BIT30),
BIT17_31=(BIT17_30|BIT31),
BIT18_19=(BIT18|BIT19),
BIT18_20=(BIT18_19|BIT20),
BIT18_21=(BIT18_20|BIT21),
BIT18_22=(BIT18_21|BIT22),
BIT18_23=(BIT18_22|BIT23),
BIT18_24=(BIT18_23|BIT24),
BIT18_25=(BIT18_24|BIT25),
BIT18_26=(BIT18_25|BIT26),
BIT18_27=(BIT18_26|BIT27),
BIT18_28=(BIT18_27|BIT28),
BIT18_29=(BIT18_28|BIT29),
BIT18_30=(BIT18_29|BIT30),
BIT18_31=(BIT18_30|BIT31),
BIT19_20=(BIT19|BIT20),
BIT19_21=(BIT19_20|BIT21),
BIT19_22=(BIT19_21|BIT22),
BIT19_23=(BIT19_22|BIT23),
BIT19_24=(BIT19_23|BIT24),
BIT19_25=(BIT19_24|BIT25),
BIT19_26=(BIT19_25|BIT26),
BIT19_27=(BIT19_26|BIT27),
BIT19_28=(BIT19_27|BIT28),
BIT19_29=(BIT19_28|BIT29),
BIT19_30=(BIT19_29|BIT30),
BIT19_31=(BIT19_30|BIT31),
BIT20_21=(BIT20|BIT21),
BIT20_22=(BIT20_21|BIT22),
BIT20_23=(BIT20_22|BIT23),
BIT20_24=(BIT20_23|BIT24),
BIT20_25=(BIT20_24|BIT25),
BIT20_26=(BIT20_25|BIT26),
BIT20_27=(BIT20_26|BIT27),
BIT20_28=(BIT20_27|BIT28),
BIT20_29=(BIT20_28|BIT29),
BIT20_30=(BIT20_29|BIT30),
BIT20_31=(BIT20_30|BIT31),
BIT21_22=(BIT21|BIT22),
BIT21_23=(BIT21_22|BIT23),
BIT21_24=(BIT21_23|BIT24),
BIT21_25=(BIT21_24|BIT25),
BIT21_26=(BIT21_25|BIT26),
BIT21_27=(BIT21_26|BIT27),
BIT21_28=(BIT21_27|BIT28),
BIT21_29=(BIT21_28|BIT29),
BIT21_30=(BIT21_29|BIT30),
BIT21_31=(BIT21_30|BIT31),
BIT22_23=(BIT22|BIT23),
BIT22_24=(BIT22_23|BIT24),
BIT22_25=(BIT22_24|BIT25),
BIT22_26=(BIT22_25|BIT26),
BIT22_27=(BIT22_26|BIT27),
BIT22_28=(BIT22_27|BIT28),
BIT22_29=(BIT22_28|BIT29),
BIT22_30=(BIT22_29|BIT30),
BIT22_31=(BIT22_30|BIT31),
BIT23_24=(BIT23|BIT24),
BIT23_25=(BIT23_24|BIT25),
BIT23_26=(BIT23_25|BIT26),
BIT23_27=(BIT23_26|BIT27),
BIT23_28=(BIT23_27|BIT28),
BIT23_29=(BIT23_28|BIT29),
BIT23_30=(BIT23_29|BIT30),
BIT23_31=(BIT23_30|BIT31),
BIT24_25=(BIT24|BIT25),
BIT24_26=(BIT24_25|BIT26),
BIT24_27=(BIT24_26|BIT27),
BIT24_28=(BIT24_27|BIT28),
BIT24_29=(BIT24_28|BIT29),
BIT24_30=(BIT24_29|BIT30),
BIT24_31=(BIT24_30|BIT31),
BIT25_26=(BIT25|BIT26),
BIT25_27=(BIT25_26|BIT27),
BIT25_28=(BIT25_27|BIT28),
BIT25_29=(BIT25_28|BIT29),
BIT25_30=(BIT25_29|BIT30),
BIT25_31=(BIT25_30|BIT31),
BIT26_27=(BIT26|BIT27),
BIT26_28=(BIT26_27|BIT28),
BIT26_29=(BIT26_28|BIT29),
BIT26_30=(BIT26_29|BIT30),
BIT26_31=(BIT26_30|BIT31),
BIT27_28=(BIT27|BIT28),
BIT27_29=(BIT27_28|BIT29),
BIT27_30=(BIT27_29|BIT30),
BIT27_31=(BIT27_30|BIT31),
BIT28_29=(BIT28|BIT29),
BIT28_30=(BIT28_29|BIT30),
BIT28_31=(BIT28_30|BIT31),
BIT29_30=(BIT29|BIT30),
BIT29_31=(BIT29_30|BIT31),
BIT30_31=(BIT30|BIT31),
}EBits;
#endif
@@ -0,0 +1,913 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_json_api
*
* Description :
* JSON API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/04/21 Laurence Zhou 0.01 First draft
***********************************************************/
#include "lux_json_api.h"
/***********************************************************
* Name:
* LuxcJSONParseJsonFile
*
* Summary:
* parse JSON file to get the HEAD pointer(note: remeber to call Luxcjsondelete() to free memory)
*
* Return Value:
* The LuxcJSONParseJsonFile() function returns a HEAD pointer to HEAD node of the Doubly Linked List
*
* Parameter Input:
* char* pcFileName -- JSON file name with Absolute path
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
cJSON* LuxcJSONParseJsonFile(char* pcFileName)
{
long lLen = 0;
char* psBuf = NULL;
cJSON* psRoot = NULL;
if(NULL == pcFileName)
{
return NULL;
}
FILE* fp = LuxFopen(pcFileName, "rb+");
if (NULL == fp)
{
printf("open file %s failed.\n", pcFileName);
return NULL;
}
LuxFseek(fp, 0, SEEK_END);
lLen = LuxFtell(fp);
if (0 == lLen)
{
return NULL;
}
LuxFseek(fp, 0, SEEK_SET);
psBuf = (char *)LuxMalloc(sizeof(char) * lLen);
LuxFread(psBuf, 1, lLen, fp);
LuxFclose(fp);
cJSON_Minify(psBuf);
psRoot = cJSON_Parse(psBuf);
if (NULL == psRoot)
{
return NULL;
}
LuxFree(psBuf);
return psRoot;
}
/***********************************************************
* Name:
* LuxcJSONPrint
*
* Summary:
* Render a cJSON entity to text for transfer/storage(note: remeber to call Luxcjsonfree to free memory)
*
* Return Value:
* a string
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
char* LuxcJSONPrint(const cJSON* psItem)
{
if(NULL != psItem)
{
return cJSON_Print(psItem);
}
return NULL;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectItem
*
* Summary:
* Get item "pcKey" from psObject
*
* Return Value:
* Pointer to the "pcKey" cJSON node
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
**********************************************************/
cJSON* LuxcJSONGetObjectItem(const cJSON* const psObject, const char* const pcKey)
{
if(NULL == psObject)
{
return NULL;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return NULL;
}
if(NULL == pcKey)
{
return NULL;
}
cJSON* psTemp = NULL;
psTemp = cJSON_GetObjectItem(psObject, pcKey);
if (psTemp)
{
return psTemp;
}
else
{
return NULL;
}
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntValue
*
* Summary:
* Get int value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piValue -- Pointer that holds the int value
*
* Parameter Output:
* piVAlue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntValue(const cJSON* const psObject, const char* const pcKey,int* piValue )
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piValue)
{
return FUNC_FAILED;
}
if( NULL == (psItem = (cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
*piValue = psItem->valueint;
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleValue
*
* Summary:
* Get double value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double* pdValue -- Pointer that holds the double value
*
* Parameter Output:
* pdValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleValue(const cJSON* const psObject,const char* const pcKey, double* pdValue)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pdValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem = (cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
*pdValue = psItem->valuedouble;
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringSize
*
* Summary:
* Get the length of String
*
* Return Value:
* length of String
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetOjectStringSize(const cJSON* const psObject, const char* const pcKey, int *piSize)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
psItem = cJSON_GetObjectItem(psObject, pcKey);
*piSize = LuxStrlen(psItem->valuestring);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringValue
*
* Summary:
* Get string value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* char* pcValue -- Pointer that holds the String value
*
* Parameter Output:
* pcValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectStringValue(const cJSON* const psObject, const char* const pcKey, char* pcValue )
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pcValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem=(cJSON_GetObjectItem(psObject, pcKey))))
{
return FUNC_FAILED;
}
LuxStrcpy(pcValue,psItem->valuestring);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectBooleanValue
*
* Summary:
* Get boolean value
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psItem -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* cJSON_bool* pbValue -- Pointer that holds the boolean value
*
* Parameter Output:
* pbValue
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectBooleanValue(const cJSON* const psObject, const char* const pcKey, cJSON_bool* pbValue)
{
cJSON* psItem = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == pbValue)
{
return FUNC_FAILED;
}
if(NULL == (psItem = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
if(false == psItem->valueint)
{
*pbValue = false;
return FUNC_OK;
}
else
{
*pbValue = true;
return FUNC_OK;
}
}
/***********************************************************
* Name:
* LuxcJSONGetObjectArraySize
*
* Summary:
* Get the array size
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectArraySize(const cJSON* const psObject, const char* const pcKey, int* piSize)
{
cJSON* psArray = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
*piSize = cJSON_GetArraySize(psArray);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntArray
*
* Summary:
* Get the int array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piArray -- Pointer that holds the int array(if pass NULL to piArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* piArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntArray(const cJSON* const psObject, const char* const pcKey, int* piArray,int* piSize)
{
cJSON *psArray = NULL;
cJSON *psTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == piArray )
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0,j = 0; i < *piSize && j < *piSize; ++i,++j)
{
psTemp = cJSON_GetArrayItem(psArray, i);
piArray[j] = psTemp->valueint;
psTemp = NULL;
}
psArray = NULL;
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleArray
*
* Summary:
* Get the double array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double* piArray -- Pointer that holds the double array(if pass NULL to pdArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* pdArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleArray(const cJSON* const psObject, const char* const pcKey, double* pdArray, int* piSize )
{
cJSON *psArray = NULL;
cJSON *psTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == pdArray)
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0,j = 0; i < *piSize && j < *piSize; ++i,++j)
{
psTemp = cJSON_GetArrayItem(psArray, i);
pdArray[j] = psTemp->valuedouble;
psTemp = NULL;
}
psArray = NULL;
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectStringArray
*
* Summary:
* Get the string array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* char (*pcArray)[MAXSIZE] -- Pointer that holds the string array(if pass NULL to pcArray,we can get the array size)
* int* piSize -- Pointer that holds the array size
*
* Parameter Output:
* pcArray,piSize
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectStringArray(const cJSON* const psObject, const char* const pcKey, char (*pcArray)[MAXSIZE],int* piSize)
{
cJSON* pscJSONStringArray = NULL;
cJSON* pscJSONStringTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piSize)
{
return FUNC_FAILED;
}
if(NULL == pcArray)
{
if(FUNC_OK == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetObjectArraySize(psObject, pcKey, piSize))
{
return FUNC_FAILED;
}
if(NULL == (pscJSONStringArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piSize; ++i)
{
pscJSONStringTemp = cJSON_GetArrayItem(pscJSONStringArray, i);
LuxStrcpy(pcArray[i],pscJSONStringTemp->valuestring);
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetArrayRowColumnSize
*
* Summary:
* Get the two-dimensional array's row and column
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetArrayRowColumnSize(const cJSON* const psObject, const char* const pcKey,int* piRow,int* piColumn)
{
cJSON* psArray =NULL;
cJSON *psArray21 = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
*piRow = cJSON_GetArraySize(psArray);
if(NULL == (psArray21 = cJSON_GetArrayItem(psArray, 0)))
{
return FUNC_FAILED;
}
*piColumn = cJSON_GetArraySize(psArray21);
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectIntArray2
*
* Summary:
* Get the two-dimensional array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* int (*piArray2)[MAXSIZE] -- Pointer that holds the two-dimensional arrray
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* piArray2,piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectIntArray2(const cJSON* const psObject, const char* const pcKey, int (*piArray2)[MAXSIZE],int* piRow, int* piColumn)
{
cJSON *psArray = NULL;
cJSON *psArrayTemp = NULL;
cJSON *psValueTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == piArray2)
{
if(FUNC_OK == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piRow; ++i )
{
psArrayTemp = cJSON_GetArrayItem(psArray, i);
for(int j = 0; j < *piColumn; ++j){
psValueTemp = cJSON_GetArrayItem(psArrayTemp, j);
piArray2[i][j] = psValueTemp->valueint;
psValueTemp= NULL;
}
psArrayTemp = NULL;
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONGetObjectDoubleArray2
*
* Summary:
* Get the two-dimensional array
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* const cJSON* psObject -- The HEAD pointer of the CJSON entity
* const char* const pcKey -- Key/Name
* double (*piArray2)[MAXSIZE] -- Pointer that holds the two-dimensional arrray
* int* piRow -- Pointer that holds the row size
* int* piColumn -- Pointer that holds the column size
*
* Parameter Output:
* pdArray2,piRow,piColumn
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONGetObjectDoubleArray2(const cJSON* const psObject, const char* const pcKey, double (*pdArray2)[MAXSIZE],int* piRow, int* piColumn)
{
cJSON *psArray = NULL;
cJSON *psArrayTemp = NULL;
cJSON *PsValueTemp = NULL;
if(NULL == psObject)
{
return FUNC_FAILED;
}
if(false == cJSON_HasObjectItem(psObject, pcKey))
{
return FUNC_FAILED;
}
if(NULL == piRow || NULL == piColumn)
{
return FUNC_FAILED;
}
if(NULL == pdArray2)
{
if(FUNC_OK == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_OK;
}
}
else
{
if(FUNC_FAILED == LuxcJSONGetArrayRowColumnSize(psObject, pcKey, piRow, piColumn))
{
return FUNC_FAILED;
}
if(NULL == (psArray = cJSON_GetObjectItem(psObject, pcKey)))
{
return FUNC_FAILED;
}
for (int i = 0; i < *piRow; ++i )
{
psArrayTemp = cJSON_GetArrayItem(psArray, i);
for(int j = 0; j < *piColumn; ++j)
{
PsValueTemp = cJSON_GetArrayItem(psArrayTemp, j);
pdArray2[i][j] = PsValueTemp->valuedouble;
PsValueTemp = NULL;
}
psArrayTemp = NULL;
}
return FUNC_OK;
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONDelete
*
* Summary:
* Delete a cJSON entity and all subentities
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* cJSON* psItem -- the HEAD pointer
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONDelete(cJSON* psItem)
{
if(NULL != psItem)
{
cJSON_Delete(psItem);
}
return FUNC_OK;
}
/***********************************************************
* Name:
* LuxcJSONFree
*
* Summary:
* free object
*
* Return Value:
* EFuncRetCode(FUNC_FAILED or FUNC_OK)
*
* Parameter Input:
* cJSON* psItem -- the HEAD pointer
*
* Parameter Output:
* None
*
* Author:
* Laurence.Zhou@luxshare-ict.com: Initial Version
*
***********************************************************/
EFuncRetCode LuxcJSONFree(void* psObject)
{
if(NULL != psObject)
{
cJSON_free(psObject);
}
return FUNC_OK;
}
@@ -0,0 +1,56 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : LuxcJSON
*
* Description :
* JSON API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/04/21 Laurence Zhou 0.01 First draft
***********************************************************/
#ifndef LUX_JSON_API_H
#define LUX_JSON_API_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
#include "lux_system_api.h"
#define MAXSIZE 128
#ifdef true
#undef true
#endif
#define true ((cJSON_bool)1)
#ifdef false
#undef false
#endif
#define false ((cJSON_bool)0)
extern cJSON* LuxcJSONParseJsonFile(char* pcFileName);
extern char* LuxcJSONPrint(const cJSON* psItem);
extern cJSON* LuxcJSONGetObjectItem(const cJSON* const psObject, const char* const pcKey);
extern EFuncRetCode LuxcJSONGetObjectIntValue(const cJSON* const psObject, const char* const pcKey,int* piValue );
extern EFuncRetCode LuxcJSONGetObjectDoubleValue(const cJSON* const psObject,const char* const pcKey, double* pdValue);
extern EFuncRetCode LuxcJSONGetObjectStringValue(const cJSON* const psObject, const char* const pcKey, char* pcValue );
extern EFuncRetCode LuxcJSONGetObjectBooleanValue(const cJSON* const psObject, const char* const pcKey, cJSON_bool* pbValue);
extern EFuncRetCode LuxcJSONGetObjectArraySize(const cJSON* const psObject, const char* const pcKey, int* piSize);
extern EFuncRetCode LuxcJSONGetObjectIntArray(const cJSON* const psObject, const char* const pcKey, int* piArray,int* piSize);
extern EFuncRetCode LuxcJSONGetObjectDoubleArray(const cJSON* const psObject, const char* const pcKey, double* pdArray, int* piSize );
extern EFuncRetCode LuxcJSONGetObjectStringArray(const cJSON* const psObject, const char* const pcKey, char (*pcArray)[MAXSIZE],int* piSize);
extern EFuncRetCode LuxcJSONGetObjectIntArray2(const cJSON* const psObject, const char* const pcKey, int (*piArray2)[MAXSIZE],int* piRow, int* piColumn);
extern EFuncRetCode LuxcJSONGetObjectDoubleArray2(const cJSON* const psObject, const char* const pcKey, double (*pdArray2)[MAXSIZE],int* piRow, int* piColumn);
extern EFuncRetCode LuxcJSONDelete(cJSON* psItem);
extern EFuncRetCode LuxcJSONFree(void* psObject);
EFuncRetCode LuxcJSONGetOjectStringSize(const cJSON* const psObject, const char* const pcKey, int *piSize);
extern EFuncRetCode LuxcJSONGetArrayRowColumnSize(const cJSON* const psObject, const char* const pcKey, int* piRow,int* piColumn);
#endif /* LUX_JSON_API_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,123 @@
/***********************************************************
* Copyright (C), 2021, LuxShare co.,
*
* File name : lux_system_api
*
* Description :
* system or C API
*
* History:
*
* <Date> <Author> <version> <Modification>
* 2021/03/23 chin 0.01 First draft
* 2021/4/25 huangliang 0.02 add system calls
***********************************************************/
#ifndef __LUX_SYSTEM_API_H__
#define __LUX_SYSTEM_API_H__
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include "lux_base.h"
#include <unistd.h>
#include <arpa/inet.h>
#include <regex.h>
#include <netdb.h> /* gethostbyname() */
#define F_OK 0
extern void* LuxMmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset);
extern int LuxMunmap(void *addr, size_t length);
extern int LuxMsync(void *addr, size_t length, int flags);
extern void* LuxMemset(void* pStr, int iValue, size_t szCount);
extern EFuncRetCode LuxMemsetSafe(void* pDestStr, size_t szSize, int iValue, size_t szCount);
extern void* LuxMemcpy(void* pDst, const void* pSrc, size_t szCount);
extern EFuncRetCode LuxMemcpySafe(void* pDst, size_t szSize, const void* pSrc, size_t szCount);
extern int LuxMemcmp(const void* pBuf1,const void* pBuf2,size_t szCount);
extern char* LuxStrcpy(char* pcDestStr, const char* pcScrStr);
extern char* LuxStrncpy(char* pcDestStr, const char* pcScrStr, size_t szCount);
extern int LuxStrcmp(const char* pcStr1, const char* pcStr2);
extern int LuxStrncmp(const char* pcStr1, const char* pcStr2, size_t szCount);
extern size_t LuxStrlen(const char* pcStr);
extern size_t LuxStrnlen(const char* pcStr, size_t szLen);
extern char* LuxStrcat(char* pcDestStr, const char* pcSrcStr);
extern char* LuxStrncat(char* pcDest, const char* pcSrc, size_t szCount);
extern char* LuxStrstr(char* pcDestStr, const char* pcSrcStr);
extern int LuxPrintf(const char* fmt,...);
extern int LuxFprintf(FILE* fp, char* fmt, ...);
extern int LuxDprintf(int fd, const char *fmt, ...);
extern int LuxSprintf(char* pcBuf, const char* fmt, ...);
extern int LuxSnprintf(char* pcBuf, size_t szSize, const char* fmt, ...);
extern int LuxSscanf(const char* pcBuf, const char* fmt, ...);
extern int LuxScanf(const char* fmt, ...);
extern int LuxFscanf(FILE* stream, const char* fmt, ...);
extern int LuxOpenAndCreat(const char* pcPathname,int iFlags,mode_t mode);
extern int LuxOpen(const char* pcPathname,int iFlags);
extern int LuxClose(int fd);
extern ssize_t LuxRead(int fd, void* pBuf, size_t szCount);
extern ssize_t LuxWrite(int fd, void* pBuf, size_t szCount);
extern off_t LuxLseek(int fd, off_t offset, int iWhence);
extern FILE* LuxFopen(const char* pcPathname, const char* pcMode);
extern int LuxFclose(FILE* stream);
extern size_t LuxFread(void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern size_t LuxFwrite(const void* ptr, size_t szSize, size_t szNmemb, FILE* stream);
extern int LuxFseek(FILE *stream, long offset, int iWhence);
extern long LuxFtell(FILE* stream);
extern void LuxRewind(FILE* stream);
extern EFuncRetCode LuxSystem(char* pcCmdStr);
extern FILE* LuxPopen(const char* pcCmdStr, const char* pcType);
extern int LuxPclose(FILE* stream);
extern void* LuxDlopen(const char* pcFilename, int iFlags);
extern int LuxDlclose(void* pDlhandle);
extern void* LuxDlsym(void* pDlhandle, const char* pcSymbol);
extern char* LuxDlerror(void);
extern time_t LuxTime(time_t* timep);
extern char* LuxCtime(const time_t* timep);
extern char* LuxAsctime(const struct tm* tm);
extern struct tm* LuxGmtime(const time_t* timep);
extern struct tm* LuxLocaltime(const time_t* timep);
extern time_t LuxMktime(struct tm* tm);
extern void* LuxMalloc(size_t size);
extern void* LuxCalloc(size_t nmemb, size_t size);
extern void* LuxRealloc(void* ptr, size_t size);
extern void LuxFree(void* ptr);
extern void* LuxMemchr(const void* pStr, int iCharacter, size_t szCount);
extern char* LuxStrchr(const char* pcStr, int iCharacter);
extern char* LuxStrtok(char* pcStr, const char* pcDelim);
extern int LuxFeof(FILE* stream);
extern int LuxFflush(FILE* stream);
extern int LuxRemove(const char* pcFilename);
extern int LuxRename(const char* pcOldFilename, const char* pcNewFilename);
extern int LuxRand(void);
extern void LuxSrand(unsigned int iSeed);
extern int LuxAccess(const char* pcPathName,int mode);
extern int LuxClosedir(DIR* psDir);
extern struct dirent* LuxReaddir(DIR* psDir);
extern int LuxChdir(const char* pcPathName);
extern int LuxRmdir(const char* pcPathname);
extern int LuxChmod(const char* pcFilename,mode_t mode);
extern int LuxMkdir(const char* pcPathName,mode_t mode);
extern int LuxClockgettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int LuxClocksettime (__clockid_t ClockId, struct timespec* psTimeSpec);
extern int LuxFgetc(FILE *pstream);
extern int LuxFputc(int chara, FILE *pstream);
extern int LuxFerror(FILE *pstream);
extern DIR* LuxOpendir(const char *pcdirname);
extern const char* LuxInetNtop(int af, const void* psrc, char* pcDst, size_t size);
extern int LuxInetPton(int af, const char *pcSrc, void *pDst);
extern char* LuxInetNtoa(struct in_addr in);
extern int LuxSocket(int domain, int type, int protocol);
extern int LuxIoctl(int fd, unsigned long request, ...);
extern void LuxReboot(int iFlag);
extern int LuxRegcomp(regex_t *compiled, const char *pattern, int cflags);
extern int LuxRegexec(regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr[], int eflags);
extern void LuxRegfree(regex_t *compiled);
extern int LuxGetaddrinfo( const char *hostname, const char *service, const struct addrinfo *hints, struct addrinfo **result );
extern int LuxAtoi(const char* paddr);
#endif
@@ -0,0 +1,37 @@
From ca1ba3ae07328386bc2ef188859e60af400e1e83 Mon Sep 17 00:00:00 2001
From: Anuj Agrawal <anuj.agrawal@intel.com>
Date: Thu, 23 Jun 2022 07:40:08 +0000
Subject: [PATCH] Post Complete Signal Handling
1.PostComplete Signal handling is changed from GPIO-based to Dbus-based.
2. Removed the WorkAround patch.
Tested: Tested on AVC, Property is changing as expected.
Signed-off-by: Anuj Agrawal <anuj.agrawal@intel.com>
Upstream-Status: Pending
---
config/power-config-host0.json | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/config/power-config-host0.json b/config/power-config-host0.json
index 3224457..b655692 100644
--- a/config/power-config-host0.json
+++ b/config/power-config-host0.json
@@ -21,8 +21,11 @@
{
"Name": "PostComplete",
"LineName": "POST_COMPLETE",
- "Type": "GPIO",
- "Polarity": "ActiveLow"
+ "Type" : "DBUS",
+ "DbusName" : "xyz.openbmc_project.Host.Misc.Manager",
+ "Path" : "/xyz/openbmc_project/misc/platform_state",
+ "Interface" : "xyz.openbmc_project.State.Host.Misc",
+ "Property" : "PostComplete"
},
{
"Name": "PowerButton",
--
2.17.1
@@ -0,0 +1,62 @@
From 1a69465a1b75db75087fd9d060109284feafe190 Mon Sep 17 00:00:00 2001
From: Nikhil Jain C S <nikhil.jain.c.s@intel.com>
Date: Fri, 24 Jun 2022 16:54:25 +0530
Subject: [PATCH] Polarity Issue
Reversing the polarity on D-Bus
Tested on AVC.
Power is off -> OSStatus Inactive
Power is On -> OSStatus Standby
Signed-off-by: Nikhil Jain C S <nikhil.jain.c.s@intel.com>
Upstream-Status: Pending
---
src/power_control.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/power_control.cpp b/src/power_control.cpp
index bc30b71..cfd0eb0 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -2276,12 +2276,12 @@ static void postCompleteHandler(bool state)
if (!state)
{
sendPowerControlEvent(Event::postCompleteAssert);
- setOperatingSystemState(OperatingSystemStateStage::Standby);
+ setOperatingSystemState(OperatingSystemStateStage::Inactive);
}
else
{
sendPowerControlEvent(Event::postCompleteDeAssert);
- setOperatingSystemState(OperatingSystemStateStage::Inactive);
+ setOperatingSystemState(OperatingSystemStateStage::Standby);
}
}
@@ -2565,8 +2565,8 @@ void setInitialValue(const ConfigData& configData, bool initialValue)
else if (configData.name == "PostComplete")
{
OperatingSystemStateStage osState =
- (initialValue ? OperatingSystemStateStage::Inactive
- : OperatingSystemStateStage::Standby);
+ (initialValue ? OperatingSystemStateStage::Standby
+ : OperatingSystemStateStage::Inactive);
setOperatingSystemState(osState);
}
else
@@ -3412,8 +3412,8 @@ int main(int argc, char* argv[])
else
{
osState = getProperty(postCompleteConfig) > 0
- ? OperatingSystemStateStage::Inactive
- : OperatingSystemStateStage::Standby;
+ ? OperatingSystemStateStage::Standby
+ : OperatingSystemStateStage::Inactive;
}
osIface->register_property(
--
2.25.1
@@ -0,0 +1,27 @@
From 52afd4c45be3a724976093e3a63c71731b4c68fd Mon Sep 17 00:00:00 2001
From: Jan Sowinski <jan.sowinski@intel.com>
Date: Wed, 9 Nov 2022 11:54:34 +0100
Subject: [PATCH] Update NMIOut LineName to match DTS
Signed-off-by: Jan Sowinski <jan.sowinski@intel.com>
Upstream-Status: Pending
---
config/power-config-host0.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/power-config-host0.json b/config/power-config-host0.json
index b655692..9341d90 100644
--- a/config/power-config-host0.json
+++ b/config/power-config-host0.json
@@ -14,7 +14,7 @@
},
{
"Name": "NMIOut",
- "LineName": "NMI_OUT",
+ "LineName": "IRQ_BMC_CPU_NMI_P0",
"Type": "GPIO",
"Polarity": "ActiveHigh"
},
--
2.17.1
@@ -0,0 +1,91 @@
From 0d413f596ebcb180b629c73adcc11acd1e58d003 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Thu, 22 Aug 2024 11:28:40 +0800
Subject: [PATCH] Remove the GPIO configuration for unused pins
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
config/power-config-host0.json | 42 ----------------------------------
src/power_control.cpp | 6 +----
2 files changed, 1 insertion(+), 47 deletions(-)
diff --git a/config/power-config-host0.json b/config/power-config-host0.json
index 9b39d57..5a68242 100644
--- a/config/power-config-host0.json
+++ b/config/power-config-host0.json
@@ -6,18 +6,6 @@
"Type": "GPIO",
"Polarity": "ActiveLow"
},
- {
- "Name": "NMIButton",
- "LineName": "NMI_BUTTON",
- "Type": "GPIO",
- "Polarity": "ActiveLow"
- },
- {
- "Name": "NMIOut",
- "LineName": "IRQ_BMC_CPU_NMI_P0",
- "Type": "GPIO",
- "Polarity": "ActiveHigh"
- },
{
"Name": "PostComplete",
"LineName": "POST_COMPLETE",
@@ -44,36 +32,6 @@
"LineName": "POWER_OUT",
"Type": "GPIO",
"Polarity": "ActiveLow"
- },
- {
- "Name": "ResetButton",
- "LineName": "RESET_BUTTON",
- "Type": "GPIO",
- "Polarity": "ActiveLow"
- },
- {
- "Name": "ResetOut",
- "LineName": "RESET_OUT",
- "Type": "GPIO",
- "Polarity": "ActiveLow"
- },
- {
- "Name": "SioOnControl",
- "LineName": "SIO_ONCONTROL",
- "Type": "GPIO",
- "Polarity": "ActiveLow"
- },
- {
- "Name": "SioPowerGood",
- "LineName": "SIO_POWER_GOOD",
- "Type": "GPIO",
- "Polarity": "ActiveHigh"
- },
- {
- "Name": "SIOS5",
- "LineName": "SIO_S5",
- "Type": "GPIO",
- "Polarity": "ActiveLow"
}
],
"timing_configs": {
diff --git a/src/power_control.cpp b/src/power_control.cpp
index cfd0eb0..7a47957 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -2886,11 +2886,7 @@ int main(int argc, char* argv[])
return -1;
}
}
- else
- {
- lg2::error("ResetOut name should be configured from json config file");
- return -1;
- }
+
// Release line
line.reset();
--
2.34.1
@@ -0,0 +1,164 @@
From fa312c462de18b25a67f08c8f7be51f9fbdc4df5 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Thu, 19 Sep 2024 15:11:18 +0800
Subject: [PATCH] Implement power reset control
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/power_control.cpp | 128 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 126 insertions(+), 2 deletions(-)
diff --git a/src/power_control.cpp b/src/power_control.cpp
index 7a47957..586d1e3 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -27,10 +27,18 @@
#include <nlohmann/json.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/object_server.hpp>
-
#include <filesystem>
#include <fstream>
#include <string_view>
+#include <thread>
+#include <chrono>
+#include <iostream>
+
+extern "C"
+{
+#include <i2c/smbus.h>
+#include <linux/i2c-dev.h>
+}
namespace power_control
{
@@ -1408,9 +1416,125 @@ static void forcePowerOff()
});
}
+int i2cWriteRead(std::string& i2cDev, const uint8_t slaveAddr,
+ std::vector<uint8_t> writeData,
+ std::vector<uint8_t>& readBuf)
+{
+ int fd = open(i2cDev.c_str(), O_RDWR | O_CLOEXEC);
+ if (fd < 0)
+ {
+ lg2::error("unable to open i2c device");
+ return -1;
+ }
+
+ const size_t writeCount = writeData.size();
+ const size_t readCount = readBuf.size();
+
+ int msgCount = 0;
+ struct i2c_msg i2cmsg[2];
+
+ memset(i2cmsg, 0, sizeof(i2cmsg));
+
+ if (writeCount)
+ {
+ // Data will be writtern to the slave address
+ i2cmsg[msgCount].addr = slaveAddr;
+ i2cmsg[msgCount].flags = 0x00;
+ i2cmsg[msgCount].len = writeCount;
+ i2cmsg[msgCount].buf = writeData.data();
+ msgCount++;
+ }
+
+ if (readCount)
+ {
+ // Data will be read into the buffer from the slave address
+ i2cmsg[msgCount].addr = slaveAddr;
+ i2cmsg[msgCount].flags = I2C_M_RD;
+ i2cmsg[msgCount].len = readCount;
+ i2cmsg[msgCount].buf = readBuf.data();
+ msgCount++;
+ }
+
+ struct i2c_rdwr_ioctl_data msgReadWrite;
+ memset((void*)&msgReadWrite, 0, sizeof(msgReadWrite));
+ msgReadWrite.msgs = i2cmsg;
+ msgReadWrite.nmsgs = msgCount;
+
+ int ret = ioctl(fd, I2C_RDWR, &msgReadWrite);
+ close(fd);
+ if (ret < 0)
+ {
+ lg2::error("I2C Read Write Failed.");
+ return -1;
+ }
+
+ if (readCount)
+ {
+ readBuf.resize(msgReadWrite.msgs[msgCount - 1].len);
+ }
+
+ return 0;
+}
+
+#define BIT2 (1 << 2)
+void luxResetChassis()
+{
+ int ret = 0;
+ std::string i2cDev = "/dev/i2c-0";
+ // Perform the combined write/read
+
+ std::vector<uint8_t> readBuf(1);
+ std::vector<uint8_t> writeData = {0x30, 0x01};
+ const uint8_t slaveAddr = 0x0D;
+ uint8_t regVal, tmp;
+
+ ret = i2cWriteRead(i2cDev, slaveAddr, writeData, readBuf);
+ if (ret < 0)
+ {
+ lg2::error("i2c failed to read regVal.");
+ goto err;
+ }
+
+ regVal = readBuf[0];
+ readBuf.resize(0);
+ tmp = regVal & (~BIT2);
+ writeData.push_back(tmp);
+
+ ret = i2cWriteRead(i2cDev, slaveAddr, writeData, readBuf);
+ if (ret < 0)
+ {
+ lg2::error("i2c WriteRead failed.");
+ goto err;
+ }
+
+ writeData.pop_back();
+ tmp = regVal | BIT2;
+ writeData.push_back(tmp);
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(400));
+
+ ret = i2cWriteRead(i2cDev, slaveAddr, writeData, readBuf);
+ if (ret < 0)
+ {
+ lg2::error("i2c WriteRead failed.");
+ goto err;
+ }
+
+ lg2::error("Success to reset Host.");
+ return;
+err:
+ lg2::error("Fail to reset Host.");
+ return;
+}
+
static void reset()
{
- assertGPIOForMs(resetOutConfig, TimerMap["ResetPulseMs"]);
+ if (!resetOutConfig.lineName.empty())
+ assertGPIOForMs(resetOutConfig, TimerMap["ResetPulseMs"]);
+ else {
+ std::thread myThread(luxResetChassis);
+ myThread.join();
+ }
}
static void gracefulPowerOffTimerStart()
--
2.34.1
@@ -0,0 +1,95 @@
diff --git a/src/power_control.cpp b/src/power_control.cpp
index 586d1e3..b671b23 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -558,6 +558,58 @@ static constexpr std::string_view getChassisState(const PowerState state)
break;
}
};
+
+static void powerStateLog(const PowerState state)
+{
+ constexpr const char* selService = "xyz.openbmc_project.Logging.IPMI";
+ constexpr const char* selPath = "/xyz/openbmc_project/Logging/IPMI";
+ constexpr const char* selInterface = "xyz.openbmc_project.Logging.IPMI";
+ constexpr const char* selMethod = "IpmiSelAdd";
+ constexpr const char* sensorPath =
+ "/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/ACPI_State";
+
+ auto bus = sdbusplus::bus::new_default();
+ std::string stateStr = std::string(getChassisState(state));
+
+ auto method =
+ bus.new_method_call(selService, selPath, selInterface, selMethod);
+
+ method.append("SEL Entry");
+ method.append(sensorPath);
+
+ if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.On")
+ {
+ std::cerr << "Send Power State On SEL Log\n";
+ method.append(
+ std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // S0/G0: working
+ }
+ else if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.Off")
+ {
+ std::cerr << "Send Power State Off SEL Log\n";
+ method.append(
+ std::array<uint8_t, 3>({0x06, 0xFF, 0xFF})); // S4/S5: soft-off
+ }
+ else
+ {
+ std::cerr << "Send Power State SEL Log Error\n";
+ return;
+ }
+
+ method.append(true); // assert is true and deassert is false
+ method.append(uint16_t(0x0020)); // generator ID
+ try
+ {
+ bus.call_noreply(method);
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
+ {
+ lg2::error(
+ "Failed to call sel log {SELPATH}, {SELINTERFACE}, {SELMRTHOD}",
+ "SELPATH", selPath, "SELINTERFACE", selInterface, "SELMRTHOD",
+ selMethod);
+ }
+}
+
#ifdef CHASSIS_SYSTEM_RESET
enum class SlotPowerState
{
@@ -1890,6 +1942,7 @@ static void powerStateWaitForPSPowerOK(const Event event)
else
{
setPowerState(PowerState::on);
+ powerStateLog(PowerState::on);
}
break;
}
@@ -1941,6 +1994,7 @@ static void powerStateOff(const Event event)
else
{
setPowerState(PowerState::on);
+ powerStateLog(PowerState::on);
}
break;
}
@@ -1975,6 +2029,7 @@ static void powerStateTransitionToOff(const Event event)
// Cancel any GPIO assertions held during the transition
gpioAssertTimer.cancel();
setPowerState(PowerState::off);
+ powerStateLog(PowerState::off);
break;
default:
lg2::info("No action taken.");
@@ -2064,6 +2119,7 @@ static void powerStateTransitionToCycleOff(const Event event)
// Cancel any GPIO assertions held during the transition
gpioAssertTimer.cancel();
setPowerState(PowerState::cycleOff);
+ powerStateLog(PowerState::cycleOff);
powerCycleTimerStart();
break;
default:
@@ -0,0 +1,91 @@
From 5a8896cc3a8e02e3d09be450a0c7fcc5a5266b55 Mon Sep 17 00:00:00 2001
From: "Wang.Bin" <Bin-B.Wang@luxshare-ict.com>
Date: Wed, 23 Oct 2024 13:34:12 +0800
Subject: [PATCH 7/7] Add power button sensor
---
src/power_control.cpp | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/power_control.cpp b/src/power_control.cpp
index b671b23..fbc9605 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -277,6 +277,7 @@ enum class PowerState
transitionToCycleOff,
gracefulTransitionToCycleOff,
checkForWarmReset,
+ powerButtonPressed,
};
static PowerState powerState;
static std::string getPowerStateName(PowerState state)
@@ -553,6 +554,9 @@ static constexpr std::string_view getChassisState(const PowerState state)
case PowerState::cycleOff:
return "xyz.openbmc_project.State.Chassis.PowerState.Off";
break;
+ case PowerState::powerButtonPressed:
+ return "ButtonPressed";
+ break;
default:
return "";
break;
@@ -565,7 +569,7 @@ static void powerStateLog(const PowerState state)
constexpr const char* selPath = "/xyz/openbmc_project/Logging/IPMI";
constexpr const char* selInterface = "xyz.openbmc_project.Logging.IPMI";
constexpr const char* selMethod = "IpmiSelAdd";
- constexpr const char* sensorPath =
+ std::string sensorPath =
"/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/ACPI_State";
auto bus = sdbusplus::bus::new_default();
@@ -574,21 +578,30 @@ static void powerStateLog(const PowerState state)
auto method =
bus.new_method_call(selService, selPath, selInterface, selMethod);
- method.append("SEL Entry");
- method.append(sensorPath);
+ method.append("SEL Entry");
if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.On")
{
std::cerr << "Send Power State On SEL Log\n";
+ method.append(sensorPath.c_str());
method.append(
std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // S0/G0: working
}
else if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.Off")
{
std::cerr << "Send Power State Off SEL Log\n";
+ method.append(sensorPath.c_str());
method.append(
std::array<uint8_t, 3>({0x06, 0xFF, 0xFF})); // S4/S5: soft-off
}
+ else if (stateStr == "ButtonPressed")
+ {
+ std::cerr << "Send Power State Button Pressed SEL Log\n";
+ sensorPath = "/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/Power_Button";
+ method.append(sensorPath.c_str());
+ method.append(
+ std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // power button pressed
+ }
else
{
std::cerr << "Send Power State SEL Log Error\n";
@@ -826,9 +839,11 @@ static void powerRestorePolicyLog()
static void powerButtonPressLog()
{
- sd_journal_send("MESSAGE=PowerControl: power button pressed", "PRIORITY=%i",
- LOG_INFO, "REDFISH_MESSAGE_ID=%s",
- "OpenBMC.0.1.PowerButtonPressed", NULL);
+ // sd_journal_send("MESSAGE=PowerControl: power button pressed", "PRIORITY=%i",
+ // LOG_INFO, "REDFISH_MESSAGE_ID=%s",
+ // "OpenBMC.0.1.PowerButtonPressed", NULL);
+ powerStateLog(PowerState::powerButtonPressed);
+
}
static void resetButtonPressLog()
--
2.25.1
@@ -0,0 +1,90 @@
From fd9fd44b8adda86cc292943fbb477293b321f390 Mon Sep 17 00:00:00 2001
From: "Wang.Bin" <Bin-B.Wang@luxshare-ict.com>
Date: Tue, 5 Nov 2024 19:15:22 +0800
Subject: [PATCH 8/8] Add ACPI_State event monitoring Test ACPI_State |
FBh | ok | 7.70 | S4/S5: soft-off 3 | 04/03/23 | 20:59:16 UTC | System
ACPI Power State ACPI_State | S4/S5: soft-off | Asserted ipmitool power on
reboot ACPI_State | FBh | ok | 7.70 | S0/G0: working 5 | 04/03/23 |
21:03:14 UTC | System ACPI Power State ACPI_State | S0/G0: working | Asserted
---
...bmc_project.Chassis.Control.Power@.service | 4 ++-
src/power_control.cpp | 26 +++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/service_files/xyz.openbmc_project.Chassis.Control.Power@.service b/service_files/xyz.openbmc_project.Chassis.Control.Power@.service
index 4d676c2..03a1782 100644
--- a/service_files/xyz.openbmc_project.Chassis.Control.Power@.service
+++ b/service_files/xyz.openbmc_project.Chassis.Control.Power@.service
@@ -1,6 +1,8 @@
[Unit]
Description=Intel Power Control for the Host %i
ConditionPathExists=/usr/share/x86-power-control/power-config-host%i.json
+Wants=obmc-fru-fault-monitor.service
+After=obmc-fru-fault-monitor.service
[Service]
Restart=always
@@ -10,4 +12,4 @@ Type=dbus
BusName=xyz.openbmc_project.State.Host%i
[Install]
-WantedBy=sysinit.target
+WantedBy=sysinit.target
\ No newline at end of file
diff --git a/src/power_control.cpp b/src/power_control.cpp
index fbc9605..bfb55ef 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -177,6 +177,8 @@ static boost::asio::steady_timer pohCounterTimer(io);
// Time when to allow restart cause updates
static boost::asio::steady_timer restartCauseTimer(io);
static boost::asio::steady_timer slotPowerCycleTimer(io);
+// SEL timer
+static boost::asio::steady_timer selTimer(io);
// Map containing timers used for D-Bus get-property retries
static boost::container::flat_map<std::string, boost::asio::steady_timer>
@@ -2810,8 +2812,31 @@ void reschedulePropertyRead(const ConfigData& configData)
}
});
}
+
+static void ACPIStateSel(void)
+{
+ const static constexpr int TimeMs = 20000;
+ selTimer.expires_after(std::chrono::milliseconds(TimeMs));
+ selTimer.async_wait([](const boost::system::error_code ec) {
+ if (ec)
+ {
+ // operation_aborted is expected if timer is canceled before
+ // completion.
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ lg2::info("ACPI State timer error: {ERROR}", "ERROR",
+ ec.message());
+ }
+ }
+ lg2::info("ACPI State sel");
+ powerStateLog(powerState);
+ });
+
+}
+
} // namespace power_control
+
int main(int argc, char* argv[])
{
using namespace power_control;
@@ -3106,6 +3131,7 @@ int main(int argc, char* argv[])
powerState = PowerState::on;
}
}
+ ACPIStateSel();
// Check if we need to start the Power Restore policy
if (powerState != PowerState::on)
{
--
2.25.1
@@ -0,0 +1,80 @@
From c30e74c4dc90960f935401fe403c833eac3bb7fd Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Wed, 6 Nov 2024 15:18:08 +0800
Subject: [PATCH] Control uidLed in uid button handler
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
---
src/power_control.cpp | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/power_control.cpp b/src/power_control.cpp
index bfb55ef..8d462be 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -118,6 +118,13 @@ static std::string buttonDbusName = "xyz.openbmc_project.Chassis.Buttons";
static std::string nmiDbusName = "xyz.openbmc_project.Control.Host.NMI";
static std::string rstCauseDbusName =
"xyz.openbmc_project.Control.Host.RestartCause";
+constexpr const char* uidLedPath = "/xyz/openbmc_project/led/groups/uid_btn";
+constexpr const char* ledIface = "xyz.openbmc_project.Led.Group";
+constexpr const char* ledAssertProp = "Asserted";
+constexpr const char* ledManagerBusname =
+ "xyz.openbmc_project.LED.GroupManager";
+static bool uidLastState = false;
+
static std::shared_ptr<sdbusplus::asio::dbus_interface> hostIface;
static std::shared_ptr<sdbusplus::asio::dbus_interface> chassisIface;
#ifdef CHASSIS_SYSTEM_RESET
@@ -580,7 +587,7 @@ static void powerStateLog(const PowerState state)
auto method =
bus.new_method_call(selService, selPath, selInterface, selMethod);
- method.append("SEL Entry");
+ method.append("SEL Entry");
if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.On")
{
@@ -845,7 +852,7 @@ static void powerButtonPressLog()
// LOG_INFO, "REDFISH_MESSAGE_ID=%s",
// "OpenBMC.0.1.PowerButtonPressed", NULL);
powerStateLog(PowerState::powerButtonPressed);
-
+
}
static void resetButtonPressLog()
@@ -2416,9 +2423,30 @@ static void nmiButtonHandler(bool state)
}
}
+static void setUidLed()
+{
+ conn->async_method_call(
+ [&uidLastState](const boost::system::error_code ec) {
+ if (ec)
+ {
+ std::cerr << "Cannot set uidLed to "
+ << std::boolalpha
+ << !uidLastState << "\n";
+ }
+
+ uidLastState = !uidLastState;
+ },
+ ledManagerBusname, uidLedPath,
+ "org.freedesktop.DBus.Properties", "Set", ledIface,
+ ledAssertProp, std::variant<bool>(!uidLastState));
+}
+
static void idButtonHandler(bool state)
{
idButtonIface->set_property("ButtonPressed", !state);
+ if(!state) {
+ setUidLed();
+ }
}
static void pltRstHandler(bool pltRst)
--
2.34.1
@@ -0,0 +1,432 @@
From 8b6def70a95ddab05ec565db1c5437ad17423d20 Mon Sep 17 00:00:00 2001
From: "Wang.Bin" <Bin-B.Wang@luxshare-ict.com>
Date: Tue, 3 Dec 2024 21:23:28 +0800
Subject: [PATCH 10/10] Fix soft-shutdown without SEL
---
src/power_control.cpp | 275 +++++++++++++++++++++++++++++++++++-------
1 file changed, 233 insertions(+), 42 deletions(-)
diff --git a/src/power_control.cpp b/src/power_control.cpp
index 2a72473..cfe6e57 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -94,6 +94,22 @@ static ConfigData idButtonConfig;
static ConfigData nmiButtonConfig;
static ConfigData slotPowerConfig;
+struct LogData
+{
+ bool assert;
+ uint16_t generatorID;
+ std::vector<uint8_t> selData;
+ std::string sensorPath;
+};
+
+struct LogData acpiStatusOffSensor = {true, 0x0020, {6, 255, 255}, "null"};
+struct LogData acpiStatusOnSensor = {true, 0x0020, {0, 255, 255}, "null"};
+struct LogData osBootSensor = {true, 0x0020, {6, 255, 255}, "null"};
+struct LogData sysBootPowerUpSensor = {true, 0x0020, {0, 255, 255}, "null"};
+struct LogData sysBootHardResetSensor = {true, 0x0020, {1, 255, 255}, "null"};
+struct LogData sysBootWarmResetSensor = {true, 0x0020, {2, 255, 255}, "null"};
+struct LogData powerButtonPressedSensor = {true, 0x0020, {0, 255, 255}, "null"};
+
// map for storing list of gpio parameters whose config are to be read from x86
// power control json config
boost::container::flat_map<std::string, ConfigData*> powerSignalMap = {
@@ -578,47 +594,48 @@ static void powerStateLog(const PowerState state)
constexpr const char* selPath = "/xyz/openbmc_project/Logging/IPMI";
constexpr const char* selInterface = "xyz.openbmc_project.Logging.IPMI";
constexpr const char* selMethod = "IpmiSelAdd";
- std::string sensorPath =
- "/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/ACPI_State";
+ struct LogData powerStatusSensor;
auto bus = sdbusplus::bus::new_default();
- std::string stateStr = std::string(getChassisState(state));
+
auto method =
bus.new_method_call(selService, selPath, selInterface, selMethod);
- method.append("SEL Entry");
-
- if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.On")
- {
- std::cerr << "Send Power State On SEL Log\n";
- method.append(sensorPath.c_str());
- method.append(
- std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // S0/G0: working
- }
- else if (stateStr == "xyz.openbmc_project.State.Chassis.PowerState.Off")
- {
- std::cerr << "Send Power State Off SEL Log\n";
- method.append(sensorPath.c_str());
- method.append(
- std::array<uint8_t, 3>({0x06, 0xFF, 0xFF})); // S4/S5: soft-off
- }
- else if (stateStr == "ButtonPressed")
- {
- std::cerr << "Send Power State Button Pressed SEL Log\n";
- sensorPath = "/xyz/openbmc_project/inventory/system/board/Lux_Baseboard/Power_Button";
- method.append(sensorPath.c_str());
- method.append(
- std::array<uint8_t, 3>({0x00, 0xFF, 0xFF})); // power button pressed
- }
- else
+ switch (state)
{
- std::cerr << "Send Power State SEL Log Error\n";
- return;
+ case PowerState::on:
+ std::cout << "PowerState:: on" << std::endl;
+ powerStatusSensor = acpiStatusOnSensor;
+ break;
+ // both off and cycleOff will call acpiStatusOffSensor
+ case PowerState::off:
+ case PowerState::cycleOff:
+ std::cout << "PowerState:: off" << std::endl;
+ powerStatusSensor = acpiStatusOffSensor;
+ break;
+ case PowerState::transitionToCycleOff:
+ powerStatusSensor = sysBootHardResetSensor;
+ break;
+ case PowerState::waitForPSPowerOK:
+ powerStatusSensor = sysBootPowerUpSensor;
+ break;
+ case PowerState::checkForWarmReset:
+ powerStatusSensor = sysBootWarmResetSensor;
+ break;
+ case PowerState::powerButtonPressed:
+ powerStatusSensor = powerButtonPressedSensor;
+ break;
+ default:
+ break;
}
- method.append(true); // assert is true and deassert is false
- method.append(uint16_t(0x0020)); // generator ID
+ method.append("SEL Entry");
+ method.append(powerStatusSensor.sensorPath);
+ method.append(powerStatusSensor.selData);
+ method.append(
+ powerStatusSensor.assert); // assert is true and deassert is false
+ method.append(powerStatusSensor.generatorID); // generator ID
try
{
bus.call_noreply(method);
@@ -851,6 +868,7 @@ static void powerButtonPressLog()
// sd_journal_send("MESSAGE=PowerControl: power button pressed", "PRIORITY=%i",
// LOG_INFO, "REDFISH_MESSAGE_ID=%s",
// "OpenBMC.0.1.PowerButtonPressed", NULL);
+ std::cout << "power button pressed" << __LINE__ << std::endl;
powerStateLog(PowerState::powerButtonPressed);
}
@@ -1829,9 +1847,10 @@ static void currentHostStateMonitor()
pohCounterTimerStart();
// Clear the restart cause set for the next restart
clearRestartCause();
- sd_journal_send("MESSAGE=Host system DC power is on", "PRIORITY=%i",
- LOG_INFO, "REDFISH_MESSAGE_ID=%s",
- "OpenBMC.0.1.DCPowerOn", NULL);
+ std::cout << "Host system DC power is on" << __LINE__ << std::endl;
+ //sd_journal_send("MESSAGE=Host system DC power is on", "PRIORITY=%i",
+ // LOG_INFO, "REDFISH_MESSAGE_ID=%s",
+ // "OpenBMC.0.1.DCPowerOn", NULL);
}
else
{
@@ -1848,9 +1867,10 @@ static void currentHostStateMonitor()
#ifdef USE_ACBOOT
resetACBootProperty();
#endif // USE_ACBOOT
- sd_journal_send("MESSAGE=Host system DC power is off",
- "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s",
- "OpenBMC.0.1.DCPowerOff", NULL);
+ std::cout << "Host system DC power is off" << __LINE__ << std::endl;
+ //sd_journal_send("MESSAGE=Host system DC power is off",
+ // "PRIORITY=%i", LOG_INFO, "REDFISH_MESSAGE_ID=%s",
+ // "OpenBMC.0.1.DCPowerOff", NULL);
}
});
}
@@ -1966,6 +1986,7 @@ static void powerStateWaitForPSPowerOK(const Event event)
else
{
setPowerState(PowerState::on);
+ std::cout << "powerStateWaitForPSPowerOK" << __LINE__ << std::endl;
powerStateLog(PowerState::on);
}
break;
@@ -2018,7 +2039,6 @@ static void powerStateOff(const Event event)
else
{
setPowerState(PowerState::on);
- powerStateLog(PowerState::on);
}
break;
}
@@ -2053,6 +2073,7 @@ static void powerStateTransitionToOff(const Event event)
// Cancel any GPIO assertions held during the transition
gpioAssertTimer.cancel();
setPowerState(PowerState::off);
+ std::cout << "powerStateTransitionToOff" << __LINE__ << std::endl;
powerStateLog(PowerState::off);
break;
default:
@@ -2069,6 +2090,8 @@ static void powerStateGracefulTransitionToOff(const Event event)
case Event::psPowerOKDeAssert:
gracefulPowerOffTimer.cancel();
setPowerState(PowerState::off);
+ std::cout << "powerStateGracefulTransitionToOff power off" << __LINE__ << std::endl;
+ powerStateLog(PowerState::off);
break;
case Event::gracefulPowerOffTimerExpired:
setPowerState(PowerState::on);
@@ -2110,6 +2133,7 @@ static void powerStateCycleOff(const Event event)
else
{
setPowerState(PowerState::on);
+ std::cout << "powerStateCycleOff:power on" << __LINE__ << std::endl;
}
break;
}
@@ -2143,6 +2167,7 @@ static void powerStateTransitionToCycleOff(const Event event)
// Cancel any GPIO assertions held during the transition
gpioAssertTimer.cancel();
setPowerState(PowerState::cycleOff);
+ std::cout << "powerStateTransitionToCycleOff power off" << __LINE__ << std::endl;
powerStateLog(PowerState::cycleOff);
powerCycleTimerStart();
break;
@@ -2160,6 +2185,8 @@ static void powerStateGracefulTransitionToCycleOff(const Event event)
case Event::psPowerOKDeAssert:
gracefulPowerOffTimer.cancel();
setPowerState(PowerState::cycleOff);
+ std::cout << "powerStateGracefulTransitionToCycleOff power off" << __LINE__ << std::endl;
+ powerStateLog(PowerState::cycleOff);
powerCycleTimerStart();
break;
case Event::gracefulPowerOffTimerExpired:
@@ -2201,6 +2228,8 @@ static void powerStateCheckForWarmReset(const Event event)
case Event::psPowerOKDeAssert:
warmResetCheckTimer.cancel();
setPowerState(PowerState::off);
+ std::cout << "powerStateCheckForWarmReset power off" << __LINE__ << std::endl;
+ powerStateLog(PowerState::cycleOff);
// DC power is unexpectedly lost, beep
beep(beepPowerFail);
break;
@@ -2496,12 +2525,43 @@ static void pltRstHandler(bool pltRst)
}
}
+static void postCompleteLog()
+{
+ constexpr const char* selService = "xyz.openbmc_project.Logging.IPMI";
+ constexpr const char* selPath = "/xyz/openbmc_project/Logging/IPMI";
+ constexpr const char* selInterface = "xyz.openbmc_project.Logging.IPMI";
+ constexpr const char* selMethod = "IpmiSelAdd";
+
+ auto bus = sdbusplus::bus::new_default();
+
+ auto method =
+ bus.new_method_call(selService, selPath, selInterface, selMethod);
+
+ method.append("SEL Entry");
+ method.append(osBootSensor.sensorPath);
+ method.append(osBootSensor.selData);
+ method.append(osBootSensor.assert); // assert is true and deassert is false
+ method.append(osBootSensor.generatorID); // generator ID
+ try
+ {
+ bus.call_noreply(method);
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
+ {
+ lg2::error(
+ "Failed to call sel log {SELPATH}, {SELINTERFACE}, {SELMRTHOD}",
+ "SELPATH", selPath, "SELINTERFACE", selInterface, "SELMRTHOD",
+ selMethod);
+ }
+}
+
static void postCompleteHandler(bool state)
{
if (!state)
{
sendPowerControlEvent(Event::postCompleteAssert);
setOperatingSystemState(OperatingSystemStateStage::Inactive);
+ //postCompleteLog();
}
else
{
@@ -2510,6 +2570,107 @@ static void postCompleteHandler(bool state)
}
}
+std::optional<std::string> getDiscretePrefixFromFile()
+{
+ constexpr auto boardNameFile = "/usr/share/boardname/boardname.conf";
+ constexpr auto boardPrefix = "/xyz/openbmc_project/inventory/system/board/";
+
+ std::ifstream file(boardNameFile);
+ if (!file.is_open())
+ {
+ lg2::error("Fail to open {FILE}", "FILE", boardNameFile);
+ return std::nullopt;
+ }
+
+ std::string boardName{};
+ std::getline(file, boardName);
+ if (boardName.empty())
+ {
+ lg2::error("Fail to read {FILE}", "FILE", boardNameFile);
+ return std::nullopt;
+ }
+ lg2::info("Board name is {BOARD}", "BOARD", boardName);
+ return boardPrefix + boardName;
+}
+
+std::optional<std::vector<std::string>>
+ getSubTreePaths(sdbusplus::bus::bus& bus, const std::string& objectPath,
+ const std::string& interface)
+{
+ constexpr auto mapperBusname = "xyz.openbmc_project.ObjectMapper";
+ constexpr auto mapperObjPath = "/xyz/openbmc_project/object_mapper";
+ constexpr auto mapperIface = "xyz.openbmc_project.ObjectMapper";
+ std::vector<std::string> paths;
+
+ auto method = bus.new_method_call(mapperBusname, mapperObjPath, mapperIface,
+ "GetSubTreePaths");
+ method.append(objectPath.c_str());
+ method.append(0); // Depth 0 to search all
+ method.append(std::vector<std::string>({interface.c_str()}));
+
+ try
+ {
+ auto reply = bus.call(method);
+ reply.read(paths);
+ return paths;
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ lg2::error("Fail to get chassis path");
+ return std::nullopt;
+ }
+
+ return std::nullopt;
+}
+
+std::optional<std::string> getDiscreteSensorPath(const std::string& sensorName)
+{
+ static std::string discreteSensorPathPrefix{};
+ if (discreteSensorPathPrefix.empty())
+ {
+ // First try to get the path from the file
+ auto prefix = getDiscretePrefixFromFile();
+ if (prefix)
+ {
+ discreteSensorPathPrefix = *prefix;
+ }
+ else
+ {
+ // If the file doesn't exist, get the path from the dbus
+ constexpr auto discreteSensorUpperPath =
+ "/xyz/openbmc_project/inventory";
+ constexpr auto discreteSensorInterface =
+ "xyz.openbmc_project.Configuration.Status";
+ auto bus = sdbusplus::bus::new_default();
+ auto sensorPaths = getSubTreePaths(bus, discreteSensorUpperPath,
+ discreteSensorInterface);
+ // if call fail or empty, return nullopt
+ if (!sensorPaths || sensorPaths.value().size() == 0)
+ {
+ return std::nullopt;
+ }
+ // if any sensor path is find, get the prefix of the path
+ // because all discrete sensor path in the inventory has the same
+ // prefix
+ for (const auto& sensorPath : sensorPaths.value())
+ {
+ discreteSensorPathPrefix =
+ sensorPath.substr(0, sensorPath.find_last_of('/'));
+ break;
+ }
+ if (discreteSensorPathPrefix.empty())
+ {
+ return std::nullopt;
+ }
+ }
+ }
+
+ std::string path = discreteSensorPathPrefix;
+ path.append("/");
+ path.append(sensorName);
+ return path;
+}
+
static int loadConfigValues()
{
const std::string configFilePath =
@@ -2661,6 +2822,33 @@ static int loadConfigValues()
nmiWhenPoweredOff = events.value("NMIWhenPoweredOff", true);
}
+ auto acpiSensorPath = getDiscreteSensorPath("ACPI_State");
+ if (acpiSensorPath != std::nullopt)
+ {
+ acpiStatusOnSensor.sensorPath = acpiSensorPath.value();
+ acpiStatusOffSensor.sensorPath = acpiSensorPath.value();
+ }
+
+ auto sysbootSensorPath = getDiscreteSensorPath("SYS_Boot");
+ if (sysbootSensorPath != std::nullopt)
+ {
+ sysBootPowerUpSensor.sensorPath = sysbootSensorPath.value();
+ sysBootHardResetSensor.sensorPath = sysbootSensorPath.value();
+ sysBootWarmResetSensor.sensorPath = sysbootSensorPath.value();
+ }
+
+ auto osbootSensorPath = getDiscreteSensorPath("OS_Boot");
+ if (osbootSensorPath != std::nullopt)
+ {
+ osBootSensor.sensorPath = osbootSensorPath.value();
+ }
+
+ auto powerbuttonSensorPath = getDiscreteSensorPath("Power_Button");
+ if (powerbuttonSensorPath != std::nullopt)
+ {
+ powerButtonPressedSensor.sensorPath = powerbuttonSensorPath.value();
+ }
+
return 0;
}
@@ -2840,7 +3028,7 @@ void reschedulePropertyRead(const ConfigData& configData)
}
});
}
-
+bool bmcReset = true;
static void ACPIStateSel(void)
{
const static constexpr int TimeMs = 20000;
@@ -2856,8 +3044,11 @@ static void ACPIStateSel(void)
ec.message());
}
}
- lg2::info("ACPI State sel");
- powerStateLog(powerState);
+ std::cout << "BMC reboot:power state" << __LINE__ << std::endl;
+ if (bmcReset == true){
+ powerStateLog(powerState);
+ }
+ bmcReset = false;
});
}
--
2.25.1
@@ -0,0 +1,18 @@
FILESEXTRAPATHS:append := "${THISDIR}/${PN}:"
SRC_URI += " \
file://0001-Post-Complete-Signal-Handling.patch \
file://0002-Polarity-Issue.patch \
file://0003-Update-NMIOut-LineName-to-match-DTS.patch \
file://0004-Remove-the-GPIO-configuration-for-unused-pins.patch \
file://0005-Implement-power-reset-control.patch \
file://0006-Add-power-control-SEL.patch \
file://0007-Add-power-button-sensor.patch \
file://0008-Add-ACPI_State-event-monitoring.patch \
file://0009-Control-uidLed-in-uid-button-handler.patch \
file://0010-Fix-soft-shutdown-without-SEL.patch \
"
do_install:append() {
mkdir -p ${D}${sysconfdir}/systemd/system/xyz.openbmc_project.Chassis.Control.Power@.service.d/
}
@@ -0,0 +1,11 @@
SUMMARY = "boardname configuration for Lux_Baseboard"
PR = "r1"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
SRC_URI += "file://boardname.conf"
do_install() {
install -d ${D}/usr/share/boardname
install -m 0444 ${WORKDIR}/boardname.conf ${D}/usr/share/boardname
}
@@ -0,0 +1 @@
Lux_Baseboard
@@ -0,0 +1,83 @@
From 8d85b0f37638c606e195753553fe21cbe8663cd1 Mon Sep 17 00:00:00 2001
From: wangjue <jue.wang2@luxshare-ict.com>
Date: Tue, 15 Oct 2024 18:42:41 +0800
Subject: [PATCH] Add Status interface to settableInterfaces
Signed-off-by: wangjue <jue.wang2@luxshare-ict.com>
%% original patch: 0001-Add-Status-interface-to-settableInterfaces.patch
---
src/entity_manager.cpp | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/src/entity_manager.cpp b/src/entity_manager.cpp
index ee08c00..24da084 100644
--- a/src/entity_manager.cpp
+++ b/src/entity_manager.cpp
@@ -52,6 +52,9 @@ constexpr const char* tempConfigDir = "/tmp/configuration/";
constexpr const char* lastConfiguration = "/tmp/configuration/last.json";
constexpr const char* currentConfiguration = "/var/configuration/system.json";
constexpr const char* globalSchema = "global.json";
+constexpr auto configIfaceName = "xyz.openbmc_project.Configuration.Status";
+constexpr auto statusPropName = "Status";
+bool internalSet = false;
const boost::container::flat_map<const char*, probe_type_codes, CmpStr>
probeTypes{{{"FALSE", probe_type_codes::FALSE_T},
@@ -61,8 +64,8 @@ const boost::container::flat_map<const char*, probe_type_codes, CmpStr>
{"FOUND", probe_type_codes::FOUND},
{"MATCH_ONE", probe_type_codes::MATCH_ONE}}};
-static constexpr std::array<const char*, 6> settableInterfaces = {
- "FanProfile", "Pid", "Pid.Zone", "Stepwise", "Thresholds", "Polling"};
+static constexpr std::array<const char*, 9> settableInterfaces = {
+ "FanProfile", "Pid", "Pid.Zone", "Stepwise", "Thresholds", "Polling", "Status", "Description", "Health"};
using JsonVariantType =
std::variant<std::vector<std::string>, std::vector<double>, std::string,
int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
@@ -216,9 +219,31 @@ void addProperty(const std::string& name, const PropertyType& value,
iface->register_property(
name, value,
[&systemConfiguration,
- jsonPointerString{std::string(jsonPointerString)}](
- const PropertyType& newVal, PropertyType& val) {
- val = newVal;
+ jsonPointerString{std::string(jsonPointerString)},
+ interface = iface->get_interface_name(),
+ propertyName = name](const PropertyType& newVal, PropertyType& val) {
+ // if set from external source, for status property, only
+ // keep the bits 0..15
+ if (!internalSet && interface == configIfaceName &&
+ propertyName == statusPropName)
+ {
+ if constexpr (std::is_same_v<PropertyType, double>)
+ {
+ auto tmp = static_cast<uint32_t>(newVal);
+ tmp &= 0xFFFF;
+ val = static_cast<double>(
+ (static_cast<uint32_t>(val) & ~0xFFFF) | tmp);
+ }
+ else
+ {
+ val = newVal;
+ }
+ }
+ else
+ {
+ val = newVal;
+ }
+
if (!setJsonFromPointer(jsonPointerString, val, systemConfiguration))
{
std::cerr << "error setting json field\n";
@@ -1280,6 +1305,7 @@ int main()
entityIface->register_method("ReScan", [&]() {
propertiesChangedCallback(systemConfiguration, objServer);
});
+
entityIface->initialize();
if (fwVersionIsSame())
--
2.34.1
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,401 @@
{
"Exposes": [
{
"Name": "System Fan connector 1",
"Pwm": 0,
"Tachs": [
0,
1
],
"Type": "IntelFanConnector"
},
{
"Name": "System Fan connector 2",
"Pwm": 1,
"Tachs": [
2,
3
],
"Type": "IntelFanConnector"
},
{
"Name": "System Fan connector 3",
"Pwm": 2,
"Tachs": [
4,
5
],
"Type": "IntelFanConnector"
},
{
"Name": "System Fan connector 4",
"Pwm": 3,
"Tachs": [
6,
7
],
"Type": "IntelFanConnector"
},
{
"Name": "System Fan connector 5",
"Pwm": 4,
"Tachs": [
8,
9
],
"Type": "IntelFanConnector"
},
{
"Name": "System Fan connector 6",
"Pwm": 5,
"Tachs": [
10,
11
],
"Type": "IntelFanConnector"
},
{
"BindConnector": "System Fan connector 1",
"Index": 0,
"Name": "Fan 1 Inlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 1",
"Index": 1,
"Name": "Fan 1 Outlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 2",
"Index": 2,
"Name": "Fan 2 Inlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 2",
"Index": 3,
"Name": "Fan 2 Outlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 3",
"Index": 4,
"Name": "Fan 3 Inlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 3",
"Index": 5,
"Name": "Fan 3 Outlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 4",
"Index": 6,
"Name": "Fan 4 Inlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 4",
"Index": 7,
"Name": "Fan 4 Outlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 5",
"Index": 8,
"Name": "Fan 5 Inlet",
"Type": "AspeedFan"
},
{
"BindConnector": "System Fan connector 5",
"Index": 9,
"Name": "Fan 5 Outlet",
"Type": "AspeedFan"
},
{
"Class": "fan",
"FFGainCoefficient": 0.01,
"FFOffCoefficient": 0.0,
"ICoefficient": 0.0,
"ILimitMax": 0.0,
"ILimitMin": 0.0,
"Inputs": [
"Fan 1 Inlet",
"Fan 1 Outlet"
],
"Name": "Fan 1",
"NegativeHysteresis": 2.0,
"OutLimitMax": 100.0,
"OutLimitMin": 30.0,
"Outputs": [
"Pwm 1"
],
"PCoefficient": 0.0,
"PositiveHysteresis": 0.0,
"SlewNeg": 0.0,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan1"
]
},
{
"Class": "fan",
"FFGainCoefficient": 0.01,
"FFOffCoefficient": 0.0,
"ICoefficient": 0.0,
"ILimitMax": 0.0,
"ILimitMin": 0.0,
"Inputs": [
"Fan 2 Inlet",
"Fan 2 Outlet"
],
"Name": "Fan 2",
"NegativeHysteresis": 2.0,
"OutLimitMax": 100.0,
"OutLimitMin": 30.0,
"Outputs": [
"Pwm 2"
],
"PCoefficient": 0.0,
"PositiveHysteresis": 0.0,
"SlewNeg": 0.0,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan2"
]
},
{
"Class": "fan",
"FFGainCoefficient": 0.01,
"FFOffCoefficient": 0.0,
"ICoefficient": 0.0,
"ILimitMax": 0.0,
"ILimitMin": 0.0,
"Inputs": [
"Fan 3 Inlet",
"Fan 3 Outlet"
],
"Name": "Fan 3",
"NegativeHysteresis": 2.0,
"OutLimitMax": 100.0,
"OutLimitMin": 30.0,
"Outputs": [
"Pwm 3"
],
"PCoefficient": 0.0,
"PositiveHysteresis": 0.0,
"SlewNeg": 0.0,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan3"
]
},
{
"Class": "fan",
"FFGainCoefficient": 0.01,
"FFOffCoefficient": 0.0,
"ICoefficient": 0.0,
"ILimitMax": 0.0,
"ILimitMin": 0.0,
"Inputs": [
"Fan 4 Inlet",
"Fan 4 Outlet"
],
"Name": "Fan 4",
"NegativeHysteresis": 2.0,
"OutLimitMax": 100.0,
"OutLimitMin": 30.0,
"Outputs": [
"Pwm 4"
],
"PCoefficient": 0.0,
"PositiveHysteresis": 0.0,
"SlewNeg": 0.0,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan4"
]
},
{
"Class": "fan",
"FFGainCoefficient": 0.01,
"FFOffCoefficient": 0.0,
"ICoefficient": 0.0,
"ILimitMax": 0.0,
"ILimitMin": 0.0,
"Inputs": [
"Fan 5 Inlet",
"Fan 5 Outlet"
],
"Name": "Fan 5",
"NegativeHysteresis": 2.0,
"OutLimitMax": 100.0,
"OutLimitMin": 30.0,
"Outputs": [
"Pwm 5"
],
"PCoefficient": 0.0,
"PositiveHysteresis": 0.0,
"SlewNeg": 0.0,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan5"
]
},
{
"FailSafePercent": 100,
"MinThermalRpm": 3000,
"Name": "Fan1",
"Type": "Pid.Zone"
},
{
"FailSafePercent": 100,
"MinThermalRpm": 3000,
"Name": "Fan2",
"Type": "Pid.Zone"
},
{
"FailSafePercent": 100,
"MinThermalRpm": 3000,
"Name": "Fan3",
"Type": "Pid.Zone"
},
{
"FailSafePercent": 100,
"MinThermalRpm": 3000,
"Name": "Fan4",
"Type": "Pid.Zone"
},
{
"FailSafePercent": 100,
"MinThermalRpm": 3000,
"Name": "Fan5",
"Type": "Pid.Zone"
},
{
"AllowedFailures": 1,
"Name": "FanRedundancy",
"Type": "FanRedundancy"
},
{
"Class": "temp",
"FFGainCoefficient": 0.0,
"FFOffCoefficient": 0.0,
"ICoefficient": -0.2,
"ILimitMax": 100,
"ILimitMin": 30,
"Inputs": [
"CPU0 Temp0"
],
"Name": "CPU0",
"NegativeHysteresis": 2.0,
"OutLimitMax": 100,
"OutLimitMin": 30,
"Outputs": [],
"PCoefficient": -3.0,
"PositiveHysteresis": 0.0,
"SetPoint": 45.0,
"SlewNeg": -1,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan1",
"Fan2",
"Fan3",
"Fan4",
"Fan5"
]
},
{
"Class": "temp",
"FFGainCoefficient": 0.0,
"FFOffCoefficient": 0.0,
"ICoefficient": -0.2,
"ILimitMax": 100,
"ILimitMin": 30,
"Inputs": [
"CPU1 Temp0"
],
"Name": "CPU1",
"OutLimitMax": 100,
"OutLimitMin": 30,
"Outputs": [],
"PCoefficient": -3.0,
"SetPoint": 45.0,
"SlewNeg": -1,
"SlewPos": 0.0,
"Type": "Pid",
"Zones": [
"Fan1",
"Fan2",
"Fan3",
"Fan4",
"Fan5"
]
},
{
"Class": "Floor",
"Inputs": [
"XXX Temp"
],
"Name": "Front Panel LCC",
"NegativeHysteresis": 2,
"Output": [
50.0,
60.0
],
"PositiveHysteresis": 0,
"Reading": [
20.0,
30.0
],
"Type": "Stepwise",
"Zones": [
"Fan1",
"Fan2"
]
},
{
"Class": "Ceiling",
"Inputs": [
"Front Panel Temp"
],
"Name": "Front Panel UCC",
"NegativeHysteresis": 2,
"Output": [
70.0,
80.0
],
"PositiveHysteresis": 0,
"Reading": [
22.0,
32.0
],
"Type": "Stepwise",
"Zones": [
"Fan3",
"Fan4"
]
}
],
"Name": "Board Fan",
"Probe": "TRUE",
"Type": "Board",
"xyz.openbmc_project.Inventory.Decorator.Asset": {
"Manufacturer": "",
"Model": "",
"PartNumber": "",
"SerialNumber": ""
},
"xyz.openbmc_project.Inventory.Item.Bmc": {
"Present": true,
"Functional": true
}
}
@@ -0,0 +1,4 @@
{
"buses": [
]
}
@@ -0,0 +1,15 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
SRC_URI:append = " \
file://blacklist.json \
file://Lux-Baseboard.json \
file://0001-Add-Status-interface-to-settableInterfaces.patch \
"
do_install:append () {
rm -rf ${D}/usr/share/entity-manager/configurations/*.json
install -d ${D}${datadir}/${PN}
install -d ${D}/usr/share/entity-manager/configurations
install -m 0644 -D ${WORKDIR}/blacklist.json ${D}${datadir}/${PN}/blacklist.json
install -m 0444 ${WORKDIR}/Lux-Baseboard.json ${D}/usr/share/entity-manager/configurations
}
@@ -0,0 +1,31 @@
SUMMARY = "YAML configuration for luxshare"
PR = "r1"
LICENSE = "CLOSED"
inherit allarch
SRC_URI = " \
file://lux-ipmi-fru.yaml \
file://lux-ipmi-sensors.yaml \
file://lux-ipmi-fru-properties.yaml \
file://lux-ipmi-inventory-sensors.yaml \
"
S = "${WORKDIR}"
do_install() {
install -m 0644 -D lux-ipmi-fru.yaml ${D}${datadir}/${BPN}/ipmi-fru-read.yaml
install -m 0644 -D lux-ipmi-sensors.yaml ${D}${datadir}/${BPN}/ipmi-sensors.yaml
install -m 0644 -D lux-ipmi-fru-properties.yaml ${D}${datadir}/${BPN}/ipmi-extra-properties.yaml
install -m 0644 -D lux-ipmi-inventory-sensors.yaml ${D}${datadir}/${BPN}/ipmi-inventory-sensors.yaml
}
FILES:${PN}: = " \
${datadir}/${BPN}/ipmi-fru-read.yaml \
${datadir}/${BPN}/ipmi-sensors.yaml \
${datadir}/${BPN}/ipmi-extra-properties.yaml \
${datadir}/${BPN}/ipmi-inventory-sensors.yaml \
"
ALLOW_EMPTY:${PN} = "1"
@@ -0,0 +1,21 @@
/system:
xyz.openbmc_project.Inventory.Decorator.Cacheable:
Cached: 'true'
xyz.openbmc_project.Inventory.Decorator.Replaceable:
FieldReplaceable: 'true'
xyz.openbmc_project.Inventory.Item:
Present: 'true'
/system/board:
xyz.openbmc_project.Inventory.Decorator.Cacheable:
Cached: 'true'
xyz.openbmc_project.Inventory.Decorator.Replaceable:
FieldReplaceable: 'true'
xyz.openbmc_project.Inventory.Item:
Present: 'true'
/system/board/Mobile:
xyz.openbmc_project.Inventory.Decorator.Cacheable:
Cached: 'true'
xyz.openbmc_project.Inventory.Decorator.Replaceable:
FieldReplaceable: 'true'
xyz.openbmc_project.Inventory.Item:
Present: 'true'
@@ -0,0 +1,12 @@
0:
/xyz/openbmc_project/FruDevice/Mobile:
entityID: 7
entityInstance: 1
interfaces:
xyz.openbmc_project.FruDevice:
PRODUCT_MANUFACTURER:
IPMIFruProperty: Manufacturer
IPMIFruSection: Product
PRODUCT_PRODUCT_NAME:
IPMIFruProperty: Name
IPMIFruSection: Product

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