示例#1
0
文件: i2c.c 项目: smhuang426/Keil
void i2c()
{
	comm_init();
	init_24c02();
	while(temp!='#')
	{
		temp=_getkey();
		if(temp=='&')
		{
			while(temp!='$')
			{
				temp=_getkey();
				write_add(i++,temp);
			}
			i=0;
		}
		if(temp=='^')
		{
			while(read_add(t++)!='$')
			{
				printf("%c",read_add(t-1));
			}
			t=0;
		}
	}
}
示例#2
0
gs_id *gs_init( PetscInt *elms, PetscInt nel, PetscInt level)
{
   gs_id *gs;
  MPI_Group gs_group;
  MPI_Comm  gs_comm;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  /* ensure that communication package has been initialized */
  comm_init();


  /* determines if we have enough dynamic/semi-static memory */
  /* checks input, allocs and sets gd_id template            */
  gs = gsi_check_args(elms,nel,level);

  /* only bit mask version up and working for the moment    */
  /* LATER :: get int list version working for sparse pblms */
  ierr = gsi_via_bit_mask(gs);CHKERRABORT(PETSC_COMM_WORLD,ierr);


  ierr = MPI_Comm_group(MPI_COMM_WORLD,&gs_group);CHKERRABORT(PETSC_COMM_WORLD,ierr);
  ierr = MPI_Comm_create(MPI_COMM_WORLD,gs_group,&gs_comm);CHKERRABORT(PETSC_COMM_WORLD,ierr);
  gs->gs_comm=gs_comm;

  return(gs);
}
示例#3
0
文件: main.c 项目: seekr/thin
static void init() {
  setlocale(LC_ALL, "");
  comm_init();
  data_init();

  main_window_push();
}
示例#4
0
文件: init.c 项目: wcasper/fluid
int init() {
  int status = 0;

  // initialize MPI task numbers
  status = comm_init();
  error_check(&status, "error in comm_init\n");
  if(status) return status;

  // initialize grid
  status = grid_init();
  error_check(&status, "error in grid_init\n");
  if(status) return status;

  // initialize fourier
  status = fourier_init();
  error_check(&status, "error in fourier_init\n");
  if(status) return status;

  // initialize state
  status = state_init();
  error_check(&status, "error in state_init\n");
  if(status) return status;

  // initialize model
  status = model_init();
  error_check(&status, "error in model_init\n");
  if(status) return status;

  // initialize time step
  status = time_init();
  error_check(&status, "error in time_init\n");
  if(status) return status;

  return status;
}
示例#5
0
int main(int argc, char** argv)
{
  comm_init();
  char const* path;
  if (argc == 2)
    path = argv[1];
  else
    path = ".";
  struct mesh* m = new_box_mesh(2);
  mesh_derive_model(m, PI / 4);
  mesh_set_rep(m, MESH_FULL);
  mesh_eval_field(m, 0, "adapt_size", 1, size_fun);
  while (refine_by_size(m, 0));
  char prefix[128];
  sprintf(prefix, "%s/warp", path);
  start_vtk_steps(prefix);
  mesh_eval_field(m, 0, "dye", 1, dye_fun);
  set_size_field(m);
  write_vtk_step(m);
  mesh_adapt(m, size_floor, good_qual_floor, nsliver_layers, max_ops);
  for (unsigned i = 0; i < 2; ++i) {
    for (unsigned j = 0; j < 4; ++j) {
      mesh_eval_field(m, 0, "warp", 3, warp_fun);
      printf("new warp field\n");
      warped_adapt(m);
      mesh_free_tag(m, 0, "warp");
    }
    the_rotation = -the_rotation;
  }
  free_mesh(m);
  comm_fini();
}
示例#6
0
void COMM_UDP_init() {
#ifdef CONFIG_ETHSPI
  DBG(D_COMM, D_DEBUG, "COMM UDP init\n");
  memset(&ecomm, 0, sizeof(comm));

  ecomm.tx_ix = UDP_DATA_P;

  OS_thread_create(&ecomm.thread, OS_THREAD_FLAG_PRIVILEGED,
      COMM_UDP_thread_func, NULL, comm_udp_thr_stack,
      sizeof(comm_udp_thr_stack) - 4, "comm_udp");

  // comm stack setup
  comm_init(&ecomm.driver,        // comm stack struct
      0,                    // conf
      1,                    // this address
      0,                    // comm_phy_rx_char - called from eth callback
      COMM_UDP_tx_char,         // comm_phy_tx_char
      COMM_UDP_tx_buf,          // comm_phy_tx_buf
      COMM_UDP_tx_flush,        // comm_phy_tx_flush
      COMM_cb_get_tick_count,  // comm_app_get_time
      COMM_cb_rx_pkt,          // comm_app_user_rx
      COMM_cb_ack_pkt,         // comm_app_user_ack
      COMM_cb_err,             // comm_app_user_err
      COMM_cb_tra_inf,         // comm_app_user_inf
      COMM_cb_alert            // comm_app_alert
      );
  // using comm stacks allocation callback for pkt buffers
  comm_init_alloc(&ecomm.driver, COMM_UDP_alloc, COMM_UDP_free);

  // stack now active
#endif
}
示例#7
0
xsock_t
comm_connect_udp4(const struct in_addr *remote_addr,
		  unsigned short remote_port, int is_blocking,
		  int *in_progress)
{
    xsock_t sock;

    if (in_progress != NULL)
	*in_progress = 0;

    comm_init();
    sock = comm_sock_open(AF_INET, SOCK_DGRAM, 0, is_blocking);
    if (sock == XORP_BAD_SOCKET)
	return (XORP_BAD_SOCKET);
    if (comm_sock_connect4(sock, remote_addr, remote_port, is_blocking,
			   in_progress)
	!= XORP_OK) {
	/*
	 * If this is a non-blocking socket and the connect couldn't
	 * complete, then return the socket.
	 */
	if ((! is_blocking) && (in_progress != NULL) && (*in_progress == 1))
	    return (sock);

	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }

    return (sock);
}
示例#8
0
xsock_t
comm_bind_tcp6(const struct in6_addr *my_addr, unsigned int my_ifindex,
	       unsigned short my_port, int is_blocking)
{
#ifdef HAVE_IPV6
    xsock_t sock;

    comm_init();
    sock = comm_sock_open(AF_INET6, SOCK_STREAM, 0, is_blocking);
    if (sock == XORP_BAD_SOCKET)
	return (XORP_BAD_SOCKET);
    if (comm_set_reuseaddr(sock, 1) != XORP_OK) {
	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }
    if (comm_sock_bind6(sock, my_addr, my_ifindex, my_port) != XORP_OK) {
	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }

    return (sock);

#else /* ! HAVE_IPV6 */
    comm_sock_no_ipv6("comm_bind_tcp6", my_addr, my_ifindex, my_port,
		      is_blocking);
    return (XORP_BAD_SOCKET);
#endif /* ! HAVE_IPV6 */
}
示例#9
0
xsock_t
comm_bind_udp4(const struct in_addr *my_addr, unsigned short my_port,
	       int is_blocking, int reuse_flag)
{
    xsock_t sock;

    comm_init();
    sock = comm_sock_open(AF_INET, SOCK_DGRAM, 0, is_blocking);
    if (sock == XORP_BAD_SOCKET)
	return (XORP_BAD_SOCKET);

    /* For multicast, you need to set reuse before you bind, if you want
     * more than one socket to be able to bind to a particular IP (like, 0.0.0.0)
     */
    if (reuse_flag) {
	if (comm_set_reuseaddr(sock, 1) != XORP_OK) {
	    comm_sock_close(sock);
	    return (XORP_BAD_SOCKET);
	}
	if (comm_set_reuseport(sock, 1) != XORP_OK) {
	    comm_sock_close(sock);
	    return (XORP_BAD_SOCKET);
	}
    }
    
    if (comm_sock_bind4(sock, my_addr, my_port) != XORP_OK) {
	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }

    return (sock);
}
示例#10
0
int main(int narg, char *arg[])
{
    comm_ext world;
    struct comm comm;

#ifdef MPI
    MPI_Init(&narg,&arg);
    world = MPI_COMM_WORLD;
#else
    world=0;
#endif

    comm_init(&comm,world);
    id=comm.id, np=comm.np;

    lobatto_nodes(zr,NR),lobatto_nodes(zs,NS),lobatto_nodes(zt,NT);
    array_init(struct pt_data,&testp,NEL*MULD(TN,TN,TN));
    crystal_init(&cr,&comm);
    test(&comm);
    crystal_free(&cr);
    array_free(&testp);

    comm_free(&comm);

#ifdef MPI
    MPI_Finalize();
#endif

    return 0;
}
示例#11
0
void thread_map__read_comms(struct thread_map *threads)
{
	int i;

	for (i = 0; i < threads->nr; ++i)
		comm_init(threads, i);
}
示例#12
0
void initCommsQuda(int argc, char **argv, const int *X, const int nDim) {

  if (nDim != 4) errorQuda("Comms dimensions %d != 4", nDim);

#ifdef MULTI_GPU

#ifdef QMP_COMMS
  QMP_thread_level_t tl;
  QMP_init_msg_passing(&argc, &argv, QMP_THREAD_SINGLE, &tl);

  QMP_declare_logical_topology(X, nDim);
#elif defined(MPI_COMMS)
  MPI_Init (&argc, &argv);  

  int volume = 1;
  for (int d=0; d<nDim; d++) volume *= X[d];
  int size = -1;
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  if (volume != size)
    errorQuda("Number of processes %d must match requested MPI volume %d",
	      size, volume);

  comm_set_gridsize(X[0], X[1], X[2], X[3]);  
  comm_init();
#endif

#endif
}
示例#13
0
int main(int argc, char *argv[])
{
	log_init(NAME);

	if (options_parse(&argc, argv) != 0) {
		exit(1);
	}

	sys_init();

	if (comm_init()) {
		exit(2);
	}

	log_str("Test mode: %d", opt_mode);

	if (opt_mode) {
		comm_sink_register("A", (comm_sink_func_t) sink_event, NULL);
		comm_source_register("B", 0);
	}
	else {
		comm_sink_register("B", (comm_sink_func_t) sink_event, NULL);
		comm_source_register("A", 0);
	}

	sys_run();

	return 0;
}
示例#14
0
xsock_t
comm_connect_unix(const char* path, int is_blocking)
{
    xsock_t		sock;
    struct sockaddr_un 	s_un;

    comm_init();

    if (comm_unix_setup(&s_un, path) == -1)
	return (XORP_BAD_SOCKET);

    sock = comm_sock_open(s_un.sun_family, SOCK_STREAM, 0, is_blocking);
    if (sock == XORP_BAD_SOCKET)
	return (XORP_BAD_SOCKET);

    if (connect(sock, (struct sockaddr*) &s_un, sizeof(s_un)) == -1) {
	_comm_set_serrno();
	if (is_blocking || comm_get_last_error() != EINPROGRESS) {
	    XLOG_ERROR("Error connecting to unix socket.  Path: %s.  Error: %s",
	       s_un.sun_path, comm_get_error_str(comm_get_last_error()));

	    comm_sock_close(sock);

	    return (XORP_BAD_SOCKET);
	}
    }

    return (sock);
}
void on_set_button_clicked(GtkObject *object, gpointer wn)
{
	g_print("Set Button Clicked\n");

	int32_t error_code = ERR_NONE;

	if (0 > comm_init(com_port_name))
		error_code = ERR_PORT_INIT;

	if (ERR_NONE == error_code)
		error_code = send_password("WIFIBOT123");

	if (ERR_NONE == error_code)
	{
		int32_t motor_levels[NUMBER_OF_MOTOR_CHANNELS];
		motor_levels[MOTOR_SPEED_CHANNEL] = get_motor_value_from_control(
				wm->left_motor_slide);
		motor_levels[MOTOR_DIRECTION_CHANNEL] = get_motor_value_from_control(
				wm->right_motor_slide);
		error_code = write_motor_levels(motor_levels[MOTOR_SPEED_CHANNEL],
				motor_levels[MOTOR_DIRECTION_CHANNEL]);
	}

	if (ERR_NONE == error_code)
	{
		error_code = set_ir_led(get_ir_led_from_control(wm->ir_led_control));
	}

	if (ERR_NONE == error_code)
	{
		error_code = set_motor_timeout(get_motor_timeout_from_control(
				wm->motor_timeout_control));
	}

	if (ERR_NONE == error_code)
	{
		StatusLedFlashState_t flash_state;
		int32_t flash_rate;

		get_led_state_from_control(wm->status_led_control, &flash_state,
				&flash_rate);
		write_status_led(flash_state, flash_rate);
	}

	if (ERR_NONE == error_code)
	{
		int32_t i;
		for (i = 0; i < LCD_TEXT_LINES; i++)
		{
			gchar * lcd_line_text = get_lcd_text_from_control(wm->lcd_text, i);
			set_lcd(i, lcd_line_text);
		}

	}

	comm_close();

	error_handler(wm->window, error_code);
}
示例#16
0
文件: main.c 项目: kddlb/thin
int main() {
  comm_init();
  config_init();

  main_window_push();
  
  app_event_loop();
}
示例#17
0
void initAll ()
{
	comm_init();

	//RNG Peripheral enable
	RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
	RNG_Cmd(ENABLE);
}
示例#18
0
文件: main.c 项目: smhuang426/Keil
void main()
{
	comm_init();
	while(1)
	{
		readtemphumi();
		delay(2000);
	}
}
示例#19
0
文件: main.c 项目: eduardochiaro/thin
int main() {
  setlocale(LC_ALL, "");
  comm_init();
  config_init();

  main_window_push();
  
  app_event_loop();
}
示例#20
0
文件: hakit.c 项目: hakit-dev/hakit
int main(int argc, char *argv[])
{
	char *app;
	int use_ssl = 1;  // 0 = disable SSL, 2 = allow insecure SSL

	if (options_parse(&argc, argv) != 0) {
		exit(1);
	}

	if (opt_daemon) {
		run_as_daemon();
	}

	/* Init exec environment */
	env_init(argc, argv);

	/* Init log management */
	log_init("hakit");
	log_str(options_summary);
	log_str("Using libwebsockets version " LWS_LIBRARY_VERSION " build " LWS_BUILD_HASH);

	/* Init system runtime */
	sys_init();

	/* Init communication engine */
	if (opt_no_ssl) {
		use_ssl = 0;
	}
	else if (opt_insecure_ssl) {
		use_ssl = 2;
	}
	if (comm_init(use_ssl, opt_no_hkcp ? 0:1, opt_hosts)) {
		return 2;
	}

	if (opt_monitor) {
		comm_monitor((comm_sink_func_t) monitor_sink_event, NULL);
	}

	/* Init module management */
	if (hk_mod_init(opt_class_path)) {
		return 2;
	}

	app = env_app();
	if (app != NULL) {
		if (hk_mod_load(app)) {
			return 3;
		}
		hk_obj_start_all();
	}

	sys_run();

	return 0;
}
void update_port_names(GtkComboBox *combobox)
{
#if !_PCSIM
	gdk_threads_enter();
	int32_t fd;
	char port_name[32] = "";

	bool comm_trace = get_comm_trace();
	set_comm_trace(false); // mask printing errors opening port

	gtk_list_store_clear(wm->com_port_list);

	int32_t i = 0;
	// look for com ports
	for (i = 0; i < 10; i++)
	{
		sprintf(port_name, "/dev/ttyS%d", i);
		fd = comm_init(port_name);
		comm_close();
		if (0 < fd)
		gtk_combo_box_append_text(combobox, port_name);
	}

	// look for usb com ports
	for (i = 0; i < 10; i++)
	{
		sprintf(port_name, "/dev/ttyUSB%d", i);
		fd = comm_init(port_name);
		comm_close();
		if (0 < fd)
		gtk_combo_box_append_text(combobox, port_name);
	}

	/// TODO this currently resets com port name. Eventually this should retain value
	gtk_combo_box_set_active(combobox, 0);
	com_port_name = gtk_combo_box_get_active_text(combobox);
	set_comm_trace(comm_trace); // restore comm trace
	gdk_threads_leave();
#else

#endif

}
示例#22
0
static inline void autopilot_main_init( void ) {
  hw_init();
  sys_time_init();
  led_init();

  supervision_init();
  actuators_init(ACTUATOR_BANK_MOTORS);

#if BOMB_ENABLED
  bomb_init_servo(RADIO_FMS, 0, 0);
#endif

  rc_init();

#if HARDWARE_ENABLED_GPS
  gps_init();
#else
  comm_init(COMM_0);
  comm_add_tx_callback(COMM_0, comm_autopilot_message_send);
  comm_add_rx_callback(COMM_0, comm_autopilot_message_received);
#endif

  comm_init(COMM_TELEMETRY);
  comm_add_tx_callback(COMM_TELEMETRY, comm_autopilot_message_send);
  comm_add_rx_callback(COMM_TELEMETRY, comm_autopilot_message_received);

  analog_init();
  analog_enable_channel(ANALOG_CHANNEL_BATTERY);
  analog_enable_channel(ANALOG_CHANNEL_PRESSURE);

  altimeter_init();

  imu_init();

  autopilot_init();

  ahrs_init();
  ins_init();

  fms_init();

  int_enable();
}
示例#23
0
static inline void main_init( void ) {
    hw_init();
    sys_time_init();
    led_init();

    comm_init(DA_COMM);
    comm_add_tx_callback(DA_COMM, test_message_tx);
    comm_add_rx_callback(DA_COMM, test_message_rx);

    int_enable();
}
示例#24
0
static void init() {

    int initialized = protocol_init() && caps_init() && signal_init() && comm_init() && injectable_init();
    
    if (!initialized) {
        fatal("Initialization failed.");
        cleanup();
        exit(EXIT_FAILURE);
    }
    
}
示例#25
0
static void init(void) {
    options_init();
    comm_init();
    tl_init();
    ts_init();
    ti_init();
    sb_init();

    tl_show();
    // others...
}
示例#26
0
static inline void main_init( void ) {
    hw_init();
    sys_time_init();
    led_init();

    comm_init(COMM_TELEMETRY);

    rc_init();

    int_enable();
}
示例#27
0
文件: main.c 项目: tasos85/summer
int main(void)
{
	/* Start led connected to P1.29 and P1.18 */
	LPC_GPIO1->FIODIR |= 0x20040000;
	LPC_GPIO1->FIOSET |= (1 << 29);
	LPC_GPIO1->FIOCLR |= (1 << 18);

	SystemInit(); // lpc1768_startup.c
	SystemCoreClockUpdate();
	GPIOInit();
	TimerInit();
	ValueInit();
	ADCInit();

	comm_init();
//	welcomeMsg();
	set_echo();
	easyWEB_init();
	printchar("at+ndhcp=1\r");
	printchar("at+wa=greenet\r");
	printchar("at+nstcp=20\r");
	printchar("                              \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");

	while(1)
	{
		easyWEB_s_loop();
		//handle_command();	//UART command
		if(UpdateChannel >= 3)
		{
			UpdateChannel = -1;
			ADCRead(0);
			if (mode ==1)  //decide which ADC channel to read when the converter is working in different direction
			{
				Vout = ADCValues(0);
				Vin = ADCValues(1);
			}
			else
			{
				Vout = ADCValues(1);
				Vin = ADCValues(0);
			}
			Iref = ADCValues(2);
			Il = abs (ADCValues(3) - Iref); //get the correct inductor current
			MeanValues();
			BangBang();
			LPC_GPIO1->FIOPIN ^= (1 << 29);
			LPC_GPIO1->FIOPIN ^= (1 << 18);
		}

	}

	return 0;
}
示例#28
0
xsock_t
comm_open_udp(int family, int is_blocking)
{
    xsock_t sock;

    comm_init();
    sock = comm_sock_open(family, SOCK_DGRAM, 0, is_blocking);
    if (sock == XORP_BAD_SOCKET)
	return (XORP_BAD_SOCKET);

    return (sock);
}
示例#29
0
xsock_t
comm_bind_connect_tcp6(const struct in6_addr *local_addr,
		       unsigned int my_ifindex,
		       unsigned short local_port,
		       const struct in6_addr *remote_addr,
		       unsigned short remote_port,
		       int is_blocking,
		       int *in_progress)
{
#ifdef HAVE_IPV6
    xsock_t sock;

    if (in_progress != NULL)
	*in_progress = 0;

    comm_init();
    sock = comm_sock_open(AF_INET6, SOCK_STREAM, 0, is_blocking);
    if (sock == XORP_BAD_SOCKET)
	return (XORP_BAD_SOCKET);
    if (comm_set_reuseaddr(sock, 1) != XORP_OK) {
	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }
    if (comm_sock_bind6(sock, local_addr, my_ifindex, local_port) != XORP_OK) {
	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }
    if (comm_sock_connect6(sock, remote_addr, remote_port, is_blocking,
			   in_progress)
	!= XORP_OK) {
	/*
	 * If this is a non-blocking socket and the connect couldn't
	 * complete, then return the socket.
	 */
	if ((! is_blocking) && (in_progress != NULL) && (*in_progress == 1))
	    return (sock);

	comm_sock_close(sock);
	return (XORP_BAD_SOCKET);
    }

    return (sock);

#else /* ! HAVE_IPV6 */
    if (in_progress != NULL)
	*in_progress = 0;

    comm_sock_no_ipv6("comm_bind_connect_tcp6", local_addr, my_ifindex,
		      local_port, remote_addr, remote_port, is_blocking,
		      in_progress);
    return (XORP_BAD_SOCKET);
#endif /* ! HAVE_IPV6 */
}
示例#30
0
static inline void main_init( void ) {
    hw_init();
    sys_time_init();
    led_init();

#if USE_DA_UART0
    /* Uart 0 (aka gps) */
    comm_init(COMM_0);
#endif

#if USE_DA_UART1
    /* Uart 1 (aka telemetry) */
    comm_init(COMM_1);
#endif

#if USE_DA_USB
    /* USB */
    comm_init(COMM_USB);
#endif

    int_enable();
}