# HG changeset patch # User Paul Boddie # Date 1609433943 -3600 # Node ID 50b5bc23fbc5be53e775f23c6e7fcbaa60e980a5 # Parent 94f26795b5edd6eeaa4bf92f15f1ff3a1a1c120b Converted the PWM device to use interface descriptions and generated components. This affects the Letux 400 backlight device. diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/Control --- a/pkg/devices/Control Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/Control Thu Dec 31 17:59:03 2020 +0100 @@ -29,7 +29,6 @@ provides: libdevice-keypad-server provides: libdevice-lcd provides: libdevice-lcd-jz4740 -provides: libdevice-pwm-client provides: libdevice-util provides: libdrivers-common provides: libdrivers-cpm diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/backlight/src/pwm/Makefile --- a/pkg/devices/backlight/src/pwm/Makefile Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/backlight/src/pwm/Makefile Thu Dec 31 17:59:03 2020 +0100 @@ -23,23 +23,27 @@ # Individual interfaces. +CLIENT_INTERFACES_CC = activation pwm + SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC)) # Generated and plain source files. +CLIENT_INTERFACES_SRC_CC = $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC)) + SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC)) PLAIN_SRC_CC = backlight-pwm.cc # Normal definitions. -SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) +SRC_CC = $(CLIENT_INTERFACES_SRC_CC) $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) -REQUIRES_LIBS = l4re_c l4re_c-util libdevice-pwm-client libipc +REQUIRES_LIBS = l4re_c l4re_c-util libipc PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) include $(L4DIR)/mk/prog.mk include $(IDL_MK_DIR)/interface_rules.mk -$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC) +$(PLAIN_SRC_CC): $(CLIENT_INTERFACES_SRC_CC) $(SERVER_INTERFACES_SRC_CC) diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/backlight/src/pwm/backlight-pwm.cc --- a/pkg/devices/backlight/src/pwm/backlight-pwm.cc Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/backlight/src/pwm/backlight-pwm.cc Thu Dec 31 17:59:03 2020 +0100 @@ -19,19 +19,14 @@ * Boston, MA 02110-1301, USA */ -#include -#include +#include #include -#include - #include #include "backlight_object_server.h" - -/* PWM access abstractions. */ - -static L4::Cap pwm_device; +#include "activation_client.h" +#include "pwm_client.h" @@ -39,11 +34,14 @@ class server_BacklightObject : public BacklightObject { + Activation *_activation; + PWM *_pwm; int _min, _max; public: - explicit server_BacklightObject(int min, int max) - : _min(min), _max(max) + explicit server_BacklightObject(Activation *activation, PWM *pwm, + int min, int max) + : _activation(activation), _pwm(pwm), _min(min), _max(max) { } @@ -51,7 +49,7 @@ long disable() { - pwm_device->disable(); + _activation->disable(); return L4_EOK; } @@ -59,7 +57,7 @@ long enable() { - pwm_device->enable(); + _activation->enable(); return L4_EOK; } @@ -67,7 +65,7 @@ long set_brightness(int level) { - pwm_device->set_duty(level); + _pwm->set_duty(level); return L4_EOK; } }; @@ -85,15 +83,18 @@ /* Obtain a reference to the PWM device. */ - pwm_device = L4Re::Env::env()->get_cap("pwm"); - if (!pwm_device.is_valid()) return 1; + l4_cap_idx_t pwm = l4re_env_get_cap("pwm"); + if (!l4_is_valid_cap(pwm)) return 1; + + client_Activation activation_obj(pwm); + client_PWM pwm_obj(pwm); /* Initialise and register a new server object. */ min = atoi(argv[1]); max = atoi(argv[2]); - server_BacklightObject obj(min, max); + server_BacklightObject obj(&activation_obj, &pwm_obj, min, max); l4_cap_idx_t server; if (ipc_server_bind("backlight", (l4_umword_t) &obj, &server)) return 1; diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/include/protocols.h --- a/pkg/devices/include/protocols.h Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/include/protocols.h Thu Dec 31 17:59:03 2020 +0100 @@ -23,4 +23,5 @@ #define LANDFALL_ACTIVATION 0x1f01 #define LANDFALL_BACKLIGHT 0x1f02 +#define LANDFALL_PWM 0x1f10 #define LANDFALL_SPI 0x1f13 diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/include/Makefile --- a/pkg/devices/pwm/include/Makefile Thu Dec 31 16:58:39 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -PKGDIR = ../.. -L4DIR ?= $(PKGDIR)/../.. - -include $(L4DIR)/mk/include.mk diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/include/pwm-client.h --- a/pkg/devices/pwm/include/pwm-client.h Thu Dec 31 16:58:39 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * PWM client to access PWM servers. - * - * Copyright (C) 2018 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#pragma once - -#ifdef __cplusplus - -#include -#include "pwm-ops.h" - -/* PWM device interface. */ - -class Pwm_device_interface : public L4::Kobject_t -{ - L4_KOBJECT(Pwm_device_interface) - -public: - int disable() throw(); - int enable() throw(); - int set_control(int control) throw(); - int set_duty(int duty) throw(); - int set_period(int period) throw(); -}; - -#endif diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/include/pwm-ops.h --- a/pkg/devices/pwm/include/pwm-ops.h Thu Dec 31 16:58:39 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -/* - * PWM server operations. - * - * Copyright (C) 2018 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#pragma once - -enum { Pwm_op_disable, Pwm_op_enable, Pwm_op_set_control, Pwm_op_set_duty, Pwm_op_set_period }; diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/src/Makefile --- a/pkg/devices/pwm/src/Makefile Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/pwm/src/Makefile Thu Dec 31 17:59:03 2020 +0100 @@ -1,6 +1,6 @@ PKGDIR ?= ../.. L4DIR ?= $(PKGDIR)/../.. -TARGET := client jz4730 +TARGET := jz4730 include $(L4DIR)/mk/subdir.mk diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/src/client/Makefile --- a/pkg/devices/pwm/src/client/Makefile Thu Dec 31 16:58:39 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -PKGDIR ?= ../../.. -L4DIR ?= $(PKGDIR)/../.. - -TARGET = libdevice_pwm_client.o.a libdevice_pwm_client.o.so -PC_FILENAME := libdevice-pwm-client - -SRC_CC := pwm-client.cc - -PRIVATE_INCDIR += $(PKGDIR)/pwm/include - -REQUIRES_LIBS := l4re_c l4re_c-util - -include $(L4DIR)/mk/lib.mk diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/src/client/pwm-client.cc --- a/pkg/devices/pwm/src/client/pwm-client.cc Thu Dec 31 16:58:39 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * PWM client library to access PWM servers. - * - * Copyright (C) 2018 Paul Boddie - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA - */ - -#include -#include - -#include "pwm-client.h" - -/* PWM device interface. */ - -int -Pwm_device_interface::disable() throw() -{ - L4::Ipc::Iostream s(l4_utcb()); - - return l4_error(s.call(cap(), Pwm_op_disable)); -} - -int -Pwm_device_interface::enable() throw() -{ - L4::Ipc::Iostream s(l4_utcb()); - - return l4_error(s.call(cap(), Pwm_op_enable)); -} - -int -Pwm_device_interface::set_control(int control) throw() -{ - L4::Ipc::Iostream s(l4_utcb()); - - s << control; - return l4_error(s.call(cap(), Pwm_op_set_control)); -} - -int -Pwm_device_interface::set_duty(int duty) throw() -{ - L4::Ipc::Iostream s(l4_utcb()); - - s << duty; - return l4_error(s.call(cap(), Pwm_op_set_duty)); -} - -int -Pwm_device_interface::set_period(int period) throw() -{ - L4::Ipc::Iostream s(l4_utcb()); - - s << period; - return l4_error(s.call(cap(), Pwm_op_set_period)); -} diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/src/jz4730/Makefile --- a/pkg/devices/pwm/src/jz4730/Makefile Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/pwm/src/jz4730/Makefile Thu Dec 31 17:59:03 2020 +0100 @@ -3,12 +3,43 @@ TARGET = dev_pwm_jz4730 MODE = shared -PC_FILENAME := devices-pwm-jz4730 +PC_FILENAME = devices-pwm-jz4730 + +# Locations for interface input and generated output. + +IDL_DIR = $(PKGDIR)/idl +IDL_MK_DIR = $(L4DIR)/idl4re/mk +IDL_BUILD_DIR = . +IDL_EXPORT_DIR = . -SRC_CC := pwm-jz4730.cc +include $(IDL_MK_DIR)/idl.mk + +# Compound interface definitions. + +pwm_object_NAME = PWMObject +pwm_object_INTERFACES = activation pwm + +COMP_INTERFACES_CC = pwm_object -PRIVATE_INCDIR += $(PKGDIR)/pwm/include $(PKGDIR)/util/include +# Individual interfaces. + +SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC)) + +# Generated and plain source files. + +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC)) -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-util libdrivers-pwm libdrivers-gpio # to use GPIO device +PLAIN_SRC_CC = pwm-jz4730.cc + +# Normal definitions. + +SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) + +REQUIRES_LIBS = l4re_c l4re_c-util libdevice-util libdrivers-pwm libdrivers-gpio libipc + +PRIVATE_INCDIR = $(PKGDIR)/pwm/include $(PKGDIR)/util/include $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) include $(L4DIR)/mk/prog.mk +include $(IDL_MK_DIR)/interface_rules.mk + +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC) diff -r 94f26795b5ed -r 50b5bc23fbc5 pkg/devices/pwm/src/jz4730/pwm-jz4730.cc --- a/pkg/devices/pwm/src/jz4730/pwm-jz4730.cc Thu Dec 31 16:58:39 2020 +0100 +++ b/pkg/devices/pwm/src/jz4730/pwm-jz4730.cc Thu Dec 31 17:59:03 2020 +0100 @@ -1,7 +1,7 @@ /* * Export a JZ4730 PWM peripheral as a server. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2018, 2020 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -21,16 +21,15 @@ #include #include +#include -#include -#include -#include +#include #include #include -#include "pwm-ops.h" -#include "memory.h" +#include +#include "pwm_object_server.h" /* Virtual addresses for the GPIO and PWM register blocks. */ @@ -54,7 +53,7 @@ /* PWM peripheral device. */ -class Pwm_device_server : public L4::Server_object_t +class server_PWMObject : public PWMObject { Pwm_jz4730_chip *_device = 0; int _duty, _period, _prescale; @@ -62,94 +61,62 @@ public: /* Associate the device with a particular memory region. */ - explicit Pwm_device_server(Pwm_jz4730_chip *device, int duty, int period, int prescale) + explicit server_PWMObject(Pwm_jz4730_chip *device, int duty, int period, + int prescale) : _device(device), _duty(duty), _period(period), _prescale(prescale) { } - /* Dispatch incoming requests. */ - - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) - { - l4_msgtag_t tag; - int arg; - - (void) obj; - ios >> tag; - - switch (tag.label()) - { - case Pwm_op_disable: - disable(); - return L4_EOK; + /* Disable the device. */ - case Pwm_op_enable: - enable(); - return L4_EOK; - - case Pwm_op_set_control: - ios >> arg; - set_control(arg); - return L4_EOK; - - case Pwm_op_set_duty: - ios >> arg; - set_duty(arg); - return L4_EOK; - - case Pwm_op_set_period: - ios >> arg; - set_period(arg); - return L4_EOK; - - default: - return -L4_EBADPROTO; - } + long disable() + { + _device->disable(); + return L4_EOK; } - void disable() - { - _device->disable(); - } + /* Enable the device. */ - void enable() + long enable() { set_duty(_duty); set_period(_period); set_control(0x80 | _prescale); /* enable | prescale */ + return L4_EOK; } /* Set the control register. */ - void set_control(uint8_t control) + long set_control(uint8_t control) { _device->set_control(control); + return L4_EOK; } /* Set the PWM duty cycle. */ - void set_duty(uint16_t duty) + long set_duty(uint16_t duty) { _duty = duty; _device->set_duty(duty); + return L4_EOK; } /* Set the PWM period. */ - void set_period(uint16_t period) + long set_period(uint16_t period) { _period = period; _device->set_period(period); + return L4_EOK; } }; -static L4Re::Util::Registry_server<> server; - /* Initialise devices and start the server. */ -static void run(int number, int duty, int period, int prescale) +static int run(int number, int duty, int period, int prescale) { Pwm_jz4730_chip pwm_device(pwm_virt_base + number * 0x1000, pwm_virt_base + (number + 1) * 0x1000); @@ -163,12 +130,16 @@ /* Initialise and register a new server object. */ - Pwm_device_server server_obj(&pwm_device, duty, period, prescale); - server.registry()->register_obj(&server_obj, "pwm"); + server_PWMObject obj(&pwm_device, duty, period, prescale); + l4_cap_idx_t server; + + if (ipc_server_bind("pwm", (l4_umword_t) &obj, &server)) return 1; /* Enter the IPC server loop. */ - server.loop(); + ipc_server_loop(PWMObject_expected_items, &obj, + (ipc_server_handler_type) handle_PWMObject); + return 0; } @@ -197,6 +168,5 @@ if (setup_memory()) return 1; - run(number, duty, period, prescale); - return 0; + return run(number, duty, period, prescale); }