diff options
author | Yong Li <yong.b.li@linux.intel.com> | 2018-05-22 13:17:19 +0300 |
---|---|---|
committer | Yong Li <yong.b.li@linux.intel.com> | 2018-05-22 14:00:02 +0300 |
commit | 2d43ed2bf9ef9ec30af8f5bb91d5b45a5ad72004 (patch) | |
tree | 171836b7b04776fbc78a255a1f378f3e001a9295 /services | |
parent | 54d185a631afc2d3c73b3f69bda20c08ba6bcc94 (diff) | |
download | provingground-2d43ed2bf9ef9ec30af8f5bb91d5b45a5ad72004.tar.xz |
Add ID button support
Using reset button as a template
Change-Id: Iccdaa758e15c913271426ec5d9b27aee92468593
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Diffstat (limited to 'services')
6 files changed, 204 insertions, 1 deletions
diff --git a/services/chassis/Buttons/CMakeLists.txt b/services/chassis/Buttons/CMakeLists.txt index a26c637..7421972 100644 --- a/services/chassis/Buttons/CMakeLists.txt +++ b/services/chassis/Buttons/CMakeLists.txt @@ -17,13 +17,17 @@ set(POWER_DBUS_INTF_NAME "xyz.openbmc_project.Chassis.Buttons.Power") set(RESET_DBUS_OBJECT_NAME "xyz/openbmc_project/Chassis/Buttons/Reset") set(RESET_DBUS_INTF_NAME "xyz.openbmc_project.Chassis.Buttons.Reset") -add_definitions(-DPOWER_DBUS_OBJECT_NAME="/${POWER_DBUS_OBJECT_NAME}0") +set(ID_DBUS_OBJECT_NAME "xyz/openbmc_project/Chassis/Buttons/ID") +set(ID_DBUS_INTF_NAME "xyz.openbmc_project.Chassis.Buttons.ID") +add_definitions(-DPOWER_DBUS_OBJECT_NAME="/${POWER_DBUS_OBJECT_NAME}0") add_definitions(-DRESET_DBUS_OBJECT_NAME="/${RESET_DBUS_OBJECT_NAME}0") +add_definitions(-DID_DBUS_OBJECT_NAME="/${ID_DBUS_OBJECT_NAME}0") set(SRC_FILES src/PowerButton.cpp src/ResetButton.cpp + src/IDButton.cpp src/main.cpp ) set(GENERATED_SRC_FILES @@ -31,6 +35,8 @@ set(GENERATED_SRC_FILES ${POWER_DBUS_OBJECT_NAME}/server.cpp ${RESET_DBUS_OBJECT_NAME}/error.cpp ${RESET_DBUS_OBJECT_NAME}/server.cpp + ${ID_DBUS_OBJECT_NAME}/error.cpp + ${ID_DBUS_OBJECT_NAME}/server.cpp ) # import libsystemd @@ -61,6 +67,19 @@ link_directories(${DBUSINTERFACE_LIBRARY_DIRS}) #include_directories(${CMAKE_CURRENT_BINARY_DIR}/${DBUS_OBJECT_NAME}) add_custom_command( + OUTPUT ${ID_DBUS_OBJECT_NAME}/error.hpp + OUTPUT ${ID_DBUS_OBJECT_NAME}/error.cpp + COMMAND mkdir -p ${ID_DBUS_OBJECT_NAME} + COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} error exception-header ${ID_DBUS_INTF_NAME} > ${ID_DBUS_OBJECT_NAME}/error.hpp + COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} error exception-cpp ${ID_DBUS_INTF_NAME} > ${ID_DBUS_OBJECT_NAME}/error.cpp + DEPENDS ${ID_DBUS_OBJECT_NAME}.errors.yaml +) +set_source_files_properties( + ${ID_DBUS_OBJECT_NAME}/error.hpp + ${ID_DBUS_OBJECT_NAME}/error.cpp + PROPERTIES GENERATED TRUE) + +add_custom_command( OUTPUT ${POWER_DBUS_OBJECT_NAME}/error.hpp OUTPUT ${POWER_DBUS_OBJECT_NAME}/error.cpp COMMAND mkdir -p ${POWER_DBUS_OBJECT_NAME} @@ -87,6 +106,19 @@ set_source_files_properties( PROPERTIES GENERATED TRUE) add_custom_command( + OUTPUT ${ID_DBUS_OBJECT_NAME}/server.hpp + OUTPUT ${ID_DBUS_OBJECT_NAME}/server.cpp + COMMAND mkdir -p ${ID_DBUS_OBJECT_NAME} + COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} interface server-header ${ID_DBUS_INTF_NAME} > ${ID_DBUS_OBJECT_NAME}/server.hpp + COMMAND ${SDBUSPLUSPLUS} -r ${CMAKE_CURRENT_SOURCE_DIR} interface server-cpp ${ID_DBUS_INTF_NAME} > ${ID_DBUS_OBJECT_NAME}/server.cpp + DEPENDS ${ID_DBUS_OBJECT_NAME}.interface.yaml +) +set_source_files_properties( + ${POWER_DBUS_OBJECT_NAME}/server.hpp + ${POWER_DBUS_OBJECT_NAME}/server.cpp + PROPERTIES GENERATED TRUE) + +add_custom_command( OUTPUT ${POWER_DBUS_OBJECT_NAME}/server.hpp OUTPUT ${POWER_DBUS_OBJECT_NAME}/server.cpp COMMAND mkdir -p ${POWER_DBUS_OBJECT_NAME} diff --git a/services/chassis/Buttons/inc/IDButton.hpp b/services/chassis/Buttons/inc/IDButton.hpp new file mode 100644 index 0000000..d050dce --- /dev/null +++ b/services/chassis/Buttons/inc/IDButton.hpp @@ -0,0 +1,96 @@ +#pragma once +#include "xyz/openbmc_project/Chassis/Buttons/ID/error.hpp" +#include "xyz/openbmc_project/Chassis/Buttons/ID/server.hpp" +#include "Common.hpp" +#include "Gpio.hpp" + +const static constexpr char *ID_BUTTON = "ID_BTN"; + +struct IDButton + : sdbusplus::server::object::object< + sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID> +{ + + IDButton(sdbusplus::bus::bus &bus, const char *path, EventPtr &event, + sd_event_io_handler_t handler = IDButton::EventHandler) : + sdbusplus::server::object::object< + sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID>( + bus, path), + fd(-1), bus(bus), event(event), callbackHandler(handler) + { + + int ret; + + // config gpio + ret = ::configGpio(ID_BUTTON, &fd, bus); + if (ret < 0) + { + throw std::runtime_error("failed to config GPIO"); + } + + ret = sd_event_add_io(event.get(), nullptr, fd, EPOLLPRI, + callbackHandler, this); + if (ret < 0) + { + throw std::runtime_error("failed to add to event loop"); + } + } + + ~IDButton() + { + ::closeGpio(fd); + } + bool simPress() override; + static int EventHandler(sd_event_source *es, int fd, uint32_t revents, + void *userdata) + { + + int n; + char buf; + + IDButton *idButton = static_cast<IDButton *>(userdata); + + if (!idButton) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "null pointer!"); + return -1; + } + + n = ::lseek(fd, 0, SEEK_SET); + + if (n < 0) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "lseek error!"); + return n; + } + + n = ::read(fd, &buf, 1); + if (n < 0) + { + phosphor::logging::log<phosphor::logging::level::ERR>( + "read error!"); + return n; + } + + if (buf == '0') + { + // emit pressed signal + idButton->pressed(); + } + else + { + // released + idButton->released(); + } + + return 0; + } + + private: + int fd; + sdbusplus::bus::bus &bus; + EventPtr &event; + sd_event_io_handler_t callbackHandler; +}; diff --git a/services/chassis/Buttons/src/IDButton.cpp b/services/chassis/Buttons/src/IDButton.cpp new file mode 100644 index 0000000..30f6157 --- /dev/null +++ b/services/chassis/Buttons/src/IDButton.cpp @@ -0,0 +1,39 @@ +/* +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +*/ +#include <chrono> +#include <experimental/filesystem> +#include <fcntl.h> +#include <fstream> +#include <iostream> +#include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> +#include <phosphor-logging/log.hpp> +#include <sys/stat.h> +#include <sys/types.h> +#include <systemd/sd-event.h> +#include <unistd.h> +#include <xyz/openbmc_project/Common/error.hpp> +#include "IDButton.hpp" + +const static constexpr char *SYSMGR_SERVICE = "org.openbmc.managers.System"; +const static constexpr char *SYSMGR_OBJ_PATH = "/org/openbmc/managers/System"; +const static constexpr char *SYSMGR_INTERFACE = "org.openbmc.managers.System"; + +bool IDButton::simPress() +{ + pressed(); + return true; +}
\ No newline at end of file diff --git a/services/chassis/Buttons/src/main.cpp b/services/chassis/Buttons/src/main.cpp index a329dab..24e6189 100644 --- a/services/chassis/Buttons/src/main.cpp +++ b/services/chassis/Buttons/src/main.cpp @@ -13,6 +13,7 @@ #include <xyz/openbmc_project/Common/error.hpp> #include "ResetButton.hpp" #include "PowerButton.hpp" +#include "IDButton.hpp" int main(int argc, char *argv[]) { @@ -42,6 +43,8 @@ int main(int argc, char *argv[]) ResetButton resetButton{bus, RESET_DBUS_OBJECT_NAME, eventP}; + IDButton idButton{bus, ID_DBUS_OBJECT_NAME, eventP}; + try { bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); diff --git a/services/chassis/Buttons/xyz/openbmc_project/Chassis/Buttons/ID.errors.yaml b/services/chassis/Buttons/xyz/openbmc_project/Chassis/Buttons/ID.errors.yaml new file mode 100644 index 0000000..9de4b9d --- /dev/null +++ b/services/chassis/Buttons/xyz/openbmc_project/Chassis/Buttons/ID.errors.yaml @@ -0,0 +1,9 @@ +- name: UnsupportedCommand + description: > + An unsupported command was attempted. +- name: InvalidParameter + description: > + An invalid parameter was attempted. +- name: IOError + description: > + An IO error occurred. diff --git a/services/chassis/Buttons/xyz/openbmc_project/Chassis/Buttons/ID.interface.yaml b/services/chassis/Buttons/xyz/openbmc_project/Chassis/Buttons/ID.interface.yaml new file mode 100644 index 0000000..e25942f --- /dev/null +++ b/services/chassis/Buttons/xyz/openbmc_project/Chassis/Buttons/ID.interface.yaml @@ -0,0 +1,24 @@ +description: > + ID button control service +methods: + - name: simPress + description: > + emulate ID button press. + returns: + - name: state + type: boolean + description: > + The result of command. + errors: + - self.Error.UnsupportedCommand + - self.Error.InvalidParameter + - self.Error.IOError + + +signals: + - name: Released + description: > + ID button release signal + - name: Pressed + description: > + ID button pressed signal |