void Space::save_motor(uint8_t m, int32_t &addr) { // {{{ write_16(addr, motor[m]->step_pin.write()); write_16(addr, motor[m]->dir_pin.write()); write_16(addr, motor[m]->enable_pin.write()); write_16(addr, motor[m]->limit_min_pin.write()); write_16(addr, motor[m]->limit_max_pin.write()); write_16(addr, motor[m]->sense_pin.write()); write_float(addr, motor[m]->steps_per_unit); write_8(addr, motor[m]->max_steps); write_float(addr, motor[m]->home_pos); write_float(addr, motor[m]->limit_v); write_float(addr, motor[m]->limit_a); write_8(addr, motor[m]->home_order); } // }}}
static void esave(Space *s, int32_t &addr) { write_8(addr, s->num_axes); for (int a = 0; a < s->num_axes; ++a) { for (int o = 0; o < 3; ++o) write_float(addr, EADATA(s, a).offset[o]); } }
void write_float(int32_t &address, double data) { ReadFloat d; d.f = data; for (uint8_t t = 0; t < sizeof(double); ++t) write_8(address, d.b[t]); }
void OSD_EEPROM::_write(uint16_t addr, uint8_t val){ uint8_t cv = _read(addr); if(cv == val) return; // already is if( /* we can write - there is no '0' where we need '1' */ (~cv & val)==0 ){ FLASH_Unlock_dis(); write_8(ee_ptr, val); // just overwrite last value goto done; } if(val != 0xFF){ // the only way to write FF is to clear all - but OSD don't writes it for(uint8_t i=0; i<PAGE_SIZE/EEPROM_SIZE; i++){ // look 0xFF uint32_t ea = EEPROM_PAGE + i*EEPROM_SIZE + addr; cv = read_8(ea); if(cv == 0xFF) { // empty FLASH_Unlock_dis(); write_8(ea, val); goto done; } } } // no empty slots - so need to erase page // 1st - erase page. power loss here cause data loss! In execution time CPU is frozen! printf("\nEEprom_OSD erase page %d\n ", (uint16_t)((EEPROM_PAGE & 0x00ffffff) / 0x4000) ); // clear high byte of address and count 16K blocks FLASH_Unlock_dis(); erasePageByAddress(EEPROM_PAGE); // 2rd write data back to the beginning of Flash page for(uint16_t i=0;i<EEPROM_SIZE; i++){ write_8(EEPROM_PAGE+i, data[i]); } done: FLASH_Lock_check(); }
void diff_write_commit(const char* zone, uint32_t old_serial, uint32_t new_serial, uint16_t id, uint32_t num_parts, uint8_t commit, const char* log_str, nsd_options_t* opt) { const char* filename = opt->difffile; struct timeval tv; FILE *df; uint32_t len; if (gettimeofday(&tv, NULL) != 0) { log_msg(LOG_ERR, "could not set timestamp for %s: %s", filename, strerror(errno)); return; } df = fopen(filename, "a"); if(!df) { log_msg(LOG_ERR, "could not open file %s for append: %s", filename, strerror(errno)); return; } len = strlen(zone) + sizeof(len) + sizeof(old_serial) + sizeof(new_serial) + sizeof(id) + sizeof(num_parts) + sizeof(commit) + strlen(log_str) + sizeof(len); if(!write_32(df, DIFF_PART_SURE) || !write_32(df, (uint32_t) tv.tv_sec) || !write_32(df, (uint32_t) tv.tv_usec) || !write_32(df, len) || !write_str(df, zone) || !write_32(df, old_serial) || !write_32(df, new_serial) || !write_16(df, id) || !write_32(df, num_parts) || !write_8(df, commit) || !write_str(df, log_str) || !write_32(df, len)) { log_msg(LOG_ERR, "could not write to file %s: %s", filename, strerror(errno)); } fflush(df); fclose(df); }
void globals_save(int32_t &addr) { write_8(addr, QUEUE_LENGTH); write_8(addr, NUM_PINS); write_8(addr, num_temps); write_8(addr, num_gpios); write_16(addr, led_pin.write()); write_16(addr, stop_pin.write()); write_16(addr, probe_pin.write()); write_16(addr, spiss_pin.write()); write_16(addr, timeout); write_16(addr, bed_id); write_16(addr, fan_id); write_16(addr, spindle_id); write_float(addr, feedrate); write_float(addr, max_deviation); write_float(addr, max_v); write_8(addr, current_extruder); write_float(addr, targetx); write_float(addr, targety); write_float(addr, zoffset); write_8(addr, store_adc != NULL); }
Buffer::Pointer Buffer::write(uint8_t in_value) throw(KafkaError) { write_8(&in_value); return shared_from_this(); }
void Space::save_axis(uint8_t a, int32_t &addr) { // {{{ write_float(addr, axis[a]->park); write_8(addr, axis[a]->park_order); write_float(addr, axis[a]->min_pos); write_float(addr, axis[a]->max_pos); } // }}}
void Space::save_info(int32_t &addr) { // {{{ write_8(addr, type); space_types[type].save(this, addr); } // }}}
static void save(Space *s, int32_t &addr) { write_8(addr, s->num_axes); }
void write_16(int32_t &address, int16_t data) { write_8(address, data & 0xff); write_8(address, (data >> 8) & 0xff); }
void sf240320_set_page(uint16_t start, uint16_t end) { write_8(true, 0x2B); write_8(false, start); write_8(false, end); }
void sf240320_set_column(uint16_t start, uint16_t end) { write_8(true, 0x2A); write_8(false, start); write_8(false, end); }
static int relocate_rela(image_t *rootImage, image_t *image, Elf32_Rela *rel, int rel_len, SymbolLookupCache* cache) { int i; addr_t S; addr_t final_val; # define P ((addr_t *)(image->regions[0].delta + rel[i].r_offset)) //# define A (*(P)) #define A ((addr_t)rel[i].r_addend) # define B (image->regions[0].delta) for (i = 0; i * (int)sizeof(Elf32_Rel) < rel_len; i++) { unsigned type = ELF32_R_TYPE(rel[i].r_info); switch (type) { case R_68K_32: case R_68K_16: case R_68K_8: case R_68K_PC32: case R_68K_PC16: case R_68K_PC8: case R_68K_GLOB_DAT: case R_68K_JMP_SLOT: { Elf32_Sym *sym; status_t status; sym = SYMBOL(image, ELF32_R_SYM(rel[i].r_info)); status = resolve_symbol(rootImage, image, sym, cache, &S); if (status < B_OK) { TRACE(("resolve symbol \"%s\" returned: %ld\n", SYMNAME(image, sym), status)); printf("resolve symbol \"%s\" returned: %ld\n", SYMNAME(image, sym), status); return status; } } } switch (type) { case R_68K_NONE: continue; case R_68K_32: write_32(P, S + A); break; case R_68K_16: if (write_16_check(P, S + A)) break; TRACE(("R_68K_16 overflow\n")); return B_BAD_DATA; case R_68K_8: if (write_8_check(P, S + A)) break; TRACE(("R_68K_8 overflow\n")); return B_BAD_DATA; case R_68K_PC32: write_32(P, (S + A - (addr_t)P)); break; #if 0 case R_68K_PC16: if (write_16_check(P, (S + A - P))) break; TRACE(("R_68K_PC16 overflow\n")); return B_BAD_DATA; case R_68K_PC8: if (write_8(P, (S + A - P))) break; TRACE(("R_68K_PC8 overflow\n")); return B_BAD_DATA; case R_68K_GOT32: REQUIRE_GOT; write_32(P, (G + A - P)); break; case R_68K_GOT16: REQUIRE_GOT; if (write_16_check(P, (G + A - P))) break; TRACE(("R_68K_GOT16 overflow\n")); return B_BAD_DATA; case R_68K_GOT8: REQUIRE_GOT; if (write_8_check(P, (G + A - P))) break; TRACE(("R_68K_GOT8 overflow\n")); return B_BAD_DATA; case R_68K_GOT32O: REQUIRE_GOT; write_32(P, (G + A)); break; case R_68K_GOT16O: REQUIRE_GOT; if (write_16_check(P, (G + A))) break; TRACE(("R_68K_GOT16 overflow\n")); return B_BAD_DATA; case R_68K_GOT8O: REQUIRE_GOT; if (write_8_check(P, (G + A))) break; TRACE(("R_68K_GOT8 overflow\n")); return B_BAD_DATA; case R_68K_PLT32: REQUIRE_PLT; write_32(P, (L + A - P)); break; case R_68K_PLT16: REQUIRE_PLT; if (write_16_check(P, (L + A - P))) break; TRACE(("R_68K_PLT16 overflow\n")); return B_BAD_DATA; case R_68K_PLT8: REQUIRE_PLT; if (write_8_check(P, (L + A - P))) break; TRACE(("R_68K_PLT8 overflow\n")); return B_BAD_DATA; case R_68K_PLT32O: REQUIRE_PLT; write_32(P, (L + A)); break; case R_68K_PLT16O: REQUIRE_PLT; if (write_16_check(P, (L + A))) break; TRACE(("R_68K_PLT16O overflow\n")); return B_BAD_DATA; case R_68K_PLT8O: REQUIRE_PLT; if (write_8_check(P, (L + A))) break; TRACE(("R_68K_PLT8O overflow\n")); return B_BAD_DATA; case R_386_GOT32: final_val = G + A; break; case R_386_PLT32: final_val = L + A - (addr_t)P; break; #endif case R_68K_COPY: /* what ? */ continue; case R_68K_GLOB_DAT: write_32(P, S/* + A*/); break; case R_68K_JMP_SLOT: //XXX ? write_32(P, (G + A)); write_32(P, S); break; #if 0 case R_386_JMP_SLOT: write_32(P, S); break; #endif case R_68K_RELATIVE: write_32(P, B + A); break; #if 0 case R_386_GOTOFF: final_val = S + A - GOT; break; case R_386_GOTPC: final_val = GOT + A - P; break; #endif default: TRACE(("unhandled relocation type %d\n", ELF32_R_TYPE(rel[i].r_info))); return B_NOT_ALLOWED; } *P = final_val; } # undef P # undef A # undef B return B_NO_ERROR; }
int arch_elf_relocate_rela(struct elf_image_info *image, struct elf_image_info *resolve_image, struct Elf32_Rela *rel, int rel_len) #endif { int i; struct Elf32_Sym *sym; int vlErr; addr_t S = 0; // symbol address addr_t R = 0; // section relative symbol address addr_t G = 0; // GOT address addr_t L = 0; // PLT address #define P ((addr_t)(image->text_region.delta + rel[i].r_offset)) #define A ((addr_t)rel[i].r_addend) #define B (image->text_region.delta) // TODO: Get the GOT address! #define REQUIRE_GOT \ if (G == 0) { \ dprintf("arch_elf_relocate_rela(): Failed to get GOT address!\n"); \ return B_ERROR; \ } // TODO: Get the PLT address! #define REQUIRE_PLT \ if (L == 0) { \ dprintf("arch_elf_relocate_rela(): Failed to get PLT address!\n"); \ return B_ERROR; \ } for (i = 0; i * (int)sizeof(struct Elf32_Rela) < rel_len; i++) { #if CHATTY dprintf("looking at rel type %d, offset 0x%lx, sym 0x%lx, addend 0x%lx\n", ELF32_R_TYPE(rel[i].r_info), rel[i].r_offset, ELF32_R_SYM(rel[i].r_info), rel[i].r_addend); #endif switch (ELF32_R_TYPE(rel[i].r_info)) { case R_68K_32: case R_68K_16: case R_68K_8: case R_68K_PC32: case R_68K_PC16: case R_68K_PC8: case R_68K_GLOB_DAT: case R_68K_JMP_SLOT: sym = SYMBOL(image, ELF32_R_SYM(rel[i].r_info)); #ifdef _BOOT_MODE vlErr = boot_elf_resolve_symbol(image, sym, &S); #else vlErr = elf_resolve_symbol(image, sym, resolve_image, &S); #endif if (vlErr < 0) { dprintf("%s(): Failed to relocate " "entry index %d, rel type %d, offset 0x%lx, sym 0x%lx, " "addend 0x%lx\n", __FUNCTION__, i, ELF32_R_TYPE(rel[i].r_info), rel[i].r_offset, ELF32_R_SYM(rel[i].r_info), rel[i].r_addend); return vlErr; } break; } switch (ELF32_R_TYPE(rel[i].r_info)) { case R_68K_NONE: break; case R_68K_COPY: // TODO: Implement! dprintf("arch_elf_relocate_rela(): R_68K_COPY not yet " "supported!\n"); return B_ERROR; case R_68K_32: case R_68K_GLOB_DAT: write_32(P, S + A); break; case R_68K_16: if (write_16_check(P, S + A)) break; dprintf("R_68K_16 overflow\n"); return B_BAD_DATA; case R_68K_8: if (write_8_check(P, S + A)) break; dprintf("R_68K_8 overflow\n"); return B_BAD_DATA; case R_68K_PC32: write_32(P, (S + A - P)); break; case R_68K_PC16: if (write_16_check(P, (S + A - P))) break; dprintf("R_68K_PC16 overflow\n"); return B_BAD_DATA; case R_68K_PC8: if (write_8(P, (S + A - P))) break; dprintf("R_68K_PC8 overflow\n"); return B_BAD_DATA; case R_68K_GOT32: REQUIRE_GOT; write_32(P, (G + A - P)); break; case R_68K_GOT16: REQUIRE_GOT; if (write_16_check(P, (G + A - P))) break; dprintf("R_68K_GOT16 overflow\n"); return B_BAD_DATA; case R_68K_GOT8: REQUIRE_GOT; if (write_8_check(P, (G + A - P))) break; dprintf("R_68K_GOT8 overflow\n"); return B_BAD_DATA; case R_68K_GOT32O: REQUIRE_GOT; write_32(P, (G + A)); break; case R_68K_GOT16O: REQUIRE_GOT; if (write_16_check(P, (G + A))) break; dprintf("R_68K_GOT16 overflow\n"); return B_BAD_DATA; case R_68K_GOT8O: REQUIRE_GOT; if (write_8_check(P, (G + A))) break; dprintf("R_68K_GOT8 overflow\n"); return B_BAD_DATA; case R_68K_JMP_SLOT: write_32(P, (G + A)); break; case R_68K_RELATIVE: write_32(P, B + A); break; case R_68K_PLT32: REQUIRE_PLT; write_32(P, (L + A - P)); break; case R_68K_PLT16: REQUIRE_PLT; if (write_16_check(P, (L + A - P))) break; dprintf("R_68K_PLT16 overflow\n"); return B_BAD_DATA; case R_68K_PLT8: REQUIRE_PLT; if (write_8_check(P, (L + A - P))) break; dprintf("R_68K_PLT8 overflow\n"); return B_BAD_DATA; case R_68K_PLT32O: REQUIRE_PLT; write_32(P, (L + A)); break; case R_68K_PLT16O: REQUIRE_PLT; if (write_16_check(P, (L + A))) break; dprintf("R_68K_PLT16O overflow\n"); return B_BAD_DATA; case R_68K_PLT8O: REQUIRE_PLT; if (write_8_check(P, (L + A))) break; dprintf("R_68K_PLT8O overflow\n"); return B_BAD_DATA; default: dprintf("arch_elf_relocate_rela: unhandled relocation type %d\n", ELF32_R_TYPE(rel[i].r_info)); return B_ERROR; } } return B_NO_ERROR; }
extern int output_flv(struct mp4_context_t const* mp4_context, unsigned int* trak_sample_start, unsigned int* trak_sample_end, struct bucket_t** buckets, struct mp4_split_options_t* options) { struct moov_t* moov = mp4_context->moov; unsigned int track = 0; for(track = 0; track != moov->tracks_; ++track) { struct trak_t* trak = moov->traks_[track]; struct stsd_t const* stsd = trak->mdia_->minf_->stbl_->stsd_; struct sample_entry_t const* sample_entry = &stsd->sample_entries_[0]; unsigned int start_sample = trak_sample_start[track]; unsigned int end_sample = trak_sample_end[track]; unsigned int s; if(trak->mdia_->hdlr_->handler_type_ != FOURCC('v', 'i', 'd', 'e')) continue; if(trak->mdia_->hdlr_->handler_type_ == FOURCC('v', 'i', 'd', 'e')) { unsigned char* buffer = (unsigned char*)malloc(1 + 1 + 3 + sample_entry->codec_private_data_length_); unsigned char* p = buffer; p = write_8(p, 0x17); p = write_8(p, RTMP_AVC_SEQUENCE_HEADER); p = write_24(p, 0); memcpy(p, sample_entry->codec_private_data_, sample_entry->codec_private_data_length_); p += sample_entry->codec_private_data_length_; bucket_insert_tail(buckets, bucket_init_memory(buffer, p - buffer)); free(buffer); } else if(trak->mdia_->hdlr_->handler_type_ == FOURCC('s', 'o', 'u', 'n')) { unsigned char* buffer = (unsigned char*)malloc(1 + 1 + sample_entry->codec_private_data_length_); unsigned char* p = buffer; p = write_8(p, 0xaf); p = write_8(p, RTMP_AAC_SEQUENCE_HEADER); memcpy(p, sample_entry->codec_private_data_, sample_entry->codec_private_data_length_); p += sample_entry->codec_private_data_length_; bucket_insert_tail(buckets, bucket_init_memory(buffer, p - buffer)); free(buffer); } else { continue; } for(s = start_sample; s != end_sample; ++s) { uint64_t sample_pos = trak->samples_[s].pos_; unsigned int sample_size = trak->samples_[s].size_; int cto = trak->samples_[s].cto_; // FLV uses a fixed 1000 timescale unsigned int composition_time = (unsigned int) (trak_time_to_moov_time(cto, 1000, trak->mdia_->mdhd_->timescale_)); MP4_INFO( "frame=%u pts=%u offset=%llu size=%u\n", s, composition_time, sample_pos, sample_size); if(trak->mdia_->hdlr_->handler_type_ == FOURCC('v', 'i', 'd', 'e')) { // if(is_avc) { // VIDEODATA unsigned char header[5]; unsigned int is_keyframe = trak->samples_[s].is_ss_; unsigned int codec_id = 7; // AVC write_8(header, ((is_keyframe ? 1 : 2) << 4) + codec_id); write_8(header + 1, RTMP_AVC_NALU); write_24(header + 2, composition_time); bucket_insert_tail(buckets, bucket_init_memory(header, 5)); bucket_insert_tail(buckets, bucket_init_file(sample_pos, sample_size)); } } else { // AUDIODATA unsigned char header[2]; write_8(header, 0xaf); write_8(header + 1, RTMP_AAC_RAW); // AACAUDIODATA bucket_insert_tail(buckets, bucket_init_memory(header, 2)); bucket_insert_tail(buckets, bucket_init_file(sample_pos, sample_size)); } } } return 1; }
static void do_set(int fd, int argc, const char *argv[]) { int x, y, w, h; int bpp; if (argc != 6) usage(); screen = mmap(NULL, mem_size, PROT_WRITE, MAP_SHARED, fd, 0); if (screen == MAP_FAILED) { printf("Can't mmap %s\n", argv[1]); perror("mmap"); usage(); } do_ioctl(fd, IOCTRL_GET_LCD_BPP, &bpp); if (bpp == 8) bytes_per_pixel = 1; else if (bpp == 16) bytes_per_pixel = 2; else if (bpp == 24) bytes_per_pixel = 3; else if (bpp == 32) bytes_per_pixel = 4; do_ioctl(fd, IOCTRL_GET_LCD_WIDTH, &screen_w); do_ioctl(fd, IOCTRL_GET_LCD_HEIGHT, &screen_h); printf("Screen is %lux%lu, %u bits per pixel\n", screen_w, screen_h, bpp); do_ioctl(fd, IOCTRL_DISPLAY_ENABLE, NULL); do_ioctl(fd, IOCTRL_CLEAR_LCD, NULL); x = strtoul(argv[1], NULL, 0); y = strtoul(argv[2], NULL, 0); w = strtoul(argv[3], NULL, 0); h = strtoul(argv[4], NULL, 0); val = strtoul(argv[5], NULL, 0); if ( y * screen_w + x * bytes_per_pixel > mem_size ) { printf("Would write outside of memory\n"); usage(); } switch (bytes_per_pixel) { case 1: write_8(w, h, x, y); break; case 2: write_16(w, h, x, y); break; case 3: write_24(w, h, x, y); break; case 4: write_32(w, h, x, y); break; default: printf("Illegal byte-per-pixel, bpp %d\n", bpp); usage(); break; } do_ioctl(fd, IOCTRL_UPDATE_NOW, NULL); msync(screen, mem_size, MS_SYNC); munmap(screen, mem_size); }