示例#1
0
void thread_tty () {
    int x;
    assume (drv_registered_with_serial_fw);
    serial_install ();
    yield();
    //while (port_tty_installed != 0) {
        lock_tty ();
        if (nondet) {
            assume(port_tty_installed);
            notify(port_write_in_progress);
            //serial_write();
            x = port_initialized;
            x = dev_usb_serial_initialized;
            x = port_tty_state;
            lock_port ();
            x = port_consistent;
            port_consistent = 0;
            port_consistent = 1;
            unlock_port ();

            if (nondet) {
                assume_not(write_urb_submitted);
                notify(write_urb_submitted);
            } else {
                assume(write_urb_submitted);
            }
            // end serial_write
        } else {
            assume_not(port_tty_installed);
        }
        unlock_tty ();
    //}
    // TODO
}
示例#2
0
void serial_write_callback() {
  assert(port_initialized);
  lock_port();
  assert(port_consistent);
  port_consistent = 0;
  port_consistent = 1;
  unlock_port();
  assert(port_work_initialized);
  port_work = 1;
}
示例#3
0
void serial_write_callback () {
    int x;
    x = port_initialized;
    lock_port ();
    x = port_consistent;
    port_consistent = 0;
    port_consistent = 1;
    unlock_port ();
    x = port_work_initialized;
    notify(port_work);
}
示例#4
0
void serial_write() {
  assert(port_initialized);
  assert(dev_usb_serial_initialized);
  assert(port_tty_installed);
  lock_port();
  assert(port_consistent);
  port_consistent = 0;
  port_consistent = 1;
  unlock_port();
  if (write_urb_state != 0) {
  } else {
    write_urb_state = 1;
  }
}
示例#5
0
void serial_write () {
    int x;
    x = port_initialized;
    x = dev_usb_serial_initialized;
    x = port_tty_state;
    lock_port ();
    x = port_consistent;
    port_consistent = 0;
    port_consistent = 1;
    unlock_port ();

    if (nondet){ 
        assume(write_urb_submitted);
        return;
    } else {
        assume_not(write_urb_submitted);
        notify(write_urb_submitted);
    }
    // TODO model concurrent operations on the port
}
示例#6
0
void tty_thread() {
  assume(drv_registered_with_serial_fw);
  serial_install();
  lock_tty();
  if (port_tty_installed == 0) {
  } else {
    port_write_in_progress = 1;
    assert(port_initialized);
    assert(dev_usb_serial_initialized);
    assert(port_tty_installed);
    lock_port();
    assert(port_consistent);
    port_consistent = 0;
    port_consistent = 1;
    unlock_port();
    if (write_urb_state == 0) {
      write_urb_state = 1;
    }
  }
  unlock_tty();
}
示例#7
0
G_MODULE_EXPORT gboolean load_firmware (GtkButton *button)
{
	GtkWidget *widget = NULL;
	gchar *port;
	gchar *filename = NULL;
	gint port_fd = 0;
	gint file_fd = 0;
	FirmwareType type = MS1;

	widget = GTK_WIDGET(gtk_builder_get_object((GtkBuilder *)DATA_GET(global_data,"builder"), "port_entry"));
	port = (gchar *)gtk_entry_get_text(GTK_ENTRY(widget));
	widget = GTK_WIDGET(gtk_builder_get_object ((GtkBuilder *)DATA_GET(global_data,"builder"), "filechooser_button"));
	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget));

	if (g_utf8_strlen(port, -1) == 0)
		return FALSE;
	if (filename == NULL)
		return FALSE;

	/* If we got this far, all is good argument wise */
	if (!lock_port(port))
	{
		output((gchar *)"Could NOT LOCK Serial Port,\nYou should check for other programs using the serial port\n",FALSE);
		return FALSE;
	}
	port_fd = open_port(port);
	if (port_fd > 0)
		output((gchar *)"Port successfully opened\n",FALSE);
	else
	{
		output((gchar *)"Could NOT open Port, You should check perms\n",FALSE);
		unlock_port();
		return FALSE;
	}
#ifdef __WIN32__
	file_fd = open(filename, O_RDWR | O_BINARY );
#else
	file_fd = g_open(filename,O_RDONLY,S_IRUSR);
#endif
	if (file_fd > 0 )
		output((gchar *)"Firmware file successfully opened\n",FALSE);
	else
	{
		output((gchar *)"Could NOT open firmware file, check permissions/paths\n",FALSE);
		close_port(port_fd);
		unlock_port();
		return FALSE;
	}
	lock_buttons();
	if ((GINT)DATA_GET(global_data,"persona") == MS1)
	{
		setup_port(port_fd, 9600);
		do_ms1_load(port_fd,file_fd);
	}
	else if ((GINT)DATA_GET(global_data,"persona") == MS2)
	{
		setup_port(port_fd, 115200);
		do_ms2_load(port_fd,file_fd);
	}
	else if ((GINT)DATA_GET(global_data,"persona") == FREEEMS)
	{
		setup_port(port_fd, 115200);
		do_freeems_load(port_fd,file_fd);
	}
	unlock_buttons();
	close_port(port_fd);
	unlock_port();
	return TRUE;
}
示例#8
0
/*!
 \brief main() is the typical main function in a C program, it performs
 all core initialization, loading of all main parameters, initializing handlers
 and entering gtk_main to process events until program close
 \param argc (gint) count of command line arguments
 \param argv (char **) array of command line args
 \returns TRUE
 */
gint main(gint argc, gchar ** argv)
{
	gint port_fd = 0;
	gint file_fd = 0;
	
	verify_args(argc, argv);

	output(g_strdup_printf("MegaTunix msloader %s\n",VERSION),TRUE);

	/* If we got this far, all is good argument wise */
	if (!lock_port(argv[2]))
	{
		output("Could NOT LOCK Serial Port\nCheck for already running serial apps using the port\n",FALSE);
		exit(-1);
	}

	port_fd = open_port(argv[2]);
	if (port_fd > 0)
		output("Port successfully opened\n",FALSE);
	else
	{
		output("Could NOT open Port check permissions\n",FALSE);
		unlock_port();
		exit(-1);
	}
#ifdef __WIN32__
	file_fd = open(argv[3], O_RDWR | O_BINARY );
#else
	file_fd = g_open(argv[3],O_RDONLY,S_IRUSR);
#endif
	if (file_fd > 0 )
		output("Firmware file successfully opened\n",FALSE);
	else
	{
		output("Could NOT open firmware file, check permissions/paths\n",FALSE);
		close_port(port_fd);
		unlock_port();
		exit(-1);
	}
	if (type == MS1)
	{
		setup_port(port_fd, 9600);
		do_ms1_load(port_fd,file_fd);
	}
	else if (type == MS2)
	{
		setup_port(port_fd,115200);
		do_ms2_load(port_fd,file_fd);
	}

	else if (type == FREEEMS)
	{
		setup_port(port_fd,115200);
		do_freeems_load(port_fd,file_fd);
	}

	flush_serial(port_fd,BOTH);
	close_port(port_fd);
	unlock_port();
	return (0) ;
}