int pm860x_page_reg_write(struct i2c_client *i2c, int reg, unsigned char data) { unsigned char zero; int ret; i2c_lock_adapter(i2c->adapter); read_device(i2c, 0xFA, 0, &zero); read_device(i2c, 0xFB, 0, &zero); read_device(i2c, 0xFF, 0, &zero); ret = write_device(i2c, reg, 1, &data); read_device(i2c, 0xFE, 0, &zero); read_device(i2c, 0xFC, 0, &zero); i2c_unlock_adapter(i2c->adapter); return ret; }
/******************************************************************** * reset_06 WS2300 by sending command 06 (Linux version) * * Input: device number of the already open serial port * * Returns: nothing, exits progrsm if failing to reset * ********************************************************************/ void reset_06(WEATHERSTATION serdevice) { unsigned char command = 0x06; unsigned char answer; int i; for (i = 0; i < 100; i++) { // Discard any garbage in the input buffer tcflush(serdevice, TCIFLUSH); write_device(serdevice, &command, 1); // Occasionally 0, then 2 is returned. If zero comes back, continue // reading as this is more efficient than sending an out-of sync // reset and letting the data reads restore synchronization. // Occasionally, multiple 2's are returned. Read with a fast timeout // until all data is exhausted, if we got a two back at all, we // consider it a success while (1 == read_device(serdevice, &answer, 1)) { if (answer == 2) { return; } } usleep(50000 * i); //we sleep longer and longer for each retry } fprintf(stderr, "\nCould not reset\n"); exit(EXIT_FAILURE); }
int pm860x_page_bulk_write(struct i2c_client *i2c, int reg, int count, unsigned char *buf) { unsigned char zero = 0; int ret; i2c_lock_adapter(i2c->adapter); read_device(i2c, 0xFA, 0, &zero); read_device(i2c, 0xFB, 0, &zero); read_device(i2c, 0xFF, 0, &zero); ret = write_device(i2c, reg, count, buf); read_device(i2c, 0xFE, 0, &zero); read_device(i2c, 0xFC, 0, &zero); i2c_unlock_adapter(i2c->adapter); i2c_unlock_adapter(i2c->adapter); return ret; }
int read_fan_value(const int fan, const char *device, int *value) { char device_name[LARGEST_DEVICE_NAME]; char output_value[LARGEST_DEVICE_NAME]; char full_name[LARGEST_DEVICE_NAME]; snprintf(device_name, LARGEST_DEVICE_NAME, device, fan); snprintf(full_name, LARGEST_DEVICE_NAME, "%s/%s", PWM_DIR,device_name); return read_device(full_name, value); }
int read_temp(const char *device, int *value) { char full_name[LARGEST_DEVICE_NAME + 1]; /* We set an impossible value to check for errors */ *value = BAD_TEMP; snprintf( full_name, LARGEST_DEVICE_NAME, "%s/temp1_input", device); return read_device(full_name, value); }
static inline thread_binding read_thread_binding(const char *value) { auto vec = pfq::split(value, "."); if (vec.size() < 2) throw std::runtime_error("read_thread_binding: parse error"); thread_binding t { std::stoi(vec[0]), std::stoi(vec[1]), { }}; for(size_t n = 2; n < vec.size(); n++) t.dev.push_back(read_device(vec[n].c_str())); return t; }
static GstFlowReturn gst_dvbsrc_create (GstPushSrc * element, GstBuffer ** buf) { gint buffer_size; GstFlowReturn retval = GST_FLOW_ERROR; GstDvbSrc *object; object = GST_DVBSRC (element); GST_LOG ("fd_dvr: %d", object->fd_dvr); //g_object_get(G_OBJECT(object), "blocksize", &buffer_size, NULL); buffer_size = DEFAULT_BUFFER_SIZE; /* device can not be tuned during read */ g_mutex_lock (object->tune_mutex); if (object->fd_dvr > -1) { /* --- Read TS from DVR device --- */ GST_DEBUG_OBJECT (object, "Reading from DVR device"); *buf = read_device (object->fd_dvr, object->adapter_number, object->frontend_number, buffer_size, object); if (*buf != NULL) { GstCaps *caps; retval = GST_FLOW_OK; caps = gst_pad_get_caps (GST_BASE_SRC_PAD (object)); gst_buffer_set_caps (*buf, caps); gst_caps_unref (caps); } else { GST_DEBUG_OBJECT (object, "Failed to read from device"); gst_element_post_message (GST_ELEMENT_CAST (object), gst_message_new_element (GST_OBJECT (object), gst_structure_empty_new ("dvb-read-failure"))); } if (object->stats_interval != 0 && ++object->stats_counter == object->stats_interval) { gst_dvbsrc_output_frontend_stats (object); object->stats_counter = 0; } } g_mutex_unlock (object->tune_mutex); return retval; }
// Return the front panel's Reset Button status int pal_get_rst_btn(uint8_t *status) { char path[64] = {0}; int val; sprintf(path, GPIO_VAL, GPIO_RST_BTN); if (read_device(path, &val)) { return -1; } if (val) { *status = 0x0; } else { *status = 0x1; } return 0; }
int pal_is_debug_card_prsnt(uint8_t *status) { int val; char path[64] = {0}; sprintf(path, GPIO_VAL, GPIO_DBG_CARD_PRSNT); if (read_device(path, &val)) { return -1; } // TODO: Logic is reversed until DVT board with h/w fix if (val == 0x0) { *status = 0; } else { *status = 1; } return 0; }
static twin_bool_t pboot_proc_client_sock(int sock, twin_file_op_t ops, void *closure) { struct device_context *dev_ctx = closure; uint8_t action; if (read_action(sock, &action)) goto out_err; if (action == DEV_ACTION_ADD_DEVICE) { if (!read_device(sock, dev_ctx)) goto out_err; } else if (action == DEV_ACTION_ADD_OPTION) { if (dev_ctx->device_idx == -1) { LOG("option, but no device has been sent?\n"); goto out_err; } if (!read_option(sock, dev_ctx)) goto out_err; } else if (action == DEV_ACTION_REMOVE_DEVICE) { char *dev_id = read_string(sock); if (!dev_id) goto out_err; LOG("remove device %s\n", dev_id); pboot_remove_device(dev_id); } else { LOG("unsupported action %d\n", action); goto out_err; } return TWIN_TRUE; out_err: close(sock); return TWIN_FALSE; }
int pal_is_server_prsnt(uint8_t slot_id, uint8_t *status) { int val; char path[64] = {0}; if (slot_id < 1 || slot_id > 4) { return -1; } sprintf(path, GPIO_VAL, gpio_prsnt[slot_id]); if (read_device(path, &val)) { return -1; } if (val == 0x0) { *status = 1; } else { *status = 0; } return 0; }
int pm860x_page_reg_read(struct i2c_client *i2c, int reg) { unsigned char zero = 0; unsigned char data; int ret; i2c_lock_adapter(i2c->adapter); read_device(i2c, 0xFA, 0, &zero); read_device(i2c, 0xFB, 0, &zero); read_device(i2c, 0xFF, 0, &zero); ret = read_device(i2c, reg, 1, &data); if (ret >= 0) ret = (int)data; read_device(i2c, 0xFE, 0, &zero); read_device(i2c, 0xFC, 0, &zero); i2c_unlock_adapter(i2c->adapter); return ret; }
int pm860x_page_set_bits(struct i2c_client *i2c, int reg, unsigned char mask, unsigned char data) { unsigned char zero; unsigned char value; int ret; i2c_lock_adapter(i2c->adapter); read_device(i2c, 0xFA, 0, &zero); read_device(i2c, 0xFB, 0, &zero); read_device(i2c, 0xFF, 0, &zero); ret = read_device(i2c, reg, 1, &value); if (ret < 0) goto out; value &= ~mask; value |= data; ret = write_device(i2c, reg, 1, &value); out: read_device(i2c, 0xFE, 0, &zero); read_device(i2c, 0xFC, 0, &zero); i2c_unlock_adapter(i2c->adapter); return ret; }
int execute(void) { long long tmp; int cmp; switch(opcode) { //add case 0x18: ra += load_mem(&memory[path],3); break; //and case 0x40: ra &= load_mem(&memory[path],3); break; //comp // = -> 0b001 // > -> 0b010 // < -> 0b100 // save status in register sw case 0x28: cmp = load_mem(&memory[path],3); if(ra==cmp) rsw = 0x1; else if (ra>cmp) rsw = 0x2; else if (ra<cmp) rsw = 0x4; else rsw = 0; break; //div case 0x24: ra /= load_mem(&memory[path],3); break; //j case 0x3C: rpc = path; break; //jeq case 0x30: if(rsw==0x1) rpc = path; break; //jgt case 0x34: if(rsw==0x2) rpc = path; break; //jlt case 0x38: if(rsw==0x4) rpc = path; break; //jsub case 0x48: rl = rpc; rpc = path; break; //lda case 0x00: ra = load_mem(&memory[path],3); break; //ldch case 0x50: ra = (ra&0xFFFF00) + load_mem(&memory[path], 1); break; //ldl case 0x08: rl = load_mem(&memory[path],3); break; //ldx case 0x04: rx = load_mem(&memory[path],3); break; //mul case 0x20: tmp = (long long) ra * load_mem(&memory[path],3); ra = (int) (0xFFFFFF & tmp); break; //or case 0x44: ra |= load_mem(&memory[path],3); break; //rsub case 0x4C: rpc = rl; break; //sta case 0x0C: //incomplete save_mem(ra, &memory[path], 3); break; //stch case 0x54: save_mem(ra, &memory[path], 1); break; //stl case 0x14: save_mem(rl, &memory[path], 3); break; //stsw case 0xE8: save_mem(rsw, &memory[path], 3); break; //stx case 0x10: save_mem(rx, &memory[path], 3); break; //sub case 0x1C: ra -= load_mem(&memory[path], 3); break; //tix case 0x2C: cmp = load_mem(&memory[path],3); rx++; if(rx==cmp) rsw = 0x1; else if (rx>cmp) rsw = 0x2; else if (rx<cmp) rsw = 0x4; else rsw = 0; break; //td case 0xE0: rsw = test_device(memory[path]); break; //rd case 0xD8: ra = (ra&0xFFFF00) + read_device(memory[path]); break; //wd case 0xDC: write_device(memory[path], (ra&0x0000FF)); break; //break case 0xFF: return 10; break; default: printf("CPU Error: Could not found opcode\n"); printf("rpc= %06X\n", rpc); return 11; break; } return 0; }
int main(int argc, char **argv) { int opt; char *device_str = NULL; /* No arguments */ if (argc == 1) { fprintf(stderr, syntax, argv[0]); return 1; } /* Process options */ while ((opt = getopt(argc, argv, "ld:aeg")) != -1) { switch (opt) { case 'l': action_list_devices = 1; break; case 'd': device_str = optarg; break; case 'a': dump_intermediate = 1; break; case 'v': verbose = 1; break; case 'g': debug_info = 1; break; default: fprintf(stderr, syntax, argv[0]); return 1; } } /* The only remaining argument should be the kernel to compile */ if (argc - optind > 1) { fprintf(stderr, syntax, argv[0]); return 1; } else if (argc - optind == 1) kernel_file_name = argv[optind]; if (!kernel_file_name && !action_list_devices) fatal("no kernel to compile"); /* Platform */ cl_int err; err = clGetPlatformIDs(1, &platform, NULL); if (err != CL_SUCCESS) fatal("cannot get OpenCL platform"); /* Get context */ cl_context_properties cprops[5]; cprops[0] = CL_CONTEXT_PLATFORM; cprops[1] = (cl_context_properties)platform; cprops[2] = CL_CONTEXT_OFFLINE_DEVICES_AMD; cprops[3] = (cl_context_properties) 1; cprops[4] = (cl_context_properties) NULL; context = clCreateContextFromType(cprops, CL_DEVICE_TYPE_ALL, NULL, NULL, &err); if (err != CL_SUCCESS) fatal("cannot create context"); /* Get device list from context */ err = clGetContextInfo(context, CL_CONTEXT_NUM_DEVICES, sizeof(num_devices), &num_devices, NULL); if (err != CL_SUCCESS) fatal("cannot get number of devices"); err = clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(devices), devices, NULL); if (err != CL_SUCCESS) fatal("cannot get list of devices"); /* Get selected device */ if (device_str) { device_id = read_device(device_str); device = devices[device_id]; } /* List available devices */ if (action_list_devices) main_list_devices(stdout); /* Compile list of kernels */ if (kernel_file_name) main_compile_kernel(); /* End program */ printf("\n"); return 0; }
int read_gpio_value(const int id, const char *device, int *value) { char full_name[LARGEST_DEVICE_NAME]; snprintf(full_name, LARGEST_DEVICE_NAME, device, id); return read_device(full_name, value); }
// Read the Front Panel Hand Switch and return the position int pal_get_hand_sw(uint8_t *pos) { char path[64] = {0}; int id1, id2, id4, id8; uint8_t loc; // Read 4 GPIOs to read the current position // id1: GPIOR2(138) // id2: GPIOR3(139) // id4: GPIOR4(140) // id8: GPIOR5(141) // Read ID1 sprintf(path, GPIO_VAL, GPIO_HAND_SW_ID1); if (read_device(path, &id1)) { return -1; } // Read ID2 sprintf(path, GPIO_VAL, GPIO_HAND_SW_ID2); if (read_device(path, &id2)) { return -1; } // Read ID4 sprintf(path, GPIO_VAL, GPIO_HAND_SW_ID4); if (read_device(path, &id4)) { return -1; } // Read ID8 sprintf(path, GPIO_VAL, GPIO_HAND_SW_ID8); if (read_device(path, &id8)) { return -1; } loc = ((id8 << 3) | (id4 << 2) | (id2 << 1) | (id1)); switch(loc) { case 1: case 6: *pos = HAND_SW_SERVER1; break; case 2: case 7: *pos = HAND_SW_SERVER2; break; case 3: case 8: *pos = HAND_SW_SERVER3; break; case 4: case 9: *pos = HAND_SW_SERVER4; break; default: *pos = HAND_SW_BMC; break; } return 0; }