Exemplo n.º 1
0
static void
on_connect_stream (GObject *object,
                   GAsyncResult *result,
                   gpointer user_data)
{
  CockpitStream *self = COCKPIT_STREAM (user_data);
  GError *error = NULL;
  GIOStream *io;

  io = cockpit_connect_stream_finish (result, &error);
  if (error)
    {
      set_problem_from_error (self, "couldn't connect", error);
      close_immediately (self, NULL);
      g_error_free (error);
    }
  else if (!self->priv->closed)
    {
      self->priv->io = g_object_ref (io);
      initialize_io (self);
    }

  g_clear_object (&io);
  g_object_unref (self);
}
Exemplo n.º 2
0
static void
cockpit_stream_constructed (GObject *object)
{
  CockpitStream *self = COCKPIT_STREAM (object);

  G_OBJECT_CLASS (cockpit_stream_parent_class)->constructed (object);

  if (self->priv->io)
    initialize_io (self);
}
Exemplo n.º 3
0
 IOFSTest() {
   // You can do set-up work for each test here.
   initialize_memory();
   initialize_io();
 }
Exemplo n.º 4
0
static void
on_socket_connect (GObject *object,
                   GAsyncResult *result,
                   gpointer user_data)
{
  CockpitStream *self = user_data;
  GError *error = NULL;

  g_socket_connection_connect_finish (G_SOCKET_CONNECTION (object), result, &error);

  if (!error && !self->priv->closed)
    {
      g_debug ("%s: connected", self->priv->name);

      if (self->priv->options && self->priv->options->tls_client)
        {
          self->priv->io = g_tls_client_connection_new (G_IO_STREAM (object), NULL, &error);
          if (self->priv->io)
            {
              g_debug ("%s: tls handshake", self->priv->name);

              g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (self->priv->io),
                                                            self->priv->options->tls_client_flags);

              if (self->priv->options->tls_cert)
                {
                  g_tls_connection_set_certificate (G_TLS_CONNECTION (self->priv->io),
                                                    self->priv->options->tls_cert);
                }
              if (self->priv->options->tls_database)
                {
                  g_tls_connection_set_database (G_TLS_CONNECTION (self->priv->io),
                                                 self->priv->options->tls_database);
                }

              /* We track data end the same way we do for HTTP */
              g_tls_connection_set_require_close_notify (G_TLS_CONNECTION (self->priv->io), FALSE);
            }
        }
      else
        {
          self->priv->io = g_object_ref (object);
        }
    }

  if (error)
    {
      g_debug ("%s: couldn't connect: %s", self->priv->name, error->message);
      g_clear_error (&self->priv->connect_error);
      self->priv->connect_error = error;

      g_socket_address_enumerator_next_async (self->priv->connecting, NULL,
                                              on_address_next, g_object_ref (self));
    }
  else
    {
      initialize_io (self);
    }

  g_object_unref (object);
  g_object_unref (self);
}
Exemplo n.º 5
0
void
sgi_master_io_infr_init(void)
{
	int cnode;
	extern int maxnodes;

	/*
	 * Do any early init stuff .. einit_tbl[] etc.
	 */
	DBG("--> sgi_master_io_infr_init: calling init_hcl().\n");
	init_hcl(); /* Sets up the hwgraph compatibility layer with devfs */

	/*
	 * initialize the Linux PCI to xwidget vertexes ..
	 */
	DBG("--> sgi_master_io_infr_init: calling pci_bus_cvlink_init().\n");
	pci_bus_cvlink_init();

	/*
	 * Hack to provide statically initialzed klgraph entries.
	 */
	DBG("--> sgi_master_io_infr_init: calling klgraph_hack_init()\n");
	klgraph_hack_init();

	/*
	 * This is the Master CPU.  Emulate mlsetup and main.c in Irix.
	 */
	DBG("--> sgi_master_io_infr_init: calling mlreset(0).\n");
	mlreset(0); /* Master .. */

	/*
	 * allowboot() is called by kern/os/main.c in main()
	 * Emulate allowboot() ...
	 *   per_cpu_init() - only need per_hub_init()
	 *   cpu_io_setup() - Nothing to do.
	 * 
	 */
	DBG("--> sgi_master_io_infr_init: calling sn_mp_setup().\n");
	sn_mp_setup();

	DBG("--> sgi_master_io_infr_init: calling per_hub_init(0).\n");
	for (cnode = 0; cnode < maxnodes; cnode++) {
		per_hub_init(cnode);
	}

	/* We can do headless hub cnodes here .. */

	/*
	 * io_init[] stuff.
	 *
	 * Get SGI IO Infrastructure drivers to init and register with 
	 * each other etc.
	 */

	DBG("--> sgi_master_io_infr_init: calling hubspc_init()\n");
	hubspc_init();

	DBG("--> sgi_master_io_infr_init: calling pciba_init()\n");
	pciba_init();

	DBG("--> sgi_master_io_infr_init: calling pciio_init()\n");
	pciio_init();

	DBG("--> sgi_master_io_infr_init: calling pcibr_init()\n");
	pcibr_init();

	DBG("--> sgi_master_io_infr_init: calling xtalk_init()\n");
	xtalk_init();

	DBG("--> sgi_master_io_infr_init: calling xbow_init()\n");
	xbow_init();

	DBG("--> sgi_master_io_infr_init: calling xbmon_init()\n");
	xbmon_init();

	DBG("--> sgi_master_io_infr_init: calling pciiox_init()\n");
	pciiox_init();

	DBG("--> sgi_master_io_infr_init: calling usrpci_init()\n");
	usrpci_init();

	DBG("--> sgi_master_io_infr_init: calling ioc3_init()\n");
	ioc3_init();

	/*
	 *
	 * Our IO Infrastructure drivers are in place .. 
	 * Initialize the whole IO Infrastructure .. xwidget/device probes.
	 *
	 */
	DBG("--> sgi_master_io_infr_init: Start Probe and IO Initialization\n");
	initialize_io();

	DBG("--> sgi_master_io_infr_init: Setting up SGI IO Links for Linux PCI\n");
	pci_bus_to_hcl_cvlink();

	DBG("--> Leave sgi_master_io_infr_init: DONE setting up SGI Links for PCI\n");
}
Exemplo n.º 6
0
int main()
{
	initialize_io();
	initialize_spi();

	const int MAGIC_SPI_TRANSMIT_DELAY = 12; // actually seems to be 10 but let's be safe here
	const int MAGIC_MUX_SWITCH_DELAY = 100; // way to large but let's be generous
	
	int RGB_counter = 0;
	int LED_counter = 0;
	int LED_R = 0x01;
	int LED_G = 0x01;
	int LED_B = 0x01;
	const int CYCLE_SIZE = 16;

	bool isReadySPI = false;
	bool isCommResetting = false;
	bool isCommTransmitting = false;

	// Data variables. (NOTE: Not sure if these should be "volatile".)
	uint8_t t_isPressedDebugA	= 0x00;	// 1 bit (1 = true)
	uint8_t t_isPressedDebugB	= 0x00;	// 1 bit (1 = true)
	uint8_t t_XY_low			= 0x00;	// 8 bits
	uint8_t t_XY_high			= 0x00;	// 7 bits
	uint8_t t_Z_low				= 0x00;	// 8 bits
	uint8_t t_Z_high			= 0x00;	// 1 bit
	uint8_t t_bump_map			= 0x00;	// 8 bits
	uint8_t t_overheat_alert	= 0x00; // 1 bit
	uint8_t t_overheat_map		= 0x00; // 8 bits
	uint8_t t_IR_alert			= 0x00; // 1 bit

	// Doesn't work on an ATmega8.
	//// Delay the clock frequency change to ensure re-programmability.
	//// The argument for the delay may be completely off because at this
	//// point in the program the specified `F_CPU` does not match the
	//// actual clock's frequency.
	//ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
	//	// Delay!
		_delay_ms(100);
	//
	//	//CLKPR = 1 << CLKPCE; // "only updated when [... the other bits are] written to zero"
	//	//CLKPR &= ~(1<<CLKPS0);
	//	//CLKPR &= ~(1<<CLKPS1);
	//	//CLKPR &= ~(1<<CLKPS2);
	//	//CLKPR &= ~(1<<CLKPS3);
	//	//// ^ (0b0000) Corresponds to a division factor of 1.
	//
	//	// Someone else's way of doing it.
	//	CLKPR = 0x80;
	//	CLKPR = 0x00;
	//}

	// Check if other MCUs are ready to go.
	// TODO: Periodically check for connectivity later.
	resync_spi();
	isReadySPI = true;
	
	// NOTE: FOR SOME REASON THIS LINE BREAKS THINGS :(
	sei(); // ready to go.

	while (true) {
		++RGB_counter;
		RGB_counter %= 3;
		if (RGB_counter == 0) {
			++LED_counter;
			LED_counter %= CYCLE_SIZE;
		}

		auto req_data = [](uint8_t SPI_code) -> uint8_t
		{
			_delay_us(MAGIC_SPI_TRANSMIT_DELAY);
			SPDR = SPI_code;
			while ( !(SPSR & (1<<SPIF)) ) { ; } // wait for reception to complete
			uint8_t byte_read = SPDR;
			return byte_read;
		};

		// ask for stuff, update registers
		set_SPI_mux(MUX_1);
		_delay_us(MAGIC_MUX_SWITCH_DELAY);

		uint8_t check_link = req_data(SPI_REQ_DEBUG_A);
		if (check_link != SPI_ACK_READY) {
			resync_spi();
		}
		t_isPressedDebugA = req_data(SPI_REQ_DEBUG_B);
		t_isPressedDebugB = req_data(SPI_REQ_Z_LOW);
		t_Z_low = req_data(SPI_REQ_Z_HIGH);
		t_Z_high = req_data(SPI_REQ_XY_LOW);
		t_XY_low = req_data(SPI_REQ_XY_HIGH);
		t_XY_high = req_data(SPI_REQ_BUMP_MAP);
		t_bump_map = req_data(SPI_REQ_OVERHEAT_ALERT);
		t_overheat_alert = req_data(SPI_REQ_OVERHEAT_MAP);
		t_overheat_map = req_data(SPI_REQ_IR_ALERT);
		t_IR_alert = req_data(SPI_TRANSMIT_OVER);
		
		set_SPI_mux(MUX_2);
		_delay_us(MAGIC_MUX_SWITCH_DELAY);

		// NOTE: get rid of this
		_delay_us(100); // pretend we do other stuff here

		if (t_isPressedDebugA == 0x00) {
			LED_G = 0x01;
		} else {
			LED_G = 0x00;
		}
		if (t_isPressedDebugB == 0x00) {
			LED_B = 0x01;
		} else {
			LED_B = 0x00;
		}

		// LED stuffs
		PORTC |= 0b111<<PC0;
		switch (RGB_counter) {
			case 0 :
				if (LED_counter < LED_R) {
					PORTC &= ~(1<<PC0);
				}
				break;
			case 1 :
				if (LED_counter < LED_G) {
					PORTC &= ~(1<<PC1);
				}
				break;
			case 2 :
				if (LED_counter < LED_B) {
					PORTC &= ~(1<<PC2);
				}
				break;
		}

		if (isReadySPI) {
			PORTC |= 1<<PC3; // always true for now
		} else {
			PORTC &= ~(1<<PC3); // R
		}
		//if (isCommResetting) {
		//	PORTC |= 1<<PC4;
		//} else {
		//	PORTC &= ~(1<<PC4); // Y
		//}
		//if (isCommTransmitting) {
		//	PORTC |= 1<<PC5;
		//} else {
		//	PORTC &= ~(1<<PC5); // G
		//}

		//// NOTE: Enable this delay if there aren't other delay sources.
		//_delay_us(10);
	}
}