int main(int argc, char** argv){ /* 主线程主体流程: conn_init; thread_init; 还得有一个 stat_init stats的结构是用来记录当前的状态的,stats是一个静态变量 server_socket 请求,分发 注册事件loop */ int retval; main_base = event_init(); FILE *portnumber_file = NULL; portnumber_file = fopen("/tmp/portnumber.file", "a"); stats_init(); conn_init(); thread_init(NUM_OF_THREADS); server_socket("127.0.0.1", SERVER_PORT, tcp_transport, portnumber_file); if (event_base_loop(main_base, 0) != 0) { printf("event_base_loop error"); retval = EXIT_FAILURE; } return retval; exit(0); }
void app_startup(void) { msg_init(FALSE); iv_set_fatal_msg_handler(app_fatal); iv_init(); g_thread_init(NULL); crypto_init(); hostname_global_init(); dns_caching_global_init(); dns_caching_thread_init(); afinter_global_init(); child_manager_init(); alarm_init(); stats_init(); tzset(); log_msg_global_init(); log_tags_global_init(); log_source_global_init(); log_template_global_init(); value_pairs_global_init(); service_management_init(); scratch_buffers_allocator_init(); main_loop_thread_resource_init(); nondumpable_setlogger(nondumpable_allocator_logger); secret_storage_init(); transport_factory_id_global_init(); }
/** * main * * The main task for the project. This function initializes the packages, calls * init_tasks to initialize additional tasks (and possibly other objects), * then starts serving events from default event queue. * * @return int NOTE: this function should never return! */ int main(int argc, char **argv) { int rc; #ifdef ARCH_sim mcu_sim_parse_args(argc, argv); #endif sysinit(); cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF); log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL); stats_init(STATS_HDR(g_stats_gpio_toggle), STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32), STATS_NAME_INIT_PARMS(gpio_stats)); stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle)); conf_load(); reboot_start(hal_reset_cause()); init_tasks(); while (1) { os_eventq_run(os_eventq_dflt_get()); } /* Never exit */ return rc; }
void test_stats() { GString *reply = NULL; GString *command = g_string_sized_new(128); StatsCounterItem *counter = NULL; gchar **stats_result; stats_init(); stats_lock(); stats_register_counter(0, SCS_CENTER, "id", "received", SC_TYPE_PROCESSED, &counter); stats_unlock(); g_string_assign(command,"STATS"); reply = control_connection_send_stats(command); stats_result = g_strsplit(reply->str, "\n", 2); assert_string(stats_result[0], "SourceName;SourceId;SourceInstance;State;Type;Number", "Bad reply"); g_strfreev(stats_result); g_string_free(reply, TRUE); g_string_free(command, TRUE); stats_destroy(); return; }
/** * main * * The main function for the project. This function initializes the os, calls * init_tasks to initialize tasks (and possibly other objects), then starts the * OS. We should not return from os start. * * @return int NOTE: this function should never return! */ int main(int argc, char **argv) { int rc; #ifdef ARCH_sim mcu_sim_parse_args(argc, argv); #endif sysinit(); cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF); log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL); stats_init(STATS_HDR(g_stats_gpio_toggle), STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32), STATS_NAME_INIT_PARMS(gpio_stats)); stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle)); conf_load(); log_reboot(HARD_REBOOT); init_tasks(); os_start(); /* os start should never return. If it does, this should be an error */ assert(0); return rc; }
/* Try to execute action with the drop action, which should succeed */ static void test_action_execute_drop(int argc, char *argv[]) { struct rte_mbuf buf_free; struct rte_mbuf buf_drop; struct action action_multiple[MAX_ACTIONS] = {0}; struct action action_drop[MAX_ACTIONS] = {0}; stats_init(); stats_vswitch_clear(); /* TODO: Break this into multiple tests? */ /* check that mbuf is freed on drop */ assert(memcmp(&buf_free, &buf_drop, sizeof(buf_drop)) != 0); buf_drop.pkt.next = NULL; /* Required for rte_pktmbuf_free */ memcpy(&buf_free, &buf_drop, sizeof(buf_drop)); assert(memcmp(&buf_free, &buf_drop, sizeof(buf_drop)) == 0); action_drop_build(&action_drop[0]); action_null_build(&action_drop[1]); action_execute(action_drop, &buf_free); assert(memcmp(&buf_free, &buf_drop, sizeof(buf_drop)) != 0); /* check that vswitch rx drop stats are increased */ stats_vswitch_clear(); assert(stats_vswitch_rx_drop_get() == 0); action_drop_build(&action_drop[0]); action_null_build(&action_drop[1]); action_execute(action_drop, &buf_drop); assert(stats_vswitch_rx_drop_get() == 1); }
void race_set(struct race_t* pRace, const char* name, unsigned str, unsigned dex, unsigned con, unsigned intel, unsigned wis) { pRace->name[0] = '\0'; strcat(pRace->name, name); stats_init(&pRace->stats, str, dex, con, intel, wis); }
int main(int argc, char **argv) { char *config_xml; if (argc != 2) { printf("Usage: %s config.xml \n", argv[0]); return (EXIT_SUCCESS); } // GET Ctrl+C signal; signal(SIGINT, exit_proc); /** Read configure file */ config_xml = argv[1]; parse_doc(config_xml); /** Initialize NFQUEUE forwarding process, logging files e.t.c */ if(!nfqp_init() || !glb_init() || !stats_init() /* MYSQL , */){ exit_proc(); } nfqp_analyzer_function(); return(EXIT_SUCCESS); }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this color sensor * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int tcs34725_init(struct os_dev *dev, void *arg) { struct tcs34725 *tcs34725; struct sensor *sensor; int rc; if (!arg || !dev) { rc = SYS_ENODEV; goto err; } tcs34725 = (struct tcs34725 *) dev; tcs34725->cfg.mask = SENSOR_TYPE_ALL; sensor = &tcs34725->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_tcs34725stats), STATS_SIZE_INIT_PARMS(g_tcs34725stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(tcs34725_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register("tcs34725", STATS_HDR(g_tcs34725stats)); SYSINIT_PANIC_ASSERT(rc == 0); rc = sensor_init(sensor, dev); if (rc != 0) { goto err; } /* Add the color sensor driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_COLOR, (struct sensor_driver *) &g_tcs34725_sensor_driver); if (rc != 0) { goto err; } /* Set the interface */ rc = sensor_set_interface(sensor, arg); if (rc) { goto err; } rc = sensor_mgr_register(sensor); if (rc != 0) { goto err; } rc = sensor_set_type_mask(sensor, tcs34725->cfg.mask); if (rc) { goto err; } return (0); err: return (rc); }
// initialisation void DataFlash_MAVLink::Init(const struct LogStructure *structure, uint8_t num_types) { DataFlash_Backend::Init(structure, num_types); _blocks = NULL; while (_blockcount >= 8) { // 8 is a *magic* number _blocks = (struct dm_block *) malloc(_blockcount * sizeof(_blocks[0])); if (_blocks != NULL) { break; } _blockcount /= 2; } if (_blocks == NULL) { return; } free_all_blocks(); stats_init(); _initialised = true; _logging_started = true; // in actual fact, we throw away // everything until a client connects. // This stops calls to start_new_log from // the vehicles }
// initialisation void DataFlash_MAVLink::Init() { semaphore = hal.util->new_semaphore(); if (semaphore == nullptr) { AP_HAL::panic("Failed to create DataFlash_MAVLink semaphore"); return; } DataFlash_Backend::Init(); _blocks = nullptr; while (_blockcount >= 8) { // 8 is a *magic* number _blocks = (struct dm_block *) malloc(_blockcount * sizeof(_blocks[0])); if (_blocks != nullptr) { break; } _blockcount /= 2; } if (_blocks == nullptr) { return; } free_all_blocks(); stats_init(); _initialised = true; _logging_started = true; // in actual fact, we throw away // everything until a client connects. // This stops calls to start_new_log from // the vehicles }
/* Try to clear stats for all vport counters, which should succeed */ static void test_stats_vport_xxx_clear(int argc, char *argv[]) { int vportid = 0; stats_init(); stats_vport_clear_all(); /* increment stats so there's something to clear */ for (vportid = 0; vportid < MAX_VPORTS; vportid++) { stats_vport_rx_increment(vportid, 23); stats_vport_rx_drop_increment(vportid, 23); stats_vport_tx_increment(vportid, 23); stats_vport_tx_drop_increment(vportid, 23); stats_vport_overrun_increment(vportid, 23); stats_vport_rx_increment(vportid, 19); stats_vport_rx_drop_increment(vportid, 19); stats_vport_tx_increment(vportid, 19); stats_vport_tx_drop_increment(vportid, 19); stats_vport_overrun_increment(vportid, 19); } for (vportid = 0; vportid < MAX_VPORTS; vportid++) { stats_vport_clear(vportid); assert(stats_vport_rx_get(vportid) == 0); assert(stats_vport_rx_drop_get(vportid) == 0); assert(stats_vport_tx_get(vportid) == 0); assert(stats_vport_tx_drop_get(vportid) == 0); assert(stats_vport_overrun_get(vportid) == 0); } }
void test_reset_stats() { GString *reply = NULL; GString *command = g_string_sized_new(128); StatsCounterItem *counter = NULL; stats_init(); stats_lock(); stats_register_counter(0, SCS_CENTER, "id", "received", SC_TYPE_PROCESSED, &counter); stats_counter_set(counter, 666); stats_unlock(); g_string_assign(command, "RESET_STATS"); reply = control_connection_reset_stats(command); assert_string(reply->str, "The statistics of syslog-ng have been reset to 0.", "Bad reply"); g_string_free(reply, TRUE); g_string_assign(command, "STATS"); reply = control_connection_send_stats(command); assert_string(reply->str, "SourceName;SourceId;SourceInstance;State;Type;Number\ncenter;id;received;a;processed;0\n", "Bad reply"); g_string_free(reply, TRUE); stats_destroy(); g_string_free(command, TRUE); return; }
static inline void i1480u_init(struct i1480u *i1480u) { /* nothing so far... doesn't it suck? */ spin_lock_init(&i1480u->lock); INIT_LIST_HEAD(&i1480u->tx_list); spin_lock_init(&i1480u->tx_list_lock); wlp_options_init(&i1480u->options); edc_init(&i1480u->tx_errors); edc_init(&i1480u->rx_errors); #ifdef i1480u_FLOW_CONTROL edc_init(&i1480u->notif_edc); #endif stats_init(&i1480u->lqe_stats); stats_init(&i1480u->rssi_stats); wlp_init(&i1480u->wlp); }
static void setup(void) { g_thread_init(NULL); stats_init(); scratch_buffers_global_init(); scratch_buffers_allocator_init(); }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { /* Sanity check user-configurable values */ lwip_sanity_check(); /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ #if !NO_SYS /* in the Xilinx lwIP 1.2.0 port, lwip_init() was added as a convenience utility function to initialize all the lwIP layers. lwIP 1.3.0 introduced lwip_init() in the base lwIP itself. However a user cannot use lwip_init() regardless of whether it is raw or socket modes. The following call to lwip_sock_init() is made to make sure that lwIP is properly initialized in both raw & socket modes with just a call to lwip_init(). */ lwip_sock_init(); #endif }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { /*++ Changed by Espressif ++*/ MEMP_NUM_TCP_PCB = 5; TCP_WND = (4 * TCP_MSS); TCP_MAXRTX = 3; TCP_SYNMAXRTX = 6; /*-- --*/ /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ /*++ Changed by Espressif ++*/ #if 0 mem_init(&_bss_end); #endif /*-- --*/ memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accellerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int bno055_init(struct os_dev *dev, void *arg) { struct bno055 *bno055; struct sensor *sensor; int rc; bno055 = (struct bno055 *) dev; rc = bno055_default_cfg(&bno055->cfg); if (rc) { goto err; } #if MYNEWT_VAL(BNO055_LOG) log_register("bno055", &_log, &log_console_handler, NULL, LOG_SYSLEVEL); #endif sensor = &bno055->sensor; #if MYNEWT_VAL(BNO055_STATS) /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_bno055stats), STATS_SIZE_INIT_PARMS(g_bno055stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(bno055_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register("bno055", STATS_HDR(g_bno055stats)); SYSINIT_PANIC_ASSERT(rc == 0); #endif rc = sensor_init(sensor, dev); if (rc != 0) { goto err; } /* Add the accelerometer/magnetometer driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER | SENSOR_TYPE_MAGNETIC_FIELD | SENSOR_TYPE_GYROSCOPE | SENSOR_TYPE_TEMPERATURE | SENSOR_TYPE_ROTATION_VECTOR | SENSOR_TYPE_GRAVITY | SENSOR_TYPE_LINEAR_ACCEL | SENSOR_TYPE_EULER, (struct sensor_driver *) &g_bno055_sensor_driver); if (rc != 0) { goto err; } rc = sensor_mgr_register(sensor); if (rc != 0) { goto err; } return (0); err: return (rc); }
JNIEXPORT void JNICALL Java_com_android_spinningcube_SpinningCubeLib_init(JNIEnv * env, jobject obj, jint width, jint height, jstring vShader, jstring fShader) { if(!gVertexShader && !gFragmentShader) { gVertexShader = env->GetStringUTFChars(vShader, 0); gFragmentShader = env->GetStringUTFChars(fShader, 0); } setupGraphics(width, height); stats_init(&stats); }
static void init_stats(system_data_t *sysdata) { assert(sysdata); assert(sysdata->stats == NULL); sysdata->stats = (stats_t *) malloc(sizeof(stats_t)); stats_init(sysdata->stats); sysdata->stats->sysdata = sysdata; stats_start(sysdata->stats); }
void network_init() { struct ip_addr ipaddr, netmask, gw; printf("trying to initialize network...\n"); #ifdef STATS stats_init(); #endif /* STATS */ mem_init(); memp_init(); pbuf_init(); netif_init(); ip_init(); udp_init(); tcp_init(); etharp_init(); printf("ok now the NIC\n"); if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, enet_init, ip_input)) { printf("netif_add failed!\n"); return; } netif_set_default(&netif); dhcp_start(&netif); mftb(&last_tcp); mftb(&last_dhcp); printf("\nWaiting for DHCP"); int i; for (i=0; i<10; i++) { mdelay(500); network_poll(); printf("."); if (netif.ip_addr.addr) break; } if (netif.ip_addr.addr) { printf("%u.%u.%u.%u\n", (netif.ip_addr.addr >> 24) & 0xFF, (netif.ip_addr.addr >> 16) & 0xFF, (netif.ip_addr.addr >> 8) & 0xFF, (netif.ip_addr.addr >> 0) & 0xFF); printf("\n"); } else {
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void lwip_init(void) { esp_ms_timer_init(); // espressif /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_IPV4 ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #endif /* LWIP_IPV4 */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_IPV6 ip6_init(); nd6_init(); #if LWIP_IPV6_MLD mld6_init(); #endif /* LWIP_IPV6_MLD */ #endif /* LWIP_IPV6 */ #if PPP_SUPPORT ppp_init(); #endif #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); init_syslog(); uopt_init(); if (fuse_opt_parse(&args, NULL, unionfs_opts, unionfs_opt_proc) == -1) RETURN(1); if (uopt.debug) debug_init(); if (!uopt.doexit) { if (uopt.nbranches == 0) { printf("You need to specify at least one branch!\n"); RETURN(1); } if (uopt.stats_enabled) stats_init(&stats); } // enable fuse permission checks, we need to set this, even we we are // not root, since we don't have our own access() function int uid = getuid(); int gid = getgid(); bool default_permissions = true; if (uid != 0 && gid != 0 && uopt.relaxed_permissions) { default_permissions = false; } else if (uopt.relaxed_permissions) { // protec the user of a very critical security issue fprintf(stderr, "Relaxed permissions disallowed for root!\n"); exit(1); } if (default_permissions) { if (fuse_opt_add_arg(&args, "-odefault_permissions")) { fprintf(stderr, "Severe failure, can't enable permssion checks, aborting!\n"); exit(1); } } unionfs_post_opts(); #ifdef FUSE_CAP_BIG_WRITES /* libfuse > 0.8 supports large IO, also for reads, to increase performance * We support any IO sizes, so lets enable that option */ if (fuse_opt_add_arg(&args, "-obig_writes")) { fprintf(stderr, "Failed to enable big writes!\n"); exit(1); } #endif umask(0); int res = fuse_main(args.argc, args.argv, &unionfs_oper, NULL); RETURN(uopt.doexit ? uopt.retval : res); }
/* Try to increment stats for all vswitch counters, which should * succeed */ static void test_stats_vswitch_increment(int argc, char *argv[]) { stats_init(); stats_vswitch_clear(); stats_vswitch_rx_drop_increment(23); stats_vswitch_tx_drop_increment(23); stats_vswitch_rx_drop_increment(19); stats_vswitch_tx_drop_increment(19); }
void _thread_process(moThread *thread) { moModule *module = (moModule *)thread->getUserData(); stats_init(&module->stats); while ( !thread->wantQuit() ) { if ( !module->needUpdate(true) ) continue; stats_wait(&module->stats); module->update(); stats_process(&module->stats); } }
/** * Perform Sanity check of user-configurable values, and initialize all modules. */ void ICACHE_FLASH_ATTR lwip_init(void) { /* Modules initialization */ stats_init(); #if !NO_SYS sys_init(); #endif /* !NO_SYS */ mem_init(); memp_init(); pbuf_init(); netif_init(); #if LWIP_SOCKET lwip_socket_init(); #endif /* LWIP_SOCKET */ ip_init(); #if LWIP_ARP etharp_init(); #endif /* LWIP_ARP */ #if LWIP_RAW raw_init(); #endif /* LWIP_RAW */ #if LWIP_UDP udp_init(); #endif /* LWIP_UDP */ #if LWIP_TCP tcp_init(); #endif /* LWIP_TCP */ #if LWIP_SNMP snmp_init(); #endif /* LWIP_SNMP */ #if LWIP_AUTOIP autoip_init(); #endif /* LWIP_AUTOIP */ #if LWIP_IGMP igmp_init(); #endif /* LWIP_IGMP */ #if LWIP_DNS dns_init(); #endif /* LWIP_DNS */ #if LWIP_IPV6 ip6_init(); nd6_init(); #if LWIP_IPV6_MLD mld6_init(); #endif /* LWIP_IPV6_MLD */ #endif /* LWIP_IPV6 */ #if LWIP_TIMERS sys_timeouts_init(); #endif /* LWIP_TIMERS */ }
/** * main * * The main task for the project. This function initializes the packages, calls * init_tasks to initialize additional tasks (and possibly other objects), * then starts serving events from default event queue. * * @return int NOTE: this function should never return! */ int main(int argc, char **argv) { int rc; #ifdef ARCH_sim mcu_sim_parse_args(argc, argv); #endif sysinit(); rc = conf_register(&test_conf_handler); assert(rc == 0); cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF); log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL); stats_init(STATS_HDR(g_stats_gpio_toggle), STATS_SIZE_INIT_PARMS(g_stats_gpio_toggle, STATS_SIZE_32), STATS_NAME_INIT_PARMS(gpio_stats)); stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle)); flash_test_init(); conf_load(); log_reboot(hal_reset_cause()); init_tasks(); /* If this app is acting as the loader in a split image setup, jump into * the second stage application instead of starting the OS. */ #if MYNEWT_VAL(SPLIT_LOADER) { void *entry; rc = split_app_go(&entry, true); if(rc == 0) { hal_system_restart(entry); } } #endif /* * As the last thing, process events from default event queue. */ while (1) { os_eventq_run(os_eventq_dflt_get()); } }
int main(int argc, char** argv) { stats_init(); int i = 0; while (++i < 5000) { stats_add(ARANDN, ARANDN, ARANDN); if (i % 10 == 0) { printf("xsum: %d\nysum: %d\nzsum: %d\nptr: %d\n\n", stats.xsum, stats.ysum, stats.zsum, stats.aptr); } } return 0; }
static int control(struct af_instance_s *af, int cmd, void *arg) { struct af_stats *s = af->setup; switch(cmd) { case AF_CONTROL_REINIT: return stats_init(af, s, arg); case AF_CONTROL_PRE_DESTROY: stats_print(s); return AF_OK; } return AF_UNKNOWN; }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accellerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int mpu6050_init(struct os_dev *dev, void *arg) { struct mpu6050 *mpu; struct sensor *sensor; int rc; if (!arg || !dev) { return SYS_ENODEV; } mpu = (struct mpu6050 *) dev; mpu->cfg.mask = SENSOR_TYPE_ALL; log_register(dev->od_name, &_log, &log_console_handler, NULL, LOG_SYSLEVEL); sensor = &mpu->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_mpu6050stats), STATS_SIZE_INIT_PARMS(g_mpu6050stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(mpu6050_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register(dev->od_name, STATS_HDR(g_mpu6050stats)); SYSINIT_PANIC_ASSERT(rc == 0); rc = sensor_init(sensor, dev); if (rc) { return rc; } /* Add the accelerometer/gyroscope driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_GYROSCOPE | SENSOR_TYPE_ACCELEROMETER, (struct sensor_driver *) &g_mpu6050_sensor_driver); if (rc) { return rc; } rc = sensor_set_interface(sensor, arg); if (rc) { return rc; } return sensor_mgr_register(sensor); }