void clear_line(uint8_t line){ shift_cursor_to(line*LINE_LENGTH+15); uint8_t i; for(i=0; i<LINE_LENGTH-1; ++i){ //LINE_LENGTH-1, bo w ostatniej iteracji nie chce przesuwac kursora dwukrotnie data_write(' '); shift_cursor(SH_LEFT); shift_cursor(SH_LEFT); } data_write(' '); shift_cursor(SH_LEFT); }
static void write_received_packet( volatile struct mstp_port_struct_t *mstp_port) { uint32_t ts_sec; /* timestamp seconds */ uint32_t ts_usec; /* timestamp microseconds */ uint32_t incl_len; /* number of octets of packet saved in file */ uint32_t orig_len; /* actual length of packet */ uint8_t header[8]; /* MS/TP header */ struct timeval tv; size_t max_data = 0; if (pFile) { gettimeofday(&tv, NULL); ts_sec = tv.tv_sec; ts_usec = tv.tv_usec; if ((mstp_port->ReceivedValidFrame) || (mstp_port->ReceivedValidFrameNotForUs)) { packet_statistics(&tv, mstp_port); } (void) data_write(&ts_sec, sizeof(ts_sec), 1); (void) data_write(&ts_usec, sizeof(ts_usec), 1); if (mstp_port->DataLength) { max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength); incl_len = orig_len = 8 + max_data + 2; } else { incl_len = orig_len = 8; } (void) data_write(&incl_len, sizeof(incl_len), 1); (void) data_write(&orig_len, sizeof(orig_len), 1); header[0] = 0x55; header[1] = 0xFF; header[2] = mstp_port->FrameType; header[3] = mstp_port->DestinationAddress; header[4] = mstp_port->SourceAddress; header[5] = HI_BYTE(mstp_port->DataLength); header[6] = LO_BYTE(mstp_port->DataLength); header[7] = mstp_port->HeaderCRCActual; (void) data_write(header, sizeof(header), 1); if (mstp_port->DataLength) { (void) data_write(mstp_port->InputBuffer, max_data, 1); (void) data_write((char *) &mstp_port->DataCRCActualMSB, 1, 1); (void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1); } } else { fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n", Capture_Filename, strerror(errno)); } }
static ICACHE_FLASH_ATTR void* data_write_auto(config_t* config, void* start, uint16_t length) { if (start == NULL) return NULL; void* address = (void*) (1 + config->position); // skip (pretty sure) unwriteable bytes uint32_t offset = config->address + sizeof(config->head) + config->position; if ((offset & 3) != 0) { address = (void*) (((uint32_t) address) + 4 - (offset & 3)); } data_write(config, address, start, length); config->position += length; return address; }
//****************************************************************** // Write a string on LCD //****************************************************************** void string_write(unsigned char idx) { unsigned int i=0; unsigned int z=0; char b; while (i<16) { z = idx*16; z = z + i; b = string[z]; data_write(b); Delay10TCYx(50); i++; }//end while }//end string_write
void run(void) { uint8_t c; int q=0; int st=0; int it=0; cmd_t *cptr; while(1) { it++; c = data_read(); if(p_cache[q]==NULL) { st=1; break; } cptr=p_cache[q]; while(cmd_qF(*cptr)==q && cmd_cF(*cptr)!=c)cptr++; if(cmd_qF(*cptr)==q) { q=cmd_qT(*cptr); data_write(cmd_cT(*cptr)); if(debug) printf("Q%02i -> Q%02i; %c -> %c\n", cmd_qF(*cptr),cmd_qT(*cptr), cmd_cF(*cptr), cmd_cT(*cptr)); if(cmd_act(*cptr)==CMD_ACT_S) break; else if(cmd_act(*cptr)==CMD_ACT_L) data.pos--; else if(cmd_act(*cptr)==CMD_ACT_R) data.pos++; } else { st=1; break; } } if(st==1) printf("ERROR: No command. Q = %i, C = `%c`, pos = %i\n", q, c, data.pos); else printf("Done.\n"); printf("Count of iterations:%i\n", it); }
static int write_suspend_image(void) { int error; init_header(); if ((error = data_write())) goto FreeData; if ((error = write_pagedir())) goto FreePagedir; if ((error = close_swap())) goto FreePagedir; Done: return error; FreePagedir: free_pagedir_entries(); FreeData: data_free(); goto Done; }
void char_write(char mychar) { chars_written++; if ((chars_written==17)||(mychar=='\n')) { if (line_num==1) { set_ddram_address(0x40); line_num = 2; chars_written = 0; } else if (line_num==2) { lcd_init(); } } if (mychar!='\n') data_write((uint8_t)mychar); }
static size_t sys_platform_stdout_write(void *data, size_t count) { char *cdata = data; #if defined(SEL4_DEBUG_KERNEL) && defined(CONFIG_REFOS_SYS_FORCE_DEBUGPUTCHAR) for (size_t i = 0; i < count; i++) { seL4_DebugPutChar(cdata[i]); } #else if (refosIOState.stdioWriteOverride != NULL) { /* Use overridden write function. */ return refosIOState.stdioWriteOverride(data, count); } /* Use serial dataspace on Console server. */ if (refosIOState.stdioDataspace && refosIOState.stdioSession.serverSession) { refosio_internal_save_IPC_buffer(); for (size_t i = 0; i < count;) { int c = MIN(REFOS_DEFAULT_DSPACE_IPC_MAXLEN, count - i); int n = data_write(refosIOState.stdioSession.serverSession, refosIOState.stdioDataspace, 0, &cdata[i], c); if (!n) { /* An error occured. */ refosio_internal_restore_IPC_buffer(); return i; } i += n; } refosio_internal_restore_IPC_buffer(); } #endif return count; }
int main(int argc, char **argv) { int i; struct stat st; #ifdef HAVE_REALPATH char rpath[PATH_MAX], rpath2[PATH_MAX]; #endif setlocale(LC_NUMERIC, "C"); ecore_app_no_system_modules(); if (!eina_init()) return -1; _edje_cc_log_dom = eina_log_domain_register ("edje_cc", EDJE_CC_DEFAULT_LOG_COLOR); if (_edje_cc_log_dom < 0) { EINA_LOG_ERR("Enable to create a log domain."); exit(-1); } if (!eina_log_domain_level_check(_edje_cc_log_dom, EINA_LOG_LEVEL_WARN)) eina_log_domain_level_set("edje_cc", EINA_LOG_LEVEL_WARN); progname = ecore_file_file_get(argv[0]); eina_log_print_cb_set(_edje_cc_log_cb, NULL); tmp_dir = getenv("TMPDIR"); img_dirs = eina_list_append(img_dirs, "."); /* add defines to epp so edc files can detect edje_cc version */ defines = eina_list_append(defines, mem_strdup("-DEDJE_VERSION_12=12")); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h")) { main_help(); exit(0); } else if ((!strcmp(argv[i], "-V")) || (!strcmp(argv[i], "--version"))) { printf("Version: %s\n", PACKAGE_VERSION); exit(0); } else if (!strcmp(argv[i], "-v")) { eina_log_domain_level_set("edje_cc", EINA_LOG_LEVEL_INFO); } else if (!strcmp(argv[i], "-no-lossy")) { no_lossy = 1; } else if (!strcmp(argv[i], "-no-comp")) { no_comp = 1; } else if (!strcmp(argv[i], "-no-raw")) { no_raw = 1; } else if (!strcmp(argv[i], "-no-etc1")) { no_etc1 = 1; } else if (!strcmp(argv[i], "-no-etc2")) { no_etc2 = 1; } else if (!strcmp(argv[i], "-no-save")) { no_save = 1; } else if ((!strcmp(argv[i], "-id") || !strcmp(argv[i], "--image_dir")) && (i < (argc - 1))) { i++; img_dirs = eina_list_append(img_dirs, argv[i]); } else if ((!strcmp(argv[i], "-fd") || !strcmp(argv[i], "--font_dir")) && (i < (argc - 1))) { i++; fnt_dirs = eina_list_append(fnt_dirs, argv[i]); } else if ((!strcmp(argv[i], "-sd") || !strcmp(argv[i], "--sound_dir")) && (i < (argc - 1))) { i++; snd_dirs = eina_list_append(snd_dirs, argv[i]); } else if ((!strcmp(argv[i], "-md") || !strcmp(argv[i], "--mo_dir")) && (i < (argc - 1))) { i++; mo_dirs = eina_list_append(mo_dirs, argv[i]); } else if ((!strcmp(argv[i], "-vd") || !strcmp(argv[i], "--vibration_dir")) && (i < (argc - 1))) { i++; vibration_dirs = eina_list_append(vibration_dirs, argv[i]); } else if ((!strcmp(argv[i], "-dd") || !strcmp(argv[i], "--data_dir")) && (i < (argc - 1))) { i++; data_dirs = eina_list_append(data_dirs, argv[i]); } else if ((!strcmp(argv[i], "-td") || !strcmp(argv[i], "--tmp_dir")) && (i < (argc - 1))) { i++; if (!tmp_dir) tmp_dir = argv[i]; } else if ((!strcmp(argv[i], "-l") || !strcmp(argv[i], "--license")) && (i < (argc - 1))) { i++; if (!license) license = argv[i]; else licenses = eina_list_append(licenses, argv[i]); } else if ((!strcmp(argv[i], "-a") || !strcmp(argv[i], "--authors")) && (i < (argc - 1))) { i++; if (!authors) authors = argv[i]; } else if ((!strcmp(argv[i], "-min-quality")) && (i < (argc - 1))) { i++; min_quality = atoi(argv[i]); if (min_quality < 0) min_quality = 0; if (min_quality > 100) min_quality = 100; } else if ((!strcmp(argv[i], "-max-quality")) && (i < (argc - 1))) { i++; max_quality = atoi(argv[i]); if (max_quality < 0) max_quality = 0; if (max_quality > 100) max_quality = 100; } else if (!strcmp(argv[i], "-fastcomp")) { compress_mode = EET_COMPRESSION_SUPERFAST; } else if (!strcmp(argv[i], "-fastdecomp")) { compress_mode = EET_COMPRESSION_VERYFAST; } else if (!strcmp(argv[i], "-threads")) { threads = 1; } else if (!strcmp(argv[i], "-nothreads")) { threads = 0; } else if (!strncmp(argv[i], "-D", 2)) { defines = eina_list_append(defines, mem_strdup(argv[i])); } else if ((!strcmp(argv[i], "-o")) && (i < (argc - 1))) { i++; file_out = argv[i]; } else if ((!strcmp(argv[i], "-w")) && (i < (argc - 1))) { i++; watchfile = argv[i]; unlink(watchfile); } else if (!strcmp(argv[i], "-annotate")) { annotate = 1; } else if ((!strcmp(argv[i], "-deps")) && (i < (argc - 1))) { i++; depfile = argv[i]; unlink(depfile); } else if (!file_in) file_in = argv[i]; else if (!file_out) file_out = argv[i]; } if (!file_in) { ERR("no input file specified."); main_help(); exit(-1); } pfx = eina_prefix_new(argv[0], /* argv[0] value (optional) */ main, /* an optional symbol to check path of */ "EDJE", /* env var prefix to use (XXX_PREFIX, XXX_BIN_DIR etc. */ "edje", /* dir to add after "share" (PREFIX/share/DIRNAME) */ "include/edje.inc", /* a magic file to check for in PREFIX/share/DIRNAME for success */ PACKAGE_BIN_DIR, /* package bin dir @ compile time */ PACKAGE_LIB_DIR, /* package lib dir @ compile time */ PACKAGE_DATA_DIR, /* package data dir @ compile time */ PACKAGE_DATA_DIR /* if locale needed use LOCALE_DIR */ ); /* check whether file_in exists */ #ifdef HAVE_REALPATH if (!realpath(file_in, rpath) || stat(rpath, &st) || !S_ISREG(st.st_mode)) #else if (stat(file_in, &st) || !S_ISREG(st.st_mode)) #endif { ERR("file not found: %s.", file_in); main_help(); exit(-1); } if (!file_out) { char *suffix; if ((suffix = strstr(file_in,".edc")) && (suffix[4] == 0)) { file_out = strdup(file_in); if (file_out) { suffix = strstr(file_out,".edc"); strcpy(suffix,".edj"); } } } if (!file_out) { ERR("no output file specified."); main_help(); exit(-1); } #ifdef HAVE_REALPATH if (realpath(file_out, rpath2) && !strcmp (rpath, rpath2)) #else if (!strcmp (file_in, file_out)) #endif { ERR("input file equals output file."); main_help(); exit(-1); } using_file(file_in, 'E'); if (annotate) using_file(file_out, 'O'); if (!edje_init()) exit(-1); edje_file = mem_alloc(SZ(Edje_File)); edje_file->compiler = strdup("edje_cc"); edje_file->version = EDJE_FILE_VERSION; edje_file->minor = EDJE_FILE_MINOR; edje_file->feature_ver = 1; /* increment this every time we add a field * or feature to the edje file format that * does not load nicely as a NULL or 0 value * and needs a special fallback initialization */ edje_file->base_scale = FROM_INT(1); source_edd(); source_fetch(); data_setup(); compile(); reorder_parts(); data_process_scripts(); data_process_lookups(); data_process_script_lookups(); data_write(); eina_prefix_free(pfx); pfx = NULL; edje_shutdown(); eina_log_domain_unregister(_edje_cc_log_dom); eina_shutdown(); return 0; }
/******************** * write_mc_parts *******************/ int write_mc_parts(FILE *fp, mc_evt_t *mc_evt){ int i,ret; static itape_header_t *buffer=NULL; esr_nparticle_t *esr; int group=802; /* esrGroup*/ int nparticles; esr_particle_t esrp[MAX_ESR_PARTS]; if(!buffer){ buffer=(itape_header_t *)malloc(BUFSIZE); data_newItape(buffer); } /* * write header info */ buffer->runNo=mc_evt->runNo; buffer->eventNo= mc_evt->eventNo; buffer->spillNo= 0; buffer->trigger= 1; if(Debug) fprintf(fp,"%d %d\n", mc_evt->runNo, mc_evt->eventNo); esr=data_addGroup(buffer,BUFSIZE,802,sizeof(esr_nparticle_t)+ (mc_evt->nparts)*sizeof(esr_particle_t)); esr->nparticles = mc_evt->nparts; /* * now loop over the particle in the event and fill the esr */ /* * Kludged Beam */ esr->beam.space.x=0; esr->beam.space.y=0; esr->beam.space.z=KludgedBeam; esr->beam.t = KludgedBeam; for(i=0;i<mc_evt->nparts;i++){ esr->p[i].particleType =mc_evt->part[i].pid; esr->p[i].charge = getCharge( mc_evt->part[i].pid); esr->p[i].p.space.x=mc_evt->part[i].p.space.x;/* float = double */ esr->p[i].p.space.y=mc_evt->part[i].p.space.y; esr->p[i].p.space.z=mc_evt->part[i].p.space.z; esr->p[i].p.t=mc_evt->part[i].p.t; if(Debug) fprintf(fp,"%d %d %lf \n",(i+1), mc_evt->part[i].pid, mc_evt->part[i].mass); if(Debug) fprintf(fp," %d %lf %lf %lf %lf\n", getCharge( mc_evt->part[i].pid), /*mc_evt->part[i].pid/abs(mc_evt->part[i].pid),*/ mc_evt->part[i].p.space.x, mc_evt->part[i].p.space.y, mc_evt->part[i].p.space.z, mc_evt->part[i].p.t); } data_saveGroups(buffer,1,&group); data_clean(buffer); data_write(fileno(fp),buffer); return 1; }
static DEC_errCode data_to_struct(uint8_t sender,uint8_t stream[], int length) // start = 0 { #if DEBUG > 1 printf("Entering data_to_struct\n"); #endif switch(sender) { case BONE_PLANE: //sender_id of beaglebone switch(stream[MESSAGE_ID_INDEX]) { case BEAGLE_ERROR: data_write(stream, (void *)&write_data->bone_plane.error, sizeof(Beagle_error)-1); write_data->bone_plane.error.new_data = 0; break; default: return DEC_ERR_UNKNOWN_BONE_PACKAGE; break; } break; case LISA: //sender_id of lisa switch(stream[MESSAGE_ID_INDEX]) // the message id of the folowing message { case SVINFO: data_write(stream, (void *)&write_data->lisa_plane.svinfo, sizeof(Svinfo)-1); break; case SYSMON: data_write(stream, (void *)&write_data->lisa_plane.sys_mon, sizeof(Sys_mon)-1); break; case AIRSPEED_ETS: data_write(stream, (void *)&write_data->lisa_plane.airspeed_ets, sizeof(Airspeed_ets)-1); break; case ACTUATORS: data_write(stream, (void *)&write_data->lisa_plane.actuators, sizeof(Actuators)-1); break; case GPS_INT: data_write(stream, (void *)&write_data->lisa_plane.gps_int, sizeof(Gps_int)-1); break; case IMU_GYRO_RAW: data_write(stream, (void *)&write_data->lisa_plane.imu_gyro_raw, sizeof(Imu_gyro_raw)-1); break; case IMU_ACCEL_RAW: data_write(stream, (void *)&write_data->lisa_plane.imu_accel_raw, sizeof(Imu_accel_raw)-1); break; case IMU_MAG_RAW: data_write(stream, (void *)&write_data->lisa_plane.imu_mag_raw, sizeof(Imu_mag_raw)-1); break; case UART_ERRORS: data_write(stream, (void *)&write_data->lisa_plane.uart_errors, sizeof(UART_errors)-1); break; case BARO_RAW: data_write(stream, (void *)&write_data->lisa_plane.baro_raw, sizeof(Baro_raw)-1); break; default: return DEC_ERR_UNKNOWN_LISA_PACKAGE;break; } break; case BONE_WIND: switch(stream[MESSAGE_ID_INDEX]){ case NMEA_IIMWV_ID: data_write(stream, (void *)&write_data->bone_wind.nmea_iimmwv, sizeof(NMEA_IIMWV)-1); break; case NMEA_WIXDR_ID: data_write(stream, (void *)&write_data->bone_wind.nmea_wixdr, sizeof(NMEA_WIXDR)-1); break; default: return DEC_ERR_UNKNOWN_WIND_PACKAGE; break; } break; case BONE_ARM: switch(stream[MESSAGE_ID_INDEX]){ case LINE_ANGLE_ID: data_write(stream, (void *)&write_data->bone_arm.line_angle, sizeof(LINE_ANGLE)-1); break; default: return DEC_ERR_UNKNOWN_WIND_PACKAGE; break; } break; default: return DEC_ERR_UNKNOWN_SENDER; break; } return DEC_ERR_NONE; }
/*----------------------------------------------------------------------------* * This function is carrying out processing which calls a lgmon process. * And pipes create. */ static int lgmon_exec( int argc, FILE *fp, int fd, char *command, int copies ) { int rtn ; /* return status buffer */ int pipe_fds[2] ; /* pipe disripter */ if ( pipe(pipe_fds) < 0 ) { /* pipe cleate */ return( CANON_STS_PIPE_ERR ) ; } g_pid = fork() ; /* fork() */ if ( g_pid == -1 ) { /* fork() error */ return( CANON_STS_FORK_ERR ) ; } else if ( g_pid == 0 ) { /* child process */ static int cmd_argv_cnt = 0 ; /* argument counter */ static char *cmd_argv[4] ; /* command argument beffer */ static char *cmd_sh_path = "/bin/sh"; /* shell path */ static char str_msg[128] ; /* message beffer */ memset( str_msg, 0x00, sizeof(str_msg) ) ; close( 0 ) ; /* stdin close */ close( 1 ) ; /* stdout close */ dup2( pipe_fds[0], 0 ) ; /* pipe cleate */ dup2( fd, 1 ) ; /* stdout to device */ close( fd ) ; /* device fd close */ close( pipe_fds[0] ) ; /* pipe(in) close */ close( pipe_fds[1] ) ; /* pipe(out) close */ cmd_argv[cmd_argv_cnt++] = "sh" ; /* create lgmon command */ cmd_argv[cmd_argv_cnt++] = "-c" ; cmd_argv[cmd_argv_cnt++] = (char *)command ; cmd_argv[cmd_argv_cnt++] = NULL ; fprintf( stderr, "%s(Canon) langage moniter[%s] start!\n", message_str_base[DEBUG_MESSAGE], cmd_argv[2] ) ; rtn = execvp ( cmd_sh_path, cmd_argv ) ;/* lgmon exec */ if ( rtn == -1 ) { /* error */ switch( errno ) { case ENOENT : /* Command not found */ strcpy( str_msg, "Command not found" ) ; break ; case EACCES : /* Command Permission denied*/ strcpy( str_msg, "Command Permission denied" ) ; break ; default : strcpy( str_msg, "Please refer to <asm/errno.h>" ) ; } fprintf( stderr, "%s %s %s(errno=%d[%s])\n", message_str_base[ERROR_MASSAGE], sts_message_str[CANON_STS_DEFAULT], sts_message_str[CANON_STS_LGMON_EXEC_ERR], errno, str_msg ) ; exit(0) ; } } else { /* parents process */ close( pipe_fds[0] ) ; /* pipe(in) close */ data_write( argc, fp, copies, pipe_fds[1] ) ; /* data write */ close( pipe_fds[1] ) ; /* pipe(out) close */ } if ( g_pid > 0 ) { /* if child process has started.... */ waitpid( g_pid, NULL, 0) ; /* child process wait */ } return( CANON_STS_SUCCESS ) ; }
void dsp16_device::execute_one(const UINT16& op, UINT8& cycles, UINT8& pcAdvance) { cycles = 1; pcAdvance = 0; const UINT8 opcode = (op >> 11) & 0x1f; switch(opcode) { // Format 1: Multiply/ALU Read/Write Group case 0x06: { // F1, Y : (page 3-38) const UINT8 Y = (op & 0x000f); const UINT8 S = (op & 0x0200) >> 9; const UINT8 D = (op & 0x0400) >> 10; const UINT8 F1 = (op & 0x01e0) >> 5; executeF1Field(F1, D, S); executeYFieldPost(Y); cycles = 1; pcAdvance = 1; break; } case 0x04: case 0x1c: { // F1 Y=a0[1] | F1 Y=a1[1] //const UINT8 Y = (op & 0x000f); //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } case 0x16: { // F1, x = Y //const UINT8 Y = (op & 0x000f); //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } case 0x17: { // F1, y[l] = Y : (page 3-44) const UINT8 Y = (op & 0x000f); const UINT8 X = (op & 0x0010) >> 4; const UINT8 S = (op & 0x0200) >> 9; const UINT8 D = (op & 0x0400) >> 10; const UINT8 F1 = (op & 0x01e0) >> 5; executeF1Field(F1, D, S); UINT16* sourceReg = (UINT16*)registerFromYFieldUpper(Y); UINT16 sourceValue = data_read(*sourceReg); switch (X) { case 0x00: writeRegister(addressYL(), sourceValue); break; case 0x01: writeRegister(&m_y, sourceValue); break; default: break; } executeYFieldPost(Y); cycles = 1; pcAdvance = 1; break; } case 0x1f: { // F1, y = Y, x = *pt++[i] //const UINT8 Y = (op & 0x000f); //const UINT8 X = (op & 0x0010) >> 4; //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } case 0x19: case 0x1b: { // F1, y = a0|1, x = *pt++[i] //const UINT8 Y = (op & 0x000f); //const UINT8 X = (op & 0x0010) >> 4; //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } case 0x14: { // F1, Y = y[1] : (page 3-53) const UINT8 Y = (op & 0x000f); const UINT8 X = (op & 0x0010) >> 4; const UINT8 S = (op & 0x0200) >> 9; const UINT8 D = (op & 0x0400) >> 10; const UINT8 F1 = (op & 0x01e0) >> 5; executeF1Field(F1, D, S); UINT16* destinationReg = (UINT16*)registerFromYFieldUpper(Y); UINT16 yRegValue = 0x0000; switch (X) { case 0x00: yRegValue = (m_y & 0x0000ffff); break; case 0x01: yRegValue = (m_y & 0xffff0000) >> 16; break; default: break; } data_write(*destinationReg, yRegValue); executeYFieldPost(Y); cycles = 2; pcAdvance = 1; break; } // Format 1a: Multiply/ALU Read/Write Group (TODO: Figure out major typo in docs on p3-51) case 0x07: { // F1, At[1] = Y : (page 3-50) const UINT8 Y = (op & 0x000f); const UINT8 S = (op & 0x0200) >> 9; const UINT8 aT = (op & 0x0400) >> 10; const UINT8 F1 = (op & 0x01e0) >> 5; executeF1Field(F1, !aT, S); UINT64* destinationReg = NULL; switch(aT) { case 0: destinationReg = &m_a1; break; case 1: destinationReg = &m_a0; break; default: break; } UINT16 sourceAddress = *((UINT16*)registerFromYFieldUpper(Y)); INT64 sourceValueSigned = (INT16)data_read(sourceAddress); *destinationReg = sourceValueSigned & U64(0xffffffffff); executeYFieldPost(Y); cycles = 1; pcAdvance = 1; break; } // Format 2: Multiply/ALU Read/Write Group case 0x15: { // F1, Z : y[1] //const UINT8 Z = (op & 0x000f); //const UINT8 X = (op & 0x0010) >> 4; //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } case 0x1d: { // F1, Z : y, x=*pt++[i] //const UINT8 Z = (op & 0x000f); //const UINT8 X = (op & 0x0010) >> 4; //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } // Format 2a: Multiply/ALU Read/Write Group case 0x05: { // F1, Z : aT[1] //const UINT8 Z = (op & 0x000f); //const UINT8 X = (op & 0x0010) >> 4; //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 aT = (op & 0x0400) >> 10; //const UINT8 F1 = (op & 0x01e0) >> 5; break; } // Format 3: Special Functions case 0x12: case 0x13: { // if|ifc CON F2 //const UINT8 CON = (op & 0x001f); //const UINT8 S = (op & 0x0200) >> 9; //const UINT8 D = (op & 0x0400) >> 10; //const UINT8 F2 = (op & 0x01e0) >> 5; break; } // Format 4: Branch Direct Group case 0x00: case 0x01: { // goto JA : (page 3-20) const UINT16 JA = (op & 0x0fff) | (m_pc & 0xf000); m_pc = JA; cycles = 2; pcAdvance = 0; break; } case 0x10: case 0x11: { // call JA : (page 3-23) const UINT16 JA = (op & 0x0fff) | (m_pc & 0xf000); m_pr = m_pc + 1; m_pc = JA; cycles = 2; pcAdvance = 0; break; } // Format 5: Branch Indirect Group case 0x18: { // goto B //const UINT8 B = (op & 0x0700) >> 8; break; } // Format 6: Contitional Branch Qualifier/Software Interrupt (icall) case 0x1a: { // if CON [goto/call/return] //const UINT8 CON = (op & 0x001f); break; } // Format 7: Data Move Group case 0x09: case 0x0b: { // R = aS //const UINT8 R = (op & 0x03f0) >> 4; //const UINT8 S = (op & 0x1000) >> 12; break; } case 0x08: { // aT = R //const UINT8 R = (op & 0x03f0) >> 4; //const UINT8 aT = (op & 0x0400) >> 10; break; } case 0x0f: { // R = Y //const UINT8 Y = (op & 0x000f); //const UINT8 R = (op & 0x03f0) >> 4; break; } case 0x0c: { // Y = R : (page 3-33) const UINT8 Y = (op & 0x000f); const UINT8 R = (op & 0x03f0) >> 4; UINT16* destinationReg = (UINT16*)registerFromYFieldUpper(Y); UINT16* sourceReg = (UINT16*)registerFromRTable(R); data_write(*destinationReg, *sourceReg); executeYFieldPost(Y); cycles = 2; pcAdvance = 1; break; } case 0x0d: { // Z : R //const UINT8 Z = (op & 0x000f); //const UINT8 R = (op & 0x03f0) >> 4; break; } // Format 8: Data Move (immediate operand - 2 words) case 0x0a: { // R = N : (page 3-28) const UINT8 R = (op & 0x03f0) >> 4; const UINT16 iVal = opcode_read(1); void* reg = registerFromRTable(R); writeRegister(reg, iVal); cycles = 2; pcAdvance = 2; break; } // Format 9: Short Immediate Group case 0x02: case 0x03: { // R = M : (page 3-27) const INT8 M = (op & 0x00ff); const UINT8 R = (op & 0x0e00) >> 9; void* reg = registerFromRImmediateField(R); writeRegister(reg, (INT16)M); // Sign extend 8 bit int cycles = 1; pcAdvance = 1; break; } // Format 10: do - redo case 0x0e: { // do|redo K : (pages 3-25 & 3-26) const UINT8 K = (op & 0x007f); const UINT8 NI = (op & 0x0780) >> 7; if (NI != 0) { // Do m_cacheStart = m_pc + 1; m_cacheEnd = m_pc + NI + 1; m_cacheIterations = K-1; // -1 because we check the counter below cycles = 1; pcAdvance = 1; } else { // Redo m_cacheIterations = K-1; // -1 because we check the counter below m_cacheRedoNextPC = m_pc + 1; m_pc = m_cacheStart; pcAdvance = 0; cycles = 2; pcAdvance = 1; } break; } // RESERVED case 0x1e: { break; } // UNKNOWN default: { break; } } // Handle end-of-cache conditions for do|redos if (m_cacheIterations == 0 && m_cacheRedoNextPC != CACHE_INVALID) { // You've reached the end of a cache loop after a redo opcode. m_pc = m_cacheRedoNextPC; m_cacheRedoNextPC = CACHE_INVALID; pcAdvance = 0; } if (m_cacheIterations > 0 && (m_pc+pcAdvance == m_cacheEnd)) { // A regular iteration on a cached loop. m_cacheIterations--; m_pc = m_cacheStart; pcAdvance = 0; } }
/* data_read - read data from socket * * @data_ptr - pointer to memory where to store read data * @data_len - how much to read from socket * * return 0 on success, otherwise (-1) */ int data_read(int fd, void *data_ptr, int data_len) { int rc = 0; int data_read = 0; int data_total = 0; int try = 1; int errno_save = 0; if (data_len < 0) { return (-1); } while (data_total < data_len && try < 4) { errno = 0; /* TODO - add poll() */ data_read = read(fd, data_ptr, data_len); errno_save = errno; if (data_read > 0) { data_total+= data_read; } if (errno_save != 0) { if (errno_save == EINTR || errno_save == EAGAIN) { try++; sleep(2); continue; } else { errno = errno_save; perror("dummy failed on read(): "); rc = (-1); break; } } } if (try > 3 && data_total != data_len) { rc = (-1); } return rc; } /* data_write - write data to the socket * * @data_ptr - ptr to data to send * @data_len - how long is the data to send * * returns 0 on success, otherwise (-1) */ int data_write(int fd, void *data_ptr, int data_len) { int rc = 0; int data_written = 0; int data_total = 0; int try = 1; int errno_save = 0; if (data_len < 0) { return (-1); } while (data_total < data_len && try < 4) { errno = 0; /* TODO - add poll() */ data_written = write(fd, data_ptr, data_len); errno_save = errno; if (data_read > 0) { data_total+= data_written; } if (errno_save != 0) { if (errno_save == EINTR || errno_save == EAGAIN) { try++; sleep(2); continue; } else { errno = errno_save; perror("dummy failed on read(): "); rc = (-1); break; } } } if (try > 3 && data_total != data_len) { rc = (-1); } return rc; } /* ipmi_dummyipmi_close - send "BYE" and close socket * * @intf - ptr to initialize ipmi_intf struct * * returns void */ static void ipmi_dummyipmi_close(struct ipmi_intf *intf) { struct dummy_rq req; int data_total = 0; int data_written = 0; int try = 0; if (intf->fd < 0) { return; } memset(&req, 0, sizeof(req)); req.msg.netfn = 0x3f; req.msg.cmd = 0xff; if (data_write(intf->fd, &req, sizeof(req)) != 0) { lprintf(LOG_ERR, "dummy failed to send 'BYE'"); } close(intf->fd); intf->fd = (-1); intf->opened = 0; } /* ipmi_dummyipmi_open - open socket and prepare ipmi_intf struct * * @intf - ptr to ipmi_inf struct * * returns 0 on success, (-1) on error */ static int ipmi_dummyipmi_open(struct ipmi_intf *intf) { struct sockaddr_un address; int len; int rc; if (intf->opened == 1) { return intf->fd; } intf->fd = socket(AF_UNIX, SOCK_STREAM, 0); if (intf->fd == (-1)) { lprintf(LOG_ERR, "dummy failed on socket()"); return (-1); } address.sun_family = AF_UNIX; strcpy(address.sun_path, DUMMY_SOCKET_PATH); len = sizeof(address); rc = connect(intf->fd, (struct sockaddr *)&address, len); if (rc != 0) { perror("dummy failed on connect(): "); return (-1); } intf->opened = 1; return intf->fd; } /* ipmi_dummyipmi_send_cmd - send IPMI payload and await reply * * @intf - ptr to initialized ipmi_intf struct * @req - ptr to ipmi_rq struct to send * * return pointer to struct ipmi_rs OR NULL on error */ static struct ipmi_rs* ipmi_dummyipmi_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req) { static struct ipmi_rs rsp; struct dummy_rq req_dummy; struct dummy_rs rsp_dummy; if (intf == NULL || intf->fd < 0 || intf->opened != 1) { lprintf(LOG_ERR, "dummy failed on intf check."); return NULL; } memset(&req_dummy, 0, sizeof(req_dummy)); req_dummy.msg.netfn = req->msg.netfn; req_dummy.msg.lun = req->msg.lun; req_dummy.msg.cmd = req->msg.cmd; req_dummy.msg.target_cmd = req->msg.target_cmd; req_dummy.msg.data_len = req->msg.data_len; req_dummy.msg.data = req->msg.data; if (verbose) { lprintf(LOG_NOTICE, ">>> IPMI req"); lprintf(LOG_NOTICE, "msg.data_len: %i", req_dummy.msg.data_len); lprintf(LOG_NOTICE, "msg.netfn: %x", req_dummy.msg.netfn); lprintf(LOG_NOTICE, "msg.cmd: %x", req_dummy.msg.cmd); lprintf(LOG_NOTICE, "msg.target_cmd: %x", req_dummy.msg.target_cmd); lprintf(LOG_NOTICE, "msg.lun: %x", req_dummy.msg.lun); lprintf(LOG_NOTICE, ">>>"); } if (data_write(intf->fd, &req_dummy, sizeof(struct dummy_rq)) != 0) { return NULL; } if (req->msg.data_len > 0) { if (data_write(intf->fd, (uint8_t *)(req->msg.data), req_dummy.msg.data_len) != 0) { return NULL; } } memset(&rsp_dummy, 0, sizeof(rsp_dummy)); if (data_read(intf->fd, &rsp_dummy, sizeof(struct dummy_rs)) != 0) { return NULL; } if (rsp_dummy.data_len > 0) { if (data_read(intf->fd, (uint8_t *)&rsp.data, rsp_dummy.data_len) != 0) { return NULL; } } rsp.ccode = rsp_dummy.ccode; rsp.data_len = rsp_dummy.data_len; rsp.msg.netfn = rsp_dummy.msg.netfn; rsp.msg.cmd = rsp_dummy.msg.cmd; rsp.msg.seq = rsp_dummy.msg.seq; rsp.msg.lun = rsp_dummy.msg.lun; if (verbose) { lprintf(LOG_NOTICE, "<<< IPMI rsp"); lprintf(LOG_NOTICE, "ccode: %x", rsp.ccode); lprintf(LOG_NOTICE, "data_len: %i", rsp.data_len); lprintf(LOG_NOTICE, "msg.netfn: %x", rsp.msg.netfn); lprintf(LOG_NOTICE, "msg.cmd: %x", rsp.msg.cmd); lprintf(LOG_NOTICE, "msg.seq: %x", rsp.msg.seq); lprintf(LOG_NOTICE, "msg.lun: %x", rsp.msg.lun); lprintf(LOG_NOTICE, "<<<"); } return &rsp; } struct ipmi_intf ipmi_dummy_intf = { name: "dummy", desc: "Linux DummyIPMI Interface", open: ipmi_dummyipmi_open, close: ipmi_dummyipmi_close, sendrecv: ipmi_dummyipmi_send_cmd, my_addr: IPMI_BMC_SLAVE_ADDR, target_addr: IPMI_BMC_SLAVE_ADDR, };
int main(int argc, char **argv) { int i; int in_offset=0; char *in_fill=NULL; FILE *pfile; char ltrs[] = "urls"; int synt = 5; pfile = stdin; for(i=1;i<argc;i++) { if(argv[i][0]=='-') { if(argv[i][1]=='p') pfile = fopen(argv[++i],"r"); else if(argv[i][1]=='i' && argv[i][2]=='o') sscanf(argv[++i], "%i", &in_offset); else if(argv[i][1]=='i' && argv[i][2]==0) in_fill=argv[++i]; else if(argv[i][1]=='d') debug = 1; else if(argv[i][1]=='s') { if(argv[i][2]=='4' || argv[i][2]=='5') synt = argv[i][2]-'0'; else { printf("Wrong syntax type!\n"); return 0; }; } else if(argv[i][1]=='h') { printf(USAGE_MSG); return 0; } } } if(in_fill) { data.pos = in_offset; while(*in_fill) { data_write(*in_fill); in_fill++; data.pos++; } } if(!pfile) { printf("Cant open program file.\n"); return 0; } if(synt==5) feed_program(pfile); else feed_program4(pfile); run(); print_line(); if(debug) for(i=0;i<prog_len;i++) printf("%2u,%c,%c,%c,%2u\n", cmd_qF(prog[i]), cmd_cF(prog[i]), cmd_cT(prog[i]), ltrs[cmd_act(prog[i])>>16], cmd_qT(prog[i]) ); return 0; }
int main(void){ //ustawienie portow DDRD = 0xff; DDRC = 0x0f; PORTC = 0x30; DDRB = 0x00; PORTB = 0x02; display_on(); display_clear(); set_entry_mode(); function_set(); print("Ladies and"); _delay_ms(1500); clear_line(0); print("Gentlemen"); _delay_ms(1500); clear_line(0); print("We are floating"); _delay_ms(1500); clear_line(0); print("in space"); _delay_ms(1500); clear_line(0); short offset = 0; while(1){ if(!(PINC & 0x20)){ ++offset; data_write('a'+offset); shift_cursor(SH_LEFT); _delay_ms(20); // przeczekaj drgania stykow uint8_t step = 10, counter = 0; while(!(PINC & 0x20)){ //dopoki wcisniety if(counter>100){ step = 3; counter = 0; ++offset; data_write('a'+offset); shift_cursor(SH_LEFT); }else ++counter; _delay_ms(step); } _delay_ms(20); // przeczekaj drgania stykow } if(!(PINC & 0x10)){ --offset; data_write('a'+offset); shift_cursor(SH_LEFT); _delay_ms(20); // przeczekaj drgania stykow uint8_t step = 10, counter = 0; while(!(PINC & 0x10)){ //dopoki wcisniety if(counter>100){ step = 3; counter = 0; --offset; data_write('a'+offset); shift_cursor(SH_LEFT); }else ++counter; _delay_ms(step); } _delay_ms(20); // przeczekaj drgania stykow } if(!(PINB & 0x2)){ shift_cursor(SH_RIGHT); data_write('a'); shift_cursor(SH_LEFT); offset = 0; _delay_ms(20); // przeczekaj drgania stykow while(!(PINB & 0x2)){} //dopoki wcisniety _delay_ms(20); // przeczekaj drgania stykow } } }
int main(int argc, char *argv[]) { char *dev_name; char *file_name; int dev_fd = 0; FILE *file_fd = NULL; int cnt = 0; struct tsu_stat tsu_stat; /* Eecutable name. */ util_name = argv[cnt++]; if(argc < 4) { if(argc > 1) fprintf(stderr,"Missing parameters.\n"); usage(); } /* Device name */ dev_name = argv[cnt++]; /* Read / Write operation. */ if(!strcmp(argv[cnt],"r")) { g_is_read = 1; } else if(!strcmp(argv[cnt],"w")) { g_is_read = 0; } else { fprintf(stderr,"Bad read / write option.\n"); usage(); } cnt++; /* Open the device. */ if(g_is_read) dev_fd = open(dev_name, O_RDONLY); else dev_fd = open(dev_name, O_WRONLY); if(dev_fd <= 0) { fprintf(stderr,"%s - Cannot open device %s.\n",util_name,dev_name); exit(2); } /* Input / Output file name. */ file_name = argv[cnt++]; if(g_is_read) { if(!strncmp(file_name,"stdout",strlen("stdout"))) file_fd = stdout; else file_fd = fopen(file_name, "w+"); }else{ file_fd = fopen(file_name, "r"); } if(file_fd == NULL) { fprintf(stderr,"%s - Cannot open file %s.\n",util_name,file_name); goto error; } if(get_buff_info(dev_fd) < 0){ fprintf(stderr,"%s - Failed to retrieve device buffer configuration.\n"); goto error; } /* Allocate buffer. */ data_buff = malloc(g_buf_size); if(data_buff == NULL) { fprintf(stderr,"%s - Failed to allocate memory (%d Bytes).\n",util_name, BUFSIZE); goto error; } if(process_options(argc,argv,cnt,dev_fd) < 0) { fprintf(stderr,"Bad options.\n"); goto error; } /* Clear statistics. */ if(ioctl(dev_fd,MVTSU_IOCCLEARSTAT,0) < 0) { fprintf(stderr,"Error Clearing statistics.\n"); goto error; } if(g_is_read) data_read(dev_fd,file_fd); else data_write(dev_fd,file_fd); /* Print statistics. */ if(ioctl(dev_fd,MVTSU_IOCGETSTAT,&tsu_stat) < 0) { fprintf(stderr,"Error Printing statistics.\n"); goto error; } tsu_print_stat(&tsu_stat); error: if(dev_fd != 0) close(dev_fd); if(file_fd != NULL) fclose(file_fd); if(data_buff != NULL) free(data_buff); if(g_stat_fd != NULL) fclose(g_stat_fd); return 0; }
void char_write(char mychar) { data_write((uint8_t)mychar); }
void print(char * str){ while(*str != 0){ data_write(*str); ++str; } }