bool HT1632::read_from_address( uint8_t addr, uint8_t *value ) { if( addr >= memory_limit() ) return false; set_mode(read_mode); send_address( addr ); *value = read_nibble(); deselect(); return true; }
bool HT1632::write_to_address( uint8_t addr, uint8_t value ) { if( addr >= memory_limit() ) return false; set_mode(write_mode); send_address( addr ); send_data( value ); deselect(); return true; }
bool HT1632::write_buffer( uint8_t *buffer, uint8_t length, uint8_t offset ) { if( (length + offset)*2 > memory_limit() ) return false; uint8_t *pointer = buffer; set_mode(write_mode); send_address( offset*2 ); while( length-- ) { uint8_t temp = *pointer; send_data( temp ); swap( temp ); send_data( temp ); ++pointer; } deselect(); return true; }
int main(int argc, char** argv) { setlocale(LC_ALL, ""); TBSYS_LOGGER.setFileName("ups_admin.log", true); TBSYS_LOG(INFO, "ups_admin start=================================================="); ob_init_memory_pool(); CmdLineParam clp; parse_cmd_line(argc, argv, clp); timeout = clp.timeout?: timeout; MockClient client; init_mock_client(clp.serv_addr, clp.serv_port, clp.login_type, client); PageArena<char> allocer; int rc = 0; if (0 == strcmp("apply", clp.cmd_type)) { apply(clp.ini_fname, allocer, client); } else if (0 == strcmp("get_clog_status", clp.cmd_type)) { get_clog_status(client); } else if (0 == strcmp("get_max_log_seq", clp.cmd_type)) { get_max_log_seq(client); } else if (0 == strcmp("get_clog_cursor", clp.cmd_type)) { get_clog_cursor(client); } else if (0 == strcmp("get_clog_master", clp.cmd_type)) { get_clog_master(client); } else if (0 == strcmp("get_log_sync_delay_stat", clp.cmd_type)) { get_log_sync_delay_stat(client); } else if (0 == strcmp("get", clp.cmd_type)) { get(clp.ini_fname, allocer, client, clp.version_range,clp.expected_result_fname, clp.schema_fname); } else if (0 == strcmp("param_get", clp.cmd_type)) { param_get(clp.ini_fname, client); } else if (0 == strcmp("scan", clp.cmd_type)) { scan(clp.ini_fname, allocer, client, clp.version_range,clp.expected_result_fname, clp.schema_fname); } else if (0 == strcmp("total_scan", clp.cmd_type)) { total_scan(clp.ini_fname, allocer, client, clp.version_range); } else if (0 == strcmp("minor_freeze", clp.cmd_type)) { minor_freeze(client); } else if (0 == strcmp("major_freeze", clp.cmd_type)) { major_freeze(client); } else if (0 == strcmp("fetch_schema", clp.cmd_type)) { fetch_schema(client, clp.timestamp); } else if (0 == strcmp("get_sstable_range_list", clp.cmd_type)) { get_sstable_range_list(client, clp.timestamp, clp.session_id); } else if (0 == strcmp("drop", clp.cmd_type)) { drop(client); } else if (0 == strcmp("dump_memtable", clp.cmd_type)) { dump_memtable(clp.ini_fname, client); } else if (0 == strcmp("dump_schemas", clp.cmd_type)) { dump_schemas(client); } else if (0 == strcmp("force_fetch_schema", clp.cmd_type)) { force_fetch_schema(client); } else if (0 == strcmp("reload_conf", clp.cmd_type)) { reload_conf(clp.ini_fname, client); } else if (0 == strcmp("memory_watch", clp.cmd_type)) { memory_watch(client); } else if (0 == strcmp("memory_limit", clp.cmd_type)) { memory_limit(clp.memory_limit, clp.memtable_limit, client); } else if (0 == strcmp("priv_queue_conf", clp.cmd_type)) { priv_queue_conf(clp.priv_queue_conf, client); } else if (0 == strcmp("clear_active_memtable", clp.cmd_type)) { clear_active_memtable(client); } else if (0 == strcmp("get_last_frozen_version", clp.cmd_type)) { get_last_frozen_version(client); } else if (0 == strcmp("fetch_ups_stat_info", clp.cmd_type)) { fetch_ups_stat_info(client); } else if (0 == strcmp("get_bloomfilter", clp.cmd_type)) { get_bloomfilter(client, clp.timestamp); } else if (0 == strcmp("store_memtable", clp.cmd_type)) { store_memtable(client, clp.timestamp); } else if (0 == strcmp("erase_sstable", clp.cmd_type)) { erase_sstable(client); } else if (0 == strcmp("load_new_store", clp.cmd_type)) { load_new_store(client); } else if (0 == strcmp("reload_all_store", clp.cmd_type)) { reload_all_store(client); } else if (0 == strcmp("reload_store", clp.cmd_type)) { reload_store(client, clp.timestamp); } else if (0 == strcmp("umount_store", clp.cmd_type)) { umount_store(client, clp.ini_fname); } else if (0 == strcmp("force_report_frozen_version", clp.cmd_type)) { force_report_frozen_version(client); } else if (0 == strcmp("switch_commit_log", clp.cmd_type)) { switch_commit_log(client); } else if (0 == strcmp("get_table_time_stamp", clp.cmd_type)) { get_table_time_stamp(client, clp.timestamp); } else if (0 == strcmp("disable_memtable_checksum", clp.cmd_type)) { disable_memtable_checksum(client); } else if (0 == strcmp("enable_memtable_checksum", clp.cmd_type)) { enable_memtable_checksum(client); } else if (0 == strcmp("immediately_drop_memtable", clp.cmd_type)) { immediately_drop_memtable(client); } else if (0 == strcmp("delay_drop_memtable", clp.cmd_type)) { delay_drop_memtable(client); } else if (0 == strcmp("minor_load_bypass", clp.cmd_type)) { rc = minor_load_bypass(client); } else if (0 == strcmp("major_load_bypass", clp.cmd_type)) { rc = major_load_bypass(client); } else if(0 == strcmp("list_sessions", clp.cmd_type)) { client.list_sessions(timeout); } else if(0 == strcmp("kill_session", clp.cmd_type)) { client.kill_session(timeout, clp.session_id); } else if (0 == strcmp("change_log_level", clp.cmd_type)) { change_log_level(client, clp.log_level); } else if (0 == strcmp("get_slave_ups_info", clp.cmd_type)) { get_slave_ups_info(client); } else if (0 == strcmp("print_scanner", clp.cmd_type)) { print_scanner(clp.ini_fname); } else if (0 == strcmp("print_schema", clp.cmd_type)) { print_schema(clp.ini_fname); } else if (0 == strcmp("sql_query", clp.cmd_type)) { execute_sql(client, clp.sql_query); } else if (0 == strcmp("ups_show_sessions", clp.cmd_type)) { ups_show_sessions(client); } else if (0 == strcmp("ups_kill_session", clp.cmd_type)) { ups_kill_session(static_cast<uint32_t>(clp.session_id), client); } else { print_usage(); } if (!clp.quickly_exit) { client.destroy(); TBSYS_LOG(INFO, "ups_admin end=================================================="); return rc; } else { TBSYS_LOG(INFO, "ups_admin killed=================================================="); fflush(stdout); fflush(stderr); _exit(rc); } }
int main(int argc, char * const argv[]) { int i, ret; pthread_t threads[THREADS_NUM]; struct ubi_mkvol_request req; long long mem_limit; if (initial_check(argc, argv)) return 1; node = argv[1]; libubi = libubi_open(); if (libubi == NULL) { failed("libubi_open"); return 1; } if (ubi_get_dev_info(libubi, node, &dev_info)) { failed("ubi_get_dev_info"); goto close; } req.alignment = 1; mem_limit = memory_limit(); if (mem_limit && mem_limit < dev_info.avail_bytes) total_bytes = req.bytes = (mem_limit / dev_info.eb_size / THREADS_NUM) * dev_info.eb_size; else total_bytes = req.bytes = ((dev_info.avail_ebs - 3) / THREADS_NUM) * dev_info.eb_size; for (i = 0; i < THREADS_NUM; i++) { char name[100]; req.vol_id = i; sprintf(&name[0], TESTNAME":%d", i); req.name = &name[0]; req.vol_type = (i & 1) ? UBI_STATIC_VOLUME : UBI_DYNAMIC_VOLUME; if (ubi_mkvol(libubi, node, &req)) { failed("ubi_mkvol"); goto remove; } } /* Create one volume with static data to make WL work more */ req.vol_id = THREADS_NUM; req.name = TESTNAME ":static"; req.vol_type = UBI_DYNAMIC_VOLUME; req.bytes = 3*dev_info.eb_size; if (ubi_mkvol(libubi, node, &req)) { failed("ubi_mkvol"); goto remove; } for (i = 0; i < THREADS_NUM; i++) { ret = pthread_create(&threads[i], NULL, &the_thread, (void*)i); if (ret) { failed("pthread_create"); goto remove; } } for (i = 0; i < THREADS_NUM; i++) pthread_join(threads[i], NULL); for (i = 0; i <= THREADS_NUM; i++) { if (ubi_rmvol(libubi, node, i)) { failed("ubi_rmvol"); goto remove; } } libubi_close(libubi); return 0; remove: for (i = 0; i <= THREADS_NUM; i++) ubi_rmvol(libubi, node, i); close: libubi_close(libubi); return 1; }