/** * 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); }
/** * 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; }
/** * 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; }
/** * 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); }
/** * 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()); } }
/** * 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); }
/** * 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); /* Initialize the OIC */ log_register("oic", &oc_log, &log_console_handler, NULL, 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()); #if MYNEWT_VAL(SPLIT_LOADER) { void *entry; rc = split_app_go(&entry, true); if(rc == 0) { hal_system_start(entry); } } #endif init_tasks(); while (1) { os_eventq_run(os_eventq_dflt_get()); } /* Never returns */ return rc; }
/** * 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(); 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)); conf_load(); log_reboot(HARD_REBOOT); #if MYNEWT_VAL(SPLIT_LOADER) { void *entry; rc = split_app_go(&entry, true); if(rc == 0) { hal_system_start(entry); } } #endif init_tasks(); os_start(); /* os start should never return. If it does, this should be an error */ assert(0); return rc; }
int init_stats(int nr_of_processes) { LM_DBG("initializing stats for %d processes\n", nr_of_processes); global_stats = shm_malloc(nr_of_processes*sizeof(struct stats_s)); if(!global_stats) { LM_ERR("Out of memory\n"); return -1; } stats_segments = nr_of_processes; if(stats_register() == -1) LM_WARN("Couldn't register stats with snmp module\n"); return 0; }
/** * Clear an asserted interrupt on the device * * @param The sensor interface * @return 0 on success, non-zero on failure */ int tsl2561_clear_interrupt(struct sensor_itf *itf) { int rc; uint8_t payload = { TSL2561_COMMAND_BIT | TSL2561_CLEAR_BIT }; struct hal_i2c_master_data data_struct = { .address = itf->si_addr, .len = 1, .buffer = &payload }; /* To clear the interrupt set the CLEAR bit in the COMMAND register */ rc = hal_i2c_master_write(itf->si_num, &data_struct, OS_TICKS_PER_SEC / 10, 1); if (rc) { goto err; } STATS_INC(g_tsl2561stats, ints_cleared); return 0; err: return rc; } /** * Expects to be called back through os_dev_create(). * * @param The device object associated with this luminosity sensor * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int tsl2561_init(struct os_dev *dev, void *arg) { struct tsl2561 *tsl2561; struct sensor *sensor; int rc; if (!arg || !dev) { rc = SYS_ENODEV; goto err; } tsl2561 = (struct tsl2561 *) dev; tsl2561->cfg.mask = SENSOR_TYPE_ALL; sensor = &tsl2561->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_tsl2561stats), STATS_SIZE_INIT_PARMS(g_tsl2561stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(tsl2561_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register(dev->od_name, STATS_HDR(g_tsl2561stats)); SYSINIT_PANIC_ASSERT(rc == 0); rc = sensor_init(sensor, dev); if (rc) { goto err; } /* Add the light driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_LIGHT, (struct sensor_driver *) &g_tsl2561_sensor_driver); if (rc) { goto err; } /* Set the interface */ rc = sensor_set_interface(sensor, arg); if (rc) { goto err; } rc = sensor_mgr_register(sensor); if (rc) { goto err; } return 0; err: return rc; } static uint32_t tsl2561_calculate_lux(uint16_t broadband, uint16_t ir, struct tsl2561_cfg *cfg) { uint64_t chscale; uint64_t channel1; uint64_t channel0; uint16_t clipthreshold; uint64_t ratio1; uint64_t ratio; int64_t b, m; uint64_t temp; uint32_t lux; /* Make sure the sensor isn't saturated! */ switch (cfg->integration_time) { case TSL2561_LIGHT_ITIME_13MS: clipthreshold = TSL2561_CLIPPING_13MS; break; case TSL2561_LIGHT_ITIME_101MS: clipthreshold = TSL2561_CLIPPING_101MS; break; default: clipthreshold = TSL2561_CLIPPING_402MS; break; } /* Return 65536 lux if the sensor is saturated */ if ((broadband > clipthreshold) || (ir > clipthreshold)) { return 65536; } /* Get the correct scale depending on the intergration time */ switch (cfg->integration_time) { case TSL2561_LIGHT_ITIME_13MS: chscale = TSL2561_LUX_CHSCALE_TINT0; break; case TSL2561_LIGHT_ITIME_101MS: chscale = TSL2561_LUX_CHSCALE_TINT1; break; default: /* No scaling ... integration time = 402ms */ chscale = (1 << TSL2561_LUX_CHSCALE); break; } /* Scale for gain (1x or 16x) */ if (!cfg->gain) { chscale = chscale << 4; } /* Scale the channel values */ channel0 = (broadband * chscale) >> TSL2561_LUX_CHSCALE; channel1 = (ir * chscale) >> TSL2561_LUX_CHSCALE; ratio1 = 0; /* Find the ratio of the channel values (Channel1/Channel0) */ if (channel0 != 0) { ratio1 = (channel1 << (TSL2561_LUX_RATIOSCALE+1)) / channel0; } /* round the ratio value */ ratio = (ratio1 + 1) >> 1; #if MYNEWT_VAL(TSL2561_PACKAGE_CS) if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1C)) { b = TSL2561_LUX_B1C; m = TSL2561_LUX_M1C; } else if (ratio <= TSL2561_LUX_K2C) { b = TSL2561_LUX_B2C; m = TSL2561_LUX_M2C; } else if (ratio <= TSL2561_LUX_K3C) { b = TSL2561_LUX_B3C; m = TSL2561_LUX_M3C; } else if (ratio <= TSL2561_LUX_K4C) { b = TSL2561_LUX_B4C; m = TSL2561_LUX_M4C; } else if (ratio <= TSL2561_LUX_K5C) { b = TSL2561_LUX_B5C; m = TSL2561_LUX_M5C; } else if (ratio <= TSL2561_LUX_K6C) { b = TSL2561_LUX_B6C; m = TSL2561_LUX_M6C; } else if (ratio <= TSL2561_LUX_K7C) { b = TSL2561_LUX_B7C; m = TSL2561_LUX_M7C; } else if (ratio > TSL2561_LUX_K8C) { b = TSL2561_LUX_B8C; m = TSL2561_LUX_M8C; } #else if ((ratio >= 0) && (ratio <= TSL2561_LUX_K1T)) { b = TSL2561_LUX_B1T; m = TSL2561_LUX_M1T; } else if (ratio <= TSL2561_LUX_K2T) { b = TSL2561_LUX_B2T; m = TSL2561_LUX_M2T; } else if (ratio <= TSL2561_LUX_K3T) { b = TSL2561_LUX_B3T; m = TSL2561_LUX_M3T; } else if (ratio <= TSL2561_LUX_K4T) { b = TSL2561_LUX_B4T; m = TSL2561_LUX_M4T; } else if (ratio <= TSL2561_LUX_K5T) { b = TSL2561_LUX_B5T; m = TSL2561_LUX_M5T; } else if (ratio <= TSL2561_LUX_K6T) { b = TSL2561_LUX_B6T; m = TSL2561_LUX_M6T; } else if (ratio <= TSL2561_LUX_K7T) { b = TSL2561_LUX_B7T; m = TSL2561_LUX_M7T; } else if (ratio > TSL2561_LUX_K8T) { b = TSL2561_LUX_B8T; m = TSL2561_LUX_M8T; } #endif temp = ((channel0 * b) - (channel1 * m)); /* Do not allow negative lux value */ if (temp < 0) { temp = 0; } /* Round lsb (2^(LUX_SCALE-1)) */ temp += (1 << (TSL2561_LUX_LUXSCALE - 1)); /* Strip off fractional portion */ lux = temp >> TSL2561_LUX_LUXSCALE; return lux; }
void stats_plugin_init(struct module *module) { mail_stats_item = stats_register(&mail_stats_vfuncs); mail_storage_hooks_add(module, &stats_mail_storage_hooks); }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accelerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int lis2dw12_init(struct os_dev *dev, void *arg) { struct lis2dw12 *lis2dw12; struct sensor *sensor; int rc; if (!arg || !dev) { rc = SYS_ENODEV; goto err; } lis2dw12 = (struct lis2dw12 *) dev; lis2dw12->cfg.mask = SENSOR_TYPE_ALL; log_register(dev->od_name, &_log, &log_console_handler, NULL, LOG_SYSLEVEL); sensor = &lis2dw12->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_lis2dw12stats), STATS_SIZE_INIT_PARMS(g_lis2dw12stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(lis2dw12_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register(dev->od_name, STATS_HDR(g_lis2dw12stats)); SYSINIT_PANIC_ASSERT(rc == 0); rc = sensor_init(sensor, dev); if (rc) { goto err; } /* Add the light driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER, (struct sensor_driver *) &g_lis2dw12_sensor_driver); if (rc) { goto err; } /* Set the interface */ rc = sensor_set_interface(sensor, arg); if (rc) { goto err; } rc = sensor_mgr_register(sensor); if (rc) { goto err; } if (sensor->s_itf.si_type == SENSOR_ITF_SPI) { rc = hal_spi_disable(sensor->s_itf.si_num); if (rc) { goto err; } rc = hal_spi_config(sensor->s_itf.si_num, &spi_lis2dw12_settings); if (rc == EINVAL) { /* If spi is already enabled, for nrf52, it returns -1, We should not * fail if the spi is already enabled */ goto err; } rc = hal_spi_enable(sensor->s_itf.si_num); if (rc) { goto err; } rc = hal_gpio_init_out(sensor->s_itf.si_cs_pin, 1); if (rc) { goto err; } } init_interrupt(&lis2dw12->intr, lis2dw12->sensor.s_itf.si_ints); lis2dw12->pdd.notify_ctx.snec_sensor = sensor; lis2dw12->pdd.registered_mask = 0; lis2dw12->pdd.interrupt = NULL; rc = init_intpin(lis2dw12, lis2dw12_int_irq_handler, sensor); if (rc) { return rc; } return 0; err: return rc; }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accelerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int adxl345_init(struct os_dev *dev, void *arg) { struct adxl345 *adxl; struct sensor *sensor; int rc; if (!arg || !dev) { return SYS_ENODEV; } adxl = (struct adxl345 *) dev; adxl->cfg.mask = SENSOR_TYPE_ALL; log_register(dev->od_name, &_log, &log_console_handler, NULL, LOG_SYSLEVEL); sensor = &adxl->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_adxl345stats), STATS_SIZE_INIT_PARMS(g_adxl345stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(adxl345_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register(dev->od_name, STATS_HDR(g_adxl345stats)); 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_ACCELEROMETER, (struct sensor_driver *) &adxl345_sensor_driver); if (rc) { return rc; } rc = sensor_set_interface(sensor, arg); if (rc) { return rc; } rc = sensor_mgr_register(sensor); if (rc) { return rc; } if (sensor->s_itf.si_type == SENSOR_ITF_SPI) { rc = hal_spi_config(sensor->s_itf.si_num, &spi_adxl345_settings); if (rc == EINVAL) { return rc; } rc = hal_spi_enable(sensor->s_itf.si_num); if (rc) { return rc; } rc = hal_gpio_init_out(sensor->s_itf.si_cs_pin, 1); if (rc) { return rc; } } #if MYNEWT_VAL(ADXL345_INT_ENABLE) adxl->pdd.read_ctx.srec_sensor = sensor; adxl->pdd.notify_ctx.snec_sensor = sensor; rc = init_intpin(adxl, interrupt_handler, sensor); if (rc != 0) { return rc; } #endif return 0; }