[OSADL-svn-commits] r53 - in fddi-20070618-1-trunk: doc tests
OSADL repository commits
osadl-svn-commits at lists.osadl.org
Tue Oct 2 11:44:49 CEST 2007
Author: robert
Date: Wed Jul 11 21:02:15 2007
New Revision: 53
Log:
Added:
fddi-20070618-1-trunk/doc/header.txt
fddi-20070618-1-trunk/tests/test_fddi_examplebus_tpu_usecase.c
Added: fddi-20070618-1-trunk/doc/header.txt
==============================================================================
--- (empty file)
+++ fddi-20070618-1-trunk/doc/header.txt Wed Jul 11 21:02:15 2007
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2007 Robert Schwebel <r.schwebel at pengutronix.de>
+ *
+ * This file is part of the OSADL Fieldbus Framework.
+ *
+ * The OSADL Fieldbus Framework is free software; you can redistribute it
+ * and/or modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation. Note that there
+ * is a special link exception; see COPYING for details.
+ *
+ * The OSADL Fieldbus Framework 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 Lesser General Public
+ * License along with the OSADL Fieldbus Framework; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307 USA.
+ */
Added: fddi-20070618-1-trunk/tests/test_fddi_examplebus_tpu_usecase.c
==============================================================================
--- (empty file)
+++ fddi-20070618-1-trunk/tests/test_fddi_examplebus_tpu_usecase.c Wed Jul 11 21:02:15 2007
@@ -0,0 +1,150 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <osadl/fddi.h>
+
+int main(void)
+{
+ fddi_iface_attr_t exb0_attr;
+ fddi_iface_t exb0_iface;
+ fddi_tpu_t *tpu;
+
+ int ret;
+
+ /* instanciate io_interface */
+ fddi_iface_attr_init(&exb0_attr);
+ fddi_iface_attr_setclass(&exb0_attr, "libfddi_examplebus.so");
+ fddi_iface_attr_setdevice(&exb0_attr, "exb0");
+
+ ret = fddi_iface_init(&exb0_iface, &exb0_attr);
+ if (ret) {
+ fprintf(stderr, "fddi_iface_init() failed\n");
+ return ret;
+ }
+
+ ret = fddi_iface_configure(&exb0_iface, "config.xml", NULL);
+ if (ret) {
+ fprintf(stderr, "fddi_iface_configure() failed\n");
+ fddi_iface_destroy(&exb0_iface);
+ return ret;
+ }
+
+ /* destruct io_interface */
+ fddi_iface_destroy(&exb0_iface);
+
+ exit(0);
+}
+
+/* FIXME pseudocode */
+
+int main1(void)
+{
+ int endme;
+ pv_engine_t engine;
+ pv_engine_attr_t engine_attr;
+ pv_group_t group;
+ int ret;
+
+ struct pv {
+ pv_uint32_t voltage;
+ pv_uint32_t speed;
+ pv_uint32_t x;
+ pv_bool_t end_switch_left;
+ pv_bool_t end_switch_right;
+ }
+
+ /* instanciate a pv_engine */
+ ret = pv_engine_init(&engine, &engine_attr);
+ if (ret) {
+ fprintf(stderr, "pv_init() failed\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * now register a pv_group (lockable set of pvs)
+ * let's take for example a linear drive
+ */
+
+ ret = pv_group_init(&group);
+ if (ret) {
+ fprintf(stderr, "pv_group_init() failed\n");
+ pv_engine_destroy(&engine);
+ exit(EXIT_FAILURE);
+ }
+
+ ret = 0;
+ ret += pv_group_register_uint32(&group, "voltage", &pv.voltage, O_RDWR);
+ ret += pv_group_register_uint32(&group, "current_speed", &pv.current_speed, O_RDONLY);
+ ret += pv_group_register_uint32(&group, "current_x", &pv.current_x, O_RDONLY);
+ ret += pv_group_register_bool(&group, "end_switch_left", &pv.end_switch_left, O_RDONLY);
+ ret += pv_group_register_bool(&group, "end_switch_right", &pv.end_switch_right, O_RDONLY);
+
+ if (ret != 0) {
+ fprintf(stderr, "error registering process variables\n");
+ pv_group_destroy(&group);
+ pv_engine_destroy(&engine);
+ exit(EXIT_FAILURE);
+ }
+
+ /* example for "active / locking" scenario */
+
+ while (!endme) {
+
+ /*
+ * "lock" the pv_group while updating the pvs; note that the
+ * pv_group contains a list of all affected TPUs, and locking
+ * means that we "allocate" a tpu (usecount+=1) while accessing it
+ */
+ pv_group_lock(&group, timeout);
+
+ /* starting from here, we have our exclusive sets of TPU buffers */
+
+ /* yes, printf is not realtime, just for demonstration */
+ printf("current speed: \n", pv_uint32_get(&pv.current_speed));
+ printf("current x: \n", pv_uint32_get(&pv.current_x));
+ printf("end_switch_left: \n", pv_bool_get(&pv.end_switch_left));
+ printf("end_switch_right: \n", pv_bool_get(&pv.end_switch_right));
+
+ /* now calculate the outputs */
+ pv_uint32_set(&pv.voltage, 12345);
+
+ /*
+ * update outputs
+ */
+ pv_group_unlock(&group);
+
+ sleep_until_next_period();
+
+ }
+
+ /* example for "blocking" scenario, for group */
+
+ while (!endme) {
+ /* sleep until one of the TPUs in the group updates */
+ pv_group_lock_on_group_change(&group, timeout);
+ /* do something with the pvs, or find out which pvs have changed */
+ pv_group_unlock(&group);
+ }
+
+ /* example for "blocking" scenario, for pv */
+
+ while (!endme) {
+ pv_group_lock_on_pv_change(&group, &pv.current.speed, timeout);
+ /* ... */
+ pv_group_unlock(&group);
+ }
+
+ /* example for "callback" scenario */
+ pv_group_callback_on_group_change(&group, function);
+ pv_group_callback_on_pv_change(&group, &pv.current.speed, function);
+
+ while (!endme)
+ sleep(1);
+
+ /* destruct */
+ pv_set_destroy(&set);
+ pv_engine_destroy(&engine);
+
+ return 0;
+}
+
More information about the OSADL-svn-commits
mailing list