/** * main * * The main task for the project. This function initializes the packages, * then starts serving events from default event queue. * * @return int NOTE: this function should never return! */ int main(void) { int rc; /* Initialize OS */ sysinit(); /* Initialize the blesplit log. */ log_register("blesplit", &blesplit_log, &log_console_handler, NULL, LOG_SYSLEVEL); /* Initialize the NimBLE host configuration. */ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL); ble_hs_cfg.reset_cb = blesplit_on_reset; ble_hs_cfg.sync_cb = blesplit_on_sync; ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /* Set the default device name. */ rc = ble_svc_gap_device_name_set("nimble-blesplit"); assert(rc == 0); conf_load(); /* * As the last thing, process events from default event queue. */ while (1) { os_eventq_run(os_eventq_dflt_get()); } return 0; }
static VALUE bdb_log_register(VALUE obj, VALUE a) { #if ! (HAVE_ST_DB_ENV_LOG_REGISTER || HAVE_DB_LOG_REGISTER || HAVE_ST_DB_ENV_LG_INFO) rb_warn("log_register is obsolete"); return Qnil; #else bdb_DB *dbst; bdb_ENV *envst; if (TYPE(a) != T_STRING) { rb_raise(bdb_eFatal, "Need a filename"); } if (bdb_env_p(obj) == Qfalse) { rb_raise(bdb_eFatal, "Database must be open in an Env"); } Data_Get_Struct(obj, bdb_DB, dbst); Data_Get_Struct(dbst->env, bdb_ENV, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_register(envst->envp->lg_info, dbst->dbp, StringValuePtr(a), dbst->type, &envst->fidp)); #elif HAVE_ST_DB_ENV_LOG_REGISTER bdb_test_error(envst->envp->log_register(envst->envp, dbst->dbp, StringValuePtr(a))); #else #if HAVE_DB_LOG_REGISTER_4 bdb_test_error(log_register(envst->envp, dbst->dbp, StringValuePtr(a), &envst->fidp)); #else bdb_test_error(log_register(envst->envp, dbst->dbp, StringValuePtr(a))); #endif #endif return obj; #endif }
/** * 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 task for the project. This function initializes the packages, * then starts serving events from default event queue. * * @return int NOTE: this function should never return! */ int main(void) { int rc; /* Initialize OS */ sysinit(); /* Initialize the BLE host. */ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL); ble_hs_cfg.sync_cb = bleuart_on_sync; ble_hs_cfg.store_status_cb = ble_store_util_status_rr; rc = bleuart_gatt_svr_init(); assert(rc == 0); /* Set the default device name. */ rc = ble_svc_gap_device_name_set("Mynewt_BLEuart"); assert(rc == 0); while (1) { os_eventq_run(os_eventq_dflt_get()); } /* Never exit */ return 0; }
/** * 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; }
/** * 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; }
static void ble_oic_log_init(void) { #if MYNEWT_VAL(SENSOR_BLE) /* Initialize the bleprph log. */ log_register("bleprph", &bleprph_log, &log_console_handler, NULL, LOG_SYSLEVEL); /* Initialize the NimBLE host configuration. */ log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL); #endif #if MYNEWT_VAL(SENSOR_OIC) /* Initialize the OIC */ log_register("oic", &oc_log, &log_console_handler, NULL, LOG_SYSLEVEL); #endif }
/** * 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); }
static int log_millisecond_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) { static APR_OPTIONAL_FN_TYPE(ap_register_log_handler) *log_register; log_register = APR_RETRIEVE_OPTIONAL_FN(ap_register_log_handler); if (!log_register) return DECLINED; log_register(p, "M", log_request_duration_milliseconds, 1); return OK; }
/** * 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 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 conf_init(); log_init(); log_console_handler_init(&log_console_handler); log_register("log", &my_log, &log_console_handler); LOG_DEBUG(&my_log, LOG_MODULE_DEFAULT, "bla"); LOG_DEBUG(&my_log, LOG_MODULE_DEFAULT, "bab"); os_init(); rc = os_mempool_init(&default_mbuf_mpool, DEFAULT_MBUF_MPOOL_NBUFS, DEFAULT_MBUF_MPOOL_BUF_LEN, default_mbuf_mpool_data, "default_mbuf_data"); assert(rc == 0); rc = os_mbuf_pool_init(&default_mbuf_pool, &default_mbuf_mpool, DEFAULT_MBUF_MPOOL_BUF_LEN, DEFAULT_MBUF_MPOOL_NBUFS); assert(rc == 0); rc = os_msys_register(&default_mbuf_pool); assert(rc == 0); shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE, SHELL_MAX_INPUT_LEN); (void) console_init(shell_console_rx_cb); stats_module_init(); rc = init_tasks(); os_start(); /* os start should never return. If it does, this should be an error */ assert(0); return rc; }
return_t module_start (void) { service_register_t service_register_info; service_register_info.service_vendor = "chaos development"; service_register_info.device_vendor = "N/A"; service_register_info.model = "Log module"; service_register_info.device_id = "1"; service_register_info.info_handler = &service_info; // FIXME: Fill in this structure. service_method_t service_method[] = { { -1, NULL } }; return log_register (&service_register_info, service_method); }
/** * 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; }
/** * Initializes the host portion of the BLE stack. */ int ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg) { int rc; ble_hs_free_mem(); if (app_evq == NULL) { rc = BLE_HS_EINVAL; goto err; } ble_hs_parent_evq = app_evq; ble_hs_cfg_init(cfg); log_init(); log_console_handler_init(&ble_hs_log_console_handler); log_register("ble_hs", &ble_hs_log, &ble_hs_log_console_handler); ble_hs_hci_cmd_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs, HCI_CMD_BUF_SIZE)); if (ble_hs_hci_cmd_buf == NULL) { rc = BLE_HS_ENOMEM; goto err; } /* Create memory pool of command buffers */ rc = os_mempool_init(&g_hci_cmd_pool, ble_hs_cfg.max_hci_bufs, HCI_CMD_BUF_SIZE, ble_hs_hci_cmd_buf, "HCICmdPool"); assert(rc == 0); ble_hs_hci_os_event_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs, HCI_OS_EVENT_BUF_SIZE)); if (ble_hs_hci_os_event_buf == NULL) { rc = BLE_HS_ENOMEM; goto err; } /* Create memory pool of OS events */ rc = os_mempool_init(&g_hci_os_event_pool, ble_hs_cfg.max_hci_bufs, HCI_OS_EVENT_BUF_SIZE, ble_hs_hci_os_event_buf, "HCIOsEventPool"); assert(rc == 0); /* Initialize eventq */ os_eventq_init(&ble_hs_evq); /* Initialize stats. */ rc = stats_module_init(); if (rc != 0) { rc = BLE_HS_EOS; goto err; } ble_hci_cmd_init(); rc = ble_hs_conn_init(); if (rc != 0) { goto err; } rc = ble_l2cap_init(); if (rc != 0) { goto err; } rc = ble_att_init(); if (rc != 0) { goto err; } rc = ble_att_svr_init(); if (rc != 0) { goto err; } rc = ble_gap_init(); if (rc != 0) { goto err; } rc = ble_gattc_init(); if (rc != 0) { goto err; } rc = ble_gatts_init(); if (rc != 0) { goto err; } os_mqueue_init(&ble_hs_rx_q, NULL); os_mqueue_init(&ble_hs_tx_q, NULL); rc = stats_init_and_reg( STATS_HDR(ble_hs_stats), STATS_SIZE_INIT_PARMS(ble_hs_stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_hs_stats), "ble_hs"); if (rc != 0) { rc = BLE_HS_EOS; goto err; } os_callout_func_init(&ble_hs_heartbeat_timer, ble_hs_parent_evq, ble_hs_heartbeat, NULL); os_callout_func_init(&ble_hs_event_co, &ble_hs_evq, ble_hs_event_handle, NULL); rc = os_mutex_init(&ble_hs_mutex); if (rc != 0) { rc = BLE_HS_EOS; goto err; } return 0; err: ble_hs_free_mem(); return rc; }
/** * Initializes internal nffs memory and data structures. This must be called * before any nffs operations are attempted. * * @return 0 on success; nonzero on error. */ int nffs_init(void) { int rc; nffs_config_init(); nffs_cache_clear(); rc = os_mutex_init(&nffs_mutex); if (rc != 0) { return FS_EOS; } free(nffs_file_mem); nffs_file_mem = malloc( OS_MEMPOOL_BYTES(nffs_config.nc_num_files, sizeof (struct nffs_file))); if (nffs_file_mem == NULL) { return FS_ENOMEM; } free(nffs_inode_mem); nffs_inode_mem = malloc( OS_MEMPOOL_BYTES(nffs_config.nc_num_inodes, sizeof (struct nffs_inode_entry))); if (nffs_inode_mem == NULL) { return FS_ENOMEM; } free(nffs_block_entry_mem); nffs_block_entry_mem = malloc( OS_MEMPOOL_BYTES(nffs_config.nc_num_blocks, sizeof (struct nffs_hash_entry))); if (nffs_block_entry_mem == NULL) { return FS_ENOMEM; } free(nffs_cache_inode_mem); nffs_cache_inode_mem = malloc( OS_MEMPOOL_BYTES(nffs_config.nc_num_cache_inodes, sizeof (struct nffs_cache_inode))); if (nffs_cache_inode_mem == NULL) { return FS_ENOMEM; } free(nffs_cache_block_mem); nffs_cache_block_mem = malloc( OS_MEMPOOL_BYTES(nffs_config.nc_num_cache_blocks, sizeof (struct nffs_cache_block))); if (nffs_cache_block_mem == NULL) { return FS_ENOMEM; } free(nffs_dir_mem); nffs_dir_mem = malloc( OS_MEMPOOL_BYTES(nffs_config.nc_num_dirs, sizeof (struct nffs_dir))); if (nffs_dir_mem == NULL) { return FS_ENOMEM; } log_init(); log_console_handler_init(&nffs_log_console_handler); log_register("nffs", &nffs_log, &nffs_log_console_handler); rc = nffs_misc_reset(); if (rc != 0) { return rc; } fs_register(&nffs_ops); return 0; }
int tsl2561_clear_interrupt (void) { int rc; uint8_t payload = { TSL2561_COMMAND_BIT | TSL2561_CLEAR_BIT }; struct hal_i2c_master_data data_struct = { .address = MYNEWT_VAL(TSL2561_I2CADDR), .len = 1, .buffer = &payload }; /* To clear the interrupt set the CLEAR bit in the COMMAND register */ rc = hal_i2c_master_write(MYNEWT_VAL(TSL2561_I2CBUS), &data_struct, OS_TICKS_PER_SEC / 10, 1); if (rc) { goto err; } #if MYNEWT_VAL(TSL2561_STATS) STATS_INC(g_tsl2561stats, ints_cleared); #endif err: 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 tsl2561_init(struct os_dev *dev, void *arg) { struct tsl2561 *tsl2561; struct sensor *sensor; int rc; tsl2561 = (struct tsl2561 *) dev; #if MYNEWT_VAL(TSL2561_LOG) log_register("tsl2561", &_log, &log_console_handler, NULL, LOG_SYSLEVEL); #endif sensor = &tsl2561->sensor; #if MYNEWT_VAL(TSL2561_STATS) /* 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("tsl2561", STATS_HDR(g_tsl2561stats)); SYSINIT_PANIC_ASSERT(rc == 0); #endif rc = sensor_init(sensor, dev); if (rc != 0) { goto err; } /* Add the light driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_LIGHT, (struct sensor_driver *) &g_tsl2561_sensor_driver); if (rc != 0) { goto err; } rc = sensor_mgr_register(sensor); if (rc != 0) { goto err; } return (0); err: return (rc); } static void * tsl2561_sensor_get_interface(struct sensor *sensor, sensor_type_t type) { return (NULL); } 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; }
/** * 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; }
void lldpctl_log_callback(void (*cb)(int severity, const char *msg)) { log_register(cb); }
/** * 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; }
/** * 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(void) { struct ble_hs_cfg cfg; uint32_t seed; int rc; int i; /* Initialize OS */ os_init(); /* Set cputime to count at 1 usec increments */ rc = cputime_init(1000000); assert(rc == 0); /* Seed random number generator with least significant bytes of device * address. */ seed = 0; for (i = 0; i < 4; ++i) { seed |= g_dev_addr[i]; seed <<= 8; } srand(seed); /* Initialize msys mbufs. */ rc = os_mempool_init(&bleprph_mbuf_mpool, MBUF_NUM_MBUFS, MBUF_MEMBLOCK_SIZE, bleprph_mbuf_mpool_data, "bleprph_mbuf_data"); assert(rc == 0); rc = os_mbuf_pool_init(&bleprph_mbuf_pool, &bleprph_mbuf_mpool, MBUF_MEMBLOCK_SIZE, MBUF_NUM_MBUFS); assert(rc == 0); rc = os_msys_register(&bleprph_mbuf_pool); assert(rc == 0); /* Initialize the logging system. */ log_init(); log_console_handler_init(&bleprph_log_console_handler); log_register("bleprph", &bleprph_log, &bleprph_log_console_handler); os_task_init(&bleprph_task, "bleprph", bleprph_task_handler, NULL, BLEPRPH_TASK_PRIO, OS_WAIT_FOREVER, bleprph_stack, BLEPRPH_STACK_SIZE); /* Initialize the BLE LL */ rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE); assert(rc == 0); /* Initialize the BLE host. */ cfg = ble_hs_cfg_dflt; cfg.max_hci_bufs = 3; cfg.max_connections = 1; cfg.max_attrs = 42; cfg.max_services = 5; cfg.max_client_configs = 6; cfg.max_gattc_procs = 2; cfg.max_l2cap_chans = 3; cfg.max_l2cap_sig_procs = 1; cfg.sm_bonding = 1; cfg.sm_our_key_dist = BLE_L2CAP_SM_PAIR_KEY_DIST_ENC; cfg.sm_their_key_dist = BLE_L2CAP_SM_PAIR_KEY_DIST_ENC; /* Initialize eventq */ os_eventq_init(&bleprph_evq); rc = ble_hs_init(&bleprph_evq, &cfg); assert(rc == 0); /* Initialize the console (for log output). */ rc = console_init(NULL); assert(rc == 0); /* Register GATT attributes (services, characteristics, and * descriptors). */ gatt_svr_init(); /* Start the OS */ os_start(); /* os start should never return. If it does, this should be an error */ assert(0); return 0; }
/** * main * * The main task for the project. This function initializes the packages, * then starts serving events from default event queue. * * @return int NOTE: this function should never return! */ int main(void) { int rc; /* Initialize OS */ sysinit(); /* Dummy device address */ #if BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER g_dev_addr[0] = 0x00; g_dev_addr[1] = 0x00; g_dev_addr[2] = 0x00; g_dev_addr[3] = 0x88; g_dev_addr[4] = 0x88; g_dev_addr[5] = 0x08; g_bletest_cur_peer_addr[0] = 0x00; g_bletest_cur_peer_addr[1] = 0x00; g_bletest_cur_peer_addr[2] = 0x00; g_bletest_cur_peer_addr[3] = 0x99; g_bletest_cur_peer_addr[4] = 0x99; g_bletest_cur_peer_addr[5] = 0x09; #else g_dev_addr[0] = 0x00; g_dev_addr[1] = 0x00; g_dev_addr[2] = 0x00; g_dev_addr[3] = 0x99; g_dev_addr[4] = 0x99; g_dev_addr[5] = 0x09; g_bletest_cur_peer_addr[0] = 0x00; g_bletest_cur_peer_addr[1] = 0x00; g_bletest_cur_peer_addr[2] = 0x00; g_bletest_cur_peer_addr[3] = 0x88; g_bletest_cur_peer_addr[4] = 0x88; g_bletest_cur_peer_addr[5] = 0x08; #endif log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL, LOG_SYSLEVEL); /* Set the led pin as an output */ g_led_pin = LED_BLINK_PIN; hal_gpio_init_out(g_led_pin, 1); /* Initialize eventq for bletest task */ os_eventq_init(&g_bletest_evq); rc = os_task_init(&bletest_task, "bletest", bletest_task_handler, NULL, BLETEST_TASK_PRIO, OS_WAIT_FOREVER, bletest_stack, BLETEST_STACK_SIZE); assert(rc == 0); while (1) { os_eventq_run(os_eventq_dflt_get()); } /* Never returns */ /* os start should never return. If it does, this should be an error */ assert(0); return rc; }