new objects
diff --git a/objects/control_host_obj.c b/objects/control_host_obj.c
new file mode 100644
index 0000000..fafcd31
--- /dev/null
+++ b/objects/control_host_obj.c
@@ -0,0 +1,160 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include "interfaces/control_host.h"
+#include "objects/openbmc_utilities.h"
+
+
+/* ---------------------------------------------------------------------------------------------------- */
+static const gchar* dbus_object_path = "/org/openbmc/control/Host";
+static const gchar* dbus_name = "org.openbmc.control.Host";
+
+static GDBusObjectManagerServer *manager = NULL;
+static ControlHost *control_host = NULL;
+
+GPIO fsi_data = (GPIO){ "FSI_DATA" };
+GPIO fsi_clk = (GPIO){ "FSI_CLK" };
+GPIO fsi_enable = (GPIO){ "FSI_ENABLE" };
+GPIO cronus_sel = (GPIO){ "CRONUS_SEL" };
+
+
+static gboolean
+on_boot (ControlHost *host,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ // TODO: Implement gpio toggling
+ g_print("Boot\n");
+
+ control_host_complete_boot(host,invocation);
+
+ gpio_open(&fsi_clk);
+ gpio_open(&fsi_data);
+ gpio_open(&fsi_enable);
+ gpio_open(&cronus_sel);
+
+ gpio_write(&cronus_sel,1);
+ //putcfam pu 281c 30000000 -p0
+ char a[] = "000011111111110101111000111001100111111111111111111111111111101111111111";
+ //putcfam pu 281c B0000000 -p0
+ char b[] = "000011111111110101111000111000100111111111111111111111111111101101111111";
+
+ gpio_write(&fsi_enable,1);
+ gpio_write(&fsi_clk,1);
+ gpio_write(&fsi_data,1);
+ gpio_clock_cycle(&fsi_clk,5000);
+ gpio_write(&fsi_data,0);
+ gpio_clock_cycle(&fsi_clk,256);
+ gpio_write(&fsi_data,1);
+ gpio_clock_cycle(&fsi_clk,50);
+ uint16_t i=0;
+ for(i=0;i<strlen(a);i++) {
+ gpio_writec(&fsi_data,a[i]);
+ gpio_clock_cycle(&fsi_clk,1);
+ }
+ gpio_write(&fsi_data,1); /* Data standby state */
+ gpio_clock_cycle(&fsi_clk,5000);
+
+ for(i=0;i<strlen(b);i++) {
+ gpio_writec(&fsi_data,b[i]);
+ gpio_clock_cycle(&fsi_clk,1);
+ }
+ gpio_write(&fsi_data,1); /* Data standby state */
+ gpio_clock_cycle(&fsi_clk,2);
+
+ gpio_write(&fsi_clk,0); /* hold clk low for clock mux */
+ gpio_write(&fsi_enable,0);
+ gpio_clock_cycle(&fsi_clk,16);
+ gpio_write(&fsi_clk,0); /* Data standby state */
+
+ gpio_close(&fsi_clk);
+ gpio_close(&fsi_data);
+ gpio_close(&fsi_enable);
+ gpio_close(&cronus_sel);
+
+ control_host_emit_booted(host);
+ return TRUE;
+}
+
+static void
+on_bus_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ ObjectSkeleton *object;
+ g_print ("Acquired a message bus connection: %s\n",name);
+ manager = g_dbus_object_manager_server_new (dbus_object_path);
+
+ gchar *s;
+ s = g_strdup_printf ("%s/0",dbus_object_path);
+ object = object_skeleton_new (s);
+ g_free (s);
+ control_host = control_host_skeleton_new ();
+ object_skeleton_set_control_host (object, control_host);
+ g_object_unref (control_host);
+
+ //define method callbacks here
+ g_signal_connect (control_host,
+ "handle-boot",
+ G_CALLBACK (on_boot),
+ NULL); /* user_data */
+
+ /* Export the object (@manager takes its own reference to @object) */
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
+
+ /* Export all objects */
+ g_dbus_object_manager_server_set_connection (manager, connection);
+
+ gpio_init(connection,&fsi_data);
+ gpio_init(connection,&fsi_clk);
+ gpio_init(connection,&fsi_enable);
+ gpio_init(connection,&cronus_sel);
+
+}
+
+static void
+on_name_acquired (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_print ("Acquired the name %s\n", name);
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ g_print ("Lost the name %s\n", name);
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+ GMainLoop *loop;
+
+ guint id;
+ //g_type_init ();
+ loop = g_main_loop_new (NULL, FALSE);
+
+ id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ dbus_name,
+ G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
+ G_BUS_NAME_OWNER_FLAGS_REPLACE,
+ on_bus_acquired,
+ on_name_acquired,
+ on_name_lost,
+ loop,
+ NULL);
+
+ g_main_loop_run (loop);
+
+ g_bus_unown_name (id);
+ g_main_loop_unref (loop);
+ return 0;
+}
diff --git a/objects/openbmc_utilities.c b/objects/openbmc_utilities.c
new file mode 100644
index 0000000..d03fdb4
--- /dev/null
+++ b/objects/openbmc_utilities.c
@@ -0,0 +1,137 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <argp.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+
+#include "interfaces/power_control.h"
+#include "objects/openbmc_utilities.h"
+
+void gpio_writec(GPIO* gpio, char value)
+{
+ char buf[1];
+ buf[0] = value;
+ if (write(gpio->fd, buf, 1) != 1)
+ {
+ //TODO: error handling
+ printf("Write error\n");
+ }
+}
+
+void gpio_write(GPIO* gpio, uint8_t value)
+{
+ char buf[1];
+ buf[0] = '0';
+ if (value==1)
+ {
+ buf[0]='1';
+ }
+ if (write(gpio->fd, buf, 1) != 1)
+ {
+ //TODO: error handling
+ printf("write error\n");
+ }
+}
+
+uint8_t gpio_read(GPIO* gpio)
+{
+ char buf[1];
+ if (read(gpio->fd,&buf,1) != 1)
+ {
+ //TODO: error hjandling
+ printf("read error\n");
+ }
+ if (buf[0]=='1') {
+ return 1;
+ }
+ return 0;
+
+}
+void gpio_clock_cycle(GPIO* gpio, int num_clks) {
+ int i=0;
+ for (i=0;i<num_clks;i++) {
+ gpio_writec(gpio,'0');
+ gpio_writec(gpio,'1');
+ }
+}
+
+// Gets the gpio device path from gpio manager object
+void gpio_init(GDBusConnection *connection, GPIO* gpio)
+{
+ GDBusProxy *proxy;
+ GError *error;
+ GVariant *result;
+
+ error = NULL;
+ g_assert_no_error (error);
+ error = NULL;
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, /* GDBusInterfaceInfo */
+ "org.openbmc.managers.Gpios", /* name */
+ "/org/openbmc/managers/Gpios", /* object path */
+ "org.openbmc.managers.Gpios", /* interface */
+ NULL, /* GCancellable */
+ &error);
+ g_assert_no_error (error);
+
+ result = g_dbus_proxy_call_sync (proxy,
+ "init",
+ g_variant_new ("(s)", gpio->name),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
+ g_assert (result != NULL);
+ g_variant_get (result, "(&si&s)", &gpio->dev,&gpio->num,&gpio->direction);
+ g_print("GPIO Lookup: %s = %d,%s\n",gpio->name,gpio->num,gpio->direction);
+
+ //export and set direction
+ char dev[254];
+ char data[4];
+ sprintf(dev,"%s/export",gpio->dev);
+ int fd = open(dev, O_WRONLY);
+ sprintf(data,"%d",gpio->num);
+ write(fd,data,strlen(data));
+ close(fd);
+
+ sprintf(dev,"%s/gpio%d/direction",gpio->dev,gpio->num);
+ fd = open(dev,O_WRONLY);
+ write(fd,gpio->direction,strlen(gpio->direction));
+ close(fd);
+
+
+}
+int gpio_open(GPIO* gpio)
+{
+ // open gpio for writing or reading
+ char buf[254];
+ if (strcmp(gpio->direction,"in")==0)
+ {
+ sprintf(buf, "%s/gpio%d/value", gpio->dev, gpio->num);
+ gpio->fd = open(buf, O_RDONLY);
+ }
+ else
+ {
+ sprintf(buf, "%s/gpio%d/value", gpio->dev, gpio->num);
+ gpio->fd = open(buf, O_WRONLY);
+
+ }
+ if (gpio->fd == -1)
+ {
+ printf("error opening: %s\n",buf);
+ }
+ return gpio->fd;
+}
+
+void gpio_close(GPIO* gpio)
+{
+ close(gpio->fd);
+}
diff --git a/objects/openbmc_utilities.h b/objects/openbmc_utilities.h
new file mode 100644
index 0000000..1aa2032
--- /dev/null
+++ b/objects/openbmc_utilities.h
@@ -0,0 +1,23 @@
+
+#include <stdint.h>
+
+typedef struct {
+ gchar* name;
+ gchar* dev;
+ uint16_t num;
+ gchar* direction;
+ int fd;
+} GPIO;
+
+
+//gpio functions
+void gpio_init(GDBusConnection*, GPIO*);
+void gpio_close(GPIO*);
+int gpio_open(GPIO*);
+void gpio_write(GPIO*, uint8_t);
+void gpio_writec(GPIO*, char);
+void gpio_clock_cycle(GPIO*, int);
+uint8_t gpio_read(GPIO*);
+
+
+